]> git.sur5r.net Git - openldap/commitdiff
allow '-o value-check={yes|no}' for optional value checking, disabled in quick mode...
authorPierangelo Masarati <ando@openldap.org>
Tue, 7 Sep 2010 05:47:55 +0000 (05:47 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 7 Sep 2010 05:47:55 +0000 (05:47 +0000)
servers/slapd/slap.h
servers/slapd/slapadd.c
servers/slapd/slapcommon.c

index 81ceca8655b837ec8439cbf8f96ade9ee82bfc1d..a4bf1e9bc23d8d4c1af4535c179ac92917611d7a 100644 (file)
@@ -1588,6 +1588,7 @@ LDAP_SLAPD_V (int) slapMode;
 #define        SLAP_TOOL_READONLY      0x0400
 #define        SLAP_TOOL_QUICK         0x0800
 #define SLAP_TOOL_NO_SCHEMA_CHECK      0x1000
+#define SLAP_TOOL_VALUE_CHECK  0x2000
 
 #define SB_TLS_DEFAULT         (-1)
 #define SB_TLS_OFF             0
index fe205eafb5f00bff907d0a83a8c2c3845be565a6..d88e1219713d78daf1dbf5842e512c8672b2c98d 100644 (file)
@@ -103,6 +103,14 @@ slapadd( int argc, char **argv )
 
        checkvals = (slapMode & SLAP_TOOL_QUICK) ? 0 : 1;
 
+       /* do not check values in quick mode */
+       if ( slapMode & SLAP_TOOL_QUICK ) {
+               if ( slapMode & SLAP_TOOL_VALUE_CHECK ) {
+                       fprintf( stderr, "%s: value-check incompatible with quick mode; disabled.\n", progname );
+                       slapMode &= ~SLAP_TOOL_VALUE_CHECK;
+               }
+       }
+
        lmax = 0;
        nextline = 0;
 
@@ -267,6 +275,34 @@ slapadd( int argc, char **argv )
                                }
                                textbuf[ 0 ] = '\0';
                        }
+
+                       if ( (slapMode & SLAP_TOOL_VALUE_CHECK) != 0) {
+                               Modifications *ml = NULL;
+
+                               if ( slap_entry2mods( e, &ml, &text, textbuf, textlen )
+                                       != LDAP_SUCCESS )
+                               {
+                                       fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
+                                               progname, e->e_dn, lineno, rc, text );
+                                       rc = EXIT_FAILURE;
+                                       entry_free( e );
+                                       if( continuemode ) continue;
+                                       break;
+                               }
+                               textbuf[ 0 ] = '\0';
+
+                               rc = slap_mods_check( op, ml, &text, textbuf, textlen, NULL );
+                               slap_mods_free( ml, 1 );
+                               if ( rc != LDAP_SUCCESS ) {
+                                       fprintf( stderr, "%s: dn=\"%s\" (line=%d): (%d) %s\n",
+                                               progname, e->e_dn, lineno, rc, text );
+                                       rc = EXIT_FAILURE;
+                                       entry_free( e );
+                                       if( continuemode ) continue;
+                                       break;
+                               }
+                               textbuf[ 0 ] = '\0';
+                       }
                }
 
                if ( SLAP_LASTMOD(be) ) {
index a043764ada06fd09ff0b615adb603bd39656cbd8..5805232176344b710ff708ee48c12ba15595ac10 100644 (file)
@@ -192,6 +192,42 @@ parse_slapopt( int tool, int *mode )
 #endif /* LOG_LOCAL4 */
 #endif /* LDAP_DEBUG && LDAP_SYSLOG */
 
+       } else if ( strncasecmp( optarg, "schema-check", len ) == 0 ) {
+               switch ( tool ) {
+               case SLAPADD:
+                       if ( strcasecmp( p, "yes" ) == 0 ) {
+                               *mode &= ~SLAP_TOOL_NO_SCHEMA_CHECK;
+                       } else if ( strcasecmp( p, "no" ) == 0 ) {
+                               *mode |= SLAP_TOOL_NO_SCHEMA_CHECK;
+                       } else {
+                               Debug( LDAP_DEBUG_ANY, "unable to parse schema-check=\"%s\".\n", p, 0, 0 );
+                               return -1;
+                       }
+                       break;
+
+               default:
+                       Debug( LDAP_DEBUG_ANY, "schema-check meaningless for tool.\n", 0, 0, 0 );
+                       break;
+               }
+
+       } else if ( strncasecmp( optarg, "value-check", len ) == 0 ) {
+               switch ( tool ) {
+               case SLAPADD:
+                       if ( strcasecmp( p, "yes" ) == 0 ) {
+                               *mode |= SLAP_TOOL_VALUE_CHECK;
+                       } else if ( strcasecmp( p, "no" ) == 0 ) {
+                               *mode &= ~SLAP_TOOL_VALUE_CHECK;
+                       } else {
+                               Debug( LDAP_DEBUG_ANY, "unable to parse value-check=\"%s\".\n", p, 0, 0 );
+                               return -1;
+                       }
+                       break;
+
+               default:
+                       Debug( LDAP_DEBUG_ANY, "value-check meaningless for tool.\n", 0, 0, 0 );
+                       break;
+               }
+
        } else {
                return -1;
        }