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.

377 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. // File: GPEPage.cpp
  8. //
  9. // Contents: Implementation of CGPERootGeneralPage
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include <gpedit.h>
  14. #include "GPEPage.h"
  15. #include "storegpe.h"
  16. #include "CompData.h"
  17. #ifdef _DEBUG
  18. #ifndef ALPHA
  19. #define new DEBUG_NEW
  20. #endif
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. extern GUID g_guidExtension;
  25. extern GUID g_guidSnapin;
  26. extern GUID g_guidRegExt;
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CGPERootGeneralPage property page
  29. CGPERootGeneralPage::CGPERootGeneralPage(CCertMgrComponentData* pCompData,
  30. bool fIsComputerType) :
  31. CHelpPropertyPage(CGPERootGeneralPage::IDD),
  32. m_dwGPERootFlags (0),
  33. m_hUserRootFlagsKey (0),
  34. m_hGroupPolicyKey (0),
  35. m_pGPEInformation (pCompData->GetGPEInformation ()),
  36. m_fIsComputerType (fIsComputerType)
  37. {
  38. //{{AFX_DATA_INIT(CGPERootGeneralPage)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. if ( m_pGPEInformation )
  42. {
  43. m_pGPEInformation->AddRef ();
  44. HRESULT hResult = m_pGPEInformation->GetRegistryKey (GPO_SECTION_MACHINE,
  45. &m_hGroupPolicyKey);
  46. ASSERT (SUCCEEDED (hResult));
  47. if ( SUCCEEDED (hResult) )
  48. GPEGetUserRootFlags ();
  49. }
  50. else
  51. RSOPGetUserRootFlags (pCompData);
  52. }
  53. CGPERootGeneralPage::~CGPERootGeneralPage()
  54. {
  55. if ( m_hUserRootFlagsKey )
  56. ::RegCloseKey (m_hUserRootFlagsKey);
  57. if ( m_hGroupPolicyKey )
  58. ::RegCloseKey (m_hGroupPolicyKey);
  59. if ( m_pGPEInformation )
  60. m_pGPEInformation->Release ();
  61. }
  62. void CGPERootGeneralPage::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CHelpPropertyPage::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CGPERootGeneralPage)
  66. DDX_Control(pDX, IDC_ENABLE_USER_ROOT_STORE, m_enableUserRootStoreBtn);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CGPERootGeneralPage, CHelpPropertyPage)
  70. //{{AFX_MSG_MAP(CGPERootGeneralPage)
  71. ON_BN_CLICKED(IDC_ENABLE_USER_ROOT_STORE, OnEnableUserRootStore)
  72. ON_BN_CLICKED(IDC_SET_DISABLE_LM_AUTH_FLAG, OnSetDisableLmAuthFlag)
  73. ON_BN_CLICKED(IDC_UNSET_DISABLE_LM_AUTH_FLAG, OnUnsetDisableLmAuthFlag)
  74. ON_BN_CLICKED(IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG, OnUnsetDisableNtAuthRequiredFlag)
  75. ON_BN_CLICKED(IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG, OnSetDisableNtAuthRequiredFlag)
  76. //}}AFX_MSG_MAP
  77. END_MESSAGE_MAP()
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CGPERootGeneralPage message handlers
  80. BOOL CGPERootGeneralPage::OnInitDialog()
  81. {
  82. CHelpPropertyPage::OnInitDialog();
  83. // If this is the RSOP, make it read-only
  84. if ( !m_pGPEInformation )
  85. {
  86. // Make the page read-only
  87. m_enableUserRootStoreBtn.EnableWindow (FALSE);
  88. GetDlgItem (IDC_SET_DISABLE_LM_AUTH_FLAG)->EnableWindow (FALSE);
  89. GetDlgItem (IDC_UNSET_DISABLE_LM_AUTH_FLAG)->EnableWindow (FALSE);
  90. GetDlgItem (IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG)->EnableWindow (FALSE);
  91. GetDlgItem (IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG)->EnableWindow (FALSE);
  92. }
  93. if ( IsCurrentUserRootEnabled () )
  94. m_enableUserRootStoreBtn.SetCheck (BST_CHECKED);
  95. if ( m_dwGPERootFlags & CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG )
  96. SendDlgItemMessage (IDC_SET_DISABLE_LM_AUTH_FLAG, BM_SETCHECK, BST_CHECKED);
  97. else
  98. SendDlgItemMessage (IDC_UNSET_DISABLE_LM_AUTH_FLAG, BM_SETCHECK, BST_CHECKED);
  99. if ( m_dwGPERootFlags & CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG )
  100. SendDlgItemMessage (IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG, BM_SETCHECK, BST_CHECKED);
  101. else
  102. SendDlgItemMessage (IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG, BM_SETCHECK, BST_CHECKED);
  103. return TRUE; // return TRUE unless you set the focus to a control
  104. // EXCEPTION: OCX Property Pages should return FALSE
  105. }
  106. void CGPERootGeneralPage::OnOK()
  107. {
  108. if ( m_pGPEInformation )
  109. {
  110. SaveCheck ();
  111. CHelpPropertyPage::OnOK ();
  112. }
  113. }
  114. void CGPERootGeneralPage::SaveCheck()
  115. {
  116. ASSERT (m_pGPEInformation);
  117. if ( m_pGPEInformation )
  118. {
  119. bool bRetVal = false;
  120. if ( m_enableUserRootStoreBtn.GetCheck () == BST_CHECKED )
  121. bRetVal = SetGPEFlags ((DWORD) CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG, TRUE); // remove flag
  122. else
  123. bRetVal = SetGPEFlags ((DWORD) CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG, FALSE); // set flag
  124. if ( bRetVal )
  125. {
  126. if ( BST_CHECKED == SendDlgItemMessage (IDC_SET_DISABLE_LM_AUTH_FLAG, BM_GETCHECK) )
  127. bRetVal = SetGPEFlags ((DWORD) CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG, FALSE); // set flag
  128. else if ( BST_CHECKED == SendDlgItemMessage (IDC_UNSET_DISABLE_LM_AUTH_FLAG, BM_GETCHECK) )
  129. bRetVal = SetGPEFlags ((DWORD) CERT_PROT_ROOT_DISABLE_LM_AUTH_FLAG, TRUE); // remove flag
  130. }
  131. if ( bRetVal )
  132. {
  133. if ( BST_CHECKED == SendDlgItemMessage (IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG, BM_GETCHECK) )
  134. bRetVal = SetGPEFlags ((DWORD) CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG, FALSE); // set flag
  135. else if ( BST_CHECKED == SendDlgItemMessage (IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG, BM_GETCHECK) )
  136. bRetVal = SetGPEFlags ((DWORD) CERT_PROT_ROOT_DISABLE_NT_AUTH_REQUIRED_FLAG, TRUE); // remove flag
  137. }
  138. if ( bRetVal )
  139. {
  140. // TRUE means we're changing the machine policy only
  141. m_pGPEInformation->PolicyChanged (TRUE, TRUE, &g_guidExtension, &g_guidSnapin);
  142. m_pGPEInformation->PolicyChanged (TRUE, TRUE, &g_guidRegExt, &g_guidSnapin);
  143. }
  144. }
  145. }
  146. void CGPERootGeneralPage::OnEnableUserRootStore()
  147. {
  148. SetModified (TRUE);
  149. }
  150. void CGPERootGeneralPage::OnSetDisableLmAuthFlag()
  151. {
  152. SetModified (TRUE);
  153. }
  154. bool CGPERootGeneralPage::SetGPEFlags (DWORD dwFlags, BOOL bRemoveFlag)
  155. {
  156. bool bRetVal = false;
  157. ASSERT (m_pGPEInformation);
  158. if ( m_pGPEInformation )
  159. {
  160. DWORD dwType = REG_DWORD;
  161. DWORD dwData = 0;
  162. DWORD cbData = sizeof (dwData);
  163. // security review 2/27/2002 BryanWal ok
  164. LONG lResult = ::RegQueryValueEx (m_hUserRootFlagsKey, // handle of key to query
  165. CERT_PROT_ROOT_FLAGS_VALUE_NAME, // address of name of value to query
  166. 0, // reserved
  167. &dwType, // address of buffer for value type
  168. (LPBYTE) &dwData, // address of data buffer
  169. &cbData); // address of data buffer size);
  170. ASSERT (ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult);
  171. if ( ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult )
  172. {
  173. if ( ERROR_SUCCESS == lResult && REG_DWORD != dwType )
  174. {
  175. ASSERT (0);
  176. return false;
  177. }
  178. if ( bRemoveFlag )
  179. dwData &= ~dwFlags;
  180. else
  181. dwData |= dwFlags;
  182. lResult = ::RegSetValueEx (m_hUserRootFlagsKey,
  183. CERT_PROT_ROOT_FLAGS_VALUE_NAME, // address of value to set
  184. 0, // reserved
  185. REG_DWORD, // flag for value type
  186. (CONST BYTE *) &dwData, // address of value data
  187. cbData); // size of value data);
  188. ASSERT (ERROR_SUCCESS == lResult);
  189. if ( ERROR_SUCCESS == lResult )
  190. {
  191. m_dwGPERootFlags = dwData;
  192. bRetVal = true;
  193. }
  194. else
  195. DisplaySystemError (m_hWnd, lResult);
  196. }
  197. else
  198. DisplaySystemError (m_hWnd, lResult);
  199. }
  200. return bRetVal;
  201. }
  202. bool CGPERootGeneralPage::IsCurrentUserRootEnabled() const
  203. {
  204. if (m_dwGPERootFlags & CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG)
  205. return false;
  206. else
  207. return true;
  208. }
  209. void CGPERootGeneralPage::RSOPGetUserRootFlags(const CCertMgrComponentData* pCompData)
  210. {
  211. if ( pCompData )
  212. {
  213. const CRSOPObjectArray* pObjectArray = m_fIsComputerType ?
  214. pCompData->GetRSOPObjectArrayComputer () :
  215. pCompData->GetRSOPObjectArrayUser ();
  216. int nIndex = 0;
  217. // NOTE: rsop object array is sorted first by registry key, then by precedence
  218. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  219. while ( nUpperBound >= nIndex )
  220. {
  221. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  222. if ( pObject )
  223. {
  224. // Consider only entries from this store
  225. // security review 2/27/2002 BryanWal ok
  226. if ( !wcscmp (CERT_PROT_ROOT_FLAGS_REGPATH, pObject->GetRegistryKey ()) )
  227. {
  228. ASSERT (1 == pObject->GetPrecedence ());
  229. m_dwGPERootFlags = pObject->GetDWORDValue ();
  230. break;
  231. }
  232. }
  233. else
  234. break;
  235. nIndex++;
  236. }
  237. }
  238. }
  239. void CGPERootGeneralPage::GPEGetUserRootFlags()
  240. {
  241. DWORD dwDisposition = 0;
  242. // security review 2/27/2002 BryanWal ok
  243. LONG lResult = ::RegCreateKeyEx (m_hGroupPolicyKey, // handle of an open key
  244. CERT_PROT_ROOT_FLAGS_REGPATH, // address of subkey name
  245. 0, // reserved
  246. L"", // address of class string
  247. REG_OPTION_NON_VOLATILE, // special options flag
  248. KEY_QUERY_VALUE | KEY_SET_VALUE, // desired security access
  249. NULL, // address of key security structure
  250. &m_hUserRootFlagsKey, // address of buffer for opened handle
  251. &dwDisposition); // address of disposition value buffer
  252. ASSERT (lResult == ERROR_SUCCESS);
  253. if ( lResult == ERROR_SUCCESS )
  254. {
  255. // Read value
  256. DWORD dwType = REG_DWORD;
  257. DWORD dwData = 0;
  258. DWORD cbData = sizeof (dwData);
  259. // security review 2/27/2002 BryanWal ok
  260. lResult = ::RegQueryValueEx (m_hUserRootFlagsKey, // handle of key to query
  261. CERT_PROT_ROOT_FLAGS_VALUE_NAME, // address of name of value to query
  262. 0, // reserved
  263. &dwType, // address of buffer for value type
  264. (LPBYTE) &dwData, // address of data buffer
  265. &cbData); // address of data buffer size);
  266. ASSERT (ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult);
  267. if ( ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult )
  268. {
  269. if ( REG_DWORD == dwType )
  270. {
  271. m_dwGPERootFlags = dwData;
  272. }
  273. }
  274. else
  275. DisplaySystemError (NULL, lResult);
  276. }
  277. else
  278. DisplaySystemError (NULL, lResult);
  279. }
  280. void CGPERootGeneralPage::DoContextHelp (HWND hWndControl)
  281. {
  282. _TRACE (1, L"Entering CGPERootGeneralPage::DoContextHelp\n");
  283. static const DWORD help_map[] =
  284. {
  285. IDC_ENABLE_USER_ROOT_STORE, IDH_GPEPAGE_ENABLE_USER_ROOT_STORE,
  286. IDC_SET_DISABLE_LM_AUTH_FLAG, IDH_SET_DISABLE_LM_AUTH_FLAG,
  287. IDC_UNSET_DISABLE_LM_AUTH_FLAG, IDH_UNSET_DISABLE_LM_AUTH_FLAG,
  288. IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG, IDH_SET_DISABLE_NT_AUTH_REQUIRED_FLAG,
  289. IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG, IDH_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG,
  290. 0, 0
  291. };
  292. switch (::GetDlgCtrlID (hWndControl))
  293. {
  294. case IDC_ENABLE_USER_ROOT_STORE:
  295. case IDC_SET_DISABLE_LM_AUTH_FLAG:
  296. case IDC_UNSET_DISABLE_LM_AUTH_FLAG:
  297. case IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG:
  298. case IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG:
  299. if ( !::WinHelp (
  300. hWndControl,
  301. GetF1HelpFilename(),
  302. HELP_WM_HELP,
  303. (DWORD_PTR) help_map) )
  304. {
  305. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  306. }
  307. break;
  308. default:
  309. break;
  310. }
  311. _TRACE (-1, L"Leaving CGPERootGeneralPage::DoContextHelp\n");
  312. }
  313. void CGPERootGeneralPage::OnUnsetDisableLmAuthFlag()
  314. {
  315. SetModified (TRUE);
  316. }
  317. void CGPERootGeneralPage::OnUnsetDisableNtAuthRequiredFlag()
  318. {
  319. SetModified (TRUE);
  320. }
  321. void CGPERootGeneralPage::OnSetDisableNtAuthRequiredFlag()
  322. {
  323. SetModified (TRUE);
  324. }