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.

1029 lines
23 KiB

  1. //***************************************************************************
  2. //
  3. // NTEVTSERV.CPP
  4. //
  5. // Module: WBEM NT EVENT PROVIDER
  6. //
  7. // Purpose: Contains the WBEM locator and services interfaces
  8. //
  9. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Functions constructor, destructor and IUnknown
  15. //***************************************************************************
  16. //
  17. // CImpNTEvtProv ::CImpNTEvtProv
  18. // CImpNTEvtProv ::~CImpNTEvtProv
  19. //
  20. //***************************************************************************
  21. CImpNTEvtProv ::CImpNTEvtProv ()
  22. : m_localeId ( NULL ) ,
  23. m_Namespace ( NULL ) ,
  24. m_Server ( NULL ) ,
  25. m_NotificationClassObject ( NULL ) ,
  26. m_ExtendedNotificationClassObject ( NULL )
  27. {
  28. m_ReferenceCount = 0 ;
  29. InterlockedIncrement ( & CNTEventProviderClassFactory :: objectsInProgress ) ;
  30. /*
  31. * Implementation
  32. */
  33. m_Initialised = FALSE ;
  34. m_GetNotifyCalled = FALSE ;
  35. m_GetExtendedNotifyCalled = FALSE ;
  36. }
  37. CImpNTEvtProv ::~CImpNTEvtProv(void)
  38. {
  39. delete [] m_localeId ;
  40. delete [] m_Namespace ;
  41. if ( m_Server )
  42. m_Server->Release () ;
  43. if ( m_NotificationClassObject )
  44. m_NotificationClassObject->Release () ;
  45. if ( m_ExtendedNotificationClassObject )
  46. m_ExtendedNotificationClassObject->Release () ;
  47. InterlockedDecrement ( & CNTEventProviderClassFactory :: objectsInProgress ) ;
  48. }
  49. //***************************************************************************
  50. //
  51. // CImpNTEvtProv ::QueryInterface
  52. // CImpNTEvtProv ::AddRef
  53. // CImpNTEvtProv ::Release
  54. //
  55. // Purpose: IUnknown members for CImpNTEvtProv object.
  56. //***************************************************************************
  57. STDMETHODIMP CImpNTEvtProv ::QueryInterface (
  58. REFIID iid ,
  59. LPVOID FAR *iplpv
  60. )
  61. {
  62. SetStructuredExceptionHandler seh;
  63. try
  64. {
  65. *iplpv = NULL ;
  66. if ( iid == IID_IUnknown )
  67. {
  68. *iplpv = ( IWbemServices* ) this ;
  69. }
  70. else if ( iid == IID_IWbemServices )
  71. {
  72. *iplpv = ( IWbemServices* ) this ;
  73. }
  74. else if ( iid == IID_IWbemProviderInit )
  75. {
  76. *iplpv = ( IWbemProviderInit* ) this ;
  77. }
  78. if ( *iplpv )
  79. {
  80. ( ( LPUNKNOWN ) *iplpv )->AddRef () ;
  81. return S_OK ;
  82. }
  83. else
  84. {
  85. return E_NOINTERFACE ;
  86. }
  87. }
  88. catch(Structured_Exception e_SE)
  89. {
  90. return E_UNEXPECTED;
  91. }
  92. catch(Heap_Exception e_HE)
  93. {
  94. return E_OUTOFMEMORY;
  95. }
  96. catch(...)
  97. {
  98. return E_UNEXPECTED;
  99. }
  100. }
  101. STDMETHODIMP_(ULONG) CImpNTEvtProv ::AddRef(void)
  102. {
  103. SetStructuredExceptionHandler seh;
  104. try
  105. {
  106. return InterlockedIncrement ( & m_ReferenceCount ) ;
  107. }
  108. catch(Structured_Exception e_SE)
  109. {
  110. return 0;
  111. }
  112. catch(Heap_Exception e_HE)
  113. {
  114. return 0;
  115. }
  116. catch(...)
  117. {
  118. return 0;
  119. }
  120. }
  121. STDMETHODIMP_(ULONG) CImpNTEvtProv ::Release(void)
  122. {
  123. SetStructuredExceptionHandler seh;
  124. try
  125. {
  126. LONG t_Ref ;
  127. if ( ( t_Ref = InterlockedDecrement ( & m_ReferenceCount ) ) == 0 )
  128. {
  129. delete this ;
  130. return 0 ;
  131. }
  132. else
  133. {
  134. return t_Ref ;
  135. }
  136. }
  137. catch(Structured_Exception e_SE)
  138. {
  139. return 0;
  140. }
  141. catch(Heap_Exception e_HE)
  142. {
  143. return 0;
  144. }
  145. catch(...)
  146. {
  147. return 0;
  148. }
  149. }
  150. IWbemServices *CImpNTEvtProv :: GetServer ()
  151. {
  152. if ( m_Server )
  153. m_Server->AddRef () ;
  154. return m_Server ;
  155. }
  156. void CImpNTEvtProv :: SetLocaleId ( wchar_t *localeId )
  157. {
  158. m_localeId = UnicodeStringDuplicate ( localeId ) ;
  159. }
  160. wchar_t *CImpNTEvtProv :: GetNamespace ()
  161. {
  162. return m_Namespace ;
  163. }
  164. void CImpNTEvtProv :: SetNamespace ( wchar_t *a_Namespace )
  165. {
  166. m_Namespace = UnicodeStringDuplicate ( a_Namespace ) ;
  167. }
  168. IWbemClassObject *CImpNTEvtProv :: GetNotificationObject (
  169. WbemProvErrorObject &a_errorObject,
  170. IWbemContext *pCtx
  171. )
  172. {
  173. if ( m_NotificationClassObject )
  174. {
  175. m_NotificationClassObject->AddRef () ;
  176. }
  177. else
  178. {
  179. BOOL t_Status = CreateNotificationObject ( a_errorObject, pCtx ) ;
  180. if ( t_Status )
  181. {
  182. /*
  183. * Keep around until we close
  184. */
  185. m_NotificationClassObject->AddRef () ;
  186. }
  187. }
  188. return m_NotificationClassObject ;
  189. }
  190. IWbemClassObject *CImpNTEvtProv :: GetExtendedNotificationObject (
  191. WbemProvErrorObject &a_errorObject,
  192. IWbemContext *pCtx
  193. )
  194. {
  195. if ( m_ExtendedNotificationClassObject )
  196. {
  197. m_ExtendedNotificationClassObject->AddRef () ;
  198. }
  199. else
  200. {
  201. BOOL t_Status = CreateExtendedNotificationObject ( a_errorObject, pCtx ) ;
  202. if ( t_Status )
  203. {
  204. /*
  205. * Keep around until we close
  206. */
  207. m_ExtendedNotificationClassObject->AddRef () ;
  208. }
  209. }
  210. return m_ExtendedNotificationClassObject ;
  211. }
  212. BOOL CImpNTEvtProv :: CreateExtendedNotificationObject (
  213. WbemProvErrorObject &a_errorObject,
  214. IWbemContext *pCtx
  215. )
  216. {
  217. m_ExtendedNotifyLock.Lock();
  218. BOOL t_Status = TRUE ;
  219. if ( m_GetExtendedNotifyCalled )
  220. {
  221. if ( !m_ExtendedNotificationClassObject )
  222. t_Status = FALSE ;
  223. }
  224. else
  225. {
  226. HRESULT t_Result = WBEM_E_FAILED ;
  227. m_GetExtendedNotifyCalled = TRUE ;
  228. BSTR t_clsStr = SysAllocString(WBEM_CLASS_EXTENDEDSTATUS);
  229. if ( t_clsStr )
  230. {
  231. t_Result = m_Server->GetObject (
  232. t_clsStr ,
  233. 0 ,
  234. pCtx,
  235. & m_ExtendedNotificationClassObject ,
  236. NULL
  237. ) ;
  238. SysFreeString(t_clsStr);
  239. DebugOut(
  240. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  241. _T(__FILE__),__LINE__,
  242. L"CreateExtendedNotificationObject :: ~CreateExtendedNotificationObject: GetObject for %s returned %lx\r\n",
  243. WBEM_CLASS_EXTENDEDSTATUS, t_Result
  244. ) ;
  245. )
  246. }
  247. else
  248. {
  249. t_Result = WBEM_E_OUT_OF_MEMORY ;
  250. }
  251. if ( ! SUCCEEDED ( t_Result ) )
  252. {
  253. t_Status = FALSE ;
  254. a_errorObject.SetStatus ( WBEM_PROV_E_INVALID_OBJECT ) ;
  255. a_errorObject.SetWbemStatus ( ( WBEMSTATUS ) t_Result ) ;
  256. a_errorObject.SetMessage ( L"Failed to get Win32_PrivilegesStatus" ) ;
  257. m_ExtendedNotificationClassObject = NULL ;
  258. }
  259. }
  260. m_ExtendedNotifyLock.Unlock();
  261. return t_Status ;
  262. }
  263. BOOL CImpNTEvtProv :: CreateNotificationObject (
  264. WbemProvErrorObject &a_errorObject,
  265. IWbemContext *pCtx
  266. )
  267. {
  268. m_NotifyLock.Lock();
  269. BOOL t_Status = TRUE ;
  270. if ( m_GetNotifyCalled )
  271. {
  272. if ( !m_NotificationClassObject )
  273. t_Status = FALSE ;
  274. }
  275. else
  276. {
  277. m_GetNotifyCalled = TRUE ;
  278. HRESULT t_Result = WBEM_E_FAILED ;
  279. BSTR t_clsStr = SysAllocString(WBEM_CLASS_EXTENDEDSTATUS);
  280. if ( t_clsStr )
  281. {
  282. t_Result = m_Server->GetObject (
  283. t_clsStr ,
  284. 0 ,
  285. pCtx,
  286. & m_NotificationClassObject ,
  287. NULL
  288. ) ;
  289. SysFreeString(t_clsStr);
  290. DebugOut(
  291. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  292. _T(__FILE__),__LINE__,
  293. L"CreateNotificationObject :: ~CreateNotificationObject: GetObject for %s returned %lx\r\n",
  294. WBEM_CLASS_EXTENDEDSTATUS, t_Result
  295. ) ;
  296. )
  297. }
  298. else
  299. {
  300. t_Result = WBEM_E_OUT_OF_MEMORY ;
  301. }
  302. if ( ! SUCCEEDED ( t_Result ) )
  303. {
  304. t_Status = FALSE ;
  305. a_errorObject.SetStatus ( WBEM_PROV_E_INVALID_OBJECT ) ;
  306. a_errorObject.SetWbemStatus ( ( WBEMSTATUS ) t_Result ) ;
  307. a_errorObject.SetMessage ( L"Failed to get Win32_PrivilegesStatus" ) ;
  308. m_NotificationClassObject = NULL;
  309. }
  310. }
  311. m_NotifyLock.Unlock();
  312. return t_Status ;
  313. }
  314. /////////////////////////////////////////////////////////////////////////////
  315. // Functions for the IWbemServices interface that are handled here
  316. HRESULT CImpNTEvtProv :: CancelAsyncCall (
  317. IWbemObjectSink __RPC_FAR *pSink
  318. )
  319. {
  320. return WBEM_E_NOT_AVAILABLE ;
  321. }
  322. HRESULT CImpNTEvtProv :: QueryObjectSink (
  323. long lFlags,
  324. IWbemObjectSink __RPC_FAR* __RPC_FAR* ppHandler
  325. )
  326. {
  327. return WBEM_E_NOT_AVAILABLE ;
  328. }
  329. HRESULT CImpNTEvtProv :: GetObject (
  330. const BSTR ObjectPath,
  331. long lFlags,
  332. IWbemContext __RPC_FAR *pCtx,
  333. IWbemClassObject __RPC_FAR* __RPC_FAR *ppObject,
  334. IWbemCallResult __RPC_FAR* __RPC_FAR *ppCallResult
  335. )
  336. {
  337. return WBEM_E_NOT_AVAILABLE ;
  338. }
  339. HRESULT CImpNTEvtProv :: GetObjectAsync (
  340. const BSTR ObjectPath,
  341. long lFlags,
  342. IWbemContext __RPC_FAR *pCtx,
  343. IWbemObjectSink __RPC_FAR* pHandler
  344. )
  345. {
  346. HRESULT t_Status = WBEM_NO_ERROR;
  347. SetStructuredExceptionHandler seh;
  348. try
  349. {
  350. DebugOut(
  351. CNTEventProvider::g_NTEvtDebugLog->Write (
  352. L"\r\n"
  353. ) ;
  354. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  355. _T(__FILE__),__LINE__,
  356. L"CImpNTEvtProv::GetObjectAsync ()"
  357. ) ;
  358. )
  359. /*
  360. * Create Asynchronous GetObjectByPath object
  361. */
  362. GetObjectAsyncEventObject t_AsyncEvent ( this , ObjectPath , lFlags , pHandler , pCtx ) ;
  363. t_AsyncEvent.Process () ;
  364. DebugOut(
  365. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  366. _T(__FILE__),__LINE__,
  367. L"Returning from CImpNTEvtProv::GetObjectAsync ( (%s) ) with Result = (%lx)" ,
  368. ObjectPath ,
  369. t_Status
  370. ) ;
  371. )
  372. }
  373. catch(Structured_Exception e_SE)
  374. {
  375. t_Status = WBEM_E_UNEXPECTED;
  376. }
  377. catch(Heap_Exception e_HE)
  378. {
  379. t_Status = WBEM_E_OUT_OF_MEMORY;
  380. }
  381. catch(...)
  382. {
  383. t_Status = WBEM_E_UNEXPECTED;
  384. }
  385. return t_Status;
  386. }
  387. HRESULT CImpNTEvtProv :: PutClass (
  388. IWbemClassObject __RPC_FAR* pClass ,
  389. long lFlags,
  390. IWbemContext __RPC_FAR *pCtx,
  391. IWbemCallResult __RPC_FAR* __RPC_FAR* ppCallResult
  392. )
  393. {
  394. return WBEM_E_NOT_AVAILABLE ;
  395. }
  396. HRESULT CImpNTEvtProv :: PutClassAsync (
  397. IWbemClassObject __RPC_FAR* pClass,
  398. long lFlags,
  399. IWbemContext __RPC_FAR *pCtx,
  400. IWbemObjectSink __RPC_FAR* pHandler
  401. )
  402. {
  403. return WBEM_E_NOT_AVAILABLE ;
  404. }
  405. HRESULT CImpNTEvtProv :: DeleteClass (
  406. const BSTR Class,
  407. long lFlags,
  408. IWbemContext __RPC_FAR *pCtx,
  409. IWbemCallResult __RPC_FAR* __RPC_FAR* ppCallResult
  410. )
  411. {
  412. return WBEM_E_NOT_AVAILABLE ;
  413. }
  414. HRESULT CImpNTEvtProv :: DeleteClassAsync (
  415. const BSTR Class,
  416. long lFlags,
  417. IWbemContext __RPC_FAR *pCtx,
  418. IWbemObjectSink __RPC_FAR* pHandler
  419. )
  420. {
  421. return WBEM_E_NOT_AVAILABLE ;
  422. }
  423. HRESULT CImpNTEvtProv :: CreateClassEnum (
  424. const BSTR Superclass,
  425. long lFlags,
  426. IWbemContext __RPC_FAR *pCtx,
  427. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  428. )
  429. {
  430. return WBEM_E_NOT_AVAILABLE ;
  431. }
  432. SCODE CImpNTEvtProv :: CreateClassEnumAsync (
  433. const BSTR Superclass,
  434. long lFlags,
  435. IWbemContext __RPC_FAR* pCtx,
  436. IWbemObjectSink __RPC_FAR* pHandler
  437. )
  438. {
  439. return WBEM_E_NOT_AVAILABLE ;
  440. }
  441. HRESULT CImpNTEvtProv :: PutInstance (
  442. IWbemClassObject __RPC_FAR *pInstance,
  443. long lFlags,
  444. IWbemContext __RPC_FAR *pCtx,
  445. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  446. )
  447. {
  448. return WBEM_E_NOT_AVAILABLE ;
  449. }
  450. HRESULT CImpNTEvtProv :: PutInstanceAsync (
  451. IWbemClassObject __RPC_FAR* pInstance,
  452. long lFlags,
  453. IWbemContext __RPC_FAR *pCtx,
  454. IWbemObjectSink __RPC_FAR* pHandler
  455. )
  456. {
  457. HRESULT t_Status = WBEM_NO_ERROR;
  458. SetStructuredExceptionHandler seh;
  459. try
  460. {
  461. DebugOut(
  462. CNTEventProvider::g_NTEvtDebugLog->Write (
  463. L"\r\n"
  464. ) ;
  465. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  466. _T(__FILE__),__LINE__,
  467. L"CImpNTEvtProv::PutInstanceAsync ()"
  468. ) ;
  469. )
  470. /*
  471. * Create Asynchronous GetObjectByPath object
  472. */
  473. PutInstanceAsyncEventObject t_AsyncEvent ( this , pInstance , lFlags , pHandler , pCtx ) ;
  474. t_AsyncEvent.Process();
  475. DebugOut(
  476. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  477. _T(__FILE__),__LINE__,
  478. L"Returning from CImpNTEvtProv::PutInstanceAsync with Result = (%lx)" ,
  479. t_Status
  480. ) ;
  481. )
  482. }
  483. catch(Structured_Exception e_SE)
  484. {
  485. t_Status = WBEM_E_UNEXPECTED;
  486. }
  487. catch(Heap_Exception e_HE)
  488. {
  489. t_Status = WBEM_E_OUT_OF_MEMORY;
  490. }
  491. catch(...)
  492. {
  493. t_Status = WBEM_E_UNEXPECTED;
  494. }
  495. return t_Status;
  496. }
  497. HRESULT CImpNTEvtProv :: DeleteInstance (
  498. const BSTR ObjectPath,
  499. long lFlags,
  500. IWbemContext __RPC_FAR *pCtx,
  501. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  502. )
  503. {
  504. return WBEM_E_NOT_AVAILABLE ;
  505. }
  506. HRESULT CImpNTEvtProv :: DeleteInstanceAsync (
  507. const BSTR ObjectPath,
  508. long lFlags,
  509. IWbemContext __RPC_FAR *pCtx,
  510. IWbemObjectSink __RPC_FAR *pHandler
  511. )
  512. {
  513. return WBEM_E_NOT_AVAILABLE ;
  514. }
  515. HRESULT CImpNTEvtProv :: CreateInstanceEnum (
  516. const BSTR Class,
  517. long lFlags,
  518. IWbemContext __RPC_FAR *pCtx,
  519. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  520. )
  521. {
  522. return WBEM_E_NOT_AVAILABLE ;
  523. }
  524. HRESULT CImpNTEvtProv :: CreateInstanceEnumAsync (
  525. const BSTR Class,
  526. long lFlags,
  527. IWbemContext __RPC_FAR *pCtx,
  528. IWbemObjectSink __RPC_FAR* pHandler
  529. )
  530. {
  531. HRESULT t_Status = WBEM_NO_ERROR;
  532. SetStructuredExceptionHandler seh;
  533. try
  534. {
  535. DebugOut(
  536. CNTEventProvider::g_NTEvtDebugLog->Write (
  537. L"\r\n"
  538. ) ;
  539. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  540. _T(__FILE__),__LINE__,
  541. L"CImpNTEvtProv::CreateInstanceEnumAsync ( (%s) )" ,
  542. Class
  543. ) ;
  544. )
  545. /*
  546. * Create Synchronous Enum Instance object
  547. */
  548. CStringW QueryStr(ENUM_INST_QUERY_START);
  549. QueryStr += CStringW(Class);
  550. QueryStr += ENUM_INST_QUERY_MID;
  551. QueryStr += CStringW(Class);
  552. QueryStr += PROP_END_QUOTE;
  553. BSTR Query = QueryStr.AllocSysString();
  554. ExecQueryAsyncEventObject t_AsyncEvent ( this , WBEM_QUERY_LANGUAGE_SQL1 , Query , lFlags , pHandler , pCtx ) ;
  555. t_AsyncEvent.Process() ;
  556. DebugOut(
  557. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  558. _T(__FILE__),__LINE__,
  559. L"Returning from CImpNTEvtProv::CreateInstanceEnumAsync ( (%s),(%s) ) with Result = (%lx)" ,
  560. Class,
  561. Query,
  562. t_Status
  563. ) ;
  564. )
  565. SysFreeString(Query);
  566. }
  567. catch(Structured_Exception e_SE)
  568. {
  569. t_Status = WBEM_E_UNEXPECTED;
  570. }
  571. catch(Heap_Exception e_HE)
  572. {
  573. t_Status = WBEM_E_OUT_OF_MEMORY;
  574. }
  575. catch(...)
  576. {
  577. t_Status = WBEM_E_UNEXPECTED;
  578. }
  579. return t_Status;
  580. }
  581. HRESULT CImpNTEvtProv :: ExecQuery (
  582. const BSTR QueryLanguage,
  583. const BSTR Query,
  584. long lFlags,
  585. IWbemContext __RPC_FAR *pCtx,
  586. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  587. )
  588. {
  589. return WBEM_E_NOT_AVAILABLE ;
  590. }
  591. HRESULT CImpNTEvtProv :: ExecQueryAsync (
  592. const BSTR QueryFormat,
  593. const BSTR Query,
  594. long lFlags,
  595. IWbemContext __RPC_FAR* pCtx,
  596. IWbemObjectSink __RPC_FAR* pHandler
  597. )
  598. {
  599. HRESULT t_Status = WBEM_NO_ERROR;
  600. SetStructuredExceptionHandler seh;
  601. try
  602. {
  603. DebugOut(
  604. CNTEventProvider::g_NTEvtDebugLog->Write (
  605. L"\r\n"
  606. ) ;
  607. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  608. _T(__FILE__),__LINE__,
  609. L"CImpNTEvtProv::ExecQueryAsync ( (%s),(%s) )" ,
  610. QueryFormat ,
  611. Query
  612. ) ;
  613. )
  614. /*
  615. * Create Synchronous Enum Instance object
  616. */
  617. pHandler->SetStatus(WBEM_STATUS_REQUIREMENTS, S_OK, NULL, NULL);
  618. ExecQueryAsyncEventObject t_AsyncEvent ( this , QueryFormat , Query , lFlags , pHandler , pCtx ) ;
  619. t_AsyncEvent.Process() ;
  620. DebugOut(
  621. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  622. _T(__FILE__),__LINE__,
  623. L"Returning from CImpNTEvtProv::ExecqQueryAsync ( (%s),(%s) ) with Result = (%lx)" ,
  624. QueryFormat,
  625. Query,
  626. t_Status
  627. ) ;
  628. )
  629. }
  630. catch(Structured_Exception e_SE)
  631. {
  632. t_Status = WBEM_E_UNEXPECTED;
  633. }
  634. catch(Heap_Exception e_HE)
  635. {
  636. t_Status = WBEM_E_OUT_OF_MEMORY;
  637. }
  638. catch(...)
  639. {
  640. t_Status = WBEM_E_UNEXPECTED;
  641. }
  642. return t_Status;
  643. }
  644. HRESULT CImpNTEvtProv :: ExecNotificationQuery (
  645. const BSTR QueryLanguage,
  646. const BSTR Query,
  647. long lFlags,
  648. IWbemContext __RPC_FAR *pCtx,
  649. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum
  650. )
  651. {
  652. return WBEM_E_NOT_AVAILABLE ;
  653. }
  654. HRESULT CImpNTEvtProv :: ExecNotificationQueryAsync (
  655. const BSTR QueryLanguage,
  656. const BSTR Query,
  657. long lFlags,
  658. IWbemContext __RPC_FAR *pCtx,
  659. IWbemObjectSink __RPC_FAR *pHandler
  660. )
  661. {
  662. return WBEM_E_NOT_AVAILABLE ;
  663. }
  664. HRESULT STDMETHODCALLTYPE CImpNTEvtProv :: ExecMethod(
  665. const BSTR ObjectPath,
  666. const BSTR MethodName,
  667. long lFlags,
  668. IWbemContext __RPC_FAR *pCtx,
  669. IWbemClassObject __RPC_FAR *pInParams,
  670. IWbemClassObject __RPC_FAR *__RPC_FAR *ppOutParams,
  671. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult
  672. )
  673. {
  674. return WBEM_E_NOT_AVAILABLE ;
  675. }
  676. HRESULT STDMETHODCALLTYPE CImpNTEvtProv :: ExecMethodAsync (
  677. const BSTR ObjectPath,
  678. const BSTR MethodName,
  679. long lFlags,
  680. IWbemContext __RPC_FAR *pCtx,
  681. IWbemClassObject __RPC_FAR *pInParams,
  682. IWbemObjectSink __RPC_FAR *pResponseHandler
  683. )
  684. {
  685. HRESULT t_Status = WBEM_NO_ERROR;
  686. SetStructuredExceptionHandler seh;
  687. try
  688. {
  689. DebugOut(
  690. CNTEventProvider::g_NTEvtDebugLog->Write (
  691. L"\r\n"
  692. ) ;
  693. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  694. _T(__FILE__),__LINE__,
  695. L"CImpNTEvtProv::ExecMethodAsync ()"
  696. ) ;
  697. )
  698. /*
  699. * Create Asynchronous GetObjectByPath object
  700. */
  701. ExecMethodAsyncEventObject t_AsyncEvent ( this , ObjectPath , MethodName ,
  702. lFlags , pInParams , pResponseHandler , pCtx ) ;
  703. t_AsyncEvent.Process() ;
  704. DebugOut(
  705. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  706. _T(__FILE__),__LINE__,
  707. L"Returning from CImpNTEvtProv::ExecMethodAsync ( (%s) ) with Result = (%lx)" ,
  708. ObjectPath ,
  709. t_Status
  710. ) ;
  711. )
  712. }
  713. catch(Structured_Exception e_SE)
  714. {
  715. t_Status = WBEM_E_UNEXPECTED;
  716. }
  717. catch(Heap_Exception e_HE)
  718. {
  719. t_Status = WBEM_E_OUT_OF_MEMORY;
  720. }
  721. catch(...)
  722. {
  723. t_Status = WBEM_E_UNEXPECTED;
  724. }
  725. return t_Status;
  726. }
  727. HRESULT CImpNTEvtProv :: Initialize(
  728. LPWSTR pszUser,
  729. LONG lFlags,
  730. LPWSTR pszNamespace,
  731. LPWSTR pszLocale,
  732. IWbemServices *pCIMOM, // For anybody
  733. IWbemContext *pCtx,
  734. IWbemProviderInitSink *pInitSink // For init signals
  735. )
  736. {
  737. HRESULT t_Status = WBEM_NO_ERROR;
  738. SetStructuredExceptionHandler seh;
  739. try
  740. {
  741. DebugOut(
  742. CNTEventProvider::g_NTEvtDebugLog->Write (
  743. L"\r\n"
  744. ) ;
  745. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  746. _T(__FILE__),__LINE__,
  747. L"CImpNTEvtProv::Initialize "
  748. ) ;
  749. )
  750. m_Server = pCIMOM ;
  751. m_Server->AddRef () ;
  752. m_NamespacePath.SetNamespacePath ( pszNamespace ) ;
  753. DebugOut(
  754. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  755. _T(__FILE__),__LINE__,
  756. L"Returning From CImpPropProv::Initialize () "
  757. ) ;
  758. )
  759. pInitSink->SetStatus ( WBEM_S_INITIALIZED , 0 ) ;
  760. }
  761. catch(Structured_Exception e_SE)
  762. {
  763. t_Status = WBEM_E_UNEXPECTED;
  764. }
  765. catch(Heap_Exception e_HE)
  766. {
  767. t_Status = WBEM_E_OUT_OF_MEMORY;
  768. }
  769. catch(...)
  770. {
  771. t_Status = WBEM_E_UNEXPECTED;
  772. }
  773. return t_Status;
  774. }
  775. HRESULT STDMETHODCALLTYPE CImpNTEvtProv::OpenNamespace (
  776. const BSTR ObjectPath,
  777. long lFlags,
  778. IWbemContext FAR* pCtx,
  779. IWbemServices FAR* FAR* pNewContext,
  780. IWbemCallResult FAR* FAR* ppErrorObject
  781. )
  782. {
  783. return WBEM_E_NOT_AVAILABLE ;
  784. }
  785. HRESULT CImpNTEvtProv::GetImpersonation()
  786. {
  787. HRESULT hr = WBEM_E_FAILED;
  788. DWORD dwVersion = GetVersion();
  789. if ( (4 < (DWORD)(LOBYTE(LOWORD(dwVersion))))
  790. || ObtainedSerialAccess(CNTEventProvider::g_secMutex) )
  791. {
  792. if (SUCCEEDED(WbemCoImpersonateClient()))
  793. {
  794. HANDLE hThreadTok;
  795. if ( !OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &hThreadTok) )
  796. {
  797. DWORD dwLastError = GetLastError();
  798. if (dwLastError == ERROR_NO_TOKEN)
  799. {
  800. // If the CoImpersonate works, but the OpenThreadToken fails due to ERROR_NO_TOKEN, we
  801. // are running under the process token (either local system, or if we are running
  802. // with /exe, the rights of the logged in user). In either case, impersonation rights
  803. // don't apply. We have the full rights of that user.
  804. hr = WBEM_S_NO_ERROR;
  805. }
  806. else
  807. {
  808. // If we failed to get the thread token for any other reason, an error.
  809. hr = WBEM_E_ACCESS_DENIED;
  810. }
  811. }
  812. else
  813. {
  814. DWORD dwImp;
  815. DWORD dwBytesReturned;
  816. // We really do have a thread token, so let's retrieve its level
  817. if (GetTokenInformation(hThreadTok, TokenImpersonationLevel, &dwImp,
  818. sizeof(DWORD), &dwBytesReturned))
  819. {
  820. // Is the impersonation level Impersonate?
  821. if ((dwImp == SecurityImpersonation) || (dwImp == SecurityDelegation))
  822. {
  823. hr = WBEM_S_NO_ERROR;
  824. }
  825. else
  826. {
  827. hr = WBEM_E_ACCESS_DENIED;
  828. }
  829. }
  830. CloseHandle(hThreadTok);
  831. }
  832. if (FAILED(hr))
  833. {
  834. WbemCoRevertToSelf();
  835. }
  836. }
  837. if ( 5 > (DWORD)(LOBYTE(LOWORD(dwVersion))) )
  838. {
  839. ReleaseSerialAccess(CNTEventProvider::g_secMutex);
  840. }
  841. }
  842. return hr;
  843. }