dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0048-IPA-Get-ipaDomainsResolutionOrder-from-ipaConfig.patch

bb7cd1
From 4ff821a9a37cb43f9c34faef4b5ccbdc8dc6a7e8 Mon Sep 17 00:00:00 2001
bb7cd1
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
bb7cd1
Date: Wed, 22 Mar 2017 13:40:20 +0100
bb7cd1
Subject: [PATCH 48/54] IPA: Get ipaDomainsResolutionOrder from ipaConfig
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
ipaDomainsResolutionOrder provides a list of domains that have to be
bb7cd1
looked up firstly during cache_req searches.
bb7cd1
bb7cd1
This commit only fetches this list from the server and stores its value
bb7cd1
at sysdb so we can make use of it later on this patch series.
bb7cd1
bb7cd1
There are no tests for newly introduced sysdb methods are those are
bb7cd1
basically only calling sysdb_update_domain_resolution_order(),
bb7cd1
sysdb_get_domain_resolution_order() and
bb7cd1
sysdb_get_use_domain_resolution_order() which are have tests written
bb7cd1
for.
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: Sumit Bose <sbose@redhat.com>
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
---
bb7cd1
 src/db/sysdb.h                     |  11 +++
bb7cd1
 src/db/sysdb_subdomains.c          |  67 +++++++++++++++
bb7cd1
 src/providers/ipa/ipa_subdomains.c | 168 ++++++++++++++++++++++++++++++++++---
bb7cd1
 3 files changed, 234 insertions(+), 12 deletions(-)
bb7cd1
bb7cd1
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
bb7cd1
index 42d2857ed7765c17e7d84b0da93ed07758fbe012..75a07d4d2effb028ec654342113f8478e1eba10e 100644
bb7cd1
--- a/src/db/sysdb.h
bb7cd1
+++ b/src/db/sysdb.h
bb7cd1
@@ -489,6 +489,17 @@ int sysdb_transaction_cancel(struct sysdb_ctx *sysdb);
bb7cd1
 /* functions related to subdomains */
bb7cd1
 errno_t sysdb_domain_create(struct sysdb_ctx *sysdb, const char *domain_name);
bb7cd1
 
bb7cd1
+errno_t sysdb_domain_get_domain_resolution_order(
bb7cd1
+                                        TALLOC_CTX *mem_ctx,
bb7cd1
+                                        struct sysdb_ctx *sysdb,
bb7cd1
+                                        const char *domain_name,
bb7cd1
+                                        const char **_domain_resolution_order);
bb7cd1
+
bb7cd1
+errno_t sysdb_domain_update_domain_resolution_order(
bb7cd1
+                                        struct sysdb_ctx *sysdb,
bb7cd1
+                                        const char *domain_name,
bb7cd1
+                                        const char *domain_resolution_order);
bb7cd1
+
bb7cd1
 errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
bb7cd1
                               const char *name, const char *realm,
bb7cd1
                               const char *flat_name, const char *domain_id,
bb7cd1
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
bb7cd1
index 916dbba153d8c08837425f6fd29a20f5a6aa9fc9..e2a4f7bb1fcdf20b6b7e04efc7f396d1c3d08f0f 100644
bb7cd1
--- a/src/db/sysdb_subdomains.c
bb7cd1
+++ b/src/db/sysdb_subdomains.c
bb7cd1
@@ -22,6 +22,7 @@
bb7cd1
 
bb7cd1
 #include "util/util.h"
bb7cd1
 #include "db/sysdb_private.h"
bb7cd1
+#include "db/sysdb_domain_resolution_order.h"
bb7cd1
 
bb7cd1
 static errno_t
bb7cd1
 check_subdom_config_file(struct confdb_ctx *confdb,
bb7cd1
@@ -1210,3 +1211,69 @@ done:
bb7cd1
     talloc_free(tmp_ctx);
bb7cd1
     return ret;
bb7cd1
 }
