Blame SOURCES/openldap-chase-referral.patch

5fcfe9
diff -up openldap-2.3.43/libraries/libldap/os-ip.c.orig openldap-2.3.43/libraries/libldap/os-ip.c
5fcfe9
--- openldap-2.3.43/libraries/libldap/os-ip.c.orig	2008-05-19 19:28:54.000000000 -0400
5fcfe9
+++ openldap-2.3.43/libraries/libldap/os-ip.c	2009-07-29 17:01:32.000000000 -0400
5fcfe9
@@ -738,6 +738,9 @@ ldap_mark_select_read( LDAP *ld, Sockbuf
5fcfe9
 
5fcfe9
 	sip = (struct selectinfo *)ld->ld_selectinfo;
5fcfe9
 
5fcfe9
+	if (ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ))
5fcfe9
+		return;
5fcfe9
+
5fcfe9
 	ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
5fcfe9
 
5fcfe9
 #ifdef HAVE_POLL
5fcfe9
diff -up openldap-2.3.43/libraries/libldap/result.c.orig openldap-2.3.43/libraries/libldap/result.c
5fcfe9
--- openldap-2.3.43/libraries/libldap/result.c.orig	2009-07-29 17:00:42.000000000 -0400
5fcfe9
+++ openldap-2.3.43/libraries/libldap/result.c	2009-07-29 18:10:35.000000000 -0400
5fcfe9
@@ -73,7 +73,7 @@ static int ldap_mark_abandoned LDAP_P(( 
5fcfe9
 static int wait4msg LDAP_P(( LDAP *ld, ber_int_t msgid, int all, struct timeval *timeout,
5fcfe9
 	LDAPMessage **result ));
5fcfe9
 static ber_tag_t try_read1msg LDAP_P(( LDAP *ld, ber_int_t msgid,
5fcfe9
-	int all, LDAPConn **lc, LDAPMessage **result ));
5fcfe9
+	int all, LDAPConn *lc, LDAPMessage **result ));
5fcfe9
 static ber_tag_t build_result_ber LDAP_P(( LDAP *ld, BerElement **bp, LDAPRequest *lr ));
5fcfe9
 static void merge_error_info LDAP_P(( LDAP *ld, LDAPRequest *parentr, LDAPRequest *lr ));
5fcfe9
 static LDAPMessage * chkResponseList LDAP_P(( LDAP *ld, int msgid, int all));
