Commit 4eebecb4 authored by Julio Sánchez Fernández's avatar Julio Sánchez Fernández
Browse files

Defer normalization to later stages.

parent 55270ce9
...@@ -34,7 +34,6 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -34,7 +34,6 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
* 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 {
...@@ -45,27 +44,37 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -45,27 +44,37 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
* 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) );
f->f_next = NULL; f->f_next = NULL;
err = LDAP_SUCCESS; err = 0;
*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 )) == LDAP_SUCCESS ) { if ( (err = get_ava( ber, &f->f_ava )) == 0 ) {
*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,
...@@ -80,7 +89,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -80,7 +89,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 )) == LDAP_SUCCESS ) { if ( (err = get_ava( ber, &f->f_ava )) == 0 ) {
*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,
...@@ -90,7 +99,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -90,7 +99,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 )) == LDAP_SUCCESS ) { if ( (err = get_ava( ber, &f->f_ava )) == 0 ) {
*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,
...@@ -101,7 +110,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -101,7 +110,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 = -1; err = LDAP_PROTOCOL_ERROR;
} else { } else {
err = LDAP_SUCCESS; err = LDAP_SUCCESS;
attr_normalize( f->f_type ); attr_normalize( f->f_type );
...@@ -112,7 +121,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -112,7 +121,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 )) == LDAP_SUCCESS ) { if ( (err = get_ava( ber, &f->f_ava )) == 0 ) {
*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,
...@@ -123,7 +132,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -123,7 +132,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 ))
== LDAP_SUCCESS ) { == 0 ) {
if (ftmp == NULL) ftmp = ch_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 );
...@@ -134,7 +143,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -134,7 +143,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 ))
== LDAP_SUCCESS ) { == 0 ) {
if (ftmp == NULL) ftmp = ch_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 );
...@@ -145,7 +154,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -145,7 +154,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
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 )) == LDAP_SUCCESS ) { if ( (err = get_filter( conn, ber, &f->f_not, &ftmp )) == 0 ) {
if (ftmp == NULL) ftmp = ch_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 );
...@@ -153,12 +162,6 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -153,12 +162,6 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
} }
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 %lu\n", Debug( LDAP_DEBUG_ANY, "unknown filter type %lu\n",
f->f_choice, 0, 0 ); f->f_choice, 0, 0 );
...@@ -166,7 +169,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr ) ...@@ -166,7 +169,7 @@ get_filter( Connection *conn, BerElement *ber, Filter **filt, char **fstr )
break; break;
} }
if ( err != LDAP_SUCCESS ) { if ( err != 0 ) {
free( (char *) f ); free( (char *) f );
if ( *fstr != NULL ) { if ( *fstr != NULL ) {
free( *fstr ); free( *fstr );
...@@ -190,12 +193,16 @@ get_filter_list( Connection *conn, BerElement *ber, Filter **f, char **fstr ) ...@@ -190,12 +193,16 @@ get_filter_list( Connection *conn, BerElement *ber, Filter **f, char **fstr )
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;
...@@ -210,7 +217,7 @@ get_filter_list( Connection *conn, BerElement *ber, Filter **f, char **fstr ) ...@@ -210,7 +217,7 @@ get_filter_list( Connection *conn, BerElement *ber, Filter **f, char **fstr )
*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( LDAP_SUCCESS ); return( 0 );
} }
static int static int
...@@ -225,15 +232,17 @@ get_substring_filter( ...@@ -225,15 +232,17 @@ get_substring_filter(
ber_len_t len; ber_len_t len;
ber_tag_t rc; ber_tag_t rc;
char *val, *last; char *val, *last;
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 ( conn->c_version == 30 ) {
(void) ber_skip_tag( ber, &len );
}
#endif
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( LDAP_PROTOCOL_ERROR );
} }
attr_normalize( f->f_sub_type );
syntax = attr_syntax( f->f_sub_type );
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;
...@@ -241,11 +250,15 @@ get_substring_filter( ...@@ -241,11 +250,15 @@ 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
rc = ber_scanf( ber, "a", &val ); if ( conn->c_version == 30 ) {
rc = ber_scanf( ber, "{a}", &val );
} else
#endif
rc = ber_scanf( ber, "a", &val );
if ( rc == LBER_ERROR ) { if ( rc == LBER_ERROR ) {
return( -1 ); return( LDAP_PROTOCOL_ERROR );
} }
if ( val == NULL || *val == '\0' ) { if ( val == NULL || *val == '\0' ) {
if ( val != NULL ) { if ( val != NULL ) {
...@@ -253,9 +266,11 @@ get_substring_filter( ...@@ -253,9 +266,11 @@ get_substring_filter(
} }
return( LDAP_INVALID_SYNTAX ); return( LDAP_INVALID_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 ) {
...@@ -267,6 +282,9 @@ get_substring_filter( ...@@ -267,6 +282,9 @@ 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 );
...@@ -276,6 +294,9 @@ get_substring_filter( ...@@ -276,6 +294,9 @@ 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 ) {
...@@ -301,7 +322,7 @@ get_substring_filter( ...@@ -301,7 +322,7 @@ 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( LDAP_SUCCESS ); return( 0 );
} }
void void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment