Blame SOURCES/0079-ad-move-current-site-and-forest-name-to-a-more-globa.patch

5a92ae
From ecfb7df52fd3b0edf8549d42cfa6b378407fb982 Mon Sep 17 00:00:00 2001
5a92ae
From: Sumit Bose <sbose@redhat.com>
5a92ae
Date: Fri, 8 Oct 2021 13:14:30 +0200
5a92ae
Subject: [PATCH 79/83] ad: move current site and forest name to a more global
5a92ae
 context
5a92ae
MIME-Version: 1.0
5a92ae
Content-Type: text/plain; charset=UTF-8
5a92ae
Content-Transfer-Encoding: 8bit
5a92ae
5a92ae
Currently only during the DNS discovery steps the stored forest and site
5a92ae
name are reused to avoid redundant lookups. Since those names are needed
5a92ae
in other areas of the code as well it would be good to make them
5a92ae
available in a more global context.
5a92ae
5a92ae
Resolves: https://github.com/SSSD/sssd/issues/5820
5a92ae
5a92ae
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
5a92ae
(cherry picked from commit 4508ef5f7183c640191393605ea163044d9ac267)
5a92ae
5a92ae
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
5a92ae
---
5a92ae
 src/providers/ad/ad_cldap_ping.c          | 15 ++++++-----
5a92ae
 src/providers/ad/ad_common.h              |  4 +++
5a92ae
 src/providers/ad/ad_init.c                |  1 +
5a92ae
 src/providers/ad/ad_srv.c                 | 33 +++++++++++++----------
5a92ae
 src/providers/ad/ad_srv.h                 |  4 +--
5a92ae
 src/providers/ad/ad_subdomains.c          |  1 +
5a92ae
 src/providers/ipa/ipa_subdomains_server.c |  1 +
5a92ae
 7 files changed, 37 insertions(+), 22 deletions(-)
5a92ae
5a92ae
diff --git a/src/providers/ad/ad_cldap_ping.c b/src/providers/ad/ad_cldap_ping.c
5a92ae
index ab234f4d7..100d448f5 100644
5a92ae
--- a/src/providers/ad/ad_cldap_ping.c
5a92ae
+++ b/src/providers/ad/ad_cldap_ping.c
5a92ae
@@ -601,10 +601,12 @@ struct tevent_req *ad_cldap_ping_send(TALLOC_CTX *mem_ctx,
5a92ae
     }
5a92ae
 
