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/>.
|
|
|
|
*
|
2013-01-03 02:20:30 +08:00
|
|
|
* Copyright 1998-2013 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"
|
2005-05-12 08:46:39 +08:00
|
|
|
#include "ldif.h"
|
2004-02-27 03:03:41 +08:00
|
|
|
|
|
|
|
tool_vars tool_globals;
|
|
|
|
|
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
static char *leakfilename;
|
|
|
|
static FILE *leakfile;
|
|
|
|
#endif
|
|
|
|
|
2005-05-12 08:46:39 +08:00
|
|
|
static LDIFFP dummy;
|
|
|
|
|
2007-05-12 07:04:33 +08:00
|
|
|
#if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
|
2006-05-25 01:57:13 +08:00
|
|
|
int start_syslog;
|
|
|
|
static char **syslog_unknowns;
|
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
static int syslogUser = SLAP_DEFAULT_SYSLOG_USER;
|
|
|
|
#endif /* LOG_LOCAL4 */
|
2007-05-12 07:04:33 +08:00
|
|
|
#endif /* LDAP_DEBUG && LDAP_SYSLOG */
|
2006-05-25 01:57:13 +08:00
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
static void
|
|
|
|
usage( int tool, const char *progname )
|
|
|
|
{
|
|
|
|
char *options = NULL;
|
|
|
|
fprintf( stderr,
|
2006-05-25 01:57:13 +08:00
|
|
|
"usage: %s [-v] [-d debuglevel] [-f configfile] [-F configdir] [-o <name>[=<value>]]",
|
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:
|
2005-04-13 03:36:56 +08:00
|
|
|
options = "\n\t[-U authcID | -D authcDN] [-X authzID | -o authzDN=<DN>]"
|
2006-05-25 01:57:13 +08:00
|
|
|
"\n\t-b DN [-u] [attr[/access][:value]] [...]\n";
|
2005-01-08 20:02:14 +08:00
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case SLAPADD:
|
2005-10-16 05:52:01 +08:00
|
|
|
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n"
|
2006-05-29 10:41:06 +08:00
|
|
|
"\t[-l ldiffile] [-j linenumber] [-q] [-u] [-s] [-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-10-16 05:52:01 +08:00
|
|
|
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
|
2010-01-18 23:00:40 +08:00
|
|
|
" [-l ldiffile] [-a filter] [-s subtree] [-H url]\n";
|
2004-03-18 07:25:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPDN:
|
2005-04-01 20:59:26 +08:00
|
|
|
options = "\n\t[-N | -P] DN [...]\n";
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPINDEX:
|
2007-11-21 23:40:09 +08:00
|
|
|
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [attr ...] [-q] [-t]\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:
|
2009-09-29 15:33:01 +08:00
|
|
|
options = " [-n databasenumber] [-u]\n";
|
2004-04-20 08:08:44 +08:00
|
|
|
break;
|
2009-05-28 21:40:57 +08:00
|
|
|
|
|
|
|
case SLAPSCHEMA:
|
|
|
|
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]"
|
2010-01-18 23:00:40 +08:00
|
|
|
" [-l errorfile] [-a filter] [-s subtree] [-H url]\n";
|
2009-05-28 21:40:57 +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 );
|
|
|
|
}
|
|
|
|
|
2005-03-31 06:29:35 +08:00
|
|
|
static int
|
2010-09-07 13:45:36 +08:00
|
|
|
parse_slapopt( int tool, int *mode )
|
2005-03-31 06:29:35 +08:00
|
|
|
{
|
2006-05-25 01:57:13 +08:00
|
|
|
size_t len = 0;
|
2005-03-31 06:29:35 +08:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = strchr( optarg, '=' );
|
2006-05-25 01:57:13 +08:00
|
|
|
if ( p != NULL ) {
|
|
|
|
len = p - optarg;
|
|
|
|
p++;
|
2005-03-31 06:29:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( strncasecmp( optarg, "sockurl", len ) == 0 ) {
|
|
|
|
if ( !BER_BVISNULL( &listener_url ) ) {
|
|
|
|
ber_memfree( listener_url.bv_val );
|
|
|
|
}
|
|
|
|
ber_str2bv( p, 0, 1, &listener_url );
|
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "domain", len ) == 0 ) {
|
|
|
|
if ( !BER_BVISNULL( &peer_domain ) ) {
|
|
|
|
ber_memfree( peer_domain.bv_val );
|
|
|
|
}
|
|
|
|
ber_str2bv( p, 0, 1, &peer_domain );
|
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "peername", len ) == 0 ) {
|
|
|
|
if ( !BER_BVISNULL( &peer_name ) ) {
|
|
|
|
ber_memfree( peer_name.bv_val );
|
|
|
|
}
|
|
|
|
ber_str2bv( p, 0, 1, &peer_name );
|
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "sockname", len ) == 0 ) {
|
|
|
|
if ( !BER_BVISNULL( &sock_name ) ) {
|
|
|
|
ber_memfree( sock_name.bv_val );
|
|
|
|
}
|
|
|
|
ber_str2bv( p, 0, 1, &sock_name );
|
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "ssf", len ) == 0 ) {
|
2005-11-24 01:29:16 +08:00
|
|
|
if ( lutil_atou( &ssf, p ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse ssf=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-31 06:29:35 +08:00
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "transport_ssf", len ) == 0 ) {
|
2005-11-24 01:29:16 +08:00
|
|
|
if ( lutil_atou( &transport_ssf, p ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse transport_ssf=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-31 06:29:35 +08:00
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "tls_ssf", len ) == 0 ) {
|
2005-11-24 01:29:16 +08:00
|
|
|
if ( lutil_atou( &tls_ssf, p ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse tls_ssf=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-31 06:29:35 +08:00
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "sasl_ssf", len ) == 0 ) {
|
2005-11-24 01:29:16 +08:00
|
|
|
if ( lutil_atou( &sasl_ssf, p ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse sasl_ssf=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-31 06:29:35 +08:00
|
|
|
|
2005-04-13 03:36:56 +08:00
|
|
|
} else if ( strncasecmp( optarg, "authzDN", len ) == 0 ) {
|
|
|
|
ber_str2bv( p, 0, 1, &authzDN );
|
|
|
|
|
2007-05-12 07:04:33 +08:00
|
|
|
#if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
|
2006-05-25 01:57:13 +08:00
|
|
|
} else if ( strncasecmp( optarg, "syslog", len ) == 0 ) {
|
|
|
|
if ( parse_debug_level( p, &ldap_syslog, &syslog_unknowns ) ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
start_syslog = 1;
|
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "syslog-level", len ) == 0 ) {
|
|
|
|
if ( parse_syslog_level( p, &ldap_syslog_level ) ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
start_syslog = 1;
|
|
|
|
|
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
} else if ( strncasecmp( optarg, "syslog-user", len ) == 0 ) {
|
|
|
|
if ( parse_syslog_user( p, &syslogUser ) ) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
start_syslog = 1;
|
|
|
|
#endif /* LOG_LOCAL4 */
|
2007-05-12 07:04:33 +08:00
|
|
|
#endif /* LDAP_DEBUG && LDAP_SYSLOG */
|
2006-05-25 01:57:13 +08:00
|
|
|
|
2010-09-07 13:47:55 +08:00
|
|
|
} else if ( strncasecmp( optarg, "schema-check", len ) == 0 ) {
|
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPADD:
|
|
|
|
if ( strcasecmp( p, "yes" ) == 0 ) {
|
|
|
|
*mode &= ~SLAP_TOOL_NO_SCHEMA_CHECK;
|
|
|
|
} else if ( strcasecmp( p, "no" ) == 0 ) {
|
|
|
|
*mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
|
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse schema-check=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug( LDAP_DEBUG_ANY, "schema-check meaningless for tool.\n", 0, 0, 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ( strncasecmp( optarg, "value-check", len ) == 0 ) {
|
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPADD:
|
|
|
|
if ( strcasecmp( p, "yes" ) == 0 ) {
|
|
|
|
*mode |= SLAP_TOOL_VALUE_CHECK;
|
|
|
|
} else if ( strcasecmp( p, "no" ) == 0 ) {
|
|
|
|
*mode &= ~SLAP_TOOL_VALUE_CHECK;
|
|
|
|
} else {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse value-check=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug( LDAP_DEBUG_ANY, "value-check meaningless for tool.\n", 0, 0, 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-07 18:14:51 +08:00
|
|
|
} else if ( strncasecmp( optarg, "ldif-wrap", len ) == 0 ) {
|
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPCAT:
|
|
|
|
if ( strcasecmp( p, "no" ) == 0 ) {
|
|
|
|
ldif_wrap = LDIF_LINE_WIDTH_MAX;
|
|
|
|
|
2010-12-07 19:58:38 +08:00
|
|
|
} else {
|
|
|
|
unsigned int u;
|
|
|
|
if ( lutil_atou( &u, p ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "unable to parse ldif-wrap=\"%s\".\n", p, 0, 0 );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ldif_wrap = (ber_len_t)u;
|
2010-12-07 18:14:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug( LDAP_DEBUG_ANY, "value-check meaningless for tool.\n", 0, 0, 0 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-03-31 06:29:35 +08:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* slap_tool_init - initialize slap utility, handle program options.
|
|
|
|
* arguments:
|
|
|
|
* name program name
|
|
|
|
* tool tool code
|
|
|
|
* argc, argv command line arguments
|
|
|
|
*/
|
|
|
|
|
2005-12-17 06:24:53 +08:00
|
|
|
static int need_shutdown;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
void
|
|
|
|
slap_tool_init(
|
|
|
|
const char* progname,
|
|
|
|
int tool,
|
|
|
|
int argc, char **argv )
|
|
|
|
{
|
|
|
|
char *options;
|
2005-05-02 04:55:15 +08:00
|
|
|
char *conffile = NULL;
|
|
|
|
char *confdir = NULL;
|
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;
|
2006-02-02 16:30:56 +08:00
|
|
|
char **debug_unknowns = NULL;
|
2009-03-05 18:59:34 +08:00
|
|
|
int rc, i;
|
2004-02-27 03:03:41 +08:00
|
|
|
int mode = SLAP_TOOL_MODE;
|
|
|
|
int truncatemode = 0;
|
2005-10-16 05:52:01 +08:00
|
|
|
int use_glue = 1;
|
2009-05-28 21:40:57 +08:00
|
|
|
int writer;
|
2004-02-27 03:03:41 +08:00
|
|
|
|
2005-11-09 19:53:34 +08:00
|
|
|
#ifdef LDAP_DEBUG
|
|
|
|
/* tools default to "none", so that at least LDAP_DEBUG_ANY
|
|
|
|
* messages show up; use -d 0 to reset */
|
2005-11-28 18:55:07 +08:00
|
|
|
slap_debug = LDAP_DEBUG_NONE;
|
2009-07-08 05:51:27 +08:00
|
|
|
ldif_debug = slap_debug;
|
2005-11-09 19:53:34 +08:00
|
|
|
#endif
|
2006-05-25 01:57:13 +08:00
|
|
|
ldap_syslog = 0;
|
2005-11-09 19:53:34 +08:00
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
#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 );
|
2009-05-04 19:37:58 +08:00
|
|
|
leakfilename = NULL;
|
2004-02-27 03:03:41 +08:00
|
|
|
#endif
|
|
|
|
|
2010-12-07 18:14:51 +08:00
|
|
|
ldif_wrap = LDIF_LINE_WIDTH;
|
|
|
|
|
2010-01-18 23:00:40 +08:00
|
|
|
scope = LDAP_SCOPE_DEFAULT;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
switch( tool ) {
|
|
|
|
case SLAPADD:
|
2007-11-21 23:40:09 +08:00
|
|
|
options = "b:cd:f:F:gj:l:n:o:qsS:uvw";
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPCAT:
|
2010-01-18 23:00:40 +08:00
|
|
|
options = "a:b:cd:f:F:gH:l:n:o: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:
|
2006-05-25 01:57:13 +08:00
|
|
|
options = "d:f:F:No:Pv";
|
2004-07-17 22:45:07 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
2004-03-18 07:25:09 +08:00
|
|
|
break;
|
|
|
|
|
2010-04-20 14:00:16 +08:00
|
|
|
case SLAPMODIFY:
|
|
|
|
options = "b:cd:f:F:gj:l:n:o:qsS:uvw";
|
|
|
|
break;
|
|
|
|
|
2009-05-28 21:40:57 +08:00
|
|
|
case SLAPSCHEMA:
|
2010-01-18 23:00:40 +08:00
|
|
|
options = "a:b:cd:f:F:gH:l:n:o:s:v";
|
2009-05-28 21:40:57 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
|
|
|
break;
|
|
|
|
|
2005-01-08 20:02:14 +08:00
|
|
|
case SLAPTEST:
|
2009-09-29 15:33:01 +08:00
|
|
|
options = "d:f:F:n:o:Quv";
|
2005-01-08 20:02:14 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
|
|
|
|
break;
|
|
|
|
|
2004-04-16 14:12:13 +08:00
|
|
|
case SLAPAUTH:
|
2006-05-25 01:57:13 +08:00
|
|
|
options = "d:f:F:M:o: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:
|
2007-11-21 23:40:09 +08:00
|
|
|
options = "b:cd:f:F:gn:o:qtv";
|
2004-03-18 07:25:09 +08:00
|
|
|
mode |= SLAP_TOOL_READMAIN;
|
|
|
|
break;
|
|
|
|
|
2004-04-20 08:08:44 +08:00
|
|
|
case SLAPACL:
|
2005-04-13 03:36:56 +08:00
|
|
|
options = "b:D:d:f:F:o:uU:vX:";
|
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':
|
2006-08-29 09:36:52 +08:00
|
|
|
filterstr = ch_strdup( optarg );
|
2004-09-09 05:44:28 +08:00
|
|
|
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;
|
|
|
|
|
2005-12-05 18:39:38 +08:00
|
|
|
case 'd': { /* turn on debugging */
|
|
|
|
int level = 0;
|
|
|
|
|
2006-02-02 16:30:56 +08:00
|
|
|
if ( parse_debug_level( optarg, &level, &debug_unknowns ) ) {
|
2005-12-20 16:20:16 +08:00
|
|
|
usage( tool, progname );
|
|
|
|
}
|
2005-11-01 02:48:12 +08:00
|
|
|
#ifdef LDAP_DEBUG
|
2005-12-20 16:20:16 +08:00
|
|
|
if ( level == 0 ) {
|
|
|
|
/* allow to reset log level */
|
|
|
|
slap_debug = 0;
|
2005-11-28 18:55:07 +08:00
|
|
|
|
|
|
|
} else {
|
2005-12-20 16:20:16 +08:00
|
|
|
slap_debug |= level;
|
2005-11-01 02:48:12 +08:00
|
|
|
}
|
|
|
|
#else
|
2005-12-20 16:20:16 +08:00
|
|
|
if ( level != 0 )
|
2005-11-01 02:48:12 +08:00
|
|
|
fputs( "must compile with LDAP_DEBUG for debugging\n",
|
|
|
|
stderr );
|
|
|
|
#endif
|
2005-12-05 18:39:38 +08:00
|
|
|
} break;
|
2004-02-27 03:03:41 +08:00
|
|
|
|
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 */
|
2006-08-29 09:36:52 +08:00
|
|
|
conffile = ch_strdup( optarg );
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
2005-03-15 16:57:34 +08:00
|
|
|
case 'F': /* specify a conf dir */
|
2006-08-29 09:36:52 +08:00
|
|
|
confdir = ch_strdup( optarg );
|
2005-03-15 16:57:34 +08:00
|
|
|
break;
|
|
|
|
|
2005-10-16 05:52:01 +08:00
|
|
|
case 'g': /* disable subordinate glue */
|
|
|
|
use_glue = 0;
|
|
|
|
break;
|
|
|
|
|
2010-01-18 23:00:40 +08:00
|
|
|
case 'H': {
|
|
|
|
LDAPURLDesc *ludp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ldap_url_parse_ext( optarg, &ludp,
|
|
|
|
LDAP_PVT_URL_PARSE_NOEMPTY_HOST | LDAP_PVT_URL_PARSE_NOEMPTY_DN );
|
|
|
|
if ( rc != LDAP_URL_SUCCESS ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't accept host, port, attrs, extensions */
|
|
|
|
if ( ldap_pvt_url_scheme2proto( ludp->lud_scheme ) != LDAP_PROTO_TCP ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ludp->lud_host != NULL ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ludp->lud_port != 0 ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ludp->lud_attrs != NULL ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ludp->lud_exts != NULL ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ludp->lud_dn != NULL && ludp->lud_dn[0] != '\0' ) {
|
|
|
|
subtree = ludp->lud_dn;
|
|
|
|
ludp->lud_dn = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ludp->lud_filter != NULL && ludp->lud_filter[0] != '\0' ) {
|
|
|
|
filterstr = ludp->lud_filter;
|
|
|
|
ludp->lud_filter = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
scope = ludp->lud_scope;
|
|
|
|
|
|
|
|
ldap_free_urldesc( ludp );
|
|
|
|
} break;
|
|
|
|
|
2006-05-29 10:41:06 +08:00
|
|
|
case 'j': /* jump to linenumber */
|
2013-01-23 10:19:02 +08:00
|
|
|
if ( lutil_atoul( &jumpline, optarg ) ) {
|
2006-05-29 10:41:06 +08:00
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 'l': /* LDIF file */
|
2006-08-29 09:36:52 +08:00
|
|
|
ldiffile = ch_strdup( optarg );
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
2004-12-06 23:17:23 +08:00
|
|
|
case 'M':
|
|
|
|
ber_str2bv( optarg, 0, 0, &mech );
|
|
|
|
break;
|
|
|
|
|
2005-04-01 20:59:26 +08:00
|
|
|
case 'N':
|
|
|
|
if ( dn_mode && dn_mode != SLAP_TOOL_LDAPDN_NORMAL ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
dn_mode = SLAP_TOOL_LDAPDN_NORMAL;
|
|
|
|
break;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
case 'n': /* which config file db to index */
|
2009-03-05 18:59:34 +08:00
|
|
|
if ( lutil_atoi( &dbnum, optarg ) || dbnum < 0 ) {
|
2005-11-24 01:29:16 +08:00
|
|
|
usage( tool, progname );
|
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
break;
|
|
|
|
|
2005-03-31 06:29:35 +08:00
|
|
|
case 'o':
|
2010-09-07 13:45:36 +08:00
|
|
|
if ( parse_slapopt( tool, &mode ) ) {
|
2005-03-31 06:29:35 +08:00
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-04-01 20:59:26 +08:00
|
|
|
case 'P':
|
|
|
|
if ( dn_mode && dn_mode != SLAP_TOOL_LDAPDN_PRETTY ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
dn_mode = SLAP_TOOL_LDAPDN_PRETTY;
|
|
|
|
break;
|
|
|
|
|
2007-08-14 21:42:40 +08:00
|
|
|
case 'Q':
|
|
|
|
quiet++;
|
|
|
|
slap_debug = 0;
|
|
|
|
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;
|
|
|
|
|
2007-08-29 03:35:57 +08:00
|
|
|
case 'S':
|
2007-09-21 21:11:39 +08:00
|
|
|
if ( lutil_atou( &csnsid, optarg )
|
2007-08-29 03:35:57 +08:00
|
|
|
|| csnsid > SLAP_SYNC_SID_MAX )
|
|
|
|
{
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-09-07 13:45:36 +08:00
|
|
|
case 's':
|
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPADD:
|
|
|
|
case SLAPMODIFY:
|
|
|
|
/* no schema check */
|
2006-01-09 04:18:14 +08:00
|
|
|
mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
|
2010-09-07 13:45:36 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLAPCAT:
|
|
|
|
case SLAPSCHEMA:
|
|
|
|
/* dump subtree */
|
2006-08-29 09:36:52 +08:00
|
|
|
subtree = ch_strdup( optarg );
|
2010-09-07 13:45:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-12 07:04:33 +08:00
|
|
|
#if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
|
2006-05-25 01:57:13 +08:00
|
|
|
if ( start_syslog ) {
|
|
|
|
char *logName;
|
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
logName = ch_strdup( progname );
|
|
|
|
__atoe( logName );
|
|
|
|
#else
|
|
|
|
logName = (char *)progname;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef LOG_LOCAL4
|
|
|
|
openlog( logName, OPENLOG_OPTIONS, syslogUser );
|
2007-05-10 02:17:10 +08:00
|
|
|
#elif defined LOG_DEBUG
|
2006-05-25 01:57:13 +08:00
|
|
|
openlog( logName, OPENLOG_OPTIONS );
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_EBCDIC
|
|
|
|
free( logName );
|
2009-05-04 19:37:58 +08:00
|
|
|
logName = NULL;
|
2006-05-25 01:57:13 +08:00
|
|
|
#endif
|
|
|
|
}
|
2007-05-12 07:04:33 +08:00
|
|
|
#endif /* LDAP_DEBUG && LDAP_SYSLOG */
|
2006-05-25 01:57:13 +08:00
|
|
|
|
2009-05-28 21:40:57 +08:00
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPCAT:
|
|
|
|
case SLAPSCHEMA:
|
|
|
|
writer = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
writer = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-03-18 07:25:09 +08:00
|
|
|
switch ( tool ) {
|
|
|
|
case SLAPADD:
|
|
|
|
case SLAPCAT:
|
2010-04-20 14:00:16 +08:00
|
|
|
case SLAPMODIFY:
|
2009-05-28 21:40:57 +08:00
|
|
|
case SLAPSCHEMA:
|
2004-03-18 07:25:09 +08:00
|
|
|
if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2004-02-27 03:03:41 +08:00
|
|
|
|
2007-01-15 09:14:14 +08:00
|
|
|
case SLAPINDEX:
|
|
|
|
if ( dbnum >= 0 && base.bv_val != NULL ) {
|
|
|
|
usage( tool, progname );
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if ( ldiffile == NULL ) {
|
2009-05-28 21:40:57 +08:00
|
|
|
dummy.fp = writer ? stdout : stdin;
|
2005-05-12 08:46:39 +08:00
|
|
|
ldiffp = &dummy;
|
2004-02-27 03:03:41 +08:00
|
|
|
|
2009-05-28 21:40:57 +08:00
|
|
|
} else if ((ldiffp = ldif_open( ldiffile, writer ? "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
|
|
|
|
*/
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2005-03-15 16:57:34 +08:00
|
|
|
rc = read_config( conffile, confdir );
|
2004-02-27 03:03:41 +08:00
|
|
|
|
|
|
|
if ( rc != 0 ) {
|
2005-08-12 05:02:32 +08:00
|
|
|
fprintf( stderr, "%s: bad configuration %s!\n",
|
|
|
|
progname, confdir ? "directory" : "file" );
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2006-02-02 16:30:56 +08:00
|
|
|
if ( debug_unknowns ) {
|
|
|
|
rc = parse_debug_unknowns( debug_unknowns, &slap_debug );
|
|
|
|
ldap_charray_free( debug_unknowns );
|
|
|
|
debug_unknowns = NULL;
|
|
|
|
if ( rc )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2007-05-12 07:04:33 +08:00
|
|
|
#if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
|
2006-05-25 01:57:13 +08:00
|
|
|
if ( syslog_unknowns ) {
|
|
|
|
rc = parse_debug_unknowns( syslog_unknowns, &ldap_syslog );
|
|
|
|
ldap_charray_free( syslog_unknowns );
|
|
|
|
syslog_unknowns = NULL;
|
|
|
|
if ( rc )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2006-09-14 15:29:46 +08:00
|
|
|
#endif
|
2006-05-25 01:57:13 +08:00
|
|
|
|
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:
|
2010-04-20 14:00:16 +08:00
|
|
|
case SLAPMODIFY:
|
2009-05-28 21:40:57 +08:00
|
|
|
case SLAPSCHEMA:
|
2004-03-18 07:25:09 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2005-10-16 05:52:01 +08:00
|
|
|
if ( use_glue ) {
|
2009-02-06 05:44:21 +08:00
|
|
|
rc = glue_sub_attach( 0 );
|
2005-09-01 19:45:04 +08:00
|
|
|
|
2005-10-16 05:52:01 +08:00
|
|
|
if ( rc != 0 ) {
|
|
|
|
fprintf( stderr,
|
|
|
|
"%s: subordinate configuration error\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2005-09-01 19:45:04 +08:00
|
|
|
}
|
|
|
|
|
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 SLAPTEST:
|
2009-09-29 15:33:01 +08:00
|
|
|
if ( dbnum >= 0 )
|
|
|
|
goto get_db;
|
|
|
|
/* FALLTHRU */
|
|
|
|
case SLAPDN:
|
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 );
|
|
|
|
}
|
2009-05-04 19:37:58 +08:00
|
|
|
|
|
|
|
ch_free( filterstr );
|
|
|
|
filterstr = NULL;
|
2004-09-09 05:44:28 +08:00
|
|
|
}
|
|
|
|
|
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 );
|
2009-05-04 19:37:58 +08:00
|
|
|
subtree = NULL;
|
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 );
|
|
|
|
}
|
|
|
|
|
2007-07-13 11:18:20 +08:00
|
|
|
be = select_backend( &nbase, 0 );
|
2004-02-27 03:03:41 +08:00
|
|
|
ber_memfree( nbase.bv_val );
|
2009-05-04 19:37:58 +08:00
|
|
|
BER_BVZERO( &nbase );
|
2004-02-27 03:03:41 +08:00
|
|
|
|
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
|
|
|
|
*/
|
2005-04-13 04:33:45 +08:00
|
|
|
if ( SLAP_GLUE_INSTANCE( be ) ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
nosubordinates = 1;
|
|
|
|
}
|
|
|
|
|
2009-04-30 19:36:12 +08:00
|
|
|
ch_free( base.bv_val );
|
2009-05-04 19:37:58 +08:00
|
|
|
BER_BVZERO( &base );
|
2009-04-30 19:36:12 +08:00
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
} else if ( dbnum == -1 ) {
|
2005-08-10 19:26:32 +08:00
|
|
|
/* no suffix and no dbnum specified, just default to
|
|
|
|
* the first available database
|
|
|
|
*/
|
2004-02-27 03:03:41 +08:00
|
|
|
if ( nbackends <= 0 ) {
|
|
|
|
fprintf( stderr, "No available databases\n" );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2005-03-24 13:13:31 +08:00
|
|
|
LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
|
|
|
|
dbnum++;
|
2005-08-10 19:26:32 +08:00
|
|
|
|
|
|
|
/* db #0 is cn=config, don't select it as a default */
|
2005-03-24 13:13:31 +08:00
|
|
|
if ( dbnum < 1 ) continue;
|
2004-02-27 03:03:41 +08:00
|
|
|
|
2005-03-24 13:13:31 +08:00
|
|
|
if ( SLAP_MONITOR(be))
|
|
|
|
continue;
|
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
/* If just doing the first by default and it is a
|
|
|
|
* glue subordinate, find the master.
|
|
|
|
*/
|
2005-03-24 13:13:31 +08:00
|
|
|
if ( SLAP_GLUE_SUBORDINATE(be) ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
nosubordinates = 1;
|
2005-03-24 13:13:31 +08:00
|
|
|
continue;
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
2005-03-24 13:13:31 +08:00
|
|
|
break;
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
2005-03-24 13:13:31 +08:00
|
|
|
if ( !be ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
fprintf( stderr, "Available database(s) "
|
|
|
|
"do not allow %s\n", progname );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2005-08-10 19:26:32 +08:00
|
|
|
if ( nosubordinates == 0 && dbnum > 1 ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
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",
|
2005-08-10 19:26:32 +08:00
|
|
|
progname, dbnum, 0 );
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
2009-03-05 18:59:34 +08:00
|
|
|
} else if ( dbnum >= nbackends ) {
|
2004-02-27 03:03:41 +08:00
|
|
|
fprintf( stderr,
|
|
|
|
"Database number selected via -n is out of range\n"
|
2005-08-10 19:26:32 +08:00
|
|
|
"Must be in the range 0 to %d"
|
2009-03-06 02:06:27 +08:00
|
|
|
" (the number of configured databases)\n",
|
|
|
|
nbackends - 1 );
|
2004-02-27 03:03:41 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
|
|
|
|
} else {
|
2009-09-29 15:33:01 +08:00
|
|
|
get_db:
|
2005-03-24 13:13:31 +08:00
|
|
|
LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
|
|
|
|
if ( dbnum == 0 ) break;
|
|
|
|
dbnum--;
|
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
|
2010-01-18 23:00:40 +08:00
|
|
|
if ( scope != LDAP_SCOPE_DEFAULT && BER_BVISNULL( &sub_ndn ) ) {
|
|
|
|
if ( be && be->be_nsuffix ) {
|
|
|
|
ber_dupbv( &sub_ndn, be->be_nsuffix );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
fprintf( stderr,
|
|
|
|
"<scope> needs a DN or a valid database\n" );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-14 01:18:03 +08:00
|
|
|
startup:;
|
2009-03-05 18:59:34 +08:00
|
|
|
if ( be ) {
|
|
|
|
BackendDB *bdtmp;
|
|
|
|
|
|
|
|
dbnum = 0;
|
|
|
|
LDAP_STAILQ_FOREACH( bdtmp, &backendDB, be_next ) {
|
|
|
|
if ( bdtmp == be ) break;
|
|
|
|
dbnum++;
|
|
|
|
}
|
|
|
|
}
|
2004-04-14 01:18:03 +08:00
|
|
|
|
2004-02-27 03:03:41 +08:00
|
|
|
#ifdef CSRIMALLOC
|
|
|
|
mal_leaktrace(1);
|
|
|
|
#endif
|
|
|
|
|
2005-08-12 07:35:47 +08:00
|
|
|
if ( conffile != NULL ) {
|
|
|
|
ch_free( conffile );
|
2009-05-04 19:37:58 +08:00
|
|
|
conffile = NULL;
|
2005-08-12 07:35:47 +08:00
|
|
|
}
|
|
|
|
|
2009-11-24 05:52:11 +08:00
|
|
|
if ( confdir != NULL ) {
|
|
|
|
ch_free( confdir );
|
|
|
|
confdir = NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-12 07:35:47 +08:00
|
|
|
if ( ldiffile != NULL ) {
|
|
|
|
ch_free( ldiffile );
|
2009-05-04 19:37:58 +08:00
|
|
|
ldiffile = NULL;
|
2005-08-12 07:35:47 +08:00
|
|
|
}
|
|
|
|
|
2005-06-10 04:09:15 +08:00
|
|
|
/* slapdn doesn't specify a backend to startup */
|
2006-01-11 02:32:09 +08:00
|
|
|
if ( !dryrun && tool != SLAPDN ) {
|
2005-12-17 06:24:53 +08:00
|
|
|
need_shutdown = 1;
|
|
|
|
|
2006-01-11 02:32:09 +08:00
|
|
|
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;
|
|
|
|
}
|
2005-01-12 22:31:03 +08:00
|
|
|
|
2006-01-11 02:32:09 +08:00
|
|
|
exit( EXIT_FAILURE );
|
2005-01-12 22:31:03 +08:00
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-03 21:23:05 +08:00
|
|
|
int slap_tool_destroy( void )
|
2004-02-27 03:03:41 +08:00
|
|
|
{
|
2008-11-03 21:23:05 +08:00
|
|
|
int rc = 0;
|
2005-04-01 03:34:36 +08:00
|
|
|
if ( !dryrun ) {
|
2005-12-17 06:24:53 +08:00
|
|
|
if ( need_shutdown ) {
|
2008-11-03 21:23:05 +08:00
|
|
|
if ( slap_shutdown( be ))
|
|
|
|
rc = EXIT_FAILURE;
|
2005-12-17 06:24:53 +08:00
|
|
|
}
|
2008-11-03 21:23:05 +08:00
|
|
|
if ( slap_destroy())
|
|
|
|
rc = EXIT_FAILURE;
|
2004-07-19 05:36:39 +08:00
|
|
|
}
|
2004-02-27 03:03:41 +08:00
|
|
|
#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 );
|
2009-05-04 19:37:58 +08:00
|
|
|
BER_BVZERO( &authcDN );
|
2004-07-17 22:45:07 +08:00
|
|
|
}
|
2007-08-27 15:14:04 +08:00
|
|
|
|
|
|
|
if ( ldiffp && ldiffp != &dummy ) {
|
|
|
|
ldif_close( ldiffp );
|
|
|
|
}
|
2008-11-03 21:23:05 +08:00
|
|
|
return rc;
|
2004-02-27 03:03:41 +08:00
|
|
|
}
|
2010-01-18 23:00:40 +08:00
|
|
|
|
2010-12-07 18:50:54 +08:00
|
|
|
int
|
|
|
|
slap_tool_update_ctxcsn(
|
|
|
|
const char *progname,
|
|
|
|
unsigned long sid,
|
|
|
|
struct berval *bvtext )
|
|
|
|
{
|
|
|
|
struct berval ctxdn;
|
|
|
|
ID ctxcsn_id;
|
|
|
|
Entry *ctxcsn_e;
|
|
|
|
int rc = EXIT_SUCCESS;
|
|
|
|
|
|
|
|
if ( !(update_ctxcsn && !dryrun && sid != SLAP_SYNC_SID_MAX + 1) ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( SLAP_SYNC_SUBENTRY( be )) {
|
|
|
|
build_new_dn( &ctxdn, &be->be_nsuffix[0],
|
|
|
|
(struct berval *)&slap_ldapsync_cn_bv, NULL );
|
|
|
|
} else {
|
|
|
|
ctxdn = be->be_nsuffix[0];
|
|
|
|
}
|
|
|
|
ctxcsn_id = be->be_dn2id_get( be, &ctxdn );
|
|
|
|
if ( ctxcsn_id == NOID ) {
|
|
|
|
if ( SLAP_SYNC_SUBENTRY( be )) {
|
|
|
|
ctxcsn_e = slap_create_context_csn_entry( be, NULL );
|
|
|
|
for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
|
|
|
|
if ( maxcsn[ sid ].bv_len ) {
|
|
|
|
attr_merge_one( ctxcsn_e, slap_schema.si_ad_contextCSN,
|
|
|
|
&maxcsn[ sid ], NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctxcsn_id = be->be_entry_put( be, ctxcsn_e, bvtext );
|
|
|
|
if ( ctxcsn_id == NOID ) {
|
|
|
|
fprintf( stderr, "%s: couldn't create context entry\n", progname );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fprintf( stderr, "%s: context entry is missing\n", progname );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctxcsn_e = be->be_entry_get( be, ctxcsn_id );
|
|
|
|
if ( ctxcsn_e != NULL ) {
|
|
|
|
Entry *e = entry_dup( ctxcsn_e );
|
|
|
|
int change;
|
|
|
|
Attribute *attr = attr_find( e->e_attrs, slap_schema.si_ad_contextCSN );
|
|
|
|
if ( attr ) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
change = 0;
|
|
|
|
|
|
|
|
for ( i = 0; !BER_BVISNULL( &attr->a_nvals[ i ] ); i++ ) {
|
|
|
|
int rc_sid;
|
|
|
|
int match;
|
|
|
|
const char *text = NULL;
|
|
|
|
|
|
|
|
rc_sid = slap_parse_csn_sid( &attr->a_nvals[ i ] );
|
|
|
|
if ( rc_sid < 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"%s: unable to extract SID "
|
|
|
|
"from #%d contextCSN=%s\n",
|
|
|
|
progname, i,
|
|
|
|
attr->a_nvals[ i ].bv_val );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( rc_sid <= SLAP_SYNC_SID_MAX );
|
|
|
|
|
|
|
|
sid = (unsigned)rc_sid;
|
|
|
|
|
|
|
|
if ( maxcsn[ sid ].bv_len == 0 ) {
|
|
|
|
match = -1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
value_match( &match, slap_schema.si_ad_entryCSN,
|
|
|
|
slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
|
|
|
|
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
|
|
|
|
&maxcsn[ sid ], &attr->a_nvals[i], &text );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( match > 0 ) {
|
|
|
|
change = 1;
|
|
|
|
} else {
|
|
|
|
AC_MEMCPY( maxcsn[ sid ].bv_val,
|
|
|
|
attr->a_nvals[ i ].bv_val,
|
|
|
|
attr->a_nvals[ i ].bv_len );
|
|
|
|
maxcsn[ sid ].bv_val[ attr->a_nvals[ i ].bv_len ] = '\0';
|
|
|
|
maxcsn[ sid ].bv_len = attr->a_nvals[ i ].bv_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( change ) {
|
|
|
|
if ( attr->a_nvals != attr->a_vals ) {
|
|
|
|
ber_bvarray_free( attr->a_nvals );
|
|
|
|
}
|
|
|
|
attr->a_nvals = NULL;
|
|
|
|
ber_bvarray_free( attr->a_vals );
|
|
|
|
attr->a_vals = NULL;
|
|
|
|
attr->a_numvals = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
change = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( change ) {
|
|
|
|
for ( sid = 0; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
|
|
|
|
if ( maxcsn[ sid ].bv_len ) {
|
|
|
|
attr_merge_one( e, slap_schema.si_ad_contextCSN,
|
|
|
|
&maxcsn[ sid], NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxcsn_id = be->be_entry_modify( be, e, bvtext );
|
|
|
|
if( ctxcsn_id == NOID ) {
|
|
|
|
fprintf( stderr, "%s: could not modify ctxcsn (%s)\n",
|
|
|
|
progname, bvtext->bv_val ? bvtext->bv_val : "" );
|
|
|
|
rc = EXIT_FAILURE;
|
|
|
|
} else if ( verbose ) {
|
|
|
|
fprintf( stderr, "modified: \"%s\" (%08lx)\n",
|
|
|
|
e->e_dn, (long) ctxcsn_id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entry_free( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return value:
|
|
|
|
* -1: update_ctxcsn == 0
|
|
|
|
* SLAP_SYNC_SID_MAX + 1: unable to extract SID
|
|
|
|
* 0 <= SLAP_SYNC_SID_MAX: the SID
|
|
|
|
*/
|
|
|
|
unsigned long
|
|
|
|
slap_tool_update_ctxcsn_check(
|
|
|
|
const char *progname,
|
|
|
|
Entry *e )
|
|
|
|
{
|
|
|
|
if ( update_ctxcsn ) {
|
|
|
|
unsigned long sid = SLAP_SYNC_SID_MAX + 1;
|
|
|
|
int rc_sid;
|
|
|
|
Attribute *attr;
|
|
|
|
|
|
|
|
attr = attr_find( e->e_attrs, slap_schema.si_ad_entryCSN );
|
|
|
|
assert( attr != NULL );
|
|
|
|
|
|
|
|
rc_sid = slap_parse_csn_sid( &attr->a_nvals[ 0 ] );
|
|
|
|
if ( rc_sid < 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "%s: could not "
|
|
|
|
"extract SID from entryCSN=%s, entry dn=\"%s\"\n",
|
|
|
|
progname, attr->a_nvals[ 0 ].bv_val, e->e_name.bv_val );
|
|
|
|
return (unsigned long)(-1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
int match;
|
|
|
|
const char *text = NULL;
|
|
|
|
|
|
|
|
assert( rc_sid <= SLAP_SYNC_SID_MAX );
|
|
|
|
|
|
|
|
sid = (unsigned)rc_sid;
|
|
|
|
if ( maxcsn[ sid ].bv_len != 0 ) {
|
|
|
|
match = 0;
|
|
|
|
value_match( &match, slap_schema.si_ad_entryCSN,
|
|
|
|
slap_schema.si_ad_entryCSN->ad_type->sat_ordering,
|
|
|
|
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
|
|
|
|
&maxcsn[ sid ], &attr->a_nvals[0], &text );
|
|
|
|
} else {
|
|
|
|
match = -1;
|
|
|
|
}
|
|
|
|
if ( match < 0 ) {
|
|
|
|
strcpy( maxcsn[ sid ].bv_val, attr->a_nvals[0].bv_val );
|
|
|
|
maxcsn[ sid ].bv_len = attr->a_nvals[0].bv_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (unsigned long)(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
slap_tool_update_ctxcsn_init(void)
|
|
|
|
{
|
|
|
|
if ( update_ctxcsn ) {
|
|
|
|
unsigned long sid;
|
|
|
|
maxcsn[ 0 ].bv_val = maxcsnbuf;
|
|
|
|
for ( sid = 1; sid <= SLAP_SYNC_SID_MAX; sid++ ) {
|
|
|
|
maxcsn[ sid ].bv_val = maxcsn[ sid - 1 ].bv_val + LDAP_PVT_CSNSTR_BUFSIZE;
|
|
|
|
maxcsn[ sid ].bv_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
slap_tool_entry_check(
|
|
|
|
const char *progname,
|
|
|
|
Operation *op,
|
|
|
|
Entry *e,
|
|
|
|
int lineno,
|
|
|
|
const char **text,
|
|
|
|
char *textbuf,
|
|
|
|
size_t textlen )
|
|
|
|
{
|
|
|
|
/* NOTE: we may want to conditionally enable manage */
|
|
|
|
int manage = 0;
|
|
|
|
|
|
|
|
Attribute *oc = attr_find( e->e_attrs,
|
|
|
|
slap_schema.si_ad_objectClass );
|
|
|
|
|
|
|
|
if( oc == NULL ) {
|
|
|
|
fprintf( stderr, "%s: dn=\"%s\" (line=%d): %s\n",
|
|
|
|
progname, e->e_dn, lineno,
|
|
|
|
"no objectClass attribute");
|
|
|
|
return LDAP_NO_SUCH_ATTRIBUTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check schema */
|
|
|
|
op->o_bd = be;
|
|
|
|
|
|
|
|
if ( (slapMode & SLAP_TOOL_NO_SCHEMA_CHECK) == 0) {
|
|
|
|
int rc = entry_schema_check( op, e, NULL, manage, 1, NULL,
|
|
|
|
text, textbuf, textlen );
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
|
|
|
|
progname, e->e_dn, lineno, rc, *text );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
textbuf[ 0 ] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (slapMode & SLAP_TOOL_VALUE_CHECK) != 0) {
|
|
|
|
Modifications *ml = NULL;
|
|
|
|
|
|
|
|
int rc = slap_entry2mods( e, &ml, text, textbuf, textlen );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
|
|
|
|
progname, e->e_dn, lineno, rc, *text );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
textbuf[ 0 ] = '\0';
|
|
|
|
|
|
|
|
rc = slap_mods_check( op, ml, text, textbuf, textlen, NULL );
|
|
|
|
slap_mods_free( ml, 1 );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
|
|
|
fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
|
|
|
|
progname, e->e_dn, lineno, rc, *text );
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
textbuf[ 0 ] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
2010-01-18 23:00:40 +08:00
|
|
|
|