Blame SOURCES/0031-sdap-inherit-SDAP_SASL_MECH-if-not-set-explicitly.patch

5fca41
From 373b1136ccb3bf54f32d47473e8120d0258f8405 Mon Sep 17 00:00:00 2001
5fca41
From: Sumit Bose <sbose@redhat.com>
5fca41
Date: Tue, 21 May 2019 10:22:04 +0200
5fca41
Subject: [PATCH 31/31] sdap: inherit SDAP_SASL_MECH if not set explicitly
5fca41
5fca41
If ldap_sasl_mech is set for the configured domain in sssd.conf the
5fca41
value is inherited automatically to all sub-domains. The can be
5fca41
overwritten by setting ldap_sasl_mech for a given sub-domain explicitly
5fca41
in sssd.conf.
5fca41
5fca41
Related to https://pagure.io/SSSD/sssd/issue/4006
5fca41
5fca41
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
5fca41
(cherry picked from commit 070f22f896b909c140ed7598aed2393d61a834ae)
5fca41
---
5fca41
 src/config/cfg_rules.ini                  |  1 +
5fca41
 src/man/sssd-ldap.5.xml                   | 10 ++++++
5fca41
 src/man/sssd.conf.5.xml                   |  1 +
5fca41
 src/providers/ad/ad_common.c              | 38 +++++++++++++++++++++++
5fca41
 src/providers/ad/ad_common.h              |  5 +++
5fca41
 src/providers/ad/ad_subdomains.c          | 18 ++++++++++-
5fca41
 src/providers/ipa/ipa_subdomains_server.c | 19 +++++++++++-
5fca41
 7 files changed, 90 insertions(+), 2 deletions(-)
5fca41
5fca41
diff --git a/src/config/cfg_rules.ini b/src/config/cfg_rules.ini
5fca41
index 603211711..3976ec4e1 100644
5fca41
--- a/src/config/cfg_rules.ini
5fca41
+++ b/src/config/cfg_rules.ini
5fca41
@@ -753,6 +753,7 @@ option = ldap_user_search_base
5fca41
 option = ldap_group_search_base
5fca41
 option = ldap_netgroup_search_base
5fca41
 option = ldap_service_search_base
5fca41
+option = ldap_sasl_mech
5fca41
 option = ad_server
5fca41
 option = ad_backup_server
5fca41
 option = ad_site
5fca41
diff --git a/src/man/sssd-ldap.5.xml b/src/man/sssd-ldap.5.xml
5fca41
index 17c5523c0..fadd05cb7 100644
5fca41
--- a/src/man/sssd-ldap.5.xml
5fca41
+++ b/src/man/sssd-ldap.5.xml
5fca41
@@ -1808,6 +1808,16 @@
5fca41
                             Specify the SASL mechanism to use.  Currently only
5fca41
                             GSSAPI and GSS-SPNEGO are tested and supported.
5fca41
                         </para>
5fca41
+                        <para>
5fca41
+                            If the backend supports sub-domains the value of
5fca41
+                            ldap_sasl_mech is automatically inherited to the
5fca41
+                            sub-domains. If a different value is needed for a
5fca41
+                            sub-domain it can be overwritten by setting
5fca41
+                            ldap_sasl_mech for this sub-domain explicitly.
5fca41
+                            Please see TRUSTED DOMAIN SECTION in
5fca41
+                            <citerefentry><refentrytitle>sssd.conf</refentrytitle>
5fca41
+                            <manvolnum>5</manvolnum></citerefentry> for details.
5fca41
+                        </para>
5fca41
                         <para>
5fca41
                             Default: not set
5fca41
                         </para>
5fca41
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
5fca41
index 1ab7af00b..3f05b3942 100644
5fca41
--- a/src/man/sssd.conf.5.xml
5fca41
+++ b/src/man/sssd.conf.5.xml
5fca41
@@ -3356,6 +3356,7 @@ ldap_user_extra_attrs = phone:telephoneNumber
5fca41
             <para>ldap_group_search_base,</para>
