|
|
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:
1.1.1.26! root 4457: if (selDrive != -1 && (current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
1.1.1.13 root 4458: {
4459: nSelectedDriveIndex = -1;
4460: return FALSE;
4461: }
1.1.1.2 root 4462:
1.1.1.26! root 4463: if (selDrive != -1)
1.1.1.13 root 4464: SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
4465: }
1.1 root 4466:
1.1.1.13 root 4467: try
4468: {
4469: newBootEncStatus = BootEncObj->GetStatus();
4470:
4471: if (newBootEncStatus.SetupInProgress != RecentBootEncStatus.SetupInProgress
4472: || newBootEncStatus.EncryptedAreaEnd != RecentBootEncStatus.EncryptedAreaEnd
4473: || newBootEncStatus.DriveEncrypted != RecentBootEncStatus.DriveEncrypted
4474: || newBootEncStatus.DriveMounted != RecentBootEncStatus.DriveMounted
4475: || newBootEncStatus.SetupMode != RecentBootEncStatus.SetupMode
4476: || newBootEncStatus.EncryptedAreaStart != RecentBootEncStatus.EncryptedAreaStart)
4477: {
4478: /* System encryption status change */
4479:
1.1.1.23 root 4480: char selDrive;
1.1.1.13 root 4481: int driveLetterToRefresh;
4482:
4483: if (RecentBootEncStatus.DriveMounted == newBootEncStatus.DriveMounted) // If an icon (and whole new line) for a system device isn't to be added/removed
4484: {
4485: // Partial refresh
4486: if (WholeSysDriveEncryption (TRUE))
4487: {
4488: // System drive (not just partition)
4489: driveLetterToRefresh = ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER;
4490: }
4491: else
4492: {
4493: // System partition
4494: driveLetterToRefresh = GetSystemDriveLetter ();
4495: }
4496: }
4497: else
4498: {
4499: // Full rebuild of the mount list
4500: driveLetterToRefresh = 0;
4501: }
4502:
1.1.1.23 root 4503: selDrive = (char) HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
1.1.1.13 root 4504: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), driveLetterToRefresh);
4505:
1.1.1.23 root 4506: RecentBootEncStatus = newBootEncStatus;
1.1.1.13 root 4507:
1.1.1.26! root 4508: if (selDrive != -1 && (current.ulMountedDrives & (1 << (selDrive - 'A'))) == 0 && !IsDriveAvailable (selDrive - 'A'))
1.1.1.13 root 4509: {
4510: nSelectedDriveIndex = -1;
4511: }
4512:
1.1.1.26! root 4513: if (selDrive != -1)
1.1.1.13 root 4514: {
4515: SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
4516: }
4517: }
4518:
1.1.1.17 root 4519: /* Miscellaneous notifications */
4520:
1.1.1.13 root 4521: // Hibernation prevention notifications
4522: if (newBootEncStatus.HibernationPreventionCount != RecentBootEncStatus.HibernationPreventionCount
4523: && !bHibernationPreventionNotified)
4524: {
4525: bHibernationPreventionNotified = TRUE;
4526: RecentBootEncStatus.HibernationPreventionCount = newBootEncStatus.HibernationPreventionCount;
1.1.1.23 root 4527:
4528: if (IsHiddenOSRunning() && BootEncObj->GetSystemDriveConfiguration().ExtraBootPartitionPresent)
4529: WarningTopMost ("HIDDEN_OS_HIBERNATION_PREVENTED");
4530: else
4531: WarningTopMost ("SYS_ENC_HIBERNATION_PREVENTED");
1.1.1.13 root 4532: }
1.1.1.17 root 4533:
4534: // Write mode prevention (hidden OS leak protection)
4535: if (IsHiddenOSRunning())
4536: {
4537: if (newBootEncStatus.HiddenSysLeakProtectionCount != RecentBootEncStatus.HiddenSysLeakProtectionCount
4538: && !bHiddenSysLeakProtNotifiedDuringSession)
4539: {
4540: bHiddenSysLeakProtNotifiedDuringSession = TRUE;
4541:
4542: switch (HiddenSysLeakProtectionNotificationStatus)
4543: {
4544: case TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT:
4545: {
4546: char *tmp[] = {0, "HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO", "SHOW_MORE_INFORMATION", "DO_NOT_SHOW_THIS_AGAIN", "CONTINUE", 0};
1.1.1.19 root 4547: switch (AskMultiChoice ((void **) tmp, FALSE))
1.1.1.17 root 4548: {
4549: case 1:
4550: InfoDirect ((wstring (GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO"))
4551: + L"\n\n"
4552: + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")
4553: + L"\n\n\n"
4554: + GetString ("DECOY_TO_HIDDEN_OS_DATA_TRANSFER_HOWTO")).c_str());
4555: break;
4556:
4557: case 2:
4558: // No more warnings will be shown
4559: if (ConfigBuffer == NULL)
4560: {
4561: // We need to load the config file because it is not done automatically when
4562: // launched from the sys startup sequence (and SaveSettings would start by _loading_
4563: // the settings to cache).
4564: LoadSettings (MainDlg);
4565: }
4566: HiddenSysLeakProtectionNotificationStatus = TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED;
4567: SaveSettings (MainDlg);
4568: break;
4569:
4570: default:
4571: // NOP
4572: break;
4573: }
4574: }
4575: break;
4576:
4577: case TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_DISABLED:
4578: // NOP
4579: break;
4580:
4581: case TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_NONE:
4582: default:
4583: {
4584: // First time warning -- include technical explanation
4585: InfoDirect ((wstring (GetString ("HIDDEN_OS_WRITE_PROTECTION_BRIEF_INFO"))
4586: + L"\n\n"
4587: + GetString ("HIDDEN_OS_WRITE_PROTECTION_EXPLANATION")
4588: + L"\n\n\n"
4589: + GetString ("DECOY_TO_HIDDEN_OS_DATA_TRANSFER_HOWTO")).c_str());
4590:
4591: // Further warnings will not include the explanation (and will allow disabling)
4592:
4593: if (ConfigBuffer == NULL)
4594: {
4595: // We need to load the config file because it is not done automatically when
4596: // launched from the sys startup sequence (and SaveSettings would start by _loading_
4597: // the settings to cache).
4598: LoadSettings (MainDlg);
4599: }
4600: HiddenSysLeakProtectionNotificationStatus = TC_HIDDEN_OS_READ_ONLY_NOTIF_MODE_COMPACT;
4601: SaveSettings (MainDlg);
4602: }
4603: break;
4604: }
4605: }
4606: }
1.1.1.13 root 4607: }
4608: catch (...)
4609: {
4610: // NOP
1.1.1.7 root 4611: }
1.1 root 4612:
1.1.1.7 root 4613: return TRUE;
4614: }
1.1.1.6 root 4615:
1.1 root 4616:
1.1.1.13 root 4617: /* Except in response to the WM_INITDIALOG and WM_ENDSESSION messages, the dialog box procedure
1.1.1.11 root 4618: should return nonzero if it processes a message, and zero if it does not. */
1.1.1.13 root 4619: BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
1.1.1.7 root 4620: {
1.1.1.11 root 4621: static UINT taskBarCreatedMsg;
1.1.1.7 root 4622: WORD lw = LOWORD (wParam);
4623: WORD hw = HIWORD (wParam);
4624: DWORD mPos;
1.1 root 4625:
1.1.1.7 root 4626: switch (uMsg)
4627: {
4628: case WM_HOTKEY:
1.1 root 4629:
1.1.1.7 root 4630: HandleHotKey (hwndDlg, wParam);
4631: return 1;
1.1 root 4632:
1.1.1.7 root 4633: case WM_INITDIALOG:
4634: {
4635: int exitCode = 0;
1.1.1.13 root 4636: int modeOfOperation;
4637:
1.1.1.7 root 4638: MainDlg = hwndDlg;
1.1 root 4639:
1.1.1.17 root 4640: if (IsTrueCryptInstallerRunning())
4641: AbortProcess ("TC_INSTALLER_IS_RUNNING");
4642:
1.1.1.7 root 4643: // Set critical default options in case UsePreferences is false
4644: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE;
1.1 root 4645:
1.1.1.17 root 4646: ResetWrongPwdRetryCount ();
4647:
1.1.1.7 root 4648: ExtractCommandLine (hwndDlg, (char *) lParam);
4649:
1.1.1.11 root 4650: if (ComServerMode)
4651: {
1.1.1.19 root 4652: InitDialog (hwndDlg);
4653:
1.1.1.11 root 4654: if (!ComServerMain ())
4655: {
4656: handleWin32Error (hwndDlg);
4657: exit (1);
4658: }
4659: exit (0);
4660: }
4661:
1.1.1.13 root 4662: try
4663: {
4664: BootEncStatus = BootEncObj->GetStatus();
1.1.1.23 root 4665: RecentBootEncStatus = BootEncStatus;
1.1.1.13 root 4666: }
4667: catch (...)
4668: {
4669: // NOP
4670: }
4671:
1.1.1.7 root 4672: if (UsePreferences)
1.1 root 4673: {
1.1.1.7 root 4674: // General preferences
4675: LoadSettings (hwndDlg);
4676:
4677: // Keyfiles
4678: LoadDefaultKeyFilesParam ();
4679: RestoreDefaultKeyFilesParam ();
1.1 root 4680: }
4681:
1.1.1.23 root 4682: if (CmdMountOptionsValid)
4683: mountOptions = CmdMountOptions;
4684:
1.1.1.7 root 4685: InitMainDialog (hwndDlg);
4686:
1.1.1.25 root 4687: try
1.1.1.17 root 4688: {
1.1.1.25 root 4689: if (IsHiddenOSRunning())
1.1.1.17 root 4690: {
4691: if (BootEncObj->GetInstalledBootLoaderVersion() > VERSION_NUM)
1.1.1.21 root 4692: Warning ("UPDATE_TC_IN_HIDDEN_OS_TOO");
1.1.1.17 root 4693: }
1.1.1.25 root 4694: else if (SysDriveOrPartitionFullyEncrypted (TRUE)
4695: && BootEncObj->GetInstalledBootLoaderVersion() != VERSION_NUM)
4696: {
4697: Warning ("BOOT_LOADER_VERSION_DIFFERENT_FROM_DRIVER_VERSION");
4698: }
4699: }
4700: catch (...) { }
1.1.1.17 root 4701:
1.1.1.2 root 4702: // Automount
1.1.1.7 root 4703: if (bAuto || (Quit && szFileName[0] != 0))
1.1 root 4704: {
1.1.1.5 root 4705: // No drive letter specified on command line
4706: if (commandLineDrive == 0)
1.1.1.23 root 4707: szDriveLetter[0] = (char) GetFirstAvailableDrive () + 'A';
1.1.1.5 root 4708:
1.1.1.6 root 4709: if (bAutoMountDevices)
4710: {
4711: defaultMountOptions = mountOptions;
1.1.1.8 root 4712: if (FirstCmdKeyFile)
4713: {
4714: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
4715: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4716: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4717: }
4718:
1.1.1.23 root 4719: if (!MountAllDevices (hwndDlg, !Silent && !CmdVolumePasswordValid && IsPasswordCacheEmpty()))
1.1.1.7 root 4720: exitCode = 1;
4721: }
4722:
4723: if (bAutoMountFavorites)
4724: {
4725: defaultMountOptions = mountOptions;
1.1.1.8 root 4726: if (FirstCmdKeyFile)
4727: {
4728: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
4729: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4730: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
4731: }
4732:
1.1.1.25 root 4733: if (!MountFavoriteVolumes (FALSE, LogOn))
1.1.1.7 root 4734: exitCode = 1;
1.1.1.6 root 4735: }
1.1.1.7 root 4736:
4737: if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
1.1.1.2 root 4738: {
4739: BOOL mounted;
4740:
4741: // Cached password
1.1.1.7 root 4742: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1.1.2 root 4743:
1.1.1.7 root 4744: // Command line password or keyfiles
4745: if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
1.1.1.2 root 4746: {
1.1.1.7 root 4747: BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
4748:
4749: if (FirstCmdKeyFile)
1.1.1.12 root 4750: KeyFilesApply (&CmdVolumePassword, FirstCmdKeyFile);
1.1.1.7 root 4751:
4752: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
4753: szFileName, &CmdVolumePassword, bCacheInDriver, bForceMount,
4754: &mountOptions, Silent, reportBadPasswd);
4755:
4756: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
4757: }
4758:
4759: if (FirstCmdKeyFile)
4760: {
4761: FirstKeyFile = FirstCmdKeyFile;
4762: KeyFilesEnable = TRUE;
1.1.1.2 root 4763: }
4764:
4765: // Ask user for password
1.1.1.7 root 4766: while (!mounted && !Silent)
1.1.1.2 root 4767: {
1.1.1.7 root 4768: VolumePassword.Length = 0;
1.1.1.2 root 4769:
1.1.1.7 root 4770: strcpy (PasswordDlgVolume, szFileName);
1.1.1.17 root 4771: if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
1.1.1.2 root 4772: break;
4773:
1.1.1.11 root 4774: WaitCursor ();
1.1.1.7 root 4775:
4776: if (KeyFilesEnable && FirstKeyFile)
1.1.1.12 root 4777: KeyFilesApply (&VolumePassword, FirstKeyFile);
1.1.1.7 root 4778:
4779: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
4780:
4781: burn (&VolumePassword, sizeof (VolumePassword));
4782: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
4783:
1.1.1.2 root 4784: NormalCursor ();
4785: }
4786:
1.1.1.7 root 4787: if (UsePreferences)
1.1.1.11 root 4788: {
1.1.1.7 root 4789: RestoreDefaultKeyFilesParam ();
1.1.1.11 root 4790: bCacheInDriver = bCacheInDriverDefault;
4791: }
1.1.1.7 root 4792:
1.1.1.5 root 4793: if (mounted > 0)
1.1.1.2 root 4794: {
1.1.1.11 root 4795: if (bBeep)
1.1.1.23 root 4796: MessageBeep (0xFFFFFFFF);
1.1.1.11 root 4797:
4798: if (bExplore)
4799: OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
4800:
1.1.1.7 root 4801: RefreshMainDlg(hwndDlg);
1.1.1.11 root 4802:
4803: if(!Silent)
4804: {
1.1.1.13 root 4805: // Check for deprecated CBC mode
4806: modeOfOperation = GetModeOfOperationByDriveNo (szDriveLetter[0] - 'A');
4807: if (modeOfOperation == CBC || modeOfOperation == OUTER_CBC)
4808: Warning("WARN_CBC_MODE");
4809:
4810: // Check for deprecated 64-bit-block ciphers
1.1.1.11 root 4811: if (GetCipherBlockSizeByDriveNo (szDriveLetter[0] - 'A') == 64)
4812: Warning("WARN_64_BIT_BLOCK_CIPHER");
4813:
4814: // Check for problematic file extensions (exe, dll, sys)
4815: if (CheckFileExtension (szFileName))
4816: Warning ("EXE_FILE_EXTENSION_MOUNT_WARNING");
4817: }
1.1.1.2 root 4818: }
1.1.1.7 root 4819: else
4820: exitCode = 1;
1.1.1.2 root 4821: }
1.1.1.12 root 4822: else if (bExplore && GetMountedVolumeDriveNo (szFileName) != -1)
4823: OpenVolumeExplorerWindow (GetMountedVolumeDriveNo (szFileName));
1.1.1.10 root 4824: else if (szFileName[0] != 0 && IsMountedVolume (szFileName))
1.1.1.11 root 4825: Warning ("VOL_ALREADY_MOUNTED");
1.1.1.10 root 4826:
1.1.1.8 root 4827: if (!Quit)
4828: RefreshMainDlg(hwndDlg);
1.1.1.7 root 4829: }
1.1.1.23 root 4830:
4831: // Wipe cache
4832: if (bWipe)
4833: WipeCache (hwndDlg, Silent);
1.1.1.7 root 4834:
4835: // Wipe command line password
4836: if (CmdVolumePassword.Length != 0)
4837: {
4838: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
4839: CmdVolumePassword.Length = 0;
1.1 root 4840: }
4841:
1.1.1.7 root 4842: // Wipe command line keyfiles
4843: if (FirstCmdKeyFile)
1.1.1.8 root 4844: {
4845: if (defaultKeyFilesParam.FirstKeyFile)
4846: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
4847:
4848: defaultKeyFilesParam.EnableKeyFiles = FALSE;
4849:
1.1.1.10 root 4850: if (!Quit)
4851: {
4852: LoadSettings (hwndDlg);
4853: LoadDefaultKeyFilesParam ();
4854: RestoreDefaultKeyFilesParam ();
4855: }
1.1.1.8 root 4856: }
1.1.1.7 root 4857:
4858: // Dismount
1.1.1.5 root 4859: if (cmdUnmountDrive > 0)
1.1.1.7 root 4860: {
4861: if (!Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A'))
4862: exitCode = 1;
4863: }
1.1.1.5 root 4864: else if (cmdUnmountDrive == -1)
1.1.1.7 root 4865: {
4866: if (!DismountAll (hwndDlg, bForceUnmount, !Silent, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY))
4867: exitCode = 1;
4868: }
1.1.1.5 root 4869:
1.1.1.7 root 4870: // TaskBar icon
4871: if (bEnableBkgTask)
4872: TaskBarIconAdd (hwndDlg);
1.1.1.11 root 4873:
1.1.1.7 root 4874: // Quit
1.1.1.12 root 4875: if (Quit)
4876: {
4877: if (TaskBarIconMutex == NULL)
4878: exit (exitCode);
4879:
4880: MainWindowHidden = TRUE;
4881:
4882: LoadSettings (hwndDlg);
4883: LoadDefaultKeyFilesParam ();
4884: RestoreDefaultKeyFilesParam ();
4885:
4886: if (!bEnableBkgTask)
4887: {
4888: if (TaskBarIconMutex)
4889: TaskBarIconRemove (hwndDlg);
4890: exit (exitCode);
4891: }
4892: }
1.1.1.7 root 4893:
1.1.1.8 root 4894: // No command line arguments or only /volume => bring active instance
4895: // to foreground if available
4896: if (NoCmdLineArgs == 0 || (CmdLineVolumeSpecified && NoCmdLineArgs <= 2))
4897: {
4898: HWND h = hwndDlg;
4899: EnumWindows (FindTCWindowEnum, (LPARAM) &h);
4900:
1.1.1.23 root 4901: if (h != hwndDlg
4902: && (!IsAdmin() || (GetWindowLongPtr (h, DWLP_USER) & TC_MAIN_WINDOW_FLAG_ADMIN_PRIVILEGES) != 0))
1.1.1.8 root 4903: {
4904: if (CmdLineVolumeSpecified)
4905: {
4906: COPYDATASTRUCT cd;
4907: memcpy (&cd.dwData, WM_COPY_SET_VOLUME_NAME, 4);
4908: cd.lpData = szFileName;
4909: cd.cbData = strlen (szFileName) + 1;
4910:
4911: SendMessage (h, WM_COPYDATA, (WPARAM)hwndDlg, (LPARAM)&cd);
4912: }
4913:
1.1.1.13 root 4914: SendMessage (h, TC_APPMSG_MOUNT_SHOW_WINDOW, 0, 0);
1.1.1.8 root 4915:
4916: ShowWindow (h, SW_SHOW);
4917: SetForegroundWindow (h);
1.1.1.12 root 4918:
4919: if (TaskBarIconMutex == NULL)
4920: exit (0);
1.1.1.8 root 4921: }
4922: }
4923:
1.1.1.25 root 4924: HookMouseWheel (hwndDlg, IDC_VOLUME);
4925:
1.1.1.12 root 4926: // Register hot keys
4927: if (!RegisterAllHotkeys (hwndDlg, Hotkeys)
4928: && TaskBarIconMutex != NULL) // Warn only if we are the first instance of TrueCrypt
4929: Warning("HOTKEY_REGISTRATION_ERROR");
4930:
1.1.1.7 root 4931: Silent = FALSE;
4932:
4933: GetMountList (&LastKnownMountList);
1.1.1.13 root 4934: SetTimer (hwndDlg, TIMER_ID_MAIN, TIMER_INTERVAL_MAIN, NULL);
1.1.1.3 root 4935:
1.1.1.11 root 4936: taskBarCreatedMsg = RegisterWindowMessage ("TaskbarCreated");
4937:
1.1 root 4938: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1.1.13 root 4939:
4940: /* Check system encryption status */
4941:
1.1.1.19 root 4942: 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 4943: {
4944: if (SysEncryptionOrDecryptionRequired ())
4945: {
1.1.1.17 root 4946: if (!MutexExistsOnSystem (TC_MUTEX_NAME_SYSENC)) // If no instance of the wizard is currently taking care of system encryption
1.1.1.13 root 4947: {
1.1.1.17 root 4948: // We shouldn't block the mutex at this point
1.1.1.13 root 4949:
4950: if (SystemEncryptionStatus == SYSENC_STATUS_PRETEST
4951: || AskWarnYesNo ("SYSTEM_ENCRYPTION_RESUME_PROMPT") == IDYES)
4952: {
4953: // The wizard was not launched during the system startup seq, or the user may have forgotten
4954: // to resume the encryption/decryption process.
4955:
4956:
4957: LaunchVolCreationWizard (hwndDlg, "/csysenc");
4958: }
4959: }
4960: }
1.1.1.19 root 4961:
4962: if (bInPlaceEncNonSysPending && !NonSysInplaceEncInProgressElsewhere())
4963: {
1.1.1.21 root 4964: if (AskNonSysInPlaceEncryptionResume() == IDYES)
1.1.1.19 root 4965: ResumeInterruptedNonSysInplaceEncProcess ();
4966: }
1.1.1.13 root 4967: }
1.1.1.17 root 4968:
1.1.1.25 root 4969: if (!DisableSystemCrashDetection
4970: && IsOSAtLeast (WIN_7))
4971: {
4972: // Auto-detect a system crash
4973:
4974: const int detectionPeriodInMonthsSinceReleaseDate = 1;
4975: int maxYear = TC_RELEASE_DATE_YEAR;
4976: int maxMonth = TC_RELEASE_DATE_MONTH + detectionPeriodInMonthsSinceReleaseDate;
4977: if (maxMonth > 12)
4978: {
4979: ++maxYear;
4980: maxMonth -= 12;
4981: }
4982:
4983: SYSTEMTIME systemTime;
4984: GetSystemTime (&systemTime);
4985:
4986: if (systemTime.wYear >= TC_RELEASE_DATE_YEAR
4987: && !(systemTime.wYear == TC_RELEASE_DATE_YEAR && systemTime.wMonth < TC_RELEASE_DATE_MONTH)
4988: && systemTime.wYear <= maxYear
4989: && !(systemTime.wYear == maxYear && systemTime.wMonth > maxMonth))
4990: {
4991: char winDir[MAX_PATH] = { 0 };
4992: GetWindowsDirectory (winDir, sizeof (winDir));
4993:
4994: WIN32_FIND_DATA findData;
4995: HANDLE find = FindFirstFile ((string (winDir) + "\\MEMORY.DMP").c_str(), &findData);
4996:
4997: if (find != INVALID_HANDLE_VALUE)
4998: {
4999: SYSTEMTIME systemTime;
5000: FILETIME ft;
5001: GetSystemTime (&systemTime);
5002: SystemTimeToFileTime (&systemTime, &ft);
5003:
5004: ULARGE_INTEGER sysTime, fileTime;
5005: sysTime.HighPart = ft.dwHighDateTime;
5006: sysTime.LowPart = ft.dwLowDateTime;
5007: fileTime.HighPart = findData.ftLastWriteTime.dwHighDateTime;
5008: fileTime.LowPart = findData.ftLastWriteTime.dwLowDateTime;
5009:
5010: // Memory dump must not be older than 10 minutes
5011: if (sysTime.QuadPart - fileTime.QuadPart < 10I64 * 1000 * 1000 * 60 * 10)
5012: SystemCrashDetected = TRUE;
5013:
5014: FindClose (find);
5015: }
5016: }
5017: }
5018:
1.1.1.17 root 5019: DoPostInstallTasks ();
1.1.1.23 root 5020: ResetCurrentDirectory ();
1.1 root 5021: }
5022: return 0;
1.1.1.25 root 5023:
5024: case WM_MOUSEWHEEL:
5025: return HandleDriveListMouseWheelEvent (uMsg, wParam, lParam, FALSE);
1.1 root 5026:
1.1.1.7 root 5027: case WM_WINDOWPOSCHANGING:
5028: if (MainWindowHidden)
5029: {
1.1.1.13 root 5030: // Prevent window from being shown
1.1.1.7 root 5031: PWINDOWPOS wp = (PWINDOWPOS)lParam;
5032: wp->flags &= ~SWP_SHOWWINDOW;
5033: return 0;
5034: }
5035: return 1;
5036:
1.1 root 5037: case WM_SYSCOMMAND:
5038: if (lw == IDC_ABOUT)
5039: {
1.1.1.7 root 5040: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 5041: return 1;
5042: }
5043: return 0;
5044:
5045: case WM_HELP:
1.1.1.7 root 5046: OpenPageHelp (hwndDlg, 0);
1.1 root 5047: return 1;
5048:
1.1.1.7 root 5049: case WM_ENDSESSION:
5050: if (TaskBarIconMutex != NULL)
1.1 root 5051: {
1.1.1.7 root 5052: if (bDismountOnLogOff)
5053: {
5054: // Auto-dismount when user logs off
5055: DWORD dwResult;
5056:
5057: if (bWipeCacheOnAutoDismount)
1.1.1.13 root 5058: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 5059:
1.1.1.23 root 5060: DismountAll (hwndDlg, bForceAutoDismount, FALSE, 1, 0);
1.1.1.7 root 5061: }
5062:
5063: TaskBarIconRemove (hwndDlg);
5064: }
1.1.1.13 root 5065: EndMainDlg (hwndDlg);
5066: localcleanup ();
1.1.1.7 root 5067: return 0;
5068:
5069: case WM_POWERBROADCAST:
5070: if (wParam == PBT_APMSUSPEND
5071: && TaskBarIconMutex != NULL && bDismountOnPowerSaving)
5072: {
5073: // Auto-dismount when entering power-saving mode
5074: DWORD dwResult;
1.1.1.12 root 5075:
1.1.1.7 root 5076: if (bWipeCacheOnAutoDismount)
1.1.1.19 root 5077: {
1.1.1.13 root 5078: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 5079: SecurityToken::CloseAllSessions();
5080: }
1.1.1.12 root 5081:
1.1.1.23 root 5082: DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7 root 5083: }
5084: return 0;
5085:
5086: case WM_TIMER:
5087: {
5088: // Check mount list and update GUI if needed
5089: CheckMountList ();
5090:
5091: // Cache status
5092: if (IsPasswordCacheEmpty() == IsWindowEnabled (GetDlgItem (hwndDlg, IDC_WIPE_CACHE)))
5093: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
5094:
1.1.1.25 root 5095: // Check driver warning flags
5096: DWORD bytesOut;
5097: GetWarningFlagsRequest warnings;
5098: if (DeviceIoControl (hDriver, TC_IOCTL_GET_WARNING_FLAGS, NULL, 0, &warnings, sizeof (warnings), &bytesOut, NULL))
5099: {
5100: if (warnings.SystemFavoriteVolumeDirty)
5101: WarningTopMost ("SYS_FAVORITE_VOLUME_DIRTY");
5102:
5103: if (warnings.PagingFileCreationPrevented)
5104: WarningTopMost ("PAGING_FILE_CREATION_PREVENTED");
5105: }
5106:
1.1.1.7 root 5107: if (TaskBarIconMutex != NULL)
5108: {
1.1.1.25 root 5109: // Handle system crash
5110: static BOOL systemCrashHandlerLocked = FALSE;
5111: if (SystemCrashDetected && !systemCrashHandlerLocked)
5112: {
5113: systemCrashHandlerLocked = TRUE;
5114:
5115: SetForegroundWindow (hwndDlg);
5116: MainWindowHidden = FALSE;
5117: ShowWindow (hwndDlg, SW_SHOW);
5118: ShowWindow (hwndDlg, SW_RESTORE);
5119:
5120: if (AskYesNo ("SYSTEM_CRASHED_ASK_REPORT") == IDYES)
5121: {
5122: if (!IsAdmin() && IsUacSupported())
5123: UacAnalyzeKernelMiniDump (hwndDlg);
5124: else
5125: AnalyzeKernelMiniDump (hwndDlg);
5126: }
5127: else if (AskYesNo ("ASK_KEEP_DETECTING_SYSTEM_CRASH") == IDNO)
5128: {
5129: DisableSystemCrashDetection = TRUE;
5130: SaveSettings (hwndDlg);
5131: }
5132: }
5133:
1.1.1.7 root 5134: // Idle auto-dismount
5135: if (MaxVolumeIdleTime > 0)
5136: DismountIdleVolumes ();
5137:
5138: // Screen saver auto-dismount
5139: if (bDismountOnScreenSaver)
5140: {
5141: static BOOL previousState = FALSE;
5142: BOOL running = FALSE;
5143: SystemParametersInfo (SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
5144:
5145: if (running && !previousState)
5146: {
5147: DWORD dwResult;
5148: previousState = TRUE;
5149:
5150: if (bWipeCacheOnAutoDismount)
1.1.1.19 root 5151: {
1.1.1.13 root 5152: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 5153: SecurityToken::CloseAllSessions();
5154: }
1.1.1.12 root 5155:
5156: DismountAll (hwndDlg, bForceAutoDismount, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.7 root 5157: }
5158: else
5159: {
5160: previousState = running;
1.1.1.8 root 5161: }
1.1.1.7 root 5162: }
1.1.1.25 root 5163:
5164: // Auto-mount favorite volumes on arrival
5165: #if TIMER_INTERVAL_MAIN != 500
5166: #error TIMER_INTERVAL_MAIN != 500
5167: #endif
5168: static int favoritesAutoMountTimerDivisor = 0;
5169: if ((++favoritesAutoMountTimerDivisor & 1) && !FavoritesOnArrivalMountRequired.empty())
5170: {
5171: static bool reentry = false;
5172: if (reentry)
5173: break;
5174:
5175: reentry = true;
5176:
5177: foreach (FavoriteVolume favorite, FavoritesOnArrivalMountRequired)
5178: {
5179: if (!favorite.VolumePathId.empty())
5180: {
5181: if (IsMountedVolume (favorite.Path.c_str()))
5182: continue;
5183:
5184: char volDevPath[TC_MAX_PATH];
5185: if (QueryDosDevice (favorite.VolumePathId.substr (4, favorite.VolumePathId.size() - 5).c_str(), volDevPath, TC_MAX_PATH) == 0)
5186: continue;
5187:
5188: favorite.DisconnectedDevice = false;
5189: }
5190: else if (favorite.Path.find ("\\\\?\\Volume{") == 0)
5191: {
5192: string resolvedPath = VolumeGuidPathToDevicePath (favorite.Path);
5193: if (resolvedPath.empty())
5194: continue;
5195:
5196: favorite.DisconnectedDevice = false;
5197: favorite.VolumePathId = favorite.Path;
5198: favorite.Path = resolvedPath;
5199: }
5200:
5201: if (IsMountedVolume (favorite.Path.c_str()))
5202: continue;
5203:
5204: if (!IsVolumeDeviceHosted (favorite.Path.c_str()))
5205: {
5206: if (!FileExists (favorite.Path.c_str()))
5207: continue;
5208: }
5209: else if (favorite.VolumePathId.empty())
5210: continue;
5211:
5212: bool mountedAndNotDisconnected = false;
5213: foreach (FavoriteVolume mountedFavorite, FavoritesMountedOnArrivalStillConnected)
5214: {
5215: if (favorite.Path == mountedFavorite.Path)
5216: {
5217: mountedAndNotDisconnected = true;
5218: break;
5219: }
5220: }
5221:
5222: if (!mountedAndNotDisconnected)
5223: {
5224: FavoriteMountOnArrivalInProgress = TRUE;
5225: MountFavoriteVolumes (FALSE, FALSE, FALSE, favorite);
5226: FavoriteMountOnArrivalInProgress = FALSE;
5227:
5228: FavoritesMountedOnArrivalStillConnected.push_back (favorite);
5229: }
5230: }
5231:
5232: bool deleted;
5233: for (list <FavoriteVolume>::iterator favorite = FavoritesMountedOnArrivalStillConnected.begin();
5234: favorite != FavoritesMountedOnArrivalStillConnected.end();
5235: deleted ? favorite : ++favorite)
5236: {
5237: deleted = false;
5238:
5239: if (IsMountedVolume (favorite->Path.c_str()))
5240: continue;
5241:
5242: if (!IsVolumeDeviceHosted (favorite->Path.c_str()))
5243: {
5244: if (FileExists (favorite->Path.c_str()))
5245: continue;
5246: }
5247:
5248: char volDevPath[TC_MAX_PATH];
5249: if (favorite->VolumePathId.size() > 5
5250: && QueryDosDevice (favorite->VolumePathId.substr (4, favorite->VolumePathId.size() - 5).c_str(), volDevPath, TC_MAX_PATH) != 0)
5251: {
5252: continue;
5253: }
5254:
5255: favorite = FavoritesMountedOnArrivalStillConnected.erase (favorite);
5256: deleted = true;
5257: }
5258:
5259: reentry = false;
5260: }
1.1.1.7 root 5261: }
5262:
1.1.1.8 root 5263: // Exit background process in non-install mode or if no volume mounted
1.1.1.7 root 5264: // and no other instance active
5265: if (LastKnownMountList.ulMountedDrives == 0
1.1.1.13 root 5266: && MainWindowHidden
1.1.1.7 root 5267: #ifndef _DEBUG
5268: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
1.1.1.13 root 5269: && !SysEncDeviceActive (TRUE)
1.1.1.25 root 5270: #endif
1.1.1.7 root 5271: && GetDriverRefCount () < 2)
5272: {
5273: TaskBarIconRemove (hwndDlg);
5274: EndMainDlg (hwndDlg);
5275: }
1.1 root 5276: }
1.1.1.13 root 5277: return 1;
1.1 root 5278:
1.1.1.13 root 5279: case TC_APPMSG_TASKBAR_ICON:
1.1 root 5280: {
1.1.1.7 root 5281: switch (lParam)
5282: {
5283: case WM_LBUTTONDOWN:
1.1.1.8 root 5284: SetForegroundWindow (hwndDlg);
1.1.1.7 root 5285: MainWindowHidden = FALSE;
5286: ShowWindow (hwndDlg, SW_SHOW);
1.1.1.13 root 5287: ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.21 root 5288: return 1;
1.1.1.7 root 5289:
1.1.1.21 root 5290: case WM_RBUTTONUP:
1.1.1.7 root 5291: {
5292: POINT pos;
5293: HMENU popup = CreatePopupMenu ();
5294: int sel, i, n;
1.1.1.8 root 5295:
1.1.1.7 root 5296: if (MainWindowHidden)
5297: {
5298: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
5299: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5300: }
5301: else if (bEnableBkgTask
5302: && (!(LastKnownMountList.ulMountedDrives == 0
5303: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
1.1.1.13 root 5304: && !SysEncDeviceActive (TRUE)
1.1.1.7 root 5305: && GetDriverRefCount () < 2)))
5306: {
5307: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
5308: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5309: }
1.1.1.13 root 5310: AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL"));
1.1.1.7 root 5311: AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
5312: AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDM_UNMOUNTALL"));
5313: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5314:
5315: for (n = 0; n < 2; n++)
5316: {
5317: for (i = 0; i < 26; i++)
5318: {
5319: if (LastKnownMountList.ulMountedDrives & (1 << i))
5320: {
5321: wchar_t s[1024];
1.1.1.13 root 5322: wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[i];
1.1.1.7 root 5323:
5324: if (wcsstr (vol, L"\\??\\")) vol += 4;
5325:
1.1.1.25 root 5326: wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol));
5327:
1.1.1.7 root 5328: wsprintfW (s, L"%s %c: (%s)",
5329: GetString (n==0 ? "OPEN" : "DISMOUNT"),
5330: i + L'A',
1.1.1.25 root 5331: label.empty() ? vol : label.c_str());
1.1.1.13 root 5332: AppendMenuW (popup, MF_STRING, n*26 + TRAYICON_MENU_DRIVE_OFFSET + i, s);
1.1.1.7 root 5333: }
5334: }
5335: if (LastKnownMountList.ulMountedDrives != 0)
5336: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5337: }
5338:
5339: AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
1.1.1.11 root 5340: AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
1.1.1.7 root 5341: AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
5342: AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
5343: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.13 root 5344: AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT"));
1.1.1.7 root 5345:
5346: GetCursorPos (&pos);
5347:
5348: SetForegroundWindow(hwndDlg);
5349:
5350: sel = TrackPopupMenu (popup,
5351: TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
5352: pos.x,
5353: pos.y,
5354: 0,
5355: hwndDlg,
5356: NULL);
5357:
1.1.1.13 root 5358: if (sel >= TRAYICON_MENU_DRIVE_OFFSET && sel < TRAYICON_MENU_DRIVE_OFFSET + 26)
1.1.1.7 root 5359: {
1.1.1.13 root 5360: OpenVolumeExplorerWindow (sel - TRAYICON_MENU_DRIVE_OFFSET);
1.1.1.7 root 5361: }
1.1.1.13 root 5362: else if (sel >= TRAYICON_MENU_DRIVE_OFFSET + 26 && sel < TRAYICON_MENU_DRIVE_OFFSET + 26*2)
1.1.1.7 root 5363: {
5364: if (CheckMountList ())
1.1.1.13 root 5365: Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26);
1.1.1.7 root 5366: }
5367: else if (sel == IDM_SHOW_HIDE)
5368: {
1.1.1.13 root 5369: ChangeMainWindowVisibility ();
1.1.1.7 root 5370: }
1.1.1.11 root 5371: else if (sel == IDM_HOMEPAGE_SYSTRAY)
5372: {
5373: Applink ("home", TRUE, "");
5374: }
1.1.1.13 root 5375: else if (sel == IDCANCEL)
1.1.1.7 root 5376: {
1.1.1.13 root 5377: if ((LastKnownMountList.ulMountedDrives == 0
5378: && !SysEncDeviceActive (TRUE))
1.1.1.7 root 5379: || AskWarnNoYes ("CONFIRM_EXIT") == IDYES)
5380: {
5381: // Close all other TC windows
5382: EnumWindows (CloseTCWindowsEnum, 0);
5383:
5384: TaskBarIconRemove (hwndDlg);
5385: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
5386: }
5387: }
5388: else
5389: {
5390: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
5391: }
5392:
5393: PostMessage(hwndDlg, WM_NULL, 0, 0);
5394: DestroyMenu (popup);
5395: }
1.1.1.21 root 5396: return 1;
1.1 root 5397: }
1.1.1.7 root 5398: }
5399:
1.1.1.21 root 5400: return 0;
5401:
1.1.1.13 root 5402: case TC_APPMSG_CLOSE_BKG_TASK:
1.1.1.11 root 5403: if (TaskBarIconMutex != NULL)
5404: TaskBarIconRemove (hwndDlg);
5405:
5406: return 1;
5407:
1.1.1.13 root 5408: case TC_APPMSG_SYSENC_CONFIG_UPDATE:
5409: LoadSysEncSettings (hwndDlg);
5410:
1.1.1.16 root 5411: // The wizard added TrueCrypt.exe to the system startup sequence or performed other operations that
5412: // require us to update our cached settings.
1.1.1.13 root 5413: LoadSettings (hwndDlg);
5414:
5415: return 1;
5416:
1.1.1.11 root 5417: case WM_DEVICECHANGE:
1.1.1.12 root 5418: if (!IgnoreWmDeviceChange && wParam != DBT_DEVICEARRIVAL)
1.1.1.11 root 5419: {
5420: // Check if any host device has been removed and force dismount of volumes accordingly
5421: PDEV_BROADCAST_HDR hdr = (PDEV_BROADCAST_HDR) lParam;
1.1.1.12 root 5422: int m;
5423:
5424: GetMountList (&LastKnownMountList);
5425:
1.1.1.11 root 5426: if (wParam == DBT_DEVICEREMOVECOMPLETE && hdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
5427: {
1.1.1.12 root 5428: // File-hosted volumes
1.1.1.11 root 5429: PDEV_BROADCAST_VOLUME vol = (PDEV_BROADCAST_VOLUME) lParam;
1.1.1.12 root 5430: int i;
1.1.1.11 root 5431:
5432: for (i = 0; i < 26; i++)
5433: {
1.1.1.25 root 5434: if ((vol->dbcv_unitmask & (1 << i)) && !(GetLogicalDrives() & (1 << i)))
1.1.1.11 root 5435: {
5436: for (m = 0; m < 26; m++)
5437: {
5438: if (LastKnownMountList.ulMountedDrives & (1 << m))
5439: {
1.1.1.13 root 5440: wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.11 root 5441:
1.1.1.12 root 5442: if (wcsstr (vol, L"\\??\\") == vol)
1.1.1.11 root 5443: vol += 4;
5444:
1.1.1.12 root 5445: if (vol[1] == L':' && i == (vol[0] - (vol[0] <= L'Z' ? L'A' : L'a')))
1.1.1.11 root 5446: UnmountVolume (hwndDlg, m, TRUE);
5447: }
5448: }
5449: }
5450: }
1.1.1.12 root 5451: }
1.1.1.11 root 5452:
1.1.1.12 root 5453: // Device-hosted volumes
5454: for (m = 0; m < 26; m++)
5455: {
5456: if (LastKnownMountList.ulMountedDrives & (1 << m))
5457: {
1.1.1.13 root 5458: wchar_t *vol = (wchar_t *) LastKnownMountList.wszVolume[m];
1.1.1.12 root 5459: char volp[MAX_PATH];
5460:
5461: if (wcsstr (vol, L"\\??\\") == vol)
5462: vol += 4;
5463:
5464: _snprintf (volp, sizeof(volp), "%ls", vol);
5465:
5466: if (IsVolumeDeviceHosted (volp))
5467: {
5468: OPEN_TEST_STRUCT ots;
5469:
1.1.1.21 root 5470: if (!OpenDevice (volp, &ots, FALSE))
1.1.1.12 root 5471: UnmountVolume (hwndDlg, m, TRUE);
5472: }
5473: }
1.1.1.11 root 5474: }
1.1.1.25 root 5475:
5476: // Favorite volumes
5477: UpdateDeviceHostedFavoriteVolumes();
5478:
1.1.1.12 root 5479: return 1;
1.1.1.11 root 5480: }
1.1.1.12 root 5481: return 0;
1.1.1.11 root 5482:
1.1.1.7 root 5483: case WM_NOTIFY:
5484:
5485: if(wParam == IDC_DRIVELIST)
5486: {
1.1.1.23 root 5487: if (((LPNMHDR) lParam)->code == NM_CUSTOMDRAW)
5488: {
5489: int width = ListView_GetColumnWidth (GetDlgItem (hwndDlg, IDC_DRIVELIST), 1);
5490: if (width != LastDriveListVolumeColumnWidth)
5491: {
5492: LastDriveListVolumeColumnWidth = width;
5493: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
5494: }
5495: return 0;
5496: }
5497:
1.1.1.7 root 5498: /* Single click within drive list */
5499: if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
5500: {
5501: nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
5502: EnableDisableButtons (hwndDlg);
5503: return 1;
5504: }
5505:
5506: /* Double click within drive list */
5507: if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1.1 root 5508: {
1.1.1.13 root 5509: int state = GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
1.1.1.7 root 5510: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
1.1.1.13 root 5511: if (LOWORD(state) == TC_MLIST_ITEM_NONSYS_VOL || LOWORD(state) == TC_MLIST_ITEM_SYS_PARTITION)
1.1.1.7 root 5512: {
5513: // Open explorer window for mounted volume
1.1.1.11 root 5514: WaitCursor ();
1.1.1.7 root 5515: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
5516: NormalCursor ();
5517: }
1.1.1.13 root 5518: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
1.1.1.7 root 5519: {
1.1.1.11 root 5520: mountOptions = defaultMountOptions;
1.1.1.15 root 5521: bPrebootPasswordDlgMode = FALSE;
1.1.1.11 root 5522:
1.1.1.9 root 5523: if (GetAsyncKeyState (VK_CONTROL) < 0)
5524: {
5525: if (IDCANCEL == DialogBoxParamW (hInst,
5526: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
5527: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
5528: return 1;
5529:
5530: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1.1.1.12 root 5531: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
1.1.1.9 root 5532: }
5533:
1.1.1.7 root 5534: if (CheckMountList ())
5535: Mount (hwndDlg, 0, 0);
5536: }
5537: return 1;
5538: }
5539:
5540: /* Right click and drag&drop operations */
1.1.1.13 root 5541:
5542: switch (((NM_LISTVIEW *) lParam)->hdr.code)
1.1.1.7 root 5543: {
5544: case NM_RCLICK:
5545: case LVN_BEGINRDRAG:
5546: /* If the mouse was moving while the right mouse button is pressed, popup menu would
5547: not open, because drag&drop operation would be initiated. Therefore, we're handling
5548: RMB drag-and-drop operations as well. */
5549: {
5550:
5551: /* Drive list context menu */
5552:
5553: int menuItem;
5554: HMENU popup = CreatePopupMenu ();
5555:
5556: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
5557:
1.1.1.13 root 5558: switch (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))))
1.1.1.7 root 5559: {
1.1.1.13 root 5560: case TC_MLIST_ITEM_FREE:
5561:
1.1.1.7 root 5562: // No mounted volume at this drive letter
1.1.1.13 root 5563:
1.1.1.7 root 5564: AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
1.1.1.19 root 5565: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5566: AppendMenuW (popup, MF_STRING, IDPM_SELECT_FILE_AND_MOUNT, GetString ("SELECT_FILE_AND_MOUNT"));
5567: AppendMenuW (popup, MF_STRING, IDPM_SELECT_DEVICE_AND_MOUNT, GetString ("SELECT_DEVICE_AND_MOUNT"));
1.1.1.13 root 5568: break;
5569:
5570: case TC_MLIST_ITEM_NONSYS_VOL:
5571:
5572: // There's a mounted non-system volume at this drive letter
5573:
1.1.1.7 root 5574: AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
5575: AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
5576: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
5577: AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
5578: AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
5579: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.25 root 5580: AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_FAVORITES, GetString ("IDPM_ADD_TO_FAVORITES"));
5581: AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_SYSTEM_FAVORITES, GetString ("IDPM_ADD_TO_SYSTEM_FAVORITES"));
5582: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.7 root 5583: AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
1.1.1.13 root 5584: break;
5585:
5586: case TC_MLIST_ITEM_SYS_PARTITION:
5587: case TC_MLIST_ITEM_SYS_DRIVE:
5588:
5589: // System partition/drive
5590:
5591: PopulateSysEncContextMenu (popup, FALSE);
5592: break;
1.1.1.7 root 5593: }
5594:
5595: mPos=GetMessagePos();
5596:
5597: menuItem = TrackPopupMenu (popup,
5598: TPM_RETURNCMD | TPM_LEFTBUTTON,
5599: GET_X_LPARAM(mPos),
5600: GET_Y_LPARAM(mPos),
5601: 0,
5602: hwndDlg,
5603: NULL);
5604:
5605: DestroyMenu (popup);
5606:
5607: switch (menuItem)
5608: {
1.1.1.19 root 5609: case IDPM_SELECT_FILE_AND_MOUNT:
5610: if (SelectContainer (hwndDlg))
5611: MountSelectedVolume (hwndDlg, FALSE);
5612: break;
5613:
5614: case IDPM_SELECT_DEVICE_AND_MOUNT:
5615: if (SelectPartition (hwndDlg))
5616: MountSelectedVolume (hwndDlg, FALSE);
5617: break;
5618:
1.1.1.7 root 5619: case IDPM_CHECK_FILESYS:
5620: case IDPM_REPAIR_FILESYS:
5621: {
5622: LPARAM lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
5623:
5624: if (LOWORD (lLetter) != 0xffff)
1.1.1.19 root 5625: CheckFilesystem ((char) HIWORD (lLetter) - 'A', menuItem == IDPM_REPAIR_FILESYS);
1.1.1.7 root 5626: }
5627: break;
5628:
5629: case IDM_UNMOUNT_VOLUME:
5630: if (CheckMountList ())
5631: Dismount (hwndDlg, 0);
5632: break;
5633:
5634: case IDPM_OPEN_VOLUME:
5635: {
5636: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
5637: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
5638:
1.1.1.11 root 5639: WaitCursor ();
1.1.1.7 root 5640: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
5641: NormalCursor ();
5642: }
5643: break;
5644:
5645: case IDM_VOLUME_PROPERTIES:
5646: DialogBoxParamW (hInst,
5647: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1.1.13 root 5648: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) FALSE);
1.1.1.7 root 5649: break;
5650:
5651: case IDM_MOUNT_VOLUME:
5652: if (!VolumeSelected(hwndDlg))
5653: {
5654: Warning ("NO_VOLUME_SELECTED");
5655: }
5656: else
5657: {
5658: mountOptions = defaultMountOptions;
1.1.1.15 root 5659: bPrebootPasswordDlgMode = FALSE;
1.1.1.7 root 5660:
5661: if (CheckMountList ())
5662: Mount (hwndDlg, 0, 0);
5663: }
5664: break;
1.1.1.19 root 5665:
1.1.1.25 root 5666: case IDPM_ADD_TO_FAVORITES:
5667: case IDPM_ADD_TO_SYSTEM_FAVORITES:
5668: {
5669: LPARAM selectedDrive = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
5670:
5671: if (LOWORD (selectedDrive) == TC_MLIST_ITEM_NONSYS_VOL)
5672: AddMountedVolumeToFavorites (hwndDlg, HIWORD (selectedDrive) - 'A', menuItem == IDPM_ADD_TO_SYSTEM_FAVORITES);
5673: }
5674: break;
5675:
1.1.1.19 root 5676: default:
5677: SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
1.1.1.13 root 5678: break;
1.1.1.7 root 5679: }
5680: return 1;
5681: }
1.1 root 5682: }
5683: }
5684: return 0;
5685:
5686: case WM_ERASEBKGND:
5687: return 0;
5688:
5689: case WM_COMMAND:
5690:
1.1.1.13 root 5691: if (lw == IDCANCEL || lw == IDC_EXIT)
1.1 root 5692: {
5693: EndMainDlg (hwndDlg);
5694: return 1;
5695: }
5696:
5697: if (lw == IDHELP || lw == IDM_HELP)
5698: {
1.1.1.7 root 5699: OpenPageHelp (hwndDlg, 0);
1.1 root 5700: return 1;
5701: }
5702:
1.1.1.12 root 5703: if (lw == IDM_ABOUT || lw == IDC_LOGO)
1.1 root 5704: {
1.1.1.7 root 5705: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 5706: return 1;
5707: }
5708:
1.1.1.13 root 5709: if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_NONSYS_VOL
1.1.1.7 root 5710: || lw == IDM_UNMOUNT_VOLUME)
1.1 root 5711: {
1.1.1.13 root 5712: if (lw == IDM_UNMOUNT_VOLUME && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) != TC_MLIST_ITEM_NONSYS_VOL)
1.1.1.6 root 5713: {
1.1.1.7 root 5714: Warning ("SELECT_A_MOUNTED_VOLUME");
5715: return 1;
1.1.1.6 root 5716: }
1.1 root 5717:
1.1.1.7 root 5718: if (CheckMountList ())
5719: Dismount (hwndDlg, 0);
1.1 root 5720: return 1;
5721: }
5722:
1.1.1.7 root 5723: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS || lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 5724: && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
5725: {
1.1.1.7 root 5726: MessageBoxW (hwndDlg, GetString ("SELECT_FREE_DRIVE"), L"TrueCrypt", MB_ICONEXCLAMATION);
1.1 root 5727: return 1;
5728: }
5729:
1.1.1.7 root 5730: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS))
1.1 root 5731: {
1.1.1.19 root 5732: MountSelectedVolume (hwndDlg, lw == IDM_MOUNT_VOLUME_OPTIONS);
1.1 root 5733: return 1;
5734: }
5735:
1.1.1.7 root 5736: if (lw == IDC_UNMOUNTALL || lw == IDM_UNMOUNTALL)
1.1 root 5737: {
1.1.1.7 root 5738: DismountAll (hwndDlg, bForceUnmount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1 root 5739: return 1;
5740: }
5741:
1.1.1.7 root 5742: if (lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 5743: {
1.1.1.7 root 5744: // If Shift key is down and the password cache isn't empty, bypass password prompt
5745: MountAllDevices (hwndDlg, !(GetAsyncKeyState (VK_SHIFT) < 0 && !IsPasswordCacheEmpty()));
1.1 root 5746: return 1;
5747: }
5748:
1.1.1.7 root 5749: if (lw == IDC_SELECT_FILE || lw == IDM_SELECT_FILE)
1.1 root 5750: {
5751: SelectContainer (hwndDlg);
5752: return 1;
5753: }
5754:
1.1.1.7 root 5755: if (lw == IDC_SELECT_DEVICE || lw == IDM_SELECT_DEVICE)
1.1 root 5756: {
5757: SelectPartition (hwndDlg);
5758: return 1;
5759: }
5760:
1.1.1.13 root 5761: // System Encryption menu
5762: switch (lw)
5763: {
5764: case IDM_ENCRYPT_SYSTEM_DEVICE:
5765: EncryptSystemDevice ();
5766: break;
5767: case IDM_PERMANENTLY_DECRYPT_SYS:
5768: DecryptSystemDevice ();
5769: break;
1.1.1.17 root 5770: case IDM_CREATE_HIDDEN_OS:
5771: CreateHiddenOS ();
5772: break;
1.1.1.13 root 5773: case IDM_SYSENC_RESUME:
5774: ResumeInterruptedSysEncProcess ();
5775: break;
5776: case IDM_SYSTEM_ENCRYPTION_STATUS:
5777: ShowSystemEncryptionStatus ();
5778: break;
5779: case IDM_CHANGE_SYS_PASSWORD:
5780: ChangeSysEncPassword (hwndDlg, FALSE);
5781: break;
5782: case IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO:
5783: ChangeSysEncPassword (hwndDlg, TRUE);
5784: break;
5785: case IDM_CREATE_RESCUE_DISK:
5786: CreateRescueDisk ();
5787: break;
5788: case IDM_VERIFY_RESCUE_DISK:
5789: VerifyRescueDisk ();
5790: break;
1.1.1.15 root 5791: case IDM_MOUNT_SYSENC_PART_WITHOUT_PBA:
5792:
5793: if (CheckSysEncMountWithoutPBA ("", FALSE))
5794: {
5795: mountOptions = defaultMountOptions;
5796: bPrebootPasswordDlgMode = TRUE;
5797:
5798: if (CheckMountList ())
5799: Mount (hwndDlg, 0, 0);
5800:
5801: bPrebootPasswordDlgMode = FALSE;
5802: }
5803: break;
1.1.1.13 root 5804: }
5805:
1.1.1.7 root 5806: if (lw == IDC_VOLUME_TOOLS)
5807: {
1.1.1.13 root 5808: /* Volume Tools popup menu */
5809:
1.1.1.7 root 5810: int menuItem;
5811: char volPath[TC_MAX_PATH]; /* Volume to mount */
5812: HMENU popup = CreatePopupMenu ();
5813: RECT rect;
5814:
1.1.1.13 root 5815: if (ActiveSysEncDeviceSelected ())
5816: {
5817: PopulateSysEncContextMenu (popup, TRUE);
5818: }
5819: else
5820: {
5821: AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
5822: AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
5823: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.25 root 5824: AppendMenuW (popup, MF_STRING, IDM_ADD_REMOVE_VOL_KEYFILES, GetString ("IDM_ADD_REMOVE_VOL_KEYFILES"));
5825: AppendMenuW (popup, MF_STRING, IDM_REMOVE_ALL_KEYFILES_FROM_VOL, GetString ("IDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
5826: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
1.1.1.13 root 5827: AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
5828: AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
5829: }
1.1.1.7 root 5830:
5831: GetWindowRect (GetDlgItem (hwndDlg, IDC_VOLUME_TOOLS), &rect);
5832:
5833: menuItem = TrackPopupMenu (popup,
5834: TPM_RETURNCMD | TPM_LEFTBUTTON,
5835: rect.left + 2,
5836: rect.top + 2,
5837: 0,
5838: hwndDlg,
5839: NULL);
5840:
5841: DestroyMenu (popup);
5842:
5843: switch (menuItem)
5844: {
5845: case IDM_CHANGE_PASSWORD:
5846: if (!VolumeSelected(hwndDlg))
5847: {
5848: Warning ("NO_VOLUME_SELECTED");
5849: }
5850: else
5851: {
5852: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
5853: ChangePassword (hwndDlg);
5854: }
5855: break;
5856:
5857: case IDM_CHANGE_HEADER_KEY_DERIV_ALGO:
5858: if (!VolumeSelected(hwndDlg))
5859: {
5860: Warning ("NO_VOLUME_SELECTED");
5861: }
5862: else
5863: {
5864: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
5865: ChangePassword (hwndDlg);
5866: }
5867: break;
5868:
1.1.1.25 root 5869: case IDM_ADD_REMOVE_VOL_KEYFILES:
5870: if (!VolumeSelected(hwndDlg))
5871: {
5872: Warning ("NO_VOLUME_SELECTED");
5873: }
5874: else
5875: {
5876: pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
5877: ChangePassword (hwndDlg);
5878: }
5879: break;
5880:
5881: case IDM_REMOVE_ALL_KEYFILES_FROM_VOL:
5882: if (!VolumeSelected(hwndDlg))
5883: {
5884: Warning ("NO_VOLUME_SELECTED");
5885: }
5886: else
5887: {
5888: pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
5889: ChangePassword (hwndDlg);
5890: }
5891: break;
5892:
1.1.1.7 root 5893: case IDM_BACKUP_VOL_HEADER:
5894: if (!VolumeSelected(hwndDlg))
5895: {
5896: Warning ("NO_VOLUME_SELECTED");
5897: }
5898: else
5899: {
5900: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
5901:
1.1.1.19 root 5902: WaitCursor ();
5903:
1.1.1.11 root 5904: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
5905: UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
5906: else
5907: BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.19 root 5908:
5909: NormalCursor ();
1.1.1.7 root 5910: }
5911: break;
5912:
5913: case IDM_RESTORE_VOL_HEADER:
5914: if (!VolumeSelected(hwndDlg))
5915: {
5916: Warning ("NO_VOLUME_SELECTED");
5917: }
5918: else
5919: {
5920: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
5921:
1.1.1.19 root 5922: WaitCursor ();
5923:
1.1.1.11 root 5924: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
5925: UacRestoreVolumeHeader (hwndDlg, volPath);
5926: else
5927: RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.19 root 5928:
5929: NormalCursor ();
1.1.1.7 root 5930: }
5931: break;
1.1.1.13 root 5932:
1.1.1.19 root 5933: default:
5934: SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
1.1.1.13 root 5935: break;
1.1.1.7 root 5936: }
5937: return 1;
5938: }
5939:
5940: if (lw == IDM_CHANGE_PASSWORD)
1.1 root 5941: {
1.1.1.7 root 5942: if (!VolumeSelected(hwndDlg))
5943: {
5944: Warning ("NO_VOLUME_SELECTED");
5945: }
5946: else
5947: {
1.1.1.13 root 5948: if (ActiveSysEncDeviceSelected ())
5949: {
5950: ChangeSysEncPassword (hwndDlg, FALSE);
5951: }
5952: else
5953: {
5954: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
5955: ChangePassword (hwndDlg);
5956: }
1.1.1.7 root 5957: }
1.1 root 5958: return 1;
5959: }
5960:
1.1.1.7 root 5961: if (lw == IDM_CHANGE_HEADER_KEY_DERIV_ALGO)
5962: {
5963: if (!VolumeSelected(hwndDlg))
5964: {
5965: Warning ("NO_VOLUME_SELECTED");
5966: }
5967: else
5968: {
1.1.1.13 root 5969: if (ActiveSysEncDeviceSelected ())
5970: {
5971: ChangeSysEncPassword (hwndDlg, TRUE);
5972: }
5973: else
5974: {
5975: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
5976: ChangePassword (hwndDlg);
5977: }
1.1.1.7 root 5978: }
5979: return 1;
5980: }
5981:
5982: if (lw == IDC_WIPE_CACHE || lw == IDM_WIPE_CACHE)
1.1 root 5983: {
1.1.1.21 root 5984: WipeCache (hwndDlg, FALSE);
1.1 root 5985: return 1;
5986: }
5987:
1.1.1.7 root 5988: if (lw == IDM_CLEAR_HISTORY)
1.1 root 5989: {
1.1.1.11 root 5990: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1 root 5991: EnableDisableButtons (hwndDlg);
5992: return 1;
5993: }
5994:
1.1.1.7 root 5995: if (lw == IDC_CREATE_VOLUME || lw == IDM_CREATE_VOLUME || lw == IDM_VOLUME_WIZARD)
1.1 root 5996: {
1.1.1.13 root 5997: LaunchVolCreationWizard (hwndDlg, "");
1.1 root 5998: return 1;
5999: }
6000:
1.1.1.7 root 6001: if (lw == IDM_ADD_REMOVE_VOL_KEYFILES)
1.1.1.3 root 6002: {
1.1.1.7 root 6003: if (!VolumeSelected(hwndDlg))
6004: {
6005: Warning ("NO_VOLUME_SELECTED");
6006: }
6007: else
6008: {
6009: pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
6010: ChangePassword (hwndDlg);
6011: }
6012: return 1;
6013: }
1.1.1.3 root 6014:
1.1.1.7 root 6015: if (lw == IDM_REMOVE_ALL_KEYFILES_FROM_VOL)
6016: {
6017: if (!VolumeSelected(hwndDlg))
1.1.1.3 root 6018: {
1.1.1.7 root 6019: Warning ("NO_VOLUME_SELECTED");
6020: }
6021: else
6022: {
6023: pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
6024: ChangePassword (hwndDlg);
1.1.1.3 root 6025: }
6026: return 1;
6027: }
1.1.1.7 root 6028:
1.1.1.19 root 6029: if (lw == IDM_MANAGE_TOKEN_KEYFILES)
6030: {
6031: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_KEYFILES), hwndDlg, (DLGPROC) SecurityTokenKeyfileDlgProc, NULL);
6032: return 1;
6033: }
6034:
6035: if (lw == IDM_CLOSE_ALL_TOKEN_SESSIONS)
6036: {
6037: {
1.1.1.23 root 6038: WaitCursor();
6039: finally_do ({ NormalCursor(); });
1.1.1.19 root 6040:
1.1.1.23 root 6041: SecurityToken::CloseAllSessions();
1.1.1.19 root 6042: }
1.1.1.23 root 6043: Info ("ALL_TOKEN_SESSIONS_CLOSED");
1.1.1.19 root 6044:
6045: return 1;
6046: }
6047:
1.1.1.25 root 6048: if (lw == IDM_KEYFILE_GENERATOR)
1.1.1.7 root 6049: {
6050: DialogBoxParamW (hInst,
6051: MAKEINTRESOURCEW (IDD_KEYFILE_GENERATOR), hwndDlg,
6052: (DLGPROC) KeyfileGeneratorDlgProc, (LPARAM) 0);
6053:
6054: return 1;
6055: }
6056:
6057: if (lw == IDM_LICENSE)
6058: {
1.1.1.13 root 6059: TextInfoDialogBox (TC_TBXID_LEGAL_NOTICES);
1.1.1.7 root 6060: return 1;
6061: }
1.1.1.3 root 6062:
1.1.1.11 root 6063: if (lw == IDM_WEBSITE)
1.1.1.7 root 6064: {
1.1.1.11 root 6065: Applink ("website", TRUE, "");
6066: return 1;
6067: }
6068: else if (lw == IDM_HOMEPAGE)
6069: {
6070: Applink ("homepage", TRUE, "");
1.1.1.7 root 6071: return 1;
6072: }
6073: else if (lw == IDM_FORUMS)
1.1 root 6074: {
1.1.1.11 root 6075: Applink ("forum", TRUE, "");
1.1.1.5 root 6076: return 1;
6077: }
1.1.1.9 root 6078: else if (lw == IDM_ONLINE_TUTORIAL)
6079: {
1.1.1.11 root 6080: Applink ("tutorial", TRUE, "");
1.1.1.9 root 6081: return 1;
6082: }
6083: else if (lw == IDM_ONLINE_HELP)
6084: {
1.1.1.10 root 6085: OpenOnlineHelp ();
1.1.1.9 root 6086: return 1;
6087: }
1.1.1.7 root 6088: else if (lw == IDM_FAQ)
6089: {
1.1.1.11 root 6090: Applink ("faq", TRUE, "");
1.1.1.7 root 6091: return 1;
6092: }
6093: else if (lw == IDM_TC_DOWNLOADS)
1.1.1.5 root 6094: {
1.1.1.11 root 6095: Applink ("downloads", TRUE, "");
1.1 root 6096: return 1;
6097: }
1.1.1.7 root 6098: else if (lw == IDM_NEWS)
6099: {
1.1.1.11 root 6100: Applink ("news", TRUE, "");
1.1.1.7 root 6101: return 1;
6102: }
6103: else if (lw == IDM_VERSION_HISTORY)
1.1.1.6 root 6104: {
1.1.1.11 root 6105: Applink ("history", TRUE, "");
1.1.1.6 root 6106: return 1;
6107: }
1.1.1.7 root 6108: else if (lw == IDM_BUGREPORT)
6109: {
1.1.1.11 root 6110: Applink ("bugreport", TRUE, "");
6111: return 1;
6112: }
1.1.1.25 root 6113: else if (lw == IDM_ANALYZE_SYSTEM_CRASH)
6114: {
6115: if (!IsAdmin() && IsUacSupported())
6116: UacAnalyzeKernelMiniDump (hwndDlg);
6117: else
6118: AnalyzeKernelMiniDump (hwndDlg);
6119:
6120: return 1;
6121: }
1.1.1.11 root 6122: else if (lw == IDM_DONATIONS)
6123: {
6124: Applink ("donations", FALSE, "");
1.1.1.7 root 6125: return 1;
6126: }
6127: else if (lw == IDM_CONTACT)
1.1 root 6128: {
1.1.1.11 root 6129: Applink ("contact", FALSE, "");
1.1.1.7 root 6130: return 1;
6131: }
6132:
6133: if (lw == IDM_PREFERENCES)
6134: {
6135: if (IDOK == DialogBoxParamW (hInst,
6136: MAKEINTRESOURCEW (IDD_PREFERENCES_DLG), hwndDlg,
6137: (DLGPROC) PreferencesDlgProc, (LPARAM) 0))
6138: {
6139: if (bEnableBkgTask)
1.1.1.12 root 6140: {
1.1.1.7 root 6141: TaskBarIconAdd (hwndDlg);
1.1.1.12 root 6142: }
1.1.1.7 root 6143: else
1.1.1.12 root 6144: {
1.1.1.7 root 6145: TaskBarIconRemove (hwndDlg);
1.1.1.13 root 6146: if (MainWindowHidden)
1.1.1.12 root 6147: EndMainDlg (hwndDlg);
6148: }
1.1.1.7 root 6149: }
6150: return 1;
6151: }
6152:
6153: if (lw == IDM_HOTKEY_SETTINGS)
6154: {
6155: DialogBoxParamW (hInst,
6156: MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
6157: (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
6158: return 1;
6159: }
6160:
1.1.1.25 root 6161: if (lw == IDM_PERFORMANCE_SETTINGS)
6162: {
6163: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_PERFORMANCE_SETTINGS), hwndDlg, (DLGPROC) PerformanceSettingsDlgProc, 0);
6164: return 1;
6165: }
6166:
6167: if (lw == IDM_DEFAULT_KEYFILES)
1.1.1.7 root 6168: {
6169: KeyfileDefaultsDlg (hwndDlg);
1.1 root 6170: return 1;
6171: }
6172:
1.1.1.25 root 6173: if (lw == IDM_ADD_VOLUME_TO_FAVORITES || lw == IDM_ADD_VOLUME_TO_SYSTEM_FAVORITES)
6174: {
6175: LPARAM selectedDrive = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
6176:
6177: char volPathLower[TC_MAX_PATH];
6178: wchar_t volPathLowerW[TC_MAX_PATH];
6179:
6180: // volPathLower will contain the volume path (if any) from the input field below the drive list
6181: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPathLower, sizeof (volPathLower));
6182:
6183: if (LOWORD (selectedDrive) != TC_MLIST_ITEM_NONSYS_VOL
6184: && !(VolumeSelected (hwndDlg) && IsMountedVolume (volPathLower)))
6185: {
6186: Warning ("SELECT_A_MOUNTED_VOLUME");
6187:
6188: return 1;
6189: }
6190:
6191: int driveNo;
6192:
6193: if (VolumeSelected (hwndDlg)
6194: && IsMountedVolume (volPathLower))
6195: {
6196: if (LOWORD (selectedDrive) != TC_MLIST_ITEM_NONSYS_VOL)
6197: {
6198: driveNo = GetMountedVolumeDriveNo (volPathLower);
6199: }
6200: else
6201: {
6202: /* We need to resolve selection ambiguity. Two different mounted volumes are currently
6203: selected (one in the drive letter list and the other in the input field below the list). */
6204:
6205: VOLUME_PROPERTIES_STRUCT prop;
6206: DWORD dwResult;
6207:
6208: memset (&prop, 0, sizeof(prop));
6209: prop.driveNo = HIWORD (selectedDrive) - 'A';
6210:
6211: if (!DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop, sizeof (prop), &prop, sizeof (prop), &dwResult, NULL) || dwResult == 0)
6212: {
6213: Warning ("SELECT_A_MOUNTED_VOLUME");
6214: return 1;
6215: }
6216:
6217: // volPathHigher will contain the volume path selected in the main drive list
6218: wstring volPathHigher (prop.wszVolume);
6219:
6220: ToSBCS (prop.wszVolume);
6221: strcpy ((char *) volPathLowerW, volPathLower);
6222: ToUNICODE ((char *) volPathLowerW);
6223:
6224: if (strcmp (((memcmp ((char *) prop.wszVolume, "\\??\\", 4) == 0) ? (char *) prop.wszVolume + 4 : (char *) prop.wszVolume), volPathLower) != 0)
6225: {
6226: // The path selected in the input field is different from the path to the volume selected
6227: // in the drive lettter list. We have to resolve possible ambiguity.
6228:
6229: wchar_t *tmp[] = {L"", L"", L"", L"", L"", 0};
6230: const int maxVolPathLen = 80;
6231:
6232: if (volPathHigher.length () > maxVolPathLen)
6233: {
6234: volPathHigher = wstring (L"...") + volPathHigher.substr (volPathHigher.length () - maxVolPathLen, maxVolPathLen);
6235: }
6236:
6237: wstring volPathLowerWStr (volPathLowerW);
6238:
6239: if (volPathLowerWStr.length () > maxVolPathLen)
6240: {
6241: volPathLowerWStr = wstring (L"...") + volPathLowerWStr.substr (volPathLowerWStr.length () - maxVolPathLen, maxVolPathLen);
6242: }
6243:
6244: tmp[1] = GetString ("AMBIGUOUS_VOL_SELECTION");
6245: tmp[2] = (wchar_t *) volPathHigher.c_str();
6246: tmp[3] = (wchar_t *) volPathLowerWStr.c_str();
6247: tmp[4] = GetString ("IDCANCEL");
6248:
6249: switch (AskMultiChoice ((void **) tmp, FALSE))
6250: {
6251: case 1:
6252: driveNo = HIWORD (selectedDrive) - 'A';
6253: break;
6254:
6255: case 2:
6256: driveNo = GetMountedVolumeDriveNo (volPathLower);
6257: break;
6258:
6259: default:
6260: return 1;
6261: }
6262: }
6263: else
6264: {
6265: driveNo = HIWORD (selectedDrive) - 'A';
6266: }
6267: }
6268: }
6269: else
6270: {
6271: driveNo = HIWORD (selectedDrive) - 'A';
6272: }
6273:
6274: AddMountedVolumeToFavorites (hwndDlg, driveNo, lw == IDM_ADD_VOLUME_TO_SYSTEM_FAVORITES);
6275:
6276: return 1;
6277: }
6278:
6279: if (lw == IDM_ORGANIZE_FAVORITES || lw == IDM_ORGANIZE_SYSTEM_FAVORITES)
6280: {
6281: OrganizeFavoriteVolumes (hwndDlg, lw == IDM_ORGANIZE_SYSTEM_FAVORITES);
6282: return 1;
6283: }
6284:
1.1.1.19 root 6285: if (lw == IDM_TOKEN_PREFERENCES)
6286: {
6287: SecurityTokenPreferencesDialog (hwndDlg);
6288: return 1;
6289: }
6290:
6291: if (lw == IDM_SYSENC_SETTINGS || lw == IDM_SYS_ENC_SETTINGS)
6292: {
6293: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_SYSENC_SETTINGS), hwndDlg, (DLGPROC) BootLoaderPreferencesDlgProc, 0);
6294: return 1;
6295: }
6296:
1.1.1.23 root 6297: if (lw == IDM_SYS_FAVORITES_SETTINGS)
6298: {
1.1.1.25 root 6299: OrganizeFavoriteVolumes (hwndDlg, true);
1.1.1.23 root 6300: return 1;
6301: }
6302:
1.1.1.7 root 6303: if (lw == IDM_BENCHMARK)
1.1.1.5 root 6304: {
6305: Benchmark (hwndDlg);
6306: return 1;
6307: }
6308:
1.1.1.13 root 6309: if (lw == IDM_TRAVELER)
1.1.1.6 root 6310: {
1.1.1.7 root 6311: DialogBoxParamW (hInst,
1.1.1.13 root 6312: MAKEINTRESOURCEW (IDD_TRAVELER_DLG), hwndDlg,
6313: (DLGPROC) TravelerDlgProc, (LPARAM) 0);
1.1.1.6 root 6314: return 1;
6315: }
6316:
1.1.1.7 root 6317: if (lw == IDM_BACKUP_VOL_HEADER)
6318: {
6319: if (!VolumeSelected(hwndDlg))
6320: {
6321: Warning ("NO_VOLUME_SELECTED");
6322: }
6323: else
6324: {
6325: char volPath[TC_MAX_PATH]; /* Volume to mount */
6326:
6327: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
6328:
1.1.1.19 root 6329: WaitCursor ();
6330:
1.1.1.11 root 6331: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
6332: UacBackupVolumeHeader (hwndDlg, TRUE, volPath);
6333: else
6334: BackupVolumeHeader (hwndDlg, TRUE, volPath);
1.1.1.19 root 6335:
6336: NormalCursor ();
1.1.1.7 root 6337: }
6338: return 1;
6339: }
6340:
6341: if (lw == IDM_RESTORE_VOL_HEADER)
6342: {
6343: if (!VolumeSelected(hwndDlg))
6344: {
6345: Warning ("NO_VOLUME_SELECTED");
6346: }
6347: else
6348: {
6349: char volPath[TC_MAX_PATH]; /* Volume to mount */
6350:
6351: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
6352:
1.1.1.19 root 6353: WaitCursor ();
6354:
1.1.1.11 root 6355: if (!IsAdmin () && IsUacSupported () && IsVolumeDeviceHosted (volPath))
6356: UacRestoreVolumeHeader (hwndDlg, volPath);
6357: else
6358: RestoreVolumeHeader (hwndDlg, volPath);
1.1.1.19 root 6359:
6360: NormalCursor ();
1.1.1.7 root 6361: }
6362: return 1;
6363: }
6364:
6365: if (lw == IDM_LANGUAGE)
6366: {
6367: BOOL p;
6368: if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), hwndDlg,
6369: (DLGPROC) LanguageDlgProc, (LPARAM) 0) == IDOK)
6370: {
6371: LoadLanguageFile ();
6372: SaveSettings (hwndDlg);
6373:
6374: p = LocalizationActive;
6375: LocalizationActive = TRUE;
6376: InitMainDialog (hwndDlg);
6377: InvalidateRect (hwndDlg, NULL, FALSE);
6378: LocalizationActive = p;
6379: DrawMenuBar (hwndDlg);
6380: }
6381: return 1;
6382: }
6383:
6384: if (lw == IDM_TEST_VECTORS)
6385: {
6386: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG), hwndDlg, (DLGPROC) CipherTestDialogProc, (LPARAM) 1);
6387: return 1;
6388: }
6389:
1.1.1.6 root 6390: if (lw == IDM_REFRESH_DRIVE_LETTERS)
6391: {
6392: DWORD driveMap = GetLogicalDrives ();
6393:
1.1.1.11 root 6394: WaitCursor ();
1.1.1.7 root 6395:
1.1.1.10 root 6396: if (!(nCurrentOS == WIN_2000 && RemoteSession))
6397: {
6398: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
6399: Sleep (100);
6400: BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
6401: }
1.1.1.7 root 6402:
1.1.1.6 root 6403: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1.1.7 root 6404:
6405: if (nSelectedDriveIndex >= 0)
6406: {
6407: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST),
6408: (char) HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
6409: }
6410:
1.1.1.6 root 6411: NormalCursor ();
1.1.1.7 root 6412: return 1;
6413: }
6414:
6415: if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
6416: {
1.1.1.25 root 6417: MountFavoriteVolumes();
1.1.1.7 root 6418: return 1;
6419: }
6420:
1.1.1.19 root 6421: if (lw == IDM_RESUME_INTERRUPTED_PROC)
6422: {
6423: ResumeInterruptedNonSysInplaceEncProcess ();
6424: return 1;
6425: }
6426:
1.1.1.7 root 6427: if (lw == IDC_VOLUME_PROPERTIES || lw == IDM_VOLUME_PROPERTIES)
1.1 root 6428: {
1.1.1.7 root 6429: DialogBoxParamW (hInst,
6430: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1 root 6431: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
6432: return 1;
6433: }
6434:
6435: if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
6436: {
1.1.1.5 root 6437: EnableDisableButtons (hwndDlg);
1.1 root 6438: return 1;
6439: }
6440:
6441: if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
6442: {
6443: UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10 root 6444: MoveEditToCombo ((HWND) lParam, bHistory);
1.1.1.13 root 6445: PostMessage (hwndDlg, TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS, 0, 0);
1.1.1.5 root 6446: return 1;
6447: }
6448:
6449: if (lw == IDC_NO_HISTORY)
6450: {
1.1.1.11 root 6451: if (!(bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY))))
6452: ClearHistory (GetDlgItem (hwndDlg, IDC_VOLUME));
6453:
1.1 root 6454: return 1;
6455: }
6456:
1.1.1.25 root 6457: if (lw >= TC_FAVORITE_MENU_CMD_ID_OFFSET && lw < TC_FAVORITE_MENU_CMD_ID_OFFSET_END)
1.1.1.6 root 6458: {
1.1.1.25 root 6459: size_t favoriteIndex = lw - TC_FAVORITE_MENU_CMD_ID_OFFSET;
6460:
6461: if (favoriteIndex < FavoriteVolumes.size())
6462: {
6463: if (IsMountedVolume (FavoriteVolumes[favoriteIndex].Path.c_str()))
6464: {
6465: WaitCursor();
6466: OpenVolumeExplorerWindow (GetMountedVolumeDriveNo ((char *) FavoriteVolumes[favoriteIndex].Path.c_str()));
6467: NormalCursor();
6468: }
6469: else
6470: MountFavoriteVolumes (FALSE, FALSE, FALSE, FavoriteVolumes[favoriteIndex]);
6471: }
6472:
6473: return 1;
6474: }
6475:
6476: return 0;
6477:
6478: case WM_DROPFILES:
6479: {
6480: HDROP hdrop = (HDROP) wParam;
6481: DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
1.1.1.6 root 6482: DragFinish (hdrop);
6483:
1.1.1.10 root 6484: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.6 root 6485: EnableDisableButtons (hwndDlg);
6486: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
6487: }
1.1.1.7 root 6488: return 1;
1.1.1.6 root 6489:
1.1.1.13 root 6490: case TC_APPMSG_MOUNT_ENABLE_DISABLE_CONTROLS:
1.1 root 6491: EnableDisableButtons (hwndDlg);
6492: return 1;
6493:
1.1.1.13 root 6494: case TC_APPMSG_MOUNT_SHOW_WINDOW:
1.1.1.8 root 6495: MainWindowHidden = FALSE;
1.1.1.13 root 6496: ShowWindow (hwndDlg, SW_SHOW);
6497: ShowWindow (hwndDlg, SW_RESTORE);
1.1.1.8 root 6498: return 1;
6499:
6500: case WM_COPYDATA:
6501: {
6502: PCOPYDATASTRUCT cd = (PCOPYDATASTRUCT)lParam;
6503: if (memcmp (&cd->dwData, WM_COPY_SET_VOLUME_NAME, 4) == 0)
6504: {
6505: if (cd->cbData > 0)
1.1.1.23 root 6506: {
6507: ((char *) cd->lpData)[cd->cbData - 1] = 0;
1.1.1.10 root 6508: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), (char *)cd->lpData, bHistory);
1.1.1.23 root 6509: }
1.1.1.8 root 6510:
6511: EnableDisableButtons (hwndDlg);
6512: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
6513: }
6514: }
6515: return 1;
6516:
1.1 root 6517: case WM_CLOSE:
6518: EndMainDlg (hwndDlg);
6519: return 1;
1.1.1.11 root 6520:
6521: default:
6522: // Recreate tray icon if Explorer restarted
6523: if (taskBarCreatedMsg != 0 && uMsg == taskBarCreatedMsg && TaskBarIconMutex != NULL)
6524: {
6525: TaskBarIconRemove (hwndDlg);
6526: TaskBarIconAdd (hwndDlg);
6527: return 1;
6528: }
1.1 root 6529: }
6530:
6531: return 0;
6532: }
6533:
1.1.1.15 root 6534: void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
1.1 root 6535: {
6536: char **lpszCommandLineArgs; /* Array of command line arguments */
6537: int nNoCommandLineArgs; /* The number of arguments in the array */
1.1.1.7 root 6538: char tmpPath[MAX_PATH * 2];
6539:
6540: /* Defaults */
6541: mountOptions.PreserveTimestamp = TRUE;
1.1.1.11 root 6542:
6543: if (_stricmp (lpszCommandLine, "-Embedding") == 0)
6544: {
6545: ComServerMode = TRUE;
6546: return;
6547: }
1.1 root 6548:
6549: /* Extract command line arguments */
1.1.1.8 root 6550: NoCmdLineArgs = nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1.1.1.11 root 6551:
1.1 root 6552: if (nNoCommandLineArgs > 0)
6553: {
6554: int i;
6555:
6556: for (i = 0; i < nNoCommandLineArgs; i++)
6557: {
1.1.1.19 root 6558: enum
6559: {
6560: OptionAuto,
6561: OptionBeep,
6562: OptionCache,
6563: CommandDismount,
6564: OptionExplore,
6565: OptionForce,
6566: CommandHelp,
6567: OptionHistory,
6568: OptionKeyfile,
6569: OptionLetter,
6570: OptionMountOption,
6571: OptionPassword,
6572: OptionQuit,
6573: OptionSilent,
6574: OptionTokenLib,
6575: OptionVolume,
6576: CommandWipeCache
6577: };
6578:
1.1 root 6579: argument args[]=
6580: {
1.1.1.19 root 6581: { OptionAuto, "/auto", "/a", FALSE },
6582: { OptionBeep, "/beep", "/b", FALSE },
6583: { OptionCache, "/cache", "/c", FALSE },
6584: { CommandDismount, "/dismount", "/d", FALSE },
6585: { OptionExplore, "/explore", "/e", FALSE },
6586: { OptionForce, "/force", "/f", FALSE },
6587: { CommandHelp, "/help", "/?", FALSE },
6588: { OptionHistory, "/history", "/h", FALSE },
6589: { OptionKeyfile, "/keyfile", "/k", FALSE },
6590: { OptionLetter, "/letter", "/l", FALSE },
6591: { OptionMountOption, "/mountoption", "/m", FALSE },
6592: { OptionPassword, "/password", "/p", FALSE },
6593: { OptionQuit, "/quit", "/q", FALSE },
6594: { OptionSilent, "/silent", "/s", FALSE },
6595: { OptionTokenLib, "/tokenlib", NULL, FALSE },
6596: { OptionVolume, "/volume", "/v", FALSE },
6597: { CommandWipeCache, "/wipecache", "/w", FALSE }
1.1 root 6598: };
6599:
6600: argumentspec as;
6601:
6602: int nArgPos;
6603:
6604: as.args = args;
6605: as.arg_cnt = sizeof(args)/ sizeof(args[0]);
6606:
1.1.1.19 root 6607: switch (GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos))
1.1 root 6608: {
1.1.1.19 root 6609: case OptionAuto:
1.1.1.7 root 6610: {
6611: char szTmp[32];
6612: bAuto = TRUE;
1.1.1.2 root 6613:
1.1.1.7 root 6614: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
6615: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
6616: {
6617: if (!_stricmp (szTmp, "devices"))
6618: bAutoMountDevices = TRUE;
6619: else if (!_stricmp (szTmp, "favorites"))
6620: bAutoMountFavorites = TRUE;
1.1.1.25 root 6621: else if (!_stricmp (szTmp, "logon"))
6622: LogOn = TRUE;
1.1.1.7 root 6623: }
6624: }
6625: break;
1.1.1.2 root 6626:
1.1.1.19 root 6627: case OptionBeep:
1.1.1.7 root 6628: bBeep = TRUE;
1.1 root 6629: break;
6630:
1.1.1.19 root 6631: case OptionCache:
1.1.1.2 root 6632: {
1.1.1.7 root 6633: char szTmp[8];
6634: bCacheInDriver = TRUE;
6635:
6636: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
6637: szTmp, sizeof (szTmp));
6638:
6639: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
6640: bCacheInDriver = FALSE;
1.1.1.2 root 6641: }
1.1 root 6642: break;
6643:
1.1.1.19 root 6644: case CommandDismount:
1.1.1.7 root 6645:
6646: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
6647: szDriveLetter, sizeof (szDriveLetter)))
6648: cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
6649: else
6650: cmdUnmountDrive = -1;
6651:
1.1 root 6652: break;
6653:
1.1.1.19 root 6654: case OptionExplore:
1.1 root 6655: bExplore = TRUE;
6656: break;
6657:
1.1.1.19 root 6658: case OptionForce:
1.1.1.5 root 6659: bForceMount = TRUE;
6660: bForceUnmount = TRUE;
6661: break;
6662:
1.1.1.19 root 6663: case OptionKeyfile:
1.1.1.7 root 6664: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
6665: nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
6666: {
6667: KeyFile *kf;
6668: RelativePath2Absolute (tmpPath);
1.1.1.13 root 6669: kf = (KeyFile *) malloc (sizeof (KeyFile));
1.1.1.7 root 6670: strncpy (kf->FileName, tmpPath, sizeof (kf->FileName));
6671: FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
6672: }
6673: break;
6674:
1.1.1.19 root 6675: case OptionLetter:
1.1.1.2 root 6676: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.7 root 6677: szDriveLetter, sizeof (szDriveLetter));
6678: commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1.1.23 root 6679:
6680: if (commandLineDrive < 'C' || commandLineDrive > 'Z')
6681: AbortProcess ("BAD_DRIVE_LETTER");
6682:
1.1 root 6683: break;
6684:
1.1.1.19 root 6685: case OptionHistory:
1.1.1.6 root 6686: {
6687: char szTmp[8];
1.1.1.7 root 6688: bHistory = bHistoryCmdLine = TRUE;
1.1.1.6 root 6689:
1.1.1.7 root 6690: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
6691: szTmp, sizeof (szTmp));
6692:
6693: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
6694: bHistory = FALSE;
1.1.1.6 root 6695: }
6696: break;
6697:
1.1.1.19 root 6698: case OptionMountOption:
1.1.1.6 root 6699: {
1.1.1.7 root 6700: char szTmp[16];
1.1.1.6 root 6701: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
6702: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
6703: {
1.1.1.7 root 6704: if (!_stricmp (szTmp, "ro") || !_stricmp (szTmp, "readonly"))
1.1.1.6 root 6705: mountOptions.ReadOnly = TRUE;
6706:
1.1.1.7 root 6707: if (!_stricmp (szTmp, "rm") || !_stricmp (szTmp, "removable"))
1.1.1.6 root 6708: mountOptions.Removable = TRUE;
1.1.1.7 root 6709:
6710: if (!_stricmp (szTmp, "ts") || !_stricmp (szTmp, "timestamp"))
6711: mountOptions.PreserveTimestamp = FALSE;
1.1.1.15 root 6712:
6713: if (!_stricmp (szTmp, "sm") || !_stricmp (szTmp, "system"))
6714: mountOptions.PartitionInInactiveSysEncScope = bPrebootPasswordDlgMode = TRUE;
1.1.1.17 root 6715:
6716: if (!_stricmp (szTmp, "bk") || !_stricmp (szTmp, "headerbak"))
6717: mountOptions.UseBackupHeader = TRUE;
1.1.1.19 root 6718:
6719: if (!_stricmp (szTmp, "recovery"))
6720: mountOptions.RecoveryMode = TRUE;
1.1.1.23 root 6721:
6722: CmdMountOptions = mountOptions;
6723: CmdMountOptionsValid = TRUE;
1.1.1.6 root 6724: }
6725: }
1.1 root 6726: break;
6727:
1.1.1.19 root 6728: case OptionPassword:
1.1.1.7 root 6729: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.13 root 6730: (char *) CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text));
6731: CmdVolumePassword.Length = strlen ((char *) CmdVolumePassword.Text);
1.1.1.7 root 6732: CmdVolumePasswordValid = TRUE;
6733: break;
6734:
1.1.1.19 root 6735: case OptionVolume:
1.1.1.7 root 6736: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
6737: nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1 root 6738: {
1.1.1.7 root 6739: RelativePath2Absolute (szFileName);
1.1.1.10 root 6740: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.8 root 6741: CmdLineVolumeSpecified = TRUE;
1.1 root 6742: }
6743: break;
6744:
1.1.1.19 root 6745: case OptionQuit:
1.1 root 6746: {
1.1.1.7 root 6747: char szTmp[32];
1.1 root 6748:
1.1.1.7 root 6749: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
6750: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
1.1 root 6751: {
1.1.1.12 root 6752: if (!_stricmp (szTmp, "UAC")) // Used to indicate non-install elevation
6753: break;
6754:
1.1.1.7 root 6755: if (!_stricmp (szTmp, "preferences"))
1.1.1.12 root 6756: {
6757: Quit = TRUE;
1.1.1.7 root 6758: UsePreferences = TRUE;
1.1.1.12 root 6759: break;
6760: }
6761:
6762: if (!_stricmp (szTmp, "background"))
6763: bEnableBkgTask = TRUE;
1.1 root 6764: }
1.1.1.12 root 6765:
6766: Quit = TRUE;
6767: UsePreferences = FALSE;
1.1 root 6768: }
6769: break;
6770:
1.1.1.19 root 6771: case OptionSilent:
1.1.1.7 root 6772: Silent = TRUE;
1.1 root 6773: break;
6774:
1.1.1.19 root 6775: case OptionTokenLib:
6776: if (GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT)
6777: InitSecurityTokenLibrary();
6778: else
6779: Error ("COMMAND_LINE_ERROR");
6780:
6781: break;
6782:
6783: case CommandWipeCache:
1.1.1.7 root 6784: bWipe = TRUE;
1.1 root 6785: break;
6786:
1.1.1.19 root 6787: case CommandHelp:
1.1.1.7 root 6788: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1.1 root 6789: CommandHelpDlgProc, (LPARAM) &as);
6790: exit(0);
6791: break;
6792:
6793: // no option = file name
6794: default:
1.1.1.2 root 6795: {
1.1.1.23 root 6796: strcpy_s (szFileName, array_capacity (szFileName), lpszCommandLineArgs[i]);
6797: RelativePath2Absolute (szFileName);
1.1.1.8 root 6798:
6799: if (nNoCommandLineArgs == 1)
6800: CmdLineVolumeSpecified = TRUE;
1.1.1.10 root 6801: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.2 root 6802: }
1.1 root 6803: }
6804: }
6805: }
6806:
6807: /* Free up the command line arguments */
6808: while (--nNoCommandLineArgs >= 0)
6809: {
6810: free (lpszCommandLineArgs[nNoCommandLineArgs]);
6811: }
6812: }
6813:
1.1.1.7 root 6814:
1.1.1.23 root 6815: static SERVICE_STATUS SystemFavoritesServiceStatus;
6816: static SERVICE_STATUS_HANDLE SystemFavoritesServiceStatusHandle;
6817:
6818:
6819: static void SystemFavoritesServiceLogError (const string &errorMessage)
6820: {
6821: HANDLE eventSource = RegisterEventSource (NULL, TC_SYSTEM_FAVORITES_SERVICE_NAME);
6822:
6823: if (eventSource)
6824: {
6825: LPCTSTR strings[] = { TC_SYSTEM_FAVORITES_SERVICE_NAME, errorMessage.c_str() };
6826: ReportEvent (eventSource, EVENTLOG_ERROR_TYPE, 0, 0xC0000001, NULL, array_capacity (strings), 0, strings, NULL);
6827:
6828: DeregisterEventSource (eventSource);
6829: }
6830: }
6831:
6832:
6833: static void SystemFavoritesServiceSetStatus (DWORD status, DWORD waitHint = 0)
6834: {
6835: SystemFavoritesServiceStatus.dwCurrentState = status;
6836: SystemFavoritesServiceStatus.dwWaitHint = waitHint;
6837: SystemFavoritesServiceStatus.dwWin32ExitCode = NO_ERROR;
6838:
6839: SetServiceStatus (SystemFavoritesServiceStatusHandle, &SystemFavoritesServiceStatus);
6840: }
6841:
6842:
6843: static VOID WINAPI SystemFavoritesServiceCtrlHandler (DWORD control)
6844: {
6845: if (control == SERVICE_CONTROL_STOP)
6846: SystemFavoritesServiceSetStatus (SERVICE_STOP_PENDING);
6847: else
6848: SystemFavoritesServiceSetStatus (SystemFavoritesServiceStatus.dwCurrentState);
6849: }
6850:
6851:
6852: static VOID WINAPI SystemFavoritesServiceMain (DWORD argc, LPTSTR *argv)
1.1 root 6853: {
1.1.1.23 root 6854: memset (&SystemFavoritesServiceStatus, 0, sizeof (SystemFavoritesServiceStatus));
6855: SystemFavoritesServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
6856:
6857: SystemFavoritesServiceStatusHandle = RegisterServiceCtrlHandler (TC_SYSTEM_FAVORITES_SERVICE_NAME, SystemFavoritesServiceCtrlHandler);
6858: if (!SystemFavoritesServiceStatusHandle)
6859: return;
6860:
6861: SystemFavoritesServiceSetStatus (SERVICE_START_PENDING, 60000);
6862:
1.1.1.25 root 6863: try
6864: {
6865: MountFavoriteVolumes (TRUE);
6866: }
6867: catch (...) { }
1.1.1.23 root 6868:
6869: SystemFavoritesServiceSetStatus (SERVICE_RUNNING);
6870: SystemFavoritesServiceSetStatus (SERVICE_STOPPED);
6871: }
6872:
6873:
6874: static BOOL StartSystemFavoritesService ()
6875: {
6876: ServiceMode = TRUE;
6877: Silent = TRUE;
6878: DeviceChangeBroadcastDisabled = TRUE;
6879:
1.1.1.25 root 6880: InitOSVersionInfo();
6881:
1.1.1.23 root 6882: if (DriverAttach() != ERR_SUCCESS)
6883: return FALSE;
6884:
6885: SERVICE_TABLE_ENTRY serviceTable[2];
6886: serviceTable[0].lpServiceName = TC_SYSTEM_FAVORITES_SERVICE_NAME;
6887: serviceTable[0].lpServiceProc = SystemFavoritesServiceMain;
6888:
6889: serviceTable[1].lpServiceName = NULL;
6890: serviceTable[1].lpServiceProc = NULL;
6891:
6892: BOOL result = StartServiceCtrlDispatcher (serviceTable);
6893:
6894: if (!(ReadDriverConfigurationFlags() & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD))
6895: WipeCache (NULL, TRUE);
6896:
6897: return result;
6898: }
6899:
6900:
6901: int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine, int nCmdShow)
6902: {
6903: int argc;
6904: LPWSTR *argv = CommandLineToArgvW (GetCommandLineW(), &argc);
6905:
6906: if (argv && argc == 2 && SingleStringToWide (TC_SYSTEM_FAVORITES_SERVICE_CMDLINE_OPTION) == argv[1])
6907: return StartSystemFavoritesService() ? 0 : 1;
6908:
1.1 root 6909: int status;
1.1.1.13 root 6910: atexit (localcleanup);
1.1.1.19 root 6911: SetProcessShutdownParameters (0x100, 0);
1.1.1.13 root 6912:
6913: VirtualLock (&VolumePassword, sizeof (VolumePassword));
6914: VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
6915: VirtualLock (&mountOptions, sizeof (mountOptions));
6916: VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
1.1.1.18 root 6917: VirtualLock (&szFileName, sizeof(szFileName));
1.1 root 6918:
1.1.1.13 root 6919: try
6920: {
6921: BootEncObj = new BootEncryption (NULL);
6922: }
6923: catch (Exception &e)
6924: {
6925: e.Show (NULL);
6926: }
1.1 root 6927:
1.1.1.13 root 6928: if (BootEncObj == NULL)
6929: AbortProcess ("INIT_SYS_ENC");
1.1 root 6930:
1.1.1.11 root 6931: InitCommonControls ();
6932: InitApp (hInstance, lpszCommandLine);
1.1 root 6933:
1.1.1.7 root 6934: RegisterRedTick(hInstance);
6935:
6936: /* Allocate, dup, then store away the application title */
6937: lpszTitle = L"TrueCrypt";
6938:
1.1 root 6939: status = DriverAttach ();
6940: if (status != 0)
6941: {
6942: if (status == ERR_OS_ERROR)
6943: handleWin32Error (NULL);
6944: else
6945: handleError (NULL, status);
6946:
1.1.1.7 root 6947: AbortProcess ("NODRIVER");
1.1 root 6948: }
6949:
6950: /* Create the main dialog box */
1.1.1.7 root 6951: DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1.1 root 6952: (LPARAM) lpszCommandLine);
6953:
6954: /* Terminate */
6955: return 0;
6956: }
1.1.1.6 root 6957:
1.1.1.7 root 6958:
6959: BOOL TaskBarIconAdd (HWND hwnd)
6960: {
6961: BOOL res;
6962: NOTIFYICONDATAW tnid;
6963:
6964: // Only one icon may be created
6965: if (TaskBarIconMutex != NULL) return TRUE;
6966:
6967: TaskBarIconMutex = CreateMutex (NULL, TRUE, "TrueCryptTaskBarIcon");
6968: if (TaskBarIconMutex == NULL || GetLastError () == ERROR_ALREADY_EXISTS)
6969: {
6970: TaskBarIconMutex = NULL;
6971: return FALSE;
6972: }
6973:
6974: tnid.cbSize = sizeof (NOTIFYICONDATAW);
6975: tnid.hWnd = hwnd;
6976: tnid.uID = IDI_TRUECRYPT_ICON;
6977: tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
1.1.1.13 root 6978: tnid.uCallbackMessage = TC_APPMSG_TASKBAR_ICON;
6979: tnid.hIcon = (HICON) LoadImage (hInst, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON),
1.1.1.12 root 6980: IMAGE_ICON,
6981: ScreenDPI >= 120 ? 0 : 16,
6982: ScreenDPI >= 120 ? 0 : 16,
6983: (ScreenDPI >= 120 ? LR_DEFAULTSIZE : 0)
6984: | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
6985:
1.1.1.7 root 6986: wcscpy (tnid.szTip, L"TrueCrypt");
6987:
6988: res = Shell_NotifyIconW (NIM_ADD, &tnid);
6989:
6990: if (tnid.hIcon)
6991: DestroyIcon (tnid.hIcon);
6992:
6993: return res;
6994: }
6995:
6996:
6997: BOOL TaskBarIconRemove (HWND hwnd)
6998: {
6999: if (TaskBarIconMutex != NULL)
7000: {
7001: NOTIFYICONDATA tnid;
7002: BOOL res;
7003:
7004: ZeroMemory (&tnid, sizeof (tnid));
7005: tnid.cbSize = sizeof(NOTIFYICONDATA);
7006: tnid.hWnd = hwnd;
7007: tnid.uID = IDI_TRUECRYPT_ICON;
7008:
7009: res = Shell_NotifyIcon (NIM_DELETE, &tnid);
7010: if (TaskBarIconMutex)
7011: {
7012: CloseHandle (TaskBarIconMutex);
7013: TaskBarIconMutex = NULL;
7014: }
7015: return res;
7016: }
7017: else
7018: return FALSE;
7019: }
7020:
7021:
7022: void DismountIdleVolumes ()
7023: {
1.1.1.13 root 7024: static DWORD lastMinTickCount;
1.1.1.7 root 7025: static int InactivityTime[26];
7026: static unsigned __int64 LastRead[26], LastWritten[26];
7027: static int LastId[26];
7028:
7029: VOLUME_PROPERTIES_STRUCT prop;
7030: DWORD dwResult;
7031: BOOL bResult;
7032: int i;
7033:
1.1.1.13 root 7034: if (GetTickCount() > lastMinTickCount && GetTickCount() - lastMinTickCount < 60 * 1000)
7035: return;
7036:
7037: lastMinTickCount = GetTickCount();
1.1.1.7 root 7038:
7039: for (i = 0; i < 26; i++)
7040: {
7041: if (LastKnownMountList.ulMountedDrives & (1 << i))
7042: {
7043: memset (&prop, 0, sizeof(prop));
7044: prop.driveNo = i;
7045:
1.1.1.13 root 7046: bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_VOLUME_PROPERTIES, &prop,
1.1.1.7 root 7047: sizeof (prop), &prop, sizeof (prop), &dwResult, NULL);
7048:
7049: if (bResult)
7050: {
7051: if (LastRead[i] == prop.totalBytesRead
7052: && LastWritten[i] == prop.totalBytesWritten
7053: && LastId[i] == prop.uniqueId)
7054: {
7055: if (++InactivityTime[i] >= MaxVolumeIdleTime)
7056: {
1.1.1.11 root 7057: BroadcastDeviceChange (DBT_DEVICEREMOVEPENDING, i, 0);
7058:
1.1.1.7 root 7059: if (bCloseDismountedWindows && CloseVolumeExplorerWindows (MainDlg, i))
7060: Sleep (250);
7061:
7062: if (DriverUnmountVolume (MainDlg, i, bForceAutoDismount) == 0)
7063: {
7064: InactivityTime[i] = 0;
7065: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i, 0);
7066:
7067: if (bWipeCacheOnAutoDismount)
1.1.1.19 root 7068: {
1.1.1.13 root 7069: DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.19 root 7070: SecurityToken::CloseAllSessions();
7071: }
1.1.1.7 root 7072: }
7073: }
7074: }
7075: else
7076: {
7077: InactivityTime[i] = 0;
7078: LastRead[i] = prop.totalBytesRead;
7079: LastWritten[i] = prop.totalBytesWritten;
7080: LastId[i] = prop.uniqueId;
7081: }
7082: }
7083: }
7084: }
7085: }
7086:
7087:
1.1.1.25 root 7088: BOOL MountFavoriteVolumes (BOOL systemFavorites, BOOL logOnMount, BOOL hotKeyMount, const FavoriteVolume &favoriteVolumeToMount)
1.1.1.7 root 7089: {
7090: BOOL status = TRUE;
1.1.1.25 root 7091: BOOL lastbExplore;
1.1.1.7 root 7092:
1.1.1.11 root 7093: mountOptions = defaultMountOptions;
7094:
1.1.1.23 root 7095: VolumePassword.Length = 0;
1.1.1.19 root 7096: MultipleMountOperationInProgress = TRUE;
7097:
1.1.1.25 root 7098: vector <FavoriteVolume> favorites;
7099:
7100: if (systemFavorites)
7101: {
7102: try
7103: {
7104: LoadFavoriteVolumes (favorites, true);
7105: }
7106: catch (...)
7107: {
7108: return false;
7109: }
7110: }
7111: else if (!favoriteVolumeToMount.Path.empty())
7112: favorites.push_back (favoriteVolumeToMount);
7113: else
7114: favorites = FavoriteVolumes;
7115:
7116: foreach (const FavoriteVolume &favorite, favorites)
1.1.1.7 root 7117: {
1.1.1.25 root 7118: if (favorite.DisconnectedDevice
7119: || (logOnMount && !favorite.MountOnLogOn)
7120: || (hotKeyMount && favorite.DisableHotkeyMount))
7121: {
7122: continue;
7123: }
7124:
1.1.1.7 root 7125: int drive;
1.1.1.25 root 7126: drive = toupper (favorite.MountPoint[0]) - 'A';
7127:
7128: mountOptions.ReadOnly = favorite.ReadOnly;
7129: mountOptions.Removable = favorite.Removable;
1.1.1.21 root 7130:
1.1.1.25 root 7131: if (favorite.SystemEncryption)
1.1.1.23 root 7132: {
7133: mountOptions.PartitionInInactiveSysEncScope = TRUE;
7134: bPrebootPasswordDlgMode = TRUE;
7135: }
7136: else
7137: {
7138: mountOptions.PartitionInInactiveSysEncScope = FALSE;
7139: bPrebootPasswordDlgMode = FALSE;
7140: }
7141:
1.1.1.25 root 7142: if ((LastKnownMountList.ulMountedDrives & (1 << drive)) == 0)
1.1.1.23 root 7143: {
1.1.1.25 root 7144: MountVolumesAsSystemFavorite = systemFavorites;
7145:
7146: string mountPoint = (char) (drive + 'A') + string (":\\");
7147: char prevVolumeAtMountPoint[MAX_PATH] = { 0 };
7148:
7149: if (systemFavorites)
1.1.1.23 root 7150: {
1.1.1.25 root 7151: // Partitions of new drives are assigned free drive letters by Windows on boot. Make sure this does not prevent system favorite volumes
7152: // from being mounted. Each partition (using the same drive letter as a system favorite volume) is assigned another free drive letter.
7153:
7154: if (GetVolumeNameForVolumeMountPoint (mountPoint.c_str(), prevVolumeAtMountPoint, sizeof (prevVolumeAtMountPoint)))
7155: DeleteVolumeMountPoint (mountPoint.c_str());
7156: else
7157: prevVolumeAtMountPoint[0] = 0;
7158: }
7159:
7160: lastbExplore = bExplore;
7161:
7162: bExplore = (BOOL) favorite.OpenExplorerWindow;
7163:
7164: if (!Mount (MainDlg, drive, (char *) favorite.Path.c_str()))
7165: status = FALSE;
7166:
7167: bExplore = lastbExplore;
7168:
7169: if (systemFavorites && prevVolumeAtMountPoint[0])
7170: {
7171: if (status)
1.1.1.23 root 7172: {
1.1.1.25 root 7173: int freeDrive = GetFirstAvailableDrive();
7174: if (freeDrive != -1)
1.1.1.23 root 7175: {
1.1.1.25 root 7176: mountPoint[0] = (char) (freeDrive + 'A');
7177: SetVolumeMountPoint (mountPoint.c_str(), prevVolumeAtMountPoint);
1.1.1.23 root 7178: }
7179: }
1.1.1.25 root 7180: else
7181: SetVolumeMountPoint (mountPoint.c_str(), prevVolumeAtMountPoint);
1.1.1.23 root 7182: }
7183:
1.1.1.7 root 7184: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.23 root 7185:
7186: MountVolumesAsSystemFavorite = FALSE;
7187:
7188: if (ServiceMode && LastMountedVolumeDirty)
7189: {
7190: DWORD bytesOut;
7191: DeviceIoControl (hDriver, TC_IOCTL_SET_SYSTEM_FAVORITE_VOLUME_DIRTY, NULL, 0, NULL, 0, &bytesOut, NULL);
7192:
7193: SystemFavoritesServiceLogError (string ("The filesystem of the volume mounted as ") + (char) (drive + 'A') + ": was not cleanly dismounted and needs to be checked for errors.");
7194: }
1.1.1.7 root 7195: }
7196: }
7197:
1.1.1.19 root 7198: MultipleMountOperationInProgress = FALSE;
1.1.1.23 root 7199: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.19 root 7200:
7201: if (status && CloseSecurityTokenSessionsAfterMount)
7202: SecurityToken::CloseAllSessions();
7203:
1.1.1.7 root 7204: return status;
7205: }
7206:
7207:
7208: static void SaveDefaultKeyFilesParam (void)
7209: {
7210: if (defaultKeyFilesParam.FirstKeyFile == NULL)
7211: {
7212: /* No keyfiles selected */
1.1.1.19 root 7213: remove (GetConfigPath (TC_APPD_FILENAME_DEFAULT_KEYFILES));
1.1.1.7 root 7214: }
7215: else
7216: {
7217: FILE *f;
7218: KeyFile *kf = FirstKeyFile;
7219:
1.1.1.19 root 7220: f = fopen (GetConfigPath (TC_APPD_FILENAME_DEFAULT_KEYFILES), "w");
1.1.1.7 root 7221: if (f == NULL)
7222: {
7223: handleWin32Error (MainDlg);
7224: return;
7225: }
7226:
7227: XmlWriteHeader (f);
7228:
7229: fputs ("\n\t<defaultkeyfiles>", f);
7230:
7231: while (kf != NULL)
7232: {
1.1.1.11 root 7233: char q[TC_MAX_PATH * 2];
7234:
7235: XmlQuoteText (kf->FileName, q, sizeof (q));
7236: fprintf (f, "\n\t\t<keyfile>%s</keyfile>", q);
7237:
1.1.1.7 root 7238: kf = kf->Next;
7239: }
7240:
7241: fputs ("\n\t</defaultkeyfiles>", f);
7242:
7243: XmlWriteFooter (f);
7244:
1.1.1.25 root 7245: CheckFileStreamWriteErrors (f, TC_APPD_FILENAME_DEFAULT_KEYFILES);
1.1.1.7 root 7246: fclose (f);
7247: return;
7248: }
7249: }
7250:
7251:
7252: static void KeyfileDefaultsDlg (HWND hwndDlg)
7253: {
7254: KeyFilesDlgParam param;
7255:
7256: param.EnableKeyFiles = defaultKeyFilesParam.EnableKeyFiles;
7257: param.FirstKeyFile = defaultKeyFilesParam.FirstKeyFile;
7258:
7259: if (DialogBoxParamW (hInst,
7260: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
7261: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m) == IDOK)
7262: {
1.1.1.13 root 7263: if (!param.EnableKeyFiles || AskWarnYesNo ("CONFIRM_SAVE_DEFAULT_KEYFILES") == IDYES)
1.1.1.7 root 7264: {
7265: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
7266: defaultKeyFilesParam.EnableKeyFiles = param.EnableKeyFiles;
7267: defaultKeyFilesParam.FirstKeyFile = param.FirstKeyFile;
7268:
7269: RestoreDefaultKeyFilesParam ();
7270: SaveDefaultKeyFilesParam ();
7271: }
7272: }
7273: }
7274:
7275:
7276: static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
7277: {
7278: DWORD dwResult;
7279: BOOL success = TRUE;
7280:
7281: switch (wParam)
7282: {
7283: case HK_AUTOMOUNT_DEVICES:
7284: MountAllDevices (hwndDlg, TRUE);
7285:
7286: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7287: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7288:
7289: break;
7290:
7291: case HK_DISMOUNT_ALL:
1.1.1.21 root 7292: case HK_DISMOUNT_ALL_AND_WIPE:
7293:
7294: if (wParam == HK_DISMOUNT_ALL_AND_WIPE)
7295: WipeCache (hwndDlg, TRUE);
7296:
1.1.1.12 root 7297: if (DismountAll (hwndDlg, FALSE, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY) && bDisplayMsgBoxOnHotkeyDismount)
1.1.1.21 root 7298: InfoTopMost (wParam == HK_DISMOUNT_ALL_AND_WIPE ? "VOLUMES_DISMOUNTED_CACHE_WIPED" : "MOUNTED_VOLUMES_DISMOUNTED");
1.1.1.12 root 7299: else if (bDisplayMsgBoxOnHotkeyDismount)
1.1.1.21 root 7300: InfoTopMost (wParam == HK_DISMOUNT_ALL_AND_WIPE ? "PASSWORD_CACHE_WIPED" : "DISMOUNT_ALL_ATTEMPT_COMPLETED");
1.1.1.7 root 7301:
1.1.1.12 root 7302: if (!bDisplayMsgBoxOnHotkeyDismount && bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7303: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7304:
7305: break;
7306:
1.1.1.11 root 7307: case HK_WIPE_CACHE:
1.1.1.21 root 7308: WipeCache (hwndDlg, FALSE);
1.1.1.11 root 7309: break;
7310:
1.1.1.7 root 7311: case HK_FORCE_DISMOUNT_ALL_AND_WIPE:
7312: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13 root 7313: success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7 root 7314: if (success)
7315: {
7316: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7317: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7318:
7319: if (bDisplayMsgBoxOnHotkeyDismount)
1.1.1.20 root 7320: InfoTopMost ("VOLUMES_DISMOUNTED_CACHE_WIPED");
1.1.1.7 root 7321: }
7322: break;
7323:
7324: case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT:
7325: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1.1.13 root 7326: success &= DeviceIoControl (hDriver, TC_IOCTL_WIPE_PASSWORD_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
1.1.1.7 root 7327: if (success)
7328: {
7329: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7330: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7331:
7332: if (bDisplayMsgBoxOnHotkeyDismount)
1.1.1.20 root 7333: InfoTopMost ("VOLUMES_DISMOUNTED_CACHE_WIPED");
1.1.1.7 root 7334: }
7335: TaskBarIconRemove (hwndDlg);
7336: EndMainDlg (hwndDlg);
7337: break;
7338:
7339: case HK_MOUNT_FAVORITE_VOLUMES:
1.1.1.25 root 7340: MountFavoriteVolumes (FALSE, FALSE, TRUE);
1.1.1.7 root 7341:
7342: if (bPlaySoundOnHotkeyMountDismount)
1.1.1.23 root 7343: MessageBeep (0xFFFFFFFF);
1.1.1.7 root 7344:
7345: break;
7346:
7347: case HK_SHOW_HIDE_MAIN_WINDOW:
1.1.1.13 root 7348: ChangeMainWindowVisibility ();
1.1.1.7 root 7349: break;
1.1.1.21 root 7350:
7351: case HK_CLOSE_SECURITY_TOKEN_SESSIONS:
1.1.1.23 root 7352: SecurityToken::CloseAllSessions();
7353: InfoTopMost ("ALL_TOKEN_SESSIONS_CLOSED");
1.1.1.21 root 7354: break;
1.1.1.7 root 7355: }
1.1.1.13 root 7356: }
7357:
7358:
7359: void ChangeMainWindowVisibility ()
7360: {
7361: MainWindowHidden = !MainWindowHidden;
7362:
7363: if (!MainWindowHidden)
7364: SetForegroundWindow (MainDlg);
7365:
7366: ShowWindow (MainDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
7367:
7368: if (!MainWindowHidden)
7369: ShowWindow (MainDlg, SW_RESTORE);
1.1.1.17 root 7370: }
7371:
7372:
7373: int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume)
7374: {
7375: int nStatus = ERR_OS_ERROR;
7376: wchar_t szTmp[4096];
7377: int fBackup = -1;
7378: OpenVolumeContext volume;
7379: OpenVolumeContext hiddenVolume;
7380: Password hiddenVolPassword;
1.1.1.20 root 7381: byte temporaryKey[MASTER_KEYDATA_SIZE];
7382: byte originalK2[MASTER_KEYDATA_SIZE];
7383:
1.1.1.17 root 7384: volume.VolumeIsOpen = FALSE;
7385: hiddenVolume.VolumeIsOpen = FALSE;
7386:
7387: switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
7388: {
7389: case 1:
7390: case 2:
7391: if (AskErrNoYes ("BACKUP_HEADER_NOT_FOR_SYS_DEVICE") == IDYES)
7392: CreateRescueDisk ();
7393:
7394: return 0;
7395: }
7396:
7397: if (IsMountedVolume (lpszVolume))
7398: {
7399: Warning ("DISMOUNT_FIRST");
7400: goto ret;
7401: }
7402:
1.1.1.23 root 7403: if (!VolumePathExists (lpszVolume))
7404: {
7405: handleWin32Error (hwndDlg);
7406: goto ret;
7407: }
7408:
1.1.1.17 root 7409: Info ("EXTERNAL_VOL_HEADER_BAK_FIRST_INFO");
7410:
1.1.1.19 root 7411:
7412: WaitCursor();
7413:
1.1.1.17 root 7414: // Open both types of volumes
7415: for (int type = TC_VOLUME_TYPE_NORMAL; type <= TC_VOLUME_TYPE_HIDDEN; ++type)
7416: {
7417: OpenVolumeContext *askVol = (type == TC_VOLUME_TYPE_HIDDEN ? &hiddenVolume : &volume);
7418: Password *askPassword = (type == TC_VOLUME_TYPE_HIDDEN ? &hiddenVolPassword : &VolumePassword);
7419:
7420: while (TRUE)
7421: {
7422: if (!AskVolumePassword (hwndDlg, askPassword, type == TC_VOLUME_TYPE_HIDDEN ? "ENTER_HIDDEN_VOL_PASSWORD" : "ENTER_NORMAL_VOL_PASSWORD", FALSE))
7423: {
7424: nStatus = ERR_SUCCESS;
7425: goto ret;
7426: }
7427:
1.1.1.19 root 7428: WaitCursor();
7429:
1.1.1.17 root 7430: if (KeyFilesEnable && FirstKeyFile)
1.1.1.19 root 7431: KeyFilesApply (askPassword, FirstKeyFile);
1.1.1.17 root 7432:
7433: nStatus = OpenVolume (askVol, lpszVolume, askPassword, FALSE, bPreserveTimestamp, FALSE);
1.1.1.19 root 7434:
7435: NormalCursor();
7436:
1.1.1.17 root 7437: if (nStatus == ERR_SUCCESS)
7438: {
7439: if ((type == TC_VOLUME_TYPE_NORMAL && askVol->CryptoInfo->hiddenVolume)
7440: || (type == TC_VOLUME_TYPE_HIDDEN && !askVol->CryptoInfo->hiddenVolume))
7441: {
7442: CloseVolume (askVol);
7443: handleError (hwndDlg, ERR_PASSWORD_WRONG);
7444: continue;
7445: }
7446:
7447: RandSetHashFunction (askVol->CryptoInfo->pkcs5);
7448:
7449: if (type == TC_VOLUME_TYPE_NORMAL)
7450: {
7451: // Ask the user if there is a hidden volume
7452: char *volTypeChoices[] = {0, "DOES_VOLUME_CONTAIN_HIDDEN", "VOLUME_CONTAINS_HIDDEN", "VOLUME_DOES_NOT_CONTAIN_HIDDEN", "IDCANCEL", 0};
1.1.1.19 root 7453: switch (AskMultiChoice ((void **) volTypeChoices, FALSE))
1.1.1.17 root 7454: {
7455: case 1:
7456: break;
7457: case 2:
7458: goto noHidden;
7459:
7460: default:
7461: nStatus = ERR_SUCCESS;
7462: goto ret;
7463: }
7464: }
7465:
7466: break;
7467: }
7468:
7469: if (nStatus != ERR_PASSWORD_WRONG)
7470: goto error;
7471:
7472: handleError (hwndDlg, nStatus);
7473: }
7474: }
7475: noHidden:
7476:
7477: if (hiddenVolume.VolumeIsOpen && volume.CryptoInfo->LegacyVolume != hiddenVolume.CryptoInfo->LegacyVolume)
7478: {
7479: nStatus = ERR_PARAMETER_INCORRECT;
7480: goto error;
7481: }
7482:
7483: swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume);
7484:
7485: if (bRequireConfirmation
7486: && (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO))
7487: goto ret;
7488:
7489: /* Select backup file */
1.1.1.19 root 7490: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, TRUE, NULL))
1.1.1.17 root 7491: goto ret;
7492:
7493: /* Conceive the backup file */
7494: if ((fBackup = _open(szFileName, _O_CREAT|_O_TRUNC|_O_WRONLY|_O_BINARY, _S_IREAD|_S_IWRITE)) == -1)
7495: {
7496: nStatus = ERR_OS_ERROR;
7497: goto error;
7498: }
7499:
7500: // Backup headers
7501:
7502: byte backup[TC_VOLUME_HEADER_GROUP_SIZE];
7503:
7504: bool legacyVolume = volume.CryptoInfo->LegacyVolume ? true : false;
7505: int backupFileSize = legacyVolume ? TC_VOLUME_HEADER_SIZE_LEGACY * 2 : TC_VOLUME_HEADER_GROUP_SIZE;
7506:
7507: // Fill backup buffer with random data
7508: memcpy (originalK2, volume.CryptoInfo->k2, sizeof (volume.CryptoInfo->k2));
7509:
7510: if (Randinit() != ERR_SUCCESS)
7511: {
7512: nStatus = ERR_PARAMETER_INCORRECT;
7513: goto error;
7514: }
7515:
1.1.1.21 root 7516: NormalCursor();
7517: UserEnrichRandomPool (hwndDlg);
7518: WaitCursor();
7519:
1.1.1.17 root 7520: // Temporary keys
7521: if (!RandgetBytes (temporaryKey, EAGetKeySize (volume.CryptoInfo->ea), TRUE)
7522: || !RandgetBytes (volume.CryptoInfo->k2, sizeof (volume.CryptoInfo->k2), FALSE))
7523: {
7524: nStatus = ERR_PARAMETER_INCORRECT;
7525: goto error;
7526: }
7527:
7528: if (EAInit (volume.CryptoInfo->ea, temporaryKey, volume.CryptoInfo->ks) != ERR_SUCCESS || !EAInitMode (volume.CryptoInfo))
7529: {
7530: nStatus = ERR_PARAMETER_INCORRECT;
7531: goto error;
7532: }
7533:
7534: EncryptBuffer (backup, backupFileSize, volume.CryptoInfo);
7535:
7536: memcpy (volume.CryptoInfo->k2, originalK2, sizeof (volume.CryptoInfo->k2));
7537: if (EAInit (volume.CryptoInfo->ea, volume.CryptoInfo->master_keydata, volume.CryptoInfo->ks) != ERR_SUCCESS || !EAInitMode (volume.CryptoInfo))
7538: {
7539: nStatus = ERR_PARAMETER_INCORRECT;
7540: goto error;
7541: }
7542:
7543: // Store header encrypted with a new key
7544: nStatus = ReEncryptVolumeHeader ((char *) backup, FALSE, volume.CryptoInfo, &VolumePassword, FALSE);
7545: if (nStatus != ERR_SUCCESS)
7546: goto error;
7547:
7548: if (hiddenVolume.VolumeIsOpen)
7549: {
7550: nStatus = ReEncryptVolumeHeader ((char *) backup + (legacyVolume ? TC_VOLUME_HEADER_SIZE_LEGACY : TC_VOLUME_HEADER_SIZE),
7551: FALSE, hiddenVolume.CryptoInfo, &hiddenVolPassword, FALSE);
7552:
7553: if (nStatus != ERR_SUCCESS)
7554: goto error;
7555: }
7556:
7557: if (_write (fBackup, backup, backupFileSize) == -1)
7558: {
7559: nStatus = ERR_OS_ERROR;
7560: goto error;
7561: }
7562:
7563: /* Backup has been successfully created */
7564: Warning("VOL_HEADER_BACKED_UP");
7565:
7566: ret:
7567: nStatus = ERR_SUCCESS;
7568:
7569: error:
7570: DWORD dwError = GetLastError ();
7571:
7572: CloseVolume (&volume);
7573: CloseVolume (&hiddenVolume);
7574:
7575: if (fBackup != -1)
7576: _close (fBackup);
7577:
7578: SetLastError (dwError);
7579: if (nStatus != 0)
7580: handleError (hwndDlg, nStatus);
7581:
7582: burn (&VolumePassword, sizeof (VolumePassword));
7583: burn (&hiddenVolPassword, sizeof (hiddenVolPassword));
1.1.1.20 root 7584: burn (temporaryKey, sizeof (temporaryKey));
7585: burn (originalK2, sizeof (originalK2));
1.1.1.17 root 7586:
1.1.1.19 root 7587: RestoreDefaultKeyFilesParam();
1.1.1.21 root 7588: RandStop (FALSE);
1.1.1.19 root 7589: NormalCursor();
7590:
1.1.1.17 root 7591: return nStatus;
7592: }
7593:
7594:
7595: int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
7596: {
7597: int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR;
7598: char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
7599: char szFileName[TC_MAX_PATH];
7600: char szDosDevice[TC_MAX_PATH];
7601: void *dev = INVALID_HANDLE_VALUE;
7602: DWORD dwError;
7603: BOOL bDevice;
7604: unsigned __int64 hostSize = 0;
7605: FILETIME ftCreationTime;
7606: FILETIME ftLastWriteTime;
7607: FILETIME ftLastAccessTime;
7608: wchar_t szTmp[4096];
7609: BOOL bTimeStampValid = FALSE;
7610: HANDLE fBackup = INVALID_HANDLE_VALUE;
7611: LARGE_INTEGER headerOffset;
7612: CRYPTO_INFO *restoredCryptoInfo = NULL;
7613:
7614: switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
7615: {
7616: case 1:
7617: case 2:
7618: if (AskErrNoYes ("RESTORE_HEADER_NOT_FOR_SYS_DEVICE") == IDYES)
7619: CreateRescueDisk ();
7620:
7621: return 0;
7622:
7623: case -1:
1.1.1.19 root 7624: // In some environments (such as PE), the system volume is not located on a hard drive.
7625: // Therefore, we must interpret this return code as "Not a system device path" (otherwise,
7626: // it would not be possible to restore headers on non-system devices in such environments).
7627: // Note that this is rather safe, because bReliableRequired is set to TRUE.
7628:
7629: // NOP
7630: break;
1.1.1.17 root 7631: }
7632:
7633: if (IsMountedVolume (lpszVolume))
7634: {
7635: Warning ("DISMOUNT_FIRST");
7636: return 0;
7637: }
7638:
1.1.1.23 root 7639: if (!VolumePathExists (lpszVolume))
7640: {
7641: handleWin32Error (hwndDlg);
7642: return 0;
7643: }
7644:
1.1.1.17 root 7645: BOOL restoreInternalBackup;
7646:
7647: // Ask the user to select the type of backup (internal/external)
7648: char *volTypeChoices[] = {0, "HEADER_RESTORE_EXTERNAL_INTERNAL", "HEADER_RESTORE_INTERNAL", "HEADER_RESTORE_EXTERNAL", "IDCANCEL", 0};
1.1.1.19 root 7649: switch (AskMultiChoice ((void **) volTypeChoices, FALSE))
1.1.1.17 root 7650: {
7651: case 1:
7652: restoreInternalBackup = TRUE;
7653: break;
7654: case 2:
7655: restoreInternalBackup = FALSE;
7656: break;
7657: default:
7658: return 0;
7659: }
7660:
7661: OpenVolumeContext volume;
7662: volume.VolumeIsOpen = FALSE;
7663:
1.1.1.19 root 7664: WaitCursor();
7665:
1.1.1.17 root 7666: if (restoreInternalBackup)
7667: {
7668: // Restore header from the internal backup
7669:
7670: // Open the volume using backup header
7671: while (TRUE)
7672: {
7673: strncpy (PasswordDlgVolume, lpszVolume, sizeof (PasswordDlgVolume));
7674: if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, FALSE))
7675: {
7676: nStatus = ERR_SUCCESS;
7677: goto ret;
7678: }
7679:
1.1.1.19 root 7680: WaitCursor();
7681:
1.1.1.17 root 7682: if (KeyFilesEnable && FirstKeyFile)
7683: KeyFilesApply (&VolumePassword, FirstKeyFile);
7684:
7685: nStatus = OpenVolume (&volume, lpszVolume, &VolumePassword, TRUE, bPreserveTimestamp, TRUE);
1.1.1.19 root 7686:
7687: NormalCursor();
7688:
1.1.1.17 root 7689: if (nStatus == ERR_SUCCESS)
7690: break;
7691:
7692: if (nStatus != ERR_PASSWORD_WRONG)
7693: goto error;
7694:
7695: handleError (hwndDlg, nStatus);
7696: }
7697:
7698: if (volume.CryptoInfo->LegacyVolume)
7699: {
7700: Error ("VOLUME_HAS_NO_BACKUP_HEADER");
7701: nStatus = ERROR_SUCCESS;
7702: goto error;
7703: }
7704:
7705: // Create a new header with a new salt
7706: char buffer[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
7707:
7708: nStatus = ReEncryptVolumeHeader (buffer, FALSE, volume.CryptoInfo, &VolumePassword, FALSE);
7709: if (nStatus != 0)
7710: goto error;
7711:
7712: headerOffset.QuadPart = volume.CryptoInfo->hiddenVolume ? TC_HIDDEN_VOLUME_HEADER_OFFSET : TC_VOLUME_HEADER_OFFSET;
7713: if (!SetFilePointerEx (volume.HostFileHandle, headerOffset, NULL, FILE_BEGIN))
7714: {
7715: nStatus = ERR_OS_ERROR;
7716: goto error;
7717: }
7718:
1.1.1.25 root 7719: if (!WriteEffectiveVolumeHeader (volume.IsDevice, volume.HostFileHandle, (byte *) buffer))
1.1.1.17 root 7720: {
7721: nStatus = ERR_OS_ERROR;
7722: goto error;
7723: }
7724: }
7725: else
7726: {
7727: // Restore header from an external backup
7728:
7729: swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume);
7730:
7731: if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO)
7732: {
7733: nStatus = ERR_SUCCESS;
7734: goto ret;
7735: }
7736:
7737: /* Select backup file */
1.1.1.19 root 7738: if (!BrowseFiles (hwndDlg, "OPEN_TITLE", szFileName, bHistory, FALSE, NULL))
1.1.1.17 root 7739: {
7740: nStatus = ERR_SUCCESS;
7741: goto ret;
7742: }
7743:
7744: /* Open the backup file */
7745: fBackup = CreateFile (szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7746: if (fBackup == INVALID_HANDLE_VALUE)
7747: {
7748: nStatus = ERR_OS_ERROR;
7749: goto error;
7750: }
7751:
7752: // Determine size of the backup file
7753: LARGE_INTEGER backupSize;
7754: if (!GetFileSizeEx (fBackup, &backupSize))
7755: {
7756: nStatus = ERR_OS_ERROR;
7757: goto error;
7758: }
7759:
7760: CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice);
7761:
7762: if (bDevice == FALSE)
7763: strcpy (szCFDevice, szDiskFile);
7764: else
7765: {
7766: nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE);
7767: if (nDosLinkCreated != 0)
7768: goto error;
7769: }
7770:
7771: // Open the volume
7772: dev = CreateFile (szCFDevice, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
7773:
7774: if (dev == INVALID_HANDLE_VALUE)
7775: {
7776: nStatus = ERR_OS_ERROR;
7777: goto error;
7778: }
7779:
7780: // Determine volume host size
7781: if (bDevice)
7782: {
7783: PARTITION_INFORMATION diskInfo;
7784: DWORD dwResult;
7785: BOOL bResult;
7786:
7787: bResult = GetPartitionInfo (lpszVolume, &diskInfo);
7788:
7789: if (bResult)
7790: {
7791: hostSize = diskInfo.PartitionLength.QuadPart;
7792: }
7793: else
7794: {
7795: DISK_GEOMETRY driveInfo;
7796:
7797: bResult = DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
7798: &driveInfo, sizeof (driveInfo), &dwResult, NULL);
7799:
7800: if (!bResult)
7801: goto error;
7802:
7803: hostSize = driveInfo.Cylinders.QuadPart * driveInfo.BytesPerSector *
7804: driveInfo.SectorsPerTrack * driveInfo.TracksPerCylinder;
7805: }
7806:
7807: if (hostSize == 0)
7808: {
7809: nStatus = ERR_VOL_SIZE_WRONG;
7810: goto error;
7811: }
7812: }
7813: else
7814: {
7815: LARGE_INTEGER fileSize;
7816: if (!GetFileSizeEx (dev, &fileSize))
7817: {
7818: nStatus = ERR_OS_ERROR;
7819: goto error;
7820: }
7821:
7822: hostSize = fileSize.QuadPart;
7823: }
7824:
7825: if (!bDevice && bPreserveTimestamp)
7826: {
7827: /* Remember the container modification/creation date and time. */
7828:
7829: if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
7830: bTimeStampValid = FALSE;
7831: else
7832: bTimeStampValid = TRUE;
7833: }
7834:
7835: /* Read the volume header from the backup file */
7836: char buffer[TC_VOLUME_HEADER_GROUP_SIZE];
7837:
7838: DWORD bytesRead;
7839: if (!ReadFile (fBackup, buffer, sizeof (buffer), &bytesRead, NULL))
7840: {
7841: nStatus = ERR_OS_ERROR;
7842: goto error;
7843: }
7844:
7845: if (bytesRead != backupSize.QuadPart)
7846: {
7847: nStatus = ERR_VOL_SIZE_WRONG;
7848: goto error;
7849: }
7850:
7851: LARGE_INTEGER headerOffset;
7852: LARGE_INTEGER headerBackupOffset;
7853: bool legacyBackup;
7854: int headerOffsetBackupFile;
7855:
7856: // Determine the format of the backup file
7857: switch (backupSize.QuadPart)
7858: {
7859: case TC_VOLUME_HEADER_GROUP_SIZE:
7860: legacyBackup = false;
7861: break;
7862:
7863: case TC_VOLUME_HEADER_SIZE_LEGACY * 2:
7864: legacyBackup = true;
7865: break;
7866:
7867: default:
7868: Error ("HEADER_BACKUP_SIZE_INCORRECT");
7869: nStatus = ERR_SUCCESS;
7870: goto error;
7871: }
7872:
7873: // Open the header
7874: while (TRUE)
7875: {
7876: if (!AskVolumePassword (hwndDlg, &VolumePassword, "ENTER_HEADER_BACKUP_PASSWORD", FALSE))
7877: {
7878: nStatus = ERR_SUCCESS;
7879: goto ret;
7880: }
7881:
7882: if (KeyFilesEnable && FirstKeyFile)
7883: KeyFilesApply (&VolumePassword, FirstKeyFile);
7884:
7885: // Decrypt volume header
7886: headerOffsetBackupFile = 0;
7887: for (int type = TC_VOLUME_TYPE_NORMAL; type <= TC_VOLUME_TYPE_HIDDEN; ++type)
7888: {
7889: if (type == TC_VOLUME_TYPE_HIDDEN)
7890: headerOffsetBackupFile += (legacyBackup ? TC_VOLUME_HEADER_SIZE_LEGACY : TC_VOLUME_HEADER_SIZE);
7891:
1.1.1.19 root 7892: nStatus = ReadVolumeHeader (FALSE, buffer + headerOffsetBackupFile, &VolumePassword, &restoredCryptoInfo, NULL);
1.1.1.17 root 7893: if (nStatus == ERR_SUCCESS)
7894: break;
7895: }
7896:
7897: if (nStatus == ERR_SUCCESS)
7898: break;
7899:
7900: if (nStatus != ERR_PASSWORD_WRONG)
7901: goto error;
7902:
7903: handleError (hwndDlg, nStatus);
7904: }
7905:
7906: BOOL hiddenVol = restoredCryptoInfo->hiddenVolume;
7907:
7908: if (legacyBackup)
7909: {
7910: headerOffset.QuadPart = hiddenVol ? hostSize - TC_HIDDEN_VOLUME_HEADER_OFFSET_LEGACY : TC_VOLUME_HEADER_OFFSET;
7911: }
7912: else
7913: {
7914: headerOffset.QuadPart = hiddenVol ? TC_HIDDEN_VOLUME_HEADER_OFFSET : TC_VOLUME_HEADER_OFFSET;
7915: headerBackupOffset.QuadPart = hiddenVol ? hostSize - TC_VOLUME_HEADER_SIZE : hostSize - TC_VOLUME_HEADER_GROUP_SIZE;
7916: }
7917:
7918: WaitCursor();
7919:
7920: // Restore header encrypted with a new key
7921: ReEncryptVolumeHeader (buffer, FALSE, restoredCryptoInfo, &VolumePassword, FALSE);
7922:
7923: if (!SetFilePointerEx (dev, headerOffset, NULL, FILE_BEGIN))
7924: {
7925: nStatus = ERR_OS_ERROR;
7926: goto error;
7927: }
7928:
1.1.1.25 root 7929: if (!WriteEffectiveVolumeHeader (bDevice, dev, (byte *) buffer))
1.1.1.17 root 7930: {
7931: nStatus = ERR_OS_ERROR;
7932: goto error;
7933: }
7934:
7935: if (!restoredCryptoInfo->LegacyVolume)
7936: {
7937: // Restore backup header encrypted with a new key
7938: ReEncryptVolumeHeader (buffer, FALSE, restoredCryptoInfo, &VolumePassword, FALSE);
7939:
7940: if (!SetFilePointerEx (dev, headerBackupOffset, NULL, FILE_BEGIN))
7941: {
7942: nStatus = ERR_OS_ERROR;
7943: goto error;
7944: }
7945:
1.1.1.25 root 7946: if (!WriteEffectiveVolumeHeader (bDevice, dev, (byte *) buffer))
1.1.1.17 root 7947: {
7948: nStatus = ERR_OS_ERROR;
7949: goto error;
7950: }
7951: }
7952: }
7953:
7954:
7955: /* Volume header has been successfully restored */
7956:
7957: Info("VOL_HEADER_RESTORED");
7958: ret:
7959: nStatus = ERR_SUCCESS;
7960:
7961: error:
7962: dwError = GetLastError ();
7963: NormalCursor();
7964:
7965: if (restoreInternalBackup)
7966: {
7967: CloseVolume (&volume);
7968: }
7969: else
7970: {
7971: if (restoredCryptoInfo)
7972: crypto_close (restoredCryptoInfo);
7973:
7974: if (bTimeStampValid)
1.1.1.24 root 7975: SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);
1.1.1.17 root 7976:
7977: if (dev != INVALID_HANDLE_VALUE)
7978: CloseHandle (dev);
7979:
7980: if (fBackup != INVALID_HANDLE_VALUE)
7981: CloseHandle (fBackup);
7982:
7983: if (nDosLinkCreated == 0)
7984: RemoveFakeDosName (szDiskFile, szDosDevice);
7985: }
7986:
7987: SetLastError (dwError);
7988: if (nStatus != 0)
7989: handleError (hwndDlg, nStatus);
7990:
7991: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.19 root 7992: RestoreDefaultKeyFilesParam();
1.1.1.21 root 7993: RandStop (FALSE);
1.1.1.19 root 7994: NormalCursor();
1.1.1.21 root 7995:
1.1.1.17 root 7996: return nStatus;
7997: }
1.1.1.19 root 7998:
7999:
1.1.1.25 root 8000: void SetDriverConfigurationFlag (uint32 flag, BOOL state)
1.1.1.19 root 8001: {
1.1.1.25 root 8002: BootEncObj->SetDriverConfigurationFlag (flag, state ? true : false);
1.1.1.19 root 8003: }
8004:
8005:
1.1.1.25 root 8006: static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1.1.1.19 root 8007: {
1.1.1.25 root 8008: WORD lw = LOWORD (wParam);
8009:
8010: switch (msg)
8011: {
8012: case WM_INITDIALOG:
8013: {
8014: LocalizeDialog (hwndDlg, "IDD_PERFORMANCE_SETTINGS");
8015:
8016: uint32 driverConfig = ReadDriverConfigurationFlags();
8017: CheckDlgButton (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION, (driverConfig & TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION) ? BST_UNCHECKED : BST_CHECKED);
8018:
8019: SYSTEM_INFO sysInfo;
8020: GetSystemInfo (&sysInfo);
8021:
8022: HWND freeCpuCombo = GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT);
8023: uint32 encryptionFreeCpuCount = ReadEncryptionThreadPoolFreeCpuCountLimit();
8024:
8025: if (encryptionFreeCpuCount > sysInfo.dwNumberOfProcessors - 1)
8026: encryptionFreeCpuCount = sysInfo.dwNumberOfProcessors - 1;
8027:
8028: for (uint32 i = 1; i < sysInfo.dwNumberOfProcessors; ++i)
8029: {
8030: stringstream s;
8031: s << i;
8032: AddComboPair (freeCpuCombo, s.str().c_str(), i);
8033: }
8034:
8035: if (sysInfo.dwNumberOfProcessors < 2 || encryptionFreeCpuCount == 0)
8036: EnableWindow (freeCpuCombo, FALSE);
8037:
8038: if (sysInfo.dwNumberOfProcessors < 2)
8039: EnableWindow (GetDlgItem (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL), FALSE);
8040:
8041: if (encryptionFreeCpuCount != 0)
8042: {
8043: CheckDlgButton (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL, BST_CHECKED);
8044: SendMessage (freeCpuCombo, CB_SETCURSEL, encryptionFreeCpuCount - 1, 0);
8045: }
8046:
8047: SetWindowTextW (GetDlgItem (hwndDlg, IDT_LIMIT_ENC_THREAD_POOL_NOTE), GetString("LIMIT_ENC_THREAD_POOL_NOTE"));
8048:
8049: SetDlgItemTextW (hwndDlg, IDC_HW_AES_SUPPORTED_BY_CPU, (wstring (L" ") + (GetString (is_aes_hw_cpu_supported() ? "UISTR_YES" : "UISTR_NO"))).c_str());
8050:
8051: ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_HW_ACCELERATION);
8052: ToHyperlink (hwndDlg, IDC_MORE_INFO_ON_THREAD_BASED_PARALLELIZATION);
8053: }
8054: return 0;
8055:
8056: case WM_COMMAND:
8057:
8058: switch (lw)
8059: {
8060: case IDCANCEL:
8061: EndDialog (hwndDlg, lw);
8062: return 1;
8063:
8064: case IDOK:
8065: {
8066: BOOL disableHW = !IsDlgButtonChecked (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION);
8067:
8068: try
8069: {
8070: try
8071: {
8072: BootEncStatus = BootEncObj->GetStatus();
8073: }
8074: catch (...)
8075: {
8076: BootEncStatus.DriveMounted = false;
8077: }
8078:
8079: if (BootEncStatus.DriveMounted)
8080: {
8081: byte userConfig;
8082: string customUserMessage;
8083: uint16 bootLoaderVersion;
8084:
8085: BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig, &customUserMessage, &bootLoaderVersion);
8086:
8087: if (bootLoaderVersion != VERSION_NUM)
8088: Warning ("BOOT_LOADER_VERSION_INCORRECT_PREFERENCES");
8089:
8090: if (disableHW)
8091: userConfig |= TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION;
8092: else
8093: userConfig &= ~TC_BOOT_USER_CFG_FLAG_DISABLE_HW_ENCRYPTION;
8094:
8095: BootEncObj->WriteBootSectorUserConfig (userConfig, customUserMessage);
8096: }
8097:
8098: SetDriverConfigurationFlag (TC_DRIVER_CONFIG_DISABLE_HARDWARE_ENCRYPTION, disableHW);
8099:
8100: DWORD bytesReturned;
8101: if (!DeviceIoControl (hDriver, TC_IOCTL_REREAD_DRIVER_CONFIG, NULL, 0, NULL, 0, &bytesReturned, NULL))
8102: handleWin32Error (hwndDlg);
8103:
8104: EnableHwEncryption (!disableHW);
8105:
8106: uint32 cpuFreeCount = 0;
8107: if (IsDlgButtonChecked (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL))
8108: {
8109: LRESULT cpuFreeItem = SendMessage (GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT), CB_GETCURSEL, 0, 0);
8110: if (cpuFreeItem != CB_ERR)
8111: cpuFreeCount = (uint32) (cpuFreeItem + 1);
8112: }
8113:
8114: if (ReadEncryptionThreadPoolFreeCpuCountLimit() != cpuFreeCount)
8115: {
8116: BootEncObj->WriteLocalMachineRegistryDwordValue ("SYSTEM\\CurrentControlSet\\Services\\truecrypt", TC_ENCRYPTION_FREE_CPU_COUNT_REG_VALUE_NAME, cpuFreeCount);
8117: Warning ("SETTING_REQUIRES_REBOOT");
8118: }
8119:
8120: EndDialog (hwndDlg, lw);
8121: return 1;
8122: }
8123: catch (Exception &e)
8124: {
8125: e.Show (hwndDlg);
8126: }
8127: }
8128: return 1;
8129:
8130: case IDC_ENABLE_HARDWARE_ENCRYPTION:
8131: if (!IsDlgButtonChecked (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION)
8132: && AskWarnYesNo ("CONFIRM_SETTING_DEGRADES_PERFORMANCE") == IDNO)
8133: {
8134: CheckDlgButton (hwndDlg, IDC_ENABLE_HARDWARE_ENCRYPTION, BST_CHECKED);
8135: }
8136: return 1;
8137:
8138: case IDC_LIMIT_ENC_THREAD_POOL:
8139: if (IsDlgButtonChecked (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL)
8140: && AskWarnYesNo ("CONFIRM_SETTING_DEGRADES_PERFORMANCE") == IDNO)
8141: {
8142: CheckDlgButton (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL, BST_UNCHECKED);
8143: }
8144: else
8145: {
8146: SendMessage (GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT), CB_SETCURSEL, 0, 0);
8147: Warning ("SETTING_REQUIRES_REBOOT"); // Warn the user before he thinks about benchmarking
8148: }
8149:
8150: EnableWindow (GetDlgItem (hwndDlg, IDC_ENCRYPTION_FREE_CPU_COUNT), IsDlgButtonChecked (hwndDlg, IDC_LIMIT_ENC_THREAD_POOL));
8151: return 1;
8152:
8153: case IDC_BENCHMARK:
8154: Benchmark (hwndDlg);
8155: return 1;
8156:
8157: case IDC_MORE_INFO_ON_HW_ACCELERATION:
8158: Applink ("hwacceleration", TRUE, "");
8159: return 1;
8160:
8161: case IDC_MORE_INFO_ON_THREAD_BASED_PARALLELIZATION:
8162: Applink ("parallelization", TRUE, "");
8163: return 1;
8164: }
8165:
8166: return 0;
8167: }
8168:
8169: return 0;
1.1.1.19 root 8170: }
8171:
8172:
8173: static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
8174: {
8175: WORD lw = LOWORD (wParam);
8176:
8177: switch (msg)
8178: {
8179: case WM_INITDIALOG:
8180: LocalizeDialog (hwndDlg, "IDD_TOKEN_PREFERENCES");
8181: SetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, SecurityTokenLibraryPath);
8182: CheckDlgButton (hwndDlg, IDC_CLOSE_TOKEN_SESSION_AFTER_MOUNT, CloseSecurityTokenSessionsAfterMount ? BST_CHECKED : BST_UNCHECKED);
8183:
8184: SetWindowTextW (GetDlgItem (hwndDlg, IDT_PKCS11_LIB_HELP), GetString("PKCS11_LIB_LOCATION_HELP"));
8185:
8186: return 0;
8187:
8188: case WM_COMMAND:
8189:
8190: switch (lw)
8191: {
8192: case IDCANCEL:
8193: EndDialog (hwndDlg, lw);
8194: return 1;
8195:
8196: case IDOK:
8197: {
8198: char securityTokenLibraryPath[MAX_PATH];
8199: GetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, securityTokenLibraryPath, sizeof (securityTokenLibraryPath));
8200:
8201: if (securityTokenLibraryPath[0] == 0)
8202: {
8203: try
8204: {
8205: SecurityToken::CloseLibrary();
8206: }
8207: catch (...) { }
8208:
8209: SecurityTokenLibraryPath[0] = 0;
8210: }
8211: else
8212: {
8213: char prevSecurityTokenLibraryPath[MAX_PATH];
8214: strcpy (prevSecurityTokenLibraryPath, SecurityTokenLibraryPath);
8215: strcpy (SecurityTokenLibraryPath, securityTokenLibraryPath);
8216:
8217: if (!InitSecurityTokenLibrary())
8218: {
8219: strcpy (SecurityTokenLibraryPath, prevSecurityTokenLibraryPath);
8220: return 1;
8221: }
8222: }
8223:
1.1.1.20 root 8224: CloseSecurityTokenSessionsAfterMount = (IsDlgButtonChecked (hwndDlg, IDC_CLOSE_TOKEN_SESSION_AFTER_MOUNT) == BST_CHECKED);
8225:
1.1.1.19 root 8226: WaitCursor ();
8227: SaveSettings (hwndDlg);
8228: NormalCursor ();
8229:
8230: EndDialog (hwndDlg, lw);
8231: return 1;
8232: }
8233:
8234: case IDC_AUTO_DETECT_PKCS11_MODULE:
8235: {
8236: char systemDir[MAX_PATH];
8237: GetSystemDirectory (systemDir, sizeof (systemDir));
8238: WIN32_FIND_DATA findData;
8239: bool found = false;
8240:
8241: WaitCursor();
8242:
8243: HANDLE find = FindFirstFile ((string (systemDir) + "\\*.dll").c_str(), &findData);
8244: while (!found && find != INVALID_HANDLE_VALUE)
8245: {
8246: string dllPathname = string (systemDir) + "\\" + findData.cFileName;
8247: DWORD fileSize;
8248:
8249: char *file = LoadFile (dllPathname.c_str(), &fileSize);
8250: if (file)
8251: {
8252: const char *functionName = "C_GetFunctionList";
8253: size_t strLen = strlen (functionName);
8254:
8255: if (fileSize > strLen)
8256: {
8257: for (size_t i = 0; i < fileSize - strLen; ++i)
8258: {
8259: if (memcmp (file + i, functionName, strLen) == 0)
8260: {
8261: HMODULE module = LoadLibrary (dllPathname.c_str());
8262: if (module)
8263: {
8264: if (GetProcAddress (module, functionName))
8265: {
8266: SetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, dllPathname.c_str());
8267: found = true;
8268:
8269: FreeLibrary (module);
8270: break;
8271: }
8272:
8273: FreeLibrary (module);
8274: }
8275: }
8276: }
8277: }
8278:
8279: free (file);
8280: }
8281:
8282: if (!FindNextFile (find, &findData))
8283: break;
8284: }
8285:
8286: if (find != INVALID_HANDLE_VALUE)
8287: FindClose (find);
8288:
8289: NormalCursor();
8290:
8291: if (!found)
8292: Warning ("PKCS11_MODULE_AUTO_DETECTION_FAILED");
8293:
8294: return 1;
8295: }
8296:
8297: case IDC_SELECT_PKCS11_MODULE:
8298: {
8299: char securityTokenLibraryPath[MAX_PATH];
8300: char systemDir[MAX_PATH];
8301: wchar_t browseFilter[1024];
8302:
8303: Info ("SELECT_PKCS11_MODULE_HELP");
8304:
8305: wsprintfW (browseFilter, L"%ls (*.dll)%c*.dll%c%c", GetString ("DLL_FILES"), 0, 0, 0);
8306: GetSystemDirectory (systemDir, sizeof (systemDir));
8307:
8308: if (BrowseFilesInDir (hwndDlg, "SELECT_PKCS11_MODULE", systemDir, securityTokenLibraryPath, TRUE, FALSE, browseFilter))
8309: SetDlgItemText (hwndDlg, IDC_PKCS11_MODULE, securityTokenLibraryPath);
8310: return 1;
8311: }
8312: }
8313: return 0;
8314: }
8315:
8316: return 0;
8317: }
8318:
8319:
8320: void SecurityTokenPreferencesDialog (HWND hwndDlg)
8321: {
8322: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_TOKEN_PREFERENCES), hwndDlg, (DLGPROC) SecurityTokenPreferencesDlgProc, 0);
8323: }
8324:
8325:
8326: static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
8327: {
8328: WORD lw = LOWORD (wParam);
8329:
8330: switch (msg)
8331: {
8332: case WM_INITDIALOG:
8333: {
1.1.1.23 root 8334: if (!BootEncObj->GetStatus().DriveMounted)
1.1.1.19 root 8335: {
8336: Warning ("SYS_DRIVE_NOT_ENCRYPTED");
8337: EndDialog (hwndDlg, IDCANCEL);
8338: return 1;
8339: }
8340:
8341: try
8342: {
8343: LocalizeDialog (hwndDlg, "IDD_SYSENC_SETTINGS");
8344:
1.1.1.23 root 8345: uint32 driverConfig = ReadDriverConfigurationFlags();
1.1.1.19 root 8346: byte userConfig;
8347: string customUserMessage;
1.1.1.21 root 8348: uint16 bootLoaderVersion;
8349:
8350: BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig, &customUserMessage, &bootLoaderVersion);
8351:
8352: if (bootLoaderVersion != VERSION_NUM)
8353: Warning ("BOOT_LOADER_VERSION_INCORRECT_PREFERENCES");
1.1.1.19 root 8354:
8355: SendMessage (GetDlgItem (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE), EM_LIMITTEXT, TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH, 0);
8356: SetDlgItemText (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE, customUserMessage.c_str());
8357:
8358: CheckDlgButton (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT, (userConfig & TC_BOOT_USER_CFG_FLAG_SILENT_MODE) ? BST_CHECKED : BST_UNCHECKED);
8359: CheckDlgButton (hwndDlg, IDC_ALLOW_ESC_PBA_BYPASS, (userConfig & TC_BOOT_USER_CFG_FLAG_DISABLE_ESC) ? BST_UNCHECKED : BST_CHECKED);
1.1.1.23 root 8360: CheckDlgButton (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD, (driverConfig & TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD) ? BST_CHECKED : BST_UNCHECKED);
1.1.1.19 root 8361:
8362: SetWindowTextW (GetDlgItem (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE_HELP), GetString("CUSTOM_BOOT_LOADER_MESSAGE_HELP"));
8363: }
8364: catch (Exception &e)
8365: {
8366: e.Show (hwndDlg);
8367: EndDialog (hwndDlg, IDCANCEL);
8368: return 1;
8369: }
8370: }
8371: return 0;
8372:
8373: case WM_COMMAND:
8374:
8375: switch (lw)
8376: {
8377: case IDCANCEL:
8378: EndDialog (hwndDlg, lw);
8379: return 1;
8380:
8381: case IDOK:
8382: {
1.1.1.23 root 8383: if (!BootEncObj->GetStatus().DriveMounted)
8384: {
8385: EndDialog (hwndDlg, IDCANCEL);
8386: return 1;
8387: }
8388:
1.1.1.19 root 8389: char customUserMessage[TC_BOOT_SECTOR_USER_MESSAGE_MAX_LENGTH + 1];
8390: GetDlgItemText (hwndDlg, IDC_CUSTOM_BOOT_LOADER_MESSAGE, customUserMessage, sizeof (customUserMessage));
8391:
1.1.1.25 root 8392: byte userConfig;
8393: try
8394: {
8395: BootEncObj->ReadBootSectorConfig (nullptr, 0, &userConfig);
8396: }
8397: catch (Exception &e)
8398: {
8399: e.Show (hwndDlg);
8400: return 1;
8401: }
8402:
1.1.1.19 root 8403: if (IsDlgButtonChecked (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT))
8404: userConfig |= TC_BOOT_USER_CFG_FLAG_SILENT_MODE;
1.1.1.25 root 8405: else
8406: userConfig &= ~TC_BOOT_USER_CFG_FLAG_SILENT_MODE;
1.1.1.19 root 8407:
8408: if (!IsDlgButtonChecked (hwndDlg, IDC_ALLOW_ESC_PBA_BYPASS))
8409: userConfig |= TC_BOOT_USER_CFG_FLAG_DISABLE_ESC;
1.1.1.25 root 8410: else
8411: userConfig &= ~TC_BOOT_USER_CFG_FLAG_DISABLE_ESC;
1.1.1.19 root 8412:
8413: try
8414: {
8415: BootEncObj->WriteBootSectorUserConfig (userConfig, customUserMessage);
1.1.1.23 root 8416: SetDriverConfigurationFlag (TC_DRIVER_CONFIG_CACHE_BOOT_PASSWORD, IsDlgButtonChecked (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD));
1.1.1.19 root 8417: }
8418: catch (Exception &e)
8419: {
8420: e.Show (hwndDlg);
8421: return 1;
8422: }
8423:
8424: EndDialog (hwndDlg, lw);
8425: return 1;
8426: }
8427:
8428: case IDC_DISABLE_BOOT_LOADER_OUTPUT:
8429: if ((IsDlgButtonChecked (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT))
8430: && AskWarnYesNo ("CUSTOM_BOOT_LOADER_MESSAGE_PROMPT") == IDNO)
8431: {
8432: CheckDlgButton (hwndDlg, IDC_DISABLE_BOOT_LOADER_OUTPUT, BST_UNCHECKED);
8433: }
8434:
8435: break;
8436:
8437: case IDC_BOOT_LOADER_CACHE_PASSWORD:
8438: if (IsDlgButtonChecked (hwndDlg, IDC_BOOT_LOADER_CACHE_PASSWORD))
8439: Warning ("BOOT_PASSWORD_CACHE_KEYBOARD_WARNING");
8440:
8441: break;
8442: }
8443: return 0;
8444: }
8445:
8446: return 0;
8447: }
8448:
8449:
1.1.1.25 root 8450: void MountSelectedVolume (HWND hwndDlg, BOOL mountWithOptions)
1.1.1.23 root 8451: {
1.1.1.25 root 8452: if (!VolumeSelected(hwndDlg))
8453: {
8454: Warning ("NO_VOLUME_SELECTED");
8455: }
8456: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == TC_MLIST_ITEM_FREE)
8457: {
8458: mountOptions = defaultMountOptions;
8459: bPrebootPasswordDlgMode = FALSE;
1.1.1.23 root 8460:
1.1.1.25 root 8461: if (mountWithOptions || GetAsyncKeyState (VK_CONTROL) < 0)
8462: {
8463: if (IDCANCEL == DialogBoxParamW (hInst,
8464: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
8465: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
8466: return;
8467:
8468: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
8469: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile);
8470: }
8471:
8472: if (CheckMountList ())
8473: Mount (hwndDlg, 0, 0);
8474: }
8475: else
8476: Warning ("SELECT_FREE_DRIVE");
8477: }
8478:
8479:
8480: BOOL GetExecutableImageInformation (const string &path, string &version, string &description, string &companyName, string &productName)
8481: {
8482: DWORD handle;
8483: DWORD size = GetFileVersionInfoSize (path.c_str(), &handle);
8484: if (size == 0)
8485: return FALSE;
8486:
8487: void *buf = err_malloc (size);
8488: finally_do_arg (void*, buf, { free (finally_arg); });
8489:
8490: if (!GetFileVersionInfo (path.c_str(), handle, size, buf))
8491: return FALSE;
8492:
8493: version = description = companyName = productName = "";
8494:
8495: UINT varSize;
8496: VS_FIXEDFILEINFO *fileInfo;
8497: if (VerQueryValue (buf, "\\", (LPVOID *) &fileInfo, &varSize) && varSize > 0)
1.1.1.23 root 8498: {
1.1.1.25 root 8499: stringstream s;
8500: s << HIWORD (fileInfo->dwFileVersionMS) << '.' << LOWORD (fileInfo->dwFileVersionMS) << '.' << HIWORD (fileInfo->dwFileVersionLS) << '.' << LOWORD (fileInfo->dwFileVersionLS);
8501: version = s.str();
8502: }
8503:
8504: DWORD *langCodes;
8505: if (VerQueryValue (buf, "\\VarFileInfo\\Translation", (LPVOID *) &langCodes, &varSize) && varSize >= sizeof (DWORD))
8506: {
8507: char prefix[128];
8508: sprintf_s (prefix, sizeof (prefix), "\\StringFileInfo\\%04x%04x\\", LOWORD (langCodes[0]), HIWORD (langCodes[0]));
8509:
8510: char *str;
8511: if (VerQueryValue (buf, (string (prefix) + "FileDescription").c_str(), (LPVOID *) &str, &varSize) && varSize > 0)
8512: description = str;
8513:
8514: if (VerQueryValue (buf, (string (prefix) + "CompanyName").c_str(), (LPVOID *) &str, &varSize) && varSize > 0)
8515: companyName = str;
8516:
8517: if (VerQueryValue (buf, (string (prefix) + "ProductName").c_str(), (LPVOID *) &str, &varSize) && varSize > 0)
8518: productName = str;
8519: }
8520:
8521: return TRUE;
8522: }
8523:
8524:
8525: void AnalyzeKernelMiniDump (HWND hwndDlg)
8526: {
8527: char winDir[MAX_PATH] = { 0 };
8528: GetWindowsDirectory (winDir, sizeof (winDir));
8529:
8530: string dumpPath = FindLatestFileOrDirectory (string (winDir) + "\\Minidump", "*.dmp", false, true);
8531: if (dumpPath.empty())
8532: {
8533: Error ("NO_MINIDUMP_FOUND");
8534: return;
8535: }
8536:
8537: STARTUPINFO startupInfo;
8538: PROCESS_INFORMATION procInfo;
8539:
8540: ZeroMemory (&startupInfo, sizeof (startupInfo));
8541: ZeroMemory (&procInfo, sizeof (procInfo));
8542:
8543: if (!IsApplicationInstalled (Is64BitOs() ? "Debugging Tools for Windows (x64)" : "Debugging Tools for Windows (x86)"))
8544: {
8545: if (AskOkCancel ("ASK_DEBUGGER_INSTALL") != IDOK)
8546: return;
8547:
8548: if (!CreateProcess (NULL, (LPSTR) (string ("msiexec.exe /qb /i " TC_APPLINK "&dest=ms-debug-tools-x") + (Is64BitOs() ? "64" : "86")).c_str(),
8549: NULL, NULL, FALSE, 0, NULL, NULL, &startupInfo, &procInfo))
1.1.1.23 root 8550: {
1.1.1.25 root 8551: handleWin32Error (hwndDlg);
8552: return;
8553: }
8554:
8555: WaitCursor();
8556: WaitForSingleObject (procInfo.hProcess, INFINITE);
8557: NormalCursor();
8558:
8559: DWORD exitCode;
8560: if (!GetExitCodeProcess (procInfo.hProcess, &exitCode) || exitCode != 0)
8561: return;
8562: }
8563:
8564: if (AskOkCancel ("SYSTEM_CRASH_ANALYSIS_INFO") == IDCANCEL)
8565: return;
8566:
8567: ZeroMemory (&startupInfo, sizeof (startupInfo));
8568: ZeroMemory (&procInfo, sizeof (procInfo));
8569:
8570: SECURITY_ATTRIBUTES securityAttrib;
8571: securityAttrib.bInheritHandle = TRUE;
8572: securityAttrib.nLength = sizeof (securityAttrib);
8573: securityAttrib.lpSecurityDescriptor = NULL;
8574:
8575: HANDLE hChildStdoutWrite = INVALID_HANDLE_VALUE;
8576: HANDLE hChildStdoutRead = INVALID_HANDLE_VALUE;
8577: if (!CreatePipe (&hChildStdoutRead, &hChildStdoutWrite, &securityAttrib, 0))
8578: {
8579: handleWin32Error (hwndDlg);
8580: return;
8581: }
8582: SetHandleInformation (hChildStdoutRead, HANDLE_FLAG_INHERIT, 0);
8583:
8584: startupInfo.hStdInput = INVALID_HANDLE_VALUE;
8585: startupInfo.hStdOutput = hChildStdoutWrite;
8586: startupInfo.cb = sizeof (startupInfo);
8587: startupInfo.hStdError = hChildStdoutWrite;
8588: startupInfo.dwFlags |= STARTF_USESTDHANDLES;
8589:
8590: list <string> kdPaths;
8591: string kdPath;
8592: char progPath[MAX_PATH];
8593: if (SHGetSpecialFolderPath (hwndDlg, progPath, CSIDL_PROGRAM_FILES, FALSE))
8594: {
8595: if (Is64BitOs())
8596: {
8597: string s = progPath;
8598: size_t p = s.find (" (x86)");
8599: if (p != string::npos)
1.1.1.23 root 8600: {
1.1.1.25 root 8601: s = s.substr (0, p);
8602: if (_access (s.c_str(), 0) != -1)
8603: strcpy_s (progPath, sizeof (progPath), s.c_str());
1.1.1.23 root 8604: }
1.1.1.25 root 8605: }
1.1.1.23 root 8606:
1.1.1.25 root 8607: kdPath = string (progPath) + "\\Debugging Tools for Windows (" + (Is64BitOs() ? "x64" : "x86") + ")\\kd.exe";
8608: kdPaths.push_back (kdPath);
8609: }
1.1.1.23 root 8610:
1.1.1.25 root 8611: kdPath = FindLatestFileOrDirectory (string (winDir).substr (0, 1) + ":\\WinDDK", "*", true, false);
8612: kdPath += "\\Debuggers\\kd.exe";
8613: kdPaths.push_back (kdPath);
1.1.1.23 root 8614:
1.1.1.25 root 8615: kdPaths.push_back ("kd.exe");
8616:
8617: bool kdRunning = false;
8618: foreach (const string &kdPath, kdPaths)
8619: {
8620: if (CreateProcess (NULL, (LPSTR) ("\"" + kdPath + "\" -z \"" + dumpPath + "\" -y http://msdl.microsoft.com/download/symbols -c \".bugcheck; !analyze -v; q\"").c_str(),
8621: NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &procInfo))
8622: {
8623: kdRunning = true;
8624: break;
1.1.1.23 root 8625: }
1.1.1.25 root 8626: }
1.1.1.23 root 8627:
1.1.1.25 root 8628: if (!kdRunning)
8629: {
8630: handleWin32Error (hwndDlg);
8631: Error ("DEBUGGER_NOT_FOUND");
8632: return;
8633: }
1.1.1.23 root 8634:
1.1.1.25 root 8635: EnableElevatedCursorChange (hwndDlg);
8636: WaitCursor();
1.1.1.23 root 8637:
1.1.1.25 root 8638: CloseHandle (procInfo.hProcess);
8639: CloseHandle (procInfo.hThread);
8640: CloseHandle (hChildStdoutWrite);
1.1.1.23 root 8641:
1.1.1.25 root 8642: string output;
1.1.1.23 root 8643:
1.1.1.25 root 8644: while (TRUE)
8645: {
8646: DWORD bytesReceived;
8647: char pipeBuffer [4096];
1.1.1.23 root 8648:
1.1.1.25 root 8649: if (!ReadFile (hChildStdoutRead, pipeBuffer, sizeof (pipeBuffer), &bytesReceived, NULL))
8650: break;
1.1.1.23 root 8651:
1.1.1.25 root 8652: output.insert (output.size(), pipeBuffer, bytesReceived);
8653: }
1.1.1.23 root 8654:
1.1.1.25 root 8655: NormalCursor();
1.1.1.23 root 8656:
1.1.1.25 root 8657: bool otherDriver = (StringToUpperCase (output).find (StringToUpperCase (TC_APP_NAME)) == string::npos);
8658:
8659: size_t p, p2;
8660: while ((p = output.find ('`')) != string::npos)
8661: output.erase (output.begin() + p);
8662:
8663: p = output.find ("Bugcheck code ");
8664: if (p == string::npos)
8665: {
8666: Error ("ERR_PARAMETER_INCORRECT");
8667: return;
8668: }
8669:
8670: uint64 bugcheckCode;
8671: int n = sscanf (output.substr (p + 14, 8).c_str(), "%I64X", &bugcheckCode);
8672: if (n != 1)
8673: {
8674: Error ("ERR_PARAMETER_INCORRECT");
8675: return;
8676: }
1.1.1.23 root 8677:
1.1.1.25 root 8678: p = output.find ("Arguments ", p);
8679:
8680: uint64 bugcheckArgs[4];
8681: n = sscanf (output.substr (p + 10, (Is64BitOs() ? 17 : 9) * 4).c_str(), "%I64X %I64X %I64X %I64X", &bugcheckArgs[0], &bugcheckArgs[1], &bugcheckArgs[2], &bugcheckArgs[3]);
8682: if (n != 4)
8683: {
8684: Error ("ERR_PARAMETER_INCORRECT");
8685: return;
8686: }
8687:
8688: // Image name
8689: string imageName, imageVersion;
8690: p = output.find ("IMAGE_NAME:");
8691: if (p != string::npos)
8692: {
8693: p += 13;
8694: p2 = output.find ('\n', p);
8695: if (p2 != string::npos)
8696: imageName = output.substr (p, p2 - p);
8697: }
8698:
8699: // Stack trace
8700: p = output.find ("STACK_TEXT:");
8701: if (p == string::npos)
8702: {
8703: Error ("ERR_PARAMETER_INCORRECT");
8704: return;
8705: }
8706:
8707: p2 = output.find ("FOLLOWUP_IP:", p);
8708: if (p2 == string::npos)
8709: p2 = output.find ("STACK_COMMAND:", p);
8710: if (p2 == string::npos)
8711: p2 = output.size();
8712:
8713: output = output.substr (p, p2 - p);
8714:
8715: list <string> retAddrs;
8716: p = 0;
8717: while ((p = output.find ("+", p)) != string::npos)
8718: {
8719: size_t p1 = output.rfind (" ", p);
8720: if (p1 == string::npos)
1.1.1.23 root 8721: break;
1.1.1.25 root 8722:
8723: p = output.find ('\n', p);
8724: if (p == string::npos)
8725: p = output.size() - 1;
8726:
8727: string s = output.substr (p1 + 1, p - p1 - 1);
8728:
8729: if (s.find ('(') == 0)
8730: s = s.substr (1);
8731: if (s.rfind (')') == s.size() - 1)
8732: s = s.substr (0, s.size() - 1);
8733:
8734: retAddrs.push_back (s);
8735: }
8736:
8737: char url[MAX_URL_LENGTH];
8738: 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",
8739: GetWindowsEdition().c_str(),
8740: CurrentOSMajor,
8741: CurrentOSMinor,
8742: CurrentOSServicePack,
8743: Is64BitOs() ? "x64" : "x86",
8744: bugcheckCode,
8745: bugcheckArgs[0],
8746: bugcheckArgs[1],
8747: bugcheckArgs[2],
8748: bugcheckArgs[3],
8749: otherDriver ? "0" : "1",
8750: imageName.empty() ? "-" : imageName.c_str()
8751: );
8752:
8753: stringstream stackTraceArgs;
8754: int i = 0;
8755: foreach (const string &retAddr, retAddrs)
8756: {
8757: stackTraceArgs << "&st" << i++ << "=" << retAddr;
8758: }
8759:
8760: wstring msg;
8761:
1.1.1.26! root 8762: if (!imageName.empty() && StringToUpperCase (imageName) != StringToUpperCase (TC_APP_NAME) + ".SYS")
1.1.1.25 root 8763: {
1.1.1.26! root 8764: msg += wstring (GetString ("SYSTEM_CRASH_UPDATE_DRIVER")) + L"\n\n" + SingleStringToWide (imageName);
1.1.1.25 root 8765:
1.1.1.26! root 8766: string description, company, product;
! 8767: if (GetExecutableImageInformation (string (winDir) + "\\System32\\drivers\\" + imageName, imageVersion, description, company, product))
! 8768: {
! 8769: string s;
! 8770: if (!description.empty())
! 8771: s += description;
! 8772: if (!company.empty())
! 8773: s += "; " + company;
! 8774: if (!product.empty())
! 8775: s += "; " + product;
1.1.1.25 root 8776:
1.1.1.26! root 8777: if (s.find ("; ") == 0)
! 8778: s = s.substr (3);
1.1.1.25 root 8779:
1.1.1.26! root 8780: if (!s.empty())
! 8781: msg += SingleStringToWide (" (" + s + ")");
1.1.1.23 root 8782: }
1.1.1.25 root 8783:
1.1.1.26! root 8784: msg += L"\n\n";
! 8785: }
! 8786:
! 8787: if (otherDriver)
! 8788: {
1.1.1.25 root 8789: msg += GetString ("SYSTEM_CRASH_NO_TRUECRYPT");
8790: msg += L"\n\n";
1.1.1.23 root 8791: }
1.1.1.26! root 8792:
1.1.1.25 root 8793: string urlStr = string (url) + "&drvver=" + (imageVersion.empty() ? "-" : imageVersion) + stackTraceArgs.str();
1.1.1.23 root 8794:
1.1.1.25 root 8795: for (size_t i = 0; i < urlStr.size(); ++i)
8796: {
8797: if (urlStr[i] == '+')
8798: urlStr[i] = '.';
8799: }
8800:
8801: msg += GetString ("SYSTEM_CRASH_REPORT");
8802: msg += L"\n\n";
8803:
8804: msg += SingleStringToWide (urlStr);
8805:
8806: msg += L"\n\n";
8807: msg += GetString ("ASK_SEND_ERROR_REPORT");
8808:
8809: if (AskYesNoString (msg.c_str()) == IDYES)
8810: ShellExecute (NULL, "open", urlStr.c_str(), NULL, NULL, SW_SHOWNORMAL);
1.1.1.23 root 8811: }
8812:
8813:
1.1.1.25 root 8814: static BOOL HandleDriveListMouseWheelEvent (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bListMustBePointed)
1.1.1.19 root 8815: {
1.1.1.26! root 8816: static BOOL eventHandlerActive = FALSE;
! 8817: if (eventHandlerActive)
! 8818: return 0;
! 8819:
1.1.1.25 root 8820: RECT listRect;
8821: int mouseX = GET_X_LPARAM (lParam);
8822: int mouseY = GET_Y_LPARAM (lParam);
8823:
8824: GetWindowRect (GetDlgItem (MainDlg, IDC_DRIVELIST), &listRect);
8825:
8826: // Determine if the mouse pointer is within the main drive list
8827: bool bListPointed = (mouseX >= listRect.left && mouseX <= listRect.right
8828: && mouseY >= listRect.top && mouseY <= listRect.bottom);
8829:
8830: if (bListMustBePointed && bListPointed
8831: || !bListMustBePointed)
1.1.1.19 root 8832: {
1.1.1.26! root 8833: eventHandlerActive = TRUE;
! 8834:
1.1.1.25 root 8835: if (!bListMustBePointed && bListPointed)
8836: SetFocus (GetDlgItem (MainDlg, IDC_DRIVELIST));
8837:
8838: SendMessage (GetDlgItem (MainDlg, IDC_DRIVELIST), uMsg, wParam, lParam);
8839:
1.1.1.26! root 8840: eventHandlerActive = FALSE;
1.1.1.25 root 8841: 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 8842: }
8843:
1.1.1.25 root 8844: return 1;
8845: }
1.1.1.19 root 8846:
8847:
1.1.1.25 root 8848: static LRESULT CALLBACK MouseWheelProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
8849: {
8850: WNDPROC wp = (WNDPROC) GetWindowLongPtr (hwnd, GWLP_USERDATA);
8851:
8852: switch (message)
8853: {
8854: case WM_MOUSEWHEEL:
8855:
8856: if (HandleDriveListMouseWheelEvent (message, wParam, lParam, TRUE) == 0)
8857: 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 8858: }
1.1.1.25 root 8859:
8860: return CallWindowProc (wp, hwnd, message, wParam, lParam);
8861: }
8862:
8863:
8864: void HookMouseWheel (HWND hwndDlg, UINT ctrlId)
8865: {
8866: HWND hwndCtrl = GetDlgItem (hwndDlg, ctrlId);
8867:
8868: SetWindowLongPtr (hwndCtrl, GWLP_USERDATA, (LONG_PTR) GetWindowLongPtr (hwndCtrl, GWLP_WNDPROC));
8869: SetWindowLongPtr (hwndCtrl, GWLP_WNDPROC, (LONG_PTR) MouseWheelProc);
1.1.1.19 root 8870: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.