1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-05 07:59:13 +08:00
|
|
|
/*
|
2000-05-13 10:47:56 +08:00
|
|
|
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
|
1999-08-05 07:59:13 +08:00
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "portable.h"
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1999-02-07 00:00:00 +08:00
|
|
|
#include <ac/signal.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/unistd.h>
|
1999-03-28 00:21:44 +08:00
|
|
|
#include <ac/wait.h>
|
|
|
|
#include <ac/errno.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include "slap.h"
|
1999-06-19 07:53:05 +08:00
|
|
|
#include "lutil.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-03-29 17:04:35 +08:00
|
|
|
#ifdef LDAP_SIGCHLD
|
1999-03-28 00:21:44 +08:00
|
|
|
static RETSIGTYPE wait4child( int sig );
|
|
|
|
#endif
|
|
|
|
|
1999-11-02 05:25:22 +08:00
|
|
|
#ifdef HAVE_NT_SERVICE_MANAGER
|
1999-06-19 05:33:39 +08:00
|
|
|
#define MAIN_RETURN(x) return
|
1999-06-18 02:46:02 +08:00
|
|
|
struct sockaddr_in bind_addr;
|
|
|
|
|
1999-06-19 05:33:39 +08:00
|
|
|
/* in nt_main.c */
|
2000-06-20 11:53:12 +08:00
|
|
|
LDAP_LUTIL_V(SERVICE_STATUS) SLAPDServiceStatus;
|
|
|
|
LDAP_LUTIL_V(SERVICE_STATUS_HANDLE) hSLAPDServiceStatus;
|
1999-06-18 02:46:02 +08:00
|
|
|
extern ldap_pvt_thread_cond_t started_event, stopped_event;
|
|
|
|
extern int is_NT_Service;
|
|
|
|
|
2000-05-27 14:21:23 +08:00
|
|
|
void CommenceStartupProcessing( LPCTSTR serverName,
|
1999-06-18 02:46:02 +08:00
|
|
|
void(*stopper)(int));
|
|
|
|
void ReportSlapdShutdownComplete( void );
|
|
|
|
void *getRegParam( char *svc, char *value );
|
|
|
|
|
1999-11-02 06:00:18 +08:00
|
|
|
#define SERVICE_EXIT( e, n ) do { \
|
|
|
|
if ( is_NT_Service ) { \
|
|
|
|
SLAPDServiceStatus.dwWin32ExitCode = (e); \
|
|
|
|
SLAPDServiceStatus.dwServiceSpecificExitCode = (n); \
|
|
|
|
} \
|
|
|
|
} while ( 0 )
|
|
|
|
|
1999-06-18 02:46:02 +08:00
|
|
|
#else
|
|
|
|
#define SERVICE_EXIT( e, n )
|
1999-06-19 05:33:39 +08:00
|
|
|
#define MAIN_RETURN(x) return(x)
|
1999-06-18 02:46:02 +08:00
|
|
|
#endif
|
|
|
|
|
1999-11-02 06:00:18 +08:00
|
|
|
#ifdef HAVE_NT_EVENT_LOG
|
1999-11-02 05:25:22 +08:00
|
|
|
void LogSlapdStartedEvent( char *svc, int slap_debug, char *configfile, char *urls );
|
|
|
|
void LogSlapdStoppedEvent( char *svc );
|
|
|
|
#endif
|
|
|
|
|
1999-01-05 23:40:58 +08:00
|
|
|
/*
|
|
|
|
* when more than one slapd is running on one machine, each one might have
|
|
|
|
* it's own LOCAL for syslogging and must have its own pid/args files
|
|
|
|
*/
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
#ifndef HAVE_MKVERSION
|
1999-05-21 11:53:37 +08:00
|
|
|
const char Versionstr[] =
|
|
|
|
OPENLDAP_PACKAGE " " OPENLDAP_VERSION " Standalone LDAP Server (slapd)";
|
1999-05-19 09:12:33 +08:00
|
|
|
#endif
|
|
|
|
|
1999-01-05 23:40:58 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
|
|
|
|
#define DEFAULT_SYSLOG_USER LOG_LOCAL4
|
|
|
|
|
|
|
|
typedef struct _str2intDispatch {
|
1999-02-05 17:03:47 +08:00
|
|
|
char *stringVal;
|
|
|
|
int abbr;
|
|
|
|
int intVal;
|
1999-01-05 23:40:58 +08:00
|
|
|
} STRDISP, *STRDISP_P;
|
|
|
|
|
|
|
|
|
|
|
|
/* table to compute syslog-options to integer */
|
|
|
|
static STRDISP syslog_types[] = {
|
1999-08-25 14:44:08 +08:00
|
|
|
{ "LOCAL0", sizeof("LOCAL0"), LOG_LOCAL0 },
|
|
|
|
{ "LOCAL1", sizeof("LOCAL1"), LOG_LOCAL1 },
|
|
|
|
{ "LOCAL2", sizeof("LOCAL2"), LOG_LOCAL2 },
|
|
|
|
{ "LOCAL3", sizeof("LOCAL3"), LOG_LOCAL3 },
|
|
|
|
{ "LOCAL4", sizeof("LOCAL4"), LOG_LOCAL4 },
|
|
|
|
{ "LOCAL5", sizeof("LOCAL5"), LOG_LOCAL5 },
|
|
|
|
{ "LOCAL6", sizeof("LOCAL6"), LOG_LOCAL6 },
|
|
|
|
{ "LOCAL7", sizeof("LOCAL7"), LOG_LOCAL7 },
|
|
|
|
{ NULL }
|
1999-01-05 23:40:58 +08:00
|
|
|
};
|
|
|
|
|
1999-03-04 21:51:14 +08:00
|
|
|
static int cnvt_str2int( char *, STRDISP_P, int );
|
1999-01-05 23:40:58 +08:00
|
|
|
|
|
|
|
#endif /* LOG_LOCAL4 */
|
|
|
|
|
|
|
|
|
1998-11-05 14:49:49 +08:00
|
|
|
static void
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
usage( char *name )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-07-20 03:40:33 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"usage: %s options\n", name );
|
|
|
|
fprintf( stderr,
|
|
|
|
"\t-d level\tDebug Level" "\n"
|
|
|
|
"\t-f filename\tConfiguration File\n"
|
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
|
|
|
"\t-g group\tGroup (id or name) to ran as\n"
|
1999-04-02 06:31:24 +08:00
|
|
|
#endif
|
1999-08-06 04:50:40 +08:00
|
|
|
"\t-h URLs\tList of URLs to serve\n"
|
1999-01-05 23:40:58 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
1999-07-20 03:40:33 +08:00
|
|
|
"\t-l sysloguser\tSyslog User (default: LOCAL4)\n"
|
1999-04-03 11:19:07 +08:00
|
|
|
#endif
|
2000-05-27 14:21:23 +08:00
|
|
|
"\t-n serverName\tservice name\n"
|
2000-08-17 12:21:20 +08:00
|
|
|
#ifdef HAVE_CHROOT
|
|
|
|
"\t-r directory\n"
|
|
|
|
#endif
|
1999-07-20 03:40:33 +08:00
|
|
|
"\t-s level\tSyslog Level\n"
|
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
|
|
|
"\t-u user\tUser (id or name) to ran as\n"
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
1999-03-22 15:14:54 +08:00
|
|
|
|
1999-11-02 05:25:22 +08:00
|
|
|
#ifdef HAVE_NT_SERVICE_MANAGER
|
1999-06-18 02:46:02 +08:00
|
|
|
void WINAPI ServiceMain( DWORD argc, LPTSTR *argv )
|
|
|
|
#else
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
#endif
|
1999-06-19 07:53:05 +08:00
|
|
|
{
|
1999-09-05 04:24:40 +08:00
|
|
|
int i, no_detach = 0;
|
1999-04-02 00:32:11 +08:00
|
|
|
int rc;
|
1999-07-20 03:40:33 +08:00
|
|
|
char *urls = NULL;
|
1999-06-18 02:46:02 +08:00
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
|
|
|
char *username = NULL;
|
|
|
|
char *groupname = NULL;
|
1999-06-17 08:51:12 +08:00
|
|
|
#endif
|
2000-05-11 07:30:52 +08:00
|
|
|
#if defined(HAVE_CHROOT)
|
|
|
|
char *sandbox = NULL;
|
|
|
|
#endif
|
1999-01-05 23:40:58 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
int syslogUser = DEFAULT_SYSLOG_USER;
|
1999-04-03 11:19:07 +08:00
|
|
|
#endif
|
1999-11-02 06:00:18 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_NT_SERVICE_MANAGER
|
1999-06-18 02:46:02 +08:00
|
|
|
char *configfile = ".\\slapd.conf";
|
|
|
|
#else
|
|
|
|
char *configfile = SLAPD_DEFAULT_CONFIGFILE;
|
1999-01-05 23:40:58 +08:00
|
|
|
#endif
|
2000-05-27 03:52:40 +08:00
|
|
|
char *serverName = NULL;
|
1999-02-12 22:36:16 +08:00
|
|
|
int serverMode = SLAP_SERVER_MODE;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-08-20 01:06:28 +08:00
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
FILE *leakfile;
|
|
|
|
if( ( leakfile = fopen( "slapd.leak", "w" )) == NULL ) {
|
|
|
|
leakfile = stderr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
g_argc = argc;
|
|
|
|
g_argv = argv;
|
|
|
|
|
1999-11-02 05:25:22 +08:00
|
|
|
#ifdef HAVE_NT_SERVICE_MANAGER
|
1999-06-18 02:46:02 +08:00
|
|
|
{
|
1999-07-20 03:40:33 +08:00
|
|
|
int *i;
|
1999-06-18 02:46:02 +08:00
|
|
|
char *newConfigFile;
|
2000-05-12 04:50:20 +08:00
|
|
|
char *newUrls;
|
2000-05-13 05:26:30 +08:00
|
|
|
char *regService = NULL;
|
1999-08-31 13:18:06 +08:00
|
|
|
|
|
|
|
if ( is_NT_Service ) {
|
2000-05-27 14:21:23 +08:00
|
|
|
serverName = argv[0];
|
|
|
|
CommenceStartupProcessing( serverName, slap_sig_shutdown );
|
|
|
|
if ( strcmp(serverName, SERVICE_NAME) )
|
|
|
|
regService = serverName;
|
1999-08-31 13:18:06 +08:00
|
|
|
}
|
|
|
|
|
2000-05-13 05:26:30 +08:00
|
|
|
i = (int*)getRegParam( regService, "DebugLevel" );
|
1999-07-20 03:40:33 +08:00
|
|
|
if ( i != NULL )
|
1999-06-18 02:46:02 +08:00
|
|
|
{
|
1999-07-20 03:40:33 +08:00
|
|
|
slap_debug = *i;
|
1999-06-18 02:46:02 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "new debug level from registry is: %d\n", slap_debug, 0, 0 );
|
|
|
|
}
|
2000-05-12 04:50:20 +08:00
|
|
|
|
2000-05-13 05:26:30 +08:00
|
|
|
newUrls = (char *) getRegParam(regService, "Urls");
|
2000-05-12 04:50:20 +08:00
|
|
|
if (newUrls)
|
|
|
|
{
|
|
|
|
if (urls)
|
|
|
|
ch_free(urls);
|
|
|
|
|
|
|
|
urls = ch_strdup(newUrls);
|
|
|
|
Debug(LDAP_DEBUG_ANY, "new urls from registry: %s\n",
|
|
|
|
urls, 0, 0);
|
|
|
|
}
|
|
|
|
|
2000-05-13 05:26:30 +08:00
|
|
|
newConfigFile = (char*)getRegParam( regService, "ConfigFile" );
|
1999-06-18 02:46:02 +08:00
|
|
|
if ( newConfigFile != NULL )
|
|
|
|
{
|
|
|
|
configfile = newConfigFile;
|
|
|
|
Debug ( LDAP_DEBUG_ANY, "new config file from registry is: %s\n", configfile, 0, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-02 06:31:24 +08:00
|
|
|
while ( (i = getopt( argc, argv,
|
2000-05-27 03:52:40 +08:00
|
|
|
"d:f:h:s:n:"
|
2000-05-11 07:30:52 +08:00
|
|
|
#ifdef HAVE_CHROOT
|
|
|
|
"r:"
|
|
|
|
#endif
|
1999-04-02 06:31:24 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
"l:"
|
|
|
|
#endif
|
1999-04-21 08:40:20 +08:00
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
|
|
|
"u:g:"
|
1999-02-12 22:36:16 +08:00
|
|
|
#endif
|
1999-04-02 06:31:24 +08:00
|
|
|
)) != EOF ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
switch ( i ) {
|
1999-07-20 03:40:33 +08:00
|
|
|
case 'h': /* listen URLs */
|
1999-08-22 11:36:19 +08:00
|
|
|
if ( urls != NULL ) free( urls );
|
1999-07-20 03:40:33 +08:00
|
|
|
urls = ch_strdup( optarg );
|
1999-03-17 11:56:25 +08:00
|
|
|
break;
|
|
|
|
|
1999-09-05 04:24:40 +08:00
|
|
|
case 'd': /* set debug level and 'do not detach' flag */
|
|
|
|
no_detach = 1;
|
1998-08-09 08:43:13 +08:00
|
|
|
#ifdef LDAP_DEBUG
|
1999-07-20 03:40:33 +08:00
|
|
|
slap_debug |= atoi( optarg );
|
1998-08-09 08:43:13 +08:00
|
|
|
#else
|
1999-09-05 04:24:40 +08:00
|
|
|
if ( atoi( optarg ) != 0 )
|
|
|
|
fputs( "must compile with LDAP_DEBUG for debugging\n",
|
|
|
|
stderr );
|
1998-08-09 08:43:13 +08:00
|
|
|
#endif
|
1999-09-05 04:24:40 +08:00
|
|
|
break;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
case 'f': /* read config file */
|
1998-11-28 04:21:54 +08:00
|
|
|
configfile = ch_strdup( optarg );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's': /* set syslog level */
|
|
|
|
ldap_syslog = atoi( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-01-05 23:40:58 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
case 'l': /* set syslog local user */
|
1999-07-20 03:40:33 +08:00
|
|
|
syslogUser = cnvt_str2int( optarg,
|
|
|
|
syslog_types, DEFAULT_SYSLOG_USER );
|
1999-01-05 23:40:58 +08:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2000-05-11 07:30:52 +08:00
|
|
|
#ifdef HAVE_CHROOT
|
|
|
|
case 'r':
|
|
|
|
if( sandbox ) free(sandbox);
|
|
|
|
sandbox = ch_strdup( optarg );
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1999-05-01 05:32:12 +08:00
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
1999-04-21 08:40:20 +08:00
|
|
|
case 'u': /* user name */
|
|
|
|
if( username ) free(username);
|
1999-04-03 11:19:07 +08:00
|
|
|
username = ch_strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
1999-04-21 08:40:20 +08:00
|
|
|
case 'g': /* group name */
|
|
|
|
if( groupname ) free(groupname);
|
1999-04-03 11:19:07 +08:00
|
|
|
groupname = ch_strdup( optarg );
|
|
|
|
break;
|
1999-04-21 08:40:20 +08:00
|
|
|
#endif /* SETUID && GETUID */
|
1999-07-20 03:40:33 +08:00
|
|
|
|
1999-06-19 07:53:05 +08:00
|
|
|
case 'n': /* NT service name */
|
2000-05-27 03:52:40 +08:00
|
|
|
if( serverName != NULL ) free( serverName );
|
|
|
|
serverName = ch_strdup( optarg );
|
1999-06-19 05:33:39 +08:00
|
|
|
break;
|
2000-05-27 03:52:40 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
default:
|
|
|
|
usage( argv[0] );
|
1999-06-18 02:46:02 +08:00
|
|
|
rc = 1;
|
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 15 );
|
|
|
|
goto stop;
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-26 00:50:45 +08:00
|
|
|
#ifdef NEW_LOGGING
|
|
|
|
lutil_log_initialize( argc, argv );
|
|
|
|
#endif
|
|
|
|
|
2000-10-14 04:24:49 +08:00
|
|
|
lutil_set_debug_level( "slapd", slap_debug );
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &slap_debug);
|
1998-12-22 09:34:01 +08:00
|
|
|
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &slap_debug);
|
|
|
|
ldif_debug = slap_debug;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "%s", Versionstr, 0, 0 );
|
|
|
|
|
2000-05-27 03:52:40 +08:00
|
|
|
if( serverName == NULL ) {
|
|
|
|
if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
|
|
|
|
serverName = ch_strdup( argv[0] );
|
|
|
|
} else {
|
|
|
|
serverName = ch_strdup( serverName + 1 );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LOG_LOCAL4
|
1999-01-05 23:40:58 +08:00
|
|
|
openlog( serverName, OPENLOG_OPTIONS, syslogUser );
|
1999-11-02 02:14:26 +08:00
|
|
|
#elif LOG_DEBUG
|
1999-01-05 23:40:58 +08:00
|
|
|
openlog( serverName, OPENLOG_OPTIONS );
|
1998-08-09 08:43:13 +08:00
|
|
|
#endif
|
|
|
|
|
1999-12-13 02:45:06 +08:00
|
|
|
if( slapd_daemon_init( urls ) != 0 ) {
|
1999-07-20 04:48:19 +08:00
|
|
|
rc = 1;
|
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
|
|
|
|
goto stop;
|
|
|
|
}
|
1999-07-20 03:40:33 +08:00
|
|
|
|
2000-05-11 07:30:52 +08:00
|
|
|
#if defined(HAVE_CHROOT)
|
2000-10-10 07:38:30 +08:00
|
|
|
if ( sandbox ) {
|
|
|
|
if ( chdir( sandbox ) ) {
|
|
|
|
perror("chdir");
|
|
|
|
rc = 1;
|
|
|
|
goto stop;
|
|
|
|
}
|
|
|
|
if ( chroot( sandbox ) ) {
|
|
|
|
perror("chroot");
|
|
|
|
rc = 1;
|
|
|
|
goto stop;
|
|
|
|
}
|
2000-05-11 07:30:52 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-21 08:40:20 +08:00
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
1999-07-20 03:40:33 +08:00
|
|
|
if ( username != NULL || groupname != NULL ) {
|
1999-04-03 11:19:07 +08:00
|
|
|
slap_init_user( username, groupname );
|
1999-07-20 03:40:33 +08:00
|
|
|
}
|
1999-04-03 11:19:07 +08:00
|
|
|
#endif
|
|
|
|
|
1999-12-10 06:33:22 +08:00
|
|
|
extops_init();
|
|
|
|
|
1999-11-10 05:22:12 +08:00
|
|
|
#ifdef SLAPD_MODULES
|
|
|
|
if ( module_init() != 0 ) {
|
|
|
|
rc = 1;
|
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 17 );
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
if ( slap_init( serverMode, serverName ) != 0 ) {
|
1999-02-05 17:03:47 +08:00
|
|
|
rc = 1;
|
1999-06-18 02:46:02 +08:00
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
|
1999-02-05 17:03:47 +08:00
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2000-05-16 04:04:36 +08:00
|
|
|
if ( schema_init( ) != 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"schema initialization error\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
if ( read_config( configfile ) != 0 ) {
|
|
|
|
rc = 1;
|
1999-06-18 02:46:02 +08:00
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
|
1999-02-05 17:03:47 +08:00
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
2000-05-16 04:04:36 +08:00
|
|
|
if ( schema_prep( ) != 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"schema prep error\n",
|
|
|
|
0, 0, 0 );
|
|
|
|
goto destroy;
|
|
|
|
}
|
|
|
|
|
1999-07-16 05:07:01 +08:00
|
|
|
#ifdef HAVE_TLS
|
2000-09-22 05:30:02 +08:00
|
|
|
rc = ldap_pvt_tls_init();
|
2000-05-12 04:50:20 +08:00
|
|
|
|
2000-09-22 05:30:02 +08:00
|
|
|
if (rc || ldap_pvt_tls_init_def_ctx() != 0) {
|
2000-05-12 04:50:20 +08:00
|
|
|
rc = 1;
|
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
|
|
|
|
goto destroy;
|
|
|
|
}
|
1999-07-16 05:07:01 +08:00
|
|
|
#endif
|
|
|
|
|
1999-08-31 13:18:06 +08:00
|
|
|
(void) SIGNAL( LDAP_SIGUSR1, slap_sig_wake );
|
|
|
|
(void) SIGNAL( LDAP_SIGUSR2, slap_sig_shutdown );
|
|
|
|
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef SIGPIPE
|
1999-03-22 15:14:54 +08:00
|
|
|
(void) SIGNAL( SIGPIPE, SIG_IGN );
|
1999-03-02 06:37:05 +08:00
|
|
|
#endif
|
|
|
|
#ifdef SIGHUP
|
1999-08-31 13:18:06 +08:00
|
|
|
(void) SIGNAL( SIGHUP, slap_sig_shutdown );
|
1999-03-02 06:37:05 +08:00
|
|
|
#endif
|
1999-08-31 13:18:06 +08:00
|
|
|
(void) SIGNAL( SIGINT, slap_sig_shutdown );
|
|
|
|
(void) SIGNAL( SIGTERM, slap_sig_shutdown );
|
1999-03-29 17:04:35 +08:00
|
|
|
#ifdef LDAP_SIGCHLD
|
|
|
|
(void) SIGNAL( LDAP_SIGCHLD, wait4child );
|
1999-03-28 00:21:44 +08:00
|
|
|
#endif
|
1999-06-19 07:53:05 +08:00
|
|
|
#ifdef SIGBREAK
|
1999-06-19 05:33:39 +08:00
|
|
|
/* SIGBREAK is generated when Ctrl-Break is pressed. */
|
1999-08-31 13:18:06 +08:00
|
|
|
(void) SIGNAL( SIGBREAK, slap_sig_shutdown );
|
1999-06-18 02:46:02 +08:00
|
|
|
#endif
|
1999-02-07 00:00:00 +08:00
|
|
|
|
1999-06-18 02:46:02 +08:00
|
|
|
#ifndef HAVE_WINSOCK
|
1999-11-02 06:00:18 +08:00
|
|
|
lutil_detach( no_detach, 0 );
|
1999-07-20 03:40:33 +08:00
|
|
|
#endif /* HAVE_WINSOCK */
|
1999-02-05 17:03:47 +08:00
|
|
|
|
1999-08-20 01:06:28 +08:00
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
mal_leaktrace(1);
|
|
|
|
#endif
|
|
|
|
|
1999-08-18 03:00:59 +08:00
|
|
|
if ( slap_startup( NULL ) != 0 ) {
|
1999-03-22 15:14:54 +08:00
|
|
|
rc = 1;
|
2000-05-12 04:50:20 +08:00
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 21 );
|
1999-03-22 15:14:54 +08:00
|
|
|
goto shutdown;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
{
|
1999-03-22 15:14:54 +08:00
|
|
|
FILE *fp;
|
1998-12-30 08:06:27 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "slapd starting\n", 0, 0, 0 );
|
1998-12-30 08:06:27 +08:00
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
if (( slapd_pid_file != NULL ) &&
|
|
|
|
(( fp = fopen( slapd_pid_file, "w" )) != NULL ))
|
|
|
|
{
|
|
|
|
fprintf( fp, "%d\n", (int) getpid() );
|
|
|
|
fclose( fp );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
1999-03-22 15:14:54 +08:00
|
|
|
if (( slapd_args_file != NULL ) &&
|
|
|
|
(( fp = fopen( slapd_args_file, "w" )) != NULL ))
|
|
|
|
{
|
|
|
|
for ( i = 0; i < g_argc; i++ ) {
|
|
|
|
fprintf( fp, "%s ", g_argv[i] );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-03-22 15:14:54 +08:00
|
|
|
fprintf( fp, "\n" );
|
|
|
|
fclose( fp );
|
|
|
|
}
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-11-02 06:00:18 +08:00
|
|
|
#ifdef HAVE_NT_EVENT_LOG
|
2000-05-12 04:50:20 +08:00
|
|
|
if (is_NT_Service)
|
2000-05-27 14:21:23 +08:00
|
|
|
LogSlapdStartedEvent( serverName, slap_debug, configfile, urls );
|
1999-06-18 02:46:02 +08:00
|
|
|
#endif
|
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
rc = slapd_daemon();
|
1999-06-18 02:46:02 +08:00
|
|
|
|
1999-11-02 05:25:22 +08:00
|
|
|
#ifdef HAVE_NT_SERVICE_MANAGER
|
1999-06-19 05:33:39 +08:00
|
|
|
/* Throw away the event that we used during the startup process. */
|
1999-06-18 02:46:02 +08:00
|
|
|
if ( is_NT_Service )
|
|
|
|
ldap_pvt_thread_cond_destroy( &started_event );
|
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
shutdown:
|
1999-02-08 19:42:14 +08:00
|
|
|
/* remember an error during shutdown */
|
1999-08-18 03:00:59 +08:00
|
|
|
rc |= slap_shutdown( NULL );
|
1999-08-20 01:06:28 +08:00
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
destroy:
|
1999-02-08 19:42:14 +08:00
|
|
|
/* remember an error during destroy */
|
|
|
|
rc |= slap_destroy();
|
|
|
|
|
1999-11-10 05:22:12 +08:00
|
|
|
#ifdef SLAPD_MODULES
|
|
|
|
module_kill();
|
|
|
|
#endif
|
|
|
|
|
1999-12-10 06:33:22 +08:00
|
|
|
extops_kill();
|
|
|
|
|
1999-06-18 02:46:02 +08:00
|
|
|
stop:
|
1999-11-02 06:00:18 +08:00
|
|
|
#ifdef HAVE_NT_EVENT_LOG
|
2000-05-12 04:50:20 +08:00
|
|
|
if (is_NT_Service)
|
2000-05-27 14:21:23 +08:00
|
|
|
LogSlapdStoppedEvent( serverName );
|
1999-06-18 02:46:02 +08:00
|
|
|
#endif
|
1999-07-20 03:40:33 +08:00
|
|
|
|
1999-02-08 19:42:14 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "slapd stopped.\n", 0, 0, 0 );
|
1999-07-20 03:40:33 +08:00
|
|
|
|
1999-11-02 05:25:22 +08:00
|
|
|
#ifdef HAVE_NT_SERVICE_MANAGER
|
1999-06-18 02:46:02 +08:00
|
|
|
ReportSlapdShutdownComplete();
|
|
|
|
#endif
|
1999-02-08 19:42:14 +08:00
|
|
|
|
1999-11-02 02:14:26 +08:00
|
|
|
#ifdef LOG_DEBUG
|
1999-06-18 02:46:02 +08:00
|
|
|
closelog();
|
1999-11-02 02:14:26 +08:00
|
|
|
#endif
|
1999-07-20 03:40:33 +08:00
|
|
|
slapd_daemon_destroy();
|
1999-04-06 09:55:11 +08:00
|
|
|
|
1999-08-20 01:06:28 +08:00
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
mal_dumpleaktrace( leakfile );
|
|
|
|
#endif
|
|
|
|
|
1999-06-19 05:33:39 +08:00
|
|
|
MAIN_RETURN(rc);
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-05 23:40:58 +08:00
|
|
|
|
|
|
|
|
1999-03-29 17:04:35 +08:00
|
|
|
#ifdef LDAP_SIGCHLD
|
1999-03-28 00:21:44 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Catch and discard terminated child processes, to avoid zombies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static RETSIGTYPE
|
|
|
|
wait4child( int sig )
|
|
|
|
{
|
|
|
|
int save_errno = errno;
|
1999-04-02 12:12:18 +08:00
|
|
|
|
|
|
|
#ifdef WNOHANG
|
1999-03-28 00:21:44 +08:00
|
|
|
errno = 0;
|
1999-04-02 12:12:18 +08:00
|
|
|
#ifdef HAVE_WAITPID
|
1999-03-28 00:21:44 +08:00
|
|
|
while ( waitpid( (pid_t)-1, NULL, WNOHANG ) >= 0 || errno == EINTR )
|
|
|
|
; /* NULL */
|
1999-04-02 12:12:18 +08:00
|
|
|
#else
|
1999-03-28 00:21:44 +08:00
|
|
|
while ( wait3( NULL, WNOHANG, NULL ) >= 0 || errno == EINTR )
|
|
|
|
; /* NULL */
|
1999-04-02 12:12:18 +08:00
|
|
|
#endif
|
1999-04-02 16:30:02 +08:00
|
|
|
#else
|
1999-03-28 00:21:44 +08:00
|
|
|
(void) wait( NULL );
|
|
|
|
#endif
|
2000-07-22 08:37:51 +08:00
|
|
|
(void) SIGNAL_REINSTALL( sig, wait4child );
|
1999-03-28 00:21:44 +08:00
|
|
|
errno = save_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SIGCHLD || SIGCLD */
|
|
|
|
|
|
|
|
|
1999-01-05 23:40:58 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a string to an integer by means of a dispatcher table
|
|
|
|
* if the string is not in the table return the default
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
1999-03-04 21:51:14 +08:00
|
|
|
cnvt_str2int( char *stringVal, STRDISP_P dispatcher, int defaultVal )
|
1999-01-05 23:40:58 +08:00
|
|
|
{
|
|
|
|
int retVal = defaultVal;
|
|
|
|
STRDISP_P disp;
|
|
|
|
|
|
|
|
for (disp = dispatcher; disp->stringVal; disp++) {
|
|
|
|
|
|
|
|
if (!strncasecmp (stringVal, disp->stringVal, disp->abbr)) {
|
|
|
|
|
|
|
|
retVal = disp->intVal;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (retVal);
|
1999-07-20 03:40:33 +08:00
|
|
|
}
|
1999-01-05 23:40:58 +08:00
|
|
|
|
|
|
|
#endif /* LOG_LOCAL4 */
|