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.

424 lines
9.8 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation **/
  4. /**********************************************************************/
  5. /*
  6. pgnetwk.cpp
  7. Implemenation of CPgNetworking -- property page to edit
  8. profile attributes related to inter-networking
  9. FILE HISTORY:
  10. */
  11. // PgNetwk.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "resource.h"
  15. #include "PgNetwk.h"
  16. #include "helptable.h"
  17. #include "mprapi.h"
  18. #include "std.h"
  19. #include "mprsnap.h"
  20. #include "infobase.h"
  21. #include "router.h"
  22. #include "mprfltr.h"
  23. #include "iasdefs.h"
  24. #include <ipinfoid.h>
  25. #include <fltdefs.h>
  26. #include "iprtinfo.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CPgNetworkingMerge property page
  34. IMPLEMENT_DYNCREATE(CPgNetworkingMerge, CManagedPage)
  35. CPgNetworkingMerge::CPgNetworkingMerge(CRASProfileMerge* profile)
  36. : CManagedPage(CPgNetworkingMerge::IDD),
  37. m_pProfile(profile),
  38. m_bInited(false),
  39. m_dwStaticIP(0)
  40. {
  41. //{{AFX_DATA_INIT(CPgNetworkingMerge)
  42. m_nRadioStatic = -1;
  43. //}}AFX_DATA_INIT
  44. m_pBox = NULL;
  45. if(!(m_pProfile->m_dwAttributeFlags & PABF_msRADIUSFramedIPAddress)) // not defined in policy
  46. {
  47. m_nRadioStatic = 2;
  48. }
  49. else
  50. {
  51. m_dwStaticIP = m_pProfile->m_dwFramedIPAddress;
  52. switch(m_dwStaticIP)
  53. {
  54. case RAS_IP_USERSELECT:
  55. m_nRadioStatic = 1;
  56. break;
  57. case RAS_IP_SERVERASSIGN:
  58. m_nRadioStatic = 0;
  59. break;
  60. default:
  61. m_nRadioStatic = 3;
  62. break;
  63. }
  64. }
  65. // filters
  66. if((BSTR)m_pProfile->m_cbstrFilters)
  67. {
  68. m_cbstrFilters.AssignBSTR(m_pProfile->m_cbstrFilters);
  69. }
  70. SetHelpTable(g_aHelpIDs_IDD_NETWORKING_MERGE);
  71. }
  72. CPgNetworkingMerge::~CPgNetworkingMerge()
  73. {
  74. delete m_pBox;
  75. }
  76. void CPgNetworkingMerge::DoDataExchange(CDataExchange* pDX)
  77. {
  78. ASSERT(m_pProfile);
  79. CPropertyPage::DoDataExchange(pDX);
  80. //{{AFX_DATA_MAP(CPgNetworkingMerge)
  81. DDX_Radio(pDX, IDC_RADIOSERVER, m_nRadioStatic);
  82. //}}AFX_DATA_MAP
  83. if(pDX->m_bSaveAndValidate) // save data to this class
  84. {
  85. // ip adress control
  86. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_GETADDRESS, 0, (LPARAM)&m_dwStaticIP);
  87. }
  88. else // put to dialog
  89. {
  90. // ip adress control
  91. if(m_bInited)
  92. {
  93. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  94. }
  95. else
  96. {
  97. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_CLEARADDRESS, 0, m_dwStaticIP);
  98. }
  99. }
  100. }
  101. BEGIN_MESSAGE_MAP(CPgNetworkingMerge, CPropertyPage)
  102. //{{AFX_MSG_MAP(CPgNetworkingMerge)
  103. ON_BN_CLICKED(IDC_RADIOCLIENT, OnRadioclient)
  104. ON_BN_CLICKED(IDC_RADIOSERVER, OnRadioserver)
  105. ON_WM_HELPINFO()
  106. ON_WM_CONTEXTMENU()
  107. ON_BN_CLICKED(IDC_RADIODEFAULT, OnRadiodefault)
  108. ON_BN_CLICKED(IDC_RADIOSTATIC, OnRadioStatic)
  109. ON_BN_CLICKED(IDC_BUTTON_TOCLIENT, OnButtonToclient)
  110. ON_BN_CLICKED(IDC_BUTTON_FROMCLIENT, OnButtonFromclient)
  111. ON_EN_CHANGE(IDC_EDIT_STATIC_IP_ADDRESS, OnStaticIPAddressChanged)
  112. //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114. /////////////////////////////////////////////////////////////////////////////
  115. // CPgNetworking message handlers
  116. BOOL CPgNetworkingMerge::OnInitDialog()
  117. {
  118. // necessary?
  119. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  120. CPropertyPage::OnInitDialog();
  121. m_bInited = true;
  122. // should be replaced by a proper init of the control
  123. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  124. if (IPWnd != NULL)
  125. {
  126. IPWnd->EnableWindow(TRUE);
  127. }
  128. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  129. if (m_nRadioStatic == 3)
  130. {
  131. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  132. if (IPWnd != NULL)
  133. {
  134. IPWnd->EnableWindow(TRUE);
  135. }
  136. }
  137. else
  138. {
  139. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  140. if (IPWnd != NULL)
  141. {
  142. IPWnd->EnableWindow(FALSE);
  143. }
  144. }
  145. return TRUE; // return TRUE unless you set the focus to a control
  146. // EXCEPTION: OCX Property Pages should return FALSE
  147. }
  148. void CPgNetworkingMerge::OnRadioclient()
  149. {
  150. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  151. if (IPWnd != NULL)
  152. {
  153. IPWnd->EnableWindow(FALSE);
  154. }
  155. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  156. SetModified();
  157. }
  158. void CPgNetworkingMerge::OnRadioserver()
  159. {
  160. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  161. if (IPWnd != NULL)
  162. {
  163. IPWnd->EnableWindow(FALSE);
  164. }
  165. SendDlgItemMessage(IDC_EDIT_STATIC_IP_ADDRESS, IPM_SETADDRESS, 0, m_dwStaticIP);
  166. SetModified();
  167. }
  168. void CPgNetworkingMerge::OnRadiodefault()
  169. {
  170. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  171. if (IPWnd != NULL)
  172. {
  173. IPWnd->EnableWindow(FALSE);
  174. }
  175. SetModified();
  176. }
  177. void CPgNetworkingMerge::OnRadioStatic()
  178. {
  179. if (m_bInited)
  180. {
  181. CWnd* IPWnd = GetDlgItem(IDC_EDIT_STATIC_IP_ADDRESS);
  182. if (IPWnd != NULL)
  183. {
  184. IPWnd->EnableWindow(TRUE);
  185. }
  186. }
  187. SetModified();
  188. }
  189. void CPgNetworkingMerge::OnStaticIPAddressChanged()
  190. {
  191. SetModified();
  192. }
  193. void CPgNetworkingMerge::EnableFilterSettings(BOOL bEnable)
  194. {
  195. m_pBox->Enable(bEnable);
  196. }
  197. BOOL CPgNetworkingMerge::OnApply()
  198. {
  199. if (!GetModified()) return TRUE;
  200. // get the IP policy value
  201. switch(m_nRadioStatic)
  202. {
  203. case 3:
  204. {
  205. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSFramedIPAddress;
  206. m_pProfile->m_dwFramedIPAddress = m_dwStaticIP;
  207. break;
  208. }
  209. case 2: // default server settings
  210. {
  211. m_pProfile->m_dwFramedIPAddress = 0;
  212. m_pProfile->m_dwAttributeFlags &= ~PABF_msRADIUSFramedIPAddress; // not defined in policy
  213. break;
  214. }
  215. case 1: // client requre
  216. {
  217. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSFramedIPAddress;
  218. m_pProfile->m_dwFramedIPAddress = RAS_IP_USERSELECT;
  219. break; // server assign
  220. }
  221. case 0:
  222. {
  223. m_pProfile->m_dwAttributeFlags |= PABF_msRADIUSFramedIPAddress;
  224. m_pProfile->m_dwFramedIPAddress = RAS_IP_SERVERASSIGN;
  225. break;
  226. }
  227. default:
  228. {
  229. break;
  230. }
  231. }
  232. // filters
  233. m_pProfile->m_cbstrFilters.AssignBSTR(m_cbstrFilters);
  234. m_pProfile->m_nFiltersSize = SysStringByteLen(m_cbstrFilters);
  235. return CManagedPage::OnApply();
  236. }
  237. BOOL CPgNetworkingMerge::OnHelpInfo(HELPINFO* pHelpInfo)
  238. {
  239. return CManagedPage::OnHelpInfo(pHelpInfo);
  240. }
  241. void CPgNetworkingMerge::OnContextMenu(CWnd* pWnd, CPoint point)
  242. {
  243. CManagedPage::OnContextMenu(pWnd, point);
  244. }
  245. void CPgNetworkingMerge::OnButtonToclient()
  246. {
  247. ConfigureFilter(FILTER_TO_USER);
  248. }
  249. void CPgNetworkingMerge::OnButtonFromclient()
  250. {
  251. ConfigureFilter(FILTER_FROM_USER);
  252. }
  253. void CPgNetworkingMerge::ConfigureFilter(DWORD dwFilterType) throw ()
  254. {
  255. HRESULT hr;
  256. // Create the InfoBase.
  257. CComPtr<IInfoBase> infoBase;
  258. hr = CreateInfoBase(&infoBase);
  259. if (FAILED(hr))
  260. {
  261. return;
  262. }
  263. // Load the current filters into the InfoBase.
  264. UINT oldLen = m_cbstrFilters.ByteLen();
  265. if (oldLen > 0)
  266. {
  267. hr = infoBase->LoadFrom(
  268. oldLen,
  269. reinterpret_cast<BYTE*>(m_cbstrFilters.m_bstr)
  270. );
  271. if (FAILED(hr))
  272. {
  273. return;
  274. }
  275. }
  276. // Loop until we have a filter that isn't too big.
  277. bool tooBig;
  278. do
  279. {
  280. // Bring up the UI.
  281. hr = MprUIFilterConfigInfoBase(
  282. m_hWnd,
  283. infoBase,
  284. 0,
  285. PID_IP,
  286. dwFilterType
  287. );
  288. if (hr != S_OK)
  289. {
  290. return;
  291. }
  292. BYTE* newFilter;
  293. DWORD newFilterLen;
  294. // check if at least one filter is present.
  295. BYTE* pfilter;
  296. if (
  297. ( (infoBase->GetData(IP_IN_FILTER_INFO, 0, &pfilter) == S_OK) &&
  298. pfilter &&
  299. ((FILTER_DESCRIPTOR *) pfilter)->dwNumFilters > 0
  300. )
  301. ||
  302. (
  303. (infoBase->GetData(IP_OUT_FILTER_INFO, 0, &pfilter) == S_OK) &&
  304. pfilter &&
  305. ((FILTER_DESCRIPTOR *) pfilter)->dwNumFilters > 0
  306. )
  307. )
  308. {
  309. // at lease ont filter present
  310. // Get the new filter.
  311. hr = infoBase->WriteTo(&newFilter, &newFilterLen);
  312. if (FAILED(hr))
  313. {
  314. return;
  315. }
  316. }
  317. else
  318. {
  319. m_cbstrFilters.Clean();
  320. // Activate the apply button.
  321. SetModified();
  322. return;
  323. }
  324. if (newFilterLen < MAX_FILTER_SIZE)
  325. {
  326. // Filter isn't too big.
  327. tooBig = false;
  328. BSTR bstr = SysAllocStringByteLen(
  329. reinterpret_cast<char*>(newFilter),
  330. newFilterLen
  331. );
  332. if (bstr != 0)
  333. {
  334. m_cbstrFilters.Clean();
  335. m_cbstrFilters.m_bstr = bstr;
  336. // Activate the apply button.
  337. SetModified();
  338. }
  339. }
  340. else
  341. {
  342. // Filter is too big.
  343. tooBig = true;
  344. // Warn the user and let him try again.
  345. AfxMessageBox(
  346. IDS_ERROR_IP_FILTER_TOO_BIG,
  347. (MB_OK | MB_ICONEXCLAMATION)
  348. );
  349. }
  350. CoTaskMemFree(newFilter);
  351. }
  352. while(tooBig);
  353. }