]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/filter.c
Skip over unsupported tags
[openldap] / servers / slapd / filter.c
index dc8e0201ada8be0796ebdb6bc655b2270e56cd04..6af8f867c76da075319c48a8253114710ab9eade 100644 (file)
@@ -19,13 +19,14 @@ static int  get_filter_list(
        BerElement *ber,
        Filter **f,
        char **fstr,
-       char **text );
+       const char **text );
+
 static int     get_substring_filter(
        Connection *conn,
        BerElement *ber,
        Filter *f,
        char **fstr,
-       char **text );
+       const char **text );
 
 int
 get_filter(
@@ -33,7 +34,7 @@ get_filter(
        BerElement *ber,
        Filter **filt,
        char **fstr,
-       char **text )
+       const char **text )
 {
        ber_tag_t       tag;
        ber_len_t       len;
@@ -94,16 +95,11 @@ get_filter(
        case LDAP_FILTER_EQUALITY:
                Debug( LDAP_DEBUG_FILTER, "EQUALITY\n", 0, 0, 0 );
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                err = get_ava( ber, &f->f_ava, SLAP_MR_EQUALITY, text );
-#else
-               err = get_ava( ber, &f->f_ava, text );
-#endif
                if ( err != LDAP_SUCCESS ) {
                        break;
                }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                assert( f->f_ava != NULL );
 
                *fstr = ch_malloc( sizeof("(=)")
@@ -114,13 +110,6 @@ get_filter(
                        f->f_av_desc->ad_cname->bv_val,
                    f->f_av_value->bv_val );
 
-#else
-               *fstr = ch_malloc( sizeof("(=)")
-                       + strlen( f->f_avtype )
-                       + f->f_avvalue.bv_len);
-               sprintf( *fstr, "(%s=%s)", f->f_avtype,
-                   f->f_avvalue.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_SUBSTRINGS:
@@ -131,16 +120,11 @@ get_filter(
        case LDAP_FILTER_GE:
                Debug( LDAP_DEBUG_FILTER, "GE\n", 0, 0, 0 );
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                err = get_ava( ber, &f->f_ava, SLAP_MR_ORDERING, text );
-#else
-               err = get_ava( ber, &f->f_ava, text );
-#endif
                if ( err != LDAP_SUCCESS ) {
                        break;
                }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                *fstr = ch_malloc( sizeof("(>=)")
                        + f->f_av_desc->ad_cname->bv_len
                        + f->f_av_value->bv_len );
@@ -149,29 +133,17 @@ get_filter(
                        f->f_av_desc->ad_cname->bv_val,
                    f->f_av_value->bv_val );
 
-#else
-               *fstr = ch_malloc( sizeof("(>=)")
-                       + strlen( f->f_avtype )
-                       + f->f_avvalue.bv_len);
-               sprintf( *fstr, "(%s>=%s)", f->f_avtype,
-                   f->f_avvalue.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_LE:
                Debug( LDAP_DEBUG_FILTER, "LE\n", 0, 0, 0 );
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                err = get_ava( ber, &f->f_ava, SLAP_MR_ORDERING, text );
-#else
-               err = get_ava( ber, &f->f_ava, text );
-#endif
                if ( err != LDAP_SUCCESS ) {
                        break;
                }
 
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                *fstr = ch_malloc( sizeof("(<=)")
                        + f->f_av_desc->ad_cname->bv_len
                        + f->f_av_value->bv_len );
@@ -180,13 +152,6 @@ get_filter(
                        f->f_av_desc->ad_cname->bv_val,
                    f->f_av_value->bv_val );
 
-#else
-               *fstr = ch_malloc( sizeof("(<=)")
-                       + strlen( f->f_avtype )
-                       + f->f_avvalue.bv_len);
-               sprintf( *fstr, "(%s<=%s)", f->f_avtype,
-                   f->f_avvalue.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_PRESENT: {
@@ -200,7 +165,6 @@ get_filter(
                        break;
                }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                f->f_desc = NULL;
                err = slap_bv2ad( &type, &f->f_desc, text );
 
@@ -216,29 +180,16 @@ get_filter(
                sprintf( *fstr, "(%s=*)",
                        f->f_desc->ad_cname->bv_val );
 
-#else
-               f->f_type = type.bv_val;
-               err = LDAP_SUCCESS;
-               attr_normalize( f->f_type );
-               *fstr = ch_malloc( sizeof("(=*)")
-                       + strlen( f->f_type ) );
-               sprintf( *fstr, "(%s=*)", f->f_type );
-#endif
                } break;
 
        case LDAP_FILTER_APPROX:
                Debug( LDAP_DEBUG_FILTER, "APPROX\n", 0, 0, 0 );
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                err = get_ava( ber, &f->f_ava, SLAP_MR_EQUALITY_APPROX, text );
-#else
-               err = get_ava( ber, &f->f_ava, text );
-#endif
                if ( err != LDAP_SUCCESS ) {
                        break;
                }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                *fstr = ch_malloc( sizeof("(~=)")
                        + f->f_av_desc->ad_cname->bv_len
                        + f->f_av_value->bv_len );
@@ -247,13 +198,6 @@ get_filter(
                        f->f_av_desc->ad_cname->bv_val,
                    f->f_av_value->bv_val );
 
-#else
-               *fstr = ch_malloc( sizeof("(~=)")
-                       + strlen( f->f_avtype )
-                       + f->f_avvalue.bv_len);
-               sprintf( *fstr, "(%s~=%s)", f->f_avtype,
-                   f->f_avvalue.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_AND:
@@ -297,12 +241,14 @@ get_filter(
                /* not yet implemented */
                Debug( LDAP_DEBUG_ANY, "extensible match not yet implemented.\n",
                       f->f_choice, 0, 0 );
+               (void) ber_skip_tag( ber, &len );
                f->f_choice = SLAPD_FILTER_COMPUTED;
                f->f_result = SLAPD_COMPARE_UNDEFINED;
                *fstr = ch_strdup( "(extended)" );
                break;
 
        default:
+               (void) ber_skip_tag( ber, &len );
                Debug( LDAP_DEBUG_ANY, "get_filter: unknown filter type=%lu\n",
                       f->f_choice, 0, 0 );
                f->f_choice = SLAPD_FILTER_COMPUTED;
@@ -311,23 +257,36 @@ get_filter(
                break;
        }
 
+       free( ftmp );
+
        if ( err != LDAP_SUCCESS ) {
-               free( (char *) f );
                if ( *fstr != NULL ) {
                        free( *fstr );
                }
+
+               if( err != SLAPD_DISCONNECT ) {
+                       /* ignore error */
+                       f->f_choice = SLAPD_FILTER_COMPUTED;
+                       f->f_result = SLAPD_COMPARE_UNDEFINED;
+                       *fstr = ch_strdup( "(badfilter)" );
+                       err = LDAP_SUCCESS;
+                       *filt = f;
+
+               } else {
+                       free(f);
+               }
        } else {
                *filt = f;
        }
 
-       free( ftmp );
-
        Debug( LDAP_DEBUG_FILTER, "end get_filter %d\n", err, 0, 0 );
        return( err );
 }
 
 static int
-get_filter_list( Connection *conn, BerElement *ber, Filter **f, char **fstr, char **text )
+get_filter_list( Connection *conn, BerElement *ber,
+       Filter **f, char **fstr,
+       const char **text )
 {
        Filter          **new;
        int             err;
@@ -368,7 +327,7 @@ get_substring_filter(
     BerElement *ber,
     Filter     *f,
     char       **fstr,
-       char    **text
+       const char      **text
 )
 {
        ber_tag_t       tag;
@@ -377,10 +336,7 @@ get_substring_filter(
        struct berval *value;
        char            *last;
        struct berval type;
-#ifndef SLAPD_SCHEMA_NOT_COMPAT
-       int             syntax;
        struct berval *nvalue;
-#endif
        *text = "error decoding filter";
 
        Debug( LDAP_DEBUG_FILTER, "begin get_substring_filter\n", 0, 0, 0 );
@@ -389,7 +345,7 @@ get_substring_filter(
                return SLAPD_DISCONNECT;
        }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
+       f->f_sub = ch_calloc( 1, sizeof(SubstringsAssertion) );
        f->f_sub_desc = NULL;
        rc = slap_bv2ad( &type, &f->f_sub_desc, text );
 
@@ -397,35 +353,22 @@ get_substring_filter(
 
        if( rc != LDAP_SUCCESS ) {
                text = NULL;
+               ch_free( f->f_sub );
                f->f_choice = SLAPD_FILTER_COMPUTED;
                f->f_result = SLAPD_COMPARE_UNDEFINED;
                *fstr = ch_strdup( "(undefined)" );
                return LDAP_SUCCESS;
        }
-#else
-       f->f_sub_type = type.bv_val;
-       attr_normalize( f->f_sub_type );
-
-       /* should get real syntax and see if we have a substring matching rule */
-       syntax = attr_syntax( f->f_sub_type );
-#endif
 
        f->f_sub_initial = NULL;
        f->f_sub_any = NULL;
        f->f_sub_final = NULL;
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
        if( fstr ) {
                *fstr = ch_malloc( sizeof("(=" /*)*/) +
                        f->f_sub_desc->ad_cname->bv_len );
                sprintf( *fstr, "(%s=" /*)*/, f->f_sub_desc->ad_cname->bv_val );
        }
-#else
-       if( fstr ) {
-               *fstr = ch_malloc( strlen( f->f_sub_type ) + 3 );
-               sprintf( *fstr, "(%s=" /*)*/, f->f_sub_type );
-       }
-#endif
 
        for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
            tag = ber_next_element( ber, &len, last ) )
@@ -444,7 +387,6 @@ get_substring_filter(
                        goto return_error;
                } 
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                switch ( tag ) {
                case LDAP_SUBSTRING_INITIAL:
                        usage = SLAP_MR_SUBSTR_INITIAL;
@@ -477,13 +419,6 @@ get_substring_filter(
                }
 
                value = nvalue;
-#else
-
-               /* we should call a substring syntax normalization routine */
-               value_normalize( value->bv_val, syntax );
-               /* this is bogus, value_normalize should take a berval */
-               value->bv_len = strlen( value->bv_val );
-#endif
 
                rc = LDAP_PROTOCOL_ERROR;
 
@@ -551,14 +486,11 @@ return_error:
                                *fstr = NULL;
                        }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                        ad_free( f->f_sub_desc, 1 );
-#else
-                       ch_free( f->f_sub_type );
-#endif
                        ber_bvfree( f->f_sub_initial );
                        ber_bvecfree( f->f_sub_any );
                        ber_bvfree( f->f_sub_final );
+                       ch_free( f->f_sub );
                        return rc;
                }
        }
@@ -586,28 +518,17 @@ filter_free( Filter *f )
 
        switch ( f->f_choice ) {
        case LDAP_FILTER_PRESENT:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                ad_free( f->f_desc, 1 );
-#else
-               if ( f->f_type != NULL ) {
-                       free( f->f_type );
-               }
-#endif
                break;
 
        case LDAP_FILTER_EQUALITY:
        case LDAP_FILTER_GE:
        case LDAP_FILTER_LE:
        case LDAP_FILTER_APPROX:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                ava_free( f->f_ava, 1 );
-#else
-               ava_free( &f->f_ava, 0 );
-#endif
                break;
 
        case LDAP_FILTER_SUBSTRINGS:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                ad_free( f->f_sub_desc, 1 );
                if ( f->f_sub_initial != NULL ) {
                        ber_bvfree( f->f_sub_initial );
@@ -616,18 +537,6 @@ filter_free( Filter *f )
                if ( f->f_sub_final != NULL ) {
                        ber_bvfree( f->f_sub_final );
                }
-#else
-               if ( f->f_sub_type != NULL ) {
-                       free( f->f_sub_type );
-               }
-               if ( f->f_sub_initial != NULL ) {
-                       ber_bvfree( f->f_sub_initial );
-               }
-               ber_bvecfree( f->f_sub_any );
-               if ( f->f_sub_final != NULL ) {
-                       ber_bvfree( f->f_sub_final );
-               }
-#endif
                break;
 
        case LDAP_FILTER_AND:
@@ -665,61 +574,32 @@ filter_print( Filter *f )
 
        switch ( f->f_choice ) {
        case LDAP_FILTER_EQUALITY:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                fprintf( stderr, "(%s=%s)",
                        f->f_av_desc->ad_cname->bv_val,
                    f->f_av_value->bv_val );
-#else
-               fprintf( stderr, "(%s=%s)",
-                       f->f_ava.ava_type,
-                   f->f_ava.ava_value.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_GE:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                fprintf( stderr, "(%s>=%s)",
                        f->f_av_desc->ad_cname->bv_val,
                    f->f_av_value->bv_val );
-#else
-               fprintf( stderr, "(%s>=%s)",
-                       f->f_ava.ava_type,
-                   f->f_ava.ava_value.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_LE:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                fprintf( stderr, "(%s<=%s)",
                        f->f_ava->aa_desc->ad_cname->bv_val,
                    f->f_ava->aa_value->bv_val );
-#else
-               fprintf( stderr, "(%s<=%s)",
-                       f->f_ava.ava_type,
-                   f->f_ava.ava_value.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_APPROX:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                fprintf( stderr, "(%s~=%s)",
                        f->f_ava->aa_desc->ad_cname->bv_val,
                    f->f_ava->aa_value->bv_val );
-#else
-               fprintf( stderr, "(%s~=%s)",
-                       f->f_ava.ava_type,
-                   f->f_ava.ava_value.bv_val );
-#endif
                break;
 
        case LDAP_FILTER_SUBSTRINGS:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                fprintf( stderr, "(%s=" /*)*/,
                        f->f_sub_desc->ad_cname->bv_val );
-#else
-               fprintf( stderr, "(%s=" /*)*/,
-                       f->f_sub_type );
-#endif
                if ( f->f_sub_initial != NULL ) {
                        fprintf( stderr, "%s",
                                f->f_sub_initial->bv_val );
@@ -738,13 +618,8 @@ filter_print( Filter *f )
                break;
 
        case LDAP_FILTER_PRESENT:
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
                fprintf( stderr, "(%s=*)",
                        f->f_desc->ad_cname->bv_val );
-#else
-               fprintf( stderr, "(%s=*)",
-                       f->f_type );
-#endif
                break;
 
        case LDAP_FILTER_AND: