]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/map.c
Fix compare op
[openldap] / servers / slapd / back-meta / map.c
index 1871ebbddf9521c2306f4548c1dd6dfbc023e378..9044c1ffc748295776414d8667ca5241f95796a9 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2007 The OpenLDAP Foundation.
+ * Copyright 1998-2009 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,7 @@
 #include <ac/socket.h>
 
 #include "slap.h"
+#include "lutil.h"
 #include "../back-ldap/back-ldap.h"
 #include "back-meta.h"
 
@@ -118,6 +119,15 @@ ldap_back_mapping ( struct ldapmap *map, struct berval *s, struct ldapmapping **
 
        assert( m != NULL );
 
+       /* let special attrnames slip through (ITS#5760) */
+       if ( bvmatch( s, slap_bv_no_attrs )
+               || bvmatch( s, slap_bv_all_user_attrs )
+               || bvmatch( s, slap_bv_all_operational_attrs ) )
+       {
+               *m = NULL;
+               return 0;
+       }
+
        if ( remap == BACKLDAP_REMAP ) {
                tree = map->remap;
 
@@ -139,6 +149,7 @@ ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
        int remap )
 {
        struct ldapmapping *mapping;
+       int drop_missing;
 
        /* map->map may be NULL when mapping is configured,
         * but map->remap can't */
@@ -148,7 +159,7 @@ ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
        }
 
        BER_BVZERO( bv );
-       ( void )ldap_back_mapping( map, s, &mapping, remap );
+       drop_missing = ldap_back_mapping( map, s, &mapping, remap );
        if ( mapping != NULL ) {
                if ( !BER_BVISNULL( &mapping->dst ) ) {
                        *bv = mapping->dst;
@@ -156,7 +167,7 @@ ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
                return;
        }
 
-       if ( !map->drop_missing ) {
+       if ( !drop_missing ) {
                *bv = *s;
        }
 }
@@ -258,6 +269,15 @@ map_attr_value(
                        return -1;
                }
 
+       } else if ( ad->ad_type->sat_equality->smr_usage & SLAP_MR_MUTATION_NORMALIZER ) {
+               if ( ad->ad_type->sat_equality->smr_normalize(
+                       (SLAP_MR_DENORMALIZE|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX),
+                       NULL, NULL, value, &vtmp, NULL ) )
+               {
+                       return -1;
+               }
+               freeval = 1;
+
        } else if ( ad == slap_schema.si_ad_objectClass || ad == slap_schema.si_ad_structuralObjectClass ) {
                ldap_back_map( &dc->target->mt_rwmap.rwm_oc, value, &vtmp, remap );
                if ( BER_BVISNULL( &vtmp ) || BER_BVISEMPTY( &vtmp ) ) {
@@ -313,7 +333,7 @@ ldap_back_int_filter_map_rewrite(
                return LDAP_OTHER;
        }
 
-       switch ( f->f_choice ) {
+       switch ( ( f->f_choice & SLAPD_FILTER_MASK ) ) {
        case LDAP_FILTER_EQUALITY:
                if ( map_attr_value( dc, f->f_av_desc, &atmp,
                                        &f->f_av_value, &vtmp, remap ) )
@@ -323,7 +343,7 @@ ldap_back_int_filter_map_rewrite(
 
                fstr->bv_len = atmp.bv_len + vtmp.bv_len
                        + ( sizeof("(=)") - 1 );
-               fstr->bv_val = malloc( fstr->bv_len + 1 );
+               fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=%s)",
                        atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
@@ -340,7 +360,7 @@ ldap_back_int_filter_map_rewrite(
 
                fstr->bv_len = atmp.bv_len + vtmp.bv_len
                        + ( sizeof("(>=)") - 1 );
-               fstr->bv_val = malloc( fstr->bv_len + 1 );
+               fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s>=%s)",
                        atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
@@ -357,7 +377,7 @@ ldap_back_int_filter_map_rewrite(
 
                fstr->bv_len = atmp.bv_len + vtmp.bv_len
                        + ( sizeof("(<=)") - 1 );
-               fstr->bv_val = malloc( fstr->bv_len + 1 );
+               fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s<=%s)",
                        atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
@@ -374,7 +394,7 @@ ldap_back_int_filter_map_rewrite(
 
                fstr->bv_len = atmp.bv_len + vtmp.bv_len
                        + ( sizeof("(~=)") - 1 );
-               fstr->bv_val = malloc( fstr->bv_len + 1 );
+               fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s~=%s)",
                        atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
@@ -392,7 +412,7 @@ ldap_back_int_filter_map_rewrite(
                /* cannot be a DN ... */
 
                fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) );
-               fstr->bv_val = malloc( fstr->bv_len + 128 ); /* FIXME: why 128 ? */
+               fstr->bv_val = ch_malloc( fstr->bv_len + 128 ); /* FIXME: why 128 ? */
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
                        atmp.bv_val );
@@ -452,7 +472,7 @@ ldap_back_int_filter_map_rewrite(
                }
 
                fstr->bv_len = atmp.bv_len + ( STRLENOF( "(=*)" ) );
-               fstr->bv_val = malloc( fstr->bv_len + 1 );
+               fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s=*)",
                        atmp.bv_val );
@@ -462,7 +482,7 @@ ldap_back_int_filter_map_rewrite(
        case LDAP_FILTER_OR:
        case LDAP_FILTER_NOT:
                fstr->bv_len = STRLENOF( "(%)" );
-               fstr->bv_val = malloc( fstr->bv_len + 128 );    /* FIXME: why 128? */
+               fstr->bv_val = ch_malloc( fstr->bv_len + 128 ); /* FIXME: why 128? */
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%c)",
                        f->f_choice == LDAP_FILTER_AND ? '&' :
@@ -507,7 +527,7 @@ ldap_back_int_filter_map_rewrite(
                        ( f->f_mr_dnattrs ? STRLENOF( ":dn" ) : 0 ) +
                        ( !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_len + 1 : 0 ) +
                        vtmp.bv_len + ( STRLENOF( "(:=)" ) );
-               fstr->bv_val = malloc( fstr->bv_len + 1 );
+               fstr->bv_val = ch_malloc( fstr->bv_len + 1 );
 
                snprintf( fstr->bv_val, fstr->bv_len + 1, "(%s%s%s%s:=%s)",
                        atmp.bv_val,
@@ -520,10 +540,15 @@ ldap_back_int_filter_map_rewrite(
 
        case SLAPD_FILTER_COMPUTED:
                switch ( f->f_result ) {
-               case LDAP_COMPARE_FALSE:
                /* FIXME: treat UNDEFINED as FALSE */
                case SLAPD_COMPARE_UNDEFINED:
 computed:;
+                       if ( META_BACK_TGT_NOUNDEFFILTER( dc->target ) ) {
+                               return LDAP_COMPARE_FALSE;
+                       }
+                       /* fallthru */
+
+               case LDAP_COMPARE_FALSE:
                        if ( META_BACK_TGT_T_F( dc->target ) ) {
                                tmp = &ber_bvtf_false;
                                break;