/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2003 The OpenLDAP Foundation.
+ * Copyright 1998-2004 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "ldif.h"
#ifdef LDAP_SLAPI
-#include "slapi.h"
+#include "slapi/slapi.h"
#endif
#ifdef LDAP_SIGCHLD
#define MAIN_RETURN(x) return(x)
#endif
+typedef int (MainFunc) LDAP_P(( int argc, char *argv[] ));
+extern MainFunc slapadd, slapcat, slapindex, slappasswd;
+
+static struct {
+ char *name;
+ MainFunc *func;
+} tools[] = {
+ {"slapadd", slapadd},
+ {"slapcat", slapcat},
+ {"slapindex", slapindex},
+ {"slappasswd", slappasswd},
+ {NULL, NULL}
+};
+
/*
* 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
fprintf( stderr,
"\t-4\t\tIPv4 only\n"
"\t-6\t\tIPv6 only\n"
+ "\t-T (a|c|i|p)\tRun in Tool mode\n"
"\t-c cookie\tSync cookie of consumer\n"
"\t-d level\tDebug level" "\n"
"\t-f filename\tConfiguration file\n"
#else
char *configfile = SLAPD_DEFAULT_CONFIGFILE;
#endif
- char *serverName = NULL;
+ char *serverName;
int serverMode = SLAP_SERVER_MODE;
struct berval cookie = { 0, NULL };
sl_mem_init();
+ serverName = lutil_progname( "slapd", argc, argv );
+
+ if ( strcmp( serverName, "slapd" ) ) {
+ for (i=0; tools[i].name; i++) {
+ if ( !strcmp( serverName, tools[i].name ) ) {
+ rc = tools[i].func(argc, argv);
+ MAIN_RETURN(rc);
+ }
+ }
+ }
+
#ifdef HAVE_NT_SERVICE_MANAGER
{
int *i;
char *regService = NULL;
if ( is_NT_Service ) {
- serverName = argv[0];
lutil_CommenceStartupProcessing( serverName, slap_sig_shutdown );
if ( strcmp(serverName, SERVICE_NAME) )
regService = serverName;
#endif
while ( (i = getopt( argc, argv,
- "c:d:f:h:s:n:t:V"
+ "c:d:f:h:s:n:t:T:V"
#if LDAP_PF_INET6
"46"
#endif
#endif /* SETUID && GETUID */
case 'n': /* NT service name */
- if( serverName != NULL ) free( serverName );
serverName = ch_strdup( optarg );
break;
version++;
break;
+ case 'T':
+ for (i=0; tools[i].name; i++) {
+ if ( optarg[0] == tools[i].name[4] ) {
+ rc = tools[i].func(argc, argv);
+ MAIN_RETURN(rc);
+ }
+ }
+ /* FALLTHRU */
default:
usage( argv[0] );
rc = 1;
if ( version > 1 ) goto stop;
}
- if( serverName == NULL ) {
- if ( (serverName = strrchr( argv[0], *LDAP_DIRSEP )) == NULL ) {
- serverName = argv[0];
- } else {
- serverName = serverName + 1;
- }
- }
+ {
+ char *logName;
+#ifdef HAVE_EBCDIC
+ logName = ch_strdup( serverName );
+ __atoe( logName );
+#else
+ logName = serverName;
+#endif
#ifdef LOG_LOCAL4
- openlog( serverName, OPENLOG_OPTIONS, syslogUser );
+ openlog( logName, OPENLOG_OPTIONS, syslogUser );
#elif LOG_DEBUG
- openlog( serverName, OPENLOG_OPTIONS );
+ openlog( logName, OPENLOG_OPTIONS );
#endif
+#ifdef HAVE_EBCDIC
+ free( logName );
+#endif
+ }
#ifdef NEW_LOGGING
LDAP_LOG( SLAPD, INFO, "%s", Versionstr, 0, 0 );
#endif
#ifdef LDAP_SLAPI
- if ( slapi_init() != 0 ) {
+ if ( slapi_int_initialize() != 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT, "main: slapi initialization error\n", 0, 0, 0 );
#else
}
#endif /* LDAP_SLAPI */
+ if ( overlay_init() ) {
+ goto destroy;
+ }
+
if ( read_config( configfile, 0 ) != 0 ) {
rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );