src: use LIBC_SO and LIBNSL_SO from GNU libc, if available
[nss_wrapper.git] / src / nss_wrapper.c
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};