]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/map.c
Fix compare op
[openldap] / servers / slapd / back-meta / map.c
index 912bd1671ded37bcf0150c5d4aa7436559be663e..9044c1ffc748295776414d8667ca5241f95796a9 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 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"
 
@@ -90,19 +91,19 @@ ldap_back_map_init ( struct ldapmap *lm, struct ldapmapping **m )
        assert( m != NULL );
 
        *m = NULL;
-       
+
        mapping = (struct ldapmapping *)ch_calloc( 2, 
                        sizeof( struct ldapmapping ) );
        if ( mapping == NULL ) {
                return;
        }
 
-       ber_str2bv( "objectclass", sizeof("objectclass")-1, 1, &mapping->src);
-       ber_dupbv( &mapping->dst, &mapping->src );
-       mapping[1].src = mapping->src;
-       mapping[1].dst = mapping->dst;
+       ber_str2bv( "objectclass", STRLENOF("objectclass"), 1, &mapping[0].src);
+       ber_dupbv( &mapping[0].dst, &mapping[0].src );
+       mapping[1].src = mapping[0].src;
+       mapping[1].dst = mapping[0].dst;
 
-       avl_insert( &lm->map, (caddr_t)mapping
+       avl_insert( &lm->map, (caddr_t)&mapping[0]
                        mapping_cmp, mapping_dup );
        avl_insert( &lm->remap, (caddr_t)&mapping[1], 
                        mapping_cmp, mapping_dup );
@@ -118,8 +119,18 @@ 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;
+
        } else {
                tree = map->map;
        }
@@ -138,9 +149,17 @@ 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 */
+       if ( map->remap == NULL ) {
+               *bv = *s;
+               return;
+       }
 
        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;
@@ -148,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;
        }
 }
@@ -250,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 ) ) {
@@ -305,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 ) )
@@ -315,10 +343,10 @@ 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_val );
+                       atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
 
                ber_memfree( vtmp.bv_val );
                break;
@@ -332,10 +360,10 @@ 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_val );
+                       atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
 
                ber_memfree( vtmp.bv_val );
                break;
@@ -349,10 +377,10 @@ 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_val );
+                       atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
 
                ber_memfree( vtmp.bv_val );
                break;
@@ -366,10 +394,10 @@ 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_val );
+                       atmp.bv_val, vtmp.bv_len ? vtmp.bv_val : "" );
 
                ber_memfree( vtmp.bv_val );
                break;
@@ -384,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 );
@@ -399,7 +427,7 @@ ldap_back_int_filter_map_rewrite(
 
                        snprintf( &fstr->bv_val[len - 2], vtmp.bv_len + 3,
                                /* "(attr=" */ "%s*)",
-                               vtmp.bv_val );
+                               vtmp.bv_len ? vtmp.bv_val : "" );
 
                        ber_memfree( vtmp.bv_val );
                }
@@ -414,7 +442,7 @@ ldap_back_int_filter_map_rewrite(
 
                                snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
                                        /* "(attr=[init]*[any*]" */ "%s*)",
-                                       vtmp.bv_val );
+                                       vtmp.bv_len ? vtmp.bv_val : "" );
                                ber_memfree( vtmp.bv_val );
                        }
                }
@@ -429,7 +457,7 @@ ldap_back_int_filter_map_rewrite(
 
                        snprintf( &fstr->bv_val[len - 1], vtmp.bv_len + 3,
                                /* "(attr=[init*][any*]" */ "%s)",
-                               vtmp.bv_val );
+                               vtmp.bv_len ? vtmp.bv_val : "" );
 
                        ber_memfree( vtmp.bv_val );
                }
@@ -444,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 );
@@ -454,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 ? '&' :
@@ -474,7 +502,7 @@ ldap_back_int_filter_map_rewrite(
                        fstr->bv_val = ch_realloc( fstr->bv_val, fstr->bv_len + 1 );
 
                        snprintf( &fstr->bv_val[len-1], vtmp.bv_len + 2, 
-                               /*"("*/ "%s)", vtmp.bv_val );
+                               /*"("*/ "%s)", vtmp.bv_len ? vtmp.bv_val : "" );
 
                        ch_free( vtmp.bv_val );
                }
@@ -499,24 +527,29 @@ 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,
                        f->f_mr_dnattrs ? ":dn" : "",
                        !BER_BVISEMPTY( &f->f_mr_rule_text ) ? ":" : "",
                        !BER_BVISEMPTY( &f->f_mr_rule_text ) ? f->f_mr_rule_text.bv_val : "",
-                       vtmp.bv_val );
+                       vtmp.bv_len ? vtmp.bv_val : "" );
                ber_memfree( vtmp.bv_val );
                break;
 
        case SLAPD_FILTER_COMPUTED:
                switch ( f->f_result ) {
-               case LDAP_COMPARE_FALSE:
                /* FIXME: treat UNDEFINED as FALSE */
                case SLAPD_COMPARE_UNDEFINED:
 computed:;
-                       if ( dc->target->mt_flags & LDAP_BACK_F_SUPPORT_T_F ) {
+                       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;
                        }
@@ -524,7 +557,7 @@ computed:;
                        break;
 
                case LDAP_COMPARE_TRUE:
-                       if ( dc->target->mt_flags & LDAP_BACK_F_SUPPORT_T_F ) {
+                       if ( META_BACK_TGT_T_F( dc->target ) ) {
                                tmp = &ber_bvtf_true;
                                break;
                        }