From: Kurt Zeilenga Date: Fri, 20 Aug 1999 18:27:50 +0000 (+0000) Subject: Fixed slapd/back-ldbm memory leak of lastmod attributes (ITS#249 ITS#250) X-Git-Tag: OPENLDAP_REL_ENG_1_2_7~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1f0e487bc0a9a84dbeaa6c82275fb4b869cfd78;p=thirdparty%2Fopenldap.git Fixed slapd/back-ldbm memory leak of lastmod attributes (ITS#249 ITS#250) --- diff --git a/CHANGES b/CHANGES index 55b23619f0..6c7764558f 100644 --- 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 diff --git a/servers/slapd/back-ldbm/modify.c b/servers/slapd/back-ldbm/modify.c index 2f0ea3673b..2f31913080 100644 --- a/servers/slapd/back-ldbm/modify.c +++ b/servers/slapd/back-ldbm/modify.c @@ -14,81 +14,6 @@ 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( ¤ttime_mutex ); -#ifndef LDAP_LOCALTIME - ltm = gmtime( ¤ttime ); - strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm ); -#else - ltm = localtime( ¤ttime ); - strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm ); -#endif - ldap_pvt_thread_mutex_unlock( ¤ttime_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; diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 44982c11dd..6ba1ef9bdd 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -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( ¤ttime_mutex ); +#ifndef LDAP_LOCALTIME + ltm = gmtime( ¤ttime ); + strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm ); +#else + ltm = localtime( ¤ttime ); + strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm ); +#endif + ldap_pvt_thread_mutex_unlock( ¤ttime_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