2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2010 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.
31 #include <ac/socket.h>
32 #include <ac/string.h>
34 #include <ac/unistd.h>
43 #include "slapi/slapi.h"
47 static RETSIGTYPE wait4child( int sig );
50 #ifdef HAVE_NT_SERVICE_MANAGER
51 #define MAIN_RETURN(x) return
52 static struct sockaddr_in bind_addr;
54 #define SERVICE_EXIT( e, n ) do { \
55 if ( is_NT_Service ) { \
56 lutil_ServiceStatus.dwWin32ExitCode = (e); \
57 lutil_ServiceStatus.dwServiceSpecificExitCode = (n); \
62 #define SERVICE_EXIT( e, n )
63 #define MAIN_RETURN(x) return(x)
66 typedef int (MainFunc) LDAP_P(( int argc, char *argv[] ));
67 extern MainFunc slapadd, slapcat, slapdn, slapindex, slappasswd,
68 slaptest, slapauth, slapacl, slapschema, slapmodify;
77 {"slapindex", slapindex},
78 {"slapmodify", slapmodify},
79 {"slappasswd", slappasswd},
80 {"slapschema", slapschema},
81 {"slaptest", slaptest},
82 {"slapauth", slapauth},
84 /* NOTE: new tools must be added in chronological order,
85 * not in alphabetical order, because for backwards
86 * compatibility name[4] is used to identify the
87 * tools; so name[4]=='a' must refer to "slapadd" and
88 * not to "slapauth". Alphabetical order can be used
89 * for tools whose name[4] is not used yet */
94 * when more than one slapd is running on one machine, each one might have
95 * it's own LOCAL for syslogging and must have its own pid/args files
98 #ifndef HAVE_MKVERSION
99 const char Versionstr[] =
100 OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
103 #define CHECK_NONE 0x00
104 #define CHECK_CONFIG 0x01
105 #define CHECK_LOGLEVEL 0x02
106 static int check = CHECK_NONE;
107 static int version = 0;
113 slapd_opt_slp( const char *val, void *arg )
116 /* NULL is default */
117 if ( val == NULL || *val == '(' || strcasecmp( val, "on" ) == 0 ) {
118 slapd_register_slp = 1;
119 slapd_slp_attrs = (val != NULL && *val == '(') ? val : NULL;
121 } else if ( strcasecmp( val, "off" ) == 0 ) {
122 slapd_register_slp = 0;
124 /* NOTE: add support for URL specification? */
127 fprintf(stderr, "unrecognized value \"%s\" for SLP option\n", val );
134 fputs( "slapd: SLP support is not available\n", stderr );
140 * Option helper structure:
142 * oh_nam is left-hand part of <option>[=<value>]
143 * oh_fnc is handler function
144 * oh_arg is an optional arg to oh_fnc
145 * oh_usage is the one-line usage string related to the option,
146 * which is assumed to start with <option>[=<value>]
148 * please leave valid options in the structure, and optionally #ifdef
149 * their processing inside the helper, so that reasonable and helpful
150 * error messages can be generated if a disabled option is requested.
152 struct option_helper {
153 struct berval oh_name;
154 int (*oh_fnc)(const char *val, void *arg);
156 const char *oh_usage;
157 } option_helpers[] = {
158 { BER_BVC("slp"), slapd_opt_slp, NULL, "slp[={on|off|(attrs)}] enable/disable SLP using (attrs)" },
159 { BER_BVNULL, 0, NULL, NULL }
162 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
165 parse_syslog_user( const char *arg, int *syslogUser )
167 static slap_verbmasks syslogUsers[] = {
168 { BER_BVC( "LOCAL0" ), LOG_LOCAL0 },
169 { BER_BVC( "LOCAL1" ), LOG_LOCAL1 },
170 { BER_BVC( "LOCAL2" ), LOG_LOCAL2 },
171 { BER_BVC( "LOCAL3" ), LOG_LOCAL3 },
172 { BER_BVC( "LOCAL4" ), LOG_LOCAL4 },
173 { BER_BVC( "LOCAL5" ), LOG_LOCAL5 },
174 { BER_BVC( "LOCAL6" ), LOG_LOCAL6 },
175 { BER_BVC( "LOCAL7" ), LOG_LOCAL7 },
177 { BER_BVC( "USER" ), LOG_USER },
178 #endif /* LOG_USER */
180 { BER_BVC( "DAEMON" ), LOG_DAEMON },
181 #endif /* LOG_DAEMON */
184 int i = verb_to_mask( arg, syslogUsers );
186 if ( BER_BVISNULL( &syslogUsers[ i ].word ) ) {
187 Debug( LDAP_DEBUG_ANY,
188 "unrecognized syslog user \"%s\".\n",
193 *syslogUser = syslogUsers[ i ].mask;
197 #endif /* LOG_LOCAL4 */
200 parse_syslog_level( const char *arg, int *levelp )
202 static slap_verbmasks str2syslog_level[] = {
203 { BER_BVC( "EMERG" ), LOG_EMERG },
204 { BER_BVC( "ALERT" ), LOG_ALERT },
205 { BER_BVC( "CRIT" ), LOG_CRIT },
206 { BER_BVC( "ERR" ), LOG_ERR },
207 { BER_BVC( "WARNING" ), LOG_WARNING },
208 { BER_BVC( "NOTICE" ), LOG_NOTICE },
209 { BER_BVC( "INFO" ), LOG_INFO },
210 { BER_BVC( "DEBUG" ), LOG_DEBUG },
213 int i = verb_to_mask( arg, str2syslog_level );
214 if ( BER_BVISNULL( &str2syslog_level[ i ].word ) ) {
215 Debug( LDAP_DEBUG_ANY,
216 "unknown syslog level \"%s\".\n",
221 *levelp = str2syslog_level[ i ].mask;
225 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
228 parse_debug_unknowns( char **unknowns, int *levelp )
230 int i, level, rc = 0;
232 for ( i = 0; unknowns[ i ] != NULL; i++ ) {
234 if ( str2loglevel( unknowns[ i ], &level )) {
236 "unrecognized log level \"%s\"\n", unknowns[ i ] );
246 parse_debug_level( const char *arg, int *levelp, char ***unknowns )
250 if ( arg && arg[ 0 ] != '-' && !isdigit( (unsigned char) arg[ 0 ] ) )
255 levels = ldap_str2charray( arg, "," );
257 for ( i = 0; levels[ i ] != NULL; i++ ) {
260 if ( str2loglevel( levels[ i ], &level ) ) {
261 /* remember this for later */
262 ldap_charray_add( unknowns, levels[ i ] );
264 "unrecognized log level \"%s\" (deferred)\n",
271 ldap_charray_free( levels );
276 if ( arg[0] == '-' ) {
277 rc = lutil_atoix( &level, arg, 0 );
281 rc = lutil_atoux( &ulevel, arg, 0 );
287 "unrecognized log level "
307 "usage: %s options\n", name );
309 "\t-4\t\tIPv4 only\n"
310 "\t-6\t\tIPv6 only\n"
311 "\t-T {acl|add|auth|cat|dn|index|modify|passwd|test}\n"
312 "\t\t\tRun in Tool mode\n"
313 "\t-c cookie\tSync cookie of consumer\n"
314 "\t-d level\tDebug level" "\n"
315 "\t-f filename\tConfiguration file\n"
316 "\t-F dir\tConfiguration directory\n"
317 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
318 "\t-g group\tGroup (id or name) to run as\n"
320 "\t-h URLs\t\tList of URLs to serve\n"
321 #ifdef SLAP_DEFAULT_SYSLOG_USER
322 "\t-l facility\tSyslog facility (default: LOCAL4)\n"
324 "\t-n serverName\tService name\n"
325 "\t-o <opt>[=val] generic means to specify options" );
326 if ( !BER_BVISNULL( &option_helpers[0].oh_name ) ) {
329 fprintf( stderr, "; supported options:\n" );
330 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++) {
331 fprintf( stderr, "\t\t%s\n", option_helpers[i].oh_usage );
334 fprintf( stderr, "\n" );
338 "\t-r directory\tSandbox directory to chroot to\n"
340 "\t-s level\tSyslog level\n"
341 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
342 "\t-u user\t\tUser (id or name) to run as\n"
344 "\t-V\t\tprint version info (-VV only)\n"
348 #ifdef HAVE_NT_SERVICE_MANAGER
349 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
351 int main( int argc, char **argv )
354 int i, no_detach = 0;
357 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
358 char *username = NULL;
359 char *groupname = NULL;
361 #if defined(HAVE_CHROOT)
362 char *sandbox = NULL;
364 #ifdef SLAP_DEFAULT_SYSLOG_USER
365 int syslogUser = SLAP_DEFAULT_SYSLOG_USER;
369 char **g_argv = argv;
371 char *configfile = NULL;
372 char *configdir = NULL;
374 int serverMode = SLAP_SERVER_MODE;
376 struct sync_cookie *scp = NULL;
377 struct sync_cookie *scp_entry = NULL;
379 char **debug_unknowns = NULL;
380 char **syslog_unknowns = NULL;
382 char *serverNamePrefix = "";
385 int slapd_pid_file_unlink = 0, slapd_args_file_unlink = 0;
390 if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
397 (void) ldap_pvt_thread_initialize();
399 serverName = lutil_progname( "slapd", argc, argv );
401 if ( strcmp( serverName, "slapd" ) ) {
402 for (i=0; tools[i].name; i++) {
403 if ( !strcmp( serverName, tools[i].name ) ) {
404 rc = tools[i].func(argc, argv);
410 #ifdef HAVE_NT_SERVICE_MANAGER
416 char *regService = NULL;
418 if ( is_NT_Service ) {
419 lutil_CommenceStartupProcessing( serverName, slap_sig_shutdown );
420 if ( strcmp(serverName, SERVICE_NAME) )
421 regService = serverName;
424 ip = (int*)lutil_getRegParam( regService, "DebugLevel" );
427 Debug( LDAP_DEBUG_ANY,
428 "new debug level from registry is: %d\n", slap_debug, 0, 0 );
431 newUrls = (char *) lutil_getRegParam(regService, "Urls");
436 urls = ch_strdup(newUrls);
437 Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
441 newConfigFile = (char*)lutil_getRegParam( regService, "ConfigFile" );
442 if ( newConfigFile != NULL ) {
443 configfile = newConfigFile;
444 Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
447 newConfigDir = (char*)lutil_getRegParam( regService, "ConfigDir" );
448 if ( newConfigDir != NULL ) {
449 configdir = newConfigDir;
450 Debug ( LDAP_DEBUG_ANY, "new config dir from registry is: %s\n", configdir, 0, 0 );
455 while ( (i = getopt( argc, argv,
456 "c:d:f:F:h:n:o:s:tT:V"
463 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
469 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
476 slap_inet4or6 = AF_INET;
479 slap_inet4or6 = AF_INET6;
483 case 'h': /* listen URLs */
484 if ( urls != NULL ) free( urls );
485 urls = ch_strdup( optarg );
488 case 'c': /* provide sync cookie, override if exist in replica */
489 scp = (struct sync_cookie *) ch_calloc( 1,
490 sizeof( struct sync_cookie ));
491 ber_str2bv( optarg, 0, 1, &scp->octet_str );
493 /* This only parses out the rid at this point */
494 slap_parse_sync_cookie( scp, NULL );
496 if ( scp->rid == -1 ) {
497 Debug( LDAP_DEBUG_ANY,
498 "main: invalid cookie \"%s\"\n",
500 slap_sync_cookie_free( scp, 1 );
504 LDAP_STAILQ_FOREACH( scp_entry, &slap_sync_cookie, sc_next ) {
505 if ( scp->rid == scp_entry->rid ) {
506 Debug( LDAP_DEBUG_ANY,
507 "main: duplicated replica id in cookies\n",
509 slap_sync_cookie_free( scp, 1 );
513 LDAP_STAILQ_INSERT_TAIL( &slap_sync_cookie, scp, sc_next );
516 case 'd': { /* set debug level and 'do not detach' flag */
519 if ( strcmp( optarg, "?" ) == 0 ) {
520 check |= CHECK_LOGLEVEL;
525 if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
532 fputs( "must compile with LDAP_DEBUG for debugging\n",
537 case 'f': /* read config file */
538 configfile = ch_strdup( optarg );
541 case 'F': /* use config dir */
542 configdir = ch_strdup( optarg );
546 char *val = strchr( optarg, '=' );
552 opt.bv_len = ( val - optarg );
556 opt.bv_len = strlen( optarg );
559 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++ ) {
560 if ( ber_bvstrcasecmp( &option_helpers[i].oh_name, &opt ) == 0 ) {
561 assert( option_helpers[i].oh_fnc != NULL );
562 if ( (*option_helpers[i].oh_fnc)( val, option_helpers[i].oh_arg ) == -1 ) {
563 /* we assume the option parsing helper
564 * issues appropriate and self-explanatory
565 * error messages... */
572 if ( BER_BVISNULL( &option_helpers[i].oh_name ) ) {
573 goto unhandled_option;
578 case 's': /* set syslog level */
579 if ( strcmp( optarg, "?" ) == 0 ) {
580 check |= CHECK_LOGLEVEL;
584 if ( parse_debug_level( optarg, &ldap_syslog, &syslog_unknowns ) ) {
589 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
591 if ( parse_syslog_level( optarg, &ldap_syslog_level ) ) {
597 case 'l': /* set syslog local user */
598 if ( parse_syslog_user( optarg, &syslogUser ) ) {
603 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
607 if( sandbox ) free(sandbox);
608 sandbox = ch_strdup( optarg );
612 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
613 case 'u': /* user name */
614 if( username ) free(username);
615 username = ch_strdup( optarg );
618 case 'g': /* group name */
619 if( groupname ) free(groupname);
620 groupname = ch_strdup( optarg );
622 #endif /* SETUID && GETUID */
624 case 'n': /* NT service name */
625 serverName = ch_strdup( optarg );
629 /* deprecated; use slaptest instead */
630 fprintf( stderr, "option -t deprecated; "
631 "use slaptest command instead\n" );
632 check |= CHECK_CONFIG;
640 if ( firstopt == 0 ) {
641 fprintf( stderr, "warning: \"-T %s\" "
642 "should be the first option.\n",
646 /* try full option string first */
647 for ( i = 0; tools[i].name; i++ ) {
648 if ( strcmp( optarg, &tools[i].name[4] ) == 0 ) {
649 rc = tools[i].func( argc, argv );
654 /* try bits of option string (backward compatibility for single char) */
655 l = strlen( optarg );
656 for ( i = 0; tools[i].name; i++ ) {
657 if ( strncmp( optarg, &tools[i].name[4], l ) == 0 ) {
658 rc = tools[i].func( argc, argv );
665 serverNamePrefix = "slap";
666 fprintf( stderr, "program name \"%s%s\" unrecognized; "
667 "aborting...\n", serverNamePrefix, serverName );
673 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
682 ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
683 ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
684 ldif_debug = slap_debug;
687 fprintf( stderr, "%s\n", Versionstr );
688 if ( version > 1 ) goto stop;
691 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
695 logName = ch_strdup( serverName );
698 logName = serverName;
702 openlog( logName, OPENLOG_OPTIONS, syslogUser );
703 #elif defined LOG_DEBUG
704 openlog( logName, OPENLOG_OPTIONS );
710 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
712 Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
714 global_host = ldap_pvt_get_fqdn( NULL );
715 ber_str2bv( global_host, 0, 0, &global_host_bv );
717 if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
719 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
723 #if defined(HAVE_CHROOT)
725 if ( chdir( sandbox ) ) {
730 if ( chroot( sandbox ) ) {
738 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
739 if ( username != NULL || groupname != NULL ) {
740 slap_init_user( username, groupname );
748 rc = ldap_create( &slap_tls_ld );
750 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
753 /* Library defaults to full certificate checking. This is correct when
754 * a client is verifying a server because all servers should have a
755 * valid cert. But few clients have valid certs, so we want our default
756 * to be no checking. The config file can override this as usual.
758 rc = LDAP_OPT_X_TLS_NEVER;
759 (void) ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc );
762 rc = slap_init( serverMode, serverName );
764 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
768 if ( read_config( configfile, configdir ) != 0 ) {
770 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
772 if ( check & CHECK_CONFIG ) {
773 fprintf( stderr, "config check failed\n" );
779 if ( debug_unknowns ) {
780 rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
781 ldap_charray_free( debug_unknowns );
782 debug_unknowns = NULL;
786 if ( syslog_unknowns ) {
787 rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog );
788 ldap_charray_free( syslog_unknowns );
789 syslog_unknowns = NULL;
794 if ( check & CHECK_LOGLEVEL ) {
799 if ( check & CHECK_CONFIG ) {
800 fprintf( stderr, "config check succeeded\n" );
802 check &= ~CHECK_CONFIG;
803 if ( check == CHECK_NONE ) {
809 if ( glue_sub_attach( 0 ) != 0 ) {
810 Debug( LDAP_DEBUG_ANY,
811 "subordinate config error\n",
817 if ( slap_schema_check( ) != 0 ) {
818 Debug( LDAP_DEBUG_ANY,
819 "schema prep error\n",
826 rc = ldap_pvt_tls_init();
828 Debug( LDAP_DEBUG_ANY,
829 "main: TLS init failed: %d\n",
832 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
839 /* Force new ctx to be created */
840 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
842 /* The ctx's refcount is bumped up here */
843 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
844 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
845 } else if ( rc != LDAP_NOT_SUPPORTED ) {
846 Debug( LDAP_DEBUG_ANY,
847 "main: TLS init def ctx failed: %d\n",
850 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
856 #ifdef HAVE_CYRUS_SASL
857 if( sasl_host == NULL ) {
858 sasl_host = ch_strdup( global_host );
862 (void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
863 (void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
866 (void) SIGNAL( SIGPIPE, SIG_IGN );
869 (void) SIGNAL( SIGHUP, slap_sig_shutdown );
871 (void) SIGNAL( SIGINT, slap_sig_shutdown );
872 (void) SIGNAL( SIGTERM, slap_sig_shutdown );
874 (void) SIGNAL( SIGTRAP, slap_sig_shutdown );
877 (void) SIGNAL( LDAP_SIGCHLD, wait4child );
880 /* SIGBREAK is generated when Ctrl-Break is pressed. */
881 (void) SIGNAL( SIGBREAK, slap_sig_shutdown );
885 lutil_detach( no_detach, 0 );
886 #endif /* HAVE_WINSOCK */
892 if ( slapd_pid_file != NULL ) {
893 FILE *fp = fopen( slapd_pid_file, "w" );
896 int save_errno = errno;
898 Debug( LDAP_DEBUG_ANY, "unable to open pid file "
901 save_errno, strerror( save_errno ) );
903 free( slapd_pid_file );
904 slapd_pid_file = NULL;
909 fprintf( fp, "%d\n", (int) getpid() );
911 slapd_pid_file_unlink = 1;
914 if ( slapd_args_file != NULL ) {
915 FILE *fp = fopen( slapd_args_file, "w" );
918 int save_errno = errno;
920 Debug( LDAP_DEBUG_ANY, "unable to open args file "
923 save_errno, strerror( save_errno ) );
925 free( slapd_args_file );
926 slapd_args_file = NULL;
932 for ( i = 0; i < g_argc; i++ ) {
933 fprintf( fp, "%s ", g_argv[i] );
937 slapd_args_file_unlink = 1;
941 * FIXME: moved here from slapd_daemon_task()
942 * because back-monitor db_open() needs it
948 if ( slap_startup( NULL ) != 0 ) {
950 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
954 Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
956 #ifdef HAVE_NT_EVENT_LOG
958 lutil_LogStartedEvent( serverName, slap_debug, configfile ?
959 configfile : SLAPD_DEFAULT_CONFIGFILE , urls );
964 #ifdef HAVE_NT_SERVICE_MANAGER
965 /* Throw away the event that we used during the startup process. */
967 ldap_pvt_thread_cond_destroy( &started_event );
971 /* remember an error during shutdown */
972 rc |= slap_shutdown( NULL );
975 if ( check & CHECK_LOGLEVEL ) {
976 (void)loglevel_print( stdout );
978 /* remember an error during destroy */
979 rc |= slap_destroy();
981 while ( !LDAP_STAILQ_EMPTY( &slap_sync_cookie )) {
982 scp = LDAP_STAILQ_FIRST( &slap_sync_cookie );
983 LDAP_STAILQ_REMOVE_HEAD( &slap_sync_cookie, sc_next );
993 supported_feature_destroy();
994 entry_info_destroy();
997 #ifdef HAVE_NT_EVENT_LOG
999 lutil_LogStoppedEvent( serverName );
1002 Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
1005 #ifdef HAVE_NT_SERVICE_MANAGER
1006 lutil_ReportShutdownComplete();
1012 slapd_daemon_destroy();
1020 lutil_passwd_destroy();
1023 if ( slap_tls_ld ) {
1024 ldap_pvt_tls_ctx_free( slap_tls_ctx );
1025 ldap_unbind_ext( slap_tls_ld, NULL, NULL );
1027 ldap_pvt_tls_destroy();
1030 slap_sasl_regexp_destroy();
1032 if ( slapd_pid_file_unlink ) {
1033 unlink( slapd_pid_file );
1035 if ( slapd_args_file_unlink ) {
1036 unlink( slapd_args_file );
1042 ch_free( configfile );
1044 ch_free( configdir );
1048 ch_free( global_host );
1050 /* kludge, get symbols referenced */
1051 tavl_free( NULL, NULL );
1054 mal_dumpleaktrace( leakfile );
1064 * Catch and discard terminated child processes, to avoid zombies.
1068 wait4child( int sig )
1070 int save_errno = errno;
1076 while ( waitpid( (pid_t)-1, NULL, WNOHANG ) > 0 || errno == EINTR );
1078 while ( wait3( NULL, WNOHANG, NULL ) > 0 || errno == EINTR );
1081 (void) wait( NULL );
1083 (void) SIGNAL_REINSTALL( sig, wait4child );
1087 #endif /* LDAP_SIGCHLD */