dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0144-sysdb-add-parent_dom-to-sysdb_get_direct_parents.patch

9f89df
From b368dca11e715400da64348a17049abf5b072f57 Mon Sep 17 00:00:00 2001
9f89df
From: Sumit Bose <sbose@redhat.com>
9f89df
Date: Tue, 18 Oct 2016 14:59:19 +0200
9f89df
Subject: [PATCH 144/151] sysdb: add parent_dom to sysdb_get_direct_parents()
9f89df
9f89df
Currently sysdb_get_direct_parents() only return direct parents from the
9f89df
same domain as the child object. In setups with sub-domains this might
9f89df
not be sufficient. A new option parent_dom is added which allows to
9f89df
specify a domain the direct parents should be lookup up in. If it is
9f89df
NULL the whole cache is searched.
9f89df
9f89df
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
9f89df
(cherry picked from commit 3dd4c3eca80e9223a65f3318821bd0fb5b45aedd)
9f89df
---
9f89df
 src/db/sysdb.h                             | 21 +++++++++++++++++++++
9f89df
 src/db/sysdb_search.c                      |  7 ++++++-
9f89df
 src/providers/ldap/sdap_async_initgroups.c | 11 +++++++----
9f89df
 3 files changed, 34 insertions(+), 5 deletions(-)
9f89df
9f89df
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
9f89df
index 8713efa6e8fcc6fb620340fe152989a5dae58434..4164657c2b329a240d46fe3ecdfb4b2eefffc5b3 100644
9f89df
--- a/src/db/sysdb.h
9f89df
+++ b/src/db/sysdb.h
9f89df
@@ -1135,8 +1135,29 @@ errno_t sysdb_remove_attrs(struct sss_domain_info *domain,
9f89df
                            enum sysdb_member_type type,
9f89df
                            char **remove_attrs);
9f89df
 
9f89df
+/**
9f89df
+ * @brief Return direct parents of an object in the cache
9f89df
+ *
9f89df
+ * @param[in]  mem_ctx         Memory context the result should be allocated
9f89df
+ *                             on
9f89df
+ * @param[in]  dom             domain the object is in
9f89df
+ * @param[in]  parent_dom      domain which should be searched for direct
9f89df
+ *                             parents if NULL all domains in the given cache
9f89df
+ *                             are searched
9f89df
+ * @param[in]  mtype           Type of the object, SYSDB_MEMBER_USER or
9f89df
+ *                             SYSDB_MEMBER_GROUP
9f89df
+ * @param[in]  name            Name of the object
9f89df
+ * @param[out] _direct_parents List of names of the direct parent groups
9f89df
+ *
9f89df
+ *
9f89df
+ * @return
9f89df
+ *  - EOK:    success
9f89df
+ *  - EINVAL: wrong mtype
9f89df
+ *  - ENOMEM: Memory allocation failed
9f89df
+ */
9f89df
 errno_t sysdb_get_direct_parents(TALLOC_CTX *mem_ctx,
9f89df
                                  struct sss_domain_info *dom,
9f89df
+                                 struct sss_domain_info *parent_dom,
9f89df
                                  enum sysdb_member_type mtype,
9f89df
                                  const char *name,
9f89df
                                  char ***_direct_parents);
9f89df
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
9f89df
index cfee5784dbadd692f30d0758e7e5c3c9fb2814cb..4d63c3838a49392bbf2a57aeb6f7740f4d4fbdcd 100644
9f89df
--- a/src/db/sysdb_search.c
9f89df
+++ b/src/db/sysdb_search.c
9f89df
@@ -1981,6 +1981,7 @@ done:
9f89df
 
9f89df
 errno_t sysdb_get_direct_parents(TALLOC_CTX *mem_ctx,
9f89df
                                  struct sss_domain_info *dom,
9f89df
+                                 struct sss_domain_info *parent_dom,
9f89df
                                  enum sysdb_member_type mtype,
9f89df
                                  const char *name,
9f89df
                                  char ***_direct_parents)
