Diff for /servers/slapd/filter.c between versions 1.4.2.2 and 1.16

version 1.4.2.2, 1998/11/15 19:09:05 version 1.16, 1999/09/08 17:06:33
Line 1 Line 1
 /* filter.c - routines for parsing and dealing with filters */  /* filter.c - routines for parsing and dealing with filters */
   /* $OpenLDAP$ */
   /*
    * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
    * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
    */
   
 #include "portable.h"  #include "portable.h"
   
Line 9 Line 14
   
 #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();  
   
 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;          ber_len_t       len;
         int             err;          int             err;
         Filter          *f;          Filter          *f;
         char            *ftmp;          char            *ftmp;
Line 36  get_filter( Connection *conn, BerElement Line 39  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 46  get_filter( Connection *conn, BerElement Line 50  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 92  get_filter( Connection *conn, BerElement Line 85  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 102  get_filter( Connection *conn, BerElement Line 95  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 113  get_filter( Connection *conn, BerElement Line 106  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 124  get_filter( Connection *conn, BerElement Line 117  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 135  get_filter( Connection *conn, BerElement Line 128  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 146  get_filter( Connection *conn, BerElement Line 139  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 157  get_filter( Connection *conn, BerElement Line 150  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 188  get_filter_list( Connection *conn, BerEl Line 189  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 217  get_filter_list( Connection *conn, BerEl Line 215  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 228  get_substring_filter( Line 226  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 251  get_substring_filter( Line 246  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 270  get_substring_filter( Line 261  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 284  get_substring_filter( Line 272  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 296  get_substring_filter( Line 281  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 324  get_substring_filter( Line 306  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 373  filter_free( Filter *f ) Line 355  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 445  filter_print( Filter *f ) Line 427  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;
         }          }
 }  }

Removed from v.1.4.2.2  
changed lines
  Added in v.1.16


______________
© Copyright 1998-2020, OpenLDAP Foundation, info@OpenLDAP.org