Blame SOURCES/0005-AD-IPA-Create-kdcinfo-file-for-sub-domains.patch

cdf651
From 660ef95e36ad73b4715656a4207aeb499ac96d16 Mon Sep 17 00:00:00 2001
cdf651
From: Sumit Bose <sbose@redhat.com>
cdf651
Date: Thu, 24 May 2018 17:15:38 +0200
cdf651
Subject: [PATCH] AD/IPA: Create kdcinfo file for sub-domains
cdf651
cdf651
With this patch kdcinfo files are created for sub-domains by the AD
cdf651
provider and by the IPA provider on the IPA servers
cdf651
(ipa_server_mode=True).
cdf651
cdf651
Related to https://pagure.io/SSSD/sssd/issue/3652
cdf651
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
cdf651
cdf651
(cherry picked from commit cc7922755dac53c69558ba060b309ac48ae82783)
cdf651
---
cdf651
 src/providers/ad/ad_common.c              |  9 +++++++++
cdf651
 src/providers/ad/ad_common.h              |  1 +
cdf651
 src/providers/ad/ad_init.c                |  1 +
cdf651
 src/providers/ad/ad_subdomains.c          | 17 ++++++++++++++---
cdf651
 src/providers/ipa/ipa_subdomains_server.c | 16 ++++++++++++++--
cdf651
 5 files changed, 39 insertions(+), 5 deletions(-)
cdf651
cdf651
diff --git a/src/providers/ad/ad_common.c b/src/providers/ad/ad_common.c
cdf651
index be7791e6cc2527d45d3e2ff50294f9b98106ffae..0aea985e00faa996643fd7e7630d4264fb6cf233 100644
cdf651
--- a/src/providers/ad/ad_common.c
cdf651
+++ b/src/providers/ad/ad_common.c
cdf651
@@ -727,6 +727,7 @@ ad_failover_init(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
cdf651
                  const char *ad_service,
cdf651
                  const char *ad_gc_service,
cdf651
                  const char *ad_domain,
cdf651
+                 bool use_kdcinfo,
cdf651
                  struct ad_service **_service)
