1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-05 07:59:13 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* 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/signal.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 */
|
1999-11-28 07:40:08 +08:00
|
|
|
LIBLUTIL_F (SERVICE_STATUS) SLAPDServiceStatus;
|
|
|
|
LIBLUTIL_F (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;
|
|
|
|
|
|
|
|
void CommenceStartupProcessing( LPCTSTR serviceName,
|
|
|
|
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,
|
1999-04-21 08:40:20 +08:00
|
|
|
#if LDAP_CONNECTIONLESS
|
1999-07-20 03:40:33 +08:00
|
|
|
"\t-c\t\tEnable (experimental) Connectionless LDAP\n"
|
1999-04-21 08:40:20 +08:00
|
|
|
#endif
|
1999-07-20 03:40:33 +08:00
|
|
|
"\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
|
1999-11-02 06:00:18 +08:00
|
|
|
#ifdef HAVE_NT_EVENT_LOG
|
1999-07-20 03:40:33 +08:00
|
|
|
"\t-n NTserviceName\tNT service name\n"
|
1999-01-05 23:40:58 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
"\t-s level\tSyslog Level\n"
|
|
|
|
#ifdef SLAPD_BDB2
|
|
|
|
"\t-t\t\tEnable BDB2 timing\n"
|
1999-07-14 21:16:13 +08:00
|
|
|
#endif
|
1999-07-20 03:40:33 +08:00
|
|
|
#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
|
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_EVENT_LOG
|
1999-06-19 05:33:39 +08:00
|
|
|
char *NTservice = SERVICE_NAME;
|
1999-11-02 06:00:18 +08:00
|
|
|
#endif
|
|
|
|
#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
|
1999-01-21 23:53:54 +08:00
|
|
|
char *serverName;
|
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;
|
1999-08-31 13:18:06 +08:00
|
|
|
|
|
|
|
if ( is_NT_Service ) {
|
|
|
|
CommenceStartupProcessing( NTservice, slap_sig_shutdown );
|
|
|
|
}
|
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
i = (int*)getRegParam( NULL, "DebugLevel" );
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
newConfigFile = (char*)getRegParam( NULL, "ConfigFile" );
|
|
|
|
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,
|
1999-12-13 02:45:06 +08:00
|
|
|
"d:f:h:s:"
|
1999-04-02 06:31:24 +08:00
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
"l:"
|
|
|
|
#endif
|
1999-02-12 22:36:16 +08:00
|
|
|
#ifdef SLAPD_BDB2
|
1999-04-02 06:31:24 +08:00
|
|
|
"t"
|
1999-04-03 11:19:07 +08:00
|
|
|
#endif
|
1999-04-21 08:40:20 +08:00
|
|
|
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
|
|
|
|
"u:g:"
|
1999-05-19 09:12:33 +08:00
|
|
|
#endif
|
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
|
|
|
"c"
|
1999-06-19 05:33:39 +08:00
|
|
|
#endif
|
1999-11-02 06:00:18 +08:00
|
|
|
#ifdef HAVE_NT_EVENT_LOG
|
1999-06-19 07:53:05 +08:00
|
|
|
"n:"
|
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
|
|
|
|
|
1999-04-21 08:40:20 +08:00
|
|
|
#ifdef LDAP_CONNECTIONLESS
|
|
|
|
case 'c': /* do connectionless (udp) */
|
1999-08-02 15:40:15 +08:00
|
|
|
/* udp = 1; */
|
|
|
|
fprintf( stderr, "connectionless support not supported");
|
1999-08-04 02:14:24 +08:00
|
|
|
exit( EXIT_FAILURE );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
1999-04-21 08:40:20 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-02-12 22:36:16 +08:00
|
|
|
#ifdef SLAPD_BDB2
|
|
|
|
case 't': /* timed server */
|
1999-08-18 03:00:59 +08:00
|
|
|
serverMode |= SLAP_TIMED_MODE;
|
1999-02-12 22:36:16 +08:00
|
|
|
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-11-02 06:00:18 +08:00
|
|
|
#ifdef HAVE_NT_EVENT_LOG
|
1999-06-19 07:53:05 +08:00
|
|
|
case 'n': /* NT service name */
|
1999-06-19 05:33:39 +08:00
|
|
|
NTservice = ch_strdup( optarg );
|
|
|
|
break;
|
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
|
1999-06-19 05:33:39 +08:00
|
|
|
if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
|
1999-01-05 23:40:58 +08:00
|
|
|
serverName = ch_strdup( argv[0] );
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
1999-01-05 23:40:58 +08:00
|
|
|
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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-07-16 05:07:01 +08:00
|
|
|
#ifdef HAVE_TLS
|
|
|
|
ldap_pvt_tls_init();
|
|
|
|
ldap_pvt_tls_init_def_ctx();
|
|
|
|
#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;
|
1999-06-18 02:46:02 +08:00
|
|
|
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
|
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
|
1999-07-20 03:40:33 +08:00
|
|
|
LogSlapdStartedEvent( NTservice, 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
|
1999-06-19 05:33:39 +08:00
|
|
|
LogSlapdStoppedEvent( NTservice );
|
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
|
1999-04-02 12:12:18 +08:00
|
|
|
(void) SIGNAL( 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 */
|