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 $
5 * $DragonFly: src/libexec/bootpd/dumptab.c,v 1.2 2003/06/17 04:27:07 dillon Exp $
9 #include <netinet/in.h>
10 #include <arpa/inet.h> /* inet_ntoa */
19 /* Yes, memcpy is OK here (no overlapped copies). */
20 #define bcopy(a,b,c) memcpy(b,a,c)
21 #define bzero(p,l) memset(p,0,l)
22 #define bcmp(a,b,c) memcmp(a,b,c)
29 #include "patchlevel.h"
33 static void dump_generic(FILE *, struct shared_bindata
*);
34 static void dump_host(FILE *, struct host
*);
35 static void list_ipaddresses(FILE *, struct in_addr_list
*);
40 dumptab(char *filename
)
42 report(LOG_INFO
, "No dumptab support!");
48 * Dump the internal memory database to bootpd_dump.
52 dumptab(char *filename
)
58 /* Print symbols in alphabetical order for reader's convenience. */
59 static char legend
[] = "#\n# Legend:\t(see bootptab.5)\n\
60 #\tfirst field -- hostname (not indented)\n\
62 #\tbs -- bootfile size in 512-octet blocks\n\
63 #\tcs -- cookie servers\n\
64 #\tdf -- dump file name\n\
65 #\tdn -- domain name\n\
66 #\tds -- domain name servers\n\
67 #\tef -- extension file\n\
68 #\tex -- exec file (YORK_EX_OPTION)\n\
70 #\tha -- hardware address\n\
71 #\thd -- home directory for bootfiles\n\
72 #\thn -- host name set for client\n\
73 #\tht -- hardware type\n\
74 #\tim -- impress servers\n\
75 #\tip -- host IP address\n\
76 #\tlg -- log servers\n\
77 #\tlp -- LPR servers\n\
78 #\tms -- message size\n\
79 #\tmw -- min wait (secs)\n\
80 #\tns -- IEN-116 name servers\n\
81 #\tnt -- NTP servers (RFC 1129)\n\
82 #\tra -- reply address override\n\
83 #\trl -- resource location protocol servers\n\
85 #\tsa -- boot server address\n\
86 #\tsm -- subnet mask\n\
87 #\tsw -- swap server\n\
88 #\ttc -- template host (points to similar host entry)\n\
89 #\ttd -- TFTP directory\n\
90 #\tto -- time offset (seconds)\n\
91 #\tts -- time servers\n\
92 #\tvm -- vendor magic number\n\
93 #\tyd -- YP (NIS) domain\n\
94 #\tys -- YP (NIS) servers\n\
95 #\tTn -- generic option tag n\n\
99 * Open bootpd.dump file.
101 if ((fp
= fopen(filename
, "w")) == NULL
) {
102 report(LOG_ERR
, "error opening \"%s\": %s",
103 filename
, get_errmsg());
107 fprintf(fp
, "\n# %s %s.%d\n", progname
, VERSION
, PATCHLEVEL
);
108 fprintf(fp
, "# %s: dump of bootp server database.\n", filename
);
109 fprintf(fp
, "# Dump taken %s", ctime(&t
));
110 fwrite(legend
, 1, sizeof(legend
) - 1, fp
);
113 for (hp
= (struct host
*) hash_FirstEntry(nmhashtable
); hp
!= NULL
;
114 hp
= (struct host
*) hash_NextEntry(nmhashtable
)) {
121 report(LOG_INFO
, "dumped %d entries to \"%s\".", n
, filename
);
127 * Dump all the available information on the host pointed to by "hp".
128 * The output is sent to the file pointed to by "fp".
132 dump_host(FILE *fp
, struct host
*hp
)
134 /* Print symbols in alphabetical order for reader's convenience. */
136 fprintf(fp
, "%s:", (hp
->hostname
?
137 hp
->hostname
->string
: "?"));
138 if (hp
->flags
.bootfile
) {
139 fprintf(fp
, "\\\n\t:bf=%s:", hp
->bootfile
->string
);
141 if (hp
->flags
.bootsize
) {
142 fprintf(fp
, "\\\n\t:bs=");
143 if (hp
->flags
.bootsize_auto
) {
144 fprintf(fp
, "auto:");
146 fprintf(fp
, "%lu:", (u_long
)hp
->bootsize
);
149 if (hp
->flags
.cookie_server
) {
150 fprintf(fp
, "\\\n\t:cs=");
151 list_ipaddresses(fp
, hp
->cookie_server
);
154 if (hp
->flags
.dump_file
) {
155 fprintf(fp
, "\\\n\t:df=%s:", hp
->dump_file
->string
);
157 if (hp
->flags
.domain_name
) {
158 fprintf(fp
, "\\\n\t:dn=%s:", hp
->domain_name
->string
);
160 if (hp
->flags
.domain_server
) {
161 fprintf(fp
, "\\\n\t:ds=");
162 list_ipaddresses(fp
, hp
->domain_server
);
165 if (hp
->flags
.exten_file
) {
166 fprintf(fp
, "\\\n\t:ef=%s:", hp
->exten_file
->string
);
168 if (hp
->flags
.exec_file
) {
169 fprintf(fp
, "\\\n\t:ex=%s:", hp
->exec_file
->string
);
171 if (hp
->flags
.gateway
) {
172 fprintf(fp
, "\\\n\t:gw=");
173 list_ipaddresses(fp
, hp
->gateway
);
176 /* FdC: swap_server (see below) */
177 if (hp
->flags
.homedir
) {
178 fprintf(fp
, "\\\n\t:hd=%s:", hp
->homedir
->string
);
180 /* FdC: dump_file (see above) */
181 /* FdC: domain_name (see above) */
182 /* FdC: root_path (see below) */
183 if (hp
->flags
.name_switch
&& hp
->flags
.send_name
) {
184 fprintf(fp
, "\\\n\t:hn:");
186 if (hp
->flags
.htype
) {
187 int hlen
= haddrlength(hp
->htype
);
188 fprintf(fp
, "\\\n\t:ht=%u:", (unsigned) hp
->htype
);
189 if (hp
->flags
.haddr
) {
190 fprintf(fp
, "ha=\"%s\":",
191 haddrtoa(hp
->haddr
, hlen
));
194 if (hp
->flags
.impress_server
) {
195 fprintf(fp
, "\\\n\t:im=");
196 list_ipaddresses(fp
, hp
->impress_server
);
199 /* NetBSD: swap_server (see below) */
200 if (hp
->flags
.iaddr
) {
201 fprintf(fp
, "\\\n\t:ip=%s:", inet_ntoa(hp
->iaddr
));
203 if (hp
->flags
.log_server
) {
204 fprintf(fp
, "\\\n\t:lg=");
205 list_ipaddresses(fp
, hp
->log_server
);
208 if (hp
->flags
.lpr_server
) {
209 fprintf(fp
, "\\\n\t:lp=");
210 list_ipaddresses(fp
, hp
->lpr_server
);
213 if (hp
->flags
.msg_size
) {
214 fprintf(fp
, "\\\n\t:ms=%lu:", (u_long
)hp
->msg_size
);
216 if (hp
->flags
.min_wait
) {
217 fprintf(fp
, "\\\n\t:mw=%lu:", (u_long
)hp
->min_wait
);
219 if (hp
->flags
.name_server
) {
220 fprintf(fp
, "\\\n\t:ns=");
221 list_ipaddresses(fp
, hp
->name_server
);
224 if (hp
->flags
.ntp_server
) {
225 fprintf(fp
, "\\\n\t:nt=");
226 list_ipaddresses(fp
, hp
->ntp_server
);
229 if (hp
->flags
.reply_addr
) {
230 fprintf(fp
, "\\\n\t:ra=%s:", inet_ntoa(hp
->reply_addr
));
232 if (hp
->flags
.rlp_server
) {
233 fprintf(fp
, "\\\n\t:rl=");
234 list_ipaddresses(fp
, hp
->rlp_server
);
237 if (hp
->flags
.root_path
) {
238 fprintf(fp
, "\\\n\t:rp=%s:", hp
->root_path
->string
);
240 if (hp
->flags
.bootserver
) {
241 fprintf(fp
, "\\\n\t:sa=%s:", inet_ntoa(hp
->bootserver
));
243 if (hp
->flags
.subnet_mask
) {
244 fprintf(fp
, "\\\n\t:sm=%s:", inet_ntoa(hp
->subnet_mask
));
246 if (hp
->flags
.swap_server
) {
247 fprintf(fp
, "\\\n\t:sw=%s:", inet_ntoa(hp
->subnet_mask
));
249 if (hp
->flags
.tftpdir
) {
250 fprintf(fp
, "\\\n\t:td=%s:", hp
->tftpdir
->string
);
252 /* NetBSD: rootpath (see above) */
253 /* NetBSD: domainname (see above) */
254 /* NetBSD: dumpfile (see above) */
255 if (hp
->flags
.time_offset
) {
256 fprintf(fp
, "\\\n\t:to=%ld:", (long)hp
->time_offset
);
258 if (hp
->flags
.time_server
) {
259 fprintf(fp
, "\\\n\t:ts=");
260 list_ipaddresses(fp
, hp
->time_server
);
263 if (hp
->flags
.vm_cookie
) {
264 fprintf(fp
, "\\\n\t:vm=");
265 if (!bcmp(hp
->vm_cookie
, vm_rfc1048
, 4)) {
266 fprintf(fp
, "rfc1048:");
267 } else if (!bcmp(hp
->vm_cookie
, vm_cmu
, 4)) {
270 fprintf(fp
, "%d.%d.%d.%d:",
271 (int) ((hp
->vm_cookie
)[0]),
272 (int) ((hp
->vm_cookie
)[1]),
273 (int) ((hp
->vm_cookie
)[2]),
274 (int) ((hp
->vm_cookie
)[3]));
277 if (hp
->flags
.nis_domain
) {
278 fprintf(fp
, "\\\n\t:yd=%s:",
279 hp
->nis_domain
->string
);
281 if (hp
->flags
.nis_server
) {
282 fprintf(fp
, "\\\n\t:ys=");
283 list_ipaddresses(fp
, hp
->nis_server
);
287 * XXX - Add new tags here (or above,
288 * so they print in alphabetical order).
291 if (hp
->flags
.generic
) {
292 dump_generic(fp
, hp
->generic
);
299 dump_generic(FILE *fp
, struct shared_bindata
*generic
)
301 u_char
*bp
= generic
->data
;
302 u_char
*ep
= bp
+ generic
->length
;
314 fprintf(fp
, " #junk in generic! :");
317 fprintf(fp
, "\\\n\t:T%d=", tag
);
319 fprintf(fp
, "%02X", *bp
);
332 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
334 * The addresses are printed in standard ASCII "dot" notation and separated
335 * from one another by a single space. A single leading space is also
336 * printed before the first adddress.
338 * Null lists produce no output (and no error).
342 list_ipaddresses(FILE *fp
, struct in_addr_list
*ipptr
)
345 struct in_addr
*addrptr
;
348 count
= ipptr
->addrcount
;
349 addrptr
= ipptr
->addr
;
351 fprintf(fp
, "%s", inet_ntoa(*addrptr
++));
365 * c-argdecl-indent: 4
366 * c-continued-statement-offset: 4
367 * c-continued-brace-offset: -4