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 */
42 #define SLAP_C_CLIENT 0x05 /* outbound client conn */
45 connection_state2str( int state )
48 case SLAP_C_INVALID: return "!";
49 case SLAP_C_INACTIVE: return "|";
50 case SLAP_C_ACTIVE: return "";
51 case SLAP_C_BINDING: return "B";
52 case SLAP_C_CLOSING: return "C";
53 case SLAP_C_CLIENT: return "L";
59 static Connection* connection_get( ber_socket_t s );
61 static int connection_input( Connection *c );
62 static void connection_close( Connection *c );
64 static int connection_op_activate( Operation *op );
65 static int connection_resched( Connection *conn );
66 static void connection_abandon( Connection *conn );
67 static void connection_destroy( Connection *c );
69 static ldap_pvt_thread_start_t connection_operation;
72 * Initialize connection management infrastructure.
74 int connections_init(void)
76 assert( connections == NULL );
78 if( connections != NULL) {
80 LDAP_LOG( CONNECTION, INFO,
81 "connections_init: already initialized.\n", 0, 0, 0 );
83 Debug( LDAP_DEBUG_ANY, "connections_init: already initialized.\n",
89 /* should check return of every call */
90 ldap_pvt_thread_mutex_init( &connections_mutex );
92 connections = (Connection *) ch_calloc( dtblsize, sizeof(Connection) );
94 if( connections == NULL ) {
96 LDAP_LOG( CONNECTION, ERR,
97 "connections_init: allocation (%d * %ld) of connection "
98 "array failed\n", dtblsize, (long) sizeof(Connection), 0 );
100 Debug( LDAP_DEBUG_ANY,
101 "connections_init: allocation (%d*%ld) of connection array failed\n",
102 dtblsize, (long) sizeof(Connection), 0 );
107 assert( connections[0].c_struct_state == SLAP_C_UNINITIALIZED );
108 assert( connections[dtblsize-1].c_struct_state == SLAP_C_UNINITIALIZED );
111 * per entry initialization of the Connection array initialization
112 * will be done by connection_init()
119 * Destroy connection management infrastructure.
121 int connections_destroy(void)
125 /* should check return of every call */
127 if( connections == NULL) {
129 LDAP_LOG( CONNECTION, INFO,
130 "connections_destroy: nothing to destroy.\n", 0, 0, 0 );
132 Debug( LDAP_DEBUG_ANY, "connections_destroy: nothing to destroy.\n",
138 for ( i = 0; i < dtblsize; i++ ) {
139 if( connections[i].c_struct_state != SLAP_C_UNINITIALIZED ) {
140 ber_sockbuf_free( connections[i].c_sb );
141 ldap_pvt_thread_mutex_destroy( &connections[i].c_mutex );
142 ldap_pvt_thread_mutex_destroy( &connections[i].c_write_mutex );
143 ldap_pvt_thread_cond_destroy( &connections[i].c_write_cv );
145 slapi_x_free_object_extensions( SLAPI_X_EXT_CONNECTION, &connections[i] );
153 ldap_pvt_thread_mutex_destroy( &connections_mutex );
158 * shutdown all connections
160 int connections_shutdown(void)
164 ldap_pvt_thread_mutex_lock( &connections_mutex );
166 for ( i = 0; i < dtblsize; i++ ) {
167 if( connections[i].c_struct_state != SLAP_C_USED ) {
171 ldap_pvt_thread_mutex_lock( &connections[i].c_mutex );
173 /* connections_mutex and c_mutex are locked */
174 connection_closing( &connections[i] );
175 connection_close( &connections[i] );
177 ldap_pvt_thread_mutex_unlock( &connections[i].c_mutex );
180 ldap_pvt_thread_mutex_unlock( &connections_mutex );
186 * Timeout idle connections.
188 int connections_timeout_idle(time_t now)
194 for( c = connection_first( &connindex );
196 c = connection_next( c, &connindex ) )
198 /* Don't timeout a slow-running request */
199 if( c->c_n_ops_executing ) continue;
201 if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) {
203 connection_closing( c );
204 connection_close( c );
208 connection_done( c );
213 static Connection* connection_get( ber_socket_t s )
215 /* connections_mutex should be locked by caller */
220 LDAP_LOG( CONNECTION, ENTRY, "connection_get: socket %ld\n", (long)s, 0, 0 );
222 Debug( LDAP_DEBUG_ARGS,
223 "connection_get(%ld)\n",
227 assert( connections != NULL );
229 if(s == AC_SOCKET_INVALID) {
236 assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
243 for(i=0; i<dtblsize; i++) {
244 if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
245 assert( connections[i].c_conn_state == SLAP_C_INVALID );
246 assert( connections[i].c_sb == 0 );
250 ber_sockbuf_ctrl( connections[i].c_sb,
251 LBER_SB_OPT_GET_FD, &sd );
253 if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
254 assert( connections[i].c_conn_state == SLAP_C_INVALID );
255 assert( sd == AC_SOCKET_INVALID );
259 /* state can actually change from used -> unused by resched,
260 * so don't assert details here.
274 ldap_pvt_thread_mutex_lock( &c->c_mutex );
276 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
277 if( c->c_struct_state != SLAP_C_USED ) {
278 /* connection must have been closed due to resched */
280 assert( c->c_conn_state == SLAP_C_INVALID );
281 assert( sd == AC_SOCKET_INVALID );
284 LDAP_LOG( CONNECTION, ARGS,
285 "connection_get: connection %d not used\n", s, 0, 0 );
287 Debug( LDAP_DEBUG_TRACE,
288 "connection_get(%d): connection not used\n",
292 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
297 LDAP_LOG( CONNECTION, RESULTS,
298 "connection_get: get for %d got connid %lu\n", s, c->c_connid, 0 );
300 Debug( LDAP_DEBUG_TRACE,
301 "connection_get(%d): got connid=%lu\n",
307 assert( c->c_struct_state == SLAP_C_USED );
308 assert( c->c_conn_state != SLAP_C_INVALID );
309 assert( sd != AC_SOCKET_INVALID );
312 c->c_activitytime = slap_get_time();
314 if( global_idletimeout > 0 ) {
315 c->c_activitytime = slap_get_time();
323 static void connection_return( Connection *c )
325 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
328 long connection_init(
332 const char* peername,
340 assert( connections != NULL );
342 assert( listener != NULL );
343 assert( dnsname != NULL );
344 assert( peername != NULL );
347 assert( tls_udp_option != 1 );
350 if( s == AC_SOCKET_INVALID ) {
352 LDAP_LOG( CONNECTION, INFO,
353 "connection_init: init of socket %ld invalid.\n", (long)s, 0, 0 );
355 Debug( LDAP_DEBUG_ANY,
356 "connection_init(%ld): invalid.\n",
364 assert( s < dtblsize );
367 ldap_pvt_thread_mutex_lock( &connections_mutex );
378 for( i=0; i < dtblsize; i++) {
381 if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
382 assert( connections[i].c_sb == 0 );
387 sd = AC_SOCKET_INVALID;
388 if (connections[i].c_sb != NULL)
389 ber_sockbuf_ctrl( connections[i].c_sb, LBER_SB_OPT_GET_FD, &sd );
391 if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
392 assert( sd == AC_SOCKET_INVALID );
397 assert( connections[i].c_struct_state == SLAP_C_USED );
398 assert( connections[i].c_conn_state != SLAP_C_INVALID );
399 assert( sd != AC_SOCKET_INVALID );
404 LDAP_LOG( CONNECTION, INFO,
405 "connection_init: skt %d connection table full "
406 "(%d/%d)\n", s, i, dtblsize );
408 Debug( LDAP_DEBUG_ANY,
409 "connection_init(%d): connection table full "
410 "(%d/%d)\n", s, i, dtblsize);
412 ldap_pvt_thread_mutex_unlock( &connections_mutex );
420 if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
421 c->c_send_ldap_result = slap_send_ldap_result;
422 c->c_send_search_entry = slap_send_search_entry;
423 c->c_send_search_reference = slap_send_search_reference;
424 c->c_send_ldap_extended = slap_send_ldap_extended;
425 #ifdef LDAP_RES_INTERMEDIATE
426 c->c_send_ldap_intermediate = slap_send_ldap_intermediate;
429 c->c_authmech.bv_val = NULL;
430 c->c_authmech.bv_len = 0;
431 c->c_dn.bv_val = NULL;
433 c->c_ndn.bv_val = NULL;
436 c->c_listener = NULL;
437 c->c_peer_domain.bv_val = NULL;
438 c->c_peer_domain.bv_len = 0;
439 c->c_peer_name.bv_val = NULL;
440 c->c_peer_name.bv_len = 0;
442 LDAP_STAILQ_INIT(&c->c_ops);
443 LDAP_STAILQ_INIT(&c->c_pending_ops);
445 c->c_sasl_bind_mech.bv_val = NULL;
446 c->c_sasl_bind_mech.bv_len = 0;
448 c->c_sasl_authctx = NULL;
449 c->c_sasl_sockctx = NULL;
450 c->c_sasl_extra = NULL;
451 c->c_sasl_bindop = NULL;
453 c->c_sb = ber_sockbuf_alloc( );
456 ber_len_t max = sockbuf_max_incoming;
457 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
460 c->c_currentber = NULL;
462 /* should check status of thread calls */
463 ldap_pvt_thread_mutex_init( &c->c_mutex );
464 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
465 ldap_pvt_thread_cond_init( &c->c_write_cv );
468 if ( slapi_plugins_used ) {
469 slapi_x_create_object_extensions( SLAPI_X_EXT_CONNECTION, c );
473 c->c_struct_state = SLAP_C_UNUSED;
476 ldap_pvt_thread_mutex_lock( &c->c_mutex );
478 assert( c->c_struct_state == SLAP_C_UNUSED );
479 assert( c->c_authmech.bv_val == NULL );
480 assert( c->c_dn.bv_val == NULL );
481 assert( c->c_ndn.bv_val == NULL );
482 assert( c->c_listener == NULL );
483 assert( c->c_peer_domain.bv_val == NULL );
484 assert( c->c_peer_name.bv_val == NULL );
485 assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
486 assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
487 assert( c->c_sasl_bind_mech.bv_val == NULL );
488 assert( c->c_sasl_done == 0 );
489 assert( c->c_sasl_authctx == NULL );
490 assert( c->c_sasl_sockctx == NULL );
491 assert( c->c_sasl_extra == NULL );
492 assert( c->c_sasl_bindop == NULL );
493 assert( c->c_currentber == NULL );
495 c->c_listener = listener;
496 ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
497 ber_str2bv( peername, 0, 1, &c->c_peer_name );
499 c->c_n_ops_received = 0;
500 c->c_n_ops_executing = 0;
501 c->c_n_ops_pending = 0;
502 c->c_n_ops_completed = 0;
508 /* set to zero until bind, implies LDAP_VERSION3 */
512 c->c_activitytime = c->c_starttime = slap_get_time();
514 if( global_idletimeout > 0 ) {
515 c->c_activitytime = c->c_starttime = slap_get_time();
519 #ifdef LDAP_CONNECTIONLESS
521 if( tls_udp_option == 2 ) {
524 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
525 LBER_SBIOD_LEVEL_PROVIDER, (void*)"udp_" );
527 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_udp,
528 LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
529 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_readahead,
530 LBER_SBIOD_LEVEL_PROVIDER, NULL );
535 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
536 LBER_SBIOD_LEVEL_PROVIDER, (void*)"tcp_" );
538 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_tcp,
539 LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
543 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
544 INT_MAX, (void*)"ldap_" );
547 if( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_NONBLOCK,
548 c /* non-NULL */ ) < 0 )
551 LDAP_LOG( CONNECTION, INFO,
552 "connection_init: conn %lu set nonblocking failed\n",
555 Debug( LDAP_DEBUG_ANY,
556 "connection_init(%d, %s): set nonblocking failed\n",
557 s, c->c_peer_name.bv_val, 0 );
561 id = c->c_connid = conn_nextid++;
563 c->c_conn_state = SLAP_C_INACTIVE;
564 c->c_struct_state = SLAP_C_USED;
566 c->c_ssf = c->c_transport_ssf = ssf;
570 if ( tls_udp_option == 1 ) {
572 c->c_needs_tls_accept = 1;
575 c->c_needs_tls_accept = 0;
579 slap_sasl_open( c, 0 );
580 slap_sasl_external( c, ssf, authid );
582 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
583 ldap_pvt_thread_mutex_unlock( &connections_mutex );
585 backend_connection_init(c);
590 void connection2anonymous( Connection *c )
592 assert( connections != NULL );
596 ber_len_t max = sockbuf_max_incoming;
597 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
600 if(c->c_authmech.bv_val != NULL ) {
601 free(c->c_authmech.bv_val);
602 c->c_authmech.bv_val = NULL;
604 c->c_authmech.bv_len = 0;
606 if(c->c_dn.bv_val != NULL) {
607 free(c->c_dn.bv_val);
608 c->c_dn.bv_val = NULL;
611 if(c->c_ndn.bv_val != NULL) {
612 free(c->c_ndn.bv_val);
613 c->c_ndn.bv_val = NULL;
617 c->c_authz_backend = NULL;
621 connection_destroy( Connection *c )
623 /* note: connections_mutex should be locked by caller */
625 unsigned long connid;
627 assert( connections != NULL );
629 assert( c->c_struct_state != SLAP_C_UNUSED );
630 assert( c->c_conn_state != SLAP_C_INVALID );
631 assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
633 /* only for stats (print -1 as "%lu" may give unexpected results ;) */
634 connid = c->c_connid;
636 backend_connection_destroy(c);
641 c->c_activitytime = c->c_starttime = 0;
643 connection2anonymous( c );
644 c->c_listener = NULL;
646 if(c->c_peer_domain.bv_val != NULL) {
647 free(c->c_peer_domain.bv_val);
648 c->c_peer_domain.bv_val = NULL;
650 c->c_peer_domain.bv_len = 0;
651 if(c->c_peer_name.bv_val != NULL) {
652 free(c->c_peer_name.bv_val);
653 c->c_peer_name.bv_val = NULL;
655 c->c_peer_name.bv_len = 0;
657 c->c_sasl_bind_in_progress = 0;
658 if(c->c_sasl_bind_mech.bv_val != NULL) {
659 free(c->c_sasl_bind_mech.bv_val);
660 c->c_sasl_bind_mech.bv_val = NULL;
662 c->c_sasl_bind_mech.bv_len = 0;
664 slap_sasl_close( c );
666 if ( c->c_currentber != NULL ) {
667 ber_free( c->c_currentber, 1 );
668 c->c_currentber = NULL;
671 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
672 if ( sd != AC_SOCKET_INVALID ) {
673 slapd_remove( sd, 0 );
675 Statslog( LDAP_DEBUG_STATS,
676 "conn=%lu fd=%ld closed\n",
677 connid, (long) sd, 0, 0, 0 );
680 ber_sockbuf_free( c->c_sb );
682 c->c_sb = ber_sockbuf_alloc( );
685 ber_len_t max = sockbuf_max_incoming;
686 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
689 c->c_conn_state = SLAP_C_INVALID;
690 c->c_struct_state = SLAP_C_UNUSED;
693 /* call destructors, then constructors; avoids unnecessary allocation */
694 if ( slapi_plugins_used ) {
695 slapi_x_clear_object_extensions( SLAPI_X_EXT_CONNECTION, c );
700 int connection_state_closing( Connection *c )
702 /* c_mutex must be locked by caller */
706 assert( c->c_struct_state == SLAP_C_USED );
708 state = c->c_conn_state;
710 assert( state != SLAP_C_INVALID );
712 return state == SLAP_C_CLOSING;
715 static void connection_abandon( Connection *c )
717 /* c_mutex must be locked by caller */
721 LDAP_STAILQ_FOREACH(o, &c->c_ops, o_next) {
725 /* remove pending operations */
726 while ( (o = LDAP_STAILQ_FIRST( &c->c_pending_ops )) != NULL) {
727 LDAP_STAILQ_REMOVE_HEAD( &c->c_pending_ops, o_next );
728 LDAP_STAILQ_NEXT(o, o_next) = NULL;
733 void connection_closing( Connection *c )
735 assert( connections != NULL );
737 assert( c->c_struct_state == SLAP_C_USED );
738 assert( c->c_conn_state != SLAP_C_INVALID );
740 /* c_mutex must be locked by caller */
742 if( c->c_conn_state != SLAP_C_CLOSING ) {
745 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
747 LDAP_LOG( CONNECTION, DETAIL1,
748 "connection_closing: conn %lu readying socket %d for close.\n",
749 c->c_connid, sd, 0 );
751 Debug( LDAP_DEBUG_TRACE,
752 "connection_closing: readying conn=%lu sd=%d for close\n",
753 c->c_connid, sd, 0 );
755 /* update state to closing */
756 c->c_conn_state = SLAP_C_CLOSING;
758 /* don't listen on this port anymore */
759 slapd_clr_read( sd, 1 );
761 /* abandon active operations */
762 connection_abandon( c );
764 /* wake write blocked operations */
765 slapd_clr_write( sd, 1 );
766 ldap_pvt_thread_cond_signal( &c->c_write_cv );
770 static void connection_close( Connection *c )
774 assert( connections != NULL );
776 assert( c->c_struct_state == SLAP_C_USED );
777 assert( c->c_conn_state == SLAP_C_CLOSING );
779 /* note: connections_mutex and c_mutex should be locked by caller */
781 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
782 if( !LDAP_STAILQ_EMPTY(&c->c_ops) ) {
784 LDAP_LOG( CONNECTION, DETAIL1,
785 "connection_close: conn %lu deferring sd %d\n",
786 c->c_connid, sd, 0 );
788 Debug( LDAP_DEBUG_TRACE,
789 "connection_close: deferring conn=%lu sd=%d\n",
790 c->c_connid, sd, 0 );
796 LDAP_LOG( CONNECTION, RESULTS,
797 "connection_close: conn %lu sd %d\n", c->c_connid, sd, 0 );
799 Debug( LDAP_DEBUG_TRACE, "connection_close: conn=%lu sd=%d\n",
800 c->c_connid, sd, 0 );
802 connection_destroy( c );
805 unsigned long connections_nextid(void)
808 assert( connections != NULL );
810 ldap_pvt_thread_mutex_lock( &connections_mutex );
814 ldap_pvt_thread_mutex_unlock( &connections_mutex );
819 Connection* connection_first( ber_socket_t *index )
821 assert( connections != NULL );
822 assert( index != NULL );
824 ldap_pvt_thread_mutex_lock( &connections_mutex );
828 return connection_next(NULL, index);
831 Connection* connection_next( Connection *c, ber_socket_t *index )
833 assert( connections != NULL );
834 assert( index != NULL );
835 assert( *index <= dtblsize );
838 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
843 for(; *index < dtblsize; (*index)++) {
844 if( connections[*index].c_struct_state == SLAP_C_UNINITIALIZED ) {
845 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
853 if( connections[*index].c_struct_state == SLAP_C_USED ) {
854 assert( connections[*index].c_conn_state != SLAP_C_INVALID );
855 c = &connections[(*index)++];
859 assert( connections[*index].c_struct_state == SLAP_C_UNUSED );
860 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
864 ldap_pvt_thread_mutex_lock( &c->c_mutex );
870 void connection_done( Connection *c )
872 assert( connections != NULL );
875 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
878 ldap_pvt_thread_mutex_unlock( &connections_mutex );
882 * connection_activity - handle the request operation op on connection
883 * conn. This routine figures out what kind of operation it is and
884 * calls the appropriate stub to handle it.
888 #define INCR_OP(var,index) \
890 ldap_pvt_thread_mutex_lock( &num_ops_mutex ); \
892 ldap_pvt_thread_mutex_unlock( &num_ops_mutex ); \
894 #else /* !SLAPD_MONITOR */
895 #define INCR_OP(var,index)
896 #endif /* !SLAPD_MONITOR */
899 connection_operation( void *ctx, void *arg_v )
901 int rc = SLAPD_DISCONNECT;
902 Operation *op = arg_v;
903 SlapReply rs = {REP_RESULT};
904 ber_tag_t tag = op->o_tag;
906 ber_tag_t oldtag = tag;
907 #endif /* SLAPD_MONITOR */
908 Connection *conn = op->o_conn;
912 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
914 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
916 op->o_threadctx = ctx;
918 if( conn->c_sasl_bind_in_progress && tag != LDAP_REQ_BIND ) {
920 LDAP_LOG( CONNECTION, ERR,
921 "connection_operation: conn %lu SASL bind in progress (tag=%ld).\n",
922 conn->c_connid, (long)tag, 0 );
924 Debug( LDAP_DEBUG_ANY, "connection_operation: "
925 "error: SASL bind in progress (tag=%ld).\n",
928 send_ldap_error( op, &rs, LDAP_OPERATIONS_ERROR,
929 "SASL bind in progress" );
930 goto operations_error;
933 /* We can use Thread-Local storage for most mallocs. We can
934 * also use TL for ber parsing, but not on Add or Modify.
936 #define SLAB_SIZE 1048576
938 memsiz = ber_len( op->o_ber ) * 64;
939 if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE;
943 memctx = sl_mem_create( memsiz, ctx );
944 op->o_tmpmemctx = memctx;
945 op->o_tmpmfuncs = &sl_mfuncs;
946 if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) {
947 /* Note - the ber and its buffer are already allocated from
948 * regular memory; this only affects subsequent mallocs that
949 * ber_scanf may invoke.
951 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx );
956 INCR_OP(num_ops_initiated_, SLAP_OP_BIND);
957 rc = do_bind( op, &rs );
960 case LDAP_REQ_UNBIND:
961 INCR_OP(num_ops_initiated_, SLAP_OP_UNBIND);
962 rc = do_unbind( op, &rs );
966 INCR_OP(num_ops_initiated_, SLAP_OP_ADD);
967 rc = do_add( op, &rs );
970 case LDAP_REQ_DELETE:
971 INCR_OP(num_ops_initiated_, SLAP_OP_DELETE);
972 rc = do_delete( op, &rs );
975 case LDAP_REQ_MODRDN:
976 INCR_OP(num_ops_initiated_, SLAP_OP_MODRDN);
977 rc = do_modrdn( op, &rs );
980 case LDAP_REQ_MODIFY:
981 INCR_OP(num_ops_initiated_, SLAP_OP_MODIFY);
982 rc = do_modify( op, &rs );
985 case LDAP_REQ_COMPARE:
986 INCR_OP(num_ops_initiated_, SLAP_OP_COMPARE);
987 rc = do_compare( op, &rs );
990 case LDAP_REQ_SEARCH:
991 INCR_OP(num_ops_initiated_, SLAP_OP_SEARCH);
992 rc = do_search( op, &rs );
995 case LDAP_REQ_ABANDON:
996 INCR_OP(num_ops_initiated_, SLAP_OP_ABANDON);
997 rc = do_abandon( op, &rs );
1000 case LDAP_REQ_EXTENDED:
1001 INCR_OP(num_ops_initiated_, SLAP_OP_EXTENDED);
1002 rc = do_extended( op, &rs );
1007 LDAP_LOG( CONNECTION, INFO,
1008 "connection_operation: conn %lu unknown LDAP request 0x%lx\n",
1009 conn->c_connid, tag, 0 );
1011 Debug( LDAP_DEBUG_ANY, "unknown LDAP request 0x%lx\n",
1014 op->o_tag = LBER_ERROR;
1015 rs.sr_err = LDAP_PROTOCOL_ERROR;
1016 rs.sr_text = "unknown LDAP request";
1017 send_ldap_disconnect( op, &rs );
1022 #ifdef SLAPD_MONITOR
1024 #endif /* SLAPD_MONITOR */
1025 if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR;
1028 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
1029 num_ops_completed++;
1030 #ifdef SLAPD_MONITOR
1033 num_ops_completed_[SLAP_OP_BIND]++;
1035 case LDAP_REQ_UNBIND:
1036 num_ops_completed_[SLAP_OP_UNBIND]++;
1039 num_ops_completed_[SLAP_OP_ADD]++;
1041 case LDAP_REQ_DELETE:
1042 num_ops_completed_[SLAP_OP_DELETE]++;
1044 case LDAP_REQ_MODRDN:
1045 num_ops_completed_[SLAP_OP_MODRDN]++;
1047 case LDAP_REQ_MODIFY:
1048 num_ops_completed_[SLAP_OP_MODIFY]++;
1050 case LDAP_REQ_COMPARE:
1051 num_ops_completed_[SLAP_OP_COMPARE]++;
1053 case LDAP_REQ_SEARCH:
1054 num_ops_completed_[SLAP_OP_SEARCH]++;
1056 case LDAP_REQ_ABANDON:
1057 num_ops_completed_[SLAP_OP_ABANDON]++;
1059 case LDAP_REQ_EXTENDED:
1060 num_ops_completed_[SLAP_OP_EXTENDED]++;
1063 #endif /* SLAPD_MONITOR */
1064 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
1066 #ifdef LDAP_EXOP_X_CANCEL
1067 if ( op->o_cancel == SLAP_CANCEL_REQ ) {
1068 op->o_cancel = LDAP_TOO_LATE;
1071 while ( op->o_cancel != SLAP_CANCEL_NONE &&
1072 op->o_cancel != SLAP_CANCEL_DONE )
1074 ldap_pvt_thread_yield();
1078 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1080 if ( op->o_cancel != SLAP_CANCEL_ACK && ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) {
1081 sl_mem_detach( ctx, memctx );
1085 LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
1086 LDAP_STAILQ_NEXT(op, o_next) = NULL;
1088 conn->c_n_ops_executing--;
1089 conn->c_n_ops_completed++;
1091 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx );
1098 case LDAP_REQ_UNBIND:
1099 /* c_mutex is locked */
1100 connection_closing( conn );
1104 conn->c_sasl_bind_in_progress =
1105 rc == LDAP_SASL_BIND_IN_PROGRESS ? 1 : 0;
1107 if( conn->c_conn_state == SLAP_C_BINDING) {
1108 conn->c_conn_state = SLAP_C_ACTIVE;
1112 connection_resched( conn );
1114 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1119 int connection_read(ber_socket_t s)
1124 assert( connections != NULL );
1126 ldap_pvt_thread_mutex_lock( &connections_mutex );
1128 /* get (locked) connection */
1129 c = connection_get( s );
1133 LDAP_LOG( CONNECTION, INFO,
1134 "connection_read: sock %ld no connection\n", (long)s, 0, 0 );
1136 Debug( LDAP_DEBUG_ANY,
1137 "connection_read(%ld): no connection!\n",
1142 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1148 if( c->c_conn_state == SLAP_C_CLOSING ) {
1150 LDAP_LOG( CONNECTION, INFO,
1151 "connection_read: conn %lu connection closing, ignoring input\n",
1152 c->c_connid, 0, 0 );
1154 Debug( LDAP_DEBUG_TRACE,
1155 "connection_read(%d): closing, ignoring input for id=%lu\n",
1156 s, c->c_connid, 0 );
1158 connection_return( c );
1159 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1164 LDAP_LOG( CONNECTION, DETAIL1,
1165 "connection_read: conn %lu checking for input.\n",
1166 c->c_connid, 0, 0 );
1168 Debug( LDAP_DEBUG_TRACE,
1169 "connection_read(%d): checking for input on id=%lu\n",
1170 s, c->c_connid, 0 );
1174 if ( c->c_is_tls && c->c_needs_tls_accept ) {
1175 rc = ldap_pvt_tls_accept( c->c_sb, NULL );
1177 #if 0 /* required by next #if 0 */
1183 LDAP_LOG( CONNECTION, ERR,
1184 "connection_read: conn %lu TLS accept error, error %d\n",
1185 c->c_connid, rc, 0 );
1187 Debug( LDAP_DEBUG_TRACE,
1188 "connection_read(%d): TLS accept error "
1189 "error=%d id=%lu, closing\n",
1190 s, rc, c->c_connid );
1192 c->c_needs_tls_accept = 0;
1193 /* connections_mutex and c_mutex are locked */
1194 connection_closing( c );
1197 /* Drain input before close, to allow SSL error codes
1198 * to propagate to client. */
1204 rc = select(s+1, &rfd, NULL, NULL, &tv);
1206 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DRAIN, NULL);
1210 connection_close( c );
1212 } else if ( rc == 0 ) {
1214 struct berval authid = { 0, NULL };
1216 c->c_needs_tls_accept = 0;
1218 /* we need to let SASL know */
1219 ssl = ldap_pvt_tls_sb_ctx( c->c_sb );
1221 c->c_tls_ssf = (slap_ssf_t) ldap_pvt_tls_get_strength( ssl );
1222 if( c->c_tls_ssf > c->c_ssf ) {
1223 c->c_ssf = c->c_tls_ssf;
1226 rc = dnX509peerNormalize( ssl, &authid );
1227 if ( rc != LDAP_SUCCESS ) {
1229 LDAP_LOG( CONNECTION, INFO,
1230 "connection_read: conn %lu unable to get TLS client DN, "
1231 "error %d\n", c->c_connid, rc, 0 );
1233 Debug( LDAP_DEBUG_TRACE,
1234 "connection_read(%d): unable to get TLS client DN "
1235 "error=%d id=%lu\n",
1236 s, rc, c->c_connid );
1239 slap_sasl_external( c, c->c_tls_ssf, authid.bv_val );
1240 if ( authid.bv_val ) free( authid.bv_val );
1243 /* if success and data is ready, fall thru to data input loop */
1245 !ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) )
1247 connection_return( c );
1248 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1254 #ifdef HAVE_CYRUS_SASL
1255 if ( c->c_sasl_layers ) {
1256 /* If previous layer is not removed yet, give up for now */
1257 if ( !c->c_sasl_sockctx ) {
1258 connection_return( c );
1259 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1263 c->c_sasl_layers = 0;
1265 rc = ldap_pvt_sasl_install( c->c_sb, c->c_sasl_sockctx );
1267 if( rc != LDAP_SUCCESS ) {
1269 LDAP_LOG( CONNECTION, ERR,
1270 "connection_read: conn %lu SASL install error %d, closing\n",
1271 c->c_connid, rc, 0 );
1273 Debug( LDAP_DEBUG_TRACE,
1274 "connection_read(%d): SASL install error "
1275 "error=%d id=%lu, closing\n",
1276 s, rc, c->c_connid );
1278 /* connections_mutex and c_mutex are locked */
1279 connection_closing( c );
1280 connection_close( c );
1281 connection_return( c );
1282 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1288 #define CONNECTION_INPUT_LOOP 1
1289 /* #define DATA_READY_LOOP 1 */
1293 /* How do we do this without getting into a busy loop ? */
1294 rc = connection_input( c );
1296 #ifdef DATA_READY_LOOP
1297 while( !rc && ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) );
1298 #elif CONNECTION_INPUT_LOOP
1306 LDAP_LOG( CONNECTION, ERR,
1307 "connection_read: conn %lu input error %d, closing.\n",
1308 c->c_connid, rc, 0 );
1310 Debug( LDAP_DEBUG_TRACE,
1311 "connection_read(%d): input error=%d id=%lu, closing.\n",
1312 s, rc, c->c_connid );
1314 /* connections_mutex and c_mutex are locked */
1315 connection_closing( c );
1316 connection_close( c );
1317 connection_return( c );
1318 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1322 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) ) {
1323 slapd_set_read( s, 1 );
1326 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
1327 slapd_set_write( s, 1 );
1330 connection_return( c );
1331 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1346 #ifdef LDAP_CONNECTIONLESS
1351 if ( conn->c_currentber == NULL &&
1352 ( conn->c_currentber = ber_alloc()) == NULL )
1355 LDAP_LOG( CONNECTION, ERR,
1356 "connection_input: conn %lu ber_alloc failed.\n",
1357 conn->c_connid, 0, 0 );
1359 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
1366 #ifdef LDAP_CONNECTIONLESS
1367 if ( conn->c_is_udp ) {
1368 char peername[sizeof("IP=255.255.255.255:65336")];
1369 len = ber_int_sb_read(conn->c_sb, &peeraddr,
1370 sizeof(struct sockaddr));
1371 if (len != sizeof(struct sockaddr))
1373 sprintf( peername, "IP=%s:%d",
1374 inet_ntoa( peeraddr.sa_in_addr.sin_addr ),
1375 (unsigned) ntohs( peeraddr.sa_in_addr.sin_port ) );
1376 Statslog( LDAP_DEBUG_STATS,
1377 "conn=%lu UDP request from %s (%s) accepted.\n",
1378 conn->c_connid, peername, conn->c_sock_name.bv_val, 0, 0 );
1381 tag = ber_get_next( conn->c_sb, &len, conn->c_currentber );
1382 if ( tag != LDAP_TAG_MESSAGE ) {
1386 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
1389 LDAP_LOG( CONNECTION, ERR,
1390 "connection_input: conn %lu ber_get_next failed, errno %d (%s).\n",
1391 conn->c_connid, err, sock_errstr(err) );
1393 Debug( LDAP_DEBUG_TRACE,
1394 "ber_get_next on fd %d failed errno=%d (%s)\n",
1395 sd, err, sock_errstr(err) );
1397 if ( err != EWOULDBLOCK && err != EAGAIN ) {
1398 /* log, close and send error */
1399 ber_free( conn->c_currentber, 1 );
1400 conn->c_currentber = NULL;
1407 ber = conn->c_currentber;
1408 conn->c_currentber = NULL;
1410 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
1411 /* log, close and send error */
1413 LDAP_LOG( CONNECTION, ERR,
1414 "connection_input: conn %lu ber_get_int returns 0x%lx.\n",
1415 conn->c_connid, tag, 0 );
1417 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
1424 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
1425 /* log, close and send error */
1427 LDAP_LOG( CONNECTION, ERR,
1428 "connection_input: conn %lu ber_peek_tag returns 0x%lx.\n",
1429 conn->c_connid, tag, 0 );
1431 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
1439 #ifdef LDAP_CONNECTIONLESS
1440 if( conn->c_is_udp ) {
1441 if( tag == LBER_OCTETSTRING ) {
1442 ber_get_stringa( ber, &cdn );
1443 tag = ber_peek_tag(ber, &len);
1445 if( tag != LDAP_REQ_ABANDON && tag != LDAP_REQ_SEARCH ) {
1447 LDAP_LOG( CONNECTION, ERR,
1448 "connection_input: conn %lu invalid req for UDP 0x%lx.\n",
1449 conn->c_connid, tag, 0 );
1451 Debug( LDAP_DEBUG_ANY, "invalid req for UDP 0x%lx\n", tag, 0,
1459 if(tag == LDAP_REQ_BIND) {
1460 /* immediately abandon all exiting operations upon BIND */
1461 connection_abandon( conn );
1464 op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++ );
1467 op->o_assertion = NULL;
1468 op->o_preread_attrs = NULL;
1469 op->o_postread_attrs = NULL;
1470 op->o_vrFilter = NULL;
1472 #ifdef LDAP_CONTROL_PAGEDRESULTS
1473 op->o_pagedresults_state = conn->c_pagedresults_state;
1476 op->o_res_ber = NULL;
1478 #ifdef LDAP_CONNECTIONLESS
1479 if (conn->c_is_udp) {
1481 ber_str2bv( cdn, 0, 1, &op->o_dn );
1482 op->o_protocol = LDAP_VERSION2;
1484 op->o_res_ber = ber_alloc_t( LBER_USE_DER );
1485 if (op->o_res_ber == NULL) return 1;
1487 rc = ber_write( op->o_res_ber, (char *)&peeraddr,
1488 sizeof(struct sockaddr), 0 );
1490 if (rc != sizeof(struct sockaddr)) {
1492 LDAP_LOG( CONNECTION, INFO,
1493 "connection_input: conn %lu ber_write failed\n",
1494 conn->c_connid, 0, 0 );
1496 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
1501 if (op->o_protocol == LDAP_VERSION2) {
1502 rc = ber_printf(op->o_res_ber, "{is{" /*}}*/, op->o_msgid, "");
1505 LDAP_LOG( CONNECTION, INFO,
1506 "connection_input: conn %lu put outer sequence failed\n",
1507 conn->c_connid, 0, 0 );
1509 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
1515 #endif /* LDAP_CONNECTIONLESS */
1519 /* Don't process requests when the conn is in the middle of a
1520 * Bind, or if it's closing. Also, don't let any single conn
1521 * use up all the available threads, and don't execute if we're
1522 * currently blocked on output. And don't execute if there are
1523 * already pending ops, let them go first.
1525 * But always allow Abandon through; it won't cost much.
1527 if ( tag != LDAP_REQ_ABANDON && (conn->c_conn_state == SLAP_C_BINDING
1528 || conn->c_conn_state == SLAP_C_CLOSING
1529 || conn->c_n_ops_executing >= connection_pool_max/2
1530 || conn->c_n_ops_pending
1531 || conn->c_writewaiter))
1533 int max = conn->c_dn.bv_len ? slap_conn_max_pending_auth
1534 : slap_conn_max_pending;
1536 LDAP_LOG( CONNECTION, INFO,
1537 "connection_input: conn %lu deferring operation\n",
1538 conn->c_connid, 0, 0 );
1540 Debug( LDAP_DEBUG_ANY, "deferring operation\n", 0, 0, 0 );
1542 conn->c_n_ops_pending++;
1543 LDAP_STAILQ_INSERT_TAIL( &conn->c_pending_ops, op, o_next );
1544 if ( conn->c_n_ops_pending > max ) {
1550 conn->c_n_ops_executing++;
1551 connection_op_activate( op );
1555 if ( conn->c_struct_state != SLAP_C_USED ) {
1556 /* connection must have got closed underneath us */
1560 assert( conn->c_struct_state == SLAP_C_USED );
1566 connection_resched( Connection *conn )
1570 if( conn->c_conn_state == SLAP_C_CLOSING ) {
1573 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
1575 /* us trylock to avoid possible deadlock */
1576 rc = ldap_pvt_thread_mutex_trylock( &connections_mutex );
1580 LDAP_LOG( CONNECTION, DETAIL1,
1581 "connection_resched: conn %lu reaquiring locks.\n",
1582 conn->c_connid, 0, 0 );
1584 Debug( LDAP_DEBUG_TRACE,
1585 "connection_resched: reaquiring locks conn=%lu sd=%d\n",
1586 conn->c_connid, sd, 0 );
1589 * reaquire locks in the right order...
1590 * this may allow another thread to close this connection,
1591 * so recheck state below.
1593 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1594 ldap_pvt_thread_mutex_lock( &connections_mutex );
1595 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1598 if( conn->c_conn_state != SLAP_C_CLOSING ) {
1600 LDAP_LOG( CONNECTION, INFO,
1601 "connection_resched: conn %lu closed by other thread.\n",
1602 conn->c_connid, 0, 0 );
1604 Debug( LDAP_DEBUG_TRACE, "connection_resched: "
1605 "closed by other thread conn=%lu sd=%d\n",
1606 conn->c_connid, sd, 0 );
1610 LDAP_LOG( CONNECTION, DETAIL1,
1611 "connection_resched: conn %lu attempting closing.\n",
1612 conn->c_connid, 0, 0 );
1614 Debug( LDAP_DEBUG_TRACE, "connection_resched: "
1615 "attempting closing conn=%lu sd=%d\n",
1616 conn->c_connid, sd, 0 );
1618 connection_close( conn );
1621 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1625 if( conn->c_conn_state != SLAP_C_ACTIVE || conn->c_writewaiter ) {
1626 /* other states need different handling */
1630 while ((op = LDAP_STAILQ_FIRST( &conn->c_pending_ops )) != NULL) {
1631 if ( conn->c_n_ops_executing > connection_pool_max/2 ) {
1634 LDAP_STAILQ_REMOVE_HEAD( &conn->c_pending_ops, o_next );
1635 LDAP_STAILQ_NEXT(op, o_next) = NULL;
1636 /* pending operations should not be marked for abandonment */
1637 assert(!op->o_abandon);
1639 conn->c_n_ops_pending--;
1640 conn->c_n_ops_executing++;
1642 connection_op_activate( op );
1644 if ( conn->c_conn_state == SLAP_C_BINDING ) {
1651 static int connection_op_activate( Operation *op )
1654 ber_tag_t tag = op->o_tag;
1656 if(tag == LDAP_REQ_BIND) {
1657 op->o_conn->c_conn_state = SLAP_C_BINDING;
1660 if (!op->o_dn.bv_len) {
1661 op->o_authz = op->o_conn->c_authz;
1662 ber_dupbv( &op->o_dn, &op->o_conn->c_dn );
1663 ber_dupbv( &op->o_ndn, &op->o_conn->c_ndn );
1665 op->o_authtype = op->o_conn->c_authtype;
1666 ber_dupbv( &op->o_authmech, &op->o_conn->c_authmech );
1668 if (!op->o_protocol) {
1669 op->o_protocol = op->o_conn->c_protocol
1670 ? op->o_conn->c_protocol : LDAP_VERSION3;
1672 if (op->o_conn->c_conn_state == SLAP_C_INACTIVE
1673 && op->o_protocol > LDAP_VERSION2) {
1674 op->o_conn->c_conn_state = SLAP_C_ACTIVE;
1677 op->o_connid = op->o_conn->c_connid;
1679 LDAP_STAILQ_INSERT_TAIL( &op->o_conn->c_ops, op, o_next );
1681 status = ldap_pvt_thread_pool_submit( &connection_pool,
1682 connection_operation, (void *) op );
1684 if ( status != 0 ) {
1686 LDAP_LOG( CONNECTION, ERR,
1687 "connection_op_activate: conn %lu thread pool submit failed.\n",
1688 op->o_connid, 0, 0 );
1690 Debug( LDAP_DEBUG_ANY,
1691 "ldap_pvt_thread_pool_submit failed (%d)\n", status, 0, 0 );
1693 /* should move op to pending list */
1699 int connection_write(ber_socket_t s)
1703 assert( connections != NULL );
1705 ldap_pvt_thread_mutex_lock( &connections_mutex );
1707 c = connection_get( s );
1709 slapd_clr_write( s, 0);
1713 LDAP_LOG( CONNECTION, ERR,
1714 "connection_write: sock %ld no connection!\n", (long)s, 0, 0);
1716 Debug( LDAP_DEBUG_ANY,
1717 "connection_write(%ld): no connection!\n",
1721 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1728 LDAP_LOG( CONNECTION, DETAIL1,
1729 "connection_write conn %lu waking output.\n", c->c_connid, 0, 0 );
1731 Debug( LDAP_DEBUG_TRACE,
1732 "connection_write(%d): waking output for id=%lu\n",
1733 s, c->c_connid, 0 );
1735 ldap_pvt_thread_cond_signal( &c->c_write_cv );
1737 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) )
1738 slapd_set_read( s, 1 );
1739 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) )
1740 slapd_set_write( s, 1 );
1741 connection_return( c );
1742 ldap_pvt_thread_mutex_unlock( &connections_mutex );