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"
39 static void dump_generic
P((FILE *, struct shared_bindata
*));
40 static void dump_host
P((FILE *, struct host
*));
41 static void list_ipaddresses
P((FILE *, struct in_addr_list
*));
51 report(LOG_INFO
, "No dumptab support!");
57 * Dump the internal memory database to bootpd_dump.
68 /* Print symbols in alphabetical order for reader's convenience. */
69 static char legend
[] = "#\n# Legend:\t(see bootptab.5)\n\
70 #\tfirst field -- hostname (not indented)\n\
72 #\tbs -- bootfile size in 512-octet blocks\n\
73 #\tcs -- cookie servers\n\
74 #\tdf -- dump file name\n\
75 #\tdn -- domain name\n\
76 #\tds -- domain name servers\n\
77 #\tef -- extension file\n\
78 #\tex -- exec file (YORK_EX_OPTION)\n\
80 #\tha -- hardware address\n\
81 #\thd -- home directory for bootfiles\n\
82 #\thn -- host name set for client\n\
83 #\tht -- hardware type\n\
84 #\tim -- impress servers\n\
85 #\tip -- host IP address\n\
86 #\tlg -- log servers\n\
87 #\tlp -- LPR servers\n\
88 #\tms -- message size\n\
89 #\tmw -- min wait (secs)\n\
90 #\tns -- IEN-116 name servers\n\
91 #\tnt -- NTP servers (RFC 1129)\n\
92 #\tra -- reply address override\n\
93 #\trl -- resource location protocol servers\n\
95 #\tsa -- boot server address\n\
96 #\tsm -- subnet mask\n\
97 #\tsw -- swap server\n\
98 #\ttc -- template host (points to similar host entry)\n\
99 #\ttd -- TFTP directory\n\
100 #\tto -- time offset (seconds)\n\
101 #\tts -- time servers\n\
102 #\tvm -- vendor magic number\n\
103 #\tyd -- YP (NIS) domain\n\
104 #\tys -- YP (NIS) servers\n\
105 #\tTn -- generic option tag n\n\
109 * Open bootpd.dump file.
111 if ((fp
= fopen(filename
, "w")) == NULL
) {
112 report(LOG_ERR
, "error opening \"%s\": %s",
113 filename
, get_errmsg());
117 fprintf(fp
, "\n# %s %s.%d\n", progname
, VERSION
, PATCHLEVEL
);
118 fprintf(fp
, "# %s: dump of bootp server database.\n", filename
);
119 fprintf(fp
, "# Dump taken %s", ctime(&t
));
120 fwrite(legend
, 1, sizeof(legend
) - 1, fp
);
123 for (hp
= (struct host
*) hash_FirstEntry(nmhashtable
); hp
!= NULL
;
124 hp
= (struct host
*) hash_NextEntry(nmhashtable
)) {
131 report(LOG_INFO
, "dumped %d entries to \"%s\".", n
, filename
);
137 * Dump all the available information on the host pointed to by "hp".
138 * The output is sent to the file pointed to by "fp".
146 /* Print symbols in alphabetical order for reader's convenience. */
148 fprintf(fp
, "%s:", (hp
->hostname
?
149 hp
->hostname
->string
: "?"));
150 if (hp
->flags
.bootfile
) {
151 fprintf(fp
, "\\\n\t:bf=%s:", hp
->bootfile
->string
);
153 if (hp
->flags
.bootsize
) {
154 fprintf(fp
, "\\\n\t:bs=");
155 if (hp
->flags
.bootsize_auto
) {
156 fprintf(fp
, "auto:");
158 fprintf(fp
, "%lu:", (u_long
)hp
->bootsize
);
161 if (hp
->flags
.cookie_server
) {
162 fprintf(fp
, "\\\n\t:cs=");
163 list_ipaddresses(fp
, hp
->cookie_server
);
166 if (hp
->flags
.dump_file
) {
167 fprintf(fp
, "\\\n\t:df=%s:", hp
->dump_file
->string
);
169 if (hp
->flags
.domain_name
) {
170 fprintf(fp
, "\\\n\t:dn=%s:", hp
->domain_name
->string
);
172 if (hp
->flags
.domain_server
) {
173 fprintf(fp
, "\\\n\t:ds=");
174 list_ipaddresses(fp
, hp
->domain_server
);
177 if (hp
->flags
.exten_file
) {
178 fprintf(fp
, "\\\n\t:ef=%s:", hp
->exten_file
->string
);
180 if (hp
->flags
.exec_file
) {
181 fprintf(fp
, "\\\n\t:ex=%s:", hp
->exec_file
->string
);
183 if (hp
->flags
.gateway
) {
184 fprintf(fp
, "\\\n\t:gw=");
185 list_ipaddresses(fp
, hp
->gateway
);
188 /* FdC: swap_server (see below) */
189 if (hp
->flags
.homedir
) {
190 fprintf(fp
, "\\\n\t:hd=%s:", hp
->homedir
->string
);
192 /* FdC: dump_file (see above) */
193 /* FdC: domain_name (see above) */
194 /* FdC: root_path (see below) */
195 if (hp
->flags
.name_switch
&& hp
->flags
.send_name
) {
196 fprintf(fp
, "\\\n\t:hn:");
198 if (hp
->flags
.htype
) {
199 int hlen
= haddrlength(hp
->htype
);
200 fprintf(fp
, "\\\n\t:ht=%u:", (unsigned) hp
->htype
);
201 if (hp
->flags
.haddr
) {
202 fprintf(fp
, "ha=\"%s\":",
203 haddrtoa(hp
->haddr
, hlen
));
206 if (hp
->flags
.impress_server
) {
207 fprintf(fp
, "\\\n\t:im=");
208 list_ipaddresses(fp
, hp
->impress_server
);
211 /* NetBSD: swap_server (see below) */
212 if (hp
->flags
.iaddr
) {
213 fprintf(fp
, "\\\n\t:ip=%s:", inet_ntoa(hp
->iaddr
));
215 if (hp
->flags
.log_server
) {
216 fprintf(fp
, "\\\n\t:lg=");
217 list_ipaddresses(fp
, hp
->log_server
);
220 if (hp
->flags
.lpr_server
) {
221 fprintf(fp
, "\\\n\t:lp=");
222 list_ipaddresses(fp
, hp
->lpr_server
);
225 if (hp
->flags
.msg_size
) {
226 fprintf(fp
, "\\\n\t:ms=%lu:", (u_long
)hp
->msg_size
);
228 if (hp
->flags
.min_wait
) {
229 fprintf(fp
, "\\\n\t:mw=%lu:", (u_long
)hp
->min_wait
);
231 if (hp
->flags
.name_server
) {
232 fprintf(fp
, "\\\n\t:ns=");
233 list_ipaddresses(fp
, hp
->name_server
);
236 if (hp
->flags
.ntp_server
) {
237 fprintf(fp
, "\\\n\t:nt=");
238 list_ipaddresses(fp
, hp
->ntp_server
);
241 if (hp
->flags
.reply_addr
) {
242 fprintf(fp
, "\\\n\t:ra=%s:", inet_ntoa(hp
->reply_addr
));
244 if (hp
->flags
.rlp_server
) {
245 fprintf(fp
, "\\\n\t:rl=");
246 list_ipaddresses(fp
, hp
->rlp_server
);
249 if (hp
->flags
.root_path
) {
250 fprintf(fp
, "\\\n\t:rp=%s:", hp
->root_path
->string
);
252 if (hp
->flags
.bootserver
) {
253 fprintf(fp
, "\\\n\t:sa=%s:", inet_ntoa(hp
->bootserver
));
255 if (hp
->flags
.subnet_mask
) {
256 fprintf(fp
, "\\\n\t:sm=%s:", inet_ntoa(hp
->subnet_mask
));
258 if (hp
->flags
.swap_server
) {
259 fprintf(fp
, "\\\n\t:sw=%s:", inet_ntoa(hp
->subnet_mask
));
261 if (hp
->flags
.tftpdir
) {
262 fprintf(fp
, "\\\n\t:td=%s:", hp
->tftpdir
->string
);
264 /* NetBSD: rootpath (see above) */
265 /* NetBSD: domainname (see above) */
266 /* NetBSD: dumpfile (see above) */
267 if (hp
->flags
.time_offset
) {
268 fprintf(fp
, "\\\n\t:to=%ld:", (long)hp
->time_offset
);
270 if (hp
->flags
.time_server
) {
271 fprintf(fp
, "\\\n\t:ts=");
272 list_ipaddresses(fp
, hp
->time_server
);
275 if (hp
->flags
.vm_cookie
) {
276 fprintf(fp
, "\\\n\t:vm=");
277 if (!bcmp(hp
->vm_cookie
, vm_rfc1048
, 4)) {
278 fprintf(fp
, "rfc1048:");
279 } else if (!bcmp(hp
->vm_cookie
, vm_cmu
, 4)) {
282 fprintf(fp
, "%d.%d.%d.%d:",
283 (int) ((hp
->vm_cookie
)[0]),
284 (int) ((hp
->vm_cookie
)[1]),
285 (int) ((hp
->vm_cookie
)[2]),
286 (int) ((hp
->vm_cookie
)[3]));
289 if (hp
->flags
.nis_domain
) {
290 fprintf(fp
, "\\\n\t:yd=%s:",
291 hp
->nis_domain
->string
);
293 if (hp
->flags
.nis_server
) {
294 fprintf(fp
, "\\\n\t:ys=");
295 list_ipaddresses(fp
, hp
->nis_server
);
299 * XXX - Add new tags here (or above,
300 * so they print in alphabetical order).
303 if (hp
->flags
.generic
) {
304 dump_generic(fp
, hp
->generic
);
311 dump_generic(fp
, generic
)
313 struct shared_bindata
*generic
;
315 u_char
*bp
= generic
->data
;
316 u_char
*ep
= bp
+ generic
->length
;
328 fprintf(fp
, " #junk in generic! :");
331 fprintf(fp
, "\\\n\t:T%d=", tag
);
333 fprintf(fp
, "%02X", *bp
);
346 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
348 * The addresses are printed in standard ASCII "dot" notation and separated
349 * from one another by a single space. A single leading space is also
350 * printed before the first adddress.
352 * Null lists produce no output (and no error).
356 list_ipaddresses(fp
, ipptr
)
358 struct in_addr_list
*ipptr
;
361 struct in_addr
*addrptr
;
364 count
= ipptr
->addrcount
;
365 addrptr
= ipptr
->addr
;
367 fprintf(fp
, "%s", inet_ntoa(*addrptr
++));
381 * c-argdecl-indent: 4
382 * c-continued-statement-offset: 4
383 * c-continued-brace-offset: -4