if ( lc->lconn_status == LDAP_CONNST_CONNECTED ) {
ldap_mark_select_clear( ld, lc->lconn_sb );
if ( unbind ) {
- ldap_send_unbind( ld, lc->lconn_sb, NULL, NULL );
+ ldap_send_unbind( ld, lc->lconn_sb,
+ NULL, NULL );
}
}
#endif
if ( rc < 0 ) {
/* Failure, try next referral in the list */
- Debug( LDAP_DEBUG_ANY, "Unable to chase referral \"%s\" (%s)\n",
- refarray[i], ldap_err2string( ld->ld_errno ), 0);
- unfollowedcnt += ldap_append_referral( ld, &unfollowed, refarray[i]);
- ldap_free_urllist(srv);
+ Debug( LDAP_DEBUG_ANY, "Unable to chase referral \"%s\" (%d: %s)\n",
+ refarray[i], ld->ld_errno, ldap_err2string( ld->ld_errno ) );
+ unfollowedcnt += ldap_append_referral( ld, &unfollowed, refarray[i] );
+ ldap_free_urllist( srv );
srv = NULL;
} else {
/* Success, no need to try this referral list further */
*hadrefp = 1;
/* check if there is a queue of referrals that came in during bind */
- if( lc == NULL) {
- if (( lc = find_connection( ld, srv, 1 )) == NULL ) {
+ if ( lc == NULL) {
+ lc = find_connection( ld, srv, 1 );
+ if ( lc == NULL ) {
ld->ld_errno = LDAP_OPERATIONS_ERROR;
rc = -1;
goto done;
}
}
- if( lc->lconn_rebind_queue != NULL) {
+ if ( lc->lconn_rebind_queue != NULL ) {
/* Release resources of previous list */
- LDAP_VFREE(refarray);
+ LDAP_VFREE( refarray );
refarray = NULL;
- ldap_free_urllist(srv);
+ ldap_free_urllist( srv );
srv = NULL;
/* Pull entries off end of queue so list always null terminated */
- for( j = 0; lc->lconn_rebind_queue[j] != NULL; j++) {
+ for( j = 0; lc->lconn_rebind_queue[j] != NULL; j++ )
;
- }
- refarray = lc->lconn_rebind_queue[j-1];
+ refarray = lc->lconn_rebind_queue[j - 1];
lc->lconn_rebind_queue[j-1] = NULL;
/* we pulled off last entry from queue, free queue */
if ( j == 1 ) {
- LDAP_FREE( lc->lconn_rebind_queue);
+ LDAP_FREE( lc->lconn_rebind_queue );
lc->lconn_rebind_queue = NULL;
}
/* restart the loop the with new referral list */
/* parse out & follow referrals */
for ( ref = p; rc == 0 && ref != NULL; ref = p ) {
- if (( p = strchr( ref, '\n' )) != NULL ) {
+ p = strchr( ref, '\n' );
+ if ( p != NULL ) {
*p++ = '\0';
- } else {
- p = NULL;
}
rc = ldap_url_parse_ext( ref, &srv );
continue;
}
- if( srv->lud_dn != NULL && srv->lud_dn == '\0' ) {
+ if ( srv->lud_dn != NULL && srv->lud_dn == '\0' ) {
LDAP_FREE( srv->lud_dn );
srv->lud_dn = NULL;
}
ber = re_encode_request( ld, origreq->lr_ber,
id, sref, srv, &rinfo.ri_request );
- if( ber == NULL ) {
+ if ( ber == NULL ) {
return -1 ;
}
++count;
} else {
Debug( LDAP_DEBUG_ANY,
- "Unable to chase referral (%s)\n",
- ldap_err2string( ld->ld_errno ), 0, 0 );
+ "Unable to chase referral \"%s\" (%d: %s)\n",
+ ref, ld->ld_errno, ldap_err2string( ld->ld_errno ) );
rc = ldap_append_referral( ld, &unfollowed, ref );
}
while ( ld->ld_requests != NULL ) {
ldap_free_request( ld, ld->ld_requests );
}
-#ifdef LDAP_R_COMPILE
- ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
-#endif
/* free and unbind from all open connections */
while ( ld->ld_conns != NULL ) {
ldap_free_connection( ld, ld->ld_conns, 1, close );
}
+#ifdef LDAP_R_COMPILE
+ ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
#ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_lock( &ld->ld_res_mutex );
return( ldap_unbind_ext( ld, NULL, NULL ) );
}
-
+/* FIXME: this function is called only by ldap_free_connection(),
+ * which, most of the times, is called with ld_req_mutex locked */
int
ldap_send_unbind(
LDAP *ld,
return( ld->ld_errno );
}
- LDAP_NEXT_MSGID( ld, id );
+ id = ++(ld)->ld_msgid;
+
/* fill it in */
if ( ber_printf( ber, "{itn" /*}*/, id,
LDAP_REQ_UNBIND ) == -1 ) {
return( ld->ld_errno );
}
-#ifdef LDAP_R_COMPILE
- ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
-#endif
ld->ld_errno = LDAP_SUCCESS;
/* send the message */
if ( ber_flush( sb, ber, 1 ) == -1 ) {
ld->ld_errno = LDAP_SERVER_DOWN;
ber_free( ber, 1 );
}
-#ifdef LDAP_R_COMPILE
- ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
-#endif
return( ld->ld_errno );
}