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.

1650 lines
52 KiB

  1. //***************************************************************************
  2. //
  3. // NTEVTGET.CPP
  4. //
  5. // Module: WBEM NT EVENT PROVIDER
  6. //
  7. // Purpose: Contains the GetObject implementation
  8. //
  9. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. extern BOOL GenerateAssocInstance (WbemProvErrorObject &a_ErrorObject,
  14. const wchar_t* objPath1,
  15. const wchar_t* objPath2,
  16. wchar_t* prop1,
  17. wchar_t* prop2,
  18. IWbemClassObject* pClassObject,
  19. IWbemObjectSink* pNtfcnHandler,
  20. BOOL *pbIndicated);
  21. BOOL GetObjectAsyncEventObject :: GetObject ( WbemProvErrorObject &a_ErrorObject )
  22. {
  23. DebugOut(
  24. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  25. _T(__FILE__),__LINE__,
  26. L"GetObjectAsyncEventObject :: GetObject\r\n"
  27. ) ;
  28. )
  29. if (FAILED(m_ErrorObject.GetWbemStatus()))
  30. {
  31. return FALSE;
  32. }
  33. BOOL t_Status = ! m_ObjectPathParser.Parse ( m_ObjectPath , &m_ParsedObjectPath ) ;
  34. if ( t_Status )
  35. {
  36. BOOL bClass = TRUE;
  37. if ( _wcsicmp ( m_ParsedObjectPath->m_pClass , NTEVT_CLASS) == 0 )
  38. {
  39. BSTR bstCls = SysAllocString( m_ParsedObjectPath->m_pClass ) ;
  40. if ( bstCls )
  41. {
  42. t_Status = GetClassObject ( bstCls ) ;
  43. SysFreeString ( bstCls ) ;
  44. if ( t_Status )
  45. {
  46. t_Status = Dispatch_Record ( a_ErrorObject ) ;
  47. if ( t_Status )
  48. {
  49. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  50. }
  51. }
  52. else
  53. {
  54. bClass = FALSE ;
  55. }
  56. }
  57. else
  58. {
  59. t_Status = FALSE ;
  60. a_ErrorObject.SetStatus ( WBEM_PROV_E_OUT_OF_MEMORY ) ;
  61. a_ErrorObject.SetWbemStatus ( WBEM_E_OUT_OF_MEMORY ) ;
  62. a_ErrorObject.SetMessage ( L"Unable to allocate class string" ) ;
  63. }
  64. }
  65. else if ( _wcsicmp ( m_ParsedObjectPath->m_pClass , NTEVTLOG_CLASS ) == 0 )
  66. {
  67. BSTR bstCls = SysAllocString( m_ParsedObjectPath->m_pClass ) ;
  68. if ( bstCls )
  69. {
  70. t_Status = GetClassObject ( bstCls ) ;
  71. SysFreeString ( bstCls ) ;
  72. if ( t_Status )
  73. {
  74. t_Status = Dispatch_EventLog ( a_ErrorObject ) ;
  75. if ( t_Status )
  76. {
  77. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  78. }
  79. }
  80. else
  81. {
  82. bClass = FALSE ;
  83. }
  84. }
  85. else
  86. {
  87. t_Status = FALSE ;
  88. a_ErrorObject.SetStatus ( WBEM_PROV_E_OUT_OF_MEMORY ) ;
  89. a_ErrorObject.SetWbemStatus ( WBEM_E_OUT_OF_MEMORY ) ;
  90. a_ErrorObject.SetMessage ( L"Unable to allocate class string" ) ;
  91. }
  92. }
  93. else if ( _wcsicmp ( m_ParsedObjectPath->m_pClass , ASSOC_LOGRECORD ) == 0 )
  94. {
  95. BSTR bstCls = SysAllocString( m_ParsedObjectPath->m_pClass ) ;
  96. if ( bstCls )
  97. {
  98. t_Status = GetClassObject ( bstCls ) ;
  99. SysFreeString ( bstCls ) ;
  100. if ( t_Status )
  101. {
  102. t_Status = Dispatch_LogRecord ( a_ErrorObject ) ;
  103. if ( t_Status )
  104. {
  105. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  106. }
  107. }
  108. else
  109. {
  110. bClass = FALSE ;
  111. }
  112. }
  113. else
  114. {
  115. t_Status = FALSE ;
  116. a_ErrorObject.SetStatus ( WBEM_PROV_E_OUT_OF_MEMORY ) ;
  117. a_ErrorObject.SetWbemStatus ( WBEM_E_OUT_OF_MEMORY ) ;
  118. a_ErrorObject.SetMessage ( L"Unable to allocate class string" ) ;
  119. }
  120. }
  121. else if ( _wcsicmp ( m_ParsedObjectPath->m_pClass , ASSOC_USERRECORD ) == 0 )
  122. {
  123. BSTR bstCls = SysAllocString( m_ParsedObjectPath->m_pClass ) ;
  124. if ( bstCls )
  125. {
  126. t_Status = GetClassObject ( bstCls ) ;
  127. SysFreeString ( bstCls ) ;
  128. if ( t_Status )
  129. {
  130. t_Status = Dispatch_UserRecord ( a_ErrorObject ) ;
  131. if ( t_Status )
  132. {
  133. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  134. }
  135. }
  136. else
  137. {
  138. bClass = FALSE ;
  139. }
  140. }
  141. else
  142. {
  143. t_Status = FALSE ;
  144. a_ErrorObject.SetStatus ( WBEM_PROV_E_OUT_OF_MEMORY ) ;
  145. a_ErrorObject.SetWbemStatus ( WBEM_E_OUT_OF_MEMORY ) ;
  146. a_ErrorObject.SetMessage ( L"Unable to allocate class string" ) ;
  147. }
  148. }
  149. else if ( _wcsicmp ( m_ParsedObjectPath->m_pClass , ASSOC_COMPRECORD ) == 0 )
  150. {
  151. t_Status = GetClassObject ( m_ParsedObjectPath->m_pClass ) ;
  152. if ( t_Status )
  153. {
  154. t_Status = Dispatch_ComputerRecord ( a_ErrorObject ) ;
  155. if ( t_Status )
  156. {
  157. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE ;
  158. }
  159. }
  160. else
  161. {
  162. bClass = FALSE ;
  163. }
  164. }
  165. else
  166. {
  167. t_Status = FALSE ;
  168. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS ) ;
  169. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  170. a_ErrorObject.SetMessage ( L"Dynamic NT Eventlog Provider does not support this class" ) ;
  171. DebugOut(
  172. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  173. _T(__FILE__),__LINE__,
  174. L"GetObjectAsyncEventObject :: GetObject:Dynamic NT Eventlog Provider does not support this class %s\r\n",
  175. m_ParsedObjectPath->m_pClass
  176. ) ;
  177. )
  178. }
  179. if (!bClass)
  180. {
  181. t_Status = FALSE ;
  182. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS ) ;
  183. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  184. a_ErrorObject.SetMessage ( L"Class definition not found" ) ;
  185. DebugOut(
  186. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  187. _T(__FILE__),__LINE__,
  188. L"GetObjectAsyncEventObject :: GetObject:Class definition not found\r\n"
  189. ) ;
  190. )
  191. }
  192. }
  193. else
  194. {
  195. t_Status = FALSE ;
  196. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS ) ;
  197. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  198. a_ErrorObject.SetMessage ( L"Unable to parse object path" ) ;
  199. DebugOut(
  200. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  201. _T(__FILE__),__LINE__,
  202. L"GetObjectAsyncEventObject :: GetObject:Dynamic NT Eventlog Provider does not support this class %s\r\n",
  203. m_ObjectPath
  204. ) ;
  205. )
  206. }
  207. DebugOut(
  208. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  209. _T(__FILE__),__LINE__,
  210. L"leaving GetObjectAsyncEventObject :: GetObject with %lx\r\n",
  211. t_Status
  212. ) ;
  213. )
  214. return t_Status ;
  215. }
  216. BOOL GetObjectAsyncEventObject :: Dispatch_Record ( WbemProvErrorObject &a_ErrorObject )
  217. {
  218. DebugOut(
  219. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  220. _T(__FILE__),__LINE__,
  221. L"GetObjectAsyncEventObject :: Dispatch_Record\r\n"
  222. ) ;
  223. )
  224. if (m_ParsedObjectPath->m_dwNumKeys != 2)
  225. {
  226. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  227. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  228. a_ErrorObject.SetMessage ( L"Object path has incorrect number of keys." ) ;
  229. DebugOut(
  230. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  231. _T(__FILE__),__LINE__,
  232. L"GetObjectAsyncEventObject :: Dispatch_Record: Wrong number of key values\r\n"
  233. ) ;
  234. )
  235. return FALSE;
  236. }
  237. BOOL t_Status ;
  238. KeyRef *t_Key1 = m_ParsedObjectPath->m_paKeys [ 0 ] ;
  239. KeyRef *t_Key2 = m_ParsedObjectPath->m_paKeys [ 1 ] ;
  240. if ( t_Key1 && t_Key2 )
  241. {
  242. if ( _wcsicmp ( t_Key1->m_pName , LOGFILE_PROP ) == 0 )
  243. {
  244. if ( _wcsicmp ( t_Key2->m_pName , RECORD_PROP ) == 0 )
  245. {
  246. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_I4 ) )
  247. {
  248. t_Status = Get_Record ( a_ErrorObject , t_Key1 , t_Key2 ) ;
  249. }
  250. else
  251. {
  252. t_Status = FALSE ;
  253. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  254. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  255. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  256. DebugOut(
  257. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  258. _T(__FILE__),__LINE__,
  259. L"GetObjectAsyncEventObject :: Dispatch_Record: Key value(s) have incorrect type\r\n"
  260. ) ;
  261. )
  262. }
  263. }
  264. else
  265. {
  266. t_Status = FALSE ;
  267. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  268. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  269. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  270. DebugOut(
  271. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  272. _T(__FILE__),__LINE__,
  273. L"GetObjectAsyncEventObject :: Dispatch_Record: Key value(s) have incorrect name\r\n"
  274. ) ;
  275. )
  276. }
  277. }
  278. else if ( _wcsicmp ( t_Key2->m_pName , LOGFILE_PROP ) == 0 )
  279. {
  280. if ( _wcsicmp ( t_Key1->m_pName , RECORD_PROP ) == 0 )
  281. {
  282. if ( ( t_Key1->m_vValue.vt == VT_I4 ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  283. {
  284. t_Status = Get_Record ( a_ErrorObject , t_Key2 , t_Key1 ) ;
  285. }
  286. else
  287. {
  288. t_Status = FALSE ;
  289. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  290. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  291. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  292. DebugOut(
  293. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  294. _T(__FILE__),__LINE__,
  295. L"GetObjectAsyncEventObject :: Dispatch_Record: Key value(s) have incorrect type\r\n"
  296. ) ;
  297. )
  298. }
  299. }
  300. else
  301. {
  302. t_Status = FALSE ;
  303. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  304. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  305. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  306. DebugOut(
  307. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  308. _T(__FILE__),__LINE__,
  309. L"GetObjectAsyncEventObject :: Dispatch_Record: Key value(s) have incorrect name\r\n"
  310. ) ;
  311. )
  312. }
  313. }
  314. else
  315. {
  316. t_Status = FALSE ;
  317. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  318. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  319. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  320. DebugOut(
  321. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  322. _T(__FILE__),__LINE__,
  323. L"GetObjectAsyncEventObject :: Dispatch_Record: Key value(s) have incorrect name\r\n"
  324. ) ;
  325. )
  326. }
  327. }
  328. else
  329. {
  330. t_Status = FALSE ;
  331. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  332. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  333. a_ErrorObject.SetMessage ( L"Failed to get key values" ) ;
  334. DebugOut(
  335. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  336. _T(__FILE__),__LINE__,
  337. L"GetObjectAsyncEventObject :: Dispatch_Record: Failed to get key values\r\n"
  338. ) ;
  339. )
  340. }
  341. DebugOut(
  342. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  343. _T(__FILE__),__LINE__,
  344. L"leaving GetObjectAsyncEventObject :: Dispatch_Record with %lx\r\n",
  345. t_Status
  346. ) ;
  347. )
  348. return t_Status ;
  349. }
  350. BOOL GetObjectAsyncEventObject :: Dispatch_EventLog ( WbemProvErrorObject &a_ErrorObject )
  351. {
  352. DebugOut(
  353. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  354. _T(__FILE__),__LINE__,
  355. L"GetObjectAsyncEventObject :: Dispatch_EventLog\r\n"
  356. ) ;
  357. )
  358. if (m_ParsedObjectPath->m_dwNumKeys != 1)
  359. {
  360. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  361. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  362. a_ErrorObject.SetMessage ( L"Object path has incorrect number of keys." ) ;
  363. DebugOut(
  364. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  365. _T(__FILE__),__LINE__,
  366. L"GetObjectAsyncEventObject :: Dispatch_EventLog: Wrong number of key values\r\n"
  367. ) ;
  368. )
  369. return FALSE;
  370. }
  371. BOOL t_Status ;
  372. KeyRef *t_Key1 = m_ParsedObjectPath->m_paKeys [ 0 ] ;
  373. if ( t_Key1 )
  374. {
  375. if ((t_Key1->m_pName == NULL) || _wcsicmp ( t_Key1->m_pName , PROP_NAME ) == 0 )
  376. {
  377. if ( t_Key1->m_vValue.vt == VT_BSTR )
  378. {
  379. t_Status = Get_EventLog ( a_ErrorObject , t_Key1 ) ;
  380. }
  381. else
  382. {
  383. t_Status = FALSE ;
  384. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  385. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  386. a_ErrorObject.SetMessage ( L"Key value has incorrect type" ) ;
  387. DebugOut(
  388. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  389. _T(__FILE__),__LINE__,
  390. L"GetObjectAsyncEventObject :: Dispatch_EventLog:Key value has incorrect type\r\n"
  391. ) ;
  392. )
  393. }
  394. }
  395. else
  396. {
  397. t_Status = FALSE ;
  398. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  399. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  400. a_ErrorObject.SetMessage ( L"Key value has incorrect name" ) ;
  401. DebugOut(
  402. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  403. _T(__FILE__),__LINE__,
  404. L"GetObjectAsyncEventObject :: Dispatch_EventLog:Key value has incorrect name\r\n"
  405. ) ;
  406. )
  407. }
  408. }
  409. else
  410. {
  411. t_Status = FALSE ;
  412. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  413. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  414. a_ErrorObject.SetMessage ( L"Failed to get key value" ) ;
  415. DebugOut(
  416. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  417. _T(__FILE__),__LINE__,
  418. L"GetObjectAsyncEventObject :: Dispatch_EventLog:Failed to get key value\r\n"
  419. ) ;
  420. )
  421. }
  422. DebugOut(
  423. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  424. _T(__FILE__),__LINE__,
  425. L"GetObjectAsyncEventObject :: Dispatch_EventLog:return %lx\r\n",
  426. t_Status
  427. ) ;
  428. )
  429. return t_Status ;
  430. }
  431. BOOL GetObjectAsyncEventObject :: Dispatch_LogRecord ( WbemProvErrorObject &a_ErrorObject )
  432. {
  433. DebugOut(
  434. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  435. _T(__FILE__),__LINE__,
  436. L"GetObjectAsyncEventObject :: Dispatch_LogRecord\r\n"
  437. ) ;
  438. )
  439. if (m_ParsedObjectPath->m_dwNumKeys != 2)
  440. {
  441. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  442. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  443. a_ErrorObject.SetMessage ( L"Object path has incorrect number of keys." ) ;
  444. DebugOut(
  445. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  446. _T(__FILE__),__LINE__,
  447. L"GetObjectAsyncEventObject :: Dispatch_LogRecord: Wrong number of key values\r\n"
  448. ) ;
  449. )
  450. return FALSE;
  451. }
  452. BOOL t_Status ;
  453. KeyRef *t_Key1 = m_ParsedObjectPath->m_paKeys [ 0 ] ;
  454. KeyRef *t_Key2 = m_ParsedObjectPath->m_paKeys [ 1 ] ;
  455. if ( t_Key1 && t_Key2 )
  456. {
  457. if ( _wcsicmp ( t_Key1->m_pName , REF_LOG ) == 0 )
  458. {
  459. if ( _wcsicmp ( t_Key2->m_pName , REF_REC ) == 0 )
  460. {
  461. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  462. {
  463. t_Status = Get_LogRecord ( a_ErrorObject , t_Key1 , t_Key2 ) ;
  464. }
  465. else
  466. {
  467. t_Status = FALSE ;
  468. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  469. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  470. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  471. DebugOut(
  472. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  473. _T(__FILE__),__LINE__,
  474. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:Key value(s) have incorrect type\r\n"
  475. ) ;
  476. )
  477. }
  478. }
  479. else
  480. {
  481. t_Status = FALSE ;
  482. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  483. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  484. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  485. DebugOut(
  486. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  487. _T(__FILE__),__LINE__,
  488. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:Key value(s) have incorrect name\r\n"
  489. ) ;
  490. )
  491. }
  492. }
  493. else if ( _wcsicmp ( t_Key2->m_pName , REF_LOG ) == 0 )
  494. {
  495. if ( _wcsicmp ( t_Key1->m_pName , REF_REC ) == 0 )
  496. {
  497. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  498. {
  499. t_Status = Get_LogRecord ( a_ErrorObject , t_Key2 , t_Key1 ) ;
  500. }
  501. else
  502. {
  503. t_Status = FALSE ;
  504. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  505. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  506. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  507. DebugOut(
  508. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  509. _T(__FILE__),__LINE__,
  510. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:Key value(s) have incorrect type\r\n"
  511. ) ;
  512. )
  513. }
  514. }
  515. else
  516. {
  517. t_Status = FALSE ;
  518. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  519. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  520. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  521. DebugOut(
  522. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  523. _T(__FILE__),__LINE__,
  524. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:Key value(s) have incorrect name\r\n"
  525. ) ;
  526. )
  527. }
  528. }
  529. else
  530. {
  531. t_Status = FALSE ;
  532. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  533. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  534. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  535. DebugOut(
  536. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  537. _T(__FILE__),__LINE__,
  538. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:Key value(s) have incorrect name\r\n"
  539. ) ;
  540. )
  541. }
  542. }
  543. else
  544. {
  545. t_Status = FALSE ;
  546. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  547. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  548. a_ErrorObject.SetMessage ( L"Failed to get key values" ) ;
  549. DebugOut(
  550. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  551. _T(__FILE__),__LINE__,
  552. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:Failed to get key values\r\n"
  553. ) ;
  554. )
  555. }
  556. DebugOut(
  557. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  558. _T(__FILE__),__LINE__,
  559. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:returning with %lx\r\n",
  560. t_Status
  561. ) ;
  562. )
  563. return t_Status ;
  564. }
  565. BOOL GetObjectAsyncEventObject :: Dispatch_UserRecord ( WbemProvErrorObject &a_ErrorObject )
  566. {
  567. if (m_ParsedObjectPath->m_dwNumKeys != 2)
  568. {
  569. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  570. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  571. a_ErrorObject.SetMessage ( L"Object path has incorrect number of keys." ) ;
  572. DebugOut(
  573. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  574. _T(__FILE__),__LINE__,
  575. L"GetObjectAsyncEventObject :: Dispatch_UserRecord: Wrong number of key values\r\n"
  576. ) ;
  577. )
  578. return FALSE;
  579. }
  580. BOOL t_Status ;
  581. KeyRef *t_Key1 = m_ParsedObjectPath->m_paKeys [ 0 ] ;
  582. KeyRef *t_Key2 = m_ParsedObjectPath->m_paKeys [ 1 ] ;
  583. if ( t_Key1 && t_Key2 )
  584. {
  585. if ( _wcsicmp ( t_Key1->m_pName , REF_USER ) == 0 )
  586. {
  587. if ( _wcsicmp ( t_Key2->m_pName , REF_REC ) == 0 )
  588. {
  589. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  590. {
  591. t_Status = Get_UserRecord ( a_ErrorObject , t_Key1 , t_Key2 ) ;
  592. }
  593. else
  594. {
  595. t_Status = FALSE ;
  596. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  597. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  598. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  599. }
  600. }
  601. else
  602. {
  603. t_Status = FALSE ;
  604. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  605. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  606. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  607. }
  608. }
  609. else if ( _wcsicmp ( t_Key2->m_pName , REF_USER ) == 0 )
  610. {
  611. if ( _wcsicmp ( t_Key1->m_pName , REF_REC ) == 0 )
  612. {
  613. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  614. {
  615. t_Status = Get_UserRecord ( a_ErrorObject , t_Key2 , t_Key1 ) ;
  616. }
  617. else
  618. {
  619. t_Status = FALSE ;
  620. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  621. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  622. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  623. }
  624. }
  625. else
  626. {
  627. t_Status = FALSE ;
  628. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  629. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  630. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  631. }
  632. }
  633. else
  634. {
  635. t_Status = FALSE ;
  636. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  637. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  638. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  639. }
  640. }
  641. else
  642. {
  643. t_Status = FALSE ;
  644. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  645. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  646. a_ErrorObject.SetMessage ( L"Failed to get key values" ) ;
  647. }
  648. DebugOut(
  649. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  650. _T(__FILE__),__LINE__,
  651. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:returning with %lx\r\n",
  652. t_Status
  653. ) ;
  654. )
  655. return t_Status ;
  656. }
  657. BOOL GetObjectAsyncEventObject :: Dispatch_ComputerRecord ( WbemProvErrorObject &a_ErrorObject )
  658. {
  659. DebugOut(
  660. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  661. _T(__FILE__),__LINE__,
  662. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord\r\n"
  663. ) ;
  664. )
  665. if (m_ParsedObjectPath->m_dwNumKeys != 2)
  666. {
  667. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  668. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  669. a_ErrorObject.SetMessage ( L"Object path has incorrect number of keys." ) ;
  670. DebugOut(
  671. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  672. _T(__FILE__),__LINE__,
  673. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord: Wrong number of key values\r\n"
  674. ) ;
  675. )
  676. return FALSE;
  677. }
  678. BOOL t_Status ;
  679. KeyRef *t_Key1 = m_ParsedObjectPath->m_paKeys [ 0 ] ;
  680. KeyRef *t_Key2 = m_ParsedObjectPath->m_paKeys [ 1 ] ;
  681. if ( t_Key1 && t_Key2 )
  682. {
  683. if ( _wcsicmp ( t_Key1->m_pName , REF_COMP ) == 0 )
  684. {
  685. if ( _wcsicmp ( t_Key2->m_pName , REF_REC ) == 0 )
  686. {
  687. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  688. {
  689. t_Status = Get_ComputerRecord ( a_ErrorObject , t_Key1 , t_Key2 ) ;
  690. }
  691. else
  692. {
  693. t_Status = FALSE ;
  694. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  695. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  696. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  697. DebugOut(
  698. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  699. _T(__FILE__),__LINE__,
  700. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:Key value(s) have incorrect type\r\n"
  701. ) ;
  702. )
  703. }
  704. }
  705. else
  706. {
  707. t_Status = FALSE ;
  708. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  709. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  710. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  711. DebugOut(
  712. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  713. _T(__FILE__),__LINE__,
  714. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:Key value(s) have incorrect name\r\n"
  715. ) ;
  716. )
  717. }
  718. }
  719. else if ( _wcsicmp ( t_Key2->m_pName , REF_COMP ) == 0 )
  720. {
  721. if ( _wcsicmp ( t_Key1->m_pName , REF_REC ) == 0 )
  722. {
  723. if ( ( t_Key1->m_vValue.vt == VT_BSTR ) && ( t_Key2->m_vValue.vt == VT_BSTR ) )
  724. {
  725. t_Status = Get_ComputerRecord ( a_ErrorObject , t_Key2 , t_Key1 ) ;
  726. }
  727. else
  728. {
  729. t_Status = FALSE ;
  730. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  731. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  732. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect type" ) ;
  733. DebugOut(
  734. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  735. _T(__FILE__),__LINE__,
  736. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:Key value(s) have incorrect type\r\n"
  737. ) ;
  738. )
  739. }
  740. }
  741. else
  742. {
  743. t_Status = FALSE ;
  744. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  745. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  746. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  747. DebugOut(
  748. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  749. _T(__FILE__),__LINE__,
  750. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:Key value(s) have incorrect name\r\n"
  751. ) ;
  752. )
  753. }
  754. }
  755. else
  756. {
  757. t_Status = FALSE ;
  758. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  759. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  760. a_ErrorObject.SetMessage ( L"Key value(s) have incorrect name" ) ;
  761. DebugOut(
  762. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  763. _T(__FILE__),__LINE__,
  764. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:Key value(s) have incorrect name\r\n"
  765. ) ;
  766. )
  767. }
  768. }
  769. else
  770. {
  771. t_Status = FALSE ;
  772. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  773. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_PARAMETER ) ;
  774. a_ErrorObject.SetMessage ( L"Failed to get key values" ) ;
  775. DebugOut(
  776. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  777. _T(__FILE__),__LINE__,
  778. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:Failed to get key values\r\n"
  779. ) ;
  780. )
  781. }
  782. DebugOut(
  783. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  784. _T(__FILE__),__LINE__,
  785. L"GetObjectAsyncEventObject :: Dispatch_ComputerRecord:returning with %lx\r\n",
  786. t_Status
  787. ) ;
  788. )
  789. return t_Status ;
  790. }
  791. BOOL GetObjectAsyncEventObject :: Get_LogRecord ( WbemProvErrorObject &a_ErrorObject ,
  792. KeyRef *a_LogKey , KeyRef *a_RecordKey )
  793. {
  794. DebugOut(
  795. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  796. _T(__FILE__),__LINE__,
  797. L"GetObjectAsyncEventObject :: Get_LogRecord\r\n"
  798. ) ;
  799. )
  800. BOOL retVal = TRUE;
  801. GetObjectAsyncEventObject *t_getRec = new GetObjectAsyncEventObject (
  802. m_Provider , a_RecordKey->m_vValue.bstrVal ,
  803. 0 , m_NotificationHandler , m_Ctx, FALSE ) ;
  804. try
  805. {
  806. if (!t_getRec->GetObject(t_getRec->m_ErrorObject))
  807. {
  808. retVal = FALSE;
  809. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  810. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  811. a_ErrorObject.SetMessage ( L"Failed to verify given eventlog record object" ) ;
  812. DebugOut(
  813. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  814. _T(__FILE__),__LINE__,
  815. L"GetObjectAsyncEventObject :: Get_LogRecord:Failed to verify given eventlog record object\r\n"
  816. ) ;
  817. )
  818. }
  819. else
  820. {
  821. GetObjectAsyncEventObject *t_getLog = new GetObjectAsyncEventObject (
  822. m_Provider , a_LogKey->m_vValue.bstrVal ,
  823. 0 , m_NotificationHandler , m_Ctx, FALSE ) ;
  824. try
  825. {
  826. if (!t_getLog->GetObject(t_getLog->m_ErrorObject))
  827. {
  828. retVal = FALSE;
  829. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  830. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  831. a_ErrorObject.SetMessage ( L"Failed to verify given eventlog file object" ) ;
  832. DebugOut(
  833. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  834. _T(__FILE__),__LINE__,
  835. L"GetObjectAsyncEventObject :: Get_LogRecord:Failed to verify given eventlog file object\r\n"
  836. ) ;
  837. )
  838. }
  839. else
  840. {
  841. //check the association
  842. VARIANT vLog;
  843. VariantInit(&vLog);
  844. HRESULT result = t_getLog->m_Out->Get(PROP_LOGNAME, 0, &vLog, NULL, NULL);
  845. if ((FAILED(result)) || (vLog.vt != VT_BSTR))
  846. {
  847. retVal = FALSE;
  848. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  849. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  850. a_ErrorObject.SetMessage ( L"Failed to get logfile property from eventlog file object" ) ;
  851. DebugOut(
  852. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  853. _T(__FILE__),__LINE__,
  854. L"GetObjectAsyncEventObject :: Get_LogRecord:Failed to get logfile property from eventlog file object\r\n"
  855. ) ;
  856. )
  857. }
  858. else
  859. {
  860. VARIANT vRec;
  861. VariantInit(&vRec);
  862. result = t_getRec->m_Out->Get(LOGFILE_PROP, 0, &vRec, NULL, NULL);
  863. if ((FAILED(result)) || (vRec.vt != VT_BSTR))
  864. {
  865. retVal = FALSE;
  866. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  867. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  868. a_ErrorObject.SetMessage ( L"Failed to get logfile property from eventlog record object" ) ;
  869. DebugOut(
  870. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  871. _T(__FILE__),__LINE__,
  872. L"GetObjectAsyncEventObject :: Get_LogRecord:Failed to get logfile property from eventlog record object\r\n"
  873. ) ;
  874. )
  875. }
  876. else if (_wcsicmp(vRec.bstrVal, vLog.bstrVal) == 0)
  877. {
  878. retVal = GenerateAssocInstance(a_ErrorObject, a_RecordKey->m_vValue.bstrVal,
  879. a_LogKey->m_vValue.bstrVal, REF_REC, REF_LOG,
  880. m_ClassObject, m_NotificationHandler, NULL);
  881. }
  882. else
  883. {
  884. retVal = FALSE;
  885. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  886. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  887. a_ErrorObject.SetMessage ( L"Both objects exist but are not associated" ) ;
  888. DebugOut(
  889. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  890. _T(__FILE__),__LINE__,
  891. L"GetObjectAsyncEventObject :: Get_LogRecord:Both objects exist but are not associated\r\n"
  892. ) ;
  893. )
  894. }
  895. VariantClear(&vRec);
  896. }
  897. VariantClear(&vLog);
  898. }
  899. }
  900. catch(...)
  901. {
  902. delete t_getLog;
  903. throw;
  904. }
  905. delete t_getLog;
  906. }
  907. }
  908. catch (...)
  909. {
  910. delete t_getRec;
  911. throw;
  912. }
  913. delete t_getRec;
  914. DebugOut(
  915. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  916. _T(__FILE__),__LINE__,
  917. L"GetObjectAsyncEventObject :: Dispatch_LogRecord:returning with %lx\r\n",
  918. retVal
  919. ) ;
  920. )
  921. return retVal;
  922. }
  923. BOOL GetObjectAsyncEventObject :: Get_UserRecord ( WbemProvErrorObject &a_ErrorObject ,
  924. KeyRef *a_UserKey , KeyRef *a_RecordKey )
  925. {
  926. DebugOut(
  927. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  928. _T(__FILE__),__LINE__,
  929. L"GetObjectAsyncEventObject :: Get_UserRecord\r\n"
  930. ) ;
  931. )
  932. BOOL retVal = TRUE;
  933. GetObjectAsyncEventObject *t_getRec = new GetObjectAsyncEventObject (
  934. m_Provider , a_RecordKey->m_vValue.bstrVal ,
  935. 0 , m_NotificationHandler , m_Ctx, FALSE) ;
  936. try
  937. {
  938. if (!t_getRec->GetObject(t_getRec->m_ErrorObject))
  939. {
  940. retVal = FALSE;
  941. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  942. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  943. a_ErrorObject.SetMessage ( L"Failed to verify given eventlog record object" ) ;
  944. DebugOut(
  945. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  946. _T(__FILE__),__LINE__,
  947. L"GetObjectAsyncEventObject :: Get_UserRecord:Failed to verify given eventlog record object\r\n"
  948. ) ;
  949. )
  950. }
  951. else
  952. {
  953. IWbemClassObject* userObj = NULL;
  954. IWbemServices *t_Server = m_Provider->GetServer() ;
  955. HRESULT result = t_Server->GetObject(a_UserKey->m_vValue.bstrVal, 0, m_Ctx, &userObj, NULL);
  956. t_Server->Release();
  957. if (FAILED(result))
  958. {
  959. retVal = FALSE;
  960. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  961. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  962. a_ErrorObject.SetMessage ( L"Failed to verify given user object" ) ;
  963. DebugOut(
  964. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  965. _T(__FILE__),__LINE__,
  966. L"GetObjectAsyncEventObject :: Get_UserRecord:Failed to verify given user object\r\n"
  967. ) ;
  968. )
  969. }
  970. else
  971. {
  972. //check the association
  973. VARIANT vUserN;
  974. VariantInit(&vUserN);
  975. result = userObj->Get(PROP_NAME, 0, &vUserN, NULL, NULL);
  976. if ((FAILED(result)) || (vUserN.vt != VT_BSTR))
  977. {
  978. retVal = FALSE;
  979. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  980. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  981. a_ErrorObject.SetMessage ( L"Failed to get name property from eventlog record object" ) ;
  982. DebugOut(
  983. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  984. _T(__FILE__),__LINE__,
  985. L"GetObjectAsyncEventObject :: Get_UserRecord:Failed to get name property from eventlog record object\r\n"
  986. ) ;
  987. )
  988. }
  989. else
  990. {
  991. VARIANT vUserD;
  992. VariantInit(&vUserD);
  993. result = userObj->Get(PROP_DOMAIN, 0, &vUserD, NULL, NULL);
  994. if ((FAILED(result)) || (vUserD.vt != VT_BSTR))
  995. {
  996. retVal = FALSE;
  997. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  998. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  999. a_ErrorObject.SetMessage ( L"Failed to get name property from user object" ) ;
  1000. DebugOut(
  1001. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1002. _T(__FILE__),__LINE__,
  1003. L"GetObjectAsyncEventObject :: Get_UserRecord:Failed to get name property from user object\r\n"
  1004. ) ;
  1005. )
  1006. }
  1007. else
  1008. {
  1009. wchar_t userStr[1024];
  1010. if ( SUCCEEDED ( result = StringCchCopyW ( userStr, 1024, vUserD.bstrVal ) ) )
  1011. {
  1012. if ( SUCCEEDED ( result = StringCchCatW ( userStr, 1024, L"\\" ) ) )
  1013. {
  1014. if ( SUCCEEDED ( result = StringCchCatW ( userStr, 1024, vUserN.bstrVal ) ) )
  1015. {
  1016. VARIANT vRec;
  1017. VariantInit(&vRec);
  1018. result = t_getRec->m_Out->Get(USER_PROP, 0, &vRec, NULL, NULL);
  1019. if ((FAILED(result)) || (vRec.vt != VT_BSTR))
  1020. {
  1021. retVal = FALSE;
  1022. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1023. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  1024. a_ErrorObject.SetMessage ( L"Failed to get user property from eventlog record object" ) ;
  1025. DebugOut(
  1026. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1027. _T(__FILE__),__LINE__,
  1028. L"GetObjectAsyncEventObject :: Get_UserRecord:Failed to get user property from eventlog record object\r\n"
  1029. ) ;
  1030. )
  1031. }
  1032. else if (_wcsicmp(vRec.bstrVal, userStr) == 0)
  1033. {
  1034. retVal = GenerateAssocInstance(a_ErrorObject, a_RecordKey->m_vValue.bstrVal,
  1035. a_UserKey->m_vValue.bstrVal, REF_REC, REF_USER,
  1036. m_ClassObject, m_NotificationHandler, NULL);
  1037. }
  1038. else
  1039. {
  1040. retVal = FALSE;
  1041. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1042. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1043. a_ErrorObject.SetMessage ( L"Both objects exist but are not associated" ) ;
  1044. DebugOut(
  1045. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1046. _T(__FILE__),__LINE__,
  1047. L"GetObjectAsyncEventObject :: Get_UserRecord:Both objects exist but are not associated\r\n"
  1048. ) ;
  1049. )
  1050. }
  1051. VariantClear(&vRec);
  1052. }
  1053. }
  1054. }
  1055. }
  1056. VariantClear(&vUserD);
  1057. }
  1058. VariantClear(&vUserN);
  1059. userObj->Release();
  1060. }
  1061. }
  1062. }
  1063. catch(...)
  1064. {
  1065. delete t_getRec;
  1066. throw;
  1067. }
  1068. delete t_getRec;
  1069. DebugOut(
  1070. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1071. _T(__FILE__),__LINE__,
  1072. L"GetObjectAsyncEventObject :: Get_UserRecord:returning with %lx\r\n",
  1073. retVal
  1074. ) ;
  1075. )
  1076. return retVal;
  1077. }
  1078. BOOL GetObjectAsyncEventObject :: Get_ComputerRecord ( WbemProvErrorObject &a_ErrorObject ,
  1079. KeyRef *a_CompKey , KeyRef *a_RecordKey )
  1080. {
  1081. DebugOut(
  1082. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1083. _T(__FILE__),__LINE__,
  1084. L"GetObjectAsyncEventObject :: Get_ComputerRecord\r\n"
  1085. ) ;
  1086. )
  1087. BOOL retVal = TRUE;
  1088. GetObjectAsyncEventObject *t_getRec = new GetObjectAsyncEventObject (
  1089. m_Provider , a_RecordKey->m_vValue.bstrVal ,
  1090. 0 , m_NotificationHandler , m_Ctx, FALSE ) ;
  1091. try
  1092. {
  1093. if (!t_getRec->GetObject(t_getRec->m_ErrorObject))
  1094. {
  1095. retVal = FALSE;
  1096. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1097. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1098. a_ErrorObject.SetMessage ( L"Failed to verify given eventlog record object" ) ;
  1099. DebugOut(
  1100. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1101. _T(__FILE__),__LINE__,
  1102. L"GetObjectAsyncEventObject :: Get_ComputerRecord:Failed to verify given eventlog record object\r\n"
  1103. ) ;
  1104. )
  1105. }
  1106. else
  1107. {
  1108. IWbemClassObject* compObj = NULL;
  1109. IWbemServices *t_Server = m_Provider->GetServer() ;
  1110. HRESULT result = t_Server->GetObject(a_CompKey->m_vValue.bstrVal, 0, m_Ctx, &compObj, NULL);
  1111. t_Server->Release();
  1112. if (FAILED(result))
  1113. {
  1114. retVal = FALSE;
  1115. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1116. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1117. a_ErrorObject.SetMessage ( L"Failed to verify given computer object" ) ;
  1118. DebugOut(
  1119. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1120. _T(__FILE__),__LINE__,
  1121. L"GetObjectAsyncEventObject :: Get_ComputerRecord:Failed to verify given computer object\r\n"
  1122. ) ;
  1123. )
  1124. }
  1125. else
  1126. {
  1127. //check the association
  1128. VARIANT vComp;
  1129. VariantInit(&vComp);
  1130. result = compObj->Get(PROP_NAME, 0, &vComp, NULL, NULL);
  1131. if ((FAILED(result)) || (vComp.vt != VT_BSTR))
  1132. {
  1133. retVal = FALSE;
  1134. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1135. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  1136. a_ErrorObject.SetMessage ( L"Failed to get Name property from computer object" ) ;
  1137. DebugOut(
  1138. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1139. _T(__FILE__),__LINE__,
  1140. L"GetObjectAsyncEventObject :: Get_ComputerRecord:Failed to get Name property from computer object\r\n"
  1141. ) ;
  1142. )
  1143. }
  1144. else
  1145. {
  1146. VARIANT vRec;
  1147. VariantInit(&vRec);
  1148. result = t_getRec->m_Out->Get(COMPUTER_PROP, 0, &vRec, NULL, NULL);
  1149. if ((FAILED(result)) || (vRec.vt != VT_BSTR))
  1150. {
  1151. retVal = FALSE;
  1152. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1153. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  1154. a_ErrorObject.SetMessage ( L"Failed to get computer property from eventlog record object" ) ;
  1155. DebugOut(
  1156. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1157. _T(__FILE__),__LINE__,
  1158. L"GetObjectAsyncEventObject :: Get_ComputerRecord:Failed to get computer property from eventlog record object\r\n"
  1159. ) ;
  1160. )
  1161. }
  1162. else if (_wcsicmp(vRec.bstrVal, vComp.bstrVal) == 0)
  1163. {
  1164. retVal = GenerateAssocInstance(a_ErrorObject, a_RecordKey->m_vValue.bstrVal,
  1165. a_CompKey->m_vValue.bstrVal, REF_REC, REF_COMP,
  1166. m_ClassObject, m_NotificationHandler, NULL);
  1167. }
  1168. else
  1169. {
  1170. retVal = FALSE;
  1171. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1172. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1173. a_ErrorObject.SetMessage ( L"Both objects exist but are not associated" ) ;
  1174. DebugOut(
  1175. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1176. _T(__FILE__),__LINE__,
  1177. L"GetObjectAsyncEventObject :: Get_ComputerRecord:Both objects exist but are not associated\r\n"
  1178. ) ;
  1179. )
  1180. }
  1181. VariantClear(&vRec);
  1182. }
  1183. VariantClear(&vComp);
  1184. compObj->Release();
  1185. }
  1186. }
  1187. }
  1188. catch (...)
  1189. {
  1190. delete t_getRec;
  1191. throw;
  1192. }
  1193. delete t_getRec;
  1194. DebugOut(
  1195. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1196. _T(__FILE__),__LINE__,
  1197. L"GetObjectAsyncEventObject :: Get_ComputerRecord:returning with %lx\r\n",
  1198. retVal
  1199. ) ;
  1200. )
  1201. return retVal;
  1202. }
  1203. BOOL GetObjectAsyncEventObject :: Get_EventLog ( WbemProvErrorObject &a_ErrorObject , KeyRef *a_FileKey)
  1204. {
  1205. DebugOut(
  1206. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1207. _T(__FILE__),__LINE__,
  1208. L"GetObjectAsyncEventObject :: Get_EventLog\r\n"
  1209. ) ;
  1210. )
  1211. BOOL retVal = FALSE;
  1212. CStringW log = CEventLogFile::GetLogName((const wchar_t*)a_FileKey->m_vValue.bstrVal);
  1213. if (log.IsEmpty())
  1214. {
  1215. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  1216. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1217. a_ErrorObject.SetMessage ( L"Failed to translate key to instance of logfile." ) ;
  1218. DebugOut(
  1219. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1220. _T(__FILE__),__LINE__,
  1221. L"GetObjectAsyncEventObject :: Get_EventLog: Failed to get instance of logfile named %s\r\n",
  1222. (const wchar_t*)a_FileKey->m_vValue.bstrVal
  1223. ) ;
  1224. )
  1225. }
  1226. else
  1227. {
  1228. CEventlogFileAttributes evtlog(log);
  1229. IWbemClassObject* pInst = NULL;
  1230. if (evtlog.GenerateInstance(m_ClassObject, m_AClassObject, &pInst))
  1231. {
  1232. if (m_bIndicate)
  1233. {
  1234. m_NotificationHandler->Indicate ( 1 , & pInst ) ;
  1235. pInst->Release();
  1236. }
  1237. else
  1238. {
  1239. m_Out = pInst;
  1240. }
  1241. retVal = TRUE;
  1242. }
  1243. else
  1244. {
  1245. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_PARAMETER ) ;
  1246. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  1247. a_ErrorObject.SetMessage ( L"Failed while generating instance of logfile." ) ;
  1248. DebugOut(
  1249. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1250. _T(__FILE__),__LINE__,
  1251. L"GetObjectAsyncEventObject :: Get_EventLog: Failed to generate instance of logfile named %s\r\n",
  1252. log
  1253. ) ;
  1254. )
  1255. }
  1256. }
  1257. DebugOut(
  1258. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1259. _T(__FILE__),__LINE__,
  1260. L"GetObjectAsyncEventObject :: Get_EventLog:returning with %lx\r\n",
  1261. retVal
  1262. ) ;
  1263. )
  1264. return retVal;
  1265. }
  1266. BOOL GetObjectAsyncEventObject :: Get_Record ( WbemProvErrorObject &a_ErrorObject , KeyRef *a_FileKey , KeyRef *a_RecordKey )
  1267. {
  1268. DebugOut(
  1269. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1270. _T(__FILE__),__LINE__,
  1271. L"GetObjectAsyncEventObject :: Get_Record\r\n"
  1272. ) ;
  1273. )
  1274. BOOL retVal = TRUE;
  1275. CEventLogFile evtlog(a_FileKey->m_vValue.bstrVal, TRUE);
  1276. if (!evtlog.IsValid())
  1277. {
  1278. //failed to find log i.e. no such record??
  1279. retVal = FALSE;
  1280. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1281. if ((evtlog.GetReason() == ERROR_ACCESS_DENIED) || (evtlog.GetReason() == ERROR_PRIVILEGE_NOT_HELD))
  1282. {
  1283. a_ErrorObject.SetWbemStatus ( WBEM_E_ACCESS_DENIED ) ;
  1284. a_ErrorObject.SetPrivilegeFailed();
  1285. a_ErrorObject.SetSecurityPrivRequired();
  1286. a_ErrorObject.SetSecurityPrivFailed();
  1287. }
  1288. else
  1289. {
  1290. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1291. }
  1292. a_ErrorObject.SetMessage ( L"Failed to find the logfile" ) ;
  1293. DebugOut(
  1294. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1295. _T(__FILE__),__LINE__,
  1296. L"GetObjectAsyncEventObject :: Get_Record:Failed to find the logfile %s\r\n",
  1297. a_FileKey->m_vValue.bstrVal
  1298. ) ;
  1299. )
  1300. }
  1301. else
  1302. {
  1303. if (0 == evtlog.ReadRecord(a_RecordKey->m_vValue.lVal))
  1304. {
  1305. EVENTLOGRECORD* pEvt = (EVENTLOGRECORD*) evtlog.GetBuffer();
  1306. CEventlogRecord evtRec(a_FileKey->m_vValue.bstrVal, pEvt, NULL, m_ClassObject, m_AClassObject);
  1307. IWbemClassObject* pInst = NULL;
  1308. if (evtRec.GenerateInstance(&pInst))
  1309. {
  1310. if (m_bIndicate)
  1311. {
  1312. m_NotificationHandler->Indicate ( 1 , & pInst ) ;
  1313. pInst->Release();
  1314. }
  1315. else
  1316. {
  1317. m_Out = pInst;
  1318. }
  1319. }
  1320. else
  1321. {
  1322. //failed to create record
  1323. retVal = FALSE;
  1324. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1325. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  1326. a_ErrorObject.SetMessage ( L"Failed to create instance from Eventlog data" ) ;
  1327. DebugOut(
  1328. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1329. _T(__FILE__),__LINE__,
  1330. L"GetObjectAsyncEventObject :: Get_Record:Failed to create instance from Eventlog data\r\n"
  1331. ) ;
  1332. )
  1333. }
  1334. }
  1335. else
  1336. {
  1337. //record not found i.e. no such record??
  1338. retVal = FALSE;
  1339. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  1340. a_ErrorObject.SetWbemStatus ( WBEM_E_NOT_FOUND ) ;
  1341. a_ErrorObject.SetMessage ( L"Failed to find the record in the logfile" ) ;
  1342. DebugOut(
  1343. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1344. _T(__FILE__),__LINE__,
  1345. L"GetObjectAsyncEventObject :: Get_Record:Failed to find the record in the logfile\r\n"
  1346. ) ;
  1347. )
  1348. }
  1349. }
  1350. DebugOut(
  1351. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1352. _T(__FILE__),__LINE__,
  1353. L"GetObjectAsyncEventObject :: Get_Record:returning with %lx\r\n",
  1354. retVal
  1355. ) ;
  1356. )
  1357. return retVal;
  1358. }
  1359. GetObjectAsyncEventObject :: GetObjectAsyncEventObject (
  1360. CImpNTEvtProv *a_Provider ,
  1361. wchar_t* a_ObjectPath ,
  1362. ULONG a_OperationFlag ,
  1363. IWbemObjectSink *a_NotificationHandler ,
  1364. IWbemContext *a_Ctx ,
  1365. BOOL a_bIndicate
  1366. ) : WbemTaskObject ( a_Provider , a_NotificationHandler , a_OperationFlag , a_Ctx ) ,
  1367. m_Class ( NULL ) , m_bIndicate ( a_bIndicate ) , m_Out ( NULL ) ,
  1368. m_ParsedObjectPath ( NULL )
  1369. {
  1370. m_ObjectPath = UnicodeStringDuplicate ( a_ObjectPath ) ;
  1371. }
  1372. GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject ()
  1373. {
  1374. DebugOut(
  1375. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1376. _T(__FILE__),__LINE__,
  1377. L"GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject: Object path (%s) SetStatus with %lx\r\n",
  1378. m_ObjectPath, m_ErrorObject.GetWbemStatus ()
  1379. ) ;
  1380. )
  1381. delete [] m_ObjectPath ;
  1382. delete m_ParsedObjectPath ;
  1383. // Get Status object
  1384. if (m_bIndicate)
  1385. {
  1386. DebugOut(
  1387. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1388. _T(__FILE__),__LINE__,
  1389. L"GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject: Indicating Object path (%s) SetStatus with %lx\r\n",
  1390. m_ObjectPath, m_ErrorObject.GetWbemStatus ()
  1391. ) ;
  1392. )
  1393. IWbemClassObject *t_NotifyStatus = NULL ;
  1394. BOOL t_Status = TRUE;
  1395. if (WBEM_NO_ERROR != m_ErrorObject.GetWbemStatus ())
  1396. {
  1397. t_Status = GetExtendedNotifyStatusObject ( &t_NotifyStatus ) ;
  1398. }
  1399. if ( t_Status )
  1400. {
  1401. DebugOut(
  1402. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1403. _T(__FILE__),__LINE__,
  1404. L"GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject: Really Indicating Object path (%s) SetStatus with %lx\r\n",
  1405. m_ObjectPath, m_ErrorObject.GetWbemStatus ()
  1406. ) ;
  1407. )
  1408. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_ErrorObject.GetWbemStatus () , 0 , t_NotifyStatus ) ;
  1409. if (t_NotifyStatus)
  1410. {
  1411. t_NotifyStatus->Release () ;
  1412. }
  1413. DebugOut(
  1414. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1415. _T(__FILE__),__LINE__,
  1416. L"GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject:Indicated status, released objectsink\r\n"
  1417. ) ;
  1418. )
  1419. }
  1420. else
  1421. {
  1422. DebugOut(
  1423. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1424. _T(__FILE__),__LINE__,
  1425. L"GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject: Failed to get Status object Object path (%s)\r\n",
  1426. m_ObjectPath
  1427. ) ;
  1428. )
  1429. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0 , m_ErrorObject.GetWbemStatus () , 0 , NULL ) ;
  1430. }
  1431. }
  1432. else
  1433. {
  1434. DebugOut(
  1435. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1436. _T(__FILE__),__LINE__,
  1437. L"GetObjectAsyncEventObject :: ~GetObjectAsyncEventObject:Released object without indicating it\r\n"
  1438. ) ;
  1439. )
  1440. if (m_Out != NULL)
  1441. {
  1442. m_Out->Release();
  1443. }
  1444. }
  1445. }
  1446. void GetObjectAsyncEventObject :: Process ()
  1447. {
  1448. GetObject ( m_ErrorObject ) ;
  1449. }