/* $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] [-s subtree]\n";
+ " [-l ldiffile] [-a filter] [-s subtree] [-H url]\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";
+ " [-l errorfile] [-a filter] [-s subtree] [-H url]\n";
break;
}
}
static int
-parse_slapopt( void )
+parse_slapopt( int tool, int *mode )
{
size_t len = 0;
char *p;
#endif /* LOG_LOCAL4 */
#endif /* LDAP_DEBUG && LDAP_SYSLOG */
+ } 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;
+ }
+
} else {
return -1;
}
leakfilename = NULL;
#endif
+ scope = LDAP_SCOPE_DEFAULT;
+
switch( tool ) {
case SLAPADD:
options = "b:cd:f:F:gj:l:n:o:qsS:uvw";
break;
case SLAPCAT:
- options = "a:b:cd:f:F:gl:n:o:s:v";
+ options = "a:b:cd:f:F:gH:l:n:o:s:v";
mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
break;
break;
case SLAPSCHEMA:
- options = "a:b:cd:f:F:gl:n:o:s:v";
+ options = "a:b:cd:f:F:gH:l: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;
use_glue = 0;
break;
+ 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;
+
case 'j': /* jump to linenumber */
if ( lutil_atoi( &jumpline, optarg ) ) {
usage( tool, progname );
break;
case 'o':
- if ( parse_slapopt() ) {
+ if ( parse_slapopt( tool, &mode ) ) {
usage( tool, progname );
}
break;
}
break;
- case 's': /* dump subtree */
- if ( tool == SLAPADD )
+ case 's':
+ switch ( tool ) {
+ case SLAPADD:
+ /* no schema check */
mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
- else if ( tool == SLAPCAT || tool == SLAPSCHEMA )
+ break;
+
+ case SLAPCAT:
+ case SLAPSCHEMA:
+ /* dump subtree */
subtree = ch_strdup( optarg );
+ break;
+ }
break;
case 't': /* turn on truncate */
}
switch ( tool ) {
- case SLAPDN:
case SLAPTEST:
+ if ( dbnum >= 0 )
+ goto get_db;
+ /* FALLTHRU */
+ case SLAPDN:
case SLAPAUTH:
be = NULL;
goto startup;
exit( EXIT_FAILURE );
} else {
+get_db:
LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
if ( dbnum == 0 ) break;
dbnum--;
}
}
+ 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 );
+ }
+ }
+
startup:;
if ( be ) {
BackendDB *bdtmp;
conffile = NULL;
}
+ if ( confdir != NULL ) {
+ ch_free( confdir );
+ confdir = NULL;
+ }
+
if ( ldiffile != NULL ) {
ch_free( ldiffile );
ldiffile = NULL;
}
return rc;
}
+
+