Blame SOURCES/0080-AD-Set-ignore_mark_offline-false-when-resolving-AD-r.patch

6cf099
From d89c2dc276a8974b20a77b54ba663d4a1fa5acd2 Mon Sep 17 00:00:00 2001
6cf099
From: Jakub Hrozek <jhrozek@redhat.com>
6cf099
Date: Wed, 2 Sep 2015 12:10:03 +0000
6cf099
Subject: [PATCH 80/87] AD: Set ignore_mark_offline=false when resolving AD
6cf099
 root domain
6cf099
MIME-Version: 1.0
6cf099
Content-Type: text/plain; charset=UTF-8
6cf099
Content-Transfer-Encoding: 8bit
6cf099
6cf099
https://fedorahosted.org/sssd/ticket/2637
6cf099
6cf099
Avoid going offline in cases where SSSD is connected to a child domain
6cf099
but the root domain is not accessible.
6cf099
6cf099
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
6cf099
(cherry picked from commit ece345a74cec793e6d970a4955beb3d4a05935b3)
6cf099
---
6cf099
 src/providers/ad/ad_subdomains.c | 56 +++++++++++++++++++++++-----------------
6cf099
 1 file changed, 33 insertions(+), 23 deletions(-)
6cf099
6cf099
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
6cf099
index d1d468043410c80e6bf7f0f48a13bd9e962552af..8ed3dab0995f78a16f4a7df2e729ea88a39a782c 100644
6cf099
--- a/src/providers/ad/ad_subdomains.c
6cf099
+++ b/src/providers/ad/ad_subdomains.c
6cf099
@@ -80,7 +80,8 @@ struct ad_subdomains_req_ctx {
6cf099
     struct ad_id_ctx *root_id_ctx;
6cf099
     struct sdap_id_op *root_op;
6cf099
     size_t root_base_iter;
6cf099
-    struct sysdb_attrs *root_domain;
6cf099
+    struct sysdb_attrs *root_domain_attrs;
6cf099
+    struct sss_domain_info *root_domain;
6cf099
 
6cf099
     size_t reply_count;
6cf099
     struct sysdb_attrs **reply;
6cf099
@@ -689,6 +690,7 @@ static errno_t ad_subdomains_get_root(struct ad_subdomains_req_ctx *ctx)
6cf099
     return EAGAIN;
6cf099
 }
6cf099
 
6cf099
+static struct sss_domain_info *ads_get_root_domain(struct ad_subdomains_req_ctx *ctx);
6cf099
 static struct ad_id_ctx *ads_get_root_id_ctx(struct ad_subdomains_req_ctx *ctx);
6cf099
 static void ad_subdomains_root_conn_done(struct tevent_req *req);
6cf099
 
6cf099
@@ -769,7 +771,14 @@ static void ad_subdomains_get_root_domain_done(struct tevent_req *req)
6cf099
         }
6cf099
     }
6cf099
 
6cf099
-    ctx->root_domain = reply[0];
6cf099
+    ctx->root_domain_attrs = reply[0];
6cf099
+    ctx->root_domain = ads_get_root_domain(ctx);
6cf099
+    if (ctx->root_domain == NULL) {
6cf099
+        DEBUG(SSSDBG_OP_FAILURE, "Could not find the root domain\n");
6cf099
+        ret = EFAULT;
6cf099
+        goto fail;
6cf099
+    }
6cf099
+
6cf099
     ctx->root_id_ctx = ads_get_root_id_ctx(ctx);
6cf099
     if (ctx->root_id_ctx == NULL) {
6cf099
         DEBUG(SSSDBG_OP_FAILURE, "Cannot create id ctx for the root domain\n");
6cf099
@@ -803,15 +812,13 @@ fail:
6cf099
     be_req_terminate(ctx->be_req, dp_error, ret, NULL);
6cf099
 }
6cf099
 
