]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/rwm.c
ITS#5339
[openldap] / servers / slapd / overlays / rwm.c
index 031f9f5d3c22ec18a094af944d392cf81322c2a0..5275aa57a53961a4e14d151a88ba489a5f153e51 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2003-2007 The OpenLDAP Foundation.
+ * Copyright 2003-2008 The OpenLDAP Foundation.
  * Portions Copyright 2003 Pierangelo Masarati.
  * All rights reserved.
  *
@@ -226,9 +226,7 @@ rwm_op_add( Operation *op, SlapReply *rs )
                {
                        int             j, last;
 
-                       for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[ last ] ); last++ )
-                                       /* count values */ ;
-                       last--;
+                       last = (*ap)->a_numvals - 1;
                        for ( j = 0; !BER_BVISNULL( &(*ap)->a_vals[ j ] ); j++ ) {
                                struct ldapmapping      *mapping = NULL;
 
@@ -245,6 +243,7 @@ rwm_op_add( Operation *op, SlapReply *rs )
                                                        (*ap)->a_vals[ j ] = (*ap)->a_vals[ last ];
                                                }
                                                BER_BVZERO( &(*ap)->a_vals[ last ] );
+                                               (*ap)->a_numvals--;
                                                last--;
                                                j--;
                                        }
@@ -504,14 +503,10 @@ rwm_op_modify( Operation *op, SlapReply *rs )
        isupdate = be_shadow_update( op );
        for ( mlp = &op->orm_modlist; *mlp; ) {
                int                     is_oc = 0;
-               Modifications           *ml;
+               Modifications           *ml = *mlp;
                struct ldapmapping      *mapping = NULL;
 
-               /* duplicate the modlist */
-               ml = ch_malloc( sizeof( Modifications ));
-               *ml = **mlp;
-               *mlp = ml;
-
+               /* ml points to a temporary mod until needs duplication */
                if ( ml->sml_desc == slap_schema.si_ad_objectClass 
                                || ml->sml_desc == slap_schema.si_ad_structuralObjectClass )
                {
@@ -519,6 +514,15 @@ rwm_op_modify( Operation *op, SlapReply *rs )
 
                } else if ( !isupdate && !get_relax( op ) && ml->sml_desc->ad_type->sat_no_user_mod  )
                {
+                       ml = ch_malloc( sizeof( Modifications ) );
+                       *ml = **mlp;
+                       if ( (*mlp)->sml_values ) {
+                               ber_bvarray_dup_x( &ml->sml_values, (*mlp)->sml_values, NULL );
+                               if ( (*mlp)->sml_nvalues ) {
+                                       ber_bvarray_dup_x( &ml->sml_nvalues, (*mlp)->sml_nvalues, NULL );
+                               }
+                       }
+                       *mlp = ml;
                        goto next_mod;
 
                } else {
@@ -533,6 +537,11 @@ rwm_op_modify( Operation *op, SlapReply *rs )
                        }
                }
 
+               /* duplicate the modlist */
+               ml = ch_malloc( sizeof( Modifications ));
+               *ml = **mlp;
+               *mlp = ml;
+
                if ( ml->sml_values != NULL ) {
                        int i, num;
                        struct berval *bva;
@@ -835,8 +844,11 @@ rwm_exop_passwd( Operation *op, SlapReply *rs )
        }
 
        if ( !BER_BVISNULL( &id ) ) {
+               char idNul = id.bv_val[id.bv_len];
+               id.bv_val[id.bv_len] = '\0';
                rs->sr_err = dnPrettyNormal( NULL, &id, &op->o_req_dn,
                                &op->o_req_ndn, op->o_tmpmemctx );
+               id.bv_val[id.bv_len] = idNul;
                if ( rs->sr_err != LDAP_SUCCESS ) {
                        rs->sr_text = "Invalid DN";
                        return rs->sr_err;
@@ -1044,9 +1056,8 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                                        mapping->m_dst_ad->ad_type->sat_equality->smr_normalize )
                                {
                                        int i = 0;
-                                       for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
-                                               /* just count */ ;
 
+                                       last = (*ap)->a_numvals;
                                        if ( last )
                                        {
                                                (*ap)->a_nvals = ch_malloc( (last+1) * sizeof(struct berval) );
@@ -1095,8 +1106,7 @@ rwm_attrs( Operation *op, SlapReply *rs, Attribute** a_first, int stripEntryDN )
                }
 
                if ( last == -1 ) { /* not yet counted */ 
-                       for ( last = 0; !BER_BVISNULL( &(*ap)->a_vals[last] ); last++ )
-                               /* just count */ ;
+                       last = (*ap)->a_numvals;
                }
 
                if ( last == 0 ) {
@@ -1215,8 +1225,11 @@ cleanup_attr:;
                                        mod.sm_op = LDAP_MOD_ADD;
                                        mod.sm_desc = (*ap)->a_desc;
                                        mod.sm_type = mod.sm_desc->ad_cname;
+                                       mod.sm_numvals = (*tap)->a_numvals;
                                        mod.sm_values = (*tap)->a_vals;
-                                       mod.sm_nvalues = (*tap)->a_nvals;
+                                       if ( (*tap)->a_nvals != (*tap)->a_vals ) {
+                                               mod.sm_nvalues = (*tap)->a_nvals;
+                                       }
 
                                        (void)modify_add_values( &e, &mod,
                                                /* permissive */ 1,
@@ -1603,6 +1616,7 @@ rwm_db_config(
                                fname, lineno, argv[ 1 ] );
                        return 1;
                }
+
        } else if ( strcasecmp( argv[0], "normalize-mapped-attrs" ) ==  0 ) {
                if ( argc !=2 ) { 
                        fprintf( stderr,