2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2004 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
21 #include <ac/socket.h>
29 MatchingRuleAssertion *mra,
34 test_substrings_vrFilter(
37 ValuesReturnFilter *f,
42 test_presence_vrFilter(
45 AttributeDescription *desc,
53 AttributeAssertion *ava,
60 filter_matched_values(
66 ValuesReturnFilter *vrf;
67 int rc = LDAP_SUCCESS;
70 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
72 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
75 for ( vrf = op->o_vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
76 switch ( vrf->vrf_choice ) {
77 case SLAPD_FILTER_COMPUTED:
79 LDAP_LOG( FILTER, DETAIL1,
80 "test_vrFilter: COMPUTED %s (%d)\n",
81 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
82 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
83 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
84 "error", vrf->vrf_result, 0 );
86 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
87 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
88 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
89 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
92 /*This type of filter does not affect the result */
96 case LDAP_FILTER_EQUALITY:
98 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
100 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
102 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
103 LDAP_FILTER_EQUALITY, e_flags );
109 case LDAP_FILTER_SUBSTRINGS:
111 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
113 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
116 rc = test_substrings_vrFilter( op, a,
123 case LDAP_FILTER_PRESENT:
125 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
127 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
129 rc = test_presence_vrFilter( op, a,
130 vrf->vrf_desc, e_flags );
137 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
138 LDAP_FILTER_GE, e_flags );
145 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
146 LDAP_FILTER_LE, e_flags );
152 case LDAP_FILTER_EXT:
154 LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
156 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
158 rc = test_mra_vrFilter( op, a,
159 vrf->vrf_mra, e_flags );
167 LDAP_LOG( FILTER, INFO,
168 "test_vrFilter: unknown filter type %lu\n", vrf->vrf_choice, 0, 0 );
170 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
171 vrf->vrf_choice, 0, 0 );
173 rc = LDAP_PROTOCOL_ERROR;
178 LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
180 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
189 AttributeAssertion *ava,
196 for ( i=0; a != NULL; a = a->a_next, i++ ) {
201 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
206 case LDAP_FILTER_APPROX:
207 mr = a->a_desc->ad_type->sat_approx;
208 if( mr != NULL ) break;
210 /* use EQUALITY matching rule if no APPROX rule */
211 case LDAP_FILTER_EQUALITY:
212 mr = a->a_desc->ad_type->sat_equality;
217 mr = a->a_desc->ad_type->sat_ordering;
230 for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
235 rc = value_match( &ret, a->a_desc, mr, 0,
236 bv, &ava->aa_value, &text );
237 if( rc != LDAP_SUCCESS ) {
242 case LDAP_FILTER_EQUALITY:
243 case LDAP_FILTER_APPROX:
245 (*e_flags)[i][j] = 1;
251 (*e_flags)[i][j] = 1;
257 (*e_flags)[i][j] = 1;
263 return( LDAP_SUCCESS );
267 test_presence_vrFilter(
270 AttributeDescription *desc,
276 for ( i=0; a != NULL; a = a->a_next, i++ ) {
279 if ( !is_ad_subtype( a->a_desc, desc ) ) {
283 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
284 memset( (*e_flags)[i], 1, j);
287 return( LDAP_SUCCESS );
291 test_substrings_vrFilter(
294 ValuesReturnFilter *vrf,
300 for ( i=0; a != NULL; a = a->a_next, i++ ) {
301 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
304 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
313 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
318 rc = value_match( &ret, a->a_desc, mr, 0,
319 bv, vrf->vrf_sub, &text );
321 if( rc != LDAP_SUCCESS ) {
326 (*e_flags)[i][j] = 1;
338 MatchingRuleAssertion *mra,
344 for ( i=0; a != NULL; a = a->a_next, i++ ) {
345 struct berval *bv, value;
347 if ( mra->ma_desc ) {
348 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
351 value = mra->ma_value;
355 const char *text = NULL;
357 /* check if matching is appropriate */
358 if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
359 a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
363 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
364 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
365 &mra->ma_value, &value, &text, op->o_tmpmemctx );
367 if( rc != LDAP_SUCCESS ) continue;
371 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
376 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
378 if( rc != LDAP_SUCCESS ) {
383 (*e_flags)[i][j] = 1;