]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldap/add.c
use BerVarray for suffix_massaging stuff
[openldap] / servers / slapd / back-ldap / add.c
index d7e145d8b754dd1cad210a2304ace365d612ae8d..2eb05502b127b9b0e7b2d3ec5272a0916eeb70cb 100644 (file)
@@ -1,7 +1,7 @@
 /* add.c - ldap backend add function */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* This is an altered version */
@@ -77,10 +77,13 @@ ldap_back_add(
         * Rewrite the add dn, if needed
         */
 #ifdef ENABLE_REWRITE
-       switch (rewrite_session( li->rwinfo, "addDn", e->e_dn, conn, &mdn.bv_val )) {
+       switch (rewrite_session( li->rwinfo, "addDn", e->e_dn, conn, 
+                               &mdn.bv_val )) {
        case REWRITE_REGEXEC_OK:
-               if ( mdn.bv_val == NULL ) {
-                       mdn.bv_val = e->e_dn;
+               if ( mdn.bv_val != NULL && mdn.bv_val[ 0 ] != '\0' ) {
+                       mdn.bv_len = strlen( mdn.bv_val );
+               } else {
+                       mdn = e->e_name;
                }
 #ifdef NEW_LOGGING
                LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
@@ -162,16 +165,17 @@ ldap_back_add(
                attrs[i]->mod_vals.modv_bvals = ch_malloc((j+1)*sizeof(struct berval *));
                for (j=0; a->a_vals[j].bv_val; j++)
                        attrs[i]->mod_vals.modv_bvals[j] = &a->a_vals[j];
+               attrs[i]->mod_vals.modv_bvals[j] = NULL;
                i++;
        }
        attrs[i] = NULL;
 
        ldap_add_s(lc->ld, mdn.bv_val, attrs);
        for (--i; i>= 0; --i) {
-               free(attrs[i]->mod_vals.modv_bvals);
-               free(attrs[i]);
+               ch_free(attrs[i]->mod_vals.modv_bvals);
+               ch_free(attrs[i]);
        }
-       free(attrs);
+       ch_free(attrs);
        if ( mdn.bv_val != e->e_dn ) {
                free( mdn.bv_val );
        }
@@ -183,15 +187,14 @@ ldap_back_add(
 int
 ldap_dnattr_rewrite(
                struct rewrite_info     *rwinfo,
-               struct berval           **a_vals,
+               BerVarray                       a_vals,
                void                    *cookie
 )
 {
-       int j;
        char *mattr;
        
-       for ( j = 0; a_vals[ j ] != NULL; j++ ) {
-               switch ( rewrite_session( rwinfo, "bindDn", a_vals[ j ]->bv_val,
+       for ( ; a_vals->bv_val != NULL; a_vals++ ) {
+               switch ( rewrite_session( rwinfo, "bindDn", a_vals->bv_val,
                                        cookie, &mattr )) {
                case REWRITE_REGEXEC_OK:
                        if ( mattr == NULL ) {
@@ -202,17 +205,22 @@ ldap_dnattr_rewrite(
                        LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
                                        "[rw] bindDn (in add of dn-valued"
                                        " attr): \"%s\" -> \"%s\"\n",
-                                       a_vals[ j ]->bv_val, mattr ));
+                                       a_vals->bv_val, mattr ));
 #else /* !NEW_LOGGING */
                        Debug( LDAP_DEBUG_ARGS,
                                        "rw> bindDn (in add of dn-valued attr):"
                                        " \"%s\" -> \"%s\"\n%s",
-                                       a_vals[ j ]->bv_val, mattr, "" );
+                                       a_vals->bv_val, mattr, "" );
 #endif /* !NEW_LOGGING */
 
-                       free( a_vals[ j ]->bv_val );
-                       a_vals[ j ]->bv_val = mattr;
-                       a_vals[ j ]->bv_len = strlen( mattr );
+                       /*
+                        * FIXME: replacing server-allocated memory 
+                        * (ch_malloc) with librewrite allocated memory
+                        * (malloc)
+                        */
+                       ch_free( a_vals->bv_val );
+                       a_vals->bv_val = mattr;
+                       a_vals->bv_len = strlen( mattr );
                        
                        break;