Blame SOURCES/0035-SDAP-Detect-schemaNamingContext-from-the-rootDSE.patch

cdf651
From bf4580b2f893cfb29d804a9fe6bb2d6247bb5cf2 Mon Sep 17 00:00:00 2001
cdf651
From: Jakub Hrozek <jhrozek@redhat.com>
cdf651
Date: Sun, 8 Jul 2018 22:17:41 +0200
cdf651
Subject: [PATCH] SDAP: Detect schemaNamingContext from the rootDSE
cdf651
MIME-Version: 1.0
cdf651
Content-Type: text/plain; charset=UTF-8
cdf651
Content-Transfer-Encoding: 8bit
cdf651
cdf651
Whether an attribute is replicated to the Global Catalog or not can be
cdf651
detected by checking the value of the isMemberOfPartialAttributeSet
cdf651
attribute:
cdf651
https://docs.microsoft.com/en-us/windows/desktop/ADSchema/a-ismemberofpartialattributeset
cdf651
cdf651
This attribute is present in all objects with the objectClass
cdf651
attributeSchema in AD:
cdf651
https://docs.microsoft.com/en-us/windows/desktop/AD/characteristics-of-attributes
cdf651
cdf651
And finally, the attributeSchema objects in AD are present in a schema
cdf651
naming context. The schema naming context is replicated to all DCs in the
cdf651
forest even though their own naming context might be different:
cdf651
https://docs.microsoft.com/en-us/windows/desktop/ad/naming-contexts-and-partitions
cdf651
cdf651
Where the schema naming context is located is given by the
cdf651
schemaNamingContext attribute of the rootDSE.
cdf651
cdf651
This patch is trivial on its own and just reads schemaNamingContext from
cdf651
the rootDSE and stores it in the sdap_options structure for later use.
cdf651
cdf651
Related:
cdf651
https://pagure.io/SSSD/sssd/issue/3755
cdf651
cdf651
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
cdf651
(cherry picked from commit c8d1c1b734a1763b3e1233f060cc5c8d6db078e9)
cdf651
---
cdf651
 src/providers/ldap/sdap.c | 10 ++++++++++
cdf651
 src/providers/ldap/sdap.h |  3 +++
cdf651
 2 files changed, 13 insertions(+)
cdf651
cdf651
diff --git a/src/providers/ldap/sdap.c b/src/providers/ldap/sdap.c
cdf651
index 0241a99e49e94345753399d5d62639c99b95ee77..5c9d0a45dfb96e8901467aa6a3391b8df84f6d42 100644
cdf651
--- a/src/providers/ldap/sdap.c
cdf651
+++ b/src/providers/ldap/sdap.c
cdf651
@@ -1284,6 +1284,7 @@ int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx,
cdf651
     const char *last_usn_name;
cdf651
     const char *last_usn_value;
cdf651
     const char *entry_usn_name;
cdf651
+    const char *schema_nc = NULL;
cdf651
     char *endptr = NULL;
cdf651
     int ret;
cdf651
     int i;
cdf651
@@ -1400,6 +1401,15 @@ int sdap_get_server_opts_from_rootdse(TALLOC_CTX *memctx,
cdf651
                    "(%s). Continuing without AD performance enhancements\n",
cdf651
                    strerror(ret));
cdf651
         }
cdf651
+
cdf651
+        ret = sysdb_attrs_get_string(rootdse,
cdf651
+                                     SDAP_ROOTDSE_ATTR_AD_SCHEMA_NC,
cdf651
+                                     &schema_nc);
cdf651
+        if (ret == EOK) {
cdf651
+            DEBUG(SSSDBG_CONF_SETTINGS,
cdf651
+                  "Will look for schema at [%s]\n", schema_nc);
cdf651
+            opts->schema_basedn = talloc_strdup(opts, schema_nc);
cdf651
+        }
cdf651
     }
cdf651
 
cdf651
     if (!last_usn_name) {
cdf651
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
cdf651
index 0790544818633e26ee5a8fbdca556b8230b1df3f..31c25c32f059b4290a7511600cee638ee7a269e8 100644
cdf651
--- a/src/providers/ldap/sdap.h
cdf651
+++ b/src/providers/ldap/sdap.h
cdf651
@@ -130,6 +130,7 @@ struct sdap_ppolicy_data {
cdf651
 #define SDAP_ROOTDSE_ATTR_NAMING_CONTEXTS "namingContexts"
cdf651
 #define SDAP_ROOTDSE_ATTR_DEFAULT_NAMING_CONTEXT "defaultNamingContext"
cdf651
 #define SDAP_ROOTDSE_ATTR_AD_VERSION "domainControllerFunctionality"
cdf651
+#define SDAP_ROOTDSE_ATTR_AD_SCHEMA_NC "schemaNamingContext"
cdf651
 
cdf651
 #define SDAP_IPA_USN "entryUSN"
cdf651
 #define SDAP_IPA_LAST_USN "lastUSN"
cdf651
@@ -496,8 +497,10 @@ struct sdap_options {
cdf651
     /* The search bases for the domain or its subdomain */
cdf651
     struct sdap_domain *sdom;
cdf651
 
cdf651
+    /* The options below are normally only used with AD */
cdf651
     bool support_matching_rule;
cdf651
     enum dc_functional_level dc_functional_level;
cdf651
+    const char *schema_basedn;
cdf651
 
cdf651
     /* Certificate mapping support */
cdf651
     struct sdap_certmap_ctx *sdap_certmap_ctx;
cdf651
-- 
cdf651
2.17.1
cdf651