1998-08-08 20:43:13 -04:00
|
|
|
/* filter.c - routines for parsing and dealing with filters */
|
1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 20:17:14 -05:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
|
*
|
2011-01-04 19:42:37 -05:00
|
|
|
* Copyright 1998-2011 The OpenLDAP Foundation.
|
2003-11-26 20:17:14 -05:00
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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>.
|
|
|
|
|
*/
|
|
|
|
|
/* Portions Copyright (c) 1995 Regents of the University of Michigan.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
1999-08-06 19:07:46 -04:00
|
|
|
*/
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1998-10-24 21:41:42 -04:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <stdio.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include "slap.h"
|
2007-10-05 04:24:36 -04:00
|
|
|
#include "lutil.h"
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2007-09-15 13:38:53 -04:00
|
|
|
const Filter *slap_filter_objectClass_pres;
|
|
|
|
|
const struct berval *slap_filterstr_objectClass_pres;
|
|
|
|
|
|
2000-03-01 17:59:34 -05:00
|
|
|
static int get_filter_list(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2000-03-01 17:59:34 -05:00
|
|
|
BerElement *ber,
|
|
|
|
|
Filter **f,
|
2000-05-21 23:46:57 -04:00
|
|
|
const char **text );
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
static int get_ssa(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2000-03-01 17:59:34 -05:00
|
|
|
BerElement *ber,
|
2006-12-25 18:30:45 -05:00
|
|
|
Filter *f,
|
2000-05-21 23:46:57 -04:00
|
|
|
const char **text );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2002-05-02 14:56:56 -04:00
|
|
|
static void simple_vrFilter2bv(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2002-05-02 14:56:56 -04:00
|
|
|
ValuesReturnFilter *f,
|
|
|
|
|
struct berval *fstr );
|
|
|
|
|
|
|
|
|
|
static int get_simple_vrFilter(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2002-05-02 14:56:56 -04:00
|
|
|
BerElement *ber,
|
|
|
|
|
ValuesReturnFilter **f,
|
|
|
|
|
const char **text );
|
|
|
|
|
|
2007-09-15 13:38:53 -04:00
|
|
|
int
|
|
|
|
|
filter_init( void )
|
|
|
|
|
{
|
|
|
|
|
static Filter filter_objectClass_pres = { LDAP_FILTER_PRESENT };
|
|
|
|
|
static struct berval filterstr_objectClass_pres = BER_BVC("(objectClass=*)");
|
|
|
|
|
|
|
|
|
|
filter_objectClass_pres.f_desc = slap_schema.si_ad_objectClass;
|
|
|
|
|
|
|
|
|
|
slap_filter_objectClass_pres = &filter_objectClass_pres;
|
|
|
|
|
slap_filterstr_objectClass_pres = &filterstr_objectClass_pres;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
filter_destroy( void )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
int
|
2000-03-01 17:59:34 -05:00
|
|
|
get_filter(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2000-03-01 17:59:34 -05:00
|
|
|
BerElement *ber,
|
|
|
|
|
Filter **filt,
|
2000-05-21 23:46:57 -04:00
|
|
|
const char **text )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
2000-02-29 18:48:01 -05:00
|
|
|
ber_tag_t tag;
|
1999-08-02 01:29:35 -04:00
|
|
|
ber_len_t len;
|
1998-08-08 20:43:13 -04:00
|
|
|
int err;
|
2003-03-16 16:50:39 -05:00
|
|
|
Filter f;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_filter\n", 0, 0, 0 );
|
|
|
|
|
/*
|
|
|
|
|
* A filter looks like this coming in:
|
|
|
|
|
* Filter ::= CHOICE {
|
|
|
|
|
* and [0] SET OF Filter,
|
|
|
|
|
* or [1] SET OF Filter,
|
|
|
|
|
* not [2] Filter,
|
|
|
|
|
* equalityMatch [3] AttributeValueAssertion,
|
|
|
|
|
* substrings [4] SubstringFilter,
|
|
|
|
|
* greaterOrEqual [5] AttributeValueAssertion,
|
|
|
|
|
* lessOrEqual [6] AttributeValueAssertion,
|
2006-12-25 18:30:45 -05:00
|
|
|
* present [7] AttributeType,
|
|
|
|
|
* approxMatch [8] AttributeValueAssertion,
|
2002-08-31 06:41:49 -04:00
|
|
|
* extensibleMatch [9] MatchingRuleAssertion
|
1998-08-08 20:43:13 -04:00
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* SubstringFilter ::= SEQUENCE {
|
2001-01-17 11:35:53 -05:00
|
|
|
* type AttributeType,
|
1998-08-08 20:43:13 -04:00
|
|
|
* SEQUENCE OF CHOICE {
|
2001-01-17 11:35:53 -05:00
|
|
|
* initial [0] IA5String,
|
|
|
|
|
* any [1] IA5String,
|
|
|
|
|
* final [2] IA5String
|
1998-08-08 20:43:13 -04:00
|
|
|
* }
|
|
|
|
|
* }
|
1999-07-07 14:51:39 -04:00
|
|
|
*
|
2002-03-06 22:13:11 -05:00
|
|
|
* MatchingRuleAssertion ::= SEQUENCE {
|
|
|
|
|
* matchingRule [1] MatchingRuleId OPTIONAL,
|
|
|
|
|
* type [2] AttributeDescription OPTIONAL,
|
|
|
|
|
* matchValue [3] AssertionValue,
|
|
|
|
|
* dnAttributes [4] BOOLEAN DEFAULT FALSE
|
1999-07-07 14:51:39 -04:00
|
|
|
* }
|
|
|
|
|
*
|
1998-08-08 20:43:13 -04:00
|
|
|
*/
|
|
|
|
|
|
2000-02-29 18:48:01 -05:00
|
|
|
tag = ber_peek_tag( ber, &len );
|
|
|
|
|
|
|
|
|
|
if( tag == LBER_ERROR ) {
|
2000-03-01 17:59:34 -05:00
|
|
|
*text = "error decoding filter";
|
2000-02-29 18:48:01 -05:00
|
|
|
return SLAPD_DISCONNECT;
|
|
|
|
|
}
|
|
|
|
|
|
1999-07-07 14:51:39 -04:00
|
|
|
err = LDAP_SUCCESS;
|
1999-06-28 20:03:34 -04:00
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
f.f_next = NULL;
|
|
|
|
|
f.f_choice = tag;
|
|
|
|
|
|
|
|
|
|
switch ( f.f_choice ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "EQUALITY\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, &f, SLAP_MR_EQUALITY, text );
|
2000-05-17 16:08:13 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
2000-03-01 17:59:34 -05:00
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2000-05-15 14:46:03 -04:00
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
assert( f.f_ava != NULL );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "SUBSTRINGS\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ssa( op, ber, &f, text );
|
2003-03-15 14:45:36 -05:00
|
|
|
if( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
assert( f.f_sub != NULL );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "GE\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, &f, SLAP_MR_ORDERING, text );
|
2000-05-17 16:08:13 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
2000-03-01 17:59:34 -05:00
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
assert( f.f_ava != NULL );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "LE\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, &f, SLAP_MR_ORDERING, text );
|
2000-05-17 16:08:13 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
2000-05-15 14:46:03 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
assert( f.f_ava != NULL );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
2000-05-15 14:46:03 -04:00
|
|
|
case LDAP_FILTER_PRESENT: {
|
|
|
|
|
struct berval type;
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
Debug( LDAP_DEBUG_FILTER, "PRESENT\n", 0, 0, 0 );
|
2002-01-06 01:11:01 -05:00
|
|
|
if ( ber_scanf( ber, "m", &type ) == LBER_ERROR ) {
|
2000-02-29 18:48:01 -05:00
|
|
|
err = SLAPD_DISCONNECT;
|
2000-03-01 17:59:34 -05:00
|
|
|
*text = "error decoding filter";
|
2000-02-29 18:48:01 -05:00
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2000-02-29 18:48:01 -05:00
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
f.f_desc = NULL;
|
|
|
|
|
err = slap_bv2ad( &type, &f.f_desc, text );
|
2000-05-15 14:46:03 -04:00
|
|
|
|
2000-05-16 17:54:24 -04:00
|
|
|
if( err != LDAP_SUCCESS ) {
|
2006-12-25 18:30:45 -05:00
|
|
|
f.f_choice |= SLAPD_FILTER_UNDEFINED;
|
2006-12-25 23:51:08 -05:00
|
|
|
err = slap_bv2undef_ad( &type, &f.f_desc, text,
|
|
|
|
|
SLAP_AD_PROXIED|SLAP_AD_NOINSERT );
|
|
|
|
|
|
2005-08-25 17:14:26 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
/* unrecognized attribute description or other error */
|
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
|
"get_filter: conn %lu unknown attribute "
|
|
|
|
|
"type=%s (%d)\n",
|
|
|
|
|
op->o_connid, type.bv_val, err );
|
|
|
|
|
|
|
|
|
|
err = LDAP_SUCCESS;
|
2006-12-25 23:51:08 -05:00
|
|
|
f.f_desc = slap_bv2tmp_ad( &type, op->o_tmpmemctx );
|
2005-08-25 17:14:26 -04:00
|
|
|
}
|
2006-12-25 18:30:45 -05:00
|
|
|
*text = NULL;
|
2000-05-15 14:46:03 -04:00
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
|
|
|
|
|
assert( f.f_desc != NULL );
|
2000-05-15 14:46:03 -04:00
|
|
|
} break;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "APPROX\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, &f, SLAP_MR_EQUALITY_APPROX, text );
|
2000-05-17 16:08:13 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
2000-05-15 14:46:03 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
assert( f.f_ava != NULL );
|
2000-05-15 14:46:03 -04:00
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
case LDAP_FILTER_AND:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "AND\n", 0, 0, 0 );
|
2003-04-09 12:52:03 -04:00
|
|
|
err = get_filter_list( op, ber, &f.f_and, text );
|
2000-03-01 17:59:34 -05:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2003-04-29 01:58:28 -04:00
|
|
|
if ( f.f_and == NULL ) {
|
|
|
|
|
f.f_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
f.f_result = LDAP_COMPARE_TRUE;
|
|
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
/* no assert - list could be empty */
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_OR:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "OR\n", 0, 0, 0 );
|
2003-04-09 12:52:03 -04:00
|
|
|
err = get_filter_list( op, ber, &f.f_or, text );
|
2000-03-01 17:59:34 -05:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2003-04-29 01:58:28 -04:00
|
|
|
if ( f.f_or == NULL ) {
|
|
|
|
|
f.f_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
f.f_result = LDAP_COMPARE_FALSE;
|
|
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
/* no assert - list could be empty */
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_NOT:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "NOT\n", 0, 0, 0 );
|
|
|
|
|
(void) ber_skip_tag( ber, &len );
|
2003-04-09 12:52:03 -04:00
|
|
|
err = get_filter( op, ber, &f.f_not, text );
|
2000-03-01 17:59:34 -05:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
|
|
|
|
|
assert( f.f_not != NULL );
|
2003-04-29 01:58:28 -04:00
|
|
|
if ( f.f_not->f_choice == SLAPD_FILTER_COMPUTED ) {
|
2003-04-29 16:40:26 -04:00
|
|
|
int fresult = f.f_not->f_result;
|
2003-04-29 14:13:10 -04:00
|
|
|
f.f_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
op->o_tmpfree( f.f_not, op->o_tmpmemctx );
|
|
|
|
|
f.f_not = NULL;
|
|
|
|
|
|
2003-04-29 16:40:26 -04:00
|
|
|
switch( fresult ) {
|
2003-04-29 14:13:10 -04:00
|
|
|
case LDAP_COMPARE_TRUE:
|
2003-04-29 01:58:28 -04:00
|
|
|
f.f_result = LDAP_COMPARE_FALSE;
|
2003-04-29 14:13:10 -04:00
|
|
|
break;
|
|
|
|
|
case LDAP_COMPARE_FALSE:
|
2003-04-29 01:58:28 -04:00
|
|
|
f.f_result = LDAP_COMPARE_TRUE;
|
2003-04-29 14:13:10 -04:00
|
|
|
break;
|
2003-04-29 16:12:00 -04:00
|
|
|
default: ;
|
2003-04-29 14:13:10 -04:00
|
|
|
/* (!Undefined) is Undefined */
|
2003-04-29 01:58:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
2000-02-06 16:09:44 -05:00
|
|
|
case LDAP_FILTER_EXT:
|
2000-10-13 16:39:36 -04:00
|
|
|
Debug( LDAP_DEBUG_FILTER, "EXTENSIBLE\n", 0, 0, 0 );
|
|
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_mra( op, ber, &f, text );
|
2000-10-13 16:39:36 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
assert( f.f_mra != NULL );
|
1999-07-07 14:51:39 -04:00
|
|
|
break;
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
default:
|
2001-06-15 22:20:48 -04:00
|
|
|
(void) ber_scanf( ber, "x" ); /* skip the element */
|
2000-05-15 14:46:03 -04:00
|
|
|
Debug( LDAP_DEBUG_ANY, "get_filter: unknown filter type=%lu\n",
|
2003-03-16 16:50:39 -05:00
|
|
|
f.f_choice, 0, 0 );
|
|
|
|
|
f.f_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
f.f_result = SLAPD_COMPARE_UNDEFINED;
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
if( err != LDAP_SUCCESS && err != SLAPD_DISCONNECT ) {
|
|
|
|
|
/* ignore error */
|
2003-04-18 00:44:06 -04:00
|
|
|
*text = NULL;
|
2003-03-16 16:50:39 -05:00
|
|
|
f.f_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
f.f_result = SLAPD_COMPARE_UNDEFINED;
|
|
|
|
|
err = LDAP_SUCCESS;
|
|
|
|
|
}
|
2002-03-10 12:41:14 -05:00
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
if ( err == LDAP_SUCCESS ) {
|
2003-04-09 12:52:03 -04:00
|
|
|
*filt = op->o_tmpalloc( sizeof(f), op->o_tmpmemctx );
|
2003-03-16 16:50:39 -05:00
|
|
|
**filt = f;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "end get_filter %d\n", err, 0, 0 );
|
2003-03-16 16:50:39 -05:00
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
return( err );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2003-04-09 12:52:03 -04:00
|
|
|
get_filter_list( Operation *op, BerElement *ber,
|
2002-03-06 22:13:11 -05:00
|
|
|
Filter **f,
|
2000-05-21 23:46:57 -04:00
|
|
|
const char **text )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
Filter **new;
|
|
|
|
|
int err;
|
1999-06-18 19:53:05 -04:00
|
|
|
ber_tag_t tag;
|
|
|
|
|
ber_len_t len;
|
2001-12-26 08:47:10 -05:00
|
|
|
char *last;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_filter_list\n", 0, 0, 0 );
|
|
|
|
|
new = f;
|
2003-03-16 01:41:53 -05:00
|
|
|
for ( tag = ber_first_element( ber, &len, &last );
|
|
|
|
|
tag != LBER_DEFAULT;
|
2002-03-06 22:13:11 -05:00
|
|
|
tag = ber_next_element( ber, &len, last ) )
|
1999-07-07 14:51:39 -04:00
|
|
|
{
|
2003-04-09 12:52:03 -04:00
|
|
|
err = get_filter( op, ber, new, text );
|
2000-03-01 17:59:34 -05:00
|
|
|
if ( err != LDAP_SUCCESS )
|
1998-08-08 20:43:13 -04:00
|
|
|
return( err );
|
|
|
|
|
new = &(*new)->f_next;
|
|
|
|
|
}
|
|
|
|
|
*new = NULL;
|
|
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "end get_filter_list\n", 0, 0, 0 );
|
1999-07-07 14:51:39 -04:00
|
|
|
return( LDAP_SUCCESS );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2003-03-17 01:06:02 -05:00
|
|
|
get_ssa(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2002-03-06 22:13:11 -05:00
|
|
|
BerElement *ber,
|
2006-12-25 18:30:45 -05:00
|
|
|
Filter *f,
|
2002-03-06 22:13:11 -05:00
|
|
|
const char **text )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
1999-06-18 19:53:05 -04:00
|
|
|
ber_tag_t tag;
|
|
|
|
|
ber_len_t len;
|
2009-08-04 18:41:59 -04:00
|
|
|
int rc;
|
2003-03-16 16:50:39 -05:00
|
|
|
struct berval desc, value, nvalue;
|
2000-01-25 16:13:31 -05:00
|
|
|
char *last;
|
2003-03-16 16:50:39 -05:00
|
|
|
SubstringsAssertion ssa;
|
2003-03-16 14:09:07 -05:00
|
|
|
|
2000-03-01 17:59:34 -05:00
|
|
|
*text = "error decoding filter";
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_ssa\n", 0, 0, 0 );
|
2003-03-16 16:50:39 -05:00
|
|
|
if ( ber_scanf( ber, "{m" /*}*/, &desc ) == LBER_ERROR ) {
|
2000-02-29 18:48:01 -05:00
|
|
|
return SLAPD_DISCONNECT;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2000-01-25 16:13:31 -05:00
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
*text = NULL;
|
|
|
|
|
|
|
|
|
|
ssa.sa_desc = NULL;
|
|
|
|
|
ssa.sa_initial.bv_val = NULL;
|
|
|
|
|
ssa.sa_any = NULL;
|
|
|
|
|
ssa.sa_final.bv_val = NULL;
|
|
|
|
|
|
|
|
|
|
rc = slap_bv2ad( &desc, &ssa.sa_desc, text );
|
2000-05-16 12:22:52 -04:00
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
2006-12-25 18:30:45 -05:00
|
|
|
f->f_choice |= SLAPD_FILTER_UNDEFINED;
|
2006-12-25 23:51:08 -05:00
|
|
|
rc = slap_bv2undef_ad( &desc, &ssa.sa_desc, text,
|
|
|
|
|
SLAP_AD_PROXIED|SLAP_AD_NOINSERT );
|
|
|
|
|
|
2005-08-25 17:14:26 -04:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
|
"get_ssa: conn %lu unknown attribute type=%s (%ld)\n",
|
|
|
|
|
op->o_connid, desc.bv_val, (long) rc );
|
|
|
|
|
|
2006-12-25 23:51:08 -05:00
|
|
|
ssa.sa_desc = slap_bv2tmp_ad( &desc, op->o_tmpmemctx );
|
2003-04-18 00:44:06 -04:00
|
|
|
}
|
2000-05-16 12:22:52 -04:00
|
|
|
}
|
2000-01-25 16:13:31 -05:00
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
2009-08-04 18:41:59 -04:00
|
|
|
/* If there is no substring matching rule, there's nothing
|
|
|
|
|
* we can do with this filter. But we continue to parse it
|
|
|
|
|
* for logging purposes.
|
|
|
|
|
*/
|
2008-11-11 13:01:35 -05:00
|
|
|
if ( ssa.sa_desc->ad_type->sat_substr == NULL ) {
|
2009-08-04 18:41:59 -04:00
|
|
|
f->f_choice |= SLAPD_FILTER_UNDEFINED;
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER,
|
|
|
|
|
"get_ssa: no substring matching rule for attributeType %s\n",
|
|
|
|
|
desc.bv_val, 0, 0 );
|
2008-11-11 13:01:35 -05:00
|
|
|
}
|
|
|
|
|
|
2003-03-16 16:50:39 -05:00
|
|
|
for ( tag = ber_first_element( ber, &len, &last );
|
|
|
|
|
tag != LBER_DEFAULT;
|
2002-03-06 22:13:11 -05:00
|
|
|
tag = ber_next_element( ber, &len, last ) )
|
1999-07-07 14:51:39 -04:00
|
|
|
{
|
2000-05-17 16:29:26 -04:00
|
|
|
unsigned usage;
|
|
|
|
|
|
2011-01-12 09:41:33 -05:00
|
|
|
if ( ber_scanf( ber, "m", &value ) == LBER_ERROR ) {
|
2000-02-29 18:48:01 -05:00
|
|
|
rc = SLAPD_DISCONNECT;
|
2000-01-28 15:01:00 -05:00
|
|
|
goto return_error;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2000-01-28 15:01:00 -05:00
|
|
|
|
2001-12-29 10:01:10 -05:00
|
|
|
if ( value.bv_val == NULL || value.bv_len == 0 ) {
|
2000-01-28 15:01:00 -05:00
|
|
|
rc = LDAP_INVALID_SYNTAX;
|
|
|
|
|
goto return_error;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-17 16:29:26 -04:00
|
|
|
switch ( tag ) {
|
|
|
|
|
case LDAP_SUBSTRING_INITIAL:
|
2005-06-20 20:38:55 -04:00
|
|
|
if ( ssa.sa_initial.bv_val != NULL
|
|
|
|
|
|| ssa.sa_any != NULL
|
|
|
|
|
|| ssa.sa_final.bv_val != NULL )
|
|
|
|
|
{
|
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
|
goto return_error;
|
|
|
|
|
}
|
2000-05-17 16:29:26 -04:00
|
|
|
usage = SLAP_MR_SUBSTR_INITIAL;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_SUBSTRING_ANY:
|
2005-06-20 20:38:55 -04:00
|
|
|
if ( ssa.sa_final.bv_val != NULL ) {
|
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
|
goto return_error;
|
|
|
|
|
}
|
2000-05-17 16:29:26 -04:00
|
|
|
usage = SLAP_MR_SUBSTR_ANY;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_SUBSTRING_FINAL:
|
2005-06-20 20:38:55 -04:00
|
|
|
if ( ssa.sa_final.bv_val != NULL ) {
|
|
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
|
|
|
|
goto return_error;
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-17 16:29:26 -04:00
|
|
|
usage = SLAP_MR_SUBSTR_FINAL;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER,
|
|
|
|
|
" unknown substring choice=%ld\n",
|
|
|
|
|
(long) tag, 0, 0 );
|
2003-03-16 19:27:33 -05:00
|
|
|
|
2005-06-20 20:38:55 -04:00
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
2000-05-17 16:29:26 -04:00
|
|
|
goto return_error;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-28 19:14:32 -05:00
|
|
|
/* validate/normalize using equality matching rule validator! */
|
2003-02-26 20:54:43 -05:00
|
|
|
rc = asserted_value_validate_normalize(
|
2003-03-16 16:58:00 -05:00
|
|
|
ssa.sa_desc, ssa.sa_desc->ad_type->sat_equality,
|
2003-04-10 21:29:28 -04:00
|
|
|
usage, &value, &nvalue, text, op->o_tmpmemctx );
|
2009-08-04 18:41:59 -04:00
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
|
f->f_choice |= SLAPD_FILTER_UNDEFINED;
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER,
|
|
|
|
|
"get_ssa: illegal value for attributeType %s (%d) %s\n",
|
|
|
|
|
desc.bv_val, rc, *text );
|
|
|
|
|
ber_dupbv_x( &nvalue, &value, op->o_tmpmemctx );
|
|
|
|
|
}
|
2000-05-17 16:29:26 -04:00
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
switch ( tag ) {
|
|
|
|
|
case LDAP_SUBSTRING_INITIAL:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " INITIAL\n", 0, 0, 0 );
|
2003-03-16 16:50:39 -05:00
|
|
|
ssa.sa_initial = nvalue;
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_SUBSTRING_ANY:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " ANY\n", 0, 0, 0 );
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_bvarray_add_x( &ssa.sa_any, &nvalue, op->o_tmpmemctx );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_SUBSTRING_FINAL:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, " FINAL\n", 0, 0, 0 );
|
2003-03-16 16:50:39 -05:00
|
|
|
ssa.sa_final = nvalue;
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2003-03-16 19:27:33 -05:00
|
|
|
assert( 0 );
|
2004-04-19 23:44:57 -04:00
|
|
|
slap_sl_free( nvalue.bv_val, op->o_tmpmemctx );
|
2005-06-20 20:38:55 -04:00
|
|
|
rc = LDAP_PROTOCOL_ERROR;
|
2000-01-28 15:01:00 -05:00
|
|
|
|
2000-01-25 16:13:31 -05:00
|
|
|
return_error:
|
2000-04-11 21:39:52 -04:00
|
|
|
Debug( LDAP_DEBUG_FILTER, " error=%ld\n",
|
|
|
|
|
(long) rc, 0, 0 );
|
2004-04-19 23:44:57 -04:00
|
|
|
slap_sl_free( ssa.sa_initial.bv_val, op->o_tmpmemctx );
|
2003-04-10 21:29:28 -04:00
|
|
|
ber_bvarray_free_x( ssa.sa_any, op->o_tmpmemctx );
|
2006-12-25 23:51:08 -05:00
|
|
|
if ( ssa.sa_desc->ad_flags & SLAP_DESC_TEMPORARY )
|
|
|
|
|
op->o_tmpfree( ssa.sa_desc, op->o_tmpmemctx );
|
2004-04-19 23:44:57 -04:00
|
|
|
slap_sl_free( ssa.sa_final.bv_val, op->o_tmpmemctx );
|
2000-01-28 15:01:00 -05:00
|
|
|
return rc;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2003-03-16 16:50:39 -05:00
|
|
|
|
2008-09-05 20:00:37 -04:00
|
|
|
*text = NULL;
|
2003-03-16 16:50:39 -05:00
|
|
|
rc = LDAP_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( rc == LDAP_SUCCESS ) {
|
2006-12-25 18:30:45 -05:00
|
|
|
f->f_sub = op->o_tmpalloc( sizeof( ssa ), op->o_tmpmemctx );
|
|
|
|
|
*f->f_sub = ssa;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
2000-01-25 16:13:31 -05:00
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
Debug( LDAP_DEBUG_FILTER, "end get_ssa\n", 0, 0, 0 );
|
2004-01-11 17:52:07 -05:00
|
|
|
return rc /* LDAP_SUCCESS */ ;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2008-10-09 18:34:43 -04:00
|
|
|
filter_free_x( Operation *op, Filter *f, int freeme )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
Filter *p, *next;
|
|
|
|
|
|
|
|
|
|
if ( f == NULL ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
f->f_choice &= SLAPD_FILTER_MASK;
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
switch ( f->f_choice ) {
|
2000-02-06 16:09:44 -05:00
|
|
|
case LDAP_FILTER_PRESENT:
|
2010-08-29 12:27:08 -04:00
|
|
|
if ( f->f_desc->ad_flags & SLAP_DESC_TEMPORARY )
|
|
|
|
|
op->o_tmpfree( f->f_desc, op->o_tmpmemctx );
|
2000-02-06 16:09:44 -05:00
|
|
|
break;
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
2003-04-09 12:52:03 -04:00
|
|
|
ava_free( op, f->f_ava, 1 );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
2001-12-29 10:01:10 -05:00
|
|
|
if ( f->f_sub_initial.bv_val != NULL ) {
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( f->f_sub_initial.bv_val, op->o_tmpmemctx );
|
2000-02-06 16:09:44 -05:00
|
|
|
}
|
2003-04-10 21:29:28 -04:00
|
|
|
ber_bvarray_free_x( f->f_sub_any, op->o_tmpmemctx );
|
2001-12-29 10:01:10 -05:00
|
|
|
if ( f->f_sub_final.bv_val != NULL ) {
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( f->f_sub_final.bv_val, op->o_tmpmemctx );
|
2000-02-06 16:09:44 -05:00
|
|
|
}
|
2006-12-25 23:51:08 -05:00
|
|
|
if ( f->f_sub->sa_desc->ad_flags & SLAP_DESC_TEMPORARY )
|
|
|
|
|
op->o_tmpfree( f->f_sub->sa_desc, op->o_tmpmemctx );
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( f->f_sub, op->o_tmpmemctx );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_AND:
|
|
|
|
|
case LDAP_FILTER_OR:
|
|
|
|
|
case LDAP_FILTER_NOT:
|
|
|
|
|
for ( p = f->f_list; p != NULL; p = next ) {
|
|
|
|
|
next = p->f_next;
|
2008-10-09 18:34:43 -04:00
|
|
|
filter_free_x( op, p, 1 );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2002-01-06 01:21:30 -05:00
|
|
|
case LDAP_FILTER_EXT:
|
2003-04-09 12:52:03 -04:00
|
|
|
mra_free( op, f->f_mra, 1 );
|
2002-01-06 01:21:30 -05:00
|
|
|
break;
|
|
|
|
|
|
2000-02-29 18:48:01 -05:00
|
|
|
case SLAPD_FILTER_COMPUTED:
|
|
|
|
|
break;
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
default:
|
2000-05-15 14:46:03 -04:00
|
|
|
Debug( LDAP_DEBUG_ANY, "filter_free: unknown filter type=%lu\n",
|
2002-03-06 22:13:11 -05:00
|
|
|
f->f_choice, 0, 0 );
|
1998-08-08 20:43:13 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2000-02-06 16:09:44 -05:00
|
|
|
|
2008-10-09 18:34:43 -04:00
|
|
|
if ( freeme ) {
|
|
|
|
|
op->o_tmpfree( f, op->o_tmpmemctx );
|
|
|
|
|
}
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
2002-03-06 22:13:11 -05:00
|
|
|
void
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_free( Filter *f )
|
|
|
|
|
{
|
|
|
|
|
Operation op;
|
2004-11-25 17:59:00 -05:00
|
|
|
Opheader ohdr;
|
2003-04-09 12:52:03 -04:00
|
|
|
|
2004-11-25 17:59:00 -05:00
|
|
|
op.o_hdr = &ohdr;
|
2004-04-19 23:44:57 -04:00
|
|
|
op.o_tmpmemctx = slap_sl_context( f );
|
|
|
|
|
op.o_tmpmfuncs = &slap_sl_mfuncs;
|
2008-10-09 18:34:43 -04:00
|
|
|
filter_free_x( &op, f, 1 );
|
2003-04-09 12:52:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2003-04-09 19:37:00 -04:00
|
|
|
filter2bv_x( Operation *op, Filter *f, struct berval *fstr )
|
2011-01-29 07:29:20 -05:00
|
|
|
{
|
|
|
|
|
return filter2bv_undef_x( op, f, 0, fstr );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
filter2bv_undef_x( Operation *op, Filter *f, int noundef, struct berval *fstr )
|
2002-03-06 22:13:11 -05:00
|
|
|
{
|
2004-01-11 17:52:07 -05:00
|
|
|
int i;
|
|
|
|
|
Filter *p;
|
2007-10-05 05:49:19 -04:00
|
|
|
struct berval tmp, value;
|
2004-03-09 02:08:04 -05:00
|
|
|
static struct berval
|
2004-01-11 17:52:07 -05:00
|
|
|
ber_bvfalse = BER_BVC( "(?=false)" ),
|
|
|
|
|
ber_bvtrue = BER_BVC( "(?=true)" ),
|
|
|
|
|
ber_bvundefined = BER_BVC( "(?=undefined)" ),
|
|
|
|
|
ber_bverror = BER_BVC( "(?=error)" ),
|
2004-03-09 02:08:04 -05:00
|
|
|
ber_bvunknown = BER_BVC( "(?=unknown)" ),
|
2011-01-29 09:16:02 -05:00
|
|
|
ber_bvnone = BER_BVC( "(?=none)" ),
|
|
|
|
|
ber_bvF = BER_BVC( "(|)" ),
|
|
|
|
|
ber_bvT = BER_BVC( "(&)" );
|
2004-01-11 17:52:07 -05:00
|
|
|
ber_len_t len;
|
2006-12-25 18:30:45 -05:00
|
|
|
ber_tag_t choice;
|
2011-01-29 07:29:20 -05:00
|
|
|
int undef, undef2;
|
2006-12-25 18:30:45 -05:00
|
|
|
char *sign;
|
2002-03-06 22:13:11 -05:00
|
|
|
|
|
|
|
|
if ( f == NULL ) {
|
2004-03-09 02:08:04 -05:00
|
|
|
ber_dupbv_x( fstr, &ber_bvnone, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
undef = f->f_choice & SLAPD_FILTER_UNDEFINED;
|
2011-01-29 07:29:20 -05:00
|
|
|
undef2 = (undef && !noundef);
|
2006-12-25 18:30:45 -05:00
|
|
|
choice = f->f_choice & SLAPD_FILTER_MASK;
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
switch ( choice ) {
|
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
|
fstr->bv_len = STRLENOF("(=)");
|
|
|
|
|
sign = "=";
|
|
|
|
|
goto simple;
|
2002-03-06 22:13:11 -05:00
|
|
|
case LDAP_FILTER_GE:
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len = STRLENOF("(>=)");
|
|
|
|
|
sign = ">=";
|
|
|
|
|
goto simple;
|
2002-03-06 22:13:11 -05:00
|
|
|
case LDAP_FILTER_LE:
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len = STRLENOF("(<=)");
|
|
|
|
|
sign = "<=";
|
|
|
|
|
goto simple;
|
2002-03-06 22:13:11 -05:00
|
|
|
case LDAP_FILTER_APPROX:
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len = STRLENOF("(~=)");
|
|
|
|
|
sign = "~=";
|
|
|
|
|
|
|
|
|
|
simple:
|
2007-10-05 05:49:19 -04:00
|
|
|
value = f->f_av_value;
|
2007-11-06 23:02:21 -05:00
|
|
|
if ( f->f_av_desc->ad_type->sat_equality &&
|
2008-02-18 14:47:07 -05:00
|
|
|
!undef &&
|
|
|
|
|
( f->f_av_desc->ad_type->sat_equality->smr_usage & SLAP_MR_MUTATION_NORMALIZER ))
|
|
|
|
|
{
|
2007-10-05 05:49:19 -04:00
|
|
|
f->f_av_desc->ad_type->sat_equality->smr_normalize(
|
|
|
|
|
(SLAP_MR_DENORMALIZE|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX),
|
|
|
|
|
NULL, NULL, &f->f_av_value, &value, op->o_tmpmemctx );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filter_escape_value_x( &value, &tmp, op->o_tmpmemctx );
|
2006-09-09 12:23:02 -04:00
|
|
|
/* NOTE: tmp can legitimately be NULL (meaning empty)
|
|
|
|
|
* since in a Filter values in AVAs are supposed
|
|
|
|
|
* to have been normalized, meaning that an empty value
|
|
|
|
|
* is legal for that attribute's syntax */
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len += f->f_av_desc->ad_cname.bv_len + tmp.bv_len;
|
2011-01-29 07:29:20 -05:00
|
|
|
if ( undef2 )
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len++;
|
2003-04-09 19:37:00 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s)",
|
2011-01-29 07:29:20 -05:00
|
|
|
undef2 ? "?" : "",
|
2006-12-25 18:30:45 -05:00
|
|
|
f->f_av_desc->ad_cname.bv_val, sign,
|
|
|
|
|
tmp.bv_len ? tmp.bv_val : "" );
|
|
|
|
|
|
2007-10-05 05:49:19 -04:00
|
|
|
if ( value.bv_val != f->f_av_value.bv_val ) {
|
|
|
|
|
ber_memfree_x( value.bv_val, op->o_tmpmemctx );
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
|
|
|
|
fstr->bv_len = f->f_sub_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
STRLENOF("(=*)");
|
2011-01-29 07:29:20 -05:00
|
|
|
if ( undef2 )
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len++;
|
2003-04-09 19:37:00 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 128, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s=*)",
|
2011-01-29 07:29:20 -05:00
|
|
|
undef2 ? "?" : "",
|
2002-03-06 22:13:11 -05:00
|
|
|
f->f_sub_desc->ad_cname.bv_val );
|
|
|
|
|
|
|
|
|
|
if ( f->f_sub_initial.bv_val != NULL ) {
|
2006-09-09 12:23:02 -04:00
|
|
|
ber_len_t tmplen;
|
|
|
|
|
|
2002-03-06 22:13:11 -05:00
|
|
|
len = fstr->bv_len;
|
|
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
filter_escape_value_x( &f->f_sub_initial, &tmp, op->o_tmpmemctx );
|
2007-02-20 18:08:09 -05:00
|
|
|
tmplen = tmp.bv_len;
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-09-09 12:23:02 -04:00
|
|
|
fstr->bv_len += tmplen;
|
|
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val,
|
|
|
|
|
fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2007-02-20 18:08:09 -05:00
|
|
|
snprintf( &fstr->bv_val[len - 2],
|
2006-09-09 12:23:02 -04:00
|
|
|
tmplen + STRLENOF( /*(*/ "*)" ) + 1,
|
2002-03-06 22:13:11 -05:00
|
|
|
/* "(attr=" */ "%s*)",
|
2007-02-20 18:08:09 -05:00
|
|
|
tmp.bv_len ? tmp.bv_val : "");
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( f->f_sub_any != NULL ) {
|
|
|
|
|
for ( i = 0; f->f_sub_any[i].bv_val != NULL; i++ ) {
|
2006-09-09 12:23:02 -04:00
|
|
|
ber_len_t tmplen;
|
|
|
|
|
|
2002-03-06 22:13:11 -05:00
|
|
|
len = fstr->bv_len;
|
2004-05-19 15:39:40 -04:00
|
|
|
filter_escape_value_x( &f->f_sub_any[i],
|
|
|
|
|
&tmp, op->o_tmpmemctx );
|
2007-02-20 18:08:09 -05:00
|
|
|
tmplen = tmp.bv_len;
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-09-09 12:23:02 -04:00
|
|
|
fstr->bv_len += tmplen + STRLENOF( /*(*/ ")" );
|
|
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val,
|
|
|
|
|
fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2007-02-20 18:08:09 -05:00
|
|
|
snprintf( &fstr->bv_val[len - 1],
|
2006-09-09 12:23:02 -04:00
|
|
|
tmplen + STRLENOF( /*(*/ "*)" ) + 1,
|
2002-03-06 22:13:11 -05:00
|
|
|
/* "(attr=[init]*[any*]" */ "%s*)",
|
2007-02-20 18:08:09 -05:00
|
|
|
tmp.bv_len ? tmp.bv_val : "");
|
2003-04-09 19:37:00 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( f->f_sub_final.bv_val != NULL ) {
|
2006-09-09 12:23:02 -04:00
|
|
|
ber_len_t tmplen;
|
|
|
|
|
|
2002-03-06 22:13:11 -05:00
|
|
|
len = fstr->bv_len;
|
|
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
filter_escape_value_x( &f->f_sub_final, &tmp, op->o_tmpmemctx );
|
2007-02-20 18:08:09 -05:00
|
|
|
tmplen = tmp.bv_len;
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-09-09 12:23:02 -04:00
|
|
|
fstr->bv_len += tmplen;
|
|
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val,
|
|
|
|
|
fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2007-02-20 18:08:09 -05:00
|
|
|
snprintf( &fstr->bv_val[len - 1],
|
2006-09-09 12:23:02 -04:00
|
|
|
tmplen + STRLENOF( /*(*/ ")" ) + 1,
|
2002-03-06 22:13:11 -05:00
|
|
|
/* "(attr=[init*][any*]" */ "%s)",
|
2007-02-20 18:08:09 -05:00
|
|
|
tmp.bv_len ? tmp.bv_val : "");
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
|
|
|
|
fstr->bv_len = f->f_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
STRLENOF("(=*)");
|
2011-01-29 07:29:20 -05:00
|
|
|
if ( undef2 )
|
2006-12-25 18:30:45 -05:00
|
|
|
fstr->bv_len++;
|
|
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s=*)",
|
2011-01-29 07:29:20 -05:00
|
|
|
undef2 ? "?" : "",
|
2002-03-06 22:13:11 -05:00
|
|
|
f->f_desc->ad_cname.bv_val );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_AND:
|
|
|
|
|
case LDAP_FILTER_OR:
|
|
|
|
|
case LDAP_FILTER_NOT:
|
2006-09-09 12:23:02 -04:00
|
|
|
fstr->bv_len = STRLENOF("(%)");
|
2003-04-09 19:37:00 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 128, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
|
|
|
|
|
f->f_choice == LDAP_FILTER_AND ? '&' :
|
|
|
|
|
f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
|
|
|
|
|
|
|
|
|
|
for ( p = f->f_list; p != NULL; p = p->f_next ) {
|
|
|
|
|
len = fstr->bv_len;
|
|
|
|
|
|
2011-01-29 07:29:20 -05:00
|
|
|
filter2bv_undef_x( op, p, noundef, &tmp );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
|
|
|
|
fstr->bv_len += tmp.bv_len;
|
2004-05-19 15:39:40 -04:00
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val, fstr->bv_len + 1,
|
|
|
|
|
op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2006-09-09 12:23:02 -04:00
|
|
|
snprintf( &fstr->bv_val[len-1],
|
|
|
|
|
tmp.bv_len + STRLENOF( /*(*/ ")" ) + 1,
|
2002-03-06 22:13:11 -05:00
|
|
|
/*"("*/ "%s)", tmp.bv_val );
|
|
|
|
|
|
2003-04-09 19:37:00 -04:00
|
|
|
op->o_tmpfree( tmp.bv_val, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2002-08-31 20:33:20 -04:00
|
|
|
case LDAP_FILTER_EXT: {
|
2006-09-09 12:23:02 -04:00
|
|
|
struct berval ad;
|
|
|
|
|
|
|
|
|
|
filter_escape_value_x( &f->f_mr_value, &tmp, op->o_tmpmemctx );
|
|
|
|
|
/* NOTE: tmp can legitimately be NULL (meaning empty)
|
|
|
|
|
* since in a Filter values in MRAs are supposed
|
|
|
|
|
* to have been normalized, meaning that an empty value
|
|
|
|
|
* is legal for that attribute's syntax */
|
|
|
|
|
|
|
|
|
|
if ( f->f_mr_desc ) {
|
|
|
|
|
ad = f->f_mr_desc->ad_cname;
|
|
|
|
|
} else {
|
|
|
|
|
ad.bv_len = 0;
|
|
|
|
|
ad.bv_val = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fstr->bv_len = ad.bv_len +
|
2011-01-29 07:29:20 -05:00
|
|
|
( undef2 ? 1 : 0 ) +
|
2006-09-09 12:23:02 -04:00
|
|
|
( f->f_mr_dnattrs ? STRLENOF(":dn") : 0 ) +
|
2011-01-29 07:29:20 -05:00
|
|
|
( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + STRLENOF(":") : 0 ) +
|
2006-09-09 12:23:02 -04:00
|
|
|
tmp.bv_len + STRLENOF("(:=)");
|
|
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
|
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s%s:=%s)",
|
2011-01-29 07:29:20 -05:00
|
|
|
undef2 ? "?" : "",
|
2006-09-09 12:23:02 -04:00
|
|
|
ad.bv_val,
|
|
|
|
|
f->f_mr_dnattrs ? ":dn" : "",
|
|
|
|
|
f->f_mr_rule_text.bv_len ? ":" : "",
|
|
|
|
|
f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_val : "",
|
|
|
|
|
tmp.bv_len ? tmp.bv_val : "" );
|
|
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-08-31 20:33:20 -04:00
|
|
|
} break;
|
2002-03-10 20:48:37 -05:00
|
|
|
|
2002-03-06 22:13:11 -05:00
|
|
|
case SLAPD_FILTER_COMPUTED:
|
2004-01-11 17:52:07 -05:00
|
|
|
switch ( f->f_result ) {
|
|
|
|
|
case LDAP_COMPARE_FALSE:
|
2011-01-29 09:16:02 -05:00
|
|
|
tmp = ( noundef ? ber_bvF : ber_bvfalse );
|
2004-01-11 17:52:07 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_COMPARE_TRUE:
|
2011-01-29 09:16:02 -05:00
|
|
|
tmp = ( noundef ? ber_bvT : ber_bvtrue );
|
2004-01-11 17:52:07 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SLAPD_COMPARE_UNDEFINED:
|
|
|
|
|
tmp = ber_bvundefined;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
tmp = ber_bverror;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-06 22:13:11 -05:00
|
|
|
|
2004-01-11 17:52:07 -05:00
|
|
|
ber_dupbv_x( fstr, &tmp, op->o_tmpmemctx );
|
|
|
|
|
break;
|
|
|
|
|
|
2002-03-06 22:13:11 -05:00
|
|
|
default:
|
2004-01-11 17:52:07 -05:00
|
|
|
ber_dupbv_x( fstr, &ber_bvunknown, op->o_tmpmemctx );
|
2002-03-06 22:13:11 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
void
|
|
|
|
|
filter2bv( Filter *f, struct berval *fstr )
|
2011-01-29 07:29:20 -05:00
|
|
|
{
|
|
|
|
|
return filter2bv_undef( f, 0, fstr );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
filter2bv_undef( Filter *f, int noundef, struct berval *fstr )
|
2003-04-09 12:52:03 -04:00
|
|
|
{
|
2003-04-09 19:37:00 -04:00
|
|
|
Operation op;
|
2004-11-25 17:59:00 -05:00
|
|
|
Opheader ohdr;
|
|
|
|
|
|
|
|
|
|
op.o_hdr = &ohdr;
|
2003-04-09 19:37:00 -04:00
|
|
|
op.o_tmpmemctx = NULL;
|
|
|
|
|
op.o_tmpmfuncs = &ch_mfuncs;
|
|
|
|
|
|
2011-01-29 07:29:20 -05:00
|
|
|
filter2bv_undef_x( &op, f, noundef, fstr );
|
2003-04-09 12:52:03 -04:00
|
|
|
}
|
|
|
|
|
|
2006-01-23 15:53:52 -05:00
|
|
|
Filter *
|
|
|
|
|
filter_dup( Filter *f, void *memctx )
|
|
|
|
|
{
|
|
|
|
|
BerMemoryFunctions *mf = &slap_sl_mfuncs;
|
|
|
|
|
Filter *n;
|
|
|
|
|
|
|
|
|
|
if ( !f )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
n = mf->bmf_malloc( sizeof(Filter), memctx );
|
|
|
|
|
n->f_choice = f->f_choice;
|
|
|
|
|
n->f_next = NULL;
|
|
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
switch( f->f_choice & SLAPD_FILTER_MASK ) {
|
2006-01-23 15:53:52 -05:00
|
|
|
case SLAPD_FILTER_COMPUTED:
|
|
|
|
|
n->f_result = f->f_result;
|
|
|
|
|
break;
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
2006-12-25 23:51:08 -05:00
|
|
|
if ( f->f_desc->ad_flags & SLAP_DESC_TEMPORARY )
|
|
|
|
|
n->f_desc = slap_bv2tmp_ad( &f->f_desc->ad_cname, memctx );
|
|
|
|
|
else
|
|
|
|
|
n->f_desc = f->f_desc;
|
2006-01-23 15:53:52 -05:00
|
|
|
break;
|
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
|
|
|
|
/* Should this be ava_dup() ? */
|
|
|
|
|
n->f_ava = mf->bmf_calloc( 1, sizeof(AttributeAssertion), memctx );
|
|
|
|
|
*n->f_ava = *f->f_ava;
|
2006-12-25 23:51:08 -05:00
|
|
|
if ( f->f_av_desc->ad_flags & SLAP_DESC_TEMPORARY )
|
|
|
|
|
n->f_av_desc = slap_bv2tmp_ad( &f->f_av_desc->ad_cname, memctx );
|
2006-01-23 15:53:52 -05:00
|
|
|
ber_dupbv_x( &n->f_av_value, &f->f_av_value, memctx );
|
|
|
|
|
break;
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
|
|
|
|
n->f_sub = mf->bmf_calloc( 1, sizeof(SubstringsAssertion), memctx );
|
2006-12-25 23:51:08 -05:00
|
|
|
if ( f->f_sub_desc->ad_flags & SLAP_DESC_TEMPORARY )
|
|
|
|
|
n->f_sub_desc = slap_bv2tmp_ad( &f->f_sub_desc->ad_cname, memctx );
|
|
|
|
|
else
|
|
|
|
|
n->f_sub_desc = f->f_sub_desc;
|
2006-01-23 15:53:52 -05:00
|
|
|
if ( !BER_BVISNULL( &f->f_sub_initial ))
|
|
|
|
|
ber_dupbv_x( &n->f_sub_initial, &f->f_sub_initial, memctx );
|
|
|
|
|
if ( f->f_sub_any ) {
|
|
|
|
|
int i;
|
|
|
|
|
for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ );
|
|
|
|
|
n->f_sub_any = mf->bmf_malloc(( i+1 )*sizeof( struct berval ),
|
|
|
|
|
memctx );
|
|
|
|
|
for ( i = 0; !BER_BVISNULL( &f->f_sub_any[i] ); i++ ) {
|
|
|
|
|
ber_dupbv_x( &n->f_sub_any[i], &f->f_sub_any[i], memctx );
|
|
|
|
|
}
|
|
|
|
|
BER_BVZERO( &n->f_sub_any[i] );
|
|
|
|
|
}
|
|
|
|
|
if ( !BER_BVISNULL( &f->f_sub_final ))
|
|
|
|
|
ber_dupbv_x( &n->f_sub_final, &f->f_sub_final, memctx );
|
|
|
|
|
break;
|
|
|
|
|
case LDAP_FILTER_EXT: {
|
|
|
|
|
/* Should this be mra_dup() ? */
|
|
|
|
|
ber_len_t length;
|
|
|
|
|
length = sizeof(MatchingRuleAssertion);
|
|
|
|
|
if ( !BER_BVISNULL( &f->f_mr_rule_text ))
|
|
|
|
|
length += f->f_mr_rule_text.bv_len + 1;
|
|
|
|
|
n->f_mra = mf->bmf_calloc( 1, length, memctx );
|
|
|
|
|
*n->f_mra = *f->f_mra;
|
2006-12-25 23:51:08 -05:00
|
|
|
if ( f->f_mr_desc && ( f->f_sub_desc->ad_flags & SLAP_DESC_TEMPORARY ))
|
|
|
|
|
n->f_mr_desc = slap_bv2tmp_ad( &f->f_mr_desc->ad_cname, memctx );
|
2006-01-23 15:53:52 -05:00
|
|
|
ber_dupbv_x( &n->f_mr_value, &f->f_mr_value, memctx );
|
|
|
|
|
if ( !BER_BVISNULL( &f->f_mr_rule_text )) {
|
|
|
|
|
n->f_mr_rule_text.bv_val = (char *)(n->f_mra+1);
|
|
|
|
|
AC_MEMCPY(n->f_mr_rule_text.bv_val,
|
|
|
|
|
f->f_mr_rule_text.bv_val, f->f_mr_rule_text.bv_len );
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
case LDAP_FILTER_AND:
|
|
|
|
|
case LDAP_FILTER_OR:
|
|
|
|
|
case LDAP_FILTER_NOT: {
|
|
|
|
|
Filter **p;
|
|
|
|
|
for ( p = &n->f_list, f = f->f_list; f; f = f->f_next ) {
|
|
|
|
|
*p = filter_dup( f, memctx );
|
|
|
|
|
p = &(*p)->f_next;
|
|
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-02 14:56:56 -04:00
|
|
|
static int
|
|
|
|
|
get_simple_vrFilter(
|
2003-04-09 12:52:03 -04:00
|
|
|
Operation *op,
|
2002-05-02 14:56:56 -04:00
|
|
|
BerElement *ber,
|
|
|
|
|
ValuesReturnFilter **filt,
|
|
|
|
|
const char **text )
|
|
|
|
|
{
|
|
|
|
|
ber_tag_t tag;
|
|
|
|
|
ber_len_t len;
|
|
|
|
|
int err;
|
2003-03-17 01:06:02 -05:00
|
|
|
ValuesReturnFilter vrf;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_simple_vrFilter\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
|
|
tag = ber_peek_tag( ber, &len );
|
|
|
|
|
|
|
|
|
|
if( tag == LBER_ERROR ) {
|
|
|
|
|
*text = "error decoding filter";
|
|
|
|
|
return SLAPD_DISCONNECT;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
vrf.vrf_next = NULL;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
err = LDAP_SUCCESS;
|
2003-03-17 01:06:02 -05:00
|
|
|
vrf.vrf_choice = tag;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
switch ( vrf.vrf_choice ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "EQUALITY\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, (Filter *)&vrf, SLAP_MR_EQUALITY, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
assert( vrf.vrf_ava != NULL );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "SUBSTRINGS\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ssa( op, ber, (Filter *)&vrf, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "GE\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, (Filter *)&vrf, SLAP_MR_ORDERING, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "LE\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, (Filter *)&vrf, SLAP_MR_ORDERING, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT: {
|
|
|
|
|
struct berval type;
|
|
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "PRESENT\n", 0, 0, 0 );
|
|
|
|
|
if ( ber_scanf( ber, "m", &type ) == LBER_ERROR ) {
|
|
|
|
|
err = SLAPD_DISCONNECT;
|
|
|
|
|
*text = "error decoding filter";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
vrf.vrf_desc = NULL;
|
|
|
|
|
err = slap_bv2ad( &type, &vrf.vrf_desc, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
if( err != LDAP_SUCCESS ) {
|
2006-12-25 18:30:45 -05:00
|
|
|
vrf.vrf_choice |= SLAPD_FILTER_UNDEFINED;
|
2005-08-25 17:14:26 -04:00
|
|
|
err = slap_bv2undef_ad( &type, &vrf.vrf_desc, text,
|
2006-12-25 18:30:45 -05:00
|
|
|
SLAP_AD_PROXIED);
|
2005-08-25 17:14:26 -04:00
|
|
|
|
|
|
|
|
if( err != LDAP_SUCCESS ) {
|
|
|
|
|
/* unrecognized attribute description or other error */
|
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
|
"get_simple_vrFilter: conn %lu unknown "
|
|
|
|
|
"attribute type=%s (%d)\n",
|
|
|
|
|
op->o_connid, type.bv_val, err );
|
|
|
|
|
|
|
|
|
|
vrf.vrf_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
vrf.vrf_result = LDAP_COMPARE_FALSE;
|
|
|
|
|
err = LDAP_SUCCESS;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "APPROX\n", 0, 0, 0 );
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_ava( op, ber, (Filter *)&vrf, SLAP_MR_EQUALITY_APPROX, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_EXT:
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "EXTENSIBLE\n", 0, 0, 0 );
|
|
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
err = get_mra( op, ber, (Filter *)&vrf, text );
|
2002-05-02 14:56:56 -04:00
|
|
|
if ( err != LDAP_SUCCESS ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
assert( vrf.vrf_mra != NULL );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
(void) ber_scanf( ber, "x" ); /* skip the element */
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "get_simple_vrFilter: unknown filter type=%lu\n",
|
2003-03-17 01:06:02 -05:00
|
|
|
vrf.vrf_choice, 0, 0 );
|
|
|
|
|
vrf.vrf_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
vrf.vrf_result = SLAPD_COMPARE_UNDEFINED;
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
if ( err != LDAP_SUCCESS && err != SLAPD_DISCONNECT ) {
|
|
|
|
|
/* ignore error */
|
|
|
|
|
vrf.vrf_choice = SLAPD_FILTER_COMPUTED;
|
|
|
|
|
vrf.vrf_result = SLAPD_COMPARE_UNDEFINED;
|
|
|
|
|
err = LDAP_SUCCESS;
|
|
|
|
|
}
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-03-17 01:06:02 -05:00
|
|
|
if ( err == LDAP_SUCCESS ) {
|
2006-12-28 05:32:46 -05:00
|
|
|
*filt = op->o_tmpalloc( sizeof vrf, op->o_tmpmemctx );
|
2003-03-17 01:06:02 -05:00
|
|
|
**filt = vrf;
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "end get_simple_vrFilter %d\n", err, 0, 0 );
|
2003-03-17 01:06:02 -05:00
|
|
|
|
|
|
|
|
return err;
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2003-04-09 12:52:03 -04:00
|
|
|
get_vrFilter( Operation *op, BerElement *ber,
|
2003-01-20 15:21:17 -05:00
|
|
|
ValuesReturnFilter **vrf,
|
2002-05-02 14:56:56 -04:00
|
|
|
const char **text )
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* A ValuesReturnFilter looks like this:
|
|
|
|
|
*
|
|
|
|
|
* ValuesReturnFilter ::= SEQUENCE OF SimpleFilterItem
|
|
|
|
|
* SimpleFilterItem ::= CHOICE {
|
|
|
|
|
* equalityMatch [3] AttributeValueAssertion,
|
|
|
|
|
* substrings [4] SubstringFilter,
|
|
|
|
|
* greaterOrEqual [5] AttributeValueAssertion,
|
|
|
|
|
* lessOrEqual [6] AttributeValueAssertion,
|
|
|
|
|
* present [7] AttributeType,
|
|
|
|
|
* approxMatch [8] AttributeValueAssertion,
|
|
|
|
|
* extensibleMatch [9] SimpleMatchingAssertion -- LDAPv3
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* SubstringFilter ::= SEQUENCE {
|
|
|
|
|
* type AttributeType,
|
|
|
|
|
* SEQUENCE OF CHOICE {
|
|
|
|
|
* initial [0] IA5String,
|
|
|
|
|
* any [1] IA5String,
|
|
|
|
|
* final [2] IA5String
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* SimpleMatchingAssertion ::= SEQUENCE { -- LDAPv3
|
|
|
|
|
* matchingRule [1] MatchingRuleId OPTIONAL,
|
|
|
|
|
* type [2] AttributeDescription OPTIONAL,
|
|
|
|
|
* matchValue [3] AssertionValue }
|
|
|
|
|
*/
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
ValuesReturnFilter **n;
|
2002-05-02 14:56:56 -04:00
|
|
|
ber_tag_t tag;
|
|
|
|
|
ber_len_t len;
|
|
|
|
|
char *last;
|
|
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_vrFilter\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
|
|
tag = ber_peek_tag( ber, &len );
|
|
|
|
|
|
|
|
|
|
if( tag == LBER_ERROR ) {
|
|
|
|
|
*text = "error decoding vrFilter";
|
|
|
|
|
return SLAPD_DISCONNECT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( tag != LBER_SEQUENCE ) {
|
|
|
|
|
*text = "error decoding vrFilter, expect SEQUENCE tag";
|
|
|
|
|
return SLAPD_DISCONNECT;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
n = vrf;
|
|
|
|
|
for ( tag = ber_first_element( ber, &len, &last );
|
|
|
|
|
tag != LBER_DEFAULT;
|
2002-05-02 14:56:56 -04:00
|
|
|
tag = ber_next_element( ber, &len, last ) )
|
|
|
|
|
{
|
2003-04-09 12:52:03 -04:00
|
|
|
int err = get_simple_vrFilter( op, ber, n, text );
|
2003-03-17 01:06:02 -05:00
|
|
|
|
|
|
|
|
if ( err != LDAP_SUCCESS ) return( err );
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
n = &(*n)->vrf_next;
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
2003-01-20 15:21:17 -05:00
|
|
|
*n = NULL;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2002-05-04 06:50:24 -04:00
|
|
|
Debug( LDAP_DEBUG_FILTER, "end get_vrFilter\n", 0, 0, 0 );
|
2002-05-02 14:56:56 -04:00
|
|
|
return( LDAP_SUCCESS );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2003-04-09 12:52:03 -04:00
|
|
|
vrFilter_free( Operation *op, ValuesReturnFilter *vrf )
|
2002-05-02 14:56:56 -04:00
|
|
|
{
|
|
|
|
|
ValuesReturnFilter *p, *next;
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf == NULL ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
for ( p = vrf; p != NULL; p = next ) {
|
|
|
|
|
next = p->vrf_next;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
switch ( vrf->vrf_choice & SLAPD_FILTER_MASK ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
case LDAP_FILTER_PRESENT:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
|
case LDAP_FILTER_GE:
|
|
|
|
|
case LDAP_FILTER_LE:
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
2003-04-09 12:52:03 -04:00
|
|
|
ava_free( op, vrf->vrf_ava, 1 );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf->vrf_sub_initial.bv_val != NULL ) {
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( vrf->vrf_sub_initial.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_bvarray_free_x( vrf->vrf_sub_any, op->o_tmpmemctx );
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf->vrf_sub_final.bv_val != NULL ) {
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( vrf->vrf_sub_final.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( vrf->vrf_sub, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_EXT:
|
2003-04-09 12:52:03 -04:00
|
|
|
mra_free( op, vrf->vrf_mra, 1 );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SLAPD_FILTER_COMPUTED:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "filter_free: unknown filter type=%lu\n",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_choice, 0, 0 );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( vrf, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2003-04-09 12:52:03 -04:00
|
|
|
vrFilter2bv( Operation *op, ValuesReturnFilter *vrf, struct berval *fstr )
|
2002-05-02 14:56:56 -04:00
|
|
|
{
|
|
|
|
|
ValuesReturnFilter *p;
|
|
|
|
|
struct berval tmp;
|
|
|
|
|
ber_len_t len;
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf == NULL ) {
|
2006-09-09 12:23:02 -04:00
|
|
|
ber_str2bv_x( "No filter!", STRLENOF("No filter!"),
|
2003-04-29 14:13:10 -04:00
|
|
|
1, fstr, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-09 12:23:02 -04:00
|
|
|
fstr->bv_len = STRLENOF("()");
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 128, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "()");
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
for ( p = vrf; p != NULL; p = p->vrf_next ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
len = fstr->bv_len;
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
simple_vrFilter2bv( op, p, &tmp );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
fstr->bv_len += tmp.bv_len;
|
2004-05-19 15:39:40 -04:00
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val, fstr->bv_len + 1,
|
|
|
|
|
op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( &fstr->bv_val[len-1], tmp.bv_len + 2,
|
|
|
|
|
/*"("*/ "%s)", tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
op->o_tmpfree( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2003-04-09 12:52:03 -04:00
|
|
|
simple_vrFilter2bv( Operation *op, ValuesReturnFilter *vrf, struct berval *fstr )
|
2002-05-02 14:56:56 -04:00
|
|
|
{
|
|
|
|
|
struct berval tmp;
|
|
|
|
|
ber_len_t len;
|
2006-12-26 06:34:33 -05:00
|
|
|
int undef;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf == NULL ) {
|
2006-09-09 12:23:02 -04:00
|
|
|
ber_str2bv_x( "No filter!", STRLENOF("No filter!"), 1, fstr,
|
2004-05-19 15:39:40 -04:00
|
|
|
op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2006-12-26 06:34:33 -05:00
|
|
|
undef = vrf->vrf_choice & SLAPD_FILTER_UNDEFINED;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2006-12-25 18:30:45 -05:00
|
|
|
switch ( vrf->vrf_choice & SLAPD_FILTER_MASK ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
case LDAP_FILTER_EQUALITY:
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_av_value, &tmp, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
fstr->bv_len = vrf->vrf_av_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
tmp.bv_len + STRLENOF("(=)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_av_desc->ad_cname.bv_val,
|
2002-05-02 14:56:56 -04:00
|
|
|
tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_GE:
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_av_value, &tmp, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
fstr->bv_len = vrf->vrf_av_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
tmp.bv_len + STRLENOF("(>=)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_av_desc->ad_cname.bv_val,
|
2002-05-02 14:56:56 -04:00
|
|
|
tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_av_value, &tmp, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
fstr->bv_len = vrf->vrf_av_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
tmp.bv_len + STRLENOF("(<=)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_av_desc->ad_cname.bv_val,
|
2002-05-02 14:56:56 -04:00
|
|
|
tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_av_value, &tmp, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
fstr->bv_len = vrf->vrf_av_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
tmp.bv_len + STRLENOF("(~=)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_av_desc->ad_cname.bv_val,
|
2002-05-02 14:56:56 -04:00
|
|
|
tmp.bv_val );
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
2003-01-20 15:21:17 -05:00
|
|
|
fstr->bv_len = vrf->vrf_sub_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
STRLENOF("(=*)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 128, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_sub_desc->ad_cname.bv_val );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf->vrf_sub_initial.bv_val != NULL ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
len = fstr->bv_len;
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_sub_initial, &tmp, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
fstr->bv_len += tmp.bv_len;
|
2004-05-19 15:39:40 -04:00
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val, fstr->bv_len + 1,
|
|
|
|
|
op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( &fstr->bv_val[len-2], tmp.bv_len+3,
|
|
|
|
|
/* "(attr=" */ "%s*)",
|
|
|
|
|
tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf->vrf_sub_any != NULL ) {
|
2002-07-08 14:55:50 -04:00
|
|
|
int i;
|
2003-01-20 15:21:17 -05:00
|
|
|
for ( i = 0; vrf->vrf_sub_any[i].bv_val != NULL; i++ ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
len = fstr->bv_len;
|
2004-05-19 15:39:40 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_sub_any[i], &tmp,
|
|
|
|
|
op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
fstr->bv_len += tmp.bv_len + 1;
|
2004-05-19 15:39:40 -04:00
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val,
|
|
|
|
|
fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( &fstr->bv_val[len-1], tmp.bv_len+3,
|
|
|
|
|
/* "(attr=[init]*[any*]" */ "%s*)",
|
|
|
|
|
tmp.bv_val );
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf->vrf_sub_final.bv_val != NULL ) {
|
2002-05-02 14:56:56 -04:00
|
|
|
len = fstr->bv_len;
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_sub_final, &tmp, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
fstr->bv_len += tmp.bv_len;
|
2004-05-19 15:39:40 -04:00
|
|
|
fstr->bv_val = op->o_tmprealloc( fstr->bv_val, fstr->bv_len + 1,
|
|
|
|
|
op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( &fstr->bv_val[len-1], tmp.bv_len+3,
|
|
|
|
|
/* "(attr=[init*][any*]" */ "%s)",
|
|
|
|
|
tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
2003-01-20 15:21:17 -05:00
|
|
|
fstr->bv_len = vrf->vrf_desc->ad_cname.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
STRLENOF("(=*)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_desc->ad_cname.bv_val );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
2002-08-31 20:33:20 -04:00
|
|
|
case LDAP_FILTER_EXT: {
|
2002-08-29 06:55:48 -04:00
|
|
|
struct berval ad;
|
2003-04-09 12:52:03 -04:00
|
|
|
filter_escape_value_x( &vrf->vrf_mr_value, &tmp, op->o_tmpmemctx );
|
2002-08-29 06:55:48 -04:00
|
|
|
|
2003-01-20 15:21:17 -05:00
|
|
|
if ( vrf->vrf_mr_desc ) {
|
|
|
|
|
ad = vrf->vrf_mr_desc->ad_cname;
|
2002-08-29 06:55:48 -04:00
|
|
|
} else {
|
|
|
|
|
ad.bv_len = 0;
|
|
|
|
|
ad.bv_val = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fstr->bv_len = ad.bv_len +
|
2006-09-09 12:23:02 -04:00
|
|
|
( vrf->vrf_mr_dnattrs ? STRLENOF(":dn") : 0 ) +
|
2004-05-19 15:39:40 -04:00
|
|
|
( vrf->vrf_mr_rule_text.bv_len
|
|
|
|
|
? vrf->vrf_mr_rule_text.bv_len+1 : 0 ) +
|
2006-09-09 12:23:02 -04:00
|
|
|
tmp.bv_len + STRLENOF("(:=)");
|
2006-12-25 18:30:45 -05:00
|
|
|
if ( undef ) fstr->bv_len++;
|
2003-04-09 12:52:03 -04:00
|
|
|
fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
|
2002-08-29 06:55:48 -04:00
|
|
|
|
|
|
|
|
snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
|
|
|
|
|
ad.bv_val,
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_mr_dnattrs ? ":dn" : "",
|
|
|
|
|
vrf->vrf_mr_rule_text.bv_len ? ":" : "",
|
|
|
|
|
vrf->vrf_mr_rule_text.bv_len ? vrf->vrf_mr_rule_text.bv_val : "",
|
2002-08-29 06:55:48 -04:00
|
|
|
tmp.bv_val );
|
|
|
|
|
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_memfree_x( tmp.bv_val, op->o_tmpmemctx );
|
2002-08-31 20:33:20 -04:00
|
|
|
} break;
|
2002-05-02 14:56:56 -04:00
|
|
|
|
|
|
|
|
case SLAPD_FILTER_COMPUTED:
|
2003-04-09 12:52:03 -04:00
|
|
|
ber_str2bv_x(
|
2003-01-20 15:21:17 -05:00
|
|
|
vrf->vrf_result == LDAP_COMPARE_FALSE ? "(?=false)" :
|
|
|
|
|
vrf->vrf_result == LDAP_COMPARE_TRUE ? "(?=true)" :
|
2004-05-19 15:39:40 -04:00
|
|
|
vrf->vrf_result == SLAPD_COMPARE_UNDEFINED
|
|
|
|
|
? "(?=undefined)" : "(?=error)",
|
2006-09-09 12:23:02 -04:00
|
|
|
vrf->vrf_result == LDAP_COMPARE_FALSE ? STRLENOF("(?=false)") :
|
|
|
|
|
vrf->vrf_result == LDAP_COMPARE_TRUE ? STRLENOF("(?=true)") :
|
2004-05-19 15:39:40 -04:00
|
|
|
vrf->vrf_result == SLAPD_COMPARE_UNDEFINED
|
2006-09-09 12:23:02 -04:00
|
|
|
? STRLENOF("(?=undefined)") : STRLENOF("(?=error)"),
|
2003-04-09 12:52:03 -04:00
|
|
|
1, fstr, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2006-09-09 12:23:02 -04:00
|
|
|
ber_str2bv_x( "(?=unknown)", STRLENOF("(?=unknown)"),
|
2003-04-29 14:13:10 -04:00
|
|
|
1, fstr, op->o_tmpmemctx );
|
2002-05-02 14:56:56 -04:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|