2 * dumptab.c - handles dumping the database
8 #include <netinet/in.h>
9 #include <arpa/inet.h> /* inet_ntoa */
21 #include "patchlevel.h"
25 static void dump_generic(FILE *, struct shared_bindata *);
26 static void dump_host(FILE *, struct host *);
27 static void list_ipaddresses(FILE *, struct in_addr_list *);
32 dumptab(char *filename)
34 report(LOG_INFO, "No dumptab support!");
40 * Dump the internal memory database to bootpd_dump.
44 dumptab(char *filename)
50 /* Print symbols in alphabetical order for reader's convenience. */
51 static char legend[] = "#\n# Legend:\t(see bootptab.5)\n\
52 #\tfirst field -- hostname (not indented)\n\
54 #\tbs -- bootfile size in 512-octet blocks\n\
55 #\tcs -- cookie servers\n\
56 #\tdf -- dump file name\n\
57 #\tdn -- domain name\n\
58 #\tds -- domain name servers\n\
59 #\tef -- extension file\n\
60 #\tex -- exec file (YORK_EX_OPTION)\n\
62 #\tha -- hardware address\n\
63 #\thd -- home directory for bootfiles\n\
64 #\thn -- host name set for client\n\
65 #\tht -- hardware type\n\
66 #\tim -- impress servers\n\
67 #\tip -- host IP address\n\
68 #\tlg -- log servers\n\
69 #\tlp -- LPR servers\n\
70 #\tms -- message size\n\
71 #\tmw -- min wait (secs)\n\
72 #\tns -- IEN-116 name servers\n\
73 #\tnt -- NTP servers (RFC 1129)\n\
74 #\tra -- reply address override\n\
75 #\trl -- resource location protocol servers\n\
77 #\tsa -- boot server address\n\
78 #\tsm -- subnet mask\n\
79 #\tsw -- swap server\n\
80 #\ttc -- template host (points to similar host entry)\n\
81 #\ttd -- TFTP directory\n\
82 #\tto -- time offset (seconds)\n\
83 #\tts -- time servers\n\
84 #\tvm -- vendor magic number\n\
85 #\tyd -- YP (NIS) domain\n\
86 #\tys -- YP (NIS) servers\n\
87 #\tTn -- generic option tag n\n\
91 * Open bootpd.dump file.
93 if ((fp = fopen(filename, "w")) == NULL) {
94 report(LOG_ERR, "error opening \"%s\": %s",
95 filename, get_errmsg());
99 fprintf(fp, "\n# %s %s.%d\n", progname, VERSION, PATCHLEVEL);
100 fprintf(fp, "# %s: dump of bootp server database.\n", filename);
101 fprintf(fp, "# Dump taken %s", ctime(&t));
102 fwrite(legend, 1, sizeof(legend) - 1, fp);
105 for (hp = (struct host *) hash_FirstEntry(nmhashtable); hp != NULL;
106 hp = (struct host *) hash_NextEntry(nmhashtable)) {
113 report(LOG_INFO, "dumped %d entries to \"%s\".", n, filename);
119 * Dump all the available information on the host pointed to by "hp".
120 * The output is sent to the file pointed to by "fp".
124 dump_host(FILE *fp, struct host *hp)
126 /* Print symbols in alphabetical order for reader's convenience. */
128 fprintf(fp, "%s:", (hp->hostname ?
129 hp->hostname->string : "?"));
130 if (hp->flags.bootfile) {
131 fprintf(fp, "\\\n\t:bf=%s:", hp->bootfile->string);
133 if (hp->flags.bootsize) {
134 fprintf(fp, "\\\n\t:bs=");
135 if (hp->flags.bootsize_auto) {
136 fprintf(fp, "auto:");
138 fprintf(fp, "%lu:", (u_long)hp->bootsize);
141 if (hp->flags.cookie_server) {
142 fprintf(fp, "\\\n\t:cs=");
143 list_ipaddresses(fp, hp->cookie_server);
146 if (hp->flags.dump_file) {
147 fprintf(fp, "\\\n\t:df=%s:", hp->dump_file->string);
149 if (hp->flags.domain_name) {
150 fprintf(fp, "\\\n\t:dn=%s:", hp->domain_name->string);
152 if (hp->flags.domain_server) {
153 fprintf(fp, "\\\n\t:ds=");
154 list_ipaddresses(fp, hp->domain_server);
157 if (hp->flags.exten_file) {
158 fprintf(fp, "\\\n\t:ef=%s:", hp->exten_file->string);
160 if (hp->flags.exec_file) {
161 fprintf(fp, "\\\n\t:ex=%s:", hp->exec_file->string);
163 if (hp->flags.gateway) {
164 fprintf(fp, "\\\n\t:gw=");
165 list_ipaddresses(fp, hp->gateway);
168 /* FdC: swap_server (see below) */
169 if (hp->flags.homedir) {
170 fprintf(fp, "\\\n\t:hd=%s:", hp->homedir->string);
172 /* FdC: dump_file (see above) */
173 /* FdC: domain_name (see above) */
174 /* FdC: root_path (see below) */
175 if (hp->flags.name_switch && hp->flags.send_name) {
176 fprintf(fp, "\\\n\t:hn:");
178 if (hp->flags.htype) {
179 int hlen = haddrlength(hp->htype);
180 fprintf(fp, "\\\n\t:ht=%u:", (unsigned) hp->htype);
181 if (hp->flags.haddr) {
182 fprintf(fp, "ha=\"%s\":",
183 haddrtoa(hp->haddr, hlen));
186 if (hp->flags.impress_server) {
187 fprintf(fp, "\\\n\t:im=");
188 list_ipaddresses(fp, hp->impress_server);
191 /* NetBSD: swap_server (see below) */
192 if (hp->flags.iaddr) {
193 fprintf(fp, "\\\n\t:ip=%s:", inet_ntoa(hp->iaddr));
195 if (hp->flags.log_server) {
196 fprintf(fp, "\\\n\t:lg=");
197 list_ipaddresses(fp, hp->log_server);
200 if (hp->flags.lpr_server) {
201 fprintf(fp, "\\\n\t:lp=");
202 list_ipaddresses(fp, hp->lpr_server);
205 if (hp->flags.msg_size) {
206 fprintf(fp, "\\\n\t:ms=%lu:", (u_long)hp->msg_size);
208 if (hp->flags.min_wait) {
209 fprintf(fp, "\\\n\t:mw=%lu:", (u_long)hp->min_wait);
211 if (hp->flags.name_server) {
212 fprintf(fp, "\\\n\t:ns=");
213 list_ipaddresses(fp, hp->name_server);
216 if (hp->flags.ntp_server) {
217 fprintf(fp, "\\\n\t:nt=");
218 list_ipaddresses(fp, hp->ntp_server);
221 if (hp->flags.reply_addr) {
222 fprintf(fp, "\\\n\t:ra=%s:", inet_ntoa(hp->reply_addr));
224 if (hp->flags.rlp_server) {
225 fprintf(fp, "\\\n\t:rl=");
226 list_ipaddresses(fp, hp->rlp_server);
229 if (hp->flags.root_path) {
230 fprintf(fp, "\\\n\t:rp=%s:", hp->root_path->string);
232 if (hp->flags.bootserver) {
233 fprintf(fp, "\\\n\t:sa=%s:", inet_ntoa(hp->bootserver));
235 if (hp->flags.subnet_mask) {
236 fprintf(fp, "\\\n\t:sm=%s:", inet_ntoa(hp->subnet_mask));
238 if (hp->flags.swap_server) {
239 fprintf(fp, "\\\n\t:sw=%s:", inet_ntoa(hp->subnet_mask));
241 if (hp->flags.tftpdir) {
242 fprintf(fp, "\\\n\t:td=%s:", hp->tftpdir->string);
244 /* NetBSD: rootpath (see above) */
245 /* NetBSD: domainname (see above) */
246 /* NetBSD: dumpfile (see above) */
247 if (hp->flags.time_offset) {
248 fprintf(fp, "\\\n\t:to=%ld:", (long)hp->time_offset);
250 if (hp->flags.time_server) {
251 fprintf(fp, "\\\n\t:ts=");
252 list_ipaddresses(fp, hp->time_server);
255 if (hp->flags.vm_cookie) {
256 fprintf(fp, "\\\n\t:vm=");
257 if (!bcmp(hp->vm_cookie, vm_rfc1048, 4)) {
258 fprintf(fp, "rfc1048:");
259 } else if (!bcmp(hp->vm_cookie, vm_cmu, 4)) {
262 fprintf(fp, "%d.%d.%d.%d:",
263 (int) ((hp->vm_cookie)[0]),
264 (int) ((hp->vm_cookie)[1]),
265 (int) ((hp->vm_cookie)[2]),
266 (int) ((hp->vm_cookie)[3]));
269 if (hp->flags.nis_domain) {
270 fprintf(fp, "\\\n\t:yd=%s:",
271 hp->nis_domain->string);
273 if (hp->flags.nis_server) {
274 fprintf(fp, "\\\n\t:ys=");
275 list_ipaddresses(fp, hp->nis_server);
279 * XXX - Add new tags here (or above,
280 * so they print in alphabetical order).
283 if (hp->flags.generic) {
284 dump_generic(fp, hp->generic);
291 dump_generic(FILE *fp, struct shared_bindata *generic)
293 u_char *bp = generic->data;
294 u_char *ep = bp + generic->length;
306 fprintf(fp, " #junk in generic! :");
309 fprintf(fp, "\\\n\t:T%d=", tag);
311 fprintf(fp, "%02X", *bp);
324 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
326 * The addresses are printed in standard ASCII "dot" notation and separated
327 * from one another by a single space. A single leading space is also
328 * printed before the first adddress.
330 * Null lists produce no output (and no error).
334 list_ipaddresses(FILE *fp, struct in_addr_list *ipptr)
337 struct in_addr *addrptr;
340 count = ipptr->addrcount;
341 addrptr = ipptr->addr;
343 fprintf(fp, "%s", inet_ntoa(*addrptr++));
357 * c-argdecl-indent: 4
358 * c-continued-statement-offset: 4
359 * c-continued-brace-offset: -4