Deleted Added
full compact
res_init.c (156953) res_init.c (156956)
1/*
2 * Copyright (c) 1985, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 58 unchanged lines hidden (view full) ---

67 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
68 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
69 */
70
71#if defined(LIBC_SCCS) && !defined(lint)
72static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
73static const char rcsid[] = "$Id: res_init.c,v 1.9.2.5.4.5 2005/11/03 00:00:52 marka Exp $";
74#endif /* LIBC_SCCS and not lint */
1/*
2 * Copyright (c) 1985, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 58 unchanged lines hidden (view full) ---

67 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
68 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
69 */
70
71#if defined(LIBC_SCCS) && !defined(lint)
72static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
73static const char rcsid[] = "$Id: res_init.c,v 1.9.2.5.4.5 2005/11/03 00:00:52 marka Exp $";
74#endif /* LIBC_SCCS and not lint */
75#include <sys/cdefs.h>
76__FBSDID("$FreeBSD: head/lib/libc/resolv/res_init.c 156956 2006-03-21 15:37:16Z ume $");
75
76#include "port_before.h"
77
78#include <sys/types.h>
79#include <sys/param.h>
80#include <sys/socket.h>
81#include <sys/time.h>
82

--- 18 unchanged lines hidden (view full) ---

101/* Options. Should all be left alone. */
102#define RESOLVSORT
103#define DEBUG
104
105#ifdef SOLARIS2
106#include <sys/systeminfo.h>
107#endif
108
77
78#include "port_before.h"
79
80#include <sys/types.h>
81#include <sys/param.h>
82#include <sys/socket.h>
83#include <sys/time.h>
84

--- 18 unchanged lines hidden (view full) ---

103/* Options. Should all be left alone. */
104#define RESOLVSORT
105#define DEBUG
106
107#ifdef SOLARIS2
108#include <sys/systeminfo.h>
109#endif
110
109static void res_setoptions __P((res_state, const char *, const char *));
111static void res_setoptions(res_state, const char *, const char *);
110
111#ifdef RESOLVSORT
112static const char sort_mask[] = "/&";
113#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
112
113#ifdef RESOLVSORT
114static const char sort_mask[] = "/&";
115#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
114static u_int32_t net_mask __P((struct in_addr));
116static u_int32_t net_mask(struct in_addr);
115#endif
116
117#if !defined(isascii) /* XXX - could be a function */
118# define isascii(c) (!(c & 0200))
119#endif
120
121/*
122 * Resolver state default settings.

--- 25 unchanged lines hidden (view full) ---

148 extern int __res_vinit(res_state, int);
149
150 return (__res_vinit(statp, 0));
151}
152
153/* This function has to be reachable by res_data.c but not publically. */
154int
155__res_vinit(res_state statp, int preinit) {
117#endif
118
119#if !defined(isascii) /* XXX - could be a function */
120# define isascii(c) (!(c & 0200))
121#endif
122
123/*
124 * Resolver state default settings.

--- 25 unchanged lines hidden (view full) ---

150 extern int __res_vinit(res_state, int);
151
152 return (__res_vinit(statp, 0));
153}
154
155/* This function has to be reachable by res_data.c but not publically. */
156int
157__res_vinit(res_state statp, int preinit) {
156 register FILE *fp;
157 register char *cp, **pp;
158 register int n;
158 FILE *fp;
159 char *cp, **pp;
160 int n;
159 char buf[BUFSIZ];
160 int nserv = 0; /* number of nameserver records read from file */
161 int haveenv = 0;
162 int havesearch = 0;
163#ifdef RESOLVSORT
164 int nsort = 0;
165 char *net;
166#endif

--- 81 unchanged lines hidden (view full) ---

248 >= sizeof(statp->defdname))
249 goto freedata;
250 }
251 }
252 }
253#endif /* SOLARIS2 */
254
255 /* Allow user to override the local domain definition */
161 char buf[BUFSIZ];
162 int nserv = 0; /* number of nameserver records read from file */
163 int haveenv = 0;
164 int havesearch = 0;
165#ifdef RESOLVSORT
166 int nsort = 0;
167 char *net;
168#endif

--- 81 unchanged lines hidden (view full) ---

