From: Pierangelo Masarati Date: Thu, 11 Aug 2005 23:35:15 +0000 (+0000) Subject: wrap validate/pretty/normalize for ordered values (only #ifdef LDAP_DEVEL) X-Git-Tag: OPENLDAP_AC_BP~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2b93e9b376041ee934693424514b98d9b4c9e974;p=openldap wrap validate/pretty/normalize for ordered values (only #ifdef LDAP_DEVEL) --- diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index 9441de24e6..6c1d45b1c4 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -268,15 +268,24 @@ str2entry2( char *s, int checkvals ) slap_syntax_transform_func *pretty = ad->ad_type->sat_syntax->ssyn_pretty; - if( pretty ) { + if ( pretty ) { +#ifdef SLAP_ORDERED_PRETTYNORM + rc = ordered_value_pretty( ad, + &vals[i], &pval, NULL ); +#else /* ! SLAP_ORDERED_PRETTYNORM */ rc = pretty( ad->ad_type->sat_syntax, &vals[i], &pval, NULL ); +#endif /* ! SLAP_ORDERED_PRETTYNORM */ - } else if( validate ) { + } else if ( validate ) { /* * validate value per syntax */ +#ifdef SLAP_ORDERED_PRETTYNORM + rc = ordered_value_validate( ad, &vals[i] ); +#else /* ! SLAP_ORDERED_PRETTYNORM */ rc = validate( ad->ad_type->sat_syntax, &vals[i] ); +#endif /* ! SLAP_ORDERED_PRETTYNORM */ } else { Debug( LDAP_DEBUG_ANY, @@ -303,16 +312,24 @@ str2entry2( char *s, int checkvals ) } } - if( ad->ad_type->sat_equality && + if ( ad->ad_type->sat_equality && ad->ad_type->sat_equality->smr_normalize ) { +#ifdef SLAP_ORDERED_PRETTYNORM + rc = ordered_value_normalize( + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + ad, + ad->ad_type->sat_equality, + &vals[i], &nvals[i], NULL ); +#else /* ! SLAP_ORDERED_PRETTYNORM */ rc = ad->ad_type->sat_equality->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, ad->ad_type->sat_syntax, ad->ad_type->sat_equality, &vals[i], &nvals[i], NULL ); +#endif /* ! SLAP_ORDERED_PRETTYNORM */ - if( rc ) { + if ( rc ) { Debug( LDAP_DEBUG_ANY, "<= str2entry NULL (smr_normalize %d)\n", rc, 0, 0 ); goto fail; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 4025e40b37..56d6c0bf4a 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -668,14 +668,25 @@ int slap_mods_check( * check that each value is valid per syntax * and pretty if appropriate */ - for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) { + for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) { struct berval pval; - if( pretty ) { + + if ( pretty ) { +#ifdef SLAP_ORDERED_PRETTYNORM + rc = ordered_value_pretty( ad, + &ml->sml_values[nvals], &pval, ctx ); +#else /* ! SLAP_ORDERED_PRETTYNORM */ rc = pretty( ad->ad_type->sat_syntax, &ml->sml_values[nvals], &pval, ctx ); +#endif /* ! SLAP_ORDERED_PRETTYNORM */ } else { +#ifdef SLAP_ORDERED_PRETTYNORM + rc = ordered_value_validate( ad, + &ml->sml_values[nvals] ); +#else /* ! SLAP_ORDERED_PRETTYNORM */ rc = validate( ad->ad_type->sat_syntax, &ml->sml_values[nvals] ); +#endif /* ! SLAP_ORDERED_PRETTYNORM */ } if( rc != 0 ) { @@ -720,13 +731,21 @@ int slap_mods_check( ml->sml_nvalues = ber_memalloc_x( (nvals+1)*sizeof(struct berval), ctx ); - for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) { + for ( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) { +#ifdef SLAP_ORDERED_PRETTYNORM + rc = ordered_value_normalize( + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + ad, + ad->ad_type->sat_equality, + &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx ); +#else /* ! SLAP_ORDERED_PRETTYNORM */ rc = ad->ad_type->sat_equality->smr_normalize( SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, ad->ad_type->sat_syntax, ad->ad_type->sat_equality, &ml->sml_values[nvals], &ml->sml_nvalues[nvals], ctx ); - if( rc ) { +#endif /* ! SLAP_ORDERED_PRETTYNORM */ + if ( rc ) { Debug( LDAP_DEBUG_ANY, "<= str2entry NULL (ssyn_normalize %d)\n", rc, 0, 0 ); @@ -738,8 +757,7 @@ int slap_mods_check( } } - ml->sml_nvalues[nvals].bv_val = NULL; - ml->sml_nvalues[nvals].bv_len = 0; + BER_BVZERO( &ml->sml_nvalues[nvals] ); } /* check for duplicates, but ignore Deletes. diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 5ad9092de7..4542c96886 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1513,6 +1513,24 @@ LDAP_SLAPD_F (int) ordered_value_add LDAP_P(( BerVarray vals, BerVarray nvals )); +LDAP_SLAPD_F (int) ordered_value_validate LDAP_P(( + AttributeDescription *ad, + struct berval *in )); + +LDAP_SLAPD_F (int) ordered_value_pretty LDAP_P(( + AttributeDescription *ad, + struct berval *val, + struct berval *out, + void *ctx )); + +LDAP_SLAPD_F (int) ordered_value_normalize LDAP_P(( + slap_mask_t usage, + AttributeDescription *ad, + MatchingRule *mr, + struct berval *val, + struct berval *normalized, + void *ctx )); + LDAP_SLAPD_F (int) ordered_value_match LDAP_P(( int *match, AttributeDescription *ad, diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 7d97375c36..81a01025d7 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -71,6 +71,8 @@ LDAP_BEGIN_DECL #define SLAP_CONTROL_X_TREE_DELETE LDAP_CONTROL_X_TREE_DELETE #define SLAPD_CONF_UNKNOWN_BAILOUT +#define SLAP_ORDERED_PRETTYNORM + #ifdef ENABLE_REWRITE #define SLAP_AUTH_REWRITE 1 /* use librewrite for sasl-regexp */ #endif diff --git a/servers/slapd/value.c b/servers/slapd/value.c index aab6b34bc8..898715ed4c 100644 --- a/servers/slapd/value.c +++ b/servers/slapd/value.c @@ -396,6 +396,166 @@ ordered_value_sort( Attribute *a, int do_renumber ) return 0; } +/* + * wrapper for validate function + * uses the validate function of the syntax after removing + * the index, if allowed an present + */ +int +ordered_value_validate( + AttributeDescription *ad, + struct berval *in ) +{ + struct berval bv = *in; + + assert( ad->ad_type->sat_syntax != NULL ); + assert( ad->ad_type->sat_syntax->ssyn_validate != NULL ); + + if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) { + + /* Skip past the assertion index */ + if ( bv.bv_val[0] == '{' ) { + char *ptr; + + ptr = strchr( bv.bv_val, '}' ); + if ( ptr == NULL ) { + return LDAP_INVALID_SYNTAX; + } + ptr++; + bv.bv_len -= ptr - bv.bv_val; + bv.bv_val = ptr; + in = &bv; + } + } + + return ad->ad_type->sat_syntax->ssyn_validate( ad->ad_type->sat_syntax, in ); +} + +/* + * wrapper for pretty function + * uses the pretty function of the syntax after removing + * the index, if allowed and present; in case, it's prepended + * to the pretty value + */ +int +ordered_value_pretty( + AttributeDescription *ad, + struct berval *val, + struct berval *out, + void *ctx ) +{ + struct berval bv = *val, + idx = BER_BVNULL; + int rc; + + assert( ad->ad_type->sat_syntax != NULL ); + assert( ad->ad_type->sat_syntax->ssyn_pretty != NULL ); + assert( val != NULL ); + assert( out != NULL ); + + if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) { + + /* Skip past the assertion index */ + if ( bv.bv_val[0] == '{' ) { + char *ptr; + + ptr = strchr( bv.bv_val, '}' ); + if ( ptr == NULL ) { + return LDAP_INVALID_SYNTAX; + } + ptr++; + + idx = bv; + idx.bv_len = ptr - bv.bv_val; + + bv.bv_len -= idx.bv_len; + bv.bv_val = ptr; + + val = &bv; + } + } + + rc = ad->ad_type->sat_syntax->ssyn_pretty( ad->ad_type->sat_syntax, val, out, ctx ); + + if ( rc == LDAP_SUCCESS && !BER_BVISNULL( &idx ) ) { + bv = *out; + + out->bv_len = idx.bv_len + bv.bv_len; + out->bv_val = ber_memalloc_x( out->bv_len + 1, ctx ); + + AC_MEMCPY( out->bv_val, idx.bv_val, idx.bv_len ); + AC_MEMCPY( &out->bv_val[ idx.bv_len ], bv.bv_val, bv.bv_len + 1 ); + + ber_memfree_x( bv.bv_val, ctx ); + } + + return rc; +} + +/* + * wrapper for normalize function + * uses the normalize function of the attribute description equality rule + * after removing the index, if allowed and present; in case, it's + * prepended to the value + */ +int +ordered_value_normalize( + slap_mask_t usage, + AttributeDescription *ad, + MatchingRule *mr, + struct berval *val, + struct berval *normalized, + void *ctx ) +{ + struct berval bv = *val, + idx = BER_BVNULL; + int rc; + + assert( ad->ad_type->sat_equality != NULL ); + assert( ad->ad_type->sat_equality->smr_normalize != NULL ); + assert( val != NULL ); + assert( normalized != NULL ); + + if ( ad->ad_type->sat_flags & SLAP_AT_ORDERED ) { + + /* Skip past the assertion index */ + if ( bv.bv_val[0] == '{' ) { + char *ptr; + + ptr = strchr( bv.bv_val, '}' ); + if ( ptr == NULL ) { + return LDAP_INVALID_SYNTAX; + } + ptr++; + + idx = bv; + idx.bv_len = ptr - bv.bv_val; + + bv.bv_len -= idx.bv_len; + bv.bv_val = ptr; + + val = &bv; + } + } + + rc = ad->ad_type->sat_equality->smr_normalize( usage, + ad->ad_type->sat_syntax, mr, val, normalized, ctx ); + + if ( rc == LDAP_SUCCESS && !BER_BVISNULL( &idx ) ) { + bv = *normalized; + + normalized->bv_len = idx.bv_len + bv.bv_len; + normalized->bv_val = ber_memalloc_x( normalized->bv_len + 1, ctx ); + + AC_MEMCPY( normalized->bv_val, idx.bv_val, idx.bv_len ); + AC_MEMCPY( &normalized->bv_val[ idx.bv_len ], bv.bv_val, bv.bv_len + 1 ); + + ber_memfree_x( bv.bv_val, ctx ); + } + + return rc; +} + /* A wrapper for value match, handles Equality matches for attributes * with ordered values. */