2002-05-03 02:56:56 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-27 09:17:14 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2010-04-14 06:17:29 +08:00
|
|
|
* Copyright 1999-2010 The OpenLDAP Foundation.
|
2002-05-03 02:56:56 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2003-11-27 09:17:14 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2002-05-03 02:56:56 +08:00
|
|
|
*/
|
2003-11-27 09:17:14 +08:00
|
|
|
|
2002-05-03 02:56:56 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
static int
|
|
|
|
test_mra_vrFilter(
|
2002-05-03 02:56:56 +08:00
|
|
|
Operation *op,
|
2002-06-04 00:45:09 +08:00
|
|
|
Attribute *a,
|
2002-05-03 02:56:56 +08:00
|
|
|
MatchingRuleAssertion *mra,
|
|
|
|
char ***e_flags
|
|
|
|
);
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_substrings_vrFilter(
|
|
|
|
Operation *op,
|
2002-06-04 00:45:09 +08:00
|
|
|
Attribute *a,
|
2002-05-03 02:56:56 +08:00
|
|
|
ValuesReturnFilter *f,
|
|
|
|
char ***e_flags
|
|
|
|
);
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_presence_vrFilter(
|
|
|
|
Operation *op,
|
2002-06-04 00:45:09 +08:00
|
|
|
Attribute *a,
|
2002-05-03 02:56:56 +08:00
|
|
|
AttributeDescription *desc,
|
|
|
|
char ***e_flags
|
|
|
|
);
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_ava_vrFilter(
|
|
|
|
Operation *op,
|
2002-06-04 00:45:09 +08:00
|
|
|
Attribute *a,
|
2002-05-03 02:56:56 +08:00
|
|
|
AttributeAssertion *ava,
|
|
|
|
int type,
|
|
|
|
char ***e_flags
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
filter_matched_values(
|
|
|
|
Operation *op,
|
2002-06-04 00:45:09 +08:00
|
|
|
Attribute *a,
|
2004-09-18 09:19:07 +08:00
|
|
|
char ***e_flags )
|
2002-05-03 02:56:56 +08:00
|
|
|
{
|
2003-01-21 04:21:17 +08:00
|
|
|
ValuesReturnFilter *vrf;
|
2002-05-03 02:56:56 +08:00
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
|
|
|
|
|
2003-06-10 11:32:33 +08:00
|
|
|
for ( vrf = op->o_vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
|
2003-01-21 04:21:17 +08:00
|
|
|
switch ( vrf->vrf_choice ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
case SLAPD_FILTER_COMPUTED:
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
|
2004-09-18 09:19:07 +08:00
|
|
|
vrf->vrf_result == LDAP_COMPARE_FALSE ? "false"
|
|
|
|
: vrf->vrf_result == LDAP_COMPARE_TRUE ? "true"
|
|
|
|
: vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined"
|
|
|
|
: "error",
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf->vrf_result, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
/*This type of filter does not affect the result */
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
|
2002-05-03 02:56:56 +08:00
|
|
|
LDAP_FILTER_EQUALITY, e_flags );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc == -1 ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_substrings_vrFilter( op, a,
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf, e_flags );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc == -1 ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_presence_vrFilter( op, a,
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf->vrf_desc, e_flags );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc == -1 ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
|
2002-05-03 02:56:56 +08:00
|
|
|
LDAP_FILTER_GE, e_flags );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc == -1 ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_ava_vrFilter( op, a, vrf->vrf_ava,
|
2002-05-03 02:56:56 +08:00
|
|
|
LDAP_FILTER_LE, e_flags );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc == -1 ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_EXT:
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
|
2003-03-30 17:03:54 +08:00
|
|
|
rc = test_mra_vrFilter( op, a,
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf->vrf_mra, e_flags );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc == -1 ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug( LDAP_DEBUG_ANY, " unknown filter type %lu\n",
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf->vrf_choice, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
2004-09-18 09:19:07 +08:00
|
|
|
}
|
2002-05-03 02:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_ava_vrFilter(
|
2002-06-04 00:45:09 +08:00
|
|
|
Operation *op,
|
|
|
|
Attribute *a,
|
2002-05-03 02:56:56 +08:00
|
|
|
AttributeAssertion *ava,
|
2002-06-04 00:45:09 +08:00
|
|
|
int type,
|
2004-09-18 09:19:07 +08:00
|
|
|
char ***e_flags )
|
2002-05-03 02:56:56 +08:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2002-06-04 00:45:09 +08:00
|
|
|
for ( i=0; a != NULL; a = a->a_next, i++ ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
MatchingRule *mr;
|
|
|
|
struct berval *bv;
|
|
|
|
|
|
|
|
if ( !is_ad_subtype( a->a_desc, ava->aa_desc ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( type ) {
|
|
|
|
case LDAP_FILTER_APPROX:
|
|
|
|
mr = a->a_desc->ad_type->sat_approx;
|
|
|
|
if( mr != NULL ) break;
|
2004-04-10 05:30:55 +08:00
|
|
|
/* use EQUALITY matching rule if no APPROX rule */
|
2002-05-03 02:56:56 +08:00
|
|
|
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
mr = a->a_desc->ad_type->sat_equality;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
mr = a->a_desc->ad_type->sat_ordering;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
mr = NULL;
|
|
|
|
}
|
|
|
|
|
2004-04-10 05:30:55 +08:00
|
|
|
if( mr == NULL ) continue;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2003-03-24 10:03:33 +08:00
|
|
|
bv = a->a_nvals;
|
2005-01-27 05:48:36 +08:00
|
|
|
for ( j=0; !BER_BVISNULL( bv ); bv++, j++ ) {
|
2004-09-18 14:04:57 +08:00
|
|
|
int rc, match;
|
2002-05-03 02:56:56 +08:00
|
|
|
const char *text;
|
|
|
|
|
2004-09-18 14:04:57 +08:00
|
|
|
rc = value_match( &match, a->a_desc, mr, 0,
|
2003-02-27 09:54:43 +08:00
|
|
|
bv, &ava->aa_value, &text );
|
2004-09-18 09:19:07 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
|
|
|
switch ( type ) {
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
case LDAP_FILTER_APPROX:
|
2004-09-18 14:04:57 +08:00
|
|
|
if ( match == 0 ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
2004-09-18 14:04:57 +08:00
|
|
|
if ( match >= 0 ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
2004-09-18 14:04:57 +08:00
|
|
|
if ( match <= 0 ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-18 14:04:57 +08:00
|
|
|
return LDAP_SUCCESS;
|
2002-05-03 02:56:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_presence_vrFilter(
|
2002-06-04 00:45:09 +08:00
|
|
|
Operation *op,
|
|
|
|
Attribute *a,
|
|
|
|
AttributeDescription *desc,
|
2004-09-18 09:19:07 +08:00
|
|
|
char ***e_flags )
|
2002-05-03 02:56:56 +08:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2002-06-04 00:45:09 +08:00
|
|
|
for ( i=0; a != NULL; a = a->a_next, i++ ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
struct berval *bv;
|
|
|
|
|
2004-09-18 09:19:07 +08:00
|
|
|
if ( !is_ad_subtype( a->a_desc, desc ) ) continue;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2005-01-27 05:48:36 +08:00
|
|
|
for ( bv = a->a_vals, j = 0; !BER_BVISNULL( bv ); bv++, j++ );
|
2002-05-03 02:56:56 +08:00
|
|
|
memset( (*e_flags)[i], 1, j);
|
|
|
|
}
|
|
|
|
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_substrings_vrFilter(
|
2002-06-04 00:45:09 +08:00
|
|
|
Operation *op,
|
|
|
|
Attribute *a,
|
2003-01-21 04:21:17 +08:00
|
|
|
ValuesReturnFilter *vrf,
|
2004-09-18 09:19:07 +08:00
|
|
|
char ***e_flags )
|
2002-05-03 02:56:56 +08:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2002-06-04 00:45:09 +08:00
|
|
|
for ( i=0; a != NULL; a = a->a_next, i++ ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
MatchingRule *mr = a->a_desc->ad_type->sat_substr;
|
|
|
|
struct berval *bv;
|
|
|
|
|
2003-01-21 04:21:17 +08:00
|
|
|
if ( !is_ad_subtype( a->a_desc, vrf->vrf_sub_desc ) ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-09-18 09:19:07 +08:00
|
|
|
if( mr == NULL ) continue;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2003-03-24 10:03:33 +08:00
|
|
|
bv = a->a_nvals;
|
2005-01-27 05:48:36 +08:00
|
|
|
for ( j = 0; !BER_BVISNULL( bv ); bv++, j++ ) {
|
2004-09-18 14:04:57 +08:00
|
|
|
int rc, match;
|
2002-05-03 02:56:56 +08:00
|
|
|
const char *text;
|
|
|
|
|
2004-09-18 14:04:57 +08:00
|
|
|
rc = value_match( &match, a->a_desc, mr, 0,
|
2003-01-21 04:21:17 +08:00
|
|
|
bv, vrf->vrf_sub, &text );
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2004-09-18 14:04:57 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2004-09-18 14:04:57 +08:00
|
|
|
if ( match == 0 ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
static int
|
|
|
|
test_mra_vrFilter(
|
2002-05-03 02:56:56 +08:00
|
|
|
Operation *op,
|
2002-06-04 00:45:09 +08:00
|
|
|
Attribute *a,
|
2002-05-03 02:56:56 +08:00
|
|
|
MatchingRuleAssertion *mra,
|
2004-09-18 09:19:07 +08:00
|
|
|
char ***e_flags )
|
2002-05-03 02:56:56 +08:00
|
|
|
{
|
2005-01-27 05:48:36 +08:00
|
|
|
int i, j;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2005-01-27 05:48:36 +08:00
|
|
|
for ( i = 0; a != NULL; a = a->a_next, i++ ) {
|
|
|
|
struct berval *bv, assertedValue;
|
|
|
|
int normalize_attribute = 0;
|
2002-08-29 18:55:48 +08:00
|
|
|
|
|
|
|
if ( mra->ma_desc ) {
|
|
|
|
if ( !is_ad_subtype( a->a_desc, mra->ma_desc ) ) {
|
2002-08-31 18:29:03 +08:00
|
|
|
continue;
|
2002-08-29 18:55:48 +08:00
|
|
|
}
|
2004-07-03 19:17:11 +08:00
|
|
|
assertedValue = mra->ma_value;
|
2002-08-29 18:55:48 +08:00
|
|
|
|
|
|
|
} else {
|
2003-02-27 09:54:43 +08:00
|
|
|
int rc;
|
2002-08-29 18:55:48 +08:00
|
|
|
const char *text = NULL;
|
|
|
|
|
|
|
|
/* check if matching is appropriate */
|
2004-07-03 19:17:11 +08:00
|
|
|
if ( !mr_usable_with_at( mra->ma_rule, a->a_desc->ad_type ) ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
rc = asserted_value_validate_normalize( a->a_desc, mra->ma_rule,
|
|
|
|
SLAP_MR_EXT|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
|
2004-07-03 19:17:11 +08:00
|
|
|
&mra->ma_value, &assertedValue, &text, op->o_tmpmemctx );
|
2002-08-29 18:55:48 +08:00
|
|
|
|
2005-01-27 05:48:36 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) continue;
|
2002-08-29 18:55:48 +08:00
|
|
|
}
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2004-07-03 19:17:11 +08:00
|
|
|
/* check match */
|
2005-01-27 05:48:36 +08:00
|
|
|
if ( mra->ma_rule == a->a_desc->ad_type->sat_equality ) {
|
2004-07-03 19:17:11 +08:00
|
|
|
bv = a->a_nvals;
|
2005-01-27 05:48:36 +08:00
|
|
|
|
2004-07-03 19:17:11 +08:00
|
|
|
} else {
|
|
|
|
bv = a->a_vals;
|
2005-01-27 05:48:36 +08:00
|
|
|
normalize_attribute = 1;
|
2004-07-03 19:17:11 +08:00
|
|
|
}
|
|
|
|
|
2005-01-27 05:48:36 +08:00
|
|
|
for ( j = 0; !BER_BVISNULL( bv ); bv++, j++ ) {
|
|
|
|
int rc, match;
|
|
|
|
const char *text;
|
|
|
|
struct berval nbv = BER_BVNULL;
|
|
|
|
|
|
|
|
if ( normalize_attribute && mra->ma_rule->smr_normalize ) {
|
|
|
|
/* see comment in filterentry.c */
|
|
|
|
if ( mra->ma_rule->smr_normalize(
|
|
|
|
SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
|
|
|
|
mra->ma_rule->smr_syntax,
|
|
|
|
mra->ma_rule,
|
|
|
|
bv, &nbv, op->o_tmpmemctx ) != LDAP_SUCCESS )
|
|
|
|
{
|
|
|
|
/* FIXME: stop processing? */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
nbv = *bv;
|
|
|
|
}
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2004-09-18 14:04:57 +08:00
|
|
|
rc = value_match( &match, a->a_desc, mra->ma_rule, 0,
|
2005-01-27 05:48:36 +08:00
|
|
|
&nbv, &assertedValue, &text );
|
|
|
|
|
|
|
|
if ( nbv.bv_val != bv->bv_val ) {
|
|
|
|
op->o_tmpfree( nbv.bv_val, op->o_tmpmemctx );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) return rc;
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2004-09-18 14:04:57 +08:00
|
|
|
if ( match == 0 ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|
2004-07-03 19:17:11 +08:00
|
|
|
|