ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/reslib.c
(Generate patch)

Comparing ircd-hybrid-7.2/src/irc_reslib.c (file contents):
Revision 912 by michael, Wed Nov 7 22:47:44 2007 UTC vs.
Revision 996 by michael, Fri Aug 21 10:16:29 2009 UTC

# Line 96 | Line 96
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*/
# Line 124 | Line 123 | static const char digits[] = "0123456789
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    
# Line 144 | Line 143 | int
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  
# Line 209 | Line 210 | parse_resvconf(void)
210      if ((p = strpbrk(arg, " \t")) != NULL)
211        *p = '\0';  /* take the first word */
212  
213 <    if (irccmp(opt, "domain") == 0)
213 <      strlcpy(irc_domain, arg, HOSTLEN);
214 <    else if (irccmp(opt, "nameserver") == 0)
213 >    if (irccmp(opt, "nameserver") == 0)
214        add_nameserver(arg);
215    }
216  
# Line 267 | Line 266 | irc_dn_expand(const unsigned char *msg,
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)
# Line 286 | Line 285 | irc_ns_name_uncompress(const unsigned ch
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.
# Line 369 | Line 369 | irc_ns_name_unpack(const unsigned char *
369          if (len < 0)
370                  len = srcp - src;
371          return (len);
372 < }
372 > } /*2*/
373  
374   /*
375   * irc_ns_name_ntop(src, dst, dstsiz)
# Line 381 | Line 381 | irc_ns_name_unpack(const unsigned char *
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;
# Line 406 | Line 406 | irc_ns_name_ntop(const char *src, char *
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                  }
# Line 470 | Line 470 | irc_ns_name_ntop(const char *src, char *
470          }
471          *dn++ = '\0';
472          return (dn - dst);
473 < }
474 <
475 < /*
476 < * Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
477 < * Return the size of the compressed name or -1.
478 < * 'length' is the size of the array pointed to by 'comp_dn'.
479 < */
480 < static int
481 < irc_dn_comp(const char *src, unsigned char *dst, int dstsiz,
482 <            unsigned char **dnptrs, unsigned char **lastdnptr)
483 < {
484 <  return(irc_ns_name_compress(src, dst, (size_t)dstsiz,
485 <                              (const unsigned char **)dnptrs,
486 <                              (const unsigned char **)lastdnptr));
487 < }
473 > } /*2*/
474  
475   /*
476   * Skip over a compressed domain name. Return the size or -1.
# Line 496 | Line 482 | irc_dn_skipname(const unsigned char *ptr
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)
# Line 549 | Line 535 | irc_ns_name_skip(const unsigned char **p
535  
536    *ptrptr = cp;
537    return(0);
538 < }
538 > } /*2*/
539  
540   unsigned int
541   irc_ns_get16(const unsigned char *src)
# Line 608 | Line 594 | special(int ch)
594      default:
595        return(0);
596    }
597 < }
597 > } /*2*/
598  
599   static int
600   labellen(const unsigned char *lp)
# Line 635 | Line 621 | labellen(const unsigned char *lp)
621    }
622  
623    return(l);
624 < }
624 > } /*2*/
625  
626  
627   /*
# Line 649 | Line 635 | static int
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  
# Line 681 | Line 667 | irc_decode_bitstring(const char **cpp, c
667  
668          *cpp = cp;
669          return(dn - beg);
670 < }
670 > } /*2*/
671  
672   /*
673   * irc_ns_name_pton(src, dst, dstsiz)
# Line 717 | Line 703 | irc_ns_name_pton(const char *src, unsign
703                 cp + 2,
704                 &label,
705                 &bp,
706 <               (const char *)eom))
706 >               eom))
707              != 0) {
708            errno = e;
709            return(-1);
# Line 821 | Line 807 | irc_ns_name_pton(const char *src, unsign
807    }
808  
809    return (0);
810 < }
810 > } /*2*/
811  
812   /*
813   * irc_ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
# Line 930 | Line 916 | cleanup:
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,
# Line 945 | Line 931 | irc_ns_name_compress(const char *src, un
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;
# Line 966 | Line 953 | irc_encode_bitsring(const char **bp, con
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) {
# Line 1043 | Line 1030 | irc_encode_bitsring(const char **bp, con
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)
# Line 1115 | Line 1102 | irc_dn_find(const unsigned char *domain,
1102    }
1103    errno = ENOENT;
1104    return (-1);
1105 < }
1105 > } /*2*/
1106  
1107   /*
1108   *  *  Thinking in noninternationalized USASCII (per the DNS spec),
# Line 1128 | Line 1115 | mklower(int ch)
1115      return(ch + 0x20);
1116  
1117    return(ch);
1118 < }
1118 > } /*2*/
1119  
1120   /* From resolv/mkquery.c */
1121  
# Line 1169 | Line 1156 | irc_res_mkquery(
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)