Diff for /servers/slapd/filter.c between versions 1.134.2.15 and 1.134.2.22

version 1.134.2.15, 2008/11/11 19:30:37 version 1.134.2.22, 2011/01/31 19:46:55
Line 1 Line 1
 /* filter.c - routines for parsing and dealing with filters */  /* filter.c - routines for parsing and dealing with filters */
 /* $OpenLDAP: pkg/ldap/servers/slapd/filter.c,v 1.134.2.14 2008/11/08 00:28:43 quanah Exp $ */  /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.  /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *   *
  * Copyright 1998-2008 The OpenLDAP Foundation.   * Copyright 1998-2011 The OpenLDAP Foundation.
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 348  get_ssa( Line 348  get_ssa(
 {  {
         ber_tag_t       tag;          ber_tag_t       tag;
         ber_len_t       len;          ber_len_t       len;
         ber_tag_t       rc;          int     rc;
         struct berval desc, value, nvalue;          struct berval desc, value, nvalue;
         char            *last;          char            *last;
         SubstringsAssertion ssa;          SubstringsAssertion ssa;
Line 385  get_ssa( Line 385  get_ssa(
   
         rc = LDAP_PROTOCOL_ERROR;          rc = LDAP_PROTOCOL_ERROR;
   
           /* If there is no substring matching rule, there's nothing
            * we can do with this filter. But we continue to parse it
            * for logging purposes.
            */
         if ( ssa.sa_desc->ad_type->sat_substr == NULL ) {          if ( ssa.sa_desc->ad_type->sat_substr == NULL ) {
                 for ( tag = ber_first_element( ber, &len, &last );                  f->f_choice |= SLAPD_FILTER_UNDEFINED;
                         tag != LBER_DEFAULT;                  Debug( LDAP_DEBUG_FILTER,
                         tag = ber_next_element( ber, &len, last ) )                  "get_ssa: no substring matching rule for attributeType %s\n",
                 {                          desc.bv_val, 0, 0 );
                         /* eat all */  
                         rc = ber_scanf( ber, "x" );  
                 }  
   
                 rc = LDAP_INVALID_SYNTAX;  
                 goto return_error;  
         }          }
   
         for ( tag = ber_first_element( ber, &len, &last );          for ( tag = ber_first_element( ber, &len, &last );
Line 404  get_ssa( Line 402  get_ssa(
         {          {
                 unsigned usage;                  unsigned usage;
   
                 rc = ber_scanf( ber, "m", &value );                  if ( ber_scanf( ber, "m", &value ) == LBER_ERROR ) {
                 if ( rc == LBER_ERROR ) {  
                         rc = SLAPD_DISCONNECT;                          rc = SLAPD_DISCONNECT;
                         goto return_error;                          goto return_error;
                 }                  }
Line 457  get_ssa( Line 454  get_ssa(
                 rc = asserted_value_validate_normalize(                  rc = asserted_value_validate_normalize(
                         ssa.sa_desc, ssa.sa_desc->ad_type->sat_equality,                          ssa.sa_desc, ssa.sa_desc->ad_type->sat_equality,
                         usage, &value, &nvalue, text, op->o_tmpmemctx );                          usage, &value, &nvalue, text, op->o_tmpmemctx );
                 if( rc != LDAP_SUCCESS ) goto return_error;                  if( rc != LDAP_SUCCESS ) {
                           f->f_choice |= SLAPD_FILTER_UNDEFINED;
                           Debug( LDAP_DEBUG_FILTER,
                           "get_ssa: illegal value for attributeType %s (%d) %s\n",
                                   desc.bv_val, rc, *text );
                           ber_dupbv_x( &nvalue, &value, op->o_tmpmemctx );
                   }
   
                 switch ( tag ) {                  switch ( tag ) {
                 case LDAP_SUBSTRING_INITIAL:                  case LDAP_SUBSTRING_INITIAL:
Line 517  filter_free_x( Operation *op, Filter *f, Line 520  filter_free_x( Operation *op, Filter *f,
   
         switch ( f->f_choice ) {          switch ( f->f_choice ) {
         case LDAP_FILTER_PRESENT:          case LDAP_FILTER_PRESENT:
                   if ( f->f_desc->ad_flags & SLAP_DESC_TEMPORARY )
                           op->o_tmpfree( f->f_desc, op->o_tmpmemctx );
                 break;                  break;
   
         case LDAP_FILTER_EQUALITY:          case LDAP_FILTER_EQUALITY:
Line 581  filter_free( Filter *f ) Line 586  filter_free( Filter *f )
 void  void
 filter2bv_x( Operation *op, Filter *f, struct berval *fstr )  filter2bv_x( Operation *op, Filter *f, struct berval *fstr )
 {  {
           return filter2bv_undef_x( op, f, 0, fstr );
   }
   
   void
   filter2bv_undef_x( Operation *op, Filter *f, int noundef, struct berval *fstr )
   {
         int             i;          int             i;
         Filter          *p;          Filter          *p;
         struct berval   tmp, value;          struct berval   tmp, value;
Line 590  filter2bv_x( Operation *op, Filter *f, s Line 601  filter2bv_x( Operation *op, Filter *f, s
                         ber_bvundefined = BER_BVC( "(?=undefined)" ),                          ber_bvundefined = BER_BVC( "(?=undefined)" ),
                         ber_bverror = BER_BVC( "(?=error)" ),                          ber_bverror = BER_BVC( "(?=error)" ),
                         ber_bvunknown = BER_BVC( "(?=unknown)" ),                          ber_bvunknown = BER_BVC( "(?=unknown)" ),
                         ber_bvnone = BER_BVC( "(?=none)" );                          ber_bvnone = BER_BVC( "(?=none)" ),
                           ber_bvF = BER_BVC( "(|)" ),
                           ber_bvT = BER_BVC( "(&)" );
         ber_len_t       len;          ber_len_t       len;
         ber_tag_t       choice;          ber_tag_t       choice;
         int undef;          int undef, undef2;
         char *sign;          char *sign;
   
         if ( f == NULL ) {          if ( f == NULL ) {
Line 602  filter2bv_x( Operation *op, Filter *f, s Line 615  filter2bv_x( Operation *op, Filter *f, s
         }          }
   
         undef = f->f_choice & SLAPD_FILTER_UNDEFINED;          undef = f->f_choice & SLAPD_FILTER_UNDEFINED;
           undef2 = (undef && !noundef);
         choice = f->f_choice & SLAPD_FILTER_MASK;          choice = f->f_choice & SLAPD_FILTER_MASK;
   
         switch ( choice ) {          switch ( choice ) {
Line 639  simple: Line 653  simple:
                  * is legal for that attribute's syntax */                   * is legal for that attribute's syntax */
   
                 fstr->bv_len += f->f_av_desc->ad_cname.bv_len + tmp.bv_len;                  fstr->bv_len += f->f_av_desc->ad_cname.bv_len + tmp.bv_len;
                 if ( undef )                  if ( undef2 )
                         fstr->bv_len++;                          fstr->bv_len++;
                 fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );                  fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
   
                 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s)",                  snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s)",
                         undef ? "?" : "",                          undef2 ? "?" : "",
                         f->f_av_desc->ad_cname.bv_val, sign,                          f->f_av_desc->ad_cname.bv_val, sign,
                         tmp.bv_len ? tmp.bv_val : "" );                          tmp.bv_len ? tmp.bv_val : "" );
   
Line 658  simple: Line 672  simple:
         case LDAP_FILTER_SUBSTRINGS:          case LDAP_FILTER_SUBSTRINGS:
                 fstr->bv_len = f->f_sub_desc->ad_cname.bv_len +                  fstr->bv_len = f->f_sub_desc->ad_cname.bv_len +
                         STRLENOF("(=*)");                          STRLENOF("(=*)");
                 if ( undef )                  if ( undef2 )
                         fstr->bv_len++;                          fstr->bv_len++;
                 fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 128, op->o_tmpmemctx );                  fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 128, op->o_tmpmemctx );
   
                 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s=*)",                  snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s=*)",
                         undef ? "?" : "",                          undef2 ? "?" : "",
                         f->f_sub_desc->ad_cname.bv_val );                          f->f_sub_desc->ad_cname.bv_val );
   
                 if ( f->f_sub_initial.bv_val != NULL ) {                  if ( f->f_sub_initial.bv_val != NULL ) {
Line 732  simple: Line 746  simple:
         case LDAP_FILTER_PRESENT:          case LDAP_FILTER_PRESENT:
                 fstr->bv_len = f->f_desc->ad_cname.bv_len +                  fstr->bv_len = f->f_desc->ad_cname.bv_len +
                         STRLENOF("(=*)");                          STRLENOF("(=*)");
                 if ( undef )                  if ( undef2 )
                         fstr->bv_len++;                          fstr->bv_len++;
   
                 fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );                  fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
   
                 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s=*)",                  snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s=*)",
                         undef ? "?" : "",                          undef2 ? "?" : "",
                         f->f_desc->ad_cname.bv_val );                          f->f_desc->ad_cname.bv_val );
                 break;                  break;
   
Line 755  simple: Line 769  simple:
                 for ( p = f->f_list; p != NULL; p = p->f_next ) {                  for ( p = f->f_list; p != NULL; p = p->f_next ) {
                         len = fstr->bv_len;                          len = fstr->bv_len;
   
                         filter2bv_x( op, p, &tmp );                          filter2bv_undef_x( op, p, noundef, &tmp );
                                                   
                         fstr->bv_len += tmp.bv_len;                          fstr->bv_len += tmp.bv_len;
                         fstr->bv_val = op->o_tmprealloc( fstr->bv_val, fstr->bv_len + 1,                          fstr->bv_val = op->o_tmprealloc( fstr->bv_val, fstr->bv_len + 1,
Line 787  simple: Line 801  simple:
                 }                  }
                                   
                 fstr->bv_len = ad.bv_len +                  fstr->bv_len = ad.bv_len +
                           ( undef2 ? 1 : 0 ) +
                         ( f->f_mr_dnattrs ? STRLENOF(":dn") : 0 ) +                          ( f->f_mr_dnattrs ? STRLENOF(":dn") : 0 ) +
                         ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len+1 : 0 ) +                          ( f->f_mr_rule_text.bv_len ? f->f_mr_rule_text.bv_len + STRLENOF(":") : 0 ) +
                         tmp.bv_len + STRLENOF("(:=)");                          tmp.bv_len + STRLENOF("(:=)");
                 fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );                  fstr->bv_val = op->o_tmpalloc( fstr->bv_len + 1, op->o_tmpmemctx );
   
                 snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s%s:=%s)",                  snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s%s:=%s)",
                         undef ? "?" : "",                          undef2 ? "?" : "",
                         ad.bv_val,                          ad.bv_val,
                         f->f_mr_dnattrs ? ":dn" : "",                          f->f_mr_dnattrs ? ":dn" : "",
                         f->f_mr_rule_text.bv_len ? ":" : "",                          f->f_mr_rule_text.bv_len ? ":" : "",
Line 805  simple: Line 820  simple:
         case SLAPD_FILTER_COMPUTED:          case SLAPD_FILTER_COMPUTED:
                 switch ( f->f_result ) {                  switch ( f->f_result ) {
                 case LDAP_COMPARE_FALSE:                  case LDAP_COMPARE_FALSE:
                         tmp = ber_bvfalse;                          tmp = ( noundef ? ber_bvF : ber_bvfalse );
                         break;                          break;
   
                 case LDAP_COMPARE_TRUE:                  case LDAP_COMPARE_TRUE:
                         tmp = ber_bvtrue;                          tmp = ( noundef ? ber_bvT : ber_bvtrue );
                         break;                          break;
                                                   
                 case SLAPD_COMPARE_UNDEFINED:                  case SLAPD_COMPARE_UNDEFINED:
Line 833  simple: Line 848  simple:
 void  void
 filter2bv( Filter *f, struct berval *fstr )  filter2bv( Filter *f, struct berval *fstr )
 {  {
           return filter2bv_undef( f, 0, fstr );
   }
   
   void
   filter2bv_undef( Filter *f, int noundef, struct berval *fstr )
   {
         Operation op;          Operation op;
         Opheader ohdr;          Opheader ohdr;
   
Line 840  filter2bv( Filter *f, struct berval *fst Line 861  filter2bv( Filter *f, struct berval *fst
         op.o_tmpmemctx = NULL;          op.o_tmpmemctx = NULL;
         op.o_tmpmfuncs = &ch_mfuncs;          op.o_tmpmfuncs = &ch_mfuncs;
   
         filter2bv_x( &op, f, fstr );          filter2bv_undef_x( &op, f, noundef, fstr );
 }  }
   
 Filter *  Filter *

Removed from v.1.134.2.15  
changed lines
  Added in v.1.134.2.22


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