96 |
|
|
97 |
|
struct irc_ssaddr irc_nsaddr_list[IRCD_MAXNS]; |
98 |
|
int irc_nscount = 0; |
99 |
– |
char irc_domain[HOSTLEN + 1]; |
99 |
|
|
100 |
|
static const char digitvalue[256] = { |
101 |
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/ |
123 |
|
static int labellen(const unsigned char *lp); |
124 |
|
static int special(int ch); |
125 |
|
static int printable(int ch); |
126 |
< |
static int irc_decode_bitstring(const char **cpp, char *dn, const char *eom); |
126 |
> |
static int irc_decode_bitstring(const unsigned char **cpp, char *dn, const char *eom); |
127 |
|
static int irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz, |
128 |
|
const unsigned char **dnptrs, const unsigned char **lastdnptr); |
129 |
|
static int irc_dn_find(const unsigned char *, const unsigned char *, const unsigned char * const *, |
130 |
|
const unsigned char * const *); |
131 |
|
static int irc_encode_bitsring(const char **, const char *, unsigned char **, unsigned char **, |
132 |
< |
const char *); |
132 |
> |
const unsigned char *); |
133 |
|
static int irc_ns_name_uncompress(const unsigned char *, const unsigned char *, |
134 |
|
const unsigned char *, char *, size_t); |
135 |
|
static int irc_ns_name_unpack(const unsigned char *, const unsigned char *, |
136 |
|
const unsigned char *, unsigned char *, |
137 |
|
size_t); |
138 |
< |
static int irc_ns_name_ntop(const char *, char *, size_t); |
138 |
> |
static int irc_ns_name_ntop(const unsigned char *, char *, size_t); |
139 |
|
static int irc_ns_name_skip(const unsigned char **, const unsigned char *); |
140 |
|
static int mklower(int ch); |
141 |
|
|
143 |
|
irc_res_init(void) |
144 |
|
{ |
145 |
|
irc_nscount = 0; |
146 |
+ |
memset(irc_nsaddr_list, 0, sizeof(irc_nsaddr_list)); |
147 |
+ |
|
148 |
|
return parse_resvconf(); |
149 |
|
} |
150 |
|
|
163 |
|
char input[MAXLINE]; |
164 |
|
FBFILE *file; |
165 |
|
|
166 |
< |
/* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps |
166 |
> |
/* XXX "/etc/resolv.conf" should be from a define in config.h perhaps |
167 |
|
* for cygwin support etc. this hardcodes it to unix for now -db |
168 |
|
*/ |
169 |
|
if ((file = fbopen("/etc/resolv.conf", "r")) == NULL) |
170 |
< |
return(-1); |
170 |
> |
return -1; |
171 |
|
|
172 |
< |
while (fbgets(input, MAXLINE, file) != NULL) |
172 |
> |
while (fbgets(input, sizeof(input), file) != NULL) |
173 |
|
{ |
174 |
|
/* blow away any newline */ |
175 |
|
if ((p = strpbrk(input, "\r\n")) != NULL) |
176 |
|
*p = '\0'; |
177 |
|
|
177 |
– |
/* Ignore comment lines immediately */ |
178 |
– |
if (*input == '#') |
179 |
– |
continue; |
180 |
– |
|
178 |
|
p = input; |
179 |
+ |
|
180 |
|
/* skip until something thats not a space is seen */ |
181 |
|
while (IsSpace(*p)) |
182 |
< |
p++; |
182 |
> |
++p; |
183 |
> |
|
184 |
|
/* if at this point, have a '\0' then continue */ |
185 |
|
if (*p == '\0') |
186 |
|
continue; |
187 |
|
|
188 |
+ |
/* Ignore comment lines immediately */ |
189 |
+ |
if (*p == ';' || *p == '#') |
190 |
+ |
continue; |
191 |
+ |
|
192 |
|
/* skip until a space is found */ |
193 |
< |
opt = input; |
194 |
< |
while (!IsSpace(*p)) |
195 |
< |
if (*p++ == '\0') |
196 |
< |
continue; /* no arguments?.. ignore this line */ |
193 |
> |
opt = p; |
194 |
> |
while (!IsSpace(*p) && *p) |
195 |
> |
++p; |
196 |
> |
|
197 |
> |
if (*p == '\0') |
198 |
> |
continue; /* no arguments?.. ignore this line */ |
199 |
> |
|
200 |
|
/* blow away the space character */ |
201 |
|
*p++ = '\0'; |
202 |
|
|
203 |
|
/* skip these spaces that are before the argument */ |
204 |
|
while (IsSpace(*p)) |
205 |
< |
p++; |
205 |
> |
++p; |
206 |
> |
|
207 |
|
/* Now arg should be right where p is pointing */ |
208 |
|
arg = p; |
209 |
+ |
|
210 |
|
if ((p = strpbrk(arg, " \t")) != NULL) |
211 |
|
*p = '\0'; /* take the first word */ |
212 |
|
|
213 |
< |
if (irccmp(opt, "domain") == 0) |
206 |
< |
strlcpy(irc_domain, arg, HOSTLEN); |
207 |
< |
else if (irccmp(opt, "nameserver") == 0) |
213 |
> |
if (irccmp(opt, "nameserver") == 0) |
214 |
|
add_nameserver(arg); |
215 |
|
} |
216 |
|
|
217 |
|
fbclose(file); |
218 |
< |
return(0); |
218 |
> |
return 0; |
219 |
|
} |
220 |
|
|
221 |
|
/* add_nameserver() |
266 |
|
if (n > 0 && dst[0] == '.') |
267 |
|
dst[0] = '\0'; |
268 |
|
return(n); |
269 |
< |
} |
269 |
> |
} /*2*/ |
270 |
|
|
271 |
|
/* |
272 |
|
* irc_ns_name_uncompress(msg, eom, src, dst, dstsiz) |
285 |
|
|
286 |
|
if ((n = irc_ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1) |
287 |
|
return(-1); |
288 |
< |
if (irc_ns_name_ntop((char*)tmp, dst, dstsiz) == -1) |
288 |
> |
if (irc_ns_name_ntop(tmp, dst, dstsiz) == -1) |
289 |
|
return(-1); |
290 |
|
return(n); |
291 |
< |
} |
291 |
> |
} /*2*/ |
292 |
> |
|
293 |
|
/* |
294 |
|
* irc_ns_name_unpack(msg, eom, src, dst, dstsiz) |
295 |
|
* Unpack a domain name from a message, source may be compressed. |
369 |
|
if (len < 0) |
370 |
|
len = srcp - src; |
371 |
|
return (len); |
372 |
< |
} |
372 |
> |
} /*2*/ |
373 |
|
|
374 |
|
/* |
375 |
|
* irc_ns_name_ntop(src, dst, dstsiz) |
381 |
|
* All other domains are returned in non absolute form |
382 |
|
*/ |
383 |
|
static int |
384 |
< |
irc_ns_name_ntop(const char *src, char *dst, size_t dstsiz) |
384 |
> |
irc_ns_name_ntop(const unsigned char *src, char *dst, size_t dstsiz) |
385 |
|
{ |
386 |
< |
const char *cp; |
386 |
> |
const unsigned char *cp; |
387 |
|
char *dn, *eom; |
388 |
|
unsigned char c; |
389 |
|
unsigned int n; |
406 |
|
} |
407 |
|
*dn++ = '.'; |
408 |
|
} |
409 |
< |
if ((l = labellen((unsigned char*)(cp - 1))) < 0) { |
409 |
> |
if ((l = labellen((cp - 1))) < 0) { |
410 |
|
errno = EMSGSIZE; /* XXX */ |
411 |
|
return(-1); |
412 |
|
} |
470 |
|
} |
471 |
|
*dn++ = '\0'; |
472 |
|
return (dn - dst); |
473 |
< |
} |
467 |
< |
|
468 |
< |
/* |
469 |
< |
* Pack domain name 'exp_dn' in presentation form into 'comp_dn'. |
470 |
< |
* Return the size of the compressed name or -1. |
471 |
< |
* 'length' is the size of the array pointed to by 'comp_dn'. |
472 |
< |
*/ |
473 |
< |
static int |
474 |
< |
irc_dn_comp(const char *src, unsigned char *dst, int dstsiz, |
475 |
< |
unsigned char **dnptrs, unsigned char **lastdnptr) |
476 |
< |
{ |
477 |
< |
return(irc_ns_name_compress(src, dst, (size_t)dstsiz, |
478 |
< |
(const unsigned char **)dnptrs, |
479 |
< |
(const unsigned char **)lastdnptr)); |
480 |
< |
} |
473 |
> |
} /*2*/ |
474 |
|
|
475 |
|
/* |
476 |
|
* Skip over a compressed domain name. Return the size or -1. |
482 |
|
if (irc_ns_name_skip(&ptr, eom) == -1) |
483 |
|
return(-1); |
484 |
|
return(ptr - saveptr); |
485 |
< |
} |
485 |
> |
} /*2*/ |
486 |
|
|
487 |
|
/* |
488 |
|
* ns_name_skip(ptrptr, eom) |
535 |
|
|
536 |
|
*ptrptr = cp; |
537 |
|
return(0); |
538 |
< |
} |
538 |
> |
} /*2*/ |
539 |
|
|
540 |
|
unsigned int |
541 |
|
irc_ns_get16(const unsigned char *src) |
594 |
|
default: |
595 |
|
return(0); |
596 |
|
} |
597 |
< |
} |
597 |
> |
} /*2*/ |
598 |
|
|
599 |
|
static int |
600 |
|
labellen(const unsigned char *lp) |
621 |
|
} |
622 |
|
|
623 |
|
return(l); |
624 |
< |
} |
624 |
> |
} /*2*/ |
625 |
|
|
626 |
|
|
627 |
|
/* |
635 |
|
printable(int ch) |
636 |
|
{ |
637 |
|
return(ch > 0x20 && ch < 0x7f); |
638 |
< |
} |
638 |
> |
} /*2*/ |
639 |
|
|
640 |
|
static int |
641 |
< |
irc_decode_bitstring(const char **cpp, char *dn, const char *eom) |
641 |
> |
irc_decode_bitstring(const unsigned char **cpp, char *dn, const char *eom) |
642 |
|
{ |
643 |
< |
const char *cp = *cpp; |
643 |
> |
const unsigned char *cp = *cpp; |
644 |
|
char *beg = dn, tc; |
645 |
|
int b, blen, plen; |
646 |
|
|
667 |
|
|
668 |
|
*cpp = cp; |
669 |
|
return(dn - beg); |
670 |
< |
} |
670 |
> |
} /*2*/ |
671 |
|
|
672 |
|
/* |
673 |
|
* irc_ns_name_pton(src, dst, dstsiz) |
703 |
|
cp + 2, |
704 |
|
&label, |
705 |
|
&bp, |
706 |
< |
(const char *)eom)) |
706 |
> |
eom)) |
707 |
|
!= 0) { |
708 |
|
errno = e; |
709 |
|
return(-1); |
807 |
|
} |
808 |
|
|
809 |
|
return (0); |
810 |
< |
} |
810 |
> |
} /*2*/ |
811 |
|
|
812 |
|
/* |
813 |
|
* irc_ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr) |
916 |
|
return (-1); |
917 |
|
} |
918 |
|
return(dstp - dst); |
919 |
< |
} |
919 |
> |
} /*2*/ |
920 |
|
|
921 |
|
static int |
922 |
|
irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz, |
931 |
|
|
932 |
|
static int |
933 |
|
irc_encode_bitsring(const char **bp, const char *end, unsigned char **labelp, |
934 |
< |
unsigned char **dst, const char *eom) |
934 |
> |
unsigned char **dst, const unsigned char *eom) |
935 |
|
{ |
936 |
|
int afterslash = 0; |
937 |
|
const char *cp = *bp; |
938 |
< |
char *tp, c; |
938 |
> |
unsigned char *tp; |
939 |
> |
char c; |
940 |
|
const char *beg_blen; |
941 |
|
char *end_blen = NULL; |
942 |
|
int value = 0, count = 0, tbcount = 0, blen = 0; |
953 |
|
if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */ |
954 |
|
return(EINVAL); |
955 |
|
|
956 |
< |
for (tp = (char*)(dst + 1); cp < end && tp < eom; cp++) { |
956 |
> |
for (tp = *dst + 1; cp < end && tp < eom; cp++) { |
957 |
|
switch((c = *cp)) { |
958 |
|
case ']': /* end of the bitstring */ |
959 |
|
if (afterslash) { |
1030 |
|
**dst = blen; |
1031 |
|
|
1032 |
|
*bp = cp; |
1033 |
< |
*dst = (unsigned char*)tp; |
1033 |
> |
*dst = tp; |
1034 |
|
|
1035 |
|
return(0); |
1036 |
< |
} |
1036 |
> |
} /*2*/ |
1037 |
|
|
1038 |
|
/* |
1039 |
|
* dn_find(domain, msg, dnptrs, lastdnptr) |
1102 |
|
} |
1103 |
|
errno = ENOENT; |
1104 |
|
return (-1); |
1105 |
< |
} |
1105 |
> |
} /*2*/ |
1106 |
|
|
1107 |
|
/* |
1108 |
|
* * Thinking in noninternationalized USASCII (per the DNS spec), |
1115 |
|
return(ch + 0x20); |
1116 |
|
|
1117 |
|
return(ch); |
1118 |
< |
} |
1118 |
> |
} /*2*/ |
1119 |
|
|
1120 |
|
/* From resolv/mkquery.c */ |
1121 |
|
|
1156 |
|
|
1157 |
|
if ((buflen -= QFIXEDSZ) < 0) |
1158 |
|
return (-1); |
1159 |
< |
if ((n = irc_dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) |
1159 |
> |
if ((n = irc_ns_name_compress(dname, cp, buflen, (const unsigned char **)dnptrs, |
1160 |
> |
(const unsigned char **)lastdnptr)) < 0) |
1161 |
|
return (-1); |
1162 |
|
|
1163 |
|
cp += n; |