|
|
5cd47f |
From 2ea937af47c529ca827bcdd307a47e2b96690d38 Mon Sep 17 00:00:00 2001
|
|
|
5cd47f |
From: Sumit Bose <sbose@redhat.com>
|
|
|
5cd47f |
Date: Thu, 12 Sep 2019 14:49:30 +0200
|
|
|
5cd47f |
Subject: [PATCH 93/97] utils: extend some find_domain_* calls to search
|
|
|
5cd47f |
disabled domain
|
|
|
5cd47f |
MIME-Version: 1.0
|
|
|
5cd47f |
Content-Type: text/plain; charset=UTF-8
|
|
|
5cd47f |
Content-Transfer-Encoding: 8bit
|
|
|
5cd47f |
|
|
|
5cd47f |
This extension is needed to support disabled domains since it is
|
|
|
5cd47f |
now important to know if a domain is really unknown or only disabled.
|
|
|
5cd47f |
While an unknown domain might typically lead to an error, a caller might
|
|
|
5cd47f |
just ignore requests for disabled domains or objects from disabled
|
|
|
5cd47f |
domains.
|
|
|
5cd47f |
|
|
|
5cd47f |
Related to https://pagure.io/SSSD/sssd/issue/4078
|
|
|
5cd47f |
|
|
|
5cd47f |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
5cd47f |
---
|
|
|
5cd47f |
src/providers/ipa/ipa_id.c | 3 +-
|
|
|
5cd47f |
src/responder/sudo/sudosrv_get_sudorules.c | 3 +-
|
|
|
5cd47f |
src/tests/cmocka/test_utils.c | 90 ++++++++++++++++++++++
|
|
|
5cd47f |
src/util/domain_info_utils.c | 31 +++++---
|
|
|
5cd47f |
src/util/util.h | 7 +-
|
|
|
5cd47f |
5 files changed, 122 insertions(+), 12 deletions(-)
|
|
|
5cd47f |
|
|
|
5cd47f |
diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
|
|
|
5cd47f |
index 9abee34cb..f34692aa2 100644
|
|
|
5cd47f |
--- a/src/providers/ipa/ipa_id.c
|
|
|
5cd47f |
+++ b/src/providers/ipa/ipa_id.c
|
|
|
5cd47f |
@@ -138,7 +138,8 @@ static errno_t ipa_resolve_user_list_get_user_step(struct tevent_req *req)
|
|
|
5cd47f |
|
|
|
5cd47f |
state->user_domain = find_domain_by_object_name_ex(
|
|
|
5cd47f |
state->ipa_ctx->sdap_id_ctx->be->domain,
|
|
|
5cd47f |
- ar->filter_value, true);
|
|
|
5cd47f |
+ ar->filter_value, true,
|
|
|
5cd47f |
+ SSS_GND_DESCEND);
|
|
|
5cd47f |
/* Use provided domain as fallback because no known domain was found in the
|
|
|
5cd47f |
* user name. */
|
|
|
5cd47f |
if (state->user_domain == NULL) {
|
|
|
5cd47f |
diff --git a/src/responder/sudo/sudosrv_get_sudorules.c b/src/responder/sudo/sudosrv_get_sudorules.c
|
|
|
5cd47f |
index d928a5ead..c9c11bfde 100644
|
|
|
5cd47f |
--- a/src/responder/sudo/sudosrv_get_sudorules.c
|
|
|
5cd47f |
+++ b/src/responder/sudo/sudosrv_get_sudorules.c
|
|
|
5cd47f |
@@ -147,7 +147,8 @@ static errno_t sudosrv_format_runas(struct resp_ctx *rctx,
|
|
|
5cd47f |
continue;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
- dom = find_domain_by_object_name_ex(rctx->domains, value, true);
|
|
|
5cd47f |
+ dom = find_domain_by_object_name_ex(rctx->domains, value, true,
|
|
|
5cd47f |
+ SSS_GND_DESCEND);
|
|
|
5cd47f |
if (dom == NULL) {
|
|
|
5cd47f |
continue;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c
|
|
|
5cd47f |
index 1a8699a2a..d49eb9fbc 100644
|
|
|
5cd47f |
--- a/src/tests/cmocka/test_utils.c
|
|
|
5cd47f |
+++ b/src/tests/cmocka/test_utils.c
|
|
|
5cd47f |
@@ -400,6 +400,92 @@ void test_find_domain_by_name_disabled(void **state)
|
|
|
5cd47f |
}
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
+void test_find_domain_by_name_ex_disabled(void **state)
|
|
|
5cd47f |
+{
|
|
|
5cd47f |
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5cd47f |
+ struct dom_list_test_ctx);
|
|
|
5cd47f |
+ struct sss_domain_info *dom;
|
|
|
5cd47f |
+ struct sss_domain_info *disabled_dom;
|
|
|
5cd47f |
+ size_t c;
|
|
|
5cd47f |
+ size_t mis;
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ mis = test_ctx->dom_count/2;
|
|
|
5cd47f |
+ assert_true((mis >= 1 && mis < test_ctx->dom_count));
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = test_ctx->dom_list;
|
|
|
5cd47f |
+ for (c = 0; c < mis; c++) {
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ dom = dom->next;
|
|
|
5cd47f |
+ }
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ sss_domain_set_state(dom, DOM_DISABLED);
|
|
|
5cd47f |
+ disabled_dom = dom;
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_name(test_ctx->dom_list, disabled_dom->name, true);
|
|
|
5cd47f |
+ assert_null(dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_name_ex(test_ctx->dom_list, disabled_dom->name, true,
|
|
|
5cd47f |
+ SSS_GND_DESCEND);
|
|
|
5cd47f |
+ assert_null(dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_name_ex(test_ctx->dom_list, disabled_dom->name, true,
|
|
|
5cd47f |
+ SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED);
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ assert_ptr_equal(disabled_dom, dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_name_ex(test_ctx->dom_list, disabled_dom->name, true,
|
|
|
5cd47f |
+ SSS_GND_ALL_DOMAINS);
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ assert_ptr_equal(disabled_dom, dom);
|
|
|
5cd47f |
+}
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+void test_find_domain_by_object_name_ex(void **state)
|
|
|
5cd47f |
+{
|
|
|
5cd47f |
+ struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5cd47f |
+ struct dom_list_test_ctx);
|
|
|
5cd47f |
+ struct sss_domain_info *dom;
|
|
|
5cd47f |
+ struct sss_domain_info *disabled_dom;
|
|
|
5cd47f |
+ size_t c;
|
|
|
5cd47f |
+ size_t mis;
|
|
|
5cd47f |
+ char *obj_name;
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ mis = test_ctx->dom_count/2;
|
|
|
5cd47f |
+ assert_true((mis >= 1 && mis < test_ctx->dom_count));
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = test_ctx->dom_list;
|
|
|
5cd47f |
+ for (c = 0; c < mis; c++) {
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ dom = dom->next;
|
|
|
5cd47f |
+ }
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ sss_domain_set_state(dom, DOM_DISABLED);
|
|
|
5cd47f |
+ disabled_dom = dom;
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ obj_name = talloc_asprintf(global_talloc_context, "myname@%s",
|
|
|
5cd47f |
+ disabled_dom->name);
|
|
|
5cd47f |
+ assert_non_null(obj_name);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_object_name(test_ctx->dom_list, obj_name);
|
|
|
5cd47f |
+ assert_null(dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_object_name_ex(test_ctx->dom_list, obj_name, true,
|
|
|
5cd47f |
+ SSS_GND_DESCEND);
|
|
|
5cd47f |
+ assert_null(dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_object_name_ex(test_ctx->dom_list, obj_name, true,
|
|
|
5cd47f |
+ SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED);
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ assert_ptr_equal(disabled_dom, dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ dom = find_domain_by_object_name_ex(test_ctx->dom_list, obj_name, true,
|
|
|
5cd47f |
+ SSS_GND_ALL_DOMAINS);
|
|
|
5cd47f |
+ assert_non_null(dom);
|
|
|
5cd47f |
+ assert_ptr_equal(disabled_dom, dom);
|
|
|
5cd47f |
+
|
|
|
5cd47f |
+ talloc_free(obj_name);
|
|
|
5cd47f |
+}
|
|
|
5cd47f |
+
|
|
|
5cd47f |
void test_find_domain_by_sid_null(void **state)
|
|
|
5cd47f |
{
|
|
|
5cd47f |
struct dom_list_test_ctx *test_ctx = talloc_get_type(*state,
|
|
|
5cd47f |
@@ -1877,6 +1963,10 @@ int main(int argc, const char *argv[])
|
|
|
5cd47f |
setup_dom_list, teardown_dom_list),
|
|
|
5cd47f |
cmocka_unit_test_setup_teardown(test_find_domain_by_name_disabled,
|
|
|
5cd47f |
setup_dom_list, teardown_dom_list),
|
|
|
5cd47f |
+ cmocka_unit_test_setup_teardown(test_find_domain_by_name_ex_disabled,
|
|
|
5cd47f |
+ setup_dom_list, teardown_dom_list),
|
|
|
5cd47f |
+ cmocka_unit_test_setup_teardown(test_find_domain_by_object_name_ex,
|
|
|
5cd47f |
+ setup_dom_list, teardown_dom_list),
|
|
|
5cd47f |
|
|
|
5cd47f |
cmocka_unit_test_setup_teardown(test_sss_names_init,
|
|
|
5cd47f |
confdb_test_setup,
|
|
|
5cd47f |
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
|
|
|
5cd47f |
index 4b1c9df39..c56a0611e 100644
|
|
|
5cd47f |
--- a/src/util/domain_info_utils.c
|
|
|
5cd47f |
+++ b/src/util/domain_info_utils.c
|
|
|
5cd47f |
@@ -93,9 +93,10 @@ bool subdomain_enumerates(struct sss_domain_info *parent,
|
|
|
5cd47f |
return false;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
-struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
|
|
|
5cd47f |
- const char *name,
|
|
|
5cd47f |
- bool match_any)
|
|
|
5cd47f |
+struct sss_domain_info *find_domain_by_name_ex(struct sss_domain_info *domain,
|
|
|
5cd47f |
+ const char *name,
|
|
|
5cd47f |
+ bool match_any,
|
|
|
5cd47f |
+ uint32_t gnd_flags)
|
|
|
5cd47f |
{
|
|
|
5cd47f |
struct sss_domain_info *dom = domain;
|
|
|
5cd47f |
|
|
|
5cd47f |
@@ -103,21 +104,31 @@ struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
|
|
|
5cd47f |
return NULL;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
- while (dom && sss_domain_get_state(dom) == DOM_DISABLED) {
|
|
|
5cd47f |
- dom = get_next_domain(dom, SSS_GND_DESCEND);
|
|
|
5cd47f |
+ if (!(gnd_flags & SSS_GND_INCLUDE_DISABLED)) {
|
|
|
5cd47f |
+ while (dom && sss_domain_get_state(dom) == DOM_DISABLED) {
|
|
|
5cd47f |
+ dom = get_next_domain(dom, gnd_flags);
|
|
|
5cd47f |
+ }
|
|
|
5cd47f |
}
|
|
|
5cd47f |
+
|
|
|
5cd47f |
while (dom) {
|
|
|
5cd47f |
if (strcasecmp(dom->name, name) == 0 ||
|
|
|
5cd47f |
((match_any == true) && (dom->flat_name != NULL) &&
|
|
|
5cd47f |
(strcasecmp(dom->flat_name, name) == 0))) {
|
|
|
5cd47f |
return dom;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
- dom = get_next_domain(dom, SSS_GND_DESCEND);
|
|
|
5cd47f |
+ dom = get_next_domain(dom, gnd_flags);
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
return NULL;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
+struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
|
|
|
5cd47f |
+ const char *name,
|
|
|
5cd47f |
+ bool match_any)
|
|
|
5cd47f |
+{
|
|
|
5cd47f |
+ return find_domain_by_name_ex(domain, name, match_any, SSS_GND_DESCEND);
|
|
|
5cd47f |
+}
|
|
|
5cd47f |
+
|
|
|
5cd47f |
struct sss_domain_info *find_domain_by_sid(struct sss_domain_info *domain,
|
|
|
5cd47f |
const char *sid)
|
|
|
5cd47f |
{
|
|
|
5cd47f |
@@ -175,7 +186,8 @@ sss_get_domain_by_sid_ldap_fallback(struct sss_domain_info *domain,
|
|
|
5cd47f |
|
|
|
5cd47f |
struct sss_domain_info *
|
|
|
5cd47f |
find_domain_by_object_name_ex(struct sss_domain_info *domain,
|
|
|
5cd47f |
- const char *object_name, bool strict)
|
|
|
5cd47f |
+ const char *object_name, bool strict,
|
|
|
5cd47f |
+ uint32_t gnd_flags)
|
|
|
5cd47f |
{
|
|
|
5cd47f |
TALLOC_CTX *tmp_ctx;
|
|
|
5cd47f |
struct sss_domain_info *dom = NULL;
|
|
|
5cd47f |
@@ -203,7 +215,7 @@ find_domain_by_object_name_ex(struct sss_domain_info *domain,
|
|
|
5cd47f |
dom = domain;
|
|
|
5cd47f |
}
|
|
|
5cd47f |
} else {
|
|
|
5cd47f |
- dom = find_domain_by_name(domain, domainname, true);
|
|
|
5cd47f |
+ dom = find_domain_by_name_ex(domain, domainname, true, gnd_flags);
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
done:
|
|
|
5cd47f |
@@ -215,7 +227,8 @@ struct sss_domain_info *
|
|
|
5cd47f |
find_domain_by_object_name(struct sss_domain_info *domain,
|
|
|
5cd47f |
const char *object_name)
|
|
|
5cd47f |
{
|
|
|
5cd47f |
- return find_domain_by_object_name_ex(domain, object_name, false);
|
|
|
5cd47f |
+ return find_domain_by_object_name_ex(domain, object_name, false,
|
|
|
5cd47f |
+ SSS_GND_DESCEND);
|
|
|
5cd47f |
}
|
|
|
5cd47f |
|
|
|
5cd47f |
errno_t sssd_domain_init(TALLOC_CTX *mem_ctx,
|
|
|
5cd47f |
diff --git a/src/util/util.h b/src/util/util.h
|
|
|
5cd47f |
index fce7e42c3..8a754dbfd 100644
|
|
|
5cd47f |
--- a/src/util/util.h
|
|
|
5cd47f |
+++ b/src/util/util.h
|
|
|
5cd47f |
@@ -542,6 +542,10 @@ struct sss_domain_info *get_next_domain(struct sss_domain_info *domain,
|
|
|
5cd47f |
struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
|
|
|
5cd47f |
const char *name,
|
|
|
5cd47f |
bool match_any);
|
|
|
5cd47f |
+struct sss_domain_info *find_domain_by_name_ex(struct sss_domain_info *domain,
|
|
|
5cd47f |
+ const char *name,
|
|
|
5cd47f |
+ bool match_any,
|
|
|
5cd47f |
+ uint32_t gnd_flags);
|
|
|
5cd47f |
struct sss_domain_info *find_domain_by_sid(struct sss_domain_info *domain,
|
|
|
5cd47f |
const char *sid);
|
|
|
5cd47f |
enum sss_domain_state sss_domain_get_state(struct sss_domain_info *dom);
|
|
|
5cd47f |
@@ -560,7 +564,8 @@ find_domain_by_object_name(struct sss_domain_info *domain,
|
|
|
5cd47f |
|
|
|
5cd47f |
struct sss_domain_info *
|
|
|
5cd47f |
find_domain_by_object_name_ex(struct sss_domain_info *domain,
|
|
|
5cd47f |
- const char *object_name, bool strict);
|
|
|
5cd47f |
+ const char *object_name, bool strict,
|
|
|
5cd47f |
+ uint32_t gnd_flags);
|
|
|
5cd47f |
|
|
|
5cd47f |
bool subdomain_enumerates(struct sss_domain_info *parent,
|
|
|
5cd47f |
const char *sd_name);
|
|
|
5cd47f |
--
|
|
|
5cd47f |
2.20.1
|
|
|
5cd47f |
|