]> git.sur5r.net Git - openldap/commitdiff
Add schema checking, continue mode, and fix a few leaks.
authorKurt Zeilenga <kurt@openldap.org>
Wed, 18 Aug 1999 01:45:59 +0000 (01:45 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 18 Aug 1999 01:45:59 +0000 (01:45 +0000)
servers/slapd/tools/slapadd.c
servers/slapd/tools/slapcat.c
servers/slapd/tools/slapcommon.c
servers/slapd/tools/slapcommon.h
servers/slapd/tools/slapindex.c

index 99a793244af7fb17c31d9f27ab3120f166f2476b..8816cbeaa8815fb3efb14b34ce6924c1239a5cd1 100644 (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",
index f5d035e4abf5d8ecff355d6b6128e7f1834e35b4..32fa0214ad946942c3628d4bd4d134c900afe032 100644 (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 );
index 8a678bac261988e604463a5fac1e0227d83c696f..b9a98f55e8323186eb80d89f95deae980a2e35ef 100644 (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;
index a5b62b42b15406d1c3757113c18fcd396dc5eb4f..c610539c91e76df14bb09cee508525659034f0ab 100644 (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;
index 8de92b938db32647df9279b820db1fb93b9a246a..31ae1e3b1e70cda5e3294e74f2f3aec9371c8283 100644 (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 );