2004-02-27 03:03:41 +08:00
|
|
|
/* slapcommon.c - common routine for the slap tools */
|
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 1998-2005 The OpenLDAP Foundation.
|
2004-02-27 03:03:41 +08:00
|
|
|
* Portions Copyright 1998-2003 Kurt D. Zeilenga.
|
|
|
|
* Portions Copyright 2003 IBM Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Kurt Zeilenga for inclusion
|
|
|
|
* in OpenLDAP Software. Additional signficant contributors include
|
|
|
|
* Jong Hyuk Choi
|
|
|
|
* Hallvard B. Furuseth
|
|
|
|
* Howard Chu
|
|
|
|
* Pierangelo Masarati
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
|
|
|
|
#include "slapcommon.h"
|
|
|
|
#include "lutil.h"
|
|
|
|
|
|
|
|
tool_vars tool_globals;
|
|
|
|
|
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
static char *leakfilename;
|
|
|
|
static FILE *leakfile;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage( int tool, const char *progname )
|
|
|
|
{
|
|
|
|
char *options = NULL;
|
|
|
|
fprintf( stderr,
|
2005-01-08 20:02:14 +08:00
|
|
|
"usage: %s [-v] [-c] [-d debuglevel] [-f configfile]",
|
2004-03-18 07:25:09 +08:00
|
|
|
progname );
|
2004-02-27 03:03:41 +08:00
|
|
|
|
|
|
|
switch( tool ) {
|
2005-01-08 20:02:14 +08:00
|
|
|
case SLAPACL:
|
|
|
|
options = "\n\t[-U authcID | -D authcDN]"
|
|
|
|
" -b DN [attr[/access][:value]] [...]\n";
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case SLAPADD:
|
2005-01-08 20:02:14 +08:00
|
|
|
options = "\n\t[-n databasenumber | -b suffix]\n"
|
2005-01-26 11:14:47 +08:00
|
|
|
"\t[-l ldiffile] [-q] [-u] [-w]\n";
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
2005-01-08 20:02:14 +08:00
|
|
|
case SLAPAUTH:
|
|
|
|
options = "\n\t[-U authcID] [-X authzID] [-R realm] [-M mech] ID [...]\n";
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case SLAPCAT:
|
2005-01-08 20:02:14 +08:00
|
|
|
options = "\n\t[-n databasenumber | -b suffix]"
|
2005-01-15 00:23:50 +08:00
|
|
|
" [-l ldiffile] [-a filter]\n";
|
2004-03-18 07:25:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPDN:
|
2005-01-08 20:02:14 +08:00
|
|
|
options = " DN [...]\n";
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPINDEX:
|
2005-01-26 11:14:47 +08:00
|
|
|
options = "\n\t[-n databasenumber | -b suffix] [-q]\n";
|
2004-04-14 01:18:03 +08:00
|
|
|
break;
|
2004-04-20 08:08:44 +08:00
|
|
|
|
2005-01-08 20:02:14 +08:00
|
|
|
case SLAPTEST:
|
|
|
|
options = " [-u]\n";
|
2004-04-20 08:08:44 +08:00
|
|
|
break;
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
if ( options != NULL ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
fputs( options, stderr );
|
|
|
|
}
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* slap_tool_init - initialize slap utility, handle program options.
|
|
|
|
* arguments:
|
|
|
|
* name program name
|
|
|
|
* tool tool code
|
|
|
|
* argc, argv command line arguments
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
slap_tool_init(
|
|
|
|
const char* progname,
|
|
|
|
int tool,
|
|
|
|
int argc, char **argv )
|
|
|
|
{
|
|
|
|
char *options;
|
|
|
|
char *conffile = SLAPD_DEFAULT_CONFIGFILE;
|
2004-04-07 12:11:43 +08:00
|
|
|
struct berval base = BER_BVNULL;
|
2004-09-09 05:44:28 +08:00
|
|
|
char *filterstr = NULL;
|
2004-02-27 03:03:41 +08:00
|
|
|
char *subtree = NULL;
|
|
|
|
char *ldiffile = NULL;
|
|
|
|
int rc, i, dbnum;
|
|
|
|
int mode = SLAP_TOOL_MODE;
|
|
|
|
int truncatemode = 0;
|
|
|
|
|
|
|
|
#ifdef CSRIMALLOC
|
2005-01-12 22:34:46 +08:00
|
|
|
leakfilename = malloc( strlen( progname ) + STRLENOF( ".leak" ) + 1 );
|
2004-02-27 03:03:41 +08:00
|
|
|
sprintf( leakfilename, "%s.leak", progname );
|
|
|
|
if( ( leakfile = fopen( leakfilename, "w" )) == NULL ) {
|
|
|
|
leakfile = stderr;
|
|
|
|
}
|
|
|
|
free( leakfilename );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch( tool ) {
|
|
|
|
case SLAPADD:
|
2005-01-24 09:37:09 +08:00
|
|
|
options = "b:cd:f:l:n:qtuvw";
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPCAT:
|
2005-01-14 12:26:59 +08:00
|
|
|
options = "a:b:cd:f:l:n:s:v";
|
2004-02-27 03:03:41 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
|
|
|
break;
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
case SLAPDN:
|
|
|
|
options = "d:f:v";
|
2004-07-17 22:45:07 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
2004-03-18 07:25:09 +08:00
|
|
|
break;
|
|
|
|
|
2005-01-08 20:02:14 +08:00
|
|
|
case SLAPTEST:
|
|
|
|
options = "d:f:uv";
|
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
|
|
|
break;
|
|
|
|
|
2004-04-16 14:12:13 +08:00
|
|
|
case SLAPAUTH:
|
2004-12-06 23:17:23 +08:00
|
|
|
options = "d:f:M:R:U:vX:";
|
2004-07-17 22:45:07 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
2004-04-14 01:18:03 +08:00
|
|
|
break;
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
case SLAPINDEX:
|
2005-01-26 11:14:47 +08:00
|
|
|
options = "b:cd:f:n:qv";
|
2004-03-18 07:25:09 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN;
|
|
|
|
break;
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
case SLAPACL:
|
|
|
|
options = "b:D:d:f:U:v";
|
2004-07-17 22:45:07 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
2004-04-20 08:08:44 +08:00
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
default:
|
2004-09-09 05:44:28 +08:00
|
|
|
fprintf( stderr, "%s: unknown tool mode (%d)\n", progname, tool );
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
dbnum = -1;
|
|
|
|
while ( (i = getopt( argc, argv, options )) != EOF ) {
|
|
|
|
switch ( i ) {
|
2004-09-09 05:44:28 +08:00
|
|
|
case 'a':
|
|
|
|
filterstr = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 'b':
|
2004-04-14 01:18:03 +08:00
|
|
|
ber_str2bv( optarg, 0, 1, &base );
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c': /* enable continue mode */
|
|
|
|
continuemode++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* turn on debugging */
|
|
|
|
ldap_debug += atoi( optarg );
|
|
|
|
break;
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
case 'D':
|
2004-07-17 22:45:07 +08:00
|
|
|
ber_str2bv( optarg, 0, 1, &authcDN );
|
2004-04-20 08:08:44 +08:00
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 'f': /* specify a conf file */
|
|
|
|
conffile = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': /* LDIF file */
|
|
|
|
ldiffile = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
2004-12-06 23:17:23 +08:00
|
|
|
case 'M':
|
|
|
|
ber_str2bv( optarg, 0, 0, &mech );
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 'n': /* which config file db to index */
|
2005-02-21 19:28:59 +08:00
|
|
|
dbnum = atoi( optarg );
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
2005-01-24 09:37:09 +08:00
|
|
|
case 'q': /* turn on quick */
|
|
|
|
mode |= SLAP_TOOL_QUICK;
|
|
|
|
break;
|
|
|
|
|
2004-12-06 23:17:23 +08:00
|
|
|
case 'R':
|
|
|
|
realm = optarg;
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 's': /* dump subtree */
|
|
|
|
subtree = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't': /* turn on truncate */
|
|
|
|
truncatemode++;
|
|
|
|
mode |= SLAP_TRUNCATE_MODE;
|
|
|
|
break;
|
|
|
|
|
2004-04-14 01:18:03 +08:00
|
|
|
case 'U':
|
|
|
|
ber_str2bv( optarg, 0, 0, &authcID );
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 'u': /* dry run */
|
|
|
|
dryrun++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v': /* turn on verbose */
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
|
2005-01-15 00:23:50 +08:00
|
|
|
case 'w': /* write context csn at the end */
|
2005-01-14 12:26:59 +08:00
|
|
|
update_ctxcsn++;
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
2004-04-14 01:18:03 +08:00
|
|
|
case 'X':
|
|
|
|
ber_str2bv( optarg, 0, 0, &authzID );
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
default:
|
|
|
|
usage( tool, progname );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPADD:
|
|
|
|
case SLAPCAT:
|
|
|
|
case SLAPINDEX:
|
|
|
|
if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2004-02-27 03:03:41 +08:00
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
case SLAPDN:
|
|
|
|
if ( argc == optind ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
usage( tool, progname );
|
|
|
|
}
|
2004-03-18 07:25:09 +08:00
|
|
|
break;
|
|
|
|
|
2004-04-16 14:12:13 +08:00
|
|
|
case SLAPAUTH:
|
2004-04-14 01:18:03 +08:00
|
|
|
if ( argc == optind && BER_BVISNULL( &authcID ) ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
case SLAPTEST:
|
|
|
|
if ( argc != optind ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
case SLAPACL:
|
|
|
|
if ( !BER_BVISNULL( &authcDN ) && !BER_BVISNULL( &authcID ) ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
if ( BER_BVISNULL( &base ) ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
ber_dupbv( &baseDN, &base );
|
|
|
|
break;
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
default:
|
|
|
|
break;
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
2005-03-04 12:32:43 +08:00
|
|
|
ldap_syslog = 0;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
if ( ldiffile == NULL ) {
|
|
|
|
ldiffp = tool == SLAPCAT ? stdout : stdin;
|
|
|
|
|
2004-09-09 05:44:28 +08:00
|
|
|
} else if ((ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" ))
|
2004-02-27 03:03:41 +08:00
|
|
|
== NULL )
|
|
|
|
{
|
|
|
|
perror( ldiffile );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize stuff and figure out which backend we're dealing with
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef SLAPD_MODULES
|
|
|
|
if ( module_init() != 0 ) {
|
|
|
|
fprintf( stderr, "%s: module_init failed!\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-03-04 17:26:50 +08:00
|
|
|
rc = slap_schema_init();
|
2004-02-27 03:03:41 +08:00
|
|
|
|
|
|
|
if ( rc != 0 ) {
|
2005-03-04 17:26:50 +08:00
|
|
|
fprintf( stderr, "%s: slap_schema_init failed!\n", progname );
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2005-03-04 17:26:50 +08:00
|
|
|
rc = slap_init( mode, progname );
|
2004-02-27 03:03:41 +08:00
|
|
|
|
|
|
|
if ( rc != 0 ) {
|
2005-03-04 17:26:50 +08:00
|
|
|
fprintf( stderr, "%s: slap_init failed!\n", progname );
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2004-07-27 05:26:34 +08:00
|
|
|
if ( frontend_init() ) {
|
|
|
|
fprintf( stderr, "%s: frontend_init failed!\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2004-04-06 20:22:29 +08:00
|
|
|
if ( overlay_init() ) {
|
|
|
|
fprintf( stderr, "%s: overlay_init failed!\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
rc = read_config( conffile, 0 );
|
|
|
|
|
|
|
|
if ( rc != 0 ) {
|
|
|
|
fprintf( stderr, "%s: bad configuration file!\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2005-01-23 04:18:38 +08:00
|
|
|
at_oc_cache = 1;
|
2004-03-10 10:44:38 +08:00
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPADD:
|
|
|
|
case SLAPCAT:
|
|
|
|
case SLAPINDEX:
|
|
|
|
if ( !nbackends ) {
|
|
|
|
fprintf( stderr, "No databases found "
|
|
|
|
"in config file\n" );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = slap_schema_check();
|
|
|
|
|
|
|
|
if ( rc != 0 ) {
|
|
|
|
fprintf( stderr, "%s: slap_schema_prep failed!\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPDN:
|
|
|
|
case SLAPTEST:
|
2004-04-16 14:12:13 +08:00
|
|
|
case SLAPAUTH:
|
2004-04-14 01:18:03 +08:00
|
|
|
be = NULL;
|
|
|
|
goto startup;
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-09-09 05:44:28 +08:00
|
|
|
if( filterstr ) {
|
|
|
|
filter = str2filter( filterstr );
|
|
|
|
|
|
|
|
if( filter == NULL ) {
|
|
|
|
fprintf( stderr, "Invalid filter '%s'\n", filterstr );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
if( subtree ) {
|
|
|
|
struct berval val;
|
2004-04-14 01:18:03 +08:00
|
|
|
ber_str2bv( subtree, 0, 0, &val );
|
2004-02-27 03:03:41 +08:00
|
|
|
rc = dnNormalize( 0, NULL, NULL, &val, &sub_ndn, NULL );
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2004-09-09 05:44:28 +08:00
|
|
|
fprintf( stderr, "Invalid subtree DN '%s'\n", subtree );
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2004-09-09 05:44:28 +08:00
|
|
|
if ( BER_BVISNULL( &base ) && dbnum == -1 ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
base = val;
|
2004-09-09 05:44:28 +08:00
|
|
|
} else {
|
2004-02-27 03:03:41 +08:00
|
|
|
free( subtree );
|
2004-09-09 05:44:28 +08:00
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if( base.bv_val != NULL ) {
|
|
|
|
struct berval nbase;
|
|
|
|
|
|
|
|
rc = dnNormalize( 0, NULL, NULL, &base, &nbase, NULL );
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "%s: slap_init invalid suffix (\"%s\")\n",
|
|
|
|
progname, base.bv_val );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
be = select_backend( &nbase, 0, 0 );
|
|
|
|
ber_memfree( nbase.bv_val );
|
|
|
|
|
2004-07-17 22:45:07 +08:00
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPACL:
|
2004-04-20 22:55:02 +08:00
|
|
|
goto startup;
|
2004-07-17 22:45:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2004-04-20 22:55:02 +08:00
|
|
|
}
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
if( be == NULL ) {
|
|
|
|
fprintf( stderr, "%s: slap_init no backend for \"%s\"\n",
|
|
|
|
progname, base.bv_val );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
/* If the named base is a glue master, operate on the
|
|
|
|
* entire context
|
|
|
|
*/
|
|
|
|
if (SLAP_GLUE_INSTANCE(be)) {
|
|
|
|
nosubordinates = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( dbnum == -1 ) {
|
|
|
|
if ( nbackends <= 0 ) {
|
|
|
|
fprintf( stderr, "No available databases\n" );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2005-02-21 19:28:59 +08:00
|
|
|
be = &backends[dbnum=1];
|
2004-02-27 03:03:41 +08:00
|
|
|
/* If just doing the first by default and it is a
|
|
|
|
* glue subordinate, find the master.
|
|
|
|
*/
|
|
|
|
while (SLAP_GLUE_SUBORDINATE(be) || SLAP_MONITOR(be)) {
|
|
|
|
if (SLAP_GLUE_SUBORDINATE(be)) {
|
|
|
|
nosubordinates = 1;
|
|
|
|
}
|
|
|
|
be++;
|
|
|
|
dbnum++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( dbnum >= nbackends ) {
|
|
|
|
fprintf( stderr, "Available database(s) "
|
|
|
|
"do not allow %s\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( nosubordinates == 0 && dbnum > 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
2004-09-09 05:44:28 +08:00
|
|
|
"The first database does not allow %s;"
|
|
|
|
" using the first available one (%d)\n",
|
2004-02-27 03:03:41 +08:00
|
|
|
progname, dbnum + 1, 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"
|
2004-09-09 05:44:28 +08:00
|
|
|
" (number of databases in the config file)\n",
|
2004-02-27 03:03:41 +08:00
|
|
|
nbackends );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
be = &backends[dbnum];
|
|
|
|
}
|
|
|
|
|
2004-04-14 01:18:03 +08:00
|
|
|
startup:;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
mal_leaktrace(1);
|
|
|
|
#endif
|
|
|
|
|
2004-07-19 05:36:39 +08:00
|
|
|
if ( !dryrun && slap_startup( be ) ) {
|
2005-01-12 22:31:03 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void slap_tool_destroy( void )
|
|
|
|
{
|
2004-09-11 01:15:33 +08:00
|
|
|
if ( !dryrun && be != NULL ) {
|
2004-07-19 05:36:39 +08:00
|
|
|
slap_shutdown( be );
|
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
slap_destroy();
|
|
|
|
#ifdef SLAPD_MODULES
|
|
|
|
if ( slapMode == SLAP_SERVER_MODE ) {
|
|
|
|
/* always false. just pulls in necessary symbol references. */
|
|
|
|
lutil_uuidstr(NULL, 0);
|
|
|
|
}
|
|
|
|
module_kill();
|
|
|
|
#endif
|
|
|
|
schema_destroy();
|
|
|
|
#ifdef HAVE_TLS
|
|
|
|
ldap_pvt_tls_destroy();
|
|
|
|
#endif
|
|
|
|
config_destroy();
|
|
|
|
|
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
mal_dumpleaktrace( leakfile );
|
|
|
|
#endif
|
2004-07-17 22:45:07 +08:00
|
|
|
|
|
|
|
if ( !BER_BVISNULL( &authcDN ) ) {
|
|
|
|
ch_free( authcDN.bv_val );
|
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|