]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/map.c
Merge remote branch 'origin/mdb.master'
[openldap] / servers / slapd / back-meta / map.c
index 025e443ec6eeb37dfbb1e9e65bc802076844bc01..7bb172469b7362a308d468688d1351765d9887d3 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2011 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,9 +61,6 @@
 #include "../back-ldap/back-ldap.h"
 #include "back-meta.h"
 
-#undef ldap_debug      /* silence a warning in ldap-int.h */
-#include "../../../libraries/libldap/ldap-int.h"
-
 int
 mapping_cmp ( const void *c1, const void *c2 )
 {
@@ -174,42 +171,73 @@ ldap_back_map ( struct ldapmap *map, struct berval *s, struct berval *bv,
 
 int
 ldap_back_map_attrs(
+               Operation *op,
                struct ldapmap *at_map,
                AttributeName *an,
                int remap,
-               char ***mapped_attrs,
-               void *memctx )
+               char ***mapped_attrs )
 {
-       int i, j;
+       int i, x, j;
        char **na;
        struct berval mapped;
 
-       if ( an == NULL ) {
+       if ( an == NULL && op->o_bd->be_extra_anlist == NULL ) {
                *mapped_attrs = NULL;
                return LDAP_SUCCESS;
        }
 
-       for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ )
-               /*  */ ;
+       i = 0;
+       if ( an != NULL ) {
+               for ( ; !BER_BVISNULL( &an[i].an_name ); i++ )
+                       /*  */ ;
+       }
+
+       x = 0;
+       if ( op->o_bd->be_extra_anlist != NULL ) {
+               for ( ; !BER_BVISNULL( &op->o_bd->be_extra_anlist[x].an_name ); x++ )
+                       /*  */ ;
+       }
 
-       na = (char **)ber_memcalloc_x( i + 1, sizeof(char *), memctx );
+       assert( i > 0 || x > 0 );
+       
+       na = (char **)ber_memcalloc_x( i + x + 1, sizeof(char *), op->o_tmpmemctx );
        if ( na == NULL ) {
                *mapped_attrs = NULL;
                return LDAP_NO_MEMORY;
        }
 
-       for ( i = j = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
-               ldap_back_map( at_map, &an[i].an_name, &mapped, remap );
-               if ( !BER_BVISNULL( &mapped ) && !BER_BVISEMPTY( &mapped ) ) {
-                       na[j++] = mapped.bv_val;
+       j = 0;
+       if ( i > 0 ) {
+               for ( i = 0; !BER_BVISNULL( &an[i].an_name ); i++ ) {
+                       ldap_back_map( at_map, &an[i].an_name, &mapped, remap );
+                       if ( !BER_BVISNULL( &mapped ) && !BER_BVISEMPTY( &mapped ) ) {
+                               na[j++] = mapped.bv_val;
+                       }
+               }
+       }
+
+       if ( x > 0 ) {
+               for ( x = 0; !BER_BVISNULL( &op->o_bd->be_extra_anlist[x].an_name ); x++ ) {
+                       if ( op->o_bd->be_extra_anlist[x].an_desc &&
+                               ad_inlist( op->o_bd->be_extra_anlist[x].an_desc, an ) )
+                       {
+                               continue;
+                       }
+
+                       ldap_back_map( at_map, &op->o_bd->be_extra_anlist[x].an_name, &mapped, remap );
+                       if ( !BER_BVISNULL( &mapped ) && !BER_BVISEMPTY( &mapped ) ) {
+                               na[j++] = mapped.bv_val;
+                       }
                }
        }
-       if ( j == 0 && i != 0 ) {
+
+       if ( j == 0 && ( i > 0 || x > 0 ) ) {
                na[j++] = LDAP_NO_ATTRS;
        }
        na[j] = NULL;
 
        *mapped_attrs = na;
+
        return LDAP_SUCCESS;
 }
 
@@ -270,7 +298,9 @@ map_attr_value(
                        return -1;
                }
 
-       } else if ( ad->ad_type->sat_equality->smr_usage & SLAP_MR_MUTATION_NORMALIZER ) {
+       } else if ( ad->ad_type->sat_equality && 
+               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, memctx ) )
@@ -711,7 +741,7 @@ ldap_back_referral_result_rewrite(
                         * legal to trim values when adding/modifying;
                         * it should be when searching (e.g. ACLs).
                         */
-                       LBER_FREE( a_vals[ i ].bv_val );
+                       ber_memfree( a_vals[ i ].bv_val );
                        if ( last > i ) {
                                a_vals[ i ] = a_vals[ last ];
                        }
@@ -738,7 +768,7 @@ ldap_back_referral_result_rewrite(
 
                                ber_memfree_x( a_vals[ i ].bv_val, memctx );
                                ber_str2bv_x( newurl, 0, 1, &a_vals[ i ], memctx );
-                               LDAP_FREE( newurl );
+                               ber_memfree( newurl );
                                ludp->lud_dn = olddn.bv_val;
                        }
                        break;
@@ -824,7 +854,7 @@ ldap_dnattr_result_rewrite(
                         * legal to trim values when adding/modifying;
                         * it should be when searching (e.g. ACLs).
                         */
-                       LBER_FREE( a_vals[i].bv_val );
+                       ber_memfree( a_vals[i].bv_val );
                        if ( last > i ) {
                                a_vals[i] = a_vals[last];
                        }
@@ -835,7 +865,7 @@ ldap_dnattr_result_rewrite(
                default:
                        /* leave attr untouched if massage failed */
                        if ( !BER_BVISNULL( &bv ) && a_vals[i].bv_val != bv.bv_val ) {
-                               LBER_FREE( a_vals[i].bv_val );
+                               ber_memfree( a_vals[i].bv_val );
                                a_vals[i] = bv;
                        }
                        break;