X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fvalue.c;h=071286a0ee506f2d825d46856dcc14968f4a9332;hb=dbaf7c5c2503b2770c9075e30a9a63b6ff577d6f;hp=280ab4af5736de9697de846b86a41e0d19cdd4d7;hpb=ba881c5e6fc779cf2bb00f02476f0ec5121a9ddd;p=openldap
diff --git a/servers/slapd/value.c b/servers/slapd/value.c
index 280ab4af57..071286a0ee 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
@@ -75,7 +75,7 @@ value_add(
}
v2 = &(*vals)[n];
- for ( ; !BER_BVISNULL( addvals ); v2++, addvals++ ) {
+ for ( n = 0 ; n < nn; v2++, addvals++ ) {
ber_dupbv( v2, addvals );
if ( BER_BVISNULL( v2 ) ) break;
}
@@ -153,8 +153,12 @@ int asserted_value_validate_normalize(
rc = (mr->smr_syntax->ssyn_pretty)( mr->smr_syntax, in, &pval, ctx );
in = &pval;
- } else {
+ } else if ( mr->smr_syntax->ssyn_validate ) {
rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in );
+
+ } else {
+ *text = "inappropriate matching request";
+ return LDAP_INAPPROPRIATE_MATCHING;
}
if( rc != LDAP_SUCCESS ) {
@@ -225,14 +229,14 @@ int value_find_ex(
return LDAP_INAPPROPRIATE_MATCHING;
}
- assert(SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags ));
+ assert( SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags ) != 0 );
if( !SLAP_IS_MR_ASSERTED_VALUE_NORMALIZED_MATCH( flags ) &&
mr->smr_normalize )
{
rc = (mr->smr_normalize)(
flags & (SLAP_MR_TYPE_MASK|SLAP_MR_SUBTYPE_MASK|SLAP_MR_VALUE_OF_SYNTAX),
- ad ? ad->ad_type->sat_syntax : NULL,
+ ad->ad_type->sat_syntax,
mr, val, &nval, ctx );
if( rc != LDAP_SUCCESS ) {
@@ -271,7 +275,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 = strchr(vtmp.bv_val, '}') + 1;
+ ptr = ber_bvchr(&vtmp, '}');
+ assert( ptr != NULL );
+ ++ptr;
vtmp.bv_len -= ptr - vtmp.bv_val;
vtmp.bv_val = ptr;
}
@@ -286,7 +292,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 = strchr(vtmp.bv_val, '}') + 1;
+ ptr = ber_bvchr(&vtmp, '}');
+ assert( ptr != NULL );
+ ++ptr;
vtmp.bv_len -= ptr - vtmp.bv_val;
vtmp.bv_val = ptr;
}
@@ -321,7 +329,7 @@ ordered_value_sort( Attribute *a, int do_renumber )
if ( a->a_vals[i].bv_val[0] == '{' ) {
char *ptr;
index = 1;
- ptr = strchr( a->a_vals[i].bv_val, '}' );
+ ptr = ber_bvchr( &a->a_vals[i], '}' );
if ( !ptr )
return LDAP_INVALID_SYNTAX;
if ( noindex )
@@ -345,7 +353,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].bv_val, '}') + 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);
@@ -353,7 +361,7 @@ ordered_value_sort( Attribute *a, int do_renumber )
}
} else {
for ( i=0; ia_nvals[i].bv_val, '}') + 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);
}
@@ -405,12 +413,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;
@@ -423,7 +432,7 @@ ordered_value_validate(
if ( bv.bv_val[0] == '{' ) {
char *ptr;
- ptr = strchr( bv.bv_val, '}' );
+ ptr = ber_bvchr( &bv, '}' );
if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
@@ -431,6 +440,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;
}
}
@@ -465,7 +477,7 @@ ordered_value_pretty(
if ( bv.bv_val[0] == '{' ) {
char *ptr;
- ptr = strchr( bv.bv_val, '}' );
+ ptr = ber_bvchr( &bv, '}' );
if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
@@ -525,10 +537,10 @@ ordered_value_normalize(
if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) {
/* Skip past the assertion index */
- if ( bv.bv_val[0] == '{' ) {
+ if ( bv.bv_val[ 0 ] == '{' ) {
char *ptr;
- ptr = strchr( bv.bv_val, '}' );
+ ptr = ber_bvchr( &bv, '}' );
if ( ptr == NULL ) {
return LDAP_INVALID_SYNTAX;
}
@@ -540,6 +552,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;
}
}
@@ -600,7 +617,11 @@ ordered_value_match(
/* Skip past the assertion index */
if ( bv2.bv_val[0] == '{' ) {
- ptr = strchr( bv2.bv_val, '}' ) + 1;
+ ptr = ber_bvchr( &bv2, '}' );
+ if ( ptr == NULL ) {
+ return LDAP_INVALID_SYNTAX;
+ }
+ ptr++;
bv2.bv_len -= ptr - bv2.bv_val;
bv2.bv_val = ptr;
v2 = &bv2;
@@ -627,7 +648,11 @@ ordered_value_match(
}
/* Skip past the attribute index */
if ( bv1.bv_val[0] == '{' ) {
- ptr = strchr( bv1.bv_val, '}' ) + 1;
+ ptr = ber_bvchr( &bv1, '}' );
+ if ( ptr == NULL ) {
+ return LDAP_INVALID_SYNTAX;
+ }
+ ptr++;
bv1.bv_len -= ptr - bv1.bv_val;
bv1.bv_val = ptr;
v1 = &bv1;
@@ -666,8 +691,7 @@ ordered_value_add(
Attribute **ap;
anum = 0;
for ( ap=&e->e_attrs; *ap; ap = &(*ap)->a_next ) ;
- a = ch_calloc( 1, sizeof(Attribute) );
- a->a_desc = ad;
+ a = attr_alloc( ad );
*ap = a;
}
@@ -684,9 +708,19 @@ ordered_value_add(
}
for (i=0; i vals[i].bv_len )
+ {
+ ch_free( nnew );
+ ch_free( new );
+ return -1;
+ }
if ( k > anum ) k = -1;
}
/* No index, or index is greater than current number of