]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/search.c
use result of validation (ITS#4028)
[openldap] / servers / slapd / back-meta / search.c
index 55edc25767777b32ecacfee03d01f4637ee8e16f..1f1408d19c49b3c8a2054f4e2385cbff347f200d 100644 (file)
@@ -867,9 +867,11 @@ meta_send_entry(
        Entry                   ent = { 0 };
        BerElement              ber = *e->lm_ber;
        Attribute               *attr, **attrp;
-       struct berval           *bv, bdn;
+       struct berval           bdn,
+                               dn = BER_BVNULL;
        const char              *text;
        dncookie                dc;
+       int                     rc;
 
        if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) {
                return LDAP_DECODING_ERROR;
@@ -883,7 +885,7 @@ meta_send_entry(
        dc.rs = rs;
        dc.ctx = "searchResult";
 
-       rs->sr_err = ldap_back_dn_massage( &dc, &bdn, &ent.e_name );
+       rs->sr_err = ldap_back_dn_massage( &dc, &bdn, &dn );
        if ( rs->sr_err != LDAP_SUCCESS) {
                return rs->sr_err;
        }
@@ -895,9 +897,14 @@ meta_send_entry(
         * 
         * FIXME: should we log anything, or delegate to dnNormalize?
         */
-       if ( dnNormalize( 0, NULL, NULL, &ent.e_name, &ent.e_nname,
-               op->o_tmpmemctx ) != LDAP_SUCCESS )
-       {
+       rc = dnPrettyNormal( NULL, &dn, &ent.e_name, &ent.e_nname,
+               op->o_tmpmemctx );
+       if ( dn.bv_val != bdn.bv_val ) {
+               free( dn.bv_val );
+       }
+       BER_BVZERO( &dn );
+
+       if ( rc != LDAP_SUCCESS ) {
                return LDAP_INVALID_DN_SYNTAX;
        }
 
@@ -992,6 +999,8 @@ meta_send_entry(
                if ( attr->a_desc == slap_schema.si_ad_objectClass
                                || attr->a_desc == slap_schema.si_ad_structuralObjectClass )
                {
+                       struct berval   *bv;
+
                        for ( bv = attr->a_vals; !BER_BVISNULL( bv ); bv++ ) {
                                ldap_back_map( &mi->mi_targets[ target ].mt_rwmap.rwm_oc,
                                                bv, &mapped, BACKLDAP_REMAP );
@@ -1045,11 +1054,29 @@ meta_send_entry(
                                                &attr->a_vals[i] );
                                }
 
+                               if ( rc ) {
+                                       LBER_FREE( attr->a_vals[i].bv_val );
+                                       if ( --last == i ) {
+                                               BER_BVZERO( &attr->a_vals[ i ] );
+                                               break;
+                                       }
+                                       attr->a_vals[i] = attr->a_vals[last];
+                                       BER_BVZERO( &attr->a_vals[last] );
+                                       i--;
+                                       continue;
+                               }
+
                                if ( pretty ) {
                                        LBER_FREE( attr->a_vals[i].bv_val );
                                        attr->a_vals[i] = pval;
                                }
                        }
+
+                       if ( last == 0 ) {
+                               ch_free( attr->a_vals );
+                               ch_free( attr );
+                               goto next_attr;
+                       }
                }
 
                if ( last && attr->a_desc->ad_type->sat_equality &&
@@ -1084,9 +1111,7 @@ next_attr:;
        rs->sr_attrs = NULL;
        
        if ( !BER_BVISNULL( &ent.e_name ) ) {
-               if ( ent.e_name.bv_val != bdn.bv_val ) {
-                       free( ent.e_name.bv_val );
-               }
+               free( ent.e_name.bv_val );
                BER_BVZERO( &ent.e_name );
        }
        if ( !BER_BVISNULL( &ent.e_nname ) ) {