5a92ae
     if (!srv_ctx->renew_site) {
5a92ae
-        state->site = talloc_strdup(state, srv_ctx->current_site);
5a92ae
-        state->forest = talloc_strdup(state, srv_ctx->current_forest);
5a92ae
-        if ((srv_ctx->current_site != NULL && state->site == NULL)
5a92ae
-                || (srv_ctx->current_forest != NULL && state->forest == NULL)) {
5a92ae
+        state->site = talloc_strdup(state, srv_ctx->ad_options->current_site);
5a92ae
+        state->forest = talloc_strdup(state,
5a92ae
+                                      srv_ctx->ad_options->current_forest);
5a92ae
+        if ((srv_ctx->ad_options->current_site != NULL && state->site == NULL)
5a92ae
+                || (srv_ctx->ad_options->current_forest != NULL
5a92ae
+                                    && state->forest == NULL)) {
5a92ae
             DEBUG(SSSDBG_OP_FAILURE,
5a92ae
                   "Failed to copy current site or forest name.\n");
5a92ae
             ret = ENOMEM;
5a92ae
@@ -629,9 +631,10 @@ struct tevent_req *ad_cldap_ping_send(TALLOC_CTX *mem_ctx,
5a92ae
     state->discovery_domain = discovery_domain;
5a92ae
 
5a92ae
     /* If possible, lookup the information in the current site first. */
5a92ae
-    if (srv_ctx->current_site != NULL) {
5a92ae
+    if (srv_ctx->ad_options->current_site != NULL) {
5a92ae
         state->all_tried = false;
5a92ae
-        domain = ad_site_dns_discovery_domain(state, srv_ctx->current_site,
5a92ae
+        domain = ad_site_dns_discovery_domain(state,
5a92ae
+                                              srv_ctx->ad_options->current_site,
5a92ae
                                               discovery_domain);
5a92ae
         if (domain == NULL) {
5a92ae
             DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory!");
5a92ae
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
5a92ae
index 815b41419..311b84f4c 100644
5a92ae
--- a/src/providers/ad/ad_common.h
5a92ae
+++ b/src/providers/ad/ad_common.h
5a92ae
@@ -105,6 +105,10 @@ struct ad_options {
5a92ae
     /* Dynamic DNS updates */
5a92ae
     struct be_resolv_ctx *be_res;
5a92ae
     struct be_nsupdate_ctx *dyndns_ctx;
5a92ae
+
5a92ae
+    /* Discovered site and forest names */
5a92ae
+    const char *current_site;
5a92ae
+    const char *current_forest;
5a92ae
 };
5a92ae
 
5a92ae
 errno_t
5a92ae
diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
5a92ae
index 5abd28b7c..9f258e2bd 100644
5a92ae
--- a/src/providers/ad/ad_init.c
5a92ae
+++ b/src/providers/ad/ad_init.c
5a92ae
@@ -206,6 +206,7 @@ static errno_t ad_init_srv_plugin(struct be_ctx *be_ctx,
5a92ae
 
5a92ae
     srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
5a92ae
                                      default_host_dbs, ad_options->id,
5a92ae
+                                     ad_options,
5a92ae
                                      hostname, ad_domain,
5a92ae
                                      ad_site_override);
5a92ae
     if (srv_ctx == NULL) {
5a92ae
diff --git a/src/providers/ad/ad_srv.c b/src/providers/ad/ad_srv.c
5a92ae
index e58c19aac..a10c6a247 100644
5a92ae
--- a/src/providers/ad/ad_srv.c
5a92ae
+++ b/src/providers/ad/ad_srv.c
5a92ae
@@ -130,6 +130,7 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
5a92ae
                        struct be_resolv_ctx *be_res,
5a92ae
                        enum host_database *host_dbs,
5a92ae
                        struct sdap_options *opts,
5a92ae
+                       struct ad_options *ad_options,
5a92ae
                        const char *hostname,
5a92ae
                        const char *ad_domain,
5a92ae
                        const char *ad_site_override)
5a92ae
@@ -147,6 +148,7 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
5a92ae
     ctx->host_dbs = host_dbs;
5a92ae
     ctx->opts = opts;
5a92ae
     ctx->renew_site = true;
5a92ae
+    ctx->ad_options = ad_options;
5a92ae
 
5a92ae
     ctx->hostname = talloc_strdup(ctx, hostname);
5a92ae
     if (ctx->hostname == NULL) {
5a92ae
@@ -164,18 +166,20 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
5a92ae
             goto fail;
5a92ae
         }
5a92ae
 
5a92ae
-        ctx->current_site = talloc_strdup(ctx, ad_site_override);
5a92ae
-        if (ctx->current_site == NULL) {
5a92ae
+        ctx->ad_options->current_site = talloc_strdup(ctx->ad_options,
5a92ae
+                                                      ad_site_override);
5a92ae
+        if (ctx->ad_options->current_site == NULL) {
5a92ae
             goto fail;
5a92ae
         }
5a92ae
     } else {
5a92ae
-        ret = sysdb_get_site(ctx, be_ctx->domain, &ctx->current_site);
5a92ae
+        ret = sysdb_get_site(ctx->ad_options, be_ctx->domain,
5a92ae
+                             &ctx->ad_options->current_site);
5a92ae
         if (ret != EOK) {
5a92ae
             /* Not fatal. */
5a92ae
             DEBUG(SSSDBG_MINOR_FAILURE,
5a92ae
                   "Unable to get current site from cache [%d]: %s\n",
5a92ae
                   ret, sss_strerror(ret));
5a92ae
-            ctx->current_site = NULL;
5a92ae
+            ctx->ad_options->current_site = NULL;
5a92ae
         }
5a92ae
     }
5a92ae
 
5a92ae
@@ -203,34 +207,35 @@ ad_srv_plugin_ctx_switch_site(struct ad_srv_plugin_ctx *ctx,
5a92ae
 
5a92ae
     /* Switch forest. */
5a92ae
     if (new_forest != NULL
5a92ae
-        && (ctx->current_forest == NULL
5a92ae
-            || strcmp(ctx->current_forest, new_forest) != 0)) {
5a92ae
-        forest = talloc_strdup(ctx, new_forest);
5a92ae
+        && (ctx->ad_options->current_forest == NULL
5a92ae
+            || strcmp(ctx->ad_options->current_forest, new_forest) != 0)) {
5a92ae
+        forest = talloc_strdup(ctx->ad_options, new_forest);
5a92ae
         if (forest == NULL) {
5a92ae
             return ENOMEM;
5a92ae
         }
5a92ae
 
5a92ae
-        talloc_zfree(ctx->current_forest);
5a92ae
-        ctx->current_forest = forest;
5a92ae
+        talloc_zfree(ctx->ad_options->current_forest);
5a92ae
+        ctx->ad_options->current_forest = forest;
5a92ae
     }
5a92ae
 
5a92ae
     if (new_site == NULL) {
5a92ae
         return EOK;
5a92ae
     }
5a92ae
 
5a92ae
-    if (ctx->current_site != NULL && strcmp(ctx->current_site, new_site) == 0) {
5a92ae
+    if (ctx->ad_options->current_site != NULL
5a92ae
+                    && strcmp(ctx->ad_options->current_site, new_site) == 0) {
5a92ae
         return EOK;
5a92ae
     }
5a92ae
 
5a92ae
-    site = talloc_strdup(ctx, new_site);
5a92ae
+    site = talloc_strdup(ctx->ad_options, new_site);
5a92ae
     if (site == NULL) {
5a92ae
         return ENOMEM;
5a92ae
     }
5a92ae
 
5a92ae
-    talloc_zfree(ctx->current_site);
5a92ae
-    ctx->current_site = site;
5a92ae
+    talloc_zfree(ctx->ad_options->current_site);
5a92ae
+    ctx->ad_options->current_site = site;
5a92ae
 
5a92ae
-    ret = sysdb_set_site(ctx->be_ctx->domain, ctx->current_site);
5a92ae
+    ret = sysdb_set_site(ctx->be_ctx->domain, ctx->ad_options->current_site);
5a92ae
     if (ret != EOK) {
5a92ae
         /* Not fatal. */
5a92ae
         DEBUG(SSSDBG_MINOR_FAILURE, "Unable to store site information "
5a92ae
diff --git a/src/providers/ad/ad_srv.h b/src/providers/ad/ad_srv.h
5a92ae
index 3c6a779ea..fd70f15a8 100644
5a92ae
--- a/src/providers/ad/ad_srv.h
5a92ae
+++ b/src/providers/ad/ad_srv.h
5a92ae
@@ -26,11 +26,10 @@ struct ad_srv_plugin_ctx {
5a92ae
     struct be_resolv_ctx *be_res;
5a92ae
     enum host_database *host_dbs;
5a92ae
     struct sdap_options *opts;
5a92ae
+    struct ad_options *ad_options;
5a92ae
     const char *hostname;
5a92ae
     const char *ad_domain;
5a92ae
     const char *ad_site_override;
5a92ae
-    const char *current_site;
5a92ae
-    const char *current_forest;
5a92ae
 
5a92ae
     bool renew_site;
5a92ae
 };
5a92ae
@@ -41,6 +40,7 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
5a92ae
                        struct be_resolv_ctx *be_res,
5a92ae
                        enum host_database *host_dbs,
5a92ae
                        struct sdap_options *opts,
5a92ae
+                       struct ad_options *ad_options,
5a92ae
                        const char *hostname,
5a92ae
                        const char *ad_domain,
5a92ae
                        const char *ad_site_override);
5a92ae
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
5a92ae
index 5be7c2003..8a331c503 100644
5a92ae
--- a/src/providers/ad/ad_subdomains.c
5a92ae
+++ b/src/providers/ad/ad_subdomains.c
5a92ae
@@ -416,6 +416,7 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
5a92ae
     srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
5a92ae
                                      default_host_dbs,
5a92ae
                                      ad_id_ctx->ad_options->id,
5a92ae
+                                     ad_id_ctx->ad_options,
5a92ae
                                      hostname,
5a92ae
                                      ad_domain,
5a92ae
                                      ad_site_override);
5a92ae
diff --git a/src/providers/ipa/ipa_subdomains_server.c b/src/providers/ipa/ipa_subdomains_server.c
5a92ae
index f0d8a6a20..ed363c22f 100644
5a92ae
--- a/src/providers/ipa/ipa_subdomains_server.c
5a92ae
+++ b/src/providers/ipa/ipa_subdomains_server.c
5a92ae
@@ -342,6 +342,7 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
5a92ae
     srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
5a92ae
                                      default_host_dbs,
5a92ae
                                      ad_id_ctx->ad_options->id,
5a92ae
+                                     ad_id_ctx->ad_options,
5a92ae
                                      id_ctx->server_mode->hostname,
5a92ae
                                      ad_domain,
5a92ae
                                      ad_site_override);
5a92ae
-- 
5a92ae
2.26.3
5a92ae