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"
26 MatchingRuleAssertion *mra,
31 test_substrings_vrFilter(
34 ValuesReturnFilter *f,
39 test_presence_vrFilter(
42 AttributeDescription *desc,
50 AttributeAssertion *ava,
57 filter_matched_values(
63 ValuesReturnFilter *vrf;
64 int rc = LDAP_SUCCESS;
67 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
69 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
72 for ( vrf = op->vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
73 switch ( vrf->vrf_choice ) {
74 case SLAPD_FILTER_COMPUTED:
76 LDAP_LOG( FILTER, DETAIL1,
77 "test_vrFilter: COMPUTED %s (%d)\n",
78 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
79 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
80 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
81 "error", vrf->vrf_result, 0 );
83 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
84 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
85 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
86 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
89 /*This type of filter does not affect the result */
93 case LDAP_FILTER_EQUALITY:
95 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
97 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
99 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
100 LDAP_FILTER_EQUALITY, e_flags );
106 case LDAP_FILTER_SUBSTRINGS:
108 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
110 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
113 rc = test_substrings_vrFilter( op, a,
120 case LDAP_FILTER_PRESENT:
122 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
124 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
126 rc = test_presence_vrFilter( op, a,
127 vrf->vrf_desc, e_flags );
134 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
135 LDAP_FILTER_GE, e_flags );
142 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
143 LDAP_FILTER_LE, e_flags );
149 case LDAP_FILTER_EXT:
151 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
153 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
155 rc = test_mra_vrFilter( op, a,
156 vrf->vrf_mra, e_flags );
164 LDAP_LOG( FILTER, INFO,
165 "test_vrFilter: unknown filter type %lu\n", vrf->vrf_choice, 0, 0 );
167 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
168 vrf->vrf_choice, 0, 0 );
170 rc = LDAP_PROTOCOL_ERROR;
175 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
177 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
186 AttributeAssertion *ava,
193 for ( i=0; a != NULL; a = a->a_next, i++ ) {
198 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
203 case LDAP_FILTER_APPROX:
204 mr = a->a_desc->ad_type->sat_approx;
205 if( mr != NULL ) break;
207 /* use EQUALITY matching rule if no APPROX rule */
208 case LDAP_FILTER_EQUALITY:
209 mr = a->a_desc->ad_type->sat_equality;
214 mr = a->a_desc->ad_type->sat_ordering;
231 for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
236 rc = value_match( &ret, a->a_desc, mr, 0,
237 bv, &ava->aa_value, &text );
238 if( rc != LDAP_SUCCESS ) {
243 case LDAP_FILTER_EQUALITY:
244 case LDAP_FILTER_APPROX:
246 (*e_flags)[i][j] = 1;
252 (*e_flags)[i][j] = 1;
258 (*e_flags)[i][j] = 1;
264 return( LDAP_SUCCESS );
268 test_presence_vrFilter(
271 AttributeDescription *desc,
277 for ( i=0; a != NULL; a = a->a_next, i++ ) {
280 if ( !is_ad_subtype( a->a_desc, desc ) ) {
284 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
285 memset( (*e_flags)[i], 1, j);
288 return( LDAP_SUCCESS );
292 test_substrings_vrFilter(
295 ValuesReturnFilter *vrf,
301 for ( i=0; a != NULL; a = a->a_next, i++ ) {
302 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
305 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
318 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
323 rc = value_match( &ret, a->a_desc, mr, 0,
324 bv, vrf->vrf_sub, &text );
326 if( rc != LDAP_SUCCESS ) {
331 (*e_flags)[i][j] = 1;
343 MatchingRuleAssertion *mra,
349 for ( i=0; a != NULL; a = a->a_next, i++ ) {
350 struct berval *bv, value;
352 if ( mra->ma_desc ) {
353 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
356 value = mra->ma_value;
360 const char *text = NULL;
362 /* check if matching is appropriate */
363 if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
364 a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
369 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
370 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
371 &mra->ma_value, &value, &text );
373 /* normalize for equality */
374 rc = value_validate_normalize( a->a_desc,
376 &mra->ma_value, &value,
380 if( rc != LDAP_SUCCESS ) continue;
388 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
393 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
395 if( rc != LDAP_SUCCESS ) {
400 (*e_flags)[i][j] = 1;