cdf651
 {
cdf651
     errno_t ret;
cdf651
@@ -762,6 +763,14 @@ ad_failover_init(TALLOC_CTX *mem_ctx, struct be_ctx *bectx,
cdf651
         goto done;
cdf651
     }
cdf651
 
cdf651
+    /* Set flag that controls whether we want to write the
cdf651
+     * kdcinfo files at all
cdf651
+     */
cdf651
+    service->krb5_service->write_kdcinfo = use_kdcinfo;
cdf651
+    DEBUG(SSSDBG_CONF_SETTINGS, "write_kdcinfo for realm %s set to %s\n",
cdf651
+                       krb5_realm,
cdf651
+                       service->krb5_service->write_kdcinfo ? "true" : "false");
cdf651
+
cdf651
     ret = be_fo_add_service(bectx, ad_service, ad_user_data_cmp);
cdf651
     if (ret != EOK) {
cdf651
         DEBUG(SSSDBG_CRIT_FAILURE, "Failed to create failover service!\n");
cdf651
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
cdf651
index 6eb2ba7e9a7350d1924c45d33d8c332073767a34..dd440da33d48a5820c665f43908d1e1fb18171a6 100644
cdf651
--- a/src/providers/ad/ad_common.h
cdf651
+++ b/src/providers/ad/ad_common.h
cdf651
@@ -144,6 +144,7 @@ ad_failover_init(TALLOC_CTX *mem_ctx, struct be_ctx *ctx,
cdf651
                  const char *ad_service,
cdf651
                  const char *ad_gc_service,
cdf651
                  const char *ad_domain,
cdf651
+                 bool use_kdcinfo,
cdf651
                  struct ad_service **_service);
cdf651
 
cdf651
 errno_t
cdf651
diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
cdf651
index b19624782000c5c7c65e766e3e01ff6ac3ab7adb..637efb761c1cf87b0a2c2b1c19b00ea0bbbe161f 100644
cdf651
--- a/src/providers/ad/ad_init.c
cdf651
+++ b/src/providers/ad/ad_init.c
cdf651
@@ -159,6 +159,7 @@ static errno_t ad_init_options(TALLOC_CTX *mem_ctx,
cdf651
     ret = ad_failover_init(ad_options, be_ctx, ad_servers, ad_backup_servers,
cdf651
                            ad_realm, AD_SERVICE_NAME, AD_GC_SERVICE_NAME,
cdf651
                            dp_opt_get_string(ad_options->basic, AD_DOMAIN),
cdf651
+                           false, /* will be set in ad_get_auth_options() */
cdf651
                            &ad_options->service);
cdf651
     if (ret != EOK) {
cdf651
         DEBUG(SSSDBG_FATAL_FAILURE, "Failed to init AD failover service: "
cdf651
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
cdf651
index 74b9f075174b1eaa6c5b5dcbaf609600ef197b52..84886e920b37f8803d85ce0903b74e6c809a8904 100644
cdf651
--- a/src/providers/ad/ad_subdomains.c
cdf651
+++ b/src/providers/ad/ad_subdomains.c
cdf651
@@ -249,6 +249,7 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
cdf651
     const char *hostname;
cdf651
     const char *keytab;
cdf651
     char *subdom_conf_path;
cdf651
+    bool use_kdcinfo = false;
cdf651
 
cdf651
     realm = dp_opt_get_cstring(id_ctx->ad_options->basic, AD_KRB5_REALM);
cdf651
     hostname = dp_opt_get_cstring(id_ctx->ad_options->basic, AD_HOSTNAME);
cdf651
@@ -296,9 +297,19 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
cdf651
     servers = dp_opt_get_string(ad_options->basic, AD_SERVER);
cdf651
     backup_servers = dp_opt_get_string(ad_options->basic, AD_BACKUP_SERVER);
cdf651
 
cdf651
-    ret = ad_failover_init(ad_options, be_ctx, servers, backup_servers, realm,
cdf651
-                           service_name, gc_service_name,
cdf651
-                           subdom->name, &ad_options->service);
cdf651
+    if (id_ctx->ad_options->auth_ctx != NULL
cdf651
+            && id_ctx->ad_options->auth_ctx->opts != NULL) {
cdf651
+        use_kdcinfo = dp_opt_get_bool(id_ctx->ad_options->auth_ctx->opts,
cdf651
+                                      KRB5_USE_KDCINFO);
cdf651
+    }
cdf651
+
cdf651
+    DEBUG(SSSDBG_TRACE_ALL,
cdf651
+          "Init failover for [%s][%s] with use_kdcinfo [%s].\n",
cdf651
+          subdom->name, subdom->realm, use_kdcinfo ? "true" : "false");
cdf651
+
cdf651
+    ret = ad_failover_init(ad_options, be_ctx, servers, backup_servers,
cdf651
+                           subdom->realm, service_name, gc_service_name,
cdf651
+                           subdom->name, use_kdcinfo, &ad_options->service);
cdf651
     if (ret != EOK) {
cdf651
         DEBUG(SSSDBG_OP_FAILURE, "Cannot initialize AD failover\n");
cdf651
         talloc_free(ad_options);
cdf651
diff --git a/src/providers/ipa/ipa_subdomains_server.c b/src/providers/ipa/ipa_subdomains_server.c
cdf651
index 1e53e7a951189120fcf3f438362e902a5a8f6d97..02577c92159d099a04cbd5cee80064309466db93 100644
cdf651
--- a/src/providers/ipa/ipa_subdomains_server.c
cdf651
+++ b/src/providers/ipa/ipa_subdomains_server.c
cdf651
@@ -228,6 +228,7 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
cdf651
     struct sdap_domain *sdom;
cdf651
     errno_t ret;
cdf651
     const char *extra_attrs;
cdf651
+    bool use_kdcinfo = false;
cdf651
 
cdf651
     ad_domain = subdom->name;
cdf651
     DEBUG(SSSDBG_TRACE_LIBS, "Setting up AD subdomain %s\n", subdom->name);
cdf651
@@ -284,12 +285,23 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
cdf651
     ad_servers = dp_opt_get_string(ad_options->basic, AD_SERVER);
cdf651
     ad_backup_servers = dp_opt_get_string(ad_options->basic, AD_BACKUP_SERVER);
cdf651
 
cdf651
+    if (id_ctx->ipa_options != NULL && id_ctx->ipa_options->auth != NULL) {
cdf651
+        use_kdcinfo = dp_opt_get_bool(id_ctx->ipa_options->auth,
cdf651
+                                      KRB5_USE_KDCINFO);
cdf651
+    }
cdf651
+
cdf651
+    DEBUG(SSSDBG_TRACE_ALL,
cdf651
+          "Init failover for [%s][%s] with use_kdcinfo [%s].\n",
cdf651
+          subdom->name, subdom->realm, use_kdcinfo ? "true" : "false");
cdf651
+
cdf651
     /* Set KRB5 realm to same as the one of IPA when IPA
cdf651
      * is able to attach PAC. For testing, use hardcoded. */
cdf651
+    /* Why? */
cdf651
     ret = ad_failover_init(ad_options, be_ctx, ad_servers, ad_backup_servers,
cdf651
-                           id_ctx->server_mode->realm,
cdf651
+                           subdom->realm,
cdf651
                            service_name, gc_service_name,
cdf651
-                           subdom->name, &ad_options->service);
cdf651
+                           subdom->name, use_kdcinfo,
cdf651
+                           &ad_options->service);
cdf651
     if (ret != EOK) {
cdf651
         DEBUG(SSSDBG_OP_FAILURE, "Cannot initialize AD failover\n");
cdf651
         talloc_free(ad_options);
cdf651
-- 
cdf651
2.17.1
cdf651