Confdump Agent  1.4.0
ComContext.cpp
Go to the documentation of this file.
00001 /* 
00002  * Confdump-Agent - Dump static and runtime system configuration
00003  * Copyright (C) 2009-2012  Straton IT, SAS
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <comdef.h>
00019 #include <string>
00020 #include <sstream>
00021 
00022 #include "Confdump/System/Wmi/ComContext.hpp"
00023 #include "Confdump/System/Wmi/errors.hpp"
00024 
00025 namespace Confdump
00026 {
00027 namespace System
00028 {
00029 namespace Wmi
00030 {
00031 
00032 boost::weak_ptr<ComContext::GuardImpl> ComContext::instance_;
00033 
00034 ComContext::Guard ComContext::getGuard()
00035 {
00036     Guard guard = instance_.lock();
00037     if ( !guard )
00038     {
00039         guard.reset( new GuardImpl );
00040         instance_ = guard;
00041     }
00042 
00043     return guard;
00044 }
00045 
00046 ComContext::ComContext()
00047 {
00048 }
00049 
00050 ComContext::~ComContext()
00051 {
00052 }
00053 
00054 
00055 
00056 
00057 ComContext::GuardImpl::GuardImpl()
00058 {
00059         HRESULT hr = CoInitializeEx( 0, COINIT_MULTITHREADED );
00060     throwOnComError( hr, "initialize the COM library" );
00061     comInitGuard_.reset( static_cast<void*>( 0 ), boost::bind( CoUninitialize ) );
00062     
00063     hr = CoInitializeSecurity(
00064         0,                                                              /* Security descriptor */
00065         -1,                             /* COM negotiates authentication service */
00066         0,                                                              /* Authentication services */
00067         0,                                                              /* Reserved */
00068         RPC_C_AUTHN_LEVEL_DEFAULT,      /* Default authentication level for proxies */
00069         RPC_C_IMP_LEVEL_IMPERSONATE,    /* Default Impersonation level for proxies  */
00070         0,                                                              /* Authentication info */
00071         EOAC_NONE,                                              /* Additional capabilities of the client or server */
00072         0 );                                                    /* Reserved */
00073     throwOnComError( hr, "configure the COM security" );
00074 }
00075 
00076 ComContext::GuardImpl::~GuardImpl()
00077 {
00078 }
00079 
00080 }
00081 }
00082 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends