Annotation of truecrypt/mount/maincom.cpp, revision 1.1.1.10

1.1       root        1: /*
1.1.1.10! root        2:  Copyright (c) 2007-2010 TrueCrypt Developers Association. All rights reserved.
1.1       root        3: 
1.1.1.10! root        4:  Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.9   root        5:  the file License.txt included in TrueCrypt binary and source code distribution
                      6:  packages.
1.1       root        7: */
                      8: 
                      9: #include <atlcomcli.h>
                     10: #include <atlconv.h>
                     11: #include <windows.h>
                     12: #include "BaseCom.h"
1.1.1.3   root       13: #include "BootEncryption.h"
1.1       root       14: #include "Dlgcode.h"
                     15: #include "MainCom.h"
                     16: #include "MainCom_h.h"
                     17: #include "MainCom_i.c"
1.1.1.4   root       18: #include "Mount.h"
1.1       root       19: #include "Password.h"
                     20: 
1.1.1.3   root       21: using namespace TrueCrypt;
                     22: 
1.1       root       23: static volatile LONG ObjectCount = 0;
                     24: 
1.1.1.3   root       25: class TrueCryptMainCom : public ITrueCryptMainCom
1.1       root       26: {
                     27: 
                     28: public:
1.1.1.3   root       29:        TrueCryptMainCom (DWORD messageThreadId) : RefCount (0), MessageThreadId (messageThreadId)
1.1       root       30:        {
                     31:                InterlockedIncrement (&ObjectCount);
                     32:        }
                     33: 
1.1.1.3   root       34:        ~TrueCryptMainCom ()
1.1       root       35:        {
                     36:                if (InterlockedDecrement (&ObjectCount) == 0)
                     37:                        PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
                     38:        }
                     39: 
                     40:        virtual ULONG STDMETHODCALLTYPE AddRef ()
                     41:        {
                     42:                return InterlockedIncrement (&RefCount);
                     43:        }
                     44: 
                     45:        virtual ULONG STDMETHODCALLTYPE Release ()
                     46:        {
                     47:                if (!InterlockedDecrement (&RefCount))
                     48:                {
                     49:                        delete this;
                     50:                        return 0;
                     51:                }
                     52: 
                     53:                return RefCount;
                     54:        }
                     55: 
                     56:        virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
                     57:        {
1.1.1.3   root       58:                if (riid == IID_IUnknown || riid == IID_ITrueCryptMainCom)
1.1       root       59:                        *ppvObject = this;
                     60:                else
                     61:                {
                     62:                        *ppvObject = NULL;
                     63:                        return E_NOINTERFACE;
                     64:                }
                     65: 
                     66:                AddRef ();
                     67:                return S_OK;
                     68:        }
1.1.1.10! root       69: 
        !            70:        virtual void STDMETHODCALLTYPE AnalyzeKernelMiniDump (LONG_PTR hwndDlg)
        !            71:        {
        !            72:                MainDlg = (HWND) hwndDlg;
        !            73:                ::AnalyzeKernelMiniDump ((HWND) hwndDlg);
        !            74:        }
        !            75: 
1.1       root       76:        virtual int STDMETHODCALLTYPE BackupVolumeHeader (LONG_PTR hwndDlg, BOOL bRequireConfirmation, BSTR lpszVolume)
                     77:        {
                     78:                USES_CONVERSION;
1.1.1.4   root       79:                MainDlg = (HWND) hwndDlg;
1.1       root       80:                return ::BackupVolumeHeader ((HWND) hwndDlg, bRequireConfirmation, CW2A (lpszVolume));
                     81:        }
                     82: 
                     83:        virtual int STDMETHODCALLTYPE RestoreVolumeHeader (LONG_PTR hwndDlg, BSTR lpszVolume)
                     84:        {
                     85:                USES_CONVERSION;
1.1.1.4   root       86:                MainDlg = (HWND) hwndDlg;
1.1       root       87:                return ::RestoreVolumeHeader ((HWND) hwndDlg, CW2A (lpszVolume));
                     88:        }
                     89: 
1.1.1.3   root       90:        virtual DWORD STDMETHODCALLTYPE CallDriver (DWORD ioctl, BSTR input, BSTR *output)
                     91:        {
                     92:                return BaseCom::CallDriver (ioctl, input, output);
                     93:        }
                     94: 
1.1       root       95:        virtual int STDMETHODCALLTYPE ChangePassword (BSTR volumePath, Password *oldPassword, Password *newPassword, int pkcs5, LONG_PTR hWnd)
                     96:        {
                     97:                USES_CONVERSION;
1.1.1.4   root       98:                MainDlg = (HWND) hWnd;
1.1       root       99:                return ::ChangePwd (CW2A (volumePath), oldPassword, newPassword, pkcs5, (HWND) hWnd);
                    100:        }
1.1.1.8   root      101: 
                    102:        virtual DWORD STDMETHODCALLTYPE CopyFile (BSTR sourceFile, BSTR destinationFile)
                    103:        {
                    104:                return BaseCom::CopyFile (sourceFile, destinationFile);
                    105:        }
                    106: 
                    107:        virtual DWORD STDMETHODCALLTYPE DeleteFile (BSTR file)
                    108:        {
                    109:                return BaseCom::DeleteFile (file);
                    110:        }
                    111: 
1.1.1.5   root      112:        virtual BOOL STDMETHODCALLTYPE IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
1.1.1.4   root      113:        {
1.1.1.5   root      114:                return BaseCom::IsPagingFileActive (checkNonWindowsPartitionsOnly);
1.1.1.4   root      115:        }
1.1       root      116: 
1.1.1.3   root      117:        virtual DWORD STDMETHODCALLTYPE ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
                    118:        {
                    119:                return BaseCom::ReadWriteFile (write, device, filePath, bufferBstr, offset, size, sizeDone);
                    120:        }
                    121: 
1.1.1.10! root      122:        virtual DWORD STDMETHODCALLTYPE RegisterFilterDriver (BOOL registerDriver, int filterType)
1.1.1.3   root      123:        {
1.1.1.10! root      124:                return BaseCom::RegisterFilterDriver (registerDriver, filterType);
1.1.1.3   root      125:        }
                    126: 
1.1.1.8   root      127:        virtual DWORD STDMETHODCALLTYPE RegisterSystemFavoritesService (BOOL registerService)
                    128:        {
                    129:                return BaseCom::RegisterSystemFavoritesService (registerService);
                    130:        }
                    131: 
1.1.1.3   root      132:        virtual DWORD STDMETHODCALLTYPE SetDriverServiceStartType (DWORD startType)
                    133:        {
                    134:                return BaseCom::SetDriverServiceStartType (startType);
                    135:        }
                    136: 
1.1.1.4   root      137:        virtual DWORD STDMETHODCALLTYPE WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
                    138:        {
                    139:                return BaseCom::WriteLocalMachineRegistryDwordValue (keyPath, valueName, value);
                    140:        }
                    141: 
1.1       root      142: protected:
                    143:        DWORD MessageThreadId;
                    144:        LONG RefCount;
                    145: };
                    146: 
                    147: 
                    148: extern "C" BOOL ComServerMain ()
                    149: {
1.1.1.5   root      150:        SetProcessShutdownParameters (0x100, 0);
                    151: 
1.1.1.3   root      152:        TrueCryptFactory<TrueCryptMainCom> factory (GetCurrentThreadId ());
1.1       root      153:        DWORD cookie;
                    154: 
                    155:        if (IsUacSupported ())
                    156:                UacElevated = TRUE;
                    157: 
1.1.1.3   root      158:        if (CoRegisterClassObject (CLSID_TrueCryptMainCom, (LPUNKNOWN) &factory,
1.1       root      159:                CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie) != S_OK)
                    160:                return FALSE;
                    161: 
                    162:        MSG msg;
1.1.1.2   root      163:        while (int r = GetMessage (&msg, NULL, 0, 0))
1.1       root      164:        {
1.1.1.2   root      165:                if (r == -1)
                    166:                        return FALSE;
                    167: 
1.1       root      168:                TranslateMessage (&msg);
                    169:                DispatchMessage (&msg);
                    170: 
                    171:                if (msg.message == WM_APP
                    172:                        && ObjectCount < 1
                    173:                        && !factory.IsServerLocked ())
                    174:                        break;
                    175:        }
                    176:        CoRevokeClassObject (cookie);
                    177: 
                    178:        return TRUE;
                    179: }
                    180: 
                    181: 
