Red Hat Bugzilla – Bug 73852
HOSTALIASES environment variable not used by resolver
Last modified: 2016-11-24 09:55:39 EST
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.
Steps to Reproduce:
1. Create a host aliases file:
cat > $HOME/hosts <<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.
Created attachment 75884 [details]
Test case for gethostbyname()
No, the file pointed to by HOSTALIASES is not the same format as /etc/hosts.
Furthermore, it is used only if looking up name which doesn't contain any dots.
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).
#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
$ export HOSTALIASES
$ ls -l $HOSTALIASES
-rw-r--r-- 1 gordon gordon 20 Sep 12 09:36 \
$ cat $HOSTALIASES
$ host www
www.dragonsdawn.net is an alias for phantom.dragonsdawn.net.
phantom.dragonsdawn.net has address 22.214.171.124
$ host www.eburg.com
www.eburg.com is an alias for naneum.eburg.com.
naneum.eburg.com has address 126.96.36.199
$ ./test-gethostbyname www
gethostbyname returned 188.8.131.52
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.
Works just fine for me (on glibc-2.2.93-4).
Is that available via up2date or rawhide? I'm running glibc-2.2.93-2