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

1.1     ! root        1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org
        !             2:    This product uses components written by Paul Le Roux <[email protected]> */
        !             3: 
        !             4: #include "TCdefs.h"
        !             5: 
        !             6: #include "crypto.h"
        !             7: #include "apidrvr.h"
        !             8: #include "dlgcode.h"
        !             9: #include "combo.h"
        !            10: #include "registry.h"
        !            11: #include "../common/resource.h"
        !            12: 
        !            13: #include "resource.h"
        !            14: #include "cmdline.h"
        !            15: #include "Mount.h"
        !            16: 
        !            17: #include "dismount.h"
        !            18: 
        !            19: #include "Password.h"
        !            20: #include <time.h>
        !            21: 
        !            22: BOOL bExplore = FALSE;                         /* Display explorer window after mount */
        !            23: BOOL bBeep = FALSE;                                    /* Donot beep after mount */
        !            24: char szFileName[TC_MAX_PATH];          /* Volume to mount */
        !            25: char szDriveLetter[3];                         /* Drive Letter to mount */
        !            26: BOOL bCacheInDriver = FALSE;           /* Cache any passwords we see */
        !            27: BOOL bHistory = FALSE;                         /* Don't save history */
        !            28: BOOL bHistoryCmdLine = FALSE;          /* History control is always disabled */
        !            29: BOOL bCloseDismountedWindows=TRUE;     /* Close all open explorer windows of dismounted volume */
        !            30: BOOL bWipeCacheOnExit = FALSE;         /* Wipe password from chace on exit */
        !            31: 
        !            32: BOOL bWipe = FALSE;                                    /* Wipe driver passwords */
        !            33: BOOL bAuto = FALSE;                                    /* Do everything without user input */
        !            34: 
        !            35: BOOL bQuiet = FALSE;                           /* No dialogs/messages */
        !            36: 
        !            37: #define VMOUNTED 1
        !            38: #define VFREE  0
        !            39: 
        !            40: int nCurrentShowType = 0;                      /* current display mode, mount, unmount etc */
        !            41: int nSelectedDriveIndex = 0;           /* Item number of selected drive */
        !            42: 
        !            43: void
        !            44: localcleanup (void)
        !            45: {
        !            46:        /* Free the application title */
        !            47:        if (lpszTitle != NULL)
        !            48:                free (lpszTitle);
        !            49: 
        !            50:        /* Cleanup common code resources */
        !            51:        cleanup ();
        !            52: }
        !            53: 
        !            54: void
        !            55: RefreshMainDlg (HWND hwndDlg)
        !            56: {
        !            57:        int drive = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))));
        !            58: 
        !            59:        MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
        !            60:        LoadDriveLetters (GetDlgItem (hwndDlg, IDC_DRIVELIST), drive);
        !            61:        EnableDisableButtons (hwndDlg);
        !            62: }
        !            63: 
        !            64: void
        !            65: EndMainDlg (HWND hwndDlg)
        !            66: {
        !            67:        MoveEditToCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
        !            68:        SaveSettings (hwndDlg);
        !            69: 
        !            70:        if (bWipeCacheOnExit)
        !            71:        {
        !            72:                DWORD dwResult;
        !            73:                DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
        !            74:        }
        !            75: 
        !            76:        EndDialog (hwndDlg, 0);
        !            77: }
        !            78: 
        !            79: void
        !            80: EnableDisableButtons (HWND hwndDlg)
        !            81: {
        !            82:        HWND hOKButton = GetDlgItem (hwndDlg, IDOK);
        !            83:        HWND hChangeButton = GetDlgItem (hwndDlg, IDC_CHANGE_PASSWORD);
        !            84:        HWND hVolume = GetDlgItem (hwndDlg, IDC_VOLUME);
        !            85:        BOOL bEnable = TRUE;
        !            86:        WORD x;
        !            87: 
        !            88:        x = LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)));
        !            89: 
        !            90:        if (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_VOLUME)) > 0)
        !            91:        {
        !            92:                EnableWindow (hOKButton, TRUE);
        !            93:                EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_ENABLED);
        !            94: 
        !            95:                EnableWindow (hChangeButton, TRUE);
        !            96:                EnableMenuItem (GetMenu (hwndDlg), IDC_CHANGE_PASSWORD, MF_ENABLED);
        !            97:        }
        !            98:        else
        !            99:        {
        !           100:                EnableWindow (hOKButton, FALSE);
        !           101:                EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_GRAYED);
        !           102: 
        !           103:                EnableWindow (hChangeButton, FALSE);
        !           104:                EnableMenuItem (GetMenu (hwndDlg), IDC_CHANGE_PASSWORD, MF_GRAYED);
        !           105:        }
        !           106: 
        !           107:        if (x == VFREE)
        !           108:        {
        !           109:                SetWindowText (hOKButton, getstr (IDS_MOUNT_BUTTON));
        !           110: 
        !           111:                EnableMenuItem (GetMenu (hwndDlg), ID_UNMOUNT_VOLUME, MF_GRAYED);
        !           112:        }
        !           113: 
        !           114:        if (x == VMOUNTED)
        !           115:        {
        !           116:                SetWindowText (hOKButton, getstr (IDS_UNMOUNT_BUTTON));
        !           117:                EnableWindow (hOKButton, TRUE);
        !           118: 
        !           119:                EnableMenuItem (GetMenu (hwndDlg), ID_MOUNT_VOLUME, MF_GRAYED);
        !           120:                EnableMenuItem (GetMenu (hwndDlg), ID_UNMOUNT_VOLUME, MF_ENABLED);
        !           121: 
        !           122:                EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), TRUE);
        !           123:                EnableMenuItem (GetMenu (hwndDlg), IDC_VOLUME_PROPERTIES, MF_ENABLED);
        !           124:        }
        !           125:        else
        !           126:        {
        !           127:                EnableWindow (GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES), FALSE);
        !           128:                EnableMenuItem (GetMenu (hwndDlg), IDC_VOLUME_PROPERTIES, MF_GRAYED);
        !           129:        }
        !           130: 
        !           131:        EnableWindow (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), !IsPasswordCacheEmpty());
        !           132:        EnableMenuItem (GetMenu (hwndDlg), IDC_WIPE_CACHE, IsPasswordCacheEmpty() ? MF_GRAYED:MF_ENABLED);
        !           133:        EnableMenuItem (GetMenu (hwndDlg), IDC_CLEAR_HISTORY, IsComboEmpty (GetDlgItem (hwndDlg, IDC_VOLUME)) ? MF_GRAYED:MF_ENABLED);
        !           134: }
        !           135: 
        !           136: void
        !           137: OpenPageHelp (HWND hwndDlg)
        !           138: {
        !           139:        int r = (int)ShellExecute (NULL, "open", szHelpFile, NULL, NULL, SW_SHOWNORMAL);
        !           140: 
        !           141:        if (r == ERROR_FILE_NOT_FOUND)
        !           142:                MessageBox (hwndDlg, getstr (IDS_HELP_ERROR), lpszTitle, MB_ICONERROR);
        !           143: 
        !           144:        if (r == SE_ERR_NOASSOC)
        !           145:                MessageBox (hwndDlg, getstr (IDS_HELP_READER_ERROR), lpszTitle, MB_ICONERROR);
        !           146: }
        !           147: 
        !           148: void
        !           149: LoadSettings (HWND hwndDlg)
        !           150: {
        !           151: 
        !           152:        // Options
        !           153:        bCacheInDriver =                        ReadRegistryInt ("CachePasswordsInDriver", FALSE);
        !           154:        bExplore =                                      ReadRegistryInt ("OpenExplorerWindowAfterMount", FALSE);
        !           155:        bCloseDismountedWindows =       ReadRegistryInt ("CloseExplorerWindowsOnDismount", TRUE);
        !           156:        bHistory =                                      ReadRegistryInt ("SaveMountedVolumesHistory", FALSE);
        !           157:        bWipeCacheOnExit =                      ReadRegistryInt ("WipePasswordCacheOnExit", FALSE);
        !           158: 
        !           159:        // Drive Letter
        !           160:        ReadRegistryString ("LastSelectedDrive", "", szDriveLetter, sizeof (szDriveLetter));
        !           161: 
        !           162:        // History
        !           163:        if (bHistoryCmdLine != TRUE)
        !           164:                LoadCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume");
        !           165: }
        !           166: 
        !           167: void
        !           168: SaveSettings (HWND hwndDlg)
        !           169: {
        !           170:        char szTmp[32] = {0};
        !           171:        LPARAM lLetter;
        !           172: 
        !           173:        // Options
        !           174:        WriteRegistryInt ("CachePasswordsInDriver",                     bCacheInDriver);
        !           175:        WriteRegistryInt ("OpenExplorerWindowAfterMount",       bExplore);
        !           176:        WriteRegistryInt ("CloseExplorerWindowsOnDismount", bCloseDismountedWindows);
        !           177:        WriteRegistryInt ("SaveMountedVolumesHistory",          !IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
        !           178:        WriteRegistryInt ("WipePasswordCacheOnExit",            bWipeCacheOnExit);
        !           179: 
        !           180:        // Drive Letter
        !           181:        lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
        !           182:        if (LOWORD (lLetter) != 0xffff)
        !           183:                sprintf (szTmp, "%c:", (char) HIWORD (lLetter));
        !           184:        WriteRegistryString ("LastSelectedDrive", szTmp);
        !           185: 
        !           186:        // History
        !           187:        DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume", IsButtonChecked (GetDlgItem (hwndDlg, IDC_NO_HISTORY)));
        !           188: }
        !           189: 
        !           190: BOOL
        !           191: SelectItem (HWND hTree, char nLetter)
        !           192: {
        !           193:        int i;
        !           194:        LVITEM item;
        !           195:        
        !           196:        for (i = 0; i < ListView_GetItemCount(hTree); i++)
        !           197:        {
        !           198:                memset(&item, 0, sizeof(LVITEM));
        !           199:                item.mask = LVIF_PARAM;
        !           200:                item.iItem = i;
        !           201: 
        !           202:                if (ListView_GetItem (hTree, &item) == FALSE)
        !           203:                        return FALSE;
        !           204:                else
        !           205:                {
        !           206:                        if (HIWORD (item.lParam) == nLetter)
        !           207:                        {
        !           208:                                memset(&item, 0, sizeof(LVITEM));
        !           209:                                item.state = LVIS_FOCUSED|LVIS_SELECTED;
        !           210:                                item.stateMask = LVIS_FOCUSED|LVIS_SELECTED;
        !           211:                                item.mask = LVIF_STATE;
        !           212:                                item.iItem = i;
        !           213:                                SendMessage(hTree, LVM_SETITEMSTATE, i, (LPARAM) &item);
        !           214:                                return TRUE;
        !           215:                        }
        !           216:                }
        !           217: 
        !           218:        }
        !           219: 
        !           220:        return TRUE;
        !           221: }
        !           222: 
        !           223: 
        !           224: // Fills drive list
        !           225: // drive>0 = update only the corresponding drive subitems
        !           226: void
        !           227: LoadDriveLetters (HWND hTree, int drive)
        !           228: {
        !           229:        char *szDriveLetters[]=
        !           230:        {"A:", "B:", "C:", "D:",
        !           231:         "E:", "F:", "G:", "H:", "I:", "J:", "K:",
        !           232:         "L:", "M:", "N:", "O:", "P:", "Q:", "R:",
        !           233:         "S:", "T:", "U:", "V:", "W:", "X:", "Y:",
        !           234:         "Z:"};
        !           235: 
        !           236:        DWORD dwResult;
        !           237:        BOOL bResult;   
        !           238:        DWORD dwUsedDrives;
        !           239:        MOUNT_LIST_STRUCT driver;
        !           240: 
        !           241:        LVITEM listItem;
        !           242:        int item = 0;
        !           243:        char i;
        !           244: 
        !           245:        bResult = DeviceIoControl (hDriver, MOUNT_LIST, &driver,
        !           246:                sizeof (driver), &driver, sizeof (driver), &dwResult,
        !           247:                NULL);
        !           248: 
        !           249:        if (bResult == FALSE)
        !           250:        {
        !           251:                handleWin32Error (hTree);
        !           252:                driver.ulMountedDrives = 0;
        !           253:        }
        !           254: 
        !           255:        dwUsedDrives = GetLogicalDrives();
        !           256:        if (dwUsedDrives == 0 && bQuiet == FALSE)
        !           257:                        MessageBox (hTree, getstr (IDS_DRIVELETTERS), lpszTitle, ICON_HAND);
        !           258: 
        !           259:        if(drive == 0)
        !           260:                ListView_DeleteAllItems(hTree);
        !           261: 
        !           262:        for (i = 2; i < 26; i++)
        !           263:        {
        !           264:                int curDrive = 0;
        !           265: 
        !           266:                if(drive > 0)
        !           267:                {
        !           268:                        LVITEM tmp;
        !           269:                        memset(&tmp, 0, sizeof(LVITEM));
        !           270:                        tmp.mask = LVIF_PARAM;
        !           271:                        tmp.iItem = item;
        !           272:                        if (ListView_GetItem (hTree, &tmp) != FALSE)
        !           273:                                curDrive = HIWORD(tmp.lParam);
        !           274:                }
        !           275: 
        !           276:                if ( driver.ulMountedDrives & (1 << i) )
        !           277:                {
        !           278:                        char szTmp[256];
        !           279: 
        !           280:                        memset(&listItem, 0, sizeof(listItem));
        !           281: 
        !           282:                        listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
        !           283:                        listItem.iImage = 1;
        !           284:                        listItem.iItem = item++;  
        !           285: 
        !           286:                        if(drive > 0 && drive != curDrive)
        !           287:                                continue;
        !           288: 
        !           289:                        if (nCurrentOS == WIN_NT)
        !           290:                                ToSBCS ((void *) driver.wszVolume[i]);
        !           291: 
        !           292:                        if (memcmp (driver.wszVolume[i], "\\Device", 7) == 0)
        !           293:                                sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]));
        !           294:                        else
        !           295:                        {
        !           296:                                if (nCurrentOS == WIN_NT)
        !           297:                                        sprintf (szTmp, "%s", ((char *) driver.wszVolume[i]) + 4);
        !           298:                                else
        !           299:                                        sprintf (szTmp, "%s", (char *) driver.wszVolume[i]);
        !           300:                        }
        !           301: 
        !           302:                        listItem.pszText = szDriveLetters[i];
        !           303:                        listItem.lParam = MAKELONG (VMOUNTED, i + 'A');
        !           304:                        
        !           305:                        if(drive == 0) 
        !           306:                                ListView_InsertItem (hTree, &listItem);
        !           307:                        else
        !           308:                                ListView_SetItem (hTree, &listItem);
        !           309: 
        !           310:                        listItem.mask=LVIF_TEXT;   
        !           311:                        listItem.pszText = szTmp;
        !           312: 
        !           313:                        listItem.iSubItem = 1;
        !           314:                        ListView_SetItem(hTree, &listItem);
        !           315: 
        !           316:                        if(driver.diskLength[i] > 1024I64*1024*1024)
        !           317:                                sprintf (szTmp,"%.1f GB",(double)(driver.diskLength[i]/1024.0/1024/1024));
        !           318:                        else if(driver.diskLength[i] > 1024I64*1024)
        !           319:                                sprintf (szTmp, "%I64d MB", driver.diskLength[i]/1024/1024);
        !           320:                        else if(driver.diskLength[i] > 0)
        !           321:                                sprintf (szTmp, "%I64d KB", driver.diskLength[i]/1024);
        !           322:                        else
        !           323:                                szTmp[0] = 0;
        !           324: 
        !           325:                        listItem.iSubItem = 2;
        !           326:                        ListView_SetItem(hTree, &listItem);
        !           327: 
        !           328:                        sprintf (szTmp, "%s", get_cipher_name (driver.cipher[i]));
        !           329:                        listItem.iSubItem = 3;
        !           330:                        ListView_SetItem(hTree, &listItem);
        !           331: 
        !           332:                }
        !           333:                else
        !           334:                {
        !           335:                        if (!(dwUsedDrives & 1 << i))
        !           336:                        {
        !           337:                                if(drive > 0 && drive != HIWORD (GetSelectedLong (hTree)))
        !           338:                                {
        !           339:                                        item++;
        !           340:                                        continue;
        !           341:                                }
        !           342: 
        !           343:                                memset(&listItem,0,sizeof(listItem));
        !           344: 
        !           345:                                listItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
        !           346:                                listItem.iImage = 0;
        !           347:                                listItem.iItem = item++;  
        !           348:                                listItem.pszText = szDriveLetters[i];
        !           349:                                listItem.lParam = MAKELONG (VFREE, i + 'A');
        !           350: 
        !           351:                                if(drive == 0) 
        !           352:                                        ListView_InsertItem (hTree, &listItem);
        !           353:                                else
        !           354:                                        ListView_SetItem (hTree, &listItem);
        !           355: 
        !           356:                                listItem.mask=LVIF_TEXT;   
        !           357:                                listItem.pszText = "";
        !           358:                                listItem.iSubItem = 1;
        !           359:                                ListView_SetItem(hTree, &listItem);
        !           360:                                listItem.iSubItem = 2;
        !           361:                                ListView_SetItem(hTree, &listItem);
        !           362:                                listItem.iSubItem = 3;
        !           363:                                ListView_SetItem(hTree, &listItem);
        !           364: 
        !           365:                        }
        !           366:                }
        !           367:        }
        !           368: }
        !           369: 
        !           370: 
        !           371: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
        !           372:    should return nonzero if it processes the message, and zero if it does
        !           373:    not. - see DialogProc */
        !           374: BOOL WINAPI
        !           375: PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
        !           376: {
        !           377: 
        !           378:        WORD lw = LOWORD (wParam);
        !           379:        WORD hw = HIWORD (wParam);
        !           380: 
        !           381:        if (lParam);            /* remove warning */
        !           382:        if (hw);                        /* remove warning */
        !           383: 
        !           384:        switch (msg)
        !           385:        {
        !           386:        case WM_INITDIALOG:
        !           387:                {
        !           388:                        UINT nID[4];
        !           389: 
        !           390:                        nID[0] = IDS_PASSWORD_HELP0;
        !           391:                        nID[1] = IDS_PASSWORD_HELP1;
        !           392:                        nID[2] = IDS_PASSWORD_HELP2;
        !           393:                        nID[3] = IDS_PASSWORD_HELP3;
        !           394: 
        !           395:                        SetDefaultUserFont (hwndDlg);
        !           396: 
        !           397:                        SendMessage (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
        !           398:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
        !           399:                        SendMessage (GetDlgItem (hwndDlg, IDC_VERIFY), EM_LIMITTEXT, MAX_PASSWORD, 0);
        !           400:                        SetWindowText (GetDlgItem (hwndDlg, IDC_BOX_HELP), getmultilinestr (nID));
        !           401:                        EnableWindow (GetDlgItem (hwndDlg, IDOK), FALSE);
        !           402: 
        !           403:                        return 1;
        !           404:                }
        !           405: 
        !           406:        case WM_COMMAND:
        !           407:                if (lw == IDCANCEL)
        !           408:                {
        !           409:                        // Attempt to wipe passwords stored in the input field buffers
        !           410:                        char tmp[MAX_PASSWORD+1];
        !           411:                        memset (tmp, 'X', MAX_PASSWORD);
        !           412:                        tmp[MAX_PASSWORD] = 0;
        !           413: 
        !           414:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
        !           415:                        SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);    
        !           416:                        SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);  
        !           417: 
        !           418:                        EndDialog (hwndDlg, IDCANCEL);
        !           419:                        return 1;
        !           420:                }
        !           421:                if (hw == EN_CHANGE)
        !           422:                {
        !           423:                        VerifyPasswordAndUpdate (hwndDlg, GetDlgItem (hwndDlg, IDOK), GetDlgItem (hwndDlg, IDC_PASSWORD),
        !           424:                                                 GetDlgItem (hwndDlg, IDC_VERIFY), NULL, NULL);
        !           425:                        return 1;
        !           426:                }
        !           427:                if (lw == IDOK)
        !           428:                {
        !           429:                        HWND hParent = GetParent (hwndDlg);
        !           430:                        char szOldPassword[MAX_PASSWORD + 1];
        !           431:                        char szPassword[MAX_PASSWORD + 1];
        !           432:                        int nStatus;
        !           433: 
        !           434:                        GetWindowText (GetDlgItem (hParent, IDC_VOLUME), szFileName, sizeof (szFileName));
        !           435: 
        !           436:                        GetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), szOldPassword, sizeof (szOldPassword));
        !           437: 
        !           438:                        GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szPassword, sizeof (szPassword));
        !           439: 
        !           440:                        nStatus = ChangePwd (szFileName, szOldPassword, szPassword);
        !           441: 
        !           442:                        burn (szOldPassword, sizeof (szOldPassword));
        !           443:                        burn (szPassword, sizeof (szPassword));
        !           444: 
        !           445:                        if (nStatus != 0)
        !           446:                                handleError (hwndDlg, nStatus);
        !           447:                        else
        !           448:                        {
        !           449:                                // Attempt to wipe passwords stored in the input field buffers
        !           450:                                char tmp[MAX_PASSWORD+1];
        !           451:                                memset (tmp, 'X', MAX_PASSWORD);
        !           452:                                tmp[MAX_PASSWORD] = 0;
        !           453:                                SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
        !           454:                                SetWindowText (GetDlgItem (hwndDlg, IDC_OLD_PASSWORD), tmp);    
        !           455:                                SetWindowText (GetDlgItem (hwndDlg, IDC_VERIFY), tmp);  
        !           456: 
        !           457:                                EndDialog (hwndDlg, IDOK);
        !           458:                        }
        !           459: 
        !           460:                        return 1;
        !           461:                }
        !           462:                return 0;
        !           463:        }
        !           464: 
        !           465:        return 0;
        !           466: }
        !           467: 
        !           468: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
        !           469:    should return nonzero if it processes the message, and zero if it does
        !           470:    not. - see DialogProc */
        !           471: BOOL WINAPI
        !           472: PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
        !           473: {
        !           474:        WORD lw = LOWORD (wParam);
        !           475:        static char* szXPwd;    
        !           476: 
        !           477:        switch (msg)
        !           478:        {
        !           479:        case WM_INITDIALOG:
        !           480:                {
        !           481:                        szXPwd = (char*) lParam;
        !           482:                        SetDefaultUserFont (hwndDlg);
        !           483:                        SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
        !           484:                        SendMessage (GetDlgItem (hwndDlg, IDC_CACHE), BM_SETCHECK, bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
        !           485:                        return 1;
        !           486:                }
        !           487: 
        !           488:        case WM_COMMAND:
        !           489: 
        !           490:                if (lw == IDCANCEL || lw == IDOK)
        !           491:                {
        !           492:                        char tmp[MAX_PASSWORD+1];
        !           493:                        
        !           494:                        if (lw == IDOK)
        !           495:                        {
        !           496:                                GetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szXPwd, MAX_PASSWORD + 1);
        !           497:                                bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_CACHE));      
        !           498:                        }
        !           499: 
        !           500:                        // Attempt to wipe password stored in the input field buffer
        !           501:                        memset (tmp, 'X', MAX_PASSWORD);
        !           502:                        tmp[MAX_PASSWORD] = 0;
        !           503:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);        
        !           504:                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), 0);  
        !           505: 
        !           506:                        EndDialog (hwndDlg, lw);
        !           507:                        return 1;
        !           508:                }
        !           509:                return 0;
        !           510:        }
        !           511: 
        !           512:        return 0;
        !           513: }
        !           514: 
        !           515: BOOL WINAPI
        !           516: PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
        !           517: {
        !           518:        WORD lw = LOWORD (wParam);
        !           519: 
        !           520:        switch (msg)
        !           521:        {
        !           522:        case WM_INITDIALOG:
        !           523:                {
        !           524:                        SetDefaultUserFont (hwndDlg);
        !           525:                
        !           526:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER), BM_SETCHECK, 
        !           527:                                                bExplore ? BST_CHECKED:BST_UNCHECKED, 0);
        !           528: 
        !           529:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS), BM_SETCHECK, 
        !           530:                                                bCloseDismountedWindows ? BST_CHECKED:BST_UNCHECKED, 0);
        !           531:                        
        !           532:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT), BM_SETCHECK, 
        !           533:                                                bWipeCacheOnExit ? BST_CHECKED:BST_UNCHECKED, 0);
        !           534: 
        !           535:                        SendMessage (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS), BM_SETCHECK, 
        !           536:                                                bCacheInDriver ? BST_CHECKED:BST_UNCHECKED, 0);
        !           537:                        
        !           538:                        
        !           539:                        return 1;
        !           540:                }
        !           541: 
        !           542:        case WM_COMMAND:
        !           543: 
        !           544:                if (lw == IDCANCEL)
        !           545:                {
        !           546:                        EndDialog (hwndDlg, lw);
        !           547:                        return 1;
        !           548:                }
        !           549: 
        !           550:                if (lw == IDOK)
        !           551:                {
        !           552:                        bExplore = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_OPEN_EXPLORER));       
        !           553:                        bCloseDismountedWindows = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CLOSE_DISMOUNTED_WINDOWS));     
        !           554:                        bWipeCacheOnExit = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_WIPE_CACHE_ON_EXIT));  
        !           555:                        bCacheInDriver = IsButtonChecked (GetDlgItem (hwndDlg, IDC_PREF_CACHE_PASSWORDS));       
        !           556: 
        !           557:                        EndDialog (hwndDlg, lw);
        !           558:                        return 1;
        !           559:                }
        !           560:                return 0;
        !           561:        }
        !           562: 
        !           563:        return 0;
        !           564: }
        !           565: 
        !           566: BOOL WINAPI
        !           567: VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
        !           568: {
        !           569:        WORD lw = LOWORD (wParam);
        !           570: 
        !           571:        switch (msg)
        !           572:        {
        !           573:        case WM_INITDIALOG:
        !           574:                {
        !           575:                        VOLUME_PROPERTIES_STRUCT prop;
        !           576:                        DWORD dwResult;
        !           577:                        BOOL bResult;   
        !           578: 
        !           579:                        LVCOLUMN lvCol;
        !           580:                        LVITEM listItem;
        !           581:                        HWND list = GetDlgItem (hwndDlg, IDC_VOLUME_PROPERTIES_LIST);
        !           582:                        char szTmp[128];
        !           583: 
        !           584:                        SetDefaultUserFont (hwndDlg);
        !           585: 
        !           586:                        SendMessage (list,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
        !           587:                                LVS_EX_FULLROWSELECT
        !           588:                                |LVS_EX_HEADERDRAGDROP 
        !           589:                                //|LVS_EX_GRIDLINES 
        !           590:                                //|LVS_EX_TWOCLICKACTIVATE 
        !           591:                                ); 
        !           592: 
        !           593:                        memset (&lvCol,0,sizeof(lvCol));               
        !           594:                        lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
        !           595:                        lvCol.pszText = "Value";                           
        !           596:                        lvCol.cx = 220;
        !           597:                        lvCol.fmt = LVCFMT_LEFT ;
        !           598:                        SendMessage (list,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
        !           599: 
        !           600:                        lvCol.pszText = "Property";  
        !           601:                        lvCol.cx = 100;           
        !           602:                        lvCol.fmt = LVCFMT_LEFT;
        !           603:                        SendMessage (list,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
        !           604:        
        !           605:        
        !           606:                        memset (&prop, 0, sizeof(prop));
        !           607:                        prop.driveNo = HIWORD (GetSelectedLong (GetDlgItem (GetParent(hwndDlg), IDC_DRIVELIST))) - 'A';
        !           608: 
        !           609:                        bResult = DeviceIoControl (hDriver, VOLUME_PROPERTIES, &prop,
        !           610:                                sizeof (prop), &prop, sizeof (prop), &dwResult,
        !           611:                                NULL);
        !           612:        
        !           613:                        memset (&listItem, 0, sizeof(listItem));
        !           614: 
        !           615:                        listItem.mask = LVIF_TEXT;
        !           616:                        listItem.iItem = -1;
        !           617: 
        !           618:                        listItem.pszText = "Volume Location";
        !           619:                        listItem.iItem++; 
        !           620:                        listItem.iSubItem = 0;
        !           621:                        ListView_InsertItem(list, &listItem);
        !           622:                        listItem.iSubItem++;
        !           623:                        listItem.pszText = (LPSTR)prop.wszVolume;
        !           624:                        if (nCurrentOS == WIN_NT)
        !           625:                        {
        !           626:                                ToSBCS (prop.wszVolume);
        !           627:                                if (prop.wszVolume[0] == '?\\')
        !           628:                                listItem.pszText = (LPSTR)prop.wszVolume + 4;
        !           629:                        }
        !           630:                        ListView_SetItem(list, &listItem);
        !           631: 
        !           632:                        listItem.pszText = "Volume Size";
        !           633:                        listItem.iItem++;  
        !           634:                        listItem.iSubItem = 0;
        !           635:                        ListView_InsertItem(list, &listItem);
        !           636:                        listItem.iSubItem++;
        !           637:                        sprintf (szTmp, "%I64d bytes", prop.diskLength);
        !           638:                        listItem.pszText = szTmp;
        !           639:                        ListView_SetItem (list, &listItem);
        !           640: 
        !           641:                        listItem.pszText = "Cipher";
        !           642:                        listItem.iItem++; 
        !           643:                        listItem.iSubItem = 0;
        !           644:                        ListView_InsertItem(list, &listItem);
        !           645:                        listItem.iSubItem++;
        !           646:                        listItem.pszText = get_cipher_name (prop.cipher);
        !           647:                        ListView_SetItem (list, &listItem);
        !           648: 
        !           649:                        listItem.pszText = "Key Size";
        !           650:                        listItem.iItem++;  
        !           651:                        listItem.iSubItem = 0;
        !           652:                        ListView_InsertItem(list, &listItem);
        !           653:                        listItem.iSubItem++;
        !           654:                        sprintf (szTmp, "%d bits", get_key_size (prop.cipher)*8);
        !           655:                        listItem.pszText = szTmp;
        !           656:                        ListView_SetItem (list, &listItem);
        !           657: 
        !           658:                        listItem.pszText = "PKCS5 PRF";
        !           659:                        listItem.iItem++; 
        !           660:                        listItem.iSubItem = 0;
        !           661:                        ListView_InsertItem(list, &listItem);
        !           662:                        listItem.iSubItem++;
        !           663:                        listItem.pszText = get_hash_name (prop.pkcs5);
        !           664:                        ListView_SetItem (list, &listItem);
        !           665: 
        !           666:                        listItem.pszText = "PKCS5 Iterations";
        !           667:                        listItem.iItem++;  
        !           668:                        listItem.iSubItem = 0;
        !           669:                        ListView_InsertItem(list, &listItem);
        !           670:                        listItem.iSubItem++;
        !           671:                        sprintf (szTmp, "%d", prop.pkcs5Iterations);
        !           672:                        listItem.pszText = szTmp;
        !           673:                        ListView_SetItem (list, &listItem);
        !           674:                        
        !           675:                        {
        !           676:                                FILETIME ft, curFt;
        !           677:                                SYSTEMTIME st;
        !           678:                                char date[128];
        !           679:                                memset (date, 0, sizeof (date));
        !           680: 
        !           681:                                listItem.pszText = "Volume Created";
        !           682:                                listItem.iItem++;  
        !           683:                                listItem.iSubItem = 0;
        !           684:                                ListView_InsertItem (list, &listItem);
        !           685: 
        !           686:                                listItem.iSubItem++;
        !           687:                                *(unsigned __int64 *)(&ft) = prop.volumeCreationTime;
        !           688:                                FileTimeToSystemTime (&ft, &st);
        !           689:                                GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
        !           690:                                sprintf (date, "%s ", szTmp);
        !           691:                                GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
        !           692:                                strcat (date, szTmp);
        !           693:                                listItem.pszText = date;
        !           694:                                ListView_SetItem (list, &listItem);
        !           695: 
        !           696:                                listItem.pszText = "Password Changed";
        !           697:                                listItem.iItem++;  
        !           698:                                listItem.iSubItem = 0;
        !           699:                                ListView_InsertItem (list, &listItem);
        !           700: 
        !           701:                                listItem.iSubItem++;
        !           702:                                *(unsigned __int64 *)(&ft) = prop.headerCreationTime;
        !           703:                                FileTimeToSystemTime (&ft, &st);
        !           704:                                GetDateFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
        !           705:                                sprintf (date, "%s ", szTmp);
        !           706:                                GetTimeFormat (LOCALE_USER_DEFAULT, 0, &st, 0, (LPSTR) szTmp, sizeof (szTmp));
        !           707:                                strcat (date, szTmp);
        !           708: 
        !           709:                                GetLocalTime (&st);
        !           710:                                SystemTimeToFileTime (&st, &curFt);
        !           711:                                sprintf (date + strlen (date), " (%I64d days ago)"
        !           712:                                        , (*(__int64 *)&curFt - *(__int64 *)&ft)/1000000000000 );
        !           713:                                listItem.pszText = date;
        !           714:                                ListView_SetItem (list, &listItem);
        !           715:                        }
        !           716: 
        !           717:                        return 1;
        !           718:                }
        !           719: 
        !           720:        case WM_COMMAND:
        !           721: 
        !           722:                if (lw == IDCANCEL)
        !           723:                {
        !           724:                        EndDialog (hwndDlg, lw);
        !           725:                        return 1;
        !           726:                }
        !           727: 
        !           728:                if (lw == IDOK)
        !           729:                {
        !           730:                        EndDialog (hwndDlg, lw);
        !           731:                        return 1;
        !           732:                }
        !           733:                return 0;
        !           734:        }
        !           735: 
        !           736:        return 0;
        !           737: }
        !           738: 
        !           739: void
        !           740: BuildTree (HWND hTree)
        !           741: {
        !           742:        HIMAGELIST hList;
        !           743:        HBITMAP hBitmap, hBitmapMask;
        !           744:        LVCOLUMN lvCol;
        !           745:        SendMessage(hTree,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
        !           746:                LVS_EX_FULLROWSELECT
        !           747:                |LVS_EX_HEADERDRAGDROP 
        !           748:                //|LVS_EX_GRIDLINES 
        !           749:                //|LVS_EX_TWOCLICKACTIVATE 
        !           750:                ); 
        !           751: 
        !           752:        memset(&lvCol,0,sizeof(lvCol)); 
        !           753: 
        !           754:        lvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;  
        !           755:        lvCol.pszText="Drive";                           
        !           756:        lvCol.cx=40;
        !           757:        lvCol.fmt = LVCFMT_COL_HAS_IMAGES|LVCFMT_LEFT ;
        !           758:        SendMessage (hTree,LVM_INSERTCOLUMN,0,(LPARAM)&lvCol);
        !           759: 
        !           760:        lvCol.pszText="Volume";  
        !           761:        lvCol.cx=290;           
        !           762:        lvCol.fmt = LVCFMT_LEFT;
        !           763:        SendMessage (hTree,LVM_INSERTCOLUMN,1,(LPARAM)&lvCol);
        !           764: 
        !           765:        lvCol.pszText="Size";  
        !           766:        lvCol.cx=80;
        !           767:        lvCol.fmt = LVCFMT_RIGHT;
        !           768:        SendMessage (hTree,LVM_INSERTCOLUMN,2,(LPARAM)&lvCol);
        !           769: 
        !           770:        lvCol.pszText="Cipher";  
        !           771:        lvCol.cx=110;
        !           772:        lvCol.fmt = LVCFMT_LEFT;
        !           773:        SendMessage (hTree,LVM_INSERTCOLUMN,3,(LPARAM)&lvCol);
        !           774: 
        !           775:        hBitmap = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON));
        !           776:        if (hBitmap == NULL)
        !           777:                return;
        !           778:        hBitmapMask = LoadBitmap (hInst, MAKEINTRESOURCE (IDB_DRIVEICON_MASK));
        !           779: 
        !           780:        hList = ImageList_Create (16, 12, ILC_COLOR8|ILC_MASK, 2, 2);
        !           781:        if (ImageList_Add (hList, hBitmap, hBitmapMask) == -1)
        !           782:        {
        !           783:                DeleteObject (hBitmap);
        !           784:                return;
        !           785:        }
        !           786:        else
        !           787:                DeleteObject (hBitmap);
        !           788: 
        !           789:        ListView_SetImageList (hTree, hList, LVSIL_NORMAL); 
        !           790:        ListView_SetImageList (hTree, hList, LVSIL_SMALL);
        !           791: 
        !           792:        LoadDriveLetters (hTree, 0);
        !           793: }
        !           794: 
        !           795: LPARAM
        !           796: GetSelectedLong (HWND hTree)
        !           797: {
        !           798:        int hItem = ListView_GetSelectionMark (hTree);
        !           799:        LVITEM item;
        !           800: 
        !           801:        if (nSelectedDriveIndex != 0)
        !           802:                hItem = nSelectedDriveIndex;
        !           803: 
        !           804:        memset(&item, 0, sizeof(LVITEM));
        !           805:        item.mask = LVIF_PARAM;
        !           806:        item.iItem = hItem;
        !           807: 
        !           808:        if (ListView_GetItem (hTree, &item) == FALSE)
        !           809:                return MAKELONG (0xffff, 0xffff);
        !           810:        else
        !           811:                return item.lParam;
        !           812: }
        !           813: 
        !           814: LPARAM
        !           815: GetItemLong (HWND hTree, int itemNo)
        !           816: {
        !           817:        LVITEM item;
        !           818: 
        !           819:        memset(&item, 0, sizeof(LVITEM));
        !           820:        item.mask = LVIF_PARAM;
        !           821:        item.iItem = itemNo;
        !           822: 
        !           823:        if (ListView_GetItem (hTree, &item) == FALSE)
        !           824:                return MAKELONG (0xffff, 0xffff);
        !           825:        else
        !           826:                return item.lParam;
        !           827: }
        !           828: 
        !           829: static BOOL MountVolume (HWND hwndDlg, int driveNo, char *volumePath, char *szPassword, int quiet)
        !           830: {
        !           831:        MOUNT_STRUCT driver;
        !           832:        DWORD dwResult;
        !           833:        BOOL bResult, bDevice;
        !           834: 
        !           835:        if (IsMountedVolume (volumePath))
        !           836:        {
        !           837:                if (!quiet)
        !           838:                        MessageBox(0, getstr (IDS_ALREADY_MOUNTED), lpszTitle, MB_ICONASTERISK);
        !           839:                return FALSE;
        !           840:        }
        !           841: 
        !           842:        driver.nDosDriveNo = driveNo;
        !           843:        driver.bCache = bCacheInDriver;
        !           844:        driver.time = time (NULL);
        !           845:        driver.nPasswordLen = strlen (szPassword);
        !           846:        strcpy (driver.szPassword, szPassword);
        !           847: 
        !           848:        CreateFullVolumePath ((char *) driver.wszVolume, volumePath, &bDevice);
        !           849: 
        !           850:        if (nCurrentOS == WIN_NT)
        !           851:                ToUNICODE ((char *) driver.wszVolume);
        !           852: 
        !           853:        bResult = DeviceIoControl (hDriver, MOUNT, &driver,
        !           854:                sizeof (driver), &driver, sizeof (driver), &dwResult, NULL);
        !           855: 
        !           856:        burn (&driver.szPassword, sizeof (driver.szPassword));
        !           857: 
        !           858:        if (bResult == FALSE)
        !           859:        {
        !           860:                if (!quiet)
        !           861:                        handleWin32Error (hwndDlg);
        !           862:                return bResult;
        !           863:        }
        !           864:        else
        !           865:        {
        !           866:                if (driver.nReturnCode == 0)
        !           867:                {
        !           868:                        if (nCurrentOS == WIN_NT)
        !           869:                        {
        !           870:                                char *lpszPipeName = "\\\\.\\pipe\\truecryptservice";
        !           871:                                DWORD bytesRead;
        !           872:                                char inbuf[80];
        !           873:                                char outbuf[80];
        !           874: 
        !           875:                                sprintf (outbuf, "mount %d", driver.nDosDriveNo);
        !           876: 
        !           877:                                bResult = CallNamedPipe (lpszPipeName,
        !           878:                                        outbuf, sizeof (outbuf),
        !           879:                                        inbuf, sizeof (inbuf),
        !           880:                                        &bytesRead, NMPWAIT_WAIT_FOREVER);
        !           881: 
        !           882:                                if (bResult == FALSE)
        !           883:                                {
        !           884:                                        handleWin32Error (hwndDlg);
        !           885:                                }
        !           886:                                else
        !           887:                                {
        !           888:                                        DWORD os_err = 0;
        !           889:                                        int err = 0;
        !           890: 
        !           891:                                        sscanf (inbuf, "%s %d %lu", outbuf, &err, &os_err);
        !           892: 
        !           893:                                        if (*inbuf == '-' && !quiet)
        !           894:                                        {
        !           895:                                                if (err == ERR_OS_ERROR)
        !           896:                                                {
        !           897:                                                        SetLastError (os_err);
        !           898:                                                        handleWin32Error (hwndDlg);
        !           899:                                                }
        !           900:                                                else
        !           901:                                                {
        !           902:                                                        handleError (hwndDlg, err);
        !           903:                                                }
        !           904: 
        !           905:                                                bResult = 0;
        !           906:                                        }
        !           907: 
        !           908:                                }
        !           909: 
        !           910:                                if (bResult == FALSE && !quiet)
        !           911:                                {
        !           912:                                        if (bQuiet == FALSE)
        !           913:                                                MessageBox (hwndDlg, getstr (IDS_SYMLINK), lpszTitle, ICON_HAND);
        !           914: 
        !           915:                                        return FALSE;
        !           916:                                }
        !           917: 
        !           918:                        }
        !           919:                        else 
        !           920:                        {
        !           921:                                EjectStop ((char)toupper(szFileName[0]), TRUE);
        !           922:                        }
        !           923:                }
        !           924:                else
        !           925:                {
        !           926:                        if (bQuiet == FALSE)
        !           927:                        {
        !           928:                                if (!quiet) handleError (hwndDlg, driver.nReturnCode);
        !           929:                        }
        !           930:                        else
        !           931:                                EndMainDlg (hwndDlg);
        !           932: 
        !           933:                        return FALSE;
        !           934:                }
        !           935:        }
        !           936: 
        !           937:        return TRUE;
        !           938: }
        !           939: 
        !           940: static BOOL IsPasswordCacheEmpty (void)
        !           941: {
        !           942:        DWORD dw;
        !           943:        return !DeviceIoControl (hDriver, CACHE_STATUS, 0, 0, 0, 0, &dw, 0);
        !           944: }
        !           945: 
        !           946: static BOOL IsMountedVolume (char *volname)
        !           947: {
        !           948:        MOUNT_LIST_STRUCT mlist;
        !           949:        DWORD dwResult;
        !           950:        int i;
        !           951:        char volume[TC_MAX_PATH*2+16];
        !           952: 
        !           953:        strcpy (volume, volname);
        !           954:        if (nCurrentOS == WIN_NT) 
        !           955:        {
        !           956:                if (strstr (volname, "\\Device\\") != volname)
        !           957:                        sprintf(volume, "\\??\\%s", volname);
        !           958:                ToUNICODE (volume);
        !           959:        }
        !           960: 
        !           961:        memset (&mlist, 0, sizeof (mlist));
        !           962:        DeviceIoControl (hDriver, MOUNT_LIST, &mlist,
        !           963:                sizeof (mlist), &mlist, sizeof (mlist), &dwResult,
        !           964:                NULL);
        !           965: 
        !           966:        for (i=0 ; i<26; i++)
        !           967:                if (nCurrentOS != WIN_NT && 0 == strcmp ((char *)mlist.wszVolume[i], volume) 
        !           968:                        || nCurrentOS == WIN_NT && 0 == wcscmp (mlist.wszVolume[i], (WCHAR *)volume))
        !           969:                        return TRUE;
        !           970: 
        !           971:        return FALSE;
        !           972: }
        !           973: 
        !           974: static int AskUserPassword (HWND hwndDlg, char *password)
        !           975: {
        !           976:        int result = DialogBoxParam (hInst, 
        !           977:                MAKEINTRESOURCE (IDD_PASSWORD_DLG), hwndDlg,
        !           978:                (DLGPROC) PasswordDlgProc, (LPARAM) password);
        !           979: 
        !           980:        if (result != IDOK)
        !           981:                *password = 0;
        !           982: 
        !           983:        return result == IDOK;
        !           984: }
        !           985: 
        !           986: // GUI actions
        !           987: 
        !           988: static void Mount (HWND hwndDlg)
        !           989: {
        !           990:        char szPassword[MAX_PASSWORD + 1];
        !           991:        int mounted = 0;
        !           992:        int nDosDriveNo = HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A';
        !           993: 
        !           994:        burn (szPassword, sizeof (szPassword));
        !           995:        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName,
        !           996:                sizeof (szFileName));
        !           997: 
        !           998:        if (strlen(szFileName) == 0)
        !           999:                return;
        !          1000: 
        !          1001:        if (IsMountedVolume (szFileName))
        !          1002:        {
        !          1003:                MessageBox(0, getstr (IDS_ALREADY_MOUNTED), lpszTitle, MB_ICONASTERISK);
        !          1004:                return;
        !          1005:        }
        !          1006: 
        !          1007:        // First try cached passwords and if they fail ask user for a new one
        !          1008:        ArrowWaitCursor ();
        !          1009:        mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, "", TRUE);
        !          1010:        NormalCursor ();
        !          1011:        
        !          1012:        while (!mounted)
        !          1013:        {
        !          1014:                if (!AskUserPassword (hwndDlg, szPassword))
        !          1015:                        return;
        !          1016: 
        !          1017:                ArrowWaitCursor ();
        !          1018:                mounted = MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, FALSE);
        !          1019:                NormalCursor ();
        !          1020:        }
        !          1021: 
        !          1022:        if (mounted)
        !          1023:        {
        !          1024:                if (bBeep == TRUE)
        !          1025:                        MessageBeep (MB_OK);
        !          1026: 
        !          1027:                RefreshMainDlg(hwndDlg);
        !          1028: 
        !          1029:                if (bExplore == TRUE)
        !          1030:                {       
        !          1031:                        ArrowWaitCursor();
        !          1032:                        OpenVolumeExplorerWindow (nDosDriveNo);
        !          1033:                        NormalCursor();
        !          1034:                }
        !          1035:        }
        !          1036: 
        !          1037:        burn (szPassword, sizeof (szPassword));
        !          1038:        return;
        !          1039: }
        !          1040: 
        !          1041: void OpenVolumeExplorerWindow (int driveNo)
        !          1042: {
        !          1043:        char dosName[5];
        !          1044:        SHFILEINFO fInfo;
        !          1045: 
        !          1046:        sprintf (dosName, "%c:\\", (char) driveNo + 'A');
        !          1047: 
        !          1048:        // Force explorer to discover the drive
        !          1049:        SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0);
        !          1050: 
        !          1051:        ShellExecute (NULL, "open", dosName, NULL, NULL, SW_SHOWNORMAL);
        !          1052: }
        !          1053: 
        !          1054: static BOOL CALLBACK CloseVolumeExplorerWindowsEnum( HWND hwnd, LPARAM driveNo)
        !          1055: {
        !          1056:        char get[128], driveStr[10];
        !          1057:        HWND h;
        !          1058: 
        !          1059:        GetClassName (hwnd, get, sizeof get);
        !          1060: 
        !          1061:        if (strcmp (get, "CabinetWClass") == 0)
        !          1062:        {
        !          1063:                sprintf (driveStr, "%c:\\", driveNo + 'A');
        !          1064: 
        !          1065:                // Title bar
        !          1066:                GetWindowText (hwnd, get, sizeof get);
        !          1067:                if (strstr (get, driveStr) == get)
        !          1068:                {
        !          1069:                        PostMessage (hwnd, WM_CLOSE, 0, 0);
        !          1070:                        return TRUE;
        !          1071:                }
        !          1072: 
        !          1073:                // URL edit box
        !          1074:                h = FindWindowEx (hwnd, 0, "WorkerW", 0);
        !          1075:                if (!h) return TRUE;
        !          1076:                h = FindWindowEx (h, 0, "ReBarWindow32", 0);
        !          1077:                if (!h) return TRUE;
        !          1078:                h = FindWindowEx (h, 0, "ComboBoxEx32", 0);
        !          1079:                if (h)
        !          1080:                {
        !          1081:                        SendMessage (h, WM_GETTEXT, sizeof get, (LPARAM) get);
        !          1082:                        if (strstr (get, driveStr) == get)
        !          1083:                                PostMessage (hwnd, WM_CLOSE, 0, 0);
        !          1084:                }
        !          1085:        }
        !          1086:        return TRUE;
        !          1087: }
        !          1088: 
        !          1089: void CloseVolumeExplorerWindows (HWND hwnd, int driveNo)
        !          1090: {
        !          1091:        EnumWindows (CloseVolumeExplorerWindowsEnum, (LPARAM) driveNo);
        !          1092: }
        !          1093: 
        !          1094: static void Dismount (HWND hwndDlg)
        !          1095: {
        !          1096:        char *lpszPipeName = "\\\\.\\pipe\\truecryptservice";
        !          1097:        DWORD bytesRead;
        !          1098:        BOOL bResult;
        !          1099:        int nDosDriveNo;
        !          1100:        char inbuf[80];
        !          1101:        char outbuf[80];
        !          1102: 
        !          1103:        nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) - 'A');
        !          1104: 
        !          1105:        if (nCurrentOS == WIN_NT)
        !          1106:        {
        !          1107: 
        !          1108:                if (bCloseDismountedWindows)
        !          1109:                        CloseVolumeExplorerWindows (hwndDlg, nDosDriveNo);
        !          1110: 
        !          1111:                /* Unmount the volume using the TrueCryptService,
        !          1112:                this is done to allow non-administrators
        !          1113:                to unmount volumes */
        !          1114: 
        !          1115:                sprintf (outbuf, "unmount %d", nDosDriveNo);
        !          1116: 
        !          1117:                ArrowWaitCursor ();
        !          1118: 
        !          1119:                bResult = CallNamedPipe (lpszPipeName,
        !          1120:                        outbuf, sizeof (outbuf),
        !          1121:                        inbuf, sizeof (inbuf),
        !          1122:                        &bytesRead, NMPWAIT_WAIT_FOREVER);
        !          1123: 
        !          1124:                NormalCursor ();
        !          1125: 
        !          1126:                if (bResult == FALSE)
        !          1127:                {
        !          1128:                        handleWin32Error (hwndDlg);
        !          1129:                }
        !          1130:                else
        !          1131:                {
        !          1132:                        DWORD os_err = 0;
        !          1133:                        int err = 0;
        !          1134: 
        !          1135:                        sscanf (inbuf, "%s %d %lu", outbuf, &err, &os_err);
        !          1136: 
        !          1137:                        if (*inbuf == '-')
        !          1138:                        {
        !          1139:                                //if (err == ERR_OS_ERROR)
        !          1140:                                //{
        !          1141:                                //      SetLastError (os_err);
        !          1142: 
        !          1143:                                //      handleWin32Error (hwndDlg);
        !          1144:                                //}
        !          1145:                                //else
        !          1146:                                //{
        !          1147:                                //      handleError (hwndDlg, err);
        !          1148:                                //}
        !          1149:                                MessageBox(0, getstr (IDS_UNMOUNT_FAILED), lpszTitle, MB_ICONEXCLAMATION);
        !          1150:                        } 
        !          1151:                        else
        !          1152:                        {
        !          1153:                                //if (bBeep == TRUE)
        !          1154:                                //      MessageBeep (MB_OK);
        !          1155: 
        !          1156:                                RefreshMainDlg(hwndDlg);
        !          1157:                        }
        !          1158:                }
        !          1159: 
        !          1160:        }
        !          1161:        else
        !          1162:        {
        !          1163:                int err = 0;
        !          1164: 
        !          1165:                bResult = CloseSlot (nDosDriveNo, 0, &err);
        !          1166: 
        !          1167:                if (bResult == FALSE)
        !          1168:                {
        !          1169:                        handleWin32Error (hwndDlg);
        !          1170:                }
        !          1171:                else
        !          1172:                {
        !          1173:                        if (err != 0)
        !          1174:                        {
        !          1175:                                //handleError (hwndDlg, err);
        !          1176:                                MessageBox(0, getstr (IDS_UNMOUNT_FAILED), lpszTitle, MB_ICONEXCLAMATION);
        !          1177:                        }
        !          1178:                        else
        !          1179:                        {
        !          1180:                                //if (bBeep == TRUE)
        !          1181:                                //      MessageBeep (MB_OK);
        !          1182: 
        !          1183:                                RefreshMainDlg(hwndDlg);
        !          1184:                        }
        !          1185:                }
        !          1186:        }
        !          1187: 
        !          1188:        return;
        !          1189: }
        !          1190: 
        !          1191: 
        !          1192: 
        !          1193: static void DismountAll (HWND hwndDlg)
        !          1194: {
        !          1195:        char *lpszPipeName = "\\\\.\\pipe\\truecryptservice";
        !          1196:        DWORD bytesRead;
        !          1197:        BOOL bResult;
        !          1198:        int nDosDriveNo;
        !          1199:        char inbuf[80];
        !          1200:        char outbuf[80];
        !          1201: 
        !          1202:        nDosDriveNo = (char) (HIWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) -
        !          1203:                'A');
        !          1204: 
        !          1205:        ArrowWaitCursor();
        !          1206: 
        !          1207:        if (nCurrentOS == WIN_NT)
        !          1208:        {
        !          1209:                if (bCloseDismountedWindows)
        !          1210:                {
        !          1211:                        MOUNT_LIST_STRUCT driver;
        !          1212:                        DWORD dwResult;
        !          1213: 
        !          1214:                        if (DeviceIoControl (hDriver, MOUNT_LIST, &driver, sizeof (driver), &driver, sizeof (driver), &dwResult, NULL))
        !          1215:                        {
        !          1216:                                int i;
        !          1217:                                for (i = 0; i < 26; i++)
        !          1218:                                        if ((driver.ulMountedDrives & 1 << i))
        !          1219:                                                CloseVolumeExplorerWindows (hwndDlg, i); 
        !          1220: 
        !          1221:                        }
        !          1222:                }
        !          1223: 
        !          1224:                /* Unmount the volume using the TrueCryptService,
        !          1225:                this is done to allow non-administrators
        !          1226:                to unmount volumes */
        !          1227: 
        !          1228:                strcpy (outbuf, "unmountall");
        !          1229: 
        !          1230:                ArrowWaitCursor ();
        !          1231: 
        !          1232:                bResult = CallNamedPipe (lpszPipeName,
        !          1233:                        outbuf, sizeof (outbuf),
        !          1234:                        inbuf, sizeof (inbuf),
        !          1235:                        &bytesRead, NMPWAIT_WAIT_FOREVER);
        !          1236: 
        !          1237:                NormalCursor ();
        !          1238: 
        !          1239:                if (bResult == FALSE)
        !          1240:                {
        !          1241:                        handleWin32Error (hwndDlg);
        !          1242:                }
        !          1243:                else
        !          1244:                {
        !          1245:                        DWORD os_err = 0;
        !          1246:                        int err = 0;
        !          1247: 
        !          1248:                        sscanf (inbuf, "%s %d %lu", outbuf, &err, &os_err);
        !          1249: 
        !          1250:                        if (*inbuf == '-')
        !          1251:                        {
        !          1252:                                //if (err == ERR_OS_ERROR)
        !          1253:                                //{
        !          1254:                                //      SetLastError (os_err);
        !          1255: 
        !          1256:                                //      handleWin32Error (hwndDlg);
        !          1257:                                //}
        !          1258:                                //else
        !          1259:                                //{
        !          1260:                                //      handleError (hwndDlg, err);
        !          1261:                                //}
        !          1262: 
        !          1263:                                RefreshMainDlg(hwndDlg);
        !          1264:                                MessageBox(0, getstr (IDS_UNMOUNT_FAILED), lpszTitle, MB_ICONEXCLAMATION);
        !          1265:                        }
        !          1266:                        else
        !          1267:                        {
        !          1268:                                if (bBeep == TRUE)
        !          1269:                                        MessageBeep (MB_OK);
        !          1270:                        }
        !          1271:                }
        !          1272:        }
        !          1273:        else
        !          1274:        {
        !          1275:                DWORD os_error;
        !          1276:                int i, err;
        !          1277: 
        !          1278:                for (i=0; i<26; i++)
        !          1279:                        CloseSlot (i, 0, &err);
        !          1280:        }
        !          1281: 
        !          1282:        RefreshMainDlg (hwndDlg);
        !          1283:        NormalCursor();
        !          1284: }
        !          1285: 
        !          1286: static void MountAllPartitions (HWND hwndDlg)
        !          1287: {
        !          1288:        HWND driveList = GetDlgItem (hwndDlg, IDC_DRIVELIST);
        !          1289:        int i, n, selDrive = ListView_GetSelectionMark (driveList);
        !          1290:        char szPassword[MAX_PASSWORD + 1];
        !          1291: 
        !          1292:        // User is always asked for password as we can't tell 
        !          1293:        // for sure if it is needed or not
        !          1294:        burn (szPassword, sizeof (szPassword));
        !          1295:        if (!AskUserPassword (hwndDlg, szPassword))
        !          1296:                return;
        !          1297: 
        !          1298:        ArrowWaitCursor();
        !          1299:        
        !          1300:        for (i = 0; i < 64; i++)
        !          1301:        {
        !          1302:                BOOL drivePresent = FALSE;
        !          1303: 
        !          1304:                for (n = 1; n <= 32; n++)
        !          1305:                {
        !          1306:                        char szFileName[TC_MAX_PATH];
        !          1307:                        OPEN_TEST_STRUCT driver;
        !          1308: 
        !          1309:                        sprintf (szFileName, "\\Device\\Harddisk%d\\Partition%d", i, n);
        !          1310:                        if (OpenDevice (szFileName, &driver) == TRUE && !IsMountedVolume (szFileName))
        !          1311:                        {       
        !          1312:                                int nDosDriveNo;
        !          1313: 
        !          1314:                                while (LOWORD (GetItemLong (driveList, selDrive)) != 0xffff)
        !          1315:                                {
        !          1316:                                        if(LOWORD (GetItemLong (driveList, selDrive)) != VFREE)
        !          1317:                                        {
        !          1318:                                                selDrive++;
        !          1319:                                                continue;
        !          1320:                                        }
        !          1321:                                        nDosDriveNo = HIWORD(GetItemLong (driveList, selDrive)) - 'A';
        !          1322:                                        break;
        !          1323:                                }
        !          1324: 
        !          1325:                                if (LOWORD (GetItemLong (driveList, selDrive)) == 0xffff)
        !          1326:                                        goto ret;
        !          1327: 
        !          1328:                                // First try user password then cached passwords
        !          1329:                                if (MountVolume (hwndDlg, nDosDriveNo, szFileName, szPassword, TRUE)
        !          1330:                                        || MountVolume (hwndDlg, nDosDriveNo, szFileName, "", TRUE))
        !          1331:                                {
        !          1332:                                        LoadDriveLetters (driveList, (HIWORD (GetItemLong (GetDlgItem (hwndDlg, IDC_DRIVELIST), selDrive))));
        !          1333:                                        selDrive++;
        !          1334: 
        !          1335:                                        if (bExplore == TRUE)
        !          1336:                                        {       
        !          1337:                                                ArrowWaitCursor();
        !          1338:                                                OpenVolumeExplorerWindow (nDosDriveNo);
        !          1339:                                                NormalCursor();
        !          1340:                                        }
        !          1341:                                }
        !          1342:                        }
        !          1343:                }
        !          1344:        }
        !          1345: 
        !          1346: ret:
        !          1347:        burn (szPassword, sizeof (szPassword));
        !          1348:        EnableDisableButtons (hwndDlg);
        !          1349:        NormalCursor();
        !          1350: }
        !          1351: 
        !          1352: static void ChangePassword (HWND hwndDlg)
        !          1353: {
        !          1354:        int result;
        !          1355:        
        !          1356:        GetWindowText (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, sizeof (szFileName));
        !          1357:        if (IsMountedVolume (szFileName))
        !          1358:        {
        !          1359:                MessageBox (hwndDlg, getstr (IDS_MOUNTED_NOPWCHANGE), lpszTitle, MB_ICONEXCLAMATION);
        !          1360:                return;
        !          1361:        }
        !          1362: 
        !          1363:        result = DialogBox (hInst, MAKEINTRESOURCE (IDD_PASSWORDCHANGE_DLG), hwndDlg,
        !          1364:                (DLGPROC) PasswordChangeDlgProc);
        !          1365: 
        !          1366:        if (result == IDOK)
        !          1367:        {
        !          1368:                HWND tmp = GetDlgItem (hwndDlg, IDC_PASSWORD);
        !          1369:                MessageBox (hwndDlg, getstr (IDS_PASSWORD_CHANGED), lpszTitle, MB_ICONASTERISK);
        !          1370:                SetFocus (tmp);
        !          1371:        }
        !          1372: }
        !          1373: 
        !          1374: static void SelectContainer (HWND hwndDlg)
        !          1375: {
        !          1376:        if (BrowseFiles (hwndDlg, IDS_OPEN_TITLE, szFileName) == FALSE)
        !          1377:                return;
        !          1378: 
        !          1379:        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
        !          1380:        EnableDisableButtons (hwndDlg);
        !          1381:        SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD));
        !          1382: }
        !          1383: 
        !          1384: static void SelectPartition (HWND hwndDlg)
        !          1385: {
        !          1386:        int nResult = DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_RAWDEVICES_DLG), hwndDlg,
        !          1387:                (DLGPROC) RawDevicesDlgProc, (LPARAM) & szFileName[0]);
        !          1388:        if (nResult == IDOK)
        !          1389:        {
        !          1390:                AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
        !          1391:                EnableDisableButtons (hwndDlg);
        !          1392:                SetFocus (GetDlgItem (hwndDlg, IDC_PASSWORD));
        !          1393:        }
        !          1394: }
        !          1395: 
        !          1396: static void WipeCache (HWND hwndDlg)
        !          1397: {
        !          1398:        DWORD dwResult;
        !          1399:        BOOL bResult;
        !          1400: 
        !          1401:        bResult = DeviceIoControl (hDriver, WIPE_CACHE, NULL, 0, NULL, 0, &dwResult, NULL);
        !          1402: 
        !          1403:        if (bResult == FALSE)
        !          1404:                handleWin32Error (hwndDlg);
        !          1405:        else
        !          1406:        {
        !          1407:                EnableDisableButtons (hwndDlg);
        !          1408: 
        !          1409:                if (bQuiet == FALSE)
        !          1410:                        MessageBox (hwndDlg, getstr (IDS_WIPE_CACHE), lpszTitle, MB_ICONINFORMATION);
        !          1411:        }
        !          1412: }
        !          1413: 
        !          1414: 
        !          1415: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
        !          1416:    should return nonzero if it processes the message, and zero if it does
        !          1417:    not. - see DialogProc */
        !          1418: BOOL CALLBACK
        !          1419: MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
        !          1420: {
        !          1421:        WORD lw = LOWORD (wParam);
        !          1422:        WORD hw = HIWORD (wParam);
        !          1423:        if (lParam);            /* remove warning */
        !          1424: 
        !          1425:        switch (uMsg)
        !          1426:        {
        !          1427: 
        !          1428:        case WM_INITDIALOG:
        !          1429:                {
        !          1430:                        LoadSettings (hwndDlg);
        !          1431: 
        !          1432:                        /* Call the common dialog init code */
        !          1433:                        InitDialog (hwndDlg);
        !          1434:                        SetDefaultUserFont (hwndDlg);
        !          1435: 
        !          1436:                        SendMessage (GetDlgItem (hwndDlg, IDC_VOLUME), CB_LIMITTEXT, TC_MAX_PATH, 0);
        !          1437: 
        !          1438:                        SendMessage (GetDlgItem (hwndDlg, IDC_NO_DRIVES_STATIC), WM_SETFONT, (WPARAM) hBoldFont, (LPARAM) TRUE);
        !          1439:                        SetWindowText (hwndDlg, lpszTitle);
        !          1440: 
        !          1441:                        BuildTree (GetDlgItem (hwndDlg, IDC_DRIVELIST));
        !          1442: 
        !          1443:                        ExtractCommandLine (hwndDlg, (char *) lParam);
        !          1444: 
        !          1445:                        if (*szDriveLetter != 0)
        !          1446:                        {
        !          1447:                                SelectItem (GetDlgItem (hwndDlg, IDC_DRIVELIST), *szDriveLetter);
        !          1448: 
        !          1449:                                if(nSelectedDriveIndex > SendMessage (GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_GETITEMCOUNT, 0, 0)/2) 
        !          1450:                                        SendMessage(GetDlgItem (hwndDlg, IDC_DRIVELIST), LVM_SCROLL, 0, 1000);
        !          1451:                        }
        !          1452: 
        !          1453:                        SendMessage (GetDlgItem (hwndDlg, IDC_NO_HISTORY), BM_SETCHECK, bHistory ? BST_UNCHECKED : BST_CHECKED, 0);
        !          1454: 
        !          1455:                        EnableDisableButtons (hwndDlg);
        !          1456: 
        !          1457:                        if (bWipe == TRUE)
        !          1458:                        {
        !          1459:                                SendMessage (GetDlgItem (hwndDlg, IDC_WIPE_CACHE), BM_CLICK, 0, 0);
        !          1460:                        }
        !          1461: 
        !          1462:                        if (bAuto == TRUE && IsWindowEnabled (GetDlgItem (hwndDlg, IDOK)))
        !          1463:                        {
        !          1464:                                SendMessage (GetDlgItem (hwndDlg, IDOK), BM_CLICK, 0, 0);
        !          1465:                        }
        !          1466: 
        !          1467:                        SetFocus (GetDlgItem (hwndDlg, IDC_DRIVELIST));
        !          1468:                }
        !          1469:                return 0;
        !          1470: 
        !          1471:        case WM_SYSCOMMAND:
        !          1472:                if (lw == IDC_ABOUT)
        !          1473:                {
        !          1474:                        DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
        !          1475:                        return 1;
        !          1476:                }
        !          1477:                return 0;
        !          1478: 
        !          1479:        case WM_HELP:
        !          1480:                OpenPageHelp (hwndDlg);
        !          1481:                return 1;
        !          1482: 
        !          1483:        case WM_NOTIFY:
        !          1484:                // Single click in drive list
        !          1485:                if (((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
        !          1486:                {
        !          1487:                        nSelectedDriveIndex = ((LPNMLISTVIEW) lParam)->iItem;
        !          1488:                        EnableDisableButtons (hwndDlg);
        !          1489: 
        !          1490:                        return 1;
        !          1491:                }
        !          1492: 
        !          1493:                // Double click in drive list
        !          1494:                if (((LPNMHDR) lParam)->code == LVN_ITEMACTIVATE)
        !          1495:                {
        !          1496:                        int state = GetItemLong(GetDlgItem (hwndDlg, IDC_DRIVELIST), ((LPNMITEMACTIVATE)lParam)->iItem );
        !          1497:                        nSelectedDriveIndex = ((LPNMITEMACTIVATE)lParam)->iItem;
        !          1498:                        if (LOWORD(state) == VMOUNTED)
        !          1499:                        {
        !          1500:                                // Open explorer window for mounted volume
        !          1501:                                ArrowWaitCursor ();
        !          1502:                                OpenVolumeExplorerWindow (HIWORD(state) - 'A');
        !          1503:                                NormalCursor ();
        !          1504:                        }
        !          1505:                        else if (LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
        !          1506:                        {
        !          1507:                                Mount (hwndDlg);
        !          1508:                        }
        !          1509:                }
        !          1510:                return 0;
        !          1511: 
        !          1512:        case WM_ERASEBKGND:
        !          1513:                return 0;
        !          1514: 
        !          1515:        case WM_COMMAND:
        !          1516: 
        !          1517:                if (lw == IDCANCEL)
        !          1518:                {
        !          1519:                        EndMainDlg (hwndDlg);
        !          1520:                        return 1;
        !          1521:                }
        !          1522: 
        !          1523:                if (lw == IDHELP || lw == IDM_HELP)
        !          1524:                {
        !          1525:                        OpenPageHelp (hwndDlg);
        !          1526:                        return 1;
        !          1527:                }
        !          1528: 
        !          1529:                if (lw == IDM_ABOUT || lw == IDB_LOGO)
        !          1530:                {
        !          1531:                        DialogBox (hInst, MAKEINTRESOURCE (IDD_ABOUT_DLG), hwndDlg, (DLGPROC) AboutDlgProc);
        !          1532:                        return 1;
        !          1533:                }
        !          1534: 
        !          1535:                if ((lw == IDOK || lw == ID_MOUNT_VOLUME) 
        !          1536:                        && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VFREE)
        !          1537:                {
        !          1538: 
        !          1539:                        Mount (hwndDlg);
        !          1540:                        return 1;
        !          1541:                }
        !          1542: 
        !          1543:                if ((lw == IDOK || lw == ID_MOUNT_VOLUME || lw == IDC_MOUNTALL) 
        !          1544:                        && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == 0xffff)
        !          1545:                {
        !          1546:                        MessageBox (hwndDlg, "No drive selected.","TrueCrypt", MB_ICONEXCLAMATION);
        !          1547:                        return 1;
        !          1548:                }
        !          1549: 
        !          1550:                if (lw == IDOK && LOWORD (GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST))) == VMOUNTED
        !          1551:                        || lw == ID_UNMOUNT_VOLUME)
        !          1552:                {
        !          1553:                        Dismount (hwndDlg);
        !          1554:                        return 1;
        !          1555:                }
        !          1556: 
        !          1557:                if (lw == IDUNMOUNTALL)
        !          1558:                {
        !          1559:                        DismountAll (hwndDlg);
        !          1560:                        return 1;
        !          1561:                }
        !          1562: 
        !          1563:                if (lw == IDC_MOUNTALL)
        !          1564:                {
        !          1565:                        MountAllPartitions (hwndDlg);
        !          1566:                        return 1;
        !          1567:                }
        !          1568:                
        !          1569:                if (lw == IDC_BROWSE_FILES)
        !          1570:                {
        !          1571:                        SelectContainer (hwndDlg);
        !          1572:                        return 1;
        !          1573:                }
        !          1574: 
        !          1575:                if (lw == IDC_BROWSE_DEVICES)
        !          1576:                {
        !          1577:                        SelectPartition (hwndDlg);
        !          1578:                        return 1;
        !          1579:                }
        !          1580: 
        !          1581:                if (lw == IDC_CHANGE_PASSWORD)
        !          1582:                {
        !          1583:                        ChangePassword (hwndDlg);
        !          1584:                        return 1;
        !          1585:                }
        !          1586: 
        !          1587:                if (lw == IDC_WIPE_CACHE)
        !          1588:                {
        !          1589:                        WipeCache (hwndDlg);
        !          1590:                        return 1;
        !          1591:                }
        !          1592: 
        !          1593:                if (lw == IDC_CLEAR_HISTORY)
        !          1594:                {
        !          1595:                        ClearCombo (GetDlgItem (hwndDlg, IDC_VOLUME));
        !          1596:                        DumpCombo (GetDlgItem (hwndDlg, IDC_VOLUME), "LastMountedVolume", TRUE);
        !          1597:                        EnableDisableButtons (hwndDlg);
        !          1598:                        return 1;
        !          1599:                }
        !          1600: 
        !          1601:                if (lw == IDC_CREATE_VOLUME)
        !          1602:                {
        !          1603:                        char t[TC_MAX_PATH];
        !          1604:                        char *tmp;
        !          1605: 
        !          1606:                        GetModuleFileName (NULL, t, sizeof (t));
        !          1607:                        tmp = strrchr (t, '\\');
        !          1608:                        if (tmp)
        !          1609:                        {
        !          1610:                                strcpy (++tmp, "TrueCrypt Format.exe");
        !          1611:                                ShellExecute (NULL, "open", t, NULL, NULL, SW_SHOWNORMAL);
        !          1612:                        }
        !          1613:                        return 1;
        !          1614:                }
        !          1615: 
        !          1616:                if (lw == ID_WEBSITE)
        !          1617:                {
        !          1618:                        ShellExecute (NULL, "open", "http://www.truecrypt.org", NULL, NULL, SW_SHOWNORMAL);
        !          1619:                        return 1;
        !          1620:                }
        !          1621:                
        !          1622:                if (lw == ID_PREFERENCES)
        !          1623:                {
        !          1624:                        DialogBoxParam (hInst, 
        !          1625:                                MAKEINTRESOURCE (IDD_PREFERENCES_DLG), hwndDlg,
        !          1626:                                (DLGPROC) PreferencesDlgProc, (LPARAM) 0);
        !          1627:                        return 1;
        !          1628:                }
        !          1629: 
        !          1630:                if (lw == IDC_VOLUME_PROPERTIES)
        !          1631:                {
        !          1632:                        DialogBoxParam (hInst, 
        !          1633:                                MAKEINTRESOURCE (IDD_VOLUME_PROPERTIES), hwndDlg,
        !          1634:                                (DLGPROC) VolumePropertiesDlgProc, (LPARAM) 0);
        !          1635:                        return 1;
        !          1636:                }
        !          1637: 
        !          1638:                if (lw == IDC_VOLUME && hw == CBN_EDITCHANGE)
        !          1639:                {
        !          1640:                        PostMessage (hwndDlg, WM_USER, 0, 0);
        !          1641:                        return 1;
        !          1642:                }
        !          1643: 
        !          1644:                if (lw == IDC_VOLUME && hw == CBN_SELCHANGE)
        !          1645:                {
        !          1646:                        UpdateComboOrder (GetDlgItem (hwndDlg, IDC_VOLUME));
        !          1647:                        MoveEditToCombo ((HWND) lParam);
        !          1648:                        PostMessage (hwndDlg, WM_USER, 0, 0);
        !          1649:                        return 1;
        !          1650:                }
        !          1651: 
        !          1652:                return 0;
        !          1653: 
        !          1654:        case WM_USER:
        !          1655:                EnableDisableButtons (hwndDlg);
        !          1656:                return 1;
        !          1657: 
        !          1658:        case WM_CLOSE:
        !          1659:                EndMainDlg (hwndDlg);
        !          1660:                return 1;
        !          1661:        }
        !          1662: 
        !          1663:        return 0;
        !          1664: }
        !          1665: 
        !          1666: void
        !          1667: ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
        !          1668: {
        !          1669:        char **lpszCommandLineArgs;     /* Array of command line arguments */
        !          1670:        int nNoCommandLineArgs; /* The number of arguments in the array */
        !          1671: 
        !          1672:        /* Extract command line arguments */
        !          1673:        nNoCommandLineArgs = Win32CommandLine (lpszCommandLine, &lpszCommandLineArgs);
        !          1674:        if (nNoCommandLineArgs > 0)
        !          1675:        {
        !          1676:                int i;
        !          1677: 
        !          1678:                for (i = 0; i < nNoCommandLineArgs; i++)
        !          1679:                {
        !          1680:                        argument args[]=
        !          1681:                        {
        !          1682:                                {"/volume", "/v"},
        !          1683:                                {"/letter", "/l"},
        !          1684:                                {"/explore", "/e"},
        !          1685:                                {"/beep", "/b"},
        !          1686:                                {"/password", "/p"},
        !          1687:                                {"/auto", "/a"},
        !          1688:                                {"/cache", "/c"},
        !          1689:                                {"/history", "/h"},
        !          1690:                                {"/wipecache", "/wc"},
        !          1691:                                {"/quiet", "/q"},
        !          1692:                                {"/help", "/?"},
        !          1693:                                {"/dismountall", "/d"}
        !          1694:                        };
        !          1695: 
        !          1696:                        argumentspec as;
        !          1697: 
        !          1698:                        int nArgPos;
        !          1699:                        int x;
        !          1700: 
        !          1701:                        as.args = args;
        !          1702:                        as.arg_cnt = sizeof(args)/ sizeof(args[0]);
        !          1703:                        
        !          1704:                        x = GetArgumentID (&as, lpszCommandLineArgs[i], &nArgPos);
        !          1705: 
        !          1706:                        switch (x)
        !          1707:                        {
        !          1708:                        case 'd':
        !          1709:                                DismountAll (hwndDlg);
        !          1710:                                ExitProcess (0);
        !          1711:                                break;
        !          1712: 
        !          1713:                        case 'v':
        !          1714:                                if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, nArgPos, &i,
        !          1715:                                                                      nNoCommandLineArgs, szFileName, sizeof (szFileName)))
        !          1716:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName);
        !          1717:                                break;
        !          1718: 
        !          1719:                        case 'l':
        !          1720:                                GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
        !          1721:                                     szDriveLetter, sizeof (szDriveLetter));
        !          1722:                                *szDriveLetter = (char) toupper (*szDriveLetter);
        !          1723:                                break;
        !          1724: 
        !          1725:                        case 'e':
        !          1726:                                bExplore = TRUE;
        !          1727:                                break;
        !          1728: 
        !          1729:                        case 'b':
        !          1730:                                bBeep = TRUE;
        !          1731:                                break;
        !          1732: 
        !          1733:                        case 'p':
        !          1734:                                {
        !          1735:                                        char szTmp[MAX_PASSWORD + 1];
        !          1736:                                        
        !          1737:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
        !          1738:                                                     szTmp, sizeof (szTmp));
        !          1739: 
        !          1740:                                        if (strlen(szTmp) == 1 && *szTmp == '?') 
        !          1741:                                        {
        !          1742: 
        !          1743:                                                int result = DialogBoxParam (hInst, 
        !          1744:                                                                        MAKEINTRESOURCE (IDD_PASSWORD_DLG), hwndDlg,
        !          1745:                                                                        (DLGPROC) PasswordDlgProc, (LPARAM) szTmp);
        !          1746: 
        !          1747:                                                if (result != IDOK)
        !          1748:                                                        *szTmp = 0;
        !          1749:                                        }
        !          1750: 
        !          1751:                                        SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), szTmp);
        !          1752:                                        burn (szTmp, sizeof (szTmp));
        !          1753:                                }
        !          1754:                                break;
        !          1755: 
        !          1756:                        case 'a':
        !          1757:                                bAuto = TRUE;
        !          1758:                                break;
        !          1759: 
        !          1760:                        case 'c':
        !          1761:                                {
        !          1762:                                        char szTmp[8];
        !          1763:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
        !          1764:                                                     szTmp, sizeof (szTmp));
        !          1765:                                        if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
        !          1766:                                                bCacheInDriver = TRUE;
        !          1767:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
        !          1768:                                                bCacheInDriver = FALSE;
        !          1769:                                }
        !          1770:                                break;
        !          1771: 
        !          1772:                        case 'h':
        !          1773:                                {
        !          1774:                                        char szTmp[8];
        !          1775:                                        GetArgumentValue (lpszCommandLineArgs, nArgPos, &i, nNoCommandLineArgs,
        !          1776:                                                     szTmp, sizeof (szTmp));
        !          1777:                                        if (!_stricmp(szTmp,"y") || !_stricmp(szTmp,"yes"))
        !          1778:                                        {
        !          1779:                                                bHistory = TRUE;
        !          1780:                                                bHistoryCmdLine = TRUE;
        !          1781:                                        }
        !          1782: 
        !          1783:                                        if (!_stricmp(szTmp,"n") || !_stricmp(szTmp,"no"))
        !          1784:                                        {
        !          1785:                                                bHistory = FALSE;
        !          1786:                                                bHistoryCmdLine = TRUE;
        !          1787:                                        }
        !          1788:                                }
        !          1789:                                break;
        !          1790: 
        !          1791:                        case 'w':
        !          1792:                                bWipe = TRUE;
        !          1793:                                break;
        !          1794: 
        !          1795:                        case 'q':
        !          1796:                                bQuiet = TRUE;
        !          1797:                                break;
        !          1798: 
        !          1799:                        case '?':
        !          1800:                                DialogBoxParam (hInst, MAKEINTRESOURCE (IDD_COMMANDHELP_DLG), hwndDlg, (DLGPROC)
        !          1801:                                                CommandHelpDlgProc, (LPARAM) &as);
        !          1802:                                exit(0);
        !          1803:                                break;
        !          1804: 
        !          1805:                                // no option = file name
        !          1806:                        default:
        !          1807:                                        AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), lpszCommandLineArgs[0]);
        !          1808:                        }
        !          1809:                }
        !          1810:        }
        !          1811: 
        !          1812:        /* Free up the command line arguments */
        !          1813:        while (--nNoCommandLineArgs >= 0)
        !          1814:        {
        !          1815:                free (lpszCommandLineArgs[nNoCommandLineArgs]);
        !          1816:        }
        !          1817: }
        !          1818: 
        !          1819: int WINAPI
        !          1820: WINMAIN (HINSTANCE hInstance, HINSTANCE hPrevInstance, char *lpszCommandLine,
        !          1821:         int nCmdShow)
        !          1822: {
        !          1823:        int status;
        !          1824: 
        !          1825:        if (nCmdShow && hPrevInstance); /* Remove unused parameter warning */
        !          1826: 
        !          1827:        atexit (localcleanup);
        !          1828: 
        !          1829:        /* Allocate, dup, then store away the application title */
        !          1830:        lpszTitle = err_strdup (getstr (IDS_TITLE));
        !          1831: 
        !          1832:        /* Call InitApp to initialize the common code */
        !          1833:        InitApp (hInstance);
        !          1834: 
        !          1835:        status = DriverAttach ();
        !          1836:        if (status != 0)
        !          1837:        {
        !          1838:                if (status == ERR_OS_ERROR)
        !          1839:                        handleWin32Error (NULL);
        !          1840:                else
        !          1841:                        handleError (NULL, status);
        !          1842: 
        !          1843:                AbortProcess (IDS_NODRIVER);
        !          1844:        }
        !          1845: 
        !          1846:        /* Create the main dialog box */
        !          1847:        DialogBoxParam (hInstance, MAKEINTRESOURCE (IDD_MOUNT_DLG), NULL, (DLGPROC) MainDialogProc,
        !          1848:                        (LPARAM) lpszCommandLine);
        !          1849: 
        !          1850:        /* Terminate */
        !          1851:        return 0;
        !          1852: }

unix.superglobalmegacorp.com

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