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

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