Blame SOURCES/0025-NSS-add-support-for-SSS_NSS_EX_FLAG_NO_CACHE.patch

ced1f5
From 21633dc4ad13c0ebae0f2b4e4f4188556202113e Mon Sep 17 00:00:00 2001
ced1f5
From: Sumit Bose <sbose@redhat.com>
ced1f5
Date: Thu, 12 Oct 2017 10:42:41 +0200
ced1f5
Subject: [PATCH 25/31] NSS: add support for SSS_NSS_EX_FLAG_NO_CACHE
ced1f5
ced1f5
If SSS_NSS_EX_FLAG_NO_CACHE is set the object is refresh by directly
ced1f5
looking it up in the backend.
ced1f5
ced1f5
Related to https://pagure.io/SSSD/sssd/issue/2478
ced1f5
ced1f5
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ced1f5
(cherry picked from commit ac6b267ff3df6d0417062a128ec16b184ea2c1b7)
ced1f5
---
ced1f5
 src/responder/nss/nss_cmd.c          |  8 ++++
ced1f5
 src/sss_client/idmap/sss_nss_ex.c    | 71 ++++++++++++++++++++----------------
ced1f5
 src/sss_client/idmap/sss_nss_idmap.h |  4 ++
ced1f5
 3 files changed, 52 insertions(+), 31 deletions(-)
ced1f5
ced1f5
diff --git a/src/responder/nss/nss_cmd.c b/src/responder/nss/nss_cmd.c
ced1f5
index 974eaccc93cea3a330007735676da69eb9b84141..c5ddd2f2cc2122cd169ea991b94a14eb5bad095f 100644
ced1f5
--- a/src/responder/nss/nss_cmd.c
ced1f5
+++ b/src/responder/nss/nss_cmd.c
ced1f5
@@ -92,6 +92,10 @@ static errno_t nss_getby_name(struct cli_ctx *cli_ctx,
ced1f5
         goto done;
ced1f5
     }
ced1f5
 
ced1f5
+    if ((flags & SSS_NSS_EX_FLAG_NO_CACHE) != 0) {
ced1f5
+        cache_req_data_set_bypass_cache(data, true);
ced1f5
+    }
ced1f5
+
ced1f5
     subreq = nss_get_object_send(cmd_ctx, cli_ctx->ev, cli_ctx,
ced1f5
                                  data, memcache, rawname, 0);
