summaryrefslogtreecommitdiffstats
path: root/src/providers/ad
diff options
context:
space:
mode:
authorPetr Cech <pcech@redhat.com>2016-06-21 08:34:15 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-08-17 16:08:36 +0200
commita82baf596bac1fdac6addca6419d8992111a8aa2 (patch)
tree39b224d4bc806d99fa631cce8eabd62728dfb30c /src/providers/ad
parentd6342c92c226becbdd254f90a0005b8c00c300dc (diff)
downloadsssd-a82baf596bac1fdac6addca6419d8992111a8aa2.tar.gz
sssd-a82baf596bac1fdac6addca6419d8992111a8aa2.tar.xz
sssd-a82baf596bac1fdac6addca6419d8992111a8aa2.zip
AD_PROVIDER: Initializing of ad_enabled_domains
We add ad_enabled_domains into ad_subdomains_ctx. Resolves: https://fedorahosted.org/sssd/ticket/2828 Reviewed-by: Jakub Hrozek <jhrozek@redhat.com> Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/providers/ad')
-rw-r--r--src/providers/ad/ad_subdomains.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index a0d5c2e54..6e4476033 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -57,6 +57,79 @@
/* do not refresh more often than every 5 seconds for now */
#define AD_SUBDOMAIN_REFRESH_LIMIT 5
+static errno_t ad_get_enabled_domains(TALLOC_CTX *mem_ctx,
+ struct ad_id_ctx *ad_id_ctx,
+ const char *ad_domain,
+ const char ***_ad_enabled_domains)
+{
+ int ret;
+ const char *str;
+ const char *option_name;
+ const char **domains = NULL;
+ int count;
+ bool is_ad_in_domains;
+ TALLOC_CTX *tmp_ctx = NULL;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ str = dp_opt_get_cstring(ad_id_ctx->ad_options->basic, AD_ENABLED_DOMAINS);
+ if (str == NULL) {
+ *_ad_enabled_domains = NULL;
+ ret = EOK;
+ goto done;
+ }
+
+ count = 0;
+ ret = split_on_separator(tmp_ctx, str, ',', true, true,
+ discard_const_p(char **, &domains), &count);
+ if (ret != EOK) {
+ option_name = ad_id_ctx->ad_options->basic[AD_ENABLED_DOMAINS].opt_name;
+ DEBUG(SSSDBG_CRIT_FAILURE, "Failed to parse option [%s], [%i] [%s]!\n",
+ option_name, ret, sss_strerror(ret));
+ ret = EINVAL;
+ goto done;
+ }
+
+ is_ad_in_domains = false;
+ for (int i = 0; i < count; i++) {
+ is_ad_in_domains += strcmp(ad_domain, domains[i]) == 0 ? true : false;
+ }
+
+ if (is_ad_in_domains == false) {
+ domains = talloc_realloc(tmp_ctx, domains, const char*, count + 2);
+ if (domains == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ domains[count] = talloc_strdup(domains, ad_domain);
+ if (domains[count] == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ domains[count + 1] = NULL;
+ } else {
+ domains = talloc_realloc(tmp_ctx, domains, const char*, count + 1);
+ if (domains == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ domains[count] = NULL;
+ }
+
+ *_ad_enabled_domains = talloc_steal(mem_ctx, domains);
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
static errno_t
ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
struct ad_id_ctx *id_ctx,
@@ -171,6 +244,7 @@ struct ad_subdomains_ctx {
struct sdap_domain *sdom;
char *domain_name;
+ const char **ad_enabled_domains;
time_t last_refreshed;
};
@@ -1357,6 +1431,7 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
{
struct ad_subdomains_ctx *sd_ctx;
const char *ad_domain;
+ const char **ad_enabled_domains = NULL;
time_t period;
errno_t ret;
@@ -1368,6 +1443,12 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
return ENOMEM;
}
+ ret = ad_get_enabled_domains(sd_ctx, ad_id_ctx, ad_domain,
+ &ad_enabled_domains);
+ if (ret != EOK) {
+ return EINVAL;
+ }
+
sd_ctx->be_ctx = be_ctx;
sd_ctx->sdom = ad_id_ctx->sdap_id_ctx->opts->sdom;
sd_ctx->sdap_id_ctx = ad_id_ctx->sdap_id_ctx;
@@ -1376,6 +1457,7 @@ errno_t ad_subdomains_init(TALLOC_CTX *mem_ctx,
DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
return ENOMEM;
}
+ sd_ctx->ad_enabled_domains = ad_enabled_domains;
sd_ctx->ad_id_ctx = ad_id_ctx;
dp_set_method(dp_methods, DPM_DOMAINS_HANDLER,