2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2011 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;
77 {"slapindex", slapindex},
78 {"slappasswd", slappasswd},
79 {"slapschema", slapschema},
80 {"slaptest", slaptest},
81 {"slapauth", slapauth},
83 /* NOTE: new tools must be added in chronological order,
84 * not in alphabetical order, because for backwards
85 * compatibility name[4] is used to identify the
86 * tools; so name[4]=='a' must refer to "slapadd" and
87 * not to "slapauth". Alphabetical order can be used
88 * for tools whose name[4] is not used yet */
93 * when more than one slapd is running on one machine, each one might have
94 * it's own LOCAL for syslogging and must have its own pid/args files
97 #ifndef HAVE_MKVERSION
98 const char Versionstr[] =
99 OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
102 extern OverlayInit slap_oinfo[];
103 extern BackendInfo slap_binfo[];
105 #define CHECK_NONE 0x00
106 #define CHECK_CONFIG 0x01
107 #define CHECK_LOGLEVEL 0x02
108 static int check = CHECK_NONE;
109 static int version = 0;
115 slapd_opt_slp( const char *val, void *arg )
118 /* NULL is default */
119 if ( val == NULL || *val == '(' || strcasecmp( val, "on" ) == 0 ) {
120 slapd_register_slp = 1;
121 slapd_slp_attrs = (val != NULL && *val == '(') ? val : NULL;
123 } else if ( strcasecmp( val, "off" ) == 0 ) {
124 slapd_register_slp = 0;
126 /* NOTE: add support for URL specification? */
129 fprintf(stderr, "unrecognized value \"%s\" for SLP option\n", val );
136 fputs( "slapd: SLP support is not available\n", stderr );
142 * Option helper structure:
144 * oh_nam is left-hand part of <option>[=<value>]
145 * oh_fnc is handler function
146 * oh_arg is an optional arg to oh_fnc
147 * oh_usage is the one-line usage string related to the option,
148 * which is assumed to start with <option>[=<value>]
150 * please leave valid options in the structure, and optionally #ifdef
151 * their processing inside the helper, so that reasonable and helpful
152 * error messages can be generated if a disabled option is requested.
154 struct option_helper {
155 struct berval oh_name;
156 int (*oh_fnc)(const char *val, void *arg);
158 const char *oh_usage;
159 } option_helpers[] = {
160 { BER_BVC("slp"), slapd_opt_slp, NULL, "slp[={on|off|(attrs)}] enable/disable SLP using (attrs)" },
161 { BER_BVNULL, 0, NULL, NULL }
164 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
167 parse_syslog_user( const char *arg, int *syslogUser )
169 static slap_verbmasks syslogUsers[] = {
170 { BER_BVC( "LOCAL0" ), LOG_LOCAL0 },
171 { BER_BVC( "LOCAL1" ), LOG_LOCAL1 },
172 { BER_BVC( "LOCAL2" ), LOG_LOCAL2 },
173 { BER_BVC( "LOCAL3" ), LOG_LOCAL3 },
174 { BER_BVC( "LOCAL4" ), LOG_LOCAL4 },
175 { BER_BVC( "LOCAL5" ), LOG_LOCAL5 },
176 { BER_BVC( "LOCAL6" ), LOG_LOCAL6 },
177 { BER_BVC( "LOCAL7" ), LOG_LOCAL7 },
179 { BER_BVC( "USER" ), LOG_USER },
180 #endif /* LOG_USER */
182 { BER_BVC( "DAEMON" ), LOG_DAEMON },
183 #endif /* LOG_DAEMON */
186 int i = verb_to_mask( arg, syslogUsers );
188 if ( BER_BVISNULL( &syslogUsers[ i ].word ) ) {
189 Debug( LDAP_DEBUG_ANY,
190 "unrecognized syslog user \"%s\".\n",
195 *syslogUser = syslogUsers[ i ].mask;
199 #endif /* LOG_LOCAL4 */
202 parse_syslog_level( const char *arg, int *levelp )
204 static slap_verbmasks str2syslog_level[] = {
205 { BER_BVC( "EMERG" ), LOG_EMERG },
206 { BER_BVC( "ALERT" ), LOG_ALERT },
207 { BER_BVC( "CRIT" ), LOG_CRIT },
208 { BER_BVC( "ERR" ), LOG_ERR },
209 { BER_BVC( "WARNING" ), LOG_WARNING },
210 { BER_BVC( "NOTICE" ), LOG_NOTICE },
211 { BER_BVC( "INFO" ), LOG_INFO },
212 { BER_BVC( "DEBUG" ), LOG_DEBUG },
215 int i = verb_to_mask( arg, str2syslog_level );
216 if ( BER_BVISNULL( &str2syslog_level[ i ].word ) ) {
217 Debug( LDAP_DEBUG_ANY,
218 "unknown syslog level \"%s\".\n",
223 *levelp = str2syslog_level[ i ].mask;
227 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
230 parse_debug_unknowns( char **unknowns, int *levelp )
232 int i, level, rc = 0;
234 for ( i = 0; unknowns[ i ] != NULL; i++ ) {
236 if ( str2loglevel( unknowns[ i ], &level )) {
238 "unrecognized log level \"%s\"\n", unknowns[ i ] );
248 parse_debug_level( const char *arg, int *levelp, char ***unknowns )
252 if ( arg && arg[ 0 ] != '-' && !isdigit( (unsigned char) arg[ 0 ] ) )
257 levels = ldap_str2charray( arg, "," );
259 for ( i = 0; levels[ i ] != NULL; i++ ) {
262 if ( str2loglevel( levels[ i ], &level ) ) {
263 /* remember this for later */
264 ldap_charray_add( unknowns, levels[ i ] );
266 "unrecognized log level \"%s\" (deferred)\n",
273 ldap_charray_free( levels );
278 if ( arg[0] == '-' ) {
279 rc = lutil_atoix( &level, arg, 0 );
283 rc = lutil_atoux( &ulevel, arg, 0 );
289 "unrecognized log level "
309 "usage: %s options\n", name );
311 "\t-4\t\tIPv4 only\n"
312 "\t-6\t\tIPv6 only\n"
313 "\t-T {acl|add|auth|cat|dn|index|passwd|test}\n"
314 "\t\t\tRun in Tool mode\n"
315 "\t-c cookie\tSync cookie of consumer\n"
316 "\t-d level\tDebug level" "\n"
317 "\t-f filename\tConfiguration file\n"
318 "\t-F dir\tConfiguration directory\n"
319 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
320 "\t-g group\tGroup (id or name) to run as\n"
322 "\t-h URLs\t\tList of URLs to serve\n"
323 #ifdef SLAP_DEFAULT_SYSLOG_USER
324 "\t-l facility\tSyslog facility (default: LOCAL4)\n"
326 "\t-n serverName\tService name\n"
327 "\t-o <opt>[=val] generic means to specify options" );
328 if ( !BER_BVISNULL( &option_helpers[0].oh_name ) ) {
331 fprintf( stderr, "; supported options:\n" );
332 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++) {
333 fprintf( stderr, "\t\t%s\n", option_helpers[i].oh_usage );
336 fprintf( stderr, "\n" );
340 "\t-r directory\tSandbox directory to chroot to\n"
342 "\t-s level\tSyslog level\n"
343 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
344 "\t-u user\t\tUser (id or name) to run as\n"
346 "\t-V\t\tprint version info (-VV exit afterwards, -VVV print\n"
347 "\t\t\tinfo about static overlays and backends)\n"
351 #ifdef HAVE_NT_SERVICE_MANAGER
352 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
354 int main( int argc, char **argv )
357 int i, no_detach = 0;
360 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
361 char *username = NULL;
362 char *groupname = NULL;
364 #if defined(HAVE_CHROOT)
365 char *sandbox = NULL;
367 #ifdef SLAP_DEFAULT_SYSLOG_USER
368 int syslogUser = SLAP_DEFAULT_SYSLOG_USER;
372 char **g_argv = argv;
374 char *configfile = NULL;
375 char *configdir = NULL;
377 int serverMode = SLAP_SERVER_MODE;
379 struct sync_cookie *scp = NULL;
380 struct sync_cookie *scp_entry = NULL;
382 char **debug_unknowns = NULL;
383 char **syslog_unknowns = NULL;
385 char *serverNamePrefix = "";
388 int slapd_pid_file_unlink = 0, slapd_args_file_unlink = 0;
393 if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
400 (void) ldap_pvt_thread_initialize();
402 serverName = lutil_progname( "slapd", argc, argv );
404 if ( strcmp( serverName, "slapd" ) ) {
405 for (i=0; tools[i].name; i++) {
406 if ( !strcmp( serverName, tools[i].name ) ) {
407 rc = tools[i].func(argc, argv);
413 #ifdef HAVE_NT_SERVICE_MANAGER
419 char *regService = NULL;
421 if ( is_NT_Service ) {
422 lutil_CommenceStartupProcessing( serverName, slap_sig_shutdown );
423 if ( strcmp(serverName, SERVICE_NAME) )
424 regService = serverName;
427 ip = (int*)lutil_getRegParam( regService, "DebugLevel" );
430 Debug( LDAP_DEBUG_ANY,
431 "new debug level from registry is: %d\n", slap_debug, 0, 0 );
434 newUrls = (char *) lutil_getRegParam(regService, "Urls");
439 urls = ch_strdup(newUrls);
440 Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
444 newConfigFile = (char*)lutil_getRegParam( regService, "ConfigFile" );
445 if ( newConfigFile != NULL ) {
446 configfile = ch_strdup(newConfigFile);
447 Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
450 newConfigDir = (char*)lutil_getRegParam( regService, "ConfigDir" );
451 if ( newConfigDir != NULL ) {
452 configdir = ch_strdup(newConfigDir);
453 Debug ( LDAP_DEBUG_ANY, "new config dir from registry is: %s\n", configdir, 0, 0 );
458 while ( (i = getopt( argc, argv,
459 "c:d:f:F:h:n:o:s:tT:V"
466 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
472 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
479 slap_inet4or6 = AF_INET;
482 slap_inet4or6 = AF_INET6;
486 case 'h': /* listen URLs */
487 if ( urls != NULL ) free( urls );
488 urls = ch_strdup( optarg );
491 case 'c': /* provide sync cookie, override if exist in replica */
492 scp = (struct sync_cookie *) ch_calloc( 1,
493 sizeof( struct sync_cookie ));
494 ber_str2bv( optarg, 0, 1, &scp->octet_str );
496 /* This only parses out the rid at this point */
497 slap_parse_sync_cookie( scp, NULL );
499 if ( scp->rid == -1 ) {
500 Debug( LDAP_DEBUG_ANY,
501 "main: invalid cookie \"%s\"\n",
503 slap_sync_cookie_free( scp, 1 );
507 LDAP_STAILQ_FOREACH( scp_entry, &slap_sync_cookie, sc_next ) {
508 if ( scp->rid == scp_entry->rid ) {
509 Debug( LDAP_DEBUG_ANY,
510 "main: duplicated replica id in cookies\n",
512 slap_sync_cookie_free( scp, 1 );
516 LDAP_STAILQ_INSERT_TAIL( &slap_sync_cookie, scp, sc_next );
519 case 'd': { /* set debug level and 'do not detach' flag */
522 if ( strcmp( optarg, "?" ) == 0 ) {
523 check |= CHECK_LOGLEVEL;
528 if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
535 fputs( "must compile with LDAP_DEBUG for debugging\n",
540 case 'f': /* read config file */
541 configfile = ch_strdup( optarg );
544 case 'F': /* use config dir */
545 configdir = ch_strdup( optarg );
549 char *val = strchr( optarg, '=' );
555 opt.bv_len = ( val - optarg );
559 opt.bv_len = strlen( optarg );
562 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++ ) {
563 if ( ber_bvstrcasecmp( &option_helpers[i].oh_name, &opt ) == 0 ) {
564 assert( option_helpers[i].oh_fnc != NULL );
565 if ( (*option_helpers[i].oh_fnc)( val, option_helpers[i].oh_arg ) == -1 ) {
566 /* we assume the option parsing helper
567 * issues appropriate and self-explanatory
568 * error messages... */
575 if ( BER_BVISNULL( &option_helpers[i].oh_name ) ) {
576 goto unhandled_option;
581 case 's': /* set syslog level */
582 if ( strcmp( optarg, "?" ) == 0 ) {
583 check |= CHECK_LOGLEVEL;
587 if ( parse_debug_level( optarg, &ldap_syslog, &syslog_unknowns ) ) {
592 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
594 if ( parse_syslog_level( optarg, &ldap_syslog_level ) ) {
600 case 'l': /* set syslog local user */
601 if ( parse_syslog_user( optarg, &syslogUser ) ) {
606 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
610 if( sandbox ) free(sandbox);
611 sandbox = ch_strdup( optarg );
615 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
616 case 'u': /* user name */
617 if( username ) free(username);
618 username = ch_strdup( optarg );
621 case 'g': /* group name */
622 if( groupname ) free(groupname);
623 groupname = ch_strdup( optarg );
625 #endif /* SETUID && GETUID */
627 case 'n': /* NT service name */
628 serverName = ch_strdup( optarg );
632 /* deprecated; use slaptest instead */
633 fprintf( stderr, "option -t deprecated; "
634 "use slaptest command instead\n" );
635 check |= CHECK_CONFIG;
643 if ( firstopt == 0 ) {
644 fprintf( stderr, "warning: \"-T %s\" "
645 "should be the first option.\n",
649 /* try full option string first */
650 for ( i = 0; tools[i].name; i++ ) {
651 if ( strcmp( optarg, &tools[i].name[4] ) == 0 ) {
652 rc = tools[i].func( argc, argv );
657 /* try bits of option string (backward compatibility for single char) */
658 l = strlen( optarg );
659 for ( i = 0; tools[i].name; i++ ) {
660 if ( strncmp( optarg, &tools[i].name[4], l ) == 0 ) {
661 rc = tools[i].func( argc, argv );
668 serverNamePrefix = "slap";
669 fprintf( stderr, "program name \"%s%s\" unrecognized; "
670 "aborting...\n", serverNamePrefix, serverName );
676 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
685 if ( optind != argc )
686 goto unhandled_option;
688 ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
689 ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
690 ldif_debug = slap_debug;
693 fprintf( stderr, "%s\n", Versionstr );
695 if ( slap_oinfo[0].ov_type ) {
696 fprintf( stderr, "Included static overlays:\n");
697 for ( i= 0 ; slap_oinfo[i].ov_type; i++ ) {
698 fprintf( stderr, " %s\n", slap_oinfo[i].ov_type );
701 if ( slap_binfo[0].bi_type ) {
702 fprintf( stderr, "Included static backends:\n");
703 for ( i= 0 ; slap_binfo[i].bi_type; i++ ) {
704 fprintf( stderr, " %s\n", slap_binfo[i].bi_type );
709 if ( version > 1 ) goto stop;
712 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
716 logName = ch_strdup( serverName );
719 logName = serverName;
723 openlog( logName, OPENLOG_OPTIONS, syslogUser );
724 #elif defined LOG_DEBUG
725 openlog( logName, OPENLOG_OPTIONS );
731 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
733 Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
735 global_host = ldap_pvt_get_fqdn( NULL );
736 ber_str2bv( global_host, 0, 0, &global_host_bv );
738 if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
740 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
744 #if defined(HAVE_CHROOT)
746 if ( chdir( sandbox ) ) {
751 if ( chroot( sandbox ) ) {
759 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
760 if ( username != NULL || groupname != NULL ) {
761 slap_init_user( username, groupname );
769 rc = ldap_create( &slap_tls_ld );
771 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
774 /* Library defaults to full certificate checking. This is correct when
775 * a client is verifying a server because all servers should have a
776 * valid cert. But few clients have valid certs, so we want our default
777 * to be no checking. The config file can override this as usual.
779 rc = LDAP_OPT_X_TLS_NEVER;
780 (void) ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc );
783 rc = slap_init( serverMode, serverName );
785 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
789 if ( read_config( configfile, configdir ) != 0 ) {
791 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
793 if ( check & CHECK_CONFIG ) {
794 fprintf( stderr, "config check failed\n" );
800 if ( debug_unknowns ) {
801 rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
802 ldap_charray_free( debug_unknowns );
803 debug_unknowns = NULL;
807 if ( syslog_unknowns ) {
808 rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog );
809 ldap_charray_free( syslog_unknowns );
810 syslog_unknowns = NULL;
815 if ( check & CHECK_LOGLEVEL ) {
820 if ( check & CHECK_CONFIG ) {
821 fprintf( stderr, "config check succeeded\n" );
823 check &= ~CHECK_CONFIG;
824 if ( check == CHECK_NONE ) {
830 if ( glue_sub_attach( 0 ) != 0 ) {
831 Debug( LDAP_DEBUG_ANY,
832 "subordinate config error\n",
838 if ( slap_schema_check( ) != 0 ) {
839 Debug( LDAP_DEBUG_ANY,
840 "schema prep error\n",
847 rc = ldap_pvt_tls_init();
849 Debug( LDAP_DEBUG_ANY,
850 "main: TLS init failed: %d\n",
853 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
860 /* Force new ctx to be created */
861 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
863 /* The ctx's refcount is bumped up here */
864 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
865 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
866 } else if ( rc != LDAP_NOT_SUPPORTED ) {
867 Debug( LDAP_DEBUG_ANY,
868 "main: TLS init def ctx failed: %d\n",
871 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
877 #ifdef HAVE_CYRUS_SASL
878 if( sasl_host == NULL ) {
879 sasl_host = ch_strdup( global_host );
883 (void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
884 (void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
887 (void) SIGNAL( SIGPIPE, SIG_IGN );
890 (void) SIGNAL( SIGHUP, slap_sig_shutdown );
892 (void) SIGNAL( SIGINT, slap_sig_shutdown );
893 (void) SIGNAL( SIGTERM, slap_sig_shutdown );
895 (void) SIGNAL( SIGTRAP, slap_sig_shutdown );
898 (void) SIGNAL( LDAP_SIGCHLD, wait4child );
901 /* SIGBREAK is generated when Ctrl-Break is pressed. */
902 (void) SIGNAL( SIGBREAK, slap_sig_shutdown );
906 lutil_detach( no_detach, 0 );
907 #endif /* HAVE_WINSOCK */
913 if ( slapd_pid_file != NULL ) {
914 FILE *fp = fopen( slapd_pid_file, "w" );
917 int save_errno = errno;
919 Debug( LDAP_DEBUG_ANY, "unable to open pid file "
922 save_errno, strerror( save_errno ) );
924 free( slapd_pid_file );
925 slapd_pid_file = NULL;
930 fprintf( fp, "%d\n", (int) getpid() );
932 slapd_pid_file_unlink = 1;
935 if ( slapd_args_file != NULL ) {
936 FILE *fp = fopen( slapd_args_file, "w" );
939 int save_errno = errno;
941 Debug( LDAP_DEBUG_ANY, "unable to open args file "
944 save_errno, strerror( save_errno ) );
946 free( slapd_args_file );
947 slapd_args_file = NULL;
953 for ( i = 0; i < g_argc; i++ ) {
954 fprintf( fp, "%s ", g_argv[i] );
958 slapd_args_file_unlink = 1;
962 * FIXME: moved here from slapd_daemon_task()
963 * because back-monitor db_open() needs it
969 if ( slap_startup( NULL ) != 0 ) {
971 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
975 Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
977 #ifdef HAVE_NT_EVENT_LOG
979 lutil_LogStartedEvent( serverName, slap_debug, configfile ?
980 configfile : SLAPD_DEFAULT_CONFIGFILE , urls );
985 #ifdef HAVE_NT_SERVICE_MANAGER
986 /* Throw away the event that we used during the startup process. */
988 ldap_pvt_thread_cond_destroy( &started_event );
992 /* remember an error during shutdown */
993 rc |= slap_shutdown( NULL );
996 if ( check & CHECK_LOGLEVEL ) {
997 (void)loglevel_print( stdout );
999 /* remember an error during destroy */
1000 rc |= slap_destroy();
1002 while ( !LDAP_STAILQ_EMPTY( &slap_sync_cookie )) {
1003 scp = LDAP_STAILQ_FIRST( &slap_sync_cookie );
1004 LDAP_STAILQ_REMOVE_HEAD( &slap_sync_cookie, sc_next );
1008 #ifdef SLAPD_MODULES
1014 supported_feature_destroy();
1015 entry_info_destroy();
1018 #ifdef HAVE_NT_EVENT_LOG
1020 lutil_LogStoppedEvent( serverName );
1023 Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
1026 #ifdef HAVE_NT_SERVICE_MANAGER
1027 lutil_ReportShutdownComplete();
1033 slapd_daemon_destroy();
1041 lutil_passwd_destroy();
1044 if ( slap_tls_ld ) {
1045 ldap_pvt_tls_ctx_free( slap_tls_ctx );
1046 ldap_unbind_ext( slap_tls_ld, NULL, NULL );
1048 ldap_pvt_tls_destroy();
1051 slap_sasl_regexp_destroy();
1053 if ( slapd_pid_file_unlink ) {
1054 unlink( slapd_pid_file );
1056 if ( slapd_args_file_unlink ) {
1057 unlink( slapd_args_file );
1063 ch_free( configfile );
1065 ch_free( configdir );
1069 ch_free( global_host );
1071 /* kludge, get symbols referenced */
1072 tavl_free( NULL, NULL );
1075 mal_dumpleaktrace( leakfile );
1085 * Catch and discard terminated child processes, to avoid zombies.
1089 wait4child( int sig )
1091 int save_errno = errno;
1097 while ( waitpid( (pid_t)-1, NULL, WNOHANG ) > 0 || errno == EINTR );
1099 while ( wait3( NULL, WNOHANG, NULL ) > 0 || errno == EINTR );
1102 (void) wait( NULL );
1104 (void) SIGNAL_REINSTALL( sig, wait4child );
1108 #endif /* LDAP_SIGCHLD */