]> git.sur5r.net Git - openldap/commitdiff
ITS#4541 better fix
authorHoward Chu <hyc@openldap.org>
Fri, 12 May 2006 06:33:27 +0000 (06:33 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 12 May 2006 06:33:27 +0000 (06:33 +0000)
libraries/libldap/cyrus.c
libraries/libldap/kbind.c
libraries/libldap/open.c
libraries/libldap/request.c

index 6c82969f0957dfb8ca31eff6514a88661c35126d..936f44d35b53e33b3faa9bb6e0250065a30375c1 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 a7f05c2c56e0e9232c6b8f8df00470b9c08578a5..ef21432fddcf974d585ff2ae146cfc7702b3fa07 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 d02048dfd688288d4a06456c5068c00be8cdde7b..785260a5d8ec9c28f2b350c0ea9cd1b7e9f5feee 100644 (file)
 #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 )
 {
-       int rc = 0;
+       ld->ld_defconn = ldap_new_connection( ld,
+               &ld->ld_options.ldo_defludp, 1, 1, NULL );
 
-#ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_lock( &ld->ld_req_mutex );
-#endif /* LDAP_R_COMPILE */
-       if ( ld->ld_defconn == NULL ) {
-               ld->ld_defconn = ldap_new_connection( ld,
-                       &ld->ld_options.ldo_defludp, 1, 1, NULL );
-
-               if( ld->ld_defconn == NULL ) {
-                       ld->ld_errno = LDAP_SERVER_DOWN;
-                       rc = -1;
-               } else {
-                       ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */
-               }
+       if( ld->ld_defconn == NULL ) {
+               ld->ld_errno = LDAP_SERVER_DOWN;
+               return -1;
        }
-#ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_unlock( &ld->ld_req_mutex );
-#endif /* LDAP_R_COMPILE */
-       return rc;
+
+       ++ld->ld_defconn->lconn_refcnt; /* so it never gets closed/freed */
+       return 0;
 }
 
 /*
index 3df34e633f0982b9fa6e8e3051b0c346d32b8cee..2fa9f0f8abf6e4f37781b627d38e2d2e3e9cc139 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 );