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.

689 lines
11 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. ipdomdlg.cpp
  5. Abstract:
  6. IP and domain security restrictions
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. //
  14. // Include Files
  15. //
  16. #include "stdafx.h"
  17. #include "w3scfg.h"
  18. #include "accessdl.h"
  19. #include "ipdomdlg.h"
  20. //
  21. // Needed for granted/denied icons
  22. //
  23. #include "..\comprop\resource.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. #define ILIST_DENY 0
  30. #define ILIST_GRANT 1
  31. #define ITYPE_DNS 0
  32. #define ITYPE_IP 1
  33. CIPDomainDlg::CIPDomainDlg(
  34. IN BOOL & fIpDirty,
  35. IN BOOL & fDefaultGranted,
  36. IN BOOL & fOldDefaultGranted,
  37. IN CObListPlus & oblAccessList,
  38. IN CWnd * pParent OPTIONAL
  39. )
  40. /*++
  41. Routine Description:
  42. IP/Domain access restrictions dialog constructor
  43. Argumentss:
  44. CWnd * pParent : Parent window
  45. Return Value:
  46. N/A
  47. --*/
  48. : CEmphasizedDialog(CIPDomainDlg::IDD, pParent),
  49. m_ListBoxRes(
  50. IDB_ACCESS,
  51. m_list_IpAddresses.nBitmaps
  52. ),
  53. m_oblAccessList(),
  54. m_list_IpAddresses(TRUE),
  55. m_fIpDirty(fIpDirty),
  56. m_fOldDefaultGranted(fOldDefaultGranted),
  57. m_fDefaultGranted(fDefaultGranted)
  58. {
  59. #if 0 // Keep class wizard happy
  60. //{{AFX_DATA_INIT(CIPDomainDlg)
  61. m_nGrantedDenied = 0;
  62. //}}AFX_DATA_INIT
  63. #endif // 0
  64. //
  65. // Keep a temporary copy of these
  66. //
  67. m_oblAccessList.SetOwnership(FALSE);
  68. m_oblAccessList.AddTail(&oblAccessList);
  69. m_list_IpAddresses.AttachResources(&m_ListBoxRes);
  70. m_nGrantedDenied = m_fDefaultGranted ? DEFAULT_GRANTED : DEFAULT_DENIED;
  71. }
  72. void
  73. CIPDomainDlg::DoDataExchange(
  74. IN CDataExchange * pDX
  75. )
  76. /*++
  77. Routine Description:
  78. Initialise/Store control data
  79. Arguments:
  80. CDataExchange * pDX - DDX/DDV control structure
  81. Return Value:
  82. None
  83. --*/
  84. {
  85. CEmphasizedDialog::DoDataExchange(pDX);
  86. //{{AFX_DATA_MAP(CIPDomainDlg)
  87. DDX_Control(pDX, IDC_RADIO_GRANTED, m_radio_Granted);
  88. DDX_Control(pDX, IDC_BUTTON_ADD, m_button_Add);
  89. DDX_Control(pDX, IDC_BUTTON_REMOVE, m_button_Remove);
  90. DDX_Control(pDX, IDC_BUTTON_EDIT, m_button_Edit);
  91. DDX_Control(pDX, IDC_ICON_GRANTED, m_icon_Granted);
  92. DDX_Control(pDX, IDC_ICON_DENIED, m_icon_Denied);
  93. DDX_Radio(pDX, IDC_RADIO_GRANTED, m_nGrantedDenied);
  94. //}}AFX_DATA_MAP
  95. //
  96. // Private DDX/DDV Routines
  97. //
  98. DDX_Control(pDX, IDC_RADIO_DENIED, m_radio_Denied);
  99. DDX_Control(pDX, IDC_LIST_IP_ADDRESSES, m_list_IpAddresses);
  100. }
  101. //
  102. // Message Map
  103. //
  104. BEGIN_MESSAGE_MAP(CIPDomainDlg, CEmphasizedDialog)
  105. //{{AFX_MSG_MAP(CIPDomainDlg)
  106. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  107. ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  108. ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  109. ON_LBN_DBLCLK(IDC_LIST_IP_ADDRESSES, OnDblclkListIpAddresses)
  110. ON_LBN_ERRSPACE(IDC_LIST_IP_ADDRESSES, OnErrspaceListIpAddresses)
  111. ON_BN_CLICKED(IDC_RADIO_GRANTED, OnRadioGranted)
  112. ON_BN_CLICKED(IDC_RADIO_DENIED, OnRadioDenied)
  113. ON_LBN_SELCHANGE(IDC_LIST_IP_ADDRESSES, OnSelchangeListIpAddresses)
  114. ON_WM_VKEYTOITEM()
  115. //}}AFX_MSG_MAP
  116. END_MESSAGE_MAP()
  117. //
  118. // Message Handlers
  119. //
  120. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  121. void
  122. CIPDomainDlg::OnButtonAdd()
  123. /*++
  124. Routine Description:
  125. 'Add' button handler
  126. Arguments:
  127. None
  128. Return Value:
  129. None
  130. --*/
  131. {
  132. if (ShowPropertiesDialog(TRUE) == IDOK)
  133. {
  134. m_fIpDirty = TRUE;
  135. SetControlStates();
  136. }
  137. }
  138. void
  139. CIPDomainDlg::OnButtonEdit()
  140. /*++
  141. Routine Description:
  142. 'Edit' button handler
  143. Arguments:
  144. None
  145. Return Value:
  146. None
  147. --*/
  148. {
  149. if (ShowPropertiesDialog(FALSE) == IDOK)
  150. {
  151. m_fIpDirty = TRUE;
  152. SetControlStates();
  153. }
  154. }
  155. void
  156. CIPDomainDlg::OnButtonRemove()
  157. /*++
  158. Routine Description:
  159. 'Remove' button handler
  160. Arguments:
  161. None
  162. Return Value:
  163. None
  164. --*/
  165. {
  166. int nSel = 0;
  167. int nCurSel = m_list_IpAddresses.GetCurSel();
  168. while (m_list_IpAddresses.GetNextSelectedItem(&nSel))
  169. {
  170. m_oblAccessList.RemoveIndex(nSel);
  171. m_list_IpAddresses.DeleteString(nSel);
  172. }
  173. m_fIpDirty = TRUE;
  174. if (nCurSel > 0)
  175. {
  176. --nCurSel;
  177. }
  178. m_list_IpAddresses.SetCurSel(nCurSel);
  179. if (!SetControlStates())
  180. {
  181. m_button_Add.SetFocus();
  182. }
  183. }
  184. BOOL
  185. CIPDomainDlg::SetControlStates()
  186. /*++
  187. Routine Description:
  188. Set button states depending on content of the listbox and the controls
  189. Arguments:
  190. None
  191. Return Value:
  192. TRUE if at least one item is currently selected in the listbox.
  193. --*/
  194. {
  195. BOOL fSomeSelection = m_list_IpAddresses.GetSelCount() > 0;
  196. m_button_Edit.EnableWindow(m_list_IpAddresses.GetSelCount() == 1);
  197. m_button_Remove.EnableWindow(m_list_IpAddresses.GetSelCount() > 0);
  198. return fSomeSelection;
  199. }
  200. void
  201. CIPDomainDlg::FillListBox(
  202. IN CIPAccessDescriptor * pSelection OPTIONAL
  203. )
  204. /*++
  205. Routine Description:
  206. Fill the ip address listbox from the oblist of access entries
  207. Arguments:
  208. CIPAccessDescriptor * pSelection : Item to be selected or NULL.
  209. Return Value:
  210. None
  211. --*/
  212. {
  213. CObListIter obli(m_oblAccessList);
  214. const CIPAccessDescriptor * pAccess;
  215. m_list_IpAddresses.SetRedraw(FALSE);
  216. m_list_IpAddresses.ResetContent();
  217. int cItems = 0 ;
  218. int nSel = LB_ERR, nItem;
  219. for ( /**/; pAccess = (CIPAccessDescriptor *)obli.Next(); ++cItems)
  220. {
  221. //
  222. // We only list those not adhering to the default
  223. //
  224. if (pAccess->HasAccess() != m_fDefaultGranted)
  225. {
  226. nItem = m_list_IpAddresses.AddItem(pAccess);
  227. if (pAccess == pSelection)
  228. {
  229. //
  230. // Found item to be selected
  231. //
  232. nSel = nItem;
  233. }
  234. }
  235. }
  236. m_list_IpAddresses.SetCurSel(nSel);
  237. m_list_IpAddresses.SetRedraw(TRUE);
  238. }
  239. DWORD
  240. CIPDomainDlg::SortAccessList()
  241. /*++
  242. Routine Description:
  243. Sorting the access list by grant denied and ip address
  244. FillListBox() should be called after this because
  245. the listbox will no longer reflect the true status
  246. of the list of directories.
  247. Arguments:
  248. None
  249. Return Value:
  250. Error Return code
  251. --*/
  252. {
  253. BeginWaitCursor();
  254. DWORD dw = m_oblAccessList.Sort((CObjectPlus::PCOBJPLUS_ORDER_FUNC)
  255. &CIPAccessDescriptor::OrderByAddress);
  256. EndWaitCursor();
  257. return dw;
  258. }
  259. INT_PTR
  260. CIPDomainDlg::ShowPropertiesDialog(
  261. IN BOOL fAdd
  262. )
  263. /*++
  264. Routine Description:
  265. Bring up the dialog used for add or edit. Return the value returned
  266. by the dialog
  267. Arguments:
  268. BOOL fAdd : If TRUE, create new item. Otherwise, edit existing item
  269. Return Value:
  270. Dialog return code (IDOK/IDCANCEL)
  271. --*/
  272. {
  273. //
  274. // Bring up the dialog
  275. //
  276. CIPAccessDescriptor * pAccess = NULL;
  277. int nCurSel = LB_ERR;
  278. if (!fAdd)
  279. {
  280. //
  281. // Edit existing entry -- there better be only one...
  282. //
  283. pAccess = m_list_IpAddresses.GetSelectedItem();
  284. ASSERT(pAccess != NULL);
  285. if (pAccess == NULL)
  286. {
  287. //
  288. // Double click?
  289. //
  290. return IDCANCEL;
  291. }
  292. }
  293. CIPAccessDlg dlgAccess(
  294. m_fDefaultGranted,
  295. pAccess,
  296. &m_oblAccessList,
  297. this,
  298. TRUE
  299. );
  300. INT_PTR nReturn = dlgAccess.DoModal();
  301. if (nReturn == IDOK)
  302. {
  303. CError err;
  304. ASSERT(pAccess != NULL);
  305. if (pAccess == NULL)
  306. {
  307. err = ERROR_NOT_ENOUGH_MEMORY;
  308. }
  309. else
  310. {
  311. try
  312. {
  313. if (fAdd)
  314. {
  315. m_oblAccessList.AddTail(pAccess);
  316. }
  317. SortAccessList();
  318. FillListBox(pAccess);
  319. }
  320. catch(CMemoryException * e)
  321. {
  322. err = ERROR_NOT_ENOUGH_MEMORY;
  323. e->Delete();
  324. }
  325. }
  326. err.MessageBoxOnFailure();
  327. }
  328. return nReturn;
  329. }
  330. void
  331. CIPDomainDlg::OnDblclkListIpAddresses()
  332. /*++
  333. Routine Description:
  334. Double click handler for IP listbox
  335. Arguments:
  336. None
  337. Return Value:
  338. None
  339. --*/
  340. {
  341. OnButtonEdit();
  342. }
  343. void
  344. CIPDomainDlg::OnErrspaceListIpAddresses()
  345. /*++
  346. Routine Description:
  347. Error -- out of memory error for IP listbox
  348. Arguments:
  349. None
  350. Return Value:
  351. None
  352. --*/
  353. {
  354. SetControlStates();
  355. }
  356. void
  357. CIPDomainDlg::OnSelchangeListIpAddresses()
  358. /*++
  359. Routine Description:
  360. ip address 'selection change' notification handler
  361. Arguments:
  362. None
  363. Return Value:
  364. None
  365. --*/
  366. {
  367. SetControlStates();
  368. }
  369. BOOL
  370. CIPDomainDlg::OnInitDialog()
  371. /*++
  372. Routine Description:
  373. WM_INITDIALOG handler. Initialize the dialog.
  374. Arguments:
  375. None.
  376. Return Value:
  377. TRUE if no focus is to be set automatically, FALSE if the focus
  378. is already set.
  379. --*/
  380. {
  381. CEmphasizedDialog::OnInitDialog();
  382. m_icon_Granted.SetIcon(::AfxGetApp()->LoadIcon(IDI_GRANTED));
  383. m_icon_Denied.SetIcon(::AfxGetApp()->LoadIcon(IDI_DENIED));
  384. m_list_IpAddresses.Initialize();
  385. FillListBox();
  386. SetControlStates();
  387. return TRUE;
  388. }
  389. void
  390. CIPDomainDlg::OnRadioGranted()
  391. /*++
  392. Routine Description:
  393. 'Granted' radio button handler.
  394. Granted by default has been selected. Refill the listbox with
  395. items that have been explicitly denied. Although we can
  396. only have a deny list or a grant list, we keep both of them
  397. around until it comes time to saving the information.
  398. Arguments:
  399. None
  400. Return Value:
  401. None
  402. --*/
  403. {
  404. if (!m_fDefaultGranted)
  405. {
  406. m_fDefaultGranted = TRUE;
  407. FillListBox();
  408. SetControlStates();
  409. }
  410. }
  411. void
  412. CIPDomainDlg::OnRadioDenied()
  413. /*++
  414. Routine Description:
  415. 'Denied' radio button handler. Same as above, with reverse granted
  416. and denied.
  417. Arguments:
  418. None
  419. Return Value:
  420. None
  421. --*/
  422. {
  423. if (m_fDefaultGranted)
  424. {
  425. m_fDefaultGranted = FALSE;
  426. FillListBox();
  427. SetControlStates();
  428. }
  429. }
  430. int
  431. CIPDomainDlg::OnVKeyToItem(
  432. IN UINT nKey,
  433. IN CListBox * pListBox,
  434. IN UINT nIndex
  435. )
  436. /*++
  437. Routine Description:
  438. Map virtual keys to commands for ip listbox
  439. Arguments:
  440. UINT nKey Specifies the virtual-key code of the key
  441. that the user pressed.
  442. CListBox * pListBox Specifies a pointer to the list box. The
  443. pointer may be temporary and should not be stored for later use.
  444. UINT nIndex Specifies the current caret position.
  445. Return Value:
  446. -2 : No further action necessary
  447. -1 : Perform default action for the keystroke
  448. >=0 : Indicates the default action should be performed on the index
  449. specified.
  450. --*/
  451. {
  452. switch(nKey)
  453. {
  454. case VK_DELETE:
  455. OnButtonRemove();
  456. break;
  457. case VK_INSERT:
  458. OnButtonAdd();
  459. break;
  460. default:
  461. //
  462. // Not completely handled by this function, let
  463. // windows handle the remaining default action.
  464. //
  465. return -1;
  466. }
  467. //
  468. // No further action is neccesary.
  469. //
  470. return -2;
  471. }