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;
435 c->c_listener = NULL;
436 c->c_peer_domain.bv_val = NULL;
437 c->c_peer_domain.bv_len = 0;
438 c->c_peer_name.bv_val = NULL;
439 c->c_peer_name.bv_len = 0;
441 LDAP_STAILQ_INIT(&c->c_ops);
442 LDAP_STAILQ_INIT(&c->c_pending_ops);
444 c->c_sasl_bind_mech.bv_val = NULL;
445 c->c_sasl_bind_mech.bv_len = 0;
447 c->c_sasl_authctx = NULL;
448 c->c_sasl_sockctx = NULL;
449 c->c_sasl_extra = NULL;
450 c->c_sasl_bindop = NULL;
452 c->c_sb = ber_sockbuf_alloc( );
455 ber_len_t max = sockbuf_max_incoming;
456 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
459 c->c_currentber = NULL;
461 /* should check status of thread calls */
462 ldap_pvt_thread_mutex_init( &c->c_mutex );
463 ldap_pvt_thread_mutex_init( &c->c_write_mutex );
464 ldap_pvt_thread_cond_init( &c->c_write_cv );
467 slapi_x_create_object_extensions( SLAPI_X_EXT_CONNECTION, c );
470 c->c_struct_state = SLAP_C_UNUSED;
473 ldap_pvt_thread_mutex_lock( &c->c_mutex );
475 assert( c->c_struct_state == SLAP_C_UNUSED );
476 assert( c->c_authmech.bv_val == NULL );
477 assert( c->c_dn.bv_val == NULL );
478 assert( c->c_ndn.bv_val == NULL );
479 assert( c->c_groups == NULL );
480 assert( c->c_listener == NULL );
481 assert( c->c_peer_domain.bv_val == NULL );
482 assert( c->c_peer_name.bv_val == NULL );
483 assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
484 assert( LDAP_STAILQ_EMPTY(&c->c_pending_ops) );
485 assert( c->c_sasl_bind_mech.bv_val == NULL );
486 assert( c->c_sasl_done == 0 );
487 assert( c->c_sasl_authctx == NULL );
488 assert( c->c_sasl_sockctx == NULL );
489 assert( c->c_sasl_extra == NULL );
490 assert( c->c_sasl_bindop == NULL );
491 assert( c->c_currentber == NULL );
493 c->c_listener = listener;
494 ber_str2bv( dnsname, 0, 1, &c->c_peer_domain );
495 ber_str2bv( peername, 0, 1, &c->c_peer_name );
497 c->c_n_ops_received = 0;
498 c->c_n_ops_executing = 0;
499 c->c_n_ops_pending = 0;
500 c->c_n_ops_completed = 0;
506 /* set to zero until bind, implies LDAP_VERSION3 */
510 c->c_activitytime = c->c_starttime = slap_get_time();
512 if( global_idletimeout > 0 ) {
513 c->c_activitytime = c->c_starttime = slap_get_time();
517 #ifdef LDAP_CONNECTIONLESS
519 if( tls_udp_option == 2 ) {
522 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
523 LBER_SBIOD_LEVEL_PROVIDER, (void*)"udp_" );
525 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_udp,
526 LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
527 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_readahead,
528 LBER_SBIOD_LEVEL_PROVIDER, NULL );
533 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
534 LBER_SBIOD_LEVEL_PROVIDER, (void*)"tcp_" );
536 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_tcp,
537 LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
541 ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_debug,
542 INT_MAX, (void*)"ldap_" );
545 if( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_NONBLOCK,
546 c /* non-NULL */ ) < 0 )
549 LDAP_LOG( CONNECTION, INFO,
550 "connection_init: conn %lu set nonblocking failed\n",
553 Debug( LDAP_DEBUG_ANY,
554 "connection_init(%d, %s): set nonblocking failed\n",
555 s, c->c_peer_name.bv_val, 0 );
559 id = c->c_connid = conn_nextid++;
561 c->c_conn_state = SLAP_C_INACTIVE;
562 c->c_struct_state = SLAP_C_USED;
564 c->c_ssf = c->c_transport_ssf = ssf;
568 if ( tls_udp_option == 1 ) {
570 c->c_needs_tls_accept = 1;
573 c->c_needs_tls_accept = 0;
577 slap_sasl_open( c, 0 );
578 slap_sasl_external( c, ssf, authid );
580 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
581 ldap_pvt_thread_mutex_unlock( &connections_mutex );
583 backend_connection_init(c);
588 void connection2anonymous( Connection *c )
590 assert( connections != NULL );
594 ber_len_t max = sockbuf_max_incoming;
595 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
598 if(c->c_authmech.bv_val != NULL ) {
599 free(c->c_authmech.bv_val);
600 c->c_authmech.bv_val = NULL;
602 c->c_authmech.bv_len = 0;
604 if(c->c_dn.bv_val != NULL) {
605 free(c->c_dn.bv_val);
606 c->c_dn.bv_val = NULL;
609 if(c->c_ndn.bv_val != NULL) {
610 free(c->c_ndn.bv_val);
611 c->c_ndn.bv_val = NULL;
615 c->c_authz_backend = NULL;
618 GroupAssertion *g, *n;
619 for (g = c->c_groups; g; g=n) {
628 connection_destroy( Connection *c )
630 /* note: connections_mutex should be locked by caller */
632 unsigned long connid;
634 assert( connections != NULL );
636 assert( c->c_struct_state != SLAP_C_UNUSED );
637 assert( c->c_conn_state != SLAP_C_INVALID );
638 assert( LDAP_STAILQ_EMPTY(&c->c_ops) );
640 /* only for stats (print -1 as "%lu" may give unexpected results ;) */
641 connid = c->c_connid;
643 backend_connection_destroy(c);
648 c->c_activitytime = c->c_starttime = 0;
650 connection2anonymous( c );
651 c->c_listener = NULL;
653 if(c->c_peer_domain.bv_val != NULL) {
654 free(c->c_peer_domain.bv_val);
655 c->c_peer_domain.bv_val = NULL;
657 c->c_peer_domain.bv_len = 0;
658 if(c->c_peer_name.bv_val != NULL) {
659 free(c->c_peer_name.bv_val);
660 c->c_peer_name.bv_val = NULL;
662 c->c_peer_name.bv_len = 0;
664 c->c_sasl_bind_in_progress = 0;
665 if(c->c_sasl_bind_mech.bv_val != NULL) {
666 free(c->c_sasl_bind_mech.bv_val);
667 c->c_sasl_bind_mech.bv_val = NULL;
669 c->c_sasl_bind_mech.bv_len = 0;
671 slap_sasl_close( c );
673 if ( c->c_currentber != NULL ) {
674 ber_free( c->c_currentber, 1 );
675 c->c_currentber = NULL;
678 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
679 if ( sd != AC_SOCKET_INVALID ) {
680 slapd_remove( sd, 0 );
682 Statslog( LDAP_DEBUG_STATS,
683 "conn=%lu fd=%ld closed\n",
684 connid, (long) sd, 0, 0, 0 );
687 ber_sockbuf_free( c->c_sb );
689 c->c_sb = ber_sockbuf_alloc( );
692 ber_len_t max = sockbuf_max_incoming;
693 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
696 c->c_conn_state = SLAP_C_INVALID;
697 c->c_struct_state = SLAP_C_UNUSED;
700 /* call destructors, then constructors; avoids unnecessary allocation */
701 slapi_x_clear_object_extensions( SLAPI_X_EXT_CONNECTION, c );
705 int connection_state_closing( Connection *c )
707 /* c_mutex must be locked by caller */
711 assert( c->c_struct_state == SLAP_C_USED );
713 state = c->c_conn_state;
715 assert( state != SLAP_C_INVALID );
717 return state == SLAP_C_CLOSING;
720 static void connection_abandon( Connection *c )
722 /* c_mutex must be locked by caller */
726 LDAP_STAILQ_FOREACH(o, &c->c_ops, o_next) {
730 /* remove pending operations */
731 while ( (o = LDAP_STAILQ_FIRST( &c->c_pending_ops )) != NULL) {
732 LDAP_STAILQ_REMOVE_HEAD( &c->c_pending_ops, o_next );
733 LDAP_STAILQ_NEXT(o, o_next) = NULL;
738 void connection_closing( Connection *c )
740 assert( connections != NULL );
742 assert( c->c_struct_state == SLAP_C_USED );
743 assert( c->c_conn_state != SLAP_C_INVALID );
745 /* c_mutex must be locked by caller */
747 if( c->c_conn_state != SLAP_C_CLOSING ) {
750 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
752 LDAP_LOG( CONNECTION, DETAIL1,
753 "connection_closing: conn %lu readying socket %d for close.\n",
754 c->c_connid, sd, 0 );
756 Debug( LDAP_DEBUG_TRACE,
757 "connection_closing: readying conn=%lu sd=%d for close\n",
758 c->c_connid, sd, 0 );
760 /* update state to closing */
761 c->c_conn_state = SLAP_C_CLOSING;
763 /* don't listen on this port anymore */
764 slapd_clr_read( sd, 1 );
766 /* abandon active operations */
767 connection_abandon( c );
769 /* wake write blocked operations */
770 slapd_clr_write( sd, 1 );
771 ldap_pvt_thread_cond_signal( &c->c_write_cv );
775 static void connection_close( Connection *c )
779 assert( connections != NULL );
781 assert( c->c_struct_state == SLAP_C_USED );
782 assert( c->c_conn_state == SLAP_C_CLOSING );
784 /* note: connections_mutex and c_mutex should be locked by caller */
786 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd );
787 if( !LDAP_STAILQ_EMPTY(&c->c_ops) ) {
789 LDAP_LOG( CONNECTION, DETAIL1,
790 "connection_close: conn %lu deferring sd %d\n",
791 c->c_connid, sd, 0 );
793 Debug( LDAP_DEBUG_TRACE,
794 "connection_close: deferring conn=%lu sd=%d\n",
795 c->c_connid, sd, 0 );
801 LDAP_LOG( CONNECTION, RESULTS,
802 "connection_close: conn %lu sd %d\n", c->c_connid, sd, 0 );
804 Debug( LDAP_DEBUG_TRACE, "connection_close: conn=%lu sd=%d\n",
805 c->c_connid, sd, 0 );
807 connection_destroy( c );
810 unsigned long connections_nextid(void)
813 assert( connections != NULL );
815 ldap_pvt_thread_mutex_lock( &connections_mutex );
819 ldap_pvt_thread_mutex_unlock( &connections_mutex );
824 Connection* connection_first( ber_socket_t *index )
826 assert( connections != NULL );
827 assert( index != NULL );
829 ldap_pvt_thread_mutex_lock( &connections_mutex );
833 return connection_next(NULL, index);
836 Connection* connection_next( Connection *c, ber_socket_t *index )
838 assert( connections != NULL );
839 assert( index != NULL );
840 assert( *index <= dtblsize );
843 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
848 for(; *index < dtblsize; (*index)++) {
849 if( connections[*index].c_struct_state == SLAP_C_UNINITIALIZED ) {
850 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
858 if( connections[*index].c_struct_state == SLAP_C_USED ) {
859 assert( connections[*index].c_conn_state != SLAP_C_INVALID );
860 c = &connections[(*index)++];
864 assert( connections[*index].c_struct_state == SLAP_C_UNUSED );
865 assert( connections[*index].c_conn_state == SLAP_C_INVALID );
869 ldap_pvt_thread_mutex_lock( &c->c_mutex );
875 void connection_done( Connection *c )
877 assert( connections != NULL );
880 ldap_pvt_thread_mutex_unlock( &c->c_mutex );
883 ldap_pvt_thread_mutex_unlock( &connections_mutex );
887 * connection_activity - handle the request operation op on connection
888 * conn. This routine figures out what kind of operation it is and
889 * calls the appropriate stub to handle it.
893 #define INCR_OP(var,index) \
895 ldap_pvt_thread_mutex_lock( &num_ops_mutex ); \
897 ldap_pvt_thread_mutex_unlock( &num_ops_mutex ); \
899 #else /* !SLAPD_MONITOR */
900 #define INCR_OP(var,index)
901 #endif /* !SLAPD_MONITOR */
904 connection_operation( void *ctx, void *arg_v )
906 int rc = SLAPD_DISCONNECT;
907 Operation *op = arg_v;
908 SlapReply rs = {REP_RESULT};
909 ber_tag_t tag = op->o_tag;
911 ber_tag_t oldtag = tag;
912 #endif /* SLAPD_MONITOR */
913 Connection *conn = op->o_conn;
917 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
919 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
921 op->o_threadctx = ctx;
923 if( conn->c_sasl_bind_in_progress && tag != LDAP_REQ_BIND ) {
925 LDAP_LOG( CONNECTION, ERR,
926 "connection_operation: conn %lu SASL bind in progress (tag=%ld).\n",
927 conn->c_connid, (long)tag, 0 );
929 Debug( LDAP_DEBUG_ANY, "connection_operation: "
930 "error: SASL bind in progress (tag=%ld).\n",
933 send_ldap_error( op, &rs, LDAP_OPERATIONS_ERROR,
934 "SASL bind in progress" );
935 goto operations_error;
938 /* We can use Thread-Local storage for most mallocs. We can
939 * also use TL for ber parsing, but not on Add or Modify.
941 #define SLAB_SIZE 1048576
943 memsiz = ber_len( op->o_ber ) * 64;
944 if ( SLAB_SIZE > memsiz ) memsiz = SLAB_SIZE;
948 memctx = sl_mem_create( memsiz, ctx );
949 op->o_tmpmemctx = memctx;
950 op->o_tmpmfuncs = &sl_mfuncs;
951 if ( tag != LDAP_REQ_ADD && tag != LDAP_REQ_MODIFY ) {
952 /* Note - the ber and its buffer are already allocated from
953 * regular memory; this only affects subsequent mallocs that
954 * ber_scanf may invoke.
956 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx );
961 INCR_OP(num_ops_initiated_, SLAP_OP_BIND);
962 rc = do_bind( op, &rs );
965 case LDAP_REQ_UNBIND:
966 INCR_OP(num_ops_initiated_, SLAP_OP_UNBIND);
967 rc = do_unbind( op, &rs );
971 INCR_OP(num_ops_initiated_, SLAP_OP_ADD);
972 rc = do_add( op, &rs );
975 case LDAP_REQ_DELETE:
976 INCR_OP(num_ops_initiated_, SLAP_OP_DELETE);
977 rc = do_delete( op, &rs );
980 case LDAP_REQ_MODRDN:
981 INCR_OP(num_ops_initiated_, SLAP_OP_MODRDN);
982 rc = do_modrdn( op, &rs );
985 case LDAP_REQ_MODIFY:
986 INCR_OP(num_ops_initiated_, SLAP_OP_MODIFY);
987 rc = do_modify( op, &rs );
990 case LDAP_REQ_COMPARE:
991 INCR_OP(num_ops_initiated_, SLAP_OP_COMPARE);
992 rc = do_compare( op, &rs );
995 case LDAP_REQ_SEARCH:
996 INCR_OP(num_ops_initiated_, SLAP_OP_SEARCH);
997 rc = do_search( op, &rs );
1000 case LDAP_REQ_ABANDON:
1001 INCR_OP(num_ops_initiated_, SLAP_OP_ABANDON);
1002 rc = do_abandon( op, &rs );
1005 case LDAP_REQ_EXTENDED:
1006 INCR_OP(num_ops_initiated_, SLAP_OP_EXTENDED);
1007 rc = do_extended( op, &rs );
1012 LDAP_LOG( CONNECTION, INFO,
1013 "connection_operation: conn %lu unknown LDAP request 0x%lx\n",
1014 conn->c_connid, tag, 0 );
1016 Debug( LDAP_DEBUG_ANY, "unknown LDAP request 0x%lx\n",
1019 op->o_tag = LBER_ERROR;
1020 rs.sr_err = LDAP_PROTOCOL_ERROR;
1021 rs.sr_text = "unknown LDAP request";
1022 send_ldap_disconnect( op, &rs );
1027 #ifdef SLAPD_MONITOR
1029 #endif /* SLAPD_MONITOR */
1030 if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR;
1033 ldap_pvt_thread_mutex_lock( &num_ops_mutex );
1034 num_ops_completed++;
1035 #ifdef SLAPD_MONITOR
1038 num_ops_completed_[SLAP_OP_BIND]++;
1040 case LDAP_REQ_UNBIND:
1041 num_ops_completed_[SLAP_OP_UNBIND]++;
1044 num_ops_completed_[SLAP_OP_ADD]++;
1046 case LDAP_REQ_DELETE:
1047 num_ops_completed_[SLAP_OP_DELETE]++;
1049 case LDAP_REQ_MODRDN:
1050 num_ops_completed_[SLAP_OP_MODRDN]++;
1052 case LDAP_REQ_MODIFY:
1053 num_ops_completed_[SLAP_OP_MODIFY]++;
1055 case LDAP_REQ_COMPARE:
1056 num_ops_completed_[SLAP_OP_COMPARE]++;
1058 case LDAP_REQ_SEARCH:
1059 num_ops_completed_[SLAP_OP_SEARCH]++;
1061 case LDAP_REQ_ABANDON:
1062 num_ops_completed_[SLAP_OP_ABANDON]++;
1064 case LDAP_REQ_EXTENDED:
1065 num_ops_completed_[SLAP_OP_EXTENDED]++;
1068 #endif /* SLAPD_MONITOR */
1069 ldap_pvt_thread_mutex_unlock( &num_ops_mutex );
1071 #ifdef LDAP_EXOP_X_CANCEL
1072 if ( op->o_cancel == SLAP_CANCEL_REQ ) {
1073 op->o_cancel = LDAP_TOO_LATE;
1076 while ( op->o_cancel != SLAP_CANCEL_NONE &&
1077 op->o_cancel != SLAP_CANCEL_DONE )
1079 ldap_pvt_thread_yield();
1083 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1085 LDAP_STAILQ_REMOVE( &conn->c_ops, op, slap_op, o_next);
1086 LDAP_STAILQ_NEXT(op, o_next) = NULL;
1088 if ( op->o_cancel == SLAP_CANCEL_ACK )
1090 if ( ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) {
1091 sl_mem_detach( ctx, memctx );
1097 conn->c_n_ops_executing--;
1098 conn->c_n_ops_completed++;
1100 ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx );
1107 case LDAP_REQ_UNBIND:
1108 /* c_mutex is locked */
1109 connection_closing( conn );
1113 conn->c_sasl_bind_in_progress =
1114 rc == LDAP_SASL_BIND_IN_PROGRESS ? 1 : 0;
1116 if( conn->c_conn_state == SLAP_C_BINDING) {
1117 conn->c_conn_state = SLAP_C_ACTIVE;
1121 connection_resched( conn );
1123 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1128 int connection_read(ber_socket_t s)
1133 assert( connections != NULL );
1135 ldap_pvt_thread_mutex_lock( &connections_mutex );
1137 /* get (locked) connection */
1138 c = connection_get( s );
1142 LDAP_LOG( CONNECTION, INFO,
1143 "connection_read: sock %ld no connection\n", (long)s, 0, 0 );
1145 Debug( LDAP_DEBUG_ANY,
1146 "connection_read(%ld): no connection!\n",
1151 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1157 if( c->c_conn_state == SLAP_C_CLOSING ) {
1159 LDAP_LOG( CONNECTION, INFO,
1160 "connection_read: conn %lu connection closing, ignoring input\n",
1161 c->c_connid, 0, 0 );
1163 Debug( LDAP_DEBUG_TRACE,
1164 "connection_read(%d): closing, ignoring input for id=%lu\n",
1165 s, c->c_connid, 0 );
1167 connection_return( c );
1168 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1173 LDAP_LOG( CONNECTION, DETAIL1,
1174 "connection_read: conn %lu checking for input.\n",
1175 c->c_connid, 0, 0 );
1177 Debug( LDAP_DEBUG_TRACE,
1178 "connection_read(%d): checking for input on id=%lu\n",
1179 s, c->c_connid, 0 );
1183 if ( c->c_is_tls && c->c_needs_tls_accept ) {
1184 rc = ldap_pvt_tls_accept( c->c_sb, NULL );
1186 #if 0 /* required by next #if 0 */
1192 LDAP_LOG( CONNECTION, ERR,
1193 "connection_read: conn %lu TLS accept error, error %d\n",
1194 c->c_connid, rc, 0 );
1196 Debug( LDAP_DEBUG_TRACE,
1197 "connection_read(%d): TLS accept error "
1198 "error=%d id=%lu, closing\n",
1199 s, rc, c->c_connid );
1201 c->c_needs_tls_accept = 0;
1202 /* connections_mutex and c_mutex are locked */
1203 connection_closing( c );
1206 /* Drain input before close, to allow SSL error codes
1207 * to propagate to client. */
1213 rc = select(s+1, &rfd, NULL, NULL, &tv);
1215 ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DRAIN, NULL);
1219 connection_close( c );
1221 } else if ( rc == 0 ) {
1223 struct berval authid = { 0, NULL };
1225 c->c_needs_tls_accept = 0;
1227 /* we need to let SASL know */
1228 ssl = ldap_pvt_tls_sb_ctx( c->c_sb );
1230 c->c_tls_ssf = (slap_ssf_t) ldap_pvt_tls_get_strength( ssl );
1231 if( c->c_tls_ssf > c->c_ssf ) {
1232 c->c_ssf = c->c_tls_ssf;
1235 rc = dnX509peerNormalize( ssl, &authid );
1236 if ( rc != LDAP_SUCCESS ) {
1238 LDAP_LOG( CONNECTION, INFO,
1239 "connection_read: conn %lu unable to get TLS client DN, "
1240 "error %d\n", c->c_connid, rc, 0 );
1242 Debug( LDAP_DEBUG_TRACE,
1243 "connection_read(%d): unable to get TLS client DN "
1244 "error=%d id=%lu\n",
1245 s, rc, c->c_connid );
1248 slap_sasl_external( c, c->c_tls_ssf, authid.bv_val );
1249 if ( authid.bv_val ) free( authid.bv_val );
1252 /* if success and data is ready, fall thru to data input loop */
1254 !ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) )
1256 connection_return( c );
1257 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1263 #ifdef HAVE_CYRUS_SASL
1264 if ( c->c_sasl_layers ) {
1265 /* If previous layer is not removed yet, give up for now */
1266 if ( !c->c_sasl_sockctx ) {
1267 connection_return( c );
1268 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1272 c->c_sasl_layers = 0;
1274 rc = ldap_pvt_sasl_install( c->c_sb, c->c_sasl_sockctx );
1276 if( rc != LDAP_SUCCESS ) {
1278 LDAP_LOG( CONNECTION, ERR,
1279 "connection_read: conn %lu SASL install error %d, closing\n",
1280 c->c_connid, rc, 0 );
1282 Debug( LDAP_DEBUG_TRACE,
1283 "connection_read(%d): SASL install error "
1284 "error=%d id=%lu, closing\n",
1285 s, rc, c->c_connid );
1287 /* connections_mutex and c_mutex are locked */
1288 connection_closing( c );
1289 connection_close( c );
1290 connection_return( c );
1291 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1297 #define CONNECTION_INPUT_LOOP 1
1298 /* #define DATA_READY_LOOP 1 */
1302 /* How do we do this without getting into a busy loop ? */
1303 rc = connection_input( c );
1305 #ifdef DATA_READY_LOOP
1306 while( !rc && ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) );
1307 #elif CONNECTION_INPUT_LOOP
1315 LDAP_LOG( CONNECTION, ERR,
1316 "connection_read: conn %lu input error %d, closing.\n",
1317 c->c_connid, rc, 0 );
1319 Debug( LDAP_DEBUG_TRACE,
1320 "connection_read(%d): input error=%d id=%lu, closing.\n",
1321 s, rc, c->c_connid );
1323 /* connections_mutex and c_mutex are locked */
1324 connection_closing( c );
1325 connection_close( c );
1326 connection_return( c );
1327 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1331 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) ) {
1332 slapd_set_read( s, 1 );
1335 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) ) {
1336 slapd_set_write( s, 1 );
1339 connection_return( c );
1340 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1355 #ifdef LDAP_CONNECTIONLESS
1360 if ( conn->c_currentber == NULL &&
1361 ( conn->c_currentber = ber_alloc()) == NULL )
1364 LDAP_LOG( CONNECTION, ERR,
1365 "connection_input: conn %lu ber_alloc failed.\n",
1366 conn->c_connid, 0, 0 );
1368 Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
1375 #ifdef LDAP_CONNECTIONLESS
1376 if ( conn->c_is_udp ) {
1377 char peername[sizeof("IP=255.255.255.255:65336")];
1378 len = ber_int_sb_read(conn->c_sb, &peeraddr,
1379 sizeof(struct sockaddr));
1380 if (len != sizeof(struct sockaddr))
1382 sprintf( peername, "IP=%s:%d",
1383 inet_ntoa( peeraddr.sa_in_addr.sin_addr ),
1384 (unsigned) ntohs( peeraddr.sa_in_addr.sin_port ) );
1385 Statslog( LDAP_DEBUG_STATS,
1386 "conn=%lu UDP request from %s (%s) accepted.\n",
1387 conn->c_connid, peername, conn->c_sock_name.bv_val, 0, 0 );
1390 tag = ber_get_next( conn->c_sb, &len, conn->c_currentber );
1391 if ( tag != LDAP_TAG_MESSAGE ) {
1395 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
1398 LDAP_LOG( CONNECTION, ERR,
1399 "connection_input: conn %lu ber_get_next failed, errno %d (%s).\n",
1400 conn->c_connid, err, sock_errstr(err) );
1402 Debug( LDAP_DEBUG_TRACE,
1403 "ber_get_next on fd %d failed errno=%d (%s)\n",
1404 sd, err, sock_errstr(err) );
1406 if ( err != EWOULDBLOCK && err != EAGAIN ) {
1407 /* log, close and send error */
1408 ber_free( conn->c_currentber, 1 );
1409 conn->c_currentber = NULL;
1416 ber = conn->c_currentber;
1417 conn->c_currentber = NULL;
1419 if ( (tag = ber_get_int( ber, &msgid )) != LDAP_TAG_MSGID ) {
1420 /* log, close and send error */
1422 LDAP_LOG( CONNECTION, ERR,
1423 "connection_input: conn %lu ber_get_int returns 0x%lx.\n",
1424 conn->c_connid, tag, 0 );
1426 Debug( LDAP_DEBUG_ANY, "ber_get_int returns 0x%lx\n", tag, 0,
1433 if ( (tag = ber_peek_tag( ber, &len )) == LBER_ERROR ) {
1434 /* log, close and send error */
1436 LDAP_LOG( CONNECTION, ERR,
1437 "connection_input: conn %lu ber_peek_tag returns 0x%lx.\n",
1438 conn->c_connid, tag, 0 );
1440 Debug( LDAP_DEBUG_ANY, "ber_peek_tag returns 0x%lx\n", tag, 0,
1448 #ifdef LDAP_CONNECTIONLESS
1449 if( conn->c_is_udp ) {
1450 if( tag == LBER_OCTETSTRING ) {
1451 ber_get_stringa( ber, &cdn );
1452 tag = ber_peek_tag(ber, &len);
1454 if( tag != LDAP_REQ_ABANDON && tag != LDAP_REQ_SEARCH ) {
1456 LDAP_LOG( CONNECTION, ERR,
1457 "connection_input: conn %lu invalid req for UDP 0x%lx.\n",
1458 conn->c_connid, tag, 0 );
1460 Debug( LDAP_DEBUG_ANY, "invalid req for UDP 0x%lx\n", tag, 0,
1468 if(tag == LDAP_REQ_BIND) {
1469 /* immediately abandon all exiting operations upon BIND */
1470 connection_abandon( conn );
1473 op = slap_op_alloc( ber, msgid, tag, conn->c_n_ops_received++ );
1476 op->o_assertion = NULL;
1477 op->o_preread_attrs = NULL;
1478 op->o_postread_attrs = NULL;
1479 op->o_vrFilter = NULL;
1481 #ifdef LDAP_CONTROL_PAGEDRESULTS
1482 op->o_pagedresults_state = conn->c_pagedresults_state;
1485 op->o_res_ber = NULL;
1487 #ifdef LDAP_CONNECTIONLESS
1488 if (conn->c_is_udp) {
1490 ber_str2bv( cdn, 0, 1, &op->o_dn );
1491 op->o_protocol = LDAP_VERSION2;
1493 op->o_res_ber = ber_alloc_t( LBER_USE_DER );
1494 if (op->o_res_ber == NULL) return 1;
1496 rc = ber_write( op->o_res_ber, (char *)&peeraddr,
1497 sizeof(struct sockaddr), 0 );
1499 if (rc != sizeof(struct sockaddr)) {
1501 LDAP_LOG( CONNECTION, INFO,
1502 "connection_input: conn %lu ber_write failed\n",
1503 conn->c_connid, 0, 0 );
1505 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
1510 if (op->o_protocol == LDAP_VERSION2) {
1511 rc = ber_printf(op->o_res_ber, "{is{" /*}}*/, op->o_msgid, "");
1514 LDAP_LOG( CONNECTION, INFO,
1515 "connection_input: conn %lu put outer sequence failed\n",
1516 conn->c_connid, 0, 0 );
1518 Debug( LDAP_DEBUG_ANY, "ber_write failed\n", 0, 0, 0 );
1524 #endif /* LDAP_CONNECTIONLESS */
1528 /* Don't process requests when the conn is in the middle of a
1529 * Bind, or if it's closing. Also, don't let any single conn
1530 * use up all the available threads, and don't execute if we're
1531 * currently blocked on output. And don't execute if there are
1532 * already pending ops, let them go first.
1534 * But always allow Abandon through; it won't cost much.
1536 if ( tag != LDAP_REQ_ABANDON && (conn->c_conn_state == SLAP_C_BINDING
1537 || conn->c_conn_state == SLAP_C_CLOSING
1538 || conn->c_n_ops_executing >= connection_pool_max/2
1539 || conn->c_n_ops_pending
1540 || conn->c_writewaiter))
1542 int max = conn->c_dn.bv_len ? slap_conn_max_pending_auth
1543 : slap_conn_max_pending;
1545 LDAP_LOG( CONNECTION, INFO,
1546 "connection_input: conn %lu deferring operation\n",
1547 conn->c_connid, 0, 0 );
1549 Debug( LDAP_DEBUG_ANY, "deferring operation\n", 0, 0, 0 );
1551 conn->c_n_ops_pending++;
1552 LDAP_STAILQ_INSERT_TAIL( &conn->c_pending_ops, op, o_next );
1553 if ( conn->c_n_ops_pending > max ) {
1559 conn->c_n_ops_executing++;
1560 connection_op_activate( op );
1564 if ( conn->c_struct_state != SLAP_C_USED ) {
1565 /* connection must have got closed underneath us */
1569 assert( conn->c_struct_state == SLAP_C_USED );
1575 connection_resched( Connection *conn )
1579 if( conn->c_conn_state == SLAP_C_CLOSING ) {
1582 ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
1584 /* us trylock to avoid possible deadlock */
1585 rc = ldap_pvt_thread_mutex_trylock( &connections_mutex );
1589 LDAP_LOG( CONNECTION, DETAIL1,
1590 "connection_resched: conn %lu reaquiring locks.\n",
1591 conn->c_connid, 0, 0 );
1593 Debug( LDAP_DEBUG_TRACE,
1594 "connection_resched: reaquiring locks conn=%lu sd=%d\n",
1595 conn->c_connid, sd, 0 );
1598 * reaquire locks in the right order...
1599 * this may allow another thread to close this connection,
1600 * so recheck state below.
1602 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
1603 ldap_pvt_thread_mutex_lock( &connections_mutex );
1604 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
1607 if( conn->c_conn_state != SLAP_C_CLOSING ) {
1609 LDAP_LOG( CONNECTION, INFO,
1610 "connection_resched: conn %lu closed by other thread.\n",
1611 conn->c_connid, 0, 0 );
1613 Debug( LDAP_DEBUG_TRACE, "connection_resched: "
1614 "closed by other thread conn=%lu sd=%d\n",
1615 conn->c_connid, sd, 0 );
1619 LDAP_LOG( CONNECTION, DETAIL1,
1620 "connection_resched: conn %lu attempting closing.\n",
1621 conn->c_connid, 0, 0 );
1623 Debug( LDAP_DEBUG_TRACE, "connection_resched: "
1624 "attempting closing conn=%lu sd=%d\n",
1625 conn->c_connid, sd, 0 );
1627 connection_close( conn );
1630 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1634 if( conn->c_conn_state != SLAP_C_ACTIVE || conn->c_writewaiter ) {
1635 /* other states need different handling */
1639 while ((op = LDAP_STAILQ_FIRST( &conn->c_pending_ops )) != NULL) {
1640 if ( conn->c_n_ops_executing > connection_pool_max/2 ) {
1643 LDAP_STAILQ_REMOVE_HEAD( &conn->c_pending_ops, o_next );
1644 LDAP_STAILQ_NEXT(op, o_next) = NULL;
1645 /* pending operations should not be marked for abandonment */
1646 assert(!op->o_abandon);
1648 conn->c_n_ops_pending--;
1649 conn->c_n_ops_executing++;
1651 connection_op_activate( op );
1653 if ( conn->c_conn_state == SLAP_C_BINDING ) {
1660 static int connection_op_activate( Operation *op )
1663 ber_tag_t tag = op->o_tag;
1665 if(tag == LDAP_REQ_BIND) {
1666 op->o_conn->c_conn_state = SLAP_C_BINDING;
1669 if (!op->o_dn.bv_len) {
1670 op->o_authz = op->o_conn->c_authz;
1671 ber_dupbv( &op->o_dn, &op->o_conn->c_dn );
1672 ber_dupbv( &op->o_ndn, &op->o_conn->c_ndn );
1674 op->o_authtype = op->o_conn->c_authtype;
1675 ber_dupbv( &op->o_authmech, &op->o_conn->c_authmech );
1677 if (!op->o_protocol) {
1678 op->o_protocol = op->o_conn->c_protocol
1679 ? op->o_conn->c_protocol : LDAP_VERSION3;
1681 if (op->o_conn->c_conn_state == SLAP_C_INACTIVE
1682 && op->o_protocol > LDAP_VERSION2) {
1683 op->o_conn->c_conn_state = SLAP_C_ACTIVE;
1686 op->o_connid = op->o_conn->c_connid;
1688 LDAP_STAILQ_INSERT_TAIL( &op->o_conn->c_ops, op, o_next );
1690 status = ldap_pvt_thread_pool_submit( &connection_pool,
1691 connection_operation, (void *) op );
1693 if ( status != 0 ) {
1695 LDAP_LOG( CONNECTION, ERR,
1696 "connection_op_activate: conn %lu thread pool submit failed.\n",
1697 op->o_connid, 0, 0 );
1699 Debug( LDAP_DEBUG_ANY,
1700 "ldap_pvt_thread_pool_submit failed (%d)\n", status, 0, 0 );
1702 /* should move op to pending list */
1708 int connection_write(ber_socket_t s)
1712 assert( connections != NULL );
1714 ldap_pvt_thread_mutex_lock( &connections_mutex );
1716 c = connection_get( s );
1718 slapd_clr_write( s, 0);
1722 LDAP_LOG( CONNECTION, ERR,
1723 "connection_write: sock %ld no connection!\n", (long)s, 0, 0);
1725 Debug( LDAP_DEBUG_ANY,
1726 "connection_write(%ld): no connection!\n",
1730 ldap_pvt_thread_mutex_unlock( &connections_mutex );
1737 LDAP_LOG( CONNECTION, DETAIL1,
1738 "connection_write conn %lu waking output.\n", c->c_connid, 0, 0 );
1740 Debug( LDAP_DEBUG_TRACE,
1741 "connection_write(%d): waking output for id=%lu\n",
1742 s, c->c_connid, 0 );
1744 ldap_pvt_thread_cond_signal( &c->c_write_cv );
1746 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_READ, NULL ) )
1747 slapd_set_read( s, 1 );
1748 if ( ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_NEEDS_WRITE, NULL ) )
1749 slapd_set_write( s, 1 );
1750 connection_return( c );
1751 ldap_pvt_thread_mutex_unlock( &connections_mutex );