]> git.sur5r.net Git - openldap/commitdiff
Fixed slapd/back-ldbm memory leak of lastmod attributes (ITS#249 ITS#250)
authorKurt Zeilenga <kurt@openldap.org>
Fri, 20 Aug 1999 18:27:50 +0000 (18:27 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 20 Aug 1999 18:27:50 +0000 (18:27 +0000)
CHANGES
servers/slapd/back-ldbm/modify.c
servers/slapd/modify.c

diff --git a/CHANGES b/CHANGES
index 55b23619f09fe35abd4e3c87275be76c0e4d03d3..6c7764558f3d4e91b14fe24b287cc60d9dd5845e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,7 @@ OpenLDAP Change Log
 
 Changes included in OpenLDAP 1.2 Release Engineering
        CVS Tag: OPENLDAP_REL_ENG_1_2
+       Fixed slapd/back-ldbm memory leak of lastmod attributes (ITS#249 ITS#250)
        Added ldapsearch -W password prompting
        Added dcObject, uidObject, referral object classes to slapd.oc.conf
        Added ref attribute type to slapd.at.conf
index 2f0ea3673b36e5aaf92ab166684416c0704c3654..2f3191308025a15786607387337049a8e23058e8 100644 (file)
 static int     add_values(Entry *e, LDAPMod *mod, char *dn);
 static int     delete_values(Entry *e, LDAPMod *mod, char *dn);
 static int     replace_values(Entry *e, LDAPMod *mod, char *dn);
-static void    add_lastmods(Operation *op, LDAPMod **mods);
-
-
-static void
-add_lastmods( Operation *op, LDAPMod **mods )
-{
-       char            buf[22];
-       struct berval   bv;
-       struct berval   *bvals[2];
-       LDAPMod         **m;
-       LDAPMod         *tmp;
-       struct tm       *ltm;
-
-       Debug( LDAP_DEBUG_TRACE, "add_lastmods\n", 0, 0, 0 );
-
-       bvals[0] = &bv;
-       bvals[1] = NULL;
-
-       /* remove any attempts by the user to modify these attrs */
-       for ( m = mods; *m != NULL; m = &(*m)->mod_next ) {
-            if ( strcasecmp( (*m)->mod_type, "modifytimestamp" ) == 0 || 
-                               strcasecmp( (*m)->mod_type, "modifiersname" ) == 0 ||
-                               strcasecmp( (*m)->mod_type, "createtimestamp" ) == 0 || 
-                               strcasecmp( (*m)->mod_type, "creatorsname" ) == 0 ) {
-
-                Debug( LDAP_DEBUG_TRACE,
-                                       "add_lastmods: found lastmod attr: %s\n",
-                                       (*m)->mod_type, 0, 0 );
-                tmp = *m;
-                *m = (*m)->mod_next;
-                free( tmp->mod_type );
-                if ( tmp->mod_bvalues != NULL ) {
-                    ber_bvecfree( tmp->mod_bvalues );
-                }
-                free( tmp );
-                if (!*m)
-                    break;
-            }
-        }
-
-       if ( op->o_dn == NULL || op->o_dn[0] == '\0' ) {
-               bv.bv_val = "NULLDN";
-               bv.bv_len = strlen( bv.bv_val );
-       } else {
-               bv.bv_val = op->o_dn;
-               bv.bv_len = strlen( bv.bv_val );
-       }
-       tmp = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) );
-       tmp->mod_type = ch_strdup( "modifiersname" );
-       tmp->mod_op = LDAP_MOD_REPLACE;
-       tmp->mod_bvalues = (struct berval **) ch_calloc( 1,
-           2 * sizeof(struct berval *) );
-       tmp->mod_bvalues[0] = ber_bvdup( &bv );
-       tmp->mod_next = *mods;
-       *mods = tmp;
-
-       ldap_pvt_thread_mutex_lock( &currenttime_mutex );
-#ifndef LDAP_LOCALTIME
-       ltm = gmtime( &currenttime );
-       strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
-#else
-       ltm = localtime( &currenttime );
-       strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
-#endif
-       ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
-       bv.bv_val = buf;
-       bv.bv_len = strlen( bv.bv_val );
-       tmp = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) );
-       tmp->mod_type = ch_strdup( "modifytimestamp" );
-       tmp->mod_op = LDAP_MOD_REPLACE;
-       tmp->mod_bvalues = (struct berval **) ch_calloc( 1, 2 * sizeof(struct berval *) );
-       tmp->mod_bvalues[0] = ber_bvdup( &bv );
-       tmp->mod_next = *mods;
-       *mods = tmp;
-}
 
 /* We need this function because of LDAP modrdn. If we do not 
  * add this there would be a bunch of code replication here 
@@ -110,17 +35,6 @@ int ldbm_internal_modify(
        Attribute       *a;
        Attribute       *save_attrs;
 
-       if ( ((be->be_lastmod == ON)
-             || ((be->be_lastmod == UNDEFINED)&&(global_lastmod == ON)))
-            && (be->be_update_ndn == NULL)) {
-
-               /* XXX: It may be wrong, it changes mod time even if 
-                * mod fails! I also Think this is leaking memory...
-                */
-               add_lastmods( op, &mods );
-
-       }
-
        if ( (err = acl_check_mods( be, conn, op, e, mods )) != LDAP_SUCCESS ) {
                send_ldap_result( conn, op, err, NULL, NULL );
                return -1;
index 44982c11dddaed2d15d94e6f8d0d90c1210b0515..6ba1ef9bddab046b511e4f7c26cf749e2e07241c 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "slap.h"
 
+static void add_lastmods( Operation *op, LDAPMod **mods );
 static void    modlist_free(LDAPMod *mods);
 
 
@@ -153,6 +154,11 @@ do_modify(
                if ( be->be_update_ndn == NULL ||
                        strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
                {
+                       if(( be->be_lastmod == ON || (be->be_lastmod == UNDEFINED
+                               && global_lastmod == ON )) && be->be_update_ndn == NULL )
+                       {
+                               add_lastmods( op, &mods );
+                       }
 
                        if ( (*be->be_modify)( be, conn, op, ndn, mods ) == 0 ) {
                                replog( be, LDAP_REQ_MODIFY, ndn, mods, 0 );
@@ -172,6 +178,80 @@ do_modify(
        modlist_free( mods );
 }
 
+static void
+add_lastmods( Operation *op, LDAPMod **mods )
+{
+       char            buf[22];
+       struct berval   bv;
+       struct berval   *bvals[2];
+       LDAPMod         **m;
+       LDAPMod         *tmp;
+       struct tm       *ltm;
+
+       Debug( LDAP_DEBUG_TRACE, "add_lastmods\n", 0, 0, 0 );
+
+       bvals[0] = &bv;
+       bvals[1] = NULL;
+
+       /* remove any attempts by the user to modify these attrs */
+       for ( m = mods; *m != NULL; m = &(*m)->mod_next ) {
+            if ( strcasecmp( (*m)->mod_type, "modifytimestamp" ) == 0 || 
+                               strcasecmp( (*m)->mod_type, "modifiersname" ) == 0 ||
+                               strcasecmp( (*m)->mod_type, "createtimestamp" ) == 0 || 
+                               strcasecmp( (*m)->mod_type, "creatorsname" ) == 0 ) {
+
+                Debug( LDAP_DEBUG_TRACE,
+                                       "add_lastmods: found lastmod attr: %s\n",
+                                       (*m)->mod_type, 0, 0 );
+                tmp = *m;
+                *m = (*m)->mod_next;
+                free( tmp->mod_type );
+                if ( tmp->mod_bvalues != NULL ) {
+                    ber_bvecfree( tmp->mod_bvalues );
+                }
+                free( tmp );
+                if (!*m)
+                    break;
+            }
+        }
+
+       if ( op->o_dn == NULL || op->o_dn[0] == '\0' ) {
+               bv.bv_val = "NULLDN";
+               bv.bv_len = strlen( bv.bv_val );
+       } else {
+               bv.bv_val = op->o_dn;
+               bv.bv_len = strlen( bv.bv_val );
+       }
+       tmp = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) );
+       tmp->mod_type = ch_strdup( "modifiersname" );
+       tmp->mod_op = LDAP_MOD_REPLACE;
+       tmp->mod_bvalues = (struct berval **) ch_calloc( 1,
+           2 * sizeof(struct berval *) );
+       tmp->mod_bvalues[0] = ber_bvdup( &bv );
+       tmp->mod_next = *mods;
+       *mods = tmp;
+
+       ldap_pvt_thread_mutex_lock( &currenttime_mutex );
+#ifndef LDAP_LOCALTIME
+       ltm = gmtime( &currenttime );
+       strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
+#else
+       ltm = localtime( &currenttime );
+       strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
+#endif
+       ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
+       bv.bv_val = buf;
+       bv.bv_len = strlen( bv.bv_val );
+       tmp = (LDAPMod *) ch_calloc( 1, sizeof(LDAPMod) );
+       tmp->mod_type = ch_strdup( "modifytimestamp" );
+       tmp->mod_op = LDAP_MOD_REPLACE;
+       tmp->mod_bvalues = (struct berval **) ch_calloc( 1, 2 * sizeof(struct berval *) );
+       tmp->mod_bvalues[0] = ber_bvdup( &bv );
+       tmp->mod_next = *mods;
+       *mods = tmp;
+}
+
+
 static void
 modlist_free(
     LDAPMod    *mods