Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2037 lines
54 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Globals.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include <precomp.h>
  9. #include <windows.h>
  10. #include <objbase.h>
  11. #include <initguid.h>
  12. #ifndef INITGUID
  13. #define INITGUID
  14. #endif
  15. #include <wbemcli.h>
  16. #include <wbemint.h>
  17. #include <winntsec.h>
  18. #include <callsec.h>
  19. #include <cominit.h>
  20. #include <NCObjApi.h>
  21. #include "winmgmtr.h"
  22. #include <Guids.h>
  23. #include <BasicTree.h>
  24. #include <Thread.h>
  25. #include <Logging.h>
  26. #include "Globals.h"
  27. #include "CGlobals.h"
  28. #include "ProvSubS.h"
  29. #ifdef WMIASLOCAL
  30. #include "Main.h"
  31. #endif
  32. /******************************************************************************
  33. *
  34. * Name:
  35. *
  36. *
  37. * Description:
  38. *
  39. *
  40. *****************************************************************************/
  41. LONG ProviderSubSystem_Globals :: s_Initialized = 0 ;
  42. WmiAllocator *ProviderSubSystem_Globals :: s_Allocator = NULL ;
  43. CriticalSection ProviderSubSystem_Globals :: s_DecoupledRegistrySection(NOTHROW_LOCK) ;
  44. HANDLE ProviderSubSystem_Globals :: s_FileMapping = NULL ;
  45. CServerObject_ProviderSubsystem_Counters *ProviderSubSystem_Globals :: s_SharedCounters = NULL ;
  46. StrobeThread *ProviderSubSystem_Globals :: s_StrobeThread = NULL ;
  47. HANDLE ProviderSubSystem_Globals :: s_CoFreeUnusedLibrariesEvent = NULL ;
  48. HANDLE ProviderSubSystem_Globals :: s_HostJobObject = NULL ;
  49. LPCWSTR ProviderSubSystem_Globals :: s_HostJobObjectName = L"Global\\WmiProviderSubSystemHostJob" ;
  50. LPCWSTR ProviderSubSystem_Globals :: s_ProviderSubsystemEventSourceName = L"WinMgmt" ;
  51. HANDLE ProviderSubSystem_Globals :: s_NtEventLogSource = NULL ;
  52. HostController *ProviderSubSystem_Globals :: s_HostController = NULL ;
  53. RefresherManagerController *ProviderSubSystem_Globals :: s_RefresherManagerController = NULL ;
  54. CWbemGlobal_HostedProviderController *ProviderSubSystem_Globals :: s_HostedProviderController = NULL ;
  55. CWbemGlobal_IWmiProvSubSysController *ProviderSubSystem_Globals :: s_ProvSubSysController = NULL ;
  56. CWbemGlobal_IWbemSyncProviderController *ProviderSubSystem_Globals :: s_SyncProviderController = NULL ;
  57. CDecoupled_ProviderSubsystemRegistrar *ProviderSubSystem_Globals :: s_DecoupledRegistrar = NULL ;
  58. CriticalSection ProviderSubSystem_Globals :: s_GuidTagSection(NOTHROW_LOCK) ;
  59. CWbemGlobal_ComServerTagContainer *ProviderSubSystem_Globals :: s_GuidTag = NULL ;
  60. LONG ProviderSubSystem_Globals :: s_LocksInProgress = 0 ;
  61. LONG ProviderSubSystem_Globals :: s_ObjectsInProgress = 0 ;
  62. ULONG ProviderSubSystem_Globals :: s_InternalCacheTimeout = DEFAULT_PROVIDER_TIMEOUT ;
  63. ULONG ProviderSubSystem_Globals :: s_ObjectCacheTimeout = DEFAULT_PROVIDER_TIMEOUT ;
  64. ULONG ProviderSubSystem_Globals :: s_EventCacheTimeout = DEFAULT_PROVIDER_TIMEOUT ;
  65. ULONG ProviderSubSystem_Globals :: s_StrobeTimeout = DEFAULT_PROVIDER_TIMEOUT >> 1 ;
  66. ULONG ProviderSubSystem_Globals :: s_Quota_ProcessLimitCount = 0x20 ;
  67. SIZE_T ProviderSubSystem_Globals :: s_Quota_ProcessMemoryLimitCount = 0x10000000 ;
  68. SIZE_T ProviderSubSystem_Globals :: s_Quota_JobMemoryLimitCount = 0x10000000 ;
  69. SIZE_T ProviderSubSystem_Globals :: s_Quota_PrivatePageCount = 0x10000000 ;
  70. ULONG ProviderSubSystem_Globals :: s_Quota_HandleCount = 0x1000 ;
  71. ULONG ProviderSubSystem_Globals :: s_Quota_NumberOfThreads = 0x1000 ;
  72. LONG ProviderSubSystem_Globals :: s_CAggregator_IWbemProvider_ObjectsInProgress = 0 ;
  73. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemProviderInitSink_ObjectsInProgress = 0 ;
  74. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemServices_Proxy_ObjectsInProgress = 0 ;
  75. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemServices_Stub_ObjectsInProgress = 0 ;
  76. LONG ProviderSubSystem_Globals :: s_CInterceptor_IEnumWbemClassObject_Stub_ObjectsInProgress = 0 ;
  77. LONG ProviderSubSystem_Globals :: s_CInterceptor_IEnumWbemClassObject_Proxy_ObjectsInProgress = 0 ;
  78. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemServices_Interceptor_ObjectsInProgress = 0 ;
  79. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemServices_RestrictingInterceptor_ObjectsInProgress = 0 ;
  80. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemObjectSink_ObjectsInProgress = 0 ;
  81. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemObjectSinkEx_ObjectsInProgress = 0 ;
  82. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemFilteringObjectSink_ObjectsInProgress = 0 ;
  83. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemProvider_ObjectsInProgress = 0 ;
  84. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemSyncProvider_ObjectsInProgress = 0 ;
  85. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemSyncObjectSink_ObjectsInProgress = 0 ;
  86. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemSyncObjectSinkEx_ObjectsInProgress = 0 ;
  87. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemSyncFilteringObjectSink_ObjectsInProgress = 0 ;
  88. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemCombiningObjectSink_ObjectsInProgress = 0 ;
  89. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemWaitingObjectSink_ObjectsInProgress = 0 ;
  90. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemUnboundObjectSink_ObjectsInProgress = 0 ;
  91. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemSyncUnboundObjectSink_ObjectsInProgress = 0 ;
  92. LONG ProviderSubSystem_Globals :: s_CInterceptor_IWbemDecoupledProvider_ObjectsInProgress = 0 ;
  93. LONG ProviderSubSystem_Globals :: s_CDecoupled_IWbemUnboundObjectSink_ObjectsInProgress = 0 ;
  94. LONG ProviderSubSystem_Globals :: s_CServerObject_Host_ObjectsInProgress = 0 ;
  95. LONG ProviderSubSystem_Globals :: s_CServerObject_HostInterceptor_ObjectsInProgress = 0 ;
  96. LONG ProviderSubSystem_Globals :: s_CServerObject_BindingFactory_ObjectsInProgress = 0 ;
  97. LONG ProviderSubSystem_Globals :: s_CServerObject_DynamicPropertyProviderResolver_ObjectsInProgress = 0 ;
  98. LONG ProviderSubSystem_Globals :: s_CServerObject_IWbemServices_ObjectsInProgress = 0 ;
  99. LONG ProviderSubSystem_Globals :: s_CServerObject_ProviderSubsystem_Counters_ObjectsInProgress = 0 ;
  100. LONG ProviderSubSystem_Globals :: s_CServerObject_ProviderSubSystem_ObjectsInProgress = 0 ;
  101. LONG ProviderSubSystem_Globals :: s_CServerObject_RawFactory_ObjectsInProgress = 0 ;
  102. LONG ProviderSubSystem_Globals :: s_StaTask_Create_ObjectsInProgress = 0 ;
  103. LONG ProviderSubSystem_Globals :: s_CServerObject_StaThread_ObjectsInProgress = 0 ;
  104. LONG ProviderSubSystem_Globals :: s_StrobeThread_ObjectsInProgress = 0 ;
  105. LONG ProviderSubSystem_Globals :: s_CServerClassFactory_ObjectsInProgress = 0 ;
  106. LONG ProviderSubSystem_Globals :: s_CDecoupledAggregator_IWbemProvider_ObjectsInProgress = 0 ;
  107. LONG ProviderSubSystem_Globals :: s_CDecoupled_ProviderSubsystemRegistrar_ObjectsInProgress = 0 ;
  108. LONG ProviderSubSystem_Globals :: s_CServerObject_ProviderRefresherManager_ObjectsInProgress = 0 ;
  109. LONG ProviderSubSystem_Globals :: s_CServerProvRefreshManagerClassFactory_ObjectsInProgress = 0 ;
  110. LONG ProviderSubSystem_Globals :: s_CServerObject_InterceptorProviderRefresherManager_ObjectsInProgress = 0 ;
  111. /******************************************************************************
  112. *
  113. * Name:
  114. *
  115. *
  116. * Description:
  117. *
  118. *
  119. *****************************************************************************/
  120. LPCWSTR ProviderSubSystem_Globals :: s_FileMappingName = L"Global\\Wmi Provider Sub System Counters" ;
  121. LPCWSTR ProviderSubSystem_Globals :: s_QueryPrefix = L"Select * from __Win32Provider Where Name = \"" ;
  122. ULONG ProviderSubSystem_Globals :: s_QueryPrefixLen = wcslen ( ProviderSubSystem_Globals :: s_QueryPrefix ) ;
  123. LPCWSTR ProviderSubSystem_Globals :: s_QueryPostfix = L"\"" ;
  124. ULONG ProviderSubSystem_Globals :: s_QueryPostfixLen = wcslen ( ProviderSubSystem_Globals :: s_QueryPostfix ) ;
  125. ULONG ProviderSubSystem_Globals :: s_QueryConstantsLen = ProviderSubSystem_Globals :: s_QueryPrefixLen + ProviderSubSystem_Globals :: s_QueryPostfixLen ;
  126. LPCWSTR ProviderSubSystem_Globals :: s_Provider = L"Provider" ;
  127. ULONG ProviderSubSystem_Globals :: s_ProviderLen = wcslen ( ProviderSubSystem_Globals :: s_Provider ) ;
  128. LPCWSTR ProviderSubSystem_Globals :: s_Class = L"__Class" ;
  129. ULONG ProviderSubSystem_Globals :: s_ClassLen = wcslen ( ProviderSubSystem_Globals :: s_Class ) ;
  130. LPCWSTR ProviderSubSystem_Globals :: s_Wql = L"Wql" ;
  131. LPCWSTR ProviderSubSystem_Globals :: s_DynProps = L"DynProps" ;
  132. LPCWSTR ProviderSubSystem_Globals :: s_Dynamic = L"Dynamic" ;
  133. LPCWSTR ProviderSubSystem_Globals :: s_ClassContext = L"ClassContext" ;
  134. LPCWSTR ProviderSubSystem_Globals :: s_InstanceContext = L"InstanceContext" ;
  135. LPCWSTR ProviderSubSystem_Globals :: s_PropertyContext = L"PropertyContext" ;
  136. HANDLE ProviderSubSystem_Globals :: s_EventSource = NULL ;
  137. LPWSTR ProviderSubSystem_Globals :: s_EventPropertySources [] = {
  138. L"Msft_WmiProvider_ComServerLoadOperationEvent" ,
  139. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Clsid!s! ServerName!s! InProcServer!b! LocalServer!b! InProcServerPath!s! LocalServerPath!s!" ,
  140. L"Msft_WmiProvider_ComServerOperationFailureEvent" ,
  141. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Clsid!s! ServerName!s! InProcServer!b! LocalServer!b! InProcServerPath!s! LocalServerPath!s! ResultCode!u!" ,
  142. L"Msft_WmiProvider_LoadOperationEvent",
  143. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Clsid!s! ServerName!s! InProcServer!b! LocalServer!b! InProcServerPath!s! LocalServerPath!s! ThreadingModel!u! Synchronisation!u!" ,
  144. L"Msft_WmiProvider_LoadOperationFailureEvent",
  145. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Clsid!s! ServerName!s! InProcServer!b! LocalServer!b! InProcServerPath!s! LocalServerPath!s! ThreadingModel!u! Synchronisation!u! ResultCode!u!" ,
  146. L"Msft_WmiProvider_InitializationOperationFailureEvent" ,
  147. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! ResultCode!u!" ,
  148. L"Msft_WmiProvider_InitializationOperationEvent" ,
  149. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s!" ,
  150. L"Msft_WmiProvider_UnLoadOperationEvent" ,
  151. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s!" ,
  152. L"Msft_WmiProvider_GetObjectAsyncEvent_Pre" ,
  153. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ObjectPath!s!" ,
  154. L"Msft_WmiProvider_PutClassAsyncEvent_Pre" ,
  155. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ClassObject!O!" ,
  156. L"Msft_WmiProvider_DeleteClassAsyncEvent_Pre" ,
  157. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ClassName!s!" ,
  158. L"Msft_WmiProvider_CreateClassEnumAsyncEvent_Pre" ,
  159. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! SuperclassName!s!" ,
  160. L"Msft_WmiProvider_PutInstanceAsyncEvent_Pre" ,
  161. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! InstanceObject!O!" ,
  162. L"Msft_WmiProvider_DeleteInstanceAsyncEvent_Pre" ,
  163. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ObjectPath!s!" ,
  164. L"Msft_WmiProvider_CreateInstanceEnumAsyncEvent_Pre" ,
  165. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ClassName!s!" ,
  166. L"Msft_WmiProvider_ExecQueryAsyncEvent_Pre" ,
  167. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! QueryLanguage!s! Query!s!" ,
  168. L"Msft_WmiProvider_ExecNotificationQueryAsyncEvent_Pre" ,
  169. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! QueryLanguage!s! Query!s!" ,
  170. L"Msft_WmiProvider_ExecMethodAsyncEvent_Pre" ,
  171. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ObjectPath!s! MethodName!s! InputParameters!O!" ,
  172. L"Msft_WmiProvider_ProvideEvents_Pre" ,
  173. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u!" ,
  174. L"Msft_WmiProvider_AccessCheck_Pre" ,
  175. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! QueryLanguage!s! Query!s! Sid!c[]!" ,
  176. L"Msft_WmiProvider_CancelQuery_Pre" ,
  177. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! QueryId!u!" ,
  178. L"Msft_WmiProvider_NewQuery_Pre" ,
  179. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! QueryId!u! QueryLanguage!s! Query!s!" ,
  180. L"Msft_WmiProvider_GetObjectAsyncEvent_Post" ,
  181. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ObjectPath!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  182. L"Msft_WmiProvider_PutClassAsyncEvent_Post" ,
  183. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ClassObject!O! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  184. L"Msft_WmiProvider_DeleteClassAsyncEvent_Post" ,
  185. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ClassName!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  186. L"Msft_WmiProvider_CreateClassEnumAsyncEvent_Post" ,
  187. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! SuperclassName!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  188. L"Msft_WmiProvider_PutInstanceAsyncEvent_Post" ,
  189. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! InstanceObject!O! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  190. L"Msft_WmiProvider_DeleteInstanceAsyncEvent_Post" ,
  191. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ObjectPath!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  192. L"Msft_WmiProvider_CreateInstanceEnumAsyncEvent_Post" ,
  193. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ClassName!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  194. L"Msft_WmiProvider_ExecQueryAsyncEvent_Post" ,
  195. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! QueryLanguage!s! Query!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  196. L"Msft_WmiProvider_ExecNotificationQueryAsyncEvent_Post" ,
  197. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! QueryLanguage!s! Query!s! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  198. L"Msft_WmiProvider_ExecMethodAsyncEvent_Post" ,
  199. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! ObjectPath!s! MethodName!s! InputParameters!O! ResultCode!u! StringParameter!s! ObjectParameter!O!" ,
  200. L"Msft_WmiProvider_ProvideEvents_Post" ,
  201. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! Flags!u! Result!u!" ,
  202. L"Msft_WmiProvider_AccessCheck_Post" ,
  203. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! QueryLanguage!s! Query!s! Sid!c[]! Result!u!" ,
  204. L"Msft_WmiProvider_CancelQuery_Post" ,
  205. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! QueryId!u! Result!u!" ,
  206. L"Msft_WmiProvider_NewQuery_Post" ,
  207. L"Namespace!s! Provider!s! User!s! Locale!s! TransactionIdentifier!s! QueryId!u! QueryLanguage!s! Query!s! Result!u!"
  208. } ;
  209. ULONG ProviderSubSystem_Globals :: s_EventClassHandlesSize = sizeof ( s_EventPropertySources ) / ( sizeof ( wchar_t * ) * 2 ) ;
  210. HANDLE ProviderSubSystem_Globals :: s_EventClassHandles [ sizeof ( s_EventPropertySources ) / ( sizeof ( wchar_t * ) * 2 ) ] ;
  211. /******************************************************************************
  212. *
  213. * Name:
  214. *
  215. *
  216. * Description:
  217. *
  218. *
  219. *****************************************************************************/
  220. HRESULT ProviderSubSystem_Globals :: Initialize_Events ()
  221. {
  222. HRESULT t_Result = S_OK ;
  223. ProviderSubSystem_Globals ::s_EventSource = WmiEventSourceConnect (
  224. L"root\\cimv2" ,
  225. L"ProviderSubSystem" ,
  226. TRUE ,
  227. 32000 ,
  228. 100 ,
  229. NULL ,
  230. NULL
  231. ) ;
  232. if ( ProviderSubSystem_Globals :: s_EventSource )
  233. {
  234. for ( ULONG t_Index = 0 ; t_Index < ProviderSubSystem_Globals :: s_EventClassHandlesSize ; t_Index ++ )
  235. {
  236. ProviderSubSystem_Globals :: s_EventClassHandles [ t_Index ] = WmiCreateObjectWithFormat (
  237. ProviderSubSystem_Globals :: s_EventSource ,
  238. s_EventPropertySources [ t_Index * 2 ] ,
  239. WMI_CREATEOBJ_LOCKABLE ,
  240. s_EventPropertySources [ t_Index * 2 + 1 ]
  241. ) ;
  242. if ( ProviderSubSystem_Globals :: s_EventClassHandles [ t_Index ] == NULL )
  243. {
  244. t_Result = WBEM_E_CRITICAL_ERROR ;
  245. break;
  246. }
  247. }
  248. }
  249. else
  250. {
  251. t_Result = WBEM_E_CRITICAL_ERROR ;
  252. }
  253. return t_Result ;
  254. }
  255. /******************************************************************************
  256. *
  257. * Name:
  258. *
  259. *
  260. * Description:
  261. *
  262. *
  263. *****************************************************************************/
  264. HRESULT ProviderSubSystem_Globals :: UnInitialize_Events ()
  265. {
  266. HRESULT t_Result = S_OK ;
  267. if ( ProviderSubSystem_Globals ::s_EventSource )
  268. {
  269. for ( ULONG t_Index = 0 ; t_Index < ProviderSubSystem_Globals :: s_EventClassHandlesSize ; t_Index ++ )
  270. {
  271. HANDLE eventHandle = ProviderSubSystem_Globals :: s_EventClassHandles [ t_Index ];
  272. ProviderSubSystem_Globals :: s_EventClassHandles [ t_Index ] = NULL;
  273. WmiDestroyObject ( eventHandle) ;
  274. }
  275. WmiEventSourceDisconnect ( ProviderSubSystem_Globals :: s_EventSource );
  276. ProviderSubSystem_Globals :: s_EventSource = NULL;
  277. }
  278. return t_Result ;
  279. }
  280. /******************************************************************************
  281. *
  282. * Name:
  283. *
  284. *
  285. * Description:
  286. *
  287. *
  288. *****************************************************************************/
  289. HRESULT GetSecurityDescriptor ( SECURITY_DESCRIPTOR &a_SecurityDescriptor , DWORD a_Access )
  290. {
  291. HRESULT t_Result = S_OK ;
  292. BOOL t_BoolResult = InitializeSecurityDescriptor ( & a_SecurityDescriptor , SECURITY_DESCRIPTOR_REVISION ) ;
  293. if ( t_BoolResult )
  294. {
  295. SID_IDENTIFIER_AUTHORITY t_NtAuthoritySid = SECURITY_NT_AUTHORITY ;
  296. PSID t_System_Sid = NULL ;
  297. ACCESS_ALLOWED_ACE *t_System_ACE = NULL ;
  298. USHORT t_System_ACESize = 0 ;
  299. t_BoolResult = AllocateAndInitializeSid (
  300. & t_NtAuthoritySid ,
  301. 1 ,
  302. SECURITY_LOCAL_SYSTEM_RID,
  303. 0,
  304. 0,
  305. 0,
  306. 0,
  307. 0,
  308. 0,
  309. 0,
  310. & t_System_Sid
  311. );
  312. if ( t_BoolResult )
  313. {
  314. DWORD t_SidLength = ::GetLengthSid ( t_System_Sid );
  315. t_System_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  316. t_System_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_System_ACESize ] ;
  317. if ( t_System_ACE )
  318. {
  319. CopySid ( t_SidLength, (PSID) & t_System_ACE->SidStart, t_System_Sid ) ;
  320. t_System_ACE->Mask = FILE_MAP_ALL_ACCESS;
  321. t_System_ACE->Header.AceType = 0 ;
  322. t_System_ACE->Header.AceFlags = 3 ;
  323. t_System_ACE->Header.AceSize = t_System_ACESize ;
  324. }
  325. else
  326. {
  327. t_Result = WBEM_E_OUT_OF_MEMORY ;
  328. }
  329. }
  330. else
  331. {
  332. DWORD t_LastError = ::GetLastError();
  333. t_Result = WBEM_E_OUT_OF_MEMORY ;
  334. }
  335. PSID t_LocalService_Sid = NULL ;
  336. ACCESS_ALLOWED_ACE *t_LocalService_ACE = NULL ;
  337. USHORT t_LocalService_ACESize = 0 ;
  338. if ( SUCCEEDED ( t_Result ) )
  339. {
  340. t_BoolResult = AllocateAndInitializeSid (
  341. & t_NtAuthoritySid ,
  342. 1 ,
  343. SECURITY_LOCAL_SERVICE_RID ,
  344. 0,
  345. 0,
  346. 0,
  347. 0,
  348. 0,
  349. 0,
  350. 0,
  351. & t_LocalService_Sid
  352. );
  353. if ( t_BoolResult )
  354. {
  355. DWORD t_SidLength = ::GetLengthSid ( t_LocalService_Sid );
  356. t_LocalService_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  357. t_LocalService_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_LocalService_ACESize ] ;
  358. if ( t_LocalService_ACE )
  359. {
  360. CopySid ( t_SidLength, (PSID) & t_LocalService_ACE->SidStart, t_LocalService_Sid ) ;
  361. t_LocalService_ACE->Mask = FILE_MAP_ALL_ACCESS ;
  362. t_LocalService_ACE->Header.AceType = 0 ;
  363. t_LocalService_ACE->Header.AceFlags = 3 ;
  364. t_LocalService_ACE->Header.AceSize = t_LocalService_ACESize ;
  365. }
  366. else
  367. {
  368. t_Result = WBEM_E_OUT_OF_MEMORY ;
  369. }
  370. }
  371. else
  372. {
  373. DWORD t_LastError = ::GetLastError();
  374. t_Result = WBEM_E_OUT_OF_MEMORY ;
  375. }
  376. }
  377. PSID t_NetworkService_Sid = NULL ;
  378. ACCESS_ALLOWED_ACE *t_NetworkService_ACE = NULL ;
  379. USHORT t_NetworkService_ACESize = 0 ;
  380. if ( SUCCEEDED ( t_Result ) )
  381. {
  382. t_BoolResult = AllocateAndInitializeSid (
  383. & t_NtAuthoritySid ,
  384. 1 ,
  385. SECURITY_NETWORK_SERVICE_RID ,
  386. 0,
  387. 0,
  388. 0,
  389. 0,
  390. 0,
  391. 0,
  392. 0,
  393. & t_NetworkService_Sid
  394. );
  395. if ( t_BoolResult )
  396. {
  397. DWORD t_SidLength = ::GetLengthSid ( t_NetworkService_Sid );
  398. t_NetworkService_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  399. t_NetworkService_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_NetworkService_ACESize ] ;
  400. if ( t_NetworkService_ACE )
  401. {
  402. CopySid ( t_SidLength, (PSID) & t_NetworkService_ACE->SidStart, t_NetworkService_Sid ) ;
  403. t_NetworkService_ACE->Mask = FILE_MAP_ALL_ACCESS ;
  404. t_NetworkService_ACE->Header.AceType = 0 ;
  405. t_NetworkService_ACE->Header.AceFlags = 3 ;
  406. t_NetworkService_ACE->Header.AceSize = t_NetworkService_ACESize ;
  407. }
  408. else
  409. {
  410. t_Result = WBEM_E_OUT_OF_MEMORY ;
  411. }
  412. }
  413. else
  414. {
  415. DWORD t_LastError = ::GetLastError();
  416. t_Result = WBEM_E_OUT_OF_MEMORY ;
  417. }
  418. }
  419. PSID t_Everyone_Sid = NULL ;
  420. ACCESS_ALLOWED_ACE *t_Everyone_ACE = NULL ;
  421. USHORT t_Everyone_ACESize = 0 ;
  422. if ( SUCCEEDED ( t_Result ) )
  423. {
  424. SID_IDENTIFIER_AUTHORITY t_WorldAuthoritySid = SECURITY_WORLD_SID_AUTHORITY ;
  425. t_BoolResult = AllocateAndInitializeSid (
  426. & t_WorldAuthoritySid ,
  427. 1 ,
  428. SECURITY_WORLD_RID ,
  429. 0,
  430. 0,
  431. 0,
  432. 0,
  433. 0,
  434. 0,
  435. 0,
  436. & t_Everyone_Sid
  437. );
  438. if ( t_BoolResult )
  439. {
  440. DWORD t_SidLength = ::GetLengthSid ( t_Everyone_Sid );
  441. t_Everyone_ACESize = sizeof(ACCESS_ALLOWED_ACE) + (WORD) ( t_SidLength - sizeof(DWORD) ) ;
  442. t_Everyone_ACE = (ACCESS_ALLOWED_ACE*) new BYTE [ t_Everyone_ACESize ] ;
  443. if ( t_Everyone_ACE )
  444. {
  445. CopySid ( t_SidLength, (PSID) & t_Everyone_ACE->SidStart, t_Everyone_Sid ) ;
  446. t_Everyone_ACE->Mask = a_Access ;
  447. t_Everyone_ACE->Header.AceType = 0 ;
  448. t_Everyone_ACE->Header.AceFlags = 3 ;
  449. t_Everyone_ACE->Header.AceSize = t_Everyone_ACESize ;
  450. }
  451. else
  452. {
  453. t_Result = WBEM_E_OUT_OF_MEMORY ;
  454. }
  455. }
  456. else
  457. {
  458. DWORD t_LastError = ::GetLastError();
  459. t_Result = WBEM_E_OUT_OF_MEMORY ;
  460. }
  461. }
  462. if ( SUCCEEDED ( t_Result ) )
  463. {
  464. // Now we need to set permissions on the registry: Everyone read; Admins full.
  465. // We have the sid for admins from the above code. Now get the sid for "Everyone"
  466. DWORD t_TotalAclSize = sizeof(ACL) + t_System_ACESize + t_NetworkService_ACESize + t_LocalService_ACESize + t_Everyone_ACESize ;
  467. PACL t_Dacl = (PACL) new BYTE [ t_TotalAclSize ] ;
  468. if ( t_Dacl )
  469. {
  470. if ( :: InitializeAcl ( t_Dacl, t_TotalAclSize, ACL_REVISION ) )
  471. {
  472. DWORD t_AceIndex = 0 ;
  473. if ( t_System_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_System_ACE , t_System_ACESize ) )
  474. {
  475. t_AceIndex ++ ;
  476. }
  477. if ( t_NetworkService_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_NetworkService_ACE , t_NetworkService_ACESize ) )
  478. {
  479. t_AceIndex ++ ;
  480. }
  481. if ( t_LocalService_ACESize && :: AddAce ( t_Dacl , ACL_REVISION , t_AceIndex , t_LocalService_ACE , t_LocalService_ACESize ) )
  482. {
  483. t_AceIndex ++ ;
  484. }
  485. if ( a_Access )
  486. {
  487. if ( t_Everyone_ACESize && :: AddAce ( t_Dacl , ACL_REVISION, t_AceIndex , t_Everyone_ACE , t_Everyone_ACESize ) )
  488. {
  489. t_AceIndex ++ ;
  490. }
  491. }
  492. t_BoolResult = SetSecurityDescriptorDacl (
  493. & a_SecurityDescriptor ,
  494. TRUE ,
  495. t_Dacl ,
  496. FALSE
  497. ) ;
  498. if ( t_BoolResult == FALSE )
  499. {
  500. delete [] ( ( BYTE * ) t_Dacl ) ;
  501. t_Result = WBEM_E_CRITICAL_ERROR ;
  502. }
  503. }
  504. }
  505. else
  506. {
  507. t_Result = WBEM_E_OUT_OF_MEMORY ;
  508. }
  509. }
  510. if ( t_System_ACE )
  511. {
  512. delete [] ( ( BYTE * ) t_System_ACE ) ;
  513. }
  514. if ( t_NetworkService_ACE )
  515. {
  516. delete [] ( ( BYTE * ) t_NetworkService_ACE ) ;
  517. }
  518. if ( t_LocalService_ACE )
  519. {
  520. delete [] ( ( BYTE * ) t_LocalService_ACE ) ;
  521. }
  522. if ( t_Everyone_ACE )
  523. {
  524. delete [] ( ( BYTE * ) t_Everyone_ACE ) ;
  525. }
  526. if ( t_System_Sid )
  527. {
  528. FreeSid ( t_System_Sid ) ;
  529. }
  530. if ( t_NetworkService_Sid )
  531. {
  532. FreeSid ( t_NetworkService_Sid ) ;
  533. }
  534. if ( t_LocalService_Sid )
  535. {
  536. FreeSid ( t_LocalService_Sid ) ;
  537. }
  538. if ( t_Everyone_Sid )
  539. {
  540. FreeSid ( t_Everyone_Sid ) ;
  541. }
  542. }
  543. else
  544. {
  545. t_Result = WBEM_E_CRITICAL_ERROR ;
  546. }
  547. return t_Result ;
  548. }
  549. /******************************************************************************
  550. *
  551. * Name:
  552. *
  553. *
  554. * Description:
  555. *
  556. *
  557. *****************************************************************************/
  558. HRESULT ProviderSubSystem_Globals :: Initialize_SharedCounters ()
  559. {
  560. HRESULT t_Result = S_OK ;
  561. HANDLE t_Handle = OpenFileMapping (
  562. FILE_MAP_READ | FILE_MAP_WRITE ,
  563. FALSE ,
  564. s_FileMappingName
  565. ) ;
  566. if ( t_Handle == NULL )
  567. {
  568. if ( GetLastError () == ERROR_FILE_NOT_FOUND )
  569. {
  570. SECURITY_DESCRIPTOR t_SecurityDescriptor ;
  571. t_Result = GetSecurityDescriptor (
  572. t_SecurityDescriptor ,
  573. 0
  574. // FILE_MAP_ALL_ACCESS
  575. ) ;
  576. if ( SUCCEEDED ( t_Result ) )
  577. {
  578. SECURITY_ATTRIBUTES t_SecurityAttributes ;
  579. t_SecurityAttributes.nLength = sizeof ( SECURITY_ATTRIBUTES ) ;
  580. t_SecurityAttributes.lpSecurityDescriptor = & t_SecurityDescriptor ;
  581. t_SecurityAttributes.bInheritHandle = FALSE ;
  582. t_Handle = CreateFileMapping (
  583. INVALID_HANDLE_VALUE ,
  584. & t_SecurityAttributes ,
  585. PAGE_READWRITE | SEC_COMMIT ,
  586. 0 ,
  587. sizeof ( CServerObject_ProviderSubsystem_Counters ) ,
  588. s_FileMappingName
  589. ) ;
  590. if ( t_Handle == NULL )
  591. {
  592. t_Result = WBEM_E_ACCESS_DENIED ;
  593. }
  594. delete [] t_SecurityDescriptor.Dacl ;
  595. }
  596. }
  597. else
  598. {
  599. t_Result = WBEM_E_ACCESS_DENIED ;
  600. }
  601. }
  602. void *t_Location = NULL ;
  603. if ( SUCCEEDED ( t_Result ) )
  604. {
  605. t_Location = MapViewOfFile (
  606. t_Handle ,
  607. FILE_MAP_READ | FILE_MAP_WRITE ,
  608. 0 ,
  609. 0 ,
  610. sizeof ( CServerObject_ProviderSubsystem_Counters )
  611. ) ;
  612. if ( t_Location )
  613. {
  614. }
  615. else
  616. {
  617. t_Result = WBEM_E_ACCESS_DENIED ;
  618. }
  619. }
  620. if ( SUCCEEDED ( t_Result ) )
  621. {
  622. s_FileMapping = t_Handle ;
  623. s_SharedCounters = ( CServerObject_ProviderSubsystem_Counters * ) t_Location ;
  624. }
  625. else
  626. {
  627. if ( t_Handle )
  628. {
  629. CloseHandle ( t_Handle ) ;
  630. }
  631. SID_IDENTIFIER_AUTHORITY t_NtAuthoritySid = SECURITY_NT_AUTHORITY ;
  632. PSID t_System_Sid = NULL ;
  633. BOOL t_BoolResult = AllocateAndInitializeSid (
  634. & t_NtAuthoritySid ,
  635. 1 ,
  636. SECURITY_LOCAL_SYSTEM_RID,
  637. 0,
  638. 0,
  639. 0,
  640. 0,
  641. 0,
  642. 0,
  643. 0,
  644. & t_System_Sid
  645. );
  646. if ( t_BoolResult )
  647. {
  648. LPCWSTR t_Array [ 1 ] ;
  649. t_Array [ 0 ] = s_FileMappingName ;
  650. BOOL t_Status = :: ReportEvent (
  651. ProviderSubSystem_Globals :: GetNtEventSource () ,
  652. EVENTLOG_WARNING_TYPE ,
  653. 0 ,
  654. WBEM_MC_PROVIDER_SUBSYSTEM_LOCALSYSTEM_NAMED_SECTION ,
  655. t_System_Sid ,
  656. 1 ,
  657. 0 ,
  658. ( LPCWSTR * ) t_Array ,
  659. NULL
  660. ) ;
  661. if ( t_Status == 0 )
  662. {
  663. DWORD t_LastError = GetLastError () ;
  664. }
  665. LocalFree ( t_System_Sid ) ;
  666. }
  667. }
  668. return t_Result ;
  669. }
  670. /******************************************************************************
  671. *
  672. * Name:
  673. *
  674. *
  675. * Description:
  676. *
  677. *
  678. *****************************************************************************/
  679. HRESULT ProviderSubSystem_Globals :: UnInitialize_SharedCounters ()
  680. {
  681. HRESULT t_Result = S_OK ;
  682. if ( s_SharedCounters )
  683. {
  684. BOOL t_Status = UnmapViewOfFile ( ( void * ) s_SharedCounters ) ;
  685. s_SharedCounters = NULL ;
  686. }
  687. if ( s_FileMapping )
  688. {
  689. CloseHandle ( s_FileMapping ) ;
  690. s_FileMapping = NULL ;
  691. }
  692. return t_Result ;
  693. }
  694. /******************************************************************************
  695. *
  696. * Name:
  697. *
  698. *
  699. * Description:
  700. *
  701. *
  702. *****************************************************************************/
  703. HRESULT ProviderSubSystem_Globals :: CreateJobObject ()
  704. {
  705. HRESULT t_Result = S_OK ;
  706. s_HostJobObject = :: CreateJobObject (
  707. NULL ,
  708. s_HostJobObjectName
  709. ) ;
  710. if ( s_HostJobObject == NULL )
  711. {
  712. switch ( GetLastError () )
  713. {
  714. case ERROR_ALREADY_EXISTS:
  715. {
  716. s_HostJobObject = OpenJobObject (
  717. JOB_OBJECT_ALL_ACCESS ,
  718. FALSE ,
  719. s_HostJobObjectName
  720. ) ;
  721. if ( ! s_HostJobObject )
  722. {
  723. t_Result = WBEM_E_ACCESS_DENIED ;
  724. }
  725. }
  726. break ;
  727. default:
  728. {
  729. t_Result = WBEM_E_ACCESS_DENIED ;
  730. }
  731. break;
  732. }
  733. }
  734. else
  735. {
  736. JOBOBJECTINFOCLASS t_JobObjectInfoClass = JobObjectExtendedLimitInformation ;
  737. JOBOBJECT_EXTENDED_LIMIT_INFORMATION t_JobObjectInfo ;
  738. DWORD t_JobObjectInfoLength = sizeof ( JOBOBJECT_EXTENDED_LIMIT_INFORMATION ) ;
  739. ZeroMemory ( & t_JobObjectInfo , sizeof ( JOBOBJECT_EXTENDED_LIMIT_INFORMATION ) ) ;
  740. ULONG t_LimitRequirements = s_Quota_ProcessLimitCount > 0 ? JOB_OBJECT_LIMIT_ACTIVE_PROCESS : 0 ;
  741. t_LimitRequirements = ( s_Quota_ProcessMemoryLimitCount > 0 ? t_LimitRequirements | JOB_OBJECT_LIMIT_JOB_MEMORY : t_LimitRequirements );
  742. t_LimitRequirements = s_Quota_JobMemoryLimitCount > 0 ? t_LimitRequirements | JOB_OBJECT_LIMIT_PROCESS_MEMORY : t_LimitRequirements ;
  743. t_JobObjectInfo.BasicLimitInformation.LimitFlags = t_LimitRequirements | JOB_OBJECT_LIMIT_BREAKAWAY_OK;
  744. t_JobObjectInfo.BasicLimitInformation.ActiveProcessLimit = s_Quota_ProcessLimitCount ;
  745. t_JobObjectInfo.ProcessMemoryLimit = s_Quota_ProcessMemoryLimitCount ;
  746. t_JobObjectInfo.JobMemoryLimit = s_Quota_JobMemoryLimitCount ;
  747. t_JobObjectInfo.PeakProcessMemoryUsed = s_Quota_ProcessMemoryLimitCount ;
  748. t_JobObjectInfo.PeakJobMemoryUsed = s_Quota_JobMemoryLimitCount ;
  749. OSVERSIONINFOEX t_OsInformationEx ;
  750. ZeroMemory ( & t_OsInformationEx , sizeof ( t_OsInformationEx ) ) ;
  751. t_OsInformationEx.dwOSVersionInfoSize = sizeof ( t_OsInformationEx ) ;
  752. if ( GetVersionEx ( ( OSVERSIONINFO * ) & t_OsInformationEx ) )
  753. {
  754. if ( ( t_OsInformationEx.dwPlatformId == VER_PLATFORM_WIN32_NT ) && ( ( t_OsInformationEx.dwMajorVersion > 5 ) || ( ( t_OsInformationEx.dwMajorVersion == 5 ) && ( t_OsInformationEx.dwMinorVersion >= 1 ) ) ) )
  755. {
  756. t_JobObjectInfo.BasicLimitInformation.LimitFlags = t_JobObjectInfo.BasicLimitInformation.LimitFlags | JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE | JOB_OBJECT_LIMIT_BREAKAWAY_OK;
  757. }
  758. }
  759. else
  760. {
  761. t_Result = WBEM_E_UNEXPECTED ;
  762. }
  763. if ( SUCCEEDED ( t_Result ) )
  764. {
  765. BOOL t_Status = SetInformationJobObject (
  766. s_HostJobObject ,
  767. t_JobObjectInfoClass ,
  768. & t_JobObjectInfo ,
  769. t_JobObjectInfoLength
  770. ) ;
  771. if ( t_Status == FALSE )
  772. {
  773. t_Result = WBEM_E_ACCESS_DENIED ;
  774. }
  775. }
  776. }
  777. return t_Result ;
  778. }
  779. /******************************************************************************
  780. *
  781. * Name:
  782. *
  783. *
  784. * Description:
  785. *
  786. *
  787. *****************************************************************************/
  788. HRESULT ProviderSubSystem_Globals :: DeleteJobObject ()
  789. {
  790. HRESULT t_Result = S_OK ;
  791. if ( s_HostJobObject )
  792. {
  793. BOOL t_Status = TerminateJobObject ( s_HostJobObject , 0 ) ;
  794. CloseHandle ( s_HostJobObject ) ;
  795. s_HostJobObject = NULL ;
  796. }
  797. return t_Result ;
  798. }
  799. /******************************************************************************
  800. *
  801. * Name:
  802. *
  803. *
  804. * Description:
  805. *
  806. *
  807. *****************************************************************************/
  808. HRESULT ProviderSubSystem_Globals :: AssignProcessToJobObject ( HANDLE a_Handle )
  809. {
  810. HRESULT t_Result = S_OK ;
  811. if ( s_HostJobObject )
  812. {
  813. BOOL t_Status =:: AssignProcessToJobObject (
  814. s_HostJobObject ,
  815. a_Handle
  816. ) ;
  817. if ( t_Status == FALSE )
  818. {
  819. t_Result = WBEM_E_ACCESS_DENIED ;
  820. }
  821. }
  822. else
  823. {
  824. t_Result = WBEM_E_CRITICAL_ERROR ;
  825. }
  826. return t_Result ;
  827. }
  828. /******************************************************************************
  829. *
  830. * Name:
  831. *
  832. *
  833. * Description:
  834. *
  835. *
  836. *****************************************************************************/
  837. HRESULT ProviderSubSystem_Globals :: Global_Startup ()
  838. {
  839. HRESULT t_Result = S_OK ;
  840. if ( ! s_Allocator )
  841. {
  842. /*
  843. * Use the global process heap for this particular boot operation
  844. */
  845. WmiAllocator t_Allocator ;
  846. WmiStatusCode t_StatusCode = t_Allocator.New (
  847. ( void ** ) & s_Allocator ,
  848. sizeof ( WmiAllocator )
  849. ) ;
  850. if ( t_StatusCode == e_StatusCode_Success )
  851. {
  852. #ifdef DBG
  853. :: new ( ( void * ) s_Allocator ) WmiAllocator ( WmiAllocator :: e_DefaultAllocation , 0 , 0 ) ;
  854. #else
  855. :: new ( ( void * ) s_Allocator ) WmiAllocator ;
  856. #endif
  857. t_StatusCode = s_Allocator->Initialize () ;
  858. if ( t_StatusCode != e_StatusCode_Success )
  859. {
  860. t_Result = WBEM_E_OUT_OF_MEMORY ;
  861. }
  862. }
  863. else
  864. {
  865. t_Result = WBEM_E_OUT_OF_MEMORY ;
  866. }
  867. }
  868. if ( SUCCEEDED ( t_Result ) )
  869. {
  870. WmiStatusCode t_StatusCode = WmiHelper :: InitializeCriticalSection ( & s_DecoupledRegistrySection ) ;
  871. if ( t_StatusCode != e_StatusCode_Success )
  872. {
  873. t_Result = WBEM_E_OUT_OF_MEMORY ;
  874. }
  875. }
  876. if ( SUCCEEDED ( t_Result ) )
  877. {
  878. WmiStatusCode t_StatusCode = WmiHelper :: InitializeCriticalSection ( & s_GuidTagSection ) ;
  879. if ( t_StatusCode == e_StatusCode_Success )
  880. {
  881. s_GuidTag = new CWbemGlobal_ComServerTagContainer ( *s_Allocator ) ;
  882. if ( s_GuidTag )
  883. {
  884. t_StatusCode = s_GuidTag->Initialize () ;
  885. if ( t_StatusCode != e_StatusCode_Success )
  886. {
  887. t_Result = WBEM_E_OUT_OF_MEMORY ;
  888. }
  889. }
  890. else
  891. {
  892. t_Result = WBEM_E_OUT_OF_MEMORY ;
  893. }
  894. }
  895. else
  896. {
  897. t_Result = WBEM_E_OUT_OF_MEMORY ;
  898. }
  899. }
  900. if ( SUCCEEDED ( t_Result ) )
  901. {
  902. s_NtEventLogSource = RegisterEventSource ( NULL , s_ProviderSubsystemEventSourceName ) ;
  903. if ( s_NtEventLogSource == NULL )
  904. {
  905. return WBEM_E_CRITICAL_ERROR ;
  906. }
  907. }
  908. if ( SUCCEEDED ( t_Result ) )
  909. {
  910. s_ProvSubSysController = :: new CWbemGlobal_IWmiProvSubSysController ( *s_Allocator ) ;
  911. if ( s_ProvSubSysController )
  912. {
  913. s_ProvSubSysController->AddRef () ;
  914. WmiStatusCode t_StatusCode = s_ProvSubSysController->Initialize () ;
  915. if ( t_StatusCode != e_StatusCode_Success )
  916. {
  917. delete s_ProvSubSysController ;
  918. s_ProvSubSysController = NULL ;
  919. t_Result = WBEM_E_OUT_OF_MEMORY ;
  920. }
  921. }
  922. else
  923. {
  924. t_Result = WBEM_E_OUT_OF_MEMORY ;
  925. }
  926. }
  927. if ( SUCCEEDED ( t_Result ) )
  928. {
  929. s_SyncProviderController = :: new CWbemGlobal_IWbemSyncProviderController ( *s_Allocator ) ;
  930. if ( s_SyncProviderController )
  931. {
  932. s_SyncProviderController->AddRef () ;
  933. WmiStatusCode t_StatusCode = s_SyncProviderController->Initialize () ;
  934. if ( t_StatusCode != e_StatusCode_Success )
  935. {
  936. delete s_SyncProviderController ;
  937. s_SyncProviderController = NULL ;
  938. t_Result = WBEM_E_OUT_OF_MEMORY ;
  939. }
  940. }
  941. else
  942. {
  943. t_Result = WBEM_E_OUT_OF_MEMORY ;
  944. }
  945. }
  946. if ( SUCCEEDED ( t_Result ) )
  947. {
  948. s_HostedProviderController = :: new CWbemGlobal_HostedProviderController ( *s_Allocator ) ;
  949. if ( s_HostedProviderController )
  950. {
  951. s_HostedProviderController->AddRef () ;
  952. WmiStatusCode t_StatusCode = s_HostedProviderController->Initialize () ;
  953. if ( t_StatusCode != e_StatusCode_Success )
  954. {
  955. delete s_HostedProviderController ;
  956. s_HostedProviderController = NULL ;
  957. t_Result = WBEM_E_OUT_OF_MEMORY ;
  958. }
  959. }
  960. else
  961. {
  962. t_Result = WBEM_E_OUT_OF_MEMORY ;
  963. }
  964. }
  965. if ( SUCCEEDED ( t_Result ) )
  966. {
  967. s_HostController = :: new HostController ( *s_Allocator ) ;
  968. if ( s_HostController )
  969. {
  970. s_HostController->AddRef () ;
  971. WmiStatusCode t_StatusCode = s_HostController->Initialize () ;
  972. if ( t_StatusCode != e_StatusCode_Success )
  973. {
  974. delete s_HostController ;
  975. s_HostController = NULL ;
  976. t_Result = WBEM_E_OUT_OF_MEMORY ;
  977. }
  978. }
  979. else
  980. {
  981. t_Result = WBEM_E_OUT_OF_MEMORY ;
  982. }
  983. }
  984. if ( SUCCEEDED ( t_Result ) )
  985. {
  986. s_RefresherManagerController = :: new RefresherManagerController ( *s_Allocator ) ;
  987. if ( s_RefresherManagerController )
  988. {
  989. s_RefresherManagerController->AddRef () ;
  990. WmiStatusCode t_StatusCode = s_RefresherManagerController->Initialize () ;
  991. if ( t_StatusCode != e_StatusCode_Success )
  992. {
  993. delete s_RefresherManagerController ;
  994. s_RefresherManagerController = NULL ;
  995. t_Result = WBEM_E_OUT_OF_MEMORY ;
  996. }
  997. }
  998. else
  999. {
  1000. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1001. }
  1002. }
  1003. if ( SUCCEEDED ( t_Result ) )
  1004. {
  1005. WmiStatusCode t_StatusCode = WmiThread <ULONG> :: Static_Initialize ( *s_Allocator ) ;
  1006. }
  1007. ProviderSubSystem_Common_Globals :: InitializeTransmitSize () ;
  1008. ProviderSubSystem_Common_Globals :: InitializeDefaultStackSize () ;
  1009. return t_Result ;
  1010. }
  1011. /******************************************************************************
  1012. *
  1013. * Name:
  1014. *
  1015. *
  1016. * Description:
  1017. *
  1018. *
  1019. *****************************************************************************/
  1020. HRESULT ProviderSubSystem_Globals :: Global_Shutdown ()
  1021. {
  1022. HRESULT t_Result = S_OK ;
  1023. WmiStatusCode t_StatusCode = WmiHelper :: DeleteCriticalSection ( & s_DecoupledRegistrySection ) ;
  1024. t_StatusCode = WmiHelper :: DeleteCriticalSection ( & s_GuidTagSection ) ;
  1025. if ( s_GuidTag )
  1026. {
  1027. t_StatusCode = s_GuidTag->UnInitialize () ;
  1028. delete s_GuidTag ;
  1029. s_GuidTag = NULL ;
  1030. }
  1031. if ( s_ProvSubSysController )
  1032. {
  1033. WmiStatusCode t_StatusCode = s_ProvSubSysController->UnInitialize () ;
  1034. s_ProvSubSysController->Release () ;
  1035. s_ProvSubSysController = NULL ;
  1036. }
  1037. if ( s_SyncProviderController )
  1038. {
  1039. WmiStatusCode t_StatusCode = s_SyncProviderController->Shutdown () ;
  1040. t_StatusCode = s_SyncProviderController->UnInitialize () ;
  1041. s_SyncProviderController->Release () ;
  1042. s_SyncProviderController = NULL ;
  1043. }
  1044. if ( s_HostedProviderController )
  1045. {
  1046. WmiStatusCode t_StatusCode = s_HostController->Shutdown () ;
  1047. t_StatusCode = s_HostController->UnInitialize () ;
  1048. s_HostController->Release () ;
  1049. s_HostController = NULL ;
  1050. }
  1051. if ( s_HostController )
  1052. {
  1053. WmiStatusCode t_StatusCode = s_HostController->Shutdown () ;
  1054. t_StatusCode = s_HostController->UnInitialize () ;
  1055. s_HostController->Release () ;
  1056. s_HostController = NULL ;
  1057. }
  1058. if ( s_RefresherManagerController )
  1059. {
  1060. WmiStatusCode t_StatusCode = s_RefresherManagerController->Shutdown () ;
  1061. t_StatusCode = s_RefresherManagerController->UnInitialize () ;
  1062. s_RefresherManagerController->Release () ;
  1063. s_RefresherManagerController= NULL ;
  1064. }
  1065. t_StatusCode = WmiThread <ULONG> :: Static_UnInitialize ( *s_Allocator ) ;
  1066. if ( s_NtEventLogSource )
  1067. {
  1068. DeregisterEventSource ( s_NtEventLogSource ) ;
  1069. }
  1070. if ( s_Allocator )
  1071. {
  1072. /*
  1073. * Use the global process heap for this particular boot operation
  1074. */
  1075. WmiAllocator t_Allocator ;
  1076. WmiStatusCode t_StatusCode = t_Allocator.Delete (
  1077. ( void * ) s_Allocator
  1078. ) ;
  1079. if ( t_StatusCode != e_StatusCode_Success )
  1080. {
  1081. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1082. }
  1083. }
  1084. return t_Result ;
  1085. }
  1086. /******************************************************************************
  1087. *
  1088. * Name:
  1089. *
  1090. *
  1091. * Description:
  1092. *
  1093. *
  1094. *****************************************************************************/
  1095. CWbemGlobal_ComServerTagContainer *ProviderSubSystem_Globals :: GetGuidTag ()
  1096. {
  1097. return s_GuidTag ;
  1098. }
  1099. /******************************************************************************
  1100. *
  1101. * Name:
  1102. *
  1103. *
  1104. * Description:
  1105. *
  1106. *
  1107. *****************************************************************************/
  1108. CWbemGlobal_IWmiProvSubSysController *ProviderSubSystem_Globals :: GetProvSubSysController ()
  1109. {
  1110. return s_ProvSubSysController ;
  1111. }
  1112. /******************************************************************************
  1113. *
  1114. * Name:
  1115. *
  1116. *
  1117. * Description:
  1118. *
  1119. *
  1120. *****************************************************************************/
  1121. CWbemGlobal_IWbemSyncProviderController *ProviderSubSystem_Globals :: GetSyncProviderController ()
  1122. {
  1123. return s_SyncProviderController ;
  1124. }
  1125. /******************************************************************************
  1126. *
  1127. * Name:
  1128. *
  1129. *
  1130. * Description:
  1131. *
  1132. *
  1133. *****************************************************************************/
  1134. HostController *ProviderSubSystem_Globals :: GetHostController ()
  1135. {
  1136. return s_HostController ;
  1137. }
  1138. /******************************************************************************
  1139. *
  1140. * Name:
  1141. *
  1142. *
  1143. * Description:
  1144. *
  1145. *
  1146. *****************************************************************************/
  1147. RefresherManagerController *ProviderSubSystem_Globals :: GetRefresherManagerController ()
  1148. {
  1149. return s_RefresherManagerController ;
  1150. }
  1151. /******************************************************************************
  1152. *
  1153. * Name:
  1154. *
  1155. *
  1156. * Description:
  1157. *
  1158. *
  1159. *****************************************************************************/
  1160. CWbemGlobal_HostedProviderController *ProviderSubSystem_Globals :: GetHostedProviderController ()
  1161. {
  1162. return s_HostedProviderController ;
  1163. }
  1164. /******************************************************************************
  1165. *
  1166. * Name:
  1167. *
  1168. *
  1169. * Description:
  1170. *
  1171. *
  1172. *****************************************************************************/
  1173. CriticalSection *ProviderSubSystem_Globals :: GetGuidTagCriticalSection ()
  1174. {
  1175. return & s_GuidTagSection ;
  1176. }
  1177. /******************************************************************************
  1178. *
  1179. * Name:
  1180. *
  1181. *
  1182. * Description:
  1183. *
  1184. *
  1185. *****************************************************************************/
  1186. CriticalSection *ProviderSubSystem_Globals :: GetDecoupledRegistrySection ()
  1187. {
  1188. return & s_DecoupledRegistrySection ;
  1189. }
  1190. /******************************************************************************
  1191. *
  1192. * Name:
  1193. *
  1194. *
  1195. * Description:
  1196. *
  1197. *
  1198. *****************************************************************************/
  1199. void * __cdecl operator new ( size_t a_Size )
  1200. {
  1201. void *t_Ptr ;
  1202. WmiStatusCode t_StatusCode = ProviderSubSystem_Globals :: s_Allocator->New (
  1203. ( void ** ) & t_Ptr ,
  1204. a_Size
  1205. ) ;
  1206. if ( t_StatusCode != e_StatusCode_Success )
  1207. {
  1208. #if 1
  1209. t_Ptr = NULL ;
  1210. #else
  1211. throw Wmi_Heap_Exception (
  1212. Wmi_Heap_Exception::HEAP_ERROR::E_ALLOCATION_ERROR
  1213. ) ;
  1214. #endif
  1215. }
  1216. return t_Ptr ;
  1217. }
  1218. /******************************************************************************
  1219. *
  1220. * Name:
  1221. *
  1222. *
  1223. * Description:
  1224. *
  1225. *
  1226. *****************************************************************************/
  1227. void __cdecl operator delete ( void *a_Ptr )
  1228. {
  1229. if ( a_Ptr )
  1230. {
  1231. WmiStatusCode t_StatusCode = ProviderSubSystem_Globals :: s_Allocator->Delete (
  1232. ( void * ) a_Ptr
  1233. ) ;
  1234. }
  1235. }
  1236. /******************************************************************************
  1237. *
  1238. * Name:
  1239. *
  1240. *
  1241. * Description:
  1242. *
  1243. *
  1244. *****************************************************************************/
  1245. HRESULT ProviderSubSystem_Globals :: ForwardReload (
  1246. long a_Flags ,
  1247. IWbemContext *a_Context ,
  1248. LPCWSTR a_Namespace ,
  1249. LPCWSTR a_Provider
  1250. )
  1251. {
  1252. HRESULT t_Result = S_OK ;
  1253. CWbemGlobal_IWmiProvSubSysController *t_SubSystemController = ProviderSubSystem_Globals :: GetProvSubSysController () ;
  1254. if ( t_SubSystemController )
  1255. {
  1256. t_SubSystemController->Lock () ;
  1257. CWbemGlobal_IWmiProvSubSysController_Container *t_Container = NULL ;
  1258. t_SubSystemController->GetContainer ( t_Container ) ;
  1259. if ( t_Container->Size () )
  1260. {
  1261. CWbemGlobal_IWmiProvSubSysController_Container_Iterator t_Iterator = t_Container->Begin ();
  1262. CServerObject_ProviderSubSystem **t_ControllerElements = new CServerObject_ProviderSubSystem * [ t_Container->Size () ] ;
  1263. if ( t_ControllerElements )
  1264. {
  1265. ULONG t_Count = 0 ;
  1266. while ( ! t_Iterator.Null () )
  1267. {
  1268. HRESULT t_Result = t_Iterator.GetElement ()->QueryInterface ( IID_CWbemProviderSubSystem , ( void ** ) & t_ControllerElements [ t_Count ] ) ;
  1269. t_Iterator.Increment () ;
  1270. t_Count ++ ;
  1271. }
  1272. t_SubSystemController->UnLock () ;
  1273. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  1274. {
  1275. if ( t_ControllerElements [ t_Index ] )
  1276. {
  1277. t_Result = t_ControllerElements [ t_Index ]->ForwardReload (
  1278. 0 ,
  1279. NULL ,
  1280. a_Namespace ,
  1281. a_Provider
  1282. ) ;
  1283. t_ControllerElements [ t_Index ]->Release () ;
  1284. }
  1285. }
  1286. delete [] t_ControllerElements ;
  1287. }
  1288. else
  1289. {
  1290. t_SubSystemController->UnLock () ;
  1291. }
  1292. }
  1293. else
  1294. {
  1295. t_SubSystemController->UnLock () ;
  1296. }
  1297. }
  1298. else
  1299. {
  1300. t_Result = WBEM_E_CRITICAL_ERROR ;
  1301. }
  1302. return t_Result ;
  1303. }
  1304. /******************************************************************************
  1305. *
  1306. * Name:
  1307. *
  1308. *
  1309. * Description:
  1310. *
  1311. *
  1312. *****************************************************************************/
  1313. BOOL ProviderSubSystem_Globals :: CheckGuidTag ( const GUID &a_Guid )
  1314. {
  1315. BOOL t_Present = FALSE ;
  1316. CWbemGlobal_ComServerTagContainer_Iterator t_Iterator ;
  1317. WmiStatusCode t_StatusCode = WmiHelper :: EnterCriticalSection ( & s_GuidTagSection ) ;
  1318. t_StatusCode = s_GuidTag->Find ( a_Guid , t_Iterator ) ;
  1319. if ( t_StatusCode == e_StatusCode_Success )
  1320. {
  1321. t_Present = TRUE ;
  1322. }
  1323. t_StatusCode = WmiHelper :: LeaveCriticalSection ( & s_GuidTagSection ) ;
  1324. return t_Present ;
  1325. }
  1326. /******************************************************************************
  1327. *
  1328. * Name:
  1329. *
  1330. *
  1331. * Description:
  1332. *
  1333. *
  1334. *****************************************************************************/
  1335. void ProviderSubSystem_Globals :: InsertGuidTag ( const GUID &a_Guid )
  1336. {
  1337. CWbemGlobal_ComServerTagContainer_Iterator t_Iterator ;
  1338. WmiStatusCode t_StatusCode = WmiHelper :: EnterCriticalSection ( & s_GuidTagSection ) ;
  1339. t_StatusCode = s_GuidTag->Insert ( a_Guid , a_Guid , t_Iterator ) ;
  1340. t_StatusCode = WmiHelper :: LeaveCriticalSection ( & s_GuidTagSection ) ;
  1341. }
  1342. /******************************************************************************
  1343. *
  1344. * Name:
  1345. *
  1346. *
  1347. * Description:
  1348. *
  1349. *
  1350. *****************************************************************************/
  1351. void ProviderSubSystem_Globals :: DeleteGuidTag ( const GUID &a_Guid )
  1352. {
  1353. WmiStatusCode t_StatusCode = WmiHelper :: EnterCriticalSection ( & s_GuidTagSection ) ;
  1354. t_StatusCode = s_GuidTag->Delete ( a_Guid ) ;
  1355. t_StatusCode = WmiHelper :: LeaveCriticalSection ( & s_GuidTagSection ) ;
  1356. }
  1357. /******************************************************************************
  1358. *
  1359. * Name:
  1360. *
  1361. *
  1362. * Description:
  1363. *
  1364. *
  1365. *****************************************************************************/
  1366. void ProviderSubSystem_Globals :: ClearGuidTag ()
  1367. {
  1368. WmiStatusCode t_StatusCode = WmiHelper :: EnterCriticalSection ( & s_GuidTagSection ) ;
  1369. CWbemGlobal_ComServerTagContainer_Iterator GuidTagIt = s_GuidTag->Begin();
  1370. while (!GuidTagIt.Null())
  1371. {
  1372. s_GuidTag->Delete (GuidTagIt.GetKey());
  1373. GuidTagIt = s_GuidTag->Begin();
  1374. }
  1375. t_StatusCode = WmiHelper :: LeaveCriticalSection ( & s_GuidTagSection ) ;
  1376. }
  1377. /******************************************************************************
  1378. *
  1379. * Name:
  1380. *
  1381. *
  1382. * Description:
  1383. *
  1384. *
  1385. *****************************************************************************/
  1386. HRESULT ProviderSubSystem_Globals :: BeginThreadImpersonation (
  1387. IUnknown *&a_OldContext ,
  1388. IServerSecurity *&a_OldSecurity ,
  1389. BOOL &a_Impersonating
  1390. )
  1391. {
  1392. HRESULT t_Result = S_OK ;
  1393. IServerSecurity *t_ServerSecurity = NULL ;
  1394. t_Result = CoGetCallContext ( IID_IUnknown , ( void ** ) & a_OldContext ) ;
  1395. if ( SUCCEEDED ( t_Result ) )
  1396. {
  1397. t_Result = a_OldContext->QueryInterface ( IID_IServerSecurity , ( void ** ) & t_ServerSecurity ) ;
  1398. if ( SUCCEEDED ( t_Result ) )
  1399. {
  1400. a_Impersonating = t_ServerSecurity->IsImpersonating () ;
  1401. }
  1402. else
  1403. {
  1404. a_Impersonating = FALSE ;
  1405. }
  1406. }
  1407. CWbemCallSecurity *t_CallSecurity = CWbemCallSecurity :: New () ;
  1408. if ( t_CallSecurity )
  1409. {
  1410. t_CallSecurity->AddRef () ;
  1411. _IWmiThreadSecHandle *t_ThreadSecurity = NULL ;
  1412. t_Result = t_CallSecurity->GetThreadSecurity ( ( WMI_THREAD_SECURITY_ORIGIN ) ( WMI_ORIGIN_THREAD ) , & t_ThreadSecurity ) ;
  1413. if ( SUCCEEDED ( t_Result ) )
  1414. {
  1415. t_Result = t_CallSecurity->SetThreadSecurity ( t_ThreadSecurity ) ;
  1416. if ( SUCCEEDED ( t_Result ) )
  1417. {
  1418. t_Result = t_CallSecurity->QueryInterface ( IID_IServerSecurity , ( void ** ) & a_OldSecurity ) ;
  1419. if ( SUCCEEDED ( t_Result ) )
  1420. {
  1421. if ( a_Impersonating )
  1422. {
  1423. t_ServerSecurity->RevertToSelf () ;
  1424. }
  1425. }
  1426. }
  1427. t_ThreadSecurity->Release () ;
  1428. }
  1429. t_CallSecurity->Release () ;
  1430. }
  1431. if ( t_ServerSecurity )
  1432. {
  1433. t_ServerSecurity->Release () ;
  1434. }
  1435. return t_Result ;
  1436. }
  1437. /******************************************************************************
  1438. *
  1439. * Name:
  1440. *
  1441. *
  1442. * Description:
  1443. *
  1444. *
  1445. *****************************************************************************/
  1446. HRESULT ProviderSubSystem_Globals :: EndThreadImpersonation (
  1447. IUnknown *a_OldContext ,
  1448. IServerSecurity *a_OldSecurity ,
  1449. BOOL a_Impersonating
  1450. )
  1451. {
  1452. HRESULT t_Result = S_OK ;
  1453. IUnknown *t_NewContext = NULL ;
  1454. t_Result = CoSwitchCallContext ( a_OldContext , & t_NewContext ) ;
  1455. if ( SUCCEEDED ( t_Result ) )
  1456. {
  1457. if ( a_OldContext )
  1458. {
  1459. if ( a_Impersonating )
  1460. {
  1461. IServerSecurity *t_ServerSecurity = NULL ;
  1462. t_Result = a_OldContext->QueryInterface ( IID_IServerSecurity , ( void ** ) & t_ServerSecurity ) ;
  1463. if ( SUCCEEDED ( t_Result ) )
  1464. {
  1465. t_ServerSecurity->ImpersonateClient () ;
  1466. t_ServerSecurity->Release () ;
  1467. }
  1468. }
  1469. }
  1470. if ( a_OldSecurity )
  1471. {
  1472. a_OldSecurity->Release() ;
  1473. }
  1474. }
  1475. else
  1476. {
  1477. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1478. }
  1479. /*
  1480. * CoGetCallContext AddReffed this thing so now we have to release it.
  1481. */
  1482. if ( a_OldContext )
  1483. {
  1484. a_OldContext->Release () ;
  1485. }
  1486. return t_Result ;
  1487. }
  1488. /******************************************************************************
  1489. *
  1490. * Name:
  1491. *
  1492. *
  1493. * Description:
  1494. *
  1495. *
  1496. *****************************************************************************/
  1497. HRESULT ProviderSubSystem_Globals :: Begin_IdentifyCall_PrvHost (
  1498. WmiInternalContext a_InternalContext ,
  1499. BOOL &a_Impersonating ,
  1500. IUnknown *&a_OldContext ,
  1501. IServerSecurity *&a_OldSecurity
  1502. )
  1503. {
  1504. HRESULT t_Result = WBEM_E_INVALID_PARAMETER ;
  1505. if ( a_InternalContext.m_IdentifyHandle )
  1506. {
  1507. HANDLE t_IdentifyToken = ( HANDLE ) a_InternalContext.m_IdentifyHandle ;
  1508. BOOL t_Status = SetThreadToken ( NULL , t_IdentifyToken ) ;
  1509. if ( t_Status )
  1510. {
  1511. t_Result = BeginThreadImpersonation ( a_OldContext , a_OldSecurity , a_Impersonating ) ;
  1512. RevertToSelf () ;
  1513. }
  1514. else
  1515. {
  1516. t_Result = WBEM_E_ACCESS_DENIED ;
  1517. }
  1518. CloseHandle ( t_IdentifyToken ) ;
  1519. }
  1520. return t_Result ;
  1521. }
  1522. /******************************************************************************
  1523. *
  1524. * Name:
  1525. *
  1526. *
  1527. * Description:
  1528. *
  1529. *
  1530. *****************************************************************************/
  1531. HRESULT ProviderSubSystem_Globals :: End_IdentifyCall_PrvHost (
  1532. WmiInternalContext a_InternalContext ,
  1533. IUnknown *&a_OldContext ,
  1534. IServerSecurity *&a_OldSecurity ,
  1535. BOOL &a_Impersonating
  1536. )
  1537. {
  1538. EndThreadImpersonation ( a_OldContext , a_OldSecurity , a_Impersonating ) ;
  1539. RevertToSelf () ;
  1540. return S_OK ;
  1541. }
  1542. /******************************************************************************
  1543. *
  1544. * Name:
  1545. *
  1546. *
  1547. * Description:
  1548. *
  1549. *
  1550. *****************************************************************************/
  1551. HRESULT ProviderSubSystem_Globals :: Begin_IdentifyCall_SvcHost (
  1552. WmiInternalContext a_InternalContext ,
  1553. BOOL &a_Impersonating ,
  1554. IUnknown *&a_OldContext ,
  1555. IServerSecurity *&a_OldSecurity
  1556. )
  1557. {
  1558. HRESULT t_Result = WBEM_E_INVALID_PARAMETER ;
  1559. if ( a_InternalContext.m_IdentifyHandle )
  1560. {
  1561. HANDLE t_IdentifyToken = NULL ;
  1562. t_Result = CoImpersonateClient () ;
  1563. if ( SUCCEEDED ( t_Result ) )
  1564. {
  1565. HANDLE t_CallerIdentifyToken = ( HANDLE ) a_InternalContext.m_IdentifyHandle ;
  1566. DWORD t_ProcessIdentifier = a_InternalContext.m_ProcessIdentifier ;
  1567. HANDLE t_ProcessHandle = OpenProcess (
  1568. PROCESS_DUP_HANDLE ,
  1569. FALSE ,
  1570. t_ProcessIdentifier
  1571. ) ;
  1572. if ( t_ProcessHandle )
  1573. {
  1574. BOOL t_Status = DuplicateHandle (
  1575. t_ProcessHandle ,
  1576. t_CallerIdentifyToken ,
  1577. GetCurrentProcess () ,
  1578. & t_IdentifyToken ,
  1579. MAXIMUM_ALLOWED | TOKEN_DUPLICATE | TOKEN_IMPERSONATE ,
  1580. TRUE ,
  1581. 0
  1582. ) ;
  1583. if ( t_Status )
  1584. {
  1585. }
  1586. else
  1587. {
  1588. t_Result = WBEM_E_ACCESS_DENIED ;
  1589. }
  1590. CloseHandle ( t_ProcessHandle ) ;
  1591. }
  1592. else
  1593. {
  1594. t_Result = WBEM_E_ACCESS_DENIED ;
  1595. }
  1596. CoRevertToSelf () ;
  1597. }
  1598. if ( SUCCEEDED ( t_Result ) )
  1599. {
  1600. BOOL t_Status = SetThreadToken ( NULL , t_IdentifyToken ) ;
  1601. if ( t_Status )
  1602. {
  1603. t_Result = BeginThreadImpersonation ( a_OldContext , a_OldSecurity , a_Impersonating ) ;
  1604. CoRevertToSelf () ;
  1605. RevertToSelf () ;
  1606. }
  1607. else
  1608. {
  1609. t_Result = WBEM_E_ACCESS_DENIED ;
  1610. }
  1611. CloseHandle ( t_IdentifyToken ) ;
  1612. }
  1613. }
  1614. return t_Result ;
  1615. }
  1616. /******************************************************************************
  1617. *
  1618. * Name:
  1619. *
  1620. *
  1621. * Description:
  1622. *
  1623. *
  1624. *****************************************************************************/
  1625. HRESULT ProviderSubSystem_Globals :: End_IdentifyCall_SvcHost (
  1626. WmiInternalContext a_InternalContext ,
  1627. IUnknown *&a_OldContext ,
  1628. IServerSecurity *&a_OldSecurity ,
  1629. BOOL &a_Impersonating
  1630. )
  1631. {
  1632. EndThreadImpersonation ( a_OldContext , a_OldSecurity , a_Impersonating ) ;
  1633. RevertToSelf () ;
  1634. return S_OK ;
  1635. }
  1636. /******************************************************************************
  1637. *
  1638. * Name:
  1639. *
  1640. *
  1641. * Description:
  1642. *
  1643. *
  1644. *****************************************************************************/
  1645. LONG ProviderSubSystem_Globals :: Increment_Global_Object_Count ()
  1646. {
  1647. return InterlockedIncrement ( & ProviderSubSystem_Globals :: s_ObjectsInProgress ) ;
  1648. }
  1649. /******************************************************************************
  1650. *
  1651. * Name:
  1652. *
  1653. *
  1654. * Description:
  1655. *
  1656. *
  1657. *****************************************************************************/
  1658. LONG ProviderSubSystem_Globals :: Decrement_Global_Object_Count ()
  1659. {
  1660. LONG t_Count = InterlockedDecrement ( & ProviderSubSystem_Globals :: s_ObjectsInProgress ) ;
  1661. #ifdef WMIASLOCAL
  1662. #ifdef DBG
  1663. if ( t_Count == 1 )
  1664. {
  1665. SetObjectDestruction () ;
  1666. }
  1667. #else
  1668. if ( ProviderSubSystem_Globals :: s_CServerObject_Host_ObjectsInProgress == 0 )
  1669. {
  1670. SetObjectDestruction () ;
  1671. }
  1672. #endif
  1673. #endif
  1674. return t_Count ;
  1675. }