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>
20 #include "../../libraries/liblber/lber-int.h"
28 MatchingRuleAssertion *mra,
33 test_substrings_vrFilter(
38 ValuesReturnFilter *f,
43 test_presence_vrFilter(
48 AttributeDescription *desc,
58 AttributeAssertion *ava,
65 filter_matched_values(
73 ValuesReturnFilter *vrf;
74 int rc = LDAP_SUCCESS;
77 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
79 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
82 for ( vrf = op->vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
83 switch ( vrf->vrf_choice ) {
84 case SLAPD_FILTER_COMPUTED:
86 LDAP_LOG( FILTER, DETAIL1,
87 "test_vrFilter: COMPUTED %s (%d)\n",
88 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
89 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
90 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
91 "error", vrf->vrf_result, 0 );
93 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
94 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
95 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
96 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
99 /*This type of filter does not affect the result */
103 case LDAP_FILTER_EQUALITY:
105 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
107 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
109 rc = test_ava_vrFilter( be, conn, op, a, vrf->vrf_ava,
110 LDAP_FILTER_EQUALITY, e_flags );
116 case LDAP_FILTER_SUBSTRINGS:
118 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
120 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
123 rc = test_substrings_vrFilter( be, conn, op, a,
130 case LDAP_FILTER_PRESENT:
132 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
134 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
136 rc = test_presence_vrFilter( be, conn, op, a,
137 vrf->vrf_desc, e_flags );
144 rc = test_ava_vrFilter( be, conn, op, a, vrf->vrf_ava,
145 LDAP_FILTER_GE, e_flags );
152 rc = test_ava_vrFilter( be, conn, op, a, vrf->vrf_ava,
153 LDAP_FILTER_LE, e_flags );
159 case LDAP_FILTER_EXT:
161 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
163 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
165 rc = test_mra_vrFilter( be, conn, op, a,
166 vrf->vrf_mra, e_flags );
174 LDAP_LOG( FILTER, INFO,
175 "test_vrFilter: unknown filter type %lu\n", vrf->vrf_choice, 0, 0 );
177 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
178 vrf->vrf_choice, 0, 0 );
180 rc = LDAP_PROTOCOL_ERROR;
185 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
187 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
198 AttributeAssertion *ava,
205 for ( i=0; a != NULL; a = a->a_next, i++ ) {
210 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
215 case LDAP_FILTER_APPROX:
216 mr = a->a_desc->ad_type->sat_approx;
217 if( mr != NULL ) break;
219 /* use EQUALITY matching rule if no APPROX rule */
220 case LDAP_FILTER_EQUALITY:
221 mr = a->a_desc->ad_type->sat_equality;
226 mr = a->a_desc->ad_type->sat_ordering;
238 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ ) {
243 rc = value_match( &ret, a->a_desc, mr, 0,
244 bv, &ava->aa_value, &text );
245 if( rc != LDAP_SUCCESS ) {
250 case LDAP_FILTER_EQUALITY:
251 case LDAP_FILTER_APPROX:
253 (*e_flags)[i][j] = 1;
259 (*e_flags)[i][j] = 1;
265 (*e_flags)[i][j] = 1;
271 return( LDAP_SUCCESS );
275 test_presence_vrFilter(
280 AttributeDescription *desc,
286 for ( i=0; a != NULL; a = a->a_next, i++ ) {
289 if ( !is_ad_subtype( a->a_desc, desc ) ) {
293 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
294 memset( (*e_flags)[i], 1, j);
297 return( LDAP_SUCCESS );
301 test_substrings_vrFilter(
306 ValuesReturnFilter *vrf,
312 for ( i=0; a != NULL; a = a->a_next, i++ ) {
313 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
316 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
324 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
329 rc = value_match( &ret, a->a_desc, mr, 0,
330 bv, vrf->vrf_sub, &text );
332 if( rc != LDAP_SUCCESS ) {
337 (*e_flags)[i][j] = 1;
351 MatchingRuleAssertion *mra,
357 for ( i=0; a != NULL; a = a->a_next, i++ ) {
358 struct berval *bv, value;
360 if ( mra->ma_desc ) {
361 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
364 value = mra->ma_value;
368 const char *text = NULL;
370 /* check if matching is appropriate */
371 if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
372 a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
377 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
378 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
379 &mra->ma_value, &value, &text );
381 /* normalize for equality */
382 rc = value_validate_normalize( a->a_desc,
384 &mra->ma_value, &value,
388 if( rc != LDAP_SUCCESS ) continue;
391 for ( bv = a->a_vals, j = 0; bv->bv_val != NULL; bv++, j++ ) {
396 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
398 if( rc != LDAP_SUCCESS ) {
403 (*e_flags)[i][j] = 1;