]> git.sur5r.net Git - openldap/commitdiff
Attribute/Modification value counters
authorHoward Chu <hyc@openldap.org>
Fri, 21 Sep 2007 08:43:56 +0000 (08:43 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 21 Sep 2007 08:43:56 +0000 (08:43 +0000)
27 files changed:
servers/slapd/add.c
servers/slapd/attr.c
servers/slapd/back-bdb/monitor.c
servers/slapd/back-ldap/search.c
servers/slapd/back-meta/search.c
servers/slapd/back-sql/entry-id.c
servers/slapd/back-sql/operational.c
servers/slapd/bconfig.c
servers/slapd/entry.c
servers/slapd/modify.c
servers/slapd/modrdn.c
servers/slapd/mods.c
servers/slapd/operational.c
servers/slapd/overlays/accesslog.c
servers/slapd/overlays/dds.c
servers/slapd/overlays/ppolicy.c
servers/slapd/overlays/refint.c
servers/slapd/overlays/rwm.c
servers/slapd/overlays/syncprov.c
servers/slapd/overlays/translucent.c
servers/slapd/passwd.c
servers/slapd/proto-slap.h
servers/slapd/sasl.c
servers/slapd/slap.h
servers/slapd/slapi/slapi_utils.c
servers/slapd/syncrepl.c
servers/slapd/value.c

index 280fb4f20f5c083b564285330ebe7fa6c993f885..1525b4e3e246983215b9250b497c43b6f55c24df 100644 (file)
@@ -380,6 +380,7 @@ slap_mods2entry(
        char *textbuf, size_t textlen )
 {
        Attribute **tail;
+       int i;
 
        if ( initial ) {
                assert( (*e)->e_attrs == NULL );
@@ -400,7 +401,7 @@ slap_mods2entry(
                if( attr != NULL ) {
 #define SLURPD_FRIENDLY
 #ifdef SLURPD_FRIENDLY
-                       ber_len_t i,j;
+                       int j;
 
                        if ( !initial ) {
                                /*      
@@ -413,12 +414,9 @@ slap_mods2entry(
                                return LDAP_SUCCESS;
                        }
 
-                       for( i=0; attr->a_vals[i].bv_val; i++ ) {
-                               /* count them */
-                       }
-                       for( j=0; mods->sml_values[j].bv_val; j++ ) {
-                               /* count them */
-                       }
+                       i = attr->a_numvals;
+                       j = mods->sml_numvals;
+                       attr->a_numvals += j;
                        j++;    /* NULL */
                        
                        attr->a_vals = ch_realloc( attr->a_vals,
@@ -466,9 +464,9 @@ slap_mods2entry(
                attr = attr_alloc( mods->sml_desc );
 
                /* move values to attr structure */
+               i = mods->sml_numvals;
+               attr->a_numvals = mods->sml_numvals;
                if ( dup ) { 
-                       int i;
-                       for ( i = 0; mods->sml_values[i].bv_val; i++ ) /* EMPTY */;
                        attr->a_vals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
                        for ( i = 0; mods->sml_values[i].bv_val; i++ ) {
                                ber_dupbv( &attr->a_vals[i], &mods->sml_values[i] );
@@ -480,8 +478,7 @@ slap_mods2entry(
 
                if ( mods->sml_nvalues ) {
                        if ( dup ) {
-                               int i;
-                               for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) /* EMPTY */;
+                               i = mods->sml_numvals;
                                attr->a_nvals = (BerVarray) ch_calloc( i+1, sizeof( BerValue ));
                                for ( i = 0; mods->sml_nvalues[i].bv_val; i++ ) {
                                        ber_dupbv( &attr->a_nvals[i], &mods->sml_nvalues[i] );
@@ -528,7 +525,8 @@ slap_entry2mods(
 
                mod->sml_type = a_new_desc->ad_cname;
 
-               for ( count = 0; a_new->a_vals[count].bv_val; count++ ) /* EMPTY */;
+               count = a_new->a_numvals;
+               mod->sml_numvals = a_new->a_numvals;
 
                mod->sml_values = (struct berval*) malloc(
                        (count+1) * sizeof( struct berval) );
index 315442466f4403587a8ba80ed6fb722294c40814..f4d76dc21c92269ea15419251e557bb8d2ace93a 100644 (file)
@@ -153,6 +153,7 @@ attr_clean( Attribute *a )
        a->a_comp_data = NULL;
 #endif
        a->a_flags = 0;
+       a->a_numvals = 0;
 }
 
 void
@@ -213,12 +214,9 @@ attr_dup2( Attribute *tmp, Attribute *a )
        if ( a->a_vals != NULL ) {
                int     i;
 
-               for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
-                       /* EMPTY */ ;
-               }
-
-               tmp->a_vals = ch_malloc( (i + 1) * sizeof(struct berval) );
-               for ( i = 0; !BER_BVISNULL( &a->a_vals[i] ); i++ ) {
+               tmp->a_numvals = a->a_numvals;
+               tmp->a_vals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
+               for ( i = 0; i < tmp->a_numvals; i++ ) {
                        ber_dupbv( &tmp->a_vals[i], &a->a_vals[i] );
                        if ( BER_BVISNULL( &tmp->a_vals[i] ) ) break;
                        /* FIXME: error? */
@@ -231,7 +229,7 @@ attr_dup2( Attribute *tmp, Attribute *a )
                if ( a->a_nvals != a->a_vals ) {
                        int     j;
 
-                       tmp->a_nvals = ch_malloc( (i + 1) * sizeof(struct berval) );
+                       tmp->a_nvals = ch_malloc( (tmp->a_numvals + 1) * sizeof(struct berval) );
                        for ( j = 0; !BER_BVISNULL( &a->a_nvals[j] ); j++ ) {
                                assert( j < i );
                                ber_dupbv( &tmp->a_nvals[j], &a->a_nvals[j] );
@@ -283,6 +281,55 @@ attrs_dup( Attribute *a )
        return anew;
 }
 
+int
+attr_valadd(
+       Attribute *a,
+       BerVarray vals,
+       BerVarray nvals,
+       int nn )
+{
+       int             i;
+       BerVarray       v2;
+
+       v2 = (BerVarray) SLAP_REALLOC( (char *) a->a_vals,
+                   (a->a_numvals + nn + 1) * sizeof(struct berval) );
+       if( v2 == NULL ) {
+               Debug(LDAP_DEBUG_TRACE,
+                 "attr_valadd: SLAP_REALLOC failed.\n", 0, 0, 0 );
+               return LBER_ERROR_MEMORY;
+       }
+       a->a_vals = v2;
+       if ( nvals ) {
+               v2 = (BerVarray) SLAP_REALLOC( (char *) a->a_nvals,
+                               (a->a_numvals + nn + 1) * sizeof(struct berval) );
+               if( v2 == NULL ) {
+                       Debug(LDAP_DEBUG_TRACE,
+                         "attr_valadd: SLAP_REALLOC failed.\n", 0, 0, 0 );
+                       return LBER_ERROR_MEMORY;
+               }
+               a->a_nvals = v2;
+       } else {
+               a->a_nvals = a->a_vals;
+       }
+
+       v2 = &a->a_vals[a->a_numvals];
+       for ( i = 0 ; i < nn; i++ ) {
+               ber_dupbv( &v2[i], &vals[i] );
+               if ( BER_BVISNULL( &v2[i] ) ) break;
+       }
+       BER_BVZERO( &v2[i] );
+
+       if ( nvals ) {
+               v2 = &a->a_nvals[a->a_numvals];
+               for ( i = 0 ; i < nn; i++ ) {
+                       ber_dupbv( &v2[i], &nvals[i] );
+                       if ( BER_BVISNULL( &v2[i] ) ) break;
+               }
+               BER_BVZERO( &v2[i] );
+       }
+       a->a_numvals += i;
+       return 0;
+}
 
 /*
  * attr_merge - merge the given type and value with the list of
@@ -302,7 +349,7 @@ attr_merge(
        BerVarray       vals,
        BerVarray       nvals )
 {
-       int rc;
+       int i = 0;
 
        Attribute       **a;
 
@@ -325,18 +372,10 @@ attr_merge(
                                        || ( (*a)->a_nvals != (*a)->a_vals ) ) ) );
        }
 
-       rc = value_add( &(*a)->a_vals, vals );
-
-       if ( rc == LDAP_SUCCESS ) {
-               if ( nvals ) {
-                       rc = value_add( &(*a)->a_nvals, nvals );
-                       /* FIXME: what if rc != LDAP_SUCCESS ? */
-               } else {
-                       (*a)->a_nvals = (*a)->a_vals;
-               }
+       if ( vals != NULL ) {
+               for ( ; !BER_BVISNULL( &vals[i] ); i++ ) ;
        }
-
-       return rc;
+       return attr_valadd( *a, vals, nvals, i );
 }
 
 /*
@@ -415,7 +454,6 @@ attr_merge_one(
        struct berval   *val,
        struct berval   *nval )
 {
-       int rc;
        Attribute       **a;
 
        for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
@@ -428,17 +466,7 @@ attr_merge_one(
                *a = attr_alloc( desc );
        }
 
-       rc = value_add_one( &(*a)->a_vals, val );
-
-       if ( rc == LDAP_SUCCESS ) {
-               if ( nval ) {
-                       rc = value_add_one( &(*a)->a_nvals, nval );
-                       /* FIXME: what if rc != LDAP_SUCCESS ? */
-               } else {
-                       (*a)->a_nvals = (*a)->a_vals;
-               }
-       }
-       return rc;
+       return attr_valadd( *a, val, nval, 1 );
 }
 
 /*
index f30469702cda7bf85d632ba5204b7013c7f8a013..96ad30996755c7393c6757c4d5ce8280639fa3c3 100644 (file)
@@ -371,26 +371,22 @@ bdb_monitor_db_open( BackendDB *be )
        }
 
        a->a_desc = slap_schema.si_ad_objectClass;
-       value_add_one( &a->a_vals, &oc_olmBDBDatabase->soc_cname );
-       a->a_nvals = a->a_vals;
+       attr_valadd( a, &oc_olmBDBDatabase->soc_cname, NULL, 1 );
        next = a->a_next;
 
        {
                struct berval   bv = BER_BVC( "0" );
 
                next->a_desc = ad_olmBDBEntryCache;
-               value_add_one( &next->a_vals, &bv );
-               next->a_nvals = next->a_vals;
+               attr_valadd( next, &bv, NULL, 1 );
                next = next->a_next;
 
                next->a_desc = ad_olmBDBDNCache;
-               value_add_one( &next->a_vals, &bv );
-               next->a_nvals = next->a_vals;
+               attr_valadd( next, &bv, NULL, 1 );
                next = next->a_next;
 
                next->a_desc = ad_olmBDBIDLCache;
-               value_add_one( &next->a_vals, &bv );
-               next->a_nvals = next->a_vals;
+               attr_valadd( next, &bv, NULL, 1 );
                next = next->a_next;
        }
 
@@ -432,6 +428,7 @@ bdb_monitor_db_open( BackendDB *be )
                next->a_desc = ad_olmDbDirectory;
                next->a_vals = ch_calloc( sizeof( struct berval ), 2 );
                next->a_vals[ 0 ] = bv;
+               next->a_numvals = 1;
 
                if ( BER_BVISNULL( &nbv ) ) {
                        next->a_nvals = next->a_vals;
index 13a9fb3960f6b1c877635df192983780058a55f7..69d03ce0a26e4f3dafec7ecb563390ece1ccb452 100644 (file)
@@ -682,6 +682,7 @@ ldap_build_entry(
                        for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); last++ )
                                /* just count vals */ ;
                }
+               attr->a_numvals = last;
 
                validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
                pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
index c9e435b41d08cdf48f0e7605ca3a5ec021357e5b..571d10a663a2e393893066c0b53aa98a0a22fc67 100644 (file)
@@ -1885,6 +1885,7 @@ meta_send_entry(
                        for ( last = 0; !BER_BVISNULL( &attr->a_vals[ last ] ); ++last )
                                ;
                }
+               attr->a_numvals = last;
 
                validate = attr->a_desc->ad_type->sat_syntax->ssyn_validate;
                pretty = attr->a_desc->ad_type->sat_syntax->ssyn_pretty;
index 78f1da14459b6ece37edc0d7eb604450871ab09f..2f8b93820da1aac0ebe5d228500d2f243ad63461 100644 (file)
@@ -645,13 +645,13 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
 
                /* Make space for the array of values */
                attr = attr_alloc( at->bam_true_ad );
+               attr->a_numvals = count;
                attr->a_vals = ch_calloc( count + 1, sizeof( struct berval ) );
                if ( attr->a_vals == NULL ) {
                        Debug( LDAP_DEBUG_TRACE, "Out of memory!\n", 0,0,0 );
                        ch_free( attr );
                        return 1;
                }
-               memset( attr->a_vals, 0, ( count + 1 ) * sizeof( struct berval ) );
                if ( normfunc ) {
                        attr->a_nvals = ch_calloc( count + 1, sizeof( struct berval ) );
                        if ( attr->a_nvals == NULL ) {
@@ -659,8 +659,6 @@ backsql_get_attr_vals( void *v_at, void *v_bsi )
                                ch_free( attr );
                                return 1;
 
-                       } else {
-                               memset( attr->a_nvals, 0, ( count + 1 ) * sizeof( struct berval ) );
                        }
 
                } else {
index f6fe6aea4ff06f768f96c3286e6c6dd06ccc9cdd..6909d7b31a4e720f0d9a8a26248079ee27639e2d 100644 (file)
@@ -55,6 +55,7 @@ backsql_operational_entryUUID( backsql_info *bi, backsql_entryID *id )
 
        a = attr_alloc( desc );
 
+       a->a_numvals = 1;
        a->a_vals = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
        a->a_vals[ 0 ] = val;
        BER_BVZERO( &a->a_vals[ 1 ] );
@@ -74,6 +75,7 @@ backsql_operational_entryCSN( Operation *op )
        Attribute       *a;
 
        a = attr_alloc( slap_schema.si_ad_entryCSN );
+       a->a_numvals = 1;
        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
        BER_BVZERO( &a->a_vals[ 1 ] );
 
index 022b0850e6dcea21fbeebdd61603302907e7bd35..d417ae18d756459ee31c88b48ebb6d35dfaba31c 100644 (file)
@@ -5384,6 +5384,7 @@ config_check_schema(Operation *op, CfBackInfo *cfb)
                                ber_bvarray_free( a->a_vals );
                                a->a_vals = NULL;
                                a->a_nvals = NULL;
+                               a->a_numvals = 0;
                        }
                        oidm_unparse( &bv, NULL, NULL, 1 );
                        attr_merge_normalize( e, cfAd_om, bv, NULL );
@@ -5398,6 +5399,7 @@ config_check_schema(Operation *op, CfBackInfo *cfb)
                                ber_bvarray_free( a->a_vals );
                                a->a_vals = NULL;
                                a->a_nvals = NULL;
+                               a->a_numvals = 0;
                        }
                        at_unparse( &bv, NULL, NULL, 1 );
                        attr_merge_normalize( e, cfAd_attr, bv, NULL );
@@ -5412,6 +5414,7 @@ config_check_schema(Operation *op, CfBackInfo *cfb)
                                ber_bvarray_free( a->a_vals );
                                a->a_vals = NULL;
                                a->a_nvals = NULL;
+                               a->a_numvals = 0;
                        }
                        oc_unparse( &bv, NULL, NULL, 1 );
                        attr_merge_normalize( e, cfAd_oc, bv, NULL );
index 660bcb676b7ba680b3b2aa6f7cb28b2a1e63f914..3e868cc811ffe9a66746c3d2c9dc74cca8c478fb 100644 (file)
@@ -280,6 +280,7 @@ str2entry2( char *s, int checkvals )
                        atail->a_next = attr_alloc( NULL );
                        atail = atail->a_next;
                        atail->a_flags = 0;
+                       atail->a_numvals = attr_cnt;
                        atail->a_desc = ad_prev;
                        atail->a_vals = ch_malloc( (attr_cnt + 1) * sizeof(struct berval));
                        if( ad_prev->ad_type->sat_equality &&
@@ -744,6 +745,7 @@ int entry_encode(Entry *e, struct berval *bv)
                *ptr++ = '\0';
                if (a->a_vals) {
                        for (i=0; a->a_vals[i].bv_val; i++);
+                       assert( i == a->a_numvals );
                        entry_putlen(&ptr, i);
                        for (i=0; a->a_vals[i].bv_val; i++) {
                                entry_putlen(&ptr, a->a_vals[i].bv_len);
@@ -805,7 +807,7 @@ int entry_decode(EntryHeader *eh, Entry **e, void *ctx)
 int entry_decode(EntryHeader *eh, Entry **e)
 #endif
 {
-       int i, j, count, nattrs, nvals;
+       int i, j, nattrs, nvals;
        int rc;
        Attribute *a;
        Entry *x;
@@ -857,7 +859,8 @@ int entry_decode(EntryHeader *eh, Entry **e)
                ptr += i + 1;
                a->a_desc = ad;
                a->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
-               count = j = entry_getlen(&ptr);
+               j = entry_getlen(&ptr);
+               a->a_numvals = j;
                a->a_vals = bptr;
 
                while (j) {
@@ -962,6 +965,7 @@ Entry *entry_dup_bv( Entry *e )
                dst->a_desc = src->a_desc;
                dst->a_flags = SLAP_ATTR_DONT_FREE_DATA | SLAP_ATTR_DONT_FREE_VALS;
                dst->a_vals = bvl;
+               dst->a_numvals = src->a_numvals;
                for ( i=0; src->a_vals[i].bv_val; i++ ) {
                        bvl->bv_len = src->a_vals[i].bv_len;
                        bvl->bv_val = ptr;
index e6ba1dfe4b2aedcf1813af0ca8e777c8e798fbee..f3948d4e33b0f6cf922f88e472b5e6bccf288dc8 100644 (file)
@@ -585,6 +585,7 @@ int slap_mods_check(
                                        ml->sml_values[nvals] = pval;
                                }
                        }
+                       ml->sml_numvals = nvals;
 
                        /*
                         * a rough single value check... an additional check is needed
@@ -946,6 +947,7 @@ void slap_mods_opattrs(
                        mod->sml_next = NULL;
                        BER_BVZERO( &mod->sml_type );
                        mod->sml_desc = slap_schema.si_ad_entryCSN;
+                       mod->sml_numvals = 1;
                        mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &csn );
                        BER_BVZERO( &mod->sml_values[1] );
@@ -963,6 +965,7 @@ void slap_mods_opattrs(
                        mod->sml_next = NULL;
                        BER_BVZERO( &mod->sml_type );
                        mod->sml_desc = slap_schema.si_ad_modifiersName;
+                       mod->sml_numvals = 1;
                        mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &name );
                        BER_BVZERO( &mod->sml_values[1] );
@@ -983,6 +986,7 @@ void slap_mods_opattrs(
                        mod->sml_next = NULL;
                        BER_BVZERO( &mod->sml_type );
                        mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
+                       mod->sml_numvals = 1;
                        mod->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod->sml_values[0], &timestamp );
                        BER_BVZERO( &mod->sml_values[1] );
index 3aae6ac4448c7733197577d195e6069ab2d196e9..e0f1725efef6f43a3e9e19dd01d1327247cebb84 100644 (file)
@@ -428,6 +428,7 @@ slap_modrdn2mods(
                mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
                mod_tmp->sml_desc = desc;
                BER_BVZERO( &mod_tmp->sml_type );
+               mod_tmp->sml_numvals = 1;
                mod_tmp->sml_values = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
                ber_dupbv( &mod_tmp->sml_values[0], &new_rdn[a_cnt]->la_value );
                mod_tmp->sml_values[1].bv_val = NULL;
@@ -469,6 +470,7 @@ slap_modrdn2mods(
                        mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
                        mod_tmp->sml_desc = desc;
                        BER_BVZERO( &mod_tmp->sml_type );
+                       mod_tmp->sml_numvals = 1;
                        mod_tmp->sml_values = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mod_tmp->sml_values[0], &old_rdn[d_cnt]->la_value );
                        mod_tmp->sml_values[1].bv_val = NULL;
index 31b79274c8a0fddf04ac21bcd35bf2c58516b6f8..bfc0cd76e63256d1a2b6933bbb108a8bce6ce764 100644 (file)
@@ -289,6 +289,7 @@ modify_delete_vindex(
                                free( a->a_nvals[j].bv_val );
                                a->a_nvals[j].bv_val = &dummy;
                        }
+                       a->a_numvals--;
 
                        break;
                }
index fd12d0aff6e38f89c691edfe763b8b015e05aedb..f55cfd98f8491b2df94ff7795c3094aae9c30c5d 100644 (file)
@@ -31,6 +31,7 @@ slap_operational_subschemaSubentry( Backend *be )
 
        a = attr_alloc( slap_schema.si_ad_subschemaSubentry );
 
+       a->a_numvals = 1;
        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
        ber_dupbv( a->a_vals, &frontendDB->be_schemadn );
        a->a_vals[1].bv_len = 0;
@@ -55,6 +56,7 @@ slap_operational_entryDN( Entry *e )
 
        a = attr_alloc( slap_schema.si_ad_entryDN );
 
+       a->a_numvals = 1;
        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
        ber_dupbv( &a->a_vals[ 0 ], &e->e_name );
        BER_BVZERO( &a->a_vals[ 1 ] );
@@ -75,6 +77,7 @@ slap_operational_hasSubordinate( int hs )
        val = hs ? slap_true_bv : slap_false_bv;
 
        a = attr_alloc( slap_schema.si_ad_hasSubordinates );
+       a->a_numvals = 1;
        a->a_vals = ch_malloc( 2 * sizeof( struct berval ) );
 
        ber_dupbv( &a->a_vals[0], &val );
index b034d061cb7ce3ceb5766f5811031b9fe3beb9d4..646c9a8d1ffa34639986ab8258ce3b5e9e952772 100644 (file)
@@ -1383,6 +1383,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                vals[i].bv_val = NULL;
                vals[i].bv_len = 0;
                a = attr_alloc( logop == LOG_EN_ADD ? ad_reqMod : ad_reqOld );
+               a->a_numvals = i;
                a->a_vals = vals;
                a->a_nvals = vals;
                last_attr->a_next = a;
@@ -1478,6 +1479,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                if ( i > 0 ) {
                        BER_BVZERO( &vals[i] );
                        a = attr_alloc( ad_reqMod );
+                       a->a_numvals = i;
                        a->a_vals = vals;
                        a->a_nvals = vals;
                        last_attr->a_next = a;
@@ -1509,6 +1511,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                        vals[i].bv_val = NULL;
                        vals[i].bv_len = 0;
                        a = attr_alloc( ad_reqOld );
+                       a->a_numvals = i;
                        a->a_vals = vals;
                        a->a_nvals = vals;
                        last_attr->a_next = a;
@@ -1788,10 +1791,9 @@ accesslog_operational( Operation *op, SlapReply *rs )
                                ad_inlist( ad_auditContext, rs->sr_attrs ) )
                {
                        *ap = attr_alloc( ad_auditContext );
-                       value_add_one( &(*ap)->a_vals,
-                               &li->li_db->be_suffix[0] );
-                       value_add_one( &(*ap)->a_nvals,
-                               &li->li_db->be_nsuffix[0] );
+                       attr_valadd( *ap,
+                               &li->li_db->be_suffix[0],
+                               &li->li_db->be_nsuffix[0], 1 );
                }
        }
 
index 1df2ccd7bbbc061464daa80e7f2ac90a9328ccb2..82ae17a10588ad933e13bfb53ad2b01364d4b27b 100644 (file)
@@ -788,6 +788,7 @@ done:;
                        tmpmod->sml_op = LDAP_MOD_REPLACE;
                        value_add_one( &tmpmod->sml_values, &bv );
                        value_add_one( &tmpmod->sml_nvalues, &bv );
+                       tmpmod->sml_numvals = 1;
                }
        }
 
index 2900c64c31cd0ff17301e976080d1ca26c4df9b8..e126598055cc1fd3e186c8091899474709639bce 100644 (file)
@@ -921,6 +921,7 @@ ppolicy_bind_response( Operation *op, SlapReply *rs )
                m->sml_flags = 0;
                m->sml_type = ad_pwdFailureTime->ad_cname;
                m->sml_desc = ad_pwdFailureTime;
+               m->sml_numvals = 1;
                m->sml_values = ch_calloc( sizeof(struct berval), 2 );
                m->sml_nvalues = ch_calloc( sizeof(struct berval), 2 );
 
@@ -970,6 +971,7 @@ ppolicy_bind_response( Operation *op, SlapReply *rs )
                        m->sml_flags = 0;
                        m->sml_type = ad_pwdAccountLockedTime->ad_cname;
                        m->sml_desc = ad_pwdAccountLockedTime;
+                       m->sml_numvals = 1;
                        m->sml_values = ch_calloc( sizeof(struct berval), 2 );
                        m->sml_nvalues = ch_calloc( sizeof(struct berval), 2 );
                        ber_dupbv( &m->sml_values[0], &timestamp );
@@ -1062,6 +1064,7 @@ grace:
                m->sml_flags = 0;
                m->sml_type = ad_pwdGraceUseTime->ad_cname;
                m->sml_desc = ad_pwdGraceUseTime;
+               m->sml_numvals = 1;
                m->sml_values = ch_calloc( sizeof(struct berval), 2 );
                m->sml_nvalues = ch_calloc( sizeof(struct berval), 2 );
                ber_dupbv( &m->sml_values[0], &timestamp );
@@ -1469,6 +1472,7 @@ ppolicy_modify( Operation *op, SlapReply *rs )
                                ml->sml_flags = SLAP_MOD_INTERNAL;
                                ml->sml_type.bv_val = NULL;
                                ml->sml_desc = ad_pwdGraceUseTime;
+                               ml->sml_numvals = 0;
                                ml->sml_values = NULL;
                                ml->sml_nvalues = NULL;
                                ml->sml_next = NULL;
@@ -1481,6 +1485,7 @@ ppolicy_modify( Operation *op, SlapReply *rs )
                                ml->sml_flags = SLAP_MOD_INTERNAL;
                                ml->sml_type.bv_val = NULL;
                                ml->sml_desc = ad_pwdAccountLockedTime;
+                               ml->sml_numvals = 0;
                                ml->sml_values = NULL;
                                ml->sml_nvalues = NULL;
                                ml->sml_next = NULL;
@@ -1492,6 +1497,7 @@ ppolicy_modify( Operation *op, SlapReply *rs )
                                ml->sml_flags = SLAP_MOD_INTERNAL;
                                ml->sml_type.bv_val = NULL;
                                ml->sml_desc = ad_pwdFailureTime;
+                               ml->sml_numvals = 0;
                                ml->sml_values = NULL;
                                ml->sml_nvalues = NULL;
                                ml->sml_next = NULL;
@@ -1671,6 +1677,7 @@ ppolicy_modify( Operation *op, SlapReply *rs )
                ml->sml_flags = SLAP_MOD_INTERNAL;
                ml->sml_desc = pp.ad;
                ml->sml_type = pp.ad->ad_cname;
+               ml->sml_numvals = 1;
                ml->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                ber_dupbv( &ml->sml_values[0], &oldpw );
                BER_BVZERO( &ml->sml_values[1] );
@@ -1838,6 +1845,7 @@ do_modify:
                mods->sml_desc = ad_pwdChangedTime;
                if (pwmop != LDAP_MOD_DELETE) {
                        mods->sml_op = LDAP_MOD_REPLACE;
+                       mods->sml_numvals = 1;
                        mods->sml_values = (BerVarray) ch_malloc( 2 * sizeof( struct berval ) );
                        ber_dupbv( &mods->sml_values[0], &timestamp );
                        BER_BVZERO( &mods->sml_values[1] );
@@ -1914,6 +1922,7 @@ do_modify:
                                mods->sml_op = LDAP_MOD_DELETE;
                                mods->sml_flags = SLAP_MOD_INTERNAL;
                                mods->sml_desc = ad_pwdHistory;
+                               mods->sml_numvals = hsize - pp.pwdInHistory + 1;
                                mods->sml_values = ch_calloc( sizeof( struct berval ),
                                        hsize - pp.pwdInHistory + 2 );
                                BER_BVZERO( &mods->sml_values[ hsize - pp.pwdInHistory + 1 ] );
@@ -1945,6 +1954,7 @@ do_modify:
                                mods->sml_type.bv_val = NULL;
                                mods->sml_desc = ad_pwdHistory;
                                mods->sml_nvalues = NULL;
+                               mods->sml_numvals = 1;
                                mods->sml_values = ch_calloc( sizeof( struct berval ), 2 );
                                mods->sml_values[ 1 ].bv_val = NULL;
                                mods->sml_values[ 1 ].bv_len = 0;
index 4afc7204e17ac64a878cf3797c86e25a75d2ddd8..6b1d3f72e6d5a0bef93f32c20cbe58eee8bae5d5 100644 (file)
@@ -461,7 +461,7 @@ refint_search_cb(
                                                ber_bvarray_add_x( &na->new_nvals, &newdn, op->o_tmpmemctx );
                                        }
 
-                                       /* count deteles */
+                                       /* count deletes */
                                        if ( BER_BVISEMPTY( &rq->newdn ) ) {
                                                deleted++;
                                        }
@@ -642,6 +642,7 @@ refint_qtask( void *ctx, void *arg )
                                        m->sml_flags = SLAP_MOD_INTERNAL;
                                        m->sml_desc = slap_schema.si_ad_modifiersName;
                                        m->sml_type = m->sml_desc->ad_cname;
+                                       m->sml_numvals = 1;
                                        m->sml_values = (BerVarray)(m+1);
                                        m->sml_nvalues = m->sml_values+2;
                                        BER_BVZERO( &m->sml_values[1] );
@@ -672,6 +673,7 @@ refint_qtask( void *ctx, void *arg )
                                                m->sml_nvalues = m->sml_values+2;
                                                BER_BVZERO( &m->sml_values[1] );
                                                BER_BVZERO( &m->sml_nvalues[1] );
+                                               m->sml_numvals = 1;
                                                if ( BER_BVISEMPTY( &rq->newdn )) {
                                                        op->o_tmpfree( ra, op->o_tmpmemctx );
                                                        ra = dp->attrs;
index 88e7146b7990c0248a724dbc59cbc30c4529eaa8..47068cda38926bd67af0ca8c26c402082b059eea 100644 (file)
@@ -1225,6 +1225,7 @@ 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;
 
index bbdbf30085b373932baa4986e91d4534f44b262b..8a3c6817b154b0525f860109be8d5449d5d0d450 100644 (file)
@@ -2306,9 +2306,9 @@ syncprov_operational(
                                        a->a_nvals = NULL;
                                        ber_bvarray_free( a->a_vals );
                                        a->a_vals = NULL;
+                                       a->a_numvals = 0;
                                }
-                               ber_bvarray_dup_x( &a->a_vals, si->si_ctxcsn, NULL );
-                               ber_bvarray_dup_x( &a->a_nvals, si->si_ctxcsn, NULL );
+                               attr_valadd( a, si->si_ctxcsn, si->si_ctxcsn, si->si_numcsns );
                        }
                        ldap_pvt_thread_rdwr_runlock( &si->si_csn_rwlock );
                }
index dce035531d1d1610d374d1bad2292ec2e9263a33..db9079692f43fe09b21a1c796b98a66a0eb09c9f 100644 (file)
@@ -147,6 +147,7 @@ void glue_parent(Operation *op) {
        ber_dupbv(&e->e_nname, &ndn);
 
        a = attr_alloc( slap_schema.si_ad_objectClass );
+       a->a_numvals = 2;
        a->a_vals = ch_malloc(sizeof(struct berval) * 3);
        ber_dupbv(&a->a_vals[0], &glue[0]);
        ber_dupbv(&a->a_vals[1], &glue[1]);
@@ -156,6 +157,7 @@ void glue_parent(Operation *op) {
        e->e_attrs = a;
 
        a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
+       a->a_numvals = 1;
        a->a_vals = ch_malloc(sizeof(struct berval) * 2);
        ber_dupbv(&a->a_vals[0], &glue[1]);
        ber_dupbv(&a->a_vals[1], &glue[2]);
@@ -428,6 +430,8 @@ release:
                atmp.a_desc = m->sml_desc;
                atmp.a_vals = m->sml_values;
                atmp.a_nvals = m->sml_nvalues ? m->sml_nvalues : atmp.a_vals;
+               atmp.a_numvals = m->sml_numvals;
+               atmp.a_flags = 0;
                a = attr_dup( &atmp );
                a->a_next  = ax;
                ax = a;
index a08bbba4b21f08e5107d4924d193569564ca29fa..9057f969ccd875d9a0dcc86d4874523882c03cff 100644 (file)
@@ -245,6 +245,7 @@ old_good:
                nhash = 1;
                hashes = (char **)defhash;
        }
+       ml->sml_numvals = nhash;
        ml->sml_values = ch_malloc( (nhash+1)*sizeof(struct berval) );
        for ( i=0; hashes[i]; i++ ) {
                slap_passwd_hash_type( &qpw->rs_new, &hash, hashes[i], &rs->sr_text );
index ec130c416012d2c7e864ee791f063ff2b932d42e..0dfce791c804053045ec5192530833af0fa5d6a7 100644 (file)
@@ -268,6 +268,10 @@ LDAP_SLAPD_F (void) comp_tree_free LDAP_P(( Attribute *a ));
 LDAP_SLAPD_F (Attribute *) attr_alloc LDAP_P(( AttributeDescription *ad ));
 LDAP_SLAPD_F (Attribute *) attrs_alloc LDAP_P(( int num ));
 LDAP_SLAPD_F (int) attr_prealloc LDAP_P(( int num ));
+LDAP_SLAPD_F (int) attr_valadd LDAP_P(( Attribute *a,
+       BerVarray vals,
+       BerVarray nvals,
+       int num ));
 LDAP_SLAPD_F (int) attr_merge LDAP_P(( Entry *e,
        AttributeDescription *desc,
        BerVarray vals,
@@ -1803,8 +1807,7 @@ LDAP_SLAPD_F (int) ordered_value_match LDAP_P((
        const char ** text ));
 
 LDAP_SLAPD_F (void) ordered_value_renumber LDAP_P((
-       Attribute *a,
-       int vals ));
+       Attribute *a ));
 
 LDAP_SLAPD_F (int) ordered_value_sort LDAP_P((
        Attribute *a,
index 9e019fdec0bc91a64c34d6d965b8f12528c6c02a..d9a604efc1e08a2f9740e28505fc3b72ed7eba76 100644 (file)
@@ -455,6 +455,7 @@ slap_auxprop_store(
                mod->sml_op = LDAP_MOD_REPLACE;
                mod->sml_flags = 0;
                ber_str2bv( pr[i].name, 0, 0, &mod->sml_type );
+               mod->sml_numvals = pr[i].nvalues;
                mod->sml_values = (struct berval *)ch_malloc( (pr[i].nvalues + 1) *
                        sizeof(struct berval));
                for (j=0; j<pr[i].nvalues; j++) {
index b04ccd3f7a52a8b7690503505767c0e72c432b4e..77077481463b9a5dddc7668fab433a825ff5a7bf 100644 (file)
@@ -1118,11 +1118,13 @@ struct Attribute {
        ComponentData           *a_comp_data;   /* component values */
 #endif
        Attribute               *a_next;
+       unsigned                a_numvals;      /* number of vals */
        unsigned                a_flags;
 #define SLAP_ATTR_IXADD                        0x1U
 #define SLAP_ATTR_IXDEL                        0x2U
 #define SLAP_ATTR_DONT_FREE_DATA       0x4U
 #define SLAP_ATTR_DONT_FREE_VALS       0x8U
+#define        SLAP_ATTR_SORTED_VALS           0x10U
 };
 
 
@@ -1183,6 +1185,7 @@ struct Modification {
        struct berval sm_type;
        BerVarray sm_values;
        BerVarray sm_nvalues;
+       unsigned sm_numvals;
 };
 
 struct Modifications {
@@ -1193,17 +1196,10 @@ struct Modifications {
 #define        sml_type        sml_mod.sm_type
 #define sml_values     sml_mod.sm_values
 #define sml_nvalues    sml_mod.sm_nvalues
+#define sml_numvals    sml_mod.sm_numvals
        Modifications   *sml_next;
 };
 
-struct LDAPModList {
-       LDAPMod         ml_mod;
-       LDAPModList     *ml_next;
-#define ml_op          ml_mod.mod_op
-#define ml_type                ml_mod.mod_type
-#define ml_values      ml_mod.mod_values
-};
-
 /*
  * represents an access control list
  */
index 99d5ccbc33840033df433532ba70d57f2dc75d83..f676e5402dba970b98a91dfbd8dda3df69fc757d 100644 (file)
@@ -2720,6 +2720,7 @@ Modifications *slapi_int_ldapmods2modifications ( Operation *op, LDAPMod **mods
                                        i++;
                        }
                }
+               mod->sml_numvals = i;
 
                if ( i == 0 ) {
                        mod->sml_values = NULL;
index af6de8893d89d25a0432a6441ae9ad73d1ebf042..86a81f32d37018d0eaca7001a19bdc54c1c72c2a 100644 (file)
@@ -1383,6 +1383,7 @@ syncrepl_accesslog_mods(
                        mod->sml_type = ad->ad_cname;
                        mod->sml_values = NULL;
                        mod->sml_nvalues = NULL;
+                       mod->sml_numvals = 0;
 
                        *modtail = mod;
                        modtail = &mod->sml_next;
@@ -1392,6 +1393,7 @@ syncrepl_accesslog_mods(
                        bv.bv_len = vals[i].bv_len - ( bv.bv_val - vals[i].bv_val );
                        ber_dupbv( &bv2, &bv );
                        ber_bvarray_add( &mod->sml_values, &bv2 );
+                       mod->sml_numvals++;
                }
        }
        return modlist;
@@ -1724,6 +1726,7 @@ syncrepl_message_to_entry(
                mod->sml_type = tmp.sml_type;
                mod->sml_values = tmp.sml_values;
                mod->sml_nvalues = NULL;
+               mod->sml_numvals = 0;   /* slap_mods_check will set this */
 
                *modtail = mod;
                modtail = &mod->sml_next;
@@ -2337,6 +2340,7 @@ syncrepl_del_nonpresent(
                                mod1.sml_flags = 0;
                                mod1.sml_desc = slap_schema.si_ad_objectClass;
                                mod1.sml_type = mod1.sml_desc->ad_cname;
+                               mod1.sml_numvals = 2;
                                mod1.sml_values = &gcbva[0];
                                mod1.sml_nvalues = NULL;
                                mod1.sml_next = &mod2;
@@ -2345,6 +2349,7 @@ syncrepl_del_nonpresent(
                                mod2.sml_flags = 0;
                                mod2.sml_desc = slap_schema.si_ad_structuralObjectClass;
                                mod2.sml_type = mod2.sml_desc->ad_cname;
+                               mod1.sml_numvals = 1;
                                mod2.sml_values = &gcbva[1];
                                mod2.sml_nvalues = NULL;
                                mod2.sml_next = NULL;
@@ -2472,6 +2477,7 @@ syncrepl_add_glue(
 
                a = attr_alloc( slap_schema.si_ad_objectClass );
 
+               a->a_numvals = 2;
                a->a_vals = ch_calloc( 3, sizeof( struct berval ) );
                ber_dupbv( &a->a_vals[0], &gcbva[0] );
                ber_dupbv( &a->a_vals[1], &gcbva[1] );
@@ -2484,6 +2490,7 @@ syncrepl_add_glue(
 
                a = attr_alloc( slap_schema.si_ad_structuralObjectClass );
 
+               a->a_numvals = 1;
                a->a_vals = ch_calloc( 2, sizeof( struct berval ) );
                ber_dupbv( &a->a_vals[0], &gcbva[1] );
                ber_dupbv( &a->a_vals[1], &gcbva[2] );
@@ -2727,6 +2734,7 @@ attr_cmp( Operation *op, Attribute *old, Attribute *new,
                        mod->sml_flags = 0;
                        mod->sml_desc = old->a_desc;
                        mod->sml_type = mod->sml_desc->ad_cname;
+                       mod->sml_numvals = no;
                        mod->sml_values = ch_malloc( ( no + 1 ) * sizeof(struct berval) );
                        if ( old->a_vals != old->a_nvals ) {
                                mod->sml_nvalues = ch_malloc( ( no + 1 ) * sizeof(struct berval) );
@@ -2758,6 +2766,7 @@ attr_cmp( Operation *op, Attribute *old, Attribute *new,
                        mod->sml_flags = 0;
                        mod->sml_desc = old->a_desc;
                        mod->sml_type = mod->sml_desc->ad_cname;
+                       mod->sml_numvals = nn;
                        mod->sml_values = ch_malloc( ( nn + 1 ) * sizeof(struct berval) );
                        if ( old->a_vals != old->a_nvals ) {
                                mod->sml_nvalues = ch_malloc( ( nn + 1 ) * sizeof(struct berval) );
@@ -2937,6 +2946,7 @@ dn_callback(
                                                        mod->sml_flags = 0;
                                                        mod->sml_desc = old->a_desc;
                                                        mod->sml_type = mod->sml_desc->ad_cname;
+                                                       mod->sml_numvals = 0;
                                                        mod->sml_values = NULL;
                                                        mod->sml_nvalues = NULL;
                                                        *modtail = mod;
index ac6ddd3c5372f0d0bd2aef269ac34a48a8cb9d87..64d7298dde912a25ca01855cfad3a813151de93c 100644 (file)
@@ -263,7 +263,7 @@ int value_find_ex(
 
 /* assign new indexes to an attribute's ordered values */
 void
-ordered_value_renumber( Attribute *a, int vals )
+ordered_value_renumber( Attribute *a )
 {
        char *ptr, ibuf[64];    /* many digits */
        struct berval ibv, tmp, vtmp;
@@ -271,7 +271,7 @@ ordered_value_renumber( Attribute *a, int vals )
 
        ibv.bv_val = ibuf;
 
-       for (i=0; i<vals; i++) {
+       for (i=0; i<a->a_numvals; i++) {
                ibv.bv_len = sprintf(ibv.bv_val, "{%d}", i);
                vtmp = a->a_vals[i];
                if ( vtmp.bv_val[0] == '{' ) {
@@ -405,7 +405,7 @@ ordered_value_sort( Attribute *a, int do_renumber )
        }
 
        if ( do_renumber && renumber )
-               ordered_value_renumber( a, vals );
+               ordered_value_renumber( a );
 
        return 0;
 }
@@ -706,16 +706,14 @@ ordered_value_add(
        vnum = i;
 
        if ( a ) {
-               for (i=0; !BER_BVISNULL( a->a_vals+i ); i++) ;
-               anum = i;
                ordered_value_sort( a, 0 );
        } else {
                Attribute **ap;
-               anum = 0;
                for ( ap=&e->e_attrs; *ap; ap = &(*ap)->a_next ) ;
                a = attr_alloc( ad );
                *ap = a;
        }
+       anum = a->a_numvals;
 
        new = ch_malloc( (anum+vnum+1) * sizeof(struct berval));
 
@@ -789,7 +787,8 @@ ordered_value_add(
                a->a_nvals = a->a_vals;
        }
 
-       ordered_value_renumber( a, anum );
+       a->a_numvals = anum;
+       ordered_value_renumber( a );
 
        return 0;
 }