From: Kurt Zeilenga Date: Thu, 27 Feb 2003 01:54:43 +0000 (+0000) Subject: SLAP_NVALUES: X-Git-Tag: NO_SLAP_OP_BLOCKS~267 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=152829be87dbff64388e3771807dad467e2d1401;p=openldap SLAP_NVALUES: schema engine updated (but not schema routines so things don't run yet) nvalues mostly populated, enough for tests 0-2 to pass schema routines needs lots of work modify/mods codes needs lots of work --- diff --git a/servers/slapd/acl.c b/servers/slapd/acl.c index 4ca945e8dd..404842ad14 100644 --- a/servers/slapd/acl.c +++ b/servers/slapd/acl.c @@ -889,8 +889,8 @@ dn_match_cleanup:; at = attrs_find( at->a_next, b->a_dn_at ) ) { if( value_find_ex( b->a_dn_at, - SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, at->a_vals, &bv ) - == 0 ) + SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, + at->a_vals, &bv ) == 0 ) { /* found it */ match = 1; diff --git a/servers/slapd/ad.c b/servers/slapd/ad.c index 407b091cad..cc3e7c1674 100644 --- a/servers/slapd/ad.c +++ b/servers/slapd/ad.c @@ -845,3 +845,25 @@ ad_find_option_definition( const char *opt, int optlen ) } return NULL; } + +MatchingRule *ad_mr( + AttributeDescription *ad, + unsigned usage ) +{ + switch( usage & SLAP_MR_TYPE_MASK ) { + case SLAP_MR_NONE: + case SLAP_MR_EQUALITY: + return ad->ad_type->sat_equality; + break; + case SLAP_MR_ORDERING: + return ad->ad_type->sat_ordering; + break; + case SLAP_MR_SUBSTR: + return ad->ad_type->sat_substr; + break; + case SLAP_MR_EXT: + default: + assert( 0 /* ad_mr: bad usage */); + } + return NULL; +} diff --git a/servers/slapd/at.c b/servers/slapd/at.c index 5333e376dc..d0b3e241d7 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -485,6 +485,11 @@ at_add( } if ( sat->sat_ordering_oid ) { + if( !sat->sat_equality ) { + *err = sat->sat_ordering_oid; + return SLAP_SCHERR_ATTR_BAD_MR; + } + mr = mr_find(sat->sat_ordering_oid); if( mr == NULL ) { @@ -520,6 +525,11 @@ at_add( } if ( sat->sat_substr_oid ) { + if( !sat->sat_equality ) { + *err = sat->sat_substr_oid; + return SLAP_SCHERR_ATTR_BAD_MR; + } + mr = mr_find(sat->sat_substr_oid); if( mr == NULL ) { @@ -537,9 +547,7 @@ at_add( * syntax and compat syntaxes instead of those * associated with the substrings rule. */ - if( sat->sat_equality && - sat->sat_syntax != sat->sat_equality->smr_syntax ) - { + if( sat->sat_syntax != sat->sat_equality->smr_syntax ) { if( sat->sat_equality->smr_compat_syntaxes == NULL ) { *err = sat->sat_substr_oid; return SLAP_SCHERR_ATTR_BAD_MR; diff --git a/servers/slapd/ava.c b/servers/slapd/ava.c index 01287a0b4f..4a30f64174 100644 --- a/servers/slapd/ava.c +++ b/servers/slapd/ava.c @@ -63,8 +63,14 @@ get_ava( return rc; } +#ifdef SLAP_NVALUES + rc = asserted_value_validate_normalize( + aa->aa_desc, ad_mr(aa->aa_desc, usage), + usage, &value, &aa->aa_value, text ); +#else rc = value_validate_normalize( aa->aa_desc, usage, &value, &aa->aa_value, text ); +#endif if( rc != LDAP_SUCCESS ) { ch_free( aa ); diff --git a/servers/slapd/back-bdb/compare.c b/servers/slapd/back-bdb/compare.c index df74448224..4f2ab650c5 100644 --- a/servers/slapd/back-bdb/compare.c +++ b/servers/slapd/back-bdb/compare.c @@ -125,7 +125,14 @@ dn2entry_retry: { rc = LDAP_COMPARE_FALSE; - if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) { +#ifdef SLAP_NVALUES + if ( value_find_ex( ava->aa_desc, + SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, + a->a_vals, &ava->aa_value ) == 0 ) +#else + if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) +#endif + { rc = LDAP_COMPARE_TRUE; break; } diff --git a/servers/slapd/back-bdb/group.c b/servers/slapd/back-bdb/group.c index 4113eaa936..10b3b17106 100644 --- a/servers/slapd/back-bdb/group.c +++ b/servers/slapd/back-bdb/group.c @@ -216,10 +216,7 @@ dn2entry_retry: group_oc_name, group_at_name, 0 ); #endif - if( value_find_ex( group_at, - SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, - attr->a_vals, op_ndn ) != LDAP_SUCCESS ) - { + if( value_find_ex( group_at, 0, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( BACK_BDB, DETAIL1, "bdb_group: \"%s\" not in \"%s\": %s\n", diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index feea82ee22..ffe0b4eb17 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -1226,8 +1226,7 @@ bdb_build_lcup_update_ctrl( ber_dupbv( latest_entrycsn_bv, &entrycsn_bv ); } else { res = value_match( &ret, desc, - desc->ad_type->sat_ordering, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + desc->ad_type->sat_ordering, 0, &entrycsn_bv, latest_entrycsn_bv, &text ); if ( res != LDAP_SUCCESS ) { ret = 0; @@ -1368,8 +1367,7 @@ bdb_build_sync_state_ctrl( ber_dupbv( latest_entrycsn_bv, &entrycsn_bv ); } else { res = value_match( &ret, desc, - desc->ad_type->sat_ordering, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + desc->ad_type->sat_ordering, 0, &entrycsn_bv, latest_entrycsn_bv, &text ); if ( res != LDAP_SUCCESS ) { ret = 0; diff --git a/servers/slapd/back-ldbm/group.c b/servers/slapd/back-ldbm/group.c index 1bf1802645..0c3f6c29b4 100644 --- a/servers/slapd/back-ldbm/group.c +++ b/servers/slapd/back-ldbm/group.c @@ -178,9 +178,7 @@ ldbm_back_group( #endif - if( value_find_ex( group_at, SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH, - attr->a_vals, op_ndn ) != LDAP_SUCCESS ) - { + if( value_find_ex( group_at, 0, attr->a_vals, op_ndn ) != LDAP_SUCCESS ) { #ifdef NEW_LOGGING LDAP_LOG( BACK_LDBM, DETAIL1, "ldbm_back_group: \"%s\" not in \"%s\": %s\n", diff --git a/servers/slapd/back-monitor/log.c b/servers/slapd/back-monitor/log.c index dcc34c4bb3..2fd6e4d454 100644 --- a/servers/slapd/back-monitor/log.c +++ b/servers/slapd/back-monitor/log.c @@ -332,7 +332,11 @@ add_values( Entry *e, Modification *mod, int *newlevel ) for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) { int match; int rc = value_match( &match, mod->sm_desc, mr, +#ifdef SLAP_NVALUES + 0, +#else SLAP_MR_ATTRIBUTE_SYNTAX_MATCH, +#endif &a->a_vals[j], &asserted, &text ); if ( rc == LDAP_SUCCESS && match == 0 ) { @@ -411,7 +415,11 @@ delete_values( Entry *e, Modification *mod, int *newlevel ) for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) { int match; int rc = value_match( &match, mod->sm_desc, mr, +#ifdef SLAP_NVALUES + 0, +#else SLAP_MR_ATTRIBUTE_SYNTAX_MATCH, +#endif &a->a_vals[j], &asserted, &text ); if( rc == LDAP_SUCCESS && match != 0 ) { diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index 67651aa877..bca36de6fa 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -143,8 +143,15 @@ do_compare( goto cleanup; } +#ifdef SLAP_NVALUES + rc = asserted_value_validate_normalize( ava.aa_desc, + ava.aa_desc->ad_type->sat_equality, + SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, + &value, &ava.aa_value, &text ); +#else rc = value_validate_normalize( ava.aa_desc, SLAP_MR_EQUALITY, &value, &ava.aa_value, &text ); +#endif if( rc != LDAP_SUCCESS ) { send_ldap_result( conn, op, rc, NULL, text, NULL, NULL ); goto cleanup; @@ -347,7 +354,15 @@ static int compare_entry( { rc = LDAP_COMPARE_FALSE; - if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) { +#ifdef SLAP_NVALUES + if ( value_find_ex( ava->aa_desc, + SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, + a->a_nvals ? a->a_nvals : a->a_vals, + &ava->aa_value ) == 0 ) +#else + if ( value_find( ava->aa_desc, a->a_vals, &ava->aa_value ) == 0 ) +#endif + { rc = LDAP_COMPARE_TRUE; break; } diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 148d8155e9..2b76efc586 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -241,8 +241,11 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) LDAPAVA *ava = rdn[ 0 ][ iAVA ]; AttributeDescription *ad; slap_syntax_validate_func *validf = NULL; +#ifdef SLAP_NVALUES + slap_mr_normalize_func *normf = NULL; +#endif slap_syntax_transform_func *transf = NULL; - MatchingRule *mr; + MatchingRule *mr = NULL; struct berval bv = { 0, NULL }; int do_sort = 0; @@ -267,17 +270,19 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) if( ava->la_flags & LDAP_AVA_BINARY ) { /* AVA is binary encoded, don't muck with it */ - validf = NULL; - transf = NULL; - mr = NULL; } else if( flags & SLAP_LDAPDN_PRETTY ) { - validf = NULL; transf = ad->ad_type->sat_syntax->ssyn_pretty; - mr = NULL; - } else { + if( !transf ) { + validf = ad->ad_type->sat_syntax->ssyn_validate; + } + } else { /* normalization */ validf = ad->ad_type->sat_syntax->ssyn_validate; - transf = ad->ad_type->sat_syntax->ssyn_normalize; mr = ad->ad_type->sat_equality; +#ifdef SLAP_NVALUES + if( mr ) normf = mr->smr_normalize; +#else + transf = ad->ad_type->sat_syntax->ssyn_normalize; +#endif } if ( validf ) { @@ -294,7 +299,11 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) if ( transf ) { /* +#ifdef SLAP_NVALUES + * transform value by pretty function +#else * transform value by normalize/pretty function +#endif * if value is empty, use empty_bv */ rc = ( *transf )( ad->ad_type->sat_syntax, @@ -308,6 +317,27 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) } } +#ifdef SLAP_NVALUES + if ( normf ) { + /* + * normalize value + * if value is empty, use empty_bv + */ + rc = ( *normf )( + 0, + ad->ad_type->sat_syntax, + mr, + ava->la_value.bv_len + ? &ava->la_value + : (struct berval *) &slap_empty_bv, + &bv ); + + if ( rc != LDAP_SUCCESS ) { + return LDAP_INVALID_SYNTAX; + } + } + +#else if( mr && ( mr->smr_usage & SLAP_MR_DN_FOLD ) ) { char *s = bv.bv_val; @@ -317,6 +347,7 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) } free( s ); } +#endif if( bv.bv_val ) { free( ava->la_value.bv_val ); diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index f4dba0124b..0268322684 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -244,20 +244,21 @@ str2entry( char *s ) nvals[0].bv_val = NULL; if( ad->ad_type->sat_equality && - ad->ad_type->sat_equality->smr_match && - ad->ad_type->sat_syntax->ssyn_normalize ) + ad->ad_type->sat_equality->smr_normalize ) { - rc = ad->ad_type->sat_syntax->ssyn_normalize( + 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[0], &nvals[0] ); if( rc ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, DETAIL1, - "str2entry: NULL (ssyn_normalize %d)\n" , rc, 0, 0 ); + "str2entry: NULL (smr_normalize %d)\n" , rc, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, - "<= str2entry NULL (ssyn_normalize %d)\n", rc, 0, 0 ); + "<= str2entry NULL (smr_normalize %d)\n", rc, 0, 0 ); #endif entry_free( e ); @@ -683,24 +684,25 @@ int entry_decode(struct berval *bv, Entry **e) #ifdef SLAP_NVALUES if( count && ad->ad_type->sat_equality && - ad->ad_type->sat_equality->smr_match && - ad->ad_type->sat_syntax->ssyn_normalize ) + ad->ad_type->sat_equality->smr_normalize ) { a->a_nvals = ch_malloc((count+1)*sizeof(struct berval)); for(j=0; jad_type->sat_syntax->ssyn_normalize( + rc = ad->ad_type->sat_equality->smr_normalize( + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, ad->ad_type->sat_syntax, + ad->ad_type->sat_equality, &a->a_vals[j], &a->a_nvals[j] ); if( rc ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, DETAIL1, - "entry_decode: NULL (ssyn_normalize %d)\n", + "entry_decode: NULL (smr_normalize %d)\n", rc, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, - "<= entry_decode NULL (ssyn_normalize %d)\n", + "<= entry_decode NULL (smr_normalize %d)\n", rc, 0, 0 ); #endif diff --git a/servers/slapd/filter.c b/servers/slapd/filter.c index 45a8d190e9..137102b940 100644 --- a/servers/slapd/filter.c +++ b/servers/slapd/filter.c @@ -414,6 +414,15 @@ get_substring_filter( goto return_error; } +#ifdef SLAP_NVALUES + /* validate using equality matching rule validator! */ + rc = asserted_value_validate_normalize( + f->f_sub_desc, f->f_sub_desc->ad_type->sat_substr, + usage, &value, &bv, text ); + if( rc != LDAP_SUCCESS ) { + goto return_error; + } +#else /* validate using equality matching rule validator! */ rc = value_validate( f->f_sub_desc->ad_type->sat_equality, &value, text ); @@ -426,6 +435,7 @@ get_substring_filter( if( rc != LDAP_SUCCESS ) { goto return_error; } +#endif value = bv; @@ -1423,6 +1433,15 @@ get_substring_vrFilter( goto return_error; } +#ifdef SLAP_NVALUES + /* validate using equality matching rule validator! */ + rc = asserted_value_validate_normalize( + vrf->vrf_sub_desc, vrf->vrf_sub_desc->ad_type->sat_substr, + usage, &value, &bv, text ); + if( rc != LDAP_SUCCESS ) { + goto return_error; + } +#else /* valiate using equality matching rule validator! */ rc = value_validate( vrf->vrf_sub_desc->ad_type->sat_equality, &value, text ); @@ -1435,6 +1454,7 @@ get_substring_vrFilter( if( rc != LDAP_SUCCESS ) { goto return_error; } +#endif value = bv; diff --git a/servers/slapd/filterentry.c b/servers/slapd/filterentry.c index f01e7a822b..f137556461 100644 --- a/servers/slapd/filterentry.c +++ b/servers/slapd/filterentry.c @@ -237,8 +237,7 @@ static int test_mra_filter( int rc; const char *text; - rc = value_match( &ret, a->a_desc, mra->ma_rule, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, bv, &mra->ma_value, &text ); if( rc != LDAP_SUCCESS ) { @@ -266,9 +265,15 @@ static int test_mra_filter( } /* normalize for equality */ +#ifdef SLAP_NVALUES + rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule, + SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, + &mra->ma_value, &value, &text ); +#else rc = value_validate_normalize( a->a_desc, SLAP_MR_EQUALITY, &mra->ma_value, &value, &text ); +#endif if ( rc != LDAP_SUCCESS ) { continue; } @@ -284,8 +289,7 @@ static int test_mra_filter( int ret; int rc; - rc = value_match( &ret, a->a_desc, mra->ma_rule, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, bv, &value, &text ); if( rc != LDAP_SUCCESS ) { @@ -341,8 +345,15 @@ static int test_mra_filter( } /* normalize for equality */ +#ifdef SLAP_NVALUES + rc = asserted_value_validate_normalize( ad, + mra->ma_rule, + SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, + &mra->ma_value, &value, &text ); +#else rc = value_validate_normalize( ad, SLAP_MR_EQUALITY, &mra->ma_value, &value, &text ); +#endif if ( rc != LDAP_SUCCESS ) { continue; } @@ -355,8 +366,7 @@ static int test_mra_filter( } /* check match */ - rc = value_match( &ret, ad, mra->ma_rule, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + rc = value_match( &ret, ad, mra->ma_rule, 0, bv, &value, &text ); if( rc != LDAP_SUCCESS ) { @@ -429,8 +439,7 @@ test_ava_filter( int rc; const char *text; - rc = value_match( &ret, a->a_desc, mr, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + rc = value_match( &ret, a->a_desc, mr, 0, bv, &ava->aa_value, &text ); if( rc != LDAP_SUCCESS ) { @@ -661,8 +670,7 @@ test_substrings_filter( int rc; const char *text; - rc = value_match( &ret, a->a_desc, mr, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + rc = value_match( &ret, a->a_desc, mr, 0, bv, f->f_sub, &text ); if( rc != LDAP_SUCCESS ) { diff --git a/servers/slapd/matchedValues.c b/servers/slapd/matchedValues.c index ca028564fe..17fe275a52 100644 --- a/servers/slapd/matchedValues.c +++ b/servers/slapd/matchedValues.c @@ -240,8 +240,8 @@ test_ava_vrFilter( int rc; const char *text; - rc = value_match( &ret, a->a_desc, mr, - SLAP_MR_ASSERTION_SYNTAX_MATCH, bv, &ava->aa_value, &text ); + rc = value_match( &ret, a->a_desc, mr, 0, + bv, &ava->aa_value, &text ); if( rc != LDAP_SUCCESS ) { return rc; } @@ -326,8 +326,7 @@ test_substrings_vrFilter( int rc; const char *text; - rc = value_match( &ret, a->a_desc, mr, - SLAP_MR_ASSERTION_SYNTAX_MATCH, + rc = value_match( &ret, a->a_desc, mr, 0, bv, vrf->vrf_sub, &text ); if( rc != LDAP_SUCCESS ) { @@ -365,6 +364,7 @@ test_mra_vrFilter( value = mra->ma_value; } else { + int rc; const char *text = NULL; /* check if matching is appropriate */ @@ -373,14 +373,19 @@ test_mra_vrFilter( continue; } +#ifdef SLAP_NVALUES + rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule, + SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, + &mra->ma_value, &value, &text ); +#else /* normalize for equality */ - if ( value_validate_normalize( a->a_desc, + rc = value_validate_normalize( a->a_desc, SLAP_MR_EQUALITY, &mra->ma_value, &value, - &text ) != LDAP_SUCCESS ) { - continue; - } + &text ); +#endif + if( rc != LDAP_SUCCESS ) continue; } for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) { @@ -388,11 +393,8 @@ test_mra_vrFilter( int rc; const char *text; - rc = value_match( &ret, a->a_desc, mra->ma_rule, - SLAP_MR_ASSERTION_SYNTAX_MATCH, - bv, &value, - &text ); - + rc = value_match( &ret, a->a_desc, mra->ma_rule, 0, + bv, &value, &text ); if( rc != LDAP_SUCCESS ) { return rc; } diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 94d642c2b5..a24e250abb 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -609,13 +609,14 @@ int slap_mods_check( #ifdef SLAP_NVALUES if( nvals && ad->ad_type->sat_equality && - ad->ad_type->sat_equality->smr_match && - ad->ad_type->sat_syntax->ssyn_normalize ) + ad->ad_type->sat_equality->smr_normalize ) { ml->sml_nvalues = ch_malloc( (nvals+1)*sizeof(struct berval) ); for( nvals = 0; ml->sml_values[nvals].bv_val; nvals++ ) { - rc = ad->ad_type->sat_syntax->ssyn_normalize( + rc = ad->ad_type->sat_equality->smr_normalize( + 0, ad->ad_type->sat_syntax, + ad->ad_type->sat_equality, &ml->sml_values[nvals], &ml->sml_nvalues[nvals] ); if( rc ) { #ifdef NEW_LOGGING diff --git a/servers/slapd/mods.c b/servers/slapd/mods.c index d83ed68b71..21dc31669d 100644 --- a/servers/slapd/mods.c +++ b/servers/slapd/mods.c @@ -30,6 +30,9 @@ modify_check_duplicates( { int i, j, numvals = 0, nummods, rc = LDAP_SUCCESS, matched; +#ifdef SLAP_NVALUES + /* needs major reworking */ +#else BerVarray nvals = NULL, nmods = NULL; /* @@ -121,23 +124,24 @@ modify_check_duplicates( goto return_results; } - for ( i = 0; mods[ i ].bv_val != NULL; i++ ) { + for ( i=0; mods[i].bv_val != NULL; i++ ) { rc = value_normalize( ad, SLAP_MR_EQUALITY, - &mods[ i ], &nmods[ i ], text ); + &mods[i], &nmods[i], text ); if ( rc != LDAP_SUCCESS ) { - nmods[ i ].bv_val = NULL; + nmods[i].bv_val = NULL; goto return_results; } if ( numvals > 0 && numvals < nummods ) { - for ( matched = 0, j = 0; nvals[ j ].bv_val; j++ ) { + for ( matched=0, j=0; nvals[j].bv_val; j++ ) { int match; rc = (*mr->smr_match)( &match, SLAP_MR_ATTRIBUTE_SYNTAX_MATCH, ad->ad_type->sat_syntax, mr, &nmods[ i ], &nvals[ j ] ); + if ( rc != LDAP_SUCCESS ) { nmods[ i + 1 ].bv_val = NULL; *text = textbuf; @@ -270,6 +274,7 @@ return_results:; ber_bvarray_free( nmods ); } +#endif return rc; } @@ -324,8 +329,7 @@ modify_add_values( /* test asserted values against existing values */ if( a ) { for( matched = 0, j = 0; a->a_vals[j].bv_val != NULL; j++ ) { - if ( bvmatch( &mod->sm_bvalues[i], - &a->a_vals[j] ) ) { + if ( bvmatch( &mod->sm_bvalues[i], &a->a_vals[j] ) ) { if ( permissive ) { matched++; continue; @@ -389,24 +393,49 @@ modify_add_values( int rc; - if ( mod->sm_bvalues[ 1 ].bv_val == 0 ) { + if ( mod->sm_bvalues[1].bv_val == 0 ) { if ( a != NULL ) { struct berval asserted; int i; +#ifndef SLAP_NVALUES rc = value_normalize( mod->sm_desc, SLAP_MR_EQUALITY, &mod->sm_bvalues[ 0 ], &asserted, text ); - if ( rc != LDAP_SUCCESS ) { return rc; } +#endif for ( matched = 0, i = 0; a->a_vals[ i ].bv_val; i++ ) { int match; +#ifdef SLAP_NVALUES + if( mod->sm_nvalues ) { + rc = value_match( &match, mod->sm_desc, mr, + SLAP_MR_EQUALITY + | SLAP_MR_VALUE_OF_ASSERTION_SYNTAX + | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH + | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, + &a->a_nvals[i], + &mod->sm_nvalues[0], + text ); + + } else { + rc = value_match( &match, mod->sm_desc, mr, + SLAP_MR_EQUALITY + | SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + &a->a_vals[i], + &mod->sm_values[0], + text ); + } + +#else rc = value_match( &match, mod->sm_desc, mr, SLAP_MR_ATTRIBUTE_SYNTAX_MATCH, - &a->a_vals[ i ], &asserted, text ); + &a->a_vals[i], + &asserted, + text ); +#endif if( rc == LDAP_SUCCESS && match == 0 ) { if ( permissive ) { @@ -519,6 +548,9 @@ modify_delete_values( return LDAP_NO_SUCH_ATTRIBUTE; } +#ifdef SLAP_NVALUES + nvals = a->a_nvals; +#else /* find each value to delete */ for ( j = 0; a->a_vals[ j ].bv_val != NULL; j++ ) /* count existing values */ ; @@ -545,10 +577,12 @@ modify_delete_values( goto return_results; } } +#endif for ( i = 0; mod->sm_bvalues[ i ].bv_val != NULL; i++ ) { - struct berval asserted; int found = 0; +#ifndef SLAP_NVALUES + struct berval asserted; /* normalize the value to be deleted */ rc = value_normalize( mod->sm_desc, SLAP_MR_EQUALITY, @@ -557,6 +591,7 @@ modify_delete_values( if( rc != LDAP_SUCCESS ) { goto return_results; } +#endif /* search it */ for ( j = 0; nvals[ j ].bv_val != NULL; j++ ) { @@ -566,13 +601,34 @@ modify_delete_values( continue; } +#ifdef SLAP_NVALUES + if( mod->sm_nvalues ) { + rc = (*mr->smr_match)( &match, + SLAP_MR_VALUE_OF_ASSERTION_SYNTAX + | SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH + | SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH, + a->a_desc->ad_type->sat_syntax, + mr, &nvals[ j ], + &mod->sm_nvalues[i] ); + } else { + rc = (*mr->smr_match)( &match, + SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX, + a->a_desc->ad_type->sat_syntax, + mr, &nvals[ j ], + &mod->sm_values[i] ); + } +#else rc = (*mr->smr_match)( &match, SLAP_MR_ATTRIBUTE_SYNTAX_MATCH, a->a_desc->ad_type->sat_syntax, - mr, &nvals[ j ], &asserted ); + mr, &nvals[ j ], + &asserted ); +#endif if ( rc != LDAP_SUCCESS ) { +#ifndef SLAP_NVALUES free( asserted.bv_val ); +#endif *text = textbuf; snprintf( textbuf, textlen, "%s: matching rule failed", @@ -593,7 +649,9 @@ modify_delete_values( break; } +#ifndef SLAP_NVALUES free( asserted.bv_val ); +#endif if ( found == 0 ) { *text = textbuf; diff --git a/servers/slapd/mra.c b/servers/slapd/mra.c index 79c35c4674..a8f2d7fcfd 100644 --- a/servers/slapd/mra.c +++ b/servers/slapd/mra.c @@ -218,6 +218,7 @@ get_mra( return LDAP_INAPPROPRIATE_MATCHING; } +#ifndef SLAP_NVALUES /* * OK, if no matching rule, normalize for equality, otherwise * normalize for the matching rule. @@ -232,8 +233,21 @@ get_mra( if ( rc == LDAP_SUCCESS ) { ber_dupbv( &ma->ma_value, &value ); } +#endif + } +#ifdef SLAP_NVALUES + /* + * Normalize per matching rule + */ + rc = asserted_value_validate_normalize( ma->ma_desc, + ma->ma_rule, + SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, + &ma->ma_value, &value, text ); + if ( rc == LDAP_SUCCESS ) { + ber_dupbv( &ma->ma_value, &value ); } +#endif if( rc != LDAP_SUCCESS ) { mra_free( ma, 1 ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index c85866f60c..6a1ff16cae 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -88,6 +88,10 @@ LDAP_SLAPD_F (int) an_find LDAP_P(( AttributeName *a, struct berval *s )); LDAP_SLAPD_F (int) ad_define_option LDAP_P(( const char *name, const char *fname, int lineno )); +LDAP_SLAPD_F (MatchingRule *) ad_mr( + AttributeDescription *ad, + unsigned usage ); + /* * add.c */ @@ -1065,6 +1069,15 @@ LDAP_SLAPD_F (void) slap_init_user LDAP_P(( char *username, char *groupname )); /* * value.c */ +#ifdef SLAP_NVALUES +LDAP_SLAPD_F (int) asserted_value_validate_normalize LDAP_P(( + AttributeDescription *ad, + MatchingRule *mr, + unsigned usage, + struct berval *in, + struct berval *out, + const char ** text )); +#else LDAP_SLAPD_F (int) value_validate LDAP_P(( MatchingRule *mr, struct berval *in, @@ -1081,6 +1094,9 @@ LDAP_SLAPD_F (int) value_validate_normalize LDAP_P(( struct berval *in, struct berval *out, const char ** text )); +#define value_find(ad,values,value) (value_find_ex((ad),0,(values),(value))) +#endif + LDAP_SLAPD_F (int) value_match LDAP_P(( int *match, AttributeDescription *ad, @@ -1089,12 +1105,12 @@ LDAP_SLAPD_F (int) value_match LDAP_P(( struct berval *v1, void *v2, const char ** text )); -#define value_find(ad,values,value) (value_find_ex((ad),0,(values),(value))) LDAP_SLAPD_F (int) value_find_ex LDAP_P(( AttributeDescription *ad, unsigned flags, BerVarray values, struct berval *value )); + LDAP_SLAPD_F (int) value_add LDAP_P(( BerVarray *vals, BerVarray addvals )); diff --git a/servers/slapd/schema_check.c b/servers/slapd/schema_check.c index 6125db6811..3aca7b68b4 100644 --- a/servers/slapd/schema_check.c +++ b/servers/slapd/schema_check.c @@ -224,7 +224,7 @@ entry_schema_check( /* naming check */ rc = entry_naming_check( e, text, textbuf, textlen ); - if ( rc != LDAP_SUCCESS ) { + if( rc != LDAP_SUCCESS ) { return rc; } @@ -849,7 +849,15 @@ entry_naming_check( break; } - if ( value_find( desc, attr->a_vals, &ava->la_value ) != 0 ) { +#ifdef SLAP_NVALUES + if ( value_find_ex( desc, + SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH. + attr->a_nvals ? attr->a_nvals : attr->a_vals, + &ava->la_value ) != 0 ) +#else + if ( value_find( desc, attr->a_vals, &ava->la_value ) != 0 ) +#endif + { snprintf( textbuf, textlen, "value of naming attribute '%s' is not present in entry", ava->la_attr.bv_val ); diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 53cdb6a6f2..1822e719e5 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -28,6 +28,10 @@ #define HASH_Update(c,buf,len) lutil_HASHUpdate(c,buf,len) #define HASH_Final(d,c) lutil_HASHFinal(d,c) +#ifdef SLAP_NVALUES +#define SLAP_MR_DN_FOLD (0) /* TO BE DELETED */ +#endif + /* recycled validatation routines */ #define berValidate blobValidate @@ -2983,11 +2987,13 @@ static int caseIgnoreIA5Indexer( if( rc != LDAP_SUCCESS ) { break; } +#ifndef SLAP_NVALUES } else if ( mr->smr_syntax->ssyn_normalize ) { rc = (mr->smr_syntax->ssyn_normalize)( syntax, &values[i], &value ); if( rc != LDAP_SUCCESS ) { break; } +#endif } else { ber_dupbv( &value, &values[i] ); } diff --git a/servers/slapd/schema_prep.c b/servers/slapd/schema_prep.c index 9b1dbb57e0..4d13356fb0 100644 --- a/servers/slapd/schema_prep.c +++ b/servers/slapd/schema_prep.c @@ -90,11 +90,15 @@ objectSubClassMatch( return SLAPD_COMPARE_UNDEFINED; } +#ifdef SLAP_NVALUES + assert(0 /* FIX ME */); +#else if( SLAP_IS_MR_ATTRIBUTE_SYNTAX_MATCH( flags ) ) { *matchp = ( asserted != oc ); } else { *matchp = !is_object_subclass( asserted, oc ); } +#endif #if OCDEBUG #ifdef NEW_LOGGING diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index bf4ab72477..9dea20e0aa 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -316,7 +316,9 @@ typedef struct slap_syntax { #define SLAP_SYNTAX_HIDE 0x8000U /* hide (do not publish) */ slap_syntax_validate_func *ssyn_validate; +#ifndef SLAP_NVALUES slap_syntax_transform_func *ssyn_normalize; +#endif slap_syntax_transform_func *ssyn_pretty; #ifdef SLAPD_BINARY_CONVERSION @@ -338,7 +340,11 @@ typedef struct slap_syntax_defs_rec { char *sd_desc; int sd_flags; slap_syntax_validate_func *sd_validate; +#ifdef SLAP_NVALUES + slap_syntax_transform_func *sd_normalizeXXX; /* to be deleted */ +#else slap_syntax_transform_func *sd_normalize; +#endif slap_syntax_transform_func *sd_pretty; #ifdef SLAPD_BINARY_CONVERSION slap_syntax_transform_func *sd_ber2str; @@ -410,23 +416,27 @@ typedef struct slap_matching_rule { #define SLAP_MR_HIDE 0x8000U -#define SLAP_MR_TYPE_MASK 0x0F00U -#define SLAP_MR_SUBTYPE_MASK 0x00F0U -#define SLAP_MR_USAGE 0x000FU +#define SLAP_MR_TYPE_MASK 0xF000U +#define SLAP_MR_SUBTYPE_MASK 0x0F00U +#define SLAP_MR_USAGE 0x00FFU #define SLAP_MR_NONE 0x0000U -#define SLAP_MR_EQUALITY 0x0100U -#define SLAP_MR_ORDERING 0x0200U -#define SLAP_MR_SUBSTR 0x0400U -#define SLAP_MR_EXT 0x0800U /* implicitly extensible */ +#define SLAP_MR_EQUALITY 0x1000U +#define SLAP_MR_ORDERING 0x2000U +#define SLAP_MR_SUBSTR 0x4000U +#define SLAP_MR_EXT 0x8000U /* implicitly extensible */ + +#define SLAP_MR_EQUALITY_APPROX ( SLAP_MR_EQUALITY | 0x0100U ) -#define SLAP_MR_EQUALITY_APPROX ( SLAP_MR_EQUALITY | 0x0010U ) -#define SLAP_MR_DN_FOLD 0x0008U +#define SLAP_MR_SUBSTR_INITIAL ( SLAP_MR_SUBSTR | 0x0100U ) +#define SLAP_MR_SUBSTR_ANY ( SLAP_MR_SUBSTR | 0x0200U ) +#define SLAP_MR_SUBSTR_FINAL ( SLAP_MR_SUBSTR | 0x0400U ) -#define SLAP_MR_SUBSTR_INITIAL ( SLAP_MR_SUBSTR | 0x0010U ) -#define SLAP_MR_SUBSTR_ANY ( SLAP_MR_SUBSTR | 0x0020U ) -#define SLAP_MR_SUBSTR_FINAL ( SLAP_MR_SUBSTR | 0x0040U ) +#ifndef SLAP_NVALUES +#define SLAP_MR_DN_FOLD 0x0080U +#endif +#ifndef SLAP_NVALUES /* * normally the asserted value is expected to conform to * assertion syntax specified in the matching rule, however @@ -434,8 +444,8 @@ typedef struct slap_matching_rule { * the asserted value is expected to conform to the * attribute's value syntax. */ -#define SLAP_MR_ASSERTION_SYNTAX_MATCH 0x0000U -#define SLAP_MR_ATTRIBUTE_SYNTAX_MATCH 0x0001U +#define SLAP_MR_ASSERTION_SYNTAX_MATCH 0x0000U +#define SLAP_MR_ATTRIBUTE_SYNTAX_MATCH 0x0001U /* For SLAP_MR_ATTRIBUTE_SYNTAX_MATCHes, this flag indicates * that the asserted value of the attribute syntax has been @@ -444,11 +454,32 @@ typedef struct slap_matching_rule { */ #define SLAP_MR_ATTRIBUTE_SYNTAX_CONVERTED_MATCH 0x0002U +#else +/* + * The asserted value, depending on the particular usage, + * is expected to conform to either the assertion syntax + * or the attribute syntax. In some cases, the syntax of + * the value is known. If so, these flags indicate which + * syntax the value is expected to conform to. If not, + * neither of these flags is set (until the syntax of the + * provided value is determined). If the value is of the + * attribute syntax, the flag is changed once a value of + * the assertion syntax is derived from the provided value. + */ +#define SLAP_MR_VALUE_OF_ASSERTION_SYNTAX 0x0001U +#define SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX 0x0002U + +#define SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX( usage ) \ + ((usage) & SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX ) +#define SLAP_MR_IS_VALUE_OF_ASSERTION_SYNTAX( usage ) \ + ((usage) & SLAP_MR_VALUE_OF_ASSERTION_SYNTAX ) +#endif + /* either or both the asserted value or attribute value * may be provided in normalized form */ -#define SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH 0x0004U -#define SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH 0x0008U +#define SLAP_MR_ASSERTED_VALUE_NORMALIZED_MATCH 0x0010U +#define SLAP_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH 0x0020U #define SLAP_IS_MR_ASSERTION_SYNTAX_MATCH( usage ) \ (!((usage) & SLAP_MR_ATTRIBUTE_SYNTAX_MATCH)) @@ -519,6 +550,7 @@ typedef struct slap_mrule_defs_rec { slap_mr_indexer_func * mrd_indexer; slap_mr_filter_func * mrd_filter; + /* For equality rule, this may refer to an appropriate approximate rule */ char * mrd_associated; } slap_mrule_defs_rec; diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index d808d8126a..f8468a91aa 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -151,7 +151,9 @@ syn_add( ssyn->ssyn_oidlen = strlen(syn->syn_oid); ssyn->ssyn_flags = def->sd_flags; ssyn->ssyn_validate = def->sd_validate; +#ifndef SLAP_NVALUES ssyn->ssyn_normalize = def->sd_normalize; +#endif ssyn->ssyn_pretty = def->sd_pretty; #ifdef SLAPD_BINARY_CONVERSION diff --git a/servers/slapd/value.c b/servers/slapd/value.c index cd6c65c93e..83ec803257 100644 --- a/servers/slapd/value.c +++ b/servers/slapd/value.c @@ -123,6 +123,56 @@ value_add_one( return LDAP_SUCCESS; } +#ifdef SLAP_NVALUES +int asserted_value_validate_normalize( + AttributeDescription *ad, + MatchingRule *mr, + unsigned usage, + struct berval *in, + struct berval *out, + const char ** text ) +{ + int rc; + + /* we expect the value to be in the assertion syntax */ + assert( !SLAP_MR_IS_VALUE_OF_ATTRIBUTE_SYNTAX(usage) ); + + if( mr == NULL ) { + *text = "inappropriate matching request"; + return LDAP_INAPPROPRIATE_MATCHING; + } + + if( !mr->smr_match ) { + *text = "requested matching rule not supported"; + return LDAP_INAPPROPRIATE_MATCHING; + } + + assert( mr->smr_syntax ); + assert( mr->smr_syntax->ssyn_validate ); + + rc = (mr->smr_syntax->ssyn_validate)( mr->smr_syntax, in ); + + if( rc != LDAP_SUCCESS ) { + *text = "value does not conform to assertion syntax"; + return LDAP_INVALID_SYNTAX; + } + + if( mr->smr_normalize ) { + rc = (mr->smr_normalize)( usage, + ad ? ad->ad_type->sat_syntax : NULL, + mr, in, out ); + + if( rc != LDAP_SUCCESS ) { + *text = "unable to normalize value for matching"; + return LDAP_INVALID_SYNTAX; + } + + } else { + ber_dupbv( out, in ); + } +} + +#else int value_validate( MatchingRule *mr, @@ -165,25 +215,7 @@ value_normalize( const char **text ) { int rc; - MatchingRule *mr; - - switch( usage & SLAP_MR_TYPE_MASK ) { - case SLAP_MR_NONE: - case SLAP_MR_EQUALITY: - mr = ad->ad_type->sat_equality; - break; - case SLAP_MR_ORDERING: - mr = ad->ad_type->sat_ordering; - break; - case SLAP_MR_SUBSTR: - mr = ad->ad_type->sat_substr; - break; - case SLAP_MR_EXT: - default: - assert( 0 ); - *text = "internal error"; - return LDAP_OTHER; - } + MatchingRule *mr = ad_mr( ad, usage ); if( mr == NULL ) { *text = "inappropriate matching request"; @@ -233,25 +265,7 @@ value_validate_normalize( const char **text ) { int rc; - MatchingRule *mr; - - switch( usage & SLAP_MR_TYPE_MASK ) { - case SLAP_MR_NONE: - case SLAP_MR_EQUALITY: - mr = ad->ad_type->sat_equality; - break; - case SLAP_MR_ORDERING: - mr = ad->ad_type->sat_ordering; - break; - case SLAP_MR_SUBSTR: - mr = ad->ad_type->sat_substr; - break; - case SLAP_MR_EXT: - default: - assert( 0 ); - *text = "internal error"; - return LDAP_OTHER; - } + MatchingRule *mr = ad_mr( ad, usage ); if( mr == NULL ) { *text = "inappropriate matching request"; @@ -308,6 +322,7 @@ value_validate_normalize( return LDAP_SUCCESS; } +#endif int value_match( @@ -329,6 +344,7 @@ value_match( return LDAP_INAPPROPRIATE_MATCHING; } +#ifndef SLAP_NVALUES if( ad->ad_type->sat_syntax->ssyn_normalize ) { rc = ad->ad_type->sat_syntax->ssyn_normalize( ad->ad_type->sat_syntax, v1, &nv1 ); @@ -349,6 +365,7 @@ value_match( /* let smr_match know we've converted the value */ flags |= SLAP_MR_ATTRIBUTE_SYNTAX_CONVERTED_MATCH; } +#endif rc = (mr->smr_match)( match, flags, ad->ad_type->sat_syntax, @@ -361,7 +378,6 @@ value_match( return rc; } - int value_find_ex( AttributeDescription *ad, unsigned flags, @@ -377,6 +393,23 @@ int value_find_ex( return LDAP_INAPPROPRIATE_MATCHING; } +#ifdef SLAP_NVALUES + assert(SLAP_IS_MR_ATTRIBUTE_VALUE_NORMALIZED_MATCH( flags )); + + 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, + ad ? ad->ad_type->sat_syntax : NULL, + mr, val, &nval ); + + if( rc != LDAP_SUCCESS ) { + return LDAP_INVALID_SYNTAX; + } + } +#else + /* Take care of this here or ssyn_normalize later will hurt */ if ( SLAP_IS_MR_ATTRIBUTE_SYNTAX_NONCONVERTED_MATCH( flags ) && mr->smr_convert ) @@ -406,6 +439,7 @@ int value_find_ex( return LDAP_INAPPROPRIATE_MATCHING; } } +#endif for ( i = 0; vals[i].bv_val != NULL; i++ ) { int match;