Blame SOURCES/0116-ad-handle-forest-root-not-listed-in-ad_enabled_domai.patch

bb7cd1
From 5ca331e80520035d7de2680cd2803fa508d15287 Mon Sep 17 00:00:00 2001
bb7cd1
From: Sumit Bose <sbose@redhat.com>
bb7cd1
Date: Mon, 3 Apr 2017 21:27:32 +0200
bb7cd1
Subject: [PATCH 116/118] ad: handle forest root not listed in
bb7cd1
 ad_enabled_domains
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
Although users and groups from the forest root should be ignored SSSD
bb7cd1
will still try to get information about the forest topology from a DC
bb7cd1
from the forest root. So even if the forest root domain is disabled we
bb7cd1
should makes sure it is usable for those searches.
bb7cd1
bb7cd1
Resolves https://pagure.io/SSSD/sssd/issue/3361
bb7cd1
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
(cherry picked from commit feeabf273aa7af580552366ce58655e6a482a0cd)
bb7cd1
---
bb7cd1
 src/providers/ad/ad_subdomains.c | 39 ++++++++++++++++++++++++++++++++++++---
bb7cd1
 1 file changed, 36 insertions(+), 3 deletions(-)
bb7cd1
bb7cd1
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
bb7cd1
index bc659b2cb0a02723437d24d0021ec3592381e84c..ef166446e837c3f7cd824c1abf4b5cc587aec9da 100644
bb7cd1
--- a/src/providers/ad/ad_subdomains.c
bb7cd1
+++ b/src/providers/ad/ad_subdomains.c
bb7cd1
@@ -433,6 +433,14 @@ static errno_t ad_subdomains_refresh(struct be_ctx *be_ctx,
bb7cd1
         if (c >= num_subdomains) {
bb7cd1
             /* ok this subdomain does not exist anymore, let's clean up */
bb7cd1
             sss_domain_set_state(dom, DOM_DISABLED);
bb7cd1
+
bb7cd1
+            /* Just disable the forest root but do not remove sdap data */
bb7cd1
+            if (sss_domain_is_forest_root(dom)) {
bb7cd1
+                DEBUG(SSSDBG_TRACE_ALL,
bb7cd1
+                      "Skipping removal of forest root sdap data.\n");
bb7cd1
+                continue;
bb7cd1
+            }
bb7cd1
+
bb7cd1
             ret = sysdb_subdomain_delete(dom->sysdb, dom->name);
bb7cd1
             if (ret != EOK) {
bb7cd1
                 goto done;
bb7cd1
@@ -633,6 +641,7 @@ static errno_t ad_subdom_reinit(struct ad_subdomains_ctx *subdoms_ctx)
bb7cd1
     const char *path;
bb7cd1
     errno_t ret;
bb7cd1
     bool canonicalize = false;
bb7cd1
+    struct sss_domain_info *dom;
bb7cd1
 
bb7cd1
     path = dp_opt_get_string(subdoms_ctx->ad_id_ctx->ad_options->basic,
bb7cd1
                              AD_KRB5_CONFD_PATH);
bb7cd1
@@ -675,6 +684,17 @@ static errno_t ad_subdom_reinit(struct ad_subdomains_ctx *subdoms_ctx)
bb7cd1
         return ret;
bb7cd1
     }
bb7cd1
 
bb7cd1
+    /* Make sure disabled domains are not re-enabled accidentially */
bb7cd1
+    if (subdoms_ctx->ad_enabled_domains != NULL) {
bb7cd1
+        for (dom = subdoms_ctx->be_ctx->domain->subdomains; dom;
bb7cd1
+                                            dom = get_next_domain(dom, false)) {
bb7cd1
+            if (!is_domain_enabled(dom->name,
bb7cd1
+                                   subdoms_ctx->ad_enabled_domains)) {
bb7cd1
+                sss_domain_set_state(dom, DOM_DISABLED);
bb7cd1
+            }
bb7cd1
+        }
bb7cd1
+    }
bb7cd1
+
bb7cd1
     return EOK;
bb7cd1
 }
bb7cd1
 
bb7cd1
@@ -898,7 +918,7 @@ static errno_t ad_get_slave_domain_recv(struct tevent_req *req)
bb7cd1
 static struct sss_domain_info *
bb7cd1
 ads_get_root_domain(struct be_ctx *be_ctx, struct sysdb_attrs *attrs)
bb7cd1
 {
bb7cd1
-    struct sss_domain_info *root;
bb7cd1
+    struct sss_domain_info *dom;
bb7cd1
     const char *name;
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
@@ -909,9 +929,22 @@ ads_get_root_domain(struct be_ctx *be_ctx, struct sysdb_attrs *attrs)
bb7cd1
     }
bb7cd1
 
bb7cd1
     /* With a subsequent run, the root should already be known */
bb7cd1
-    root = find_domain_by_name(be_ctx->domain, name, false);
bb7cd1
+    for (dom = be_ctx->domain; dom != NULL;
bb7cd1
+         dom = get_next_domain(dom, SSS_GND_ALL_DOMAINS)) {
bb7cd1
 
bb7cd1
-    return root;
bb7cd1
+        if (strcasecmp(dom->name, name) == 0) {
bb7cd1
+            /* The forest root is special, although it might be disabled for
bb7cd1
+             * general lookups we still want to try to get the domains in the
bb7cd1
+             * forest from a DC of the forest root */
bb7cd1
+            if (sss_domain_get_state(dom) == DOM_DISABLED
bb7cd1
+                    && !sss_domain_is_forest_root(dom)) {
bb7cd1
+                return NULL;
bb7cd1
+            }
bb7cd1
+            return dom;
bb7cd1
+        }
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    return NULL;
bb7cd1
 }
bb7cd1
 
bb7cd1
 static struct ad_id_ctx *
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1