From d8b234648cbc18c02d2c79a32be766080c61b42a Mon Sep 17 00:00:00 2001 From: Björn Jacke Date: Mon, 26 May 2008 11:29:24 +0200 Subject: Add ldap connection timeout for OpenLDAP and Netscape LDAP libs. This can be controlled via the ldap connection timeout parameter. This fixes fallbacks to secondary LDAP servers in multi LDAP server setups like in #4544 (This used to be commit 8e59a2fedc940b081222b0e8f90fe0c5a0981c06) --- source3/lib/smbldap.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index 9fb16f8927..c2c58c0abf 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -672,9 +672,33 @@ int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri) return LDAP_OPERATIONS_ERROR; #endif /* LDAP_OPT_X_TLS */ } - } #endif /* HAVE_LDAP_INITIALIZE */ + + + /* now set connection timeout */ +#ifdef LDAP_X_OPT_CONNECT_TIMEOUT /* Netscape */ + { + int ct = lp_ldap_connection_timeout()*1000; + rc = ldap_set_option(*ldap_struct, LDAP_X_OPT_CONNECT_TIMEOUT, &ct); + if (rc != LDAP_SUCCESS) { + DEBUG(0,("Failed to setup an ldap connection timeout %d: %s\n", + ct, ldap_err2string(rc))); + } + } +#elif defined (LDAP_OPT_NETWORK_TIMEOUT) /* OpenLDAP */ + { + struct timeval ct; + ct.tv_usec = 0; + ct.tv_sec = lp_ldap_connection_timeout(); + rc = ldap_set_option(*ldap_struct, LDAP_OPT_NETWORK_TIMEOUT, &ct); + if (rc != LDAP_SUCCESS) { + DEBUG(0,("Failed to setup an ldap connection timeout %d: %s\n", + ct.tv_sec, ldap_err2string(rc))); + } + } +#endif + return LDAP_SUCCESS; } -- cgit