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