bb7cd1
+
bb7cd1
+errno_t
bb7cd1
+sysdb_domain_get_domain_resolution_order(TALLOC_CTX *mem_ctx,
bb7cd1
+                                         struct sysdb_ctx *sysdb,
bb7cd1
+                                         const char *domain_name,
bb7cd1
+                                         const char **_domain_resolution_order)
bb7cd1
+{
bb7cd1
+    TALLOC_CTX *tmp_ctx;
bb7cd1
+    struct ldb_dn *dn;
bb7cd1
+    errno_t ret;
bb7cd1
+
bb7cd1
+    tmp_ctx = talloc_new(NULL);
bb7cd1
+    if (tmp_ctx == NULL) {
bb7cd1
+        return ENOMEM;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, domain_name);
bb7cd1
+    if (dn == NULL) {
bb7cd1
+        ret = ENOMEM;
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = sysdb_get_domain_resolution_order(mem_ctx, sysdb, dn,
bb7cd1
+                                            _domain_resolution_order);
bb7cd1
+
bb7cd1
+done:
bb7cd1
+    talloc_free(tmp_ctx);
bb7cd1
+    return ret;
bb7cd1
+}
bb7cd1
+
bb7cd1
+errno_t
bb7cd1
+sysdb_domain_update_domain_resolution_order(struct sysdb_ctx *sysdb,
bb7cd1
+                                            const char *domain_name,
bb7cd1
+                                            const char *domain_resolution_order)
bb7cd1
+{
bb7cd1
+
bb7cd1
+    TALLOC_CTX *tmp_ctx;
bb7cd1
+    struct ldb_dn *dn;
bb7cd1
+    errno_t ret;
bb7cd1
+
bb7cd1
+    tmp_ctx = talloc_new(NULL);
bb7cd1
+    if (tmp_ctx == NULL) {
bb7cd1
+        return ENOMEM;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_DOM_BASE, domain_name);
bb7cd1
+    if (dn == NULL) {
bb7cd1
+        ret = ENOMEM;
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = sysdb_update_domain_resolution_order(sysdb, dn,
bb7cd1
+                                               domain_resolution_order);
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        DEBUG(SSSDBG_OP_FAILURE,
bb7cd1
+              "sysdb_update_domain_resolution_order() failed [%d]: [%s].\n",
bb7cd1
+              ret, sss_strerror(ret));
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = EOK;
bb7cd1
+
bb7cd1
+done:
bb7cd1
+    talloc_free(tmp_ctx);
bb7cd1
+    return ret;
bb7cd1
+}
bb7cd1
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
bb7cd1
index a07b88fe2f499353293ba90345552413c9792f4b..01a0ce812d861b24565d2f71f27d6b8ceb2965bc 100644
bb7cd1
--- a/src/providers/ipa/ipa_subdomains.c
bb7cd1
+++ b/src/providers/ipa/ipa_subdomains.c
bb7cd1
@@ -29,6 +29,7 @@
bb7cd1
 #include "providers/ipa/ipa_common.h"
bb7cd1
 #include "providers/ipa/ipa_id.h"
bb7cd1
 #include "providers/ipa/ipa_opts.h"
bb7cd1
+#include "providers/ipa/ipa_config.h"
bb7cd1
 
bb7cd1
 #include <ctype.h>
bb7cd1
 
bb7cd1
@@ -51,6 +52,8 @@
bb7cd1
 
bb7cd1
 #define IPA_ASSIGNED_ID_VIEW "ipaAssignedIDView"
bb7cd1
 
bb7cd1
+#define IPA_DOMAIN_RESOLUTION_ORDER "ipaDomainResolutionOrder"
bb7cd1
+
bb7cd1
 /* do not refresh more often than every 5 seconds for now */
bb7cd1
 #define IPA_SUBDOMAIN_REFRESH_LIMIT 5
bb7cd1
 
bb7cd1
@@ -1681,6 +1684,117 @@ static errno_t ipa_subdomains_view_name_recv(struct tevent_req *req)
bb7cd1
     return EOK;
bb7cd1
 }
bb7cd1
 
bb7cd1
+struct ipa_domain_resolution_order_state {
bb7cd1
+    struct sss_domain_info *domain;
bb7cd1
+};
bb7cd1
+
bb7cd1
+static void ipa_domain_resolution_order_done(struct tevent_req *subreq);
bb7cd1
+
bb7cd1
+static struct tevent_req *
bb7cd1
+ipa_domain_resolution_order_send(TALLOC_CTX *mem_ctx,
bb7cd1
+                                 struct tevent_context *ev,
bb7cd1
+                                 struct ipa_subdomains_ctx *sd_ctx,
bb7cd1
+                                 struct sdap_handle *sh)
bb7cd1
+{
bb7cd1
+    struct ipa_domain_resolution_order_state *state;
bb7cd1
+    struct tevent_req *subreq;
bb7cd1
+    struct tevent_req *req;
bb7cd1
+    const char *attrs[] = {IPA_DOMAIN_RESOLUTION_ORDER, NULL};
bb7cd1
+    errno_t ret;
bb7cd1
+
bb7cd1
+    req = tevent_req_create(mem_ctx, &state,
bb7cd1
+                            struct ipa_domain_resolution_order_state);
bb7cd1
+    if (req == NULL) {
bb7cd1
+        DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
bb7cd1
+        return NULL;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    state->domain = sd_ctx->be_ctx->domain;
bb7cd1
+
bb7cd1
+    subreq = ipa_get_config_send(state, ev, sh, sd_ctx->sdap_id_ctx->opts,
bb7cd1
+                                 state->domain->name, attrs);
bb7cd1
+    if (subreq == NULL) {
bb7cd1
+        ret = ENOMEM;
bb7cd1
+        goto immediately;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    tevent_req_set_callback(subreq, ipa_domain_resolution_order_done, req);
bb7cd1
+
bb7cd1
+    return req;
bb7cd1
+
bb7cd1
+immediately:
bb7cd1
+    if (ret == EOK) {
bb7cd1
+        tevent_req_done(req);
bb7cd1
+    } else {
bb7cd1
+        tevent_req_error(req, ret);
bb7cd1
+    }
bb7cd1
+    tevent_req_post(req, ev);
bb7cd1
+
bb7cd1
+    return req;
bb7cd1
+}
bb7cd1
+
bb7cd1
+static void ipa_domain_resolution_order_done(struct tevent_req *subreq)
bb7cd1
+{
bb7cd1
+    struct ipa_domain_resolution_order_state *state;
bb7cd1
+    struct tevent_req *req;
bb7cd1
+    struct sysdb_attrs *config = NULL;
bb7cd1
+    const char *domain_resolution_order = NULL;
bb7cd1
+    errno_t ret;
bb7cd1
+
bb7cd1
+    req = tevent_req_callback_data(subreq, struct tevent_req);
bb7cd1
+    state = tevent_req_data(req, struct ipa_domain_resolution_order_state);
bb7cd1
+
bb7cd1
+    ret = ipa_get_config_recv(subreq, state, &config);
bb7cd1
+    talloc_zfree(subreq);
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        DEBUG(SSSDBG_OP_FAILURE,
bb7cd1
+              "Failed to get the domains' resolution order configuration "
bb7cd1
+              "from the server [%d]: %s\n",
bb7cd1
+              ret, sss_strerror(ret));
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    if (config != NULL) {
bb7cd1
+        ret = sysdb_attrs_get_string(config, IPA_DOMAIN_RESOLUTION_ORDER,
bb7cd1
+                                     &domain_resolution_order);
bb7cd1
+        if (ret != EOK && ret != ENOENT) {
bb7cd1
+            DEBUG(SSSDBG_OP_FAILURE,
bb7cd1
+                  "Failed to get the domains' resolution order configuration "
bb7cd1
+                  "value [%d]: %s\n",
bb7cd1
+                  ret, sss_strerror(ret));
bb7cd1
+            goto done;
bb7cd1
+        } else if (ret == ENOENT) {
bb7cd1
+            domain_resolution_order = NULL;
bb7cd1
+        }
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = sysdb_domain_update_domain_resolution_order(
bb7cd1
+                        state->domain->sysdb, state->domain->name,
bb7cd1
+                        domain_resolution_order);
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        DEBUG(SSSDBG_OP_FAILURE,
bb7cd1
+              "sysdb_domain_update_resolution_order() [%d]: [%s].\n",
bb7cd1
+              ret, sss_strerror(ret));
bb7cd1
+        goto done;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ret = EOK;
bb7cd1
+
bb7cd1
+done:
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        tevent_req_error(req, ret);
bb7cd1
+        return;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    tevent_req_done(req);
bb7cd1
+}
bb7cd1
+
bb7cd1
+static errno_t ipa_domain_resolution_order_recv(struct tevent_req *req)
bb7cd1
+{
bb7cd1
+    TEVENT_REQ_RETURN_ON_ERROR(req);
bb7cd1
+
bb7cd1
+    return EOK;
bb7cd1
+}
bb7cd1
 
bb7cd1
 struct ipa_subdomains_refresh_state {
bb7cd1
     struct tevent_context *ev;
bb7cd1
@@ -1695,6 +1809,7 @@ static void ipa_subdomains_refresh_certmap_done(struct tevent_req *subreq);
bb7cd1
 static void ipa_subdomains_refresh_master_done(struct tevent_req *subreq);
bb7cd1
 static void ipa_subdomains_refresh_slave_done(struct tevent_req *subreq);
bb7cd1
 static void ipa_subdomains_refresh_view_done(struct tevent_req *subreq);
bb7cd1
+static void ipa_domain_refresh_resolution_order_done(struct tevent_req *subreq);
bb7cd1
 
bb7cd1
 static struct tevent_req *
bb7cd1
 ipa_subdomains_refresh_send(TALLOC_CTX *mem_ctx,
bb7cd1
@@ -1916,7 +2031,6 @@ static void ipa_subdomains_refresh_view_done(struct tevent_req *subreq)
bb7cd1
 {
bb7cd1
     struct ipa_subdomains_refresh_state *state;
bb7cd1
     struct tevent_req *req;
bb7cd1
-    int dp_error;
bb7cd1
     errno_t ret;
bb7cd1
 
bb7cd1
     req = tevent_req_callback_data(subreq, struct tevent_req);
bb7cd1
@@ -1924,24 +2038,55 @@ static void ipa_subdomains_refresh_view_done(struct tevent_req *subreq)
bb7cd1
 
bb7cd1
     ret = ipa_subdomains_view_name_recv(subreq);
bb7cd1
     talloc_zfree(subreq);
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        DEBUG(SSSDBG_CRIT_FAILURE,
bb7cd1
+              "Unable to get view name [%d]: %s\n",
bb7cd1
+              ret, sss_strerror(ret));
bb7cd1
+        tevent_req_error(req, ret);
bb7cd1
+        return;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    subreq = ipa_domain_resolution_order_send(state, state->ev, state->sd_ctx,
bb7cd1
+                                            sdap_id_op_handle(state->sdap_op));
bb7cd1
+    if (subreq == NULL) {
bb7cd1
+        tevent_req_error(req, ENOMEM);
bb7cd1
+        return;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    tevent_req_set_callback(subreq,
bb7cd1
+                            ipa_domain_refresh_resolution_order_done,
bb7cd1
+                            req);
bb7cd1
+}
bb7cd1
+
bb7cd1
+static void
bb7cd1
+ipa_domain_refresh_resolution_order_done(struct tevent_req *subreq)
bb7cd1
+{
bb7cd1
+    struct ipa_subdomains_refresh_state *state;
bb7cd1
+    struct tevent_req *req;
bb7cd1
+    int dp_error;
bb7cd1
+    errno_t ret;
bb7cd1
+
bb7cd1
+    req = tevent_req_callback_data(subreq, struct tevent_req);
bb7cd1
+    state = tevent_req_data(req, struct ipa_subdomains_refresh_state);
bb7cd1
+
bb7cd1
+    ret = ipa_domain_resolution_order_recv(subreq);
bb7cd1
+    talloc_zfree(subreq);
bb7cd1
+    if (ret != EOK) {
bb7cd1
+        DEBUG(SSSDBG_MINOR_FAILURE,
bb7cd1
+              "Unable to get the domains order resolution [%d]: %s\n",
bb7cd1
+              ret, sss_strerror(ret));
bb7cd1
+        tevent_req_error(req, ret);
bb7cd1
+        return;
bb7cd1
+    }
bb7cd1
+
bb7cd1
     ret = sdap_id_op_done(state->sdap_op, ret, &dp_error);
bb7cd1
     if (dp_error == DP_ERR_OK && ret != EOK) {
bb7cd1
         /* retry */
bb7cd1
         ret = ipa_subdomains_refresh_retry(req);
bb7cd1
-        if (ret != EOK) {
bb7cd1
-            goto done;
bb7cd1
-        }
bb7cd1
-        return;
bb7cd1
     } else if (dp_error == DP_ERR_OFFLINE) {
bb7cd1
         ret = ERR_OFFLINE;
bb7cd1
-        goto done;
bb7cd1
-    } else if (ret != EOK) {
bb7cd1
-        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get view name "
bb7cd1
-              "[%d]: %s\n", ret, sss_strerror(ret));
bb7cd1
-        goto done;
bb7cd1
     }
bb7cd1
 
bb7cd1
-done:
bb7cd1
     if (ret != EOK) {
bb7cd1
         DEBUG(SSSDBG_TRACE_FUNC, "Unable to refresh subdomains [%d]: %s\n",
bb7cd1
               ret, sss_strerror(ret));
bb7cd1
@@ -1949,7 +2094,6 @@ done:
bb7cd1
         return;
bb7cd1
     }
bb7cd1
 
bb7cd1
-    DEBUG(SSSDBG_TRACE_FUNC, "Subdomains refreshed.\n");
bb7cd1
     tevent_req_done(req);
bb7cd1
 }
bb7cd1
 
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1