Blame SOURCES/0083-cldap-use-dns_resolver_server_timeout-timeout-for-cl.patch

5a92ae
From be3ee30c68dd9d2e5184da226dfbe66f516a4b92 Mon Sep 17 00:00:00 2001
5a92ae
From: Sumit Bose <sbose@redhat.com>
5a92ae
Date: Tue, 16 Nov 2021 15:01:20 +0100
5a92ae
Subject: [PATCH 83/83] cldap: use dns_resolver_server_timeout timeout for
5a92ae
 cldap ping
5a92ae
MIME-Version: 1.0
5a92ae
Content-Type: text/plain; charset=UTF-8
5a92ae
Content-Transfer-Encoding: 8bit
5a92ae
5a92ae
Currently the cldap ping is using the ldap_search_timeout since it is
5a92ae
basically a LDAP search operation. However, the default of
5a92ae
ldap_search_timeout is 6s which is quite a long time for the discovery
5a92ae
of the AD DCs where the cldap ping is a part of. The default even
5a92ae
collides which the default of dns_resolver_timeout which might easily
5a92ae
lead to failures during the discovery phase.
5a92ae
5a92ae
To avoid the addition of a new option this patch is using
5a92ae
dns_resolver_server_timeout, which has a default of 1000ms (1s), as new
5a92ae
timeout for the clapd ping. Since the original purpose of the timeout is
5a92ae
the waiting time for a reply from a DNS server and both DNS and cldap by
5a92ae
default use UDP I think reusing the option here is justified.
5a92ae
5a92ae
Resolves: https://github.com/SSSD/sssd/issues/5875
5a92ae
5a92ae
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
5a92ae
(cherry picked from commit c0941810fc3c3d74a00697349723f14e2f6bbdd2)
5a92ae
5a92ae
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
5a92ae
---
5a92ae
 src/man/sssd.conf.5.xml          |  4 ++++
5a92ae
 src/providers/ad/ad_cldap_ping.c | 10 +++++++++-
5a92ae
 2 files changed, 13 insertions(+), 1 deletion(-)
5a92ae
5a92ae
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
5a92ae
index a597828ca..d81ec35a6 100644
5a92ae
--- a/src/man/sssd.conf.5.xml
5a92ae
+++ b/src/man/sssd.conf.5.xml
5a92ae
@@ -2817,6 +2817,10 @@ pam_p11_allowed_services = +my_pam_service, -login
5a92ae
                             SSSD would try to talk to DNS server before
5a92ae
                             trying next DNS server.
5a92ae
                         </para>
5a92ae
+                        <para>
5a92ae
+                                The AD provider will use this option for the
5a92ae
+                                CLDAP ping timeouts as well.
5a92ae
+                        </para>
5a92ae
                         <para>
5a92ae
                             Please see the section <quote>FAILOVER</quote>
5a92ae
                             for more information about the service
5a92ae
diff --git a/src/providers/ad/ad_cldap_ping.c b/src/providers/ad/ad_cldap_ping.c
5a92ae
index 91db81bfc..8ae65e8c9 100644
5a92ae
--- a/src/providers/ad/ad_cldap_ping.c
5a92ae
+++ b/src/providers/ad/ad_cldap_ping.c
5a92ae
@@ -39,6 +39,7 @@
5a92ae
 struct ad_cldap_ping_dc_state {
5a92ae
     struct tevent_context *ev;
5a92ae
     struct sdap_options *opts;
5a92ae
+    struct be_resolv_ctx *be_res;
5a92ae
     struct fo_server_info *dc;
5a92ae
     struct sdap_handle *sh;
5a92ae
     const char *ad_domain;
5a92ae
@@ -72,6 +73,7 @@ static struct tevent_req *ad_cldap_ping_dc_send(TALLOC_CTX *mem_ctx,
5a92ae
 
5a92ae
     state->ev = ev;
5a92ae
     state->opts = opts;
5a92ae
+    state->be_res = be_res;
5a92ae
     state->dc = dc;
5a92ae
     state->ad_domain = ad_domain;
5a92ae
 
5a92ae
@@ -103,6 +105,7 @@ static void ad_cldap_ping_dc_connect_done(struct tevent_req *subreq)
5a92ae
     char *filter;
5a92ae
     int timeout;
5a92ae
     errno_t ret;
5a92ae
+    div_t timeout_int;
5a92ae
 
5a92ae
     req = tevent_req_callback_data(subreq, struct tevent_req);
5a92ae
     state = tevent_req_data(req, struct ad_cldap_ping_dc_state);
5a92ae
@@ -127,7 +130,12 @@ static void ad_cldap_ping_dc_connect_done(struct tevent_req *subreq)
5a92ae
         goto done;
5a92ae
     }
5a92ae
 
5a92ae
-    timeout = dp_opt_get_int(state->opts->basic, SDAP_SEARCH_TIMEOUT);
5a92ae
+    /* DP_RES_OPT_RESOLVER_SERVER_TIMEOUT is in milli-seconds and
5a92ae
+     * sdap_get_generic_send() expects seconds */
5a92ae
+    timeout_int = div(dp_opt_get_int(state->be_res->opts,
5a92ae
+                                     DP_RES_OPT_RESOLVER_SERVER_TIMEOUT),
5a92ae
+                      1000);
5a92ae
+    timeout = (timeout_int.quot > 0) ? timeout_int.quot : 1;
5a92ae
     subreq = sdap_get_generic_send(state, state->ev, state->opts, state->sh, "",
5a92ae
                                    LDAP_SCOPE_BASE, filter, attrs, NULL,
5a92ae
                                    0, timeout, false);
5a92ae
-- 
5a92ae
2.26.3
5a92ae