summaryrefslogtreecommitdiffstats
path: root/pki/base/java-tools/src
diff options
context:
space:
mode:
authormharmsen <mharmsen@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2009-02-12 18:35:32 +0000
committermharmsen <mharmsen@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2009-02-12 18:35:32 +0000
commit7afb54c93ae56ea4bf09fc5012045b4e7c19a9ec (patch)
tree5dafd62821ed01a6d5540b5b9b02f3f19677f7a7 /pki/base/java-tools/src
parent7315a95377ee364d8f14c68ef4a469fc7dae743d (diff)
downloadpki-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/java-tools/src')
-rw-r--r--pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java49
1 files changed, 38 insertions, 11 deletions
diff --git a/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java b/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
index 388fedcd8..2031337de 100644
--- a/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
+++ b/pki/base/java-tools/src/com/netscape/cmstools/PasswordCache.java
@@ -612,28 +612,55 @@ class PWsdrCache {
if (tmpPWcache.exists()) {
// it wasn't removed?
tmpPWcache.delete();
- tmpPWcache = new File(mPWcachedb + ".tmp");
}
FileOutputStream outstream = new FileOutputStream(mPWcachedb + ".tmp");
outstream.write(writebuf);
outstream.close();
+ // Make certain that this temporary file has
+ // the correct permissions.
+ if( !isNT() ) {
+ exec( "chmod 00660 " + tmpPWcache.getAbsolutePath() );
+ }
+
File origFile = new File(mPWcachedb);
try {
- if (tmpPWcache.renameTo(origFile) == true) {
- debug("operation completed for " + mPWcachedb);
+ // Always remove any pre-existing target file
+ if( origFile.exists() ) {
+ origFile.delete();
+ }
+
+ if (isNT()) {
+ // NT is very picky on the path
+ 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 temporary file which
+ // preserves the temporary file's permissions.
+ exec("cp -p " + tmpPWcache.getAbsolutePath() + " " +
+ origFile.getAbsolutePath());
+ }
+
+ // Remove the temporary file if and only if
+ // the "rename" was successful.
+ if( origFile.exists() ) {
+ tmpPWcache.delete();
+
+ // Make certain that the final file has
+ // the correct permissions.
+ if( !isNT() ) {
+ exec( "chmod 00660 " + origFile.getAbsolutePath() );
}
+
+ // report success
+ debug( "Renaming operation completed for " + mPWcachedb );
+ } else {
+ // report failure and exit
+ debug( "Renaming operation failed for " + mPWcachedb );
+ System.exit(1);
}
} catch (IOException exx) {
System.out.println("sdrPWcache: Error " + exx.toString());