5fcfe9
@@ -118,15 +118,9 @@ ldap_result(
5fcfe9
 #ifdef LDAP_R_COMPILE
5fcfe9
 	ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
5fcfe9
 #endif
5fcfe9
-	lm = chkResponseList(ld, msgid, all);
5fcfe9
 
5fcfe9
-	if ( lm == NULL ) {
5fcfe9
-		rc = wait4msg( ld, msgid, all, timeout, result );
5fcfe9
-	} else {
5fcfe9
-		*result = lm;
5fcfe9
-		ld->ld_errno = LDAP_SUCCESS;
5fcfe9
-		rc = lm->lm_msgtype;
5fcfe9
-	}
5fcfe9
+	rc = wait4msg( ld, msgid, all, timeout, result );
5fcfe9
+
5fcfe9
 #ifdef LDAP_R_COMPILE
5fcfe9
 	ldap_pvt_thread_mutex_unlock( &ld->ld_res_mutex );
5fcfe9
 #endif
5fcfe9
@@ -233,7 +227,7 @@ wait4msg(
5fcfe9
 			*tvp;
5fcfe9
 	time_t		start_time = 0;
5fcfe9
 	time_t		tmp_time;
5fcfe9
-	LDAPConn	*lc;
5fcfe9
+	LDAPConn	*lc, *nextlc;
5fcfe9
 
5fcfe9
 	assert( ld != NULL );
5fcfe9
 	assert( result != NULL );
5fcfe9
@@ -280,13 +274,6 @@ wait4msg(
5fcfe9
 			for ( lc = ld->ld_conns; lc != NULL; lc = lc->lconn_next ) {
5fcfe9
 				if ( ber_sockbuf_ctrl( lc->lconn_sb,
5fcfe9
 						LBER_SB_OPT_DATA_READY, NULL ) ) {
5fcfe9
-#ifdef LDAP_R_COMPILE
5fcfe9
-					ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
5fcfe9
-#endif
5fcfe9
-					rc = try_read1msg( ld, msgid, all, &lc, result );
5fcfe9
-#ifdef LDAP_R_COMPILE
5fcfe9
-					ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
5fcfe9
-#endif
5fcfe9
 					lc_ready = 1;
5fcfe9
 					break;
5fcfe9
 				}
5fcfe9
@@ -319,7 +306,11 @@ wait4msg(
5fcfe9
 				if ( rc == -1 ) {
5fcfe9
 					rc = LDAP_MSG_X_KEEP_LOOKING;	/* select interrupted: loop */
5fcfe9
 				} else {
5fcfe9
-					rc = LDAP_MSG_X_KEEP_LOOKING;
5fcfe9
+					lc_ready = 1;
5fcfe9
+				}
5fcfe9
+			}
5fcfe9
+			if ( lc_ready ) {
5fcfe9
+				rc = LDAP_MSG_X_KEEP_LOOKING;
5fcfe9
 #ifdef LDAP_R_COMPILE
5fcfe9
 					ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
5fcfe9
 #endif
5fcfe9
@@ -335,38 +326,43 @@ wait4msg(
5fcfe9
 					ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
5fcfe9
 #endif
5fcfe9
 					for ( lc = ld->ld_conns;
5fcfe9
-						rc == LDAP_MSG_X_KEEP_LOOKING && lc != NULL; )
5fcfe9
+						rc == LDAP_MSG_X_KEEP_LOOKING && lc != NULL;
5fcfe9
+						lc = nextlc )
5fcfe9
 					{
5fcfe9
 						if ( lc->lconn_status == LDAP_CONNST_CONNECTED &&
5fcfe9
 							ldap_is_read_ready( ld, lc->lconn_sb ))
5fcfe9
 						{
5fcfe9
+							/* Don't let it get freed out from under us */
5fcfe9
+							++lc->lconn_refcnt;
5fcfe9
 #ifdef LDAP_R_COMPILE
5fcfe9
 							ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
5fcfe9
 #endif
5fcfe9
-							rc = try_read1msg( ld, msgid, all, &lc, result );
5fcfe9
+							rc = try_read1msg( ld, msgid, all, lc, result );
5fcfe9
+							nextlc = lc->lconn_next;
5fcfe9
+
5fcfe9
+							/* Only take locks if we're really freeing */
5fcfe9
+							if ( lc->lconn_refcnt <= 1 ) {
5fcfe9
 #ifdef LDAP_R_COMPILE
5fcfe9
-							ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
5fcfe9
+								ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
5fcfe9
 #endif
5fcfe9
-							if ( lc == NULL ) {
5fcfe9
-								/* if lc gets free()'d,
5fcfe9
-								 * there's no guarantee
5fcfe9
-								 * lc->lconn_next is still
5fcfe9
-								 * sane; better restart
5fcfe9
-								 * (ITS#4405) */
5fcfe9
-								lc = ld->ld_conns;
5fcfe9
-
5fcfe9
-								/* don't get to next conn! */
5fcfe9
-								break;
5fcfe9
+								ldap_free_connection( ld, lc, 0, 1 );
5fcfe9
+#ifdef LDAP_R_COMPILE
5fcfe9
+								ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
5fcfe9
+#endif
5fcfe9
+							} else {
5fcfe9
+								--lc->lconn_refcnt;
5fcfe9
 							}
5fcfe9
+#ifdef LDAP_R_COMPILE
5fcfe9
+							ldap_pvt_thread_mutex_lock( &ld->ld_conn_mutex );
5fcfe9
+#endif
5fcfe9
+						} else {
5fcfe9
+							/* next conn */
5fcfe9
+							nextlc = lc->lconn_next;
5fcfe9
 						}
5fcfe9
-
5fcfe9
-						/* next conn */
5fcfe9
-						lc = lc->lconn_next;
5fcfe9
 					}
5fcfe9
 #ifdef LDAP_R_COMPILE
5fcfe9
 					ldap_pvt_thread_mutex_unlock( &ld->ld_conn_mutex );
5fcfe9
 #endif
5fcfe9
-				}
5fcfe9
 			}
5fcfe9
 		}
5fcfe9
 
5fcfe9
@@ -380,7 +376,6 @@ wait4msg(
5fcfe9
 			if ( tv0.tv_sec <= delta_time ) {
5fcfe9
 				rc = 0;	/* timed out */
5fcfe9
 				ld->ld_errno = LDAP_TIMEOUT;
5fcfe9
-				break;
5fcfe9
 			}
5fcfe9
 			tv0.tv_sec -= delta_time;
5fcfe9
 			tv.tv_sec = tv0.tv_sec;
5fcfe9
@@ -400,7 +395,7 @@ try_read1msg(
5fcfe9
 	LDAP *ld,
5fcfe9
 	ber_int_t msgid,
5fcfe9
 	int all,
5fcfe9
-	LDAPConn **lcp,
5fcfe9
+	LDAPConn *lc,
5fcfe9
 	LDAPMessage **result )
5fcfe9
 {
5fcfe9
 	BerElement	*ber;
5fcfe9
@@ -410,7 +405,6 @@ try_read1msg(
5fcfe9
 	ber_len_t	len;
5fcfe9
 	int		foundit = 0;
5fcfe9
 	LDAPRequest	*lr, *tmplr;
5fcfe9
-	LDAPConn	*lc;
5fcfe9
 	BerElement	tmpber;
5fcfe9
 	int		rc, refer_cnt, hadref, simple_request, err;
5fcfe9
 	ber_int_t	lderr;
5fcfe9
@@ -431,14 +425,11 @@ try_read1msg(
5fcfe9
 	}	v3ref;
5fcfe9
 
5fcfe9
 	assert( ld != NULL );
5fcfe9
-	assert( lcp != NULL );
5fcfe9
-	assert( *lcp != NULL );
5fcfe9
+	assert( lc != NULL );
5fcfe9
 	
5fcfe9
 	Debug( LDAP_DEBUG_TRACE, "read1msg: ld %p msgid %d all %d\n",
5fcfe9
 		(void *)ld, msgid, all );
5fcfe9
 
5fcfe9
-	lc = *lcp;
5fcfe9
-
5fcfe9
 retry:
5fcfe9
 	if ( lc->lconn_ber == NULL ) {
5fcfe9
 		lc->lconn_ber = ldap_alloc_ber_with_options(ld);
5fcfe9
@@ -839,14 +830,8 @@ lr->lr_res_matched ? lr->lr_res_matched 
5fcfe9
 			}
5fcfe9
 
5fcfe9
 			if ( lc != NULL ) {
5fcfe9
-#ifdef LDAP_R_COMPILE
5fcfe9
-				ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
5fcfe9
-#endif
5fcfe9
-				ldap_free_connection( ld, lc, 0, 1 );
5fcfe9
-#ifdef LDAP_R_COMPILE
5fcfe9
-				ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
5fcfe9
-#endif
5fcfe9
-				lc = *lcp = NULL;
5fcfe9
+				--lc->lconn_refcnt;
5fcfe9
+				lc = NULL;
5fcfe9
 			}
5fcfe9
 		}
5fcfe9
 	}