|
|
1.1.1.11 root 1: /*
1.1.1.13 root 2: Legal Notice: Some portions of the source code contained in this file were
3: derived from the source code of Encryption for the Masses 2.02a, which is
4: Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
5: Agreement for Encryption for the Masses'. Modifications and additions to
1.1.1.24 root 6: the original source code (contained in this file) and all other portions
7: of this file are Copyright (c) 2003-2009 TrueCrypt Developers Association
1.1.1.25! root 8: and are governed by the TrueCrypt License 3.0 the full text of which is
1.1.1.24 root 9: contained in the file License.txt included in TrueCrypt binary and source
10: code distribution packages. */
1.1 root 11:
1.1.1.7 root 12: #include "Tcdefs.h"
1.1.1.13 root 13:
1.1.1.5 root 14: #include <time.h>
1.1.1.7 root 15: #include <math.h>
1.1.1.5 root 16: #include <dbt.h>
1.1.1.17 root 17: #include <fcntl.h>
18: #include <io.h>
1.1.1.23 root 19: #include <shlobj.h>
1.1.1.17 root 20: #include <sys/stat.h>
1.1.1.7 root 21: #include <windowsx.h>
1.1.1.13 root 22:
1.1.1.7 root 23: #include "Apidrvr.h"
1.1.1.13 root 24: #include "BootEncryption.h"
1.1.1.7 root 25: #include "Cmdline.h"
26: #include "Crypto.h"
27: #include "Dlgcode.h"
28: #include "Combo.h"
1.1.1.25! root 29: #include "Favorites.h"
1.1.1.7 root 30: #include "Hotkeys.h"
31: #include "Keyfiles.h"
32: #include "Language.h"
1.1.1.11 root 33: #include "MainCom.h"
1.1 root 34: #include "Mount.h"
1.1.1.7 root 35: #include "Pkcs5.h"
1.1.1.17 root 36: #include "Random.h"
1.1.1.7 root 37: #include "Registry.h"
38: #include "Resource.h"
1.1 root 39: #include "Password.h"
1.1.1.7 root 40: #include "Xml.h"
1.1.1.13 root 41: #include "../Boot/Windows/BootCommon.h"
1.1.1.7 root 42: #include "../Common/Dictionary.h"
43: #include "../Common/Common.h"
44: #include "../Common/Resource.h"
1.1.1.19 root 45: #include "../Common/SecurityToken.h"
46: #include "../Platform/Finally.h"
47: #include "../Platform/ForEach.h"
1.1 root 48:
1.1.1.13 root 49: using namespace TrueCrypt;
50:
51: enum timer_ids
52: {
53: TIMER_ID_MAIN = 0xff,
54: TIMER_ID_KEYB_LAYOUT_GUARD
55: };
56:
1.1.1.17 root 57: enum hidden_os_read_only_notif_mode
58: {
59: TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE = 0,
60: TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT,
61: TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED
62: };
63:
1.1.1.13 root 64: #define TIMER_INTERVAL_MAIN 500
65: #define TIMER_INTERVAL_KEYB_LAYOUT_GUARD 10
66:
67: BootEncryption *BootEncObj = NULL;
68: BootEncryptionStatus BootEncStatus;
69: BootEncryptionStatus RecentBootEncStatus;
70:
1.1 root 71: BOOL bExplore = FALSE; /* Display explorer window after mount */
72: BOOL bBeep = FALSE; /* Donot beep after mount */
1.1.1.8 root 73: char szFileName[TC_MAX_PATH+1]; /* Volume to mount */
1.1 root 74: char szDriveLetter[3]; /* Drive Letter to mount */
1.1.1.5 root 75: char commandLineDrive = 0;
1.1 root 76: BOOL bCacheInDriver = FALSE; /* Cache any passwords we see */
1.1.1.11 root 77: BOOL bCacheInDriverDefault = FALSE;
1.1 root 78: BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */
79: BOOL bCloseDismountedWindows=TRUE; /* Close all open explorer windows of dismounted volume */
80: BOOL bWipeCacheOnExit = FALSE; /* Wipe password from chace on exit */
1.1.1.7 root 81: BOOL bWipeCacheOnAutoDismount = TRUE;
82: BOOL bEnableBkgTask = FALSE;
83: BOOL bCloseBkgTaskWhenNoVolumes = FALSE;
84: BOOL bDismountOnLogOff = TRUE;
85: BOOL bDismountOnScreenSaver = TRUE;
86: BOOL bDismountOnPowerSaving = FALSE;
87: BOOL bForceAutoDismount = TRUE;
1.1.1.5 root 88: BOOL bForceMount = FALSE; /* Mount volume even if host file/device already in use */
89: BOOL bForceUnmount = FALSE; /* Unmount volume even if it cannot be locked */
1.1 root 90: BOOL bWipe = FALSE; /* Wipe driver passwords */
91: BOOL bAuto = FALSE; /* Do everything without user input */
1.1.1.25! root 92: BOOL LogOn = FALSE;
1.1.1.6 root 93: BOOL bAutoMountDevices = FALSE; /* Auto-mount devices */
1.1.1.7 root 94: BOOL bAutoMountFavorites = FALSE;
95: BOOL bPlaySoundOnHotkeyMountDismount = TRUE;
96: BOOL bDisplayMsgBoxOnHotkeyDismount = FALSE;
1.1.1.13 root 97: BOOL bHibernationPreventionNotified = FALSE; /* TRUE if the user has been notified that hibernation was prevented (system encryption) during the session. */
1.1.1.17 root 98: BOOL bHiddenSysLeakProtNotifiedDuringSession = FALSE; /* TRUE if the user has been notified during the session that unencrypted filesystems and non-hidden TrueCrypt volumes are mounted as read-only under hidden OS. */
1.1.1.19 root 99: BOOL CloseSecurityTokenSessionsAfterMount = FALSE;
1.1.1.25! root 100: BOOL DisableSystemCrashDetection = FALSE;
! 101: BOOL SystemCrashDetected = FALSE;
1.1.1.19 root 102:
103: BOOL MultipleMountOperationInProgress = FALSE;
1.1 root 104:
1.1.1.7 root 105: BOOL Quit = FALSE; /* Exit after processing command line */
1.1.1.11 root 106: BOOL ComServerMode = FALSE;
1.1.1.23 root 107: BOOL ServiceMode = FALSE;
1.1.1.7 root 108: BOOL UsePreferences = TRUE;
1.1 root 109:
1.1.1.17 root 110: int HiddenSysLeakProtectionNotificationStatus = TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE;
1.1.1.7 root 111: int MaxVolumeIdleTime = -120;
1.1 root 112: int nCurrentShowType = 0; /* current display mode, mount, unmount etc */
1.1.1.5 root 113: int nSelectedDriveIndex = -1; /* Item number of selected drive */
1.1 root 114:
1.1.1.7 root 115: int cmdUnmountDrive = 0; /* Volume drive letter to unmount (-1 = all) */
116: Password VolumePassword; /* Password used for mounting volumes */
117: Password CmdVolumePassword; /* Password passed from command line */
1.1.1.20 root 118: BOOL CmdVolumePasswordValid = FALSE;
1.1.1.23 root 119: MountOptions CmdMountOptions;
120: BOOL CmdMountOptionsValid = FALSE;
1.1.1.6 root 121: MountOptions mountOptions;
122: MountOptions defaultMountOptions;
1.1.1.7 root 123: KeyFile *FirstCmdKeyFile;
124:
1.1.1.12 root 125: HBITMAP hbmLogoBitmapRescaled = NULL;
1.1.1.13 root 126: char OrigKeyboardLayout [8+1] = "00000409";
1.1.1.15 root 127: BOOL bKeyboardLayoutChanged = FALSE; /* TRUE if the keyboard layout was changed to the standard US keyboard layout (from any other layout). */
128: BOOL bKeybLayoutAltKeyWarningShown = FALSE; /* TRUE if the user has been informed that it is not possible to type characters by pressing keys while the right Alt key is held down. */
1.1.1.12 root 129:
1.1.1.7 root 130: static KeyFilesDlgParam hidVolProtKeyFilesParam;
131:
1.1.1.17 root 132: static MOUNT_LIST_STRUCT LastKnownMountList;
133: VOLUME_NOTIFICATIONS_LIST VolumeNotificationsList;
134: static DWORD LastKnownLogicalDrives;
1.1.1.7 root 135:
136: static HANDLE TaskBarIconMutex = NULL;
137: static BOOL MainWindowHidden = FALSE;
138: static int pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
1.1.1.13 root 139: static int bSysEncPwdChangeDlgMode = FALSE;
1.1.1.15 root 140: static int bPrebootPasswordDlgMode = FALSE;
1.1.1.8 root 141: static int NoCmdLineArgs;
142: static BOOL CmdLineVolumeSpecified;
1.1.1.23 root 143: static int LastDriveListVolumeColumnWidth;
1.1.1.6 root 144:
1.1.1.17 root 145: static void localcleanup (void)
1.1 root 146: {
1.1.1.9 root 147: // Wipe command line
148: char *c = GetCommandLineA ();
149: wchar_t *wc = GetCommandLineW ();
150: burn(c, strlen (c));
151: burn(wc, wcslen (wc) * sizeof (wchar_t));
152:
1.1.1.12 root 153: /* Delete buffered bitmaps (if any) */
154: if (hbmLogoBitmapRescaled != NULL)
155: {
156: DeleteObject ((HGDIOBJ) hbmLogoBitmapRescaled);
157: hbmLogoBitmapRescaled = NULL;
158: }
159:
1.1.1.18 root 160: /* These items should have already been cleared by the functions that used them, but we're going to
161: clear them for extra security. */
162: burn (&VolumePassword, sizeof (VolumePassword));
163: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
164: burn (&mountOptions, sizeof (mountOptions));
165: burn (&defaultMountOptions, sizeof (defaultMountOptions));
166: burn (&szFileName, sizeof(szFileName));
167:
1.1 root 168: /* Cleanup common code resources */
169: cleanup ();
1.1.1.13 root 170:
171: if (BootEncObj != NULL)
1.1.1.15 root 172: {
1.1.1.13 root 173: delete BootEncObj;
1.1.1.15 root 174: BootEncObj = NULL;
175: }
1.1.1.21 root 176:
177: RandStop (TRUE);
1.1 root 178: }
179:
1.1.1.13 root 180: void RefreshMainDlg (HWND hwndDlg)
1.1 root 181: {
182: int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
183:
1.1.1.10 root 184: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1 root 185: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
186: EnableDisableButtons (hwndDlg);
187: }
188:
1.1.1.13 root 189: void EndMainDlg (HWND hwndDlg)
1.1 root 190: {
1.1.1.10 root 191: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1.1.7 root 192:
193: if (UsePreferences)
194: SaveSettings (hwndDlg);
1.1 root 195:
196: if (bWipeCacheOnExit)
197: {
198: DWORD dwResult;
1.1.1.13 root 199: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1 root 200: }
201:
1.1.1.10 root 202: if (!bHistory)
203: {
204: SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), "");
1.1.1.11 root 205: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 206: }
207:
1.1.1.7 root 208: if (TaskBarIconMutex != NULL)
209: {
210: MainWindowHidden = TRUE;
211: ShowWindow (hwndDlg, SW_HIDE);
212: }
213: else
214: {
1.1.1.24 root 215: KillTimer (hwndDlg, TIMER_ID_MAIN);
1.1.1.7 root 216: TaskBarIconRemove (hwndDlg);
217: EndDialog (hwndDlg, 0);
218: }
1.1 root 219: }
220:
1.1.1.7 root 221: static void InitMainDialog (HWND hwndDlg)
1.1 root 222: {
1.1.1.7 root 223: MENUITEMINFOW info;
1.1.1.25! root 224: char *popupTexts[] = {"MENU_VOLUMES", "MENU_SYSTEM_ENCRYPTION", "MENU_FAVORITES", "MENU_TOOLS", "MENU_SETTINGS", "MENU_HELP", "MENU_WEBSITE", 0};
1.1.1.7 root 225: wchar_t *str;
226: int i;
1.1 root 227:
1.1.1.7 root 228: /* Call the common dialog init code */
229: InitDialog (hwndDlg);
230: LocalizeDialog (hwndDlg, NULL);
231:
1.1.1.23 root 232: SetWindowLongPtr (hwndDlg, DWLP_USER, (LONG_PTR) (IsAdmin() ? TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES : 0));
233:
1.1.1.7 root 234: DragAcceptFiles (hwndDlg, TRUE);
1.1 root 235:
1.1.1.7 root 236: SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
1.1.1.23 root 237: SetWindowTextW (hwndDlg, (IsAdmin() && !IsBuiltInAdmin() && IsUacSupported() && !IsNonInstallMode()) ? (wstring (lpszTitle) + L" [" + GetString ("ADMINISTRATOR") + L"]").c_str() : lpszTitle);
1.1.1.7 root 238:
239: // Help file name
240: InitHelpFileName();
241:
242: // Localize menu strings
243: for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
1.1 root 244: {
1.1.1.7 root 245: info.cbSize = sizeof (info);
246: info.fMask = MIIM_TYPE;
247: info.fType = MFT_STRING;
248: info.dwTypeData = str;
249: info.cch = wcslen (str);
1.1 root 250:
1.1.1.7 root 251: SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
1.1 root 252: }
1.1.1.7 root 253:
254: for (i = 0; popupTexts[i] != 0; i++)
255: {
256: str = GetString (popupTexts[i]);
257:
258: info.cbSize = sizeof (info);
259: info.fMask = MIIM_TYPE;
260:
1.1.1.25! root 261: if (strcmp (popupTexts[i], "MENU_WEBSITE") == 0)
1.1.1.7 root 262: info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
263: else
264: info.fType = MFT_STRING;
265:
1.1.1.25! root 266: if (strcmp (popupTexts[i], "MENU_FAVORITES") == 0)
! 267: FavoriteVolumesMenu = GetSubMenu (GetMenu (hwndDlg), i);
! 268:
1.1.1.7 root 269: info.dwTypeData = str;
270: info.cch = wcslen (str);
271:
272: SetMenuItemInfoW (GetMenu (hwndDlg), i, TRUE, &info);
273: }
274:
1.1.1.25! root 275: try
! 276: {
! 277: LoadFavoriteVolumes();
! 278: }
! 279: catch (Exception &e)
! 280: {
! 281: e.Show (NULL);
! 282: }
! 283:
1.1.1.12 root 284: // Resize the logo bitmap if the user has a non-default DPI
1.1.1.15 root 285: if (ScreenDPI != USER_DEFAULT_SCREEN_DPI
286: && hbmLogoBitmapRescaled == NULL) // If not re-called (e.g. after language pack change)
1.1.1.12 root 287: {
288: hbmLogoBitmapRescaled = RenderBitmap (MAKEINTRESOURCE (IDB_LOGO_288DPI),
289: GetDlgItem (hwndDlg, IDC_LOGO),
290: 0, 0, 0, 0, FALSE, TRUE);
291: }
292:
1.1.1.7 root 293: BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
294:
295: if (*szDriveLetter != 0)
1.1 root 296: {
1.1.1.7 root 297: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
1.1 root 298:
1.1.1.7 root 299: if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
1.1.1.25! root 300: SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 10000);
1.1 root 301: }
302:
1.1.1.7 root 303: SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
304: EnableDisableButtons (hwndDlg);
305: }
306:
1.1.1.13 root 307: void EnableDisableButtons (HWND hwndDlg)
1.1.1.7 root 308: {
309: HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
310: WORD x;
311:
312: x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
313:
314: EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME, MF_ENABLED);
315: EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_ENABLED);
316: EnableMenuItem (GetMenu (hwndDlg), IDM_BACKUP_VOL_HEADER, MF_ENABLED);
317: EnableMenuItem (GetMenu (hwndDlg), IDM_RESTORE_VOL_HEADER, MF_ENABLED);
318: EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_PASSWORD, MF_ENABLED);
319: EnableWindow (hOKButton, TRUE);
320:
1.1.1.13 root 321: switch (x)
1.1 root 322: {
1.1.1.13 root 323: case TC_MLIST_ITEM_NONSYS_VOL:
324: {
325: SetWindowTextW (hOKButton, GetString ("UNMOUNT_BUTTON"));
326: EnableWindow (hOKButton, TRUE);
327: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_ENABLED);
1.1 root 328:
1.1.1.13 root 329: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
330: EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_ENABLED);
331: }
332: break;
1.1 root 333:
1.1.1.13 root 334: case TC_MLIST_ITEM_SYS_PARTITION:
335: case TC_MLIST_ITEM_SYS_DRIVE:
336: EnableWindow (hOKButton, FALSE);
337: SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1 root 338: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
1.1.1.13 root 339: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_GRAYED);
340: break;
341:
342: case TC_MLIST_ITEM_FREE:
343: default:
1.1.1.7 root 344: SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1 root 345: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
1.1.1.7 root 346: EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_GRAYED);
1.1.1.13 root 347: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_GRAYED);
1.1 root 348: }
349:
350: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
1.1.1.7 root 351: EnableMenuItem (GetMenu (hwndDlg), IDM_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
352: EnableMenuItem (GetMenu (hwndDlg), IDM_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
1.1 root 353: }
354:
1.1.1.7 root 355: BOOL VolumeSelected (HWND hwndDlg)
1.1 root 356: {
1.1.1.7 root 357: return (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0);
1.1 root 358: }
359:
1.1.1.13 root 360: /* Returns TRUE if the last partition/drive selected via the Select Device dialog box was the system
361: partition/drive and if it is encrypted.
362: WARNING: This function is very fast but not always reliable (for example, if the user manually types
363: a device path before Select Device is invoked during the session; after the Select Device dialog
364: has been invoked at least once, the correct system device paths are cached). Therefore, it must NOT
365: be used before performing any dangerous operations (such as header backup restore or formatting a
366: supposedly non-system device) -- instead use IsSystemDevicePath(path, hwndDlg, TRUE) for such
367: purposes. This function can be used only for preliminary GUI checks requiring very fast responses. */
368: BOOL ActiveSysEncDeviceSelected (void)
369: {
370: try
371: {
372: BootEncStatus = BootEncObj->GetStatus();
373:
374: if (BootEncStatus.DriveEncrypted)
375: {
376: int retCode = 0;
377:
378: GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
379:
380: retCode = IsSystemDevicePath (szFileName, MainDlg, FALSE);
381:
382: return (WholeSysDriveEncryption(FALSE) ? (retCode == 2 || retCode == 1) : (retCode == 1));
383: }
384: }
385: catch (Exception &e)
386: {
387: e.Show (MainDlg);
388: }
389:
390: return FALSE;
391: }
392:
393: void LoadSettings (HWND hwndDlg)
1.1 root 394: {
1.1.1.25! root 395: EnableHwEncryption ((ReadDriverConfigurationFlags() & TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION) ? FALSE : TRUE);
! 396:
1.1.1.19 root 397: WipeAlgorithmId savedWipeAlgorithm = TC_WIPE_NONE;
398:
1.1.1.13 root 399: LoadSysEncSettings (hwndDlg);
400:
1.1.1.19 root 401: if (LoadNonSysInPlaceEncSettings (&savedWipeAlgorithm) != 0)
402: bInPlaceEncNonSysPending = TRUE;
403:
1.1.1.13 root 404: // If the config file has already been loaded during this session
405: if (ConfigBuffer != NULL)
406: {
407: free (ConfigBuffer);
408: ConfigBuffer = NULL;
409: }
410:
1.1 root 411: // Options
1.1.1.7 root 412: bExplore = ConfigReadInt ("OpenExplorerWindowAfterMount", FALSE);
413: bCloseDismountedWindows = ConfigReadInt ("CloseExplorerWindowsOnDismount", TRUE);
414:
415: bHistory = ConfigReadInt ("SaveVolumeHistory", FALSE);
416:
1.1.1.11 root 417: bCacheInDriverDefault = bCacheInDriver = ConfigReadInt ("CachePasswords", FALSE);
1.1.1.7 root 418: bWipeCacheOnExit = ConfigReadInt ("WipePasswordCacheOnExit", FALSE);
419: bWipeCacheOnAutoDismount = ConfigReadInt ("WipeCacheOnAutoDismount", TRUE);
420:
421: bStartOnLogon = ConfigReadInt ("StartOnLogon", FALSE);
422: bMountDevicesOnLogon = ConfigReadInt ("MountDevicesOnLogon", FALSE);
423: bMountFavoritesOnLogon = ConfigReadInt ("MountFavoritesOnLogon", FALSE);
424:
425: bEnableBkgTask = ConfigReadInt ("EnableBackgroundTask", TRUE);
426: bCloseBkgTaskWhenNoVolumes = ConfigReadInt ("CloseBackgroundTaskOnNoVolumes", FALSE);
427:
1.1.1.23 root 428: bDismountOnLogOff = ConfigReadInt ("DismountOnLogOff", !(IsServerOS() && IsAdmin()));
1.1.1.21 root 429: bDismountOnPowerSaving = ConfigReadInt ("DismountOnPowerSaving", FALSE);
1.1.1.7 root 430: bDismountOnScreenSaver = ConfigReadInt ("DismountOnScreenSaver", FALSE);
431: bForceAutoDismount = ConfigReadInt ("ForceAutoDismount", TRUE);
1.1.1.19 root 432: MaxVolumeIdleTime = ConfigReadInt ("MaxVolumeIdleTime", -60);
1.1.1.7 root 433:
1.1.1.16 root 434: HiddenSectorDetectionStatus = ConfigReadInt ("HiddenSectorDetectionStatus", 0);
435:
1.1.1.7 root 436: defaultKeyFilesParam.EnableKeyFiles = ConfigReadInt ("UseKeyfiles", FALSE);
437:
438: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = ConfigReadInt ("PreserveTimestamps", TRUE);
439: defaultMountOptions.Removable = ConfigReadInt ("MountVolumesRemovable", FALSE);
440: defaultMountOptions.ReadOnly = ConfigReadInt ("MountVolumesReadOnly", FALSE);
441: defaultMountOptions.ProtectHiddenVolume = FALSE;
1.1.1.15 root 442: defaultMountOptions.PartitionInInactiveSysEncScope = FALSE;
1.1.1.19 root 443: defaultMountOptions.RecoveryMode = FALSE;
1.1.1.17 root 444: defaultMountOptions.UseBackupHeader = FALSE;
1.1.1.7 root 445:
1.1.1.6 root 446: mountOptions = defaultMountOptions;
1.1 root 447:
1.1.1.19 root 448: CloseSecurityTokenSessionsAfterMount = ConfigReadInt ("CloseSecurityTokenSessionsAfterMount", 0);
1.1.1.25! root 449: DisableSystemCrashDetection = ConfigReadInt ("DisableSystemCrashDetection", FALSE);
1.1.1.19 root 450:
1.1.1.17 root 451: if (IsHiddenOSRunning())
452: HiddenSysLeakProtectionNotificationStatus = ConfigReadInt ("HiddenSystemLeakProtNotifStatus", TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE);
453:
1.1.1.5 root 454: // Drive letter - command line arg overrides registry
455: if (szDriveLetter[0] == 0)
1.1.1.7 root 456: ConfigReadString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
457:
1.1.1.19 root 458: ConfigReadString ("SecurityTokenLibrary", "", SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath) - 1);
459: if (SecurityTokenLibraryPath[0])
460: InitSecurityTokenLibrary();
461:
1.1.1.7 root 462: // Hotkeys
463: bPlaySoundOnHotkeyMountDismount = ConfigReadInt ("PlaySoundOnHotkeyMountDismount", TRUE);
464: bDisplayMsgBoxOnHotkeyDismount = ConfigReadInt ("DisplayMsgBoxOnHotkeyDismount", FALSE);
465: Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyModifiers = ConfigReadInt ("HotkeyModAutoMountDevices", 0);
466: Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyCode = ConfigReadInt ("HotkeyCodeAutoMountDevices", 0);
467: Hotkeys [HK_DISMOUNT_ALL].vKeyModifiers = ConfigReadInt ("HotkeyModDismountAll", 0);
468: Hotkeys [HK_DISMOUNT_ALL].vKeyCode = ConfigReadInt ("HotkeyCodeDismountAll", 0);
1.1.1.11 root 469: Hotkeys [HK_WIPE_CACHE].vKeyModifiers = ConfigReadInt ("HotkeyModWipeCache", 0);
470: Hotkeys [HK_WIPE_CACHE].vKeyCode = ConfigReadInt ("HotkeyCodeWipeCache", 0);
1.1.1.21 root 471: Hotkeys [HK_DISMOUNT_ALL_AND_WIPE].vKeyModifiers = ConfigReadInt ("HotkeyModDismountAllWipe", 0);
472: Hotkeys [HK_DISMOUNT_ALL_AND_WIPE].vKeyCode = ConfigReadInt ("HotkeyCodeDismountAllWipe", 0);
1.1.1.7 root 473: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipe", 0);
474: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode = ConfigReadInt ("HotkeyCodeForceDismountAllWipe", 0);
475: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipeExit", 0);
476: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode = ConfigReadInt ("HotkeyCodeForceDismountAllWipeExit", 0);
477: Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers = ConfigReadInt ("HotkeyModMountFavoriteVolumes", 0);
478: Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyCode = ConfigReadInt ("HotkeyCodeMountFavoriteVolumes", 0);
479: Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers = ConfigReadInt ("HotkeyModShowHideMainWindow", 0);
480: Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode = ConfigReadInt ("HotkeyCodeShowHideMainWindow", 0);
1.1.1.21 root 481: Hotkeys [HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyModifiers = ConfigReadInt ("HotkeyModCloseSecurityTokenSessions", 0);
482: Hotkeys [HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyCode = ConfigReadInt ("HotkeyCodeCloseSecurityTokenSessions", 0);
1.1 root 483:
484: // History
485: if (bHistoryCmdLine != TRUE)
1.1.1.10 root 486: {
1.1.1.7 root 487: LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 488: if (CmdLineVolumeSpecified)
489: SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
490: }
1.1 root 491: }
492:
1.1.1.13 root 493: void SaveSettings (HWND hwndDlg)
1.1 root 494: {
1.1.1.13 root 495: WaitCursor ();
496:
1.1 root 497: char szTmp[32] = {0};
498: LPARAM lLetter;
499:
500: // Options
1.1.1.7 root 501: ConfigWriteBegin ();
502:
503: ConfigWriteInt ("OpenExplorerWindowAfterMount", bExplore);
504: ConfigWriteInt ("CloseExplorerWindowsOnDismount", bCloseDismountedWindows);
505: ConfigWriteInt ("SaveVolumeHistory", !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
506:
1.1.1.11 root 507: ConfigWriteInt ("CachePasswords", bCacheInDriverDefault);
1.1.1.7 root 508: ConfigWriteInt ("WipePasswordCacheOnExit", bWipeCacheOnExit);
509: ConfigWriteInt ("WipeCacheOnAutoDismount", bWipeCacheOnAutoDismount);
510:
511: ConfigWriteInt ("StartOnLogon", bStartOnLogon);
512: ConfigWriteInt ("MountDevicesOnLogon", bMountDevicesOnLogon);
513: ConfigWriteInt ("MountFavoritesOnLogon", bMountFavoritesOnLogon);
514:
515: ConfigWriteInt ("MountVolumesReadOnly", defaultMountOptions.ReadOnly);
516: ConfigWriteInt ("MountVolumesRemovable", defaultMountOptions.Removable);
517: ConfigWriteInt ("PreserveTimestamps", defaultMountOptions.PreserveTimestamp);
518:
519: ConfigWriteInt ("EnableBackgroundTask", bEnableBkgTask);
520: ConfigWriteInt ("CloseBackgroundTaskOnNoVolumes", bCloseBkgTaskWhenNoVolumes);
521:
522: ConfigWriteInt ("DismountOnLogOff", bDismountOnLogOff);
523: ConfigWriteInt ("DismountOnPowerSaving", bDismountOnPowerSaving);
524: ConfigWriteInt ("DismountOnScreenSaver", bDismountOnScreenSaver);
525: ConfigWriteInt ("ForceAutoDismount", bForceAutoDismount);
526: ConfigWriteInt ("MaxVolumeIdleTime", MaxVolumeIdleTime);
527:
1.1.1.16 root 528: ConfigWriteInt ("HiddenSectorDetectionStatus", HiddenSectorDetectionStatus);
529:
1.1.1.7 root 530: ConfigWriteInt ("UseKeyfiles", defaultKeyFilesParam.EnableKeyFiles);
1.1 root 531:
1.1.1.17 root 532: if (IsHiddenOSRunning())
533: ConfigWriteInt ("HiddenSystemLeakProtNotifStatus", HiddenSysLeakProtectionNotificationStatus);
534:
1.1 root 535: // Drive Letter
536: lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
537: if (LOWORD (lLetter) != 0xffff)
538: sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
1.1.1.7 root 539: ConfigWriteString ("LastSelectedDrive", szTmp);
540:
1.1.1.19 root 541: ConfigWriteInt ("CloseSecurityTokenSessionsAfterMount", CloseSecurityTokenSessionsAfterMount);
1.1.1.25! root 542: ConfigWriteInt ("DisableSystemCrashDetection", DisableSystemCrashDetection);
1.1.1.19 root 543:
1.1.1.7 root 544: // Hotkeys
545: ConfigWriteInt ("HotkeyModAutoMountDevices", Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyModifiers);
546: ConfigWriteInt ("HotkeyCodeAutoMountDevices", Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyCode);
547: ConfigWriteInt ("HotkeyModDismountAll", Hotkeys[HK_DISMOUNT_ALL].vKeyModifiers);
548: ConfigWriteInt ("HotkeyCodeDismountAll", Hotkeys[HK_DISMOUNT_ALL].vKeyCode);
1.1.1.11 root 549: ConfigWriteInt ("HotkeyModWipeCache", Hotkeys[HK_WIPE_CACHE].vKeyModifiers);
550: ConfigWriteInt ("HotkeyCodeWipeCache", Hotkeys[HK_WIPE_CACHE].vKeyCode);
1.1.1.21 root 551: ConfigWriteInt ("HotkeyModDismountAllWipe", Hotkeys[HK_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);
552: ConfigWriteInt ("HotkeyCodeDismountAllWipe", Hotkeys[HK_DISMOUNT_ALL_AND_WIPE].vKeyCode);
1.1.1.7 root 553: ConfigWriteInt ("HotkeyModForceDismountAllWipe", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);
554: ConfigWriteInt ("HotkeyCodeForceDismountAllWipe", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode);
555: ConfigWriteInt ("HotkeyModForceDismountAllWipeExit", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers);
556: ConfigWriteInt ("HotkeyCodeForceDismountAllWipeExit", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode);
557: ConfigWriteInt ("HotkeyModMountFavoriteVolumes", Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers);
558: ConfigWriteInt ("HotkeyCodeMountFavoriteVolumes", Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyCode);
559: ConfigWriteInt ("HotkeyModShowHideMainWindow", Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers);
560: ConfigWriteInt ("HotkeyCodeShowHideMainWindow", Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode);
1.1.1.21 root 561: ConfigWriteInt ("HotkeyModCloseSecurityTokenSessions", Hotkeys[HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyModifiers);
562: ConfigWriteInt ("HotkeyCodeCloseSecurityTokenSessions", Hotkeys[HK_CLOSE_SECURITY_TOKEN_SESSIONS].vKeyCode);
1.1.1.7 root 563: ConfigWriteInt ("PlaySoundOnHotkeyMountDismount", bPlaySoundOnHotkeyMountDismount);
564: ConfigWriteInt ("DisplayMsgBoxOnHotkeyDismount", bDisplayMsgBoxOnHotkeyDismount);
565:
566: // Language
567: if (GetPreferredLangId () != NULL)
568: ConfigWriteString ("Language", GetPreferredLangId ());
569:
1.1.1.19 root 570: // PKCS#11 Library Path
571: ConfigWriteString ("SecurityTokenLibrary", SecurityTokenLibraryPath[0] ? SecurityTokenLibraryPath : "");
572:
1.1.1.7 root 573: ConfigWriteEnd ();
1.1 root 574:
575: // History
1.1.1.7 root 576: DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
1.1.1.13 root 577:
578: NormalCursor ();
579: }
580:
581: // Returns TRUE if system encryption or decryption had been or is in progress and has not been completed
582: static BOOL SysEncryptionOrDecryptionRequired (void)
583: {
584: /* If you update this function, revise SysEncryptionOrDecryptionRequired() in Tcformat.c as well. */
585:
586: try
587: {
588: BootEncStatus = BootEncObj->GetStatus();
589: }
590: catch (Exception &e)
591: {
592: e.Show (MainDlg);
593: }
594:
595: return (SystemEncryptionStatus == SYSENC_STATUS_ENCRYPTING
596: || SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING
597: ||
598: (
599: BootEncStatus.DriveMounted
600: &&
601: (
602: BootEncStatus.ConfiguredEncryptedAreaStart != BootEncStatus.EncryptedAreaStart
603: || BootEncStatus.ConfiguredEncryptedAreaEnd != BootEncStatus.EncryptedAreaEnd
604: )
605: )
606: );
607: }
608:
609: // Returns TRUE if the system partition/drive is completely encrypted
610: static BOOL SysDriveOrPartitionFullyEncrypted (BOOL bSilent)
611: {
612: /* If you update this function, revise SysDriveOrPartitionFullyEncrypted() in Tcformat.c as well. */
613:
614: try
615: {
616: BootEncStatus = BootEncObj->GetStatus();
617: }
618: catch (Exception &e)
619: {
620: if (!bSilent)
621: e.Show (MainDlg);
622: }
623:
624: return (!BootEncStatus.SetupInProgress
625: && BootEncStatus.ConfiguredEncryptedAreaEnd != 0
626: && BootEncStatus.ConfiguredEncryptedAreaEnd != -1
627: && BootEncStatus.ConfiguredEncryptedAreaStart == BootEncStatus.EncryptedAreaStart
628: && BootEncStatus.ConfiguredEncryptedAreaEnd == BootEncStatus.EncryptedAreaEnd);
629: }
630:
631: // Returns TRUE if the system partition/drive is being filtered by the TrueCrypt driver and the key data
632: // was successfully decrypted (the device is fully ready to be encrypted or decrypted). Note that this
633: // function does not examine whether the system device is encrypted or not (or to what extent).
634: static BOOL SysEncDeviceActive (BOOL bSilent)
635: {
636: try
637: {
638: BootEncStatus = BootEncObj->GetStatus();
639: }
640: catch (Exception &e)
641: {
642: if (!bSilent)
643: e.Show (MainDlg);
644:
645: return FALSE;
646: }
647:
648: return (BootEncStatus.DriveMounted);
649: }
650:
651: // Returns TRUE if the entire system drive (as opposed to the system partition only) is (or is to be) encrypted
652: BOOL WholeSysDriveEncryption (BOOL bSilent)
653: {
654: try
655: {
656: BootEncStatus = BootEncObj->GetStatus();
657:
658: return (BootEncStatus.ConfiguredEncryptedAreaStart == TC_BOOT_LOADER_AREA_SIZE
659: && BootEncStatus.ConfiguredEncryptedAreaEnd >= BootEncStatus.BootDriveLength.QuadPart - 1);
660: }
661: catch (Exception &e)
662: {
663: if (!bSilent)
664: e.Show (MainDlg);
665:
666: return FALSE;
667: }
668: }
669:
670: // Returns the size of the system drive/partition (if encrypted) in bytes
671: unsigned __int64 GetSysEncDeviceSize (BOOL bSilent)
672: {
673: try
674: {
675: BootEncStatus = BootEncObj->GetStatus();
676: }
677: catch (Exception &e)
678: {
679: if (!bSilent)
680: e.Show (MainDlg);
681: }
682:
683: return (BootEncStatus.ConfiguredEncryptedAreaEnd - BootEncStatus.ConfiguredEncryptedAreaStart + 1);
684: }
685:
686: // Returns the current size of the encrypted area of the system drive/partition in bytes
687: unsigned __int64 GetSysEncDeviceEncryptedPartSize (BOOL bSilent)
688: {
689: try
690: {
691: BootEncStatus = BootEncObj->GetStatus();
692: }
693: catch (Exception &e)
694: {
695: if (!bSilent)
696: e.Show (MainDlg);
697: }
698:
699: return (BootEncStatus.EncryptedAreaEnd - BootEncStatus.EncryptedAreaStart + 1);
700: }
701:
702:
703: static void PopulateSysEncContextMenu (HMENU popup, BOOL bToolsOnly)
704: {
705: try
706: {
707: BootEncStatus = BootEncObj->GetStatus();
708: }
709: catch (Exception &e)
710: {
711: e.Show (MainDlg);
712: }
713:
1.1.1.17 root 714: if (!bToolsOnly && !IsHiddenOSRunning())
1.1.1.13 root 715: {
716: if (SysEncryptionOrDecryptionRequired ())
717: {
718: if (!BootEncStatus.SetupInProgress)
719: AppendMenuW (popup, MF_STRING, IDM_SYSENC_RESUME, GetString ("IDM_SYSENC_RESUME"));
720:
721: if (SystemEncryptionStatus != SYSENC_STATUS_DECRYPTING)
722: AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
1.1.1.15 root 723:
724: AppendMenuW (popup, MF_STRING, IDM_ENCRYPT_SYSTEM_DEVICE, GetString ("ENCRYPT"));
1.1.1.13 root 725: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
726: }
727: }
728:
729: AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_PASSWORD, GetString ("IDM_CHANGE_SYS_PASSWORD"));
730: AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO"));
1.1.1.17 root 731:
1.1.1.19 root 732: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
733: AppendMenuW (popup, MF_STRING, IDM_SYS_ENC_SETTINGS, GetString ("IDM_SYS_ENC_SETTINGS"));
734:
1.1.1.17 root 735: if (!IsHiddenOSRunning())
736: {
737: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
738: AppendMenuW (popup, MF_STRING, IDM_CREATE_RESCUE_DISK, GetString ("IDM_CREATE_RESCUE_DISK"));
739: AppendMenuW (popup, MF_STRING, IDM_VERIFY_RESCUE_DISK, GetString ("IDM_VERIFY_RESCUE_DISK"));
740: }
741:
1.1.1.13 root 742: if (!bToolsOnly)
743: {
1.1.1.17 root 744: if (SysDriveOrPartitionFullyEncrypted (FALSE) && !IsHiddenOSRunning())
1.1.1.13 root 745: {
746: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
747: AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
748: }
749: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
750: AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
751: }
1.1 root 752: }
753:
1.1.1.13 root 754:
1.1.1.15 root 755: // WARNING: This function may take a long time to complete. To prevent data corruption, it MUST be called before
1.1.1.17 root 756: // mounting a partition (as a regular volume) that is within key scope of system encryption.
1.1.1.15 root 757: // Returns TRUE if the partition can be mounted as a partition within key scope of inactive system encryption.
758: // If devicePath is empty, the currently selected partition in the GUI is checked.
1.1.1.19 root 759: BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
1.1.1.15 root 760: {
761: BOOL tmpbDevice;
762: char szDevicePath [TC_MAX_PATH+1];
763: char szDiskFile [TC_MAX_PATH+1];
764:
765: if (strlen (devicePath) < 2)
766: {
767: GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath));
768: CreateFullVolumePath (szDiskFile, szDevicePath, &tmpbDevice);
769:
770: if (!tmpbDevice)
771: {
772: if (!quiet)
773: Warning ("NO_SYSENC_PARTITION_SELECTED");
774:
775: return FALSE;
776: }
777:
778: if (LOWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST))) != TC_MLIST_ITEM_FREE)
779: {
780: if (!quiet)
781: Warning ("SELECT_FREE_DRIVE");
782:
783: return FALSE;
784: }
785: }
786: else
787: strncpy (szDevicePath, devicePath, sizeof (szDevicePath));
788:
789: char *partionPortion = strrchr (szDevicePath, '\\');
790:
791: if (!partionPortion
792: || !_stricmp (partionPortion, "\\Partition0"))
793: {
794: // Only partitions are supported (not whole drives)
795: if (!quiet)
796: Warning ("NO_SYSENC_PARTITION_SELECTED");
797:
798: return FALSE;
799: }
800:
801: try
802: {
803: BootEncStatus = BootEncObj->GetStatus();
804:
805: if (BootEncStatus.DriveMounted)
806: {
807: int retCode = 0;
808: int driveNo;
809: char parentDrivePath [TC_MAX_PATH+1];
810:
811: if (sscanf (szDevicePath, "\\Device\\Harddisk%d\\Partition", &driveNo) != 1)
812: {
813: if (!quiet)
814: Error ("INVALID_PATH");
815:
816: return FALSE;
817: }
818:
819: _snprintf (parentDrivePath,
820: sizeof (parentDrivePath),
821: "\\Device\\Harddisk%d\\Partition0",
822: driveNo);
823:
824: WaitCursor ();
825:
826: // This is critical (re-mounting a mounted system volume as a normal volume could cause data corruption)
827: // so we force the slower but reliable method
828: retCode = IsSystemDevicePath (parentDrivePath, MainDlg, TRUE);
829:
830: NormalCursor();
831:
832: if (retCode != 2)
833: return TRUE;
834: else
835: {
1.1.1.17 root 836: // The partition is located on active system drive
837:
1.1.1.15 root 838: if (!quiet)
1.1.1.17 root 839: Warning ("MOUNT_WITHOUT_PBA_VOL_ON_ACTIVE_SYSENC_DRIVE");
1.1.1.15 root 840:
841: return FALSE;
842: }
843: }
844: else
845: return TRUE;
846: }
847: catch (Exception &e)
848: {
849: NormalCursor();
850: e.Show (MainDlg);
851: }
852:
853: return FALSE;
854: }
855:
856:
857: // Returns TRUE if the host drive of the specified partition contains a portion of the TrueCrypt Boot Loader
858: // and if the drive is not within key scope of active system encryption (e.g. the system drive of the running OS).
859: // If bPrebootPasswordDlgMode is TRUE, this function returns FALSE (because the check would be redundant).
860: BOOL TCBootLoaderOnInactiveSysEncDrive (void)
861: {
862: try
863: {
864: int driveNo;
865: char szDevicePath [TC_MAX_PATH+1];
866: char parentDrivePath [TC_MAX_PATH+1];
867:
868: if (bPrebootPasswordDlgMode)
869: return FALSE;
870:
871: GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath));
872:
873: if (sscanf (szDevicePath, "\\Device\\Harddisk%d\\Partition", &driveNo) != 1)
874: return FALSE;
875:
876: _snprintf (parentDrivePath,
877: sizeof (parentDrivePath),
878: "\\Device\\Harddisk%d\\Partition0",
879: driveNo);
880:
881: BootEncStatus = BootEncObj->GetStatus();
882:
883: if (BootEncStatus.DriveMounted
884: && IsSystemDevicePath (parentDrivePath, MainDlg, FALSE) == 2)
885: {
886: // The partition is within key scope of active system encryption
887: return FALSE;
888: }
889:
890: return ((BOOL) BootEncObj->IsBootLoaderOnDrive (parentDrivePath));
891: }
892: catch (...)
893: {
894: return FALSE;
895: }
896:
897: }
898:
899:
1.1.1.13 root 900: BOOL SelectItem (HWND hTree, char nLetter)
1.1 root 901: {
1.1.1.25! root 902: if (nLetter == 0)
! 903: {
! 904: // The caller specified an invalid drive letter (typically because it is unknown).
! 905: // Find out which drive letter is currently selected in the list and use it.
! 906: nLetter = (char) (HIWORD (GetSelectedLong (hTree)));
! 907: }
! 908:
1.1 root 909: int i;
910: LVITEM item;
911:
912: for (i = 0; i < ListView_GetItemCount(hTree); i++)
913: {
914: memset(&item, 0, sizeof(LVITEM));
915: item.mask = LVIF_PARAM;
916: item.iItem = i;
917:
918: if (ListView_GetItem (hTree, &item) == FALSE)
919: return FALSE;
920: else
921: {
922: if (HIWORD (item.lParam) == nLetter)
923: {
924: memset(&item, 0, sizeof(LVITEM));
925: item.state = LVIS_FOCUSED|LVIS_SELECTED;
926: item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
927: item.mask = LVIF_STATE;
928: item.iItem = i;
929: SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
930: return TRUE;
931: }
932: }
933: }
934:
935: return TRUE;
936: }
937:
938:
1.1.1.13 root 939: static void LaunchVolCreationWizard (HWND hwndDlg, const char *arg)
940: {
941: char t[TC_MAX_PATH] = {'"',0};
942: char *tmp;
943:
944: GetModuleFileName (NULL, t+1, sizeof(t)-1);
945:
946: tmp = strrchr (t, '\\');
947: if (tmp)
948: {
949: STARTUPINFO si;
950: PROCESS_INFORMATION pi;
951: ZeroMemory (&si, sizeof (si));
952:
953: strcpy (++tmp, "TrueCrypt Format.exe\"");
954:
955: if (!FileExists(t))
956: Error ("VOL_CREATION_WIZARD_NOT_FOUND"); // Display a user-friendly error message and advise what to do
957:
958: if (strlen (arg) > 0)
959: {
960: strcat (t, " ");
961: strcat (t, arg);
962: }
963:
964: if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
965: {
966: handleWin32Error (hwndDlg);
967: }
968: else
969: {
970: CloseHandle (pi.hProcess);
971: CloseHandle (pi.hThread);
972: }
973: }
974: }
975:
976:
1.1 root 977: // Fills drive list
978: // drive>0 = update only the corresponding drive subitems
1.1.1.13 root 979: void LoadDriveLetters (HWND hTree, int drive)
1.1 root 980: {
1.1.1.25! root 981: // Remember the top-most visible item
! 982: int lastTopMostVisibleItem = ListView_GetTopIndex (hTree);
! 983:
1.1 root 984: char *szDriveLetters[]=
985: {"A:", "B:", "C:", "D:",
986: "E:", "F:", "G:", "H:", "I:", "J:", "K:",
987: "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
988: "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
989: "Z:"};
990:
991: DWORD dwResult;
992: BOOL bResult;
993: DWORD dwUsedDrives;
994: MOUNT_LIST_STRUCT driver;
1.1.1.13 root 995: VOLUME_PROPERTIES_STRUCT propSysEnc;
996: char sysDriveLetter = 0;
997:
998: BOOL bSysEnc = FALSE;
999: BOOL bWholeSysDriveEncryption = FALSE;
1.1 root 1000:
1001: LVITEM listItem;
1002: int item = 0;
1003: char i;
1004:
1.1.1.13 root 1005: try
1006: {
1007: BootEncStatus = BootEncObj->GetStatus();
1008: if (bSysEnc = BootEncStatus.DriveMounted)
1009: {
1010: BootEncObj->GetVolumeProperties (&propSysEnc);
1011: }
1012: }
1013: catch (...)
1014: {
1015: bSysEnc = FALSE;
1016: }
1017:
1.1.1.7 root 1018: ZeroMemory (&driver, sizeof (driver));
1.1.1.13 root 1019: bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &driver,
1.1 root 1020: sizeof (driver), &driver, sizeof (driver), &dwResult,
1021: NULL);
1.1.1.7 root 1022: memcpy (&LastKnownMountList, &driver, sizeof (driver));
1.1 root 1023:
1024: if (bResult == FALSE)
1025: {
1.1.1.24 root 1026: KillTimer (MainDlg, TIMER_ID_MAIN);
1.1 root 1027: handleWin32Error (hTree);
1.1.1.24 root 1028: AbortProcessSilent();
1.1 root 1029: }
1030:
1.1.1.7 root 1031: LastKnownLogicalDrives = dwUsedDrives = GetLogicalDrives ();
1032: if (dwUsedDrives == 0)
1033: Warning ("DRIVELETTERS");
1.1 root 1034:
1035: if(drive == 0)
1036: ListView_DeleteAllItems(hTree);
1037:
1.1.1.13 root 1038: if (bSysEnc)
1.1 root 1039: {
1.1.1.13 root 1040: bWholeSysDriveEncryption = WholeSysDriveEncryption (TRUE);
1041:
1042: sysDriveLetter = GetSystemDriveLetter ();
1043: }
1044:
1045: /* System drive */
1046:
1047: if (bWholeSysDriveEncryption)
1048: {
1.1 root 1049: int curDrive = 0;
1050:
1.1.1.13 root 1051: if (drive > 0)
1.1 root 1052: {
1053: LVITEM tmp;
1054: memset(&tmp, 0, sizeof(LVITEM));
1055: tmp.mask = LVIF_PARAM;
1056: tmp.iItem = item;
1.1.1.7 root 1057: if (ListView_GetItem (hTree, &tmp))
1.1 root 1058: curDrive = HIWORD(tmp.lParam);
1059: }
1060:
1061: {
1.1.1.7 root 1062: char szTmp[1024];
1063: wchar_t szTmpW[1024];
1.1 root 1064:
1065: memset(&listItem, 0, sizeof(listItem));
1066:
1067: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1.1.1.13 root 1068: listItem.iImage = 2;
1.1 root 1069: listItem.iItem = item++;
1070:
1.1.1.13 root 1071: listItem.pszText = szTmp;
1072: strcpy (szTmp, " ");
1.1 root 1073:
1.1.1.13 root 1074: listItem.lParam = MAKELONG (TC_MLIST_ITEM_SYS_DRIVE, ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER);
1.1 root 1075:
1076: if(drive == 0)
1077: ListView_InsertItem (hTree, &listItem);
1078: else
1079: ListView_SetItem (hTree, &listItem);
1080:
1081: listItem.mask=LVIF_TEXT;
1082:
1.1.1.13 root 1083: // Fully encrypted
1084: if (SysDriveOrPartitionFullyEncrypted (TRUE))
1085: {
1086: wcscpy (szTmpW, GetString ("SYSTEM_DRIVE"));
1087: }
1088: else
1089: {
1090: // Partially encrypted
1091:
1092: if (BootEncStatus.SetupInProgress)
1093: {
1094: // Currently encrypting/decrypting
1095:
1096: if (BootEncStatus.SetupMode != SetupDecryption)
1097: {
1098: _snwprintf (szTmpW,
1099: sizeof szTmpW/2,
1100: GetString ("SYSTEM_DRIVE_ENCRYPTING"),
1101: (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1102: }
1103: else
1104: {
1105: _snwprintf (szTmpW,
1106: sizeof szTmpW/2,
1107: GetString ("SYSTEM_DRIVE_DECRYPTING"),
1108: 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
1109: }
1110: }
1111: else
1112: {
1113: _snwprintf (szTmpW,
1114: sizeof szTmpW/2,
1115: GetString ("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"),
1116: (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1117: }
1118: }
1119:
1120: ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW);
1.1 root 1121:
1.1.1.13 root 1122: GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW);
1.1.1.7 root 1123: ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1.1 root 1124:
1.1.1.13 root 1125: EAGetName (szTmp, propSysEnc.ea);
1.1 root 1126: listItem.iSubItem = 3;
1.1.1.5 root 1127: ListView_SetItem (hTree, &listItem);
1.1 root 1128:
1.1.1.17 root 1129: ListSubItemSetW (hTree, listItem.iItem, 4, GetString (IsHiddenOSRunning() ? "HIDDEN" : "SYSTEM_VOLUME_TYPE_ADJECTIVE"));
1.1.1.13 root 1130: }
1131: }
1132:
1133: /* Drive letters */
1134:
1135: for (i = 2; i < 26; i++)
1136: {
1137: int curDrive = 0;
1138:
1139: BOOL bSysEncPartition = (bSysEnc && !bWholeSysDriveEncryption && sysDriveLetter == *((char *) szDriveLetters[i]));
1140:
1141: if (drive > 0)
1142: {
1143: LVITEM tmp;
1144: memset(&tmp, 0, sizeof(LVITEM));
1145: tmp.mask = LVIF_PARAM;
1146: tmp.iItem = item;
1147: if (ListView_GetItem (hTree, &tmp))
1148: curDrive = HIWORD(tmp.lParam);
1149: }
1150:
1151: if (driver.ulMountedDrives & (1 << i)
1152: || bSysEncPartition)
1153: {
1154: char szTmp[1024];
1155: wchar_t szTmpW[1024];
1156: wchar_t *ws;
1157:
1158: memset(&listItem, 0, sizeof(listItem));
1159:
1160: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1161: listItem.iImage = bSysEncPartition ? 2 : 1;
1162: listItem.iItem = item++;
1163:
1164: if (drive > 0 && drive != curDrive)
1165: continue;
1166:
1167: listItem.lParam = MAKELONG (
1168: bSysEncPartition ? TC_MLIST_ITEM_SYS_PARTITION : TC_MLIST_ITEM_NONSYS_VOL,
1169: i + 'A');
1170:
1171: listItem.pszText = szDriveLetters[i];
1172:
1173: if (drive == 0)
1174: ListView_InsertItem (hTree, &listItem);
1175: else
1176: ListView_SetItem (hTree, &listItem);
1177:
1178: listItem.mask=LVIF_TEXT;
1179: listItem.pszText = szTmp;
1.1.1.7 root 1180:
1.1.1.13 root 1181: if (bSysEncPartition)
1182: {
1183: // Fully encrypted
1184: if (SysDriveOrPartitionFullyEncrypted (TRUE))
1.1.1.7 root 1185: {
1.1.1.17 root 1186: wcscpy (szTmpW, GetString (IsHiddenOSRunning() ? "HIDDEN_SYSTEM_PARTITION" : "SYSTEM_PARTITION"));
1.1.1.13 root 1187: }
1188: else
1189: {
1190: // Partially encrypted
1.1.1.7 root 1191:
1.1.1.13 root 1192: if (BootEncStatus.SetupInProgress)
1193: {
1194: // Currently encrypting/decrypting
1195:
1196: if (BootEncStatus.SetupMode != SetupDecryption)
1197: {
1198: _snwprintf (szTmpW,
1199: sizeof szTmpW/2,
1200: GetString ("SYSTEM_PARTITION_ENCRYPTING"),
1201: (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1202: }
1203: else
1204: {
1205: _snwprintf (szTmpW,
1206: sizeof szTmpW/2,
1207: GetString ("SYSTEM_PARTITION_DECRYPTING"),
1208: 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
1209: }
1210: }
1211: else
1212: {
1213: _snwprintf (szTmpW,
1214: sizeof szTmpW/2,
1215: GetString ("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"),
1216: (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1217: }
1.1.1.7 root 1218: }
1.1.1.13 root 1219:
1220: ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW);
1.1.1.7 root 1221: }
1.1.1.5 root 1222: else
1.1.1.7 root 1223: {
1.1.1.25! root 1224: ToSBCS (driver.wszVolume[i]);
! 1225: char *path = (char *) driver.wszVolume[i];
1.1.1.13 root 1226:
1.1.1.25! root 1227: if (memcmp (path, "\\??\\", 4) == 0)
! 1228: path += 4;
1.1.1.13 root 1229:
1230: listItem.iSubItem = 1;
1.1.1.25! root 1231:
! 1232: wstring label = GetFavoriteVolumeLabel (path);
! 1233: if (!label.empty())
! 1234: ListSubItemSetW (hTree, listItem.iItem, 1, (wchar_t *) label.c_str());
! 1235: else
! 1236: ListSubItemSet (hTree, listItem.iItem, 1, (char *) FitPathInGfxWidth (hTree, hUserFont, ListView_GetColumnWidth (hTree, 1) - GetTextGfxWidth (hTree, L"___", hUserFont), path).c_str());
1.1.1.13 root 1237: }
1238:
1239: GetSizeString (bSysEncPartition ? GetSysEncDeviceSize(TRUE) : driver.diskLength[i], szTmpW);
1240: ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1241:
1242: EAGetName (szTmp, bSysEncPartition ? propSysEnc.ea : driver.ea[i]);
1243: listItem.iSubItem = 3;
1244: ListView_SetItem (hTree, &listItem);
1245:
1246: if (bSysEncPartition)
1247: {
1.1.1.17 root 1248: ws = GetString (IsHiddenOSRunning() ? "HIDDEN" : "SYSTEM_VOLUME_TYPE_ADJECTIVE");
1.1.1.7 root 1249: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
1.1.1.13 root 1250: ListSubItemSetW (hTree, listItem.iItem, 4, ws);
1251: }
1252: else
1253: {
1254: switch (driver.volumeType[i])
1255: {
1256: case PROP_VOL_TYPE_NORMAL:
1257: ws = GetString ("NORMAL");
1258: break;
1259: case PROP_VOL_TYPE_HIDDEN:
1260: ws = GetString ("HIDDEN");
1261: break;
1262: case PROP_VOL_TYPE_OUTER:
1263: ws = GetString ("OUTER"); // Normal/outer volume (hidden volume protected)
1264: break;
1265: case PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED:
1266: ws = GetString ("OUTER_VOL_WRITE_PREVENTED"); // Normal/outer volume (hidden volume protected AND write denied)
1267: break;
1268: default:
1269: ws = L"?";
1270: }
1271: ListSubItemSetW (hTree, listItem.iItem, 4, ws);
1272:
1273: if (driver.volumeType[i] == PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED) // Normal/outer volume (hidden volume protected AND write denied)
1274: {
1275: if (!VolumeNotificationsList.bHidVolDamagePrevReported[i])
1276: {
1277: wchar_t szTmp[4096];
1278:
1279: VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
1280: swprintf (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
1281: SetForegroundWindow (GetParent(hTree));
1.1.1.17 root 1282: MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
1.1.1.13 root 1283: }
1284: }
1285: else
1286: {
1287: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
1288: }
1.1.1.7 root 1289: }
1.1 root 1290: }
1291: else
1292: {
1.1.1.7 root 1293: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
1294:
1.1 root 1295: if (!(dwUsedDrives & 1 << i))
1296: {
1297: if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
1298: {
1299: item++;
1300: continue;
1301: }
1302:
1303: memset(&listItem,0,sizeof(listItem));
1304:
1305: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
1306: listItem.iImage = 0;
1307: listItem.iItem = item++;
1308: listItem.pszText = szDriveLetters[i];
1.1.1.13 root 1309: listItem.lParam = MAKELONG (TC_MLIST_ITEM_FREE, i + 'A');
1.1 root 1310:
1311: if(drive == 0)
1312: ListView_InsertItem (hTree, &listItem);
1313: else
1314: ListView_SetItem (hTree, &listItem);
1315:
1316: listItem.mask=LVIF_TEXT;
1317: listItem.pszText = "";
1318: listItem.iSubItem = 1;
1.1.1.5 root 1319: ListView_SetItem (hTree, &listItem);
1.1 root 1320: listItem.iSubItem = 2;
1.1.1.5 root 1321: ListView_SetItem (hTree, &listItem);
1.1 root 1322: listItem.iSubItem = 3;
1.1.1.5 root 1323: ListView_SetItem (hTree, &listItem);
1324: listItem.iSubItem = 4;
1325: ListView_SetItem (hTree, &listItem);
1.1 root 1326:
1327: }
1328: }
1329: }
1330:
1.1.1.25! root 1331: // Restore the original scroll position (the topmost item that was visible when we were called) and the
! 1332: // last selected item.
! 1333: SetListScrollHPos (hTree, lastTopMostVisibleItem);
! 1334: SelectItem (hTree, 0);
! 1335: }
1.1 root 1336:
1.1.1.7 root 1337: static void PasswordChangeEnable (HWND hwndDlg, int button, int passwordId, BOOL keyFilesEnabled,
1338: int newPasswordId, int newVerifyId, BOOL newKeyFilesEnabled)
1339: {
1340: char password[MAX_PASSWORD + 1];
1341: char newPassword[MAX_PASSWORD + 1];
1342: char newVerify[MAX_PASSWORD + 1];
1343: BOOL bEnable = TRUE;
1344:
1345: GetWindowText (GetDlgItem (hwndDlg, passwordId), password, sizeof (password));
1346:
1347: if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
1348: newKeyFilesEnabled = keyFilesEnabled;
1349:
1350: switch (pwdChangeDlgMode)
1351: {
1352: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
1353: case PCDM_ADD_REMOVE_VOL_KEYFILES:
1354: case PCDM_CHANGE_PKCS5_PRF:
1355: memcpy (newPassword, password, sizeof (newPassword));
1356: memcpy (newVerify, password, sizeof (newVerify));
1357: break;
1358:
1359: default:
1360: GetWindowText (GetDlgItem (hwndDlg, newPasswordId), newPassword, sizeof (newPassword));
1361: GetWindowText (GetDlgItem (hwndDlg, newVerifyId), newVerify, sizeof (newVerify));
1362: }
1363:
1364: if (!keyFilesEnabled && strlen (password) < MIN_PASSWORD)
1365: bEnable = FALSE;
1366: else if (strcmp (newPassword, newVerify) != 0)
1367: bEnable = FALSE;
1368: else if (!newKeyFilesEnabled && strlen (newPassword) < MIN_PASSWORD)
1369: bEnable = FALSE;
1370:
1371: burn (password, sizeof (password));
1372: burn (newPassword, sizeof (newPassword));
1373: burn (newVerify, sizeof (newVerify));
1374:
1375: EnableWindow (GetDlgItem (hwndDlg, button), bEnable);
1376: }
1377:
1378:
1.1 root 1379: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
1380: should return nonzero if it processes the message, and zero if it does
1381: not. - see DialogProc */
1.1.1.19 root 1382: BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1 root 1383: {
1.1.1.7 root 1384: static KeyFilesDlgParam newKeyFilesParam;
1.1 root 1385:
1386: WORD lw = LOWORD (wParam);
1387: WORD hw = HIWORD (wParam);
1388:
1389: switch (msg)
1390: {
1391: case WM_INITDIALOG:
1392: {
1.1.1.3 root 1393: LPARAM nIndex;
1.1.1.7 root 1394: HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
1.1.1.3 root 1395: int i;
1.1 root 1396:
1.1.1.7 root 1397: ZeroMemory (&newKeyFilesParam, sizeof (newKeyFilesParam));
1.1 root 1398:
1.1.1.7 root 1399: SetWindowTextW (hwndDlg, GetString ("IDD_PASSWORDCHANGE_DLG"));
1400: LocalizeDialog (hwndDlg, "IDD_PASSWORDCHANGE_DLG");
1.1 root 1401:
1402: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
1403: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
1404: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
1405: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
1406:
1.1.1.7 root 1407: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
1.1.1.19 root 1408: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), TRUE);
1409: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), TRUE);
1.1.1.7 root 1410:
1.1.1.3 root 1411: SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
1412:
1.1.1.7 root 1413: nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("UNCHANGED"));
1.1.1.3 root 1414: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
1415:
1.1.1.13 root 1416: for (i = FIRST_PRF_ID; i <= LAST_PRF_ID; i++)
1.1.1.3 root 1417: {
1.1.1.13 root 1418: if (!HashIsDeprecated (i))
1419: {
1420: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
1421: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
1422: }
1.1.1.3 root 1423: }
1424:
1425: SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
1426:
1.1.1.7 root 1427: switch (pwdChangeDlgMode)
1428: {
1429: case PCDM_CHANGE_PKCS5_PRF:
1430: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_CHANGE_PKCS5_PRF"));
1431: LocalizeDialog (hwndDlg, "IDD_PCDM_CHANGE_PKCS5_PRF");
1432: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
1433: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
1434: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
1435: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
1436: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
1437: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
1438: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
1439: break;
1440:
1441: case PCDM_ADD_REMOVE_VOL_KEYFILES:
1442: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_ADD_REMOVE_VOL_KEYFILES"));
1443: LocalizeDialog (hwndDlg, "IDD_PCDM_ADD_REMOVE_VOL_KEYFILES");
1444: newKeyFilesParam.EnableKeyFiles = TRUE;
1445: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
1446: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
1447: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
1448: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
1449: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
1450: break;
1451:
1452: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
1453: newKeyFilesParam.EnableKeyFiles = FALSE;
1454: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
1455: LocalizeDialog (hwndDlg, "IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL");
1456: KeyFilesEnable = TRUE;
1457: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, TRUE);
1458: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), TRUE);
1459: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_KEYFILES), TRUE);
1460: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
1461: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
1462: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
1463: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
1464: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
1465: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
1466: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
1467: EnableWindow (GetDlgItem (hwndDlg, IDT_PKCS5_PRF), FALSE);
1468: EnableWindow (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), FALSE);
1469: break;
1470:
1471: case PCDM_CHANGE_PASSWORD:
1472: default:
1473: // NOP
1474: break;
1475: };
1476:
1.1.1.13 root 1477: if (bSysEncPwdChangeDlgMode)
1478: {
1479: ToBootPwdField (hwndDlg, IDC_PASSWORD);
1480: ToBootPwdField (hwndDlg, IDC_VERIFY);
1481: ToBootPwdField (hwndDlg, IDC_OLD_PASSWORD);
1482:
1.1.1.15 root 1483: if ((DWORD) GetKeyboardLayout (NULL) != 0x00000409 && (DWORD) GetKeyboardLayout (NULL) != 0x04090409)
1.1.1.13 root 1484: {
1.1.1.15 root 1485: DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
1486:
1487: if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
1488: {
1489: Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
1490: EndDialog (hwndDlg, IDCANCEL);
1491: return 0;
1492: }
1493:
1494: bKeyboardLayoutChanged = TRUE;
1.1.1.13 root 1495: }
1496:
1497: ShowWindow(GetDlgItem(hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), SW_HIDE);
1498: ShowWindow(GetDlgItem(hwndDlg, IDC_SHOW_PASSWORD_CHPWD_ORI), SW_HIDE);
1499:
1500: if (SetTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD, TIMER_INTERVAL_KEYB_LAYOUT_GUARD, NULL) == 0)
1501: {
1502: Error ("CANNOT_SET_TIMER");
1503: EndDialog (hwndDlg, IDCANCEL);
1504: return 0;
1505: }
1506:
1507: newKeyFilesParam.EnableKeyFiles = FALSE;
1508: KeyFilesEnable = FALSE;
1509: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, FALSE);
1510: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_KEYFILES), FALSE);
1511: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
1512: }
1513:
1.1.1.5 root 1514: CheckCapsLock (hwndDlg, FALSE);
1515:
1.1.1.13 root 1516: return 0;
1517: }
1518:
1519: case WM_TIMER:
1520: switch (wParam)
1521: {
1522: case TIMER_ID_KEYB_LAYOUT_GUARD:
1523: if (bSysEncPwdChangeDlgMode)
1524: {
1525: DWORD keybLayout = (DWORD) GetKeyboardLayout (NULL);
1526:
1.1.1.15 root 1527: /* Watch the keyboard layout */
1528:
1.1.1.13 root 1529: if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
1530: {
1531: // Keyboard layout is not standard US
1532:
1533: // Attempt to wipe passwords stored in the input field buffers
1534: char tmp[MAX_PASSWORD+1];
1535: memset (tmp, 'X', MAX_PASSWORD);
1536: tmp [MAX_PASSWORD] = 0;
1537: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
1538: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1539: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
1540:
1541: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), "");
1542: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), "");
1543: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), "");
1544:
1545: keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
1546:
1547: if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
1548: {
1549: KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
1550: Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
1551: EndDialog (hwndDlg, IDCANCEL);
1552: return 1;
1553: }
1554:
1.1.1.15 root 1555: bKeyboardLayoutChanged = TRUE;
1556:
1557: wchar_t szTmp [4096];
1558: wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
1559: wcscat (szTmp, L"\n\n");
1560: wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
1561: MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
1562: }
1563:
1564:
1565: /* Watch the right Alt key (which is used to enter various characters on non-US keyboards) */
1566:
1567: if (bKeyboardLayoutChanged && !bKeybLayoutAltKeyWarningShown)
1568: {
1569: if (GetAsyncKeyState (VK_RMENU) < 0)
1570: {
1571: bKeybLayoutAltKeyWarningShown = TRUE;
1572:
1573: wchar_t szTmp [4096];
1574: wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
1575: wcscat (szTmp, L"\n\n");
1576: wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
1577: MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
1578: }
1.1.1.13 root 1579: }
1580: }
1.1 root 1581: return 1;
1582: }
1.1.1.13 root 1583: return 0;
1.1 root 1584:
1585: case WM_COMMAND:
1586: if (lw == IDCANCEL)
1587: {
1588: // Attempt to wipe passwords stored in the input field buffers
1589: char tmp[MAX_PASSWORD+1];
1590: memset (tmp, 'X', MAX_PASSWORD);
1591: tmp[MAX_PASSWORD] = 0;
1592: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1593: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
1594: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
1.1.1.7 root 1595: RestoreDefaultKeyFilesParam ();
1.1 root 1596:
1597: EndDialog (hwndDlg, IDCANCEL);
1598: return 1;
1599: }
1.1.1.7 root 1600:
1.1 root 1601: if (hw == EN_CHANGE)
1602: {
1.1.1.7 root 1603: PasswordChangeEnable (hwndDlg, IDOK,
1604: IDC_OLD_PASSWORD,
1605: KeyFilesEnable && FirstKeyFile != NULL,
1606: IDC_PASSWORD, IDC_VERIFY,
1607: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
1608:
1609: return 1;
1610: }
1611:
1612: if (lw == IDC_KEYFILES)
1613: {
1.1.1.19 root 1614: if (bSysEncPwdChangeDlgMode)
1615: {
1616: Warning ("KEYFILES_NOT_SUPPORTED_FOR_SYS_ENCRYPTION");
1617: return 1;
1618: }
1619:
1.1.1.7 root 1620: KeyFilesDlgParam param;
1621: param.EnableKeyFiles = KeyFilesEnable;
1622: param.FirstKeyFile = FirstKeyFile;
1623:
1624: if (IDOK == DialogBoxParamW (hInst,
1625: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
1626: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
1627: {
1628: KeyFilesEnable = param.EnableKeyFiles;
1629: FirstKeyFile = param.FirstKeyFile;
1630:
1631: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
1632: }
1633:
1634: PasswordChangeEnable (hwndDlg, IDOK,
1635: IDC_OLD_PASSWORD,
1636: KeyFilesEnable && FirstKeyFile != NULL,
1637: IDC_PASSWORD, IDC_VERIFY,
1638: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
1639:
1640: return 1;
1641: }
1642:
1643:
1644: if (lw == IDC_NEW_KEYFILES)
1645: {
1.1.1.19 root 1646: if (bSysEncPwdChangeDlgMode)
1647: {
1648: Warning ("KEYFILES_NOT_SUPPORTED_FOR_SYS_ENCRYPTION");
1649: return 1;
1650: }
1651:
1.1.1.7 root 1652: if (IDOK == DialogBoxParamW (hInst,
1653: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
1654: (DLGPROC) KeyFilesDlgProc, (LPARAM) &newKeyFilesParam))
1655: {
1656: SetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES, newKeyFilesParam.EnableKeyFiles);
1657:
1658: VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
1659: GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL,
1660: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
1661: }
1662:
1663: PasswordChangeEnable (hwndDlg, IDOK,
1664: IDC_OLD_PASSWORD,
1665: KeyFilesEnable && FirstKeyFile != NULL,
1666: IDC_PASSWORD, IDC_VERIFY,
1667: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
1668:
1669: return 1;
1670: }
1671:
1672: if (lw == IDC_ENABLE_KEYFILES)
1673: {
1674: KeyFilesEnable = GetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES);
1675:
1676: PasswordChangeEnable (hwndDlg, IDOK,
1677: IDC_OLD_PASSWORD,
1678: KeyFilesEnable && FirstKeyFile != NULL,
1679: IDC_PASSWORD, IDC_VERIFY,
1680: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
1681:
1682: return 1;
1683: }
1684:
1685: if (lw == IDC_ENABLE_NEW_KEYFILES)
1686: {
1687: newKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES);
1688:
1689: PasswordChangeEnable (hwndDlg, IDOK,
1690: IDC_OLD_PASSWORD,
1691: KeyFilesEnable && FirstKeyFile != NULL,
1692: IDC_PASSWORD, IDC_VERIFY,
1693: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
1694:
1695: return 1;
1696: }
1697:
1.1.1.13 root 1698: if (hw == CBN_SELCHANGE)
1699: {
1700: switch (lw)
1701: {
1702: case IDC_PKCS5_PRF_ID:
1703: if (bSysEncPwdChangeDlgMode)
1704: {
1705: int new_hash_algo_id = SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA,
1706: SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
1707:
1708: if (new_hash_algo_id != 0 && new_hash_algo_id != DEFAULT_HASH_ALGORITHM_BOOT)
1709: {
1710: int new_hash_algo_id = DEFAULT_HASH_ALGORITHM_BOOT;
1711: Info ("ALGO_NOT_SUPPORTED_FOR_SYS_ENCRYPTION");
1712: SelectAlgo (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), &new_hash_algo_id);
1713: }
1714: }
1715: break;
1716: }
1717: return 1;
1718:
1719: }
1720:
1.1.1.7 root 1721: if (lw == IDC_SHOW_PASSWORD_CHPWD_ORI)
1722: {
1723: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD),
1724: EM_SETPASSWORDCHAR,
1725: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_ORI) ? 0 : '*',
1726: 0);
1727: InvalidateRect (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), NULL, TRUE);
1728: return 1;
1729: }
1730:
1731: if (lw == IDC_SHOW_PASSWORD_CHPWD_NEW)
1732: {
1733: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
1734: EM_SETPASSWORDCHAR,
1735: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
1736: 0);
1737: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY),
1738: EM_SETPASSWORDCHAR,
1739: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
1740: 0);
1741: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
1742: InvalidateRect (GetDlgItem (hwndDlg, IDC_VERIFY), NULL, TRUE);
1.1 root 1743: return 1;
1744: }
1.1.1.7 root 1745:
1.1 root 1746: if (lw == IDOK)
1747: {
1748: HWND hParent = GetParent (hwndDlg);
1.1.1.7 root 1749: Password oldPassword;
1750: Password newPassword;
1.1 root 1751: int nStatus;
1.1.1.7 root 1752: int pkcs5 = SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA,
1753: SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
1754:
1755: if (!CheckPasswordCharEncoding (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL))
1756: {
1757: Error ("UNSUPPORTED_CHARS_IN_PWD");
1758: return 1;
1759: }
1.1 root 1760:
1.1.1.7 root 1761: if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
1762: {
1763: newKeyFilesParam.EnableKeyFiles = KeyFilesEnable;
1764: }
1.1.1.8 root 1765: else if (!(newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL)
1766: && pwdChangeDlgMode == PCDM_CHANGE_PASSWORD)
1.1.1.7 root 1767: {
1768: if (!CheckPasswordLength (hwndDlg, GetDlgItem (hwndDlg, IDC_PASSWORD)))
1769: return 1;
1770: }
1.1.1.5 root 1771:
1.1 root 1772: GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
1773:
1.1.1.13 root 1774: GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), (LPSTR) oldPassword.Text, sizeof (oldPassword.Text));
1775: oldPassword.Length = strlen ((char *) oldPassword.Text);
1.1.1.7 root 1776:
1777: switch (pwdChangeDlgMode)
1778: {
1779: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
1780: case PCDM_ADD_REMOVE_VOL_KEYFILES:
1781: case PCDM_CHANGE_PKCS5_PRF:
1782: memcpy (newPassword.Text, oldPassword.Text, sizeof (newPassword.Text));
1.1.1.13 root 1783: newPassword.Length = strlen ((char *) oldPassword.Text);
1.1.1.7 root 1784: break;
1785:
1786: default:
1.1.1.13 root 1787: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), (LPSTR) newPassword.Text, sizeof (newPassword.Text));
1788: newPassword.Length = strlen ((char *) newPassword.Text);
1.1.1.7 root 1789: }
1790:
1.1.1.19 root 1791: WaitCursor ();
1792:
1.1.1.7 root 1793: if (KeyFilesEnable)
1.1.1.12 root 1794: KeyFilesApply (&oldPassword, FirstKeyFile);
1.1 root 1795:
1.1.1.7 root 1796: if (newKeyFilesParam.EnableKeyFiles)
1.1.1.24 root 1797: {
1798: if (!KeyFilesApply (&newPassword, pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF ? FirstKeyFile : newKeyFilesParam.FirstKeyFile))
1799: {
1800: nStatus = ERR_DONT_REPORT;
1801: goto err;
1802: }
1803: }
1.1 root 1804:
1.1.1.13 root 1805: if (bSysEncPwdChangeDlgMode)
1806: {
1807: // System
1808:
1809: pkcs5 = 0; // PKCS-5 PRF unchanged (currently system encryption supports only RIPEMD-160)
1810:
1811: try
1812: {
1813: nStatus = BootEncObj->ChangePassword (&oldPassword, &newPassword, pkcs5);
1814: }
1815: catch (Exception &e)
1816: {
1817: e.Show (MainDlg);
1818: nStatus = ERR_OS_ERROR;
1819: }
1820: }
1821: else
1822: {
1823: // Non-system
1824:
1825: nStatus = ChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
1.1 root 1826:
1.1.1.13 root 1827: if (nStatus == ERR_OS_ERROR
1828: && GetLastError () == ERROR_ACCESS_DENIED
1829: && IsUacSupported ()
1830: && IsVolumeDeviceHosted (szFileName))
1831: {
1832: nStatus = UacChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
1833: }
1.1.1.11 root 1834: }
1835:
1.1.1.24 root 1836: err:
1.1.1.7 root 1837: burn (&oldPassword, sizeof (oldPassword));
1838: burn (&newPassword, sizeof (newPassword));
1.1 root 1839:
1.1.1.13 root 1840: NormalCursor ();
1841:
1.1.1.11 root 1842: if (nStatus == 0)
1.1 root 1843: {
1844: // Attempt to wipe passwords stored in the input field buffers
1845: char tmp[MAX_PASSWORD+1];
1846: memset (tmp, 'X', MAX_PASSWORD);
1847: tmp[MAX_PASSWORD] = 0;
1848: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1849: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
1850: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
1851:
1.1.1.7 root 1852: KeyFileRemoveAll (&newKeyFilesParam.FirstKeyFile);
1853: RestoreDefaultKeyFilesParam ();
1854:
1.1.1.13 root 1855: if (bSysEncPwdChangeDlgMode)
1856: {
1857: KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
1858: }
1859:
1.1 root 1860: EndDialog (hwndDlg, IDOK);
1861: }
1862: return 1;
1863: }
1864: return 0;
1865: }
1866:
1867: return 0;
1868: }
1869:
1.1.1.7 root 1870: static char PasswordDlgVolume[MAX_PATH];
1.1.1.17 root 1871: static BOOL PasswordDialogDisableMountOptions;
1872: static char *PasswordDialogTitleStringId;
1.1.1.7 root 1873:
1.1 root 1874: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
1875: should return nonzero if it processes the message, and zero if it does
1876: not. - see DialogProc */
1.1.1.19 root 1877: BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1 root 1878: {
1879: WORD lw = LOWORD (wParam);
1.1.1.7 root 1880: static Password *szXPwd;
1.1 root 1881:
1882: switch (msg)
1883: {
1884: case WM_INITDIALOG:
1885: {
1.1.1.7 root 1886: szXPwd = (Password *) lParam;
1887: LocalizeDialog (hwndDlg, "IDD_PASSWORD_DLG");
1.1.1.9 root 1888: DragAcceptFiles (hwndDlg, TRUE);
1.1.1.7 root 1889:
1.1.1.17 root 1890: if (PasswordDialogTitleStringId)
1891: {
1892: SetWindowTextW (hwndDlg, GetString (PasswordDialogTitleStringId));
1893: }
1894: else if (strlen (PasswordDlgVolume) > 0)
1.1.1.7 root 1895: {
1896: wchar_t s[1024];
1.1.1.23 root 1897: RECT rect;
1898: GetWindowRect (hwndDlg, &rect);
1899:
1.1.1.25! root 1900: wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume);
! 1901: if (!label.empty())
! 1902: {
! 1903: wsprintfW (s, GetString ("ENTER_PASSWORD_FOR_LABEL"), label.c_str());
! 1904: }
! 1905: else
! 1906: {
! 1907: wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), "___");
! 1908: wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), FitPathInGfxWidth (hwndDlg, WindowTitleBarFont, rect.right - rect.left - GetTextGfxWidth (hwndDlg, s, WindowTitleBarFont), PasswordDlgVolume).c_str());
! 1909: }
1.1.1.19 root 1910:
1.1.1.7 root 1911: SetWindowTextW (hwndDlg, s);
1912: }
1913:
1.1 root 1914: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
1915: SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7 root 1916:
1917: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
1.1.1.8 root 1918:
1.1.1.15 root 1919: mountOptions.PartitionInInactiveSysEncScope = bPrebootPasswordDlgMode;
1920:
1921: if (bPrebootPasswordDlgMode)
1922: {
1923: SendMessage (hwndDlg, TC_APPMSG_PREBOOT_PASSWORD_MODE, 0, 0);
1924: }
1925:
1.1.1.17 root 1926: if (PasswordDialogDisableMountOptions)
1927: {
1928: EnableWindow (GetDlgItem (hwndDlg, IDC_CACHE), FALSE);
1929: EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_OPTIONS), FALSE);
1930: }
1931:
1.1.1.25! root 1932: if (!SetForegroundWindow (hwndDlg) && (FavoriteMountOnArrivalInProgress || LogOn))
! 1933: {
! 1934: SetWindowPos (hwndDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
! 1935:
! 1936: FLASHWINFO flash;
! 1937: flash.cbSize = sizeof (flash);
! 1938: flash.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
! 1939: flash.dwTimeout = 0;
! 1940: flash.hwnd = hwndDlg;
! 1941: flash.uCount = 0;
! 1942:
! 1943: FlashWindowEx (&flash);
! 1944:
! 1945: SetWindowPos (hwndDlg, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
! 1946: }
1.1 root 1947: }
1.1.1.13 root 1948: return 0;
1.1 root 1949:
1.1.1.15 root 1950: case TC_APPMSG_PREBOOT_PASSWORD_MODE:
1951: {
1952: ToBootPwdField (hwndDlg, IDC_PASSWORD);
1953:
1954: // Attempt to wipe the password stored in the input field buffer
1955: char tmp[MAX_PASSWORD+1];
1956: memset (tmp, 'X', MAX_PASSWORD);
1957: tmp [MAX_PASSWORD] = 0;
1958: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1959: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), "");
1960:
1961: sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
1962:
1963: DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
1964:
1965: if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
1966: {
1967: Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
1968: EndDialog (hwndDlg, IDCANCEL);
1969: return 1;
1970: }
1971:
1972: if (SetTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD, TIMER_INTERVAL_KEYB_LAYOUT_GUARD, NULL) == 0)
1973: {
1974: Error ("CANNOT_SET_TIMER");
1975: EndDialog (hwndDlg, IDCANCEL);
1976: return 1;
1977: }
1978:
1979: SetCheckBox (hwndDlg, IDC_SHOW_PASSWORD, FALSE);
1980: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD), FALSE);
1981:
1982: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_SETPASSWORDCHAR, '*', 0);
1983: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
1984:
1985: bPrebootPasswordDlgMode = TRUE;
1986: }
1987: return 1;
1988:
1989: case WM_TIMER:
1990: switch (wParam)
1991: {
1992: case TIMER_ID_KEYB_LAYOUT_GUARD:
1993: if (bPrebootPasswordDlgMode)
1994: {
1995: DWORD keybLayout = (DWORD) GetKeyboardLayout (NULL);
1996:
1997: if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
1998: {
1999: // Keyboard layout is not standard US
2000:
2001: // Attempt to wipe the password stored in the input field buffer
2002: char tmp[MAX_PASSWORD+1];
2003: memset (tmp, 'X', MAX_PASSWORD);
2004: tmp [MAX_PASSWORD] = 0;
2005: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
2006: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), "");
2007:
2008: keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
2009:
2010: if (keybLayout != 0x00000409 && keybLayout != 0x04090409)
2011: {
2012: KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
2013: Error ("CANT_CHANGE_KEYB_LAYOUT_FOR_SYS_ENCRYPTION");
2014: EndDialog (hwndDlg, IDCANCEL);
2015: return 1;
2016: }
2017:
2018: wchar_t szTmp [4096];
2019: wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
2020: wcscat (szTmp, L"\n\n");
2021: wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
2022: MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
2023: }
2024: }
2025: return 1;
2026: }
2027: return 0;
2028:
1.1 root 2029: case WM_COMMAND:
2030:
1.1.1.6 root 2031: if (lw == IDC_MOUNT_OPTIONS)
2032: {
1.1.1.7 root 2033: DialogBoxParamW (hInst,
2034: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
1.1.1.6 root 2035: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions);
1.1.1.15 root 2036:
2037: if (!bPrebootPasswordDlgMode && mountOptions.PartitionInInactiveSysEncScope)
2038: SendMessage (hwndDlg, TC_APPMSG_PREBOOT_PASSWORD_MODE, 0, 0);
2039:
1.1.1.6 root 2040: return 1;
2041: }
2042:
1.1.1.7 root 2043: if (lw == IDC_SHOW_PASSWORD)
2044: {
2045: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
2046: EM_SETPASSWORDCHAR,
2047: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD) ? 0 : '*',
2048: 0);
2049: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
2050: return 1;
2051: }
2052:
2053: if (lw == IDC_KEY_FILES)
2054: {
2055: KeyFilesDlgParam param;
2056: param.EnableKeyFiles = KeyFilesEnable;
2057: param.FirstKeyFile = FirstKeyFile;
2058:
2059: if (IDOK == DialogBoxParamW (hInst,
2060: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
2061: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
2062: {
2063: KeyFilesEnable = param.EnableKeyFiles;
2064: FirstKeyFile = param.FirstKeyFile;
2065:
2066: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
2067: }
2068:
2069: return 1;
2070: }
2071:
2072: if (lw == IDC_KEYFILES_ENABLE)
2073: {
2074: KeyFilesEnable = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE);
2075:
2076: return 1;
2077: }
2078:
1.1 root 2079: if (lw == IDCANCEL || lw == IDOK)
2080: {
2081: char tmp[MAX_PASSWORD+1];
2082:
2083: if (lw == IDOK)
2084: {
1.1.1.7 root 2085: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12 root 2086: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.7 root 2087:
1.1.1.13 root 2088: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), (LPSTR) szXPwd->Text, MAX_PASSWORD + 1);
2089: szXPwd->Length = strlen ((char *) szXPwd->Text);
1.1.1.7 root 2090:
1.1 root 2091: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));
2092: }
2093:
2094: // Attempt to wipe password stored in the input field buffer
2095: memset (tmp, 'X', MAX_PASSWORD);
2096: tmp[MAX_PASSWORD] = 0;
2097: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1.1.1.7 root 2098: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
2099:
2100: if (hidVolProtKeyFilesParam.FirstKeyFile != NULL)
2101: {
2102: KeyFileRemoveAll (&hidVolProtKeyFilesParam.FirstKeyFile);
2103: hidVolProtKeyFilesParam.EnableKeyFiles = FALSE;
2104: }
1.1 root 2105:
1.1.1.15 root 2106: if (bPrebootPasswordDlgMode)
2107: {
2108: KillTimer (hwndDlg, TIMER_ID_KEYB_LAYOUT_GUARD);
2109:
2110: // Restore the original keyboard layout
2111: if (LoadKeyboardLayout (OrigKeyboardLayout, KLF_ACTIVATE | KLF_SUBSTITUTE_OK) == NULL)
2112: Warning ("CANNOT_RESTORE_KEYBOARD_LAYOUT");
2113: }
2114:
1.1 root 2115: EndDialog (hwndDlg, lw);
2116: return 1;
2117: }
2118: return 0;
1.1.1.9 root 2119:
1.1.1.19 root 2120: case WM_CONTEXTMENU:
2121: {
2122: RECT buttonRect;
2123: GetWindowRect (GetDlgItem (hwndDlg, IDC_KEY_FILES), &buttonRect);
2124:
2125: if (LOWORD (lParam) >= buttonRect.left && LOWORD (lParam) <= buttonRect.right
2126: && HIWORD (lParam) >= buttonRect.top && HIWORD (lParam) <= buttonRect.bottom)
2127: {
2128: // The "Keyfiles" button has been right-clicked
2129:
2130: KeyFilesDlgParam param;
2131: param.EnableKeyFiles = KeyFilesEnable;
2132: param.FirstKeyFile = FirstKeyFile;
2133:
2134: POINT popupPos;
2135: popupPos.x = buttonRect.left + 2;
2136: popupPos.y = buttonRect.top + 2;
2137:
2138: if (KeyfilesPopupMenu (hwndDlg, popupPos, ¶m))
2139: {
2140: KeyFilesEnable = param.EnableKeyFiles;
2141: FirstKeyFile = param.FirstKeyFile;
2142: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
2143: }
2144: }
2145: }
2146: break;
2147:
1.1.1.9 root 2148: case WM_DROPFILES:
2149: {
2150: HDROP hdrop = (HDROP) wParam;
1.1.1.23 root 2151: int i = 0, count = DragQueryFile (hdrop, 0xFFFFFFFF, NULL, 0);
1.1.1.9 root 2152:
2153: while (count-- > 0)
2154: {
1.1.1.13 root 2155: KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
1.1.1.9 root 2156: DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
2157: FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
2158: KeyFilesEnable = TRUE;
2159: }
2160:
2161: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
2162: DragFinish (hdrop);
2163: }
2164: return 1;
1.1 root 2165: }
2166:
2167: return 0;
2168: }
2169:
1.1.1.7 root 2170: static void PreferencesDlgEnableButtons (HWND hwndDlg)
2171: {
1.1.1.11 root 2172: BOOL back = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
1.1.1.7 root 2173: BOOL idle = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
2174: BOOL installed = !IsNonInstallMode();
2175:
1.1.1.11 root 2176: EnableWindow (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), back && installed);
1.1.1.7 root 2177: EnableWindow (GetDlgItem (hwndDlg, IDT_LOGON), installed);
1.1.1.19 root 2178: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), back && installed);
2179: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), installed);
1.1.1.11 root 2180: EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT), back);
2181: EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT_ON), back);
2182: EnableWindow (GetDlgItem (hwndDlg, IDT_MINUTES), back);
2183: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), back);
2184: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), back);
2185: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), back);
2186: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), back);
2187: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME), back && idle);
2188: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), back);
1.1.1.7 root 2189: }
2190:
1.1.1.19 root 2191: BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1 root 2192: {
1.1.1.21 root 2193: static BOOL PreferencesDialogActive = FALSE;
2194: static HWND ActivePreferencesDialogWindow;
2195:
1.1 root 2196: WORD lw = LOWORD (wParam);
2197:
2198: switch (msg)
2199: {
2200: case WM_INITDIALOG:
2201: {
1.1.1.21 root 2202: if (PreferencesDialogActive)
2203: {
2204: ShowWindow (ActivePreferencesDialogWindow, SW_SHOW);
2205: SetForegroundWindow (ActivePreferencesDialogWindow);
2206: EndDialog (hwndDlg, IDCANCEL);
2207: return 1;
2208: }
2209:
2210: ActivePreferencesDialogWindow = hwndDlg;
2211: PreferencesDialogActive = TRUE;
2212:
1.1.1.7 root 2213: LocalizeDialog (hwndDlg, "IDD_PREFERENCES_DLG");
1.1 root 2214:
2215: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK,
2216: bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
2217:
2218: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK,
2219: bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
2220:
1.1.1.7 root 2221: SendMessage (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS), BM_SETCHECK,
2222: defaultMountOptions.PreserveTimestamp ? BST_CHECKED:BST_UNCHECKED, 0);
2223:
1.1 root 2224: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK,
2225: bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
2226:
1.1.1.7 root 2227: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT), BM_SETCHECK,
2228: bWipeCacheOnAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
2229:
1.1 root 2230: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK,
2231: bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
2232:
1.1.1.6 root 2233: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY), BM_SETCHECK,
2234: defaultMountOptions.ReadOnly ? BST_CHECKED:BST_UNCHECKED, 0);
2235:
2236: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE), BM_SETCHECK,
2237: defaultMountOptions.Removable ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7 root 2238:
2239: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), BM_SETCHECK,
2240: bStartOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
2241:
2242: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), BM_SETCHECK,
2243: bMountDevicesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
2244:
2245: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE), BM_SETCHECK,
2246: bEnableBkgTask ? BST_CHECKED:BST_UNCHECKED, 0);
2247:
2248: SendMessage (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), BM_SETCHECK,
2249: bCloseBkgTaskWhenNoVolumes || IsNonInstallMode() ? BST_CHECKED:BST_UNCHECKED, 0);
2250:
2251: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), BM_SETCHECK,
2252: bDismountOnLogOff ? BST_CHECKED:BST_UNCHECKED, 0);
2253:
2254: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), BM_SETCHECK,
2255: bDismountOnPowerSaving ? BST_CHECKED:BST_UNCHECKED, 0);
2256:
2257: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), BM_SETCHECK,
2258: bDismountOnScreenSaver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1 root 2259:
1.1.1.7 root 2260: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), BM_SETCHECK,
2261: bForceAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
2262:
2263: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), BM_SETCHECK,
2264: MaxVolumeIdleTime > 0 ? BST_CHECKED:BST_UNCHECKED, 0);
2265:
2266: SetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, abs (MaxVolumeIdleTime), FALSE);
2267:
2268: PreferencesDlgEnableButtons (hwndDlg);
1.1 root 2269: }
1.1.1.13 root 2270: return 0;
1.1 root 2271:
2272: case WM_COMMAND:
2273:
1.1.1.7 root 2274: if (lw == IDC_PREF_BKG_TASK_ENABLE && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE)))
2275: {
2276: if (AskWarnNoYes ("CONFIRM_BACKGROUND_TASK_DISABLED") == IDNO)
2277: SetCheckBox (hwndDlg, IDC_PREF_BKG_TASK_ENABLE, TRUE);
2278: }
2279:
2280: // Forced dismount disabled warning
2281: if (lw == IDC_PREF_DISMOUNT_INACTIVE
1.1.1.23 root 2282: || lw == IDC_PREF_DISMOUNT_LOGOFF
1.1.1.7 root 2283: || lw == IDC_PREF_DISMOUNT_POWERSAVING
2284: || lw == IDC_PREF_DISMOUNT_SCREENSAVER
2285: || lw == IDC_PREF_FORCE_AUTO_DISMOUNT)
2286: {
2287: BOOL i = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
1.1.1.23 root 2288: BOOL l = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
1.1.1.7 root 2289: BOOL p = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
2290: BOOL s = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
2291: BOOL q = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
2292:
2293: if (!q)
2294: {
1.1.1.23 root 2295: if (lw == IDC_PREF_FORCE_AUTO_DISMOUNT && (i || l || p || s))
1.1.1.7 root 2296: {
2297: if (AskWarnNoYes ("CONFIRM_NO_FORCED_AUTODISMOUNT") == IDNO)
2298: SetCheckBox (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT, TRUE);
2299: }
2300: else if ((lw == IDC_PREF_DISMOUNT_INACTIVE && i
1.1.1.23 root 2301: || lw == IDC_PREF_DISMOUNT_LOGOFF && l
1.1.1.7 root 2302: || lw == IDC_PREF_DISMOUNT_POWERSAVING && p
2303: || lw == IDC_PREF_DISMOUNT_SCREENSAVER && s))
2304: Warning ("WARN_PREF_AUTO_DISMOUNT");
2305: }
2306:
1.1.1.21 root 2307: if (p && lw == IDC_PREF_DISMOUNT_POWERSAVING)
2308: Warning ("WARN_PREF_AUTO_DISMOUNT_ON_POWER");
1.1.1.7 root 2309: }
2310:
1.1 root 2311: if (lw == IDCANCEL)
2312: {
1.1.1.21 root 2313: PreferencesDialogActive = FALSE;
1.1 root 2314: EndDialog (hwndDlg, lw);
2315: return 1;
2316: }
2317:
2318: if (lw == IDOK)
2319: {
1.1.1.7 root 2320: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));
2321: bCloseDismountedWindows = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));
2322: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS));
2323: bWipeCacheOnExit = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));
2324: bWipeCacheOnAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT));
1.1.1.11 root 2325: bCacheInDriverDefault = bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));
1.1.1.7 root 2326: defaultMountOptions.ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY));
2327: defaultMountOptions.Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE));
2328: bEnableBkgTask = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
2329: bCloseBkgTaskWhenNoVolumes = IsNonInstallMode() ? bCloseBkgTaskWhenNoVolumes : IsButtonChecked (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL));
2330: bDismountOnLogOff = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
2331: bDismountOnPowerSaving = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
2332: bDismountOnScreenSaver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
2333: bForceAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
2334: MaxVolumeIdleTime = GetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, NULL, FALSE)
2335: * (IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE)) ? 1 : -1);
2336: bStartOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));
2337: bMountDevicesOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES));
2338:
1.1.1.13 root 2339: ManageStartupSeq ();
1.1.1.7 root 2340:
1.1.1.12 root 2341: WaitCursor ();
1.1.1.7 root 2342: SaveSettings (hwndDlg);
1.1.1.12 root 2343: NormalCursor ();
1.1 root 2344:
1.1.1.21 root 2345: PreferencesDialogActive = FALSE;
1.1 root 2346: EndDialog (hwndDlg, lw);
2347: return 1;
2348: }
2349:
1.1.1.19 root 2350: if (lw == IDC_MORE_SETTINGS)
1.1.1.7 root 2351: {
1.1.1.19 root 2352: HMENU popup = CreatePopupMenu ();
1.1 root 2353:
1.1.1.19 root 2354: AppendMenuW (popup, MF_STRING, IDM_LANGUAGE, GetString ("IDM_LANGUAGE"));
2355: AppendMenuW (popup, MF_STRING, IDM_HOTKEY_SETTINGS, GetString ("IDM_HOTKEY_SETTINGS"));
1.1.1.25! root 2356: AppendMenuW (popup, MF_STRING, IDM_PERFORMANCE_SETTINGS, GetString ("IDM_PERFORMANCE_SETTINGS"));
1.1.1.19 root 2357: AppendMenuW (popup, MF_STRING, IDM_SYSENC_SETTINGS, GetString ("IDM_SYSENC_SETTINGS"));
1.1.1.23 root 2358: AppendMenuW (popup, MF_STRING, IDM_SYS_FAVORITES_SETTINGS, GetString ("IDM_SYS_FAVORITES_SETTINGS"));
1.1.1.19 root 2359: AppendMenuW (popup, MF_STRING, IDM_DEFAULT_KEYFILES, GetString ("IDM_DEFAULT_KEYFILES"));
2360: AppendMenuW (popup, MF_STRING, IDM_TOKEN_PREFERENCES, GetString ("IDM_TOKEN_PREFERENCES"));
1.1.1.6 root 2361:
1.1.1.19 root 2362: RECT rect;
2363: GetWindowRect (GetDlgItem (hwndDlg, IDC_MORE_SETTINGS), &rect);
2364:
2365: int menuItem = TrackPopupMenu (popup, TPM_RETURNCMD | TPM_LEFTBUTTON, rect.left + 2, rect.top + 2, 0, hwndDlg, NULL);
2366: DestroyMenu (popup);
2367:
2368: SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
1.1.1.7 root 2369: return 1;
2370: }
2371:
2372: if (HIWORD (wParam) == BN_CLICKED)
2373: {
2374: PreferencesDlgEnableButtons (hwndDlg);
2375: return 1;
2376: }
2377:
2378: return 0;
2379: }
2380:
2381: return 0;
2382: }
2383:
2384:
1.1.1.19 root 2385: BOOL CALLBACK MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.7 root 2386: {
2387: static MountOptions *mountOptions;
2388:
2389: WORD lw = LOWORD (wParam);
2390:
2391: switch (msg)
2392: {
2393: case WM_INITDIALOG:
2394: {
2395: BOOL protect;
2396:
2397: mountOptions = (MountOptions *) lParam;
2398:
2399: LocalizeDialog (hwndDlg, "IDD_MOUNT_OPTIONS");
2400:
2401: SendDlgItemMessage (hwndDlg, IDC_MOUNT_READONLY, BM_SETCHECK,
2402: mountOptions->ReadOnly ? BST_CHECKED : BST_UNCHECKED, 0);
2403: SendDlgItemMessage (hwndDlg, IDC_MOUNT_REMOVABLE, BM_SETCHECK,
2404: mountOptions->Removable ? BST_CHECKED : BST_UNCHECKED, 0);
2405: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK,
2406: mountOptions->ProtectHiddenVolume ? BST_CHECKED : BST_UNCHECKED, 0);
2407:
1.1.1.15 root 2408: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK,
2409: mountOptions->ProtectHiddenVolume ? BST_CHECKED : BST_UNCHECKED, 0);
2410:
2411: mountOptions->PartitionInInactiveSysEncScope = bPrebootPasswordDlgMode;
2412:
2413: SendDlgItemMessage (hwndDlg, IDC_MOUNT_SYSENC_PART_WITHOUT_PBA, BM_SETCHECK,
2414: bPrebootPasswordDlgMode ? BST_CHECKED : BST_UNCHECKED, 0);
2415:
1.1.1.17 root 2416: SendDlgItemMessage (hwndDlg, IDC_USE_EMBEDDED_HEADER_BAK, BM_SETCHECK,
2417: mountOptions->UseBackupHeader ? BST_CHECKED : BST_UNCHECKED, 0);
2418:
1.1.1.15 root 2419: EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_SYSENC_PART_WITHOUT_PBA), !bPrebootPasswordDlgMode);
2420:
1.1.1.7 root 2421: protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
2422:
2423: EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
2424: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
2425: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
2426: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
2427: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
1.1.1.19 root 2428: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect);
1.1.1.7 root 2429: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
2430:
2431: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
2432:
1.1.1.8 root 2433: SendDlgItemMessage (hwndDlg, IDC_PASSWORD_PROT_HIDVOL, EM_LIMITTEXT, MAX_PASSWORD, 0);
2434:
1.1.1.7 root 2435: if (mountOptions->ProtectedHidVolPassword.Length > 0)
1.1.1.13 root 2436: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), (LPSTR) mountOptions->ProtectedHidVolPassword.Text);
1.1.1.11 root 2437:
2438: ToHyperlink (hwndDlg, IDC_LINK_HIDVOL_PROTECTION_INFO);
1.1.1.7 root 2439:
2440: }
1.1.1.13 root 2441: return 0;
1.1.1.7 root 2442:
1.1.1.21 root 2443: case WM_CONTEXTMENU:
2444: {
2445: RECT buttonRect;
2446: GetWindowRect (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), &buttonRect);
2447:
2448: if (IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL))
2449: && LOWORD (lParam) >= buttonRect.left && LOWORD (lParam) <= buttonRect.right
2450: && HIWORD (lParam) >= buttonRect.top && HIWORD (lParam) <= buttonRect.bottom)
2451: {
2452: // The "Keyfiles" button has been right-clicked
2453:
2454: POINT popupPos;
2455: popupPos.x = buttonRect.left + 2;
2456: popupPos.y = buttonRect.top + 2;
2457:
2458: if (KeyfilesPopupMenu (hwndDlg, popupPos, &hidVolProtKeyFilesParam))
2459: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
2460: }
2461: }
2462: break;
2463:
1.1.1.7 root 2464: case WM_COMMAND:
2465:
2466: if (lw == IDC_KEYFILES_HIDVOL_PROT)
2467: {
2468: if (IDOK == DialogBoxParamW (hInst,
2469: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
2470: (DLGPROC) KeyFilesDlgProc, (LPARAM) &hidVolProtKeyFilesParam))
2471: {
2472: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
2473: }
2474: }
2475:
2476: if (lw == IDC_KEYFILES_ENABLE_HIDVOL_PROT)
2477: {
2478: hidVolProtKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT);
2479:
2480: return 0;
2481: }
2482:
2483: if (lw == IDC_SHOW_PASSWORD_MO)
2484: {
2485: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
2486: EM_SETPASSWORDCHAR,
2487: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_MO) ? 0 : '*',
2488: 0);
2489: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), NULL, TRUE);
2490: return 1;
2491: }
2492:
1.1.1.11 root 2493: if (lw == IDC_LINK_HIDVOL_PROTECTION_INFO)
2494: {
2495: Applink ("hiddenvolprotection", TRUE, "");
2496: }
2497:
1.1.1.7 root 2498: if (lw == IDCANCEL)
2499: {
2500: char tmp[MAX_PASSWORD+1];
2501:
2502: // Cleanup
2503: memset (tmp, 'X', MAX_PASSWORD);
2504: tmp[MAX_PASSWORD] = 0;
2505: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
2506:
2507: EndDialog (hwndDlg, lw);
2508: return 1;
2509: }
2510:
2511: if (lw == IDOK)
2512: {
2513: char tmp[MAX_PASSWORD+1];
2514:
2515: mountOptions->ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
2516: mountOptions->Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_REMOVABLE));
2517: mountOptions->ProtectHiddenVolume = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1.1.1.15 root 2518: mountOptions->PartitionInInactiveSysEncScope = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_SYSENC_PART_WITHOUT_PBA));
1.1.1.17 root 2519: mountOptions->UseBackupHeader = IsButtonChecked (GetDlgItem (hwndDlg, IDC_USE_EMBEDDED_HEADER_BAK));
2520:
1.1.1.7 root 2521: if (mountOptions->ProtectHiddenVolume)
2522: {
2523: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
1.1.1.13 root 2524: (LPSTR) mountOptions->ProtectedHidVolPassword.Text,
1.1.1.7 root 2525: sizeof (mountOptions->ProtectedHidVolPassword.Text));
2526:
1.1.1.13 root 2527: mountOptions->ProtectedHidVolPassword.Length = strlen ((char *) mountOptions->ProtectedHidVolPassword.Text);
1.1.1.7 root 2528: }
2529:
2530: // Cleanup
2531: memset (tmp, 'X', MAX_PASSWORD);
2532: tmp[MAX_PASSWORD] = 0;
2533: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
2534:
1.1.1.11 root 2535: if ((mountOptions->ProtectHiddenVolume && !bEnableBkgTask)
2536: && (AskWarnYesNo ("HIDVOL_PROT_BKG_TASK_WARNING") == IDYES))
2537: {
2538: bEnableBkgTask = TRUE;
2539: TaskBarIconAdd (MainDlg);
2540: }
1.1.1.7 root 2541:
2542: EndDialog (hwndDlg, lw);
2543: return 1;
2544: }
2545:
2546: if (lw == IDC_MOUNT_READONLY || lw == IDC_PROTECT_HIDDEN_VOL)
2547: {
2548: BOOL protect;
2549:
2550: if (lw == IDC_MOUNT_READONLY)
2551: {
2552: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK, BST_UNCHECKED, 0);
2553: EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
2554: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
2555: }
2556:
2557: protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
2558:
2559: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
2560: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
2561: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
1.1.1.19 root 2562: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect);
1.1.1.7 root 2563: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
2564:
2565: return 1;
2566: }
2567:
2568: return 0;
2569: }
2570:
2571: return 0;
2572: }
2573:
2574:
1.1.1.11 root 2575: // Returns the block size (in bits) of the cipher with which the volume mounted as the
2576: // specified drive letter is encrypted. In case of a cascade of ciphers with different
2577: // block sizes the function returns the smallest block size.
2578: int GetCipherBlockSizeByDriveNo (int nDosDriveNo)
2579: {
2580: VOLUME_PROPERTIES_STRUCT prop;
2581: DWORD dwResult;
2582:
2583: int blockSize = 0, cipherID;
2584:
2585: memset (&prop, 0, sizeof(prop));
2586: prop.driveNo = nDosDriveNo;
2587:
1.1.1.13 root 2588: if (DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL))
1.1.1.11 root 2589: {
2590: for (cipherID = EAGetLastCipher (prop.ea);
2591: cipherID != 0;
2592: cipherID = EAGetPreviousCipher (prop.ea, cipherID))
2593: {
2594: if (blockSize > 0)
2595: blockSize = min (blockSize, CipherGetBlockSize (cipherID) * 8);
2596: else
2597: blockSize = CipherGetBlockSize (cipherID) * 8;
2598: }
2599: }
2600:
1.1.1.13 root 2601: return blockSize;
2602: }
2603:
2604:
2605: // Returns the mode of operation in which the volume mounted as the specified drive letter is encrypted.
2606: int GetModeOfOperationByDriveNo (int nDosDriveNo)
2607: {
2608: VOLUME_PROPERTIES_STRUCT prop;
2609: DWORD dwResult;
2610:
2611: memset (&prop, 0, sizeof(prop));
2612: prop.driveNo = nDosDriveNo;
2613:
2614: if (DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL))
2615: {
2616: return prop.mode;
2617: }
2618:
2619: return 0;
1.1.1.11 root 2620: }
2621:
2622:
1.1.1.13 root 2623: BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.7 root 2624: {
1.1.1.13 root 2625: BOOL bSysEnc = (BOOL) lParam;
2626: BOOL bSysEncWholeDrive = FALSE;
1.1 root 2627: WORD lw = LOWORD (wParam);
1.1.1.7 root 2628: int i = 0;
1.1 root 2629:
2630: switch (msg)
2631: {
2632: case WM_INITDIALOG:
2633: {
2634: VOLUME_PROPERTIES_STRUCT prop;
2635: DWORD dwResult;
2636:
1.1.1.7 root 2637: LVCOLUMNW lvCol;
1.1 root 2638: HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
1.1.1.7 root 2639: char szTmp[1024];
2640: wchar_t sw[1024];
2641: wchar_t *s;
1.1 root 2642:
1.1.1.13 root 2643: if (bSysEnc)
2644: {
2645: try
2646: {
2647: BootEncStatus = BootEncObj->GetStatus();
2648: bSysEncWholeDrive = WholeSysDriveEncryption(FALSE);
2649: }
2650: catch (Exception &e)
2651: {
2652: e.Show (MainDlg);
2653: return 0;
2654: }
2655:
2656: if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
2657: return 0;
2658: }
2659: else
2660: {
2661: switch (LOWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))))
2662: {
2663: case TC_MLIST_ITEM_FREE:
2664:
2665: // No mounted volume
2666: EndDialog (hwndDlg, IDOK);
2667: return 0;
2668:
2669: case TC_MLIST_ITEM_NONSYS_VOL:
2670: // NOP
2671: break;
2672:
2673: case TC_MLIST_ITEM_SYS_DRIVE:
2674: // Encrypted system drive
2675: bSysEnc = TRUE;
2676: bSysEncWholeDrive = TRUE;
2677: break;
2678:
2679: case TC_MLIST_ITEM_SYS_PARTITION:
2680: // Encrypted system partition
2681: bSysEnc = TRUE;
2682: bSysEncWholeDrive = FALSE;
2683: break;
2684: }
2685: }
2686:
1.1.1.7 root 2687: LocalizeDialog (hwndDlg, "IDD_VOLUME_PROPERTIES");
1.1 root 2688:
1.1.1.7 root 2689: SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
1.1 root 2690: LVS_EX_FULLROWSELECT
1.1.1.7 root 2691: |LVS_EX_HEADERDRAGDROP
2692: |LVS_EX_LABELTIP
1.1.1.25! root 2693: );
1.1 root 2694:
1.1.1.25! root 2695: memset (&lvCol,0,sizeof(lvCol));
! 2696: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
! 2697: lvCol.pszText = GetString ("VALUE");
1.1.1.12 root 2698: lvCol.cx = CompensateXDPI (208);
1.1.1.25! root 2699: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 2700: SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 2701:
1.1.1.25! root 2702: lvCol.pszText = GetString ("PROPERTY");
! 2703: lvCol.cx = CompensateXDPI (192);
1.1 root 2704: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 2705: SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1.1.25! root 2706:
1.1 root 2707: memset (&prop, 0, sizeof(prop));
2708: prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
2709:
1.1.1.13 root 2710: if (bSysEnc)
2711: {
2712: try
2713: {
2714: BootEncStatus = BootEncObj->GetStatus();
2715: if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
2716: return 0;
2717:
2718: BootEncObj->GetVolumeProperties (&prop);
2719: }
2720: catch (Exception &e)
2721: {
2722: e.Show (MainDlg);
2723: return 0;
2724: }
2725: }
2726: else
2727: {
2728: if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL) || dwResult == 0)
2729: return 0;
2730: }
1.1.1.11 root 2731:
1.1.1.7 root 2732: // Location
2733: ListItemAddW (list, i, GetString ("LOCATION"));
1.1.1.13 root 2734: if (bSysEnc)
1.1.1.17 root 2735: ListSubItemSetW (list, i++, 1, GetString (bSysEncWholeDrive ? "SYSTEM_DRIVE" : IsHiddenOSRunning() ? "HIDDEN_SYSTEM_PARTITION" : "SYSTEM_PARTITION"));
1.1.1.13 root 2736: else
2737: ListSubItemSetW (list, i++, 1, (wchar_t *) (prop.wszVolume[1] != L'?' ? prop.wszVolume : prop.wszVolume + 4));
1.1.1.7 root 2738:
2739: // Size
2740: ListItemAddW (list, i, GetString ("SIZE"));
2741: swprintf (sw, L"%I64u %s", prop.diskLength, GetString ("BYTES"));
2742: ListSubItemSetW (list, i++, 1, sw);
2743:
2744: // Type
2745: ListItemAddW (list, i, GetString ("TYPE"));
1.1.1.13 root 2746: if (bSysEnc)
1.1.1.17 root 2747: ListSubItemSetW (list, i++, 1, GetString (IsHiddenOSRunning() ? "TYPE_HIDDEN_SYSTEM_ADJECTIVE" : "SYSTEM_VOLUME_TYPE_ADJECTIVE"));
1.1.1.13 root 2748: else
2749: {
2750: ListSubItemSetW (list, i++, 1,
2751: prop.hiddenVolume ? GetString ("HIDDEN") :
2752: (prop.hiddenVolProtection != HIDVOL_PROT_STATUS_NONE ? GetString ("OUTER") : GetString ("NORMAL")));
2753: }
1.1.1.7 root 2754:
1.1.1.13 root 2755: if (!bSysEnc)
2756: {
2757: // Write protection
2758: ListItemAddW (list, i, GetString ("READ_ONLY"));
1.1 root 2759:
1.1.1.13 root 2760: if (prop.readOnly || prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
2761: s = GetString ("UISTR_YES");
2762: else
2763: s = GetString ("UISTR_NO");
1.1 root 2764:
1.1.1.13 root 2765: ListSubItemSetW (list, i++, 1, s);
1.1 root 2766:
1.1.1.13 root 2767: // Hidden Volume Protection
2768: ListItemAddW (list, i, GetString ("HIDDEN_VOL_PROTECTION"));
2769: if (prop.hiddenVolume)
1.1.1.19 root 2770: s = GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE");
1.1.1.13 root 2771: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_NONE)
2772: s = GetString ("UISTR_NO");
2773: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTIVE)
2774: s = GetString ("UISTR_YES");
2775: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
2776: s = GetString ("HID_VOL_DAMAGE_PREVENTED");
1.1.1.6 root 2777:
1.1.1.13 root 2778: ListSubItemSetW (list, i++, 1, s);
2779: }
1.1 root 2780:
1.1.1.7 root 2781: // Encryption algorithm
2782: ListItemAddW (list, i, GetString ("ENCRYPTION_ALGORITHM"));
1.1.1.11 root 2783:
2784: if (prop.ea == 0 || prop.ea > EAGetCount ())
2785: {
2786: ListSubItemSet (list, i, 1, "?");
2787: return 1;
2788: }
2789:
1.1.1.7 root 2790: EAGetName (szTmp, prop.ea);
2791: ListSubItemSet (list, i++, 1, szTmp);
1.1.1.5 root 2792:
1.1.1.17 root 2793: // Key size(s)
1.1.1.7 root 2794: {
2795: char name[128];
2796: int size = EAGetKeySize (prop.ea);
2797: EAGetName (name, prop.ea);
2798:
1.1.1.12 root 2799: if (strcmp (name, "Triple DES") == 0) /* Deprecated/legacy */
1.1.1.7 root 2800: size -= 3; // Compensate for parity bytes
2801:
1.1.1.17 root 2802: // Primary key
1.1.1.7 root 2803: ListItemAddW (list, i, GetString ("KEY_SIZE"));
2804: wsprintfW (sw, L"%d %s", size * 8, GetString ("BITS"));
2805: ListSubItemSetW (list, i++, 1, sw);
1.1.1.17 root 2806:
2807: if (strcmp (EAGetModeName (prop.ea, prop.mode, TRUE), "XTS") == 0)
2808: {
2809: // Secondary key (XTS)
2810:
2811: ListItemAddW (list, i, GetString ("SECONDARY_KEY_SIZE_XTS"));
2812: ListSubItemSetW (list, i++, 1, sw);
2813: }
2814: else if (strcmp (EAGetModeName (prop.ea, prop.mode, TRUE), "LRW") == 0)
2815: {
2816: // Tweak key (LRW)
2817:
2818: ListItemAddW (list, i, GetString ("SECONDARY_KEY_SIZE_LRW"));
2819: swprintf (sw, L"%d %s", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8, GetString ("BITS"));
2820: ListSubItemSetW (list, i++, 1, sw);
2821: }
1.1.1.7 root 2822: }
1.1.1.5 root 2823:
1.1.1.7 root 2824: // Block size
2825: ListItemAddW (list, i, GetString ("BLOCK_SIZE"));
1.1.1.8 root 2826: if (EAGetFirstMode (prop.ea) == INNER_CBC)
1.1.1.5 root 2827: {
1.1.1.8 root 2828: // Cascaded ciphers with non-equal block sizes (deprecated/legacy)
2829: wchar_t tmpstr[64];
1.1.1.5 root 2830: int i = EAGetLastCipher(prop.ea);
2831:
1.1.1.7 root 2832: swprintf (sw, L"%d", CipherGetBlockSize(i)*8);
1.1.1.5 root 2833:
2834: while (i = EAGetPreviousCipher(prop.ea, i))
2835: {
1.1.1.7 root 2836: swprintf (tmpstr, L"/%d", CipherGetBlockSize(i)*8);
2837: wcscat (sw, tmpstr);
1.1.1.5 root 2838: }
1.1.1.7 root 2839: wcscat (sw, L" ");
1.1.1.5 root 2840: }
2841: else
2842: {
1.1.1.7 root 2843: swprintf (sw, L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
1.1.1.5 root 2844: }
1.1.1.7 root 2845: wcscat (sw, GetString ("BITS"));
2846: ListSubItemSetW (list, i++, 1, sw);
1.1.1.5 root 2847:
1.1.1.7 root 2848: // Mode
2849: ListItemAddW (list, i, GetString ("MODE_OF_OPERATION"));
1.1.1.8 root 2850: ListSubItemSet (list, i++, 1, EAGetModeName (prop.ea, prop.mode, TRUE));
1.1.1.7 root 2851:
1.1.1.17 root 2852: // PKCS 5 PRF
1.1.1.7 root 2853: ListItemAddW (list, i, GetString ("PKCS5_PRF"));
2854: ListSubItemSet (list, i++, 1, get_pkcs5_prf_name (prop.pkcs5));
1.1 root 2855:
1.1.1.17 root 2856: #if 0
2857: // PCKS 5 iterations
1.1.1.7 root 2858: ListItemAddW (list, i, GetString ("PKCS5_ITERATIONS"));
1.1 root 2859: sprintf (szTmp, "%d", prop.pkcs5Iterations);
1.1.1.7 root 2860: ListSubItemSet (list, i++, 1, szTmp);
1.1.1.17 root 2861: #endif
1.1.1.7 root 2862:
1.1.1.17 root 2863: #if 0
1.1 root 2864: {
1.1.1.17 root 2865: // Legacy
2866:
1.1 root 2867: FILETIME ft, curFt;
1.1.1.12 root 2868: LARGE_INTEGER ft64, curFt64;
1.1 root 2869: SYSTEMTIME st;
1.1.1.7 root 2870: wchar_t date[128];
1.1 root 2871: memset (date, 0, sizeof (date));
2872:
1.1.1.7 root 2873: // Volume date
2874: ListItemAddW (list, i, GetString ("VOLUME_CREATE_DATE"));
1.1 root 2875: *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
2876: FileTimeToSystemTime (&ft, &st);
1.1.1.7 root 2877: GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
2878: swprintf (date, L"%s ", sw);
2879: GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
2880: wcscat (date, sw);
2881: ListSubItemSetW (list, i++, 1, date);
1.1 root 2882:
1.1.1.7 root 2883: // Header date
2884: ListItemAddW (list, i, GetString ("VOLUME_HEADER_DATE"));
1.1 root 2885: *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
2886: FileTimeToSystemTime (&ft, &st);
1.1.1.7 root 2887: GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
2888: swprintf (date, L"%s ", sw);
2889: GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
2890: wcscat (date, sw);
1.1 root 2891:
2892: GetLocalTime (&st);
2893: SystemTimeToFileTime (&st, &curFt);
1.1.1.12 root 2894: curFt64.HighPart = curFt.dwHighDateTime;
2895: curFt64.LowPart = curFt.dwLowDateTime;
2896: ft64.HighPart = ft.dwHighDateTime;
2897: ft64.LowPart = ft.dwLowDateTime;
1.1.1.7 root 2898: swprintf (date + wcslen (date), GetString ("VOLUME_HEADER_DAYS")
1.1.1.12 root 2899: , (curFt64.QuadPart - ft64.QuadPart)/(24LL*3600*10000000));
1.1.1.7 root 2900: ListSubItemSetW (list, i++, 1, date);
1.1 root 2901: }
1.1.1.17 root 2902: #endif // 0
2903:
2904: if (!bSysEnc || IsHiddenOSRunning())
2905: {
2906: // Volume format version
2907: ListItemAddW (list, i, GetString ("VOLUME_FORMAT_VERSION"));
2908: sprintf (szTmp, "%d", prop.volFormatVersion);
2909: ListSubItemSet (list, i++, 1, szTmp);
2910:
2911: // Backup header
2912: ListItemAddW (list, i, GetString ("BACKUP_HEADER"));
2913: ListSubItemSetW (list, i++, 1, GetString (prop.volFormatVersion > 1 ? "UISTR_YES" : "UISTR_NO"));
2914: }
1.1 root 2915:
1.1.1.7 root 2916: // Total data read
2917: ListItemAddW (list, i, GetString ("TOTAL_DATA_READ"));
2918: GetSizeString (prop.totalBytesRead, sw);
2919: ListSubItemSetW (list, i++, 1, sw);
2920:
2921: // Total data written
2922: ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN"));
2923: GetSizeString (prop.totalBytesWritten, sw);
2924: ListSubItemSetW (list, i++, 1, sw);
2925:
1.1.1.13 root 2926: if (bSysEnc)
2927: {
1.1.1.25! root 2928: // TrueCrypt Boot Loader version
! 2929: ListItemAddW (list, i, GetString ("TC_BOOT_LOADER_VERSION"));
! 2930: ListSubItemSet (list, i++, 1, (char *) GetUserFriendlyVersionString (BootEncStatus.BootLoaderVersion).c_str());
! 2931:
1.1.1.13 root 2932: // Encrypted portion
2933: ListItemAddW (list, i, GetString ("ENCRYPTED_PORTION"));
2934: if (GetSysEncDeviceEncryptedPartSize (FALSE) == GetSysEncDeviceSize (FALSE))
2935: ListSubItemSetW (list, i++, 1, GetString ("ENCRYPTED_PORTION_FULLY_ENCRYPTED"));
2936: else if (GetSysEncDeviceEncryptedPartSize (FALSE) <= 1)
2937: ListSubItemSetW (list, i++, 1, GetString ("ENCRYPTED_PORTION_NOT_ENCRYPTED"));
2938: else
2939: {
2940:
2941: _snwprintf (sw,
2942: sizeof sw/2,
2943: GetString ("PROCESSED_PORTION_X_PERCENT"),
2944: (double) GetSysEncDeviceEncryptedPartSize (FALSE) / (double) GetSysEncDeviceSize (FALSE) * 100.0);
2945:
2946: ListSubItemSetW (list, i++, 1, sw);
2947: }
2948: }
2949:
2950: return 0;
1.1 root 2951: }
2952:
2953: case WM_COMMAND:
2954: if (lw == IDOK)
2955: {
2956: EndDialog (hwndDlg, lw);
2957: return 1;
2958: }
2959: return 0;
1.1.1.9 root 2960:
2961: case WM_CLOSE:
2962: EndDialog (hwndDlg, lw);
2963: return 1;
1.1 root 2964: }
2965:
2966: return 0;
2967: }
2968:
1.1.1.6 root 2969:
1.1.1.19 root 2970: BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.6 root 2971: {
2972: WORD lw = LOWORD (wParam);
1.1.1.21 root 2973: static BOOL bAutoRunWarningDisplayed = FALSE;
1.1.1.6 root 2974:
2975: switch (msg)
2976: {
2977: case WM_INITDIALOG:
2978: {
1.1.1.23 root 2979: char i;
2980: int index;
1.1.1.6 root 2981: char drive[] = { 0, ':', 0 };
2982:
1.1.1.13 root 2983: LocalizeDialog (hwndDlg, "IDD_TRAVELER_DLG");
1.1.1.6 root 2984:
2985: SendDlgItemMessage (hwndDlg, IDC_COPY_WIZARD, BM_SETCHECK,
2986: BST_CHECKED, 0);
2987:
1.1.1.7 root 2988: SendDlgItemMessage (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER, BM_SETCHECK,
1.1.1.6 root 2989: BST_CHECKED, 0);
2990:
2991: SendDlgItemMessage (hwndDlg, IDC_AUTORUN_DISABLE, BM_SETCHECK,
2992: BST_CHECKED, 0);
2993:
2994: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_RESETCONTENT, 0, 0);
2995:
1.1.1.7 root 2996: index = SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) GetString ("FIRST_AVAILABLE"));
1.1.1.6 root 2997: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) 0);
2998:
1.1.1.11 root 2999: for (i = 'D'; i <= 'Z'; i++)
1.1.1.6 root 3000: {
3001: drive[0] = i;
3002: index = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive);
3003: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i);
3004: }
3005:
3006: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0);
3007:
1.1.1.13 root 3008: return 0;
1.1.1.6 root 3009: }
3010:
1.1.1.7 root 3011:
1.1.1.6 root 3012: case WM_COMMAND:
3013:
1.1.1.7 root 3014: if (HIWORD (wParam) == BN_CLICKED
3015: && (lw == IDC_AUTORUN_DISABLE || lw == IDC_AUTORUN_MOUNT || lw == IDC_AUTORUN_START ))
3016: {
1.1.1.11 root 3017: BOOL enabled = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
1.1.1.7 root 3018:
3019: EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE_FILES), enabled);
3020: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_NAME), enabled);
3021: EnableWindow (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER), enabled);
3022: EnableWindow (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS), enabled);
3023: EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY), enabled);
3024: EnableWindow (GetDlgItem (hwndDlg, IDC_DRIVELIST), enabled);
1.1.1.13 root 3025: EnableWindow (GetDlgItem (hwndDlg, IDT_TRAVELER_MOUNT), enabled);
1.1.1.7 root 3026: EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_LETTER), enabled);
3027: EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_SETTINGS), enabled);
3028:
1.1.1.21 root 3029: if (!bAutoRunWarningDisplayed
3030: && (lw == IDC_AUTORUN_MOUNT || lw == IDC_AUTORUN_START))
3031: {
3032: bAutoRunWarningDisplayed = TRUE;
3033: Warning ("AUTORUN_MAY_NOT_ALWAYS_WORK");
3034: }
3035:
1.1.1.7 root 3036: return 1;
3037: }
3038:
1.1.1.6 root 3039: if (lw == IDC_BROWSE_FILES)
3040: {
1.1.1.11 root 3041: char dstDir[MAX_PATH];
1.1.1.7 root 3042: char volName[MAX_PATH] = { 0 };
1.1.1.6 root 3043:
1.1.1.11 root 3044: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
3045:
1.1.1.19 root 3046: if (BrowseFilesInDir (hwndDlg, "OPEN_TITLE", dstDir, volName, bHistory, FALSE, NULL))
1.1.1.6 root 3047: SetDlgItemText (hwndDlg, IDC_VOLUME_NAME, strchr (volName, '\\') + 1);
1.1.1.7 root 3048:
1.1.1.6 root 3049: return 1;
3050: }
3051:
3052: if (lw == IDC_BROWSE_DIRS)
3053: {
3054: char dstPath[MAX_PATH * 2];
1.1.1.7 root 3055: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath, sizeof dstPath);
1.1.1.6 root 3056:
1.1.1.7 root 3057: if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", dstPath))
1.1.1.6 root 3058: SetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath);
1.1.1.7 root 3059:
1.1.1.6 root 3060: return 1;
3061: }
3062:
1.1.1.11 root 3063: if (lw == IDCANCEL || lw == IDCLOSE)
1.1.1.6 root 3064: {
3065: EndDialog (hwndDlg, lw);
3066: return 1;
3067: }
3068:
1.1.1.7 root 3069: if (lw == IDC_CREATE)
1.1.1.6 root 3070: {
1.1.1.13 root 3071:
1.1.1.6 root 3072: BOOL copyWizard, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly;
3073: char dstDir[MAX_PATH];
3074: char srcPath[MAX_PATH * 2];
3075: char dstPath[MAX_PATH * 2];
3076: char appDir[MAX_PATH];
3077: char sysDir[MAX_PATH];
3078: char volName[MAX_PATH];
3079: int drive;
3080:
3081: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
3082: volName[0] = 0;
3083: GetDlgItemText (hwndDlg, IDC_VOLUME_NAME, volName + 1, sizeof volName);
3084:
3085: drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETCURSEL, 0, 0);
3086: drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETITEMDATA, drive, 0);
3087:
3088: copyWizard = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_WIZARD));
1.1.1.7 root 3089: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER));
3090: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS));
1.1.1.6 root 3091: bMountReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
3092: bAutoRun = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_DISABLE));
3093: bAutoMount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
3094:
3095: if (dstDir[0] == 0)
3096: {
3097: SetFocus (GetDlgItem (hwndDlg, IDC_DIRECTORY));
1.1.1.7 root 3098: MessageBoxW (hwndDlg, GetString ("NO_PATH_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6 root 3099: return 1;
3100: }
3101:
3102:
3103: if (bAutoMount && volName[1] == 0)
3104: {
3105: SetFocus (GetDlgItem (hwndDlg, IDC_VOLUME_NAME));
1.1.1.7 root 3106: MessageBoxW (hwndDlg, GetString ("NO_FILE_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6 root 3107: return 1;
3108: }
3109:
3110: if (volName[1] != 0)
3111: {
3112: volName[0] = '"';
3113: strcat (volName, "\"");
3114: }
3115:
3116: GetModuleFileName (NULL, appDir, sizeof (appDir));
3117: strrchr (appDir, '\\')[0] = 0;
3118:
1.1.1.11 root 3119: WaitCursor ();
1.1.1.6 root 3120: GetSystemDirectory (sysDir, sizeof (sysDir));
3121:
3122: sprintf (dstPath, "%s\\TrueCrypt", dstDir);
3123: CreateDirectory (dstPath, NULL);
3124:
3125: // Main app
3126: sprintf (srcPath, "%s\\TrueCrypt.exe", appDir);
3127: sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt.exe", dstDir);
3128: if (!TCCopyFile (srcPath, dstPath))
3129: {
3130: handleWin32Error (hwndDlg);
3131: goto stop;
3132: }
3133:
3134: // Wizard
3135: if (copyWizard)
3136: {
3137: sprintf (srcPath, "%s\\TrueCrypt Format.exe", appDir);
3138: sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt Format.exe", dstDir);
3139: if (!TCCopyFile (srcPath, dstPath))
3140: {
3141: handleWin32Error (hwndDlg);
3142: goto stop;
3143: }
3144: }
3145:
3146: // Driver
1.1.1.7 root 3147: sprintf (srcPath, "%s\\truecrypt.sys", appDir);
1.1.1.6 root 3148: sprintf (dstPath, "%s\\TrueCrypt\\truecrypt.sys", dstDir);
3149: if (!TCCopyFile (srcPath, dstPath))
3150: {
3151: handleWin32Error (hwndDlg);
3152: goto stop;
3153: }
3154:
1.1.1.7 root 3155: // Driver x64
3156: sprintf (srcPath, "%s\\truecrypt-x64.sys", appDir);
3157: sprintf (dstPath, "%s\\TrueCrypt\\truecrypt-x64.sys", dstDir);
3158: if (!TCCopyFile (srcPath, dstPath))
3159: {
3160: handleWin32Error (hwndDlg);
3161: goto stop;
3162: }
3163:
1.1.1.11 root 3164: if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0)
3165: {
3166: // Language pack
3167: sprintf (srcPath, "%s\\Language.%s.xml", appDir, GetPreferredLangId ());
3168: sprintf (dstPath, "%s\\TrueCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ());
3169: TCCopyFile (srcPath, dstPath);
3170: }
3171:
1.1.1.6 root 3172: // AutoRun
1.1.1.12 root 3173: sprintf (dstPath, "%s\\autorun.inf", dstDir);
3174: DeleteFile (dstPath);
1.1.1.6 root 3175: if (bAutoRun)
3176: {
3177: FILE *af;
3178: char autoMount[100];
1.1.1.23 root 3179: char driveLetter[] = { ' ', '/', 'l', (char) drive, 0 };
1.1.1.6 root 3180:
1.1.1.11 root 3181: af = fopen (dstPath, "w,ccs=UNICODE");
1.1.1.6 root 3182:
3183: if (af == NULL)
3184: {
1.1.1.7 root 3185: MessageBoxW (hwndDlg, GetString ("CANT_CREATE_AUTORUN"), lpszTitle, MB_ICONERROR);
1.1.1.6 root 3186: goto stop;
3187: }
3188:
1.1.1.11 root 3189: sprintf (autoMount, "TrueCrypt\\TrueCrypt.exe /q background%s%s%s%s /m rm /v %s",
1.1.1.6 root 3190: drive > 0 ? driveLetter : "",
3191: bExplore ? " /e" : "",
1.1.1.11 root 3192: bCacheInDriver ? " /c y" : "",
1.1.1.6 root 3193: bMountReadOnly ? " /m ro" : "",
3194: volName);
3195:
1.1.1.13 root 3196: fwprintf (af, L"[autorun]\nlabel=%s\nicon=TrueCrypt\\TrueCrypt.exe\n", GetString ("TC_TRAVELER_DISK"));
1.1.1.11 root 3197: fwprintf (af, L"action=%s\n", bAutoMount ? GetString ("MOUNT_TC_VOLUME") : GetString ("IDC_PREF_LOGON_START"));
3198: fwprintf (af, L"open=%hs\n", bAutoMount ? autoMount : "TrueCrypt\\TrueCrypt.exe");
3199: fwprintf (af, L"shell\\start=%s\nshell\\start\\command=TrueCrypt\\TrueCrypt.exe\n", GetString ("IDC_PREF_LOGON_START"));
3200: fwprintf (af, L"shell\\dismount=%s\nshell\\dismount\\command=TrueCrypt\\TrueCrypt.exe /q /d\n", GetString ("DISMOUNT_ALL_TC_VOLUMES"));
1.1.1.6 root 3201:
1.1.1.25! root 3202: CheckFileStreamWriteErrors (af, dstPath);
1.1.1.6 root 3203: fclose (af);
3204: }
1.1.1.13 root 3205: MessageBoxW (hwndDlg, GetString ("TRAVELER_DISK_CREATED"), lpszTitle, MB_ICONINFORMATION);
1.1.1.6 root 3206:
3207: stop:
3208: NormalCursor ();
3209: return 1;
3210: }
3211: return 0;
3212: }
3213:
3214: return 0;
3215: }
3216:
1.1.1.25! root 3217: void BuildTree (HWND hTree)
1.1 root 3218: {
3219: HIMAGELIST hList;
3220: HBITMAP hBitmap, hBitmapMask;
1.1.1.7 root 3221: LVCOLUMNW lvCol;
3222:
3223: ListView_DeleteColumn (hTree,0);
3224: ListView_DeleteColumn (hTree,0);
3225: ListView_DeleteColumn (hTree,0);
3226: ListView_DeleteColumn (hTree,0);
3227: ListView_DeleteColumn (hTree,0);
3228: ListView_DeleteColumn (hTree,0);
3229:
1.1 root 3230: SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
3231: LVS_EX_FULLROWSELECT
3232: |LVS_EX_HEADERDRAGDROP
3233: );
3234:
3235: memset(&lvCol,0,sizeof(lvCol));
3236:
3237: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
1.1.1.7 root 3238: lvCol.pszText = GetString ("DRIVE");
1.1.1.12 root 3239: lvCol.cx = CompensateXDPI (38);
1.1 root 3240: lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
1.1.1.7 root 3241: SendMessage (hTree,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 3242:
1.1.1.7 root 3243: lvCol.pszText = GetString ("VOLUME");
1.1.1.12 root 3244: lvCol.cx = CompensateXDPI (253);
1.1 root 3245: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 3246: SendMessage (hTree,LVM_INSERTCOLUMNW,1,(LPARAM)&lvCol);
1.1.1.23 root 3247: LastDriveListVolumeColumnWidth = ListView_GetColumnWidth (hTree, 1);
1.1 root 3248:
1.1.1.7 root 3249: lvCol.pszText = GetString ("SIZE");
1.1.1.12 root 3250: lvCol.cx = CompensateXDPI (55);
1.1 root 3251: lvCol.fmt = LVCFMT_RIGHT;
1.1.1.7 root 3252: SendMessage (hTree,LVM_INSERTCOLUMNW,2,(LPARAM)&lvCol);
1.1 root 3253:
1.1.1.11 root 3254: lvCol.pszText = GetString ("ENCRYPTION_ALGORITHM_LV");
1.1.1.12 root 3255: lvCol.cx = CompensateXDPI (121);
1.1 root 3256: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 3257: SendMessage (hTree,LVM_INSERTCOLUMNW,3,(LPARAM)&lvCol);
1.1 root 3258:
1.1.1.7 root 3259: lvCol.pszText = GetString ("TYPE");
1.1.1.12 root 3260: lvCol.cx = CompensateXDPI (52);
1.1.1.5 root 3261: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 3262: SendMessage (hTree,LVM_INSERTCOLUMNW,4,(LPARAM)&lvCol);
1.1.1.5 root 3263:
1.1.1.13 root 3264: // Regular drive icon
3265:
1.1 root 3266: hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
3267: if (hBitmap == NULL)
3268: return;
3269: hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
3270:
3271: hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
3272: if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
3273: {
3274: DeleteObject (hBitmap);
1.1.1.13 root 3275: DeleteObject (hBitmapMask);
3276: return;
3277: }
3278: else
3279: {
3280: DeleteObject (hBitmap);
3281: DeleteObject (hBitmapMask);
3282: }
3283:
3284: // System drive icon
3285:
3286: hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_SYS_DRIVEICON));
3287: if (hBitmap == NULL)
3288: return;
3289: hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_SYS_DRIVEICON_MASK));
3290:
3291: if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
3292: {
3293: DeleteObject (hBitmap);
3294: DeleteObject (hBitmapMask);
1.1 root 3295: return;
3296: }
3297: else
1.1.1.13 root 3298: {
1.1 root 3299: DeleteObject (hBitmap);
1.1.1.13 root 3300: DeleteObject (hBitmapMask);
3301: }
1.1 root 3302:
3303: ListView_SetImageList (hTree, hList, LVSIL_NORMAL);
3304: ListView_SetImageList (hTree, hList, LVSIL_SMALL);
3305:
3306: LoadDriveLetters (hTree, 0);
3307: }
3308:
1.1.1.25! root 3309: LPARAM GetSelectedLong (HWND hTree)
1.1 root 3310: {
3311: int hItem = ListView_GetSelectionMark (hTree);
3312: LVITEM item;
3313:
1.1.1.5 root 3314: if (nSelectedDriveIndex >= 0)
1.1 root 3315: hItem = nSelectedDriveIndex;
3316:
3317: memset(&item, 0, sizeof(LVITEM));
3318: item.mask = LVIF_PARAM;
3319: item.iItem = hItem;
3320:
3321: if (ListView_GetItem (hTree, &item) == FALSE)
3322: return MAKELONG (0xffff, 0xffff);
3323: else
3324: return item.lParam;
3325: }
3326:
1.1.1.25! root 3327: LPARAM GetItemLong (HWND hTree, int itemNo)
1.1 root 3328: {
3329: LVITEM item;
3330:
3331: memset(&item, 0, sizeof(LVITEM));
3332: item.mask = LVIF_PARAM;
3333: item.iItem = itemNo;
3334:
3335: if (ListView_GetItem (hTree, &item) == FALSE)
3336: return MAKELONG (0xffff, 0xffff);
3337: else
3338: return item.lParam;
3339: }
3340:
1.1.1.17 root 3341: static int AskVolumePassword (HWND hwndDlg, Password *password, char *titleStringId, BOOL enableMountOptions)
1.1 root 3342: {
1.1.1.7 root 3343: int result;
3344:
1.1.1.17 root 3345: PasswordDialogTitleStringId = titleStringId;
3346: PasswordDialogDisableMountOptions = !enableMountOptions;
3347:
1.1.1.7 root 3348: result = DialogBoxParamW (hInst,
3349: MAKEINTRESOURCEW (IDD_PASSWORD_DLG), hwndDlg,
1.1 root 3350: (DLGPROC) PasswordDlgProc, (LPARAM) password);
3351:
3352: if (result != IDOK)
1.1.1.7 root 3353: {
3354: password->Length = 0;
3355: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
3356: }
1.1 root 3357:
3358: return result == IDOK;
3359: }
3360:
3361: // GUI actions
3362:
1.1.1.7 root 3363: static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
1.1 root 3364: {
1.1.1.7 root 3365: BOOL status = FALSE;
3366: char fileName[MAX_PATH];
1.1.1.13 root 3367: int mounted = 0, modeOfOperation;
1.1.1.7 root 3368: if (nDosDriveNo == 0)
3369: nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
1.1 root 3370:
1.1.1.23 root 3371: if (!MultipleMountOperationInProgress)
3372: VolumePassword.Length = 0;
1.1.1.7 root 3373:
3374: if (szFileName == NULL)
3375: {
3376: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), fileName, sizeof (fileName));
3377: szFileName = fileName;
3378: }
1.1 root 3379:
3380: if (strlen(szFileName) == 0)
1.1.1.7 root 3381: {
3382: status = FALSE;
3383: goto ret;
3384: }
1.1 root 3385:
3386: if (IsMountedVolume (szFileName))
3387: {
1.1.1.11 root 3388: Warning ("VOL_ALREADY_MOUNTED");
1.1.1.7 root 3389: status = FALSE;
3390: goto ret;
1.1 root 3391: }
3392:
1.1.1.23 root 3393: if (!VolumePathExists (szFileName))
3394: {
3395: if (!MultipleMountOperationInProgress)
3396: handleWin32Error (hwndDlg);
3397:
3398: status = FALSE;
3399: goto ret;
3400: }
3401:
1.1.1.17 root 3402: ResetWrongPwdRetryCount ();
3403:
1.1 root 3404: // First try cached passwords and if they fail ask user for a new one
1.1.1.11 root 3405: WaitCursor ();
1.1.1.7 root 3406:
1.1.1.23 root 3407: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1 root 3408:
1.1.1.7 root 3409: // If keyfiles are enabled, test empty password first
1.1.1.24 root 3410: if (!mounted && KeyFilesEnable && FirstKeyFile)
1.1 root 3411: {
1.1.1.24 root 3412: Password emptyPassword;
3413: emptyPassword.Length = 0;
3414:
3415: KeyFilesApply (&emptyPassword, FirstKeyFile);
3416: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &emptyPassword, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
3417:
3418: burn (&emptyPassword, sizeof (emptyPassword));
1.1.1.7 root 3419: }
1.1 root 3420:
1.1.1.24 root 3421: // Test password and/or keyfiles used for the previous volume
3422: if (!mounted && MultipleMountOperationInProgress && VolumePassword.Length != 0)
1.1.1.23 root 3423: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
3424:
1.1.1.13 root 3425: NormalCursor ();
3426:
1.1.1.11 root 3427: if (mounted)
3428: {
1.1.1.13 root 3429: // Check for deprecated CBC mode
3430: modeOfOperation = GetModeOfOperationByDriveNo (nDosDriveNo);
3431: if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
3432: Warning("WARN_CBC_MODE");
3433:
3434: // Check for deprecated 64-bit-block ciphers
1.1.1.11 root 3435: if (GetCipherBlockSizeByDriveNo (nDosDriveNo) == 64)
3436: Warning("WARN_64_BIT_BLOCK_CIPHER");
3437:
3438: // Check for problematic file extensions (exe, dll, sys)
3439: if (CheckFileExtension(szFileName))
3440: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
3441: }
3442:
1.1.1.7 root 3443: while (mounted == 0)
3444: {
3445: if (CmdVolumePassword.Length > 0)
3446: {
3447: VolumePassword = CmdVolumePassword;
3448: }
3449: else if (!Silent)
3450: {
3451: strcpy (PasswordDlgVolume, szFileName);
1.1.1.17 root 3452: if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
1.1.1.7 root 3453: goto ret;
3454: }
3455:
1.1.1.11 root 3456: WaitCursor ();
1.1.1.7 root 3457:
3458: if (KeyFilesEnable)
1.1.1.12 root 3459: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 3460:
1.1.1.23 root 3461: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, Silent, !Silent);
1.1 root 3462: NormalCursor ();
1.1.1.7 root 3463:
1.1.1.13 root 3464: // Check for deprecated CBC mode
3465: modeOfOperation = GetModeOfOperationByDriveNo (nDosDriveNo);
3466: if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
3467: Warning("WARN_CBC_MODE");
3468:
3469: // Check for deprecated 64-bit-block ciphers
1.1.1.11 root 3470: if (GetCipherBlockSizeByDriveNo (nDosDriveNo) == 64)
3471: Warning("WARN_64_BIT_BLOCK_CIPHER");
3472:
3473: // Check for legacy non-ASCII passwords
1.1.1.9 root 3474: if (mounted > 0 && !KeyFilesEnable && !CheckPasswordCharEncoding (NULL, &VolumePassword))
3475: Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
3476:
1.1.1.11 root 3477: // Check for problematic file extensions (exe, dll, sys)
1.1.1.13 root 3478: if (mounted > 0 && CheckFileExtension (szFileName))
1.1.1.11 root 3479: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
3480:
1.1.1.23 root 3481: if (!MultipleMountOperationInProgress)
3482: burn (&VolumePassword, sizeof (VolumePassword));
3483:
1.1.1.7 root 3484: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
3485:
3486: if (CmdVolumePassword.Length > 0 || Silent)
3487: break;
1.1 root 3488: }
3489:
1.1.1.5 root 3490: if (mounted > 0)
1.1 root 3491: {
1.1.1.7 root 3492: status = TRUE;
3493:
3494: if (bBeep)
1.1.1.23 root 3495: MessageBeep (0xFFFFFFFF);
1.1 root 3496:
3497: RefreshMainDlg(hwndDlg);
3498:
1.1.1.7 root 3499: if (bExplore)
1.1 root 3500: {
1.1.1.11 root 3501: WaitCursor();
1.1 root 3502: OpenVolumeExplorerWindow (nDosDriveNo);
3503: NormalCursor();
3504: }
1.1.1.7 root 3505:
3506: if (mountOptions.ProtectHiddenVolume)
3507: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
1.1 root 3508: }
3509:
1.1.1.7 root 3510: ret:
1.1.1.23 root 3511: if (!MultipleMountOperationInProgress)
3512: burn (&VolumePassword, sizeof (VolumePassword));
3513:
1.1.1.7 root 3514: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
1.1.1.11 root 3515:
1.1.1.7 root 3516: RestoreDefaultKeyFilesParam ();
1.1.1.11 root 3517:
3518: if (UsePreferences)
3519: bCacheInDriver = bCacheInDriverDefault;
3520:
1.1.1.19 root 3521: if (status && CloseSecurityTokenSessionsAfterMount && !MultipleMountOperationInProgress)
3522: SecurityToken::CloseAllSessions();
3523:
1.1.1.7 root 3524: return status;
1.1 root 3525: }
3526:
3527:
1.1.1.7 root 3528: static BOOL Dismount (HWND hwndDlg, int nDosDriveNo)
1.1 root 3529: {
1.1.1.7 root 3530: BOOL status = FALSE;
1.1.1.11 root 3531: WaitCursor ();
1.1 root 3532:
1.1.1.2 root 3533: if (nDosDriveNo == 0)
3534: nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
1.1 root 3535:
1.1.1.5 root 3536: if (bCloseDismountedWindows)
1.1 root 3537: {
1.1.1.6 root 3538: CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
1.1 root 3539: }
3540:
1.1.1.5 root 3541: if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
3542: {
1.1.1.7 root 3543: status = TRUE;
3544:
3545: if (bBeep)
1.1.1.23 root 3546: MessageBeep (0xFFFFFFFF);
1.1.1.5 root 3547: RefreshMainDlg (hwndDlg);
1.1.1.10 root 3548:
3549: if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
3550: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1 root 3551: }
3552:
1.1.1.5 root 3553: NormalCursor ();
1.1.1.7 root 3554: return status;
1.1 root 3555: }
3556:
1.1.1.7 root 3557: static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dismountMaxRetries, int dismountAutoRetryDelay)
1.1 root 3558: {
1.1.1.7 root 3559: BOOL status = TRUE;
1.1.1.5 root 3560: MOUNT_LIST_STRUCT mountList;
3561: DWORD dwResult;
3562: UNMOUNT_STRUCT unmount;
1.1 root 3563: BOOL bResult;
1.1.1.5 root 3564: unsigned __int32 prevMountedDrives = 0;
3565: int i;
1.1 root 3566:
1.1.1.5 root 3567: retry:
1.1.1.11 root 3568: WaitCursor();
1.1 root 3569:
1.1.1.13 root 3570: DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.7 root 3571:
3572: if (mountList.ulMountedDrives == 0)
3573: {
3574: NormalCursor();
3575: return TRUE;
3576: }
3577:
1.1.1.11 root 3578: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, 0, mountList.ulMountedDrives);
3579:
1.1.1.5 root 3580: prevMountedDrives = mountList.ulMountedDrives;
3581:
3582: for (i = 0; i < 26; i++)
1.1 root 3583: {
1.1.1.5 root 3584: if (mountList.ulMountedDrives & (1 << i))
1.1 root 3585: {
1.1.1.5 root 3586: if (bCloseDismountedWindows)
1.1.1.6 root 3587: CloseVolumeExplorerWindows (hwndDlg, i);
1.1 root 3588: }
1.1.1.5 root 3589: }
1.1 root 3590:
1.1.1.5 root 3591: unmount.nDosDriveNo = 0;
3592: unmount.ignoreOpenFiles = forceUnmount;
1.1 root 3593:
1.1.1.6 root 3594: do
3595: {
1.1.1.13 root 3596: bResult = DeviceIoControl (hDriver, TC_IOCTL_DISMOUNT_ALL_VOLUMES, &unmount,
1.1.1.6 root 3597: sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
3598:
3599: if (bResult == FALSE)
3600: {
3601: NormalCursor();
3602: handleWin32Error (hwndDlg);
1.1.1.7 root 3603: return FALSE;
1.1.1.6 root 3604: }
1.1 root 3605:
1.1.1.17 root 3606: if (unmount.nReturnCode == ERR_SUCCESS
3607: && unmount.HiddenVolumeProtectionTriggered
3608: && !VolumeNotificationsList.bHidVolDamagePrevReported [unmount.nDosDriveNo])
3609: {
3610: wchar_t msg[4096];
3611:
3612: VolumeNotificationsList.bHidVolDamagePrevReported [unmount.nDosDriveNo] = TRUE;
3613: swprintf (msg, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), unmount.nDosDriveNo + 'A');
3614: SetForegroundWindow (hwndDlg);
3615: MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
3616:
3617: unmount.HiddenVolumeProtectionTriggered = FALSE;
3618: continue;
3619: }
3620:
1.1.1.6 root 3621: if (unmount.nReturnCode == ERR_FILES_OPEN)
1.1.1.7 root 3622: Sleep (dismountAutoRetryDelay);
1.1.1.6 root 3623: else
3624: break;
1.1 root 3625:
1.1.1.6 root 3626: } while (--dismountMaxRetries > 0);
1.1 root 3627:
1.1.1.7 root 3628: memset (&mountList, 0, sizeof (mountList));
1.1.1.13 root 3629: DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.6 root 3630: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
1.1 root 3631:
1.1.1.7 root 3632: RefreshMainDlg (hwndDlg);
1.1.1.10 root 3633:
3634: if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
3635: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
3636:
1.1.1.5 root 3637: NormalCursor();
1.1 root 3638:
1.1.1.5 root 3639: if (unmount.nReturnCode != 0)
3640: {
1.1.1.7 root 3641: if (forceUnmount)
3642: status = FALSE;
3643:
1.1.1.5 root 3644: if (unmount.nReturnCode == ERR_FILES_OPEN)
3645: {
1.1.1.7 root 3646: if (interact && IDYES == AskWarnNoYes ("UNMOUNTALL_LOCK_FAILED"))
1.1 root 3647: {
1.1.1.5 root 3648: forceUnmount = TRUE;
3649: goto retry;
1.1 root 3650: }
1.1.1.5 root 3651:
1.1.1.23 root 3652: if (IsOSAtLeast (WIN_7))
3653: {
3654: // Undo SHCNE_DRIVEREMOVED
3655: DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, NULL, 0, &mountList, sizeof (mountList), &dwResult, NULL);
3656:
3657: for (i = 0; i < 26; i++)
3658: {
3659: if (mountList.ulMountedDrives & (1 << i))
3660: {
3661: char root[] = { (char) i + 'A', ':', '\\', 0 };
3662: SHChangeNotify (SHCNE_DRIVEADD, SHCNF_PATH, root, NULL);
3663: }
3664: }
3665: }
3666:
1.1.1.7 root 3667: return FALSE;
1.1 root 3668: }
1.1.1.5 root 3669:
1.1.1.7 root 3670: if (interact)
3671: MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
1.1 root 3672: }
3673: else
3674: {
1.1.1.7 root 3675: if (bBeep)
1.1.1.23 root 3676: MessageBeep (0xFFFFFFFF);
1.1 root 3677: }
1.1.1.7 root 3678:
3679: return status;
1.1 root 3680: }
3681:
1.1.1.7 root 3682: static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
1.1 root 3683: {
3684: HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
1.1.1.19 root 3685: int selDrive = ListView_GetSelectionMark (driveList);
1.1.1.17 root 3686: BOOL shared = FALSE, status = FALSE, b64BitBlockCipher = FALSE, bCBCMode = FALSE, bHeaderBakRetry = FALSE;
1.1.1.13 root 3687: int mountedVolCount = 0, modeOfOperation;
1.1.1.19 root 3688: vector <HostDevice> devices;
1.1.1.6 root 3689:
1.1.1.7 root 3690: VolumePassword.Length = 0;
1.1.1.6 root 3691: mountOptions = defaultMountOptions;
1.1.1.15 root 3692: bPrebootPasswordDlgMode = FALSE;
1.1.1.6 root 3693:
1.1.1.19 root 3694: if (selDrive == -1)
3695: selDrive = 0;
1.1 root 3696:
1.1.1.17 root 3697: ResetWrongPwdRetryCount ();
3698:
1.1.1.19 root 3699: MultipleMountOperationInProgress = TRUE;
3700:
1.1.1.7 root 3701: do
1.1 root 3702: {
1.1.1.17 root 3703: if (!bHeaderBakRetry)
1.1.1.7 root 3704: {
1.1.1.17 root 3705: if (!CmdVolumePasswordValid && bPasswordPrompt)
3706: {
3707: PasswordDlgVolume[0] = '\0';
3708: if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
3709: goto ret;
3710: }
3711: else if (CmdVolumePasswordValid)
3712: {
3713: bPasswordPrompt = FALSE;
3714: VolumePassword = CmdVolumePassword;
3715: }
1.1.1.7 root 3716:
1.1.1.17 root 3717: WaitCursor();
1.1.1.7 root 3718:
1.1.1.17 root 3719: if (FirstCmdKeyFile)
3720: KeyFilesApply (&VolumePassword, FirstCmdKeyFile);
3721: else if (KeyFilesEnable)
3722: KeyFilesApply (&VolumePassword, FirstKeyFile);
3723:
3724: }
1.1.1.7 root 3725:
1.1.1.19 root 3726: if (devices.empty())
1.1.1.22 root 3727: devices = GetAvailableHostDevices (true, false, true, true);
1.1.1.19 root 3728: foreach (const HostDevice &drive, devices)
1.1 root 3729: {
1.1.1.19 root 3730: vector <HostDevice> partitions = drive.Partitions;
3731: partitions.insert (partitions.begin(), drive);
3732:
3733: foreach (const HostDevice &device, partitions)
1.1.1.7 root 3734: {
3735: char szFileName[TC_MAX_PATH];
1.1.1.19 root 3736: strcpy_s (szFileName, sizeof (szFileName), device.Path.c_str());
3737: BOOL mounted = IsMountedVolume (szFileName);
1.1.1.6 root 3738:
1.1.1.7 root 3739: // Skip other partitions of the disk if partition0 (whole disk) is mounted
1.1.1.19 root 3740: if (!device.IsPartition && mounted)
1.1.1.7 root 3741: break;
1.1.1.6 root 3742:
1.1.1.19 root 3743: if (device.Floppy)
1.1.1.21 root 3744: break;
3745:
3746: if (device.HasUnencryptedFilesystem && !mountOptions.UseBackupHeader && !bHeaderBakRetry)
1.1.1.19 root 3747: continue;
3748:
3749: if (!mounted)
1.1.1.7 root 3750: {
3751: int nDosDriveNo;
1.1 root 3752:
1.1.1.7 root 3753: while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
1.1 root 3754: {
1.1.1.13 root 3755: if(LOWORD (GetItemLong (driveList, selDrive)) != TC_MLIST_ITEM_FREE)
1.1.1.7 root 3756: {
3757: selDrive++;
3758: continue;
3759: }
3760: nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
3761: break;
1.1 root 3762: }
3763:
1.1.1.7 root 3764: if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
3765: goto ret;
1.1 root 3766:
1.1.1.7 root 3767: // First try user password then cached passwords
3768: if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0
3769: || (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0)
3770: {
1.1.1.17 root 3771: // A volume has been successfully mounted
3772:
3773: ResetWrongPwdRetryCount ();
3774:
1.1.1.7 root 3775: if (mounted == 2)
3776: shared = TRUE;
1.1.1.5 root 3777:
1.1.1.7 root 3778: LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
3779: selDrive++;
1.1 root 3780:
1.1.1.7 root 3781: if (bExplore)
3782: {
1.1.1.11 root 3783: WaitCursor();
1.1.1.7 root 3784: OpenVolumeExplorerWindow (nDosDriveNo);
3785: NormalCursor();
3786: }
3787:
3788: if (bBeep)
1.1.1.23 root 3789: MessageBeep (0xFFFFFFFF);
1.1.1.6 root 3790:
1.1.1.7 root 3791: status = TRUE;
3792:
1.1.1.13 root 3793: // Check for deprecated CBC mode
3794: modeOfOperation = GetModeOfOperationByDriveNo (nDosDriveNo);
3795: bCBCMode = (modeOfOperation == CBC || modeOfOperation == OUTER_CBC);
3796:
1.1.1.11 root 3797: if (GetCipherBlockSizeByDriveNo(nDosDriveNo) == 64)
3798: b64BitBlockCipher = TRUE;
3799:
1.1.1.7 root 3800: mountedVolCount++;
3801:
3802: // Skip other partitions of the disk if partition0 (whole disk) has been mounted
1.1.1.19 root 3803: if (!device.IsPartition)
1.1.1.7 root 3804: break;
3805: }
1.1 root 3806: }
3807: }
3808: }
1.1.1.8 root 3809:
1.1.1.17 root 3810: if (mountedVolCount < 1)
3811: {
3812: // Failed to mount any volume
3813:
3814: IncreaseWrongPwdRetryCount (1);
1.1.1.8 root 3815:
1.1.1.17 root 3816: if (WrongPwdRetryCountOverLimit ()
3817: && !mountOptions.UseBackupHeader
3818: && !bHeaderBakRetry)
3819: {
3820: // Retry using embedded header backup (if any)
3821: mountOptions.UseBackupHeader = TRUE;
3822: bHeaderBakRetry = TRUE;
3823: }
3824: else if (bHeaderBakRetry)
3825: {
3826: mountOptions.UseBackupHeader = defaultMountOptions.UseBackupHeader;
3827: bHeaderBakRetry = FALSE;
3828: }
3829:
3830: if (!Silent && !bHeaderBakRetry)
3831: {
3832: WCHAR szTmp[4096];
3833:
3834: swprintf (szTmp, GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"));
3835: if (CheckCapsLock (hwndDlg, TRUE))
3836: wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
3837:
3838: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING);
3839: }
3840: }
3841: else if (bHeaderBakRetry)
1.1.1.7 root 3842: {
1.1.1.17 root 3843: // We have successfully mounted a volume using the header backup embedded in the volume (the header is damaged)
3844: mountOptions.UseBackupHeader = defaultMountOptions.UseBackupHeader;
3845: bHeaderBakRetry = FALSE;
1.1.1.7 root 3846:
1.1.1.17 root 3847: if (!Silent)
3848: Warning ("HEADER_DAMAGED_AUTO_USED_HEADER_BAK");
3849: }
1.1.1.7 root 3850:
1.1.1.17 root 3851: if (!bHeaderBakRetry)
3852: {
3853: burn (&VolumePassword, sizeof (VolumePassword));
3854: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
1.1.1.7 root 3855: }
3856:
3857: } while (bPasswordPrompt && mountedVolCount < 1);
3858:
3859: /* One or more volumes successfully mounted */
1.1 root 3860:
1.1.1.17 root 3861: ResetWrongPwdRetryCount ();
3862:
1.1.1.5 root 3863: if (shared)
1.1.1.7 root 3864: Warning ("DEVICE_IN_USE_INFO");
3865:
3866: if (mountOptions.ProtectHiddenVolume)
3867: {
1.1.1.11 root 3868: if (mountedVolCount > 1)
1.1.1.7 root 3869: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT_PLURAL");
3870: else if (mountedVolCount == 1)
3871: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
3872: }
3873:
1.1.1.13 root 3874: // Check for deprecated CBC mode
3875: if (bCBCMode)
3876: Warning("WARN_CBC_MODE");
3877:
3878: // Check for deprecated 64-bit-block ciphers
1.1.1.11 root 3879: if (b64BitBlockCipher)
3880: Warning("WARN_64_BIT_BLOCK_CIPHER");
3881:
3882: // Check for legacy non-ASCII passwords
1.1.1.7 root 3883: if (!KeyFilesEnable
3884: && !FirstCmdKeyFile
3885: && mountedVolCount > 0
3886: && !CheckPasswordCharEncoding (NULL, &VolumePassword))
3887: Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
1.1.1.5 root 3888:
1.1.1.19 root 3889: if (status && CloseSecurityTokenSessionsAfterMount)
3890: SecurityToken::CloseAllSessions();
3891:
1.1.1.13 root 3892: ret:
1.1.1.19 root 3893: MultipleMountOperationInProgress = FALSE;
3894:
1.1.1.13 root 3895: burn (&VolumePassword, sizeof (VolumePassword));
3896: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
3897:
1.1.1.17 root 3898: mountOptions.UseBackupHeader = defaultMountOptions.UseBackupHeader;
3899:
1.1.1.13 root 3900: RestoreDefaultKeyFilesParam ();
3901:
3902: if (UsePreferences)
3903: bCacheInDriver = bCacheInDriverDefault;
3904:
3905: EnableDisableButtons (hwndDlg);
3906:
3907: NormalCursor();
3908:
3909: return status;
3910: }
3911:
3912: static void ChangePassword (HWND hwndDlg)
3913: {
3914: int result;
3915:
3916: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
3917: if (IsMountedVolume (szFileName))
3918: {
3919: Warning (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF ? "MOUNTED_NO_PKCS5_PRF_CHANGE" : "MOUNTED_NOPWCHANGE");
3920: return;
3921: }
3922:
1.1.1.23 root 3923: if (!VolumePathExists (szFileName))
3924: {
3925: handleWin32Error (hwndDlg);
3926: return;
3927: }
3928:
1.1.1.13 root 3929: bSysEncPwdChangeDlgMode = FALSE;
3930:
3931: result = DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_PASSWORDCHANGE_DLG), hwndDlg,
3932: (DLGPROC) PasswordChangeDlgProc);
3933:
3934: if (result == IDOK)
3935: {
3936: switch (pwdChangeDlgMode)
3937: {
3938: case PCDM_CHANGE_PKCS5_PRF:
3939: Info ("PKCS5_PRF_CHANGED");
3940: break;
3941:
3942: case PCDM_ADD_REMOVE_VOL_KEYFILES:
3943: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
3944: Info ("KEYFILE_CHANGED");
3945: break;
3946:
3947: case PCDM_CHANGE_PASSWORD:
3948: default:
3949: Info ("PASSWORD_CHANGED");
3950: }
3951: }
3952: }
3953:
3954: // Change password of the system partition/drive
3955: static void ChangeSysEncPassword (HWND hwndDlg, BOOL bOnlyChangeKDF)
3956: {
3957: try
3958: {
3959: BootEncStatus = BootEncObj->GetStatus();
3960: }
3961: catch (Exception &e)
3962: {
3963: e.Show (MainDlg);
3964: }
3965:
3966: if (!BootEncStatus.DriveEncrypted
3967: && !BootEncStatus.DriveMounted
3968: && !BootEncStatus.VolumeHeaderPresent
3969: && !SysEncryptionOrDecryptionRequired ())
3970: {
3971: Warning ("SYS_DRIVE_NOT_ENCRYPTED");
3972: return;
3973: }
3974:
3975: if (SysEncryptionOrDecryptionRequired ()
3976: || BootEncStatus.SetupInProgress)
3977: {
3978: Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
3979: return;
3980: }
3981:
3982: if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption
3983: {
3984: sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
3985:
3986: bSysEncPwdChangeDlgMode = TRUE;
3987:
3988: if (bOnlyChangeKDF)
3989: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
3990: else
3991: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
3992:
3993:
3994: if (DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_PASSWORDCHANGE_DLG), hwndDlg,
3995: (DLGPROC) PasswordChangeDlgProc) == IDOK)
3996: {
3997: switch (pwdChangeDlgMode)
3998: {
3999: case PCDM_CHANGE_PKCS5_PRF:
4000: Info ("PKCS5_PRF_CHANGED");
4001:
1.1.1.17 root 4002: if (!IsHiddenOSRunning())
4003: {
4004: if (AskWarnYesNo ("SYS_HKD_ALGO_CHANGED_ASK_RESCUE_DISK") == IDYES)
4005: CreateRescueDisk ();
4006: }
1.1.1.13 root 4007:
4008: break;
4009:
4010: case PCDM_ADD_REMOVE_VOL_KEYFILES:
4011: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
4012: // NOP - Keyfiles are not supported for system encryption
4013: break;
4014:
4015: case PCDM_CHANGE_PASSWORD:
4016: default:
4017: Info ("PASSWORD_CHANGED");
4018:
1.1.1.17 root 4019: if (!IsHiddenOSRunning())
4020: {
4021: if (AskWarnYesNo ("SYS_PASSWORD_CHANGED_ASK_RESCUE_DISK") == IDYES)
4022: CreateRescueDisk ();
4023: }
1.1.1.13 root 4024: }
4025: }
4026:
4027: bSysEncPwdChangeDlgMode = FALSE;
4028:
1.1.1.15 root 4029: if (bKeyboardLayoutChanged)
4030: {
4031: // Restore the original keyboard layout
4032: if (LoadKeyboardLayout (OrigKeyboardLayout, KLF_ACTIVATE | KLF_SUBSTITUTE_OK) == NULL)
4033: Warning ("CANNOT_RESTORE_KEYBOARD_LAYOUT");
4034: else
4035: bKeyboardLayoutChanged = FALSE;
4036: }
4037:
4038: bKeybLayoutAltKeyWarningShown = FALSE;
1.1.1.13 root 4039:
4040: CloseSysEncMutex ();
4041: }
4042: else
4043: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
4044: }
4045:
4046: // Initiates or resumes encryption of the system partition/drive
4047: static void EncryptSystemDevice (void)
4048: {
4049: try
4050: {
4051: BootEncStatus = BootEncObj->GetStatus();
4052: }
4053: catch (Exception &e)
4054: {
4055: e.Show (MainDlg);
4056: }
4057:
4058: if (!BootEncStatus.DriveEncrypted
4059: && !BootEncStatus.DriveMounted
4060: && !SysEncryptionOrDecryptionRequired ())
4061: {
4062: // System partition/drive is not encrypted (nothing to resume). Initiate the process.
4063:
1.1.1.17 root 4064: if (!MutexExistsOnSystem (TC_MUTEX_NAME_SYSENC)) // If no instance of the wizard is currently taking care of system encryption
1.1.1.13 root 4065: {
4066: LaunchVolCreationWizard (MainDlg, "/sysenc");
4067: }
4068: else
4069: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
4070:
4071: return;
4072: }
4073: else if (SysEncryptionOrDecryptionRequired ())
4074: {
4075: // System partition/drive encryption already initiated but is incomplete -- attempt to resume the process.
4076: // Note that this also covers the pretest phase and paused decryption (reverses decrypting and starts encrypting)
4077:
1.1.1.17 root 4078: if (!MutexExistsOnSystem (TC_MUTEX_NAME_SYSENC)) // If no instance of the wizard is currently taking care of system encryption
1.1.1.13 root 4079: {
4080: LaunchVolCreationWizard (MainDlg, "/sysenc");
4081: }
4082: else
4083: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
4084: }
4085: else if (SysDriveOrPartitionFullyEncrypted (FALSE))
4086: {
4087: // System partition/drive appears to be fully encrypted
4088: Info ("SYS_PARTITION_OR_DRIVE_APPEARS_FULLY_ENCRYPTED");
4089: return;
4090: }
4091: }
4092:
4093: // Initiates decryption of the system partition/drive
4094: static void DecryptSystemDevice (void)
4095: {
4096: try
4097: {
4098: BootEncStatus = BootEncObj->GetStatus();
4099: }
4100: catch (Exception &e)
4101: {
4102: e.Show (MainDlg);
4103: }
4104:
4105: if (!BootEncStatus.DriveEncrypted
4106: && !BootEncStatus.DriveMounted
1.1.1.14 root 4107: && !BootEncStatus.DeviceFilterActive
1.1.1.13 root 4108: && !BootEncStatus.VolumeHeaderPresent
4109: && !SysEncryptionOrDecryptionRequired ())
4110: {
4111: Warning ("SYS_DRIVE_NOT_ENCRYPTED");
4112: return;
4113: }
4114:
1.1.1.17 root 4115: if (IsHiddenOSRunning())
4116: {
4117: Warning ("CANNOT_DECRYPT_HIDDEN_OS");
4118: return;
4119: }
4120:
1.1.1.13 root 4121: if (AskNoYes ("CONFIRM_DECRYPT_SYS_DEVICE") == IDNO)
4122: return;
4123:
4124: if (AskWarnNoYes ("CONFIRM_DECRYPT_SYS_DEVICE_CAUTION") == IDNO)
4125: return;
4126:
4127: if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption
4128: {
4129: try
4130: {
4131: // User-mode app may have crashed and its mutex may have gotten lost, so we need to check the driver status too
4132: if (BootEncStatus.SetupInProgress)
4133: {
4134: int attempts = 20;
4135:
4136: BootEncObj->AbortSetup ();
4137: while (BootEncStatus.SetupInProgress && attempts > 0)
4138: {
4139: Sleep (100);
4140: BootEncStatus = BootEncObj->GetStatus();
4141: attempts--;
4142: WaitCursor();
4143: }
4144: }
4145: }
4146: catch (Exception &e)
4147: {
4148: e.Show (MainDlg);
4149: }
4150: NormalCursor ();
4151:
4152: if (BootEncStatus.SetupInProgress)
4153: {
4154: CloseSysEncMutex ();
4155: Error ("SYS_ENCRYPTION_OR_DECRYPTION_IN_PROGRESS");
4156: return;
4157: }
4158:
4159: CloseSysEncMutex ();
4160: LaunchVolCreationWizard (MainDlg, "/dsysenc");
4161: }
4162: else
4163: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
4164: }
4165:
1.1.1.17 root 4166: // Initiates the process of creation of a hidden operating system
4167: static void CreateHiddenOS (void)
4168: {
4169:
4170: // Display brief information as to what a hidden operating system is and what it's good for. This needs to be
4171: // done, because if the system partition/drive is currently encrypted, the wizard will not display any
4172: // such information, but will exit (displaying only an error meessage).
4173: Info("HIDDEN_OS_PREINFO");
4174:
4175: LaunchVolCreationWizard (MainDlg, "/isysenc");
4176: }
4177:
1.1.1.13 root 4178: // Blindly attempts (without any checks) to instruct the wizard to resume whatever system encryption process
4179: // had been interrupted or not started but scheduled or exptected to start.
4180: static void ResumeInterruptedSysEncProcess (void)
4181: {
1.1.1.17 root 4182: if (!MutexExistsOnSystem (TC_MUTEX_NAME_SYSENC)) // If no instance of the wizard is currently taking care of system encryption
1.1.1.13 root 4183: {
4184: LaunchVolCreationWizard (MainDlg, "/csysenc");
4185: }
4186: else
4187: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
4188: }
4189:
4190: void CreateRescueDisk (void)
4191: {
4192: try
4193: {
4194: BootEncStatus = BootEncObj->GetStatus();
4195: }
4196: catch (Exception &e)
4197: {
4198: e.Show (MainDlg);
4199: }
4200:
1.1.1.17 root 4201: if (IsHiddenOSRunning())
4202: {
4203: Warning ("CANNOT_CREATE_RESCUE_DISK_ON_HIDDEN_OS");
4204: return;
4205: }
4206:
1.1.1.13 root 4207: if (!BootEncStatus.DriveEncrypted
4208: && !BootEncStatus.DriveMounted
4209: && !BootEncStatus.VolumeHeaderPresent
4210: && !SysEncryptionOrDecryptionRequired ())
4211: {
4212: Warning ("SYS_DRIVE_NOT_ENCRYPTED");
4213: return;
4214: }
4215:
4216: if (SysEncryptionOrDecryptionRequired ()
4217: || BootEncStatus.SetupInProgress)
4218: {
4219: Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
4220: return;
4221: }
4222:
4223: if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption
4224: {
4225: try
4226: {
4227: wchar_t szTmp [8096];
4228: char szRescueDiskISO [TC_MAX_PATH+1];
4229:
4230: if (AskOkCancel ("RESCUE_DISK_NON_WIZARD_CREATION_SELECT_PATH") != IDOK)
1.1.1.19 root 4231: {
4232: CloseSysEncMutex ();
1.1.1.13 root 4233: return;
1.1.1.19 root 4234: }
1.1.1.11 root 4235:
1.1.1.23 root 4236: char initialDir[MAX_PATH];
4237: SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, initialDir);
4238:
4239: if (!BrowseFilesInDir (MainDlg, "OPEN_TITLE", initialDir, szRescueDiskISO, FALSE, TRUE, NULL, L"TrueCrypt Rescue Disk.iso", L"iso"))
1.1.1.19 root 4240: {
4241: CloseSysEncMutex ();
1.1.1.13 root 4242: return;
1.1.1.19 root 4243: }
1.1.1.11 root 4244:
1.1.1.13 root 4245: WaitCursor();
4246: BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO);
1.1.1.11 root 4247:
1.1.1.13 root 4248: _snwprintf (szTmp, sizeof szTmp / 2,
1.1.1.23 root 4249: GetString (IsWindowsIsoBurnerAvailable() ? "RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN" : "RESCUE_DISK_NON_WIZARD_CREATION_BURN"),
1.1.1.13 root 4250: szRescueDiskISO);
1.1.1.11 root 4251:
1.1.1.23 root 4252: if (IsWindowsIsoBurnerAvailable())
4253: {
4254: if (AskYesNoString (szTmp) == IDYES)
4255: LaunchWindowsIsoBurner (MainDlg, szRescueDiskISO);
4256: }
4257: else
4258: InfoDirect (szTmp);
1.1.1.13 root 4259: }
4260: catch (Exception &e)
4261: {
4262: e.Show (MainDlg);
4263: Error ("ERROR_CREATING_RESCUE_DISK");
4264: }
4265: CloseSysEncMutex ();
1.1.1.7 root 4266:
1.1.1.13 root 4267: NormalCursor ();
4268: }
4269: else
4270: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
1.1 root 4271: }
4272:
1.1.1.13 root 4273: static void VerifyRescueDisk (void)
1.1 root 4274: {
1.1.1.13 root 4275: try
1.1 root 4276: {
1.1.1.13 root 4277: BootEncStatus = BootEncObj->GetStatus();
4278: }
4279: catch (Exception &e)
4280: {
4281: e.Show (MainDlg);
1.1 root 4282: }
4283:
1.1.1.13 root 4284: if (!BootEncStatus.DriveEncrypted
4285: && !BootEncStatus.DriveMounted
4286: && !BootEncStatus.VolumeHeaderPresent
4287: && !SysEncryptionOrDecryptionRequired ())
4288: {
4289: Warning ("SYS_DRIVE_NOT_ENCRYPTED");
4290: return;
4291: }
1.1 root 4292:
1.1.1.13 root 4293: if (SysEncryptionOrDecryptionRequired ()
4294: || BootEncStatus.SetupInProgress)
1.1 root 4295: {
1.1.1.13 root 4296: Warning ("SYSTEM_ENCRYPTION_NOT_COMPLETED");
4297: return;
4298: }
1.1.1.7 root 4299:
1.1.1.13 root 4300: if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption
4301: {
4302: try
1.1.1.7 root 4303: {
1.1.1.13 root 4304: if (AskOkCancel ("RESCUE_DISK_NON_WIZARD_CHECK_INSERT") != IDOK)
1.1.1.19 root 4305: {
4306: CloseSysEncMutex ();
1.1.1.13 root 4307: return;
1.1.1.19 root 4308: }
1.1.1.7 root 4309:
1.1.1.13 root 4310: // Create a temporary up-to-date rescue disk image in RAM (with it the CD/DVD content will be compared)
4311: BootEncObj->CreateRescueIsoImage (false, "");
1.1.1.7 root 4312:
1.1.1.13 root 4313: WaitCursor();
4314: if (!BootEncObj->VerifyRescueDisk ())
4315: Error ("RESCUE_DISK_NON_WIZARD_CHECK_FAILED");
4316: else
4317: Info ("RESCUE_DISK_NON_WIZARD_CHECK_PASSED");
1.1.1.7 root 4318: }
1.1.1.13 root 4319: catch (Exception &e)
4320: {
4321: e.Show (MainDlg);
4322: Error ("RESCUE_DISK_NON_WIZARD_CHECK_FAILED");
4323: }
4324: CloseSysEncMutex ();
4325:
4326: NormalCursor ();
4327: }
4328: else
4329: Warning ("SYSTEM_ENCRYPTION_IN_PROGRESS_ELSEWHERE");
4330: }
4331:
4332: static void ShowSystemEncryptionStatus (void)
4333: {
4334: try
4335: {
4336: BootEncStatus = BootEncObj->GetStatus();
4337: }
4338: catch (Exception &e)
4339: {
4340: e.Show (MainDlg);
4341: }
4342:
4343: if (GetAsyncKeyState (VK_SHIFT) < 0 && GetAsyncKeyState (VK_CONTROL) < 0)
4344: {
4345: // Ctrl+Shift held (for debugging purposes)
4346:
1.1.1.14 root 4347: DebugMsgBox ("Debugging information for system encryption:\n\nDeviceFilterActive: %d\nBootLoaderVersion: %x\nSetupInProgress: %d\nSetupMode: %d\nVolumeHeaderPresent: %d\nDriveMounted: %d\nDriveEncrypted: %d\n"
1.1.1.17 root 4348: "HiddenSystem: %d\nHiddenSystemPartitionStart: %I64d\n"
1.1.1.14 root 4349: "ConfiguredEncryptedAreaStart: %I64d\nConfiguredEncryptedAreaEnd: %I64d\nEncryptedAreaStart: %I64d\nEncryptedAreaEnd: %I64d\nEncrypted: %I64d%%",
1.1.1.13 root 4350: BootEncStatus.DeviceFilterActive,
4351: BootEncStatus.BootLoaderVersion,
4352: BootEncStatus.SetupInProgress,
4353: BootEncStatus.SetupMode,
4354: BootEncStatus.VolumeHeaderPresent,
4355: BootEncStatus.DriveMounted,
4356: BootEncStatus.DriveEncrypted,
1.1.1.17 root 4357: BootEncStatus.HiddenSystem ? 1 : 0,
4358: BootEncStatus.HiddenSystemPartitionStart,
1.1.1.13 root 4359: BootEncStatus.ConfiguredEncryptedAreaStart,
4360: BootEncStatus.ConfiguredEncryptedAreaEnd,
4361: BootEncStatus.EncryptedAreaStart,
4362: BootEncStatus.EncryptedAreaEnd,
4363: !BootEncStatus.DriveEncrypted ? 0 : (BootEncStatus.EncryptedAreaEnd + 1 - BootEncStatus.EncryptedAreaStart) * 100I64 / (BootEncStatus.ConfiguredEncryptedAreaEnd + 1 - BootEncStatus.ConfiguredEncryptedAreaStart));
1.1 root 4364: }
1.1.1.13 root 4365:
4366: if (!BootEncStatus.DriveEncrypted && !BootEncStatus.DriveMounted)
4367: {
4368: Info ("SYS_DRIVE_NOT_ENCRYPTED");
4369: return;
4370: }
4371:
4372: DialogBoxParamW (hInst,
4373: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), MainDlg,
4374: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) TRUE);
4375:
1.1 root 4376: }
4377:
1.1.1.19 root 4378: static void ResumeInterruptedNonSysInplaceEncProcess (void)
1.1 root 4379: {
1.1.1.19 root 4380: // IMPORTANT: This function must not check any config files! Otherwise, if a config file was lost or corrupt,
4381: // the user would not be able resume encryption and the data on the volume would be inaccessible.
4382:
4383: LaunchVolCreationWizard (MainDlg, "/zinplace");
4384: }
4385:
4386: static BOOL SelectContainer (HWND hwndDlg)
4387: {
4388: if (BrowseFiles (hwndDlg, "OPEN_VOL_TITLE", szFileName, bHistory, FALSE, NULL) == FALSE)
4389: return FALSE;
1.1 root 4390:
1.1.1.10 root 4391: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1 root 4392: EnableDisableButtons (hwndDlg);
1.1.1.6 root 4393: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1.1.19 root 4394: return TRUE;
1.1 root 4395: }
4396:
1.1.1.19 root 4397: static BOOL SelectPartition (HWND hwndDlg)
1.1 root 4398: {
1.1.1.7 root 4399: int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
1.1 root 4400: (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
4401: if (nResult == IDOK)
4402: {
1.1.1.10 root 4403: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1 root 4404: EnableDisableButtons (hwndDlg);
1.1.1.6 root 4405: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1.1.19 root 4406: return TRUE;
1.1 root 4407: }
1.1.1.19 root 4408:
4409: return FALSE;
1.1 root 4410: }
4411:
1.1.1.21 root 4412: static void WipeCache (HWND hwndDlg, BOOL silent)
1.1 root 4413: {
4414: DWORD dwResult;
4415: BOOL bResult;
4416:
1.1.1.13 root 4417: bResult = DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.11 root 4418: if (hwndDlg == NULL)
4419: return;
1.1 root 4420:
4421: if (bResult == FALSE)
4422: handleWin32Error (hwndDlg);
4423: else
4424: {
4425: EnableDisableButtons (hwndDlg);
4426:
1.1.1.21 root 4427: if (!silent)
4428: Info ("PASSWORD_CACHE_WIPED");
1.1 root 4429: }
4430: }
4431:
1.1.1.5 root 4432: static void Benchmark (HWND hwndDlg)
4433: {
1.1.1.7 root 4434: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_BENCHMARK_DLG), hwndDlg,
1.1.1.5 root 4435: (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
4436: }
1.1 root 4437:
1.1.1.7 root 4438:
4439: static BOOL CheckMountList ()
1.1 root 4440: {
1.1.1.7 root 4441: MOUNT_LIST_STRUCT current;
4442: GetMountList (¤t);
1.1.1.13 root 4443: static BootEncryptionStatus newBootEncStatus;
1.1 root 4444:
1.1.1.7 root 4445: if (LastKnownLogicalDrives != GetLogicalDrives()
4446: || memcmp (&LastKnownMountList, ¤t, sizeof (current)) != 0)
1.1 root 4447: {
1.1.1.23 root 4448: char selDrive;
1.1 root 4449:
1.1.1.11 root 4450: WaitCursor ();
1.1.1.13 root 4451: LastKnownMountList = current;
4452:
1.1.1.23 root 4453: selDrive = (char) HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
1.1.1.7 root 4454: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.13 root 4455: NormalCursor ();
4456:
4457: if ((current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
4458: {
4459: nSelectedDriveIndex = -1;
4460: return FALSE;
4461: }
1.1.1.2 root 4462:
1.1.1.7 root 4463: if (nSelectedDriveIndex >= 0)
4464: {
1.1.1.13 root 4465: SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
4466:
1.1.1.25! root 4467: //if(nSelectedDriveIndex > SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
! 4468: // SendMessage(GetDlgItem (MainDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 10000);
1.1.1.7 root 4469: }
1.1.1.13 root 4470: }
1.1 root 4471:
1.1.1.13 root 4472: try
4473: {
4474: newBootEncStatus = BootEncObj->GetStatus();
4475:
4476: if (newBootEncStatus.SetupInProgress != RecentBootEncStatus.SetupInProgress
4477: || newBootEncStatus.EncryptedAreaEnd != RecentBootEncStatus.EncryptedAreaEnd
4478: || newBootEncStatus.DriveEncrypted != RecentBootEncStatus.DriveEncrypted
4479: || newBootEncStatus.DriveMounted != RecentBootEncStatus.DriveMounted
4480: || newBootEncStatus.SetupMode != RecentBootEncStatus.SetupMode
4481: || newBootEncStatus.EncryptedAreaStart != RecentBootEncStatus.EncryptedAreaStart)
4482: {
4483: /* System encryption status change */
4484:
1.1.1.23 root 4485: char selDrive;
1.1.1.13 root 4486: int driveLetterToRefresh;
4487:
4488: if (RecentBootEncStatus.DriveMounted == newBootEncStatus.DriveMounted) // If an icon (and whole new line) for a system device isn't to be added/removed
4489: {
4490: // Partial refresh
4491: if (WholeSysDriveEncryption (TRUE))
4492: {
4493: // System drive (not just partition)
4494: driveLetterToRefresh = ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER;
4495: }
4496: else
4497: {
4498: // System partition
4499: driveLetterToRefresh = GetSystemDriveLetter ();
4500: }
4501: }
4502: else
4503: {
4504: // Full rebuild of the mount list
4505: driveLetterToRefresh = 0;
4506: }
4507:
1.1.1.23 root 4508: selDrive = (char) HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
1.1.1.13 root 4509: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), driveLetterToRefresh);
4510:
1.1.1.23 root 4511: RecentBootEncStatus = newBootEncStatus;
1.1.1.13 root 4512:
4513: if ((current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
4514: {
4515: nSelectedDriveIndex = -1;
4516: }
4517:
4518: if (nSelectedDriveIndex >= 0)
4519: {
4520: SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
4521: }
4522: }
4523:
1.1.1.17 root 4524: /* Miscellaneous notifications */
4525:
1.1.1.13 root 4526: // Hibernation prevention notifications
4527: if (newBootEncStatus.HibernationPreventionCount != RecentBootEncStatus.HibernationPreventionCount
4528: && !bHibernationPreventionNotified)
4529: {
4530: bHibernationPreventionNotified = TRUE;
4531: RecentBootEncStatus.HibernationPreventionCount = newBootEncStatus.HibernationPreventionCount;
1.1.1.23 root 4532:
4533: if (IsHiddenOSRunning() && BootEncObj->GetSystemDriveConfiguration().ExtraBootPartitionPresent)
4534: WarningTopMost ("HIDDEN_OS_HIBERNATION_PREVENTED");
4535: else
4536: WarningTopMost ("SYS_ENC_HIBERNATION_PREVENTED");
1.1.1.13 root 4537: }
1.1.1.17 root 4538:
4539: // Write mode prevention (hidden OS leak protection)
4540: if (IsHiddenOSRunning())
4541: {
4542: if (newBootEncStatus.HiddenSysLeakProtectionCount != RecentBootEncStatus.HiddenSysLeakProtectionCount
4543: && !bHiddenSysLeakProtNotifiedDuringSession)
4544: {
4545: bHiddenSysLeakProtNotifiedDuringSession = TRUE;
4546:
4547: switch (HiddenSysLeakProtectionNotificationStatus)
4548: {
4549: case TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT:
4550: {
4551: char *tmp[] = {0, "HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO", "SHOW_MORE_INFORMATION", "DO_NOT_SHOW_THIS_AGAIN", "CONTINUE", 0};
1.1.1.19 root 4552: switch (AskMultiChoice ((void **) tmp, FALSE))
1.1.1.17 root 4553: {
4554: case 1:
4555: InfoDirect ((wstring (GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO"))
4556: + L"\n\n"
4557: + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")
4558: + L"\n\n\n"
4559: + GetString ("DECOY_TO_HIDDEN_OS_DATA_TRANSFER_HOWTO")).c_str());
4560: break;
4561:
4562: case 2:
4563: // No more warnings will be shown
4564: if (ConfigBuffer == NULL)
4565: {
4566: // We need to load the config file because it is not done automatically when
4567: // launched from the sys startup sequence (and SaveSettings would start by _loading_
4568: // the settings to cache).
4569: LoadSettings (MainDlg);
4570: }
4571: HiddenSysLeakProtectionNotificationStatus = TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED;
4572: SaveSettings (MainDlg);
4573: break;
4574:
4575: default:
4576: // NOP
4577: break;
4578: }
4579: }
4580: break;
4581:
4582: case TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED:
4583: // NOP
4584: break;
4585:
4586: case TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE:
4587: default:
4588: {
4589: // First time warning -- include technical explanation
4590: InfoDirect ((wstring (GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO"))
4591: + L"\n\n"
4592: + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")
4593: + L"\n\n\n"
4594: + GetString ("DECOY_TO_HIDDEN_OS_DATA_TRANSFER_HOWTO")).c_str());
4595:
4596: // Further warnings will not include the explanation (and will allow disabling)
4597:
4598: if (ConfigBuffer == NULL)
4599: {
4600: // We need to load the config file because it is not done automatically when
4601: // launched from the sys startup sequence (and SaveSettings would start by _loading_
4602: // the settings to cache).
4603: LoadSettings (MainDlg);
4604: }
4605: HiddenSysLeakProtectionNotificationStatus = TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT;
4606: SaveSettings (MainDlg);
4607: }
4608: break;
4609: }
4610: }
4611: }
1.1.1.13 root 4612: }
4613: catch (...)
4614: {
4615: // NOP
1.1.1.7 root 4616: }
1.1 root 4617:
1.1.1.7 root 4618: return TRUE;
4619: }
1.1.1.6 root 4620:
1.1 root 4621:
1.1.1.13 root 4622: /* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
1.1.1.11 root 4623: should return nonzero if it processes a message, and zero if it does not. */
1.1.1.13 root 4624: BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1.1.1.7 root 4625: {
1.1.1.11 root 4626: static UINT taskBarCreatedMsg;
1.1.1.7 root 4627: WORD lw = LOWORD (wParam);
4628: WORD hw = HIWORD (wParam);
4629: DWORD mPos;
1.1 root 4630:
1.1.1.7 root 4631: switch (uMsg)
4632: {
4633: case WM_HOTKEY:
1.1 root 4634:
1.1.1.7 root 4635: HandleHotKey (hwndDlg, wParam);
4636: return 1;
1.1 root 4637:
1.1.1.7 root 4638: case WM_INITDIALOG:
4639: {
4640: int exitCode = 0;
1.1.1.13 root 4641: int modeOfOperation;
4642:
1.1.1.7 root 4643: MainDlg = hwndDlg;
1.1 root 4644:
1.1.1.17 root 4645: if (IsTrueCryptInstallerRunning())
4646: AbortProcess ("TC_INSTALLER_IS_RUNNING");
4647:
1.1.1.7 root 4648: // Set critical default options in case UsePreferences is false
4649: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE;
1.1 root 4650:
1.1.1.17 root 4651: ResetWrongPwdRetryCount ();
4652:
1.1.1.7 root 4653: ExtractCommandLine (hwndDlg, (char *) lParam);
4654:
1.1.1.11 root 4655: if (ComServerMode)
4656: {
1.1.1.19 root 4657: InitDialog (hwndDlg);
4658:
1.1.1.11 root 4659: if (!ComServerMain ())
4660: {
4661: handleWin32Error (hwndDlg);
4662: exit (1);
4663: }
4664: exit (0);
4665: }
4666:
1.1.1.13 root 4667: try
4668: {
4669: BootEncStatus = BootEncObj->GetStatus();
1.1.1.23 root 4670: RecentBootEncStatus = BootEncStatus;
1.1.1.13 root 4671: }
4672: catch (...)
4673: {
4674: // NOP
4675: }
4676:
1.1.1.7 root 4677: if (UsePreferences)
1.1 root 4678: {
1.1.1.7 root 4679: // General preferences
4680: LoadSettings (hwndDlg);
4681:
4682: // Keyfiles
4683: LoadDefaultKeyFilesParam ();
4684: RestoreDefaultKeyFilesParam ();
1.1 root 4685: }
4686:
1.1.1.23 root 4687: if (CmdMountOptionsValid)
4688: mountOptions = CmdMountOptions;
4689:
1.1.1.7 root 4690: InitMainDialog (hwndDlg);
4691:
1.1.1.25! root 4692: try
1.1.1.17 root 4693: {
1.1.1.25! root 4694: if (IsHiddenOSRunning())
1.1.1.17 root 4695: {
4696: if (BootEncObj->GetInstalledBootLoaderVersion() > VERSION_NUM)
1.1.1.21 root 4697: Warning ("UPDATE_TC_IN_HIDDEN_OS_TOO");
1.1.1.17 root 4698: }
1.1.1.25! root 4699: else if (SysDriveOrPartitionFullyEncrypted (TRUE)
! 4700: && BootEncObj->GetInstalledBootLoaderVersion() != VERSION_NUM)
! 4701: {
! 4702: Warning ("BOOT_LOADER_VERSION_DIFFERENT_FROM_DRIVER_VERSION");
! 4703: }
! 4704: }
! 4705: catch (...) { }
1.1.1.17 root 4706:
1.1.1.2 root 4707: // Automount
1.1.1.7 root 4708: if (bAuto || (Quit && szFileName[0] != 0))
1.1 root 4709: {
1.1.1.5 root 4710: // No drive letter specified on command line
4711: if (commandLineDrive == 0)
1.1.1.23 root 4712: szDriveLetter[0] = (char) GetFirstAvailableDrive () + 'A';
1.1.1.5 root 4713:
1.1.1.6 root 4714: if (bAutoMountDevices)
4715: {
4716: defaultMountOptions = mountOptions;
1.1.1.8 root 4717: if (FirstCmdKeyFile)
4718: {
4719: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
4720: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4721: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4722: }
4723:
1.1.1.23 root 4724: if (!MountAllDevices (hwndDlg, !Silent && !CmdVolumePasswordValid && IsPasswordCacheEmpty()))
1.1.1.7 root 4725: exitCode = 1;
4726: }
4727:
4728: if (bAutoMountFavorites)
4729: {
4730: defaultMountOptions = mountOptions;
1.1.1.8 root 4731: if (FirstCmdKeyFile)
4732: {
4733: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
4734: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4735: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4736: }
4737:
1.1.1.25! root 4738: if (!MountFavoriteVolumes (FALSE, LogOn))
1.1.1.7 root 4739: exitCode = 1;
1.1.1.6 root 4740: }
1.1.1.7 root 4741:
4742: if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
1.1.1.2 root 4743: {
4744: BOOL mounted;
4745:
4746: // Cached password
1.1.1.7 root 4747: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1.1.2 root 4748:
1.1.1.7 root 4749: // Command line password or keyfiles
4750: if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
1.1.1.2 root 4751: {
1.1.1.7 root 4752: BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
4753:
4754: if (FirstCmdKeyFile)
1.1.1.12 root 4755: KeyFilesApply (&CmdVolumePassword, FirstCmdKeyFile);
1.1.1.7 root 4756:
4757: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
4758: szFileName, &CmdVolumePassword, bCacheInDriver, bForceMount,
4759: &mountOptions, Silent, reportBadPasswd);
4760:
4761: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
4762: }
4763:
4764: if (FirstCmdKeyFile)
4765: {
4766: FirstKeyFile = FirstCmdKeyFile;
4767: KeyFilesEnable = TRUE;
1.1.1.2 root 4768: }
4769:
4770: // Ask user for password
1.1.1.7 root 4771: while (!mounted && !Silent)
1.1.1.2 root 4772: {
1.1.1.7 root 4773: VolumePassword.Length = 0;
1.1.1.2 root 4774:
1.1.1.7 root 4775: strcpy (PasswordDlgVolume, szFileName);
1.1.1.17 root 4776: if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
1.1.1.2 root 4777: break;
4778:
1.1.1.11 root 4779: WaitCursor ();
1.1.1.7 root 4780:
4781: if (KeyFilesEnable && FirstKeyFile)
1.1.1.12 root 4782: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 4783:
4784: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
4785:
4786: burn (&VolumePassword, sizeof (VolumePassword));
4787: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
4788:
1.1.1.2 root 4789: NormalCursor ();
4790: }
4791:
1.1.1.7 root 4792: if (UsePreferences)
1.1.1.11 root 4793: {
1.1.1.7 root 4794: RestoreDefaultKeyFilesParam ();
1.1.1.11 root 4795: bCacheInDriver = bCacheInDriverDefault;
4796: }
1.1.1.7 root 4797:
1.1.1.5 root 4798: if (mounted > 0)
1.1.1.2 root 4799: {
1.1.1.11 root 4800: if (bBeep)
1.1.1.23 root 4801: MessageBeep (0xFFFFFFFF);
1.1.1.11 root 4802:
4803: if (bExplore)
4804: OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
4805:
1.1.1.7 root 4806: RefreshMainDlg(hwndDlg);
1.1.1.11 root 4807:
4808: if(!Silent)
4809: {
1.1.1.13 root 4810: // Check for deprecated CBC mode
4811: modeOfOperation = GetModeOfOperationByDriveNo (szDriveLetter[0] - 'A');
4812: if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
4813: Warning("WARN_CBC_MODE");
4814:
4815: // Check for deprecated 64-bit-block ciphers
1.1.1.11 root 4816: if (GetCipherBlockSizeByDriveNo (szDriveLetter[0] - 'A') == 64)
4817: Warning("WARN_64_BIT_BLOCK_CIPHER");
4818:
4819: // Check for problematic file extensions (exe, dll, sys)
4820: if (CheckFileExtension (szFileName))
4821: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
4822: }
1.1.1.2 root 4823: }
1.1.1.7 root 4824: else
4825: exitCode = 1;
1.1.1.2 root 4826: }
1.1.1.12 root 4827: else if (bExplore && GetMountedVolumeDriveNo (szFileName) != -1)
4828: OpenVolumeExplorerWindow (GetMountedVolumeDriveNo (szFileName));
1.1.1.10 root 4829: else if (szFileName[0] != 0 && IsMountedVolume (szFileName))
1.1.1.11 root 4830: Warning ("VOL_ALREADY_MOUNTED");
1.1.1.10 root 4831:
1.1.1.8 root 4832: if (!Quit)
4833: RefreshMainDlg(hwndDlg);
1.1.1.7 root 4834: }
1.1.1.23 root 4835:
4836: // Wipe cache
4837: if (bWipe)
4838: WipeCache (hwndDlg, Silent);
1.1.1.7 root 4839:
4840: // Wipe command line password
4841: if (CmdVolumePassword.Length != 0)
4842: {
4843: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
4844: CmdVolumePassword.Length = 0;
1.1 root 4845: }
4846:
1.1.1.7 root 4847: // Wipe command line keyfiles
4848: if (FirstCmdKeyFile)
1.1.1.8 root 4849: {
4850: if (defaultKeyFilesParam.FirstKeyFile)
4851: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
4852:
4853: defaultKeyFilesParam.EnableKeyFiles = FALSE;
4854:
1.1.1.10 root 4855: if (!Quit)
4856: {
4857: LoadSettings (hwndDlg);
4858: LoadDefaultKeyFilesParam ();
4859: RestoreDefaultKeyFilesParam ();
4860: }
1.1.1.8 root 4861: }
1.1.1.7 root 4862:
4863: // Dismount
1.1.1.5 root 4864: if (cmdUnmountDrive > 0)
1.1.1.7 root 4865: {
4866: if (!Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A'))
4867: exitCode = 1;
4868: }
1.1.1.5 root 4869: else if (cmdUnmountDrive == -1)
1.1.1.7 root 4870: {
4871: if (!DismountAll (hwndDlg, bForceUnmount, !Silent, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY))
4872: exitCode = 1;
4873: }
1.1.1.5 root 4874:
1.1.1.7 root 4875: // TaskBar icon
4876: if (bEnableBkgTask)
4877: TaskBarIconAdd (hwndDlg);
1.1.1.11 root 4878:
1.1.1.7 root 4879: // Quit
1.1.1.12 root 4880: if (Quit)
4881: {
4882: if (TaskBarIconMutex == NULL)
4883: exit (exitCode);
4884:
4885: MainWindowHidden = TRUE;
4886:
4887: LoadSettings (hwndDlg);
4888: LoadDefaultKeyFilesParam ();
4889: RestoreDefaultKeyFilesParam ();
4890:
4891: if (!bEnableBkgTask)
4892: {
4893: if (TaskBarIconMutex)
4894: TaskBarIconRemove (hwndDlg);
4895: exit (exitCode);
4896: }
4897: }
1.1.1.7 root 4898:
1.1.1.8 root 4899: // No command line arguments or only /volume => bring active instance
4900: // to foreground if available
4901: if (NoCmdLineArgs == 0 || (CmdLineVolumeSpecified && NoCmdLineArgs <= 2))
4902: {
4903: HWND h = hwndDlg;
4904: EnumWindows (FindTCWindowEnum, (LPARAM) &h);
4905:
1.1.1.23 root 4906: if (h != hwndDlg
4907: && (!IsAdmin() || (GetWindowLongPtr (h, DWLP_USER) & TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES) != 0))
1.1.1.8 root 4908: {
4909: if (CmdLineVolumeSpecified)
4910: {
4911: COPYDATASTRUCT cd;
4912: memcpy (&cd.dwData, WM_COPY_SET_VOLUME_NAME, 4);
4913: cd.lpData = szFileName;
4914: cd.cbData = strlen (szFileName) + 1;
4915:
4916: SendMessage (h, WM_COPYDATA, (WPARAM)hwndDlg, (LPARAM)&cd);
4917: }
4918:
1.1.1.13 root 4919: SendMessage (h, TC_APPMSG_MOUNT_SHOW_WINDOW, 0, 0);
1.1.1.8 root 4920:
4921: ShowWindow (h, SW_SHOW);
4922: SetForegroundWindow (h);
1.1.1.12 root 4923:
4924: if (TaskBarIconMutex == NULL)
4925: exit (0);
1.1.1.8 root 4926: }
4927: }
4928:
1.1.1.25! root 4929: HookMouseWheel (hwndDlg, IDC_VOLUME);
! 4930:
1.1.1.12 root 4931: // Register hot keys
4932: if (!RegisterAllHotkeys (hwndDlg, Hotkeys)
4933: && TaskBarIconMutex != NULL) // Warn only if we are the first instance of TrueCrypt
4934: Warning("HOTKEY_REGISTRATION_ERROR");
4935:
1.1.1.7 root 4936: Silent = FALSE;
4937:
4938: GetMountList (&LastKnownMountList);
1.1.1.13 root 4939: SetTimer (hwndDlg, TIMER_ID_MAIN, TIMER_INTERVAL_MAIN, NULL);
1.1.1.3 root 4940:
1.1.1.11 root 4941: taskBarCreatedMsg = RegisterWindowMessage ("TaskbarCreated");
4942:
1.1 root 4943: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1.1.13 root 4944:
4945: /* Check system encryption status */
4946:
1.1.1.19 root 4947: if (!Quit) // Do not care about system encryption or in-place encryption if we were launched from the system startup sequence (the wizard was added to it too).
1.1.1.13 root 4948: {
4949: if (SysEncryptionOrDecryptionRequired ())
4950: {
1.1.1.17 root 4951: if (!MutexExistsOnSystem (TC_MUTEX_NAME_SYSENC)) // If no instance of the wizard is currently taking care of system encryption
1.1.1.13 root 4952: {
1.1.1.17 root 4953: // We shouldn't block the mutex at this point
1.1.1.13 root 4954:
4955: if (SystemEncryptionStatus == SYSENC_STATUS_PRETEST
4956: || AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
4957: {
4958: // The wizard was not launched during the system startup seq, or the user may have forgotten
4959: // to resume the encryption/decryption process.
4960:
4961:
4962: LaunchVolCreationWizard (hwndDlg, "/csysenc");
4963: }
4964: }
4965: }
1.1.1.19 root 4966:
4967: if (bInPlaceEncNonSysPending && !NonSysInplaceEncInProgressElsewhere())
4968: {
1.1.1.21 root 4969: if (AskNonSysInPlaceEncryptionResume() == IDYES)
1.1.1.19 root 4970: ResumeInterruptedNonSysInplaceEncProcess ();
4971: }
1.1.1.13 root 4972: }
1.1.1.17 root 4973:
1.1.1.25! root 4974: if (!DisableSystemCrashDetection
! 4975: && IsOSAtLeast (WIN_7))
! 4976: {
! 4977: // Auto-detect a system crash
! 4978:
! 4979: const int detectionPeriodInMonthsSinceReleaseDate = 1;
! 4980: int maxYear = TC_RELEASE_DATE_YEAR;
! 4981: int maxMonth = TC_RELEASE_DATE_MONTH + detectionPeriodInMonthsSinceReleaseDate;
! 4982: if (maxMonth > 12)
! 4983: {
! 4984: ++maxYear;
! 4985: maxMonth -= 12;
! 4986: }
! 4987:
! 4988: SYSTEMTIME systemTime;
! 4989: GetSystemTime (&systemTime);
! 4990:
! 4991: if (systemTime.wYear >= TC_RELEASE_DATE_YEAR
! 4992: && !(systemTime.wYear == TC_RELEASE_DATE_YEAR && systemTime.wMonth < TC_RELEASE_DATE_MONTH)
! 4993: && systemTime.wYear <= maxYear
! 4994: && !(systemTime.wYear == maxYear && systemTime.wMonth > maxMonth))
! 4995: {
! 4996: char winDir[MAX_PATH] = { 0 };
! 4997: GetWindowsDirectory (winDir, sizeof (winDir));
! 4998:
! 4999: WIN32_FIND_DATA findData;
! 5000: HANDLE find = FindFirstFile ((string (winDir) + "\\MEMORY.DMP").c_str(), &findData);
! 5001:
! 5002: if (find != INVALID_HANDLE_VALUE)
! 5003: {
! 5004: SYSTEMTIME systemTime;
! 5005: FILETIME ft;
! 5006: GetSystemTime (&systemTime);
! 5007: SystemTimeToFileTime (&systemTime, &ft);
! 5008:
! 5009: ULARGE_INTEGER sysTime, fileTime;
! 5010: sysTime.HighPart = ft.dwHighDateTime;
! 5011: sysTime.LowPart = ft.dwLowDateTime;
! 5012: fileTime.HighPart = findData.ftLastWriteTime.dwHighDateTime;
! 5013: fileTime.LowPart = findData.ftLastWriteTime.dwLowDateTime;
! 5014:
! 5015: // Memory dump must not be older than 10 minutes
! 5016: if (sysTime.QuadPart - fileTime.QuadPart < 10I64 * 1000 * 1000 * 60 * 10)
! 5017: SystemCrashDetected = TRUE;
! 5018:
! 5019: FindClose (find);
! 5020: }
! 5021: }
! 5022: }
! 5023:
1.1.1.17 root 5024: DoPostInstallTasks ();
1.1.1.23 root 5025: ResetCurrentDirectory ();
1.1 root 5026: }
5027: return 0;
1.1.1.25! root 5028:
! 5029: case WM_MOUSEWHEEL:
! 5030: return HandleDriveListMouseWheelEvent (uMsg, wParam, lParam, FALSE);
1.1 root 5031:
1.1.1.7 root 5032: case WM_WINDOWPOSCHANGING:
5033: if (MainWindowHidden)
5034: {
1.1.1.13 root 5035: // Prevent window from being shown
1.1.1.7 root 5036: PWINDOWPOS wp = (PWINDOWPOS)lParam;
5037: wp->flags &= ~SWP_SHOWWINDOW;
5038: return 0;
5039: }
5040: return 1;
5041:
1.1 root 5042: case WM_SYSCOMMAND:
5043: if (lw == IDC_ABOUT)
5044: {
1.1.1.7 root 5045: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 5046: return 1;
5047: }
5048: return 0;
5049:
5050: case WM_HELP:
1.1.1.7 root 5051: OpenPageHelp (hwndDlg, 0);
1.1 root 5052: return 1;
5053:
1.1.1.7 root 5054: case WM_ENDSESSION:
5055: if (TaskBarIconMutex != NULL)
1.1 root 5056: {
1.1.1.7 root 5057: if (bDismountOnLogOff)
5058: {
5059: // Auto-dismount when user logs off
5060: DWORD dwResult;
5061:
5062: if (bWipeCacheOnAutoDismount)
1.1.1.13 root 5063: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 5064:
1.1.1.23 root 5065: DismountAll (hwndDlg, bForceAutoDismount, FALSE, 1, 0);
1.1.1.7 root 5066: }
5067:
5068: TaskBarIconRemove (hwndDlg);
5069: }
1.1.1.13 root 5070: EndMainDlg (hwndDlg);
5071: localcleanup ();
1.1.1.7 root 5072: return 0;
5073:
5074: case WM_POWERBROADCAST:
5075: if (wParam == PBT_APMSUSPEND
5076: && TaskBarIconMutex != NULL && bDismountOnPowerSaving)
5077: {
5078: // Auto-dismount when entering power-saving mode
5079: DWORD dwResult;
1.1.1.12 root 5080:
1.1.1.7 root 5081: if (bWipeCacheOnAutoDismount)
1.1.1.19 root 5082: {
1.1.1.13 root 5083: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 5084: SecurityToken::CloseAllSessions();
5085: }
1.1.1.12 root 5086:
1.1.1.23 root 5087: DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7 root 5088: }
5089: return 0;
5090:
5091: case WM_TIMER:
5092: {
5093: // Check mount list and update GUI if needed
5094: CheckMountList ();
5095:
5096: // Cache status
5097: if (IsPasswordCacheEmpty() == IsWindowEnabled (GetDlgItem (hwndDlg, IDC_WIPE_CACHE)))
5098: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
5099:
1.1.1.25! root 5100: // Check driver warning flags
! 5101: DWORD bytesOut;
! 5102: GetWarningFlagsRequest warnings;
! 5103: if (DeviceIoControl (hDriver, TC_IOCTL_GET_WARNING_FLAGS, NULL, 0, &warnings, sizeof (warnings), &bytesOut, NULL))
! 5104: {
! 5105: if (warnings.SystemFavoriteVolumeDirty)
! 5106: WarningTopMost ("SYS_FAVORITE_VOLUME_DIRTY");
! 5107:
! 5108: if (warnings.PagingFileCreationPrevented)
! 5109: WarningTopMost ("PAGING_FILE_CREATION_PREVENTED");
! 5110: }
! 5111:
1.1.1.7 root 5112: if (TaskBarIconMutex != NULL)
5113: {
1.1.1.25! root 5114: // Handle system crash
! 5115: static BOOL systemCrashHandlerLocked = FALSE;
! 5116: if (SystemCrashDetected && !systemCrashHandlerLocked)
! 5117: {
! 5118: systemCrashHandlerLocked = TRUE;
! 5119:
! 5120: SetForegroundWindow (hwndDlg);
! 5121: MainWindowHidden = FALSE;
! 5122: ShowWindow (hwndDlg, SW_SHOW);
! 5123: ShowWindow (hwndDlg, SW_RESTORE);
! 5124:
! 5125: if (AskYesNo ("SYSTEM_CRASHED_ASK_REPORT") == IDYES)
! 5126: {
! 5127: if (!IsAdmin() && IsUacSupported())
! 5128: UacAnalyzeKernelMiniDump (hwndDlg);
! 5129: else
! 5130: AnalyzeKernelMiniDump (hwndDlg);
! 5131: }
! 5132: else if (AskYesNo ("ASK_KEEP_DETECTING_SYSTEM_CRASH") == IDNO)
! 5133: {
! 5134: DisableSystemCrashDetection = TRUE;
! 5135: SaveSettings (hwndDlg);
! 5136: }
! 5137: }
! 5138:
1.1.1.7 root 5139: // Idle auto-dismount
5140: if (MaxVolumeIdleTime > 0)
5141: DismountIdleVolumes ();
5142:
5143: // Screen saver auto-dismount
5144: if (bDismountOnScreenSaver)
5145: {
5146: static BOOL previousState = FALSE;
5147: BOOL running = FALSE;
5148: SystemParametersInfo (SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
5149:
5150: if (running && !previousState)
5151: {
5152: DWORD dwResult;
5153: previousState = TRUE;
5154:
5155: if (bWipeCacheOnAutoDismount)
1.1.1.19 root 5156: {
1.1.1.13 root 5157: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 5158: SecurityToken::CloseAllSessions();
5159: }
1.1.1.12 root 5160:
5161: DismountAll (hwndDlg, bForceAutoDismount, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7 root 5162: }
5163: else
5164: {
5165: previousState = running;
1.1.1.8 root 5166: }
1.1.1.7 root 5167: }
1.1.1.25! root 5168:
! 5169: // Auto-mount favorite volumes on arrival
! 5170: #if TIMER_INTERVAL_MAIN != 500
! 5171: #error TIMER_INTERVAL_MAIN != 500
! 5172: #endif
! 5173: static int favoritesAutoMountTimerDivisor = 0;
! 5174: if ((++favoritesAutoMountTimerDivisor & 1) && !FavoritesOnArrivalMountRequired.empty())
! 5175: {
! 5176: static bool reentry = false;
! 5177: if (reentry)
! 5178: break;
! 5179:
! 5180: reentry = true;
! 5181:
! 5182: foreach (FavoriteVolume favorite, FavoritesOnArrivalMountRequired)
! 5183: {
! 5184: if (!favorite.VolumePathId.empty())
! 5185: {
! 5186: if (IsMountedVolume (favorite.Path.c_str()))
! 5187: continue;
! 5188:
! 5189: char volDevPath[TC_MAX_PATH];
! 5190: if (QueryDosDevice (favorite.VolumePathId.substr (4, favorite.VolumePathId.size() - 5).c_str(), volDevPath, TC_MAX_PATH) == 0)
! 5191: continue;
! 5192:
! 5193: favorite.DisconnectedDevice = false;
! 5194: }
! 5195: else if (favorite.Path.find ("\\\\?\\Volume{") == 0)
! 5196: {
! 5197: string resolvedPath = VolumeGuidPathToDevicePath (favorite.Path);
! 5198: if (resolvedPath.empty())
! 5199: continue;
! 5200:
! 5201: favorite.DisconnectedDevice = false;
! 5202: favorite.VolumePathId = favorite.Path;
! 5203: favorite.Path = resolvedPath;
! 5204: }
! 5205:
! 5206: if (IsMountedVolume (favorite.Path.c_str()))
! 5207: continue;
! 5208:
! 5209: if (!IsVolumeDeviceHosted (favorite.Path.c_str()))
! 5210: {
! 5211: if (!FileExists (favorite.Path.c_str()))
! 5212: continue;
! 5213: }
! 5214: else if (favorite.VolumePathId.empty())
! 5215: continue;
! 5216:
! 5217: bool mountedAndNotDisconnected = false;
! 5218: foreach (FavoriteVolume mountedFavorite, FavoritesMountedOnArrivalStillConnected)
! 5219: {
! 5220: if (favorite.Path == mountedFavorite.Path)
! 5221: {
! 5222: mountedAndNotDisconnected = true;
! 5223: break;
! 5224: }
! 5225: }
! 5226:
! 5227: if (!mountedAndNotDisconnected)
! 5228: {
! 5229: FavoriteMountOnArrivalInProgress = TRUE;
! 5230: MountFavoriteVolumes (FALSE, FALSE, FALSE, favorite);
! 5231: FavoriteMountOnArrivalInProgress = FALSE;
! 5232:
! 5233: FavoritesMountedOnArrivalStillConnected.push_back (favorite);
! 5234: }
! 5235: }
! 5236:
! 5237: bool deleted;
! 5238: for (list <FavoriteVolume>::iterator favorite = FavoritesMountedOnArrivalStillConnected.begin();
! 5239: favorite != FavoritesMountedOnArrivalStillConnected.end();
! 5240: deleted ? favorite : ++favorite)
! 5241: {
! 5242: deleted = false;
! 5243:
! 5244: if (IsMountedVolume (favorite->Path.c_str()))
! 5245: continue;
! 5246:
! 5247: if (!IsVolumeDeviceHosted (favorite->Path.c_str()))
! 5248: {
! 5249: if (FileExists (favorite->Path.c_str()))
! 5250: continue;
! 5251: }
! 5252:
! 5253: char volDevPath[TC_MAX_PATH];
! 5254: if (favorite->VolumePathId.size() > 5
! 5255: && QueryDosDevice (favorite->VolumePathId.substr (4, favorite->VolumePathId.size() - 5).c_str(), volDevPath, TC_MAX_PATH) != 0)
! 5256: {
! 5257: continue;
! 5258: }
! 5259:
! 5260: favorite = FavoritesMountedOnArrivalStillConnected.erase (favorite);
! 5261: deleted = true;
! 5262: }
! 5263:
! 5264: reentry = false;
! 5265: }
1.1.1.7 root 5266: }
5267:
1.1.1.8 root 5268: // Exit background process in non-install mode or if no volume mounted
1.1.1.7 root 5269: // and no other instance active
5270: if (LastKnownMountList.ulMountedDrives == 0
1.1.1.13 root 5271: && MainWindowHidden
1.1.1.7 root 5272: #ifndef _DEBUG
5273: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
1.1.1.13 root 5274: && !SysEncDeviceActive (TRUE)
1.1.1.25! root 5275: #endif
1.1.1.7 root 5276: && GetDriverRefCount () < 2)
5277: {
5278: TaskBarIconRemove (hwndDlg);
5279: EndMainDlg (hwndDlg);
5280: }
1.1 root 5281: }
1.1.1.13 root 5282: return 1;
1.1 root 5283:
1.1.1.13 root 5284: case TC_APPMSG_TASKBAR_ICON:
1.1 root 5285: {
1.1.1.7 root 5286: switch (lParam)
5287: {
5288: case WM_LBUTTONDOWN:
1.1.1.8 root 5289: SetForegroundWindow (hwndDlg);
1.1.1.7 root 5290: MainWindowHidden = FALSE;
5291: ShowWindow (hwndDlg, SW_SHOW);
1.1.1.13 root 5292: ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.21 root 5293: return 1;
1.1.1.7 root 5294:
1.1.1.21 root 5295: case WM_RBUTTONUP:
1.1.1.7 root 5296: {
5297: POINT pos;
5298: HMENU popup = CreatePopupMenu ();
5299: int sel, i, n;
1.1.1.8 root 5300:
1.1.1.7 root 5301: if (MainWindowHidden)
5302: {
5303: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
5304: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5305: }
5306: else if (bEnableBkgTask
5307: && (!(LastKnownMountList.ulMountedDrives == 0
5308: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
1.1.1.13 root 5309: && !SysEncDeviceActive (TRUE)
1.1.1.7 root 5310: && GetDriverRefCount () < 2)))
5311: {
5312: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
5313: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5314: }
1.1.1.13 root 5315: AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL"));
1.1.1.7 root 5316: AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
5317: AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDM_UNMOUNTALL"));
5318: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5319:
5320: for (n = 0; n < 2; n++)
5321: {
5322: for (i = 0; i < 26; i++)
5323: {
5324: if (LastKnownMountList.ulMountedDrives & (1 << i))
5325: {
5326: wchar_t s[1024];
1.1.1.13 root 5327: wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[i];
1.1.1.7 root 5328:
5329: if (wcsstr (vol, L"\\??\\")) vol += 4;
5330:
1.1.1.25! root 5331: wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol));
! 5332:
1.1.1.7 root 5333: wsprintfW (s, L"%s %c: (%s)",
5334: GetString (n==0 ? "OPEN" : "DISMOUNT"),
5335: i + L'A',
1.1.1.25! root 5336: label.empty() ? vol : label.c_str());
1.1.1.13 root 5337: AppendMenuW (popup, MF_STRING, n*26 + TRAYICON_MENU_DRIVE_OFFSET + i, s);
1.1.1.7 root 5338: }
5339: }
5340: if (LastKnownMountList.ulMountedDrives != 0)
5341: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5342: }
5343:
5344: AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
1.1.1.11 root 5345: AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
1.1.1.7 root 5346: AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
5347: AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
5348: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.13 root 5349: AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT"));
1.1.1.7 root 5350:
5351: GetCursorPos (&pos);
5352:
5353: SetForegroundWindow(hwndDlg);
5354:
5355: sel = TrackPopupMenu (popup,
5356: TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
5357: pos.x,
5358: pos.y,
5359: 0,
5360: hwndDlg,
5361: NULL);
5362:
1.1.1.13 root 5363: if (sel >= TRAYICON_MENU_DRIVE_OFFSET && sel < TRAYICON_MENU_DRIVE_OFFSET + 26)
1.1.1.7 root 5364: {
1.1.1.13 root 5365: OpenVolumeExplorerWindow (sel - TRAYICON_MENU_DRIVE_OFFSET);
1.1.1.7 root 5366: }
1.1.1.13 root 5367: else if (sel >= TRAYICON_MENU_DRIVE_OFFSET + 26 && sel < TRAYICON_MENU_DRIVE_OFFSET + 26*2)
1.1.1.7 root 5368: {
5369: if (CheckMountList ())
1.1.1.13 root 5370: Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26);
1.1.1.7 root 5371: }
5372: else if (sel == IDM_SHOW_HIDE)
5373: {
1.1.1.13 root 5374: ChangeMainWindowVisibility ();
1.1.1.7 root 5375: }
1.1.1.11 root 5376: else if (sel == IDM_HOMEPAGE_SYSTRAY)
5377: {
5378: Applink ("home", TRUE, "");
5379: }
1.1.1.13 root 5380: else if (sel == IDCANCEL)
1.1.1.7 root 5381: {
1.1.1.13 root 5382: if ((LastKnownMountList.ulMountedDrives == 0
5383: && !SysEncDeviceActive (TRUE))
1.1.1.7 root 5384: || AskWarnNoYes ("CONFIRM_EXIT") == IDYES)
5385: {
5386: // Close all other TC windows
5387: EnumWindows (CloseTCWindowsEnum, 0);
5388:
5389: TaskBarIconRemove (hwndDlg);
5390: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
5391: }
5392: }
5393: else
5394: {
5395: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
5396: }
5397:
5398: PostMessage(hwndDlg, WM_NULL, 0, 0);
5399: DestroyMenu (popup);
5400: }
1.1.1.21 root 5401: return 1;
1.1 root 5402: }
1.1.1.7 root 5403: }
5404:
1.1.1.21 root 5405: return 0;
5406:
1.1.1.13 root 5407: case TC_APPMSG_CLOSE_BKG_TASK:
1.1.1.11 root 5408: if (TaskBarIconMutex != NULL)
5409: TaskBarIconRemove (hwndDlg);
5410:
5411: return 1;
5412:
1.1.1.13 root 5413: case TC_APPMSG_SYSENC_CONFIG_UPDATE:
5414: LoadSysEncSettings (hwndDlg);
5415:
1.1.1.16 root 5416: // The wizard added TrueCrypt.exe to the system startup sequence or performed other operations that
5417: // require us to update our cached settings.
1.1.1.13 root 5418: LoadSettings (hwndDlg);
5419:
5420: return 1;
5421:
1.1.1.11 root 5422: case WM_DEVICECHANGE:
1.1.1.12 root 5423: if (!IgnoreWmDeviceChange && wParam != DBT_DEVICEARRIVAL)
1.1.1.11 root 5424: {
5425: // Check if any host device has been removed and force dismount of volumes accordingly
5426: PDEV_BROADCAST_HDR hdr = (PDEV_BROADCAST_HDR) lParam;
1.1.1.12 root 5427: int m;
5428:
5429: GetMountList (&LastKnownMountList);
5430:
1.1.1.11 root 5431: if (wParam == DBT_DEVICEREMOVECOMPLETE && hdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
5432: {
1.1.1.12 root 5433: // File-hosted volumes
1.1.1.11 root 5434: PDEV_BROADCAST_VOLUME vol = (PDEV_BROADCAST_VOLUME) lParam;
1.1.1.12 root 5435: int i;
1.1.1.11 root 5436:
5437: for (i = 0; i < 26; i++)
5438: {
1.1.1.25! root 5439: if ((vol->dbcv_unitmask & (1 << i)) && !(GetLogicalDrives() & (1 << i)))
1.1.1.11 root 5440: {
5441: for (m = 0; m < 26; m++)
5442: {
5443: if (LastKnownMountList.ulMountedDrives & (1 << m))
5444: {
1.1.1.13 root 5445: wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.11 root 5446:
1.1.1.12 root 5447: if (wcsstr (vol, L"\\??\\") == vol)
1.1.1.11 root 5448: vol += 4;
5449:
1.1.1.12 root 5450: if (vol[1] == L':' && i == (vol[0] - (vol[0] <= L'Z' ? L'A' : L'a')))
1.1.1.11 root 5451: UnmountVolume (hwndDlg, m, TRUE);
5452: }
5453: }
5454: }
5455: }
1.1.1.12 root 5456: }
1.1.1.11 root 5457:
1.1.1.12 root 5458: // Device-hosted volumes
5459: for (m = 0; m < 26; m++)
5460: {
5461: if (LastKnownMountList.ulMountedDrives & (1 << m))
5462: {
1.1.1.13 root 5463: wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.12 root 5464: char volp[MAX_PATH];
5465:
5466: if (wcsstr (vol, L"\\??\\") == vol)
5467: vol += 4;
5468:
5469: _snprintf (volp, sizeof(volp), "%ls", vol);
5470:
5471: if (IsVolumeDeviceHosted (volp))
5472: {
5473: OPEN_TEST_STRUCT ots;
5474:
1.1.1.21 root 5475: if (!OpenDevice (volp, &ots, FALSE))
1.1.1.12 root 5476: UnmountVolume (hwndDlg, m, TRUE);
5477: }
5478: }
1.1.1.11 root 5479: }
1.1.1.25! root 5480:
! 5481: // Favorite volumes
! 5482: UpdateDeviceHostedFavoriteVolumes();
! 5483:
1.1.1.12 root 5484: return 1;
1.1.1.11 root 5485: }
1.1.1.12 root 5486: return 0;
1.1.1.11 root 5487:
1.1.1.7 root 5488: case WM_NOTIFY:
5489:
5490: if(wParam == IDC_DRIVELIST)
5491: {
1.1.1.23 root 5492: if (((LPNMHDR) lParam)->code == NM_CUSTOMDRAW)
5493: {
5494: int width = ListView_GetColumnWidth (GetDlgItem (hwndDlg, IDC_DRIVELIST), 1);
5495: if (width != LastDriveListVolumeColumnWidth)
5496: {
5497: LastDriveListVolumeColumnWidth = width;
5498: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
5499: }
5500: return 0;
5501: }
5502:
1.1.1.7 root 5503: /* Single click within drive list */
5504: if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
5505: {
5506: nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
5507: EnableDisableButtons (hwndDlg);
5508: return 1;
5509: }
5510:
5511: /* Double click within drive list */
5512: if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1.1 root 5513: {
1.1.1.13 root 5514: int state = GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
1.1.1.7 root 5515: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
1.1.1.13 root 5516: if (LOWORD(state) == TC_MLIST_ITEM_NONSYS_VOL || LOWORD(state) == TC_MLIST_ITEM_SYS_PARTITION)
1.1.1.7 root 5517: {
5518: // Open explorer window for mounted volume
1.1.1.11 root 5519: WaitCursor ();
1.1.1.7 root 5520: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
5521: NormalCursor ();
5522: }
1.1.1.13 root 5523: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
1.1.1.7 root 5524: {
1.1.1.11 root 5525: mountOptions = defaultMountOptions;
1.1.1.15 root 5526: bPrebootPasswordDlgMode = FALSE;
1.1.1.11 root 5527:
1.1.1.9 root 5528: if (GetAsyncKeyState (VK_CONTROL) < 0)
5529: {
5530: if (IDCANCEL == DialogBoxParamW (hInst,
5531: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
5532: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
5533: return 1;
5534:
5535: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12 root 5536: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.9 root 5537: }
5538:
1.1.1.7 root 5539: if (CheckMountList ())
5540: Mount (hwndDlg, 0, 0);
5541: }
5542: return 1;
5543: }
5544:
5545: /* Right click and drag&drop operations */
1.1.1.13 root 5546:
5547: switch (((NM_LISTVIEW *) lParam)->hdr.code)
1.1.1.7 root 5548: {
5549: case NM_RCLICK:
5550: case LVN_BEGINRDRAG:
5551: /* If the mouse was moving while the right mouse button is pressed, popup menu would
5552: not open, because drag&drop operation would be initiated. Therefore, we're handling
5553: RMB drag-and-drop operations as well. */
5554: {
5555:
5556: /* Drive list context menu */
5557:
5558: int menuItem;
5559: HMENU popup = CreatePopupMenu ();
5560:
5561: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
5562:
1.1.1.13 root 5563: switch (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))))
1.1.1.7 root 5564: {
1.1.1.13 root 5565: case TC_MLIST_ITEM_FREE:
5566:
1.1.1.7 root 5567: // No mounted volume at this drive letter
1.1.1.13 root 5568:
1.1.1.7 root 5569: AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
1.1.1.19 root 5570: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5571: AppendMenuW (popup, MF_STRING, IDPM_SELECT_FILE_AND_MOUNT, GetString ("SELECT_FILE_AND_MOUNT"));
5572: AppendMenuW (popup, MF_STRING, IDPM_SELECT_DEVICE_AND_MOUNT, GetString ("SELECT_DEVICE_AND_MOUNT"));
1.1.1.13 root 5573: break;
5574:
5575: case TC_MLIST_ITEM_NONSYS_VOL:
5576:
5577: // There's a mounted non-system volume at this drive letter
5578:
1.1.1.7 root 5579: AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
5580: AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
5581: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5582: AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
5583: AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
5584: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.25! root 5585: AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_FAVORITES, GetString ("IDPM_ADD_TO_FAVORITES"));
! 5586: AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_SYSTEM_FAVORITES, GetString ("IDPM_ADD_TO_SYSTEM_FAVORITES"));
! 5587: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.7 root 5588: AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
1.1.1.13 root 5589: break;
5590:
5591: case TC_MLIST_ITEM_SYS_PARTITION:
5592: case TC_MLIST_ITEM_SYS_DRIVE:
5593:
5594: // System partition/drive
5595:
5596: PopulateSysEncContextMenu (popup, FALSE);
5597: break;
1.1.1.7 root 5598: }
5599:
5600: mPos=GetMessagePos();
5601:
5602: menuItem = TrackPopupMenu (popup,
5603: TPM_RETURNCMD | TPM_LEFTBUTTON,
5604: GET_X_LPARAM(mPos),
5605: GET_Y_LPARAM(mPos),
5606: 0,
5607: hwndDlg,
5608: NULL);
5609:
5610: DestroyMenu (popup);
5611:
5612: switch (menuItem)
5613: {
1.1.1.19 root 5614: case IDPM_SELECT_FILE_AND_MOUNT:
5615: if (SelectContainer (hwndDlg))
5616: MountSelectedVolume (hwndDlg, FALSE);
5617: break;
5618:
5619: case IDPM_SELECT_DEVICE_AND_MOUNT:
5620: if (SelectPartition (hwndDlg))
5621: MountSelectedVolume (hwndDlg, FALSE);
5622: break;
5623:
1.1.1.7 root 5624: case IDPM_CHECK_FILESYS:
5625: case IDPM_REPAIR_FILESYS:
5626: {
5627: LPARAM lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
5628:
5629: if (LOWORD (lLetter) != 0xffff)
1.1.1.19 root 5630: CheckFilesystem ((char) HIWORD (lLetter) - 'A', menuItem == IDPM_REPAIR_FILESYS);
1.1.1.7 root 5631: }
5632: break;
5633:
5634: case IDM_UNMOUNT_VOLUME:
5635: if (CheckMountList ())
5636: Dismount (hwndDlg, 0);
5637: break;
5638:
5639: case IDPM_OPEN_VOLUME:
5640: {
5641: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
5642: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
5643:
1.1.1.11 root 5644: WaitCursor ();
1.1.1.7 root 5645: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
5646: NormalCursor ();
5647: }
5648: break;
5649:
5650: case IDM_VOLUME_PROPERTIES:
5651: DialogBoxParamW (hInst,
5652: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1.1.13 root 5653: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) FALSE);
1.1.1.7 root 5654: break;
5655:
5656: case IDM_MOUNT_VOLUME:
5657: if (!VolumeSelected(hwndDlg))
5658: {
5659: Warning ("NO_VOLUME_SELECTED");
5660: }
5661: else
5662: {
5663: mountOptions = defaultMountOptions;
1.1.1.15 root 5664: bPrebootPasswordDlgMode = FALSE;
1.1.1.7 root 5665:
5666: if (CheckMountList ())
5667: Mount (hwndDlg, 0, 0);
5668: }
5669: break;
1.1.1.19 root 5670:
1.1.1.25! root 5671: case IDPM_ADD_TO_FAVORITES:
! 5672: case IDPM_ADD_TO_SYSTEM_FAVORITES:
! 5673: {
! 5674: LPARAM selectedDrive = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
! 5675:
! 5676: if (LOWORD (selectedDrive) == TC_MLIST_ITEM_NONSYS_VOL)
! 5677: AddMountedVolumeToFavorites (hwndDlg, HIWORD (selectedDrive) - 'A', menuItem == IDPM_ADD_TO_SYSTEM_FAVORITES);
! 5678: }
! 5679: break;
! 5680:
1.1.1.19 root 5681: default:
5682: SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
1.1.1.13 root 5683: break;
1.1.1.7 root 5684: }
5685: return 1;
5686: }
1.1 root 5687: }
5688: }
5689: return 0;
5690:
5691: case WM_ERASEBKGND:
5692: return 0;
5693:
5694: case WM_COMMAND:
5695:
1.1.1.13 root 5696: if (lw == IDCANCEL || lw == IDC_EXIT)
1.1 root 5697: {
5698: EndMainDlg (hwndDlg);
5699: return 1;
5700: }
5701:
5702: if (lw == IDHELP || lw == IDM_HELP)
5703: {
1.1.1.7 root 5704: OpenPageHelp (hwndDlg, 0);
1.1 root 5705: return 1;
5706: }
5707:
1.1.1.12 root 5708: if (lw == IDM_ABOUT || lw == IDC_LOGO)
1.1 root 5709: {
1.1.1.7 root 5710: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 5711: return 1;
5712: }
5713:
1.1.1.13 root 5714: if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_NONSYS_VOL
1.1.1.7 root 5715: || lw == IDM_UNMOUNT_VOLUME)
1.1 root 5716: {
1.1.1.13 root 5717: if (lw == IDM_UNMOUNT_VOLUME && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) != TC_MLIST_ITEM_NONSYS_VOL)
1.1.1.6 root 5718: {
1.1.1.7 root 5719: Warning ("SELECT_A_MOUNTED_VOLUME");
5720: return 1;
1.1.1.6 root 5721: }
1.1 root 5722:
1.1.1.7 root 5723: if (CheckMountList ())
5724: Dismount (hwndDlg, 0);
1.1 root 5725: return 1;
5726: }
5727:
1.1.1.7 root 5728: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS || lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 5729: && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
5730: {
1.1.1.7 root 5731: MessageBoxW (hwndDlg, GetString ("SELECT_FREE_DRIVE"), L"TrueCrypt", MB_ICONEXCLAMATION);
1.1 root 5732: return 1;
5733: }
5734:
1.1.1.7 root 5735: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS))
1.1 root 5736: {
1.1.1.19 root 5737: MountSelectedVolume (hwndDlg, lw == IDM_MOUNT_VOLUME_OPTIONS);
1.1 root 5738: return 1;
5739: }
5740:
1.1.1.7 root 5741: if (lw == IDC_UNMOUNTALL || lw == IDM_UNMOUNTALL)
1.1 root 5742: {
1.1.1.7 root 5743: DismountAll (hwndDlg, bForceUnmount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1 root 5744: return 1;
5745: }
5746:
1.1.1.7 root 5747: if (lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 5748: {
1.1.1.7 root 5749: // If Shift key is down and the password cache isn't empty, bypass password prompt
5750: MountAllDevices (hwndDlg, !(GetAsyncKeyState (VK_SHIFT) < 0 && !IsPasswordCacheEmpty()));
1.1 root 5751: return 1;
5752: }
5753:
1.1.1.7 root 5754: if (lw == IDC_SELECT_FILE || lw == IDM_SELECT_FILE)
1.1 root 5755: {
5756: SelectContainer (hwndDlg);
5757: return 1;
5758: }
5759:
1.1.1.7 root 5760: if (lw == IDC_SELECT_DEVICE || lw == IDM_SELECT_DEVICE)
1.1 root 5761: {
5762: SelectPartition (hwndDlg);
5763: return 1;
5764: }
5765:
1.1.1.13 root 5766: // System Encryption menu
5767: switch (lw)
5768: {
5769: case IDM_ENCRYPT_SYSTEM_DEVICE:
5770: EncryptSystemDevice ();
5771: break;
5772: case IDM_PERMANENTLY_DECRYPT_SYS:
5773: DecryptSystemDevice ();
5774: break;
1.1.1.17 root 5775: case IDM_CREATE_HIDDEN_OS:
5776: CreateHiddenOS ();
5777: break;
1.1.1.13 root 5778: case IDM_SYSENC_RESUME:
5779: ResumeInterruptedSysEncProcess ();
5780: break;
5781: case IDM_SYSTEM_ENCRYPTION_STATUS:
5782: ShowSystemEncryptionStatus ();
5783: break;
5784: case IDM_CHANGE_SYS_PASSWORD:
5785: ChangeSysEncPassword (hwndDlg, FALSE);
5786: break;
5787: case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
5788: ChangeSysEncPassword (hwndDlg, TRUE);
5789: break;
5790: case IDM_CREATE_RESCUE_DISK:
5791: CreateRescueDisk ();
5792: break;
5793: case IDM_VERIFY_RESCUE_DISK:
5794: VerifyRescueDisk ();
5795: break;
1.1.1.15 root 5796: case IDM_MOUNT_SYSENC_PART_WITHOUT_PBA:
5797:
5798: if (CheckSysEncMountWithoutPBA ("", FALSE))
5799: {
5800: mountOptions = defaultMountOptions;
5801: bPrebootPasswordDlgMode = TRUE;
5802:
5803: if (CheckMountList ())
5804: Mount (hwndDlg, 0, 0);
5805:
5806: bPrebootPasswordDlgMode = FALSE;
5807: }
5808: break;
1.1.1.13 root 5809: }
5810:
1.1.1.7 root 5811: if (lw == IDC_VOLUME_TOOLS)
5812: {
1.1.1.13 root 5813: /* Volume Tools popup menu */
5814:
1.1.1.7 root 5815: int menuItem;
5816: char volPath[TC_MAX_PATH]; /* Volume to mount */
5817: HMENU popup = CreatePopupMenu ();
5818: RECT rect;
5819:
1.1.1.13 root 5820: if (ActiveSysEncDeviceSelected ())
5821: {
5822: PopulateSysEncContextMenu (popup, TRUE);
5823: }
5824: else
5825: {
5826: AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
5827: AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
5828: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.25! root 5829: AppendMenuW (popup, MF_STRING, IDM_ADD_REMOVE_VOL_KEYFILES, GetString ("IDM_ADD_REMOVE_VOL_KEYFILES"));
! 5830: AppendMenuW (popup, MF_STRING, IDM_REMOVE_ALL_KEYFILES_FROM_VOL, GetString ("IDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
! 5831: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.13 root 5832: AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
5833: AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
5834: }
1.1.1.7 root 5835:
5836: GetWindowRect (GetDlgItem (hwndDlg, IDC_VOLUME_TOOLS), &rect);
5837:
5838: menuItem = TrackPopupMenu (popup,
5839: TPM_RETURNCMD | TPM_LEFTBUTTON,
5840: rect.left + 2,
5841: rect.top + 2,
5842: 0,
5843: hwndDlg,
5844: NULL);
5845:
5846: DestroyMenu (popup);
5847:
5848: switch (menuItem)
5849: {
5850: case IDM_CHANGE_PASSWORD:
5851: if (!VolumeSelected(hwndDlg))
5852: {
5853: Warning ("NO_VOLUME_SELECTED");
5854: }
5855: else
5856: {
5857: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
5858: ChangePassword (hwndDlg);
5859: }
5860: break;
5861:
5862: case IDM_CHANGE_HEADER_KEY_DERIV_ALGO:
5863: if (!VolumeSelected(hwndDlg))
5864: {
5865: Warning ("NO_VOLUME_SELECTED");
5866: }
5867: else
5868: {
5869: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
5870: ChangePassword (hwndDlg);
5871: }
5872: break;
5873:
1.1.1.25! root 5874: case IDM_ADD_REMOVE_VOL_KEYFILES:
! 5875: if (!VolumeSelected(hwndDlg))
! 5876: {
! 5877: Warning ("NO_VOLUME_SELECTED");
! 5878: }
! 5879: else
! 5880: {
! 5881: pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
! 5882: ChangePassword (hwndDlg);
! 5883: }
! 5884: break;
! 5885:
! 5886: case IDM_REMOVE_ALL_KEYFILES_FROM_VOL:
! 5887: if (!VolumeSelected(hwndDlg))
! 5888: {
! 5889: Warning ("NO_VOLUME_SELECTED");
! 5890: }
! 5891: else
! 5892: {
! 5893: pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
! 5894: ChangePassword (hwndDlg);
! 5895: }
! 5896: break;
! 5897:
1.1.1.7 root 5898: case IDM_BACKUP_VOL_HEADER:
5899: if (!VolumeSelected(hwndDlg))
5900: {
5901: Warning ("NO_VOLUME_SELECTED");
5902: }
5903: else
5904: {
5905: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
5906:
1.1.1.19 root 5907: WaitCursor ();
5908:
1.1.1.11 root 5909: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
5910: UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
5911: else
5912: BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.19 root 5913:
5914: NormalCursor ();
1.1.1.7 root 5915: }
5916: break;
5917:
5918: case IDM_RESTORE_VOL_HEADER:
5919: if (!VolumeSelected(hwndDlg))
5920: {
5921: Warning ("NO_VOLUME_SELECTED");
5922: }
5923: else
5924: {
5925: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
5926:
1.1.1.19 root 5927: WaitCursor ();
5928:
1.1.1.11 root 5929: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
5930: UacRestoreVolumeHeader (hwndDlg, volPath);
5931: else
5932: RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.19 root 5933:
5934: NormalCursor ();
1.1.1.7 root 5935: }
5936: break;
1.1.1.13 root 5937:
1.1.1.19 root 5938: default:
5939: SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
1.1.1.13 root 5940: break;
1.1.1.7 root 5941: }
5942: return 1;
5943: }
5944:
5945: if (lw == IDM_CHANGE_PASSWORD)
1.1 root 5946: {
1.1.1.7 root 5947: if (!VolumeSelected(hwndDlg))
5948: {
5949: Warning ("NO_VOLUME_SELECTED");
5950: }
5951: else
5952: {
1.1.1.13 root 5953: if (ActiveSysEncDeviceSelected ())
5954: {
5955: ChangeSysEncPassword (hwndDlg, FALSE);
5956: }
5957: else
5958: {
5959: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
5960: ChangePassword (hwndDlg);
5961: }
1.1.1.7 root 5962: }
1.1 root 5963: return 1;
5964: }
5965:
1.1.1.7 root 5966: if (lw == IDM_CHANGE_HEADER_KEY_DERIV_ALGO)
5967: {
5968: if (!VolumeSelected(hwndDlg))
5969: {
5970: Warning ("NO_VOLUME_SELECTED");
5971: }
5972: else
5973: {
1.1.1.13 root 5974: if (ActiveSysEncDeviceSelected ())
5975: {
5976: ChangeSysEncPassword (hwndDlg, TRUE);
5977: }
5978: else
5979: {
5980: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
5981: ChangePassword (hwndDlg);
5982: }
1.1.1.7 root 5983: }
5984: return 1;
5985: }
5986:
5987: if (lw == IDC_WIPE_CACHE || lw == IDM_WIPE_CACHE)
1.1 root 5988: {
1.1.1.21 root 5989: WipeCache (hwndDlg, FALSE);
1.1 root 5990: return 1;
5991: }
5992:
1.1.1.7 root 5993: if (lw == IDM_CLEAR_HISTORY)
1.1 root 5994: {
1.1.1.11 root 5995: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1 root 5996: EnableDisableButtons (hwndDlg);
5997: return 1;
5998: }
5999:
1.1.1.7 root 6000: if (lw == IDC_CREATE_VOLUME || lw == IDM_CREATE_VOLUME || lw == IDM_VOLUME_WIZARD)
1.1 root 6001: {
1.1.1.13 root 6002: LaunchVolCreationWizard (hwndDlg, "");
1.1 root 6003: return 1;
6004: }
6005:
1.1.1.7 root 6006: if (lw == IDM_ADD_REMOVE_VOL_KEYFILES)
1.1.1.3 root 6007: {
1.1.1.7 root 6008: if (!VolumeSelected(hwndDlg))
6009: {
6010: Warning ("NO_VOLUME_SELECTED");
6011: }
6012: else
6013: {
6014: pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
6015: ChangePassword (hwndDlg);
6016: }
6017: return 1;
6018: }
1.1.1.3 root 6019:
1.1.1.7 root 6020: if (lw == IDM_REMOVE_ALL_KEYFILES_FROM_VOL)
6021: {
6022: if (!VolumeSelected(hwndDlg))
1.1.1.3 root 6023: {
1.1.1.7 root 6024: Warning ("NO_VOLUME_SELECTED");
6025: }
6026: else
6027: {
6028: pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
6029: ChangePassword (hwndDlg);
1.1.1.3 root 6030: }
6031: return 1;
6032: }
1.1.1.7 root 6033:
1.1.1.19 root 6034: if (lw == IDM_MANAGE_TOKEN_KEYFILES)
6035: {
6036: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_KEYFILES), hwndDlg, (DLGPROC) SecurityTokenKeyfileDlgProc, NULL);
6037: return 1;
6038: }
6039:
6040: if (lw == IDM_CLOSE_ALL_TOKEN_SESSIONS)
6041: {
6042: {
1.1.1.23 root 6043: WaitCursor();
6044: finally_do ({ NormalCursor(); });
1.1.1.19 root 6045:
1.1.1.23 root 6046: SecurityToken::CloseAllSessions();
1.1.1.19 root 6047: }
1.1.1.23 root 6048: Info ("ALL_TOKEN_SESSIONS_CLOSED");
1.1.1.19 root 6049:
6050: return 1;
6051: }
6052:
1.1.1.25! root 6053: if (lw == IDM_KEYFILE_GENERATOR)
1.1.1.7 root 6054: {
6055: DialogBoxParamW (hInst,
6056: MAKEINTRESOURCEW (IDD_KEYFILE_GENERATOR), hwndDlg,
6057: (DLGPROC) KeyfileGeneratorDlgProc, (LPARAM) 0);
6058:
6059: return 1;
6060: }
6061:
6062: if (lw == IDM_LICENSE)
6063: {
1.1.1.13 root 6064: TextInfoDialogBox (TC_TBXID_LEGAL_NOTICES);
1.1.1.7 root 6065: return 1;
6066: }
1.1.1.3 root 6067:
1.1.1.11 root 6068: if (lw == IDM_WEBSITE)
1.1.1.7 root 6069: {
1.1.1.11 root 6070: Applink ("website", TRUE, "");
6071: return 1;
6072: }
6073: else if (lw == IDM_HOMEPAGE)
6074: {
6075: Applink ("homepage", TRUE, "");
1.1.1.7 root 6076: return 1;
6077: }
6078: else if (lw == IDM_FORUMS)
1.1 root 6079: {
1.1.1.11 root 6080: Applink ("forum", TRUE, "");
1.1.1.5 root 6081: return 1;
6082: }
1.1.1.9 root 6083: else if (lw == IDM_ONLINE_TUTORIAL)
6084: {
1.1.1.11 root 6085: Applink ("tutorial", TRUE, "");
1.1.1.9 root 6086: return 1;
6087: }
6088: else if (lw == IDM_ONLINE_HELP)
6089: {
1.1.1.10 root 6090: OpenOnlineHelp ();
1.1.1.9 root 6091: return 1;
6092: }
1.1.1.7 root 6093: else if (lw == IDM_FAQ)
6094: {
1.1.1.11 root 6095: Applink ("faq", TRUE, "");
1.1.1.7 root 6096: return 1;
6097: }
6098: else if (lw == IDM_TC_DOWNLOADS)
1.1.1.5 root 6099: {
1.1.1.11 root 6100: Applink ("downloads", TRUE, "");
1.1 root 6101: return 1;
6102: }
1.1.1.7 root 6103: else if (lw == IDM_NEWS)
6104: {
1.1.1.11 root 6105: Applink ("news", TRUE, "");
1.1.1.7 root 6106: return 1;
6107: }
6108: else if (lw == IDM_VERSION_HISTORY)
1.1.1.6 root 6109: {
1.1.1.11 root 6110: Applink ("history", TRUE, "");
1.1.1.6 root 6111: return 1;
6112: }
1.1.1.7 root 6113: else if (lw == IDM_BUGREPORT)
6114: {
1.1.1.11 root 6115: Applink ("bugreport", TRUE, "");
6116: return 1;
6117: }
1.1.1.25! root 6118: else if (lw == IDM_ANALYZE_SYSTEM_CRASH)
! 6119: {
! 6120: if (!IsAdmin() && IsUacSupported())
! 6121: UacAnalyzeKernelMiniDump (hwndDlg);
! 6122: else
! 6123: AnalyzeKernelMiniDump (hwndDlg);
! 6124:
! 6125: return 1;
! 6126: }
1.1.1.11 root 6127: else if (lw == IDM_DONATIONS)
6128: {
6129: Applink ("donations", FALSE, "");
1.1.1.7 root 6130: return 1;
6131: }
6132: else if (lw == IDM_CONTACT)
1.1 root 6133: {
1.1.1.11 root 6134: Applink ("contact", FALSE, "");
1.1.1.7 root 6135: return 1;
6136: }
6137:
6138: if (lw == IDM_PREFERENCES)
6139: {
6140: if (IDOK == DialogBoxParamW (hInst,
6141: MAKEINTRESOURCEW (IDD_PREFERENCES_DLG), hwndDlg,
6142: (DLGPROC) PreferencesDlgProc, (LPARAM) 0))
6143: {
6144: if (bEnableBkgTask)
1.1.1.12 root 6145: {
1.1.1.7 root 6146: TaskBarIconAdd (hwndDlg);
1.1.1.12 root 6147: }
1.1.1.7 root 6148: else
1.1.1.12 root 6149: {
1.1.1.7 root 6150: TaskBarIconRemove (hwndDlg);
1.1.1.13 root 6151: if (MainWindowHidden)
1.1.1.12 root 6152: EndMainDlg (hwndDlg);
6153: }
1.1.1.7 root 6154: }
6155: return 1;
6156: }
6157:
6158: if (lw == IDM_HOTKEY_SETTINGS)
6159: {
6160: DialogBoxParamW (hInst,
6161: MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
6162: (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
6163: return 1;
6164: }
6165:
1.1.1.25! root 6166: if (lw == IDM_PERFORMANCE_SETTINGS)
! 6167: {
! 6168: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_PERFORMANCE_SETTINGS), hwndDlg, (DLGPROC) PerformanceSettingsDlgProc, 0);
! 6169: return 1;
! 6170: }
! 6171:
! 6172: if (lw == IDM_DEFAULT_KEYFILES)
1.1.1.7 root 6173: {
6174: KeyfileDefaultsDlg (hwndDlg);
1.1 root 6175: return 1;
6176: }
6177:
1.1.1.25! root 6178: if (lw == IDM_ADD_VOLUME_TO_FAVORITES || lw == IDM_ADD_VOLUME_TO_SYSTEM_FAVORITES)
! 6179: {
! 6180: LPARAM selectedDrive = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
! 6181:
! 6182: char volPathLower[TC_MAX_PATH];
! 6183: wchar_t volPathLowerW[TC_MAX_PATH];
! 6184:
! 6185: // volPathLower will contain the volume path (if any) from the input field below the drive list
! 6186: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPathLower, sizeof (volPathLower));
! 6187:
! 6188: if (LOWORD (selectedDrive) != TC_MLIST_ITEM_NONSYS_VOL
! 6189: && !(VolumeSelected (hwndDlg) && IsMountedVolume (volPathLower)))
! 6190: {
! 6191: Warning ("SELECT_A_MOUNTED_VOLUME");
! 6192:
! 6193: return 1;
! 6194: }
! 6195:
! 6196: int driveNo;
! 6197:
! 6198: if (VolumeSelected (hwndDlg)
! 6199: && IsMountedVolume (volPathLower))
! 6200: {
! 6201: if (LOWORD (selectedDrive) != TC_MLIST_ITEM_NONSYS_VOL)
! 6202: {
! 6203: driveNo = GetMountedVolumeDriveNo (volPathLower);
! 6204: }
! 6205: else
! 6206: {
! 6207: /* We need to resolve selection ambiguity. Two different mounted volumes are currently
! 6208: selected (one in the drive letter list and the other in the input field below the list). */
! 6209:
! 6210: VOLUME_PROPERTIES_STRUCT prop;
! 6211: DWORD dwResult;
! 6212:
! 6213: memset (&prop, 0, sizeof(prop));
! 6214: prop.driveNo = HIWORD (selectedDrive) - 'A';
! 6215:
! 6216: if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL) || dwResult == 0)
! 6217: {
! 6218: Warning ("SELECT_A_MOUNTED_VOLUME");
! 6219: return 1;
! 6220: }
! 6221:
! 6222: // volPathHigher will contain the volume path selected in the main drive list
! 6223: wstring volPathHigher (prop.wszVolume);
! 6224:
! 6225: ToSBCS (prop.wszVolume);
! 6226: strcpy ((char *) volPathLowerW, volPathLower);
! 6227: ToUNICODE ((char *) volPathLowerW);
! 6228:
! 6229: if (strcmp (((memcmp ((char *) prop.wszVolume, "\\??\\", 4) == 0) ? (char *) prop.wszVolume + 4 : (char *) prop.wszVolume), volPathLower) != 0)
! 6230: {
! 6231: // The path selected in the input field is different from the path to the volume selected
! 6232: // in the drive lettter list. We have to resolve possible ambiguity.
! 6233:
! 6234: wchar_t *tmp[] = {L"", L"", L"", L"", L"", 0};
! 6235: const int maxVolPathLen = 80;
! 6236:
! 6237: if (volPathHigher.length () > maxVolPathLen)
! 6238: {
! 6239: volPathHigher = wstring (L"...") + volPathHigher.substr (volPathHigher.length () - maxVolPathLen, maxVolPathLen);
! 6240: }
! 6241:
! 6242: wstring volPathLowerWStr (volPathLowerW);
! 6243:
! 6244: if (volPathLowerWStr.length () > maxVolPathLen)
! 6245: {
! 6246: volPathLowerWStr = wstring (L"...") + volPathLowerWStr.substr (volPathLowerWStr.length () - maxVolPathLen, maxVolPathLen);
! 6247: }
! 6248:
! 6249: tmp[1] = GetString ("AMBIGUOUS_VOL_SELECTION");
! 6250: tmp[2] = (wchar_t *) volPathHigher.c_str();
! 6251: tmp[3] = (wchar_t *) volPathLowerWStr.c_str();
! 6252: tmp[4] = GetString ("IDCANCEL");
! 6253:
! 6254: switch (AskMultiChoice ((void **) tmp, FALSE))
! 6255: {
! 6256: case 1:
! 6257: driveNo = HIWORD (selectedDrive) - 'A';
! 6258: break;
! 6259:
! 6260: case 2:
! 6261: driveNo = GetMountedVolumeDriveNo (volPathLower);
! 6262: break;
! 6263:
! 6264: default:
! 6265: return 1;
! 6266: }
! 6267: }
! 6268: else
! 6269: {
! 6270: driveNo = HIWORD (selectedDrive) - 'A';
! 6271: }
! 6272: }
! 6273: }
! 6274: else
! 6275: {
! 6276: driveNo = HIWORD (selectedDrive) - 'A';
! 6277: }
! 6278:
! 6279: AddMountedVolumeToFavorites (hwndDlg, driveNo, lw == IDM_ADD_VOLUME_TO_SYSTEM_FAVORITES);
! 6280:
! 6281: return 1;
! 6282: }
! 6283:
! 6284: if (lw == IDM_ORGANIZE_FAVORITES || lw == IDM_ORGANIZE_SYSTEM_FAVORITES)
! 6285: {
! 6286: OrganizeFavoriteVolumes (hwndDlg, lw == IDM_ORGANIZE_SYSTEM_FAVORITES);
! 6287: return 1;
! 6288: }
! 6289:
1.1.1.19 root 6290: if (lw == IDM_TOKEN_PREFERENCES)
6291: {
6292: SecurityTokenPreferencesDialog (hwndDlg);
6293: return 1;
6294: }
6295:
6296: if (lw == IDM_SYSENC_SETTINGS || lw == IDM_SYS_ENC_SETTINGS)
6297: {
6298: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_SETTINGS), hwndDlg, (DLGPROC) BootLoaderPreferencesDlgProc, 0);
6299: return 1;
6300: }
6301:
1.1.1.23 root 6302: if (lw == IDM_SYS_FAVORITES_SETTINGS)
6303: {
1.1.1.25! root 6304: OrganizeFavoriteVolumes (hwndDlg, true);
1.1.1.23 root 6305: return 1;
6306: }
6307:
1.1.1.7 root 6308: if (lw == IDM_BENCHMARK)
1.1.1.5 root 6309: {
6310: Benchmark (hwndDlg);
6311: return 1;
6312: }
6313:
1.1.1.13 root 6314: if (lw == IDM_TRAVELER)
1.1.1.6 root 6315: {
1.1.1.7 root 6316: DialogBoxParamW (hInst,
1.1.1.13 root 6317: MAKEINTRESOURCEW (IDD_TRAVELER_DLG), hwndDlg,
6318: (DLGPROC) TravelerDlgProc, (LPARAM) 0);
1.1.1.6 root 6319: return 1;
6320: }
6321:
1.1.1.7 root 6322: if (lw == IDM_BACKUP_VOL_HEADER)
6323: {
6324: if (!VolumeSelected(hwndDlg))
6325: {
6326: Warning ("NO_VOLUME_SELECTED");
6327: }
6328: else
6329: {
6330: char volPath[TC_MAX_PATH]; /* Volume to mount */
6331:
6332: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
6333:
1.1.1.19 root 6334: WaitCursor ();
6335:
1.1.1.11 root 6336: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
6337: UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
6338: else
6339: BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.19 root 6340:
6341: NormalCursor ();
1.1.1.7 root 6342: }
6343: return 1;
6344: }
6345:
6346: if (lw == IDM_RESTORE_VOL_HEADER)
6347: {
6348: if (!VolumeSelected(hwndDlg))
6349: {
6350: Warning ("NO_VOLUME_SELECTED");
6351: }
6352: else
6353: {
6354: char volPath[TC_MAX_PATH]; /* Volume to mount */
6355:
6356: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
6357:
1.1.1.19 root 6358: WaitCursor ();
6359:
1.1.1.11 root 6360: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
6361: UacRestoreVolumeHeader (hwndDlg, volPath);
6362: else
6363: RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.19 root 6364:
6365: NormalCursor ();
1.1.1.7 root 6366: }
6367: return 1;
6368: }
6369:
6370: if (lw == IDM_LANGUAGE)
6371: {
6372: BOOL p;
6373: if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), hwndDlg,
6374: (DLGPROC) LanguageDlgProc, (LPARAM) 0) == IDOK)
6375: {
6376: LoadLanguageFile ();
6377: SaveSettings (hwndDlg);
6378:
6379: p = LocalizationActive;
6380: LocalizationActive = TRUE;
6381: InitMainDialog (hwndDlg);
6382: InvalidateRect (hwndDlg, NULL, FALSE);
6383: LocalizationActive = p;
6384: DrawMenuBar (hwndDlg);
6385: }
6386: return 1;
6387: }
6388:
6389: if (lw == IDM_TEST_VECTORS)
6390: {
6391: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG), hwndDlg, (DLGPROC) CipherTestDialogProc, (LPARAM) 1);
6392: return 1;
6393: }
6394:
1.1.1.6 root 6395: if (lw == IDM_REFRESH_DRIVE_LETTERS)
6396: {
6397: DWORD driveMap = GetLogicalDrives ();
6398:
1.1.1.11 root 6399: WaitCursor ();
1.1.1.7 root 6400:
1.1.1.10 root 6401: if (!(nCurrentOS == WIN_2000 && RemoteSession))
6402: {
6403: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
6404: Sleep (100);
6405: BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
6406: }
1.1.1.7 root 6407:
1.1.1.6 root 6408: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1.1.7 root 6409:
6410: if (nSelectedDriveIndex >= 0)
6411: {
6412: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST),
6413: (char) HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
6414: }
6415:
1.1.1.6 root 6416: NormalCursor ();
1.1.1.7 root 6417: return 1;
6418: }
6419:
6420: if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
6421: {
1.1.1.25! root 6422: MountFavoriteVolumes();
1.1.1.7 root 6423: return 1;
6424: }
6425:
1.1.1.19 root 6426: if (lw == IDM_RESUME_INTERRUPTED_PROC)
6427: {
6428: ResumeInterruptedNonSysInplaceEncProcess ();
6429: return 1;
6430: }
6431:
1.1.1.7 root 6432: if (lw == IDC_VOLUME_PROPERTIES || lw == IDM_VOLUME_PROPERTIES)
1.1 root 6433: {
1.1.1.7 root 6434: DialogBoxParamW (hInst,
6435: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1 root 6436: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
6437: return 1;
6438: }
6439:
6440: if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
6441: {
1.1.1.5 root 6442: EnableDisableButtons (hwndDlg);
1.1 root 6443: return 1;
6444: }
6445:
6446: if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
6447: {
6448: UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 6449: MoveEditToCombo ((HWND) lParam, bHistory);
1.1.1.13 root 6450: PostMessage (hwndDlg, TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS, 0, 0);
1.1.1.5 root 6451: return 1;
6452: }
6453:
6454: if (lw == IDC_NO_HISTORY)
6455: {
1.1.1.11 root 6456: if (!(bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY))))
6457: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
6458:
1.1 root 6459: return 1;
6460: }
6461:
1.1.1.25! root 6462: if (lw >= TC_FAVORITE_MENU_CMD_ID_OFFSET && lw < TC_FAVORITE_MENU_CMD_ID_OFFSET_END)
1.1.1.6 root 6463: {
1.1.1.25! root 6464: size_t favoriteIndex = lw - TC_FAVORITE_MENU_CMD_ID_OFFSET;
! 6465:
! 6466: if (favoriteIndex < FavoriteVolumes.size())
! 6467: {
! 6468: if (IsMountedVolume (FavoriteVolumes[favoriteIndex].Path.c_str()))
! 6469: {
! 6470: WaitCursor();
! 6471: OpenVolumeExplorerWindow (GetMountedVolumeDriveNo ((char *) FavoriteVolumes[favoriteIndex].Path.c_str()));
! 6472: NormalCursor();
! 6473: }
! 6474: else
! 6475: MountFavoriteVolumes (FALSE, FALSE, FALSE, FavoriteVolumes[favoriteIndex]);
! 6476: }
! 6477:
! 6478: return 1;
! 6479: }
! 6480:
! 6481: return 0;
! 6482:
! 6483: case WM_DROPFILES:
! 6484: {
! 6485: HDROP hdrop = (HDROP) wParam;
! 6486: DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
1.1.1.6 root 6487: DragFinish (hdrop);
6488:
1.1.1.10 root 6489: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.6 root 6490: EnableDisableButtons (hwndDlg);
6491: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
6492: }
1.1.1.7 root 6493: return 1;
1.1.1.6 root 6494:
1.1.1.13 root 6495: case TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS:
1.1 root 6496: EnableDisableButtons (hwndDlg);
6497: return 1;
6498:
1.1.1.13 root 6499: case TC_APPMSG_MOUNT_SHOW_WINDOW:
1.1.1.8 root 6500: MainWindowHidden = FALSE;
1.1.1.13 root 6501: ShowWindow (hwndDlg, SW_SHOW);
6502: ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.8 root 6503: return 1;
6504:
6505: case WM_COPYDATA:
6506: {
6507: PCOPYDATASTRUCT cd = (PCOPYDATASTRUCT)lParam;
6508: if (memcmp (&cd->dwData, WM_COPY_SET_VOLUME_NAME, 4) == 0)
6509: {
6510: if (cd->cbData > 0)
1.1.1.23 root 6511: {
6512: ((char *) cd->lpData)[cd->cbData - 1] = 0;
1.1.1.10 root 6513: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), (char *)cd->lpData, bHistory);
1.1.1.23 root 6514: }
1.1.1.8 root 6515:
6516: EnableDisableButtons (hwndDlg);
6517: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
6518: }
6519: }
6520: return 1;
6521:
1.1 root 6522: case WM_CLOSE:
6523: EndMainDlg (hwndDlg);
6524: return 1;
1.1.1.11 root 6525:
6526: default:
6527: // Recreate tray icon if Explorer restarted
6528: if (taskBarCreatedMsg != 0 && uMsg == taskBarCreatedMsg && TaskBarIconMutex != NULL)
6529: {
6530: TaskBarIconRemove (hwndDlg);
6531: TaskBarIconAdd (hwndDlg);
6532: return 1;
6533: }
1.1 root 6534: }
6535:
6536: return 0;
6537: }
6538:
1.1.1.15 root 6539: void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
1.1 root 6540: {
6541: char **lpszCommandLineArgs; /* Array of command line arguments */
6542: int nNoCommandLineArgs; /* The number of arguments in the array */
1.1.1.7 root 6543: char tmpPath[MAX_PATH * 2];
6544:
6545: /* Defaults */
6546: mountOptions.PreserveTimestamp = TRUE;
1.1.1.11 root 6547:
6548: if (_stricmp (lpszCommandLine, "-Embedding") == 0)
6549: {
6550: ComServerMode = TRUE;
6551: return;
6552: }
1.1 root 6553:
6554: /* Extract command line arguments */
1.1.1.8 root 6555: NoCmdLineArgs = nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1.1.1.11 root 6556:
1.1 root 6557: if (nNoCommandLineArgs > 0)
6558: {
6559: int i;
6560:
6561: for (i = 0; i < nNoCommandLineArgs; i++)
6562: {
1.1.1.19 root 6563: enum
6564: {
6565: OptionAuto,
6566: OptionBeep,
6567: OptionCache,
6568: CommandDismount,
6569: OptionExplore,
6570: OptionForce,
6571: CommandHelp,
6572: OptionHistory,
6573: OptionKeyfile,
6574: OptionLetter,
6575: OptionMountOption,
6576: OptionPassword,
6577: OptionQuit,
6578: OptionSilent,
6579: OptionTokenLib,
6580: OptionVolume,
6581: CommandWipeCache
6582: };
6583:
1.1 root 6584: argument args[]=
6585: {
1.1.1.19 root 6586: { OptionAuto, "/auto", "/a", FALSE },
6587: { OptionBeep, "/beep", "/b", FALSE },
6588: { OptionCache, "/cache", "/c", FALSE },
6589: { CommandDismount, "/dismount", "/d", FALSE },
6590: { OptionExplore, "/explore", "/e", FALSE },
6591: { OptionForce, "/force", "/f", FALSE },
6592: { CommandHelp, "/help", "/?", FALSE },
6593: { OptionHistory, "/history", "/h", FALSE },
6594: { OptionKeyfile, "/keyfile", "/k", FALSE },
6595: { OptionLetter, "/letter", "/l", FALSE },
6596: { OptionMountOption, "/mountoption", "/m", FALSE },
6597: { OptionPassword, "/password", "/p", FALSE },
6598: { OptionQuit, "/quit", "/q", FALSE },
6599: { OptionSilent, "/silent", "/s", FALSE },
6600: { OptionTokenLib, "/tokenlib", NULL, FALSE },
6601: { OptionVolume, "/volume", "/v", FALSE },
6602: { CommandWipeCache, "/wipecache", "/w", FALSE }
1.1 root 6603: };
6604:
6605: argumentspec as;
6606:
6607: int nArgPos;
6608:
6609: as.args = args;
6610: as.arg_cnt = sizeof(args)/ sizeof(args[0]);
6611:
1.1.1.19 root 6612: switch (GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos))
1.1 root 6613: {
1.1.1.19 root 6614: case OptionAuto:
1.1.1.7 root 6615: {
6616: char szTmp[32];
6617: bAuto = TRUE;
1.1.1.2 root 6618:
1.1.1.7 root 6619: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
6620: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
6621: {
6622: if (!_stricmp (szTmp, "devices"))
6623: bAutoMountDevices = TRUE;
6624: else if (!_stricmp (szTmp, "favorites"))
6625: bAutoMountFavorites = TRUE;
1.1.1.25! root 6626: else if (!_stricmp (szTmp, "logon"))
! 6627: LogOn = TRUE;
1.1.1.7 root 6628: }
6629: }
6630: break;
1.1.1.2 root 6631:
1.1.1.19 root 6632: case OptionBeep:
1.1.1.7 root 6633: bBeep = TRUE;
1.1 root 6634: break;
6635:
1.1.1.19 root 6636: case OptionCache:
1.1.1.2 root 6637: {
1.1.1.7 root 6638: char szTmp[8];
6639: bCacheInDriver = TRUE;
6640:
6641: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
6642: szTmp, sizeof (szTmp));
6643:
6644: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
6645: bCacheInDriver = FALSE;
1.1.1.2 root 6646: }
1.1 root 6647: break;
6648:
1.1.1.19 root 6649: case CommandDismount:
1.1.1.7 root 6650:
6651: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
6652: szDriveLetter, sizeof (szDriveLetter)))
6653: cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
6654: else
6655: cmdUnmountDrive = -1;
6656:
1.1 root 6657: break;
6658:
1.1.1.19 root 6659: case OptionExplore:
1.1 root 6660: bExplore = TRUE;
6661: break;
6662:
1.1.1.19 root 6663: case OptionForce:
1.1.1.5 root 6664: bForceMount = TRUE;
6665: bForceUnmount = TRUE;
6666: break;
6667:
1.1.1.19 root 6668: case OptionKeyfile:
1.1.1.7 root 6669: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
6670: nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
6671: {
6672: KeyFile *kf;
6673: RelativePath2Absolute (tmpPath);
1.1.1.13 root 6674: kf = (KeyFile *) malloc (sizeof (KeyFile));
1.1.1.7 root 6675: strncpy (kf->FileName, tmpPath, sizeof (kf->FileName));
6676: FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
6677: }
6678: break;
6679:
1.1.1.19 root 6680: case OptionLetter:
1.1.1.2 root 6681: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.7 root 6682: szDriveLetter, sizeof (szDriveLetter));
6683: commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1.1.23 root 6684:
6685: if (commandLineDrive < 'C' || commandLineDrive > 'Z')
6686: AbortProcess ("BAD_DRIVE_LETTER");
6687:
1.1 root 6688: break;
6689:
1.1.1.19 root 6690: case OptionHistory:
1.1.1.6 root 6691: {
6692: char szTmp[8];
1.1.1.7 root 6693: bHistory = bHistoryCmdLine = TRUE;
1.1.1.6 root 6694:
1.1.1.7 root 6695: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
6696: szTmp, sizeof (szTmp));
6697:
6698: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
6699: bHistory = FALSE;
1.1.1.6 root 6700: }
6701: break;
6702:
1.1.1.19 root 6703: case OptionMountOption:
1.1.1.6 root 6704: {
1.1.1.7 root 6705: char szTmp[16];
1.1.1.6 root 6706: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
6707: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
6708: {
1.1.1.7 root 6709: if (!_stricmp (szTmp, "ro") || !_stricmp (szTmp, "readonly"))
1.1.1.6 root 6710: mountOptions.ReadOnly = TRUE;
6711:
1.1.1.7 root 6712: if (!_stricmp (szTmp, "rm") || !_stricmp (szTmp, "removable"))
1.1.1.6 root 6713: mountOptions.Removable = TRUE;
1.1.1.7 root 6714:
6715: if (!_stricmp (szTmp, "ts") || !_stricmp (szTmp, "timestamp"))
6716: mountOptions.PreserveTimestamp = FALSE;
1.1.1.15 root 6717:
6718: if (!_stricmp (szTmp, "sm") || !_stricmp (szTmp, "system"))
6719: mountOptions.PartitionInInactiveSysEncScope = bPrebootPasswordDlgMode = TRUE;
1.1.1.17 root 6720:
6721: if (!_stricmp (szTmp, "bk") || !_stricmp (szTmp, "headerbak"))
6722: mountOptions.UseBackupHeader = TRUE;
1.1.1.19 root 6723:
6724: if (!_stricmp (szTmp, "recovery"))
6725: mountOptions.RecoveryMode = TRUE;
1.1.1.23 root 6726:
6727: CmdMountOptions = mountOptions;
6728: CmdMountOptionsValid = TRUE;
1.1.1.6 root 6729: }
6730: }
1.1 root 6731: break;
6732:
1.1.1.19 root 6733: case OptionPassword:
1.1.1.7 root 6734: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.13 root 6735: (char *) CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text));
6736: CmdVolumePassword.Length = strlen ((char *) CmdVolumePassword.Text);
1.1.1.7 root 6737: CmdVolumePasswordValid = TRUE;
6738: break;
6739:
1.1.1.19 root 6740: case OptionVolume:
1.1.1.7 root 6741: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
6742: nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1 root 6743: {
1.1.1.7 root 6744: RelativePath2Absolute (szFileName);
1.1.1.10 root 6745: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.8 root 6746: CmdLineVolumeSpecified = TRUE;
1.1 root 6747: }
6748: break;
6749:
1.1.1.19 root 6750: case OptionQuit:
1.1 root 6751: {
1.1.1.7 root 6752: char szTmp[32];
1.1 root 6753:
1.1.1.7 root 6754: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
6755: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
1.1 root 6756: {
1.1.1.12 root 6757: if (!_stricmp (szTmp, "UAC")) // Used to indicate non-install elevation
6758: break;
6759:
1.1.1.7 root 6760: if (!_stricmp (szTmp, "preferences"))
1.1.1.12 root 6761: {
6762: Quit = TRUE;
1.1.1.7 root 6763: UsePreferences = TRUE;
1.1.1.12 root 6764: break;
6765: }
6766:
6767: if (!_stricmp (szTmp, "background"))
6768: bEnableBkgTask = TRUE;
1.1 root 6769: }
1.1.1.12 root 6770:
6771: Quit = TRUE;
6772: UsePreferences = FALSE;
1.1 root 6773: }
6774: break;
6775:
1.1.1.19 root 6776: case OptionSilent:
1.1.1.7 root 6777: Silent = TRUE;
1.1 root 6778: break;
6779:
1.1.1.19 root 6780: case OptionTokenLib:
6781: if (GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT)
6782: InitSecurityTokenLibrary();
6783: else
6784: Error ("COMMAND_LINE_ERROR");
6785:
6786: break;
6787:
6788: case CommandWipeCache:
1.1.1.7 root 6789: bWipe = TRUE;
1.1 root 6790: break;
6791:
1.1.1.19 root 6792: case CommandHelp:
1.1.1.7 root 6793: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1.1 root 6794: CommandHelpDlgProc, (LPARAM) &as);
6795: exit(0);
6796: break;
6797:
6798: // no option = file name
6799: default:
1.1.1.2 root 6800: {
1.1.1.23 root 6801: strcpy_s (szFileName, array_capacity (szFileName), lpszCommandLineArgs[i]);
6802: RelativePath2Absolute (szFileName);
1.1.1.8 root 6803:
6804: if (nNoCommandLineArgs == 1)
6805: CmdLineVolumeSpecified = TRUE;
1.1.1.10 root 6806: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.2 root 6807: }
1.1 root 6808: }
6809: }
6810: }
6811:
6812: /* Free up the command line arguments */
6813: while (--nNoCommandLineArgs >= 0)
6814: {
6815: free (lpszCommandLineArgs[nNoCommandLineArgs]);
6816: }
6817: }
6818:
1.1.1.7 root 6819:
1.1.1.23 root 6820: static SERVICE_STATUS SystemFavoritesServiceStatus;
6821: static SERVICE_STATUS_HANDLE SystemFavoritesServiceStatusHandle;
6822:
6823:
6824: static void SystemFavoritesServiceLogError (const string &errorMessage)
6825: {
6826: HANDLE eventSource = RegisterEventSource (NULL, TC_SYSTEM_FAVORITES_SERVICE_NAME);
6827:
6828: if (eventSource)
6829: {
6830: LPCTSTR strings[] = { TC_SYSTEM_FAVORITES_SERVICE_NAME, errorMessage.c_str() };
6831: ReportEvent (eventSource, EVENTLOG_ERROR_TYPE, 0, 0xC0000001, NULL, array_capacity (strings), 0, strings, NULL);
6832:
6833: DeregisterEventSource (eventSource);
6834: }
6835: }
6836:
6837:
6838: static void SystemFavoritesServiceSetStatus (DWORD status, DWORD waitHint = 0)
6839: {
6840: SystemFavoritesServiceStatus.dwCurrentState = status;
6841: SystemFavoritesServiceStatus.dwWaitHint = waitHint;
6842: SystemFavoritesServiceStatus.dwWin32ExitCode = NO_ERROR;
6843:
6844: SetServiceStatus (SystemFavoritesServiceStatusHandle, &SystemFavoritesServiceStatus);
6845: }
6846:
6847:
6848: static VOID WINAPI SystemFavoritesServiceCtrlHandler (DWORD control)
6849: {
6850: if (control == SERVICE_CONTROL_STOP)
6851: SystemFavoritesServiceSetStatus (SERVICE_STOP_PENDING);
6852: else
6853: SystemFavoritesServiceSetStatus (SystemFavoritesServiceStatus.dwCurrentState);
6854: }
6855:
6856:
6857: static VOID WINAPI SystemFavoritesServiceMain (DWORD argc, LPTSTR *argv)
1.1 root 6858: {
1.1.1.23 root 6859: memset (&SystemFavoritesServiceStatus, 0, sizeof (SystemFavoritesServiceStatus));
6860: SystemFavoritesServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
6861:
6862: SystemFavoritesServiceStatusHandle = RegisterServiceCtrlHandler (TC_SYSTEM_FAVORITES_SERVICE_NAME, SystemFavoritesServiceCtrlHandler);
6863: if (!SystemFavoritesServiceStatusHandle)
6864: return;
6865:
6866: SystemFavoritesServiceSetStatus (SERVICE_START_PENDING, 60000);
6867:
1.1.1.25! root 6868: try
! 6869: {
! 6870: MountFavoriteVolumes (TRUE);
! 6871: }
! 6872: catch (...) { }
1.1.1.23 root 6873:
6874: SystemFavoritesServiceSetStatus (SERVICE_RUNNING);
6875: SystemFavoritesServiceSetStatus (SERVICE_STOPPED);
6876: }
6877:
6878:
6879: static BOOL StartSystemFavoritesService ()
6880: {
6881: ServiceMode = TRUE;
6882: Silent = TRUE;
6883: DeviceChangeBroadcastDisabled = TRUE;
6884:
1.1.1.25! root 6885: InitOSVersionInfo();
! 6886:
1.1.1.23 root 6887: if (DriverAttach() != ERR_SUCCESS)
6888: return FALSE;
6889:
6890: SERVICE_TABLE_ENTRY serviceTable[2];
6891: serviceTable[0].lpServiceName = TC_SYSTEM_FAVORITES_SERVICE_NAME;
6892: serviceTable[0].lpServiceProc = SystemFavoritesServiceMain;
6893:
6894: serviceTable[1].lpServiceName = NULL;
6895: serviceTable[1].lpServiceProc = NULL;
6896:
6897: BOOL result = StartServiceCtrlDispatcher (serviceTable);
6898:
6899: if (!(ReadDriverConfigurationFlags() & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD))
6900: WipeCache (NULL, TRUE);
6901:
6902: return result;
6903: }
6904:
6905:
6906: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
6907: {
6908: int argc;
6909: LPWSTR *argv = CommandLineToArgvW (GetCommandLineW(), &argc);
6910:
6911: if (argv && argc == 2 && SingleStringToWide (TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION) == argv[1])
6912: return StartSystemFavoritesService() ? 0 : 1;
6913:
1.1 root 6914: int status;
1.1.1.13 root 6915: atexit (localcleanup);
1.1.1.19 root 6916: SetProcessShutdownParameters (0x100, 0);
1.1.1.13 root 6917:
6918: VirtualLock (&VolumePassword, sizeof (VolumePassword));
6919: VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
6920: VirtualLock (&mountOptions, sizeof (mountOptions));
6921: VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
1.1.1.18 root 6922: VirtualLock (&szFileName, sizeof(szFileName));
1.1 root 6923:
1.1.1.13 root 6924: try
6925: {
6926: BootEncObj = new BootEncryption (NULL);
6927: }
6928: catch (Exception &e)
6929: {
6930: e.Show (NULL);
6931: }
1.1 root 6932:
1.1.1.13 root 6933: if (BootEncObj == NULL)
6934: AbortProcess ("INIT_SYS_ENC");
1.1 root 6935:
1.1.1.11 root 6936: InitCommonControls ();
6937: InitApp (hInstance, lpszCommandLine);
1.1 root 6938:
1.1.1.7 root 6939: RegisterRedTick(hInstance);
6940:
6941: /* Allocate, dup, then store away the application title */
6942: lpszTitle = L"TrueCrypt";
6943:
1.1 root 6944: status = DriverAttach ();
6945: if (status != 0)
6946: {
6947: if (status == ERR_OS_ERROR)
6948: handleWin32Error (NULL);
6949: else
6950: handleError (NULL, status);
6951:
1.1.1.7 root 6952: AbortProcess ("NODRIVER");
1.1 root 6953: }
6954:
6955: /* Create the main dialog box */
1.1.1.7 root 6956: DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1.1 root 6957: (LPARAM) lpszCommandLine);
6958:
6959: /* Terminate */
6960: return 0;
6961: }
1.1.1.6 root 6962:
1.1.1.7 root 6963:
6964: BOOL TaskBarIconAdd (HWND hwnd)
6965: {
6966: BOOL res;
6967: NOTIFYICONDATAW tnid;
6968:
6969: // Only one icon may be created
6970: if (TaskBarIconMutex != NULL) return TRUE;
6971:
6972: TaskBarIconMutex = CreateMutex (NULL, TRUE, "TrueCryptTaskBarIcon");
6973: if (TaskBarIconMutex == NULL || GetLastError () == ERROR_ALREADY_EXISTS)
6974: {
6975: TaskBarIconMutex = NULL;
6976: return FALSE;
6977: }
6978:
6979: tnid.cbSize = sizeof (NOTIFYICONDATAW);
6980: tnid.hWnd = hwnd;
6981: tnid.uID = IDI_TRUECRYPT_ICON;
6982: tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
1.1.1.13 root 6983: tnid.uCallbackMessage = TC_APPMSG_TASKBAR_ICON;
6984: tnid.hIcon = (HICON) LoadImage (hInst, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON),
1.1.1.12 root 6985: IMAGE_ICON,
6986: ScreenDPI >= 120 ? 0 : 16,
6987: ScreenDPI >= 120 ? 0 : 16,
6988: (ScreenDPI >= 120 ? LR_DEFAULTSIZE : 0)
6989: | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
6990:
1.1.1.7 root 6991: wcscpy (tnid.szTip, L"TrueCrypt");
6992:
6993: res = Shell_NotifyIconW (NIM_ADD, &tnid);
6994:
6995: if (tnid.hIcon)
6996: DestroyIcon (tnid.hIcon);
6997:
6998: return res;
6999: }
7000:
7001:
7002: BOOL TaskBarIconRemove (HWND hwnd)
7003: {
7004: if (TaskBarIconMutex != NULL)
7005: {
7006: NOTIFYICONDATA tnid;
7007: BOOL res;
7008:
7009: ZeroMemory (&tnid, sizeof (tnid));
7010: tnid.cbSize = sizeof(NOTIFYICONDATA);
7011: tnid.hWnd = hwnd;
7012: tnid.uID = IDI_TRUECRYPT_ICON;
7013:
7014: res = Shell_NotifyIcon (NIM_DELETE, &tnid);
7015: if (TaskBarIconMutex)
7016: {
7017: CloseHandle (TaskBarIconMutex);
7018: TaskBarIconMutex = NULL;
7019: }
7020: return res;
7021: }
7022: else
7023: return FALSE;
7024: }
7025:
7026:
7027: void DismountIdleVolumes ()
7028: {
1.1.1.13 root 7029: static DWORD lastMinTickCount;
1.1.1.7 root 7030: static int InactivityTime[26];
7031: static unsigned __int64 LastRead[26], LastWritten[26];
7032: static int LastId[26];
7033:
7034: VOLUME_PROPERTIES_STRUCT prop;
7035: DWORD dwResult;
7036: BOOL bResult;
7037: int i;
7038:
1.1.1.13 root 7039: if (GetTickCount() > lastMinTickCount && GetTickCount() - lastMinTickCount < 60 * 1000)
7040: return;
7041:
7042: lastMinTickCount = GetTickCount();
1.1.1.7 root 7043:
7044: for (i = 0; i < 26; i++)
7045: {
7046: if (LastKnownMountList.ulMountedDrives & (1 << i))
7047: {
7048: memset (&prop, 0, sizeof(prop));
7049: prop.driveNo = i;
7050:
1.1.1.13 root 7051: bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop,
1.1.1.7 root 7052: sizeof (prop), &prop, sizeof (prop), &dwResult, NULL);
7053:
7054: if (bResult)
7055: {
7056: if (LastRead[i] == prop.totalBytesRead
7057: && LastWritten[i] == prop.totalBytesWritten
7058: && LastId[i] == prop.uniqueId)
7059: {
7060: if (++InactivityTime[i] >= MaxVolumeIdleTime)
7061: {
1.1.1.11 root 7062: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, i, 0);
7063:
1.1.1.7 root 7064: if (bCloseDismountedWindows && CloseVolumeExplorerWindows (MainDlg, i))
7065: Sleep (250);
7066:
7067: if (DriverUnmountVolume (MainDlg, i, bForceAutoDismount) == 0)
7068: {
7069: InactivityTime[i] = 0;
7070: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i, 0);
7071:
7072: if (bWipeCacheOnAutoDismount)
1.1.1.19 root 7073: {
1.1.1.13 root 7074: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 7075: SecurityToken::CloseAllSessions();
7076: }
1.1.1.7 root 7077: }
7078: }
7079: }
7080: else
7081: {
7082: InactivityTime[i] = 0;
7083: LastRead[i] = prop.totalBytesRead;
7084: LastWritten[i] = prop.totalBytesWritten;
7085: LastId[i] = prop.uniqueId;
7086: }
7087: }
7088: }
7089: }
7090: }
7091:
7092:
1.1.1.25! root 7093: BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
1.1.1.7 root 7094: {
7095: BOOL status = TRUE;
1.1.1.25! root 7096: BOOL lastbExplore;
1.1.1.7 root 7097:
1.1.1.11 root 7098: mountOptions = defaultMountOptions;
7099:
1.1.1.23 root 7100: VolumePassword.Length = 0;
1.1.1.19 root 7101: MultipleMountOperationInProgress = TRUE;
7102:
1.1.1.25! root 7103: vector <FavoriteVolume> favorites;
! 7104:
! 7105: if (systemFavorites)
! 7106: {
! 7107: try
! 7108: {
! 7109: LoadFavoriteVolumes (favorites, true);
! 7110: }
! 7111: catch (...)
! 7112: {
! 7113: return false;
! 7114: }
! 7115: }
! 7116: else if (!favoriteVolumeToMount.Path.empty())
! 7117: favorites.push_back (favoriteVolumeToMount);
! 7118: else
! 7119: favorites = FavoriteVolumes;
! 7120:
! 7121: foreach (const FavoriteVolume &favorite, favorites)
1.1.1.7 root 7122: {
1.1.1.25! root 7123: if (favorite.DisconnectedDevice
! 7124: || (logOnMount && !favorite.MountOnLogOn)
! 7125: || (hotKeyMount && favorite.DisableHotkeyMount))
! 7126: {
! 7127: continue;
! 7128: }
! 7129:
1.1.1.7 root 7130: int drive;
1.1.1.25! root 7131: drive = toupper (favorite.MountPoint[0]) - 'A';
! 7132:
! 7133: mountOptions.ReadOnly = favorite.ReadOnly;
! 7134: mountOptions.Removable = favorite.Removable;
1.1.1.21 root 7135:
1.1.1.25! root 7136: if (favorite.SystemEncryption)
1.1.1.23 root 7137: {
7138: mountOptions.PartitionInInactiveSysEncScope = TRUE;
7139: bPrebootPasswordDlgMode = TRUE;
7140: }
7141: else
7142: {
7143: mountOptions.PartitionInInactiveSysEncScope = FALSE;
7144: bPrebootPasswordDlgMode = FALSE;
7145: }
7146:
1.1.1.25! root 7147: if ((LastKnownMountList.ulMountedDrives & (1 << drive)) == 0)
1.1.1.23 root 7148: {
1.1.1.25! root 7149: MountVolumesAsSystemFavorite = systemFavorites;
! 7150:
! 7151: string mountPoint = (char) (drive + 'A') + string (":\\");
! 7152: char prevVolumeAtMountPoint[MAX_PATH] = { 0 };
! 7153:
! 7154: if (systemFavorites)
1.1.1.23 root 7155: {
1.1.1.25! root 7156: // Partitions of new drives are assigned free drive letters by Windows on boot. Make sure this does not prevent system favorite volumes
! 7157: // from being mounted. Each partition (using the same drive letter as a system favorite volume) is assigned another free drive letter.
! 7158:
! 7159: if (GetVolumeNameForVolumeMountPoint (mountPoint.c_str(), prevVolumeAtMountPoint, sizeof (prevVolumeAtMountPoint)))
! 7160: DeleteVolumeMountPoint (mountPoint.c_str());
! 7161: else
! 7162: prevVolumeAtMountPoint[0] = 0;
! 7163: }
! 7164:
! 7165: lastbExplore = bExplore;
! 7166:
! 7167: bExplore = (BOOL) favorite.OpenExplorerWindow;
! 7168:
! 7169: if (!Mount (MainDlg, drive, (char *) favorite.Path.c_str()))
! 7170: status = FALSE;
! 7171:
! 7172: bExplore = lastbExplore;
! 7173:
! 7174: if (systemFavorites && prevVolumeAtMountPoint[0])
! 7175: {
! 7176: if (status)
1.1.1.23 root 7177: {
1.1.1.25! root 7178: int freeDrive = GetFirstAvailableDrive();
! 7179: if (freeDrive != -1)
1.1.1.23 root 7180: {
1.1.1.25! root 7181: mountPoint[0] = (char) (freeDrive + 'A');
! 7182: SetVolumeMountPoint (mountPoint.c_str(), prevVolumeAtMountPoint);
1.1.1.23 root 7183: }
7184: }
1.1.1.25! root 7185: else
! 7186: SetVolumeMountPoint (mountPoint.c_str(), prevVolumeAtMountPoint);
1.1.1.23 root 7187: }
7188:
1.1.1.7 root 7189: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.23 root 7190:
7191: MountVolumesAsSystemFavorite = FALSE;
7192:
7193: if (ServiceMode && LastMountedVolumeDirty)
7194: {
7195: DWORD bytesOut;
7196: DeviceIoControl (hDriver, TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY, NULL, 0, NULL, 0, &bytesOut, NULL);
7197:
7198: SystemFavoritesServiceLogError (string ("The filesystem of the volume mounted as ") + (char) (drive + 'A') + ": was not cleanly dismounted and needs to be checked for errors.");
7199: }
1.1.1.7 root 7200: }
7201: }
7202:
1.1.1.19 root 7203: MultipleMountOperationInProgress = FALSE;
1.1.1.23 root 7204: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.19 root 7205:
7206: if (status && CloseSecurityTokenSessionsAfterMount)
7207: SecurityToken::CloseAllSessions();
7208:
1.1.1.7 root 7209: return status;
7210: }
7211:
7212:
7213: static void SaveDefaultKeyFilesParam (void)
7214: {
7215: if (defaultKeyFilesParam.FirstKeyFile == NULL)
7216: {
7217: /* No keyfiles selected */
1.1.1.19 root 7218: remove (GetConfigPath (TC_APPD_FILENAME_DEFAULT_KEYFILES));
1.1.1.7 root 7219: }
7220: else
7221: {
7222: FILE *f;
7223: KeyFile *kf = FirstKeyFile;
7224:
1.1.1.19 root 7225: f = fopen (GetConfigPath (TC_APPD_FILENAME_DEFAULT_KEYFILES), "w");
1.1.1.7 root 7226: if (f == NULL)
7227: {
7228: handleWin32Error (MainDlg);
7229: return;
7230: }
7231:
7232: XmlWriteHeader (f);
7233:
7234: fputs ("\n\t<defaultkeyfiles>", f);
7235:
7236: while (kf != NULL)
7237: {
1.1.1.11 root 7238: char q[TC_MAX_PATH * 2];
7239:
7240: XmlQuoteText (kf->FileName, q, sizeof (q));
7241: fprintf (f, "\n\t\t<keyfile>%s</keyfile>", q);
7242:
1.1.1.7 root 7243: kf = kf->Next;
7244: }
7245:
7246: fputs ("\n\t</defaultkeyfiles>", f);
7247:
7248: XmlWriteFooter (f);
7249:
1.1.1.25! root 7250: CheckFileStreamWriteErrors (f, TC_APPD_FILENAME_DEFAULT_KEYFILES);
1.1.1.7 root 7251: fclose (f);
7252: return;
7253: }
7254: }
7255:
7256:
7257: static void KeyfileDefaultsDlg (HWND hwndDlg)
7258: {
7259: KeyFilesDlgParam param;
7260:
7261: param.EnableKeyFiles = defaultKeyFilesParam.EnableKeyFiles;
7262: param.FirstKeyFile = defaultKeyFilesParam.FirstKeyFile;
7263:
7264: if (DialogBoxParamW (hInst,
7265: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
7266: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m) == IDOK)
7267: {
1.1.1.13 root 7268: if (!param.EnableKeyFiles || AskWarnYesNo ("CONFIRM_SAVE_DEFAULT_KEYFILES") == IDYES)
1.1.1.7 root 7269: {
7270: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
7271: defaultKeyFilesParam.EnableKeyFiles = param.EnableKeyFiles;
7272: defaultKeyFilesParam.FirstKeyFile = param.FirstKeyFile;
7273:
7274: RestoreDefaultKeyFilesParam ();
7275: SaveDefaultKeyFilesParam ();
7276: }
7277: }
7278: }
7279:
7280:
7281: static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
7282: {
7283: DWORD dwResult;
7284: BOOL success = TRUE;
7285:
7286: switch (wParam)
7287: {
7288: case HK_AUTOMOUNT_DEVICES:
7289: MountAllDevices (hwndDlg, TRUE);
7290:
7291: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7292: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7293:
7294: break;
7295:
7296: case HK_DISMOUNT_ALL:
1.1.1.21 root 7297: case HK_DISMOUNT_ALL_AND_WIPE:
7298:
7299: if (wParam == HK_DISMOUNT_ALL_AND_WIPE)
7300: WipeCache (hwndDlg, TRUE);
7301:
1.1.1.12 root 7302: if (DismountAll (hwndDlg, FALSE, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && bDisplayMsgBoxOnHotkeyDismount)
1.1.1.21 root 7303: InfoTopMost (wParam == HK_DISMOUNT_ALL_AND_WIPE ? "VOLUMES_DISMOUNTED_CACHE_WIPED" : "MOUNTED_VOLUMES_DISMOUNTED");
1.1.1.12 root 7304: else if (bDisplayMsgBoxOnHotkeyDismount)
1.1.1.21 root 7305: InfoTopMost (wParam == HK_DISMOUNT_ALL_AND_WIPE ? "PASSWORD_CACHE_WIPED" : "DISMOUNT_ALL_ATTEMPT_COMPLETED");
1.1.1.7 root 7306:
1.1.1.12 root 7307: if (!bDisplayMsgBoxOnHotkeyDismount && bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7308: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7309:
7310: break;
7311:
1.1.1.11 root 7312: case HK_WIPE_CACHE:
1.1.1.21 root 7313: WipeCache (hwndDlg, FALSE);
1.1.1.11 root 7314: break;
7315:
1.1.1.7 root 7316: case HK_FORCE_DISMOUNT_ALL_AND_WIPE:
7317: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13 root 7318: success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7 root 7319: if (success)
7320: {
7321: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7322: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7323:
7324: if (bDisplayMsgBoxOnHotkeyDismount)
1.1.1.20 root 7325: InfoTopMost ("VOLUMES_DISMOUNTED_CACHE_WIPED");
1.1.1.7 root 7326: }
7327: break;
7328:
7329: case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT:
7330: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13 root 7331: success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7 root 7332: if (success)
7333: {
7334: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7335: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7336:
7337: if (bDisplayMsgBoxOnHotkeyDismount)
1.1.1.20 root 7338: InfoTopMost ("VOLUMES_DISMOUNTED_CACHE_WIPED");
1.1.1.7 root 7339: }
7340: TaskBarIconRemove (hwndDlg);
7341: EndMainDlg (hwndDlg);
7342: break;
7343:
7344: case HK_MOUNT_FAVORITE_VOLUMES:
1.1.1.25! root 7345: MountFavoriteVolumes (FALSE, FALSE, TRUE);
1.1.1.7 root 7346:
7347: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7348: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7349:
7350: break;
7351:
7352: case HK_SHOW_HIDE_MAIN_WINDOW:
1.1.1.13 root 7353: ChangeMainWindowVisibility ();
1.1.1.7 root 7354: break;
1.1.1.21 root 7355:
7356: case HK_CLOSE_SECURITY_TOKEN_SESSIONS:
1.1.1.23 root 7357: SecurityToken::CloseAllSessions();
7358: InfoTopMost ("ALL_TOKEN_SESSIONS_CLOSED");
1.1.1.21 root 7359: break;
1.1.1.7 root 7360: }
1.1.1.13 root 7361: }
7362:
7363:
7364: void ChangeMainWindowVisibility ()
7365: {
7366: MainWindowHidden = !MainWindowHidden;
7367:
7368: if (!MainWindowHidden)
7369: SetForegroundWindow (MainDlg);
7370:
7371: ShowWindow (MainDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
7372:
7373: if (!MainWindowHidden)
7374: ShowWindow (MainDlg, SW_RESTORE);
1.1.1.17 root 7375: }
7376:
7377:
7378: int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume)
7379: {
7380: int nStatus = ERR_OS_ERROR;
7381: wchar_t szTmp[4096];
7382: int fBackup = -1;
7383: OpenVolumeContext volume;
7384: OpenVolumeContext hiddenVolume;
7385: Password hiddenVolPassword;
1.1.1.20 root 7386: byte temporaryKey[MASTER_KEYDATA_SIZE];
7387: byte originalK2[MASTER_KEYDATA_SIZE];
7388:
1.1.1.17 root 7389: volume.VolumeIsOpen = FALSE;
7390: hiddenVolume.VolumeIsOpen = FALSE;
7391:
7392: switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
7393: {
7394: case 1:
7395: case 2:
7396: if (AskErrNoYes ("BACKUP_HEADER_NOT_FOR_SYS_DEVICE") == IDYES)
7397: CreateRescueDisk ();
7398:
7399: return 0;
7400: }
7401:
7402: if (IsMountedVolume (lpszVolume))
7403: {
7404: Warning ("DISMOUNT_FIRST");
7405: goto ret;
7406: }
7407:
1.1.1.23 root 7408: if (!VolumePathExists (lpszVolume))
7409: {
7410: handleWin32Error (hwndDlg);
7411: goto ret;
7412: }
7413:
1.1.1.17 root 7414: Info ("EXTERNAL_VOL_HEADER_BAK_FIRST_INFO");
7415:
1.1.1.19 root 7416:
7417: WaitCursor();
7418:
1.1.1.17 root 7419: // Open both types of volumes
7420: for (int type = TC_VOLUME_TYPE_NORMAL; type <= TC_VOLUME_TYPE_HIDDEN; ++type)
7421: {
7422: OpenVolumeContext *askVol = (type == TC_VOLUME_TYPE_HIDDEN ? &hiddenVolume : &volume);
7423: Password *askPassword = (type == TC_VOLUME_TYPE_HIDDEN ? &hiddenVolPassword : &VolumePassword);
7424:
7425: while (TRUE)
7426: {
7427: if (!AskVolumePassword (hwndDlg, askPassword, type == TC_VOLUME_TYPE_HIDDEN ? "ENTER_HIDDEN_VOL_PASSWORD" : "ENTER_NORMAL_VOL_PASSWORD", FALSE))
7428: {
7429: nStatus = ERR_SUCCESS;
7430: goto ret;
7431: }
7432:
1.1.1.19 root 7433: WaitCursor();
7434:
1.1.1.17 root 7435: if (KeyFilesEnable && FirstKeyFile)
1.1.1.19 root 7436: KeyFilesApply (askPassword, FirstKeyFile);
1.1.1.17 root 7437:
7438: nStatus = OpenVolume (askVol, lpszVolume, askPassword, FALSE, bPreserveTimestamp, FALSE);
1.1.1.19 root 7439:
7440: NormalCursor();
7441:
1.1.1.17 root 7442: if (nStatus == ERR_SUCCESS)
7443: {
7444: if ((type == TC_VOLUME_TYPE_NORMAL && askVol->CryptoInfo->hiddenVolume)
7445: || (type == TC_VOLUME_TYPE_HIDDEN && !askVol->CryptoInfo->hiddenVolume))
7446: {
7447: CloseVolume (askVol);
7448: handleError (hwndDlg, ERR_PASSWORD_WRONG);
7449: continue;
7450: }
7451:
7452: RandSetHashFunction (askVol->CryptoInfo->pkcs5);
7453:
7454: if (type == TC_VOLUME_TYPE_NORMAL)
7455: {
7456: // Ask the user if there is a hidden volume
7457: char *volTypeChoices[] = {0, "DOES_VOLUME_CONTAIN_HIDDEN", "VOLUME_CONTAINS_HIDDEN", "VOLUME_DOES_NOT_CONTAIN_HIDDEN", "IDCANCEL", 0};
1.1.1.19 root 7458: switch (AskMultiChoice ((void **) volTypeChoices, FALSE))
1.1.1.17 root 7459: {
7460: case 1:
7461: break;
7462: case 2:
7463: goto noHidden;
7464:
7465: default:
7466: nStatus = ERR_SUCCESS;
7467: goto ret;
7468: }
7469: }
7470:
7471: break;
7472: }
7473:
7474: if (nStatus != ERR_PASSWORD_WRONG)
7475: goto error;
7476:
7477: handleError (hwndDlg, nStatus);
7478: }
7479: }
7480: noHidden:
7481:
7482: if (hiddenVolume.VolumeIsOpen && volume.CryptoInfo->LegacyVolume != hiddenVolume.CryptoInfo->LegacyVolume)
7483: {
7484: nStatus = ERR_PARAMETER_INCORRECT;
7485: goto error;
7486: }
7487:
7488: swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume);
7489:
7490: if (bRequireConfirmation
7491: && (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO))
7492: goto ret;
7493:
7494: /* Select backup file */
1.1.1.19 root 7495: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, TRUE, NULL))
1.1.1.17 root 7496: goto ret;
7497:
7498: /* Conceive the backup file */
7499: if ((fBackup = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
7500: {
7501: nStatus = ERR_OS_ERROR;
7502: goto error;
7503: }
7504:
7505: // Backup headers
7506:
7507: byte backup[TC_VOLUME_HEADER_GROUP_SIZE];
7508:
7509: bool legacyVolume = volume.CryptoInfo->LegacyVolume ? true : false;
7510: int backupFileSize = legacyVolume ? TC_VOLUME_HEADER_SIZE_LEGACY * 2 : TC_VOLUME_HEADER_GROUP_SIZE;
7511:
7512: // Fill backup buffer with random data
7513: memcpy (originalK2, volume.CryptoInfo->k2, sizeof (volume.CryptoInfo->k2));
7514:
7515: if (Randinit() != ERR_SUCCESS)
7516: {
7517: nStatus = ERR_PARAMETER_INCORRECT;
7518: goto error;
7519: }
7520:
1.1.1.21 root 7521: NormalCursor();
7522: UserEnrichRandomPool (hwndDlg);
7523: WaitCursor();
7524:
1.1.1.17 root 7525: // Temporary keys
7526: if (!RandgetBytes (temporaryKey, EAGetKeySize (volume.CryptoInfo->ea), TRUE)
7527: || !RandgetBytes (volume.CryptoInfo->k2, sizeof (volume.CryptoInfo->k2), FALSE))
7528: {
7529: nStatus = ERR_PARAMETER_INCORRECT;
7530: goto error;
7531: }
7532:
7533: if (EAInit (volume.CryptoInfo->ea, temporaryKey, volume.CryptoInfo->ks) != ERR_SUCCESS || !EAInitMode (volume.CryptoInfo))
7534: {
7535: nStatus = ERR_PARAMETER_INCORRECT;
7536: goto error;
7537: }
7538:
7539: EncryptBuffer (backup, backupFileSize, volume.CryptoInfo);
7540:
7541: memcpy (volume.CryptoInfo->k2, originalK2, sizeof (volume.CryptoInfo->k2));
7542: if (EAInit (volume.CryptoInfo->ea, volume.CryptoInfo->master_keydata, volume.CryptoInfo->ks) != ERR_SUCCESS || !EAInitMode (volume.CryptoInfo))
7543: {
7544: nStatus = ERR_PARAMETER_INCORRECT;
7545: goto error;
7546: }
7547:
7548: // Store header encrypted with a new key
7549: nStatus = ReEncryptVolumeHeader ((char *) backup, FALSE, volume.CryptoInfo, &VolumePassword, FALSE);
7550: if (nStatus != ERR_SUCCESS)
7551: goto error;
7552:
7553: if (hiddenVolume.VolumeIsOpen)
7554: {
7555: nStatus = ReEncryptVolumeHeader ((char *) backup + (legacyVolume ? TC_VOLUME_HEADER_SIZE_LEGACY : TC_VOLUME_HEADER_SIZE),
7556: FALSE, hiddenVolume.CryptoInfo, &hiddenVolPassword, FALSE);
7557:
7558: if (nStatus != ERR_SUCCESS)
7559: goto error;
7560: }
7561:
7562: if (_write (fBackup, backup, backupFileSize) == -1)
7563: {
7564: nStatus = ERR_OS_ERROR;
7565: goto error;
7566: }
7567:
7568: /* Backup has been successfully created */
7569: Warning("VOL_HEADER_BACKED_UP");
7570:
7571: ret:
7572: nStatus = ERR_SUCCESS;
7573:
7574: error:
7575: DWORD dwError = GetLastError ();
7576:
7577: CloseVolume (&volume);
7578: CloseVolume (&hiddenVolume);
7579:
7580: if (fBackup != -1)
7581: _close (fBackup);
7582:
7583: SetLastError (dwError);
7584: if (nStatus != 0)
7585: handleError (hwndDlg, nStatus);
7586:
7587: burn (&VolumePassword, sizeof (VolumePassword));
7588: burn (&hiddenVolPassword, sizeof (hiddenVolPassword));
1.1.1.20 root 7589: burn (temporaryKey, sizeof (temporaryKey));
7590: burn (originalK2, sizeof (originalK2));
1.1.1.17 root 7591:
1.1.1.19 root 7592: RestoreDefaultKeyFilesParam();
1.1.1.21 root 7593: RandStop (FALSE);
1.1.1.19 root 7594: NormalCursor();
7595:
1.1.1.17 root 7596: return nStatus;
7597: }
7598:
7599:
7600: int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
7601: {
7602: int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR;
7603: char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
7604: char szFileName[TC_MAX_PATH];
7605: char szDosDevice[TC_MAX_PATH];
7606: void *dev = INVALID_HANDLE_VALUE;
7607: DWORD dwError;
7608: BOOL bDevice;
7609: unsigned __int64 hostSize = 0;
7610: FILETIME ftCreationTime;
7611: FILETIME ftLastWriteTime;
7612: FILETIME ftLastAccessTime;
7613: wchar_t szTmp[4096];
7614: BOOL bTimeStampValid = FALSE;
7615: HANDLE fBackup = INVALID_HANDLE_VALUE;
7616: LARGE_INTEGER headerOffset;
7617: CRYPTO_INFO *restoredCryptoInfo = NULL;
7618:
7619: switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
7620: {
7621: case 1:
7622: case 2:
7623: if (AskErrNoYes ("RESTORE_HEADER_NOT_FOR_SYS_DEVICE") == IDYES)
7624: CreateRescueDisk ();
7625:
7626: return 0;
7627:
7628: case -1:
1.1.1.19 root 7629: // In some environments (such as PE), the system volume is not located on a hard drive.
7630: // Therefore, we must interpret this return code as "Not a system device path" (otherwise,
7631: // it would not be possible to restore headers on non-system devices in such environments).
7632: // Note that this is rather safe, because bReliableRequired is set to TRUE.
7633:
7634: // NOP
7635: break;
1.1.1.17 root 7636: }
7637:
7638: if (IsMountedVolume (lpszVolume))
7639: {
7640: Warning ("DISMOUNT_FIRST");
7641: return 0;
7642: }
7643:
1.1.1.23 root 7644: if (!VolumePathExists (lpszVolume))
7645: {
7646: handleWin32Error (hwndDlg);
7647: return 0;
7648: }
7649:
1.1.1.17 root 7650: BOOL restoreInternalBackup;
7651:
7652: // Ask the user to select the type of backup (internal/external)
7653: char *volTypeChoices[] = {0, "HEADER_RESTORE_EXTERNAL_INTERNAL", "HEADER_RESTORE_INTERNAL", "HEADER_RESTORE_EXTERNAL", "IDCANCEL", 0};
1.1.1.19 root 7654: switch (AskMultiChoice ((void **) volTypeChoices, FALSE))
1.1.1.17 root 7655: {
7656: case 1:
7657: restoreInternalBackup = TRUE;
7658: break;
7659: case 2:
7660: restoreInternalBackup = FALSE;
7661: break;
7662: default:
7663: return 0;
7664: }
7665:
7666: OpenVolumeContext volume;
7667: volume.VolumeIsOpen = FALSE;
7668:
1.1.1.19 root 7669: WaitCursor();
7670:
1.1.1.17 root 7671: if (restoreInternalBackup)
7672: {
7673: // Restore header from the internal backup
7674:
7675: // Open the volume using backup header
7676: while (TRUE)
7677: {
7678: strncpy (PasswordDlgVolume, lpszVolume, sizeof (PasswordDlgVolume));
7679: if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, FALSE))
7680: {
7681: nStatus = ERR_SUCCESS;
7682: goto ret;
7683: }
7684:
1.1.1.19 root 7685: WaitCursor();
7686:
1.1.1.17 root 7687: if (KeyFilesEnable && FirstKeyFile)
7688: KeyFilesApply (&VolumePassword, FirstKeyFile);
7689:
7690: nStatus = OpenVolume (&volume, lpszVolume, &VolumePassword, TRUE, bPreserveTimestamp, TRUE);
1.1.1.19 root 7691:
7692: NormalCursor();
7693:
1.1.1.17 root 7694: if (nStatus == ERR_SUCCESS)
7695: break;
7696:
7697: if (nStatus != ERR_PASSWORD_WRONG)
7698: goto error;
7699:
7700: handleError (hwndDlg, nStatus);
7701: }
7702:
7703: if (volume.CryptoInfo->LegacyVolume)
7704: {
7705: Error ("VOLUME_HAS_NO_BACKUP_HEADER");
7706: nStatus = ERROR_SUCCESS;
7707: goto error;
7708: }
7709:
7710: // Create a new header with a new salt
7711: char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
7712:
7713: nStatus = ReEncryptVolumeHeader (buffer, FALSE, volume.CryptoInfo, &VolumePassword, FALSE);
7714: if (nStatus != 0)
7715: goto error;
7716:
7717: headerOffset.QuadPart = volume.CryptoInfo->hiddenVolume ? TC_HIDDEN_VOLUME_HEADER_OFFSET : TC_VOLUME_HEADER_OFFSET;
7718: if (!SetFilePointerEx (volume.HostFileHandle, headerOffset, NULL, FILE_BEGIN))
7719: {
7720: nStatus = ERR_OS_ERROR;
7721: goto error;
7722: }
7723:
1.1.1.25! root 7724: if (!WriteEffectiveVolumeHeader (volume.IsDevice, volume.HostFileHandle, (byte *) buffer))
1.1.1.17 root 7725: {
7726: nStatus = ERR_OS_ERROR;
7727: goto error;
7728: }
7729: }
7730: else
7731: {
7732: // Restore header from an external backup
7733:
7734: swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume);
7735:
7736: if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO)
7737: {
7738: nStatus = ERR_SUCCESS;
7739: goto ret;
7740: }
7741:
7742: /* Select backup file */
1.1.1.19 root 7743: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, FALSE, NULL))
1.1.1.17 root 7744: {
7745: nStatus = ERR_SUCCESS;
7746: goto ret;
7747: }
7748:
7749: /* Open the backup file */
7750: fBackup = CreateFile (szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7751: if (fBackup == INVALID_HANDLE_VALUE)
7752: {
7753: nStatus = ERR_OS_ERROR;
7754: goto error;
7755: }
7756:
7757: // Determine size of the backup file
7758: LARGE_INTEGER backupSize;
7759: if (!GetFileSizeEx (fBackup, &backupSize))
7760: {
7761: nStatus = ERR_OS_ERROR;
7762: goto error;
7763: }
7764:
7765: CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice);
7766:
7767: if (bDevice == FALSE)
7768: strcpy (szCFDevice, szDiskFile);
7769: else
7770: {
7771: nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE);
7772: if (nDosLinkCreated != 0)
7773: goto error;
7774: }
7775:
7776: // Open the volume
7777: dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7778:
7779: if (dev == INVALID_HANDLE_VALUE)
7780: {
7781: nStatus = ERR_OS_ERROR;
7782: goto error;
7783: }
7784:
7785: // Determine volume host size
7786: if (bDevice)
7787: {
7788: PARTITION_INFORMATION diskInfo;
7789: DWORD dwResult;
7790: BOOL bResult;
7791:
7792: bResult = GetPartitionInfo (lpszVolume, &diskInfo);
7793:
7794: if (bResult)
7795: {
7796: hostSize = diskInfo.PartitionLength.QuadPart;
7797: }
7798: else
7799: {
7800: DISK_GEOMETRY driveInfo;
7801:
7802: bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
7803: &driveInfo, sizeof (driveInfo), &dwResult, NULL);
7804:
7805: if (!bResult)
7806: goto error;
7807:
7808: hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
7809: driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
7810: }
7811:
7812: if (hostSize == 0)
7813: {
7814: nStatus = ERR_VOL_SIZE_WRONG;
7815: goto error;
7816: }
7817: }
7818: else
7819: {
7820: LARGE_INTEGER fileSize;
7821: if (!GetFileSizeEx (dev, &fileSize))
7822: {
7823: nStatus = ERR_OS_ERROR;
7824: goto error;
7825: }
7826:
7827: hostSize = fileSize.QuadPart;
7828: }
7829:
7830: if (!bDevice && bPreserveTimestamp)
7831: {
7832: /* Remember the container modification/creation date and time. */
7833:
7834: if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
7835: bTimeStampValid = FALSE;
7836: else
7837: bTimeStampValid = TRUE;
7838: }
7839:
7840: /* Read the volume header from the backup file */
7841: char buffer[TC_VOLUME_HEADER_GROUP_SIZE];
7842:
7843: DWORD bytesRead;
7844: if (!ReadFile (fBackup, buffer, sizeof (buffer), &bytesRead, NULL))
7845: {
7846: nStatus = ERR_OS_ERROR;
7847: goto error;
7848: }
7849:
7850: if (bytesRead != backupSize.QuadPart)
7851: {
7852: nStatus = ERR_VOL_SIZE_WRONG;
7853: goto error;
7854: }
7855:
7856: LARGE_INTEGER headerOffset;
7857: LARGE_INTEGER headerBackupOffset;
7858: bool legacyBackup;
7859: int headerOffsetBackupFile;
7860:
7861: // Determine the format of the backup file
7862: switch (backupSize.QuadPart)
7863: {
7864: case TC_VOLUME_HEADER_GROUP_SIZE:
7865: legacyBackup = false;
7866: break;
7867:
7868: case TC_VOLUME_HEADER_SIZE_LEGACY * 2:
7869: legacyBackup = true;
7870: break;
7871:
7872: default:
7873: Error ("HEADER_BACKUP_SIZE_INCORRECT");
7874: nStatus = ERR_SUCCESS;
7875: goto error;
7876: }
7877:
7878: // Open the header
7879: while (TRUE)
7880: {
7881: if (!AskVolumePassword (hwndDlg, &VolumePassword, "ENTER_HEADER_BACKUP_PASSWORD", FALSE))
7882: {
7883: nStatus = ERR_SUCCESS;
7884: goto ret;
7885: }
7886:
7887: if (KeyFilesEnable && FirstKeyFile)
7888: KeyFilesApply (&VolumePassword, FirstKeyFile);
7889:
7890: // Decrypt volume header
7891: headerOffsetBackupFile = 0;
7892: for (int type = TC_VOLUME_TYPE_NORMAL; type <= TC_VOLUME_TYPE_HIDDEN; ++type)
7893: {
7894: if (type == TC_VOLUME_TYPE_HIDDEN)
7895: headerOffsetBackupFile += (legacyBackup ? TC_VOLUME_HEADER_SIZE_LEGACY : TC_VOLUME_HEADER_SIZE);
7896:
1.1.1.19 root 7897: nStatus = ReadVolumeHeader (FALSE, buffer + headerOffsetBackupFile, &VolumePassword, &restoredCryptoInfo, NULL);
1.1.1.17 root 7898: if (nStatus == ERR_SUCCESS)
7899: break;
7900: }
7901:
7902: if (nStatus == ERR_SUCCESS)
7903: break;
7904:
7905: if (nStatus != ERR_PASSWORD_WRONG)
7906: goto error;
7907:
7908: handleError (hwndDlg, nStatus);
7909: }
7910:
7911: BOOL hiddenVol = restoredCryptoInfo->hiddenVolume;
7912:
7913: if (legacyBackup)
7914: {
7915: headerOffset.QuadPart = hiddenVol ? hostSize - TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY : TC_VOLUME_HEADER_OFFSET;
7916: }
7917: else
7918: {
7919: headerOffset.QuadPart = hiddenVol ? TC_HIDDEN_VOLUME_HEADER_OFFSET : TC_VOLUME_HEADER_OFFSET;
7920: headerBackupOffset.QuadPart = hiddenVol ? hostSize - TC_VOLUME_HEADER_SIZE : hostSize - TC_VOLUME_HEADER_GROUP_SIZE;
7921: }
7922:
7923: WaitCursor();
7924:
7925: // Restore header encrypted with a new key
7926: ReEncryptVolumeHeader (buffer, FALSE, restoredCryptoInfo, &VolumePassword, FALSE);
7927:
7928: if (!SetFilePointerEx (dev, headerOffset, NULL, FILE_BEGIN))
7929: {
7930: nStatus = ERR_OS_ERROR;
7931: goto error;
7932: }
7933:
1.1.1.25! root 7934: if (!WriteEffectiveVolumeHeader (bDevice, dev, (byte *) buffer))
1.1.1.17 root 7935: {
7936: nStatus = ERR_OS_ERROR;
7937: goto error;
7938: }
7939:
7940: if (!restoredCryptoInfo->LegacyVolume)
7941: {
7942: // Restore backup header encrypted with a new key
7943: ReEncryptVolumeHeader (buffer, FALSE, restoredCryptoInfo, &VolumePassword, FALSE);
7944:
7945: if (!SetFilePointerEx (dev, headerBackupOffset, NULL, FILE_BEGIN))
7946: {
7947: nStatus = ERR_OS_ERROR;
7948: goto error;
7949: }
7950:
1.1.1.25! root 7951: if (!WriteEffectiveVolumeHeader (bDevice, dev, (byte *) buffer))
1.1.1.17 root 7952: {
7953: nStatus = ERR_OS_ERROR;
7954: goto error;
7955: }
7956: }
7957: }
7958:
7959:
7960: /* Volume header has been successfully restored */
7961:
7962: Info("VOL_HEADER_RESTORED");
7963: ret:
7964: nStatus = ERR_SUCCESS;
7965:
7966: error:
7967: dwError = GetLastError ();
7968: NormalCursor();
7969:
7970: if (restoreInternalBackup)
7971: {
7972: CloseVolume (&volume);
7973: }
7974: else
7975: {
7976: if (restoredCryptoInfo)
7977: crypto_close (restoredCryptoInfo);
7978:
7979: if (bTimeStampValid)
1.1.1.24 root 7980: SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
1.1.1.17 root 7981:
7982: if (dev != INVALID_HANDLE_VALUE)
7983: CloseHandle (dev);
7984:
7985: if (fBackup != INVALID_HANDLE_VALUE)
7986: CloseHandle (fBackup);
7987:
7988: if (nDosLinkCreated == 0)
7989: RemoveFakeDosName (szDiskFile, szDosDevice);
7990: }
7991:
7992: SetLastError (dwError);
7993: if (nStatus != 0)
7994: handleError (hwndDlg, nStatus);
7995:
7996: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.19 root 7997: RestoreDefaultKeyFilesParam();
1.1.1.21 root 7998: RandStop (FALSE);
1.1.1.19 root 7999: NormalCursor();
1.1.1.21 root 8000:
1.1.1.17 root 8001: return nStatus;
8002: }
1.1.1.19 root 8003:
8004:
1.1.1.25! root 8005: void SetDriverConfigurationFlag (uint32 flag, BOOL state)
1.1.1.19 root 8006: {
1.1.1.25! root 8007: BootEncObj->SetDriverConfigurationFlag (flag, state ? true : false);
1.1.1.19 root 8008: }
8009:
8010:
1.1.1.25! root 8011: static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.19 root 8012: {
1.1.1.25! root 8013: WORD lw = LOWORD (wParam);
! 8014:
! 8015: switch (msg)
! 8016: {
! 8017: case WM_INITDIALOG:
! 8018: {
! 8019: LocalizeDialog (hwndDlg, "IDD_PERFORMANCE_SETTINGS");
! 8020:
! 8021: uint32 driverConfig = ReadDriverConfigurationFlags();
! 8022: CheckDlgButton (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION, (driverConfig & TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION) ? BST_UNCHECKED : BST_CHECKED);
! 8023:
! 8024: SYSTEM_INFO sysInfo;
! 8025: GetSystemInfo (&sysInfo);
! 8026:
! 8027: HWND freeCpuCombo = GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT);
! 8028: uint32 encryptionFreeCpuCount = ReadEncryptionThreadPoolFreeCpuCountLimit();
! 8029:
! 8030: if (encryptionFreeCpuCount > sysInfo.dwNumberOfProcessors - 1)
! 8031: encryptionFreeCpuCount = sysInfo.dwNumberOfProcessors - 1;
! 8032:
! 8033: for (uint32 i = 1; i < sysInfo.dwNumberOfProcessors; ++i)
! 8034: {
! 8035: stringstream s;
! 8036: s << i;
! 8037: AddComboPair (freeCpuCombo, s.str().c_str(), i);
! 8038: }
! 8039:
! 8040: if (sysInfo.dwNumberOfProcessors < 2 || encryptionFreeCpuCount == 0)
! 8041: EnableWindow (freeCpuCombo, FALSE);
! 8042:
! 8043: if (sysInfo.dwNumberOfProcessors < 2)
! 8044: EnableWindow (GetDlgItem (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL), FALSE);
! 8045:
! 8046: if (encryptionFreeCpuCount != 0)
! 8047: {
! 8048: CheckDlgButton (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL, BST_CHECKED);
! 8049: SendMessage (freeCpuCombo, CB_SETCURSEL, encryptionFreeCpuCount - 1, 0);
! 8050: }
! 8051:
! 8052: SetWindowTextW (GetDlgItem (hwndDlg, IDT_LIMIT_ENC_THREAD_POOL_NOTE), GetString("LIMIT_ENC_THREAD_POOL_NOTE"));
! 8053:
! 8054: SetDlgItemTextW (hwndDlg, IDC_HW_AES_SUPPORTED_BY_CPU, (wstring (L" ") + (GetString (is_aes_hw_cpu_supported() ? "UISTR_YES" : "UISTR_NO"))).c_str());
! 8055:
! 8056: ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_HW_ACCELERATION);
! 8057: ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_THREAD_BASED_PARALLELIZATION);
! 8058: }
! 8059: return 0;
! 8060:
! 8061: case WM_COMMAND:
! 8062:
! 8063: switch (lw)
! 8064: {
! 8065: case IDCANCEL:
! 8066: EndDialog (hwndDlg, lw);
! 8067: return 1;
! 8068:
! 8069: case IDOK:
! 8070: {
! 8071: BOOL disableHW = !IsDlgButtonChecked (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION);
! 8072:
! 8073: try
! 8074: {
! 8075: try
! 8076: {
! 8077: BootEncStatus = BootEncObj->GetStatus();
! 8078: }
! 8079: catch (...)
! 8080: {
! 8081: BootEncStatus.DriveMounted = false;
! 8082: }
! 8083:
! 8084: if (BootEncStatus.DriveMounted)
! 8085: {
! 8086: byte userConfig;
! 8087: string customUserMessage;
! 8088: uint16 bootLoaderVersion;
! 8089:
! 8090: BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig, &customUserMessage, &bootLoaderVersion);
! 8091:
! 8092: if (bootLoaderVersion != VERSION_NUM)
! 8093: Warning ("BOOT_LOADER_VERSION_INCORRECT_PREFERENCES");
! 8094:
! 8095: if (disableHW)
! 8096: userConfig |= TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION;
! 8097: else
! 8098: userConfig &= ~TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION;
! 8099:
! 8100: BootEncObj->WriteBootSectorUserConfig (userConfig, customUserMessage);
! 8101: }
! 8102:
! 8103: SetDriverConfigurationFlag (TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION, disableHW);
! 8104:
! 8105: DWORD bytesReturned;
! 8106: if (!DeviceIoControl (hDriver, TC_IOCTL_REREAD_DRIVER_CONFIG, NULL, 0, NULL, 0, &bytesReturned, NULL))
! 8107: handleWin32Error (hwndDlg);
! 8108:
! 8109: EnableHwEncryption (!disableHW);
! 8110:
! 8111: uint32 cpuFreeCount = 0;
! 8112: if (IsDlgButtonChecked (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL))
! 8113: {
! 8114: LRESULT cpuFreeItem = SendMessage (GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT), CB_GETCURSEL, 0, 0);
! 8115: if (cpuFreeItem != CB_ERR)
! 8116: cpuFreeCount = (uint32) (cpuFreeItem + 1);
! 8117: }
! 8118:
! 8119: if (ReadEncryptionThreadPoolFreeCpuCountLimit() != cpuFreeCount)
! 8120: {
! 8121: BootEncObj->WriteLocalMachineRegistryDwordValue ("SYSTEM\\CurrentControlSet\\Services\\truecrypt", TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME, cpuFreeCount);
! 8122: Warning ("SETTING_REQUIRES_REBOOT");
! 8123: }
! 8124:
! 8125: EndDialog (hwndDlg, lw);
! 8126: return 1;
! 8127: }
! 8128: catch (Exception &e)
! 8129: {
! 8130: e.Show (hwndDlg);
! 8131: }
! 8132: }
! 8133: return 1;
! 8134:
! 8135: case IDC_ENABLE_HARDWARE_ENCRYPTION:
! 8136: if (!IsDlgButtonChecked (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION)
! 8137: && AskWarnYesNo ("CONFIRM_SETTING_DEGRADES_PERFORMANCE") == IDNO)
! 8138: {
! 8139: CheckDlgButton (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION, BST_CHECKED);
! 8140: }
! 8141: return 1;
! 8142:
! 8143: case IDC_LIMIT_ENC_THREAD_POOL:
! 8144: if (IsDlgButtonChecked (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL)
! 8145: && AskWarnYesNo ("CONFIRM_SETTING_DEGRADES_PERFORMANCE") == IDNO)
! 8146: {
! 8147: CheckDlgButton (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL, BST_UNCHECKED);
! 8148: }
! 8149: else
! 8150: {
! 8151: SendMessage (GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT), CB_SETCURSEL, 0, 0);
! 8152: Warning ("SETTING_REQUIRES_REBOOT"); // Warn the user before he thinks about benchmarking
! 8153: }
! 8154:
! 8155: EnableWindow (GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT), IsDlgButtonChecked (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL));
! 8156: return 1;
! 8157:
! 8158: case IDC_BENCHMARK:
! 8159: Benchmark (hwndDlg);
! 8160: return 1;
! 8161:
! 8162: case IDC_MORE_INFO_ON_HW_ACCELERATION:
! 8163: Applink ("hwacceleration", TRUE, "");
! 8164: return 1;
! 8165:
! 8166: case IDC_MORE_INFO_ON_THREAD_BASED_PARALLELIZATION:
! 8167: Applink ("parallelization", TRUE, "");
! 8168: return 1;
! 8169: }
! 8170:
! 8171: return 0;
! 8172: }
! 8173:
! 8174: return 0;
1.1.1.19 root 8175: }
8176:
8177:
8178: static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
8179: {
8180: WORD lw = LOWORD (wParam);
8181:
8182: switch (msg)
8183: {
8184: case WM_INITDIALOG:
8185: LocalizeDialog (hwndDlg, "IDD_TOKEN_PREFERENCES");
8186: SetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, SecurityTokenLibraryPath);
8187: CheckDlgButton (hwndDlg, IDC_CLOSE_TOKEN_SESSION_AFTER_MOUNT, CloseSecurityTokenSessionsAfterMount ? BST_CHECKED : BST_UNCHECKED);
8188:
8189: SetWindowTextW (GetDlgItem (hwndDlg, IDT_PKCS11_LIB_HELP), GetString("PKCS11_LIB_LOCATION_HELP"));
8190:
8191: return 0;
8192:
8193: case WM_COMMAND:
8194:
8195: switch (lw)
8196: {
8197: case IDCANCEL:
8198: EndDialog (hwndDlg, lw);
8199: return 1;
8200:
8201: case IDOK:
8202: {
8203: char securityTokenLibraryPath[MAX_PATH];
8204: GetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, securityTokenLibraryPath, sizeof (securityTokenLibraryPath));
8205:
8206: if (securityTokenLibraryPath[0] == 0)
8207: {
8208: try
8209: {
8210: SecurityToken::CloseLibrary();
8211: }
8212: catch (...) { }
8213:
8214: SecurityTokenLibraryPath[0] = 0;
8215: }
8216: else
8217: {
8218: char prevSecurityTokenLibraryPath[MAX_PATH];
8219: strcpy (prevSecurityTokenLibraryPath, SecurityTokenLibraryPath);
8220: strcpy (SecurityTokenLibraryPath, securityTokenLibraryPath);
8221:
8222: if (!InitSecurityTokenLibrary())
8223: {
8224: strcpy (SecurityTokenLibraryPath, prevSecurityTokenLibraryPath);
8225: return 1;
8226: }
8227: }
8228:
1.1.1.20 root 8229: CloseSecurityTokenSessionsAfterMount = (IsDlgButtonChecked (hwndDlg, IDC_CLOSE_TOKEN_SESSION_AFTER_MOUNT) == BST_CHECKED);
8230:
1.1.1.19 root 8231: WaitCursor ();
8232: SaveSettings (hwndDlg);
8233: NormalCursor ();
8234:
8235: EndDialog (hwndDlg, lw);
8236: return 1;
8237: }
8238:
8239: case IDC_AUTO_DETECT_PKCS11_MODULE:
8240: {
8241: char systemDir[MAX_PATH];
8242: GetSystemDirectory (systemDir, sizeof (systemDir));
8243: WIN32_FIND_DATA findData;
8244: bool found = false;
8245:
8246: WaitCursor();
8247:
8248: HANDLE find = FindFirstFile ((string (systemDir) + "\\*.dll").c_str(), &findData);
8249: while (!found && find != INVALID_HANDLE_VALUE)
8250: {
8251: string dllPathname = string (systemDir) + "\\" + findData.cFileName;
8252: DWORD fileSize;
8253:
8254: char *file = LoadFile (dllPathname.c_str(), &fileSize);
8255: if (file)
8256: {
8257: const char *functionName = "C_GetFunctionList";
8258: size_t strLen = strlen (functionName);
8259:
8260: if (fileSize > strLen)
8261: {
8262: for (size_t i = 0; i < fileSize - strLen; ++i)
8263: {
8264: if (memcmp (file + i, functionName, strLen) == 0)
8265: {
8266: HMODULE module = LoadLibrary (dllPathname.c_str());
8267: if (module)
8268: {
8269: if (GetProcAddress (module, functionName))
8270: {
8271: SetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, dllPathname.c_str());
8272: found = true;
8273:
8274: FreeLibrary (module);
8275: break;
8276: }
8277:
8278: FreeLibrary (module);
8279: }
8280: }
8281: }
8282: }
8283:
8284: free (file);
8285: }
8286:
8287: if (!FindNextFile (find, &findData))
8288: break;
8289: }
8290:
8291: if (find != INVALID_HANDLE_VALUE)
8292: FindClose (find);
8293:
8294: NormalCursor();
8295:
8296: if (!found)
8297: Warning ("PKCS11_MODULE_AUTO_DETECTION_FAILED");
8298:
8299: return 1;
8300: }
8301:
8302: case IDC_SELECT_PKCS11_MODULE:
8303: {
8304: char securityTokenLibraryPath[MAX_PATH];
8305: char systemDir[MAX_PATH];
8306: wchar_t browseFilter[1024];
8307:
8308: Info ("SELECT_PKCS11_MODULE_HELP");
8309:
8310: wsprintfW (browseFilter, L"%ls (*.dll)%c*.dll%c%c", GetString ("DLL_FILES"), 0, 0, 0);
8311: GetSystemDirectory (systemDir, sizeof (systemDir));
8312:
8313: if (BrowseFilesInDir (hwndDlg, "SELECT_PKCS11_MODULE", systemDir, securityTokenLibraryPath, TRUE, FALSE, browseFilter))
8314: SetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, securityTokenLibraryPath);
8315: return 1;
8316: }
8317: }
8318: return 0;
8319: }
8320:
8321: return 0;
8322: }
8323:
8324:
8325: void SecurityTokenPreferencesDialog (HWND hwndDlg)
8326: {
8327: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_PREFERENCES), hwndDlg, (DLGPROC) SecurityTokenPreferencesDlgProc, 0);
8328: }
8329:
8330:
8331: static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
8332: {
8333: WORD lw = LOWORD (wParam);
8334:
8335: switch (msg)
8336: {
8337: case WM_INITDIALOG:
8338: {
1.1.1.23 root 8339: if (!BootEncObj->GetStatus().DriveMounted)
1.1.1.19 root 8340: {
8341: Warning ("SYS_DRIVE_NOT_ENCRYPTED");
8342: EndDialog (hwndDlg, IDCANCEL);
8343: return 1;
8344: }
8345:
8346: try
8347: {
8348: LocalizeDialog (hwndDlg, "IDD_SYSENC_SETTINGS");
8349:
1.1.1.23 root 8350: uint32 driverConfig = ReadDriverConfigurationFlags();
1.1.1.19 root 8351: byte userConfig;
8352: string customUserMessage;
1.1.1.21 root 8353: uint16 bootLoaderVersion;
8354:
8355: BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig, &customUserMessage, &bootLoaderVersion);
8356:
8357: if (bootLoaderVersion != VERSION_NUM)
8358: Warning ("BOOT_LOADER_VERSION_INCORRECT_PREFERENCES");
1.1.1.19 root 8359:
8360: SendMessage (GetDlgItem (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE), EM_LIMITTEXT, TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, 0);
8361: SetDlgItemText (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE, customUserMessage.c_str());
8362:
8363: CheckDlgButton (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT, (userConfig & TC_BOOT_USER_CFG_FLAG_SILENT_MODE) ? BST_CHECKED : BST_UNCHECKED);
8364: CheckDlgButton (hwndDlg, IDC_ALLOW_ESC_PBA_BYPASS, (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_ESC) ? BST_UNCHECKED : BST_CHECKED);
1.1.1.23 root 8365: CheckDlgButton (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD, (driverConfig & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD) ? BST_CHECKED : BST_UNCHECKED);
1.1.1.19 root 8366:
8367: SetWindowTextW (GetDlgItem (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE_HELP), GetString("CUSTOM_BOOT_LOADER_MESSAGE_HELP"));
8368: }
8369: catch (Exception &e)
8370: {
8371: e.Show (hwndDlg);
8372: EndDialog (hwndDlg, IDCANCEL);
8373: return 1;
8374: }
8375: }
8376: return 0;
8377:
8378: case WM_COMMAND:
8379:
8380: switch (lw)
8381: {
8382: case IDCANCEL:
8383: EndDialog (hwndDlg, lw);
8384: return 1;
8385:
8386: case IDOK:
8387: {
1.1.1.23 root 8388: if (!BootEncObj->GetStatus().DriveMounted)
8389: {
8390: EndDialog (hwndDlg, IDCANCEL);
8391: return 1;
8392: }
8393:
1.1.1.19 root 8394: char customUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
8395: GetDlgItemText (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE, customUserMessage, sizeof (customUserMessage));
8396:
1.1.1.25! root 8397: byte userConfig;
! 8398: try
! 8399: {
! 8400: BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig);
! 8401: }
! 8402: catch (Exception &e)
! 8403: {
! 8404: e.Show (hwndDlg);
! 8405: return 1;
! 8406: }
! 8407:
1.1.1.19 root 8408: if (IsDlgButtonChecked (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT))
8409: userConfig |= TC_BOOT_USER_CFG_FLAG_SILENT_MODE;
1.1.1.25! root 8410: else
! 8411: userConfig &= ~TC_BOOT_USER_CFG_FLAG_SILENT_MODE;
1.1.1.19 root 8412:
8413: if (!IsDlgButtonChecked (hwndDlg, IDC_ALLOW_ESC_PBA_BYPASS))
8414: userConfig |= TC_BOOT_USER_CFG_FLAG_DISABLE_ESC;
1.1.1.25! root 8415: else
! 8416: userConfig &= ~TC_BOOT_USER_CFG_FLAG_DISABLE_ESC;
1.1.1.19 root 8417:
8418: try
8419: {
8420: BootEncObj->WriteBootSectorUserConfig (userConfig, customUserMessage);
1.1.1.23 root 8421: SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD, IsDlgButtonChecked (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD));
1.1.1.19 root 8422: }
8423: catch (Exception &e)
8424: {
8425: e.Show (hwndDlg);
8426: return 1;
8427: }
8428:
8429: EndDialog (hwndDlg, lw);
8430: return 1;
8431: }
8432:
8433: case IDC_DISABLE_BOOT_LOADER_OUTPUT:
8434: if ((IsDlgButtonChecked (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT))
8435: && AskWarnYesNo ("CUSTOM_BOOT_LOADER_MESSAGE_PROMPT") == IDNO)
8436: {
8437: CheckDlgButton (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT, BST_UNCHECKED);
8438: }
8439:
8440: break;
8441:
8442: case IDC_BOOT_LOADER_CACHE_PASSWORD:
8443: if (IsDlgButtonChecked (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD))
8444: Warning ("BOOT_PASSWORD_CACHE_KEYBOARD_WARNING");
8445:
8446: break;
8447: }
8448: return 0;
8449: }
8450:
8451: return 0;
8452: }
8453:
8454:
1.1.1.25! root 8455: void MountSelectedVolume (HWND hwndDlg, BOOL mountWithOptions)
1.1.1.23 root 8456: {
1.1.1.25! root 8457: if (!VolumeSelected(hwndDlg))
! 8458: {
! 8459: Warning ("NO_VOLUME_SELECTED");
! 8460: }
! 8461: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
! 8462: {
! 8463: mountOptions = defaultMountOptions;
! 8464: bPrebootPasswordDlgMode = FALSE;
1.1.1.23 root 8465:
1.1.1.25! root 8466: if (mountWithOptions || GetAsyncKeyState (VK_CONTROL) < 0)
! 8467: {
! 8468: if (IDCANCEL == DialogBoxParamW (hInst,
! 8469: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
! 8470: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
! 8471: return;
! 8472:
! 8473: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
! 8474: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
! 8475: }
! 8476:
! 8477: if (CheckMountList ())
! 8478: Mount (hwndDlg, 0, 0);
! 8479: }
! 8480: else
! 8481: Warning ("SELECT_FREE_DRIVE");
! 8482: }
! 8483:
! 8484:
! 8485: BOOL GetExecutableImageInformation (const string &path, string &version, string &description, string &companyName, string &productName)
! 8486: {
! 8487: DWORD handle;
! 8488: DWORD size = GetFileVersionInfoSize (path.c_str(), &handle);
! 8489: if (size == 0)
! 8490: return FALSE;
! 8491:
! 8492: void *buf = err_malloc (size);
! 8493: finally_do_arg (void*, buf, { free (finally_arg); });
! 8494:
! 8495: if (!GetFileVersionInfo (path.c_str(), handle, size, buf))
! 8496: return FALSE;
! 8497:
! 8498: version = description = companyName = productName = "";
! 8499:
! 8500: UINT varSize;
! 8501: VS_FIXEDFILEINFO *fileInfo;
! 8502: if (VerQueryValue (buf, "\\", (LPVOID *) &fileInfo, &varSize) && varSize > 0)
1.1.1.23 root 8503: {
1.1.1.25! root 8504: stringstream s;
! 8505: s << HIWORD (fileInfo->dwFileVersionMS) << '.' << LOWORD (fileInfo->dwFileVersionMS) << '.' << HIWORD (fileInfo->dwFileVersionLS) << '.' << LOWORD (fileInfo->dwFileVersionLS);
! 8506: version = s.str();
! 8507: }
! 8508:
! 8509: DWORD *langCodes;
! 8510: if (VerQueryValue (buf, "\\VarFileInfo\\Translation", (LPVOID *) &langCodes, &varSize) && varSize >= sizeof (DWORD))
! 8511: {
! 8512: char prefix[128];
! 8513: sprintf_s (prefix, sizeof (prefix), "\\StringFileInfo\\%04x%04x\\", LOWORD (langCodes[0]), HIWORD (langCodes[0]));
! 8514:
! 8515: char *str;
! 8516: if (VerQueryValue (buf, (string (prefix) + "FileDescription").c_str(), (LPVOID *) &str, &varSize) && varSize > 0)
! 8517: description = str;
! 8518:
! 8519: if (VerQueryValue (buf, (string (prefix) + "CompanyName").c_str(), (LPVOID *) &str, &varSize) && varSize > 0)
! 8520: companyName = str;
! 8521:
! 8522: if (VerQueryValue (buf, (string (prefix) + "ProductName").c_str(), (LPVOID *) &str, &varSize) && varSize > 0)
! 8523: productName = str;
! 8524: }
! 8525:
! 8526: return TRUE;
! 8527: }
! 8528:
! 8529:
! 8530: void AnalyzeKernelMiniDump (HWND hwndDlg)
! 8531: {
! 8532: char winDir[MAX_PATH] = { 0 };
! 8533: GetWindowsDirectory (winDir, sizeof (winDir));
! 8534:
! 8535: string dumpPath = FindLatestFileOrDirectory (string (winDir) + "\\Minidump", "*.dmp", false, true);
! 8536: if (dumpPath.empty())
! 8537: {
! 8538: Error ("NO_MINIDUMP_FOUND");
! 8539: return;
! 8540: }
! 8541:
! 8542: STARTUPINFO startupInfo;
! 8543: PROCESS_INFORMATION procInfo;
! 8544:
! 8545: ZeroMemory (&startupInfo, sizeof (startupInfo));
! 8546: ZeroMemory (&procInfo, sizeof (procInfo));
! 8547:
! 8548: if (!IsApplicationInstalled (Is64BitOs() ? "Debugging Tools for Windows (x64)" : "Debugging Tools for Windows (x86)"))
! 8549: {
! 8550: if (AskOkCancel ("ASK_DEBUGGER_INSTALL") != IDOK)
! 8551: return;
! 8552:
! 8553: if (!CreateProcess (NULL, (LPSTR) (string ("msiexec.exe /qb /i " TC_APPLINK "&dest=ms-debug-tools-x") + (Is64BitOs() ? "64" : "86")).c_str(),
! 8554: NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &procInfo))
1.1.1.23 root 8555: {
1.1.1.25! root 8556: handleWin32Error (hwndDlg);
! 8557: return;
! 8558: }
! 8559:
! 8560: WaitCursor();
! 8561: WaitForSingleObject (procInfo.hProcess, INFINITE);
! 8562: NormalCursor();
! 8563:
! 8564: DWORD exitCode;
! 8565: if (!GetExitCodeProcess (procInfo.hProcess, &exitCode) || exitCode != 0)
! 8566: return;
! 8567: }
! 8568:
! 8569: if (AskOkCancel ("SYSTEM_CRASH_ANALYSIS_INFO") == IDCANCEL)
! 8570: return;
! 8571:
! 8572: ZeroMemory (&startupInfo, sizeof (startupInfo));
! 8573: ZeroMemory (&procInfo, sizeof (procInfo));
! 8574:
! 8575: SECURITY_ATTRIBUTES securityAttrib;
! 8576: securityAttrib.bInheritHandle = TRUE;
! 8577: securityAttrib.nLength = sizeof (securityAttrib);
! 8578: securityAttrib.lpSecurityDescriptor = NULL;
! 8579:
! 8580: HANDLE hChildStdoutWrite = INVALID_HANDLE_VALUE;
! 8581: HANDLE hChildStdoutRead = INVALID_HANDLE_VALUE;
! 8582: if (!CreatePipe (&hChildStdoutRead, &hChildStdoutWrite, &securityAttrib, 0))
! 8583: {
! 8584: handleWin32Error (hwndDlg);
! 8585: return;
! 8586: }
! 8587: SetHandleInformation (hChildStdoutRead, HANDLE_FLAG_INHERIT, 0);
! 8588:
! 8589: startupInfo.hStdInput = INVALID_HANDLE_VALUE;
! 8590: startupInfo.hStdOutput = hChildStdoutWrite;
! 8591: startupInfo.cb = sizeof (startupInfo);
! 8592: startupInfo.hStdError = hChildStdoutWrite;
! 8593: startupInfo.dwFlags |= STARTF_USESTDHANDLES;
! 8594:
! 8595: list <string> kdPaths;
! 8596: string kdPath;
! 8597: char progPath[MAX_PATH];
! 8598: if (SHGetSpecialFolderPath (hwndDlg, progPath, CSIDL_PROGRAM_FILES, FALSE))
! 8599: {
! 8600: if (Is64BitOs())
! 8601: {
! 8602: string s = progPath;
! 8603: size_t p = s.find (" (x86)");
! 8604: if (p != string::npos)
1.1.1.23 root 8605: {
1.1.1.25! root 8606: s = s.substr (0, p);
! 8607: if (_access (s.c_str(), 0) != -1)
! 8608: strcpy_s (progPath, sizeof (progPath), s.c_str());
1.1.1.23 root 8609: }
1.1.1.25! root 8610: }
1.1.1.23 root 8611:
1.1.1.25! root 8612: kdPath = string (progPath) + "\\Debugging Tools for Windows (" + (Is64BitOs() ? "x64" : "x86") + ")\\kd.exe";
! 8613: kdPaths.push_back (kdPath);
! 8614: }
1.1.1.23 root 8615:
1.1.1.25! root 8616: kdPath = FindLatestFileOrDirectory (string (winDir).substr (0, 1) + ":\\WinDDK", "*", true, false);
! 8617: kdPath += "\\Debuggers\\kd.exe";
! 8618: kdPaths.push_back (kdPath);
1.1.1.23 root 8619:
1.1.1.25! root 8620: kdPaths.push_back ("kd.exe");
! 8621:
! 8622: bool kdRunning = false;
! 8623: foreach (const string &kdPath, kdPaths)
! 8624: {
! 8625: if (CreateProcess (NULL, (LPSTR) ("\"" + kdPath + "\" -z \"" + dumpPath + "\" -y http://msdl.microsoft.com/download/symbols -c \".bugcheck; !analyze -v; q\"").c_str(),
! 8626: NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &procInfo))
! 8627: {
! 8628: kdRunning = true;
! 8629: break;
1.1.1.23 root 8630: }
1.1.1.25! root 8631: }
1.1.1.23 root 8632:
1.1.1.25! root 8633: if (!kdRunning)
! 8634: {
! 8635: handleWin32Error (hwndDlg);
! 8636: Error ("DEBUGGER_NOT_FOUND");
! 8637: return;
! 8638: }
1.1.1.23 root 8639:
1.1.1.25! root 8640: EnableElevatedCursorChange (hwndDlg);
! 8641: WaitCursor();
1.1.1.23 root 8642:
1.1.1.25! root 8643: CloseHandle (procInfo.hProcess);
! 8644: CloseHandle (procInfo.hThread);
! 8645: CloseHandle (hChildStdoutWrite);
1.1.1.23 root 8646:
1.1.1.25! root 8647: string output;
1.1.1.23 root 8648:
1.1.1.25! root 8649: while (TRUE)
! 8650: {
! 8651: DWORD bytesReceived;
! 8652: char pipeBuffer [4096];
1.1.1.23 root 8653:
1.1.1.25! root 8654: if (!ReadFile (hChildStdoutRead, pipeBuffer, sizeof (pipeBuffer), &bytesReceived, NULL))
! 8655: break;
1.1.1.23 root 8656:
1.1.1.25! root 8657: output.insert (output.size(), pipeBuffer, bytesReceived);
! 8658: }
1.1.1.23 root 8659:
1.1.1.25! root 8660: NormalCursor();
1.1.1.23 root 8661:
1.1.1.25! root 8662: bool otherDriver = (StringToUpperCase (output).find (StringToUpperCase (TC_APP_NAME)) == string::npos);
! 8663:
! 8664: size_t p, p2;
! 8665: while ((p = output.find ('`')) != string::npos)
! 8666: output.erase (output.begin() + p);
! 8667:
! 8668: p = output.find ("Bugcheck code ");
! 8669: if (p == string::npos)
! 8670: {
! 8671: Error ("ERR_PARAMETER_INCORRECT");
! 8672: return;
! 8673: }
! 8674:
! 8675: uint64 bugcheckCode;
! 8676: int n = sscanf (output.substr (p + 14, 8).c_str(), "%I64X", &bugcheckCode);
! 8677: if (n != 1)
! 8678: {
! 8679: Error ("ERR_PARAMETER_INCORRECT");
! 8680: return;
! 8681: }
1.1.1.23 root 8682:
1.1.1.25! root 8683: p = output.find ("Arguments ", p);
! 8684:
! 8685: uint64 bugcheckArgs[4];
! 8686: n = sscanf (output.substr (p + 10, (Is64BitOs() ? 17 : 9) * 4).c_str(), "%I64X %I64X %I64X %I64X", &bugcheckArgs[0], &bugcheckArgs[1], &bugcheckArgs[2], &bugcheckArgs[3]);
! 8687: if (n != 4)
! 8688: {
! 8689: Error ("ERR_PARAMETER_INCORRECT");
! 8690: return;
! 8691: }
! 8692:
! 8693: // Image name
! 8694: string imageName, imageVersion;
! 8695: p = output.find ("IMAGE_NAME:");
! 8696: if (p != string::npos)
! 8697: {
! 8698: p += 13;
! 8699: p2 = output.find ('\n', p);
! 8700: if (p2 != string::npos)
! 8701: imageName = output.substr (p, p2 - p);
! 8702: }
! 8703:
! 8704: // Stack trace
! 8705: p = output.find ("STACK_TEXT:");
! 8706: if (p == string::npos)
! 8707: {
! 8708: Error ("ERR_PARAMETER_INCORRECT");
! 8709: return;
! 8710: }
! 8711:
! 8712: p2 = output.find ("FOLLOWUP_IP:", p);
! 8713: if (p2 == string::npos)
! 8714: p2 = output.find ("STACK_COMMAND:", p);
! 8715: if (p2 == string::npos)
! 8716: p2 = output.size();
! 8717:
! 8718: output = output.substr (p, p2 - p);
! 8719:
! 8720: list <string> retAddrs;
! 8721: p = 0;
! 8722: while ((p = output.find ("+", p)) != string::npos)
! 8723: {
! 8724: size_t p1 = output.rfind (" ", p);
! 8725: if (p1 == string::npos)
1.1.1.23 root 8726: break;
1.1.1.25! root 8727:
! 8728: p = output.find ('\n', p);
! 8729: if (p == string::npos)
! 8730: p = output.size() - 1;
! 8731:
! 8732: string s = output.substr (p1 + 1, p - p1 - 1);
! 8733:
! 8734: if (s.find ('(') == 0)
! 8735: s = s.substr (1);
! 8736: if (s.rfind (')') == s.size() - 1)
! 8737: s = s.substr (0, s.size() - 1);
! 8738:
! 8739: retAddrs.push_back (s);
! 8740: }
! 8741:
! 8742: char url[MAX_URL_LENGTH];
! 8743: sprintf (url, TC_APPLINK_SECURE "&dest=syserr-report&os=%s&osver=%d.%d.%d&arch=%s&err=%I64x&arg1=%I64x&arg2=%I64x&arg3=%I64x&arg4=%I64x&flag=%s&drv=%s",
! 8744: GetWindowsEdition().c_str(),
! 8745: CurrentOSMajor,
! 8746: CurrentOSMinor,
! 8747: CurrentOSServicePack,
! 8748: Is64BitOs() ? "x64" : "x86",
! 8749: bugcheckCode,
! 8750: bugcheckArgs[0],
! 8751: bugcheckArgs[1],
! 8752: bugcheckArgs[2],
! 8753: bugcheckArgs[3],
! 8754: otherDriver ? "0" : "1",
! 8755: imageName.empty() ? "-" : imageName.c_str()
! 8756: );
! 8757:
! 8758: stringstream stackTraceArgs;
! 8759: int i = 0;
! 8760: foreach (const string &retAddr, retAddrs)
! 8761: {
! 8762: stackTraceArgs << "&st" << i++ << "=" << retAddr;
! 8763: }
! 8764:
! 8765: wstring msg;
! 8766:
! 8767: if (otherDriver)
! 8768: {
! 8769: if (!imageName.empty())
! 8770: {
! 8771: msg += wstring (GetString ("SYSTEM_CRASH_UPDATE_DRIVER")) + L"\n\n" + SingleStringToWide (imageName);
! 8772:
! 8773: string description, company, product;
! 8774: if (GetExecutableImageInformation (string (winDir) + "\\System32\\drivers\\" + imageName, imageVersion, description, company, product))
! 8775: {
! 8776: string s;
! 8777: if (!description.empty())
! 8778: s += description;
! 8779: if (!company.empty())
! 8780: s += "; " + company;
! 8781: if (!product.empty())
! 8782: s += "; " + product;
! 8783:
! 8784: if (s.find ("; ") == 0)
! 8785: s = s.substr (3);
! 8786:
! 8787: if (!s.empty())
! 8788: msg += SingleStringToWide (" (" + s + ")");
! 8789: }
! 8790:
! 8791: msg += L"\n\n";
1.1.1.23 root 8792: }
1.1.1.25! root 8793:
! 8794: msg += GetString ("SYSTEM_CRASH_NO_TRUECRYPT");
! 8795: msg += L"\n\n";
1.1.1.23 root 8796: }
1.1.1.25! root 8797:
! 8798: string urlStr = string (url) + "&drvver=" + (imageVersion.empty() ? "-" : imageVersion) + stackTraceArgs.str();
1.1.1.23 root 8799:
1.1.1.25! root 8800: for (size_t i = 0; i < urlStr.size(); ++i)
! 8801: {
! 8802: if (urlStr[i] == '+')
! 8803: urlStr[i] = '.';
! 8804: }
! 8805:
! 8806: msg += GetString ("SYSTEM_CRASH_REPORT");
! 8807: msg += L"\n\n";
! 8808:
! 8809: msg += SingleStringToWide (urlStr);
! 8810:
! 8811: msg += L"\n\n";
! 8812: msg += GetString ("ASK_SEND_ERROR_REPORT");
! 8813:
! 8814: if (AskYesNoString (msg.c_str()) == IDYES)
! 8815: ShellExecute (NULL, "open", urlStr.c_str(), NULL, NULL, SW_SHOWNORMAL);
1.1.1.23 root 8816: }
8817:
8818:
1.1.1.25! root 8819: static BOOL HandleDriveListMouseWheelEvent (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bListMustBePointed)
1.1.1.19 root 8820: {
1.1.1.25! root 8821: RECT listRect;
! 8822: int mouseX = GET_X_LPARAM (lParam);
! 8823: int mouseY = GET_Y_LPARAM (lParam);
! 8824:
! 8825: GetWindowRect (GetDlgItem (MainDlg, IDC_DRIVELIST), &listRect);
! 8826:
! 8827: // Determine if the mouse pointer is within the main drive list
! 8828: bool bListPointed = (mouseX >= listRect.left && mouseX <= listRect.right
! 8829: && mouseY >= listRect.top && mouseY <= listRect.bottom);
! 8830:
! 8831: if (bListMustBePointed && bListPointed
! 8832: || !bListMustBePointed)
1.1.1.19 root 8833: {
1.1.1.25! root 8834: if (!bListMustBePointed && bListPointed)
! 8835: SetFocus (GetDlgItem (MainDlg, IDC_DRIVELIST));
! 8836:
! 8837: SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), uMsg, wParam, lParam);
! 8838:
! 8839: return 0; // Do not process this event any further e.g. to prevent two lists from being scrolled at once
1.1.1.19 root 8840: }
8841:
1.1.1.25! root 8842: return 1;
! 8843: }
1.1.1.19 root 8844:
8845:
1.1.1.25! root 8846: static LRESULT CALLBACK MouseWheelProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
! 8847: {
! 8848: WNDPROC wp = (WNDPROC) GetWindowLongPtr (hwnd, GWLP_USERDATA);
! 8849:
! 8850: switch (message)
! 8851: {
! 8852: case WM_MOUSEWHEEL:
! 8853:
! 8854: if (HandleDriveListMouseWheelEvent (message, wParam, lParam, TRUE) == 0)
! 8855: return 0; // Do not process this event any further e.g. to prevent two lists from being scrolled at once
1.1.1.19 root 8856: }
1.1.1.25! root 8857:
! 8858: return CallWindowProc (wp, hwnd, message, wParam, lParam);
! 8859: }
! 8860:
! 8861:
! 8862: void HookMouseWheel (HWND hwndDlg, UINT ctrlId)
! 8863: {
! 8864: HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId);
! 8865:
! 8866: SetWindowLongPtr (hwndCtrl, GWLP_USERDATA, (LONG_PTR) GetWindowLongPtr (hwndCtrl, GWLP_WNDPROC));
! 8867: SetWindowLongPtr (hwndCtrl, GWLP_WNDPROC, (LONG_PTR) MouseWheelProc);
1.1.1.19 root 8868: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.