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

1.1     ! root        1: /*
        !             2:  Copyright (c) TrueCrypt Foundation. All rights reserved.
        !             3: 
        !             4:  Covered by the TrueCrypt License 2.2 the full text of which is contained
        !             5:  in the file License.txt included in TrueCrypt binary and source code
        !             6:  distribution packages.
        !             7: */
        !             8: 
        !             9: #include <atlcomcli.h>
        !            10: #include <atlconv.h>
        !            11: #include <strsafe.h>
        !            12: #include <windows.h>
        !            13: #include "BaseCom.h"
        !            14: #include "Dlgcode.h"
        !            15: #include "MainCom.h"
        !            16: #include "MainCom_h.h"
        !            17: #include "MainCom_i.c"
        !            18: #include "Password.h"
        !            19: 
        !            20: static volatile LONG ObjectCount = 0;
        !            21: 
        !            22: class TrueCrypt : public ITrueCrypt
        !            23: {
        !            24: 
        !            25: public:
        !            26:        TrueCrypt (DWORD messageThreadId) : RefCount (0), MessageThreadId (messageThreadId)
        !            27:        {
        !            28:                InterlockedIncrement (&ObjectCount);
        !            29:        }
        !            30: 
        !            31:        ~TrueCrypt ()
        !            32:        {
        !            33:                if (InterlockedDecrement (&ObjectCount) == 0)
        !            34:                        PostThreadMessage (MessageThreadId, WM_APP, 0, 0);
        !            35:        }
        !            36: 
        !            37:        virtual ULONG STDMETHODCALLTYPE AddRef ()
        !            38:        {
        !            39:                return InterlockedIncrement (&RefCount);
        !            40:        }
        !            41: 
        !            42:        virtual ULONG STDMETHODCALLTYPE Release ()
        !            43:        {
        !            44:                if (!InterlockedDecrement (&RefCount))
        !            45:                {
        !            46:                        delete this;
        !            47:                        return 0;
        !            48:                }
        !            49: 
        !            50:                return RefCount;
        !            51:        }
        !            52: 
        !            53:        virtual HRESULT STDMETHODCALLTYPE QueryInterface (REFIID riid, void **ppvObject)
        !            54:        {
        !            55:                if (riid == IID_IUnknown || riid == IID_ITrueCrypt)
        !            56:                        *ppvObject = this;
        !            57:                else
        !            58:                {
        !            59:                        *ppvObject = NULL;
        !            60:                        return E_NOINTERFACE;
        !            61:                }
        !            62: 
        !            63:                AddRef ();
        !            64:                return S_OK;
        !            65:        }
        !            66:        
        !            67:        virtual int STDMETHODCALLTYPE BackupVolumeHeader (LONG_PTR hwndDlg, BOOL bRequireConfirmation, BSTR lpszVolume)
        !            68:        {
        !            69:                USES_CONVERSION;
        !            70:                return ::BackupVolumeHeader ((HWND) hwndDlg, bRequireConfirmation, CW2A (lpszVolume));
        !            71:        }
        !            72: 
        !            73:        virtual int STDMETHODCALLTYPE RestoreVolumeHeader (LONG_PTR hwndDlg, BSTR lpszVolume)
        !            74:        {
        !            75:                USES_CONVERSION;
        !            76:                return ::RestoreVolumeHeader ((HWND) hwndDlg, CW2A (lpszVolume));
        !            77:        }
        !            78: 
        !            79:        virtual int STDMETHODCALLTYPE ChangePassword (BSTR volumePath, Password *oldPassword, Password *newPassword, int pkcs5, LONG_PTR hWnd)
        !            80:        {
        !            81:                USES_CONVERSION;
        !            82:                return ::ChangePwd (CW2A (volumePath), oldPassword, newPassword, pkcs5, (HWND) hWnd);
        !            83:        }
        !            84: 
        !            85: protected:
        !            86:        DWORD MessageThreadId;
        !            87:        LONG RefCount;
        !            88: };
        !            89: 
        !            90: 
        !            91: extern "C" BOOL ComServerMain ()
        !            92: {
        !            93:        TrueCryptFactory<TrueCrypt> factory (GetCurrentThreadId ());
        !            94:        DWORD cookie;
        !            95: 
        !            96:        if (IsUacSupported ())
        !            97:                UacElevated = TRUE;
        !            98: 
        !            99:        if (CoRegisterClassObject (CLSID_TrueCrypt, (LPUNKNOWN) &factory,
        !           100:                CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &cookie) != S_OK)
        !           101:                return FALSE;
        !           102: 
        !           103:        MSG msg;
        !           104:        while (GetMessage (&msg, NULL, 0, 0))
        !           105:        {
        !           106:                TranslateMessage (&msg);
        !           107:                DispatchMessage (&msg);
        !           108: 
        !           109:                if (msg.message == WM_APP
        !           110:                        && ObjectCount < 1
        !           111:                        && !factory.IsServerLocked ())
        !           112:                        break;
        !           113:        }
        !           114:        CoRevokeClassObject (cookie);
        !           115: 
        !           116:        return TRUE;
        !           117: }
        !           118: 
        !           119: 
        !           120: static BOOL ComGetInstance (HWND hWnd, ITrueCrypt **tcServer)
        !           121: {
        !           122:        return ComGetInstanceBase (hWnd, CLSID_TrueCrypt, IID_ITrueCrypt, (void **) tcServer);
        !           123: }
        !           124: 
        !           125: 
        !           126: extern "C" int UacBackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume)
        !           127: {
        !           128:        CComPtr<ITrueCrypt> tc;
        !           129:        int r;
        !           130: 
        !           131:        CoInitialize (NULL);
        !           132: 
        !           133:        if (ComGetInstance (hwndDlg, &tc))
        !           134:                r = tc->BackupVolumeHeader ((LONG_PTR) hwndDlg, bRequireConfirmation, CComBSTR (lpszVolume));
        !           135:        else
        !           136:                r = -1;
        !           137: 
        !           138:        CoUninitialize ();
        !           139: 
        !           140:        return r;
        !           141: }
        !           142: 
        !           143: 
        !           144: extern "C" int UacRestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
        !           145: {
        !           146:        CComPtr<ITrueCrypt> tc;
        !           147:        int r;
        !           148: 
        !           149:        CoInitialize (NULL);
        !           150: 
        !           151:        if (ComGetInstance (hwndDlg, &tc))
        !           152:                r = tc->RestoreVolumeHeader ((LONG_PTR) hwndDlg, CComBSTR (lpszVolume));
        !           153:        else
        !           154:                r = -1;
        !           155: 
        !           156:        CoUninitialize ();
        !           157: 
        !           158:        return r;
        !           159: }
        !           160: 
        !           161: 
        !           162: extern "C" int UacChangePwd (char *lpszVolume, Password *oldPassword, Password *newPassword, int pkcs5, HWND hwndDlg)
        !           163: {
        !           164:        CComPtr<ITrueCrypt> tc;
        !           165:        int r;
        !           166: 
        !           167:        if (ComGetInstance (hwndDlg, &tc))
        !           168:        {
        !           169:                WaitCursor ();
        !           170:                r = tc->ChangePassword (CComBSTR (lpszVolume), oldPassword, newPassword, 0, (LONG_PTR) hwndDlg);
        !           171:                NormalCursor ();
        !           172:        }
        !           173:        else
        !           174:                r = -1;
        !           175: 
        !           176:        return r;
        !           177: }

unix.superglobalmegacorp.com

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