5fca41
             <para>ldap_netgroup_search_base,</para>
5fca41
             <para>ldap_service_search_base,</para>
5fca41
+            <para>ldap_sasl_mech,</para>
5fca41
             <para>ad_server,</para>
5fca41
             <para>ad_backup_server,</para>
5fca41
             <para>ad_site,</para>
5fca41
diff --git a/src/providers/ad/ad_common.c b/src/providers/ad/ad_common.c
5fca41
index 19d4b3d5a..1b8b1df19 100644
5fca41
--- a/src/providers/ad/ad_common.c
5fca41
+++ b/src/providers/ad/ad_common.c
5fca41
@@ -1455,3 +1455,41 @@ ad_user_conn_list(TALLOC_CTX *mem_ctx,
5fca41
 
5fca41
     return clist;
5fca41
 }
5fca41
+
5fca41
+errno_t ad_inherit_opts_if_needed(struct dp_option *parent_opts,
5fca41
+                                  struct dp_option *suddom_opts,
5fca41
+                                  struct confdb_ctx *cdb,
5fca41
+                                  const char *subdom_conf_path,
5fca41
+                                  int opt_id)
5fca41
+{
5fca41
+    int ret;
5fca41
+    const char *parent_val = NULL;
5fca41
+    char *dummy = NULL;
5fca41
+    char *option_list[2] = { NULL, NULL };
5fca41
+
5fca41
+    parent_val = dp_opt_get_cstring(parent_opts, opt_id);
5fca41
+    if (parent_val != NULL) {
5fca41
+        ret = confdb_get_string(cdb, NULL, subdom_conf_path,
5fca41
+                                parent_opts[opt_id].opt_name, NULL, &dummy);
5fca41
+        if (ret != EOK) {
5fca41
+            DEBUG(SSSDBG_OP_FAILURE, "confdb_get_string failed.\n");
5fca41
+            goto done;
5fca41
+        }
5fca41
+
5fca41
+        if (dummy == NULL) {
5fca41
+            DEBUG(SSSDBG_CONF_SETTINGS,
5fca41
+                  "Option [%s] is set in parent domain but not set for "
5fca41
+                  "sub-domain trying to set it to [%s].\n",
5fca41
+                  parent_opts[opt_id].opt_name, parent_val);
5fca41
+            option_list[0] = discard_const(parent_opts[opt_id].opt_name);
5fca41
+            dp_option_inherit(option_list, opt_id, parent_opts, suddom_opts);
5fca41
+        }
5fca41
+    }
5fca41
+
5fca41
+    ret = EOK;
5fca41
+
5fca41
+done:
5fca41
+    talloc_free(dummy);
5fca41
+
5fca41
+    return ret;
5fca41
+}
5fca41
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
5fca41
index 638465958..2f624df3d 100644
5fca41
--- a/src/providers/ad/ad_common.h
5fca41
+++ b/src/providers/ad/ad_common.h
5fca41
@@ -216,4 +216,9 @@ errno_t netlogon_get_domain_info(TALLOC_CTX *mem_ctx,
5fca41
                                  char **_site,
5fca41
                                  char **_forest);
5fca41
 
5fca41
+errno_t ad_inherit_opts_if_needed(struct dp_option *parent_opts,
5fca41
+                                  struct dp_option *suddom_opts,
5fca41
+                                  struct confdb_ctx *cdb,
5fca41
+                                  const char *subdom_conf_path,
5fca41
+                                  int opt_id);
5fca41
 #endif /* AD_COMMON_H_ */
5fca41
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
5fca41
index b4ad347e4..b4e09fb7e 100644
5fca41
--- a/src/providers/ad/ad_subdomains.c
5fca41
+++ b/src/providers/ad/ad_subdomains.c
5fca41
@@ -305,13 +305,29 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
5fca41
                                               realm,
5fca41
                                               subdom,
5fca41
                                               hostname, keytab);
