diff options
Diffstat (limited to 'lib/libc/resolv/res_init.c')
-rw-r--r-- | lib/libc/resolv/res_init.c | 125 |
1 files changed, 97 insertions, 28 deletions
diff --git a/lib/libc/resolv/res_init.c b/lib/libc/resolv/res_init.c index 013a3ca..f8e4c67 100644 --- a/lib/libc/resolv/res_init.c +++ b/lib/libc/resolv/res_init.c @@ -10,10 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. @@ -70,11 +66,15 @@ #if defined(LIBC_SCCS) && !defined(lint) static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "$Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 marka Exp $"; +static const char rcsid[] = "$Id: res_init.c,v 1.9.2.5.4.6 2006/08/30 23:23:01 marka Exp $"; #endif /* LIBC_SCCS and not lint */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); #include "port_before.h" +#include "namespace.h" + #include <sys/types.h> #include <sys/param.h> #include <sys/socket.h> @@ -91,6 +91,8 @@ static const char rcsid[] = "$Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 mar #include <unistd.h> #include <netdb.h> +#include "un-namespace.h" + #include "port_after.h" /* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */ @@ -98,7 +100,7 @@ static const char rcsid[] = "$Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 mar #include "res_private.h" -/*% Options. Should all be left alone. */ +/* Options. Should all be left alone. */ #define RESOLVSORT #define DEBUG @@ -106,15 +108,15 @@ static const char rcsid[] = "$Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 mar #include <sys/systeminfo.h> #endif -static void res_setoptions __P((res_state, const char *, const char *)); +static void res_setoptions(res_state, const char *, const char *); #ifdef RESOLVSORT static const char sort_mask[] = "/&"; #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) -static u_int32_t net_mask __P((struct in_addr)); +static u_int32_t net_mask(struct in_addr); #endif -#if !defined(isascii) /*%< XXX - could be a function */ +#if !defined(isascii) /* XXX - could be a function */ # define isascii(c) (!(c & 0200)) #endif @@ -122,7 +124,7 @@ static u_int32_t net_mask __P((struct in_addr)); * Resolver state default settings. */ -/*% +/* * Set up default settings. If the configuration file exist, the values * there will have precedence. Otherwise, the server address is set to * INADDR_ANY and the default domain name comes from the gethostname(). @@ -150,14 +152,14 @@ res_ninit(res_state statp) { return (__res_vinit(statp, 0)); } -/*% This function has to be reachable by res_data.c but not publically. */ +/* This function has to be reachable by res_data.c but not publically. */ int __res_vinit(res_state statp, int preinit) { - register FILE *fp; - register char *cp, **pp; - register int n; + FILE *fp; + char *cp, **pp; + int n; char buf[BUFSIZ]; - int nserv = 0; /*%< number of nameserver records read from file */ + int nserv = 0; /* number of nameserver records read from file */ int haveenv = 0; int havesearch = 0; #ifdef RESOLVSORT @@ -246,7 +248,7 @@ __res_vinit(res_state statp, int preinit) { #endif /* SOLARIS2 */ /* Allow user to override the local domain definition */ - if ((cp = getenv("LOCALDOMAIN")) != NULL) { + if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) { (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); statp->defdname[sizeof(statp->defdname) - 1] = '\0'; haveenv++; @@ -262,7 +264,7 @@ __res_vinit(res_state statp, int preinit) { pp = statp->dnsrch; *pp++ = cp; for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { - if (*cp == '\n') /*%< silly backwards compat */ + if (*cp == '\n') /* silly backwards compat */ break; else if (*cp == ' ' || *cp == '\t') { *cp = 0; @@ -294,7 +296,7 @@ __res_vinit(res_state statp, int preinit) { continue; /* read default domain name */ if (MATCH(buf, "domain")) { - if (haveenv) /*%< skip if have from environ */ + if (haveenv) /* skip if have from environ */ continue; cp = buf + sizeof("domain") - 1; while (*cp == ' ' || *cp == '\t') @@ -310,7 +312,7 @@ __res_vinit(res_state statp, int preinit) { } /* set search list */ if (MATCH(buf, "search")) { - if (haveenv) /*%< skip if have from environ */ + if (haveenv) /* skip if have from environ */ continue; cp = buf + sizeof("search") - 1; while (*cp == ' ' || *cp == '\t') @@ -383,6 +385,10 @@ __res_vinit(res_state statp, int preinit) { #ifdef RESOLVSORT if (MATCH(buf, "sortlist")) { struct in_addr a; + struct in6_addr a6; + int m, i; + u_char *u; + struct __res_state_ext *ext = statp->_u._ext.ext; cp = buf + sizeof("sortlist") - 1; while (nsort < MAXRESOLVSORT) { @@ -417,6 +423,57 @@ __res_vinit(res_state statp, int preinit) { statp->sort_list[nsort].mask = net_mask(statp->sort_list[nsort].addr); } + ext->sort_list[nsort].af = AF_INET; + ext->sort_list[nsort].addr.ina = + statp->sort_list[nsort].addr; + ext->sort_list[nsort].mask.ina.s_addr = + statp->sort_list[nsort].mask; + nsort++; + } + else if (inet_pton(AF_INET6, net, &a6) == 1) { + + ext->sort_list[nsort].af = AF_INET6; + ext->sort_list[nsort].addr.in6a = a6; + u = (u_char *)&ext->sort_list[nsort].mask.in6a; + *cp++ = n; + net = cp; + while (*cp && *cp != ';' && + isascii(*cp) && !isspace(*cp)) + cp++; + m = n; + n = *cp; + *cp = 0; + switch (m) { + case '/': + m = atoi(net); + break; + case '&': + if (inet_pton(AF_INET6, net, u) == 1) { + m = -1; + break; + } + /*FALLTHROUGH*/ + default: + m = sizeof(struct in6_addr) * CHAR_BIT; + break; + } + if (m >= 0) { + for (i = 0; i < sizeof(struct in6_addr); i++) { + if (m <= 0) { + *u = 0; + } else { + m -= CHAR_BIT; + *u = (u_char)~0; + if (m < 0) + *u <<= -m; + } + u++; + } + } + statp->sort_list[nsort].addr.s_addr = + (u_int32_t)0xffffffff; + statp->sort_list[nsort].mask = + (u_int32_t)0xffffffff; nsort++; } *cp = n; @@ -464,7 +521,7 @@ __res_vinit(res_state statp, int preinit) { while (pp < statp->dnsrch + MAXDFLSRCH) { if (dots < LOCALDOMAINPARTS) break; - cp = strchr(cp, '.') + 1; /*%< we know there is one */ + cp = strchr(cp, '.') + 1; /* we know there is one */ *pp++ = cp; dots--; } @@ -479,7 +536,9 @@ __res_vinit(res_state statp, int preinit) { #endif } - if ((cp = getenv("RES_OPTIONS")) != NULL) + if (issetugid()) + statp->options |= RES_NOALIASES; + else if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env"); statp->options |= RES_INIT; return (0); @@ -499,7 +558,9 @@ res_setoptions(res_state statp, const char *options, const char *source) { const char *cp = options; int i; +#ifndef _LIBC struct __res_state_ext *ext = statp->_u._ext.ext; +#endif #ifdef DEBUG if (statp->options & RES_DEBUG) @@ -573,6 +634,10 @@ res_setoptions(res_state statp, const char *options, const char *source) statp->options |= RES_NOTLDQUERY; } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { statp->options |= RES_USE_INET6; + } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) { + statp->options |= RES_INSECURE1; + } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) { + statp->options |= RES_INSECURE2; } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) { statp->options |= RES_ROTATE; } else if (!strncmp(cp, "no-check-names", @@ -584,6 +649,7 @@ res_setoptions(res_state statp, const char *options, const char *source) statp->options |= RES_USE_EDNS0; } #endif +#ifndef _LIBC else if (!strncmp(cp, "dname", sizeof("dname") - 1)) { statp->options |= RES_USE_DNAME; } @@ -613,10 +679,13 @@ res_setoptions(res_state statp, const char *options, const char *source) ~RES_NO_NIBBLE2; } } +#endif else { /* XXX - print a warning here? */ } +#ifndef _LIBC skip: +#endif /* skip to next run of spaces */ while (*cp && *cp != ' ' && *cp != '\t') cp++; @@ -626,10 +695,10 @@ res_setoptions(res_state statp, const char *options, const char *source) #ifdef RESOLVSORT /* XXX - should really support CIDR which means explicit masks always. */ static u_int32_t -net_mask(in) /*!< XXX - should really use system's version of this */ +net_mask(in) /* XXX - should really use system's version of this */ struct in_addr in; { - register u_int32_t i = ntohl(in.s_addr); + u_int32_t i = ntohl(in.s_addr); if (IN_CLASSA(i)) return (htonl(IN_CLASSA_NET)); @@ -647,7 +716,7 @@ res_randomid(void) { return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid())); } -/*% +/* * This routine is for closing the socket if a virtual circuit is used and * the program wants to close it. This provides support for endhostent() * which expects to close the socket. @@ -659,13 +728,13 @@ res_nclose(res_state statp) { int ns; if (statp->_vcsock >= 0) { - (void) close(statp->_vcsock); + (void) _close(statp->_vcsock); statp->_vcsock = -1; statp->_flags &= ~(RES_F_VC | RES_F_CONN); } for (ns = 0; ns < statp->_u._ext.nscount; ns++) { if (statp->_u._ext.nssocks[ns] != -1) { - (void) close(statp->_u._ext.nssocks[ns]); + (void) _close(statp->_u._ext.nssocks[ns]); statp->_u._ext.nssocks[ns] = -1; } } @@ -680,6 +749,7 @@ res_ndestroy(res_state statp) { statp->_u._ext.ext = NULL; } +#ifndef _LIBC const char * res_get_nibblesuffix(res_state statp) { if (statp->_u._ext.ext) @@ -693,6 +763,7 @@ res_get_nibblesuffix2(res_state statp) { return (statp->_u._ext.ext->nsuffix2); return ("ip6.int"); } +#endif void res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) { @@ -790,5 +861,3 @@ res_getservers(res_state statp, union res_sockaddr_union *set, int cnt) { } return (statp->nscount); } - -/*! \file */ |