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.

2377 lines
65 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. ProvFact.cpp
  5. Abstract:
  6. History:
  7. --*/
  8. #include <PreComp.h>
  9. #include <wbemint.h>
  10. #include <NCObjApi.h>
  11. #include "Globals.h"
  12. #include "CGlobals.h"
  13. #include "ProvResv.h"
  14. #include "ProvFact.h"
  15. #include "ProvSubS.h"
  16. #include "ProvRegInfo.h"
  17. #include "ProvLoad.h"
  18. #include "ProvWsv.h"
  19. #include "ProvWsvS.h"
  20. #include "ProvInSk.h"
  21. #include "StaThread.h"
  22. #include "Guids.h"
  23. /******************************************************************************
  24. *
  25. * Name:
  26. *
  27. *
  28. * Description:
  29. *
  30. *
  31. *****************************************************************************/
  32. CServerObject_RawFactory :: CServerObject_RawFactory (
  33. WmiAllocator &a_Allocator
  34. ) :
  35. m_Allocator ( a_Allocator ) ,
  36. m_ReferenceCount ( 0 ) ,
  37. m_Flags ( 0 ) ,
  38. m_Context ( NULL ) ,
  39. m_Namespace ( NULL ) ,
  40. m_NamespacePath ( NULL ) ,
  41. m_Repository ( NULL )
  42. {
  43. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_CServerObject_RawFactory_ObjectsInProgress ) ;
  44. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  45. }
  46. /******************************************************************************
  47. *
  48. * Name:
  49. *
  50. *
  51. * Description:
  52. *
  53. *
  54. *****************************************************************************/
  55. CServerObject_RawFactory::~CServerObject_RawFactory ()
  56. {
  57. if ( m_Context )
  58. {
  59. m_Context->Release () ;
  60. }
  61. if ( m_Namespace )
  62. {
  63. delete [] m_Namespace ;
  64. }
  65. if ( m_NamespacePath )
  66. {
  67. m_NamespacePath->Release () ;
  68. }
  69. if ( m_Repository )
  70. {
  71. m_Repository->Release () ;
  72. }
  73. if ( m_Service )
  74. {
  75. m_Service->Release () ;
  76. }
  77. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_CServerObject_RawFactory_ObjectsInProgress ) ;
  78. ProviderSubSystem_Globals :: Decrement_Global_Object_Count () ;
  79. }
  80. /******************************************************************************
  81. *
  82. * Name:
  83. *
  84. *
  85. * Description:
  86. *
  87. *
  88. *****************************************************************************/
  89. STDMETHODIMP CServerObject_RawFactory::QueryInterface (
  90. REFIID iid ,
  91. LPVOID FAR *iplpv
  92. )
  93. {
  94. *iplpv = NULL ;
  95. if ( iid == IID_IUnknown )
  96. {
  97. *iplpv = ( LPVOID ) this ;
  98. }
  99. else if ( iid == IID__IWmiProviderFactory )
  100. {
  101. *iplpv = ( LPVOID ) ( _IWmiProviderFactory * ) this ;
  102. }
  103. else if ( iid == IID__IWmiProviderFactoryInitialize )
  104. {
  105. *iplpv = ( LPVOID ) ( _IWmiProviderFactoryInitialize * ) this ;
  106. }
  107. else if ( iid == IID_IWbemShutdown )
  108. {
  109. *iplpv = ( LPVOID ) ( IWbemShutdown * )this ;
  110. }
  111. if ( *iplpv )
  112. {
  113. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  114. return ResultFromScode ( S_OK ) ;
  115. }
  116. else
  117. {
  118. return ResultFromScode ( E_NOINTERFACE ) ;
  119. }
  120. }
  121. /******************************************************************************
  122. *
  123. * Name:
  124. *
  125. *
  126. * Description:
  127. *
  128. *
  129. *****************************************************************************/
  130. STDMETHODIMP_( ULONG ) CServerObject_RawFactory :: AddRef ()
  131. {
  132. return InterlockedIncrement ( & m_ReferenceCount ) ;
  133. }
  134. /******************************************************************************
  135. *
  136. * Name:
  137. *
  138. *
  139. * Description:
  140. *
  141. *
  142. *****************************************************************************/
  143. STDMETHODIMP_(ULONG) CServerObject_RawFactory :: Release ()
  144. {
  145. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  146. if ( t_ReferenceCount == 0 )
  147. {
  148. delete this ;
  149. }
  150. return t_ReferenceCount ;
  151. }
  152. /******************************************************************************
  153. *
  154. * Name:
  155. *
  156. *
  157. * Description:
  158. *
  159. *
  160. *****************************************************************************/
  161. HRESULT CServerObject_RawFactory :: CheckInterfaceConformance (
  162. CServerObject_ProviderRegistrationV1 &a_Registration ,
  163. IUnknown *a_Unknown
  164. )
  165. {
  166. HRESULT t_Result = S_OK ;
  167. if ( a_Registration.GetClassProviderRegistration ().Supported () && ( a_Registration.GetClassProviderRegistration ().InteractionType () != e_InteractionType_Push ) )
  168. {
  169. IWbemServices *t_Services = NULL ;
  170. t_Result = a_Unknown->QueryInterface ( IID_IWbemServices , ( void ** ) & t_Services ) ;
  171. if ( SUCCEEDED ( t_Result ) )
  172. {
  173. t_Services->Release () ;
  174. }
  175. else
  176. {
  177. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  178. }
  179. }
  180. if ( SUCCEEDED ( t_Result ) && (a_Registration.GetInstanceProviderRegistration ().Supported () ||
  181. a_Registration.GetMethodProviderRegistration ().Supported ()) )
  182. {
  183. IWbemServices *t_Services = NULL ;
  184. t_Result = a_Unknown->QueryInterface ( IID_IWbemServices , ( void ** ) & t_Services ) ;
  185. if ( SUCCEEDED ( t_Result ) )
  186. {
  187. t_Services->Release () ;
  188. }
  189. else
  190. {
  191. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  192. }
  193. }
  194. if (SUCCEEDED ( t_Result ) && a_Registration.GetEventProviderRegistration ().Supported () )
  195. {
  196. IWbemEventProvider *t_EventProvider = NULL ;
  197. t_Result = a_Unknown->QueryInterface ( IID_IWbemEventProvider , ( void ** ) & t_EventProvider ) ;
  198. if ( SUCCEEDED ( t_Result ) )
  199. {
  200. t_EventProvider->Release () ;
  201. }
  202. else
  203. {
  204. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  205. }
  206. }
  207. if ( SUCCEEDED ( t_Result ) && a_Registration.GetPropertyProviderRegistration ().Supported () )
  208. {
  209. IWbemPropertyProvider *t_PropertyProvider = NULL ;
  210. t_Result = a_Unknown->QueryInterface ( IID_IWbemPropertyProvider , ( void ** ) & t_PropertyProvider ) ;
  211. if ( SUCCEEDED ( t_Result ) )
  212. {
  213. t_PropertyProvider->Release () ;
  214. }
  215. else
  216. {
  217. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  218. }
  219. }
  220. return t_Result ;
  221. }
  222. /******************************************************************************
  223. *
  224. * Name:
  225. *
  226. *
  227. * Description:
  228. *
  229. *
  230. *****************************************************************************/
  231. HRESULT CServerObject_RawFactory :: CreateInstance (
  232. CServerObject_ProviderRegistrationV1 &a_Registration ,
  233. const CLSID &a_ReferenceClsid ,
  234. LPUNKNOWN a_OuterUnknown ,
  235. const DWORD &a_ClassContext ,
  236. const UUID &a_ReferenceInterfaceId ,
  237. void **a_ObjectInterface
  238. )
  239. {
  240. HRESULT t_Result = S_OK ;
  241. COAUTHIDENTITY t_AuthenticationIdentity ;
  242. ZeroMemory ( & t_AuthenticationIdentity , sizeof ( t_AuthenticationIdentity ) ) ;
  243. t_AuthenticationIdentity.User = NULL ;
  244. t_AuthenticationIdentity.UserLength = 0 ;
  245. t_AuthenticationIdentity.Domain = NULL ;
  246. t_AuthenticationIdentity.DomainLength = 0 ;
  247. t_AuthenticationIdentity.Password = NULL ;
  248. t_AuthenticationIdentity.PasswordLength = 0 ;
  249. t_AuthenticationIdentity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE ;
  250. COAUTHINFO t_AuthenticationInfo ;
  251. ZeroMemory ( & t_AuthenticationInfo , sizeof ( t_AuthenticationInfo ) ) ;
  252. t_AuthenticationInfo.dwAuthnSvc = RPC_C_AUTHN_DEFAULT ;
  253. t_AuthenticationInfo.dwAuthzSvc = RPC_C_AUTHZ_DEFAULT ;
  254. t_AuthenticationInfo.pwszServerPrincName = NULL ;
  255. t_AuthenticationInfo.dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT ;
  256. t_AuthenticationInfo.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE ;
  257. t_AuthenticationInfo.dwCapabilities = EOAC_NONE ;
  258. t_AuthenticationInfo.pAuthIdentityData = NULL ;
  259. COSERVERINFO t_ServerInfo ;
  260. ZeroMemory ( & t_ServerInfo , sizeof ( t_ServerInfo ) ) ;
  261. t_ServerInfo.pwszName = NULL ;
  262. t_ServerInfo.dwReserved2 = 0 ;
  263. t_ServerInfo.pAuthInfo = & t_AuthenticationInfo ;
  264. IClassFactory *t_ClassFactory = NULL ;
  265. t_Result = CoGetClassObject (
  266. a_ReferenceClsid ,
  267. a_ClassContext ,
  268. & t_ServerInfo ,
  269. IID_IClassFactory ,
  270. ( void ** ) & t_ClassFactory
  271. ) ;
  272. if ( SUCCEEDED ( t_Result ) )
  273. {
  274. t_Result = t_ClassFactory->CreateInstance (
  275. a_OuterUnknown ,
  276. a_ReferenceInterfaceId ,
  277. a_ObjectInterface
  278. );
  279. if (FAILED(t_Result))
  280. DEBUGTRACE((LOG_PROVSS," IClassFactory::CreateInstance hr = %08x\n",t_Result ));
  281. t_ClassFactory->Release () ;
  282. }
  283. else
  284. {
  285. WCHAR String[64];
  286. StringFromGUID2(a_ReferenceClsid,String,64);
  287. DEBUGTRACE((LOG_PROVSS," CoGetClassObject(%S,%08x) hr = %08x\n",String,a_ClassContext,t_Result ));
  288. }
  289. return t_Result ;
  290. }
  291. /******************************************************************************
  292. *
  293. * Name:
  294. *
  295. *
  296. * Description:
  297. *
  298. *
  299. *****************************************************************************/
  300. HRESULT CServerObject_RawFactory :: CreateServerSide (
  301. CServerObject_ProviderRegistrationV1 &a_Registration ,
  302. GUID *a_TransactionIdentifier ,
  303. LPCWSTR a_User ,
  304. LPCWSTR a_Locale ,
  305. wchar_t *a_NamespacePath ,
  306. IUnknown **a_ProviderInterface
  307. )
  308. {
  309. HRESULT t_Result = S_OK ;
  310. wchar_t t_TransactionIdentifier [ sizeof ( L"{00000000-0000-0000-0000-000000000000}" ) ] ;
  311. if ( a_TransactionIdentifier )
  312. {
  313. StringFromGUID2 ( *a_TransactionIdentifier , t_TransactionIdentifier , sizeof ( t_TransactionIdentifier ) / sizeof ( wchar_t ) );
  314. }
  315. DEBUGTRACE((LOG_PROVSS," CreateServerSide hosting %d\n",a_Registration.GetHosting()));
  316. switch ( a_Registration.GetHosting () )
  317. {
  318. case e_Hosting_WmiCoreOrSelfHost:
  319. {
  320. if ( a_Registration.GetComRegistration ().GetClsidServer ().Loaded () == e_True )
  321. {
  322. t_Result = CreateInstance (
  323. a_Registration ,
  324. a_Registration.GetClsid () ,
  325. NULL ,
  326. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  327. IID_IUnknown ,
  328. ( void ** ) a_ProviderInterface
  329. ) ;
  330. }
  331. else
  332. {
  333. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  334. *a_ProviderInterface = NULL ;
  335. }
  336. }
  337. break ;
  338. case e_Hosting_WmiCore:
  339. case e_Hosting_SharedLocalSystemHost:
  340. case e_Hosting_SharedNetworkServiceHost:
  341. case e_Hosting_SharedLocalServiceHost:
  342. {
  343. if ( a_Registration.GetComRegistration ().GetClsidServer ().Loaded () == e_True )
  344. {
  345. t_Result = CreateInstance (
  346. a_Registration ,
  347. a_Registration.GetClsid () ,
  348. NULL ,
  349. CLSCTX_INPROC_SERVER ,
  350. IID_IUnknown ,
  351. ( void ** ) a_ProviderInterface
  352. ) ;
  353. }
  354. else
  355. {
  356. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  357. *a_ProviderInterface = NULL ;
  358. }
  359. }
  360. break ;
  361. case e_Hosting_SharedLocalSystemHostOrSelfHost:
  362. {
  363. if ( a_Registration.GetComRegistration ().GetClsidServer ().Loaded () == e_True )
  364. {
  365. t_Result = CreateInstance (
  366. a_Registration ,
  367. a_Registration.GetClsid () ,
  368. NULL ,
  369. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_ENABLE_AAA ,
  370. IID_IUnknown ,
  371. ( void ** ) a_ProviderInterface
  372. ) ;
  373. }
  374. else
  375. {
  376. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  377. *a_ProviderInterface = NULL ;
  378. }
  379. }
  380. break ;
  381. case e_Hosting_NonCom:
  382. {
  383. t_Result = CreateInstance (
  384. a_Registration ,
  385. CLSID_NCProvider ,
  386. NULL ,
  387. CLSCTX_INPROC_SERVER ,
  388. IID_IUnknown ,
  389. ( void ** ) a_ProviderInterface
  390. ) ;
  391. }
  392. break ;
  393. case e_Hosting_SelfHost:
  394. {
  395. if ( a_Registration.GetComRegistration ().GetClsidServer ().Loaded () == e_True )
  396. {
  397. t_Result = CreateInstance (
  398. a_Registration ,
  399. a_Registration.GetClsid () ,
  400. NULL ,
  401. CLSCTX_LOCAL_SERVER | CLSCTX_ENABLE_AAA ,
  402. IID_IUnknown ,
  403. ( void ** ) a_ProviderInterface
  404. ) ;
  405. }
  406. else
  407. {
  408. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  409. *a_ProviderInterface = NULL ;
  410. }
  411. }
  412. break ;
  413. default:
  414. {
  415. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  416. *a_ProviderInterface = NULL ;
  417. }
  418. break ;
  419. }
  420. if ( SUCCEEDED ( t_Result ) )
  421. {
  422. WmiSetAndCommitObject (
  423. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_ComServerLoadOperationEvent ] ,
  424. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  425. a_NamespacePath,
  426. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  427. a_User ,
  428. a_Locale ,
  429. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  430. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderClsid () ,
  431. a_Registration.GetComRegistration ().GetClsidServer ().GetServer_Name () ,
  432. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  433. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  434. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetInProcServer32_Path () : NULL ,
  435. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetLocalServer32_Path () : NULL
  436. ) ;
  437. }
  438. else
  439. {
  440. WmiSetAndCommitObject (
  441. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_ComServerOperationFailureEvent ] ,
  442. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  443. a_NamespacePath,
  444. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  445. a_User ,
  446. a_Locale ,
  447. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  448. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderClsid () ,
  449. a_Registration.GetComRegistration ().GetClsidServer ().GetServer_Name () ,
  450. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  451. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  452. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetInProcServer32_Path () : NULL ,
  453. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetLocalServer32_Path () : NULL ,
  454. t_Result
  455. );
  456. }
  457. return t_Result ;
  458. }
  459. /******************************************************************************
  460. *
  461. * Name:
  462. *
  463. *
  464. * Description:
  465. *
  466. *
  467. *****************************************************************************/
  468. HRESULT CServerObject_RawFactory :: GetApartmentInstanceProvider (
  469. LONG a_Flags ,
  470. IWbemContext *a_Context ,
  471. GUID *a_TransactionIdentifier ,
  472. LPCWSTR a_User ,
  473. LPCWSTR a_Locale ,
  474. LPCWSTR a_Scope ,
  475. REFIID a_RIID ,
  476. void **a_Interface ,
  477. CServerObject_ProviderRegistrationV1 &a_Registration
  478. )
  479. {
  480. wchar_t *t_NamespacePath = NULL ;
  481. HRESULT t_Result = ProviderSubSystem_Common_Globals :: GetNamespacePath (
  482. Direct_GetNamespacePath () ,
  483. t_NamespacePath
  484. ) ;
  485. if ( SUCCEEDED ( t_Result ) )
  486. {
  487. CServerObject_StaThread *t_StaThread = new CServerObject_StaThread ( m_Allocator, a_Registration ) ;
  488. if ( t_StaThread )
  489. {
  490. t_StaThread->AddRef () ;
  491. t_Result = t_StaThread->SetProviderName ( a_Registration.GetProviderName () ) ;
  492. if ( SUCCEEDED ( t_Result ) )
  493. {
  494. WmiStatusCode t_StatusCode = t_StaThread-> WmiThread <ULONG> :: Initialize () ;
  495. if ( t_StatusCode == e_StatusCode_Success )
  496. {
  497. IWbemProviderInit *t_ThreadInit = NULL ;
  498. t_Result = t_StaThread->QueryInterface ( IID_IWbemProviderInit , ( void ** ) & t_ThreadInit ) ;
  499. if ( SUCCEEDED ( t_Result ) )
  500. {
  501. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  502. if ( t_ProviderInitSink )
  503. {
  504. t_ProviderInitSink->AddRef () ;
  505. t_Result = t_ProviderInitSink->SinkInitialize () ;
  506. if ( SUCCEEDED ( t_Result ) )
  507. {
  508. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  509. if ( t_Sink )
  510. {
  511. t_Sink->AddRef () ;
  512. t_Result = t_ThreadInit->Initialize (
  513. NULL ,
  514. 0 ,
  515. NULL ,
  516. NULL ,
  517. NULL ,
  518. NULL ,
  519. t_Sink
  520. ) ;
  521. if ( SUCCEEDED ( t_Result ) )
  522. {
  523. t_ProviderInitSink->Wait ( a_Registration.GetInitializationTimeoutMilliSeconds () ) ;
  524. if ( SUCCEEDED ( t_Result = t_ProviderInitSink->GetResult () ) )
  525. {
  526. #ifdef INTERNAL_IDENTIFY
  527. CInterceptor_IWbemServices_Proxy *t_Proxy = new CInterceptor_IWbemServices_Proxy (
  528. NULL ,
  529. m_Allocator ,
  530. Direct_GetService () ,
  531. a_Registration
  532. ) ;
  533. #else
  534. CInterceptor_IWbemServices_Interceptor *t_Proxy = new CInterceptor_IWbemServices_Interceptor (
  535. m_Allocator ,
  536. Direct_GetService ()
  537. ) ;
  538. #endif
  539. if ( t_Proxy )
  540. {
  541. t_Proxy->AddRef () ;
  542. t_Result = t_Proxy->ServiceInitialize () ;
  543. if ( SUCCEEDED ( t_Result ) )
  544. {
  545. t_Result = t_StaThread->GetApartmentInstanceProvider (
  546. a_TransactionIdentifier ,
  547. a_Registration.GetComRegistration ().PerUserInitialization () ? a_User : NULL ,
  548. a_Registration.GetComRegistration ().PerLocaleInitialization () ? a_Locale : NULL ,
  549. Direct_GetNamespace () ,
  550. Direct_GetNamespacePath () ,
  551. t_Proxy ,
  552. a_Flags ,
  553. a_Context ,
  554. a_Scope ,
  555. a_Registration
  556. ) ;
  557. if ( SUCCEEDED ( t_Result ) )
  558. {
  559. IUnknown *t_Unknown = NULL ;
  560. t_Result = t_StaThread->QueryInterface ( IID_IUnknown , ( void ** ) & t_Unknown ) ;
  561. if ( SUCCEEDED ( t_Result ) )
  562. {
  563. GUID t_Guid ;
  564. t_Result = CoCreateGuid ( & t_Guid ) ;
  565. if ( SUCCEEDED ( t_Result ) )
  566. {
  567. CInterceptor_IWbemSyncProvider *t_Interceptor = new CInterceptor_IWbemSyncProvider (
  568. m_Allocator ,
  569. t_Unknown ,
  570. t_Proxy ,
  571. ProviderSubSystem_Globals :: GetSyncProviderController () ,
  572. a_Context ,
  573. a_Registration ,
  574. t_Guid
  575. ) ;
  576. if ( t_Interceptor )
  577. {
  578. t_Interceptor->AddRef () ;
  579. CWbemGlobal_IWbemSyncProvider_Container_Iterator t_Iterator ;
  580. ProviderSubSystem_Globals :: GetSyncProviderController ()->Lock () ;
  581. WmiStatusCode t_StatusCode = ProviderSubSystem_Globals :: GetSyncProviderController ()->Insert (
  582. *t_Interceptor ,
  583. t_Iterator
  584. ) ;
  585. if ( t_StatusCode == e_StatusCode_Success )
  586. {
  587. ProviderSubSystem_Globals :: GetSyncProviderController ()->UnLock () ;
  588. _IWmiProviderInitialize *t_InterceptorInit = NULL ;
  589. t_Result = t_Interceptor->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_InterceptorInit ) ;
  590. if ( SUCCEEDED ( t_Result ) )
  591. {
  592. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  593. if ( t_ProviderInitSink )
  594. {
  595. t_ProviderInitSink->AddRef () ;
  596. t_Result = t_ProviderInitSink->SinkInitialize () ;
  597. if ( SUCCEEDED ( t_Result ) )
  598. {
  599. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  600. if ( t_Sink )
  601. {
  602. t_Sink->AddRef () ;
  603. t_Result = t_InterceptorInit->Initialize (
  604. 0 ,
  605. a_Context ,
  606. a_TransactionIdentifier ,
  607. a_Registration.GetComRegistration ().PerUserInitialization () ? ( BSTR ) a_User : NULL ,
  608. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( BSTR ) a_Locale : NULL ,
  609. t_NamespacePath ,
  610. NULL ,
  611. NULL ,
  612. t_Sink
  613. ) ;
  614. if ( SUCCEEDED ( t_Result ) )
  615. {
  616. t_ProviderInitSink->Wait ( a_Registration.GetInitializationTimeoutMilliSeconds () ) ;
  617. if ( SUCCEEDED ( t_Result = t_ProviderInitSink->GetResult () ) )
  618. {
  619. t_Result = t_Interceptor->QueryInterface ( a_RIID , a_Interface ) ;
  620. }
  621. }
  622. t_Sink->Release () ;
  623. }
  624. else
  625. {
  626. t_Result = WBEM_E_OUT_OF_MEMORY ;
  627. }
  628. }
  629. t_ProviderInitSink->Release () ;
  630. }
  631. else
  632. {
  633. t_Result = WBEM_E_OUT_OF_MEMORY ;
  634. }
  635. t_InterceptorInit->Release () ;
  636. }
  637. }
  638. else
  639. {
  640. ProviderSubSystem_Globals :: GetSyncProviderController ()->UnLock () ;
  641. t_Result = WBEM_E_OUT_OF_MEMORY ;
  642. }
  643. t_Interceptor->SetInitialized ( t_Result ) ;
  644. t_Interceptor->Release () ;
  645. }
  646. else
  647. {
  648. t_Result = WBEM_E_OUT_OF_MEMORY ;
  649. }
  650. }
  651. t_Unknown->Release () ;
  652. }
  653. }
  654. }
  655. t_Proxy->Release () ;
  656. }
  657. else
  658. {
  659. t_Result = WBEM_E_OUT_OF_MEMORY ;
  660. }
  661. }
  662. }
  663. t_Sink->Release () ;
  664. }
  665. else
  666. {
  667. t_Result = WBEM_E_OUT_OF_MEMORY ;
  668. }
  669. }
  670. t_ProviderInitSink->Release () ;
  671. }
  672. else
  673. {
  674. t_Result = WBEM_E_OUT_OF_MEMORY ;
  675. }
  676. t_ThreadInit->Release () ;
  677. }
  678. }
  679. else
  680. {
  681. t_Result = WBEM_E_OUT_OF_MEMORY ;
  682. }
  683. }
  684. t_StaThread->Release () ;
  685. }
  686. else
  687. {
  688. t_Result = WBEM_E_OUT_OF_MEMORY ;
  689. }
  690. wchar_t t_TransactionIdentifier [ sizeof ( L"{00000000-0000-0000-0000-000000000000}" ) ] ;
  691. if ( a_TransactionIdentifier )
  692. {
  693. StringFromGUID2 ( *a_TransactionIdentifier , t_TransactionIdentifier , sizeof ( t_TransactionIdentifier ) / sizeof ( wchar_t ) );
  694. }
  695. if ( SUCCEEDED ( t_Result ) )
  696. {
  697. WmiSetAndCommitObject (
  698. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_LoadOperationEvent ] ,
  699. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  700. t_NamespacePath,
  701. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  702. a_User ,
  703. a_Locale ,
  704. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  705. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderClsid () ,
  706. a_Registration.GetComRegistration ().GetClsidServer ().GetServer_Name () ,
  707. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  708. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  709. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetInProcServer32_Path () : NULL ,
  710. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetLocalServer32_Path () : NULL ,
  711. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetThreadingModel () ,
  712. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetSynchronization ()
  713. ) ;
  714. }
  715. else
  716. {
  717. WmiSetAndCommitObject (
  718. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_LoadOperationFailureEvent ] ,
  719. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  720. t_NamespacePath,
  721. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  722. a_User ,
  723. a_Locale ,
  724. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  725. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderClsid () ,
  726. a_Registration.GetComRegistration ().GetClsidServer ().GetServer_Name () ,
  727. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  728. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  729. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetInProcServer32_Path () : NULL ,
  730. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetLocalServer32_Path () : NULL ,
  731. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetThreadingModel () ,
  732. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetSynchronization () ,
  733. t_Result
  734. );
  735. }
  736. delete [] t_NamespacePath ;
  737. }
  738. else
  739. {
  740. t_Result = WBEM_E_OUT_OF_MEMORY ;
  741. }
  742. return t_Result ;
  743. }
  744. /******************************************************************************
  745. *
  746. * Name:
  747. *
  748. *
  749. * Description:
  750. *
  751. *
  752. *****************************************************************************/
  753. HRESULT CServerObject_RawFactory :: CreateSyncProvider (
  754. IWbemServices *a_Stub ,
  755. IUnknown *a_ServerSideProvider ,
  756. wchar_t *a_NamespacePath ,
  757. LONG a_Flags ,
  758. IWbemContext *a_Context ,
  759. GUID *a_TransactionIdentifier ,
  760. LPCWSTR a_User ,
  761. LPCWSTR a_Locale ,
  762. LPCWSTR a_Scope ,
  763. REFIID a_RIID ,
  764. void **a_Interface ,
  765. CServerObject_ProviderRegistrationV1 &a_Registration
  766. )
  767. {
  768. HRESULT t_Result = S_OK ;
  769. GUID t_Guid ;
  770. t_Result = CoCreateGuid ( & t_Guid ) ;
  771. if ( SUCCEEDED ( t_Result ) )
  772. {
  773. CInterceptor_IWbemSyncProvider *t_Interceptor = new CInterceptor_IWbemSyncProvider (
  774. m_Allocator ,
  775. a_ServerSideProvider ,
  776. a_Stub ,
  777. ProviderSubSystem_Globals :: GetSyncProviderController () ,
  778. a_Context ,
  779. a_Registration ,
  780. t_Guid
  781. ) ;
  782. if ( t_Interceptor )
  783. {
  784. DEBUGTRACE((LOG_PROVSS," %p = CInterceptor_IWbemSyncProvider(%p)\n",t_Interceptor,a_ServerSideProvider));
  785. t_Interceptor->AddRef () ;
  786. CWbemGlobal_IWbemSyncProvider_Container_Iterator t_Iterator ;
  787. ProviderSubSystem_Globals :: GetSyncProviderController ()->Lock () ;
  788. WmiStatusCode t_StatusCode = ProviderSubSystem_Globals :: GetSyncProviderController ()->Insert (
  789. *t_Interceptor ,
  790. t_Iterator
  791. ) ;
  792. if ( t_StatusCode == e_StatusCode_Success )
  793. {
  794. ProviderSubSystem_Globals :: GetSyncProviderController ()->UnLock () ;
  795. _IWmiProviderInitialize *t_InterceptorInit = NULL ;
  796. t_Result = t_Interceptor->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_InterceptorInit ) ;
  797. if ( SUCCEEDED ( t_Result ) )
  798. {
  799. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  800. if ( t_ProviderInitSink )
  801. {
  802. t_ProviderInitSink->AddRef () ;
  803. t_Result = t_ProviderInitSink->SinkInitialize () ;
  804. if ( SUCCEEDED ( t_Result ) )
  805. {
  806. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  807. if ( t_Sink )
  808. {
  809. t_Sink->AddRef () ;
  810. t_Result = t_InterceptorInit->Initialize (
  811. 0 ,
  812. a_Context ,
  813. a_TransactionIdentifier ,
  814. a_Registration.GetComRegistration ().PerUserInitialization () ? ( BSTR ) a_User : NULL ,
  815. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( BSTR ) a_Locale : NULL ,
  816. a_NamespacePath ,
  817. NULL ,
  818. NULL ,
  819. t_Sink
  820. ) ;
  821. if ( SUCCEEDED ( t_Result ) )
  822. {
  823. t_ProviderInitSink->Wait ( a_Registration.GetInitializationTimeoutMilliSeconds () ) ;
  824. if ( SUCCEEDED ( t_Result = t_ProviderInitSink->GetResult () ) )
  825. {
  826. t_Result = t_Interceptor->QueryInterface ( a_RIID , a_Interface ) ;
  827. DEBUGTRACE((LOG_PROVSS," t_Interceptor->QI hr = %08x\n",t_Result));
  828. if ( SUCCEEDED ( t_Result ) )
  829. {
  830. t_Result = t_Interceptor->GetInitializeResult () ;
  831. // here is where the whole business of the
  832. // provider loading finishes
  833. }
  834. }
  835. }
  836. DEBUGTRACE((LOG_PROVSS," t_InterceptorInit->Initialize hr = %08x\n",t_Result,t_Result));
  837. t_Sink->Release () ;
  838. }
  839. else
  840. {
  841. t_Result = WBEM_E_OUT_OF_MEMORY ;
  842. }
  843. }
  844. t_ProviderInitSink->Release () ;
  845. }
  846. else
  847. {
  848. t_Result = WBEM_E_OUT_OF_MEMORY ;
  849. }
  850. t_InterceptorInit->Release () ;
  851. }
  852. }
  853. else
  854. {
  855. ProviderSubSystem_Globals :: GetSyncProviderController ()->UnLock () ;
  856. t_Result = WBEM_E_OUT_OF_MEMORY ;
  857. }
  858. t_Interceptor->SetInitialized ( t_Result ) ;
  859. t_Interceptor->Release () ;
  860. }
  861. else
  862. {
  863. t_Result = WBEM_E_OUT_OF_MEMORY ;
  864. }
  865. }
  866. else
  867. {
  868. t_Result = WBEM_E_CRITICAL_ERROR ;
  869. }
  870. return t_Result ;
  871. }
  872. /******************************************************************************
  873. *
  874. * Name:
  875. *
  876. *
  877. * Description:
  878. *
  879. *
  880. *****************************************************************************/
  881. HRESULT CServerObject_RawFactory :: InitializeServerProvider (
  882. IWbemServices *a_Stub ,
  883. IUnknown *a_ProviderInterface ,
  884. wchar_t *a_NamespacePath ,
  885. LONG a_Flags ,
  886. IWbemContext *a_Context ,
  887. GUID *a_TransactionIdentifier ,
  888. LPCWSTR a_User ,
  889. LPCWSTR a_Locale ,
  890. LPCWSTR a_Scope ,
  891. REFIID a_RIID ,
  892. void **a_Interface ,
  893. CServerObject_ProviderRegistrationV1 &a_Registration
  894. )
  895. {
  896. HRESULT t_Result = S_OK ;
  897. wchar_t t_TransactionIdentifier [ sizeof ( L"{00000000-0000-0000-0000-000000000000}" ) ] ;
  898. if ( a_TransactionIdentifier )
  899. {
  900. StringFromGUID2 ( *a_TransactionIdentifier , t_TransactionIdentifier , sizeof ( t_TransactionIdentifier ) / sizeof ( wchar_t ) );
  901. }
  902. if ( a_Registration.GetEventProviderRegistration ().Supported () )
  903. {
  904. IWbemProviderIdentity *t_ProviderIdentity = NULL ;
  905. t_Result = a_ProviderInterface->QueryInterface ( IID_IWbemProviderIdentity , ( void ** ) & t_ProviderIdentity ) ;
  906. DEBUGTRACE((LOG_PROVSS," QI(IID_IWbemProviderIdentity) hr = %08x\n",t_Result));
  907. if ( SUCCEEDED ( t_Result ) )
  908. {
  909. BOOL t_Impersonating = FALSE ;
  910. IUnknown *t_OldContext = NULL ;
  911. IServerSecurity *t_OldSecurity = NULL ;
  912. t_Result = ProviderSubSystem_Common_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  913. if ( SUCCEEDED ( t_Result ) )
  914. {
  915. BOOL t_Revert = FALSE ;
  916. IUnknown *t_Proxy = NULL ;
  917. DWORD t_ImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE ;
  918. IServerSecurity *t_ServerSecurity = NULL ;
  919. HRESULT t_TempResult = CoGetCallContext ( IID_IUnknown , ( void ** ) & t_ServerSecurity ) ;
  920. if ( SUCCEEDED ( t_TempResult ) )
  921. {
  922. t_Result = CoImpersonateClient () ;
  923. if ( SUCCEEDED ( t_Result ) )
  924. {
  925. t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  926. CoRevertToSelf () ;
  927. }
  928. t_ServerSecurity->Release () ;
  929. }
  930. if ( SUCCEEDED ( t_Result ) )
  931. {
  932. if ( t_ImpersonationLevel == RPC_C_IMP_LEVEL_IDENTIFY )
  933. {
  934. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState_NoImpersonation (
  935. IID_IWbemProviderIdentity ,
  936. t_ProviderIdentity ,
  937. t_Proxy ,
  938. t_Revert
  939. ) ;
  940. }
  941. else
  942. {
  943. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState (
  944. IID_IWbemProviderIdentity ,
  945. t_ProviderIdentity ,
  946. t_Proxy ,
  947. t_Revert
  948. ) ;
  949. }
  950. }
  951. if ( t_Result == WBEM_E_NOT_FOUND )
  952. {
  953. try
  954. {
  955. t_Result = t_ProviderIdentity->SetRegistrationObject (
  956. 0 ,
  957. a_Registration.GetIdentity ()
  958. ) ;
  959. }
  960. catch ( ... )
  961. {
  962. t_Result = WBEM_E_PROVIDER_FAILURE ;
  963. }
  964. CoRevertToSelf () ;
  965. }
  966. else
  967. {
  968. if ( SUCCEEDED ( t_Result ) )
  969. {
  970. IWbemProviderIdentity *t_ProviderIdentityProxy = ( IWbemProviderIdentity * ) t_Proxy ;
  971. // Set cloaking on the proxy
  972. // =========================
  973. DWORD t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  974. t_Result = ProviderSubSystem_Common_Globals :: SetCloaking (
  975. t_ProviderIdentityProxy ,
  976. RPC_C_AUTHN_LEVEL_DEFAULT ,
  977. t_ImpersonationLevel
  978. ) ;
  979. if ( SUCCEEDED ( t_Result ) )
  980. {
  981. try
  982. {
  983. t_Result = t_ProviderIdentityProxy->SetRegistrationObject (
  984. 0 ,
  985. a_Registration.GetIdentity ()
  986. ) ;
  987. }
  988. catch ( ... )
  989. {
  990. t_Result = WBEM_E_PROVIDER_FAILURE ;
  991. }
  992. }
  993. HRESULT t_TempResult = ProviderSubSystem_Common_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  994. }
  995. }
  996. ProviderSubSystem_Common_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  997. }
  998. t_ProviderIdentity->Release () ;
  999. }
  1000. }
  1001. IWbemProviderInit *t_ProviderInit = NULL ;
  1002. t_Result = a_ProviderInterface->QueryInterface ( IID_IWbemProviderInit , ( void ** ) & t_ProviderInit ) ;
  1003. DEBUGTRACE((LOG_PROVSS," QI(IID_IWbemProviderInit) hr = %08x\n",t_Result));
  1004. if ( SUCCEEDED ( t_Result ) )
  1005. {
  1006. if ( a_Registration.GetComRegistration ().PerUserInitialization () && a_Registration.GetComRegistration ().InitializeAsAdminFirst () )
  1007. {
  1008. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  1009. if ( t_ProviderInitSink )
  1010. {
  1011. t_ProviderInitSink->AddRef () ;
  1012. t_Result = t_ProviderInitSink->SinkInitialize ( a_Registration.GetComRegistration ().GetSecurityDescriptor () ) ;
  1013. if ( SUCCEEDED ( t_Result ) )
  1014. {
  1015. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  1016. if ( t_Sink )
  1017. {
  1018. t_Sink->AddRef () ;
  1019. BOOL t_Impersonating = FALSE ;
  1020. IUnknown *t_OldContext = NULL ;
  1021. IServerSecurity *t_OldSecurity = NULL ;
  1022. t_Result = ProviderSubSystem_Common_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1023. if ( SUCCEEDED ( t_Result ) )
  1024. {
  1025. BOOL t_Revert = FALSE ;
  1026. IUnknown *t_Proxy = NULL ;
  1027. DWORD t_ImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE ;
  1028. IServerSecurity *t_ServerSecurity = NULL ;
  1029. HRESULT t_TempResult = CoGetCallContext ( IID_IUnknown , ( void ** ) & t_ServerSecurity ) ;
  1030. if ( SUCCEEDED ( t_TempResult ) )
  1031. {
  1032. t_Result = CoImpersonateClient () ;
  1033. if ( SUCCEEDED ( t_Result ) )
  1034. {
  1035. t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  1036. CoRevertToSelf () ;
  1037. }
  1038. t_ServerSecurity->Release () ;
  1039. }
  1040. if ( SUCCEEDED ( t_Result ) )
  1041. {
  1042. if ( t_ImpersonationLevel == RPC_C_IMP_LEVEL_IDENTIFY )
  1043. {
  1044. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState_NoImpersonation (
  1045. IID_IWbemProviderInit ,
  1046. t_ProviderInit ,
  1047. t_Proxy ,
  1048. t_Revert
  1049. ) ;
  1050. }
  1051. else
  1052. {
  1053. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState (
  1054. IID_IWbemProviderInit ,
  1055. t_ProviderInit ,
  1056. t_Proxy ,
  1057. t_Revert
  1058. ) ;
  1059. }
  1060. }
  1061. if ( t_Result == WBEM_E_NOT_FOUND )
  1062. {
  1063. try
  1064. {
  1065. t_Result = t_ProviderInit->Initialize (
  1066. NULL ,
  1067. 0 ,
  1068. ( const BSTR ) a_NamespacePath ,
  1069. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1070. a_Stub ,
  1071. a_Context ,
  1072. t_Sink
  1073. ) ;
  1074. DEBUGTRACE((LOG_PROVSS," (Per User) t_ProviderInit->Initialize hr = %08x\n",t_Result));
  1075. }
  1076. catch ( ... )
  1077. {
  1078. t_Result = WBEM_E_PROVIDER_FAILURE ;
  1079. }
  1080. CoRevertToSelf () ;
  1081. }
  1082. else
  1083. {
  1084. if ( SUCCEEDED ( t_Result ) )
  1085. {
  1086. IWbemProviderInit *t_ProviderInitProxy = ( IWbemProviderInit * ) t_Proxy ;
  1087. // Set cloaking on the proxy
  1088. // =========================
  1089. DWORD t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  1090. t_Result = ProviderSubSystem_Common_Globals :: SetCloaking (
  1091. t_ProviderInitProxy ,
  1092. RPC_C_AUTHN_LEVEL_DEFAULT ,
  1093. t_ImpersonationLevel
  1094. ) ;
  1095. if ( SUCCEEDED ( t_Result ) )
  1096. {
  1097. try
  1098. {
  1099. t_Result = t_ProviderInitProxy->Initialize (
  1100. NULL ,
  1101. 0 ,
  1102. ( const BSTR ) a_NamespacePath ,
  1103. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1104. a_Stub ,
  1105. a_Context ,
  1106. t_Sink
  1107. ) ;
  1108. }
  1109. catch ( ... )
  1110. {
  1111. t_Result = WBEM_E_PROVIDER_FAILURE ;
  1112. }
  1113. DEBUGTRACE((LOG_PROVSS," (Per User) t_ProviderInitProxy->Initialize hr = %08x\n",t_Result));
  1114. }
  1115. HRESULT t_TempResult = ProviderSubSystem_Common_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  1116. }
  1117. }
  1118. if ( SUCCEEDED ( t_Result ) )
  1119. {
  1120. t_ProviderInitSink->Wait ( a_Registration.GetInitializationTimeoutMilliSeconds () ) ;
  1121. t_Result = t_ProviderInitSink->GetResult () ;
  1122. }
  1123. if ( SUCCEEDED ( t_Result ) )
  1124. {
  1125. WmiSetAndCommitObject (
  1126. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_InitializationOperationEvent ] ,
  1127. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  1128. a_NamespacePath,
  1129. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  1130. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1131. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1132. a_TransactionIdentifier ? t_TransactionIdentifier : NULL
  1133. ) ;
  1134. }
  1135. else
  1136. {
  1137. WmiSetAndCommitObject (
  1138. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_InitializationOperationFailureEvent ] ,
  1139. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  1140. a_NamespacePath,
  1141. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  1142. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1143. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1144. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  1145. t_Result
  1146. ) ;
  1147. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1148. }
  1149. ProviderSubSystem_Common_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1150. }
  1151. t_Sink->Release () ;
  1152. }
  1153. else
  1154. {
  1155. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1156. }
  1157. }
  1158. t_ProviderInitSink->Release () ;
  1159. }
  1160. else
  1161. {
  1162. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1163. }
  1164. }
  1165. if ( SUCCEEDED ( t_Result ) )
  1166. {
  1167. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  1168. if ( t_ProviderInitSink )
  1169. {
  1170. t_ProviderInitSink->AddRef () ;
  1171. t_Result = t_ProviderInitSink->SinkInitialize ( a_Registration.GetComRegistration ().GetSecurityDescriptor () ) ;
  1172. if ( SUCCEEDED ( t_Result ) )
  1173. {
  1174. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  1175. if ( t_Sink )
  1176. {
  1177. t_Sink->AddRef () ;
  1178. BOOL t_Impersonating = FALSE ;
  1179. IUnknown *t_OldContext = NULL ;
  1180. IServerSecurity *t_OldSecurity = NULL ;
  1181. t_Result = ProviderSubSystem_Common_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1182. if ( SUCCEEDED ( t_Result ) )
  1183. {
  1184. BOOL t_Revert = FALSE ;
  1185. IUnknown *t_Proxy = NULL ;
  1186. DWORD t_ImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE ;
  1187. IServerSecurity *t_ServerSecurity = NULL ;
  1188. HRESULT t_TempResult = CoGetCallContext ( IID_IUnknown , ( void ** ) & t_ServerSecurity ) ;
  1189. if ( SUCCEEDED ( t_TempResult ) )
  1190. {
  1191. t_Result = CoImpersonateClient () ;
  1192. if ( SUCCEEDED ( t_Result ) )
  1193. {
  1194. t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  1195. CoRevertToSelf () ;
  1196. }
  1197. t_ServerSecurity->Release () ;
  1198. }
  1199. if ( t_ImpersonationLevel == RPC_C_IMP_LEVEL_IDENTIFY )
  1200. {
  1201. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState_NoImpersonation (
  1202. IID_IWbemProviderInit ,
  1203. t_ProviderInit ,
  1204. t_Proxy ,
  1205. t_Revert
  1206. ) ;
  1207. }
  1208. else
  1209. {
  1210. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState (
  1211. IID_IWbemProviderInit ,
  1212. t_ProviderInit ,
  1213. t_Proxy ,
  1214. t_Revert
  1215. ) ;
  1216. }
  1217. if ( t_Result == WBEM_E_NOT_FOUND )
  1218. {
  1219. try
  1220. {
  1221. t_Result = t_ProviderInit->Initialize (
  1222. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1223. 0 ,
  1224. ( const BSTR ) a_NamespacePath ,
  1225. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1226. a_Stub ,
  1227. a_Context ,
  1228. t_Sink
  1229. ) ;
  1230. DEBUGTRACE((LOG_PROVSS," t_ProviderInit->Initialize hr = %08x\n",t_Result));
  1231. }
  1232. catch ( ... )
  1233. {
  1234. t_Result = WBEM_E_PROVIDER_FAILURE ;
  1235. }
  1236. CoRevertToSelf () ;
  1237. }
  1238. else
  1239. {
  1240. if ( SUCCEEDED ( t_Result ) )
  1241. {
  1242. IWbemProviderInit *t_ProviderInitProxy = ( IWbemProviderInit * ) t_Proxy ;
  1243. // Set cloaking on the proxy
  1244. // =========================
  1245. DWORD t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  1246. t_Result = ProviderSubSystem_Common_Globals :: SetCloaking (
  1247. t_ProviderInitProxy ,
  1248. RPC_C_AUTHN_LEVEL_DEFAULT ,
  1249. t_ImpersonationLevel
  1250. ) ;
  1251. if ( SUCCEEDED ( t_Result ) )
  1252. {
  1253. try
  1254. {
  1255. t_Result = t_ProviderInitProxy->Initialize (
  1256. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1257. 0 ,
  1258. ( const BSTR ) a_NamespacePath ,
  1259. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1260. a_Stub ,
  1261. a_Context ,
  1262. t_Sink
  1263. ) ;
  1264. }
  1265. catch ( ... )
  1266. {
  1267. t_Result = WBEM_E_PROVIDER_FAILURE ;
  1268. }
  1269. DEBUGTRACE((LOG_PROVSS," t_ProviderInitProxy->Initialize hr = %08x\n",t_Result));
  1270. }
  1271. HRESULT t_TempResult = ProviderSubSystem_Common_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  1272. }
  1273. }
  1274. if ( SUCCEEDED ( t_Result ) )
  1275. {
  1276. t_ProviderInitSink->Wait ( a_Registration.GetInitializationTimeoutMilliSeconds () ) ;
  1277. t_Result = t_ProviderInitSink->GetResult () ;
  1278. }
  1279. if ( SUCCEEDED ( t_Result ) )
  1280. {
  1281. WmiSetAndCommitObject (
  1282. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_InitializationOperationEvent ] ,
  1283. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  1284. a_NamespacePath,
  1285. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  1286. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1287. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1288. a_TransactionIdentifier ? t_TransactionIdentifier : NULL
  1289. ) ;
  1290. }
  1291. else
  1292. {
  1293. WmiSetAndCommitObject (
  1294. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_InitializationOperationFailureEvent ] ,
  1295. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  1296. a_NamespacePath,
  1297. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  1298. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1299. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1300. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  1301. t_Result
  1302. ) ;
  1303. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1304. }
  1305. ProviderSubSystem_Common_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1306. }
  1307. t_Sink->Release () ;
  1308. }
  1309. else
  1310. {
  1311. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1312. }
  1313. }
  1314. t_ProviderInitSink->Release () ;
  1315. }
  1316. else
  1317. {
  1318. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1319. }
  1320. }
  1321. t_ProviderInit->Release () ;
  1322. }
  1323. else
  1324. {
  1325. if ( a_Registration.GetPropertyProviderRegistration ().Supported () || a_Registration.GetEventConsumerProviderRegistration ().Supported () )
  1326. {
  1327. if ( a_Registration.GetClassProviderRegistration ().Supported () ||
  1328. a_Registration.GetInstanceProviderRegistration ().Supported () ||
  1329. a_Registration.GetMethodProviderRegistration ().Supported () ||
  1330. a_Registration.GetEventProviderRegistration ().Supported () )
  1331. {
  1332. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1333. }
  1334. else
  1335. {
  1336. t_Result = S_OK ;
  1337. }
  1338. }
  1339. else
  1340. {
  1341. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1342. }
  1343. }
  1344. return t_Result ;
  1345. }
  1346. /******************************************************************************
  1347. *
  1348. * Name:
  1349. *
  1350. *
  1351. * Description:
  1352. *
  1353. *
  1354. *****************************************************************************/
  1355. HRESULT CServerObject_RawFactory :: InitializeNonApartmentProvider (
  1356. IWbemServices *a_Stub ,
  1357. IUnknown *a_ServerSideProviderInterface ,
  1358. wchar_t *a_NamespacePath ,
  1359. LONG a_Flags ,
  1360. IWbemContext *a_Context ,
  1361. GUID *a_TransactionIdentifier ,
  1362. LPCWSTR a_User ,
  1363. LPCWSTR a_Locale ,
  1364. LPCWSTR a_Scope ,
  1365. REFIID a_RIID ,
  1366. void **a_Interface ,
  1367. CServerObject_ProviderRegistrationV1 &a_Registration
  1368. )
  1369. {
  1370. HRESULT t_Result = S_OK ;
  1371. if ( a_ServerSideProviderInterface )
  1372. {
  1373. t_Result = InitializeServerProvider (
  1374. a_Stub ,
  1375. a_ServerSideProviderInterface ,
  1376. a_NamespacePath ,
  1377. a_Flags ,
  1378. a_Context ,
  1379. a_TransactionIdentifier ,
  1380. a_User ,
  1381. a_Locale ,
  1382. a_Scope,
  1383. a_RIID ,
  1384. a_Interface ,
  1385. a_Registration
  1386. ) ;
  1387. DEBUGTRACE((LOG_PROVSS," InitializeServerProvider(%p) returned hr = %08x\n",a_ServerSideProviderInterface,t_Result ));
  1388. }
  1389. if ( SUCCEEDED ( t_Result ) )
  1390. {
  1391. t_Result = CreateSyncProvider (
  1392. a_Stub ,
  1393. a_ServerSideProviderInterface ,
  1394. a_NamespacePath ,
  1395. a_Flags ,
  1396. a_Context ,
  1397. a_TransactionIdentifier ,
  1398. a_User ,
  1399. a_Locale ,
  1400. a_Scope,
  1401. a_RIID ,
  1402. a_Interface ,
  1403. a_Registration
  1404. ) ;
  1405. if ( FAILED(t_Result) )
  1406. {
  1407. DEBUGTRACE((LOG_PROVSS," CreateSyncProvider hr = %08x\n",t_Result ));
  1408. }
  1409. }
  1410. return t_Result ;
  1411. }
  1412. /******************************************************************************
  1413. *
  1414. * Name:
  1415. *
  1416. *
  1417. * Description:
  1418. *
  1419. *
  1420. *****************************************************************************/
  1421. HRESULT CServerObject_RawFactory :: GetNonApartmentProvider (
  1422. LONG a_Flags ,
  1423. IWbemContext *a_Context ,
  1424. GUID *a_TransactionIdentifier ,
  1425. LPCWSTR a_User ,
  1426. LPCWSTR a_Locale ,
  1427. LPCWSTR a_Scope ,
  1428. REFIID a_RIID ,
  1429. void **a_Interface ,
  1430. CServerObject_ProviderRegistrationV1 &a_Registration
  1431. )
  1432. {
  1433. wchar_t *t_NamespacePath = NULL ;
  1434. HRESULT t_Result = ProviderSubSystem_Common_Globals :: GetNamespacePath (
  1435. Direct_GetNamespacePath () ,
  1436. t_NamespacePath
  1437. ) ;
  1438. if ( SUCCEEDED ( t_Result ) )
  1439. {
  1440. IUnknown *t_ServerSideProviderInterface = NULL ;
  1441. t_Result = CreateServerSide (
  1442. a_Registration ,
  1443. a_TransactionIdentifier ,
  1444. a_User ,
  1445. a_Locale ,
  1446. t_NamespacePath ,
  1447. & t_ServerSideProviderInterface
  1448. ) ;
  1449. if ( SUCCEEDED ( t_Result ) )
  1450. {
  1451. IWbemServices * t_Proxy = NULL;
  1452. if (e_Hosting_WmiCore == a_Registration.GetHosting())
  1453. {
  1454. t_Proxy = new CInterceptor_IWbemServices_RestrictingInterceptor (
  1455. m_Allocator ,
  1456. Direct_GetService () ,
  1457. a_Registration
  1458. ) ;
  1459. if (t_Proxy)
  1460. {
  1461. t_Proxy->AddRef () ;
  1462. t_Result = ((CInterceptor_IWbemServices_RestrictingInterceptor *)t_Proxy)->ServiceInitialize () ;
  1463. }
  1464. }
  1465. else
  1466. {
  1467. t_Proxy = Direct_GetService();
  1468. t_Proxy->AddRef () ;
  1469. }
  1470. if ( t_Proxy )
  1471. {
  1472. if ( SUCCEEDED ( t_Result ) )
  1473. {
  1474. t_Result = InitializeNonApartmentProvider (
  1475. t_Proxy ,
  1476. t_ServerSideProviderInterface ,
  1477. t_NamespacePath ,
  1478. a_Flags ,
  1479. a_Context ,
  1480. a_TransactionIdentifier ,
  1481. a_User ,
  1482. a_Locale ,
  1483. a_Scope,
  1484. a_RIID ,
  1485. a_Interface ,
  1486. a_Registration
  1487. ) ;
  1488. DEBUGTRACE((LOG_PROVSS," CServerObject_RawFactory::GetNonApartmentProvider pNS %S hr = %08x\n",t_NamespacePath,t_Result ));
  1489. }
  1490. t_Proxy->Release () ;
  1491. }
  1492. else
  1493. {
  1494. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1495. }
  1496. if ( t_ServerSideProviderInterface )
  1497. {
  1498. t_ServerSideProviderInterface->Release () ;
  1499. }
  1500. }
  1501. wchar_t t_TransactionIdentifier [ sizeof ( L"{00000000-0000-0000-0000-000000000000}" ) ] ;
  1502. if ( a_TransactionIdentifier )
  1503. {
  1504. StringFromGUID2 ( *a_TransactionIdentifier , t_TransactionIdentifier , sizeof ( t_TransactionIdentifier ) / sizeof ( wchar_t ) );
  1505. }
  1506. if ( SUCCEEDED ( t_Result ) )
  1507. {
  1508. WmiSetAndCommitObject (
  1509. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_LoadOperationEvent ] ,
  1510. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  1511. t_NamespacePath,
  1512. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  1513. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1514. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1515. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  1516. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderClsid () ,
  1517. a_Registration.GetComRegistration ().GetClsidServer ().GetServer_Name () ,
  1518. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  1519. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  1520. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetInProcServer32_Path () : NULL ,
  1521. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetLocalServer32_Path () : NULL ,
  1522. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetThreadingModel () ,
  1523. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetSynchronization ()
  1524. ) ;
  1525. }
  1526. else
  1527. {
  1528. WmiSetAndCommitObject (
  1529. ProviderSubSystem_Globals :: s_EventClassHandles [ Msft_WmiProvider_LoadOperationFailureEvent ] ,
  1530. WMI_SENDCOMMIT_SET_NOT_REQUIRED,
  1531. t_NamespacePath,
  1532. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderName () ,
  1533. a_Registration.GetComRegistration ().PerUserInitialization () ? ( const BSTR ) a_User : NULL ,
  1534. a_Registration.GetComRegistration ().PerLocaleInitialization () ? ( const BSTR ) a_Locale : NULL ,
  1535. a_TransactionIdentifier ? t_TransactionIdentifier : NULL ,
  1536. a_Registration.GetComRegistration ().GetClsidServer ().GetProviderClsid () ,
  1537. a_Registration.GetComRegistration ().GetClsidServer ().GetServer_Name () ,
  1538. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  1539. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? VARIANT_TRUE : VARIANT_FALSE ,
  1540. a_Registration.GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetInProcServer32_Path () : NULL ,
  1541. a_Registration.GetComRegistration ().GetClsidServer ().LocalServer32 () == e_True ? a_Registration.GetComRegistration ().GetClsidServer ().GetLocalServer32_Path () : NULL ,
  1542. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetThreadingModel () ,
  1543. ( ULONG ) a_Registration.GetComRegistration ().GetClsidServer ().GetSynchronization () ,
  1544. t_Result
  1545. );
  1546. }
  1547. if ( FAILED ( t_Result ) )
  1548. {
  1549. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1550. }
  1551. delete [] t_NamespacePath ;
  1552. }
  1553. else
  1554. {
  1555. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1556. }
  1557. return t_Result ;
  1558. }
  1559. /******************************************************************************
  1560. *
  1561. * Name:
  1562. *
  1563. *
  1564. * Description:
  1565. *
  1566. *
  1567. *****************************************************************************/
  1568. HRESULT CServerObject_RawFactory :: GetHostedProvider (
  1569. LONG a_Flags ,
  1570. IWbemContext *a_Context ,
  1571. GUID *a_TransactionIdentifier,
  1572. LPCWSTR a_User ,
  1573. LPCWSTR a_Locale ,
  1574. LPCWSTR a_Scope ,
  1575. LPCWSTR a_Name ,
  1576. ULONG a_Host ,
  1577. LPCWSTR a_HostingGroup ,
  1578. REFIID a_RIID ,
  1579. void **a_Interface
  1580. )
  1581. {
  1582. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1583. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1584. #endif
  1585. HRESULT t_Result = WBEM_E_NOT_SUPPORTED ;
  1586. return t_Result ;
  1587. }
  1588. /******************************************************************************
  1589. *
  1590. * Name:
  1591. *
  1592. *
  1593. * Description:
  1594. *
  1595. *
  1596. *****************************************************************************/
  1597. HRESULT CServerObject_RawFactory :: GetClassProvider (
  1598. LONG a_Flags ,
  1599. IWbemContext *a_Context ,
  1600. LPCWSTR a_User ,
  1601. LPCWSTR a_Locale ,
  1602. LPCWSTR a_Scope ,
  1603. IWbemClassObject *a_Class ,
  1604. REFIID a_RIID ,
  1605. void **a_Interface
  1606. )
  1607. {
  1608. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1609. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1610. #endif
  1611. try
  1612. {
  1613. }
  1614. catch ( Wmi_Structured_Exception t_StructuredException )
  1615. {
  1616. }
  1617. return S_OK ;
  1618. }
  1619. /******************************************************************************
  1620. *
  1621. * Name:
  1622. *
  1623. *
  1624. * Description:
  1625. *
  1626. *
  1627. *****************************************************************************/
  1628. HRESULT CServerObject_RawFactory :: GetDynamicPropertyResolver (
  1629. LONG a_Flags ,
  1630. IWbemContext *a_Context ,
  1631. LPCWSTR a_User ,
  1632. LPCWSTR a_Locale ,
  1633. REFIID a_RIID ,
  1634. void **a_Interface
  1635. )
  1636. {
  1637. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1638. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1639. #endif
  1640. try
  1641. {
  1642. }
  1643. catch ( Wmi_Structured_Exception t_StructuredException )
  1644. {
  1645. }
  1646. return S_OK ;
  1647. }
  1648. /******************************************************************************
  1649. *
  1650. * Name:
  1651. *
  1652. *
  1653. * Description:
  1654. *
  1655. *
  1656. *****************************************************************************/
  1657. HRESULT CServerObject_RawFactory :: GetProvider (
  1658. WmiInternalContext a_InternalContext ,
  1659. LONG a_Flags ,
  1660. IWbemContext *a_Context ,
  1661. GUID *a_TransactionIdentifier ,
  1662. LPCWSTR a_User ,
  1663. LPCWSTR a_Locale ,
  1664. LPCWSTR a_Scope,
  1665. LPCWSTR a_Name ,
  1666. REFIID a_RIID ,
  1667. void **a_Interface
  1668. )
  1669. {
  1670. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1671. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1672. #endif
  1673. DEBUGTRACE((LOG_PROVSS,"+ CServerObject_RawFactory::GetProvider %S\n",a_Name));
  1674. HRESULT t_Result = S_OK ;
  1675. try
  1676. {
  1677. BOOL t_Impersonating = FALSE ;
  1678. IUnknown *t_OldContext = NULL ;
  1679. IServerSecurity *t_OldSecurity = NULL ;
  1680. if ( a_InternalContext.m_IdentifyHandle )
  1681. {
  1682. HANDLE t_IdentifyToken = ( HANDLE ) a_InternalContext.m_IdentifyHandle ;
  1683. BOOL t_Status = SetThreadToken ( NULL , t_IdentifyToken ) ;
  1684. if ( t_Status )
  1685. {
  1686. t_Result = ProviderSubSystem_Globals :: BeginThreadImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1687. RevertToSelf () ;
  1688. }
  1689. else
  1690. {
  1691. t_Result = WBEM_E_ACCESS_DENIED ;
  1692. }
  1693. CloseHandle ( t_IdentifyToken ) ;
  1694. }
  1695. if ( SUCCEEDED ( t_Result ) )
  1696. {
  1697. IWbemPath *t_Scope = NULL ;
  1698. if ( a_Scope )
  1699. {
  1700. t_Result = CoCreateInstance (
  1701. CLSID_WbemDefPath ,
  1702. NULL ,
  1703. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER ,
  1704. IID_IWbemPath ,
  1705. ( void ** ) & t_Scope
  1706. ) ;
  1707. if ( SUCCEEDED ( t_Result ) )
  1708. {
  1709. t_Result = t_Scope->SetText ( WBEMPATH_TREAT_SINGLE_IDENT_AS_NS | WBEMPATH_CREATE_ACCEPT_ALL , a_Scope ) ;
  1710. }
  1711. }
  1712. if ( SUCCEEDED ( t_Result ) )
  1713. {
  1714. CServerObject_ProviderRegistrationV1 *t_Registration = new CServerObject_ProviderRegistrationV1 ;
  1715. if ( t_Registration )
  1716. {
  1717. t_Registration->AddRef () ;
  1718. t_Result = t_Registration->SetContext (
  1719. a_Context ,
  1720. Direct_GetNamespacePath () ,
  1721. Direct_GetRepository ()
  1722. ) ;
  1723. if ( SUCCEEDED ( t_Result ) )
  1724. {
  1725. if ( t_Registration->ObjectProvider () )
  1726. {
  1727. if ( t_Registration->EventProvider () )
  1728. {
  1729. t_Registration->SetUnloadTimeoutMilliSeconds (
  1730. ProviderSubSystem_Globals :: s_ObjectCacheTimeout < ProviderSubSystem_Globals :: s_EventCacheTimeout ?
  1731. ProviderSubSystem_Globals :: s_EventCacheTimeout : ProviderSubSystem_Globals :: s_ObjectCacheTimeout
  1732. ) ;
  1733. }
  1734. else
  1735. {
  1736. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_ObjectCacheTimeout ) ;
  1737. }
  1738. }
  1739. else
  1740. {
  1741. if ( t_Registration->EventProvider () )
  1742. {
  1743. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_EventCacheTimeout ) ;
  1744. }
  1745. }
  1746. t_Result = t_Registration->Load (
  1747. e_All ,
  1748. t_Scope ,
  1749. a_Name
  1750. ) ;
  1751. if ( SUCCEEDED ( t_Result ) )
  1752. {
  1753. DEBUGTRACE((LOG_PROVSS," Hosting %d InProcServer %d\n",
  1754. t_Registration->GetComRegistration ().GetHosting(),
  1755. t_Registration->GetComRegistration ().GetClsidServer ().InProcServer32 ()));
  1756. IUnknown *t_Unknown = NULL ;
  1757. if ( t_Registration->GetComRegistration ().GetHosting () == e_Hosting_SelfHost )
  1758. {
  1759. t_Result = GetNonApartmentProvider (
  1760. a_Flags ,
  1761. a_Context ,
  1762. a_TransactionIdentifier ,
  1763. a_User ,
  1764. a_Locale ,
  1765. a_Scope,
  1766. IID_IUnknown ,
  1767. ( void ** ) & t_Unknown ,
  1768. *t_Registration
  1769. ) ;
  1770. }
  1771. else
  1772. {
  1773. if ( t_Registration->GetComRegistration ().GetClsidServer ().InProcServer32 () == e_True )
  1774. {
  1775. switch ( t_Registration->GetThreadingModel () )
  1776. {
  1777. case e_Apartment:
  1778. {
  1779. t_Result = GetApartmentInstanceProvider (
  1780. a_Flags ,
  1781. a_Context ,
  1782. a_TransactionIdentifier ,
  1783. a_User ,
  1784. a_Locale ,
  1785. a_Scope,
  1786. IID_IUnknown ,
  1787. ( void ** ) & t_Unknown ,
  1788. *t_Registration
  1789. ) ;
  1790. }
  1791. break ;
  1792. case e_Both:
  1793. case e_Free:
  1794. case e_Neutral:
  1795. {
  1796. t_Result = GetNonApartmentProvider (
  1797. a_Flags ,
  1798. a_Context ,
  1799. a_TransactionIdentifier ,
  1800. a_User ,
  1801. a_Locale ,
  1802. a_Scope,
  1803. IID_IUnknown ,
  1804. ( void ** ) & t_Unknown ,
  1805. *t_Registration
  1806. ) ;
  1807. }
  1808. break ;
  1809. case e_ThreadingModel_Unknown:
  1810. default:
  1811. {
  1812. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  1813. }
  1814. break ;
  1815. }
  1816. }
  1817. else
  1818. {
  1819. t_Result = GetNonApartmentProvider (
  1820. a_Flags ,
  1821. a_Context ,
  1822. a_TransactionIdentifier ,
  1823. a_User ,
  1824. a_Locale ,
  1825. a_Scope,
  1826. IID_IUnknown ,
  1827. ( void ** ) & t_Unknown ,
  1828. *t_Registration
  1829. ) ;
  1830. }
  1831. }
  1832. if ( SUCCEEDED ( t_Result ) )
  1833. {
  1834. t_Result = CheckInterfaceConformance (
  1835. *t_Registration ,
  1836. t_Unknown
  1837. ) ;
  1838. if ( SUCCEEDED ( t_Result ) )
  1839. {
  1840. t_Result = t_Unknown->QueryInterface ( a_RIID , a_Interface ) ;
  1841. }
  1842. else
  1843. {
  1844. ERRORTRACE((LOG_PROVSS," CheckInterfaceConformance for %S hr = %08x\n",a_Name,t_Result));
  1845. }
  1846. t_Unknown->Release () ;
  1847. }
  1848. }
  1849. else
  1850. {
  1851. if ( t_Result == WBEM_E_NOT_FOUND )
  1852. {
  1853. t_Result = WBEM_E_PROVIDER_NOT_FOUND ;
  1854. }
  1855. else
  1856. {
  1857. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1858. }
  1859. }
  1860. }
  1861. t_Registration->Release () ;
  1862. }
  1863. else
  1864. {
  1865. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1866. }
  1867. }
  1868. if ( t_Scope )
  1869. {
  1870. t_Scope->Release () ;
  1871. }
  1872. if ( a_InternalContext.m_IdentifyHandle )
  1873. {
  1874. ProviderSubSystem_Common_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1875. RevertToSelf () ;
  1876. }
  1877. }
  1878. }
  1879. catch ( Wmi_Structured_Exception t_StructuredException )
  1880. {
  1881. t_Result = WBEM_E_CRITICAL_ERROR ;
  1882. }
  1883. DEBUGTRACE((LOG_PROVSS,"- CServerObject_RawFactory::GetProvider hr = %08x\n",t_Result ));
  1884. return t_Result ;
  1885. }
  1886. /******************************************************************************
  1887. *
  1888. * Name:
  1889. *
  1890. *
  1891. * Description:
  1892. *
  1893. *
  1894. *****************************************************************************/
  1895. HRESULT CServerObject_RawFactory :: GetDecoupledProvider (
  1896. LONG a_Flags ,
  1897. IWbemContext *a_Context ,
  1898. LPCWSTR a_User ,
  1899. LPCWSTR a_Locale ,
  1900. LPCWSTR a_Scope,
  1901. LPCWSTR a_Name ,
  1902. REFIID a_RIID ,
  1903. void **a_Interface
  1904. )
  1905. {
  1906. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1907. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1908. #endif
  1909. try
  1910. {
  1911. }
  1912. catch ( Wmi_Structured_Exception t_StructuredException )
  1913. {
  1914. }
  1915. return S_OK ;
  1916. }
  1917. /******************************************************************************
  1918. *
  1919. * Name:
  1920. *
  1921. *
  1922. * Description:
  1923. *
  1924. *
  1925. *****************************************************************************/
  1926. HRESULT CServerObject_RawFactory :: Initialize (
  1927. _IWmiProvSS *a_SubSys ,
  1928. _IWmiProviderFactory *a_Factory ,
  1929. LONG a_Flags ,
  1930. IWbemContext *a_Context ,
  1931. LPCWSTR a_Namespace ,
  1932. IWbemServices *a_Repository ,
  1933. IWbemServices *a_Service
  1934. )
  1935. {
  1936. HRESULT t_Result = S_OK ;
  1937. if ( a_Namespace )
  1938. {
  1939. m_Namespace = DupString( a_Namespace );
  1940. if ( m_Namespace == 0)
  1941. {
  1942. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1943. }
  1944. if ( SUCCEEDED ( t_Result ) )
  1945. {
  1946. t_Result = CoCreateInstance (
  1947. CLSID_WbemDefPath ,
  1948. NULL ,
  1949. CLSCTX_INPROC_SERVER ,
  1950. IID_IWbemPath ,
  1951. ( void ** ) & m_NamespacePath
  1952. ) ;
  1953. if ( SUCCEEDED ( t_Result ) )
  1954. {
  1955. t_Result = m_NamespacePath->SetText ( WBEMPATH_TREAT_SINGLE_IDENT_AS_NS | WBEMPATH_CREATE_ACCEPT_ALL , a_Namespace ) ;
  1956. }
  1957. }
  1958. }
  1959. if ( SUCCEEDED ( t_Result ) )
  1960. {
  1961. m_Flags = a_Flags ;
  1962. m_Context = a_Context ;
  1963. m_Repository = a_Repository ;
  1964. m_Service = a_Service ;
  1965. if ( m_Context )
  1966. {
  1967. m_Context->AddRef () ;
  1968. }
  1969. if ( m_Repository )
  1970. {
  1971. m_Repository->AddRef () ;
  1972. }
  1973. if ( m_Service )
  1974. {
  1975. m_Service->AddRef () ;
  1976. }
  1977. }
  1978. return t_Result ;
  1979. }
  1980. /******************************************************************************
  1981. *
  1982. * Name:
  1983. *
  1984. *
  1985. * Description:
  1986. *
  1987. *
  1988. *****************************************************************************/
  1989. HRESULT CServerObject_RawFactory :: Shutdown (
  1990. LONG a_Flags ,
  1991. ULONG a_MaxMilliSeconds ,
  1992. IWbemContext *a_Context
  1993. )
  1994. {
  1995. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1996. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1997. #endif
  1998. try
  1999. {
  2000. }
  2001. catch ( Wmi_Structured_Exception t_StructuredException )
  2002. {
  2003. }
  2004. return S_OK ;
  2005. }