Annotation of truecrypt/common/basecom.cpp, revision 1.1.1.10

1.1       root        1: /*
1.1.1.9   root        2:  Copyright (c) 2007-2010 TrueCrypt Developers Association. All rights reserved.
1.1       root        3: 
1.1.1.9   root        4:  Governed by the TrueCrypt License 3.0 the full text of which is contained in
1.1.1.8   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>
1.1.1.3   root       10: #include <atlconv.h>
                     11: #include <comutil.h>
1.1       root       12: #include <windows.h>
                     13: #include "BaseCom.h"
1.1.1.3   root       14: #include "BootEncryption.h"
1.1       root       15: #include "Dlgcode.h"
1.1.1.4   root       16: #include "Registry.h"
1.1       root       17: 
1.1.1.3   root       18: using namespace TrueCrypt;
1.1       root       19: 
                     20: HRESULT CreateElevatedComObject (HWND hwnd, REFGUID guid, REFIID iid, void **ppv)
                     21: {
1.1.1.2   root       22:     WCHAR monikerName[1024];
                     23:     WCHAR clsid[1024];
1.1       root       24:     BIND_OPTS3 bo;
                     25: 
1.1.1.2   root       26:     StringFromGUID2 (guid, clsid, sizeof (clsid) / 2);
                     27:        swprintf_s (monikerName, sizeof (monikerName) / 2, L"Elevation:Administrator!new:%s", clsid);
1.1       root       28: 
                     29:     memset (&bo, 0, sizeof (bo));
                     30:     bo.cbStruct = sizeof (bo);
                     31:     bo.hwnd = hwnd;
                     32:     bo.dwClassContext = CLSCTX_LOCAL_SERVER;
                     33: 
1.1.1.3   root       34:        // Prevent the GUI from being half-rendered when the UAC prompt "freezes" it
1.1.1.10! root       35:        ProcessPaintMessages (hwnd, 5000);
1.1.1.3   root       36: 
1.1.1.2   root       37:     return CoGetObject (monikerName, &bo, iid, ppv);
1.1       root       38: }
                     39: 
                     40: 
                     41: BOOL ComGetInstanceBase (HWND hWnd, REFCLSID clsid, REFIID iid, void **tcServer)
                     42: {
                     43:        BOOL r;
                     44: 
                     45:        if (IsUacSupported ())
                     46:                r = CreateElevatedComObject (hWnd, clsid, iid, tcServer) == S_OK;
                     47:        else
                     48:                r = CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, iid, tcServer) == S_OK;
                     49: 
                     50:        if (!r)
                     51:                Error ("UAC_INIT_ERROR");
                     52: 
                     53:        return r;
                     54: }
                     55: 
1.1.1.3   root       56: 
                     57: DWORD BaseCom::CallDriver (DWORD ioctl, BSTR input, BSTR *output)
                     58: {
                     59:        try
                     60:        {
                     61:                BootEncryption bootEnc (NULL);
                     62:                bootEnc.CallDriver (ioctl,
                     63:                        (BYTE *) input, !(BYTE *) input ? 0 : ((DWORD *) ((BYTE *) input))[-1],
                     64:                        (BYTE *) *output, !(BYTE *) *output ? 0 : ((DWORD *) ((BYTE *) *output))[-1]);
                     65:        }
                     66:        catch (SystemException &)
                     67:        {
                     68:                return GetLastError();
                     69:        }
                     70:        catch (Exception &e)
                     71:        {
                     72:                e.Show (NULL);
                     73:                return ERROR_EXCEPTION_IN_SERVICE;
                     74:        }
                     75:        catch (...)
                     76:        {
                     77:                return ERROR_EXCEPTION_IN_SERVICE;
                     78:        }
                     79: 
                     80:        return ERROR_SUCCESS;
                     81: }
                     82: 
                     83: 
1.1.1.7   root       84: DWORD BaseCom::CopyFile (BSTR sourceFile, BSTR destinationFile)
                     85: {
                     86:        USES_CONVERSION;
                     87: 
                     88:        if (!::CopyFile (CW2A (sourceFile), CW2A (destinationFile), FALSE))
                     89:                return GetLastError();
                     90: 
                     91:        return ERROR_SUCCESS;
                     92: }
                     93: 
                     94: 
                     95: DWORD BaseCom::DeleteFile (BSTR file)
                     96: {
                     97:        USES_CONVERSION;
                     98: 
                     99:        if (!::DeleteFile (CW2A (file)))
                    100:                return GetLastError();
                    101: 
                    102:        return ERROR_SUCCESS;
                    103: }
                    104: 
                    105: 
1.1.1.5   root      106: BOOL BaseCom::IsPagingFileActive (BOOL checkNonWindowsPartitionsOnly)
1.1.1.4   root      107: {
1.1.1.5   root      108:        return ::IsPagingFileActive (checkNonWindowsPartitionsOnly);
1.1.1.4   root      109: }
                    110: 
                    111: 
1.1.1.3   root      112: DWORD BaseCom::ReadWriteFile (BOOL write, BOOL device, BSTR filePath, BSTR *bufferBstr, unsigned __int64 offset, unsigned __int32 size, DWORD *sizeDone)
                    113: {
                    114:        USES_CONVERSION;
                    115: 
                    116:        try
                    117:        {
                    118:                auto_ptr <File> file (device ? new Device (string (CW2A (filePath)), !write) : new File (string (CW2A (filePath)), !write));
                    119:                file->SeekAt (offset);
                    120: 
                    121:                if (write)
                    122:                {
                    123:                        file->Write ((BYTE *) *bufferBstr, size);
                    124:                        *sizeDone = size;
                    125:                }
                    126:                else
                    127:                {
                    128:                        *sizeDone = file->Read ((BYTE *) *bufferBstr, size);
                    129:                }
                    130:        }
                    131:        catch (SystemException &)
                    132:        {
                    133:                return GetLastError();
                    134:        }
                    135:        catch (Exception &e)
                    136:        {
                    137:                e.Show (NULL);
                    138:                return ERROR_EXCEPTION_IN_SERVICE;
                    139:        }
                    140:        catch (...)
                    141:        {
                    142:                return ERROR_EXCEPTION_IN_SERVICE;
                    143:        }
                    144: 
                    145:        return ERROR_SUCCESS;
                    146: }
                    147: 
                    148: 
1.1.1.9   root      149: DWORD BaseCom::RegisterFilterDriver (BOOL registerDriver, int filterType)
1.1.1.3   root      150: {
                    151:        try
                    152:        {
                    153:                BootEncryption bootEnc (NULL);
1.1.1.9   root      154:                bootEnc.RegisterFilterDriver (registerDriver ? true : false, (BootEncryption::FilterType) filterType);
1.1.1.3   root      155:        }
                    156:        catch (SystemException &)
                    157:        {
                    158:                return GetLastError();
                    159:        }
                    160:        catch (Exception &e)
                    161:        {
                    162:                e.Show (NULL);
                    163:                return ERROR_EXCEPTION_IN_SERVICE;
                    164:        }
                    165:        catch (...)
                    166:        {
                    167:                return ERROR_EXCEPTION_IN_SERVICE;
                    168:        }
                    169: 
                    170:        return ERROR_SUCCESS;
                    171: }
                    172: 
                    173: 
1.1.1.7   root      174: DWORD BaseCom::RegisterSystemFavoritesService (BOOL registerService)
                    175: {
                    176:        try
                    177:        {
                    178:                BootEncryption bootEnc (NULL);
                    179:                bootEnc.RegisterSystemFavoritesService (registerService);
                    180:        }
                    181:        catch (SystemException &)
                    182:        {
                    183:                return GetLastError();
                    184:        }
                    185:        catch (Exception &e)
                    186:        {
                    187:                e.Show (NULL);
                    188:                return ERROR_EXCEPTION_IN_SERVICE;
                    189:        }
                    190:        catch (...)
                    191:        {
                    192:                return ERROR_EXCEPTION_IN_SERVICE;
                    193:        }
                    194: 
                    195:        return ERROR_SUCCESS;
                    196: }
                    197: 
                    198: 
1.1.1.3   root      199: DWORD BaseCom::SetDriverServiceStartType (DWORD startType)
                    200: {
                    201:        try
                    202:        {
                    203:                BootEncryption bootEnc (NULL);
                    204:                bootEnc.SetDriverServiceStartType (startType);
                    205:        }
                    206:        catch (SystemException &)
                    207:        {
                    208:                return GetLastError();
                    209:        }
                    210:        catch (Exception &e)
                    211:        {
                    212:                e.Show (NULL);
                    213:                return ERROR_EXCEPTION_IN_SERVICE;
                    214:        }
                    215:        catch (...)
                    216:        {
                    217:                return ERROR_EXCEPTION_IN_SERVICE;
                    218:        }
                    219: 
                    220:        return ERROR_SUCCESS;
                    221: }
1.1.1.4   root      222: 
                    223: 
                    224: DWORD BaseCom::WriteLocalMachineRegistryDwordValue (BSTR keyPath, BSTR valueName, DWORD value)
                    225: {
                    226:        USES_CONVERSION;
                    227:        if (!::WriteLocalMachineRegistryDword (CW2A (keyPath), CW2A (valueName), value))
                    228:                return GetLastError();
                    229: 
                    230:        return ERROR_SUCCESS;
                    231: }

unix.superglobalmegacorp.com

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