version 1.14, 1999/08/02 03:29:35
|
version 1.19, 2000/01/28 19:01:00
|
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.18 2000/01/27 23:33:29 kurt Exp $ */ |
|
/* |
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. |
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file |
|
*/ |
|
|
#include "portable.h" |
#include "portable.h" |
|
|
Line 224 get_substring_filter(
|
Line 229 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; |
char *val, *last; |
struct berval *val; |
|
char *last; |
int syntax; |
int syntax; |
|
|
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 232 get_substring_filter(
|
Line 238 get_substring_filter(
|
if ( ber_scanf( ber, "{a" /*}*/, &f->f_sub_type ) == LBER_ERROR ) { |
if ( ber_scanf( ber, "{a" /*}*/, &f->f_sub_type ) == LBER_ERROR ) { |
return( -1 ); |
return( -1 ); |
} |
} |
|
|
attr_normalize( f->f_sub_type ); |
attr_normalize( f->f_sub_type ); |
|
|
|
#ifdef SLAPD_SCHEMA_COMPAT |
|
/* should get real syntax and see if we have a substring matching rule */ |
syntax = attr_syntax( f->f_sub_type ); |
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; |
|
|
*fstr = ch_malloc( strlen( f->f_sub_type ) + 3 ); |
if( fstr ) { |
sprintf( *fstr, "(%s=", f->f_sub_type ); |
*fstr = ch_malloc( strlen( f->f_sub_type ) + 3 ); |
|
sprintf( *fstr, "(%s=", f->f_sub_type ); |
|
} |
|
|
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 ) ) |
{ |
{ |
rc = ber_scanf( ber, "a", &val ); |
rc = ber_scanf( ber, "O", &val ); |
if ( rc == LBER_ERROR ) { |
if ( rc == LBER_ERROR ) { |
return( -1 ); |
rc = -1; |
} |
goto return_error; |
if ( val == NULL || *val == '\0' ) { |
|
if ( val != NULL ) { |
|
free( val ); |
|
} |
|
return( LDAP_INVALID_SYNTAX ); |
|
} |
} |
value_normalize( val, syntax ); |
|
|
if ( val == NULL || val->bv_len == 0 ) { |
|
ber_bvfree( val ); |
|
rc = LDAP_INVALID_SYNTAX; |
|
goto return_error; |
|
} |
|
|
|
rc = LDAP_PROTOCOL_ERROR; |
|
|
|
#ifdef SLAPD_SCHEMA_COMPAT |
|
/* we should call a substring syntax normalization routine */ |
|
value_normalize( val->bv_val, syntax ); |
|
#endif |
|
|
|
/* this is bogus, value_normalize should take a berval */ |
|
val->bv_len = strlen( val->bv_val ); |
|
|
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 ) { |
return( LDAP_PROTOCOL_ERROR ); |
ber_bvfree( val ); |
|
goto return_error; |
} |
} |
f->f_sub_initial = val; |
f->f_sub_initial = val; |
*fstr = ch_realloc( *fstr, strlen( *fstr ) + |
|
strlen( val ) + 1 ); |
if( fstr ) { |
strcat( *fstr, val ); |
*fstr = ch_realloc( *fstr, |
|
strlen( *fstr ) + val->bv_len + 1 ); |
|
strcat( *fstr, val->bv_val ); |
|
} |
break; |
break; |
|
|
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 ); |
charray_add( &f->f_sub_any, val ); |
charray_add( (char ***) &f->f_sub_any, (char *) val ); |
*fstr = ch_realloc( *fstr, strlen( *fstr ) + |
|
strlen( val ) + 2 ); |
if( fstr ) { |
strcat( *fstr, "*" ); |
*fstr = ch_realloc( *fstr, |
strcat( *fstr, val ); |
strlen( *fstr ) + val->bv_len + 2 ); |
|
strcat( *fstr, "*" ); |
|
strcat( *fstr, val->bv_val ); |
|
} |
break; |
break; |
|
|
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 ) { |
return( LDAP_PROTOCOL_ERROR ); |
ber_bvfree( val ); |
|
goto return_error; |
} |
} |
f->f_sub_final = val; |
f->f_sub_final = val; |
*fstr = ch_realloc( *fstr, strlen( *fstr ) + |
|
strlen( val ) + 2 ); |
if( fstr ) { |
strcat( *fstr, "*" ); |
*fstr = ch_realloc( *fstr, |
strcat( *fstr, val ); |
strlen( *fstr ) + val->bv_len + 2 ); |
|
strcat( *fstr, "*" ); |
|
strcat( *fstr, val->bv_val ); |
|
} |
break; |
break; |
|
|
default: |
default: |
Debug( LDAP_DEBUG_FILTER, " unknown type\n", tag, 0, |
Debug( LDAP_DEBUG_FILTER, " unknown type\n", tag, 0, |
0 ); |
0 ); |
return( LDAP_PROTOCOL_ERROR ); |
|
|
ber_bvfree( val ); |
|
|
|
return_error: |
|
Debug( LDAP_DEBUG_FILTER, " error=%d\n", rc, 0, 0 ); |
|
|
|
if( fstr ) { |
|
free( *fstr ); |
|
*fstr = NULL; |
|
} |
|
|
|
ch_free( f->f_sub_type ); |
|
ber_bvfree( f->f_sub_initial ); |
|
ber_bvecfree( f->f_sub_any ); |
|
ber_bvfree( f->f_sub_final ); |
|
return rc; |
} |
} |
} |
} |
*fstr = ch_realloc( *fstr, strlen( *fstr ) + 3 ); |
|
if ( f->f_sub_final == NULL ) { |
if( fstr ) { |
strcat( *fstr, "*" ); |
*fstr = ch_realloc( *fstr, strlen( *fstr ) + 3 ); |
|
if ( f->f_sub_final == NULL ) { |
|
strcat( *fstr, "*" ); |
|
} |
|
strcat( *fstr, ")" ); |
} |
} |
strcat( *fstr, ")" ); |
|
|
|
Debug( LDAP_DEBUG_FILTER, "end get_substring_filter\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "end get_substring_filter\n", 0, 0, 0 ); |
return( LDAP_SUCCESS ); |
return( LDAP_SUCCESS ); |
Line 326 filter_free( Filter *f )
|
Line 380 filter_free( Filter *f )
|
free( f->f_sub_type ); |
free( f->f_sub_type ); |
} |
} |
if ( f->f_sub_initial != NULL ) { |
if ( f->f_sub_initial != NULL ) { |
free( f->f_sub_initial ); |
ber_bvfree( f->f_sub_initial ); |
} |
} |
charray_free( f->f_sub_any ); |
ber_bvecfree( f->f_sub_any ); |
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final != NULL ) { |
free( f->f_sub_final ); |
ber_bvfree( f->f_sub_final ); |
} |
} |
break; |
break; |
|
|
Line 393 filter_print( Filter *f )
|
Line 447 filter_print( Filter *f )
|
case LDAP_FILTER_SUBSTRINGS: |
case LDAP_FILTER_SUBSTRINGS: |
fprintf( stderr, "(%s=", f->f_sub_type ); |
fprintf( stderr, "(%s=", f->f_sub_type ); |
if ( f->f_sub_initial != NULL ) { |
if ( f->f_sub_initial != NULL ) { |
fprintf( stderr, "%s", f->f_sub_initial ); |
fprintf( stderr, "%s", f->f_sub_initial->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++ ) { |
fprintf( stderr, "*%s", f->f_sub_any[i] ); |
fprintf( stderr, "*%s", f->f_sub_any[i]->bv_val ); |
} |
} |
} |
} |
charray_free( f->f_sub_any ); |
|
if ( f->f_sub_final != NULL ) { |
if ( f->f_sub_final != NULL ) { |
fprintf( stderr, "*%s", f->f_sub_final ); |
fprintf( stderr, "*%s", f->f_sub_final->bv_val ); |
} |
} |
break; |
break; |
|
|