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

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

unix.superglobalmegacorp.com

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