From 6a1a300f694db6a186b015b6780e252a05df71f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Baumbach?= Date: Wed, 3 Jun 2020 19:40:59 +0200 Subject: [PATCH] s3-libads: use ldap_init_fd() to initialize a ldap session if possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the known ip address of the ldap server to open the connection and initialize the ldap session with ldap_init_fd(). This avoid unnecessary DNS lookups which might block or prevent the successful connection. Bug: https://bugzilla.samba.org/show_bug.cgi?id=13124 Signed-off-by: Björn Baumbach Reviewed-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett (cherry picked from commit c8080bbd708eaa3212fa516861ac9e3b267989a0) --- source3/libads/ldap.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index f0fcf9fcd56..05ee2d0b344 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -92,7 +92,23 @@ static void gotalarm_sig(int signum) return NULL; } -#ifdef HAVE_LDAP_INITIALIZE +#ifdef HAVE_LDAP_INIT_FD + { + int fd = -1; + NTSTATUS status = NT_STATUS_UNSUCCESSFUL; + + status = open_socket_out(ss, port, to, &fd); + if (!NT_STATUS_IS_OK(status)) { + return NULL; + } + +/* define LDAP_PROTO_TCP from openldap.h if required */ +#ifndef LDAP_PROTO_TCP +#define LDAP_PROTO_TCP 1 +#endif + ldap_err = ldap_init_fd(fd, LDAP_PROTO_TCP, uri, &ldp); + } +#elif defined(HAVE_LDAP_INITIALIZE) ldap_err = ldap_initialize(&ldp, uri); #else ldp = ldap_open(server, port); -- 2.26.2