From 8083f9701a6dbd013dd14666829d2a8627ee2648 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 18 Sep 2000 18:10:22 +0000 Subject: [PATCH] Rework slapadd schemacheck code to avoid unnecessary -s option --- build/version | 1 - doc/man/man8/slapadd.8 | 4 ---- servers/slapd/entry.c | 39 +++++++++++++++++++++++++++++++- servers/slapd/tools/slapadd.c | 32 ++++++++++++++------------ servers/slapd/tools/slapcommon.c | 11 +++------ servers/slapd/tools/slapcommon.h | 1 - 6 files changed, 58 insertions(+), 30 deletions(-) delete mode 100644 build/version diff --git a/build/version b/build/version deleted file mode 100644 index b06c8ab156..0000000000 --- a/build/version +++ /dev/null @@ -1 +0,0 @@ -2.0.X-Engineering diff --git a/doc/man/man8/slapadd.8 b/doc/man/man8/slapadd.8 index 47c2378784..f27be9935d 100644 --- a/doc/man/man8/slapadd.8 +++ b/doc/man/man8/slapadd.8 @@ -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 . diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index c8817c87ef..9ce6f74d98 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -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; } } diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 4cf22f2457..5762364904 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -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 ); } diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index 954635a801..67793bb368 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -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; diff --git a/servers/slapd/tools/slapcommon.h b/servers/slapd/tools/slapcommon.h index dd0f1b1f55..ca8dcf5207 100644 --- a/servers/slapd/tools/slapcommon.h +++ b/servers/slapd/tools/slapcommon.h @@ -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; -- 2.39.5