From b3646b323763441359cb953ebd78ef22f9ce428e Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 6 May 2015 20:38:30 +0200 Subject: Windows: Solve detection issue when resuming encryption. Add separate logic for manual selection of device and display error message in case of failure. --- src/Format/Tcformat.c | 81 +++++++++++++++++++++++++++++++++++++++------------ src/Format/Tcformat.h | 1 + 2 files changed, 64 insertions(+), 18 deletions(-) (limited to 'src/Format') diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c index 2617d9bd..ba35c47e 100644 --- a/src/Format/Tcformat.c +++ b/src/Format/Tcformat.c @@ -259,33 +259,77 @@ vector DeferredNonSysInPlaceEncDevices; void CALLBACK ResumeInPlaceEncWaitThreadProc(void* pArg, HWND hwndDlg) { char szDevicePath[MAX_PATH] = {0}; + RawDevicesDlgParam param; + param.devices = GetAvailableHostDevices (false, true, false); + param.pszFileName = szDevicePath; DeferredNonSysInPlaceEncDevices.clear(); - if (IDOK != DialogBoxParamW (hInst, + + if ((IDOK == DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg, - (DLGPROC) RawDevicesDlgProc, (LPARAM) & szDevicePath[0])) + (DLGPROC) RawDevicesDlgProc, (LPARAM) ¶m)) && strlen(szDevicePath)) { - szDevicePath[0] = 0; - } + foreach (const HostDevice &device, param.devices) + { + if (device.Path == szDevicePath) + { + OpenVolumeContext volume; + int status = OpenVolume (&volume, device.Path.c_str(), &volumePassword, hash_algo, FALSE, FALSE, FALSE, TRUE); + + if ( status == ERR_SUCCESS) + { + if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0 + && volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value) + { + DeferredNonSysInPlaceEncDevices.push_back (device); + } + else if (volume.CryptoInfo->EncryptedAreaLength.Value == volume.CryptoInfo->VolumeSize.Value) + { + WCHAR szMsg[1024]; + StringCbPrintfW(szMsg, sizeof(szMsg), GetString ("SELECTED_PARTITION_ALREADY_INPLACE_ENC"), + volume.CryptoInfo->HeaderFlags); + ErrorDirect(szMsg, hwndDlg); + } + else + { + WCHAR szMsg[1024]; + StringCbPrintfW(szMsg, sizeof(szMsg), GetString ("SELECTED_PARTITION_NOT_INPLACE_ENC"), + volume.CryptoInfo->HeaderFlags); + ErrorDirect(szMsg, hwndDlg); + } - foreach (const HostDevice &device, GetAvailableHostDevices (true, true)) + CloseVolume (&volume); + } + else + { + handleError(hwndDlg, status); + } + + break; + } + } + } + else { - if (device.IsPartition || device.DynamicVolume) + foreach (const HostDevice &device, param.devices) { - if ((strlen(szDevicePath) > 0) && (device.Path != szDevicePath)) - continue; + if ( !device.ContainsSystem + && (device.IsPartition || device.DynamicVolume || device.IsVirtualPartition || device.Partitions.empty()) + ) + { - OpenVolumeContext volume; + OpenVolumeContext volume; - if (OpenVolume (&volume, device.Path.c_str(), &volumePassword, hash_algo, FALSE, FALSE, FALSE, TRUE) == ERR_SUCCESS) - { - if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0 - && volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value) + if (OpenVolume (&volume, device.Path.c_str(), &volumePassword, hash_algo, FALSE, FALSE, FALSE, TRUE) == ERR_SUCCESS) { - DeferredNonSysInPlaceEncDevices.push_back (device); - } + if ((volume.CryptoInfo->HeaderFlags & TC_HEADER_FLAG_NONSYS_INPLACE_ENC) != 0 + && volume.CryptoInfo->EncryptedAreaLength.Value != volume.CryptoInfo->VolumeSize.Value) + { + DeferredNonSysInPlaceEncDevices.push_back (device); + } - CloseVolume (&volume); + CloseVolume (&volume); + } } } } @@ -5232,10 +5276,11 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa else { // Select device - + RawDevicesDlgParam param; + param.pszFileName = szFileName; int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), GetParent (hwndDlg), - (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]); + (DLGPROC) RawDevicesDlgProc, (LPARAM) & param); // Check administrator privileges if (!strstr (szFileName, "Floppy") && !IsAdmin() && !IsUacSupported ()) diff --git a/src/Format/Tcformat.h b/src/Format/Tcformat.h index cea36ccd..77579f54 100644 --- a/src/Format/Tcformat.h +++ b/src/Format/Tcformat.h @@ -94,6 +94,7 @@ extern __int64 NonSysInplaceEncBytesDone; extern __int64 NonSysInplaceEncTotalSize; extern int nPbar; extern volatile int WizardMode; +extern volatile BOOL bInPlaceEncNonSysResumed; extern char HeaderKeyGUIView [KEY_GUI_VIEW_SIZE]; extern char MasterKeyGUIView [KEY_GUI_VIEW_SIZE]; -- cgit v1.2.3