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 */
36 int slap_inet4or6 = AF_UNSPEC;
40 ber_socket_t dtblsize;
42 Listener **slap_listeners = NULL;
44 #define SLAPD_LISTEN 10
46 static ber_socket_t wake_sds[2];
50 #define WAKE_LISTENER(w) \
51 ((w && !waking) ? tcp_write( wake_sds[1], "0", 1 ), waking=1 : 0)
53 #define WAKE_LISTENER(w) \
54 do { if (w) tcp_write( wake_sds[1], "0", 1 ); } while(0)
60 volatile sig_atomic_t slapd_shutdown = 0, slapd_gentle_shutdown = 0;
62 static struct slap_daemon {
63 ldap_pvt_thread_mutex_t sd_mutex;
65 ber_socket_t sd_nactives;
68 /* In winsock, accept() returns values higher than dtblsize
69 so don't bother with this optimization */
82 * SLP related functions
86 #define LDAP_SRVTYPE_PREFIX "service:ldap://"
87 #define LDAPS_SRVTYPE_PREFIX "service:ldaps://"
88 static char** slapd_srvurls = NULL;
89 static SLPHandle slapd_hslp = 0;
91 void slapd_slp_init( const char* urls ) {
94 slapd_srvurls = str2charray( urls, " " );
96 if( slapd_srvurls == NULL ) return;
98 /* find and expand INADDR_ANY URLs */
99 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
100 if( strcmp( slapd_srvurls[i], "ldap:///" ) == 0) {
101 char *host = ldap_pvt_get_fqdn( NULL );
102 if ( host != NULL ) {
103 slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
105 sizeof( LDAP_SRVTYPE_PREFIX ) );
106 strcpy( slap_strcopy(slapd_srvurls[i],
107 LDAP_SRVTYPE_PREFIX ), host );
112 } else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0) {
113 char *host = ldap_pvt_get_fqdn( NULL );
114 if ( host != NULL ) {
115 slapd_srvurls[i] = (char *) realloc( slapd_srvurls[i],
117 sizeof( LDAPS_SRVTYPE_PREFIX ) );
118 strcpy( slap_strcopy(slapd_srvurls[i],
119 LDAPS_SRVTYPE_PREFIX ), host );
126 /* open the SLP handle */
127 SLPOpen( "en", 0, &slapd_hslp );
130 void slapd_slp_deinit() {
131 if( slapd_srvurls == NULL ) return;
133 charray_free( slapd_srvurls );
134 slapd_srvurls = NULL;
136 /* close the SLP handle */
137 SLPClose( slapd_hslp );
140 void slapd_slp_regreport(
148 void slapd_slp_reg() {
151 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
152 if( strncmp( slapd_srvurls[i], LDAP_SRVTYPE_PREFIX,
153 sizeof( LDAP_SRVTYPE_PREFIX ) - 1 ) == 0 ||
154 strncmp( slapd_srvurls[i], LDAPS_SRVTYPE_PREFIX,
155 sizeof( LDAPS_SRVTYPE_PREFIX ) - 1 ) == 0 )
159 SLP_LIFETIME_MAXIMUM,
169 void slapd_slp_dereg() {
172 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
173 SLPDereg( slapd_hslp,
179 #endif /* HAVE_SLP */
182 * Add a descriptor to daemon control
184 static void slapd_add(ber_socket_t s) {
185 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
187 assert( !FD_ISSET( s, &slap_daemon.sd_actives ));
188 assert( !FD_ISSET( s, &slap_daemon.sd_readers ));
189 assert( !FD_ISSET( s, &slap_daemon.sd_writers ));
192 if (s >= slap_daemon.sd_nfds) {
193 slap_daemon.sd_nfds = s + 1;
197 slap_daemon.sd_nactives++;
199 FD_SET( s, &slap_daemon.sd_actives );
200 FD_SET( s, &slap_daemon.sd_readers );
203 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
204 "slapd_add: added %ld%s%s\n",
206 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
207 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" ));
209 Debug( LDAP_DEBUG_CONNS, "daemon: added %ld%s%s\n",
211 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
212 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
214 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
218 * Remove the descriptor from daemon control
220 void slapd_remove(ber_socket_t s, int wake) {
221 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
223 slap_daemon.sd_nactives--;
226 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
227 "slapd_remove: removing %ld%s%s\n",
229 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
230 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" ));
232 Debug( LDAP_DEBUG_CONNS, "daemon: removing %ld%s%s\n",
234 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
235 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
237 FD_CLR( s, &slap_daemon.sd_actives );
238 FD_CLR( s, &slap_daemon.sd_readers );
239 FD_CLR( s, &slap_daemon.sd_writers );
241 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
242 WAKE_LISTENER(wake || slapd_gentle_shutdown == 2);
245 void slapd_clr_write(ber_socket_t s, int wake) {
246 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
248 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
249 FD_CLR( s, &slap_daemon.sd_writers );
251 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
255 void slapd_set_write(ber_socket_t s, int wake) {
256 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
258 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
259 if (!FD_ISSET(s, &slap_daemon.sd_writers))
260 FD_SET( (unsigned) s, &slap_daemon.sd_writers );
262 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
266 void slapd_clr_read(ber_socket_t s, int wake) {
267 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
269 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
270 FD_CLR( s, &slap_daemon.sd_readers );
272 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
276 void slapd_set_read(ber_socket_t s, int wake) {
277 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
279 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
280 if (!FD_ISSET(s, &slap_daemon.sd_readers))
281 FD_SET( s, &slap_daemon.sd_readers );
283 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
287 static void slapd_close(ber_socket_t s) {
289 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
290 "slapd_close: closing %ld\n", (long)s ));
292 Debug( LDAP_DEBUG_CONNS, "daemon: closing %ld\n",
298 static void slap_free_listener_addresses(struct sockaddr **sal)
300 struct sockaddr **sap;
306 for (sap = sal; *sap != NULL; sap++) {
314 static int get_url_perms(
326 for ( i = 0; exts[ i ]; i++ ) {
327 char *type = exts[ i ];
330 if ( type[ 0 ] == '!' ) {
335 if ( strncasecmp( type, LDAPI_MOD_URLEXT "=", sizeof(LDAPI_MOD_URLEXT "=") - 1 ) == 0 ) {
336 char *value = type + sizeof(LDAPI_MOD_URLEXT "=") - 1;
340 if ( strlen(value) != 3 ) {
344 for ( j = 0; j < 3; j++ ) {
346 = { S_IRWXU, S_IRWXG, S_IRWXO };
348 switch ( value[ j ] ) {
368 #endif /* LDAP_PF_LOCAL */
370 /* port = 0 indicates AF_LOCAL */
371 static int slap_get_listener_addresses(
374 struct sockaddr ***sal)
376 struct sockaddr **sap;
380 *sal = ch_malloc(2 * sizeof(void *));
386 *sap = ch_malloc(sizeof(struct sockaddr_un));
392 (sizeof(((struct sockaddr_un *)*sap)->sun_path) - 1) ) {
394 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
395 "slap_get_listener_addresses: domain socket path (%s) too long in URL\n",
398 Debug( LDAP_DEBUG_ANY,
399 "daemon: domain socket path (%s) too long in URL",
405 (void)memset( (void *)*sap, '\0', sizeof(struct sockaddr_un) );
406 (*sap)->sa_family = AF_LOCAL;
407 strcpy( ((struct sockaddr_un *)*sap)->sun_path, host );
411 #ifdef HAVE_GETADDRINFO
412 struct addrinfo hints, *res, *sai;
416 memset( &hints, '\0', sizeof(hints) );
417 hints.ai_flags = AI_PASSIVE;
418 hints.ai_socktype = SOCK_STREAM;
419 hints.ai_family = slap_inet4or6;
420 snprintf(serv, sizeof serv, "%d", port);
422 if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
424 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
425 "slap_get_listener_addresses: getaddrinfo failed: %s\n",
426 AC_GAI_STRERROR(err) ));
428 Debug( LDAP_DEBUG_ANY, "daemon: getaddrinfo failed: %s\n",
429 AC_GAI_STRERROR(err), 0, 0);
435 for (n=2; (sai = sai->ai_next) != NULL; n++) {
438 *sal = ch_calloc(n, sizeof(void *));
446 for ( sai=res; sai; sai=sai->ai_next ) {
447 if( sai->ai_addr == NULL ) {
449 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
450 "slap_get_listener_addresses: "
451 "getaddrinfo ai_addr is NULL?\n" ));
453 Debug( LDAP_DEBUG_ANY, "slap_get_listener_addresses: "
454 "getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
460 switch (sai->ai_family) {
461 # ifdef LDAP_PF_INET6
463 *sap = ch_malloc(sizeof(struct sockaddr_in6));
468 *(struct sockaddr_in6 *)*sap =
469 *((struct sockaddr_in6 *)sai->ai_addr);
473 *sap = ch_malloc(sizeof(struct sockaddr_in));
478 *(struct sockaddr_in *)*sap =
479 *((struct sockaddr_in *)sai->ai_addr);
487 (*sap)->sa_family = sai->ai_family;
497 struct hostent *he = NULL;
499 if ( host == NULL ) {
500 in.s_addr = htonl(INADDR_ANY);
502 } else if ( !inet_aton( host, &in ) ) {
503 he = gethostbyname( host );
506 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
507 "slap_get_listener_addresses: invalid host %s\n",
510 Debug( LDAP_DEBUG_ANY,
511 "daemon: invalid host %s", host, 0, 0);
515 for (n = 0; he->h_addr_list[n]; n++) ;
518 *sal = ch_malloc((n+1) * sizeof(void *));
524 for ( i = 0; i<n; i++ ) {
525 sap[i] = ch_malloc(sizeof(struct sockaddr_in));
529 (void)memset( (void *)sap[i], '\0', sizeof(struct sockaddr_in) );
530 sap[i]->sa_family = AF_INET;
531 ((struct sockaddr_in *)sap[i])->sin_port = htons(port);
533 AC_MEMCPY( &((struct sockaddr_in *)sap[i])->sin_addr, he->h_addr_list[i], sizeof(struct in_addr) );
535 AC_MEMCPY( &((struct sockaddr_in *)sap[i])->sin_addr, &in, sizeof(struct in_addr) );
545 slap_free_listener_addresses(*sal);
549 static int slap_open_listener(
560 int err, addrlen = 0;
561 struct sockaddr **sal, **psal;
562 int socktype = SOCK_STREAM; /* default to COTS */
564 mode_t perms = S_IRWXU;
568 rc = ldap_url_parse( url, &lud );
570 if( rc != LDAP_URL_SUCCESS ) {
572 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
573 "slap_open_listener: listen URL \"%s\" parse error %d\n",
576 Debug( LDAP_DEBUG_ANY,
577 "daemon: listen URL \"%s\" parse error=%d\n",
584 if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
586 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
587 "slap_open_listener: TLS is not supported (%s)\n",
590 Debug( LDAP_DEBUG_ANY,
591 "daemon: TLS not supported (%s)\n",
594 ldap_free_urldesc( lud );
598 if(! lud->lud_port ) {
599 lud->lud_port = LDAP_PORT;
603 l.sl_is_tls = ldap_pvt_url_scheme2tls( lud->lud_scheme );
605 if(! lud->lud_port ) {
606 lud->lud_port = l.sl_is_tls ? LDAPS_PORT : LDAP_PORT;
610 port = (unsigned short) lud->lud_port;
612 tmp = ldap_pvt_url_scheme2proto(lud->lud_scheme);
613 if ( tmp == LDAP_PROTO_IPC ) {
615 if ( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) {
616 err = slap_get_listener_addresses(LDAPI_SOCK, 0, &sal);
618 err = slap_get_listener_addresses(lud->lud_host, 0, &sal);
621 if ( lud->lud_exts ) {
622 err = get_url_perms( lud->lud_exts, &perms, &crit );
627 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
628 "slap_open_listener: URL scheme is not supported: %s\n",
631 Debug( LDAP_DEBUG_ANY, "daemon: URL scheme not supported: %s",
634 ldap_free_urldesc( lud );
638 #ifdef LDAP_CONNECTIONLESS
639 l.sl_is_udp = ( tmp == LDAP_PROTO_UDP );
641 if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
642 || strcmp(lud->lud_host, "*") == 0 )
644 err = slap_get_listener_addresses(NULL, port, &sal);
646 err = slap_get_listener_addresses(lud->lud_host, port, &sal);
650 ldap_free_urldesc( lud );
655 /* If we got more than one address returned, we need to make space
656 * for it in the slap_listeners array.
658 for ( num=0; sal[num]; num++ );
661 slap_listeners = ch_realloc( slap_listeners, (*listeners + 1) * sizeof(Listener *) );
665 while ( *sal != NULL ) {
666 switch( (*sal)->sa_family ) {
679 #ifdef LDAP_CONNECTIONLESS
681 socktype = SOCK_DGRAM;
683 l.sl_sd = socket( (*sal)->sa_family, socktype, 0);
684 if ( l.sl_sd == AC_SOCKET_INVALID ) {
685 int err = sock_errno();
687 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
688 "slap_open_listener: socket() failed errno=%d (%s)\n",
689 err, sock_errstr(err) ));
691 Debug( LDAP_DEBUG_ANY,
692 "daemon: socket() failed errno=%d (%s)\n", err,
693 sock_errstr(err), 0 );
699 if ( l.sl_sd >= dtblsize ) {
701 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
702 "slap_open_listener: listener descriptor %ld is too great %ld\n",
703 (long)l.sl_sd, (long)dtblsize ));
705 Debug( LDAP_DEBUG_ANY,
706 "daemon: listener descriptor %ld is too great %ld\n",
707 (long) l.sl_sd, (long) dtblsize, 0 );
709 tcp_close( l.sl_sd );
715 if ( (*sal)->sa_family == AF_LOCAL ) {
716 unlink ( ((struct sockaddr_un *)*sal)->sun_path );
721 /* enable address reuse */
723 rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
724 (char *) &tmp, sizeof(tmp) );
725 if ( rc == AC_SOCKET_ERROR ) {
726 int err = sock_errno();
728 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
729 "slap_open_listener: setsockopt( %ld, SO_REUSEADDR ) failed errno %d (%s)\n",
730 (long)l.sl_sd, err, sock_errstr(err) ));
732 Debug( LDAP_DEBUG_ANY,
733 "slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
734 (long) l.sl_sd, err, sock_errstr(err) );
740 switch( (*sal)->sa_family ) {
742 addrlen = sizeof(struct sockaddr_in);
746 addrlen = sizeof(struct sockaddr_in6);
751 addrlen = sizeof(struct sockaddr_un);
756 if (bind(l.sl_sd, *sal, addrlen)) {
759 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
760 "slap_open_listener: bind(%ld) failed errno=%d (%s)\n",
761 (long)l.sl_sd, err, sock_errstr(err) ));
763 Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
764 (long) l.sl_sd, err, sock_errstr(err) );
766 tcp_close( l.sl_sd );
771 switch ( (*sal)->sa_family ) {
774 char *addr = ((struct sockaddr_un *)*sal)->sun_path;
775 if ( chmod( addr, perms ) < 0 && crit ) {
776 int err = sock_errno();
778 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
779 "slap_open_listener: fchmod(%ld) failed errno=%d (%s)\n",
780 (long)l.sl_sd, err, sock_errstr(err) ));
782 Debug( LDAP_DEBUG_ANY, "daemon: fchmod(%ld) failed errno=%d (%s)",
783 (long) l.sl_sd, err, sock_errstr(err) );
785 tcp_close( l.sl_sd );
786 slap_free_listener_addresses(psal);
789 l.sl_name = ch_malloc( strlen(addr) + sizeof("PATH=") );
790 sprintf( l.sl_name, "PATH=%s", addr );
792 #endif /* LDAP_PF_LOCAL */
796 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
797 char addr[INET_ADDRSTRLEN];
798 inet_ntop( AF_INET, &((struct sockaddr_in *)*sal)->sin_addr,
799 addr, sizeof(addr) );
802 s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
804 port = ntohs( ((struct sockaddr_in *)*sal) ->sin_port );
805 l.sl_name = ch_malloc( sizeof("IP=255.255.255.255:65535") );
806 sprintf( l.sl_name, "IP=%s:%d",
807 s != NULL ? s : "unknown" , port );
812 char addr[INET6_ADDRSTRLEN];
813 inet_ntop( AF_INET6, &((struct sockaddr_in6 *)*sal)->sin6_addr,
815 port = ntohs( ((struct sockaddr_in6 *)*sal)->sin6_port );
816 l.sl_name = ch_malloc( strlen(addr) + sizeof("IP= 65535") );
817 sprintf( l.sl_name, "IP=%s %d", addr, port );
819 #endif /* LDAP_PF_INET6 */
823 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
824 "slap_open_listener: unsupported address family (%d)\n",
825 (int)(*sal)->sa_family ));
827 Debug( LDAP_DEBUG_ANY, "daemon: unsupported address family (%d)\n",
828 (int) (*sal)->sa_family, 0, 0 );
833 AC_MEMCPY(&l.sl_sa, *sal, addrlen);
834 l.sl_url = ch_strdup( url );
835 li = ch_malloc( sizeof( Listener ) );
837 slap_listeners[*cur] = li;
841 } /* while ( *sal != NULL ) */
843 slap_free_listener_addresses(psal);
847 LDAP_LOG(( "connection", LDAP_LEVEL_RESULTS,
848 "slap_open_listener: daemon initialized %s\n", l.sl_url ));
850 Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
856 static int sockinit(void);
857 static int sockdestroy(void);
859 int slapd_daemon_init( const char *urls )
865 LDAP_LOG(( "connection", LDAP_LEVEL_ARGS,
866 "slapd_daemon_init: %s\n",
867 urls ? urls : "<null>" ));
869 Debug( LDAP_DEBUG_ARGS, "daemon_init: %s\n",
870 urls ? urls : "<null>", 0, 0 );
872 if( (rc = sockinit()) != 0 ) {
877 dtblsize = sysconf( _SC_OPEN_MAX );
878 #elif HAVE_GETDTABLESIZE
879 dtblsize = getdtablesize();
881 dtblsize = FD_SETSIZE;
885 if(dtblsize > FD_SETSIZE) {
886 dtblsize = FD_SETSIZE;
888 #endif /* !FD_SETSIZE */
890 /* open a pipe (or something equivalent connected to itself).
891 * we write a byte on this fd whenever we catch a signal. The main
892 * loop will be select'ing on this socket, and will wake up when
895 if( (rc = lutil_pair( wake_sds )) < 0 ) {
897 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
898 "slap_daemon_init: lutil_pair() failed rc=%d\n", rc ));
900 Debug( LDAP_DEBUG_ANY,
901 "daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
906 FD_ZERO( &slap_daemon.sd_readers );
907 FD_ZERO( &slap_daemon.sd_writers );
913 u = str2charray( urls, " " );
915 if( u == NULL || u[0] == NULL ) {
917 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
918 "slap_daemon_init: no urls (%s) provided.\n", urls ));
920 Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
926 for( i=0; u[i] != NULL; i++ ) {
928 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
929 "slap_daemon_init: listen on %s\n.", u[i] ));
931 Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n",
938 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
939 "slap_daemon_init: no listeners to open (%s)\n", urls ));
941 Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n",
949 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
950 "slap_daemon_init: %d listeners to open...\n", i ));
952 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners to open...\n",
955 slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) );
957 for(n = 0, j = 0; u[n]; n++ ) {
958 if ( slap_open_listener( u[n], &i, &j ) ) {
963 slap_listeners[j] = NULL;
966 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
967 "slap_daemon_init: %d listeners opened\n", i ));
969 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners opened\n",
974 slapd_slp_init( urls );
979 ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
985 slapd_daemon_destroy(void)
987 connections_destroy();
988 tcp_close( wake_sds[1] );
989 tcp_close( wake_sds[0] );
1008 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1010 slapd_remove( slap_listeners[l]->sl_sd, 0 );
1011 if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
1012 #ifdef LDAP_PF_LOCAL
1013 if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) {
1014 unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path );
1016 #endif /* LDAP_PF_LOCAL */
1017 slapd_close( slap_listeners[l]->sl_sd );
1019 if ( slap_listeners[l]->sl_url )
1020 free ( slap_listeners[l]->sl_url );
1021 if ( slap_listeners[l]->sl_name )
1022 free ( slap_listeners[l]->sl_name );
1023 free ( slap_listeners[l] );
1024 slap_listeners[l] = NULL;
1035 time_t last_idle_check = 0;
1038 if ( global_idletimeout > 0 ) {
1039 last_idle_check = slap_get_time();
1041 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1042 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1044 #ifdef LDAP_CONNECTIONLESS
1045 /* Since this is connectionless, the data port is the
1046 * listening port. The listen() and accept() calls
1049 if ( slap_listeners[l]->sl_is_udp )
1051 slapd_add( slap_listeners[l]->sl_sd );
1056 if ( listen( slap_listeners[l]->sl_sd, SLAPD_LISTEN ) == -1 ) {
1057 int err = sock_errno();
1059 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1060 "slapd_daemon_task: listen( %s, 5 ) failed errno=%d (%s)\n",
1061 slap_listeners[l]->sl_url, err, sock_errstr(err) ));
1063 Debug( LDAP_DEBUG_ANY,
1064 "daemon: listen(%s, 5) failed errno=%d (%s)\n",
1065 slap_listeners[l]->sl_url, err,
1068 return( (void*)-1 );
1071 slapd_add( slap_listeners[l]->sl_sd );
1074 #ifdef HAVE_NT_SERVICE_MANAGER
1075 if ( started_event != NULL ) {
1076 ldap_pvt_thread_cond_signal( &started_event );
1079 /* initialization complete. Here comes the loop. */
1081 while ( !slapd_shutdown ) {
1086 #define SLAPD_EBADF_LIMIT 16
1090 #define SLAPD_IDLE_CHECK_LIMIT 4
1098 #if defined(SLAPD_RLOOKUPS)
1101 struct timeval zero;
1102 struct timeval *tvp;
1105 now = slap_get_time();
1106 connections_timeout_idle( now );
1108 else if ( global_idletimeout > 0 ) {
1109 now = slap_get_time();
1110 if ( difftime( last_idle_check+global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) {
1111 connections_timeout_idle( now );
1116 if( slapd_gentle_shutdown ) {
1117 ber_socket_t active;
1119 if( slapd_gentle_shutdown == 1 ) {
1120 Debug( LDAP_DEBUG_ANY, "slapd gentle shutdown\n", 0, 0, 0 );
1121 close_listeners( 1 );
1122 global_restrictops |= SLAP_RESTRICT_OP_WRITES;
1123 slapd_gentle_shutdown = 2;
1126 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1127 active = slap_daemon.sd_nactives;
1128 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1136 FD_ZERO( &writefds );
1137 FD_ZERO( &readfds );
1142 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1144 #ifdef FD_SET_MANUAL_COPY
1145 for( s = 0; s < nfds; s++ ) {
1146 if(FD_ISSET( &slap_sd_readers, s )) {
1147 FD_SET( s, &readfds );
1149 if(FD_ISSET( &slap_sd_writers, s )) {
1150 FD_SET( s, &writefds );
1154 AC_MEMCPY( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) );
1155 AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
1157 assert(!FD_ISSET(wake_sds[0], &readfds));
1158 FD_SET( wake_sds[0], &readfds );
1160 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1161 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1163 if (!FD_ISSET(slap_listeners[l]->sl_sd, &readfds))
1164 FD_SET( slap_listeners[l]->sl_sd, &readfds );
1167 #ifndef HAVE_WINSOCK
1168 nfds = slap_daemon.sd_nfds;
1173 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1175 at = ldap_pvt_thread_pool_backload(&connection_pool);
1177 #if defined( HAVE_YIELDING_SELECT ) || defined( NO_THREADS )
1180 tvp = at ? &zero : NULL;
1183 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1184 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1188 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1189 "slapd_daemon_task: select: listen=%d active_threads=%d tvp=%s\n",
1190 slap_listeners[l]->sl_sd, at, tvp == NULL ? "NULL" : "zero" ));
1192 Debug( LDAP_DEBUG_CONNS,
1193 "daemon: select: listen=%d active_threads=%d tvp=%s\n",
1194 slap_listeners[l]->sl_sd, at,
1195 tvp == NULL ? "NULL" : "zero" );
1199 switch(ns = select( nfds, &readfds,
1201 /* don't pass empty fd_set */
1202 ( writefds.fd_count > 0 ? &writefds : NULL ),
1208 case -1: { /* failure - try again */
1209 int err = sock_errno();
1213 /* you'd think this would be EBADF */
1214 || err == WSAENOTSOCK
1217 if (++ebadf < SLAPD_EBADF_LIMIT)
1221 if( err != EINTR ) {
1223 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1224 "slapd_daemon_task: select failed (%d): %s\n",
1225 err, sock_errstr(err) ));
1227 Debug( LDAP_DEBUG_CONNS,
1228 "daemon: select failed (%d): %s\n",
1229 err, sock_errstr(err), 0 );
1236 case 0: /* timeout - let threads run */
1239 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1240 "slapd_daemon_task: select timeout - yielding\n" ));
1242 Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n",
1245 ldap_pvt_thread_yield();
1248 default: /* something happened - deal with it */
1249 if( slapd_shutdown ) continue;
1253 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1254 "slapd_daemon_task: activity on %d descriptors\n", ns ));
1256 Debug( LDAP_DEBUG_CONNS, "daemon: activity on %d descriptors\n",
1262 if( FD_ISSET( wake_sds[0], &readfds ) ) {
1264 tcp_read( wake_sds[0], c, sizeof(c) );
1271 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1273 socklen_t len = sizeof(from);
1276 char *authid = NULL;
1278 char *dnsname = NULL;
1280 #ifdef LDAP_PF_LOCAL
1281 char peername[MAXPATHLEN + sizeof("PATH=")];
1282 #elif defined(LDAP_PF_INET6)
1283 char peername[sizeof("IP=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 65535")];
1285 char peername[sizeof("IP=255.255.255.255:65336")];
1286 #endif /* LDAP_PF_LOCAL */
1290 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1293 if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
1296 #ifdef LDAP_CONNECTIONLESS
1297 if ( slap_listeners[l]->sl_is_udp )
1299 /* The first time we receive a query, we set this
1300 * up as a "connection". It remains open for the life
1303 if ( slap_listeners[l]->sl_is_udp < 2 )
1305 id = connection_init(
1306 slap_listeners[l]->sl_sd,
1307 slap_listeners[l]->sl_url, "", "",
1308 slap_listeners[l]->sl_name,
1310 slap_listeners[l]->sl_is_udp++;
1316 s = accept( slap_listeners[l]->sl_sd,
1317 (struct sockaddr *) &from, &len );
1318 if ( s == AC_SOCKET_INVALID ) {
1319 int err = sock_errno();
1322 if( err == EMFILE ) {
1327 if( err == ENFILE ) {
1337 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1338 "slapd_daemon_task: accept(%ld) failed errno=%d (%s)\n",
1339 (long)slap_listeners[l]->sl_sd, err, sock_errstr(err) ));
1341 Debug( LDAP_DEBUG_ANY,
1342 "daemon: accept(%ld) failed errno=%d (%s)\n",
1343 (long) slap_listeners[l]->sl_sd, err,
1347 /* prevent busy loop */
1349 if( emfile % 4 == 3 ) usleep( 250 );
1351 if( emfile % 8 == 7 ) sleep( 1 );
1355 ldap_pvt_thread_yield();
1360 #ifndef HAVE_WINSOCK
1361 /* make sure descriptor number isn't too great */
1362 if ( s >= dtblsize ) {
1364 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1365 "slapd_daemon_task: %ld beyond descriptor table size %ld\n",
1366 (long)s, (long)dtblsize ));
1368 Debug( LDAP_DEBUG_ANY,
1369 "daemon: %ld beyond descriptor table size %ld\n",
1370 (long) s, (long) dtblsize, 0 );
1374 ldap_pvt_thread_yield();
1380 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1382 /* newly accepted stream should not be in any of the FD SETS */
1383 assert( !FD_ISSET( s, &slap_daemon.sd_actives) );
1384 assert( !FD_ISSET( s, &slap_daemon.sd_readers) );
1385 assert( !FD_ISSET( s, &slap_daemon.sd_writers) );
1387 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1390 #if defined( SO_KEEPALIVE ) || defined( TCP_NODELAY )
1391 #ifdef LDAP_PF_LOCAL
1392 /* for IPv4 and IPv6 sockets only */
1393 if ( from.sa_addr.sa_family != AF_LOCAL )
1394 #endif /* LDAP_PF_LOCAL */
1399 /* enable keep alives */
1401 rc = setsockopt( s, SOL_SOCKET, SO_KEEPALIVE,
1402 (char *) &tmp, sizeof(tmp) );
1403 if ( rc == AC_SOCKET_ERROR ) {
1404 int err = sock_errno();
1406 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1407 "slapd_daemon_task: setsockopt( %ld, SO_KEEPALIVE) failed errno=%d (%s)\n",
1408 (long)s, err, sock_errstr(err) ));
1410 Debug( LDAP_DEBUG_ANY,
1411 "slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
1412 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1417 /* enable no delay */
1419 rc = setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
1420 (char *)&tmp, sizeof(tmp) );
1421 if ( rc == AC_SOCKET_ERROR ) {
1422 int err = sock_errno();
1424 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1425 "slapd_daemon_task: setsockopt( %ld, TCP_NODELAY) failed errno=%d (%s)\n",
1426 (long)s, err, sock_errstr(err) ));
1428 Debug( LDAP_DEBUG_ANY,
1429 "slapd(%ld): setsockopt(TCP_NODELAY) failed "
1430 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1438 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL1,
1439 "slapd_daemon_task: new connection on %ld\n", (long)s ));
1441 Debug( LDAP_DEBUG_CONNS, "daemon: new connection on %ld\n",
1444 switch ( from.sa_addr.sa_family ) {
1445 # ifdef LDAP_PF_LOCAL
1447 sprintf( peername, "PATH=%s", from.sa_un_addr.sun_path );
1448 ssf = LDAP_PVT_SASL_LOCAL_SSF;
1451 #endif /* LDAP_PF_LOCAL */
1453 # ifdef LDAP_PF_INET6
1455 if ( IN6_IS_ADDR_V4MAPPED(&from.sa_in6_addr.sin6_addr) ) {
1456 peeraddr = inet_ntoa( *((struct in_addr *)
1457 &from.sa_in6_addr.sin6_addr.s6_addr[12]) );
1458 sprintf( peername, "IP=%s:%d",
1459 peeraddr != NULL ? peeraddr : "unknown",
1460 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1462 char addr[INET6_ADDRSTRLEN];
1463 sprintf( peername, "IP=%s %d",
1464 inet_ntop( AF_INET6,
1465 &from.sa_in6_addr.sin6_addr,
1466 addr, sizeof addr) ? addr : "unknown",
1467 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1470 # endif /* LDAP_PF_INET6 */
1473 peeraddr = inet_ntoa( from.sa_in_addr.sin_addr );
1474 sprintf( peername, "IP=%s:%d",
1475 peeraddr != NULL ? peeraddr : "unknown",
1476 (unsigned) ntohs( from.sa_in_addr.sin_port ) );
1484 if ( ( from.sa_addr.sa_family == AF_INET )
1485 #ifdef LDAP_PF_INET6
1486 || ( from.sa_addr.sa_family == AF_INET6 )
1489 #ifdef SLAPD_RLOOKUPS
1490 if ( use_reverse_lookup ) {
1491 # ifdef LDAP_PF_INET6
1492 if ( from.sa_addr.sa_family == AF_INET6 )
1494 (char *)&(from.sa_in6_addr.sin6_addr),
1495 sizeof(from.sa_in6_addr.sin6_addr),
1498 # endif /* LDAP_PF_INET6 */
1500 (char *) &(from.sa_in_addr.sin_addr),
1501 sizeof(from.sa_in_addr.sin_addr),
1503 dnsname = hp ? ldap_pvt_str2lower( hp->h_name ) : NULL;
1507 #endif /* SLAPD_RLOOKUPS */
1510 if ( !hosts_ctl("slapd",
1511 dnsname != NULL ? dnsname : STRING_UNKNOWN,
1512 peeraddr != NULL ? peeraddr : STRING_UNKNOWN,
1516 Statslog( LDAP_DEBUG_ANY,
1517 "fd=%ld host access from %s (%s) denied.\n",
1519 dnsname != NULL ? dnsname : "unknown",
1520 peeraddr != NULL ? peeraddr : "unknown",
1525 #endif /* HAVE_TCPD */
1528 id = connection_init(s,
1529 slap_listeners[l]->sl_url,
1530 dnsname != NULL ? dnsname : "unknown",
1532 slap_listeners[l]->sl_name,
1534 slap_listeners[l]->sl_is_tls,
1541 if( authid ) ch_free(authid);
1545 LDAP_LOG(( "connection", LDAP_LEVEL_INFO,
1546 "slapd_daemon_task: connection_init(%ld, %s, %s) failed.\n",
1547 (long)s, peername, slap_listeners[l]->sl_name ));
1549 Debug( LDAP_DEBUG_ANY,
1550 "daemon: connection_init(%ld, %s, %s) failed.\n",
1553 slap_listeners[l]->sl_name );
1559 Statslog( LDAP_DEBUG_STATS,
1560 "daemon: conn=%ld fd=%ld connection from %s (%s) accepted.\n",
1563 slap_listeners[l]->sl_name,
1572 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1573 "slapd_daemon_task: activity on " ));
1575 Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
1578 for ( i = 0; i < readfds.fd_count; i++ ) {
1580 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1581 " %d%s", readfds.fd_array[i], "r", 0 ));
1583 Debug( LDAP_DEBUG_CONNS, " %d%s",
1584 readfds.fd_array[i], "r", 0 );
1587 for ( i = 0; i < writefds.fd_count; i++ ) {
1589 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1590 " %d%s", writefds.fd_array[i], "w" ));
1592 Debug( LDAP_DEBUG_CONNS, " %d%s",
1593 writefds.fd_array[i], "w", 0 );
1598 for ( i = 0; i < nfds; i++ ) {
1600 int is_listener = 0;
1602 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1603 if ( i == slap_listeners[l]->sl_sd ) {
1604 #ifdef LDAP_CONNECTIONLESS
1605 /* The listener is the data port. Don't
1608 if (slap_listeners[l]->sl_is_udp)
1615 if ( is_listener ) {
1618 r = FD_ISSET( i, &readfds );
1619 w = FD_ISSET( i, &writefds );
1622 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1624 r ? "r" : "", w ? "w" : "" ));
1626 Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
1627 r ? "r" : "", w ? "w" : "" );
1633 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2, "\n" ));
1635 Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
1640 /* loop through the writers */
1642 for ( i = 0; i < writefds.fd_count; i++ )
1644 for ( i = 0; i < nfds; i++ )
1648 int is_listener = 0;
1650 wd = writefds.fd_array[i];
1652 if( ! FD_ISSET( i, &writefds ) ) {
1658 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1659 if ( i == slap_listeners[l]->sl_sd ) {
1660 #ifdef LDAP_CONNECTIONLESS
1661 if (slap_listeners[l]->sl_is_udp)
1668 if ( is_listener ) {
1672 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1673 "slapd_daemon_task: write active on %d\n", wd ));
1675 Debug( LDAP_DEBUG_CONNS,
1676 "daemon: write active on %d\n",
1680 * NOTE: it is possible that the connection was closed
1681 * and that the stream is now inactive.
1682 * connection_write() must valid the stream is still
1686 if ( connection_write( wd ) < 0 ) {
1687 FD_CLR( (unsigned) wd, &readfds );
1693 for ( i = 0; i < readfds.fd_count; i++ )
1695 for ( i = 0; i < nfds; i++ )
1699 int is_listener = 0;
1702 rd = readfds.fd_array[i];
1704 if( ! FD_ISSET( i, &readfds ) ) {
1710 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1711 if ( rd == slap_listeners[l]->sl_sd ) {
1712 #ifdef LDAP_CONNECTIONLESS
1713 if (slap_listeners[l]->sl_is_udp)
1720 if ( is_listener ) {
1725 LDAP_LOG(( "connection", LDAP_LEVEL_DETAIL2,
1726 "slapd_daemon_task: read activity on %d\n", rd ));
1728 Debug ( LDAP_DEBUG_CONNS,
1729 "daemon: read activity on %d\n", rd, 0, 0 );
1732 * NOTE: it is possible that the connection was closed
1733 * and that the stream is now inactive.
1734 * connection_read() must valid the stream is still
1738 if ( connection_read( rd ) < 0 ) {
1742 ldap_pvt_thread_yield();
1745 if( slapd_shutdown == 1 ) {
1747 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1748 "slapd_daemon_task: shutdown requested and initiated.\n"));
1750 Debug( LDAP_DEBUG_TRACE,
1751 "daemon: shutdown requested and initiated.\n",
1755 } else if ( slapd_shutdown == 2 ) {
1756 #ifdef HAVE_NT_SERVICE_MANAGER
1758 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1759 "slapd_daemon_task: shutdown initiated by Service Manager.\n"));
1761 Debug( LDAP_DEBUG_TRACE,
1762 "daemon: shutdown initiated by Service Manager.\n",
1765 #else /* !HAVE_NT_SERVICE_MANAGER */
1767 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1768 "slapd_daemon_task: abnormal condition, shutdown initiated.\n" ));
1770 Debug( LDAP_DEBUG_TRACE,
1771 "daemon: abnormal condition, shutdown initiated.\n",
1774 #endif /* !HAVE_NT_SERVICE_MANAGER */
1777 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1778 "slapd_daemon_task: no active streams, shutdown initiated.\n" ));
1780 Debug( LDAP_DEBUG_TRACE,
1781 "daemon: no active streams, shutdown initiated.\n",
1786 if( slapd_gentle_shutdown != 2 )
1787 close_listeners ( 0 );
1788 free ( slap_listeners );
1789 slap_listeners = NULL;
1792 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1793 "slapd_daemon_task: shutdown waiting for %d threads to terminate.\n",
1794 ldap_pvt_thread_pool_backload(&connection_pool) ));
1796 Debug( LDAP_DEBUG_ANY,
1797 "slapd shutdown: waiting for %d threads to terminate\n",
1798 ldap_pvt_thread_pool_backload(&connection_pool), 0, 0 );
1800 ldap_pvt_thread_pool_destroy(&connection_pool, 1);
1806 int slapd_daemon( void )
1812 #define SLAPD_LISTENER_THREAD 1
1813 #if defined( SLAPD_LISTENER_THREAD )
1815 ldap_pvt_thread_t listener_tid;
1817 /* listener as a separate THREAD */
1818 rc = ldap_pvt_thread_create( &listener_tid,
1819 0, slapd_daemon_task, NULL );
1823 LDAP_LOG(( "connection", LDAP_LEVEL_ERR,
1824 "slapd_daemon: listener ldap_pvt_thread_create failed (%d).\n", rc ));
1826 Debug( LDAP_DEBUG_ANY,
1827 "listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
1832 /* wait for the listener thread to complete */
1833 ldap_pvt_thread_join( listener_tid, (void *) NULL );
1836 /* experimental code */
1837 slapd_daemon_task( NULL );
1846 #if defined( HAVE_WINSOCK2 )
1847 WORD wVersionRequested;
1851 wVersionRequested = MAKEWORD( 2, 0 );
1853 err = WSAStartup( wVersionRequested, &wsaData );
1855 /* Tell the user that we couldn't find a usable */
1860 /* Confirm that the WinSock DLL supports 2.0.*/
1861 /* Note that if the DLL supports versions greater */
1862 /* than 2.0 in addition to 2.0, it will still return */
1863 /* 2.0 in wVersion since that is the version we */
1866 if ( LOBYTE( wsaData.wVersion ) != 2 ||
1867 HIBYTE( wsaData.wVersion ) != 0 )
1869 /* Tell the user that we couldn't find a usable */
1875 /* The WinSock DLL is acceptable. Proceed. */
1876 #elif defined( HAVE_WINSOCK )
1878 if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
1885 int sockdestroy(void)
1887 #if defined( HAVE_WINSOCK2 ) || defined( HAVE_WINSOCK )
1894 slap_sig_shutdown( int sig )
1897 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1898 "slap_sig_shutdown: signal %d\n", sig ));
1900 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
1904 * If the NT Service Manager is controlling the server, we don't
1905 * want SIGBREAK to kill the server. For some strange reason,
1906 * SIGBREAK is generated when a user logs out.
1909 #if HAVE_NT_SERVICE_MANAGER && SIGBREAK
1910 if (is_NT_Service && sig == SIGBREAK)
1912 LDAP_LOG(( "connection", LDAP_LEVEL_CRIT,
1913 "slap_sig_shutdown: SIGBREAK ignored.\n" ));
1915 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: SIGBREAK ignored.\n",
1921 if (sig == SIGHUP && global_gentlehup && slapd_gentle_shutdown == 0)
1922 slapd_gentle_shutdown = 1;
1929 /* reinstall self */
1930 (void) SIGNAL_REINSTALL( sig, slap_sig_shutdown );
1934 slap_sig_wake( int sig )
1938 /* reinstall self */
1939 (void) SIGNAL_REINSTALL( sig, slap_sig_wake );
1943 void slapd_add_internal(ber_socket_t s) {
1947 Listener ** slapd_get_listeners(void) {
1948 return slap_listeners;