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;
375 char **g_argv = argv;
377 char *configfile = NULL;
378 char *configdir = NULL;
380 int serverMode = SLAP_SERVER_MODE;
382 struct sync_cookie *scp = NULL;
383 struct sync_cookie *scp_entry = NULL;
385 char **debug_unknowns = NULL;
386 char **syslog_unknowns = NULL;
388 char *serverNamePrefix = "";
391 int slapd_pid_file_unlink = 0, slapd_args_file_unlink = 0;
396 if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
403 (void) ldap_pvt_thread_initialize();
405 serverName = lutil_progname( "slapd", argc, argv );
407 if ( strcmp( serverName, "slapd" ) ) {
408 for (i=0; tools[i].name; i++) {
409 if ( !strcmp( serverName, tools[i].name ) ) {
410 rc = tools[i].func(argc, argv);
416 #ifdef HAVE_NT_SERVICE_MANAGER
422 char *regService = NULL;
424 if ( is_NT_Service ) {
425 lutil_CommenceStartupProcessing( serverName, slap_sig_shutdown );
426 if ( strcmp(serverName, SERVICE_NAME) )
427 regService = serverName;
430 ip = (int*)lutil_getRegParam( regService, "DebugLevel" );
433 Debug( LDAP_DEBUG_ANY,
434 "new debug level from registry is: %d\n", slap_debug, 0, 0 );
437 newUrls = (char *) lutil_getRegParam(regService, "Urls");
442 urls = ch_strdup(newUrls);
443 Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
447 newConfigFile = (char*)lutil_getRegParam( regService, "ConfigFile" );
448 if ( newConfigFile != NULL ) {
449 configfile = ch_strdup(newConfigFile);
450 Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
453 newConfigDir = (char*)lutil_getRegParam( regService, "ConfigDir" );
454 if ( newConfigDir != NULL ) {
455 configdir = ch_strdup(newConfigDir);
456 Debug ( LDAP_DEBUG_ANY, "new config dir from registry is: %s\n", configdir, 0, 0 );
461 while ( (i = getopt( argc, argv,
462 "c:d:f:F:h:n:o:s:tT:V"
469 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
475 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
482 slap_inet4or6 = AF_INET;
485 slap_inet4or6 = AF_INET6;
489 case 'h': /* listen URLs */
490 if ( urls != NULL ) free( urls );
491 urls = ch_strdup( optarg );
494 case 'c': /* provide sync cookie, override if exist in replica */
495 scp = (struct sync_cookie *) ch_calloc( 1,
496 sizeof( struct sync_cookie ));
497 ber_str2bv( optarg, 0, 1, &scp->octet_str );
499 /* This only parses out the rid at this point */
500 slap_parse_sync_cookie( scp, NULL );
502 if ( scp->rid == -1 ) {
503 Debug( LDAP_DEBUG_ANY,
504 "main: invalid cookie \"%s\"\n",
506 slap_sync_cookie_free( scp, 1 );
510 LDAP_STAILQ_FOREACH( scp_entry, &slap_sync_cookie, sc_next ) {
511 if ( scp->rid == scp_entry->rid ) {
512 Debug( LDAP_DEBUG_ANY,
513 "main: duplicated replica id in cookies\n",
515 slap_sync_cookie_free( scp, 1 );
519 LDAP_STAILQ_INSERT_TAIL( &slap_sync_cookie, scp, sc_next );
522 case 'd': { /* set debug level and 'do not detach' flag */
525 if ( strcmp( optarg, "?" ) == 0 ) {
526 check |= CHECK_LOGLEVEL;
531 if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
538 fputs( "must compile with LDAP_DEBUG for debugging\n",
543 case 'f': /* read config file */
544 configfile = ch_strdup( optarg );
547 case 'F': /* use config dir */
548 configdir = ch_strdup( optarg );
552 char *val = strchr( optarg, '=' );
558 opt.bv_len = ( val - optarg );
562 opt.bv_len = strlen( optarg );
565 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++ ) {
566 if ( ber_bvstrcasecmp( &option_helpers[i].oh_name, &opt ) == 0 ) {
567 assert( option_helpers[i].oh_fnc != NULL );
568 if ( (*option_helpers[i].oh_fnc)( val, option_helpers[i].oh_arg ) == -1 ) {
569 /* we assume the option parsing helper
570 * issues appropriate and self-explanatory
571 * error messages... */
578 if ( BER_BVISNULL( &option_helpers[i].oh_name ) ) {
579 goto unhandled_option;
584 case 's': /* set syslog level */
585 if ( strcmp( optarg, "?" ) == 0 ) {
586 check |= CHECK_LOGLEVEL;
590 if ( parse_debug_level( optarg, &ldap_syslog, &syslog_unknowns ) ) {
595 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
597 if ( parse_syslog_level( optarg, &ldap_syslog_level ) ) {
603 case 'l': /* set syslog local user */
604 if ( parse_syslog_user( optarg, &syslogUser ) ) {
609 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
613 if( sandbox ) free(sandbox);
614 sandbox = ch_strdup( optarg );
618 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
619 case 'u': /* user name */
620 if( username ) free(username);
621 username = ch_strdup( optarg );
624 case 'g': /* group name */
625 if( groupname ) free(groupname);
626 groupname = ch_strdup( optarg );
628 #endif /* SETUID && GETUID */
630 case 'n': /* NT service name */
631 serverName = ch_strdup( optarg );
635 /* deprecated; use slaptest instead */
636 fprintf( stderr, "option -t deprecated; "
637 "use slaptest command instead\n" );
638 check |= CHECK_CONFIG;
646 if ( firstopt == 0 ) {
647 fprintf( stderr, "warning: \"-T %s\" "
648 "should be the first option.\n",
652 /* try full option string first */
653 for ( i = 0; tools[i].name; i++ ) {
654 if ( strcmp( optarg, &tools[i].name[4] ) == 0 ) {
655 rc = tools[i].func( argc, argv );
660 /* try bits of option string (backward compatibility for single char) */
661 l = strlen( optarg );
662 for ( i = 0; tools[i].name; i++ ) {
663 if ( strncmp( optarg, &tools[i].name[4], l ) == 0 ) {
664 rc = tools[i].func( argc, argv );
671 serverNamePrefix = "slap";
672 fprintf( stderr, "program name \"%s%s\" unrecognized; "
673 "aborting...\n", serverNamePrefix, serverName );
679 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
688 if ( optind != argc )
689 goto unhandled_option;
691 ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
692 ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
693 ldif_debug = slap_debug;
696 fprintf( stderr, "%s\n", Versionstr );
698 if ( slap_oinfo[0].ov_type ) {
699 fprintf( stderr, "Included static overlays:\n");
700 for ( i= 0 ; slap_oinfo[i].ov_type; i++ ) {
701 fprintf( stderr, " %s\n", slap_oinfo[i].ov_type );
704 if ( slap_binfo[0].bi_type ) {
705 fprintf( stderr, "Included static backends:\n");
706 for ( i= 0 ; slap_binfo[i].bi_type; i++ ) {
707 fprintf( stderr, " %s\n", slap_binfo[i].bi_type );
712 if ( version > 1 ) goto stop;
715 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
719 logName = ch_strdup( serverName );
722 logName = serverName;
726 openlog( logName, OPENLOG_OPTIONS, syslogUser );
727 #elif defined LOG_DEBUG
728 openlog( logName, OPENLOG_OPTIONS );
734 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
736 Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
738 global_host = ldap_pvt_get_fqdn( NULL );
739 ber_str2bv( global_host, 0, 0, &global_host_bv );
741 if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
743 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
747 #if defined(HAVE_CHROOT)
749 if ( chdir( sandbox ) ) {
754 if ( chroot( sandbox ) ) {
762 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
763 if ( username != NULL || groupname != NULL ) {
764 slap_init_user( username, groupname );
772 rc = ldap_create( &slap_tls_ld );
774 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
777 /* Library defaults to full certificate checking. This is correct when
778 * a client is verifying a server because all servers should have a
779 * valid cert. But few clients have valid certs, so we want our default
780 * to be no checking. The config file can override this as usual.
782 rc = LDAP_OPT_X_TLS_NEVER;
783 (void) ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc );
786 rc = slap_init( serverMode, serverName );
788 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
792 if ( read_config( configfile, configdir ) != 0 ) {
794 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
796 if ( check & CHECK_CONFIG ) {
797 fprintf( stderr, "config check failed\n" );
803 if ( debug_unknowns ) {
804 rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
805 ldap_charray_free( debug_unknowns );
806 debug_unknowns = NULL;
810 if ( syslog_unknowns ) {
811 rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog );
812 ldap_charray_free( syslog_unknowns );
813 syslog_unknowns = NULL;
818 if ( check & CHECK_LOGLEVEL ) {
823 if ( check & CHECK_CONFIG ) {
824 fprintf( stderr, "config check succeeded\n" );
826 check &= ~CHECK_CONFIG;
827 if ( check == CHECK_NONE ) {
833 if ( glue_sub_attach( 0 ) != 0 ) {
834 Debug( LDAP_DEBUG_ANY,
835 "subordinate config error\n",
841 if ( slap_schema_check( ) != 0 ) {
842 Debug( LDAP_DEBUG_ANY,
843 "schema prep error\n",
850 rc = ldap_pvt_tls_init();
852 Debug( LDAP_DEBUG_ANY,
853 "main: TLS init failed: %d\n",
856 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
863 /* Force new ctx to be created */
864 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
866 /* The ctx's refcount is bumped up here */
867 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
868 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
869 } else if ( rc != LDAP_NOT_SUPPORTED ) {
870 Debug( LDAP_DEBUG_ANY,
871 "main: TLS init def ctx failed: %d\n",
874 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
880 #ifdef HAVE_CYRUS_SASL
881 if( sasl_host == NULL ) {
882 sasl_host = ch_strdup( global_host );
886 (void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
887 (void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
890 (void) SIGNAL( SIGPIPE, SIG_IGN );
893 (void) SIGNAL( SIGHUP, slap_sig_shutdown );
895 (void) SIGNAL( SIGINT, slap_sig_shutdown );
896 (void) SIGNAL( SIGTERM, slap_sig_shutdown );
898 (void) SIGNAL( SIGTRAP, slap_sig_shutdown );
901 (void) SIGNAL( LDAP_SIGCHLD, wait4child );
904 /* SIGBREAK is generated when Ctrl-Break is pressed. */
905 (void) SIGNAL( SIGBREAK, slap_sig_shutdown );
909 if ( lutil_pair( waitfds ) < 0 ) {
910 Debug( LDAP_DEBUG_ANY,
911 "main: lutil_pair failed: %d\n",
916 pid = lutil_detach( no_detach, 0 );
921 if ( read( waitfds[0], buf, 1 ) != 1 )
927 #endif /* HAVE_WINSOCK */
933 if ( slapd_pid_file != NULL ) {
934 FILE *fp = fopen( slapd_pid_file, "w" );
937 int save_errno = errno;
939 Debug( LDAP_DEBUG_ANY, "unable to open pid file "
942 save_errno, strerror( save_errno ) );
944 free( slapd_pid_file );
945 slapd_pid_file = NULL;
950 fprintf( fp, "%d\n", (int) getpid() );
952 slapd_pid_file_unlink = 1;
955 if ( slapd_args_file != NULL ) {
956 FILE *fp = fopen( slapd_args_file, "w" );
959 int save_errno = errno;
961 Debug( LDAP_DEBUG_ANY, "unable to open args file "
964 save_errno, strerror( save_errno ) );
966 free( slapd_args_file );
967 slapd_args_file = NULL;
973 for ( i = 0; i < g_argc; i++ ) {
974 fprintf( fp, "%s ", g_argv[i] );
978 slapd_args_file_unlink = 1;
982 * FIXME: moved here from slapd_daemon_task()
983 * because back-monitor db_open() needs it
989 if ( slap_startup( NULL ) != 0 ) {
991 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
995 Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
998 write( waitfds[1], "1", 1 );
1002 #ifdef HAVE_NT_EVENT_LOG
1004 lutil_LogStartedEvent( serverName, slap_debug, configfile ?
1005 configfile : SLAPD_DEFAULT_CONFIGFILE , urls );
1008 rc = slapd_daemon();
1010 #ifdef HAVE_NT_SERVICE_MANAGER
1011 /* Throw away the event that we used during the startup process. */
1012 if ( is_NT_Service )
1013 ldap_pvt_thread_cond_destroy( &started_event );
1017 /* remember an error during shutdown */
1018 rc |= slap_shutdown( NULL );
1021 if ( check & CHECK_LOGLEVEL ) {
1022 (void)loglevel_print( stdout );
1024 /* remember an error during destroy */
1025 rc |= slap_destroy();
1027 while ( !LDAP_STAILQ_EMPTY( &slap_sync_cookie )) {
1028 scp = LDAP_STAILQ_FIRST( &slap_sync_cookie );
1029 LDAP_STAILQ_REMOVE_HEAD( &slap_sync_cookie, sc_next );
1033 #ifdef SLAPD_MODULES
1039 supported_feature_destroy();
1040 entry_info_destroy();
1043 #ifdef HAVE_NT_EVENT_LOG
1045 lutil_LogStoppedEvent( serverName );
1048 Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
1051 #ifdef HAVE_NT_SERVICE_MANAGER
1052 lutil_ReportShutdownComplete();
1058 slapd_daemon_destroy();
1066 lutil_passwd_destroy();
1069 if ( slap_tls_ld ) {
1070 ldap_pvt_tls_ctx_free( slap_tls_ctx );
1071 ldap_unbind_ext( slap_tls_ld, NULL, NULL );
1073 ldap_pvt_tls_destroy();
1076 slap_sasl_regexp_destroy();
1078 if ( slapd_pid_file_unlink ) {
1079 unlink( slapd_pid_file );
1081 if ( slapd_args_file_unlink ) {
1082 unlink( slapd_args_file );
1088 ch_free( configfile );
1090 ch_free( configdir );
1094 ch_free( global_host );
1096 /* kludge, get symbols referenced */
1097 tavl_free( NULL, NULL );
1100 mal_dumpleaktrace( leakfile );
1110 * Catch and discard terminated child processes, to avoid zombies.
1114 wait4child( int sig )
1116 int save_errno = errno;
1122 while ( waitpid( (pid_t)-1, NULL, WNOHANG ) > 0 || errno == EINTR );
1124 while ( wait3( NULL, WNOHANG, NULL ) > 0 || errno == EINTR );
1127 (void) wait( NULL );
1129 (void) SIGNAL_REINSTALL( sig, wait4child );
1133 #endif /* LDAP_SIGCHLD */