Annotation of truecrypt/mount/mount.c, revision 1.1.1.23

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.