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/src/irc_reslib.c (file contents), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid-7.2/src/irc_reslib.c (file contents), 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 162 | Line 163 | parse_resvconf(void)
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()
# Line 260 | 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 279 | 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 362 | 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 374 | 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 399 | 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 463 | Line 470 | irc_ns_name_ntop(const char *src, char *
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.
# Line 489 | 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 542 | 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 601 | 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 628 | Line 621 | labellen(const unsigned char *lp)
621    }
622  
623    return(l);
624 < }
624 > } /*2*/
625  
626  
627   /*
# Line 642 | 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 674 | 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 710 | 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 814 | 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 923 | 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 938 | 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 959 | 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 1036 | 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 1108 | 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 1121 | Line 1115 | mklower(int ch)
1115      return(ch + 0x20);
1116  
1117    return(ch);
1118 < }
1118 > } /*2*/
1119  
1120   /* From resolv/mkquery.c */
1121  
# Line 1162 | 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;

Comparing:
ircd-hybrid/src/irc_reslib.c (property svn:keywords), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid-7.2/src/irc_reslib.c (property svn:keywords), Revision 996 by michael, Fri Aug 21 10:16:29 2009 UTC

# Line 1 | Line 1
1 < Revision
1 > Id Revision

Diff Legend

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