dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone
Blob Blame History Raw
From 080b154402ad076a562e0ea6d6e8c5d2fbcef5f5 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Wed, 8 May 2019 14:38:44 +0200
Subject: [PATCH 52/64] BE/LDAP: Split out a helper function from sdap_refresh
 for later reuse

Every refresh request will send a similar account_req. Let's split out
the function that creates the account_req into a reusable one.

Also removes the type string as it was only used in DEBUG messages and
there is already a function in the back end API that provides the same
functionality.

Related:
https://pagure.io/SSSD/sssd/issue/4012

Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit ac72bb4ab1a8d3d13f0d459efe5f23cf010c2790)

Reviewed-by: Sumit Bose <sbose@redhat.com>
---
 src/providers/be_refresh.c        | 18 ++++++++++++++++++
 src/providers/be_refresh.h        |  4 ++++
 src/providers/ldap/sdap_refresh.c | 29 +++++------------------------
 3 files changed, 27 insertions(+), 24 deletions(-)

diff --git a/src/providers/be_refresh.c b/src/providers/be_refresh.c
index 8a6e1ba58..c49229e71 100644
--- a/src/providers/be_refresh.c
+++ b/src/providers/be_refresh.c
@@ -362,3 +362,21 @@ errno_t be_refresh_recv(struct tevent_req *req)
 
     return EOK;
 }
+
+struct dp_id_data *be_refresh_acct_req(TALLOC_CTX *mem_ctx,
+                                       uint32_t entry_type,
+                                       struct sss_domain_info *domain)
+{
+    struct dp_id_data *account_req;
+
+    account_req = talloc_zero(mem_ctx, struct dp_id_data);
+    if (account_req == NULL) {
+        return NULL;
+    }
+
+    account_req->entry_type = entry_type;
+    account_req->filter_type = BE_FILTER_NAME;
+    account_req->extra_value = NULL;
+    account_req->domain = domain->name;
+    return account_req;
+}
diff --git a/src/providers/be_refresh.h b/src/providers/be_refresh.h
index 980ac7d06..b7ba5d4c2 100644
--- a/src/providers/be_refresh.h
+++ b/src/providers/be_refresh.h
@@ -69,4 +69,8 @@ struct tevent_req *be_refresh_send(TALLOC_CTX *mem_ctx,
 
 errno_t be_refresh_recv(struct tevent_req *req);
 
+struct dp_id_data *be_refresh_acct_req(TALLOC_CTX *mem_ctx,
+                                       uint32_t entry_type,
+                                       struct sss_domain_info *domain);
+
 #endif /* _DP_REFRESH_H_ */
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index baa7fa59f..af39d8686 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -30,7 +30,6 @@ struct sdap_refresh_state {
     struct dp_id_data *account_req;
     struct sdap_id_ctx *id_ctx;
     struct sdap_domain *sdom;
-    const char *type;
     char **names;
     size_t index;
 };
@@ -74,32 +73,12 @@ static struct tevent_req *sdap_refresh_send(TALLOC_CTX *mem_ctx,
         goto immediately;
     }
 
-    switch (entry_type) {
-    case BE_REQ_USER:
-        state->type = "user";
-        break;
-    case BE_REQ_GROUP:
-        state->type = "group";
-        break;
-    case BE_REQ_NETGROUP:
-        state->type = "netgroup";
-        break;
-    default:
-        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid entry type [%d]!\n", entry_type);
-    }
-
-    state->account_req = talloc_zero(state, struct dp_id_data);
+    state->account_req = be_refresh_acct_req(state, entry_type, domain);
     if (state->account_req == NULL) {
         ret = ENOMEM;
         goto immediately;
     }
 
-    state->account_req->entry_type = entry_type;
-    state->account_req->filter_type = BE_FILTER_NAME;
-    state->account_req->extra_value = NULL;
-    state->account_req->domain = domain->name;
-    /* filter will be filled later */
-
     ret = sdap_refresh_step(req);
     if (ret == EOK) {
         DEBUG(SSSDBG_TRACE_FUNC, "Nothing to refresh\n");
@@ -143,7 +122,8 @@ static errno_t sdap_refresh_step(struct tevent_req *req)
     }
 
     DEBUG(SSSDBG_TRACE_FUNC, "Issuing refresh of %s %s\n",
-          state->type, state->account_req->filter_value);
+          be_req2str(state->account_req->entry_type),
+          state->account_req->filter_value);
 
     subreq = sdap_handle_acct_req_send(state, state->be_ctx,
                                        state->account_req, state->id_ctx,
@@ -178,7 +158,8 @@ static void sdap_refresh_done(struct tevent_req *subreq)
     talloc_zfree(subreq);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, "Unable to refresh %s [dp_error: %d, "
-              "sdap_ret: %d, errno: %d]: %s\n", state->type,
+              "sdap_ret: %d, errno: %d]: %s\n",
+               be_req2str(state->account_req->entry_type),
               dp_error, sdap_ret, ret, err_msg);
         goto done;
     }
-- 
2.20.1