Blame SOURCES/0026-CACHE_REQ-Add-cache_req_data_set_bypass_dp.patch

9f2ebf
From 102ea8cf91207d3dc05537d5c558d98e4756027a Mon Sep 17 00:00:00 2001
9f2ebf
From: Sumit Bose <sbose@redhat.com>
9f2ebf
Date: Mon, 23 Oct 2017 18:26:55 +0200
9f2ebf
Subject: [PATCH 26/31] CACHE_REQ: Add cache_req_data_set_bypass_dp()
9f2ebf
9f2ebf
Similar to cache_req_data_set_bypass_cache()
9f2ebf
cache_req_data_set_bypass_dp() can be used to control how the cache_req
9f2ebf
framework performs the lookup. If cache_req_data_set_bypass_dp() is used
9f2ebf
with 'true' only a cache lookup is performed and no request is send to
9f2ebf
the backend even if no entry was found.
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 52e675ec4b160720515c81ae8c0e5a95feb50c57)
9f2ebf
---
9f2ebf
 src/responder/common/cache_req/cache_req.c         | 15 +++++++++++++++
9f2ebf
 src/responder/common/cache_req/cache_req.h         |  3 +++
9f2ebf
 src/responder/common/cache_req/cache_req_data.c    | 12 ++++++++++++
9f2ebf
 src/responder/common/cache_req/cache_req_private.h |  2 ++
9f2ebf
 4 files changed, 32 insertions(+)
9f2ebf
9f2ebf
diff --git a/src/responder/common/cache_req/cache_req.c b/src/responder/common/cache_req/cache_req.c
9f2ebf
index 5fed7a2ab8beded2fee91f679a12f9a0ff6013ec..110df561101be538e3f0496addfa2e14e42ea918 100644
9f2ebf
--- a/src/responder/common/cache_req/cache_req.c
9f2ebf
+++ b/src/responder/common/cache_req/cache_req.c
9f2ebf
@@ -142,6 +142,13 @@ cache_req_create(TALLOC_CTX *mem_ctx,
9f2ebf
 
9f2ebf
     cr->cache_first = rctx->cache_first;
9f2ebf
     cr->bypass_cache = cr->plugin->bypass_cache || cr->data->bypass_cache;
9f2ebf
+    cr->bypass_dp = cr->data->bypass_dp;
9f2ebf
+    if (cr->bypass_cache && cr->bypass_dp) {
9f2ebf
+        CACHE_REQ_DEBUG(SSSDBG_CRIT_FAILURE, cr,
9f2ebf
+                        "Cannot bypass cache and dp at the same time!");
9f2ebf
+        talloc_free(cr);
9f2ebf
+        return NULL;
9f2ebf
+    }
9f2ebf
 
9f2ebf
     return cr;
9f2ebf
 }
9f2ebf
@@ -661,6 +668,14 @@ static bool cache_req_search_schema(struct cache_req *cr,
9f2ebf
         if (!first_iteration) {
9f2ebf
             return false;
9f2ebf
         }
9f2ebf
+    } else if (cr->bypass_dp) {
9f2ebf
+        /* The caller wants to lookup only in the cache */
9f2ebf
+        bypass_cache = false;
9f2ebf
+        bypass_dp = true;
9f2ebf
+
9f2ebf
+        if (!first_iteration) {
9f2ebf
+            return false;
9f2ebf
+        }
9f2ebf
     } else if (input_domain != NULL) {
9f2ebf
         /* We will search only one domain. */
9f2ebf
         bypass_cache = false;
9f2ebf
diff --git a/src/responder/common/cache_req/cache_req.h b/src/responder/common/cache_req/cache_req.h
9f2ebf
index c04b2fba6f0445dcfcc9cfe1b5963ac975c39118..2c88853887fc816bba2182d9d9beaa32fa384158 100644
9f2ebf
--- a/src/responder/common/cache_req/cache_req.h
9f2ebf
+++ b/src/responder/common/cache_req/cache_req.h
9f2ebf
@@ -127,6 +127,9 @@ void
9f2ebf
 cache_req_data_set_bypass_cache(struct cache_req_data *data,
9f2ebf
                                 bool bypass_cache);
9f2ebf
 
9f2ebf
+void
9f2ebf
+cache_req_data_set_bypass_dp(struct cache_req_data *data,
9f2ebf
+                             bool bypass_dp);
9f2ebf
 /* Output data. */
9f2ebf
 
9f2ebf
 struct cache_req_result {
9f2ebf
diff --git a/src/responder/common/cache_req/cache_req_data.c b/src/responder/common/cache_req/cache_req_data.c
9f2ebf
index 48264a321dc603f9708ba71c44542363b11a71ba..ed378274a9a0a68ede8ac99805f3ea4a041382e6 100644
9f2ebf
--- a/src/responder/common/cache_req/cache_req_data.c
9f2ebf
+++ b/src/responder/common/cache_req/cache_req_data.c
9f2ebf
@@ -365,3 +365,15 @@ cache_req_data_set_bypass_cache(struct cache_req_data *data,
9f2ebf
 
9f2ebf
     data->bypass_cache = bypass_cache;
9f2ebf
 }
9f2ebf
+
9f2ebf
+void
9f2ebf
+cache_req_data_set_bypass_dp(struct cache_req_data *data,
9f2ebf
+                             bool bypass_dp)
9f2ebf
+{
9f2ebf
+    if (data == NULL) {
9f2ebf
+        DEBUG(SSSDBG_CRIT_FAILURE, "cache_req_data should never be NULL\n");
9f2ebf
+        return;
9f2ebf
+    }
9f2ebf
+
9f2ebf
+    data->bypass_dp = bypass_dp;
9f2ebf
+}
9f2ebf
diff --git a/src/responder/common/cache_req/cache_req_private.h b/src/responder/common/cache_req/cache_req_private.h
9f2ebf
index 9b706ff7d678f543effb77089857a7e8a42a9c51..0f630542d38a277d1819063fa4134bd7d2525c90 100644
9f2ebf
--- a/src/responder/common/cache_req/cache_req_private.h
9f2ebf
+++ b/src/responder/common/cache_req/cache_req_private.h
9f2ebf
@@ -42,6 +42,7 @@ struct cache_req {
9f2ebf
     struct sss_domain_info *domain;
9f2ebf
     bool cache_first;
9f2ebf
     bool bypass_cache;
9f2ebf
+    bool bypass_dp;
9f2ebf
     /* Only contact domains with this type */
9f2ebf
     enum cache_req_dom_type req_dom_type;
9f2ebf
 
9f2ebf
@@ -90,6 +91,7 @@ struct cache_req_data {
9f2ebf
     } svc;
9f2ebf
 
9f2ebf
     bool bypass_cache;
9f2ebf
+    bool bypass_dp;
9f2ebf
 };
9f2ebf
 
9f2ebf
 struct tevent_req *
9f2ebf
-- 
9f2ebf
2.13.6
9f2ebf