Blame SOURCES/0098-ipa-use-LDAP-not-extdom-to-lookup-IPA-users-and-grou.patch

5cd47f
From fbd38903a3c4985e560e6c670ead84597982242e Mon Sep 17 00:00:00 2001
5cd47f
From: Sumit Bose <sbose@redhat.com>
5cd47f
Date: Wed, 19 Jun 2019 11:40:56 +0200
5cd47f
Subject: [PATCH] ipa: use LDAP not extdom to lookup IPA users and groups
5cd47f
MIME-Version: 1.0
5cd47f
Content-Type: text/plain; charset=UTF-8
5cd47f
Content-Transfer-Encoding: 8bit
5cd47f
5cd47f
Currently when an IPA client is resolving trusted users and groups with
5cd47f
the help of the extdom plugin it uses the extdom plugin as well to
5cd47f
lookup IPA objects. This might cause issues if e.g. there is a user in
5cd47f
IPA with the same name as a group in AD or the other way round.
5cd47f
5cd47f
To solve this and to lower the load on the extdom plugin on the IPA
5cd47f
server side this patch will lookup IPA object directly from LDAP on the
5cd47f
IPA server.
5cd47f
5cd47f
Related to https://pagure.io/SSSD/sssd/issue/4073
5cd47f
5cd47f
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
5cd47f
(cherry picked from commit 27b141f38dd04d4b69e609a4cc64676a0716226e)
5cd47f
---
5cd47f
 src/providers/ipa/ipa_id.c       | 11 +-----
5cd47f
 src/providers/ipa/ipa_id.h       |  5 +++
5cd47f
 src/providers/ipa/ipa_s2n_exop.c | 67 ++++++++++++++++++++++++++++++++
5cd47f
 3 files changed, 74 insertions(+), 9 deletions(-)
5cd47f
5cd47f
diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
5cd47f
index f34692aa2..94d5f9d90 100644
5cd47f
--- a/src/providers/ipa/ipa_id.c
5cd47f
+++ b/src/providers/ipa/ipa_id.c
5cd47f
@@ -30,13 +30,6 @@
5cd47f
 #include "providers/ldap/sdap_async.h"
5cd47f
 #include "providers/ipa/ipa_id.h"
5cd47f
 
5cd47f
-static struct tevent_req *
5cd47f
-ipa_id_get_account_info_send(TALLOC_CTX *memctx, struct tevent_context *ev,
5cd47f
-                             struct ipa_id_ctx *ipa_ctx,
5cd47f
-                             struct dp_id_data *ar);
5cd47f
-
5cd47f
-static int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error);
5cd47f
-
5cd47f
 static bool is_object_overridable(struct dp_id_data *ar)
5cd47f
 {
5cd47f
     bool ret = false;
5cd47f
@@ -516,7 +509,7 @@ static void ipa_id_get_account_info_orig_done(struct tevent_req *subreq);
5cd47f
 static void ipa_id_get_account_info_done(struct tevent_req *subreq);
5cd47f
 static void ipa_id_get_user_list_done(struct tevent_req *subreq);
5cd47f
 
5cd47f
-static struct tevent_req *
5cd47f
+struct tevent_req *
5cd47f
 ipa_id_get_account_info_send(TALLOC_CTX *memctx, struct tevent_context *ev,
5cd47f
                              struct ipa_id_ctx *ipa_ctx,
5cd47f
                              struct dp_id_data *ar)
5cd47f
@@ -1120,7 +1113,7 @@ fail:
5cd47f
     return;
5cd47f
 }
5cd47f
 
5cd47f
-static int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error)
5cd47f
+int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error)
5cd47f
 {
5cd47f
     struct ipa_id_get_account_info_state *state = tevent_req_data(req,
5cd47f
                                           struct ipa_id_get_account_info_state);
5cd47f
diff --git a/src/providers/ipa/ipa_id.h b/src/providers/ipa/ipa_id.h
5cd47f
index fe9acfeef..c18e709b8 100644
5cd47f
--- a/src/providers/ipa/ipa_id.h
5cd47f
+++ b/src/providers/ipa/ipa_id.h
5cd47f
@@ -151,4 +151,9 @@ ipa_resolve_user_list_send(TALLOC_CTX *memctx, struct tevent_context *ev,
5cd47f
                            struct ldb_message_element *users);
5cd47f
 int ipa_resolve_user_list_recv(struct tevent_req *req, int *dp_error);
5cd47f
 
5cd47f
+struct tevent_req *
5cd47f
+ipa_id_get_account_info_send(TALLOC_CTX *memctx, struct tevent_context *ev,
5cd47f
+                             struct ipa_id_ctx *ipa_ctx,
5cd47f
+                             struct dp_id_data *ar);
5cd47f
+int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error);
5cd47f
 #endif
