dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0093-utils-extend-some-find_domain_-calls-to-search-disab.patch

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