3 * Copyright 1999-2003 The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
15 #include <ac/string.h>
16 #include <ac/socket.h>
24 MatchingRuleAssertion *mra,
29 test_substrings_vrFilter(
32 ValuesReturnFilter *f,
37 test_presence_vrFilter(
40 AttributeDescription *desc,
48 AttributeAssertion *ava,
55 filter_matched_values(
61 ValuesReturnFilter *vrf;
62 int rc = LDAP_SUCCESS;
65 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
67 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
70 for ( vrf = op->o_vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
71 switch ( vrf->vrf_choice ) {
72 case SLAPD_FILTER_COMPUTED:
74 LDAP_LOG( FILTER, DETAIL1,
75 "test_vrFilter: COMPUTED %s (%d)\n",
76 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
77 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
78 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
79 "error", vrf->vrf_result, 0 );
81 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
82 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
83 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
84 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
87 /*This type of filter does not affect the result */
91 case LDAP_FILTER_EQUALITY:
93 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
95 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
97 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
98 LDAP_FILTER_EQUALITY, e_flags );
104 case LDAP_FILTER_SUBSTRINGS:
106 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
108 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
111 rc = test_substrings_vrFilter( op, a,
118 case LDAP_FILTER_PRESENT:
120 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
122 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
124 rc = test_presence_vrFilter( op, a,
125 vrf->vrf_desc, e_flags );
132 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
133 LDAP_FILTER_GE, e_flags );
140 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
141 LDAP_FILTER_LE, e_flags );
147 case LDAP_FILTER_EXT:
149 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
151 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
153 rc = test_mra_vrFilter( op, a,
154 vrf->vrf_mra, e_flags );
162 LDAP_LOG( FILTER, INFO,
163 "test_vrFilter: unknown filter type %lu\n", vrf->vrf_choice, 0, 0 );
165 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
166 vrf->vrf_choice, 0, 0 );
168 rc = LDAP_PROTOCOL_ERROR;
173 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
175 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
184 AttributeAssertion *ava,
191 for ( i=0; a != NULL; a = a->a_next, i++ ) {
196 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
201 case LDAP_FILTER_APPROX:
202 mr = a->a_desc->ad_type->sat_approx;
203 if( mr != NULL ) break;
205 /* use EQUALITY matching rule if no APPROX rule */
206 case LDAP_FILTER_EQUALITY:
207 mr = a->a_desc->ad_type->sat_equality;
212 mr = a->a_desc->ad_type->sat_ordering;
225 for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
230 rc = value_match( &ret, a->a_desc, mr, 0,
231 bv, &ava->aa_value, &text );
232 if( rc != LDAP_SUCCESS ) {
237 case LDAP_FILTER_EQUALITY:
238 case LDAP_FILTER_APPROX:
240 (*e_flags)[i][j] = 1;
246 (*e_flags)[i][j] = 1;
252 (*e_flags)[i][j] = 1;
258 return( LDAP_SUCCESS );
262 test_presence_vrFilter(
265 AttributeDescription *desc,
271 for ( i=0; a != NULL; a = a->a_next, i++ ) {
274 if ( !is_ad_subtype( a->a_desc, desc ) ) {
278 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
279 memset( (*e_flags)[i], 1, j);
282 return( LDAP_SUCCESS );
286 test_substrings_vrFilter(
289 ValuesReturnFilter *vrf,
295 for ( i=0; a != NULL; a = a->a_next, i++ ) {
296 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
299 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
308 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
313 rc = value_match( &ret, a->a_desc, mr, 0,
314 bv, vrf->vrf_sub, &text );
316 if( rc != LDAP_SUCCESS ) {
321 (*e_flags)[i][j] = 1;
333 MatchingRuleAssertion *mra,
339 for ( i=0; a != NULL; a = a->a_next, i++ ) {
340 struct berval *bv, value;
342 if ( mra->ma_desc ) {
343 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
346 value = mra->ma_value;
350 const char *text = NULL;
352 /* check if matching is appropriate */
353 if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
354 a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
358 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
359 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
360 &mra->ma_value, &value, &text, op->o_tmpmemctx );
362 if( rc != LDAP_SUCCESS ) continue;
366 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
371 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
373 if( rc != LDAP_SUCCESS ) {
378 (*e_flags)[i][j] = 1;