Blame SOURCES/0083-ldap-add-base_dn-to-sdap_search_bases.patch

8d3578
From fb9a42d952924b5ff084a103d43b6192c4ff0c1f Mon Sep 17 00:00:00 2001
8d3578
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
8d3578
Date: Thu, 15 Aug 2019 13:51:59 +0200
8d3578
Subject: [PATCH 83/90] ldap: add base_dn to sdap_search_bases
8d3578
MIME-Version: 1.0
8d3578
Content-Type: text/plain; charset=UTF-8
8d3578
Content-Transfer-Encoding: 8bit
8d3578
8d3578
To implement cases where we need to search a specific dn but we need
8d3578
to filter the result with configured filters.
8d3578
8d3578
Resolves:
8d3578
https://pagure.io/SSSD/sssd/issue/2607
8d3578
8d3578
Reviewed-by: Tomáš Halman <thalman@redhat.com>
8d3578
---
8d3578
 src/providers/ad/ad_subdomains.c              |  5 ++--
8d3578
 src/providers/ipa/ipa_subdomains.c            |  6 ++---
8d3578
 src/providers/ipa/ipa_subdomains_ext_groups.c |  2 +-
8d3578
 src/providers/ipa/ipa_sudo_async.c            |  8 +++----
8d3578
 src/providers/ldap/sdap_async_sudo.c          |  2 +-
8d3578
 src/providers/ldap/sdap_ops.c                 | 24 ++++++++++++-------
8d3578
 src/providers/ldap/sdap_ops.h                 |  6 +++--
8d3578
 7 files changed, 31 insertions(+), 22 deletions(-)
8d3578
8d3578
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
8d3578
index 45a8fe0fc..f0b5d59d2 100644
8d3578
--- a/src/providers/ad/ad_subdomains.c
8d3578
+++ b/src/providers/ad/ad_subdomains.c
8d3578
@@ -1110,7 +1110,7 @@ static void ad_get_slave_domain_connect_done(struct tevent_req *subreq)
8d3578
                                     sdap_id_op_handle(state->sdap_op),
8d3578
                                     state->root_sdom->search_bases,
8d3578
                                     NULL, false, 0,
8d3578
-                                    SLAVE_DOMAIN_FILTER, attrs);
8d3578
+                                    SLAVE_DOMAIN_FILTER, attrs, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         tevent_req_error(req, ret);
8d3578
         return;
8d3578
@@ -1304,7 +1304,8 @@ ad_get_root_domain_send(TALLOC_CTX *mem_ctx,
8d3578
 
8d3578
     subreq = sdap_search_bases_return_first_send(state, ev, opts, sh,
8d3578
                                                  opts->sdom->search_bases,
8d3578
-                                                 NULL, false, 0, filter, attrs);
8d3578
+                                                 NULL, false, 0, filter, attrs,
8d3578
+                                                 NULL);
8d3578
     if (subreq == NULL) {
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
8d3578
index 3a17c851d..322420264 100644
8d3578
--- a/src/providers/ipa/ipa_subdomains.c
8d3578
+++ b/src/providers/ipa/ipa_subdomains.c
8d3578
@@ -1005,7 +1005,7 @@ ipa_subdomains_ranges_send(TALLOC_CTX *mem_ctx,
8d3578
 
8d3578
     subreq = sdap_search_bases_send(state, ev, sd_ctx->sdap_id_ctx->opts, sh,
8d3578
                                     sd_ctx->ranges_search_bases, NULL, false,
8d3578
-                                    0, RANGE_FILTER, attrs);
8d3578
+                                    0, RANGE_FILTER, attrs, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
@@ -1251,7 +1251,7 @@ ipa_subdomains_master_send(TALLOC_CTX *mem_ctx,
8d3578
     subreq = sdap_search_bases_return_first_send(state, ev,
8d3578
                                      sd_ctx->sdap_id_ctx->opts, sh,
8d3578
                                      sd_ctx->master_search_bases, NULL, false,
8d3578
-                                     0, MASTER_DOMAIN_FILTER, attrs);
8d3578
+                                     0, MASTER_DOMAIN_FILTER, attrs, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
@@ -1397,7 +1397,7 @@ ipa_subdomains_slave_send(TALLOC_CTX *mem_ctx,
8d3578
 
8d3578
     subreq = sdap_search_bases_send(state, ev, sd_ctx->sdap_id_ctx->opts, sh,
8d3578
                                     sd_ctx->search_bases, NULL, false,
8d3578
-                                    0, SUBDOMAINS_FILTER, attrs);
8d3578
+                                    0, SUBDOMAINS_FILTER, attrs, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
diff --git a/src/providers/ipa/ipa_subdomains_ext_groups.c b/src/providers/ipa/ipa_subdomains_ext_groups.c
8d3578
index 75963bef1..cd80048b3 100644
8d3578
--- a/src/providers/ipa/ipa_subdomains_ext_groups.c
8d3578
+++ b/src/providers/ipa/ipa_subdomains_ext_groups.c
8d3578
@@ -545,7 +545,7 @@ static void ipa_get_ad_memberships_connect_done(struct tevent_req *subreq)
8d3578
                             dp_opt_get_int(state->sdap_id_ctx->opts->basic,
8d3578
                                             SDAP_ENUM_SEARCH_TIMEOUT),
8d3578
                             IPA_EXT_GROUPS_FILTER,
8d3578
-                            NULL);
8d3578
+                            NULL, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         DEBUG(SSSDBG_OP_FAILURE, "sdap_get_generic_send failed.\n");
8d3578
         ret = ENOMEM;
8d3578
diff --git a/src/providers/ipa/ipa_sudo_async.c b/src/providers/ipa/ipa_sudo_async.c
8d3578
index 060687c77..19bcd94c9 100644
8d3578
--- a/src/providers/ipa/ipa_sudo_async.c
8d3578
+++ b/src/providers/ipa/ipa_sudo_async.c
8d3578
@@ -492,7 +492,7 @@ ipa_sudo_fetch_addtl_cmdgroups(struct tevent_req *req)
8d3578
 
8d3578
     subreq = sdap_search_bases_send(state, state->ev, state->sdap_opts,
8d3578
                                     state->sh, state->sudo_sb, map, true, 0,
8d3578
-                                    filter, NULL);
8d3578
+                                    filter, NULL, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         return ENOMEM;
8d3578
     }
8d3578
@@ -582,7 +582,7 @@ ipa_sudo_fetch_rules(struct tevent_req *req)
8d3578
 
8d3578
     subreq = sdap_search_bases_send(state, state->ev, state->sdap_opts,
8d3578
                                     state->sh, state->sudo_sb, map, true, 0,
8d3578
-                                    filter, NULL);
8d3578
+                                    filter, NULL, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         return ENOMEM;
8d3578
     }
8d3578
@@ -662,7 +662,7 @@ ipa_sudo_fetch_cmdgroups(struct tevent_req *req)
8d3578
     subreq = sdap_search_bases_send(state, state->ev, state->sdap_opts,
8d3578
                                     state->sh, state->sudo_sb,
8d3578
                                     state->map_cmdgroup, true, 0,
8d3578
-                                    filter, NULL);
8d3578
+                                    filter, NULL, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         return ENOMEM;
8d3578
     }
