Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

562 lines
15 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. ModeNode.cpp
  7. This file contains all of the "Main Mode" and "Quick Mode"
  8. objects that appear in the scope pane of the MMC framework.
  9. The objects are:
  10. FILE HISTORY:
  11. */
  12. #include "stdafx.h"
  13. #include "ipsmhand.h"
  14. #include "spddb.h"
  15. #include "FltrNode.h"
  16. #include "SFltNode.h"
  17. #include "ModeNode.h"
  18. #include "MmPol.h"
  19. #include "QmPol.h"
  20. #include "MmFltr.h"
  21. #include "MmSpFltr.h"
  22. #include "MmSA.h"
  23. #include "QmSA.h"
  24. #include "Stats.h"
  25. /*---------------------------------------------------------------------------
  26. CQmNodeHandler::CQmNodeHandler
  27. Description
  28. Author: NSun
  29. ---------------------------------------------------------------------------*/
  30. CQmNodeHandler::CQmNodeHandler(ITFSComponentData *pCompData) :
  31. CIpsmHandler(pCompData)
  32. {
  33. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  34. }
  35. /*!--------------------------------------------------------------------------
  36. CQmNodeHandler::InitializeNode
  37. Initializes node specific data
  38. Author: NSun
  39. ---------------------------------------------------------------------------*/
  40. HRESULT
  41. CQmNodeHandler::InitializeNode
  42. (
  43. ITFSNode * pNode
  44. )
  45. {
  46. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  47. CString strTemp;
  48. strTemp.LoadString(IDS_QUICK_MODE_NODENAME);
  49. SetDisplayName(strTemp);
  50. // Make the node immediately visible
  51. pNode->SetVisibilityState(TFS_VIS_SHOW);
  52. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  53. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_FOLDER_CLOSED);
  54. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_FOLDER_OPEN);
  55. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  56. pNode->SetData(TFS_DATA_TYPE, IPSECMON_QUICK_MODE);
  57. return hrOK;
  58. }
  59. /*---------------------------------------------------------------------------
  60. Overridden base handler functions
  61. ---------------------------------------------------------------------------*/
  62. /*!--------------------------------------------------------------------------
  63. CQmNodeHandler::GetString
  64. Implementation of ITFSNodeHandler::GetString
  65. Author: KennT
  66. ---------------------------------------------------------------------------*/
  67. /*
  68. STDMETHODIMP_(LPCTSTR)
  69. CQmNodeHandler::GetString
  70. (
  71. ITFSNode * pNode,
  72. int nCol
  73. )
  74. {
  75. if (nCol == 0 || nCol == -1)
  76. return GetDisplayName();
  77. else
  78. return NULL;
  79. }
  80. */
  81. /*---------------------------------------------------------------------------
  82. CQmNodeHandler::OnExpand
  83. Handles enumeration of a scope item
  84. Author: NSun
  85. ---------------------------------------------------------------------------*/
  86. HRESULT
  87. CQmNodeHandler::OnExpand
  88. (
  89. ITFSNode * pNode,
  90. LPDATAOBJECT pDataObject,
  91. DWORD dwType,
  92. LPARAM arg,
  93. LPARAM param
  94. )
  95. {
  96. HRESULT hr = hrOK;
  97. if (m_bExpanded)
  98. return hr;
  99. // do the default handling
  100. hr = CIpsmHandler::OnExpand(pNode, pDataObject, dwType, arg, param);
  101. int iVisibleCount = 0;
  102. int iTotalCount = 0;
  103. pNode->GetChildCount(&iVisibleCount, &iTotalCount);
  104. if (0 == iTotalCount)
  105. {
  106. {
  107. // add the filters node
  108. SPITFSNode spFilterNode;
  109. CFilterHandler * pFilterHandler = new CFilterHandler(m_spTFSCompData);
  110. CreateContainerTFSNode(&spFilterNode,
  111. &GUID_IpsmFilterNodeType,
  112. pFilterHandler,
  113. pFilterHandler,
  114. m_spNodeMgr);
  115. pFilterHandler->InitData(m_spSpdInfo);
  116. pFilterHandler->InitializeNode(spFilterNode);
  117. pFilterHandler->Release();
  118. pNode->AddChild(spFilterNode);
  119. }
  120. {
  121. // add Specific filters node
  122. SPITFSNode spSpecificFilterNode;
  123. CSpecificFilterHandler * pSpecificFilterHandler = new CSpecificFilterHandler(m_spTFSCompData);
  124. CreateContainerTFSNode(&spSpecificFilterNode,
  125. &GUID_IpsmSpecificFilterNodeType,
  126. pSpecificFilterHandler,
  127. pSpecificFilterHandler,
  128. m_spNodeMgr);
  129. pSpecificFilterHandler->InitData(m_spSpdInfo);
  130. pSpecificFilterHandler->InitializeNode(spSpecificFilterNode);
  131. pSpecificFilterHandler->Release();
  132. pNode->AddChild(spSpecificFilterNode);
  133. }
  134. {
  135. // add Quick mode policy node
  136. SPITFSNode spQmPolicyNode;
  137. CQmPolicyHandler * pQmPolicyHandler = new CQmPolicyHandler(m_spTFSCompData);
  138. CreateContainerTFSNode(&spQmPolicyNode,
  139. &GUID_IpsmQmPolicyNodeType,
  140. pQmPolicyHandler,
  141. pQmPolicyHandler,
  142. m_spNodeMgr);
  143. pQmPolicyHandler->InitData(m_spSpdInfo);
  144. pQmPolicyHandler->InitializeNode(spQmPolicyNode);
  145. pQmPolicyHandler->Release();
  146. pNode->AddChild(spQmPolicyNode);
  147. }
  148. {
  149. // add the IPSEC stats node
  150. SPITFSNode spSANode;
  151. CIpsecStatsHandler *pIpsecHandler = new CIpsecStatsHandler(m_spTFSCompData);
  152. CreateContainerTFSNode(&spSANode,
  153. &GUID_IpsmMmIpsecStatsNodeType,
  154. pIpsecHandler,
  155. pIpsecHandler,
  156. m_spNodeMgr);
  157. pIpsecHandler->InitData(m_spSpdInfo);
  158. pIpsecHandler->InitializeNode(spSANode);
  159. pIpsecHandler->Release();
  160. pNode->AddChild(spSANode);
  161. }
  162. {
  163. // add the SA node
  164. SPITFSNode spSANode;
  165. CQmSAHandler *pSAHandler = new CQmSAHandler(m_spTFSCompData);
  166. CreateContainerTFSNode(&spSANode,
  167. &GUID_IpsmQmSANodeType,
  168. pSAHandler,
  169. pSAHandler,
  170. m_spNodeMgr);
  171. pSAHandler->InitData(m_spSpdInfo);
  172. pSAHandler->InitializeNode(spSANode);
  173. pSAHandler->Release();
  174. pNode->AddChild(spSANode);
  175. }
  176. }
  177. return hr;
  178. }
  179. /*---------------------------------------------------------------------------
  180. CQmNodeHandler::InitData
  181. Initializes data for this node
  182. Author: NSun
  183. ---------------------------------------------------------------------------*/
  184. HRESULT
  185. CQmNodeHandler::InitData
  186. (
  187. ISpdInfo * pSpdInfo
  188. )
  189. {
  190. m_spSpdInfo.Set(pSpdInfo);
  191. return hrOK;
  192. }
  193. HRESULT
  194. CQmNodeHandler::UpdateStatus
  195. (
  196. ITFSNode * pNode
  197. )
  198. {
  199. HRESULT hr = hrOK;
  200. Trace0("CQmNodeHandler::UpdateStatus");
  201. //We got a refresh notification from the background thread
  202. //The Mode node is just a container. Simply pass the update status
  203. //notification to the child nodes
  204. SPITFSNodeEnum spNodeEnum;
  205. SPITFSNode spCurrentNode;
  206. ULONG nNumReturned;
  207. CORg(pNode->GetEnum(&spNodeEnum));
  208. CORg(spNodeEnum->Next(1, &spCurrentNode, &nNumReturned));
  209. while (nNumReturned)
  210. {
  211. LONG_PTR dwDataType = spCurrentNode->GetData(TFS_DATA_TYPE);
  212. switch (dwDataType)
  213. {
  214. case IPSECMON_FILTER:
  215. {
  216. CFilterHandler * pFltrHandler = GETHANDLER(CFilterHandler, spCurrentNode);
  217. pFltrHandler->UpdateStatus(spCurrentNode);
  218. }
  219. break;
  220. case IPSECMON_SPECIFIC_FILTER:
  221. {
  222. CSpecificFilterHandler * pSpFilterHandler = GETHANDLER(CSpecificFilterHandler, spCurrentNode);
  223. pSpFilterHandler->UpdateStatus(spCurrentNode);
  224. }
  225. break;
  226. case IPSECMON_QM_SA:
  227. {
  228. CQmSAHandler * pSaHandler = GETHANDLER(CQmSAHandler, spCurrentNode);
  229. pSaHandler->UpdateStatus(spCurrentNode);
  230. }
  231. break;
  232. case IPSECMON_QM_POLICY:
  233. {
  234. CQmPolicyHandler * pQmPolHandler = GETHANDLER(CQmPolicyHandler, spCurrentNode);
  235. pQmPolHandler->UpdateStatus(spCurrentNode);
  236. }
  237. break;
  238. case IPSECMON_QM_IPSECSTATS:
  239. {
  240. CIpsecStatsHandler * pIpsecStatsHandler = GETHANDLER(CIpsecStatsHandler, spCurrentNode);
  241. pIpsecStatsHandler->UpdateStatus(spCurrentNode);
  242. }
  243. break;
  244. default:
  245. Trace0("CQmNodeHandler::UpdateStatus Unknow data type of the child node.");
  246. break;
  247. }
  248. spCurrentNode.Release();
  249. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  250. }
  251. COM_PROTECT_ERROR_LABEL;
  252. return hr;
  253. }
  254. /*---------------------------------------------------------------------------
  255. CMmNodeHandler::CMmNodeHandler
  256. Description
  257. Author: NSun
  258. ---------------------------------------------------------------------------*/
  259. CMmNodeHandler::CMmNodeHandler(ITFSComponentData *pCompData) :
  260. CIpsmHandler(pCompData)
  261. {
  262. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  263. }
  264. /*!--------------------------------------------------------------------------
  265. CMmNodeHandler::InitializeNode
  266. Initializes node specific data
  267. Author: NSun
  268. ---------------------------------------------------------------------------*/
  269. HRESULT
  270. CMmNodeHandler::InitializeNode
  271. (
  272. ITFSNode * pNode
  273. )
  274. {
  275. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  276. CString strTemp;
  277. strTemp.LoadString(IDS_MAIN_MODE_NODENAME);
  278. SetDisplayName(strTemp);
  279. // Make the node immediately visible
  280. pNode->SetVisibilityState(TFS_VIS_SHOW);
  281. pNode->SetData(TFS_DATA_COOKIE, (LPARAM) pNode);
  282. pNode->SetData(TFS_DATA_IMAGEINDEX, ICON_IDX_FOLDER_CLOSED);
  283. pNode->SetData(TFS_DATA_OPENIMAGEINDEX, ICON_IDX_FOLDER_OPEN);
  284. pNode->SetData(TFS_DATA_USER, (LPARAM) this);
  285. pNode->SetData(TFS_DATA_TYPE, IPSECMON_MAIN_MODE);
  286. return hrOK;
  287. }
  288. /*---------------------------------------------------------------------------
  289. Overridden base handler functions
  290. ---------------------------------------------------------------------------*/
  291. /*---------------------------------------------------------------------------
  292. CMmNodeHandler::OnExpand
  293. Handles enumeration of a scope item
  294. Author: NSun
  295. ---------------------------------------------------------------------------*/
  296. HRESULT
  297. CMmNodeHandler::OnExpand
  298. (
  299. ITFSNode * pNode,
  300. LPDATAOBJECT pDataObject,
  301. DWORD dwType,
  302. LPARAM arg,
  303. LPARAM param
  304. )
  305. {
  306. HRESULT hr = hrOK;
  307. if (m_bExpanded)
  308. return hr;
  309. // do the default handling
  310. hr = CIpsmHandler::OnExpand(pNode, pDataObject, dwType, arg, param);
  311. int iVisibleCount = 0;
  312. int iTotalCount = 0;
  313. pNode->GetChildCount(&iVisibleCount, &iTotalCount);
  314. if (0 == iTotalCount)
  315. {
  316. {
  317. // add the MM Filter node
  318. SPITFSNode spMmFltrNode;
  319. CMmFilterHandler * pMmFltrHandler = new CMmFilterHandler(m_spTFSCompData);
  320. CreateContainerTFSNode(&spMmFltrNode,
  321. &GUID_IpsmMmFilterNodeType,
  322. pMmFltrHandler,
  323. pMmFltrHandler,
  324. m_spNodeMgr);
  325. pMmFltrHandler->InitData(m_spSpdInfo);
  326. pMmFltrHandler->InitializeNode(spMmFltrNode);
  327. pMmFltrHandler->Release();
  328. pNode->AddChild(spMmFltrNode);
  329. }
  330. {
  331. // add the MM Specific Filter node
  332. SPITFSNode spMmSpFltrNode;
  333. CMmSpFilterHandler * pMmSpFltrHandler = new CMmSpFilterHandler(m_spTFSCompData);
  334. CreateContainerTFSNode(&spMmSpFltrNode,
  335. &GUID_IpsmMmSpFilterNodeType,
  336. pMmSpFltrHandler,
  337. pMmSpFltrHandler,
  338. m_spNodeMgr);
  339. pMmSpFltrHandler->InitData(m_spSpdInfo);
  340. pMmSpFltrHandler->InitializeNode(spMmSpFltrNode);
  341. pMmSpFltrHandler->Release();
  342. pNode->AddChild(spMmSpFltrNode);
  343. }
  344. {
  345. // add the MM Policy node
  346. SPITFSNode spMmPolNode;
  347. CMmPolicyHandler * pMmPolHandler = new CMmPolicyHandler(m_spTFSCompData);
  348. CreateContainerTFSNode(&spMmPolNode,
  349. &GUID_IpsmMmPolicyNodeType,
  350. pMmPolHandler,
  351. pMmPolHandler,
  352. m_spNodeMgr);
  353. pMmPolHandler->InitData(m_spSpdInfo);
  354. pMmPolHandler->InitializeNode(spMmPolNode);
  355. pMmPolHandler->Release();
  356. pNode->AddChild(spMmPolNode);
  357. }
  358. /* TODO completely remove auth node
  359. {
  360. // add the MM Auth node
  361. SPITFSNode spMmAuthNode;
  362. CMmAuthHandler * pMmAuthHandler = new CMmAuthHandler(m_spTFSCompData);
  363. CreateContainerTFSNode(&spMmAuthNode,
  364. &GUID_IpsmMmAuthNodeType,
  365. pMmAuthHandler,
  366. pMmAuthHandler,
  367. m_spNodeMgr);
  368. pMmAuthHandler->InitData(m_spSpdInfo);
  369. pMmAuthHandler->InitializeNode(spMmAuthNode);
  370. pMmAuthHandler->Release();
  371. pNode->AddChild(spMmAuthNode);
  372. }
  373. */
  374. {
  375. // add the IKE stats node
  376. SPITFSNode spSANode;
  377. CIkeStatsHandler *pIkeHandler = new CIkeStatsHandler(m_spTFSCompData);
  378. CreateContainerTFSNode(&spSANode,
  379. &GUID_IpsmMmIkeStatsNodeType,
  380. pIkeHandler,
  381. pIkeHandler,
  382. m_spNodeMgr);
  383. pIkeHandler->InitData(m_spSpdInfo);
  384. pIkeHandler->InitializeNode(spSANode);
  385. pIkeHandler->Release();
  386. pNode->AddChild(spSANode);
  387. }
  388. {
  389. // add the MM SA node
  390. SPITFSNode spMmSANode;
  391. CMmSAHandler * pMmSAHandler = new CMmSAHandler(m_spTFSCompData);
  392. CreateContainerTFSNode(&spMmSANode,
  393. &GUID_IpsmMmSANodeType,
  394. pMmSAHandler,
  395. pMmSAHandler,
  396. m_spNodeMgr);
  397. pMmSAHandler->InitData(m_spSpdInfo);
  398. pMmSAHandler->InitializeNode(spMmSANode);
  399. pMmSAHandler->Release();
  400. pNode->AddChild(spMmSANode);
  401. }
  402. }
  403. return hr;
  404. }
  405. /*---------------------------------------------------------------------------
  406. CMmNodeHandler::InitData
  407. Initializes data for this node
  408. Author: NSun
  409. ---------------------------------------------------------------------------*/
  410. HRESULT
  411. CMmNodeHandler::InitData
  412. (
  413. ISpdInfo * pSpdInfo
  414. )
  415. {
  416. m_spSpdInfo.Set(pSpdInfo);
  417. return hrOK;
  418. }
  419. HRESULT
  420. CMmNodeHandler::UpdateStatus
  421. (
  422. ITFSNode * pNode
  423. )
  424. {
  425. HRESULT hr = hrOK;
  426. Trace0("CMmNodeHandler::UpdateStatus");
  427. //We got a refresh notification from the background thread
  428. //The Mode node is just a container. Simply pass the update status
  429. //notification to the child nodes
  430. SPITFSNodeEnum spNodeEnum;
  431. SPITFSNode spCurrentNode;
  432. ULONG nNumReturned;
  433. CORg(pNode->GetEnum(&spNodeEnum));
  434. CORg(spNodeEnum->Next(1, &spCurrentNode, &nNumReturned));
  435. while (nNumReturned)
  436. {
  437. LONG_PTR dwDataType = spCurrentNode->GetData(TFS_DATA_TYPE);
  438. //update child nodes here
  439. switch (dwDataType)
  440. {
  441. //update child nodes here
  442. case IPSECMON_MM_POLICY:
  443. {
  444. CMmPolicyHandler * pMmPolHandler = GETHANDLER(CMmPolicyHandler, spCurrentNode);
  445. pMmPolHandler->UpdateStatus(spCurrentNode);
  446. }
  447. break;
  448. case IPSECMON_MM_FILTER:
  449. {
  450. CMmFilterHandler * pMmFltrHandler = GETHANDLER(CMmFilterHandler, spCurrentNode);
  451. pMmFltrHandler->UpdateStatus(spCurrentNode);
  452. }
  453. break;
  454. case IPSECMON_MM_SP_FILTER:
  455. {
  456. CMmSpFilterHandler * pMmSpFltrHandler = GETHANDLER(CMmSpFilterHandler, spCurrentNode);
  457. pMmSpFltrHandler->UpdateStatus(spCurrentNode);
  458. }
  459. break;
  460. case IPSECMON_MM_SA:
  461. {
  462. CMmSAHandler * pMmSaHandler = GETHANDLER(CMmSAHandler, spCurrentNode);
  463. pMmSaHandler->UpdateStatus(spCurrentNode);
  464. }
  465. break;
  466. case IPSECMON_MM_IKESTATS:
  467. {
  468. CIkeStatsHandler * pIkeStatsHandler = GETHANDLER(CIkeStatsHandler, spCurrentNode);
  469. pIkeStatsHandler->UpdateStatus(spCurrentNode);
  470. }
  471. break;
  472. default:
  473. Trace0("CMmNodeHandler::UpdateStatus Unknow data type of the child node.");
  474. break;
  475. }
  476. spCurrentNode.Release();
  477. spNodeEnum->Next(1, &spCurrentNode, &nNumReturned);
  478. }
  479. COM_PROTECT_ERROR_LABEL;
  480. return hr;
  481. }