Diff for /servers/slapd/filter.c between versions 1.3.10.1 and 1.13

version 1.3.10.1, 1998/10/20 23:24:28 version 1.13, 1999/07/07 16:51:39
Line 3 Line 3
 #include "portable.h"  #include "portable.h"
   
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  
 #include <sys/types.h>  
 #include <sys/socket.h>  
 #include "slap.h"  
   
 static int      get_filter_list();  #include <ac/socket.h>
 static int      get_substring_filter();  #include <ac/string.h>
   
   #include "slap.h"
   
 extern int      get_ava();  static int      get_filter_list(Connection *conn, BerElement *ber, Filter **f, char **fstr);
 extern char     *ch_malloc();  static int      get_substring_filter(Connection *conn, BerElement *ber, Filter *f, char **fstr);
 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 37  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 47  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 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 93  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 103  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 114  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 125  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 136  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 147  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 158  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 189  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 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 218  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 229  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 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 252  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 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 271  get_substring_filter( Line 256  get_substring_filter(
                 value_normalize( val, syntax );                  value_normalize( val, syntax );
   
                 switch ( tag ) {                  switch ( tag ) {
 #ifdef 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 285  get_substring_filter( Line 267  get_substring_filter(
                         strcat( *fstr, val );                          strcat( *fstr, val );
                         break;                          break;
   
 #ifdef 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 297  get_substring_filter( Line 276  get_substring_filter(
                         strcat( *fstr, val );                          strcat( *fstr, val );
                         break;                          break;
   
 #ifdef 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 325  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 374  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 390  filter_print( Filter *f ) Line 366  filter_print( Filter *f )
         Filter  *p;          Filter  *p;
   
         if ( f == NULL ) {          if ( f == NULL ) {
                 printf( "NULL" );                  fprintf( stderr, "NULL" );
         }          }
   
         switch ( f->f_choice ) {          switch ( f->f_choice ) {
         case LDAP_FILTER_EQUALITY:          case LDAP_FILTER_EQUALITY:
                 printf( "(%s=%s)", f->f_ava.ava_type,                  fprintf( stderr, "(%s=%s)", f->f_ava.ava_type,
                     f->f_ava.ava_value.bv_val );                      f->f_ava.ava_value.bv_val );
                 break;                  break;
   
         case LDAP_FILTER_GE:          case LDAP_FILTER_GE:
                 printf( "(%s>=%s)", f->f_ava.ava_type,                  fprintf( stderr, "(%s>=%s)", f->f_ava.ava_type,
                     f->f_ava.ava_value.bv_val );                      f->f_ava.ava_value.bv_val );
                 break;                  break;
   
         case LDAP_FILTER_LE:          case LDAP_FILTER_LE:
                 printf( "(%s<=%s)", f->f_ava.ava_type,                  fprintf( stderr, "(%s<=%s)", f->f_ava.ava_type,
                     f->f_ava.ava_value.bv_val );                      f->f_ava.ava_value.bv_val );
                 break;                  break;
   
         case LDAP_FILTER_APPROX:          case LDAP_FILTER_APPROX:
                 printf( "(%s~=%s)", f->f_ava.ava_type,                  fprintf( stderr, "(%s~=%s)", f->f_ava.ava_type,
                     f->f_ava.ava_value.bv_val );                      f->f_ava.ava_value.bv_val );
                 break;                  break;
   
         case LDAP_FILTER_SUBSTRINGS:          case LDAP_FILTER_SUBSTRINGS:
                 printf( "(%s=", f->f_sub_type );                  fprintf( stderr, "(%s=", f->f_sub_type );
                 if ( f->f_sub_initial != NULL ) {                  if ( f->f_sub_initial != NULL ) {
                         printf( "%s", f->f_sub_initial );                          fprintf( stderr, "%s", f->f_sub_initial );
                 }                  }
                 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++ ) {
                                 printf( "*%s", f->f_sub_any[i] );                                  fprintf( stderr, "*%s", f->f_sub_any[i] );
                         }                          }
                 }                  }
                 charray_free( f->f_sub_any );                  charray_free( f->f_sub_any );
                 if ( f->f_sub_final != NULL ) {                  if ( f->f_sub_final != NULL ) {
                         printf( "*%s", f->f_sub_final );                          fprintf( stderr, "*%s", f->f_sub_final );
                 }                  }
                 break;                  break;
   
         case LDAP_FILTER_PRESENT:          case LDAP_FILTER_PRESENT:
                 printf( "%s=*", f->f_type );                  fprintf( stderr, "%s=*", f->f_type );
                 break;                  break;
   
         case LDAP_FILTER_AND:          case LDAP_FILTER_AND:
         case LDAP_FILTER_OR:          case LDAP_FILTER_OR:
         case LDAP_FILTER_NOT:          case LDAP_FILTER_NOT:
                 printf( "(%c", f->f_choice == LDAP_FILTER_AND ? '&' :                  fprintf( stderr, "(%c", f->f_choice == LDAP_FILTER_AND ? '&' :
                     f->f_choice == LDAP_FILTER_OR ? '|' : '!' );                      f->f_choice == LDAP_FILTER_OR ? '|' : '!' );
                 for ( p = f->f_list; p != NULL; p = p->f_next ) {                  for ( p = f->f_list; p != NULL; p = p->f_next ) {
                         filter_print( p );                          filter_print( p );
                 }                  }
                 printf( ")" );                  fprintf( stderr, ")" );
                 break;                  break;
   
         default:          default:
                 printf( "unknown type %d", f->f_choice );                  fprintf( stderr, "unknown type %lu", f->f_choice );
                 break;                  break;
         }          }
 }  }

Removed from v.1.3.10.1  
changed lines
  Added in v.1.13


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