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

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

unix.superglobalmegacorp.com

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