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.

358 lines
13 KiB

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