mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone

Blame SOURCES/openldap-ITS8720-back-ldap-starttls-timeout.patch

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