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