1 /************************************************************************
2 Copyright 1988, 1991 by Carnegie Mellon University
6 Permission to use, copy, modify, and distribute this software and its
7 documentation for any purpose and without fee is hereby granted, provided
8 that the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation, and that the name of Carnegie Mellon University not be used
11 in advertising or publicity pertaining to distribution of the software
12 without specific, written prior permission.
14 CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
15 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
16 IN NO EVENT SHALL CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
17 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
18 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
22 $FreeBSD: src/libexec/bootpd/readfile.c,v 1.6.2.2 2001/10/14 21:25:02 iedowse Exp $
23 $DragonFly: src/libexec/bootpd/readfile.c,v 1.2 2003/06/17 04:27:07 dillon Exp $
25 ************************************************************************/
28 * bootpd configuration file reading code.
30 * The routines in this file deal with reading, interpreting, and storing
31 * the information found in the bootpd configuration file (usually
36 #include <sys/errno.h>
37 #include <sys/types.h>
41 #include <netinet/in.h>
52 /* Yes, memcpy is OK here (no overlapped copies). */
53 #define bcopy(a,b,c) memcpy(b,a,c)
54 #define bzero(p,l) memset(p,0,l)
55 #define bcmp(a,b,c) memcmp(a,b,c)
67 #define HASHTABLESIZE 257 /* Hash table size (prime) */
69 /* Non-standard hardware address type (see bootp.h) */
70 #define HTYPE_DIRECT 0
72 /* Error codes returned by eval_symbol: */
74 #define E_END_OF_ENTRY (-1)
75 #define E_SYNTAX_ERROR (-2)
76 #define E_UNKNOWN_SYMBOL (-3)
77 #define E_BAD_IPADDR (-4)
78 #define E_BAD_HWADDR (-5)
79 #define E_BAD_LONGWORD (-6)
80 #define E_BAD_HWATYPE (-7)
81 #define E_BAD_PATHNAME (-8)
82 #define E_BAD_VALUE (-9)
86 #define SYM_BOOTFILE 1
87 #define SYM_COOKIE_SERVER 2
88 #define SYM_DOMAIN_SERVER 3
93 #define SYM_IMPRESS_SERVER 8
95 #define SYM_LOG_SERVER 10
96 #define SYM_LPR_SERVER 11
97 #define SYM_NAME_SERVER 12
98 #define SYM_RLP_SERVER 13
99 #define SYM_SUBNET_MASK 14
100 #define SYM_TIME_OFFSET 15
101 #define SYM_TIME_SERVER 16
102 #define SYM_VENDOR_MAGIC 17
103 #define SYM_SIMILAR_ENTRY 18
104 #define SYM_NAME_SWITCH 19
105 #define SYM_BOOTSIZE 20
106 #define SYM_BOOT_SERVER 22
107 #define SYM_TFTPDIR 23
108 #define SYM_DUMP_FILE 24
109 #define SYM_DOMAIN_NAME 25
110 #define SYM_SWAP_SERVER 26
111 #define SYM_ROOT_PATH 27
112 #define SYM_EXTEN_FILE 28
113 #define SYM_REPLY_ADDR 29
114 #define SYM_NIS_DOMAIN 30 /* RFC 1533 */
115 #define SYM_NIS_SERVER 31 /* RFC 1533 */
116 #define SYM_NTP_SERVER 32 /* RFC 1533 */
117 #define SYM_EXEC_FILE 33 /* YORK_EX_OPTION */
118 #define SYM_MSG_SIZE 34
119 #define SYM_MIN_WAIT 35
120 /* XXX - Add new tags here */
122 #define OP_ADDITION 1 /* Operations on tags */
123 #define OP_DELETION 2
126 #define MAXINADDRS 16 /* Max size of an IP address list */
127 #define MAXBUFLEN 256 /* Max temp buffer space */
128 #define MAXENTRYLEN 2048 /* Max size of an entire entry */
133 * Structure used to map a configuration-file symbol (such as "ds") to a
149 PRIVATE
int nhosts
; /* Number of hosts (/w hw or IP address) */
150 PRIVATE
int nentries
; /* Total number of entries */
151 PRIVATE int32 modtime
= 0; /* Last modification time of bootptab */
152 PRIVATE
char *current_hostname
; /* Name of the current entry. */
153 PRIVATE
char current_tagname
[8];
156 * List of symbolic names used in the bootptab file. The order and actual
157 * values of the symbol codes (SYM_. . .) are unimportant, but they must
161 PRIVATE
struct symbolmap symbol_list
[] = {
162 {"bf", SYM_BOOTFILE
},
163 {"bs", SYM_BOOTSIZE
},
164 {"cs", SYM_COOKIE_SERVER
},
165 {"df", SYM_DUMP_FILE
},
166 {"dn", SYM_DOMAIN_NAME
},
167 {"ds", SYM_DOMAIN_SERVER
},
168 {"ef", SYM_EXTEN_FILE
},
169 {"ex", SYM_EXEC_FILE
}, /* YORK_EX_OPTION */
173 {"hn", SYM_NAME_SWITCH
},
175 {"im", SYM_IMPRESS_SERVER
},
177 {"lg", SYM_LOG_SERVER
},
178 {"lp", SYM_LPR_SERVER
},
179 {"ms", SYM_MSG_SIZE
},
180 {"mw", SYM_MIN_WAIT
},
181 {"ns", SYM_NAME_SERVER
},
182 {"nt", SYM_NTP_SERVER
},
183 {"ra", SYM_REPLY_ADDR
},
184 {"rl", SYM_RLP_SERVER
},
185 {"rp", SYM_ROOT_PATH
},
186 {"sa", SYM_BOOT_SERVER
},
187 {"sm", SYM_SUBNET_MASK
},
188 {"sw", SYM_SWAP_SERVER
},
189 {"tc", SYM_SIMILAR_ENTRY
},
191 {"to", SYM_TIME_OFFSET
},
192 {"ts", SYM_TIME_SERVER
},
193 {"vm", SYM_VENDOR_MAGIC
},
194 {"yd", SYM_NIS_DOMAIN
},
195 {"ys", SYM_NIS_SERVER
},
196 /* XXX - Add new tags here */
201 * List of symbolic names for hardware types. Name translates into
202 * hardware type code listed with it. Names must begin with a letter
203 * and must be all lowercase. This is searched linearly, so put
204 * commonly-used entries near the beginning.
207 PRIVATE
struct htypename htnamemap
[] = {
208 {"ethernet", HTYPE_ETHERNET
},
209 {"ethernet3", HTYPE_EXP_ETHERNET
},
210 {"ether", HTYPE_ETHERNET
},
211 {"ether3", HTYPE_EXP_ETHERNET
},
212 {"ieee802", HTYPE_IEEE802
},
213 {"tr", HTYPE_IEEE802
},
214 {"token-ring", HTYPE_IEEE802
},
215 {"pronet", HTYPE_PRONET
},
216 {"chaos", HTYPE_CHAOS
},
217 {"arcnet", HTYPE_ARCNET
},
218 {"ax.25", HTYPE_AX25
},
219 {"direct", HTYPE_DIRECT
},
220 {"serial", HTYPE_DIRECT
},
221 {"slip", HTYPE_DIRECT
},
222 {"ppp", HTYPE_DIRECT
}
228 * Externals and forward declarations.
231 extern boolean
iplookcmp();
232 boolean
nmcmp(hash_datum
*, hash_datum
*);
237 del_string(struct shared_string
*);
239 del_bindata(struct shared_bindata
*);
241 del_iplist(struct in_addr_list
*);
243 eat_whitespace(char **);
245 eval_symbol(char **, struct host
*);
247 fill_defaults(struct host
*, char **);
249 free_host(hash_datum
*);
250 PRIVATE
struct in_addr_list
*
251 get_addresses(char **);
252 PRIVATE
struct shared_string
*
253 get_shared_string(char **);
255 get_string(char **, char *, u_int
*);
261 hwinscmp(hash_datum
*, hash_datum
*);
263 interp_byte(char **, byte
*);
267 nullcmp(hash_datum
*, hash_datum
*);
269 process_entry(struct host
*, char *);
271 process_generic(char **, struct shared_bindata
**, u_int
);
273 prs_haddr(char **, u_int
);
275 prs_inetaddr(char **, u_int32
*);
277 read_entry(FILE *, char *, u_int
*);
283 * Vendor magic cookies for CMU and RFC1048
285 u_char vm_cmu
[4] = VM_CMU
;
286 u_char vm_rfc1048
[4] = VM_RFC1048
;
291 hash_tbl
*hwhashtable
;
292 hash_tbl
*iphashtable
;
293 hash_tbl
*nmhashtable
;
296 * Allocate hash tables for hardware address, ip address, and hostname
297 * (shared by bootpd and bootpef)
302 hwhashtable
= hash_Init(HASHTABLESIZE
);
303 iphashtable
= hash_Init(HASHTABLESIZE
);
304 nmhashtable
= hash_Init(HASHTABLESIZE
);
305 if (!(hwhashtable
&& iphashtable
&& nmhashtable
)) {
306 report(LOG_ERR
, "Unable to allocate hash tables.");
313 * Read bootptab database file. Avoid rereading the file if the
314 * write date hasn't changed since the last time we read it.
323 unsigned hashcode
, buflen
;
324 static char buffer
[MAXENTRYLEN
];
327 * Check the last modification time.
329 if (stat(bootptab
, &st
) < 0) {
330 report(LOG_ERR
, "stat on \"%s\": %s",
331 bootptab
, get_errmsg());
337 strcpy(timestr
, ctime(&(st
.st_mtime
)));
338 /* zap the newline */
340 report(LOG_INFO
, "bootptab mtime: %s",
345 (st
.st_mtime
== modtime
) &&
348 * hasn't been modified or deleted yet.
353 report(LOG_INFO
, "reading %s\"%s\"",
354 (modtime
!= 0L) ? "new " : "",
358 * Open bootptab file.
360 if ((fp
= fopen(bootptab
, "r")) == NULL
) {
361 report(LOG_ERR
, "error opening \"%s\": %s", bootptab
, get_errmsg());
365 * Record file modification time.
367 if (fstat(fileno(fp
), &st
) < 0) {
368 report(LOG_ERR
, "fstat: %s", get_errmsg());
372 modtime
= st
.st_mtime
;
375 * Entirely erase all hash tables.
377 hash_Reset(hwhashtable
, free_host
);
378 hash_Reset(iphashtable
, free_host
);
379 hash_Reset(nmhashtable
, free_host
);
384 buflen
= sizeof(buffer
);
385 read_entry(fp
, buffer
, &buflen
);
386 if (buflen
== 0) { /* More entries? */
389 hp
= (struct host
*) smalloc(sizeof(struct host
));
390 bzero((char *) hp
, sizeof(*hp
));
391 /* the link count it zero */
394 * Get individual info
396 if (process_entry(hp
, buffer
) < 0) {
398 free_host((hash_datum
*) hp
);
402 * If this is not a dummy entry, and the IP or HW
403 * address is not yet set, try to get them here.
404 * Dummy entries have . as first char of name.
406 if (goodname(hp
->hostname
->string
)) {
407 char *hn
= hp
->hostname
->string
;
409 if (hp
->flags
.iaddr
== 0) {
410 if (lookup_ipa(hn
, &value
)) {
411 report(LOG_ERR
, "can not get IP addr for %s", hn
);
412 report(LOG_ERR
, "(dummy names should start with '.')");
414 hp
->iaddr
.s_addr
= value
;
415 hp
->flags
.iaddr
= TRUE
;
418 /* Set default subnet mask. */
419 if (hp
->flags
.subnet_mask
== 0) {
420 if (lookup_netmask(hp
->iaddr
.s_addr
, &value
)) {
421 report(LOG_ERR
, "can not get netmask for %s", hn
);
423 hp
->subnet_mask
.s_addr
= value
;
424 hp
->flags
.subnet_mask
= TRUE
;
428 if (hp
->flags
.iaddr
) {
431 /* Register by HW addr if known. */
432 if (hp
->flags
.htype
&& hp
->flags
.haddr
) {
433 /* We will either insert it or free it. */
435 hashcode
= hash_HashFunction(hp
->haddr
, haddrlength(hp
->htype
));
436 if (hash_Insert(hwhashtable
, hashcode
, hwinscmp
, hp
, hp
) < 0) {
437 report(LOG_NOTICE
, "duplicate %s address: %s",
439 haddrtoa(hp
->haddr
, haddrlength(hp
->htype
)));
440 free_host((hash_datum
*) hp
);
444 /* Register by IP addr if known. */
445 if (hp
->flags
.iaddr
) {
446 hashcode
= hash_HashFunction((u_char
*) & (hp
->iaddr
.s_addr
), 4);
447 if (hash_Insert(iphashtable
, hashcode
, nullcmp
, hp
, hp
) < 0) {
449 "hash_Insert() failed on IP address insertion");
451 /* Just inserted the host struct in a new hash list. */
455 /* Register by Name (always known) */
456 hashcode
= hash_HashFunction((u_char
*) hp
->hostname
->string
,
457 strlen(hp
->hostname
->string
));
458 if (hash_Insert(nmhashtable
, hashcode
, nullcmp
,
459 hp
->hostname
->string
, hp
) < 0) {
461 "hash_Insert() failed on insertion of hostname: \"%s\"",
462 hp
->hostname
->string
);
464 /* Just inserted the host struct in a new hash list. */
473 report(LOG_INFO
, "read %d entries (%d hosts) from \"%s\"",
474 nentries
, nhosts
, bootptab
);
481 * Read an entire host entry from the file pointed to by "fp" and insert it
482 * into the memory pointed to by "buffer". Leading whitespace and comments
483 * starting with "#" are ignored (removed). Backslashes (\) always quote
484 * the next character except that newlines preceded by a backslash cause
485 * line-continuation onto the next line. The entry is terminated by a
486 * newline character which is not preceded by a backslash. Sequences
487 * surrounded by double quotes are taken literally (including newlines, but
490 * The "bufsiz" parameter points to an unsigned int which specifies the
491 * maximum permitted buffer size. Upon return, this value will be replaced
492 * with the actual length of the entry (not including the null terminator).
494 * This code is a little scary. . . . I don't like using gotos in C
495 * either, but I first wrote this as an FSM diagram and gotos seemed like
496 * the easiest way to implement it. Maybe later I'll clean it up.
500 read_entry(FILE *fp
, char *buffer
, unsigned *bufsiz
)
507 * Eat whitespace, blank lines, and comment lines.
512 goto done
; /* Exit if end-of-file */
515 goto top
; /* Skip over whitespace */
518 while (TRUE
) { /* Eat comments after # */
521 goto done
; /* Exit if end-of-file */
524 goto top
; /* Try to read the next line */
528 ungetc(c
, fp
); /* Other character, push it back to reprocess it */
532 * Now we're actually reading a data entry. Get each character and
533 * assemble it into the data buffer, processing special characters like
534 * double quotes (") and backslashes (\).
542 goto done
; /* Exit on EOF or newline */
544 c
= fgetc(fp
); /* Backslash, read a new character */
546 goto done
; /* Exit on EOF */
548 *buffer
++ = c
; /* Store the literal character */
550 if (length
< *bufsiz
- 1) {
556 *buffer
++ = '"'; /* Store double-quote */
558 if (length
>= *bufsiz
- 1) {
561 while (TRUE
) { /* Special quote processing loop */
565 goto done
; /* Exit on EOF . . . */
567 *buffer
++ = '"';/* Store matching quote */
569 if (length
< *bufsiz
- 1) {
570 goto mainloop
; /* And continue main loop */
575 if ((c
= fgetc(fp
)) < 0) { /* Backslash */
576 goto done
; /* EOF. . . .*/
577 } /* else fall through */
579 *buffer
++ = c
; /* Other character, store it */
581 if (length
>= *bufsiz
- 1) {
587 *buffer
++ = c
; /* Store colons */
589 if (length
>= *bufsiz
- 1) {
592 do { /* But remove whitespace after them */
594 if ((c
< 0) || (c
== '\n')) {
597 } while (isspace(c
)); /* Skip whitespace */
599 if (c
== '\\') { /* Backslash quotes next character */
605 goto top
; /* Backslash-newline continuation */
608 /* fall through if "other" character */
610 *buffer
++ = c
; /* Store other characters */
612 if (length
>= *bufsiz
- 1) {
616 goto mainloop
; /* Keep going */
619 *buffer
= '\0'; /* Terminate string */
620 *bufsiz
= length
; /* Tell the caller its length */
626 * Parse out all the various tags and parameters in the host entry pointed
627 * to by "src". Stuff all the data into the appropriate fields of the
628 * host structure pointed to by "host". If there is any problem with the
629 * entry, an error message is reported via report(), no further processing
630 * is done, and -1 is returned. Successful calls return 0.
632 * (Some errors probably shouldn't be so completely fatal. . . .)
636 process_entry(struct host
*host
, char *src
)
641 if (!host
|| *src
== '\0') {
644 host
->hostname
= get_shared_string(&src
);
646 /* Be more liberal for the benefit of dummy tag names. */
647 if (!goodname(host
->hostname
->string
)) {
648 report(LOG_ERR
, "bad hostname: \"%s\"", host
->hostname
->string
);
649 del_string(host
->hostname
);
653 current_hostname
= host
->hostname
->string
;
656 retval
= eval_symbol(&src
, host
);
657 if (retval
== SUCCESS
) {
661 if (retval
== E_END_OF_ENTRY
) {
662 /* The default subnet mask is set in readtab() */
665 /* Some kind of error. */
670 case E_UNKNOWN_SYMBOL
:
671 msg
= "unknown symbol";
674 msg
= "bad INET address";
677 msg
= "bad hardware address";
680 msg
= "bad longword value";
683 msg
= "bad HW address type";
686 msg
= "bad pathname (need leading '/')";
692 msg
= "unknown error";
695 report(LOG_ERR
, "in entry named \"%s\", symbol \"%s\": %s",
696 current_hostname
, current_tagname
, msg
);
703 * Macros for use in the function below:
706 /* Parse one INET address stored directly in MEMBER. */
707 #define PARSE_IA1(MEMBER) do \
709 if (optype == OP_BOOLEAN) \
710 return E_SYNTAX_ERROR; \
711 hp->flags.MEMBER = FALSE; \
712 if (optype == OP_ADDITION) { \
713 if (prs_inetaddr(symbol, &value) < 0) \
714 return E_BAD_IPADDR; \
715 hp->MEMBER.s_addr = value; \
716 hp->flags.MEMBER = TRUE; \
720 /* Parse a list of INET addresses pointed to by MEMBER */
721 #define PARSE_IAL(MEMBER) do \
723 if (optype == OP_BOOLEAN) \
724 return E_SYNTAX_ERROR; \
725 if (hp->flags.MEMBER) { \
726 hp->flags.MEMBER = FALSE; \
727 assert(hp->MEMBER); \
728 del_iplist(hp->MEMBER); \
731 if (optype == OP_ADDITION) { \
732 hp->MEMBER = get_addresses(symbol); \
733 if (hp->MEMBER == NULL) \
734 return E_SYNTAX_ERROR; \
735 hp->flags.MEMBER = TRUE; \
739 /* Parse a shared string pointed to by MEMBER */
740 #define PARSE_STR(MEMBER) do \
742 if (optype == OP_BOOLEAN) \
743 return E_SYNTAX_ERROR; \
744 if (hp->flags.MEMBER) { \
745 hp->flags.MEMBER = FALSE; \
746 assert(hp->MEMBER); \
747 del_string(hp->MEMBER); \
750 if (optype == OP_ADDITION) { \
751 hp->MEMBER = get_shared_string(symbol); \
752 if (hp->MEMBER == NULL) \
753 return E_SYNTAX_ERROR; \
754 hp->flags.MEMBER = TRUE; \
758 /* Parse an unsigned integer value for MEMBER */
759 #define PARSE_UINT(MEMBER) do \
761 if (optype == OP_BOOLEAN) \
762 return E_SYNTAX_ERROR; \
763 hp->flags.MEMBER = FALSE; \
764 if (optype == OP_ADDITION) { \
765 value = get_u_long(symbol); \
766 hp->MEMBER = value; \
767 hp->flags.MEMBER = TRUE; \
772 * Evaluate the two-character tag symbol pointed to by "symbol" and place
773 * the data in the structure pointed to by "hp". The pointer pointed to
774 * by "symbol" is updated to point past the source string (but may not
775 * point to the next tag entry).
777 * Obviously, this need a few more comments. . . .
780 eval_symbol(char **symbol
, struct host
*hp
)
782 char tmpstr
[MAXSTRINGLEN
];
784 struct symbolmap
*symbolptr
;
789 int optype
; /* Indicates boolean, addition, or deletion */
791 eat_whitespace(symbol
);
793 /* Make sure this is set before returning. */
794 current_tagname
[0] = (*symbol
)[0];
795 current_tagname
[1] = (*symbol
)[1];
796 current_tagname
[2] = 0;
798 if ((*symbol
)[0] == '\0') {
799 return E_END_OF_ENTRY
;
801 if ((*symbol
)[0] == ':') {
804 if ((*symbol
)[0] == 'T') { /* generic symbol */
806 value
= get_u_long(symbol
);
807 snprintf(current_tagname
, sizeof(current_tagname
),
809 eat_whitespace(symbol
);
810 if ((*symbol
)[0] != '=') {
811 return E_SYNTAX_ERROR
;
814 if (!(hp
->generic
)) {
815 hp
->generic
= (struct shared_bindata
*)
816 smalloc(sizeof(struct shared_bindata
));
818 if (process_generic(symbol
, &(hp
->generic
), (byte
) (value
& 0xFF)))
819 return E_SYNTAX_ERROR
;
820 hp
->flags
.generic
= TRUE
;
824 * Determine the type of operation to be done on this symbol
826 switch ((*symbol
)[2]) {
828 optype
= OP_ADDITION
;
831 optype
= OP_DELETION
;
838 return E_SYNTAX_ERROR
;
841 symbolptr
= symbol_list
;
842 numsymbols
= sizeof(symbol_list
) / sizeof(struct symbolmap
);
843 for (i
= 0; i
< numsymbols
; i
++) {
844 if (((symbolptr
->symbol
)[0] == (*symbol
)[0]) &&
845 ((symbolptr
->symbol
)[1] == (*symbol
)[1])) {
850 if (i
>= numsymbols
) {
851 return E_UNKNOWN_SYMBOL
;
854 * Skip past the = or @ character (to point to the data) if this
855 * isn't a boolean operation. For boolean operations, just skip
856 * over the two-character tag symbol (and nothing else. . . .).
858 (*symbol
) += (optype
== OP_BOOLEAN
) ? 2 : 3;
860 eat_whitespace(symbol
);
862 /* The cases below are in order by symbolcode value. */
863 switch (symbolptr
->symbolcode
) {
869 case SYM_COOKIE_SERVER
:
870 PARSE_IAL(cookie_server
);
873 case SYM_DOMAIN_SERVER
:
874 PARSE_IAL(domain_server
);
882 if (optype
== OP_BOOLEAN
)
883 return E_SYNTAX_ERROR
;
884 hp
->flags
.haddr
= FALSE
;
885 if (optype
== OP_ADDITION
) {
886 /* Default the HW type to Ethernet */
887 if (hp
->flags
.htype
== 0) {
888 hp
->flags
.htype
= TRUE
;
889 hp
->htype
= HTYPE_ETHERNET
;
891 tmphaddr
= prs_haddr(symbol
, hp
->htype
);
894 bcopy(tmphaddr
, hp
->haddr
, haddrlength(hp
->htype
));
895 hp
->flags
.haddr
= TRUE
;
904 if (optype
== OP_BOOLEAN
)
905 return E_SYNTAX_ERROR
;
906 hp
->flags
.htype
= FALSE
;
907 if (optype
== OP_ADDITION
) {
908 value
= 0L; /* Assume an illegal value */
909 eat_whitespace(symbol
);
910 if (isdigit(**symbol
)) {
911 value
= get_u_long(symbol
);
913 len
= sizeof(tmpstr
);
914 (void) get_string(symbol
, tmpstr
, &len
);
916 numsymbols
= sizeof(htnamemap
) /
917 sizeof(struct htypename
);
918 for (i
= 0; i
< numsymbols
; i
++) {
919 if (!strcmp(htnamemap
[i
].name
, tmpstr
)) {
923 if (i
< numsymbols
) {
924 value
= htnamemap
[i
].htype
;
927 if (value
>= hwinfocnt
) {
928 return E_BAD_HWATYPE
;
930 hp
->htype
= (byte
) (value
& 0xFF);
931 hp
->flags
.htype
= TRUE
;
935 case SYM_IMPRESS_SERVER
:
936 PARSE_IAL(impress_server
);
944 PARSE_IAL(log_server
);
948 PARSE_IAL(lpr_server
);
951 case SYM_NAME_SERVER
:
952 PARSE_IAL(name_server
);
956 PARSE_IAL(rlp_server
);
959 case SYM_SUBNET_MASK
:
960 PARSE_IA1(subnet_mask
);
963 case SYM_TIME_OFFSET
:
964 if (optype
== OP_BOOLEAN
)
965 return E_SYNTAX_ERROR
;
966 hp
->flags
.time_offset
= FALSE
;
967 if (optype
== OP_ADDITION
) {
968 len
= sizeof(tmpstr
);
969 (void) get_string(symbol
, tmpstr
, &len
);
970 if (!strncmp(tmpstr
, "auto", 4)) {
971 hp
->time_offset
= secondswest
;
973 if (sscanf(tmpstr
, "%d", (int*)&timeoff
) != 1)
974 return E_BAD_LONGWORD
;
975 hp
->time_offset
= timeoff
;
977 hp
->flags
.time_offset
= TRUE
;
981 case SYM_TIME_SERVER
:
982 PARSE_IAL(time_server
);
985 case SYM_VENDOR_MAGIC
:
986 if (optype
== OP_BOOLEAN
)
987 return E_SYNTAX_ERROR
;
988 hp
->flags
.vm_cookie
= FALSE
;
989 if (optype
== OP_ADDITION
) {
990 if (strncmp(*symbol
, "auto", 4)) {
991 /* The string is not "auto" */
992 if (!strncmp(*symbol
, "rfc", 3)) {
993 bcopy(vm_rfc1048
, hp
->vm_cookie
, 4);
994 } else if (!strncmp(*symbol
, "cmu", 3)) {
995 bcopy(vm_cmu
, hp
->vm_cookie
, 4);
997 if (!isdigit(**symbol
))
999 if (prs_inetaddr(symbol
, &value
) < 0)
1000 return E_BAD_IPADDR
;
1001 bcopy(&value
, hp
->vm_cookie
, 4);
1003 hp
->flags
.vm_cookie
= TRUE
;
1008 case SYM_SIMILAR_ENTRY
:
1011 fill_defaults(hp
, symbol
);
1014 return E_SYNTAX_ERROR
;
1018 case SYM_NAME_SWITCH
:
1021 return E_SYNTAX_ERROR
;
1023 hp
->flags
.send_name
= FALSE
;
1024 hp
->flags
.name_switch
= FALSE
;
1027 hp
->flags
.send_name
= TRUE
;
1028 hp
->flags
.name_switch
= TRUE
;
1036 if (!strncmp(*symbol
, "auto", 4)) {
1037 hp
->flags
.bootsize
= TRUE
;
1038 hp
->flags
.bootsize_auto
= TRUE
;
1040 hp
->bootsize
= (unsigned int) get_u_long(symbol
);
1041 hp
->flags
.bootsize
= TRUE
;
1042 hp
->flags
.bootsize_auto
= FALSE
;
1046 hp
->flags
.bootsize
= FALSE
;
1049 hp
->flags
.bootsize
= TRUE
;
1050 hp
->flags
.bootsize_auto
= TRUE
;
1055 case SYM_BOOT_SERVER
:
1056 PARSE_IA1(bootserver
);
1061 if ((hp
->tftpdir
!= NULL
) &&
1062 (hp
->tftpdir
->string
[0] != '/'))
1063 return E_BAD_PATHNAME
;
1067 PARSE_STR(dump_file
);
1070 case SYM_DOMAIN_NAME
:
1071 PARSE_STR(domain_name
);
1074 case SYM_SWAP_SERVER
:
1075 PARSE_IA1(swap_server
);
1079 PARSE_STR(root_path
);
1082 case SYM_EXTEN_FILE
:
1083 PARSE_STR(exten_file
);
1086 case SYM_REPLY_ADDR
:
1087 PARSE_IA1(reply_addr
);
1090 case SYM_NIS_DOMAIN
:
1091 PARSE_STR(nis_domain
);
1094 case SYM_NIS_SERVER
:
1095 PARSE_IAL(nis_server
);
1098 case SYM_NTP_SERVER
:
1099 PARSE_IAL(ntp_server
);
1102 #ifdef YORK_EX_OPTION
1104 PARSE_STR(exec_file
);
1109 PARSE_UINT(msg_size
);
1110 if (hp
->msg_size
< BP_MINPKTSZ
||
1111 hp
->msg_size
> MAX_MSG_SIZE
)
1116 PARSE_UINT(min_wait
);
1119 /* XXX - Add new tags here */
1122 return E_UNKNOWN_SYMBOL
;
1124 } /* switch symbolcode */
1136 * Read a string from the buffer indirectly pointed to through "src" and
1137 * move it into the buffer pointed to by "dest". A pointer to the maximum
1138 * allowable length of the string (including null-terminator) is passed as
1139 * "length". The actual length of the string which was read is returned in
1140 * the unsigned integer pointed to by "length". This value is the same as
1141 * that which would be returned by applying the strlen() function on the
1142 * destination string (i.e the terminating null is not counted as a
1143 * character). Trailing whitespace is removed from the string. For
1144 * convenience, the function returns the new value of "dest".
1146 * The string is read until the maximum number of characters, an unquoted
1147 * colon (:), or a null character is read. The return string in "dest" is
1152 get_string(char **src
, char *dest
, unsigned *length
)
1154 int n
, len
, quoteflag
;
1159 while ((n
< len
) && (**src
)) {
1160 if (!quoteflag
&& (**src
== ':')) {
1165 quoteflag
= !quoteflag
;
1168 if (**src
== '\\') {
1174 *dest
++ = *(*src
)++;
1179 * Remove that troublesome trailing whitespace. . .
1181 while ((n
> 0) && isspace(dest
[-1])) {
1194 * Read the string indirectly pointed to by "src", update the caller's
1195 * pointer, and return a pointer to a malloc'ed shared_string structure
1196 * containing the string.
1198 * The string is read using the same rules as get_string() above.
1201 PRIVATE
struct shared_string
*
1202 get_shared_string(char **src
)
1204 char retstring
[MAXSTRINGLEN
];
1205 struct shared_string
*s
;
1208 length
= sizeof(retstring
);
1209 (void) get_string(src
, retstring
, &length
);
1211 s
= (struct shared_string
*) smalloc(sizeof(struct shared_string
)
1214 strcpy(s
->string
, retstring
);
1222 * Load RFC1048 generic information directly into a memory buffer.
1224 * "src" indirectly points to the ASCII representation of the generic data.
1225 * "dest" points to a string structure which is updated to point to a new
1226 * string with the new data appended to the old string. The old string is
1229 * The given tag value is inserted with the new data.
1231 * The data may be represented as either a stream of hexadecimal numbers
1232 * representing bytes (any or all bytes may optionally start with '0x' and
1233 * be separated with periods ".") or as a quoted string of ASCII
1234 * characters (the quotes are required).
1238 process_generic(char **src
, struct shared_bindata
**dest
, u_int tagvalue
)
1240 byte tmpbuf
[MAXBUFLEN
];
1242 struct shared_bindata
*bdata
;
1243 u_int newlength
, oldlength
;
1246 *str
++ = (tagvalue
& 0xFF); /* Store tag value */
1247 str
++; /* Skip over length field */
1248 if ((*src
)[0] == '"') { /* ASCII data */
1249 newlength
= sizeof(tmpbuf
) - 2; /* Set maximum allowed length */
1250 (void) get_string(src
, (char *) str
, &newlength
);
1251 newlength
++; /* null terminator */
1252 } else { /* Numeric data */
1254 while (newlength
< sizeof(tmpbuf
) - 2) {
1255 if (interp_byte(src
, str
++) < 0)
1263 if ((*src
)[0] != ':')
1266 tmpbuf
[1] = (newlength
& 0xFF);
1267 oldlength
= ((*dest
)->length
);
1268 bdata
= (struct shared_bindata
*) smalloc(sizeof(struct shared_bindata
)
1269 + oldlength
+ newlength
+ 1);
1270 if (oldlength
> 0) {
1271 bcopy((*dest
)->data
, bdata
->data
, oldlength
);
1273 bcopy(tmpbuf
, bdata
->data
+ oldlength
, newlength
+ 2);
1274 bdata
->length
= oldlength
+ newlength
+ 2;
1275 bdata
->linkcount
= 1;
1286 * Verify that the given string makes sense as a hostname (according to
1287 * Appendix 1, page 29 of RFC882).
1289 * Return TRUE for good names, FALSE otherwise.
1293 goodname(char *hostname
)
1296 if (!isalpha(*hostname
++)) { /* First character must be a letter */
1299 while (isalnum(*hostname
) ||
1300 (*hostname
== '-') ||
1301 (*hostname
== '_') )
1303 hostname
++; /* Alphanumeric or a hyphen */
1305 if (!isalnum(hostname
[-1])) { /* Last must be alphanumeric */
1308 if (*hostname
== '\0') {/* Done? */
1311 } while (*hostname
++ == '.'); /* Dot, loop for next label */
1313 return FALSE
; /* If it's not a dot, lose */
1319 * Null compare function -- always returns FALSE so an element is always
1320 * inserted into a hash table (i.e. there is never a collision with an
1321 * existing element).
1325 nullcmp(hash_datum
*d1
, hash_datum
*d2
)
1332 * Function for comparing a string with the hostname field of a host
1337 nmcmp(hash_datum
*d1
, hash_datum
*d2
)
1339 char *name
= (char *) d1
; /* XXX - OK? */
1340 struct host
*hp
= (struct host
*) d2
;
1342 return !strcmp(name
, hp
->hostname
->string
);
1347 * Compare function to determine whether two hardware addresses are
1348 * equivalent. Returns TRUE if "host1" and "host2" are equivalent, FALSE
1351 * If the hardware addresses of "host1" and "host2" are identical, but
1352 * they are on different IP subnets, this function returns FALSE.
1354 * This function is used when inserting elements into the hardware address
1359 hwinscmp(hash_datum
*d1
, hash_datum
*d2
)
1361 struct host
*host1
= (struct host
*) d1
;
1362 struct host
*host2
= (struct host
*) d2
;
1364 if (host1
->htype
!= host2
->htype
) {
1367 if (bcmp(host1
->haddr
, host2
->haddr
, haddrlength(host1
->htype
))) {
1370 /* XXX - Is the subnet_mask field set yet? */
1371 if ((host1
->subnet_mask
.s_addr
) == (host2
->subnet_mask
.s_addr
)) {
1372 if (((host1
->iaddr
.s_addr
) & (host1
->subnet_mask
.s_addr
)) !=
1373 ((host2
->iaddr
.s_addr
) & (host2
->subnet_mask
.s_addr
)))
1383 * Macros for use in the function below:
1386 #define DUP_COPY(MEMBER) do \
1388 if (!hp->flags.MEMBER) { \
1389 if ((hp->flags.MEMBER = hp2->flags.MEMBER) != 0) { \
1390 hp->MEMBER = hp2->MEMBER; \
1395 #define DUP_LINK(MEMBER) do \
1397 if (!hp->flags.MEMBER) { \
1398 if ((hp->flags.MEMBER = hp2->flags.MEMBER) != 0) { \
1399 assert(hp2->MEMBER); \
1400 hp->MEMBER = hp2->MEMBER; \
1401 (hp->MEMBER->linkcount)++; \
1407 * Process the "similar entry" symbol.
1409 * The host specified as the value of the "tc" symbol is used as a template
1410 * for the current host entry. Symbol values not explicitly set in the
1411 * current host entry are inferred from the template entry.
1414 fill_defaults(struct host
*hp
, char **src
)
1416 unsigned int tlen
, hashcode
;
1418 char tstring
[MAXSTRINGLEN
];
1420 tlen
= sizeof(tstring
);
1421 (void) get_string(src
, tstring
, &tlen
);
1422 hashcode
= hash_HashFunction((u_char
*) tstring
, tlen
);
1423 hp2
= (struct host
*) hash_Lookup(nmhashtable
, hashcode
, nmcmp
, tstring
);
1426 report(LOG_ERR
, "can't find tc=\"%s\"", tstring
);
1430 DUP_LINK(cookie_server
);
1431 DUP_LINK(domain_server
);
1433 /* haddr not copied */
1437 DUP_LINK(impress_server
);
1438 /* iaddr not copied */
1439 DUP_LINK(log_server
);
1440 DUP_LINK(lpr_server
);
1441 DUP_LINK(name_server
);
1442 DUP_LINK(rlp_server
);
1444 DUP_COPY(subnet_mask
);
1445 DUP_COPY(time_offset
);
1446 DUP_LINK(time_server
);
1448 if (!hp
->flags
.vm_cookie
) {
1449 if ((hp
->flags
.vm_cookie
= hp2
->flags
.vm_cookie
)) {
1450 bcopy(hp2
->vm_cookie
, hp
->vm_cookie
, 4);
1453 if (!hp
->flags
.name_switch
) {
1454 if ((hp
->flags
.name_switch
= hp2
->flags
.name_switch
)) {
1455 hp
->flags
.send_name
= hp2
->flags
.send_name
;
1458 if (!hp
->flags
.bootsize
) {
1459 if ((hp
->flags
.bootsize
= hp2
->flags
.bootsize
)) {
1460 hp
->flags
.bootsize_auto
= hp2
->flags
.bootsize_auto
;
1461 hp
->bootsize
= hp2
->bootsize
;
1464 DUP_COPY(bootserver
);
1467 DUP_LINK(dump_file
);
1468 DUP_LINK(domain_name
);
1470 DUP_COPY(swap_server
);
1471 DUP_LINK(root_path
);
1472 DUP_LINK(exten_file
);
1474 DUP_COPY(reply_addr
);
1476 DUP_LINK(nis_domain
);
1477 DUP_LINK(nis_server
);
1478 DUP_LINK(ntp_server
);
1480 #ifdef YORK_EX_OPTION
1481 DUP_LINK(exec_file
);
1487 /* XXX - Add new tags here */
1498 * This function adjusts the caller's pointer to point just past the
1499 * first-encountered colon. If it runs into a null character, it leaves
1500 * the pointer pointing to it.
1509 while (*t
&& (*t
!= ':')) {
1522 * This function adjusts the caller's pointer to point to the first
1523 * non-whitespace character. If it runs into a null character, it leaves
1524 * the pointer pointing to it.
1528 eat_whitespace(char **s
)
1533 while (*t
&& isspace(*t
)) {
1542 * This function converts the given string to all lowercase.
1562 * In many of the functions which follow, a parameter such as "src" or
1563 * "symbol" is passed as a pointer to a pointer to something. This is
1564 * done for the purpose of letting the called function update the
1565 * caller's copy of the parameter (i.e. to effect call-by-reference
1566 * parameter passing). The value of the actual parameter is only used
1567 * to locate the real parameter of interest and then update this indirect
1570 * I'm sure somebody out there won't like this. . . .
1571 * (Yea, because it usually makes code slower... -gwr)
1578 * "src" points to a character pointer which points to an ASCII string of
1579 * whitespace-separated IP addresses. A pointer to an in_addr_list
1580 * structure containing the list of addresses is returned. NULL is
1581 * returned if no addresses were found at all. The pointer pointed to by
1582 * "src" is updated to point to the first non-address (illegal) character.
1585 PRIVATE
struct in_addr_list
*
1586 get_addresses(char **src
)
1588 struct in_addr tmpaddrlist
[MAXINADDRS
];
1589 struct in_addr
*address1
, *address2
;
1590 struct in_addr_list
*result
;
1591 unsigned addrcount
, totalsize
;
1593 address1
= tmpaddrlist
;
1594 for (addrcount
= 0; addrcount
< MAXINADDRS
; addrcount
++) {
1595 while (isspace(**src
) || (**src
== ',')) {
1598 if (!**src
) { /* Quit if nothing more */
1601 if (prs_inetaddr(src
, &(address1
->s_addr
)) < 0) {
1604 address1
++; /* Point to next address slot */
1606 if (addrcount
< 1) {
1609 totalsize
= sizeof(struct in_addr_list
)
1610 + (addrcount
- 1) * sizeof(struct in_addr
);
1611 result
= (struct in_addr_list
*) smalloc(totalsize
);
1612 result
->linkcount
= 1;
1613 result
->addrcount
= addrcount
;
1614 address1
= tmpaddrlist
;
1615 address2
= result
->addr
;
1616 for (; addrcount
> 0; addrcount
--) {
1617 address2
->s_addr
= address1
->s_addr
;
1628 * prs_inetaddr(src, result)
1630 * "src" is a value-result parameter; the pointer it points to is updated
1631 * to point to the next data position. "result" points to an unsigned long
1632 * in which an address is returned.
1634 * This function parses the IP address string in ASCII "dot notation" pointed
1635 * to by (*src) and places the result (in network byte order) in the unsigned
1636 * long pointed to by "result". For malformed addresses, -1 is returned,
1637 * (*src) points to the first illegal character, and the unsigned long pointed
1638 * to by "result" is unchanged. Successful calls return 0.
1642 prs_inetaddr(char **src
, u_int32
*result
)
1644 char tmpstr
[MAXSTRINGLEN
];
1646 u_int32 parts
[4], *pp
;
1650 /* Leading alpha char causes IP addr lookup. */
1651 if (isalpha(**src
)) {
1652 /* Lookup IP address. */
1655 while ((isalnum(*s
) || (*s
== '.') ||
1656 (*s
== '-') || (*s
== '_') ) &&
1657 (t
< &tmpstr
[MAXSTRINGLEN
- 1]) )
1662 n
= lookup_ipa(tmpstr
, result
);
1664 report(LOG_ERR
, "can not get IP addr for %s", tmpstr
);
1669 * Parse an address in Internet format:
1671 * a.b.c (with c treated as 16-bits)
1672 * a.b (with b treated as 24 bits)
1676 /* If it's not a digit, return error. */
1677 if (!isdigit(**src
))
1679 *pp
++ = get_u_long(src
);
1681 if (pp
< (parts
+ 4)) {
1688 /* This is handled by the caller. */
1689 if (**src
&& !(isspace(**src
) || (**src
== ':'))) {
1695 * Construct the address according to
1696 * the number of parts specified.
1700 case 1: /* a -- 32 bits */
1703 case 2: /* a.b -- 8.24 bits */
1704 value
= (parts
[0] << 24) | (parts
[1] & 0xFFFFFF);
1706 case 3: /* a.b.c -- 8.8.16 bits */
1707 value
= (parts
[0] << 24) | ((parts
[1] & 0xFF) << 16) |
1708 (parts
[2] & 0xFFFF);
1710 case 4: /* a.b.c.d -- 8.8.8.8 bits */
1711 value
= (parts
[0] << 24) | ((parts
[1] & 0xFF) << 16) |
1712 ((parts
[2] & 0xFF) << 8) | (parts
[3] & 0xFF);
1717 *result
= htonl(value
);
1724 * "src" points to a pointer which in turn points to a hexadecimal ASCII
1725 * string. This string is interpreted as a hardware address and returned
1726 * as a pointer to the actual hardware address, represented as an array of
1729 * The ASCII string must have the proper number of digits for the specified
1730 * hardware type (e.g. twelve digits for a 48-bit Ethernet address).
1731 * Two-digit sequences (bytes) may be separated with periods (.) and/or
1732 * prefixed with '0x' for readability, but this is not required.
1734 * For bad addresses, the pointer which "src" points to is updated to point
1735 * to the start of the first two-digit sequence which was bad, and the
1736 * function returns a NULL pointer.
1740 prs_haddr(char **src
, u_int htype
)
1742 static byte haddr
[MAXHADDRLEN
];
1744 char tmpstr
[MAXSTRINGLEN
];
1749 hal
= haddrlength(htype
); /* Get length of this address type */
1751 report(LOG_ERR
, "Invalid addr type for HW addr parse");
1754 tmplen
= sizeof(tmpstr
);
1755 get_string(src
, tmpstr
, &tmplen
);
1758 /* If it's a valid host name, try to lookup the HW address. */
1760 /* Lookup Hardware Address for hostname. */
1761 if ((hap
= lookup_hwa(p
, htype
)) != NULL
)
1762 return hap
; /* success */
1763 report(LOG_ERR
, "Add 0x prefix if hex value starts with A-F");
1764 /* OK, assume it must be numeric. */
1768 while (hap
< haddr
+ hal
) {
1769 if ((*p
== '.') || (*p
== ':'))
1771 if (interp_byte(&p
, hap
++) < 0) {
1781 * "src" is a pointer to a character pointer which in turn points to a
1782 * hexadecimal ASCII representation of a byte. This byte is read, the
1783 * character pointer is updated, and the result is deposited into the
1784 * byte pointed to by "retbyte".
1786 * The usual '0x' notation is allowed but not required. The number must be
1787 * a two digit hexadecimal number. If the number is invalid, "src" and
1788 * "retbyte" are left untouched and -1 is returned as the function value.
1789 * Successful calls return 0.
1793 interp_byte(char **src
, byte
*retbyte
)
1797 if ((*src
)[0] == '0' &&
1798 ((*src
)[1] == 'x' ||
1799 (*src
)[1] == 'X')) {
1800 (*src
) += 2; /* allow 0x for hex, but don't require it */
1802 if (!isxdigit((*src
)[0]) || !isxdigit((*src
)[1])) {
1805 if (sscanf(*src
, "%2x", &v
) != 1) {
1809 *retbyte
= (byte
) (v
& 0xFF);
1816 * The parameter "src" points to a character pointer which points to an
1817 * ASCII string representation of an unsigned number. The number is
1818 * returned as an unsigned long and the character pointer is updated to
1819 * point to the first illegal character.
1823 get_u_long(char **src
)
1825 u_int32 value
, base
;
1829 * Collect number up to first illegal character. Values are specified
1830 * as for C: 0x=hex, 0=octal, other=decimal.
1838 if (**src
== 'x' || **src
== 'X') {
1842 while ((c
= **src
)) {
1844 value
= (value
* base
) + (c
- '0');
1848 if (base
== 16 && isxdigit(c
)) {
1849 value
= (value
<< 4) + ((c
& ~32) + 10 - 'A');
1861 * Routines for deletion of data associated with the main data structure.
1866 * Frees the entire host data structure given. Does nothing if the passed
1871 free_host(hash_datum
*hmp
)
1873 struct host
*hostptr
= (struct host
*) hmp
;
1874 if (hostptr
== NULL
)
1876 assert(hostptr
->linkcount
> 0);
1877 if (--(hostptr
->linkcount
))
1878 return; /* Still has references */
1879 del_iplist(hostptr
->cookie_server
);
1880 del_iplist(hostptr
->domain_server
);
1881 del_iplist(hostptr
->gateway
);
1882 del_iplist(hostptr
->impress_server
);
1883 del_iplist(hostptr
->log_server
);
1884 del_iplist(hostptr
->lpr_server
);
1885 del_iplist(hostptr
->name_server
);
1886 del_iplist(hostptr
->rlp_server
);
1887 del_iplist(hostptr
->time_server
);
1888 del_iplist(hostptr
->nis_server
);
1889 del_iplist(hostptr
->ntp_server
);
1892 * XXX - Add new tags here
1893 * (if the value is an IP list)
1896 del_string(hostptr
->hostname
);
1897 del_string(hostptr
->homedir
);
1898 del_string(hostptr
->bootfile
);
1899 del_string(hostptr
->tftpdir
);
1900 del_string(hostptr
->root_path
);
1901 del_string(hostptr
->domain_name
);
1902 del_string(hostptr
->dump_file
);
1903 del_string(hostptr
->exten_file
);
1904 del_string(hostptr
->nis_domain
);
1906 #ifdef YORK_EX_OPTION
1907 del_string(hostptr
->exec_file
);
1911 * XXX - Add new tags here
1912 * (if it is a shared string)
1915 del_bindata(hostptr
->generic
);
1916 free((char *) hostptr
);
1922 * Decrements the linkcount on the given IP address data structure. If the
1923 * linkcount goes to zero, the memory associated with the data is freed.
1927 del_iplist(struct in_addr_list
*iplist
)
1930 if (!(--(iplist
->linkcount
))) {
1931 free((char *) iplist
);
1939 * Decrements the linkcount on a string data structure. If the count
1940 * goes to zero, the memory associated with the string is freed. Does
1941 * nothing if the passed pointer is NULL.
1945 del_string(struct shared_string
*stringptr
)
1948 if (!(--(stringptr
->linkcount
))) {
1949 free((char *) stringptr
);
1957 * Decrements the linkcount on a shared_bindata data structure. If the
1958 * count goes to zero, the memory associated with the data is freed. Does
1959 * nothing if the passed pointer is NULL.
1963 del_bindata(struct shared_bindata
*dataptr
)
1966 if (!(--(dataptr
->linkcount
))) {
1967 free((char *) dataptr
);
1975 /* smalloc() -- safe malloc()
1977 * Always returns a valid pointer (if it returns at all). The allocated
1978 * memory is initialized to all zeros. If malloc() returns an error, a
1979 * message is printed using the report() function and the program aborts
1980 * with a status of 1.
1984 smalloc(unsigned nbytes
)
1988 retvalue
= malloc(nbytes
);
1990 report(LOG_ERR
, "malloc() failure -- exiting");
1993 bzero(retvalue
, nbytes
);
1999 * Compare function to determine whether two hardware addresses are
2000 * equivalent. Returns TRUE if "host1" and "host2" are equivalent, FALSE
2003 * This function is used when retrieving elements from the hardware address
2008 hwlookcmp(hash_datum
*d1
, hash_datum
*d2
)
2010 struct host
*host1
= (struct host
*) d1
;
2011 struct host
*host2
= (struct host
*) d2
;
2013 if (host1
->htype
!= host2
->htype
) {
2016 if (bcmp(host1
->haddr
, host2
->haddr
, haddrlength(host1
->htype
))) {
2024 * Compare function for doing IP address hash table lookup.
2028 iplookcmp(hash_datum
*d1
, hash_datum
*d2
)
2030 struct host
*host1
= (struct host
*) d1
;
2031 struct host
*host2
= (struct host
*) d2
;
2033 return (host1
->iaddr
.s_addr
== host2
->iaddr
.s_addr
);
2040 * c-argdecl-indent: 4
2041 * c-continued-statement-offset: 4
2042 * c-continued-brace-offset: -4
2043 * c-label-offset: -4