version 1.13.4.10, 2001/12/07 15:43:18
|
version 1.49, 2000/07/01 02:57:54
|
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.13.4.9 2001/08/31 20:24:17 kurt Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/filter.c,v 1.48 2000/06/30 15:09:26 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 28 static int get_substring_filter(
|
Line 28 static int get_substring_filter(
|
char **fstr, |
char **fstr, |
const char **text ); |
const char **text ); |
|
|
static int filter_escape_value( |
static int escape_value( |
struct berval *in, |
struct berval *in, |
struct berval *out ); |
struct berval *out ); |
|
|
Line 107 get_filter(
|
Line 107 get_filter(
|
|
|
assert( f->f_ava != NULL ); |
assert( f->f_ava != NULL ); |
|
|
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
|
|
*fstr = ch_malloc( sizeof("(=)") |
*fstr = ch_malloc( sizeof("(=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
Line 133 get_filter(
|
Line 133 get_filter(
|
break; |
break; |
} |
} |
|
|
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
|
|
*fstr = ch_malloc( sizeof("(>=)") |
*fstr = ch_malloc( sizeof("(>=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
Line 155 get_filter(
|
Line 155 get_filter(
|
} |
} |
|
|
|
|
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
|
|
*fstr = ch_malloc( sizeof("(<=)") |
*fstr = ch_malloc( sizeof("(<=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
Line 183 get_filter(
|
Line 183 get_filter(
|
err = slap_bv2ad( &type, &f->f_desc, text ); |
err = slap_bv2ad( &type, &f->f_desc, text ); |
|
|
if( err != LDAP_SUCCESS ) { |
if( err != LDAP_SUCCESS ) { |
/* unrecognized attribute description or other error */ |
|
f->f_choice = SLAPD_FILTER_COMPUTED; |
|
f->f_result = LDAP_COMPARE_FALSE; |
|
*fstr = ch_strdup( "(unrecogized=*)" ); |
|
ch_free( type.bv_val ); |
ch_free( type.bv_val ); |
err = LDAP_SUCCESS; |
|
break; |
break; |
} |
} |
|
|
Line 209 get_filter(
|
Line 204 get_filter(
|
break; |
break; |
} |
} |
|
|
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
|
|
*fstr = ch_malloc( sizeof("(~=)") |
*fstr = ch_malloc( sizeof("(~=)") |
+ f->f_av_desc->ad_cname->bv_len |
+ f->f_av_desc->ad_cname->bv_len |
Line 262 get_filter(
|
Line 257 get_filter(
|
case LDAP_FILTER_EXT: |
case LDAP_FILTER_EXT: |
/* not yet implemented */ |
/* not yet implemented */ |
Debug( LDAP_DEBUG_ANY, "extensible match not yet implemented.\n", |
Debug( LDAP_DEBUG_ANY, "extensible match not yet implemented.\n", |
0, 0, 0 ); |
f->f_choice, 0, 0 ); |
(void) ber_skip_tag( ber, &len ); |
(void) ber_skip_tag( ber, &len ); |
f->f_choice = SLAPD_FILTER_COMPUTED; |
f->f_choice = SLAPD_FILTER_COMPUTED; |
f->f_result = SLAPD_COMPARE_UNDEFINED; |
f->f_result = SLAPD_COMPARE_UNDEFINED; |
Line 270 get_filter(
|
Line 265 get_filter(
|
break; |
break; |
|
|
default: |
default: |
(void) ber_scanf( ber, "x" ); /* skip the element */ |
(void) ber_skip_tag( ber, &len ); |
Debug( LDAP_DEBUG_ANY, "get_filter: unknown filter type=%lu\n", |
Debug( LDAP_DEBUG_ANY, "get_filter: unknown filter type=%lu\n", |
f->f_choice, 0, 0 ); |
f->f_choice, 0, 0 ); |
f->f_choice = SLAPD_FILTER_COMPUTED; |
f->f_choice = SLAPD_FILTER_COMPUTED; |
Line 448 get_substring_filter(
|
Line 443 get_substring_filter(
|
switch ( tag ) { |
switch ( tag ) { |
case LDAP_SUBSTRING_INITIAL: |
case LDAP_SUBSTRING_INITIAL: |
Debug( LDAP_DEBUG_FILTER, " INITIAL\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, " INITIAL\n", 0, 0, 0 ); |
if ( f->f_sub_initial != NULL |
if ( f->f_sub_initial != NULL ) { |
|| f->f_sub_any != NULL |
|
|| f->f_sub_final != NULL ) |
|
{ |
|
ber_bvfree( value ); |
ber_bvfree( value ); |
goto return_error; |
goto return_error; |
} |
} |
Line 459 get_substring_filter(
|
Line 451 get_substring_filter(
|
f->f_sub_initial = value; |
f->f_sub_initial = value; |
|
|
if( fstr ) { |
if( fstr ) { |
filter_escape_value( value, &escaped ); |
escape_value( value, &escaped ); |
*fstr = ch_realloc( *fstr, |
*fstr = ch_realloc( *fstr, |
strlen( *fstr ) + escaped.bv_len + 1 ); |
strlen( *fstr ) + escaped.bv_len + 1 ); |
strcat( *fstr, escaped.bv_val ); |
strcat( *fstr, escaped.bv_val ); |
Line 469 get_substring_filter(
|
Line 461 get_substring_filter(
|
|
|
case LDAP_SUBSTRING_ANY: |
case LDAP_SUBSTRING_ANY: |
Debug( LDAP_DEBUG_FILTER, " ANY\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, " ANY\n", 0, 0, 0 ); |
|
|
if ( f->f_sub_final != NULL ) { |
|
ber_bvfree( value ); |
|
goto return_error; |
|
} |
|
|
|
if( ber_bvecadd( &f->f_sub_any, value ) < 0 ) { |
if( ber_bvecadd( &f->f_sub_any, value ) < 0 ) { |
ber_bvfree( value ); |
ber_bvfree( value ); |
goto return_error; |
goto return_error; |
} |
} |
|
|
if( fstr ) { |
if( fstr ) { |
filter_escape_value( value, &escaped ); |
escape_value( value, &escaped ); |
*fstr = ch_realloc( *fstr, |
*fstr = ch_realloc( *fstr, |
strlen( *fstr ) + escaped.bv_len + 2 ); |
strlen( *fstr ) + escaped.bv_len + 2 ); |
strcat( *fstr, "*" ); |
strcat( *fstr, "*" ); |
Line 492 get_substring_filter(
|
Line 478 get_substring_filter(
|
|
|
case LDAP_SUBSTRING_FINAL: |
case LDAP_SUBSTRING_FINAL: |
Debug( LDAP_DEBUG_FILTER, " FINAL\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, " FINAL\n", 0, 0, 0 ); |
|
|
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final != NULL ) { |
ber_bvfree( value ); |
ber_bvfree( value ); |
goto return_error; |
goto return_error; |
} |
} |
|
|
f->f_sub_final = value; |
f->f_sub_final = value; |
|
|
if( fstr ) { |
if( fstr ) { |
filter_escape_value( value, &escaped ); |
escape_value( value, &escaped ); |
*fstr = ch_realloc( *fstr, |
*fstr = ch_realloc( *fstr, |
strlen( *fstr ) + escaped.bv_len + 2 ); |
strlen( *fstr ) + escaped.bv_len + 2 ); |
strcat( *fstr, "*" ); |
strcat( *fstr, "*" ); |
Line 577 filter_free( Filter *f )
|
Line 561 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 ); |
} |
} |
ch_free( f->f_sub ); |
|
break; |
break; |
|
|
case LDAP_FILTER_AND: |
case LDAP_FILTER_AND: |
Line 615 filter_print( Filter *f )
|
Line 598 filter_print( Filter *f )
|
|
|
switch ( f->f_choice ) { |
switch ( f->f_choice ) { |
case LDAP_FILTER_EQUALITY: |
case LDAP_FILTER_EQUALITY: |
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
fprintf( stderr, "(%s=%s)", |
fprintf( stderr, "(%s=%s)", |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
escaped.bv_val ); |
escaped.bv_val ); |
Line 623 filter_print( Filter *f )
|
Line 606 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_GE: |
case LDAP_FILTER_GE: |
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
fprintf( stderr, "(%s>=%s)", |
fprintf( stderr, "(%s>=%s)", |
f->f_av_desc->ad_cname->bv_val, |
f->f_av_desc->ad_cname->bv_val, |
escaped.bv_val ); |
escaped.bv_val ); |
Line 631 filter_print( Filter *f )
|
Line 614 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_LE: |
case LDAP_FILTER_LE: |
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
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, |
escaped.bv_val ); |
escaped.bv_val ); |
Line 639 filter_print( Filter *f )
|
Line 622 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_APPROX: |
case LDAP_FILTER_APPROX: |
filter_escape_value( f->f_av_value, &escaped ); |
escape_value( f->f_av_value, &escaped ); |
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, |
escaped.bv_val ); |
escaped.bv_val ); |
Line 650 filter_print( Filter *f )
|
Line 633 filter_print( Filter *f )
|
fprintf( stderr, "(%s=" /*)*/, |
fprintf( stderr, "(%s=" /*)*/, |
f->f_sub_desc->ad_cname->bv_val ); |
f->f_sub_desc->ad_cname->bv_val ); |
if ( f->f_sub_initial != NULL ) { |
if ( f->f_sub_initial != NULL ) { |
filter_escape_value( f->f_sub_initial, &escaped ); |
escape_value( f->f_sub_initial, &escaped ); |
fprintf( stderr, "%s", |
fprintf( stderr, "%s", |
escaped.bv_val ); |
escaped.bv_val ); |
ber_memfree( escaped.bv_val ); |
ber_memfree( escaped.bv_val ); |
} |
} |
if ( f->f_sub_any != NULL ) { |
if ( f->f_sub_any != NULL ) { |
for ( i = 0; f->f_sub_any[i] != NULL; i++ ) { |
for ( i = 0; f->f_sub_any[i] != NULL; i++ ) { |
filter_escape_value( f->f_sub_any[i], &escaped ); |
escape_value( f->f_sub_any[i], &escaped ); |
fprintf( stderr, "*%s", |
fprintf( stderr, "*%s", |
escaped.bv_val ); |
escaped.bv_val ); |
ber_memfree( escaped.bv_val ); |
ber_memfree( escaped.bv_val ); |
} |
} |
} |
} |
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final != NULL ) { |
filter_escape_value( f->f_sub_final, &escaped ); |
escape_value( f->f_sub_final, &escaped ); |
fprintf( stderr, |
fprintf( stderr, |
"*%s", escaped.bv_val ); |
"*%s", escaped.bv_val ); |
ber_memfree( escaped.bv_val ); |
ber_memfree( escaped.bv_val ); |
Line 705 filter_print( Filter *f )
|
Line 688 filter_print( Filter *f )
|
|
|
#endif /* ldap_debug */ |
#endif /* ldap_debug */ |
|
|
int filter_escape_value( |
int escape_value( |
struct berval *in, |
struct berval *in, |
struct berval *out ) |
struct berval *out ) |
{ |
{ |
Line 713 int filter_escape_value(
|
Line 696 int filter_escape_value(
|
assert( in ); |
assert( in ); |
assert( out ); |
assert( out ); |
|
|
out->bv_val = (char *) ch_malloc( ( in->bv_len * 3 ) + 1 ); |
out->bv_val = (char *) ch_malloc( in->bv_len * 3 ) + 1; |
out->bv_len = 0; |
out->bv_len = 0; |
|
|
|
#undef NIBBLE |
|
#undef ESCAPE_LO |
|
#undef ESCAPE_HI |
|
#define NIBBLE(c) ((c)&0x0f) |
|
#define ESCAPE_LO(c) ( NIBBLE(c) + ( NIBBLE(c) < 10 ? '0' : 'A' - 10 ) ) |
|
#define ESCAPE_HI(c) ( ESCAPE_LO((c)>>4) ) |
|
|
for( i=0; i < in->bv_len ; i++ ) { |
for( i=0; i < in->bv_len ; i++ ) { |
if( FILTER_ESCAPE(in->bv_val[i]) ) { |
if( FILTER_ESCAPE(in->bv_val[i]) ) { |
out->bv_val[out->bv_len++] = SLAP_ESCAPE_CHAR; |
out->bv_val[out->bv_len++] = '\\'; |
out->bv_val[out->bv_len++] = SLAP_ESCAPE_HI( in->bv_val[i] ); |
out->bv_val[out->bv_len++] = ESCAPE_HI( in->bv_val[i] ); |
out->bv_val[out->bv_len++] = SLAP_ESCAPE_LO( in->bv_val[i] ); |
out->bv_val[out->bv_len++] = ESCAPE_LO( in->bv_val[i] ); |
} else { |
} else { |
out->bv_val[out->bv_len++] = in->bv_val[i]; |
out->bv_val[out->bv_len++] = in->bv_val[i]; |
} |
} |
Line 729 int filter_escape_value(
|
Line 719 int filter_escape_value(
|
out->bv_val[out->bv_len] = '\0'; |
out->bv_val[out->bv_len] = '\0'; |
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
} |
} |
|
|
|
|