Blame SOURCES/0053-negcache-do-not-use-default_domain_suffix.patch

32a074
From 56d509ad3001101f04c4af050c3da7472032e4cb Mon Sep 17 00:00:00 2001
32a074
From: Sumit Bose <sbose@redhat.com>
32a074
Date: Fri, 9 Oct 2020 15:26:39 +0200
32a074
Subject: [PATCH 53/53] negcache: do not use default_domain_suffix
32a074
32a074
When splitting the names from the filter_users and filter_groups options
32a074
do not use the default_domain_suffix because it will hide that the
32a074
original name is a short name and should be added everywhere.
32a074
32a074
Additionally this patch fixes a typo where sss_parse_name() was used
32a074
instead of sss_parse_name_for_domains().
32a074
32a074
Resolves: https://github.com/SSSD/sssd/issues/5238
32a074
32a074
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
32a074
(cherry picked from commit fa4b46e7de7297da3c0e37913eab8cba7f103629)
32a074
---
32a074
 src/responder/common/negcache.c  | 29 +++++++++++++++--------------
32a074
 src/tests/cmocka/test_negcache.c | 22 ++++++++++++++++++++--
32a074
 2 files changed, 35 insertions(+), 16 deletions(-)
32a074
32a074
diff --git a/src/responder/common/negcache.c b/src/responder/common/negcache.c
32a074
index 47fbb2106..ff05aaea5 100644
32a074
--- a/src/responder/common/negcache.c
32a074
+++ b/src/responder/common/negcache.c
32a074
@@ -998,13 +998,13 @@ errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
32a074
 
