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.

524 lines
14 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 2002 **/
  4. /**********************************************************************/
  5. /*
  6. edituser.h
  7. Edit user dialog implementation file
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "mdlsdlg.h"
  12. #include "SrchMFlt.h"
  13. #include "spdutil.h"
  14. #include "ncglobal.h" // network console global defines
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CSearchMMFilters dialog
  22. CSearchMMFilters::CSearchMMFilters(ISpdInfo * pSpdInfo)
  23. : CModelessDlg()
  24. {
  25. //{{AFX_DATA_INIT(CSearchMMFilters)
  26. // NOTE: the ClassWizard will add member initialization here
  27. //}}AFX_DATA_INIT
  28. m_spSpdInfo.Set(pSpdInfo);
  29. }
  30. void CSearchMMFilters::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CBaseDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CSearchMMFilters)
  34. DDX_Control(pDX, IDC_MM_SRCH_LIST, m_listResult);
  35. //}}AFX_DATA_MAP
  36. }
  37. BEGIN_MESSAGE_MAP(CSearchMMFilters, CBaseDialog)
  38. //{{AFX_MSG_MAP(CSearchMMFilters)
  39. ON_BN_CLICKED(IDC_MM_SEARCH, OnButtonSearch)
  40. ON_BN_CLICKED(IDC_MM_SRCH_SRC_ANY, OnSrcOptionClicked)
  41. ON_BN_CLICKED(IDC_MM_SRCH_SRC_SPEC, OnSrcOptionClicked)
  42. ON_BN_CLICKED(IDC_MM_SRCH_DEST_ANY, OnDestOptionClicked)
  43. ON_BN_CLICKED(IDC_MM_SRCH_SRC_ME, OnSrcMeOptionClicked)
  44. ON_BN_CLICKED(IDC_MM_SRCH_DST_ME, OnDstMeOptionClicked)
  45. ON_BN_CLICKED(IDC_MM_SRCH_DEST_SPEC, OnDestOptionClicked)
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. //To manually create the IP control and disable mirroring if the parent dialog is mirrored
  49. //
  50. //Arguments:
  51. // uID [IN] the control that the new IP control should overwrite
  52. // uIDIpCtr [IN] the ID of the IP control to create
  53. //
  54. //Note: $REVIEW (nsun) this should be removed after the snapin is themed since IP controls
  55. // in comctl v6 will handle the mirroring by itself
  56. //
  57. HWND CSearchMMFilters::CreateIPControl(UINT uID, UINT uIDIpCtl)
  58. {
  59. HWND hwndIPControl = NULL;
  60. RECT rcClient; // client area of parent window
  61. CWnd* pWnd = GetDlgItem(uID);
  62. if (pWnd)
  63. {
  64. // get pos info from our template static and then make sure it is hidden
  65. pWnd->GetWindowRect(&rcClient);
  66. pWnd->ShowWindow (SW_HIDE);
  67. ScreenToClient (&rcClient);
  68. //$REVIEW WS_EX_NOINHERITLAYOUT is to fix the mirroring problem of IP control
  69. //See WinXP bug 261926. We should remove that we switch the comctl32 v6
  70. LONG lExStyles = 0;
  71. LONG lExStyles0 = 0;
  72. if (m_hWnd)
  73. {
  74. lExStyles0 = lExStyles = GetWindowLong(m_hWnd, GWL_EXSTYLE);
  75. if (lExStyles & WS_EX_LAYOUTRTL)
  76. {
  77. lExStyles |= WS_EX_NOINHERITLAYOUT;
  78. SetWindowLong(m_hWnd, GWL_EXSTYLE, lExStyles);
  79. }
  80. }
  81. // create the new edit control
  82. hwndIPControl = ::CreateWindowEx(WS_EX_NOINHERITLAYOUT, WC_IPADDRESS, NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
  83. rcClient.left,
  84. rcClient.top,
  85. rcClient.right - rcClient.left,
  86. rcClient.bottom - rcClient.top,
  87. GetSafeHwnd(),
  88. (HMENU) IntToPtr(uIDIpCtl),
  89. AfxGetInstanceHandle (), //g_hinst,
  90. NULL);
  91. if (lExStyles0 != lExStyles && m_hWnd)
  92. {
  93. SetWindowLong(m_hWnd, GWL_EXSTYLE, lExStyles0);
  94. }
  95. // move the control directly behind the pWnd in the Z order
  96. if (hwndIPControl)
  97. {
  98. ::SetWindowPos (hwndIPControl, pWnd->GetSafeHwnd(), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  99. }
  100. }
  101. return hwndIPControl;
  102. }
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CSearchMMFilters message handlers
  105. BOOL CSearchMMFilters::OnInitDialog()
  106. {
  107. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  108. HWND hIpCtrl = CreateIPControl(IDC_MM_SRCH_SRC_IP_TEXT, IDC_MM_SRCH_SRC_IP);
  109. m_ipSrc.Create(hIpCtrl);
  110. hIpCtrl = CreateIPControl(IDC_MM_SRCH_DEST_IP_TEXT, IDC_MM_SRCH_DEST_IP);
  111. m_ipDest.Create(hIpCtrl);
  112. m_ipSrc.SetFieldRange(0, 1, 223);
  113. m_ipDest.SetFieldRange(0, 1, 223);
  114. CBaseDialog::OnInitDialog();
  115. CString st;
  116. CheckDlgButton(IDC_MM_SRCH_SRC_ANY, BST_CHECKED);
  117. OnSrcOptionClicked();
  118. CheckDlgButton(IDC_MM_SRCH_DEST_ANY, BST_CHECKED);
  119. OnDestOptionClicked();
  120. AddIpAddrsToCombo();
  121. //disable the two combo boxes
  122. ((CWnd*)GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO))->EnableWindow(FALSE);
  123. ((CWnd*)GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO))->EnableWindow(FALSE);
  124. CheckDlgButton(IDC_MM_SRCH_INBOUND, BST_CHECKED);
  125. CheckDlgButton(IDC_MM_SRCH_OUTBOUND, BST_CHECKED);
  126. CheckDlgButton(IDC_MM_SRCH_RADIO_BEST, BST_CHECKED);
  127. int nWidth;
  128. nWidth = m_listResult.GetStringWidth(_T("555.555.555.555 - "));
  129. st.LoadString(IDS_COL_FLTR_SRC);
  130. m_listResult.InsertColumn(0, st, LVCFMT_LEFT, nWidth);
  131. nWidth = m_listResult.GetStringWidth(_T("555.555.555.555 - "));
  132. st.LoadString(IDS_COL_FLTR_DEST);
  133. m_listResult.InsertColumn(1, st, LVCFMT_LEFT, nWidth);
  134. st.LoadString(IDS_FLTR_DIR_OUT);
  135. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  136. st.LoadString(IDS_FILTER_PP_COL_DIRECTION);
  137. m_listResult.InsertColumn(2, st, LVCFMT_LEFT, nWidth);
  138. st.LoadString(IDS_FILTER_PP_COL_WEIGHT);
  139. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  140. m_listResult.InsertColumn(3, st, LVCFMT_LEFT, nWidth);
  141. st.LoadString(IDS_FLTER_PP_COL_IKE_POL);
  142. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  143. m_listResult.InsertColumn(4, st, LVCFMT_LEFT, nWidth);
  144. st.LoadString(IDS_FLTER_PP_COL_MM_AUTH);
  145. nWidth = m_listResult.GetStringWidth((LPCTSTR)st) + 20;
  146. m_listResult.InsertColumn(5, st, LVCFMT_LEFT, nWidth);
  147. return TRUE; // return TRUE unless you set the focus to a control
  148. // EXCEPTION: OCX Property Pages should return FALSE
  149. }
  150. void CSearchMMFilters::AddIpAddrsToCombo()
  151. {
  152. PMIB_IPADDRTABLE pIpTable;
  153. ULONG dwSize=0;
  154. ULONG index;
  155. DWORD dwRet;
  156. CString strIP;
  157. dwRet = GetIpAddrTable(
  158. NULL, // buffer for mapping table
  159. &dwSize, // size of buffer
  160. FALSE // sort the table
  161. );
  162. if( ERROR_INSUFFICIENT_BUFFER != dwRet && ERROR_SUCCESS != dwRet ) {
  163. return;
  164. } else {
  165. pIpTable = (PMIB_IPADDRTABLE) LocalAlloc(LMEM_ZEROINIT,dwSize);
  166. }
  167. dwRet = GetIpAddrTable(
  168. pIpTable, // buffer for mapping table
  169. &dwSize, // size of buffer
  170. FALSE // sort the table
  171. );
  172. if(ERROR_SUCCESS != dwRet) {
  173. if(pIpTable)
  174. LocalFree(pIpTable);
  175. return;
  176. }
  177. CComboBox* pComboSrc = (CComboBox*) GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO);
  178. CComboBox* pComboDst = (CComboBox*) GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO);
  179. for(index=0; index<pIpTable->dwNumEntries; index++) {
  180. strIP.Format(_T("%d.%d.%d.%d"),GET_SOCKADDR(pIpTable->table[index].dwAddr));
  181. if(lstrcmp(strIP, _T("127.0.0.1"))) {
  182. pComboSrc->AddString(strIP);
  183. pComboDst->AddString(strIP);
  184. }
  185. }
  186. if(pIpTable)
  187. LocalFree(pIpTable);
  188. }
  189. void CSearchMMFilters::OnButtonSearch()
  190. {
  191. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  192. CMmFilterInfo fltr;
  193. CMmFilterInfoArray arrMatchFltrs;
  194. if (!LoadConditionInfoFromControls(&fltr))
  195. return;
  196. DWORD dwNum = 1000; //TODO BUGBUG, should change to 0 to mean search all matches
  197. if(IsDlgButtonChecked(IDC_MM_SRCH_RADIO_BEST))
  198. {
  199. dwNum = 1;
  200. }
  201. m_spSpdInfo->GetMatchMMFilters(&fltr, dwNum, &arrMatchFltrs);
  202. PopulateFilterListToControl(&arrMatchFltrs);
  203. FreeItemsAndEmptyArray(arrMatchFltrs);
  204. }
  205. BOOL CSearchMMFilters::LoadConditionInfoFromControls(CMmFilterInfo * pFltr)
  206. {
  207. CString st;
  208. if (IsDlgButtonChecked(IDC_MM_SRCH_SRC_ANY))
  209. {
  210. pFltr->m_SrcAddr.AddrType = IP_ADDR_SUBNET;
  211. pFltr->m_SrcAddr.uIpAddr = 0;
  212. pFltr->m_SrcAddr.uSubNetMask = 0;
  213. }
  214. else if (IsDlgButtonChecked(IDC_MM_SRCH_SRC_ME))
  215. {
  216. USES_CONVERSION;
  217. pFltr->m_SrcAddr.AddrType = IP_ADDR_UNIQUE;
  218. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO);
  219. INT nSelected = pCombo->GetCurSel();
  220. if( CB_ERR != nSelected)
  221. {
  222. pCombo->GetLBText(nSelected, st);
  223. try
  224. {
  225. pFltr->m_SrcAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  226. }
  227. catch(...)
  228. {
  229. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  230. return FALSE;
  231. }
  232. pFltr->m_SrcAddr.uSubNetMask = 0xFFFFFFFF;
  233. }
  234. }
  235. else
  236. {
  237. USES_CONVERSION;
  238. pFltr->m_SrcAddr.AddrType = IP_ADDR_UNIQUE;
  239. m_ipSrc.GetAddress(st);
  240. try
  241. {
  242. pFltr->m_SrcAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  243. }
  244. catch(...)
  245. {
  246. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  247. return FALSE;
  248. }
  249. pFltr->m_SrcAddr.uSubNetMask = 0xFFFFFFFF;
  250. }
  251. if (IsDlgButtonChecked(IDC_MM_SRCH_DEST_ANY))
  252. {
  253. pFltr->m_DesAddr.AddrType = IP_ADDR_SUBNET;
  254. pFltr->m_DesAddr.uIpAddr = 0;
  255. pFltr->m_DesAddr.uSubNetMask = 0;
  256. }
  257. else if (IsDlgButtonChecked(IDC_MM_SRCH_DST_ME))
  258. {
  259. USES_CONVERSION;
  260. pFltr->m_DesAddr.AddrType = IP_ADDR_UNIQUE;
  261. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO);
  262. INT nSelected = pCombo->GetCurSel();
  263. if( CB_ERR != nSelected)
  264. {
  265. pCombo->GetLBText(nSelected, st);
  266. try
  267. {
  268. pFltr->m_DesAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  269. }
  270. catch(...)
  271. {
  272. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  273. return FALSE;
  274. }
  275. pFltr->m_DesAddr.uSubNetMask = 0xFFFFFFFF;
  276. }
  277. }
  278. else
  279. {
  280. USES_CONVERSION;
  281. pFltr->m_DesAddr.AddrType = IP_ADDR_UNIQUE;
  282. m_ipDest.GetAddress(st);
  283. try
  284. {
  285. pFltr->m_DesAddr.uIpAddr = inet_addr(T2A((LPCTSTR)st));
  286. }
  287. catch(...)
  288. {
  289. AfxMessageBox(IDS_ERR_OUTOFMEMORY);
  290. return FALSE;
  291. }
  292. pFltr->m_DesAddr.uSubNetMask = 0xFFFFFFFF;
  293. }
  294. if (IsDlgButtonChecked(IDC_MM_SRCH_INBOUND))
  295. {
  296. //if both inbound and outbound are chosen, then
  297. //set the driection valude as 0
  298. if (IsDlgButtonChecked(IDC_MM_SRCH_OUTBOUND))
  299. {
  300. pFltr->m_dwDirection = 0;
  301. }
  302. else
  303. {
  304. pFltr->m_dwDirection = FILTER_DIRECTION_INBOUND;
  305. }
  306. }
  307. else if (IsDlgButtonChecked(IDC_MM_SRCH_OUTBOUND))
  308. {
  309. pFltr->m_dwDirection = FILTER_DIRECTION_OUTBOUND;
  310. }
  311. else
  312. {
  313. ::AfxMessageBox(IDS_ERR_NO_DIRECTION);
  314. return FALSE;
  315. }
  316. return TRUE;
  317. }
  318. void CSearchMMFilters::PopulateFilterListToControl(CMmFilterInfoArray * parrFltrs)
  319. {
  320. CString st;
  321. m_listResult.DeleteAllItems();
  322. int nRows = -1;
  323. for (int i = 0; i < parrFltrs->GetSize(); i++)
  324. {
  325. nRows++;
  326. nRows = m_listResult.InsertItem(nRows, _T(""));
  327. if (-1 != nRows)
  328. {
  329. AddressToString((*parrFltrs)[i]->m_SrcAddr, &st);
  330. m_listResult.SetItemText(nRows, 0, st);
  331. AddressToString((*parrFltrs)[i]->m_DesAddr, &st);
  332. m_listResult.SetItemText(nRows, 1, st);
  333. DirectionToString((*parrFltrs)[i]->m_dwDirection, &st);
  334. m_listResult.SetItemText(nRows, 2, st);
  335. st.Format(_T("%d"), (*parrFltrs)[i]->m_dwWeight);
  336. m_listResult.SetItemText(nRows, 3, st);
  337. st = (*parrFltrs)[i]->m_stPolicyName;
  338. if( (*parrFltrs)[i]->m_dwFlags & IPSEC_MM_POLICY_DEFAULT_POLICY )
  339. {
  340. AfxFormatString1(st, IDS_POL_DEFAULT, (LPCTSTR) (*parrFltrs)[i]->m_stPolicyName);
  341. }
  342. m_listResult.SetItemText(nRows, 4, st);
  343. m_listResult.SetItemText(nRows, 5, (*parrFltrs)[i]->m_stAuthDescription);
  344. m_listResult.SetItemData(nRows, i);
  345. }
  346. }
  347. if ( 0 == parrFltrs->GetSize() )
  348. {
  349. AfxMessageBox(IDS_ERROR_NOMATCH_FILTER);
  350. }
  351. }
  352. void CSearchMMFilters::OnSrcOptionClicked()
  353. {
  354. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  355. BOOL fAny = IsDlgButtonChecked(IDC_MM_SRCH_SRC_ANY);
  356. ((CWnd*)GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO))->EnableWindow(FALSE);
  357. if (fAny)
  358. {
  359. m_ipSrc.ClearAddress();
  360. }
  361. if (m_ipSrc.m_hIPaddr)
  362. {
  363. ::EnableWindow(m_ipSrc.m_hIPaddr, !fAny);
  364. }
  365. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO);
  366. pCombo->SetCurSel(-1);
  367. }
  368. void CSearchMMFilters::OnDestOptionClicked()
  369. {
  370. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  371. BOOL fAny = IsDlgButtonChecked(IDC_MM_SRCH_DEST_ANY);
  372. ((CWnd*)GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO))->EnableWindow(FALSE);
  373. if (fAny)
  374. {
  375. m_ipDest.ClearAddress();
  376. }
  377. if (m_ipDest.m_hIPaddr)
  378. {
  379. ::EnableWindow(m_ipDest.m_hIPaddr, !fAny);
  380. }
  381. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO);
  382. pCombo->SetCurSel(-1);
  383. }
  384. void CSearchMMFilters::OnSrcMeOptionClicked()
  385. {
  386. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  387. ((CWnd*)GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO))->EnableWindow(TRUE);
  388. ::EnableWindow(m_ipSrc.m_hIPaddr, FALSE);
  389. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_MM_SRCH_SRC_ME_COMBO);
  390. int nCount = pCombo->GetCount();
  391. if (nCount > 0) {
  392. pCombo->SetCurSel(0);
  393. }
  394. }
  395. void CSearchMMFilters::OnDstMeOptionClicked()
  396. {
  397. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  398. ((CWnd*)GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO))->EnableWindow(TRUE);
  399. ::EnableWindow(m_ipDest.m_hIPaddr, FALSE);
  400. CComboBox* pCombo = (CComboBox*) GetDlgItem(IDC_MM_SRCH_DST_ME_COMBO);
  401. int nCount = pCombo->GetCount();
  402. if (nCount > 0) {
  403. pCombo->SetCurSel(0);
  404. }
  405. }
  406. void CSearchMMFilters::OnOK()
  407. {
  408. //Since this is a modelless dialog, need to call DestroyWindow
  409. DestroyWindow();
  410. }