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.

351 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1997-2001.
  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. VERIFY (ERROR_SUCCESS == ::RegCloseKey (m_hUserRootFlagsKey));
  57. if ( m_hGroupPolicyKey )
  58. VERIFY (::RegCloseKey (m_hGroupPolicyKey) == ERROR_SUCCESS);
  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. LONG lResult = ::RegQueryValueEx (m_hUserRootFlagsKey, // handle of key to query
  164. CERT_PROT_ROOT_FLAGS_VALUE_NAME, // address of name of value to query
  165. 0, // reserved
  166. &dwType, // address of buffer for value type
  167. (LPBYTE) &dwData, // address of data buffer
  168. &cbData); // address of data buffer size);
  169. ASSERT (ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult);
  170. if ( ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult )
  171. {
  172. if ( bRemoveFlag )
  173. dwData &= ~dwFlags;
  174. else
  175. dwData |= dwFlags;
  176. lResult = ::RegSetValueEx (m_hUserRootFlagsKey,
  177. CERT_PROT_ROOT_FLAGS_VALUE_NAME, // address of value to set
  178. 0, // reserved
  179. REG_DWORD, // flag for value type
  180. (CONST BYTE *) &dwData, // address of value data
  181. cbData); // size of value data);
  182. ASSERT (ERROR_SUCCESS == lResult);
  183. if ( ERROR_SUCCESS == lResult )
  184. {
  185. m_dwGPERootFlags = dwData;
  186. bRetVal = true;
  187. }
  188. else
  189. DisplaySystemError (m_hWnd, lResult);
  190. }
  191. else
  192. DisplaySystemError (m_hWnd, lResult);
  193. }
  194. return bRetVal;
  195. }
  196. bool CGPERootGeneralPage::IsCurrentUserRootEnabled() const
  197. {
  198. if (m_dwGPERootFlags & CERT_PROT_ROOT_DISABLE_CURRENT_USER_FLAG)
  199. return false;
  200. else
  201. return true;
  202. }
  203. void CGPERootGeneralPage::RSOPGetUserRootFlags(const CCertMgrComponentData* pCompData)
  204. {
  205. if ( pCompData )
  206. {
  207. const CRSOPObjectArray* pObjectArray = m_fIsComputerType ?
  208. pCompData->GetRSOPObjectArrayComputer () :
  209. pCompData->GetRSOPObjectArrayUser ();
  210. int nIndex = 0;
  211. // NOTE: rsop object array is sorted first by registry key, then by precedence
  212. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  213. while ( nUpperBound >= nIndex )
  214. {
  215. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  216. if ( pObject )
  217. {
  218. // Consider only entries from this store
  219. if ( !wcscmp (CERT_PROT_ROOT_FLAGS_REGPATH, pObject->GetRegistryKey ()) )
  220. {
  221. ASSERT (1 == pObject->GetPrecedence ());
  222. m_dwGPERootFlags = pObject->GetDWORDValue ();
  223. break;
  224. }
  225. }
  226. else
  227. break;
  228. nIndex++;
  229. }
  230. }
  231. }
  232. void CGPERootGeneralPage::GPEGetUserRootFlags()
  233. {
  234. DWORD dwDisposition = 0;
  235. LONG lResult = ::RegCreateKeyEx (m_hGroupPolicyKey, // handle of an open key
  236. CERT_PROT_ROOT_FLAGS_REGPATH, // address of subkey name
  237. 0, // reserved
  238. L"", // address of class string
  239. REG_OPTION_NON_VOLATILE, // special options flag
  240. KEY_ALL_ACCESS, // desired security access
  241. NULL, // address of key security structure
  242. &m_hUserRootFlagsKey, // address of buffer for opened handle
  243. &dwDisposition); // address of disposition value buffer
  244. ASSERT (lResult == ERROR_SUCCESS);
  245. if ( lResult == ERROR_SUCCESS )
  246. {
  247. // Read value
  248. DWORD dwType = REG_DWORD;
  249. DWORD dwData = 0;
  250. DWORD cbData = sizeof (dwData);
  251. lResult = ::RegQueryValueEx (m_hUserRootFlagsKey, // handle of key to query
  252. CERT_PROT_ROOT_FLAGS_VALUE_NAME, // address of name of value to query
  253. 0, // reserved
  254. &dwType, // address of buffer for value type
  255. (LPBYTE) &dwData, // address of data buffer
  256. &cbData); // address of data buffer size);
  257. ASSERT (ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult);
  258. if ( ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult )
  259. {
  260. m_dwGPERootFlags = dwData;
  261. }
  262. else
  263. DisplaySystemError (NULL, lResult);
  264. }
  265. else
  266. DisplaySystemError (NULL, lResult);
  267. }
  268. void CGPERootGeneralPage::DoContextHelp (HWND hWndControl)
  269. {
  270. _TRACE (1, L"Entering CGPERootGeneralPage::DoContextHelp\n");
  271. static const DWORD help_map[] =
  272. {
  273. IDC_ENABLE_USER_ROOT_STORE, IDH_GPEPAGE_ENABLE_USER_ROOT_STORE,
  274. IDC_SET_DISABLE_LM_AUTH_FLAG, IDH_SET_DISABLE_LM_AUTH_FLAG,
  275. IDC_UNSET_DISABLE_LM_AUTH_FLAG, IDH_UNSET_DISABLE_LM_AUTH_FLAG,
  276. IDC_SET_DISABLE_NT_AUTH_REQUIRED_FLAG, IDH_SET_DISABLE_NT_AUTH_REQUIRED_FLAG,
  277. IDC_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG, IDH_UNSET_DISABLE_NT_AUTH_REQUIRED_FLAG,
  278. 0, 0
  279. };
  280. if ( !::WinHelp (
  281. hWndControl,
  282. GetF1HelpFilename(),
  283. HELP_WM_HELP,
  284. (DWORD_PTR) help_map) )
  285. {
  286. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  287. }
  288. _TRACE (-1, L"Leaving CGPERootGeneralPage::DoContextHelp\n");
  289. }
  290. void CGPERootGeneralPage::OnUnsetDisableLmAuthFlag()
  291. {
  292. SetModified (TRUE);
  293. }
  294. void CGPERootGeneralPage::OnUnsetDisableNtAuthRequiredFlag()
  295. {
  296. SetModified (TRUE);
  297. }
  298. void CGPERootGeneralPage::OnSetDisableNtAuthRequiredFlag()
  299. {
  300. SetModified (TRUE);
  301. }