8d3578
@@ -742,7 +742,7 @@ ipa_sudo_fetch_cmds(struct tevent_req *req)
8d3578
     subreq = sdap_search_bases_send(state, state->ev, state->sdap_opts,
8d3578
                                     state->sh, state->sudo_sb,
8d3578
                                     state->map_cmd, true, 0,
8d3578
-                                    filter, NULL);
8d3578
+                                    filter, NULL, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         return ENOMEM;
8d3578
     }
8d3578
diff --git a/src/providers/ldap/sdap_async_sudo.c b/src/providers/ldap/sdap_async_sudo.c
8d3578
index 5ccfad61f..c19ee87c2 100644
8d3578
--- a/src/providers/ldap/sdap_async_sudo.c
8d3578
+++ b/src/providers/ldap/sdap_async_sudo.c
8d3578
@@ -75,7 +75,7 @@ sdap_sudo_load_sudoers_send(TALLOC_CTX *mem_ctx,
8d3578
 
8d3578
     subreq = sdap_search_bases_send(state, ev, opts, sh, sb,
8d3578
                                     opts->sudorule_map, true, 0,
8d3578
-                                    ldap_filter, NULL);
8d3578
+                                    ldap_filter, NULL, NULL);
8d3578
     if (subreq == NULL) {
8d3578
         ret = ENOMEM;
8d3578
         goto immediately;
8d3578
diff --git a/src/providers/ldap/sdap_ops.c b/src/providers/ldap/sdap_ops.c
8d3578
index a90857469..2125b21aa 100644
8d3578
--- a/src/providers/ldap/sdap_ops.c
8d3578
+++ b/src/providers/ldap/sdap_ops.c
8d3578
@@ -37,6 +37,7 @@ struct sdap_search_bases_ex_state {
8d3578
     int timeout;
8d3578
     bool allow_paging;
8d3578
     bool return_first_reply;
8d3578
+    const char *base_dn;
8d3578
 
8d3578
     size_t base_iter;
8d3578
     struct sdap_search_base *cur_base;
8d3578
@@ -60,7 +61,8 @@ sdap_search_bases_ex_send(TALLOC_CTX *mem_ctx,
8d3578
                           bool return_first_reply,
8d3578
                           int timeout,
8d3578
                           const char *filter,
8d3578
-                          const char **attrs)
8d3578
+                          const char **attrs,
8d3578
+                          const char *base_dn)
8d3578
 {
8d3578
     struct tevent_req *req;
8d3578
     struct sdap_search_bases_ex_state *state;
8d3578
@@ -86,6 +88,7 @@ sdap_search_bases_ex_send(TALLOC_CTX *mem_ctx,
8d3578
     state->attrs = attrs;
8d3578
     state->allow_paging = allow_paging;
8d3578
     state->return_first_reply = return_first_reply;
8d3578
+    state->base_dn = base_dn;
8d3578
 
8d3578
     state->timeout = timeout == 0
8d3578
                      ? dp_opt_get_int(opts->basic, SDAP_SEARCH_TIMEOUT)
8d3578
@@ -133,6 +136,7 @@ static errno_t sdap_search_bases_ex_next_base(struct tevent_req *req)
8d3578
 {
8d3578
     struct sdap_search_bases_ex_state *state;
8d3578
     struct tevent_req *subreq;
8d3578
+    const char *base_dn;
8d3578
     char *filter;
8d3578
 
8d3578
     state = tevent_req_data(req, struct sdap_search_bases_ex_state);
8d3578
@@ -148,12 +152,12 @@ static errno_t sdap_search_bases_ex_next_base(struct tevent_req *req)
8d3578
         return ENOMEM;
8d3578
     }
8d3578
 
8d3578
-    DEBUG(SSSDBG_TRACE_FUNC, "Issuing LDAP lookup with base [%s]\n",
8d3578
-                             state->cur_base->basedn);
8d3578
+    base_dn = state->base_dn != NULL ? state->base_dn : state->cur_base->basedn;
8d3578
+
8d3578
+    DEBUG(SSSDBG_TRACE_FUNC, "Issuing LDAP lookup with base [%s]\n", base_dn);
8d3578
 
8d3578
     subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh,
8d3578
-                                   state->cur_base->basedn,
8d3578
-                                   state->cur_base->scope, filter,
8d3578
+                                   base_dn, state->cur_base->scope, filter,
8d3578
                                    state->attrs, state->map,
8d3578
                                    state->map_num_attrs, state->timeout,
8d3578
                                    state->allow_paging);
8d3578
@@ -253,11 +257,12 @@ sdap_search_bases_send(TALLOC_CTX *mem_ctx,
8d3578
                        bool allow_paging,
8d3578
                        int timeout,
8d3578
                        const char *filter,
8d3578
-                       const char **attrs)
8d3578
+                       const char **attrs,
8d3578
+                       const char *base_dn)
8d3578
 {
8d3578
     return sdap_search_bases_ex_send(mem_ctx, ev, opts, sh, bases, map,
8d3578
                                      allow_paging, false, timeout,
8d3578
-                                     filter, attrs);
8d3578
+                                     filter, attrs, base_dn);
8d3578
 }
