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;
69 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
71 for ( vrf = op->o_vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
72 switch ( vrf->vrf_choice ) {
73 case SLAPD_FILTER_COMPUTED:
74 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
75 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
76 vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
77 vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
79 /*This type of filter does not affect the result */
83 case LDAP_FILTER_EQUALITY:
84 Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
85 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
86 LDAP_FILTER_EQUALITY, e_flags );
92 case LDAP_FILTER_SUBSTRINGS:
93 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
95 rc = test_substrings_vrFilter( op, a,
102 case LDAP_FILTER_PRESENT:
103 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
104 rc = test_presence_vrFilter( op, a,
105 vrf->vrf_desc, e_flags );
112 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
113 LDAP_FILTER_GE, e_flags );
120 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
121 LDAP_FILTER_LE, e_flags );
127 case LDAP_FILTER_EXT:
128 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
129 rc = test_mra_vrFilter( op, a,
130 vrf->vrf_mra, e_flags );
137 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
138 vrf->vrf_choice, 0, 0 );
139 rc = LDAP_PROTOCOL_ERROR;
143 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
151 AttributeAssertion *ava,
158 for ( i=0; a != NULL; a = a->a_next, i++ ) {
163 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
168 case LDAP_FILTER_APPROX:
169 mr = a->a_desc->ad_type->sat_approx;
170 if( mr != NULL ) break;
171 /* use EQUALITY matching rule if no APPROX rule */
173 case LDAP_FILTER_EQUALITY:
174 mr = a->a_desc->ad_type->sat_equality;
179 mr = a->a_desc->ad_type->sat_ordering;
186 if( mr == NULL ) continue;
189 for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
194 rc = value_match( &ret, a->a_desc, mr, 0,
195 bv, &ava->aa_value, &text );
196 if( rc != LDAP_SUCCESS ) {
201 case LDAP_FILTER_EQUALITY:
202 case LDAP_FILTER_APPROX:
204 (*e_flags)[i][j] = 1;
210 (*e_flags)[i][j] = 1;
216 (*e_flags)[i][j] = 1;
222 return( LDAP_SUCCESS );
226 test_presence_vrFilter(
229 AttributeDescription *desc,
235 for ( i=0; a != NULL; a = a->a_next, i++ ) {
238 if ( !is_ad_subtype( a->a_desc, desc ) ) {
242 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
243 memset( (*e_flags)[i], 1, j);
246 return( LDAP_SUCCESS );
250 test_substrings_vrFilter(
253 ValuesReturnFilter *vrf,
259 for ( i=0; a != NULL; a = a->a_next, i++ ) {
260 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
263 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
272 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
277 rc = value_match( &ret, a->a_desc, mr, 0,
278 bv, vrf->vrf_sub, &text );
280 if( rc != LDAP_SUCCESS ) {
285 (*e_flags)[i][j] = 1;
297 MatchingRuleAssertion *mra,
303 for ( i=0; a != NULL; a = a->a_next, i++ ) {
304 struct berval *bv, assertedValue;
306 if ( mra->ma_desc ) {
307 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
310 assertedValue = mra->ma_value;
314 const char *text = NULL;
316 /* check if matching is appropriate */
317 if ( !mr_usable_with_at( mra->ma_rule, a->a_desc->ad_type ) ) {
321 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
322 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
323 &mra->ma_value, &assertedValue, &text, op->o_tmpmemctx );
325 if( rc != LDAP_SUCCESS ) continue;
329 if (mra->ma_rule == a->a_desc->ad_type->sat_equality) {
335 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
340 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
341 bv, &assertedValue, &text );
342 if( rc != LDAP_SUCCESS ) {
347 (*e_flags)[i][j] = 1;