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.

503 lines
13 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name: tcpipopt.c
  7. //
  8. // Description:
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "pch.h"
  12. #include "resource.h"
  13. #include "tcpip.h"
  14. typedef struct {
  15. TCHAR *szName;
  16. TCHAR *szDescription;
  17. BOOL bInstalled;
  18. } TCPIP_Options_Entry_Struct;
  19. #define NUMBER_OF_TCPIP_OPTIONS 2
  20. // ISSUE-2002/02/28-stelo- make these an enum
  21. #define IP_SECURITY 0
  22. #define TCPIP_FILTERING 1
  23. static TCPIP_Options_Entry_Struct TCPIP_Options_Entries[NUMBER_OF_TCPIP_OPTIONS];
  24. //----------------------------------------------------------------------------
  25. //
  26. // Function: EnableIpSecurityControls
  27. //
  28. // Purpose:
  29. //
  30. // Arguments:
  31. //
  32. // Returns:
  33. //
  34. //----------------------------------------------------------------------------
  35. VOID
  36. EnableIpSecurityControls( IN HWND hwnd, IN BOOL bState ) {
  37. //
  38. // Grab handles to each of the controls
  39. //
  40. HWND hPolicyComboBox = GetDlgItem( hwnd, IDC_CMB_IPSEC_POLICY_LIST );
  41. HWND hPolicyDescBox = GetDlgItem( hwnd, IDC_EDT_POLICY_DESC );
  42. //
  43. // Grey or ungrey them appropriately
  44. //
  45. EnableWindow( hPolicyComboBox, bState );
  46. EnableWindow( hPolicyDescBox, bState );
  47. }
  48. //----------------------------------------------------------------------------
  49. //
  50. // Function: IpSecurityDlgProc
  51. //
  52. // Purpose:
  53. //
  54. // Arguments:
  55. //
  56. // Returns:
  57. //
  58. //----------------------------------------------------------------------------
  59. INT_PTR CALLBACK
  60. IpSecurityDlgProc( IN HWND hwnd,
  61. IN UINT uMsg,
  62. IN WPARAM wParam,
  63. IN LPARAM lParam) {
  64. BOOL bStatus = TRUE;
  65. switch( uMsg ) {
  66. case WM_INITDIALOG: {
  67. HWND hDescriptionBox = GetDlgItem( hwnd, IDC_EDT_POLICY_DESC );
  68. //
  69. // Load strings from resources
  70. //
  71. StrSecureInitiator = MyLoadString( IDS_SECURE_INITIATOR );
  72. StrSecureInitiatorDesc = MyLoadString( IDS_SECURE_INITIATOR_DESC );
  73. StrSecureResponder = MyLoadString( IDS_SECURE_RESPONDER );
  74. StrSecureResponderDesc = MyLoadString( IDS_SECURE_RESPONDER_DESC );
  75. StrLockdown = MyLoadString( IDS_LOCKDOWN );
  76. StrLockdownDesc = MyLoadString( IDS_LOCKDOWN_DESC );
  77. CheckRadioButton( hwnd,
  78. IDC_RAD_IPSEC_NOIPSEC,
  79. IDC_RAD_IPSEC_CUSTOM,
  80. IDC_RAD_IPSEC_NOIPSEC );
  81. EnableIpSecurityControls( hwnd, FALSE );
  82. SendDlgItemMessage( hwnd,
  83. IDC_CMB_IPSEC_POLICY_LIST,
  84. CB_ADDSTRING,
  85. (WPARAM) 0,
  86. (LPARAM) StrSecureInitiator );
  87. SendDlgItemMessage( hwnd,
  88. IDC_CMB_IPSEC_POLICY_LIST,
  89. CB_ADDSTRING,
  90. (WPARAM) 0,
  91. (LPARAM) StrSecureResponder );
  92. SendDlgItemMessage( hwnd,
  93. IDC_CMB_IPSEC_POLICY_LIST,
  94. CB_ADDSTRING,
  95. (WPARAM) 0,
  96. (LPARAM) StrLockdown );
  97. //
  98. // Set the combo box selection and description
  99. //
  100. // ISSUE-2002/02/28-stelo- this eventually needs to be fixed once I know
  101. // what the security answerfile settings will be
  102. SendDlgItemMessage( hwnd,
  103. IDC_CMB_IPSEC_POLICY_LIST,
  104. CB_SETCURSEL,
  105. (WPARAM) 0,
  106. (LPARAM) 0 );
  107. SetWindowText( hDescriptionBox, StrSecureInitiatorDesc );
  108. break;
  109. }
  110. case WM_COMMAND: {
  111. int nButtonId = LOWORD( wParam );
  112. switch ( nButtonId ) {
  113. case IDC_CMB_IPSEC_POLICY_LIST: {
  114. if( HIWORD( wParam ) == CBN_SELCHANGE ) {
  115. INT_PTR iIndex;
  116. HWND hDescriptionBox = GetDlgItem( hwnd,
  117. IDC_EDT_POLICY_DESC );
  118. // get the current selection from the combo box
  119. iIndex = SendDlgItemMessage( hwnd,
  120. IDC_CMB_IPSEC_POLICY_LIST,
  121. CB_GETCURSEL,
  122. (WPARAM) 0,
  123. (LPARAM) 0 );
  124. switch( iIndex ) {
  125. case 0: SetWindowText( hDescriptionBox,
  126. StrSecureInitiatorDesc );
  127. break;
  128. case 1: SetWindowText( hDescriptionBox,
  129. StrSecureResponderDesc );
  130. break;
  131. case 2: SetWindowText( hDescriptionBox,
  132. StrLockdownDesc );
  133. break;
  134. default:
  135. AssertMsg(FALSE,
  136. "Bad case in TCPIP switch statement.");
  137. }
  138. }
  139. break;
  140. }
  141. case IDC_RAD_IPSEC_NOIPSEC:
  142. if ( HIWORD(wParam) == BN_CLICKED ) {
  143. EnableIpSecurityControls( hwnd, FALSE );
  144. }
  145. break;
  146. case IDC_RAD_IPSEC_CUSTOM:
  147. if ( HIWORD(wParam) == BN_CLICKED ) {
  148. EnableIpSecurityControls( hwnd, TRUE );
  149. }
  150. break;
  151. case IDOK: {
  152. EndDialog( hwnd, 1 );
  153. break;
  154. }
  155. case IDCANCEL: {
  156. EndDialog( hwnd, 0 );
  157. break;
  158. }
  159. }
  160. }
  161. default:
  162. bStatus = FALSE;
  163. break;
  164. }
  165. return bStatus;
  166. }
  167. //----------------------------------------------------------------------------
  168. //
  169. // Function: TcpipFilteringDlgProc
  170. //
  171. // Purpose:
  172. //
  173. // Arguments:
  174. //
  175. // Returns:
  176. //
  177. //----------------------------------------------------------------------------
  178. INT_PTR CALLBACK
  179. TcpipFilteringDlgProc( IN HWND hwnd,
  180. IN UINT uMsg,
  181. IN WPARAM wParam,
  182. IN LPARAM lParam) {
  183. BOOL bStatus = TRUE;
  184. switch( uMsg ) {
  185. case WM_INITDIALOG: {
  186. break;
  187. }
  188. case WM_COMMAND: {
  189. int nButtonId = LOWORD( wParam );
  190. switch ( nButtonId ) {
  191. case IDOK: {
  192. EndDialog( hwnd, 1 );
  193. break;
  194. }
  195. case IDCANCEL: {
  196. EndDialog( hwnd, 0 );
  197. break;
  198. }
  199. }
  200. }
  201. default:
  202. bStatus = FALSE;
  203. break;
  204. }
  205. return bStatus;
  206. }
  207. //----------------------------------------------------------------------------
  208. //
  209. // Function: TCPIP_OptionsPageProc
  210. //
  211. // Purpose: Required function for the property sheet page to function properly.
  212. // The important thing is to give the return value of 1 to the message PSPCB_CREATE and
  213. // 0 for PSPCB_RELEASE
  214. //
  215. // Arguments:
  216. //
  217. // Returns:
  218. //
  219. //----------------------------------------------------------------------------
  220. UINT CALLBACK
  221. TCPIP_OptionsPageProc( HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp ) {
  222. switch( uMsg ) {
  223. case PSPCB_CREATE :
  224. return 1 ; // needed for property sheet page to initialize correctly
  225. case PSPCB_RELEASE :
  226. return 0;
  227. default:
  228. return -1;
  229. }
  230. }
  231. //----------------------------------------------------------------------------
  232. //
  233. // Function: TCPIP_OptionsDlgProc
  234. //
  235. // Purpose: Dialog procedure for the Options page of the property sheet
  236. // handles all the messages sent to this window
  237. //
  238. // Arguments:
  239. //
  240. // Returns:
  241. //
  242. //----------------------------------------------------------------------------
  243. INT_PTR CALLBACK
  244. TCPIP_OptionsDlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
  245. switch( uMsg ) {
  246. case WM_INITDIALOG: {
  247. int i;
  248. HWND hOptionsListView = GetDlgItem( hwndDlg,
  249. IDC_LVW_OPTIONS );
  250. TCPIP_Options_Entries[IP_SECURITY].szName = MyLoadString( IDS_IP_SEC );
  251. TCPIP_Options_Entries[IP_SECURITY].szDescription = MyLoadString( IDS_IP_SEC_DESC );
  252. TCPIP_Options_Entries[IP_SECURITY].bInstalled = TRUE;
  253. TCPIP_Options_Entries[TCPIP_FILTERING].szName = MyLoadString( IDS_TCPIP_FILTERING );
  254. TCPIP_Options_Entries[TCPIP_FILTERING].szDescription = MyLoadString( IDS_TCPIP_FILTERING_DESC );
  255. TCPIP_Options_Entries[TCPIP_FILTERING].bInstalled = TRUE;
  256. // ISSUE-2002/02/28-stelo- Are there anymore settings that can be added to
  257. // this list view
  258. // Under what conditions are these visible? Only
  259. // when DHCP is enabled?
  260. //
  261. // Insert DHCP class ID and IP Security into the list view
  262. //
  263. for( i = 0; i < 2; i++ ) {
  264. InsertItemIntoTcpipListView( hOptionsListView,
  265. (LPARAM) &TCPIP_Options_Entries[i],
  266. 1 );
  267. }
  268. SetListViewSelection( hwndDlg, IDC_LVW_OPTIONS, 1 );
  269. //
  270. // Set the description
  271. //
  272. SetWindowText( GetDlgItem( hwndDlg, IDC_OPT_DESC ),
  273. TCPIP_Options_Entries[0].szDescription );
  274. return TRUE ;
  275. }
  276. case WM_COMMAND: {
  277. WORD wNotifyCode = HIWORD( wParam );
  278. WORD wButtonId = LOWORD( wParam );
  279. switch( wButtonId ) {
  280. case IDC_OPT_PROPERTIES: {
  281. INT iItemSelected;
  282. HWND hOptionsListView = GetDlgItem( hwndDlg, IDC_LVW_OPTIONS );
  283. iItemSelected = ListView_GetSelectionMark( hOptionsListView );
  284. if( iItemSelected == TCPIP_FILTERING ) {
  285. if( DialogBox( FixedGlobals.hInstance,
  286. (LPCTSTR) IDD_TCPIP_FILTER,
  287. hwndDlg,
  288. TcpipFilteringDlgProc ) ) {
  289. }
  290. }
  291. else if( iItemSelected == IP_SECURITY ) {
  292. if( DialogBox( FixedGlobals.hInstance,
  293. (LPCTSTR) IDD_IPSEC,
  294. hwndDlg,
  295. IpSecurityDlgProc ) ) {
  296. }
  297. }
  298. break;
  299. }
  300. } // end switch
  301. break;
  302. }
  303. case WM_NOTIFY: {
  304. LV_DISPINFO *pLvdi = (LV_DISPINFO *) lParam;
  305. NM_LISTVIEW *pNm = (NM_LISTVIEW *)lParam;
  306. TCPIP_Options_Entry_Struct *pListViewEntry = (TCPIP_Options_Entry_Struct *) (pLvdi->item.lParam);
  307. if( wParam == IDC_LVW_OPTIONS ) {
  308. switch( pLvdi->hdr.code ) {
  309. case LVN_GETDISPINFO:
  310. pLvdi->item.pszText = pListViewEntry->szName;
  311. break;
  312. }
  313. switch( pNm->hdr.code ) {
  314. case LVN_ITEMCHANGED:
  315. // test to see if a new item in the list has been selected
  316. if( pNm->uNewState == SELECTED ) {
  317. LV_ITEM lvI;
  318. TCPIP_Options_Entry_Struct *currentEntry;
  319. if( !GetSelectedItemFromListView( hwndDlg,
  320. IDC_LVW_OPTIONS,
  321. &lvI ) ) {
  322. return TRUE ;
  323. }
  324. currentEntry = (TCPIP_Options_Entry_Struct *) lvI.lParam;
  325. //
  326. // Set the description
  327. //
  328. SetWindowText( GetDlgItem( hwndDlg, IDC_OPT_DESC ),
  329. currentEntry->szDescription );
  330. }
  331. break;
  332. }
  333. }
  334. }
  335. default:
  336. return FALSE ;
  337. }
  338. //
  339. // Message was handled so return TRUE
  340. //
  341. return TRUE ;
  342. }