250 >= sizeof(statp->defdname))
251 goto freedata;
252 }
253 }
254 }
255#endif /* SOLARIS2 */
256
257 /* Allow user to override the local domain definition */
256 if ((cp = getenv("LOCALDOMAIN")) != NULL) {
258 if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) {
257 (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
258 statp->defdname[sizeof(statp->defdname) - 1] = '\0';
259 haveenv++;
260
261 /*
262 * Set search list to be blank-separated strings
263 * from rest of env value. Permits users of LOCALDOMAIN
264 * to still have a search list, and anyone to set the

--- 120 unchanged lines hidden (view full) ---

385 nserv++;
386 }
387 }
388 continue;
389 }
390#ifdef RESOLVSORT
391 if (MATCH(buf, "sortlist")) {
392 struct in_addr a;
259 (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
260 statp->defdname[sizeof(statp->defdname) - 1] = '\0';
261 haveenv++;
262
263 /*
264 * Set search list to be blank-separated strings
265 * from rest of env value. Permits users of LOCALDOMAIN
266 * to still have a search list, and anyone to set the

--- 120 unchanged lines hidden (view full) ---

387 nserv++;
388 }
389 }
390 continue;
391 }
392#ifdef RESOLVSORT
393 if (MATCH(buf, "sortlist")) {
394 struct in_addr a;
395 struct in6_addr a6;
396 int m, i;
397 u_char *u;
398 struct __res_state_ext *ext = statp->_u._ext.ext;
393
394 cp = buf + sizeof("sortlist") - 1;
395 while (nsort < MAXRESOLVSORT) {
396 while (*cp == ' ' || *cp == '\t')
397 cp++;
398 if (*cp == '\0' || *cp == '\n' || *cp == ';')
399 break;
400 net = cp;

--- 18 unchanged lines hidden (view full) ---

419 } else {
420 statp->sort_list[nsort].mask =
421 net_mask(statp->sort_list[nsort].addr);
422 }
423 } else {
424 statp->sort_list[nsort].mask =
425 net_mask(statp->sort_list[nsort].addr);
426 }
399
400 cp = buf + sizeof("sortlist") - 1;
401 while (nsort < MAXRESOLVSORT) {
402 while (*cp == ' ' || *cp == '\t')
403 cp++;
404 if (*cp == '\0' || *cp == '\n' || *cp == ';')
405 break;
406 net = cp;

--- 18 unchanged lines hidden (view full) ---

425 } else {
426 statp->sort_list[nsort].mask =
427 net_mask(statp->sort_list[nsort].addr);
428 }
429 } else {
430 statp->sort_list[nsort].mask =
431 net_mask(statp->sort_list[nsort].addr);
432 }
433 ext->sort_list[nsort].af = AF_INET;
434 ext->sort_list[nsort].addr.ina =
435 statp->sort_list[nsort].addr;
436 ext->sort_list[nsort].mask.ina.s_addr =
437 statp->sort_list[nsort].mask;
427 nsort++;
428 }
438 nsort++;
439 }
440 else if (inet_pton(AF_INET6, net, &a6) == 1) {
441
442 ext->sort_list[nsort].af = AF_INET6;
443 ext->sort_list[nsort].addr.in6a = a6;
444 u = (u_char *)&ext->sort_list[nsort].mask.in6a;
445 *cp++ = n;
446 net = cp;
447 while (*cp && *cp != ';' &&
448 isascii(*cp) && !isspace(*cp))
449 cp++;
450 m = n;
451 n = *cp;
452 *cp = 0;
453 switch (m) {
454 case '/':
455 m = atoi(net);
456 break;
457 case '&':
458 if (inet_pton(AF_INET6, net, u) == 1) {
459 m = -1;
460 break;
461 }
462 /*FALLTHROUGH*/
463 default:
464 m = sizeof(struct in6_addr) * CHAR_BIT;
465 break;
466 }
467 if (m >= 0) {
468 for (i = 0; i < sizeof(struct in6_addr); i++) {
469 if (m <= 0) {
470 *u = 0;
471 } else {
472 m -= CHAR_BIT;
473 *u = (u_char)~0;
474 if (m < 0)
475 *u <<= -m;
476 }
477 u++;
478 }
479 }
480 statp->sort_list[nsort].addr.s_addr =
481 (u_int32_t)0xffffffff;
482 statp->sort_list[nsort].mask =
483 (u_int32_t)0xffffffff;
484 nsort++;
485 }
429 *cp = n;
430 }
431 continue;
432 }
433#endif
434 if (MATCH(buf, "options")) {
435 res_setoptions(statp, buf + sizeof("options") - 1, "conf");
436 continue;

--- 44 unchanged lines hidden (view full) ---

481 printf(";; res_init()... default dnsrch list:\n");
482 for (pp = statp->dnsrch; *pp; pp++)
483 printf(";;\t%s\n", *pp);
484 printf(";;\t..END..\n");
485 }
486#endif
487 }
488
486 *cp = n;
487 }
488 continue;
489 }
490#endif
491 if (MATCH(buf, "options")) {
492 res_setoptions(statp, buf + sizeof("options") - 1, "conf");
493 continue;

--- 44 unchanged lines hidden (view full) ---

538 printf(";; res_init()... default dnsrch list:\n");
539 for (pp = statp->dnsrch; *pp; pp++)
540 printf(";;\t%s\n", *pp);
541 printf(";;\t..END..\n");
542 }
543#endif
544 }
545
489 if ((cp = getenv("RES_OPTIONS")) != NULL)
546 if (issetugid())
547 statp->options |= RES_NOALIASES;
548 else if ((cp = getenv("RES_OPTIONS")) != NULL)
490 res_setoptions(statp, cp, "env");
491 statp->options |= RES_INIT;
492 return (0);
493
494#ifdef SOLARIS2
495 freedata:
496 if (statp->_u._ext.ext != NULL) {
497 free(statp->_u._ext.ext);
498 statp->_u._ext.ext = NULL;
499 }
500 return (-1);
501#endif
502}
503
504static void
505res_setoptions(res_state statp, const char *options, const char *source)
506{
507 const char *cp = options;
508 int i;
549 res_setoptions(statp, cp, "env");
550 statp->options |= RES_INIT;
551 return (0);
552
553#ifdef SOLARIS2
554 freedata:
555 if (statp->_u._ext.ext != NULL) {
556 free(statp->_u._ext.ext);
557 statp->_u._ext.ext = NULL;
558 }
559 return (-1);
560#endif
561}
562
563static void
564res_setoptions(res_state statp, const char *options, const char *source)
565{
566 const char *cp = options;
567 int i;
568#ifndef _LIBC
509 struct __res_state_ext *ext = statp->_u._ext.ext;
569 struct __res_state_ext *ext = statp->_u._ext.ext;
570#endif
510
511#ifdef DEBUG
512 if (statp->options & RES_DEBUG)
513 printf(";; res_setoptions(\"%s\", \"%s\")...\n",
514 options, source);
515#endif
516 while (*cp) {
517 /* skip leading and inner runs of spaces */

--- 57 unchanged lines hidden (view full) ---

575#endif
576 } else if (!strncmp(cp, "no_tld_query",
577 sizeof("no_tld_query") - 1) ||
578 !strncmp(cp, "no-tld-query",
579 sizeof("no-tld-query") - 1)) {
580 statp->options |= RES_NOTLDQUERY;
581 } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
582 statp->options |= RES_USE_INET6;
571
572#ifdef DEBUG
573 if (statp->options & RES_DEBUG)
574 printf(";; res_setoptions(\"%s\", \"%s\")...\n",
575 options, source);
576#endif
577 while (*cp) {
578 /* skip leading and inner runs of spaces */

--- 57 unchanged lines hidden (view full) ---

636#endif
637 } else if (!strncmp(cp, "no_tld_query",
638 sizeof("no_tld_query") - 1) ||
639 !strncmp(cp, "no-tld-query",
640 sizeof("no-tld-query") - 1)) {
641 statp->options |= RES_NOTLDQUERY;
642 } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
643 statp->options |= RES_USE_INET6;
644 } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) {
645 statp->options |= RES_INSECURE1;
646 } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) {
647 statp->options |= RES_INSECURE2;
583 } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
584 statp->options |= RES_ROTATE;
585 } else if (!strncmp(cp, "no-check-names",
586 sizeof("no-check-names") - 1)) {
587 statp->options |= RES_NOCHECKNAME;
588 }
589#ifdef RES_USE_EDNS0
590 else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
591 statp->options |= RES_USE_EDNS0;
592 }
593#endif
648 } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
649 statp->options |= RES_ROTATE;
650 } else if (!strncmp(cp, "no-check-names",
651 sizeof("no-check-names") - 1)) {
652 statp->options |= RES_NOCHECKNAME;
653 }
654#ifdef RES_USE_EDNS0
655 else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
656 statp->options |= RES_USE_EDNS0;
657 }
658#endif
659#ifndef _LIBC
594 else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
595 statp->options |= RES_USE_DNAME;
596 }
597 else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
598 if (ext == NULL)
599 goto skip;
600 cp += sizeof("nibble:") - 1;
601 i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);

