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;
209 /* 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;
224 if( mr == NULL ) continue;
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, op->o_tmpmemctx );
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;