VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-12-06 10:54:19 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-12-07 22:40:23 +0100
commitec327c006ec93ea21538605c516f919b66fd015b (patch)
tree57205624cd179eaf400faeb8b040a995d5ebc1d4 /src
parent03afe1224a961ef923706250e4dae08e762e7d32 (diff)
downloadVeraCrypt-ec327c006ec93ea21538605c516f919b66fd015b.tar.gz
VeraCrypt-ec327c006ec93ea21538605c516f919b66fd015b.zip
Windows: implement auto-dismount option when session is locked
Diffstat (limited to 'src')
-rw-r--r--src/Common/Language.xml1
-rw-r--r--src/Mount/Mount.c93
-rw-r--r--src/Mount/Mount.rc6
-rw-r--r--src/Mount/Resource.h3
4 files changed, 99 insertions, 4 deletions
diff --git a/src/Common/Language.xml b/src/Common/Language.xml
index 302dbcfe..fb18bf45 100644
--- a/src/Common/Language.xml
+++ b/src/Common/Language.xml
@@ -144,8 +144,9 @@
<control lang="en" key="IDC_PREF_BKG_TASK_ENABLE">Enabled</control>
<control lang="en" key="IDC_PREF_CACHE_PASSWORDS">Cache passwords in driver memory</control>
<control lang="en" key="IDC_PREF_DISMOUNT_INACTIVE">Auto-dismount volume after no data has been read/written to it for</control>
<control lang="en" key="IDC_PREF_DISMOUNT_LOGOFF">User logs off</control>
+ <control lang="en" key="IDC_PREF_DISMOUNT_SESSION_LOCKED">User session locked</control>
<control lang="en" key="IDC_PREF_DISMOUNT_POWERSAVING">Entering power saving mode</control>
<control lang="en" key="IDC_PREF_DISMOUNT_SCREENSAVER">Screen saver is launched</control>
<control lang="en" key="IDC_PREF_FORCE_AUTO_DISMOUNT">Force auto-dismount even if volume contains open files or directories</control>
<control lang="en" key="IDC_PREF_LOGON_MOUNT_DEVICES">Mount all device-hosted VeraCrypt volumes</control>
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index d790c675..d1576608 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -47,8 +47,13 @@
#include "../Platform/ForEach.h"
#include <Strsafe.h>
+#include <wtsapi32.h>
+
+typedef BOOL (WINAPI *WTSREGISTERSESSIONNOTIFICATION)(HWND, DWORD);
+typedef BOOL (WINAPI *WTSUNREGISTERSESSIONNOTIFICATION)(HWND);
+
using namespace VeraCrypt;
enum timer_ids
{
@@ -84,8 +89,9 @@ BOOL bWipeCacheOnExit = FALSE; /* Wipe password from chace on exit */
BOOL bWipeCacheOnAutoDismount = TRUE;
BOOL bEnableBkgTask = FALSE;
BOOL bCloseBkgTaskWhenNoVolumes = FALSE;
BOOL bDismountOnLogOff = TRUE;
+BOOL bDismountOnSessionLocked = TRUE;
BOOL bDismountOnScreenSaver = TRUE;
BOOL bDismountOnPowerSaving = FALSE;
BOOL bForceAutoDismount = TRUE;
BOOL bForceMount = FALSE; /* Mount volume even if host file/device already in use */
@@ -141,8 +147,53 @@ static int bSysEncPwdChangeDlgMode = FALSE;
static int bPrebootPasswordDlgMode = FALSE;
static int NoCmdLineArgs;
static BOOL CmdLineVolumeSpecified;
static int LastDriveListVolumeColumnWidth;
+// WTS handling
+static HMODULE hWtsLib = NULL;
+static WTSREGISTERSESSIONNOTIFICATION fnWtsRegisterSessionNotification = NULL;
+static WTSUNREGISTERSESSIONNOTIFICATION fnWtsUnRegisterSessionNotification = NULL;
+
+static void RegisterWtsNotification(HWND hWnd)
+{
+ if (!hWtsLib)
+ {
+ char dllPath[MAX_PATH];
+ if (GetSystemDirectory(dllPath, MAX_PATH))
+ StringCbCatA(dllPath, sizeof(dllPath), "\\wtsapi32.dll");
+ else
+ StringCbCopyA(dllPath, sizeof(dllPath), "c:\\Windows\\System32\\wtsapi32.dll");
+
+ hWtsLib = LoadLibrary(dllPath);
+ if (hWtsLib)
+ {
+ fnWtsRegisterSessionNotification = (WTSREGISTERSESSIONNOTIFICATION) GetProcAddress(hWtsLib, "WTSRegisterSessionNotification" );
+ fnWtsUnRegisterSessionNotification = (WTSUNREGISTERSESSIONNOTIFICATION) GetProcAddress(hWtsLib, "WTSUnRegisterSessionNotification" );
+ if ( !fnWtsRegisterSessionNotification
+ || !fnWtsUnRegisterSessionNotification
+ || !fnWtsRegisterSessionNotification( hWnd, NOTIFY_FOR_THIS_SESSION )
+ )
+ {
+ fnWtsRegisterSessionNotification = NULL;
+ fnWtsUnRegisterSessionNotification = NULL;
+ FreeLibrary(hWtsLib);
+ hWtsLib = NULL;
+ }
+ }
+ }
+}
+
+static void UnregisterWtsNotification(HWND hWnd)
+{
+ if (hWtsLib && fnWtsUnRegisterSessionNotification)
+ {
+ fnWtsUnRegisterSessionNotification(hWnd);
+ FreeLibrary(hWtsLib);
+ hWtsLib = NULL;
+ fnWtsRegisterSessionNotification = NULL;
+ fnWtsUnRegisterSessionNotification = NULL;
+ }
+}
static void localcleanup (void)
{
// Wipe command line
@@ -214,8 +265,9 @@ void EndMainDlg (HWND hwndDlg)
else
{
KillTimer (hwndDlg, TIMER_ID_MAIN);
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
EndDialog (hwndDlg, 0);
}
}
@@ -426,8 +478,9 @@ void LoadSettings (HWND hwndDlg)
bEnableBkgTask = ConfigReadInt ("EnableBackgroundTask", TRUE);
bCloseBkgTaskWhenNoVolumes = ConfigReadInt ("CloseBackgroundTaskOnNoVolumes", FALSE);
bDismountOnLogOff = ConfigReadInt ("DismountOnLogOff", !(IsServerOS() && IsAdmin()));
+ bDismountOnSessionLocked = ConfigReadInt ("DismountOnSessionLocked", FALSE);
bDismountOnPowerSaving = ConfigReadInt ("DismountOnPowerSaving", FALSE);
bDismountOnScreenSaver = ConfigReadInt ("DismountOnScreenSaver", FALSE);
bForceAutoDismount = ConfigReadInt ("ForceAutoDismount", TRUE);
MaxVolumeIdleTime = ConfigReadInt ("MaxVolumeIdleTime", -60);
@@ -520,8 +573,9 @@ void SaveSettings (HWND hwndDlg)
ConfigWriteInt ("EnableBackgroundTask", bEnableBkgTask);
ConfigWriteInt ("CloseBackgroundTaskOnNoVolumes", bCloseBkgTaskWhenNoVolumes);
ConfigWriteInt ("DismountOnLogOff", bDismountOnLogOff);
+ ConfigWriteInt ("DismountOnSessionLocked", bDismountOnSessionLocked);
ConfigWriteInt ("DismountOnPowerSaving", bDismountOnPowerSaving);
ConfigWriteInt ("DismountOnScreenSaver", bDismountOnScreenSaver);
ConfigWriteInt ("ForceAutoDismount", bForceAutoDismount);
ConfigWriteInt ("MaxVolumeIdleTime", MaxVolumeIdleTime);
@@ -2186,8 +2240,9 @@ static void PreferencesDlgEnableButtons (HWND hwndDlg)
{
BOOL back = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
BOOL idle = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
BOOL installed = !IsNonInstallMode();
+ BOOL wtsEnabled = (hWtsLib != NULL) ? TRUE : FALSE;
EnableWindow (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), back && installed);
EnableWindow (GetDlgItem (hwndDlg, IDT_LOGON), installed);
EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), back && installed);
@@ -2195,8 +2250,9 @@ static void PreferencesDlgEnableButtons (HWND hwndDlg)
EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT), back);
EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT_ON), back);
EnableWindow (GetDlgItem (hwndDlg, IDT_MINUTES), back);
EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), back);
+ EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SESSION_LOCKED), back && wtsEnabled);
EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), back);
EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), back);
EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), back);
EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME), back && idle);
@@ -2265,8 +2321,11 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), BM_SETCHECK,
bDismountOnLogOff ? BST_CHECKED:BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SESSION_LOCKED), BM_SETCHECK,
+ bDismountOnSessionLocked ? BST_CHECKED:BST_UNCHECKED, 0);
+
SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), BM_SETCHECK,
bDismountOnPowerSaving ? BST_CHECKED:BST_UNCHECKED, 0);
SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), BM_SETCHECK,
@@ -2294,27 +2353,30 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
// Forced dismount disabled warning
if (lw == IDC_PREF_DISMOUNT_INACTIVE
|| lw == IDC_PREF_DISMOUNT_LOGOFF
+ || lw == IDC_PREF_DISMOUNT_SESSION_LOCKED
|| lw == IDC_PREF_DISMOUNT_POWERSAVING
|| lw == IDC_PREF_DISMOUNT_SCREENSAVER
|| lw == IDC_PREF_FORCE_AUTO_DISMOUNT)
{
BOOL i = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
BOOL l = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
+ BOOL sl = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SESSION_LOCKED));
BOOL p = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
BOOL s = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
BOOL q = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
if (!q)
{
- if (lw == IDC_PREF_FORCE_AUTO_DISMOUNT && (i || l || p || s))
+ if (lw == IDC_PREF_FORCE_AUTO_DISMOUNT && (i || l || sl || p || s))
{
if (AskWarnNoYes ("CONFIRM_NO_FORCED_AUTODISMOUNT") == IDNO)
SetCheckBox (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT, TRUE);
}
else if ((lw == IDC_PREF_DISMOUNT_INACTIVE && i
|| lw == IDC_PREF_DISMOUNT_LOGOFF && l
+ || lw == IDC_PREF_DISMOUNT_SESSION_LOCKED && sl
|| lw == IDC_PREF_DISMOUNT_POWERSAVING && p
|| lw == IDC_PREF_DISMOUNT_SCREENSAVER && s))
Warning ("WARN_PREF_AUTO_DISMOUNT");
}
@@ -2344,8 +2406,9 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
defaultMountOptions.Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE));
bEnableBkgTask = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
bCloseBkgTaskWhenNoVolumes = IsNonInstallMode() ? bCloseBkgTaskWhenNoVolumes : IsButtonChecked (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL));
bDismountOnLogOff = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
+ bDismountOnSessionLocked = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SESSION_LOCKED));
bDismountOnPowerSaving = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
bDismountOnScreenSaver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
bForceAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
MaxVolumeIdleTime = GetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, NULL, FALSE)
@@ -4999,8 +5062,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
}
}
}
+ if (TaskBarIconMutex != NULL)
+ RegisterWtsNotification(hwndDlg);
DoPostInstallTasks ();
ResetCurrentDirectory ();
}
return 0;
@@ -5029,8 +5094,27 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case WM_HELP:
OpenPageHelp (hwndDlg, 0);
return 1;
+ case WM_WTSSESSION_CHANGE:
+ if (TaskBarIconMutex != NULL)
+ {
+ if (bDismountOnSessionLocked && (WTS_SESSION_LOCK == wParam))
+ {
+ // Auto-dismount when session is locked
+ DWORD dwResult;
+
+ if (bWipeCacheOnAutoDismount)
+ {
+ DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
+ SecurityToken::CloseAllSessions();
+ }
+
+ DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
+ }
+ }
+ return 0;
+
case WM_ENDSESSION:
if (TaskBarIconMutex != NULL)
{
if (bDismountOnLogOff)
@@ -5044,8 +5128,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
DismountAll (hwndDlg, bForceAutoDismount, FALSE, 1, 0);
}
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
}
EndMainDlg (hwndDlg);
localcleanup ();
return 0;
@@ -5254,8 +5339,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
#endif
&& GetDriverRefCount () < 2)
{
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
EndMainDlg (hwndDlg);
}
}
return 1;
@@ -5373,8 +5459,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
// Close all other TC windows
EnumWindows (CloseTCWindowsEnum, 0);
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
SendMessage (hwndDlg, WM_COMMAND, sel, 0);
}
}
else
@@ -5393,8 +5480,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case TC_APPMSG_CLOSE_BKG_TASK:
if (TaskBarIconMutex != NULL)
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
return 1;
case TC_APPMSG_SYSENC_CONFIG_UPDATE:
@@ -6128,12 +6216,14 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
{
if (bEnableBkgTask)
{
TaskBarIconAdd (hwndDlg);
+ RegisterWtsNotification(hwndDlg);
}
else
{
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
if (MainWindowHidden)
EndMainDlg (hwndDlg);
}
}
@@ -7375,8 +7465,9 @@ static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
if (bPlaySoundOnSuccessfulHkDismount)
MessageBeep (0xFFFFFFFF);
}
TaskBarIconRemove (hwndDlg);
+ UnregisterWtsNotification(hwndDlg);
EndMainDlg (hwndDlg);
break;
case HK_MOUNT_FAVORITE_VOLUMES:
diff --git a/src/Mount/Mount.rc b/src/Mount/Mount.rc
index 8346deac..56597cd2 100644
--- a/src/Mount/Mount.rc
+++ b/src/Mount/Mount.rc
@@ -58,11 +58,11 @@ BEGIN
CONTROL "Mount all device-hosted VeraCrypt volumes",IDC_PREF_LOGON_MOUNT_DEVICES,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,75,188,10
CONTROL "User logs off",IDC_PREF_DISMOUNT_LOGOFF,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,81,104,114,11
CONTROL "Entering power saving mode",IDC_PREF_DISMOUNT_POWERSAVING,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,197,109,130,11
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,197,115,130,11
CONTROL "Screen saver is launched",IDC_PREF_DISMOUNT_SCREENSAVER,
- "Button",BS_AUTOCHECKBOX | WS_TABSTOP,81,115,114,10
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,81,116,114,10
CONTROL "Auto-dismount volume after no data has been read/written to it for",IDC_PREF_DISMOUNT_INACTIVE,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,128,246,11
EDITTEXT IDC_PREF_DISMOUNT_INACTIVE_TIME,258,127,27,12,ES_AUTOHSCROLL | ES_NUMBER,WS_EX_RIGHT
CONTROL "Force auto-dismount even if volume contains open files or directories",IDC_PREF_FORCE_AUTO_DISMOUNT,
@@ -89,8 +89,10 @@ BEGIN
LTEXT "minutes",IDT_MINUTES,289,129,39,10
LTEXT "Dismount all when:",IDT_AUTO_DISMOUNT_ON,9,110,71,17
GROUPBOX "Password Cache",IDT_PW_CACHE_OPTIONS,4,216,328,39
GROUPBOX "Actions to perform upon logon to Windows",IDT_LOGON,4,63,328,28
+ CONTROL "User session locked",IDC_PREF_DISMOUNT_SESSION_LOCKED,
+ "Button",BS_AUTOCHECKBOX | WS_TABSTOP,197,105,130,11
END
IDD_VOLUME_PROPERTIES DIALOGEX 60, 30, 284, 186
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
diff --git a/src/Mount/Resource.h b/src/Mount/Resource.h
index 7ed08e06..3ba75242 100644
--- a/src/Mount/Resource.h
+++ b/src/Mount/Resource.h
@@ -158,8 +158,9 @@
#define IDT_LIMIT_ENC_THREAD_POOL_NOTE 1133
#define IDC_FAV_VOL_OPTIONS_GROUP_BOX 1134
#define IDC_FAVORITES_HELP_LINK 1135
#define IDC_FAV_VOL_OPTIONS_GLOBAL_SETTINGS_BOX 1136
+#define IDC_PREF_DISMOUNT_SESSION_LOCKED 1137
#define IDM_HELP 40001
#define IDM_ABOUT 40002
#define IDM_UNMOUNT_VOLUME 40003
#define IDM_CLEAR_HISTORY 40004
@@ -229,8 +230,8 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 118
#define _APS_NEXT_COMMAND_VALUE 40064
-#define _APS_NEXT_CONTROL_VALUE 1137
+#define _APS_NEXT_CONTROL_VALUE 1138
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif