dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0105-RESPONDER-Fallback-to-global-domain-resolution-order.patch

bb7cd1
From b7d2310e9ddd79bfdea2bc334bd11d4df9be37a2 Mon Sep 17 00:00:00 2001
bb7cd1
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
bb7cd1
Date: Wed, 12 Apr 2017 10:43:25 +0200
bb7cd1
Subject: [PATCH 105/110] RESPONDER: Fallback to global domain resolution order
bb7cd1
 in case the view doesn't have this option set
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
The current code has been ignoring the domain resolution order set
bb7cd1
globally on IPA in case there's a view but this doesn't have any domain
bb7cd1
resolution order set.
bb7cd1
bb7cd1
It happens because we haven't been checking whether the view attribute
bb7cd1
didn't exist and then we ended up populating the list cache_req domains'
bb7cd1
list assuming that no order has been set instead of falling back to the
bb7cd1
next preferred method.
bb7cd1
bb7cd1
Related:
bb7cd1
https://pagure.io/SSSD/sssd/issue/3001
bb7cd1
bb7cd1
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
bb7cd1
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
(cherry picked from commit a3faad0e4dc1ca4473746c3822ecfc5aed876e6d)
bb7cd1
---
bb7cd1
 src/responder/common/cache_req/cache_req_domain.c |  14 ++-
bb7cd1
 src/responder/common/cache_req/cache_req_domain.h |   5 +-
bb7cd1
 src/responder/common/responder_common.c           | 108 +++++++++++++---------
bb7cd1
 3 files changed, 74 insertions(+), 53 deletions(-)
bb7cd1
bb7cd1
diff --git a/src/responder/common/cache_req/cache_req_domain.c b/src/responder/common/cache_req/cache_req_domain.c
bb7cd1
index bbabd695f1c6b6c29b7e61f571382ab9adfb0ea2..86a88efd54ca0f4a0748b44ece1b8515438d4628 100644
bb7cd1
--- a/src/responder/common/cache_req/cache_req_domain.c
bb7cd1
+++ b/src/responder/common/cache_req/cache_req_domain.c
bb7cd1
@@ -120,20 +120,21 @@ done:
bb7cd1
     return cr_domains;
bb7cd1
 }
bb7cd1
 
bb7cd1
-struct cache_req_domain *
bb7cd1
+errno_t
bb7cd1
 cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
                                         TALLOC_CTX *mem_ctx,
bb7cd1
                                         struct sss_domain_info *domains,
bb7cd1
-                                        const char *domain_resolution_order)
bb7cd1
+                                        const char *domain_resolution_order,
bb7cd1
+                                        struct cache_req_domain **_cr_domains)
bb7cd1
 {
bb7cd1
     TALLOC_CTX *tmp_ctx;
bb7cd1
-    struct cache_req_domain *cr_domains = NULL;
bb7cd1
+    struct cache_req_domain *cr_domains;
bb7cd1
     char **list = NULL;
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
     tmp_ctx = talloc_new(NULL);
bb7cd1
     if (tmp_ctx == NULL) {
bb7cd1
-        return NULL;
bb7cd1
+        return ENOMEM;
bb7cd1
     }
bb7cd1
 
bb7cd1
     if (domain_resolution_order != NULL) {
bb7cd1
@@ -160,7 +161,10 @@ cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
+    *_cr_domains = cr_domains;
bb7cd1
+    ret = EOK;
bb7cd1
+
bb7cd1
 done:
bb7cd1
     talloc_free(tmp_ctx);
bb7cd1
-    return cr_domains;
bb7cd1
+    return ret;
bb7cd1
 }
bb7cd1
diff --git a/src/responder/common/cache_req/cache_req_domain.h b/src/responder/common/cache_req/cache_req_domain.h
bb7cd1
index 41c50e8c293d7b032cb2f05482c40e93e4f723dc..000087e5ca2074f22169a4af627810f4f287e430 100644
bb7cd1
--- a/src/responder/common/cache_req/cache_req_domain.h
bb7cd1
+++ b/src/responder/common/cache_req/cache_req_domain.h
bb7cd1
@@ -34,11 +34,12 @@ struct cache_req_domain *
bb7cd1
 cache_req_domain_get_domain_by_name(struct cache_req_domain *domains,
bb7cd1
                                     const char *name);
bb7cd1
 
bb7cd1
-struct cache_req_domain *
bb7cd1
+errno_t
bb7cd1
 cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
                                         TALLOC_CTX *mem_ctx,
bb7cd1
                                         struct sss_domain_info *domains,
bb7cd1
-                                        const char *domain_resolution_order);
bb7cd1
+                                        const char *domain_resolution_order,
bb7cd1
+                                        struct cache_req_domain **_cr_domains);
bb7cd1
 
