2 * dumptab.c - handles dumping the database
8 #include <netinet/in.h>
9 #include <arpa/inet.h> /* inet_ntoa */
18 /* Yes, memcpy is OK here (no overlapped copies). */
19 #define bcopy(a,b,c) memcpy(b,a,c)
20 #define bzero(p,l) memset(p,0,l)
21 #define bcmp(a,b,c) memcmp(a,b,c)
28 #include "patchlevel.h"
32 static void dump_generic(FILE *, struct shared_bindata *);
33 static void dump_host(FILE *, struct host *);
34 static void list_ipaddresses(FILE *, struct in_addr_list *);
42 report(LOG_INFO, "No dumptab support!");
48 * Dump the internal memory database to bootpd_dump.
59 /* Print symbols in alphabetical order for reader's convenience. */
60 static char legend[] = "#\n# Legend:\t(see bootptab.5)\n\
61 #\tfirst field -- hostname (not indented)\n\
63 #\tbs -- bootfile size in 512-octet blocks\n\
64 #\tcs -- cookie servers\n\
65 #\tdf -- dump file name\n\
66 #\tdn -- domain name\n\
67 #\tds -- domain name servers\n\
68 #\tef -- extension file\n\
69 #\tex -- exec file (YORK_EX_OPTION)\n\
71 #\tha -- hardware address\n\
72 #\thd -- home directory for bootfiles\n\
73 #\thn -- host name set for client\n\
74 #\tht -- hardware type\n\
75 #\tim -- impress servers\n\
76 #\tip -- host IP address\n\
77 #\tlg -- log servers\n\
78 #\tlp -- LPR servers\n\
79 #\tms -- message size\n\
80 #\tmw -- min wait (secs)\n\
81 #\tns -- IEN-116 name servers\n\
82 #\tnt -- NTP servers (RFC 1129)\n\
83 #\tra -- reply address override\n\
84 #\trl -- resource location protocol servers\n\
86 #\tsa -- boot server address\n\
87 #\tsm -- subnet mask\n\
88 #\tsw -- swap server\n\
89 #\ttc -- template host (points to similar host entry)\n\
90 #\ttd -- TFTP directory\n\
91 #\tto -- time offset (seconds)\n\
92 #\tts -- time servers\n\
93 #\tvm -- vendor magic number\n\
94 #\tyd -- YP (NIS) domain\n\
95 #\tys -- YP (NIS) servers\n\
96 #\tTn -- generic option tag n\n\
100 * Open bootpd.dump file.
102 if ((fp = fopen(filename, "w")) == NULL) {
103 report(LOG_ERR, "error opening \"%s\": %s",
104 filename, get_errmsg());
108 fprintf(fp, "\n# %s %s.%d\n", progname, VERSION, PATCHLEVEL);
109 fprintf(fp, "# %s: dump of bootp server database.\n", filename);
110 fprintf(fp, "# Dump taken %s", ctime(&t));
111 fwrite(legend, 1, sizeof(legend) - 1, fp);
114 for (hp = (struct host *) hash_FirstEntry(nmhashtable); hp != NULL;
115 hp = (struct host *) hash_NextEntry(nmhashtable)) {
122 report(LOG_INFO, "dumped %d entries to \"%s\".", n, filename);
128 * Dump all the available information on the host pointed to by "hp".
129 * The output is sent to the file pointed to by "fp".
137 /* Print symbols in alphabetical order for reader's convenience. */
139 fprintf(fp, "%s:", (hp->hostname ?
140 hp->hostname->string : "?"));
141 if (hp->flags.bootfile) {
142 fprintf(fp, "\\\n\t:bf=%s:", hp->bootfile->string);
144 if (hp->flags.bootsize) {
145 fprintf(fp, "\\\n\t:bs=");
146 if (hp->flags.bootsize_auto) {
147 fprintf(fp, "auto:");
149 fprintf(fp, "%lu:", (u_long)hp->bootsize);
152 if (hp->flags.cookie_server) {
153 fprintf(fp, "\\\n\t:cs=");
154 list_ipaddresses(fp, hp->cookie_server);
157 if (hp->flags.dump_file) {
158 fprintf(fp, "\\\n\t:df=%s:", hp->dump_file->string);
160 if (hp->flags.domain_name) {
161 fprintf(fp, "\\\n\t:dn=%s:", hp->domain_name->string);
163 if (hp->flags.domain_server) {
164 fprintf(fp, "\\\n\t:ds=");
165 list_ipaddresses(fp, hp->domain_server);
168 if (hp->flags.exten_file) {
169 fprintf(fp, "\\\n\t:ef=%s:", hp->exten_file->string);
171 if (hp->flags.exec_file) {
172 fprintf(fp, "\\\n\t:ex=%s:", hp->exec_file->string);
174 if (hp->flags.gateway) {
175 fprintf(fp, "\\\n\t:gw=");
176 list_ipaddresses(fp, hp->gateway);
179 /* FdC: swap_server (see below) */
180 if (hp->flags.homedir) {
181 fprintf(fp, "\\\n\t:hd=%s:", hp->homedir->string);
183 /* FdC: dump_file (see above) */
184 /* FdC: domain_name (see above) */
185 /* FdC: root_path (see below) */
186 if (hp->flags.name_switch && hp->flags.send_name) {
187 fprintf(fp, "\\\n\t:hn:");
189 if (hp->flags.htype) {
190 int hlen = haddrlength(hp->htype);
191 fprintf(fp, "\\\n\t:ht=%u:", (unsigned) hp->htype);
192 if (hp->flags.haddr) {
193 fprintf(fp, "ha=\"%s\":",
194 haddrtoa(hp->haddr, hlen));
197 if (hp->flags.impress_server) {
198 fprintf(fp, "\\\n\t:im=");
199 list_ipaddresses(fp, hp->impress_server);
202 /* NetBSD: swap_server (see below) */
203 if (hp->flags.iaddr) {
204 fprintf(fp, "\\\n\t:ip=%s:", inet_ntoa(hp->iaddr));
206 if (hp->flags.log_server) {
207 fprintf(fp, "\\\n\t:lg=");
208 list_ipaddresses(fp, hp->log_server);
211 if (hp->flags.lpr_server) {
212 fprintf(fp, "\\\n\t:lp=");
213 list_ipaddresses(fp, hp->lpr_server);
216 if (hp->flags.msg_size) {
217 fprintf(fp, "\\\n\t:ms=%lu:", (u_long)hp->msg_size);
219 if (hp->flags.min_wait) {
220 fprintf(fp, "\\\n\t:mw=%lu:", (u_long)hp->min_wait);
222 if (hp->flags.name_server) {
223 fprintf(fp, "\\\n\t:ns=");
224 list_ipaddresses(fp, hp->name_server);
227 if (hp->flags.ntp_server) {
228 fprintf(fp, "\\\n\t:nt=");
229 list_ipaddresses(fp, hp->ntp_server);
232 if (hp->flags.reply_addr) {
233 fprintf(fp, "\\\n\t:ra=%s:", inet_ntoa(hp->reply_addr));
235 if (hp->flags.rlp_server) {
236 fprintf(fp, "\\\n\t:rl=");
237 list_ipaddresses(fp, hp->rlp_server);
240 if (hp->flags.root_path) {
241 fprintf(fp, "\\\n\t:rp=%s:", hp->root_path->string);
243 if (hp->flags.bootserver) {
244 fprintf(fp, "\\\n\t:sa=%s:", inet_ntoa(hp->bootserver));
246 if (hp->flags.subnet_mask) {
247 fprintf(fp, "\\\n\t:sm=%s:", inet_ntoa(hp->subnet_mask));
249 if (hp->flags.swap_server) {
250 fprintf(fp, "\\\n\t:sw=%s:", inet_ntoa(hp->subnet_mask));
252 if (hp->flags.tftpdir) {
253 fprintf(fp, "\\\n\t:td=%s:", hp->tftpdir->string);
255 /* NetBSD: rootpath (see above) */
256 /* NetBSD: domainname (see above) */
257 /* NetBSD: dumpfile (see above) */
258 if (hp->flags.time_offset) {
259 fprintf(fp, "\\\n\t:to=%ld:", (long)hp->time_offset);
261 if (hp->flags.time_server) {
262 fprintf(fp, "\\\n\t:ts=");
263 list_ipaddresses(fp, hp->time_server);
266 if (hp->flags.vm_cookie) {
267 fprintf(fp, "\\\n\t:vm=");
268 if (!bcmp(hp->vm_cookie, vm_rfc1048, 4)) {
269 fprintf(fp, "rfc1048:");
270 } else if (!bcmp(hp->vm_cookie, vm_cmu, 4)) {
273 fprintf(fp, "%d.%d.%d.%d:",
274 (int) ((hp->vm_cookie)[0]),
275 (int) ((hp->vm_cookie)[1]),
276 (int) ((hp->vm_cookie)[2]),
277 (int) ((hp->vm_cookie)[3]));
280 if (hp->flags.nis_domain) {
281 fprintf(fp, "\\\n\t:yd=%s:",
282 hp->nis_domain->string);
284 if (hp->flags.nis_server) {
285 fprintf(fp, "\\\n\t:ys=");
286 list_ipaddresses(fp, hp->nis_server);
290 * XXX - Add new tags here (or above,
291 * so they print in alphabetical order).
294 if (hp->flags.generic) {
295 dump_generic(fp, hp->generic);
302 dump_generic(fp, generic)
304 struct shared_bindata *generic;
306 u_char *bp = generic->data;
307 u_char *ep = bp + generic->length;
319 fprintf(fp, " #junk in generic! :");
322 fprintf(fp, "\\\n\t:T%d=", tag);
324 fprintf(fp, "%02X", *bp);
337 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
339 * The addresses are printed in standard ASCII "dot" notation and separated
340 * from one another by a single space. A single leading space is also
341 * printed before the first adddress.
343 * Null lists produce no output (and no error).
347 list_ipaddresses(fp, ipptr)
349 struct in_addr_list *ipptr;
352 struct in_addr *addrptr;
355 count = ipptr->addrcount;
356 addrptr = ipptr->addr;
358 fprintf(fp, "%s", inet_ntoa(*addrptr++));
372 * c-argdecl-indent: 4
373 * c-continued-statement-offset: 4
374 * c-continued-brace-offset: -4