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.

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