ced1f5
     if (subreq == NULL) {
ced1f5
@@ -152,6 +156,10 @@ static errno_t nss_getby_id(struct cli_ctx *cli_ctx,
ced1f5
         goto done;
ced1f5
     }
ced1f5
 
ced1f5
+    if ((flags & SSS_NSS_EX_FLAG_NO_CACHE) != 0) {
ced1f5
+        cache_req_data_set_bypass_cache(data, true);
ced1f5
+    }
ced1f5
+
ced1f5
     subreq = nss_get_object_send(cmd_ctx, cli_ctx->ev, cli_ctx,
ced1f5
                                  data, memcache, NULL, id);
ced1f5
     if (subreq == NULL) {
ced1f5
diff --git a/src/sss_client/idmap/sss_nss_ex.c b/src/sss_client/idmap/sss_nss_ex.c
ced1f5
index dc7610a4e528b5126f0d25d84cd3c1a22f683b75..edb3ea652ef7032b76c8f815b9f83fe185a669ea 100644
ced1f5
--- a/src/sss_client/idmap/sss_nss_ex.c
ced1f5
+++ b/src/sss_client/idmap/sss_nss_ex.c
ced1f5
@@ -115,42 +115,51 @@ int sss_get_ex(struct nss_input *inp, uint32_t flags, unsigned int timeout)
ced1f5
     size_t c;
ced1f5
     gid_t *new_groups;
ced1f5
     size_t idx;
ced1f5
+    bool skip_mc = false;
ced1f5
 
ced1f5
-    ret = sss_nss_mc_get(inp);
ced1f5
-    switch (ret) {
ced1f5
-    case 0:
ced1f5
-        return 0;
ced1f5
-    case ERANGE:
ced1f5
-        return ERANGE;
ced1f5
-    case ENOENT:
ced1f5
-        /* fall through, we need to actively ask the parent
ced1f5
-         * if no entry is found */
ced1f5
-        break;
ced1f5
-    default:
ced1f5
-        /* if using the mmaped cache failed,
ced1f5
-         * fall back to socket based comms */
ced1f5
-        break;
ced1f5
+    if ((flags & SSS_NSS_EX_FLAG_NO_CACHE) != 0) {
ced1f5
+        skip_mc = true;
ced1f5
+    }
ced1f5
+
ced1f5
+    if (!skip_mc) {
ced1f5
+        ret = sss_nss_mc_get(inp);
ced1f5
+        switch (ret) {
ced1f5
+        case 0:
ced1f5
+            return 0;
ced1f5
+        case ERANGE:
ced1f5
+            return ERANGE;
ced1f5
+        case ENOENT:
ced1f5
+            /* fall through, we need to actively ask the parent
ced1f5
+             * if no entry is found */
ced1f5
+            break;
ced1f5
+        default:
ced1f5
+            /* if using the mmaped cache failed,
ced1f5
+             * fall back to socket based comms */
ced1f5
+            break;
ced1f5
+        }
ced1f5
     }
ced1f5
 
ced1f5
     sss_nss_timedlock(timeout, &time_left);
ced1f5
 
ced1f5
-    /* previous thread might already initialize entry in mmap cache */
ced1f5
-    ret = sss_nss_mc_get(inp);
ced1f5
-    switch (ret) {
ced1f5
-    case 0:
ced1f5
-        ret = 0;
ced1f5
-        goto out;
ced1f5
-    case ERANGE:
ced1f5
-        ret = ERANGE;
ced1f5
-        goto out;
ced1f5
-    case ENOENT:
ced1f5
-        /* fall through, we need to actively ask the parent
ced1f5
-         * if no entry is found */
ced1f5
-        break;
ced1f5
-    default:
ced1f5
-        /* if using the mmaped cache failed,
ced1f5
-         * fall back to socket based comms */
ced1f5
-        break;
ced1f5
+    if (!skip_mc) {
ced1f5
+        /* previous thread might already initialize entry in mmap cache */
ced1f5
+        ret = sss_nss_mc_get(inp);
ced1f5
+        switch (ret) {
ced1f5
+        case 0:
ced1f5
+            ret = 0;
ced1f5
+            goto out;
ced1f5
+        case ERANGE:
ced1f5
+            ret = ERANGE;
ced1f5
+            goto out;
ced1f5
+        case ENOENT:
ced1f5
+            /* fall through, we need to actively ask the parent
ced1f5
+             * if no entry is found */
ced1f5
+            break;
ced1f5
+        default:
ced1f5
+            /* if using the mmaped cache failed,
ced1f5
+             * fall back to socket based comms */
ced1f5
+            break;
ced1f5
+        }
ced1f5
     }
ced1f5
 
ced1f5
     ret = sss_nss_make_request_timeout(inp->cmd, &inp->rd, time_left,
ced1f5
diff --git a/src/sss_client/idmap/sss_nss_idmap.h b/src/sss_client/idmap/sss_nss_idmap.h
ced1f5
index 2334b6cb3fb8ef62e4ce3a7187c7affaeaa034e7..1649830afbb80c617fd339f054aef8bc8e585fb9 100644
ced1f5
--- a/src/sss_client/idmap/sss_nss_idmap.h
ced1f5
+++ b/src/sss_client/idmap/sss_nss_idmap.h
ced1f5
@@ -169,6 +169,10 @@ void sss_nss_free_kv(struct sss_nss_kv *kv_list);
ced1f5
 
ced1f5
 #define SSS_NSS_EX_FLAG_NO_FLAGS 0
ced1f5
 
ced1f5
+/** Always request data from the server side, client must be privileged to do
ced1f5
+ *  so, see nss_trusted_users option in man sssd.conf for details */
ced1f5
+#define SSS_NSS_EX_FLAG_NO_CACHE (1 << 0)
ced1f5
+
ced1f5
 #ifdef IPA_389DS_PLUGIN_HELPER_CALLS
ced1f5
 
ced1f5
 /**
ced1f5
-- 
ced1f5
2.13.6
ced1f5