Bug 1702218

Summary: Resolver does not resolve host names listed in a file specified with HOSTALIASES variable
Product: [Fedora] Fedora Reporter: Petr Pisar <ppisar>
Component: man-pagesAssignee: Nikola Forró <nforro>
Status: CLOSED UPSTREAM QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 29CC: aoliva, arjun, codonell, dj, fweimer, jchaloup, kasal, law, mfabian, nforro, pfrankli, rth, siddhesh
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-04-23 10:03:13 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Petr Pisar 2019-04-23 08:52:42 UTC
hostname(7) manual page states:

       If the name consists of a single component, that is, contains no dot, and if the
       environment variable HOSTALIASES is set to the name of  a  file,  that  file  is
       searched for any string matching the input hostname.  The file should consist of
       lines made up of two white-space separated strings, the first of  which  is  the
       hostname  alias,  and the second of which is the complete hostname to be substi‐
       tuted for that alias.  If a case-insensitive match is found between the hostname
       to  be  resolved and the first field of a line in the file, the substituted name
       is looked up with no further processing.

This does not work for me:

$ cat /tmp/aliases 
foo localhost
$ HOSTALIASES=/tmp/aliases getent hosts foo
$ echo $?
2

It seems the file is read, but the content is not honored:

$ HOSTALIASES=/tmp/aliases strace -e openat getent hosts foo
[...]
openat(AT_FDCWD, "/lib64/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libnss_dns.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libresolv.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/librt.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libmount.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libblkid.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libuuid.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libpcre2-8.so.0", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib64/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/tmp/aliases", O_RDONLY|O_CLOEXEC) = 3

My /etc/nsswitch.conf is:

hosts:      files dns myhostname

I have glibc-2.28-27.fc29.x86_64.

Comment 1 Florian Weimer 2019-04-23 08:57:53 UTC
HOSTALIASES only applies to the DNS resolver.  I assume that you have “localhost” defined in /etc/hosts, and not available in DNS.

Does this answer your question?

Comment 2 Petr Pisar 2019-04-23 09:56:28 UTC
Yes, I have localhost entry in /etc/hosts.

So is that a bug in hostname(7) documentation, or is glibc going to support HOSTALIASES processing with hosts "files" resolver?

Comment 3 Florian Weimer 2019-04-23 10:03:13 UTC
(In reply to Petr Pisar from comment #2)
> Yes, I have localhost entry in /etc/hosts.
> 
> So is that a bug in hostname(7) documentation, or is glibc going to support
> HOSTALIASES processing with hosts "files" resolver?

The documentation is misleading.  The search path processing applies to the “Internet name resolver” (which really means DNS) only, and I really don't think we can change that.  I submitted a patch here: https://marc.info/?l=linux-man&m=155601078704361&w=2