From 8909140066666267711358b4e89fabe945c2599d Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 30 May 2014 19:01:29 +0200 Subject: [PATCH] src: use LIBC_SO and LIBNSL_SO from GNU libc, if available Look for gnu/lib-names.h and use the LIBC_SO and LIBNSL_SO defines to dlopen libc and libnsl, so the right library is loaded without manually searching for libc.so.N or libnsl.so.N. --- ConfigureChecks.cmake | 1 + config.h.cmake | 1 + src/nss_wrapper.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index b74ed8d..bf9b933 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -52,6 +52,7 @@ check_include_file(pwd.h HAVE_PWD_H) check_include_file(grp.h HAVE_GRP_H) check_include_file(nss.h HAVE_NSS_H) check_include_file(nss_common.h HAVE_NSS_COMMON_H) +check_include_file(gnu/lib-names.h HAVE_GNU_LIB_NAMES_H) # FUNCTIONS check_function_exists(strncpy HAVE_STRNCPY) diff --git a/config.h.cmake b/config.h.cmake index b94b621..15c6483 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -19,6 +19,7 @@ #cmakedefine HAVE_GRP_H 1 #cmakedefine HAVE_NSS_H 1 #cmakedefine HAVE_NSS_COMMON_H 1 +#cmakedefine HAVE_GNU_LIB_NAMES_H 1 /*************************** FUNCTIONS ***************************/ diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c index 6ed48c6..4978c34 100644 --- a/src/nss_wrapper.c +++ b/src/nss_wrapper.c @@ -50,6 +50,10 @@ #include #include +#ifdef HAVE_GNU_LIB_NAMES_H +#include +#endif + /* * Defining _POSIX_PTHREAD_SEMANTICS before including pwd.h and grp.h gives us * the posix getpwnam_r(), getpwuid_r(), getgrnam_r and getgrgid_r calls on @@ -570,6 +574,13 @@ static void *nwrap_load_lib_handle(enum nwrap_lib lib) case NWRAP_LIBNSL: #ifdef HAVE_LIBNSL handle = nwrap_main_global->libc->nsl_handle; +#ifdef LIBNSL_SO + if (handle == NULL) { + handle = dlopen(LIBNSL_SO, flags); + + nwrap_main_global->libc->nsl_handle = handle; + } +#endif if (handle == NULL) { for (handle = NULL, i = 10; handle == NULL && i >= 0; i--) { char soname[256] = {0}; @@ -601,6 +612,13 @@ static void *nwrap_load_lib_handle(enum nwrap_lib lib) /* FALL TROUGH */ case NWRAP_LIBC: handle = nwrap_main_global->libc->handle; +#ifdef LIBC_SO + if (handle == NULL) { + handle = dlopen(LIBC_SO, flags); + + nwrap_main_global->libc->handle = handle; + } +#endif if (handle == NULL) { for (handle = NULL, i = 10; handle == NULL && i >= 0; i--) { char soname[256] = {0}; -- 2.0.0.rc2