version 1.5, 1998/10/27 01:07:12
|
version 1.13, 1999/07/07 16:51:39
|
Line 9
|
Line 9
|
|
|
#include "slap.h" |
#include "slap.h" |
|
|
static int get_filter_list(); |
static int get_filter_list(Connection *conn, BerElement *ber, Filter **f, char **fstr); |
static int get_substring_filter(); |
static int get_substring_filter(Connection *conn, BerElement *ber, Filter *f, char **fstr); |
|
|
extern int get_ava(); |
|
extern char *ch_malloc(); |
|
extern char *ch_realloc(); |
|
|
|
int |
int |
get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) |
get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) |
{ |
{ |
unsigned long tag, len; |
unsigned long len; |
int err; |
int err; |
Filter *f; |
Filter *f; |
char *ftmp; |
char *ftmp; |
Line 38 get_filter( Connection *conn, BerElement
|
Line 34 get_filter( Connection *conn, BerElement
|
* lessOrEqual [6] AttributeValueAssertion, |
* lessOrEqual [6] AttributeValueAssertion, |
* present [7] AttributeType,, |
* present [7] AttributeType,, |
* approxMatch [8] AttributeValueAssertion |
* approxMatch [8] AttributeValueAssertion |
|
* extensibleMatch [9] MatchingRuleAssertion |
* } |
* } |
* |
* |
* SubstringFilter ::= SEQUENCE { |
* SubstringFilter ::= SEQUENCE { |
Line 48 get_filter( Connection *conn, BerElement
|
Line 45 get_filter( Connection *conn, BerElement
|
* final [2] IA5String |
* final [2] IA5String |
* } |
* } |
* } |
* } |
|
* |
|
* MatchingRuleAssertion ::= SEQUENCE { |
|
* matchingRule [1] MatchingRuleId OPTIONAL, |
|
* type [2] AttributeDescription OPTIONAL, |
|
* matchValue [3] AssertionValue, |
|
* dnAttributes [4] BOOLEAN DEFAULT FALSE |
|
* } |
|
* |
*/ |
*/ |
|
|
f = (Filter *) ch_malloc( sizeof(Filter) ); |
f = (Filter *) ch_malloc( sizeof(Filter) ); |
*filt = f; |
|
f->f_next = NULL; |
f->f_next = NULL; |
|
|
err = 0; |
err = LDAP_SUCCESS; |
*fstr = NULL; |
*fstr = NULL; |
f->f_choice = ber_peek_tag( ber, &len ); |
f->f_choice = ber_peek_tag( ber, &len ); |
#ifdef LDAP_COMPAT30 |
|
if ( conn->c_version == 30 ) { |
|
switch ( f->f_choice ) { |
|
case LDAP_FILTER_EQUALITY: |
|
case LDAP_FILTER_GE: |
|
case LDAP_FILTER_LE: |
|
case LDAP_FILTER_PRESENT: |
|
case LDAP_FILTER_PRESENT_30: |
|
case LDAP_FILTER_APPROX: |
|
(void) ber_skip_tag( ber, &len ); |
|
if ( f->f_choice == LDAP_FILTER_PRESENT_30 ) { |
|
f->f_choice = LDAP_FILTER_PRESENT; |
|
} |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
|
#endif |
|
switch ( f->f_choice ) { |
switch ( f->f_choice ) { |
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 ); |
if ( (err = get_ava( ber, &f->f_ava )) == 0 ) { |
if ( (err = get_ava( ber, &f->f_ava )) == LDAP_SUCCESS ) { |
*fstr = ch_malloc(4 + strlen( f->f_avtype ) + |
*fstr = ch_malloc(4 + strlen( f->f_avtype ) + |
f->f_avvalue.bv_len); |
f->f_avvalue.bv_len); |
sprintf( *fstr, "(%s=%s)", f->f_avtype, |
sprintf( *fstr, "(%s=%s)", f->f_avtype, |
Line 94 get_filter( Connection *conn, BerElement
|
Line 80 get_filter( Connection *conn, BerElement
|
|
|
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 ); |
if ( (err = get_ava( ber, &f->f_ava )) == 0 ) { |
if ( (err = get_ava( ber, &f->f_ava )) == LDAP_SUCCESS ) { |
*fstr = ch_malloc(5 + strlen( f->f_avtype ) + |
*fstr = ch_malloc(5 + strlen( f->f_avtype ) + |
f->f_avvalue.bv_len); |
f->f_avvalue.bv_len); |
sprintf( *fstr, "(%s>=%s)", f->f_avtype, |
sprintf( *fstr, "(%s>=%s)", f->f_avtype, |
Line 104 get_filter( Connection *conn, BerElement
|
Line 90 get_filter( Connection *conn, BerElement
|
|
|
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 ); |
if ( (err = get_ava( ber, &f->f_ava )) == 0 ) { |
if ( (err = get_ava( ber, &f->f_ava )) == LDAP_SUCCESS ) { |
*fstr = ch_malloc(5 + strlen( f->f_avtype ) + |
*fstr = ch_malloc(5 + strlen( f->f_avtype ) + |
f->f_avvalue.bv_len); |
f->f_avvalue.bv_len); |
sprintf( *fstr, "(%s<=%s)", f->f_avtype, |
sprintf( *fstr, "(%s<=%s)", f->f_avtype, |
Line 115 get_filter( Connection *conn, BerElement
|
Line 101 get_filter( Connection *conn, BerElement
|
case LDAP_FILTER_PRESENT: |
case LDAP_FILTER_PRESENT: |
Debug( LDAP_DEBUG_FILTER, "PRESENT\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "PRESENT\n", 0, 0, 0 ); |
if ( ber_scanf( ber, "a", &f->f_type ) == LBER_ERROR ) { |
if ( ber_scanf( ber, "a", &f->f_type ) == LBER_ERROR ) { |
err = LDAP_PROTOCOL_ERROR; |
err = -1; |
} else { |
} else { |
err = LDAP_SUCCESS; |
err = LDAP_SUCCESS; |
attr_normalize( f->f_type ); |
attr_normalize( f->f_type ); |
Line 126 get_filter( Connection *conn, BerElement
|
Line 112 get_filter( Connection *conn, BerElement
|
|
|
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 ); |
if ( (err = get_ava( ber, &f->f_ava )) == 0 ) { |
if ( (err = get_ava( ber, &f->f_ava )) == LDAP_SUCCESS ) { |
*fstr = ch_malloc(5 + strlen( f->f_avtype ) + |
*fstr = ch_malloc(5 + strlen( f->f_avtype ) + |
f->f_avvalue.bv_len); |
f->f_avvalue.bv_len); |
sprintf( *fstr, "(%s~=%s)", f->f_avtype, |
sprintf( *fstr, "(%s~=%s)", f->f_avtype, |
Line 137 get_filter( Connection *conn, BerElement
|
Line 123 get_filter( Connection *conn, BerElement
|
case LDAP_FILTER_AND: |
case LDAP_FILTER_AND: |
Debug( LDAP_DEBUG_FILTER, "AND\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "AND\n", 0, 0, 0 ); |
if ( (err = get_filter_list( conn, ber, &f->f_and, &ftmp )) |
if ( (err = get_filter_list( conn, ber, &f->f_and, &ftmp )) |
== 0 ) { |
== LDAP_SUCCESS ) { |
if (ftmp == NULL) ftmp = strdup(""); |
if (ftmp == NULL) ftmp = ch_strdup(""); |
*fstr = ch_malloc( 4 + strlen( ftmp ) ); |
*fstr = ch_malloc( 4 + strlen( ftmp ) ); |
sprintf( *fstr, "(&%s)", ftmp ); |
sprintf( *fstr, "(&%s)", ftmp ); |
free( ftmp ); |
free( ftmp ); |
Line 148 get_filter( Connection *conn, BerElement
|
Line 134 get_filter( Connection *conn, BerElement
|
case LDAP_FILTER_OR: |
case LDAP_FILTER_OR: |
Debug( LDAP_DEBUG_FILTER, "OR\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "OR\n", 0, 0, 0 ); |
if ( (err = get_filter_list( conn, ber, &f->f_or, &ftmp )) |
if ( (err = get_filter_list( conn, ber, &f->f_or, &ftmp )) |
== 0 ) { |
== LDAP_SUCCESS ) { |
if (ftmp == NULL) ftmp = strdup(""); |
if (ftmp == NULL) ftmp = ch_strdup(""); |
*fstr = ch_malloc( 4 + strlen( ftmp ) ); |
*fstr = ch_malloc( 4 + strlen( ftmp ) ); |
sprintf( *fstr, "(|%s)", ftmp ); |
sprintf( *fstr, "(|%s)", ftmp ); |
free( ftmp ); |
free( ftmp ); |
Line 159 get_filter( Connection *conn, BerElement
|
Line 145 get_filter( Connection *conn, BerElement
|
case LDAP_FILTER_NOT: |
case LDAP_FILTER_NOT: |
Debug( LDAP_DEBUG_FILTER, "NOT\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "NOT\n", 0, 0, 0 ); |
(void) ber_skip_tag( ber, &len ); |
(void) ber_skip_tag( ber, &len ); |
if ( (err = get_filter( conn, ber, &f->f_not, &ftmp )) == 0 ) { |
if ( (err = get_filter( conn, ber, &f->f_not, &ftmp )) == LDAP_SUCCESS ) { |
if (ftmp == NULL) ftmp = strdup(""); |
if (ftmp == NULL) ftmp = ch_strdup(""); |
*fstr = ch_malloc( 4 + strlen( ftmp ) ); |
*fstr = ch_malloc( 4 + strlen( ftmp ) ); |
sprintf( *fstr, "(!%s)", ftmp ); |
sprintf( *fstr, "(!%s)", ftmp ); |
free( ftmp ); |
free( ftmp ); |
} |
} |
break; |
break; |
|
|
|
case LBER_DEFAULT: |
|
Debug( LDAP_DEBUG_ANY, "decoding filter error\n", |
|
0, 0, 0 ); |
|
err = -1; |
|
break; |
|
|
default: |
default: |
Debug( LDAP_DEBUG_ANY, "unknown filter type %d\n", f->f_choice, |
Debug( LDAP_DEBUG_ANY, "unknown filter type %lu\n", |
0, 0 ); |
f->f_choice, 0, 0 ); |
err = LDAP_PROTOCOL_ERROR; |
err = LDAP_PROTOCOL_ERROR; |
break; |
break; |
} |
} |
|
|
if ( err != 0 ) { |
if ( err != LDAP_SUCCESS ) { |
free( (char *) f ); |
free( (char *) f ); |
if ( *fstr != NULL ) { |
if ( *fstr != NULL ) { |
free( *fstr ); |
free( *fstr ); |
} |
} |
|
} else { |
|
*filt = f; |
} |
} |
|
|
Debug( LDAP_DEBUG_FILTER, "end get_filter %d\n", err, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "end get_filter %d\n", err, 0, 0 ); |
Line 190 get_filter_list( Connection *conn, BerEl
|
Line 184 get_filter_list( Connection *conn, BerEl
|
{ |
{ |
Filter **new; |
Filter **new; |
int err; |
int err; |
unsigned long tag, len; |
ber_tag_t tag; |
|
ber_len_t len; |
char *last, *ftmp; |
char *last, *ftmp; |
|
|
Debug( LDAP_DEBUG_FILTER, "begin get_filter_list\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "begin get_filter_list\n", 0, 0, 0 ); |
|
|
#ifdef LDAP_COMPAT30 |
|
if ( conn->c_version == 30 ) { |
|
(void) ber_skip_tag( ber, &len ); |
|
} |
|
#endif |
|
*fstr = NULL; |
*fstr = NULL; |
new = f; |
new = f; |
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 ) ) |
if ( (err = get_filter( conn, ber, new, &ftmp )) != 0 ) |
{ |
|
if ( (err = get_filter( conn, ber, new, &ftmp )) != LDAP_SUCCESS ) |
return( err ); |
return( err ); |
if ( *fstr == NULL ) { |
if ( *fstr == NULL ) { |
*fstr = ftmp; |
*fstr = ftmp; |
Line 219 get_filter_list( Connection *conn, BerEl
|
Line 210 get_filter_list( Connection *conn, BerEl
|
*new = NULL; |
*new = NULL; |
|
|
Debug( LDAP_DEBUG_FILTER, "end get_filter_list\n", 0, 0, 0 ); |
Debug( LDAP_DEBUG_FILTER, "end get_filter_list\n", 0, 0, 0 ); |
return( 0 ); |
return( LDAP_SUCCESS ); |
} |
} |
|
|
static int |
static int |
Line 230 get_substring_filter(
|
Line 221 get_substring_filter(
|
char **fstr |
char **fstr |
) |
) |
{ |
{ |
unsigned long tag, len, rc; |
ber_tag_t tag; |
|
ber_len_t len; |
|
ber_tag_t rc; |
char *val, *last; |
char *val, *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 ); |
|
|
#ifdef LDAP_COMPAT30 |
if ( ber_scanf( ber, "{a" /*}*/, &f->f_sub_type ) == LBER_ERROR ) { |
if ( conn->c_version == 30 ) { |
return( -1 ); |
(void) ber_skip_tag( ber, &len ); |
|
} |
|
#endif |
|
if ( ber_scanf( ber, "{a", &f->f_sub_type ) == LBER_ERROR ) { |
|
return( LDAP_PROTOCOL_ERROR ); |
|
} |
} |
attr_normalize( f->f_sub_type ); |
attr_normalize( f->f_sub_type ); |
syntax = attr_syntax( f->f_sub_type ); |
syntax = attr_syntax( f->f_sub_type ); |
Line 253 get_substring_filter(
|
Line 241 get_substring_filter(
|
*fstr = ch_malloc( strlen( f->f_sub_type ) + 3 ); |
*fstr = ch_malloc( strlen( f->f_sub_type ) + 3 ); |
sprintf( *fstr, "(%s=", f->f_sub_type ); |
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 ) ) |
#ifdef LDAP_COMPAT30 |
{ |
if ( conn->c_version == 30 ) { |
rc = ber_scanf( ber, "a", &val ); |
rc = ber_scanf( ber, "{a}", &val ); |
|
} else |
|
#endif |
|
rc = ber_scanf( ber, "a", &val ); |
|
if ( rc == LBER_ERROR ) { |
if ( rc == LBER_ERROR ) { |
return( LDAP_PROTOCOL_ERROR ); |
return( -1 ); |
} |
} |
if ( val == NULL || *val == '\0' ) { |
if ( val == NULL || *val == '\0' ) { |
if ( val != NULL ) { |
if ( val != NULL ) { |
Line 272 get_substring_filter(
|
Line 256 get_substring_filter(
|
value_normalize( val, syntax ); |
value_normalize( val, syntax ); |
|
|
switch ( tag ) { |
switch ( tag ) { |
#ifdef LDAP_COMPAT30 |
|
case LDAP_SUBSTRING_INITIAL_30: |
|
#endif |
|
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 ) { |
Line 286 get_substring_filter(
|
Line 267 get_substring_filter(
|
strcat( *fstr, val ); |
strcat( *fstr, val ); |
break; |
break; |
|
|
#ifdef LDAP_COMPAT30 |
|
case LDAP_SUBSTRING_ANY_30: |
|
#endif |
|
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( &f->f_sub_any, val ); |
Line 298 get_substring_filter(
|
Line 276 get_substring_filter(
|
strcat( *fstr, val ); |
strcat( *fstr, val ); |
break; |
break; |
|
|
#ifdef LDAP_COMPAT30 |
|
case LDAP_SUBSTRING_FINAL_30: |
|
#endif |
|
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 ) { |
Line 326 get_substring_filter(
|
Line 301 get_substring_filter(
|
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( 0 ); |
return( LDAP_SUCCESS ); |
} |
} |
|
|
void |
void |
Line 375 filter_free( Filter *f )
|
Line 350 filter_free( Filter *f )
|
break; |
break; |
|
|
default: |
default: |
Debug( LDAP_DEBUG_ANY, "unknown filter type %d\n", f->f_choice, |
Debug( LDAP_DEBUG_ANY, "unknown filter type %lu\n", |
0, 0 ); |
f->f_choice, 0, 0 ); |
break; |
break; |
} |
} |
free( f ); |
free( f ); |
Line 447 filter_print( Filter *f )
|
Line 422 filter_print( Filter *f )
|
break; |
break; |
|
|
default: |
default: |
fprintf( stderr, "unknown type %d", f->f_choice ); |
fprintf( stderr, "unknown type %lu", f->f_choice ); |
break; |
break; |
} |
} |
} |
} |