2 * dumptab.c - handles dumping the database
4 * $FreeBSD: src/libexec/bootpd/dumptab.c,v 1.6.2.1 2001/10/14 21:39:48 iedowse Exp $
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"
38 static void dump_generic P((FILE *, struct shared_bindata *));
39 static void dump_host P((FILE *, struct host *));
40 static void list_ipaddresses P((FILE *, struct in_addr_list *));
50 report(LOG_INFO, "No dumptab support!");
56 * Dump the internal memory database to bootpd_dump.
67 /* Print symbols in alphabetical order for reader's convenience. */
68 static char legend[] = "#\n# Legend:\t(see bootptab.5)\n\
69 #\tfirst field -- hostname (not indented)\n\
71 #\tbs -- bootfile size in 512-octet blocks\n\
72 #\tcs -- cookie servers\n\
73 #\tdf -- dump file name\n\
74 #\tdn -- domain name\n\
75 #\tds -- domain name servers\n\
76 #\tef -- extension file\n\
77 #\tex -- exec file (YORK_EX_OPTION)\n\
79 #\tha -- hardware address\n\
80 #\thd -- home directory for bootfiles\n\
81 #\thn -- host name set for client\n\
82 #\tht -- hardware type\n\
83 #\tim -- impress servers\n\
84 #\tip -- host IP address\n\
85 #\tlg -- log servers\n\
86 #\tlp -- LPR servers\n\
87 #\tms -- message size\n\
88 #\tmw -- min wait (secs)\n\
89 #\tns -- IEN-116 name servers\n\
90 #\tnt -- NTP servers (RFC 1129)\n\
91 #\tra -- reply address override\n\
92 #\trl -- resource location protocol servers\n\
94 #\tsa -- boot server address\n\
95 #\tsm -- subnet mask\n\
96 #\tsw -- swap server\n\
97 #\ttc -- template host (points to similar host entry)\n\
98 #\ttd -- TFTP directory\n\
99 #\tto -- time offset (seconds)\n\
100 #\tts -- time servers\n\
101 #\tvm -- vendor magic number\n\
102 #\tyd -- YP (NIS) domain\n\
103 #\tys -- YP (NIS) servers\n\
104 #\tTn -- generic option tag n\n\
108 * Open bootpd.dump file.
110 if ((fp = fopen(filename, "w")) == NULL) {
111 report(LOG_ERR, "error opening \"%s\": %s",
112 filename, get_errmsg());
116 fprintf(fp, "\n# %s %s.%d\n", progname, VERSION, PATCHLEVEL);
117 fprintf(fp, "# %s: dump of bootp server database.\n", filename);
118 fprintf(fp, "# Dump taken %s", ctime(&t));
119 fwrite(legend, 1, sizeof(legend) - 1, fp);
122 for (hp = (struct host *) hash_FirstEntry(nmhashtable); hp != NULL;
123 hp = (struct host *) hash_NextEntry(nmhashtable)) {
130 report(LOG_INFO, "dumped %d entries to \"%s\".", n, filename);
136 * Dump all the available information on the host pointed to by "hp".
137 * The output is sent to the file pointed to by "fp".
145 /* Print symbols in alphabetical order for reader's convenience. */
147 fprintf(fp, "%s:", (hp->hostname ?
148 hp->hostname->string : "?"));
149 if (hp->flags.bootfile) {
150 fprintf(fp, "\\\n\t:bf=%s:", hp->bootfile->string);
152 if (hp->flags.bootsize) {
153 fprintf(fp, "\\\n\t:bs=");
154 if (hp->flags.bootsize_auto) {
155 fprintf(fp, "auto:");
157 fprintf(fp, "%lu:", (u_long)hp->bootsize);
160 if (hp->flags.cookie_server) {
161 fprintf(fp, "\\\n\t:cs=");
162 list_ipaddresses(fp, hp->cookie_server);
165 if (hp->flags.dump_file) {
166 fprintf(fp, "\\\n\t:df=%s:", hp->dump_file->string);
168 if (hp->flags.domain_name) {
169 fprintf(fp, "\\\n\t:dn=%s:", hp->domain_name->string);
171 if (hp->flags.domain_server) {
172 fprintf(fp, "\\\n\t:ds=");
173 list_ipaddresses(fp, hp->domain_server);
176 if (hp->flags.exten_file) {
177 fprintf(fp, "\\\n\t:ef=%s:", hp->exten_file->string);
179 if (hp->flags.exec_file) {
180 fprintf(fp, "\\\n\t:ex=%s:", hp->exec_file->string);
182 if (hp->flags.gateway) {
183 fprintf(fp, "\\\n\t:gw=");
184 list_ipaddresses(fp, hp->gateway);
187 /* FdC: swap_server (see below) */
188 if (hp->flags.homedir) {
189 fprintf(fp, "\\\n\t:hd=%s:", hp->homedir->string);
191 /* FdC: dump_file (see above) */
192 /* FdC: domain_name (see above) */
193 /* FdC: root_path (see below) */
194 if (hp->flags.name_switch && hp->flags.send_name) {
195 fprintf(fp, "\\\n\t:hn:");
197 if (hp->flags.htype) {
198 int hlen = haddrlength(hp->htype);
199 fprintf(fp, "\\\n\t:ht=%u:", (unsigned) hp->htype);
200 if (hp->flags.haddr) {
201 fprintf(fp, "ha=\"%s\":",
202 haddrtoa(hp->haddr, hlen));
205 if (hp->flags.impress_server) {
206 fprintf(fp, "\\\n\t:im=");
207 list_ipaddresses(fp, hp->impress_server);
210 /* NetBSD: swap_server (see below) */
211 if (hp->flags.iaddr) {
212 fprintf(fp, "\\\n\t:ip=%s:", inet_ntoa(hp->iaddr));
214 if (hp->flags.log_server) {
215 fprintf(fp, "\\\n\t:lg=");
216 list_ipaddresses(fp, hp->log_server);
219 if (hp->flags.lpr_server) {
220 fprintf(fp, "\\\n\t:lp=");
221 list_ipaddresses(fp, hp->lpr_server);
224 if (hp->flags.msg_size) {
225 fprintf(fp, "\\\n\t:ms=%lu:", (u_long)hp->msg_size);
227 if (hp->flags.min_wait) {
228 fprintf(fp, "\\\n\t:mw=%lu:", (u_long)hp->min_wait);
230 if (hp->flags.name_server) {
231 fprintf(fp, "\\\n\t:ns=");
232 list_ipaddresses(fp, hp->name_server);
235 if (hp->flags.ntp_server) {
236 fprintf(fp, "\\\n\t:nt=");
237 list_ipaddresses(fp, hp->ntp_server);
240 if (hp->flags.reply_addr) {
241 fprintf(fp, "\\\n\t:ra=%s:", inet_ntoa(hp->reply_addr));
243 if (hp->flags.rlp_server) {
244 fprintf(fp, "\\\n\t:rl=");
245 list_ipaddresses(fp, hp->rlp_server);
248 if (hp->flags.root_path) {
249 fprintf(fp, "\\\n\t:rp=%s:", hp->root_path->string);
251 if (hp->flags.bootserver) {
252 fprintf(fp, "\\\n\t:sa=%s:", inet_ntoa(hp->bootserver));
254 if (hp->flags.subnet_mask) {
255 fprintf(fp, "\\\n\t:sm=%s:", inet_ntoa(hp->subnet_mask));
257 if (hp->flags.swap_server) {
258 fprintf(fp, "\\\n\t:sw=%s:", inet_ntoa(hp->subnet_mask));
260 if (hp->flags.tftpdir) {
261 fprintf(fp, "\\\n\t:td=%s:", hp->tftpdir->string);
263 /* NetBSD: rootpath (see above) */
264 /* NetBSD: domainname (see above) */
265 /* NetBSD: dumpfile (see above) */
266 if (hp->flags.time_offset) {
267 fprintf(fp, "\\\n\t:to=%ld:", (long)hp->time_offset);
269 if (hp->flags.time_server) {
270 fprintf(fp, "\\\n\t:ts=");
271 list_ipaddresses(fp, hp->time_server);
274 if (hp->flags.vm_cookie) {
275 fprintf(fp, "\\\n\t:vm=");
276 if (!bcmp(hp->vm_cookie, vm_rfc1048, 4)) {
277 fprintf(fp, "rfc1048:");
278 } else if (!bcmp(hp->vm_cookie, vm_cmu, 4)) {
281 fprintf(fp, "%d.%d.%d.%d:",
282 (int) ((hp->vm_cookie)[0]),
283 (int) ((hp->vm_cookie)[1]),
284 (int) ((hp->vm_cookie)[2]),
285 (int) ((hp->vm_cookie)[3]));
288 if (hp->flags.nis_domain) {
289 fprintf(fp, "\\\n\t:yd=%s:",
290 hp->nis_domain->string);
292 if (hp->flags.nis_server) {
293 fprintf(fp, "\\\n\t:ys=");
294 list_ipaddresses(fp, hp->nis_server);
298 * XXX - Add new tags here (or above,
299 * so they print in alphabetical order).
302 if (hp->flags.generic) {
303 dump_generic(fp, hp->generic);
310 dump_generic(fp, generic)
312 struct shared_bindata *generic;
314 u_char *bp = generic->data;
315 u_char *ep = bp + generic->length;
327 fprintf(fp, " #junk in generic! :");
330 fprintf(fp, "\\\n\t:T%d=", tag);
332 fprintf(fp, "%02X", *bp);
345 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
347 * The addresses are printed in standard ASCII "dot" notation and separated
348 * from one another by a single space. A single leading space is also
349 * printed before the first adddress.
351 * Null lists produce no output (and no error).
355 list_ipaddresses(fp, ipptr)
357 struct in_addr_list *ipptr;
360 struct in_addr *addrptr;
363 count = ipptr->addrcount;
364 addrptr = ipptr->addr;
366 fprintf(fp, "%s", inet_ntoa(*addrptr++));
380 * c-argdecl-indent: 4
381 * c-continued-statement-offset: 4
382 * c-continued-brace-offset: -4