]> andersk Git - nss_nonlocal.git/blobdiff - nonlocal-shadow.c
Switch from __nss_next API to __nss_next2 API
[nss_nonlocal.git] / nonlocal-shadow.c
index bfc201c48e85a489f6eb208e8a6494596bd55170..9a78f08bd81c77deaff7efdc0ed24b620723036a 100644 (file)
@@ -43,8 +43,8 @@ static service_user *__nss_shadow_nonlocal_database;
 
 static int
 internal_function
-__nss_shadow_nonlocal_lookup(service_user **ni, const char *fct_name,
-                           void **fctp)
+__nss_shadow_nonlocal_lookup2(service_user **ni, const char *fct_name,
+                             const char *fct2_name, void **fctp)
 {
     if (__nss_shadow_nonlocal_database == NULL
        && __nss_database_lookup("shadow_nonlocal", NULL, NULL,
@@ -54,10 +54,13 @@ __nss_shadow_nonlocal_lookup(service_user **ni, const char *fct_name,
     *ni = __nss_shadow_nonlocal_database;
 
     *fctp = __nss_lookup_function(*ni, fct_name);
+    if (*fctp == NULL && fct2_name != NULL)
+       *fctp = __nss_lookup_function(*ni, fct2_name);
     return 0;
 }
 
 
+static bool spent_initialized = false;
 static service_user *spent_startp, *spent_nip;
 static void *spent_fct_start;
 static union {
@@ -72,7 +75,7 @@ _nss_nonlocal_setspent(int stayopen)
 {
     enum nss_status status;
     const struct walk_nss w = {
-       .lookup = &__nss_shadow_nonlocal_lookup, .fct_name = "setspent",
+       .lookup2 = &__nss_shadow_nonlocal_lookup2, .fct_name = "setspent",
        .status = &status
     };
     const __typeof__(&_nss_nonlocal_setspent) self = NULL;
@@ -82,9 +85,12 @@ _nss_nonlocal_setspent(int stayopen)
     if (status != NSS_STATUS_SUCCESS)
        return status;
 
-    if (spent_fct_start == NULL)
-       __nss_shadow_nonlocal_lookup(&spent_startp, spent_fct_name,
-                                    &spent_fct_start);
+    if (!spent_initialized) {
+       __nss_shadow_nonlocal_lookup2(&spent_startp, spent_fct_name, NULL,
+                                     &spent_fct_start);
+       __sync_synchronize();
+       spent_initialized = true;
+    }
     spent_nip = spent_startp;
     spent_fct.ptr = spent_fct_start;
     return NSS_STATUS_SUCCESS;
@@ -95,7 +101,7 @@ _nss_nonlocal_endspent(void)
 {
     enum nss_status status;
     const struct walk_nss w = {
-       .lookup = &__nss_shadow_nonlocal_lookup, .fct_name = "endspent",
+       .lookup2 = &__nss_shadow_nonlocal_lookup2, .fct_name = "endspent",
        .status = &status
     };
     const __typeof__(&_nss_nonlocal_endspent) self = NULL;
@@ -133,7 +139,8 @@ _nss_nonlocal_getspent_r(struct spwd *pwd, char *buffer, size_t buflen,
 
        if (status == NSS_STATUS_SUCCESS)
            return NSS_STATUS_SUCCESS;
-    } while (__nss_next(&spent_nip, spent_fct_name, &spent_fct.ptr, status, 0) == 0);
+    } while (__nss_next2(&spent_nip, spent_fct_name, NULL, &spent_fct.ptr,
+                        status, 0) == 0);
 
     spent_nip = NULL;
     return NSS_STATUS_NOTFOUND;
@@ -146,7 +153,7 @@ _nss_nonlocal_getspnam_r(const char *name, struct spwd *pwd,
 {
     enum nss_status status;
     const struct walk_nss w = {
-       .lookup = __nss_shadow_nonlocal_lookup, .fct_name = "getspnam_r",
+       .lookup2 = __nss_shadow_nonlocal_lookup2, .fct_name = "getspnam_r",
        .status = &status, .errnop = errnop
     };
     const __typeof__(&_nss_nonlocal_getspnam_r) self = NULL;
This page took 0.485288 seconds and 4 git commands to generate.