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;
227 for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
232 rc = value_match( &ret, a->a_desc, mr, 0,
233 bv, &ava->aa_value, &text );
234 if( rc != LDAP_SUCCESS ) {
239 case LDAP_FILTER_EQUALITY:
240 case LDAP_FILTER_APPROX:
242 (*e_flags)[i][j] = 1;
248 (*e_flags)[i][j] = 1;
254 (*e_flags)[i][j] = 1;
260 return( LDAP_SUCCESS );
264 test_presence_vrFilter(
267 AttributeDescription *desc,
273 for ( i=0; a != NULL; a = a->a_next, i++ ) {
276 if ( !is_ad_subtype( a->a_desc, desc ) ) {
280 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
281 memset( (*e_flags)[i], 1, j);
284 return( LDAP_SUCCESS );
288 test_substrings_vrFilter(
291 ValuesReturnFilter *vrf,
297 for ( i=0; a != NULL; a = a->a_next, i++ ) {
298 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
301 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
310 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
315 rc = value_match( &ret, a->a_desc, mr, 0,
316 bv, vrf->vrf_sub, &text );
318 if( rc != LDAP_SUCCESS ) {
323 (*e_flags)[i][j] = 1;
335 MatchingRuleAssertion *mra,
341 for ( i=0; a != NULL; a = a->a_next, i++ ) {
342 struct berval *bv, value;
344 if ( mra->ma_desc ) {
345 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
348 value = mra->ma_value;
352 const char *text = NULL;
354 /* check if matching is appropriate */
355 if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
356 a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
360 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
361 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
362 &mra->ma_value, &value, &text );
364 if( rc != LDAP_SUCCESS ) continue;
368 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
373 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
375 if( rc != LDAP_SUCCESS ) {
380 (*e_flags)[i][j] = 1;