]> git.sur5r.net Git - openldap/commitdiff
need a second function because of different free() routines
authorPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 17:51:42 +0000 (17:51 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 7 Apr 2003 17:51:42 +0000 (17:51 +0000)
servers/slapd/back-ldap/back-ldap.h
servers/slapd/back-ldap/map.c
servers/slapd/back-ldap/search.c

index d605d694f8cd6e1c35ccb7587135c1d16ab3aa04..dc67f7e1586c0a964f097e8cf992bec23afd4723 100644 (file)
@@ -192,6 +192,7 @@ extern int suffix_massage_config( struct rewrite_info *info,
                struct berval *prnc, struct berval *nrnc);
 #endif /* ENABLE_REWRITE */
 extern int ldap_dnattr_rewrite( dncookie *dc, BerVarray a_vals );
+extern int ldap_dnattr_result_rewrite( dncookie *dc, BerVarray a_vals );
 
 LDAP_END_DECL
 
index c74eee875e27b1a6df4916d85a7ada4bc88c6a22..007ed1b985146e0550bc542ad8dccc2d0bcb9b2c 100644 (file)
@@ -44,6 +44,9 @@
 #include "slap.h"
 #include "back-ldap.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 )
 {
@@ -468,6 +471,13 @@ ldap_back_filter_map_rewrite(
        return 0;
 }
 
+/*
+ * I don't like this much, but we need two different
+ * functions because different heap managers may be
+ * in use in back-ldap/meta to reduce the amount of
+ * calls to malloc routines, and some of the free()
+ * routines may be macros with args
+ */
 int
 ldap_dnattr_rewrite(
        dncookie                *dc,
@@ -482,33 +492,73 @@ ldap_dnattr_rewrite(
 
        for ( i = 0; a_vals[i].bv_val != NULL; i++ ) {
                switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
-               case LDAP_SUCCESS:
-               case LDAP_OTHER:        /* ? */
-               default:                /* ??? */
+               case LDAP_UNWILLING_TO_PERFORM:
+                       /*
+                        * FIXME: need to check if it may be considered 
+                        * legal to trim values when adding/modifying;
+                        * it should be when searching (e.g. ACLs).
+                        */
+                       ch_free( a_vals[i].bv_val );
+                       if (last > i ) {
+                               a_vals[i] = a_vals[last];
+                       }
+                       a_vals[last].bv_len = 0;
+                       a_vals[last].bv_val = NULL;
+                       last--;
+                       break;
+
+               default:
                        /* leave attr untouched if massage failed */
                        if ( bv.bv_val && bv.bv_val != a_vals[i].bv_val ) {
                                ch_free( a_vals[i].bv_val );
                                a_vals[i] = bv;
                        }
                        break;
+               }
+       }
+       
+       return 0;
+}
 
+int
+ldap_dnattr_result_rewrite(
+       dncookie                *dc,
+       BerVarray               a_vals
+)
+{
+       struct berval   bv;
+       int             i, last;
+
+       for ( last = 0; a_vals[last].bv_val; last++ );
+       last--;
+
+       for ( i = 0; a_vals[i].bv_val; i++ ) {
+               switch ( ldap_back_dn_massage( dc, &a_vals[i], &bv ) ) {
                case LDAP_UNWILLING_TO_PERFORM:
                        /*
                         * FIXME: need to check if it may be considered 
                         * legal to trim values when adding/modifying;
-                        * it should be when searching (see ACLs).
+                        * it should be when searching (e.g. ACLs).
                         */
-                       ch_free( a_vals[i].bv_val );
-                       if (last > i ) {
+                       LBER_FREE( &a_vals[i].bv_val );
+                       if ( last > i ) {
                                a_vals[i] = a_vals[last];
                        }
-                       a_vals[last].bv_len = 0;
                        a_vals[last].bv_val = NULL;
+                       a_vals[last].bv_len = 0;
                        last--;
                        break;
+
+               default:
+                       /* leave attr untouched if massage failed */
+                       if ( bv.bv_val && a_vals[i].bv_val != bv.bv_val ) {
+                               LBER_FREE( a_vals[i].bv_val );
+                               a_vals[i] = bv;
+                       }
+                       break;
                }
        }
-       
+
        return 0;
 }
 
index 39097d907195103a89a33f1b7801bfe605fe4b57..c9827ae247e92f5ebe8d36cdebb80dcb1990fd31 100644 (file)
@@ -519,37 +519,8 @@ ldap_build_entry(
                 */
                } else if ( attr->a_desc->ad_type->sat_syntax ==
                                slap_schema.si_syn_distinguishedName ) {
-                       int     last, i;
+                       ldap_dnattr_result_rewrite( &dc, attr->a_vals );
 
-                       /*
-                        * FIXME: should use ldap_dnattr_rewrite(),
-                        * but need a different free() callback ...
-                        */
-
-                       for ( last = 0; attr->a_vals[last].bv_val; last++ );
-
-                       for ( i = 0; attr->a_vals[i].bv_val; i++ ) {
-                               struct berval   newval = { 0, NULL };
-
-                               bv = &attr->a_vals[i];
-                               switch ( ldap_back_dn_massage( &dc, bv, &newval ) ) {
-                               case LDAP_UNWILLING_TO_PERFORM:
-                                       LBER_FREE( bv->bv_val );
-                                       if ( last > i ) {
-                                               *bv = attr->a_vals[last];
-                                       }
-                                       attr->a_vals[last].bv_val = NULL;
-                                       last--;
-                                       break;
-
-                               default:
-                                       if ( newval.bv_val && bv->bv_val != newval.bv_val ) {
-                                               LBER_FREE( bv->bv_val );
-                                               *bv = newval;
-                                       }
-                                       break;
-                               }
-                       }
                }
 
                if ( normalize && last && attr->a_desc->ad_type->sat_equality &&