This service will be undergoing maintenance at 20:00 UTC, 2017-04-03. It is expected to last about 30 minutes
Bug 73852 - HOSTALIASES environment variable not used by resolver
HOSTALIASES environment variable not used by resolver
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
8.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-09-12 04:40 EDT by Gordon Messmer
Modified: 2016-11-24 09:55 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-12-15 17:58:44 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Test case for gethostbyname() (512 bytes, text/plain)
2002-09-12 04:48 EDT, Gordon Messmer
no flags Details

  None (edit)
Description Gordon Messmer 2002-09-12 04:40:32 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 Galeon/1.2.5 (X11; Linux i686; U;) Gecko/20020809

Description of problem:
The man page for the function gethostbyname() documents that the HOSTALIASES
environment variable will be used as an alternate "hosts" file if set.  This
hasn't worked since release 7.0.

I will attach a test case which demonstrates the problem.  On my systems
(currently 7.3 and (null)), the variable is never used.  strace/ltrace never
shows the variable looked up.

How reproducible:
Always

Steps to Reproduce:
1. Create a host aliases file:
cat > $HOME/hosts <<EOF
127.0.0.1     www.localdomain
EOF

2. export HOSTALIASES=$HOME/hosts

3. Compile test case:  gcc test-gethostbyname.c -o test-gethostbyname

4. ./test-gethostbyname mail.localdomain


Actual Results:  Regardless of what name or address you put in the hosts file,
it never gets looked up.  The environment variable is ignored.

Expected Results:  The file should be opened by the resolver functions, and
hosts listed there should resolve.

Additional info:
Comment 1 Gordon Messmer 2002-09-12 04:48:27 EDT
Created attachment 75884 [details]
Test case for gethostbyname()
Comment 2 Jakub Jelinek 2002-09-12 07:59:53 EDT
No, the file pointed to by HOSTALIASES is not the same format as /etc/hosts.
See http://unixhelp.ed.ac.uk/CGI/man-cgi?hostname+7
Furthermore, it is used only if looking up name which doesn't contain any dots.
Having
www www.foobar.com
in $HOME/hosts
and doing HOSTALIASES=$HOME/hosts ./test-gethostbyname www
should give you address of www.foobar.com
(also note that HOSTALIASES only works for non-suid/sgid apps).
Comment 3 Gordon Messmer 2002-09-12 12:59:32 EDT
#HOSTALIASES is not the same format as /etc/hosts
No?  I swear I'd used it that way in the past.

Removing the contents of that file, and rebuilding it according to the man page
you link to causes it to work on release 7.3, but it's not working on (null).

$ gcc test-gethostbyname.c -o test-gethostbyname
$ echo $HOSTALIASES
/home/gordon/root/etc/hosts
$ export HOSTALIASES
$ ls -l $HOSTALIASES
-rw-r--r--    1 gordon   gordon         20 Sep 12 09:36 \
         /home/gordon/root/etc/hosts
$ cat $HOSTALIASES
www
	www.eburg.com
$ host www
www.dragonsdawn.net is an alias for phantom.dragonsdawn.net.
phantom.dragonsdawn.net has address 63.164.112.5
$ host www.eburg.com
www.eburg.com is an alias for naneum.eburg.com.
naneum.eburg.com has address 63.164.112.2
$ ./test-gethostbyname www
gethostbyname returned 63.164.112.5
Comment 4 Gordon Messmer 2002-09-12 13:01:42 EDT
Don't know where that line break in the HOSTALIASES file came from (in the above
text).  I think the text widget put it there.  The file is only one line long.
Comment 5 Jakub Jelinek 2002-09-12 13:43:33 EDT
Works just fine for me (on glibc-2.2.93-4).
Comment 6 Gordon Messmer 2002-09-12 14:52:10 EDT
Is that available via up2date or rawhide?  I'm running glibc-2.2.93-2

Note You need to log in before you can comment on or make changes to this bug.