2002-05-03 02:56:56 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/*
|
2003-01-04 04:20:47 +08:00
|
|
|
* Copyright 1999-2003 The OpenLDAP Foundation.
|
2002-05-03 02:56:56 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted only
|
|
|
|
* as authorized by the OpenLDAP Public License. A copy of this
|
|
|
|
* license is available at http://www.OpenLDAP.org/license.html or
|
|
|
|
* in file LICENSE in the top-level directory of the distribution.
|
|
|
|
*/
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
|
|
#include "slap.h"
|
|
|
|
|
|
|
|
#include "../../libraries/liblber/lber-int.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,
|
2002-05-03 02:56:56 +08:00
|
|
|
char ***e_flags
|
|
|
|
)
|
|
|
|
{
|
2003-01-21 04:21:17 +08:00
|
|
|
ValuesReturnFilter *vrf;
|
2002-05-03 02:56:56 +08:00
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, ENTRY, "filter_matched_values: begin\n", 0, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "=> filter_matched_values\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
|
2003-01-21 04:21:17 +08:00
|
|
|
for ( vrf = op->vrFilter; vrf != NULL; vrf = vrf->vrf_next ) {
|
|
|
|
switch ( vrf->vrf_choice ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
case SLAPD_FILTER_COMPUTED:
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, DETAIL1,
|
2002-05-03 02:56:56 +08:00
|
|
|
"test_vrFilter: COMPUTED %s (%d)\n",
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
|
|
|
|
vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
|
|
|
|
vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" :
|
|
|
|
"error", vrf->vrf_result, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " COMPUTED %s (%d)\n",
|
2003-01-21 04:21:17 +08:00
|
|
|
vrf->vrf_result == LDAP_COMPARE_FALSE ? "false" :
|
|
|
|
vrf->vrf_result == LDAP_COMPARE_TRUE ? "true" :
|
|
|
|
vrf->vrf_result == SLAPD_COMPARE_UNDEFINED ? "undefined" : "error",
|
|
|
|
vrf->vrf_result, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#endif
|
|
|
|
/*This type of filter does not affect the result */
|
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EQUALITY\n", 0, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " EQUALITY\n", 0, 0, 0 );
|
|
|
|
#endif
|
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 );
|
|
|
|
if( rc == -1 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, DETAIL1, "test_vrFilter SUBSTRINGS\n", 0, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " SUBSTRINGS\n", 0, 0, 0 );
|
|
|
|
#endif
|
|
|
|
|
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 );
|
2002-05-03 02:56:56 +08:00
|
|
|
if( rc == -1 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: PRESENT\n", 0, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " PRESENT\n", 0, 0, 0 );
|
|
|
|
#endif
|
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 );
|
2002-05-03 02:56:56 +08:00
|
|
|
if( rc == -1 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
if( rc == -1 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
if( rc == -1 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_EXT:
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, DETAIL1, "test_vrFilter: EXT\n", 0, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " EXT\n", 0, 0, 0 );
|
|
|
|
#endif
|
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 );
|
2002-05-03 02:56:56 +08:00
|
|
|
if( rc == -1 ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, INFO,
|
2003-01-21 04:21:17 +08:00
|
|
|
"test_vrFilter: unknown filter type %lu\n", vrf->vrf_choice, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
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
|
|
|
#endif
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( FILTER, ENTRY, "filter_matched_values: return=%d\n", rc, 0, 0 );
|
2002-05-03 02:56:56 +08:00
|
|
|
#else
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "<= filter_matched_values %d\n", rc, 0, 0 );
|
|
|
|
#endif
|
|
|
|
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,
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* use EQUALITY matching rule if no APPROX rule */
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mr == NULL ) {
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-03-24 10:03:33 +08:00
|
|
|
bv = a->a_nvals;
|
|
|
|
for ( j=0; bv->bv_val != NULL; bv++, j++ ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
int ret;
|
|
|
|
int rc;
|
|
|
|
const char *text;
|
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
rc = value_match( &ret, a->a_desc, mr, 0,
|
|
|
|
bv, &ava->aa_value, &text );
|
2002-05-03 02:56:56 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( type ) {
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
case LDAP_FILTER_APPROX:
|
|
|
|
if ( ret == 0 ) {
|
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
if ( ret >= 0 ) {
|
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
if ( ret <= 0 ) {
|
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
test_presence_vrFilter(
|
2002-06-04 00:45:09 +08:00
|
|
|
Operation *op,
|
|
|
|
Attribute *a,
|
|
|
|
AttributeDescription *desc,
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ( !is_ad_subtype( a->a_desc, desc ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( bv = a->a_vals, j=0; bv->bv_val != NULL; bv++, j++ );
|
|
|
|
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,
|
2002-06-04 00:45:09 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( mr == NULL ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-03-24 10:03:33 +08:00
|
|
|
bv = a->a_nvals;
|
|
|
|
for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
int ret;
|
|
|
|
int rc;
|
|
|
|
const char *text;
|
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
rc = value_match( &ret, 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
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ret == 0 ) {
|
|
|
|
(*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,
|
|
|
|
char ***e_flags
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2002-06-04 00:45:09 +08:00
|
|
|
for ( i=0; a != NULL; a = a->a_next, i++ ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
struct berval *bv, value;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
value = mra->ma_value;
|
|
|
|
|
|
|
|
} 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 */
|
|
|
|
if ( strcmp( mra->ma_rule->smr_syntax->ssyn_oid,
|
|
|
|
a->a_desc->ad_type->sat_syntax->ssyn_oid ) != 0 ) {
|
|
|
|
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,
|
|
|
|
&mra->ma_value, &value, &text );
|
2002-08-29 18:55:48 +08:00
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) continue;
|
2002-08-29 18:55:48 +08:00
|
|
|
}
|
2002-05-03 02:56:56 +08:00
|
|
|
|
2003-03-24 09:56:56 +08:00
|
|
|
bv = a->a_nvals;
|
|
|
|
for ( j = 0; bv->bv_val != NULL; bv++, j++ ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
int ret;
|
|
|
|
int rc;
|
|
|
|
const char *text;
|
|
|
|
|
2003-02-27 09:54:43 +08:00
|
|
|
rc = value_match( &ret, a->a_desc, mra->ma_rule, 0,
|
|
|
|
bv, &value, &text );
|
2002-05-03 02:56:56 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2002-08-29 18:45:24 +08:00
|
|
|
if ( ret == 0 ) {
|
2002-05-03 02:56:56 +08:00
|
|
|
(*e_flags)[i][j] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
|
|
|
}
|