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.

320 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: SaferTrustedPublishersPropertyPage.h
  7. //
  8. // Contents: Declaration of CSaferTrustedPublishersPropertyPage
  9. //
  10. //----------------------------------------------------------------------------
  11. // SaferTrustedPublishersPropertyPage.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "certmgr.h"
  15. #include <gpedit.h>
  16. #include "compdata.h"
  17. #include "SaferTrustedPublishersPropertyPage.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. // CSaferTrustedPublishersPropertyPage property page
  28. CSaferTrustedPublishersPropertyPage::CSaferTrustedPublishersPropertyPage(
  29. bool fIsMachineType, IGPEInformation* pGPEInformation,
  30. CCertMgrComponentData* pCompData)
  31. : CHelpPropertyPage(CSaferTrustedPublishersPropertyPage::IDD),
  32. m_pGPEInformation (pGPEInformation),
  33. m_hGroupPolicyKey (0),
  34. m_dwTrustedPublisherFlags (0),
  35. m_fIsComputerType (fIsMachineType),
  36. m_bComputerIsStandAlone (false),
  37. m_bRSOPValueFound (false)
  38. {
  39. // NTRAID# 263969 Safer Windows: "Enterprise Administrators" radio
  40. // button should be disabled on Trusted Publishers property sheet for
  41. // computers in workgroups.
  42. ASSERT (pCompData);
  43. if ( pCompData )
  44. m_bComputerIsStandAlone = pCompData->ComputerIsStandAlone ();
  45. if ( m_pGPEInformation )
  46. {
  47. m_pGPEInformation->AddRef ();
  48. HRESULT hResult = m_pGPEInformation->GetRegistryKey (
  49. m_fIsComputerType ? GPO_SECTION_MACHINE : GPO_SECTION_USER,
  50. &m_hGroupPolicyKey);
  51. ASSERT (SUCCEEDED (hResult));
  52. if ( SUCCEEDED (hResult) )
  53. GetTrustedPublisherFlags ();
  54. }
  55. else
  56. RSOPGetTrustedPublisherFlags (pCompData);
  57. //{{AFX_DATA_INIT(CSaferTrustedPublishersPropertyPage)
  58. // NOTE: the ClassWizard will add member initialization here
  59. //}}AFX_DATA_INIT
  60. }
  61. CSaferTrustedPublishersPropertyPage::~CSaferTrustedPublishersPropertyPage()
  62. {
  63. if ( m_hGroupPolicyKey )
  64. RegCloseKey (m_hGroupPolicyKey);
  65. if ( m_pGPEInformation )
  66. {
  67. m_pGPEInformation->Release ();
  68. }
  69. }
  70. void CSaferTrustedPublishersPropertyPage::DoDataExchange(CDataExchange* pDX)
  71. {
  72. CHelpPropertyPage::DoDataExchange(pDX);
  73. //{{AFX_DATA_MAP(CSaferTrustedPublishersPropertyPage)
  74. // NOTE: the ClassWizard will add DDX and DDV calls here
  75. //}}AFX_DATA_MAP
  76. }
  77. BEGIN_MESSAGE_MAP(CSaferTrustedPublishersPropertyPage, CHelpPropertyPage)
  78. //{{AFX_MSG_MAP(CSaferTrustedPublishersPropertyPage)
  79. ON_BN_CLICKED(IDC_TP_BY_END_USER, OnTpByEndUser)
  80. ON_BN_CLICKED(IDC_TP_BY_LOCAL_COMPUTER_ADMIN, OnTpByLocalComputerAdmin)
  81. ON_BN_CLICKED(IDC_TP_BY_ENTERPRISE_ADMIN, OnTpByEnterpriseAdmin)
  82. ON_BN_CLICKED(IDC_TP_REV_CHECK_PUBLISHER, OnTpRevCheckPublisher)
  83. ON_BN_CLICKED(IDC_TP_REV_CHECK_TIMESTAMP, OnTpRevCheckTimestamp)
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CSaferTrustedPublishersPropertyPage message handlers
  88. void CSaferTrustedPublishersPropertyPage::DoContextHelp (HWND hWndControl)
  89. {
  90. _TRACE (1, L"Entering CSaferTrustedPublishersPropertyPage::DoContextHelp\n");
  91. static const DWORD help_map[] =
  92. {
  93. IDC_TP_BY_END_USER, IDH_TP_BY_END_USER,
  94. IDC_TP_BY_LOCAL_COMPUTER_ADMIN, IDH_TP_BY_LOCAL_COMPUTER_ADMIN,
  95. IDC_TP_BY_ENTERPRISE_ADMIN, IDH_TP_BY_ENTERPRISE_ADMIN,
  96. IDC_TP_REV_CHECK_PUBLISHER, IDH_TP_REV_CHECK_PUBLISHER,
  97. IDC_TP_REV_CHECK_TIMESTAMP, IDH_TP_REV_CHECK_TIMESTAMP,
  98. 0, 0
  99. };
  100. if ( !::WinHelp (
  101. hWndControl,
  102. GetF1HelpFilename(),
  103. HELP_WM_HELP,
  104. (DWORD_PTR) help_map) )
  105. {
  106. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  107. }
  108. _TRACE (-1, L"Leaving CSaferTrustedPublishersPropertyPage::DoContextHelp\n");
  109. }
  110. BOOL CSaferTrustedPublishersPropertyPage::OnInitDialog()
  111. {
  112. CHelpPropertyPage::OnInitDialog();
  113. if ( m_pGPEInformation || m_bRSOPValueFound )
  114. {
  115. if ( m_dwTrustedPublisherFlags & CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG )
  116. SendDlgItemMessage (IDC_TP_REV_CHECK_PUBLISHER, BM_SETCHECK, BST_CHECKED);
  117. if ( m_dwTrustedPublisherFlags & CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG )
  118. SendDlgItemMessage (IDC_TP_REV_CHECK_TIMESTAMP, BM_SETCHECK, BST_CHECKED);
  119. if ( m_dwTrustedPublisherFlags & CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST )
  120. SendDlgItemMessage (IDC_TP_BY_ENTERPRISE_ADMIN, BM_SETCHECK, BST_CHECKED);
  121. else if ( m_dwTrustedPublisherFlags & CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST )
  122. SendDlgItemMessage (IDC_TP_BY_LOCAL_COMPUTER_ADMIN, BM_SETCHECK, BST_CHECKED);
  123. else
  124. SendDlgItemMessage (IDC_TP_BY_END_USER, BM_SETCHECK, BST_CHECKED);
  125. }
  126. if ( !m_pGPEInformation )
  127. {
  128. // Is RSOP
  129. GetDlgItem (IDC_TP_REV_CHECK_PUBLISHER)->EnableWindow (FALSE);
  130. GetDlgItem (IDC_TP_REV_CHECK_TIMESTAMP)->EnableWindow (FALSE);
  131. GetDlgItem (IDC_TP_BY_ENTERPRISE_ADMIN)->EnableWindow (FALSE);
  132. GetDlgItem (IDC_TP_BY_LOCAL_COMPUTER_ADMIN)->EnableWindow (FALSE);
  133. GetDlgItem (IDC_TP_BY_END_USER)->EnableWindow (FALSE);
  134. }
  135. // NTRAID# 263969 Safer Windows: "Enterprise Administrators" radio
  136. // button should be disabled on Trusted Publishers property sheet for
  137. // computers in workgroups.
  138. if ( m_bComputerIsStandAlone )
  139. GetDlgItem (IDC_TP_BY_ENTERPRISE_ADMIN)->EnableWindow (FALSE);
  140. return TRUE; // return TRUE unless you set the focus to a control
  141. // EXCEPTION: OCX Property Pages should return FALSE
  142. }
  143. void CSaferTrustedPublishersPropertyPage::GetTrustedPublisherFlags()
  144. {
  145. DWORD dwDisposition = 0;
  146. HKEY hKey = 0;
  147. LONG lResult = ::RegCreateKeyEx (m_hGroupPolicyKey, // handle of an open key
  148. CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH, // address of subkey name
  149. 0, // reserved
  150. L"", // address of class string
  151. REG_OPTION_NON_VOLATILE, // special options flag
  152. KEY_ALL_ACCESS, // desired security access
  153. NULL, // address of key security structure
  154. &hKey, // address of buffer for opened handle
  155. &dwDisposition); // address of disposition value buffer
  156. ASSERT (lResult == ERROR_SUCCESS);
  157. if ( lResult == ERROR_SUCCESS )
  158. {
  159. // Read value
  160. DWORD dwType = REG_DWORD;
  161. DWORD dwData = 0;
  162. DWORD cbData = sizeof (dwData);
  163. lResult = ::RegQueryValueEx (hKey, // handle of key to query
  164. CERT_TRUST_PUB_AUTHENTICODE_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. m_dwTrustedPublisherFlags = dwData;
  173. }
  174. else
  175. DisplaySystemError (m_hWnd, lResult);
  176. RegCloseKey (hKey);
  177. }
  178. else
  179. DisplaySystemError (m_hWnd, lResult);
  180. }
  181. void CSaferTrustedPublishersPropertyPage::OnTpByEndUser()
  182. {
  183. SetModified ();
  184. }
  185. void CSaferTrustedPublishersPropertyPage::OnTpByLocalComputerAdmin()
  186. {
  187. SetModified ();
  188. }
  189. void CSaferTrustedPublishersPropertyPage::OnTpByEnterpriseAdmin()
  190. {
  191. SetModified ();
  192. }
  193. void CSaferTrustedPublishersPropertyPage::OnTpRevCheckPublisher()
  194. {
  195. SetModified ();
  196. }
  197. void CSaferTrustedPublishersPropertyPage::OnTpRevCheckTimestamp()
  198. {
  199. SetModified ();
  200. }
  201. BOOL CSaferTrustedPublishersPropertyPage::OnApply()
  202. {
  203. if ( m_pGPEInformation )
  204. {
  205. DWORD dwFlags = 0;
  206. if ( BST_CHECKED == SendDlgItemMessage (IDC_TP_REV_CHECK_PUBLISHER, BM_GETCHECK) )
  207. dwFlags |= CERT_TRUST_PUB_CHECK_PUBLISHER_REV_FLAG;
  208. if ( BST_CHECKED == SendDlgItemMessage (IDC_TP_REV_CHECK_TIMESTAMP, BM_GETCHECK) )
  209. dwFlags |= CERT_TRUST_PUB_CHECK_TIMESTAMP_REV_FLAG;
  210. if ( BST_CHECKED == SendDlgItemMessage (IDC_TP_BY_ENTERPRISE_ADMIN, BM_GETCHECK) )
  211. dwFlags |= CERT_TRUST_PUB_ALLOW_ENTERPRISE_ADMIN_TRUST;
  212. else if ( BST_CHECKED == SendDlgItemMessage (IDC_TP_BY_LOCAL_COMPUTER_ADMIN, BM_GETCHECK) )
  213. dwFlags |= CERT_TRUST_PUB_ALLOW_MACHINE_ADMIN_TRUST;
  214. else
  215. dwFlags |= CERT_TRUST_PUB_ALLOW_END_USER_TRUST;
  216. HKEY hKey = 0;
  217. DWORD dwDisposition = 0;
  218. LONG lResult = ::RegCreateKeyEx (m_hGroupPolicyKey, // handle of an open key
  219. CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH, // address of subkey name
  220. 0, // reserved
  221. L"", // address of class string
  222. REG_OPTION_NON_VOLATILE, // special options flag
  223. KEY_ALL_ACCESS, // desired security access
  224. NULL, // address of key security structure
  225. &hKey, // address of buffer for opened handle
  226. &dwDisposition); // address of disposition value buffer
  227. ASSERT (lResult == ERROR_SUCCESS);
  228. if ( lResult == ERROR_SUCCESS )
  229. {
  230. DWORD cbData = sizeof (dwFlags);
  231. lResult = ::RegSetValueEx (hKey,
  232. CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME, // address of value to set
  233. 0, // reserved
  234. REG_DWORD, // flag for value type
  235. (CONST BYTE *) &dwFlags, // address of value data
  236. cbData); // size of value data);
  237. ASSERT (ERROR_SUCCESS == lResult);
  238. if ( ERROR_SUCCESS == lResult )
  239. {
  240. // TRUE means we're changing the machine policy only
  241. m_pGPEInformation->PolicyChanged (m_fIsComputerType ? TRUE : FALSE,
  242. TRUE, &g_guidExtension, &g_guidSnapin);
  243. m_pGPEInformation->PolicyChanged (m_fIsComputerType ? TRUE : FALSE,
  244. TRUE, &g_guidRegExt, &g_guidSnapin);
  245. }
  246. else
  247. DisplaySystemError (m_hWnd, lResult);
  248. RegCloseKey (hKey);
  249. }
  250. }
  251. return CHelpPropertyPage::OnApply();
  252. }
  253. void CSaferTrustedPublishersPropertyPage::RSOPGetTrustedPublisherFlags(const CCertMgrComponentData* pCompData)
  254. {
  255. if ( pCompData )
  256. {
  257. int nIndex = 0;
  258. // NOTE: rsop object array is sorted first by registry key, then by precedence
  259. const CRSOPObjectArray* pObjectArray = m_fIsComputerType ?
  260. pCompData->GetRSOPObjectArrayComputer () : pCompData->GetRSOPObjectArrayUser ();
  261. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  262. while ( nUpperBound >= nIndex )
  263. {
  264. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  265. if ( pObject )
  266. {
  267. if ( !_wcsicmp (CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH, pObject->GetRegistryKey ()) &&
  268. !_wcsicmp (CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME, pObject->GetValueName ()) )
  269. {
  270. ASSERT (1 == pObject->GetPrecedence ());
  271. m_dwTrustedPublisherFlags = pObject->GetDWORDValue ();
  272. m_bRSOPValueFound = true;
  273. break;
  274. }
  275. }
  276. else
  277. break;
  278. nIndex++;
  279. }
  280. }
  281. }