|
|
32a074 |
From ea32d0eb61336858aa23697b4e91d420481fc3e2 Mon Sep 17 00:00:00 2001
|
|
|
32a074 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
32a074 |
Date: Thu, 8 Oct 2020 17:57:29 +0200
|
|
|
32a074 |
Subject: [PATCH 51/53] utils: add SSS_GND_SUBDOMAINS flag for
|
|
|
32a074 |
get_next_domain()
|
|
|
32a074 |
|
|
|
32a074 |
To allow to only iterate over a singel domain an its sub-domains a new
|
|
|
32a074 |
flag is added to get_next_domain().
|
|
|
32a074 |
|
|
|
32a074 |
Resolves: https://github.com/SSSD/sssd/issues/5238
|
|
|
32a074 |
|
|
|
32a074 |
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
|
|
|
32a074 |
(cherry picked from commit 385af99ff4d5a75d0c1edc9ad830da3eb7478295)
|
|
|
32a074 |
---
|
|
|
32a074 |
src/tests/cmocka/test_utils.c | 31 +++++++++++++++++++++++++++++++
|
|
|
32a074 |
src/util/domain_info_utils.c | 10 +++++++---
|
|
|
32a074 |
src/util/util.h | 4 ++++
|
|
|
32a074 |
3 files changed, 42 insertions(+), 3 deletions(-)
|
|
|
32a074 |
|
|
|
32a074 |
diff --git a/src/tests/cmocka/test_utils.c b/src/tests/cmocka/test_utils.c
|
|
|
32a074 |
index aa245f00b..8c0ce83f3 100644
|
|
|
32a074 |
--- a/src/tests/cmocka/test_utils.c
|
|
|
32a074 |
+++ b/src/tests/cmocka/test_utils.c
|
|
|
32a074 |
@@ -876,6 +876,37 @@ static void test_get_next_domain_flags(void **state)
|
|
|
32a074 |
|
|
|
32a074 |
dom = get_next_domain(dom, gnd_flags);
|
|
|
32a074 |
assert_null(dom);
|
|
|
32a074 |
+
|
|
|
32a074 |
+ /* Descend only to subdomains */
|
|
|
32a074 |
+ gnd_flags = SSS_GND_SUBDOMAINS | SSS_GND_INCLUDE_DISABLED;
|
|
|
32a074 |
+
|
|
|
32a074 |
+ dom = get_next_domain(test_ctx->dom_list, gnd_flags);
|
|
|
32a074 |
+ assert_non_null(dom);
|
|
|
32a074 |
+ assert_string_equal(dom->name, "sub1a");
|
|
|
32a074 |
+
|
|
|
32a074 |
+ dom = get_next_domain(dom, gnd_flags);
|
|
|
32a074 |
+ assert_null(dom);
|
|
|
32a074 |
+
|
|
|
32a074 |
+ dom = find_domain_by_name_ex(test_ctx->dom_list, "dom2", true,
|
|
|
32a074 |
+ SSS_GND_ALL_DOMAINS);
|
|
|
32a074 |
+ assert_non_null(dom);
|
|
|
32a074 |
+ assert_string_equal(dom->name, "dom2");
|
|
|
32a074 |
+
|
|
|
32a074 |
+ dom = get_next_domain(dom, gnd_flags);
|
|
|
32a074 |
+ assert_non_null(dom);
|
|
|
32a074 |
+ assert_string_equal(dom->name, "sub2a");
|
|
|
32a074 |
+
|
|
|
32a074 |
+ dom = get_next_domain(dom, gnd_flags);
|
|
|
32a074 |
+ assert_non_null(dom);
|
|
|
32a074 |
+ assert_string_equal(dom->name, "sub2b");
|
|
|
32a074 |
+
|
|
|
32a074 |
+ dom = get_next_domain(dom, gnd_flags);
|
|
|
32a074 |
+ assert_null(dom);
|
|
|
32a074 |
+
|
|
|
32a074 |
+ /* Expect NULL if the domain has no sub-domains */
|
|
|
32a074 |
+ test_ctx->dom_list->subdomains = NULL;
|
|
|
32a074 |
+ dom = get_next_domain(test_ctx->dom_list, gnd_flags);
|
|
|
32a074 |
+ assert_null(dom);
|
|
|
32a074 |
}
|
|
|
32a074 |
|
|
|
32a074 |
struct name_init_test_ctx {
|
|
|
32a074 |
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
|
|
|
32a074 |
index c56a0611e..71dfcba02 100644
|
|
|
32a074 |
--- a/src/util/domain_info_utils.c
|
|
|
32a074 |
+++ b/src/util/domain_info_utils.c
|
|
|
32a074 |
@@ -39,16 +39,20 @@ struct sss_domain_info *get_next_domain(struct sss_domain_info *domain,
|
|
|
32a074 |
uint32_t gnd_flags)
|
|
|
32a074 |
{
|
|
|
32a074 |
struct sss_domain_info *dom;
|
|
|
32a074 |
- bool descend = gnd_flags & SSS_GND_DESCEND;
|
|
|
32a074 |
+ bool descend = gnd_flags & (SSS_GND_DESCEND | SSS_GND_SUBDOMAINS);
|
|
|
32a074 |
bool include_disabled = gnd_flags & SSS_GND_INCLUDE_DISABLED;
|
|
|
32a074 |
+ bool only_subdomains = gnd_flags & SSS_GND_SUBDOMAINS;
|
|
|
32a074 |
|
|
|
32a074 |
dom = domain;
|
|
|
32a074 |
while (dom) {
|
|
|
32a074 |
if (descend && dom->subdomains) {
|
|
|
32a074 |
dom = dom->subdomains;
|
|
|
32a074 |
- } else if (dom->next) {
|
|
|
32a074 |
+ } else if (dom->next && only_subdomains && IS_SUBDOMAIN(dom)) {
|
|
|
32a074 |
dom = dom->next;
|
|
|
32a074 |
- } else if (descend && IS_SUBDOMAIN(dom) && dom->parent->next) {
|
|
|
32a074 |
+ } else if (dom->next && !only_subdomains) {
|
|
|
32a074 |
+ dom = dom->next;
|
|
|
32a074 |
+ } else if (descend && !only_subdomains && IS_SUBDOMAIN(dom)
|
|
|
32a074 |
+ && dom->parent->next) {
|
|
|
32a074 |
dom = dom->parent->next;
|
|
|
32a074 |
} else {
|
|
|
32a074 |
dom = NULL;
|
|
|
32a074 |
diff --git a/src/util/util.h b/src/util/util.h
|
|
|
32a074 |
index d7d2017fa..486394448 100644
|
|
|
32a074 |
--- a/src/util/util.h
|
|
|
32a074 |
+++ b/src/util/util.h
|
|
|
32a074 |
@@ -558,7 +558,11 @@ struct sss_domain_info *get_domains_head(struct sss_domain_info *domain);
|
|
|
32a074 |
|
|
|
32a074 |
#define SSS_GND_DESCEND 0x01
|
|
|
32a074 |
#define SSS_GND_INCLUDE_DISABLED 0x02
|
|
|
32a074 |
+/* Descend to sub-domains of current domain but do not go to next parent */
|
|
|
32a074 |
+#define SSS_GND_SUBDOMAINS 0x04
|
|
|
32a074 |
#define SSS_GND_ALL_DOMAINS (SSS_GND_DESCEND | SSS_GND_INCLUDE_DISABLED)
|
|
|
32a074 |
+#define SSS_GND_ALL_SUBDOMAINS (SSS_GND_SUBDOMAINS | SSS_GND_INCLUDE_DISABLED)
|
|
|
32a074 |
+
|
|
|
32a074 |
struct sss_domain_info *get_next_domain(struct sss_domain_info *domain,
|
|
|
32a074 |
uint32_t gnd_flags);
|
|
|
32a074 |
struct sss_domain_info *find_domain_by_name(struct sss_domain_info *domain,
|
|
|
32a074 |
--
|
|
|
32a074 |
2.21.3
|
|
|
32a074 |
|