1.1.1.3   root      182: static BOOL ComGetInstance (HWND hWnd, ITrueCryptMainCom **tcServer)
1.1       root      183: {
1.1.1.3   root      184:        return ComGetInstanceBase (hWnd, CLSID_TrueCryptMainCom, IID_ITrueCryptMainCom, (void **) tcServer);
                    185: }
                    186: 
                    187: 
                    188: ITrueCryptMainCom *GetElevatedInstance (HWND parent)
                    189: {
                    190:        ITrueCryptMainCom *instance;
                    191: 
                    192:        if (!ComGetInstance (parent, &instance))
                    193:                throw UserAbort (SRC_POS);
                    194: 
                    195:        return instance;
1.1       root      196: }
                    197: 
                    198: 
1.1.1.10! root      199: extern "C" void UacAnalyzeKernelMiniDump (HWND hwndDlg)
        !           200: {
        !           201:        CComPtr<ITrueCryptMainCom> tc;
        !           202: 
        !           203:        CoInitialize (NULL);
        !           204: 
        !           205:        if (ComGetInstance (hwndDlg, &tc))
        !           206:        {
        !           207:                WaitCursor();
        !           208:                tc->AnalyzeKernelMiniDump ((LONG_PTR) hwndDlg);
        !           209:                NormalCursor();
        !           210:        }
        !           211: 
        !           212:        CoUninitialize ();
        !           213: }
        !           214: 
        !           215: 
