3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/socket.h>
14 #include <ac/string.h>
16 #include <ac/unistd.h>
26 /* protected by connections_mutex */
27 static ldap_pvt_thread_mutex_t connections_mutex;
28 static Connection *connections = NULL;
29 static unsigned long conn_nextid = 0;
31 /* structure state (protected by connections_mutex) */
32 #define SLAP_C_UNINITIALIZED 0x00 /* MUST BE ZERO (0) */
33 #define SLAP_C_UNUSED 0x01
34 #define SLAP_C_USED 0x02
36 /* connection state (protected by c_mutex ) */
37 #define SLAP_C_INVALID 0x00 /* MUST BE ZERO (0) */
38 #define SLAP_C_INACTIVE 0x01 /* zero threads */
39 #define SLAP_C_ACTIVE 0x02 /* one or more threads */
40 #define SLAP_C_BINDING 0x03 /* binding */
41 #define SLAP_C_CLOSING 0x04 /* closing */
44 connection_state2str( int state )
47 case SLAP_C_INVALID: return "!";
48 case SLAP_C_INACTIVE: return "|";
49 case SLAP_C_ACTIVE: return "";
50 case SLAP_C_BINDING: return "B";
51 case SLAP_C_CLOSING: return "C";
57 static Connection* connection_get( ber_socket_t s );
59 static int connection_input( Connection *c );
60 static void connection_close( Connection *c );
62 static int connection_op_activate( Operation *op );
63 static int connection_resched( Connection *conn );
64 static void connection_abandon( Connection *conn );
65 static void connection_destroy( Connection *c );
67 static ldap_pvt_thread_start_t connection_operation;
70 * Initialize connection management infrastructure.
72 int connections_init(void)
74 assert( connections == NULL );
76 if( connections != NULL) {
78 LDAP_LOG( CONNECTION, INFO,
79 "connections_init: already initialized.\n", 0, 0, 0 );
81 Debug( LDAP_DEBUG_ANY, "connections_init: already initialized.\n",
87 /* should check return of every call */
88 ldap_pvt_thread_mutex_init( &connections_mutex );
90 connections = (Connection *) ch_calloc( dtblsize, sizeof(Connection) );
92 if( connections == NULL ) {
94 LDAP_LOG( CONNECTION, ERR,
95 "connections_init: allocation (%d * %ld) of connection "
96 "array failed\n", dtblsize, (long) sizeof(Connection), 0 );
98 Debug( LDAP_DEBUG_ANY,
99 "connections_init: allocation (%d*%ld) of connection array failed\n",
100 dtblsize, (long) sizeof(Connection), 0 );
105 assert( connections[0].c_struct_state == SLAP_C_UNINITIALIZED );
106 assert( connections[dtblsize-1].c_struct_state == SLAP_C_UNINITIALIZED );
109 * per entry initialization of the Connection array initialization
110 * will be done by connection_init()
117 * Destroy connection management infrastructure.
119 int connections_destroy(void)
123 /* should check return of every call */
125 if( connections == NULL) {
127 LDAP_LOG( CONNECTION, INFO,
128 "connections_destroy: nothing to destroy.\n", 0, 0, 0 );
130 Debug( LDAP_DEBUG_ANY, "connections_destroy: nothing to destroy.\n",
136 for ( i = 0; i < dtblsize; i++ ) {
137 if( connections[i].c_struct_state != SLAP_C_UNINITIALIZED ) {
138 ber_sockbuf_free( connections[i].c_sb );
139 ldap_pvt_thread_mutex_destroy( &connections[i].c_mutex );
140 ldap_pvt_thread_mutex_destroy( &connections[i].c_write_mutex );
141 ldap_pvt_thread_cond_destroy( &connections[i].c_write_cv );
143 slapi_x_free_object_extensions( SLAPI_X_EXT_CONNECTION, &connections[i] );
151 ldap_pvt_thread_mutex_destroy( &connections_mutex );
156 * shutdown all connections
158 int connections_shutdown(void)
162 ldap_pvt_thread_mutex_lock( &connections_mutex );
164 for ( i = 0; i < dtblsize; i++ ) {
165 if( connections[i].c_struct_state != SLAP_C_USED ) {
169 ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
171 /* connections_mutex and c_mutex are locked */
172 connection_closing( &connections[i] );
173 connection_close( &connections[i] );
175 ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
178 ldap_pvt_thread_mutex_unlock( &connections_mutex );
184 * Timeout idle connections.
186 int connections_timeout_idle(time_t now)
192 for( c = connection_first( &connindex );
194 c = connection_next( c, &connindex ) )
196 /* Don't timeout a slow-running request */
197 if( c->c_n_ops_executing ) continue;
199 if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) {
201 connection_closing( c );
202 connection_close( c );
206 connection_done( c );
211 static Connection* connection_get( ber_socket_t s )
213 /* connections_mutex should be locked by caller */
218 LDAP_LOG( CONNECTION, ENTRY, "connection_get: socket %ld\n", (long)s, 0, 0 );
220 Debug( LDAP_DEBUG_ARGS,
221 "connection_get(%ld)\n",
225 assert( connections != NULL );
227 if(s == AC_SOCKET_INVALID) {
234 assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
241 for(i=0; i<dtblsize; i++) {
242 if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
243 assert( connections[i].c_conn_state == SLAP_C_INVALID );
244 assert( connections[i].c_sb == 0 );
248 ber_sockbuf_ctrl( connections[i].c_sb,
249 LBER_SB_OPT_GET_FD, &sd );
251 if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
252 assert( connections[i].c_conn_state == SLAP_C_INVALID );
253 assert( sd == AC_SOCKET_INVALID );
257 /* state can actually change from used -> unused by resched,
258 * so don't assert details here.
272 ldap_pvt_thread_mutex_lock( &c->c_mutex );
274 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
275 if( c->c_struct_state != SLAP_C_USED ) {
276 /* connection must have been closed due to resched */
278 assert( c->c_conn_state == SLAP_C_INVALID );
279 assert( sd == AC_SOCKET_INVALID );
282 LDAP_LOG( CONNECTION, ARGS,
283 "connection_get: connection %d not used\n", s, 0, 0 );
285 Debug( LDAP_DEBUG_TRACE,
286 "connection_get(%d): connection not used\n",
290 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
295 LDAP_LOG( CONNECTION, RESULTS,
296 "connection_get: get for %d got connid %lu\n", s, c->c_connid, 0 );
298 Debug( LDAP_DEBUG_TRACE,
299 "connection_get(%d): got connid=%lu\n",
305 assert( c->c_struct_state == SLAP_C_USED );
306 assert( c->c_conn_state != SLAP_C_INVALID );
307 assert( sd != AC_SOCKET_INVALID );
310 c->c_activitytime = slap_get_time();
312 if( global_idletimeout > 0 ) {
313 c->c_activitytime = slap_get_time();
321 static void connection_return( Connection *c )
323 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
326 long connection_init(
330 const char* peername,
338 assert( connections != NULL );
340 assert( listener != NULL );
341 assert( dnsname != NULL );
342 assert( peername != NULL );
345 assert( tls_udp_option != 1 );
348 if( s == AC_SOCKET_INVALID ) {
350 LDAP_LOG( CONNECTION, INFO,
351 "connection_init: init of socket %ld invalid.\n", (long)s, 0, 0 );
353 Debug( LDAP_DEBUG_ANY,
354 "connection_init(%ld): invalid.\n",
362 assert( s < dtblsize );
365 ldap_pvt_thread_mutex_lock( &connections_mutex );
376 for( i=0; i < dtblsize; i++) {
379 if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
380 assert( connections[i].c_sb == 0 );
385 sd = AC_SOCKET_INVALID;
386 if (connections[i].c_sb != NULL)
387 ber_sockbuf_ctrl( connections[i].c_sb, LBER_SB_OPT_GET_FD, &sd );
389 if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
390 assert( sd == AC_SOCKET_INVALID );
395 assert( connections[i].c_struct_state == SLAP_C_USED );
396 assert( connections[i].c_conn_state != SLAP_C_INVALID );
397 assert( sd != AC_SOCKET_INVALID );
402 LDAP_LOG( CONNECTION, INFO,
403 "connection_init: skt %d connection table full "
404 "(%d/%d)\n", s, i, dtblsize );
406 Debug( LDAP_DEBUG_ANY,
407 "connection_init(%d): connection table full "
408 "(%d/%d)\n", s, i, dtblsize);
410 ldap_pvt_thread_mutex_unlock( &connections_mutex );
418 if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
419 c->c_send_ldap_result = slap_send_ldap_result;
420 c->c_send_search_entry = slap_send_search_entry;
421 c->c_send_search_reference = slap_send_search_reference;
422 c->c_send_ldap_extended = slap_send_ldap_extended;
423 #ifdef LDAP_RES_INTERMEDIATE
424 c->c_send_ldap_intermediate = slap_send_ldap_intermediate;
427 c->c_authmech.bv_val = NULL;
428 c->c_authmech.bv_len = 0;
429 c->c_dn.bv_val = NULL;
431 c->c_ndn.bv_val = NULL;
434 c->c_listener = NULL;
435 c->c_peer_domain.bv_val = NULL;
436 c->c_peer_domain.bv_len = 0;
437 c->c_peer_name.bv_val = NULL;
438 c->c_peer_name.bv_len = 0;
440 LDAP_STAILQ_INIT(&c->c_ops);
441 LDAP_STAILQ_INIT(&c->c_pending_ops);
443 c->c_sasl_bind_mech.bv_val = NULL;
444 c->c_sasl_bind_mech.bv_len = 0;
446 c->c_sasl_authctx = NULL;
447 c->c_sasl_sockctx = NULL;
448 c->c_sasl_extra = NULL;
449 c->c_sasl_bindop = NULL;
451 c->c_sb = ber_sockbuf_alloc( );
454 ber_len_t max = sockbuf_max_incoming;
455 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
458 c->c_currentber = NULL;
460 /* should check status of thread calls */
461 ldap_pvt_thread_mutex_init( &c->c_mutex );
462 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
463 ldap_pvt_thread_cond_init( &c->c_write_cv );
466 slapi_x_create_object_extensions( SLAPI_X_EXT_CONNECTION, c );
469 c->c_struct_state = SLAP_C_UNUSED;
472 ldap_pvt_thread_mutex_lock( &c->c_mutex );
474 assert( c->c_struct_state == SLAP_C_UNUSED );
475 assert( c->c_authmech.bv_val == NULL );
476 assert( c->c_dn.bv_val == NULL );
477 assert( c->c_ndn.bv_val == NULL );
478 assert( c->c_listener == NULL );
479 assert( c->c_peer_domain.bv_val == NULL );
480 assert( c->c_peer_name.bv_val == NULL );
481 assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
482 assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
483 assert( c->c_sasl_bind_mech.bv_val == NULL );
484 assert( c->c_sasl_done == 0 );
485 assert( c->c_sasl_authctx == NULL );
486 assert( c->c_sasl_sockctx == NULL );
487 assert( c->c_sasl_extra == NULL );
488 assert( c->c_sasl_bindop == NULL );
489 assert( c->c_currentber == NULL );
491 c->c_listener = listener;
492 ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
493 ber_str2bv( peername, 0, 1, &c->c_peer_name );
495 c->c_n_ops_received = 0;
496 c->c_n_ops_executing = 0;
497 c->c_n_ops_pending = 0;
498 c->c_n_ops_completed = 0;
504 /* set to zero until bind, implies LDAP_VERSION3 */
508 c->c_activitytime = c->c_starttime = slap_get_time();
510 if( global_idletimeout > 0 ) {
511 c->c_activitytime = c->c_starttime = slap_get_time();
515 #ifdef LDAP_CONNECTIONLESS
517 if( tls_udp_option == 2 ) {
520 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
521 LBER_SBIOD_LEVEL_PROVIDER, (void*)"udp_" );
523 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_udp,
524 LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
525 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_readahead,
526 LBER_SBIOD_LEVEL_PROVIDER, NULL );
531 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
532 LBER_SBIOD_LEVEL_PROVIDER, (void*)"tcp_" );
534 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_tcp,
535 LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
539 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
540 INT_MAX, (void*)"ldap_" );
543 if( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_NONBLOCK,
544 c /* non-NULL */ ) < 0 )
547 LDAP_LOG( CONNECTION, INFO,
548 "connection_init: conn %lu set nonblocking failed\n",
551 Debug( LDAP_DEBUG_ANY,
552 "connection_init(%d, %s): set nonblocking failed\n",
553 s, c->c_peer_name.bv_val, 0 );
557 id = c->c_connid = conn_nextid++;
559 c->c_conn_state = SLAP_C_INACTIVE;
560 c->c_struct_state = SLAP_C_USED;
562 c->c_ssf = c->c_transport_ssf = ssf;
566 if ( tls_udp_option == 1 ) {
568 c->c_needs_tls_accept = 1;
571 c->c_needs_tls_accept = 0;
575 slap_sasl_open( c, 0 );
576 slap_sasl_external( c, ssf, authid );
578 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
579 ldap_pvt_thread_mutex_unlock( &connections_mutex );
581 backend_connection_init(c);
586 void connection2anonymous( Connection *c )
588 assert( connections != NULL );
592 ber_len_t max = sockbuf_max_incoming;
593 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
596 if(c->c_authmech.bv_val != NULL ) {
597 free(c->c_authmech.bv_val);
598 c->c_authmech.bv_val = NULL;
600 c->c_authmech.bv_len = 0;
602 if(c->c_dn.bv_val != NULL) {
603 free(c->c_dn.bv_val);
604 c->c_dn.bv_val = NULL;
607 if(c->c_ndn.bv_val != NULL) {
608 free(c->c_ndn.bv_val);
609 c->c_ndn.bv_val = NULL;
613 c->c_authz_backend = NULL;
617 connection_destroy( Connection *c )
619 /* note: connections_mutex should be locked by caller */
621 unsigned long connid;
623 assert( connections != NULL );
625 assert( c->c_struct_state != SLAP_C_UNUSED );
626 assert( c->c_conn_state != SLAP_C_INVALID );
627 assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
629 /* only for stats (print -1 as "%lu" may give unexpected results ;) */
630 connid = c->c_connid;
632 backend_connection_destroy(c);
637 c->c_activitytime = c->c_starttime = 0;
639 connection2anonymous( c );
640 c->c_listener = NULL;
642 if(c->c_peer_domain.bv_val != NULL) {
643 free(c->c_peer_domain.bv_val);
644 c->c_peer_domain.bv_val = NULL;
646 c->c_peer_domain.bv_len = 0;
647 if(c->c_peer_name.bv_val != NULL) {
648 free(c->c_peer_name.bv_val);
649 c->c_peer_name.bv_val = NULL;
651 c->c_peer_name.bv_len = 0;
653 c->c_sasl_bind_in_progress = 0;
654 if(c->c_sasl_bind_mech.bv_val != NULL) {
655 free(c->c_sasl_bind_mech.bv_val);
656 c->c_sasl_bind_mech.bv_val = NULL;
658 c->c_sasl_bind_mech.bv_len = 0;
660 slap_sasl_close( c );
662 if ( c->c_currentber != NULL ) {
663 ber_free( c->c_currentber, 1 );
664 c->c_currentber = NULL;
667 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
668 if ( sd != AC_SOCKET_INVALID ) {
669 slapd_remove( sd, 0 );
671 Statslog( LDAP_DEBUG_STATS,
672 "conn=%lu fd=%ld closed\n",
673 connid, (long) sd, 0, 0, 0 );
676 ber_sockbuf_free( c->c_sb );
678 c->c_sb = ber_sockbuf_alloc( );
681 ber_len_t max = sockbuf_max_incoming;
682 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
685 c->c_conn_state = SLAP_C_INVALID;
686 c->c_struct_state = SLAP_C_UNUSED;
689 /* call destructors, then constructors; avoids unnecessary allocation */
690 slapi_x_clear_object_extensions( SLAPI_X_EXT_CONNECTION, c );
694 int connection_state_closing( Connection *c )
696 /* c_mutex must be locked by caller */
700 assert( c->c_struct_state == SLAP_C_USED );
702 state = c->c_conn_state;
704 assert( state != SLAP_C_INVALID );
706 return state == SLAP_C_CLOSING;
709 static void connection_abandon( Connection *c )
711 /* c_mutex must be locked by caller */
715 LDAP_STAILQ_FOREACH(o, &c->c_ops, o_next) {
719 /* remove pending operations */
720 while ( (o = LDAP_STAILQ_FIRST( &c->c_pending_ops )) != NULL) {
721 LDAP_STAILQ_REMOVE_HEAD( &c->c_pending_ops, o_next );
722 LDAP_STAILQ_NEXT(o, o_next) = NULL;
727 void connection_closing( Connection *c )
729 assert( connections != NULL );
731 assert( c->c_struct_state == SLAP_C_USED );
732 assert( c->c_conn_state != SLAP_C_INVALID );
734 /* c_mutex must be locked by caller */
736 if( c->c_conn_state != SLAP_C_CLOSING ) {
739 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
741 LDAP_LOG( CONNECTION, DETAIL1,
742 "connection_closing: conn %lu readying socket %d for close.\n",
743 c->c_connid, sd, 0 );
745 Debug( LDAP_DEBUG_TRACE,
746 "connection_closing: readying conn=%lu sd=%d for close\n",
747 c->c_connid, sd, 0 );
749 /* update state to closing */
750 c->c_conn_state = SLAP_C_CLOSING;
752 /* don't listen on this port anymore */
753 slapd_clr_read( sd, 1 );
755 /* abandon active operations */
756 connection_abandon( c );
758 /* wake write blocked operations */
759 slapd_clr_write( sd, 1 );
760 ldap_pvt_thread_cond_signal( &c->c_write_cv );
764 static void connection_close( Connection *c )
768 assert( connections != NULL );
770 assert( c->c_struct_state == SLAP_C_USED );
771 assert( c->c_conn_state == SLAP_C_CLOSING );
773 /* note: connections_mutex and c_mutex should be locked by caller */
775 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
776 if( !LDAP_STAILQ_EMPTY(&c->c_ops) ) {
778 LDAP_LOG( CONNECTION, DETAIL1,
779 "connection_close: conn %lu deferring sd %d\n",
780 c->c_connid, sd, 0 );
782 Debug( LDAP_DEBUG_TRACE,
783 "connection_close: deferring conn=%lu sd=%d\n",
784 c->c_connid, sd, 0 );
790 LDAP_LOG( CONNECTION, RESULTS,
791 "connection_close: conn %lu sd %d\n", c->c_connid, sd, 0 );
793 Debug( LDAP_DEBUG_TRACE, "connection_close: conn=%lu sd=%d\n",
794 c->c_connid, sd, 0 );
796 connection_destroy( c );
799 unsigned long connections_nextid(void)
802 assert( connections != NULL );
804 ldap_pvt_thread_mutex_lock( &connections_mutex );
808 ldap_pvt_thread_mutex_unlock( &connections_mutex );
813 Connection* connection_first( ber_socket_t *index )
815 assert( connections != NULL );
816 assert( index != NULL );
818 ldap_pvt_thread_mutex_lock( &connections_mutex );
822 return connection_next(NULL, index);
825 Connection* connection_next( Connection *c, ber_socket_t *index )
827 assert( connections != NULL );
828 assert( index != NULL );
829 assert( *index <= dtblsize );
832 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
837 for(; *index < dtblsize; (*index)++) {
838 if( connections[*index].c_struct_state == SLAP_C_UNINITIALIZED ) {
839 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
847 if( connections[*index].c_struct_state == SLAP_C_USED ) {
848 assert( connections[*index].c_conn_state != SLAP_C_INVALID );
849 c = &connections[(*index)++];
853 assert( connections[*index].c_struct_state == SLAP_C_UNUSED );
854 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
858 ldap_pvt_thread_mutex_lock( &c->c_mutex );
864 void connection_done( Connection *c )
866 assert( connections != NULL );
869 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
872 ldap_pvt_thread_mutex_unlock( &connections_mutex );
876 * connection_activity - handle the request operation op on connection
877 * conn. This routine figures out what kind of operation it is and
878 * calls the appropriate stub to handle it.
882 #define INCR_OP(var,index) \
884 ldap_pvt_thread_mutex_lock( &num_ops_mutex ); \
886 ldap_pvt_thread_mutex_unlock( &num_ops_mutex ); \
888 #else /* !SLAPD_MONITOR */
889 #define INCR_OP(var,index)
890 #endif /* !SLAPD_MONITOR */
893 connection_operation( void *ctx, void *arg_v )
895 int rc = SLAPD_DISCONNECT;
896 Operation *op = arg_v;
897 SlapReply rs = {REP_RESULT};
898 ber_tag_t tag = op->o_tag;
900 ber_tag_t oldtag = tag;
901 #endif /* SLAPD_MONITOR */
902 Connection *conn = op->o_conn;
906 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
908 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
910 op->o_threadctx = ctx;
912 if( conn->c_sasl_bind_in_progress && tag != LDAP_REQ_BIND ) {
914 LDAP_LOG( CONNECTION, ERR,
915 "connection_operation: conn %lu SASL bind in progress (tag=%ld).\n",
916 conn->c_connid, (long)tag, 0 );
918 Debug( LDAP_DEBUG_ANY, "connection_operation: "
919 "error: SASL bind in progress (tag=%ld).\n",
922 send_ldap_error( op, &rs, LDAP_OPERATIONS_ERROR,
923 "SASL bind in progress" );
924 goto operations_error;
927 /* We can use Thread-Local storage for most mallocs. We can
928 * also use TL for ber parsing, but not on Add or Modify.
930 #define SLAB_SIZE 1048576
932 memsiz = ber_len( op->o_ber ) * 64;
933 if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE;
937 memctx = sl_mem_create( memsiz, ctx );
938 op->o_tmpmemctx = memctx;
939 op->o_tmpmfuncs = &sl_mfuncs;
940 if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) {
941 /* Note - the ber and its buffer are already allocated from
942 * regular memory; this only affects subsequent mallocs that
943 * ber_scanf may invoke.
945 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx );
950 INCR_OP(num_ops_initiated_, SLAP_OP_BIND);
951 rc = do_bind( op, &rs );
954 case LDAP_REQ_UNBIND:
955 INCR_OP(num_ops_initiated_, SLAP_OP_UNBIND);
956 rc = do_unbind( op, &rs );
960 INCR_OP(num_ops_initiated_, SLAP_OP_ADD);
961 rc = do_add( op, &rs );
964 case LDAP_REQ_DELETE:
965 INCR_OP(num_ops_initiated_, SLAP_OP_DELETE);
966 rc = do_delete( op, &rs );
969 case LDAP_REQ_MODRDN:
970 INCR_OP(num_ops_initiated_, SLAP_OP_MODRDN);
971 rc = do_modrdn( op, &rs );
974 case LDAP_REQ_MODIFY:
975 INCR_OP(num_ops_initiated_, SLAP_OP_MODIFY);
976 rc = do_modify( op, &rs );
979 case LDAP_REQ_COMPARE:
980 INCR_OP(num_ops_initiated_, SLAP_OP_COMPARE);
981 rc = do_compare( op, &rs );
984 case LDAP_REQ_SEARCH:
985 INCR_OP(num_ops_initiated_, SLAP_OP_SEARCH);
986 rc = do_search( op, &rs );
989 case LDAP_REQ_ABANDON:
990 INCR_OP(num_ops_initiated_, SLAP_OP_ABANDON);
991 rc = do_abandon( op, &rs );
994 case LDAP_REQ_EXTENDED:
995 INCR_OP(num_ops_initiated_, SLAP_OP_EXTENDED);
996 rc = do_extended( op, &rs );
1001 LDAP_LOG( CONNECTION, INFO,
1002 "connection_operation: conn %lu unknown LDAP request 0x%lx\n",
1003 conn->c_connid, tag, 0 );
1005 Debug( LDAP_DEBUG_ANY, "unknown LDAP request 0x%lx\n",
1008 op->o_tag = LBER_ERROR;
1009 rs.sr_err = LDAP_PROTOCOL_ERROR;
1010 rs.sr_text = "unknown LDAP request";
1011 send_ldap_disconnect( op, &rs );
1016 #ifdef SLAPD_MONITOR
1018 #endif /* SLAPD_MONITOR */
1019 if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR;
1022 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
1023 num_ops_completed++;
1024 #ifdef SLAPD_MONITOR
1027 num_ops_completed_[SLAP_OP_BIND]++;
1029 case LDAP_REQ_UNBIND:
1030 num_ops_completed_[SLAP_OP_UNBIND]++;
1033 num_ops_completed_[SLAP_OP_ADD]++;
1035 case LDAP_REQ_DELETE:
1036 num_ops_completed_[SLAP_OP_DELETE]++;
1038 case LDAP_REQ_MODRDN:
1039 num_ops_completed_[SLAP_OP_MODRDN]++;
1041 case LDAP_REQ_MODIFY:
1042 num_ops_completed_[SLAP_OP_MODIFY]++;
1044 case LDAP_REQ_COMPARE:
1045 num_ops_completed_[SLAP_OP_COMPARE]++;
1047 case LDAP_REQ_SEARCH:
1048 num_ops_completed_[SLAP_OP_SEARCH]++;
1050 case LDAP_REQ_ABANDON:
1051 num_ops_completed_[SLAP_OP_ABANDON]++;
1053 case LDAP_REQ_EXTENDED:
1054 num_ops_completed_[SLAP_OP_EXTENDED]++;
1057 #endif /* SLAPD_MONITOR */
1058 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
1060 #ifdef LDAP_EXOP_X_CANCEL
1061 if ( op->o_cancel == SLAP_CANCEL_REQ ) {
1062 op->o_cancel = LDAP_TOO_LATE;
1065 while ( op->o_cancel != SLAP_CANCEL_NONE &&
1066 op->o_cancel != SLAP_CANCEL_DONE )
1068 ldap_pvt_thread_yield();
1072 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1074 if ( op->o_cancel != SLAP_CANCEL_ACK && ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) {
1075 sl_mem_detach( ctx, memctx );
1079 LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
1080 LDAP_STAILQ_NEXT(op, o_next) = NULL;
1082 conn->c_n_ops_executing--;
1083 conn->c_n_ops_completed++;
1085 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx );
1092 case LDAP_REQ_UNBIND:
1093 /* c_mutex is locked */
1094 connection_closing( conn );
1098 conn->c_sasl_bind_in_progress =
1099 rc == LDAP_SASL_BIND_IN_PROGRESS ? 1 : 0;
1101 if( conn->c_conn_state == SLAP_C_BINDING) {
1102 conn->c_conn_state = SLAP_C_ACTIVE;
1106 connection_resched( conn );
1108 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1113 int connection_read(ber_socket_t s)
1118 assert( connections != NULL );
1120 ldap_pvt_thread_mutex_lock( &connections_mutex );
1122 /* get (locked) connection */
1123 c = connection_get( s );
1127 LDAP_LOG( CONNECTION, INFO,
1128 "connection_read: sock %ld no connection\n", (long)s, 0, 0 );
1130 Debug( LDAP_DEBUG_ANY,
1131 "connection_read(%ld): no connection!\n",
1136 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1142 if( c->c_conn_state == SLAP_C_CLOSING ) {
1144 LDAP_LOG( CONNECTION, INFO,
1145 "connection_read: conn %lu connection closing, ignoring input\n",
1146 c->c_connid, 0, 0 );
1148 Debug( LDAP_DEBUG_TRACE,
1149 "connection_read(%d): closing, ignoring input for id=%lu\n",
1150 s, c->c_connid, 0 );
1152 connection_return( c );
1153 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1158 LDAP_LOG( CONNECTION, DETAIL1,
1159 "connection_read: conn %lu checking for input.\n",
1160 c->c_connid, 0, 0 );
1162 Debug( LDAP_DEBUG_TRACE,
1163 "connection_read(%d): checking for input on id=%lu\n",
1164 s, c->c_connid, 0 );
1168 if ( c->c_is_tls && c->c_needs_tls_accept ) {
1169 rc = ldap_pvt_tls_accept( c->c_sb, NULL );
1171 #if 0 /* required by next #if 0 */
1177 LDAP_LOG( CONNECTION, ERR,
1178 "connection_read: conn %lu TLS accept error, error %d\n",
1179 c->c_connid, rc, 0 );
1181 Debug( LDAP_DEBUG_TRACE,
1182 "connection_read(%d): TLS accept error "
1183 "error=%d id=%lu, closing\n",
1184 s, rc, c->c_connid );
1186 c->c_needs_tls_accept = 0;
1187 /* connections_mutex and c_mutex are locked */
1188 connection_closing( c );
1191 /* Drain input before close, to allow SSL error codes
1192 * to propagate to client. */
1198 rc = select(s+1, &rfd, NULL, NULL, &tv);
1200 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DRAIN, NULL);
1204 connection_close( c );
1206 } else if ( rc == 0 ) {
1208 struct berval authid = { 0, NULL };
1210 c->c_needs_tls_accept = 0;
1212 /* we need to let SASL know */
1213 ssl = ldap_pvt_tls_sb_ctx( c->c_sb );
1215 c->c_tls_ssf = (slap_ssf_t) ldap_pvt_tls_get_strength( ssl );
1216 if( c->c_tls_ssf > c->c_ssf ) {
1217 c->c_ssf = c->c_tls_ssf;
1220 rc = dnX509peerNormalize( ssl, &authid );
1221 if ( rc != LDAP_SUCCESS ) {
1223 LDAP_LOG( CONNECTION, INFO,
1224 "connection_read: conn %lu unable to get TLS client DN, "
1225 "error %d\n", c->c_connid, rc, 0 );
1227 Debug( LDAP_DEBUG_TRACE,
1228 "connection_read(%d): unable to get TLS client DN "
1229 "error=%d id=%lu\n",
1230 s, rc, c->c_connid );
1233 slap_sasl_external( c, c->c_tls_ssf, authid.bv_val );
1234 if ( authid.bv_val ) free( authid.bv_val );
1237 /* if success and data is ready, fall thru to data input loop */
1239 !ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) )
1241 connection_return( c );
1242 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1248 #ifdef HAVE_CYRUS_SASL
1249 if ( c->c_sasl_layers ) {
1250 /* If previous layer is not removed yet, give up for now */
1251 if ( !c->c_sasl_sockctx ) {
1252 connection_return( c );
1253 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1257 c->c_sasl_layers = 0;
1259 rc = ldap_pvt_sasl_install( c->c_sb, c->c_sasl_sockctx );
1261 if( rc != LDAP_SUCCESS ) {
1263 LDAP_LOG( CONNECTION, ERR,
1264 "connection_read: conn %lu SASL install error %d, closing\n",
1265 c->c_connid, rc, 0 );
1267 Debug( LDAP_DEBUG_TRACE,
1268 "connection_read(%d): SASL install error "
1269 "error=%d id=%lu, closing\n",
1270 s, rc, c->c_connid );
1272 /* connections_mutex and c_mutex are locked */
1273 connection_closing( c );
1274 connection_close( c );
1275 connection_return( c );
1276 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1282 #define CONNECTION_INPUT_LOOP 1
1283 /* #define DATA_READY_LOOP 1 */
1287 /* How do we do this without getting into a busy loop ? */
1288 rc = connection_input( c );
1290 #ifdef DATA_READY_LOOP
1291 while( !rc && ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) );
1292 #elif CONNECTION_INPUT_LOOP
1300 LDAP_LOG( CONNECTION, ERR,
1301 "connection_read: conn %lu input error %d, closing.\n",
1302 c->c_connid, rc, 0 );
1304 Debug( LDAP_DEBUG_TRACE,
1305 "connection_read(%d): input error=%d id=%lu, closing.\n",
1306 s, rc, c->c_connid );
1308 /* connections_mutex and c_mutex are locked */
1309 connection_closing( c );
1310 connection_close( c );
1311 connection_return( c );
1312 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1316 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) ) {
1317 slapd_set_read( s, 1 );
1320 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
1321 slapd_set_write( s, 1 );
1324 connection_return( c );
1325 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1340 #ifdef LDAP_CONNECTIONLESS
1345 if ( conn->c_currentber == NULL &&
1346 ( conn->c_currentber = ber_alloc()) == NULL )
1349 LDAP_LOG( CONNECTION, ERR,
1350 "connection_input: conn %lu ber_alloc failed.\n",
1351 conn->c_connid, 0, 0 );
1353 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
1360 #ifdef LDAP_CONNECTIONLESS
1361 if ( conn->c_is_udp ) {
1362 char peername[sizeof("IP=255.255.255.255:65336")];
1363 len = ber_int_sb_read(conn->c_sb, &peeraddr,
1364 sizeof(struct sockaddr));
1365 if (len != sizeof(struct sockaddr))
1367 sprintf( peername, "IP=%s:%d",
1368 inet_ntoa( peeraddr.sa_in_addr.sin_addr ),
1369 (unsigned) ntohs( peeraddr.sa_in_addr.sin_port ) );
1370 Statslog( LDAP_DEBUG_STATS,
1371 "conn=%lu UDP request from %s (%s) accepted.\n",
1372 conn->c_connid, peername, conn->c_sock_name.bv_val, 0, 0 );
1375 tag = ber_get_next( conn->c_sb, &len, conn->c_currentber );
1376 if ( tag != LDAP_TAG_MESSAGE ) {
1380 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
1383 LDAP_LOG( CONNECTION, ERR,
1384 "connection_input: conn %lu ber_get_next failed, errno %d (%s).\n",
1385 conn->c_connid, err, sock_errstr(err) );
1387 Debug( LDAP_DEBUG_TRACE,
1388 "ber_get_next on fd %d failed errno=%d (%s)\n",
1389 sd, err, sock_errstr(err) );
1391 if ( err != EWOULDBLOCK && err != EAGAIN ) {
1392 /* log, close and send error */
1393 ber_free( conn->c_currentber, 1 );
1394 conn->c_currentber = NULL;
1401 ber = conn->c_currentber;
1402 conn->c_currentber = NULL;
1404 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
1405 /* log, close and send error */
1407 LDAP_LOG( CONNECTION, ERR,
1408 "connection_input: conn %lu ber_get_int returns 0x%lx.\n",
1409 conn->c_connid, tag, 0 );
1411 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
1418 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
1419 /* log, close and send error */
1421 LDAP_LOG( CONNECTION, ERR,
1422 "connection_input: conn %lu ber_peek_tag returns 0x%lx.\n",
1423 conn->c_connid, tag, 0 );
1425 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
1433 #ifdef LDAP_CONNECTIONLESS
1434 if( conn->c_is_udp ) {
1435 if( tag == LBER_OCTETSTRING ) {
1436 ber_get_stringa( ber, &cdn );
1437 tag = ber_peek_tag(ber, &len);
1439 if( tag != LDAP_REQ_ABANDON && tag != LDAP_REQ_SEARCH ) {
1441 LDAP_LOG( CONNECTION, ERR,
1442 "connection_input: conn %lu invalid req for UDP 0x%lx.\n",
1443 conn->c_connid, tag, 0 );
1445 Debug( LDAP_DEBUG_ANY, "invalid req for UDP 0x%lx\n", tag, 0,
1453 if(tag == LDAP_REQ_BIND) {
1454 /* immediately abandon all exiting operations upon BIND */
1455 connection_abandon( conn );
1458 op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++ );
1461 op->o_assertion = NULL;
1462 op->o_preread_attrs = NULL;
1463 op->o_postread_attrs = NULL;
1464 op->o_vrFilter = NULL;
1466 #ifdef LDAP_CONTROL_PAGEDRESULTS
1467 op->o_pagedresults_state = conn->c_pagedresults_state;
1470 op->o_res_ber = NULL;
1472 #ifdef LDAP_CONNECTIONLESS
1473 if (conn->c_is_udp) {
1475 ber_str2bv( cdn, 0, 1, &op->o_dn );
1476 op->o_protocol = LDAP_VERSION2;
1478 op->o_res_ber = ber_alloc_t( LBER_USE_DER );
1479 if (op->o_res_ber == NULL) return 1;
1481 rc = ber_write( op->o_res_ber, (char *)&peeraddr,
1482 sizeof(struct sockaddr), 0 );
1484 if (rc != sizeof(struct sockaddr)) {
1486 LDAP_LOG( CONNECTION, INFO,
1487 "connection_input: conn %lu ber_write failed\n",
1488 conn->c_connid, 0, 0 );
1490 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
1495 if (op->o_protocol == LDAP_VERSION2) {
1496 rc = ber_printf(op->o_res_ber, "{is{" /*}}*/, op->o_msgid, "");
1499 LDAP_LOG( CONNECTION, INFO,
1500 "connection_input: conn %lu put outer sequence failed\n",
1501 conn->c_connid, 0, 0 );
1503 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
1509 #endif /* LDAP_CONNECTIONLESS */
1513 /* Don't process requests when the conn is in the middle of a
1514 * Bind, or if it's closing. Also, don't let any single conn
1515 * use up all the available threads, and don't execute if we're
1516 * currently blocked on output. And don't execute if there are
1517 * already pending ops, let them go first.
1519 * But always allow Abandon through; it won't cost much.
1521 if ( tag != LDAP_REQ_ABANDON && (conn->c_conn_state == SLAP_C_BINDING
1522 || conn->c_conn_state == SLAP_C_CLOSING
1523 || conn->c_n_ops_executing >= connection_pool_max/2
1524 || conn->c_n_ops_pending
1525 || conn->c_writewaiter))
1527 int max = conn->c_dn.bv_len ? slap_conn_max_pending_auth
1528 : slap_conn_max_pending;
1530 LDAP_LOG( CONNECTION, INFO,
1531 "connection_input: conn %lu deferring operation\n",
1532 conn->c_connid, 0, 0 );
1534 Debug( LDAP_DEBUG_ANY, "deferring operation\n", 0, 0, 0 );
1536 conn->c_n_ops_pending++;
1537 LDAP_STAILQ_INSERT_TAIL( &conn->c_pending_ops, op, o_next );
1538 if ( conn->c_n_ops_pending > max ) {
1544 conn->c_n_ops_executing++;
1545 connection_op_activate( op );
1549 if ( conn->c_struct_state != SLAP_C_USED ) {
1550 /* connection must have got closed underneath us */
1554 assert( conn->c_struct_state == SLAP_C_USED );
1560 connection_resched( Connection *conn )
1564 if( conn->c_conn_state == SLAP_C_CLOSING ) {
1567 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
1569 /* us trylock to avoid possible deadlock */
1570 rc = ldap_pvt_thread_mutex_trylock( &connections_mutex );
1574 LDAP_LOG( CONNECTION, DETAIL1,
1575 "connection_resched: conn %lu reaquiring locks.\n",
1576 conn->c_connid, 0, 0 );
1578 Debug( LDAP_DEBUG_TRACE,
1579 "connection_resched: reaquiring locks conn=%lu sd=%d\n",
1580 conn->c_connid, sd, 0 );
1583 * reaquire locks in the right order...
1584 * this may allow another thread to close this connection,
1585 * so recheck state below.
1587 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1588 ldap_pvt_thread_mutex_lock( &connections_mutex );
1589 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1592 if( conn->c_conn_state != SLAP_C_CLOSING ) {
1594 LDAP_LOG( CONNECTION, INFO,
1595 "connection_resched: conn %lu closed by other thread.\n",
1596 conn->c_connid, 0, 0 );
1598 Debug( LDAP_DEBUG_TRACE, "connection_resched: "
1599 "closed by other thread conn=%lu sd=%d\n",
1600 conn->c_connid, sd, 0 );
1604 LDAP_LOG( CONNECTION, DETAIL1,
1605 "connection_resched: conn %lu attempting closing.\n",
1606 conn->c_connid, 0, 0 );
1608 Debug( LDAP_DEBUG_TRACE, "connection_resched: "
1609 "attempting closing conn=%lu sd=%d\n",
1610 conn->c_connid, sd, 0 );
1612 connection_close( conn );
1615 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1619 if( conn->c_conn_state != SLAP_C_ACTIVE || conn->c_writewaiter ) {
1620 /* other states need different handling */
1624 while ((op = LDAP_STAILQ_FIRST( &conn->c_pending_ops )) != NULL) {
1625 if ( conn->c_n_ops_executing > connection_pool_max/2 ) {
1628 LDAP_STAILQ_REMOVE_HEAD( &conn->c_pending_ops, o_next );
1629 LDAP_STAILQ_NEXT(op, o_next) = NULL;
1630 /* pending operations should not be marked for abandonment */
1631 assert(!op->o_abandon);
1633 conn->c_n_ops_pending--;
1634 conn->c_n_ops_executing++;
1636 connection_op_activate( op );
1638 if ( conn->c_conn_state == SLAP_C_BINDING ) {
1645 static int connection_op_activate( Operation *op )
1648 ber_tag_t tag = op->o_tag;
1650 if(tag == LDAP_REQ_BIND) {
1651 op->o_conn->c_conn_state = SLAP_C_BINDING;
1654 if (!op->o_dn.bv_len) {
1655 op->o_authz = op->o_conn->c_authz;
1656 ber_dupbv( &op->o_dn, &op->o_conn->c_dn );
1657 ber_dupbv( &op->o_ndn, &op->o_conn->c_ndn );
1659 op->o_authtype = op->o_conn->c_authtype;
1660 ber_dupbv( &op->o_authmech, &op->o_conn->c_authmech );
1662 if (!op->o_protocol) {
1663 op->o_protocol = op->o_conn->c_protocol
1664 ? op->o_conn->c_protocol : LDAP_VERSION3;
1666 if (op->o_conn->c_conn_state == SLAP_C_INACTIVE
1667 && op->o_protocol > LDAP_VERSION2) {
1668 op->o_conn->c_conn_state = SLAP_C_ACTIVE;
1671 op->o_connid = op->o_conn->c_connid;
1673 LDAP_STAILQ_INSERT_TAIL( &op->o_conn->c_ops, op, o_next );
1675 status = ldap_pvt_thread_pool_submit( &connection_pool,
1676 connection_operation, (void *) op );
1678 if ( status != 0 ) {
1680 LDAP_LOG( CONNECTION, ERR,
1681 "connection_op_activate: conn %lu thread pool submit failed.\n",
1682 op->o_connid, 0, 0 );
1684 Debug( LDAP_DEBUG_ANY,
1685 "ldap_pvt_thread_pool_submit failed (%d)\n", status, 0, 0 );
1687 /* should move op to pending list */
1693 int connection_write(ber_socket_t s)
1697 assert( connections != NULL );
1699 ldap_pvt_thread_mutex_lock( &connections_mutex );
1701 c = connection_get( s );
1703 slapd_clr_write( s, 0);
1707 LDAP_LOG( CONNECTION, ERR,
1708 "connection_write: sock %ld no connection!\n", (long)s, 0, 0);
1710 Debug( LDAP_DEBUG_ANY,
1711 "connection_write(%ld): no connection!\n",
1715 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1722 LDAP_LOG( CONNECTION, DETAIL1,
1723 "connection_write conn %lu waking output.\n", c->c_connid, 0, 0 );
1725 Debug( LDAP_DEBUG_TRACE,
1726 "connection_write(%d): waking output for id=%lu\n",
1727 s, c->c_connid, 0 );
1729 ldap_pvt_thread_cond_signal( &c->c_write_cv );
1731 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) )
1732 slapd_set_read( s, 1 );
1733 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) )
1734 slapd_set_write( s, 1 );
1735 connection_return( c );
1736 ldap_pvt_thread_mutex_unlock( &connections_mutex );