2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
16 * All rights reserved.
18 * Redistribution and use in source and binary forms are permitted
19 * provided that this notice is preserved and that due credit is given
20 * to the University of Michigan at Ann Arbor. The name of the University
21 * may not be used to endorse or promote products derived from this
22 * software without specific prior written permission. This software
23 * is provided ``as is'' without express or implied warranty.
32 #include <ac/socket.h>
33 #include <ac/string.h>
35 #include <ac/unistd.h>
38 #include "ldap_pvt_thread.h"
45 #define SLAP_STRING_UNKNOWN STRING_UNKNOWN
47 int allow_severity = LOG_INFO;
48 int deny_severity = LOG_NOTICE;
49 #else /* ! TCP Wrappers */
50 #define SLAP_STRING_UNKNOWN "unknown"
51 #endif /* ! TCP Wrappers */
55 /* this should go in <ldap.h> as soon as it is accepted */
56 #define LDAPI_MOD_URLEXT "x-mod"
57 #endif /* LDAP_PF_LOCAL */
60 int slap_inet4or6 = AF_UNSPEC;
62 int slap_inet4or6 = AF_INET;
67 ber_socket_t dtblsize;
68 slap_ssf_t local_ssf = LDAP_PVT_SASL_LOCAL_SSF;
70 Listener **slap_listeners = NULL;
72 #define SLAPD_LISTEN 10
74 static ber_socket_t wake_sds[2];
78 #define WAKE_LISTENER(w) \
79 do { if (w && waking < 5) { tcp_write( wake_sds[1], "0", 1 ); waking++;} } while(0)
81 volatile sig_atomic_t slapd_shutdown = 0, slapd_gentle_shutdown = 0;
82 volatile sig_atomic_t slapd_abrupt_shutdown = 0;
84 static struct slap_daemon {
85 ldap_pvt_thread_mutex_t sd_mutex;
87 ber_socket_t sd_nactives;
90 /* In winsock, accept() returns values higher than dtblsize
91 so don't bother with this optimization */
105 * SLP related functions
109 #define LDAP_SRVTYPE_PREFIX "service:ldap://"
110 #define LDAPS_SRVTYPE_PREFIX "service:ldaps://"
111 static char** slapd_srvurls = NULL;
112 static SLPHandle slapd_hslp = 0;
113 int slapd_register_slp = 0;
115 void slapd_slp_init( const char* urls ) {
118 slapd_srvurls = ldap_str2charray( urls, " " );
120 if( slapd_srvurls == NULL ) return;
122 /* find and expand INADDR_ANY URLs */
123 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
124 if( strcmp( slapd_srvurls[i], "ldap:///" ) == 0) {
125 char *host = ldap_pvt_get_fqdn( NULL );
126 if ( host != NULL ) {
127 slapd_srvurls[i] = (char *) ch_realloc( slapd_srvurls[i],
129 sizeof( LDAP_SRVTYPE_PREFIX ) );
130 strcpy( lutil_strcopy(slapd_srvurls[i],
131 LDAP_SRVTYPE_PREFIX ), host );
136 } else if ( strcmp( slapd_srvurls[i], "ldaps:///" ) == 0) {
137 char *host = ldap_pvt_get_fqdn( NULL );
138 if ( host != NULL ) {
139 slapd_srvurls[i] = (char *) ch_realloc( slapd_srvurls[i],
141 sizeof( LDAPS_SRVTYPE_PREFIX ) );
142 strcpy( lutil_strcopy(slapd_srvurls[i],
143 LDAPS_SRVTYPE_PREFIX ), host );
150 /* open the SLP handle */
151 SLPOpen( "en", 0, &slapd_hslp );
154 void slapd_slp_deinit() {
155 if( slapd_srvurls == NULL ) return;
157 ldap_charray_free( slapd_srvurls );
158 slapd_srvurls = NULL;
160 /* close the SLP handle */
161 SLPClose( slapd_hslp );
164 void slapd_slp_regreport(
172 void slapd_slp_reg() {
175 if( slapd_srvurls == NULL ) return;
177 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
178 if( strncmp( slapd_srvurls[i], LDAP_SRVTYPE_PREFIX,
179 sizeof( LDAP_SRVTYPE_PREFIX ) - 1 ) == 0 ||
180 strncmp( slapd_srvurls[i], LDAPS_SRVTYPE_PREFIX,
181 sizeof( LDAPS_SRVTYPE_PREFIX ) - 1 ) == 0 )
185 SLP_LIFETIME_MAXIMUM,
195 void slapd_slp_dereg() {
198 if( slapd_srvurls == NULL ) return;
200 for( i=0; slapd_srvurls[i] != NULL; i++ ) {
201 SLPDereg( slapd_hslp,
207 #endif /* HAVE_SLP */
210 * Add a descriptor to daemon control
212 * If isactive, the descriptor is a live server session and is subject
213 * to idletimeout control. Otherwise, the descriptor is a passive
214 * listener or an outbound client session, and not subject to
217 static void slapd_add(ber_socket_t s, int isactive) {
218 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
220 assert( !FD_ISSET( s, &slap_daemon.sd_actives ));
221 assert( !FD_ISSET( s, &slap_daemon.sd_readers ));
222 assert( !FD_ISSET( s, &slap_daemon.sd_writers ));
225 if (s >= slap_daemon.sd_nfds) {
226 slap_daemon.sd_nfds = s + 1;
231 slap_daemon.sd_nactives++;
234 FD_SET( s, &slap_daemon.sd_actives );
235 FD_SET( s, &slap_daemon.sd_readers );
237 Debug( LDAP_DEBUG_CONNS, "daemon: added %ld%s%s\n",
239 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
240 FD_ISSET(s, &slap_daemon.sd_writers) ? "w" : "" );
241 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
245 * Remove the descriptor from daemon control
247 void slapd_remove(ber_socket_t s, int wasactive, int wake) {
249 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
252 slap_daemon.sd_nactives--;
254 waswriter = FD_ISSET(s, &slap_daemon.sd_writers);
256 Debug( LDAP_DEBUG_CONNS, "daemon: removing %ld%s%s\n",
258 FD_ISSET(s, &slap_daemon.sd_readers) ? "r" : "",
259 waswriter ? "w" : "" );
260 if ( waswriter ) slap_daemon.sd_nwriters--;
261 FD_CLR( s, &slap_daemon.sd_actives );
262 FD_CLR( s, &slap_daemon.sd_readers );
263 FD_CLR( s, &slap_daemon.sd_writers );
265 /* If we ran out of file descriptors, we dropped a listener from
266 * the select() loop. Now that we're removing a session from our
267 * control, we can try to resume a dropped listener to use.
271 for ( i = 0; slap_listeners[i] != NULL; i++ ) {
272 if ( slap_listeners[i]->sl_sd != AC_SOCKET_INVALID ) {
273 if ( slap_listeners[i]->sl_sd == s ) continue;
274 if ( slap_listeners[i]->sl_is_mute ) {
275 slap_listeners[i]->sl_is_mute = 0;
281 /* Walked the entire list without enabling anything; emfile
282 * counter is stale. Reset it.
284 if ( slap_listeners[i] == NULL )
287 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
288 WAKE_LISTENER(wake || slapd_gentle_shutdown == 2);
291 void slapd_clr_write(ber_socket_t s, int wake) {
292 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
294 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
295 if ( FD_ISSET( s, &slap_daemon.sd_writers )) {
296 FD_CLR( s, &slap_daemon.sd_writers );
297 slap_daemon.sd_nwriters--;
300 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
304 void slapd_set_write(ber_socket_t s, int wake) {
305 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
307 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
308 if (!FD_ISSET(s, &slap_daemon.sd_writers)) {
309 FD_SET( (unsigned) s, &slap_daemon.sd_writers );
310 slap_daemon.sd_nwriters++;
313 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
317 void slapd_clr_read(ber_socket_t s, int wake) {
318 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
320 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
321 FD_CLR( s, &slap_daemon.sd_readers );
323 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
327 void slapd_set_read(ber_socket_t s, int wake) {
328 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
330 assert( FD_ISSET( s, &slap_daemon.sd_actives) );
331 if (!FD_ISSET(s, &slap_daemon.sd_readers))
332 FD_SET( s, &slap_daemon.sd_readers );
334 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
338 static void slapd_close(ber_socket_t s) {
339 Debug( LDAP_DEBUG_CONNS, "daemon: closing %ld\n",
344 static void slap_free_listener_addresses(struct sockaddr **sal)
346 struct sockaddr **sap;
352 for (sap = sal; *sap != NULL; sap++) {
359 #if defined(LDAP_PF_LOCAL) || defined(SLAP_X_LISTENER_MOD)
360 static int get_url_perms(
372 for ( i = 0; exts[ i ]; i++ ) {
373 char *type = exts[ i ];
376 if ( type[ 0 ] == '!' ) {
381 if ( strncasecmp( type, LDAPI_MOD_URLEXT "=", sizeof(LDAPI_MOD_URLEXT "=") - 1 ) == 0 ) {
383 + ( sizeof(LDAPI_MOD_URLEXT "=") - 1 );
387 switch (strlen(value)) {
389 /* skip leading '0' */
390 if ( value[ 0 ] != '0' ) {
396 for ( j = 0; j < 3; j++) {
399 v = value[ j ] - '0';
401 if ( v < 0 || v > 7 ) {
410 for ( j = 1; j < 10; j++ ) {
411 static mode_t m[] = { 0,
412 S_IRUSR, S_IWUSR, S_IXUSR,
413 S_IRGRP, S_IWGRP, S_IXGRP,
414 S_IROTH, S_IWOTH, S_IXOTH
416 static char c[] = "-rwxrwxrwx";
418 if ( value[ j ] == c[ j ] ) {
421 } else if ( value[ j ] != '-' ) {
440 #endif /* LDAP_PF_LOCAL || SLAP_X_LISTENER_MOD */
442 /* port = 0 indicates AF_LOCAL */
443 static int slap_get_listener_addresses(
446 struct sockaddr ***sal)
448 struct sockaddr **sap;
452 *sal = ch_malloc(2 * sizeof(void *));
458 *sap = ch_malloc(sizeof(struct sockaddr_un));
464 (sizeof(((struct sockaddr_un *)*sap)->sun_path) - 1) ) {
465 Debug( LDAP_DEBUG_ANY,
466 "daemon: domain socket path (%s) too long in URL",
471 (void)memset( (void *)*sap, '\0', sizeof(struct sockaddr_un) );
472 (*sap)->sa_family = AF_LOCAL;
473 strcpy( ((struct sockaddr_un *)*sap)->sun_path, host );
477 #ifdef HAVE_GETADDRINFO
478 struct addrinfo hints, *res, *sai;
482 memset( &hints, '\0', sizeof(hints) );
483 hints.ai_flags = AI_PASSIVE;
484 hints.ai_socktype = SOCK_STREAM;
485 hints.ai_family = slap_inet4or6;
486 snprintf(serv, sizeof serv, "%d", port);
488 if ( (err = getaddrinfo(host, serv, &hints, &res)) ) {
489 Debug( LDAP_DEBUG_ANY, "daemon: getaddrinfo failed: %s\n",
490 AC_GAI_STRERROR(err), 0, 0);
495 for (n=2; (sai = sai->ai_next) != NULL; n++) {
498 *sal = ch_calloc(n, sizeof(void *));
506 for ( sai=res; sai; sai=sai->ai_next ) {
507 if( sai->ai_addr == NULL ) {
508 Debug( LDAP_DEBUG_ANY, "slap_get_listener_addresses: "
509 "getaddrinfo ai_addr is NULL?\n", 0, 0, 0 );
514 switch (sai->ai_family) {
515 # ifdef LDAP_PF_INET6
517 *sap = ch_malloc(sizeof(struct sockaddr_in6));
522 *(struct sockaddr_in6 *)*sap =
523 *((struct sockaddr_in6 *)sai->ai_addr);
527 *sap = ch_malloc(sizeof(struct sockaddr_in));
532 *(struct sockaddr_in *)*sap =
533 *((struct sockaddr_in *)sai->ai_addr);
541 (*sap)->sa_family = sai->ai_family;
551 struct hostent *he = NULL;
553 if ( host == NULL ) {
554 in.s_addr = htonl(INADDR_ANY);
556 } else if ( !inet_aton( host, &in ) ) {
557 he = gethostbyname( host );
559 Debug( LDAP_DEBUG_ANY,
560 "daemon: invalid host %s", host, 0, 0);
563 for (n = 0; he->h_addr_list[n]; n++) ;
566 *sal = ch_malloc((n+1) * sizeof(void *));
572 for ( i = 0; i<n; i++ ) {
573 sap[i] = ch_malloc(sizeof(struct sockaddr_in));
577 (void)memset( (void *)sap[i], '\0', sizeof(struct sockaddr_in) );
578 sap[i]->sa_family = AF_INET;
579 ((struct sockaddr_in *)sap[i])->sin_port = htons(port);
581 AC_MEMCPY( &((struct sockaddr_in *)sap[i])->sin_addr, he->h_addr_list[i], sizeof(struct in_addr) );
583 AC_MEMCPY( &((struct sockaddr_in *)sap[i])->sin_addr, &in, sizeof(struct in_addr) );
593 slap_free_listener_addresses(*sal);
597 static int slap_open_listener(
608 int err, addrlen = 0;
609 struct sockaddr **sal, **psal;
610 int socktype = SOCK_STREAM; /* default to COTS */
612 #if defined(LDAP_PF_LOCAL) || defined(SLAP_X_LISTENER_MOD)
617 #endif /* LDAP_PF_LOCAL || SLAP_X_LISTENER_MOD */
619 rc = ldap_url_parse( url, &lud );
621 if( rc != LDAP_URL_SUCCESS ) {
622 Debug( LDAP_DEBUG_ANY,
623 "daemon: listen URL \"%s\" parse error=%d\n",
628 l.sl_url.bv_val = NULL;
632 if( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) {
633 Debug( LDAP_DEBUG_ANY,
634 "daemon: TLS not supported (%s)\n",
636 ldap_free_urldesc( lud );
640 if(! lud->lud_port ) {
641 lud->lud_port = LDAP_PORT;
645 l.sl_is_tls = ldap_pvt_url_scheme2tls( lud->lud_scheme );
647 if(! lud->lud_port ) {
648 lud->lud_port = l.sl_is_tls ? LDAPS_PORT : LDAP_PORT;
652 port = (unsigned short) lud->lud_port;
654 tmp = ldap_pvt_url_scheme2proto(lud->lud_scheme);
655 if ( tmp == LDAP_PROTO_IPC ) {
657 if ( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) {
658 err = slap_get_listener_addresses(LDAPI_SOCK, 0, &sal);
660 err = slap_get_listener_addresses(lud->lud_host, 0, &sal);
664 Debug( LDAP_DEBUG_ANY, "daemon: URL scheme not supported: %s",
666 ldap_free_urldesc( lud );
670 if( lud->lud_host == NULL || lud->lud_host[0] == '\0'
671 || strcmp(lud->lud_host, "*") == 0 )
673 err = slap_get_listener_addresses(NULL, port, &sal);
675 err = slap_get_listener_addresses(lud->lud_host, port, &sal);
678 #ifdef LDAP_CONNECTIONLESS
679 l.sl_is_udp = ( tmp == LDAP_PROTO_UDP );
682 #if defined(LDAP_PF_LOCAL) || defined(SLAP_X_LISTENER_MOD)
683 if ( lud->lud_exts ) {
684 err = get_url_perms( lud->lud_exts, &l.sl_perms, &crit );
686 l.sl_perms = S_IRWXU | S_IRWXO;
688 #endif /* LDAP_PF_LOCAL || SLAP_X_LISTENER_MOD */
690 ldap_free_urldesc( lud );
695 /* If we got more than one address returned, we need to make space
696 * for it in the slap_listeners array.
698 for ( num=0; sal[num]; num++ );
701 slap_listeners = ch_realloc( slap_listeners, (*listeners + 1) * sizeof(Listener *) );
705 while ( *sal != NULL ) {
707 switch( (*sal)->sa_family ) {
725 #ifdef LDAP_CONNECTIONLESS
726 if( l.sl_is_udp ) socktype = SOCK_DGRAM;
728 l.sl_sd = socket( (*sal)->sa_family, socktype, 0);
729 if ( l.sl_sd == AC_SOCKET_INVALID ) {
730 int err = sock_errno();
731 Debug( LDAP_DEBUG_ANY,
732 "daemon: %s socket() failed errno=%d (%s)\n",
733 af, err, sock_errstr(err) );
738 if ( l.sl_sd >= dtblsize ) {
739 Debug( LDAP_DEBUG_ANY,
740 "daemon: listener descriptor %ld is too great %ld\n",
741 (long) l.sl_sd, (long) dtblsize, 0 );
742 tcp_close( l.sl_sd );
748 if ( (*sal)->sa_family == AF_LOCAL ) {
749 unlink ( ((struct sockaddr_un *)*sal)->sun_path );
754 /* enable address reuse */
756 rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
757 (char *) &tmp, sizeof(tmp) );
758 if ( rc == AC_SOCKET_ERROR ) {
759 int err = sock_errno();
760 Debug( LDAP_DEBUG_ANY,
761 "slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n",
762 (long) l.sl_sd, err, sock_errstr(err) );
767 switch( (*sal)->sa_family ) {
769 addrlen = sizeof(struct sockaddr_in);
774 /* Try to use IPv6 sockets for IPv6 only */
776 rc = setsockopt( l.sl_sd, IPPROTO_IPV6, IPV6_V6ONLY,
777 (char *) &tmp, sizeof(tmp) );
778 if ( rc == AC_SOCKET_ERROR ) {
779 int err = sock_errno();
780 Debug( LDAP_DEBUG_ANY,
781 "slapd(%ld): setsockopt(IPV6_V6ONLY) failed errno=%d (%s)\n",
782 (long) l.sl_sd, err, sock_errstr(err) );
785 addrlen = sizeof(struct sockaddr_in6);
790 addrlen = sizeof(struct sockaddr_un);
795 if (bind(l.sl_sd, *sal, addrlen)) {
797 Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n",
798 (long) l.sl_sd, err, sock_errstr(err) );
799 tcp_close( l.sl_sd );
804 switch ( (*sal)->sa_family ) {
807 char *addr = ((struct sockaddr_un *)*sal)->sun_path;
808 #if 0 /* don't muck with socket perms */
809 if ( chmod( addr, l.sl_perms ) < 0 && crit ) {
810 int err = sock_errno();
811 Debug( LDAP_DEBUG_ANY, "daemon: fchmod(%ld) failed errno=%d (%s)",
812 (long) l.sl_sd, err, sock_errstr(err) );
813 tcp_close( l.sl_sd );
814 slap_free_listener_addresses(psal);
818 l.sl_name.bv_len = strlen(addr) + sizeof("PATH=") - 1;
819 l.sl_name.bv_val = ber_memalloc( l.sl_name.bv_len + 1 );
820 snprintf( l.sl_name.bv_val, l.sl_name.bv_len + 1,
823 #endif /* LDAP_PF_LOCAL */
827 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
828 char addr[INET_ADDRSTRLEN];
829 inet_ntop( AF_INET, &((struct sockaddr_in *)*sal)->sin_addr,
830 addr, sizeof(addr) );
833 s = inet_ntoa( ((struct sockaddr_in *) *sal)->sin_addr );
835 port = ntohs( ((struct sockaddr_in *)*sal) ->sin_port );
836 l.sl_name.bv_val = ber_memalloc( sizeof("IP=255.255.255.255:65535") );
837 snprintf( l.sl_name.bv_val, sizeof("IP=255.255.255.255:65535"),
839 s != NULL ? s : SLAP_STRING_UNKNOWN, port );
840 l.sl_name.bv_len = strlen( l.sl_name.bv_val );
845 char addr[INET6_ADDRSTRLEN];
846 inet_ntop( AF_INET6, &((struct sockaddr_in6 *)*sal)->sin6_addr,
848 port = ntohs( ((struct sockaddr_in6 *)*sal)->sin6_port );
849 l.sl_name.bv_len = strlen(addr) + sizeof("IP= 65535");
850 l.sl_name.bv_val = ber_memalloc( l.sl_name.bv_len );
851 snprintf( l.sl_name.bv_val, l.sl_name.bv_len, "IP=%s %d",
853 l.sl_name.bv_len = strlen( l.sl_name.bv_val );
855 #endif /* LDAP_PF_INET6 */
858 Debug( LDAP_DEBUG_ANY, "daemon: unsupported address family (%d)\n",
859 (int) (*sal)->sa_family, 0, 0 );
863 AC_MEMCPY(&l.sl_sa, *sal, addrlen);
864 ber_str2bv( url, 0, 1, &l.sl_url);
865 li = ch_malloc( sizeof( Listener ) );
867 slap_listeners[*cur] = li;
871 } /* while ( *sal != NULL ) */
873 slap_free_listener_addresses(psal);
875 if ( l.sl_url.bv_val == NULL )
877 Debug( LDAP_DEBUG_TRACE,
878 "slap_open_listener: failed on %s\n", url, 0, 0 );
882 Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n",
883 l.sl_url.bv_val, 0, 0 );
887 static int sockinit(void);
888 static int sockdestroy(void);
890 int slapd_daemon_init( const char *urls )
895 Debug( LDAP_DEBUG_ARGS, "daemon_init: %s\n",
896 urls ? urls : "<null>", 0, 0 );
897 if( (rc = sockinit()) != 0 ) {
902 dtblsize = sysconf( _SC_OPEN_MAX );
903 #elif HAVE_GETDTABLESIZE
904 dtblsize = getdtablesize();
906 dtblsize = FD_SETSIZE;
910 if(dtblsize > FD_SETSIZE) {
911 dtblsize = FD_SETSIZE;
913 #endif /* !FD_SETSIZE */
915 /* open a pipe (or something equivalent connected to itself).
916 * we write a byte on this fd whenever we catch a signal. The main
917 * loop will be select'ing on this socket, and will wake up when
920 if( (rc = lutil_pair( wake_sds )) < 0 ) {
921 Debug( LDAP_DEBUG_ANY,
922 "daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 );
926 FD_ZERO( &slap_daemon.sd_readers );
927 FD_ZERO( &slap_daemon.sd_writers );
933 u = ldap_str2charray( urls, " " );
935 if( u == NULL || u[0] == NULL ) {
936 Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n",
941 for( i=0; u[i] != NULL; i++ ) {
942 Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n",
947 Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n",
949 ldap_charray_free( u );
953 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 ) ) {
959 ldap_charray_free( u );
963 slap_listeners[j] = NULL;
965 Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners opened\n",
969 if( slapd_register_slp ) {
970 slapd_slp_init( urls );
975 ldap_charray_free( u );
976 ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex );
982 slapd_daemon_destroy(void)
984 connections_destroy();
985 tcp_close( wake_sds[1] );
986 tcp_close( wake_sds[0] );
990 if( slapd_register_slp ) {
1007 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1008 if ( slap_listeners[l]->sl_sd != AC_SOCKET_INVALID ) {
1010 slapd_remove( slap_listeners[l]->sl_sd, 0, 0 );
1011 #ifdef LDAP_PF_LOCAL
1012 if ( slap_listeners[l]->sl_sa.sa_addr.sa_family == AF_LOCAL ) {
1013 unlink( slap_listeners[l]->sl_sa.sa_un_addr.sun_path );
1015 #endif /* LDAP_PF_LOCAL */
1016 slapd_close( slap_listeners[l]->sl_sd );
1018 if ( slap_listeners[l]->sl_url.bv_val )
1019 ber_memfree( slap_listeners[l]->sl_url.bv_val );
1020 if ( slap_listeners[l]->sl_name.bv_val )
1021 ber_memfree( slap_listeners[l]->sl_name.bv_val );
1022 free ( slap_listeners[l] );
1023 slap_listeners[l] = NULL;
1034 time_t last_idle_check = 0;
1035 struct timeval idle;
1037 #define SLAPD_IDLE_CHECK_LIMIT 4
1039 if ( global_idletimeout > 0 ) {
1040 last_idle_check = slap_get_time();
1041 /* Set the select timeout.
1042 * Don't just truncate, preserve the fractions of
1043 * seconds to prevent sleeping for zero time.
1045 idle.tv_sec = global_idletimeout/SLAPD_IDLE_CHECK_LIMIT;
1046 idle.tv_usec = global_idletimeout - idle.tv_sec * SLAPD_IDLE_CHECK_LIMIT;
1047 idle.tv_usec *= 1000000 / SLAPD_IDLE_CHECK_LIMIT;
1053 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1054 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1056 #ifdef LDAP_CONNECTIONLESS
1057 /* Since this is connectionless, the data port is the
1058 * listening port. The listen() and accept() calls
1061 if ( slap_listeners[l]->sl_is_udp ) {
1062 slapd_add( slap_listeners[l]->sl_sd, 1 );
1067 if ( listen( slap_listeners[l]->sl_sd, SLAPD_LISTEN ) == -1 ) {
1068 int err = sock_errno();
1070 #ifdef LDAP_PF_INET6
1071 /* If error is EADDRINUSE, we are trying to listen to INADDR_ANY and
1072 * we are already listening to in6addr_any, then we want to ignore
1073 * this and continue.
1075 if ( err == EADDRINUSE ) {
1077 struct sockaddr_in sa = slap_listeners[l]->sl_sa.sa_in_addr;
1078 struct sockaddr_in6 sa6;
1080 if ( sa.sin_family == AF_INET &&
1081 sa.sin_addr.s_addr == htonl(INADDR_ANY) ) {
1082 for ( i = 0 ; i < l; i++ ) {
1083 sa6 = slap_listeners[i]->sl_sa.sa_in6_addr;
1084 if ( sa6.sin6_family == AF_INET6 &&
1085 !memcmp( &sa6.sin6_addr, &in6addr_any, sizeof(struct in6_addr) ) )
1090 /* We are already listening to in6addr_any */
1091 Debug( LDAP_DEBUG_CONNS,
1092 "daemon: Attempt to listen to 0.0.0.0 failed, already listening on ::, assuming IPv4 included\n",
1094 slapd_close( slap_listeners[l]->sl_sd );
1095 slap_listeners[l]->sl_sd = AC_SOCKET_INVALID;
1101 Debug( LDAP_DEBUG_ANY,
1102 "daemon: listen(%s, 5) failed errno=%d (%s)\n",
1103 slap_listeners[l]->sl_url.bv_val, err,
1105 return( (void*)-1 );
1108 slapd_add( slap_listeners[l]->sl_sd, 0 );
1111 #ifdef HAVE_NT_SERVICE_MANAGER
1112 if ( started_event != NULL ) {
1113 ldap_pvt_thread_cond_signal( &started_event );
1116 /* initialization complete. Here comes the loop. */
1118 while ( !slapd_shutdown ) {
1122 ber_socket_t nfds, nrfds, nwfds;
1123 #define SLAPD_EBADF_LIMIT 16
1133 struct timeval *tvp;
1135 struct timeval *cat;
1138 now = slap_get_time();
1140 if( ( global_idletimeout > 0 ) &&
1141 difftime( last_idle_check +
1142 global_idletimeout/SLAPD_IDLE_CHECK_LIMIT, now ) < 0 ) {
1143 connections_timeout_idle( now );
1144 last_idle_check = now;
1149 if( slapd_gentle_shutdown ) {
1150 ber_socket_t active;
1152 if( slapd_gentle_shutdown == 1 ) {
1153 Debug( LDAP_DEBUG_ANY, "slapd gentle shutdown\n", 0, 0, 0 );
1154 close_listeners( 1 );
1155 frontendDB->be_restrictops |= SLAP_RESTRICT_OP_WRITES;
1156 slapd_gentle_shutdown = 2;
1159 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1160 active = slap_daemon.sd_nactives;
1161 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1171 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1173 nwriters = slap_daemon.sd_nwriters;
1174 AC_MEMCPY( &readfds, &slap_daemon.sd_readers, sizeof(fd_set) );
1176 AC_MEMCPY( &writefds, &slap_daemon.sd_writers, sizeof(fd_set) );
1177 assert(!FD_ISSET(wake_sds[0], &readfds));
1178 FD_SET( wake_sds[0], &readfds );
1180 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1181 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1183 if ( slap_listeners[l]->sl_is_mute )
1184 FD_CLR( slap_listeners[l]->sl_sd, &readfds );
1186 if (!FD_ISSET(slap_listeners[l]->sl_sd, &readfds))
1187 FD_SET( slap_listeners[l]->sl_sd, &readfds );
1190 #ifndef HAVE_WINSOCK
1191 nfds = slap_daemon.sd_nfds;
1195 if ( global_idletimeout && slap_daemon.sd_nactives )
1198 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1201 #if defined(HAVE_YIELDING_SELECT) || defined(NO_THREADS)
1202 && ( tv.tv_sec || tv.tv_usec )
1209 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
1210 rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
1211 while ( cat && cat->tv_sec && cat->tv_sec <= now ) {
1212 if ( ldap_pvt_runqueue_isrunning( &syncrepl_rq, rtask )) {
1213 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
1215 ldap_pvt_runqueue_runtask( &syncrepl_rq, rtask );
1216 ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
1217 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
1218 ldap_pvt_thread_pool_submit( &connection_pool,
1219 rtask->routine, (void *) rtask );
1220 ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
1222 rtask = ldap_pvt_runqueue_next_sched( &syncrepl_rq, &cat );
1224 ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
1226 if ( cat != NULL ) {
1227 time_t diff = difftime( cat->tv_sec, now );
1230 if ( tvp == NULL || diff < tv.tv_sec ) {
1237 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1238 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ||
1239 slap_listeners[l]->sl_is_mute )
1242 Debug( LDAP_DEBUG_CONNS,
1243 "daemon: select: listen=%d active_threads=%d tvp=%s\n",
1244 slap_listeners[l]->sl_sd, at,
1245 tvp == NULL ? "NULL" : "zero" );
1248 switch(ns = select( nfds, &readfds, nwriters > 0 ? &writefds : NULL,
1251 case -1: { /* failure - try again */
1252 int err = sock_errno();
1256 /* you'd think this would be EBADF */
1257 || err == WSAENOTSOCK
1260 if (++ebadf < SLAPD_EBADF_LIMIT)
1264 if( err != EINTR ) {
1265 Debug( LDAP_DEBUG_CONNS,
1266 "daemon: select failed (%d): %s\n",
1267 err, sock_errstr(err), 0 );
1273 case 0: /* timeout - let threads run */
1275 Debug( LDAP_DEBUG_CONNS, "daemon: select timeout - yielding\n",
1278 ldap_pvt_thread_yield();
1281 default: /* something happened - deal with it */
1282 if( slapd_shutdown ) continue;
1285 Debug( LDAP_DEBUG_CONNS, "daemon: activity on %d descriptors\n",
1290 if( FD_ISSET( wake_sds[0], &readfds ) ) {
1292 tcp_read( wake_sds[0], c, sizeof(c) );
1298 for ( l = 0; slap_listeners[l] != NULL; l++ ) {
1300 socklen_t len = sizeof(from);
1303 struct berval authid = BER_BVNULL;
1304 #ifdef SLAPD_RLOOKUPS
1305 char hbuf[NI_MAXHOST];
1308 char *dnsname = NULL;
1309 char *peeraddr = NULL;
1310 #ifdef LDAP_PF_LOCAL
1311 char peername[MAXPATHLEN + sizeof("PATH=")];
1312 #elif defined(LDAP_PF_INET6)
1313 char peername[sizeof(
1314 "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 ( ns <= 0 ) break;
1323 if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
1326 if ( !FD_ISSET( slap_listeners[l]->sl_sd, &readfds ) )
1331 #ifdef LDAP_CONNECTIONLESS
1332 if ( slap_listeners[l]->sl_is_udp ) {
1333 /* The first time we receive a query, we set this
1334 * up as a "connection". It remains open for the life
1337 if ( slap_listeners[l]->sl_is_udp < 2 ) {
1338 id = connection_init(
1339 slap_listeners[l]->sl_sd,
1340 slap_listeners[l], "", "",
1341 CONN_IS_UDP, ssf, NULL );
1342 slap_listeners[l]->sl_is_udp++;
1348 /* Don't need to look at this in the data loops */
1349 FD_CLR( slap_listeners[l]->sl_sd, &readfds );
1350 FD_CLR( slap_listeners[l]->sl_sd, &writefds );
1352 # ifdef LDAP_PF_LOCAL
1353 /* FIXME: apparently accept doesn't fill
1354 * the sun_path sun_path member */
1355 from.sa_un_addr.sun_path[0] = '\0';
1356 # endif /* LDAP_PF_LOCAL */
1357 s = accept( slap_listeners[l]->sl_sd,
1358 (struct sockaddr *) &from, &len );
1359 if ( s == AC_SOCKET_INVALID ) {
1360 int err = sock_errno();
1371 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1373 /* Stop listening until an existing session closes */
1374 slap_listeners[l]->sl_is_mute = 1;
1375 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1378 Debug( LDAP_DEBUG_ANY,
1379 "daemon: accept(%ld) failed errno=%d (%s)\n",
1380 (long) slap_listeners[l]->sl_sd, err,
1382 ldap_pvt_thread_yield();
1386 #ifndef HAVE_WINSOCK
1387 /* make sure descriptor number isn't too great */
1388 if ( s >= dtblsize ) {
1389 Debug( LDAP_DEBUG_ANY,
1390 "daemon: %ld beyond descriptor table size %ld\n",
1391 (long) s, (long) dtblsize, 0 );
1394 ldap_pvt_thread_yield();
1400 ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
1402 /* newly accepted stream should not be in any of the FD SETS */
1403 assert( !FD_ISSET( s, &slap_daemon.sd_actives) );
1404 assert( !FD_ISSET( s, &slap_daemon.sd_readers) );
1405 assert( !FD_ISSET( s, &slap_daemon.sd_writers) );
1407 ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
1410 #if defined( SO_KEEPALIVE ) || defined( TCP_NODELAY )
1411 #ifdef LDAP_PF_LOCAL
1412 /* for IPv4 and IPv6 sockets only */
1413 if ( from.sa_addr.sa_family != AF_LOCAL )
1414 #endif /* LDAP_PF_LOCAL */
1419 /* enable keep alives */
1421 rc = setsockopt( s, SOL_SOCKET, SO_KEEPALIVE,
1422 (char *) &tmp, sizeof(tmp) );
1423 if ( rc == AC_SOCKET_ERROR ) {
1424 int err = sock_errno();
1425 Debug( LDAP_DEBUG_ANY,
1426 "slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
1427 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1431 /* enable no delay */
1433 rc = setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
1434 (char *)&tmp, sizeof(tmp) );
1435 if ( rc == AC_SOCKET_ERROR ) {
1436 int err = sock_errno();
1437 Debug( LDAP_DEBUG_ANY,
1438 "slapd(%ld): setsockopt(TCP_NODELAY) failed "
1439 "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
1445 Debug( LDAP_DEBUG_CONNS, "daemon: new connection on %ld\n",
1447 switch ( from.sa_addr.sa_family ) {
1448 # ifdef LDAP_PF_LOCAL
1450 /* FIXME: apparently accept doesn't fill
1451 * the sun_path sun_path member */
1452 if ( from.sa_un_addr.sun_path[0] == '\0' ) {
1453 AC_MEMCPY( from.sa_un_addr.sun_path,
1454 slap_listeners[l]->sl_sa.sa_un_addr.sun_path,
1455 sizeof( from.sa_un_addr.sun_path ) );
1458 sprintf( peername, "PATH=%s", from.sa_un_addr.sun_path );
1464 if( getpeereid( s, &uid, &gid ) == 0 ) {
1465 authid.bv_val = ch_malloc(
1466 sizeof("uidnumber=4294967295+gidnumber=4294967295,"
1467 "cn=peercred,cn=external,cn=auth"));
1468 authid.bv_len = sprintf( authid.bv_val,
1469 "uidnumber=%d+gidnumber=%d,"
1470 "cn=peercred,cn=external,cn=auth",
1471 (int) uid, (int) gid);
1476 #endif /* LDAP_PF_LOCAL */
1478 # ifdef LDAP_PF_INET6
1480 if ( IN6_IS_ADDR_V4MAPPED(&from.sa_in6_addr.sin6_addr) ) {
1481 peeraddr = inet_ntoa( *((struct in_addr *)
1482 &from.sa_in6_addr.sin6_addr.s6_addr[12]) );
1483 sprintf( peername, "IP=%s:%d",
1484 peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN,
1485 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1487 char addr[INET6_ADDRSTRLEN];
1489 peeraddr = (char *) inet_ntop( AF_INET6,
1490 &from.sa_in6_addr.sin6_addr,
1491 addr, sizeof addr );
1492 sprintf( peername, "IP=%s %d",
1493 peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN,
1494 (unsigned) ntohs( from.sa_in6_addr.sin6_port ) );
1497 # endif /* LDAP_PF_INET6 */
1500 peeraddr = inet_ntoa( from.sa_in_addr.sin_addr );
1501 sprintf( peername, "IP=%s:%d",
1502 peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN,
1503 (unsigned) ntohs( from.sa_in_addr.sin_port ) );
1511 if ( ( from.sa_addr.sa_family == AF_INET )
1512 #ifdef LDAP_PF_INET6
1513 || ( from.sa_addr.sa_family == AF_INET6 )
1516 #ifdef SLAPD_RLOOKUPS
1517 if ( use_reverse_lookup ) {
1519 if (ldap_pvt_get_hname( (const struct sockaddr *)&from, len, hbuf,
1520 sizeof(hbuf), &herr ) == 0) {
1521 ldap_pvt_str2lower( hbuf );
1527 #endif /* SLAPD_RLOOKUPS */
1530 if ( !hosts_ctl("slapd",
1531 dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
1532 peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN,
1533 SLAP_STRING_UNKNOWN ))
1536 Statslog( LDAP_DEBUG_STATS,
1537 "fd=%ld DENIED from %s (%s)\n",
1539 dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
1540 peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN,
1545 #endif /* HAVE_TCPD */
1548 id = connection_init(s,
1550 dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
1553 slap_listeners[l]->sl_is_tls ? CONN_IS_TLS : 0,
1558 authid.bv_val ? &authid : NULL );
1560 if( authid.bv_val ) ch_free(authid.bv_val);
1563 Debug( LDAP_DEBUG_ANY,
1564 "daemon: connection_init(%ld, %s, %s) "
1568 slap_listeners[l]->sl_name.bv_val );
1573 Statslog( LDAP_DEBUG_STATS,
1574 "conn=%ld fd=%ld ACCEPT from %s (%s)\n",
1577 slap_listeners[l]->sl_name.bv_val,
1584 /* bypass the following tests if no descriptors left */
1586 ldap_pvt_thread_yield();
1590 Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
1592 nrfds = readfds.fd_count;
1593 nwfds = writefds.fd_count;
1594 for ( i = 0; i < readfds.fd_count; i++ ) {
1595 Debug( LDAP_DEBUG_CONNS, " %d%s",
1596 readfds.fd_array[i], "r", 0 );
1598 for ( i = 0; i < writefds.fd_count; i++ ) {
1599 Debug( LDAP_DEBUG_CONNS, " %d%s",
1600 writefds.fd_array[i], "w", 0 );
1606 for ( i = 0; i < nfds; i++ ) {
1609 r = FD_ISSET( i, &readfds );
1610 w = FD_ISSET( i, &writefds );
1612 Debug( LDAP_DEBUG_CONNS, " %d%s%s", i,
1613 r ? "r" : "", w ? "w" : "" );
1623 if ( ns <= 0 ) break;
1626 Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
1629 /* loop through the writers */
1630 for ( i = 0; nwfds > 0; i++ )
1634 wd = writefds.fd_array[i];
1636 if( ! FD_ISSET( i, &writefds ) ) {
1643 Debug( LDAP_DEBUG_CONNS,
1644 "daemon: write active on %d\n",
1647 * NOTE: it is possible that the connection was closed
1648 * and that the stream is now inactive.
1649 * connection_write() must valid the stream is still
1653 if ( connection_write( wd ) < 0 ) {
1654 if ( FD_ISSET( wd, &readfds )) {
1655 FD_CLR( (unsigned) wd, &readfds );
1662 for ( i = 0; nrfds > 0; i++ )
1666 rd = readfds.fd_array[i];
1668 if( ! FD_ISSET( i, &readfds ) ) {
1675 Debug ( LDAP_DEBUG_CONNS,
1676 "daemon: read activity on %d\n", rd, 0, 0 );
1678 * NOTE: it is possible that the connection was closed
1679 * and that the stream is now inactive.
1680 * connection_read() must valid the stream is still
1684 if ( connection_read( rd ) < 0 ) {
1688 ldap_pvt_thread_yield();
1691 if( slapd_shutdown == 1 ) {
1692 Debug( LDAP_DEBUG_TRACE,
1693 "daemon: shutdown requested and initiated.\n",
1696 } else if ( slapd_shutdown == 2 ) {
1697 #ifdef HAVE_NT_SERVICE_MANAGER
1698 Debug( LDAP_DEBUG_TRACE,
1699 "daemon: shutdown initiated by Service Manager.\n",
1701 #else /* !HAVE_NT_SERVICE_MANAGER */
1702 Debug( LDAP_DEBUG_TRACE,
1703 "daemon: abnormal condition, shutdown initiated.\n",
1705 #endif /* !HAVE_NT_SERVICE_MANAGER */
1707 Debug( LDAP_DEBUG_TRACE,
1708 "daemon: no active streams, shutdown initiated.\n",
1712 if( slapd_gentle_shutdown != 2 ) {
1713 close_listeners ( 0 );
1716 free ( slap_listeners );
1717 slap_listeners = NULL;
1719 if( !slapd_gentle_shutdown ) {
1720 slapd_abrupt_shutdown = 1;
1721 connections_shutdown();
1724 Debug( LDAP_DEBUG_ANY,
1725 "slapd shutdown: waiting for %d threads to terminate\n",
1726 ldap_pvt_thread_pool_backload(&connection_pool), 0, 0 );
1727 ldap_pvt_thread_pool_destroy(&connection_pool, 1);
1733 int slapd_daemon( void )
1739 #define SLAPD_LISTENER_THREAD 1
1740 #if defined( SLAPD_LISTENER_THREAD )
1742 ldap_pvt_thread_t listener_tid;
1744 /* listener as a separate THREAD */
1745 rc = ldap_pvt_thread_create( &listener_tid,
1746 0, slapd_daemon_task, NULL );
1749 Debug( LDAP_DEBUG_ANY,
1750 "listener ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
1754 /* wait for the listener thread to complete */
1755 ldap_pvt_thread_join( listener_tid, (void *) NULL );
1758 /* experimental code */
1759 slapd_daemon_task( NULL );
1768 #if defined( HAVE_WINSOCK2 )
1769 WORD wVersionRequested;
1773 wVersionRequested = MAKEWORD( 2, 0 );
1775 err = WSAStartup( wVersionRequested, &wsaData );
1777 /* Tell the user that we couldn't find a usable */
1782 /* Confirm that the WinSock DLL supports 2.0.*/
1783 /* Note that if the DLL supports versions greater */
1784 /* than 2.0 in addition to 2.0, it will still return */
1785 /* 2.0 in wVersion since that is the version we */
1788 if ( LOBYTE( wsaData.wVersion ) != 2 ||
1789 HIBYTE( wsaData.wVersion ) != 0 )
1791 /* Tell the user that we couldn't find a usable */
1797 /* The WinSock DLL is acceptable. Proceed. */
1798 #elif defined( HAVE_WINSOCK )
1800 if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
1807 int sockdestroy(void)
1809 #if defined( HAVE_WINSOCK2 ) || defined( HAVE_WINSOCK )
1816 slap_sig_shutdown( int sig )
1819 Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
1823 * If the NT Service Manager is controlling the server, we don't
1824 * want SIGBREAK to kill the server. For some strange reason,
1825 * SIGBREAK is generated when a user logs out.
1828 #if HAVE_NT_SERVICE_MANAGER && SIGBREAK
1829 if (is_NT_Service && sig == SIGBREAK)
1834 if (sig == SIGHUP && global_gentlehup && slapd_gentle_shutdown == 0)
1835 slapd_gentle_shutdown = 1;
1841 /* reinstall self */
1842 (void) SIGNAL_REINSTALL( sig, slap_sig_shutdown );
1846 slap_sig_wake( int sig )
1850 /* reinstall self */
1851 (void) SIGNAL_REINSTALL( sig, slap_sig_wake );
1855 void slapd_add_internal(ber_socket_t s, int isactive) {
1856 slapd_add(s, isactive);
1859 Listener ** slapd_get_listeners(void) {
1860 return slap_listeners;
1863 void slap_wake_listener()