diff options
author | mharmsen <mharmsen@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2009-02-12 18:35:32 +0000 |
---|---|---|
committer | mharmsen <mharmsen@c9f7a03b-bd48-0410-a16d-cbbf54688b0b> | 2009-02-12 18:35:32 +0000 |
commit | 7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec (patch) | |
tree | 5dafd62821ed01a6d5540b5b9b02f3f19677f7a7 /pki/base/common/src/com/netscape/cmscore | |
parent | 7315a95377ee364d8f14c68ef4a469fc7dae743d (diff) | |
download | pki-7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec.tar.gz pki-7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec.tar.xz pki-7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec.zip |
Bugzilla Bug #467155 - Change "renameTo" to "cp -p ".
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@225 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/base/FileConfigStore.java | 48 | ||||
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java | 40 |
2 files changed, 72 insertions, 16 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/base/FileConfigStore.java b/pki/base/common/src/com/netscape/cmscore/base/FileConfigStore.java index 35e5f3e8c..e9cd48a57 100644 --- a/pki/base/common/src/com/netscape/cmscore/base/FileConfigStore.java +++ b/pki/base/common/src/com/netscape/cmscore/base/FileConfigStore.java @@ -22,6 +22,7 @@ import java.io.*; import java.util.*; import com.netscape.certsrv.base.*; import com.netscape.certsrv.apps.CMS; +import com.netscape.cmsutil.util.Utils; /** @@ -78,7 +79,8 @@ public class FileConfigStore extends PropConfigStore implements } /** - * The original config file is moved to <filename>.<date>. + * The original config file is copied to + * <filename>.<current_time_in_milliseconds>. * Commits the current properties to the configuration file. * <P> * @@ -89,12 +91,48 @@ public class FileConfigStore extends PropConfigStore implements File newName = new File(mFile.getPath() + "." + Long.toString(System.currentTimeMillis())); - if (!mFile.renameTo(newName)) { - throw new EBaseException("rename failed"); + try { + if( Utils.isNT() ) { + // NT is very picky on the path + Utils.exec( "copy " + + mFile.getAbsolutePath().replace( '/', '\\' ) + + " " + + newName.getAbsolutePath().replace( '/', + '\\' ) ); + } else { + // Create a copy of the original file which + // preserves the original file permissions. + Utils.exec( "cp -p " + mFile.getAbsolutePath() + " " + + newName.getAbsolutePath() ); + } + + // Proceed only if the backup copy was successful. + if( !newName.exists() ) { + throw new EBaseException( "backup copy failed" ); + } else { + // Make certain that the backup file has + // the correct permissions. + if( !Utils.isNT() ) { + Utils.exec( "chmod 00660 " + newName.getAbsolutePath() ); + } + } + } catch( EBaseException e ) { + throw new EBaseException( "backup copy failed" ); + } + } + + // Overwrite the contents of the original file + // to preserve the original file permissions. + save( mFile.getPath() ); + + try { + // Make certain that the original file retains + // the correct permissions. + if( !Utils.isNT() ) { + Utils.exec( "chmod 00660 " + mFile.getCanonicalPath() ); } + } catch( Exception e ) { } - // proceed only if the rename is successful - save(mFile.getPath()); } /** diff --git a/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java b/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java index abba2dcec..234a425d7 100644 --- a/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java +++ b/pki/base/common/src/com/netscape/cmscore/security/PWsdrCache.java @@ -35,6 +35,7 @@ import com.netscape.cmscore.base.*; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.logging.ILogger; +import com.netscape.cmsutil.util.Utils; /* @@ -384,20 +385,37 @@ public class PWsdrCache { File origFile = new File(mPWcachedb); try { - if (tmpPWcache.renameTo(origFile) == true) { - debug("operation completed for " + mPWcachedb); + if( Utils.isNT() ) { + // NT is very picky on the path + Utils.exec( "copy " + + tmpPWcache.getAbsolutePath().replace( '/', + '\\' ) + + " " + + origFile.getAbsolutePath().replace( '/', + '\\' ) ); } else { - if (isNT()) { - // NT is very picky on the path - exec("copy " + - tmpPWcache.getAbsolutePath().replace('/', '\\') + " " + - origFile.getAbsolutePath().replace('/', '\\')); - } else { - exec("cp " + tmpPWcache.getAbsolutePath() + " " + - origFile.getAbsolutePath()); + // Create a copy of the original file which + // preserves the original file permissions. + Utils.exec( "cp -p " + tmpPWcache.getAbsolutePath() + " " + + origFile.getAbsolutePath() ); + } + + // Remove the original file if and only if + // the backup copy was successful. + if( origFile.exists() ) { + if( !Utils.isNT() ) { + try { + Utils.exec( "chmod 00660 " + + origFile.getCanonicalPath() ); + } catch( IOException e ) { + CMS.debug( "Unable to change file permissions on " + + origFile.toString() ); + } } + tmpPWcache.delete(); + debug( "operation completed for " + mPWcachedb ); } - } catch (EBaseException exx) { + } catch (Exception exx) { log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_SECURITY_PW_CACHE", exx.toString())); throw new EBaseException(exx.toString() + ": " + mPWcachedb); } |