/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2006 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 2003 IBM Corporation.
* All rights reserved.
case SLAPADD:
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n"
- "\t[-l ldiffile] [-q] [-u] [-w]\n";
+ "\t[-l ldiffile] [-q] [-u] [-s] [-w]\n";
break;
case SLAPAUTH:
* argc, argv command line arguments
*/
+static int need_shutdown;
+
void
slap_tool_init(
const char* progname,
char *filterstr = NULL;
char *subtree = NULL;
char *ldiffile = NULL;
+ char **debug_unknowns = NULL;
int rc, i, dbnum;
int mode = SLAP_TOOL_MODE;
int truncatemode = 0;
#ifdef LDAP_DEBUG
/* tools default to "none", so that at least LDAP_DEBUG_ANY
* messages show up; use -d 0 to reset */
- ldap_debug = LDAP_DEBUG_NONE;
+ slap_debug = LDAP_DEBUG_NONE;
#endif
#ifdef CSRIMALLOC
switch( tool ) {
case SLAPADD:
- options = "b:cd:f:F:gl:n:qtuvw";
+ options = "b:cd:f:F:gl:n:qstuvw";
break;
case SLAPCAT:
continuemode++;
break;
- case 'd': /* turn on debugging */
- {
-#ifdef LDAP_DEBUG
- int level;
-
- if ( optarg != NULL && optarg[ 0 ] != '-' && !isdigit( optarg[ 0 ] ) )
- {
- if ( str2loglevel( optarg, &level ) ) {
- fprintf( stderr,
- "unrecognized log level "
- "\"%s\"\n", optarg );
- exit( EXIT_FAILURE );
- }
-
- } else if ( lutil_atoix( &level, optarg, 0 ) != 0 ) {
- fprintf( stderr,
- "unrecognized log level "
- "\"%s\"\n", optarg );
- exit( EXIT_FAILURE );
+ case 'd': { /* turn on debugging */
+ int level = 0;
+
+ if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
+ usage( tool, progname );
}
+#ifdef LDAP_DEBUG
+ if ( level == 0 ) {
+ /* allow to reset log level */
+ slap_debug = 0;
- if ( level ) {
- ldap_debug |= level;
} else {
- /* allow to reset log level */
- ldap_debug = 0;
+ slap_debug |= level;
}
#else
- if ( lutil_atoi( &level, optarg ) != 0 || level != 0 )
+ if ( level != 0 )
fputs( "must compile with LDAP_DEBUG for debugging\n",
stderr );
#endif
break;
case 's': /* dump subtree */
- subtree = strdup( optarg );
+ if ( tool == SLAPADD )
+ mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
+ else if ( tool == SLAPCAT )
+ subtree = strdup( optarg );
break;
case 't': /* turn on truncate */
exit( EXIT_FAILURE );
}
+ if ( debug_unknowns ) {
+ rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
+ ldap_charray_free( debug_unknowns );
+ debug_unknowns = NULL;
+ if ( rc )
+ exit( EXIT_FAILURE );
+ }
+
at_oc_cache = 1;
switch ( tool ) {
}
/* slapdn doesn't specify a backend to startup */
- if ( !dryrun && tool != SLAPDN && slap_startup( be ) ) {
- switch ( tool ) {
- case SLAPTEST:
- fprintf( stderr, "slap_startup failed "
- "(test would succeed using "
- "the -u switch)\n" );
- break;
+ if ( !dryrun && tool != SLAPDN ) {
+ need_shutdown = 1;
+
+ if ( slap_startup( be ) ) {
+ switch ( tool ) {
+ case SLAPTEST:
+ fprintf( stderr, "slap_startup failed "
+ "(test would succeed using "
+ "the -u switch)\n" );
+ break;
+
+ default:
+ fprintf( stderr, "slap_startup failed\n" );
+ break;
+ }
- default:
- fprintf( stderr, "slap_startup failed\n" );
- break;
+ exit( EXIT_FAILURE );
}
-
- exit( EXIT_FAILURE );
}
}
void slap_tool_destroy( void )
{
if ( !dryrun ) {
- slap_shutdown( be );
+ if ( need_shutdown ) {
+ slap_shutdown( be );
+ }
slap_destroy();
}
#ifdef SLAPD_MODULES