/* $OpenLDAP$ */
/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
assert( c != NULL );
if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
+ c->c_authmech = NULL;
c->c_dn = NULL;
c->c_cdn = NULL;
c->c_ops = NULL;
c->c_pending_ops = NULL;
- c->c_authmech = NULL;
- c->c_authstate = NULL;
+ c->c_sasl_bind_mech = NULL;
#ifdef HAVE_CYRUS_SASL
- c->c_sasl_context = NULL;
-#endif /* HAVE_CYRUS_SASL */
+ c->c_sasl_bind_context = NULL;
+#endif
c->c_sb = ber_sockbuf_alloc( );
c->c_currentber = NULL;
ldap_pvt_thread_mutex_lock( &c->c_mutex );
assert( c->c_struct_state == SLAP_C_UNUSED );
+ assert( c->c_authmech == NULL );
assert( c->c_dn == NULL );
assert( c->c_cdn == NULL );
assert( c->c_listener_url == NULL );
assert( c->c_sock_name == NULL );
assert( c->c_ops == NULL );
assert( c->c_pending_ops == NULL );
- assert( c->c_authmech == NULL );
- assert( c->c_authstate == NULL );
+ assert( c->c_sasl_bind_mech == NULL );
#ifdef HAVE_CYRUS_SASL
- assert( c->c_sasl_context == NULL );
+ assert( c->c_sasl_bind_context == NULL );
#endif
assert( c->c_currentber == NULL );
c->c_activitytime = c->c_starttime = 0;
+ if(c->c_authmech != NULL ) {
+ free(c->c_authmech);
+ c->c_authmech = NULL;
+ }
if(c->c_dn != NULL) {
free(c->c_dn);
c->c_dn = NULL;
free(c->c_sock_name);
c->c_sock_name = NULL;
}
- if(c->c_authmech != NULL ) {
- free(c->c_authmech);
- c->c_authmech = NULL;
- }
- if(c->c_authstate != NULL ) {
- free(c->c_authstate);
- c->c_authstate = NULL;
- }
+ c->c_sasl_bind_in_progress = 0;
+ if(c->c_sasl_bind_mech != NULL) {
+ free(c->c_sasl_bind_mech);
+ c->c_sasl_bind_mech = NULL;
+ }
#ifdef HAVE_CYRUS_SASL
- if(c->c_sasl_context != NULL ) {
- sasl_dispose( &c->c_sasl_context );
- c->c_sasl_context = NULL;
+ if(c->c_sasl_bind_context != NULL ) {
+ sasl_dispose( &c->c_sasl_bind_context );
+ c->c_sasl_bind_context = NULL;
}
-#endif /* HAVE_CYRUS_SASL */
-
- c->c_bind_in_progress = 0;
+#endif
if ( c->c_currentber != NULL ) {
ber_free( c->c_currentber, 1 );
/* c_mutex must be locked by caller */
if( c->c_conn_state != SLAP_C_CLOSING ) {
-
Debug( LDAP_DEBUG_TRACE,
"connection_closing: readying conn=%ld sd=%d for close\n",
c->c_connid, ber_pvt_sb_get_desc( c->c_sb ), 0 );
/* don't listen on this port anymore */
slapd_clr_read( ber_pvt_sb_get_desc( c->c_sb ), 1 );
- /* shutdown I/O -- not yet implemented */
-
/* abandon active operations */
connection_abandon( c );
num_ops_initiated++;
ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
+ if( conn->c_sasl_bind_in_progress && tag != LDAP_REQ_BIND ) {
+ Debug( LDAP_DEBUG_ANY, "connection_operation: "
+ "error: SASL bind in progress (tag=%ld).\n",
+ (long) tag, 0, 0 );
+ send_ldap_result( conn, arg->co_op,
+ rc = LDAP_OPERATIONS_ERROR,
+ NULL, "SASL bind in progress", NULL, NULL );
+ goto operations_error;
+ }
+
switch ( tag ) {
case LDAP_REQ_BIND:
rc = do_bind( conn, arg->co_op );
break;
}
- if( rc == -1 ) tag = LBER_ERROR;
+ if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR;
+operations_error:
ldap_pvt_thread_mutex_lock( &num_ops_mutex );
num_ops_completed++;
ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
break;
case LDAP_REQ_BIND:
+ conn->c_sasl_bind_in_progress =
+ rc == LDAP_SASL_BIND_IN_PROGRESS ? 1 : 0;
+
if( conn->c_conn_state == SLAP_C_BINDING) {
conn->c_conn_state = SLAP_C_ACTIVE;
}
- /*
- * Is this ever the case? For now, rely on
- * the backend to set this.
- */
- if ( rc == LDAP_SASL_BIND_IN_PROGRESS ) {
- conn->c_bind_in_progress = 1;
- }
}
ldap_pvt_thread_mutex_lock( &active_threads_mutex );
if ( c->c_is_tls && c->c_needs_tls_accept ) {
rc = ldap_pvt_tls_accept( c->c_sb, NULL );
if ( rc < 0 ) {
+ struct timeval tv;
+ fd_set rfd;
+
Debug( LDAP_DEBUG_TRACE,
"connection_read(%d): TLS accept error error=%d id=%ld, closing\n",
s, rc, c->c_connid );
c->c_needs_tls_accept = 0;
/* connections_mutex and c_mutex are locked */
connection_closing( c );
+
+ /* Drain input before close, to allow SSL error codes
+ * to propagate to client. */
+ FD_ZERO(&rfd);
+ FD_SET(s, &rfd);
+ ber_pvt_sb_set_readahead(c->c_sb, 0);
+ for (rc=1; rc>0;)
+ {
+ char buf[4096];
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ rc = select(s+1, &rfd, NULL, NULL, &tv);
+ if (rc == 1)
+ rc = ber_pvt_sb_read(c->c_sb, buf, sizeof(buf));
+ }
connection_close( c );
} else if ( rc == 0 ) {
c->c_needs_tls_accept = 0;
Debug( LDAP_DEBUG_TRACE,
"ber_get_next on fd %d failed errno=%d (%s)\n",
- ber_pvt_sb_get_desc( conn->c_sb ), err, STRERROR(err) );
+ ber_pvt_sb_get_desc( conn->c_sb ), err, sock_errstr(err) );
Debug( LDAP_DEBUG_TRACE,
"\t*** got %ld of %lu so far\n",
(long) ( conn->c_currentber->ber_buf
arg->co_conn = conn;
arg->co_op = op;
- arg->co_op->o_bind_in_progress = conn->c_bind_in_progress;
-
arg->co_op->o_dn = ch_strdup( tmpdn != NULL ? tmpdn : "" );
arg->co_op->o_ndn = ch_strdup( arg->co_op->o_dn );
(void) dn_normalize( arg->co_op->o_ndn );