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.

4308 lines
115 KiB

  1. //***************************************************************************
  2. //
  3. // NTEVTQUERY.CPP
  4. //
  5. // Module: WBEM NT EVENT PROVIDER
  6. //
  7. // Purpose: Contains the ExecQuery implementation
  8. //
  9. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  10. //
  11. //***************************************************************************
  12. #include "precomp.h"
  13. #include <wbemtime.h>
  14. #define NTEVT_DECPOS 14
  15. #define NTEVT_SGNPOS 21
  16. #define NTEVT_DMTFLEN 25
  17. wchar_t* CheckForSpecialCharacters(const wchar_t* wstr)
  18. {
  19. if (wstr == NULL)
  20. {
  21. return NULL;
  22. }
  23. int wstrlen = wcslen(wstr) * 2;
  24. wchar_t* ret = new wchar_t[wstrlen + 1];
  25. const wchar_t* tmp = wstr;
  26. int x = 0;
  27. while ((*tmp != L'\0') && (x < wstrlen))
  28. {
  29. if (*tmp == L'\\')
  30. {
  31. ret[x++] = L'\\';
  32. }
  33. ret[x++] = *tmp;
  34. tmp++;
  35. }
  36. ret[x] = L'\0';
  37. return ret;
  38. }
  39. BOOL GenerateAssocInstance ( WbemProvErrorObject &a_ErrorObject,
  40. const wchar_t* objPath1,
  41. const wchar_t* objPath2,
  42. wchar_t* prop1,
  43. wchar_t* prop2,
  44. IWbemClassObject* pClassObject,
  45. IWbemObjectSink* pNtfcnHandler,
  46. BOOL *pbIndicated)
  47. {
  48. DebugOut(
  49. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  50. _T(__FILE__),__LINE__,
  51. L"GenerateAssocInstance\r\n"
  52. );
  53. )
  54. IWbemClassObject* pInst = NULL;
  55. HRESULT result = pClassObject->SpawnInstance(0, &pInst);
  56. BOOL retVal = TRUE;
  57. if (pbIndicated)
  58. {
  59. *pbIndicated = FALSE;
  60. }
  61. if (FAILED(result))
  62. {
  63. retVal = FALSE;
  64. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  65. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  66. a_ErrorObject.SetMessage ( L"Failed to spawn association instance." );
  67. DebugOut(
  68. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  69. _T(__FILE__),__LINE__,
  70. L"GenerateAssocInstance:Failed to spawn association instance.\r\n"
  71. );
  72. )
  73. }
  74. else
  75. {
  76. VARIANT v;
  77. VariantInit (&v);
  78. v.vt = VT_BSTR;
  79. HRESULT result = WBEM_E_OUT_OF_MEMORY ;
  80. v.bstrVal = SysAllocString(objPath1);
  81. if ( v.bstrVal )
  82. {
  83. result = pInst->Put(prop1, 0, &v, 0);
  84. }
  85. VariantClear(&v);
  86. if (FAILED(result))
  87. {
  88. retVal = FALSE;
  89. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  90. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  91. a_ErrorObject.SetMessage ( L"Failed to set association key property." );
  92. DebugOut(
  93. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  94. _T(__FILE__),__LINE__,
  95. L"GenerateAssocInstance:Failed to set association key property\r\n"
  96. );
  97. )
  98. }
  99. else
  100. {
  101. VariantInit (&v);
  102. v.vt = VT_BSTR;
  103. HRESULT result = WBEM_E_OUT_OF_MEMORY ;
  104. v.bstrVal = SysAllocString(objPath2);
  105. if ( v.bstrVal )
  106. {
  107. result = pInst->Put(prop2, 0, &v, 0);
  108. }
  109. VariantClear(&v);
  110. if (FAILED(result))
  111. {
  112. retVal = FALSE;
  113. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  114. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  115. a_ErrorObject.SetMessage ( L"Failed to set association key property." );
  116. DebugOut(
  117. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  118. _T(__FILE__),__LINE__,
  119. L"GenerateAssocInstance:Failed to set association key property\r\n"
  120. );
  121. )
  122. }
  123. else
  124. {
  125. result = pNtfcnHandler->Indicate ( 1, & pInst );
  126. if (FAILED(result))
  127. {
  128. retVal = FALSE;
  129. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  130. a_ErrorObject.SetMessage ( L"Failed to indicate association instance." );
  131. }
  132. else
  133. {
  134. if (pbIndicated)
  135. {
  136. *pbIndicated = TRUE;
  137. }
  138. }
  139. }
  140. }
  141. pInst->Release();
  142. }
  143. DebugOut(
  144. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  145. _T(__FILE__),__LINE__,
  146. L"GenerateAssocInstance:returning %lx\r\n",
  147. retVal
  148. );
  149. )
  150. return retVal;
  151. }
  152. BOOL ExecQueryAsyncEventObject :: OptimizeAssocQuery (
  153. WbemProvErrorObject &a_ErrorObject,
  154. BSTR *a_ObjectPath
  155. )
  156. {
  157. *a_ObjectPath = NULL;
  158. BOOL t_Status = FALSE;
  159. SQL_LEVEL_1_TOKEN *pArrayOfTokens = m_RPNExpression->pArrayOfTokens;
  160. int nNumTokens = m_RPNExpression->nNumTokens;
  161. if ( ! pArrayOfTokens )
  162. {
  163. return t_Status;
  164. }
  165. if (( nNumTokens != 3 ) && ( nNumTokens != 1 ))
  166. {
  167. return t_Status;
  168. }
  169. if ( pArrayOfTokens [ 0 ].dwPropertyFunction != SQL_LEVEL_1_TOKEN :: IFUNC_NONE )
  170. {
  171. return t_Status;
  172. }
  173. if ( pArrayOfTokens [ 0 ].dwConstFunction != SQL_LEVEL_1_TOKEN :: IFUNC_NONE )
  174. {
  175. return t_Status;
  176. }
  177. if ( pArrayOfTokens [ 0 ].nTokenType != SQL_LEVEL_1_TOKEN :: OP_EXPRESSION )
  178. {
  179. return t_Status;
  180. }
  181. if ( pArrayOfTokens [ 0 ].vConstValue.vt != VT_BSTR )
  182. {
  183. return t_Status;
  184. }
  185. if ( pArrayOfTokens [ 0 ].vConstValue.bstrVal == NULL )
  186. {
  187. return t_Status;
  188. }
  189. if ( nNumTokens == 3 )
  190. {
  191. if ( pArrayOfTokens [ 1 ].dwPropertyFunction != SQL_LEVEL_1_TOKEN :: IFUNC_NONE )
  192. {
  193. return t_Status;
  194. }
  195. if ( pArrayOfTokens [ 1 ].dwConstFunction != SQL_LEVEL_1_TOKEN :: IFUNC_NONE )
  196. {
  197. return t_Status;
  198. }
  199. if ( pArrayOfTokens [ 1 ].nTokenType != SQL_LEVEL_1_TOKEN :: OP_EXPRESSION )
  200. {
  201. return t_Status;
  202. }
  203. if ( pArrayOfTokens [ 1 ].vConstValue.vt != VT_BSTR )
  204. {
  205. return t_Status;
  206. }
  207. if ( pArrayOfTokens [ 1 ].vConstValue.bstrVal == NULL )
  208. {
  209. return t_Status;
  210. }
  211. if ( pArrayOfTokens [ 2 ].nTokenType != SQL_LEVEL_1_TOKEN :: TOKEN_OR )
  212. {
  213. return t_Status;
  214. }
  215. if (_wcsicmp(pArrayOfTokens[0].vConstValue.bstrVal, pArrayOfTokens[1].vConstValue.bstrVal) != 0)
  216. {
  217. return t_Status;
  218. }
  219. *a_ObjectPath = SysAllocString ( pArrayOfTokens [ 0 ].vConstValue.bstrVal );
  220. if ( *a_ObjectPath )
  221. {
  222. t_Status = TRUE;
  223. }
  224. }
  225. else
  226. {
  227. *a_ObjectPath = SysAllocString ( pArrayOfTokens [ 0 ].vConstValue.bstrVal );
  228. if ( *a_ObjectPath )
  229. {
  230. t_Status = TRUE;
  231. }
  232. }
  233. return t_Status;
  234. }
  235. wchar_t* ExecQueryAsyncEventObject :: GetClassFromPath(wchar_t* path)
  236. {
  237. wchar_t* retVal = NULL;
  238. CObjectPathParser pathParser;
  239. ParsedObjectPath *parsedObjectPath = NULL;
  240. if (!pathParser.Parse(path, &parsedObjectPath))
  241. {
  242. retVal = UnicodeStringDuplicate(parsedObjectPath->m_pClass);
  243. }
  244. delete parsedObjectPath;
  245. return retVal;
  246. }
  247. BOOL ExecQueryAsyncEventObject :: Query_LogRecord ( WbemProvErrorObject &a_ErrorObject )
  248. {
  249. DebugOut(
  250. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  251. _T(__FILE__),__LINE__,
  252. L"ExecQueryAsyncEventObject :: Query_LogRecord\r\n"
  253. );
  254. )
  255. BSTR t_ObjectPath = NULL;
  256. BOOL retVal = TRUE;
  257. BOOL bGenAll = FALSE;
  258. if (OptimizeAssocQuery (a_ErrorObject, &t_ObjectPath))
  259. {
  260. GetObjectAsyncEventObject *t_getObj = new GetObjectAsyncEventObject (
  261. m_Provider, t_ObjectPath,
  262. 0, m_NotificationHandler, m_Ctx, FALSE);
  263. BOOL t_Status = t_getObj->GetObject(t_getObj->m_ErrorObject);
  264. if (! t_Status )
  265. {
  266. bGenAll = TRUE;
  267. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  268. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  269. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  270. DebugOut(
  271. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  272. _T(__FILE__),__LINE__,
  273. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to verify object given in query\r\n"
  274. );
  275. )
  276. }
  277. else
  278. {
  279. VARIANT v;
  280. VariantInit(&v);
  281. HRESULT result = t_getObj->m_Out->Get(CLASS_PROP, 0, &v, NULL, NULL);
  282. if ((FAILED(result)) || (v.vt != VT_BSTR))
  283. {
  284. retVal = FALSE;
  285. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  286. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  287. a_ErrorObject.SetMessage ( L"Failed to get class name of object given in query" );
  288. DebugOut(
  289. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  290. _T(__FILE__),__LINE__,
  291. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to get class name of object given in query\r\n"
  292. );
  293. )
  294. }
  295. else
  296. {
  297. if (_wcsicmp(v.bstrVal, NTEVTLOG_CLASS) == 0)
  298. {
  299. VARIANT vLog;
  300. VariantInit(&vLog);
  301. result = t_getObj->m_Out->Get(PROP_LOGNAME, 0, &vLog, NULL, NULL);
  302. if ((FAILED(result)) || (vLog.vt != VT_BSTR))
  303. {
  304. retVal = FALSE;
  305. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  306. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  307. a_ErrorObject.SetMessage ( L"Failed to get log file name of object given in query" );
  308. DebugOut(
  309. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  310. _T(__FILE__),__LINE__,
  311. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to get log file name of object given in query\r\n"
  312. );
  313. )
  314. }
  315. else
  316. {
  317. //get all records for this log
  318. retVal = GenerateLogAssocs(a_ErrorObject, t_ObjectPath, vLog.bstrVal, TRUE, NULL);
  319. }
  320. VariantClear(&vLog);
  321. }
  322. else if (_wcsicmp(v.bstrVal, NTEVT_CLASS) == 0)
  323. {
  324. VARIANT vLog;
  325. VariantInit(&vLog);
  326. result = t_getObj->m_Out->Get(LOGFILE_PROP, 0, &vLog, NULL, NULL);
  327. if ((FAILED(result)) || (vLog.vt != VT_BSTR))
  328. {
  329. retVal = FALSE;
  330. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  331. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  332. a_ErrorObject.SetMessage ( L"Failed to get log file name of object given in query" );
  333. DebugOut(
  334. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  335. _T(__FILE__),__LINE__,
  336. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to get log file name of object given in query\r\n"
  337. );
  338. )
  339. }
  340. else
  341. {
  342. //get log for this record
  343. CStringW logNameVal(EVENTLOG_BASE);
  344. logNameVal += L"\\";
  345. logNameVal += CStringW(vLog.bstrVal);
  346. HKEY hkResult;
  347. LONG res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, logNameVal, 0,
  348. KEY_READ, &hkResult);
  349. if (res != ERROR_SUCCESS)
  350. {
  351. retVal = FALSE;
  352. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  353. if ((res == ERROR_ACCESS_DENIED) || (res == ERROR_PRIVILEGE_NOT_HELD))
  354. {
  355. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  356. a_ErrorObject.SetPrivilegeFailed();
  357. a_ErrorObject.SetSecurityPrivRequired();
  358. a_ErrorObject.SetSecurityPrivFailed();
  359. }
  360. else
  361. {
  362. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  363. }
  364. a_ErrorObject.SetMessage ( L"Failed to get log file associated to object given in query");
  365. DebugOut(
  366. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  367. _T(__FILE__),__LINE__,
  368. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to get log file associated to object given in query\r\n"
  369. );
  370. )
  371. }
  372. else
  373. {
  374. CStringW logPath(PROP_START_LOG);
  375. wchar_t* spchrs = CheckForSpecialCharacters(CEventLogFile::GetFileName(hkResult));
  376. RegCloseKey(hkResult);
  377. logPath += CStringW(spchrs);
  378. delete [] spchrs;
  379. logPath += PROP_END_QUOTE;
  380. retVal = GenerateAssocInstance(a_ErrorObject, t_ObjectPath, logPath, REF_REC, REF_LOG,
  381. m_ClassObject, m_NotificationHandler, NULL);
  382. }
  383. }
  384. VariantClear(&vLog);
  385. }
  386. else
  387. {
  388. retVal = FALSE;
  389. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  390. a_ErrorObject.SetWbemStatus ( WBEM_E_PROVIDER_NOT_CAPABLE );
  391. a_ErrorObject.SetMessage ( L"Class name of object given in query is not a property of Association class" );
  392. DebugOut(
  393. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  394. _T(__FILE__),__LINE__,
  395. L"ExecQueryAsyncEventObject :: Query_LogRecord:Class name of object given in query is not a property of Association class\r\n"
  396. );
  397. )
  398. }
  399. }
  400. VariantClear(&v);
  401. }
  402. SysFreeString (t_ObjectPath);
  403. delete t_getObj;
  404. if ( FAILED ( WbemCoImpersonateClient() ) )
  405. {
  406. m_ErrorObject.SetStatus (WBEM_PROV_E_ACCESS_DENIED);
  407. m_ErrorObject.SetWbemStatus (WBEM_E_ACCESS_DENIED);
  408. m_ErrorObject.SetMessage (L"Access denied, impersonation level too low");
  409. return FALSE ;
  410. }
  411. }
  412. else
  413. {
  414. bGenAll = TRUE;
  415. }
  416. if (bGenAll)
  417. {
  418. //get all instances...
  419. // open registry for log names
  420. HKEY hkResult;
  421. LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  422. EVENTLOG_BASE, 0,
  423. KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
  424. &hkResult);
  425. if (status != ERROR_SUCCESS)
  426. {
  427. // indicate error
  428. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  429. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  430. {
  431. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  432. a_ErrorObject.SetPrivilegeFailed();
  433. a_ErrorObject.SetSecurityPrivRequired();
  434. a_ErrorObject.SetSecurityPrivFailed();
  435. }
  436. else
  437. {
  438. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  439. }
  440. a_ErrorObject.SetMessage ( L"Failed to open the Eventlog registry for logfiles." );
  441. DebugOut(
  442. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  443. _T(__FILE__),__LINE__,
  444. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to open the Eventlog registry for logfiles - Returning FALSE.\r\n"
  445. );
  446. )
  447. retVal = FALSE;
  448. return retVal;
  449. }
  450. DWORD iValue = 0;
  451. WCHAR t_logname[MAX_PATH+1];
  452. DWORD t_lognameSize = MAX_PATH+1;
  453. BOOL bContinue = TRUE;
  454. // read all entries under this key to find all logfiles...
  455. while (bContinue && ((status = RegEnumKey(hkResult, iValue, t_logname, t_lognameSize)) != ERROR_NO_MORE_ITEMS))
  456. {
  457. // if error during read
  458. if (status != ERROR_SUCCESS)
  459. {
  460. // indicate error
  461. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  462. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  463. {
  464. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  465. a_ErrorObject.SetPrivilegeFailed();
  466. a_ErrorObject.SetSecurityPrivRequired();
  467. a_ErrorObject.SetSecurityPrivFailed();
  468. }
  469. else
  470. {
  471. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  472. }
  473. a_ErrorObject.SetMessage ( L"Failed while enumerating the Eventlog registry for logfiles." );
  474. retVal = FALSE;
  475. DebugOut(
  476. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  477. _T(__FILE__),__LINE__,
  478. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed while enumerating the Eventlog registry for logfiles.\r\n"
  479. );
  480. )
  481. break;
  482. }
  483. //create the associations for this logfile...
  484. HKEY hkLog;
  485. if (ERROR_SUCCESS == RegOpenKeyEx(hkResult, t_logname, 0, KEY_QUERY_VALUE, &hkLog))
  486. {
  487. CStringW t_logPath(PROP_START_LOG);
  488. CStringW t_evtlognamestr = CEventLogFile::GetFileName(hkLog);
  489. if (!t_evtlognamestr.IsEmpty())
  490. {
  491. wchar_t* spchrs = CheckForSpecialCharacters(t_evtlognamestr);
  492. t_logPath += CStringW(spchrs);
  493. delete [] spchrs;
  494. t_logPath += PROP_END_QUOTE;
  495. if (!GenerateLogAssocs(a_ErrorObject, t_logPath, t_logname, FALSE, &bContinue))
  496. {
  497. retVal = FALSE;
  498. }
  499. }
  500. else
  501. {
  502. retVal = FALSE;
  503. DebugOut(
  504. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  505. _T(__FILE__),__LINE__,
  506. L"ExecQueryAsyncEventObject :: Query_LogRecord:Failed to get file for the %s logfile.\r\n",
  507. t_logname
  508. );
  509. )
  510. }
  511. RegCloseKey(hkLog);
  512. }
  513. // read next parameter
  514. iValue++;
  515. } // end while
  516. RegCloseKey(hkResult);
  517. }
  518. DebugOut(
  519. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  520. _T(__FILE__),__LINE__,
  521. L"ExecQueryAsyncEventObject :: Query_LogRecord:returning %lx\r\n",
  522. retVal
  523. );
  524. )
  525. return retVal;
  526. }
  527. BOOL ExecQueryAsyncEventObject :: GenerateLogAssocs( WbemProvErrorObject &a_ErrorObject,
  528. const wchar_t* logPath,
  529. const wchar_t* logName,
  530. BOOL bVerifyLogname,
  531. BOOL *pbContinue)
  532. {
  533. BOOL retVal = TRUE;
  534. if (pbContinue)
  535. {
  536. *pbContinue = TRUE;
  537. }
  538. CEventLogFile evtLog(logName, bVerifyLogname);
  539. DebugOut(
  540. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  541. _T(__FILE__),__LINE__,
  542. L"ExecQueryAsyncEventObject :: GenerateLogAssocs\r\n"
  543. );
  544. )
  545. if (!evtLog.IsValid())
  546. {
  547. retVal = FALSE;
  548. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  549. if ((evtLog.GetReason() == ERROR_ACCESS_DENIED) || (evtLog.GetReason() == ERROR_PRIVILEGE_NOT_HELD))
  550. {
  551. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  552. a_ErrorObject.SetSecurityPrivRequired();
  553. a_ErrorObject.SetSecurityPrivFailed();
  554. a_ErrorObject.SetPrivilegeFailed();
  555. }
  556. else
  557. {
  558. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  559. }
  560. a_ErrorObject.SetMessage ( L"Failed to open eventlog to enumerate records for Log Association." );
  561. DebugOut(
  562. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  563. _T(__FILE__),__LINE__,
  564. L"ExecQueryAsyncEventObject :: GenerateLogAssocs:Failed to open eventlog to enumerate records for Log Association\r\n"
  565. );
  566. )
  567. }
  568. else
  569. {
  570. DWORD recId;
  571. DWORD numRecs;
  572. if (evtLog.GetLastRecordID(recId, numRecs))
  573. {
  574. for (DWORD x = recId; (x > (recId - numRecs)); x--)
  575. {
  576. CStringW recPath(PROP_START_REC);
  577. recPath += CStringW(logName);
  578. recPath += PROP_MID_REC;
  579. wchar_t buff[40];
  580. recPath += CStringW(_ultow((ULONG)x, buff, 10));
  581. if (!GenerateAssocInstance(a_ErrorObject, recPath,
  582. logPath, REF_REC, REF_LOG,
  583. m_ClassObject, m_NotificationHandler, pbContinue))
  584. {
  585. retVal = FALSE;
  586. }
  587. if (pbContinue && !(*pbContinue))
  588. {
  589. break;
  590. }
  591. }
  592. }
  593. else
  594. {
  595. retVal = FALSE;
  596. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  597. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  598. a_ErrorObject.SetMessage ( L"Failed to determine number of records in eventlog for log associations" );
  599. DebugOut(
  600. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  601. _T(__FILE__),__LINE__,
  602. L"ExecQueryAsyncEventObject :: GenerateLogAssocs:Failed to determine number of records in eventlog for log associations\r\n"
  603. );
  604. )
  605. }
  606. }
  607. DebugOut(
  608. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  609. _T(__FILE__),__LINE__,
  610. L"ExecQueryAsyncEventObject :: GenerateLogAssocs:Returning %lx\r\n",
  611. retVal
  612. );
  613. )
  614. return retVal;
  615. }
  616. BOOL ExecQueryAsyncEventObject :: Query_UserRecord ( WbemProvErrorObject &a_ErrorObject )
  617. {
  618. DebugOut(
  619. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  620. _T(__FILE__),__LINE__,
  621. L"ExecQueryAsyncEventObject :: Query_UserRecord\r\n"
  622. );
  623. )
  624. BSTR t_ObjectPath = NULL;
  625. BOOL retVal = TRUE;
  626. BOOL bGenAll = FALSE;
  627. if (OptimizeAssocQuery (a_ErrorObject, &t_ObjectPath))
  628. {
  629. wchar_t* str_classname = GetClassFromPath(t_ObjectPath);
  630. if (str_classname == NULL)
  631. {
  632. bGenAll = TRUE;
  633. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  634. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  635. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  636. DebugOut(
  637. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  638. _T(__FILE__),__LINE__,
  639. L"ExecQueryAsyncEventObject :: Query_UserRecord:Failed to verify object given in query\r\n"
  640. );
  641. )
  642. }
  643. else if (_wcsicmp(str_classname, USER_CLASS) == 0)
  644. {
  645. IWbemClassObject* pObj = NULL;
  646. IWbemServices *t_Server = m_Provider->GetServer();
  647. HRESULT result = t_Server->GetObject(t_ObjectPath, 0, m_Ctx, &pObj, NULL);
  648. t_Server->Release();
  649. if (FAILED(result))
  650. {
  651. retVal = FALSE;
  652. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  653. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  654. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  655. DebugOut(
  656. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  657. _T(__FILE__),__LINE__,
  658. L"ExecQueryAsyncEventObject :: Query_UserRecord:Failed to verify object given in query\r\n"
  659. );
  660. )
  661. }
  662. else
  663. {
  664. pObj->Release ();
  665. //get all records...
  666. retVal = GenerateCompUserAssocs(a_ErrorObject, FALSE);
  667. }
  668. delete [] str_classname;
  669. }
  670. else if (_wcsicmp(str_classname, NTEVT_CLASS) == 0)
  671. {
  672. GetObjectAsyncEventObject *t_getRec = new GetObjectAsyncEventObject (
  673. m_Provider, t_ObjectPath,
  674. 0, m_NotificationHandler,
  675. m_Ctx, FALSE );
  676. if (t_getRec->GetObject(t_getRec->m_ErrorObject))
  677. {
  678. VARIANT vUser;
  679. CIMTYPE cT;
  680. VariantInit(&vUser);
  681. HRESULT result = t_getRec->m_Out->Get(USER_PROP, 0, &vUser, &cT, NULL);
  682. if ((FAILED(result)) || (cT != CIM_STRING))
  683. {
  684. retVal = FALSE;
  685. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  686. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  687. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  688. DebugOut(
  689. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  690. _T(__FILE__),__LINE__,
  691. L"ExecQueryAsyncEventObject :: Query_UserRecord:Failed to get user name of object given in query\r\n"
  692. );
  693. )
  694. }
  695. else
  696. {
  697. if ((vUser.vt == VT_BSTR) && (vUser.bstrVal != NULL))
  698. {
  699. //get user for this record
  700. CStringW userVal(vUser.bstrVal);
  701. int pos = userVal.Find(L'\\');
  702. if (pos != -1)
  703. {
  704. CStringW dom = userVal.Left(pos);
  705. CStringW nm = userVal.Right(userVal.GetLength() - 1 - pos);
  706. if (!nm.IsEmpty() && !dom.IsEmpty())
  707. {
  708. wchar_t userPath[1024];
  709. if ( SUCCEEDED ( StringCchCopyW ( userPath, 1024, PROP_START_USER ) ) )
  710. {
  711. if ( SUCCEEDED ( StringCchCatW ( userPath, 1024, dom ) ) )
  712. {
  713. if ( SUCCEEDED ( StringCchCatW ( userPath, 1024, PROP_MID_USER ) ) )
  714. {
  715. if ( SUCCEEDED ( StringCchCatW ( userPath, 1024, nm ) ) )
  716. {
  717. if ( SUCCEEDED ( StringCchCatW ( userPath, 1024, PROP_END_QUOTE ) ) )
  718. {
  719. IWbemClassObject* pUObj = NULL;
  720. IWbemServices *t_Server = m_Provider->GetServer();
  721. HRESULT result = WBEM_E_OUT_OF_MEMORY ;
  722. BSTR userStr = SysAllocString(userPath);
  723. if ( userStr )
  724. {
  725. result = t_Server->GetObject(userStr, 0, m_Ctx, &pUObj, NULL);
  726. SysFreeString(userStr);
  727. }
  728. t_Server->Release();
  729. if (SUCCEEDED(result))
  730. {
  731. retVal = GenerateAssocInstance(a_ErrorObject, t_ObjectPath,
  732. userPath, REF_REC, REF_USER,
  733. m_ClassObject, m_NotificationHandler, NULL);
  734. pUObj->Release();
  735. }
  736. else
  737. {
  738. retVal = FALSE;
  739. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  740. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  741. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  742. }
  743. }
  744. else
  745. {
  746. retVal = FALSE;
  747. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  748. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  749. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  750. }
  751. }
  752. else
  753. {
  754. retVal = FALSE;
  755. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  756. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  757. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  758. }
  759. }
  760. else
  761. {
  762. retVal = FALSE;
  763. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  764. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  765. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  766. }
  767. }
  768. else
  769. {
  770. retVal = FALSE;
  771. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  772. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  773. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  774. }
  775. }
  776. else
  777. {
  778. retVal = FALSE;
  779. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  780. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  781. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  782. }
  783. }
  784. }
  785. }
  786. }
  787. VariantClear(&vUser);
  788. }
  789. else
  790. {
  791. retVal = FALSE;
  792. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  793. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  794. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  795. DebugOut(
  796. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  797. _T(__FILE__),__LINE__,
  798. L"ExecQueryAsyncEventObject :: Query_UserRecord:Failed to verify object given in query\r\n"
  799. );
  800. )
  801. }
  802. delete t_getRec;
  803. delete [] str_classname;
  804. if ( FAILED ( WbemCoImpersonateClient() ) )
  805. {
  806. m_ErrorObject.SetStatus (WBEM_PROV_E_ACCESS_DENIED);
  807. m_ErrorObject.SetWbemStatus (WBEM_E_ACCESS_DENIED);
  808. m_ErrorObject.SetMessage (L"Access denied, impersonation level too low");
  809. SysFreeString (t_ObjectPath);
  810. return FALSE ;
  811. }
  812. }
  813. else
  814. {
  815. bGenAll = TRUE;
  816. delete [] str_classname;
  817. }
  818. SysFreeString (t_ObjectPath);
  819. }
  820. else
  821. {
  822. bGenAll = TRUE;
  823. }
  824. if (bGenAll)
  825. {
  826. //get all instances...
  827. retVal = GenerateCompUserAssocs(a_ErrorObject, FALSE);
  828. }
  829. DebugOut(
  830. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  831. _T(__FILE__),__LINE__,
  832. L"ExecQueryAsyncEventObject :: Query_UserRecord:Returning %lx\r\n",
  833. retVal
  834. );
  835. )
  836. return retVal;
  837. }
  838. BOOL ExecQueryAsyncEventObject :: Query_ComputerRecord ( WbemProvErrorObject &a_ErrorObject )
  839. {
  840. DebugOut(
  841. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  842. _T(__FILE__),__LINE__,
  843. L"ExecQueryAsyncEventObject :: Query_ComputerRecord\r\n"
  844. );
  845. )
  846. BSTR t_ObjectPath = NULL;
  847. BOOL retVal = TRUE;
  848. BOOL bGenAll = FALSE;
  849. if (OptimizeAssocQuery (a_ErrorObject, &t_ObjectPath))
  850. {
  851. wchar_t* str_classname = GetClassFromPath(t_ObjectPath);
  852. if (str_classname == NULL)
  853. {
  854. bGenAll = TRUE;
  855. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  856. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  857. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  858. DebugOut(
  859. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  860. _T(__FILE__),__LINE__,
  861. L"ExecQueryAsyncEventObject :: Query_ComputerRecord:Failed to verify object given in query\r\n"
  862. );
  863. )
  864. }
  865. else if (_wcsicmp(str_classname, COMP_CLASS) == 0)
  866. {
  867. IWbemClassObject* pObj = NULL;
  868. IWbemServices *t_Server = m_Provider->GetServer();
  869. HRESULT result = t_Server->GetObject(t_ObjectPath, 0, m_Ctx, &pObj, NULL);
  870. t_Server->Release();
  871. if (FAILED(result))
  872. {
  873. retVal = FALSE;
  874. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  875. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  876. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  877. DebugOut(
  878. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  879. _T(__FILE__),__LINE__,
  880. L"ExecQueryAsyncEventObject :: Query_ComputerRecord:Failed to verify object given in query\r\n"
  881. );
  882. )
  883. }
  884. else
  885. {
  886. pObj->Release ();
  887. //get all records...
  888. retVal = GenerateCompUserAssocs(a_ErrorObject, TRUE);
  889. }
  890. delete [] str_classname;
  891. }
  892. else if (_wcsicmp(str_classname, NTEVT_CLASS) == 0)
  893. {
  894. GetObjectAsyncEventObject *t_getRec = new GetObjectAsyncEventObject (
  895. m_Provider, t_ObjectPath,
  896. 0, m_NotificationHandler,
  897. m_Ctx, FALSE);
  898. if (t_getRec->GetObject(t_getRec->m_ErrorObject))
  899. {
  900. VARIANT vComp;
  901. CIMTYPE cT;
  902. VariantInit(&vComp);
  903. HRESULT result = t_getRec->m_Out->Get(COMPUTER_PROP, 0, &vComp, &cT, NULL);
  904. if ((FAILED(result)) || (cT != CIM_STRING))
  905. {
  906. retVal = FALSE;
  907. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  908. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  909. a_ErrorObject.SetMessage ( L"Failed to get computer name of object given in query" );
  910. DebugOut(
  911. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  912. _T(__FILE__),__LINE__,
  913. L"ExecQueryAsyncEventObject :: Query_ComputerRecord:Failed to get computer name of object given in query\r\n"
  914. );
  915. )
  916. }
  917. else
  918. {
  919. if ((vComp.vt == VT_BSTR) && (vComp.bstrVal != NULL))
  920. {
  921. //get computer for this record
  922. wchar_t compPath[1024];
  923. if ( SUCCEEDED ( StringCchCopyW ( compPath, 1024, PROP_START_COMP ) ) )
  924. {
  925. if ( SUCCEEDED ( StringCchCatW ( compPath, 1024, vComp.bstrVal ) ) )
  926. {
  927. if ( SUCCEEDED ( StringCchCatW ( compPath, 1024, PROP_END_QUOTE ) ) )
  928. {
  929. IWbemClassObject* pCObj = NULL;
  930. IWbemServices *t_Server = m_Provider->GetServer();
  931. HRESULT result = WBEM_E_OUT_OF_MEMORY ;
  932. BSTR compStr = SysAllocString(compPath);
  933. if ( compStr )
  934. {
  935. result = t_Server->GetObject(compStr, 0, m_Ctx, &pCObj, NULL);
  936. SysFreeString(compStr);
  937. }
  938. t_Server->Release();
  939. if (SUCCEEDED(result))
  940. {
  941. retVal = GenerateAssocInstance(a_ErrorObject, t_ObjectPath,
  942. compPath, REF_REC, REF_COMP,
  943. m_ClassObject, m_NotificationHandler, NULL);
  944. pCObj->Release();
  945. }
  946. else
  947. {
  948. retVal = FALSE;
  949. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  950. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  951. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  952. }
  953. }
  954. else
  955. {
  956. retVal = FALSE;
  957. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  958. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  959. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  960. }
  961. }
  962. else
  963. {
  964. retVal = FALSE;
  965. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  966. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  967. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  968. }
  969. }
  970. else
  971. {
  972. retVal = FALSE;
  973. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  974. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  975. a_ErrorObject.SetMessage ( L"Failed to get user name of object given in query" );
  976. }
  977. }
  978. }
  979. VariantClear(&vComp);
  980. }
  981. else
  982. {
  983. retVal = FALSE;
  984. //a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  985. //a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  986. //a_ErrorObject.SetMessage ( L"Failed to verify object given in query" );
  987. DebugOut(
  988. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  989. _T(__FILE__),__LINE__,
  990. L"ExecQueryAsyncEventObject :: Query_ComputerRecord:Failed to verify object given in query\r\n"
  991. );
  992. )
  993. }
  994. delete t_getRec;
  995. delete [] str_classname;
  996. if ( FAILED ( WbemCoImpersonateClient() ) )
  997. {
  998. m_ErrorObject.SetStatus (WBEM_PROV_E_ACCESS_DENIED);
  999. m_ErrorObject.SetWbemStatus (WBEM_E_ACCESS_DENIED);
  1000. m_ErrorObject.SetMessage (L"Access denied, impersonation level too low");
  1001. SysFreeString (t_ObjectPath);
  1002. return FALSE ;
  1003. }
  1004. }
  1005. else
  1006. {
  1007. bGenAll = TRUE;
  1008. delete [] str_classname;
  1009. }
  1010. SysFreeString (t_ObjectPath);
  1011. }
  1012. else
  1013. {
  1014. bGenAll = TRUE;
  1015. }
  1016. if (bGenAll)
  1017. {
  1018. //get all instances...
  1019. retVal = GenerateCompUserAssocs(a_ErrorObject, TRUE);
  1020. }
  1021. DebugOut(
  1022. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1023. _T(__FILE__),__LINE__,
  1024. L"ExecQueryAsyncEventObject :: Query_ComputerRecord:Returning %lx\r\n",
  1025. retVal
  1026. );
  1027. )
  1028. return retVal;
  1029. }
  1030. BOOL ExecQueryAsyncEventObject :: GenerateCompUserAssocs ( WbemProvErrorObject &a_ErrorObject, BOOL bComp )
  1031. {
  1032. DebugOut(
  1033. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1034. _T(__FILE__),__LINE__,
  1035. L"ExecQueryAsyncEventObject :: GenerateCompUserAssocs\r\n"
  1036. );
  1037. )
  1038. BOOL retVal = TRUE;
  1039. //just enumerate all logs and let cimom post filter...
  1040. // open registry for log names
  1041. HKEY hkResult;
  1042. LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1043. EVENTLOG_BASE, 0,
  1044. KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
  1045. &hkResult);
  1046. if (status != ERROR_SUCCESS)
  1047. {
  1048. // indicate error
  1049. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1050. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  1051. {
  1052. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1053. a_ErrorObject.SetSecurityPrivRequired();
  1054. a_ErrorObject.SetSecurityPrivFailed();
  1055. a_ErrorObject.SetPrivilegeFailed();
  1056. }
  1057. else
  1058. {
  1059. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1060. }
  1061. a_ErrorObject.SetMessage ( L"Failed to enumerate the Eventlog registry for logfiles." );
  1062. DebugOut(
  1063. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1064. _T(__FILE__),__LINE__,
  1065. L"ExecQueryAsyncEventObject :: GenerateCompUserAssocs:Failed to enumerate the Eventlog registry for logfiles- Returning FALSE\r\n"
  1066. );
  1067. )
  1068. return FALSE;
  1069. }
  1070. DWORD iValue = 0;
  1071. WCHAR logname[MAX_PATH+1];
  1072. DWORD lognameSize = MAX_PATH+1;
  1073. CMap<CStringW, LPCWSTR, HRESULT, HRESULT> pathMap;
  1074. BOOL bContinue = TRUE;
  1075. // read all entries under this key to find all logfiles...
  1076. while (bContinue && ((status = RegEnumKey(hkResult, iValue, logname, lognameSize)) != ERROR_NO_MORE_ITEMS))
  1077. {
  1078. // if error during read
  1079. if (status != ERROR_SUCCESS)
  1080. {
  1081. RegCloseKey(hkResult);
  1082. // indicate error
  1083. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1084. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  1085. {
  1086. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1087. a_ErrorObject.SetSecurityPrivRequired();
  1088. a_ErrorObject.SetSecurityPrivFailed();
  1089. a_ErrorObject.SetPrivilegeFailed();
  1090. }
  1091. else
  1092. {
  1093. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1094. }
  1095. a_ErrorObject.SetMessage ( L"Failed while enumerating the Eventlog registry for logfiles." );
  1096. DebugOut(
  1097. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1098. _T(__FILE__),__LINE__,
  1099. L"ExecQueryAsyncEventObject :: GenerateCompUserAssocs:Failed while enumerating the Eventlog registry for logfiles - Returning FALSE\r\n"
  1100. );
  1101. )
  1102. return FALSE;
  1103. }
  1104. //process this logfile
  1105. CEventLogFile evtLog(logname, FALSE);
  1106. if (evtLog.IsValid())
  1107. {
  1108. evtLog.ReadLastRecord();
  1109. }
  1110. while (bContinue && evtLog.IsValid())
  1111. {
  1112. DWORD dwEventSize = 0;
  1113. DWORD err = evtLog.ReadRecord(0, &dwEventSize, TRUE);
  1114. if (0 != err)
  1115. {
  1116. if (retVal && (err != ERROR_HANDLE_EOF))
  1117. {
  1118. retVal = FALSE;
  1119. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1120. if ((err == ERROR_ACCESS_DENIED) || (err == ERROR_PRIVILEGE_NOT_HELD))
  1121. {
  1122. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1123. a_ErrorObject.SetSecurityPrivRequired();
  1124. a_ErrorObject.SetSecurityPrivFailed();
  1125. a_ErrorObject.SetPrivilegeFailed();
  1126. }
  1127. else
  1128. {
  1129. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1130. }
  1131. a_ErrorObject.SetMessage ( L"Failed while enumerating one of the logfiles." );
  1132. DebugOut(
  1133. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1134. _T(__FILE__),__LINE__,
  1135. L"ExecQueryAsyncEventObject :: GenerateCompUserAssocs:Failed while enumerating one of the logfiles.\r\n"
  1136. );
  1137. )
  1138. }
  1139. break;
  1140. }
  1141. PEVENTLOGRECORD EventBuffer = (PEVENTLOGRECORD)evtLog.GetBuffer();
  1142. while (bContinue && (dwEventSize != 0))
  1143. {
  1144. CStringW compPath;
  1145. BOOL bGenAssoc = FALSE;
  1146. if (bComp)
  1147. {
  1148. const wchar_t* src = (const wchar_t*)((UCHAR*)EventBuffer + sizeof(EVENTLOGRECORD));
  1149. const wchar_t* compName = (const wchar_t*)((UCHAR*)EventBuffer + sizeof(EVENTLOGRECORD))
  1150. + wcslen(src) + 1;
  1151. if (compName != NULL)
  1152. {
  1153. //get computer for this record
  1154. compPath = PROP_START_COMP;
  1155. compPath += compName;
  1156. compPath += PROP_END_QUOTE;
  1157. bGenAssoc = TRUE;
  1158. }
  1159. }
  1160. else
  1161. {
  1162. if (EventBuffer->UserSidLength > 0)
  1163. {
  1164. PSID t_Sid = (PSID)((UCHAR*)EventBuffer + EventBuffer->UserSidOffset) ;
  1165. if ( IsValidSid ( t_Sid ) )
  1166. {
  1167. CStringW user = CEventlogRecord::GetUser(
  1168. (PSID)((UCHAR*)EventBuffer + EventBuffer->UserSidOffset));
  1169. if (!user.IsEmpty())
  1170. {
  1171. int index = user.Find(L'\\');
  1172. if (index > 0)
  1173. {
  1174. compPath = PROP_START_USER;
  1175. compPath += user.Left(index++);
  1176. compPath += PROP_MID_USER;
  1177. compPath += user.Right(user.GetLength() - index);
  1178. compPath += PROP_END_QUOTE;
  1179. bGenAssoc = TRUE;
  1180. }
  1181. }
  1182. }
  1183. else
  1184. {
  1185. DebugOut(
  1186. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1187. _T(__FILE__),__LINE__,
  1188. L"ExecQueryAsyncEventObject :: GenerateCompUserAssocs:Invalid Sid.\r\n"
  1189. );
  1190. )
  1191. }
  1192. }
  1193. }
  1194. if (bGenAssoc)
  1195. {
  1196. HRESULT result;
  1197. if (pathMap.IsEmpty() || !pathMap.Lookup(compPath, result))
  1198. {
  1199. IWbemClassObject* pCObj = NULL;
  1200. IWbemServices *t_Server = m_Provider->GetServer();
  1201. BSTR compPathStr = compPath.AllocSysString();
  1202. result = t_Server->GetObject(compPathStr, 0, m_Ctx, &pCObj, NULL);
  1203. SysFreeString(compPathStr);
  1204. t_Server->Release();
  1205. pathMap[compPath] = result;
  1206. if (SUCCEEDED(result))
  1207. {
  1208. pCObj->Release();
  1209. }
  1210. }
  1211. if (SUCCEEDED(result))
  1212. {
  1213. CStringW recPath(PROP_START_REC);
  1214. recPath += CStringW(logname);
  1215. recPath += PROP_MID_REC;
  1216. wchar_t buff[40];
  1217. recPath += CStringW(_ultow((ULONG)EventBuffer->RecordNumber, buff, 10));
  1218. if (!GenerateAssocInstance(a_ErrorObject, recPath, compPath, REF_REC,
  1219. bComp ? REF_COMP : REF_USER,
  1220. m_ClassObject, m_NotificationHandler, &bContinue))
  1221. {
  1222. retVal = FALSE;
  1223. }
  1224. }
  1225. }
  1226. // drop by length of this record and point to next record
  1227. dwEventSize -= EventBuffer->Length;
  1228. EventBuffer = (PEVENTLOGRECORD) ((UCHAR*) EventBuffer + EventBuffer->Length);
  1229. }
  1230. }
  1231. // read next parameter
  1232. iValue++;
  1233. } // end while
  1234. pathMap.RemoveAll();
  1235. RegCloseKey(hkResult);
  1236. DebugOut(
  1237. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1238. _T(__FILE__),__LINE__,
  1239. L"ExecQueryAsyncEventObject :: GenerateCompUserAssocs:Returning %lx\r\n",
  1240. retVal
  1241. );
  1242. )
  1243. return retVal;
  1244. }
  1245. BOOL ExecQueryAsyncEventObject :: ExecQuery ( WbemProvErrorObject &a_ErrorObject )
  1246. {
  1247. BOOL t_Status;
  1248. DebugOut(
  1249. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1250. _T(__FILE__),__LINE__,
  1251. L"ExecQueryAsyncEventObject :: ExecQuery\r\n"
  1252. );
  1253. )
  1254. if (FAILED(m_ErrorObject.GetWbemStatus()))
  1255. {
  1256. return FALSE;
  1257. }
  1258. if ( _wcsicmp ( m_QueryFormat, WBEM_QUERY_LANGUAGE_SQL1 ) == 0 )
  1259. {
  1260. CTextLexSource querySource ( m_Query );
  1261. SQL1_Parser sqlParser ( &querySource );
  1262. t_Status = ! sqlParser.Parse ( & m_RPNExpression );
  1263. if ( t_Status )
  1264. {
  1265. t_Status = GetClassObject ( m_RPNExpression->bsClassName );
  1266. if ( t_Status )
  1267. {
  1268. t_Status = DispatchQuery ( a_ErrorObject );
  1269. }
  1270. else
  1271. {
  1272. t_Status = FALSE;
  1273. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS );
  1274. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_CLASS );
  1275. a_ErrorObject.SetMessage ( L"Unknown Class" );
  1276. DebugOut(
  1277. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1278. _T(__FILE__),__LINE__,
  1279. L"ExecQueryAsyncEventObject :: ExecQuery:Unknown Class\r\n"
  1280. );
  1281. )
  1282. }
  1283. }
  1284. else
  1285. {
  1286. t_Status = FALSE;
  1287. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_QUERY );
  1288. a_ErrorObject.SetWbemStatus ( WBEM_E_PROVIDER_NOT_CAPABLE );
  1289. a_ErrorObject.SetMessage ( L"WQL query was invalid for this provider" );
  1290. DebugOut(
  1291. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1292. _T(__FILE__),__LINE__,
  1293. L"ExecQueryAsyncEventObject :: ExecQuery:WQL query was invalid for this provider\r\n"
  1294. );
  1295. )
  1296. }
  1297. }
  1298. else
  1299. {
  1300. t_Status = FALSE;
  1301. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_QUERY_TYPE );
  1302. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_QUERY_TYPE );
  1303. a_ErrorObject.SetMessage ( L"Query Language not supported" );
  1304. DebugOut(
  1305. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1306. _T(__FILE__),__LINE__,
  1307. L"ExecQueryAsyncEventObject :: ExecQuery:Query Language not supported\r\n"
  1308. );
  1309. )
  1310. }
  1311. DebugOut(
  1312. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1313. _T(__FILE__),__LINE__,
  1314. L"ExecQueryAsyncEventObject :: ExecQuery:Returning %lx\r\n",
  1315. t_Status
  1316. );
  1317. )
  1318. return t_Status;
  1319. }
  1320. ExecQueryAsyncEventObject :: ExecQueryAsyncEventObject (
  1321. CImpNTEvtProv *a_Provider,
  1322. BSTR a_QueryFormat,
  1323. BSTR a_Query,
  1324. ULONG a_OperationFlag,
  1325. IWbemObjectSink *a_NotificationHandler,
  1326. IWbemContext *a_Ctx
  1327. ) : WbemTaskObject ( a_Provider, a_NotificationHandler, a_OperationFlag, a_Ctx ),
  1328. m_Query ( NULL ),
  1329. m_QueryFormat ( NULL ),
  1330. m_RPNExpression ( NULL )
  1331. {
  1332. m_Query = UnicodeStringDuplicate ( a_Query );
  1333. m_QueryFormat = UnicodeStringDuplicate ( a_QueryFormat );
  1334. }
  1335. ExecQueryAsyncEventObject :: ~ExecQueryAsyncEventObject ()
  1336. {
  1337. // Get Status object
  1338. delete [] m_Query;
  1339. delete [] m_QueryFormat;
  1340. delete m_RPNExpression;
  1341. IWbemClassObject *t_NotifyStatus = NULL;
  1342. BOOL t_Status = TRUE;
  1343. if (WBEM_NO_ERROR != m_ErrorObject.GetWbemStatus ())
  1344. {
  1345. t_Status = GetExtendedNotifyStatusObject ( &t_NotifyStatus );
  1346. }
  1347. if ( t_Status )
  1348. {
  1349. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0, m_ErrorObject.GetWbemStatus (), 0, t_NotifyStatus );
  1350. if (t_NotifyStatus)
  1351. {
  1352. t_NotifyStatus->Release ();
  1353. }
  1354. }
  1355. else
  1356. {
  1357. HRESULT t_Result = m_NotificationHandler->SetStatus ( 0, m_ErrorObject.GetWbemStatus (), 0, NULL );
  1358. }
  1359. }
  1360. void ExecQueryAsyncEventObject :: Process ()
  1361. {
  1362. ExecQuery ( m_ErrorObject );
  1363. }
  1364. BOOL ExecQueryAsyncEventObject :: DispatchQuery ( WbemProvErrorObject &a_ErrorObject )
  1365. {
  1366. BOOL t_Status;
  1367. DebugOut(
  1368. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1369. _T(__FILE__),__LINE__,
  1370. L"ExecQueryAsyncEventObject :: DispatchQuery\r\n"
  1371. );
  1372. )
  1373. if ( _wcsicmp ( m_RPNExpression->bsClassName, NTEVT_CLASS ) == 0 )
  1374. {
  1375. t_Status = Query_Record ( a_ErrorObject );
  1376. if ( t_Status )
  1377. {
  1378. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE;
  1379. }
  1380. }
  1381. else if ( _wcsicmp ( m_RPNExpression->bsClassName, NTEVTLOG_CLASS ) == 0 )
  1382. {
  1383. t_Status = Query_EventLog ( a_ErrorObject );
  1384. if ( t_Status )
  1385. {
  1386. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE;
  1387. }
  1388. }
  1389. else if ( _wcsicmp ( m_RPNExpression->bsClassName, ASSOC_LOGRECORD) == 0 )
  1390. {
  1391. t_Status = Query_LogRecord ( a_ErrorObject );
  1392. if ( t_Status )
  1393. {
  1394. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE;
  1395. }
  1396. }
  1397. else if ( _wcsicmp ( m_RPNExpression->bsClassName, ASSOC_USERRECORD) == 0 )
  1398. {
  1399. t_Status = Query_UserRecord ( a_ErrorObject );
  1400. if ( t_Status )
  1401. {
  1402. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE;
  1403. }
  1404. }
  1405. else if ( _wcsicmp ( m_RPNExpression->bsClassName, ASSOC_COMPRECORD) == 0 )
  1406. {
  1407. t_Status = Query_ComputerRecord ( a_ErrorObject );
  1408. if ( t_Status )
  1409. {
  1410. m_State = WBEM_TASKSTATE_ASYNCHRONOUSCOMPLETE;
  1411. }
  1412. }
  1413. else
  1414. {
  1415. //just complete!
  1416. t_Status = FALSE;
  1417. a_ErrorObject.SetStatus ( WBEM_PROV_E_INVALID_CLASS );
  1418. a_ErrorObject.SetWbemStatus ( WBEM_E_INVALID_CLASS );
  1419. a_ErrorObject.SetMessage ( L"Dynamic NT Eventlog Provider does not support this class" );
  1420. DebugOut(
  1421. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1422. _T(__FILE__),__LINE__,
  1423. L"ExecQueryAsyncEventObject :: DispatchQuery:Dynamic NT Eventlog Provider does not support this class:%s\r\n",
  1424. m_RPNExpression->bsClassName
  1425. );
  1426. )
  1427. }
  1428. DebugOut(
  1429. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1430. _T(__FILE__),__LINE__,
  1431. L"ExecQueryAsyncEventObject :: DispatchQuery:Returning %lx\r\n",
  1432. t_Status
  1433. );
  1434. )
  1435. return t_Status;
  1436. }
  1437. BOOL ExecQueryAsyncEventObject :: Query_EventLog ( WbemProvErrorObject &a_ErrorObject )
  1438. {
  1439. // open registry for log names
  1440. HKEY hkResult;
  1441. LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1442. EVENTLOG_BASE, 0,
  1443. KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
  1444. &hkResult);
  1445. if (status != ERROR_SUCCESS)
  1446. {
  1447. // indicate error
  1448. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1449. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  1450. {
  1451. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1452. a_ErrorObject.SetSecurityPrivRequired();
  1453. a_ErrorObject.SetSecurityPrivFailed();
  1454. a_ErrorObject.SetPrivilegeFailed();
  1455. }
  1456. else
  1457. {
  1458. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1459. }
  1460. a_ErrorObject.SetMessage ( L"Failed to open the Eventlog registry for logfiles." );
  1461. DebugOut(
  1462. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1463. _T(__FILE__),__LINE__,
  1464. L"ExecQueryAsyncEventObject :: Query_EventLog:Failed to open the Eventlog registry for logfiles - Returning FALSE.\r\n"
  1465. );
  1466. )
  1467. return FALSE;
  1468. }
  1469. BOOL retVal = TRUE;
  1470. DWORD iValue = 0;
  1471. WCHAR logname[MAX_PATH+1];
  1472. DWORD lognameSize = MAX_PATH+1;
  1473. // read all entries under this key to find all logfiles...
  1474. while ((status = RegEnumKey(hkResult, iValue, logname, lognameSize)) != ERROR_NO_MORE_ITEMS)
  1475. {
  1476. // if error during read
  1477. if (status != ERROR_SUCCESS)
  1478. {
  1479. // indicate error
  1480. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1481. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  1482. {
  1483. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1484. a_ErrorObject.SetPrivilegeFailed();
  1485. a_ErrorObject.SetSecurityPrivRequired();
  1486. a_ErrorObject.SetSecurityPrivFailed();
  1487. }
  1488. else
  1489. {
  1490. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1491. }
  1492. a_ErrorObject.SetMessage ( L"Failed while enumerating the Eventlog registry for logfiles." );
  1493. retVal = FALSE;
  1494. DebugOut(
  1495. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1496. _T(__FILE__),__LINE__,
  1497. L"ExecQueryAsyncEventObject :: Query_EventLog:Failed while enumerating the Eventlog registry for logfiles.\r\n"
  1498. );
  1499. )
  1500. break;
  1501. }
  1502. //create the instance logfilename
  1503. CEventlogFileAttributes evtlog(logname);
  1504. IWbemClassObject* pInst = NULL;
  1505. if (evtlog.GenerateInstance(m_ClassObject, m_AClassObject, &pInst))
  1506. {
  1507. HRESULT t_hr = m_NotificationHandler->Indicate ( 1, & pInst );
  1508. pInst->Release();
  1509. if (FAILED(t_hr))
  1510. {
  1511. DebugOut(
  1512. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1513. _T(__FILE__),__LINE__,
  1514. L"ExecQueryAsyncEventObject :: Query_EventLog:Failed while indicating instance(s) of %s Eventlog file\r\n",
  1515. logname
  1516. );
  1517. )
  1518. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1519. a_ErrorObject.SetMessage ( L"Failed while indicating instance of logfile." );
  1520. retVal = FALSE;
  1521. break;
  1522. }
  1523. }
  1524. else if (retVal) //only do this once!
  1525. {
  1526. //an error, just log an error, don't report it via the interface
  1527. //it is a bad registry entry which the eventlog service allows
  1528. //so we should let it pass...
  1529. DebugOut(
  1530. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1531. _T(__FILE__),__LINE__,
  1532. L"ExecQueryAsyncEventObject :: Query_EventLog:Failed to create instance(s) of %s Eventlog file\r\n",
  1533. logname
  1534. );
  1535. )
  1536. }
  1537. // read next parameter
  1538. iValue++;
  1539. } // end while
  1540. RegCloseKey(hkResult);
  1541. DebugOut(
  1542. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1543. _T(__FILE__),__LINE__,
  1544. L"ExecQueryAsyncEventObject :: Query_EventLog:Returning %lx\r\n",
  1545. retVal
  1546. );
  1547. )
  1548. return retVal;
  1549. }
  1550. BOOL ExecQueryAsyncEventObject :: Query_Record ( WbemProvErrorObject &a_ErrorObject )
  1551. {
  1552. DebugOut(
  1553. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1554. _T(__FILE__),__LINE__,
  1555. L"ExecQueryAsyncEventObject :: Query_Record\r\n"
  1556. );
  1557. )
  1558. BOOL retVal = TRUE;
  1559. //just enumerate all logs and let cimom post filter...
  1560. // open registry for log names
  1561. HKEY hkResult = NULL;
  1562. LONG status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1563. EVENTLOG_BASE, 0,
  1564. KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
  1565. &hkResult);
  1566. if (status != ERROR_SUCCESS)
  1567. {
  1568. // indicate error
  1569. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1570. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  1571. {
  1572. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1573. a_ErrorObject.SetPrivilegeFailed();
  1574. a_ErrorObject.SetSecurityPrivRequired();
  1575. a_ErrorObject.SetSecurityPrivFailed();
  1576. }
  1577. else
  1578. {
  1579. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1580. }
  1581. a_ErrorObject.SetMessage ( L"Failed to enumerate the Eventlog registry for logfiles." );
  1582. DebugOut(
  1583. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1584. _T(__FILE__),__LINE__,
  1585. L"ExecQueryAsyncEventObject :: Query_Record:Failed to enumerate the Eventlog registry for logfiles - Return FALSE\r\n"
  1586. );
  1587. )
  1588. retVal = FALSE;
  1589. }
  1590. if (retVal)
  1591. {
  1592. //Analyze the query...
  1593. SQL_LEVEL_1_RPN_EXPRESSION *t_RpnExpression = NULL;
  1594. PartitionSet *t_PartitionSet = NULL;
  1595. QueryPreprocessor :: QuadState t_State = Query (m_Query, t_RpnExpression);
  1596. if ( t_State == QueryPreprocessor :: QuadState :: State_True )
  1597. {
  1598. WmiTreeNode *t_Root = NULL;
  1599. t_State = PreProcess (NULL, t_RpnExpression, t_Root);
  1600. try
  1601. {
  1602. switch ( t_State )
  1603. {
  1604. case QueryPreprocessor :: QuadState :: State_True:
  1605. {
  1606. BSTR t_PropertyContainer [ 4 ];
  1607. memset ( t_PropertyContainer, 0, sizeof ( BSTR ) * 4 );
  1608. try
  1609. {
  1610. t_PropertyContainer [ 0 ] = SysAllocString ( LOGFILE_PROP );
  1611. t_PropertyContainer [ 1 ] = SysAllocString ( RECORD_PROP );
  1612. t_PropertyContainer [ 2 ] = SysAllocString ( GENERATED_PROP );
  1613. t_PropertyContainer [ 3 ] = SysAllocString ( WRITTEN_PROP );
  1614. if ((t_PropertyContainer [ 0 ] == NULL) ||
  1615. (t_PropertyContainer [ 1 ] == NULL) ||
  1616. (t_PropertyContainer [ 2 ] == NULL) ||
  1617. (t_PropertyContainer [ 3 ] == NULL) )
  1618. {
  1619. throw CHeap_Exception ( CHeap_Exception :: E_ALLOCATION_ERROR );
  1620. }
  1621. t_State = PreProcess (
  1622. NULL,
  1623. t_RpnExpression,
  1624. t_Root,
  1625. 4,
  1626. t_PropertyContainer,
  1627. t_PartitionSet
  1628. );
  1629. }
  1630. catch ( ... )
  1631. {
  1632. for (DWORD x = 0; x < 4; x++)
  1633. {
  1634. if ( t_PropertyContainer [ x ] )
  1635. {
  1636. SysFreeString ( t_PropertyContainer [ x ] );
  1637. t_PropertyContainer [ x ] = NULL;
  1638. }
  1639. }
  1640. throw;
  1641. }
  1642. for (DWORD x = 0; x < 4; x++)
  1643. {
  1644. if ( t_PropertyContainer [ x ] )
  1645. {
  1646. SysFreeString ( t_PropertyContainer [ x ] );
  1647. t_PropertyContainer [ x ] = NULL;
  1648. }
  1649. }
  1650. switch ( t_State )
  1651. {
  1652. case QueryPreprocessor :: QuadState :: State_True :
  1653. {
  1654. /*
  1655. * Full set, enumerate
  1656. */
  1657. t_PartitionSet = NULL;
  1658. }
  1659. break;
  1660. case QueryPreprocessor :: QuadState :: State_False :
  1661. {
  1662. /*
  1663. * Empty set, no work to do
  1664. */
  1665. RegCloseKey(hkResult);
  1666. hkResult = NULL;
  1667. return TRUE;
  1668. }
  1669. break;
  1670. case QueryPreprocessor :: QuadState :: State_Undefined :
  1671. {
  1672. //we have should now have a non-null partition set
  1673. }
  1674. break;
  1675. default:
  1676. {
  1677. /*
  1678. * Didn't understand the query send back everything
  1679. */
  1680. t_PartitionSet = NULL;
  1681. }
  1682. break;
  1683. }
  1684. delete t_Root;
  1685. t_Root = NULL;
  1686. }
  1687. break;
  1688. default:
  1689. {
  1690. /*
  1691. * Didn't understand the query send back everything
  1692. */
  1693. t_PartitionSet = NULL;
  1694. }
  1695. break;
  1696. }
  1697. delete t_RpnExpression;
  1698. t_RpnExpression = NULL;
  1699. }
  1700. catch (...)
  1701. {
  1702. if (t_PartitionSet)
  1703. {
  1704. delete t_PartitionSet;
  1705. t_PartitionSet = NULL;
  1706. }
  1707. if ( t_Root )
  1708. {
  1709. delete t_Root;
  1710. t_Root = NULL;
  1711. }
  1712. if ( t_RpnExpression )
  1713. {
  1714. delete t_RpnExpression;
  1715. t_RpnExpression = NULL;
  1716. }
  1717. if ( hkResult )
  1718. {
  1719. RegCloseKey(hkResult);
  1720. hkResult = NULL;
  1721. }
  1722. throw;
  1723. }
  1724. }
  1725. else
  1726. {
  1727. /*
  1728. * Didn't understand the query send back everything
  1729. */
  1730. t_PartitionSet = NULL;
  1731. }
  1732. DWORD iValue = 0;
  1733. WCHAR logname[MAX_PATH+1];
  1734. DWORD lognameSize = MAX_PATH+1;
  1735. retVal = FALSE;
  1736. // read all entries under this key to find all logfiles...
  1737. while ((status = RegEnumKey(hkResult, iValue, logname, lognameSize)) != ERROR_NO_MORE_ITEMS)
  1738. {
  1739. // if error during read
  1740. if (status != ERROR_SUCCESS)
  1741. {
  1742. // indicate error
  1743. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  1744. if ((status == ERROR_ACCESS_DENIED) || (status == ERROR_PRIVILEGE_NOT_HELD))
  1745. {
  1746. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  1747. a_ErrorObject.SetSecurityPrivRequired();
  1748. a_ErrorObject.SetSecurityPrivFailed();
  1749. a_ErrorObject.SetPrivilegeFailed();
  1750. }
  1751. else
  1752. {
  1753. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1754. }
  1755. a_ErrorObject.SetMessage ( L"Failed while enumerating the Eventlog registry for logfiles." );
  1756. DebugOut(
  1757. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1758. _T(__FILE__),__LINE__,
  1759. L"ExecQueryAsyncEventObject :: Query_Record:Failed while enumerating the Eventlog registry for logfiles - Return FALSE\r\n"
  1760. );
  1761. )
  1762. break;
  1763. }
  1764. if (t_PartitionSet)
  1765. {
  1766. //process this logfile for query
  1767. if (SUCCEEDED (RecurseLogFile (a_ErrorObject, t_PartitionSet, logname)))
  1768. {
  1769. retVal = TRUE;
  1770. }
  1771. }
  1772. else
  1773. {
  1774. //process this logfile
  1775. if ( SUCCEEDED( DoAllInLogfile(a_ErrorObject, logname, 0, 0) ) )
  1776. {
  1777. retVal = TRUE;
  1778. }
  1779. else
  1780. {
  1781. break;
  1782. }
  1783. }
  1784. // read next parameter
  1785. iValue++;
  1786. } // end while
  1787. if (t_PartitionSet)
  1788. {
  1789. delete t_PartitionSet;
  1790. }
  1791. RegCloseKey(hkResult);
  1792. }
  1793. DebugOut(
  1794. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  1795. _T(__FILE__),__LINE__,
  1796. L"ExecQueryAsyncEventObject :: Query_Record:Returning %lx\r\n",
  1797. retVal
  1798. );
  1799. )
  1800. return retVal;
  1801. }
  1802. HRESULT ExecQueryAsyncEventObject :: RecurseLogFile (
  1803. WbemProvErrorObject &a_ErrorObject,
  1804. PartitionSet *a_PartitionSet,
  1805. LPCWSTR a_logname
  1806. )
  1807. {
  1808. HRESULT t_Result = WBEM_E_FAILED;
  1809. ULONG t_PartitionCount = a_PartitionSet->GetPartitionCount ();
  1810. if (t_PartitionCount == 0)
  1811. {
  1812. t_Result = S_OK;
  1813. }
  1814. for ( DWORD t_Partition = 0; t_Partition < t_PartitionCount; t_Partition++ )
  1815. {
  1816. PartitionSet *t_PropertyPartition = a_PartitionSet->GetPartition ( t_Partition );
  1817. WmiStringRangeNode *t_Node = ( WmiStringRangeNode * ) t_PropertyPartition->GetRange ();
  1818. BOOL t_Unique = ! t_Node->InfiniteLowerBound () &&
  1819. ! t_Node->InfiniteUpperBound () &&
  1820. t_Node->ClosedLowerBound () &&
  1821. t_Node->ClosedUpperBound () &&
  1822. ( _wcsicmp ( t_Node->LowerBound (), t_Node->UpperBound () ) == 0 );
  1823. if (!t_Unique)
  1824. {
  1825. //not naming logfiles therefore do this logfile only if it meets bounds...
  1826. //if even one call succeeds return success
  1827. BOOL t_bProcess = TRUE;
  1828. if (!t_Node->InfiniteLowerBound())
  1829. {
  1830. int t_iCmp = _wcsicmp(a_logname, t_Node->LowerBound());
  1831. if (t_Node->ClosedLowerBound())
  1832. {
  1833. if (t_iCmp < 0)
  1834. {
  1835. t_bProcess = FALSE;
  1836. }
  1837. }
  1838. else
  1839. {
  1840. if (t_iCmp <= 0)
  1841. {
  1842. t_bProcess = FALSE;
  1843. }
  1844. }
  1845. }
  1846. if (!t_Node->InfiniteUpperBound())
  1847. {
  1848. int t_iCmp = _wcsicmp(a_logname, t_Node->UpperBound());
  1849. if (t_Node->ClosedUpperBound())
  1850. {
  1851. if (t_iCmp > 0)
  1852. {
  1853. t_bProcess = FALSE;
  1854. }
  1855. }
  1856. else
  1857. {
  1858. if (t_iCmp >= 0)
  1859. {
  1860. t_bProcess = FALSE;
  1861. }
  1862. }
  1863. }
  1864. if (t_bProcess)
  1865. {
  1866. if ( SUCCEEDED(RecurseRecord(a_ErrorObject, t_PropertyPartition, a_logname)) && FAILED(t_Result) )
  1867. {
  1868. t_Result = S_OK;
  1869. }
  1870. //we've processed this logfile no need to do anymore...
  1871. break;
  1872. }
  1873. }
  1874. else
  1875. {
  1876. //are naming logfiles
  1877. if (_wcsicmp(t_Node->LowerBound(), a_logname) == 0)
  1878. {
  1879. //logfile matched let's do records
  1880. if (SUCCEEDED(RecurseRecord(a_ErrorObject, t_PropertyPartition, a_logname)) && FAILED(t_Result) )
  1881. {
  1882. t_Result = S_OK;
  1883. }
  1884. break;
  1885. }
  1886. else
  1887. {
  1888. //not this logfile let's try some other...
  1889. continue;
  1890. }
  1891. }
  1892. }
  1893. return t_Result;
  1894. }
  1895. HRESULT ExecQueryAsyncEventObject :: RecurseRecord (
  1896. WbemProvErrorObject &a_ErrorObject,
  1897. PartitionSet *a_PartitionSet,
  1898. LPCWSTR a_logname
  1899. )
  1900. {
  1901. HRESULT t_Result = S_OK;
  1902. ULONG t_PartitionCount = a_PartitionSet->GetPartitionCount ();
  1903. for ( DWORD t_Partition = 0; t_Partition < t_PartitionCount; t_Partition++ )
  1904. {
  1905. PartitionSet *t_PropertyPartition = a_PartitionSet->GetPartition ( t_Partition );
  1906. WmiUnsignedIntegerRangeNode *t_Node = ( WmiUnsignedIntegerRangeNode * ) t_PropertyPartition->GetRange () ;
  1907. BOOL t_Unique = !t_Node->InfiniteLowerBound () &&
  1908. !t_Node->InfiniteUpperBound () &&
  1909. t_Node->ClosedLowerBound () &&
  1910. t_Node->ClosedUpperBound () &&
  1911. (t_Node->LowerBound() == t_Node->UpperBound());
  1912. if (!t_Unique)
  1913. {
  1914. if (t_Node->InfiniteLowerBound() && t_Node->InfiniteUpperBound())
  1915. {
  1916. //no limits on record therefore check time generated...
  1917. t_Result = RecurseTime(a_ErrorObject, t_PropertyPartition, a_logname, TRUE);
  1918. //there should be only one partition entry for this case but we'll break anyway...
  1919. break;
  1920. }
  1921. else
  1922. {
  1923. DWORD t_dwLower = 0;
  1924. DWORD t_dwUpper = 0xFFFFFFFF;
  1925. BOOL t_bProcess = TRUE;
  1926. if (!t_Node->InfiniteLowerBound())
  1927. {
  1928. if (t_Node->ClosedLowerBound())
  1929. {
  1930. t_dwLower = t_Node->LowerBound();
  1931. }
  1932. else
  1933. {
  1934. if (t_Node->LowerBound() != 0xFFFFFFFF)
  1935. {
  1936. t_dwLower = t_Node->LowerBound() + 1;
  1937. }
  1938. else
  1939. {
  1940. t_bProcess = FALSE;
  1941. }
  1942. }
  1943. }
  1944. if (!t_Node->InfiniteUpperBound())
  1945. {
  1946. if (t_Node->ClosedUpperBound())
  1947. {
  1948. t_dwUpper = t_Node->UpperBound();
  1949. }
  1950. else
  1951. {
  1952. if (t_Node->UpperBound() != 0)
  1953. {
  1954. t_dwUpper = t_Node->UpperBound() - 1;
  1955. }
  1956. else
  1957. {
  1958. t_bProcess = FALSE;
  1959. }
  1960. }
  1961. }
  1962. if (t_dwUpper < t_dwLower)
  1963. {
  1964. t_bProcess = FALSE;
  1965. }
  1966. //now return all records including the bounds
  1967. if (t_bProcess)
  1968. {
  1969. CEventLogFile evtLog(a_logname, FALSE);
  1970. if (evtLog.IsValid())
  1971. {
  1972. DWORD t_dwEventSize = 0;
  1973. DWORD t_dwErr = evtLog.ReadRecord(t_dwUpper, &t_dwEventSize, TRUE);
  1974. if (0 == t_dwErr)
  1975. {
  1976. DWORD t_dwState = 0;
  1977. while (0 == t_dwState)
  1978. {
  1979. PEVENTLOGRECORD EventBuffer = (PEVENTLOGRECORD)evtLog.GetBuffer();
  1980. while (t_dwEventSize != 0)
  1981. {
  1982. if (EventBuffer->RecordNumber >= t_dwLower)
  1983. {
  1984. CEventlogRecord evtrec(a_logname, EventBuffer, NULL, m_ClassObject, m_AClassObject);
  1985. IWbemClassObject* pInst = NULL;
  1986. if (evtrec.GenerateInstance(&pInst))
  1987. {
  1988. t_Result = m_NotificationHandler->Indicate ( 1, & pInst );
  1989. //upper limit is decreased with this indicate!
  1990. t_dwUpper--;
  1991. pInst->Release();
  1992. if (FAILED(t_Result))
  1993. {
  1994. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  1995. a_ErrorObject.SetMessage ( L"Failed while indicating record instance." );
  1996. t_dwState = 2;
  1997. break;
  1998. }
  1999. }
  2000. // drop by length of this record and point to next record
  2001. t_dwEventSize -= EventBuffer->Length;
  2002. EventBuffer = (PEVENTLOGRECORD) ((UCHAR*) EventBuffer + EventBuffer->Length);
  2003. }
  2004. else
  2005. {
  2006. t_dwState = 2;
  2007. break;
  2008. }
  2009. }
  2010. if (t_dwState == 0)
  2011. {
  2012. t_dwErr = evtLog.ReadRecord(0, &t_dwEventSize, TRUE);
  2013. if (0 != t_dwErr)
  2014. {
  2015. if (SUCCEEDED(t_Result) && (t_dwErr != ERROR_HANDLE_EOF))
  2016. {
  2017. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  2018. t_Result = WBEM_E_FAILED;
  2019. if ((t_dwErr == ERROR_ACCESS_DENIED) || (t_dwErr == ERROR_PRIVILEGE_NOT_HELD))
  2020. {
  2021. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  2022. a_ErrorObject.SetSecurityPrivRequired();
  2023. a_ErrorObject.SetSecurityPrivFailed();
  2024. a_ErrorObject.SetPrivilegeFailed();
  2025. }
  2026. else
  2027. {
  2028. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2029. }
  2030. a_ErrorObject.SetMessage ( L"Failed while enumerating one of the logfiles." );
  2031. }
  2032. t_dwState = 1;
  2033. }
  2034. }
  2035. }
  2036. if ((t_dwState == 1) && (t_dwErr == ERROR_HANDLE_EOF) && (t_dwUpper > t_dwLower))
  2037. {
  2038. //got all the records til the start of the log see if there are any at the top
  2039. t_Result = DoAllInLogfile(a_ErrorObject, a_logname, t_dwUpper, t_dwLower);
  2040. if (FAILED(t_Result))
  2041. {
  2042. break;
  2043. }
  2044. }
  2045. }
  2046. else
  2047. {
  2048. if (t_dwLower != t_dwUpper)
  2049. {
  2050. //the upper bound does not exist, try from the top down...
  2051. t_Result = DoAllInLogfile(a_ErrorObject, a_logname, t_dwUpper, t_dwLower);
  2052. if (FAILED(t_Result))
  2053. {
  2054. break;
  2055. }
  2056. }
  2057. }
  2058. }
  2059. }
  2060. }
  2061. }
  2062. else
  2063. {
  2064. //are naming records
  2065. CEventLogFile evtLog(a_logname, FALSE);
  2066. if (evtLog.IsValid())
  2067. {
  2068. DWORD err = evtLog.ReadRecord(t_Node->LowerBound());
  2069. if (0 == err)
  2070. {
  2071. EVENTLOGRECORD* EventBuffer = (EVENTLOGRECORD*) evtLog.GetBuffer();
  2072. CEventlogRecord evtRec(a_logname, EventBuffer, NULL, m_ClassObject, m_AClassObject);
  2073. IWbemClassObject* pInst = NULL;
  2074. if (evtRec.GenerateInstance(&pInst))
  2075. {
  2076. t_Result = m_NotificationHandler->Indicate ( 1 , & pInst ) ;
  2077. pInst->Release();
  2078. if (FAILED(t_Result))
  2079. {
  2080. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2081. a_ErrorObject.SetMessage ( L"Failed while indicating record instance." );
  2082. break;
  2083. }
  2084. }
  2085. else
  2086. {
  2087. //failed to create record
  2088. t_Result = WBEM_E_FAILED;
  2089. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED ) ;
  2090. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED ) ;
  2091. a_ErrorObject.SetMessage ( L"Failed to create instance from Eventlog data" ) ;
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. return t_Result;
  2098. }
  2099. HRESULT ExecQueryAsyncEventObject::RecurseTime(WbemProvErrorObject &a_ErrorObject, PartitionSet *a_PartitionSet,
  2100. LPCWSTR a_logname, BOOL a_Generated)
  2101. {
  2102. HRESULT t_Result = S_OK;
  2103. ULONG t_PartitionCount = a_PartitionSet->GetPartitionCount ();
  2104. for ( DWORD t_Partition = 0; t_Partition < t_PartitionCount; t_Partition++ )
  2105. {
  2106. PartitionSet *t_PropertyPartition = a_PartitionSet->GetPartition ( t_Partition );
  2107. WmiStringRangeNode *t_Node = ( WmiStringRangeNode * ) t_PropertyPartition->GetRange ();
  2108. BOOL t_Unique = ! t_Node->InfiniteLowerBound () &&
  2109. ! t_Node->InfiniteUpperBound () &&
  2110. t_Node->ClosedLowerBound () &&
  2111. t_Node->ClosedUpperBound () &&
  2112. ( _wcsicmp ( t_Node->LowerBound (), t_Node->UpperBound () ) == 0 );
  2113. if (!t_Unique)
  2114. {
  2115. if (t_Node->InfiniteLowerBound() && t_Node->InfiniteUpperBound())
  2116. {
  2117. //no limits on record therefore check time written...
  2118. if (a_Generated)
  2119. {
  2120. t_Result = RecurseTime(a_ErrorObject, t_PropertyPartition, a_logname, FALSE);
  2121. }
  2122. else
  2123. {
  2124. //do all in the logfile...
  2125. t_Result = DoAllInLogfile(a_ErrorObject, a_logname, 0, 0);
  2126. }
  2127. //there should be only one partition entry for this case but we'll break anyway...
  2128. break;
  2129. }
  2130. else
  2131. {
  2132. //we have bounds (at least one anyway!)
  2133. DWORD t_tmLower = 0;
  2134. DWORD t_tmUpper = 0xFFFFFFFF;
  2135. BOOL t_bProcess = TRUE;
  2136. if (!t_Node->InfiniteLowerBound())
  2137. {
  2138. WBEMTime t_Time(t_Node->LowerBound());
  2139. time_t t_temp = 0;
  2140. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2141. {
  2142. t_tmLower = (DWORD)t_temp;
  2143. if (!t_Node->ClosedLowerBound())
  2144. {
  2145. if (t_tmLower != 0xFFFFFFFF)
  2146. {
  2147. t_tmLower++;
  2148. }
  2149. else
  2150. {
  2151. t_bProcess = FALSE;
  2152. }
  2153. }
  2154. }
  2155. else
  2156. {
  2157. DWORD t_len = wcslen(t_Node->LowerBound());
  2158. if (t_len == NTEVT_DMTFLEN)
  2159. {
  2160. BOOL t_bIsLo = FALSE;
  2161. BOOL t_bIsHi = TRUE;
  2162. if (CheckTime(t_Node->LowerBound(), t_bIsLo, t_bIsHi))
  2163. {
  2164. if (t_bIsHi)
  2165. {
  2166. t_bProcess = FALSE;
  2167. }
  2168. }
  2169. else
  2170. {
  2171. t_bProcess = FALSE;
  2172. }
  2173. }
  2174. else
  2175. {
  2176. t_bProcess = FALSE;
  2177. }
  2178. }
  2179. }
  2180. if (!t_Node->InfiniteUpperBound())
  2181. {
  2182. WBEMTime t_Time(t_Node->UpperBound());
  2183. time_t t_temp = 0;
  2184. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2185. {
  2186. t_tmUpper = (DWORD)t_temp;
  2187. if (!t_Node->ClosedUpperBound())
  2188. {
  2189. if (t_tmUpper != 0)
  2190. {
  2191. t_tmUpper--;
  2192. }
  2193. else
  2194. {
  2195. t_bProcess = FALSE;
  2196. }
  2197. }
  2198. }
  2199. else
  2200. {
  2201. DWORD t_len = wcslen(t_Node->UpperBound());
  2202. if (t_len == NTEVT_DMTFLEN)
  2203. {
  2204. BOOL t_bIsLo = FALSE;
  2205. BOOL t_bIsHi = TRUE;
  2206. if (CheckTime(t_Node->LowerBound(), t_bIsLo, t_bIsHi))
  2207. {
  2208. if (t_bIsLo)
  2209. {
  2210. t_bProcess = FALSE;
  2211. }
  2212. }
  2213. else
  2214. {
  2215. t_bProcess = FALSE;
  2216. }
  2217. }
  2218. else
  2219. {
  2220. t_bProcess = FALSE;
  2221. }
  2222. }
  2223. }
  2224. if (t_tmUpper < t_tmLower)
  2225. {
  2226. t_bProcess = FALSE;
  2227. }
  2228. //now return all records including the bounds
  2229. if (t_bProcess)
  2230. {
  2231. t_Result = GetRecordsBetweenTimes(a_ErrorObject, a_logname, a_Generated, t_tmUpper, t_tmLower);
  2232. if (FAILED(t_Result))
  2233. {
  2234. break;
  2235. }
  2236. }
  2237. }
  2238. }
  2239. else
  2240. {
  2241. //want records with exactly the right time...
  2242. WBEMTime t_Time(t_Node->LowerBound());
  2243. time_t t_temp = 0;
  2244. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2245. {
  2246. t_Result = GetRecordsBetweenTimes(a_ErrorObject, a_logname, a_Generated, (DWORD)t_temp, (DWORD)t_temp);
  2247. if (FAILED(t_Result))
  2248. {
  2249. break;
  2250. }
  2251. }
  2252. }
  2253. }
  2254. return t_Result;
  2255. }
  2256. HRESULT ExecQueryAsyncEventObject::GetRecordsBetweenTimes(WbemProvErrorObject &a_ErrorObject, LPCWSTR a_logname,
  2257. BOOL a_Generated, DWORD a_dwUpper, DWORD a_dwLower)
  2258. {
  2259. HRESULT retVal = WBEM_E_FAILED;
  2260. CEventLogFile evtLog(a_logname, FALSE);
  2261. if (evtLog.IsValid())
  2262. {
  2263. DWORD t_NewRec = 0;
  2264. DWORD t_NumRecs = 0;
  2265. if (evtLog.GetLastRecordID(t_NewRec, t_NumRecs))
  2266. {
  2267. retVal = WBEM_S_NO_ERROR;
  2268. while (t_NumRecs > 0)
  2269. {
  2270. DWORD t_RecId = t_NumRecs/2;
  2271. if (t_NumRecs%2)
  2272. {
  2273. t_RecId++;
  2274. }
  2275. //adjust for the record number offset
  2276. if (t_RecId > t_NewRec)
  2277. {
  2278. //recordnumber has wrapped around...
  2279. t_RecId = 0xFFFFFFFF - t_RecId + t_NewRec + 1;
  2280. }
  2281. else
  2282. {
  2283. t_RecId = t_NewRec - t_RecId + 1;
  2284. }
  2285. DWORD t_dwEventSize = 0;
  2286. DWORD t_dwErr = evtLog.ReadRecord(t_RecId, &t_dwEventSize, TRUE);
  2287. if (0 == t_dwErr)
  2288. {
  2289. EVENTLOGRECORD* t_pEventBuffer = (EVENTLOGRECORD*) evtLog.GetBuffer();
  2290. DWORD t_Time = a_Generated ? t_pEventBuffer->TimeGenerated : t_pEventBuffer->TimeWritten;
  2291. if (a_dwUpper >= t_Time)
  2292. {
  2293. if (a_dwLower <= t_Time)
  2294. {
  2295. //generate all above and below this that match...
  2296. t_NumRecs = 0;
  2297. //below...
  2298. while((a_dwUpper >= t_Time) && (a_dwLower <= t_Time) && (t_dwEventSize != 0))
  2299. {
  2300. CEventlogRecord evtrec(a_logname, t_pEventBuffer, NULL, m_ClassObject, m_AClassObject);
  2301. IWbemClassObject* pInst = NULL;
  2302. if (evtrec.GenerateInstance(&pInst))
  2303. {
  2304. retVal = m_NotificationHandler->Indicate ( 1, & pInst );
  2305. pInst->Release();
  2306. if (FAILED(retVal))
  2307. {
  2308. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2309. a_ErrorObject.SetMessage ( L"Failed while indicating record instance." );
  2310. break;
  2311. }
  2312. }
  2313. // drop by length of this record and point to next record
  2314. t_dwEventSize -= t_pEventBuffer->Length;
  2315. if (t_dwEventSize == 0)
  2316. {
  2317. t_dwErr = evtLog.ReadRecord(0, &t_dwEventSize, TRUE);
  2318. if (t_dwErr == ERROR_SUCCESS)
  2319. {
  2320. t_pEventBuffer = (EVENTLOGRECORD*) evtLog.GetBuffer();
  2321. }
  2322. }
  2323. else
  2324. {
  2325. t_pEventBuffer = (PEVENTLOGRECORD) ((UCHAR*) t_pEventBuffer + t_pEventBuffer->Length);
  2326. }
  2327. t_Time = a_Generated ? t_pEventBuffer->TimeGenerated : t_pEventBuffer->TimeWritten;
  2328. }
  2329. if (SUCCEEDED(retVal))
  2330. {
  2331. //above...
  2332. evtLog.ReadRecord(t_RecId, &t_dwEventSize, FALSE);
  2333. //skip the record we've done already...
  2334. t_pEventBuffer = (EVENTLOGRECORD*) evtLog.GetBuffer();
  2335. t_dwEventSize -= t_pEventBuffer->Length;
  2336. if (t_dwEventSize != 0)
  2337. {
  2338. t_pEventBuffer = (PEVENTLOGRECORD) ((UCHAR*) t_pEventBuffer + t_pEventBuffer->Length);
  2339. t_Time = a_Generated ? t_pEventBuffer->TimeGenerated : t_pEventBuffer->TimeWritten;
  2340. while((a_dwUpper >= t_Time) && (a_dwLower <= t_Time) && (t_dwEventSize != 0))
  2341. {
  2342. CEventlogRecord evtrec(a_logname, t_pEventBuffer, NULL, m_ClassObject, m_AClassObject);
  2343. IWbemClassObject* pInst = NULL;
  2344. if (evtrec.GenerateInstance(&pInst))
  2345. {
  2346. retVal = m_NotificationHandler->Indicate ( 1, & pInst );
  2347. pInst->Release();
  2348. if (FAILED(retVal))
  2349. {
  2350. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2351. a_ErrorObject.SetMessage ( L"Failed while indicating record instance." );
  2352. break;
  2353. }
  2354. }
  2355. // drop by length of this record and point to next record
  2356. t_dwEventSize -= t_pEventBuffer->Length;
  2357. if (t_dwEventSize == 0)
  2358. {
  2359. t_dwErr = evtLog.ReadRecord(0, &t_dwEventSize, FALSE);
  2360. if (t_dwErr == ERROR_SUCCESS)
  2361. {
  2362. t_pEventBuffer = (EVENTLOGRECORD*) evtLog.GetBuffer();
  2363. }
  2364. }
  2365. else
  2366. {
  2367. t_pEventBuffer = (PEVENTLOGRECORD) ((UCHAR*) t_pEventBuffer + t_pEventBuffer->Length);
  2368. }
  2369. t_Time = a_Generated ? t_pEventBuffer->TimeGenerated : t_pEventBuffer->TimeWritten;
  2370. }
  2371. }
  2372. }
  2373. }
  2374. else
  2375. {
  2376. //too old, go higher done automatically by halving t_NumRecs
  2377. if (t_NumRecs > 1)
  2378. {
  2379. if ((t_NumRecs%2) || (t_NumRecs == 2))
  2380. {
  2381. t_NumRecs = t_NumRecs/2;
  2382. }
  2383. else
  2384. {
  2385. t_NumRecs = t_NumRecs/2 - 1;
  2386. }
  2387. }
  2388. else
  2389. {
  2390. t_NumRecs = 0;
  2391. }
  2392. }
  2393. }
  2394. else
  2395. {
  2396. //too recent, setup the number of records left and go lower by
  2397. //setting the upper limit to one less than we've checked...
  2398. if (t_NumRecs > 1)
  2399. {
  2400. t_NumRecs = t_NumRecs/2;
  2401. if (t_RecId == 1)
  2402. {
  2403. //we've wrapped...
  2404. t_NewRec = 0xFFFFFFFF;
  2405. }
  2406. else
  2407. {
  2408. t_NewRec = t_RecId - 1;
  2409. }
  2410. }
  2411. else
  2412. {
  2413. t_NumRecs = 0;
  2414. }
  2415. }
  2416. }
  2417. else
  2418. {
  2419. t_NumRecs = 0;
  2420. if (t_dwErr != ERROR_HANDLE_EOF)
  2421. {
  2422. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  2423. if ((t_dwErr == ERROR_ACCESS_DENIED) || (t_dwErr == ERROR_PRIVILEGE_NOT_HELD))
  2424. {
  2425. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  2426. a_ErrorObject.SetSecurityPrivRequired();
  2427. a_ErrorObject.SetSecurityPrivFailed();
  2428. a_ErrorObject.SetPrivilegeFailed();
  2429. }
  2430. else
  2431. {
  2432. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2433. }
  2434. a_ErrorObject.SetMessage ( L"Failed while searching one of the logfiles." );
  2435. }
  2436. break;
  2437. }
  2438. }
  2439. }
  2440. }
  2441. return retVal;
  2442. }
  2443. HRESULT ExecQueryAsyncEventObject::DoAllInLogfile(WbemProvErrorObject &a_ErrorObject, LPCWSTR a_logname, DWORD a_dwUpper, DWORD a_dwLower)
  2444. {
  2445. //process this logfile
  2446. HRESULT retVal = S_OK;
  2447. CEventLogFile evtLog(a_logname, FALSE);
  2448. BOOL bContinue = TRUE;
  2449. if (evtLog.IsValid())
  2450. {
  2451. evtLog.ReadLastRecord();
  2452. }
  2453. while (evtLog.IsValid() && SUCCEEDED(retVal) && bContinue)
  2454. {
  2455. DWORD dwEventSize = 0;
  2456. DWORD err = evtLog.ReadRecord(0, &dwEventSize, TRUE);
  2457. if (0 != err)
  2458. {
  2459. if (err != ERROR_HANDLE_EOF)
  2460. {
  2461. a_ErrorObject.SetStatus ( WBEM_PROV_E_UNEXPECTED );
  2462. if ((err == ERROR_ACCESS_DENIED) || (err == ERROR_PRIVILEGE_NOT_HELD))
  2463. {
  2464. a_ErrorObject.SetWbemStatus ( WBEM_S_ACCESS_DENIED );
  2465. a_ErrorObject.SetSecurityPrivRequired();
  2466. a_ErrorObject.SetSecurityPrivFailed();
  2467. a_ErrorObject.SetPrivilegeFailed();
  2468. }
  2469. else
  2470. {
  2471. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2472. }
  2473. a_ErrorObject.SetMessage ( L"Failed while enumerating one of the logfiles." );
  2474. DebugOut(
  2475. CNTEventProvider::g_NTEvtDebugLog->WriteFileAndLine (
  2476. _T(__FILE__),__LINE__,
  2477. L"ExecQueryAsyncEventObject :: Query_Record:Failed while enumerating one of the logfiles.\r\n"
  2478. );
  2479. )
  2480. }
  2481. break;
  2482. }
  2483. PEVENTLOGRECORD EventBuffer = (PEVENTLOGRECORD)evtLog.GetBuffer();
  2484. if (a_dwUpper != a_dwLower)
  2485. {
  2486. if ((EventBuffer->RecordNumber > a_dwUpper) || (EventBuffer->RecordNumber < a_dwLower))
  2487. {
  2488. break;
  2489. }
  2490. }
  2491. while (dwEventSize != 0)
  2492. {
  2493. if (a_dwUpper != a_dwLower)
  2494. {
  2495. if ((EventBuffer->RecordNumber > a_dwUpper) || (EventBuffer->RecordNumber < a_dwLower))
  2496. {
  2497. bContinue = FALSE;
  2498. break;
  2499. }
  2500. }
  2501. CEventlogRecord evtrec(a_logname, EventBuffer, NULL, m_ClassObject, m_AClassObject);
  2502. IWbemClassObject* pInst = NULL;
  2503. if (evtrec.GenerateInstance(&pInst))
  2504. {
  2505. retVal = m_NotificationHandler->Indicate ( 1, & pInst );
  2506. pInst->Release();
  2507. if (FAILED(retVal))
  2508. {
  2509. a_ErrorObject.SetWbemStatus ( WBEM_E_FAILED );
  2510. a_ErrorObject.SetMessage ( L"Failed while indicating record instance." );
  2511. }
  2512. }
  2513. // drop by length of this record and point to next record
  2514. dwEventSize -= EventBuffer->Length;
  2515. EventBuffer = (PEVENTLOGRECORD) ((UCHAR*) EventBuffer + EventBuffer->Length);
  2516. }
  2517. }
  2518. return retVal;
  2519. }
  2520. QueryPreprocessor :: QuadState ExecQueryAsyncEventObject :: Compare (
  2521. LONG a_Operand1,
  2522. LONG a_Operand2,
  2523. ULONG a_Operand1Func,
  2524. ULONG a_Operand2Func,
  2525. WmiTreeNode &a_OperatorType
  2526. )
  2527. {
  2528. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True;
  2529. switch ( a_Operand1Func )
  2530. {
  2531. case WmiValueNode :: WmiValueFunction :: Function_None:
  2532. {
  2533. }
  2534. break;
  2535. default:
  2536. {
  2537. }
  2538. break;
  2539. }
  2540. switch ( a_Operand2Func )
  2541. {
  2542. case WmiValueNode :: WmiValueFunction :: Function_None:
  2543. {
  2544. }
  2545. break;
  2546. default:
  2547. {
  2548. }
  2549. break;
  2550. }
  2551. if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualNode ) )
  2552. {
  2553. t_Status = a_Operand1 == a_Operand2
  2554. ? QueryPreprocessor :: QuadState :: State_True
  2555. : QueryPreprocessor :: QuadState :: State_False;
  2556. }
  2557. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotEqualNode ) )
  2558. {
  2559. t_Status = a_Operand1 != a_Operand2
  2560. ? QueryPreprocessor :: QuadState :: State_True
  2561. : QueryPreprocessor :: QuadState :: State_False;
  2562. }
  2563. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrGreaterNode ) )
  2564. {
  2565. t_Status = a_Operand1 >= a_Operand2
  2566. ? QueryPreprocessor :: QuadState :: State_True
  2567. : QueryPreprocessor :: QuadState :: State_False;
  2568. }
  2569. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrLessNode ) )
  2570. {
  2571. t_Status = a_Operand1 <= a_Operand2
  2572. ? QueryPreprocessor :: QuadState :: State_True
  2573. : QueryPreprocessor :: QuadState :: State_False;
  2574. }
  2575. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLessNode ) )
  2576. {
  2577. t_Status = a_Operand1 < a_Operand2
  2578. ? QueryPreprocessor :: QuadState :: State_True
  2579. : QueryPreprocessor :: QuadState :: State_False;
  2580. }
  2581. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorGreaterNode ) )
  2582. {
  2583. t_Status = a_Operand1 > a_Operand2
  2584. ? QueryPreprocessor :: QuadState :: State_True
  2585. : QueryPreprocessor :: QuadState :: State_False;
  2586. }
  2587. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLikeNode ) )
  2588. {
  2589. }
  2590. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotLikeNode ) )
  2591. {
  2592. }
  2593. return t_Status;
  2594. }
  2595. QueryPreprocessor :: QuadState ExecQueryAsyncEventObject :: Compare (
  2596. wchar_t *a_Operand1,
  2597. wchar_t *a_Operand2,
  2598. ULONG a_Operand1Func,
  2599. ULONG a_Operand2Func,
  2600. WmiTreeNode &a_OperatorType
  2601. )
  2602. {
  2603. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True;
  2604. wchar_t *a_Operand1AfterFunc = NULL;
  2605. wchar_t *a_Operand2AfterFunc = NULL;
  2606. switch ( a_Operand1Func )
  2607. {
  2608. case WmiValueNode :: WmiValueFunction :: Function_None:
  2609. {
  2610. }
  2611. break;
  2612. case WmiValueNode :: WmiValueFunction :: Function_Upper:
  2613. {
  2614. ULONG length = wcslen ( a_Operand1 );
  2615. wchar_t *a_Operand1AfterFunc = new wchar_t [ length + 1 ];
  2616. for ( ULONG index = 0; index < length; index ++ )
  2617. {
  2618. a_Operand1AfterFunc [ index ] = towupper ( a_Operand1 [ index ] );
  2619. }
  2620. }
  2621. break;
  2622. case WmiValueNode :: WmiValueFunction :: Function_Lower:
  2623. {
  2624. ULONG length = wcslen ( a_Operand1 );
  2625. wchar_t *a_Operand1AfterFunc = new wchar_t [ length + 1 ];
  2626. for ( ULONG index = 0; index < length; index ++ )
  2627. {
  2628. a_Operand1AfterFunc [ index ] = towlower ( a_Operand1 [ index ] );
  2629. }
  2630. }
  2631. break;
  2632. default:
  2633. {
  2634. }
  2635. break;
  2636. }
  2637. switch ( a_Operand2Func )
  2638. {
  2639. case WmiValueNode :: WmiValueFunction :: Function_None:
  2640. {
  2641. }
  2642. break;
  2643. case WmiValueNode :: WmiValueFunction :: Function_Upper:
  2644. {
  2645. ULONG length = wcslen ( a_Operand2 );
  2646. wchar_t *a_Operand2AfterFunc = new wchar_t [ length + 1 ];
  2647. for ( ULONG index = 0; index < length; index ++ )
  2648. {
  2649. a_Operand2AfterFunc [ index ] = towupper ( a_Operand2 [ index ] );
  2650. }
  2651. }
  2652. break;
  2653. case WmiValueNode :: WmiValueFunction :: Function_Lower:
  2654. {
  2655. ULONG length = wcslen ( a_Operand2 );
  2656. wchar_t *a_Operand2AfterFunc = new wchar_t [ length + 1 ];
  2657. for ( ULONG index = 0; index < length; index ++ )
  2658. {
  2659. a_Operand2AfterFunc [ index ] = towlower ( a_Operand2 [ index ] );
  2660. }
  2661. }
  2662. break;
  2663. default:
  2664. {
  2665. }
  2666. break;
  2667. }
  2668. const wchar_t *t_Arg1 = a_Operand1AfterFunc ? a_Operand1AfterFunc : a_Operand1;
  2669. const wchar_t *t_Arg2 = a_Operand2AfterFunc ? a_Operand2AfterFunc : a_Operand2;
  2670. if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualNode ) )
  2671. {
  2672. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  2673. {
  2674. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) == 0
  2675. ? QueryPreprocessor :: QuadState :: State_True
  2676. : QueryPreprocessor :: QuadState :: State_False ;
  2677. }
  2678. else
  2679. {
  2680. if ( ( t_Arg1 ) || ( t_Arg2 ) )
  2681. {
  2682. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2683. }
  2684. else
  2685. {
  2686. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2687. }
  2688. }
  2689. }
  2690. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotEqualNode ) )
  2691. {
  2692. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  2693. {
  2694. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) != 0
  2695. ? QueryPreprocessor :: QuadState :: State_True
  2696. : QueryPreprocessor :: QuadState :: State_False ;
  2697. }
  2698. else
  2699. {
  2700. if ( ( t_Arg1 ) || ( t_Arg2 ) )
  2701. {
  2702. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2703. }
  2704. else
  2705. {
  2706. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2707. }
  2708. }
  2709. }
  2710. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrGreaterNode ) )
  2711. {
  2712. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  2713. {
  2714. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) >= 0
  2715. ? QueryPreprocessor :: QuadState :: State_True
  2716. : QueryPreprocessor :: QuadState :: State_False ;
  2717. }
  2718. else
  2719. {
  2720. if ( t_Arg1 )
  2721. {
  2722. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2723. }
  2724. else
  2725. {
  2726. if ( t_Arg2 )
  2727. {
  2728. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2729. }
  2730. else
  2731. {
  2732. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2733. }
  2734. }
  2735. }
  2736. }
  2737. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorEqualOrLessNode ) )
  2738. {
  2739. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  2740. {
  2741. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) <= 0
  2742. ? QueryPreprocessor :: QuadState :: State_True
  2743. : QueryPreprocessor :: QuadState :: State_False ;
  2744. }
  2745. else
  2746. {
  2747. if ( ( t_Arg1 ) )
  2748. {
  2749. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2750. }
  2751. else
  2752. {
  2753. if ( t_Arg2 )
  2754. {
  2755. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2756. }
  2757. else
  2758. {
  2759. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2760. }
  2761. }
  2762. }
  2763. }
  2764. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLessNode ) )
  2765. {
  2766. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  2767. {
  2768. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) < 0
  2769. ? QueryPreprocessor :: QuadState :: State_True
  2770. : QueryPreprocessor :: QuadState :: State_False ;
  2771. }
  2772. else
  2773. {
  2774. if ( ( ! t_Arg1 ) && ( ! t_Arg2 ) )
  2775. {
  2776. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2777. }
  2778. else if ( t_Arg1 )
  2779. {
  2780. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2781. }
  2782. else
  2783. {
  2784. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2785. }
  2786. }
  2787. }
  2788. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorGreaterNode ) )
  2789. {
  2790. if ( ( t_Arg1 ) && ( t_Arg2 ) )
  2791. {
  2792. t_Status = wcscmp ( t_Arg1 , t_Arg2 ) > 0
  2793. ? QueryPreprocessor :: QuadState :: State_True
  2794. : QueryPreprocessor :: QuadState :: State_False ;
  2795. }
  2796. else
  2797. {
  2798. if ( ( ! t_Arg1 ) && ( ! t_Arg2 ) )
  2799. {
  2800. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2801. }
  2802. else if ( t_Arg1 )
  2803. {
  2804. t_Status = QueryPreprocessor :: QuadState :: State_True ;
  2805. }
  2806. else
  2807. {
  2808. t_Status = QueryPreprocessor :: QuadState :: State_False ;
  2809. }
  2810. }
  2811. }
  2812. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorLikeNode ) )
  2813. {
  2814. }
  2815. else if ( typeid ( a_OperatorType ) == typeid ( WmiOperatorNotLikeNode ) )
  2816. {
  2817. }
  2818. delete [] a_Operand1AfterFunc;
  2819. delete [] a_Operand2AfterFunc;
  2820. return t_Status;
  2821. }
  2822. QueryPreprocessor :: QuadState ExecQueryAsyncEventObject :: CompareDateTime (
  2823. IWbemClassObject *a_ClassObject,
  2824. BSTR a_PropertyName,
  2825. WmiTreeNode *a_Operator,
  2826. WmiTreeNode *a_Operand
  2827. )
  2828. {
  2829. /*
  2830. * If property and value can never occur then return State_False to imply empty set
  2831. * If property and value do not infer anything then return State_Undefined.
  2832. */
  2833. WmiStringNode *t_StringNode = ( WmiStringNode * ) a_Operand;
  2834. if ( t_StringNode == NULL || t_StringNode->GetValue() == NULL)
  2835. {
  2836. return QueryPreprocessor :: QuadState :: State_False;
  2837. }
  2838. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True;
  2839. WBEMTime t_Time((const BSTR)t_StringNode->GetValue());
  2840. if ( typeid ( *a_Operator ) == typeid ( WmiOperatorEqualNode ) )
  2841. {
  2842. time_t t_temp = 0;
  2843. t_Status = (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2844. ? QueryPreprocessor :: QuadState :: State_Undefined
  2845. : QueryPreprocessor :: QuadState :: State_False;
  2846. }
  2847. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorNotEqualNode ) )
  2848. {
  2849. time_t t_temp = 0;
  2850. t_Status = (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2851. ? QueryPreprocessor :: QuadState :: State_Undefined
  2852. : QueryPreprocessor :: QuadState :: State_True;
  2853. }
  2854. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorEqualOrGreaterNode ) )
  2855. {
  2856. //to do: check t_time >= val this will always be true if t_time >= max time_t
  2857. //will always be false if t_time is < 1970.
  2858. time_t t_temp = 0;
  2859. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2860. {
  2861. t_Status = QueryPreprocessor :: QuadState :: State_Undefined;
  2862. }
  2863. else
  2864. {
  2865. DWORD t_len = wcslen(t_StringNode->GetValue());
  2866. if (t_len == NTEVT_DMTFLEN)
  2867. {
  2868. BOOL t_bIsLo = FALSE;
  2869. BOOL t_bIsHi = TRUE;
  2870. if (CheckTime(t_StringNode->GetValue(), t_bIsLo, t_bIsHi))
  2871. {
  2872. if (t_bIsHi)
  2873. {
  2874. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2875. }
  2876. else if (t_bIsLo)
  2877. {
  2878. t_Status = QueryPreprocessor :: QuadState :: State_False;
  2879. }
  2880. }
  2881. else
  2882. {
  2883. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2884. }
  2885. }
  2886. else
  2887. {
  2888. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2889. }
  2890. }
  2891. }
  2892. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorEqualOrLessNode ) )
  2893. {
  2894. //to do: check t_time <= val this will always be true if t_time <= 1970
  2895. //will always be false if t_time is > max time_t.
  2896. time_t t_temp = 0;
  2897. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2898. {
  2899. t_Status = QueryPreprocessor :: QuadState :: State_Undefined;
  2900. }
  2901. else
  2902. {
  2903. DWORD t_len = wcslen(t_StringNode->GetValue());
  2904. if (t_len == NTEVT_DMTFLEN)
  2905. {
  2906. BOOL t_bIsLo = FALSE;
  2907. BOOL t_bIsHi = TRUE;
  2908. if (CheckTime(t_StringNode->GetValue(), t_bIsLo, t_bIsHi))
  2909. {
  2910. if (t_bIsHi)
  2911. {
  2912. t_Status = QueryPreprocessor :: QuadState :: State_False;
  2913. }
  2914. else if (t_bIsLo)
  2915. {
  2916. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2917. }
  2918. }
  2919. else
  2920. {
  2921. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2922. }
  2923. }
  2924. else
  2925. {
  2926. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2927. }
  2928. }
  2929. }
  2930. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorLessNode ) )
  2931. {
  2932. //to do: check t_time < val this will always be true if t_time < 1970
  2933. //will always be false if t_time is > max time_t.
  2934. time_t t_temp = 0;
  2935. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2936. {
  2937. t_Status = QueryPreprocessor :: QuadState :: State_Undefined;
  2938. }
  2939. else
  2940. {
  2941. DWORD t_len = wcslen(t_StringNode->GetValue());
  2942. if (t_len == NTEVT_DMTFLEN)
  2943. {
  2944. BOOL t_bIsLo = FALSE;
  2945. BOOL t_bIsHi = TRUE;
  2946. if (CheckTime(t_StringNode->GetValue(), t_bIsLo, t_bIsHi))
  2947. {
  2948. if (t_bIsHi)
  2949. {
  2950. t_Status = QueryPreprocessor :: QuadState :: State_False;
  2951. }
  2952. else if (t_bIsLo)
  2953. {
  2954. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2955. }
  2956. }
  2957. else
  2958. {
  2959. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2960. }
  2961. }
  2962. else
  2963. {
  2964. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2965. }
  2966. }
  2967. }
  2968. else if ( typeid ( *a_Operator ) == typeid ( WmiOperatorGreaterNode ) )
  2969. {
  2970. //to do: check t_time > val this will always be true if t_time > max time_t
  2971. //will always be false if t_time is < 1970.
  2972. time_t t_temp = 0;
  2973. if (t_Time.IsOk() && t_Time.Gettime_t(&t_temp))
  2974. {
  2975. t_Status = QueryPreprocessor :: QuadState :: State_Undefined;
  2976. }
  2977. else
  2978. {
  2979. DWORD t_len = wcslen(t_StringNode->GetValue());
  2980. if (t_len == NTEVT_DMTFLEN)
  2981. {
  2982. BOOL t_bIsLo = FALSE;
  2983. BOOL t_bIsHi = TRUE;
  2984. if (CheckTime(t_StringNode->GetValue(), t_bIsLo, t_bIsHi))
  2985. {
  2986. if (t_bIsHi)
  2987. {
  2988. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2989. }
  2990. else if (t_bIsLo)
  2991. {
  2992. t_Status = QueryPreprocessor :: QuadState :: State_False;
  2993. }
  2994. }
  2995. else
  2996. {
  2997. t_Status = QueryPreprocessor :: QuadState :: State_True;
  2998. }
  2999. }
  3000. else
  3001. {
  3002. t_Status = QueryPreprocessor :: QuadState :: State_True;
  3003. }
  3004. }
  3005. }
  3006. return t_Status;
  3007. }
  3008. QueryPreprocessor :: QuadState ExecQueryAsyncEventObject :: CompareString (
  3009. IWbemClassObject *a_ClassObject,
  3010. BSTR a_PropertyName,
  3011. WmiTreeNode *a_Operator,
  3012. WmiTreeNode *a_Operand
  3013. )
  3014. {
  3015. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True;
  3016. WmiStringNode *t_StringNode = ( WmiStringNode * ) a_Operand;
  3017. VARIANT t_Variant;
  3018. VariantInit ( & t_Variant );
  3019. HRESULT t_Result = a_ClassObject->Get ( a_PropertyName, 0, &t_Variant, NULL, NULL );
  3020. if ( SUCCEEDED ( t_Result ) )
  3021. {
  3022. t_Status = Compare (
  3023. t_StringNode->GetValue (),
  3024. t_Variant.bstrVal,
  3025. t_StringNode->GetPropertyFunction (),
  3026. t_StringNode->GetConstantFunction (),
  3027. *a_Operator
  3028. );
  3029. }
  3030. VariantClear ( & t_Variant );
  3031. return t_Status;
  3032. }
  3033. QueryPreprocessor :: QuadState ExecQueryAsyncEventObject :: CompareInteger (
  3034. IWbemClassObject *a_ClassObject,
  3035. BSTR a_PropertyName,
  3036. WmiTreeNode *a_Operator,
  3037. WmiTreeNode *a_Operand
  3038. )
  3039. {
  3040. QueryPreprocessor :: QuadState t_Status = QueryPreprocessor :: QuadState :: State_True;
  3041. WmiSignedIntegerNode *t_IntegerNode = ( WmiSignedIntegerNode * ) a_Operand;
  3042. VARIANT t_Variant;
  3043. VariantInit ( & t_Variant );
  3044. HRESULT t_Result = a_ClassObject->Get ( a_PropertyName, 0, &t_Variant, NULL, NULL );
  3045. if ( SUCCEEDED ( t_Result ) )
  3046. {
  3047. t_Status = Compare (
  3048. t_IntegerNode->GetValue (),
  3049. t_Variant.lVal,
  3050. t_IntegerNode->GetPropertyFunction (),
  3051. t_IntegerNode->GetConstantFunction (),
  3052. *a_Operator
  3053. );
  3054. }
  3055. VariantClear ( & t_Variant );
  3056. return t_Status;
  3057. }
  3058. WmiTreeNode *ExecQueryAsyncEventObject :: AllocTypeNode (
  3059. void *a_Context,
  3060. BSTR a_PropertyName,
  3061. VARIANT &a_Variant,
  3062. WmiValueNode :: WmiValueFunction a_PropertyFunction,
  3063. WmiValueNode :: WmiValueFunction a_ConstantFunction,
  3064. WmiTreeNode *a_Parent
  3065. )
  3066. {
  3067. WmiTreeNode *t_Node = NULL;
  3068. VARTYPE t_VarType = VT_NULL;
  3069. if ( *a_PropertyName == L'_' )
  3070. {
  3071. // System property
  3072. if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_CLASS ) == 0 &&
  3073. (V_VT(&a_Variant) == VT_BSTR))
  3074. {
  3075. t_Node = new WmiStringNode (
  3076. a_PropertyName,
  3077. a_Variant.bstrVal,
  3078. a_PropertyFunction,
  3079. a_ConstantFunction,
  3080. 0xFFFFFFFF,
  3081. a_Parent
  3082. );
  3083. }
  3084. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_SUPERCLASS ) == 0 &&
  3085. (V_VT(&a_Variant) == VT_BSTR))
  3086. {
  3087. t_Node = new WmiStringNode (
  3088. a_PropertyName,
  3089. a_Variant.bstrVal,
  3090. a_PropertyFunction,
  3091. a_ConstantFunction,
  3092. 0xFFFFFFFF,
  3093. a_Parent
  3094. );
  3095. }
  3096. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_GENUS ) == 0 &&
  3097. (V_VT(&a_Variant) == VT_I4))
  3098. {
  3099. t_Node = new WmiSignedIntegerNode (
  3100. a_PropertyName,
  3101. a_Variant.lVal,
  3102. 0xFFFFFFFF,
  3103. a_Parent
  3104. );
  3105. }
  3106. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_SERVER ) == 0 &&
  3107. (V_VT(&a_Variant) == VT_BSTR))
  3108. {
  3109. t_Node = new WmiStringNode (
  3110. a_PropertyName,
  3111. a_Variant.bstrVal,
  3112. a_PropertyFunction,
  3113. a_ConstantFunction,
  3114. 0xFFFFFFFF,
  3115. a_Parent
  3116. );
  3117. }
  3118. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_NAMESPACE ) == 0 &&
  3119. (V_VT(&a_Variant) == VT_BSTR))
  3120. {
  3121. t_Node = new WmiStringNode (
  3122. a_PropertyName,
  3123. a_Variant.bstrVal,
  3124. a_PropertyFunction,
  3125. a_ConstantFunction,
  3126. 0xFFFFFFFF,
  3127. a_Parent
  3128. );
  3129. }
  3130. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_PROPERTY_COUNT ) == 0 &&
  3131. (V_VT(&a_Variant) == VT_I4))
  3132. {
  3133. t_Node = new WmiSignedIntegerNode (
  3134. a_PropertyName,
  3135. a_Variant.lVal,
  3136. 0xFFFFFFFF,
  3137. a_Parent
  3138. );
  3139. }
  3140. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_DYNASTY ) == 0 &&
  3141. (V_VT(&a_Variant) == VT_BSTR))
  3142. {
  3143. t_Node = new WmiStringNode (
  3144. a_PropertyName,
  3145. a_Variant.bstrVal,
  3146. a_PropertyFunction,
  3147. a_ConstantFunction,
  3148. 0xFFFFFFFF,
  3149. a_Parent
  3150. );
  3151. }
  3152. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_RELPATH ) == 0 &&
  3153. (V_VT(&a_Variant) == VT_BSTR))
  3154. {
  3155. t_Node = new WmiStringNode (
  3156. a_PropertyName,
  3157. a_Variant.bstrVal,
  3158. a_PropertyFunction,
  3159. a_ConstantFunction,
  3160. 0xFFFFFFFF,
  3161. a_Parent
  3162. );
  3163. }
  3164. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_PATH ) == 0 &&
  3165. (V_VT(&a_Variant) == VT_BSTR))
  3166. {
  3167. t_Node = new WmiStringNode (
  3168. a_PropertyName,
  3169. a_Variant.bstrVal,
  3170. a_PropertyFunction,
  3171. a_ConstantFunction,
  3172. 0xFFFFFFFF,
  3173. a_Parent
  3174. );
  3175. }
  3176. else if ( _wcsicmp ( a_PropertyName, SYSTEM_PROPERTY_DERIVATION ) == 0 )
  3177. {
  3178. }
  3179. }
  3180. else
  3181. {
  3182. CIMTYPE t_VarType;
  3183. long t_Flavour;
  3184. VARIANT t_Variant;
  3185. VariantInit ( & t_Variant );
  3186. HRESULT t_Result = m_ClassObject->Get (
  3187. a_PropertyName,
  3188. 0,
  3189. & t_Variant,
  3190. & t_VarType,
  3191. & t_Flavour
  3192. );
  3193. if ( SUCCEEDED ( t_Result ) )
  3194. {
  3195. if ( t_VarType & CIM_FLAG_ARRAY )
  3196. {
  3197. }
  3198. else
  3199. {
  3200. switch ( t_VarType & ( ~ CIM_FLAG_ARRAY ) )
  3201. {
  3202. case CIM_BOOLEAN:
  3203. {
  3204. if(V_VT(&a_Variant) == VT_I4)
  3205. {
  3206. t_Node = new WmiSignedIntegerNode (
  3207. a_PropertyName,
  3208. a_Variant.lVal,
  3209. GetPriority ( a_PropertyName ),
  3210. a_Parent
  3211. );
  3212. }
  3213. else if (V_VT(&a_Variant) == VT_BOOL)
  3214. {
  3215. t_Node = new WmiSignedIntegerNode (
  3216. a_PropertyName,
  3217. (a_Variant.lVal == VARIANT_FALSE) ? 0 : 1,
  3218. GetPriority ( a_PropertyName ),
  3219. a_Parent
  3220. );
  3221. }
  3222. }
  3223. break;
  3224. case CIM_SINT8:
  3225. case CIM_SINT16:
  3226. case CIM_CHAR16:
  3227. case CIM_SINT32:
  3228. {
  3229. if(V_VT(&a_Variant) == VT_I4)
  3230. {
  3231. t_Node = new WmiSignedIntegerNode (
  3232. a_PropertyName,
  3233. a_Variant.lVal,
  3234. GetPriority ( a_PropertyName ),
  3235. a_Parent
  3236. );
  3237. }
  3238. }
  3239. break;
  3240. case CIM_UINT8:
  3241. case CIM_UINT16:
  3242. case CIM_UINT32:
  3243. {
  3244. if(V_VT(&a_Variant) == VT_I4)
  3245. {
  3246. t_Node = new WmiUnsignedIntegerNode (
  3247. a_PropertyName,
  3248. a_Variant.lVal,
  3249. GetPriority ( a_PropertyName ),
  3250. a_Parent
  3251. );
  3252. }
  3253. }
  3254. break;
  3255. case CIM_SINT64:
  3256. case CIM_UINT64:
  3257. {
  3258. if(V_VT(&a_Variant) == VT_BSTR)
  3259. {
  3260. t_Node = new WmiStringNode (
  3261. a_PropertyName,
  3262. a_Variant.bstrVal,
  3263. a_PropertyFunction,
  3264. a_ConstantFunction,
  3265. GetPriority ( a_PropertyName ),
  3266. a_Parent
  3267. );
  3268. }
  3269. else if(V_VT(&a_Variant) == VT_I4)
  3270. {
  3271. _variant_t t_uintBuff (&a_Variant);
  3272. t_Node = new WmiStringNode (
  3273. a_PropertyName,
  3274. (BSTR)((_bstr_t) t_uintBuff),
  3275. a_PropertyFunction,
  3276. a_ConstantFunction,
  3277. GetPriority ( a_PropertyName ),
  3278. a_Parent
  3279. );
  3280. }
  3281. }
  3282. break;
  3283. case CIM_STRING:
  3284. case CIM_DATETIME:
  3285. case CIM_REFERENCE:
  3286. {
  3287. if(V_VT(&a_Variant) == VT_BSTR)
  3288. {
  3289. t_Node = new WmiStringNode (
  3290. a_PropertyName,
  3291. a_Variant.bstrVal,
  3292. a_PropertyFunction,
  3293. a_ConstantFunction,
  3294. GetPriority ( a_PropertyName ),
  3295. a_Parent
  3296. );
  3297. }
  3298. }
  3299. break;
  3300. case CIM_REAL32:
  3301. case CIM_REAL64:
  3302. {
  3303. }
  3304. break;
  3305. case CIM_OBJECT:
  3306. case CIM_EMPTY:
  3307. {
  3308. }
  3309. break;
  3310. default:
  3311. {
  3312. }
  3313. break;
  3314. }
  3315. }
  3316. }
  3317. VariantClear ( & t_Variant );
  3318. }
  3319. return t_Node;
  3320. }
  3321. QueryPreprocessor :: QuadState ExecQueryAsyncEventObject :: InvariantEvaluate (
  3322. void *a_Context,
  3323. WmiTreeNode *a_Operator,
  3324. WmiTreeNode *a_Operand
  3325. )
  3326. {
  3327. /*
  3328. * If property and value are invariant i.e. will never change for all instances then return State_True.
  3329. * If property is not indexable or keyed then return State_True to define an unknown number of possible values which we cannot optimise against.
  3330. * If property and value can never occur then return State_False to imply empty set
  3331. * If property and value do not infer anything then return State_Undefined.
  3332. * If property and value are in error then return State_Error
  3333. * Never return State_ReEvaluate.
  3334. */
  3335. QueryPreprocessor :: QuadState t_State = QueryPreprocessor :: QuadState :: State_Error;
  3336. WmiValueNode *t_Node = ( WmiValueNode * ) a_Operand;
  3337. BSTR t_PropertyName = t_Node->GetPropertyName ();
  3338. if ( t_PropertyName != NULL )
  3339. {
  3340. if ( *t_PropertyName == L'_' )
  3341. {
  3342. // System property, must check values
  3343. if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_CLASS ) == 0 )
  3344. {
  3345. t_State = CompareString (
  3346. m_ClassObject,
  3347. SYSTEM_PROPERTY_CLASS,
  3348. a_Operator,
  3349. a_Operand
  3350. );
  3351. }
  3352. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_SUPERCLASS ) == 0 )
  3353. {
  3354. t_State = CompareString (
  3355. m_ClassObject,
  3356. SYSTEM_PROPERTY_SUPERCLASS,
  3357. a_Operator,
  3358. a_Operand
  3359. );
  3360. }
  3361. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_GENUS ) == 0 )
  3362. {
  3363. t_State = CompareInteger (
  3364. m_ClassObject,
  3365. SYSTEM_PROPERTY_GENUS,
  3366. a_Operator,
  3367. a_Operand
  3368. );
  3369. }
  3370. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_SERVER ) == 0 )
  3371. {
  3372. t_State = CompareString (
  3373. m_ClassObject,
  3374. SYSTEM_PROPERTY_SERVER,
  3375. a_Operator,
  3376. a_Operand
  3377. );
  3378. }
  3379. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_NAMESPACE ) == 0 )
  3380. {
  3381. t_State = CompareString (
  3382. m_ClassObject,
  3383. SYSTEM_PROPERTY_NAMESPACE,
  3384. a_Operator,
  3385. a_Operand
  3386. );
  3387. }
  3388. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_PROPERTY_COUNT ) == 0 )
  3389. {
  3390. t_State = CompareInteger (
  3391. m_ClassObject,
  3392. SYSTEM_PROPERTY_PROPERTY_COUNT,
  3393. a_Operator,
  3394. a_Operand
  3395. );
  3396. }
  3397. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_DYNASTY ) == 0 )
  3398. {
  3399. t_State = CompareString (
  3400. m_ClassObject,
  3401. SYSTEM_PROPERTY_DYNASTY,
  3402. a_Operator,
  3403. a_Operand
  3404. );
  3405. }
  3406. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_RELPATH ) == 0 )
  3407. {
  3408. t_State = CompareString (
  3409. m_ClassObject,
  3410. SYSTEM_PROPERTY_RELPATH,
  3411. a_Operator,
  3412. a_Operand
  3413. );
  3414. }
  3415. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_PATH ) == 0 )
  3416. {
  3417. t_State = CompareString (
  3418. m_ClassObject,
  3419. SYSTEM_PROPERTY_PATH,
  3420. a_Operator,
  3421. a_Operand
  3422. );
  3423. }
  3424. else if ( _wcsicmp ( t_PropertyName, SYSTEM_PROPERTY_DERIVATION ) == 0 )
  3425. {
  3426. t_State = QueryPreprocessor :: QuadState :: State_Undefined;
  3427. }
  3428. else
  3429. {
  3430. t_State = QueryPreprocessor :: QuadState :: State_Undefined;
  3431. }
  3432. }
  3433. else
  3434. {
  3435. //if it is time generated or time written check the max and min are ok
  3436. if ( _wcsicmp ( t_PropertyName, GENERATED_PROP ) == 0 )
  3437. {
  3438. t_State = CompareDateTime (
  3439. m_ClassObject,
  3440. SYSTEM_PROPERTY_PATH,
  3441. a_Operator,
  3442. a_Operand
  3443. );
  3444. }
  3445. else if ( _wcsicmp ( t_PropertyName, WRITTEN_PROP ) == 0 )
  3446. {
  3447. t_State = CompareDateTime (
  3448. m_ClassObject,
  3449. SYSTEM_PROPERTY_PATH,
  3450. a_Operator,
  3451. a_Operand
  3452. );
  3453. }
  3454. else
  3455. {
  3456. t_State = QueryPreprocessor :: QuadState :: State_Undefined;
  3457. }
  3458. }
  3459. }
  3460. else
  3461. {
  3462. t_State = QueryPreprocessor :: QuadState :: State_Undefined;
  3463. }
  3464. return t_State;
  3465. }
  3466. WmiRangeNode *ExecQueryAsyncEventObject :: AllocInfiniteRangeNode (
  3467. void *a_Context,
  3468. BSTR a_PropertyName
  3469. )
  3470. {
  3471. WmiRangeNode *t_RangeNode = NULL;
  3472. CIMTYPE t_VarType;
  3473. long t_Flavour;
  3474. VARIANT t_Variant;
  3475. VariantInit ( & t_Variant );
  3476. HRESULT t_Result = m_ClassObject->Get (
  3477. a_PropertyName,
  3478. 0,
  3479. & t_Variant,
  3480. & t_VarType,
  3481. & t_Flavour
  3482. );
  3483. if ( SUCCEEDED ( t_Result ) )
  3484. {
  3485. if ( t_VarType & CIM_FLAG_ARRAY )
  3486. {
  3487. }
  3488. else
  3489. {
  3490. switch ( t_VarType & ( ~ CIM_FLAG_ARRAY ) )
  3491. {
  3492. case CIM_BOOLEAN:
  3493. case CIM_SINT8:
  3494. case CIM_SINT16:
  3495. case CIM_CHAR16:
  3496. case CIM_SINT32:
  3497. {
  3498. t_RangeNode = new WmiSignedIntegerRangeNode (
  3499. a_PropertyName,
  3500. 0xFFFFFFFF,
  3501. TRUE,
  3502. TRUE,
  3503. FALSE,
  3504. FALSE,
  3505. 0,
  3506. 0,
  3507. NULL,
  3508. NULL
  3509. );
  3510. }
  3511. break;
  3512. case CIM_UINT8:
  3513. case CIM_UINT16:
  3514. case CIM_UINT32:
  3515. {
  3516. t_RangeNode = new WmiUnsignedIntegerRangeNode (
  3517. a_PropertyName,
  3518. 0xFFFFFFFF,
  3519. TRUE,
  3520. TRUE,
  3521. FALSE,
  3522. FALSE,
  3523. 0,
  3524. 0,
  3525. NULL,
  3526. NULL
  3527. );
  3528. }
  3529. break;
  3530. case CIM_SINT64:
  3531. case CIM_UINT64:
  3532. case CIM_STRING:
  3533. case CIM_DATETIME:
  3534. case CIM_REFERENCE:
  3535. {
  3536. t_RangeNode = new WmiStringRangeNode (
  3537. a_PropertyName,
  3538. 0x0,
  3539. TRUE,
  3540. TRUE,
  3541. FALSE,
  3542. FALSE,
  3543. NULL,
  3544. NULL,
  3545. NULL,
  3546. NULL
  3547. );
  3548. }
  3549. break;
  3550. case CIM_REAL32:
  3551. case CIM_REAL64:
  3552. {
  3553. }
  3554. break;
  3555. case CIM_OBJECT:
  3556. case CIM_EMPTY:
  3557. {
  3558. }
  3559. break;
  3560. default:
  3561. {
  3562. }
  3563. break;
  3564. }
  3565. }
  3566. }
  3567. VariantClear ( & t_Variant );
  3568. return t_RangeNode;
  3569. }
  3570. ULONG ExecQueryAsyncEventObject :: GetPriority ( BSTR a_PropertyName )
  3571. {
  3572. if ( _wcsicmp ( a_PropertyName, LOGFILE_PROP ) == 0 )
  3573. {
  3574. return 0;
  3575. }
  3576. if ( _wcsicmp ( a_PropertyName, RECORD_PROP ) == 0 )
  3577. {
  3578. return 1;
  3579. }
  3580. if ( _wcsicmp ( a_PropertyName, GENERATED_PROP ) == 0 )
  3581. {
  3582. return 2;
  3583. }
  3584. if ( _wcsicmp ( a_PropertyName, WRITTEN_PROP ) == 0 )
  3585. {
  3586. return 3;
  3587. }
  3588. return 0xFFFFFFFF;
  3589. }
  3590. BOOL ExecQueryAsyncEventObject::CheckTime( const BSTR a_wszText, BOOL &a_IsLow, BOOL &a_IsHigh )
  3591. {
  3592. a_IsLow = FALSE;
  3593. a_IsHigh = FALSE;
  3594. if (a_wszText == NULL)
  3595. {
  3596. return FALSE;
  3597. }
  3598. wchar_t t_DefaultBuffer[] = {L"16010101000000.000000+000"} ;
  3599. wchar_t t_DateBuffer[ NTEVT_DMTFLEN + 1 ] ;
  3600. t_DateBuffer[ NTEVT_DMTFLEN ] = NULL ;
  3601. // wildcard cleanup and validation
  3602. // ===============================
  3603. if( NTEVT_DMTFLEN != wcslen(a_wszText) )
  3604. {
  3605. return FALSE ;
  3606. }
  3607. const wchar_t *t_pwBuffer = (const wchar_t*)a_wszText ;
  3608. for( int t_i = 0; t_i < NTEVT_DMTFLEN; t_i++ )
  3609. {
  3610. switch( a_wszText[ t_i ] )
  3611. {
  3612. case '0':
  3613. case '1':
  3614. case '2':
  3615. case '3':
  3616. case '4':
  3617. case '5':
  3618. case '6':
  3619. case '7':
  3620. case '8':
  3621. case '9':
  3622. {
  3623. // stepping on separator or sign
  3624. if( NTEVT_DECPOS == t_i || NTEVT_SGNPOS == t_i )
  3625. {
  3626. return FALSE ;
  3627. }
  3628. t_DateBuffer[ t_i ] = a_wszText[ t_i ] ;
  3629. break ;
  3630. }
  3631. case '*':
  3632. {
  3633. // stepping on separator or sign
  3634. if( NTEVT_DECPOS == t_i || NTEVT_SGNPOS == t_i )
  3635. {
  3636. return FALSE ;
  3637. }
  3638. else
  3639. {
  3640. // replace with default stamp
  3641. t_DateBuffer[ t_i ] = t_DefaultBuffer[ t_i ] ;
  3642. }
  3643. break ;
  3644. }
  3645. case '.':
  3646. {
  3647. if( NTEVT_DECPOS != t_i )
  3648. {
  3649. return FALSE ;
  3650. }
  3651. t_DateBuffer[ t_i ] = a_wszText[ t_i ] ;
  3652. break ;
  3653. }
  3654. case '+':
  3655. case '-':
  3656. {
  3657. if( NTEVT_SGNPOS != t_i )
  3658. {
  3659. return FALSE ;
  3660. }
  3661. t_DateBuffer[ t_i ] = a_wszText[ t_i ] ;
  3662. break ;
  3663. }
  3664. default:
  3665. {
  3666. return FALSE ;
  3667. }
  3668. }
  3669. }
  3670. // Parse it
  3671. // ========
  3672. int nYear, nMonth, nDay, nHour, nMinute, nSecond, nMicro, nOffset;
  3673. WCHAR wchSep;
  3674. int nRes = swscanf (
  3675. (LPCWSTR)&t_DateBuffer,
  3676. L"%4d%2d%2d%2d%2d%2d.%6d%c%3d",
  3677. &nYear,
  3678. &nMonth,
  3679. &nDay,
  3680. &nHour,
  3681. &nMinute,
  3682. &nSecond,
  3683. &nMicro,
  3684. &wchSep,
  3685. &nOffset
  3686. );
  3687. if ( ( 9 != nRes ) )
  3688. {
  3689. return FALSE;
  3690. }
  3691. if (nYear < 1970)
  3692. {
  3693. a_IsLow = TRUE;
  3694. return TRUE;
  3695. }
  3696. BOOL retVal = FALSE;
  3697. WBEMTime t_max ((time_t)0xFFFFFFFF);
  3698. BSTR t_temp = t_max.GetBSTR();
  3699. if (t_temp)
  3700. {
  3701. if (_wcsicmp(a_wszText, t_temp) >= 0)
  3702. {
  3703. a_IsHigh = TRUE;
  3704. retVal = TRUE;
  3705. }
  3706. SysFreeString(t_temp);
  3707. }
  3708. // if we got here, the earlier WBEMTIME should have been OK so return FALSE.
  3709. return retVal;
  3710. }