]> git.sur5r.net Git - openldap/commitdiff
rdn check to prevent illegal rdns in modrdn (copied from dn_rdn) fixes ITS#1102
authorPierangelo Masarati <ando@openldap.org>
Thu, 5 Jul 2001 08:40:40 +0000 (08:40 +0000)
committerPierangelo Masarati <ando@openldap.org>
Thu, 5 Jul 2001 08:40:40 +0000 (08:40 +0000)
servers/slapd/back-ldbm/modrdn.c
servers/slapd/dn.c

index ed804339ad83010429371fe0701430db825a59c0..19b0da05a2f26814ed8eae40e872fa08c28f7db5 100644 (file)
@@ -479,7 +479,7 @@ ldbm_back_modrdn(
            /* Not a big deal but we may say something */
 #ifdef NEW_LOGGING
            LDAP_LOG(( "backend", LDAP_LEVEL_INFO,
-                      "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type-%s\n",
+                      "ldbm_back_modrdn: old_rdn_type=%s new_rdn_type=%s\n",
                       old_rdn_type, new_rdn_type ));
 #else
            Debug( LDAP_DEBUG_TRACE,
index 08cda568fa7072cd43aa37cfbe73721dc0644811..1cf7b42c532bff4d57fdddfe038ae15cdf63602a 100644 (file)
@@ -486,10 +486,55 @@ rdn_attr_value( const char * rdn )
 }
 
 
-int rdn_validate( const char * rdn )
+/* rdn_validate:
+ * 
+ * 1 if rdn is a legal rdn; 
+ * 0 otherwise (including a sequence of rdns)
+ */
+int
+rdn_validate( const char * rdn )
 {
-       /* just a simple check for now */
-       return strchr( rdn, '=' ) != NULL;
+       int     inquote;
+
+       if ( rdn == NULL ) {
+               return( 0 );
+       }
+
+       if ( strchr( rdn, '=' ) == NULL ) {
+               return( 0 );
+       }
+
+       while ( *rdn && ASCII_SPACE( *rdn ) ) {
+               rdn++;
+       }
+
+       if( *rdn == '\0' ) {
+               return( 0 );
+       }
+
+       inquote = 0;
+
+       for ( ; *rdn; rdn++ ) {
+               if ( *rdn == '\\' ) {
+                       if ( *(rdn + 1) ) {
+                               rdn++;
+                       }
+                       continue;
+               }
+               if ( inquote ) {
+                       if ( *rdn == '"' ) {
+                               inquote = 0;
+                       }
+               } else {
+                       if ( *rdn == '"' ) {
+                               inquote = 1;
+                       } else if ( DN_SEPARATOR( *rdn ) ) {
+                               return( 0 );
+                       }
+               }
+       }
+
+       return( 1 );
 }