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 31 by knight, Sun Oct 2 20:34:05 2005 UTC vs.
ircd-hybrid/trunk/src/reslib.c (file contents), Revision 3852 by michael, Thu Jun 5 13:12:45 2014 UTC

# Line 10 | Line 10
10   * 2. Redistributions in binary form must reproduce the above copyright
11   *    notice, this list of conditions and the following disclaimer in the
12   *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *      This product includes software developed by the University of
16 *      California, Berkeley and its contributors.
13   * 4. Neither the name of the University nor the names of its contributors
14   *    may be used to endorse or promote products derived from this software
15   *    without specific prior written permission.
# Line 81 | Line 77
77   */
78  
79   #include "stdinc.h"
84 #include "irc_reslib.h"
85 #include "irc_res.h"    
80   #include "ircd_defs.h"
81 < #include "fileio.h"
81 > #include "res.h"
82 > #include "reslib.h"
83   #include "irc_string.h"
89 #include "irc_getaddrinfo.h"
84  
85   #define NS_TYPE_ELT             0x40 /* EDNS0 extended label type */
86   #define DNS_LABELTYPE_BITSTRING 0x41
# Line 95 | Line 89
89   /* $Id$ */
90  
91   struct irc_ssaddr irc_nsaddr_list[IRCD_MAXNS];
92 < int irc_nscount = 0;
99 < char irc_domain[HOSTLEN + 1];
92 > unsigned int irc_nscount = 0;
93  
94 + static const char digits[] = "0123456789";
95   static const char digitvalue[256] = {
96    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
97    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
# Line 117 | Line 111 | static const char digitvalue[256] = {
111    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
112   };
113  
120 static int parse_resvconf(void);
121 static void add_nameserver(char *arg);
122
123 static const char digits[] = "0123456789";
114   static int labellen(const unsigned char *lp);
115   static int special(int ch);
116   static int printable(int ch);
117 < static int irc_decode_bitstring(const char **cpp, char *dn, const char *eom);
117 > static int irc_decode_bitstring(const unsigned char **cpp, char *dn, const char *eom);
118   static int irc_ns_name_compress(const char *src, unsigned char *dst, size_t dstsiz,
119      const unsigned char **dnptrs, const unsigned char **lastdnptr);
120   static int irc_dn_find(const unsigned char *, const unsigned char *, const unsigned char * const *,
121                         const unsigned char * const *);
122   static int irc_encode_bitsring(const char **, const char *, unsigned char **, unsigned char **,
123 <                               const char *);
123 >                               const unsigned char *);
124   static int irc_ns_name_uncompress(const unsigned char *, const unsigned char *,
125                                    const unsigned char *, char *, size_t);
126   static int irc_ns_name_unpack(const unsigned char *, const unsigned char *,
127                                const unsigned char *, unsigned char *,
128                                size_t);
129 < static int irc_ns_name_ntop(const char *, char *, size_t);
129 > static int irc_ns_name_ntop(const unsigned char *, char *, size_t);
130   static int irc_ns_name_skip(const unsigned char **, const unsigned char *);
131   static int mklower(int ch);
132    
133 < int
134 < irc_res_init(void)
133 >
134 > /* add_nameserver()
135 > *
136 > * input        - either an IPV4 address in dotted quad
137 > *                or an IPV6 address in : format
138 > * output       - NONE
139 > * side effects - entry in irc_nsaddr_list is filled in as needed
140 > */
141 > static void
142 > add_nameserver(const char *arg)
143   {
144 <  irc_nscount = 0;
145 <  return parse_resvconf();
144 >  struct addrinfo hints, *res;
145 >
146 >  /* Done max number of nameservers? */
147 >  if (irc_nscount >= IRCD_MAXNS)
148 >    return;
149 >
150 >  memset(&hints, 0, sizeof(hints));
151 >  hints.ai_family   = PF_UNSPEC;
152 >  hints.ai_socktype = SOCK_DGRAM;
153 >  hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
154 >
155 >  if (getaddrinfo(arg, "domain", &hints, &res))
156 >    return;
157 >
158 >  if (res == NULL)
159 >    return;
160 >
161 >  memcpy(&irc_nsaddr_list[irc_nscount].ss, res->ai_addr, res->ai_addrlen);
162 >  irc_nsaddr_list[irc_nscount++].ss_len = res->ai_addrlen;
163 >  freeaddrinfo(res);
164   }
165  
166   /* parse_resvconf()
# Line 153 | Line 169 | irc_res_init(void)
169   * output - -1 if failure 0 if success
170   * side effects - fills in irc_nsaddr_list
171   */
172 < static int
172 > static void
173   parse_resvconf(void)
174   {
175    char *p;
176    char *opt;
177    char *arg;
178    char input[MAXLINE];
179 <  FBFILE *file;
179 >  FILE *file;
180  
181 <  /* XXX "/etc/resolv.conf" should be from a define in setup.h perhaps
181 >  /* XXX "/etc/resolv.conf" should be from a define in config.h perhaps
182     * for cygwin support etc. this hardcodes it to unix for now -db
183     */
184 <  if ((file = fbopen("/etc/resolv.conf", "r")) == NULL)
185 <    return(-1);
184 >  if ((file = fopen("/etc/resolv.conf", "r")) == NULL)
185 >    return;
186  
187 <  while (fbgets(input, MAXLINE, file) != NULL)
187 >  while (fgets(input, sizeof(input), file))
188    {
189      /* blow away any newline */
190 <    if ((p = strpbrk(input, "\r\n")) != NULL)
190 >    if ((p = strpbrk(input, "\r\n")))
191        *p = '\0';
192  
177    /* Ignore comment lines immediately */
178    if (*input == '#')
179      continue;
180
193      p = input;
194 +
195      /* skip until something thats not a space is seen */
196      while (IsSpace(*p))
197 <      p++;
197 >      ++p;
198 >
199      /* if at this point, have a '\0' then continue */
200      if (*p == '\0')
201        continue;
202  
203 +    /* Ignore comment lines immediately */
204 +    if (*p == ';' || *p == '#')
205 +      continue;
206 +
207      /* skip until a space is found */
208 <    opt = input;
209 <    while (!IsSpace(*p))
210 <      if (*p++ == '\0')
211 <        continue;  /* no arguments?.. ignore this line */
208 >    opt = p;
209 >    while (!IsSpace(*p) && *p)
210 >      ++p;
211 >
212 >    if (*p == '\0')
213 >      continue;  /* no arguments?.. ignore this line */
214 >
215      /* blow away the space character */
216      *p++ = '\0';
217  
218      /* skip these spaces that are before the argument */
219      while (IsSpace(*p))
220 <      p++;
220 >      ++p;
221 >
222      /* Now arg should be right where p is pointing */
223      arg = p;
224 <    if ((p = strpbrk(arg, " \t")) != NULL)
224 >
225 >    if ((p = strpbrk(arg, " \t")))
226        *p = '\0';  /* take the first word */
227  
228 <    if (irccmp(opt, "domain") == 0)
206 <      strlcpy(irc_domain, arg, HOSTLEN);
207 <    else if (irccmp(opt, "nameserver") == 0)
228 >    if (!strcasecmp(opt, "nameserver"))
229        add_nameserver(arg);
230    }
231  
232 <  fbclose(file);
212 <  return(0);
232 >  fclose(file);
233   }
234  
235 < /* add_nameserver()
236 < *
217 < * input        - either an IPV4 address in dotted quad
218 < *                or an IPV6 address in : format
219 < * output       - NONE
220 < * side effects - entry in irc_nsaddr_list is filled in as needed
221 < */
222 < static void
223 < add_nameserver(char *arg)
235 > void
236 > irc_res_init(void)
237   {
238 <  struct addrinfo hints, *res;
239 <  /* Done max number of nameservers? */
227 <  if ((irc_nscount) >= IRCD_MAXNS)
228 <    return;
229 <
230 <  memset(&hints, 0, sizeof(hints));
231 <  hints.ai_family   = PF_UNSPEC;
232 <  hints.ai_socktype = SOCK_DGRAM;
233 <  hints.ai_flags    = AI_PASSIVE | AI_NUMERICHOST;
234 <
235 <  if (irc_getaddrinfo(arg, "domain", &hints, &res))
236 <    return;
238 >  irc_nscount = 0;
239 >  memset(irc_nsaddr_list, 0, sizeof(irc_nsaddr_list));
240  
241 <  if (res == NULL)
239 <    return;
241 >  parse_resvconf();
242  
243 <  memcpy(&irc_nsaddr_list[irc_nscount].ss, res->ai_addr, res->ai_addrlen);
244 <  irc_nsaddr_list[irc_nscount].ss_len = res->ai_addrlen;
243 <  irc_nscount++;
244 <  irc_freeaddrinfo(res);
243 >  if (!irc_nscount)
244 >    add_nameserver("127.0.0.1");
245   }
246  
247   /*
# Line 259 | Line 259 | irc_dn_expand(const unsigned char *msg,
259  
260    if (n > 0 && dst[0] == '.')
261      dst[0] = '\0';
262 <  return(n);
262 >  return n;
263   }
264  
265   /*
# Line 278 | Line 278 | irc_ns_name_uncompress(const unsigned ch
278    int n;
279  
280    if ((n = irc_ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
281 <    return(-1);
282 <  if (irc_ns_name_ntop((char*)tmp, dst, dstsiz) == -1)
283 <    return(-1);
284 <  return(n);
281 >    return -1;
282 >  if (irc_ns_name_ntop(tmp, dst, dstsiz) == -1)
283 >    return -1;
284 >  return n;
285   }
286 +
287   /*
288   * irc_ns_name_unpack(msg, eom, src, dst, dstsiz)
289   *      Unpack a domain name from a message, source may be compressed.
# Line 294 | Line 295 | irc_ns_name_unpack(const unsigned char *
295                     const unsigned char *src, unsigned char *dst,
296                     size_t dstsiz)
297   {
298 <        const unsigned char *srcp, *dstlim;
299 <        unsigned char *dstp;
300 <        int n, len, checked, l;
300 <
301 <        len = -1;
302 <        checked = 0;
303 <        dstp = dst;
304 <        srcp = src;
305 <        dstlim = dst + dstsiz;
306 <        if (srcp < msg || srcp >= eom) {
307 <                errno = EMSGSIZE;
308 <                return (-1);
309 <        }
310 <        /* Fetch next label in domain name. */
311 <        while ((n = *srcp++) != 0) {
312 <                /* Check for indirection. */
313 <                switch (n & NS_CMPRSFLGS) {
314 <                case 0:
315 <                case NS_TYPE_ELT:
316 <                        /* Limit checks. */
317 <                        if ((l = labellen(srcp - 1)) < 0) {
318 <                                errno = EMSGSIZE;
319 <                                return(-1);
320 <                        }
321 <                        if (dstp + l + 1 >= dstlim || srcp + l >= eom) {
322 <                                errno = EMSGSIZE;
323 <                                return (-1);
324 <                        }
325 <                        checked += l + 1;
326 <                        *dstp++ = n;
327 <                        memcpy(dstp, srcp, l);
328 <                        dstp += l;
329 <                        srcp += l;
330 <                        break;
298 >  const unsigned char *srcp, *dstlim;
299 >  unsigned char *dstp;
300 >  int n, len, checked, l;
301  
302 <                case NS_CMPRSFLGS:
303 <                        if (srcp >= eom) {
304 <                                errno = EMSGSIZE;
305 <                                return (-1);
306 <                        }
337 <                        if (len < 0)
338 <                                len = srcp - src + 1;
339 <                        srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
340 <                        if (srcp < msg || srcp >= eom) {  /* Out of range. */
341 <                                errno = EMSGSIZE;
342 <                                return (-1);
343 <                        }
344 <                        checked += 2;
345 <                        /*
346 <                         * Check for loops in the compressed name;
347 <                         * if we've looked at the whole message,
348 <                         * there must be a loop.
349 <                         */
350 <                        if (checked >= eom - msg) {
351 <                                errno = EMSGSIZE;
352 <                                return (-1);
353 <                        }
354 <                        break;
302 >  len = -1;
303 >  checked = 0;
304 >  dstp = dst;
305 >  srcp = src;
306 >  dstlim = dst + dstsiz;
307  
308 <                default:
309 <                        errno = EMSGSIZE;
310 <                        return (-1);                    /* flag error */
311 <                }
312 <        }
313 <        *dstp = '\0';
314 <        if (len < 0)
315 <                len = srcp - src;
316 <        return (len);
308 >  if (srcp < msg || srcp >= eom)
309 >  {
310 >    errno = EMSGSIZE;
311 >    return -1;
312 >  }
313 >
314 >  /* Fetch next label in domain name. */
315 >  while ((n = *srcp++) != 0)
316 >  {
317 >    /* Check for indirection. */
318 >    switch (n & NS_CMPRSFLGS)
319 >    {
320 >      case 0:
321 >      case NS_TYPE_ELT:
322 >        /* Limit checks. */
323 >        if ((l = labellen(srcp - 1)) < 0)
324 >        {
325 >          errno = EMSGSIZE;
326 >          return -1;
327 >        }
328 >
329 >        if (dstp + l + 1 >= dstlim || srcp + l >= eom)
330 >        {
331 >          errno = EMSGSIZE;
332 >          return -1;
333 >        }
334 >
335 >        checked += l + 1;
336 >        *dstp++ = n;
337 >        memcpy(dstp, srcp, l);
338 >
339 >        dstp += l;
340 >        srcp += l;
341 >        break;
342 >
343 >      case NS_CMPRSFLGS:
344 >        if (srcp >= eom)
345 >        {
346 >          errno = EMSGSIZE;
347 >          return -1;
348 >        }
349 >
350 >        if (len < 0)
351 >          len = srcp - src + 1;
352 >        srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
353 >
354 >        if (srcp < msg || srcp >= eom)
355 >        {
356 >          /* Out of range. */
357 >          errno = EMSGSIZE;
358 >          return -1;
359 >        }
360 >
361 >        checked += 2;
362 >
363 >        /*
364 >         * Check for loops in the compressed name;
365 >         * if we've looked at the whole message,
366 >         * there must be a loop.
367 >         */
368 >        if (checked >= eom - msg)
369 >        {
370 >          errno = EMSGSIZE;
371 >          return -1;
372 >        }
373 >
374 >        break;
375 >
376 >      default:
377 >        errno = EMSGSIZE;
378 >        return -1; /* Flag error */
379 >    }
380 >  }
381 >
382 >  *dstp = '\0';
383 >
384 >  if (len < 0)
385 >    len = srcp - src;
386 >
387 >  return len;
388   }
389  
390   /*
# Line 374 | Line 397 | irc_ns_name_unpack(const unsigned char *
397   *      All other domains are returned in non absolute form
398   */
399   static int
400 < irc_ns_name_ntop(const char *src, char *dst, size_t dstsiz)
400 > irc_ns_name_ntop(const unsigned char *src, char *dst, size_t dstsiz)
401   {
402 <        const char *cp;
402 >        const unsigned char *cp;
403          char *dn, *eom;
404          unsigned char c;
405          unsigned int n;
# Line 399 | Line 422 | irc_ns_name_ntop(const char *src, char *
422                          }
423                          *dn++ = '.';
424                  }
425 <                if ((l = labellen((unsigned char*)(cp - 1))) < 0) {
425 >                if ((l = labellen((cp - 1))) < 0) {
426                          errno = EMSGSIZE; /* XXX */
427                          return(-1);
428                  }
# Line 463 | Line 486 | irc_ns_name_ntop(const char *src, char *
486          }
487          *dn++ = '\0';
488          return (dn - dst);
489 < }
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 < }
489 > } /*2*/
490  
491   /*
492   * Skip over a compressed domain name. Return the size or -1.
493   */
494   int
495 < irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom) {
495 > irc_dn_skipname(const unsigned char *ptr, const unsigned char *eom)
496 > {
497    const unsigned char *saveptr = ptr;
498  
499    if (irc_ns_name_skip(&ptr, eom) == -1)
500 <    return(-1);
501 <  return(ptr - saveptr);
500 >    return -1;
501 >  return ptr - saveptr;
502   }
503  
504   /*
# Line 511 | Line 521 | irc_ns_name_skip(const unsigned char **p
521      /* Check for indirection. */
522      switch (n & NS_CMPRSFLGS)
523      {
524 <      case 0: /* normal case, n == len */
524 >      case 0:  /* Normal case, n == len */
525          cp += n;
526          continue;
527 <      case NS_TYPE_ELT: /* EDNS0 extended label */
527 >      case NS_TYPE_ELT:  /* EDNS0 extended label */
528          if ((l = labellen(cp - 1)) < 0)
529          {
530 <          errno = EMSGSIZE; /* XXX */
531 <          return(-1);
530 >          errno = EMSGSIZE;  /* XXX */
531 >          return -1;
532          }
533  
534          cp += l;
535          continue;
536 <      case NS_CMPRSFLGS: /* indirection */
536 >      case NS_CMPRSFLGS:  /* Indirection */
537          cp++;
538          break;
539 <      default: /* illegal type */
539 >      default:  /* Illegal type */
540          errno = EMSGSIZE;
541 <        return(-1);
541 >        return -1;
542      }
543  
544      break;
# Line 537 | Line 547 | irc_ns_name_skip(const unsigned char **p
547    if (cp > eom)
548    {
549      errno = EMSGSIZE;
550 <    return (-1);
550 >    return -1;
551    }
552  
553    *ptrptr = cp;
554 <  return(0);
554 >  return 0;
555   }
556  
557   unsigned int
# Line 550 | Line 560 | irc_ns_get16(const unsigned char *src)
560    unsigned int dst;
561  
562    IRC_NS_GET16(dst, src);
563 <  return(dst);
563 >  return dst;
564   }
565  
566   unsigned long
# Line 559 | Line 569 | irc_ns_get32(const unsigned char *src)
569    unsigned long dst;
570  
571    IRC_NS_GET32(dst, src);
572 <  return(dst);
572 >  return dst;
573   }
574  
575   void
# Line 588 | Line 598 | special(int ch)
598   {
599    switch (ch)
600    {
601 <    case 0x22: /* '"'  */
602 <    case 0x2E: /* '.'  */
603 <    case 0x3B: /* ';'  */
604 <    case 0x5C: /* '\\' */
605 <    case 0x28: /* '('  */
606 <    case 0x29: /* ')'  */
601 >    case 0x22:  /* '"'  */
602 >    case 0x2E:  /* '.'  */
603 >    case 0x3B:  /* ';'  */
604 >    case 0x5C:  /* '\\' */
605 >    case 0x28:  /* '('  */
606 >    case 0x29:  /* ')'  */
607      /* Special modifiers in zone files. */
608 <    case 0x40: /* '@'  */
609 <    case 0x24: /* '$'  */
610 <      return(1);
608 >    case 0x40:  /* '@'  */
609 >    case 0x24:  /* '$'  */
610 >      return 1;
611      default:
612 <      return(0);
612 >      return 0;
613    }
614   }
615  
# Line 611 | Line 621 | labellen(const unsigned char *lp)
621  
622    if ((l & NS_CMPRSFLGS) == NS_CMPRSFLGS)
623    {
624 <    /* should be avoided by the caller */
625 <    return(-1);
624 >    /* Should be avoided by the caller */
625 >    return -1;
626    }
627  
628    if ((l & NS_CMPRSFLGS) == NS_TYPE_ELT)
# Line 621 | Line 631 | labellen(const unsigned char *lp)
631      {
632        if ((bitlen = *(lp + 1)) == 0)
633          bitlen = 256;
634 <      return((bitlen + 7 ) / 8 + 1);
634 >      return (bitlen + 7 ) / 8 + 1;
635      }
636  
637 <    return(-1); /* unknwon ELT */
637 >    return -1;  /* Unknwon ELT */
638    }
639  
640 <  return(l);
640 >  return l;
641   }
642  
643  
# Line 641 | Line 651 | labellen(const unsigned char *lp)
651   static int
652   printable(int ch)
653   {
654 <  return(ch > 0x20 && ch < 0x7f);
654 >  return ch > 0x20 && ch < 0x7f;
655   }
656  
657   static int
658 < irc_decode_bitstring(const char **cpp, char *dn, const char *eom)
658 > irc_decode_bitstring(const unsigned char **cpp, char *dn, const char *eom)
659   {
660 <        const char *cp = *cpp;
660 >        const unsigned char *cp = *cpp;
661          char *beg = dn, tc;
662          int b, blen, plen;
663  
# Line 674 | Line 684 | irc_decode_bitstring(const char **cpp, c
684  
685          *cpp = cp;
686          return(dn - beg);
687 < }
687 > } /*2*/
688  
689   /*
690   * irc_ns_name_pton(src, dst, dstsiz)
# Line 710 | Line 720 | irc_ns_name_pton(const char *src, unsign
720                 cp + 2,
721                 &label,
722                 &bp,
723 <               (const char *)eom))
723 >               eom))
724              != 0) {
725            errno = e;
726            return(-1);
# Line 814 | Line 824 | irc_ns_name_pton(const char *src, unsign
824    }
825  
826    return (0);
827 < }
827 > } /*2*/
828  
829   /*
830   * irc_ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
# Line 846 | Line 856 | irc_ns_name_pack(const unsigned char *sr
856    dstp = dst;
857    eob = dstp + dstsiz;
858    lpp = cpp = NULL;
859 <  if (dnptrs != NULL) {
860 <    if ((msg = *dnptrs++) != NULL) {
859 >
860 >  if (dnptrs != NULL)
861 >  {
862 >    if ((msg = *dnptrs++))
863 >    {
864        for (cpp = dnptrs; *cpp != NULL; cpp++)
865 <        (void)NULL;
866 <      lpp = cpp;  /* end of list to search */
865 >        ;
866 >      lpp = cpp;  /* End of list to search */
867      }
868 <  } else
868 >  }
869 >  else
870      msg = NULL;
871  
872 <  /* make sure the domain we are about to add is legal */
872 >  /* Make sure the domain we are about to add is legal */
873    l = 0;
874 <  do {
874 >  do
875 >  {
876      int l0;
877  
878      n = *srcp;
879 <    if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
879 >    if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS)
880 >    {
881        errno = EMSGSIZE;
882 <      return (-1);
882 >      return -1;
883      }
884 <    if ((l0 = labellen(srcp)) < 0) {
884 >
885 >    if ((l0 = labellen(srcp)) < 0)
886 >    {
887        errno = EINVAL;
888 <      return(-1);
888 >      return -1;
889      }
890 +
891      l += l0 + 1;
892 <    if (l > NS_MAXCDNAME) {
892 >    if (l > NS_MAXCDNAME)
893 >    {
894        errno = EMSGSIZE;
895 <      return (-1);
895 >      return -1;
896      }
897 +
898      srcp += l0 + 1;
899    } while (n != 0);
900  
901 <  /* from here on we need to reset compression pointer array on error */
901 >  /* From here on we need to reset compression pointer array on error */
902    srcp = src;
903 <  do {
903 >  do
904 >  {
905      /* Look to see if we can use pointers. */
906      n = *srcp;
907 <    if (n != 0 && msg != NULL) {
908 <      l = irc_dn_find(srcp, msg, (const unsigned char * const *)dnptrs,
909 <            (const unsigned char * const *)lpp);
910 <      if (l >= 0) {
911 <        if (dstp + 1 >= eob) {
907 >
908 >    if (n != 0 && msg != NULL)
909 >    {
910 >      l = irc_dn_find(srcp, msg, (const unsigned char *const *)dnptrs,
911 >                      (const unsigned char *const *)lpp);
912 >
913 >      if (l >= 0)
914 >      {
915 >        if (dstp + 1 >= eob)
916            goto cleanup;
917 <        }
917 >
918          *dstp++ = (l >> 8) | NS_CMPRSFLGS;
919          *dstp++ = l % 256;
920 <        return (dstp - dst);
920 >        return dstp - dst;
921        }
922 +
923        /* Not found, save it. */
924 <      if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
925 <          (dstp - msg) < 0x4000 && first) {
924 >      if (lastdnptr != NULL && cpp < lastdnptr - 1 && (dstp - msg) < 0x4000 && first)
925 >      {
926          *cpp++ = dstp;
927          *cpp = NULL;
928          first = 0;
929        }
930      }
931 <    /* copy label to buffer */
932 <    if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS) {
933 <      /* Should not happen. */
934 <      goto cleanup;
935 <    }
931 >
932 >    /* Copy label to buffer */
933 >    if ((n & NS_CMPRSFLGS) == NS_CMPRSFLGS)
934 >      goto cleanup;  /* Should not happen. */
935 >
936      n = labellen(srcp);
937 <    if (dstp + 1 + n >= eob) {
937 >    if (dstp + 1 + n >= eob)
938        goto cleanup;
939 <    }
939 >
940      memcpy(dstp, srcp, n + 1);
941      srcp += n + 1;
942      dstp += n + 1;
943    } while (n != 0);
944  
945 <  if (dstp > eob) {
945 >  if (dstp > eob)
946 >  {
947   cleanup:
948      if (msg != NULL)
949        *lpp = NULL;
950      errno = EMSGSIZE;
951 <    return (-1);
951 >    return -1;
952    }
953 <  return(dstp - dst);
953 >
954 >  return dstp - dst;
955   }
956  
957   static int
# Line 932 | Line 961 | irc_ns_name_compress(const char *src, un
961    unsigned char tmp[NS_MAXCDNAME];
962  
963    if (irc_ns_name_pton(src, tmp, sizeof tmp) == -1)
964 <    return(-1);
965 <  return(irc_ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr));
964 >    return -1;
965 >  return irc_ns_name_pack(tmp, dst, dstsiz, dnptrs, lastdnptr);
966   }
967  
968   static int
969   irc_encode_bitsring(const char **bp, const char *end, unsigned char **labelp,
970 <                    unsigned char **dst, const char *eom)
970 >                    unsigned char **dst, const unsigned char *eom)
971   {
972    int afterslash = 0;
973    const char *cp = *bp;
974 <  char *tp, c;
974 >  unsigned char *tp;
975 >  char c;
976    const char *beg_blen;
977    char *end_blen = NULL;
978    int value = 0, count = 0, tbcount = 0, blen = 0;
# Line 959 | Line 989 | irc_encode_bitsring(const char **bp, con
989    if (!isxdigit((*cp) & 0xff)) /* reject '\[x/BLEN]' */
990      return(EINVAL);
991  
992 <  for (tp = (char*)(dst + 1); cp < end && tp < eom; cp++) {
992 >  for (tp = *dst + 1; cp < end && tp < eom; cp++) {
993      switch((c = *cp)) {
994      case ']': /* end of the bitstring */
995        if (afterslash) {
# Line 1036 | Line 1066 | irc_encode_bitsring(const char **bp, con
1066    **dst = blen;
1067  
1068    *bp = cp;
1069 <  *dst = (unsigned char*)tp;
1069 >  *dst = tp;
1070  
1071    return(0);
1072 < }
1072 > } /*2*/
1073  
1074   /*
1075   * dn_find(domain, msg, dnptrs, lastdnptr)
# Line 1108 | Line 1138 | irc_dn_find(const unsigned char *domain,
1138    }
1139    errno = ENOENT;
1140    return (-1);
1141 < }
1141 > } /*2*/
1142  
1143   /*
1144   *  *  Thinking in noninternationalized USASCII (per the DNS spec),
# Line 1121 | Line 1151 | mklower(int ch)
1151      return(ch + 0x20);
1152  
1153    return(ch);
1154 < }
1154 > } /*2*/
1155  
1156   /* From resolv/mkquery.c */
1157  
# Line 1139 | Line 1169 | irc_res_mkquery(
1169          HEADER *hp;
1170          unsigned char *cp;
1171          int n;
1172 <        unsigned char *dnptrs[20], **dpp, **lastdnptr;
1172 >        const unsigned char *dnptrs[20], **dpp, **lastdnptr;
1173  
1174          /*
1175           * Initialize header fields.
# Line 1162 | Line 1192 | irc_res_mkquery(
1192  
1193          if ((buflen -= QFIXEDSZ) < 0)
1194            return (-1);
1195 <        if ((n = irc_dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
1195 >        if ((n = irc_ns_name_compress(dname, cp, buflen, dnptrs,
1196 >                                                         lastdnptr)) < 0)
1197            return (-1);
1198  
1199          cp += n;

Comparing:
ircd-hybrid/src/irc_reslib.c (property svn:keywords), Revision 31 by knight, Sun Oct 2 20:34:05 2005 UTC vs.
ircd-hybrid/trunk/src/reslib.c (property svn:keywords), Revision 3852 by michael, Thu Jun 5 13:12:45 2014 UTC

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

Diff Legend

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