Hello community, here is the log from the commit of package nss_wrapper for openSUSE:Factory checked in at 2020-02-21 16:40:13 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/nss_wrapper (Old) and /work/SRC/openSUSE:Factory/.nss_wrapper.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "nss_wrapper" Fri Feb 21 16:40:13 2020 rev:10 rq:774824 version:1.1.8 Changes: -------- --- /work/SRC/openSUSE:Factory/nss_wrapper/nss_wrapper.changes 2019-11-18 19:57:35.361978497 +0100 +++ /work/SRC/openSUSE:Factory/.nss_wrapper.new.26092/nss_wrapper.changes 2020-02-21 16:40:39.157828598 +0100 @@ -1,0 +2,7 @@ +Mon Feb 17 10:22:31 UTC 2020 - Andreas Schneider <[email protected]> + +- Update to version 1.1.8 + * Fixed path to library in nss_wrapper.pc + * Try different backends for gethostbyaddr nd gethostbyname + +------------------------------------------------------------------- Old: ---- nss_wrapper-1.1.7.tar.gz nss_wrapper-1.1.7.tar.gz.asc New: ---- nss_wrapper-1.1.8.tar.gz nss_wrapper-1.1.8.tar.gz.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ nss_wrapper.spec ++++++ --- /var/tmp/diff_new_pack.PjpFRz/_old 2020-02-21 16:40:39.905830092 +0100 +++ /var/tmp/diff_new_pack.PjpFRz/_new 2020-02-21 16:40:39.909830101 +0100 @@ -1,7 +1,7 @@ # # spec file for package nss_wrapper # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -24,13 +24,13 @@ ############################# NOTE ################################## Name: nss_wrapper -Version: 1.1.7 +Version: 1.1.8 Release: 0 Summary: A wrapper for the user, group and hosts NSS API License: BSD-3-Clause Group: Development/Libraries/C and C++ -Url: http://cwrap.org/ +URL: http://cwrap.org/ Source0: https://ftp.samba.org/pub/cwrap/%{name}-%{version}.tar.gz Source1: https://ftp.samba.org/pub/cwrap/%{name}-%{version}.tar.gz.asc @@ -91,7 +91,7 @@ %files %defattr(-,root,root) -%doc AUTHORS README.md ChangeLog +%doc AUTHORS README.md CHANGELOG %license LICENSE %{_bindir}/nss_wrapper.pl %{_libdir}/libnss_wrapper.so* ++++++ nss_wrapper-1.1.7.tar.gz -> nss_wrapper-1.1.8.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nss_wrapper-1.1.7/CHANGELOG new/nss_wrapper-1.1.8/CHANGELOG --- old/nss_wrapper-1.1.7/CHANGELOG 1970-01-01 01:00:00.000000000 +0100 +++ new/nss_wrapper-1.1.8/CHANGELOG 2020-02-17 10:42:43.000000000 +0100 @@ -0,0 +1,66 @@ +ChangeLog +========== + +version 1.1.8 (released 2020-02-17) + * Fixed path to library in nss_wrapper.pc + * Try different backends for gethostbyaddr nd gethostbyname + +version 1.1.7 (released 2019-11-11) + * Added NSS_WRAPPER_DISABLE_DEEPBIND env variable + * Improvded logging + * Fixed location in cmake config + +version 1.1.6 (released 2019-05-19) + * Fixed issues with memory alignment of getgrnam() + * Fixed getpwnam() on FreeBSD + * Started to use modern cmake (>= 3.5.0) + +version 1.1.5 (released 2018-10-31) + * Fixed running on older distributions + +version 1.1.4 (released 2018-10-31) + * Fixed module getpw* functions + * Fixed nss_wrapper.pl to use correct perl binary + * Fixed compatibility with musl-libc + +version 1.1.3 (released 2015-03-18) + * Added support for BSD 'struct passwd' members + * Replaced strcpy() with snprintf() + +version 1.1.2 (released 2015-12-17) + * Fixed segfault while reloading hosts file + * Fixed issue where are not fault tolerant if an alias has already + been added + +version 1.1.1 (released 2015-11-23) + * Fixed nss_wrapper build on Solaris + +version 1.1.0 (released 2015-11-20) + * Added support for initgroups() + * Added support for shadow files (getspnam(), etc.) + * Improved support for multi address handling in getaddrinfo() + * Improved file parser + * Fixed compilation on machines without IPv4 support + * Fixed service string sanity check in getaddrinfo() (bso #11501) + * Fixed AI_NUMERICHOST handling in getaddrinfo() (bso # 11477) + +version 1.0.3 (released 2014-09-11) + * Added a nss_wrapper manpage. + * Fixed cmake find_package configs. + * Fixed resolving hostnames with a trailing dot. + * Fixed an overflow when checking if a IPv6 address is IPv4. + * Fall back to RTLD_NEXT for symbol binding if we can't find libc. + +version 1.0.2 (released 2014-04-08) + * Added public nss_wrapper_enabled(). + * Added public nss_wrapper_hosts_enabled(). + * Fixed segfault in 'getent hosts' without aliases. + * Fixed IPv4 and IPv6 resolving with 'getent ahosts'. + +version 1.0.1 (released 2014-02-04) + * Added --libs to pkg-config. + * Added nss_wrapper-config.cmake + * Fixed a bug packaging the obj directory. + +version 1.0.0 (released 2014-02-02) + * Initial release diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nss_wrapper-1.1.7/CMakeLists.txt new/nss_wrapper-1.1.8/CMakeLists.txt --- old/nss_wrapper-1.1.7/CMakeLists.txt 2019-11-11 15:46:02.000000000 +0100 +++ new/nss_wrapper-1.1.8/CMakeLists.txt 2020-02-17 10:42:43.000000000 +0100 @@ -11,7 +11,7 @@ include(DefineCMakeDefaults) include(DefineCompilerFlags) -project(nss_wrapper VERSION 1.1.7 LANGUAGES C) +project(nss_wrapper VERSION 1.1.8 LANGUAGES C) # global needed variables set(APPLICATION_NAME ${PROJECT_NAME}) @@ -23,7 +23,7 @@ # Increment AGE. Set REVISION to 0 # If the source code was changed, but there were no interface changes: # Increment REVISION. -set(LIBRARY_VERSION "0.2.6") +set(LIBRARY_VERSION "0.2.7") set(LIBRARY_SOVERSION "0") # add definitions diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nss_wrapper-1.1.7/ChangeLog new/nss_wrapper-1.1.8/ChangeLog --- old/nss_wrapper-1.1.7/ChangeLog 2019-11-11 15:45:48.000000000 +0100 +++ new/nss_wrapper-1.1.8/ChangeLog 1970-01-01 01:00:00.000000000 +0100 @@ -1,62 +0,0 @@ -ChangeLog -========== - -version 1.1.7 (released 2019-11-11) - * Added NSS_WRAPPER_DISABLE_DEEPBIND env variable - * Improvded logging - * Fixed location in cmake config - -version 1.1.6 (released 2019-05-19) - * Fixed issues with memory alignment of getgrnam() - * Fixed getpwnam() on FreeBSD - * Started to use modern cmake (>= 3.5.0) - -version 1.1.5 (released 2018-10-31) - * Fixed running on older distributions - -version 1.1.4 (released 2018-10-31) - * Fixed module getpw* functions - * Fixed nss_wrapper.pl to use correct perl binary - * Fixed compatibility with musl-libc - -version 1.1.3 (released 2015-03-18) - * Added support for BSD 'struct passwd' members - * Replaced strcpy() with snprintf() - -version 1.1.2 (released 2015-12-17) - * Fixed segfault while reloading hosts file - * Fixed issue where are not fault tolerant if an alias has already - been added - -version 1.1.1 (released 2015-11-23) - * Fixed nss_wrapper build on Solaris - -version 1.1.0 (released 2015-11-20) - * Added support for initgroups() - * Added support for shadow files (getspnam(), etc.) - * Improved support for multi address handling in getaddrinfo() - * Improved file parser - * Fixed compilation on machines without IPv4 support - * Fixed service string sanity check in getaddrinfo() (bso #11501) - * Fixed AI_NUMERICHOST handling in getaddrinfo() (bso # 11477) - -version 1.0.3 (released 2014-09-11) - * Added a nss_wrapper manpage. - * Fixed cmake find_package configs. - * Fixed resolving hostnames with a trailing dot. - * Fixed an overflow when checking if a IPv6 address is IPv4. - * Fall back to RTLD_NEXT for symbol binding if we can't find libc. - -version 1.0.2 (released 2014-04-08) - * Added public nss_wrapper_enabled(). - * Added public nss_wrapper_hosts_enabled(). - * Fixed segfault in 'getent hosts' without aliases. - * Fixed IPv4 and IPv6 resolving with 'getent ahosts'. - -version 1.0.1 (released 2014-02-04) - * Added --libs to pkg-config. - * Added nss_wrapper-config.cmake - * Fixed a bug packaging the obj directory. - -version 1.0.0 (released 2014-02-02) - * Initial release diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nss_wrapper-1.1.7/nss_wrapper.pc.cmake new/nss_wrapper-1.1.8/nss_wrapper.pc.cmake --- old/nss_wrapper-1.1.7/nss_wrapper.pc.cmake 2019-02-28 12:50:00.000000000 +0100 +++ new/nss_wrapper-1.1.8/nss_wrapper.pc.cmake 2019-11-15 13:18:04.000000000 +0100 @@ -1,4 +1,4 @@ Name: @PROJECT_NAME@ Description: The nss_wrapper library Version: @PROJECT_VERSION@ -Libs: @CMAKE_INSTALL_LIBDIR@/@NSS_WRAPPER_LIB@ +Libs: @CMAKE_INSTALL_FULL_LIBDIR@/@NSS_WRAPPER_LIB@ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nss_wrapper-1.1.7/src/nss_wrapper.c new/nss_wrapper-1.1.8/src/nss_wrapper.c --- old/nss_wrapper-1.1.7/src/nss_wrapper.c 2019-11-11 15:44:13.000000000 +0100 +++ new/nss_wrapper-1.1.8/src/nss_wrapper.c 2020-02-17 10:42:35.000000000 +0100 @@ -395,6 +395,14 @@ NSS_STATUS (*_nss_getgrent_r)(struct group *result, char *buffer, size_t buflen, int *errnop); NSS_STATUS (*_nss_endgrent)(void); + NSS_STATUS (*_nss_gethostbyaddr_r)(const void *addr, socklen_t addrlen, + int af, struct hostent *result, + char *buffer, size_t buflen, + int *errnop, int *h_errnop); + NSS_STATUS (*_nss_gethostbyname2_r)(const char *name, int af, + struct hostent *result, + char *buffer, size_t buflen, + int *errnop, int *h_errnop); }; struct nwrap_backend { @@ -405,6 +413,8 @@ struct nwrap_module_nss_fns *fns; }; +struct nwrap_vector; + struct nwrap_ops { struct passwd * (*nw_getpwnam)(struct nwrap_backend *b, const char *name); @@ -440,6 +450,18 @@ struct group *grdst, char *buf, size_t buflen, struct group **grdstp); void (*nw_endgrent)(struct nwrap_backend *b); + struct hostent *(*nw_gethostbyaddr)(struct nwrap_backend *b, + const void *addr, + socklen_t len, int type); + struct hostent *(*nw_gethostbyname)(struct nwrap_backend *b, + const char *name); + struct hostent *(*nw_gethostbyname2)(struct nwrap_backend *b, + const char *name, int af); + int (*nw_gethostbyname2_r)(struct nwrap_backend *b, + const char *name, int af, + struct hostent *hedst, + char *buf, size_t buflen, + struct hostent **hedstp); }; /* Public prototypes */ @@ -485,6 +507,18 @@ struct group *grdst, char *buf, size_t buflen, struct group **grdstp); static void nwrap_files_endgrent(struct nwrap_backend *b); +static struct hostent *nwrap_files_gethostbyaddr(struct nwrap_backend *b, + const void *addr, + socklen_t len, int type); +static struct hostent *nwrap_files_gethostbyname(struct nwrap_backend *b, + const char *name); +static struct hostent *nwrap_files_gethostbyname2(struct nwrap_backend *b, + const char *name, int af); +static int nwrap_files_gethostbyname2_r(struct nwrap_backend *b, + const char *name, int af, + struct hostent *hedst, + char *buf, size_t buflen, + struct hostent **hedstp); /* prototypes for module backend */ @@ -522,6 +556,18 @@ static void nwrap_module_endgrent(struct nwrap_backend *b); static int nwrap_module_initgroups(struct nwrap_backend *b, const char *user, gid_t group); +static struct hostent *nwrap_module_gethostbyaddr(struct nwrap_backend *b, + const void *addr, + socklen_t len, int type); +static struct hostent *nwrap_module_gethostbyname(struct nwrap_backend *b, + const char *name); +static struct hostent *nwrap_module_gethostbyname2(struct nwrap_backend *b, + const char *name, int af); +static int nwrap_module_gethostbyname2_r(struct nwrap_backend *b, + const char *name, int af, + struct hostent *hedst, + char *buf, size_t buflen, + struct hostent **hedstp); struct nwrap_ops nwrap_files_ops = { .nw_getpwnam = nwrap_files_getpwnam, @@ -541,6 +587,10 @@ .nw_getgrent = nwrap_files_getgrent, .nw_getgrent_r = nwrap_files_getgrent_r, .nw_endgrent = nwrap_files_endgrent, + .nw_gethostbyaddr = nwrap_files_gethostbyaddr, + .nw_gethostbyname = nwrap_files_gethostbyname, + .nw_gethostbyname2 = nwrap_files_gethostbyname2, + .nw_gethostbyname2_r = nwrap_files_gethostbyname2_r, }; struct nwrap_ops nwrap_module_ops = { @@ -561,6 +611,10 @@ .nw_getgrent = nwrap_module_getgrent, .nw_getgrent_r = nwrap_module_getgrent_r, .nw_endgrent = nwrap_module_endgrent, + .nw_gethostbyaddr = nwrap_module_gethostbyaddr, + .nw_gethostbyname = nwrap_module_gethostbyname, + .nw_gethostbyname2 = nwrap_module_gethostbyname2, + .nw_gethostbyname2_r = nwrap_module_gethostbyname2_r, }; struct nwrap_libc { @@ -571,7 +625,7 @@ }; struct nwrap_main { - int num_backends; + size_t num_backends; struct nwrap_backend *backends; struct nwrap_libc *libc; }; @@ -1475,6 +1529,10 @@ nwrap_load_module_fn(b, "getgrent_r"); *(void **)(&fns->_nss_endgrent) = nwrap_load_module_fn(b, "endgrent"); + *(void **)(&fns->_nss_gethostbyaddr_r) = + nwrap_load_module_fn(b, "gethostbyaddr_r"); + *(void **)(&fns->_nss_gethostbyname2_r) = + nwrap_load_module_fn(b, "gethostbyname2_r"); return fns; } @@ -1501,7 +1559,7 @@ static bool nwrap_module_init(const char *name, struct nwrap_ops *ops, const char *so_path, - int *num_backends, + size_t *num_backends, struct nwrap_backend **backends) { struct nwrap_backend *b; @@ -3513,9 +3571,9 @@ } /* hosts functions */ -static int nwrap_files_gethostbyname(const char *name, int af, - struct hostent *result, - struct nwrap_vector *addr_list) +static int nwrap_files_internal_gethostbyname(const char *name, int af, + struct hostent *result, + struct nwrap_vector *addr_list) { struct nwrap_entlist *el; struct hostent *he; @@ -3611,11 +3669,11 @@ return -1; } -#ifdef HAVE_GETHOSTBYNAME_R -static int nwrap_gethostbyname_r(const char *name, - struct hostent *ret, - char *buf, size_t buflen, - struct hostent **result, int *h_errnop) +static int nwrap_files_gethostbyname2_r(struct nwrap_backend *b, + const char *name, int af, + struct hostent *hedst, + char *buf, size_t buflen, + struct hostent **hedstp) { struct nwrap_vector *addr_list = malloc(sizeof(struct nwrap_vector)); union { @@ -3624,6 +3682,9 @@ } g; int rc; + (void) b; /* unused */ + (void) af; /* unused */ + if (addr_list == NULL) { NWRAP_LOG(NWRAP_LOG_ERROR, "Unable to allocate memory for address list"); @@ -3633,9 +3694,9 @@ ZERO_STRUCTP(addr_list); - rc = nwrap_files_gethostbyname(name, AF_UNSPEC, ret, addr_list); + rc = nwrap_files_internal_gethostbyname(name, AF_UNSPEC, hedst, + addr_list); if (rc == -1) { - *h_errnop = h_errno; if (addr_list->items != NULL) { free(addr_list->items); } @@ -3659,11 +3720,32 @@ free(addr_list); g.ptr = buf; - ret->h_addr_list = g.list; - *result = ret; + hedst->h_addr_list = g.list; + *hedstp = hedst; return 0; } +#ifdef HAVE_GETHOSTBYNAME_R +static int nwrap_gethostbyname_r(const char *name, + struct hostent *ret, + char *buf, size_t buflen, + struct hostent **result, int *h_errnop) +{ + int rc; + size_t i; + + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + rc = b->ops->nw_gethostbyname2_r(b, name, AF_UNSPEC, ret, + buf, buflen, result); + if (rc == 0) { + return 0; + } + } + *h_errnop = h_errno; + return ENOENT; +} + int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, @@ -3682,6 +3764,42 @@ } #endif +#ifdef HAVE_GETHOSTBYNAME2_R +static int nwrap_gethostbyname2_r(const char *name, int af, + struct hostent *ret, + char *buf, size_t buflen, + struct hostent **result, int *h_errnop) +{ + int rc; + size_t i; + + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + rc = b->ops->nw_gethostbyname2_r(b, name, af, ret, + buf, buflen, result); + if (rc == 0) { + return 0; + } + } + *h_errnop = h_errno; + return ENOENT; +} + +int gethostbyname2_r(const char *name, int af, + struct hostent *ret, + char *buf, size_t buflen, + struct hostent **result, int *h_errnop) +{ + if (!nss_wrapper_hosts_enabled()) { + return libc_gethostbyname2_r(name, af, ret, buf, buflen, + result, h_errnop); + } + + return nwrap_gethostbyname2_r(name, af, ret, buf, buflen, result, + h_errnop); +} +#endif + static int nwrap_files_getaddrinfo(const char *name, unsigned short port, const struct addrinfo *hints, @@ -3785,7 +3903,8 @@ return rc; } -static struct hostent *nwrap_files_gethostbyaddr(const void *addr, +static struct hostent *nwrap_files_gethostbyaddr(struct nwrap_backend *b, + const void *addr, socklen_t len, int type) { struct hostent *he; @@ -3795,6 +3914,7 @@ size_t i; bool ok; + (void) b; /* unused */ (void) len; /* unused */ ok = nwrap_files_cache_reload(nwrap_he_global.cache); @@ -3831,15 +3951,23 @@ char *buf, size_t buflen, struct hostent **result, int *h_errnop) { - *result = nwrap_files_gethostbyaddr(addr, len, type); + size_t i; + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + *result = b->ops->nw_gethostbyaddr(b, addr, len, type); + if (*result != NULL) { + break; + } + } + if (*result != NULL) { memset(buf, '\0', buflen); *ret = **result; return 0; - } else { - *h_errnop = h_errno; - return -1; } + + *h_errnop = h_errno; + return -1; } int gethostbyaddr_r(const void *addr, socklen_t len, int type, @@ -4336,13 +4464,189 @@ b->fns->_nss_endgrent(); } +static struct hostent *nwrap_module_gethostbyaddr(struct nwrap_backend *b, + const void *addr, + socklen_t len, int type) +{ + static struct hostent he; + static char *buf = NULL; + static size_t buflen = 1000; + NSS_STATUS status; + + if (b->fns->_nss_gethostbyaddr_r == NULL) { + return NULL; + } + + if (buf == NULL) { + buf = (char *)malloc(buflen); + if (buf == NULL) { + return NULL; + } + } +again: + status = b->fns->_nss_gethostbyaddr_r(addr, len, type, &he, + buf, buflen, &errno, &h_errno); + if (status == NSS_STATUS_TRYAGAIN) { + char *p = NULL; + + buflen *= 2; + p = (char *)realloc(buf, buflen); + if (p == NULL) { + SAFE_FREE(buf); + return NULL; + } + buf = p; + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + SAFE_FREE(buf); + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + SAFE_FREE(buf); + return NULL; + } + + return &he; +} + +static int nwrap_module_gethostbyname2_r(struct nwrap_backend *b, + const char *name, int af, + struct hostent *hedst, + char *buf, size_t buflen, + struct hostent **hedstp) +{ + NSS_STATUS status; + + *hedstp = NULL; + + if (b->fns->_nss_gethostbyname2_r == NULL) { + return ENOENT; + } + + status = b->fns->_nss_gethostbyname2_r(name, af, hedst, + buf, buflen, &errno, &h_errno); + switch (status) { + case NSS_STATUS_SUCCESS: + *hedstp = hedst; + return 0; + case NSS_STATUS_NOTFOUND: + if (errno != 0) { + return errno; + } + return ENOENT; + case NSS_STATUS_TRYAGAIN: + if (errno != 0) { + return errno; + } + return ERANGE; + default: + if (errno != 0) { + return errno; + } + return status; + } +} + +static struct hostent *nwrap_module_gethostbyname(struct nwrap_backend *b, + const char *name) +{ + static struct hostent he; + static char *buf = NULL; + static size_t buflen = 1000; + NSS_STATUS status; + + if (b->fns->_nss_gethostbyname2_r == NULL) { + return NULL; + } + + if (buf == NULL) { + buf = (char *)malloc(buflen); + if (buf == NULL) { + return NULL; + } + } + +again: + status = b->fns->_nss_gethostbyname2_r(name, AF_UNSPEC, &he, + buf, buflen, &errno, &h_errno); + if (status == NSS_STATUS_TRYAGAIN) { + char *p = NULL; + + buflen *= 2; + p = (char *)realloc(buf, buflen); + if (p == NULL) { + SAFE_FREE(buf); + return NULL; + } + buf = p; + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + SAFE_FREE(buf); + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + SAFE_FREE(buf); + return NULL; + } + + return &he; +} + +static struct hostent *nwrap_module_gethostbyname2(struct nwrap_backend *b, + const char *name, int af) +{ + static struct hostent he; + static char *buf = NULL; + static size_t buflen = 1000; + NSS_STATUS status; + + if (b->fns->_nss_gethostbyname2_r == NULL) { + return NULL; + } + + if (buf == NULL) { + buf = (char *)malloc(buflen); + if (buf == NULL) { + return NULL; + } + } + +again: + status = b->fns->_nss_gethostbyname2_r(name, af, &he, + buf, buflen, &errno, &h_errno); + if (status == NSS_STATUS_TRYAGAIN) { + char *p = NULL; + + buflen *= 2; + p = (char *)realloc(buf, buflen); + if (p == NULL) { + SAFE_FREE(buf); + return NULL; + } + buf = p; + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + SAFE_FREE(buf); + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + SAFE_FREE(buf); + return NULL; + } + + return &he; +} + /**************************************************************************** * GETPWNAM ***************************************************************************/ static struct passwd *nwrap_getpwnam(const char *name) { - int i; + size_t i; struct passwd *pwd; for (i=0; i < nwrap_main_global->num_backends; i++) { @@ -4372,7 +4676,8 @@ static int nwrap_getpwnam_r(const char *name, struct passwd *pwdst, char *buf, size_t buflen, struct passwd **pwdstp) { - int i,ret; + size_t i; + int ret; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4409,7 +4714,7 @@ static struct passwd *nwrap_getpwuid(uid_t uid) { - int i; + size_t i; struct passwd *pwd; for (i=0; i < nwrap_main_global->num_backends; i++) { @@ -4439,7 +4744,8 @@ static int nwrap_getpwuid_r(uid_t uid, struct passwd *pwdst, char *buf, size_t buflen, struct passwd **pwdstp) { - int i,ret; + size_t i; + int ret; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4474,7 +4780,7 @@ static void nwrap_setpwent(void) { - int i; + size_t i; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4498,7 +4804,7 @@ static struct passwd *nwrap_getpwent(void) { - int i; + size_t i; struct passwd *pwd; for (i=0; i < nwrap_main_global->num_backends; i++) { @@ -4529,7 +4835,8 @@ static int nwrap_getpwent_r(struct passwd *pwdst, char *buf, size_t buflen, struct passwd **pwdstp) { - int i,ret; + size_t i; + int ret; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4578,7 +4885,7 @@ static void nwrap_endpwent(void) { - int i; + size_t i; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4602,7 +4909,7 @@ static int nwrap_initgroups(const char *user, gid_t group) { - int i; + size_t i; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4633,7 +4940,7 @@ static struct group *nwrap_getgrnam(const char *name) { - int i; + size_t i; struct group *grp; for (i=0; i < nwrap_main_global->num_backends; i++) { @@ -4663,7 +4970,8 @@ static int nwrap_getgrnam_r(const char *name, struct group *grdst, char *buf, size_t buflen, struct group **grdstp) { - int i, ret; + size_t i; + int ret; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4704,7 +5012,7 @@ static struct group *nwrap_getgrgid(gid_t gid) { - int i; + size_t i; struct group *grp; for (i=0; i < nwrap_main_global->num_backends; i++) { @@ -4734,7 +5042,8 @@ static int nwrap_getgrgid_r(gid_t gid, struct group *grdst, char *buf, size_t buflen, struct group **grdstp) { - int i,ret; + size_t i; + int ret; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4771,7 +5080,7 @@ static void nwrap_setgrent(void) { - int i; + size_t i; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4806,7 +5115,7 @@ static struct group *nwrap_getgrent(void) { - int i; + size_t i; struct group *grp; for (i=0; i < nwrap_main_global->num_backends; i++) { @@ -4837,7 +5146,8 @@ static int nwrap_getgrent_r(struct group *grdst, char *buf, size_t buflen, struct group **grdstp) { - int i,ret; + size_t i; + int ret; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -4887,7 +5197,7 @@ static void nwrap_endgrent(void) { - int i; + size_t i; for (i=0; i < nwrap_main_global->num_backends; i++) { struct nwrap_backend *b = &nwrap_main_global->backends[i]; @@ -5129,6 +5439,7 @@ } #endif /* HAVE_SOLARIS_ENDHOSTENT */ + #ifdef BSD /* BSD implementation stores data in thread local storage but GLIBC does not */ static __thread struct hostent user_he; @@ -5137,12 +5448,37 @@ static struct hostent user_he; static struct nwrap_vector user_addrlist; #endif /* BSD */ + +static struct hostent *nwrap_files_gethostbyname(struct nwrap_backend *b, + const char *name) +{ + int ret; + + (void) b; /* unused */ + + ret = nwrap_files_internal_gethostbyname(name, AF_UNSPEC, &user_he, + &user_addrlist); + if (ret == 0) { + return &user_he; + } + + return NULL; +} + static struct hostent *nwrap_gethostbyname(const char *name) { - if (nwrap_files_gethostbyname(name, AF_UNSPEC, &user_he, &user_addrlist) == -1) { - return NULL; + size_t i; + struct hostent *he = NULL; + + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + he = b->ops->nw_gethostbyname(b, name); + if (he != NULL) { + return he; + } } - return &user_he; + + return NULL; } struct hostent *gethostbyname(const char *name) @@ -5164,12 +5500,37 @@ static struct hostent user_he2; static struct nwrap_vector user_addrlist2; #endif /* BSD */ + +static struct hostent *nwrap_files_gethostbyname2(struct nwrap_backend *b, + const char *name, int af) +{ + int ret; + + (void) b; /* unused */ + + ret = nwrap_files_internal_gethostbyname(name, af, &user_he2, + &user_addrlist2); + if (ret == 0) { + return &user_he2; + } + + return NULL; +} + static struct hostent *nwrap_gethostbyname2(const char *name, int af) { - if (nwrap_files_gethostbyname(name, af, &user_he2, &user_addrlist2) == -1) { - return NULL; + size_t i; + struct hostent *he = NULL; + + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + he = b->ops->nw_gethostbyname2(b, name, af); + if (he != NULL) { + return he; + } } - return &user_he2; + + return NULL; } struct hostent *gethostbyname2(const char *name, int af) @@ -5185,7 +5546,18 @@ static struct hostent *nwrap_gethostbyaddr(const void *addr, socklen_t len, int type) { - return nwrap_files_gethostbyaddr(addr, len, type); + size_t i; + struct hostent *he = NULL; + + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + he = b->ops->nw_gethostbyaddr(b, addr, len, type); + if (he != NULL) { + return he; + } + } + + return NULL; } struct hostent *gethostbyaddr(const void *addr, @@ -5531,6 +5903,7 @@ socklen_t addrlen; uint16_t port; sa_family_t type; + size_t i; if (sa == NULL || salen < sizeof(sa_family_t)) { return EAI_FAMILY; @@ -5585,7 +5958,13 @@ if (host != NULL) { he = NULL; if ((flags & NI_NUMERICHOST) == 0) { - he = nwrap_files_gethostbyaddr(addr, addrlen, type); + for (i=0; i < nwrap_main_global->num_backends; i++) { + struct nwrap_backend *b = &nwrap_main_global->backends[i]; + he = b->ops->nw_gethostbyaddr(b, addr, addrlen, type); + if (he != NULL) { + break; + } + } if ((flags & NI_NAMEREQD) && (he == NULL || he->h_name == NULL)) return EAI_NONAME; } @@ -5698,7 +6077,7 @@ */ void nwrap_destructor(void) { - int i; + size_t i; NWRAP_LOCK_ALL; if (nwrap_main_global != NULL) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/nss_wrapper-1.1.7/tests/testsuite.c new/nss_wrapper-1.1.8/tests/testsuite.c --- old/nss_wrapper-1.1.7/tests/testsuite.c 2019-02-15 18:04:38.000000000 +0100 +++ new/nss_wrapper-1.1.8/tests/testsuite.c 2020-02-17 09:37:41.000000000 +0100 @@ -812,8 +812,10 @@ struct group grp = grp_array[i]; if (test_nwrap_user_in_group(pwd, &grp)) { + struct group current_grp = { + .gr_name = NULL, + }; - struct group current_grp; num_user_groups_from_enum++; test_nwrap_getgrnam(grp.gr_name, ¤t_grp);