9f89df
@@ -2029,7 +2030,11 @@ errno_t sysdb_get_direct_parents(TALLOC_CTX *mem_ctx,
9f89df
         goto done;
9f89df
     }
9f89df
 
9f89df
-    basedn = sysdb_group_base_dn(tmp_ctx, dom);
9f89df
+    if (parent_dom == NULL) {
9f89df
+        basedn = sysdb_base_dn(dom->sysdb, tmp_ctx);
9f89df
+    } else {
9f89df
+        basedn = sysdb_group_base_dn(tmp_ctx, parent_dom);
9f89df
+    }
9f89df
     if (!basedn) {
9f89df
         ret = ENOMEM;
9f89df
         goto done;
9f89df
diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c
9f89df
index f9593f0dfaa2dc6e33fd6c9d1f0c9b78cad3a1d9..77324d0ee9eb2ad2fc35c2098d6c9c23a62747c9 100644
9f89df
--- a/src/providers/ldap/sdap_async_initgroups.c
9f89df
+++ b/src/providers/ldap/sdap_async_initgroups.c
9f89df
@@ -1301,7 +1301,8 @@ sdap_initgr_store_user_memberships(struct sdap_initgr_nested_state *state)
9f89df
         }
9f89df
     }
9f89df
 
9f89df
-    ret = sysdb_get_direct_parents(tmp_ctx, state->dom, SYSDB_MEMBER_USER,
9f89df
+    ret = sysdb_get_direct_parents(tmp_ctx, state->dom, state->dom,
9f89df
+                                   SYSDB_MEMBER_USER,
9f89df
                                    state->username, &sysdb_parent_name_list);
9f89df
     if (ret) {
9f89df
         DEBUG(SSSDBG_CRIT_FAILURE,
9f89df
@@ -1388,7 +1389,7 @@ sdap_initgr_nested_get_membership_diff(TALLOC_CTX *mem_ctx,
9f89df
         goto done;
9f89df
     }
9f89df
 
9f89df
-    ret = sysdb_get_direct_parents(tmp_ctx, dom, SYSDB_MEMBER_GROUP,
9f89df
+    ret = sysdb_get_direct_parents(tmp_ctx, dom, dom, SYSDB_MEMBER_GROUP,
9f89df
                                    group_name, &sysdb_parents_names_list);
9f89df
     if (ret) {
9f89df
         DEBUG(SSSDBG_CRIT_FAILURE,
9f89df
@@ -2070,7 +2071,8 @@ rfc2307bis_group_memberships_build(hash_entry_t *item, void *user_data)
9f89df
         goto done;
9f89df
     }
9f89df
 
9f89df
-    ret = sysdb_get_direct_parents(tmp_ctx, mstate->dom, SYSDB_MEMBER_GROUP,
9f89df
+    ret = sysdb_get_direct_parents(tmp_ctx, mstate->dom, mstate->dom,
9f89df
+                                   SYSDB_MEMBER_GROUP,
9f89df
                                    group_name, &sysdb_parents_names_list);
9f89df
     if (ret) {
9f89df
         DEBUG(SSSDBG_CRIT_FAILURE,
9f89df
@@ -2130,7 +2132,8 @@ errno_t save_rfc2307bis_user_memberships(
9f89df
     }
9f89df
     in_transaction = true;
9f89df
 
9f89df
-    ret = sysdb_get_direct_parents(tmp_ctx, state->dom, SYSDB_MEMBER_USER,
9f89df
+    ret = sysdb_get_direct_parents(tmp_ctx, state->dom, state->dom,
9f89df
+                                   SYSDB_MEMBER_USER,
9f89df
                                    state->name, &sysdb_parent_name_list);
9f89df
     if (ret) {
9f89df
         DEBUG(SSSDBG_CRIT_FAILURE,
9f89df
-- 
9f89df
2.7.4
9f89df