version 1.66, 2001/12/26 12:47:10
|
version 1.67, 2001/12/29 14:01:10
|
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.65 2001/12/24 05:36:45 kurt Exp $ */ |
/* $OpenLDAP: pkg/ldap/servers/slapd/filter.c,v 1.66 2001/12/26 12:47:10 hyc 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 115 get_filter(
|
Line 115 get_filter(
|
|
|
assert( f->f_ava != NULL ); |
assert( f->f_ava != NULL ); |
|
|
filter_escape_value( f->f_av_value, &escaped ); |
filter_escape_value( &f->f_av_value, &escaped ); |
|
|
fstr->bv_len = sizeof("(=)")-1 |
fstr->bv_len = sizeof("(=)")-1 |
+ f->f_av_desc->ad_cname.bv_len |
+ f->f_av_desc->ad_cname.bv_len |
Line 152 get_filter(
|
Line 152 get_filter(
|
break; |
break; |
} |
} |
|
|
filter_escape_value( f->f_av_value, &escaped ); |
filter_escape_value( &f->f_av_value, &escaped ); |
|
|
fstr->bv_len = sizeof("(>=)")-1 |
fstr->bv_len = sizeof("(>=)")-1 |
+ f->f_av_desc->ad_cname.bv_len |
+ f->f_av_desc->ad_cname.bv_len |
Line 180 get_filter(
|
Line 180 get_filter(
|
} |
} |
|
|
|
|
filter_escape_value( f->f_av_value, &escaped ); |
filter_escape_value( &f->f_av_value, &escaped ); |
|
|
fstr->bv_len = sizeof("(<=)")-1 |
fstr->bv_len = sizeof("(<=)")-1 |
+ f->f_av_desc->ad_cname.bv_len |
+ f->f_av_desc->ad_cname.bv_len |
Line 246 get_filter(
|
Line 246 get_filter(
|
break; |
break; |
} |
} |
|
|
filter_escape_value( f->f_av_value, &escaped ); |
filter_escape_value( &f->f_av_value, &escaped ); |
|
|
fstr->bv_len = sizeof("(~=)") - 1 |
fstr->bv_len = sizeof("(~=)") - 1 |
+ f->f_av_desc->ad_cname.bv_len |
+ f->f_av_desc->ad_cname.bv_len |
Line 327 get_filter(
|
Line 327 get_filter(
|
|
|
assert( f->f_mra != NULL ); |
assert( f->f_mra != NULL ); |
|
|
filter_escape_value( f->f_mr_value, &escaped ); |
filter_escape_value( &f->f_mr_value, &escaped ); |
|
|
fstr->bv_len = sizeof("(:dn::=)") - 1 |
fstr->bv_len = sizeof("(:dn::=)") - 1 |
+ (f->f_mr_desc ? f->f_mr_desc->ad_cname.bv_len : 0) |
+ (f->f_mr_desc ? f->f_mr_desc->ad_cname.bv_len : 0) |
Line 455 get_substring_filter(
|
Line 455 get_substring_filter(
|
ber_tag_t tag; |
ber_tag_t tag; |
ber_len_t len; |
ber_len_t len; |
ber_tag_t rc; |
ber_tag_t rc; |
struct berval *value; |
struct berval value; |
struct berval escaped; |
struct berval escaped; |
char *last; |
char *last; |
struct berval type; |
struct berval bv; |
struct berval *nvalue; |
|
*text = "error decoding filter"; |
*text = "error decoding filter"; |
|
|
#ifdef NEW_LOGGING |
#ifdef NEW_LOGGING |
Line 468 get_substring_filter(
|
Line 467 get_substring_filter(
|
#else |
#else |
Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 ); |
#endif |
#endif |
if ( ber_scanf( ber, "{o" /*}*/, &type ) == LBER_ERROR ) { |
if ( ber_scanf( ber, "{o" /*}*/, &bv ) == LBER_ERROR ) { |
return SLAPD_DISCONNECT; |
return SLAPD_DISCONNECT; |
} |
} |
|
|
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( &bv, &f->f_sub_desc, text ); |
|
|
ch_free( type.bv_val ); |
ch_free( bv.bv_val ); |
|
|
if( rc != LDAP_SUCCESS ) { |
if( rc != LDAP_SUCCESS ) { |
text = NULL; |
text = NULL; |
Line 487 get_substring_filter(
|
Line 486 get_substring_filter(
|
return LDAP_SUCCESS; |
return LDAP_SUCCESS; |
} |
} |
|
|
f->f_sub_initial = NULL; |
f->f_sub_initial.bv_val = NULL; |
f->f_sub_any = NULL; |
f->f_sub_any = NULL; |
f->f_sub_final = NULL; |
f->f_sub_final.bv_val = NULL; |
|
|
fstr->bv_len = sizeof("(=" /*)*/) - 1 + |
fstr->bv_len = sizeof("(=" /*)*/) - 1 + |
f->f_sub_desc->ad_cname.bv_len; |
f->f_sub_desc->ad_cname.bv_len; |
Line 501 get_substring_filter(
|
Line 500 get_substring_filter(
|
{ |
{ |
unsigned usage; |
unsigned usage; |
|
|
rc = ber_scanf( ber, "O", &value ); |
rc = ber_scanf( ber, "o", &value ); |
if ( rc == LBER_ERROR ) { |
if ( rc == LBER_ERROR ) { |
rc = SLAPD_DISCONNECT; |
rc = SLAPD_DISCONNECT; |
goto return_error; |
goto return_error; |
} |
} |
|
|
if ( value == NULL || value->bv_len == 0 ) { |
if ( value.bv_val == NULL || value.bv_len == 0 ) { |
ber_bvfree( value ); |
|
rc = LDAP_INVALID_SYNTAX; |
rc = LDAP_INVALID_SYNTAX; |
goto return_error; |
goto return_error; |
} |
} |
Line 538 get_substring_filter(
|
Line 536 get_substring_filter(
|
" unknown substring choice=%ld\n", |
" unknown substring choice=%ld\n", |
(long) tag, 0, 0 ); |
(long) tag, 0, 0 ); |
#endif |
#endif |
ber_bvfree( value ); |
free( value.bv_val ); |
goto return_error; |
goto return_error; |
} |
} |
|
|
rc = value_normalize( f->f_sub_desc, usage, value, &nvalue, text ); |
rc = value_normalize( f->f_sub_desc, usage, &value, &bv, text ); |
ber_bvfree( value ); |
free( value.bv_val ); |
|
|
if( rc != LDAP_SUCCESS ) { |
if( rc != LDAP_SUCCESS ) { |
goto return_error; |
goto return_error; |
} |
} |
|
|
value = nvalue; |
value = bv; |
|
|
rc = LDAP_PROTOCOL_ERROR; |
rc = LDAP_PROTOCOL_ERROR; |
|
|
Line 563 get_substring_filter(
|
Line 561 get_substring_filter(
|
Debug( LDAP_DEBUG_FILTER, " INITIAL\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, " INITIAL\n", 0, 0, 0 ); |
#endif |
#endif |
|
|
if ( f->f_sub_initial != NULL |
if ( f->f_sub_initial.bv_val != NULL |
|| f->f_sub_any != NULL |
|| f->f_sub_any != NULL |
|| f->f_sub_final != NULL ) |
|| f->f_sub_final.bv_val != NULL ) |
{ |
{ |
ber_bvfree( value ); |
free( value.bv_val ); |
goto return_error; |
goto return_error; |
} |
} |
|
|
Line 575 get_substring_filter(
|
Line 573 get_substring_filter(
|
|
|
if( fstr->bv_val ) { |
if( fstr->bv_val ) { |
int i = fstr->bv_len; |
int i = fstr->bv_len; |
filter_escape_value( value, &escaped ); |
filter_escape_value( &value, &escaped ); |
fstr->bv_len += escaped.bv_len; |
fstr->bv_len += escaped.bv_len; |
fstr->bv_val = ch_realloc( fstr->bv_val, |
fstr->bv_val = ch_realloc( fstr->bv_val, |
fstr->bv_len + 1 ); |
fstr->bv_len + 1 ); |
Line 593 get_substring_filter(
|
Line 591 get_substring_filter(
|
Debug( LDAP_DEBUG_FILTER, " ANY\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, " ANY\n", 0, 0, 0 ); |
#endif |
#endif |
|
|
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final.bv_val != NULL ) { |
ber_bvfree( value ); |
free( value.bv_val ); |
goto return_error; |
goto return_error; |
} |
} |
|
|
if( ber_bvecadd( &f->f_sub_any, value ) < 0 ) { |
bvarray_add( &f->f_sub_any, &value ); |
ber_bvfree( value ); |
|
goto return_error; |
|
} |
|
|
|
if( fstr->bv_val ) { |
if( fstr->bv_val ) { |
int i = fstr->bv_len; |
int i = fstr->bv_len; |
filter_escape_value( value, &escaped ); |
filter_escape_value( &value, &escaped ); |
fstr->bv_len += escaped.bv_len + 2; |
fstr->bv_len += escaped.bv_len + 2; |
fstr->bv_val = ch_realloc( fstr->bv_val, |
fstr->bv_val = ch_realloc( fstr->bv_val, |
fstr->bv_len + 1 ); |
fstr->bv_len + 1 ); |
Line 624 get_substring_filter(
|
Line 619 get_substring_filter(
|
Debug( LDAP_DEBUG_FILTER, " FINAL\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, " FINAL\n", 0, 0, 0 ); |
#endif |
#endif |
|
|
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final.bv_val != NULL ) { |
ber_bvfree( value ); |
free( value.bv_val ); |
goto return_error; |
goto return_error; |
} |
} |
|
|
Line 633 get_substring_filter(
|
Line 628 get_substring_filter(
|
|
|
if( fstr->bv_val ) { |
if( fstr->bv_val ) { |
int i = fstr->bv_len; |
int i = fstr->bv_len; |
filter_escape_value( value, &escaped ); |
filter_escape_value( &value, &escaped ); |
fstr->bv_len += escaped.bv_len + 2; |
fstr->bv_len += escaped.bv_len + 2; |
fstr->bv_val = ch_realloc( fstr->bv_val, |
fstr->bv_val = ch_realloc( fstr->bv_val, |
fstr->bv_len + 1 ); |
fstr->bv_len + 1 ); |
Line 654 get_substring_filter(
|
Line 649 get_substring_filter(
|
(long) tag, 0, 0 ); |
(long) tag, 0, 0 ); |
#endif |
#endif |
|
|
ber_bvfree( value ); |
free( value.bv_val ); |
|
|
return_error: |
return_error: |
#ifdef NEW_LOGGING |
#ifdef NEW_LOGGING |
Line 671 return_error:
|
Line 666 return_error:
|
fstr->bv_len = 0; |
fstr->bv_len = 0; |
} |
} |
|
|
ber_bvfree( f->f_sub_initial ); |
free( f->f_sub_initial.bv_val ); |
ber_bvecfree( f->f_sub_any ); |
bvarray_free( f->f_sub_any ); |
ber_bvfree( f->f_sub_final ); |
free( f->f_sub_final.bv_val ); |
ch_free( f->f_sub ); |
ch_free( f->f_sub ); |
return rc; |
return rc; |
} |
} |
Line 683 return_error:
|
Line 678 return_error:
|
int i = fstr->bv_len; |
int i = fstr->bv_len; |
fstr->bv_len += 3; |
fstr->bv_len += 3; |
fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 3 ); |
fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 3 ); |
if ( f->f_sub_final == NULL ) { |
if ( f->f_sub_final.bv_val == NULL ) { |
strcpy( fstr->bv_val+i, "*" ); |
strcpy( fstr->bv_val+i, "*" ); |
i++; |
i++; |
} |
} |
Line 720 filter_free( Filter *f )
|
Line 715 filter_free( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_SUBSTRINGS: |
case LDAP_FILTER_SUBSTRINGS: |
if ( f->f_sub_initial != NULL ) { |
if ( f->f_sub_initial.bv_val != NULL ) { |
ber_bvfree( f->f_sub_initial ); |
free( f->f_sub_initial.bv_val ); |
} |
} |
ber_bvecfree( f->f_sub_any ); |
bvarray_free( f->f_sub_any ); |
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final.bv_val != NULL ) { |
ber_bvfree( f->f_sub_final ); |
free( f->f_sub_final.bv_val ); |
} |
} |
ch_free( f->f_sub ); |
ch_free( f->f_sub ); |
break; |
break; |
Line 770 filter_print( Filter *f )
|
Line 765 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 ); |
filter_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 778 filter_print( Filter *f )
|
Line 773 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_GE: |
case LDAP_FILTER_GE: |
filter_escape_value( f->f_av_value, &escaped ); |
filter_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 786 filter_print( Filter *f )
|
Line 781 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_LE: |
case LDAP_FILTER_LE: |
filter_escape_value( f->f_av_value, &escaped ); |
filter_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 794 filter_print( Filter *f )
|
Line 789 filter_print( Filter *f )
|
break; |
break; |
|
|
case LDAP_FILTER_APPROX: |
case LDAP_FILTER_APPROX: |
filter_escape_value( f->f_av_value, &escaped ); |
filter_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 804 filter_print( Filter *f )
|
Line 799 filter_print( Filter *f )
|
case LDAP_FILTER_SUBSTRINGS: |
case LDAP_FILTER_SUBSTRINGS: |
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.bv_val != NULL ) { |
filter_escape_value( f->f_sub_initial, &escaped ); |
filter_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].bv_val != NULL; i++ ) { |
filter_escape_value( f->f_sub_any[i], &escaped ); |
filter_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.bv_val != NULL ) { |
filter_escape_value( f->f_sub_final, &escaped ); |
filter_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 ); |