Blame SOURCES/0027-IPA-enable-enterprise-principals-if-server-supports-.patch

b2d430
From 6b5b0732b7f4fab195a6205e1046a8402f5d3040 Mon Sep 17 00:00:00 2001
b2d430
From: Sumit Bose <sbose@redhat.com>
b2d430
Date: Fri, 1 Jul 2016 18:18:14 +0200
b2d430
Subject: [PATCH 27/27] IPA: enable enterprise principals if server supports
b2d430
 them
b2d430
b2d430
If there are alternative UPN suffixes found on the server we can safely
b2d430
assume that the IPA server supports enterprise principals.
b2d430
b2d430
Resolves https://fedorahosted.org/sssd/ticket/3018
b2d430
b2d430
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
b2d430
(cherry picked from commit 70673115c03c37ddc64c951b53d92df9d3310762)
b2d430
---
b2d430
 src/man/sssd-krb5.5.xml            |  6 +++
b2d430
 src/providers/ipa/ipa_subdomains.c | 86 ++++++++++++++++++++++++++++++++++++++
b2d430
 2 files changed, 92 insertions(+)
b2d430
b2d430
diff --git a/src/man/sssd-krb5.5.xml b/src/man/sssd-krb5.5.xml
b2d430
index e7fdd19e07db99314a9491faff9974d7d5e617e6..60b7dfb508c0d054a421fd46957574f52e0333d7 100644
b2d430
--- a/src/man/sssd-krb5.5.xml
b2d430
+++ b/src/man/sssd-krb5.5.xml
b2d430
@@ -513,6 +513,12 @@
b2d430
                         <para>
b2d430
                             Default: false (AD provider: true)
b2d430
                         </para>
b2d430
+                        <para>
b2d430
+                            The IPA provider will set to option to 'true' if it
b2d430
+                            detects that the server is capable of handling
b2d430
+                            enterprise principals and the option is not set
b2d430
+                            explicitly in the config file.
b2d430
+                        </para>
b2d430
                     </listitem>
b2d430
                 </varlistentry>
b2d430
 
b2d430
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
b2d430
index 925b1d8b133eb56724ee4f9133a2487090982a8b..4e5bceb8c761bf4476928168d620baf2beb62ad5 100644
b2d430
--- a/src/providers/ipa/ipa_subdomains.c
b2d430
+++ b/src/providers/ipa/ipa_subdomains.c
b2d430
@@ -28,6 +28,7 @@
b2d430
 #include "providers/ipa/ipa_subdomains.h"
b2d430
 #include "providers/ipa/ipa_common.h"
b2d430
 #include "providers/ipa/ipa_id.h"
b2d430
+#include "providers/ipa/ipa_opts.h"
b2d430
 
b2d430
 #include <ctype.h>
b2d430
 
b2d430
@@ -999,6 +1000,84 @@ immediately:
b2d430
     return req;
b2d430
 }
b2d430
 
