about summary refs log tree commit diff
path: root/resolv/res_query.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-07-19 22:03:58 +0000
committerUlrich Drepper <drepper@redhat.com>2000-07-19 22:03:58 +0000
commite685e07dfa9de08cd0b671e293b94efe116349fa (patch)
tree3c283589ea027f9b4ef9062366e9729e87efd46a /resolv/res_query.c
parent80ec4993cc416058f6f8e98ce32bd729e9be1150 (diff)
downloadglibc-e685e07dfa9de08cd0b671e293b94efe116349fa.tar.gz
glibc-e685e07dfa9de08cd0b671e293b94efe116349fa.tar.xz
glibc-e685e07dfa9de08cd0b671e293b94efe116349fa.zip
Update.
2000-07-18  Mark Kettenis  <kettenis@gnu.org>

	Update resolver code to BIND 8.2.3-T5B.

	* resolv/Versions [GLIBC_2.2] (libc): Add __res_init and
	__res_nclose.
	[GLIBC_2.2] (libresolv): Add __dn_expand, __ns_samename,
	__res_mkquery, __res_nsend, __res_query, __res_querydomain and
	__res_search.
	* resolv/Banner: BIND-8.2.3-T5B.

	* resolv/base64.c: Update from BIND 8.2.3-T5B.
	* resolv/herror.c: Likewise.
	* resolv/inet_addr.c: Likewise.
	* resolv/inet_net_ntop.c: Likewise.
	* resolv/inet_net_pton.c: Likewise.
	* resolv/inet_neta.c: Likewise.
	* resolv/inet_ntop.c: Likewise.
	* resolv/nsap_addr.c: Likewise.
	* resolv/inet_pton.c: Likewise.  Reject a few more more invalid
	IPv6 addresses (ISC bug #520).

	* resolv/ns_name.c: Avoid emitting RCS ID in object file.
	* resolv/ns_parse.c: Likewise.
	* resolv/ns_netint.c: Likewise.
	* resolv/ns_samedomain.c: Likewise.
	* resolv/ns_ttl.c: Likewise.
	* resolv/ns_print.c: Update from BIND 8.2.3-T5B.  Avoid emitting
	RCS ID in object file.

	* resolv/res_debug.c: Update from BIND 8.2.3-T5B.
	* resolv/res_mkquery.c: Likewise.
	* resolv/res_query.c: Likewise.
	* resolv/res_init.c: Likewise.
	(res_setoptions): Mark internal.
	* resolv/res_send.c: Likewise.
	[_LIBC]: Fully reinstate the code that avoids the FD_SETSIZE limit
	by using poll instead.
	* resolv/res_comp.c: Likewise.
	[SHLIB_COMPAT (libresolv, GLIBC_2_0, GLIBC_2_2)]: Make dn_expand a
	weak alias for __dn_expand.
	* resolv/res_data.c: Likewise.
	(res_close) [_LIBC]: Don't call res_nclose if RES_INIT isn't set
	in _res.options.  Avoids a potential security risk by avoiding a
	close (0).
	[SHLIB_COMPAT (libresolv, GLIBC_2_0, GLIBC_2_2)]: Make
	res_mkquery, res_query, res_querydomain adn res_search weak
	aliases for __res_mkquery, __res_query, __res_querydomain and
	__res_search.
	* resolv/res_libc.c: (_res): Don't initialize.  Fix res_close
	instead to avoid close(0).
	(res_init): Always use the static resolver context.
	[SHLIB_COMPAT (libc, GLIBC_2.0, GLIBC_2_2)]: Make res_init a weak
	alias for __res_init.

	* resolv/resolv.h: Update from BIND 8.2.3-T5B.  Move definition of
	RES_SET_H_ERRNO and accompanying comment to...
	* include/resolv.h: ... here.

	* resolv/arpa/namser.h: Update from BIND 8.2.3-T5B.
	* resolv/arpa/nameser_compat.h: Likewise.
Diffstat (limited to 'resolv/res_query.c')
-rw-r--r--resolv/res_query.c41
1 files changed, 26 insertions, 15 deletions
diff --git a/resolv/res_query.c b/resolv/res_query.c
index deebf4c62b..00a5e3eec3 100644
--- a/resolv/res_query.c
+++ b/resolv/res_query.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 1988, 1993
  *    The Regents of the University of California.  All rights reserved.
- *
+ * 
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
@@ -13,7 +13,7 @@
  * 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.
- *
+ * 
  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -29,14 +29,14 @@
 
 /*
  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
+ * 
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
  * copyright notice and this permission notice appear in all copies, and that
  * the name of Digital Equipment Corporation not be used in advertising or
  * publicity pertaining to distribution of the document or software without
  * specific, written prior permission.
- *
+ * 
  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
@@ -66,7 +66,7 @@
 
 #if defined(LIBC_SCCS) && !defined(lint)
 static const char sccsid[] = "@(#)res_query.c	8.1 (Berkeley) 6/4/93";
-static const char rcsid[] = "$Id$";
+static const char rcsid[] = "$BINDId: res_query.c,v 8.20 2000/02/29 05:39:12 vixie Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
@@ -184,8 +184,9 @@ res_nsearch(res_state statp,
 	HEADER *hp = (HEADER *) answer;
 	char tmp[NS_MAXDNAME];
 	u_int dots;
-	int trailing_dot, ret;
+	int trailing_dot, ret, saved_herrno;
 	int got_nodata = 0, got_servfail = 0, root_on_list = 0;
+	int tried_as_is = 0;
 
 	__set_errno (0);
 	RES_SET_H_ERRNO(statp, HOST_NOT_FOUND);  /* True if we never query. */
@@ -202,12 +203,19 @@ res_nsearch(res_state statp,
 		return (res_nquery(statp, cp, class, type, answer, anslen));
 
 	/*
-	 * If there are enough dots in the name, do no searching.
-	 * (The threshold can be set with the "ndots" option.)
+	 * If there are enough dots in the name, let's just give it a
+	 * try 'as is'. The threshold can be set with the "ndots" option.
+	 * Also, query 'as is', if there is a trailing dot in the name.
 	 */
-	if (dots >= statp->ndots || trailing_dot)
-		return (res_nquerydomain(statp, name, NULL, class, type,
-					 answer, anslen));
+	saved_herrno = -1;
+	if (dots >= statp->ndots || trailing_dot) {
+		ret = res_nquerydomain(statp, name, NULL, class, type,
+					 answer, anslen);
+		if (ret > 0 || trailing_dot)
+			return (ret);
+		saved_herrno = h_errno;
+		tried_as_is++;
+	}
 
 	/*
 	 * We do at least one level of search if
@@ -279,10 +287,11 @@ res_nsearch(res_state statp,
 	}
 
 	/*
-	 * If the name has any dots at all, and "." is not on the search
-	 * list, then try an as-is query now.
+	 * If the name has any dots at all, and no earlier 'as-is' query 
+	 * for the name, and "." is not on the search list, then try an as-is
+	 * query now.
 	 */
-	if (statp->ndots) {
+	if (statp->ndots && !(tried_as_is || root_on_list)) {
 		ret = res_nquerydomain(statp, name, NULL, class, type,
 				       answer, anslen);
 		if (ret > 0)
@@ -296,7 +305,9 @@ res_nsearch(res_state statp,
 	 * else send back meaningless H_ERRNO, that being the one from
 	 * the last DNSRCH we did.
 	 */
-	if (got_nodata)
+	if (saved_herrno != -1)
+		RES_SET_H_ERRNO(statp, saved_herrno);
+	else if (got_nodata)
 		RES_SET_H_ERRNO(statp, NO_DATA);
 	else if (got_servfail)
 		RES_SET_H_ERRNO(statp, TRY_AGAIN);