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"
37 static void dump_generic P((FILE *, struct shared_bindata *));
38 static void dump_host P((FILE *, struct host *));
39 static void list_ipaddresses P((FILE *, struct in_addr_list *));
48 report(LOG_INFO, "No dumptab support!");
54 * Dump the internal memory database to bootpd_dump.
65 /* Print symbols in alphabetical order for reader's convenience. */
66 static char legend[] = "#\n# Legend:\t(see bootptab.5)\n\
67 #\tfirst field -- hostname (not indented)\n\
69 #\tbs -- bootfile size in 512-octet blocks\n\
70 #\tcs -- cookie servers\n\
71 #\tdf -- dump file name\n\
72 #\tdn -- domain name\n\
73 #\tds -- domain name servers\n\
74 #\tef -- extension file\n\
75 #\tex -- exec file (YORK_EX_OPTION)\n\
77 #\tha -- hardware address\n\
78 #\thd -- home directory for bootfiles\n\
79 #\thn -- host name set for client\n\
80 #\tht -- hardware type\n\
81 #\tim -- impress servers\n\
82 #\tip -- host IP address\n\
83 #\tlg -- log servers\n\
84 #\tlp -- LPR servers\n\
85 #\tms -- message size\n\
86 #\tmw -- min wait (secs)\n\
87 #\tns -- IEN-116 name servers\n\
88 #\tnt -- NTP servers (RFC 1129)\n\
89 #\tra -- reply address override\n\
90 #\trl -- resource location protocol servers\n\
92 #\tsa -- boot server address\n\
93 #\tsm -- subnet mask\n\
94 #\tsw -- swap server\n\
95 #\ttc -- template host (points to similar host entry)\n\
96 #\ttd -- TFTP directory\n\
97 #\tto -- time offset (seconds)\n\
98 #\tts -- time servers\n\
99 #\tvm -- vendor magic number\n\
100 #\tyd -- YP (NIS) domain\n\
101 #\tys -- YP (NIS) servers\n\
102 #\tTn -- generic option tag n\n\
106 * Open bootpd.dump file.
108 if ((fp = fopen(filename, "w")) == NULL) {
109 report(LOG_ERR, "error opening \"%s\": %s",
110 filename, get_errmsg());
114 fprintf(fp, "\n# %s %s.%d\n", progname, VERSION, PATCHLEVEL);
115 fprintf(fp, "# %s: dump of bootp server database.\n", filename);
116 fprintf(fp, "# Dump taken %s", ctime(&t));
117 fwrite(legend, 1, sizeof(legend) - 1, fp);
120 for (hp = (struct host *) hash_FirstEntry(nmhashtable); hp != NULL;
121 hp = (struct host *) hash_NextEntry(nmhashtable)) {
128 report(LOG_INFO, "dumped %d entries to \"%s\".", n, filename);
134 * Dump all the available information on the host pointed to by "hp".
135 * The output is sent to the file pointed to by "fp".
143 /* Print symbols in alphabetical order for reader's convenience. */
145 fprintf(fp, "%s:", (hp->hostname ?
146 hp->hostname->string : "?"));
147 if (hp->flags.bootfile) {
148 fprintf(fp, "\\\n\t:bf=%s:", hp->bootfile->string);
150 if (hp->flags.bootsize) {
151 fprintf(fp, "\\\n\t:bs=");
152 if (hp->flags.bootsize_auto) {
153 fprintf(fp, "auto:");
155 fprintf(fp, "%lu:", (u_long)hp->bootsize);
158 if (hp->flags.cookie_server) {
159 fprintf(fp, "\\\n\t:cs=");
160 list_ipaddresses(fp, hp->cookie_server);
163 if (hp->flags.dump_file) {
164 fprintf(fp, "\\\n\t:df=%s:", hp->dump_file->string);
166 if (hp->flags.domain_name) {
167 fprintf(fp, "\\\n\t:dn=%s:", hp->domain_name->string);
169 if (hp->flags.domain_server) {
170 fprintf(fp, "\\\n\t:ds=");
171 list_ipaddresses(fp, hp->domain_server);
174 if (hp->flags.exten_file) {
175 fprintf(fp, "\\\n\t:ef=%s:", hp->exten_file->string);
177 if (hp->flags.exec_file) {
178 fprintf(fp, "\\\n\t:ex=%s:", hp->exec_file->string);
180 if (hp->flags.gateway) {
181 fprintf(fp, "\\\n\t:gw=");
182 list_ipaddresses(fp, hp->gateway);
185 /* FdC: swap_server (see below) */
186 if (hp->flags.homedir) {
187 fprintf(fp, "\\\n\t:hd=%s:", hp->homedir->string);
189 /* FdC: dump_file (see above) */
190 /* FdC: domain_name (see above) */
191 /* FdC: root_path (see below) */
192 if (hp->flags.name_switch && hp->flags.send_name) {
193 fprintf(fp, "\\\n\t:hn:");
195 if (hp->flags.htype) {
196 int hlen = haddrlength(hp->htype);
197 fprintf(fp, "\\\n\t:ht=%u:", (unsigned) hp->htype);
198 if (hp->flags.haddr) {
199 fprintf(fp, "ha=\"%s\":",
200 haddrtoa(hp->haddr, hlen));
203 if (hp->flags.impress_server) {
204 fprintf(fp, "\\\n\t:im=");
205 list_ipaddresses(fp, hp->impress_server);
208 /* NetBSD: swap_server (see below) */
209 if (hp->flags.iaddr) {
210 fprintf(fp, "\\\n\t:ip=%s:", inet_ntoa(hp->iaddr));
212 if (hp->flags.log_server) {
213 fprintf(fp, "\\\n\t:lg=");
214 list_ipaddresses(fp, hp->log_server);
217 if (hp->flags.lpr_server) {
218 fprintf(fp, "\\\n\t:lp=");
219 list_ipaddresses(fp, hp->lpr_server);
222 if (hp->flags.msg_size) {
223 fprintf(fp, "\\\n\t:ms=%lu:", (u_long)hp->msg_size);
225 if (hp->flags.min_wait) {
226 fprintf(fp, "\\\n\t:mw=%lu:", (u_long)hp->min_wait);
228 if (hp->flags.name_server) {
229 fprintf(fp, "\\\n\t:ns=");
230 list_ipaddresses(fp, hp->name_server);
233 if (hp->flags.ntp_server) {
234 fprintf(fp, "\\\n\t:nt=");
235 list_ipaddresses(fp, hp->ntp_server);
238 if (hp->flags.reply_addr) {
239 fprintf(fp, "\\\n\t:ra=%s:", inet_ntoa(hp->reply_addr));
241 if (hp->flags.rlp_server) {
242 fprintf(fp, "\\\n\t:rl=");
243 list_ipaddresses(fp, hp->rlp_server);
246 if (hp->flags.root_path) {
247 fprintf(fp, "\\\n\t:rp=%s:", hp->root_path->string);
249 if (hp->flags.bootserver) {
250 fprintf(fp, "\\\n\t:sa=%s:", inet_ntoa(hp->bootserver));
252 if (hp->flags.subnet_mask) {
253 fprintf(fp, "\\\n\t:sm=%s:", inet_ntoa(hp->subnet_mask));
255 if (hp->flags.swap_server) {
256 fprintf(fp, "\\\n\t:sw=%s:", inet_ntoa(hp->subnet_mask));
258 if (hp->flags.tftpdir) {
259 fprintf(fp, "\\\n\t:td=%s:", hp->tftpdir->string);
261 /* NetBSD: rootpath (see above) */
262 /* NetBSD: domainname (see above) */
263 /* NetBSD: dumpfile (see above) */
264 if (hp->flags.time_offset) {
265 fprintf(fp, "\\\n\t:to=%ld:", hp->time_offset);
267 if (hp->flags.time_server) {
268 fprintf(fp, "\\\n\t:ts=");
269 list_ipaddresses(fp, hp->time_server);
272 if (hp->flags.vm_cookie) {
273 fprintf(fp, "\\\n\t:vm=");
274 if (!bcmp(hp->vm_cookie, vm_rfc1048, 4)) {
275 fprintf(fp, "rfc1048:");
276 } else if (!bcmp(hp->vm_cookie, vm_cmu, 4)) {
279 fprintf(fp, "%d.%d.%d.%d:",
280 (int) ((hp->vm_cookie)[0]),
281 (int) ((hp->vm_cookie)[1]),
282 (int) ((hp->vm_cookie)[2]),
283 (int) ((hp->vm_cookie)[3]));
286 if (hp->flags.nis_domain) {
287 fprintf(fp, "\\\n\t:yd=%s:",
288 hp->nis_domain->string);
290 if (hp->flags.nis_server) {
291 fprintf(fp, "\\\n\t:ys=");
292 list_ipaddresses(fp, hp->nis_server);
296 * XXX - Add new tags here (or above,
297 * so they print in alphabetical order).
300 if (hp->flags.generic) {
301 dump_generic(fp, hp->generic);
308 dump_generic(fp, generic)
310 struct shared_bindata *generic;
312 u_char *bp = generic->data;
313 u_char *ep = bp + generic->length;
325 fprintf(fp, " #junk in generic! :");
328 fprintf(fp, "\\\n\t:T%d=", tag);
330 fprintf(fp, "%02X", *bp);
343 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
345 * The addresses are printed in standard ASCII "dot" notation and separated
346 * from one another by a single space. A single leading space is also
347 * printed before the first adddress.
349 * Null lists produce no output (and no error).
353 list_ipaddresses(fp, ipptr)
355 struct in_addr_list *ipptr;
358 struct in_addr *addrptr;
361 count = ipptr->addrcount;
362 addrptr = ipptr->addr;
364 fprintf(fp, "%s", inet_ntoa(*addrptr++));
378 * c-argdecl-indent: 4
379 * c-continued-statement-offset: 4
380 * c-continued-brace-offset: -4