8d3578
 
8d3578
 int sdap_search_bases_recv(struct tevent_req *req,
8d3578
@@ -278,11 +283,12 @@ sdap_search_bases_return_first_send(TALLOC_CTX *mem_ctx,
8d3578
                                     bool allow_paging,
8d3578
                                     int timeout,
8d3578
                                     const char *filter,
8d3578
-                                    const char **attrs)
8d3578
+                                    const char **attrs,
8d3578
+                                    const char *base_dn)
8d3578
 {
8d3578
     return sdap_search_bases_ex_send(mem_ctx, ev, opts, sh, bases, map,
8d3578
                                      allow_paging, true, timeout,
8d3578
-                                     filter, attrs);
8d3578
+                                     filter, attrs, base_dn);
8d3578
 }
8d3578
 
8d3578
 int sdap_search_bases_return_first_recv(struct tevent_req *req,
8d3578
diff --git a/src/providers/ldap/sdap_ops.h b/src/providers/ldap/sdap_ops.h
8d3578
index cc9de00d2..648a2b68c 100644
8d3578
--- a/src/providers/ldap/sdap_ops.h
8d3578
+++ b/src/providers/ldap/sdap_ops.h
8d3578
@@ -34,7 +34,8 @@ struct tevent_req *sdap_search_bases_send(TALLOC_CTX *mem_ctx,
8d3578
                                           bool allow_paging,
8d3578
                                           int timeout,
8d3578
                                           const char *filter,
8d3578
-                                          const char **attrs);
8d3578
+                                          const char **attrs,
8d3578
+                                          const char *base_dn);
8d3578
 
8d3578
 int sdap_search_bases_recv(struct tevent_req *req,
8d3578
                            TALLOC_CTX *mem_ctx,
8d3578
@@ -51,7 +52,8 @@ sdap_search_bases_return_first_send(TALLOC_CTX *mem_ctx,
8d3578
                                     bool allow_paging,
8d3578
                                     int timeout,
8d3578
                                     const char *filter,
8d3578
-                                    const char **attrs);
8d3578
+                                    const char **attrs,
8d3578
+                                    const char *base_dn);
8d3578
 
8d3578
 int sdap_search_bases_return_first_recv(struct tevent_req *req,
8d3578
                                         TALLOC_CTX *mem_ctx,
8d3578
-- 
8d3578
2.20.1
8d3578