Source code of Windows XP (NT5)
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.

4826 lines
113 KiB

  1. //***************************************************************************
  2. //
  3. // SYSTEM.CPP
  4. //
  5. // Module: HEALTHMON SERVER AGENT
  6. //
  7. // Purpose: This HMMACHINE class only has one instance. Its main member
  8. // function is called each time the polling interval goes off. It then goes
  9. // through all of the CDataGroups, CDataCollectors, and CThresholds.
  10. //
  11. // Copyright (c)1999 Microsoft Corporation, All Rights Reserved
  12. //
  13. //***************************************************************************
  14. #include <process.h>
  15. #include <tchar.h>
  16. //#include <objbase.h>
  17. #include "global.h"
  18. #include "system.h"
  19. extern HANDLE g_hConfigLock;
  20. extern CSystem* g_pSystem;
  21. extern CSystem* g_pStartupSystem;
  22. extern LPTSTR conditionLocStr[];
  23. extern LPTSTR stateLocStr[];
  24. extern HMODULE g_hModule;
  25. extern HRESULT SetLocStrings(void);
  26. extern void ClearLocStrings(void);
  27. static BYTE LocalSystemSID[] = {1,1,0,0,0,0,0,5,18,0,0,0};
  28. //////////////////////////////////////////////////////////////////////
  29. //////////////////////////////////////////////////////////////////////
  30. // Construction/Destruction
  31. //////////////////////////////////////////////////////////////////////
  32. CSystem::CSystem()
  33. {
  34. MY_OUTPUT(L"ENTER ***** CSystem::CSystem...", 4);
  35. g_pIWbemServices = NULL;
  36. g_pIWbemServicesCIMV2 = NULL;
  37. m_lAgentInterval = 0;
  38. m_lStartupDelayTime = 0;
  39. m_lFiveMinTimerTime = 0;
  40. m_lNumInstancesAccepted = 20;
  41. m_lNumberChanges = 0;
  42. m_bEnabled = FALSE;
  43. m_lCurrState = HM_GOOD;
  44. m_lPrevState = HM_GOOD;
  45. m_startTick = GetTickCount();
  46. m_szGUID = NULL;
  47. m_hmStatusType = HMSTATUS_SYSTEM;
  48. m_lNumberNormals = 0;
  49. m_lNumberWarnings = 0;
  50. m_lNumberCriticals = 0;
  51. m_lNumberChanges = 0;
  52. m_lPrevChildCount = 0;
  53. m_szMessage = NULL;
  54. m_szResetMessage = NULL;
  55. CThreshold::GetLocal();
  56. m_pTempSink = NULL;
  57. m_pEFTempSink = NULL;
  58. m_pECTempSink = NULL;
  59. m_pFTCBTempSink = NULL;
  60. m_pEFModTempSink = NULL;
  61. m_pECModTempSink = NULL;
  62. m_pFTCBModTempSink = NULL;
  63. m_processInfo.hProcess = NULL;
  64. m_bValidLoad = FALSE;
  65. m_numActionChanges = 0;
  66. MY_OUTPUT(L"EXIT ***** CSystem::CSystem...", 4);
  67. }
  68. CSystem::~CSystem()
  69. {
  70. int i, iSize;
  71. CDataGroup* pDataGroup;
  72. CAction* pAction;
  73. MY_OUTPUT(L"ENTER ***** ~CSystem::~CSystem...", 4);
  74. // g_pStartupSystem->RemovePointerFromMasterList(this);
  75. if (m_pTempSink)
  76. {
  77. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pTempSink);
  78. m_pTempSink->Release();
  79. m_pTempSink = NULL;
  80. }
  81. if (m_pEFTempSink)
  82. {
  83. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pEFTempSink);
  84. m_pEFTempSink->Release();
  85. m_pEFTempSink = NULL;
  86. }
  87. if (m_pECTempSink)
  88. {
  89. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pECTempSink);
  90. m_pECTempSink->Release();
  91. m_pECTempSink = NULL;
  92. }
  93. if (m_pFTCBTempSink)
  94. {
  95. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pFTCBTempSink);
  96. m_pFTCBTempSink->Release();
  97. m_pFTCBTempSink = NULL;
  98. }
  99. if (m_pEFModTempSink)
  100. {
  101. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pEFTempSink);
  102. m_pEFTempSink->Release();
  103. m_pEFTempSink = NULL;
  104. }
  105. if (m_pECModTempSink)
  106. {
  107. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pECTempSink);
  108. m_pECTempSink->Release();
  109. m_pECTempSink = NULL;
  110. }
  111. if (m_pFTCBModTempSink)
  112. {
  113. g_pIWbemServices->CancelAsyncCall((IWbemObjectSink*)m_pFTCBTempSink);
  114. m_pFTCBTempSink->Release();
  115. m_pFTCBTempSink = NULL;
  116. }
  117. if (m_szGUID)
  118. {
  119. delete [] m_szGUID;
  120. m_szGUID = NULL;
  121. }
  122. if (m_szMessage)
  123. {
  124. delete [] m_szMessage;
  125. m_szMessage = NULL;
  126. }
  127. if (m_szResetMessage)
  128. {
  129. delete [] m_szResetMessage;
  130. m_szResetMessage = NULL;
  131. }
  132. if (g_pSystemEventSink != NULL)
  133. {
  134. g_pSystemEventSink->Release();
  135. g_pSystemEventSink = NULL;
  136. }
  137. iSize = m_dataGroupList.size();
  138. for (i = 0; i < iSize ; i++)
  139. {
  140. MY_ASSERT(i<m_dataGroupList.size());
  141. pDataGroup = m_dataGroupList[i];
  142. delete pDataGroup;
  143. }
  144. iSize = m_actionList.size();
  145. for (i = 0; i < iSize ; i++)
  146. {
  147. MY_ASSERT(i<m_actionList.size());
  148. pAction = m_actionList[i];
  149. delete pAction;
  150. }
  151. CDataGroup::DGTerminationCleanup();
  152. CDataCollector::DETerminationCleanup();
  153. CThreshold::ThresholdTerminationCleanup();
  154. CBase::CleanupHRLList();
  155. CBase::CleanupEventLists();
  156. ClearLocStrings();
  157. m_bValidLoad = FALSE;
  158. MY_OUTPUT(L"EXIT ***** ~CSystem::~CSystem...", 4);
  159. }
  160. BOOL CSystem::InitWbemPointer(void)
  161. {
  162. HRESULT hRetRes = S_OK;
  163. BSTR bsNamespace = NULL;
  164. IWbemLocator *pLocator = NULL;
  165. MY_OUTPUT(L"ENTER ***** CSystem::InitWbemPointers...", 4);
  166. hRetRes = CoCreateInstance(CLSID_WbemAdministrativeLocator, NULL,
  167. CLSCTX_INPROC_SERVER,
  168. IID_IWbemLocator,
  169. (LPVOID*) &pLocator);
  170. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  171. bsNamespace = SysAllocString(L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor");
  172. MY_ASSERT(bsNamespace); if (!bsNamespace) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  173. hRetRes = pLocator->ConnectServer(bsNamespace,
  174. NULL,
  175. NULL,
  176. NULL,
  177. 0L,
  178. NULL,
  179. NULL,
  180. &g_pIWbemServices);
  181. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  182. SysFreeString(bsNamespace);
  183. bsNamespace = NULL;
  184. MY_OUTPUT(L"CSystem::InitWbemPointer()-Connected to namespace", 4);
  185. bsNamespace = SysAllocString(L"\\\\.\\root\\cimv2");
  186. MY_ASSERT(bsNamespace); if (!bsNamespace) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  187. hRetRes = pLocator->ConnectServer( bsNamespace,
  188. NULL,
  189. NULL,
  190. NULL,
  191. 0L,
  192. NULL,
  193. NULL,
  194. &g_pIWbemServicesCIMV2);
  195. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  196. SysFreeString(bsNamespace);
  197. bsNamespace = NULL;
  198. pLocator->Release();
  199. pLocator = NULL;
  200. MY_OUTPUT(L"EXIT ***** CSystem::InitWbemPointers...", 4);
  201. return TRUE;
  202. error:
  203. MY_ASSERT(FALSE);
  204. if (pLocator)
  205. pLocator->Release();
  206. if (bsNamespace)
  207. SysFreeString(bsNamespace);
  208. return FALSE;
  209. }
  210. HRESULT CSystem::InternalizeHMNamespace(void)
  211. {
  212. HRESULT hRes;
  213. HRESULT hRetRes;
  214. IWbemClassObject* pObj = NULL;
  215. IWbemClassObject* pNewObj = NULL;
  216. IWbemCallResult *pResult = 0;
  217. int i, iSize;
  218. CDataGroup *pDataGroup;
  219. MY_OUTPUT(L"ENTER ***** CSystem::InternalizeHMNamespace...", 4);
  220. hRetRes = SetLocStrings();
  221. if (hRetRes != S_OK) return hRetRes;
  222. g_pStartupSystem = this;
  223. hRetRes = InternalizeSystem();
  224. if (hRetRes==S_OK)
  225. {
  226. //
  227. // This reads in all the components heirarchy from the HealthMon namespace.
  228. // Each component reads in what is under it. DataPoints get read in, and they
  229. // in turn read in their thresholds.
  230. //
  231. hRetRes = InternalizeDataGroups();
  232. if (hRetRes==S_OK)
  233. {
  234. //
  235. // Set our state to enabled, or disabled and transfer to the child thresholds
  236. //
  237. iSize = m_dataGroupList.size();
  238. for (i=0; i < iSize; i++)
  239. {
  240. MY_ASSERT(i<m_dataGroupList.size());
  241. pDataGroup = m_dataGroupList[i];
  242. pDataGroup->SetParentEnabledFlag(m_bEnabled);
  243. }
  244. }
  245. else
  246. {
  247. g_pStartupSystem = NULL;
  248. return hRetRes;
  249. }
  250. }
  251. else
  252. {
  253. g_pStartupSystem = NULL;
  254. return hRetRes;
  255. }
  256. // Implements the dormancy feature. If the agent has never been active
  257. // before, we will be the first time, because a console connected to the box.
  258. // Create this instance, that will keep us loaded from now on, even if
  259. // WMI stops and starts.
  260. // create an instance of TimerEvent Filter.
  261. // instance of __EventFilter
  262. // {
  263. // Name = "MicrosoftHM_Filter";
  264. // Query = "select * from __TimerEvent where TimerId=\"MicrosoftHM_Timer\"";
  265. // QueryLanguage = "WQL";
  266. // };
  267. hRetRes = GetWbemObjectInst(&g_pIWbemServices, L"__EventFilter.Name=\"MicrosoftHM_Filter\"", NULL, &pObj);
  268. MY_HRESASSERT(hRetRes);
  269. if (!pObj)
  270. {
  271. hRetRes = GetWbemObjectInst(&g_pIWbemServices, L"__EventFilter", NULL, &pObj);
  272. MY_HRESASSERT(hRetRes);
  273. if (pObj)
  274. {
  275. pObj->SpawnInstance(0, &pNewObj);
  276. pObj->Release(); // Don't need the class any more
  277. PutStrProperty(pNewObj, L"Name", L"MicrosoftHM_Filter");
  278. PutStrProperty(pNewObj, L"Query", L"select * from __TimerEvent where TimerId=\"MicrosoftHM_Timer\"");
  279. PutStrProperty(pNewObj, L"QueryLanguage", L"WQL");
  280. hRes = g_pIWbemServices->PutInstance(pNewObj, 0, NULL, &pResult);
  281. MY_HRESASSERT(hRes);
  282. pNewObj->Release();
  283. pNewObj = NULL;
  284. }
  285. }
  286. else
  287. {
  288. pObj->Release();
  289. pObj = NULL;
  290. }
  291. g_pStartupSystem = NULL;
  292. MY_OUTPUT(L"EXIT ***** CSystem::InternalizeHMNamespace...", 4);
  293. return S_OK;
  294. }
  295. //
  296. // Get all the properties from the MicrosoftHM_SystemConfiguration instance
  297. //
  298. HRESULT CSystem::InternalizeSystem(void)
  299. {
  300. BSTR szString = NULL;
  301. IWbemClassObject* pInst = NULL;
  302. IWbemClassObject *pClassObject = NULL;
  303. BOOL fRes = TRUE;
  304. HRESULT hRetRes = S_OK;
  305. MY_OUTPUT(L"ENTER ***** CSystem::InternalizeSystem...", 4);
  306. CalcCurrTime();
  307. wcscpy(m_szDTTime, m_szDTCurrTime);
  308. wcscpy(m_szTime, m_szCurrTime);
  309. //
  310. // Get the properties from the SystemConfiguration instance
  311. //
  312. hRetRes = GetWbemObjectInst(&g_pIWbemServices, L"MicrosoftHM_SystemConfiguration.GUID=\"{@}\"", NULL, &pInst);
  313. if (!pInst)
  314. {
  315. MY_HRESASSERT(hRetRes);
  316. MY_OUTPUT(L"ERROR: Couldn't find MicrosoftHM_SYstemCOnfiguration", 4);
  317. return hRetRes;
  318. }
  319. hRetRes = LoadInstanceFromMOF(pInst);
  320. pInst->Release();
  321. pInst = NULL;
  322. MY_OUTPUT(L"EXIT ***** CSystem::InternalizeSystem...", 4);
  323. return hRetRes;
  324. }
  325. HRESULT CSystem::LoadInstanceFromMOF(IWbemClassObject* pInst)
  326. {
  327. int i, iSize;
  328. CDataGroup *pDataGroup;
  329. HRESULT hRetRes = S_OK;
  330. BOOL bRetValue = TRUE;
  331. MY_OUTPUT(L"ENTER ***** CSystem::LoadInstanceFromMOF...", 4);
  332. m_bValidLoad = TRUE;
  333. if (m_szGUID == NULL)
  334. {
  335. // Get the GUID property
  336. hRetRes = GetStrProperty(pInst, L"GUID", &m_szGUID);
  337. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) return hRetRes;
  338. }
  339. // if (bModifyPass == FALSE)
  340. // {
  341. // g_pStartupSystem->AddPointerToMasterList(this);
  342. // }
  343. m_lAgentInterval = HM_POLLING_INTERVAL;
  344. hRetRes = GetUint32Property(pInst, L"StartupDelayTime", &m_lStartupDelayTime);
  345. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  346. hRetRes = GetUint32Property(pInst, L"MaxInstancesPerDataCollector", &m_lNumInstancesAccepted);
  347. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  348. hRetRes = GetStrProperty(pInst, L"Message", &m_szMessage);
  349. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  350. hRetRes = GetStrProperty(pInst, L"ResetMessage", &m_szResetMessage);
  351. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  352. hRetRes = GetBoolProperty(pInst, L"Enabled", &m_bEnabled);
  353. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  354. //
  355. // Set our state to enabled, or disabled and transfer to the child thresholds
  356. //
  357. if (m_bEnabled==FALSE)
  358. {
  359. iSize = m_dataGroupList.size();
  360. for (i=0; i < iSize; i++)
  361. {
  362. MY_ASSERT(i<m_dataGroupList.size());
  363. pDataGroup = m_dataGroupList[i];
  364. pDataGroup->SetParentEnabledFlag(FALSE);
  365. }
  366. }
  367. else
  368. {
  369. iSize = m_dataGroupList.size();
  370. for (i=0; i < iSize; i++)
  371. {
  372. MY_ASSERT(i<m_dataGroupList.size());
  373. pDataGroup = m_dataGroupList[i];
  374. pDataGroup->SetParentEnabledFlag(TRUE);
  375. }
  376. }
  377. m_bValidLoad = TRUE;
  378. MY_OUTPUT(L"EXIT ***** CSystem::LoadInstanceFromMOF...", 4);
  379. return S_OK;
  380. error:
  381. MY_ASSERT(FALSE);
  382. if (m_szMessage)
  383. {
  384. delete [] m_szMessage;
  385. m_szMessage = NULL;
  386. }
  387. if (m_szResetMessage)
  388. {
  389. delete [] m_szResetMessage;
  390. m_szResetMessage = NULL;
  391. }
  392. m_bValidLoad = FALSE;
  393. return FALSE;
  394. }
  395. HRESULT CSystem::InternalizeDataGroups(void)
  396. {
  397. HRESULT hRetRes = S_OK;
  398. BSTR Language = NULL;
  399. BSTR Query = NULL;
  400. ULONG uReturned;
  401. IWbemClassObject *pObj = NULL;
  402. IEnumWbemClassObject *pEnum = NULL;
  403. LPTSTR pszTempGUID = NULL;
  404. MY_OUTPUT(L"ENTER ***** CSystem::InternalizeDataGroups...", 4);
  405. // Just loop through all top level DataGroups associated with the System.
  406. // Call a method of each, and have the datagroup load itself.
  407. // Dril down and then have each DataCollector load itself.
  408. Language = SysAllocString(L"WQL");
  409. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  410. Query = SysAllocString(L"ASSOCIATORS OF {MicrosoftHM_SystemConfiguration.GUID=\"{@}\"} WHERE ResultClass=MicrosoftHM_DataGroupConfiguration");
  411. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  412. // Issue query
  413. hRetRes = g_pIWbemServices->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY, 0, &pEnum);
  414. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) return hRetRes;
  415. SysFreeString(Query);
  416. Query = NULL;
  417. SysFreeString(Language);
  418. Language = NULL;
  419. // Retrieve objects in result set
  420. while (TRUE)
  421. {
  422. pObj = NULL;
  423. uReturned = 0;
  424. hRetRes = pEnum->Next(0, 1, &pObj, &uReturned);
  425. MY_ASSERT(hRetRes==S_OK || hRetRes==WBEM_S_FALSE);
  426. if (hRetRes!=S_OK && hRetRes!=WBEM_S_FALSE)
  427. {
  428. MY_HRESASSERT(hRetRes);
  429. pEnum->Release();
  430. pEnum = NULL;
  431. return hRetRes;
  432. }
  433. if (uReturned == 0)
  434. {
  435. break;
  436. }
  437. // See if this is already read in. Need to prevent endless loop, circular references.
  438. hRetRes = GetStrProperty(pObj, L"GUID", &pszTempGUID);
  439. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) return hRetRes;
  440. if (!g_pStartupSystem->FindPointerFromGUIDInMasterList(pszTempGUID))
  441. {
  442. // Create the internal class to represent the DataGroup
  443. CDataGroup* pDG = new CDataGroup;
  444. MY_ASSERT(pDG); if (!pDG) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  445. hRetRes = pDG->LoadInstanceFromMOF(pObj, NULL, m_szGUID);
  446. if (hRetRes==S_OK)
  447. {
  448. m_dataGroupList.push_back(pDG);
  449. }
  450. else
  451. {
  452. MY_ASSERT(FALSE);
  453. pDG->DeleteDGInternal();
  454. delete pDG;
  455. }
  456. }
  457. delete [] pszTempGUID;
  458. pszTempGUID = NULL;
  459. // Release it.
  460. pObj->Release();
  461. pObj = NULL;
  462. }
  463. // All done
  464. pEnum->Release();
  465. pEnum = NULL;
  466. MY_OUTPUT(L"EXIT ***** CSystem::InternalizeDataGroups...", 4);
  467. return S_OK;
  468. error:
  469. MY_ASSERT(FALSE);
  470. if (Query)
  471. SysFreeString(Query);
  472. if (Language)
  473. SysFreeString(Language);
  474. if (pObj)
  475. pObj->Release();
  476. if (pEnum)
  477. pEnum->Release();
  478. if (pszTempGUID)
  479. delete [] pszTempGUID;
  480. m_bValidLoad = FALSE;
  481. return hRetRes;
  482. }
  483. //
  484. // Called every second. We loop through all the DataGroups.
  485. // We call the member function of the DataGroup that will then loop through
  486. // all of its DataGroups and DataCollectors.
  487. //
  488. BOOL CSystem::OnAgentInterval(void)
  489. {
  490. BOOL bRetValue = TRUE;
  491. long state;
  492. int i;
  493. int iSize;
  494. CDataGroup *pDataGroup;
  495. CAction* pAction;
  496. DWORD currTick;
  497. DWORD dwReturnCode = 0L;
  498. long lCurrChildCount = 0;
  499. static int startup_init = 0;
  500. if (m_bValidLoad == FALSE)
  501. {
  502. currTick = GetTickCount();
  503. if ((150*1000) < (currTick-m_lFiveMinTimerTime))
  504. {
  505. m_lFiveMinTimerTime = currTick;
  506. CheckAllForBadLoad();
  507. }
  508. return FALSE;
  509. }
  510. if (startup_init == 0)
  511. {
  512. startup_init = 1;
  513. InternalizeActions();
  514. BOOL bSuccess = ImpersonateSelf(SecurityImpersonation);
  515. RemapActions();
  516. RevertToSelf();
  517. InitActionErrorListener();
  518. InitActionSIDListener(m_pEFTempSink, L"select * from __InstanceCreationEvent where TargetInstance isa \"__EventFilter\"");
  519. InitActionSIDListener(m_pECTempSink, L"select * from __InstanceCreationEvent where TargetInstance isa \"__EventConsumer\"");
  520. InitActionSIDListener(m_pFTCBTempSink, L"select * from __InstanceCreationEvent where TargetInstance isa \"__FilterToConsumerBinding\"");
  521. InitActionSIDListener(m_pEFModTempSink, L"select * from __InstanceModificationEvent where TargetInstance isa \"__EventFilter\"");
  522. InitActionSIDListener(m_pECModTempSink, L"select * from __InstanceModificationEvent where TargetInstance isa \"__EventConsumer\"");
  523. InitActionSIDListener(m_pFTCBModTempSink, L"select * from __InstanceModificationEvent where TargetInstance isa \"__FilterToConsumerBinding\"");
  524. DredgePerfmon();
  525. m_lFiveMinTimerTime = GetTickCount();
  526. }
  527. else
  528. {
  529. if (m_processInfo.hProcess)
  530. {
  531. GetExitCodeProcess(m_processInfo.hProcess, &dwReturnCode);
  532. if (dwReturnCode != STILL_ACTIVE)
  533. {
  534. CloseHandle(m_processInfo.hProcess);
  535. m_processInfo.hProcess = NULL;
  536. }
  537. }
  538. }
  539. currTick = GetTickCount();
  540. if ((150*1000) < (currTick-m_lFiveMinTimerTime))
  541. {
  542. m_lFiveMinTimerTime = currTick;
  543. CheckAllForBadLoad();
  544. // Safety net to catch just in case
  545. if (m_numActionChanges)
  546. {
  547. Sleep(5);
  548. m_numActionChanges = 0;
  549. BOOL bSuccess = ImpersonateSelf(SecurityImpersonation);
  550. RemapActions();
  551. RevertToSelf();
  552. }
  553. }
  554. if (m_numActionChanges>2)
  555. {
  556. Sleep(5);
  557. m_numActionChanges = 1;
  558. BOOL bSuccess = ImpersonateSelf(SecurityImpersonation);
  559. RemapActions();
  560. RevertToSelf();
  561. }
  562. MY_OUTPUT(L"ENTER ***** CSystem::OnAgentInterval...", 1);
  563. //
  564. // Wait for the delay time to be up before we do anything
  565. //
  566. if (m_lStartupDelayTime != -1)
  567. {
  568. currTick = GetTickCount();
  569. if ((m_lStartupDelayTime*1000) < (currTick-m_startTick))
  570. {
  571. m_lStartupDelayTime = -1;
  572. }
  573. else
  574. {
  575. return bRetValue;
  576. }
  577. }
  578. m_lNumberChanges = 0;
  579. //
  580. // Don't do anything if we are disabled.
  581. //
  582. if (m_bEnabled==FALSE && m_lCurrState==HM_DISABLED)
  583. {
  584. return bRetValue;
  585. }
  586. // Call to set the current time, for anyone to use that needs it.
  587. CalcCurrTime();
  588. //
  589. // Do Action scheduling and throttling
  590. //
  591. iSize = m_actionList.size();
  592. for (i=0; i < iSize; i++)
  593. {
  594. MY_ASSERT(i<m_actionList.size());
  595. pAction = m_actionList[i];
  596. pAction->OnAgentInterval();
  597. }
  598. m_lPrevState = m_lCurrState;
  599. iSize = m_dataGroupList.size();
  600. for (i=0; i < iSize; i++)
  601. {
  602. MY_ASSERT(i<m_dataGroupList.size());
  603. pDataGroup = m_dataGroupList[i];
  604. pDataGroup->OnAgentInterval();
  605. }
  606. if (m_bEnabled==FALSE)
  607. {
  608. m_lCurrState = HM_DISABLED;
  609. if (m_lNumberChanges == 0)
  610. m_lNumberChanges = 1;
  611. }
  612. else
  613. {
  614. //
  615. // Set State of the system to the worst of everything under it
  616. //
  617. m_lNumberNormals = 0;
  618. m_lNumberWarnings = 0;
  619. m_lNumberCriticals = 0;
  620. m_lNumberChanges = 0;
  621. m_lCurrState = -1;
  622. iSize = m_dataGroupList.size();
  623. lCurrChildCount = iSize;
  624. for (i = 0; i < iSize ; i++)
  625. {
  626. MY_ASSERT(i<m_dataGroupList.size());
  627. pDataGroup = m_dataGroupList[i];
  628. state = pDataGroup->GetCurrState();
  629. if (state==HM_SCHEDULEDOUT || state==HM_DISABLED)
  630. {
  631. state = HM_GOOD;
  632. }
  633. if (state > m_lCurrState)
  634. {
  635. m_lCurrState = state;
  636. }
  637. if (state == HM_GOOD)
  638. {
  639. m_lNumberNormals++;
  640. }
  641. if (state == HM_WARNING)
  642. {
  643. m_lNumberWarnings++;
  644. }
  645. if (state == HM_CRITICAL)
  646. {
  647. m_lNumberCriticals++;
  648. }
  649. if (pDataGroup->GetChange())
  650. {
  651. m_lNumberChanges++;
  652. }
  653. }
  654. // Maybe we don't have any Groups underneith
  655. // Or the disabled state of things below us did not roll up
  656. if (m_lCurrState == -1)
  657. {
  658. if (m_bEnabled==FALSE)
  659. {
  660. m_lCurrState = HM_DISABLED;
  661. }
  662. else
  663. {
  664. m_lCurrState = HM_GOOD;
  665. }
  666. if (m_lPrevState != m_lCurrState)
  667. {
  668. m_lNumberChanges++;
  669. }
  670. }
  671. else if (m_lPrevState==HM_DISABLED && m_lPrevState != m_lCurrState)
  672. {
  673. m_lNumberChanges++;
  674. }
  675. }
  676. if (m_lPrevChildCount!=lCurrChildCount)
  677. {
  678. if (m_lNumberChanges==0 && m_lPrevState!=m_lCurrState)
  679. {
  680. m_lNumberChanges++;
  681. }
  682. }
  683. m_lPrevChildCount = lCurrChildCount;
  684. FireEvents();
  685. MY_OUTPUT(L"EXIT ***** CSystem::OnAgentInterval...", 1);
  686. return bRetValue;
  687. }
  688. HRESULT CSystem::DredgePerfmon(void)
  689. {
  690. wchar_t szModule[_MAX_PATH];
  691. wchar_t szPath[_MAX_PATH];
  692. wchar_t szDir[_MAX_PATH];
  693. STARTUPINFO StartupInfo;
  694. DWORD dwReturnCode = 0L;
  695. BOOL bRetCode;
  696. MY_OUTPUT(L"ENTER ***** CSystem::DredgePerfmon...", 4);
  697. // Set the startup structure
  698. //==========================
  699. memset(&StartupInfo, '\0', sizeof(StartupInfo));
  700. StartupInfo.cb = sizeof(StartupInfo) ;
  701. StartupInfo.lpReserved = NULL ;
  702. StartupInfo.lpDesktop = NULL ;
  703. StartupInfo.lpTitle = NULL ;
  704. StartupInfo.dwFlags = 0; //STARTF_USESHOWWINDOW;//0;
  705. StartupInfo.wShowWindow = SW_HIDE;
  706. StartupInfo.cbReserved2 = 0 ;
  707. StartupInfo.lpReserved2 = NULL ;
  708. // Get the path to the dredger executable
  709. GetModuleFileNameW(g_hModule, szModule, _MAX_PATH);
  710. _tsplitpath(szModule, szPath, szDir, NULL, NULL);
  711. lstrcat(szPath, szDir);
  712. lstrcat(szPath, L"\\dredger.exe");
  713. bRetCode = CreateProcess(NULL, // App name
  714. szPath, // Full command line
  715. NULL, // Process security attributes
  716. NULL, // Thread security attributes
  717. FALSE, // Process inherits handles
  718. CREATE_NO_WINDOW, // Creation flags
  719. NULL, // Environment
  720. NULL, // Current directory
  721. &StartupInfo, // STARTUP_INFO
  722. &m_processInfo); // PROCESS_INFORMATION
  723. MY_ASSERT(bRetCode);
  724. MY_OUTPUT(L"EXIT ***** CSystem::DredgePerfmon...", 4);
  725. return S_OK;
  726. }
  727. // get polling interval in milliseconds.
  728. long CSystem::GetAgentInterval(void)
  729. {
  730. return (m_lAgentInterval*1000);
  731. }
  732. // get polling interval in milliseconds.
  733. long CSystem::GetStartupDelayTime(void)
  734. {
  735. return (m_lStartupDelayTime*1000);
  736. }
  737. // Pass on info to the DataCollector that has the GUID
  738. BOOL CSystem::HandleTempActionEvent(LPTSTR szGUID, IWbemClassObject* pObj)
  739. {
  740. BOOL bFound = FALSE;
  741. int i, iSize;
  742. CAction* pAction;
  743. DWORD dwErr = 0;
  744. if (m_bValidLoad == FALSE)
  745. return FALSE;
  746. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent BLOCK - g_hConfigLock BLOCK WAIT", 4);
  747. dwErr = WaitForSingleObject(g_hConfigLock, 120000);
  748. if(dwErr != WAIT_OBJECT_0)
  749. {
  750. if(dwErr = WAIT_TIMEOUT)
  751. {
  752. TRACE_MUTEX(L"TIMEOUT MUTEX");
  753. return FALSE;
  754. // return WBEM_S_TIMEDOUT;
  755. }
  756. else
  757. {
  758. MY_OUTPUT(L"WaitForSingleObject on Mutex failed",4);
  759. return FALSE;
  760. // return WBEM_E_FAILED;
  761. }
  762. }
  763. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent BLOCK - g_hConfigLock BLOCK GOT IT", 4);
  764. if (!g_pSystem)
  765. {
  766. ReleaseMutex(g_hConfigLock);
  767. return FALSE;
  768. }
  769. try
  770. {
  771. iSize = m_actionList.size();
  772. for (i=0; i < iSize; i++)
  773. {
  774. MY_ASSERT(i<m_actionList.size());
  775. pAction = m_actionList[i];
  776. if (pAction->HandleTempEvent(szGUID, pObj))
  777. {
  778. bFound = TRUE;
  779. break;
  780. }
  781. }
  782. if (bFound == FALSE)
  783. {
  784. MY_OUTPUT2(L"NOTFOUND: No body to handle event for GUID=%s", szGUID, 4);
  785. }
  786. }
  787. catch (...)
  788. {
  789. MY_ASSERT(FALSE);
  790. }
  791. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent g_hConfigLock BLOCK - RELEASE IT", 4);
  792. ReleaseMutex(g_hConfigLock);
  793. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent g_hConfigLock BLOCK - RELEASED", 4);
  794. return TRUE;
  795. }
  796. BOOL CSystem::HandleTempEvent(CEventQueryDataCollector *pEQDC, IWbemClassObject* pObj)
  797. {
  798. BOOL bFound = FALSE;
  799. int i, iSize;
  800. CBase* pBase;
  801. DWORD dwErr = 0;
  802. if (m_bValidLoad == FALSE)
  803. return FALSE;
  804. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent BLOCK - g_hConfigLock BLOCK WAIT", 4);
  805. dwErr = WaitForSingleObject(g_hConfigLock, 120000);
  806. if(dwErr != WAIT_OBJECT_0)
  807. {
  808. if(dwErr = WAIT_TIMEOUT)
  809. {
  810. TRACE_MUTEX(L"TIMEOUT MUTEX");
  811. return FALSE;
  812. // return WBEM_S_TIMEDOUT;
  813. }
  814. else
  815. {
  816. MY_OUTPUT(L"WaitForSingleObject on Mutex failed",4);
  817. return FALSE;
  818. // return WBEM_E_FAILED;
  819. }
  820. }
  821. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent BLOCK - g_hConfigLock BLOCK GOT IT", 4);
  822. if (!g_pSystem)
  823. {
  824. ReleaseMutex(g_hConfigLock);
  825. return FALSE;
  826. }
  827. try
  828. {
  829. iSize = m_masterList.size();
  830. for (i=0; i<iSize; i++)
  831. {
  832. MY_ASSERT(i<m_masterList.size());
  833. pBase = m_masterList[i];
  834. if (pBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR)
  835. {
  836. if (((CDataCollector *)pBase)->m_deType == HM_EQDE)
  837. {
  838. if (((CEventQueryDataCollector *)pBase) == pEQDC)
  839. {
  840. ((CEventQueryDataCollector *)pBase)->HandleTempEvent(pObj);
  841. bFound = TRUE;
  842. break;
  843. }
  844. }
  845. }
  846. }
  847. if (bFound == FALSE)
  848. {
  849. MY_OUTPUT2(L"NOTFOUND: No body to handle event for GUID=%s", pBase->m_szGUID, 4);
  850. }
  851. }
  852. catch (...)
  853. {
  854. MY_ASSERT(FALSE);
  855. }
  856. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent g_hConfigLock BLOCK - RELEASE IT", 4);
  857. ReleaseMutex(g_hConfigLock);
  858. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent g_hConfigLock BLOCK - RELEASED", 4);
  859. return TRUE;
  860. }
  861. HRESULT CSystem::SendHMSystemStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  862. {
  863. MY_OUTPUT2(L"System send for GUID=%s", pszGUID, 4);
  864. MY_ASSERT(pSink!=NULL);
  865. if (!wcscmp(L"{@}", pszGUID))
  866. {
  867. return SendHMSystemStatusInstances(pSink);
  868. }
  869. else
  870. {
  871. return WBEM_S_DIFFERENT;
  872. }
  873. }
  874. HRESULT CSystem::SendHMSystemStatusInstances(IWbemObjectSink* pSink)
  875. {
  876. HRESULT hRes = S_OK;
  877. IWbemClassObject* pInstance = NULL;
  878. MY_OUTPUT(L"ENTER ***** SendHMSystemStatusInstances...", 4);
  879. if (pSink == NULL)
  880. {
  881. MY_OUTPUT(L"CDP::SendInitialHMMachStatInstances-Invalid Sink", 1);
  882. return WBEM_E_FAILED;
  883. }
  884. hRes = GetHMSystemStatusInstance(&pInstance, FALSE);
  885. if (SUCCEEDED(hRes))
  886. {
  887. hRes = pSink->Indicate(1, &pInstance);
  888. if (FAILED(hRes) && hRes != WBEM_E_SERVER_TOO_BUSY)
  889. {
  890. MY_HRESASSERT(hRes);
  891. MY_OUTPUT(L"SendHMSystemStatusInstances-failed to send status!", 4);
  892. }
  893. else
  894. {
  895. MY_OUTPUT(L"SendHMSystemStatusInstances-success!", 4);
  896. }
  897. pInstance->Release();
  898. pInstance = NULL;
  899. }
  900. else
  901. {
  902. MY_HRESASSERT(hRes);
  903. MY_OUTPUT(L":SendHMSystemStatusInstances-failed to get instance!", 1);
  904. }
  905. MY_OUTPUT(L"EXIT ***** SendHMSystemStatusInstances...", 4);
  906. return hRes;
  907. }
  908. HRESULT CSystem::SendHMDataGroupStatusInstances(IWbemObjectSink* pSink)
  909. {
  910. BOOL bRetValue = TRUE;
  911. int i;
  912. int iSize;
  913. CDataGroup *pDataGroup;
  914. MY_OUTPUT(L"ENTER ***** CSystem::SendDataGroupStatusInstances...", 4);
  915. iSize = m_dataGroupList.size();
  916. for (i = 0; i < iSize ; i++)
  917. {
  918. MY_ASSERT(i<m_dataGroupList.size());
  919. pDataGroup = m_dataGroupList[i];
  920. pDataGroup->SendHMDataGroupStatusInstances(pSink);
  921. }
  922. MY_OUTPUT(L"EXIT ***** CSystem::SendDataGroupStatusInstances...", 4);
  923. return bRetValue;
  924. }
  925. HRESULT CSystem::SendHMDataGroupStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  926. {
  927. HRESULT hRetRes = S_OK;
  928. int i;
  929. int iSize;
  930. CDataGroup *pDataGroup;
  931. MY_OUTPUT(L"ENTER ***** CSystem::SendDataGroupStatusInstance...", 4);
  932. MY_OUTPUT2(L"DG send for GUID=%s", pszGUID, 4);
  933. iSize = m_dataGroupList.size();
  934. for (i=0; i<iSize; i++)
  935. {
  936. MY_ASSERT(i<m_dataGroupList.size());
  937. pDataGroup = m_dataGroupList[i];
  938. hRetRes = pDataGroup->SendHMDataGroupStatusInstance(pSink, pszGUID);
  939. if (hRetRes==S_OK)
  940. {
  941. break;
  942. }
  943. else if (hRetRes!=WBEM_S_DIFFERENT)
  944. {
  945. break;
  946. }
  947. }
  948. if (hRetRes==WBEM_S_DIFFERENT)
  949. {
  950. hRetRes = WBEM_E_NOT_FOUND;
  951. MY_OUTPUT(L"GUID not found", 4);
  952. }
  953. MY_OUTPUT(L"EXIT ***** CSystem::SendDataGroupStatusInstance...", 4);
  954. return hRetRes;
  955. }
  956. HRESULT CSystem::SendHMDataCollectorStatusInstances(IWbemObjectSink* pSink)
  957. {
  958. BOOL bRetValue = TRUE;
  959. int i;
  960. int iSize;
  961. CDataGroup *pDataGroup;
  962. MY_OUTPUT(L"ENTER ***** CSystem::SendDataCollectorStatusInstances...", 4);
  963. iSize = m_dataGroupList.size();
  964. for (i = 0; i < iSize ; i++)
  965. {
  966. MY_ASSERT(i<m_dataGroupList.size());
  967. pDataGroup = m_dataGroupList[i];
  968. pDataGroup->SendHMDataCollectorStatusInstances(pSink);
  969. }
  970. MY_OUTPUT(L"EXIT ***** CSystem::SendDataCollectorStatusInstances...", 4);
  971. return bRetValue;
  972. }
  973. HRESULT CSystem::SendHMDataCollectorStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  974. {
  975. HRESULT hRetRes = S_OK;
  976. int i;
  977. int iSize;
  978. CDataGroup *pDataGroup;
  979. MY_OUTPUT(L"ENTER ***** CSystem::SendDataCollectorStatusInstance...", 4);
  980. MY_OUTPUT2(L"DC send for GUID=%s", pszGUID, 4);
  981. iSize = m_dataGroupList.size();
  982. for (i=0; i<iSize; i++)
  983. {
  984. MY_ASSERT(i<m_dataGroupList.size());
  985. pDataGroup = m_dataGroupList[i];
  986. hRetRes = pDataGroup->SendHMDataCollectorStatusInstance(pSink, pszGUID);
  987. if (hRetRes==S_OK)
  988. {
  989. break;
  990. }
  991. else if (hRetRes!=WBEM_S_DIFFERENT)
  992. {
  993. break;
  994. }
  995. }
  996. if (hRetRes==WBEM_S_DIFFERENT)
  997. {
  998. hRetRes = WBEM_E_NOT_FOUND;
  999. MY_OUTPUT(L"GUID not found", 4);
  1000. }
  1001. MY_OUTPUT(L"EXIT ***** CSystem::SendDataCollectorStatusInstance...", 4);
  1002. return hRetRes;
  1003. }
  1004. HRESULT CSystem::SendHMDataCollectorPerInstanceStatusInstances(IWbemObjectSink* pSink)
  1005. {
  1006. BOOL bRetValue = TRUE;
  1007. int i;
  1008. int iSize;
  1009. CDataGroup *pDataGroup;
  1010. MY_OUTPUT(L"ENTER ***** CSystem::SendDataCollectorPerInstanceStatusInstances...", 4);
  1011. iSize = m_dataGroupList.size();
  1012. for (i = 0; i < iSize ; i++)
  1013. {
  1014. MY_ASSERT(i<m_dataGroupList.size());
  1015. pDataGroup = m_dataGroupList[i];
  1016. pDataGroup->SendHMDataCollectorPerInstanceStatusInstances(pSink);
  1017. }
  1018. MY_OUTPUT(L"EXIT ***** CSystem::SendDataCollectorPerInstanceStatusInstances...", 4);
  1019. return bRetValue;
  1020. }
  1021. HRESULT CSystem::SendHMDataCollectorPerInstanceStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  1022. {
  1023. HRESULT hRetRes = S_OK;
  1024. int i;
  1025. int iSize;
  1026. CDataGroup *pDataGroup;
  1027. MY_OUTPUT(L"ENTER ***** CSystem::SendDataCollectorPerInstanceStatusInstance...", 4);
  1028. MY_OUTPUT2(L"DC send for GUID=%s", pszGUID, 4);
  1029. iSize = m_dataGroupList.size();
  1030. for (i=0; i<iSize; i++)
  1031. {
  1032. MY_ASSERT(i<m_dataGroupList.size());
  1033. pDataGroup = m_dataGroupList[i];
  1034. hRetRes = pDataGroup->SendHMDataCollectorPerInstanceStatusInstance(pSink, pszGUID);
  1035. if (hRetRes==S_OK)
  1036. {
  1037. break;
  1038. }
  1039. else if (hRetRes!=WBEM_S_DIFFERENT)
  1040. {
  1041. break;
  1042. }
  1043. }
  1044. if (hRetRes==WBEM_S_DIFFERENT)
  1045. {
  1046. hRetRes = WBEM_E_NOT_FOUND;
  1047. MY_OUTPUT(L"GUID not found", 4);
  1048. }
  1049. MY_OUTPUT(L"EXIT ***** CSystem::SendDataCollectorPerInstanceStatusInstance...", 4);
  1050. return hRetRes;
  1051. }
  1052. HRESULT CSystem::SendHMDataCollectorStatisticsInstances(IWbemObjectSink* pSink)
  1053. {
  1054. BOOL bRetValue = TRUE;
  1055. int i, iSize;
  1056. CDataGroup *pDataGroup;
  1057. IWbemClassObject** aObjects;
  1058. IWbemClassObject* pInstance = NULL;
  1059. MY_OUTPUT(L"ENTER ***** CSystem::SendDataCollectorStatisticsInstances...", 4);
  1060. iSize = m_dataGroupList.size();
  1061. for (i = 0; i < iSize ; i++)
  1062. {
  1063. MY_ASSERT(i<m_dataGroupList.size());
  1064. pDataGroup = m_dataGroupList[i];
  1065. pDataGroup->SendHMDataCollectorStatisticsInstances(pSink);
  1066. }
  1067. //
  1068. // Loop through the DataCollectorStatistics Events and send them as one indicate
  1069. //
  1070. iSize = mg_DCStatsInstList.size();
  1071. aObjects = new IWbemClassObject*[iSize];
  1072. if (aObjects)
  1073. {
  1074. for (i=0; i < iSize; i++)
  1075. {
  1076. MY_ASSERT(i<mg_DCStatsInstList.size());
  1077. pInstance = mg_DCStatsInstList[i];
  1078. aObjects[i] = pInstance;
  1079. }
  1080. SendEvents(pSink, aObjects, iSize);
  1081. }
  1082. for (i=0; i < iSize; i++)
  1083. {
  1084. MY_ASSERT(i<mg_DCStatsInstList.size());
  1085. pInstance = mg_DCStatsInstList[i];
  1086. pInstance->Release();
  1087. }
  1088. mg_DCStatsInstList.clear();
  1089. if (aObjects)
  1090. delete [] aObjects;
  1091. MY_OUTPUT(L"EXIT ***** CSystem::SendDataCollectorStatisticsInstances...", 4);
  1092. return bRetValue;
  1093. }
  1094. HRESULT CSystem::SendHMDataCollectorStatisticsInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  1095. {
  1096. HRESULT hRetRes = S_OK;
  1097. int i;
  1098. int iSize;
  1099. CDataGroup *pDataGroup;
  1100. IWbemClassObject* pInstance = NULL;
  1101. IWbemClassObject** aObjects;
  1102. MY_OUTPUT(L"ENTER ***** CSystem::SendDataCollectorStatisticsInstance...", 4);
  1103. MY_OUTPUT2(L"DCStatistics send for GUID=%s", pszGUID, 4);
  1104. iSize = m_dataGroupList.size();
  1105. for (i=0; i<iSize; i++)
  1106. {
  1107. MY_ASSERT(i<m_dataGroupList.size());
  1108. pDataGroup = m_dataGroupList[i];
  1109. hRetRes = pDataGroup->SendHMDataCollectorStatisticsInstance(pSink, pszGUID);
  1110. if (hRetRes==S_OK)
  1111. {
  1112. break;
  1113. }
  1114. else if (hRetRes!=WBEM_S_DIFFERENT)
  1115. {
  1116. break;
  1117. }
  1118. }
  1119. //
  1120. // Loop through the DataCollectorStatistics Events and send them as one indicate
  1121. //
  1122. iSize = mg_DCStatsInstList.size();
  1123. aObjects = new IWbemClassObject*[iSize];
  1124. if (aObjects)
  1125. {
  1126. for (i=0; i < iSize; i++)
  1127. {
  1128. MY_ASSERT(i<mg_DCStatsInstList.size());
  1129. pInstance = mg_DCStatsInstList[i];
  1130. aObjects[i] = pInstance;
  1131. }
  1132. SendEvents(pSink, aObjects, iSize);
  1133. }
  1134. for (i=0; i < iSize; i++)
  1135. {
  1136. MY_ASSERT(i<mg_DCStatsInstList.size());
  1137. pInstance = mg_DCStatsInstList[i];
  1138. pInstance->Release();
  1139. }
  1140. mg_DCStatsInstList.clear();
  1141. if (aObjects)
  1142. delete [] aObjects;
  1143. if (hRetRes==WBEM_S_DIFFERENT)
  1144. {
  1145. hRetRes = WBEM_E_NOT_FOUND;
  1146. MY_OUTPUT(L"GUID not found", 4);
  1147. return WBEM_E_NOT_FOUND;
  1148. }
  1149. MY_OUTPUT(L"EXIT ***** CSystem::SendDataCollectorStatisticsInstance...", 4);
  1150. return hRetRes;
  1151. }
  1152. HRESULT CSystem::SendHMThresholdStatusInstances(IWbemObjectSink* pSink)
  1153. {
  1154. HRESULT hRetRes = S_OK;
  1155. int i;
  1156. int iSize;
  1157. CDataGroup *pDataGroup;
  1158. MY_OUTPUT(L"ENTER ***** CSystem::SendThresholdStatusInstances...", 4);
  1159. iSize = m_dataGroupList.size();
  1160. for (i = 0; i < iSize ; i++)
  1161. {
  1162. MY_ASSERT(i<m_dataGroupList.size());
  1163. pDataGroup = m_dataGroupList[i];
  1164. pDataGroup->SendHMThresholdStatusInstances(pSink);
  1165. }
  1166. MY_OUTPUT(L"EXIT ***** CSystem::SendThresholdStatusInstances...", 4);
  1167. return hRetRes;
  1168. }
  1169. HRESULT CSystem::SendHMThresholdStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  1170. {
  1171. HRESULT hRetRes = S_OK;
  1172. int i;
  1173. int iSize;
  1174. CDataGroup *pDataGroup;
  1175. MY_OUTPUT(L"ENTER ***** CSystem::SendHMThresholdStatusInstance...", 4);
  1176. MY_OUTPUT2(L"Threshold send for GUID=%s", pszGUID, 4);
  1177. iSize = m_dataGroupList.size();
  1178. for (i=0; i<iSize; i++)
  1179. {
  1180. MY_ASSERT(i<m_dataGroupList.size());
  1181. pDataGroup = m_dataGroupList[i];
  1182. hRetRes = pDataGroup->SendHMThresholdStatusInstance(pSink, pszGUID);
  1183. if (hRetRes==S_OK)
  1184. {
  1185. break;
  1186. }
  1187. else if (hRetRes!=WBEM_S_DIFFERENT)
  1188. {
  1189. break;
  1190. }
  1191. }
  1192. if (hRetRes==WBEM_S_DIFFERENT)
  1193. {
  1194. hRetRes = WBEM_E_NOT_FOUND;
  1195. MY_OUTPUT(L"GUID not found", 4);
  1196. }
  1197. MY_OUTPUT(L"EXIT ***** CSystem::SendHMThresholdStatusInstance...", 4);
  1198. return hRetRes;
  1199. }
  1200. #ifdef SAVE
  1201. NOT USED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1202. NOT USED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1203. NOT USED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1204. HRESULT CSystem::SendHMThresholdStatusInstanceInstances(IWbemObjectSink* pSink)
  1205. {
  1206. BOOL bRetValue = TRUE;
  1207. int i;
  1208. int iSize;
  1209. CDataGroup *pDataGroup;
  1210. MY_OUTPUT(L"ENTER ***** CSystem::SendThresholdStatusInstanceInstances...", 4);
  1211. iSize = m_dataGroupList.size();
  1212. for (i = 0; i < iSize ; i++)
  1213. {
  1214. MY_ASSERT(i<m_dataGroupList.size());
  1215. pDataGroup = m_dataGroupList[i];
  1216. pDataGroup->SendHMThresholdStatusInstanceInstances(pSink);
  1217. }
  1218. MY_OUTPUT(L"EXIT ***** CSystem::SendThresholdStatusInstanceInstances...", 4);
  1219. return bRetValue;
  1220. }
  1221. NOT USED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1222. NOT USED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1223. NOT USED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1224. HRESULT CSystem::SendHMThresholdStatusInstanceInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  1225. {
  1226. BOOL bRetValue = TRUE;
  1227. int i;
  1228. int iSize;
  1229. CDataGroup *pDataGroup;
  1230. MY_OUTPUT(L"ENTER ***** CSystem::SendHMThresholdStatusInstanceInstance...", 4);
  1231. MY_OUTPUT2(L"ThresholdStatusInstances send for GUID=%s", pszGUID, 4);
  1232. iSize = m_dataGroupList.size();
  1233. for (i=0; i<iSize; i++)
  1234. {
  1235. MY_ASSERT(i<m_dataGroupList.size());
  1236. pDataGroup = m_dataGroupList[i];
  1237. if (pDataGroup->SendHMThresholdStatusInstanceInstance(pSink, pszGUID))
  1238. {
  1239. MY_OUTPUT(L"Found", 4);
  1240. break;
  1241. }
  1242. }
  1243. MY_OUTPUT(L"EXIT ***** CSystem::SendHMThresholdStatusInstanceInstance...", 4);
  1244. return bRetValue;
  1245. }
  1246. #endif
  1247. HRESULT CSystem::SendHMActionStatusInstances(IWbemObjectSink* pSink)
  1248. {
  1249. HRESULT hRetRes = S_OK;
  1250. int i;
  1251. int iSize;
  1252. CAction *pAction;
  1253. MY_OUTPUT(L"ENTER ***** CSystem::SendActionStatusInstances...", 4);
  1254. iSize = m_actionList.size();
  1255. for (i = 0; i < iSize; i++)
  1256. {
  1257. MY_ASSERT(i<m_actionList.size());
  1258. pAction = m_actionList[i];
  1259. pAction->SendHMActionStatusInstances(pSink);
  1260. }
  1261. MY_OUTPUT(L"EXIT ***** CSystem::SendActionStatusInstances...", 4);
  1262. return hRetRes;
  1263. }
  1264. HRESULT CSystem::SendHMActionStatusInstance(IWbemObjectSink* pSink, LPTSTR pszGUID)
  1265. {
  1266. HRESULT hRetRes = S_OK;
  1267. int i;
  1268. int iSize;
  1269. CAction *pAction;
  1270. MY_OUTPUT(L"ENTER ***** CSystem::SendHMActionStatusInstance...", 4);
  1271. MY_OUTPUT2(L"ActionStatus send for GUID=%s", pszGUID, 4);
  1272. iSize = m_actionList.size();
  1273. for (i=0; i<iSize; i++)
  1274. {
  1275. MY_ASSERT(i<m_actionList.size());
  1276. pAction = m_actionList[i];
  1277. hRetRes = pAction->SendHMActionStatusInstance(pSink, pszGUID);
  1278. if (hRetRes==S_OK)
  1279. {
  1280. break;
  1281. }
  1282. else if (hRetRes!=WBEM_S_DIFFERENT)
  1283. {
  1284. break;
  1285. }
  1286. }
  1287. if (hRetRes==WBEM_S_DIFFERENT)
  1288. {
  1289. hRetRes = WBEM_E_NOT_FOUND;
  1290. MY_OUTPUT(L"GUID not found", 4);
  1291. }
  1292. MY_OUTPUT(L"EXIT ***** CSystem::SendHMActionStatusInstance...", 4);
  1293. return hRetRes;
  1294. }
  1295. BOOL CSystem::FireEvents(void)
  1296. {
  1297. IWbemClassObject* pInstance = NULL;
  1298. int i, iSize;
  1299. // Send the System event
  1300. FireEvent();
  1301. //
  1302. // Loop through the DataGroup Events and send them as one indicate
  1303. //
  1304. iSize = mg_DGEventList.size();
  1305. for (i=0; i < iSize; i++)
  1306. {
  1307. MY_ASSERT(i<mg_DGEventList.size());
  1308. pInstance = mg_DGEventList[i];
  1309. SendEvents(g_pDataGroupEventSink, &pInstance, 1);
  1310. pInstance->Release();
  1311. }
  1312. mg_DGEventList.clear();
  1313. //
  1314. // Loop through the DataCollector Events and send them as one indicate
  1315. //
  1316. iSize = mg_DCEventList.size();
  1317. for (i=0; i < iSize; i++)
  1318. {
  1319. MY_ASSERT(i<mg_DCEventList.size());
  1320. pInstance = mg_DCEventList[i];
  1321. SendEvents(g_pDataCollectorEventSink, &pInstance, 1);
  1322. pInstance->Release();
  1323. }
  1324. mg_DCEventList.clear();
  1325. //
  1326. // Loop through the DataCollector PerInstance Events and send them as one indicate
  1327. //
  1328. iSize = mg_DCPerInstanceEventList.size();
  1329. for (i=0; i < iSize; i++)
  1330. {
  1331. MY_ASSERT(i<mg_DCPerInstanceEventList.size());
  1332. pInstance = mg_DCPerInstanceEventList[i];
  1333. SendEvents(g_pDataCollectorPerInstanceEventSink, &pInstance, 1);
  1334. pInstance->Release();
  1335. }
  1336. mg_DCPerInstanceEventList.clear();
  1337. //
  1338. // Loop through the Threshold Events and send them as one indicate
  1339. //
  1340. iSize = mg_TEventList.size();
  1341. for (i=0; i < iSize; i++)
  1342. {
  1343. MY_ASSERT(i<mg_TEventList.size());
  1344. pInstance = mg_TEventList[i];
  1345. SendEvents(g_pThresholdEventSink, &pInstance, 1);
  1346. pInstance->Release();
  1347. }
  1348. mg_TEventList.clear();
  1349. //
  1350. // Loop through the ThresholdInstance Events and send them as one indicate
  1351. //
  1352. // iSize = mg_TIEventList.size();
  1353. // for (i=0; i < iSize; i++)
  1354. // {
  1355. // MY_ASSERT(i<mg_TIEventList.size());
  1356. // pInstance = mg_TIEventList[i];
  1357. // SendEvents(g_pThresholdInstanceEventSink, &pInstance, 1);
  1358. // pInstance->Release();
  1359. // }
  1360. // mg_TIEventList.clear();
  1361. //
  1362. // Loop through the DataCollectorStatistics Events and send them as one indicate
  1363. //
  1364. iSize = mg_DCStatsEventList.size();
  1365. MY_ASSERT(iSize==0);
  1366. #ifdef SAVE
  1367. for (i=0; i < iSize; i++)
  1368. {
  1369. MY_ASSERT(i<mg_DCStatsEventList.size());
  1370. pInstance = mg_DCStatsEventList[i];
  1371. SendEvents(g_pDataCollectorStatisticsEventSink, &pInstance, 1);
  1372. pInstance->Release();
  1373. }
  1374. mg_DCStatsEventList.clear();
  1375. #endif
  1376. #ifdef SAVE
  1377. XXX
  1378. // IWbemClassObject** aObjects;
  1379. Need to wait for the Whistler fix for sending multiple objects with one Indicate
  1380. //
  1381. // Loop through the DataGroup Events and send them as one indicate
  1382. //
  1383. iSize = mg_DGEventList.size();
  1384. aObjects = new IWbemClassObject*[iSize];
  1385. for (i=0; i < iSize; i++)
  1386. {
  1387. MY_ASSERT(i<mg_DGEventList.size());
  1388. pInstance = mg_DGEventList[i];
  1389. aObjects[i] = pInstance;
  1390. }
  1391. SendEvents(g_pDataGroupEventSink, aObjects, iSize);
  1392. for (i=0; i < iSize; i++)
  1393. {
  1394. MY_ASSERT(i<mg_DGEventList.size());
  1395. pInstance = mg_DGEventList[i];
  1396. pInstance->Release();
  1397. }
  1398. mg_DGEventList.clear();
  1399. delete [] aObjects;
  1400. .
  1401. .
  1402. .
  1403. #endif
  1404. return TRUE;
  1405. }
  1406. //
  1407. // If there has been a change in the state then send an event
  1408. //
  1409. BOOL CSystem::FireEvent(void)
  1410. {
  1411. HRESULT hRes;
  1412. BOOL bRetValue = TRUE;
  1413. IWbemClassObject* pInstance = NULL;
  1414. MY_OUTPUT(L"ENTER ***** CSystem::FireEvent...", 2);
  1415. // Don't send if no-one is listening!
  1416. if (g_pSystemEventSink == NULL)
  1417. {
  1418. return bRetValue;
  1419. }
  1420. // A quick test to see if anything has really changed!
  1421. // Proceed if there have been changes
  1422. if (m_lNumberChanges!=0 && m_lPrevState!=m_lCurrState)
  1423. {
  1424. }
  1425. else
  1426. {
  1427. return FALSE;
  1428. }
  1429. // Update time if there has been a change
  1430. wcscpy(m_szDTTime, m_szDTCurrTime);
  1431. wcscpy(m_szTime, m_szCurrTime);
  1432. hRes = GetHMSystemStatusInstance(&pInstance, TRUE);
  1433. if (SUCCEEDED(hRes) && g_pSystemEventSink)
  1434. {
  1435. MY_OUTPUT2(L"EVENT: System State Change=%d", m_lCurrState, 4);
  1436. hRes = g_pSystemEventSink->Indicate(1, &pInstance);
  1437. // WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  1438. if (FAILED(hRes) && hRes != WBEM_E_SERVER_TOO_BUSY)
  1439. {
  1440. MY_HRESASSERT(hRes);
  1441. bRetValue = FALSE;
  1442. MY_OUTPUT(L"Failed on Indicate!", 4);
  1443. }
  1444. pInstance->Release();
  1445. pInstance = NULL;
  1446. }
  1447. else
  1448. {
  1449. MY_HRESASSERT(hRes);
  1450. MY_OUTPUT(L"failed to get instance!", 4);
  1451. }
  1452. MY_OUTPUT(L"EXIT ***** CSystem::FireEvent...", 2);
  1453. return bRetValue;
  1454. }
  1455. HRESULT CSystem::GetHMSystemStatusInstance(IWbemClassObject** ppInstance, BOOL bEventBased)
  1456. {
  1457. TCHAR szTemp[1024];
  1458. IWbemClassObject* pClass = NULL;
  1459. BSTR bsString = NULL;
  1460. HRESULT hRetRes;
  1461. MY_OUTPUT(L"ENTER ***** GetHMSystemStatusInstance...", 1);
  1462. if (bEventBased)
  1463. bsString = SysAllocString(L"MicrosoftHM_SystemStatusEvent");
  1464. else
  1465. bsString = SysAllocString(L"MicrosoftHM_SystemStatus");
  1466. MY_ASSERT(bsString); if (!bsString) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1467. hRetRes = g_pIWbemServices->GetObject(bsString, 0L, NULL, &pClass, NULL);
  1468. SysFreeString(bsString);
  1469. bsString = NULL;
  1470. if (FAILED(hRetRes))
  1471. {
  1472. MY_HRESASSERT(hRetRes);
  1473. MY_OUTPUT2(L"CSystem::GetHMSystemStatusInstance()-Couldn't get HMSystemStatusInstance Error: 0x%08x",hRetRes,4);
  1474. return hRetRes;
  1475. }
  1476. hRetRes = pClass->SpawnInstance(0, ppInstance);
  1477. pClass->Release();
  1478. pClass = NULL;
  1479. if (FAILED(hRetRes))
  1480. {
  1481. MY_HRESASSERT(hRetRes);
  1482. MY_OUTPUT2(L"CSystem::GetHMSystemStatusInstance()-Couldn't get HMSystemStatusInstance Error: 0x%08x",hRetRes,4);
  1483. return hRetRes;
  1484. }
  1485. if (m_bValidLoad == FALSE)
  1486. {
  1487. hRetRes = PutStrProperty(*ppInstance, L"GUID", L"{@}");
  1488. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1489. hRetRes = PutUint32Property(*ppInstance, L"State", HM_CRITICAL);
  1490. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1491. if (g_hResLib == NULL || !LoadString(g_hResLib, HMRES_SYSTEM_LOADFAIL, szTemp, 1024))
  1492. {
  1493. wcscpy(szTemp, L"System failed to load.");
  1494. }
  1495. hRetRes = PutStrProperty(*ppInstance, L"Message", szTemp);
  1496. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1497. hRetRes = PutStrProperty(*ppInstance, L"Name", L"...");
  1498. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1499. }
  1500. else
  1501. {
  1502. hRetRes = PutStrProperty(*ppInstance, L"GUID", L"{@}");
  1503. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1504. // Get the computer name of the machine
  1505. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 1;
  1506. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  1507. if (GetComputerName(szComputerName, &dwNameLen))
  1508. {
  1509. hRetRes = PutStrProperty(*ppInstance, L"Name", szComputerName);
  1510. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1511. hRetRes = PutStrProperty(*ppInstance, L"SystemName", szComputerName);
  1512. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1513. }
  1514. else
  1515. {
  1516. hRetRes = PutStrProperty(*ppInstance, L"Name", L"LocalMachine");
  1517. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1518. hRetRes = PutStrProperty(*ppInstance, L"SystemName", L"LocalMachine");
  1519. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1520. }
  1521. hRetRes = PutStrProperty(*ppInstance, L"TimeGeneratedGMT", m_szDTTime);
  1522. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1523. hRetRes = PutStrProperty(*ppInstance, L"LocalTimeFormatted", m_szTime);
  1524. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1525. hRetRes = PutUint32Property(*ppInstance, L"State", m_lCurrState);
  1526. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1527. if (m_lCurrState != HM_GOOD)
  1528. {
  1529. hRetRes = PutStrProperty(*ppInstance, L"Message", m_szMessage);
  1530. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1531. }
  1532. else
  1533. {
  1534. hRetRes = PutStrProperty(*ppInstance, L"Message", m_szResetMessage);
  1535. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  1536. }
  1537. FormatMessage(*ppInstance);
  1538. }
  1539. MY_OUTPUT(L"EXIT ***** GetHMSystemStatusInstance...", 1);
  1540. return hRetRes;
  1541. error:
  1542. MY_ASSERT(FALSE);
  1543. if (bsString)
  1544. SysFreeString(bsString);
  1545. if (pClass)
  1546. pClass->Release();
  1547. return hRetRes;
  1548. }
  1549. HRESULT CSystem::ModSystem(IWbemClassObject* pObj)
  1550. {
  1551. HRESULT hRetRes = S_OK;
  1552. MY_OUTPUT(L"ENTER ***** CSystem::ModSystem...", 4);
  1553. // Re-load
  1554. hRetRes = LoadInstanceFromMOF(pObj);
  1555. MY_OUTPUT(L"EXIT ***** CSystem::ModSystem...", 4);
  1556. return hRetRes;
  1557. }
  1558. HRESULT CSystem::ModDataGroup(IWbemClassObject* pObj)
  1559. {
  1560. HRESULT hRes;
  1561. HRESULT hRetRes = WBEM_E_NOT_FOUND;
  1562. int i, iSize;
  1563. VARIANT v;
  1564. CDataGroup* pDataGroup;
  1565. MY_OUTPUT(L"ENTER ***** CSystem::ModDataGroup...", 4);
  1566. VariantInit(&v);
  1567. hRes = pObj->Get(L"GUID", 0L, &v, 0L, 0L);
  1568. if (FAILED(hRes))
  1569. {
  1570. MY_HRESASSERT(hRes);
  1571. MY_OUTPUT(L"ENTER ***** CSystem::ModDataGroup-Unexpected Error!...", 4);
  1572. VariantClear(&v);
  1573. return hRes;
  1574. }
  1575. MY_OUTPUT2(L"DG mod for GUID=%s", V_BSTR(&v), 4);
  1576. //
  1577. // Search right under the System to find the DataGroup.
  1578. // If don't find, drill down until we do.
  1579. //
  1580. iSize = m_dataGroupList.size();
  1581. for (i = 0; i < iSize ; i++)
  1582. {
  1583. MY_ASSERT(i<m_dataGroupList.size());
  1584. pDataGroup = m_dataGroupList[i];
  1585. hRetRes = pDataGroup->FindAndModDataGroup(V_BSTR(&v), pObj);
  1586. if (hRetRes==S_OK)
  1587. {
  1588. break;
  1589. }
  1590. else if (hRetRes!=WBEM_S_DIFFERENT)
  1591. {
  1592. break;
  1593. }
  1594. }
  1595. VariantClear(&v);
  1596. if (hRetRes==WBEM_S_DIFFERENT)
  1597. {
  1598. hRetRes = WBEM_E_NOT_FOUND;
  1599. MY_OUTPUT(L"GUID not found", 4);
  1600. }
  1601. else
  1602. {
  1603. MY_OUTPUT(L"Found", 4);
  1604. }
  1605. MY_OUTPUT(L"EXIT ***** CSystem::ModDataGroup...", 4);
  1606. return hRetRes;
  1607. }
  1608. HRESULT CSystem::ModDataCollector(IWbemClassObject* pObj)
  1609. {
  1610. HRESULT hRes;
  1611. HRESULT hRetRes = WBEM_E_NOT_FOUND;
  1612. int i, iSize;
  1613. VARIANT v;
  1614. CDataGroup* pDataGroup;
  1615. MY_OUTPUT(L"ENTER ***** CSystem::ModDataCollector...", 4);
  1616. VariantInit(&v);
  1617. hRes = pObj->Get(L"GUID", 0L, &v, 0L, 0L);
  1618. if (FAILED(hRes))
  1619. {
  1620. MY_HRESASSERT(hRes);
  1621. MY_OUTPUT(L"ENTER ***** CSystem::ModDataCollector-Unexpected Error!...", 4);
  1622. VariantClear(&v);
  1623. return hRes;
  1624. }
  1625. MY_OUTPUT2(L"DC mod for GUID=%s", V_BSTR(&v), 4);
  1626. //
  1627. // Search right under the System to find the DataGroup.
  1628. // If don't find, drill down until we do.
  1629. //
  1630. iSize = m_dataGroupList.size();
  1631. for (i = 0; i < iSize ; i++)
  1632. {
  1633. MY_ASSERT(i<m_dataGroupList.size());
  1634. pDataGroup = m_dataGroupList[i];
  1635. hRetRes = pDataGroup->FindAndModDataCollector(V_BSTR(&v), pObj);
  1636. if (hRetRes==S_OK)
  1637. {
  1638. break;
  1639. }
  1640. else if (hRetRes!=WBEM_S_DIFFERENT)
  1641. {
  1642. break;
  1643. }
  1644. }
  1645. VariantClear(&v);
  1646. if (hRetRes==WBEM_S_DIFFERENT)
  1647. {
  1648. hRetRes = WBEM_E_NOT_FOUND;
  1649. MY_OUTPUT(L"GUID not found", 4);
  1650. }
  1651. else
  1652. {
  1653. MY_OUTPUT(L"Found", 4);
  1654. }
  1655. MY_OUTPUT(L"EXIT ***** CSystem::ModDataCollector...", 4);
  1656. return hRetRes;
  1657. }
  1658. HRESULT CSystem::ModThreshold(IWbemClassObject* pObj)
  1659. {
  1660. HRESULT hRes;
  1661. HRESULT hRetRes = WBEM_E_NOT_FOUND;
  1662. int i, iSize;
  1663. VARIANT v;
  1664. CDataGroup* pDataGroup;
  1665. MY_OUTPUT(L"ENTER ***** CSystem::ModThreshold...", 4);
  1666. VariantInit(&v);
  1667. hRes = pObj->Get(L"GUID", 0L, &v, 0L, 0L);
  1668. if (FAILED(hRes))
  1669. {
  1670. MY_HRESASSERT(hRes);
  1671. MY_OUTPUT(L"ENTER ***** CSystem::ModThreshold-Unexpected Error!...", 4);
  1672. VariantClear(&v);
  1673. return hRes;
  1674. }
  1675. MY_OUTPUT2(L"Threshold mod for GUID=%s", V_BSTR(&v), 4);
  1676. //
  1677. // Search right under the System to find the DataGroup.
  1678. // If don't find, drill down until we do.
  1679. //
  1680. iSize = m_dataGroupList.size();
  1681. for (i = 0; i < iSize ; i++)
  1682. {
  1683. MY_ASSERT(i<m_dataGroupList.size());
  1684. pDataGroup = m_dataGroupList[i];
  1685. hRetRes = pDataGroup->FindAndModThreshold(V_BSTR(&v), pObj);
  1686. if (hRetRes==S_OK)
  1687. {
  1688. break;
  1689. }
  1690. else if (hRetRes!=WBEM_S_DIFFERENT)
  1691. {
  1692. break;
  1693. }
  1694. }
  1695. VariantClear(&v);
  1696. if (hRetRes==WBEM_S_DIFFERENT)
  1697. {
  1698. hRetRes = WBEM_E_NOT_FOUND;
  1699. MY_OUTPUT(L"GUID not found", 4);
  1700. }
  1701. else
  1702. {
  1703. MY_OUTPUT(L"Found", 4);
  1704. }
  1705. MY_OUTPUT(L"EXIT ***** CSystem::ModThreshold...", 4);
  1706. return hRetRes;
  1707. }
  1708. HRESULT CSystem::ModAction(IWbemClassObject* pObj)
  1709. {
  1710. HRESULT hRes;
  1711. HRESULT hRetRes = WBEM_E_NOT_FOUND;
  1712. int i, iSize;
  1713. VARIANT v;
  1714. CAction* pAction;
  1715. MY_OUTPUT(L"ENTER ***** CSystem::ModAction...", 4);
  1716. VariantInit(&v);
  1717. hRes = pObj->Get(L"GUID", 0L, &v, 0L, 0L);
  1718. if (FAILED(hRes))
  1719. {
  1720. MY_HRESASSERT(hRes);
  1721. MY_OUTPUT(L"ENTER ***** CSystem::ModAction-Unexpected Error!...", 4);
  1722. VariantClear(&v);
  1723. return hRes;
  1724. }
  1725. MY_OUTPUT2(L"Action mod for GUID=%s", V_BSTR(&v), 4);
  1726. //
  1727. // Search right under the System to find the Action.
  1728. // If don't find, drill down until we do.
  1729. //
  1730. iSize = m_actionList.size();
  1731. for (i = 0; i < iSize ; i++)
  1732. {
  1733. MY_ASSERT(i<m_actionList.size());
  1734. pAction = m_actionList[i];
  1735. hRetRes = pAction->FindAndModAction(V_BSTR(&v), pObj);
  1736. if (hRetRes==S_OK)
  1737. {
  1738. break;
  1739. }
  1740. else if (hRetRes!=WBEM_S_DIFFERENT)
  1741. {
  1742. break;
  1743. }
  1744. }
  1745. VariantClear(&v);
  1746. if (hRetRes==WBEM_S_DIFFERENT)
  1747. {
  1748. hRetRes = WBEM_E_NOT_FOUND;
  1749. MY_OUTPUT(L"GUID not found", 4);
  1750. }
  1751. else
  1752. {
  1753. MY_OUTPUT(L"Found", 4);
  1754. }
  1755. MY_OUTPUT(L"EXIT ***** CSystem::ModAction...", 4);
  1756. return hRetRes;
  1757. }
  1758. BOOL CSystem::CreateActionAssociation(IWbemClassObject* pObj)
  1759. {
  1760. TCHAR szGUID[1024];
  1761. LPTSTR pStr;
  1762. LPTSTR pStr2;
  1763. HRESULT hRes;
  1764. BOOL bRetValue = TRUE;
  1765. int i, iSize;
  1766. VARIANT v;
  1767. CAction* pAction;
  1768. MY_OUTPUT(L"ENTER ***** CSystem::CreateActionAssociation...", 4);
  1769. VariantInit(&v);
  1770. hRes = pObj->Get(L"ChildPath", 0L, &v, 0L, 0L);
  1771. if (FAILED(hRes))
  1772. {
  1773. MY_HRESASSERT(hRes);
  1774. MY_OUTPUT(L"ENTER ***** CSystem::CreateActionAssociation-Unexpected Error!...", 4);
  1775. VariantClear(&v);
  1776. return FALSE;
  1777. }
  1778. // Get the Action GUID from the path
  1779. wcscpy(szGUID, V_BSTR(&v));
  1780. pStr = wcschr(szGUID, '\"');
  1781. if (pStr)
  1782. {
  1783. pStr++;
  1784. pStr2 = wcschr(pStr, '\"');
  1785. if (pStr2)
  1786. {
  1787. *pStr2 = '\0';
  1788. //
  1789. // Find the Action and add the new association
  1790. //
  1791. iSize = m_actionList.size();
  1792. for (i = 0; i < iSize ; i++)
  1793. {
  1794. MY_ASSERT(i<m_actionList.size());
  1795. pAction = m_actionList[i];
  1796. bRetValue = pAction->FindAndCreateActionAssociation(pStr, pObj);
  1797. if (bRetValue)
  1798. {
  1799. break;
  1800. }
  1801. }
  1802. }
  1803. }
  1804. VariantClear(&v);
  1805. MY_OUTPUT(L"EXIT ***** CSystem::CreateActionAssociation...", 4);
  1806. return bRetValue;
  1807. }
  1808. BOOL CSystem::ModActionAssociation(IWbemClassObject* pObj)
  1809. {
  1810. TCHAR szGUID[1024];
  1811. LPTSTR pStr;
  1812. LPTSTR pStr2;
  1813. HRESULT hRes;
  1814. BOOL bRetValue = TRUE;
  1815. int i, iSize;
  1816. VARIANT v;
  1817. CAction* pAction;
  1818. MY_OUTPUT(L"ENTER ***** CSystem::ModActionAssociation...", 4);
  1819. VariantInit(&v);
  1820. hRes = pObj->Get(L"ChildPath", 0L, &v, 0L, 0L);
  1821. if (FAILED(hRes))
  1822. {
  1823. MY_HRESASSERT(hRes);
  1824. MY_OUTPUT(L"ENTER ***** CSystem::ModActionAssociation-Unexpected Error!...", 4);
  1825. VariantClear(&v);
  1826. return FALSE;
  1827. }
  1828. // Get the Action GUID from the path
  1829. wcscpy(szGUID, V_BSTR(&v));
  1830. pStr = wcschr(szGUID, '\"');
  1831. if (pStr)
  1832. {
  1833. pStr++;
  1834. pStr2 = wcschr(pStr, '\"');
  1835. if (pStr2)
  1836. {
  1837. *pStr2 = '\0';
  1838. //
  1839. // Find the Action and modify the association
  1840. //
  1841. iSize = m_actionList.size();
  1842. for (i = 0; i < iSize ; i++)
  1843. {
  1844. MY_ASSERT(i<m_actionList.size());
  1845. pAction = m_actionList[i];
  1846. bRetValue = pAction->FindAndModActionAssociation(pStr, pObj);
  1847. if (bRetValue)
  1848. {
  1849. break;
  1850. }
  1851. }
  1852. }
  1853. }
  1854. VariantClear(&v);
  1855. MY_OUTPUT(L"EXIT ***** CSystem::ModActionAssociation...", 4);
  1856. return bRetValue;
  1857. }
  1858. HRESULT CSystem::CreateSystemDataGroupAssociation(IWbemClassObject* pObj)
  1859. {
  1860. int i, iSize;
  1861. TCHAR szTemp[1024];
  1862. VARIANT v;
  1863. BOOL bFound;
  1864. HRESULT hRetRes = S_OK;
  1865. CDataGroup* pDG = NULL;
  1866. CDataGroup* pDataGroup = NULL;
  1867. BOOL bRetValue = TRUE;
  1868. TCHAR szGUID[1024];
  1869. LPTSTR pStr = NULL;
  1870. LPTSTR pStr2 = NULL;
  1871. BSTR Path = NULL;
  1872. IWbemClassObject* pObj2 = NULL;
  1873. LPTSTR pszTempGUID = NULL;
  1874. MY_OUTPUT(L"ENTER ***** CSystem::CreateSystemDataGroupAssociation...", 4);
  1875. //
  1876. // Get the name of the child DataGroup
  1877. //
  1878. VariantInit(&v);
  1879. hRetRes = pObj->Get(L"ChildPath", 0L, &v, 0L, 0L);
  1880. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  1881. wcscpy(szGUID, V_BSTR(&v));
  1882. pStr = wcschr(szGUID, '\"');
  1883. if (pStr)
  1884. {
  1885. pStr++;
  1886. pStr2 = wcschr(pStr, '\"');
  1887. if (pStr2)
  1888. {
  1889. *pStr2 = '\0';
  1890. //
  1891. // First make sure it is not in there already!
  1892. //
  1893. bFound = FALSE;
  1894. iSize = m_dataGroupList.size();
  1895. for (i = 0; i < iSize ; i++)
  1896. {
  1897. MY_ASSERT(i<m_dataGroupList.size());
  1898. pDataGroup = m_dataGroupList[i];
  1899. if (!_wcsicmp(pStr, pDataGroup->GetGUID()))
  1900. {
  1901. bFound = TRUE;
  1902. break;
  1903. }
  1904. }
  1905. MY_OUTPUT2(L"Association DG to System DGGUID=%s", pStr, 4);
  1906. if (bFound == FALSE)
  1907. {
  1908. MY_OUTPUT(L"OK: Not found yet", 4);
  1909. //
  1910. // Add in the DataGroup. Everything below will follow.
  1911. //
  1912. wcscpy(szTemp, L"MicrosoftHM_DataGroupConfiguration.GUID=\"");
  1913. lstrcat(szTemp, pStr);
  1914. lstrcat(szTemp, L"\"");
  1915. Path = SysAllocString(szTemp);
  1916. MY_ASSERT(Path); if (!Path) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1917. hRetRes = GetWbemObjectInst(&g_pIWbemServices, Path, NULL, &pObj2);
  1918. //XXXGet back an HRESULT and then return that
  1919. MY_ASSERT(pObj2); if (!pObj2) {hRetRes = S_FALSE; goto error;}
  1920. // See if this is already read in. Need to prevent endless loop, circular references.
  1921. hRetRes = GetStrProperty(pObj2, L"GUID", &pszTempGUID);
  1922. MY_ASSERT(hRetRes==S_OK); if (hRetRes!= S_OK) goto error;
  1923. if (!g_pStartupSystem->FindPointerFromGUIDInMasterList(pszTempGUID))
  1924. {
  1925. //
  1926. // Create the internal class to represent the DataGroup
  1927. //
  1928. pDG = new CDataGroup;
  1929. MY_ASSERT(pDG); if (!pDG) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  1930. hRetRes = pDG->LoadInstanceFromMOF(pObj2, NULL, m_szGUID);
  1931. if (hRetRes==S_OK)
  1932. {
  1933. m_dataGroupList.push_back(pDG);
  1934. pDG->SetParentEnabledFlag(m_bEnabled);
  1935. }
  1936. else
  1937. {
  1938. MY_HRESASSERT(hRetRes);
  1939. pDG->DeleteDGInternal();
  1940. delete pDG;
  1941. pDG = NULL;
  1942. }
  1943. }
  1944. delete [] pszTempGUID;
  1945. pszTempGUID = NULL;
  1946. pObj2->Release();
  1947. pObj2 = NULL;
  1948. SysFreeString(Path);
  1949. Path = NULL;
  1950. }
  1951. else
  1952. {
  1953. MY_OUTPUT(L"WHY?: Already there!", 4);
  1954. }
  1955. }
  1956. }
  1957. VariantClear(&v);
  1958. MY_OUTPUT(L"EXIT ***** CSystem::CreateSystemDataGroupAssociation...", 4);
  1959. return hRetRes;
  1960. error:
  1961. MY_HRESASSERT(hRetRes);
  1962. VariantClear(&v);
  1963. if (Path)
  1964. SysFreeString(Path);
  1965. if (pObj2)
  1966. pObj2->Release();
  1967. if (pDG)
  1968. delete pDG;
  1969. if (pszTempGUID)
  1970. delete [] pszTempGUID;
  1971. return hRetRes;
  1972. }
  1973. HRESULT CSystem::CreateDataGroupDataGroupAssociation(IWbemClassObject* pObj)
  1974. {
  1975. VARIANT vParent;
  1976. VARIANT vChild;
  1977. TCHAR szChildGUID[1024];
  1978. DGLIST::iterator iaDG;
  1979. int i, iSize;
  1980. HRESULT hRetRes = S_OK;
  1981. CDataGroup* pDataGroup = NULL;
  1982. TCHAR szParentGUID[1024];
  1983. LPTSTR pParentStr = NULL;
  1984. LPTSTR pParentStr2 = NULL;
  1985. LPTSTR pChildStr = NULL;
  1986. LPTSTR pChildStr2 = NULL;
  1987. VariantInit(&vParent);
  1988. VariantInit(&vChild);
  1989. MY_OUTPUT(L"ENTER ***** CSystem::CreateDataGroupDataGroupAssociation...", 4);
  1990. //
  1991. // Get the name of the parent DataGroup
  1992. //
  1993. hRetRes = pObj->Get(L"ParentPath", 0L, &vParent, 0L, 0L);
  1994. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  1995. //
  1996. // Get the name of the child DataGroup
  1997. //
  1998. hRetRes = pObj->Get(L"ChildPath", 0L, &vChild, 0L, 0L);
  1999. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  2000. wcscpy(szChildGUID, V_BSTR(&vChild));
  2001. pChildStr = wcschr(szChildGUID, '\"');
  2002. if (pChildStr)
  2003. {
  2004. pChildStr++;
  2005. pChildStr2 = wcschr(pChildStr, '\"');
  2006. if (pChildStr2)
  2007. {
  2008. *pChildStr2 = '\0';
  2009. wcscpy(szParentGUID, V_BSTR(&vParent));
  2010. pParentStr = wcschr(szParentGUID, '\"');
  2011. if (pParentStr)
  2012. {
  2013. pParentStr++;
  2014. pParentStr2 = wcschr(pParentStr, '\"');
  2015. if (pParentStr2)
  2016. {
  2017. *pParentStr2 = '\0';
  2018. //
  2019. // Add the DataGroup, it will add everything under itself
  2020. //
  2021. MY_OUTPUT2(L"Association DG to DG ParentGUID=%s", pParentStr, 4);
  2022. MY_OUTPUT2(L"ChildGUID=%s", pChildStr, 4);
  2023. iSize = m_dataGroupList.size();
  2024. iaDG=m_dataGroupList.begin();
  2025. for (i = 0; i < iSize ; i++, iaDG++)
  2026. {
  2027. MY_ASSERT(i<m_dataGroupList.size());
  2028. pDataGroup = m_dataGroupList[i];
  2029. hRetRes = pDataGroup->AddDataGroup(pParentStr, pChildStr);
  2030. if (hRetRes==S_OK)
  2031. {
  2032. break;
  2033. }
  2034. else if (hRetRes!=WBEM_S_DIFFERENT)
  2035. {
  2036. // MY_HRESASSERT(hRetRes);
  2037. break;
  2038. }
  2039. }
  2040. }
  2041. }
  2042. }
  2043. }
  2044. VariantClear(&vParent);
  2045. VariantClear(&vChild);
  2046. MY_OUTPUT(L"EXIT ***** CSystem::CreateDataGroupDataGroupAssociation...", 4);
  2047. return hRetRes;
  2048. error:
  2049. MY_HRESASSERT(hRetRes);
  2050. VariantClear(&vParent);
  2051. VariantClear(&vChild);
  2052. return hRetRes;
  2053. }
  2054. HRESULT CSystem::CreateDataGroupDataCollectorAssociation(IWbemClassObject* pObj)
  2055. {
  2056. VARIANT vParent;
  2057. VARIANT vChild;
  2058. int i, iSize;
  2059. TCHAR szParentGUID[1024];
  2060. DGLIST::iterator iaDG;
  2061. HRESULT hRetRes = S_OK;
  2062. CDataGroup* pDataGroup = NULL;
  2063. LPTSTR pParentStr = NULL;
  2064. LPTSTR pParentStr2 = NULL;
  2065. TCHAR szChildGUID[1024];
  2066. LPTSTR pChildStr = NULL;
  2067. LPTSTR pChildStr2 = NULL;
  2068. VariantInit(&vParent);
  2069. VariantInit(&vChild);
  2070. MY_OUTPUT(L"ENTER ***** CSystem::CreateDataGroupDataCollectorAssociation...", 4);
  2071. //
  2072. // Get the name of the parent DataGroup
  2073. //
  2074. hRetRes = pObj->Get(L"ParentPath", 0L, &vParent, 0L, 0L);
  2075. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  2076. //
  2077. // Get the name of the child DataGroup
  2078. //
  2079. hRetRes = pObj->Get(L"ChildPath", 0L, &vChild, 0L, 0L);
  2080. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  2081. wcscpy(szChildGUID, V_BSTR(&vChild));
  2082. pChildStr = wcschr(szChildGUID, '\"');
  2083. if (pChildStr)
  2084. {
  2085. pChildStr++;
  2086. pChildStr2 = wcschr(pChildStr, '\"');
  2087. if (pChildStr2)
  2088. {
  2089. *pChildStr2 = '\0';
  2090. wcscpy(szParentGUID, V_BSTR(&vParent));
  2091. pParentStr = wcschr(szParentGUID, '\"');
  2092. if (pParentStr)
  2093. {
  2094. pParentStr++;
  2095. pParentStr2 = wcschr(pParentStr, '\"');
  2096. if (pParentStr2)
  2097. {
  2098. *pParentStr2 = '\0';
  2099. //
  2100. // Add the DataGroup, it will add everything under itself
  2101. //
  2102. MY_OUTPUT2(L"Association DC to DG ParentDGGUID=%s", pParentStr, 4);
  2103. MY_OUTPUT2(L"ChildDCGUID=%s", pChildStr, 4);
  2104. iSize = m_dataGroupList.size();
  2105. iaDG=m_dataGroupList.begin();
  2106. for (i = 0; i < iSize ; i++, iaDG++)
  2107. {
  2108. MY_ASSERT(i<m_dataGroupList.size());
  2109. pDataGroup = m_dataGroupList[i];
  2110. hRetRes = pDataGroup->AddDataCollector(pParentStr, pChildStr);
  2111. if (hRetRes==S_OK)
  2112. {
  2113. break;
  2114. }
  2115. else if (hRetRes!=WBEM_S_DIFFERENT)
  2116. {
  2117. // MY_HRESASSERT(hRetRes);
  2118. break;
  2119. }
  2120. }
  2121. }
  2122. }
  2123. }
  2124. }
  2125. VariantClear(&vParent);
  2126. VariantClear(&vChild);
  2127. MY_OUTPUT(L"EXIT ***** CSystem::CreateDataGroupDataCollectorAssociation...", 4);
  2128. return hRetRes;
  2129. error:
  2130. MY_HRESASSERT(hRetRes);
  2131. VariantClear(&vParent);
  2132. VariantClear(&vChild);
  2133. return hRetRes;
  2134. }
  2135. HRESULT CSystem::CreateDataCollectorThresholdAssociation(IWbemClassObject* pObj)
  2136. {
  2137. VARIANT vParent;
  2138. VARIANT vChild;
  2139. int i, iSize;
  2140. TCHAR szChildGUID[1024];
  2141. DGLIST::iterator iaDG;
  2142. HRESULT hRetRes = S_OK;
  2143. CDataGroup* pDataGroup = NULL;
  2144. TCHAR szParentGUID[1024];
  2145. LPTSTR pParentStr = NULL;
  2146. LPTSTR pParentStr2 = NULL;
  2147. LPTSTR pChildStr = NULL;
  2148. LPTSTR pChildStr2 = NULL;
  2149. VariantInit(&vParent);
  2150. VariantInit(&vChild);
  2151. MY_OUTPUT(L"ENTER ***** CSystem::CreateDataCollectorThresholdAssociation...", 4);
  2152. //
  2153. // Get the name of the parent DataGroup
  2154. //
  2155. hRetRes = pObj->Get(L"ParentPath", 0L, &vParent, 0L, 0L);
  2156. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  2157. //
  2158. // Get the name of the child DataGroup
  2159. //
  2160. hRetRes = pObj->Get(L"ChildPath", 0L, &vChild, 0L, 0L);
  2161. MY_HRESASSERT(hRetRes); if (hRetRes != S_OK) goto error;
  2162. wcscpy(szChildGUID, V_BSTR(&vChild));
  2163. pChildStr = wcschr(szChildGUID, '\"');
  2164. if (pChildStr)
  2165. {
  2166. pChildStr++;
  2167. pChildStr2 = wcschr(pChildStr, '\"');
  2168. if (pChildStr2)
  2169. {
  2170. *pChildStr2 = '\0';
  2171. wcscpy(szParentGUID, V_BSTR(&vParent));
  2172. pParentStr = wcschr(szParentGUID, '\"');
  2173. if (pParentStr)
  2174. {
  2175. pParentStr++;
  2176. pParentStr2 = wcschr(pParentStr, '\"');
  2177. if (pParentStr2)
  2178. {
  2179. *pParentStr2 = '\0';
  2180. //
  2181. // Add the DataGroup, it will add everything under itself
  2182. //
  2183. MY_OUTPUT2(L"Association Threshold to DC ParentDCGUID=%s", pParentStr, 4);
  2184. MY_OUTPUT2(L"ChildThreshGUID=%s", pChildStr, 4);
  2185. iSize = m_dataGroupList.size();
  2186. iaDG=m_dataGroupList.begin();
  2187. for (i = 0; i < iSize ; i++, iaDG++)
  2188. {
  2189. MY_ASSERT(i<m_dataGroupList.size());
  2190. pDataGroup = m_dataGroupList[i];
  2191. hRetRes = pDataGroup->AddThreshold(pParentStr, pChildStr);
  2192. if (hRetRes==S_OK)
  2193. {
  2194. break;
  2195. }
  2196. else if (hRetRes!=WBEM_S_DIFFERENT)
  2197. {
  2198. // MY_HRESASSERT(hRetRes);
  2199. break;
  2200. }
  2201. }
  2202. }
  2203. }
  2204. }
  2205. }
  2206. VariantClear(&vParent);
  2207. VariantClear(&vChild);
  2208. MY_OUTPUT(L"EXIT ***** CSystem::CreateDataCollectorThresholdAssociation...", 4);
  2209. return hRetRes;
  2210. error:
  2211. MY_HRESASSERT(hRetRes);
  2212. VariantClear(&vParent);
  2213. VariantClear(&vChild);
  2214. return hRetRes;
  2215. }
  2216. BOOL CSystem::ResetResetThresholdStates(void)
  2217. {
  2218. BOOL bRetValue = TRUE;
  2219. int i;
  2220. int iSize;
  2221. CDataGroup *pDataGroup;
  2222. iSize = m_dataGroupList.size();
  2223. for (i = 0; i < iSize ; i++)
  2224. {
  2225. MY_ASSERT(i<m_dataGroupList.size());
  2226. pDataGroup = m_dataGroupList[i];
  2227. pDataGroup->ResetResetThresholdStates();
  2228. }
  2229. return bRetValue;
  2230. }
  2231. BOOL CSystem::GetChange(void)
  2232. {
  2233. if (m_lNumberChanges!=0 && m_lPrevState!=m_lCurrState)
  2234. {
  2235. return TRUE;
  2236. }
  2237. else
  2238. {
  2239. return FALSE;
  2240. }
  2241. }
  2242. //
  2243. // Called By the Delete method that the HMSystemConfiguration class exposes.
  2244. // Code ends up in the methprov.pp file, then gets passed here.
  2245. // We could have done method providers on the instance basis, and then we would have
  2246. // delete called for a specifric instance, but instead we chose to have a global
  2247. // static class wide function, that appies to all objects in our hierarchy,
  2248. // so you must pass in the GUID of what you want deleted, and then we search for it.
  2249. //
  2250. //
  2251. //XXXOptomize this and other similar code by creating an access array that contains
  2252. // OR hash table that contains all the GUIDs and pointers to the classes, so can go directly
  2253. // to the object and delete it. Actually probably need to go to its parent to delete it,
  2254. // as it needs to get it out of its list.
  2255. HRESULT CSystem::FindAndDeleteByGUID(LPTSTR pszGUID)
  2256. {
  2257. BOOL bDeleted = FALSE;
  2258. int i, iSize;
  2259. CDataGroup* pDataGroup;
  2260. DGLIST::iterator iaDG;
  2261. CAction* pAction;
  2262. ALIST::iterator iaA;
  2263. MY_OUTPUT(L"ENTER ***** CSystem::FindAndDeleteByGUID...", 4);
  2264. MY_OUTPUT2(L"FIND DELETION: GUID=%s", pszGUID, 4);
  2265. //
  2266. // Traverse the complete hierarchy to find the object to delete.
  2267. //
  2268. iSize = m_dataGroupList.size();
  2269. iaDG=m_dataGroupList.begin();
  2270. for (i=0; i<iSize; i++, iaDG++)
  2271. {
  2272. MY_ASSERT(i<m_dataGroupList.size());
  2273. pDataGroup = m_dataGroupList[i];
  2274. if (!_wcsicmp(pszGUID, pDataGroup->GetGUID()))
  2275. {
  2276. pDataGroup->DeleteDGConfig();
  2277. delete pDataGroup;
  2278. m_dataGroupList.erase(iaDG);
  2279. bDeleted = TRUE;
  2280. MY_OUTPUT2(L"DELETION: DGGUID=%s", pszGUID, 4);
  2281. break;
  2282. }
  2283. // Look at branch below to see if can find it
  2284. if (pDataGroup->FindAndDeleteByGUID(pszGUID)==S_OK)
  2285. {
  2286. bDeleted = TRUE;
  2287. break;
  2288. }
  2289. }
  2290. //
  2291. // Traverse through the actions also to see if that is what we were suppose to delete.
  2292. //
  2293. if (bDeleted == FALSE)
  2294. {
  2295. iSize = m_actionList.size();
  2296. iaA=m_actionList.begin();
  2297. for (i=0; i<iSize; i++, iaA++)
  2298. {
  2299. MY_ASSERT(i<m_actionList.size());
  2300. pAction = m_actionList[i];
  2301. if (!_wcsicmp(pszGUID, pAction->GetGUID()))
  2302. {
  2303. pAction->DeleteAConfig();
  2304. delete pAction;
  2305. m_actionList.erase(iaA);
  2306. bDeleted = TRUE;
  2307. MY_OUTPUT2(L"DELETION: AGUID=%s", pszGUID, 4);
  2308. break;
  2309. }
  2310. }
  2311. }
  2312. if (bDeleted == FALSE)
  2313. {
  2314. MY_OUTPUT(L"GUID not found", 4);
  2315. MY_OUTPUT(L"EXIT ***** CSystem::FindAndDeleteByGUID...", 4);
  2316. return WBEM_E_NOT_FOUND;
  2317. }
  2318. else
  2319. {
  2320. MY_OUTPUT(L"EXIT ***** CSystem::FindAndDeleteByGUID...", 4);
  2321. return S_OK;
  2322. }
  2323. }
  2324. //
  2325. // HMSystemConfiguration class exposes this method.
  2326. // Code ends up in the methprov.pp file, then gets passed here.
  2327. //
  2328. HRESULT CSystem::FindAndResetDEStateByGUID(LPTSTR pszGUID)
  2329. {
  2330. BOOL bFound = FALSE;
  2331. int i, iSize;
  2332. CDataGroup* pDataGroup;
  2333. MY_OUTPUT(L"ENTER ***** CSystem::FindAndResetDEStateByGUID...", 4);
  2334. MY_OUTPUT2(L"FIND RESET: GUID=%s", pszGUID, 4);
  2335. if (!wcscmp(L"{@}", pszGUID))
  2336. {
  2337. bFound = TRUE;
  2338. //
  2339. // Do reset of EVERYTHING
  2340. //
  2341. iSize = m_dataGroupList.size();
  2342. for (i=0; i<iSize; i++)
  2343. {
  2344. MY_ASSERT(i<m_dataGroupList.size());
  2345. pDataGroup = m_dataGroupList[i];
  2346. pDataGroup->ResetState();
  2347. }
  2348. }
  2349. else
  2350. {
  2351. //
  2352. // Traverse the complete hierarchy to find the object to reset state.
  2353. //
  2354. iSize = m_dataGroupList.size();
  2355. for (i=0; i<iSize; i++)
  2356. {
  2357. MY_ASSERT(i<m_dataGroupList.size());
  2358. pDataGroup = m_dataGroupList[i];
  2359. if (!_wcsicmp(pszGUID, pDataGroup->GetGUID()))
  2360. {
  2361. pDataGroup->ResetState();
  2362. bFound = TRUE;
  2363. MY_OUTPUT(L"DG Found and reset", 4);
  2364. break;
  2365. }
  2366. // Look at branch below to see if can find it
  2367. if (pDataGroup->FindAndResetDEStateByGUID(pszGUID)==S_OK)
  2368. {
  2369. bFound = TRUE;
  2370. break;
  2371. }
  2372. }
  2373. }
  2374. if (bFound == FALSE)
  2375. {
  2376. MY_OUTPUT(L"GUID not found", 4);
  2377. MY_OUTPUT(L"EXIT ***** CSystem::FindAndResetDEStateByGUID...", 4);
  2378. return WBEM_E_NOT_FOUND;
  2379. }
  2380. else
  2381. {
  2382. MY_OUTPUT(L"EXIT ***** CSystem::FindAndResetDEStateByGUID...", 4);
  2383. return S_OK;
  2384. }
  2385. }
  2386. //
  2387. // HMSystemConfiguration class exposes this method.
  2388. // Code ends up in the methprov.pp file, then gets passed here.
  2389. //
  2390. HRESULT CSystem::FindAndResetDEStatisticsByGUID(LPTSTR pszGUID)
  2391. {
  2392. BOOL bFound = FALSE;
  2393. int i, iSize;
  2394. CDataGroup* pDataGroup;
  2395. MY_OUTPUT(L"ENTER ***** CSystem::FindAndResetDEStatisticsByGUID...", 4);
  2396. MY_OUTPUT2(L"FIND RESET STATISTICS: GUID=%s", pszGUID, 4);
  2397. if (!wcscmp(L"{@}", pszGUID))
  2398. {
  2399. bFound = TRUE;
  2400. //
  2401. // Do reset of EVERYTHING
  2402. //
  2403. iSize = m_dataGroupList.size();
  2404. for (i=0; i<iSize; i++)
  2405. {
  2406. MY_ASSERT(i<m_dataGroupList.size());
  2407. pDataGroup = m_dataGroupList[i];
  2408. pDataGroup->ResetStatistics();
  2409. }
  2410. }
  2411. else
  2412. {
  2413. //
  2414. // Traverse the complete hierarchy to find the object to reset statistics.
  2415. //
  2416. iSize = m_dataGroupList.size();
  2417. for (i=0; i<iSize; i++)
  2418. {
  2419. MY_ASSERT(i<m_dataGroupList.size());
  2420. pDataGroup = m_dataGroupList[i];
  2421. if (!_wcsicmp(pszGUID, pDataGroup->GetGUID()))
  2422. {
  2423. pDataGroup->ResetStatistics();
  2424. bFound = TRUE;
  2425. MY_OUTPUT(L"DG found and reset statistics", 4);
  2426. break;
  2427. }
  2428. // Look at branch below to see if can find it
  2429. if (pDataGroup->FindAndResetDEStatisticsByGUID(pszGUID)==S_OK)
  2430. {
  2431. bFound = TRUE;
  2432. break;
  2433. }
  2434. }
  2435. }
  2436. if (bFound == FALSE)
  2437. {
  2438. MY_OUTPUT(L"GUID not found", 4);
  2439. MY_OUTPUT(L"EXIT ***** CSystem::FindAndResetDEStatisticsByGUID...", 4);
  2440. return WBEM_E_NOT_FOUND;
  2441. }
  2442. else
  2443. {
  2444. MY_OUTPUT(L"EXIT ***** CSystem::FindAndResetDEStatisticsByGUID...", 4);
  2445. return S_OK;
  2446. }
  2447. }
  2448. //
  2449. // HMSystemConfiguration class exposes this method.
  2450. // Code ends up in the methprov.pp file, then gets passed here.
  2451. //
  2452. HRESULT CSystem::FindAndEvaluateNowDEByGUID(LPTSTR pszGUID)
  2453. {
  2454. BOOL bFound = FALSE;
  2455. int i, iSize;
  2456. CDataGroup* pDataGroup;
  2457. MY_OUTPUT(L"ENTER ***** CSystem::FindAndEvaluateNowByGUID...", 4);
  2458. MY_OUTPUT2(L"FIND RESET STATISTICS: GUID=%s", pszGUID, 4);
  2459. if (!wcscmp(L"{@}", pszGUID))
  2460. {
  2461. bFound = TRUE;
  2462. //
  2463. // Do reset of EVERYTHING
  2464. //
  2465. iSize = m_dataGroupList.size();
  2466. for (i=0; i<iSize; i++)
  2467. {
  2468. MY_ASSERT(i<m_dataGroupList.size());
  2469. pDataGroup = m_dataGroupList[i];
  2470. pDataGroup->EvaluateNow();
  2471. }
  2472. }
  2473. else
  2474. {
  2475. //
  2476. // Traverse the complete hierarchy to find the object to evaluate now.
  2477. //
  2478. iSize = m_dataGroupList.size();
  2479. for (i=0; i<iSize; i++)
  2480. {
  2481. MY_ASSERT(i<m_dataGroupList.size());
  2482. pDataGroup = m_dataGroupList[i];
  2483. if (!_wcsicmp(pszGUID, pDataGroup->GetGUID()))
  2484. {
  2485. pDataGroup->EvaluateNow();
  2486. bFound = TRUE;
  2487. MY_OUTPUT(L"DG found and Evaluate Now", 4);
  2488. break;
  2489. }
  2490. // Look at branch below to see if can find it
  2491. if (pDataGroup->FindAndEvaluateNowDEByGUID(pszGUID)==S_OK)
  2492. {
  2493. bFound = TRUE;
  2494. break;
  2495. }
  2496. }
  2497. }
  2498. if (bFound == FALSE)
  2499. {
  2500. MY_OUTPUT(L"GUID not found", 4);
  2501. MY_OUTPUT(L"EXIT ***** CSystem::FindAndEvaluateNowByGUID...", 4);
  2502. return S_FALSE;
  2503. }
  2504. else
  2505. {
  2506. MY_OUTPUT(L"EXIT ***** CSystem::FindAndEvaluateNowByGUID...", 4);
  2507. return S_OK;
  2508. }
  2509. }
  2510. //
  2511. // HMSystemConfiguration class exposes this method.
  2512. // Code ends up in the methprov.pp file, then gets passed here.
  2513. //
  2514. BOOL CSystem::Enable(BOOL bEnable)
  2515. {
  2516. HRESULT hRes;
  2517. // BSTR PathToClass;
  2518. int i, iSize;
  2519. CDataGroup* pDataGroup;
  2520. IWbemClassObject* pInst = NULL;
  2521. IWbemCallResult *pResult = 0;
  2522. MY_OUTPUT(L"ENTER ***** CSystem::Enable...", 4);
  2523. if (m_bEnabled == bEnable)
  2524. return TRUE;
  2525. //
  2526. // Set the variable, and do the same for all children.
  2527. //
  2528. m_bEnabled = bEnable;
  2529. //
  2530. // Traverse the complete hierarchy to find the object to enable/disable.
  2531. //
  2532. iSize = m_dataGroupList.size();
  2533. for (i=0; i<iSize; i++)
  2534. {
  2535. MY_ASSERT(i<m_dataGroupList.size());
  2536. pDataGroup = m_dataGroupList[i];
  2537. //XXX pDataGroup->SetParentEnabledFlag(bEnable);
  2538. }
  2539. //
  2540. // Set the property on this Configuration instance.
  2541. //
  2542. hRes = GetWbemObjectInst(&g_pIWbemServices, L"MicrosoftHM_SystemConfiguration.GUID=\"{@}\"", NULL, &pInst);
  2543. if (!pInst)
  2544. {
  2545. MY_HRESASSERT(hRes);
  2546. return FALSE;
  2547. }
  2548. hRes = PutBoolProperty(pInst, L"Enabled", m_bEnabled);
  2549. hRes = g_pIWbemServices->PutInstance(pInst, 0, NULL, &pResult);
  2550. pInst->Release();
  2551. pInst = NULL;
  2552. MY_OUTPUT(L"EXIT ***** CSystem::Enable...", 4);
  2553. return TRUE;
  2554. }
  2555. //
  2556. // At startup, internalize all instances of Actions
  2557. //
  2558. HRESULT CSystem::InternalizeActions(void)
  2559. {
  2560. ULONG uReturned;
  2561. BOOL bFound = FALSE;
  2562. int i, iSize;
  2563. CAction* pAction;
  2564. HRESULT hRetRes = S_OK;
  2565. BSTR Language = NULL;
  2566. BSTR Query = NULL;
  2567. IWbemClassObject *pObj = NULL;
  2568. LPTSTR pszTempGUID = NULL;
  2569. IEnumWbemClassObject *pEnum = 0;
  2570. MY_OUTPUT(L"ENTER ***** CSystem::InternalizeActions...", 4);
  2571. Language = SysAllocString(L"WQL");
  2572. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2573. Query = SysAllocString(L"select * from MicrosoftHM_ActionConfiguration");
  2574. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2575. // Issue query
  2576. hRetRes = g_pIWbemServices->ExecQuery(Language, Query, WBEM_FLAG_FORWARD_ONLY, 0, &pEnum);
  2577. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2578. SysFreeString(Query);
  2579. Query = NULL;
  2580. SysFreeString(Language);
  2581. Language = NULL;
  2582. // Retrieve objects in result set
  2583. while (TRUE)
  2584. {
  2585. pObj = NULL;
  2586. uReturned = 0;
  2587. hRetRes = pEnum->Next(0, 1, &pObj, &uReturned);
  2588. MY_ASSERT(hRetRes==S_OK || hRetRes==WBEM_S_FALSE);
  2589. if (hRetRes!=S_OK && hRetRes!=WBEM_S_FALSE)
  2590. {
  2591. MY_HRESASSERT(hRetRes);
  2592. pEnum->Release();
  2593. pEnum = NULL;
  2594. return hRetRes;
  2595. }
  2596. if (uReturned == 0)
  2597. {
  2598. break;
  2599. }
  2600. // See if this is already read in. Need to prevent duplicates.
  2601. hRetRes = GetStrProperty(pObj, L"GUID", &pszTempGUID);
  2602. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2603. bFound = FALSE;
  2604. iSize = m_actionList.size();
  2605. for (i=0; i < iSize; i++)
  2606. {
  2607. MY_ASSERT(i<m_actionList.size());
  2608. pAction = m_actionList[i];
  2609. if (!_wcsicmp(pszTempGUID, pAction->m_szGUID))
  2610. {
  2611. bFound = TRUE;
  2612. break;
  2613. }
  2614. }
  2615. if (bFound == FALSE)
  2616. {
  2617. // Create the internal class to represent the Action
  2618. CAction* pA = new CAction;
  2619. MY_ASSERT(pA); if (!pA) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2620. hRetRes = pA->LoadInstanceFromMOF(pObj);
  2621. if (hRetRes==S_OK)
  2622. {
  2623. m_actionList.push_back(pA);
  2624. }
  2625. else
  2626. {
  2627. MY_HRESASSERT(hRetRes);
  2628. delete pA;
  2629. }
  2630. }
  2631. delete [] pszTempGUID;
  2632. pszTempGUID = NULL;
  2633. // Release it.
  2634. pObj->Release();
  2635. pObj = NULL;
  2636. }
  2637. // All done
  2638. pEnum->Release();
  2639. pEnum = NULL;
  2640. MY_OUTPUT(L"EXIT ***** CSystem::InternalizeActions...", 4);
  2641. return S_OK;
  2642. error:
  2643. MY_ASSERT(FALSE);
  2644. if (Query)
  2645. SysFreeString(Query);
  2646. if (Language)
  2647. SysFreeString(Language);
  2648. if (pszTempGUID)
  2649. delete [] pszTempGUID;
  2650. if (pObj)
  2651. pObj->Release();
  2652. if (pEnum)
  2653. pEnum->Release();
  2654. m_bValidLoad = FALSE;
  2655. return hRetRes;
  2656. }
  2657. HRESULT CSystem::InitActionErrorListener(void)
  2658. {
  2659. BSTR Language = NULL;
  2660. BSTR Query = NULL;
  2661. HRESULT hRetRes;
  2662. Language = SysAllocString(L"WQL");
  2663. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2664. Query = SysAllocString(L"select * from __ConsumerFailureEvent where Event isa \"MicrosoftHM_ActionTriggerEvent\"");
  2665. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2666. hRetRes = S_FALSE;
  2667. if (g_pIWbemServices != NULL)
  2668. {
  2669. m_pTempSink = new CTempConsumer(HMTEMPEVENT_ACTIONERROR);
  2670. MY_ASSERT(m_pTempSink); if (!m_pTempSink) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2671. hRetRes = g_pIWbemServices->ExecNotificationQueryAsync(
  2672. Language,
  2673. Query,
  2674. 0,
  2675. NULL,
  2676. m_pTempSink);
  2677. }
  2678. SysFreeString(Language);
  2679. Language = NULL;
  2680. SysFreeString(Query);
  2681. Query = NULL;
  2682. MY_HRESASSERT(hRetRes);
  2683. if (hRetRes != WBEM_S_NO_ERROR)
  2684. {
  2685. if (m_pTempSink)
  2686. {
  2687. m_pTempSink->Release();
  2688. m_pTempSink = NULL;
  2689. }
  2690. }
  2691. return S_OK;
  2692. error:
  2693. MY_ASSERT(FALSE);
  2694. if (Query)
  2695. SysFreeString(Query);
  2696. if (Language)
  2697. SysFreeString(Language);
  2698. m_bValidLoad = FALSE;
  2699. return hRetRes;
  2700. }
  2701. HRESULT CSystem::InitActionSIDListener(CTempConsumer* pTempSink, LPTSTR pszQuery)
  2702. {
  2703. BSTR Language = NULL;
  2704. BSTR Query = NULL;
  2705. HRESULT hRetRes;
  2706. Language = SysAllocString(L"WQL");
  2707. MY_ASSERT(Language); if (!Language) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2708. Query = SysAllocString(pszQuery);
  2709. MY_ASSERT(Query); if (!Query) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2710. hRetRes = S_FALSE;
  2711. if (g_pIWbemServices != NULL)
  2712. {
  2713. pTempSink = new CTempConsumer(HMTEMPEVENT_ACTIONSID);
  2714. MY_ASSERT(pTempSink); if (!pTempSink) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2715. hRetRes = g_pIWbemServices->ExecNotificationQueryAsync(
  2716. Language,
  2717. Query,
  2718. 0,
  2719. NULL,
  2720. pTempSink);
  2721. }
  2722. SysFreeString(Language);
  2723. Language = NULL;
  2724. SysFreeString(Query);
  2725. Query = NULL;
  2726. MY_HRESASSERT(hRetRes);
  2727. if (hRetRes != WBEM_S_NO_ERROR)
  2728. {
  2729. if (pTempSink)
  2730. {
  2731. pTempSink->Release();
  2732. pTempSink = NULL;
  2733. }
  2734. }
  2735. return S_OK;
  2736. error:
  2737. MY_ASSERT(FALSE);
  2738. if (Query)
  2739. SysFreeString(Query);
  2740. if (Language)
  2741. SysFreeString(Language);
  2742. m_bValidLoad = FALSE;
  2743. return hRetRes;
  2744. }
  2745. HRESULT CSystem::HandleTempActionSIDEvent(IWbemClassObject* pObj)
  2746. {
  2747. VARIANT vDispatch;
  2748. VARIANT var;
  2749. HRESULT hRetRes = S_OK;
  2750. IWbemClassObject* pTargetInstance = NULL;
  2751. VariantInit(&vDispatch);
  2752. VariantInit(&var);
  2753. IWbemClassObject* pInst = NULL;
  2754. SAFEARRAY* psa = NULL;
  2755. CIMTYPE vtType;
  2756. long lBound, uBound;
  2757. BOOL bObjIsLocalSystem;
  2758. DWORD dwErr = 0;
  2759. VariantInit(&vDispatch);
  2760. VariantInit(&var);
  2761. TCHAR szName[200];
  2762. DWORD dwSize = 0;
  2763. DWORD dwResult = 0;
  2764. TCHAR szDomain[200];
  2765. SID_NAME_USE SidType;
  2766. LPVOID lpCreatorSID = NULL;
  2767. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempActionSIDEvent BLOCK - g_hConfigLock BLOCK WAIT", 4);
  2768. dwErr = WaitForSingleObject(g_hConfigLock, 120000);
  2769. if(dwErr != WAIT_OBJECT_0)
  2770. {
  2771. if(dwErr = WAIT_TIMEOUT)
  2772. {
  2773. TRACE_MUTEX(L"TIMEOUT MUTEX");
  2774. return WBEM_S_TIMEDOUT;
  2775. }
  2776. else
  2777. {
  2778. MY_OUTPUT(L"WaitForSingleObject on Mutex failed",4);
  2779. return WBEM_E_FAILED;
  2780. }
  2781. }
  2782. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempActionSIDEvent BLOCK - g_hConfigLock BLOCK GOT IT", 4);
  2783. if (!g_pSystem)
  2784. {
  2785. ReleaseMutex(g_hConfigLock);
  2786. return S_FALSE;
  2787. }
  2788. hRetRes = pObj->Get(L"TargetInstance", 0L, &vDispatch, 0, 0);
  2789. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2790. hRetRes = GetWbemClassObject(&pTargetInstance, &vDispatch);
  2791. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2792. // get the CreatorSID of this instance
  2793. hRetRes = pTargetInstance->Get(L"CreatorSID", 0, &var, &vtType, NULL);
  2794. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2795. if (vtType != (CIM_UINT8 | CIM_FLAG_ARRAY))
  2796. {
  2797. hRetRes = WBEM_E_FAILED;
  2798. goto error;
  2799. }
  2800. // make sure it's the right size
  2801. psa = var.parray;
  2802. if (::SafeArrayGetElemsize(psa) != 1)
  2803. {
  2804. hRetRes = WBEM_E_FAILED;
  2805. goto error;
  2806. }
  2807. hRetRes = ::SafeArrayGetLBound(psa, 1, &lBound);
  2808. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2809. hRetRes = ::SafeArrayGetUBound(psa, 1, &uBound);
  2810. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2811. if (lBound !=0)
  2812. {
  2813. hRetRes = WBEM_E_FAILED;
  2814. goto error;
  2815. }
  2816. // now see if this is LocalSystem by comparing to
  2817. // the hardcoded LocalSystem SID
  2818. bObjIsLocalSystem = false;
  2819. if (uBound == (sizeof LocalSystemSID)-1 )
  2820. {
  2821. lpCreatorSID = NULL;
  2822. hRetRes = ::SafeArrayAccessData(psa, &lpCreatorSID);
  2823. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2824. if (memcmp (lpCreatorSID, LocalSystemSID, sizeof LocalSystemSID) == 0)
  2825. bObjIsLocalSystem = true;
  2826. hRetRes = ::SafeArrayUnaccessData(psa);
  2827. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2828. }
  2829. if (bObjIsLocalSystem == FALSE)
  2830. {
  2831. // Also, skip it if it is a LocalAccount! (non-domain)
  2832. lpCreatorSID = NULL;
  2833. hRetRes = ::SafeArrayAccessData(psa, &lpCreatorSID);
  2834. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2835. dwSize = 200;
  2836. if( !LookupAccountSid(NULL, lpCreatorSID, szName, &dwSize, szDomain, &dwSize, &SidType))
  2837. {
  2838. // Didn't work for some reason, so assume we need to check.
  2839. m_numActionChanges++;
  2840. }
  2841. else
  2842. {
  2843. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 1;
  2844. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  2845. if (GetComputerName(szComputerName, &dwNameLen))
  2846. {
  2847. // If machine name matches, then it is a local account, so skip!!!
  2848. if (_wcsicmp(szComputerName, szDomain))
  2849. {
  2850. m_numActionChanges++;
  2851. }
  2852. }
  2853. else
  2854. {
  2855. // Didn't work for some reason, so assume we need to check.
  2856. m_numActionChanges++;
  2857. }
  2858. }
  2859. hRetRes = ::SafeArrayUnaccessData(psa);
  2860. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2861. }
  2862. pTargetInstance->Release();
  2863. pTargetInstance = NULL;
  2864. VariantClear(&vDispatch);
  2865. VariantClear(&var);
  2866. ReleaseMutex(g_hConfigLock);
  2867. return S_OK;
  2868. error:
  2869. MY_ASSERT(FALSE);
  2870. if (pTargetInstance)
  2871. pTargetInstance->Release();
  2872. if (pInst)
  2873. pInst->Release();
  2874. VariantClear(&vDispatch);
  2875. VariantClear(&var);
  2876. ReleaseMutex(g_hConfigLock);
  2877. return hRetRes;
  2878. }
  2879. // Pass on info to the DataCollector that has the GUID
  2880. HRESULT CSystem::HandleTempActionErrorEvent(IWbemClassObject* pObj)
  2881. {
  2882. HRESULT hRetRes = S_OK;
  2883. BOOL bFound = FALSE;
  2884. VARIANT vDispatch;
  2885. int i, iSize;
  2886. CAction* pAction;
  2887. IWbemClassObject* pTargetInstance = NULL;
  2888. LPTSTR pszGUID = NULL;
  2889. LPTSTR pszErrorDescription = NULL;
  2890. long lNum;
  2891. DWORD dwErr = 0;
  2892. VariantInit(&vDispatch);
  2893. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempActionErrorEvent BLOCK - g_hConfigLock BLOCK WAIT", 4);
  2894. dwErr = WaitForSingleObject(g_hConfigLock, 120000);
  2895. if(dwErr != WAIT_OBJECT_0)
  2896. {
  2897. if(dwErr = WAIT_TIMEOUT)
  2898. {
  2899. TRACE_MUTEX(L"TIMEOUT MUTEX");
  2900. return WBEM_S_TIMEDOUT;
  2901. }
  2902. else
  2903. {
  2904. MY_OUTPUT(L"WaitForSingleObject on Mutex failed",4);
  2905. return WBEM_E_FAILED;
  2906. }
  2907. }
  2908. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempActionErrorEvent BLOCK - g_hConfigLock BLOCK GOT IT", 4);
  2909. if (!g_pSystem)
  2910. {
  2911. ReleaseMutex(g_hConfigLock);
  2912. return S_FALSE;
  2913. }
  2914. try
  2915. {
  2916. // Get the GUID from the Event property, which will be an ActionStatusEvent class, then
  2917. // from that GUID property.
  2918. VariantInit(&vDispatch);
  2919. hRetRes = pObj->Get(L"Event", 0L, &vDispatch, 0, 0);
  2920. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2921. hRetRes = GetWbemClassObject(&pTargetInstance, &vDispatch);
  2922. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2923. hRetRes = GetStrProperty(pTargetInstance, L"GUID", &pszGUID);
  2924. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2925. hRetRes = GetUint32Property(pObj, L"ErrorCode", &lNum);
  2926. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2927. hRetRes = GetStrProperty(pObj, L"ErrorDescription", &pszErrorDescription);
  2928. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2929. pTargetInstance->Release();
  2930. VariantClear(&vDispatch);
  2931. iSize = m_actionList.size();
  2932. for (i=0; i < iSize; i++)
  2933. {
  2934. MY_ASSERT(i<m_actionList.size());
  2935. pAction = m_actionList[i];
  2936. if (pAction->HandleTempErrorEvent(pszGUID, lNum, pszErrorDescription))
  2937. {
  2938. bFound = TRUE;
  2939. break;
  2940. }
  2941. }
  2942. if (bFound == FALSE)
  2943. {
  2944. MY_OUTPUT2(L"NOTFOUND: No body to handle Action Error event for GUID=%s", pszGUID, 4);
  2945. }
  2946. delete [] pszGUID;
  2947. pszGUID = NULL;
  2948. delete [] pszErrorDescription;
  2949. pszErrorDescription = NULL;
  2950. }
  2951. catch (...)
  2952. {
  2953. MY_ASSERT(FALSE);
  2954. }
  2955. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent g_hConfigLock BLOCK - RELEASE IT", 4);
  2956. ReleaseMutex(g_hConfigLock);
  2957. MY_OUTPUT(L"BLOCK - BLOCK CSystem::HandleTempEvent g_hConfigLock BLOCK - RELEASED", 4);
  2958. return S_OK;
  2959. error:
  2960. MY_ASSERT(FALSE);
  2961. if (pszGUID)
  2962. delete [] pszGUID;
  2963. if (pszErrorDescription)
  2964. delete [] pszErrorDescription;
  2965. ReleaseMutex(g_hConfigLock);
  2966. return hRetRes;
  2967. }
  2968. //
  2969. // For ones that are created on the fly, after we are running.
  2970. //
  2971. HRESULT CSystem::CreateAction(IWbemClassObject* pObj)
  2972. {
  2973. HRESULT hRetRes = S_OK;
  2974. BOOL bFound = FALSE;
  2975. int i, iSize;
  2976. CAction* pAction;
  2977. LPTSTR pszTempGUID = NULL;
  2978. MY_OUTPUT(L"ENTER ***** CSystem::CreateAction...", 4);
  2979. // See if this is already read in. Need to prevent duplicates.
  2980. hRetRes = GetStrProperty(pObj, L"GUID", &pszTempGUID);
  2981. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  2982. bFound = FALSE;
  2983. iSize = m_actionList.size();
  2984. for (i=0; i < iSize; i++)
  2985. {
  2986. MY_ASSERT(i<m_actionList.size());
  2987. pAction = m_actionList[i];
  2988. if (!_wcsicmp(pszTempGUID, pAction->m_szGUID))
  2989. {
  2990. bFound = TRUE;
  2991. break;
  2992. }
  2993. }
  2994. if (bFound == FALSE)
  2995. {
  2996. // Create the internal class to represent the Action
  2997. CAction* pA = new CAction;
  2998. MY_ASSERT(pA); if (!pA) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  2999. hRetRes = pA->LoadInstanceFromMOF(pObj);
  3000. if (hRetRes==S_OK)
  3001. {
  3002. m_actionList.push_back(pA);
  3003. }
  3004. else
  3005. {
  3006. MY_HRESASSERT(hRetRes);
  3007. delete pA;
  3008. }
  3009. }
  3010. delete [] pszTempGUID;
  3011. pszTempGUID= NULL;
  3012. MY_OUTPUT(L"EXIT ***** CSystem::CreateAction...", 4);
  3013. return hRetRes;
  3014. error:
  3015. MY_ASSERT(FALSE);
  3016. if (pszTempGUID)
  3017. delete [] pszTempGUID;
  3018. return hRetRes;
  3019. }
  3020. // Traverse the Configuration class hierarchy, like do from InternalizeDataGroups(),
  3021. // and create one single safearray to pass back.
  3022. // Contains the object that matches the GUID, and everything under it,
  3023. // including associations.
  3024. HRESULT CSystem::FindAndCopyByGUID(LPTSTR pszGUID, SAFEARRAY** ppsa, LPTSTR *pszOriginalParentGUID)
  3025. {
  3026. int j;
  3027. HRESULT hRetRes = S_OK;
  3028. int i, iSize;
  3029. CDataGroup* pDataGroup;
  3030. SAFEARRAYBOUND bound[1];
  3031. IWbemClassObject* pInstance = NULL;
  3032. long ix[1];
  3033. IUnknown* pIUnknown = NULL;
  3034. ILIST configList;
  3035. HRESULT hRes;
  3036. static LPTSTR systemGUID = L"{@}";
  3037. MY_OUTPUT(L"ENTER ***** CSystem::FindAndCopyByGUID...", 4);
  3038. MY_OUTPUT2(L"COPY GUID=%s", pszGUID, 4);
  3039. //
  3040. // Traverse the complete hierarchy to find the object to delete.
  3041. //
  3042. iSize = m_dataGroupList.size();
  3043. for (i=0; i<iSize; i++)
  3044. {
  3045. MY_ASSERT(i<m_dataGroupList.size());
  3046. pDataGroup = m_dataGroupList[i];
  3047. if (!_wcsicmp(pszGUID, pDataGroup->GetGUID()))
  3048. {
  3049. hRetRes = pDataGroup->Copy(&configList, NULL, NULL);
  3050. *pszOriginalParentGUID = systemGUID;
  3051. break;
  3052. }
  3053. // Look at branch below to see if can find it
  3054. hRetRes = pDataGroup->FindAndCopyByGUID(pszGUID, &configList, pszOriginalParentGUID);
  3055. if (hRetRes==S_OK)
  3056. {
  3057. break;
  3058. }
  3059. else if (hRetRes!=WBEM_S_DIFFERENT)
  3060. {
  3061. break;
  3062. }
  3063. }
  3064. if (hRetRes == WBEM_S_DIFFERENT)
  3065. {
  3066. MY_OUTPUT(L"TargetGuid to copy not found!", 4);
  3067. return WBEM_E_NOT_FOUND;
  3068. }
  3069. else if (hRetRes != S_OK)
  3070. {
  3071. MY_OUTPUT(L"Copy error not found!", 4);
  3072. return hRetRes;
  3073. }
  3074. //
  3075. // Now, here at the end, place in the safe array!
  3076. //
  3077. iSize = configList.size();
  3078. bound[0].lLbound = 0;
  3079. bound[0].cElements = iSize;
  3080. *ppsa = SafeArrayCreate(VT_UNKNOWN, 1, bound);
  3081. if (*ppsa == NULL)
  3082. {
  3083. MY_OUTPUT(L"SafeArray creation failure!", 4);
  3084. MY_ASSERT(FALSE);
  3085. return WBEM_E_OUT_OF_MEMORY;
  3086. }
  3087. j = 0;
  3088. for (i=0; i<iSize; i++)
  3089. {
  3090. MY_ASSERT(i<configList.size());
  3091. pInstance = configList[i];
  3092. // Add the DG instance to the safe array
  3093. hRes = pInstance->QueryInterface(IID_IUnknown, (void**) &pIUnknown);
  3094. if (hRes != NOERROR)
  3095. {
  3096. MY_HRESASSERT(hRes);
  3097. MY_OUTPUT(L"Copy failure!", 4);
  3098. SafeArrayDestroy(*ppsa);
  3099. return hRes;
  3100. }
  3101. ix[0] = j;
  3102. j++;
  3103. hRes = SafeArrayPutElement(*ppsa, ix, pIUnknown);
  3104. if (hRes != S_OK)
  3105. {
  3106. MY_HRESASSERT(hRes);
  3107. MY_OUTPUT(L"Copy failure!", 4);
  3108. MY_ASSERT(FALSE);
  3109. }
  3110. // SafeArrayPutElement adds a reference to the contents of the
  3111. // variant, so we must free the variable we have.
  3112. //
  3113. pIUnknown->Release();
  3114. pInstance->Release();
  3115. pIUnknown = NULL;
  3116. pInstance = NULL;
  3117. }
  3118. MY_OUTPUT(L"EXIT ***** CSystem::FindAndCopyByGUID...", 4);
  3119. return S_OK;
  3120. }
  3121. //
  3122. // What we need to do here is basically just do a PutInstance for everything
  3123. // in the array, and add the one association from my identified parent, to
  3124. // The first HMConfiguration object that was in the array.
  3125. // There are the thresholds to follow to make sure that we do not end up with two objects named
  3126. // the same at the same level. We follow the example of NTExplorer for this.
  3127. // Return 0 if success, 1 if error, and 2 if naming conflict when bForceReplace is set to FALSE.
  3128. //
  3129. HRESULT CSystem::FindAndPasteByGUID(LPTSTR pszTargetGUID, SAFEARRAY* psa, LPTSTR pszOriginalSystem, LPTSTR pszOriginalParentGUID, BOOL bForceReplace)
  3130. {
  3131. BSTR Path = NULL;
  3132. BSTR PathToClass = NULL;
  3133. TCHAR szTemp[1024];
  3134. LPTSTR pStr;
  3135. HRESULT hRes;
  3136. HRESULT hRetRes = S_OK;
  3137. IUnknown* vUnknown;
  3138. IWbemClassObject* pCO = NULL;
  3139. long iLBound, iUBound;
  3140. IWbemClassObject* pTargetObj = NULL;
  3141. LPTSTR pszChildGUID = NULL;
  3142. LPTSTR pszChildName = NULL;
  3143. LPTSTR pszParentClass = NULL;
  3144. LPTSTR pszChildClass = NULL;
  3145. IWbemCallResult *pResult = 0;
  3146. CBase *pParent = NULL;
  3147. CBase *pChild = NULL;
  3148. IWbemClassObject *pNewInstance = NULL;
  3149. IWbemClassObject *pExampleClass = NULL;
  3150. IWbemContext *pCtx = NULL;
  3151. MY_OUTPUT(L"EXIT ***** CSystem::FindAndPasteByGUID...", 4);
  3152. MY_OUTPUT2(L"PASTE Target GUID=%s", pszTargetGUID, 4);
  3153. MY_OUTPUT2(L"OrigionalSystem=%s", pszOriginalSystem, 4);
  3154. MY_OUTPUT2(L"OrigionalParent GUID=%s", pszOriginalParentGUID, 4);
  3155. MY_OUTPUT2(L"ForceReplace=%d", (int)bForceReplace, 4);
  3156. //
  3157. // Make sure that the object exists that we are to copy ourselves under!
  3158. //
  3159. wcscpy(szTemp, L"MicrosoftHM_Configuration.GUID=\"");
  3160. lstrcat(szTemp, pszTargetGUID);
  3161. lstrcat(szTemp, L"\"");
  3162. Path = SysAllocString(szTemp);
  3163. MY_ASSERT(Path); if (!Path) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3164. hRetRes = GetWbemObjectInst(&g_pIWbemServices, Path, NULL, &pTargetObj);
  3165. if (!pTargetObj)
  3166. {
  3167. MY_OUTPUT(L"Target Not found to paste under", 4);
  3168. SysFreeString(Path);
  3169. return 1;
  3170. }
  3171. SysFreeString(Path);
  3172. Path = NULL;
  3173. hRetRes = GetStrProperty(pTargetObj, L"__CLASS", &pszParentClass);
  3174. MY_HRESASSERT(hRetRes);
  3175. //XXXMake sure to prevent a paste under a Threshold
  3176. //Strcmp Parent class with MicrosoftHM_ThresholdConfiguration
  3177. //
  3178. // Do a PutInstance for everything in the array.
  3179. //
  3180. SafeArrayGetLBound(psa, 1, &iLBound);
  3181. SafeArrayGetUBound(psa, 1, &iUBound);
  3182. if ((iUBound - iLBound + 1) == 0)
  3183. {
  3184. MY_ASSERT(FALSE);
  3185. }
  3186. else
  3187. {
  3188. for (long i = iLBound; i <= iUBound; i++)
  3189. {
  3190. vUnknown = NULL;
  3191. hRetRes = SafeArrayGetElement(psa, &i, &vUnknown);
  3192. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3193. pCO = (IWbemClassObject *)vUnknown;
  3194. //
  3195. // We have here the child to get pasted under the target.
  3196. // First off we need to decide if we can paste it, and if we need
  3197. // to do a replace of an existing configuration instance.
  3198. // We also need to save info that is to be used later to create an association.
  3199. //
  3200. if (pszChildGUID == NULL)
  3201. {
  3202. hRetRes = GetStrProperty(pCO, L"GUID", &pszChildGUID);
  3203. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3204. hRetRes = GetStrProperty(pCO, L"Name", &pszChildName);
  3205. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3206. hRetRes = GetStrProperty(pCO, L"__CLASS", &pszChildClass);
  3207. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3208. //
  3209. // Search for the parent, and then look to see if there is a
  3210. // child with the same name.
  3211. //
  3212. pParent = GetParentPointerFromPath(szTemp);
  3213. MY_ASSERT(pParent); if (!pParent) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3214. pChild = pParent->FindImediateChildByName(pszChildName);
  3215. if (pChild)
  3216. {
  3217. //
  3218. // We found a child with the same name already!
  3219. //
  3220. DWORD dwNameLen = MAX_COMPUTERNAME_LENGTH + 1;
  3221. TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  3222. if (GetComputerName(szComputerName, &dwNameLen))
  3223. {
  3224. }
  3225. else
  3226. {
  3227. wcscpy(szComputerName, L"LocalMachine");
  3228. }
  3229. //
  3230. // Do what Explorer does, and act different if the original parent
  3231. // is the same as the target parent.
  3232. //
  3233. if (!_wcsicmp(pszOriginalSystem, szComputerName) &&
  3234. !_wcsicmp(pszOriginalParentGUID, pszTargetGUID))
  3235. {
  3236. //
  3237. // This is where we are copying from and to the same parent.
  3238. // So don't ask, just rename to next increment.
  3239. //
  3240. pStr = szTemp;
  3241. pParent->GetNextChildName(pszChildName, pStr);
  3242. PutStrProperty(pCO, L"Name", szTemp);
  3243. }
  3244. else
  3245. {
  3246. // Different parent, so ask if want to replace!
  3247. if (bForceReplace)
  3248. {
  3249. // Delete the old one first!
  3250. FindAndDeleteByGUID(pChild->m_szGUID);
  3251. delete [] pszChildName;
  3252. pszChildName = NULL;
  3253. }
  3254. else
  3255. {
  3256. delete [] pszParentClass;
  3257. pszParentClass = NULL;
  3258. delete [] pszChildClass;
  3259. pszChildClass = NULL;
  3260. delete [] pszChildGUID;
  3261. pszChildGUID = NULL;
  3262. delete [] pszChildName;
  3263. pszChildName = NULL;
  3264. vUnknown->Release();
  3265. pTargetObj->Release();
  3266. MY_OUTPUT(L"Paste conflict", 4);
  3267. return 2;
  3268. }
  3269. }
  3270. }
  3271. else
  3272. {
  3273. // Not found, so we are OK to proceed
  3274. }
  3275. }
  3276. hRes = g_pIWbemServices->PutInstance(pCO, 0, NULL, &pResult);
  3277. if (hRes != S_OK)
  3278. {
  3279. MY_HRESASSERT(hRes);
  3280. MY_OUTPUT2(L"Put failure Unexpected Error: 0x%08x",hRes,4);
  3281. }
  3282. vUnknown->Release();
  3283. }
  3284. }
  3285. MY_ASSERT(pszChildGUID);
  3286. //
  3287. // Add the one association from my identified parent, to the first
  3288. // HMConfiguration object that was in the array.
  3289. //
  3290. pResult = 0;
  3291. // Get the association class definition.
  3292. PathToClass = SysAllocString(L"MicrosoftHM_ConfigurationAssociation");
  3293. MY_ASSERT(PathToClass); if (!PathToClass) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3294. hRes = g_pIWbemServices->GetObject(PathToClass, 0, pCtx, &pExampleClass, &pResult);
  3295. SysFreeString(PathToClass);
  3296. PathToClass = NULL;
  3297. if (hRes != 0)
  3298. {
  3299. MY_HRESASSERT(hRes);
  3300. MY_OUTPUT2(L"GetObject failure Unexpected Error: 0x%08x",hRes,4);
  3301. return hRes;
  3302. }
  3303. // Create a new association instance.
  3304. hRetRes = pExampleClass->SpawnInstance(0, &pNewInstance);
  3305. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3306. pExampleClass->Release();
  3307. pExampleClass = NULL;
  3308. // If it is the System, then looks like ->"MicrosoftHM_SystemConfiguration.GUID=\"{@}\""
  3309. // Child looks like ->"\\.\root\cimv2\MicrosoftHealthMonitor:
  3310. // MicrosoftHM_DataGroupConfiguration.GUID="{269EA389-07CA-11d3-8FEB-006097919914}""
  3311. // MicrosoftHM_Configuration.GUID="{269EA389-07CA-11d3-8FEB-006097919914}""
  3312. if (!wcscmp(pszTargetGUID, L"{@}"))
  3313. {
  3314. wcscpy(szTemp, L"MicrosoftHM_SystemConfiguration.GUID=\"{@}\"");
  3315. }
  3316. else
  3317. {
  3318. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:");
  3319. lstrcat(szTemp, pszParentClass);
  3320. lstrcat(szTemp, L".GUID=\"");
  3321. lstrcat(szTemp, pszTargetGUID);
  3322. lstrcat(szTemp, L"\"");
  3323. }
  3324. PutStrProperty(pNewInstance, L"ParentPath", szTemp);
  3325. wcscpy(szTemp, L"\\\\.\\root\\cimv2\\MicrosoftHealthMonitor:");
  3326. lstrcat(szTemp, pszChildClass);
  3327. lstrcat(szTemp, L".GUID=\"");
  3328. lstrcat(szTemp, pszChildGUID);
  3329. lstrcat(szTemp, L"\"");
  3330. PutStrProperty(pNewInstance, L"ChildPath", szTemp);
  3331. // Write the association instance
  3332. hRetRes = g_pIWbemServices->PutInstance(pNewInstance, 0, pCtx, &pResult);
  3333. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3334. pNewInstance->Release();
  3335. pNewInstance = NULL;
  3336. //
  3337. // Cleanup
  3338. //
  3339. if (pszChildGUID != NULL)
  3340. {
  3341. delete [] pszChildGUID;
  3342. pszChildGUID = NULL;
  3343. }
  3344. pTargetObj->Release();
  3345. pTargetObj = NULL;
  3346. delete [] pszParentClass;
  3347. pszParentClass = NULL;
  3348. delete [] pszChildClass;
  3349. pszChildClass = NULL;
  3350. MY_OUTPUT(L"EXIT ***** CSystem::FindAndPasteByGUID...", 4);
  3351. return 0;
  3352. error:
  3353. MY_ASSERT(FALSE);
  3354. if (pszParentClass)
  3355. delete [] pszParentClass;
  3356. if (pszChildClass)
  3357. delete [] pszChildClass;
  3358. if (pszChildGUID)
  3359. delete [] pszChildGUID;
  3360. if (pszChildName)
  3361. delete [] pszChildName;
  3362. if (pTargetObj)
  3363. pTargetObj->Release();
  3364. if (Path)
  3365. SysFreeString(Path);
  3366. if (PathToClass)
  3367. SysFreeString(PathToClass);
  3368. if (pNewInstance)
  3369. pNewInstance->Release();
  3370. if (pExampleClass)
  3371. pExampleClass->Release();
  3372. return hRetRes;
  3373. }
  3374. HRESULT CSystem::FindAndCopyWithActionsByGUID(LPTSTR pszGUID, SAFEARRAY** ppsa, LPTSTR *pszOriginalParentGUID)
  3375. {
  3376. return AgentCopy (pszGUID, ppsa, pszOriginalParentGUID);
  3377. }
  3378. HRESULT CSystem::FindAndPasteWithActionsByGUID(LPTSTR pszTargetGUID, SAFEARRAY* psa, LPTSTR pszOriginalSystem, LPTSTR pszOriginalParentGUID, BOOL bForceReplace)
  3379. {
  3380. return AgentPaste (pszTargetGUID, psa, pszOriginalSystem, pszOriginalParentGUID, bForceReplace);
  3381. }
  3382. //
  3383. // Delete the single use of an Action
  3384. //
  3385. #ifdef SAVE
  3386. HRESULT CSystem::Move(LPTSTR pszTargetGUID, LPTSTR pszNewParentGUID)
  3387. {
  3388. int i, iSize;
  3389. CDataGroup* pDataGroup;
  3390. BOOL bFound = FALSE;
  3391. CBase *pTargetBase = NULL;
  3392. CBase *pNewParentBase = NULL;
  3393. MY_OUTPUT(L"ENTER ***** CSystem::Move...", 4);
  3394. MY_OUTPUT2(L"TargetGUID=%s", pszTargetGUID, 4);
  3395. MY_OUTPUT2(L"NewParentGUID=%s", pszNewParentGUID, 4);
  3396. //
  3397. // First locate the thing to move
  3398. //
  3399. iSize = m_dataGroupList.size();
  3400. for (i=0; i<iSize; i++)
  3401. {
  3402. MY_ASSERT(i<m_dataGroupList.size());
  3403. pDataGroup = m_dataGroupList[i];
  3404. if (!_wcsicmp(pszTargetGUID, pDataGroup->GetGUID()))
  3405. {
  3406. pTargetBase = pDataGroup;
  3407. break;
  3408. }
  3409. // Look at branch below to see if can find it
  3410. pTargetBase = pDataGroup->GetParentPointerFromGUID(pszTargetGUID);
  3411. if (pTargetBase)
  3412. {
  3413. break;
  3414. }
  3415. }
  3416. if (pTargetBase)
  3417. {
  3418. bFound = FALSE;
  3419. //
  3420. // Next locate the place to move under
  3421. //
  3422. if (!wcscmp(pszNewParentGUID, L"{@}"))
  3423. {
  3424. pNewParentBase = this;
  3425. bFound = TRUE;
  3426. }
  3427. else
  3428. {
  3429. iSize = m_dataGroupList.size();
  3430. for (i=0; i<iSize; i++)
  3431. {
  3432. MY_ASSERT(i<m_dataGroupList.size());
  3433. pDataGroup = m_dataGroupList[i];
  3434. if (!_wcsicmp(pszNewParentGUID, pDataGroup->GetGUID()))
  3435. {
  3436. pNewParentBase = pDataGroup;
  3437. bFound = TRUE;
  3438. break;
  3439. }
  3440. // Look at branch below to see if can find it
  3441. pNewParentBase = pDataGroup->GetParentPointerFromGUID(pszNewParentGUID);
  3442. if (pNewParentBase)
  3443. {
  3444. bFound = TRUE;
  3445. break;
  3446. }
  3447. }
  3448. }
  3449. if (pNewParentBase)
  3450. {
  3451. //
  3452. // Make sure that it is a legal move.
  3453. // Can't do things like move a Threshold under a System, or DataGroup.
  3454. //
  3455. if (pNewParentBase->m_hmStatusType == HMSTATUS_SYSTEM)
  3456. {
  3457. if (pTargetBase->m_hmStatusType != HMSTATUS_DATAGROUP)
  3458. {
  3459. bFound = FALSE;
  3460. }
  3461. }
  3462. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATAGROUP)
  3463. {
  3464. if (pTargetBase->m_hmStatusType != HMSTATUS_DATAGROUP &&
  3465. pTargetBase->m_hmStatusType != HMSTATUS_DATACOLLECTOR)
  3466. {
  3467. bFound = FALSE;
  3468. }
  3469. }
  3470. else if (pNewParentBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR)
  3471. {
  3472. if (pTargetBase->m_hmStatusType != HMSTATUS_THRESHOLD)
  3473. {
  3474. bFound = FALSE;
  3475. }
  3476. }
  3477. else if (pNewParentBase->m_hmStatusType == HMSTATUS_THRESHOLD)
  3478. {
  3479. bFound = FALSE;
  3480. }
  3481. else
  3482. {
  3483. MY_ASSERT(FALSE);
  3484. }
  3485. if (bFound)
  3486. {
  3487. //
  3488. // Delete the object out of the list of the old parent.
  3489. //
  3490. if (pTargetBase->m_hmStatusType == HMSTATUS_DATAGROUP)
  3491. {
  3492. if (((CDataGroup *)pTargetBase)->m_pParentDG == NULL)
  3493. {
  3494. g_pSystem->DeleteChildFromList(pszTargetGUID);
  3495. }
  3496. else
  3497. {
  3498. ((CDataGroup *)pTargetBase)->m_pParentDG->DeleteChildFromList(pszTargetGUID);
  3499. }
  3500. }
  3501. else if (pTargetBase->m_hmStatusType == HMSTATUS_DATACOLLECTOR)
  3502. {
  3503. ((CDataCollector *)pTargetBase)->m_pParentDG->DeleteChildFromList(pszTargetGUID);
  3504. }
  3505. else if (pTargetBase->m_hmStatusType == HMSTATUS_THRESHOLD)
  3506. {
  3507. ((CThreshold *)pTargetBase)->m_pParentDC->DeleteChildFromList(pszTargetGUID);
  3508. }
  3509. else
  3510. {
  3511. MY_ASSERT(FALSE);
  3512. }
  3513. //
  3514. // Modify the association in the repository.
  3515. //
  3516. pTargetBase->ModifyAssocForMove(pNewParentBase);
  3517. //
  3518. // Move the object under its new parent
  3519. //
  3520. pNewParentBase->ReceiveNewChildForMove(pTargetBase);
  3521. }
  3522. }
  3523. }
  3524. if (bFound == FALSE)
  3525. {
  3526. MY_OUTPUT(L"GUID not found", 4);
  3527. MY_OUTPUT(L"EXIT ***** CSystem::Move...", 4);
  3528. return WBEM_E_NOT_FOUND;
  3529. }
  3530. else
  3531. {
  3532. MY_OUTPUT(L"EXIT ***** CSystem::Move...", 4);
  3533. return S_OK;
  3534. }
  3535. }
  3536. #endif
  3537. #ifdef SAVE
  3538. BOOL CSystem::ModifyAssocForMove(CBase *pNewParentBase)
  3539. {
  3540. MY_ASSERT(FALSE);
  3541. return TRUE;
  3542. }
  3543. #endif
  3544. BOOL CSystem::ReceiveNewChildForMove(CBase *pBase)
  3545. {
  3546. m_dataGroupList.push_back((CDataGroup *)pBase);
  3547. // (CDataGroup *)pBase->SetParentEnabledFlag(m_bEnabled);
  3548. return TRUE;
  3549. }
  3550. BOOL CSystem::DeleteChildFromList(LPTSTR pszGUID)
  3551. {
  3552. int i, iSize;
  3553. CDataGroup* pDataGroup;
  3554. DGLIST::iterator iaDG;
  3555. iSize = m_dataGroupList.size();
  3556. iaDG=m_dataGroupList.begin();
  3557. for (i=0; i<iSize; i++, iaDG++)
  3558. {
  3559. MY_ASSERT(i<m_dataGroupList.size());
  3560. pDataGroup = m_dataGroupList[i];
  3561. if (!_wcsicmp(pszGUID, pDataGroup->GetGUID()))
  3562. {
  3563. m_dataGroupList.erase(iaDG);
  3564. break;
  3565. }
  3566. }
  3567. return TRUE;
  3568. }
  3569. //
  3570. // Delete the single use of an Action
  3571. //
  3572. HRESULT CSystem::DeleteConfigActionAssoc(LPTSTR pszConfigGUID, LPTSTR pszActionGUID)
  3573. {
  3574. BOOL bFound = FALSE;
  3575. int i, iSize;
  3576. CAction* pAction;
  3577. MY_OUTPUT(L"ENTER ***** CSystem::DeleteConfigActionAssociation...", 4);
  3578. MY_OUTPUT2(L"ConfigGUID=%s", pszConfigGUID, 4);
  3579. MY_OUTPUT2(L"ActionGUID=%s", pszActionGUID, 4);
  3580. iSize = m_actionList.size();
  3581. for (i=0; i < iSize; i++)
  3582. {
  3583. MY_ASSERT(i<m_actionList.size());
  3584. pAction = m_actionList[i];
  3585. if (pAction->DeleteConfigActionAssoc(pszConfigGUID, pszActionGUID))
  3586. {
  3587. bFound = TRUE;
  3588. break;
  3589. }
  3590. }
  3591. if (bFound == FALSE)
  3592. {
  3593. MY_OUTPUT(L"GUID not found", 4);
  3594. MY_OUTPUT(L"EXIT ***** CSystem::DeleteConfigActionAssociation...", 4);
  3595. return WBEM_E_NOT_FOUND;
  3596. }
  3597. else
  3598. {
  3599. MY_OUTPUT(L"EXIT ***** CSystem::DeleteConfigActionAssociation...", 4);
  3600. return S_OK;
  3601. }
  3602. }
  3603. //
  3604. // Delete the all associated actions to a given configuration GUID
  3605. //
  3606. HRESULT CSystem::DeleteAllConfigActionAssoc(LPTSTR pszConfigGUID)
  3607. {
  3608. BOOL bFound = FALSE;
  3609. int i, iSize;
  3610. CAction* pAction;
  3611. MY_OUTPUT(L"ENTER ***** CSystem::DeleteAllConfigActionAssociation...", 4);
  3612. MY_OUTPUT2(L"ConfigGUID=%s", pszConfigGUID, 4);
  3613. iSize = m_actionList.size();
  3614. for (i=0; i < iSize; i++)
  3615. {
  3616. MY_ASSERT(i<m_actionList.size());
  3617. pAction = m_actionList[i];
  3618. if (pAction->DeleteConfigActionAssoc(pszConfigGUID, pAction->m_szGUID))
  3619. {
  3620. bFound = TRUE;
  3621. }
  3622. }
  3623. if (bFound == FALSE)
  3624. {
  3625. MY_OUTPUT(L"No associations found. OK?", 4);
  3626. MY_OUTPUT(L"EXIT ***** CSystem::DeleteAllConfigActionAssociation...", 4);
  3627. return S_FALSE;
  3628. }
  3629. else
  3630. {
  3631. MY_OUTPUT(L"EXIT ***** CSystem::DeleteAllConfigActionAssociation...", 4);
  3632. return S_OK;
  3633. }
  3634. }
  3635. CBase *CSystem::GetParentPointerFromPath(LPTSTR pszParentPath)
  3636. {
  3637. TCHAR szGUID[1024];
  3638. int i, iSize;
  3639. CDataGroup* pDataGroup;
  3640. LPTSTR pStr;
  3641. LPTSTR pStr2;
  3642. BOOL bFound = FALSE;
  3643. CBase *pBase;
  3644. wcscpy(szGUID, pszParentPath);
  3645. pStr = wcschr(szGUID, '\"');
  3646. if (pStr)
  3647. {
  3648. pStr++;
  3649. pStr2 = wcschr(pStr, '\"');
  3650. if (pStr2)
  3651. {
  3652. *pStr2 = '\0';
  3653. if (!wcscmp(pStr, L"{@}"))
  3654. {
  3655. pBase = this;
  3656. bFound = TRUE;
  3657. }
  3658. else
  3659. {
  3660. iSize = m_dataGroupList.size();
  3661. for (i=0; i<iSize; i++)
  3662. {
  3663. MY_ASSERT(i<m_dataGroupList.size());
  3664. pDataGroup = m_dataGroupList[i];
  3665. if (!_wcsicmp(pStr, pDataGroup->GetGUID()))
  3666. {
  3667. pBase = pDataGroup;
  3668. bFound = TRUE;
  3669. break;
  3670. }
  3671. // Look at branch below to see if can find it
  3672. pBase = pDataGroup->GetParentPointerFromGUID(pStr);
  3673. if (pBase)
  3674. {
  3675. bFound = TRUE;
  3676. break;
  3677. }
  3678. }
  3679. }
  3680. }
  3681. }
  3682. else
  3683. {
  3684. pStr = wcschr(szGUID, '=');
  3685. if (pStr)
  3686. {
  3687. pStr++;
  3688. pStr++;
  3689. pStr++;
  3690. if (*pStr == '@')
  3691. {
  3692. pBase = this;
  3693. bFound = TRUE;
  3694. }
  3695. }
  3696. }
  3697. if (bFound == TRUE)
  3698. {
  3699. return pBase;
  3700. }
  3701. else
  3702. {
  3703. return NULL;
  3704. }
  3705. }
  3706. CBase *CSystem::FindImediateChildByName(LPTSTR pszName)
  3707. {
  3708. int i, iSize;
  3709. CDataGroup* pDataGroup;
  3710. BOOL bFound = FALSE;
  3711. CBase *pBase;
  3712. iSize = m_dataGroupList.size();
  3713. for (i=0; i<iSize; i++)
  3714. {
  3715. MY_ASSERT(i<m_dataGroupList.size());
  3716. pDataGroup = m_dataGroupList[i];
  3717. if (!_wcsicmp(pszName, pDataGroup->m_szName))
  3718. {
  3719. pBase = pDataGroup;
  3720. bFound = TRUE;
  3721. break;
  3722. }
  3723. }
  3724. if (bFound == TRUE)
  3725. {
  3726. return pBase;
  3727. }
  3728. else
  3729. {
  3730. return NULL;
  3731. }
  3732. }
  3733. BOOL CSystem::GetNextChildName(LPTSTR pszChildName, LPTSTR pszOutName)
  3734. {
  3735. TCHAR szTemp[1024];
  3736. TCHAR szIndex[1024];
  3737. int i, iSize;
  3738. BOOL bFound;
  3739. CDataGroup* pDataGroup;
  3740. int index;
  3741. // We are here because we know that one exists already with the same name.
  3742. // So, lets start off trying to guess what the next name should be and get one.
  3743. index = 0;
  3744. bFound = TRUE;
  3745. while (bFound == TRUE)
  3746. {
  3747. wcscpy(szTemp, pszChildName);
  3748. _itot(index, szIndex, 10);
  3749. lstrcat(szTemp, L" ");
  3750. lstrcat(szTemp, szIndex);
  3751. bFound = FALSE;
  3752. iSize = m_dataGroupList.size();
  3753. for (i=0; i<iSize; i++)
  3754. {
  3755. MY_ASSERT(i<m_dataGroupList.size());
  3756. pDataGroup = m_dataGroupList[i];
  3757. if (!_wcsicmp(szTemp, pDataGroup->m_szName))
  3758. {
  3759. bFound = TRUE;
  3760. break;
  3761. }
  3762. }
  3763. index++;
  3764. }
  3765. wcscpy(pszOutName, szTemp);
  3766. return TRUE;
  3767. }
  3768. CBase *CSystem::FindPointerFromName(LPTSTR pszName)
  3769. {
  3770. int i, iSize;
  3771. CDataGroup* pDataGroup;
  3772. BOOL bFound = FALSE;
  3773. CBase *pBase;
  3774. iSize = m_dataGroupList.size();
  3775. for (i=0; i<iSize; i++)
  3776. {
  3777. MY_ASSERT(i<m_dataGroupList.size());
  3778. pDataGroup = m_dataGroupList[i];
  3779. if (!_wcsicmp(pszName, pDataGroup->m_szName))
  3780. {
  3781. pBase = pDataGroup;
  3782. bFound = TRUE;
  3783. break;
  3784. }
  3785. // Look at branch below to see if can find it
  3786. pBase = pDataGroup->FindPointerFromName(pszName);
  3787. if (pBase)
  3788. {
  3789. bFound = TRUE;
  3790. break;
  3791. }
  3792. }
  3793. if (bFound == TRUE)
  3794. {
  3795. return pBase;
  3796. }
  3797. else
  3798. {
  3799. return NULL;
  3800. }
  3801. }
  3802. //
  3803. // Do string replacement for the Message property
  3804. //
  3805. BOOL CSystem::FormatMessage(IWbemClassObject* pInstance)
  3806. {
  3807. BSTR PropName = NULL;
  3808. LPTSTR pszMsg = NULL;
  3809. SAFEARRAY *psaNames = NULL;
  3810. long lNum;
  3811. HRESULT hRetRes = S_OK;
  3812. LPTSTR pszDest = NULL;
  3813. LPTSTR pszUpperMsg = NULL;
  3814. LPTSTR pszNewMsg = NULL;
  3815. LPTSTR pStr = NULL;
  3816. LPTSTR pStr2 = NULL;
  3817. LPTSTR pStrStart = NULL;
  3818. TOKENSTRUCT tokenElmnt;
  3819. TOKENSTRUCT *pTokenElmnt;
  3820. REPSTRUCT repElmnt;
  3821. REPSTRUCT *pRepElmnt;
  3822. REPSTRUCT *pRepElmnt2;
  3823. REPLIST replacementList;
  3824. int i, iSize, iSizeNeeded, j;
  3825. long lLower, lUpper;
  3826. static TOKENLIST tokenList;
  3827. //
  3828. // We only need to build the set of tokens one time, then from then on
  3829. // we just need to fill in the values for what the replacement strings are.
  3830. //
  3831. if (tokenList.size() == 0)
  3832. {
  3833. //
  3834. // First we build the set of tokens that we are looking for. Each property that
  3835. // is in the ThresholdStatusInstance. We build that set of strings,
  3836. // and the values to replace with.
  3837. //
  3838. //
  3839. // Now go through ThresholdInstance, which is where the Message String
  3840. // actually lives. Get that set of properties for the Instances.
  3841. //
  3842. psaNames = NULL;
  3843. hRetRes = pInstance->GetNames(NULL, WBEM_FLAG_NONSYSTEM_ONLY, NULL, &psaNames);
  3844. if (SUCCEEDED(hRetRes))
  3845. {
  3846. // Get the number of properties.
  3847. SafeArrayGetLBound(psaNames, 1, &lLower);
  3848. SafeArrayGetUBound(psaNames, 1, &lUpper);
  3849. // For each property...
  3850. for (long l=lLower; l<=lUpper; l++)
  3851. {
  3852. // Get this property.
  3853. hRetRes = SafeArrayGetElement(psaNames, &l, &PropName);
  3854. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3855. // Will want to skip some that don't make sense.
  3856. if (!wcscmp(PropName, L"Message"))
  3857. {
  3858. SysFreeString(PropName);
  3859. PropName = NULL;
  3860. continue;
  3861. }
  3862. else if (!wcscmp(PropName, L"ResetMessage"))
  3863. {
  3864. SysFreeString(PropName);
  3865. PropName = NULL;
  3866. continue;
  3867. }
  3868. else if (!wcscmp(PropName, L"EmbeddedCollectedInstance"))
  3869. {
  3870. SysFreeString(PropName);
  3871. PropName = NULL;
  3872. continue;
  3873. }
  3874. tokenElmnt.szOrigToken = new TCHAR[wcslen(PropName)+1];
  3875. MY_ASSERT(tokenElmnt.szOrigToken); if (!tokenElmnt.szOrigToken) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3876. wcscpy(tokenElmnt.szOrigToken, PropName);
  3877. tokenElmnt.szToken = new TCHAR[wcslen(PropName)+3];
  3878. MY_ASSERT(tokenElmnt.szToken); if (!tokenElmnt.szToken) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3879. wcscpy(tokenElmnt.szToken, L"%");
  3880. wcscat(tokenElmnt.szToken, PropName);
  3881. wcscat(tokenElmnt.szToken, L"%");
  3882. _wcsupr(tokenElmnt.szToken);
  3883. tokenElmnt.szReplacementText = NULL;
  3884. tokenList.push_back(tokenElmnt);
  3885. SysFreeString(PropName);
  3886. PropName = NULL;
  3887. }
  3888. SafeArrayDestroy(psaNames);
  3889. psaNames = NULL;
  3890. }
  3891. }
  3892. //
  3893. // Now we can fill in the values to use for the replacement strings.
  3894. //
  3895. //
  3896. // Now go through each ThresholdInstance, which is where the Message String
  3897. // actually lives. Get that set of properties of the Instance,
  3898. // And do the message formatting while there.
  3899. //
  3900. //
  3901. // Get the replacement strings for this instance
  3902. //
  3903. iSize = tokenList.size();
  3904. for (i=0; i<iSize; i++)
  3905. {
  3906. MY_ASSERT(i<tokenList.size());
  3907. pTokenElmnt = &tokenList[i];
  3908. if (pTokenElmnt->szReplacementText != NULL)
  3909. {
  3910. delete [] pTokenElmnt->szReplacementText;
  3911. }
  3912. if (!wcscmp(pTokenElmnt->szToken, L"%TESTCONDITION%"))
  3913. {
  3914. hRetRes = GetUint32Property(pInstance, pTokenElmnt->szOrigToken, &lNum);
  3915. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3916. MY_ASSERT(lNum<9);
  3917. pStr = new TCHAR[wcslen(conditionLocStr[lNum])+1];
  3918. MY_ASSERT(pStr); if (!pStr) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3919. wcscpy(pStr, conditionLocStr[lNum]);
  3920. }
  3921. else if (!wcscmp(pTokenElmnt->szToken, L"%STATE%"))
  3922. {
  3923. hRetRes = GetUint32Property(pInstance, pTokenElmnt->szOrigToken, &lNum);
  3924. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3925. MY_ASSERT(lNum<10);
  3926. pStr = new TCHAR[wcslen(stateLocStr[lNum])+1];
  3927. MY_ASSERT(pStr); if (!pStr) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3928. wcscpy(pStr, stateLocStr[lNum]);
  3929. }
  3930. else
  3931. {
  3932. hRetRes = GetAsStrProperty(pInstance, pTokenElmnt->szOrigToken, &pStr);
  3933. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3934. }
  3935. pTokenElmnt->szReplacementText = pStr;
  3936. }
  3937. //
  3938. // Now we have both lists of tokens that have replacement
  3939. // strings that go with them and the replacement strings
  3940. // that go with them
  3941. //
  3942. //
  3943. // Do formatting of Message. We replace all Variable Tags.
  3944. // Sample string -
  3945. // "Drive %InstanceName% is full. Currently at %CurrentValue%%."
  3946. //
  3947. //
  3948. // Get the origional un-formatted message first.
  3949. // To make case in-sensitive, do a _strdup and then a _wcsupr on the string
  3950. // to scan run the code on it, and then free the duplicated string.
  3951. //
  3952. // If it uses resource IDs, then get that string first, then format that!!!
  3953. hRetRes = GetStrProperty(pInstance, L"Message", &pszMsg);
  3954. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  3955. pszUpperMsg = _wcsdup(pszMsg);
  3956. MY_ASSERT(pszUpperMsg); if (!pszUpperMsg) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  3957. _wcsupr(pszUpperMsg);
  3958. //
  3959. // First loop through and find every token that needs replacing.
  3960. // Put that info into the replacement list.
  3961. //
  3962. // We will do strstr() for each special token until there are no more to find
  3963. // for each. At each find we will store the offset into the string of what
  3964. // we found. Then we sort by what came first.
  3965. //
  3966. // Quick test to see if it is worth searching
  3967. if (wcschr(pszUpperMsg, '%'))
  3968. {
  3969. iSize = tokenList.size();
  3970. pStrStart = pszUpperMsg;
  3971. for (i=0; i<iSize; i++)
  3972. {
  3973. MY_ASSERT(i<tokenList.size());
  3974. pTokenElmnt = &tokenList[i];
  3975. pStr = wcsstr(pStrStart, pTokenElmnt->szToken);
  3976. if (pStr != NULL)
  3977. {
  3978. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  3979. repElmnt.len = wcslen(pTokenElmnt->szToken);
  3980. repElmnt.pszReplacementText = pTokenElmnt->szReplacementText;
  3981. replacementList.push_back(repElmnt);
  3982. i--;
  3983. pStrStart = pStr+1;
  3984. }
  3985. else
  3986. {
  3987. pStrStart = pszUpperMsg;
  3988. }
  3989. }
  3990. //
  3991. // Need to look for replacement strings that have not been replaced.
  3992. // Simply search for %EmbeddedCollectedInstance. and find the end % for each
  3993. // Replace them with <null>
  3994. //
  3995. pStrStart = pszUpperMsg;
  3996. while (TRUE)
  3997. {
  3998. pStr = wcsstr(pStrStart, L"%EMBEDDEDCOLLECTEDINSTANCE.");
  3999. if (pStr != NULL)
  4000. {
  4001. repElmnt.pStartStr = pszMsg+(pStr-pszUpperMsg);
  4002. pStr2 = pStr;
  4003. while (pStr2++)
  4004. {
  4005. if (*pStr2=='%' || iswspace(*pStr2))
  4006. break;
  4007. }
  4008. if (*pStr2=='%')
  4009. {
  4010. repElmnt.len = (pStr2-pStr)+1;
  4011. repElmnt.pszReplacementText = L"<null>";
  4012. replacementList.push_back(repElmnt);
  4013. }
  4014. pStrStart = pStr+1;
  4015. }
  4016. else
  4017. {
  4018. break;
  4019. }
  4020. }
  4021. }
  4022. iSize = replacementList.size();
  4023. if (iSize != 0)
  4024. {
  4025. //
  4026. // Next, sort the replacement list from the first string to
  4027. // be replaced, to the last. Shell sort, Knuth, Vol13, pg. 84.
  4028. //
  4029. for (int gap=iSize/2; 0<gap; gap/=2)
  4030. {
  4031. for (i=gap; i<iSize; i++)
  4032. {
  4033. for (j=i-gap; 0<=j; j-=gap)
  4034. {
  4035. MY_ASSERT(j+gap<replacementList.size());
  4036. pRepElmnt = &replacementList[j+gap];
  4037. MY_ASSERT(j<replacementList.size());
  4038. pRepElmnt2 = &replacementList[j];
  4039. if (pRepElmnt->pStartStr < pRepElmnt2->pStartStr)
  4040. {
  4041. MY_ASSERT(j<replacementList.size());
  4042. repElmnt = replacementList[j];
  4043. MY_ASSERT(j+gap<replacementList.size());
  4044. replacementList[j] = replacementList[j+gap];
  4045. MY_ASSERT(j+gap<replacementList.size());
  4046. replacementList[j+gap] = repElmnt;
  4047. }
  4048. }
  4049. }
  4050. }
  4051. //
  4052. // Next, figure out the size needed for the Message with
  4053. // everything replaced.
  4054. //
  4055. iSizeNeeded = wcslen(pszMsg)+1;
  4056. iSize = replacementList.size();
  4057. for (i=0; i<iSize; i++)
  4058. {
  4059. MY_ASSERT(i<replacementList.size());
  4060. pRepElmnt = &replacementList[i];
  4061. iSizeNeeded -= pRepElmnt->len;
  4062. iSizeNeeded += wcslen(pRepElmnt->pszReplacementText);
  4063. }
  4064. pszNewMsg = new TCHAR[iSizeNeeded];
  4065. MY_ASSERT(pszNewMsg); if (!pszNewMsg) {hRetRes = WBEM_E_OUT_OF_MEMORY; goto error;}
  4066. *pszNewMsg = '\0';
  4067. //
  4068. // Next, we loop through and do the actual replacements.
  4069. // "Drive %InstanceName% is full. Currently at %CurrentValue%%."
  4070. //
  4071. pszDest = pszMsg;
  4072. iSize = replacementList.size();
  4073. for (i=0; i<iSize; i++)
  4074. {
  4075. MY_ASSERT(i<replacementList.size());
  4076. pRepElmnt = &replacementList[i];
  4077. *(pRepElmnt->pStartStr) = '\0';
  4078. wcscat(pszNewMsg, pszDest);
  4079. wcscat(pszNewMsg, pRepElmnt->pszReplacementText);
  4080. //XXXWould memcpy be faster??? memcpy(pszDest, source, charCnt*sizeof(TCHAR));
  4081. pszDest = pRepElmnt->pStartStr+pRepElmnt->len;
  4082. }
  4083. wcscat(pszNewMsg, pszDest);
  4084. PutStrProperty(pInstance, L"Message", pszNewMsg);
  4085. delete [] pszNewMsg;
  4086. pszNewMsg = NULL;
  4087. replacementList.clear();
  4088. }
  4089. else
  4090. {
  4091. PutStrProperty(pInstance, L"Message", pszMsg);
  4092. }
  4093. delete [] pszMsg;
  4094. pszMsg = NULL;
  4095. free(pszUpperMsg);
  4096. pszUpperMsg = NULL;
  4097. return TRUE;
  4098. error:
  4099. MY_ASSERT(FALSE);
  4100. if (PropName)
  4101. SysFreeString(PropName);
  4102. if (psaNames)
  4103. SafeArrayDestroy(psaNames);
  4104. if (pszNewMsg)
  4105. delete [] pszNewMsg;
  4106. if (pszMsg)
  4107. delete [] pszMsg;
  4108. if (pszUpperMsg)
  4109. free(pszUpperMsg);
  4110. m_bValidLoad = FALSE;
  4111. return hRetRes;
  4112. }
  4113. BOOL CSystem::SendReminderActionIfStateIsSame(IWbemObjectSink* pActionEventSink, IWbemObjectSink* pActionTriggerEventSink, IWbemClassObject* pActionInstance, IWbemClassObject* pActionTriggerInstance, unsigned long ulTriggerStates)
  4114. {
  4115. HRESULT hRetRes = S_OK;
  4116. IWbemClassObject* pInstance = NULL;
  4117. VARIANT v;
  4118. GUID guid;
  4119. TCHAR szStatusGUID[100];
  4120. VariantInit(&v);
  4121. if (m_bValidLoad == FALSE)
  4122. return FALSE;
  4123. //
  4124. // Check to see if still in the desired state
  4125. //
  4126. if (!(ulTriggerStates&(1<<m_lCurrState)))
  4127. {
  4128. return TRUE;
  4129. }
  4130. hRetRes = GetHMSystemStatusInstance(&pInstance, TRUE);
  4131. if (SUCCEEDED(hRetRes))
  4132. {
  4133. hRetRes = PutUint32Property(pActionTriggerInstance, L"State", m_lCurrState);
  4134. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4135. VariantInit(&v);
  4136. V_VT(&v) = VT_UNKNOWN;
  4137. V_UNKNOWN(&v) = (IUnknown*)pInstance;
  4138. (V_UNKNOWN(&v))->AddRef();
  4139. hRetRes = (pActionTriggerInstance)->Put(L"EmbeddedStatusEvent", 0L, &v, 0L);
  4140. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4141. VariantClear(&v);
  4142. if (pActionEventSink)
  4143. {
  4144. hRetRes = CoCreateGuid(&guid);
  4145. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4146. StringFromGUID2(guid, szStatusGUID, 100);
  4147. hRetRes = PutStrProperty(pActionInstance, L"StatusGUID", szStatusGUID);
  4148. MY_HRESASSERT(hRetRes); if (hRetRes!=S_OK) goto error;
  4149. hRetRes = pActionEventSink->Indicate(1, &pActionInstance);
  4150. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  4151. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  4152. {
  4153. MY_HRESASSERT(hRetRes);
  4154. MY_OUTPUT(L"Failed on Indicate!", 4);
  4155. }
  4156. }
  4157. if (pActionTriggerEventSink)
  4158. {
  4159. hRetRes = pActionEventSink->Indicate(1, &pActionTriggerInstance);
  4160. //WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  4161. if (FAILED(hRetRes) && hRetRes != WBEM_E_SERVER_TOO_BUSY)
  4162. {
  4163. MY_HRESASSERT(hRetRes);
  4164. MY_OUTPUT(L"Failed on Indicate!", 4);
  4165. }
  4166. }
  4167. pInstance->Release();
  4168. pInstance = NULL;
  4169. }
  4170. else
  4171. {
  4172. MY_HRESASSERT(hRetRes);
  4173. MY_OUTPUT(L"failed to get instance!", 4);
  4174. }
  4175. return TRUE;
  4176. error:
  4177. MY_ASSERT(FALSE);
  4178. if (pInstance)
  4179. pInstance->Release();
  4180. return FALSE;
  4181. }
  4182. HRESULT CSystem::AddPointerToMasterList(CBase *pBaseIn)
  4183. {
  4184. int i, iSize;
  4185. CBase* pBase;
  4186. MY_ASSERT(pBaseIn->m_szGUID);
  4187. if (pBaseIn->m_szGUID == NULL)
  4188. return S_FALSE;
  4189. iSize = m_masterList.size();
  4190. for (i=0; i<iSize; i++)
  4191. {
  4192. MY_ASSERT(i<m_masterList.size());
  4193. pBase = m_masterList[i];
  4194. if (pBaseIn->m_szGUID == pBase->m_szGUID)
  4195. {
  4196. MY_ASSERT(FALSE);
  4197. return S_FALSE;
  4198. }
  4199. }
  4200. m_masterList.push_back(pBaseIn);
  4201. return S_OK;
  4202. }
  4203. BOOL CSystem::RemovePointerFromMasterList(CBase *pBaseIn)
  4204. {
  4205. int i, iSize;
  4206. CBase* pBase;
  4207. BLIST::iterator iaB;
  4208. MY_ASSERT(pBaseIn->m_szGUID);
  4209. if (pBaseIn->m_szGUID == NULL)
  4210. return FALSE;
  4211. iaB=m_masterList.begin();
  4212. iSize = m_masterList.size();
  4213. for (i=0; i<iSize; i++, iaB++)
  4214. {
  4215. MY_ASSERT(i<m_masterList.size());
  4216. pBase = m_masterList[i];
  4217. if (pBaseIn->m_szGUID == pBase->m_szGUID)
  4218. {
  4219. m_masterList.erase(iaB);
  4220. return TRUE;
  4221. }
  4222. }
  4223. MY_ASSERT(FALSE);
  4224. return FALSE;
  4225. }
  4226. CBase *CSystem::FindPointerFromGUIDInMasterList(LPTSTR pszGUID)
  4227. {
  4228. int i, iSize;
  4229. CBase* pBase;
  4230. MY_ASSERT(pszGUID);
  4231. if (pszGUID == NULL)
  4232. return NULL;
  4233. iSize = m_masterList.size();
  4234. for (i=0; i<iSize; i++)
  4235. {
  4236. MY_ASSERT(i<m_masterList.size());
  4237. pBase = m_masterList[i];
  4238. if (!_wcsicmp(pszGUID, pBase->m_szGUID))
  4239. {
  4240. return pBase;
  4241. }
  4242. }
  4243. return NULL;
  4244. }
  4245. HRESULT CSystem::RemapActions(void)
  4246. {
  4247. int i, iSize;
  4248. CAction* pAction;
  4249. iSize = m_actionList.size();
  4250. for (i=0; i < iSize; i++)
  4251. {
  4252. MY_ASSERT(i<m_actionList.size());
  4253. pAction = m_actionList[i];
  4254. pAction->RemapAction();
  4255. }
  4256. return S_OK;
  4257. }
  4258. HRESULT CSystem::CheckAllForBadLoad(void)
  4259. {
  4260. int i, iSize;
  4261. CBase* pBase;
  4262. CAction* pAction;
  4263. //Verify the System???
  4264. CheckForBadLoad();
  4265. iSize = m_masterList.size();
  4266. for (i=0; i<iSize; i++)
  4267. {
  4268. MY_ASSERT(i<m_masterList.size());
  4269. pBase = m_masterList[i];
  4270. pBase->CheckForBadLoad();
  4271. }
  4272. iSize = m_actionList.size();
  4273. for (i=0; i < iSize; i++)
  4274. {
  4275. MY_ASSERT(i<m_actionList.size());
  4276. pAction = m_actionList[i];
  4277. pAction->CheckForBadLoad();
  4278. }
  4279. return S_OK;
  4280. }
  4281. HRESULT CSystem::CheckForBadLoad(void)
  4282. {
  4283. HRESULT hRetRes = S_OK;
  4284. IWbemClassObject* pObj = NULL;
  4285. TCHAR szTemp[1024];
  4286. IWbemClassObject* pInstance = NULL;
  4287. HRESULT hRes;
  4288. if (m_bValidLoad == FALSE)
  4289. {
  4290. wcscpy(szTemp, L"MicrosoftHM_SystemConfiguration.GUID=\"");
  4291. lstrcat(szTemp, m_szGUID);
  4292. lstrcat(szTemp, L"\"");
  4293. hRetRes = GetWbemObjectInst(&g_pIWbemServices, szTemp, NULL, &pObj);
  4294. if (!pObj)
  4295. {
  4296. MY_HRESASSERT(hRetRes);
  4297. return S_FALSE;
  4298. }
  4299. hRetRes = LoadInstanceFromMOF(pObj);
  4300. // Here is where we can try and send out a generic SOS if the load failed each time!!!
  4301. if (hRetRes != S_OK)
  4302. {
  4303. hRes = GetHMSystemStatusInstance(&pInstance, TRUE);
  4304. }
  4305. else
  4306. {
  4307. hRes = GetHMSystemStatusInstance(&pInstance, TRUE);
  4308. }
  4309. if (SUCCEEDED(hRes) && g_pSystemEventSink)
  4310. {
  4311. MY_OUTPUT2(L"EVENT: System State Change=%d", m_lCurrState, 4);
  4312. hRes = g_pSystemEventSink->Indicate(1, &pInstance);
  4313. // WBEM_E_SERVER_TOO_BUSY is Ok. Wbem will deliver.
  4314. if (FAILED(hRes) && hRes != WBEM_E_SERVER_TOO_BUSY)
  4315. {
  4316. MY_HRESASSERT(hRes);
  4317. MY_OUTPUT(L"Failed on Indicate!", 4);
  4318. }
  4319. pInstance->Release();
  4320. pInstance = NULL;
  4321. }
  4322. else
  4323. {
  4324. MY_HRESASSERT(hRes);
  4325. MY_OUTPUT(L"failed to get instance!", 4);
  4326. }
  4327. MY_HRESASSERT(hRetRes);
  4328. pObj->Release();
  4329. pObj = NULL;
  4330. return hRetRes;
  4331. }
  4332. return S_OK;
  4333. }