Blame SOURCES/0035-negcache-add-fq-usernames-of-know-domains-to-all-UPN.patch

5cd47f
From 934341e1ef7cf2a763b604dd1fd347aa5aae7f60 Mon Sep 17 00:00:00 2001
5cd47f
From: Sumit Bose <sbose@redhat.com>
5cd47f
Date: Mon, 24 Jun 2019 14:01:02 +0200
5cd47f
Subject: [PATCH 35/35] negcache: add fq-usernames of know domains to all UPN
5cd47f
 neg-caches
5cd47f
5cd47f
The previous patch for this issue did not handle user with
5cd47f
fully-qualified names from known domains correctly. Here the user was
5cd47f
only added to the negative cache of the known domain but not to the
5cd47f
negative UPN caches for all domains. This patch fixes this.
5cd47f
5cd47f
Related to https://pagure.io/SSSD/sssd/issue/3978
5cd47f
5cd47f
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
5cd47f
(cherry picked from commit e7e212b49bbd357129aab410cbbd5c7b1b0965a2)
5cd47f
---
5cd47f
 src/responder/common/negcache.c  | 54 ++++++++++++++++----------------
5cd47f
 src/tests/cmocka/test_negcache.c | 17 +++++++++-
5cd47f
 2 files changed, 43 insertions(+), 28 deletions(-)
5cd47f
5cd47f
diff --git a/src/responder/common/negcache.c b/src/responder/common/negcache.c
5cd47f
index d6f72d816..d9bf1417e 100644
5cd47f
--- a/src/responder/common/negcache.c
5cd47f
+++ b/src/responder/common/negcache.c
5cd47f
@@ -1070,37 +1070,37 @@ errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
5cd47f
             continue;
5cd47f
         }
