Blame SOURCES/0081-CACHE_REQ-Implement-the-plugin-methods-that-utilize-.patch

ced1f5
From 7482c6affd4dfa77a8d465ff0283617792847725 Mon Sep 17 00:00:00 2001
ced1f5
From: Jakub Hrozek <jhrozek@redhat.com>
ced1f5
Date: Mon, 6 Nov 2017 15:52:11 +0100
ced1f5
Subject: [PATCH 81/83] CACHE_REQ: Implement the plugin methods that utilize
ced1f5
 the domain locator API
ced1f5
MIME-Version: 1.0
ced1f5
Content-Type: text/plain; charset=UTF-8
ced1f5
Content-Transfer-Encoding: 8bit
ced1f5
ced1f5
Mainly, this patch adds handlers for the dp_get_domain_check_fn(),
ced1f5
dp_get_domain_send_fn() and dp_get_domain_recv_fn() functions to
ced1f5
requests that resolve objects by ID.
ced1f5
ced1f5
This patch also adds domain-local negcache setter for by-id methods
ced1f5
Previously, the by-ID methods only used global negative cache setters
ced1f5
because the ID space is global and we always iterated over all domains.
ced1f5
ced1f5
However, with addition of the domain locator plugin, we want also
ced1f5
to skip only certain domains and the easiest way to to so is to add
ced1f5
the IDs for domains that do not contain these IDs to the negative cache
ced1f5
with the get-account-domain request.
ced1f5
ced1f5
Therefore this patch also adds per-domain negative cache setters for
ced1f5
the three plugins that search by ID.
ced1f5
ced1f5
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ced1f5
Reviewed-by: Sumit Bose <sbose@redhat.com>
ced1f5
(cherry picked from commit a6eb9c4c3ff68d134bc745e8374f182737e9696b)
ced1f5
---
ced1f5
 src/responder/common/cache_req/cache_req_private.h |  5 ++
ced1f5
 .../common/cache_req/plugins/cache_req_common.c    | 17 +++++
ced1f5
 .../cache_req/plugins/cache_req_group_by_id.c      | 62 +++++++++++++++--
ced1f5
 .../cache_req/plugins/cache_req_object_by_id.c     | 77 ++++++++++++++++++++--
ced1f5
 .../cache_req/plugins/cache_req_user_by_id.c       | 63 ++++++++++++++++--
ced1f5
 src/tests/cmocka/common_mock_resp_dp.c             | 23 +++++++
ced1f5
 6 files changed, 235 insertions(+), 12 deletions(-)
ced1f5
ced1f5
diff --git a/src/responder/common/cache_req/cache_req_private.h b/src/responder/common/cache_req/cache_req_private.h
ced1f5
index 9586e3788045ff44eb2a4b626dc7fcaf11ec8028..95f24c0e5b9ab1150591d308c7288c57fe478c5d 100644
ced1f5
--- a/src/responder/common/cache_req/cache_req_private.h
ced1f5
+++ b/src/responder/common/cache_req/cache_req_private.h
ced1f5
@@ -187,4 +187,9 @@ bool
ced1f5
 cache_req_common_dp_recv(struct tevent_req *subreq,
ced1f5
                          struct cache_req *cr);
ced1f5
 
ced1f5
+errno_t
ced1f5
+cache_reg_common_get_acct_domain_recv(TALLOC_CTX *mem_ctx,
ced1f5
+                                      struct tevent_req *subreq,
ced1f5
+                                      struct cache_req *cr,
ced1f5
+                                      char **_domain);
ced1f5
 #endif /* _CACHE_REQ_PRIVATE_H_ */
ced1f5
diff --git a/src/responder/common/cache_req/plugins/cache_req_common.c b/src/responder/common/cache_req/plugins/cache_req_common.c
ced1f5
index 1f86258bc14c7a382712959f24a4ec4c153572d4..408c91949ceb3ecaf743f270f58f4e3fcfc3ccb1 100644
ced1f5
--- a/src/responder/common/cache_req/plugins/cache_req_common.c
ced1f5
+++ b/src/responder/common/cache_req/plugins/cache_req_common.c
ced1f5
@@ -147,3 +147,20 @@ done:
ced1f5
     talloc_free(err_msg);