6cf099
-static struct ad_id_ctx *ads_get_root_id_ctx(struct ad_subdomains_req_ctx *ctx)
6cf099
+static struct sss_domain_info *ads_get_root_domain(struct ad_subdomains_req_ctx *ctx)
6cf099
 {
6cf099
     errno_t ret;
6cf099
     const char *name;
6cf099
     struct sss_domain_info *root;
6cf099
-    struct sdap_domain *sdom;
6cf099
-    struct ad_id_ctx *root_id_ctx;
6cf099
 
6cf099
-    ret = sysdb_attrs_get_string(ctx->root_domain, AD_AT_TRUST_PARTNER, &name);
6cf099
+    ret = sysdb_attrs_get_string(ctx->root_domain_attrs, AD_AT_TRUST_PARTNER, &name);
6cf099
     if (ret != EOK) {
6cf099
         DEBUG(SSSDBG_OP_FAILURE, "sysdb_attrs_get_string failed.\n");
6cf099
         return NULL;
6cf099
@@ -820,32 +827,40 @@ static struct ad_id_ctx *ads_get_root_id_ctx(struct ad_subdomains_req_ctx *ctx)
6cf099
     /* With a subsequent run, the root should already be known */
6cf099
     root = find_domain_by_name(ctx->sd_ctx->be_ctx->domain,
6cf099
                                name, false);
6cf099
-    if (root == NULL) {
6cf099
-        DEBUG(SSSDBG_OP_FAILURE, "Could not find the root domain\n");
6cf099
-        return NULL;
6cf099
-    }
6cf099
 
6cf099
-    sdom = sdap_domain_get(ctx->sd_ctx->ad_id_ctx->sdap_id_ctx->opts, root);
6cf099
+    return root;
6cf099
+}
6cf099
+
6cf099
+static struct ad_id_ctx *ads_get_root_id_ctx(struct ad_subdomains_req_ctx *ctx)
6cf099
+{
6cf099
+    errno_t ret;
6cf099
+    struct sdap_domain *sdom;
6cf099
+    struct ad_id_ctx *root_id_ctx;
6cf099
+
6cf099
+    sdom = sdap_domain_get(ctx->sd_ctx->ad_id_ctx->sdap_id_ctx->opts,
6cf099
+                           ctx->root_domain);
6cf099
     if (sdom == NULL) {
6cf099
         DEBUG(SSSDBG_OP_FAILURE,
6cf099
-              "Cannot get the sdom for %s!\n", root->name);
6cf099
+              "Cannot get the sdom for %s!\n", ctx->root_domain->name);
6cf099
         return NULL;
6cf099
     }
6cf099
 
6cf099
     if (sdom->pvt == NULL) {
6cf099
         ret = ad_subdom_ad_ctx_new(ctx->sd_ctx->be_ctx,
6cf099
                                    ctx->sd_ctx->ad_id_ctx,
6cf099
-                                   root,
6cf099
+                                   ctx->root_domain,
6cf099
                                    &root_id_ctx);
6cf099
         if (ret != EOK) {
6cf099
             DEBUG(SSSDBG_OP_FAILURE, "ad_subdom_ad_ctx_new failed.\n");
6cf099
             return NULL;
6cf099
         }
6cf099
+
6cf099
         sdom->pvt = root_id_ctx;
6cf099
     } else {
6cf099
         root_id_ctx = sdom->pvt;
6cf099
     }
6cf099
 
6cf099
+    root_id_ctx->ldap_ctx->ignore_mark_offline = true;
6cf099
     return root_id_ctx;
6cf099
 }
6cf099
 
6cf099
@@ -860,16 +875,11 @@ static void ad_subdomains_root_conn_done(struct tevent_req *req)
6cf099
     ret = sdap_id_op_connect_recv(req, &dp_error);
6cf099
     talloc_zfree(req);
6cf099
     if (ret) {
6cf099
-        if (dp_error == DP_ERR_OFFLINE) {
6cf099
-            DEBUG(SSSDBG_MINOR_FAILURE,
6cf099
-                  "No AD server is available, cannot get the "
6cf099
-                  "subdomain list while offline\n");
6cf099
-        } else {
6cf099
-            DEBUG(SSSDBG_OP_FAILURE,
6cf099
-                  "Failed to connect to AD server: [%d](%s)\n",
6cf099
-                  ret, strerror(ret));
6cf099
-        }
6cf099
+        be_mark_dom_offline(ctx->root_domain, be_req_get_be_ctx(ctx->be_req));
6cf099
 
6cf099
+        DEBUG(SSSDBG_OP_FAILURE,
6cf099
+              "Failed to connect to AD server: [%d](%s)\n",
6cf099
+              ret, strerror(ret));
6cf099
         goto fail;
6cf099
     }
6cf099
 
6cf099
@@ -1040,7 +1050,7 @@ static void ad_subdomains_get_slave_domain_done(struct tevent_req *req)
6cf099
      */
6cf099
     ret = ad_subdomains_process(ctx, ctx->sd_ctx->be_ctx->domain,
6cf099
                                 ctx->reply_count, ctx->reply,
6cf099
-                                ctx->root_domain, &nsubdoms, &subdoms);
6cf099
+                                ctx->root_domain_attrs, &nsubdoms, &subdoms);
6cf099
     if (ret != EOK) {
6cf099
         DEBUG(SSSDBG_OP_FAILURE, ("Cannot process subdomain list\n"));
6cf099
         tevent_req_error(req, ret);
6cf099
-- 
6cf099
2.4.3
6cf099