Blame SOURCES/0056-negcache-use-right-domain-in-nss_protocol_fill_initg.patch

3247ef
From 231d1118727b989a4af9911a45a465912fe659d6 Mon Sep 17 00:00:00 2001
3247ef
From: Sumit Bose <sbose@redhat.com>
3247ef
Date: Fri, 12 Mar 2021 14:38:54 +0100
3247ef
Subject: [PATCH] negcache: use right domain in nss_protocol_fill_initgr()
3247ef
MIME-Version: 1.0
3247ef
Content-Type: text/plain; charset=UTF-8
3247ef
Content-Transfer-Encoding: 8bit
3247ef
3247ef
When checking if a group returned by an initgroups request is filtered
3247ef
in the negative cache the domain of the user was used. This does not
3247ef
work reliable if the user can be a member of groups from multiple
3247ef
domains.
3247ef
3247ef
With this patch th domain the group belongs to is determined and used
3247ef
while checking the negative cache.
3247ef
3247ef
Resolves: https://github.com/SSSD/sssd/issues/5534
3247ef
3247ef
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
3247ef
---
3247ef
 src/db/sysdb.c                         | 22 ++++++++++++++++++++++
3247ef
 src/db/sysdb.h                         |  7 +++++++
3247ef
 src/responder/nss/nss_protocol_grent.c |  8 +++++---
3247ef
 3 files changed, 34 insertions(+), 3 deletions(-)
3247ef
3247ef
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
3247ef
index 693f687be..6001c49cb 100644
3247ef
--- a/src/db/sysdb.c
3247ef
+++ b/src/db/sysdb.c
3247ef
@@ -2139,3 +2139,25 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level,
3247ef
                       fmt, ap);
3247ef
     }
3247ef
 }
3247ef
+
3247ef
+struct sss_domain_info *find_domain_by_msg(struct sss_domain_info *dom,
3247ef
+                                           struct ldb_message *msg)
3247ef
+{
3247ef
+    const char *name;
3247ef
+    struct sss_domain_info *obj_dom = NULL;
3247ef
+
3247ef
+    name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
3247ef
+    if (name == NULL) {
3247ef
+        DEBUG(SSSDBG_OP_FAILURE,
3247ef
+              "Object does not have a name attribute.\n");
3247ef
+        return dom;
3247ef
+    }
3247ef
+
3247ef
+    obj_dom = find_domain_by_object_name(get_domains_head(dom), name);
3247ef
+    if (obj_dom == NULL) {
3247ef
+        DEBUG(SSSDBG_OP_FAILURE, "No domain found for [%s].\n", name);
3247ef
+        return dom;
3247ef
+    }
3247ef
+
3247ef
+    return obj_dom;
3247ef
+}
3247ef
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
3247ef
index a00efa55f..37a2c4124 100644
3247ef
--- a/src/db/sysdb.h
3247ef
+++ b/src/db/sysdb.h
3247ef
@@ -1532,4 +1532,11 @@ errno_t sysdb_cert_derb64_to_ldap_filter(TALLOC_CTX *mem_ctx,
3247ef
 void ldb_debug_messages(void *context, enum ldb_debug_level level,
3247ef
                         const char *fmt, va_list ap);
3247ef
 
3247ef
+/* Try to detect the object domain from the object's SYSDB_NAME attribute and
3247ef
+ * return the matching sss_domain_info. This should work reliable with user
3247ef
+ * and group objects since fully-qualified names are used here. If the proper
3247ef
+ * domain cannot be detected the given domain is returned. */
3247ef
+struct sss_domain_info *find_domain_by_msg(struct sss_domain_info *dom,
3247ef
+                                           struct ldb_message *msg);
3247ef
+
3247ef
 #endif /* __SYS_DB_H__ */
3247ef
diff --git a/src/responder/nss/nss_protocol_grent.c b/src/responder/nss/nss_protocol_grent.c
3247ef
index 135b392f7..f6e00eb10 100644
3247ef
--- a/src/responder/nss/nss_protocol_grent.c
3247ef
+++ b/src/responder/nss/nss_protocol_grent.c
3247ef
@@ -361,6 +361,7 @@ nss_protocol_fill_initgr(struct nss_ctx *nss_ctx,
3247ef
                          struct cache_req_result *result)
3247ef
 {
3247ef
     struct sss_domain_info *domain;
3247ef
+    struct sss_domain_info *grp_dom;
3247ef
     struct ldb_message *user;
3247ef
     struct ldb_message *msg;
3247ef
     struct ldb_message *primary_group_msg;
3247ef
@@ -418,10 +419,11 @@ nss_protocol_fill_initgr(struct nss_ctx *nss_ctx,
3247ef
     num_results = 0;
3247ef
     for (i = 1; i < result->count; i++) {
3247ef
         msg = result->msgs[i];
3247ef
-        gid = sss_view_ldb_msg_find_attr_as_uint64(domain, msg, SYSDB_GIDNUM,
3247ef
+        grp_dom = find_domain_by_msg(domain, msg);
3247ef
+        gid = sss_view_ldb_msg_find_attr_as_uint64(grp_dom, msg, SYSDB_GIDNUM,
3247ef
                                                    0);
3247ef
         posix = ldb_msg_find_attr_as_string(msg, SYSDB_POSIX, NULL);
3247ef
-        grp_name = sss_view_ldb_msg_find_attr_as_string(domain, msg, SYSDB_NAME,
3247ef
+        grp_name = sss_view_ldb_msg_find_attr_as_string(grp_dom, msg, SYSDB_NAME,
3247ef
                                                         NULL);
3247ef
 
3247ef
         if (gid == 0) {
3247ef
@@ -435,7 +437,7 @@ nss_protocol_fill_initgr(struct nss_ctx *nss_ctx,
3247ef
             }
3247ef
         }
3247ef
 
3247ef
-        if (is_group_filtered(nss_ctx->rctx->ncache, domain, grp_name, gid)) {
3247ef
+        if (is_group_filtered(nss_ctx->rctx->ncache, grp_dom, grp_name, gid)) {
3247ef
             continue;
3247ef
         }
3247ef
 
3247ef
-- 
3247ef
2.26.3
3247ef