/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2010 The OpenLDAP Foundation.
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
* Portions Copyright 2003 IBM Corporation.
* All rights reserved.
case SLAPCAT:
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
- " [-l ldiffile] [-a filter]\n";
+ " [-l ldiffile] [-a filter] [-s subtree]\n";
break;
case SLAPDN:
break;
case SLAPTEST:
- options = " [-u]\n";
+ options = " [-n databasenumber] [-u]\n";
+ break;
+
+ case SLAPSCHEMA:
+ options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
+ " [-l errorfile] [-a filter] [-s subtree]\n";
break;
}
char *subtree = NULL;
char *ldiffile = NULL;
char **debug_unknowns = NULL;
- int rc, i, dbnum;
+ int rc, i;
int mode = SLAP_TOOL_MODE;
int truncatemode = 0;
int use_glue = 1;
+ int writer;
#ifdef LDAP_DEBUG
/* tools default to "none", so that at least LDAP_DEBUG_ANY
* messages show up; use -d 0 to reset */
slap_debug = LDAP_DEBUG_NONE;
+ ldif_debug = slap_debug;
#endif
ldap_syslog = 0;
leakfile = stderr;
}
free( leakfilename );
+ leakfilename = NULL;
#endif
switch( tool ) {
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
break;
+ case SLAPSCHEMA:
+ options = "a:b:cd:f:F:gl:n:o:s:v";
+ mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
+ break;
+
case SLAPTEST:
- options = "d:f:F:o:Quv";
+ options = "d:f:F:n:o:Quv";
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
break;
break;
case 'n': /* which config file db to index */
- if ( lutil_atoi( &dbnum, optarg ) ) {
+ if ( lutil_atoi( &dbnum, optarg ) || dbnum < 0 ) {
usage( tool, progname );
}
break;
case 's': /* dump subtree */
if ( tool == SLAPADD )
mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
- else if ( tool == SLAPCAT )
+ else if ( tool == SLAPCAT || tool == SLAPSCHEMA )
subtree = ch_strdup( optarg );
break;
#endif
#ifdef HAVE_EBCDIC
free( logName );
+ logName = NULL;
#endif
}
#endif /* LDAP_DEBUG && LDAP_SYSLOG */
+ switch ( tool ) {
+ case SLAPCAT:
+ case SLAPSCHEMA:
+ writer = 1;
+ break;
+
+ default:
+ writer = 0;
+ break;
+ }
+
switch ( tool ) {
case SLAPADD:
case SLAPCAT:
+ case SLAPSCHEMA:
if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
usage( tool, progname );
}
}
if ( ldiffile == NULL ) {
- dummy.fp = tool == SLAPCAT ? stdout : stdin;
+ dummy.fp = writer ? stdout : stdin;
ldiffp = &dummy;
- } else if ((ldiffp = ldif_open( ldiffile, tool == SLAPCAT ? "w" : "r" ))
+ } else if ((ldiffp = ldif_open( ldiffile, writer ? "w" : "r" ))
== NULL )
{
perror( ldiffile );
case SLAPADD:
case SLAPCAT:
case SLAPINDEX:
+ case SLAPSCHEMA:
if ( !nbackends ) {
fprintf( stderr, "No databases found "
"in config file\n" );
}
if ( use_glue ) {
- rc = glue_sub_attach();
+ rc = glue_sub_attach( 0 );
if ( rc != 0 ) {
fprintf( stderr,
}
switch ( tool ) {
- case SLAPDN:
case SLAPTEST:
+ if ( dbnum >= 0 )
+ goto get_db;
+ /* FALLTHRU */
+ case SLAPDN:
case SLAPAUTH:
be = NULL;
goto startup;
fprintf( stderr, "Invalid filter '%s'\n", filterstr );
exit( EXIT_FAILURE );
}
+
+ ch_free( filterstr );
+ filterstr = NULL;
}
if( subtree ) {
base = val;
} else {
free( subtree );
+ subtree = NULL;
}
}
be = select_backend( &nbase, 0 );
ber_memfree( nbase.bv_val );
+ BER_BVZERO( &nbase );
switch ( tool ) {
case SLAPACL:
nosubordinates = 1;
}
+ ch_free( base.bv_val );
+ BER_BVZERO( &base );
+
} else if ( dbnum == -1 ) {
/* no suffix and no dbnum specified, just default to
* the first available database
progname, dbnum, 0 );
}
- } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
+ } else if ( dbnum >= nbackends ) {
fprintf( stderr,
"Database number selected via -n is out of range\n"
"Must be in the range 0 to %d"
- " (number of configured databases)\n",
- nbackends-1 );
+ " (the number of configured databases)\n",
+ nbackends - 1 );
exit( EXIT_FAILURE );
} else {
+get_db:
LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
if ( dbnum == 0 ) break;
dbnum--;
}
startup:;
+ if ( be ) {
+ BackendDB *bdtmp;
+
+ dbnum = 0;
+ LDAP_STAILQ_FOREACH( bdtmp, &backendDB, be_next ) {
+ if ( bdtmp == be ) break;
+ dbnum++;
+ }
+ }
#ifdef CSRIMALLOC
mal_leaktrace(1);
if ( conffile != NULL ) {
ch_free( conffile );
+ conffile = NULL;
+ }
+
+ if ( confdir != NULL ) {
+ ch_free( confdir );
+ confdir = NULL;
}
if ( ldiffile != NULL ) {
ch_free( ldiffile );
+ ldiffile = NULL;
}
/* slapdn doesn't specify a backend to startup */
if ( !BER_BVISNULL( &authcDN ) ) {
ch_free( authcDN.bv_val );
+ BER_BVZERO( &authcDN );
}
if ( ldiffp && ldiffp != &dummy ) {