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