dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0015-AD-Remember-last-site-discovered-in-sysdb.patch

9f2ebf
From 1be48c91f3d80b51dc2361217f5c840656e0b088 Mon Sep 17 00:00:00 2001
9f2ebf
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
9f2ebf
Date: Wed, 1 Nov 2017 14:57:17 +0100
9f2ebf
Subject: [PATCH 15/21] AD: Remember last site discovered in sysdb
9f2ebf
9f2ebf
This can speed up sssd startup.
9f2ebf
9f2ebf
Resolves:
9f2ebf
https://pagure.io/SSSD/sssd/issue/3265
9f2ebf
9f2ebf
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
9f2ebf
(cherry picked from commit fb0431b13a9fcd8ac31e622503acbd10d2b73ac9)
9f2ebf
---
9f2ebf
 src/db/sysdb_subdomains.c                 |  2 +-
9f2ebf
 src/providers/ad/ad_init.c                |  2 +-
9f2ebf
 src/providers/ad/ad_srv.c                 | 21 +++++++++++++++++++++
9f2ebf
 src/providers/ad/ad_srv.h                 |  1 +
9f2ebf
 src/providers/ad/ad_subdomains.c          |  2 +-
9f2ebf
 src/providers/ipa/ipa_subdomains_server.c |  2 +-
9f2ebf
 6 files changed, 26 insertions(+), 4 deletions(-)
9f2ebf
9f2ebf
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
9f2ebf
index cb5de1afe3e8c9692789c5d2679eb3a4e6e1cdb2..353561765904efe4bd698c38949a1b290ecf0b80 100644
9f2ebf
--- a/src/db/sysdb_subdomains.c
9f2ebf
+++ b/src/db/sysdb_subdomains.c
9f2ebf
@@ -1291,7 +1291,7 @@ sysdb_get_site(TALLOC_CTX *mem_ctx,
9f2ebf
                const char **_site)
9f2ebf
 {
9f2ebf
     TALLOC_CTX *tmp_ctx;
9f2ebf
-    struct ldb_res *res;
9f2ebf
+    struct ldb_result *res;
9f2ebf
     struct ldb_dn *dn;
9f2ebf
     const char *attrs[] = { SYSDB_SITE, NULL };
9f2ebf
     errno_t ret;
9f2ebf
diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
9f2ebf
index 131e960d4c623398506f834742400df9c786b86b..e62025d4acd24844a5c7082d00c597516f35de16 100644
9f2ebf
--- a/src/providers/ad/ad_init.c
9f2ebf
+++ b/src/providers/ad/ad_init.c
9f2ebf
@@ -199,7 +199,7 @@ static errno_t ad_init_srv_plugin(struct be_ctx *be_ctx,
9f2ebf
         return EOK;
9f2ebf
     }
9f2ebf
 
9f2ebf
-    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
9f2ebf
+    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
9f2ebf
                                      default_host_dbs, ad_options->id,
9f2ebf
                                      hostname, ad_domain,
9f2ebf
                                      ad_site_override);
9f2ebf
diff --git a/src/providers/ad/ad_srv.c b/src/providers/ad/ad_srv.c
9f2ebf
index be1ba0f237add894566ae713ce5e29fd202d414c..4fa1668605e131b2e31802b1401f49fc6e00a23b 100644
9f2ebf
--- a/src/providers/ad/ad_srv.c
9f2ebf
+++ b/src/providers/ad/ad_srv.c
9f2ebf
@@ -34,6 +34,7 @@
9f2ebf
 #include "providers/fail_over_srv.h"
9f2ebf
 #include "providers/ldap/sdap.h"
9f2ebf
 #include "providers/ldap/sdap_async.h"
9f2ebf
+#include "db/sysdb.h"
9f2ebf
 
9f2ebf
 #define AD_SITE_DOMAIN_FMT "%s._sites.%s"
9f2ebf
 
9f2ebf
@@ -475,6 +476,7 @@ int ad_get_client_site_recv(TALLOC_CTX *mem_ctx,
9f2ebf
 }
9f2ebf
 
