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.

293 lines
9.9 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  6. //
  7. // File: SaferEntryInternetZonePropertyPage.cpp
  8. //
  9. // Contents: Implementation of CSaferEntryInternetZonePropertyPage
  10. //
  11. //----------------------------------------------------------------------------
  12. // SaferEntryInternetZonePropertyPage.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include <gpedit.h>
  16. #include "certmgr.h"
  17. #include "compdata.h"
  18. #include "SaferEntryInternetZonePropertyPage.h"
  19. #include "SaferUtil.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CSaferEntryInternetZonePropertyPage property page
  27. CSaferEntryInternetZonePropertyPage::CSaferEntryInternetZonePropertyPage(
  28. CSaferEntry& rSaferEntry,
  29. bool bNew,
  30. LONG_PTR lNotifyHandle,
  31. LPDATAOBJECT pDataObject,
  32. bool bReadOnly,
  33. CCertMgrComponentData* pCompData,
  34. bool bIsMachine,
  35. bool* pbObjectCreated /* = 0 */)
  36. : CSaferPropertyPage(CSaferEntryInternetZonePropertyPage::IDD, pbObjectCreated,
  37. pCompData, rSaferEntry, bNew, lNotifyHandle, pDataObject, bReadOnly,
  38. bIsMachine)
  39. {
  40. //{{AFX_DATA_INIT(CSaferEntryInternetZonePropertyPage)
  41. // NOTE: the ClassWizard will add member initialization here
  42. //}}AFX_DATA_INIT
  43. }
  44. CSaferEntryInternetZonePropertyPage::~CSaferEntryInternetZonePropertyPage()
  45. {
  46. }
  47. void CSaferEntryInternetZonePropertyPage::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CSaferPropertyPage::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(CSaferEntryInternetZonePropertyPage)
  51. DDX_Control(pDX, IDC_IZONE_ENTRY_ZONES, m_internetZoneCombo);
  52. DDX_Control(pDX, IDC_IZONE_ENTRY_SECURITY_LEVEL, m_securityLevelCombo);
  53. //}}AFX_DATA_MAP
  54. }
  55. BEGIN_MESSAGE_MAP(CSaferEntryInternetZonePropertyPage, CSaferPropertyPage)
  56. //{{AFX_MSG_MAP(CSaferEntryInternetZonePropertyPage)
  57. ON_CBN_SELCHANGE(IDC_IZONE_ENTRY_SECURITY_LEVEL, OnSelchangeIzoneEntrySecurityLevel)
  58. ON_CBN_SELCHANGE(IDC_IZONE_ENTRY_ZONES, OnSelchangeIzoneEntryZones)
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CSaferEntryInternetZonePropertyPage message handlers
  63. BOOL CSaferEntryInternetZonePropertyPage::OnInitDialog()
  64. {
  65. CSaferPropertyPage::OnInitDialog();
  66. // Set up User Notification combo box
  67. DWORD dwFlags = 0;
  68. m_rSaferEntry.GetFlags (dwFlags);
  69. ASSERT (m_pCompData);
  70. if ( m_pCompData )
  71. {
  72. CPolicyKey policyKey (m_pCompData->m_pGPEInformation,
  73. SAFER_HKLM_REGBASE,
  74. m_bIsMachine);
  75. InitializeSecurityLevelComboBox (m_securityLevelCombo, false,
  76. m_rSaferEntry.GetLevel (), policyKey.GetKey (),
  77. m_pCompData->m_pdwSaferLevels,
  78. m_bIsMachine);
  79. InitializeInternetZoneComboBox (m_rSaferEntry.GetURLZoneID ());
  80. SendDlgItemMessage (IDC_IZONE_ENTRY_DESCRIPTION, EM_LIMITTEXT, SAFER_MAX_DESCRIPTION_SIZE-1, 0);
  81. SetDlgItemText (IDC_IZONE_ENTRY_DESCRIPTION, m_rSaferEntry.GetDescription ());
  82. SetDlgItemText (IDC_IZONE_ENTRY_LAST_MODIFIED, m_rSaferEntry.GetLongLastModified ());
  83. if ( m_bReadOnly )
  84. {
  85. m_securityLevelCombo.EnableWindow (FALSE);
  86. m_internetZoneCombo.EnableWindow (FALSE);
  87. }
  88. if ( !m_bDirty )
  89. {
  90. CString szText;
  91. VERIFY (szText.LoadString (IDS_URLZONE_TITLE));
  92. SetDlgItemText (IDC_URLZONE_TITLE, szText);
  93. }
  94. else
  95. {
  96. GetDlgItem (IDC_DATE_LAST_MODIFIED_LABEL)->ShowWindow (SW_HIDE);
  97. GetDlgItem (IDC_IZONE_ENTRY_LAST_MODIFIED)->ShowWindow (SW_HIDE);
  98. }
  99. }
  100. return TRUE; // return TRUE unless you set the focus to a control
  101. // EXCEPTION: OCX Property Pages should return FALSE
  102. }
  103. void CSaferEntryInternetZonePropertyPage::InitializeInternetZoneComboBox (DWORD UrlZoneId)
  104. {
  105. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  106. CString szText;
  107. VERIFY (szText.LoadString (IDS_URLZONE_LOCAL_MACHINE));
  108. int nItem = m_internetZoneCombo.AddString (szText);
  109. ASSERT (nItem >= 0);
  110. if ( nItem >= 0 )
  111. {
  112. if ( URLZONE_LOCAL_MACHINE == UrlZoneId )
  113. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  114. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_LOCAL_MACHINE));
  115. }
  116. VERIFY (szText.LoadString (IDS_URLZONE_INTRANET));
  117. nItem = m_internetZoneCombo.AddString (szText);
  118. ASSERT (nItem >= 0);
  119. if ( nItem >= 0 )
  120. {
  121. if ( URLZONE_INTRANET == UrlZoneId )
  122. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  123. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_INTRANET));
  124. }
  125. VERIFY (szText.LoadString (IDS_URLZONE_TRUSTED));
  126. nItem = m_internetZoneCombo.AddString (szText);
  127. ASSERT (nItem >= 0);
  128. if ( nItem >= 0 )
  129. {
  130. if ( URLZONE_TRUSTED == UrlZoneId )
  131. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  132. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_TRUSTED));
  133. }
  134. VERIFY (szText.LoadString (IDS_URLZONE_INTERNET));
  135. nItem = m_internetZoneCombo.AddString (szText);
  136. ASSERT (nItem >= 0);
  137. if ( nItem >= 0 )
  138. {
  139. if ( URLZONE_INTERNET == UrlZoneId )
  140. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  141. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_INTERNET));
  142. }
  143. VERIFY (szText.LoadString (IDS_URLZONE_UNTRUSTED));
  144. nItem = m_internetZoneCombo.AddString (szText);
  145. ASSERT (nItem >= 0);
  146. if ( nItem >= 0 )
  147. {
  148. if ( URLZONE_UNTRUSTED == UrlZoneId )
  149. VERIFY (CB_ERR != m_internetZoneCombo.SetCurSel (nItem));
  150. VERIFY (CB_ERR != m_internetZoneCombo.SetItemData (nItem, URLZONE_UNTRUSTED));
  151. }
  152. }
  153. void CSaferEntryInternetZonePropertyPage::DoContextHelp (HWND hWndControl)
  154. {
  155. _TRACE (1, L"Entering CSaferEntryInternetZonePropertyPage::DoContextHelp\n");
  156. static const DWORD help_map[] =
  157. {
  158. IDC_IZONE_ENTRY_ZONES, IDH_IZONE_ENTRY_ZONES,
  159. IDC_IZONE_ENTRY_SECURITY_LEVEL, IDH_IZONE_ENTRY_SECURITY_LEVEL,
  160. IDC_IZONE_ENTRY_DESCRIPTION, IDH_IZONE_ENTRY_DESCRIPTION,
  161. IDC_IZONE_ENTRY_LAST_MODIFIED, IDH_IZONE_ENTRY_LAST_MODIFIED,
  162. 0, 0
  163. };
  164. switch (::GetDlgCtrlID (hWndControl))
  165. {
  166. case IDC_IZONE_ENTRY_ZONES:
  167. case IDC_IZONE_ENTRY_SECURITY_LEVEL:
  168. case IDC_IZONE_ENTRY_DESCRIPTION:
  169. case IDC_IZONE_ENTRY_LAST_MODIFIED:
  170. if ( !::WinHelp (
  171. hWndControl,
  172. GetF1HelpFilename(),
  173. HELP_WM_HELP,
  174. (DWORD_PTR) help_map) )
  175. {
  176. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  177. }
  178. break;
  179. default:
  180. break;
  181. }
  182. _TRACE (-1, L"Leaving CSaferEntryInternetZonePropertyPage::DoContextHelp\n");
  183. }
  184. BOOL CSaferEntryInternetZonePropertyPage::OnApply()
  185. {
  186. if ( m_bDirty && !m_bReadOnly )
  187. {
  188. // Set the level
  189. int nCurSel = m_securityLevelCombo.GetCurSel ();
  190. ASSERT (CB_ERR != nCurSel);
  191. m_rSaferEntry.SetLevel ((DWORD) m_securityLevelCombo.GetItemData (nCurSel));
  192. int nSel = m_internetZoneCombo.GetCurSel ();
  193. ASSERT (CB_ERR != nSel);
  194. if ( CB_ERR != nSel )
  195. {
  196. DWORD_PTR dwURLZoneID = m_internetZoneCombo.GetItemData (nSel);
  197. ASSERT (CB_ERR != dwURLZoneID);
  198. if ( CB_ERR != dwURLZoneID )
  199. m_rSaferEntry.SetURLZoneID ((DWORD) dwURLZoneID);
  200. }
  201. HRESULT hr = m_rSaferEntry.Save ();
  202. if ( SUCCEEDED (hr) )
  203. {
  204. if ( m_lNotifyHandle )
  205. MMCPropertyChangeNotify (
  206. m_lNotifyHandle, // handle to a notification
  207. (LPARAM) m_pDataObject); // unique identifier
  208. if ( m_pbObjectCreated )
  209. *m_pbObjectCreated = true;
  210. m_rSaferEntry.Refresh ();
  211. GetDlgItem (IDC_DATE_LAST_MODIFIED_LABEL)->ShowWindow (SW_SHOW);
  212. GetDlgItem (IDC_IZONE_ENTRY_LAST_MODIFIED)->ShowWindow (SW_SHOW);
  213. GetDlgItem (IDC_DATE_LAST_MODIFIED_LABEL)->UpdateWindow ();
  214. GetDlgItem (IDC_IZONE_ENTRY_LAST_MODIFIED)->UpdateWindow ();
  215. SetDlgItemText (IDC_IZONE_ENTRY_LAST_MODIFIED, m_rSaferEntry.GetLongLastModified ());
  216. m_bDirty = false;
  217. }
  218. else
  219. {
  220. CString text;
  221. CString caption;
  222. CThemeContextActivator activator;
  223. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_NODE_NAME));
  224. text.FormatMessage (IDS_ERROR_SAVING_ENTRY, GetSystemMessage (hr));
  225. MessageBox (text, caption, MB_OK);
  226. return FALSE;
  227. }
  228. }
  229. return CSaferPropertyPage::OnApply();
  230. }
  231. void CSaferEntryInternetZonePropertyPage::OnSelchangeIzoneEntrySecurityLevel()
  232. {
  233. m_bDirty = true;
  234. SetModified ();
  235. }
  236. void CSaferEntryInternetZonePropertyPage::OnSelchangeIzoneEntryZones()
  237. {
  238. int nSel = m_internetZoneCombo.GetCurSel ();
  239. ASSERT (CB_ERR != nSel);
  240. if ( CB_ERR != nSel )
  241. {
  242. DWORD_PTR dwURLZoneID = m_internetZoneCombo.GetItemData (nSel);
  243. ASSERT (CB_ERR != dwURLZoneID);
  244. if ( CB_ERR != dwURLZoneID )
  245. m_rSaferEntry.SetURLZoneID ((DWORD) dwURLZoneID);
  246. }
  247. SetDlgItemText (IDC_IZONE_ENTRY_DESCRIPTION, m_rSaferEntry.GetDescription ());
  248. m_bDirty = true;
  249. SetModified ();
  250. }