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.

5209 lines
116 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 <stdio.h>
  11. #define SECURITY_WIN32
  12. #include <Security.h>
  13. #include <lmcons.h>
  14. #include <HelperFuncs.h>
  15. #include <Logging.h>
  16. #include "Globals.h"
  17. #include "CGlobals.h"
  18. #include "ProvSubS.h"
  19. #include "ProvAggr.h"
  20. #include "ProvFact.h"
  21. #include "ProvLoad.h"
  22. #include "ProvWsv.h"
  23. #include "ProvWsvS.h"
  24. #include "ProvResv.h"
  25. #include "ProvInSk.h"
  26. #include "ProvRegDeCoupled.h"
  27. #include "ProvRegInfo.h"
  28. #include "ProvCache.h"
  29. #include "ProvHost.h"
  30. #include "ProvObSk.h"
  31. #include "Guids.h"
  32. #include <scopecheck.h>
  33. /******************************************************************************
  34. *
  35. * Name:
  36. *
  37. *
  38. * Description:
  39. *
  40. *
  41. *****************************************************************************/
  42. #pragma warning( disable : 4355 )
  43. CServerObject_BindingFactory :: CServerObject_BindingFactory (
  44. WmiAllocator &a_Allocator
  45. ) : CWbemGlobal_IWmiProviderController ( a_Allocator ) ,
  46. m_Internal ( this ) ,
  47. m_Allocator ( a_Allocator ) ,
  48. m_Context ( NULL ) ,
  49. m_Namespace ( NULL ) ,
  50. m_NamespacePath ( NULL ) ,
  51. m_Repository ( NULL ) ,
  52. m_SubSystem ( NULL ) ,
  53. m_SvcWrappersContainer( a_Allocator )
  54. {
  55. CWbemGlobal_IWmiProviderController :: AddRef () ;
  56. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_CServerObject_BindingFactory_ObjectsInProgress ) ;
  57. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  58. }
  59. /******************************************************************************
  60. *
  61. * Name:
  62. *
  63. *
  64. * Description:
  65. *
  66. *
  67. *****************************************************************************/
  68. CServerObject_BindingFactory :: CServerObject_BindingFactory (
  69. WmiAllocator &a_Allocator ,
  70. CWbemGlobal_IWmiFactoryController *a_Controller ,
  71. const BindingFactoryCacheKey &a_Key ,
  72. const ULONG &a_Period
  73. ) : BindingFactoryCacheElement (
  74. a_Controller ,
  75. a_Key ,
  76. a_Period
  77. ) ,
  78. CWbemGlobal_IWmiProviderController ( a_Allocator ) ,
  79. m_Internal ( this ) ,
  80. m_Allocator ( a_Allocator ) ,
  81. m_Context ( NULL ) ,
  82. m_Namespace ( NULL ) ,
  83. m_NamespacePath ( NULL ) ,
  84. m_Repository ( NULL ) ,
  85. m_SubSystem ( NULL ) ,
  86. m_SvcWrappersContainer( a_Allocator )
  87. {
  88. InterlockedIncrement ( & ProviderSubSystem_Globals :: s_CServerObject_BindingFactory_ObjectsInProgress ) ;
  89. ProviderSubSystem_Globals :: Increment_Global_Object_Count () ;
  90. }
  91. #pragma warning( default : 4355 )
  92. /******************************************************************************
  93. *
  94. * Name:
  95. *
  96. *
  97. * Description:
  98. *
  99. *
  100. *****************************************************************************/
  101. CServerObject_BindingFactory::~CServerObject_BindingFactory ()
  102. {
  103. if ( m_Context )
  104. {
  105. m_Context->Release () ;
  106. }
  107. if ( m_Namespace )
  108. {
  109. delete [] m_Namespace ;
  110. }
  111. if ( m_NamespacePath )
  112. {
  113. m_NamespacePath->Release () ;
  114. }
  115. if ( m_Repository )
  116. {
  117. m_Repository->Release () ;
  118. }
  119. if ( m_SubSystem )
  120. {
  121. m_SubSystem->Release () ;
  122. }
  123. CWbemGlobal_IWmiProviderController :: UnInitialize () ;
  124. ULONG t_Count = m_SvcWrappersContainer.Size();
  125. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  126. {
  127. IUnknown * t_SvcWrap ;
  128. WmiStatusCode t_StatusCode = m_SvcWrappersContainer.Top ( t_SvcWrap) ;
  129. if ( t_StatusCode == e_StatusCode_Success )
  130. {
  131. t_SvcWrap->Release () ;
  132. t_StatusCode = m_SvcWrappersContainer.DeQueue () ;
  133. }
  134. }
  135. m_SvcWrappersContainer.UnInitialize() ;
  136. InterlockedDecrement ( & ProviderSubSystem_Globals :: s_CServerObject_BindingFactory_ObjectsInProgress ) ;
  137. ProviderSubSystem_Globals :: Decrement_Global_Object_Count () ;
  138. }
  139. /******************************************************************************
  140. *
  141. * Name:
  142. *
  143. *
  144. * Description:
  145. *
  146. *
  147. *****************************************************************************/
  148. HRESULT CServerObject_BindingFactory :: Initialize (
  149. _IWmiProvSS *a_SubSys ,
  150. _IWmiProviderFactory *a_Factory ,
  151. LONG a_Flags ,
  152. IWbemContext *a_Context ,
  153. LPCWSTR a_Namespace ,
  154. IWbemServices *a_Repository ,
  155. IWbemServices *a_Service
  156. )
  157. {
  158. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  159. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  160. #endif
  161. HRESULT t_Result = S_OK ;
  162. try
  163. {
  164. if ( a_Namespace )
  165. {
  166. m_Namespace = DupString(a_Namespace );
  167. if ( m_Namespace == 0)
  168. {
  169. t_Result = WBEM_E_OUT_OF_MEMORY ;
  170. }
  171. if ( SUCCEEDED ( t_Result ) )
  172. {
  173. t_Result = CoCreateInstance (
  174. CLSID_WbemDefPath ,
  175. NULL ,
  176. CLSCTX_INPROC_SERVER ,
  177. IID_IWbemPath ,
  178. ( void ** ) & m_NamespacePath
  179. ) ;
  180. if ( SUCCEEDED ( t_Result ) )
  181. {
  182. t_Result = m_NamespacePath->SetText ( WBEMPATH_TREAT_SINGLE_IDENT_AS_NS | WBEMPATH_CREATE_ACCEPT_ALL , a_Namespace ) ;
  183. }
  184. }
  185. }
  186. if ( SUCCEEDED ( t_Result ) )
  187. {
  188. m_SubSystem = a_SubSys ;
  189. m_Flags = a_Flags ;
  190. m_Context = a_Context ;
  191. if ( m_Context )
  192. {
  193. m_Context->AddRef () ;
  194. }
  195. if ( m_SubSystem )
  196. {
  197. m_SubSystem->AddRef () ;
  198. }
  199. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Initialize () ;
  200. if ( t_StatusCode != e_StatusCode_Success )
  201. {
  202. t_Result = WBEM_E_OUT_OF_MEMORY ;
  203. }
  204. }
  205. if (e_StatusCode_Success != m_SvcWrappersContainer.Initialize() )
  206. {
  207. t_Result = WBEM_E_OUT_OF_MEMORY ;
  208. }
  209. }
  210. catch ( Wmi_Structured_Exception t_StructuredException )
  211. {
  212. t_Result = WBEM_E_CRITICAL_ERROR ;
  213. }
  214. return t_Result ;
  215. }
  216. /******************************************************************************
  217. *
  218. * Name:
  219. *
  220. *
  221. * Description:
  222. *
  223. *
  224. *****************************************************************************/
  225. STDMETHODIMP CServerObject_BindingFactory::QueryInterface (
  226. REFIID iid ,
  227. LPVOID FAR *iplpv
  228. )
  229. {
  230. *iplpv = NULL ;
  231. if ( iid == IID_IUnknown )
  232. {
  233. *iplpv = ( LPVOID ) this ;
  234. }
  235. else if ( iid == IID__IWmiProviderFactory )
  236. {
  237. *iplpv = ( LPVOID ) ( _IWmiProviderFactory * ) this ;
  238. }
  239. else if ( iid == IID__IWmiProviderFactoryInitialize )
  240. {
  241. *iplpv = ( LPVOID ) ( _IWmiProviderFactoryInitialize * ) this ;
  242. }
  243. else if ( iid == IID_IWbemShutdown )
  244. {
  245. *iplpv = ( LPVOID ) ( IWbemShutdown * ) this ;
  246. }
  247. else if ( iid == IID__IWmiProviderConfiguration )
  248. {
  249. *iplpv = ( LPVOID ) ( _IWmiProviderConfiguration * ) this ;
  250. }
  251. else if ( iid == IID_CWbemGlobal_IWmiProviderController )
  252. {
  253. *iplpv = ( LPVOID ) & ( this->m_Internal ) ;
  254. }
  255. if ( *iplpv )
  256. {
  257. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  258. return ResultFromScode ( S_OK ) ;
  259. }
  260. else
  261. {
  262. return ResultFromScode ( E_NOINTERFACE ) ;
  263. }
  264. }
  265. /******************************************************************************
  266. *
  267. * Name:
  268. *
  269. *
  270. * Description:
  271. *
  272. *
  273. *****************************************************************************/
  274. STDMETHODIMP_( ULONG ) CServerObject_BindingFactory :: AddRef ()
  275. {
  276. return BindingFactoryCacheElement :: AddRef () ;
  277. }
  278. /******************************************************************************
  279. *
  280. * Name:
  281. *
  282. *
  283. * Description:
  284. *
  285. *
  286. *****************************************************************************/
  287. STDMETHODIMP_(ULONG) CServerObject_BindingFactory :: Release ()
  288. {
  289. return BindingFactoryCacheElement :: Release () ;
  290. }
  291. /******************************************************************************
  292. *
  293. * Name:
  294. *
  295. *
  296. * Description:
  297. *
  298. *
  299. *****************************************************************************/
  300. HRESULT CServerObject_BindingFactory :: CacheProvider (
  301. _IWmiProviderSubsystemRegistrar *a_Registrar ,
  302. IWbemContext *a_Context ,
  303. CServerObject_DecoupledClientRegistration_Element &a_Element ,
  304. IUnknown *a_Unknown
  305. )
  306. {
  307. HRESULT t_Result = S_OK ;
  308. GUID t_Identity ;
  309. t_Result = CLSIDFromString ( a_Element.GetClsid () , & t_Identity ) ;
  310. if ( SUCCEEDED ( t_Result ) )
  311. {
  312. t_Result = a_Registrar->Register (
  313. 0 ,
  314. a_Context ,
  315. a_Element.GetUser () ,
  316. a_Element.GetLocale () ,
  317. a_Element.GetScope () ,
  318. a_Element.GetProvider () ,
  319. a_Element.GetProcessIdentifier () ,
  320. a_Unknown ,
  321. t_Identity
  322. ) ;
  323. }
  324. return t_Result ;
  325. }
  326. /******************************************************************************
  327. *
  328. * Name:
  329. *
  330. *
  331. * Description:
  332. *
  333. *
  334. *****************************************************************************/
  335. HRESULT CServerObject_BindingFactory :: Load (
  336. _IWmiProviderSubsystemRegistrar *a_Registrar ,
  337. IWbemContext *a_Context ,
  338. CServerObject_DecoupledClientRegistration_Element &a_Element
  339. )
  340. {
  341. HRESULT t_Result = S_OK ;
  342. BYTE *t_MarshaledProxy = a_Element.GetMarshaledProxy () ;
  343. DWORD t_MarshaledProxyLength = a_Element.GetMarshaledProxyLength () ;
  344. if ( t_MarshaledProxy )
  345. {
  346. IUnknown *t_Unknown = NULL ;
  347. t_Result = ProviderSubSystem_Common_Globals :: UnMarshalRegistration ( & t_Unknown , t_MarshaledProxy , t_MarshaledProxyLength ) ;
  348. if ( SUCCEEDED ( t_Result ) )
  349. {
  350. t_Result = CacheProvider (
  351. a_Registrar ,
  352. a_Context ,
  353. a_Element ,
  354. t_Unknown
  355. ) ;
  356. t_Unknown->Release () ;
  357. }
  358. }
  359. return t_Result ;
  360. }
  361. /******************************************************************************
  362. *
  363. * Name:
  364. *
  365. *
  366. * Description:
  367. *
  368. *
  369. *****************************************************************************/
  370. HRESULT CServerObject_BindingFactory :: Load (
  371. CDecoupledAggregator_IWbemProvider *a_Aggregator ,
  372. IWbemContext *a_Context ,
  373. BSTR a_Provider ,
  374. BSTR a_User ,
  375. BSTR a_Locale ,
  376. BSTR a_Scope
  377. )
  378. {
  379. HRESULT t_Result = S_OK ;
  380. try
  381. {
  382. _IWmiProviderSubsystemRegistrar *t_Registrar = NULL ;
  383. t_Result = a_Aggregator->QueryInterface ( IID__IWmiProviderSubsystemRegistrar , ( void ** ) & t_Registrar ) ;
  384. if ( SUCCEEDED ( t_Result ) )
  385. {
  386. WmiStatusCode t_StatusCode = WmiHelper :: EnterCriticalSection ( ProviderSubSystem_Globals :: GetDecoupledRegistrySection () ) ;
  387. CServerObject_DecoupledClientRegistration t_Elements ( m_Allocator ) ;
  388. HRESULT t_TempResult = t_Elements.Load (
  389. a_Provider ,
  390. a_User ,
  391. a_Locale ,
  392. a_Scope
  393. ) ;
  394. t_StatusCode = WmiHelper :: LeaveCriticalSection ( ProviderSubSystem_Globals :: GetDecoupledRegistrySection () ) ;
  395. if ( SUCCEEDED ( t_TempResult ) )
  396. {
  397. WmiQueue < CServerObject_DecoupledClientRegistration_Element , 8 > &t_Queue = t_Elements.GetQueue () ;
  398. CServerObject_DecoupledClientRegistration_Element t_Top ;
  399. WmiStatusCode t_StatusCode ;
  400. while ( ( t_StatusCode = t_Queue.Top ( t_Top ) ) == e_StatusCode_Success )
  401. {
  402. HRESULT t_TempResult = Load (
  403. t_Registrar ,
  404. a_Context ,
  405. t_Top
  406. ) ;
  407. t_StatusCode = t_Queue.DeQueue () ;
  408. }
  409. }
  410. else
  411. {
  412. }
  413. t_Registrar->Release () ;
  414. }
  415. }
  416. catch ( ... )
  417. {
  418. t_Result = WBEM_E_PROVIDER_FAILURE ;
  419. }
  420. return t_Result ;
  421. }
  422. /******************************************************************************
  423. *
  424. * Name:
  425. *
  426. *
  427. * Description:
  428. *
  429. *
  430. *****************************************************************************/
  431. HRESULT CServerObject_BindingFactory :: GetHosting (
  432. CServerObject_ProviderRegistrationV1 &a_Registration ,
  433. IWbemContext *a_Context ,
  434. Enum_Hosting &a_Hosting ,
  435. LPCWSTR &a_HostingGroup
  436. )
  437. {
  438. HRESULT t_Result = S_OK ;
  439. a_Hosting = e_Hosting_Undefined ;
  440. if ( a_Context )
  441. {
  442. VARIANT t_Variant ;
  443. VariantInit ( & t_Variant ) ;
  444. HRESULT t_TResult = a_Context->GetValue ( L"Hosting" , 0 , & t_Variant ) ;
  445. if ( SUCCEEDED ( t_TResult ) )
  446. {
  447. if ( t_Variant.vt == VT_I4 )
  448. {
  449. a_Hosting = ( Enum_Hosting ) t_Variant.lVal ;
  450. }
  451. VariantClear ( & t_Variant ) ;
  452. }
  453. }
  454. a_Hosting = ( a_Hosting == e_Hosting_Undefined ) ? a_Registration.GetHosting () : a_Hosting ;
  455. switch ( a_Hosting )
  456. {
  457. case e_Hosting_SharedNetworkServiceHost:
  458. case e_Hosting_SharedLocalSystemHostOrSelfHost:
  459. case e_Hosting_SharedLocalSystemHost:
  460. case e_Hosting_SharedLocalServiceHost:
  461. {
  462. a_HostingGroup = a_Registration.GetHostingGroup () ;
  463. }
  464. break ;
  465. default:
  466. {
  467. a_HostingGroup = NULL ;
  468. }
  469. break ;
  470. }
  471. return t_Result ;
  472. }
  473. /******************************************************************************
  474. *
  475. * Name:
  476. *
  477. *
  478. * Description:
  479. *
  480. *
  481. *****************************************************************************/
  482. HRESULT CServerObject_BindingFactory :: Create (
  483. CServerObject_ProviderRegistrationV1 &a_Registration ,
  484. Enum_Hosting a_Hosting ,
  485. LPCWSTR a_HostingGroup ,
  486. LPCWSTR a_User ,
  487. _IWmiProviderHost **a_Host ,
  488. _IWmiProviderFactory **a_Factory ,
  489. IWbemContext *a_Context
  490. )
  491. {
  492. HRESULT t_Result = S_OK ;
  493. switch ( a_Hosting )
  494. {
  495. case e_Hosting_WmiCore:
  496. case e_Hosting_WmiCoreOrSelfHost:
  497. case e_Hosting_SelfHost:
  498. case e_Hosting_NonCom:
  499. {
  500. t_Result = ProviderSubSystem_Common_Globals :: CreateInstance (
  501. CLSID_WmiProviderInProcFactory ,
  502. NULL ,
  503. CLSCTX_INPROC_SERVER ,
  504. IID__IWmiProviderFactory ,
  505. ( void ** ) a_Factory
  506. ) ;
  507. }
  508. break ;
  509. case e_Hosting_SharedLocalSystemHost:
  510. case e_Hosting_SharedLocalSystemHostOrSelfHost:
  511. {
  512. try
  513. {
  514. HostCacheKey t_Key (
  515. HostCacheKey :: e_HostDesignation_Shared ,
  516. a_HostingGroup ,
  517. HostCacheKey :: e_IdentityDesignation_LocalSystem ,
  518. NULL
  519. ) ;
  520. t_Result = CServerObject_HostInterceptor :: CreateUsingToken (
  521. t_Key ,
  522. a_Host ,
  523. a_Factory ,
  524. a_Context
  525. ) ;
  526. }
  527. catch ( Wmi_Heap_Exception &a_Exception )
  528. {
  529. t_Result = WBEM_E_OUT_OF_MEMORY ;
  530. }
  531. catch ( ... )
  532. {
  533. t_Result = WBEM_E_CRITICAL_ERROR ;
  534. }
  535. }
  536. break ;
  537. case e_Hosting_Decoupled:
  538. {
  539. t_Result = WBEM_E_PROVIDER_NOT_FOUND ;
  540. }
  541. break ;
  542. case e_Hosting_SharedLocalServiceHost:
  543. {
  544. try
  545. {
  546. HostCacheKey t_Key (
  547. HostCacheKey :: e_HostDesignation_Shared ,
  548. a_HostingGroup ,
  549. HostCacheKey :: e_IdentityDesignation_LocalService ,
  550. NULL
  551. ) ;
  552. t_Result = CServerObject_HostInterceptor :: CreateUsingAccount (
  553. t_Key ,
  554. L"LocalService" ,
  555. L"NT AUTHORITY" ,
  556. a_Host ,
  557. a_Factory ,
  558. a_Context
  559. ) ;
  560. }
  561. catch ( Wmi_Heap_Exception &a_Exception )
  562. {
  563. t_Result = WBEM_E_OUT_OF_MEMORY ;
  564. }
  565. catch ( ... )
  566. {
  567. t_Result = WBEM_E_CRITICAL_ERROR ;
  568. }
  569. }
  570. break ;
  571. case e_Hosting_SharedNetworkServiceHost:
  572. {
  573. try
  574. {
  575. HostCacheKey t_Key (
  576. HostCacheKey :: e_HostDesignation_Shared ,
  577. a_HostingGroup ,
  578. HostCacheKey :: e_IdentityDesignation_NetworkService ,
  579. NULL
  580. ) ;
  581. t_Result = CServerObject_HostInterceptor :: CreateUsingAccount (
  582. t_Key ,
  583. L"NetworkService" ,
  584. L"NT AUTHORITY" ,
  585. a_Host ,
  586. a_Factory ,
  587. a_Context
  588. ) ;
  589. }
  590. catch ( Wmi_Heap_Exception &a_Exception )
  591. {
  592. t_Result = WBEM_E_OUT_OF_MEMORY ;
  593. }
  594. catch ( ... )
  595. {
  596. t_Result = WBEM_E_CRITICAL_ERROR ;
  597. }
  598. }
  599. break ;
  600. default:
  601. {
  602. t_Result = WBEM_E_INVALID_PROVIDER_REGISTRATION ;
  603. }
  604. break ;
  605. }
  606. return t_Result ;
  607. }
  608. /******************************************************************************
  609. *
  610. * Name:
  611. *
  612. *
  613. * Description:
  614. *
  615. *
  616. *****************************************************************************/
  617. HRESULT CServerObject_BindingFactory :: InitializeHostedService (
  618. CInterceptor_IWbemProvider *a_Interceptor ,
  619. IUnknown *a_Unknown
  620. )
  621. {
  622. HRESULT t_Result = S_OK ;
  623. IUnknown *t_InterceptorUnknown = NULL ;
  624. t_Result = a_Interceptor->QueryInterface ( IID_IUnknown , ( void ** ) & t_InterceptorUnknown ) ;
  625. if ( SUCCEEDED ( t_Result ) )
  626. {
  627. _IWmiProviderSite *t_Site = NULL ;
  628. t_Result = a_Unknown->QueryInterface ( IID__IWmiProviderSite , ( void ** ) & t_Site ) ;
  629. if ( SUCCEEDED ( t_Result ) )
  630. {
  631. t_Result = t_Site->SetContainer ( a_Interceptor->GetQuota () ) ;
  632. if ( SUCCEEDED ( t_Result ) )
  633. {
  634. DWORD t_ProcessIdentifier = 0 ;
  635. t_Result = t_Site->GetSite ( & t_ProcessIdentifier ) ;
  636. if ( SUCCEEDED ( t_Result ) )
  637. {
  638. CWbemGlobal_HostedProviderController *t_HostedController = ProviderSubSystem_Globals :: GetHostedProviderController () ;
  639. AutoLockGuard<CWbemGlobal_HostedProviderController> localLock(*t_HostedController);
  640. CWbemGlobal_HostedProviderController_Container_Iterator t_Iterator ;
  641. WmiStatusCode t_StatusCode = t_HostedController->Find ( t_ProcessIdentifier , t_Iterator ) ;
  642. switch ( t_StatusCode )
  643. {
  644. case e_StatusCode_Success:
  645. {
  646. ProviderController *t_ProviderController = NULL ;
  647. t_Result = t_Iterator.GetElement ()->QueryInterface ( IID_ProviderController , ( void ** ) & t_ProviderController ) ;
  648. if ( SUCCEEDED ( t_Result ) )
  649. {
  650. AutoLockGuard<ProviderController> providerLock(*t_ProviderController);
  651. ProviderController :: Container_Iterator t_Iterator ;
  652. t_StatusCode = t_ProviderController->Insert ( a_Interceptor , t_Iterator ) ;
  653. if ( t_StatusCode != e_StatusCode_Success )
  654. {
  655. t_Result = WBEM_E_OUT_OF_MEMORY ;
  656. }
  657. providerLock.UnLock () ;
  658. t_ProviderController->Release () ;
  659. }
  660. }
  661. break ;
  662. default:
  663. {
  664. ProviderController *t_ProviderController = new ProviderController (
  665. m_Allocator ,
  666. t_HostedController ,
  667. t_ProcessIdentifier
  668. ) ;
  669. if ( t_ProviderController )
  670. {
  671. t_ProviderController->AddRef () ;
  672. t_StatusCode = t_ProviderController->Initialize () ;
  673. if ( t_StatusCode == e_StatusCode_Success )
  674. {
  675. t_StatusCode = t_HostedController->Insert ( *t_ProviderController , t_Iterator ) ;
  676. if ( t_StatusCode == e_StatusCode_Success )
  677. {
  678. t_ProviderController->AddRef () ;
  679. AutoLockGuard<ProviderController> providerLock(*t_ProviderController);
  680. ProviderController :: Container_Iterator t_Iterator ;
  681. t_StatusCode = t_ProviderController->Insert ( a_Interceptor , t_Iterator ) ;
  682. if ( t_StatusCode == e_StatusCode_Success )
  683. {
  684. }
  685. else
  686. {
  687. t_Result = WBEM_E_OUT_OF_MEMORY ;
  688. }
  689. if ( FAILED ( t_Result ) )
  690. {
  691. t_StatusCode = t_HostedController->Delete ( t_ProcessIdentifier ) ;
  692. }
  693. providerLock.UnLock () ;
  694. }
  695. else
  696. {
  697. t_Result = WBEM_E_OUT_OF_MEMORY ;
  698. }
  699. }
  700. else
  701. {
  702. t_Result = WBEM_E_OUT_OF_MEMORY ;
  703. }
  704. t_ProviderController->Release () ;
  705. }
  706. else
  707. {
  708. t_Result = WBEM_E_OUT_OF_MEMORY ;
  709. }
  710. }
  711. break ;
  712. }
  713. }
  714. }
  715. t_Site->Release () ;
  716. }
  717. t_InterceptorUnknown->Release () ;
  718. }
  719. return t_Result ;
  720. }
  721. /******************************************************************************
  722. *
  723. * Name:
  724. *
  725. *
  726. * Description:
  727. *
  728. *
  729. *****************************************************************************/
  730. HRESULT CServerObject_BindingFactory :: InternalFindAggregatedDecoupledProvider (
  731. IWbemServices *a_RepositoryService ,
  732. IWbemServices *a_FullService ,
  733. CServerObject_ProviderRegistrationV1 &a_Registration ,
  734. ProviderCacheKey &a_Key ,
  735. LONG a_Flags ,
  736. IWbemContext *a_Context ,
  737. LPCWSTR a_User ,
  738. LPCWSTR a_Locale ,
  739. LPCWSTR a_Scope,
  740. LPCWSTR a_Name ,
  741. REFIID a_RIID ,
  742. void **a_Interface
  743. )
  744. {
  745. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  746. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  747. #endif
  748. HRESULT t_Result = S_OK ;
  749. try
  750. {
  751. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  752. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  753. WmiStatusCode t_StatusCode = Find ( a_Key , t_Iterator ) ;
  754. if ( t_StatusCode == e_StatusCode_Success )
  755. {
  756. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  757. localLock.UnLock () ;
  758. CDecoupledAggregator_IWbemProvider *t_Aggregator = NULL ;
  759. t_Result = t_Element->QueryInterface (
  760. IID_CDecoupledAggregator_IWbemProvider ,
  761. ( void ** ) & t_Aggregator
  762. ) ;
  763. if ( SUCCEEDED ( t_Result ) )
  764. {
  765. t_Result = t_Aggregator->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  766. if ( SUCCEEDED ( t_Result ) )
  767. {
  768. if ( t_Result == S_FALSE )
  769. {
  770. t_Result = t_Element->QueryInterface (
  771. a_RIID ,
  772. a_Interface
  773. ) ;
  774. t_Aggregator->Release () ;
  775. t_Element->Release () ;
  776. return t_Result ;
  777. }
  778. if ( SUCCEEDED ( t_Result = t_Aggregator->GetInitializeResult () ) )
  779. {
  780. t_Result = t_Element->QueryInterface (
  781. a_RIID ,
  782. a_Interface
  783. ) ;
  784. if ( FAILED ( t_Result ) )
  785. {
  786. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  787. }
  788. }
  789. else
  790. {
  791. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  792. }
  793. }
  794. t_Aggregator->Release () ;
  795. }
  796. else
  797. {
  798. t_Result = WBEM_E_UNEXPECTED ;
  799. }
  800. t_Element->Release () ;
  801. }
  802. else
  803. {
  804. BOOL t_ReEntrancy = ( a_Registration.GetInitializationReentrancy () == e_InitializationReentrancy_Clsid ) ;
  805. t_ReEntrancy = t_ReEntrancy || ( a_Registration.GetInitializationReentrancy () == e_InitializationReentrancy_Namespace ) ;
  806. CDecoupledAggregator_IWbemProvider *t_InitializingAggregator = NULL ;
  807. BOOL t_IndependantCall = TRUE ;
  808. if ( t_ReEntrancy )
  809. {
  810. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  811. GetCache ( t_Cache ) ;
  812. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  813. while ( ! t_Iterator.Null () )
  814. {
  815. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  816. BOOL t_Equivalent = ( a_Key.m_Provider ) && ( t_Iterator.GetKey ().m_Provider ) && ( wcscmp ( a_Key.m_Provider , t_Iterator.GetKey ().m_Provider ) == 0 ) ;
  817. if ( t_Equivalent )
  818. {
  819. t_Result = t_Element->QueryInterface (
  820. IID_CDecoupledAggregator_IWbemProvider ,
  821. ( void ** ) & t_InitializingAggregator
  822. ) ;
  823. if ( SUCCEEDED ( t_Result ) )
  824. {
  825. t_Result = t_InitializingAggregator->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  826. if ( SUCCEEDED ( t_Result ) )
  827. {
  828. if ( t_Result == S_FALSE )
  829. {
  830. t_IndependantCall = FALSE ;
  831. }
  832. }
  833. break ;
  834. }
  835. }
  836. t_Iterator.Increment () ;
  837. }
  838. }
  839. if ( SUCCEEDED ( t_Result ) )
  840. {
  841. wchar_t *t_NamespacePath = NULL ;
  842. t_Result = ProviderSubSystem_Common_Globals :: GetNamespacePath (
  843. Direct_GetNamespacePath () ,
  844. t_NamespacePath
  845. ) ;
  846. if ( SUCCEEDED ( t_Result ) )
  847. {
  848. CInterceptor_IWbemServices_Interceptor *t_RepositoryStub = new CInterceptor_IWbemServices_Interceptor ( m_Allocator , a_RepositoryService ) ;
  849. if ( t_RepositoryStub )
  850. {
  851. t_RepositoryStub->AddRef () ;
  852. // Do not care about failure case
  853. if (e_StatusCode_Success == m_SvcWrappersContainer.EnQueue((IWbemServices *)t_RepositoryStub))
  854. t_RepositoryStub->AddRef();
  855. CInterceptor_IWbemServices_Interceptor *t_FullStub = new CInterceptor_IWbemServices_Interceptor ( m_Allocator , a_FullService ) ;
  856. if ( t_FullStub )
  857. {
  858. t_FullStub->AddRef () ;
  859. // Do not care about failure case
  860. if (e_StatusCode_Success == m_SvcWrappersContainer.EnQueue((IWbemServices *)t_FullStub))
  861. t_FullStub->AddRef();
  862. CDecoupledAggregator_IWbemProvider *t_Aggregator = NULL ;
  863. try
  864. {
  865. t_Aggregator = new CDecoupledAggregator_IWbemProvider (
  866. m_Allocator ,
  867. this ,
  868. this ,
  869. t_RepositoryStub ,
  870. t_FullStub ,
  871. a_Key ,
  872. ProviderSubSystem_Globals :: s_InternalCacheTimeout ,
  873. a_Context ,
  874. a_Registration
  875. ) ;
  876. if ( t_Aggregator == NULL )
  877. {
  878. t_Result = WBEM_E_OUT_OF_MEMORY ;
  879. }
  880. }
  881. catch ( Wmi_Heap_Exception &a_Exception )
  882. {
  883. t_Result = WBEM_E_OUT_OF_MEMORY ;
  884. }
  885. catch ( ... )
  886. {
  887. t_Result = WBEM_E_CRITICAL_ERROR ;
  888. }
  889. if ( SUCCEEDED ( t_Result ) )
  890. {
  891. t_Aggregator->AddRef () ;
  892. _IWmiProviderInitialize *t_AggregatorInit = NULL ;
  893. t_Result = t_Aggregator->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_AggregatorInit ) ;
  894. if ( SUCCEEDED ( t_Result ) )
  895. {
  896. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  897. if ( t_ProviderInitSink )
  898. {
  899. t_ProviderInitSink->AddRef () ;
  900. t_Result = t_ProviderInitSink->SinkInitialize () ;
  901. if ( SUCCEEDED ( t_Result ) )
  902. {
  903. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  904. if ( t_Sink )
  905. {
  906. t_Sink->AddRef () ;
  907. t_Result = t_AggregatorInit->Initialize (
  908. 0 ,
  909. a_Context ,
  910. NULL ,
  911. ( const BSTR ) a_User ,
  912. ( const BSTR ) a_Locale ,
  913. ( const BSTR ) t_NamespacePath ,
  914. t_RepositoryStub ,
  915. t_FullStub ,
  916. t_Sink
  917. ) ;
  918. if ( SUCCEEDED ( t_Result ) )
  919. {
  920. t_ProviderInitSink->Wait () ;
  921. t_Result = t_ProviderInitSink->GetResult () ;
  922. if ( SUCCEEDED ( t_Result ) )
  923. {
  924. }
  925. }
  926. t_Sink->Release () ;
  927. }
  928. else
  929. {
  930. t_Result = WBEM_E_OUT_OF_MEMORY ;
  931. }
  932. }
  933. t_ProviderInitSink->Release () ;
  934. }
  935. else
  936. {
  937. t_Result = WBEM_E_OUT_OF_MEMORY ;
  938. }
  939. t_AggregatorInit->Release () ;
  940. }
  941. if ( SUCCEEDED ( t_Result ) )
  942. {
  943. if ( t_IndependantCall )
  944. {
  945. WmiStatusCode t_StatusCode = Insert (
  946. *t_Aggregator ,
  947. t_Iterator
  948. ) ;
  949. if ( t_StatusCode == e_StatusCode_Success )
  950. {
  951. localLock.UnLock () ;
  952. if ( t_InitializingAggregator )
  953. {
  954. t_Result = t_InitializingAggregator->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  955. if ( SUCCEEDED ( t_Result ) )
  956. {
  957. if ( t_Result == S_FALSE )
  958. {
  959. }
  960. else
  961. {
  962. if ( SUCCEEDED ( t_Result = t_InitializingAggregator->GetInitializeResult () ) )
  963. {
  964. }
  965. else
  966. {
  967. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  968. }
  969. }
  970. }
  971. }
  972. if ( SUCCEEDED ( t_Result ) )
  973. {
  974. t_Result = Load (
  975. t_Aggregator ,
  976. a_Context ,
  977. ( BSTR ) a_Name ,
  978. ( BSTR ) ( a_Registration.PerUserInitialization () ? a_User : NULL ) ,
  979. ( BSTR ) ( a_Registration.PerLocaleInitialization () ? a_Locale : NULL ) ,
  980. ( BSTR ) t_NamespacePath
  981. ) ;
  982. if ( SUCCEEDED ( t_Result ) )
  983. {
  984. t_Result = t_Aggregator->QueryInterface (
  985. a_RIID ,
  986. a_Interface
  987. ) ;
  988. }
  989. if ( FAILED ( t_Result ) )
  990. {
  991. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Shutdown ( a_Key ) ;
  992. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  993. }
  994. }
  995. t_Aggregator->SetInitialized ( t_Result ) ;
  996. }
  997. else
  998. {
  999. localLock.UnLock () ;
  1000. }
  1001. }
  1002. else
  1003. {
  1004. localLock.UnLock () ;
  1005. t_Result = t_Aggregator->QueryInterface (
  1006. a_RIID ,
  1007. a_Interface
  1008. ) ;
  1009. }
  1010. }
  1011. else
  1012. {
  1013. localLock.UnLock () ;
  1014. }
  1015. t_Aggregator->Release () ;
  1016. }
  1017. else
  1018. {
  1019. localLock.UnLock () ;
  1020. }
  1021. t_FullStub->Release () ;
  1022. }
  1023. else
  1024. {
  1025. localLock.UnLock () ;
  1026. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1027. }
  1028. t_RepositoryStub->Release () ;
  1029. }
  1030. else
  1031. {
  1032. localLock.UnLock () ;
  1033. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1034. }
  1035. delete [] t_NamespacePath ;
  1036. }
  1037. else
  1038. {
  1039. localLock.UnLock () ;
  1040. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1041. }
  1042. }
  1043. else
  1044. {
  1045. localLock.UnLock () ;
  1046. }
  1047. if ( t_InitializingAggregator )
  1048. {
  1049. t_InitializingAggregator->Release () ;
  1050. }
  1051. }
  1052. }
  1053. catch ( Wmi_Structured_Exception t_StructuredException )
  1054. {
  1055. t_Result = WBEM_E_CRITICAL_ERROR ;
  1056. }
  1057. return t_Result ;
  1058. }
  1059. /******************************************************************************
  1060. *
  1061. * Name:
  1062. *
  1063. *
  1064. * Description:
  1065. *
  1066. *
  1067. *****************************************************************************/
  1068. HRESULT CServerObject_BindingFactory :: GetDecoupledProvider (
  1069. LONG a_Flags ,
  1070. IWbemContext *a_Context ,
  1071. LPCWSTR a_User ,
  1072. LPCWSTR a_Locale ,
  1073. LPCWSTR a_Scope,
  1074. LPCWSTR a_Name ,
  1075. REFIID a_RIID ,
  1076. void **a_Interface
  1077. )
  1078. {
  1079. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1080. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1081. #endif
  1082. HRESULT t_Result = S_OK;
  1083. try
  1084. {
  1085. IWbemPath *t_Scope = NULL ;
  1086. if ( a_Scope )
  1087. {
  1088. t_Result = CoCreateInstance (
  1089. CLSID_WbemDefPath ,
  1090. NULL ,
  1091. CLSCTX_INPROC_SERVER ,
  1092. IID_IWbemPath ,
  1093. ( void ** ) & t_Scope
  1094. ) ;
  1095. if ( SUCCEEDED ( t_Result ) )
  1096. {
  1097. t_Result = t_Scope->SetText ( WBEMPATH_TREAT_SINGLE_IDENT_AS_NS | WBEMPATH_CREATE_ACCEPT_ALL , a_Scope ) ;
  1098. }
  1099. }
  1100. CServerObject_ProviderSubSystem *t_SubSystem = NULL ;
  1101. IWbemServices *t_RepositoryService = NULL ;
  1102. IWbemServices *t_FullService = NULL ;
  1103. if ( SUCCEEDED ( t_Result ) )
  1104. {
  1105. t_Result = Direct_GetSubSystem ()->QueryInterface ( IID_CWbemProviderSubSystem , ( void ** ) & t_SubSystem ) ;
  1106. if ( SUCCEEDED ( t_Result ) )
  1107. {
  1108. t_Result = t_SubSystem->GetWmiRepositoryService (
  1109. Direct_GetNamespacePath () ,
  1110. ( const BSTR ) a_User,
  1111. ( const BSTR ) a_Locale ,
  1112. t_RepositoryService
  1113. ) ;
  1114. if ( SUCCEEDED ( t_Result ) )
  1115. {
  1116. t_Result = t_SubSystem->GetWmiService (
  1117. Direct_GetNamespacePath () ,
  1118. ( const BSTR ) a_User ,
  1119. ( const BSTR ) a_Locale ,
  1120. t_FullService
  1121. ) ;
  1122. }
  1123. }
  1124. }
  1125. CServerObject_ProviderRegistrationV1 *t_Registration = new CServerObject_ProviderRegistrationV1 ;
  1126. if ( t_Registration )
  1127. {
  1128. t_Registration->AddRef () ;
  1129. }
  1130. else
  1131. {
  1132. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1133. }
  1134. if ( SUCCEEDED ( t_Result ) )
  1135. {
  1136. t_Result = t_Registration->SetContext (
  1137. a_Context ,
  1138. Direct_GetNamespacePath () ,
  1139. t_RepositoryService
  1140. ) ;
  1141. if ( SUCCEEDED ( t_Result ) )
  1142. {
  1143. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_InternalCacheTimeout ) ;
  1144. t_Result = t_Registration->Load (
  1145. e_All ,
  1146. t_Scope ,
  1147. a_Name
  1148. ) ;
  1149. if ( SUCCEEDED ( t_Result ) )
  1150. {
  1151. if ( t_Registration->GetComRegistration ().Enabled () )
  1152. {
  1153. if ( ProviderSubSystem_Globals :: CheckGuidTag ( t_Registration->GetClsid () ) )
  1154. {
  1155. t_Result = WBEM_E_PROVIDER_DISABLED ;
  1156. }
  1157. }
  1158. else
  1159. {
  1160. t_Result = WBEM_E_PROVIDER_DISABLED ;
  1161. }
  1162. }
  1163. else
  1164. {
  1165. if ( t_Result == WBEM_E_NOT_FOUND )
  1166. {
  1167. t_Result = WBEM_E_PROVIDER_NOT_FOUND ;
  1168. }
  1169. else
  1170. {
  1171. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. if ( SUCCEEDED ( t_Result ) )
  1177. {
  1178. try
  1179. {
  1180. ProviderCacheKey t_Key (
  1181. a_Name ,
  1182. e_Hosting_Decoupled ,
  1183. NULL ,
  1184. true ,
  1185. NULL ,
  1186. a_User ,
  1187. a_Locale
  1188. ) ;
  1189. t_Result = InternalFindAggregatedDecoupledProvider (
  1190. t_RepositoryService ,
  1191. t_FullService ,
  1192. *t_Registration ,
  1193. t_Key ,
  1194. a_Flags ,
  1195. a_Context ,
  1196. a_User ,
  1197. a_Locale ,
  1198. a_Scope,
  1199. a_Name ,
  1200. a_RIID ,
  1201. a_Interface
  1202. ) ;
  1203. }
  1204. catch ( Wmi_Heap_Exception &a_Exception )
  1205. {
  1206. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1207. }
  1208. catch ( ... )
  1209. {
  1210. t_Result = WBEM_E_CRITICAL_ERROR ;
  1211. }
  1212. }
  1213. if ( t_Scope )
  1214. {
  1215. t_Scope->Release () ;
  1216. }
  1217. if ( t_RepositoryService )
  1218. {
  1219. t_RepositoryService->Release () ;
  1220. }
  1221. if ( t_FullService )
  1222. {
  1223. t_FullService->Release () ;
  1224. }
  1225. if ( t_SubSystem )
  1226. {
  1227. t_SubSystem->Release () ;
  1228. }
  1229. if ( t_Registration )
  1230. {
  1231. t_Registration->Release () ;
  1232. }
  1233. }
  1234. catch ( Wmi_Structured_Exception t_StructuredException )
  1235. {
  1236. t_Result = WBEM_E_CRITICAL_ERROR ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  1237. }
  1238. return t_Result ;
  1239. }
  1240. /******************************************************************************
  1241. *
  1242. * Name:
  1243. *
  1244. *
  1245. * Description:
  1246. *
  1247. *
  1248. *****************************************************************************/
  1249. HRESULT CServerObject_BindingFactory :: InternalGetProvider (
  1250. IWbemServices *a_RepositoryService ,
  1251. IWbemServices *a_FullService ,
  1252. _IWmiProviderHost *a_Host ,
  1253. _IWmiProviderFactory *a_Factory ,
  1254. CInterceptor_IWbemProvider *a_Interceptor ,
  1255. CServerObject_ProviderRegistrationV1 &a_Registration ,
  1256. ProviderCacheKey &a_Key ,
  1257. LONG a_Flags ,
  1258. IWbemContext *a_Context ,
  1259. GUID *a_TransactionIdentifier,
  1260. LPCWSTR a_User ,
  1261. LPCWSTR a_Locale ,
  1262. LPCWSTR a_Scope ,
  1263. LPCWSTR a_Name ,
  1264. void **a_Unknown ,
  1265. REFIID a_RIID ,
  1266. void **a_Interface
  1267. )
  1268. {
  1269. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1270. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1271. #endif
  1272. HRESULT t_Result = S_OK ;
  1273. try
  1274. {
  1275. DWORD t_ProcessIdentifier = 0 ;
  1276. if ( a_Host )
  1277. {
  1278. t_Result = a_Host->GetProcessIdentifier ( & t_ProcessIdentifier ) ;
  1279. }
  1280. if ( SUCCEEDED ( t_Result ) )
  1281. {
  1282. BOOL t_Impersonating = FALSE ;
  1283. IUnknown *t_OldContext = NULL ;
  1284. IServerSecurity *t_OldSecurity = NULL ;
  1285. t_Result = ProviderSubSystem_Common_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1286. if ( SUCCEEDED ( t_Result ) )
  1287. {
  1288. BOOL t_Revert = FALSE ;
  1289. IUnknown *t_Proxy = NULL ;
  1290. HANDLE t_IdentifyHandle = NULL ;
  1291. switch ( a_Registration.GetHosting () )
  1292. {
  1293. case e_Hosting_SharedLocalSystemHost:
  1294. case e_Hosting_SharedLocalSystemHostOrSelfHost:
  1295. {
  1296. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState_SvcHost (
  1297. IID__IWmiProviderFactory ,
  1298. a_Factory ,
  1299. t_Proxy ,
  1300. t_Revert ,
  1301. t_ProcessIdentifier ,
  1302. t_IdentifyHandle ,
  1303. ProviderSubSystem_Common_Globals :: s_Token_All_Access_System_ACE ,
  1304. ProviderSubSystem_Common_Globals :: s_System_ACESize
  1305. ) ;
  1306. }
  1307. break ;
  1308. case e_Hosting_SharedLocalServiceHost:
  1309. {
  1310. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState_SvcHost (
  1311. IID__IWmiProviderFactory ,
  1312. a_Factory ,
  1313. t_Proxy ,
  1314. t_Revert ,
  1315. t_ProcessIdentifier ,
  1316. t_IdentifyHandle ,
  1317. ProviderSubSystem_Common_Globals :: s_Token_All_Access_LocalService_ACE ,
  1318. ProviderSubSystem_Common_Globals :: s_LocalService_ACESize
  1319. ) ;
  1320. }
  1321. break ;
  1322. case e_Hosting_SharedNetworkServiceHost:
  1323. {
  1324. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState_SvcHost (
  1325. IID__IWmiProviderFactory ,
  1326. a_Factory ,
  1327. t_Proxy ,
  1328. t_Revert ,
  1329. t_ProcessIdentifier ,
  1330. t_IdentifyHandle ,
  1331. ProviderSubSystem_Common_Globals :: s_Token_All_Access_NetworkService_ACE ,
  1332. ProviderSubSystem_Common_Globals :: s_NetworkService_ACESize
  1333. ) ;
  1334. }
  1335. break ;
  1336. default:
  1337. {
  1338. t_Result = ProviderSubSystem_Common_Globals :: SetProxyState (
  1339. IID__IWmiProviderFactory ,
  1340. a_Factory ,
  1341. t_Proxy ,
  1342. t_Revert
  1343. ) ;
  1344. }
  1345. break ;
  1346. }
  1347. if ( t_Result == WBEM_E_NOT_FOUND )
  1348. {
  1349. WmiInternalContext t_InternalContext ;
  1350. ZeroMemory ( & t_InternalContext , sizeof ( t_InternalContext ) ) ;
  1351. t_Result = a_Factory->GetProvider (
  1352. t_InternalContext ,
  1353. a_Flags ,
  1354. a_Context ,
  1355. a_TransactionIdentifier ,
  1356. a_User ,
  1357. a_Locale ,
  1358. a_Scope ,
  1359. a_Name ,
  1360. IID_IUnknown ,
  1361. a_Unknown
  1362. ) ;
  1363. DEBUGTRACE((LOG_PROVSS," LOCAL GetProvider(%S) hr = %08x\n",a_Name,t_Result));
  1364. }
  1365. else
  1366. {
  1367. if ( SUCCEEDED ( t_Result ) )
  1368. {
  1369. _IWmiProviderFactory *t_FactoryProxy = ( _IWmiProviderFactory * ) t_Proxy ;
  1370. // Set cloaking on the proxy
  1371. // =========================
  1372. DWORD t_ImpersonationLevel = ProviderSubSystem_Common_Globals :: GetCurrentImpersonationLevel () ;
  1373. t_Result = ProviderSubSystem_Common_Globals :: SetCloaking (
  1374. t_FactoryProxy ,
  1375. RPC_C_AUTHN_LEVEL_DEFAULT ,
  1376. t_ImpersonationLevel
  1377. ) ;
  1378. if ( SUCCEEDED ( t_Result ) )
  1379. {
  1380. IUnknown *t_Unknown = NULL ;
  1381. WmiInternalContext t_InternalContext ;
  1382. t_InternalContext.m_IdentifyHandle = ( unsigned __int64 ) t_IdentifyHandle ;
  1383. t_InternalContext.m_ProcessIdentifier = GetCurrentProcessId () ;
  1384. t_Result = t_FactoryProxy->GetProvider (
  1385. t_InternalContext ,
  1386. a_Flags ,
  1387. a_Context ,
  1388. a_TransactionIdentifier ,
  1389. a_User ,
  1390. a_Locale ,
  1391. a_Scope ,
  1392. a_Name ,
  1393. IID_IUnknown ,
  1394. a_Unknown
  1395. ) ;
  1396. DEBUGTRACE((LOG_PROVSS," PROXY GetProvider(%S) hr = %08x\n",a_Name,t_Result));
  1397. }
  1398. if ( t_IdentifyHandle )
  1399. {
  1400. HRESULT t_Result = ProviderSubSystem_Common_Globals :: RevertProxyState_SvcHost (
  1401. t_Proxy ,
  1402. t_Revert ,
  1403. t_ProcessIdentifier ,
  1404. t_IdentifyHandle
  1405. ) ;
  1406. }
  1407. else
  1408. {
  1409. HRESULT t_Result = ProviderSubSystem_Common_Globals :: RevertProxyState (
  1410. t_Proxy ,
  1411. t_Revert
  1412. ) ;
  1413. }
  1414. }
  1415. }
  1416. ProviderSubSystem_Common_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1417. }
  1418. }
  1419. }
  1420. catch ( Wmi_Structured_Exception t_StructuredException )
  1421. {
  1422. t_Result = WBEM_E_CRITICAL_ERROR ;
  1423. }
  1424. return t_Result ;
  1425. }
  1426. /******************************************************************************
  1427. *
  1428. * Name:
  1429. *
  1430. *
  1431. * Description:
  1432. *
  1433. *
  1434. *****************************************************************************/
  1435. HRESULT CServerObject_BindingFactory :: InternalGetProviderViaProxyRoute (
  1436. IWbemServices *a_RepositoryService ,
  1437. IWbemServices *a_FullService ,
  1438. CInterceptor_IWbemProvider *a_Interceptor ,
  1439. CServerObject_ProviderRegistrationV1 &a_Registration ,
  1440. Enum_Hosting a_Hosting ,
  1441. LPCWSTR a_HostingGroup ,
  1442. ProviderCacheKey &a_Key ,
  1443. LONG a_Flags ,
  1444. IWbemContext *a_Context ,
  1445. GUID *a_TransactionIdentifier,
  1446. LPCWSTR a_User ,
  1447. LPCWSTR a_Locale ,
  1448. LPCWSTR a_Scope ,
  1449. LPCWSTR a_Name ,
  1450. REFIID a_RIID ,
  1451. void **a_Interface
  1452. )
  1453. {
  1454. HRESULT t_Result = S_OK ;
  1455. DEBUGTRACE((LOG_PROVSS,"+ CServerObject_BindingFactory::InternalGetProviderViaProxyRoute\n"));
  1456. try
  1457. {
  1458. _IWmiProviderHost *t_Host = NULL ;
  1459. _IWmiProviderFactory *t_Factory = NULL ;
  1460. t_Result = Create (
  1461. a_Registration ,
  1462. a_Hosting ,
  1463. a_HostingGroup ,
  1464. a_User ,
  1465. & t_Host ,
  1466. & t_Factory ,
  1467. a_Context
  1468. ) ;
  1469. if ( SUCCEEDED ( t_Result ) )
  1470. {
  1471. _IWmiProviderFactoryInitialize *t_Initializer = NULL ;
  1472. t_Result = t_Factory->QueryInterface ( IID__IWmiProviderFactoryInitialize , ( void ** ) & t_Initializer ) ;
  1473. if ( SUCCEEDED ( t_Result ) )
  1474. {
  1475. CInterceptor_IWbemServices_Interceptor *t_RepositoryStub = new CInterceptor_IWbemServices_Interceptor (
  1476. m_Allocator ,
  1477. a_RepositoryService
  1478. ) ;
  1479. if ( t_RepositoryStub )
  1480. {
  1481. t_RepositoryStub->AddRef () ;
  1482. t_Result = t_RepositoryStub->ServiceInitialize () ;
  1483. if ( SUCCEEDED ( t_Result ) )
  1484. {
  1485. CInterceptor_IWbemServices_Interceptor *t_FullStub = new CInterceptor_IWbemServices_Interceptor (
  1486. m_Allocator ,
  1487. a_FullService
  1488. ) ;
  1489. if ( t_FullStub )
  1490. {
  1491. t_FullStub->AddRef () ;
  1492. t_Result = t_FullStub->ServiceInitialize () ;
  1493. if ( SUCCEEDED ( t_Result ) )
  1494. {
  1495. t_Result = t_Initializer->Initialize (
  1496. NULL ,
  1497. this ,
  1498. a_Flags ,
  1499. a_Context ,
  1500. Direct_GetNamespace () ,
  1501. t_RepositoryStub ,
  1502. t_FullStub
  1503. ) ;
  1504. if ( SUCCEEDED ( t_Result ) )
  1505. {
  1506. IUnknown *t_Unknown = NULL ;
  1507. t_Result = InternalGetProvider (
  1508. t_RepositoryStub ,
  1509. t_FullStub ,
  1510. t_Host ,
  1511. t_Factory ,
  1512. a_Interceptor ,
  1513. a_Registration ,
  1514. a_Key ,
  1515. a_Flags ,
  1516. a_Context ,
  1517. a_TransactionIdentifier ,
  1518. a_User ,
  1519. a_Locale ,
  1520. a_Scope ,
  1521. a_Name ,
  1522. ( void ** ) & t_Unknown ,
  1523. a_RIID ,
  1524. a_Interface
  1525. ) ;
  1526. DEBUGTRACE((LOG_PROVSS," InternalGetProvider hr = %08x\n",t_Result ));
  1527. if ( SUCCEEDED ( t_Result ) )
  1528. {
  1529. t_Result = a_Interceptor->SetProvider ( t_Host , t_Unknown ) ;
  1530. if ( SUCCEEDED ( t_Result ) )
  1531. {
  1532. t_Result = InitializeHostedService (
  1533. a_Interceptor ,
  1534. t_Unknown
  1535. ) ;
  1536. if ( SUCCEEDED ( t_Result ) )
  1537. {
  1538. t_Result = a_Interceptor->QueryInterface (
  1539. a_RIID ,
  1540. a_Interface
  1541. ) ;
  1542. if ( FAILED ( t_Result ) )
  1543. {
  1544. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  1545. }
  1546. }
  1547. }
  1548. t_Unknown->Release () ;
  1549. }
  1550. }
  1551. }
  1552. t_FullStub->Release () ;
  1553. }
  1554. else
  1555. {
  1556. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1557. }
  1558. }
  1559. t_RepositoryStub->Release () ;
  1560. }
  1561. else
  1562. {
  1563. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1564. }
  1565. t_Initializer->Release () ;
  1566. }
  1567. t_Factory->Release () ;
  1568. if ( t_Host )
  1569. {
  1570. t_Host->Release () ;
  1571. }
  1572. }
  1573. }
  1574. catch ( Wmi_Structured_Exception t_StructuredException )
  1575. {
  1576. t_Result = WBEM_E_CRITICAL_ERROR ;
  1577. }
  1578. DEBUGTRACE((LOG_PROVSS,"- CServerObject_BindingFactory::InternalGetProviderViaProxyRoute hr = %08x\n",t_Result));
  1579. return t_Result ;
  1580. }
  1581. /******************************************************************************
  1582. *
  1583. * Name:
  1584. *
  1585. *
  1586. * Description:
  1587. *
  1588. *
  1589. *****************************************************************************/
  1590. HRESULT CServerObject_BindingFactory :: InternalFindProvider (
  1591. IWbemServices *a_RepositoryService ,
  1592. IWbemServices *a_FullService ,
  1593. CServerObject_ProviderRegistrationV1 &a_Registration ,
  1594. Enum_Hosting a_Hosting ,
  1595. LPCWSTR a_HostingGroup ,
  1596. ProviderCacheKey &a_Key ,
  1597. LONG a_Flags ,
  1598. IWbemContext *a_Context ,
  1599. GUID *a_TransactionIdentifier,
  1600. LPCWSTR a_User ,
  1601. LPCWSTR a_Locale ,
  1602. LPCWSTR a_Scope ,
  1603. LPCWSTR a_Name ,
  1604. REFIID a_RIID ,
  1605. void **a_Interface
  1606. )
  1607. {
  1608. HRESULT t_Result = S_OK ;
  1609. try
  1610. {
  1611. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  1612. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  1613. WmiStatusCode t_StatusCode = Find ( a_Key , t_Iterator ) ;
  1614. DEBUGTRACE((LOG_PROVSS," Find() StatusCode %08x\n",t_StatusCode));
  1615. if ( t_StatusCode == e_StatusCode_Success )
  1616. {
  1617. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  1618. localLock.UnLock () ;
  1619. CInterceptor_IWbemProvider *t_Interceptor = NULL ;
  1620. t_Result = t_Element->QueryInterface (
  1621. IID_CInterceptor_IWbemProvider ,
  1622. ( void ** ) & t_Interceptor
  1623. ) ;
  1624. if ( SUCCEEDED ( t_Result ) )
  1625. {
  1626. t_Result = t_Interceptor->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  1627. if ( SUCCEEDED ( t_Result ) )
  1628. {
  1629. if ( t_Result == S_FALSE )
  1630. {
  1631. t_Result = t_Element->QueryInterface (
  1632. a_RIID ,
  1633. a_Interface
  1634. ) ;
  1635. t_Interceptor->Release () ;
  1636. t_Element->Release () ;
  1637. return t_Result ;
  1638. }
  1639. if ( SUCCEEDED ( t_Result = t_Interceptor->GetInitializeResult () ) )
  1640. {
  1641. t_Result = t_Element->QueryInterface (
  1642. a_RIID ,
  1643. a_Interface
  1644. ) ;
  1645. if ( FAILED ( t_Result ) )
  1646. {
  1647. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  1648. }
  1649. }
  1650. else
  1651. {
  1652. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  1653. }
  1654. }
  1655. t_Interceptor->Release () ;
  1656. }
  1657. else
  1658. {
  1659. t_Result = WBEM_E_UNEXPECTED ;
  1660. }
  1661. t_Element->Release () ;
  1662. }
  1663. else
  1664. {
  1665. BOOL t_ReEntrancy = ( a_Registration.GetInitializationReentrancy () == e_InitializationReentrancy_Clsid ) ;
  1666. t_ReEntrancy = t_ReEntrancy || ( a_Registration.GetInitializationReentrancy () == e_InitializationReentrancy_Namespace ) ;
  1667. CInterceptor_IWbemProvider *t_InitializingInterceptor = NULL ;
  1668. BOOL t_IndependantCall = TRUE ;
  1669. if ( t_ReEntrancy )
  1670. {
  1671. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  1672. GetCache ( t_Cache ) ;
  1673. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  1674. while ( ! t_Iterator.Null () )
  1675. {
  1676. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  1677. BOOL t_Equivalent = ( a_Key.m_Provider ) && ( t_Iterator.GetKey ().m_Provider ) && ( wcscmp ( a_Key.m_Provider , t_Iterator.GetKey ().m_Provider ) == 0 ) ;
  1678. if ( t_Equivalent )
  1679. {
  1680. t_Result = t_Element->QueryInterface (
  1681. IID_CInterceptor_IWbemProvider ,
  1682. ( void ** ) & t_InitializingInterceptor
  1683. ) ;
  1684. if ( SUCCEEDED ( t_Result ) )
  1685. {
  1686. t_Result = t_InitializingInterceptor->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  1687. if ( SUCCEEDED ( t_Result ) )
  1688. {
  1689. if ( t_Result == S_FALSE )
  1690. {
  1691. t_IndependantCall = FALSE ;
  1692. }
  1693. }
  1694. break ;
  1695. }
  1696. }
  1697. t_Iterator.Increment () ;
  1698. }
  1699. }
  1700. CInterceptor_IWbemProvider *t_Interceptor = NULL ;
  1701. try
  1702. {
  1703. t_Interceptor = new CInterceptor_IWbemProvider (
  1704. m_Allocator ,
  1705. this ,
  1706. a_Key ,
  1707. a_Registration.GetUnloadTimeoutMilliSeconds () ,
  1708. a_Context ,
  1709. a_Registration
  1710. ) ;
  1711. if ( t_Interceptor )
  1712. {
  1713. t_Interceptor->AddRef () ;
  1714. }
  1715. else
  1716. {
  1717. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1718. }
  1719. }
  1720. catch ( Wmi_Heap_Exception &a_Exception )
  1721. {
  1722. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1723. }
  1724. catch ( ... )
  1725. {
  1726. t_Result = WBEM_E_CRITICAL_ERROR ;
  1727. }
  1728. if ( SUCCEEDED ( t_Result ) )
  1729. {
  1730. IWbemProviderInit *t_InterceptorInit = NULL ;
  1731. t_Result = t_Interceptor->QueryInterface ( IID_IWbemProviderInit , ( void ** ) & t_InterceptorInit ) ;
  1732. if ( SUCCEEDED ( t_Result ) )
  1733. {
  1734. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  1735. if ( t_ProviderInitSink )
  1736. {
  1737. t_ProviderInitSink->AddRef () ;
  1738. t_Result = t_ProviderInitSink->SinkInitialize () ;
  1739. if ( SUCCEEDED ( t_Result ) )
  1740. {
  1741. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  1742. if ( t_Sink )
  1743. {
  1744. t_Sink->AddRef () ;
  1745. t_Result = t_InterceptorInit->Initialize (
  1746. NULL ,
  1747. 0 ,
  1748. m_Namespace ,
  1749. NULL ,
  1750. NULL ,
  1751. NULL ,
  1752. t_Sink
  1753. ) ;
  1754. if ( SUCCEEDED ( t_Result ) )
  1755. {
  1756. t_ProviderInitSink->Wait () ;
  1757. t_Result = t_ProviderInitSink->GetResult () ;
  1758. }
  1759. DEBUGTRACE((LOG_PROVSS," IWbemProviderInit::Initialize hr = %08x\n",t_Result));
  1760. t_Sink->Release () ;
  1761. }
  1762. else
  1763. {
  1764. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1765. }
  1766. }
  1767. t_ProviderInitSink->Release () ;
  1768. }
  1769. else
  1770. {
  1771. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1772. }
  1773. t_InterceptorInit->Release () ;
  1774. }
  1775. }
  1776. if ( SUCCEEDED ( t_Result ) )
  1777. {
  1778. if ( t_IndependantCall )
  1779. {
  1780. WmiStatusCode t_StatusCode = e_StatusCode_Success;
  1781. if ( a_Registration.GetUnloadTimeoutMilliSeconds() != 0 )
  1782. {
  1783. t_StatusCode = Insert (*t_Interceptor, t_Iterator);
  1784. }
  1785. if ( t_StatusCode == e_StatusCode_Success )
  1786. {
  1787. localLock.UnLock () ;
  1788. t_Result = InternalGetProviderViaProxyRoute (
  1789. a_RepositoryService ,
  1790. a_FullService ,
  1791. t_Interceptor ,
  1792. a_Registration ,
  1793. a_Hosting ,
  1794. a_HostingGroup ,
  1795. a_Key ,
  1796. a_Flags ,
  1797. a_Context ,
  1798. a_TransactionIdentifier ,
  1799. a_User ,
  1800. a_Locale ,
  1801. a_Scope ,
  1802. a_Name ,
  1803. a_RIID ,
  1804. a_Interface
  1805. ) ;
  1806. if ( FAILED ( t_Result ) )
  1807. {
  1808. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Shutdown ( a_Key ) ;
  1809. }
  1810. t_Interceptor->SetInitialized ( t_Result ) ;
  1811. }
  1812. else
  1813. {
  1814. localLock.UnLock () ;
  1815. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1816. }
  1817. }
  1818. else
  1819. {
  1820. localLock.UnLock () ;
  1821. t_Result = t_Interceptor->QueryInterface (
  1822. a_RIID ,
  1823. a_Interface
  1824. ) ;
  1825. }
  1826. }
  1827. else
  1828. {
  1829. localLock.UnLock () ;
  1830. }
  1831. if ( t_Interceptor )
  1832. {
  1833. t_Interceptor->Release () ;
  1834. }
  1835. if ( t_InitializingInterceptor )
  1836. {
  1837. t_InitializingInterceptor->Release () ;
  1838. }
  1839. }
  1840. }
  1841. catch ( ... )
  1842. {
  1843. t_Result = WBEM_E_CRITICAL_ERROR ;
  1844. }
  1845. return t_Result ;
  1846. }
  1847. /******************************************************************************
  1848. *
  1849. * Name:
  1850. *
  1851. *
  1852. * Description:
  1853. *
  1854. *
  1855. *****************************************************************************/
  1856. HRESULT CServerObject_BindingFactory :: GetProvider (
  1857. WmiInternalContext a_InternalContext ,
  1858. LONG a_Flags ,
  1859. IWbemContext *a_Context ,
  1860. GUID *a_TransactionIdentifier,
  1861. LPCWSTR a_User ,
  1862. LPCWSTR a_Locale ,
  1863. LPCWSTR a_Scope ,
  1864. LPCWSTR a_Name ,
  1865. REFIID a_RIID ,
  1866. void **a_Interface
  1867. )
  1868. {
  1869. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  1870. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  1871. #endif
  1872. #ifdef WMI_PRIVATE_DBG
  1873. #ifdef DBG
  1874. CTestNullTokenOnScope Test(__LINE__,__FILE__);
  1875. #endif
  1876. #endif
  1877. DEBUGTRACE((LOG_PROVSS,"+ CServerObject_BindingFactory::GetProvider User %S Locale %S Scope %S Name %S\n",a_User,a_Locale,a_Scope,a_Name));
  1878. HRESULT t_Result = S_OK ;
  1879. try
  1880. {
  1881. ProviderCacheKey t_Key (
  1882. a_Name ,
  1883. e_Hosting_SharedNetworkServiceHost ,
  1884. CServerObject_ComProviderRegistrationV1 :: s_Strings_Wmi_DefaultSharedNetworkServiceHost ,
  1885. true ,
  1886. a_TransactionIdentifier ,
  1887. NULL ,
  1888. NULL
  1889. ) ;
  1890. t_Result = FindProvider (
  1891. a_Context ,
  1892. t_Key ,
  1893. FALSE ,
  1894. a_RIID ,
  1895. a_Interface ,
  1896. a_User ,
  1897. a_Locale
  1898. ) ;
  1899. DEBUGTRACE((LOG_PROVSS," FindProvider hr = %08x\n",t_Result));
  1900. if ( SUCCEEDED ( t_Result ) )
  1901. {
  1902. }
  1903. else
  1904. {
  1905. if ( t_Result == WBEM_E_NOT_FOUND )
  1906. {
  1907. CServerObject_ProviderSubSystem *t_SubSystem = NULL ;
  1908. IWbemServices *t_RepositoryService = NULL ;
  1909. IWbemServices *t_FullService = NULL ;
  1910. t_Result = Direct_GetSubSystem ()->QueryInterface ( IID_CWbemProviderSubSystem , ( void ** ) & t_SubSystem ) ;
  1911. if ( SUCCEEDED ( t_Result ) )
  1912. {
  1913. t_Result = t_SubSystem->GetWmiRepositoryService (
  1914. Direct_GetNamespacePath () ,
  1915. ( const BSTR ) a_User ,
  1916. ( const BSTR ) a_Locale ,
  1917. t_RepositoryService
  1918. ) ;
  1919. if ( SUCCEEDED ( t_Result ) )
  1920. {
  1921. t_Result = t_SubSystem->GetWmiService (
  1922. Direct_GetNamespacePath () ,
  1923. ( const BSTR ) a_User ,
  1924. ( const BSTR ) a_Locale ,
  1925. t_FullService
  1926. ) ;
  1927. }
  1928. }
  1929. IWbemContext *t_Context = NULL ;
  1930. if ( SUCCEEDED ( t_Result ) )
  1931. {
  1932. if ( a_Context == NULL )
  1933. {
  1934. t_Result = CoCreateInstance (
  1935. CLSID_WbemContext ,
  1936. NULL ,
  1937. CLSCTX_INPROC_SERVER ,
  1938. IID_IWbemContext ,
  1939. ( void ** ) & t_Context
  1940. ) ;
  1941. }
  1942. }
  1943. IWbemPath *t_Scope = NULL ;
  1944. if ( SUCCEEDED ( t_Result ) )
  1945. {
  1946. if ( a_Scope )
  1947. {
  1948. t_Result = CoCreateInstance (
  1949. CLSID_WbemDefPath ,
  1950. NULL ,
  1951. CLSCTX_INPROC_SERVER ,
  1952. IID_IWbemPath ,
  1953. ( void ** ) & t_Scope
  1954. ) ;
  1955. if ( SUCCEEDED ( t_Result ) )
  1956. {
  1957. t_Result = t_Scope->SetText ( WBEMPATH_TREAT_SINGLE_IDENT_AS_NS | WBEMPATH_CREATE_ACCEPT_ALL , a_Scope ) ;
  1958. }
  1959. }
  1960. }
  1961. CServerObject_ProviderRegistrationV1 *t_Registration = new CServerObject_ProviderRegistrationV1 ;
  1962. if ( t_Registration )
  1963. {
  1964. t_Registration->AddRef () ;
  1965. }
  1966. else
  1967. {
  1968. t_Result = WBEM_E_OUT_OF_MEMORY ;
  1969. }
  1970. if ( SUCCEEDED ( t_Result ) )
  1971. {
  1972. t_Result = t_Registration->SetContext (
  1973. a_Context ? a_Context : t_Context ,
  1974. Direct_GetNamespacePath () ,
  1975. t_RepositoryService
  1976. ) ;
  1977. if ( SUCCEEDED ( t_Result ) )
  1978. {
  1979. t_Result = t_Registration->Load (
  1980. e_All ,
  1981. t_Scope ,
  1982. a_Name
  1983. ) ;
  1984. if ( SUCCEEDED ( t_Result ) )
  1985. {
  1986. if ( t_Registration->GetComRegistration ().Enabled () )
  1987. {
  1988. if ( ProviderSubSystem_Globals :: CheckGuidTag ( t_Registration->GetClsid () ) )
  1989. {
  1990. t_Result = WBEM_E_PROVIDER_DISABLED ;
  1991. }
  1992. }
  1993. }
  1994. else
  1995. {
  1996. if ( t_Result == WBEM_E_NOT_FOUND )
  1997. {
  1998. t_Result = WBEM_E_PROVIDER_NOT_FOUND ;
  1999. }
  2000. else
  2001. {
  2002. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  2003. }
  2004. }
  2005. if (t_Registration->GetUnloadTimeoutMilliSeconds()==DEFAULT_PROVIDER_TIMEOUT)
  2006. if ( t_Registration->ObjectProvider () )
  2007. {
  2008. if ( t_Registration->EventProvider () )
  2009. {
  2010. t_Registration->SetUnloadTimeoutMilliSeconds (
  2011. ProviderSubSystem_Globals :: s_ObjectCacheTimeout < ProviderSubSystem_Globals :: s_EventCacheTimeout ?
  2012. ProviderSubSystem_Globals :: s_EventCacheTimeout : ProviderSubSystem_Globals :: s_ObjectCacheTimeout
  2013. ) ;
  2014. }
  2015. else
  2016. {
  2017. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_ObjectCacheTimeout ) ;
  2018. }
  2019. }
  2020. else
  2021. {
  2022. if ( t_Registration->EventProvider () )
  2023. {
  2024. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_EventCacheTimeout ) ;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. if ( t_Scope )
  2030. {
  2031. t_Scope->Release () ;
  2032. }
  2033. if ( SUCCEEDED ( t_Result ) )
  2034. {
  2035. LPCWSTR t_HostingGroup = NULL ;
  2036. Enum_Hosting t_Hosting = e_Hosting_Undefined ;
  2037. t_Result = GetHosting ( *t_Registration , a_Context ? a_Context : t_Context , t_Hosting , t_HostingGroup ) ;
  2038. if ( SUCCEEDED ( t_Result ) )
  2039. {
  2040. try
  2041. {
  2042. ProviderCacheKey t_Key (
  2043. a_Name ,
  2044. t_Hosting ,
  2045. t_HostingGroup ,
  2046. true ,
  2047. a_TransactionIdentifier ,
  2048. t_Registration->PerUserInitialization () ? a_User : NULL ,
  2049. t_Registration->PerLocaleInitialization () ? a_Locale : NULL
  2050. ) ;
  2051. switch ( t_Hosting )
  2052. {
  2053. case e_Hosting_Decoupled:
  2054. {
  2055. t_Result = InternalFindAggregatedDecoupledProvider (
  2056. t_RepositoryService ,
  2057. t_FullService ,
  2058. *t_Registration ,
  2059. t_Key ,
  2060. a_Flags ,
  2061. a_Context ? a_Context : t_Context ,
  2062. a_User ,
  2063. a_Locale ,
  2064. a_Scope,
  2065. a_Name ,
  2066. a_RIID ,
  2067. a_Interface
  2068. ) ;
  2069. }
  2070. break ;
  2071. default:
  2072. {
  2073. t_Result = InternalFindProvider (
  2074. t_RepositoryService ,
  2075. t_FullService ,
  2076. *t_Registration ,
  2077. t_Hosting ,
  2078. t_HostingGroup ,
  2079. t_Key ,
  2080. a_Flags ,
  2081. a_Context ? a_Context : t_Context ,
  2082. a_TransactionIdentifier ,
  2083. a_User ,
  2084. a_Locale ,
  2085. a_Scope ,
  2086. a_Name ,
  2087. a_RIID ,
  2088. a_Interface
  2089. ) ;
  2090. }
  2091. break;
  2092. }
  2093. }
  2094. catch ( Wmi_Heap_Exception &a_Exception )
  2095. {
  2096. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2097. }
  2098. catch ( Wmi_Structured_Exception t_StructuredException )
  2099. {
  2100. t_Result = WBEM_E_FAILED ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  2101. }
  2102. catch ( ... )
  2103. {
  2104. t_Result = WBEM_E_CRITICAL_ERROR ;
  2105. }
  2106. }
  2107. }
  2108. if ( t_RepositoryService )
  2109. {
  2110. t_RepositoryService->Release () ;
  2111. }
  2112. if ( t_FullService )
  2113. {
  2114. t_FullService->Release () ;
  2115. }
  2116. if ( t_SubSystem )
  2117. {
  2118. t_SubSystem->Release () ;
  2119. }
  2120. if ( t_Registration )
  2121. {
  2122. t_Registration->Release () ;
  2123. }
  2124. if ( t_Context )
  2125. {
  2126. t_Context->Release () ;
  2127. }
  2128. }
  2129. }
  2130. }
  2131. catch ( Wmi_Heap_Exception &a_Exception )
  2132. {
  2133. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2134. }
  2135. catch ( Wmi_Structured_Exception t_StructuredException )
  2136. {
  2137. t_Result = WBEM_E_FAILED ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  2138. }
  2139. catch ( ... )
  2140. {
  2141. t_Result = WBEM_E_CRITICAL_ERROR ;
  2142. }
  2143. DEBUGTRACE((LOG_PROVSS,"- CServerObject_BindingFactory::GetProvider hr = %08x\n",t_Result));
  2144. return t_Result ;
  2145. }
  2146. /******************************************************************************
  2147. *
  2148. * Name:
  2149. *
  2150. *
  2151. * Description:
  2152. *
  2153. *
  2154. *****************************************************************************/
  2155. HRESULT CServerObject_BindingFactory :: GetHostedProvider (
  2156. LONG a_Flags ,
  2157. IWbemContext *a_Context ,
  2158. GUID *a_TransactionIdentifier,
  2159. LPCWSTR a_User ,
  2160. LPCWSTR a_Locale ,
  2161. LPCWSTR a_Scope ,
  2162. LPCWSTR a_Name ,
  2163. ULONG a_Host ,
  2164. LPCWSTR a_HostingGroup ,
  2165. REFIID a_RIID ,
  2166. void **a_Interface
  2167. )
  2168. {
  2169. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  2170. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  2171. #endif
  2172. HRESULT t_Result = S_OK;
  2173. try
  2174. {
  2175. ProviderCacheKey t_Key (
  2176. a_Name ,
  2177. a_Host ,
  2178. a_HostingGroup ,
  2179. true ,
  2180. a_TransactionIdentifier ,
  2181. NULL ,
  2182. NULL
  2183. ) ;
  2184. t_Result = FindProvider (
  2185. a_Context ,
  2186. t_Key ,
  2187. TRUE ,
  2188. a_RIID ,
  2189. a_Interface ,
  2190. a_User ,
  2191. a_Locale
  2192. ) ;
  2193. if ( SUCCEEDED ( t_Result ) )
  2194. {
  2195. }
  2196. else
  2197. {
  2198. if ( t_Result == WBEM_E_NOT_FOUND )
  2199. {
  2200. CServerObject_ProviderSubSystem *t_SubSystem = NULL ;
  2201. IWbemServices *t_RepositoryService = NULL ;
  2202. IWbemServices *t_FullService = NULL ;
  2203. t_Result = Direct_GetSubSystem ()->QueryInterface ( IID_CWbemProviderSubSystem , ( void ** ) & t_SubSystem ) ;
  2204. if ( SUCCEEDED ( t_Result ) )
  2205. {
  2206. t_Result = t_SubSystem->GetWmiRepositoryService (
  2207. Direct_GetNamespacePath () ,
  2208. ( const BSTR ) a_User ,
  2209. ( const BSTR ) a_Locale ,
  2210. t_RepositoryService
  2211. ) ;
  2212. if ( SUCCEEDED ( t_Result ) )
  2213. {
  2214. t_Result = t_SubSystem->GetWmiService (
  2215. Direct_GetNamespacePath () ,
  2216. ( const BSTR ) a_User ,
  2217. ( const BSTR ) a_Locale ,
  2218. t_FullService
  2219. ) ;
  2220. }
  2221. }
  2222. IWbemPath *t_Scope = NULL ;
  2223. if ( SUCCEEDED ( t_Result ) )
  2224. {
  2225. if ( a_Scope )
  2226. {
  2227. t_Result = CoCreateInstance (
  2228. CLSID_WbemDefPath ,
  2229. NULL ,
  2230. CLSCTX_INPROC_SERVER ,
  2231. IID_IWbemPath ,
  2232. ( void ** ) & t_Scope
  2233. ) ;
  2234. if ( SUCCEEDED ( t_Result ) )
  2235. {
  2236. t_Result = t_Scope->SetText ( WBEMPATH_TREAT_SINGLE_IDENT_AS_NS | WBEMPATH_CREATE_ACCEPT_ALL , a_Scope ) ;
  2237. }
  2238. }
  2239. }
  2240. CServerObject_ProviderRegistrationV1 *t_Registration = new CServerObject_ProviderRegistrationV1 ;
  2241. if ( t_Registration )
  2242. {
  2243. t_Registration->AddRef () ;
  2244. }
  2245. else
  2246. {
  2247. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2248. }
  2249. if ( SUCCEEDED ( t_Result ) )
  2250. {
  2251. t_Result = t_Registration->SetContext (
  2252. a_Context ,
  2253. Direct_GetNamespacePath () ,
  2254. t_RepositoryService
  2255. ) ;
  2256. if ( SUCCEEDED ( t_Result ) )
  2257. {
  2258. t_Result = t_Registration->Load (
  2259. e_All ,
  2260. t_Scope ,
  2261. a_Name
  2262. ) ;
  2263. if ( SUCCEEDED ( t_Result ) )
  2264. {
  2265. if ( t_Registration->GetComRegistration ().Enabled () )
  2266. {
  2267. if ( ProviderSubSystem_Globals :: CheckGuidTag ( t_Registration->GetClsid () ) )
  2268. {
  2269. t_Result = WBEM_E_PROVIDER_DISABLED ;
  2270. }
  2271. }
  2272. if (t_Registration->GetUnloadTimeoutMilliSeconds()==DEFAULT_PROVIDER_TIMEOUT)
  2273. {
  2274. if ( t_Registration->ObjectProvider () )
  2275. {
  2276. if ( t_Registration->EventProvider () )
  2277. {
  2278. t_Registration->SetUnloadTimeoutMilliSeconds (
  2279. ProviderSubSystem_Globals :: s_ObjectCacheTimeout < ProviderSubSystem_Globals :: s_EventCacheTimeout ?
  2280. ProviderSubSystem_Globals :: s_EventCacheTimeout : ProviderSubSystem_Globals :: s_ObjectCacheTimeout
  2281. ) ;
  2282. }
  2283. else
  2284. {
  2285. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_ObjectCacheTimeout ) ;
  2286. }
  2287. }
  2288. else
  2289. {
  2290. if ( t_Registration->EventProvider () )
  2291. {
  2292. t_Registration->SetUnloadTimeoutMilliSeconds ( ProviderSubSystem_Globals :: s_EventCacheTimeout ) ;
  2293. }
  2294. }
  2295. }
  2296. }
  2297. else
  2298. {
  2299. if ( t_Result == WBEM_E_NOT_FOUND )
  2300. {
  2301. t_Result = WBEM_E_PROVIDER_NOT_FOUND ;
  2302. }
  2303. else
  2304. {
  2305. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  2306. }
  2307. }
  2308. }
  2309. }
  2310. if ( t_Scope )
  2311. {
  2312. t_Scope->Release () ;
  2313. }
  2314. if ( SUCCEEDED ( t_Result ) )
  2315. {
  2316. try
  2317. {
  2318. ProviderCacheKey t_Key (
  2319. a_Name ,
  2320. a_Host ,
  2321. a_HostingGroup ,
  2322. true ,
  2323. a_TransactionIdentifier ,
  2324. t_Registration->PerUserInitialization () ? a_User : NULL ,
  2325. t_Registration->PerLocaleInitialization () ? a_Locale : NULL
  2326. ) ;
  2327. switch ( a_Host )
  2328. {
  2329. case e_Hosting_Decoupled:
  2330. {
  2331. t_Result = InternalFindAggregatedDecoupledProvider (
  2332. t_RepositoryService ,
  2333. t_FullService ,
  2334. *t_Registration ,
  2335. t_Key ,
  2336. a_Flags ,
  2337. a_Context ,
  2338. a_User ,
  2339. a_Locale ,
  2340. a_Scope,
  2341. a_Name ,
  2342. a_RIID ,
  2343. a_Interface
  2344. ) ;
  2345. }
  2346. break ;
  2347. default:
  2348. {
  2349. t_Result = InternalFindProvider (
  2350. t_RepositoryService ,
  2351. t_FullService ,
  2352. *t_Registration ,
  2353. ( Enum_Hosting ) a_Host ,
  2354. a_HostingGroup ,
  2355. t_Key ,
  2356. a_Flags ,
  2357. a_Context ,
  2358. a_TransactionIdentifier ,
  2359. a_User ,
  2360. a_Locale ,
  2361. a_Scope ,
  2362. a_Name ,
  2363. a_RIID ,
  2364. a_Interface
  2365. ) ;
  2366. }
  2367. break;
  2368. }
  2369. }
  2370. catch ( Wmi_Heap_Exception &a_Exception )
  2371. {
  2372. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2373. }
  2374. catch ( Wmi_Structured_Exception t_StructuredException )
  2375. {
  2376. t_Result = WBEM_E_FAILED ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  2377. }
  2378. catch ( ... )
  2379. {
  2380. t_Result = WBEM_E_CRITICAL_ERROR ;
  2381. }
  2382. }
  2383. if ( t_RepositoryService )
  2384. {
  2385. t_RepositoryService->Release () ;
  2386. }
  2387. if ( t_FullService )
  2388. {
  2389. t_FullService->Release () ;
  2390. }
  2391. if ( t_SubSystem )
  2392. {
  2393. t_SubSystem->Release () ;
  2394. }
  2395. if ( t_Registration )
  2396. {
  2397. t_Registration->Release () ;
  2398. }
  2399. }
  2400. }
  2401. }
  2402. catch ( Wmi_Heap_Exception &a_Exception )
  2403. {
  2404. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2405. }
  2406. catch ( Wmi_Structured_Exception t_StructuredException )
  2407. {
  2408. t_Result = WBEM_E_FAILED ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  2409. }
  2410. catch ( ... )
  2411. {
  2412. t_Result = WBEM_E_CRITICAL_ERROR ;
  2413. }
  2414. return t_Result ;
  2415. }
  2416. /******************************************************************************
  2417. *
  2418. * Name:
  2419. *
  2420. *
  2421. * Description:
  2422. *
  2423. *
  2424. *****************************************************************************/
  2425. HRESULT CServerObject_BindingFactory :: GetAggregatedClassProvider (
  2426. IWbemServices *a_RepositoryService ,
  2427. IWbemServices *a_FullService ,
  2428. ProviderCacheKey &a_Key ,
  2429. LONG a_Flags ,
  2430. IWbemContext *a_Context ,
  2431. LPCWSTR a_User ,
  2432. LPCWSTR a_Locale ,
  2433. LPCWSTR a_Scope ,
  2434. IWbemClassObject *a_Class ,
  2435. REFIID a_RIID ,
  2436. void **a_Interface
  2437. )
  2438. {
  2439. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  2440. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  2441. #endif
  2442. HRESULT t_Result = S_OK ;
  2443. try
  2444. {
  2445. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  2446. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  2447. WmiStatusCode t_StatusCode = Find ( a_Key , t_Iterator ) ;
  2448. if ( t_StatusCode == e_StatusCode_Success )
  2449. {
  2450. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  2451. localLock.UnLock () ;
  2452. CAggregator_IWbemProvider *t_Aggregator = NULL ;
  2453. t_Result = t_Element->QueryInterface (
  2454. IID_CAggregator_IWbemProvider ,
  2455. ( void ** ) & t_Aggregator
  2456. ) ;
  2457. if ( SUCCEEDED ( t_Result ) )
  2458. {
  2459. t_Result = t_Aggregator->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  2460. if ( SUCCEEDED ( t_Result ) )
  2461. {
  2462. if ( t_Result == S_FALSE )
  2463. {
  2464. t_Result = t_Element->QueryInterface (
  2465. a_RIID ,
  2466. a_Interface
  2467. ) ;
  2468. t_Aggregator->Release () ;
  2469. t_Element->Release () ;
  2470. return t_Result ;
  2471. }
  2472. if ( SUCCEEDED ( t_Result = t_Aggregator->GetInitializeResult () ) )
  2473. {
  2474. t_Result = t_Element->QueryInterface (
  2475. a_RIID ,
  2476. a_Interface
  2477. ) ;
  2478. if ( FAILED ( t_Result ) )
  2479. {
  2480. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  2481. }
  2482. }
  2483. else
  2484. {
  2485. t_Result = WBEM_E_PROVIDER_LOAD_FAILURE ;
  2486. }
  2487. }
  2488. t_Aggregator->Release () ;
  2489. }
  2490. else
  2491. {
  2492. t_Result = WBEM_E_UNEXPECTED ;
  2493. }
  2494. t_Element->Release () ;
  2495. }
  2496. else
  2497. {
  2498. CAggregator_IWbemProvider *t_Aggregator = NULL ;
  2499. CInterceptor_IWbemServices_Interceptor *t_RepositoryStub = new CInterceptor_IWbemServices_Interceptor ( m_Allocator , a_RepositoryService ) ;
  2500. if ( t_RepositoryStub )
  2501. {
  2502. t_RepositoryStub->AddRef () ;
  2503. CInterceptor_IWbemServices_Interceptor *t_FullStub = new CInterceptor_IWbemServices_Interceptor ( m_Allocator , a_FullService ) ;
  2504. if ( t_FullStub )
  2505. {
  2506. t_FullStub->AddRef () ;
  2507. t_Aggregator = new CAggregator_IWbemProvider (
  2508. m_Allocator ,
  2509. this ,
  2510. this ,
  2511. t_RepositoryStub ,
  2512. t_FullStub ,
  2513. a_Key ,
  2514. ProviderSubSystem_Globals :: s_InternalCacheTimeout ,
  2515. a_Context
  2516. ) ;
  2517. if ( t_Aggregator )
  2518. {
  2519. t_Aggregator->AddRef () ;
  2520. wchar_t *t_NamespacePath = NULL ;
  2521. t_Result = ProviderSubSystem_Common_Globals :: GetNamespacePath (
  2522. Direct_GetNamespacePath () ,
  2523. t_NamespacePath
  2524. ) ;
  2525. if ( SUCCEEDED ( t_Result ) )
  2526. {
  2527. _IWmiProviderInitialize *t_AggregatorInit = NULL ;
  2528. t_Result = t_Aggregator->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_AggregatorInit ) ;
  2529. if ( SUCCEEDED ( t_Result ) )
  2530. {
  2531. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  2532. if ( t_ProviderInitSink )
  2533. {
  2534. t_ProviderInitSink->AddRef () ;
  2535. t_Result = t_ProviderInitSink->SinkInitialize () ;
  2536. if ( SUCCEEDED ( t_Result ) )
  2537. {
  2538. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  2539. if ( t_Sink )
  2540. {
  2541. t_Sink->AddRef () ;
  2542. t_Result = t_AggregatorInit->Initialize (
  2543. 0 ,
  2544. a_Context ,
  2545. NULL ,
  2546. ( const BSTR ) a_User ,
  2547. ( const BSTR ) a_Locale ,
  2548. ( const BSTR ) t_NamespacePath ,
  2549. t_RepositoryStub ,
  2550. t_FullStub ,
  2551. t_Sink
  2552. ) ;
  2553. if ( SUCCEEDED ( t_Result ) )
  2554. {
  2555. t_ProviderInitSink->Wait () ;
  2556. t_Result = t_ProviderInitSink->GetResult () ;
  2557. }
  2558. t_Sink->Release () ;
  2559. }
  2560. else
  2561. {
  2562. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2563. }
  2564. }
  2565. t_ProviderInitSink->Release () ;
  2566. }
  2567. else
  2568. {
  2569. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2570. }
  2571. t_AggregatorInit->Release () ;
  2572. }
  2573. delete [] t_NamespacePath ;
  2574. }
  2575. }
  2576. else
  2577. {
  2578. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2579. }
  2580. t_FullStub->Release () ;
  2581. }
  2582. else
  2583. {
  2584. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2585. }
  2586. t_RepositoryStub->Release () ;
  2587. }
  2588. else
  2589. {
  2590. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2591. }
  2592. if ( SUCCEEDED ( t_Result ) )
  2593. {
  2594. WmiStatusCode t_StatusCode = Insert (
  2595. *t_Aggregator ,
  2596. t_Iterator
  2597. ) ;
  2598. if ( t_StatusCode == e_StatusCode_Success )
  2599. {
  2600. localLock.UnLock () ;
  2601. t_Result = t_Aggregator->Enum_ClassProviders ( a_Context ) ;
  2602. if ( SUCCEEDED ( t_Result ) )
  2603. {
  2604. t_Result = t_Aggregator->QueryInterface (
  2605. a_RIID ,
  2606. a_Interface
  2607. ) ;
  2608. if ( FAILED ( t_Result ) )
  2609. {
  2610. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  2611. }
  2612. }
  2613. t_Aggregator->SetInitialized ( t_Result ) ;
  2614. }
  2615. else
  2616. {
  2617. localLock.UnLock () ;
  2618. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2619. }
  2620. }
  2621. else
  2622. {
  2623. localLock.UnLock () ;
  2624. }
  2625. if ( t_Aggregator )
  2626. {
  2627. t_Aggregator->Release () ;
  2628. }
  2629. }
  2630. }
  2631. catch ( Wmi_Structured_Exception t_StructuredException )
  2632. {
  2633. t_Result = WBEM_E_CRITICAL_ERROR ;
  2634. }
  2635. return t_Result ;
  2636. }
  2637. /******************************************************************************
  2638. *
  2639. * Name:
  2640. *
  2641. *
  2642. * Description:
  2643. *
  2644. *
  2645. *****************************************************************************/
  2646. HRESULT CServerObject_BindingFactory :: WaitProvider (
  2647. IWbemContext *a_Context ,
  2648. REFIID a_RIID ,
  2649. void **a_Interface ,
  2650. ServiceCacheElement *a_Element ,
  2651. _IWmiProviderInitialize *a_Initializer
  2652. )
  2653. {
  2654. HRESULT t_Result = a_Initializer->WaitProvider ( a_Context , DEFAULT_PROVIDER_LOAD_TIMEOUT ) ;
  2655. if ( SUCCEEDED ( t_Result ) )
  2656. {
  2657. if ( t_Result == S_FALSE )
  2658. {
  2659. t_Result = a_Element->QueryInterface (
  2660. a_RIID ,
  2661. a_Interface
  2662. ) ;
  2663. }
  2664. else
  2665. {
  2666. if ( SUCCEEDED ( t_Result = a_Initializer->GetInitializeResult () ) )
  2667. {
  2668. t_Result = a_Element->QueryInterface (
  2669. a_RIID ,
  2670. a_Interface
  2671. ) ;
  2672. if ( FAILED ( t_Result ) )
  2673. {
  2674. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  2675. }
  2676. }
  2677. }
  2678. }
  2679. return t_Result ;
  2680. }
  2681. /******************************************************************************
  2682. *
  2683. * Name:
  2684. *
  2685. *
  2686. * Description:
  2687. *
  2688. *
  2689. *****************************************************************************/
  2690. HRESULT CServerObject_BindingFactory :: SearchSpecificProvider (
  2691. IWbemContext *a_Context ,
  2692. ProviderCacheKey &a_Key ,
  2693. REFIID a_RIID ,
  2694. void **a_Interface ,
  2695. LPCWSTR a_User ,
  2696. LPCWSTR a_Locale
  2697. )
  2698. {
  2699. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  2700. HRESULT t_Result = S_OK ;
  2701. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  2702. GetCache ( t_Cache ) ;
  2703. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  2704. try
  2705. {
  2706. ProviderCacheKey t_Key (
  2707. a_Key.m_Provider ,
  2708. e_Hosting_Undefined ,
  2709. NULL ,
  2710. false ,
  2711. NULL ,
  2712. NULL ,
  2713. NULL
  2714. ) ;
  2715. WmiStatusCode t_StatusCode = t_Cache->FindNext ( t_Key , t_Iterator ) ;
  2716. if ( t_StatusCode != e_StatusCode_Success )
  2717. {
  2718. t_Result = WBEM_E_NOT_FOUND ;
  2719. }
  2720. }
  2721. catch ( Wmi_Heap_Exception &a_Exception )
  2722. {
  2723. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2724. }
  2725. catch ( ... )
  2726. {
  2727. t_Result = WBEM_E_CRITICAL_ERROR ;
  2728. }
  2729. if ( SUCCEEDED ( t_Result ) )
  2730. {
  2731. BOOL t_Equal = FALSE ;
  2732. if ( t_Iterator.GetKey ().m_Provider )
  2733. {
  2734. if ( a_Key.m_Provider )
  2735. {
  2736. if ( wbem_wcsicmp ( t_Iterator.GetKey ().m_Provider , a_Key.m_Provider ) == 0 )
  2737. {
  2738. t_Equal = TRUE ;
  2739. }
  2740. }
  2741. }
  2742. if ( t_Equal )
  2743. {
  2744. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  2745. _IWmiProviderInitialize *t_Initializer = NULL ;
  2746. t_Result = t_Element->QueryInterface (
  2747. IID__IWmiProviderInitialize ,
  2748. ( void ** ) & t_Initializer
  2749. ) ;
  2750. if ( SUCCEEDED ( t_Result ) )
  2751. {
  2752. BOOL t_PerUser ;
  2753. t_Initializer->IsPerUserInitialization ( & t_PerUser ) ;
  2754. BOOL t_PerLocale ;
  2755. t_Initializer->IsPerLocaleInitialization ( & t_PerLocale ) ;
  2756. DWORD t_Hosting ;
  2757. t_Initializer->GetHosting ( & t_Hosting ) ;
  2758. BSTR t_HostingGroup ;
  2759. t_Initializer->GetHostingGroup ( & t_HostingGroup ) ;
  2760. BOOL t_Internal ;
  2761. t_Initializer->IsInternal ( & t_Internal ) ;
  2762. try
  2763. {
  2764. ProviderCacheKey t_SpecificKey (
  2765. a_Key.m_Provider ,
  2766. t_Hosting ,
  2767. t_HostingGroup ,
  2768. t_Internal ? false : true ,
  2769. NULL ,
  2770. t_PerUser ? a_User : NULL ,
  2771. t_PerLocale ? a_Locale : NULL
  2772. ) ;
  2773. SysFreeString ( t_HostingGroup ) ;
  2774. WmiStatusCode t_StatusCode = Find ( t_SpecificKey , t_Iterator ) ;
  2775. if ( t_StatusCode != e_StatusCode_Success )
  2776. {
  2777. t_Result = WBEM_E_NOT_FOUND ;
  2778. }
  2779. }
  2780. catch ( Wmi_Heap_Exception &a_Exception )
  2781. {
  2782. t_Result = WBEM_E_OUT_OF_MEMORY ;
  2783. }
  2784. catch ( ... )
  2785. {
  2786. t_Result = WBEM_E_CRITICAL_ERROR ;
  2787. }
  2788. if ( SUCCEEDED ( t_Result ) )
  2789. {
  2790. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  2791. localLock.UnLock () ;
  2792. _IWmiProviderInitialize *t_SpecificInitializer = NULL ;
  2793. t_Result = t_Element->QueryInterface (
  2794. IID__IWmiProviderInitialize ,
  2795. ( void ** ) & t_SpecificInitializer
  2796. ) ;
  2797. if ( SUCCEEDED ( t_Result ) )
  2798. {
  2799. t_Result = WaitProvider (
  2800. a_Context ,
  2801. a_RIID ,
  2802. a_Interface ,
  2803. t_Element ,
  2804. t_SpecificInitializer
  2805. ) ;
  2806. t_SpecificInitializer->Release () ;
  2807. }
  2808. else
  2809. {
  2810. t_Result = WBEM_E_UNEXPECTED ;
  2811. }
  2812. t_Element->Release () ;
  2813. }
  2814. else
  2815. {
  2816. localLock.UnLock () ;
  2817. }
  2818. t_Initializer->Release () ;
  2819. }
  2820. else
  2821. {
  2822. localLock.UnLock () ;
  2823. }
  2824. }
  2825. else
  2826. {
  2827. localLock.UnLock () ;
  2828. t_Result = WBEM_E_NOT_FOUND ;
  2829. }
  2830. }
  2831. else
  2832. {
  2833. localLock.UnLock () ;
  2834. }
  2835. return t_Result ;
  2836. }
  2837. /******************************************************************************
  2838. *
  2839. * Name:
  2840. *
  2841. *
  2842. * Description:
  2843. *
  2844. *
  2845. *****************************************************************************/
  2846. HRESULT CServerObject_BindingFactory :: FindProvider (
  2847. IWbemContext *a_Context ,
  2848. ProviderCacheKey &a_Key ,
  2849. BOOL a_SpecificProvider ,
  2850. REFIID a_RIID ,
  2851. void **a_Interface ,
  2852. LPCWSTR a_User ,
  2853. LPCWSTR a_Locale
  2854. )
  2855. {
  2856. HRESULT t_Result = S_OK;
  2857. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  2858. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  2859. WmiStatusCode t_StatusCode = Find ( a_Key , t_Iterator ) ;
  2860. if ( t_StatusCode == e_StatusCode_Success )
  2861. {
  2862. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  2863. localLock.UnLock () ;
  2864. _IWmiProviderInitialize *t_Initializer = NULL ;
  2865. t_Result = t_Element->QueryInterface (
  2866. IID__IWmiProviderInitialize ,
  2867. ( void ** ) & t_Initializer
  2868. ) ;
  2869. if ( SUCCEEDED ( t_Result ) )
  2870. {
  2871. BOOL t_PerUser ;
  2872. t_Initializer->IsPerUserInitialization ( & t_PerUser ) ;
  2873. BOOL t_PerLocale ;
  2874. t_Initializer->IsPerLocaleInitialization ( & t_PerLocale ) ;
  2875. if ( t_PerUser || t_PerLocale )
  2876. {
  2877. t_Result = WBEM_E_NOT_FOUND ;
  2878. }
  2879. else
  2880. {
  2881. t_Result = WaitProvider (
  2882. a_Context ,
  2883. a_RIID ,
  2884. a_Interface ,
  2885. t_Element ,
  2886. t_Initializer
  2887. ) ;
  2888. }
  2889. t_Initializer->Release () ;
  2890. }
  2891. else
  2892. {
  2893. t_Result = WBEM_E_UNEXPECTED ;
  2894. }
  2895. t_Element->Release () ;
  2896. }
  2897. else
  2898. {
  2899. t_Result = WBEM_E_NOT_FOUND ;
  2900. localLock.UnLock () ;
  2901. }
  2902. if ( t_Result == WBEM_E_NOT_FOUND )
  2903. {
  2904. if ( ! a_SpecificProvider )
  2905. {
  2906. t_Result = SearchSpecificProvider (
  2907. a_Context ,
  2908. a_Key ,
  2909. a_RIID ,
  2910. a_Interface ,
  2911. a_User ,
  2912. a_Locale
  2913. ) ;
  2914. }
  2915. }
  2916. return t_Result ;
  2917. }
  2918. /******************************************************************************
  2919. *
  2920. * Name:
  2921. *
  2922. *
  2923. * Description:
  2924. *
  2925. *
  2926. *****************************************************************************/
  2927. HRESULT CServerObject_BindingFactory :: GetClassProvider (
  2928. LONG a_Flags ,
  2929. IWbemContext *a_Context ,
  2930. LPCWSTR a_User ,
  2931. LPCWSTR a_Locale ,
  2932. LPCWSTR a_Scope ,
  2933. IWbemClassObject *a_Class ,
  2934. REFIID a_RIID ,
  2935. void **a_Interface
  2936. )
  2937. {
  2938. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  2939. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  2940. #endif
  2941. HRESULT t_Result = S_OK;
  2942. try
  2943. {
  2944. ProviderCacheKey t_Key (
  2945. NULL ,
  2946. e_Hosting_WmiCore ,
  2947. NULL ,
  2948. false ,
  2949. NULL ,
  2950. a_User ,
  2951. a_Locale
  2952. ) ;
  2953. t_Result = FindProvider (
  2954. a_Context ,
  2955. t_Key ,
  2956. TRUE ,
  2957. a_RIID ,
  2958. a_Interface ,
  2959. a_User ,
  2960. a_Locale
  2961. ) ;
  2962. if ( SUCCEEDED ( t_Result ) )
  2963. {
  2964. }
  2965. else
  2966. {
  2967. if ( t_Result == WBEM_E_NOT_FOUND )
  2968. {
  2969. CServerObject_ProviderSubSystem *t_SubSystem = NULL ;
  2970. IWbemServices *t_RepositoryService = NULL ;
  2971. IWbemServices *t_FullService = NULL ;
  2972. t_Result = Direct_GetSubSystem ()->QueryInterface ( IID_CWbemProviderSubSystem , ( void ** ) & t_SubSystem ) ;
  2973. if ( SUCCEEDED ( t_Result ) )
  2974. {
  2975. t_Result = t_SubSystem->GetWmiRepositoryService (
  2976. Direct_GetNamespacePath () ,
  2977. ( const BSTR ) a_User ,
  2978. ( const BSTR ) a_Locale ,
  2979. t_RepositoryService
  2980. ) ;
  2981. if ( SUCCEEDED ( t_Result ) )
  2982. {
  2983. t_Result = t_SubSystem->GetWmiService (
  2984. Direct_GetNamespacePath () ,
  2985. ( const BSTR ) a_User ,
  2986. ( const BSTR ) a_Locale ,
  2987. t_FullService
  2988. ) ;
  2989. }
  2990. }
  2991. if ( SUCCEEDED ( t_Result ) )
  2992. {
  2993. t_Result = GetAggregatedClassProvider (
  2994. t_RepositoryService ,
  2995. t_FullService ,
  2996. t_Key ,
  2997. a_Flags ,
  2998. a_Context ,
  2999. a_User ,
  3000. a_Locale ,
  3001. a_Scope ,
  3002. a_Class ,
  3003. a_RIID ,
  3004. a_Interface
  3005. ) ;
  3006. }
  3007. if ( t_RepositoryService )
  3008. {
  3009. t_RepositoryService->Release () ;
  3010. }
  3011. if ( t_FullService )
  3012. {
  3013. t_FullService->Release () ;
  3014. }
  3015. if ( t_SubSystem )
  3016. {
  3017. t_SubSystem->Release () ;
  3018. }
  3019. }
  3020. }
  3021. }
  3022. catch ( Wmi_Structured_Exception t_StructuredException )
  3023. {
  3024. t_Result = WBEM_E_CRITICAL_ERROR ;
  3025. }
  3026. catch ( Wmi_Heap_Exception t_HeapException )
  3027. {
  3028. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3029. }
  3030. return t_Result ;
  3031. }
  3032. /******************************************************************************
  3033. *
  3034. * Name:
  3035. *
  3036. *
  3037. * Description:
  3038. *
  3039. *
  3040. *****************************************************************************/
  3041. HRESULT CServerObject_BindingFactory :: GetDynamicPropertyResolver (
  3042. LONG a_Flags ,
  3043. IWbemContext *a_Context ,
  3044. LPCWSTR a_User ,
  3045. LPCWSTR a_Locale ,
  3046. REFIID a_RIID ,
  3047. void **a_Interface
  3048. )
  3049. {
  3050. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  3051. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  3052. #endif
  3053. HRESULT t_Result = S_OK;
  3054. try
  3055. {
  3056. CServerObject_ProviderSubSystem *t_SubSystem = NULL ;
  3057. t_Result = Direct_GetSubSystem ()->QueryInterface ( IID_CWbemProviderSubSystem , ( void ** ) & t_SubSystem ) ;
  3058. if ( SUCCEEDED ( t_Result ) )
  3059. {
  3060. IWbemServices *t_FullService = NULL ;
  3061. t_Result = t_SubSystem->GetWmiService (
  3062. Direct_GetNamespacePath () ,
  3063. ( const BSTR ) a_User ,
  3064. ( const BSTR ) a_Locale ,
  3065. t_FullService
  3066. ) ;
  3067. if ( SUCCEEDED ( t_Result ) )
  3068. {
  3069. #ifdef INTERNAL_IDENTIFY
  3070. CInterceptor_IWbemServices_Stub *t_Stub = new CInterceptor_IWbemServices_Stub (
  3071. NULL ,
  3072. m_Allocator ,
  3073. t_FullService
  3074. ) ;
  3075. #else
  3076. CInterceptor_IWbemServices_Interceptor *t_Stub = new CInterceptor_IWbemServices_Interceptor (
  3077. m_Allocator ,
  3078. t_FullService
  3079. ) ;
  3080. #endif
  3081. if ( t_Stub )
  3082. {
  3083. t_Stub->AddRef () ;
  3084. t_Result = t_Stub->ServiceInitialize () ;
  3085. if ( SUCCEEDED ( t_Result ) )
  3086. {
  3087. CServerObject_DynamicPropertyProviderResolver *t_Resolver = new CServerObject_DynamicPropertyProviderResolver (
  3088. m_Allocator ,
  3089. this ,
  3090. t_Stub
  3091. ) ;
  3092. if ( t_Resolver )
  3093. {
  3094. t_Resolver->AddRef () ;
  3095. wchar_t *t_NamespacePath = NULL ;
  3096. t_Result = ProviderSubSystem_Common_Globals :: GetNamespacePath (
  3097. Direct_GetNamespacePath () ,
  3098. t_NamespacePath
  3099. ) ;
  3100. if ( SUCCEEDED ( t_Result ) )
  3101. {
  3102. IWbemProviderInit *t_ProviderInit = NULL ;
  3103. t_Result = t_Resolver->QueryInterface ( IID_IWbemProviderInit , ( void ** ) & t_ProviderInit ) ;
  3104. if ( SUCCEEDED ( t_Result ) )
  3105. {
  3106. CServerObject_ProviderInitSink *t_ProviderInitSink = new CServerObject_ProviderInitSink ;
  3107. if ( t_ProviderInitSink )
  3108. {
  3109. t_ProviderInitSink->AddRef () ;
  3110. t_Result = t_ProviderInitSink->SinkInitialize () ;
  3111. if ( SUCCEEDED ( t_Result ) )
  3112. {
  3113. CInterceptor_IWbemProviderInitSink *t_Sink = new CInterceptor_IWbemProviderInitSink ( t_ProviderInitSink ) ;
  3114. if ( t_Sink )
  3115. {
  3116. t_Sink->AddRef () ;
  3117. t_Result = t_ProviderInit->Initialize (
  3118. ( const BSTR ) a_User ,
  3119. 0 ,
  3120. ( const BSTR ) t_NamespacePath ,
  3121. ( const BSTR ) a_Locale ,
  3122. t_Stub ,
  3123. a_Context ,
  3124. t_Sink
  3125. ) ;
  3126. if ( SUCCEEDED ( t_Result ) )
  3127. {
  3128. t_ProviderInitSink->Wait () ;
  3129. t_Result = t_ProviderInitSink->GetResult () ;
  3130. if ( SUCCEEDED ( t_Result ) )
  3131. {
  3132. t_Result = t_Resolver->QueryInterface ( a_RIID , a_Interface ) ;
  3133. }
  3134. }
  3135. t_Sink->Release () ;
  3136. }
  3137. else
  3138. {
  3139. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3140. }
  3141. }
  3142. t_ProviderInitSink->Release () ;
  3143. }
  3144. else
  3145. {
  3146. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3147. }
  3148. t_ProviderInit->Release () ;
  3149. }
  3150. else
  3151. {
  3152. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3153. }
  3154. delete [] t_NamespacePath ;
  3155. }
  3156. t_Resolver->Release () ;
  3157. }
  3158. else
  3159. {
  3160. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3161. }
  3162. }
  3163. t_Stub->Release () ;
  3164. }
  3165. else
  3166. {
  3167. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3168. }
  3169. t_FullService->Release () ;
  3170. }
  3171. t_SubSystem->Release () ;
  3172. }
  3173. }
  3174. catch ( Wmi_Structured_Exception t_StructuredException )
  3175. {
  3176. t_Result = WBEM_E_CRITICAL_ERROR ;
  3177. }
  3178. return t_Result ;
  3179. }
  3180. /******************************************************************************
  3181. *
  3182. * Name:
  3183. *
  3184. *
  3185. * Description:
  3186. *
  3187. *
  3188. *****************************************************************************/
  3189. HRESULT CServerObject_BindingFactory :: Get (
  3190. IWbemServices *a_Service ,
  3191. long a_Flags ,
  3192. IWbemContext *a_Context ,
  3193. LPCWSTR a_Class ,
  3194. LPCWSTR a_Path ,
  3195. IWbemObjectSink *a_Sink
  3196. )
  3197. {
  3198. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  3199. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  3200. #endif
  3201. HRESULT t_Result = S_OK ;
  3202. wchar_t *t_Locale = NULL ;
  3203. wchar_t *t_User = NULL ;
  3204. wchar_t *t_Namespace = NULL ;
  3205. GUID *t_TransactionIdentifier = NULL ;
  3206. wchar_t *t_Provider = NULL ;
  3207. wchar_t *t_HostingGroup = NULL ;
  3208. DWORD t_HostingSpecification = 0 ;
  3209. try
  3210. {
  3211. if ( wbem_wcsicmp ( a_Class , L"Msft_Providers" ) == 0 )
  3212. {
  3213. IWbemPath *t_PathObject = NULL ;
  3214. t_Result = CoCreateInstance (
  3215. CLSID_WbemDefPath ,
  3216. NULL ,
  3217. CLSCTX_INPROC_SERVER ,
  3218. IID_IWbemPath ,
  3219. ( void ** ) & t_PathObject
  3220. ) ;
  3221. if ( SUCCEEDED ( t_Result ) )
  3222. {
  3223. t_Result = t_PathObject->SetText ( WBEMPATH_CREATE_ACCEPT_ALL , a_Path ) ;
  3224. if ( SUCCEEDED ( t_Result ) )
  3225. {
  3226. IWbemPathKeyList *t_Keys = NULL ;
  3227. t_Result = t_PathObject->GetKeyList (
  3228. & t_Keys
  3229. ) ;
  3230. if ( SUCCEEDED ( t_Result ) )
  3231. {
  3232. ULONG t_KeyCount = 0 ;
  3233. t_Result = t_Keys->GetCount (
  3234. & t_KeyCount
  3235. ) ;
  3236. if ( SUCCEEDED ( t_Result ) )
  3237. {
  3238. if ( t_KeyCount == 7 )
  3239. {
  3240. for ( ULONG t_Index = 0 ; ( t_Index < t_KeyCount ) && SUCCEEDED ( t_Result ) ; t_Index ++ )
  3241. {
  3242. wchar_t t_Key [ 32 ] ;
  3243. ULONG t_KeyLength = 32 ;
  3244. ULONG t_KeyValueLength = 0 ;
  3245. ULONG t_KeyType = 0 ;
  3246. t_Result = t_Keys->GetKey (
  3247. t_Index ,
  3248. 0 ,
  3249. & t_KeyLength ,
  3250. t_Key ,
  3251. & t_KeyValueLength ,
  3252. NULL ,
  3253. & t_KeyType
  3254. ) ;
  3255. if ( SUCCEEDED ( t_Result ) )
  3256. {
  3257. if ( t_KeyType == CIM_STRING )
  3258. {
  3259. wchar_t *t_KeyValue = new wchar_t [ t_KeyValueLength ] ;
  3260. if ( t_KeyValue )
  3261. {
  3262. t_Result = t_Keys->GetKey (
  3263. t_Index ,
  3264. 0 ,
  3265. & t_KeyLength ,
  3266. t_Key ,
  3267. & t_KeyValueLength ,
  3268. t_KeyValue ,
  3269. & t_KeyType
  3270. ) ;
  3271. if ( SUCCEEDED ( t_Result ) )
  3272. {
  3273. if ( wbem_wcsicmp ( L"Namespace" , t_Key ) == 0 )
  3274. {
  3275. t_Namespace = t_KeyValue ;
  3276. }
  3277. else if ( wbem_wcsicmp ( L"Provider" , t_Key ) == 0 )
  3278. {
  3279. t_Provider = t_KeyValue ;
  3280. }
  3281. else if ( wbem_wcsicmp ( L"HostingGroup" , t_Key ) == 0 )
  3282. {
  3283. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  3284. {
  3285. t_HostingGroup = t_KeyValue ;
  3286. }
  3287. else
  3288. {
  3289. delete [] t_KeyValue ;
  3290. }
  3291. }
  3292. else if ( wbem_wcsicmp ( L"Locale" , t_Key ) == 0 )
  3293. {
  3294. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  3295. {
  3296. t_Locale = t_KeyValue ;
  3297. }
  3298. else
  3299. {
  3300. delete [] t_KeyValue ;
  3301. }
  3302. }
  3303. else if ( wbem_wcsicmp ( L"User" , t_Key ) == 0 )
  3304. {
  3305. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  3306. {
  3307. t_User = t_KeyValue ;
  3308. }
  3309. else
  3310. {
  3311. delete [] t_KeyValue ;
  3312. }
  3313. }
  3314. else if ( wbem_wcsicmp ( L"TransactionIdentifier" , t_Key ) == 0 )
  3315. {
  3316. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  3317. {
  3318. t_TransactionIdentifier = new GUID ;
  3319. if ( t_TransactionIdentifier )
  3320. {
  3321. t_Result = CLSIDFromString (
  3322. t_KeyValue ,
  3323. t_TransactionIdentifier
  3324. ) ;
  3325. if ( FAILED ( t_Result ) )
  3326. {
  3327. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  3328. }
  3329. }
  3330. }
  3331. else
  3332. {
  3333. delete [] t_KeyValue ;
  3334. }
  3335. }
  3336. else
  3337. {
  3338. delete [] t_KeyValue ;
  3339. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  3340. }
  3341. }
  3342. else
  3343. {
  3344. t_Result = WBEM_E_CRITICAL_ERROR ;
  3345. }
  3346. }
  3347. else
  3348. {
  3349. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3350. }
  3351. }
  3352. else if ( t_KeyType == CIM_SINT32 )
  3353. {
  3354. DWORD t_KeyValue = 0 ;
  3355. t_Result = t_Keys->GetKey (
  3356. t_Index ,
  3357. 0 ,
  3358. & t_KeyLength ,
  3359. t_Key ,
  3360. & t_KeyValueLength ,
  3361. & t_KeyValue ,
  3362. & t_KeyType
  3363. ) ;
  3364. if ( SUCCEEDED ( t_Result ) )
  3365. {
  3366. if ( wbem_wcsicmp ( L"HostingSpecification" , t_Key ) == 0 )
  3367. {
  3368. t_HostingSpecification = t_KeyValue ;
  3369. }
  3370. else
  3371. {
  3372. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  3373. }
  3374. }
  3375. else
  3376. {
  3377. t_Result = WBEM_E_CRITICAL_ERROR ;
  3378. }
  3379. }
  3380. else
  3381. {
  3382. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  3383. }
  3384. }
  3385. else
  3386. {
  3387. t_Result = WBEM_E_CRITICAL_ERROR ;
  3388. }
  3389. }
  3390. }
  3391. else
  3392. {
  3393. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  3394. }
  3395. }
  3396. t_Keys->Release();
  3397. }
  3398. }
  3399. else
  3400. {
  3401. t_Result = WBEM_E_CRITICAL_ERROR ;
  3402. }
  3403. t_PathObject->Release () ;
  3404. }
  3405. else
  3406. {
  3407. t_Result = WBEM_E_CRITICAL_ERROR ;
  3408. }
  3409. if ( SUCCEEDED ( t_Result ) )
  3410. {
  3411. ProviderCacheKey t_Key (
  3412. t_Provider ,
  3413. t_HostingSpecification ,
  3414. t_HostingGroup ,
  3415. true ,
  3416. t_TransactionIdentifier ,
  3417. t_User ,
  3418. t_Locale
  3419. ) ;
  3420. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  3421. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  3422. WmiStatusCode t_StatusCode = Find ( t_Key , t_Iterator ) ;
  3423. if ( t_StatusCode == e_StatusCode_Success )
  3424. {
  3425. ServiceCacheElement *t_Service = t_Iterator.GetElement () ;
  3426. localLock.UnLock () ;
  3427. _IWmiProviderConfiguration *t_Configuration = NULL ;
  3428. t_Result = t_Service->QueryInterface ( IID__IWmiProviderConfiguration , ( void ** ) & t_Configuration ) ;
  3429. if ( SUCCEEDED ( t_Result ) )
  3430. {
  3431. _IWmiProviderInitialize *t_Initialize = NULL ;
  3432. t_Result = t_Service->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_Initialize ) ;
  3433. if ( SUCCEEDED ( t_Result ) )
  3434. {
  3435. HRESULT t_TempResult = t_Initialize->WaitProvider (
  3436. a_Context ,
  3437. DEFAULT_PROVIDER_LOAD_TIMEOUT
  3438. ) ;
  3439. if ( ( t_TempResult == S_OK ) && ( SUCCEEDED ( t_Initialize->GetInitializeResult () ) ) )
  3440. {
  3441. t_Result = t_Configuration->Get (
  3442. a_Service ,
  3443. a_Flags,
  3444. a_Context,
  3445. a_Class,
  3446. a_Path,
  3447. a_Sink
  3448. ) ;
  3449. }
  3450. else
  3451. {
  3452. t_Result = WBEM_E_NOT_FOUND ;
  3453. }
  3454. t_Initialize->Release () ;
  3455. }
  3456. t_Configuration->Release () ;
  3457. }
  3458. else
  3459. {
  3460. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  3461. }
  3462. t_Service->Release () ;
  3463. }
  3464. else
  3465. {
  3466. localLock.UnLock () ;
  3467. t_Result = WBEM_E_NOT_FOUND ;
  3468. }
  3469. }
  3470. }
  3471. else
  3472. {
  3473. t_Result = WBEM_E_INVALID_CLASS ;
  3474. }
  3475. }
  3476. catch ( Wmi_Structured_Exception t_StructuredException )
  3477. {
  3478. t_Result = WBEM_E_CRITICAL_ERROR ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  3479. }
  3480. catch ( Wmi_Heap_Exception t_HeapException )
  3481. {
  3482. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3483. }
  3484. if ( t_Locale )
  3485. {
  3486. delete [] t_Locale ;
  3487. }
  3488. if ( t_User )
  3489. {
  3490. delete [] t_User ;
  3491. }
  3492. if ( t_Namespace )
  3493. {
  3494. delete [] t_Namespace ;
  3495. }
  3496. if ( t_TransactionIdentifier )
  3497. {
  3498. delete [] t_TransactionIdentifier ;
  3499. }
  3500. if ( t_Provider )
  3501. {
  3502. delete [] t_Provider ;
  3503. }
  3504. if ( t_HostingGroup )
  3505. {
  3506. delete [] t_HostingGroup ;
  3507. }
  3508. return t_Result ;
  3509. }
  3510. /******************************************************************************
  3511. *
  3512. * Name:
  3513. *
  3514. *
  3515. * Description:
  3516. *
  3517. *
  3518. *****************************************************************************/
  3519. HRESULT CServerObject_BindingFactory :: Set (
  3520. IWbemServices *a_Service ,
  3521. long a_Flags ,
  3522. IWbemContext *a_Context ,
  3523. LPCWSTR a_Provider ,
  3524. LPCWSTR a_Class ,
  3525. LPCWSTR a_Path ,
  3526. IWbemClassObject *a_OldObject ,
  3527. IWbemClassObject *a_NewObject
  3528. )
  3529. {
  3530. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  3531. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  3532. #endif
  3533. HRESULT t_Result = S_OK ;
  3534. try
  3535. {
  3536. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  3537. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  3538. GetCache ( t_Cache ) ;
  3539. if ( t_Cache->Size () )
  3540. {
  3541. _IWmiProviderCache **t_Elements = new _IWmiProviderCache * [ t_Cache->Size () ] ;
  3542. if ( t_Elements )
  3543. {
  3544. for ( ULONG t_Index = 0 ; t_Index < t_Cache->Size () ; t_Index ++ )
  3545. {
  3546. t_Elements [ t_Index ] = NULL ;
  3547. }
  3548. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  3549. ULONG t_Count = 0 ;
  3550. while ( SUCCEEDED ( t_Result ) && ( ! t_Iterator.Null () ) )
  3551. {
  3552. try
  3553. {
  3554. ProviderCacheKey t_Key = t_Iterator.GetKey () ;
  3555. ServiceCacheElement *t_Element = t_Iterator.GetElement () ;
  3556. t_Iterator.Increment () ;
  3557. if ( t_Key.m_Provider && ( wbem_wcsicmp ( a_Provider , t_Key.m_Provider ) == 0 ) )
  3558. {
  3559. t_Result = t_Element->QueryInterface (
  3560. IID__IWmiProviderCache ,
  3561. ( void ** ) & t_Elements [ t_Count ]
  3562. ) ;
  3563. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Shutdown ( t_Key ) ;
  3564. }
  3565. t_Count ++ ;
  3566. }
  3567. catch ( Wmi_Heap_Exception &a_Exception )
  3568. {
  3569. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3570. }
  3571. catch ( ... )
  3572. {
  3573. t_Result = WBEM_E_CRITICAL_ERROR ;
  3574. }
  3575. }
  3576. localLock.UnLock () ;
  3577. for ( t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  3578. {
  3579. if ( t_Elements [ t_Index ] )
  3580. {
  3581. t_Result = t_Elements [ t_Index ]->ForceReload () ;
  3582. t_Elements [ t_Index ]->Release () ;
  3583. }
  3584. }
  3585. delete [] t_Elements ;
  3586. }
  3587. else
  3588. {
  3589. localLock.UnLock () ;
  3590. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3591. }
  3592. localLock.Lock () ;
  3593. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  3594. while ( SUCCEEDED ( t_Result ) && ( ! t_Iterator.Null () ) )
  3595. {
  3596. try
  3597. {
  3598. ProviderCacheKey t_Key = t_Iterator.GetKey () ;
  3599. t_Iterator.Increment () ;
  3600. if ( t_Key.m_Provider == NULL )
  3601. {
  3602. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Shutdown ( t_Key ) ;
  3603. }
  3604. }
  3605. catch ( Wmi_Heap_Exception &a_Exception )
  3606. {
  3607. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3608. }
  3609. catch ( ... )
  3610. {
  3611. t_Result = WBEM_E_CRITICAL_ERROR ;
  3612. }
  3613. }
  3614. }
  3615. localLock.UnLock () ;
  3616. if ( a_OldObject )
  3617. {
  3618. GUID t_Clsid ;
  3619. VARIANT t_Variant ;
  3620. VariantInit ( & t_Variant ) ;
  3621. LONG t_VarType = 0 ;
  3622. LONG t_Flavour = 0 ;
  3623. t_Result = a_OldObject->Get ( L"Clsid" , 0 , & t_Variant , & t_VarType , & t_Flavour ) ;
  3624. if ( SUCCEEDED ( t_Result ) )
  3625. {
  3626. if ( t_Variant.vt == VT_BSTR )
  3627. {
  3628. t_Result = CLSIDFromString ( t_Variant.bstrVal , & t_Clsid ) ;
  3629. if ( SUCCEEDED ( t_Result ) )
  3630. {
  3631. ProviderSubSystem_Globals :: DeleteGuidTag ( t_Clsid ) ;
  3632. }
  3633. }
  3634. VariantClear ( & t_Variant ) ;
  3635. }
  3636. }
  3637. }
  3638. catch ( Wmi_Structured_Exception t_StructuredException )
  3639. {
  3640. t_Result = WBEM_E_CRITICAL_ERROR ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  3641. }
  3642. return t_Result ;
  3643. }
  3644. /******************************************************************************
  3645. *
  3646. * Name:
  3647. *
  3648. *
  3649. * Description:
  3650. *
  3651. *
  3652. *****************************************************************************/
  3653. HRESULT CServerObject_BindingFactory :: Deleted (
  3654. IWbemServices *a_Service ,
  3655. long a_Flags ,
  3656. IWbemContext *a_Context ,
  3657. LPCWSTR a_Provider ,
  3658. LPCWSTR a_Class ,
  3659. LPCWSTR a_Path ,
  3660. IWbemClassObject *a_Object
  3661. )
  3662. {
  3663. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  3664. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  3665. #endif
  3666. HRESULT t_Result = S_OK ;
  3667. try
  3668. {
  3669. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  3670. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  3671. GetCache ( t_Cache ) ;
  3672. if ( t_Cache->Size () )
  3673. {
  3674. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  3675. while ( SUCCEEDED ( t_Result ) && ( ! t_Iterator.Null () ) )
  3676. {
  3677. try
  3678. {
  3679. ProviderCacheKey t_Key = t_Iterator.GetKey () ;
  3680. t_Iterator.Increment () ;
  3681. if ( t_Key.m_Provider && (wbem_wcsicmp ( a_Provider , t_Key.m_Provider ) == 0 ) )
  3682. {
  3683. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Shutdown ( t_Key ) ;
  3684. }
  3685. }
  3686. catch ( Wmi_Heap_Exception &a_Exception )
  3687. {
  3688. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3689. }
  3690. catch ( ... )
  3691. {
  3692. t_Result = WBEM_E_CRITICAL_ERROR ;
  3693. }
  3694. }
  3695. }
  3696. localLock.UnLock () ;
  3697. GUID t_Clsid ;
  3698. VARIANT t_Variant ;
  3699. VariantInit ( & t_Variant ) ;
  3700. LONG t_VarType = 0 ;
  3701. LONG t_Flavour = 0 ;
  3702. t_Result = a_Object->Get ( L"Clsid" , 0 , & t_Variant , & t_VarType , & t_Flavour ) ;
  3703. if ( SUCCEEDED ( t_Result ) )
  3704. {
  3705. if ( t_Variant.vt == VT_BSTR )
  3706. {
  3707. t_Result = CLSIDFromString ( t_Variant.bstrVal , & t_Clsid ) ;
  3708. if ( SUCCEEDED ( t_Result ) )
  3709. {
  3710. ProviderSubSystem_Globals :: DeleteGuidTag ( t_Clsid ) ;
  3711. }
  3712. }
  3713. VariantClear ( & t_Variant ) ;
  3714. }
  3715. }
  3716. catch ( Wmi_Structured_Exception t_StructuredException )
  3717. {
  3718. t_Result = WBEM_E_CRITICAL_ERROR ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  3719. }
  3720. return t_Result ;
  3721. }
  3722. /******************************************************************************
  3723. *
  3724. * Name:
  3725. *
  3726. *
  3727. * Description:
  3728. *
  3729. *
  3730. *****************************************************************************/
  3731. HRESULT CServerObject_BindingFactory :: Enumerate (
  3732. IWbemServices *a_Service ,
  3733. long a_Flags ,
  3734. IWbemContext *a_Context ,
  3735. LPCWSTR a_Class ,
  3736. IWbemObjectSink *a_Sink
  3737. )
  3738. {
  3739. HRESULT t_Result = S_OK ;
  3740. if ( wbem_wcsicmp ( a_Class , L"Msft_Providers" ) == 0 )
  3741. {
  3742. AutoLockGuard<CServerObject_BindingFactory> localLock(*this);
  3743. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  3744. GetCache ( t_Cache ) ;
  3745. if ( t_Cache->Size () )
  3746. {
  3747. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  3748. _IWmiProviderConfiguration **t_ControllerElements = new _IWmiProviderConfiguration * [ t_Cache->Size () ] ;
  3749. if ( t_ControllerElements )
  3750. {
  3751. ULONG t_Count = 0 ;
  3752. while ( ! t_Iterator.Null () )
  3753. {
  3754. HRESULT t_Result = t_Iterator.GetElement ()->QueryInterface ( IID__IWmiProviderConfiguration , ( void ** ) & t_ControllerElements [ t_Count ] ) ;
  3755. t_Iterator.Increment () ;
  3756. t_Count ++ ;
  3757. }
  3758. localLock.UnLock () ;
  3759. try
  3760. {
  3761. BindingFactoryCacheKey t_Key = BindingFactoryCacheElement :: GetKey () ;
  3762. VARIANT t_Variant ;
  3763. VariantInit ( & t_Variant ) ;
  3764. t_Variant.vt = VT_BSTR ;
  3765. t_Variant.bstrVal = SysAllocString ( t_Key.m_Namespace ) ;
  3766. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  3767. {
  3768. if ( t_ControllerElements [ t_Index ] )
  3769. {
  3770. _IWmiProviderInitialize *t_Initialize = NULL ;
  3771. t_Result = t_ControllerElements [ t_Index ]->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_Initialize ) ;
  3772. if ( SUCCEEDED ( t_Result ) )
  3773. {
  3774. HRESULT t_TempResult = t_Initialize->WaitProvider (
  3775. a_Context ,
  3776. DEFAULT_PROVIDER_LOAD_TIMEOUT
  3777. ) ;
  3778. if ( ( t_TempResult == S_OK ) && ( SUCCEEDED ( t_Initialize->GetInitializeResult () ) ) )
  3779. {
  3780. CWaitingObjectSink *t_Sink = new CWaitingObjectSink ( m_Allocator ) ;
  3781. if ( t_Sink )
  3782. {
  3783. t_Sink->AddRef () ;
  3784. t_Result = t_Sink->SinkInitialize () ;
  3785. if ( SUCCEEDED ( t_Result ) )
  3786. {
  3787. t_Result = t_ControllerElements [ t_Index ]->Enumerate (
  3788. a_Service ,
  3789. a_Flags,
  3790. a_Context,
  3791. a_Class,
  3792. t_Sink
  3793. ) ;
  3794. t_Result = t_Sink->Wait ( INFINITE ) ;
  3795. if ( SUCCEEDED ( t_Result ) )
  3796. {
  3797. t_Result = t_Sink->GetResult () ;
  3798. if ( FAILED ( t_Result ) )
  3799. {
  3800. }
  3801. }
  3802. WmiQueue <IWbemClassObject *,8> &t_Queue = t_Sink->GetQueue () ;
  3803. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  3804. IWbemClassObject *t_Object = NULL ;
  3805. while ( ( t_StatusCode = t_Queue.Top ( t_Object ) ) == e_StatusCode_Success )
  3806. {
  3807. if ( SUCCEEDED ( t_Result ) )
  3808. {
  3809. t_Object->Put ( L"Namespace" , 0 , & t_Variant , 0 ) ;
  3810. a_Sink->Indicate ( 1, & t_Object ) ;
  3811. }
  3812. t_Object->Release () ;
  3813. t_StatusCode = t_Queue.DeQueue () ;
  3814. }
  3815. }
  3816. t_Sink->Release () ;
  3817. }
  3818. else
  3819. {
  3820. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3821. }
  3822. }
  3823. t_Initialize->Release () ;
  3824. }
  3825. t_ControllerElements [ t_Index ]->Release () ;
  3826. }
  3827. }
  3828. VariantClear ( & t_Variant ) ;
  3829. }
  3830. catch ( Wmi_Heap_Exception &a_Exception )
  3831. {
  3832. t_Result = WBEM_E_OUT_OF_MEMORY ;
  3833. }
  3834. catch ( ... )
  3835. {
  3836. t_Result = WBEM_E_CRITICAL_ERROR ;
  3837. }
  3838. delete [] t_ControllerElements ;
  3839. }
  3840. else
  3841. {
  3842. localLock.UnLock () ;
  3843. }
  3844. }
  3845. else
  3846. {
  3847. localLock.UnLock () ;
  3848. }
  3849. }
  3850. return t_Result ;
  3851. }
  3852. /******************************************************************************
  3853. *
  3854. * Name:
  3855. *
  3856. *
  3857. * Description:
  3858. *
  3859. *
  3860. *****************************************************************************/
  3861. HRESULT CServerObject_BindingFactory :: Shutdown (
  3862. IWbemServices *a_Service ,
  3863. long a_Flags ,
  3864. IWbemContext *a_Context ,
  3865. LPCWSTR a_Provider ,
  3866. ULONG a_MilliSeconds
  3867. )
  3868. {
  3869. return S_OK ;
  3870. }
  3871. /******************************************************************************
  3872. *
  3873. * Name:
  3874. *
  3875. *
  3876. * Description:
  3877. *
  3878. *
  3879. *****************************************************************************/
  3880. HRESULT CServerObject_BindingFactory :: Call (
  3881. IWbemServices *a_Service ,
  3882. long a_Flags ,
  3883. IWbemContext *a_Context ,
  3884. LPCWSTR a_Class ,
  3885. LPCWSTR a_Path ,
  3886. LPCWSTR a_Method ,
  3887. IWbemClassObject *a_InParams ,
  3888. IWbemObjectSink *a_Sink
  3889. )
  3890. {
  3891. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  3892. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  3893. #endif
  3894. HRESULT t_Result = S_OK ;
  3895. try
  3896. {
  3897. if ( wbem_wcsicmp ( a_Class , L"Msft_Providers" ) == 0 )
  3898. {
  3899. wchar_t *t_Locale = NULL ;
  3900. wchar_t *t_User = NULL ;
  3901. wchar_t *t_Namespace = NULL ;
  3902. GUID *t_TransactionIdentifier = NULL ;
  3903. wchar_t *t_HostingGroup = NULL ;
  3904. wchar_t *t_Provider = NULL ;
  3905. DWORD t_HostingSpecification = 0 ;
  3906. IWbemPath *t_PathObject = NULL ;
  3907. t_Result = CoCreateInstance (
  3908. CLSID_WbemDefPath ,
  3909. NULL ,
  3910. CLSCTX_INPROC_SERVER ,
  3911. IID_IWbemPath ,
  3912. ( void ** ) & t_PathObject
  3913. ) ;
  3914. if ( SUCCEEDED ( t_Result ) )
  3915. {
  3916. t_Result = t_PathObject->SetText ( WBEMPATH_CREATE_ACCEPT_ALL , a_Path ) ;
  3917. if ( SUCCEEDED ( t_Result ) )
  3918. {
  3919. IWbemPathKeyList *t_Keys = NULL ;
  3920. t_Result = t_PathObject->GetKeyList (
  3921. & t_Keys
  3922. ) ;
  3923. if ( SUCCEEDED ( t_Result ) )
  3924. {
  3925. ULONG t_KeyCount = 0 ;
  3926. t_Result = t_Keys->GetCount (
  3927. & t_KeyCount
  3928. ) ;
  3929. if ( SUCCEEDED ( t_Result ) )
  3930. {
  3931. if ( t_KeyCount == 7 )
  3932. {
  3933. for ( ULONG t_Index = 0 ; ( t_Index < t_KeyCount ) && SUCCEEDED ( t_Result ) ; t_Index ++ )
  3934. {
  3935. wchar_t t_Key [ 32 ] ;
  3936. ULONG t_KeyLength = 32 ;
  3937. ULONG t_KeyValueLength = 0 ;
  3938. ULONG t_KeyType = 0 ;
  3939. t_Result = t_Keys->GetKey (
  3940. t_Index ,
  3941. 0 ,
  3942. & t_KeyLength ,
  3943. t_Key ,
  3944. & t_KeyValueLength ,
  3945. NULL ,
  3946. & t_KeyType
  3947. ) ;
  3948. if ( SUCCEEDED ( t_Result ) )
  3949. {
  3950. if ( t_KeyType == CIM_STRING )
  3951. {
  3952. wchar_t *t_KeyValue = new wchar_t [ t_KeyValueLength ] ;
  3953. if ( t_KeyValue )
  3954. {
  3955. t_Result = t_Keys->GetKey (
  3956. t_Index ,
  3957. 0 ,
  3958. & t_KeyLength ,
  3959. t_Key ,
  3960. & t_KeyValueLength ,
  3961. t_KeyValue ,
  3962. & t_KeyType
  3963. ) ;
  3964. if ( SUCCEEDED ( t_Result ) )
  3965. {
  3966. if ( wbem_wcsicmp ( L"Namespace" , t_Key ) == 0 )
  3967. {
  3968. t_Namespace = t_KeyValue ;
  3969. }
  3970. else if ( wbem_wcsicmp ( L"Provider" , t_Key ) == 0 )
  3971. {
  3972. t_Provider = t_KeyValue ;
  3973. }
  3974. else if ( wbem_wcsicmp ( L"HostingGroup" , t_Key ) == 0 )
  3975. {
  3976. t_HostingGroup = t_KeyValue ;
  3977. }
  3978. else if ( wbem_wcsicmp ( L"Locale" , t_Key ) == 0 )
  3979. {
  3980. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  3981. {
  3982. t_Locale = t_KeyValue ;
  3983. }
  3984. else
  3985. {
  3986. delete [] t_KeyValue ;
  3987. }
  3988. }
  3989. else if ( wbem_wcsicmp ( L"User" , t_Key ) == 0 )
  3990. {
  3991. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  3992. {
  3993. t_User = t_KeyValue ;
  3994. }
  3995. else
  3996. {
  3997. delete [] t_KeyValue ;
  3998. }
  3999. }
  4000. else if ( wbem_wcsicmp ( L"TransactionIdentifier" , t_Key ) == 0 )
  4001. {
  4002. if ( wbem_wcsicmp ( t_KeyValue , L"" ) != 0 )
  4003. {
  4004. t_TransactionIdentifier = new GUID ;
  4005. if ( t_TransactionIdentifier )
  4006. {
  4007. t_Result = CLSIDFromString (
  4008. t_KeyValue ,
  4009. t_TransactionIdentifier
  4010. ) ;
  4011. if ( FAILED ( t_Result ) )
  4012. {
  4013. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  4014. }
  4015. }
  4016. }
  4017. else
  4018. {
  4019. delete [] t_KeyValue ;
  4020. }
  4021. }
  4022. else
  4023. {
  4024. delete [] t_KeyValue ;
  4025. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  4026. }
  4027. }
  4028. else
  4029. {
  4030. t_Result = WBEM_E_CRITICAL_ERROR ;
  4031. }
  4032. }
  4033. else
  4034. {
  4035. t_Result = WBEM_E_OUT_OF_MEMORY ;
  4036. }
  4037. }
  4038. else if ( t_KeyType == CIM_SINT32 )
  4039. {
  4040. DWORD t_KeyValue = 0 ;
  4041. t_Result = t_Keys->GetKey (
  4042. t_Index ,
  4043. 0 ,
  4044. & t_KeyLength ,
  4045. t_Key ,
  4046. & t_KeyValueLength ,
  4047. & t_KeyValue ,
  4048. & t_KeyType
  4049. ) ;
  4050. if ( SUCCEEDED ( t_Result ) )
  4051. {
  4052. if ( wbem_wcsicmp ( L"HostingSpecification" , t_Key ) == 0 )
  4053. {
  4054. t_HostingSpecification = t_KeyValue ;
  4055. }
  4056. else
  4057. {
  4058. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  4059. }
  4060. }
  4061. else
  4062. {
  4063. t_Result = WBEM_E_CRITICAL_ERROR ;
  4064. }
  4065. }
  4066. else
  4067. {
  4068. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  4069. }
  4070. }
  4071. else
  4072. {
  4073. t_Result = WBEM_E_CRITICAL_ERROR ;
  4074. }
  4075. }
  4076. }
  4077. else
  4078. {
  4079. t_Result = WBEM_E_INVALID_OBJECT_PATH ;
  4080. }
  4081. }
  4082. t_Keys->Release();
  4083. }
  4084. }
  4085. else
  4086. {
  4087. t_Result = WBEM_E_CRITICAL_ERROR ;
  4088. }
  4089. t_PathObject->Release () ;
  4090. }
  4091. else
  4092. {
  4093. t_Result = WBEM_E_CRITICAL_ERROR ;
  4094. }
  4095. if ( SUCCEEDED ( t_Result ) )
  4096. {
  4097. try
  4098. {
  4099. ProviderCacheKey t_Key (
  4100. t_Provider ,
  4101. t_HostingSpecification ,
  4102. t_HostingGroup ,
  4103. true ,
  4104. t_TransactionIdentifier ,
  4105. t_User ,
  4106. t_Locale
  4107. ) ;
  4108. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator ;
  4109. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  4110. WmiStatusCode t_StatusCode = Find ( t_Key , t_Iterator ) ;
  4111. if ( t_StatusCode == e_StatusCode_Success )
  4112. {
  4113. ServiceCacheElement *t_Service = t_Iterator.GetElement () ;
  4114. if ( wbem_wcsicmp ( a_Method , L"UnLoad" ) == 0 )
  4115. {
  4116. localLock.UnLock () ;
  4117. _IWmiProviderLoad *t_Load = NULL ;
  4118. t_Result = t_Service->QueryInterface ( IID__IWmiProviderLoad , ( void ** ) & t_Load ) ;
  4119. if ( SUCCEEDED ( t_Result ) )
  4120. {
  4121. WmiStatusCode t_StatusCode = CWbemGlobal_IWmiProviderController :: Shutdown ( t_Key ) ;
  4122. t_Result = t_Load->Unload (
  4123. 0 ,
  4124. a_Context
  4125. ) ;
  4126. t_Load->Release () ;
  4127. }
  4128. else
  4129. {
  4130. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  4131. }
  4132. }
  4133. else if ( ( wbem_wcsicmp ( a_Method , L"Suspend" ) == 0 ) || ( wbem_wcsicmp ( a_Method , L"Resume" ) == 0 ) )
  4134. {
  4135. localLock.UnLock () ;
  4136. _IWmiProviderConfiguration *t_Configuration = NULL ;
  4137. t_Result = t_Service->QueryInterface ( IID__IWmiProviderConfiguration , ( void ** ) & t_Configuration ) ;
  4138. if ( SUCCEEDED ( t_Result ) )
  4139. {
  4140. _IWmiProviderInitialize *t_Initialize = NULL ;
  4141. t_Result = t_Service->QueryInterface ( IID__IWmiProviderInitialize , ( void ** ) & t_Initialize ) ;
  4142. if ( SUCCEEDED ( t_Result ) )
  4143. {
  4144. HRESULT t_TempResult = t_Initialize->WaitProvider (
  4145. a_Context ,
  4146. DEFAULT_PROVIDER_LOAD_TIMEOUT
  4147. ) ;
  4148. if ( ( t_TempResult == S_OK ) && ( SUCCEEDED ( t_Initialize->GetInitializeResult () ) ) )
  4149. {
  4150. t_Result = t_Configuration->Call (
  4151. a_Service ,
  4152. a_Flags,
  4153. a_Context,
  4154. a_Class,
  4155. a_Path,
  4156. a_Method,
  4157. a_InParams,
  4158. a_Sink
  4159. ) ;
  4160. }
  4161. else
  4162. {
  4163. t_Result = WBEM_E_NOT_FOUND ;
  4164. }
  4165. t_Initialize->Release () ;
  4166. }
  4167. t_Configuration->Release () ;
  4168. }
  4169. else
  4170. {
  4171. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  4172. }
  4173. }
  4174. else
  4175. {
  4176. localLock.UnLock () ;
  4177. }
  4178. t_Service->Release () ;
  4179. }
  4180. else
  4181. {
  4182. localLock.UnLock () ;
  4183. t_Result = WBEM_E_NOT_FOUND ;
  4184. }
  4185. }
  4186. catch ( Wmi_Heap_Exception &a_Exception )
  4187. {
  4188. t_Result = WBEM_E_OUT_OF_MEMORY ;
  4189. }
  4190. catch ( ... )
  4191. {
  4192. t_Result = WBEM_E_CRITICAL_ERROR ;
  4193. }
  4194. }
  4195. if ( t_Locale )
  4196. {
  4197. delete [] t_Locale ;
  4198. }
  4199. if ( t_User )
  4200. {
  4201. delete [] t_User ;
  4202. }
  4203. if ( t_Namespace )
  4204. {
  4205. delete [] t_Namespace ;
  4206. }
  4207. if ( t_TransactionIdentifier )
  4208. {
  4209. delete [] t_TransactionIdentifier ;
  4210. }
  4211. if ( t_Provider )
  4212. {
  4213. delete [] t_Provider ;
  4214. }
  4215. if ( t_HostingGroup )
  4216. {
  4217. delete [] t_HostingGroup ;
  4218. }
  4219. }
  4220. else
  4221. {
  4222. }
  4223. }
  4224. catch ( Wmi_Structured_Exception t_StructuredException )
  4225. {
  4226. t_Result = WBEM_E_CRITICAL_ERROR ; /* Need to make this WBEM_E_SUBSYSTEM_FAILURE */
  4227. }
  4228. return t_Result ;
  4229. }
  4230. /******************************************************************************
  4231. *
  4232. * Name:
  4233. *
  4234. *
  4235. * Description:
  4236. *
  4237. *
  4238. *****************************************************************************/
  4239. HRESULT CServerObject_BindingFactory :: Query (
  4240. IWbemServices *a_Service ,
  4241. long a_Flags ,
  4242. IWbemContext *a_Context ,
  4243. WBEM_PROVIDER_CONFIGURATION_CLASS_ID a_ClassIdentifier ,
  4244. WBEM_PROVIDER_CONFIGURATION_PROPERTY_ID a_PropertyIdentifier ,
  4245. VARIANT *a_Value
  4246. )
  4247. {
  4248. return WBEM_E_NOT_SUPPORTED ;
  4249. }
  4250. /******************************************************************************
  4251. *
  4252. * Name:
  4253. *
  4254. *
  4255. * Description:
  4256. *
  4257. *
  4258. *****************************************************************************/
  4259. HRESULT CServerObject_BindingFactory :: Shutdown (
  4260. LONG a_Flags ,
  4261. ULONG a_MaxMilliSeconds ,
  4262. IWbemContext *a_Context
  4263. )
  4264. {
  4265. #ifndef STRUCTURED_HANDLER_SET_BY_WMI
  4266. Wmi_SetStructuredExceptionHandler t_StructuredException ;
  4267. #endif
  4268. HRESULT t_Result = S_OK ;
  4269. try
  4270. {
  4271. AutoLockGuard<CServerObject_BindingFactory> localLock(*this) ;
  4272. CWbemGlobal_IWmiProviderController_Cache *t_Cache = NULL ;
  4273. GetCache ( t_Cache ) ;
  4274. if ( t_Cache->Size () )
  4275. {
  4276. IWbemShutdown **t_ShutdownElements = new IWbemShutdown * [ t_Cache->Size () ] ;
  4277. if ( t_ShutdownElements )
  4278. {
  4279. CWbemGlobal_IWmiProviderController_Cache_Iterator t_Iterator = t_Cache->Begin ();
  4280. ULONG t_Count = 0 ;
  4281. while ( ! t_Iterator.Null () )
  4282. {
  4283. t_Result = t_Iterator.GetElement ()->QueryInterface ( IID_IWbemShutdown , ( void ** ) & t_ShutdownElements [ t_Count ] ) ;
  4284. t_Iterator.Increment () ;
  4285. t_Count ++ ;
  4286. }
  4287. localLock.UnLock () ;
  4288. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  4289. {
  4290. if ( t_ShutdownElements [ t_Index ] )
  4291. {
  4292. t_Result = t_ShutdownElements [ t_Index ]->Shutdown (
  4293. a_Flags ,
  4294. a_MaxMilliSeconds ,
  4295. a_Context
  4296. ) ;
  4297. t_ShutdownElements [ t_Index ]->Release () ;
  4298. }
  4299. }
  4300. delete [] t_ShutdownElements ;
  4301. }
  4302. else
  4303. {
  4304. localLock.UnLock () ;
  4305. t_Result = WBEM_E_OUT_OF_MEMORY ;
  4306. }
  4307. }
  4308. else
  4309. {
  4310. localLock.UnLock () ;
  4311. }
  4312. CWbemGlobal_IWmiProviderController :: Shutdown () ;
  4313. localLock.Lock();
  4314. ULONG t_Count = m_SvcWrappersContainer.Size();
  4315. IUnknown ** t_ppUnks = 0;
  4316. if (t_Count) t_ppUnks = new IUnknown *[t_Count];
  4317. if (t_ppUnks)
  4318. {
  4319. for ( ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++ )
  4320. {
  4321. IUnknown * t_SvcWrap ;
  4322. WmiStatusCode t_StatusCode = m_SvcWrappersContainer.Top ( t_SvcWrap ) ;
  4323. if ( t_StatusCode == e_StatusCode_Success )
  4324. {
  4325. t_ppUnks[t_Index] = t_SvcWrap;
  4326. t_StatusCode = m_SvcWrappersContainer.DeQueue () ;
  4327. }
  4328. }
  4329. }
  4330. localLock.UnLock();
  4331. if (t_ppUnks)
  4332. {
  4333. for (ULONG t_Index = 0 ; t_Index < t_Count ; t_Index ++)
  4334. {
  4335. CoDisconnectObject(t_ppUnks[t_Index],0);
  4336. t_ppUnks[t_Index]->Release () ;
  4337. }
  4338. delete[] t_ppUnks;
  4339. }
  4340. }
  4341. catch ( Wmi_Structured_Exception t_StructuredException )
  4342. {
  4343. t_Result = WBEM_E_CRITICAL_ERROR ;
  4344. }
  4345. return t_Result ;
  4346. }
  4347. /******************************************************************************
  4348. *
  4349. * Name:
  4350. *
  4351. *
  4352. * Description:
  4353. *
  4354. *
  4355. *****************************************************************************/
  4356. WmiStatusCode CServerObject_BindingFactory :: Strobe ( ULONG &a_NextStrobeDelta )
  4357. {
  4358. return CWbemGlobal_IWmiProviderController :: Strobe ( a_NextStrobeDelta ) ;
  4359. }
  4360. /******************************************************************************
  4361. *
  4362. * Name:
  4363. *
  4364. *
  4365. * Description:
  4366. *
  4367. *
  4368. *****************************************************************************/
  4369. WmiStatusCode CServerObject_BindingFactory :: StrobeBegin ( const ULONG &a_Period )
  4370. {
  4371. ULONG t_Timeout = ProviderSubSystem_Globals :: GetStrobeThread ().GetTimeout () ;
  4372. ProviderSubSystem_Globals :: GetStrobeThread ().SetTimeout ( t_Timeout < a_Period ? t_Timeout : a_Period ) ;
  4373. return e_StatusCode_Success ;
  4374. }