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

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

unix.superglobalmegacorp.com

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