ced1f5
     return bret;
ced1f5
 }
ced1f5
+
ced1f5
+errno_t
ced1f5
+cache_reg_common_get_acct_domain_recv(TALLOC_CTX *mem_ctx,
ced1f5
+                                      struct tevent_req *subreq,
ced1f5
+                                      struct cache_req *cr,
ced1f5
+                                      char **_domain)
ced1f5
+{
ced1f5
+    errno_t ret;
ced1f5
+
ced1f5
+    ret = sss_dp_get_account_domain_recv(mem_ctx, subreq, _domain);
ced1f5
+    if (ret != EOK) {
ced1f5
+        CACHE_REQ_DEBUG(SSSDBG_MINOR_FAILURE, cr,
ced1f5
+                        "Could not get account domain [%d]: %s\n",
ced1f5
+                        ret, sss_strerror(ret));
ced1f5
+    }
ced1f5
+    return ret;
ced1f5
+}
ced1f5
diff --git a/src/responder/common/cache_req/plugins/cache_req_group_by_id.c b/src/responder/common/cache_req/plugins/cache_req_group_by_id.c
ced1f5
index 70381266712d2c27c95027b54efab201c5df7690..ce84b1b4458b447ff6b4b036c6e8fe8f4d7758c8 100644
ced1f5
--- a/src/responder/common/cache_req/plugins/cache_req_group_by_id.c
ced1f5
+++ b/src/responder/common/cache_req/plugins/cache_req_group_by_id.c
ced1f5
@@ -39,6 +39,15 @@ cache_req_group_by_id_ncache_check(struct sss_nc_ctx *ncache,
ced1f5
                                    struct sss_domain_info *domain,
ced1f5
                                    struct cache_req_data *data)
ced1f5
 {
ced1f5
+    errno_t ret;
ced1f5
+
ced1f5
+    if (domain != NULL) {
ced1f5
+        ret = sss_ncache_check_gid(ncache, domain, data->id);
ced1f5
+        if (ret == EEXIST) {
ced1f5
+            return ret;
ced1f5
+        }
ced1f5
+    }
ced1f5
+
ced1f5
     return sss_ncache_check_gid(ncache, NULL, data->id);
ced1f5
 }
ced1f5
 
ced1f5
@@ -57,6 +66,14 @@ cache_req_group_by_id_global_ncache_add(struct sss_nc_ctx *ncache,
ced1f5
     return sss_ncache_set_gid(ncache, false, NULL, data->id);
ced1f5
 }
ced1f5
 
ced1f5
+static errno_t
ced1f5
+cache_req_group_by_id_ncache_add(struct sss_nc_ctx *ncache,
ced1f5
+                                 struct sss_domain_info *domain,
ced1f5
+                                 struct cache_req_data *data)
ced1f5
+{
ced1f5
+    return sss_ncache_set_gid(ncache, false, domain, data->id);
ced1f5
+}
ced1f5
+
ced1f5
 static errno_t
ced1f5
 cache_req_group_by_id_lookup(TALLOC_CTX *mem_ctx,
ced1f5
                              struct cache_req *cr,
ced1f5
@@ -132,6 +149,43 @@ cache_req_group_by_id_dp_send(TALLOC_CTX *mem_ctx,
ced1f5
                                    SSS_DP_GROUP, string, id, flag);
ced1f5
 }
ced1f5
 
