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