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.

316 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2002.
  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. // security review 2/22/2002 BryanWal ok
  163. if ( !_wcsicmp (AUTO_ENROLLMENT_KEY, pObject->GetRegistryKey ()) &&
  164. !_wcsicmp (AUTO_ENROLLMENT_POLICY, pObject->GetValueName ()) )
  165. {
  166. ASSERT (1 == pObject->GetPrecedence ());
  167. m_dwAutoenrollmentFlags = pObject->GetDWORDValue ();
  168. break;
  169. }
  170. }
  171. else
  172. break;
  173. nIndex++;
  174. }
  175. }
  176. }
  177. void CAutoenrollmentPropertyPage::GPEGetAutoenrollmentFlags()
  178. {
  179. DWORD dwDisposition = 0;
  180. LONG lResult = ::RegCreateKeyEx (m_hGroupPolicyKey, // handle of an open key
  181. AUTO_ENROLLMENT_KEY, // address of subkey name
  182. 0, // reserved
  183. L"", // address of class string
  184. REG_OPTION_NON_VOLATILE, // special options flag
  185. // security review 2/22/2002 BryanWal ok
  186. KEY_ALL_ACCESS, // desired security access
  187. NULL, // address of key security structure
  188. &m_hAutoenrollmentFlagsKey, // address of buffer for opened handle
  189. &dwDisposition); // address of disposition value buffer
  190. ASSERT (lResult == ERROR_SUCCESS);
  191. if ( lResult == ERROR_SUCCESS )
  192. {
  193. // Read value
  194. DWORD dwType = REG_DWORD;
  195. DWORD dwData = 0;
  196. DWORD cbData = sizeof (dwData);
  197. // security review 2/22/2002 BryanWal ok
  198. lResult = ::RegQueryValueEx (m_hAutoenrollmentFlagsKey, // handle of key to query
  199. AUTO_ENROLLMENT_POLICY, // address of name of value to query
  200. 0, // reserved
  201. &dwType, // address of buffer for value type
  202. (LPBYTE) &dwData, // address of data buffer
  203. &cbData); // address of data buffer size);
  204. ASSERT (ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult);
  205. if ( ERROR_SUCCESS == lResult || ERROR_FILE_NOT_FOUND == lResult )
  206. {
  207. if ( REG_DWORD == dwType )
  208. m_dwAutoenrollmentFlags = dwData;
  209. }
  210. else
  211. DisplaySystemError (NULL, lResult);
  212. }
  213. else
  214. DisplaySystemError (NULL, lResult);
  215. }
  216. void CAutoenrollmentPropertyPage::DoContextHelp (HWND hWndControl)
  217. {
  218. _TRACE (1, L"Entering CAutoenrollmentPropertyPage::DoContextHelp\n");
  219. static const DWORD help_map[] =
  220. {
  221. IDC_AUTOENROLL_DISABLE_ALL, IDH_AUTOENROLL_DISABLE_ALL,
  222. IDC_AUTOENROLL_ENABLE, IDH_AUTOENROLL_ENABLE,
  223. IDC_AUTOENROLL_ENABLE_PENDING, IDH_AUTOENROLL_ENABLE_PENDING,
  224. IDC_AUTOENROLL_ENABLE_TEMPLATE, IDH_AUTOENROLL_ENABLE_TEMPLATE,
  225. 0, 0
  226. };
  227. if ( !::WinHelp (
  228. hWndControl,
  229. GetF1HelpFilename(),
  230. HELP_WM_HELP,
  231. (DWORD_PTR) help_map) )
  232. {
  233. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  234. }
  235. _TRACE (-1, L"Leaving CAutoenrollmentPropertyPage::DoContextHelp\n");
  236. }
  237. void CAutoenrollmentPropertyPage::OnAutoenrollDisableAll()
  238. {
  239. if ( !(m_dwAutoenrollmentFlags & AUTO_ENROLLMENT_DISABLE_ALL) )
  240. {
  241. m_dwAutoenrollmentFlags |= AUTO_ENROLLMENT_DISABLE_ALL;
  242. SetModified (TRUE);
  243. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_PENDING, BM_SETCHECK, BST_UNCHECKED);
  244. SendDlgItemMessage (IDC_AUTOENROLL_ENABLE_TEMPLATE, BM_SETCHECK, BST_UNCHECKED);
  245. }
  246. EnableControls ();
  247. }
  248. void CAutoenrollmentPropertyPage::OnAutoenrollEnable()
  249. {
  250. if ( m_dwAutoenrollmentFlags & AUTO_ENROLLMENT_DISABLE_ALL )
  251. {
  252. m_dwAutoenrollmentFlags &= ~AUTO_ENROLLMENT_DISABLE_ALL;
  253. SetModified (TRUE);
  254. }
  255. EnableControls ();
  256. }
  257. void CAutoenrollmentPropertyPage::OnAutoenrollEnablePending()
  258. {
  259. SetModified (TRUE);
  260. }
  261. void CAutoenrollmentPropertyPage::OnAutoenrollEnableTemplate()
  262. {
  263. SetModified (TRUE);
  264. EnableControls ();
  265. }
  266. void CAutoenrollmentPropertyPage::EnableControls ()
  267. {
  268. // Only change the enabling if this is not RSOP
  269. if ( m_pGPEInformation )
  270. {
  271. if ( BST_CHECKED == SendDlgItemMessage (IDC_AUTOENROLL_ENABLE, BM_GETCHECK) )
  272. {
  273. GetDlgItem (IDC_AUTOENROLL_ENABLE_PENDING)->EnableWindow (TRUE);
  274. GetDlgItem (IDC_AUTOENROLL_ENABLE_TEMPLATE)->EnableWindow (TRUE);
  275. }
  276. else
  277. {
  278. GetDlgItem (IDC_AUTOENROLL_ENABLE_PENDING)->EnableWindow (FALSE);
  279. GetDlgItem (IDC_AUTOENROLL_ENABLE_TEMPLATE)->EnableWindow (FALSE);
  280. }
  281. }
  282. }