summaryrefslogtreecommitdiff
path: root/lib/bind/resolv
diff options
context:
space:
mode:
authorDoug Barton <dougb@FreeBSD.org>2008-07-12 08:12:46 +0000
committerDoug Barton <dougb@FreeBSD.org>2008-07-12 08:12:46 +0000
commitcba78608de638f8cc6d1d48a2b3072e82386b70d (patch)
tree2857dd6ab984105d7ac37bbcfc816607c48ccc1d /lib/bind/resolv
parentf16b9a8f9e30675de8048c5832ffbb3f50f2fdc4 (diff)
Notes
Diffstat (limited to 'lib/bind/resolv')
-rw-r--r--lib/bind/resolv/res_data.c8
-rw-r--r--lib/bind/resolv/res_init.c41
-rw-r--r--lib/bind/resolv/res_send.c28
3 files changed, 51 insertions, 26 deletions
diff --git a/lib/bind/resolv/res_data.c b/lib/bind/resolv/res_data.c
index 204e03d685f4e..1b9078cffdb54 100644
--- a/lib/bind/resolv/res_data.c
+++ b/lib/bind/resolv/res_data.c
@@ -16,7 +16,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp $";
+static const char rcsid[] = "$Id: res_data.c,v 1.1.206.3 2007/09/14 05:35:51 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -40,7 +40,6 @@ static const char rcsid[] = "$Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 mar
#include <unistd.h>
#include "port_after.h"
-#undef _res
const char *_res_opcodes[] = {
"QUERY",
@@ -70,6 +69,7 @@ const char *_res_sectioncodes[] = {
};
#endif
+#undef _res
#ifndef __BIND_NOSTATIC
struct __res_state _res
# if defined(__BIND_RES_TEXT)
@@ -77,6 +77,10 @@ struct __res_state _res
# endif
;
+#if defined(DO_PTHREADS) || defined(__linux)
+#define _res (*__res_state())
+#endif
+
/* Proto. */
int res_ourserver_p(const res_state, const struct sockaddr_in *);
diff --git a/lib/bind/resolv/res_init.c b/lib/bind/resolv/res_init.c
index fd82e87203c05..22ad874da738a 100644
--- a/lib/bind/resolv/res_init.c
+++ b/lib/bind/resolv/res_init.c
@@ -70,7 +70,7 @@
#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.9.2.5.4.6 2006/08/30 23:23:01 marka Exp $";
+static const char rcsid[] = "$Id: res_init.c,v 1.9.2.5.4.8 2007/07/09 01:54:03 marka Exp $";
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
@@ -166,7 +166,9 @@ __res_vinit(res_state statp, int preinit) {
#endif
int dots;
union res_sockaddr_union u[2];
+ int maxns = MAXNS;
+ RES_SET_H_ERRNO(statp, 0);
if (statp->_u._ext.ext != NULL)
res_ndestroy(statp);
@@ -216,8 +218,22 @@ __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);
+ } else {
+ /*
+ * Historically res_init() rarely, if at all, failed.
+ * Examples and applications exist which do not check
+ * our return code. Furthermore several applications
+ * simply call us to get the systems domainname. So
+ * rather then immediately fail here we store the
+ * failure, which is returned later, in h_errno. And
+ * prevent the collection of 'nameserver' information
+ * by setting maxns to 0. Thus applications that fail
+ * to check our return code wont be able to make
+ * queries anyhow.
+ */
+ RES_SET_H_ERRNO(statp, NETDB_INTERNAL);
+ maxns = 0;
+ }
#ifdef RESOLVSORT
statp->nsort = 0;
#endif
@@ -238,9 +254,9 @@ __res_vinit(res_state statp, int preinit) {
buf[0] = '.';
cp = strchr(buf, '.');
cp = (cp == NULL) ? buf : (cp + 1);
- if (strlen(cp) >= sizeof(statp->defdname))
- goto freedata;
- strcpy(statp->defdname, cp);
+ strncpy(statp->defdname, cp,
+ sizeof(statp->defdname) - 1);
+ statp->defdname[sizeof(statp->defdname) - 1] = '\0';
}
}
#endif /* SOLARIS2 */
@@ -346,7 +362,7 @@ __res_vinit(res_state statp, int preinit) {
continue;
}
/* read nameservers to query */
- if (MATCH(buf, "nameserver") && nserv < MAXNS) {
+ if (MATCH(buf, "nameserver") && nserv < maxns) {
struct addrinfo hints, *ai;
char sbuf[NI_MAXSERV];
const size_t minsiz =
@@ -482,16 +498,7 @@ __res_vinit(res_state statp, int preinit) {
if ((cp = getenv("RES_OPTIONS")) != NULL)
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
+ return (statp->res_h_errno);
}
static void
diff --git a/lib/bind/resolv/res_send.c b/lib/bind/resolv/res_send.c
index c47dd49bc6e8b..bc3cc923814aa 100644
--- a/lib/bind/resolv/res_send.c
+++ b/lib/bind/resolv/res_send.c
@@ -70,7 +70,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id: res_send.c,v 1.5.2.2.4.9 2006/10/16 23:00:50 marka Exp $";
+static const char rcsid[] = "$Id: res_send.c,v 1.5.2.2.4.11 2008/01/27 02:06:07 marka Exp $";
#endif /* LIBC_SCCS and not lint */
/*
@@ -288,7 +288,7 @@ int
res_nsend(res_state statp,
const u_char *buf, int buflen, u_char *ans, int anssiz)
{
- int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
+ int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n;
char abuf[NI_MAXHOST];
#ifdef USE_POLL
@@ -400,7 +400,7 @@ res_nsend(res_state statp,
/*
* Send request, RETRY times, or until successful.
*/
- for (try = 0; try < statp->retry; try++) {
+ for (tries = 0; tries < statp->retry; tries++) {
for (ns = 0; ns < statp->nscount; ns++) {
struct sockaddr *nsap;
int nsaplen;
@@ -448,7 +448,7 @@ res_nsend(res_state statp,
if (v_circuit) {
/* Use VC; at most one attempt per server. */
- try = statp->retry;
+ tries = statp->retry;
n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
ns);
if (n < 0)
@@ -459,7 +459,7 @@ res_nsend(res_state statp,
} else {
/* Use datagrams. */
n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
- ns, try, &v_circuit, &gotsomewhere);
+ ns, tries, &v_circuit, &gotsomewhere);
if (n < 0)
goto fail;
if (n == 0)
@@ -596,6 +596,9 @@ send_vc(res_state statp,
u_short len;
u_char *cp;
void *tmp;
+#ifdef SO_NOSIGPIPE
+ int on = 1;
+#endif
nsap = get_nsaddr(statp, ns);
nsaplen = get_salen(nsap);
@@ -641,6 +644,17 @@ send_vc(res_state statp,
return (-1);
}
}
+#ifdef SO_NOSIGPIPE
+ /*
+ * Disable generation of SIGPIPE when writing to a closed
+ * socket. Write should return -1 and set errno to EPIPE
+ * instead.
+ *
+ * Push on even if setsockopt(SO_NOSIGPIPE) fails.
+ */
+ (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on,
+ sizeof(on));
+#endif
errno = 0;
if (connect(statp->_vcsock, nsap, nsaplen) < 0) {
*terrno = errno;
@@ -768,7 +782,7 @@ send_vc(res_state statp,
static int
send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans,
- int anssiz, int *terrno, int ns, int try, int *v_circuit,
+ int anssiz, int *terrno, int ns, int tries, int *v_circuit,
int *gotsomewhere)
{
const HEADER *hp = (const HEADER *) buf;
@@ -850,7 +864,7 @@ send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans,
/*
* Wait for reply.
*/
- seconds = (statp->retrans << try);
+ seconds = (statp->retrans << tries);
if (ns > 0)
seconds /= statp->nscount;
if (seconds <= 0)