summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2015-06-30 18:56:38 +0200
committerJakub Hrozek <jhrozek@redhat.com>2015-07-03 15:17:12 +0200
commit537e277876a7e4b81e68eb3836586b1a765ba0dc (patch)
treec2926d0db4c1da7094260d68e3604de5ce192975
parent0ed6114c6b2cc9d7e0c09842d19f0987e9ebbb4a (diff)
downloadsssd-537e277876a7e4b81e68eb3836586b1a765ba0dc.tar.gz
sssd-537e277876a7e4b81e68eb3836586b1a765ba0dc.tar.xz
sssd-537e277876a7e4b81e68eb3836586b1a765ba0dc.zip
sss_client: Re-check memcache after acquiring the lock
Resolves: https://fedorahosted.org/sssd/ticket/2581 Reviewed-by: Michal Židek <mzidek@redhat.com>
-rw-r--r--src/sss_client/nss_group.c64
-rw-r--r--src/sss_client/nss_passwd.c42
2 files changed, 106 insertions, 0 deletions
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c
index b614fcf7f..0e686af43 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 290aed80e..c43f9bc50 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) {