5cd47f
diff --git a/src/providers/ipa/ipa_s2n_exop.c b/src/providers/ipa/ipa_s2n_exop.c
5cd47f
index a07f73200..598b1568e 100644
5cd47f
--- a/src/providers/ipa/ipa_s2n_exop.c
5cd47f
+++ b/src/providers/ipa/ipa_s2n_exop.c
5cd47f
@@ -1121,6 +1121,7 @@ struct ipa_s2n_get_list_state {
5cd47f
 static errno_t ipa_s2n_get_list_step(struct tevent_req *req);
5cd47f
 static void ipa_s2n_get_list_get_override_done(struct tevent_req *subreq);
5cd47f
 static void ipa_s2n_get_list_next(struct tevent_req *subreq);
5cd47f
+static void ipa_s2n_get_list_ipa_next(struct tevent_req *subreq);
5cd47f
 static errno_t ipa_s2n_get_list_save_step(struct tevent_req *req);
5cd47f
 
5cd47f
 static struct tevent_req *ipa_s2n_get_list_send(TALLOC_CTX *mem_ctx,
5cd47f
@@ -1195,6 +1196,7 @@ static errno_t ipa_s2n_get_list_step(struct tevent_req *req)
5cd47f
     uint32_t id;
5cd47f
     char *endptr;
5cd47f
     bool need_v1 = false;
5cd47f
+    struct dp_id_data *ar;
5cd47f
 
5cd47f
     parent_domain = get_domains_head(state->dom);
5cd47f
     switch (state->req_input.type) {
5cd47f
@@ -1222,6 +1224,35 @@ static errno_t ipa_s2n_get_list_step(struct tevent_req *req)
5cd47f
 
5cd47f
         state->req_input.inp.name = short_name;
5cd47f
 
5cd47f
+        if (strcmp(state->obj_domain->name,
5cd47f
+            state->ipa_ctx->sdap_id_ctx->be->domain->name) == 0) {
5cd47f
+            DEBUG(SSSDBG_TRACE_INTERNAL,
5cd47f
+                  "Looking up IPA object [%s] from LDAP.\n",
5cd47f
+                  state->list[state->list_idx]);
5cd47f
+            ret = get_dp_id_data_for_user_name(state,
5cd47f
+                                               state->list[state->list_idx],
5cd47f
+                                               state->obj_domain->name,
5cd47f
+                                               &ar);
5cd47f
+            if (ret != EOK) {
5cd47f
+                DEBUG(SSSDBG_OP_FAILURE,
5cd47f
+                      "Failed to create lookup date for IPA object [%s].\n",
5cd47f
+                      state->list[state->list_idx]);
5cd47f
+                return ret;
5cd47f
+            }
5cd47f
+            ar->entry_type = state->entry_type;
5cd47f
+
5cd47f
+            subreq = ipa_id_get_account_info_send(state, state->ev,
5cd47f
+                                                  state->ipa_ctx, ar);
5cd47f
+            if (subreq == NULL) {
5cd47f
+                DEBUG(SSSDBG_OP_FAILURE,
5cd47f
+                      "ipa_id_get_account_info_send failed.\n");
5cd47f
+                return ENOMEM;
5cd47f
+            }
5cd47f
+            tevent_req_set_callback(subreq, ipa_s2n_get_list_ipa_next, req);
5cd47f
+
5cd47f
+            return EOK;
5cd47f
+        }
5cd47f
+
5cd47f
         break;
5cd47f
     case REQ_INP_ID:
5cd47f
         errno = 0;
5cd47f
@@ -1363,6 +1394,42 @@ fail:
5cd47f
     return;
5cd47f
 }
5cd47f
 
5cd47f
+static void ipa_s2n_get_list_ipa_next(struct tevent_req *subreq)
5cd47f
+{
5cd47f
+    int ret;
5cd47f
+    int dp_error;
5cd47f
+    struct tevent_req *req = tevent_req_callback_data(subreq,
5cd47f
+                                                      struct tevent_req);
5cd47f
+    struct ipa_s2n_get_list_state *state = tevent_req_data(req,
5cd47f
+                                               struct ipa_s2n_get_list_state);
5cd47f
+
5cd47f
+    ret = ipa_id_get_account_info_recv(subreq, &dp_error);
5cd47f
+    talloc_zfree(subreq);
5cd47f
+    if (ret != EOK) {
5cd47f
+        DEBUG(SSSDBG_OP_FAILURE, "ipa_id_get_account_info failed: %d %d\n", ret,
5cd47f
+                                 dp_error);
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    state->list_idx++;
5cd47f
+    if (state->list[state->list_idx] == NULL) {
5cd47f
+        tevent_req_done(req);
5cd47f
+        return;
5cd47f
+    }
5cd47f
+
5cd47f
+    ret = ipa_s2n_get_list_step(req);
5cd47f
+    if (ret != EOK) {
5cd47f
+        DEBUG(SSSDBG_OP_FAILURE, "ipa_s2n_get_list_step failed.\n");
5cd47f
+        goto done;
5cd47f
+    }
5cd47f
+
5cd47f
+    return;
5cd47f
+
5cd47f
+done:
5cd47f
+    tevent_req_error(req,ret);
5cd47f
+    return;
5cd47f
+}
5cd47f
+
5cd47f
 static void ipa_s2n_get_list_get_override_done(struct tevent_req *subreq)
5cd47f
 {
5cd47f
     int ret;
5cd47f
-- 
5cd47f
2.20.1
5cd47f