2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2009 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 #define CHECK_NONE 0x00
103 #define CHECK_CONFIG 0x01
104 #define CHECK_LOGLEVEL 0x02
105 static int check = CHECK_NONE;
106 static int version = 0;
112 slapd_opt_slp( const char *val, void *arg )
115 /* NULL is default */
116 if ( val == NULL || *val == '(' || strcasecmp( val, "on" ) == 0 ) {
117 slapd_register_slp = 1;
118 slapd_slp_attrs = (val != NULL && *val == '(') ? val : NULL;
120 } else if ( strcasecmp( val, "off" ) == 0 ) {
121 slapd_register_slp = 0;
123 /* NOTE: add support for URL specification? */
126 fprintf(stderr, "unrecognized value \"%s\" for SLP option\n", val );
133 fputs( "slapd: SLP support is not available\n", stderr );
139 * Option helper structure:
141 * oh_nam is left-hand part of <option>[=<value>]
142 * oh_fnc is handler function
143 * oh_arg is an optional arg to oh_fnc
144 * oh_usage is the one-line usage string related to the option,
145 * which is assumed to start with <option>[=<value>]
147 * please leave valid options in the structure, and optionally #ifdef
148 * their processing inside the helper, so that reasonable and helpful
149 * error messages can be generated if a disabled option is requested.
151 struct option_helper {
152 struct berval oh_name;
153 int (*oh_fnc)(const char *val, void *arg);
155 const char *oh_usage;
156 } option_helpers[] = {
157 { BER_BVC("slp"), slapd_opt_slp, NULL, "slp[={on|off|(attrs)}] enable/disable SLP using (attrs)" },
158 { BER_BVNULL, 0, NULL, NULL }
161 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
164 parse_syslog_user( const char *arg, int *syslogUser )
166 static slap_verbmasks syslogUsers[] = {
167 { BER_BVC( "LOCAL0" ), LOG_LOCAL0 },
168 { BER_BVC( "LOCAL1" ), LOG_LOCAL1 },
169 { BER_BVC( "LOCAL2" ), LOG_LOCAL2 },
170 { BER_BVC( "LOCAL3" ), LOG_LOCAL3 },
171 { BER_BVC( "LOCAL4" ), LOG_LOCAL4 },
172 { BER_BVC( "LOCAL5" ), LOG_LOCAL5 },
173 { BER_BVC( "LOCAL6" ), LOG_LOCAL6 },
174 { BER_BVC( "LOCAL7" ), LOG_LOCAL7 },
176 { BER_BVC( "USER" ), LOG_USER },
177 #endif /* LOG_USER */
179 { BER_BVC( "DAEMON" ), LOG_DAEMON },
180 #endif /* LOG_DAEMON */
183 int i = verb_to_mask( arg, syslogUsers );
185 if ( BER_BVISNULL( &syslogUsers[ i ].word ) ) {
186 Debug( LDAP_DEBUG_ANY,
187 "unrecognized syslog user \"%s\".\n",
192 *syslogUser = syslogUsers[ i ].mask;
196 #endif /* LOG_LOCAL4 */
199 parse_syslog_level( const char *arg, int *levelp )
201 static slap_verbmasks str2syslog_level[] = {
202 { BER_BVC( "EMERG" ), LOG_EMERG },
203 { BER_BVC( "ALERT" ), LOG_ALERT },
204 { BER_BVC( "CRIT" ), LOG_CRIT },
205 { BER_BVC( "ERR" ), LOG_ERR },
206 { BER_BVC( "WARNING" ), LOG_WARNING },
207 { BER_BVC( "NOTICE" ), LOG_NOTICE },
208 { BER_BVC( "INFO" ), LOG_INFO },
209 { BER_BVC( "DEBUG" ), LOG_DEBUG },
212 int i = verb_to_mask( arg, str2syslog_level );
213 if ( BER_BVISNULL( &str2syslog_level[ i ].word ) ) {
214 Debug( LDAP_DEBUG_ANY,
215 "unknown syslog level \"%s\".\n",
220 *levelp = str2syslog_level[ i ].mask;
224 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
227 parse_debug_unknowns( char **unknowns, int *levelp )
229 int i, level, rc = 0;
231 for ( i = 0; unknowns[ i ] != NULL; i++ ) {
233 if ( str2loglevel( unknowns[ i ], &level )) {
235 "unrecognized log level \"%s\"\n", unknowns[ i ] );
245 parse_debug_level( const char *arg, int *levelp, char ***unknowns )
249 if ( arg && arg[ 0 ] != '-' && !isdigit( (unsigned char) arg[ 0 ] ) )
254 levels = ldap_str2charray( arg, "," );
256 for ( i = 0; levels[ i ] != NULL; i++ ) {
259 if ( str2loglevel( levels[ i ], &level ) ) {
260 /* remember this for later */
261 ldap_charray_add( unknowns, levels[ i ] );
263 "unrecognized log level \"%s\" (deferred)\n",
270 ldap_charray_free( levels );
273 if ( lutil_atoix( &level, arg, 0 ) != 0 ) {
275 "unrecognized log level "
295 "usage: %s options\n", name );
297 "\t-4\t\tIPv4 only\n"
298 "\t-6\t\tIPv6 only\n"
299 "\t-T {acl|add|auth|cat|dn|index|passwd|test}\n"
300 "\t\t\tRun in Tool mode\n"
301 "\t-c cookie\tSync cookie of consumer\n"
302 "\t-d level\tDebug level" "\n"
303 "\t-f filename\tConfiguration file\n"
304 "\t-F dir\tConfiguration directory\n"
305 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
306 "\t-g group\tGroup (id or name) to run as\n"
308 "\t-h URLs\t\tList of URLs to serve\n"
309 #ifdef SLAP_DEFAULT_SYSLOG_USER
310 "\t-l facility\tSyslog facility (default: LOCAL4)\n"
312 "\t-n serverName\tService name\n"
313 "\t-o <opt>[=val] generic means to specify options" );
314 if ( !BER_BVISNULL( &option_helpers[0].oh_name ) ) {
317 fprintf( stderr, "; supported options:\n" );
318 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++) {
319 fprintf( stderr, "\t\t%s\n", option_helpers[i].oh_usage );
322 fprintf( stderr, "\n" );
326 "\t-r directory\tSandbox directory to chroot to\n"
328 "\t-s level\tSyslog level\n"
329 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
330 "\t-u user\t\tUser (id or name) to run as\n"
332 "\t-V\t\tprint version info (-VV only)\n"
336 #ifdef HAVE_NT_SERVICE_MANAGER
337 void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
339 int main( int argc, char **argv )
342 int i, no_detach = 0;
345 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
346 char *username = NULL;
347 char *groupname = NULL;
349 #if defined(HAVE_CHROOT)
350 char *sandbox = NULL;
352 #ifdef SLAP_DEFAULT_SYSLOG_USER
353 int syslogUser = SLAP_DEFAULT_SYSLOG_USER;
357 char **g_argv = argv;
359 char *configfile = NULL;
360 char *configdir = NULL;
362 int serverMode = SLAP_SERVER_MODE;
364 struct sync_cookie *scp = NULL;
365 struct sync_cookie *scp_entry = NULL;
367 char **debug_unknowns = NULL;
368 char **syslog_unknowns = NULL;
370 char *serverNamePrefix = "";
373 int slapd_pid_file_unlink = 0, slapd_args_file_unlink = 0;
378 if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
385 (void) ldap_pvt_thread_initialize();
387 serverName = lutil_progname( "slapd", argc, argv );
389 if ( strcmp( serverName, "slapd" ) ) {
390 for (i=0; tools[i].name; i++) {
391 if ( !strcmp( serverName, tools[i].name ) ) {
392 rc = tools[i].func(argc, argv);
398 #ifdef HAVE_NT_SERVICE_MANAGER
404 char *regService = NULL;
406 if ( is_NT_Service ) {
407 lutil_CommenceStartupProcessing( serverName, slap_sig_shutdown );
408 if ( strcmp(serverName, SERVICE_NAME) )
409 regService = serverName;
412 ip = (int*)lutil_getRegParam( regService, "DebugLevel" );
415 Debug( LDAP_DEBUG_ANY,
416 "new debug level from registry is: %d\n", slap_debug, 0, 0 );
419 newUrls = (char *) lutil_getRegParam(regService, "Urls");
424 urls = ch_strdup(newUrls);
425 Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
429 newConfigFile = (char*)lutil_getRegParam( regService, "ConfigFile" );
430 if ( newConfigFile != NULL ) {
431 configfile = newConfigFile;
432 Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
435 newConfigDir = (char*)lutil_getRegParam( regService, "ConfigDir" );
436 if ( newConfigDir != NULL ) {
437 configdir = newConfigDir;
438 Debug ( LDAP_DEBUG_ANY, "new config dir from registry is: %s\n", configdir, 0, 0 );
443 while ( (i = getopt( argc, argv,
444 "c:d:f:F:h:n:o:s:tT:V"
451 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
457 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
464 slap_inet4or6 = AF_INET;
467 slap_inet4or6 = AF_INET6;
471 case 'h': /* listen URLs */
472 if ( urls != NULL ) free( urls );
473 urls = ch_strdup( optarg );
476 case 'c': /* provide sync cookie, override if exist in replica */
477 scp = (struct sync_cookie *) ch_calloc( 1,
478 sizeof( struct sync_cookie ));
479 ber_str2bv( optarg, 0, 1, &scp->octet_str );
481 /* This only parses out the rid at this point */
482 slap_parse_sync_cookie( scp, NULL );
484 if ( scp->rid == -1 ) {
485 Debug( LDAP_DEBUG_ANY,
486 "main: invalid cookie \"%s\"\n",
488 slap_sync_cookie_free( scp, 1 );
492 LDAP_STAILQ_FOREACH( scp_entry, &slap_sync_cookie, sc_next ) {
493 if ( scp->rid == scp_entry->rid ) {
494 Debug( LDAP_DEBUG_ANY,
495 "main: duplicated replica id in cookies\n",
497 slap_sync_cookie_free( scp, 1 );
501 LDAP_STAILQ_INSERT_TAIL( &slap_sync_cookie, scp, sc_next );
504 case 'd': { /* set debug level and 'do not detach' flag */
507 if ( strcmp( optarg, "?" ) == 0 ) {
508 check |= CHECK_LOGLEVEL;
513 if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
520 fputs( "must compile with LDAP_DEBUG for debugging\n",
525 case 'f': /* read config file */
526 configfile = ch_strdup( optarg );
529 case 'F': /* use config dir */
530 configdir = ch_strdup( optarg );
534 char *val = strchr( optarg, '=' );
540 opt.bv_len = ( val - optarg );
544 opt.bv_len = strlen( optarg );
547 for ( i = 0; !BER_BVISNULL( &option_helpers[i].oh_name ); i++ ) {
548 if ( ber_bvstrcasecmp( &option_helpers[i].oh_name, &opt ) == 0 ) {
549 assert( option_helpers[i].oh_fnc != NULL );
550 if ( (*option_helpers[i].oh_fnc)( val, option_helpers[i].oh_arg ) == -1 ) {
551 /* we assume the option parsing helper
552 * issues appropriate and self-explanatory
553 * error messages... */
560 if ( BER_BVISNULL( &option_helpers[i].oh_name ) ) {
561 goto unhandled_option;
566 case 's': /* set syslog level */
567 if ( strcmp( optarg, "?" ) == 0 ) {
568 check |= CHECK_LOGLEVEL;
572 if ( parse_debug_level( optarg, &ldap_syslog, &syslog_unknowns ) ) {
577 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
579 if ( parse_syslog_level( optarg, &ldap_syslog_level ) ) {
585 case 'l': /* set syslog local user */
586 if ( parse_syslog_user( optarg, &syslogUser ) ) {
591 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
595 if( sandbox ) free(sandbox);
596 sandbox = ch_strdup( optarg );
600 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
601 case 'u': /* user name */
602 if( username ) free(username);
603 username = ch_strdup( optarg );
606 case 'g': /* group name */
607 if( groupname ) free(groupname);
608 groupname = ch_strdup( optarg );
610 #endif /* SETUID && GETUID */
612 case 'n': /* NT service name */
613 serverName = ch_strdup( optarg );
617 /* deprecated; use slaptest instead */
618 fprintf( stderr, "option -t deprecated; "
619 "use slaptest command instead\n" );
620 check |= CHECK_CONFIG;
628 if ( firstopt == 0 ) {
629 fprintf( stderr, "warning: \"-T %s\" "
630 "should be the first option.\n",
634 /* try full option string first */
635 for ( i = 0; tools[i].name; i++ ) {
636 if ( strcmp( optarg, &tools[i].name[4] ) == 0 ) {
637 rc = tools[i].func( argc, argv );
642 /* try bits of option string (backward compatibility for single char) */
643 l = strlen( optarg );
644 for ( i = 0; tools[i].name; i++ ) {
645 if ( strncmp( optarg, &tools[i].name[4], l ) == 0 ) {
646 rc = tools[i].func( argc, argv );
653 serverNamePrefix = "slap";
654 fprintf( stderr, "program name \"%s%s\" unrecognized; "
655 "aborting...\n", serverNamePrefix, serverName );
661 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
670 ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
671 ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
672 ldif_debug = slap_debug;
675 fprintf( stderr, "%s\n", Versionstr );
676 if ( version > 1 ) goto stop;
679 #if defined(LDAP_DEBUG) && defined(LDAP_SYSLOG)
683 logName = ch_strdup( serverName );
686 logName = serverName;
690 openlog( logName, OPENLOG_OPTIONS, syslogUser );
691 #elif defined LOG_DEBUG
692 openlog( logName, OPENLOG_OPTIONS );
698 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
700 Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
702 global_host = ldap_pvt_get_fqdn( NULL );
703 ber_str2bv( global_host, 0, 0, &global_host_bv );
705 if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
707 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
711 #if defined(HAVE_CHROOT)
713 if ( chdir( sandbox ) ) {
718 if ( chroot( sandbox ) ) {
726 #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
727 if ( username != NULL || groupname != NULL ) {
728 slap_init_user( username, groupname );
736 rc = ldap_create( &slap_tls_ld );
738 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
741 /* Library defaults to full certificate checking. This is correct when
742 * a client is verifying a server because all servers should have a
743 * valid cert. But few clients have valid certs, so we want our default
744 * to be no checking. The config file can override this as usual.
746 rc = LDAP_OPT_X_TLS_NEVER;
747 (void) ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc );
750 rc = slap_init( serverMode, serverName );
752 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
756 if ( read_config( configfile, configdir ) != 0 ) {
758 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
760 if ( check & CHECK_CONFIG ) {
761 fprintf( stderr, "config check failed\n" );
767 if ( debug_unknowns ) {
768 rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
769 ldap_charray_free( debug_unknowns );
770 debug_unknowns = NULL;
774 if ( syslog_unknowns ) {
775 rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog );
776 ldap_charray_free( syslog_unknowns );
777 syslog_unknowns = NULL;
782 if ( check & CHECK_LOGLEVEL ) {
787 if ( check & CHECK_CONFIG ) {
788 fprintf( stderr, "config check succeeded\n" );
790 check &= ~CHECK_CONFIG;
791 if ( check == CHECK_NONE ) {
797 if ( glue_sub_attach( 0 ) != 0 ) {
798 Debug( LDAP_DEBUG_ANY,
799 "subordinate config error\n",
805 if ( slap_schema_check( ) != 0 ) {
806 Debug( LDAP_DEBUG_ANY,
807 "schema prep error\n",
814 rc = ldap_pvt_tls_init();
816 Debug( LDAP_DEBUG_ANY,
817 "main: TLS init failed: %d\n",
820 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
827 /* Force new ctx to be created */
828 rc = ldap_pvt_tls_set_option( slap_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
830 /* The ctx's refcount is bumped up here */
831 ldap_pvt_tls_get_option( slap_tls_ld, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
832 load_extop( &slap_EXOP_START_TLS, 0, starttls_extop );
833 } else if ( rc != LDAP_NOT_SUPPORTED ) {
834 Debug( LDAP_DEBUG_ANY,
835 "main: TLS init def ctx failed: %d\n",
838 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
844 #ifdef HAVE_CYRUS_SASL
845 if( sasl_host == NULL ) {
846 sasl_host = ch_strdup( global_host );
850 (void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
851 (void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
854 (void) SIGNAL( SIGPIPE, SIG_IGN );
857 (void) SIGNAL( SIGHUP, slap_sig_shutdown );
859 (void) SIGNAL( SIGINT, slap_sig_shutdown );
860 (void) SIGNAL( SIGTERM, slap_sig_shutdown );
862 (void) SIGNAL( SIGTRAP, slap_sig_shutdown );
865 (void) SIGNAL( LDAP_SIGCHLD, wait4child );
868 /* SIGBREAK is generated when Ctrl-Break is pressed. */
869 (void) SIGNAL( SIGBREAK, slap_sig_shutdown );
873 lutil_detach( no_detach, 0 );
874 #endif /* HAVE_WINSOCK */
880 if ( slapd_pid_file != NULL ) {
881 FILE *fp = fopen( slapd_pid_file, "w" );
884 int save_errno = errno;
886 Debug( LDAP_DEBUG_ANY, "unable to open pid file "
889 save_errno, strerror( save_errno ) );
891 free( slapd_pid_file );
892 slapd_pid_file = NULL;
897 fprintf( fp, "%d\n", (int) getpid() );
899 slapd_pid_file_unlink = 1;
902 if ( slapd_args_file != NULL ) {
903 FILE *fp = fopen( slapd_args_file, "w" );
906 int save_errno = errno;
908 Debug( LDAP_DEBUG_ANY, "unable to open args file "
911 save_errno, strerror( save_errno ) );
913 free( slapd_args_file );
914 slapd_args_file = NULL;
920 for ( i = 0; i < g_argc; i++ ) {
921 fprintf( fp, "%s ", g_argv[i] );
925 slapd_args_file_unlink = 1;
929 * FIXME: moved here from slapd_daemon_task()
930 * because back-monitor db_open() needs it
936 if ( slap_startup( NULL ) != 0 ) {
938 SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
942 Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
944 #ifdef HAVE_NT_EVENT_LOG
946 lutil_LogStartedEvent( serverName, slap_debug, configfile ?
947 configfile : SLAPD_DEFAULT_CONFIGFILE , urls );
952 #ifdef HAVE_NT_SERVICE_MANAGER
953 /* Throw away the event that we used during the startup process. */
955 ldap_pvt_thread_cond_destroy( &started_event );
959 /* remember an error during shutdown */
960 rc |= slap_shutdown( NULL );
963 if ( check & CHECK_LOGLEVEL ) {
964 (void)loglevel_print( stdout );
966 /* remember an error during destroy */
967 rc |= slap_destroy();
969 while ( !LDAP_STAILQ_EMPTY( &slap_sync_cookie )) {
970 scp = LDAP_STAILQ_FIRST( &slap_sync_cookie );
971 LDAP_STAILQ_REMOVE_HEAD( &slap_sync_cookie, sc_next );
981 supported_feature_destroy();
982 entry_info_destroy();
985 #ifdef HAVE_NT_EVENT_LOG
987 lutil_LogStoppedEvent( serverName );
990 Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
993 #ifdef HAVE_NT_SERVICE_MANAGER
994 lutil_ReportShutdownComplete();
1000 slapd_daemon_destroy();
1008 lutil_passwd_destroy();
1011 if ( slap_tls_ld ) {
1012 ldap_pvt_tls_ctx_free( slap_tls_ctx );
1013 ldap_unbind_ext( slap_tls_ld, NULL, NULL );
1015 ldap_pvt_tls_destroy();
1018 slap_sasl_regexp_destroy();
1020 if ( slapd_pid_file_unlink ) {
1021 unlink( slapd_pid_file );
1023 if ( slapd_args_file_unlink ) {
1024 unlink( slapd_args_file );
1030 ch_free( configfile );
1032 ch_free( configdir );
1036 ch_free( global_host );
1038 /* kludge, get symbols referenced */
1039 tavl_free( NULL, NULL );
1042 mal_dumpleaktrace( leakfile );
1052 * Catch and discard terminated child processes, to avoid zombies.
1056 wait4child( int sig )
1058 int save_errno = errno;
1064 while ( waitpid( (pid_t)-1, NULL, WNOHANG ) > 0 || errno == EINTR );
1066 while ( wait3( NULL, WNOHANG, NULL ) > 0 || errno == EINTR );
1069 (void) wait( NULL );
1071 (void) SIGNAL_REINSTALL( sig, wait4child );
1075 #endif /* LDAP_SIGCHLD */