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.

250 lines
7.7 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  6. //
  7. // File: SaferLevelGeneral.cpp
  8. //
  9. // Contents: Implementation of CSaferLevelGeneral
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include <gpedit.h>
  14. #include <winsafer.h>
  15. #include <compdata.h>
  16. #include "SaferLevelGeneral.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CSaferLevelGeneral property page
  24. CSaferLevelGeneral::CSaferLevelGeneral(
  25. CSaferLevel& rSaferLevel,
  26. bool bReadOnly,
  27. LONG_PTR lNotifyHandle,
  28. LPDATAOBJECT pDataObject,
  29. DWORD dwDefaultSaferLevel,
  30. CCertMgrComponentData* pCompData)
  31. : CHelpPropertyPage(CSaferLevelGeneral::IDD),
  32. m_rSaferLevel (rSaferLevel),
  33. m_bReadOnly (bReadOnly),
  34. m_bSetAsDefault (false),
  35. m_lNotifyHandle (lNotifyHandle),
  36. m_bDirty (false),
  37. m_pDataObject (pDataObject),
  38. m_dwDefaultSaferLevel (dwDefaultSaferLevel),
  39. m_bFirst (true),
  40. m_bLevelChanged (false),
  41. m_pCompData (pCompData)
  42. {
  43. //{{AFX_DATA_INIT(CSaferLevelGeneral)
  44. // NOTE: the ClassWizard will add member initialization here
  45. //}}AFX_DATA_INIT
  46. m_rSaferLevel.IncrementOpenPageCount ();
  47. if ( m_pCompData )
  48. {
  49. m_pCompData->AddRef ();
  50. m_pCompData->IncrementOpenSaferPageCount ();
  51. }
  52. }
  53. CSaferLevelGeneral::~CSaferLevelGeneral()
  54. {
  55. if ( m_lNotifyHandle )
  56. {
  57. if ( m_bLevelChanged )
  58. {
  59. MMCPropertyChangeNotify (
  60. m_lNotifyHandle, // handle to a notification
  61. (LPARAM) m_pDataObject); // unique identifier
  62. }
  63. MMCFreeNotifyHandle (m_lNotifyHandle);
  64. }
  65. m_rSaferLevel.DecrementOpenPageCount ();
  66. if ( m_pCompData )
  67. {
  68. m_pCompData->DecrementOpenSaferPageCount ();
  69. m_pCompData->Release ();
  70. m_pCompData = 0;
  71. }
  72. }
  73. void CSaferLevelGeneral::DoDataExchange(CDataExchange* pDX)
  74. {
  75. CHelpPropertyPage::DoDataExchange(pDX);
  76. //{{AFX_DATA_MAP(CSaferLevelGeneral)
  77. // NOTE: the ClassWizard will add DDX and DDV calls here
  78. //}}AFX_DATA_MAP
  79. }
  80. BEGIN_MESSAGE_MAP(CSaferLevelGeneral, CHelpPropertyPage)
  81. //{{AFX_MSG_MAP(CSaferLevelGeneral)
  82. ON_BN_CLICKED(IDC_SAFER_LEVEL_SET_AS_DEFAULT, OnSaferLevelSetAsDefault)
  83. ON_EN_SETFOCUS(IDC_SAFER_LEVEL_DESCRIPTION, OnSetfocusSaferLevelDescription)
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CSaferLevelGeneral message handlers
  88. void CSaferLevelGeneral::DoContextHelp (HWND hWndControl)
  89. {
  90. _TRACE (1, L"Entering CSaferLevelGeneral::DoContextHelp\n");
  91. static const DWORD help_map[] =
  92. {
  93. IDC_SAFER_LEVEL_NAME, IDH_SAFER_LEVEL_NAME,
  94. IDC_SAFER_LEVEL_DESCRIPTION, IDH_SAFER_LEVEL_DESCRIPTION,
  95. IDC_SAFER_LEVEL_SET_AS_DEFAULT, IDH_SAFER_LEVEL_SET_AS_DEFAULT,
  96. IDC_SAFER_LEVEL_STATUS, IDH_SAFER_LEVEL_STATUS,
  97. 0, 0
  98. };
  99. if ( !::WinHelp (
  100. hWndControl,
  101. GetF1HelpFilename(),
  102. HELP_WM_HELP,
  103. (DWORD_PTR) help_map) )
  104. {
  105. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  106. }
  107. _TRACE (-1, L"Leaving CSaferLevelGeneral::DoContextHelp\n");
  108. }
  109. BOOL CSaferLevelGeneral::OnInitDialog()
  110. {
  111. CHelpPropertyPage::OnInitDialog();
  112. SetDlgItemText (IDC_SAFER_LEVEL_NAME, m_rSaferLevel.GetObjectName ());
  113. SetDlgItemText (IDC_SAFER_LEVEL_DESCRIPTION, m_rSaferLevel.GetDescription ());
  114. if ( m_rSaferLevel.IsDefault () )
  115. {
  116. m_bSetAsDefault = true;
  117. CString text;
  118. VERIFY (text.LoadString (IDS_IS_DEFAULT_LEVEL));
  119. SetDlgItemText (IDC_SAFER_LEVEL_STATUS, text);
  120. GetDlgItem (IDC_SAFER_LEVEL_SET_AS_DEFAULT)->EnableWindow (FALSE);
  121. GetDlgItem (IDC_LEVEL_INSTRUCTIONS)->EnableWindow (FALSE);
  122. }
  123. if ( m_bReadOnly || ( SAFER_LEVELID_DISALLOWED != m_rSaferLevel.GetLevel () &&
  124. SAFER_LEVELID_FULLYTRUSTED != m_rSaferLevel.GetLevel () &&
  125. SAFER_LEVELID_NORMALUSER != m_rSaferLevel.GetLevel () ) )
  126. {
  127. CString text;
  128. if ( SAFER_LEVELID_CONSTRAINED == m_rSaferLevel.GetLevel () )
  129. {
  130. VERIFY (text.LoadString (IDS_CANT_SET_CONSTRAINED_AS_DEFAULT));
  131. SetDlgItemText (IDC_LEVEL_INSTRUCTIONS, text);
  132. }
  133. GetDlgItem (IDC_SAFER_LEVEL_SET_AS_DEFAULT)->EnableWindow (FALSE);
  134. GetDlgItem (IDC_LEVEL_INSTRUCTIONS)->EnableWindow (FALSE);
  135. }
  136. return TRUE; // return TRUE unless you set the focus to a control
  137. // EXCEPTION: OCX Property Pages should return FALSE
  138. }
  139. BOOL CSaferLevelGeneral::OnApply ()
  140. {
  141. if ( !m_bReadOnly && m_bDirty )
  142. {
  143. HRESULT hr = S_OK;
  144. BOOL bResult = FALSE;
  145. if ( m_bSetAsDefault )
  146. hr = m_rSaferLevel.SetAsDefault ();
  147. if ( SUCCEEDED (hr) )
  148. {
  149. m_bLevelChanged = true;
  150. bResult = CHelpPropertyPage::OnApply ();
  151. }
  152. else
  153. {
  154. CString text;
  155. CString caption;
  156. CThemeContextActivator activator;
  157. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_EXTENSION_REGISTRY));
  158. text.FormatMessage (IDS_CANT_SET_AS_DEFAULT, m_rSaferLevel.GetObjectName (),
  159. GetSystemMessage (hr));
  160. MessageBox (text, caption, MB_ICONWARNING | MB_OK);
  161. }
  162. return bResult;
  163. }
  164. else
  165. return CHelpPropertyPage::OnApply ();
  166. }
  167. void CSaferLevelGeneral::OnSaferLevelSetAsDefault()
  168. {
  169. if ( !m_bSetAsDefault )
  170. {
  171. int iRet = IDYES;
  172. if ( m_rSaferLevel.GetLevel () < m_dwDefaultSaferLevel )
  173. {
  174. CString text;
  175. CString caption;
  176. CThemeContextActivator activator;
  177. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_EXTENSION_REGISTRY));
  178. VERIFY (text.LoadString (IDS_DEFAULT_LEVEL_CHANGE_WARNING));
  179. iRet = MessageBox (text, caption, MB_ICONWARNING | MB_YESNO);
  180. }
  181. if ( IDYES == iRet )
  182. {
  183. m_dwDefaultSaferLevel = m_rSaferLevel.GetLevel ();
  184. m_bDirty = true;
  185. m_bSetAsDefault = true;
  186. CString text;
  187. VERIFY (text.LoadString (IDS_IS_DEFAULT_LEVEL));
  188. SetDlgItemText (IDC_SAFER_LEVEL_STATUS, text);
  189. SetModified (TRUE);
  190. GetDlgItem (IDC_SAFER_LEVEL_SET_AS_DEFAULT)->EnableWindow (FALSE);
  191. }
  192. }
  193. }
  194. ///////////////////////////////////////////////////////////////////////////////
  195. // This method traps keyboard commands from the dialog, which has only
  196. // disabled controls, usually. That prevented the closing of the dialog
  197. // when the user pressed ESC.
  198. // 222693 SAFER: Pressing ESC doesn't dismiss SAFER Level dialogs
  199. ///////////////////////////////////////////////////////////////////////////////
  200. BOOL CSaferLevelGeneral::OnCommand(WPARAM wParam, LPARAM lParam)
  201. {
  202. WORD id = LOWORD (wParam);
  203. if ( IDCANCEL == id )
  204. {
  205. GetParent ()->SendMessage (WM_COMMAND, wParam, lParam);
  206. }
  207. return CHelpPropertyPage::OnCommand(wParam, lParam);
  208. }
  209. void CSaferLevelGeneral::OnSetfocusSaferLevelDescription()
  210. {
  211. if ( m_bFirst )
  212. {
  213. SendDlgItemMessage (IDC_SAFER_LEVEL_DESCRIPTION, EM_SETSEL, (WPARAM) 0, 0);
  214. m_bFirst = false;
  215. }
  216. }