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

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

unix.superglobalmegacorp.com

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