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.

1213 lines
27 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. XXXX
  5. Abstract:
  6. History:
  7. --*/
  8. #include "PreComp.h"
  9. #include <wbemint.h>
  10. #include <stdio.h>
  11. #include <NCObjApi.h>
  12. #include "Globals.h"
  13. #include "CGlobals.h"
  14. #include "ProvEvents.h"
  15. #include "ProvEvt.h"
  16. /******************************************************************************
  17. *
  18. * Name:
  19. *
  20. *
  21. * Description:
  22. *
  23. *
  24. *****************************************************************************/
  25. CEventProvider :: CEventProvider (
  26. WmiAllocator &a_Allocator ,
  27. CServerObject_ProviderEvents *a_EventRegistrar ,
  28. IUnknown *a_Unknown
  29. ) : m_EventRegistrar ( a_EventRegistrar ) ,
  30. m_Unknown ( a_Unknown ) ,
  31. m_Provider_IWbemEventProvider ( NULL ) ,
  32. m_Provider_IWbemEventProviderQuerySink ( NULL ) ,
  33. m_Provider_IWbemEventProviderSecurity ( NULL ) ,
  34. m_Provider_IWbemProviderIdentity ( NULL ) ,
  35. m_Provider_IWbemEventConsumerProvider ( NULL ) ,
  36. m_Provider_IWbemEventConsumerProviderEx ( NULL ) ,
  37. m_CoreService ( NULL ) ,
  38. m_Locale ( NULL ) ,
  39. m_User ( NULL ) ,
  40. m_Namespace ( NULL ) ,
  41. m_ReferenceCount ( 0 ) ,
  42. m_CriticalSection(NOTHROW_LOCK)
  43. {
  44. InterlockedIncrement ( & DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress ) ;
  45. if ( m_EventRegistrar )
  46. {
  47. m_EventRegistrar->InternalAddRef () ;
  48. }
  49. if ( m_Unknown )
  50. {
  51. m_Unknown->AddRef () ;
  52. HRESULT t_Result = m_Unknown->QueryInterface ( IID_IWbemEventProvider , ( void ** ) & m_Provider_IWbemEventProvider ) ;
  53. t_Result = m_Unknown->QueryInterface ( IID_IWbemEventProviderQuerySink , ( void ** ) & m_Provider_IWbemEventProviderQuerySink ) ;
  54. t_Result = m_Unknown->QueryInterface ( IID_IWbemEventProviderSecurity , ( void ** ) & m_Provider_IWbemEventProviderSecurity ) ;
  55. t_Result = m_Unknown->QueryInterface ( IID_IWbemProviderIdentity , ( void ** ) & m_Provider_IWbemProviderIdentity ) ;
  56. t_Result = m_Unknown->QueryInterface ( IID_IWbemEventConsumerProviderEx , ( void ** ) & m_Provider_IWbemEventConsumerProviderEx ) ;
  57. t_Result = m_Unknown->QueryInterface ( IID_IWbemEventConsumerProvider , ( void ** ) & m_Provider_IWbemEventConsumerProvider ) ;
  58. }
  59. }
  60. /******************************************************************************
  61. *
  62. * Name:
  63. *
  64. *
  65. * Description:
  66. *
  67. *
  68. *****************************************************************************/
  69. CEventProvider :: ~CEventProvider ()
  70. {
  71. if ( m_Namespace )
  72. {
  73. SysFreeString ( m_Namespace ) ;
  74. }
  75. if ( m_Locale )
  76. {
  77. SysFreeString ( m_Locale ) ;
  78. }
  79. if ( m_User )
  80. {
  81. SysFreeString ( m_User ) ;
  82. }
  83. if ( m_Unknown )
  84. {
  85. m_Unknown->Release () ;
  86. }
  87. if ( m_EventRegistrar )
  88. {
  89. m_EventRegistrar->InternalRelease () ;
  90. }
  91. if ( m_Provider_IWbemEventProvider )
  92. {
  93. m_Provider_IWbemEventProvider->Release () ;
  94. }
  95. if ( m_Provider_IWbemEventProviderQuerySink )
  96. {
  97. m_Provider_IWbemEventProviderQuerySink->Release () ;
  98. }
  99. if ( m_Provider_IWbemEventProviderSecurity )
  100. {
  101. m_Provider_IWbemEventProviderSecurity->Release () ;
  102. }
  103. if ( m_Provider_IWbemProviderIdentity )
  104. {
  105. m_Provider_IWbemProviderIdentity->Release () ;
  106. }
  107. if ( m_Provider_IWbemEventConsumerProviderEx )
  108. {
  109. m_Provider_IWbemEventConsumerProviderEx->Release () ;
  110. }
  111. if ( m_Provider_IWbemEventConsumerProvider )
  112. {
  113. m_Provider_IWbemEventConsumerProvider->Release () ;
  114. }
  115. if ( m_CoreService )
  116. {
  117. m_CoreService->Release () ;
  118. }
  119. InterlockedDecrement ( & DecoupledProviderSubSystem_Globals :: s_ObjectsInProgress ) ;
  120. }
  121. /******************************************************************************
  122. *
  123. * Name:
  124. *
  125. *
  126. * Description:
  127. *
  128. *
  129. *****************************************************************************/
  130. HRESULT CEventProvider :: Initialize ()
  131. {
  132. return m_CriticalSection.valid() ? S_OK : WBEM_E_OUT_OF_MEMORY ;
  133. }
  134. /******************************************************************************
  135. *
  136. * Name:
  137. *
  138. *
  139. * Description:
  140. *
  141. *
  142. *****************************************************************************/
  143. STDMETHODIMP_( ULONG ) CEventProvider :: AddRef ()
  144. {
  145. ULONG t_ReferenceCount = InterlockedIncrement ( & m_ReferenceCount ) ;
  146. return t_ReferenceCount ;
  147. }
  148. /******************************************************************************
  149. *
  150. * Name:
  151. *
  152. *
  153. * Description:
  154. *
  155. *
  156. *****************************************************************************/
  157. STDMETHODIMP_(ULONG) CEventProvider :: Release ()
  158. {
  159. ULONG t_ReferenceCount = InterlockedDecrement ( & m_ReferenceCount ) ;
  160. if ( t_ReferenceCount == 0 )
  161. {
  162. delete this ;
  163. }
  164. return t_ReferenceCount ;
  165. }
  166. /******************************************************************************
  167. *
  168. * Name:
  169. *
  170. *
  171. * Description:
  172. *
  173. *
  174. *****************************************************************************/
  175. STDMETHODIMP CEventProvider :: QueryInterface (
  176. REFIID a_Riid ,
  177. LPVOID FAR *a_Void
  178. )
  179. {
  180. *a_Void = NULL ;
  181. if ( a_Riid == IID_IUnknown )
  182. {
  183. *a_Void = ( LPVOID ) this ;
  184. }
  185. else if ( a_Riid == IID_IWbemEventProvider )
  186. {
  187. if ( m_Unknown )
  188. {
  189. if ( m_Provider_IWbemEventProvider )
  190. {
  191. *a_Void = ( LPVOID ) ( IWbemEventProvider * ) this ;
  192. }
  193. }
  194. else
  195. {
  196. *a_Void = ( LPVOID ) ( IWbemEventProvider * ) this ;
  197. }
  198. }
  199. else if ( a_Riid == IID_IWbemEventProviderQuerySink )
  200. {
  201. if ( m_Provider_IWbemEventProviderQuerySink )
  202. {
  203. *a_Void = ( LPVOID ) ( IWbemEventProviderQuerySink * ) this ;
  204. }
  205. }
  206. else if ( a_Riid == IID_IWbemEventProviderSecurity )
  207. {
  208. if ( m_Provider_IWbemEventProviderSecurity )
  209. {
  210. *a_Void = ( LPVOID ) ( IWbemEventProviderSecurity * ) this ;
  211. }
  212. }
  213. else if ( a_Riid == IID_IWbemProviderIdentity )
  214. {
  215. if ( m_Provider_IWbemProviderIdentity )
  216. {
  217. *a_Void = ( LPVOID ) ( IWbemProviderIdentity * ) this ;
  218. }
  219. }
  220. else if ( a_Riid == IID_IWbemEventConsumerProvider )
  221. {
  222. if ( m_Provider_IWbemEventConsumerProvider )
  223. {
  224. *a_Void = ( LPVOID ) ( IWbemEventConsumerProvider * ) this ;
  225. }
  226. }
  227. else if ( a_Riid == IID_IWbemEventConsumerProviderEx )
  228. {
  229. if ( m_Provider_IWbemEventConsumerProviderEx )
  230. {
  231. *a_Void = ( LPVOID ) ( IWbemEventConsumerProviderEx * ) this ;
  232. }
  233. }
  234. else if ( a_Riid == IID_IWbemProviderInit )
  235. {
  236. *a_Void = ( LPVOID ) ( IWbemProviderInit * ) this ;
  237. }
  238. else if ( a_Riid == IID_IWbemShutdown )
  239. {
  240. *a_Void = ( LPVOID ) ( IWbemShutdown * ) this ;
  241. }
  242. if ( *a_Void )
  243. {
  244. ( ( LPUNKNOWN ) *a_Void )->AddRef () ;
  245. return ResultFromScode ( S_OK ) ;
  246. }
  247. else
  248. {
  249. return ResultFromScode ( E_NOINTERFACE ) ;
  250. }
  251. }
  252. /******************************************************************************
  253. *
  254. * Name:
  255. *
  256. *
  257. * Description:
  258. *
  259. *
  260. *****************************************************************************/
  261. HRESULT CEventProvider ::ProvideEvents (
  262. IWbemObjectSink *a_Sink ,
  263. long a_Flags
  264. )
  265. {
  266. HRESULT t_Result = S_OK ;
  267. try
  268. {
  269. HRESULT t_TempResult = m_EventRegistrar->SetSink ( a_Sink ) ;
  270. if ( SUCCEEDED ( t_TempResult ) )
  271. {
  272. if ( m_Provider_IWbemEventProvider )
  273. {
  274. BOOL t_Impersonating = FALSE ;
  275. IUnknown *t_OldContext = NULL ;
  276. IServerSecurity *t_OldSecurity = NULL ;
  277. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  278. if ( SUCCEEDED ( t_Result ) )
  279. {
  280. BOOL t_Revert = FALSE ;
  281. IUnknown *t_Proxy = NULL ;
  282. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemEventProvider , m_Provider_IWbemEventProvider , t_Proxy , t_Revert ) ;
  283. if ( t_Result == WBEM_E_NOT_FOUND )
  284. {
  285. try
  286. {
  287. t_Result = m_Provider_IWbemEventProvider->ProvideEvents (
  288. a_Sink ,
  289. a_Flags
  290. ) ;
  291. }
  292. catch ( ... )
  293. {
  294. t_Result = WBEM_E_PROVIDER_FAILURE ;
  295. }
  296. }
  297. else
  298. {
  299. if ( SUCCEEDED ( t_Result ) )
  300. {
  301. IWbemEventProvider *t_Provider = ( IWbemEventProvider * ) t_Proxy ;
  302. // Set cloaking on the proxy
  303. // =========================
  304. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  305. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  306. t_Provider ,
  307. RPC_C_AUTHN_LEVEL_CONNECT ,
  308. t_ImpersonationLevel
  309. ) ;
  310. if ( SUCCEEDED ( t_Result ) )
  311. {
  312. t_Result = OS::CoImpersonateClient () ;
  313. if ( SUCCEEDED ( t_Result ) )
  314. {
  315. t_Result = t_Provider->ProvideEvents (
  316. a_Sink ,
  317. a_Flags
  318. ) ;
  319. }
  320. else
  321. {
  322. t_Result = WBEM_E_ACCESS_DENIED ;
  323. }
  324. }
  325. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  326. }
  327. }
  328. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  329. }
  330. }
  331. }
  332. }
  333. catch ( ... )
  334. {
  335. t_Result = WBEM_E_CRITICAL_ERROR ;
  336. }
  337. return t_Result ;
  338. }
  339. /******************************************************************************
  340. *
  341. * Name:
  342. *
  343. *
  344. * Description:
  345. *
  346. *
  347. *****************************************************************************/
  348. HRESULT CEventProvider ::NewQuery (
  349. unsigned long a_Id ,
  350. WBEM_WSTR a_QueryLanguage ,
  351. WBEM_WSTR a_Query
  352. )
  353. {
  354. HRESULT t_Result = S_OK ;
  355. try
  356. {
  357. if ( m_Provider_IWbemEventProviderQuerySink )
  358. {
  359. BOOL t_Impersonating = FALSE ;
  360. IUnknown *t_OldContext = NULL ;
  361. IServerSecurity *t_OldSecurity = NULL ;
  362. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  363. if ( SUCCEEDED ( t_Result ) )
  364. {
  365. BOOL t_Revert = FALSE ;
  366. IUnknown *t_Proxy = NULL ;
  367. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemEventProviderQuerySink , m_Provider_IWbemEventProviderQuerySink , t_Proxy , t_Revert ) ;
  368. if ( t_Result == WBEM_E_NOT_FOUND )
  369. {
  370. try
  371. {
  372. t_Result = m_Provider_IWbemEventProviderQuerySink->NewQuery (
  373. a_Id ,
  374. a_QueryLanguage ,
  375. a_Query
  376. ) ;
  377. }
  378. catch ( ... )
  379. {
  380. t_Result = WBEM_E_PROVIDER_FAILURE ;
  381. }
  382. }
  383. else
  384. {
  385. if ( SUCCEEDED ( t_Result ) )
  386. {
  387. IWbemEventProviderQuerySink *t_Provider = ( IWbemEventProviderQuerySink * ) t_Proxy ;
  388. // Set cloaking on the proxy
  389. // =========================
  390. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  391. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  392. t_Provider ,
  393. RPC_C_AUTHN_LEVEL_CONNECT ,
  394. t_ImpersonationLevel
  395. ) ;
  396. if ( SUCCEEDED ( t_Result ) )
  397. {
  398. t_Result = OS::CoImpersonateClient () ;
  399. if ( SUCCEEDED ( t_Result ) )
  400. {
  401. t_Result = t_Provider->NewQuery (
  402. a_Id ,
  403. a_QueryLanguage ,
  404. a_Query
  405. ) ;
  406. }
  407. else
  408. {
  409. t_Result = WBEM_E_ACCESS_DENIED ;
  410. }
  411. }
  412. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  413. }
  414. }
  415. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  416. }
  417. return t_Result ;
  418. }
  419. else
  420. {
  421. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE ;
  422. }
  423. }
  424. catch ( ... )
  425. {
  426. t_Result = WBEM_E_CRITICAL_ERROR ;
  427. }
  428. return t_Result ;
  429. }
  430. /******************************************************************************
  431. *
  432. * Name:
  433. *
  434. *
  435. * Description:
  436. *
  437. *
  438. *****************************************************************************/
  439. HRESULT CEventProvider ::CancelQuery (
  440. unsigned long a_Id
  441. )
  442. {
  443. HRESULT t_Result = S_OK ;
  444. try
  445. {
  446. if ( m_Provider_IWbemEventProviderQuerySink )
  447. {
  448. BOOL t_Impersonating = FALSE ;
  449. IUnknown *t_OldContext = NULL ;
  450. IServerSecurity *t_OldSecurity = NULL ;
  451. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  452. if ( SUCCEEDED ( t_Result ) )
  453. {
  454. BOOL t_Revert = FALSE ;
  455. IUnknown *t_Proxy = NULL ;
  456. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemEventProviderQuerySink , m_Provider_IWbemEventProviderQuerySink , t_Proxy , t_Revert ) ;
  457. if ( t_Result == WBEM_E_NOT_FOUND )
  458. {
  459. try
  460. {
  461. t_Result = m_Provider_IWbemEventProviderQuerySink->CancelQuery (
  462. a_Id
  463. ) ;
  464. }
  465. catch ( ... )
  466. {
  467. t_Result = WBEM_E_PROVIDER_FAILURE ;
  468. }
  469. }
  470. else
  471. {
  472. if ( SUCCEEDED ( t_Result ) )
  473. {
  474. IWbemEventProviderQuerySink *t_Provider = NULL ;
  475. t_Result = t_Proxy->QueryInterface ( IID_IWbemEventProviderQuerySink , ( void ** ) & t_Provider ) ;
  476. if ( SUCCEEDED ( t_Result ) )
  477. {
  478. // Set cloaking on the proxy
  479. // =========================
  480. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  481. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  482. t_Provider ,
  483. RPC_C_AUTHN_LEVEL_CONNECT ,
  484. t_ImpersonationLevel
  485. ) ;
  486. if ( SUCCEEDED ( t_Result ) )
  487. {
  488. t_Result = OS::CoImpersonateClient () ;
  489. if ( SUCCEEDED ( t_Result ) )
  490. {
  491. t_Result = t_Provider->CancelQuery (
  492. a_Id
  493. ) ;
  494. }
  495. else
  496. {
  497. t_Result = WBEM_E_ACCESS_DENIED ;
  498. }
  499. }
  500. t_Provider->Release () ;
  501. }
  502. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  503. }
  504. }
  505. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  506. }
  507. }
  508. else
  509. {
  510. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE;
  511. }
  512. }
  513. catch ( ... )
  514. {
  515. t_Result = WBEM_E_CRITICAL_ERROR ;
  516. }
  517. return t_Result ;
  518. }
  519. /******************************************************************************
  520. *
  521. * Name:
  522. *
  523. *
  524. * Description:
  525. *
  526. *
  527. *****************************************************************************/
  528. HRESULT CEventProvider ::AccessCheck (
  529. WBEM_CWSTR a_QueryLanguage ,
  530. WBEM_CWSTR a_Query ,
  531. long a_SidLength ,
  532. const BYTE *a_Sid
  533. )
  534. {
  535. HRESULT t_Result = S_OK ;
  536. try
  537. {
  538. if ( m_Provider_IWbemEventProviderSecurity )
  539. {
  540. BOOL t_Impersonating = FALSE ;
  541. IUnknown *t_OldContext = NULL ;
  542. IServerSecurity *t_OldSecurity = NULL ;
  543. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  544. if ( SUCCEEDED ( t_Result ) )
  545. {
  546. BOOL t_Revert = FALSE ;
  547. IUnknown *t_Proxy = NULL ;
  548. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemEventProviderSecurity , m_Provider_IWbemEventProviderSecurity , t_Proxy , t_Revert ) ;
  549. if ( t_Result == WBEM_E_NOT_FOUND )
  550. {
  551. try
  552. {
  553. t_Result = m_Provider_IWbemEventProviderSecurity->AccessCheck (
  554. a_QueryLanguage ,
  555. a_Query ,
  556. a_SidLength ,
  557. a_Sid
  558. ) ;
  559. }
  560. catch ( ... )
  561. {
  562. t_Result = WBEM_E_PROVIDER_FAILURE ;
  563. }
  564. }
  565. else
  566. {
  567. if ( SUCCEEDED ( t_Result ) )
  568. {
  569. IWbemEventProviderSecurity *t_Provider = ( IWbemEventProviderSecurity * ) t_Proxy ;
  570. // Set cloaking on the proxy
  571. // =========================
  572. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  573. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  574. t_Provider ,
  575. RPC_C_AUTHN_LEVEL_CONNECT ,
  576. t_ImpersonationLevel
  577. ) ;
  578. if ( SUCCEEDED ( t_Result ) )
  579. {
  580. t_Result = OS::CoImpersonateClient () ;
  581. if ( SUCCEEDED ( t_Result ) )
  582. {
  583. t_Result = t_Provider->AccessCheck (
  584. a_QueryLanguage ,
  585. a_Query ,
  586. a_SidLength ,
  587. a_Sid
  588. ) ;
  589. }
  590. else
  591. {
  592. t_Result = WBEM_E_ACCESS_DENIED ;
  593. }
  594. }
  595. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  596. }
  597. }
  598. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  599. }
  600. }
  601. else
  602. {
  603. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE;
  604. }
  605. }
  606. catch ( ... )
  607. {
  608. t_Result = WBEM_E_CRITICAL_ERROR ;
  609. }
  610. return t_Result ;
  611. }
  612. /******************************************************************************
  613. *
  614. * Name:
  615. *
  616. *
  617. * Description:
  618. *
  619. *
  620. *****************************************************************************/
  621. HRESULT CEventProvider ::SetRegistrationObject (
  622. long a_Flags ,
  623. IWbemClassObject *a_ProviderRegistration
  624. )
  625. {
  626. HRESULT t_Result = S_OK ;
  627. try
  628. {
  629. if ( m_Provider_IWbemProviderIdentity )
  630. {
  631. BOOL t_Impersonating = FALSE ;
  632. IUnknown *t_OldContext = NULL ;
  633. IServerSecurity *t_OldSecurity = NULL ;
  634. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  635. if ( SUCCEEDED ( t_Result ) )
  636. {
  637. BOOL t_Revert = FALSE ;
  638. IUnknown *t_Proxy = NULL ;
  639. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemProviderIdentity , m_Provider_IWbemProviderIdentity , t_Proxy , t_Revert ) ;
  640. if ( t_Result == WBEM_E_NOT_FOUND )
  641. {
  642. try
  643. {
  644. t_Result = m_Provider_IWbemProviderIdentity->SetRegistrationObject (
  645. a_Flags ,
  646. a_ProviderRegistration
  647. ) ;
  648. }
  649. catch ( ... )
  650. {
  651. t_Result = WBEM_E_PROVIDER_FAILURE ;
  652. }
  653. }
  654. else
  655. {
  656. if ( SUCCEEDED ( t_Result ) )
  657. {
  658. IWbemProviderIdentity *t_Provider = ( IWbemProviderIdentity * ) t_Proxy ;
  659. // Set cloaking on the proxy
  660. // =========================
  661. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  662. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  663. t_Provider ,
  664. RPC_C_AUTHN_LEVEL_CONNECT ,
  665. t_ImpersonationLevel
  666. ) ;
  667. if ( SUCCEEDED ( t_Result ) )
  668. {
  669. t_Result = OS::CoImpersonateClient () ;
  670. if ( SUCCEEDED ( t_Result ) )
  671. {
  672. t_Result = t_Provider->SetRegistrationObject (
  673. a_Flags ,
  674. a_ProviderRegistration
  675. ) ;
  676. }
  677. else
  678. {
  679. t_Result = WBEM_E_ACCESS_DENIED ;
  680. }
  681. }
  682. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  683. }
  684. }
  685. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  686. }
  687. }
  688. else
  689. {
  690. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE;
  691. }
  692. }
  693. catch ( ... )
  694. {
  695. t_Result = WBEM_E_CRITICAL_ERROR ;
  696. }
  697. return t_Result ;
  698. }
  699. /******************************************************************************
  700. *
  701. * Name:
  702. *
  703. *
  704. * Description:
  705. *
  706. *
  707. *****************************************************************************/
  708. HRESULT CEventProvider ::FindConsumer (
  709. IWbemClassObject *a_LogicalConsumer ,
  710. IWbemUnboundObjectSink **a_Consumer
  711. )
  712. {
  713. HRESULT t_Result = S_OK ;
  714. try
  715. {
  716. if ( m_Provider_IWbemEventConsumerProvider )
  717. {
  718. BOOL t_Impersonating = FALSE ;
  719. IUnknown *t_OldContext = NULL ;
  720. IServerSecurity *t_OldSecurity = NULL ;
  721. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  722. if ( SUCCEEDED ( t_Result ) )
  723. {
  724. BOOL t_Revert = FALSE ;
  725. IUnknown *t_Proxy = NULL ;
  726. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemEventConsumerProvider , m_Provider_IWbemEventConsumerProvider , t_Proxy , t_Revert ) ;
  727. if ( t_Result == WBEM_E_NOT_FOUND )
  728. {
  729. try
  730. {
  731. t_Result = m_Provider_IWbemEventConsumerProvider->FindConsumer (
  732. a_LogicalConsumer ,
  733. a_Consumer
  734. ) ;
  735. }
  736. catch ( ... )
  737. {
  738. t_Result = WBEM_E_PROVIDER_FAILURE ;
  739. }
  740. }
  741. else
  742. {
  743. if ( SUCCEEDED ( t_Result ) )
  744. {
  745. IWbemEventConsumerProvider *t_Provider = ( IWbemEventConsumerProvider * ) t_Proxy ;
  746. // Set cloaking on the proxy
  747. // =========================
  748. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  749. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  750. t_Provider ,
  751. RPC_C_AUTHN_LEVEL_CONNECT ,
  752. t_ImpersonationLevel
  753. ) ;
  754. if ( SUCCEEDED ( t_Result ) )
  755. {
  756. t_Result = OS::CoImpersonateClient () ;
  757. if ( SUCCEEDED ( t_Result ) )
  758. {
  759. t_Result = t_Provider->FindConsumer (
  760. a_LogicalConsumer ,
  761. a_Consumer
  762. ) ;
  763. }
  764. else
  765. {
  766. t_Result = WBEM_E_ACCESS_DENIED ;
  767. }
  768. }
  769. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  770. }
  771. }
  772. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  773. }
  774. }
  775. else
  776. {
  777. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE;
  778. }
  779. }
  780. catch ( ... )
  781. {
  782. t_Result = WBEM_E_CRITICAL_ERROR ;
  783. }
  784. return t_Result ;
  785. }
  786. /******************************************************************************
  787. *
  788. * Name:
  789. *
  790. *
  791. * Description:
  792. *
  793. *
  794. *****************************************************************************/
  795. HRESULT CEventProvider ::ValidateSubscription (
  796. IWbemClassObject *a_LogicalConsumer
  797. )
  798. {
  799. HRESULT t_Result = S_OK ;
  800. try
  801. {
  802. if ( m_Provider_IWbemEventConsumerProviderEx )
  803. {
  804. BOOL t_Impersonating = FALSE ;
  805. IUnknown *t_OldContext = NULL ;
  806. IServerSecurity *t_OldSecurity = NULL ;
  807. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  808. if ( SUCCEEDED ( t_Result ) )
  809. {
  810. BOOL t_Revert = FALSE ;
  811. IUnknown *t_Proxy = NULL ;
  812. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemEventConsumerProviderEx , m_Provider_IWbemEventConsumerProviderEx , t_Proxy , t_Revert ) ;
  813. if ( t_Result == WBEM_E_NOT_FOUND )
  814. {
  815. try
  816. {
  817. t_Result = m_Provider_IWbemEventConsumerProviderEx->ValidateSubscription (
  818. a_LogicalConsumer
  819. ) ;
  820. }
  821. catch ( ... )
  822. {
  823. t_Result = WBEM_E_PROVIDER_FAILURE ;
  824. }
  825. }
  826. else
  827. {
  828. if ( SUCCEEDED ( t_Result ) )
  829. {
  830. IWbemEventConsumerProviderEx *t_Provider = ( IWbemEventConsumerProviderEx * ) t_Proxy ;
  831. // Set cloaking on the proxy
  832. // =========================
  833. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  834. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  835. t_Provider ,
  836. RPC_C_AUTHN_LEVEL_CONNECT ,
  837. t_ImpersonationLevel
  838. ) ;
  839. if ( SUCCEEDED ( t_Result ) )
  840. {
  841. t_Result = OS::CoImpersonateClient () ;
  842. if ( SUCCEEDED ( t_Result ) )
  843. {
  844. t_Result = t_Provider->ValidateSubscription (
  845. a_LogicalConsumer
  846. ) ;
  847. }
  848. else
  849. {
  850. t_Result = WBEM_E_ACCESS_DENIED ;
  851. }
  852. }
  853. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  854. }
  855. }
  856. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  857. }
  858. }
  859. else
  860. {
  861. t_Result = WBEM_E_PROVIDER_NOT_CAPABLE;
  862. }
  863. }
  864. catch ( ... )
  865. {
  866. t_Result = WBEM_E_CRITICAL_ERROR ;
  867. }
  868. return t_Result ;
  869. }
  870. /******************************************************************************
  871. *
  872. * Name:
  873. *
  874. *
  875. * Description:
  876. *
  877. *
  878. *****************************************************************************/
  879. HRESULT CEventProvider :: UnRegister ()
  880. {
  881. return S_OK ;
  882. }
  883. /******************************************************************************
  884. *
  885. * Name:
  886. *
  887. *
  888. * Description:
  889. *
  890. *
  891. *****************************************************************************/
  892. HRESULT CEventProvider :: Initialize (
  893. LPWSTR a_User,
  894. LONG a_Flags,
  895. LPWSTR a_Namespace,
  896. LPWSTR a_Locale,
  897. IWbemServices *a_CoreService, // For anybody
  898. IWbemContext *a_Context,
  899. IWbemProviderInitSink *a_Sink // For init signals
  900. )
  901. {
  902. HRESULT t_Result = S_OK ;
  903. if ( a_CoreService )
  904. {
  905. m_CoreService = a_CoreService ;
  906. m_CoreService->AddRef () ;
  907. }
  908. else
  909. {
  910. t_Result = WBEM_E_INVALID_PARAMETER ;
  911. }
  912. if ( SUCCEEDED ( t_Result ) )
  913. {
  914. if ( a_User )
  915. {
  916. m_User = SysAllocString ( a_User ) ;
  917. if ( m_User == NULL )
  918. {
  919. t_Result = WBEM_E_OUT_OF_MEMORY ;
  920. }
  921. }
  922. }
  923. if ( SUCCEEDED ( t_Result ) )
  924. {
  925. if ( a_Locale )
  926. {
  927. m_Locale = SysAllocString ( a_Locale ) ;
  928. if ( m_Locale == NULL )
  929. {
  930. t_Result = WBEM_E_OUT_OF_MEMORY ;
  931. }
  932. }
  933. }
  934. if ( SUCCEEDED ( t_Result ) )
  935. {
  936. if ( a_Namespace )
  937. {
  938. m_Namespace = SysAllocString ( a_Namespace ) ;
  939. if ( m_Namespace == NULL )
  940. {
  941. t_Result = WBEM_E_OUT_OF_MEMORY ;
  942. }
  943. }
  944. }
  945. a_Sink->SetStatus ( t_Result , 0 ) ;
  946. return t_Result ;
  947. }
  948. /******************************************************************************
  949. *
  950. * Name:
  951. *
  952. *
  953. * Description:
  954. *
  955. *
  956. *****************************************************************************/
  957. HRESULT CEventProvider :: Shutdown (
  958. LONG a_Flags ,
  959. ULONG a_MaxMilliSeconds ,
  960. IWbemContext *a_Context
  961. )
  962. {
  963. HRESULT t_Result = S_OK ;
  964. IWbemShutdown *t_Shutdown = NULL ;
  965. if ( m_Unknown )
  966. {
  967. t_Result = m_Unknown->QueryInterface ( IID_IWbemShutdown , ( void ** ) & t_Shutdown ) ;
  968. if ( SUCCEEDED ( t_Result ) )
  969. {
  970. BOOL t_Impersonating = FALSE ;
  971. IUnknown *t_OldContext = NULL ;
  972. IServerSecurity *t_OldSecurity = NULL ;
  973. t_Result = DecoupledProviderSubSystem_Globals :: BeginImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  974. if ( SUCCEEDED ( t_Result ) )
  975. {
  976. BOOL t_Revert = FALSE ;
  977. IUnknown *t_Proxy = NULL ;
  978. t_Result = DecoupledProviderSubSystem_Globals :: SetProxyState ( IID_IWbemShutdown , t_Shutdown , t_Proxy , t_Revert ) ;
  979. if ( t_Result == WBEM_E_NOT_FOUND )
  980. {
  981. try
  982. {
  983. t_Result = t_Shutdown->Shutdown (
  984. a_Flags ,
  985. a_MaxMilliSeconds ,
  986. a_Context
  987. ) ;
  988. }
  989. catch ( ... )
  990. {
  991. t_Result = WBEM_E_PROVIDER_FAILURE ;
  992. }
  993. }
  994. else
  995. {
  996. if ( SUCCEEDED ( t_Result ) )
  997. {
  998. IWbemShutdown *t_Provider = ( IWbemShutdown * ) t_Proxy ;
  999. // Set cloaking on the proxy
  1000. // =========================
  1001. DWORD t_ImpersonationLevel = DecoupledProviderSubSystem_Globals :: GetCurrentImpersonationLevel () ;
  1002. t_Result = DecoupledProviderSubSystem_Globals :: SetCloaking (
  1003. t_Provider ,
  1004. RPC_C_AUTHN_LEVEL_CONNECT ,
  1005. t_ImpersonationLevel
  1006. ) ;
  1007. if ( SUCCEEDED ( t_Result ) )
  1008. {
  1009. t_Result = t_Provider->Shutdown (
  1010. a_Flags ,
  1011. a_MaxMilliSeconds ,
  1012. a_Context
  1013. ) ;
  1014. }
  1015. DecoupledProviderSubSystem_Globals :: RevertProxyState ( t_Proxy , t_Revert ) ;
  1016. }
  1017. }
  1018. DecoupledProviderSubSystem_Globals :: EndImpersonation ( t_OldContext , t_OldSecurity , t_Impersonating ) ;
  1019. }
  1020. t_Shutdown->Release () ;
  1021. }
  1022. }
  1023. return t_Result ;
  1024. }