1 /* $NetBSD: dumptab.c,v 1.8 2007/05/27 16:31:42 tls Exp $ */
5 __RCSID("$NetBSD: dumptab.c,v 1.8 2007/05/27 16:31:42 tls Exp $");
9 * dumptab.c - handles dumping the database
12 #include <sys/types.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h> /* inet_ntoa */
26 #include "patchlevel.h"
29 static void dump_generic(FILE *, struct shared_bindata
*);
30 static void dump_host(FILE *, struct host
*);
31 static void list_ipaddresses(FILE *, struct in_addr_list
*);
32 void dumptab(const char *);
36 dumptab(const char *filename
)
38 report(LOG_INFO
, "No dumptab support!");
44 * Dump the internal memory database to bootpd_dump.
48 dumptab(const char *filename
)
54 /* Print symbols in alphabetical order for reader's convenience. */
55 static char legend
[] = "#\n# Legend:\t(see bootptab.5)\n\
56 #\tfirst field -- hostname (not indented)\n\
58 #\tbs -- bootfile size in 512-octet blocks\n\
59 #\tcs -- cookie servers\n\
60 #\tdf -- dump file name\n\
61 #\tdn -- domain name\n\
62 #\tds -- domain name servers\n\
63 #\tef -- extension file\n\
64 #\tex -- exec file (YORK_EX_OPTION)\n\
66 #\tha -- hardware address\n\
67 #\thd -- home directory for bootfiles\n\
68 #\thn -- host name set for client\n\
69 #\tht -- hardware type\n\
70 #\tim -- impress servers\n\
71 #\tip -- host IP address\n\
72 #\tlg -- log servers\n\
73 #\tlp -- LPR servers\n\
74 #\tms -- message size\n\
75 #\tmw -- min wait (secs)\n\
76 #\tns -- IEN-116 name servers\n\
77 #\tnt -- NTP servers (RFC 1129)\n\
78 #\tra -- reply address override\n\
79 #\trl -- resource location protocol servers\n\
81 #\tsa -- boot server address\n\
82 #\tsm -- subnet mask\n\
83 #\tsw -- swap server\n\
84 #\ttc -- template host (points to similar host entry)\n\
85 #\ttd -- TFTP directory\n\
86 #\tto -- time offset (seconds)\n\
87 #\tts -- time servers\n\
88 #\tvm -- vendor magic number\n\
89 #\tyd -- YP (NIS) domain\n\
90 #\tys -- YP (NIS) servers\n\
91 #\tTn -- generic option tag n\n\
95 * Open bootpd.dump file.
97 if ((fp
= fopen(filename
, "w")) == NULL
) {
98 report(LOG_ERR
, "error opening \"%s\": %s",
99 filename
, get_errmsg());
103 fprintf(fp
, "\n# %s %s.%d\n", progname
, VERSION
, PATCHLEVEL
);
104 fprintf(fp
, "# %s: dump of bootp server database.\n", filename
);
105 fprintf(fp
, "# Dump taken %s", ctime(&t
));
106 fwrite(legend
, 1, sizeof(legend
) - 1, fp
);
109 for (hp
= (struct host
*) hash_FirstEntry(nmhashtable
); hp
!= NULL
;
110 hp
= (struct host
*) hash_NextEntry(nmhashtable
)) {
117 report(LOG_INFO
, "dumped %d entries to \"%s\".", n
, filename
);
123 * Dump all the available information on the host pointed to by "hp".
124 * The output is sent to the file pointed to by "fp".
128 dump_host(FILE *fp
, struct host
*hp
)
130 /* Print symbols in alphabetical order for reader's convenience. */
132 fprintf(fp
, "%s:", (hp
->hostname
?
133 hp
->hostname
->string
: "?"));
134 if (hp
->flags
.bootfile
) {
135 fprintf(fp
, "\\\n\t:bf=%s:", hp
->bootfile
->string
);
137 if (hp
->flags
.bootsize
) {
138 fprintf(fp
, "\\\n\t:bs=");
139 if (hp
->flags
.bootsize_auto
) {
140 fprintf(fp
, "auto:");
142 fprintf(fp
, "%d:", hp
->bootsize
);
145 if (hp
->flags
.cookie_server
) {
146 fprintf(fp
, "\\\n\t:cs=");
147 list_ipaddresses(fp
, hp
->cookie_server
);
150 if (hp
->flags
.dump_file
) {
151 fprintf(fp
, "\\\n\t:df=%s:", hp
->dump_file
->string
);
153 if (hp
->flags
.domain_name
) {
154 fprintf(fp
, "\\\n\t:dn=%s:", hp
->domain_name
->string
);
156 if (hp
->flags
.domain_server
) {
157 fprintf(fp
, "\\\n\t:ds=");
158 list_ipaddresses(fp
, hp
->domain_server
);
161 if (hp
->flags
.exten_file
) {
162 fprintf(fp
, "\\\n\t:ef=%s:", hp
->exten_file
->string
);
164 if (hp
->flags
.exec_file
) {
165 fprintf(fp
, "\\\n\t:ex=%s:", hp
->exec_file
->string
);
167 if (hp
->flags
.gateway
) {
168 fprintf(fp
, "\\\n\t:gw=");
169 list_ipaddresses(fp
, hp
->gateway
);
172 /* FdC: swap_server (see below) */
173 if (hp
->flags
.homedir
) {
174 fprintf(fp
, "\\\n\t:hd=%s:", hp
->homedir
->string
);
176 /* FdC: dump_file (see above) */
177 /* FdC: domain_name (see above) */
178 /* FdC: root_path (see below) */
179 if (hp
->flags
.name_switch
&& hp
->flags
.send_name
) {
180 fprintf(fp
, "\\\n\t:hn:");
182 if (hp
->flags
.htype
) {
183 int hlen
= haddrlength(hp
->htype
);
184 fprintf(fp
, "\\\n\t:ht=%u:", (unsigned) hp
->htype
);
185 if (hp
->flags
.haddr
) {
186 fprintf(fp
, "ha=\"%s\":",
187 haddrtoa(hp
->haddr
, hlen
));
190 if (hp
->flags
.impress_server
) {
191 fprintf(fp
, "\\\n\t:im=");
192 list_ipaddresses(fp
, hp
->impress_server
);
195 /* NetBSD: swap_server (see below) */
196 if (hp
->flags
.iaddr
) {
197 fprintf(fp
, "\\\n\t:ip=%s:", inet_ntoa(hp
->iaddr
));
199 if (hp
->flags
.log_server
) {
200 fprintf(fp
, "\\\n\t:lg=");
201 list_ipaddresses(fp
, hp
->log_server
);
204 if (hp
->flags
.lpr_server
) {
205 fprintf(fp
, "\\\n\t:lp=");
206 list_ipaddresses(fp
, hp
->lpr_server
);
209 if (hp
->flags
.msg_size
) {
210 fprintf(fp
, "\\\n\t:ms=%d:", hp
->msg_size
);
212 if (hp
->flags
.min_wait
) {
213 fprintf(fp
, "\\\n\t:mw=%d:", hp
->min_wait
);
215 if (hp
->flags
.name_server
) {
216 fprintf(fp
, "\\\n\t:ns=");
217 list_ipaddresses(fp
, hp
->name_server
);
220 if (hp
->flags
.ntp_server
) {
221 fprintf(fp
, "\\\n\t:nt=");
222 list_ipaddresses(fp
, hp
->ntp_server
);
225 if (hp
->flags
.reply_addr
) {
226 fprintf(fp
, "\\\n\t:ra=%s:", inet_ntoa(hp
->reply_addr
));
228 if (hp
->flags
.rlp_server
) {
229 fprintf(fp
, "\\\n\t:rl=");
230 list_ipaddresses(fp
, hp
->rlp_server
);
233 if (hp
->flags
.root_path
) {
234 fprintf(fp
, "\\\n\t:rp=%s:", hp
->root_path
->string
);
236 if (hp
->flags
.bootserver
) {
237 fprintf(fp
, "\\\n\t:sa=%s:", inet_ntoa(hp
->bootserver
));
239 if (hp
->flags
.subnet_mask
) {
240 fprintf(fp
, "\\\n\t:sm=%s:", inet_ntoa(hp
->subnet_mask
));
242 if (hp
->flags
.swap_server
) {
243 fprintf(fp
, "\\\n\t:sw=%s:", inet_ntoa(hp
->subnet_mask
));
245 if (hp
->flags
.tftpdir
) {
246 fprintf(fp
, "\\\n\t:td=%s:", hp
->tftpdir
->string
);
248 /* NetBSD: rootpath (see above) */
249 /* NetBSD: domainname (see above) */
250 /* NetBSD: dumpfile (see above) */
251 if (hp
->flags
.time_offset
) {
252 fprintf(fp
, "\\\n\t:to=%ld:", (long)hp
->time_offset
);
254 if (hp
->flags
.time_server
) {
255 fprintf(fp
, "\\\n\t:ts=");
256 list_ipaddresses(fp
, hp
->time_server
);
259 if (hp
->flags
.vm_cookie
) {
260 fprintf(fp
, "\\\n\t:vm=");
261 if (!bcmp(hp
->vm_cookie
, vm_rfc1048
, 4)) {
262 fprintf(fp
, "rfc1048:");
263 } else if (!bcmp(hp
->vm_cookie
, vm_cmu
, 4)) {
266 fprintf(fp
, "%d.%d.%d.%d:",
267 (int) ((hp
->vm_cookie
)[0]),
268 (int) ((hp
->vm_cookie
)[1]),
269 (int) ((hp
->vm_cookie
)[2]),
270 (int) ((hp
->vm_cookie
)[3]));
273 if (hp
->flags
.nis_domain
) {
274 fprintf(fp
, "\\\n\t:yd=%s:",
275 hp
->nis_domain
->string
);
277 if (hp
->flags
.nis_server
) {
278 fprintf(fp
, "\\\n\t:ys=");
279 list_ipaddresses(fp
, hp
->nis_server
);
283 * XXX - Add new tags here (or above,
284 * so they print in alphabetical order).
287 if (hp
->flags
.generic
) {
288 dump_generic(fp
, hp
->generic
);
295 dump_generic(FILE *fp
, struct shared_bindata
*generic
)
297 u_char
*bp
= generic
->data
;
298 u_char
*ep
= bp
+ generic
->length
;
310 fprintf(fp
, " #junk in generic! :");
313 fprintf(fp
, "\\\n\t:T%d=", tag
);
315 fprintf(fp
, "%02X", *bp
);
328 * Dump an entire struct in_addr_list of IP addresses to the indicated file.
330 * The addresses are printed in standard ASCII "dot" notation and separated
331 * from one another by a single space. A single leading space is also
332 * printed before the first address.
334 * Null lists produce no output (and no error).
338 list_ipaddresses(FILE *fp
, struct in_addr_list
*ipptr
)
341 struct in_addr
*addrptr
;
344 count
= ipptr
->addrcount
;
345 addrptr
= ipptr
->addr
;
347 fprintf(fp
, "%s", inet_ntoa(*addrptr
++));
361 * c-argdecl-indent: 4
362 * c-continued-statement-offset: 4
363 * c-continued-brace-offset: -4