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

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