Add schema checking, continue mode, and fix a few leaks.

This commit is contained in:
Kurt Zeilenga 1999-08-18 01:45:59 +00:00
parent aad3c488da
commit ac50982e37
5 changed files with 77 additions and 11 deletions

View File

@ -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",

View File

@ -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 );

View File

@ -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;

View File

@ -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;

View File

@ -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 );