32a074
         for (i = 0; (filter_list && filter_list[i]); i++) {
32a074
             ret = sss_parse_name_for_domains(tmpctx, domain_list,
32a074
-                                             rctx->default_domain,
32a074
+                                             NULL,
32a074
                                              filter_list[i],
32a074
                                              &domainname, &name);
32a074
             if (ret == EAGAIN) {
32a074
                 DEBUG(SSSDBG_MINOR_FAILURE,
32a074
-                      "cannot add [%s] to negcache because the required or "
32a074
-                      "default domain are not known yet\n", filter_list[i]);
32a074
+                      "Can add [%s] only as UPN to negcache because the "
32a074
+                      "required domain is not known yet\n", filter_list[i]);
32a074
             } else if (ret != EOK) {
32a074
                 DEBUG(SSSDBG_CRIT_FAILURE,
32a074
                       "Invalid name in filterUsers list: [%s] (%d)\n",
32a074
@@ -1064,12 +1064,12 @@ errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
32a074
 
32a074
     for (i = 0; (filter_list && filter_list[i]); i++) {
32a074
         ret = sss_parse_name_for_domains(tmpctx, domain_list,
32a074
-                                         rctx->default_domain, filter_list[i],
32a074
+                                         NULL, filter_list[i],
32a074
                                          &domainname, &name);
32a074
         if (ret == EAGAIN) {
32a074
             DEBUG(SSSDBG_MINOR_FAILURE,
32a074
-                  "Cannot add [%s] to negcache because the required or "
32a074
-                  "default domain are not known yet\n", filter_list[i]);
32a074
+                  "Can add [%s] only as UPN to negcache because the "
32a074
+                  "required domain is not known yet\n", filter_list[i]);
32a074
         } else if (ret != EOK) {
32a074
             DEBUG(SSSDBG_CRIT_FAILURE,
32a074
                   "Invalid name in filterUsers list: [%s] (%d)\n",
32a074
@@ -1156,9 +1156,12 @@ errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
32a074
         if (ret != EOK) goto done;
32a074
 
32a074
         for (i = 0; (filter_list && filter_list[i]); i++) {
32a074
-            ret = sss_parse_name(tmpctx, dom->names, filter_list[i],
32a074
-                                 &domainname, &name);
32a074
+            ret = sss_parse_name_for_domains(tmpctx, domain_list,
32a074
+                                             NULL, filter_list[i],
32a074
+                                             &domainname, &name);
32a074
             if (ret != EOK) {
32a074
+                /* Groups do not have UPNs, so domain names, if present,
32a074
+                 * must be known */
32a074
                 DEBUG(SSSDBG_CRIT_FAILURE,
32a074
                       "Invalid name in filterGroups list: [%s] (%d)\n",
32a074
                          filter_list[i], ret);
32a074
@@ -1205,13 +1208,11 @@ errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
32a074
 
32a074
     for (i = 0; (filter_list && filter_list[i]); i++) {
32a074
         ret = sss_parse_name_for_domains(tmpctx, domain_list,
32a074
-                                         rctx->default_domain, filter_list[i],
32a074
+                                         NULL, filter_list[i],
32a074
                                          &domainname, &name);
32a074
-        if (ret == EAGAIN) {
32a074
-            DEBUG(SSSDBG_MINOR_FAILURE,
32a074
-                  "Cannot add [%s] to negcache because the required or "
32a074
-                  "default domain are not known yet\n", filter_list[i]);
32a074
-        } else if (ret != EOK) {
32a074
+        if (ret != EOK) {
32a074
+            /* Groups do not have UPNs, so domain names, if present,
32a074
+             * must be known */
32a074
             DEBUG(SSSDBG_CRIT_FAILURE,
32a074
                   "Invalid name in filterGroups list: [%s] (%d)\n",
32a074
                      filter_list[i], ret);
32a074
diff --git a/src/tests/cmocka/test_negcache.c b/src/tests/cmocka/test_negcache.c
32a074
index 7a8827685..f8cbbc1fe 100644
32a074
--- a/src/tests/cmocka/test_negcache.c
32a074
+++ b/src/tests/cmocka/test_negcache.c
32a074
@@ -916,7 +916,9 @@ static void test_sss_ncache_reset_prepopulate(void **state)
32a074
  *
32a074
  * The result should of course be independent of the present domains. To
32a074
  * verify this the domains are added one after the other and the negative
32a074
- * cache is repopulated each time.
32a074
+ * cache is repopulated each time. The result should be also independent of
32a074
+ * the setting of default_domain_suffix option which is tested by
32a074
+ * test_sss_ncache_short_name_in_domain_with_prefix.
32a074
  *
32a074
  * With the given domains, users and group we have to following expectations:
32a074
  *  - the short name entry will be added to the domain and all sub-domains as
32a074
@@ -1064,7 +1066,8 @@ static void expect_no_entries_in_dom(struct sss_nc_ctx *ncache,
32a074
     assert_int_equal(ret, ENOENT);
32a074
 }
32a074
 
32a074
-static void test_sss_ncache_short_name_in_domain(void **state)
32a074
+static void run_sss_ncache_short_name_in_domain(void **state,
32a074
+                                                bool use_default_domain_prefix)
32a074
 {
32a074
     int ret;
32a074
     struct test_state *ts;
32a074
@@ -1114,6 +1117,9 @@ static void test_sss_ncache_short_name_in_domain(void **state)
32a074
     ncache = ts->ctx;
32a074
     ts->rctx = mock_rctx(ts, ev, dom, ts->nctx);
32a074
     assert_non_null(ts->rctx);
32a074
+    if (use_default_domain_prefix) {
32a074
+        ts->rctx->default_domain = discard_const(TEST_DOM_NAME);
32a074
+    }
32a074
     ts->rctx->cdb = tc->confdb;
32a074
 
32a074
     ret = sss_names_init(ts, tc->confdb, TEST_DOM_NAME, &dom->names);
32a074
@@ -1156,6 +1162,16 @@ static void test_sss_ncache_short_name_in_domain(void **state)
32a074
     expect_no_entries_in_dom(ncache, dom2);
32a074
 }
32a074
 
32a074
+static void test_sss_ncache_short_name_in_domain(void **state)
32a074
+{
32a074
+    run_sss_ncache_short_name_in_domain(state, false);
32a074
+}
32a074
+
32a074
+static void test_sss_ncache_short_name_in_domain_with_prefix(void **state)
32a074
+{
32a074
+    run_sss_ncache_short_name_in_domain(state, true);
32a074
+}
32a074
+
32a074
 static void test_sss_ncache_reset(void **state)
32a074
 {
32a074
     errno_t ret;
32a074
@@ -1320,6 +1336,8 @@ int main(void)
32a074
                                         setup, teardown),
32a074
         cmocka_unit_test_setup_teardown(test_sss_ncache_short_name_in_domain,
32a074
                                         setup, teardown),
32a074
+        cmocka_unit_test_setup_teardown(test_sss_ncache_short_name_in_domain_with_prefix,
32a074
+                                        setup, teardown),
32a074
         cmocka_unit_test_setup_teardown(test_sss_ncache_reset,
32a074
                                         setup, teardown),
32a074
         cmocka_unit_test_setup_teardown(test_sss_ncache_locate_uid_gid,
32a074
-- 
32a074
2.21.3
32a074