Skip to content

Commit

Permalink
ad: use right sdap_domain in ad_domain_info_send
Browse files Browse the repository at this point in the history
Originally ad_domain_info_send() was only called when there was only a
single domain available and hence only a single sdap_domain struct with
the search bases in the sdap_domain list. Since ad_domain_info_send() is
now called at other times as well the right sdap_domain struct must be
selected so that the right search bases are used.

Resolves: #6063

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit 51e9229)
  • Loading branch information
sumit-bose authored and pbrezina committed Mar 25, 2022
1 parent 64192cf commit 2b84ddd
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/providers/ad/ad_domain_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct ad_domain_info_state {
struct sdap_id_op *id_op;
struct sdap_id_ctx *id_ctx;
struct sdap_options *opts;
struct sdap_domain *sdom;

const char *dom_name;
int base_iter;
Expand Down Expand Up @@ -215,6 +216,13 @@ ad_domain_info_send(TALLOC_CTX *mem_ctx,
state->id_ctx = conn->id_ctx;
state->opts = conn->id_ctx->opts;
state->dom_name = dom_name;
state->sdom = sdap_domain_get_by_name(state->opts, state->dom_name);
if (state->sdom == NULL || state->sdom->search_bases == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "Missing internal domain data.\n");
ret = EINVAL;
goto immediate;
}


ret = ad_domain_info_next(req);
if (ret != EOK && ret != EAGAIN) {
Expand Down Expand Up @@ -243,7 +251,7 @@ ad_domain_info_next(struct tevent_req *req)
struct ad_domain_info_state *state =
tevent_req_data(req, struct ad_domain_info_state);

base = state->opts->sdom->search_bases[state->base_iter];
base = state->sdom->search_bases[state->base_iter];
if (base == NULL) {
return EOK;
}
Expand Down
3 changes: 3 additions & 0 deletions src/providers/ldap/ldap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ sdap_domain_remove(struct sdap_options *opts,
struct sdap_domain *sdap_domain_get(struct sdap_options *opts,
struct sss_domain_info *dom);

struct sdap_domain *sdap_domain_get_by_name(struct sdap_options *opts,
const char *dom_name);

struct sdap_domain *sdap_domain_get_by_dn(struct sdap_options *opts,
const char *dn);

Expand Down
21 changes: 21 additions & 0 deletions src/providers/ldap/sdap_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ sdap_domain_get(struct sdap_options *opts,
return sditer;
}

struct sdap_domain *
sdap_domain_get_by_name(struct sdap_options *opts,
const char *dom_name)
{
struct sdap_domain *sditer = NULL;

if (dom_name == NULL) {
DEBUG(SSSDBG_OP_FAILURE, "Missing domain name.\n");
return NULL;
}

DLIST_FOR_EACH(sditer, opts->sdom) {
if (sditer->dom->name != NULL
&& strcasecmp(sditer->dom->name, dom_name) == 0) {
break;
}
}

return sditer;
}

struct sdap_domain *
sdap_domain_get_by_dn(struct sdap_options *opts,
const char *dn)
Expand Down
48 changes: 47 additions & 1 deletion src/tests/cmocka/test_search_bases.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,60 @@ void test_get_by_dn_fail(void **state)
do_test_get_by_dn(dn, dns, 1, dns2, 1, DN_NOT_IN_DOMS);
}

void test_sdap_domain_get_by_name(void **state)
{
struct sdap_options *opts;
struct sss_domain_info dom1 = { 0 };
dom1.name = discard_const("dom1");
struct sss_domain_info dom2 = { 0 };
dom2.name = discard_const("dom2");
struct sss_domain_info dom3 = { 0 };
dom3.name = discard_const("dom3");
int ret;
struct sdap_domain *sdom;

opts = talloc_zero(NULL, struct sdap_options);
assert_non_null(opts);

ret = sdap_domain_add(opts, &dom1, NULL);
assert_int_equal(ret, EOK);

ret = sdap_domain_add(opts, &dom2, NULL);
assert_int_equal(ret, EOK);

ret = sdap_domain_add(opts, &dom3, NULL);
assert_int_equal(ret, EOK);

sdom = sdap_domain_get_by_name(opts, NULL);
assert_null(sdom);

sdom = sdap_domain_get_by_name(opts, "abc");
assert_null(sdom);

sdom = sdap_domain_get_by_name(opts, "dom1");
assert_non_null(sdom);
assert_ptr_equal(sdom->dom, &dom1);

sdom = sdap_domain_get_by_name(opts, "dom2");
assert_non_null(sdom);
assert_ptr_equal(sdom->dom, &dom2);

sdom = sdap_domain_get_by_name(opts, "dom3");
assert_non_null(sdom);
assert_ptr_equal(sdom->dom, &dom3);

talloc_free(opts);
}

int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_search_bases_fail),
cmocka_unit_test(test_search_bases_success),
cmocka_unit_test(test_get_by_dn_fail),
cmocka_unit_test(test_get_by_dn),
cmocka_unit_test(test_get_by_dn2)
cmocka_unit_test(test_get_by_dn2),
cmocka_unit_test(test_sdap_domain_get_by_name)
};

return cmocka_run_group_tests(tests, NULL, NULL);
Expand Down

0 comments on commit 2b84ddd

Please sign in to comment.