]> git.sur5r.net Git - openldap/commitdiff
Fixed libldap default connection concurrency issue (ITS#4541)
authorKurt Zeilenga <kurt@openldap.org>
Mon, 15 May 2006 17:26:46 +0000 (17:26 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 15 May 2006 17:26:46 +0000 (17:26 +0000)
CHANGES
libraries/libldap/cyrus.c
libraries/libldap/kbind.c
libraries/libldap/open.c
libraries/libldap/request.c

diff --git a/CHANGES b/CHANGES
index 50ed1cce09e5147b81883b32a7e71c7e088a33df..4d366dba443f0b388e2c277ad2d468c88d6b0677 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,7 @@ OpenLDAP 2.3 Change Log
 OpenLDAP 2.3.22 Engineering
        Fixed libldap referral input destroy issue (ITS#4533)
        Fixed libldap ldap_sort_entries tail bug (ITS#4536)
+       Fixed libldap default connection concurrency issue (ITS#4541)
        Fixed libldap_r thread debug missing break
        Fixed libldap_r tpool cleanup
        Fixed liblutil strtoul(3) usage (ITS#4503)
index ac963fc85e8de767974cc51656baf29931ef511e..38d98c60b8b172196a684fcb7ae83e7d4f0035f4 100644 (file)
@@ -602,23 +602,31 @@ ldap_int_sasl_bind(
                return ld->ld_errno;
        }
 
+       rc = 0;
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
        ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, &sd );
 
        if ( sd == AC_SOCKET_INVALID ) {
                /* not connected yet */
-               int rc;
 
                rc = ldap_open_defconn( ld );
-               if( rc < 0 ) return ld->ld_errno;
 
-               ber_sockbuf_ctrl( ld->ld_defconn->lconn_sb,
-                       LBER_SB_OPT_GET_FD, &sd );
+               if ( rc == 0 ) {
+                       ber_sockbuf_ctrl( ld->ld_defconn->lconn_sb,
+                               LBER_SB_OPT_GET_FD, &sd );
 
-               if( sd == AC_SOCKET_INVALID ) {
-                       ld->ld_errno = LDAP_LOCAL_ERROR;
-                       return ld->ld_errno;
+                       if( sd == AC_SOCKET_INVALID ) {
+                               ld->ld_errno = LDAP_LOCAL_ERROR;
+                               rc = ld->ld_errno;
+                       }
                }
        }   
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
+       if( rc != 0 ) return ld->ld_errno;
 
        oldctx = ld->ld_defconn->lconn_sasl_authctx;
 
index 5a83fbef92abe6f52479efbf5155387d4e8c477e..2708774ac8cbb0d7eb30c3c5afd0f52b6c2233a6 100644 (file)
@@ -255,12 +255,18 @@ ldap_get_kerberosv4_credentials(
                return( NULL );
        }
 
+       err = 0;
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
        if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
                /* not connected yet */
-               int rc = ldap_open_defconn( ld );
-
-               if( rc < 0 ) return NULL;
+               err = ldap_open_defconn( ld );
        }
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
+       if ( err < 0 ) return NULL;
 
        krbinstance = ld->ld_defconn->lconn_krbinstance;
 
index ddf37f9a75697237133fc16fa6bc80ffa36f099e..a4a5e5c07e5dbd33f078e1bd42bdf17d8cb776b7 100644 (file)
@@ -35,6 +35,7 @@
 #include "ldap-int.h"
 #include "ldap_log.h"
 
+/* Caller should hold the req_mutex if simultaneous accesses are possible */
 int ldap_open_defconn( LDAP *ld )
 {
        ld->ld_defconn = ldap_new_connection( ld,
index 5cbac2c3ad44726ab66bbd15b74d753d7ee482d3..55f43b80287e923bb4281e4c52100b7b7b87f196 100644 (file)
@@ -93,19 +93,25 @@ ldap_send_initial_request(
        BerElement *ber,
        ber_int_t msgid)
 {
-       int rc;
+       int rc = 1;
 
        Debug( LDAP_DEBUG_TRACE, "ldap_send_initial_request\n", 0, 0, 0 );
 
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
+#endif
        if ( ber_sockbuf_ctrl( ld->ld_sb, LBER_SB_OPT_GET_FD, NULL ) == -1 ) {
                /* not connected yet */
-               int rc = ldap_open_defconn( ld );
-
-               if( rc < 0 ) {
-                       ber_free( ber, 1 );
-                       return( -1 );
-               }
+               rc = ldap_open_defconn( ld );
 
+       }
+#ifdef LDAP_R_COMPILE
+       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
+#endif
+       if( rc < 0 ) {
+               ber_free( ber, 1 );
+               return( -1 );
+       } else if ( rc == 0 ) {
                Debug( LDAP_DEBUG_TRACE,
                        "ldap_open_defconn: successful\n",
                        0, 0, 0 );