>From b916fadf10140f4d9a60460d6923f0fb9938df78 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Tue, 30 Jun 2015 18:56:38 +0200 Subject: [PATCH 2/2] sss_client: Re-check memcache after acquiring the lock Resolves: https://fedorahosted.org/sssd/ticket/2581 --- src/sss_client/nss_group.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ src/sss_client/nss_passwd.c | 42 +++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index b614fcf7f493345f793d3d4a28df998534ca546b..0e686af43aeb84a5938315e3922e9fcf2fef4e83 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -316,6 +316,28 @@ enum nss_status _nss_sss_initgroups_dyn(const char *user, gid_t group, sss_nss_lock(); + /* previous thread might already initialize entry in mmap cache */ + ret = sss_nss_mc_initgroups_dyn(user, user_len, group, start, size, + groups, limit); + switch (ret) { + case 0: + *errnop = 0; + nret = NSS_STATUS_SUCCESS; + goto out; + case ERANGE: + *errnop = ERANGE; + nret = NSS_STATUS_TRYAGAIN; + goto out; + case ENOENT: + /* fall through, we need to actively ask the parent + * if no entry is found */ + break; + default: + /* if using the mmaped cache failed, + * fall back to socket based comms */ + break; + } + nret = sss_nss_make_request(SSS_NSS_INITGR, &rd, &repbuf, &replen, errnop); if (nret != NSS_STATUS_SUCCESS) { @@ -418,6 +440,27 @@ enum nss_status _nss_sss_getgrnam_r(const char *name, struct group *result, sss_nss_lock(); + /* previous thread might already initialize entry in mmap cache */ + ret = sss_nss_mc_getgrnam(name, name_len, result, buffer, buflen); + switch (ret) { + case 0: + *errnop = 0; + nret = NSS_STATUS_SUCCESS; + goto out; + case ERANGE: + *errnop = ERANGE; + nret = NSS_STATUS_TRYAGAIN; + goto out; + case ENOENT: + /* fall through, we need to actively ask the parent + * if no entry is found */ + break; + default: + /* if using the mmaped cache failed, + * fall back to socket based comms */ + break; + } + nret = sss_nss_get_getgr_cache(name, 0, GETGR_NAME, &repbuf, &replen, errnop); if (nret == NSS_STATUS_NOTFOUND) { @@ -509,6 +552,27 @@ enum nss_status _nss_sss_getgrgid_r(gid_t gid, struct group *result, sss_nss_lock(); + /* previous thread might already initialize entry in mmap cache */ + ret = sss_nss_mc_getgrgid(gid, result, buffer, buflen); + switch (ret) { + case 0: + *errnop = 0; + nret = NSS_STATUS_SUCCESS; + goto out; + case ERANGE: + *errnop = ERANGE; + nret = NSS_STATUS_TRYAGAIN; + goto out; + case ENOENT: + /* fall through, we need to actively ask the parent + * if no entry is found */ + break; + default: + /* if using the mmaped cache failed, + * fall back to socket based comms */ + break; + } + nret = sss_nss_get_getgr_cache(NULL, gid, GETGR_GID, &repbuf, &replen, errnop); if (nret == NSS_STATUS_NOTFOUND) { diff --git a/src/sss_client/nss_passwd.c b/src/sss_client/nss_passwd.c index 290aed80e0ddd817a0b2c818fdd0816cd2673a41..c43f9bc50f43599b541e97f5a5aa60de036a5cdf 100644 --- a/src/sss_client/nss_passwd.c +++ b/src/sss_client/nss_passwd.c @@ -178,6 +178,27 @@ enum nss_status _nss_sss_getpwnam_r(const char *name, struct passwd *result, sss_nss_lock(); + /* previous thread might already initialize entry in mmap cache */ + ret = sss_nss_mc_getpwnam(name, name_len, result, buffer, buflen); + switch (ret) { + case 0: + *errnop = 0; + nret = NSS_STATUS_SUCCESS; + goto out; + case ERANGE: + *errnop = ERANGE; + nret = NSS_STATUS_TRYAGAIN; + goto out; + case ENOENT: + /* fall through, we need to actively ask the parent + * if no entry is found */ + break; + default: + /* if using the mmaped cache failed, + * fall back to socket based comms */ + break; + } + nret = sss_nss_make_request(SSS_NSS_GETPWNAM, &rd, &repbuf, &replen, errnop); if (nret != NSS_STATUS_SUCCESS) { @@ -261,6 +282,27 @@ enum nss_status _nss_sss_getpwuid_r(uid_t uid, struct passwd *result, sss_nss_lock(); + /* previous thread might already initialize entry in mmap cache */ + ret = sss_nss_mc_getpwuid(uid, result, buffer, buflen); + switch (ret) { + case 0: + *errnop = 0; + nret = NSS_STATUS_SUCCESS; + goto out; + case ERANGE: + *errnop = ERANGE; + nret = NSS_STATUS_TRYAGAIN; + goto out; + case ENOENT: + /* fall through, we need to actively ask the parent + * if no entry is found */ + break; + default: + /* if using the mmaped cache failed, + * fall back to socket based comms */ + break; + } + nret = sss_nss_make_request(SSS_NSS_GETPWUID, &rd, &repbuf, &replen, errnop); if (nret != NSS_STATUS_SUCCESS) { -- 2.4.3