5cd47f
         if (domainname) {
5cd47f
-            dom = responder_get_domain(rctx, domainname);
5cd47f
-            if (!dom) {
5cd47f
-                DEBUG(SSSDBG_CRIT_FAILURE,
5cd47f
-                      "Unknown domain name [%s], assuming [%s] is UPN\n",
5cd47f
-                      domainname, filter_list[i]);
5cd47f
-                for (dom = domain_list;
5cd47f
-                     dom != NULL;
5cd47f
-                     dom = get_next_domain(dom, SSS_GND_ALL_DOMAINS)) {
5cd47f
-                    ret = sss_ncache_set_upn(ncache, true, dom, filter_list[i]);
5cd47f
-                    if (ret != EOK) {
5cd47f
-                        DEBUG(SSSDBG_OP_FAILURE,
5cd47f
-                              "sss_ncache_set_upn failed (%d [%s]), ignored\n",
5cd47f
-                              ret, sss_strerror(ret));
5cd47f
-                    }
5cd47f
+            DEBUG(SSSDBG_TRACE_ALL,
5cd47f
+                  "Adding [%s] to UPN negative cache of all domains.\n",
5cd47f
+                  filter_list[i]);
5cd47f
+            for (dom = domain_list;
5cd47f
+                 dom != NULL;
5cd47f
+                 dom = get_next_domain(dom, SSS_GND_ALL_DOMAINS)) {
5cd47f
+                ret = sss_ncache_set_upn(ncache, true, dom, filter_list[i]);
5cd47f
+                if (ret != EOK) {
5cd47f
+                    DEBUG(SSSDBG_OP_FAILURE,
5cd47f
+                          "sss_ncache_set_upn failed (%d [%s]), ignored\n",
5cd47f
+                          ret, sss_strerror(ret));
5cd47f
                 }
5cd47f
-                continue;
5cd47f
             }
5cd47f
 
5cd47f
-            fqname = sss_create_internal_fqname(tmpctx, name, dom->name);
5cd47f
-            if (fqname == NULL) {
5cd47f
-                continue;
5cd47f
-            }
5cd47f
+            /* Add name to domain specific cache for known domain names */
5cd47f
+            dom = responder_get_domain(rctx, domainname);
5cd47f
+            if (dom != NULL) {
5cd47f
+                fqname = sss_create_internal_fqname(tmpctx, name, dom->name);
5cd47f
+                if (fqname == NULL) {
5cd47f
+                    continue;
5cd47f
+                }
5cd47f
 
5cd47f
-            ret = sss_ncache_set_user(ncache, true, dom, fqname);
5cd47f
-            talloc_zfree(fqname);
5cd47f
-            if (ret != EOK) {
5cd47f
-                DEBUG(SSSDBG_CRIT_FAILURE,
5cd47f
-                      "Failed to store permanent user filter for [%s]"
5cd47f
-                          " (%d [%s])\n", filter_list[i],
5cd47f
-                          ret, strerror(ret));
5cd47f
-                continue;
5cd47f
+                ret = sss_ncache_set_user(ncache, true, dom, fqname);
5cd47f
+                talloc_zfree(fqname);
5cd47f
+                if (ret != EOK) {
5cd47f
+                    DEBUG(SSSDBG_CRIT_FAILURE,
5cd47f
+                          "Failed to store permanent user filter for [%s]"
5cd47f
+                              " (%d [%s])\n", filter_list[i],
5cd47f
+                              ret, strerror(ret));
5cd47f
+                    continue;
5cd47f
+                }
5cd47f
             }
5cd47f
         } else {
5cd47f
             for (dom = domain_list;
5cd47f
diff --git a/src/tests/cmocka/test_negcache.c b/src/tests/cmocka/test_negcache.c
5cd47f
index 9bddddd8d..0a7e563e0 100644
5cd47f
--- a/src/tests/cmocka/test_negcache.c
5cd47f
+++ b/src/tests/cmocka/test_negcache.c
5cd47f
@@ -618,7 +618,7 @@ static void test_sss_ncache_prepopulate(void **state)
5cd47f
     struct sss_domain_info *subdomain;
5cd47f
 
5cd47f
     struct sss_test_conf_param nss_params[] = {
5cd47f
-        { "filter_users", "testuser_nss@UPN.REALM, testuser_nss_short" },
5cd47f
+        { "filter_users", "testuser_nss@UPN.REALM, testuser_nss_short, all_dom_upn@"TEST_DOM_NAME },
5cd47f
         { NULL, NULL },
5cd47f
     };
5cd47f
     struct sss_test_conf_param dom_params[] = {
5cd47f
@@ -733,6 +733,21 @@ static void test_sss_ncache_prepopulate(void **state)
5cd47f
 
5cd47f
     ret = sss_ncache_check_upn(ncache, tc->dom, "testuser3@somedomain");
5cd47f
     assert_int_equal(ret, EEXIST);
5cd47f
+
5cd47f
+    /* Fully qualified names with a known domain part should be added to all
5cd47f
+     * negative UPN caches and to the negative cache of the know domain. */
5cd47f
+    ret = sss_ncache_check_upn(ncache, tc->dom, "all_dom_upn@"TEST_DOM_NAME);
5cd47f
+    assert_int_equal(ret, EEXIST);
5cd47f
+
5cd47f
+    ret = sss_ncache_check_upn(ncache, tc->dom->subdomains,
5cd47f
+                               "all_dom_upn@"TEST_DOM_NAME);
5cd47f
+    assert_int_equal(ret, EEXIST);
5cd47f
+
5cd47f
+    ret = check_user_in_ncache(ncache, tc->dom, "all_dom_upn");
5cd47f
+    assert_int_equal(ret, EEXIST);
5cd47f
+
5cd47f
+    ret = check_user_in_ncache(ncache, tc->dom->subdomains, "all_dom_upn");
5cd47f
+    assert_int_equal(ret, ENOENT);
5cd47f
 }
5cd47f
 
5cd47f
 static void test_sss_ncache_default_domain_suffix(void **state)
5cd47f
-- 
5cd47f
2.20.1
5cd47f