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.

401 lines
9.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. Servpp.h
  7. Server properties implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "mmfltrpp.h"
  12. #include "mmauthpp.h"
  13. #include "spdutil.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. //
  21. // CMmFilterProperties holder
  22. //
  23. /////////////////////////////////////////////////////////////////////////////
  24. CMmFilterProperties::CMmFilterProperties
  25. (
  26. ITFSNode * pNode,
  27. IComponentData * pComponentData,
  28. ITFSComponentData * pTFSCompData,
  29. CMmFilterInfo * pFilterInfo,
  30. ISpdInfo * pSpdInfo,
  31. LPCTSTR pszSheetName
  32. ) : CPropertyPageHolderBase(pNode, pComponentData, pszSheetName)
  33. {
  34. //ASSERT(pFolderNode == GetContainerNode());
  35. m_bAutoDeletePages = FALSE; // we have the pages as embedded members
  36. AddPageToList((CPropertyPageBase*) &m_pageGeneral);
  37. AddPageToList((CPropertyPageBase*) &m_pageAuth);
  38. Assert(pTFSCompData != NULL);
  39. m_spTFSCompData.Set(pTFSCompData);
  40. m_spSpdInfo.Set(pSpdInfo);
  41. m_FltrInfo = *pFilterInfo;
  42. //$REVIEW there is very remote possibility that this routin will fail:
  43. m_spSpdInfo->GetMmAuthMethodsInfoByGuid(m_FltrInfo.m_guidAuthID, &m_AuthMethods);
  44. m_pageAuth.InitData(&m_AuthMethods);
  45. m_bTheme = TRUE;
  46. }
  47. CMmFilterProperties::~CMmFilterProperties()
  48. {
  49. RemovePageFromList((CPropertyPageBase*) &m_pageGeneral, FALSE);
  50. RemovePageFromList((CPropertyPageBase*) &m_pageAuth, FALSE);
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMmFilterGenProp property page
  54. IMPLEMENT_DYNCREATE(CMmFilterGenProp, CPropertyPageBase)
  55. CMmFilterGenProp::CMmFilterGenProp() : CPropertyPageBase(CMmFilterGenProp::IDD)
  56. {
  57. //{{AFX_DATA_INIT(CMmFilterGenProp)
  58. // NOTE: the ClassWizard will add member initialization here
  59. //}}AFX_DATA_INIT
  60. }
  61. CMmFilterGenProp::~CMmFilterGenProp()
  62. {
  63. }
  64. void CMmFilterGenProp::DoDataExchange(CDataExchange* pDX)
  65. {
  66. CPropertyPageBase::DoDataExchange(pDX);
  67. //{{AFX_DATA_MAP(CMmFilterGenProp)
  68. DDX_Control(pDX, IDC_MM_LIST_SPECIFIC, m_listSpecificFilters);
  69. //}}AFX_DATA_MAP
  70. }
  71. BEGIN_MESSAGE_MAP(CMmFilterGenProp, CPropertyPageBase)
  72. //{{AFX_MSG_MAP(CMmFilterGenProp)
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CMmFilterGenProp message handlers
  77. BOOL CMmFilterGenProp::OnInitDialog()
  78. {
  79. CPropertyPageBase::OnInitDialog();
  80. PopulateFilterInfo();
  81. LoadSpecificFilters();
  82. SetDirty(FALSE);
  83. return TRUE; // return TRUE unless you set the focus to a control
  84. // EXCEPTION: OCX Property Pages should return FALSE
  85. }
  86. void CMmFilterGenProp::PopulateFilterInfo()
  87. {
  88. CString st;
  89. CString stMask;
  90. CMmFilterProperties * pFltrProp;
  91. CMmFilterInfo * pFltrInfo;
  92. pFltrProp = (CMmFilterProperties *) GetHolder();
  93. Assert(pFltrProp);
  94. pFltrProp->GetFilterInfo(&pFltrInfo);
  95. int iIdAddr = IDC_MM_FLTR_SRC_ADDR;
  96. BOOL fUseEditForAddr = FALSE;
  97. BOOL fHideMask = FALSE;
  98. BOOL fDnsAddr = FALSE;
  99. switch (pFltrInfo->m_SrcAddr.AddrType)
  100. {
  101. case IP_ADDR_UNIQUE:
  102. if (IP_ADDRESS_ME == pFltrInfo->m_SrcAddr.uIpAddr)
  103. {
  104. st.LoadString(IDS_ADDR_ME);
  105. fHideMask = TRUE;
  106. }
  107. else
  108. {
  109. AddressToString(pFltrInfo->m_SrcAddr, &st, &fDnsAddr);
  110. if (fDnsAddr)
  111. {
  112. fUseEditForAddr = TRUE;
  113. fHideMask = TRUE;
  114. }
  115. else
  116. {
  117. stMask = c_szSingleAddressMask;
  118. IpToString(pFltrInfo->m_SrcAddr.uIpAddr, &st);
  119. }
  120. }
  121. break;
  122. case IP_ADDR_DNS_SERVER:
  123. case IP_ADDR_WINS_SERVER:
  124. case IP_ADDR_DHCP_SERVER:
  125. case IP_ADDR_DEFAULT_GATEWAY:
  126. AddressToString(pFltrInfo->m_SrcAddr, &st);
  127. break;
  128. case IP_ADDR_SUBNET:
  129. if (SUBNET_ADDRESS_ANY == pFltrInfo->m_SrcAddr.uSubNetMask)
  130. {
  131. st.LoadString(IDS_ADDR_ANY);
  132. fHideMask = TRUE;
  133. }
  134. else
  135. {
  136. IpToString(pFltrInfo->m_SrcAddr.uIpAddr, &st);
  137. IpToString(pFltrInfo->m_SrcAddr.uSubNetMask, &stMask);
  138. }
  139. break;
  140. }
  141. if (fHideMask)
  142. {
  143. GetDlgItem(IDC_MM_FLTR_SRC_MASK)->ShowWindow(SW_HIDE);
  144. GetDlgItem(IDC_MM_STATIC_SRC_MASK)->ShowWindow(SW_HIDE);
  145. }
  146. else
  147. {
  148. GetDlgItem(IDC_MM_FLTR_SRC_MASK)->SetWindowText(stMask);
  149. }
  150. if (fUseEditForAddr)
  151. {
  152. iIdAddr = IDC_MM_FLTR_SRC_ADDR_EDIT;
  153. GetDlgItem(IDC_MM_FLTR_SRC_ADDR)->ShowWindow(SW_HIDE);
  154. }
  155. else
  156. {
  157. iIdAddr = IDC_MM_FLTR_SRC_ADDR;
  158. GetDlgItem(IDC_MM_FLTR_SRC_ADDR_EDIT)->ShowWindow(SW_HIDE);
  159. }
  160. GetDlgItem(iIdAddr)->SetWindowText(st);
  161. //now populate the destination info
  162. iIdAddr = IDC_MM_FLTR_DEST_ADDR;
  163. fUseEditForAddr = FALSE;
  164. fHideMask = FALSE;
  165. fDnsAddr = FALSE;
  166. st = _T("");
  167. stMask= _T("");
  168. switch (pFltrInfo->m_DesAddr.AddrType)
  169. {
  170. case IP_ADDR_UNIQUE:
  171. if (IP_ADDRESS_ME == pFltrInfo->m_DesAddr.uIpAddr)
  172. {
  173. st.LoadString(IDS_ADDR_ME);
  174. fHideMask = TRUE;
  175. }
  176. else
  177. {
  178. AddressToString(pFltrInfo->m_DesAddr, &st, &fDnsAddr);
  179. if (fDnsAddr)
  180. {
  181. fUseEditForAddr = TRUE;
  182. fHideMask = TRUE;
  183. }
  184. else
  185. {
  186. stMask = c_szSingleAddressMask;
  187. IpToString(pFltrInfo->m_DesAddr.uIpAddr, &st);
  188. }
  189. }
  190. break;
  191. case IP_ADDR_DNS_SERVER:
  192. case IP_ADDR_WINS_SERVER:
  193. case IP_ADDR_DHCP_SERVER:
  194. case IP_ADDR_DEFAULT_GATEWAY:
  195. AddressToString(pFltrInfo->m_DesAddr, &st);
  196. break;
  197. case IP_ADDR_SUBNET:
  198. if (SUBNET_ADDRESS_ANY == pFltrInfo->m_DesAddr.uSubNetMask)
  199. {
  200. st.LoadString(IDS_ADDR_ANY);
  201. fHideMask = TRUE;
  202. }
  203. else
  204. {
  205. IpToString(pFltrInfo->m_DesAddr.uIpAddr, &st);
  206. IpToString(pFltrInfo->m_DesAddr.uSubNetMask, &stMask);
  207. }
  208. break;
  209. }
  210. if (fHideMask)
  211. {
  212. GetDlgItem(IDC_MM_FLTR_DEST_MASK)->ShowWindow(SW_HIDE);
  213. GetDlgItem(IDC_MM_STATIC_DEST_MASK)->ShowWindow(SW_HIDE);
  214. }
  215. else
  216. {
  217. GetDlgItem(IDC_MM_FLTR_DEST_MASK)->SetWindowText(stMask);
  218. }
  219. if (fUseEditForAddr)
  220. {
  221. iIdAddr = IDC_MM_FLTR_DEST_ADDR_EDIT;
  222. GetDlgItem(IDC_MM_FLTR_DEST_ADDR)->ShowWindow(SW_HIDE);
  223. }
  224. else
  225. {
  226. iIdAddr = IDC_MM_FLTR_DEST_ADDR;
  227. GetDlgItem(IDC_MM_FLTR_DEST_ADDR_EDIT)->ShowWindow(SW_HIDE);
  228. }
  229. GetDlgItem(iIdAddr)->SetWindowText(st);
  230. //we are done with the destination address now
  231. InterfaceTypeToString(pFltrInfo->m_InterfaceType, &st);
  232. GetDlgItem(IDC_MM_FLTR_IF_TYPE)->SetWindowText(st);
  233. BoolToString(pFltrInfo->m_bCreateMirror, &st);
  234. GetDlgItem(IDC_MM_FLTR_MIRROR)->SetWindowText(st);
  235. SPISpdInfo spSpdInfo;
  236. pFltrProp->GetSpdInfo(&spSpdInfo);
  237. DWORD dwNumPol,dwIndex;
  238. st = pFltrInfo->m_stPolicyName;
  239. dwNumPol = spSpdInfo->GetMmPolicyCount();
  240. for(dwIndex=0; dwIndex<dwNumPol; dwIndex++)
  241. {
  242. CMmPolicyInfo MmPol;
  243. if(ERROR_SUCCESS == spSpdInfo->GetMmPolicyInfo(dwIndex, &MmPol))
  244. {
  245. if(IsEqualGUID(MmPol.m_guidID, pFltrInfo->m_guidPolicyID) &&
  246. (MmPol.m_dwFlags & IPSEC_MM_POLICY_DEFAULT_POLICY) )
  247. {
  248. AfxFormatString1(st, IDS_POL_DEFAULT, (LPCTSTR) pFltrInfo->m_stPolicyName);
  249. break;
  250. }
  251. }
  252. }
  253. GetDlgItem(IDC_MM_FLTR_POLICY)->SetWindowText(st);
  254. }
  255. void CMmFilterGenProp::LoadSpecificFilters()
  256. {
  257. CMmFilterProperties * pFltrProp;
  258. CMmFilterInfo * pFltrInfo;
  259. CMmFilterInfoArray arraySpFilters;
  260. int nWidth;
  261. int nRows;
  262. CString st;
  263. pFltrProp = (CMmFilterProperties *) GetHolder();
  264. SPISpdInfo spSpdInfo;
  265. pFltrProp->GetSpdInfo(&spSpdInfo);
  266. pFltrProp->GetFilterInfo(&pFltrInfo);
  267. spSpdInfo->EnumMmSpecificFilters(
  268. &pFltrInfo->m_guidFltr,
  269. &arraySpFilters
  270. );
  271. nWidth = m_listSpecificFilters.GetStringWidth(_T("555.555.555.555 - "));
  272. st.LoadString(IDS_FILTER_PP_COL_SRC);
  273. m_listSpecificFilters.InsertColumn(0, st, LVCFMT_LEFT, nWidth);
  274. nWidth = m_listSpecificFilters.GetStringWidth(_T("555.555.555.555 - "));
  275. st.LoadString(IDS_FILTER_PP_COL_DEST);
  276. m_listSpecificFilters.InsertColumn(1, st, LVCFMT_LEFT, nWidth);
  277. st.LoadString(IDS_FLTR_DIR_OUT);
  278. nWidth = m_listSpecificFilters.GetStringWidth((LPCTSTR)st) + 20;
  279. st.LoadString(IDS_FILTER_PP_COL_DIRECTION);
  280. m_listSpecificFilters.InsertColumn(2, st, LVCFMT_LEFT, nWidth);
  281. st.LoadString(IDS_FILTER_PP_COL_WEIGHT);
  282. nWidth = m_listSpecificFilters.GetStringWidth((LPCTSTR)st) + 20;
  283. m_listSpecificFilters.InsertColumn(3, st, LVCFMT_LEFT, nWidth);
  284. nRows = 0;
  285. for (int i = 0; i < arraySpFilters.GetSize(); i++)
  286. {
  287. nRows = m_listSpecificFilters.InsertItem(nRows, _T(""));
  288. if (-1 != nRows)
  289. {
  290. AddressToString(arraySpFilters[i]->m_SrcAddr, &st);
  291. m_listSpecificFilters.SetItemText(nRows, 0, st);
  292. AddressToString(arraySpFilters[i]->m_DesAddr, &st);
  293. m_listSpecificFilters.SetItemText(nRows, 1, st);
  294. DirectionToString(arraySpFilters[i]->m_dwDirection, &st);
  295. m_listSpecificFilters.SetItemText(nRows, 2, st);
  296. st.Format(_T("%d"), arraySpFilters[i]->m_dwWeight);
  297. m_listSpecificFilters.SetItemText(nRows, 3, st);
  298. m_listSpecificFilters.SetItemData(nRows, i);
  299. }
  300. nRows++;
  301. }
  302. ::FreeItemsAndEmptyArray(arraySpFilters);
  303. if ( nRows > 0 )
  304. {
  305. //select the first item
  306. m_listSpecificFilters.SetFocus();
  307. m_listSpecificFilters.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
  308. }
  309. }
  310. BOOL CMmFilterGenProp::OnApply()
  311. {
  312. if (!IsDirty())
  313. return TRUE;
  314. UpdateData();
  315. //TODO
  316. //Do nothing at this time
  317. //CPropertyPageBase::OnApply();
  318. return TRUE;
  319. }
  320. BOOL CMmFilterGenProp::OnPropertyChange(BOOL bScope, LONG_PTR *ChangeMask)
  321. {
  322. return FALSE;
  323. }