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