src: use LIBC_SO and LIBNSL_SO from GNU libc, if available master
authorPino Toscano <toscano.pino@tiscali.it>
Fri, 30 May 2014 17:01:29 +0000 (19:01 +0200)
committerAndreas Schneider <asn@samba.org>
Wed, 9 Aug 2023 09:53:37 +0000 (11:53 +0200)
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.

Signed-off-by: Simon Josefsson <simon@josefsson.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
ConfigureChecks.cmake
config.h.cmake
src/nss_wrapper.c

index 5bd69dba38ff78ae0e4f171e886c2239e4aa62ac..e74e83ee9084eaac547232919157f4050bdf4a0d 100644 (file)
@@ -54,6 +54,7 @@ check_include_file(shadow.h HAVE_SHADOW_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)
index 619996213bb11dbdfe7dfbe3245b8a41da934b02..37cd700c776b4c02bcd9f6d192ea7717cce215a2 100644 (file)
@@ -20,6 +20,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 ***************************/
 
index 3399f06412a2e03b2e1c70f40d6ed2b588cf6e8e..78d88dc9c7a33eabca5502738b92856ce8fe98e1 100644 (file)
 #include <search.h>
 #include <assert.h>
 
+#ifdef HAVE_GNU_LIB_NAMES_H
+#include <gnu/lib-names.h>
+#endif
+
 #include "nss_utils.h"
 /*
  * Defining _POSIX_PTHREAD_SEMANTICS before including pwd.h and grp.h  gives us
@@ -1156,6 +1160,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 (i = 10; i >= 0; i--) {
                                char soname[256] = {0};
@@ -1193,6 +1204,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 (i = 10; i >= 0; i--) {
                                char soname[256] = {0};