]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/dn.c
Fixup bdb_entry_release now that entry_decode uses two memory blocks
[openldap] / servers / slapd / dn.c
index 780cbb0a50ed9bbc39cd6aebe2ddab9d792caf71..851a86242f7f7680ef3af1f96cb01d0dad3455c9 100644 (file)
 #define INQUOTEDVALUE  7
 #define B4SEPARATOR            8
 
-/* schema_init.c */
-extern int 
-dnNormalize( Syntax *syntax, struct berval *val, struct berval **normalized );
-
 /*
  * dn_validate - validate and compress dn.  the dn is
  * compressed in place are returned if valid.
@@ -40,6 +36,33 @@ dnNormalize( Syntax *syntax, struct berval *val, struct berval **normalized );
 char *
 dn_validate( char *dn_in )
 {
+#ifdef USE_LDAP_DN_PARSING
+       struct berval   val, *normalized;
+       int             rc;
+
+       if ( dn_in == NULL || dn_in[ 0 ] == '\0' ) {
+               return( dn_in );
+       }
+
+       val.bv_val = dn_in;
+       val.bv_len = strlen( dn_in );
+
+       rc = dnPretty( NULL, &val, &normalized );
+       if ( rc != LDAP_SUCCESS ) {
+               return( NULL );
+       }
+
+       if ( val.bv_len < normalized->bv_len ) {
+               ber_bvfree( normalized );
+               return( NULL );
+       }
+
+       AC_MEMCPY( dn_in, normalized->bv_val, normalized->bv_len + 1 );
+       ber_bvfree( normalized );
+
+       return( dn_in );
+       
+#else /* !USE_LDAP_DN_PARSING */
        char    *d, *s;
        int     state, gotesc;
        char    *dn = dn_in;
@@ -195,6 +218,7 @@ dn_validate( char *dn_in )
        }
 
        return( dn );
+#endif /* !USE_LDAP_DN_PARSING */
 }
 
 /*
@@ -206,6 +230,35 @@ dn_validate( char *dn_in )
 char *
 dn_normalize( char *dn )
 {
+#ifdef USE_LDAP_DN_PARSING
+       struct berval   val, *normalized;
+       int             rc;
+
+       if ( dn == NULL || dn[ 0 ] == '\0' ) {
+               return( dn );
+       }
+
+       val.bv_val = dn;
+       val.bv_len = strlen( dn );
+
+       rc = dnNormalize( NULL, &val, &normalized );
+       if ( rc != LDAP_SUCCESS ) {
+               return( NULL );
+       }
+
+       if ( val.bv_len < normalized->bv_len ) {
+               ber_bvfree( normalized );
+               return( NULL );
+       }
+
+       AC_MEMCPY( dn, normalized->bv_val, normalized->bv_len + 1 );
+       ber_bvfree( normalized );
+
+       ( void )ldap_pvt_str2upper( dn );
+
+       return( dn );
+       
+#else /* !USE_LDAP_DN_PARSING */
        char *out;
        struct berval *bvdn, *nbvdn;
 
@@ -223,6 +276,25 @@ dn_normalize( char *dn )
        ber_bvfree( bvdn );
 
        return( out );
+#endif /* !USE_LDAP_DN_PARSING */
+}
+
+int
+dn_match( const char *val, const char *asserted )
+{
+       struct berval   bval, basserted;
+
+       if ( val == NULL || asserted == NULL ) {
+               return 0;
+       }
+
+       bval.bv_val = ( char * )val;
+       bval.bv_len = strlen( val );
+
+       basserted.bv_val = ( char * )asserted;
+       basserted.bv_len = strlen( asserted);
+
+       return dnMatch( NULL, 0, NULL, NULL, &bval, &basserted);
 }
 
 /*