adf540
Fix back-ldap to respect the user configured timeout
adf540
adf540
Upstream: ITS#8720
adf540
Resolves: #1540336
adf540
adf540
diff --git a/servers/slapd/back-ldap/back-ldap.h b/servers/slapd/back-ldap/back-ldap.h
adf540
index 1e2c14a..e35f622 100644
adf540
--- a/servers/slapd/back-ldap/back-ldap.h
adf540
+++ b/servers/slapd/back-ldap/back-ldap.h
adf540
@@ -89,6 +89,7 @@ typedef struct ldapconn_base_t {
adf540
 	(BER_BVISEMPTY(&(op)->o_ndn) ? \
adf540
 		LDAP_BACK_PCONN_ANON_SET((lc), (op)) : LDAP_BACK_PCONN_ROOTDN_SET((lc), (op)))
adf540
 
adf540
+    struct ldapinfo_t   *lcb_ldapinfo;
adf540
 	struct berval		lcb_local_ndn;
adf540
 	unsigned		lcb_refcnt;
adf540
 	time_t			lcb_create_time;
adf540
@@ -98,6 +99,7 @@ typedef struct ldapconn_base_t {
adf540
 typedef struct ldapconn_t {
adf540
 	ldapconn_base_t		lc_base;
adf540
 #define	lc_conn			lc_base.lcb_conn
adf540
+#define	lc_ldapinfo			lc_base.lcb_ldapinfo
adf540
 #define	lc_local_ndn		lc_base.lcb_local_ndn
adf540
 #define	lc_refcnt		lc_base.lcb_refcnt
adf540
 #define	lc_create_time		lc_base.lcb_create_time
adf540
diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c
adf540
index ff759d7..7808f7a 100644
adf540
--- a/servers/slapd/back-ldap/bind.c
adf540
+++ b/servers/slapd/back-ldap/bind.c
adf540
@@ -532,7 +532,7 @@ ldap_back_start_tls(
adf540
 	int		*is_tls,
adf540
 	const char	*url,
adf540
 	unsigned	flags,
adf540
-	int		retries,
adf540
+	int		timeout,
adf540
 	const char	**text )
adf540
 {
adf540
 	int		rc = LDAP_SUCCESS;
adf540
@@ -567,22 +567,14 @@ ldap_back_start_tls(
adf540
 			LDAPMessage	*res = NULL;
adf540
 			struct timeval	tv;
adf540
 
adf540
-			LDAP_BACK_TV_SET( &tv );
adf540
-
adf540
-retry:;
adf540
+            if ( timeout ) {
adf540
+                tv.tv_sec = timeout;
adf540
+                tv.tv_usec = 0;
adf540
+            } else {
adf540
+                LDAP_BACK_TV_SET( &tv );
adf540
+            }
adf540
 			rc = ldap_result( ld, msgid, LDAP_MSG_ALL, &tv, &res );
adf540
-			if ( rc < 0 ) {
adf540
-				rc = LDAP_UNAVAILABLE;
adf540
-
adf540
-			} else if ( rc == 0 ) {
adf540
-				if ( retries != LDAP_BACK_RETRY_NEVER ) {
adf540
-					ldap_pvt_thread_yield();
adf540
-					if ( retries > 0 ) {
adf540
-						retries--;
adf540
-					}
adf540
-					LDAP_BACK_TV_SET( &tv );
adf540
-					goto retry;
adf540
-				}
adf540
+            if ( rc <= 0 ) {
adf540
 				rc = LDAP_UNAVAILABLE;
adf540
 
adf540
 			} else if ( rc == LDAP_RES_EXTENDED ) {
adf540
@@ -754,7 +746,7 @@ ldap_back_prepare_conn( ldapconn_t *lc, Operation *op, SlapReply *rs, ldap_back_
adf540
 	assert( li->li_uri_mutex_do_not_lock == 0 );
adf540
 	li->li_uri_mutex_do_not_lock = 1;
adf540
 	rs->sr_err = ldap_back_start_tls( ld, op->o_protocol, &is_tls,
adf540
-			li->li_uri, flags, li->li_nretries, &rs->sr_text );
adf540
+			li->li_uri, flags, li->li_timeout[ SLAP_OP_EXTENDED ], &rs->sr_text );
adf540
 	li->li_uri_mutex_do_not_lock = 0;
adf540
 	ldap_pvt_thread_mutex_unlock( &li->li_uri_mutex );
adf540
 	if ( rs->sr_err != LDAP_SUCCESS ) {
adf540
@@ -980,6 +972,7 @@ retry_lock:
adf540
 		lc = (ldapconn_t *)ch_calloc( 1, sizeof( ldapconn_t ) );
adf540
 		lc->lc_flags = li->li_flags;
adf540
 		lc->lc_lcflags = lc_curr.lc_lcflags;
adf540
+		lc->lc_ldapinfo = li;
adf540
 		if ( ldap_back_prepare_conn( lc, op, rs, sendok ) != LDAP_SUCCESS ) {
adf540
 			ch_free( lc );
adf540
 			return NULL;
adf540
@@ -1649,7 +1642,7 @@ ldap_back_default_rebind( LDAP *ld, LDAP_CONST char *url, ber_tag_t request,
adf540
 		const char	*text = NULL;
adf540
 
adf540
 		rc = ldap_back_start_tls( ld, 0, &is_tls, url, lc->lc_flags,
adf540
-			LDAP_BACK_RETRY_DEFAULT, &text );
adf540
+			lc->lc_ldapinfo->li_timeout[ SLAP_OP_EXTENDED ], &text );
adf540
 		if ( rc != LDAP_SUCCESS ) {
adf540
 			return rc;
adf540
 		}