1.1       root      216: extern "C" int UacBackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume)
                    217: {
1.1.1.3   root      218:        CComPtr<ITrueCryptMainCom> tc;
1.1       root      219:        int r;
                    220: 
                    221:        CoInitialize (NULL);
                    222: 
                    223:        if (ComGetInstance (hwndDlg, &tc))
                    224:                r = tc->BackupVolumeHeader ((LONG_PTR) hwndDlg, bRequireConfirmation, CComBSTR (lpszVolume));
                    225:        else
                    226:                r = -1;
                    227: 
                    228:        CoUninitialize ();
                    229: 
                    230:        return r;
                    231: }
                    232: 
                    233: 
                    234: extern "C" int UacRestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
                    235: {
1.1.1.3   root      236:        CComPtr<ITrueCryptMainCom> tc;
1.1       root      237:        int r;
                    238: 
                    239:        CoInitialize (NULL);
                    240: 
                    241:        if (ComGetInstance (hwndDlg, &tc))
                    242:                r = tc->RestoreVolumeHeader ((LONG_PTR) hwndDlg, CComBSTR (lpszVolume));
                    243:        else
                    244:                r = -1;
                    245: 
                    246:        CoUninitialize ();
                    247: 
                    248:        return r;
                    249: }
                    250: 
                    251: 
                    252: extern "C" int UacChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg)
                    253: {
1.1.1.3   root      254:        CComPtr<ITrueCryptMainCom> tc;
1.1       root      255:        int r;
                    256: 
                    257:        if (ComGetInstance (hwndDlg, &tc))
                    258:        {
                    259:                WaitCursor ();
1.1.1.6   root      260:                r = tc->ChangePassword (CComBSTR (lpszVolume), oldPassword, newPassword, pkcs5, (LONG_PTR) hwndDlg);
1.1       root      261:                NormalCursor ();
                    262:        }
                    263:        else
                    264:                r = -1;
                    265: 
                    266:        return r;
                    267: }

unix.superglobalmegacorp.com

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