b2d430
+static errno_t ipa_enable_enterprise_principals(struct be_ctx *be_ctx)
b2d430
+{
b2d430
+    int ret;
b2d430
+    struct sss_domain_info *d;
b2d430
+    TALLOC_CTX *tmp_ctx;
b2d430
+    char **vals = NULL;
b2d430
+    struct dp_module *auth;
b2d430
+    struct krb5_ctx *krb5_auth_ctx;
b2d430
+
b2d430
+    d = get_domains_head(be_ctx->domain);
b2d430
+
b2d430
+    while (d != NULL) {
b2d430
+        DEBUG(SSSDBG_TRACE_ALL, "checking [%s].\n", d->name);
b2d430
+        if (d->upn_suffixes != NULL) {
b2d430
+            break;
b2d430
+        }
b2d430
+        d = get_next_domain(d, SSS_GND_DESCEND);
b2d430
+    }
b2d430
+
b2d430
+    if (d == NULL) {
b2d430
+        DEBUG(SSSDBG_TRACE_ALL,
b2d430
+              "No UPN suffixes found, "
b2d430
+              "no need to enable enterprise principals.\n");
b2d430
+        return EOK;
b2d430
+    }
b2d430
+
b2d430
+    tmp_ctx = talloc_new(NULL);
b2d430
+    if (tmp_ctx == NULL) {
b2d430
+        DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
b2d430
+        return ENOMEM;
b2d430
+    }
b2d430
+
b2d430
+    ret = confdb_get_param(be_ctx->cdb, tmp_ctx, be_ctx->conf_path,
b2d430
+                     ipa_def_krb5_opts[KRB5_USE_ENTERPRISE_PRINCIPAL].opt_name,
b2d430
+                     &vals);
b2d430
+    if (ret != EOK) {
b2d430
+        DEBUG(SSSDBG_OP_FAILURE, "confdb_get_param failed.\n");
b2d430
+        goto done;
b2d430
+    }
b2d430
+
b2d430
+    if (vals[0]) {
b2d430
+        DEBUG(SSSDBG_CONF_SETTINGS,
b2d430
+              "Parameter [%s] set in config file and will not be changed.\n",
b2d430
+              ipa_def_krb5_opts[KRB5_USE_ENTERPRISE_PRINCIPAL].opt_name);
b2d430
+        return EOK;
b2d430
+    }
b2d430
+
b2d430
+    auth = dp_target_module(be_ctx->provider, DPT_AUTH);
b2d430
+    if (auth == NULL) {
b2d430
+        DEBUG(SSSDBG_OP_FAILURE, "Unable to find auth proivder.\n");
b2d430
+        ret = EINVAL;
b2d430
+        goto done;
b2d430
+    }
b2d430
+
b2d430
+    krb5_auth_ctx = ipa_init_get_krb5_auth_ctx(dp_get_module_data(auth));
b2d430
+    if (krb5_auth_ctx == NULL) {
b2d430
+        DEBUG(SSSDBG_OP_FAILURE, "Unable to find auth proivder data.\n");
b2d430
+        ret = EINVAL;
b2d430
+        goto done;
b2d430
+    }
b2d430
+
b2d430
+    ret = dp_opt_set_bool(krb5_auth_ctx->opts,
b2d430
+                          KRB5_USE_ENTERPRISE_PRINCIPAL, true);
b2d430
+    if (ret != EOK) {
b2d430
+        DEBUG(SSSDBG_OP_FAILURE, "dp_opt_set_bool failed.\n");
b2d430
+        goto done;
b2d430
+    }
b2d430
+
b2d430
+    DEBUG(SSSDBG_CONF_SETTINGS, "Enterprise principals enabled.\n");
b2d430
+
b2d430
+    ret = EOK;
b2d430
+
b2d430
+done:
b2d430
+    talloc_free(tmp_ctx);
b2d430
+
b2d430
+    return ret;
b2d430
+}
b2d430
+
b2d430
 static void ipa_subdomains_slave_search_done(struct tevent_req *subreq)
b2d430
 {
b2d430
     struct ipa_subdomains_slave_state *state;
b2d430
@@ -1037,6 +1116,13 @@ static void ipa_subdomains_slave_search_done(struct tevent_req *subreq)
b2d430
         goto done;
b2d430
     }
b2d430
 
b2d430
+    ret = ipa_enable_enterprise_principals(state->sd_ctx->be_ctx);
b2d430
+    if (ret != EOK) {
b2d430
+        DEBUG(SSSDBG_OP_FAILURE, "ipa_enable_enterprise_principals failed. "
b2d430
+                                 "Enterprise principals might not work as "
b2d430
+                                 "expected.\n");
b2d430
+    }
b2d430
+
b2d430
     if (state->sd_ctx->ipa_id_ctx->server_mode == NULL) {
b2d430
         ret = EOK;
b2d430
         goto done;
b2d430
-- 
b2d430
2.4.11
b2d430