#include "slapcommon.h"
#include "lutil.h"
+#include "ldif.h"
tool_vars tool_globals;
static FILE *leakfile;
#endif
+static LDIFFP dummy;
+
static void
usage( int tool, const char *progname )
{
int argc, char **argv )
{
char *options;
- char *conffile = SLAPD_DEFAULT_CONFIGFILE;
- char *confdir = SLAPD_DEFAULT_CONFIGDIR;
+ char *conffile = NULL;
+ char *confdir = NULL;
struct berval base = BER_BVNULL;
char *filterstr = NULL;
char *subtree = NULL;
ldap_syslog = 0;
if ( ldiffile == NULL ) {
- ldiffp = tool == SLAPCAT ? stdout : stdin;
+ dummy.fp = tool == SLAPCAT ? stdout : stdin;
+ ldiffp = &dummy;
- } else if ((ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" ))
+ } else if ((ldiffp = ldif_open( ldiffile, tool == SLAPCAT ? "w" : "r" ))
== NULL )
{
perror( ldiffile );
rc = read_config( conffile, confdir );
if ( rc != 0 ) {
- fprintf( stderr, "%s: bad configuration file!\n", progname );
+ fprintf( stderr, "%s: bad configuration %s!\n",
+ progname, confdir ? "directory" : "file" );
exit( EXIT_FAILURE );
}
/* If the named base is a glue master, operate on the
* entire context
*/
- if (SLAP_GLUE_INSTANCE(be)) {
+ if ( SLAP_GLUE_INSTANCE( be ) ) {
nosubordinates = 1;
}
} else if ( dbnum == -1 ) {
+ /* no suffix and no dbnum specified, just default to
+ * the first available database
+ */
if ( nbackends <= 0 ) {
fprintf( stderr, "No available databases\n" );
exit( EXIT_FAILURE );
}
LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
dbnum++;
+
+ /* db #0 is cn=config, don't select it as a default */
if ( dbnum < 1 ) continue;
if ( SLAP_MONITOR(be))
exit( EXIT_FAILURE );
}
- if ( nosubordinates == 0 && dbnum > 0 ) {
+ if ( nosubordinates == 0 && dbnum > 1 ) {
Debug( LDAP_DEBUG_ANY,
"The first database does not allow %s;"
" using the first available one (%d)\n",
- progname, dbnum + 1, 0 );
+ progname, dbnum, 0 );
}
} else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
fprintf( stderr,
"Database number selected via -n is out of range\n"
- "Must be in the range 1 to %d"
- " (number of databases in the config file)\n",
- nbackends );
+ "Must be in the range 0 to %d"
+ " (number of configured databases)\n",
+ nbackends-1 );
exit( EXIT_FAILURE );
} else {
mal_leaktrace(1);
#endif
- if ( !dryrun && slap_startup( be ) ) {
+ if ( conffile != NULL ) {
+ ch_free( conffile );
+ }
+
+ if ( ldiffile != NULL ) {
+ ch_free( ldiffile );
+ }
+ /* slapdn doesn't specify a backend to startup */
+ if ( !dryrun && tool != SLAPDN && slap_startup( be ) ) {
switch ( tool ) {
case SLAPTEST:
fprintf( stderr, "slap_startup failed "