From ak03@gte.com  Thu Sep  7 08:39:37 2000
Return-Path: <ak03@gte.com>
Received: from h132-197-97-45.gte.com (h132-197-97-45.gte.com [132.197.97.45])
	by hub.freebsd.org (Postfix) with ESMTP id EB49F37B443
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  7 Sep 2000 08:39:33 -0700 (PDT)
Received: (from ak03@localhost)
	by h132-197-97-45.gte.com (8.11.0/8.11.0) id e87FdWd07360;
	Thu, 7 Sep 2000 11:39:32 -0400 (EDT)
	(envelope-from ak03)
Message-Id: <200009071539.e87FdWd07360@h132-197-97-45.gte.com>
Date: Thu, 7 Sep 2000 11:39:32 -0400 (EDT)
From: ak03@gte.com
Reply-To: ak03@gte.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: Resolver errors are not reported properly in NIS-only case 
X-Send-Pr-Version: 3.2

>Number:         21092
>Category:       bin
>Synopsis:       _gethostbynis function does not set h_errno on failure
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    nectar
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 07 08:40:00 PDT 2000
>Closed-Date:    Sun Oct 1 09:40:58 PDT 2000
>Last-Modified:  Sun Oct 01 09:41:42 PDT 2000
>Originator:     Alexander Kabaev
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Verizon Laboratories Inc.
>Environment:

FreeBSD kanpc.gte.com 5.0-CURRENT FreeBSD 5.0-CURRENT #0: Wed Sep  6 12:19:50 EDT 2000     root@kanpc.gte.com:/usr/src/sys/compile/KANPC  i386

>Description:

If NIS is selected as the only source used for the name resolution in
host.conf or in nsswitch.conf on newer -CURRENT and then name resolution
attempted for an unknown hostname using gethostbyname* functions, h_error 
is not getting set correctly when resolution fails. 

It seems like _gethostbynis function fails to set h_errno variable to the 
appropriate value when returning. All other functions in the family, i.e.
_gethostbydns and _gethostbyht, do so.

Without attached patch, the following command returns with strange message:

[ak03@kanpc ~]$ ping sjkjss
ping: cannot resolve sjkjss: Resolver Error 0 (no error)
  
With patch applied, ping produces more reasonable output:
[ak03@kanpc ~]$ ping sjkjss
ping: cannot resolve sjkjss: Unknown host

>How-To-Repeat:

Comment out non-nis entries in host.conf or nsswitch.conf and try to ping 
some unknown host.


Index: gethostbynis.c
===================================================================
RCS file: /usr/ncvs/src/lib/libc/net/gethostbynis.c,v
retrieving revision 1.10
diff -u -r1.10 gethostbynis.c
--- gethostbynis.c	1999/08/28 00:00:06	1.10
+++ gethostbynis.c	2000/09/07 15:12:50
@@ -76,15 +76,20 @@
 	case AF_INET6:
 		size = NS_IN6ADDRSZ;
 		errno = EAFNOSUPPORT;
+		h_errno = NETDB_INTERNAL;
 		return NULL;
 	}
 
 	if (domain == (char *)NULL)
-		if (yp_get_default_domain (&domain))
+		if (yp_get_default_domain (&domain)) {
+			h_errno = NETDB_INTERNAL;
 			return ((struct hostent *)NULL);
+		}
 
-	if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
+	if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) {
+		h_errno = HOST_NOT_FOUND;
 		return ((struct hostent *)NULL);
+	}
 
 	/* avoid potential memory leak */
 	bcopy((char *)result, (char *)&ypbuf, resultlen);

>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->nectar 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Fri Sep 8 05:50:03 PDT 2000 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21092 
State-Changed-From-To: open->closed 
State-Changed-By: nectar 
State-Changed-When: Sun Oct 1 09:40:58 PDT 2000 
State-Changed-Why:  
Committed to 4-STABLE, r1.10.2.1 

http://www.freebsd.org/cgi/query-pr.cgi?pr=21092 
>Unformatted:
