VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Dlgcode.c38
-rw-r--r--src/Common/Dlgcode.h4
2 files changed, 39 insertions, 3 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 14c57f3e..8e1e0070 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -234,9 +234,10 @@ static std::vector<HostDevice> rawHostDeviceList;
/* Critical section used to ensure that only one thread at a time can create a secure desktop */
CRITICAL_SECTION csSecureDesktop;
/* Boolean that indicates if our Secure Desktop is active and being used or not */
-BOOL bSecureDesktopOngoing = FALSE;
+volatile BOOL bSecureDesktopOngoing = FALSE;
+TCHAR SecureDesktopName[65];
HINSTANCE hInst = NULL;
HCURSOR hCursor = NULL;
@@ -12213,8 +12214,37 @@ BOOL CALLBACK SecurityTokenKeyfileDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam
}
return 0;
}
+extern "C" BOOL IsThreadInSecureDesktop(DWORD dwThreadID)
+{
+ BOOL bRet = FALSE;
+ if (bSecureDesktopOngoing)
+ {
+ HDESK currentDesk = GetThreadDesktop (dwThreadID);
+ if (currentDesk)
+ {
+ LPWSTR szName = NULL;
+ DWORD dwLen = 0;
+ if (!GetUserObjectInformation (currentDesk, UOI_NAME, NULL, 0, &dwLen))
+ {
+ szName = (LPWSTR) malloc (dwLen);
+ if (szName)
+ {
+ if (GetUserObjectInformation (currentDesk, UOI_NAME, szName, dwLen, &dwLen))
+ {
+ if (0 == _wcsicmp (szName, SecureDesktopName))
+ bRet = TRUE;
+ }
+ free (szName);
+ }
+ }
+ }
+ }
+
+ return bRet;
+}
+
BOOL InitSecurityTokenLibrary (HWND hwndDlg)
{
if (SecurityTokenLibraryPath[0] == 0)
@@ -12237,8 +12267,10 @@ BOOL InitSecurityTokenLibrary (HWND hwndDlg)
{
HWND hParent = IsWindow (m_hwnd)? m_hwnd : GetActiveWindow();
if (!hParent)
hParent = GetForegroundWindow ();
+ if (IsThreadInSecureDesktop(GetCurrentThreadId()) && !IsThreadInSecureDesktop(GetWindowThreadProcessId(hParent, NULL)))
+ hParent = GetActiveWindow ();
if (SecureDesktopDialogBoxParam (hInst, MAKEINTRESOURCEW (IDD_TOKEN_PASSWORD), hParent, (DLGPROC) SecurityTokenPasswordDlgProc, (LPARAM) &str) == IDCANCEL)
throw UserAbort (SRC_POS);
}
if (hCursor != NULL)
@@ -13846,9 +13878,9 @@ INT_PTR SecureDesktopDialogBoxParam(
BOOL bSuccess = FALSE;
INT_PTR retValue = 0;
BOOL bEffectiveUseSecureDesktop = bCmdUseSecureDesktopValid? bCmdUseSecureDesktop : bUseSecureDesktop;
- if (bEffectiveUseSecureDesktop)
+ if (bEffectiveUseSecureDesktop && !IsThreadInSecureDesktop(GetCurrentThreadId()))
{
EnterCriticalSection (&csSecureDesktop);
bSecureDesktopOngoing = TRUE;
finally_do ({ bSecureDesktopOngoing = FALSE; LeaveCriticalSection (&csSecureDesktop); });
@@ -13892,8 +13924,10 @@ INT_PTR SecureDesktopDialogBoxParam(
HANDLE hThread = ::CreateThread (NULL, 0, SecureDesktopThread, (LPVOID) &param, 0, NULL);
if (hThread)
{
+ StringCbCopy(SecureDesktopName, sizeof (SecureDesktopName), szDesktopName);
+
WaitForSingleObject (hThread, INFINITE);
CloseHandle (hThread);
retValue = param.retValue;
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index baf07a5c..6370c2a7 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -123,9 +123,10 @@ extern BOOL bShowDisconnectedNetworkDrives;
extern BOOL bHideWaitingDialog;
extern BOOL bCmdHideWaitingDialog;
extern BOOL bCmdHideWaitingDialogValid;
extern BOOL bUseSecureDesktop;
-extern BOOL bSecureDesktopOngoing;
+extern volatile BOOL bSecureDesktopOngoing;
+extern TCHAR SecureDesktopName[65];
extern BOOL bUseLegacyMaxPasswordLength;
extern BOOL bCmdUseSecureDesktop;
extern BOOL bCmdUseSecureDesktopValid;
extern BOOL bStartOnLogon;
@@ -549,8 +550,9 @@ BOOL CopyTextToClipboard (const wchar_t* txtValue);
BOOL LaunchElevatedProcess (HWND hwndDlg, const wchar_t* szModPath, const wchar_t* args);
BOOL GetFreeDriveLetter(WCHAR* pCh);
BOOL SetPrivilege(LPTSTR szPrivilegeName, BOOL bEnable);
BOOL DeleteDirectory (const wchar_t* szDirName);
+BOOL IsThreadInSecureDesktop(DWORD dwThreadID);
INT_PTR SecureDesktopDialogBoxParam (HINSTANCE, LPCWSTR, HWND, DLGPROC, LPARAM);
BOOL VerifyModuleSignature (const wchar_t* path);
void GetInstallationPath (HWND hwndDlg, wchar_t* szInstallPath, DWORD cchSize, BOOL* pbInstallPathDetermined);
BOOL GetSetupconfigLocation (wchar_t* path, DWORD cchSize);