Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/resolv/res_init.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/resolv/res_init.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.8 retrieving revision 1.9 diff -u -p -r1.8 -r1.9 --- src/lib/libc/resolv/res_init.c 2006/03/19 03:10:08 1.8 +++ src/lib/libc/resolv/res_init.c 2007/01/27 22:26:44 1.9 @@ -1,4 +1,4 @@ -/* $NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $ */ +/* $NetBSD: res_init.c,v 1.9 2007/01/27 22:26:44 christos Exp $ */ /* * Copyright (c) 1985, 1989, 1993 @@ -74,9 +74,9 @@ #if defined(LIBC_SCCS) && !defined(lint) #ifdef notdef static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; -static const char rcsid[] = "Id: res_init.c,v 1.9.2.5.4.2 2004/03/16 12:34:18 marka Exp"; +static const char rcsid[] = "Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 marka Exp"; #else -__RCSID("$NetBSD: res_init.c,v 1.8 2006/03/19 03:10:08 christos Exp $"); +__RCSID("$NetBSD: res_init.c,v 1.9 2007/01/27 22:26:44 christos Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -120,18 +120,23 @@ __weak_alias(res_setservers,__res_setser #include "res_private.h" -/* Options. Should all be left alone. */ +/*% Options. Should all be left alone. */ +#define RESOLVSORT #ifndef DEBUG #define DEBUG #endif +#ifdef SOLARIS2 +#include +#endif + static void res_setoptions __P((res_state, const char *, const char *)); static const char sort_mask[] = "/&"; #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL) static u_int32_t net_mask __P((struct in_addr)); -#if !defined(isascii) /* XXX - could be a function */ +#if !defined(isascii) /*%< XXX - could be a function */ # define isascii(c) (!(c & 0200)) #endif @@ -139,7 +144,7 @@ static u_int32_t net_mask __P((struct in * 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(). @@ -167,14 +172,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; 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; int nsort = 0; @@ -182,6 +187,9 @@ __res_vinit(res_state statp, int preinit int dots; union res_sockaddr_union u[2]; + if (statp->_u._ext.ext != NULL) + res_ndestroy(statp); + if (!preinit) { statp->retrans = RES_TIMEOUT; statp->retry = RES_DFLRETRY; @@ -189,9 +197,6 @@ __res_vinit(res_state statp, int preinit statp->id = res_randomid(); } - if ((statp->options & RES_INIT) != 0U) - res_ndestroy(statp); - memset(u, 0, sizeof(u)); #ifdef USELOOPBACK u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1); @@ -231,10 +236,34 @@ __res_vinit(res_state statp, int preinit statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); - } + } else + return (-1); +#ifdef RESOLVSORT statp->nsort = 0; res_setservers(statp, u, nserv); +#ifdef SOLARIS2 + /* + * The old libresolv derived the defaultdomain from NIS/NIS+. + * We want to keep this behaviour + */ + { + char buf[sizeof(statp->defdname)], *cp; + int ret; + + if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 && + (unsigned int)ret <= sizeof(buf)) { + if (buf[0] == '+') + buf[0] = '.'; + cp = strchr(buf, '.'); + cp = (cp == NULL) ? buf : (cp + 1); + if (strlen(cp) >= sizeof(statp->defdname)) + goto freedata; + strcpy(statp->defdname, cp); + } + } +#endif /* SOLARIS2 */ + /* Allow user to override the local domain definition */ if ((cp = getenv("LOCALDOMAIN")) != NULL) { (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); @@ -252,7 +281,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; @@ -284,7 +313,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') @@ -300,7 +329,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') @@ -450,7 +479,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--; } @@ -469,6 +498,15 @@ __res_vinit(res_state statp, int preinit res_setoptions(statp, cp, "env"); statp->options |= RES_INIT; return (0); + +#ifdef SOLARIS2 + freedata: + if (statp->_u._ext.ext != NULL) { + free(statp->_u._ext.ext); + statp->_u._ext.ext = NULL; + } + return (-1); +#endif } static void @@ -508,6 +546,22 @@ res_setoptions(res_state statp, const ch if (statp->options & RES_DEBUG) printf(";;\ttimeout=%d\n", statp->retrans); #endif +#ifdef SOLARIS2 + } else if (!strncmp(cp, "retrans:", sizeof("retrans:") - 1)) { + /* + * For backward compatibility, 'retrans' is + * supported as an alias for 'timeout', though + * without an imposed maximum. + */ + statp->retrans = atoi(cp + sizeof("retrans:") - 1); + } else if (!strncmp(cp, "retry:", sizeof("retry:") - 1)){ + /* + * For backward compatibility, 'retry' is + * supported as an alias for 'attempts', though + * without an imposed maximum. + */ + statp->retry = atoi(cp + sizeof("retry:") - 1); +#endif /* SOLARIS2 */ } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){ i = atoi(cp + sizeof("attempts:") - 1); if (i <= RES_MAXRETRY) @@ -586,7 +640,7 @@ res_setoptions(res_state statp, const ch /* 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); @@ -606,7 +660,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. @@ -751,3 +805,5 @@ res_getservers(res_state statp, union re } return (statp->nscount); } + +/*! \file */