From e95326b565bada7326ea2a369dc76e216f01a69e Mon Sep 17 00:00:00 2001 From: "javi%netscape.com" Date: Fri, 29 Jun 2001 04:35:04 +0000 Subject: [PATCH] Fix for Bug 88256 r=mcgree, sr=brendan Fix PKCS12 backup so that it works on the Mac. Use nsILocalFile::OpenNSPRFileDesc to get a PRFileDesc* instead of PR_Open since PR_Open doesn't deal with native paths on the Mac at all. git-svn-id: svn://10.0.0.236/trunk@98246 18797224-902f-48f8-a5cc-f745e15eee43 --- .../security/manager/ssl/src/nsPKCS12Blob.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp b/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp index 91b2a08ea7b..048dc3006f6 100644 --- a/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp +++ b/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp @@ -31,7 +31,7 @@ * may use your version of this file under either the MPL or the * GPL. * - * $Id: nsPKCS12Blob.cpp,v 1.13 2001-06-24 19:15:59 mcgreer%netscape.com Exp $ + * $Id: nsPKCS12Blob.cpp,v 1.14 2001-06-29 04:35:04 javi%netscape.com Exp $ */ #include "prmem.h" @@ -250,6 +250,7 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, nsXPIDLCString xpidlFilePath; nsAutoString filePath; int i; + nsCOMPtr localFileRef; NS_ASSERTION(mToken, "Need to set the token before exporting"); // init slot rv = mToken->Login(PR_TRUE); @@ -330,12 +331,22 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, this->mTmpFile = NULL; file->GetPath(getter_Copies(xpidlFilePath)); filePath.AssignWithConversion(xpidlFilePath); + // Use the nsCOMPtr var localFileRef so that + // the reference to the nsILocalFile we create gets released as soon as + // we're out of scope, ie when this function exits. if (filePath.RFind(".p12", PR_TRUE, -1, 4) < 0) { + // We're going to add the .p12 extension to the file name just like + // Communicator used to. We create a new nsILocalFile and initialize + // it with the new patch. filePath.AppendWithConversion(".p12"); + localFileRef = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); + if (NS_FAILED(rv)) goto finish; + localFileRef->InitWithUnicodePath(filePath.get()); + file = localFileRef; } - this->mTmpFile = PR_Open(NS_ConvertUCS2toUTF8(filePath.get()).get(), - PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0600); - if (!this->mTmpFile) goto finish; + rv = file->OpenNSPRFileDesc(PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0664, + &mTmpFile); + if (NS_FAILED(rv) || !this->mTmpFile) goto finish; // encode and write srv = SEC_PKCS12Encode(ecx, write_export_file, this); if (srv) goto finish;