|
|
1ad1a2 |
From 2b84dddf8c3d3b30bb1919205b4eb53e1ba31714 Mon Sep 17 00:00:00 2001
|
|
|
1ad1a2 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
1ad1a2 |
Date: Tue, 15 Mar 2022 11:36:45 +0100
|
|
|
1ad1a2 |
Subject: [PATCH] ad: use right sdap_domain in ad_domain_info_send
|
|
|
1ad1a2 |
MIME-Version: 1.0
|
|
|
1ad1a2 |
Content-Type: text/plain; charset=UTF-8
|
|
|
1ad1a2 |
Content-Transfer-Encoding: 8bit
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
Originally ad_domain_info_send() was only called when there was only a
|
|
|
1ad1a2 |
single domain available and hence only a single sdap_domain struct with
|
|
|
1ad1a2 |
the search bases in the sdap_domain list. Since ad_domain_info_send() is
|
|
|
1ad1a2 |
now called at other times as well the right sdap_domain struct must be
|
|
|
1ad1a2 |
selected so that the right search bases are used.
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
Resolves: https://github.com/SSSD/sssd/issues/6063
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
|
|
|
1ad1a2 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
1ad1a2 |
(cherry picked from commit 51e92297157562511baf8902777f02a4aa2e70e6)
|
|
|
1ad1a2 |
---
|
|
|
1ad1a2 |
src/providers/ad/ad_domain_info.c | 10 +++++-
|
|
|
1ad1a2 |
src/providers/ldap/ldap_common.h | 3 ++
|
|
|
1ad1a2 |
src/providers/ldap/sdap_domain.c | 21 ++++++++++++
|
|
|
1ad1a2 |
src/tests/cmocka/test_search_bases.c | 48 +++++++++++++++++++++++++++-
|
|
|
1ad1a2 |
4 files changed, 80 insertions(+), 2 deletions(-)
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
diff --git a/src/providers/ad/ad_domain_info.c b/src/providers/ad/ad_domain_info.c
|
|
|
1ad1a2 |
index 52b2e2442..f3a82a198 100644
|
|
|
1ad1a2 |
--- a/src/providers/ad/ad_domain_info.c
|
|
|
1ad1a2 |
+++ b/src/providers/ad/ad_domain_info.c
|
|
|
1ad1a2 |
@@ -181,6 +181,7 @@ struct ad_domain_info_state {
|
|
|
1ad1a2 |
struct sdap_id_op *id_op;
|
|
|
1ad1a2 |
struct sdap_id_ctx *id_ctx;
|
|
|
1ad1a2 |
struct sdap_options *opts;
|
|
|
1ad1a2 |
+ struct sdap_domain *sdom;
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
const char *dom_name;
|
|
|
1ad1a2 |
int base_iter;
|
|
|
1ad1a2 |
@@ -215,6 +216,13 @@ ad_domain_info_send(TALLOC_CTX *mem_ctx,
|
|
|
1ad1a2 |
state->id_ctx = conn->id_ctx;
|
|
|
1ad1a2 |
state->opts = conn->id_ctx->opts;
|
|
|
1ad1a2 |
state->dom_name = dom_name;
|
|
|
1ad1a2 |
+ state->sdom = sdap_domain_get_by_name(state->opts, state->dom_name);
|
|
|
1ad1a2 |
+ if (state->sdom == NULL || state->sdom->search_bases == NULL) {
|
|
|
1ad1a2 |
+ DEBUG(SSSDBG_OP_FAILURE, "Missing internal domain data.\n");
|
|
|
1ad1a2 |
+ ret = EINVAL;
|
|
|
1ad1a2 |
+ goto immediate;
|
|
|
1ad1a2 |
+ }
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
ret = ad_domain_info_next(req);
|
|
|
1ad1a2 |
if (ret != EOK && ret != EAGAIN) {
|
|
|
1ad1a2 |
@@ -243,7 +251,7 @@ ad_domain_info_next(struct tevent_req *req)
|
|
|
1ad1a2 |
struct ad_domain_info_state *state =
|
|
|
1ad1a2 |
tevent_req_data(req, struct ad_domain_info_state);
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
- base = state->opts->sdom->search_bases[state->base_iter];
|
|
|
1ad1a2 |
+ base = state->sdom->search_bases[state->base_iter];
|
|
|
1ad1a2 |
if (base == NULL) {
|
|
|
1ad1a2 |
return EOK;
|
|
|
1ad1a2 |
}
|
|
|
1ad1a2 |
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
|
|
|
1ad1a2 |
index 19a696a3d..1a122ea03 100644
|
|
|
1ad1a2 |
--- a/src/providers/ldap/ldap_common.h
|
|
|
1ad1a2 |
+++ b/src/providers/ldap/ldap_common.h
|
|
|
1ad1a2 |
@@ -352,6 +352,9 @@ sdap_domain_remove(struct sdap_options *opts,
|
|
|
1ad1a2 |
struct sdap_domain *sdap_domain_get(struct sdap_options *opts,
|
|
|
1ad1a2 |
struct sss_domain_info *dom);
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
+struct sdap_domain *sdap_domain_get_by_name(struct sdap_options *opts,
|
|
|
1ad1a2 |
+ const char *dom_name);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
struct sdap_domain *sdap_domain_get_by_dn(struct sdap_options *opts,
|
|
|
1ad1a2 |
const char *dn);
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
diff --git a/src/providers/ldap/sdap_domain.c b/src/providers/ldap/sdap_domain.c
|
|
|
1ad1a2 |
index fa6e9340d..1785dd20d 100644
|
|
|
1ad1a2 |
--- a/src/providers/ldap/sdap_domain.c
|
|
|
1ad1a2 |
+++ b/src/providers/ldap/sdap_domain.c
|
|
|
1ad1a2 |
@@ -44,6 +44,27 @@ sdap_domain_get(struct sdap_options *opts,
|
|
|
1ad1a2 |
return sditer;
|
|
|
1ad1a2 |
}
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
+struct sdap_domain *
|
|
|
1ad1a2 |
+sdap_domain_get_by_name(struct sdap_options *opts,
|
|
|
1ad1a2 |
+ const char *dom_name)
|
|
|
1ad1a2 |
+{
|
|
|
1ad1a2 |
+ struct sdap_domain *sditer = NULL;
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ if (dom_name == NULL) {
|
|
|
1ad1a2 |
+ DEBUG(SSSDBG_OP_FAILURE, "Missing domain name.\n");
|
|
|
1ad1a2 |
+ return NULL;
|
|
|
1ad1a2 |
+ }
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ DLIST_FOR_EACH(sditer, opts->sdom) {
|
|
|
1ad1a2 |
+ if (sditer->dom->name != NULL
|
|
|
1ad1a2 |
+ && strcasecmp(sditer->dom->name, dom_name) == 0) {
|
|
|
1ad1a2 |
+ break;
|
|
|
1ad1a2 |
+ }
|
|
|
1ad1a2 |
+ }
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ return sditer;
|
|
|
1ad1a2 |
+}
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
struct sdap_domain *
|
|
|
1ad1a2 |
sdap_domain_get_by_dn(struct sdap_options *opts,
|
|
|
1ad1a2 |
const char *dn)
|
|
|
1ad1a2 |
diff --git a/src/tests/cmocka/test_search_bases.c b/src/tests/cmocka/test_search_bases.c
|
|
|
1ad1a2 |
index 4538eaceb..0d06786ca 100644
|
|
|
1ad1a2 |
--- a/src/tests/cmocka/test_search_bases.c
|
|
|
1ad1a2 |
+++ b/src/tests/cmocka/test_search_bases.c
|
|
|
1ad1a2 |
@@ -177,6 +177,51 @@ void test_get_by_dn_fail(void **state)
|
|
|
1ad1a2 |
do_test_get_by_dn(dn, dns, 1, dns2, 1, DN_NOT_IN_DOMS);
|
|
|
1ad1a2 |
}
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
+void test_sdap_domain_get_by_name(void **state)
|
|
|
1ad1a2 |
+{
|
|
|
1ad1a2 |
+ struct sdap_options *opts;
|
|
|
1ad1a2 |
+ struct sss_domain_info dom1 = { 0 };
|
|
|
1ad1a2 |
+ dom1.name = discard_const("dom1");
|
|
|
1ad1a2 |
+ struct sss_domain_info dom2 = { 0 };
|
|
|
1ad1a2 |
+ dom2.name = discard_const("dom2");
|
|
|
1ad1a2 |
+ struct sss_domain_info dom3 = { 0 };
|
|
|
1ad1a2 |
+ dom3.name = discard_const("dom3");
|
|
|
1ad1a2 |
+ int ret;
|
|
|
1ad1a2 |
+ struct sdap_domain *sdom;
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ opts = talloc_zero(NULL, struct sdap_options);
|
|
|
1ad1a2 |
+ assert_non_null(opts);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ ret = sdap_domain_add(opts, &dom1, NULL);
|
|
|
1ad1a2 |
+ assert_int_equal(ret, EOK);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ ret = sdap_domain_add(opts, &dom2, NULL);
|
|
|
1ad1a2 |
+ assert_int_equal(ret, EOK);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ ret = sdap_domain_add(opts, &dom3, NULL);
|
|
|
1ad1a2 |
+ assert_int_equal(ret, EOK);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ sdom = sdap_domain_get_by_name(opts, NULL);
|
|
|
1ad1a2 |
+ assert_null(sdom);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ sdom = sdap_domain_get_by_name(opts, "abc");
|
|
|
1ad1a2 |
+ assert_null(sdom);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ sdom = sdap_domain_get_by_name(opts, "dom1");
|
|
|
1ad1a2 |
+ assert_non_null(sdom);
|
|
|
1ad1a2 |
+ assert_ptr_equal(sdom->dom, &dom1);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ sdom = sdap_domain_get_by_name(opts, "dom2");
|
|
|
1ad1a2 |
+ assert_non_null(sdom);
|
|
|
1ad1a2 |
+ assert_ptr_equal(sdom->dom, &dom2);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ sdom = sdap_domain_get_by_name(opts, "dom3");
|
|
|
1ad1a2 |
+ assert_non_null(sdom);
|
|
|
1ad1a2 |
+ assert_ptr_equal(sdom->dom, &dom3);
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
+ talloc_free(opts);
|
|
|
1ad1a2 |
+}
|
|
|
1ad1a2 |
+
|
|
|
1ad1a2 |
int main(void)
|
|
|
1ad1a2 |
{
|
|
|
1ad1a2 |
const struct CMUnitTest tests[] = {
|
|
|
1ad1a2 |
@@ -184,7 +229,8 @@ int main(void)
|
|
|
1ad1a2 |
cmocka_unit_test(test_search_bases_success),
|
|
|
1ad1a2 |
cmocka_unit_test(test_get_by_dn_fail),
|
|
|
1ad1a2 |
cmocka_unit_test(test_get_by_dn),
|
|
|
1ad1a2 |
- cmocka_unit_test(test_get_by_dn2)
|
|
|
1ad1a2 |
+ cmocka_unit_test(test_get_by_dn2),
|
|
|
1ad1a2 |
+ cmocka_unit_test(test_sdap_domain_get_by_name)
|
|
|
1ad1a2 |
};
|
|
|
1ad1a2 |
|
|
|
1ad1a2 |
return cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
1ad1a2 |
--
|
|
|
1ad1a2 |
2.35.3
|
|
|
1ad1a2 |
|