--- 13 unchanged lines hidden (view full) ---

615 /* "nibble" and "bitstring" used to be valid */
616 if (!strncmp(cp, "single", sizeof("single") - 1)) {
617 statp->options |= RES_NO_NIBBLE2;
618 } else if (!strncmp(cp, "both", sizeof("both") - 1)) {
619 statp->options &=
620 ~RES_NO_NIBBLE2;
621 }
622 }
660 else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
661 statp->options |= RES_USE_DNAME;
662 }
663 else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) {
664 if (ext == NULL)
665 goto skip;
666 cp += sizeof("nibble:") - 1;
667 i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1);

--- 13 unchanged lines hidden (view full) ---

681 /* "nibble" and "bitstring" used to be valid */
682 if (!strncmp(cp, "single", sizeof("single") - 1)) {
683 statp->options |= RES_NO_NIBBLE2;
684 } else if (!strncmp(cp, "both", sizeof("both") - 1)) {
685 statp->options &=
686 ~RES_NO_NIBBLE2;
687 }
688 }
689#endif
623 else {
624 /* XXX - print a warning here? */
625 }
690 else {
691 /* XXX - print a warning here? */
692 }
693#ifndef _LIBC
626 skip:
694 skip:
695#endif
627 /* skip to next run of spaces */
628 while (*cp && *cp != ' ' && *cp != '\t')
629 cp++;
630 }
631}
632
633#ifdef RESOLVSORT
634/* XXX - should really support CIDR which means explicit masks always. */
635static u_int32_t
636net_mask(in) /* XXX - should really use system's version of this */
637 struct in_addr in;
638{
696 /* skip to next run of spaces */
697 while (*cp && *cp != ' ' && *cp != '\t')
698 cp++;
699 }
700}
701
702#ifdef RESOLVSORT
703/* XXX - should really support CIDR which means explicit masks always. */
704static u_int32_t
705net_mask(in) /* XXX - should really use system's version of this */
706 struct in_addr in;
707{
639 register u_int32_t i = ntohl(in.s_addr);
708 u_int32_t i = ntohl(in.s_addr);
640
641 if (IN_CLASSA(i))
642 return (htonl(IN_CLASSA_NET));
643 else if (IN_CLASSB(i))
644 return (htonl(IN_CLASSB_NET));
645 return (htonl(IN_CLASSC_NET));
646}
647#endif