5fca41
-    talloc_free(subdom_conf_path);
5fca41
     if (ad_options == NULL) {
5fca41
         DEBUG(SSSDBG_OP_FAILURE, "Cannot initialize AD options\n");
5fca41
         talloc_free(ad_options);
5fca41
+        talloc_free(subdom_conf_path);
5fca41
         return ENOMEM;
5fca41
     }
5fca41
 
5fca41
+    ret = ad_inherit_opts_if_needed(id_ctx->sdap_id_ctx->opts->basic,
5fca41
+                                    ad_options->id->basic,
5fca41
+                                    be_ctx->cdb, subdom_conf_path,
5fca41
+                                    SDAP_SASL_MECH);
5fca41
+    talloc_free(subdom_conf_path);
5fca41
+    if (ret != EOK) {
5fca41
+        DEBUG(SSSDBG_CRIT_FAILURE,
5fca41
+              "Failed to inherit option [%s] to sub-domain [%s]. "
5fca41
+              "This error is ignored but might cause issues or unexpected "
5fca41
+              "behavior later on.\n",
5fca41
+              id_ctx->ad_options->id->basic[SDAP_SASL_MECH].opt_name,
5fca41
+              subdom->name);
5fca41
+
5fca41
+        return ret;
5fca41
+    }
5fca41
+
5fca41
     ad_site_override = dp_opt_get_string(ad_options->basic, AD_SITE);
5fca41
 
5fca41
     gc_service_name = talloc_asprintf(ad_options, "sd_gc_%s", subdom->name);
5fca41
diff --git a/src/providers/ipa/ipa_subdomains_server.c b/src/providers/ipa/ipa_subdomains_server.c
5fca41
index 1d480e52b..d0e89a4f9 100644
5fca41
--- a/src/providers/ipa/ipa_subdomains_server.c
5fca41
+++ b/src/providers/ipa/ipa_subdomains_server.c
5fca41
@@ -172,6 +172,7 @@ static struct ad_options *ipa_ad_options_new(struct be_ctx *be_ctx,
5fca41
     const char *forest;
5fca41
     const char *forest_realm;
5fca41
     char *subdom_conf_path;
5fca41
+    int ret;
5fca41
 
5fca41
     /* Trusts are only established with forest roots */
5fca41
     direction = subdom->forest_root->trust_direction;
5fca41
@@ -196,12 +197,28 @@ static struct ad_options *ipa_ad_options_new(struct be_ctx *be_ctx,
5fca41
         DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported trust direction!\n");
5fca41
         ad_options = NULL;
5fca41
     }
5fca41
-    talloc_free(subdom_conf_path);
5fca41
 
5fca41
     if (ad_options == NULL) {
5fca41
         DEBUG(SSSDBG_OP_FAILURE, "Cannot initialize AD options\n");
5fca41
+        talloc_free(subdom_conf_path);
5fca41
         return NULL;
5fca41
     }
5fca41
+
5fca41
+    ret = ad_inherit_opts_if_needed(id_ctx->ipa_options->id->basic,
5fca41
+                                    ad_options->id->basic, be_ctx->cdb,
5fca41
+                                    subdom_conf_path, SDAP_SASL_MECH);
5fca41
+    talloc_free(subdom_conf_path);
5fca41
+    if (ret != EOK) {
5fca41
+        DEBUG(SSSDBG_CRIT_FAILURE,
5fca41
+              "Failed to inherit option [%s] to sub-domain [%s]. "
5fca41
+              "This error is ignored but might cause issues or unexpected "
5fca41
+              "behavior later on.\n",
5fca41
+              id_ctx->ipa_options->id->basic[SDAP_SASL_MECH].opt_name,
5fca41
+              subdom->name);
5fca41
+
5fca41
+        return NULL;
5fca41
+    }
5fca41
+
5fca41
     return ad_options;
5fca41
 }
5fca41
 
5fca41
-- 
5fca41
2.20.1
5fca41