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(
65 ValuesReturnFilter *vrf;
66 int rc = LDAP_SUCCESS;
68 Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
70 for ( vrf = op->o_vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
71 switch ( vrf->vrf_choice ) {
72 case SLAPD_FILTER_COMPUTED:
73 Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
74 vrf->vrf_result == LDAP_COMPARE_FALSE ? "false"
75 : vrf->vrf_result == LDAP_COMPARE_TRUE ? "true"
76 : vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined"
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 );
87 if( rc == -1 ) return rc;
90 case LDAP_FILTER_SUBSTRINGS:
91 Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
92 rc = test_substrings_vrFilter( op, a,
94 if( rc == -1 ) return rc;
97 case LDAP_FILTER_PRESENT:
98 Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
99 rc = test_presence_vrFilter( op, a,
100 vrf->vrf_desc, e_flags );
101 if( rc == -1 ) return rc;
105 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
106 LDAP_FILTER_GE, e_flags );
107 if( rc == -1 ) return rc;
111 rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
112 LDAP_FILTER_LE, e_flags );
113 if( rc == -1 ) return rc;
116 case LDAP_FILTER_EXT:
117 Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
118 rc = test_mra_vrFilter( op, a,
119 vrf->vrf_mra, e_flags );
120 if( rc == -1 ) return rc;
124 Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
125 vrf->vrf_choice, 0, 0 );
126 rc = LDAP_PROTOCOL_ERROR;
130 Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
138 AttributeAssertion *ava,
144 for ( i=0; a != NULL; a = a->a_next, i++ ) {
148 if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
153 case LDAP_FILTER_APPROX:
154 mr = a->a_desc->ad_type->sat_approx;
155 if( mr != NULL ) break;
156 /* use EQUALITY matching rule if no APPROX rule */
158 case LDAP_FILTER_EQUALITY:
159 mr = a->a_desc->ad_type->sat_equality;
164 mr = a->a_desc->ad_type->sat_ordering;
171 if( mr == NULL ) continue;
174 for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
179 rc = value_match( &ret, a->a_desc, mr, 0,
180 bv, &ava->aa_value, &text );
181 if( rc != LDAP_SUCCESS ) return rc;
184 case LDAP_FILTER_EQUALITY:
185 case LDAP_FILTER_APPROX:
187 (*e_flags)[i][j] = 1;
193 (*e_flags)[i][j] = 1;
199 (*e_flags)[i][j] = 1;
205 return( LDAP_SUCCESS );
209 test_presence_vrFilter(
212 AttributeDescription *desc,
217 for ( i=0; a != NULL; a = a->a_next, i++ ) {
220 if ( !is_ad_subtype( a->a_desc, desc ) ) continue;
222 for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
223 memset( (*e_flags)[i], 1, j);
226 return( LDAP_SUCCESS );
230 test_substrings_vrFilter(
233 ValuesReturnFilter *vrf,
238 for ( i=0; a != NULL; a = a->a_next, i++ ) {
239 MatchingRule *mr = a->a_desc->ad_type->sat_substr;
242 if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
246 if( mr == NULL ) continue;
249 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
254 rc = value_match( &ret, a->a_desc, mr, 0,
255 bv, vrf->vrf_sub, &text );
257 if( rc != LDAP_SUCCESS ) {
262 (*e_flags)[i][j] = 1;
274 MatchingRuleAssertion *mra,
279 for ( i=0; a != NULL; a = a->a_next, i++ ) {
280 struct berval *bv, assertedValue;
282 if ( mra->ma_desc ) {
283 if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
286 assertedValue = mra->ma_value;
290 const char *text = NULL;
292 /* check if matching is appropriate */
293 if ( !mr_usable_with_at( mra->ma_rule, a->a_desc->ad_type ) ) {
297 rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
298 SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
299 &mra->ma_value, &assertedValue, &text, op->o_tmpmemctx );
301 if( rc != LDAP_SUCCESS ) continue;
305 if (mra->ma_rule == a->a_desc->ad_type->sat_equality) {
311 for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
316 rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
317 bv, &assertedValue, &text );
318 if( rc != LDAP_SUCCESS ) return rc;
321 (*e_flags)[i][j] = 1;