]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/rwm.c
ITS#5339
[openldap] / servers / slapd / overlays / rwm.c
index a6df7904578028f9e673cdbdbb4ec3dc7dc88a4d..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--;
                                        }
@@ -1057,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) );
@@ -1108,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 ) {
@@ -1228,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,
@@ -1616,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,