3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/socket.h>
14 #include <ac/string.h>
16 #include <ac/unistd.h>
19 #include "ldap_pvt_thread.h"
26 int allow_severity = LOG_INFO;
27 int deny_severity = LOG_NOTICE;
28 #endif /* TCP Wrappers */
32 /* this should go in <ldap.h> as soon as it is accepted */
33 #define LDAPI_MOD_URLEXT "x-mod"
34 #endif /* LDAP_PF_LOCAL */
38 ber_socket_t dtblsize;
40 Listener **slap_listeners = NULL;
42 #define SLAPD_LISTEN 10
44 static ber_socket_t wake_sds[2];
48 #define WAKE_LISTENER(w) \
49 ((w && !waking) ? tcp_write( wake_sds[1], "0", 1 ), waking=1 : 0)
51 #define WAKE_LISTENER(w) \
52 do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0)
58 volatile sig_atomic_t slapd_shutdown = 0, slapd_gentle_shutdown = 0;
60 static struct slap_daemon {
61 ldap_pvt_thread_mutex_t sd_mutex;
63 ber_socket_t sd_nactives;
66 /* In winsock, accept() returns values higher than dtblsize
67 so don't bother with this optimization */
80 * SLP related functions
84 #define LDAP_SRVTYPE_PREFIX "service:ldap://"
85 #define LDAPS_SRVTYPE_PREFIX "service:ldaps://"
86 static char** slapd_srvurls = NULL;
87 static SLPHandle slapd_hslp = 0;
89 void slapd_slp_init( const char* urls ) {
92 slapd_srvurls = str2charray( urls, " " );
94 if( slapd_srvurls == NULL ) return;
96 /* find and expand INADDR_ANY URLs */
97 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
98 if( strcmp( slapd_srvurls[i], "ldap:///" ) == 0) {
99 char *host = ldap_pvt_get_fqdn( NULL );
100 if ( host != NULL ) {
101 slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
103 sizeof( LDAP_SRVTYPE_PREFIX ) );
104 strcpy( slap_strcopy(slapd_srvurls[i],
105 LDAP_SRVTYPE_PREFIX ), host );
110 } else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0) {
111 char *host = ldap_pvt_get_fqdn( NULL );
112 if ( host != NULL ) {
113 slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
115 sizeof( LDAPS_SRVTYPE_PREFIX ) );
116 strcpy( slap_strcopy(slapd_srvurls[i],
117 LDAPS_SRVTYPE_PREFIX ), host );
124 /* open the SLP handle */
125 SLPOpen( "en", 0, &slapd_hslp );
128 void slapd_slp_deinit() {
129 if( slapd_srvurls == NULL ) return;
131 charray_free( slapd_srvurls );
132 slapd_srvurls = NULL;
134 /* close the SLP handle */
135 SLPClose( slapd_hslp );
138 void slapd_slp_regreport(
146 void slapd_slp_reg() {
149 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
150 if( strncmp( slapd_srvurls[i], LDAP_SRVTYPE_PREFIX,
151 sizeof( LDAP_SRVTYPE_PREFIX ) - 1 ) == 0 ||
152 strncmp( slapd_srvurls[i], LDAPS_SRVTYPE_PREFIX,
153 sizeof( LDAPS_SRVTYPE_PREFIX ) - 1 ) == 0 )
157 SLP_LIFETIME_MAXIMUM,
167 void slapd_slp_dereg() {
170 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
171 SLPDereg( slapd_hslp,
177 #endif /* HAVE_SLP */
180 * Add a descriptor to daemon control
182 static void slapd_add(ber_socket_t s) {
183 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
185 assert( !FD_ISSET( s, &slap_daemon.sd_actives ));
186 assert( !FD_ISSET( s, &slap_daemon.sd_readers ));
187 assert( !FD_ISSET( s, &slap_daemon.sd_writers ));
190 if (s >= slap_daemon.sd_nfds) {
191 slap_daemon.sd_nfds = s + 1;
195 slap_daemon.sd_nactives++;
197 FD_SET( s, &slap_daemon.sd_actives );
198 FD_SET( s, &slap_daemon.sd_readers );
201 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
202 "slapd_add: added %ld%s%s\n",
204 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
205 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" ));
207 Debug( LDAP_DEBUG_CONNS, "daemon: added %ld%s%s\n",
209 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
210 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
212 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
216 * Remove the descriptor from daemon control
218 void slapd_remove(ber_socket_t s, int wake) {
219 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
221 slap_daemon.sd_nactives--;
224 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
225 "slapd_remove: removing %ld%s%s\n",
227 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
228 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" ));
230 Debug( LDAP_DEBUG_CONNS, "daemon: removing %ld%s%s\n",
232 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
233 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
235 FD_CLR( s, &slap_daemon.sd_actives );
236 FD_CLR( s, &slap_daemon.sd_readers );
237 FD_CLR( s, &slap_daemon.sd_writers );
239 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
240 WAKE_LISTENER(wake || slapd_gentle_shutdown < 0);
243 void slapd_clr_write(ber_socket_t s, int wake) {
244 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
246 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
247 FD_CLR( s, &slap_daemon.sd_writers );
249 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
253 void slapd_set_write(ber_socket_t s, int wake) {
254 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
256 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
257 if (!FD_ISSET(s, &slap_daemon.sd_writers))
258 FD_SET( (unsigned) s, &slap_daemon.sd_writers );
260 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
264 void slapd_clr_read(ber_socket_t s, int wake) {
265 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
267 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
268 FD_CLR( s, &slap_daemon.sd_readers );
270 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
274 void slapd_set_read(ber_socket_t s, int wake) {
275 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
277 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
278 if (!FD_ISSET(s, &slap_daemon.sd_readers))
279 FD_SET( s, &slap_daemon.sd_readers );
281 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
285 static void slapd_close(ber_socket_t s) {
287 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
288 "slapd_close: closing %ld\n", (long)s ));
290 Debug( LDAP_DEBUG_CONNS, "daemon: closing %ld\n",
296 static void slap_free_listener_addresses(struct sockaddr **sal)
298 struct sockaddr **sap;
304 for (sap = sal; *sap != NULL; sap++) {
312 static int get_url_perms(
324 for ( i = 0; exts[ i ]; i++ ) {
325 char *type = exts[ i ];
328 if ( type[ 0 ] == '!' ) {
333 if ( strncasecmp( type, LDAPI_MOD_URLEXT "=", sizeof(LDAPI_MOD_URLEXT "=") - 1 ) == 0 ) {
334 char *value = type + sizeof(LDAPI_MOD_URLEXT "=") - 1;
338 if ( strlen(value) != 3 ) {
342 for ( j = 0; j < 3; j++ ) {
344 = { S_IRWXU, S_IRWXG, S_IRWXO };
346 switch ( value[ j ] ) {
366 #endif /* LDAP_PF_LOCAL */
368 /* port = 0 indicates AF_LOCAL */
369 static int slap_get_listener_addresses(
372 struct sockaddr ***sal)
374 struct sockaddr **sap;
378 *sal = ch_malloc(2 * sizeof(void *));
384 *sap = ch_malloc(sizeof(struct sockaddr_un));
390 (sizeof(((struct sockaddr_un *)*sap)->sun_path) - 1) ) {
392 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
393 "slap_get_listener_addresses: domain socket path (%s) too long in URL\n",
396 Debug( LDAP_DEBUG_ANY,
397 "daemon: domain socket path (%s) too long in URL",
403 (void)memset( (void *)*sap, '\0', sizeof(struct sockaddr_un) );
404 (*sap)->sa_family = AF_LOCAL;
405 strcpy( ((struct sockaddr_un *)*sap)->sun_path, host );
409 #ifdef HAVE_GETADDRINFO
410 struct addrinfo hints, *res, *sai;
414 memset( &hints, '\0', sizeof(hints) );
415 hints.ai_flags = AI_PASSIVE;
416 hints.ai_socktype = SOCK_STREAM;
417 hints.ai_family = AF_UNSPEC;
418 snprintf(serv, sizeof serv, "%d", port);
420 if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
422 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
423 "slap_get_listener_addresses: getaddrinfo failed: %s\n",
424 AC_GAI_STRERROR(err) ));
426 Debug( LDAP_DEBUG_ANY, "daemon: getaddrinfo failed: %s\n",
427 AC_GAI_STRERROR(err), 0, 0);
433 for (n=2; (sai = sai->ai_next) != NULL; n++) {
436 *sal = ch_calloc(n, sizeof(void *));
444 for ( sai=res; sai; sai=sai->ai_next ) {
445 if( sai->ai_addr == NULL ) {
447 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
448 "slap_get_listener_addresses: "
449 "getaddrinfo ai_addr is NULL?\n" ));
451 Debug( LDAP_DEBUG_ANY, "slap_get_listener_addresses: "
452 "getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
458 switch (sai->ai_family) {
459 # ifdef LDAP_PF_INET6
461 *sap = ch_malloc(sizeof(struct sockaddr_in6));
466 *(struct sockaddr_in6 *)*sap =
467 *((struct sockaddr_in6 *)sai->ai_addr);
471 *sap = ch_malloc(sizeof(struct sockaddr_in));
476 *(struct sockaddr_in *)*sap =
477 *((struct sockaddr_in *)sai->ai_addr);
485 (*sap)->sa_family = sai->ai_family;
495 struct hostent *he = NULL;
497 if ( host == NULL ) {
498 in.s_addr = htonl(INADDR_ANY);
500 } else if ( !inet_aton( host, &in ) ) {
501 he = gethostbyname( host );
504 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
505 "slap_get_listener_addresses: invalid host %s\n",
508 Debug( LDAP_DEBUG_ANY,
509 "daemon: invalid host %s", host, 0, 0);
513 for (n = 0; he->h_addr_list[n]; n++) ;
516 *sal = ch_malloc((n+1) * sizeof(void *));
522 for ( i = 0; i<n; i++ ) {
523 sap[i] = ch_malloc(sizeof(struct sockaddr_in));
527 (void)memset( (void *)sap[i], '\0', sizeof(struct sockaddr_in) );
528 sap[i]->sa_family = AF_INET;
529 ((struct sockaddr_in *)sap[i])->sin_port = htons(port);
531 AC_MEMCPY( &((struct sockaddr_in *)sap[i])->sin_addr, he->h_addr_list[i], sizeof(struct in_addr) );
533 AC_MEMCPY( &((struct sockaddr_in *)sap[i])->sin_addr, &in, sizeof(struct in_addr) );
543 slap_free_listener_addresses(*sal);
547 static int slap_open_listener(
558 int err, addrlen = 0;
559 struct sockaddr **sal, **psal;
560 int socktype = SOCK_STREAM; /* default to COTS */
562 mode_t perms = S_IRWXU;
566 rc = ldap_url_parse( url, &lud );
568 if( rc != LDAP_URL_SUCCESS ) {
570 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
571 "slap_open_listener: listen URL \"%s\" parse error %d\n",
574 Debug( LDAP_DEBUG_ANY,
575 "daemon: listen URL \"%s\" parse error=%d\n",
582 if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
584 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
585 "slap_open_listener: TLS is not supported (%s)\n",
588 Debug( LDAP_DEBUG_ANY,
589 "daemon: TLS not supported (%s)\n",
592 ldap_free_urldesc( lud );
596 if(! lud->lud_port ) {
597 lud->lud_port = LDAP_PORT;
601 l.sl_is_tls = ldap_pvt_url_scheme2tls( lud->lud_scheme );
603 if(! lud->lud_port ) {
604 lud->lud_port = l.sl_is_tls ? LDAPS_PORT : LDAP_PORT;
608 port = (unsigned short) lud->lud_port;
610 tmp = ldap_pvt_url_scheme2proto(lud->lud_scheme);
611 if ( tmp == LDAP_PROTO_IPC ) {
613 if ( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) {
614 err = slap_get_listener_addresses(LDAPI_SOCK, 0, &sal);
616 err = slap_get_listener_addresses(lud->lud_host, 0, &sal);
619 if ( lud->lud_exts ) {
620 err = get_url_perms( lud->lud_exts, &perms, &crit );
625 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
626 "slap_open_listener: URL scheme is not supported: %s\n",
629 Debug( LDAP_DEBUG_ANY, "daemon: URL scheme not supported: %s",
632 ldap_free_urldesc( lud );
636 #ifdef LDAP_CONNECTIONLESS
637 l.sl_is_udp = ( tmp == LDAP_PROTO_UDP );
639 if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
640 || strcmp(lud->lud_host, "*") == 0 )
642 err = slap_get_listener_addresses(NULL, port, &sal);
644 err = slap_get_listener_addresses(lud->lud_host, port, &sal);
648 ldap_free_urldesc( lud );
653 /* If we got more than one address returned, we need to make space
654 * for it in the slap_listeners array.
656 for ( num=0; sal[num]; num++ );
659 slap_listeners = ch_realloc( slap_listeners, (*listeners + 1) * sizeof(Listener *) );
663 while ( *sal != NULL ) {
664 switch( (*sal)->sa_family ) {
677 #ifdef LDAP_CONNECTIONLESS
679 socktype = SOCK_DGRAM;
681 l.sl_sd = socket( (*sal)->sa_family, socktype, 0);
682 if ( l.sl_sd == AC_SOCKET_INVALID ) {
683 int err = sock_errno();
685 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
686 "slap_open_listener: socket() failed errno=%d (%s)\n",
687 err, sock_errstr(err) ));
689 Debug( LDAP_DEBUG_ANY,
690 "daemon: socket() failed errno=%d (%s)\n", err,
691 sock_errstr(err), 0 );
697 if ( l.sl_sd >= dtblsize ) {
699 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
700 "slap_open_listener: listener descriptor %ld is too great %ld\n",
701 (long)l.sl_sd, (long)dtblsize ));
703 Debug( LDAP_DEBUG_ANY,
704 "daemon: listener descriptor %ld is too great %ld\n",
705 (long) l.sl_sd, (long) dtblsize, 0 );
707 tcp_close( l.sl_sd );
713 if ( (*sal)->sa_family == AF_LOCAL ) {
714 unlink ( ((struct sockaddr_un *)*sal)->sun_path );
719 /* enable address reuse */
721 rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
722 (char *) &tmp, sizeof(tmp) );
723 if ( rc == AC_SOCKET_ERROR ) {
724 int err = sock_errno();
726 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
727 "slap_open_listener: setsockopt( %ld, SO_REUSEADDR ) failed errno %d (%s)\n",
728 (long)l.sl_sd, err, sock_errstr(err) ));
730 Debug( LDAP_DEBUG_ANY,
731 "slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
732 (long) l.sl_sd, err, sock_errstr(err) );
738 switch( (*sal)->sa_family ) {
740 addrlen = sizeof(struct sockaddr_in);
744 addrlen = sizeof(struct sockaddr_in6);
749 addrlen = sizeof(struct sockaddr_un);
754 if (bind(l.sl_sd, *sal, addrlen)) {
757 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
758 "slap_open_listener: bind(%ld) failed errno=%d (%s)\n",
759 (long)l.sl_sd, err, sock_errstr(err) ));
761 Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
762 (long) l.sl_sd, err, sock_errstr(err) );
764 tcp_close( l.sl_sd );
769 switch ( (*sal)->sa_family ) {
772 char *addr = ((struct sockaddr_un *)*sal)->sun_path;
773 if ( chmod( addr, perms ) < 0 && crit ) {
774 int err = sock_errno();
776 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
777 "slap_open_listener: fchmod(%ld) failed errno=%d (%s)\n",
778 (long)l.sl_sd, err, sock_errstr(err) ));
780 Debug( LDAP_DEBUG_ANY, "daemon: fchmod(%ld) failed errno=%d (%s)",
781 (long) l.sl_sd, err, sock_errstr(err) );
783 tcp_close( l.sl_sd );
784 slap_free_listener_addresses(psal);
787 l.sl_name = ch_malloc( strlen(addr) + sizeof("PATH=") );
788 sprintf( l.sl_name, "PATH=%s", addr );
790 #endif /* LDAP_PF_LOCAL */
794 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
795 char addr[INET_ADDRSTRLEN];
796 inet_ntop( AF_INET, &((struct sockaddr_in *)*sal)->sin_addr,
797 addr, sizeof(addr) );
800 s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
802 port = ntohs( ((struct sockaddr_in *)*sal) ->sin_port );
803 l.sl_name = ch_malloc( sizeof("IP=255.255.255.255:65535") );
804 sprintf( l.sl_name, "IP=%s:%d",
805 s != NULL ? s : "unknown" , port );
810 char addr[INET6_ADDRSTRLEN];
811 inet_ntop( AF_INET6, &((struct sockaddr_in6 *)*sal)->sin6_addr,
813 port = ntohs( ((struct sockaddr_in6 *)*sal)->sin6_port );
814 l.sl_name = ch_malloc( strlen(addr) + sizeof("IP= 65535") );
815 sprintf( l.sl_name, "IP=%s %d", addr, port );
817 #endif /* LDAP_PF_INET6 */
821 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
822 "slap_open_listener: unsupported address family (%d)\n",
823 (int)(*sal)->sa_family ));
825 Debug( LDAP_DEBUG_ANY, "daemon: unsupported address family (%d)\n",
826 (int) (*sal)->sa_family, 0, 0 );
831 AC_MEMCPY(&l.sl_sa, *sal, addrlen);
832 l.sl_url = ch_strdup( url );
833 li = ch_malloc( sizeof( Listener ) );
835 slap_listeners[*cur] = li;
839 } /* while ( *sal != NULL ) */
841 slap_free_listener_addresses(psal);
845 LDAP_LOG(( "connection", LDAP_LEVEL_RESULTS,
846 "slap_open_listener: daemon initialized %s\n", l.sl_url ));
848 Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
854 static int sockinit(void);
855 static int sockdestroy(void);
857 int slapd_daemon_init( const char *urls )
863 LDAP_LOG(( "connection", LDAP_LEVEL_ARGS,
864 "slapd_daemon_init: %s\n",
865 urls ? urls : "<null>" ));
867 Debug( LDAP_DEBUG_ARGS, "daemon_init: %s\n",
868 urls ? urls : "<null>", 0, 0 );
870 if( (rc = sockinit()) != 0 ) {
875 dtblsize = sysconf( _SC_OPEN_MAX );
876 #elif HAVE_GETDTABLESIZE
877 dtblsize = getdtablesize();
879 dtblsize = FD_SETSIZE;
883 if(dtblsize > FD_SETSIZE) {
884 dtblsize = FD_SETSIZE;
886 #endif /* !FD_SETSIZE */
888 /* open a pipe (or something equivalent connected to itself).
889 * we write a byte on this fd whenever we catch a signal. The main
890 * loop will be select'ing on this socket, and will wake up when
893 if( (rc = lutil_pair( wake_sds )) < 0 ) {
895 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
896 "slap_daemon_init: lutil_pair() failed rc=%d\n", rc ));
898 Debug( LDAP_DEBUG_ANY,
899 "daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
904 FD_ZERO( &slap_daemon.sd_readers );
905 FD_ZERO( &slap_daemon.sd_writers );
911 u = str2charray( urls, " " );
913 if( u == NULL || u[0] == NULL ) {
915 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
916 "slap_daemon_init: no urls (%s) provided.\n", urls ));
918 Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
924 for( i=0; u[i] != NULL; i++ ) {
926 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
927 "slap_daemon_init: listen on %s\n.", u[i] ));
929 Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n",
936 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
937 "slap_daemon_init: no listeners to open (%s)\n", urls ));
939 Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n",
947 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
948 "slap_daemon_init: %d listeners to open...\n", i ));
950 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners to open...\n",
953 slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) );
955 for(n = 0, j = 0; u[n]; n++ ) {
956 if ( slap_open_listener( u[n], &i, &j ) ) {
961 slap_listeners[j] = NULL;
964 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
965 "slap_daemon_init: %d listeners opened\n", i ));
967 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners opened\n",
972 slapd_slp_init( urls );
977 ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
983 slapd_daemon_destroy(void)
985 connections_destroy();
986 tcp_close( wake_sds[1] );
987 tcp_close( wake_sds[0] );
1006 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1008 slapd_remove( slap_listeners[l]->sl_sd, 0 );
1009 if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
1010 #ifdef LDAP_PF_LOCAL
1011 if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) {
1012 unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path );
1014 #endif /* LDAP_PF_LOCAL */
1015 slapd_close( slap_listeners[l]->sl_sd );
1017 if ( slap_listeners[l]->sl_url )
1018 free ( slap_listeners[l]->sl_url );
1019 if ( slap_listeners[l]->sl_name )
1020 free ( slap_listeners[l]->sl_name );
1021 free ( slap_listeners[l] );
1022 slap_listeners[l] = NULL;
1033 time_t last_idle_check = 0;
1036 if ( global_idletimeout > 0 ) {
1037 last_idle_check = slap_get_time();
1039 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1040 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1042 #ifdef LDAP_CONNECTIONLESS
1043 /* Since this is connectionless, the data port is the
1044 * listening port. The listen() and accept() calls
1047 if ( slap_listeners[l]->sl_is_udp )
1049 slapd_add( slap_listeners[l]->sl_sd );
1054 if ( listen( slap_listeners[l]->sl_sd, SLAPD_LISTEN ) == -1 ) {
1055 int err = sock_errno();
1057 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1058 "slapd_daemon_task: listen( %s, 5 ) failed errno=%d (%s)\n",
1059 slap_listeners[l]->sl_url, err, sock_errstr(err) ));
1061 Debug( LDAP_DEBUG_ANY,
1062 "daemon: listen(%s, 5) failed errno=%d (%s)\n",
1063 slap_listeners[l]->sl_url, err,
1066 return( (void*)-1 );
1069 slapd_add( slap_listeners[l]->sl_sd );
1072 #ifdef HAVE_NT_SERVICE_MANAGER
1073 if ( started_event != NULL ) {
1074 ldap_pvt_thread_cond_signal( &started_event );
1077 /* initialization complete. Here comes the loop. */
1079 while ( !slapd_shutdown ) {
1084 #define SLAPD_EBADF_LIMIT 16
1088 #define SLAPD_IDLE_CHECK_LIMIT 4
1096 #if defined(SLAPD_RLOOKUPS)
1099 struct timeval zero;
1100 struct timeval *tvp;
1103 now = slap_get_time();
1104 connections_timeout_idle( now );
1106 else if ( global_idletimeout > 0 ) {
1107 now = slap_get_time();
1108 if ( difftime( last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) {
1109 connections_timeout_idle( now );
1114 if( slapd_gentle_shutdown ) {
1115 ber_socket_t active;
1117 if( slapd_gentle_shutdown > 0 ) {
1118 Debug( LDAP_DEBUG_ANY, "slapd gentle shutdown\n", 0, 0, 0 );
1119 close_listeners( 1 );
1120 slapd_gentle_shutdown = -1;
1123 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1124 active = slap_daemon.sd_nactives;
1125 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1127 slapd_shutdown = -1;
1133 FD_ZERO( &writefds );
1134 FD_ZERO( &readfds );
1139 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1141 #ifdef FD_SET_MANUAL_COPY
1142 for( s = 0; s < nfds; s++ ) {
1143 if(FD_ISSET( &slap_sd_readers, s )) {
1144 FD_SET( s, &readfds );
1146 if(FD_ISSET( &slap_sd_writers, s )) {
1147 FD_SET( s, &writefds );
1151 AC_MEMCPY( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) );
1152 AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
1154 assert(!FD_ISSET(wake_sds[0], &readfds));
1155 FD_SET( wake_sds[0], &readfds );
1157 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1158 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1160 if (!FD_ISSET(slap_listeners[l]->sl_sd, &readfds))
1161 FD_SET( slap_listeners[l]->sl_sd, &readfds );
1164 #ifndef HAVE_WINSOCK
1165 nfds = slap_daemon.sd_nfds;
1170 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1172 at = ldap_pvt_thread_pool_backload(&connection_pool);
1174 #if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS )
1177 tvp = at ? &zero : NULL;
1180 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1181 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1185 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1186 "slapd_daemon_task: select: listen=%d active_threads=%d tvp=%s\n",
1187 slap_listeners[l]->sl_sd, at, tvp == NULL ? "NULL" : "zero" ));
1189 Debug( LDAP_DEBUG_CONNS,
1190 "daemon: select: listen=%d active_threads=%d tvp=%s\n",
1191 slap_listeners[l]->sl_sd, at,
1192 tvp == NULL ? "NULL" : "zero" );
1196 switch(ns = select( nfds, &readfds,
1198 /* don't pass empty fd_set */
1199 ( writefds.fd_count > 0 ? &writefds : NULL ),
1205 case -1: { /* failure - try again */
1206 int err = sock_errno();
1210 /* you'd think this would be EBADF */
1211 || err == WSAENOTSOCK
1214 if (++ebadf < SLAPD_EBADF_LIMIT)
1218 if( err != EINTR ) {
1220 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1221 "slapd_daemon_task: select failed (%d): %s\n",
1222 err, sock_errstr(err) ));
1224 Debug( LDAP_DEBUG_CONNS,
1225 "daemon: select failed (%d): %s\n",
1226 err, sock_errstr(err), 0 );
1233 case 0: /* timeout - let threads run */
1236 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1237 "slapd_daemon_task: select timeout - yielding\n" ));
1239 Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n",
1242 ldap_pvt_thread_yield();
1245 default: /* something happened - deal with it */
1246 if( slapd_shutdown ) continue;
1250 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1251 "slapd_daemon_task: activity on %d descriptors\n", ns ));
1253 Debug( LDAP_DEBUG_CONNS, "daemon: activity on %d descriptors\n",
1259 if( FD_ISSET( wake_sds[0], &readfds ) ) {
1261 tcp_read( wake_sds[0], c, sizeof(c) );
1268 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1270 socklen_t len = sizeof(from);
1273 char *authid = NULL;
1275 char *dnsname = NULL;
1277 #ifdef LDAP_PF_LOCAL
1278 char peername[MAXPATHLEN + sizeof("PATH=")];
1279 #elif defined(LDAP_PF_INET6)
1280 char peername[sizeof("IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")];
1282 char peername[sizeof("IP=255.255.255.255:65336")];
1283 #endif /* LDAP_PF_LOCAL */
1287 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1290 if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
1293 #ifdef LDAP_CONNECTIONLESS
1294 if ( slap_listeners[l]->sl_is_udp )
1296 /* The first time we receive a query, we set this
1297 * up as a "connection". It remains open for the life
1300 if ( slap_listeners[l]->sl_is_udp < 2 )
1302 id = connection_init(
1303 slap_listeners[l]->sl_sd,
1304 slap_listeners[l]->sl_url, "", "",
1305 slap_listeners[l]->sl_name,
1307 slap_listeners[l]->sl_is_udp++;
1313 s = accept( slap_listeners[l]->sl_sd,
1314 (struct sockaddr *) &from, &len );
1315 if ( s == AC_SOCKET_INVALID ) {
1316 int err = sock_errno();
1319 if( err == EMFILE ) {
1324 if( err == ENFILE ) {
1334 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1335 "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n",
1336 (long)slap_listeners[l]->sl_sd, err, sock_errstr(err) ));
1338 Debug( LDAP_DEBUG_ANY,
1339 "daemon: accept(%ld) failed errno=%d (%s)\n",
1340 (long) slap_listeners[l]->sl_sd, err,
1344 /* prevent busy loop */
1346 if( emfile % 4 == 3 ) usleep( 250 );
1348 if( emfile % 8 == 7 ) sleep( 1 );
1352 ldap_pvt_thread_yield();
1357 #ifndef HAVE_WINSOCK
1358 /* make sure descriptor number isn't too great */
1359 if ( s >= dtblsize ) {
1361 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1362 "slapd_daemon_task: %ld beyond descriptor table size %ld\n",
1363 (long)s, (long)dtblsize ));
1365 Debug( LDAP_DEBUG_ANY,
1366 "daemon: %ld beyond descriptor table size %ld\n",
1367 (long) s, (long) dtblsize, 0 );
1371 ldap_pvt_thread_yield();
1377 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1379 /* newly accepted stream should not be in any of the FD SETS */
1380 assert( !FD_ISSET( s, &slap_daemon.sd_actives) );
1381 assert( !FD_ISSET( s, &slap_daemon.sd_readers) );
1382 assert( !FD_ISSET( s, &slap_daemon.sd_writers) );
1384 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1387 #if defined( SO_KEEPALIVE ) || defined( TCP_NODELAY )
1388 #ifdef LDAP_PF_LOCAL
1389 /* for IPv4 and IPv6 sockets only */
1390 if ( from.sa_addr.sa_family != AF_LOCAL )
1391 #endif /* LDAP_PF_LOCAL */
1396 /* enable keep alives */
1398 rc = setsockopt( s, SOL_SOCKET, SO_KEEPALIVE,
1399 (char *) &tmp, sizeof(tmp) );
1400 if ( rc == AC_SOCKET_ERROR ) {
1401 int err = sock_errno();
1403 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1404 "slapd_daemon_task: setsockopt( %ld, SO_KEEPALIVE) failed errno=%d (%s)\n",
1405 (long)s, err, sock_errstr(err) ));
1407 Debug( LDAP_DEBUG_ANY,
1408 "slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
1409 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1414 /* enable no delay */
1416 rc = setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
1417 (char *)&tmp, sizeof(tmp) );
1418 if ( rc == AC_SOCKET_ERROR ) {
1419 int err = sock_errno();
1421 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1422 "slapd_daemon_task: setsockopt( %ld, TCP_NODELAY) failed errno=%d (%s)\n",
1423 (long)s, err, sock_errstr(err) ));
1425 Debug( LDAP_DEBUG_ANY,
1426 "slapd(%ld): setsockopt(TCP_NODELAY) failed "
1427 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1435 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1436 "slapd_daemon_task: new connection on %ld\n", (long)s ));
1438 Debug( LDAP_DEBUG_CONNS, "daemon: new connection on %ld\n",
1441 switch ( from.sa_addr.sa_family ) {
1442 # ifdef LDAP_PF_LOCAL
1444 sprintf( peername, "PATH=%s", from.sa_un_addr.sun_path );
1445 ssf = LDAP_PVT_SASL_LOCAL_SSF;
1448 #endif /* LDAP_PF_LOCAL */
1450 # ifdef LDAP_PF_INET6
1452 if ( IN6_IS_ADDR_V4MAPPED(&from.sa_in6_addr.sin6_addr) ) {
1453 peeraddr = inet_ntoa( *((struct in_addr *)
1454 &from.sa_in6_addr.sin6_addr.s6_addr[12]) );
1455 sprintf( peername, "IP=%s:%d",
1456 peeraddr != NULL ? peeraddr : "unknown",
1457 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1459 char addr[INET6_ADDRSTRLEN];
1460 sprintf( peername, "IP=%s %d",
1461 inet_ntop( AF_INET6,
1462 &from.sa_in6_addr.sin6_addr,
1463 addr, sizeof addr) ? addr : "unknown",
1464 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1467 # endif /* LDAP_PF_INET6 */
1470 peeraddr = inet_ntoa( from.sa_in_addr.sin_addr );
1471 sprintf( peername, "IP=%s:%d",
1472 peeraddr != NULL ? peeraddr : "unknown",
1473 (unsigned) ntohs( from.sa_in_addr.sin_port ) );
1481 if ( ( from.sa_addr.sa_family == AF_INET )
1482 #ifdef LDAP_PF_INET6
1483 || ( from.sa_addr.sa_family == AF_INET6 )
1486 #ifdef SLAPD_RLOOKUPS
1487 if ( use_reverse_lookup ) {
1488 # ifdef LDAP_PF_INET6
1489 if ( from.sa_addr.sa_family == AF_INET6 )
1491 (char *)&(from.sa_in6_addr.sin6_addr),
1492 sizeof(from.sa_in6_addr.sin6_addr),
1495 # endif /* LDAP_PF_INET6 */
1497 (char *) &(from.sa_in_addr.sin_addr),
1498 sizeof(from.sa_in_addr.sin_addr),
1500 dnsname = hp ? ldap_pvt_str2lower( hp->h_name ) : NULL;
1504 #endif /* SLAPD_RLOOKUPS */
1507 if ( !hosts_ctl("slapd",
1508 dnsname != NULL ? dnsname : STRING_UNKNOWN,
1509 peeraddr != NULL ? peeraddr : STRING_UNKNOWN,
1513 Statslog( LDAP_DEBUG_ANY,
1514 "fd=%ld host access from %s (%s) denied.\n",
1516 dnsname != NULL ? dnsname : "unknown",
1517 peeraddr != NULL ? peeraddr : "unknown",
1522 #endif /* HAVE_TCPD */
1525 id = connection_init(s,
1526 slap_listeners[l]->sl_url,
1527 dnsname != NULL ? dnsname : "unknown",
1529 slap_listeners[l]->sl_name,
1531 slap_listeners[l]->sl_is_tls,
1538 if( authid ) ch_free(authid);
1542 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1543 "slapd_daemon_task: connection_init(%ld, %s, %s) failed.\n",
1544 (long)s, peername, slap_listeners[l]->sl_name ));
1546 Debug( LDAP_DEBUG_ANY,
1547 "daemon: connection_init(%ld, %s, %s) failed.\n",
1550 slap_listeners[l]->sl_name );
1556 Statslog( LDAP_DEBUG_STATS,
1557 "daemon: conn=%ld fd=%ld connection from %s (%s) accepted.\n",
1560 slap_listeners[l]->sl_name,
1569 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1570 "slapd_daemon_task: activity on " ));
1572 Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
1575 for ( i = 0; i < readfds.fd_count; i++ ) {
1577 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1578 " %d%s", readfds.fd_array[i], "r", 0 ));
1580 Debug( LDAP_DEBUG_CONNS, " %d%s",
1581 readfds.fd_array[i], "r", 0 );
1584 for ( i = 0; i < writefds.fd_count; i++ ) {
1586 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1587 " %d%s", writefds.fd_array[i], "w" ));
1589 Debug( LDAP_DEBUG_CONNS, " %d%s",
1590 writefds.fd_array[i], "w", 0 );
1595 for ( i = 0; i < nfds; i++ ) {
1597 int is_listener = 0;
1599 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1600 if ( i == slap_listeners[l]->sl_sd ) {
1601 #ifdef LDAP_CONNECTIONLESS
1602 /* The listener is the data port. Don't
1605 if (slap_listeners[l]->sl_is_udp)
1612 if ( is_listener ) {
1615 r = FD_ISSET( i, &readfds );
1616 w = FD_ISSET( i, &writefds );
1619 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1621 r ? "r" : "", w ? "w" : "" ));
1623 Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
1624 r ? "r" : "", w ? "w" : "" );
1630 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2, "\n" ));
1632 Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
1637 /* loop through the writers */
1639 for ( i = 0; i < writefds.fd_count; i++ )
1641 for ( i = 0; i < nfds; i++ )
1645 int is_listener = 0;
1647 wd = writefds.fd_array[i];
1649 if( ! FD_ISSET( i, &writefds ) ) {
1655 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1656 if ( i == slap_listeners[l]->sl_sd ) {
1657 #ifdef LDAP_CONNECTIONLESS
1658 if (slap_listeners[l]->sl_is_udp)
1665 if ( is_listener ) {
1669 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1670 "slapd_daemon_task: write active on %d\n", wd ));
1672 Debug( LDAP_DEBUG_CONNS,
1673 "daemon: write active on %d\n",
1677 * NOTE: it is possible that the connection was closed
1678 * and that the stream is now inactive.
1679 * connection_write() must valid the stream is still
1683 if ( connection_write( wd ) < 0 ) {
1684 FD_CLR( (unsigned) wd, &readfds );
1690 for ( i = 0; i < readfds.fd_count; i++ )
1692 for ( i = 0; i < nfds; i++ )
1696 int is_listener = 0;
1699 rd = readfds.fd_array[i];
1701 if( ! FD_ISSET( i, &readfds ) ) {
1707 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1708 if ( rd == slap_listeners[l]->sl_sd ) {
1709 #ifdef LDAP_CONNECTIONLESS
1710 if (slap_listeners[l]->sl_is_udp)
1717 if ( is_listener ) {
1722 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1723 "slapd_daemon_task: read activity on %d\n", rd ));
1725 Debug ( LDAP_DEBUG_CONNS,
1726 "daemon: read activity on %d\n", rd, 0, 0 );
1729 * NOTE: it is possible that the connection was closed
1730 * and that the stream is now inactive.
1731 * connection_read() must valid the stream is still
1735 if ( connection_read( rd ) < 0 ) {
1739 ldap_pvt_thread_yield();
1742 if( slapd_shutdown == 1 ) {
1744 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1745 "slapd_daemon_task: shutdown requested and initiated.\n"));
1747 Debug( LDAP_DEBUG_TRACE,
1748 "daemon: shutdown requested and initiated.\n",
1752 } else if ( slapd_shutdown == 2 ) {
1753 #ifdef HAVE_NT_SERVICE_MANAGER
1755 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1756 "slapd_daemon_task: shutdown initiated by Service Manager.\n"));
1758 Debug( LDAP_DEBUG_TRACE,
1759 "daemon: shutdown initiated by Service Manager.\n",
1762 #else /* !HAVE_NT_SERVICE_MANAGER */
1764 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1765 "slapd_daemon_task: abnormal condition, shutdown initiated.\n" ));
1767 Debug( LDAP_DEBUG_TRACE,
1768 "daemon: abnormal condition, shutdown initiated.\n",
1771 #endif /* !HAVE_NT_SERVICE_MANAGER */
1774 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1775 "slapd_daemon_task: no active streams, shutdown initiated.\n" ));
1777 Debug( LDAP_DEBUG_TRACE,
1778 "daemon: no active streams, shutdown initiated.\n",
1783 if( slapd_gentle_shutdown >= 0 )
1784 close_listeners ( 0 );
1785 free ( slap_listeners );
1786 slap_listeners = NULL;
1789 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1790 "slapd_daemon_task: shutdown waiting for %d threads to terminate.\n",
1791 ldap_pvt_thread_pool_backload(&connection_pool) ));
1793 Debug( LDAP_DEBUG_ANY,
1794 "slapd shutdown: waiting for %d threads to terminate\n",
1795 ldap_pvt_thread_pool_backload(&connection_pool), 0, 0 );
1797 ldap_pvt_thread_pool_destroy(&connection_pool, 1);
1803 int slapd_daemon( void )
1809 #define SLAPD_LISTENER_THREAD 1
1810 #if defined( SLAPD_LISTENER_THREAD )
1812 ldap_pvt_thread_t listener_tid;
1814 /* listener as a separate THREAD */
1815 rc = ldap_pvt_thread_create( &listener_tid,
1816 0, slapd_daemon_task, NULL );
1820 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1821 "slapd_daemon: listener ldap_pvt_thread_create failed (%d).\n", rc ));
1823 Debug( LDAP_DEBUG_ANY,
1824 "listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
1829 /* wait for the listener thread to complete */
1830 ldap_pvt_thread_join( listener_tid, (void *) NULL );
1833 /* experimental code */
1834 slapd_daemon_task( NULL );
1843 #if defined( HAVE_WINSOCK2 )
1844 WORD wVersionRequested;
1848 wVersionRequested = MAKEWORD( 2, 0 );
1850 err = WSAStartup( wVersionRequested, &wsaData );
1852 /* Tell the user that we couldn't find a usable */
1857 /* Confirm that the WinSock DLL supports 2.0.*/
1858 /* Note that if the DLL supports versions greater */
1859 /* than 2.0 in addition to 2.0, it will still return */
1860 /* 2.0 in wVersion since that is the version we */
1863 if ( LOBYTE( wsaData.wVersion ) != 2 ||
1864 HIBYTE( wsaData.wVersion ) != 0 )
1866 /* Tell the user that we couldn't find a usable */
1872 /* The WinSock DLL is acceptable. Proceed. */
1873 #elif defined( HAVE_WINSOCK )
1875 if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
1882 int sockdestroy(void)
1884 #if defined( HAVE_WINSOCK2 ) || defined( HAVE_WINSOCK )
1891 slap_sig_shutdown( int sig )
1894 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1895 "slap_sig_shutdown: signal %d\n", sig ));
1897 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
1901 * If the NT Service Manager is controlling the server, we don't
1902 * want SIGBREAK to kill the server. For some strange reason,
1903 * SIGBREAK is generated when a user logs out.
1906 #if HAVE_NT_SERVICE_MANAGER && SIGBREAK
1907 if (is_NT_Service && sig == SIGBREAK)
1909 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1910 "slap_sig_shutdown: SIGBREAK ignored.\n" ));
1912 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: SIGBREAK ignored.\n",
1918 if (sig == SIGHUP && global_gentlehup && slapd_gentle_shutdown == 0)
1919 slapd_gentle_shutdown = 1;
1926 /* reinstall self */
1927 (void) SIGNAL_REINSTALL( sig, slap_sig_shutdown );
1931 slap_sig_wake( int sig )
1935 /* reinstall self */
1936 (void) SIGNAL_REINSTALL( sig, slap_sig_wake );
1940 void slapd_add_internal(ber_socket_t s) {
1944 Listener ** slapd_get_listeners(void) {
1945 return slap_listeners;