From 049e9a118ffaf9196f809214e5f7bc9c3178f713 Mon Sep 17 00:00:00 2001
From: Quanah Gibson-Mount <quanah@openldap.org>
Date: Sun, 28 Jun 2009 16:51:59 +0000
Subject: [PATCH] ITS#6189

---
 CHANGES                    | 1 +
 servers/slapd/connection.c | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/CHANGES b/CHANGES
index 0c6b474ec5..961d69eab8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,7 @@ OpenLDAP 2.4.17 Engineering
 	Fixed slapd abandon/cancel handling for some ops (ITS#6157)
 	Fixed slapd access setstyle to expand (ITS#6179)
 	Fixed slapd assert with closing connections (ITS#6111)
+	Fixed slapd bind race condition (ITS#6189)
 	Fixed slapd cancel behavior (ITS#6137)
 	Fixed slapd cert validation (ITS#6098)
 	Fixed slapd errno handling (ITS#6037)
diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c
index cb818a4a9e..81ba89f681 100644
--- a/servers/slapd/connection.c
+++ b/servers/slapd/connection.c
@@ -1127,6 +1127,9 @@ operations_error:
 
 	ldap_pvt_thread_mutex_lock( &conn->c_mutex );
 
+	if ( opidx == SLAP_OP_BIND && conn->c_conn_state == SLAP_C_BINDING )
+		conn->c_conn_state = SLAP_C_ACTIVE;
+
 	cancel = op->o_cancel;
 	if ( cancel != SLAP_CANCEL_NONE && cancel != SLAP_CANCEL_DONE ) {
 		if ( cancel == SLAP_CANCEL_REQ ) {
@@ -1534,6 +1537,8 @@ connection_input( Connection *conn , conn_readinfo *cri )
 	ctx = cri->ctx;
 	op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++, ctx );
 
+	Debug( LDAP_DEBUG_TRACE, "op tag %d, time %d\n", tag, op->o_time, 0);
+
 	op->o_conn = conn;
 	/* clear state if the connection is being reused from inactive */
 	if ( conn->c_conn_state == SLAP_C_INACTIVE ) {
@@ -1719,8 +1724,6 @@ static int connection_bind_cleanup_cb( Operation *op, SlapReply *rs )
 static int connection_bind_cb( Operation *op, SlapReply *rs )
 {
 	ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
-	if ( op->o_conn->c_conn_state == SLAP_C_BINDING )
-		op->o_conn->c_conn_state = SLAP_C_ACTIVE;
 	op->o_conn->c_sasl_bind_in_progress =
 		( rs->sr_err == LDAP_SASL_BIND_IN_PROGRESS );
 
-- 
GitLab