ced1f5
+static bool
ced1f5
+cache_req_group_by_id_get_domain_check(struct resp_ctx *rctx,
ced1f5
+                                       struct sss_domain_info *domain,
ced1f5
+                                       struct cache_req_data *data)
ced1f5
+{
ced1f5
+    int nret;
ced1f5
+
ced1f5
+    nret = sss_ncache_check_locate_gid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret == EEXIST) {
ced1f5
+        return false;
ced1f5
+    }
ced1f5
+
ced1f5
+    return true;
ced1f5
+}
ced1f5
+
ced1f5
+static struct tevent_req *
ced1f5
+cache_req_group_by_id_get_domain_send(TALLOC_CTX *mem_ctx,
ced1f5
+                                      struct resp_ctx *rctx,
ced1f5
+                                      struct sss_domain_info *domain,
ced1f5
+                                      struct cache_req_data *data)
ced1f5
+{
ced1f5
+    int nret;
ced1f5
+
ced1f5
+    nret = sss_ncache_set_locate_gid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret != EOK) {
ced1f5
+        DEBUG(SSSDBG_MINOR_FAILURE,
ced1f5
+              "Cannot set negative cache, this might result in performance degradation\n");
ced1f5
+        /* Not fatal */
ced1f5
+    }
ced1f5
+
ced1f5
+    return sss_dp_get_account_domain_send(mem_ctx,
ced1f5
+                                          rctx,
ced1f5
+                                          domain,
ced1f5
+                                          SSS_DP_GROUP,
ced1f5
+                                          data->id);
ced1f5
+}
ced1f5
+
ced1f5
 const struct cache_req_plugin cache_req_group_by_id = {
ced1f5
     .name = "Group by ID",
ced1f5
     .attr_expiration = SYSDB_CACHE_EXPIRE,
ced1f5
@@ -151,14 +205,14 @@ const struct cache_req_plugin cache_req_group_by_id = {
ced1f5
     .create_debug_name_fn = cache_req_group_by_id_create_debug_name,
ced1f5
     .global_ncache_add_fn = cache_req_group_by_id_global_ncache_add,
ced1f5
     .ncache_check_fn = cache_req_group_by_id_ncache_check,
ced1f5
-    .ncache_add_fn = NULL,
ced1f5
+    .ncache_add_fn = cache_req_group_by_id_ncache_add,
ced1f5
     .ncache_filter_fn = cache_req_group_by_id_ncache_filter,
ced1f5
     .lookup_fn = cache_req_group_by_id_lookup,
ced1f5
     .dp_send_fn = cache_req_group_by_id_dp_send,
ced1f5
     .dp_recv_fn = cache_req_common_dp_recv,
ced1f5
-    .dp_get_domain_check_fn = NULL,
ced1f5
-    .dp_get_domain_send_fn = NULL,
ced1f5
-    .dp_get_domain_recv_fn = NULL,
ced1f5
+    .dp_get_domain_check_fn = cache_req_group_by_id_get_domain_check,
ced1f5
+    .dp_get_domain_send_fn = cache_req_group_by_id_get_domain_send,
ced1f5
+    .dp_get_domain_recv_fn = cache_reg_common_get_acct_domain_recv,
ced1f5
 };
ced1f5
 
ced1f5
 struct tevent_req *
ced1f5
diff --git a/src/responder/common/cache_req/plugins/cache_req_object_by_id.c b/src/responder/common/cache_req/plugins/cache_req_object_by_id.c
ced1f5
index 2af95313cb2df0f46a61519ac962074033f34a12..1327b480c1b1b68f9826fa229c9b001f2d92b79b 100644
ced1f5
--- a/src/responder/common/cache_req/plugins/cache_req_object_by_id.c
ced1f5
+++ b/src/responder/common/cache_req/plugins/cache_req_object_by_id.c
ced1f5
@@ -83,6 +83,26 @@ cache_req_object_by_id_global_ncache_add(struct sss_nc_ctx *ncache,
ced1f5
     return EOK;
ced1f5
 }
ced1f5
 
ced1f5
+static errno_t
ced1f5
+cache_req_object_by_id_ncache_add(struct sss_nc_ctx *ncache,
ced1f5
+                                  struct sss_domain_info *domain,
ced1f5
+                                  struct cache_req_data *data)
ced1f5
+{
ced1f5
+    errno_t ret;
ced1f5
+
ced1f5
+    ret = sss_ncache_set_uid(ncache, false, domain, data->id);
ced1f5
+    if (ret != EOK) {
ced1f5
+        return ret;
ced1f5
+    }
ced1f5
+
ced1f5
+    ret = sss_ncache_set_gid(ncache, false, domain, data->id);
ced1f5
+    if (ret != EOK) {
ced1f5
+        return ret;
ced1f5
+    }
ced1f5
+
ced1f5
+    return EOK;
ced1f5
+}
ced1f5
+
ced1f5
 static errno_t
ced1f5
 cache_req_object_by_id_lookup(TALLOC_CTX *mem_ctx,
ced1f5
                               struct cache_req *cr,
ced1f5
@@ -106,6 +126,55 @@ cache_req_object_by_id_dp_send(TALLOC_CTX *mem_ctx,
ced1f5
                                    cr->data->id, NULL);
ced1f5
 }
ced1f5
 
ced1f5
+static bool
ced1f5
+cache_req_object_by_id_get_domain_check(struct resp_ctx *rctx,
ced1f5
+                                        struct sss_domain_info *domain,
ced1f5
+                                        struct cache_req_data *data)
ced1f5
+{
ced1f5
+    int nret;
ced1f5
+
ced1f5
+    nret = sss_ncache_check_locate_uid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret == EEXIST) {
ced1f5
+        nret = sss_ncache_check_locate_gid(rctx->ncache, domain, data->id);
ced1f5
+        if (nret == EEXIST) {
ced1f5
+            return false;
ced1f5
+        }
ced1f5
+    }
ced1f5
+
ced1f5
+    return true;
ced1f5
+}
ced1f5
+
ced1f5
+static struct tevent_req *
ced1f5
+cache_req_object_by_id_get_domain_send(TALLOC_CTX *mem_ctx,
ced1f5
+                                       struct resp_ctx *rctx,
ced1f5
+                                       struct sss_domain_info *domain,
ced1f5
+                                       struct cache_req_data *data)
ced1f5
+{
ced1f5
+    int nret;
ced1f5
+
ced1f5
+    nret = sss_ncache_set_locate_uid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret != EOK) {
ced1f5
+        DEBUG(SSSDBG_MINOR_FAILURE,
ced1f5
+              "Cannot set negative cache, this might result in "
ced1f5
+              "performance degradation\n");
ced1f5
+        /* Not fatal */
ced1f5
+    }
ced1f5
+
ced1f5
+    nret = sss_ncache_set_locate_gid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret != EOK) {
ced1f5
+        DEBUG(SSSDBG_MINOR_FAILURE,
ced1f5
+              "Cannot set negative cache, this might result in "
ced1f5
+              "performance degradation\n");
ced1f5
+        /* Not fatal */
ced1f5
+    }
ced1f5
+
ced1f5
+    return sss_dp_get_account_domain_send(mem_ctx,
ced1f5
+                                          rctx,
ced1f5
+                                          domain,
ced1f5
+                                          SSS_DP_USER_AND_GROUP,
ced1f5
+                                          data->id);
ced1f5
+}
ced1f5
+
ced1f5
 const struct cache_req_plugin cache_req_object_by_id = {
ced1f5
     .name = "Object by ID",
ced1f5
     .attr_expiration = SYSDB_CACHE_EXPIRE,
ced1f5
@@ -125,14 +194,14 @@ const struct cache_req_plugin cache_req_object_by_id = {
ced1f5
     .create_debug_name_fn = cache_req_object_by_id_create_debug_name,
ced1f5
     .global_ncache_add_fn = cache_req_object_by_id_global_ncache_add,
ced1f5
     .ncache_check_fn = cache_req_object_by_id_ncache_check,
ced1f5
-    .ncache_add_fn = NULL,
ced1f5
+    .ncache_add_fn = cache_req_object_by_id_ncache_add,
ced1f5
     .ncache_filter_fn = cache_req_object_by_id_ncache_filter,
ced1f5
     .lookup_fn = cache_req_object_by_id_lookup,
ced1f5
     .dp_send_fn = cache_req_object_by_id_dp_send,
ced1f5
     .dp_recv_fn = cache_req_common_dp_recv,
ced1f5
-    .dp_get_domain_check_fn = NULL,
ced1f5
-    .dp_get_domain_send_fn = NULL,
ced1f5
-    .dp_get_domain_recv_fn = NULL,
ced1f5
+    .dp_get_domain_check_fn = cache_req_object_by_id_get_domain_check,
ced1f5
+    .dp_get_domain_send_fn = cache_req_object_by_id_get_domain_send,
ced1f5
+    .dp_get_domain_recv_fn = cache_reg_common_get_acct_domain_recv,
ced1f5
 };
ced1f5
 
ced1f5
 struct tevent_req *
ced1f5
diff --git a/src/responder/common/cache_req/plugins/cache_req_user_by_id.c b/src/responder/common/cache_req/plugins/cache_req_user_by_id.c
ced1f5
index 254330e92cc801b84bfb5e308d6d90ac54507d77..656fa41af5f39f68c64e241aa97c4eaf3ec57395 100644
ced1f5
--- a/src/responder/common/cache_req/plugins/cache_req_user_by_id.c
ced1f5
+++ b/src/responder/common/cache_req/plugins/cache_req_user_by_id.c
ced1f5
@@ -39,6 +39,15 @@ cache_req_user_by_id_ncache_check(struct sss_nc_ctx *ncache,
ced1f5
                                   struct sss_domain_info *domain,
ced1f5
                                   struct cache_req_data *data)
ced1f5
 {
ced1f5
+    errno_t ret;
ced1f5
+
ced1f5
+    if (domain != NULL) {
ced1f5
+        ret = sss_ncache_check_uid(ncache, domain, data->id);
ced1f5
+        if (ret == EEXIST) {
ced1f5
+            return ret;
ced1f5
+        }
ced1f5
+    }
ced1f5
+
ced1f5
     return sss_ncache_check_uid(ncache, NULL, data->id);
ced1f5
 }
ced1f5
 
ced1f5
@@ -57,6 +66,14 @@ cache_req_user_by_id_global_ncache_add(struct sss_nc_ctx *ncache,
ced1f5
     return sss_ncache_set_uid(ncache, false, NULL, data->id);
ced1f5
 }
ced1f5
 
ced1f5
+static errno_t
ced1f5
+cache_req_user_by_id_ncache_add(struct sss_nc_ctx *ncache,
ced1f5
+                                struct sss_domain_info *domain,
ced1f5
+                                struct cache_req_data *data)
ced1f5
+{
ced1f5
+    return sss_ncache_set_uid(ncache, false, domain, data->id);
ced1f5
+}
ced1f5
+
ced1f5
 static errno_t
ced1f5
 cache_req_user_by_id_lookup(TALLOC_CTX *mem_ctx,
ced1f5
                             struct cache_req *cr,
ced1f5
@@ -132,6 +149,44 @@ cache_req_user_by_id_dp_send(TALLOC_CTX *mem_ctx,
ced1f5
                                    SSS_DP_USER, string, id, flag);
ced1f5
 }
ced1f5
 
ced1f5
+static bool
ced1f5
+cache_req_user_by_id_get_domain_check(struct resp_ctx *rctx,
ced1f5
+                                      struct sss_domain_info *domain,
ced1f5
+                                      struct cache_req_data *data)
ced1f5
+{
ced1f5
+    int nret;
ced1f5
+
ced1f5
+    nret = sss_ncache_check_locate_uid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret == EEXIST) {
ced1f5
+        return false;
ced1f5
+    }
ced1f5
+
ced1f5
+    return true;
ced1f5
+}
ced1f5
+
ced1f5
+static struct tevent_req *
ced1f5
+cache_req_user_by_id_get_domain_send(TALLOC_CTX *mem_ctx,
ced1f5
+                                     struct resp_ctx *rctx,
ced1f5
+                                     struct sss_domain_info *domain,
ced1f5
+                                     struct cache_req_data *data)
ced1f5
+{
ced1f5
+    int nret;
ced1f5
+
ced1f5
+    nret = sss_ncache_set_locate_uid(rctx->ncache, domain, data->id);
ced1f5
+    if (nret != EOK) {
ced1f5
+        DEBUG(SSSDBG_MINOR_FAILURE,
ced1f5
+              "Cannot set negative cache, this might result in "
ced1f5
+              "performance degradation\n");
ced1f5
+        /* Not fatal */
ced1f5
+    }
ced1f5
+
ced1f5
+    return sss_dp_get_account_domain_send(mem_ctx,
ced1f5
+                                          rctx,
ced1f5
+                                          domain,
ced1f5
+                                          SSS_DP_USER,
ced1f5
+                                          data->id);
ced1f5
+}
ced1f5
+
ced1f5
 const struct cache_req_plugin cache_req_user_by_id = {
ced1f5
     .name = "User by ID",
ced1f5
     .attr_expiration = SYSDB_CACHE_EXPIRE,
ced1f5
@@ -151,14 +206,14 @@ const struct cache_req_plugin cache_req_user_by_id = {
ced1f5
     .create_debug_name_fn = cache_req_user_by_id_create_debug_name,
ced1f5
     .global_ncache_add_fn = cache_req_user_by_id_global_ncache_add,
ced1f5
     .ncache_check_fn = cache_req_user_by_id_ncache_check,
ced1f5
-    .ncache_add_fn = NULL,
ced1f5
+    .ncache_add_fn = cache_req_user_by_id_ncache_add,
ced1f5
     .ncache_filter_fn = cache_req_user_by_id_ncache_filter,
ced1f5
     .lookup_fn = cache_req_user_by_id_lookup,
ced1f5
     .dp_send_fn = cache_req_user_by_id_dp_send,
ced1f5
     .dp_recv_fn = cache_req_common_dp_recv,
ced1f5
-    .dp_get_domain_check_fn = NULL,
ced1f5
-    .dp_get_domain_send_fn = NULL,
ced1f5
-    .dp_get_domain_recv_fn = NULL,
ced1f5
+    .dp_get_domain_check_fn = cache_req_user_by_id_get_domain_check,
ced1f5
+    .dp_get_domain_send_fn = cache_req_user_by_id_get_domain_send,
ced1f5
+    .dp_get_domain_recv_fn = cache_reg_common_get_acct_domain_recv,
ced1f5
 };
ced1f5
 
ced1f5
 struct tevent_req *
ced1f5
diff --git a/src/tests/cmocka/common_mock_resp_dp.c b/src/tests/cmocka/common_mock_resp_dp.c
ced1f5
index 4b38a38e6f53499132f9fe14a0ec0af157cf85ca..f21ca53ad0d6b7f4ed28d0c1d9e491af31355d43 100644
ced1f5
--- a/src/tests/cmocka/common_mock_resp_dp.c
ced1f5
+++ b/src/tests/cmocka/common_mock_resp_dp.c
ced1f5
@@ -179,3 +179,26 @@ errno_t sss_dp_get_domains_recv(struct tevent_req *req)
ced1f5
 {
ced1f5
     return test_request_recv(req);
ced1f5
 }
ced1f5
+
ced1f5
+struct tevent_req *
ced1f5
+sss_dp_get_account_domain_send(TALLOC_CTX *mem_ctx,
ced1f5
+                               struct resp_ctx *rctx,
ced1f5
+                               struct sss_domain_info *domain,
ced1f5
+                               enum sss_dp_acct_type type,
ced1f5
+                               uint32_t opt_id)
ced1f5
+{
ced1f5
+    return test_req_succeed_send(mem_ctx, rctx->ev);
ced1f5
+}
ced1f5
+
ced1f5
+errno_t sss_dp_get_account_domain_recv(TALLOC_CTX *mem_ctx,
ced1f5
+                                       struct tevent_req *req,
ced1f5
+                                       char **_domain)
ced1f5
+{
ced1f5
+    errno_t ret;
ced1f5
+
ced1f5
+    ret = sss_mock_type(errno_t);
ced1f5
+    if (ret == EOK) {
ced1f5
+        *_domain = sss_mock_ptr_type(char *);
ced1f5
+    }
ced1f5
+    return ret;
ced1f5
+}
ced1f5
-- 
ced1f5
2.14.3
ced1f5