3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 #include <ac/signal.h>
14 #include <ac/socket.h>
15 #include <ac/string.h>
17 #include <ac/unistd.h>
20 #include "ldap_pvt_thread.h"
27 int allow_severity = LOG_INFO;
28 int deny_severity = LOG_NOTICE;
29 #endif /* TCP Wrappers */
33 /* this should go in <ldap.h> as soon as it is accepted */
34 #define LDAPI_MOD_URLEXT "x-mod"
35 #endif /* LDAP_PF_LOCAL */
39 ber_socket_t dtblsize;
41 Listener **slap_listeners = NULL;
43 #define SLAPD_LISTEN 10
45 static ber_socket_t wake_sds[2];
49 #define WAKE_LISTENER(w) \
50 ((w && !waking) ? tcp_write( wake_sds[1], "0", 1 ), waking=1 : 0)
52 #define WAKE_LISTENER(w) \
53 do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0)
59 volatile sig_atomic_t slapd_shutdown = 0;
61 static struct slap_daemon {
62 ldap_pvt_thread_mutex_t sd_mutex;
67 /* In winsock, accept() returns values higher than dtblsize
68 so don't bother with this optimization */
81 * SLP related functions
85 #define LDAP_SRVTYPE_PREFIX "service:ldap://"
86 #define LDAPS_SRVTYPE_PREFIX "service:ldaps://"
87 static char** slapd_srvurls = NULL;
88 static SLPHandle slapd_hslp = 0;
90 void slapd_slp_init( const char* urls ) {
93 slapd_srvurls = str2charray( urls, " " );
95 if( slapd_srvurls == NULL ) return;
97 /* find and expand INADDR_ANY URLs */
98 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
99 if( strcmp( slapd_srvurls[i], "ldap:///" ) == 0) {
100 char *host = ldap_pvt_get_fqdn( NULL );
101 if ( host != NULL ) {
102 slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
104 sizeof( LDAP_SRVTYPE_PREFIX ) );
105 strcpy( slap_strcopy(slapd_srvurls[i],
106 LDAP_SRVTYPE_PREFIX ), host );
111 } else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0) {
112 char *host = ldap_pvt_get_fqdn( NULL );
113 if ( host != NULL ) {
114 slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
116 sizeof( LDAPS_SRVTYPE_PREFIX ) );
117 strcpy( slap_strcopy(slapd_srvurls[i],
118 LDAPS_SRVTYPE_PREFIX ), host );
125 /* open the SLP handle */
126 SLPOpen( "en", 0, &slapd_hslp );
129 void slapd_slp_deinit() {
130 if( slapd_srvurls == NULL ) return;
132 charray_free( slapd_srvurls );
133 slapd_srvurls = NULL;
135 /* close the SLP handle */
136 SLPClose( slapd_hslp );
139 void slapd_slp_regreport(
147 void slapd_slp_reg() {
150 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
151 if( strncmp( slapd_srvurls[i], LDAP_SRVTYPE_PREFIX,
152 sizeof( LDAP_SRVTYPE_PREFIX ) - 1 ) == 0 ||
153 strncmp( slapd_srvurls[i], LDAPS_SRVTYPE_PREFIX,
154 sizeof( LDAPS_SRVTYPE_PREFIX ) - 1 ) == 0 )
158 SLP_LIFETIME_MAXIMUM,
168 void slapd_slp_dereg() {
171 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
172 SLPDereg( slapd_hslp,
178 #endif /* HAVE_SLP */
181 * Add a descriptor to daemon control
183 static void slapd_add(ber_socket_t s) {
184 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
186 assert( !FD_ISSET( s, &slap_daemon.sd_actives ));
187 assert( !FD_ISSET( s, &slap_daemon.sd_readers ));
188 assert( !FD_ISSET( s, &slap_daemon.sd_writers ));
191 if (s >= slap_daemon.sd_nfds) {
192 slap_daemon.sd_nfds = s + 1;
196 FD_SET( s, &slap_daemon.sd_actives );
197 FD_SET( s, &slap_daemon.sd_readers );
200 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
201 "slapd_add: added %ld%s%s\n",
203 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
204 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" ));
206 Debug( LDAP_DEBUG_CONNS, "daemon: added %ld%s%s\n",
208 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
209 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
211 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
215 * Remove the descriptor from daemon control
217 void slapd_remove(ber_socket_t s, int wake) {
218 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
221 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
222 "slapd_remove: removing %ld%s%s\n",
224 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
225 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" ));
227 Debug( LDAP_DEBUG_CONNS, "daemon: removing %ld%s%s\n",
229 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
230 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
232 FD_CLR( s, &slap_daemon.sd_actives );
233 FD_CLR( s, &slap_daemon.sd_readers );
234 FD_CLR( s, &slap_daemon.sd_writers );
236 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
240 void slapd_clr_write(ber_socket_t s, int wake) {
241 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
243 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
244 FD_CLR( s, &slap_daemon.sd_writers );
246 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
250 void slapd_set_write(ber_socket_t s, int wake) {
251 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
253 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
254 if (!FD_ISSET(s, &slap_daemon.sd_writers))
255 FD_SET( (unsigned) s, &slap_daemon.sd_writers );
257 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
261 void slapd_clr_read(ber_socket_t s, int wake) {
262 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
264 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
265 FD_CLR( s, &slap_daemon.sd_readers );
267 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
271 void slapd_set_read(ber_socket_t s, int wake) {
272 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
274 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
275 if (!FD_ISSET(s, &slap_daemon.sd_readers))
276 FD_SET( s, &slap_daemon.sd_readers );
278 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
282 static void slapd_close(ber_socket_t s) {
284 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
285 "slapd_close: closing %ld\n", (long)s ));
287 Debug( LDAP_DEBUG_CONNS, "daemon: closing %ld\n",
293 static void slap_free_listener_addresses(struct sockaddr **sal)
295 struct sockaddr **sap;
301 for (sap = sal; *sap != NULL; sap++) {
309 static int get_url_perms(
321 for ( i = 0; exts[ i ]; i++ ) {
322 char *type = exts[ i ];
325 if ( type[ 0 ] == '!' ) {
330 if ( strncasecmp( type, LDAPI_MOD_URLEXT "=", sizeof(LDAPI_MOD_URLEXT "=") - 1 ) == 0 ) {
331 char *value = type + sizeof(LDAPI_MOD_URLEXT "=") - 1;
335 if ( strlen( value ) != 9 ) {
339 switch ( value[ 0 ] ) {
349 switch ( value[ 1 ] ) {
359 switch ( value[ 2 ] ) {
369 switch ( value[ 3 ] ) {
379 switch ( value[ 4 ] ) {
389 switch ( value[ 5 ] ) {
399 switch ( value[ 6 ] ) {
409 switch ( value[ 7 ] ) {
419 switch ( value[ 8 ] ) {
431 if ( strlen(value) != 3 ) {
435 for ( j = 0; j < 3; j++ ) {
437 = { S_IRWXU, S_IRWXG, S_IRWXO };
439 switch ( value[ j ] ) {
460 #endif /* LDAP_PF_LOCAL */
462 /* port = 0 indicates AF_LOCAL */
463 static int slap_get_listener_addresses(
466 struct sockaddr ***sal)
468 struct sockaddr **sap;
472 *sal = ch_malloc(2 * sizeof(void *));
478 *sap = ch_malloc(sizeof(struct sockaddr_un));
484 (sizeof(((struct sockaddr_un *)*sap)->sun_path) - 1) ) {
486 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
487 "slap_get_listener_addresses: domain socket path (%s) too long in URL\n",
490 Debug( LDAP_DEBUG_ANY,
491 "daemon: domain socket path (%s) too long in URL",
497 (void)memset( (void *)*sap, '\0', sizeof(struct sockaddr_un) );
498 (*sap)->sa_family = AF_LOCAL;
499 strcpy( ((struct sockaddr_un *)*sap)->sun_path, host );
503 #ifdef HAVE_GETADDRINFO
504 struct addrinfo hints, *res, *sai;
508 memset( &hints, '\0', sizeof(hints) );
509 hints.ai_flags = AI_PASSIVE;
510 hints.ai_socktype = SOCK_STREAM;
511 hints.ai_family = AF_UNSPEC;
512 snprintf(serv, sizeof serv, "%d", port);
514 if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
516 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
517 "slap_get_listener_addresses: getaddrinfo failed: %s\n",
518 AC_GAI_STRERROR(err) ));
520 Debug( LDAP_DEBUG_ANY, "daemon: getaddrinfo failed: %s\n",
521 AC_GAI_STRERROR(err), 0, 0);
527 for (n=2; (sai = sai->ai_next) != NULL; n++) {
530 *sal = ch_calloc(n, sizeof(void *));
538 for ( sai=res; sai; sai=sai->ai_next ) {
539 if( sai->ai_addr == NULL ) {
541 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
542 "slap_get_listener_addresses: "
543 "getaddrinfo ai_addr is NULL?\n" ));
545 Debug( LDAP_DEBUG_ANY, "slap_get_listener_addresses: "
546 "getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
552 switch (sai->ai_family) {
553 # ifdef LDAP_PF_INET6
555 *sap = ch_malloc(sizeof(struct sockaddr_in6));
560 *(struct sockaddr_in6 *)*sap =
561 *((struct sockaddr_in6 *)sai->ai_addr);
565 *sap = ch_malloc(sizeof(struct sockaddr_in));
570 *(struct sockaddr_in *)*sap =
571 *((struct sockaddr_in *)sai->ai_addr);
579 (*sap)->sa_family = sai->ai_family;
589 if ( host == NULL ) {
590 in.s_addr = htonl(INADDR_ANY);
592 } else if ( !inet_aton( host, &in ) ) {
593 struct hostent *he = gethostbyname( host );
596 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
597 "slap_get_listener_addresses: invalid host %s\n",
600 Debug( LDAP_DEBUG_ANY,
601 "daemon: invalid host %s", host, 0, 0);
605 AC_MEMCPY( &in, he->h_addr, sizeof( in ) );
608 *sal = ch_malloc(2 * sizeof(void *));
614 *sap = ch_malloc(sizeof(struct sockaddr_in));
620 (void)memset( (void *)*sap, '\0', sizeof(struct sockaddr_in) );
621 (*sap)->sa_family = AF_INET;
622 ((struct sockaddr_in *)*sap)->sin_port = htons(port);
623 ((struct sockaddr_in *)*sap)->sin_addr = in;
630 slap_free_listener_addresses(*sal);
634 static Listener * slap_open_listener(
642 int err, addrlen = 0;
643 struct sockaddr **sal, **psal;
644 int socktype = SOCK_STREAM; /* default to COTS */
646 mode_t perms = S_IRWXU;
650 rc = ldap_url_parse( url, &lud );
652 if( rc != LDAP_URL_SUCCESS ) {
654 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
655 "slap_open_listener: listen URL \"%s\" parse error %d\n",
658 Debug( LDAP_DEBUG_ANY,
659 "daemon: listen URL \"%s\" parse error=%d\n",
666 if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
668 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
669 "slap_open_listener: TLS is not supported (%s)\n",
672 Debug( LDAP_DEBUG_ANY,
673 "daemon: TLS not supported (%s)\n",
676 ldap_free_urldesc( lud );
680 if(! lud->lud_port ) {
681 lud->lud_port = LDAP_PORT;
685 l.sl_is_tls = ldap_pvt_url_scheme2tls( lud->lud_scheme );
687 if(! lud->lud_port ) {
688 lud->lud_port = l.sl_is_tls ? LDAPS_PORT : LDAP_PORT;
692 port = (unsigned short) lud->lud_port;
694 tmp = ldap_pvt_url_scheme2proto(lud->lud_scheme);
695 if ( tmp == LDAP_PROTO_IPC ) {
697 if ( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) {
698 err = slap_get_listener_addresses(LDAPI_SOCK, 0, &sal);
700 err = slap_get_listener_addresses(lud->lud_host, 0, &sal);
703 if ( lud->lud_exts ) {
704 err = get_url_perms( lud->lud_exts, &perms, &crit );
709 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
710 "slap_open_listener: URL scheme is not supported: %s\n",
713 Debug( LDAP_DEBUG_ANY, "daemon: URL scheme not supported: %s",
716 ldap_free_urldesc( lud );
720 #ifdef LDAP_CONNECTIONLESS
721 l.sl_is_udp = ( tmp == LDAP_PROTO_UDP );
723 if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
724 || strcmp(lud->lud_host, "*") == 0 )
726 err = slap_get_listener_addresses(NULL, port, &sal);
728 err = slap_get_listener_addresses(lud->lud_host, port, &sal);
732 ldap_free_urldesc( lud );
738 while ( *sal != NULL ) {
739 switch( (*sal)->sa_family ) {
752 #ifdef LDAP_CONNECTIONLESS
754 socktype = SOCK_DGRAM;
756 l.sl_sd = socket( (*sal)->sa_family, socktype, 0);
757 if ( l.sl_sd == AC_SOCKET_INVALID ) {
758 int err = sock_errno();
760 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
761 "slap_open_listener: socket() failed errno=%d (%s)\n",
762 err, sock_errstr(err) ));
764 Debug( LDAP_DEBUG_ANY,
765 "daemon: socket() failed errno=%d (%s)\n", err,
766 sock_errstr(err), 0 );
772 if ( l.sl_sd >= dtblsize ) {
774 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
775 "slap_open_listener: listener descriptor %ld is too great %ld\n",
776 (long)l.sl_sd, (long)dtblsize ));
778 Debug( LDAP_DEBUG_ANY,
779 "daemon: listener descriptor %ld is too great %ld\n",
780 (long) l.sl_sd, (long) dtblsize, 0 );
782 tcp_close( l.sl_sd );
788 if ( (*sal)->sa_family == AF_LOCAL ) {
789 unlink ( ((struct sockaddr_un *)*sal)->sun_path );
794 /* enable address reuse */
796 rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
797 (char *) &tmp, sizeof(tmp) );
798 if ( rc == AC_SOCKET_ERROR ) {
799 int err = sock_errno();
801 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
802 "slap_open_listener: setsockopt( %ld, SO_REUSEADDR ) failed errno %d (%s)\n",
803 (long)l.sl_sd, err, sock_errstr(err) ));
805 Debug( LDAP_DEBUG_ANY,
806 "slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
807 (long) l.sl_sd, err, sock_errstr(err) );
813 switch( (*sal)->sa_family ) {
815 addrlen = sizeof(struct sockaddr_in);
819 addrlen = sizeof(struct sockaddr_in6);
824 addrlen = sizeof(struct sockaddr_un);
829 if (!bind(l.sl_sd, *sal, addrlen))
833 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
834 "slap_open_listener: bind(%ld) failed errno=%d (%s)\n",
835 (long)l.sl_sd, err, sock_errstr(err) ));
837 Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
838 (long) l.sl_sd, err, sock_errstr(err) );
840 tcp_close( l.sl_sd );
842 } /* while ( *sal != NULL ) */
844 if ( *sal == NULL ) {
846 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
847 "slap_open_listener: bind(%ld) failed.\n", (long)l.sl_sd ));
849 Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed\n",
850 (long) l.sl_sd, 0, 0 );
852 slap_free_listener_addresses(psal);
856 switch ( (*sal)->sa_family ) {
859 char *addr = ((struct sockaddr_un *)*sal)->sun_path;
860 if ( chmod( addr, perms ) < 0 && crit ) {
861 int err = sock_errno();
863 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
864 "slap_open_listener: fchmod(%ld) failed errno=%d (%s)\n",
865 (long)l.sl_sd, err, sock_errstr(err) ));
867 Debug( LDAP_DEBUG_ANY, "daemon: fchmod(%ld) failed errno=%d (%s)",
868 (long) l.sl_sd, err, sock_errstr(err) );
870 tcp_close( l.sl_sd );
871 slap_free_listener_addresses(psal);
874 l.sl_name = ch_malloc( strlen(addr) + sizeof("PATH=") );
875 sprintf( l.sl_name, "PATH=%s", addr );
877 #endif /* LDAP_PF_LOCAL */
881 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
882 char addr[INET_ADDRSTRLEN];
883 inet_ntop( AF_INET, &((struct sockaddr_in *)*sal)->sin_addr,
884 addr, sizeof(addr) );
887 s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
889 port = ntohs( ((struct sockaddr_in *)*sal) ->sin_port );
890 l.sl_name = ch_malloc( sizeof("IP=255.255.255.255:65535") );
891 sprintf( l.sl_name, "IP=%s:%d",
892 s != NULL ? s : "unknown" , port );
897 char addr[INET6_ADDRSTRLEN];
898 inet_ntop( AF_INET6, &((struct sockaddr_in6 *)*sal)->sin6_addr,
900 port = ntohs( ((struct sockaddr_in6 *)*sal)->sin6_port );
901 l.sl_name = ch_malloc( strlen(addr) + sizeof("IP= 65535") );
902 sprintf( l.sl_name, "IP=%s %d", addr, port );
904 #endif /* LDAP_PF_INET6 */
908 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
909 "slap_open_listener: unsupported address family (%d)\n",
910 (int)(*sal)->sa_family ));
912 Debug( LDAP_DEBUG_ANY, "daemon: unsupported address family (%d)\n",
913 (int) (*sal)->sa_family, 0, 0 );
918 slap_free_listener_addresses(psal);
920 l.sl_url = ch_strdup( url );
921 li = ch_malloc( sizeof( Listener ) );
925 LDAP_LOG(( "connection", LDAP_LEVEL_RESULTS,
926 "slap_open_listener: daemon initialzed %s\n", l.sl_url ));
928 Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
934 static int sockinit(void);
935 static int sockdestroy(void);
937 int slapd_daemon_init( const char *urls )
943 LDAP_LOG(( "connection", LDAP_LEVEL_ARGS,
944 "slapd_daemon_init: %s\n",
945 urls ? urls : "<null>" ));
947 Debug( LDAP_DEBUG_ARGS, "daemon_init: %s\n",
948 urls ? urls : "<null>", 0, 0 );
950 if( (rc = sockinit()) != 0 ) {
955 dtblsize = sysconf( _SC_OPEN_MAX );
956 #elif HAVE_GETDTABLESIZE
957 dtblsize = getdtablesize();
959 dtblsize = FD_SETSIZE;
963 if(dtblsize > FD_SETSIZE) {
964 dtblsize = FD_SETSIZE;
966 #endif /* !FD_SETSIZE */
968 /* open a pipe (or something equivalent connected to itself).
969 * we write a byte on this fd whenever we catch a signal. The main
970 * loop will be select'ing on this socket, and will wake up when
973 if( (rc = lutil_pair( wake_sds )) < 0 ) {
975 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
976 "slap_daemon_init: lutil_pair() failed rc=%d\n", rc ));
978 Debug( LDAP_DEBUG_ANY,
979 "daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
984 FD_ZERO( &slap_daemon.sd_readers );
985 FD_ZERO( &slap_daemon.sd_writers );
991 u = str2charray( urls, " " );
993 if( u == NULL || u[0] == NULL ) {
995 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
996 "slap_daemon_init: no urls (%s) provided.\n", urls ));
998 Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
1004 for( i=0; u[i] != NULL; i++ ) {
1006 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1007 "slap_daemon_init: listen on %s\n.", u[i] ));
1009 Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n",
1016 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1017 "slap_daemon_init: no listeners to open (%s)\n", urls ));
1019 Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n",
1027 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1028 "slap_daemon_init: %d listeners to open...\n", i ));
1030 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners to open...\n",
1033 slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) );
1035 for(i = 0; u[i] != NULL; i++ ) {
1036 slap_listeners[i] = slap_open_listener( u[i] );
1038 if( slap_listeners[i] == NULL ) {
1043 slap_listeners[i] = NULL;
1046 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1047 "slap_daemon_init: %d listeners opened\n", i ));
1049 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners opened\n",
1054 slapd_slp_init( urls );
1059 ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
1065 slapd_daemon_destroy(void)
1067 connections_destroy();
1068 tcp_close( wake_sds[1] );
1069 tcp_close( wake_sds[0] );
1087 time_t last_idle_check = 0;
1090 if ( global_idletimeout > 0 ) {
1091 last_idle_check = slap_get_time();
1093 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1094 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1096 #ifdef LDAP_CONNECTIONLESS
1097 /* Since this is connectionless, the data port is the
1098 * listening port. The listen() and accept() calls
1101 if ( slap_listeners[l]->sl_is_udp )
1103 slapd_add( slap_listeners[l]->sl_sd );
1108 if ( listen( slap_listeners[l]->sl_sd, SLAPD_LISTEN ) == -1 ) {
1109 int err = sock_errno();
1111 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1112 "slapd_daemon_task: listen( %s, 5 ) failed errno=%d (%s)\n",
1113 slap_listeners[l]->sl_url, err, sock_errstr(err) ));
1115 Debug( LDAP_DEBUG_ANY,
1116 "daemon: listen(%s, 5) failed errno=%d (%s)\n",
1117 slap_listeners[l]->sl_url, err,
1120 return( (void*)-1 );
1123 slapd_add( slap_listeners[l]->sl_sd );
1126 #ifdef HAVE_NT_SERVICE_MANAGER
1127 if ( started_event != NULL ) {
1128 ldap_pvt_thread_cond_signal( &started_event );
1131 /* initialization complete. Here comes the loop. */
1133 while ( !slapd_shutdown ) {
1138 #define SLAPD_EBADF_LIMIT 16
1142 #define SLAPD_IDLE_CHECK_LIMIT 4
1150 #if defined(SLAPD_RLOOKUPS)
1153 struct timeval zero;
1154 struct timeval *tvp;
1157 now = slap_get_time();
1158 connections_timeout_idle( now );
1160 else if ( global_idletimeout > 0 ) {
1161 now = slap_get_time();
1162 if ( difftime( last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) {
1163 connections_timeout_idle( now );
1167 FD_ZERO( &writefds );
1168 FD_ZERO( &readfds );
1173 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1175 #ifdef FD_SET_MANUAL_COPY
1176 for( s = 0; s < nfds; s++ ) {
1177 if(FD_ISSET( &slap_sd_readers, s )) {
1178 FD_SET( s, &readfds );
1180 if(FD_ISSET( &slap_sd_writers, s )) {
1181 FD_SET( s, &writefds );
1185 AC_MEMCPY( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) );
1186 AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
1188 assert(!FD_ISSET(wake_sds[0], &readfds));
1189 FD_SET( wake_sds[0], &readfds );
1191 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1192 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1194 if (!FD_ISSET(slap_listeners[l]->sl_sd, &readfds))
1195 FD_SET( slap_listeners[l]->sl_sd, &readfds );
1198 #ifndef HAVE_WINSOCK
1199 nfds = slap_daemon.sd_nfds;
1204 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1206 at = ldap_pvt_thread_pool_backload(&connection_pool);
1208 #if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS )
1211 tvp = at ? &zero : NULL;
1214 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1215 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1219 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1220 "slapd_daemon_task: select: listen=%d active_threads=%d tvp=%s\n",
1221 slap_listeners[l]->sl_sd, at, tvp == NULL ? "NULL" : "zero" ));
1223 Debug( LDAP_DEBUG_CONNS,
1224 "daemon: select: listen=%d active_threads=%d tvp=%s\n",
1225 slap_listeners[l]->sl_sd, at,
1226 tvp == NULL ? "NULL" : "zero" );
1230 switch(ns = select( nfds, &readfds,
1232 /* don't pass empty fd_set */
1233 ( writefds.fd_count > 0 ? &writefds : NULL ),
1239 case -1: { /* failure - try again */
1240 int err = sock_errno();
1244 /* you'd think this would be EBADF */
1245 || err == WSAENOTSOCK
1248 if (++ebadf < SLAPD_EBADF_LIMIT)
1252 if( err != EINTR ) {
1254 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1255 "slapd_daemon_task: select failed (%d): %s\n",
1256 err, sock_errstr(err) ));
1258 Debug( LDAP_DEBUG_CONNS,
1259 "daemon: select failed (%d): %s\n",
1260 err, sock_errstr(err), 0 );
1262 slapd_shutdown = -1;
1267 case 0: /* timeout - let threads run */
1270 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1271 "slapd_daemon_task: select timeout - yielding\n" ));
1273 Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n",
1276 ldap_pvt_thread_yield();
1279 default: /* something happened - deal with it */
1280 if( slapd_shutdown ) continue;
1284 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1285 "slapd_daemon_task: activity on %d descriptors\n", ns ));
1287 Debug( LDAP_DEBUG_CONNS, "daemon: activity on %d descriptors\n",
1293 if( FD_ISSET( wake_sds[0], &readfds ) ) {
1295 tcp_read( wake_sds[0], c, sizeof(c) );
1302 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1304 socklen_t len = sizeof(from);
1307 char *authid = NULL;
1309 char *dnsname = NULL;
1311 #ifdef LDAP_PF_LOCAL
1312 char peername[MAXPATHLEN + sizeof("PATH=")];
1313 #elif defined(LDAP_PF_INET6)
1314 char peername[sizeof("IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")];
1316 char peername[sizeof("IP=255.255.255.255:65336")];
1317 #endif /* LDAP_PF_LOCAL */
1321 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1324 if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
1327 #ifdef LDAP_CONNECTIONLESS
1328 if ( slap_listeners[l]->sl_is_udp )
1330 /* The first time we receive a query, we set this
1331 * up as a "connection". It remains open for the life
1334 if ( slap_listeners[l]->sl_is_udp < 2 )
1336 id = connection_init(
1337 slap_listeners[l]->sl_sd,
1338 slap_listeners[l]->sl_url, "", "",
1339 slap_listeners[l]->sl_name,
1341 slap_listeners[l]->sl_is_udp++;
1347 s = accept( slap_listeners[l]->sl_sd,
1348 (struct sockaddr *) &from, &len );
1349 if ( s == AC_SOCKET_INVALID ) {
1350 int err = sock_errno();
1353 if( err == EMFILE ) {
1358 if( err == ENFILE ) {
1368 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1369 "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n",
1370 (long)slap_listeners[l]->sl_sd, err, sock_errstr(err) ));
1372 Debug( LDAP_DEBUG_ANY,
1373 "daemon: accept(%ld) failed errno=%d (%s)\n",
1374 (long) slap_listeners[l]->sl_sd, err,
1378 /* prevent busy loop */
1380 if( emfile % 4 == 3 ) usleep( 250 );
1382 if( emfile % 8 == 7 ) sleep( 1 );
1386 ldap_pvt_thread_yield();
1391 #ifndef HAVE_WINSOCK
1392 /* make sure descriptor number isn't too great */
1393 if ( s >= dtblsize ) {
1395 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1396 "slapd_daemon_task: %ld beyond descriptor table size %ld\n",
1397 (long)s, (long)dtblsize ));
1399 Debug( LDAP_DEBUG_ANY,
1400 "daemon: %ld beyond descriptor table size %ld\n",
1401 (long) s, (long) dtblsize, 0 );
1405 ldap_pvt_thread_yield();
1411 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1413 /* newly accepted stream should not be in any of the FD SETS */
1414 assert( !FD_ISSET( s, &slap_daemon.sd_actives) );
1415 assert( !FD_ISSET( s, &slap_daemon.sd_readers) );
1416 assert( !FD_ISSET( s, &slap_daemon.sd_writers) );
1418 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1421 #if defined( SO_KEEPALIVE ) || defined( TCP_NODELAY )
1422 #ifdef LDAP_PF_LOCAL
1423 /* for IPv4 and IPv6 sockets only */
1424 if ( from.sa_addr.sa_family != AF_LOCAL )
1425 #endif /* LDAP_PF_LOCAL */
1430 /* enable keep alives */
1432 rc = setsockopt( s, SOL_SOCKET, SO_KEEPALIVE,
1433 (char *) &tmp, sizeof(tmp) );
1434 if ( rc == AC_SOCKET_ERROR ) {
1435 int err = sock_errno();
1437 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1438 "slapd_daemon_task: setsockopt( %ld, SO_KEEPALIVE) failed errno=%d (%s)\n",
1439 (long)s, err, sock_errstr(err) ));
1441 Debug( LDAP_DEBUG_ANY,
1442 "slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
1443 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1448 /* enable no delay */
1450 rc = setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
1451 (char *)&tmp, sizeof(tmp) );
1452 if ( rc == AC_SOCKET_ERROR ) {
1453 int err = sock_errno();
1455 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1456 "slapd_daemon_task: setsockopt( %ld, TCP_NODELAY) failed errno=%d (%s)\n",
1457 (long)s, err, sock_errstr(err) ));
1459 Debug( LDAP_DEBUG_ANY,
1460 "slapd(%ld): setsockopt(TCP_NODELAY) failed "
1461 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1469 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1470 "slapd_daemon_task: new connection on %ld\n", (long)s ));
1472 Debug( LDAP_DEBUG_CONNS, "daemon: new connection on %ld\n",
1475 switch ( from.sa_addr.sa_family ) {
1476 # ifdef LDAP_PF_LOCAL
1478 sprintf( peername, "PATH=%s", from.sa_un_addr.sun_path );
1479 ssf = LDAP_PVT_SASL_LOCAL_SSF;
1482 #endif /* LDAP_PF_LOCAL */
1484 # ifdef LDAP_PF_INET6
1486 if ( IN6_IS_ADDR_V4MAPPED(&from.sa_in6_addr.sin6_addr) ) {
1487 peeraddr = inet_ntoa( *((struct in_addr *)
1488 &from.sa_in6_addr.sin6_addr.s6_addr[12]) );
1489 sprintf( peername, "IP=%s:%d",
1490 peeraddr != NULL ? peeraddr : "unknown",
1491 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1493 char addr[INET6_ADDRSTRLEN];
1494 sprintf( peername, "IP=%s %d",
1495 inet_ntop( AF_INET6,
1496 &from.sa_in6_addr.sin6_addr,
1497 addr, sizeof addr) ? addr : "unknown",
1498 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1501 # endif /* LDAP_PF_INET6 */
1504 peeraddr = inet_ntoa( from.sa_in_addr.sin_addr );
1505 sprintf( peername, "IP=%s:%d",
1506 peeraddr != NULL ? peeraddr : "unknown",
1507 (unsigned) ntohs( from.sa_in_addr.sin_port ) );
1515 if ( ( from.sa_addr.sa_family == AF_INET )
1516 #ifdef LDAP_PF_INET6
1517 || ( from.sa_addr.sa_family == AF_INET6 )
1520 #ifdef SLAPD_RLOOKUPS
1521 # ifdef LDAP_PF_INET6
1522 if ( from.sa_addr.sa_family == AF_INET6 )
1524 (char *)&(from.sa_in6_addr.sin6_addr),
1525 sizeof(from.sa_in6_addr.sin6_addr),
1528 # endif /* LDAP_PF_INET6 */
1530 (char *) &(from.sa_in_addr.sin_addr),
1531 sizeof(from.sa_in_addr.sin_addr),
1533 dnsname = hp ? ldap_pvt_str2lower( hp->h_name ) : NULL;
1536 #endif /* SLAPD_RLOOKUPS */
1539 if ( !hosts_ctl("slapd",
1540 dnsname != NULL ? dnsname : STRING_UNKNOWN,
1541 peeraddr != NULL ? peeraddr : STRING_UNKNOWN,
1545 Statslog( LDAP_DEBUG_ANY,
1546 "fd=%ld host access from %s (%s) denied.\n",
1548 dnsname != NULL ? dnsname : "unknown",
1549 peeraddr != NULL ? peeraddr : "unknown",
1554 #endif /* HAVE_TCPD */
1557 id = connection_init(s,
1558 slap_listeners[l]->sl_url,
1559 dnsname != NULL ? dnsname : "unknown",
1561 slap_listeners[l]->sl_name,
1563 slap_listeners[l]->sl_is_tls,
1570 if( authid ) ch_free(authid);
1574 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1575 "slapd_daemon_task: connection_init(%ld, %s, %s) failed.\n",
1576 (long)s, peername, slap_listeners[l]->sl_name ));
1578 Debug( LDAP_DEBUG_ANY,
1579 "daemon: connection_init(%ld, %s, %s) failed.\n",
1582 slap_listeners[l]->sl_name );
1588 Statslog( LDAP_DEBUG_STATS,
1589 "daemon: conn=%ld fd=%ld connection from %s (%s) accepted.\n",
1592 slap_listeners[l]->sl_name,
1601 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1602 "slapd_daemon_task: activity on " ));
1604 Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
1607 for ( i = 0; i < readfds.fd_count; i++ ) {
1609 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1610 " %d%s", readfds.fd_array[i], "r", 0 ));
1612 Debug( LDAP_DEBUG_CONNS, " %d%s",
1613 readfds.fd_array[i], "r", 0 );
1616 for ( i = 0; i < writefds.fd_count; i++ ) {
1618 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1619 " %d%s", writefds.fd_array[i], "w" ));
1621 Debug( LDAP_DEBUG_CONNS, " %d%s",
1622 writefds.fd_array[i], "w", 0 );
1627 for ( i = 0; i < nfds; i++ ) {
1629 int is_listener = 0;
1631 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1632 if ( i == slap_listeners[l]->sl_sd ) {
1633 #ifdef LDAP_CONNECTIONLESS
1634 /* The listener is the data port. Don't
1637 if (slap_listeners[l]->sl_is_udp)
1644 if ( is_listener ) {
1647 r = FD_ISSET( i, &readfds );
1648 w = FD_ISSET( i, &writefds );
1651 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1653 r ? "r" : "", w ? "w" : "" ));
1655 Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
1656 r ? "r" : "", w ? "w" : "" );
1662 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2, "\n" ));
1664 Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
1669 /* loop through the writers */
1671 for ( i = 0; i < writefds.fd_count; i++ )
1673 for ( i = 0; i < nfds; i++ )
1677 int is_listener = 0;
1679 wd = writefds.fd_array[i];
1681 if( ! FD_ISSET( i, &writefds ) ) {
1687 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1688 if ( i == slap_listeners[l]->sl_sd ) {
1689 #ifdef LDAP_CONNECTIONLESS
1690 if (slap_listeners[l]->sl_is_udp)
1697 if ( is_listener ) {
1701 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1702 "slapd_daemon_task: write active on %d\n", wd ));
1704 Debug( LDAP_DEBUG_CONNS,
1705 "daemon: write active on %d\n",
1709 * NOTE: it is possible that the connection was closed
1710 * and that the stream is now inactive.
1711 * connection_write() must valid the stream is still
1715 if ( connection_write( wd ) < 0 ) {
1716 FD_CLR( (unsigned) wd, &readfds );
1722 for ( i = 0; i < readfds.fd_count; i++ )
1724 for ( i = 0; i < nfds; i++ )
1728 int is_listener = 0;
1731 rd = readfds.fd_array[i];
1733 if( ! FD_ISSET( i, &readfds ) ) {
1739 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1740 if ( rd == slap_listeners[l]->sl_sd ) {
1741 #ifdef LDAP_CONNECTIONLESS
1742 if (slap_listeners[l]->sl_is_udp)
1749 if ( is_listener ) {
1754 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1755 "slapd_daemon_task: read activity on %d\n", rd ));
1757 Debug ( LDAP_DEBUG_CONNS,
1758 "daemon: read activity on %d\n", rd, 0, 0 );
1761 * NOTE: it is possible that the connection was closed
1762 * and that the stream is now inactive.
1763 * connection_read() must valid the stream is still
1767 if ( connection_read( rd ) < 0 ) {
1771 ldap_pvt_thread_yield();
1774 if( slapd_shutdown > 0 ) {
1776 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1777 "slapd_daemon_task: shutdown requested and initiated.\n"));
1779 Debug( LDAP_DEBUG_TRACE,
1780 "daemon: shutdown requested and initiated.\n",
1784 } else if ( slapd_shutdown < 0 ) {
1785 #ifdef HAVE_NT_SERVICE_MANAGER
1786 if (slapd_shutdown == -1)
1789 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1790 "slapd_daemon_task: shutdown initiated by Service Manager.\n"));
1792 Debug( LDAP_DEBUG_TRACE,
1793 "daemon: shutdown initiated by Service Manager.\n",
1801 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1802 "slapd_daemon_task: abnormal condition, shutdown initiated.\n" ));
1804 Debug( LDAP_DEBUG_TRACE,
1805 "daemon: abnormal condition, shutdown initiated.\n",
1811 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1812 "slapd_daemon_task: no active streams, shutdown initiated.\n" ));
1814 Debug( LDAP_DEBUG_TRACE,
1815 "daemon: no active streams, shutdown initiated.\n",
1820 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1821 if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
1822 #ifdef LDAP_PF_LOCAL
1823 if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) {
1824 unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path );
1826 #endif /* LDAP_PF_LOCAL */
1827 slapd_close( slap_listeners[l]->sl_sd );
1829 if ( slap_listeners[l]->sl_url )
1830 free ( slap_listeners[l]->sl_url );
1831 if ( slap_listeners[l]->sl_name )
1832 free ( slap_listeners[l]->sl_name );
1833 free ( slap_listeners[l] );
1835 free ( slap_listeners );
1836 slap_listeners = NULL;
1839 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1840 "slapd_daemon_task: shutdown waiting for %d threads to terminate.\n",
1841 ldap_pvt_thread_pool_backload(&connection_pool) ));
1843 Debug( LDAP_DEBUG_ANY,
1844 "slapd shutdown: waiting for %d threads to terminate\n",
1845 ldap_pvt_thread_pool_backload(&connection_pool), 0, 0 );
1847 ldap_pvt_thread_pool_destroy(&connection_pool, 1);
1853 int slapd_daemon( void )
1859 #define SLAPD_LISTENER_THREAD 1
1860 #if defined( SLAPD_LISTENER_THREAD )
1862 ldap_pvt_thread_t listener_tid;
1864 /* listener as a separate THREAD */
1865 rc = ldap_pvt_thread_create( &listener_tid,
1866 0, slapd_daemon_task, NULL );
1870 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1871 "slapd_daemon: listener ldap_pvt_thread_create failed (%d).\n", rc ));
1873 Debug( LDAP_DEBUG_ANY,
1874 "listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
1879 /* wait for the listener thread to complete */
1880 ldap_pvt_thread_join( listener_tid, (void *) NULL );
1883 /* experimental code */
1884 slapd_daemon_task( NULL );
1893 #if defined( HAVE_WINSOCK2 )
1894 WORD wVersionRequested;
1898 wVersionRequested = MAKEWORD( 2, 0 );
1900 err = WSAStartup( wVersionRequested, &wsaData );
1902 /* Tell the user that we couldn't find a usable */
1907 /* Confirm that the WinSock DLL supports 2.0.*/
1908 /* Note that if the DLL supports versions greater */
1909 /* than 2.0 in addition to 2.0, it will still return */
1910 /* 2.0 in wVersion since that is the version we */
1913 if ( LOBYTE( wsaData.wVersion ) != 2 ||
1914 HIBYTE( wsaData.wVersion ) != 0 )
1916 /* Tell the user that we couldn't find a usable */
1922 /* The WinSock DLL is acceptable. Proceed. */
1923 #elif defined( HAVE_WINSOCK )
1925 if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
1932 int sockdestroy(void)
1934 #if defined( HAVE_WINSOCK2 ) || defined( HAVE_WINSOCK )
1941 slap_sig_shutdown( int sig )
1944 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1945 "slap_sig_shutdown: signal %d\n", sig ));
1947 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
1951 * If the NT Service Manager is controlling the server, we don't
1952 * want SIGBREAK to kill the server. For some strange reason,
1953 * SIGBREAK is generated when a user logs out.
1956 #if HAVE_NT_SERVICE_MANAGER && SIGBREAK
1957 if (is_NT_Service && sig == SIGBREAK)
1959 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1960 "slap_sig_shutdown: SIGBREAK ignored.\n" ));
1962 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: SIGBREAK ignored.\n",
1967 slapd_shutdown = sig;
1971 /* reinstall self */
1972 (void) SIGNAL_REINSTALL( sig, slap_sig_shutdown );
1976 slap_sig_wake( int sig )
1980 /* reinstall self */
1981 (void) SIGNAL_REINSTALL( sig, slap_sig_wake );
1985 void slapd_add_internal(ber_socket_t s) {
1989 Listener ** slapd_get_listeners(void) {
1990 return slap_listeners;