bb7cd1
 void cache_req_domain_list_zfree(struct cache_req_domain **cr_domains);
bb7cd1
 
bb7cd1
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
bb7cd1
index ac6320b08de09bc6c7e8dd1af72e0a493a449f7a..62b71b5104fdbb585d086d44d2ca2ab9717dd788 100644
bb7cd1
--- a/src/responder/common/responder_common.c
bb7cd1
+++ b/src/responder/common/responder_common.c
bb7cd1
@@ -1486,10 +1486,11 @@ fail:
bb7cd1
 }
bb7cd1
 
bb7cd1
 /* ====== Helper functions for the domain resolution order ======= */
bb7cd1
-static struct cache_req_domain *
bb7cd1
+static errno_t
bb7cd1
 sss_resp_new_cr_domains_from_ipa_id_view(TALLOC_CTX *mem_ctx,
bb7cd1
                                          struct sss_domain_info *domains,
bb7cd1
-                                         struct sysdb_ctx *sysdb)
bb7cd1
+                                         struct sysdb_ctx *sysdb,
bb7cd1
+                                         struct cache_req_domain **_cr_domains)
bb7cd1
 {
bb7cd1
     TALLOC_CTX *tmp_ctx;
bb7cd1
     struct cache_req_domain *cr_domains = NULL;
bb7cd1
@@ -1498,7 +1499,7 @@ sss_resp_new_cr_domains_from_ipa_id_view(TALLOC_CTX *mem_ctx,
bb7cd1
 
bb7cd1
     tmp_ctx = talloc_new(NULL);
bb7cd1
     if (tmp_ctx == NULL) {
bb7cd1
-        return NULL;
bb7cd1
+        return ENOMEM;
bb7cd1
     }
bb7cd1
 
bb7cd1
     ret = sysdb_get_view_domain_resolution_order(tmp_ctx, sysdb,
bb7cd1
@@ -1510,12 +1511,13 @@ sss_resp_new_cr_domains_from_ipa_id_view(TALLOC_CTX *mem_ctx,
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    /* Using mem_ctx (which is rctx) directly here to avoid copying
bb7cd1
-     * this memory around. */
bb7cd1
-    cr_domains = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
-                                    mem_ctx, domains, domain_resolution_order);
bb7cd1
-    if (cr_domains == NULL) {
bb7cd1
-        ret = ENOMEM;
bb7cd1
+    if (ret == ENOENT) {
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
+                        mem_ctx, domains, domain_resolution_order, &cr_domains);
bb7cd1
+    if (ret != EOK) {
bb7cd1
         DEBUG(SSSDBG_DEFAULT,
bb7cd1
               "cache_req_domain_new_list_from_domain_resolution_order() "
bb7cd1
               "failed [%d]: [%s].\n",
bb7cd1
@@ -1523,25 +1525,31 @@ sss_resp_new_cr_domains_from_ipa_id_view(TALLOC_CTX *mem_ctx,
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
+    *_cr_domains = cr_domains;
bb7cd1
+
bb7cd1
+    ret = EOK;
bb7cd1
+
bb7cd1
 done:
bb7cd1
     talloc_free(tmp_ctx);
bb7cd1
-    return cr_domains;
bb7cd1
+    return ret;
bb7cd1
 }
bb7cd1
 
bb7cd1
-static struct cache_req_domain *
bb7cd1
+static errno_t
bb7cd1
 sss_resp_new_cr_domains_from_ipa_config(TALLOC_CTX *mem_ctx,
bb7cd1
                                         struct sss_domain_info *domains,
bb7cd1
                                         struct sysdb_ctx *sysdb,
bb7cd1
-                                        const char *domain)
bb7cd1
+                                        const char *domain,
bb7cd1
+                                        struct cache_req_domain **_cr_domains)
bb7cd1
 {
bb7cd1
     TALLOC_CTX *tmp_ctx;
bb7cd1
-    struct cache_req_domain *cr_domains = NULL;
bb7cd1
     const char *domain_resolution_order = NULL;
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
+    *_cr_domains = NULL;
bb7cd1
+
bb7cd1
     tmp_ctx = talloc_new(NULL);
bb7cd1
     if (tmp_ctx == NULL) {
bb7cd1
-        return NULL;
bb7cd1
+        return ENOMEM;
bb7cd1
     }
bb7cd1
 
bb7cd1
     ret = sysdb_domain_get_domain_resolution_order(tmp_ctx, sysdb, domain,
bb7cd1
@@ -1554,11 +1562,13 @@ sss_resp_new_cr_domains_from_ipa_config(TALLOC_CTX *mem_ctx,
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    /* Using mem_ctx (which is rctx) directly here to avoid copying
bb7cd1
-     * this memory around. */
bb7cd1
-    cr_domains = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
-                                    mem_ctx, domains, domain_resolution_order);
bb7cd1
-    if (cr_domains == NULL) {
bb7cd1
+    if (ret == ENOENT) {
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
+                        mem_ctx, domains, domain_resolution_order, _cr_domains);
bb7cd1
+    if (ret != EOK) {
bb7cd1
         DEBUG(SSSDBG_DEFAULT,
bb7cd1
               "cache_req_domain_new_list_from_domain_resolution_order() "
bb7cd1
               "failed [%d]: [%s].\n",
bb7cd1
@@ -1566,9 +1576,11 @@ sss_resp_new_cr_domains_from_ipa_config(TALLOC_CTX *mem_ctx,
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
+    ret = EOK;
bb7cd1
+
bb7cd1
 done:
bb7cd1
     talloc_free(tmp_ctx);
bb7cd1
-    return cr_domains;
bb7cd1
+    return ret;
bb7cd1
 }
bb7cd1
 
bb7cd1
 errno_t sss_resp_populate_cr_domains(struct resp_ctx *rctx)
bb7cd1
@@ -1578,16 +1590,16 @@ errno_t sss_resp_populate_cr_domains(struct resp_ctx *rctx)
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
     if (rctx->domain_resolution_order != NULL) {
bb7cd1
-        cr_domains = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
-                            rctx, rctx->domains, rctx->domain_resolution_order);
bb7cd1
-
bb7cd1
-        if (cr_domains == NULL) {
bb7cd1
+        ret = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
+                rctx, rctx->domains,
bb7cd1
+                rctx->domain_resolution_order, &cr_domains);
bb7cd1
+        if (ret == EOK) {
bb7cd1
+            goto done;
bb7cd1
+        } else {
bb7cd1
             DEBUG(SSSDBG_MINOR_FAILURE,
bb7cd1
                   "Failed to use domain_resolution_order set in the config file.\n"
bb7cd1
                   "Trying to fallback to use ipaDomainOrderResolution setup by "
bb7cd1
                   "IPA.\n");
bb7cd1
-        } else {
bb7cd1
-            goto done;
bb7cd1
         }
bb7cd1
     }
bb7cd1
 
bb7cd1
@@ -1598,9 +1610,9 @@ errno_t sss_resp_populate_cr_domains(struct resp_ctx *rctx)
bb7cd1
     }
bb7cd1
 
bb7cd1
     if (dom == NULL) {
bb7cd1
-        cr_domains = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
-                                                    rctx, rctx->domains, NULL);
bb7cd1
-        if (cr_domains == NULL) {
bb7cd1
+        ret = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
+                                        rctx, rctx->domains, NULL, &cr_domains);
bb7cd1
+        if (ret != EOK) {
bb7cd1
             DEBUG(SSSDBG_CRIT_FAILURE,
bb7cd1
                   "Failed to flatten the list of domains.\n");
bb7cd1
         }
bb7cd1
@@ -1608,44 +1620,48 @@ errno_t sss_resp_populate_cr_domains(struct resp_ctx *rctx)
bb7cd1
     }
bb7cd1
 
bb7cd1
     if (dom->has_views) {
bb7cd1
-        cr_domains = sss_resp_new_cr_domains_from_ipa_id_view(rctx,
bb7cd1
-                                                              rctx->domains,
bb7cd1
-                                                              dom->sysdb);
bb7cd1
-        if (cr_domains == NULL) {
bb7cd1
+        ret = sss_resp_new_cr_domains_from_ipa_id_view(rctx, rctx->domains,
bb7cd1
+                                                       dom->sysdb,
bb7cd1
+                                                       &cr_domains);
bb7cd1
+        if (ret == EOK) {
bb7cd1
+            goto done;
bb7cd1
+        }
bb7cd1
+
bb7cd1
+        if (ret != ENOENT) {
bb7cd1
             DEBUG(SSSDBG_MINOR_FAILURE,
bb7cd1
                   "Failed to use ipaDomainResolutionOrder set for the "
bb7cd1
                   "view \"%s\".\n"
bb7cd1
                   "Trying to fallback to use ipaDomainOrderResolution "
bb7cd1
                   "set in ipaConfig for the domain: %s.\n",
bb7cd1
                   dom->view_name, dom->name);
bb7cd1
-        } else {
bb7cd1
-            goto done;
bb7cd1
         }
bb7cd1
     }
bb7cd1
 
bb7cd1
-    cr_domains = sss_resp_new_cr_domains_from_ipa_config(rctx, rctx->domains,
bb7cd1
-                                                         dom->sysdb,
bb7cd1
-                                                         dom->name);
bb7cd1
-    if (cr_domains == NULL) {
bb7cd1
+    ret = sss_resp_new_cr_domains_from_ipa_config(rctx, rctx->domains,
bb7cd1
+                                                  dom->sysdb, dom->name,
bb7cd1
+                                                  &cr_domains);
bb7cd1
+    if (ret == EOK) {
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    if (ret != ENOENT) {
bb7cd1
         DEBUG(SSSDBG_MINOR_FAILURE,
bb7cd1
               "Failed to use ipaDomainResolutionOrder set in ipaConfig "
bb7cd1
               "for the domain: \"%s\".\n"
bb7cd1
               "No ipaDomainResolutionOrder will be followed.\n",
bb7cd1
               dom->name);
bb7cd1
-    } else {
bb7cd1
-        goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    cr_domains = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
-                                                    rctx, rctx->domains, NULL);
bb7cd1
-    if (cr_domains == NULL) {
bb7cd1
+    ret = cache_req_domain_new_list_from_domain_resolution_order(
bb7cd1
+                                        rctx, rctx->domains, NULL, &cr_domains);
bb7cd1
+    if (ret != EOK) {
bb7cd1
         DEBUG(SSSDBG_CRIT_FAILURE, "Failed to flatten the list of domains.\n");
bb7cd1
         goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
-done:
bb7cd1
-    ret = cr_domains != NULL ? EOK : ENOMEM;
bb7cd1
+    ret = EOK;
bb7cd1
 
bb7cd1
+done:
bb7cd1
     cache_req_domain_list_zfree(&rctx->cr_domains);
bb7cd1
     rctx->cr_domains = cr_domains;
bb7cd1
 
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1