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"
32 static void dump_generic(FILE *, struct shared_bindata
*);
33 static void dump_host(FILE *, struct host
*);
34 static void list_ipaddresses(FILE *, struct in_addr_list
*);
39 dumptab(char *filename
)
41 report(LOG_INFO
, "No dumptab support!");
47 * Dump the internal memory database to bootpd_dump.
51 dumptab(char *filename
)
57 /* Print symbols in alphabetical order for reader's convenience. */
58 static char legend
[] = "#\n# Legend:\t(see bootptab.5)\n\
59 #\tfirst field -- hostname (not indented)\n\
61 #\tbs -- bootfile size in 512-octet blocks\n\
62 #\tcs -- cookie servers\n\
63 #\tdf -- dump file name\n\
64 #\tdn -- domain name\n\
65 #\tds -- domain name servers\n\
66 #\tef -- extension file\n\
67 #\tex -- exec file (YORK_EX_OPTION)\n\
69 #\tha -- hardware address\n\
70 #\thd -- home directory for bootfiles\n\
71 #\thn -- host name set for client\n\
72 #\tht -- hardware type\n\
73 #\tim -- impress servers\n\
74 #\tip -- host IP address\n\
75 #\tlg -- log servers\n\
76 #\tlp -- LPR servers\n\
77 #\tms -- message size\n\
78 #\tmw -- min wait (secs)\n\
79 #\tns -- IEN-116 name servers\n\
80 #\tnt -- NTP servers (RFC 1129)\n\
81 #\tra -- reply address override\n\
82 #\trl -- resource location protocol servers\n\
84 #\tsa -- boot server address\n\
85 #\tsm -- subnet mask\n\
86 #\tsw -- swap server\n\
87 #\ttc -- template host (points to similar host entry)\n\
88 #\ttd -- TFTP directory\n\
89 #\tto -- time offset (seconds)\n\
90 #\tts -- time servers\n\
91 #\tvm -- vendor magic number\n\
92 #\tyd -- YP (NIS) domain\n\
93 #\tys -- YP (NIS) servers\n\
94 #\tTn -- generic option tag n\n\
98 * Open bootpd.dump file.
100 if ((fp
= fopen(filename
, "w")) == NULL
) {
101 report(LOG_ERR
, "error opening \"%s\": %s",
102 filename
, get_errmsg());
106 fprintf(fp
, "\n# %s %s.%d\n", progname
, VERSION
, PATCHLEVEL
);
107 fprintf(fp
, "# %s: dump of bootp server database.\n", filename
);
108 fprintf(fp
, "# Dump taken %s", ctime(&t
));
109 fwrite(legend
, 1, sizeof(legend
) - 1, fp
);
112 for (hp
= (struct host
*) hash_FirstEntry(nmhashtable
); hp
!= NULL
;
113 hp
= (struct host
*) hash_NextEntry(nmhashtable
)) {
120 report(LOG_INFO
, "dumped %d entries to \"%s\".", n
, filename
);
126 * Dump all the available information on the host pointed to by "hp".
127 * The output is sent to the file pointed to by "fp".
131 dump_host(FILE *fp
, struct host
*hp
)
133 /* Print symbols in alphabetical order for reader's convenience. */
135 fprintf(fp
, "%s:", (hp
->hostname
?
136 hp
->hostname
->string
: "?"));
137 if (hp
->flags
.bootfile
) {
138 fprintf(fp
, "\\\n\t:bf=%s:", hp
->bootfile
->string
);
140 if (hp
->flags
.bootsize
) {
141 fprintf(fp
, "\\\n\t:bs=");
142 if (hp
->flags
.bootsize_auto
) {
143 fprintf(fp
, "auto:");
145 fprintf(fp
, "%lu:", (u_long
)hp
->bootsize
);
148 if (hp
->flags
.cookie_server
) {
149 fprintf(fp
, "\\\n\t:cs=");
150 list_ipaddresses(fp
, hp
->cookie_server
);
153 if (hp
->flags
.dump_file
) {
154 fprintf(fp
, "\\\n\t:df=%s:", hp
->dump_file
->string
);
156 if (hp
->flags
.domain_name
) {
157 fprintf(fp
, "\\\n\t:dn=%s:", hp
->domain_name
->string
);
159 if (hp
->flags
.domain_server
) {
160 fprintf(fp
, "\\\n\t:ds=");
161 list_ipaddresses(fp
, hp
->domain_server
);
164 if (hp
->flags
.exten_file
) {
165 fprintf(fp
, "\\\n\t:ef=%s:", hp
->exten_file
->string
);
167 if (hp
->flags
.exec_file
) {
168 fprintf(fp
, "\\\n\t:ex=%s:", hp
->exec_file
->string
);
170 if (hp
->flags
.gateway
) {
171 fprintf(fp
, "\\\n\t:gw=");
172 list_ipaddresses(fp
, hp
->gateway
);
175 /* FdC: swap_server (see below) */
176 if (hp
->flags
.homedir
) {
177 fprintf(fp
, "\\\n\t:hd=%s:", hp
->homedir
->string
);
179 /* FdC: dump_file (see above) */
180 /* FdC: domain_name (see above) */
181 /* FdC: root_path (see below) */
182 if (hp
->flags
.name_switch
&& hp
->flags
.send_name
) {
183 fprintf(fp
, "\\\n\t:hn:");
185 if (hp
->flags
.htype
) {
186 int hlen
= haddrlength(hp
->htype
);
187 fprintf(fp
, "\\\n\t:ht=%u:", (unsigned) hp
->htype
);
188 if (hp
->flags
.haddr
) {
189 fprintf(fp
, "ha=\"%s\":",
190 haddrtoa(hp
->haddr
, hlen
));
193 if (hp
->flags
.impress_server
) {
194 fprintf(fp
, "\\\n\t:im=");
195 list_ipaddresses(fp
, hp
->impress_server
);
198 /* NetBSD: swap_server (see below) */
199 if (hp
->flags
.iaddr
) {
200 fprintf(fp
, "\\\n\t:ip=%s:", inet_ntoa(hp
->iaddr
));
202 if (hp
->flags
.log_server
) {
203 fprintf(fp
, "\\\n\t:lg=");
204 list_ipaddresses(fp
, hp
->log_server
);
207 if (hp
->flags
.lpr_server
) {
208 fprintf(fp
, "\\\n\t:lp=");
209 list_ipaddresses(fp
, hp
->lpr_server
);
212 if (hp
->flags
.msg_size
) {
213 fprintf(fp
, "\\\n\t:ms=%lu:", (u_long
)hp
->msg_size
);
215 if (hp
->flags
.min_wait
) {
216 fprintf(fp
, "\\\n\t:mw=%lu:", (u_long
)hp
->min_wait
);
218 if (hp
->flags
.name_server
) {
219 fprintf(fp
, "\\\n\t:ns=");
220 list_ipaddresses(fp
, hp
->name_server
);
223 if (hp
->flags
.ntp_server
) {
224 fprintf(fp
, "\\\n\t:nt=");
225 list_ipaddresses(fp
, hp
->ntp_server
);
228 if (hp
->flags
.reply_addr
) {
229 fprintf(fp
, "\\\n\t:ra=%s:", inet_ntoa(hp
->reply_addr
));
231 if (hp
->flags
.rlp_server
) {
232 fprintf(fp
, "\\\n\t:rl=");
233 list_ipaddresses(fp
, hp
->rlp_server
);
236 if (hp
->flags
.root_path
) {
237 fprintf(fp
, "\\\n\t:rp=%s:", hp
->root_path
->string
);
239 if (hp
->flags
.bootserver
) {
240 fprintf(fp
, "\\\n\t:sa=%s:", inet_ntoa(hp
->bootserver
));
242 if (hp
->flags
.subnet_mask
) {
243 fprintf(fp
, "\\\n\t:sm=%s:", inet_ntoa(hp
->subnet_mask
));
245 if (hp
->flags
.swap_server
) {
246 fprintf(fp
, "\\\n\t:sw=%s:", inet_ntoa(hp
->subnet_mask
));
248 if (hp
->flags
.tftpdir
) {
249 fprintf(fp
, "\\\n\t:td=%s:", hp
->tftpdir
->string
);
251 /* NetBSD: rootpath (see above) */
252 /* NetBSD: domainname (see above) */
253 /* NetBSD: dumpfile (see above) */
254 if (hp
->flags
.time_offset
) {
255 fprintf(fp
, "\\\n\t:to=%ld:", (long)hp
->time_offset
);
257 if (hp
->flags
.time_server
) {
258 fprintf(fp
, "\\\n\t:ts=");
259 list_ipaddresses(fp
, hp
->time_server
);
262 if (hp
->flags
.vm_cookie
) {
263 fprintf(fp
, "\\\n\t:vm=");
264 if (!bcmp(hp
->vm_cookie
, vm_rfc1048
, 4)) {
265 fprintf(fp
, "rfc1048:");
266 } else if (!bcmp(hp
->vm_cookie
, vm_cmu
, 4)) {
269 fprintf(fp
, "%d.%d.%d.%d:",
270 (int) ((hp
->vm_cookie
)[0]),
271 (int) ((hp
->vm_cookie
)[1]),
272 (int) ((hp
->vm_cookie
)[2]),
273 (int) ((hp
->vm_cookie
)[3]));
276 if (hp
->flags
.nis_domain
) {
277 fprintf(fp
, "\\\n\t:yd=%s:",
278 hp
->nis_domain
->string
);
280 if (hp
->flags
.nis_server
) {
281 fprintf(fp
, "\\\n\t:ys=");
282 list_ipaddresses(fp
, hp
->nis_server
);
286 * XXX - Add new tags here (or above,
287 * so they print in alphabetical order).
290 if (hp
->flags
.generic
) {
291 dump_generic(fp
, hp
->generic
);
298 dump_generic(FILE *fp
, struct shared_bindata
*generic
)
300 u_char
*bp
= generic
->data
;
301 u_char
*ep
= bp
+ generic
->length
;
313 fprintf(fp
, " #junk in generic! :");
316 fprintf(fp
, "\\\n\t:T%d=", tag
);
318 fprintf(fp
, "%02X", *bp
);
331 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
333 * The addresses are printed in standard ASCII "dot" notation and separated
334 * from one another by a single space. A single leading space is also
335 * printed before the first adddress.
337 * Null lists produce no output (and no error).
341 list_ipaddresses(FILE *fp
, struct in_addr_list
*ipptr
)
344 struct in_addr
*addrptr
;
347 count
= ipptr
->addrcount
;
348 addrptr
= ipptr
->addr
;
350 fprintf(fp
, "%s", inet_ntoa(*addrptr
++));