9f2ebf
 struct ad_srv_plugin_ctx {
9f2ebf
+    struct be_ctx *be_ctx;
9f2ebf
     struct be_resolv_ctx *be_res;
9f2ebf
     enum host_database *host_dbs;
9f2ebf
     struct sdap_options *opts;
9f2ebf
@@ -486,6 +488,7 @@ struct ad_srv_plugin_ctx {
9f2ebf
 
9f2ebf
 struct ad_srv_plugin_ctx *
9f2ebf
 ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
9f2ebf
+                       struct be_ctx *be_ctx,
9f2ebf
                        struct be_resolv_ctx *be_res,
9f2ebf
                        enum host_database *host_dbs,
9f2ebf
                        struct sdap_options *opts,
9f2ebf
@@ -494,12 +497,14 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
9f2ebf
                        const char *ad_site_override)
9f2ebf
 {
9f2ebf
     struct ad_srv_plugin_ctx *ctx = NULL;
9f2ebf
+    errno_t ret;
9f2ebf
 
9f2ebf
     ctx = talloc_zero(mem_ctx, struct ad_srv_plugin_ctx);
9f2ebf
     if (ctx == NULL) {
9f2ebf
         return NULL;
9f2ebf
     }
9f2ebf
 
9f2ebf
+    ctx->be_ctx = be_ctx;
9f2ebf
     ctx->be_res = be_res;
9f2ebf
     ctx->host_dbs = host_dbs;
9f2ebf
     ctx->opts = opts;
9f2ebf
@@ -524,6 +529,15 @@ ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
9f2ebf
         if (ctx->current_site == NULL) {
9f2ebf
             goto fail;
9f2ebf
         }
9f2ebf
+    } else {
9f2ebf
+        ret = sysdb_get_site(ctx, be_ctx->domain, &ctx->current_site);
9f2ebf
+        if (ret != EOK) {
9f2ebf
+            /* Not fatal. */
9f2ebf
+            DEBUG(SSSDBG_MINOR_FAILURE,
9f2ebf
+                  "Unable to get current site from cache [%d]: %s\n",
9f2ebf
+                  ret, sss_strerror(ret));
9f2ebf
+            ctx->current_site = NULL;
9f2ebf
+        }
9f2ebf
     }
9f2ebf
 
9f2ebf
     return ctx;
9f2ebf
@@ -556,6 +570,13 @@ ad_srv_plugin_ctx_switch_site(struct ad_srv_plugin_ctx *ctx,
9f2ebf
     talloc_zfree(ctx->current_site);
9f2ebf
     ctx->current_site = site;
9f2ebf
 
9f2ebf
+    ret = sysdb_set_site(ctx->be_ctx->domain, ctx->current_site);
9f2ebf
+    if (ret != EOK) {
9f2ebf
+        /* Not fatal. */
9f2ebf
+        DEBUG(SSSDBG_MINOR_FAILURE, "Unable to store site information "
9f2ebf
+              "[%d]: %s\n", ret, sss_strerror(ret));
9f2ebf
+    }
9f2ebf
+
9f2ebf
     return EOK;
9f2ebf
 }
9f2ebf
 
9f2ebf
diff --git a/src/providers/ad/ad_srv.h b/src/providers/ad/ad_srv.h
9f2ebf
index ae5efe44755fa09f74064014cce749e35b1831da..fddef686762e57bb95d648247131d39a797aa516 100644
9f2ebf
--- a/src/providers/ad/ad_srv.h
9f2ebf
+++ b/src/providers/ad/ad_srv.h
9f2ebf
@@ -25,6 +25,7 @@ struct ad_srv_plugin_ctx;
9f2ebf
 
9f2ebf
 struct ad_srv_plugin_ctx *
9f2ebf
 ad_srv_plugin_ctx_init(TALLOC_CTX *mem_ctx,
9f2ebf
+                       struct be_ctx *be_ctx,
9f2ebf
                        struct be_resolv_ctx *be_res,
9f2ebf
                        enum host_database *host_dbs,
9f2ebf
                        struct sdap_options *opts,
9f2ebf
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
9f2ebf
index 280aa54c23bf61e60d23ea91bd44a39f9f43d155..3fb9b950f171d85817cce35ac92ad7c4974ccb68 100644
9f2ebf
--- a/src/providers/ad/ad_subdomains.c
9f2ebf
+++ b/src/providers/ad/ad_subdomains.c
9f2ebf
@@ -245,7 +245,7 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
9f2ebf
     ad_options->id_ctx = ad_id_ctx;
9f2ebf
 
9f2ebf
     /* use AD plugin */
9f2ebf
-    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
9f2ebf
+    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
9f2ebf
                                      default_host_dbs,
9f2ebf
                                      ad_id_ctx->ad_options->id,
9f2ebf
                                      hostname,
9f2ebf
diff --git a/src/providers/ipa/ipa_subdomains_server.c b/src/providers/ipa/ipa_subdomains_server.c
9f2ebf
index 10166d162f746fde176e6c7c2bfbe3906b1bfddc..d670a156b37608d20d49d79131138f02e4abf82b 100644
9f2ebf
--- a/src/providers/ipa/ipa_subdomains_server.c
9f2ebf
+++ b/src/providers/ipa/ipa_subdomains_server.c
9f2ebf
@@ -305,7 +305,7 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
9f2ebf
     ad_site_override = dp_opt_get_string(ad_options->basic, AD_SITE);
9f2ebf
 
9f2ebf
     /* use AD plugin */
9f2ebf
-    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx->be_res,
9f2ebf
+    srv_ctx = ad_srv_plugin_ctx_init(be_ctx, be_ctx, be_ctx->be_res,
9f2ebf
                                      default_host_dbs,
9f2ebf
                                      ad_id_ctx->ad_options->id,
9f2ebf
                                      id_ctx->server_mode->hostname,
9f2ebf
-- 
9f2ebf
2.13.5
9f2ebf