--- 34 unchanged lines hidden (view full) ---

682res_ndestroy(res_state statp) {
683 res_nclose(statp);
684 if (statp->_u._ext.ext != NULL)
685 free(statp->_u._ext.ext);
686 statp->options &= ~RES_INIT;
687 statp->_u._ext.ext = NULL;
688}
689
709
710 if (IN_CLASSA(i))
711 return (htonl(IN_CLASSA_NET));
712 else if (IN_CLASSB(i))
713 return (htonl(IN_CLASSB_NET));
714 return (htonl(IN_CLASSC_NET));
715}
716#endif

--- 34 unchanged lines hidden (view full) ---

751res_ndestroy(res_state statp) {
752 res_nclose(statp);
753 if (statp->_u._ext.ext != NULL)
754 free(statp->_u._ext.ext);
755 statp->options &= ~RES_INIT;
756 statp->_u._ext.ext = NULL;
757}
758
759#ifndef _LIBC
690const char *
691res_get_nibblesuffix(res_state statp) {
692 if (statp->_u._ext.ext)
693 return (statp->_u._ext.ext->nsuffix);
694 return ("ip6.arpa");
695}
696
697const char *
698res_get_nibblesuffix2(res_state statp) {
699 if (statp->_u._ext.ext)
700 return (statp->_u._ext.ext->nsuffix2);
701 return ("ip6.int");
702}
760const char *
761res_get_nibblesuffix(res_state statp) {
762 if (statp->_u._ext.ext)
763 return (statp->_u._ext.ext->nsuffix);
764 return ("ip6.arpa");
765}
766
767const char *
768res_get_nibblesuffix2(res_state statp) {
769 if (statp->_u._ext.ext)
770 return (statp->_u._ext.ext->nsuffix2);
771 return ("ip6.int");
772}
773#endif
703
704void
705res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) {
706 int i, nserv;
707 size_t size;
708
709 /* close open servers */
710 res_nclose(statp);

--- 89 unchanged lines hidden ---
774
775void
776res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) {
777 int i, nserv;
778 size_t size;
779
780 /* close open servers */
781 res_nclose(statp);

--- 89 unchanged lines hidden ---