diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-07-27 00:15:16 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-07-27 00:30:54 +0200 |
commit | aaa9a08bd48d73c6e17aa00a3fff883a2c3a716b (patch) | |
tree | e6c45d0b9b97a92dcf53e55c4e04455f5df35f85 /src | |
parent | 72b7147021a18ea6a045514fa7cad7772c4bb811 (diff) | |
download | VeraCrypt-aaa9a08bd48d73c6e17aa00a3fff883a2c3a716b.tar.gz VeraCrypt-aaa9a08bd48d73c6e17aa00a3fff883a2c3a716b.zip |
Windows: when mounting system favorites using VolumeID feature, query all disks each time instead of caching previous call results. This is not efficient but it should fix rare cases where issues happen.
Diffstat (limited to 'src')
-rw-r--r-- | src/Common/Dlgcode.c | 68 | ||||
-rw-r--r-- | src/Common/Dlgcode.h | 4 | ||||
-rw-r--r-- | src/Mount/Mount.c | 18 |
3 files changed, 50 insertions, 40 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index a6362dfb..ec805e40 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -7659,7 +7659,7 @@ static BOOL PerformMountIoctl (MOUNT_STRUCT* pmount, LPDWORD pdwResult, BOOL use { if (useVolumeID) { - wstring devicePath = FindDeviceByVolumeID (volumeID); + wstring devicePath = FindDeviceByVolumeID (volumeID, FALSE); if (devicePath == L"") { if (pdwResult) @@ -11882,11 +11882,8 @@ void AddDeviceToList (std::vector<HostDevice>& devices, int devNumber, int partN devices.push_back (device); } -std::vector <HostDevice> GetHostRawDeviceList (bool bFromService) +std::vector <HostDevice> GetHostRawDeviceList () { - if (bFromService) - return GetAvailableHostDevices (true, false, true, true); - std::vector <HostDevice> list; HDEVINFO diskClassDevices; GUID diskClassDeviceInterfaceGuid = GUID_DEVINTERFACE_DISK; @@ -11999,7 +11996,7 @@ bool CompareDeviceList (const std::vector<HostDevice>& list1, const std::vector< return true; } -void UpdateMountableHostDeviceList (bool bFromService) +void UpdateMountableHostDeviceList () { ByteArray buffer(4096); DWORD bytesReturned; @@ -12008,7 +12005,7 @@ void UpdateMountableHostDeviceList (bool bFromService) EnterCriticalSection (&csMountableDevices); finally_do ({ LeaveCriticalSection (&csMountableDevices); }); - std::vector<HostDevice> newList = GetHostRawDeviceList (bFromService); + std::vector<HostDevice> newList = GetHostRawDeviceList (); std::map<DWORD, bool> existingDevicesMap; if (CompareDeviceList (newList, rawHostDeviceList)) @@ -12051,21 +12048,6 @@ void UpdateMountableHostDeviceList (bool bFromService) if (existingDevicesMap[It->SystemNumber]) continue; - if (bFromService) - { - if (It->Partitions.empty()) - mountableDevices.push_back (*It); - else - { - for (std::vector<HostDevice>::iterator partIt = It->Partitions.begin(); partIt != It->Partitions.end(); partIt++) - { - if (!partIt->ContainsSystem && !partIt->HasUnencryptedFilesystem) - mountableDevices.push_back (*partIt); - } - } - } - else - { HANDLE disk = CreateFile( It->Path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -12156,15 +12138,14 @@ void UpdateMountableHostDeviceList (bool bFromService) if (!bHasPartition) AddDeviceToList (mountableDevices, It->SystemNumber, 0); - CloseHandle (disk); - } + CloseHandle (disk); } } rawHostDeviceList = newList; // Starting from Vista, Windows does not create partition links for dynamic volumes so it is necessary to scan \\Device\\HarddiskVolumeX devices - if (!bFromService && dynamicVolumesPresent && (CurrentOSMajor >= 6)) + if (dynamicVolumesPresent && (CurrentOSMajor >= 6)) { for (int devNumber = 0; devNumber < 256; devNumber++) { @@ -12190,10 +12171,8 @@ void UpdateMountableHostDeviceList (bool bFromService) } } -wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE]) +wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE], BOOL bFromService) { - static std::vector<HostDevice> volumeIdCandidates; - /* if it is already mounted, get the real path name used for mounting */ MOUNT_LIST_STRUCT mlist; DWORD dwResult; @@ -12224,6 +12203,36 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE]) /* not mounted. Look for it in the local drives*/ + if (bFromService) + { + for (int devNumber = 0; devNumber < MAX_HOST_DRIVE_NUMBER; devNumber++) + { + for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++) + { + wstringstream strm; + strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber; + wstring devPathStr (strm.str()); + const wchar_t *devPath = devPathStr.c_str(); + + OPEN_TEST_STRUCT openTest = {0}; + if (OpenDevice (devPath, &openTest, TRUE, TRUE) + && (openTest.VolumeIDComputed[TC_VOLUME_TYPE_NORMAL] && openTest.VolumeIDComputed[TC_VOLUME_TYPE_HIDDEN]) + ) + { + if ( (0 == memcmp (volumeID, openTest.volumeIDs[TC_VOLUME_TYPE_NORMAL], VOLUME_ID_SIZE)) + || (0 == memcmp (volumeID, openTest.volumeIDs[TC_VOLUME_TYPE_HIDDEN], VOLUME_ID_SIZE)) + ) + { + return devPath; + } + } + } + } + } + else + { + static std::vector<HostDevice> volumeIdCandidates; + EnterCriticalSection (&csMountableDevices); std::vector<HostDevice> newDevices = mountableDevices; LeaveCriticalSection (&csMountableDevices); @@ -12297,6 +12306,7 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE]) return It->Path; } } + } return L""; } @@ -12924,7 +12934,7 @@ BOOL TranslateVolumeID (HWND hwndDlg, wchar_t* pathValue, size_t cchPathValue) && (arr.size() == VOLUME_ID_SIZE) ) { - std::wstring devicePath = FindDeviceByVolumeID (&arr[0]); + std::wstring devicePath = FindDeviceByVolumeID (&arr[0], FALSE); if (devicePath.length() > 0) StringCchCopyW (pathValue, cchPathValue, devicePath.c_str()); else diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h index a997bfa8..309ceac5 100644 --- a/src/Common/Dlgcode.h +++ b/src/Common/Dlgcode.h @@ -621,7 +621,7 @@ std::wstring GetUserFriendlyVersionString (int version); std::wstring IntToWideString (int val); std::wstring ArrayToHexWideString (const unsigned char* pbData, int cbData); bool HexWideStringToArray (const wchar_t* hexStr, std::vector<byte>& arr); -std::wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE]); +std::wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE], BOOL bFromService); void RegisterDriverInf (bool registerFilter, const std::string& filter, const std::string& filterReg, HWND ParentWindow, HKEY regKey); std::wstring GetTempPathString (); void CorrectFileName (std::wstring& fileName); @@ -629,7 +629,7 @@ inline std::wstring AppendSrcPos (const wchar_t* msg, const char* srcPos) { return std::wstring (msg? msg : L"") + L"\n\nSource: " + SingleStringToWide (srcPos); } -void UpdateMountableHostDeviceList (bool bFromService); +void UpdateMountableHostDeviceList (); INT_PTR TextEditDialogBox (BOOL readOnly, HWND parent, const WCHAR* Title, std::string& text); // Display a wait dialog while calling the provided callback with the given parameter diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index ec612a16..4333bb65 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -495,7 +495,7 @@ static void InitMainDialog (HWND hwndDlg) } // initialize the list of devices available for mounting as early as possible - UpdateMountableHostDeviceList (false); + UpdateMountableHostDeviceList (); // Resize the logo bitmap if the user has a non-default DPI if (ScreenDPI != USER_DEFAULT_SCREEN_DPI @@ -7119,7 +7119,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa { if (wParam == TIMER_ID_UPDATE_DEVICE_LIST) { - UpdateMountableHostDeviceList (false); + UpdateMountableHostDeviceList (); } else { @@ -7195,7 +7195,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa if (IsMountedVolumeID (favorite.VolumeID)) continue; - std::wstring volDevPath = FindDeviceByVolumeID (favorite.VolumeID); + std::wstring volDevPath = FindDeviceByVolumeID (favorite.VolumeID, FALSE); if (volDevPath.length() > 0) { favorite.Path = volDevPath; @@ -8486,7 +8486,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa std::wstring volName; WaitCursor(); if (FavoriteVolumes[favoriteIndex].UseVolumeID) - volName = FindDeviceByVolumeID (FavoriteVolumes[favoriteIndex].VolumeID); + volName = FindDeviceByVolumeID (FavoriteVolumes[favoriteIndex].VolumeID, FALSE); else volName = FavoriteVolumes[favoriteIndex].Path; OpenVolumeExplorerWindow (GetMountedVolumeDriveNo ((wchar_t*) FavoriteVolumes[favoriteIndex].Path.c_str())); @@ -9172,7 +9172,7 @@ static VOID WINAPI SystemFavoritesServiceMain (DWORD argc, LPTSTR *argv) SystemFavoritesServiceLogInfo (wstring (L"Initializing list of host devices")); // initialize the list of devices available for mounting as early as possible - UpdateMountableHostDeviceList (true); + UpdateMountableHostDeviceList (); SystemFavoritesServiceLogInfo (wstring (L"Starting System Favorites mounting process")); @@ -9479,7 +9479,7 @@ static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite, if (favorite.UseVolumeID && !IsRepeatedByteArray (0, favorite.VolumeID, sizeof (favorite.VolumeID))) { - effectiveVolumePath = FindDeviceByVolumeID (favorite.VolumeID); + effectiveVolumePath = FindDeviceByVolumeID (favorite.VolumeID, (ServiceMode && systemFavorites)? TRUE : FALSE); } else effectiveVolumePath = favorite.Path; @@ -9645,7 +9645,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO { if (favorite->UseVolumeID) { - std::wstring path = FindDeviceByVolumeID (favorite->VolumeID); + std::wstring path = FindDeviceByVolumeID (favorite->VolumeID, TRUE); if (path.empty ()) { favorite->DisconnectedDevice = true; @@ -9706,7 +9706,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO Sleep (5000); SystemFavoritesServiceLogInfo (wstring (L"Updating list of host devices")); - UpdateMountableHostDeviceList (true); + UpdateMountableHostDeviceList (); SystemFavoritesServiceLogInfo (wstring (L"Trying to mount skipped system favorites")); @@ -9723,7 +9723,7 @@ BOOL MountFavoriteVolumes (HWND hwnd, BOOL systemFavorites, BOOL logOnMount, BOO wstring resolvedPath; if (favorite->UseVolumeID) { - resolvedPath = FindDeviceByVolumeID (favorite->VolumeID); + resolvedPath = FindDeviceByVolumeID (favorite->VolumeID, TRUE); } else resolvedPath = VolumeGuidPathToDevicePath (favorite->Path); |