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.

4693 lines
98 KiB

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