|
|
1.1.1.7 root 1: /* Legal Notice: The source code contained in this file has been derived from
2: the source code of Encryption for the Masses 2.02a, which is Copyright (c)
3: 1998-99 Paul Le Roux and which is covered by the 'License Agreement for
4: Encryption for the Masses'. Modifications and additions to that source code
1.1.1.9 root 5: contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and
1.1.1.10! root 6: Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.1
1.1.1.7 root 7: the full text of which is contained in the file License.txt included in
8: TrueCrypt binary and source code distribution archives. */
1.1 root 9:
1.1.1.7 root 10: #include "Tcdefs.h"
1.1.1.5 root 11: #include <time.h>
1.1.1.7 root 12: #include <math.h>
1.1.1.5 root 13: #include <dbt.h>
1.1.1.7 root 14: #include <windowsx.h>
15: #include "Apidrvr.h"
16: #include "Cmdline.h"
17: #include "Crypto.h"
18: #include "Dlgcode.h"
19: #include "Combo.h"
20: #include "Hotkeys.h"
21: #include "Keyfiles.h"
22: #include "Language.h"
1.1 root 23: #include "Mount.h"
1.1.1.7 root 24: #include "Pkcs5.h"
25: #include "Registry.h"
26: #include "Resource.h"
1.1 root 27: #include "Password.h"
1.1.1.7 root 28: #include "Xml.h"
29: #include "../Common/Dictionary.h"
30: #include "../Common/Common.h"
31: #include "../Common/Resource.h"
1.1 root 32:
33: BOOL bExplore = FALSE; /* Display explorer window after mount */
34: BOOL bBeep = FALSE; /* Donot beep after mount */
1.1.1.8 root 35: char szFileName[TC_MAX_PATH+1]; /* Volume to mount */
1.1 root 36: char szDriveLetter[3]; /* Drive Letter to mount */
1.1.1.5 root 37: char commandLineDrive = 0;
1.1 root 38: BOOL bCacheInDriver = FALSE; /* Cache any passwords we see */
39: BOOL bHistoryCmdLine = FALSE; /* History control is always disabled */
40: BOOL bCloseDismountedWindows=TRUE; /* Close all open explorer windows of dismounted volume */
41: BOOL bWipeCacheOnExit = FALSE; /* Wipe password from chace on exit */
1.1.1.7 root 42: BOOL bWipeCacheOnAutoDismount = TRUE;
43: BOOL bStartOnLogon = FALSE;
44: BOOL bMountDevicesOnLogon = FALSE;
45: BOOL bMountFavoritesOnLogon = FALSE;
46: BOOL bEnableBkgTask = FALSE;
47: BOOL bCloseBkgTaskWhenNoVolumes = FALSE;
48: BOOL bDismountOnLogOff = TRUE;
49: BOOL bDismountOnScreenSaver = TRUE;
50: BOOL bDismountOnPowerSaving = FALSE;
51: BOOL bForceAutoDismount = TRUE;
1.1.1.5 root 52: BOOL bForceMount = FALSE; /* Mount volume even if host file/device already in use */
53: BOOL bForceUnmount = FALSE; /* Unmount volume even if it cannot be locked */
1.1 root 54: BOOL bWipe = FALSE; /* Wipe driver passwords */
55: BOOL bAuto = FALSE; /* Do everything without user input */
1.1.1.6 root 56: BOOL bAutoMountDevices = FALSE; /* Auto-mount devices */
1.1.1.7 root 57: BOOL bAutoMountFavorites = FALSE;
58: BOOL bPlaySoundOnHotkeyMountDismount = TRUE;
59: BOOL bDisplayMsgBoxOnHotkeyDismount = FALSE;
1.1 root 60:
1.1.1.7 root 61: BOOL Quit = FALSE; /* Exit after processing command line */
62: BOOL UsePreferences = TRUE;
1.1 root 63:
1.1.1.7 root 64: int MaxVolumeIdleTime = -120;
1.1 root 65: int nCurrentShowType = 0; /* current display mode, mount, unmount etc */
1.1.1.5 root 66: int nSelectedDriveIndex = -1; /* Item number of selected drive */
1.1 root 67:
1.1.1.7 root 68: int cmdUnmountDrive = 0; /* Volume drive letter to unmount (-1 = all) */
69: Password VolumePassword; /* Password used for mounting volumes */
70: Password CmdVolumePassword; /* Password passed from command line */
71: BOOL CmdVolumePasswordValid;
1.1.1.6 root 72: MountOptions mountOptions;
73: MountOptions defaultMountOptions;
1.1.1.7 root 74: KeyFile *FirstCmdKeyFile;
75:
76: static KeyFilesDlgParam hidVolProtKeyFilesParam;
77:
78: static MOUNT_LIST_STRUCT LastKnownMountList;
79: static VOLUME_NOTIFICATIONS_LIST VolumeNotificationsList;
80: static DWORD LastKnownLogicalDrives;
81:
82: static HANDLE TaskBarIconMutex = NULL;
83: static BOOL MainWindowHidden = FALSE;
84: static int pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
1.1.1.8 root 85: static int NoCmdLineArgs;
86: static BOOL CmdLineVolumeSpecified;
1.1.1.6 root 87:
1.1 root 88: void
89: localcleanup (void)
90: {
1.1.1.9 root 91: // Wipe command line
92: char *c = GetCommandLineA ();
93: wchar_t *wc = GetCommandLineW ();
94: burn(c, strlen (c));
95: burn(wc, wcslen (wc) * sizeof (wchar_t));
96:
1.1 root 97: /* Cleanup common code resources */
98: cleanup ();
99: }
100:
101: void
102: RefreshMainDlg (HWND hwndDlg)
103: {
104: int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
105:
1.1.1.10! root 106: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1 root 107: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
108: EnableDisableButtons (hwndDlg);
109: }
110:
111: void
112: EndMainDlg (HWND hwndDlg)
113: {
1.1.1.10! root 114: MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME), bHistory);
1.1.1.7 root 115:
116: if (UsePreferences)
117: SaveSettings (hwndDlg);
1.1 root 118:
119: if (bWipeCacheOnExit)
120: {
121: DWORD dwResult;
122: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
123: }
124:
1.1.1.10! root 125: if (!bHistory)
! 126: {
! 127: SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), "");
! 128: ClearCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
! 129: }
! 130:
1.1.1.7 root 131: if (TaskBarIconMutex != NULL)
132: {
133: MainWindowHidden = TRUE;
134: ShowWindow (hwndDlg, SW_HIDE);
135: }
136: else
137: {
138: TaskBarIconRemove (hwndDlg);
139: EndDialog (hwndDlg, 0);
140: }
1.1 root 141: }
142:
1.1.1.7 root 143: static void InitMainDialog (HWND hwndDlg)
1.1 root 144: {
1.1.1.7 root 145: MENUITEMINFOW info;
146: char *popupTexts[] = {"MENU_FILE", "MENU_VOLUMES", "MENU_KEYFILES", "MENU_TOOLS", "MENU_SETTINGS", "MENU_HELP", "MENU_WEBSITE", 0};
147: wchar_t *str;
148: int i;
1.1 root 149:
1.1.1.7 root 150: /* Call the common dialog init code */
151: InitDialog (hwndDlg);
152: LocalizeDialog (hwndDlg, NULL);
153:
154: DragAcceptFiles (hwndDlg, TRUE);
1.1 root 155:
1.1.1.7 root 156: SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
157: SetWindowTextW (hwndDlg, lpszTitle);
158:
159: // Help file name
160: InitHelpFileName();
161:
162: // Localize menu strings
163: for (i = 40001; str = (wchar_t *)GetDictionaryValueByInt (i); i++)
1.1 root 164: {
1.1.1.7 root 165: info.cbSize = sizeof (info);
166: info.fMask = MIIM_TYPE;
167: info.fType = MFT_STRING;
168: info.dwTypeData = str;
169: info.cch = wcslen (str);
1.1 root 170:
1.1.1.7 root 171: SetMenuItemInfoW (GetMenu (hwndDlg), i, FALSE, &info);
1.1 root 172: }
1.1.1.7 root 173:
174: for (i = 0; popupTexts[i] != 0; i++)
175: {
176: str = GetString (popupTexts[i]);
177:
178: info.cbSize = sizeof (info);
179: info.fMask = MIIM_TYPE;
180:
181: if (memcmp (popupTexts[i], "MENU_WEBSITE", 6) == 0)
182: info.fType = MFT_STRING | MFT_RIGHTJUSTIFY;
183: else
184: info.fType = MFT_STRING;
185:
186: info.dwTypeData = str;
187: info.cch = wcslen (str);
188:
189: SetMenuItemInfoW (GetMenu (hwndDlg), i, TRUE, &info);
190: }
191:
192: BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
193:
194: if (*szDriveLetter != 0)
1.1 root 195: {
1.1.1.7 root 196: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
1.1 root 197:
1.1.1.7 root 198: if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2)
199: SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
1.1 root 200: }
201:
1.1.1.7 root 202: SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
203: EnableDisableButtons (hwndDlg);
204: }
205:
206: void
207: EnableDisableButtons (HWND hwndDlg)
208: {
209: HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
210: WORD x;
211:
212: x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
213:
214: EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME, MF_ENABLED);
215: EnableMenuItem (GetMenu (hwndDlg), IDM_MOUNT_VOLUME_OPTIONS, MF_ENABLED);
216: EnableMenuItem (GetMenu (hwndDlg), IDM_BACKUP_VOL_HEADER, MF_ENABLED);
217: EnableMenuItem (GetMenu (hwndDlg), IDM_RESTORE_VOL_HEADER, MF_ENABLED);
218: EnableMenuItem (GetMenu (hwndDlg), IDM_CHANGE_PASSWORD, MF_ENABLED);
219: EnableWindow (hOKButton, TRUE);
220:
1.1 root 221: if (x == VFREE)
222: {
1.1.1.7 root 223: SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1 root 224:
1.1.1.7 root 225: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_GRAYED);
1.1 root 226: }
227:
228: if (x == VMOUNTED)
229: {
1.1.1.7 root 230: SetWindowTextW (hOKButton, GetString ("UNMOUNT_BUTTON"));
1.1 root 231: EnableWindow (hOKButton, TRUE);
1.1.1.7 root 232: EnableMenuItem (GetMenu (hwndDlg), IDM_UNMOUNT_VOLUME, MF_ENABLED);
1.1 root 233:
234: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
1.1.1.7 root 235: EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_ENABLED);
1.1 root 236: }
237: else
238: {
1.1.1.7 root 239: SetWindowTextW (hOKButton, GetString ("MOUNT_BUTTON"));
1.1 root 240: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
1.1.1.7 root 241: EnableMenuItem (GetMenu (hwndDlg), IDM_VOLUME_PROPERTIES, MF_GRAYED);
1.1 root 242: }
243:
244: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
1.1.1.7 root 245: EnableMenuItem (GetMenu (hwndDlg), IDM_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
246: EnableMenuItem (GetMenu (hwndDlg), IDM_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
1.1 root 247: }
248:
1.1.1.7 root 249: BOOL VolumeSelected (HWND hwndDlg)
1.1 root 250: {
1.1.1.7 root 251: return (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0);
1.1 root 252: }
253:
254: void
255: LoadSettings (HWND hwndDlg)
256: {
257: // Options
1.1.1.7 root 258: bExplore = ConfigReadInt ("OpenExplorerWindowAfterMount", FALSE);
259: bCloseDismountedWindows = ConfigReadInt ("CloseExplorerWindowsOnDismount", TRUE);
260:
261: bHistory = ConfigReadInt ("SaveVolumeHistory", FALSE);
262:
263: bCacheInDriver = ConfigReadInt ("CachePasswords", FALSE);
264: bWipeCacheOnExit = ConfigReadInt ("WipePasswordCacheOnExit", FALSE);
265: bWipeCacheOnAutoDismount = ConfigReadInt ("WipeCacheOnAutoDismount", TRUE);
266:
267: bStartOnLogon = ConfigReadInt ("StartOnLogon", FALSE);
268: bMountDevicesOnLogon = ConfigReadInt ("MountDevicesOnLogon", FALSE);
269: bMountFavoritesOnLogon = ConfigReadInt ("MountFavoritesOnLogon", FALSE);
270:
271: bEnableBkgTask = ConfigReadInt ("EnableBackgroundTask", TRUE);
272: bCloseBkgTaskWhenNoVolumes = ConfigReadInt ("CloseBackgroundTaskOnNoVolumes", FALSE);
273:
274: bDismountOnLogOff = ConfigReadInt ("DismountOnLogOff", TRUE);
275: bDismountOnPowerSaving = ConfigReadInt ("DismountOnPowerSaving", FALSE);
276: bDismountOnScreenSaver = ConfigReadInt ("DismountOnScreenSaver", FALSE);
277: bForceAutoDismount = ConfigReadInt ("ForceAutoDismount", TRUE);
278: MaxVolumeIdleTime = ConfigReadInt ("MaxVolumeIdleTime", -120);
279:
280: defaultKeyFilesParam.EnableKeyFiles = ConfigReadInt ("UseKeyfiles", FALSE);
281:
282: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = ConfigReadInt ("PreserveTimestamps", TRUE);
283: defaultMountOptions.Removable = ConfigReadInt ("MountVolumesRemovable", FALSE);
284: defaultMountOptions.ReadOnly = ConfigReadInt ("MountVolumesReadOnly", FALSE);
285: defaultMountOptions.ProtectHiddenVolume = FALSE;
286:
1.1.1.6 root 287: mountOptions = defaultMountOptions;
1.1 root 288:
1.1.1.5 root 289: // Drive letter - command line arg overrides registry
290: if (szDriveLetter[0] == 0)
1.1.1.7 root 291: ConfigReadString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
292:
293: // Hotkeys
294: bPlaySoundOnHotkeyMountDismount = ConfigReadInt ("PlaySoundOnHotkeyMountDismount", TRUE);
295: bDisplayMsgBoxOnHotkeyDismount = ConfigReadInt ("DisplayMsgBoxOnHotkeyDismount", FALSE);
296: Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyModifiers = ConfigReadInt ("HotkeyModAutoMountDevices", 0);
297: Hotkeys [HK_AUTOMOUNT_DEVICES].vKeyCode = ConfigReadInt ("HotkeyCodeAutoMountDevices", 0);
298: Hotkeys [HK_DISMOUNT_ALL].vKeyModifiers = ConfigReadInt ("HotkeyModDismountAll", 0);
299: Hotkeys [HK_DISMOUNT_ALL].vKeyCode = ConfigReadInt ("HotkeyCodeDismountAll", 0);
300: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipe", 0);
301: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode = ConfigReadInt ("HotkeyCodeForceDismountAllWipe", 0);
302: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers = ConfigReadInt ("HotkeyModForceDismountAllWipeExit", 0);
303: Hotkeys [HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode = ConfigReadInt ("HotkeyCodeForceDismountAllWipeExit", 0);
304: Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers = ConfigReadInt ("HotkeyModMountFavoriteVolumes", 0);
305: Hotkeys [HK_MOUNT_FAVORITE_VOLUMES].vKeyCode = ConfigReadInt ("HotkeyCodeMountFavoriteVolumes", 0);
306: Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers = ConfigReadInt ("HotkeyModShowHideMainWindow", 0);
307: Hotkeys [HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode = ConfigReadInt ("HotkeyCodeShowHideMainWindow", 0);
308: RegisterAllHotkeys (hwndDlg, Hotkeys);
1.1 root 309:
310: // History
311: if (bHistoryCmdLine != TRUE)
1.1.1.10! root 312: {
1.1.1.7 root 313: LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10! root 314: if (CmdLineVolumeSpecified)
! 315: SetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
! 316: }
1.1 root 317: }
318:
319: void
320: SaveSettings (HWND hwndDlg)
321: {
322: char szTmp[32] = {0};
323: LPARAM lLetter;
324:
325: // Options
1.1.1.7 root 326: ConfigWriteBegin ();
327:
328: ConfigWriteInt ("OpenExplorerWindowAfterMount", bExplore);
329: ConfigWriteInt ("CloseExplorerWindowsOnDismount", bCloseDismountedWindows);
330: ConfigWriteInt ("SaveVolumeHistory", !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
331:
332: ConfigWriteInt ("CachePasswords", bCacheInDriver);
333: ConfigWriteInt ("WipePasswordCacheOnExit", bWipeCacheOnExit);
334: ConfigWriteInt ("WipeCacheOnAutoDismount", bWipeCacheOnAutoDismount);
335:
336: ConfigWriteInt ("StartOnLogon", bStartOnLogon);
337: ConfigWriteInt ("MountDevicesOnLogon", bMountDevicesOnLogon);
338: ConfigWriteInt ("MountFavoritesOnLogon", bMountFavoritesOnLogon);
339:
340: ConfigWriteInt ("MountVolumesReadOnly", defaultMountOptions.ReadOnly);
341: ConfigWriteInt ("MountVolumesRemovable", defaultMountOptions.Removable);
342: ConfigWriteInt ("PreserveTimestamps", defaultMountOptions.PreserveTimestamp);
343:
344: ConfigWriteInt ("EnableBackgroundTask", bEnableBkgTask);
345: ConfigWriteInt ("CloseBackgroundTaskOnNoVolumes", bCloseBkgTaskWhenNoVolumes);
346:
347: ConfigWriteInt ("DismountOnLogOff", bDismountOnLogOff);
348: ConfigWriteInt ("DismountOnPowerSaving", bDismountOnPowerSaving);
349: ConfigWriteInt ("DismountOnScreenSaver", bDismountOnScreenSaver);
350: ConfigWriteInt ("ForceAutoDismount", bForceAutoDismount);
351: ConfigWriteInt ("MaxVolumeIdleTime", MaxVolumeIdleTime);
352:
353: ConfigWriteInt ("UseKeyfiles", defaultKeyFilesParam.EnableKeyFiles);
1.1 root 354:
355: // Drive Letter
356: lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
357: if (LOWORD (lLetter) != 0xffff)
358: sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
1.1.1.7 root 359: ConfigWriteString ("LastSelectedDrive", szTmp);
360:
361: // Hotkeys
362: ConfigWriteInt ("HotkeyModAutoMountDevices", Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyModifiers);
363: ConfigWriteInt ("HotkeyCodeAutoMountDevices", Hotkeys[HK_AUTOMOUNT_DEVICES].vKeyCode);
364: ConfigWriteInt ("HotkeyModDismountAll", Hotkeys[HK_DISMOUNT_ALL].vKeyModifiers);
365: ConfigWriteInt ("HotkeyCodeDismountAll", Hotkeys[HK_DISMOUNT_ALL].vKeyCode);
366: ConfigWriteInt ("HotkeyModForceDismountAllWipe", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyModifiers);
367: ConfigWriteInt ("HotkeyCodeForceDismountAllWipe", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE].vKeyCode);
368: ConfigWriteInt ("HotkeyModForceDismountAllWipeExit", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyModifiers);
369: ConfigWriteInt ("HotkeyCodeForceDismountAllWipeExit", Hotkeys[HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT].vKeyCode);
370: ConfigWriteInt ("HotkeyModMountFavoriteVolumes", Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyModifiers);
371: ConfigWriteInt ("HotkeyCodeMountFavoriteVolumes", Hotkeys[HK_MOUNT_FAVORITE_VOLUMES].vKeyCode);
372: ConfigWriteInt ("HotkeyModShowHideMainWindow", Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyModifiers);
373: ConfigWriteInt ("HotkeyCodeShowHideMainWindow", Hotkeys[HK_SHOW_HIDE_MAIN_WINDOW].vKeyCode);
374: ConfigWriteInt ("PlaySoundOnHotkeyMountDismount", bPlaySoundOnHotkeyMountDismount);
375: ConfigWriteInt ("DisplayMsgBoxOnHotkeyDismount", bDisplayMsgBoxOnHotkeyDismount);
376:
377: // Language
378: if (GetPreferredLangId () != NULL)
379: ConfigWriteString ("Language", GetPreferredLangId ());
380:
381: ConfigWriteEnd ();
1.1 root 382:
383: // History
1.1.1.7 root 384: DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
1.1 root 385: }
386:
387: BOOL
388: SelectItem (HWND hTree, char nLetter)
389: {
390: int i;
391: LVITEM item;
392:
393: for (i = 0; i < ListView_GetItemCount(hTree); i++)
394: {
395: memset(&item, 0, sizeof(LVITEM));
396: item.mask = LVIF_PARAM;
397: item.iItem = i;
398:
399: if (ListView_GetItem (hTree, &item) == FALSE)
400: return FALSE;
401: else
402: {
403: if (HIWORD (item.lParam) == nLetter)
404: {
405: memset(&item, 0, sizeof(LVITEM));
406: item.state = LVIS_FOCUSED|LVIS_SELECTED;
407: item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
408: item.mask = LVIF_STATE;
409: item.iItem = i;
410: SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
411: return TRUE;
412: }
413: }
414:
415: }
416:
417: return TRUE;
418: }
419:
420:
421: // Fills drive list
422: // drive>0 = update only the corresponding drive subitems
423: void
424: LoadDriveLetters (HWND hTree, int drive)
425: {
426: char *szDriveLetters[]=
427: {"A:", "B:", "C:", "D:",
428: "E:", "F:", "G:", "H:", "I:", "J:", "K:",
429: "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
430: "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
431: "Z:"};
432:
433: DWORD dwResult;
434: BOOL bResult;
435: DWORD dwUsedDrives;
436: MOUNT_LIST_STRUCT driver;
437:
438: LVITEM listItem;
439: int item = 0;
440: char i;
441:
1.1.1.7 root 442: ZeroMemory (&driver, sizeof (driver));
1.1 root 443: bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver,
444: sizeof (driver), &driver, sizeof (driver), &dwResult,
445: NULL);
1.1.1.7 root 446: memcpy (&LastKnownMountList, &driver, sizeof (driver));
1.1 root 447:
448: if (bResult == FALSE)
449: {
450: handleWin32Error (hTree);
451: driver.ulMountedDrives = 0;
452: }
453:
1.1.1.7 root 454: LastKnownLogicalDrives = dwUsedDrives = GetLogicalDrives ();
455: if (dwUsedDrives == 0)
456: Warning ("DRIVELETTERS");
1.1 root 457:
458: if(drive == 0)
459: ListView_DeleteAllItems(hTree);
460:
461: for (i = 2; i < 26; i++)
462: {
463: int curDrive = 0;
464:
465: if(drive > 0)
466: {
467: LVITEM tmp;
468: memset(&tmp, 0, sizeof(LVITEM));
469: tmp.mask = LVIF_PARAM;
470: tmp.iItem = item;
1.1.1.7 root 471: if (ListView_GetItem (hTree, &tmp))
1.1 root 472: curDrive = HIWORD(tmp.lParam);
473: }
474:
475: if ( driver.ulMountedDrives & (1 << i) )
476: {
1.1.1.7 root 477: char szTmp[1024];
478: wchar_t szTmpW[1024];
479: wchar_t *ws;
1.1 root 480:
481: memset(&listItem, 0, sizeof(listItem));
482:
483: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
484: listItem.iImage = 1;
485: listItem.iItem = item++;
486:
487: if(drive > 0 && drive != curDrive)
488: continue;
489:
1.1.1.7 root 490: ToSBCS ((void *) driver.wszVolume[i]);
1.1 root 491:
492: if (memcmp (driver.wszVolume[i], "\\Device", 7) == 0)
493: sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]));
494: else
1.1.1.7 root 495: sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]) + 4);
1.1 root 496:
497: listItem.pszText = szDriveLetters[i];
498: listItem.lParam = MAKELONG (VMOUNTED, i + 'A');
499:
500: if(drive == 0)
501: ListView_InsertItem (hTree, &listItem);
502: else
503: ListView_SetItem (hTree, &listItem);
504:
505: listItem.mask=LVIF_TEXT;
506: listItem.pszText = szTmp;
507:
508: listItem.iSubItem = 1;
1.1.1.5 root 509: ListView_SetItem (hTree, &listItem);
1.1 root 510:
1.1.1.7 root 511: GetSizeString (driver.diskLength[i], szTmpW);
512: ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1.1 root 513:
1.1.1.5 root 514: EAGetName (szTmp, driver.ea[i]);
1.1 root 515: listItem.iSubItem = 3;
1.1.1.5 root 516: ListView_SetItem (hTree, &listItem);
1.1 root 517:
1.1.1.7 root 518: switch (driver.volumeType[i])
519: {
520: case PROP_VOL_TYPE_NORMAL:
521: ws = GetString ("NORMAL");
522: break;
523: case PROP_VOL_TYPE_HIDDEN:
524: ws = GetString ("HIDDEN");
525: break;
526: case PROP_VOL_TYPE_OUTER:
527: ws = GetString ("OUTER"); // Normal/outer volume (hidden volume protected)
528: break;
529: case PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED:
530: ws = GetString ("OUTER_VOL_WRITE_PREVENTED"); // Normal/outer volume (hidden volume protected AND write denied)
531: break;
532: default:
533: ws = L"?";
534: }
535: ListSubItemSetW (hTree, listItem.iItem, 4, ws);
536:
537: if (driver.volumeType[i] == PROP_VOL_TYPE_OUTER_VOL_WRITE_PREVENTED) // Normal/outer volume (hidden volume protected AND write denied)
538: {
539: if (!VolumeNotificationsList.bHidVolDamagePrevReported[i])
540: {
541: wchar_t szTmp[1024];
542:
543: VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
544: wsprintfW (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
545: SetForegroundWindow (GetParent(hTree));
546: MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING);
547: }
548: }
1.1.1.5 root 549: else
1.1.1.7 root 550: {
551: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
552: }
1.1 root 553: }
554: else
555: {
1.1.1.7 root 556: VolumeNotificationsList.bHidVolDamagePrevReported[i] = FALSE;
557:
1.1 root 558: if (!(dwUsedDrives & 1 << i))
559: {
560: if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
561: {
562: item++;
563: continue;
564: }
565:
566: memset(&listItem,0,sizeof(listItem));
567:
568: listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
569: listItem.iImage = 0;
570: listItem.iItem = item++;
571: listItem.pszText = szDriveLetters[i];
572: listItem.lParam = MAKELONG (VFREE, i + 'A');
573:
574: if(drive == 0)
575: ListView_InsertItem (hTree, &listItem);
576: else
577: ListView_SetItem (hTree, &listItem);
578:
579: listItem.mask=LVIF_TEXT;
580: listItem.pszText = "";
581: listItem.iSubItem = 1;
1.1.1.5 root 582: ListView_SetItem (hTree, &listItem);
1.1 root 583: listItem.iSubItem = 2;
1.1.1.5 root 584: ListView_SetItem (hTree, &listItem);
1.1 root 585: listItem.iSubItem = 3;
1.1.1.5 root 586: ListView_SetItem (hTree, &listItem);
587: listItem.iSubItem = 4;
588: ListView_SetItem (hTree, &listItem);
1.1 root 589:
590: }
591: }
592: }
593: }
594:
595:
1.1.1.7 root 596: static void PasswordChangeEnable (HWND hwndDlg, int button, int passwordId, BOOL keyFilesEnabled,
597: int newPasswordId, int newVerifyId, BOOL newKeyFilesEnabled)
598: {
599: char password[MAX_PASSWORD + 1];
600: char newPassword[MAX_PASSWORD + 1];
601: char newVerify[MAX_PASSWORD + 1];
602: BOOL bEnable = TRUE;
603:
604: GetWindowText (GetDlgItem (hwndDlg, passwordId), password, sizeof (password));
605:
606: if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
607: newKeyFilesEnabled = keyFilesEnabled;
608:
609: switch (pwdChangeDlgMode)
610: {
611: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
612: case PCDM_ADD_REMOVE_VOL_KEYFILES:
613: case PCDM_CHANGE_PKCS5_PRF:
614: memcpy (newPassword, password, sizeof (newPassword));
615: memcpy (newVerify, password, sizeof (newVerify));
616: break;
617:
618: default:
619: GetWindowText (GetDlgItem (hwndDlg, newPasswordId), newPassword, sizeof (newPassword));
620: GetWindowText (GetDlgItem (hwndDlg, newVerifyId), newVerify, sizeof (newVerify));
621: }
622:
623: if (!keyFilesEnabled && strlen (password) < MIN_PASSWORD)
624: bEnable = FALSE;
625: else if (strcmp (newPassword, newVerify) != 0)
626: bEnable = FALSE;
627: else if (!newKeyFilesEnabled && strlen (newPassword) < MIN_PASSWORD)
628: bEnable = FALSE;
629:
630: burn (password, sizeof (password));
631: burn (newPassword, sizeof (newPassword));
632: burn (newVerify, sizeof (newVerify));
633:
634: EnableWindow (GetDlgItem (hwndDlg, button), bEnable);
635: }
636:
637:
1.1 root 638: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
639: should return nonzero if it processes the message, and zero if it does
640: not. - see DialogProc */
641: BOOL WINAPI
642: PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
643: {
1.1.1.7 root 644: static KeyFilesDlgParam newKeyFilesParam;
1.1 root 645:
646: WORD lw = LOWORD (wParam);
647: WORD hw = HIWORD (wParam);
648:
649: if (lParam); /* remove warning */
650: if (hw); /* remove warning */
651:
652: switch (msg)
653: {
654: case WM_INITDIALOG:
655: {
1.1.1.3 root 656: LPARAM nIndex;
1.1.1.7 root 657: HWND hComboBox = GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID);
1.1.1.3 root 658: int i;
1.1 root 659:
1.1.1.7 root 660: ZeroMemory (&newKeyFilesParam, sizeof (newKeyFilesParam));
1.1 root 661:
1.1.1.7 root 662: SetWindowTextW (hwndDlg, GetString ("IDD_PASSWORDCHANGE_DLG"));
663: LocalizeDialog (hwndDlg, "IDD_PASSWORDCHANGE_DLG");
1.1 root 664:
665: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
666: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
667: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
668: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
669:
1.1.1.7 root 670: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
671: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
672: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
673:
1.1.1.3 root 674: SendMessage (hComboBox, CB_RESETCONTENT, 0, 0);
675:
1.1.1.7 root 676: nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) GetString ("UNCHANGED"));
1.1.1.3 root 677: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) 0);
678:
679: for (i = 1; i <= LAST_PRF_ID; i++)
680: {
1.1.1.7 root 681: nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) get_pkcs5_prf_name(i));
1.1.1.3 root 682: SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) i);
683: }
684:
685: SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
686:
1.1.1.7 root 687: switch (pwdChangeDlgMode)
688: {
689: case PCDM_CHANGE_PKCS5_PRF:
690: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_CHANGE_PKCS5_PRF"));
691: LocalizeDialog (hwndDlg, "IDD_PCDM_CHANGE_PKCS5_PRF");
692: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
693: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
694: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
695: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
696: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
697: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
698: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
699: break;
700:
701: case PCDM_ADD_REMOVE_VOL_KEYFILES:
702: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_ADD_REMOVE_VOL_KEYFILES"));
703: LocalizeDialog (hwndDlg, "IDD_PCDM_ADD_REMOVE_VOL_KEYFILES");
704: newKeyFilesParam.EnableKeyFiles = TRUE;
705: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
706: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
707: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
708: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
709: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
710: break;
711:
712: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
713: newKeyFilesParam.EnableKeyFiles = FALSE;
714: SetWindowTextW (hwndDlg, GetString ("IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
715: LocalizeDialog (hwndDlg, "IDD_PCDM_REMOVE_ALL_KEYFILES_FROM_VOL");
716: KeyFilesEnable = TRUE;
717: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, TRUE);
718: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), TRUE);
719: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_KEYFILES), TRUE);
720: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD), FALSE);
721: EnableWindow (GetDlgItem (hwndDlg, IDC_VERIFY), FALSE);
722: EnableWindow (GetDlgItem (hwndDlg, IDC_ENABLE_NEW_KEYFILES), FALSE);
723: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW), FALSE);
724: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), FALSE);
725: EnableWindow (GetDlgItem (hwndDlg, IDT_NEW_PASSWORD), FALSE);
726: EnableWindow (GetDlgItem (hwndDlg, IDT_CONFIRM_PASSWORD), FALSE);
727: EnableWindow (GetDlgItem (hwndDlg, IDT_PKCS5_PRF), FALSE);
728: EnableWindow (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), FALSE);
729: break;
730:
731: case PCDM_CHANGE_PASSWORD:
732: default:
733: // NOP
734: break;
735: };
736:
1.1.1.5 root 737: CheckCapsLock (hwndDlg, FALSE);
738:
1.1 root 739: return 1;
740: }
741:
742: case WM_COMMAND:
743: if (lw == IDCANCEL)
744: {
745: // Attempt to wipe passwords stored in the input field buffers
746: char tmp[MAX_PASSWORD+1];
747: memset (tmp, 'X', MAX_PASSWORD);
748: tmp[MAX_PASSWORD] = 0;
749: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
750: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
751: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
1.1.1.7 root 752: RestoreDefaultKeyFilesParam ();
1.1 root 753:
754: EndDialog (hwndDlg, IDCANCEL);
755: return 1;
756: }
1.1.1.7 root 757:
1.1 root 758: if (hw == EN_CHANGE)
759: {
1.1.1.7 root 760: PasswordChangeEnable (hwndDlg, IDOK,
761: IDC_OLD_PASSWORD,
762: KeyFilesEnable && FirstKeyFile != NULL,
763: IDC_PASSWORD, IDC_VERIFY,
764: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
765:
766: return 1;
767: }
768:
769: if (lw == IDC_KEYFILES)
770: {
771: KeyFilesDlgParam param;
772: param.EnableKeyFiles = KeyFilesEnable;
773: param.FirstKeyFile = FirstKeyFile;
774:
775: if (IDOK == DialogBoxParamW (hInst,
776: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
777: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
778: {
779: KeyFilesEnable = param.EnableKeyFiles;
780: FirstKeyFile = param.FirstKeyFile;
781:
782: SetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES, KeyFilesEnable);
783: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
784: }
785:
786: PasswordChangeEnable (hwndDlg, IDOK,
787: IDC_OLD_PASSWORD,
788: KeyFilesEnable && FirstKeyFile != NULL,
789: IDC_PASSWORD, IDC_VERIFY,
790: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
791:
792: return 1;
793: }
794:
795:
796: if (lw == IDC_NEW_KEYFILES)
797: {
798: if (IDOK == DialogBoxParamW (hInst,
799: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
800: (DLGPROC) KeyFilesDlgProc, (LPARAM) &newKeyFilesParam))
801: {
802: SetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES, newKeyFilesParam.EnableKeyFiles);
803: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), newKeyFilesParam.EnableKeyFiles);
804:
805: VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
806: GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL,
807: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
808: }
809:
810: PasswordChangeEnable (hwndDlg, IDOK,
811: IDC_OLD_PASSWORD,
812: KeyFilesEnable && FirstKeyFile != NULL,
813: IDC_PASSWORD, IDC_VERIFY,
814: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
815:
816: return 1;
817: }
818:
819: if (lw == IDC_ENABLE_KEYFILES)
820: {
821: KeyFilesEnable = GetCheckBox (hwndDlg, IDC_ENABLE_KEYFILES);
822: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES), KeyFilesEnable);
823:
824: PasswordChangeEnable (hwndDlg, IDOK,
825: IDC_OLD_PASSWORD,
826: KeyFilesEnable && FirstKeyFile != NULL,
827: IDC_PASSWORD, IDC_VERIFY,
828: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
829:
830: return 1;
831: }
832:
833: if (lw == IDC_ENABLE_NEW_KEYFILES)
834: {
835: newKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_ENABLE_NEW_KEYFILES);
836: EnableWindow (GetDlgItem (hwndDlg, IDC_NEW_KEYFILES), newKeyFilesParam.EnableKeyFiles);
837:
838: PasswordChangeEnable (hwndDlg, IDOK,
839: IDC_OLD_PASSWORD,
840: KeyFilesEnable && FirstKeyFile != NULL,
841: IDC_PASSWORD, IDC_VERIFY,
842: newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL);
843:
844: return 1;
845: }
846:
847: if (lw == IDC_SHOW_PASSWORD_CHPWD_ORI)
848: {
849: SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD),
850: EM_SETPASSWORDCHAR,
851: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_ORI) ? 0 : '*',
852: 0);
853: InvalidateRect (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), NULL, TRUE);
854: return 1;
855: }
856:
857: if (lw == IDC_SHOW_PASSWORD_CHPWD_NEW)
858: {
859: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
860: EM_SETPASSWORDCHAR,
861: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
862: 0);
863: SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY),
864: EM_SETPASSWORDCHAR,
865: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_CHPWD_NEW) ? 0 : '*',
866: 0);
867: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
868: InvalidateRect (GetDlgItem (hwndDlg, IDC_VERIFY), NULL, TRUE);
1.1 root 869: return 1;
870: }
1.1.1.7 root 871:
1.1 root 872: if (lw == IDOK)
873: {
874: HWND hParent = GetParent (hwndDlg);
1.1.1.7 root 875: Password oldPassword;
876: Password newPassword;
1.1 root 877: int nStatus;
1.1.1.7 root 878: int pkcs5 = SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETITEMDATA,
879: SendMessage (GetDlgItem (hwndDlg, IDC_PKCS5_PRF_ID), CB_GETCURSEL, 0, 0), 0);
880:
881: if (!CheckPasswordCharEncoding (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL))
882: {
883: Error ("UNSUPPORTED_CHARS_IN_PWD");
884: return 1;
885: }
1.1 root 886:
1.1.1.7 root 887: if (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF)
888: {
889: newKeyFilesParam.EnableKeyFiles = KeyFilesEnable;
890: }
1.1.1.8 root 891: else if (!(newKeyFilesParam.EnableKeyFiles && newKeyFilesParam.FirstKeyFile != NULL)
892: && pwdChangeDlgMode == PCDM_CHANGE_PASSWORD)
1.1.1.7 root 893: {
894: if (!CheckPasswordLength (hwndDlg, GetDlgItem (hwndDlg, IDC_PASSWORD)))
895: return 1;
896: }
1.1.1.5 root 897:
1.1 root 898: GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
899:
1.1.1.7 root 900: GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), oldPassword.Text, sizeof (oldPassword.Text));
901: oldPassword.Length = strlen (oldPassword.Text);
902:
903: switch (pwdChangeDlgMode)
904: {
905: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
906: case PCDM_ADD_REMOVE_VOL_KEYFILES:
907: case PCDM_CHANGE_PKCS5_PRF:
908: memcpy (newPassword.Text, oldPassword.Text, sizeof (newPassword.Text));
909: newPassword.Length = strlen (oldPassword.Text);
910: break;
911:
912: default:
913: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), newPassword.Text, sizeof (newPassword.Text));
914: newPassword.Length = strlen (newPassword.Text);
915: }
916:
917: if (KeyFilesEnable)
918: KeyFilesApply (&oldPassword, FirstKeyFile, bPreserveTimestamp);
1.1 root 919:
1.1.1.7 root 920: if (newKeyFilesParam.EnableKeyFiles)
921: KeyFilesApply (&newPassword,
922: pwdChangeDlgMode==PCDM_CHANGE_PKCS5_PRF ? FirstKeyFile : newKeyFilesParam.FirstKeyFile,
923: bPreserveTimestamp);
1.1 root 924:
1.1.1.7 root 925: nStatus = ChangePwd (szFileName, &oldPassword, &newPassword, pkcs5, hwndDlg);
1.1 root 926:
1.1.1.7 root 927: burn (&oldPassword, sizeof (oldPassword));
928: burn (&newPassword, sizeof (newPassword));
1.1 root 929:
930: if (nStatus != 0)
1.1.1.7 root 931: {
932: if (nStatus != -1)
933: handleError (hwndDlg, nStatus);
934: }
1.1 root 935: else
936: {
937: // Attempt to wipe passwords stored in the input field buffers
938: char tmp[MAX_PASSWORD+1];
939: memset (tmp, 'X', MAX_PASSWORD);
940: tmp[MAX_PASSWORD] = 0;
941: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
942: SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);
943: SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);
944:
1.1.1.7 root 945: KeyFileRemoveAll (&newKeyFilesParam.FirstKeyFile);
946: RestoreDefaultKeyFilesParam ();
947:
1.1 root 948: EndDialog (hwndDlg, IDOK);
949: }
950: return 1;
951: }
952: return 0;
953: }
954:
955: return 0;
956: }
957:
1.1.1.7 root 958: static char PasswordDlgVolume[MAX_PATH];
959:
1.1 root 960: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
961: should return nonzero if it processes the message, and zero if it does
962: not. - see DialogProc */
963: BOOL WINAPI
964: PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
965: {
966: WORD lw = LOWORD (wParam);
1.1.1.7 root 967: static Password *szXPwd;
1.1 root 968:
969: switch (msg)
970: {
971: case WM_INITDIALOG:
972: {
1.1.1.7 root 973: szXPwd = (Password *) lParam;
974: LocalizeDialog (hwndDlg, "IDD_PASSWORD_DLG");
1.1.1.9 root 975: DragAcceptFiles (hwndDlg, TRUE);
1.1.1.7 root 976:
977: if (strlen (PasswordDlgVolume) > 0)
978: {
979: wchar_t s[1024];
980: wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), PasswordDlgVolume);
981: SetWindowTextW (hwndDlg, s);
982: }
983:
1.1 root 984: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
985: SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7 root 986:
987: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
988: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1.1.1.8 root 989:
990: SetForegroundWindow (hwndDlg);
1.1 root 991: return 1;
992: }
993:
994: case WM_COMMAND:
995:
1.1.1.6 root 996: if (lw == IDC_MOUNT_OPTIONS)
997: {
1.1.1.7 root 998: DialogBoxParamW (hInst,
999: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
1.1.1.6 root 1000: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions);
1001: return 1;
1002: }
1003:
1.1.1.7 root 1004: if (lw == IDC_SHOW_PASSWORD)
1005: {
1006: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD),
1007: EM_SETPASSWORDCHAR,
1008: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD) ? 0 : '*',
1009: 0);
1010: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD), NULL, TRUE);
1011: return 1;
1012: }
1013:
1014: if (lw == IDC_KEY_FILES)
1015: {
1016: KeyFilesDlgParam param;
1017: param.EnableKeyFiles = KeyFilesEnable;
1018: param.FirstKeyFile = FirstKeyFile;
1019:
1020: if (IDOK == DialogBoxParamW (hInst,
1021: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
1022: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m))
1023: {
1024: KeyFilesEnable = param.EnableKeyFiles;
1025: FirstKeyFile = param.FirstKeyFile;
1026:
1027: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
1028: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1029: }
1030:
1031: return 1;
1032: }
1033:
1034: if (lw == IDC_KEYFILES_ENABLE)
1035: {
1036: KeyFilesEnable = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE);
1037: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1038:
1039: return 1;
1040: }
1041:
1.1 root 1042: if (lw == IDCANCEL || lw == IDOK)
1043: {
1044: char tmp[MAX_PASSWORD+1];
1045:
1046: if (lw == IDOK)
1047: {
1.1.1.7 root 1048: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
1049: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile,
1050: bPreserveTimestamp);
1051:
1052: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szXPwd->Text, MAX_PASSWORD + 1);
1053: szXPwd->Length = strlen (szXPwd->Text);
1054:
1.1 root 1055: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));
1056: }
1057:
1058: // Attempt to wipe password stored in the input field buffer
1059: memset (tmp, 'X', MAX_PASSWORD);
1060: tmp[MAX_PASSWORD] = 0;
1061: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1.1.1.7 root 1062: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
1063:
1064: if (hidVolProtKeyFilesParam.FirstKeyFile != NULL)
1065: {
1066: KeyFileRemoveAll (&hidVolProtKeyFilesParam.FirstKeyFile);
1067: hidVolProtKeyFilesParam.EnableKeyFiles = FALSE;
1068: }
1.1 root 1069:
1070: EndDialog (hwndDlg, lw);
1071: return 1;
1072: }
1073: return 0;
1.1.1.9 root 1074:
1075: case WM_DROPFILES:
1076: {
1077: HDROP hdrop = (HDROP) wParam;
1078: int i = 0, count = DragQueryFile (hdrop, -1, NULL, 0);
1079:
1080: while (count-- > 0)
1081: {
1082: KeyFile *kf = malloc (sizeof (KeyFile));
1083: DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
1084: FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
1085: KeyFilesEnable = TRUE;
1086: }
1087:
1088: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
1089: EnableWindow (GetDlgItem (hwndDlg, IDC_KEY_FILES), KeyFilesEnable);
1090:
1091: DragFinish (hdrop);
1092: }
1093: return 1;
1.1 root 1094: }
1095:
1096: return 0;
1097: }
1098:
1.1.1.7 root 1099: static void PreferencesDlgEnableButtons (HWND hwndDlg)
1100: {
1101: BOOL icon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
1102: BOOL idle = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
1103: BOOL logon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));
1104: BOOL installed = !IsNonInstallMode();
1105:
1106: EnableWindow (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), icon && installed);
1107: EnableWindow (GetDlgItem (hwndDlg, IDT_LOGON), installed);
1108: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), installed);
1109: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), installed && logon);
1110: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES), installed && logon);
1111: EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT), icon);
1112: EnableWindow (GetDlgItem (hwndDlg, IDT_AUTO_DISMOUNT_ON), icon);
1113: EnableWindow (GetDlgItem (hwndDlg, IDT_MINUTES), icon);
1114: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), icon);
1115: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), icon);
1116: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), icon);
1117: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), icon);
1118: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME), icon && idle);
1119: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), icon);
1120: EnableWindow (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT), icon);
1121: }
1122:
1.1 root 1123: BOOL WINAPI
1124: PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1125: {
1126: WORD lw = LOWORD (wParam);
1127:
1128: switch (msg)
1129: {
1130: case WM_INITDIALOG:
1131: {
1.1.1.7 root 1132: LocalizeDialog (hwndDlg, "IDD_PREFERENCES_DLG");
1.1 root 1133:
1134: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK,
1135: bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
1136:
1137: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK,
1138: bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
1139:
1.1.1.7 root 1140: SendMessage (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS), BM_SETCHECK,
1141: defaultMountOptions.PreserveTimestamp ? BST_CHECKED:BST_UNCHECKED, 0);
1142:
1.1 root 1143: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK,
1144: bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
1145:
1.1.1.7 root 1146: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT), BM_SETCHECK,
1147: bWipeCacheOnAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
1148:
1.1 root 1149: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK,
1150: bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
1151:
1.1.1.6 root 1152: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY), BM_SETCHECK,
1153: defaultMountOptions.ReadOnly ? BST_CHECKED:BST_UNCHECKED, 0);
1154:
1155: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE), BM_SETCHECK,
1156: defaultMountOptions.Removable ? BST_CHECKED:BST_UNCHECKED, 0);
1.1.1.7 root 1157:
1158: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START), BM_SETCHECK,
1159: bStartOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
1160:
1161: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES), BM_SETCHECK,
1162: bMountDevicesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
1163:
1164: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES), BM_SETCHECK,
1165: bMountFavoritesOnLogon ? BST_CHECKED:BST_UNCHECKED, 0);
1166:
1167: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE), BM_SETCHECK,
1168: bEnableBkgTask ? BST_CHECKED:BST_UNCHECKED, 0);
1169:
1170: SendMessage (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL), BM_SETCHECK,
1171: bCloseBkgTaskWhenNoVolumes || IsNonInstallMode() ? BST_CHECKED:BST_UNCHECKED, 0);
1172:
1173: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF), BM_SETCHECK,
1174: bDismountOnLogOff ? BST_CHECKED:BST_UNCHECKED, 0);
1175:
1176: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING), BM_SETCHECK,
1177: bDismountOnPowerSaving ? BST_CHECKED:BST_UNCHECKED, 0);
1178:
1179: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER), BM_SETCHECK,
1180: bDismountOnScreenSaver ? BST_CHECKED:BST_UNCHECKED, 0);
1.1 root 1181:
1.1.1.7 root 1182: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT), BM_SETCHECK,
1183: bForceAutoDismount ? BST_CHECKED:BST_UNCHECKED, 0);
1184:
1185: SendMessage (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE), BM_SETCHECK,
1186: MaxVolumeIdleTime > 0 ? BST_CHECKED:BST_UNCHECKED, 0);
1187:
1188: SetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, abs (MaxVolumeIdleTime), FALSE);
1189:
1190: PreferencesDlgEnableButtons (hwndDlg);
1.1 root 1191: return 1;
1192: }
1193:
1194: case WM_COMMAND:
1195:
1.1.1.7 root 1196: if (lw == IDC_PRESERVE_TIMESTAMPS && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS)))
1197: {
1198: if (AskWarnNoYes ("CONFIRM_TIMESTAMP_UPDATING") == IDNO)
1199: SetCheckBox (hwndDlg, IDC_PRESERVE_TIMESTAMPS, TRUE);
1200: }
1201:
1202: if (lw == IDC_PREF_BKG_TASK_ENABLE && !IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE)))
1203: {
1204: if (AskWarnNoYes ("CONFIRM_BACKGROUND_TASK_DISABLED") == IDNO)
1205: SetCheckBox (hwndDlg, IDC_PREF_BKG_TASK_ENABLE, TRUE);
1206: }
1207:
1208: // Forced dismount disabled warning
1209: if (lw == IDC_PREF_DISMOUNT_INACTIVE
1210: || lw == IDC_PREF_DISMOUNT_POWERSAVING
1211: || lw == IDC_PREF_DISMOUNT_SCREENSAVER
1212: || lw == IDC_PREF_FORCE_AUTO_DISMOUNT)
1213: {
1214: BOOL i = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE));
1215: BOOL p = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
1216: BOOL s = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
1217: BOOL q = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
1218:
1219: if (!q)
1220: {
1221: if (lw == IDC_PREF_FORCE_AUTO_DISMOUNT && (i || p || s))
1222: {
1223: if (AskWarnNoYes ("CONFIRM_NO_FORCED_AUTODISMOUNT") == IDNO)
1224: SetCheckBox (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT, TRUE);
1225: }
1226: else if ((lw == IDC_PREF_DISMOUNT_INACTIVE && i
1227: || lw == IDC_PREF_DISMOUNT_POWERSAVING && p
1228: || lw == IDC_PREF_DISMOUNT_SCREENSAVER && s))
1229: Warning ("WARN_PREF_AUTO_DISMOUNT");
1230: }
1231:
1232: }
1233:
1.1 root 1234: if (lw == IDCANCEL)
1235: {
1236: EndDialog (hwndDlg, lw);
1237: return 1;
1238: }
1239:
1240: if (lw == IDOK)
1241: {
1.1.1.7 root 1242: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));
1243: bCloseDismountedWindows = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));
1244: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PRESERVE_TIMESTAMPS));
1245: bWipeCacheOnExit = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));
1246: bWipeCacheOnAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_AUTODISMOUNT));
1247: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));
1248: defaultMountOptions.ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_READONLY));
1249: defaultMountOptions.Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_MOUNT_REMOVABLE));
1250: bEnableBkgTask = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_BKG_TASK_ENABLE));
1251: bCloseBkgTaskWhenNoVolumes = IsNonInstallMode() ? bCloseBkgTaskWhenNoVolumes : IsButtonChecked (GetDlgItem (hwndDlg, IDC_CLOSE_BKG_TASK_WHEN_NOVOL));
1252: bDismountOnLogOff = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_LOGOFF));
1253: bDismountOnPowerSaving = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_POWERSAVING));
1254: bDismountOnScreenSaver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_SCREENSAVER));
1255: bForceAutoDismount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_FORCE_AUTO_DISMOUNT));
1256: MaxVolumeIdleTime = GetDlgItemInt (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE_TIME, NULL, FALSE)
1257: * (IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_DISMOUNT_INACTIVE)) ? 1 : -1);
1258: bStartOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_START));
1259: bMountDevicesOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_DEVICES));
1260: bMountFavoritesOnLogon = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_LOGON_MOUNT_FAVORITES));
1261:
1262: if (!IsNonInstallMode ())
1263: {
1264: char regk [64];
1265:
1266: // Split the string in order to prevent some antivirus packages from falsely reporting
1267: // TrueCrypt.exe to contain a possible Trojan horse because of this string (heuristic scan).
1268: sprintf (regk, "%s%s", "Software\\Microsoft\\Windows\\Curren", "tVersion\\Run");
1269:
1270: if (bStartOnLogon)
1271: {
1272: char exe[MAX_PATH * 2] = { '"' };
1273: GetModuleFileName (NULL, exe + 1, sizeof (exe));
1274: strcat (exe, "\" /q preferences");
1275:
1276: if (bMountDevicesOnLogon) strcat (exe, " /a devices");
1277: if (bMountFavoritesOnLogon) strcat (exe, " /a favorites");
1278:
1279: WriteRegistryString (regk, "TrueCrypt", exe);
1280: }
1281: else
1282: DeleteRegistryValue (regk, "TrueCrypt");
1283: }
1284:
1285: SaveSettings (hwndDlg);
1.1 root 1286:
1287: EndDialog (hwndDlg, lw);
1288: return 1;
1289: }
1290:
1.1.1.7 root 1291: if (lw == IDC_PREFS_HOTKEY_SETTINGS)
1292: {
1293: DialogBoxParam (hInst,
1294: MAKEINTRESOURCE (IDD_HOTKEYS_DLG), hwndDlg,
1295: (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
1296: return 1;
1.1 root 1297:
1.1.1.7 root 1298: }
1.1.1.6 root 1299:
1.1.1.7 root 1300: if (lw == IDC_PREFS_KEYFILE_SETTINGS)
1301: {
1302: KeyfileDefaultsDlg (hwndDlg);
1303: return 1;
1304: }
1305:
1306: if (HIWORD (wParam) == BN_CLICKED)
1307: {
1308: PreferencesDlgEnableButtons (hwndDlg);
1309: return 1;
1310: }
1311:
1312: return 0;
1313: }
1314:
1315: return 0;
1316: }
1317:
1318:
1319: BOOL WINAPI
1320: MountOptionsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1321: {
1322: static MountOptions *mountOptions;
1323:
1324: WORD lw = LOWORD (wParam);
1325:
1326: switch (msg)
1327: {
1328: case WM_INITDIALOG:
1329: {
1330: BOOL protect;
1331:
1332: mountOptions = (MountOptions *) lParam;
1333:
1334: LocalizeDialog (hwndDlg, "IDD_MOUNT_OPTIONS");
1335:
1336: SendDlgItemMessage (hwndDlg, IDC_MOUNT_READONLY, BM_SETCHECK,
1337: mountOptions->ReadOnly ? BST_CHECKED : BST_UNCHECKED, 0);
1338: SendDlgItemMessage (hwndDlg, IDC_MOUNT_REMOVABLE, BM_SETCHECK,
1339: mountOptions->Removable ? BST_CHECKED : BST_UNCHECKED, 0);
1340: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK,
1341: mountOptions->ProtectHiddenVolume ? BST_CHECKED : BST_UNCHECKED, 0);
1342:
1343: protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1344:
1345: EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1346: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1347: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
1348: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
1349: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
1350: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect && hidVolProtKeyFilesParam.EnableKeyFiles);
1351: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
1352:
1353: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
1354:
1.1.1.8 root 1355: SendDlgItemMessage (hwndDlg, IDC_PASSWORD_PROT_HIDVOL, EM_LIMITTEXT, MAX_PASSWORD, 0);
1356:
1.1.1.7 root 1357: if (mountOptions->ProtectedHidVolPassword.Length > 0)
1358: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), mountOptions->ProtectedHidVolPassword.Text);
1359:
1360: return 1;
1361: }
1362:
1363: case WM_COMMAND:
1364:
1365: if (lw == IDC_KEYFILES_HIDVOL_PROT)
1366: {
1367: if (IDOK == DialogBoxParamW (hInst,
1368: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
1369: (DLGPROC) KeyFilesDlgProc, (LPARAM) &hidVolProtKeyFilesParam))
1370: {
1371: SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT, hidVolProtKeyFilesParam.EnableKeyFiles);
1372: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), hidVolProtKeyFilesParam.EnableKeyFiles);
1373: }
1374: }
1375:
1376: if (lw == IDC_KEYFILES_ENABLE_HIDVOL_PROT)
1377: {
1378: hidVolProtKeyFilesParam.EnableKeyFiles = GetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT);
1379: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), hidVolProtKeyFilesParam.EnableKeyFiles);
1380:
1381: return 0;
1382: }
1383:
1384: if (lw == IDC_SHOW_PASSWORD_MO)
1385: {
1386: SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
1387: EM_SETPASSWORDCHAR,
1388: GetCheckBox (hwndDlg, IDC_SHOW_PASSWORD_MO) ? 0 : '*',
1389: 0);
1390: InvalidateRect (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), NULL, TRUE);
1391: return 1;
1392: }
1393:
1394: if (lw == IDCANCEL)
1395: {
1396: char tmp[MAX_PASSWORD+1];
1397:
1398: // Cleanup
1399: memset (tmp, 'X', MAX_PASSWORD);
1400: tmp[MAX_PASSWORD] = 0;
1401: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
1402:
1403: EndDialog (hwndDlg, lw);
1404: return 1;
1405: }
1406:
1407: if (lw == IDOK)
1408: {
1409: char tmp[MAX_PASSWORD+1];
1410:
1411: mountOptions->ReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
1412: mountOptions->Removable = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_REMOVABLE));
1413: mountOptions->ProtectHiddenVolume = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1414:
1415: if (mountOptions->ProtectHiddenVolume)
1416: {
1417: GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL),
1418: mountOptions->ProtectedHidVolPassword.Text,
1419: sizeof (mountOptions->ProtectedHidVolPassword.Text));
1420:
1421: mountOptions->ProtectedHidVolPassword.Length = strlen (mountOptions->ProtectedHidVolPassword.Text);
1422: }
1423:
1424: // Cleanup
1425: memset (tmp, 'X', MAX_PASSWORD);
1426: tmp[MAX_PASSWORD] = 0;
1427: SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), tmp);
1428:
1429: if (mountOptions->ProtectHiddenVolume && !bEnableBkgTask)
1430: if (AskWarnYesNo ("HIDVOL_PROT_BKG_TASK_WARNING") == IDYES)
1431: bEnableBkgTask = TRUE;
1432:
1433: EndDialog (hwndDlg, lw);
1434: return 1;
1435: }
1436:
1437: if (lw == IDC_MOUNT_READONLY || lw == IDC_PROTECT_HIDDEN_VOL)
1438: {
1439: BOOL protect;
1440:
1441: if (lw == IDC_MOUNT_READONLY)
1442: {
1443: SendDlgItemMessage (hwndDlg, IDC_PROTECT_HIDDEN_VOL, BM_SETCHECK, BST_UNCHECKED, 0);
1444: EnableWindow (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1445: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_VOL_PROTECTION), !IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY)));
1446: }
1447:
1448: protect = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PROTECT_HIDDEN_VOL));
1449:
1450: EnableWindow (GetDlgItem (hwndDlg, IDC_PASSWORD_PROT_HIDVOL), protect);
1451: EnableWindow (GetDlgItem (hwndDlg, IDT_HIDDEN_PROT_PASSWD), protect);
1452: EnableWindow (GetDlgItem (hwndDlg, IDC_SHOW_PASSWORD_MO), protect);
1453: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_HIDVOL_PROT), protect && hidVolProtKeyFilesParam.EnableKeyFiles);
1454: EnableWindow (GetDlgItem (hwndDlg, IDC_KEYFILES_ENABLE_HIDVOL_PROT), protect);
1455:
1456: return 1;
1457: }
1458:
1459: return 0;
1460: }
1461:
1462: return 0;
1463: }
1464:
1465:
1466: BOOL WINAPI
1467: VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1468: {
1.1 root 1469: WORD lw = LOWORD (wParam);
1.1.1.7 root 1470: int i = 0;
1.1 root 1471:
1472: switch (msg)
1473: {
1474: case WM_INITDIALOG:
1475: {
1476: VOLUME_PROPERTIES_STRUCT prop;
1477: DWORD dwResult;
1478: BOOL bResult;
1479:
1.1.1.7 root 1480: LVCOLUMNW lvCol;
1.1 root 1481: HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
1.1.1.7 root 1482: char szTmp[1024];
1483: wchar_t sw[1024];
1484: wchar_t *s;
1.1 root 1485:
1.1.1.7 root 1486: LocalizeDialog (hwndDlg, "IDD_VOLUME_PROPERTIES");
1.1 root 1487:
1.1.1.7 root 1488: SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
1.1 root 1489: LVS_EX_FULLROWSELECT
1.1.1.7 root 1490: |LVS_EX_HEADERDRAGDROP
1491: |LVS_EX_LABELTIP
1.1 root 1492: );
1493:
1494: memset (&lvCol,0,sizeof(lvCol));
1495: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
1.1.1.7 root 1496: lvCol.pszText = GetString ("VALUE");
1497: lvCol.cx = 202;
1.1 root 1498: lvCol.fmt = LVCFMT_LEFT ;
1.1.1.7 root 1499: SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 1500:
1.1.1.7 root 1501: lvCol.pszText = GetString ("PROPERTY");
1.1.1.8 root 1502: lvCol.cx = 177;
1.1 root 1503: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 1504: SendMessage (list,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 1505:
1506: memset (&prop, 0, sizeof(prop));
1507: prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
1508:
1509: bResult = DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop,
1510: sizeof (prop), &prop, sizeof (prop), &dwResult,
1511: NULL);
1512:
1.1.1.7 root 1513: // Location
1514: ListItemAddW (list, i, GetString ("LOCATION"));
1515: ListSubItemSetW (list, i++, 1, prop.wszVolume[1] != L'?' ? prop.wszVolume : prop.wszVolume + 4);
1516:
1517: // Size
1518: ListItemAddW (list, i, GetString ("SIZE"));
1519: swprintf (sw, L"%I64u %s", prop.diskLength, GetString ("BYTES"));
1520: ListSubItemSetW (list, i++, 1, sw);
1521:
1522: // Type
1523: ListItemAddW (list, i, GetString ("TYPE"));
1524: ListSubItemSetW (list, i++, 1,
1525: prop.hiddenVolume ? GetString ("HIDDEN") :
1526: (prop.hiddenVolProtection != HIDVOL_PROT_STATUS_NONE ? GetString ("OUTER") : GetString ("NORMAL")));
1527:
1528: // Write protection
1529: ListItemAddW (list, i, GetString ("READ_ONLY"));
1.1 root 1530:
1.1.1.7 root 1531: if (prop.readOnly || prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
1532: s = GetString ("UISTR_YES");
1533: else
1534: s = GetString ("UISTR_NO");
1.1 root 1535:
1.1.1.7 root 1536: ListSubItemSetW (list, i++, 1, s);
1.1 root 1537:
1.1.1.7 root 1538: // Hidden Volume Protection
1539: ListItemAddW (list, i, GetString ("HIDDEN_VOL_PROTECTION"));
1540: if (prop.hiddenVolume)
1541: s = GetString ("N_A_UISTR");
1542: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_NONE)
1543: s = GetString ("UISTR_NO");
1544: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTIVE)
1545: s = GetString ("UISTR_YES");
1546: else if (prop.hiddenVolProtection == HIDVOL_PROT_STATUS_ACTION_TAKEN)
1547: s = GetString ("HID_VOL_DAMAGE_PREVENTED");
1.1.1.6 root 1548:
1.1.1.7 root 1549: ListSubItemSetW (list, i++, 1, s);
1.1 root 1550:
1.1.1.7 root 1551: // Encryption algorithm
1552: ListItemAddW (list, i, GetString ("ENCRYPTION_ALGORITHM"));
1553: EAGetName (szTmp, prop.ea);
1554: ListSubItemSet (list, i++, 1, szTmp);
1.1.1.5 root 1555:
1.1.1.7 root 1556: // Key size
1557: {
1558: char name[128];
1559: int size = EAGetKeySize (prop.ea);
1560: EAGetName (name, prop.ea);
1561:
1562: if (strcmp (name, "Triple DES") == 0)
1563: size -= 3; // Compensate for parity bytes
1564:
1565: ListItemAddW (list, i, GetString ("KEY_SIZE"));
1566: wsprintfW (sw, L"%d %s", size * 8, GetString ("BITS"));
1567: ListSubItemSetW (list, i++, 1, sw);
1568: }
1.1.1.5 root 1569:
1.1.1.7 root 1570: // Block size
1571: ListItemAddW (list, i, GetString ("BLOCK_SIZE"));
1.1.1.8 root 1572: if (EAGetFirstMode (prop.ea) == INNER_CBC)
1.1.1.5 root 1573: {
1.1.1.8 root 1574: // Cascaded ciphers with non-equal block sizes (deprecated/legacy)
1575: wchar_t tmpstr[64];
1.1.1.5 root 1576: int i = EAGetLastCipher(prop.ea);
1577:
1.1.1.7 root 1578: swprintf (sw, L"%d", CipherGetBlockSize(i)*8);
1.1.1.5 root 1579:
1580: while (i = EAGetPreviousCipher(prop.ea, i))
1581: {
1.1.1.7 root 1582: swprintf (tmpstr, L"/%d", CipherGetBlockSize(i)*8);
1583: wcscat (sw, tmpstr);
1.1.1.5 root 1584: }
1.1.1.7 root 1585: wcscat (sw, L" ");
1.1.1.5 root 1586: }
1587: else
1588: {
1.1.1.7 root 1589: swprintf (sw, L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
1.1.1.5 root 1590: }
1.1.1.7 root 1591: wcscat (sw, GetString ("BITS"));
1592: ListSubItemSetW (list, i++, 1, sw);
1.1.1.5 root 1593:
1.1.1.7 root 1594: // Mode
1595: ListItemAddW (list, i, GetString ("MODE_OF_OPERATION"));
1.1.1.8 root 1596: ListSubItemSet (list, i++, 1, EAGetModeName (prop.ea, prop.mode, TRUE));
1.1.1.7 root 1597:
1598: // PRF
1599: ListItemAddW (list, i, GetString ("PKCS5_PRF"));
1600: ListSubItemSet (list, i++, 1, get_pkcs5_prf_name (prop.pkcs5));
1.1 root 1601:
1.1.1.7 root 1602: // PCKS iterations
1603: ListItemAddW (list, i, GetString ("PKCS5_ITERATIONS"));
1.1 root 1604: sprintf (szTmp, "%d", prop.pkcs5Iterations);
1.1.1.7 root 1605: ListSubItemSet (list, i++, 1, szTmp);
1606:
1.1 root 1607: {
1608: FILETIME ft, curFt;
1609: SYSTEMTIME st;
1.1.1.7 root 1610: wchar_t date[128];
1.1 root 1611: memset (date, 0, sizeof (date));
1612:
1.1.1.7 root 1613: // Volume date
1614: ListItemAddW (list, i, GetString ("VOLUME_CREATE_DATE"));
1.1 root 1615: *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
1616: FileTimeToSystemTime (&ft, &st);
1.1.1.7 root 1617: GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1618: swprintf (date, L"%s ", sw);
1619: GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1620: wcscat (date, sw);
1621: ListSubItemSetW (list, i++, 1, date);
1.1 root 1622:
1.1.1.7 root 1623: // Header date
1624: ListItemAddW (list, i, GetString ("VOLUME_HEADER_DATE"));
1.1 root 1625: *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
1626: FileTimeToSystemTime (&ft, &st);
1.1.1.7 root 1627: GetDateFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1628: swprintf (date, L"%s ", sw);
1629: GetTimeFormatW (LOCALE_USER_DEFAULT, 0, &st, 0, sw, sizeof (sw)/2);
1630: wcscat (date, sw);
1.1 root 1631:
1632: GetLocalTime (&st);
1633: SystemTimeToFileTime (&st, &curFt);
1.1.1.7 root 1634: swprintf (date + wcslen (date), GetString ("VOLUME_HEADER_DAYS")
1635: , (*(__int64 *)&curFt - *(__int64 *)&ft)/1000000000000);
1636: ListSubItemSetW (list, i++, 1, date);
1.1 root 1637: }
1638:
1.1.1.7 root 1639: // Total data read
1640: ListItemAddW (list, i, GetString ("TOTAL_DATA_READ"));
1641: GetSizeString (prop.totalBytesRead, sw);
1642: ListSubItemSetW (list, i++, 1, sw);
1643:
1644: // Total data written
1645: ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN"));
1646: GetSizeString (prop.totalBytesWritten, sw);
1647: ListSubItemSetW (list, i++, 1, sw);
1648:
1.1 root 1649: return 1;
1650: }
1651:
1652: case WM_COMMAND:
1653: if (lw == IDOK)
1654: {
1655: EndDialog (hwndDlg, lw);
1656: return 1;
1657: }
1658: return 0;
1.1.1.9 root 1659:
1660: case WM_CLOSE:
1661: EndDialog (hwndDlg, lw);
1662: return 1;
1.1 root 1663: }
1664:
1665: return 0;
1666: }
1667:
1.1.1.6 root 1668:
1669: BOOL WINAPI
1670: TravellerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1671: {
1672: WORD lw = LOWORD (wParam);
1673:
1674: switch (msg)
1675: {
1676: case WM_INITDIALOG:
1677: {
1678: int i, index;
1679: char drive[] = { 0, ':', 0 };
1680:
1.1.1.7 root 1681: LocalizeDialog (hwndDlg, "IDD_TRAVELLER_DLG");
1.1.1.6 root 1682:
1683: SendDlgItemMessage (hwndDlg, IDC_COPY_WIZARD, BM_SETCHECK,
1684: BST_CHECKED, 0);
1685:
1.1.1.7 root 1686: SendDlgItemMessage (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER, BM_SETCHECK,
1.1.1.6 root 1687: BST_CHECKED, 0);
1688:
1689: SendDlgItemMessage (hwndDlg, IDC_AUTORUN_DISABLE, BM_SETCHECK,
1690: BST_CHECKED, 0);
1691:
1692: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_RESETCONTENT, 0, 0);
1693:
1.1.1.7 root 1694: index = SendDlgItemMessageW (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) GetString ("FIRST_AVAILABLE"));
1.1.1.6 root 1695: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) 0);
1696:
1697: for (i = 'A'; i <= 'Z'; i++)
1698: {
1699: drive[0] = i;
1700: index = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_ADDSTRING, 0, (LPARAM) drive);
1701: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETITEMDATA, index, (LPARAM) i);
1702: }
1703:
1704: SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_SETCURSEL, 0, 0);
1705:
1706: return 1;
1707: }
1708:
1.1.1.7 root 1709:
1.1.1.6 root 1710: case WM_COMMAND:
1711:
1.1.1.7 root 1712: if (HIWORD (wParam) == BN_CLICKED
1713: && (lw == IDC_AUTORUN_DISABLE || lw == IDC_AUTORUN_MOUNT || lw == IDC_AUTORUN_START ))
1714: {
1715: BOOL enabled = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_DISABLE));
1716:
1717: EnableWindow (GetDlgItem (hwndDlg, IDC_BROWSE_FILES), enabled);
1718: EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_NAME), enabled);
1719: EnableWindow (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER), enabled);
1720: EnableWindow (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS), enabled);
1721: EnableWindow (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY), enabled);
1722: EnableWindow (GetDlgItem (hwndDlg, IDC_DRIVELIST), enabled);
1723: EnableWindow (GetDlgItem (hwndDlg, IDT_TRAVELLER_MOUNT), enabled);
1724: EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_LETTER), enabled);
1725: EnableWindow (GetDlgItem (hwndDlg, IDT_MOUNT_SETTINGS), enabled);
1726:
1727: return 1;
1728: }
1729:
1.1.1.6 root 1730: if (lw == IDC_BROWSE_FILES)
1731: {
1.1.1.7 root 1732: char volName[MAX_PATH] = { 0 };
1.1.1.6 root 1733:
1.1.1.10! root 1734: if (BrowseFiles (hwndDlg, "OPEN_TITLE", volName, bHistory, FALSE))
1.1.1.6 root 1735: SetDlgItemText (hwndDlg, IDC_VOLUME_NAME, strchr (volName, '\\') + 1);
1.1.1.7 root 1736:
1.1.1.6 root 1737: return 1;
1738: }
1739:
1740: if (lw == IDC_BROWSE_DIRS)
1741: {
1742: char dstPath[MAX_PATH * 2];
1.1.1.7 root 1743: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath, sizeof dstPath);
1.1.1.6 root 1744:
1.1.1.7 root 1745: if (BrowseDirectories (hwndDlg, "SELECT_DEST_DIR", dstPath))
1.1.1.6 root 1746: SetDlgItemText (hwndDlg, IDC_DIRECTORY, dstPath);
1.1.1.7 root 1747:
1.1.1.6 root 1748: return 1;
1749: }
1750:
1751: if (lw == IDCANCEL)
1752: {
1753: EndDialog (hwndDlg, lw);
1754: return 1;
1755: }
1756:
1.1.1.7 root 1757: if (lw == IDC_CREATE)
1.1.1.6 root 1758: {
1759: BOOL copyWizard, bExplore, bCacheInDriver, bAutoRun, bAutoMount, bMountReadOnly;
1760: char dstDir[MAX_PATH];
1761: char srcPath[MAX_PATH * 2];
1762: char dstPath[MAX_PATH * 2];
1763: char appDir[MAX_PATH];
1764: char sysDir[MAX_PATH];
1765: char volName[MAX_PATH];
1766: int drive;
1767:
1768: GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
1769: volName[0] = 0;
1770: GetDlgItemText (hwndDlg, IDC_VOLUME_NAME, volName + 1, sizeof volName);
1771:
1772: drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETCURSEL, 0, 0);
1773: drive = SendDlgItemMessage (hwndDlg, IDC_DRIVELIST, CB_GETITEMDATA, drive, 0);
1774:
1775: copyWizard = IsButtonChecked (GetDlgItem (hwndDlg, IDC_COPY_WIZARD));
1.1.1.7 root 1776: bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAVEL_OPEN_EXPLORER));
1777: bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_TRAV_CACHE_PASSWORDS));
1.1.1.6 root 1778: bMountReadOnly = IsButtonChecked (GetDlgItem (hwndDlg, IDC_MOUNT_READONLY));
1779: bAutoRun = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_DISABLE));
1780: bAutoMount = IsButtonChecked (GetDlgItem (hwndDlg, IDC_AUTORUN_MOUNT));
1781:
1782: if (dstDir[0] == 0)
1783: {
1784: SetFocus (GetDlgItem (hwndDlg, IDC_DIRECTORY));
1.1.1.7 root 1785: MessageBoxW (hwndDlg, GetString ("NO_PATH_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6 root 1786: return 1;
1787: }
1788:
1789:
1790: if (bAutoMount && volName[1] == 0)
1791: {
1792: SetFocus (GetDlgItem (hwndDlg, IDC_VOLUME_NAME));
1.1.1.7 root 1793: MessageBoxW (hwndDlg, GetString ("NO_FILE_SELECTED"), lpszTitle, MB_ICONEXCLAMATION);
1.1.1.6 root 1794: return 1;
1795: }
1796:
1797: if (volName[1] != 0)
1798: {
1799: volName[0] = '"';
1800: strcat (volName, "\"");
1801: }
1802:
1803: EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
1804: EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), FALSE);
1805:
1806: GetModuleFileName (NULL, appDir, sizeof (appDir));
1807: strrchr (appDir, '\\')[0] = 0;
1808:
1809: ArrowWaitCursor();
1810: GetSystemDirectory (sysDir, sizeof (sysDir));
1811:
1812: sprintf (dstPath, "%s\\TrueCrypt", dstDir);
1813: CreateDirectory (dstPath, NULL);
1814:
1815: // Main app
1816: sprintf (srcPath, "%s\\TrueCrypt.exe", appDir);
1817: sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt.exe", dstDir);
1818: if (!TCCopyFile (srcPath, dstPath))
1819: {
1820: handleWin32Error (hwndDlg);
1821: goto stop;
1822: }
1823:
1824: // Wizard
1825: if (copyWizard)
1826: {
1827: sprintf (srcPath, "%s\\TrueCrypt Format.exe", appDir);
1828: sprintf (dstPath, "%s\\TrueCrypt\\TrueCrypt Format.exe", dstDir);
1829: if (!TCCopyFile (srcPath, dstPath))
1830: {
1831: handleWin32Error (hwndDlg);
1832: goto stop;
1833: }
1834: }
1835:
1836: // Driver
1.1.1.7 root 1837: sprintf (srcPath, "%s\\truecrypt.sys", appDir);
1.1.1.6 root 1838: sprintf (dstPath, "%s\\TrueCrypt\\truecrypt.sys", dstDir);
1839: if (!TCCopyFile (srcPath, dstPath))
1840: {
1841: handleWin32Error (hwndDlg);
1842: goto stop;
1843: }
1844:
1.1.1.7 root 1845: // Driver x64
1846: sprintf (srcPath, "%s\\truecrypt-x64.sys", appDir);
1847: sprintf (dstPath, "%s\\TrueCrypt\\truecrypt-x64.sys", dstDir);
1848: if (!TCCopyFile (srcPath, dstPath))
1849: {
1850: handleWin32Error (hwndDlg);
1851: goto stop;
1852: }
1853:
1.1.1.6 root 1854: // AutoRun
1855: if (bAutoRun)
1856: {
1857: FILE *af;
1858: char autoMount[100];
1859: char openApp[100];
1860: char driveLetter[] = { ' ', '/', 'l', drive, 0 };
1861:
1862: sprintf (dstPath, "%s\\autorun.inf", dstDir);
1863: af = fopen (dstPath, "w");
1864:
1865: if (af == NULL)
1866: {
1.1.1.7 root 1867: MessageBoxW (hwndDlg, GetString ("CANT_CREATE_AUTORUN"), lpszTitle, MB_ICONERROR);
1.1.1.6 root 1868: goto stop;
1869: }
1870:
1871: fprintf (af, "[autorun]\n");
1872:
1873: sprintf (autoMount, "TrueCrypt\\TrueCrypt.exe /q /a%s%s%s%s /m rm /v %s",
1874: drive > 0 ? driveLetter : "",
1875: bExplore ? " /e" : "",
1876: bCacheInDriver ? " /cy" : "",
1877: bMountReadOnly ? " /m ro" : "",
1878: volName);
1879:
1880: sprintf (openApp, "TrueCrypt\\TrueCrypt.exe%s%s%s%s /m rm%s%s",
1881: drive > 0 ? driveLetter : "",
1882: bExplore ? " /e" : "",
1883: bCacheInDriver ? " /cy" : "",
1884: bMountReadOnly ? " /m ro" : "",
1885: volName[0] != 0 ? " /v " : "",
1886: volName[0] != 0 ? volName : "");
1887:
1888: fprintf (af, "open=%s\n",
1889: bAutoMount ? autoMount : openApp);
1890:
1891: fprintf (af, "shell=%s\n",
1892: bAutoMount ? "mount" : "open");
1893:
1894: fprintf (af, "action=%s\n",
1895: bAutoMount ? "Mount TrueCrypt Volume" : "Start TrueCrypt");
1896:
1897: fprintf (af, "shell\\open\\command=%s\nshell\\open=TrueCrypt Start\n", openApp);
1898:
1899: if (volName[0] != 0)
1900: fprintf (af, "shell\\mount\\command=%s\nshell\\mount=TrueCrypt Mount\n", autoMount);
1901:
1902: fprintf (af, "shell\\dismount\\command=TrueCrypt\\TrueCrypt.exe /q /d\nshell\\dismount=TrueCrypt Dismount All\n");
1903:
1904: fclose (af);
1905: }
1.1.1.7 root 1906: MessageBoxW (hwndDlg, GetString ("TRAVELLER_DISK_CREATED"), lpszTitle, MB_ICONINFORMATION);
1.1.1.6 root 1907:
1908: stop:
1909: NormalCursor ();
1910: EnableWindow (GetDlgItem (hwndDlg, IDOK), TRUE);
1911: EnableWindow (GetDlgItem (hwndDlg, IDCANCEL), TRUE);
1912:
1913: return 1;
1914: }
1915: return 0;
1916: }
1917:
1918: return 0;
1919: }
1920:
1921:
1.1 root 1922: void
1923: BuildTree (HWND hTree)
1924: {
1925: HIMAGELIST hList;
1926: HBITMAP hBitmap, hBitmapMask;
1.1.1.7 root 1927: LVCOLUMNW lvCol;
1928:
1929: ListView_DeleteColumn (hTree,0);
1930: ListView_DeleteColumn (hTree,0);
1931: ListView_DeleteColumn (hTree,0);
1932: ListView_DeleteColumn (hTree,0);
1933: ListView_DeleteColumn (hTree,0);
1934: ListView_DeleteColumn (hTree,0);
1935:
1.1 root 1936: SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
1937: LVS_EX_FULLROWSELECT
1938: |LVS_EX_HEADERDRAGDROP
1939: );
1940:
1941: memset(&lvCol,0,sizeof(lvCol));
1942:
1943: lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
1.1.1.7 root 1944: lvCol.pszText = GetString ("DRIVE");
1945: lvCol.cx = 37;
1.1 root 1946: lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
1.1.1.7 root 1947: SendMessage (hTree,LVM_INSERTCOLUMNW,0,(LPARAM)&lvCol);
1.1 root 1948:
1.1.1.7 root 1949: lvCol.pszText = GetString ("VOLUME");
1950: lvCol.cx = 258;
1.1 root 1951: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 1952: SendMessage (hTree,LVM_INSERTCOLUMNW,1,(LPARAM)&lvCol);
1.1 root 1953:
1.1.1.7 root 1954: lvCol.pszText = GetString ("SIZE");
1955: lvCol.cx = 55;
1.1 root 1956: lvCol.fmt = LVCFMT_RIGHT;
1.1.1.7 root 1957: SendMessage (hTree,LVM_INSERTCOLUMNW,2,(LPARAM)&lvCol);
1.1 root 1958:
1.1.1.7 root 1959: lvCol.pszText = GetString ("ENCRYPTION_ALGORITHM");
1960: lvCol.cx = 117;
1.1 root 1961: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 1962: SendMessage (hTree,LVM_INSERTCOLUMNW,3,(LPARAM)&lvCol);
1.1 root 1963:
1.1.1.7 root 1964: lvCol.pszText = GetString ("TYPE");
1965: lvCol.cx = 52;
1.1.1.5 root 1966: lvCol.fmt = LVCFMT_LEFT;
1.1.1.7 root 1967: SendMessage (hTree,LVM_INSERTCOLUMNW,4,(LPARAM)&lvCol);
1.1.1.5 root 1968:
1.1 root 1969: hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
1970: if (hBitmap == NULL)
1971: return;
1972: hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
1973:
1974: hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
1975: if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
1976: {
1977: DeleteObject (hBitmap);
1978: return;
1979: }
1980: else
1981: DeleteObject (hBitmap);
1982:
1983: ListView_SetImageList (hTree, hList, LVSIL_NORMAL);
1984: ListView_SetImageList (hTree, hList, LVSIL_SMALL);
1985:
1986: LoadDriveLetters (hTree, 0);
1987: }
1988:
1989: LPARAM
1990: GetSelectedLong (HWND hTree)
1991: {
1992: int hItem = ListView_GetSelectionMark (hTree);
1993: LVITEM item;
1994:
1.1.1.5 root 1995: if (nSelectedDriveIndex >= 0)
1.1 root 1996: hItem = nSelectedDriveIndex;
1997:
1998: memset(&item, 0, sizeof(LVITEM));
1999: item.mask = LVIF_PARAM;
2000: item.iItem = hItem;
2001:
2002: if (ListView_GetItem (hTree, &item) == FALSE)
2003: return MAKELONG (0xffff, 0xffff);
2004: else
2005: return item.lParam;
2006: }
2007:
2008: LPARAM
2009: GetItemLong (HWND hTree, int itemNo)
2010: {
2011: LVITEM item;
2012:
2013: memset(&item, 0, sizeof(LVITEM));
2014: item.mask = LVIF_PARAM;
2015: item.iItem = itemNo;
2016:
2017: if (ListView_GetItem (hTree, &item) == FALSE)
2018: return MAKELONG (0xffff, 0xffff);
2019: else
2020: return item.lParam;
2021: }
2022:
1.1.1.7 root 2023: static int AskUserPassword (HWND hwndDlg, Password *password)
1.1 root 2024: {
1.1.1.7 root 2025: int result;
2026:
2027: result = DialogBoxParamW (hInst,
2028: MAKEINTRESOURCEW (IDD_PASSWORD_DLG), hwndDlg,
1.1 root 2029: (DLGPROC) PasswordDlgProc, (LPARAM) password);
2030:
2031: if (result != IDOK)
1.1.1.7 root 2032: {
2033: password->Length = 0;
2034: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2035: }
1.1 root 2036:
2037: return result == IDOK;
2038: }
2039:
2040: // GUI actions
2041:
1.1.1.7 root 2042: static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
1.1 root 2043: {
1.1.1.7 root 2044: BOOL status = FALSE;
2045: char fileName[MAX_PATH];
1.1 root 2046: int mounted = 0;
1.1.1.7 root 2047: if (nDosDriveNo == 0)
2048: nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
1.1 root 2049:
1.1.1.7 root 2050: VolumePassword.Length = 0;
2051:
2052: if (szFileName == NULL)
2053: {
2054: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), fileName, sizeof (fileName));
2055: szFileName = fileName;
2056: }
1.1 root 2057:
2058: if (strlen(szFileName) == 0)
1.1.1.7 root 2059: {
2060: status = FALSE;
2061: goto ret;
2062: }
1.1 root 2063:
2064: if (IsMountedVolume (szFileName))
2065: {
1.1.1.7 root 2066: Warning ("ALREADY_MOUNTED");
2067: status = FALSE;
2068: goto ret;
1.1 root 2069: }
2070:
2071: // First try cached passwords and if they fail ask user for a new one
2072: ArrowWaitCursor ();
1.1.1.7 root 2073:
2074: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, FALSE, FALSE);
1.1 root 2075:
1.1.1.7 root 2076: // If keyfiles are enabled, test empty password first
2077: if (!mounted && KeyFilesEnable)
1.1 root 2078: {
1.1.1.7 root 2079: KeyFilesApply (&VolumePassword, FirstKeyFile, bPreserveTimestamp);
2080: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, FALSE);
2081: }
1.1 root 2082:
1.1.1.7 root 2083: NormalCursor ();
2084:
2085: while (mounted == 0)
2086: {
2087: if (CmdVolumePassword.Length > 0)
2088: {
2089: VolumePassword = CmdVolumePassword;
2090: }
2091: else if (!Silent)
2092: {
2093: strcpy (PasswordDlgVolume, szFileName);
2094: if (!AskUserPassword (hwndDlg, &VolumePassword))
2095: goto ret;
2096: }
2097:
1.1 root 2098: ArrowWaitCursor ();
1.1.1.7 root 2099:
2100: if (KeyFilesEnable)
2101: KeyFilesApply (&VolumePassword, FirstKeyFile, bPreserveTimestamp);
2102:
2103: mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
1.1 root 2104: NormalCursor ();
1.1.1.7 root 2105:
1.1.1.9 root 2106: if (mounted > 0 && !KeyFilesEnable && !CheckPasswordCharEncoding (NULL, &VolumePassword))
2107: Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
2108:
1.1.1.8 root 2109: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.7 root 2110: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2111:
2112: if (CmdVolumePassword.Length > 0 || Silent)
2113: break;
1.1 root 2114: }
2115:
1.1.1.5 root 2116: if (mounted > 0)
1.1 root 2117: {
1.1.1.7 root 2118: status = TRUE;
2119:
2120: if (bBeep)
2121: MessageBeep (-1);
1.1 root 2122:
2123: RefreshMainDlg(hwndDlg);
2124:
1.1.1.7 root 2125: if (bExplore)
1.1 root 2126: {
2127: ArrowWaitCursor();
2128: OpenVolumeExplorerWindow (nDosDriveNo);
2129: NormalCursor();
2130: }
1.1.1.7 root 2131:
2132: if (mountOptions.ProtectHiddenVolume)
2133: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
1.1 root 2134: }
2135:
1.1.1.7 root 2136: ret:
1.1.1.8 root 2137: burn (&VolumePassword, sizeof (VolumePassword));
1.1.1.7 root 2138: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2139: RestoreDefaultKeyFilesParam ();
2140: return status;
1.1 root 2141: }
2142:
2143:
1.1.1.7 root 2144: static BOOL Dismount (HWND hwndDlg, int nDosDriveNo)
1.1 root 2145: {
1.1.1.7 root 2146: BOOL status = FALSE;
1.1.1.5 root 2147: ArrowWaitCursor ();
1.1 root 2148:
1.1.1.2 root 2149: if (nDosDriveNo == 0)
2150: nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
1.1 root 2151:
1.1.1.5 root 2152: if (bCloseDismountedWindows)
1.1 root 2153: {
1.1.1.6 root 2154: CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
1.1 root 2155: }
2156:
1.1.1.5 root 2157: if (UnmountVolume (hwndDlg, nDosDriveNo, bForceUnmount))
2158: {
1.1.1.7 root 2159: status = TRUE;
2160:
2161: if (bBeep)
2162: MessageBeep (-1);
1.1.1.5 root 2163: RefreshMainDlg (hwndDlg);
1.1.1.10! root 2164:
! 2165: if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
! 2166: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1 root 2167: }
2168:
1.1.1.5 root 2169: NormalCursor ();
1.1.1.7 root 2170: return status;
1.1 root 2171: }
2172:
1.1.1.7 root 2173: static BOOL DismountAll (HWND hwndDlg, BOOL forceUnmount, BOOL interact, int dismountMaxRetries, int dismountAutoRetryDelay)
1.1 root 2174: {
1.1.1.7 root 2175: BOOL status = TRUE;
1.1.1.5 root 2176: MOUNT_LIST_STRUCT mountList;
2177: DWORD dwResult;
2178: UNMOUNT_STRUCT unmount;
1.1 root 2179: BOOL bResult;
1.1.1.5 root 2180: unsigned __int32 prevMountedDrives = 0;
2181: int i;
1.1 root 2182:
1.1.1.5 root 2183: retry:
1.1 root 2184: ArrowWaitCursor();
2185:
1.1.1.5 root 2186: DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.7 root 2187:
2188: if (mountList.ulMountedDrives == 0)
2189: {
2190: NormalCursor();
2191: return TRUE;
2192: }
2193:
1.1.1.5 root 2194: prevMountedDrives = mountList.ulMountedDrives;
2195:
2196: for (i = 0; i < 26; i++)
1.1 root 2197: {
1.1.1.5 root 2198: if (mountList.ulMountedDrives & (1 << i))
1.1 root 2199: {
1.1.1.5 root 2200: if (bCloseDismountedWindows)
1.1.1.6 root 2201: CloseVolumeExplorerWindows (hwndDlg, i);
1.1 root 2202: }
1.1.1.5 root 2203: }
1.1 root 2204:
1.1.1.5 root 2205: unmount.nDosDriveNo = 0;
2206: unmount.ignoreOpenFiles = forceUnmount;
1.1 root 2207:
1.1.1.6 root 2208: do
2209: {
2210: bResult = DeviceIoControl (hDriver, UNMOUNT_ALL, &unmount,
2211: sizeof (unmount), &unmount, sizeof (unmount), &dwResult, NULL);
2212:
2213: if (bResult == FALSE)
2214: {
2215: NormalCursor();
2216: handleWin32Error (hwndDlg);
1.1.1.7 root 2217: return FALSE;
1.1.1.6 root 2218: }
1.1 root 2219:
1.1.1.6 root 2220: if (unmount.nReturnCode == ERR_FILES_OPEN)
1.1.1.7 root 2221: Sleep (dismountAutoRetryDelay);
1.1.1.6 root 2222: else
2223: break;
1.1 root 2224:
1.1.1.6 root 2225: } while (--dismountMaxRetries > 0);
1.1 root 2226:
1.1.1.7 root 2227: memset (&mountList, 0, sizeof (mountList));
1.1.1.5 root 2228: DeviceIoControl (hDriver, MOUNT_LIST, &mountList, sizeof (mountList), &mountList, sizeof (mountList), &dwResult, NULL);
1.1.1.6 root 2229: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, prevMountedDrives & ~mountList.ulMountedDrives);
1.1 root 2230:
1.1.1.7 root 2231: RefreshMainDlg (hwndDlg);
1.1.1.10! root 2232:
! 2233: if (nCurrentOS == WIN_2000 && RemoteSession && !IsAdmin ())
! 2234: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
! 2235:
1.1.1.5 root 2236: NormalCursor();
1.1 root 2237:
1.1.1.5 root 2238: if (unmount.nReturnCode != 0)
2239: {
1.1.1.7 root 2240: if (forceUnmount)
2241: status = FALSE;
2242:
1.1.1.5 root 2243: if (unmount.nReturnCode == ERR_FILES_OPEN)
2244: {
1.1.1.7 root 2245: if (interact && IDYES == AskWarnNoYes ("UNMOUNTALL_LOCK_FAILED"))
1.1 root 2246: {
1.1.1.5 root 2247: forceUnmount = TRUE;
2248: goto retry;
1.1 root 2249: }
1.1.1.5 root 2250:
1.1.1.7 root 2251: return FALSE;
1.1 root 2252: }
1.1.1.5 root 2253:
1.1.1.7 root 2254: if (interact)
2255: MessageBoxW (hwndDlg, GetString ("UNMOUNT_FAILED"), lpszTitle, MB_ICONERROR);
1.1 root 2256: }
2257: else
2258: {
1.1.1.7 root 2259: if (bBeep)
2260: MessageBeep (-1);
1.1 root 2261: }
1.1.1.7 root 2262:
2263: return status;
1.1 root 2264: }
2265:
1.1.1.7 root 2266: static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
1.1 root 2267: {
2268: HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
2269: int i, n, selDrive = ListView_GetSelectionMark (driveList);
1.1.1.7 root 2270: BOOL shared = FALSE, status = FALSE;
2271: int mountedVolCount = 0;
1.1.1.6 root 2272:
1.1.1.7 root 2273: VolumePassword.Length = 0;
1.1.1.6 root 2274: mountOptions = defaultMountOptions;
2275:
1.1.1.7 root 2276: if (selDrive == -1) selDrive = 0;
1.1 root 2277:
1.1.1.7 root 2278: do
1.1 root 2279: {
1.1.1.7 root 2280: if (!CmdVolumePasswordValid && bPasswordPrompt)
2281: {
2282: PasswordDlgVolume[0] = '\0';
2283: if (!AskUserPassword (hwndDlg, &VolumePassword))
2284: goto ret;
2285: }
2286: else if (CmdVolumePasswordValid)
2287: {
2288: bPasswordPrompt = FALSE;
2289: VolumePassword = CmdVolumePassword;
2290: }
2291:
2292: ArrowWaitCursor();
2293:
2294: if (FirstCmdKeyFile)
2295: KeyFilesApply (&VolumePassword, FirstCmdKeyFile, bPreserveTimestamp);
2296: else if (KeyFilesEnable)
2297: KeyFilesApply (&VolumePassword, FirstKeyFile, bPreserveTimestamp);
2298:
2299: for (i = 0; i < 64; i++)
1.1 root 2300: {
1.1.1.7 root 2301: // Include partition 0 (whole disk)
2302: for (n = 0; n <= 32; n++)
2303: {
2304: char szFileName[TC_MAX_PATH];
2305: OPEN_TEST_STRUCT driver;
2306: BOOL mounted;
1.1 root 2307:
1.1.1.7 root 2308: sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
1.1.1.6 root 2309:
1.1.1.7 root 2310: mounted = IsMountedVolume (szFileName);
1.1.1.6 root 2311:
1.1.1.7 root 2312: // Skip other partitions of the disk if partition0 (whole disk) is mounted
2313: if (n == 0 && mounted)
2314: break;
1.1.1.6 root 2315:
1.1.1.7 root 2316: if (!mounted && OpenDevice (szFileName, &driver))
2317: {
2318: int nDosDriveNo;
1.1 root 2319:
1.1.1.7 root 2320: while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
1.1 root 2321: {
1.1.1.7 root 2322: if(LOWORD (GetItemLong (driveList, selDrive)) != VFREE)
2323: {
2324: selDrive++;
2325: continue;
2326: }
2327: nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
2328: break;
1.1 root 2329: }
2330:
1.1.1.7 root 2331: if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
2332: goto ret;
1.1 root 2333:
1.1.1.7 root 2334: // First try user password then cached passwords
2335: if ((mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0
2336: || (mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, TRUE, FALSE)) > 0)
2337: {
2338: if (mounted == 2)
2339: shared = TRUE;
1.1.1.5 root 2340:
1.1.1.7 root 2341: LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
2342: selDrive++;
1.1 root 2343:
1.1.1.7 root 2344: if (bExplore)
2345: {
2346: ArrowWaitCursor();
2347: OpenVolumeExplorerWindow (nDosDriveNo);
2348: NormalCursor();
2349: }
2350:
2351: if (bBeep)
2352: MessageBeep (-1);
1.1.1.6 root 2353:
1.1.1.7 root 2354: status = TRUE;
2355:
2356: mountedVolCount++;
2357:
2358: // Skip other partitions of the disk if partition0 (whole disk) has been mounted
2359: if (n == 0)
2360: break;
2361: }
1.1 root 2362: }
1.1.1.7 root 2363: else if (n == 0)
2364: break;
1.1 root 2365: }
2366: }
1.1.1.8 root 2367:
2368: burn (&VolumePassword, sizeof (VolumePassword));
2369:
1.1.1.7 root 2370: if (mountedVolCount < 1 && !Silent)
2371: {
2372: WCHAR szTmp[1024];
2373:
2374: wsprintfW (szTmp, GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"));
2375: if (CheckCapsLock (hwndDlg, TRUE))
2376: wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
2377:
2378: MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING);
2379: }
2380:
2381: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2382: } while (bPasswordPrompt && mountedVolCount < 1);
2383:
2384: /* One or more volumes successfully mounted */
1.1 root 2385:
1.1.1.5 root 2386: if (shared)
1.1.1.7 root 2387: Warning ("DEVICE_IN_USE_INFO");
2388:
2389: if (mountOptions.ProtectHiddenVolume)
2390: {
2391: if (mountedVolCount > 1)
2392: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT_PLURAL");
2393: else if (mountedVolCount == 1)
2394: Info ("HIDVOL_PROT_WARN_AFTER_MOUNT");
2395: }
2396:
2397: if (!KeyFilesEnable
2398: && !FirstCmdKeyFile
2399: && mountedVolCount > 0
2400: && !CheckPasswordCharEncoding (NULL, &VolumePassword))
2401: Warning ("UNSUPPORTED_CHARS_IN_PWD_RECOM");
1.1.1.5 root 2402:
1.1 root 2403: ret:
1.1.1.7 root 2404: burn (&VolumePassword, sizeof (VolumePassword));
2405: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2406: RestoreDefaultKeyFilesParam ();
1.1 root 2407: EnableDisableButtons (hwndDlg);
2408: NormalCursor();
1.1.1.7 root 2409:
2410: return status;
1.1 root 2411: }
2412:
2413: static void ChangePassword (HWND hwndDlg)
2414: {
2415: int result;
2416:
2417: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
2418: if (IsMountedVolume (szFileName))
2419: {
1.1.1.7 root 2420: Warning (pwdChangeDlgMode == PCDM_CHANGE_PKCS5_PRF ? "MOUNTED_NO_PKCS5_PRF_CHANGE" : "MOUNTED_NOPWCHANGE");
1.1 root 2421: return;
2422: }
2423:
1.1.1.7 root 2424: result = DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_PASSWORDCHANGE_DLG), hwndDlg,
1.1 root 2425: (DLGPROC) PasswordChangeDlgProc);
2426:
2427: if (result == IDOK)
2428: {
2429: HWND tmp = GetDlgItem (hwndDlg, IDC_PASSWORD);
1.1.1.7 root 2430:
2431: switch (pwdChangeDlgMode)
2432: {
2433: case PCDM_CHANGE_PKCS5_PRF:
2434: Info ("PKCS5_PRF_CHANGED");
2435: break;
2436:
2437: case PCDM_ADD_REMOVE_VOL_KEYFILES:
2438: case PCDM_REMOVE_ALL_KEYFILES_FROM_VOL:
2439: Info ("KEYFILE_CHANGED");
2440: break;
2441:
2442: case PCDM_CHANGE_PASSWORD:
2443: default:
2444: Info ("PASSWORD_CHANGED");
2445: }
1.1 root 2446: SetFocus (tmp);
2447: }
2448: }
2449:
2450: static void SelectContainer (HWND hwndDlg)
2451: {
1.1.1.8 root 2452: if (BrowseFiles (hwndDlg, "OPEN_VOL_TITLE", szFileName, bHistory, FALSE) == FALSE)
1.1 root 2453: return;
2454:
1.1.1.10! root 2455: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1 root 2456: EnableDisableButtons (hwndDlg);
1.1.1.6 root 2457: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1 root 2458: }
2459:
2460: static void SelectPartition (HWND hwndDlg)
2461: {
1.1.1.7 root 2462: int nResult = DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_RAWDEVICES_DLG), hwndDlg,
1.1 root 2463: (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
2464: if (nResult == IDOK)
2465: {
1.1.1.10! root 2466: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1 root 2467: EnableDisableButtons (hwndDlg);
1.1.1.6 root 2468: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
1.1 root 2469: }
2470: }
2471:
2472: static void WipeCache (HWND hwndDlg)
2473: {
2474: DWORD dwResult;
2475: BOOL bResult;
2476:
2477: bResult = DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
2478:
2479: if (bResult == FALSE)
2480: handleWin32Error (hwndDlg);
2481: else
2482: {
2483: EnableDisableButtons (hwndDlg);
2484:
1.1.1.7 root 2485: Info ("WIPE_CACHE");
1.1 root 2486: }
2487: }
2488:
1.1.1.5 root 2489: static void Benchmark (HWND hwndDlg)
2490: {
1.1.1.7 root 2491: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_BENCHMARK_DLG), hwndDlg,
1.1.1.5 root 2492: (DLGPROC) BenchmarkDlgProc, (LPARAM) NULL);
2493: }
1.1 root 2494:
1.1.1.7 root 2495:
2496: static BOOL CheckMountList ()
1.1 root 2497: {
1.1.1.7 root 2498: MOUNT_LIST_STRUCT current;
2499: GetMountList (¤t);
1.1 root 2500:
1.1.1.7 root 2501: if (LastKnownLogicalDrives != GetLogicalDrives()
2502: || memcmp (&LastKnownMountList, ¤t, sizeof (current)) != 0)
1.1 root 2503: {
1.1.1.7 root 2504: LastKnownMountList = current;
1.1 root 2505:
1.1.1.7 root 2506: ArrowWaitCursor ();
2507: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
1.1.1.2 root 2508:
1.1.1.7 root 2509: if (nSelectedDriveIndex >= 0)
2510: {
2511: SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),
2512: (char) HIWORD (GetItemLong (GetDlgItem (MainDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
2513: }
1.1 root 2514:
1.1.1.7 root 2515: NormalCursor ();
2516: return FALSE;
2517: }
1.1 root 2518:
1.1.1.7 root 2519: return TRUE;
2520: }
1.1.1.6 root 2521:
1.1 root 2522:
1.1.1.7 root 2523: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
2524: should return nonzero if it processes the message, and zero if it does
2525: not. - see DialogProc */
2526: BOOL CALLBACK
2527: MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
2528: {
2529: WORD lw = LOWORD (wParam);
2530: WORD hw = HIWORD (wParam);
2531: DWORD mPos;
1.1 root 2532:
1.1.1.7 root 2533: if (lParam); /* remove warning */
1.1 root 2534:
1.1.1.7 root 2535: switch (uMsg)
2536: {
2537: case WM_HOTKEY:
1.1 root 2538:
1.1.1.7 root 2539: HandleHotKey (hwndDlg, wParam);
2540: return 1;
1.1 root 2541:
1.1.1.7 root 2542: case WM_INITDIALOG:
2543: {
2544: int exitCode = 0;
2545: MainDlg = hwndDlg;
1.1 root 2546:
1.1.1.7 root 2547: // Set critical default options in case UsePreferences is false
2548: bPreserveTimestamp = defaultMountOptions.PreserveTimestamp = TRUE;
1.1 root 2549:
1.1.1.7 root 2550: ExtractCommandLine (hwndDlg, (char *) lParam);
2551:
2552: if (UsePreferences)
1.1 root 2553: {
1.1.1.7 root 2554: // General preferences
2555: LoadSettings (hwndDlg);
2556:
2557: // Keyfiles
2558: LoadDefaultKeyFilesParam ();
2559: RestoreDefaultKeyFilesParam ();
1.1 root 2560: }
2561:
1.1.1.7 root 2562: InitMainDialog (hwndDlg);
2563:
2564: // Wipe cache
2565: if (bWipe)
2566: WipeCache (hwndDlg);
2567:
1.1.1.2 root 2568: // Automount
1.1.1.7 root 2569: if (bAuto || (Quit && szFileName[0] != 0))
1.1 root 2570: {
1.1.1.5 root 2571: // No drive letter specified on command line
2572: if (commandLineDrive == 0)
2573: szDriveLetter[0] = GetFirstAvailableDrive () + 'A';
2574:
1.1.1.6 root 2575: if (bAutoMountDevices)
2576: {
2577: defaultMountOptions = mountOptions;
1.1.1.8 root 2578: if (FirstCmdKeyFile)
2579: {
2580: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
2581: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2582: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2583: }
2584:
1.1.1.7 root 2585: if (!MountAllDevices (hwndDlg, !Silent))
2586: exitCode = 1;
2587: }
2588:
2589: if (bAutoMountFavorites)
2590: {
2591: defaultMountOptions = mountOptions;
1.1.1.8 root 2592: if (FirstCmdKeyFile)
2593: {
2594: KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
2595: FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2596: defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
2597: }
2598:
1.1.1.7 root 2599: if (!MountFavoriteVolumes ())
2600: exitCode = 1;
1.1.1.6 root 2601: }
1.1.1.7 root 2602:
2603: if (szFileName[0] != 0 && !IsMountedVolume (szFileName))
1.1.1.2 root 2604: {
2605: BOOL mounted;
2606:
2607: // Cached password
1.1.1.7 root 2608: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, NULL, bCacheInDriver, bForceMount, &mountOptions, Silent, FALSE);
1.1.1.2 root 2609:
1.1.1.7 root 2610: // Command line password or keyfiles
2611: if (!mounted && (CmdVolumePassword.Length != 0 || FirstCmdKeyFile))
1.1.1.2 root 2612: {
1.1.1.7 root 2613: BOOL reportBadPasswd = CmdVolumePassword.Length > 0;
2614:
2615: if (FirstCmdKeyFile)
2616: KeyFilesApply (&CmdVolumePassword, FirstCmdKeyFile, bPreserveTimestamp);
2617:
2618: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A',
2619: szFileName, &CmdVolumePassword, bCacheInDriver, bForceMount,
2620: &mountOptions, Silent, reportBadPasswd);
2621:
2622: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
2623: }
2624:
2625: if (FirstCmdKeyFile)
2626: {
2627: FirstKeyFile = FirstCmdKeyFile;
2628: KeyFilesEnable = TRUE;
1.1.1.2 root 2629: }
2630:
2631: // Ask user for password
1.1.1.7 root 2632: while (!mounted && !Silent)
1.1.1.2 root 2633: {
1.1.1.7 root 2634: VolumePassword.Length = 0;
1.1.1.2 root 2635:
1.1.1.7 root 2636: strcpy (PasswordDlgVolume, szFileName);
2637: if (!AskUserPassword (hwndDlg, &VolumePassword))
1.1.1.2 root 2638: break;
2639:
2640: ArrowWaitCursor ();
1.1.1.7 root 2641:
2642: if (KeyFilesEnable && FirstKeyFile)
2643: KeyFilesApply (&VolumePassword, FirstKeyFile, bPreserveTimestamp);
2644:
2645: mounted = MountVolume (hwndDlg, szDriveLetter[0] - 'A', szFileName, &VolumePassword, bCacheInDriver, bForceMount, &mountOptions, FALSE, TRUE);
2646:
2647: burn (&VolumePassword, sizeof (VolumePassword));
2648: burn (&mountOptions.ProtectedHidVolPassword, sizeof (mountOptions.ProtectedHidVolPassword));
2649:
1.1.1.2 root 2650: NormalCursor ();
2651: }
2652:
1.1.1.7 root 2653: if (UsePreferences)
2654: RestoreDefaultKeyFilesParam ();
2655:
1.1.1.5 root 2656: if (mounted > 0)
1.1.1.2 root 2657: {
1.1.1.7 root 2658: if (bBeep) MessageBeep (-1);
2659: if (bExplore) OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
2660: RefreshMainDlg(hwndDlg);
1.1.1.2 root 2661: }
1.1.1.7 root 2662: else
2663: exitCode = 1;
1.1.1.2 root 2664: }
1.1.1.7 root 2665: else if (bExplore)
2666: OpenVolumeExplorerWindow (szDriveLetter[0] - 'A');
1.1.1.10! root 2667: else if (szFileName[0] != 0 && IsMountedVolume (szFileName))
! 2668: Warning ("ALREADY_MOUNTED");
! 2669:
1.1.1.8 root 2670: if (!Quit)
2671: RefreshMainDlg(hwndDlg);
1.1.1.7 root 2672: }
2673:
2674: // Wipe command line password
2675: if (CmdVolumePassword.Length != 0)
2676: {
2677: burn (&CmdVolumePassword, sizeof (CmdVolumePassword));
2678: CmdVolumePassword.Length = 0;
1.1 root 2679: }
2680:
1.1.1.7 root 2681: // Wipe command line keyfiles
2682: if (FirstCmdKeyFile)
1.1.1.8 root 2683: {
2684: if (defaultKeyFilesParam.FirstKeyFile)
2685: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
2686:
2687: defaultKeyFilesParam.EnableKeyFiles = FALSE;
2688:
1.1.1.10! root 2689: if (!Quit)
! 2690: {
! 2691: LoadSettings (hwndDlg);
! 2692: LoadDefaultKeyFilesParam ();
! 2693: RestoreDefaultKeyFilesParam ();
! 2694: }
1.1.1.8 root 2695: }
1.1.1.7 root 2696:
2697: // Dismount
1.1.1.5 root 2698: if (cmdUnmountDrive > 0)
1.1.1.7 root 2699: {
2700: if (!Dismount (hwndDlg, (char)toupper(szDriveLetter[0]) - 'A'))
2701: exitCode = 1;
2702: }
1.1.1.5 root 2703: else if (cmdUnmountDrive == -1)
1.1.1.7 root 2704: {
2705: if (!DismountAll (hwndDlg, bForceUnmount, !Silent, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY))
2706: exitCode = 1;
2707: }
1.1.1.5 root 2708:
1.1.1.7 root 2709: // TaskBar icon
2710: if (bEnableBkgTask)
2711: {
2712: TaskBarIconAdd (hwndDlg);
2713: if (Quit && TaskBarIconMutex != NULL)
2714: MainWindowHidden = TRUE;
2715: }
2716:
2717: // Quit
2718: if (Quit && TaskBarIconMutex == NULL)
2719: exit (exitCode);
2720:
1.1.1.8 root 2721: // No command line arguments or only /volume => bring active instance
2722: // to foreground if available
2723: if (NoCmdLineArgs == 0 || (CmdLineVolumeSpecified && NoCmdLineArgs <= 2))
2724: {
2725: HWND h = hwndDlg;
2726: EnumWindows (FindTCWindowEnum, (LPARAM) &h);
2727:
2728: if (h != hwndDlg)
2729: {
2730: if (CmdLineVolumeSpecified)
2731: {
2732: COPYDATASTRUCT cd;
2733: memcpy (&cd.dwData, WM_COPY_SET_VOLUME_NAME, 4);
2734: cd.lpData = szFileName;
2735: cd.cbData = strlen (szFileName) + 1;
2736:
2737: SendMessage (h, WM_COPYDATA, (WPARAM)hwndDlg, (LPARAM)&cd);
2738: }
2739:
2740: SendMessage (h, WM_APP + APP_MESSAGE_SHOW_WINDOW, 0, 0);
2741:
2742: ShowWindow (h, SW_SHOW);
2743: SetForegroundWindow (h);
2744: exit (0);
2745: }
2746: }
2747:
1.1.1.7 root 2748: Silent = FALSE;
2749:
2750: GetMountList (&LastKnownMountList);
2751: SetTimer (hwndDlg, 1, MAIN_TIMER_INTERVAL, NULL);
1.1.1.3 root 2752:
1.1 root 2753: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
2754: }
2755: return 0;
2756:
1.1.1.7 root 2757: case WM_WINDOWPOSCHANGING:
2758: if (MainWindowHidden)
2759: {
2760: PWINDOWPOS wp = (PWINDOWPOS)lParam;
2761: wp->flags &= ~SWP_SHOWWINDOW;
2762: return 0;
2763: }
2764: return 1;
2765:
1.1 root 2766: case WM_SYSCOMMAND:
2767: if (lw == IDC_ABOUT)
2768: {
1.1.1.7 root 2769: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 2770: return 1;
2771: }
2772: return 0;
2773:
2774: case WM_HELP:
1.1.1.7 root 2775: OpenPageHelp (hwndDlg, 0);
1.1 root 2776: return 1;
2777:
1.1.1.7 root 2778: case WM_ENDSESSION:
2779: if (TaskBarIconMutex != NULL)
1.1 root 2780: {
1.1.1.7 root 2781: if (bDismountOnLogOff)
2782: {
2783: // Auto-dismount when user logs off
2784: DWORD dwResult;
2785:
2786: if (bWipeCacheOnAutoDismount)
2787: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
2788:
2789: if (!DismountAll (hwndDlg, FALSE, FALSE, 5, 1000))
2790: {
2791: if (bForceAutoDismount)
2792: DismountAll (hwndDlg, TRUE, FALSE, 1, 0);
2793: else
2794: DismountAll (hwndDlg, FALSE, TRUE, 1, 0);
2795: }
2796: }
2797:
2798: TaskBarIconRemove (hwndDlg);
2799: }
2800: return 0;
2801:
2802: case WM_POWERBROADCAST:
2803: if (wParam == PBT_APMSUSPEND
2804: && TaskBarIconMutex != NULL && bDismountOnPowerSaving)
2805: {
2806: // Auto-dismount when entering power-saving mode
2807: DWORD dwResult;
2808: DismountAll (hwndDlg, bForceAutoDismount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
2809:
2810: if (bWipeCacheOnAutoDismount)
2811: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
2812: }
2813: return 0;
2814:
2815: case WM_TIMER:
2816: {
1.1.1.8 root 2817: MainWindowHidden = !IsWindowVisible (hwndDlg);
2818:
1.1.1.7 root 2819: // Check mount list and update GUI if needed
2820: CheckMountList ();
2821:
2822: // Cache status
2823: if (IsPasswordCacheEmpty() == IsWindowEnabled (GetDlgItem (hwndDlg, IDC_WIPE_CACHE)))
2824: EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
2825:
2826: if (TaskBarIconMutex != NULL)
2827: {
2828: // Idle auto-dismount
2829: if (MaxVolumeIdleTime > 0)
2830: DismountIdleVolumes ();
2831:
2832: // Screen saver auto-dismount
2833: if (bDismountOnScreenSaver)
2834: {
2835: static BOOL previousState = FALSE;
2836: BOOL running = FALSE;
2837: SystemParametersInfo (SPI_GETSCREENSAVERRUNNING, 0, &running, 0);
2838:
2839: if (running && !previousState)
2840: {
2841: DWORD dwResult;
2842: previousState = TRUE;
2843: DismountAll (hwndDlg, bForceAutoDismount, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
2844:
2845: if (bWipeCacheOnAutoDismount)
2846: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
2847: }
2848: else
2849: {
2850: previousState = running;
1.1.1.8 root 2851: }
1.1.1.7 root 2852: }
2853: }
2854:
1.1.1.8 root 2855: // Exit background process in non-install mode or if no volume mounted
1.1.1.7 root 2856: // and no other instance active
2857: if (LastKnownMountList.ulMountedDrives == 0
1.1.1.8 root 2858: && !IsWindowVisible (hwndDlg)
1.1.1.7 root 2859: #ifndef _DEBUG
2860: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
2861: #endif
2862: && GetDriverRefCount () < 2)
2863: {
2864: TaskBarIconRemove (hwndDlg);
2865: EndMainDlg (hwndDlg);
2866: }
1.1 root 2867:
2868: return 1;
2869: }
2870:
1.1.1.8 root 2871: case WM_APP + MSG_TASKBAR_ICON:
1.1 root 2872: {
1.1.1.7 root 2873: switch (lParam)
2874: {
2875: case WM_LBUTTONDOWN:
1.1.1.8 root 2876: SetForegroundWindow (hwndDlg);
1.1.1.7 root 2877: MainWindowHidden = FALSE;
2878: ShowWindow (hwndDlg, SW_SHOW);
2879: break;
2880:
2881: case WM_RBUTTONDOWN:
2882: {
2883: POINT pos;
2884: HMENU popup = CreatePopupMenu ();
2885: int sel, i, n;
1.1.1.8 root 2886:
2887: MainWindowHidden = !IsWindowVisible (hwndDlg);
1.1.1.7 root 2888: if (MainWindowHidden)
2889: {
2890: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
2891: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
2892: }
2893: else if (bEnableBkgTask
2894: && (!(LastKnownMountList.ulMountedDrives == 0
2895: && (bCloseBkgTaskWhenNoVolumes || IsNonInstallMode ())
2896: && GetDriverRefCount () < 2)))
2897: {
2898: AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
2899: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
2900: }
2901: AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
2902: AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDM_UNMOUNTALL"));
2903: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
2904:
2905: for (n = 0; n < 2; n++)
2906: {
2907: for (i = 0; i < 26; i++)
2908: {
2909: if (LastKnownMountList.ulMountedDrives & (1 << i))
2910: {
2911: wchar_t s[1024];
2912: wchar_t *vol = LastKnownMountList.wszVolume[i];
2913:
2914: if (wcsstr (vol, L"\\??\\")) vol += 4;
2915:
2916: wsprintfW (s, L"%s %c: (%s)",
2917: GetString (n==0 ? "OPEN" : "DISMOUNT"),
2918: i + L'A',
2919: vol);
2920: AppendMenuW (popup, MF_STRING, n*26 + 9000 + i, s);
2921: }
2922: }
2923: if (LastKnownMountList.ulMountedDrives != 0)
2924: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
2925: }
2926:
2927: AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
2928: AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE, GetString ("HOMEPAGE"));
2929: AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
2930: AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
2931: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
2932: AppendMenuW (popup, MF_STRING, IDM_EXIT, GetString ("IDM_EXIT"));
2933:
2934: GetCursorPos (&pos);
2935:
2936: SetForegroundWindow(hwndDlg);
2937:
2938: sel = TrackPopupMenu (popup,
2939: TPM_RETURNCMD | TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
2940: pos.x,
2941: pos.y,
2942: 0,
2943: hwndDlg,
2944: NULL);
2945:
2946: if (sel >= 9000 && sel < 9026)
2947: {
2948: OpenVolumeExplorerWindow (sel - 9000);
2949: }
2950: else if (sel >= 9026 && sel < 9052)
2951: {
2952: if (CheckMountList ())
2953: Dismount (hwndDlg, sel - 9026);
2954: }
2955: else if (sel == IDM_SHOW_HIDE)
2956: {
2957: MainWindowHidden = !MainWindowHidden;
2958: ShowWindow (hwndDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
2959: }
2960: else if (sel == IDM_EXIT)
2961: {
2962: if (LastKnownMountList.ulMountedDrives == 0
2963: || AskWarnNoYes ("CONFIRM_EXIT") == IDYES)
2964: {
2965: // Close all other TC windows
2966: EnumWindows (CloseTCWindowsEnum, 0);
2967:
2968: TaskBarIconRemove (hwndDlg);
2969: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
2970: }
2971: }
2972: else
2973: {
2974: SendMessage (hwndDlg, WM_COMMAND, sel, 0);
2975: }
2976:
2977: PostMessage(hwndDlg, WM_NULL, 0, 0);
2978: DestroyMenu (popup);
2979: }
1.1 root 2980: }
1.1.1.7 root 2981: return 1;
2982: }
2983:
2984: case WM_NOTIFY:
2985:
2986: if(wParam == IDC_DRIVELIST)
2987: {
2988: /* Single click within drive list */
2989: if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
2990: {
2991: nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
2992: EnableDisableButtons (hwndDlg);
2993: return 1;
2994: }
2995:
2996: /* Double click within drive list */
2997: if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
1.1 root 2998: {
1.1.1.7 root 2999: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
3000: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
3001: if (LOWORD(state) == VMOUNTED)
3002: {
3003: // Open explorer window for mounted volume
3004: ArrowWaitCursor ();
3005: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
3006: NormalCursor ();
3007: }
3008: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
3009: {
1.1.1.9 root 3010: if (GetAsyncKeyState (VK_CONTROL) < 0)
3011: {
3012: if (IDCANCEL == DialogBoxParamW (hInst,
3013: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
3014: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
3015: return 1;
3016:
3017: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
3018: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile, bPreserveTimestamp);
3019: }
3020:
1.1.1.7 root 3021: if (CheckMountList ())
3022: Mount (hwndDlg, 0, 0);
3023: }
3024: return 1;
3025: }
3026:
3027: /* Right click and drag&drop operations */
3028: switch(((NM_LISTVIEW *) lParam)->hdr.code)
3029: {
3030: case NM_RCLICK:
3031: case LVN_BEGINRDRAG:
3032: /* If the mouse was moving while the right mouse button is pressed, popup menu would
3033: not open, because drag&drop operation would be initiated. Therefore, we're handling
3034: RMB drag-and-drop operations as well. */
3035: {
3036:
3037: /* Drive list context menu */
3038:
3039: int menuItem;
3040: HMENU popup = CreatePopupMenu ();
3041:
3042: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3043:
3044: if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
3045: {
3046: // No mounted volume at this drive letter
3047: AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
3048: }
3049: else
3050: {
3051: // There's a mounted volume at this drive letter
3052: AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
3053: AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
3054: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3055: AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
3056: AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
3057: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3058: AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
3059: }
3060:
3061: mPos=GetMessagePos();
3062:
3063: menuItem = TrackPopupMenu (popup,
3064: TPM_RETURNCMD | TPM_LEFTBUTTON,
3065: GET_X_LPARAM(mPos),
3066: GET_Y_LPARAM(mPos),
3067: 0,
3068: hwndDlg,
3069: NULL);
3070:
3071: DestroyMenu (popup);
3072:
3073: switch (menuItem)
3074: {
3075: case IDPM_CHECK_FILESYS:
3076: case IDPM_REPAIR_FILESYS:
3077: {
3078: LPARAM lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3079:
3080: if (LOWORD (lLetter) != 0xffff)
3081: {
3082: wchar_t msg[1024], param[1024];
3083: char szTmp[32] = {0};
3084:
3085: sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
3086:
3087: wsprintfW (msg,
3088: GetString (menuItem == IDPM_REPAIR_FILESYS ? "REPAIRING_FS" : "CHECKING_FS")
3089: , szTmp);
3090:
3091: wsprintfW (param,
3092: menuItem == IDPM_REPAIR_FILESYS ?
1.1.1.8 root 3093: L"/C echo %s && (chkdsk %hs /F /X || set X=0) && pause"
3094: : L"/C echo %s && (chkdsk %hs || set X=0) && pause",
1.1.1.7 root 3095: msg,
1.1.1.8 root 3096: szTmp);
1.1.1.7 root 3097:
3098: ShellExecuteW (NULL, L"open", L"cmd.exe", param, NULL, SW_SHOW);
3099: }
3100: }
3101: break;
3102:
3103: case IDM_UNMOUNT_VOLUME:
3104: if (CheckMountList ())
3105: Dismount (hwndDlg, 0);
3106: break;
3107:
3108: case IDPM_OPEN_VOLUME:
3109: {
3110: int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
3111: nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
3112:
3113: ArrowWaitCursor ();
3114: OpenVolumeExplorerWindow (HIWORD(state) - 'A');
3115: NormalCursor ();
3116: }
3117: break;
3118:
3119: case IDM_VOLUME_PROPERTIES:
3120: DialogBoxParamW (hInst,
3121: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
3122: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
3123: break;
3124:
3125: case IDM_MOUNT_VOLUME:
3126: if (!VolumeSelected(hwndDlg))
3127: {
3128: Warning ("NO_VOLUME_SELECTED");
3129: }
3130: else
3131: {
3132: mountOptions = defaultMountOptions;
3133:
3134: if (CheckMountList ())
3135: Mount (hwndDlg, 0, 0);
3136: }
3137: break;
3138: }
3139: return 1;
3140: }
1.1 root 3141: }
3142: }
3143: return 0;
3144:
3145: case WM_ERASEBKGND:
3146: return 0;
3147:
3148: case WM_COMMAND:
3149:
1.1.1.7 root 3150: if (lw == IDCANCEL || lw == IDC_EXIT || lw == IDM_EXIT)
1.1 root 3151: {
3152: EndMainDlg (hwndDlg);
3153: return 1;
3154: }
3155:
3156: if (lw == IDHELP || lw == IDM_HELP)
3157: {
1.1.1.7 root 3158: OpenPageHelp (hwndDlg, 0);
1.1 root 3159: return 1;
3160: }
3161:
3162: if (lw == IDM_ABOUT || lw == IDB_LOGO)
3163: {
1.1.1.7 root 3164: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
1.1 root 3165: return 1;
3166: }
3167:
1.1.1.7 root 3168: if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VMOUNTED
3169: || lw == IDM_UNMOUNT_VOLUME)
1.1 root 3170: {
1.1.1.7 root 3171: if (lw == IDM_UNMOUNT_VOLUME && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) != VMOUNTED)
1.1.1.6 root 3172: {
1.1.1.7 root 3173: Warning ("SELECT_A_MOUNTED_VOLUME");
3174: return 1;
1.1.1.6 root 3175: }
1.1 root 3176:
1.1.1.7 root 3177: if (CheckMountList ())
3178: Dismount (hwndDlg, 0);
1.1 root 3179: return 1;
3180: }
3181:
1.1.1.7 root 3182: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS || lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 3183: && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
3184: {
1.1.1.7 root 3185: MessageBoxW (hwndDlg, GetString ("SELECT_FREE_DRIVE"), L"TrueCrypt", MB_ICONEXCLAMATION);
1.1 root 3186: return 1;
3187: }
3188:
1.1.1.7 root 3189: if ((lw == IDOK || lw == IDM_MOUNT_VOLUME || lw == IDM_MOUNT_VOLUME_OPTIONS))
1.1 root 3190: {
1.1.1.7 root 3191: if (!VolumeSelected(hwndDlg))
3192: {
3193: Warning ("NO_VOLUME_SELECTED");
3194: }
3195: else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
3196: {
3197: mountOptions = defaultMountOptions;
3198:
3199: if (lw == IDM_MOUNT_VOLUME_OPTIONS || GetAsyncKeyState (VK_CONTROL) < 0)
3200: {
3201: if (IDCANCEL == DialogBoxParamW (hInst,
3202: MAKEINTRESOURCEW (IDD_MOUNT_OPTIONS), hwndDlg,
3203: (DLGPROC) MountOptionsDlgProc, (LPARAM) &mountOptions))
3204: return 1;
3205:
3206: if (mountOptions.ProtectHiddenVolume && hidVolProtKeyFilesParam.EnableKeyFiles)
3207: KeyFilesApply (&mountOptions.ProtectedHidVolPassword, hidVolProtKeyFilesParam.FirstKeyFile, bPreserveTimestamp);
3208: }
3209:
3210: if (CheckMountList ())
3211: Mount (hwndDlg, 0, 0);
3212: }
1.1 root 3213: return 1;
3214: }
3215:
1.1.1.7 root 3216: if (lw == IDC_UNMOUNTALL || lw == IDM_UNMOUNTALL)
1.1 root 3217: {
1.1.1.7 root 3218: DismountAll (hwndDlg, bForceUnmount, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
1.1 root 3219: return 1;
3220: }
3221:
1.1.1.7 root 3222: if (lw == IDC_MOUNTALL || lw == IDM_MOUNTALL)
1.1 root 3223: {
1.1.1.7 root 3224: // If Shift key is down and the password cache isn't empty, bypass password prompt
3225: MountAllDevices (hwndDlg, !(GetAsyncKeyState (VK_SHIFT) < 0 && !IsPasswordCacheEmpty()));
1.1 root 3226: return 1;
3227: }
3228:
1.1.1.7 root 3229: if (lw == IDC_SELECT_FILE || lw == IDM_SELECT_FILE)
1.1 root 3230: {
3231: SelectContainer (hwndDlg);
3232: return 1;
3233: }
3234:
1.1.1.7 root 3235: if (lw == IDC_SELECT_DEVICE || lw == IDM_SELECT_DEVICE)
1.1 root 3236: {
3237: SelectPartition (hwndDlg);
3238: return 1;
3239: }
3240:
1.1.1.7 root 3241: if (lw == IDC_VOLUME_TOOLS)
3242: {
3243: int menuItem;
3244: char volPath[TC_MAX_PATH]; /* Volume to mount */
3245: HMENU popup = CreatePopupMenu ();
3246: RECT rect;
3247:
3248: AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
3249: AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
3250: AppendMenu (popup, MF_SEPARATOR, 0, NULL);
3251: AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
3252: AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
3253:
3254: GetWindowRect (GetDlgItem (hwndDlg, IDC_VOLUME_TOOLS), &rect);
3255:
3256: menuItem = TrackPopupMenu (popup,
3257: TPM_RETURNCMD | TPM_LEFTBUTTON,
3258: rect.left + 2,
3259: rect.top + 2,
3260: 0,
3261: hwndDlg,
3262: NULL);
3263:
3264: DestroyMenu (popup);
3265:
3266: switch (menuItem)
3267: {
3268: case IDM_CHANGE_PASSWORD:
3269: if (!VolumeSelected(hwndDlg))
3270: {
3271: Warning ("NO_VOLUME_SELECTED");
3272: }
3273: else
3274: {
3275: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
3276: ChangePassword (hwndDlg);
3277: }
3278: break;
3279:
3280: case IDM_CHANGE_HEADER_KEY_DERIV_ALGO:
3281: if (!VolumeSelected(hwndDlg))
3282: {
3283: Warning ("NO_VOLUME_SELECTED");
3284: }
3285: else
3286: {
3287: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
3288: ChangePassword (hwndDlg);
3289: }
3290: break;
3291:
3292: case IDM_BACKUP_VOL_HEADER:
3293: if (!VolumeSelected(hwndDlg))
3294: {
3295: Warning ("NO_VOLUME_SELECTED");
3296: }
3297: else
3298: {
3299: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3300:
3301: if (BackupVolumeHeader (hwndDlg, TRUE, volPath) != 0)
3302: handleWin32Error (hwndDlg);
3303: }
3304: break;
3305:
3306: case IDM_RESTORE_VOL_HEADER:
3307: if (!VolumeSelected(hwndDlg))
3308: {
3309: Warning ("NO_VOLUME_SELECTED");
3310: }
3311: else
3312: {
3313: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3314:
3315: if (RestoreVolumeHeader (hwndDlg, volPath) != 0)
3316: handleWin32Error (hwndDlg);
3317: }
3318: break;
3319: }
3320: return 1;
3321: }
3322:
3323: if (lw == IDM_CHANGE_PASSWORD)
1.1 root 3324: {
1.1.1.7 root 3325: if (!VolumeSelected(hwndDlg))
3326: {
3327: Warning ("NO_VOLUME_SELECTED");
3328: }
3329: else
3330: {
3331: pwdChangeDlgMode = PCDM_CHANGE_PASSWORD;
3332: ChangePassword (hwndDlg);
3333: }
1.1 root 3334: return 1;
3335: }
3336:
1.1.1.7 root 3337: if (lw == IDM_CHANGE_HEADER_KEY_DERIV_ALGO)
3338: {
3339: if (!VolumeSelected(hwndDlg))
3340: {
3341: Warning ("NO_VOLUME_SELECTED");
3342: }
3343: else
3344: {
3345: pwdChangeDlgMode = PCDM_CHANGE_PKCS5_PRF;
3346: ChangePassword (hwndDlg);
3347: }
3348: return 1;
3349: }
3350:
3351: if (lw == IDC_WIPE_CACHE || lw == IDM_WIPE_CACHE)
1.1 root 3352: {
3353: WipeCache (hwndDlg);
3354: return 1;
3355: }
3356:
1.1.1.7 root 3357: if (lw == IDM_CLEAR_HISTORY)
1.1 root 3358: {
3359: ClearCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.7 root 3360: DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), TRUE);
1.1 root 3361: EnableDisableButtons (hwndDlg);
3362: return 1;
3363: }
3364:
1.1.1.7 root 3365: if (lw == IDC_CREATE_VOLUME || lw == IDM_CREATE_VOLUME || lw == IDM_VOLUME_WIZARD)
1.1 root 3366: {
3367: char t[TC_MAX_PATH];
3368: char *tmp;
1.1.1.7 root 3369: FILE *fhTemp;
1.1 root 3370:
3371: GetModuleFileName (NULL, t, sizeof (t));
1.1.1.7 root 3372:
1.1 root 3373: tmp = strrchr (t, '\\');
3374: if (tmp)
3375: {
1.1.1.9 root 3376: STARTUPINFO si;
3377: PROCESS_INFORMATION pi;
3378: ZeroMemory (&si, sizeof (si));
3379:
1.1 root 3380: strcpy (++tmp, "TrueCrypt Format.exe");
1.1.1.7 root 3381:
3382: if ((fhTemp = fopen(t, "r")) == NULL)
3383: Error ("VOL_CREATION_WIZARD_NOT_FOUND");
3384: else
3385: fclose (fhTemp);
3386:
1.1.1.9 root 3387: if (!CreateProcess (t, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
3388: {
3389: handleWin32Error (hwndDlg);
3390: }
3391: else
3392: {
3393: CloseHandle (pi.hProcess);
3394: CloseHandle (pi.hThread);
3395: }
1.1 root 3396: }
3397: return 1;
3398: }
3399:
1.1.1.7 root 3400: if (lw == IDM_ADD_REMOVE_VOL_KEYFILES)
1.1.1.3 root 3401: {
1.1.1.7 root 3402: if (!VolumeSelected(hwndDlg))
3403: {
3404: Warning ("NO_VOLUME_SELECTED");
3405: }
3406: else
3407: {
3408: pwdChangeDlgMode = PCDM_ADD_REMOVE_VOL_KEYFILES;
3409: ChangePassword (hwndDlg);
3410: }
3411: return 1;
3412: }
1.1.1.3 root 3413:
1.1.1.7 root 3414: if (lw == IDM_REMOVE_ALL_KEYFILES_FROM_VOL)
3415: {
3416: if (!VolumeSelected(hwndDlg))
1.1.1.3 root 3417: {
1.1.1.7 root 3418: Warning ("NO_VOLUME_SELECTED");
3419: }
3420: else
3421: {
3422: pwdChangeDlgMode = PCDM_REMOVE_ALL_KEYFILES_FROM_VOL;
3423: ChangePassword (hwndDlg);
1.1.1.3 root 3424: }
3425: return 1;
3426: }
1.1.1.7 root 3427:
3428: if (lw == IDM_GENERATE_KEYFILE || lw == IDM_KEYFILE_GENERATOR)
3429: {
3430: DialogBoxParamW (hInst,
3431: MAKEINTRESOURCEW (IDD_KEYFILE_GENERATOR), hwndDlg,
3432: (DLGPROC) KeyfileGeneratorDlgProc, (LPARAM) 0);
3433:
3434: return 1;
3435: }
3436:
3437: if (lw == IDM_LICENSE)
3438: {
3439: //char t[TC_MAX_PATH];
3440: //char *tmp;
3441:
3442: //GetModuleFileName (NULL, t, sizeof (t));
3443: //tmp = strrchr (t, '\\');
3444: //if (tmp)
3445: //{
3446: // strcpy (++tmp, "License.txt");
3447: // ShellExecute (NULL, "open", t, NULL, NULL, SW_SHOWNORMAL);
3448: //}
3449: DialogBoxW (hInst, MAKEINTRESOURCEW (IDD_LEGAL_NOTICES_DLG), hwndDlg, (DLGPROC) LegalNoticesDlgProc);
3450: return 1;
3451: }
1.1.1.3 root 3452:
1.1.1.7 root 3453: if (lw == IDM_WEBSITE || lw == IDM_HOMEPAGE)
3454: {
3455: char tmpstr [256];
3456:
3457: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s", VERSION_STRING);
3458: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3459: return 1;
3460: }
3461: else if (lw == IDM_FORUMS)
1.1 root 3462: {
1.1.1.5 root 3463: char tmpstr [256];
3464:
1.1.1.7 root 3465: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=forum", VERSION_STRING);
1.1.1.5 root 3466: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3467: return 1;
3468: }
1.1.1.9 root 3469: else if (lw == IDM_ONLINE_TUTORIAL)
3470: {
3471: char tmpstr [256];
3472:
3473: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=tutorial", VERSION_STRING);
3474: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3475: return 1;
3476: }
3477: else if (lw == IDM_ONLINE_HELP)
3478: {
1.1.1.10! root 3479: OpenOnlineHelp ();
1.1.1.9 root 3480: return 1;
3481: }
1.1.1.7 root 3482: else if (lw == IDM_FAQ)
3483: {
3484: char tmpstr [256];
1.1.1.5 root 3485:
1.1.1.7 root 3486: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=faq", VERSION_STRING);
3487: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3488: return 1;
3489: }
3490: else if (lw == IDM_TC_DOWNLOADS)
1.1.1.5 root 3491: {
3492: char tmpstr [256];
3493:
1.1.1.7 root 3494: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=downloads", VERSION_STRING);
1.1.1.5 root 3495: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
1.1 root 3496: return 1;
3497: }
1.1.1.7 root 3498: else if (lw == IDM_NEWS)
3499: {
3500: char tmpstr [256];
1.1.1.3 root 3501:
1.1.1.7 root 3502: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=news", VERSION_STRING);
3503: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3504: return 1;
3505: }
3506: else if (lw == IDM_VERSION_HISTORY)
1.1.1.6 root 3507: {
3508: char tmpstr [256];
3509:
1.1.1.7 root 3510: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=history", VERSION_STRING);
1.1.1.6 root 3511: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3512: return 1;
3513: }
1.1.1.7 root 3514: else if (lw == IDM_BUGREPORT)
3515: {
3516: char tmpstr [256];
1.1.1.6 root 3517:
1.1.1.7 root 3518: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=bugreport", VERSION_STRING);
3519: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3520: return 1;
3521: }
3522: else if (lw == IDM_CONTACT)
1.1 root 3523: {
1.1.1.7 root 3524: char tmpstr [256];
3525:
3526: sprintf (tmpstr, "http://www.truecrypt.org/applink.php?version=%s&dest=contact", VERSION_STRING);
3527: ShellExecute (NULL, "open", (LPCTSTR) tmpstr, NULL, NULL, SW_SHOWNORMAL);
3528: return 1;
3529: }
3530:
3531: if (lw == IDM_PREFERENCES)
3532: {
3533: if (IDOK == DialogBoxParamW (hInst,
3534: MAKEINTRESOURCEW (IDD_PREFERENCES_DLG), hwndDlg,
3535: (DLGPROC) PreferencesDlgProc, (LPARAM) 0))
3536: {
3537: if (bEnableBkgTask)
3538: TaskBarIconAdd (hwndDlg);
3539: else
3540: TaskBarIconRemove (hwndDlg);
3541: }
3542: return 1;
3543: }
3544:
3545: if (lw == IDM_HOTKEY_SETTINGS)
3546: {
3547: DialogBoxParamW (hInst,
3548: MAKEINTRESOURCEW (IDD_HOTKEYS_DLG), hwndDlg,
3549: (DLGPROC) HotkeysDlgProc, (LPARAM) 0);
3550: return 1;
3551: }
3552:
3553: if (lw == IDM_DEFAULT_KEYFILES || lw == IDM_SET_DEFAULT_KEYFILES)
3554: {
3555: KeyfileDefaultsDlg (hwndDlg);
1.1 root 3556: return 1;
3557: }
3558:
1.1.1.7 root 3559: if (lw == IDM_BENCHMARK)
1.1.1.5 root 3560: {
3561: Benchmark (hwndDlg);
3562: return 1;
3563: }
3564:
1.1.1.6 root 3565: if (lw == IDM_TRAVELLER)
3566: {
1.1.1.7 root 3567: DialogBoxParamW (hInst,
3568: MAKEINTRESOURCEW (IDD_TRAVELLER_DLG), hwndDlg,
1.1.1.6 root 3569: (DLGPROC) TravellerDlgProc, (LPARAM) 0);
3570: return 1;
3571: }
3572:
1.1.1.7 root 3573: if (lw == IDM_BACKUP_VOL_HEADER)
3574: {
3575: if (!VolumeSelected(hwndDlg))
3576: {
3577: Warning ("NO_VOLUME_SELECTED");
3578: }
3579: else
3580: {
3581: char volPath[TC_MAX_PATH]; /* Volume to mount */
3582:
3583: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3584:
3585: if (BackupVolumeHeader (hwndDlg, TRUE, volPath) != 0)
3586: handleWin32Error (hwndDlg);
3587: }
3588: return 1;
3589: }
3590:
3591: if (lw == IDM_RESTORE_VOL_HEADER)
3592: {
3593: if (!VolumeSelected(hwndDlg))
3594: {
3595: Warning ("NO_VOLUME_SELECTED");
3596: }
3597: else
3598: {
3599: char volPath[TC_MAX_PATH]; /* Volume to mount */
3600:
3601: GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), volPath, sizeof (volPath));
3602:
3603: if (RestoreVolumeHeader (hwndDlg, volPath) != 0)
3604: handleWin32Error (hwndDlg);
3605: }
3606: return 1;
3607: }
3608:
3609: if (lw == IDM_LANGUAGE)
3610: {
3611: BOOL p;
3612: if (DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_LANGUAGE), hwndDlg,
3613: (DLGPROC) LanguageDlgProc, (LPARAM) 0) == IDOK)
3614: {
3615: LoadLanguageFile ();
3616: SaveSettings (hwndDlg);
3617:
3618: p = LocalizationActive;
3619: LocalizationActive = TRUE;
3620: InitMainDialog (hwndDlg);
3621: InvalidateRect (hwndDlg, NULL, FALSE);
3622: LocalizationActive = p;
3623: DrawMenuBar (hwndDlg);
3624: }
3625: return 1;
3626: }
3627:
3628: if (lw == IDM_TEST_VECTORS)
3629: {
3630: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_CIPHER_TEST_DLG), hwndDlg, (DLGPROC) CipherTestDialogProc, (LPARAM) 1);
3631:
3632: return 1;
3633: }
3634:
1.1.1.6 root 3635: if (lw == IDM_REFRESH_DRIVE_LETTERS)
3636: {
3637: DWORD driveMap = GetLogicalDrives ();
3638:
3639: ArrowWaitCursor ();
1.1.1.7 root 3640:
1.1.1.10! root 3641: if (!(nCurrentOS == WIN_2000 && RemoteSession))
! 3642: {
! 3643: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, 0, ~driveMap);
! 3644: Sleep (100);
! 3645: BroadcastDeviceChange (DBT_DEVICEARRIVAL, 0, driveMap);
! 3646: }
1.1.1.7 root 3647:
1.1.1.6 root 3648: LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), 0);
1.1.1.7 root 3649:
3650: if (nSelectedDriveIndex >= 0)
3651: {
3652: SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST),
3653: (char) HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), nSelectedDriveIndex)));
3654: }
3655:
1.1.1.6 root 3656: NormalCursor ();
1.1.1.7 root 3657: return 1;
3658: }
3659:
3660: if (lw == IDM_MOUNT_FAVORITE_VOLUMES)
3661: {
3662: MountFavoriteVolumes ();
3663: return 1;
3664: }
3665:
3666: if (lw == IDM_SAVE_FAVORITE_VOLUMES)
3667: {
3668: SaveFavoriteVolumes ();
3669: return 1;
1.1.1.6 root 3670: }
1.1.1.5 root 3671:
1.1.1.7 root 3672: if (lw == IDC_VOLUME_PROPERTIES || lw == IDM_VOLUME_PROPERTIES)
1.1 root 3673: {
1.1.1.7 root 3674: DialogBoxParamW (hInst,
3675: MAKEINTRESOURCEW (IDD_VOLUME_PROPERTIES), hwndDlg,
1.1 root 3676: (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
3677: return 1;
3678: }
3679:
3680: if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
3681: {
1.1.1.5 root 3682: EnableDisableButtons (hwndDlg);
1.1 root 3683: return 1;
3684: }
3685:
3686: if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
3687: {
3688: UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
1.1.1.10! root 3689: MoveEditToCombo ((HWND) lParam, bHistory);
1.1.1.8 root 3690: PostMessage (hwndDlg, WM_APP + APP_MESSAGE_ENABLE_DISABLE, 0, 0);
1.1.1.5 root 3691: return 1;
3692: }
3693:
3694: if (lw == IDC_NO_HISTORY)
3695: {
3696: bHistory = !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY));
1.1 root 3697: return 1;
3698: }
3699:
3700: return 0;
3701:
1.1.1.6 root 3702: case WM_DROPFILES:
3703: {
3704: HDROP hdrop = (HDROP) wParam;
3705: DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
3706: DragFinish (hdrop);
3707:
1.1.1.10! root 3708: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.6 root 3709: EnableDisableButtons (hwndDlg);
3710: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3711: }
1.1.1.7 root 3712: return 1;
1.1.1.6 root 3713:
1.1.1.8 root 3714: case WM_APP + APP_MESSAGE_ENABLE_DISABLE:
1.1 root 3715: EnableDisableButtons (hwndDlg);
3716: return 1;
3717:
1.1.1.8 root 3718: case WM_APP + APP_MESSAGE_SHOW_WINDOW:
3719: ShowWindow (hwndDlg, SW_SHOW);
3720: MainWindowHidden = FALSE;
3721: return 1;
3722:
3723: case WM_COPYDATA:
3724: {
3725: PCOPYDATASTRUCT cd = (PCOPYDATASTRUCT)lParam;
3726: if (memcmp (&cd->dwData, WM_COPY_SET_VOLUME_NAME, 4) == 0)
3727: {
3728: if (cd->cbData > 0)
1.1.1.10! root 3729: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), (char *)cd->lpData, bHistory);
1.1.1.8 root 3730:
3731: EnableDisableButtons (hwndDlg);
3732: SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
3733: }
3734: }
3735: return 1;
3736:
1.1 root 3737: case WM_CLOSE:
3738: EndMainDlg (hwndDlg);
3739: return 1;
3740: }
3741:
3742: return 0;
3743: }
3744:
3745: void
3746: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
3747: {
3748: char **lpszCommandLineArgs; /* Array of command line arguments */
3749: int nNoCommandLineArgs; /* The number of arguments in the array */
1.1.1.7 root 3750: char tmpPath[MAX_PATH * 2];
3751:
3752: /* Defaults */
3753: mountOptions.PreserveTimestamp = TRUE;
1.1 root 3754:
3755: /* Extract command line arguments */
1.1.1.8 root 3756: NoCmdLineArgs = nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
1.1 root 3757: if (nNoCommandLineArgs > 0)
3758: {
3759: int i;
3760:
3761: for (i = 0; i < nNoCommandLineArgs; i++)
3762: {
3763: argument args[]=
3764: {
3765: {"/auto", "/a"},
1.1.1.5 root 3766: {"/beep", "/b"},
1.1 root 3767: {"/cache", "/c"},
1.1.1.5 root 3768: {"/dismount", "/d"},
3769: {"/explore", "/e"},
3770: {"/force", "/f"},
3771: {"/help", "/?"},
1.1 root 3772: {"/history", "/h"},
1.1.1.7 root 3773: {"/keyfile", "/k"},
1.1.1.5 root 3774: {"/letter", "/l"},
1.1.1.6 root 3775: {"/mountoption", "/m"},
1.1.1.5 root 3776: {"/password", "/p"},
1.1.1.7 root 3777: {"/quit", "/q"},
3778: {"/silent", "/s"},
1.1.1.5 root 3779: {"/volume", "/v"},
3780: {"/wipecache", "/w"}
1.1 root 3781: };
3782:
3783: argumentspec as;
3784:
3785: int nArgPos;
3786: int x;
3787:
3788: as.args = args;
3789: as.arg_cnt = sizeof(args)/ sizeof(args[0]);
3790:
3791: x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
3792:
3793: switch (x)
3794: {
1.1.1.7 root 3795: case 'a':
3796: {
3797: char szTmp[32];
3798: bAuto = TRUE;
1.1.1.2 root 3799:
1.1.1.7 root 3800: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
3801: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
3802: {
3803: if (!_stricmp (szTmp, "devices"))
3804: bAutoMountDevices = TRUE;
3805: else if (!_stricmp (szTmp, "favorites"))
3806: bAutoMountFavorites = TRUE;
3807: }
3808: }
3809: break;
1.1.1.2 root 3810:
1.1.1.7 root 3811: case 'b':
3812: bBeep = TRUE;
1.1 root 3813: break;
3814:
1.1.1.7 root 3815: case 'c':
1.1.1.2 root 3816: {
1.1.1.7 root 3817: char szTmp[8];
3818: bCacheInDriver = TRUE;
3819:
3820: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
3821: szTmp, sizeof (szTmp));
3822:
3823: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
3824: bCacheInDriver = FALSE;
1.1.1.2 root 3825: }
1.1 root 3826: break;
3827:
1.1.1.7 root 3828: case 'd':
3829:
3830: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
3831: szDriveLetter, sizeof (szDriveLetter)))
3832: cmdUnmountDrive = toupper(szDriveLetter[0]) - 'A';
3833: else
3834: cmdUnmountDrive = -1;
3835:
1.1 root 3836: break;
3837:
3838: case 'e':
3839: bExplore = TRUE;
3840: break;
3841:
1.1.1.5 root 3842: case 'f':
3843: bForceMount = TRUE;
3844: bForceUnmount = TRUE;
3845: break;
3846:
1.1.1.7 root 3847: case 'k':
3848: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
3849: nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
3850: {
3851: KeyFile *kf;
3852: RelativePath2Absolute (tmpPath);
3853: kf = malloc (sizeof (KeyFile));
3854: strncpy (kf->FileName, tmpPath, sizeof (kf->FileName));
3855: FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
3856: }
3857: break;
3858:
3859: case 'l':
1.1.1.2 root 3860: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
1.1.1.7 root 3861: szDriveLetter, sizeof (szDriveLetter));
3862: commandLineDrive = *szDriveLetter = (char) toupper (*szDriveLetter);
1.1 root 3863: break;
3864:
1.1.1.10! root 3865: case 'h':
1.1.1.6 root 3866: {
3867: char szTmp[8];
1.1.1.7 root 3868: bHistory = bHistoryCmdLine = TRUE;
1.1.1.6 root 3869:
1.1.1.7 root 3870: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
3871: szTmp, sizeof (szTmp));
3872:
3873: if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
3874: bHistory = FALSE;
1.1.1.6 root 3875: }
3876: break;
3877:
3878: case 'm':
3879: {
1.1.1.7 root 3880: char szTmp[16];
1.1.1.6 root 3881: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
3882: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
3883: {
1.1.1.7 root 3884: if (!_stricmp (szTmp, "ro") || !_stricmp (szTmp, "readonly"))
1.1.1.6 root 3885: mountOptions.ReadOnly = TRUE;
3886:
1.1.1.7 root 3887: if (!_stricmp (szTmp, "rm") || !_stricmp (szTmp, "removable"))
1.1.1.6 root 3888: mountOptions.Removable = TRUE;
1.1.1.7 root 3889:
3890: if (!_stricmp (szTmp, "ts") || !_stricmp (szTmp, "timestamp"))
3891: mountOptions.PreserveTimestamp = FALSE;
1.1.1.9 root 3892:
3893: if (!_stricmp (szTmp, "system"))
3894: mountOptions.SystemVolume = TRUE;
3895:
3896: if (!_stricmp (szTmp, "persistent"))
3897: mountOptions.PersistentVolume = TRUE;
1.1.1.6 root 3898: }
3899: }
1.1 root 3900: break;
3901:
1.1.1.7 root 3902: case 'p':
3903: GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
3904: CmdVolumePassword.Text, sizeof (CmdVolumePassword.Text));
3905: CmdVolumePassword.Length = strlen (CmdVolumePassword.Text);
3906: CmdVolumePasswordValid = TRUE;
3907: break;
3908:
3909: case 'v':
3910: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
3911: nNoCommandLineArgs, szFileName, sizeof (szFileName)))
1.1 root 3912: {
1.1.1.7 root 3913: RelativePath2Absolute (szFileName);
1.1.1.10! root 3914: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.8 root 3915: CmdLineVolumeSpecified = TRUE;
1.1 root 3916: }
3917: break;
3918:
1.1.1.7 root 3919: case 'q':
1.1 root 3920: {
1.1.1.7 root 3921: char szTmp[32];
3922: Quit = TRUE;
3923: UsePreferences = FALSE;
1.1 root 3924:
1.1.1.7 root 3925: if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
3926: nArgPos, &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
1.1 root 3927: {
1.1.1.7 root 3928: if (!_stricmp (szTmp, "preferences"))
3929: UsePreferences = TRUE;
1.1 root 3930: }
1.1.1.7 root 3931:
1.1 root 3932: }
3933: break;
3934:
1.1.1.7 root 3935: case 's':
3936: Silent = TRUE;
1.1 root 3937: break;
3938:
1.1.1.7 root 3939: case 'w':
3940: bWipe = TRUE;
1.1 root 3941: break;
3942:
3943: case '?':
1.1.1.7 root 3944: DialogBoxParamW (hInst, MAKEINTRESOURCEW (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
1.1 root 3945: CommandHelpDlgProc, (LPARAM) &as);
3946: exit(0);
3947: break;
3948:
3949: // no option = file name
3950: default:
1.1.1.2 root 3951: {
3952: strncpy (szFileName, lpszCommandLineArgs[0], MAX_PATH-1);
3953: if (szFileName[0] != '\\' && strchr (szFileName, ':') == 0)
3954: {
3955: char path[MAX_PATH*2];
3956: GetCurrentDirectory (MAX_PATH, path);
3957: strcat (path, "\\");
3958: strcat (path, szFileName);
3959: strncpy (szFileName, path, MAX_PATH-1);
3960: }
1.1.1.8 root 3961:
3962: if (nNoCommandLineArgs == 1)
3963: CmdLineVolumeSpecified = TRUE;
1.1.1.10! root 3964: AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
1.1.1.2 root 3965: }
1.1 root 3966: }
3967: }
3968: }
3969:
3970: /* Free up the command line arguments */
3971: while (--nNoCommandLineArgs >= 0)
3972: {
3973: free (lpszCommandLineArgs[nNoCommandLineArgs]);
3974: }
3975: }
3976:
1.1.1.7 root 3977:
1.1 root 3978: int WINAPI
3979: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
3980: int nCmdShow)
3981: {
3982: int status;
3983:
3984: if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
3985:
3986: atexit (localcleanup);
3987:
3988: /* Call InitApp to initialize the common code */
3989: InitApp (hInstance);
3990:
1.1.1.7 root 3991: RegisterRedTick(hInstance);
3992:
3993: /* Allocate, dup, then store away the application title */
3994: lpszTitle = L"TrueCrypt";
3995:
1.1 root 3996: status = DriverAttach ();
3997: if (status != 0)
3998: {
3999: if (status == ERR_OS_ERROR)
4000: handleWin32Error (NULL);
4001: else
4002: handleError (NULL, status);
4003:
1.1.1.7 root 4004: AbortProcess ("NODRIVER");
1.1 root 4005: }
4006:
1.1.1.7 root 4007: VirtualLock (&VolumePassword, sizeof (VolumePassword));
4008: VirtualLock (&CmdVolumePassword, sizeof (CmdVolumePassword));
4009: VirtualLock (&mountOptions, sizeof (mountOptions));
4010: VirtualLock (&defaultMountOptions, sizeof (defaultMountOptions));
4011:
1.1 root 4012: /* Create the main dialog box */
1.1.1.7 root 4013: DialogBoxParamW (hInstance, MAKEINTRESOURCEW (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
1.1 root 4014: (LPARAM) lpszCommandLine);
4015:
4016: /* Terminate */
4017: return 0;
4018: }
1.1.1.6 root 4019:
1.1.1.7 root 4020:
4021: BOOL TaskBarIconAdd (HWND hwnd)
4022: {
4023: BOOL res;
4024: NOTIFYICONDATAW tnid;
4025:
4026: // Only one icon may be created
4027: if (TaskBarIconMutex != NULL) return TRUE;
4028:
4029: TaskBarIconMutex = CreateMutex (NULL, TRUE, "TrueCryptTaskBarIcon");
4030: if (TaskBarIconMutex == NULL || GetLastError () == ERROR_ALREADY_EXISTS)
4031: {
4032: TaskBarIconMutex = NULL;
4033: return FALSE;
4034: }
4035:
4036: tnid.cbSize = sizeof (NOTIFYICONDATAW);
4037: tnid.hWnd = hwnd;
4038: tnid.uID = IDI_TRUECRYPT_ICON;
4039: tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
1.1.1.8 root 4040: tnid.uCallbackMessage = WM_APP + MSG_TASKBAR_ICON;
1.1.1.7 root 4041: tnid.hIcon = LoadImage (hInst, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON), IMAGE_ICON, 16, 16,
4042: nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR); // Windows 2000 cannot display more than 16 fixed colors in notification tray
4043:
4044: wcscpy (tnid.szTip, L"TrueCrypt");
4045:
4046: res = Shell_NotifyIconW (NIM_ADD, &tnid);
4047:
4048: if (tnid.hIcon)
4049: DestroyIcon (tnid.hIcon);
4050:
4051: return res;
4052: }
4053:
4054:
4055: BOOL TaskBarIconRemove (HWND hwnd)
4056: {
4057: if (TaskBarIconMutex != NULL)
4058: {
4059: NOTIFYICONDATA tnid;
4060: BOOL res;
4061:
4062: ZeroMemory (&tnid, sizeof (tnid));
4063: tnid.cbSize = sizeof(NOTIFYICONDATA);
4064: tnid.hWnd = hwnd;
4065: tnid.uID = IDI_TRUECRYPT_ICON;
4066:
4067: res = Shell_NotifyIcon (NIM_DELETE, &tnid);
4068: if (TaskBarIconMutex)
4069: {
4070: CloseHandle (TaskBarIconMutex);
4071: TaskBarIconMutex = NULL;
4072: }
4073: return res;
4074: }
4075: else
4076: return FALSE;
4077: }
4078:
4079:
4080: void DismountIdleVolumes ()
4081: {
4082: static int secCounter;
4083: static int InactivityTime[26];
4084: static unsigned __int64 LastRead[26], LastWritten[26];
4085: static int LastId[26];
4086:
4087: VOLUME_PROPERTIES_STRUCT prop;
4088: DWORD dwResult;
4089: BOOL bResult;
4090: int i;
4091:
4092: if (++secCounter % 60 != 0) return;
4093:
4094: for (i = 0; i < 26; i++)
4095: {
4096: if (LastKnownMountList.ulMountedDrives & (1 << i))
4097: {
4098: memset (&prop, 0, sizeof(prop));
4099: prop.driveNo = i;
4100:
4101: bResult = DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop,
4102: sizeof (prop), &prop, sizeof (prop), &dwResult, NULL);
4103:
4104: if (bResult)
4105: {
4106: if (LastRead[i] == prop.totalBytesRead
4107: && LastWritten[i] == prop.totalBytesWritten
4108: && LastId[i] == prop.uniqueId)
4109: {
4110: if (++InactivityTime[i] >= MaxVolumeIdleTime)
4111: {
4112: if (bCloseDismountedWindows && CloseVolumeExplorerWindows (MainDlg, i))
4113: Sleep (250);
4114:
4115: if (DriverUnmountVolume (MainDlg, i, bForceAutoDismount) == 0)
4116: {
4117: InactivityTime[i] = 0;
4118: BroadcastDeviceChange (DBT_DEVICEREMOVECOMPLETE, i, 0);
4119:
4120: if (bWipeCacheOnAutoDismount)
4121: DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
4122: }
4123: }
4124: }
4125: else
4126: {
4127: InactivityTime[i] = 0;
4128: LastRead[i] = prop.totalBytesRead;
4129: LastWritten[i] = prop.totalBytesWritten;
4130: LastId[i] = prop.uniqueId;
4131: }
4132: }
4133: }
4134: }
4135: }
4136:
4137:
4138: BOOL MountFavoriteVolumes ()
4139: {
4140: BOOL status = TRUE;
4141: DWORD size;
4142: char *favorites = LoadFile (GetConfigPath (FILE_FAVORITE_VOLUMES), &size);
4143: char *xml = favorites;
4144: char mountPoint[MAX_PATH], volume[MAX_PATH];
4145:
4146: if (xml == NULL) return FALSE;
4147:
4148: while (xml = XmlFindElement (xml, "volume"))
4149: {
4150: int drive;
4151: XmlAttribute (xml, "mountpoint", mountPoint, sizeof (mountPoint));
4152: XmlNodeText (xml, volume, sizeof (volume));
4153: drive = toupper (mountPoint[0]) - 'A';
4154:
4155: if ((LastKnownMountList.ulMountedDrives & (1 << drive)) == 0)
4156: {
4157: if (!Mount (MainDlg, drive, volume))
4158: status = FALSE;
4159: LoadDriveLetters (GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
4160: }
4161:
4162: xml++;
4163: }
4164:
4165: free (favorites);
4166: return status;
4167: }
4168:
4169:
4170: void SaveFavoriteVolumes ()
4171: {
4172: if (AskNoYes("CONFIRM_SAVE_FAVORITE_VOL") == IDYES)
4173: {
4174: FILE *f;
4175: int i, cnt = 0;
4176:
4177: f = fopen (GetConfigPath (FILE_FAVORITE_VOLUMES), "w");
4178: if (f == NULL)
4179: {
4180: handleWin32Error (MainDlg);
4181: return;
4182: }
4183:
4184: XmlWriteHeader (f);
4185: fputs ("\n\t<favorites>", f);
4186:
4187: for (i = 0; i < 26; i++)
4188: {
4189: if (LastKnownMountList.ulMountedDrives & (1 << i))
4190: {
4191: fwprintf (f, L"\n\t\t<volume mountpoint=\"%hc:\\\">%s</volume>", i + 'A',
4192: &LastKnownMountList.wszVolume[i][(LastKnownMountList.wszVolume[i][1] == L'?') ? 4 : 0]);
4193: cnt++;
4194: }
4195: }
4196:
4197: fputs ("\n\t</favorites>", f);
4198: XmlWriteFooter (f);
4199: fclose (f);
4200:
4201: if (cnt == 0)
4202: remove (GetConfigPath (FILE_FAVORITE_VOLUMES)); // No volumes to save as favorite
4203:
4204: Info ("FAVORITE_VOLUMES_SAVED");
4205: }
4206: }
4207:
4208:
4209: static void SaveDefaultKeyFilesParam (void)
4210: {
4211: if (defaultKeyFilesParam.FirstKeyFile == NULL)
4212: {
4213: /* No keyfiles selected */
4214: remove (GetConfigPath (FILE_DEFAULT_KEYFILES));
4215: }
4216: else
4217: {
4218: FILE *f;
4219: KeyFile *kf = FirstKeyFile;
4220:
4221: f = fopen (GetConfigPath (FILE_DEFAULT_KEYFILES), "w");
4222: if (f == NULL)
4223: {
4224: handleWin32Error (MainDlg);
4225: return;
4226: }
4227:
4228: XmlWriteHeader (f);
4229:
4230: fputs ("\n\t<defaultkeyfiles>", f);
4231:
4232: while (kf != NULL)
4233: {
4234: fwprintf (f, L"\n\t\t<keyfile>%hs</keyfile>", kf->FileName);
4235: kf = kf->Next;
4236: }
4237:
4238: fputs ("\n\t</defaultkeyfiles>", f);
4239:
4240: XmlWriteFooter (f);
4241:
4242: fclose (f);
4243: return;
4244: }
4245: }
4246:
4247:
4248: static void KeyfileDefaultsDlg (HWND hwndDlg)
4249: {
4250: KeyFilesDlgParam param;
4251:
4252: param.EnableKeyFiles = defaultKeyFilesParam.EnableKeyFiles;
4253: param.FirstKeyFile = defaultKeyFilesParam.FirstKeyFile;
4254:
4255: if (DialogBoxParamW (hInst,
4256: MAKEINTRESOURCEW (IDD_KEYFILES), hwndDlg,
4257: (DLGPROC) KeyFilesDlgProc, (LPARAM) ¶m) == IDOK)
4258: {
4259: if (!param.EnableKeyFiles || AskYesNo("CONFIRM_SAVE_DEFAULT_KEYFILES") == IDYES)
4260: {
4261: KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
4262: defaultKeyFilesParam.EnableKeyFiles = param.EnableKeyFiles;
4263: defaultKeyFilesParam.FirstKeyFile = param.FirstKeyFile;
4264:
4265: RestoreDefaultKeyFilesParam ();
4266: SaveDefaultKeyFilesParam ();
4267: }
4268: }
4269: }
4270:
4271:
4272: static void HandleHotKey (HWND hwndDlg, WPARAM wParam)
4273: {
4274: DWORD dwResult;
4275: BOOL success = TRUE;
4276:
4277: switch (wParam)
4278: {
4279: case HK_AUTOMOUNT_DEVICES:
4280: MountAllDevices (hwndDlg, TRUE);
4281:
4282: if (bPlaySoundOnHotkeyMountDismount)
4283: MessageBeep(-1);
4284:
4285: break;
4286:
4287: case HK_DISMOUNT_ALL:
4288: DismountAll (hwndDlg, FALSE, TRUE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
4289:
4290: if (bPlaySoundOnHotkeyMountDismount)
4291: MessageBeep(-1);
4292:
4293: if (bDisplayMsgBoxOnHotkeyDismount)
4294: Info ("DISMOUNT_ALL_ATTEMPT_COMPLETED");
4295:
4296: break;
4297:
4298: case HK_FORCE_DISMOUNT_ALL_AND_WIPE:
4299: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
4300: success &= DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
4301: if (success)
4302: {
4303: if (bPlaySoundOnHotkeyMountDismount)
4304: MessageBeep(-1);
4305:
4306: if (bDisplayMsgBoxOnHotkeyDismount)
4307: Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
4308: }
4309: break;
4310:
4311: case HK_FORCE_DISMOUNT_ALL_AND_WIPE_AND_EXIT:
4312: success = DismountAll (hwndDlg, TRUE, FALSE, UNMOUNT_MAX_AUTO_RETRIES, UNMOUNT_AUTO_RETRY_DELAY);
4313: success &= DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
4314: if (success)
4315: {
4316: if (bPlaySoundOnHotkeyMountDismount)
4317: MessageBeep(-1);
4318:
4319: if (bDisplayMsgBoxOnHotkeyDismount)
4320: Info ("VOLUMES_DISMOUNTED_CACHE_WIPED");
4321: }
4322: TaskBarIconRemove (hwndDlg);
4323: EndMainDlg (hwndDlg);
4324: break;
4325:
4326: case HK_MOUNT_FAVORITE_VOLUMES:
4327: MountFavoriteVolumes ();
4328:
4329: if (bPlaySoundOnHotkeyMountDismount)
4330: MessageBeep(-1);
4331:
4332: break;
4333:
4334: case HK_SHOW_HIDE_MAIN_WINDOW:
1.1.1.8 root 4335: MainWindowHidden = !IsWindowVisible (hwndDlg);
1.1.1.7 root 4336: MainWindowHidden = !MainWindowHidden;
1.1.1.8 root 4337:
4338: if (!MainWindowHidden)
4339: SetForegroundWindow (hwndDlg);
1.1.1.7 root 4340: ShowWindow (hwndDlg, !MainWindowHidden ? SW_SHOW : SW_HIDE);
4341: break;
4342: }
4343: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.