dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

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

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