Rework slapadd schemacheck code to avoid unnecessary -s option

This commit is contained in:
Kurt Zeilenga 2000-09-18 18:10:22 +00:00
parent eab920a399
commit 8083f9701a
6 changed files with 58 additions and 30 deletions

View file

@ -1 +0,0 @@
2.0.X-Engineering

View file

@ -8,7 +8,6 @@ slapadd \- Add entries to a SLAPD database
.B SBINDIR/slapadd
.B [\-v]
.B [\-c]
.B [\-s]
.B [\-d level]
.B [\-b suffix]
.B [\-n dbnum]
@ -38,9 +37,6 @@ enable verbose mode.
.B \-c
enable continue (ignore errors) mode.
.TP
.B \-s
disable schema and other checks.
.TP
.BI \-d " level"
enable debugging messages as defined by the specified
.IR level .

View file

@ -117,6 +117,13 @@ str2entry( char *s )
Debug( LDAP_DEBUG_TRACE,
"<= str2entry: str2ad(%s): %s\n", type, text, 0 );
if( slapMode & SLAP_TOOL_MODE ) {
entry_free( e );
free( value.bv_val );
free( type );
return NULL;
}
rc = slap_str2undef_ad( type, &ad, &text );
if( rc != LDAP_SUCCESS ) {
@ -126,7 +133,37 @@ str2entry( char *s )
entry_free( e );
free( value.bv_val );
free( type );
return( NULL );
return NULL;
}
}
if( slapMode & SLAP_TOOL_MODE ) {
slap_syntax_validate_func *validate =
ad->ad_type->sat_syntax->ssyn_validate;
if( !validate ) {
Debug( LDAP_DEBUG_ANY,
"str2entry: no validator for syntax %s\n",
ad->ad_type->sat_syntax->ssyn_oid, 0, 0 );
entry_free( e );
free( value.bv_val );
free( type );
return NULL;
}
/*
* validate value per syntax
*/
rc = validate( ad->ad_type->sat_syntax, &value );
if( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE,
"str2entry: invalid value for syntax %s\n",
ad->ad_type->sat_syntax->ssyn_oid, 0, 0 );
entry_free( e );
free( value.bv_val );
free( type );
return NULL;
}
}

View file

@ -59,7 +59,7 @@ main( int argc, char **argv )
/* make sure the DN is valid */
if( dn_normalize( e->e_ndn ) == NULL ) {
fprintf( stderr, "%s: bad dn=\"%s\" (line=%d)\n",
fprintf( stderr, "%s: invalid dn=\"%s\" (line=%d)\n",
progname, e->e_dn, lineno );
rc = EXIT_FAILURE;
entry_free( e );
@ -67,7 +67,7 @@ main( int argc, char **argv )
break;
}
/* make sure the DN is valid */
/* make sure the DN is not empty */
if( e->e_ndn == '\0' ) {
fprintf( stderr, "%s: empty dn=\"%s\" (line=%d)\n",
progname, e->e_dn, lineno );
@ -77,7 +77,18 @@ main( int argc, char **argv )
break;
}
if( !noschemacheck ) {
/* check backend */
if( select_backend( e->e_ndn ) != be ) {
fprintf( stderr, "%s: database not configured to "
"hold dn=\"%s\" (line=%d)\n",
progname, e->e_dn, lineno );
rc = EXIT_FAILURE;
entry_free( e );
if( continuemode ) continue;
break;
}
if( global_schemacheck ) {
/* check schema */
const char *text;
if ( entry_schema_check( e, NULL, &text ) != LDAP_SUCCESS ) {
@ -88,20 +99,9 @@ main( int argc, char **argv )
if( continuemode ) continue;
break;
}
/* check backend */
if( select_backend( e->e_ndn ) != be ) {
fprintf( stderr, "%s: database not configured to hold dn=\"%s\" (line=%d)\n",
progname, e->e_dn, lineno );
rc = EXIT_FAILURE;
entry_free( e );
if( continuemode ) continue;
break;
}
}
id = be->be_entry_put( be, e );
if( id == NOID ) {
fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n",
progname, e->e_dn, lineno );
@ -110,7 +110,9 @@ main( int argc, char **argv )
if( continuemode ) continue;
break;
} else if ( verbose ) {
}
if ( verbose ) {
fprintf( stderr, "added: \"%s\" (%08lx)\n",
e->e_dn, (long) id );
}

View file

@ -23,7 +23,6 @@ char *progname = NULL;
char *conffile = SLAPD_DEFAULT_CONFIGFILE;
int truncatemode = 0;
int verbose = 0;
int noschemacheck = 0;
int continuemode = 0;
char *ldiffile = NULL;
@ -42,11 +41,11 @@ usage( int tool )
char *options = NULL;
fprintf( stderr,
"usage: %s [-v] [-c] [-d debuglevel] [-f configfile]\n"
"\t[-n databasenumber | -b suffix]", progname );
"\t[-n databasenumber | -b suffix]", progname );
switch( tool ) {
case SLAPADD:
options = "\t[-s] [-l ldiffile]\n";
options = "\t[-l ldiffile]\n";
break;
case SLAPCAT:
@ -97,7 +96,7 @@ slap_tool_init(
switch( tool ) {
case SLAPADD:
options = "b:cd:f:l:n:stv";
options = "b:cd:f:l:n:tv";
break;
case SLAPINDEX:
@ -142,10 +141,6 @@ slap_tool_init(
dbnum = atoi( optarg ) - 1;
break;
case 's': /* disable schema checking */
noschemacheck++;
break;
case 't': /* turn on truncate */
truncatemode++;
mode |= SLAP_TRUNCATE_MODE;

View file

@ -24,7 +24,6 @@ extern char *conffile;
extern Backend *be;
extern int appendmode;
extern int verbose;
extern int noschemacheck;
extern int continuemode;
extern char *ldiffile;