version 1.46, 2000/05/27 20:46:37
|
version 1.47, 2000/06/06 17:43:19
|
Line 1
|
Line 1
|
/* filter.c - routines for parsing and dealing with filters */ |
/* filter.c - routines for parsing and dealing with filters */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/filter.c,v 1.45 2000/05/27 18:40:26 kurt Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/filter.c,v 1.46 2000/05/27 20:46:37 kurt Exp $ */ |
/* |
/* |
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. |
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
Line 95 get_filter(
|
Line 95 get_filter(
|
case LDAP_FILTER_EQUALITY: |
case LDAP_FILTER_EQUALITY: |
Debug( LDAP_DEBUG_FILTER, "EQUALITY\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "EQUALITY\n", 0, 0, 0 ); |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
err = get_ava( ber, &f->f_ava, SLAP_MR_EQUALITY, text ); |
err = get_ava( ber, &f->f_ava, SLAP_MR_EQUALITY, text ); |
#else |
|
err = get_ava( ber, &f->f_ava, text ); |
|
#endif |
|
if ( err != LDAP_SUCCESS ) { |
if ( err != LDAP_SUCCESS ) { |
break; |
break; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
assert( f->f_ava != NULL ); |
assert( f->f_ava != NULL ); |
|
|
*fstr = ch_malloc( sizeof("(=)") |
*fstr = ch_malloc( sizeof("(=)") |
Line 115 get_filter(
|
Line 110 get_filter(
|
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_value->bv_val ); |
f->f_av_value->bv_val ); |
|
|
#else |
|
*fstr = ch_malloc( sizeof("(=)") |
|
+ strlen( f->f_avtype ) |
|
+ f->f_avvalue.bv_len); |
|
sprintf( *fstr, "(%s=%s)", f->f_avtype, |
|
f->f_avvalue.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_SUBSTRINGS: |
case LDAP_FILTER_SUBSTRINGS: |
Line 132 get_filter(
|
Line 120 get_filter(
|
case LDAP_FILTER_GE: |
case LDAP_FILTER_GE: |
Debug( LDAP_DEBUG_FILTER, "GE\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "GE\n", 0, 0, 0 ); |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
err = get_ava( ber, &f->f_ava, SLAP_MR_ORDERING, text ); |
err = get_ava( ber, &f->f_ava, SLAP_MR_ORDERING, text ); |
#else |
|
err = get_ava( ber, &f->f_ava, text ); |
|
#endif |
|
if ( err != LDAP_SUCCESS ) { |
if ( err != LDAP_SUCCESS ) { |
break; |
break; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
*fstr = ch_malloc( sizeof("(>=)") |
*fstr = ch_malloc( sizeof("(>=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_value->bv_len ); |
+ f->f_av_value->bv_len ); |
Line 150 get_filter(
|
Line 133 get_filter(
|
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_value->bv_val ); |
f->f_av_value->bv_val ); |
|
|
#else |
|
*fstr = ch_malloc( sizeof("(>=)") |
|
+ strlen( f->f_avtype ) |
|
+ f->f_avvalue.bv_len); |
|
sprintf( *fstr, "(%s>=%s)", f->f_avtype, |
|
f->f_avvalue.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_LE: |
case LDAP_FILTER_LE: |
Debug( LDAP_DEBUG_FILTER, "LE\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "LE\n", 0, 0, 0 ); |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
err = get_ava( ber, &f->f_ava, SLAP_MR_ORDERING, text ); |
err = get_ava( ber, &f->f_ava, SLAP_MR_ORDERING, text ); |
#else |
|
err = get_ava( ber, &f->f_ava, text ); |
|
#endif |
|
if ( err != LDAP_SUCCESS ) { |
if ( err != LDAP_SUCCESS ) { |
break; |
break; |
} |
} |
|
|
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
*fstr = ch_malloc( sizeof("(<=)") |
*fstr = ch_malloc( sizeof("(<=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_value->bv_len ); |
+ f->f_av_value->bv_len ); |
Line 181 get_filter(
|
Line 152 get_filter(
|
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_value->bv_val ); |
f->f_av_value->bv_val ); |
|
|
#else |
|
*fstr = ch_malloc( sizeof("(<=)") |
|
+ strlen( f->f_avtype ) |
|
+ f->f_avvalue.bv_len); |
|
sprintf( *fstr, "(%s<=%s)", f->f_avtype, |
|
f->f_avvalue.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_PRESENT: { |
case LDAP_FILTER_PRESENT: { |
Line 201 get_filter(
|
Line 165 get_filter(
|
break; |
break; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
f->f_desc = NULL; |
f->f_desc = NULL; |
err = slap_bv2ad( &type, &f->f_desc, text ); |
err = slap_bv2ad( &type, &f->f_desc, text ); |
|
|
Line 217 get_filter(
|
Line 180 get_filter(
|
sprintf( *fstr, "(%s=*)", |
sprintf( *fstr, "(%s=*)", |
f->f_desc->ad_cname->bv_val ); |
f->f_desc->ad_cname->bv_val ); |
|
|
#else |
|
f->f_type = type.bv_val; |
|
err = LDAP_SUCCESS; |
|
attr_normalize( f->f_type ); |
|
*fstr = ch_malloc( sizeof("(=*)") |
|
+ strlen( f->f_type ) ); |
|
sprintf( *fstr, "(%s=*)", f->f_type ); |
|
#endif |
|
} break; |
} break; |
|
|
case LDAP_FILTER_APPROX: |
case LDAP_FILTER_APPROX: |
Debug( LDAP_DEBUG_FILTER, "APPROX\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "APPROX\n", 0, 0, 0 ); |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
err = get_ava( ber, &f->f_ava, SLAP_MR_EQUALITY_APPROX, text ); |
err = get_ava( ber, &f->f_ava, SLAP_MR_EQUALITY_APPROX, text ); |
#else |
|
err = get_ava( ber, &f->f_ava, text ); |
|
#endif |
|
if ( err != LDAP_SUCCESS ) { |
if ( err != LDAP_SUCCESS ) { |
break; |
break; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
*fstr = ch_malloc( sizeof("(~=)") |
*fstr = ch_malloc( sizeof("(~=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_value->bv_len ); |
+ f->f_av_value->bv_len ); |
Line 248 get_filter(
|
Line 198 get_filter(
|
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_value->bv_val ); |
f->f_av_value->bv_val ); |
|
|
#else |
|
*fstr = ch_malloc( sizeof("(~=)") |
|
+ strlen( f->f_avtype ) |
|
+ f->f_avvalue.bv_len); |
|
sprintf( *fstr, "(%s~=%s)", f->f_avtype, |
|
f->f_avvalue.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_AND: |
case LDAP_FILTER_AND: |
Line 391 get_substring_filter(
|
Line 334 get_substring_filter(
|
struct berval *value; |
struct berval *value; |
char *last; |
char *last; |
struct berval type; |
struct berval type; |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
struct berval *nvalue; |
struct berval *nvalue; |
#else |
|
int syntax; |
|
#endif |
|
*text = "error decoding filter"; |
*text = "error decoding filter"; |
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 ); |
Line 404 get_substring_filter(
|
Line 343 get_substring_filter(
|
return SLAPD_DISCONNECT; |
return SLAPD_DISCONNECT; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
f->f_sub = ch_calloc( 1, sizeof(SubstringsAssertion) ); |
f->f_sub = ch_calloc( 1, sizeof(SubstringsAssertion) ); |
f->f_sub_desc = NULL; |
f->f_sub_desc = NULL; |
rc = slap_bv2ad( &type, &f->f_sub_desc, text ); |
rc = slap_bv2ad( &type, &f->f_sub_desc, text ); |
Line 419 get_substring_filter(
|
Line 357 get_substring_filter(
|
*fstr = ch_strdup( "(undefined)" ); |
*fstr = ch_strdup( "(undefined)" ); |
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
} |
} |
#else |
|
f->f_sub_type = type.bv_val; |
|
attr_normalize( f->f_sub_type ); |
|
|
|
/* should get real syntax and see if we have a substring matching rule */ |
|
syntax = attr_syntax( f->f_sub_type ); |
|
#endif |
|
|
|
f->f_sub_initial = NULL; |
f->f_sub_initial = NULL; |
f->f_sub_any = NULL; |
f->f_sub_any = NULL; |
f->f_sub_final = NULL; |
f->f_sub_final = NULL; |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
if( fstr ) { |
if( fstr ) { |
*fstr = ch_malloc( sizeof("(=" /*)*/) + |
*fstr = ch_malloc( sizeof("(=" /*)*/) + |
f->f_sub_desc->ad_cname->bv_len ); |
f->f_sub_desc->ad_cname->bv_len ); |
sprintf( *fstr, "(%s=" /*)*/, f->f_sub_desc->ad_cname->bv_val ); |
sprintf( *fstr, "(%s=" /*)*/, f->f_sub_desc->ad_cname->bv_val ); |
} |
} |
#else |
|
if( fstr ) { |
|
*fstr = ch_malloc( strlen( f->f_sub_type ) + 3 ); |
|
sprintf( *fstr, "(%s=" /*)*/, f->f_sub_type ); |
|
} |
|
#endif |
|
|
|
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT; |
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT; |
tag = ber_next_element( ber, &len, last ) ) |
tag = ber_next_element( ber, &len, last ) ) |
{ |
{ |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
unsigned usage; |
unsigned usage; |
#endif |
|
|
|
rc = ber_scanf( ber, "O", &value ); |
rc = ber_scanf( ber, "O", &value ); |
if ( rc == LBER_ERROR ) { |
if ( rc == LBER_ERROR ) { |
Line 463 get_substring_filter(
|
Line 385 get_substring_filter(
|
goto return_error; |
goto return_error; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
switch ( tag ) { |
switch ( tag ) { |
case LDAP_SUBSTRING_INITIAL: |
case LDAP_SUBSTRING_INITIAL: |
usage = SLAP_MR_SUBSTR_INITIAL; |
usage = SLAP_MR_SUBSTR_INITIAL; |
Line 496 get_substring_filter(
|
Line 417 get_substring_filter(
|
} |
} |
|
|
value = nvalue; |
value = nvalue; |
#else |
|
|
|
/* we should call a substring syntax normalization routine */ |
|
value_normalize( value->bv_val, syntax ); |
|
/* this is bogus, value_normalize should take a berval */ |
|
value->bv_len = strlen( value->bv_val ); |
|
#endif |
|
|
|
rc = LDAP_PROTOCOL_ERROR; |
rc = LDAP_PROTOCOL_ERROR; |
|
|
Line 570 return_error:
|
Line 484 return_error:
|
*fstr = NULL; |
*fstr = NULL; |
} |
} |
|
|
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
ad_free( f->f_sub_desc, 1 ); |
ad_free( f->f_sub_desc, 1 ); |
#else |
|
ch_free( f->f_sub_type ); |
|
#endif |
|
ber_bvfree( f->f_sub_initial ); |
ber_bvfree( f->f_sub_initial ); |
ber_bvecfree( f->f_sub_any ); |
ber_bvecfree( f->f_sub_any ); |
ber_bvfree( f->f_sub_final ); |
ber_bvfree( f->f_sub_final ); |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
ch_free( f->f_sub ); |
ch_free( f->f_sub ); |
#endif |
|
return rc; |
return rc; |
} |
} |
} |
} |
Line 608 filter_free( Filter *f )
|
Line 516 filter_free( Filter *f )
|
|
|
switch ( f->f_choice ) { |
switch ( f->f_choice ) { |
case LDAP_FILTER_PRESENT: |
case LDAP_FILTER_PRESENT: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
ad_free( f->f_desc, 1 ); |
ad_free( f->f_desc, 1 ); |
#else |
|
if ( f->f_type != NULL ) { |
|
free( f->f_type ); |
|
} |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_EQUALITY: |
case LDAP_FILTER_EQUALITY: |
case LDAP_FILTER_GE: |
case LDAP_FILTER_GE: |
case LDAP_FILTER_LE: |
case LDAP_FILTER_LE: |
case LDAP_FILTER_APPROX: |
case LDAP_FILTER_APPROX: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
ava_free( f->f_ava, 1 ); |
ava_free( f->f_ava, 1 ); |
#else |
|
ava_free( &f->f_ava, 0 ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_SUBSTRINGS: |
case LDAP_FILTER_SUBSTRINGS: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
ad_free( f->f_sub_desc, 1 ); |
ad_free( f->f_sub_desc, 1 ); |
if ( f->f_sub_initial != NULL ) { |
if ( f->f_sub_initial != NULL ) { |
ber_bvfree( f->f_sub_initial ); |
ber_bvfree( f->f_sub_initial ); |
Line 638 filter_free( Filter *f )
|
Line 535 filter_free( Filter *f )
|
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final != NULL ) { |
ber_bvfree( f->f_sub_final ); |
ber_bvfree( f->f_sub_final ); |
} |
} |
#else |
|
if ( f->f_sub_type != NULL ) { |
|
free( f->f_sub_type ); |
|
} |
|
if ( f->f_sub_initial != NULL ) { |
|
ber_bvfree( f->f_sub_initial ); |
|
} |
|
ber_bvecfree( f->f_sub_any ); |
|
if ( f->f_sub_final != NULL ) { |
|
ber_bvfree( f->f_sub_final ); |
|
} |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_AND: |
case LDAP_FILTER_AND: |
Line 687 filter_print( Filter *f )
|
Line 572 filter_print( Filter *f )
|
|
|
switch ( f->f_choice ) { |
switch ( f->f_choice ) { |
case LDAP_FILTER_EQUALITY: |
case LDAP_FILTER_EQUALITY: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
fprintf( stderr, "(%s=%s)", |
fprintf( stderr, "(%s=%s)", |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_value->bv_val ); |
f->f_av_value->bv_val ); |
#else |
|
fprintf( stderr, "(%s=%s)", |
|
f->f_ava.ava_type, |
|
f->f_ava.ava_value.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_GE: |
case LDAP_FILTER_GE: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
fprintf( stderr, "(%s>=%s)", |
fprintf( stderr, "(%s>=%s)", |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_value->bv_val ); |
f->f_av_value->bv_val ); |
#else |
|
fprintf( stderr, "(%s>=%s)", |
|
f->f_ava.ava_type, |
|
f->f_ava.ava_value.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_LE: |
case LDAP_FILTER_LE: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
fprintf( stderr, "(%s<=%s)", |
fprintf( stderr, "(%s<=%s)", |
f->f_ava->aa_desc->ad_cname->bv_val, |
f->f_ava->aa_desc->ad_cname->bv_val, |
f->f_ava->aa_value->bv_val ); |
f->f_ava->aa_value->bv_val ); |
#else |
|
fprintf( stderr, "(%s<=%s)", |
|
f->f_ava.ava_type, |
|
f->f_ava.ava_value.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_APPROX: |
case LDAP_FILTER_APPROX: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
fprintf( stderr, "(%s~=%s)", |
fprintf( stderr, "(%s~=%s)", |
f->f_ava->aa_desc->ad_cname->bv_val, |
f->f_ava->aa_desc->ad_cname->bv_val, |
f->f_ava->aa_value->bv_val ); |
f->f_ava->aa_value->bv_val ); |
#else |
|
fprintf( stderr, "(%s~=%s)", |
|
f->f_ava.ava_type, |
|
f->f_ava.ava_value.bv_val ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_SUBSTRINGS: |
case LDAP_FILTER_SUBSTRINGS: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
fprintf( stderr, "(%s=" /*)*/, |
fprintf( stderr, "(%s=" /*)*/, |
f->f_sub_desc->ad_cname->bv_val ); |
f->f_sub_desc->ad_cname->bv_val ); |
#else |
|
fprintf( stderr, "(%s=" /*)*/, |
|
f->f_sub_type ); |
|
#endif |
|
if ( f->f_sub_initial != NULL ) { |
if ( f->f_sub_initial != NULL ) { |
fprintf( stderr, "%s", |
fprintf( stderr, "%s", |
f->f_sub_initial->bv_val ); |
f->f_sub_initial->bv_val ); |
Line 760 filter_print( Filter *f )
|
Line 616 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_PRESENT: |
case LDAP_FILTER_PRESENT: |
#ifdef SLAPD_SCHEMA_NOT_COMPAT |
|
fprintf( stderr, "(%s=*)", |
fprintf( stderr, "(%s=*)", |
f->f_desc->ad_cname->bv_val ); |
f->f_desc->ad_cname->bv_val ); |
#else |
|
fprintf( stderr, "(%s=*)", |
|
f->f_type ); |
|
#endif |
|
break; |
break; |
|
|
case LDAP_FILTER_AND: |
case LDAP_FILTER_AND: |