Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 9331 - host tool and possibly gethostbyname do not respect /etc/nsswitch.conf
Summary: host tool and possibly gethostbyname do not respect /etc/nsswitch.conf
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Jared H. Hudson (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-19 02:43 UTC by mike wakerly
Modified: 2003-02-04 19:42 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mike wakerly 2002-10-19 02:43:57 UTC
hello... it appears that host, and interfaces that use gethostbyname(), are
ignoring my /etc/hosts file. the behavior of this _should_ be controlled by
/etc/nsswitch.conf. indeed, i have the following lines present:

hosts:       files dns
networks:    files dns

still, running host on some entry in this file causes it to de ignored. deleting
dns from /etc/nsswitch.conf didn't help...

this is a pretty big problem imo, since apps like netscape like to use
gethostbyname() to resolve hosts. when your hostname is fake (but listed in
etc/hosts), this can cause some strange headaches.

cheers..
Comment 1 Jared H. Hudson (RETIRED) gentoo-dev 2002-12-25 21:13:23 UTC
The "host" program uses your /etc/resolv.conf and queries a DNS server directly.
It does not use /etc/nsswitch.conf, /lib/libnss.so, or gethostbyname().

Whereas a general network program like ping, looks at /etc/nsswitch.conf and
uses /etc/hosts (if files is listed), ect. Mozzila should as well, I would think.

A simple C program can test the gethostbyname() interface, to proove this:

#include <netdb.h>
#include <stdio.h>

int main(int argc, char **argv)
{
  char **ptr;
  char str[INET6_ADDRSTRLEN];
  struct hostent *h;

  if (argc < 2)
    return 1;

  h = gethostbyname(argv[1]);

  ptr = h->h_addr_list;
  for ( ; *ptr != NULL; ptr++) {
    printf("[%s]\n",
           inet_ntop(h->h_addrtype, *ptr, str, sizeof(str)));
  }

  return 0;
}

To compile run gcc -o test test.c     (assuming source is put into test.c)
./test foobar                         (assuming foobar is in your /etc/hosts,
and /etc/nsswitch.conf is setup properly)


Also, there's a command called strace that will allow you to see all the system
calls that a program runs.
emerge strace to install it.

Then you can do something like
strace host foobar 2> strace.log
less strace.log
and you will see that it never looks at or uses /etc/nsswitch.conf, it connects
directly to your nameservers listed in /etc/resolv.conf

where as if you do a
strace ping foobar 2> strace.log
less strace.log

You will see it look at /etc/nsswitch.conf, and go from there.