From: Kurt Zeilenga Date: Wed, 18 Aug 1999 01:45:59 +0000 (+0000) Subject: Add schema checking, continue mode, and fix a few leaks. X-Git-Tag: TWEB_OL_BASE~180 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ac50982e3776eecba2fdf5df3921201995434415;p=openldap Add schema checking, continue mode, and fix a few leaks. --- diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 99a793244a..8816cbeaa8 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -49,18 +49,54 @@ main( int argc, char **argv ) Entry *e = str2entry( buf ); if( e == NULL ) { - fprintf( stderr, "%s: could not parse entry at line %d\n", + fprintf( stderr, "%s: could not parse entry (line=%d)\n", progname, lineno ); rc = EXIT_FAILURE; - continue; + if( continuemode ) continue; + break; + } + + if( !noschemacheck ) { + /* make sure the DN is valid */ + if( dn_normalize_case( e->e_ndn ) == NULL ) { + fprintf( stderr, "%s: bad dn=\"%s\" (line=%d)\n", + progname, e->e_dn, lineno ); + rc = EXIT_FAILURE; + entry_free( e ); + if( continuemode ) continue; + break; + } + + /* check schema */ + if ( global_schemacheck && oc_schema_check( e ) != 0 ) { + fprintf( stderr, "%s: entry dn=\"%s\" violates schema violation (line=%d)\n", + progname, e->e_dn, lineno ); + rc = EXIT_FAILURE; + entry_free( e ); + 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 (%s) at line %d\n", + fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d)\n", progname, e->e_dn, lineno ); rc = EXIT_FAILURE; + entry_free( e ); + if( continuemode ) continue; + break; } else if ( verbose ) { fprintf( stderr, "added: \"%s\" (%08ld)\n", diff --git a/servers/slapd/tools/slapcat.c b/servers/slapd/tools/slapcat.c index f5d035e4ab..32fa0214ad 100644 --- a/servers/slapd/tools/slapcat.c +++ b/servers/slapd/tools/slapcat.c @@ -55,10 +55,19 @@ main( int argc, char **argv ) if ( e == NULL ) { printf("# no data for entry id=%08lx\n\n", (long) id ); rc = EXIT_FAILURE; - continue; + if( continuemode ) continue; + break; } data = entry2str( e, &len ); + entry_free( e ); + + if ( data == NULL ) { + printf("# bad data for entry id=%08lx\n\n", (long) id ); + rc = EXIT_FAILURE; + if( continuemode ) continue; + break; + } fputs( data, ldiffp ); fputs( "\n", ldiffp ); diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index 8a678bac26..b9a98f55e8 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -22,6 +22,8 @@ char *progname = NULL; char *conffile = SLAPD_DEFAULT_CONFIGFILE; int truncatemode = 0; int verbose = 0; +int noschemacheck = 0; +int continuemode = 0; char *ldiffile = NULL; FILE *ldiffp = NULL; @@ -33,12 +35,12 @@ usage( int tool ) { char *options = NULL; fprintf( stderr, - "usage: %s [-v] [-d debuglevel] [-f configfile]\n" + "usage: %s [-v] [-c] [-d debuglevel] [-f configfile]\n" "\t[-n databasenumber | -b suffix]", progname ); switch( tool ) { case SLAPADD: - options = "\t[-l ldiffile]\n"; + options = "\t[-s] [-l ldiffile]\n"; break; case SLAPCAT: @@ -80,15 +82,15 @@ slap_tool_init( switch( tool ) { case SLAPADD: - options = "b:d:f:l:n:tv"; + options = "b:cd:f:l:n:stv"; break; case SLAPINDEX: - options = "b:d:f:n:v"; + options = "b:cd:f:n:v"; break; case SLAPCAT: - options = "b:d:f:l:n:v"; + options = "b:cd:f:l:n:v"; break; default: @@ -105,6 +107,10 @@ slap_tool_init( case 'b': base = strdup( optarg ); + case 'c': /* enable continue mode */ + continuemode++; + break; + case 'd': /* turn on debugging */ ldap_debug += atoi( optarg ); break; @@ -121,6 +127,10 @@ 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 a5b62b42b1..c610539c91 100644 --- a/servers/slapd/tools/slapcommon.h +++ b/servers/slapd/tools/slapcommon.h @@ -24,6 +24,8 @@ extern char *conffile; extern Backend *be; extern int appendmode; extern int verbose; +extern int noschemacheck; +extern int continuemode; extern char *ldiffile; extern FILE *ldiffp; diff --git a/servers/slapd/tools/slapindex.c b/servers/slapd/tools/slapindex.c index 8de92b938d..31ae1e3b1e 100644 --- a/servers/slapd/tools/slapindex.c +++ b/servers/slapd/tools/slapindex.c @@ -67,7 +67,8 @@ main( int argc, char **argv ) fprintf( stderr, "entry id=%08lx: no data\n", (long) id ); rc = EXIT_FAILURE; - continue; + if( continuemode ) continue; + break; } if( verbose ) { @@ -78,7 +79,10 @@ main( int argc, char **argv ) if( strcasecmp( type, "dn" ) == 0 ) { attr = attr_find( e->e_attrs, type ); - if( attr == NULL ) continue; + if( attr == NULL ) { + entry_free( e ); + continue; + } values = attr->a_vals; @@ -95,6 +99,11 @@ main( int argc, char **argv ) type, attr->a_vals, id, SLAP_INDEX_ADD_OP ) ) { rc = EXIT_FAILURE; + + if( !continuemode ) { + entry_free( e ); + break; + } } entry_free( e );