X-Git-Url: http://andersk.mit.edu/gitweb/nss_nonlocal.git/blobdiff_plain/25468b961ce1288b802ae075a80640e4c30ee375..d52c3f35301d10d46a842416bd30777ceb12be7f:/nonlocal-group.c diff --git a/nonlocal-group.c b/nonlocal-group.c index 5b4dd7d..ecf6fed 100644 --- a/nonlocal-group.c +++ b/nonlocal-group.c @@ -24,18 +24,20 @@ */ #define _GNU_SOURCE + #include -#include -#include -#include -#include #include -#include -#include #include -#include #include #include +#include +#include +#include +#include +#include +#include +#include + #include "nsswitch-internal.h" #include "nonlocal.h" @@ -75,8 +77,8 @@ static service_user *__nss_group_nonlocal_database; static int internal_function -__nss_group_nonlocal_lookup(service_user **ni, const char *fct_name, - void **fctp) +__nss_group_nonlocal_lookup2(service_user **ni, const char *fct_name, + const char *fct2_name, void **fctp) { if (__nss_group_nonlocal_database == NULL && __nss_database_lookup("group_nonlocal", NULL, NULL, @@ -86,6 +88,8 @@ __nss_group_nonlocal_lookup(service_user **ni, const char *fct_name, *ni = __nss_group_nonlocal_database; *fctp = __nss_lookup_function(*ni, fct_name); + if (*fctp == NULL && fct2_name != NULL) + *fctp = __nss_lookup_function(*ni, fct2_name); return 0; } @@ -98,7 +102,7 @@ check_nonlocal_gid(const char *user, const char *group, gid_t gid, int *errnop) char *buf; size_t buflen = sysconf(_SC_GETGR_R_SIZE_MAX); const struct walk_nss w = { - .lookup = &__nss_group_lookup, .fct_name = "getgrgid_r", + .lookup2 = &__nss_group_lookup2, .fct_name = "getgrgid_r", .status = &status, .errnop = errnop, .buf = &buf, .buflen = &buflen }; const __typeof__(&_nss_nonlocal_getgrgid_r) self = &_nss_nonlocal_getgrgid_r; @@ -159,7 +163,7 @@ get_local_group(const char *name, struct group *grp, char **buffer, int *errnop) enum nss_status status; size_t buflen = sysconf(_SC_GETGR_R_SIZE_MAX); const struct walk_nss w = { - .lookup = &__nss_group_lookup, .fct_name = "getgrnam_r", + .lookup2 = &__nss_group_lookup2, .fct_name = "getgrnam_r", .status = &status, .errnop = errnop, .buf = buffer, .buflen = &buflen }; const __typeof__(&_nss_nonlocal_getgrnam_r) self = &_nss_nonlocal_getgrnam_r; @@ -169,6 +173,7 @@ get_local_group(const char *name, struct group *grp, char **buffer, int *errnop) return status; } +static bool grent_initialized = false; static service_user *grent_startp, *grent_nip; static void *grent_fct_start; static union { @@ -183,7 +188,7 @@ _nss_nonlocal_setgrent(int stayopen) { enum nss_status status; const struct walk_nss w = { - .lookup = &__nss_group_nonlocal_lookup, .fct_name = "setgrent", + .lookup2 = &__nss_group_nonlocal_lookup2, .fct_name = "setgrent", .status = &status }; const __typeof__(&_nss_nonlocal_setgrent) self = NULL; @@ -193,9 +198,12 @@ _nss_nonlocal_setgrent(int stayopen) if (status != NSS_STATUS_SUCCESS) return status; - if (grent_fct_start == NULL) - __nss_group_nonlocal_lookup(&grent_startp, grent_fct_name, - &grent_fct_start); + if (!grent_initialized) { + __nss_group_nonlocal_lookup2(&grent_startp, grent_fct_name, NULL, + &grent_fct_start); + __sync_synchronize(); + grent_initialized = true; + } grent_nip = grent_startp; grent_fct.ptr = grent_fct_start; return NSS_STATUS_SUCCESS; @@ -206,8 +214,8 @@ _nss_nonlocal_endgrent(void) { enum nss_status status; const struct walk_nss w = { - .lookup = &__nss_group_nonlocal_lookup, .fct_name = "endgrent", - .status = &status + .lookup2 = &__nss_group_nonlocal_lookup2, .fct_name = "endgrent", + .status = &status, .all_values = 1, }; const __typeof__(&_nss_nonlocal_endgrent) self = NULL; @@ -249,7 +257,8 @@ _nss_nonlocal_getgrent_r(struct group *grp, char *buffer, size_t buflen, if (status == NSS_STATUS_SUCCESS) return NSS_STATUS_SUCCESS; - } while (__nss_next(&grent_nip, grent_fct_name, &grent_fct.ptr, status, 0) == 0); + } while (__nss_next2(&grent_nip, grent_fct_name, NULL, &grent_fct.ptr, + status, 0) == 0); grent_nip = NULL; return NSS_STATUS_NOTFOUND; @@ -262,7 +271,7 @@ _nss_nonlocal_getgrnam_r(const char *name, struct group *grp, { enum nss_status status; const struct walk_nss w = { - .lookup = &__nss_group_nonlocal_lookup, .fct_name = "getgrnam_r", + .lookup2 = &__nss_group_nonlocal_lookup2, .fct_name = "getgrnam_r", .status = &status, .errnop = errnop }; const __typeof__(&_nss_nonlocal_getgrnam_r) self = NULL; @@ -291,7 +300,7 @@ _nss_nonlocal_getgrgid_r(gid_t gid, struct group *grp, { enum nss_status status; const struct walk_nss w = { - .lookup = &__nss_group_nonlocal_lookup, .fct_name = "getgrgid_r", + .lookup2 = &__nss_group_nonlocal_lookup2, .fct_name = "getgrgid_r", .status = &status, .errnop = errnop }; const __typeof__(&_nss_nonlocal_getgrgid_r) self = NULL; @@ -354,8 +363,8 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start, { enum nss_status status; const struct walk_nss w = { - .lookup = &__nss_group_nonlocal_lookup, .fct_name = "initgroups_dyn", - .status = &status, .errnop = errnop + .lookup2 = &__nss_group_nonlocal_lookup2, .fct_name = "initgroups_dyn", + .status = &status, .all_values = 1, .errnop = errnop }; const __typeof__(&_nss_nonlocal_initgroups_dyn) self = NULL; @@ -444,7 +453,9 @@ _nss_nonlocal_initgroups_dyn(const char *user, gid_t group, long int *start, #define args (user, group, start, size, groupsp, limit, errnop) #include "walk_nss.h" #undef args - if (status != NSS_STATUS_SUCCESS) + if (status == NSS_STATUS_NOTFOUND || status == NSS_STATUS_UNAVAIL) + return NSS_STATUS_SUCCESS; + else if (status != NSS_STATUS_SUCCESS) return status; for (; in < *start; ++in) {