Bug 9871

Summary: getaddrinfo() isn't obeying search rules...
Product: [Retired] Red Hat Linux Reporter: Rob Seace <rob>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 8.0CC: fweimer, ryan
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-04-21 23:54:11 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Test program to illustrate getaddrinfo()'s misbehavior... none

Description Rob Seace 2000-02-29 21:45:20 UTC
It looks to me (based on "strace" output, after noticing some odd slowness
trying to lookup "localhost") that getaddrinfo() is ignoring the search
orders specified in either "/etc/host.conf" or "/etc/nsswitch.conf", and
instead is always trying a DNS lookup first, and a local "/etc/hosts"
lookup last (which is just an utterly bass-ackwards way of doing things,
even as a hard-coded default, IMHO)...  It should further be noted that
gethostbyname() does NOT exhibit this same flaw; it correctly uses the
defined search orders, and so a lookup of "localhost" via it never tries
a DNS query at all...  But, for some reason getaddrinfo() is behaving
differently, and ALWAYS wants to do the DNS query (and, FIRST)...  Which,
of course, can be a pain, for looking up simple local stuff like that...
(And, no, I can't just switch to using gethostbyname() instead...  I need
a thread-safe function for one thing, and gethostbyname() is NOT...  And,
I want to code for future IPv6 compatibility, so getaddrinfo() is the best
choice...)

Comment 1 Rob Seace 2000-03-13 17:16:59 UTC
Created attachment 152 [details]
Test program to illustrate getaddrinfo()'s misbehavior...

Comment 2 Cristian Gafton 2000-05-22 14:52:59 UTC
assign to jakub

Comment 3 Ryan Koski 2002-12-26 17:41:56 UTC
This bug still exists in 8.0 (glibc 2.2.93-5).  Thanks much to Mr. Seace for the
test program.

This causes, among other things, a problem with the default sendmail config
where it only listens to 127.0.0.1.  Even though I have both the FQDN and short
hostname assigned to 127.0.0.1 in /etc/hosts, and "hosts: files dns" in
/etc/nsswitch.conf, glibc is always using DNS.  Therefore, when sendmail,
running on the local box, tries to connect to the FQDN of the local box, it
pulls the eth0 IP from DNS instead of the 127.0.0.1 from /etc/hosts, and it
can't connect.

Interestingly enough, if I change /etc/nsswitch.conf to:

hosts: files [NOTFOUND=return] dns

then getaddrinfo() actually returns the correct IP from /etc/hosts (which seems
contrary to the meaning of "NOTFOUND").  Of course, if I do this, then I cannot
resolve any names from DNS whatsoever...

Please fix!  I pay cash bribes under the table as necessary. ;-)


Comment 4 Ulrich Drepper 2003-04-21 23:54:11 UTC
Try it with RHL9.  Running the test program on an RHL9 system with an
nsswitch.conf entry like

hosts: files dns

does not show any DNS activity in the strace log.