]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/bind.c
Rework ac/socket.h for HAVE_WINSOCK:
[openldap] / servers / slapd / bind.c
index b7b3aba388864ef2c1153f80d7220b12f59d9f08..223401aa1ba863f0b7ed0dfbe15dc997e8b6a329 100644 (file)
@@ -28,7 +28,7 @@ do_bind(
 )
 {
        BerElement      *ber = op->o_ber;
-       int             version, method, len;
+       int             version, method;
        char            *cdn, *ndn;
        unsigned long   rc;
        struct berval   cred;
@@ -135,8 +135,22 @@ do_bind(
                        free( cred.bv_val );
                }
 
+               ldap_pvt_thread_mutex_lock( &conn->c_mutex );
+
                conn->c_protocol = version;
 
+               if ( conn->c_cdn != NULL ) {
+                       free( conn->c_cdn );
+                       conn->c_cdn = NULL;
+               }
+
+               if ( conn->c_dn != NULL ) {
+                       free( conn->c_dn );
+                       conn->c_dn = NULL;
+               }
+
+               ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
+
                send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );
                return;
        }
@@ -154,7 +168,22 @@ do_bind(
                        free( cred.bv_val );
                }
                if ( cred.bv_len == 0 ) {
+                       ldap_pvt_thread_mutex_lock( &conn->c_mutex );
+
                        conn->c_protocol = version;
+
+                       if ( conn->c_cdn != NULL ) {
+                               free( conn->c_cdn );
+                               conn->c_cdn = NULL;
+                       }
+
+                       if ( conn->c_dn != NULL ) {
+                               free( conn->c_dn );
+                               conn->c_dn = NULL;
+                       }
+
+                       ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
+
                        send_ldap_result( conn, op, LDAP_SUCCESS,
                                NULL, NULL );
                } else if ( default_referral && *default_referral ) {
@@ -167,14 +196,14 @@ do_bind(
                return;
        }
 
-       if ( be->be_bind != NULL ) {
+       if ( be->be_bind ) {
                /* alias suffix */
                char *edn;
 
                ndn = suffixAlias( ndn, op, be );
 
                if ( (*be->be_bind)( be, conn, op, ndn, method, &cred, &edn ) == 0 ) {
-                       pthread_mutex_lock( &conn->c_dnmutex );
+                       ldap_pvt_thread_mutex_lock( &conn->c_mutex );
 
                        conn->c_protocol = version;
 
@@ -185,7 +214,7 @@ do_bind(
                        conn->c_cdn = cdn;
                        cdn = NULL;
 
-                       if ( conn->c_cdn != NULL ) {
+                       if ( conn->c_dn != NULL ) {
                                free( conn->c_dn );
                        }
 
@@ -199,7 +228,7 @@ do_bind(
                        Debug( LDAP_DEBUG_TRACE, "do_bind: bound \"%s\" to \"%s\"\n",
                        conn->c_cdn, conn->c_dn, method );
 
-                       pthread_mutex_unlock( &conn->c_dnmutex );
+                       ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
 
                        /* send this here to avoid a race condition */
                        send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL );