diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2015-06-09 23:29:33 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2015-06-10 01:13:53 +0200 |
commit | b7eadfd310bc61e7a982dc8bce4eb32038a6fa09 (patch) | |
tree | 4de9e02ed3cf30e2c0af2b11ce333d356101628c /src | |
parent | a7a8d57bcaaaf4e5982d2e51cd3086d34f45f780 (diff) | |
download | VeraCrypt-b7eadfd310bc61e7a982dc8bce4eb32038a6fa09.tar.gz VeraCrypt-b7eadfd310bc61e7a982dc8bce4eb32038a6fa09.zip |
Windows: solve installer issue on Windows 10 caused by failure to overwrite VeraCrypt driver file.
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/Dlgcode.c | 37 | ||||
-rw-r--r-- | src/Common/Dlgcode.h | 4 | ||||
-rw-r--r-- | src/Format/InPlace.c | 4 | ||||
-rw-r--r-- | src/Setup/SelfExtract.c | 14 | ||||
-rw-r--r-- | src/Setup/Setup.c | 37 | ||||
-rw-r--r-- | src/Setup/Setup.h | 2 |
6 files changed, 70 insertions, 28 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 246f35a6..5e26ef0f 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -7519,20 +7519,49 @@ BOOL TCCopyFile (char *sourceFileName, char *destinationFile) }
// If bAppend is TRUE, the buffer is appended to an existing file. If bAppend is FALSE, any existing file
// is replaced. If an error occurs, the incomplete file is deleted (provided that bAppend is FALSE).
-BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend)
+BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed)
{
HANDLE dst;
DWORD bytesWritten;
BOOL res = TRUE;
+ DWORD dwLastError = 0;
dst = CreateFile (destinationFile,
GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, bAppend ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);
+ dwLastError = GetLastError();
+ if (!bAppend && bRenameIfFailed && (dst == INVALID_HANDLE_VALUE) && (GetLastError () == ERROR_SHARING_VIOLATION))
+ {
+ char renamedPath[TC_MAX_PATH + 1];
+ StringCbCopyA (renamedPath, sizeof(renamedPath), destinationFile);
+ StringCbCatA (renamedPath, sizeof(renamedPath), VC_FILENAME_RENAMED_SUFFIX);
+
+ /* rename the locked file in order to be able to create a new one */
+ if (MoveFileEx (destinationFile, renamedPath, MOVEFILE_REPLACE_EXISTING))
+ {
+ dst = CreateFile (destinationFile,
+ GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, bAppend ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);
+ dwLastError = GetLastError();
+ if (dst == INVALID_HANDLE_VALUE)
+ {
+ /* restore the original file name */
+ MoveFileEx (renamedPath, destinationFile, MOVEFILE_REPLACE_EXISTING);
+ }
+ else
+ {
+ /* delete the renamed file when the machine reboots */
+ MoveFileEx (renamedPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
+ }
+ }
+ }
+
if (dst == INVALID_HANDLE_VALUE)
{
+ SetLastError (dwLastError);
handleWin32Error (MainDlg);
return FALSE;
}
@@ -7602,16 +7631,16 @@ BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t textByteLen) StringCbCatA (path, sizeof(path), filename);
}
// Write the Unicode signature
- if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE))
+ if (!SaveBufferToFile ("\xFF\xFE", path, 2, FALSE, FALSE))
{
remove (path);
return FALSE;
}
// Write the actual text
- if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE))
+ if (!SaveBufferToFile ((char *) text, path, (DWORD) textByteLen, TRUE, FALSE))
{
remove (path);
return FALSE;
}
@@ -10067,9 +10096,9 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam }
finally_do_arg (vector <byte> *, &keyfileData, { burn (&finally_arg->front(), finally_arg->size()); });
- if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE))
+ if (!SaveBufferToFile ((char *) &keyfileData.front(), keyfilePath, (DWORD) keyfileData.size(), FALSE, FALSE))
throw SystemException ();
}
Info ("KEYFILE_EXPORTED", hwndDlg);
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h index a8d571dd..f6b285c4 100644 --- a/src/Common/Dlgcode.h +++ b/src/Common/Dlgcode.h @@ -76,8 +76,10 @@ enum #define TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE "In-Place Encryption Wipe Algo"
#define TC_APPD_FILENAME_POST_INSTALL_TASK_TUTORIAL "Post-Install Task - Tutorial"
#define TC_APPD_FILENAME_POST_INSTALL_TASK_RELEASE_NOTES "Post-Install Task - Release Notes"
+#define VC_FILENAME_RENAMED_SUFFIX "_old"
+
#ifndef USER_DEFAULT_SCREEN_DPI
#define USER_DEFAULT_SCREEN_DPI 96
#endif
@@ -350,9 +352,9 @@ HANDLE DismountDrive (char *devName, char *devicePath); int64 FindString (const char *buf, const char *str, int64 bufLen, int64 strLen, int64 startOffset);
BOOL FileExists (const char *filePathPtr);
__int64 FindStringInFile (const char *filePath, const char *str, int strLen);
BOOL TCCopyFile (char *sourceFileName, char *destinationFile);
-BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend);
+BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend, BOOL bRenameIfFailed);
BOOL TCFlushFile (FILE *f);
BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, size_t byteLen);
void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr);
BOOL IsNonInstallMode ();
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c index 043c1cd7..24303036 100644 --- a/src/Format/InPlace.c +++ b/src/Format/InPlace.c @@ -2006,9 +2006,9 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm, if (newWipeAlgorithm != TC_WIPE_NONE)
{
StringCbPrintfA (str, sizeof(str), "%d", (int) newWipeAlgorithm);
- SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), (DWORD) strlen(str), FALSE);
+ SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), (DWORD) strlen(str), FALSE, FALSE);
}
else if (FileExists (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)))
{
remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
@@ -2016,9 +2016,9 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm, }
StringCbPrintfA (str, sizeof(str), "%d", count);
- return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), (DWORD) strlen(str), FALSE);
+ return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), (DWORD) strlen(str), FALSE, FALSE);
}
// Repairs damaged sectors (i.e. those with read errors) by zeroing them.
diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c index 7169c991..a4acde26 100644 --- a/src/Setup/SelfExtract.c +++ b/src/Setup/SelfExtract.c @@ -296,9 +296,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir) }
// Write the start marker
- if (!SaveBufferToFile (MAG_START_MARKER, outputFile, strlen (MAG_START_MARKER), TRUE))
+ if (!SaveBufferToFile (MAG_START_MARKER, outputFile, strlen (MAG_START_MARKER), TRUE, FALSE))
{
if (remove (outputFile))
PkgError ("Cannot write the start marker\nFailed also to delete package file");
else
@@ -356,9 +356,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir) // Write total size of the uncompressed data
szTmp32bitPtr = szTmp32bit;
mputLong (szTmp32bitPtr, (unsigned __int32) uncompressedDataLen);
- if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE))
+ if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
{
if (remove (outputFile))
PkgError ("Cannot write the total size of the uncompressed data.\nFailed also to delete package file");
else
@@ -393,9 +393,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir) // Write the total size of the compressed data
szTmp32bitPtr = szTmp32bit;
mputLong (szTmp32bitPtr, (unsigned __int32) compressedDataLen);
- if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE))
+ if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
{
if (remove (outputFile))
PkgError ("Cannot write the total size of the compressed data.\nFailed also to delete package file");
else
@@ -403,9 +403,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir) goto err;
}
// Write the compressed data
- if (!SaveBufferToFile (compressedBuffer, outputFile, compressedDataLen, TRUE))
+ if (!SaveBufferToFile (compressedBuffer, outputFile, compressedDataLen, TRUE, FALSE))
{
if (remove (outputFile))
PkgError ("Cannot write compressed data to the package.\nFailed also to delete package file");
else
@@ -413,9 +413,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir) goto err;
}
// Write the end marker
- if (!SaveBufferToFile (MagEndMarker, outputFile, strlen (MagEndMarker), TRUE))
+ if (!SaveBufferToFile (MagEndMarker, outputFile, strlen (MagEndMarker), TRUE, FALSE))
{
if (remove (outputFile))
PkgError ("Cannot write the end marker.\nFailed also to delete package file");
else
@@ -449,9 +449,9 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, char *szDestDir) szTmp32bitPtr = szTmp32bit;
mputLong (szTmp32bitPtr, GetCrc32 (tmpBuffer, tmpFileSize));
free (tmpBuffer);
- if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE))
+ if (!SaveBufferToFile (szTmp32bit, outputFile, sizeof (szTmp32bit), TRUE, FALSE))
{
if (remove (outputFile))
PkgError ("Cannot write the total size of the compressed data.\nFailed also to delete package file");
else
@@ -744,9 +744,9 @@ void __cdecl ExtractAllFilesThread (void *hwndDlg) if (!SaveBufferToFile (
Decompressed_Files[fileNo].fileContent,
filePath,
Decompressed_Files[fileNo].fileLength,
- FALSE))
+ FALSE, FALSE))
{
wchar_t szTmp[512];
StringCbPrintfW (szTmp, sizeof (szTmp), GetString ("CANNOT_WRITE_FILE_X"), filePath);
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c index c52b311c..5f1c9300 100644 --- a/src/Setup/Setup.c +++ b/src/Setup/Setup.c @@ -85,12 +85,22 @@ void localcleanup (void) CloseAppSetupMutex ();
}
-BOOL StatDeleteFile (char *lpszFile)
+BOOL StatDeleteFile (char *lpszFile, BOOL bCheckForOldFile)
{
struct __stat64 st;
+ if (bCheckForOldFile)
+ {
+ char szOldPath[MAX_PATH + 1];
+ StringCbCopyA (szOldPath, sizeof(szOldPath), lpszFile);
+ StringCbCatA (szOldPath, sizeof(szOldPath), VC_FILENAME_RENAMED_SUFFIX);
+
+ if (_stat64 (szOldPath, &st) == 0)
+ DeleteFile (szOldPath);
+ }
+
if (_stat64 (lpszFile, &st) == 0)
return DeleteFile (lpszFile);
else
return TRUE;
@@ -724,9 +734,10 @@ BOOL DoFilesInstall (HWND hwndDlg, char *szDestDir) bResult = SaveBufferToFile (
(char *) Decompressed_Files[fileNo].fileContent,
szTmp,
Decompressed_Files[fileNo].fileLength,
- FALSE);
+ FALSE,
+ TRUE);
if (driver64)
{
if (!EnableWow64FsRedirection (TRUE))
@@ -768,9 +779,9 @@ BOOL DoFilesInstall (HWND hwndDlg, char *szDestDir) }
}
else
{
- bResult = StatDeleteFile (szTmp);
+ bResult = StatDeleteFile (szTmp, TRUE);
}
err:
if (bResult == FALSE)
@@ -1021,29 +1032,29 @@ BOOL DoApplicationDataUninstall (HWND hwndDlg) // Delete favorite volumes file
StringCbPrintfA (path2, sizeof(path2), "%s%s", path, TC_APPD_FILENAME_FAVORITE_VOLUMES);
RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2);
+ StatDeleteFile (path2, FALSE);
// Delete keyfile defaults
StringCbPrintfA (path2, sizeof(path2), "%s%s", path, TC_APPD_FILENAME_DEFAULT_KEYFILES);
RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2);
+ StatDeleteFile (path2, FALSE);
// Delete history file
StringCbPrintfA (path2, sizeof(path2), "%s%s", path, TC_APPD_FILENAME_HISTORY);
RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2);
+ StatDeleteFile (path2, FALSE);
// Delete configuration file
StringCbPrintfA (path2, sizeof(path2), "%s%s", path, TC_APPD_FILENAME_CONFIGURATION);
RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2);
+ StatDeleteFile (path2, FALSE);
// Delete system encryption configuration file
StringCbPrintfA (path2, sizeof(path2), "%s%s", path, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
RemoveMessage (hwndDlg, path2);
- StatDeleteFile (path2);
+ StatDeleteFile (path2, FALSE);
SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path);
StringCbCatA (path, sizeof(path), "\\VeraCrypt");
RemoveMessage (hwndDlg, path);
@@ -1490,24 +1501,24 @@ BOOL DoShortcutsUninstall (HWND hwndDlg, char *szDestDir) // Start menu entries
StringCbPrintfA (szTmp2, sizeof(szTmp2), "%s%s", szLinkDir, "\\VeraCrypt.lnk");
RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2) == FALSE)
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
goto error;
StringCbPrintfA (szTmp2, sizeof(szTmp2), "%s%s", szLinkDir, "\\VeraCryptExpander.lnk");
RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2) == FALSE)
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
goto error;
StringCbPrintfA (szTmp2, sizeof(szTmp2), "%s%s", szLinkDir, "\\VeraCrypt Website.url");
RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2) == FALSE)
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
goto error;
StringCbPrintfA (szTmp2, sizeof(szTmp2), "%s%s", szLinkDir, "\\Uninstall VeraCrypt.lnk");
RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2) == FALSE)
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
goto error;
StringCbPrintfA (szTmp2, sizeof(szTmp2), "%s%s", szLinkDir, "\\VeraCrypt User's Guide.lnk");
DeleteFile (szTmp2);
@@ -1526,9 +1537,9 @@ BOOL DoShortcutsUninstall (HWND hwndDlg, char *szDestDir) StringCbPrintfA (szTmp2, sizeof(szTmp2), "%s%s", szLinkDir, "\\VeraCrypt.lnk");
RemoveMessage (hwndDlg, szTmp2);
- if (StatDeleteFile (szTmp2) == FALSE)
+ if (StatDeleteFile (szTmp2, FALSE) == FALSE)
goto error;
bOK = TRUE;
diff --git a/src/Setup/Setup.h b/src/Setup/Setup.h index 5852f058..0b4b68ee 100644 --- a/src/Setup/Setup.h +++ b/src/Setup/Setup.h @@ -122,9 +122,9 @@ static char *szCompressedFiles[]= #define FILENAME_64BIT_DRIVER "veracrypt-x64.sys"
#define NBR_COMPRESSED_FILES (sizeof(szCompressedFiles) / sizeof(szCompressedFiles[0]))
void localcleanup (void);
-BOOL StatDeleteFile ( char *lpszFile );
+BOOL StatDeleteFile ( char *lpszFile, BOOL bCheckForOldFile );
BOOL StatRemoveDirectory ( char *lpszDir );
HRESULT CreateLink ( char *lpszPathObj , char *lpszArguments , char *lpszPathLink );
void GetProgramPath ( HWND hwndDlg , char *path );
void StatusMessage (HWND hwndDlg, char *stringId);
|