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.

304 lines
10 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. // File: AutoenrollmentPropertyPage.cpp
  8. //
  9. // Contents: Implementation of CAutoenrollmentPropertyPage
  10. //
  11. //----------------------------------------------------------------------------
  12. // AutoenrollmentPropertyPage.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #include <gpedit.h>
  16. #include "AutoenrollmentPropertyPage.h"
  17. #include "compdata.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. extern GUID g_guidExtension;
  24. extern GUID g_guidRegExt;
  25. extern GUID g_guidSnapin;
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CAutoenrollmentPropertyPage property page
  28. CAutoenrollmentPropertyPage::CAutoenrollmentPropertyPage(CCertMgrComponentData* pCompData,
  29. bool fIsComputerType) :
  30. CHelpPropertyPage(CAutoenrollmentPropertyPage::IDD),
  31. m_dwAutoenrollmentFlags (0),
  32. m_hAutoenrollmentFlagsKey (0),
  33. m_hGroupPolicyKey (0),
  34. m_pGPEInformation (pCompData ? pCompData->GetGPEInformation () : 0),
  35. m_fIsComputerType (fIsComputerType)
  36. {
  37. if ( m_pGPEInformation )
  38. {
  39. HRESULT hResult = m_pGPEInformation->GetRegistryKey (m_fIsComputerType ?
  40. GPO_SECTION_MACHINE : GPO_SECTION_USER,
  41. &m_hGroupPolicyKey);
  42. ASSERT (SUCCEEDED (hResult));
  43. if ( SUCCEEDED (hResult) )
  44. GPEGetAutoenrollmentFlags ();
  45. }
  46. else
  47. RSOPGetAutoenrollmentFlags (pCompData);
  48. }
  49. CAutoenrollmentPropertyPage::~CAutoenrollmentPropertyPage()
  50. {
  51. if ( m_hAutoenrollmentFlagsKey )
  52. ::RegCloseKey (m_hAutoenrollmentFlagsKey);
  53. }
  54. void CAutoenrollmentPropertyPage::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CHelpPropertyPage::DoDataExchange(pDX);
  57. //{{AFX_DATA_MAP(CAutoenrollmentPropertyPage)
  58. // NOTE: the ClassWizard will add DDX and DDV calls here
  59. //}}AFX_DATA_MAP
  60. }
  61. BEGIN_MESSAGE_MAP(CAutoenrollmentPropertyPage, CHelpPropertyPage)
  62. //{{AFX_MSG_MAP(CAutoenrollmentPropertyPage)
  63. ON_BN_CLICKED(IDC_AUTOENROLL_DISABLE_ALL, OnAutoenrollDisableAll)
  64. ON_BN_CLICKED(IDC_AUTOENROLL_ENABLE, OnAutoenrollEnable)
  65. ON_BN_CLICKED(IDC_AUTOENROLL_ENABLE_PENDING, OnAutoenrollEnablePending)
  66. ON_BN_CLICKED(IDC_AUTOENROLL_ENABLE_TEMPLATE, OnAutoenrollEnableTemplate)
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CAutoenrollmentPropertyPage message handlers
  71. BOOL CAutoenrollmentPropertyPage::OnInitDialog()
  72. {
  73. CHelpPropertyPage::OnInitDialog();
  74. // If this is the RSOP, make it read-only
  75. if ( !m_pGPEInformation )
  76. {
  77. // Make the page read-only
  78. GetDlgItem (IDC_AUTOENROLL_DISABLE_ALL)->EnableWindow (FALSE);
  79. GetDlgItem (IDC_AUTOENROLL_ENABLE)->EnableWindow (FALSE);
  80. GetDlgItem (IDC_AUTOENROLL_ENABLE_PENDING)->EnableWindow (FALSE);
  81. GetDlgItem (IDC_AUTOENROLL_ENABLE_TEMPLATE)->EnableWindow (FALSE);
  82. }
  83. if ( m_dwAutoenrollmentFlags & AUTO_ENROLLMENT_DISABLE_ALL )
  84. SendDlgItemMessage (IDC_AUTOENROLL_DISABLE_ALL, BM_SETCHECK, BST_CHECKED);
  85. else
  86. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE, BM_SETCHECK, BST_CHECKED);
  87. if ( m_dwAutoenrollmentFlags & (AUTO_ENROLLMENT_ENABLE_MY_STORE_MANAGEMENT | AUTO_ENROLLMENT_ENABLE_PENDING_FETCH) )
  88. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_PENDING, BM_SETCHECK, BST_CHECKED);
  89. if ( m_dwAutoenrollmentFlags & AUTO_ENROLLMENT_ENABLE_TEMPLATE_CHECK )
  90. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_TEMPLATE, BM_SETCHECK, BST_CHECKED);
  91. EnableControls ();
  92. return TRUE; // return TRUE unless you set the focus to a control
  93. // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. void CAutoenrollmentPropertyPage::OnOK()
  96. {
  97. if ( m_pGPEInformation )
  98. {
  99. SaveCheck ();
  100. CHelpPropertyPage::OnOK ();
  101. }
  102. }
  103. void CAutoenrollmentPropertyPage::SaveCheck()
  104. {
  105. ASSERT (m_pGPEInformation);
  106. if ( m_pGPEInformation )
  107. {
  108. m_dwAutoenrollmentFlags = 0;
  109. if ( BST_CHECKED == SendDlgItemMessage (IDC_AUTOENROLL_DISABLE_ALL, BM_GETCHECK) )
  110. m_dwAutoenrollmentFlags |= AUTO_ENROLLMENT_DISABLE_ALL;
  111. else
  112. {
  113. if ( BST_CHECKED == SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_PENDING, BM_GETCHECK) )
  114. m_dwAutoenrollmentFlags |= AUTO_ENROLLMENT_ENABLE_MY_STORE_MANAGEMENT | AUTO_ENROLLMENT_ENABLE_PENDING_FETCH;
  115. if ( BST_CHECKED == SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_TEMPLATE, BM_GETCHECK) )
  116. m_dwAutoenrollmentFlags |= AUTO_ENROLLMENT_ENABLE_TEMPLATE_CHECK;
  117. }
  118. SetGPEFlags (); // save flag to registry
  119. }
  120. }
  121. void CAutoenrollmentPropertyPage::SetGPEFlags ()
  122. {
  123. ASSERT (m_pGPEInformation);
  124. if ( m_pGPEInformation )
  125. {
  126. DWORD cbData = sizeof (m_dwAutoenrollmentFlags);
  127. LONG lResult = ::RegSetValueEx (m_hAutoenrollmentFlagsKey,
  128. AUTO_ENROLLMENT_POLICY, // address of value to set
  129. 0, // reserved
  130. REG_DWORD, // flag for value type
  131. (CONST BYTE *) &m_dwAutoenrollmentFlags, // address of value data
  132. cbData); // size of value data);
  133. ASSERT (ERROR_SUCCESS == lResult);
  134. if ( ERROR_SUCCESS == lResult )
  135. {
  136. // TRUE means we're changing the machine policy only
  137. m_pGPEInformation->PolicyChanged (m_fIsComputerType ? TRUE : FALSE,
  138. TRUE, &g_guidExtension, &g_guidSnapin);
  139. m_pGPEInformation->PolicyChanged (m_fIsComputerType ? TRUE : FALSE,
  140. TRUE, &g_guidRegExt, &g_guidSnapin);
  141. }
  142. else
  143. DisplaySystemError (m_hWnd, lResult);
  144. }
  145. }
  146. void CAutoenrollmentPropertyPage::RSOPGetAutoenrollmentFlags(const CCertMgrComponentData* pCompData)
  147. {
  148. if ( pCompData )
  149. {
  150. const CRSOPObjectArray* pObjectArray =
  151. m_fIsComputerType ? pCompData->GetRSOPObjectArrayComputer () :
  152. pCompData->GetRSOPObjectArrayUser ();
  153. int nIndex = 0;
  154. // NOTE: rsop object array is sorted first by registry key, then by precedence
  155. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  156. while ( nUpperBound >= nIndex )
  157. {
  158. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  159. if ( pObject )
  160. {
  161. // Consider only entries from this store
  162. if ( !_wcsicmp (AUTO_ENROLLMENT_KEY, pObject->GetRegistryKey ()) &&
  163. !_wcsicmp (AUTO_ENROLLMENT_POLICY, pObject->GetValueName ()) )
  164. {
  165. ASSERT (1 == pObject->GetPrecedence ());
  166. m_dwAutoenrollmentFlags = pObject->GetDWORDValue ();
  167. break;
  168. }
  169. }
  170. else
  171. break;
  172. nIndex++;
  173. }
  174. }
  175. }
  176. void CAutoenrollmentPropertyPage::GPEGetAutoenrollmentFlags()
  177. {
  178. DWORD dwDisposition = 0;
  179. LONG lResult = ::RegCreateKeyEx (m_hGroupPolicyKey, // handle of an open key
  180. AUTO_ENROLLMENT_KEY, // address of subkey name
  181. 0, // reserved
  182. L"", // address of class string
  183. REG_OPTION_NON_VOLATILE, // special options flag
  184. KEY_ALL_ACCESS, // desired security access
  185. NULL, // address of key security structure
  186. &m_hAutoenrollmentFlagsKey, // address of buffer for opened handle
  187. &dwDisposition); // address of disposition value buffer
  188. ASSERT (lResult == ERROR_SUCCESS);
  189. if ( lResult == ERROR_SUCCESS )
  190. {
  191. // Read value
  192. DWORD dwType = REG_DWORD;
  193. DWORD dwData = 0;
  194. DWORD cbData = sizeof (dwData);
  195. lResult = ::RegQueryValueEx (m_hAutoenrollmentFlagsKey, // handle of key to query
  196. AUTO_ENROLLMENT_POLICY, // address of name of value to query
  197. 0, // reserved
  198. &dwType, // address of buffer for value type
  199. (LPBYTE) &dwData, // address of data buffer
  200. &cbData); // address of data buffer size);
  201. ASSERT (ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult);
  202. if ( ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult )
  203. {
  204. m_dwAutoenrollmentFlags = dwData;
  205. }
  206. else
  207. DisplaySystemError (NULL, lResult);
  208. }
  209. else
  210. DisplaySystemError (NULL, lResult);
  211. }
  212. void CAutoenrollmentPropertyPage::DoContextHelp (HWND hWndControl)
  213. {
  214. _TRACE (1, L"Entering CAutoenrollmentPropertyPage::DoContextHelp\n");
  215. static const DWORD help_map[] =
  216. {
  217. IDC_AUTOENROLL_DISABLE_ALL, IDH_AUTOENROLL_DISABLE_ALL,
  218. IDC_AUTOENROLL_ENABLE, IDH_AUTOENROLL_ENABLE,
  219. IDC_AUTOENROLL_ENABLE_PENDING, IDH_AUTOENROLL_ENABLE_PENDING,
  220. IDC_AUTOENROLL_ENABLE_TEMPLATE, IDH_AUTOENROLL_ENABLE_TEMPLATE,
  221. 0, 0
  222. };
  223. if ( !::WinHelp (
  224. hWndControl,
  225. GetF1HelpFilename(),
  226. HELP_WM_HELP,
  227. (DWORD_PTR) help_map) )
  228. {
  229. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  230. }
  231. _TRACE (-1, L"Leaving CAutoenrollmentPropertyPage::DoContextHelp\n");
  232. }
  233. void CAutoenrollmentPropertyPage::OnAutoenrollDisableAll()
  234. {
  235. SetModified (TRUE);
  236. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_PENDING, BM_SETCHECK, BST_UNCHECKED);
  237. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_TEMPLATE, BM_SETCHECK, BST_UNCHECKED);
  238. EnableControls ();
  239. }
  240. void CAutoenrollmentPropertyPage::OnAutoenrollEnable()
  241. {
  242. SetModified (TRUE);
  243. EnableControls ();
  244. }
  245. void CAutoenrollmentPropertyPage::OnAutoenrollEnablePending()
  246. {
  247. SetModified (TRUE);
  248. }
  249. void CAutoenrollmentPropertyPage::OnAutoenrollEnableTemplate()
  250. {
  251. SetModified (TRUE);
  252. EnableControls ();
  253. }
  254. void CAutoenrollmentPropertyPage::EnableControls ()
  255. {
  256. // Only change the enabling if this is not RSOP
  257. if ( m_pGPEInformation )
  258. {
  259. if ( BST_CHECKED == SendDlgItemMessage (IDC_AUTOENROLL_ENABLE, BM_GETCHECK) )
  260. {
  261. GetDlgItem (IDC_AUTOENROLL_ENABLE_PENDING)->EnableWindow (TRUE);
  262. GetDlgItem (IDC_AUTOENROLL_ENABLE_TEMPLATE)->EnableWindow (TRUE);
  263. }
  264. else
  265. {
  266. GetDlgItem (IDC_AUTOENROLL_ENABLE_PENDING)->EnableWindow (FALSE);
  267. GetDlgItem (IDC_AUTOENROLL_ENABLE_TEMPLATE)->EnableWindow (FALSE);
  268. }
  269. }
  270. }