[Dnsmasq-discuss] nsswitch

Thomas Angst tangst@granitsoft.ch
Sun, 30 Jan 2005 10:33:16 +0100


Simon Kelley schrieb:

>
> As far as I know, the facilities in libc which use nsswitch.conf are 
> things like gethostbyname(). As these are blocking functions, they are 
> not suitable as replacements for a direct lookup on the cache in 
> dnsmasq, populated by /etc/hosts. It might be possible to read all the 
> names in LDAP at startup  and insert them into the dnsmasq cache, but 
> that needs more LDAP smarts than I have. Does anybody know if that's 
> possible?
>
> Maybe the best solution would be to configure your clients to do the 
> LDAP lookups as part of their name resolution, after all, LDAP is 
> distributed protocol too!

Thanks for your answer,

I used allways a libc6 tool named getent for watching of the correct 
working nsswitch for hosts, passwd or shadow. So I thought there must be 
a library function to do this in C. Last time I programmed in C is about 
10 years ago, so maybe the informations are not completely :).
I have made some investigations and watched the source of getent.c from 
glibc6. There are the functions print_hosts and hosts_keys.
host_keys has this part of code inside:

8<--------
     sethostent (0);
      while ((host = gethostent ()) != NULL)
        print_hosts (host);
      endhostent ();
      return result;
------->8

It seems, in my opinion, that this construct will get all entries of 
hosts, no matter if you are using /etc/host only or combined with nis, 
ldap, mysql or whatever.
By the way, there are the similar functions for the other system files too.

greets
Thomas