Blame SOURCES/0052-BE-LDAP-Split-out-a-helper-function-from-sdap_refres.patch

8d3578
From 080b154402ad076a562e0ea6d6e8c5d2fbcef5f5 Mon Sep 17 00:00:00 2001
8d3578
From: Jakub Hrozek <jhrozek@redhat.com>
8d3578
Date: Wed, 8 May 2019 14:38:44 +0200
8d3578
Subject: [PATCH 52/64] BE/LDAP: Split out a helper function from sdap_refresh
8d3578
 for later reuse
8d3578
8d3578
Every refresh request will send a similar account_req. Let's split out
8d3578
the function that creates the account_req into a reusable one.
8d3578
8d3578
Also removes the type string as it was only used in DEBUG messages and
8d3578
there is already a function in the back end API that provides the same
8d3578
functionality.
8d3578
8d3578
Related:
8d3578
https://pagure.io/SSSD/sssd/issue/4012
8d3578
8d3578
Reviewed-by: Sumit Bose <sbose@redhat.com>
8d3578
(cherry picked from commit ac72bb4ab1a8d3d13f0d459efe5f23cf010c2790)
8d3578
8d3578
Reviewed-by: Sumit Bose <sbose@redhat.com>
8d3578
---
8d3578
 src/providers/be_refresh.c        | 18 ++++++++++++++++++
8d3578
 src/providers/be_refresh.h        |  4 ++++
8d3578
 src/providers/ldap/sdap_refresh.c | 29 +++++------------------------
8d3578
 3 files changed, 27 insertions(+), 24 deletions(-)
8d3578
8d3578
diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
8d3578
index 8a6e1ba58..c49229e71 100644
8d3578
--- a/src/providers/be_refresh.c
8d3578
+++ b/src/providers/be_refresh.c
8d3578
@@ -362,3 +362,21 @@ errno_t be_refresh_recv(struct tevent_req *req)
8d3578
 
8d3578
     return EOK;
8d3578
 }
8d3578
+
8d3578
+struct dp_id_data *be_refresh_acct_req(TALLOC_CTX *mem_ctx,
8d3578
+                                       uint32_t entry_type,
8d3578
+                                       struct sss_domain_info *domain)
8d3578
+{
8d3578
+    struct dp_id_data *account_req;
8d3578
+
8d3578
+    account_req = talloc_zero(mem_ctx, struct dp_id_data);
8d3578
+    if (account_req == NULL) {
8d3578
+        return NULL;
8d3578
+    }
8d3578
+
8d3578
+    account_req->entry_type = entry_type;
8d3578
+    account_req->filter_type = BE_FILTER_NAME;
8d3578
+    account_req->extra_value = NULL;
8d3578
+    account_req->domain = domain->name;
8d3578
+    return account_req;
8d3578
+}
8d3578
diff --git a/src/providers/be_refresh.h b/src/providers/be_refresh.h
8d3578
index 980ac7d06..b7ba5d4c2 100644
8d3578
--- a/src/providers/be_refresh.h
8d3578
+++ b/src/providers/be_refresh.h
8d3578
@@ -69,4 +69,8 @@ struct tevent_req *be_refresh_send(TALLOC_CTX *mem_ctx,
8d3578
 
8d3578
 errno_t be_refresh_recv(struct tevent_req *req);
8d3578
 
8d3578
+struct dp_id_data *be_refresh_acct_req(TALLOC_CTX *mem_ctx,
8d3578
+                                       uint32_t entry_type,
8d3578
+                                       struct sss_domain_info *domain);
8d3578
+
8d3578
 #endif /* _DP_REFRESH_H_ */
8d3578
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
8d3578
index baa7fa59f..af39d8686 100644
8d3578
--- a/src/providers/ldap/sdap_refresh.c
8d3578
+++ b/src/providers/ldap/sdap_refresh.c
8d3578
@@ -30,7 +30,6 @@ struct sdap_refresh_state {
8d3578
     struct dp_id_data *account_req;
8d3578
     struct sdap_id_ctx *id_ctx;
8d3578
     struct sdap_domain *sdom;
8d3578
-    const char *type;
8d3578
     char **names;
8d3578
     size_t index;
8d3578
 };
8d3578
@@ -74,32 +73,12 @@ static struct tevent_req *sdap_refresh_send(TALLOC_CTX *mem_ctx,
8d3578
         goto immediately;
8d3578
     }
8d3578
 
8d3578
-    switch (entry_type) {
8d3578
-    case BE_REQ_USER:
8d3578
-        state->type = "user";
8d3578
-        break;
8d3578
-    case BE_REQ_GROUP:
8d3578
-        state->type = "group";
8d3578
-        break;
8d3578
-    case BE_REQ_NETGROUP:
8d3578
-        state->type = "netgroup";
8d3578
-        break;
8d3578
-    default:
8d3578
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid entry type [%d]!\n", entry_type);
8d3578
-    }
8d3578
-
8d3578
-    state->account_req = talloc_zero(state, struct dp_id_data);
8d3578
+    state->account_req = be_refresh_acct_req(state, entry_type, domain);
8d3578
     if (state->account_req == NULL) {
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
     }
8d3578
 
8d3578
-    state->account_req->entry_type = entry_type;
8d3578
-    state->account_req->filter_type = BE_FILTER_NAME;
8d3578
-    state->account_req->extra_value = NULL;
8d3578
-    state->account_req->domain = domain->name;
8d3578
-    /* filter will be filled later */
8d3578
-
8d3578
     ret = sdap_refresh_step(req);
8d3578
     if (ret == EOK) {
8d3578
         DEBUG(SSSDBG_TRACE_FUNC, "Nothing to refresh\n");
8d3578
@@ -143,7 +122,8 @@ static errno_t sdap_refresh_step(struct tevent_req *req)
8d3578
     }
8d3578
 
8d3578
     DEBUG(SSSDBG_TRACE_FUNC, "Issuing refresh of %s %s\n",
8d3578
-          state->type, state->account_req->filter_value);
8d3578
+          be_req2str(state->account_req->entry_type),
8d3578
+          state->account_req->filter_value);
8d3578
 
8d3578
     subreq = sdap_handle_acct_req_send(state, state->be_ctx,
8d3578
                                        state->account_req, state->id_ctx,
8d3578
@@ -178,7 +158,8 @@ static void sdap_refresh_done(struct tevent_req *subreq)
8d3578
     talloc_zfree(subreq);
8d3578
     if (ret != EOK) {
8d3578
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to refresh %s [dp_error: %d, "
8d3578
-              "sdap_ret: %d, errno: %d]: %s\n", state->type,
8d3578
+              "sdap_ret: %d, errno: %d]: %s\n",
8d3578
+               be_req2str(state->account_req->entry_type),
8d3578
               dp_error, sdap_ret, ret, err_msg);
8d3578
         goto done;
8d3578
     }
8d3578
-- 
8d3578
2.20.1
8d3578