|
|
b2d430 |
From 7e8b6166086cf04c5b1290c3dffd268438ef9c2c Mon Sep 17 00:00:00 2001
|
|
|
b2d430 |
From: Petr Cech <pcech@redhat.com>
|
|
|
b2d430 |
Date: Tue, 21 Jun 2016 08:34:15 +0200
|
|
|
b2d430 |
Subject: [PATCH 104/108] AD_PROVIDER: Initializing of ad_enabled_domains
|
|
|
b2d430 |
MIME-Version: 1.0
|
|
|
b2d430 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b2d430 |
Content-Transfer-Encoding: 8bit
|
|
|
b2d430 |
|
|
|
b2d430 |
We add ad_enabled_domains into ad_subdomains_ctx.
|
|
|
b2d430 |
|
|
|
b2d430 |
Resolves:
|
|
|
b2d430 |
https://fedorahosted.org/sssd/ticket/2828
|
|
|
b2d430 |
|
|
|
b2d430 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
b2d430 |
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
|
|
|
b2d430 |
---
|
|
|
b2d430 |
src/providers/ad/ad_subdomains.c | 82 ++++++++++++++++++++++++++++++++++++++++
|
|
|
b2d430 |
1 file changed, 82 insertions(+)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
|
|
|
b2d430 |
index a0d5c2e544fc62fda64771dce59b3b7ab8ecd8b6..6e44760330275f7e4262e6863f180747f659edb5 100644
|
|
|
b2d430 |
--- a/src/providers/ad/ad_subdomains.c
|
|
|
b2d430 |
+++ b/src/providers/ad/ad_subdomains.c
|
|
|
b2d430 |
@@ -57,6 +57,79 @@
|
|
|
b2d430 |
/* do not refresh more often than every 5 seconds for now */
|
|
|
b2d430 |
#define AD_SUBDOMAIN_REFRESH_LIMIT 5
|
|
|
b2d430 |
|
|
|
b2d430 |
+static errno_t ad_get_enabled_domains(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct ad_id_ctx *ad_id_ctx,
|
|
|
b2d430 |
+ const char *ad_domain,
|
|
|
b2d430 |
+ const char ***_ad_enabled_domains)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ int ret;
|
|
|
b2d430 |
+ const char *str;
|
|
|
b2d430 |
+ const char *option_name;
|
|
|
b2d430 |
+ const char **domains = NULL;
|
|
|
b2d430 |
+ int count;
|
|
|
b2d430 |
+ bool is_ad_in_domains;
|
|
|
b2d430 |
+ TALLOC_CTX *tmp_ctx = NULL;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
b2d430 |
+ if (tmp_ctx == NULL) {
|
|
|
b2d430 |
+ return ENOMEM;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ str = dp_opt_get_cstring(ad_id_ctx->ad_options->basic, AD_ENABLED_DOMAINS);
|
|
|
b2d430 |
+ if (str == NULL) {
|
|
|
b2d430 |
+ *_ad_enabled_domains = NULL;
|
|
|
b2d430 |
+ ret = EOK;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ count = 0;
|
|
|
b2d430 |
+ ret = split_on_separator(tmp_ctx, str, ',', true, true,
|
|
|
b2d430 |
+ discard_const_p(char **, &domains), &count);
|
|
|
b2d430 |
+ if (ret != EOK) {
|
|
|
b2d430 |
+ option_name = ad_id_ctx->ad_options->basic[AD_ENABLED_DOMAINS].opt_name;
|
|
|
b2d430 |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Failed to parse option [%s], [%i] [%s]!\n",
|
|
|
b2d430 |
+ option_name, ret, sss_strerror(ret));
|
|
|
b2d430 |
+ ret = EINVAL;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ is_ad_in_domains = false;
|
|
|
b2d430 |
+ for (int i = 0; i < count; i++) {
|
|
|
b2d430 |
+ is_ad_in_domains += strcmp(ad_domain, domains[i]) == 0 ? true : false;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ if (is_ad_in_domains == false) {
|
|
|
b2d430 |
+ domains = talloc_realloc(tmp_ctx, domains, const char*, count + 2);
|
|
|
b2d430 |
+ if (domains == NULL) {
|
|
|
b2d430 |
+ ret = ENOMEM;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ domains[count] = talloc_strdup(domains, ad_domain);
|
|
|
b2d430 |
+ if (domains[count] == NULL) {
|
|
|
b2d430 |
+ ret = ENOMEM;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ domains[count + 1] = NULL;
|
|
|
b2d430 |
+ } else {
|
|
|
b2d430 |
+ domains = talloc_realloc(tmp_ctx, domains, const char*, count + 1);
|
|
|
b2d430 |
+ if (domains == NULL) {
|
|
|
b2d430 |
+ ret = ENOMEM;
|
|
|
b2d430 |
+ goto done;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ domains[count] = NULL;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ *_ad_enabled_domains = talloc_steal(mem_ctx, domains);
|
|
|
b2d430 |
+ ret = EOK;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+done:
|
|
|
b2d430 |
+ talloc_free(tmp_ctx);
|
|
|
b2d430 |
+ return ret;
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
static errno_t
|
|
|
b2d430 |
ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
|
|
|
b2d430 |
struct ad_id_ctx *id_ctx,
|
|
|
b2d430 |
@@ -171,6 +244,7 @@ struct ad_subdomains_ctx {
|
|
|
b2d430 |
|
|
|
b2d430 |
struct sdap_domain *sdom;
|
|
|
b2d430 |
char *domain_name;
|
|
|
b2d430 |
+ const char **ad_enabled_domains;
|
|
|
b2d430 |
|
|
|
b2d430 |
time_t last_refreshed;
|
|
|
b2d430 |
};
|
|
|
b2d430 |
@@ -1357,6 +1431,7 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
{
|
|
|
b2d430 |
struct ad_subdomains_ctx *sd_ctx;
|
|
|
b2d430 |
const char *ad_domain;
|
|
|
b2d430 |
+ const char **ad_enabled_domains = NULL;
|
|
|
b2d430 |
time_t period;
|
|
|
b2d430 |
errno_t ret;
|
|
|
b2d430 |
|
|
|
b2d430 |
@@ -1368,6 +1443,12 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
return ENOMEM;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
+ ret = ad_get_enabled_domains(sd_ctx, ad_id_ctx, ad_domain,
|
|
|
b2d430 |
+ &ad_enabled_domains);
|
|
|
b2d430 |
+ if (ret != EOK) {
|
|
|
b2d430 |
+ return EINVAL;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
sd_ctx->be_ctx = be_ctx;
|
|
|
b2d430 |
sd_ctx->sdom = ad_id_ctx->sdap_id_ctx->opts->sdom;
|
|
|
b2d430 |
sd_ctx->sdap_id_ctx = ad_id_ctx->sdap_id_ctx;
|
|
|
b2d430 |
@@ -1376,6 +1457,7 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
|
|
|
b2d430 |
return ENOMEM;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
+ sd_ctx->ad_enabled_domains = ad_enabled_domains;
|
|
|
b2d430 |
sd_ctx->ad_id_ctx = ad_id_ctx;
|
|
|
b2d430 |
|
|
|
b2d430 |
dp_set_method(dp_methods, DPM_DOMAINS_HANDLER,
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|