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