From tegge@not.fast.no  Wed Sep  9 18:55:24 1998
Received: from midten.fast.no (midten.fast.no [195.139.251.11])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA01409
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 9 Sep 1998 18:55:22 -0700 (PDT)
          (envelope-from tegge@not.fast.no)
Received: from not.fast.no (IDENT:tegge@not.fast.no [195.139.251.12])
	by midten.fast.no (8.9.1/8.9.1) with ESMTP id DAA08062
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 10 Sep 1998 03:55:13 +0200 (CEST)
Received: (from tegge@localhost)
	by not.fast.no (8.8.8/8.8.8) id DAA13840;
	Thu, 10 Sep 1998 03:55:12 +0200 (CEST)
	(envelope-from tegge@not.fast.no)
Message-Id: <199809100155.DAA13840@not.fast.no>
Date: Thu, 10 Sep 1998 03:55:12 +0200 (CEST)
From: Tor Egge <tegge@not.fast.no>
Reply-To: tegge@not.fast.no
To: FreeBSD-gnats-submit@freebsd.org
Subject: gethostbyname flags temporary failure as unknown host
X-Send-Pr-Version: 3.2

>Number:         7876
>Category:       bin
>Synopsis:       gethostbyname flags temporary failure as unknown host
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    tegge
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep  9 19:00:00 PDT 1998
>Closed-Date:    Thu Nov 15 18:30:24 2001
>Last-Modified:  Thu Nov 15 18:32:44 PST 2001
>Originator:     Tor Egge
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Fast Search & Transfer ASA
>Environment:

FreeBSD 3.0-current from Jul 30 1998

FreeBSD not.fast.no 3.0-CURRENT FreeBSD 3.0-CURRENT #15: Sat Sep  5 18:24:21 CEST 1998     root@not.fast.no:/usr/src/sys/compile/NOT_SMP  i386

>Description:

If hosts is after bind in /etc/host.conf, the error code from the 
DNS lookup is overwritten by the error code from the /etc/hosts lookup.

This means that temporary lookup failures are incorrectly flagged as
permanent lookup failures.

>How-To-Repeat:

Add rules to sendmail 8.9.1 to reject mail from hosts not registered in DNS.

Be a victim of routing problems, cutting you off from all root name servers.

Wait for cached entries to time out in your local name server.

Discover that sendmail has bounced email from a machine properly registered in
DNS.

>Fix:

Index: lib/libc/net/gethostnamadr.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/net/gethostnamadr.c,v
retrieving revision 1.13
diff -u -r1.13 gethostnamadr.c
--- gethostnamadr.c	1997/12/25 04:21:08	1.13
+++ gethostnamadr.c	1998/09/10 01:23:36
@@ -136,6 +136,7 @@
 {
 	struct hostent *hp = 0;
 	int nserv = 0;
+	int tempfail = NETDB_SUCCESS;
 
 	if (!service_done)
 		init_services();
@@ -143,12 +144,17 @@
 	while (!hp) {
 		switch (service_order[nserv]) {
 		      case SERVICE_NONE:
+			if (tempfail != NETDB_SUCCESS &&
+			    h_errno == HOST_NOT_FOUND)
+			  h_errno = tempfail;
 			return NULL;
 		      case SERVICE_HOSTS:
 			hp = _gethostbyhtname(name, type);
 			break;
 		      case SERVICE_BIND:
 			hp = _gethostbydnsname(name, type);
+			if (hp == NULL)
+			  tempfail = h_errno;
 			break;
 		      case SERVICE_NIS:
 			hp = _gethostbynisname(name, type);
@@ -164,6 +170,7 @@
 {
 	struct hostent *hp = 0;
 	int nserv = 0;
+	int tempfail = NETDB_SUCCESS;
 
 	if (!service_done)
 		init_services();
@@ -171,12 +178,17 @@
 	while (!hp) {
 		switch (service_order[nserv]) {
 		      case SERVICE_NONE:
-			return 0;
+			if (tempfail != NETDB_SUCCESS && 
+			    h_errno == HOST_NOT_FOUND)
+			  h_errno = tempfail;
+			return NULL;
 		      case SERVICE_HOSTS:
 			hp = _gethostbyhtaddr(addr, len, type);
 			break;
 		      case SERVICE_BIND:
 			hp = _gethostbydnsaddr(addr, len, type);
+			if (hp == NULL)
+			  tempfail = h_errno;
 			break;
 		      case SERVICE_NIS:
 			hp = _gethostbynisaddr(addr, len, type);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->tegge 
Responsible-Changed-By: mike 
Responsible-Changed-When: Thu Jul 19 12:31:42 PDT 2001 
Responsible-Changed-Why:  

Originator is a committer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=7876

State-Changed-From-To: open->closed
State-Changed-By: tegge
State-Changed-When: Thu Nov 15 18:30:24 2001
State-Changed-Why:
Overtaken by changes in libc to use nsswitch.conf.  Programs needing
to differentiate between permanent and temporary failures should not
use gethostbyname().
>Unformatted:
