c - Linux getpwnam() library dependencies -
c - Linux getpwnam() library dependencies -
i had programme scheme phone call getpwnam()
failing @ runtime. debug this, decided run getpwnam()
in isolation code (it came forum):
#include <pwd.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { struct passwd *pw; if (argc != 2) { printf("usage: %s username\n", argv[0]); exit(0); } pw = getpwnam(argv[1]); if (pw == null) printf("getpwnam failed\n"); else printf("home dir = %s\n", pw->pw_dir); exit(0); }
oddly seems depend on libnss_compat-2.3.5.so
beingness present:
with libnss_compat:
./pwnam root home dir = /root
without libnss_compat:
./pwnam root getpwnam failed
so question is; why getpwnam()
dependent on libnss_compat*.so
? found out nm -d
command libc-2.3.5.so
lib provides getpwnam()
.
readelf -d
shows me libc
in turn depends on ld.so.1
. in turn depends on nothing. why on earth libnss_compat
having impact?
thanks help everyone!!
nss name service switch, library can user info in various sources (traditional password files, network info service, ldap). getpwnam
may defined in libc
, load actual nss library @ runtime. looking within libc
, find
$ strings /lib/x86_64-linux-gnu/libc.so.6 | grep libnss libnss_ libnss_ libnss_%s.so.%d.%d
the lastly line format string snprintf
used build name of actual implementation library load using dlopen
. implementation determined using /etc/nsswitch.conf
.
edit found place in glibc sources the library loaded. it's not (no longer?) using snprintf
, principle still same.
c linux
Comments
Post a Comment