X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fvalue.c;h=9ccdf5c0533558386f4f8eb8fe944a673bd15717;hb=7ce9e7b7c637a69fa1fdd78cfdfbf2581bb8217e;hp=293a4e7a35780c1cb502d4a6eb8a0fd5eb9bfd77;hpb=474dfbc8fd75aed0376695ccc2f8c092a7a1bc6f;p=openldap diff --git a/servers/slapd/value.c b/servers/slapd/value.c index 293a4e7a35..9ccdf5c053 100644 --- a/servers/slapd/value.c +++ b/servers/slapd/value.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2005 The OpenLDAP Foundation. + * Copyright 1998-2006 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -271,8 +271,9 @@ ordered_value_renumber( Attribute *a, int vals ) ibv.bv_len = sprintf(ibv.bv_val, "{%d}", i); vtmp = a->a_vals[i]; if ( vtmp.bv_val[0] == '{' ) { - ptr = ber_bvchr(&vtmp, '}') + 1; + ptr = ber_bvchr(&vtmp, '}'); assert( ptr != NULL ); + ++ptr; vtmp.bv_len -= ptr - vtmp.bv_val; vtmp.bv_val = ptr; } @@ -287,8 +288,9 @@ ordered_value_renumber( Attribute *a, int vals ) if ( a->a_nvals && a->a_nvals != a->a_vals ) { vtmp = a->a_nvals[i]; if ( vtmp.bv_val[0] == '{' ) { - ptr = ber_bvchr(&vtmp, '}') + 1; + ptr = ber_bvchr(&vtmp, '}'); assert( ptr != NULL ); + ++ptr; vtmp.bv_len -= ptr - vtmp.bv_val; vtmp.bv_val = ptr; } @@ -347,7 +349,7 @@ ordered_value_sort( Attribute *a, int do_renumber ) a->a_nvals = ch_malloc( (vals+1)*sizeof(struct berval)); BER_BVZERO(a->a_nvals+vals); for ( i=0; ia_vals[i], '}') + 1; + char *ptr = ber_bvchr(&a->a_vals[i], '}') + 1; a->a_nvals[i].bv_len = a->a_vals[i].bv_len - (ptr - a->a_vals[i].bv_val); a->a_nvals[i].bv_val = ch_malloc( a->a_nvals[i].bv_len + 1); @@ -355,7 +357,7 @@ ordered_value_sort( Attribute *a, int do_renumber ) } } else { for ( i=0; ia_nvals[i], '}') + 1; + char *ptr = ber_bvchr(&a->a_nvals[i], '}') + 1; a->a_nvals[i].bv_len -= ptr - a->a_nvals[i].bv_val; strcpy(a->a_nvals[i].bv_val, ptr); } @@ -407,12 +409,13 @@ ordered_value_sort( Attribute *a, int do_renumber ) /* * wrapper for validate function * uses the validate function of the syntax after removing - * the index, if allowed an present + * the index, if allowed and present */ int ordered_value_validate( AttributeDescription *ad, - struct berval *in ) + struct berval *in, + int mop ) { struct berval bv = *in; @@ -433,6 +436,9 @@ ordered_value_validate( bv.bv_len -= ptr - bv.bv_val; bv.bv_val = ptr; in = &bv; + /* If deleting by index, just succeed */ + if ( mop == LDAP_MOD_DELETE && BER_BVISEMPTY( &bv )) + return LDAP_SUCCESS; } } @@ -542,6 +548,11 @@ ordered_value_normalize( bv.bv_len -= idx.bv_len; bv.bv_val = ptr; + /* validator will already prevent this for Adds */ + if ( BER_BVISEMPTY( &bv )) { + ber_dupbv_x( normalized, &idx, ctx ); + return LDAP_SUCCESS; + } val = &bv; } } @@ -698,7 +709,7 @@ ordered_value_add( k = -1; if ( vals[i].bv_val[0] == '{' ) { - k = strtol( vals[i].bv_val+1, &next, 0 ); + k = strtol( vals[i].bv_val + 1, &next, 0 ); if ( next == vals[i].bv_val + 1 || next[ 0 ] != '}' || next - vals[i].bv_val > vals[i].bv_len )