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.

1106 lines
36 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2001.
  6. //
  7. // File: ComponentDataSafer.cpp
  8. //
  9. // Contents: Implementation of CCertMgrComponentData
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. USE_HANDLE_MACROS ("CERTMGR (ComponentDataSafer.cpp)")
  14. #include <gpedit.h>
  15. #include "compdata.h"
  16. #include "dataobj.h"
  17. #include "cookie.h"
  18. #include "Certifct.h"
  19. #include "dlgs.h"
  20. #pragma warning(push, 3)
  21. #include <wintrust.h>
  22. #include <cryptui.h>
  23. #pragma warning(pop)
  24. #include "storegpe.h"
  25. #include "PolicyPrecedencePropertyPage.h"
  26. #include "SaferLevelGeneral.h"
  27. #include "SaferEntry.h"
  28. #include "SaferEntryPathPropertyPage.h"
  29. #include "SaferEntryPropertySheet.h"
  30. #include "SaferEntryHashPropertyPage.h"
  31. #include "SaferEntryCertificatePropertyPage.h"
  32. #include "SaferEntryInternetZonePropertyPage.h"
  33. #include "SaferTrustedPublishersPropertyPage.h"
  34. #include "SaferDefinedFileTypesPropertyPage.h"
  35. #include "SaferEnforcementPropertyPage.h"
  36. #include "SaferUtil.h"
  37. #ifdef _DEBUG
  38. #ifndef ALPHA
  39. #define new DEBUG_NEW
  40. #endif
  41. #undef THIS_FILE
  42. static char THIS_FILE[] = __FILE__;
  43. #endif
  44. extern HKEY g_hkeyLastSaferRegistryScope;
  45. extern GUID g_guidExtension;
  46. extern GUID g_guidRegExt;
  47. extern GUID g_guidSnapin;
  48. CSaferWindowsExtension::CSaferWindowsExtension() : CCertMgrComponentData ()
  49. {
  50. SetHtmlHelpFileName (SAFER_WINDOWS_HELP_FILE);
  51. m_strLinkedHelpFile = SAFER_WINDOWS_LINKED_HELP_FILE;
  52. };
  53. HRESULT CCertMgrComponentData::AddSaferLevelSetAsDefaultMenuItem (LPCONTEXTMENUCALLBACK pContextMenuCallback, LONG lInsertionPointID)
  54. {
  55. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferLevelSetAsDefaultMenuItem\n");
  56. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  57. ASSERT (pContextMenuCallback);
  58. if ( !pContextMenuCallback )
  59. return E_POINTER;
  60. HRESULT hr = S_OK;
  61. CONTEXTMENUITEM menuItem;
  62. CString szMenu;
  63. CString szHint;
  64. ASSERT (m_pGPEInformation); // must not be RSOP
  65. if ( !m_pGPEInformation )
  66. return E_FAIL;
  67. // unchanging settings
  68. ::ZeroMemory (&menuItem, sizeof (menuItem));
  69. menuItem.lInsertionPointID = lInsertionPointID;
  70. menuItem.fFlags = 0;
  71. VERIFY (szMenu.LoadString (IDS_SAFER_SET_DEFAULT));
  72. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  73. VERIFY (szHint.LoadString (IDS_SAFER_SET_DEFAULT_HINT));
  74. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  75. menuItem.lCommandID = IDM_SAFER_LEVEL_SET_DEFAULT;
  76. hr = pContextMenuCallback->AddItem (&menuItem);
  77. ASSERT (SUCCEEDED (hr));
  78. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferLevelSetAsDefaultMenuItem: 0x%x\n", hr);
  79. return hr;
  80. }
  81. HRESULT CCertMgrComponentData::AddSaferNewEntryMenuItems (LPCONTEXTMENUCALLBACK pContextMenuCallback, LONG lInsertionPointID)
  82. {
  83. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferNewEntryMenuItems\n");
  84. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  85. ASSERT (pContextMenuCallback);
  86. if ( !pContextMenuCallback )
  87. return E_POINTER;
  88. HRESULT hr = S_OK;
  89. CONTEXTMENUITEM menuItem;
  90. CString szMenu;
  91. CString szHint;
  92. ASSERT (m_pGPEInformation); // must not be RSOP
  93. if ( !m_pGPEInformation )
  94. return E_FAIL;
  95. // unchanging settings
  96. ::ZeroMemory (&menuItem, sizeof (menuItem));
  97. menuItem.lInsertionPointID = lInsertionPointID;
  98. menuItem.fFlags = 0;
  99. if ( SUCCEEDED (hr) )
  100. {
  101. VERIFY (szMenu.LoadString (IDS_SAFER_NEW_ENTRY_CERTIFICATE));
  102. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  103. VERIFY (szHint.LoadString (IDS_SAFER_NEW_ENTRY_CERTIFICATE_HINT));
  104. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  105. menuItem.lCommandID = IDM_SAFER_NEW_ENTRY_CERTIFICATE;
  106. hr = pContextMenuCallback->AddItem (&menuItem);
  107. ASSERT (SUCCEEDED (hr));
  108. }
  109. if ( SUCCEEDED (hr) )
  110. {
  111. VERIFY (szMenu.LoadString (IDS_SAFER_NEW_ENTRY_HASH));
  112. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  113. VERIFY (szHint.LoadString (IDS_SAFER_NEW_ENTRY_HASH_HINT));
  114. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  115. menuItem.lCommandID = IDM_SAFER_NEW_ENTRY_HASH;
  116. hr = pContextMenuCallback->AddItem (&menuItem);
  117. ASSERT (SUCCEEDED (hr));
  118. }
  119. if ( SUCCEEDED (hr) )
  120. {
  121. VERIFY (szMenu.LoadString (IDS_SAFER_NEW_ENTRY_INTERNET_ZONE));
  122. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  123. VERIFY (szHint.LoadString (IDS_SAFER_NEW_ENTRY_INTERNET_ZONE_HINT));
  124. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  125. menuItem.lCommandID = IDM_SAFER_NEW_ENTRY_INTERNET_ZONE;
  126. hr = pContextMenuCallback->AddItem (&menuItem);
  127. ASSERT (SUCCEEDED (hr));
  128. }
  129. if ( SUCCEEDED (hr) )
  130. {
  131. VERIFY (szMenu.LoadString (IDS_SAFER_NEW_ENTRY_PATH));
  132. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  133. VERIFY (szHint.LoadString (IDS_SAFER_NEW_ENTRY_PATH_HINT));
  134. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  135. menuItem.lCommandID = IDM_SAFER_NEW_ENTRY_PATH;
  136. hr = pContextMenuCallback->AddItem (&menuItem);
  137. ASSERT (SUCCEEDED (hr));
  138. }
  139. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferNewEntryMenuItems: 0x%x\n", hr);
  140. return hr;
  141. }
  142. HRESULT CCertMgrComponentData::OnSetSaferLevelDefault (LPDATAOBJECT pDataObject)
  143. {
  144. _TRACE (1, L"Entering CCertMgrComponentData::OnSetSaferLevelDefault\n");
  145. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  146. ASSERT (pDataObject);
  147. if ( !pDataObject )
  148. return E_POINTER;
  149. ASSERT (m_pGPEInformation); // must not be RSOP
  150. if ( !m_pGPEInformation )
  151. return E_FAIL;
  152. HRESULT hr = S_OK;
  153. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  154. ASSERT (pCookie);
  155. if ( pCookie )
  156. {
  157. if ( pCookie->HasOpenPropertyPages () )
  158. {
  159. CString text;
  160. CString caption;
  161. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  162. VERIFY (text.LoadString (IDS_CANT_CHANGE_DEFAULT_PAGES_OPEN));
  163. int iRetVal = 0;
  164. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  165. MB_OK, &iRetVal)));
  166. return S_OK;
  167. }
  168. if ( CERTMGR_SAFER_COMPUTER_LEVEL == pCookie->m_objecttype ||
  169. CERTMGR_SAFER_USER_LEVEL == pCookie->m_objecttype )
  170. {
  171. CSaferLevel* pSaferLevel = dynamic_cast<CSaferLevel*>(pCookie);
  172. if ( pSaferLevel )
  173. {
  174. int iRetVal = IDYES;
  175. if ( pSaferLevel->GetLevel () < m_dwDefaultSaferLevel )
  176. {
  177. CString text;
  178. CString caption;
  179. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_EXTENSION_REGISTRY));
  180. VERIFY (text.LoadString (IDS_DEFAULT_LEVEL_CHANGE_WARNING));
  181. m_pConsole->MessageBox (text, caption,
  182. MB_ICONWARNING | MB_YESNO, &iRetVal);
  183. }
  184. if ( IDYES == iRetVal )
  185. {
  186. hr = pSaferLevel->SetAsDefault ();
  187. if ( SUCCEEDED (hr) )
  188. {
  189. m_dwDefaultSaferLevel = pSaferLevel->GetLevel ();
  190. if ( m_pConsole )
  191. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  192. }
  193. else
  194. {
  195. CString text;
  196. CString caption;
  197. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_EXTENSION_REGISTRY));
  198. text.FormatMessage (IDS_CANT_SET_AS_DEFAULT,
  199. pSaferLevel->GetObjectName (),
  200. GetSystemMessage (hr));
  201. iRetVal = 0;
  202. ASSERT (m_pConsole);
  203. if ( m_pConsole )
  204. {
  205. HRESULT hr1 = m_pConsole->MessageBox (text, caption,
  206. MB_ICONWARNING | MB_OK, &iRetVal);
  207. ASSERT (SUCCEEDED (hr1));
  208. }
  209. }
  210. }
  211. }
  212. }
  213. else
  214. hr = E_FAIL;
  215. }
  216. _TRACE (-1, L"Leaving CCertMgrComponentData::OnSetSaferLevelDefault: 0x%x\n", hr);
  217. return hr;
  218. }
  219. HRESULT CCertMgrComponentData::AddSaferLevelPropPage (
  220. LPPROPERTYSHEETCALLBACK pCallback,
  221. CSaferLevel* pSaferLevel,
  222. LONG_PTR lNotifyHandle,
  223. LPDATAOBJECT pDataObject)
  224. {
  225. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferLevelPropPage\n");
  226. HRESULT hr = S_OK;
  227. ASSERT (pCallback && pSaferLevel);
  228. if ( pCallback && pSaferLevel )
  229. {
  230. CSaferLevelGeneral * pLevelPage = new CSaferLevelGeneral (*pSaferLevel,
  231. m_bIsRSOP, lNotifyHandle, pDataObject, m_dwDefaultSaferLevel);
  232. if ( pLevelPage )
  233. {
  234. HPROPSHEETPAGE hLevelPage = MyCreatePropertySheetPage (&pLevelPage->m_psp);
  235. if ( hLevelPage )
  236. {
  237. hr = pCallback->AddPage (hLevelPage);
  238. ASSERT (SUCCEEDED (hr));
  239. if ( SUCCEEDED (hr) )
  240. {
  241. if ( m_bIsRSOP )
  242. {
  243. // CString regPath = SAFER_LEVELOBJECTS_REGKEY;
  244. // regPath += L"\\";
  245. // DWORD dwLevel = pSaferLevel->GetLevel ();
  246. // WCHAR szLevel[16];
  247. // regPath += _itow (dwLevel, szLevel, 10);
  248. CPolicyPrecedencePropertyPage * pPrecedencePage =
  249. new CPolicyPrecedencePropertyPage (this, SAFER_HKLM_REGBASE,
  250. SAFER_DEFAULTOBJ_REGVALUE,
  251. CERTMGR_SAFER_COMPUTER_LEVEL == pSaferLevel->m_objecttype);
  252. if ( pPrecedencePage )
  253. {
  254. HPROPSHEETPAGE hPrecedencePage = MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  255. if ( hPrecedencePage )
  256. {
  257. hr = pCallback->AddPage (hPrecedencePage);
  258. ASSERT (SUCCEEDED (hr));
  259. if ( FAILED (hr) )
  260. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  261. }
  262. else
  263. delete pPrecedencePage;
  264. }
  265. else
  266. {
  267. hr = E_OUTOFMEMORY;
  268. }
  269. }
  270. }
  271. else
  272. {
  273. VERIFY (::DestroyPropertySheetPage (hLevelPage));
  274. }
  275. }
  276. else
  277. delete pLevelPage;
  278. }
  279. else
  280. {
  281. hr = E_OUTOFMEMORY;
  282. }
  283. }
  284. else
  285. hr = E_POINTER;
  286. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferLevelPropPage: 0x%x\n", hr);
  287. return hr;
  288. }
  289. HRESULT CCertMgrComponentData::OnCreateNewSaferPolicy (LPDATAOBJECT pDataObject)
  290. {
  291. HRESULT hr = S_OK;
  292. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  293. ASSERT (pCookie);
  294. if ( pCookie )
  295. {
  296. bool bIsComputer = CERTMGR_SAFER_COMPUTER_ROOT == pCookie->m_objecttype;
  297. HKEY hGroupPolicyKey = 0;
  298. hr = m_pGPEInformation->GetRegistryKey (
  299. bIsComputer ?
  300. GPO_SECTION_MACHINE : GPO_SECTION_USER,
  301. &hGroupPolicyKey);
  302. if ( SUCCEEDED (hr) )
  303. {
  304. BOOL bDefaultsActuallyPopulated = FALSE;
  305. BOOL bResult = ::SaferiPopulateDefaultsInRegistry(
  306. hGroupPolicyKey, &bDefaultsActuallyPopulated);
  307. if ( bResult && bDefaultsActuallyPopulated )
  308. {
  309. m_pGPEInformation->PolicyChanged (TRUE,
  310. TRUE, &g_guidExtension, &g_guidSnapin);
  311. m_pGPEInformation->PolicyChanged (TRUE,
  312. TRUE, &g_guidRegExt, &g_guidSnapin);
  313. }
  314. ::RegCloseKey (hGroupPolicyKey);
  315. }
  316. CSaferRootCookie* pSaferRootCookie = dynamic_cast <CSaferRootCookie*> (pCookie);
  317. if ( pSaferRootCookie )
  318. pSaferRootCookie->m_bCreateSaferNodes = true;
  319. if ( !m_pResultData )
  320. hr = GetResultData (&m_pResultData);
  321. if ( m_pResultData )
  322. hr = m_pResultData->DeleteAllRsltItems ();
  323. // Force scope item selection to for call to
  324. // IComponent::QueryResultViewType ()
  325. hr = m_pComponentConsole->SelectScopeItem (pCookie->m_hScopeItem);
  326. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  327. hr = OnNotifyExpand (pDataObject, TRUE, pCookie->m_hScopeItem);
  328. }
  329. else
  330. hr = E_FAIL;
  331. return hr;
  332. }
  333. HRESULT CCertMgrComponentData::OnNewSaferEntry(long nCommandID, LPDATAOBJECT pDataObject)
  334. {
  335. _TRACE (1, L"Entering CCertMgrComponentData::OnNewSaferEntry ()\n");
  336. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  337. HRESULT hr = S_OK;
  338. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  339. ASSERT (pCookie);
  340. if ( pCookie )
  341. {
  342. bool bIsComputer = false;
  343. switch (pCookie->m_objecttype)
  344. {
  345. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  346. bIsComputer = true;
  347. break;
  348. case CERTMGR_SAFER_USER_ENTRIES:
  349. break;
  350. default:
  351. ASSERT (0);
  352. hr = E_FAIL;
  353. return hr;
  354. }
  355. CSaferEntries* pSaferEntries = dynamic_cast <CSaferEntries*> (pCookie);
  356. if ( !pSaferEntries )
  357. return E_UNEXPECTED;
  358. SAFER_ENTRY_TYPE saferEntryType = SAFER_ENTRY_TYPE_UNKNOWN;
  359. switch (nCommandID)
  360. {
  361. case IDM_SAFER_NEW_ENTRY_PATH:
  362. saferEntryType = SAFER_ENTRY_TYPE_PATH;
  363. break;
  364. case IDM_SAFER_NEW_ENTRY_HASH:
  365. saferEntryType = SAFER_ENTRY_TYPE_HASH;
  366. break;
  367. case IDM_SAFER_NEW_ENTRY_CERTIFICATE:
  368. saferEntryType = SAFER_ENTRY_TYPE_CERT;
  369. break;
  370. case IDM_SAFER_NEW_ENTRY_INTERNET_ZONE:
  371. saferEntryType = SAFER_ENTRY_TYPE_URLZONE;
  372. break;
  373. default:
  374. ASSERT (0);
  375. break;
  376. }
  377. CSaferEntry* pSaferEntry = new CSaferEntry (
  378. saferEntryType,
  379. bIsComputer,
  380. L"",
  381. L"",
  382. 0,
  383. (DWORD) AUTHZ_UNKNOWN_LEVEL,
  384. m_pGPEInformation,
  385. 0,
  386. pSaferEntries,
  387. bIsComputer ? m_rsopObjectArrayComputer : m_rsopObjectArrayUser);
  388. ASSERT (pSaferEntry);
  389. if ( pSaferEntry )
  390. {
  391. UINT nIDCaption = 0;
  392. switch (nCommandID)
  393. {
  394. case IDM_SAFER_NEW_ENTRY_PATH:
  395. nIDCaption = IDS_NEW_PATH_RULE;
  396. break;
  397. case IDM_SAFER_NEW_ENTRY_HASH:
  398. nIDCaption = IDS_NEW_HASH_RULE;
  399. break;
  400. case IDM_SAFER_NEW_ENTRY_CERTIFICATE:
  401. nIDCaption = IDS_NEW_CERTIFICATE_RULE;
  402. break;
  403. case IDM_SAFER_NEW_ENTRY_INTERNET_ZONE:
  404. nIDCaption = IDS_NEW_URLZONE_RULE;
  405. break;
  406. default:
  407. ASSERT (0);
  408. hr = E_FAIL;
  409. break;
  410. }
  411. HWND hParent = 0;
  412. hr = m_pConsole->GetMainWindow (&hParent);
  413. ASSERT (SUCCEEDED (hr));
  414. if ( SUCCEEDED (hr) )
  415. {
  416. CWnd parentWnd;
  417. VERIFY (parentWnd.Attach (hParent));
  418. CSaferEntryPropertySheet propSheet (nIDCaption, &parentWnd);
  419. CPropertyPage* pPage = 0;
  420. switch (nCommandID)
  421. {
  422. case IDM_SAFER_NEW_ENTRY_PATH:
  423. {
  424. CSaferEntryPathPropertyPage* pPropPage = new
  425. CSaferEntryPathPropertyPage (*pSaferEntry, 0,
  426. 0, false, true, this, bIsComputer);
  427. if ( pPropPage )
  428. {
  429. pPage = pPropPage;
  430. }
  431. else
  432. hr = E_OUTOFMEMORY;
  433. }
  434. break;
  435. case IDM_SAFER_NEW_ENTRY_HASH:
  436. {
  437. CSaferEntryHashPropertyPage* pPropPage = new
  438. CSaferEntryHashPropertyPage (*pSaferEntry, 0,
  439. 0, false, this, bIsComputer);
  440. if ( pPropPage )
  441. {
  442. pPage = pPropPage;
  443. }
  444. else
  445. hr = E_OUTOFMEMORY;
  446. }
  447. break;
  448. case IDM_SAFER_NEW_ENTRY_CERTIFICATE:
  449. {
  450. CSaferEntryCertificatePropertyPage* pPropPage = new
  451. CSaferEntryCertificatePropertyPage (*pSaferEntry,
  452. pSaferEntries, 0, 0, false, this, true,
  453. m_pGPEInformation, bIsComputer);
  454. if ( pPropPage )
  455. {
  456. pPage = pPropPage;
  457. }
  458. else
  459. hr = E_OUTOFMEMORY;
  460. }
  461. break;
  462. case IDM_SAFER_NEW_ENTRY_INTERNET_ZONE:
  463. {
  464. CSaferEntryInternetZonePropertyPage* pPropPage = new
  465. CSaferEntryInternetZonePropertyPage (*pSaferEntry,
  466. true, 0, 0, false, this, bIsComputer);
  467. if ( pPropPage )
  468. {
  469. pPage = pPropPage;
  470. }
  471. else
  472. hr = E_OUTOFMEMORY;
  473. }
  474. break;
  475. default:
  476. hr = E_FAIL;
  477. break;
  478. }
  479. if ( SUCCEEDED (hr) && pPage )
  480. {
  481. propSheet.AddPage (pPage);
  482. CThemeContextActivator activator;
  483. INT_PTR iRet = propSheet.DoModal ();
  484. if ( IDOK == iRet )
  485. {
  486. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  487. }
  488. }
  489. delete pSaferEntry;
  490. parentWnd.Detach ();
  491. }
  492. }
  493. else
  494. hr = E_OUTOFMEMORY;
  495. }
  496. else
  497. hr = E_FAIL;
  498. _TRACE (-1, L"Leaving CCertMgrComponentData::OnNewSaferEntry (): 0x%x\n", hr);
  499. return hr;
  500. }
  501. HRESULT CCertMgrComponentData::AddSaferTrustedPublisherPropPages (
  502. LPPROPERTYSHEETCALLBACK pCallback,
  503. bool bIsMachineType)
  504. {
  505. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferTrustedPublisherPropPages\n");
  506. HRESULT hr = S_OK;
  507. ASSERT (pCallback);
  508. if ( pCallback )
  509. {
  510. CSaferTrustedPublishersPropertyPage * pTrustedPublisherPage = new
  511. CSaferTrustedPublishersPropertyPage (
  512. bIsMachineType,
  513. m_pGPEInformation, this);
  514. if ( pTrustedPublisherPage )
  515. {
  516. HPROPSHEETPAGE hTrustedPublisherPage = MyCreatePropertySheetPage (&pTrustedPublisherPage->m_psp);
  517. if ( hTrustedPublisherPage )
  518. {
  519. hr = pCallback->AddPage (hTrustedPublisherPage);
  520. ASSERT (SUCCEEDED (hr));
  521. if ( SUCCEEDED (hr) )
  522. {
  523. // Add the precedence page if this is RSOP
  524. if ( m_bIsRSOP )
  525. {
  526. CPolicyPrecedencePropertyPage * pPrecedencePage =
  527. new CPolicyPrecedencePropertyPage (this,
  528. CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH,
  529. CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME,
  530. bIsMachineType);
  531. if ( pPrecedencePage )
  532. {
  533. HPROPSHEETPAGE hPrecedencePage =
  534. MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  535. if ( hPrecedencePage )
  536. {
  537. hr = pCallback->AddPage (hPrecedencePage);
  538. ASSERT (SUCCEEDED (hr));
  539. if ( FAILED (hr) )
  540. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  541. }
  542. else
  543. {
  544. delete pPrecedencePage;
  545. }
  546. }
  547. else
  548. {
  549. hr = E_OUTOFMEMORY;
  550. }
  551. }
  552. }
  553. else
  554. {
  555. VERIFY (::DestroyPropertySheetPage (hTrustedPublisherPage));
  556. }
  557. }
  558. else
  559. delete pTrustedPublisherPage;
  560. }
  561. else
  562. {
  563. hr = E_OUTOFMEMORY;
  564. }
  565. }
  566. else
  567. hr = E_POINTER;
  568. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferTrustedPublisherPropPages: 0x%x\n", hr);
  569. return hr;
  570. }
  571. HRESULT CCertMgrComponentData::AddSaferDefinedFileTypesPropPages (
  572. LPPROPERTYSHEETCALLBACK pCallback,
  573. bool bIsComputerType)
  574. {
  575. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferDefinedFileTypesPropPages\n");
  576. HRESULT hr = S_OK;
  577. ASSERT (pCallback);
  578. if ( pCallback )
  579. {
  580. CSaferDefinedFileTypesPropertyPage * pDefinedFileTypesPage = new
  581. CSaferDefinedFileTypesPropertyPage (
  582. m_pGPEInformation,
  583. m_bIsRSOP,
  584. bIsComputerType ?
  585. m_rsopObjectArrayComputer : m_rsopObjectArrayUser,
  586. bIsComputerType);
  587. if ( pDefinedFileTypesPage )
  588. {
  589. HPROPSHEETPAGE hDefinedFileTypesPage = MyCreatePropertySheetPage (&pDefinedFileTypesPage->m_psp);
  590. if ( hDefinedFileTypesPage )
  591. {
  592. hr = pCallback->AddPage (hDefinedFileTypesPage);
  593. ASSERT (SUCCEEDED (hr));
  594. if ( SUCCEEDED (hr) )
  595. {
  596. if ( m_bIsRSOP )
  597. {
  598. CPolicyPrecedencePropertyPage * pPrecedencePage =
  599. new CPolicyPrecedencePropertyPage (this,
  600. SAFER_HKLM_REGBASE,
  601. SAFER_EXETYPES_REGVALUE,
  602. bIsComputerType);
  603. if ( pPrecedencePage )
  604. {
  605. HPROPSHEETPAGE hPrecedencePage =
  606. MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  607. if ( hPrecedencePage )
  608. {
  609. hr = pCallback->AddPage (hPrecedencePage);
  610. ASSERT (SUCCEEDED (hr));
  611. if ( FAILED (hr) )
  612. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  613. }
  614. else
  615. delete pPrecedencePage;
  616. }
  617. else
  618. {
  619. hr = E_OUTOFMEMORY;
  620. }
  621. }
  622. }
  623. else
  624. {
  625. VERIFY (::DestroyPropertySheetPage (hDefinedFileTypesPage));
  626. }
  627. }
  628. else
  629. delete pDefinedFileTypesPage;
  630. }
  631. else
  632. {
  633. hr = E_OUTOFMEMORY;
  634. }
  635. }
  636. else
  637. hr = E_POINTER;
  638. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferDefinedFileTypesPropPages: 0x%x\n", hr);
  639. return hr;
  640. }
  641. HRESULT CCertMgrComponentData::AddSaferEnforcementPropPages (
  642. LPPROPERTYSHEETCALLBACK pCallback,
  643. bool bIsComputerType)
  644. {
  645. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferEnforcementPropPages\n");
  646. HRESULT hr = S_OK;
  647. ASSERT (pCallback);
  648. if ( pCallback )
  649. {
  650. CSaferEnforcementPropertyPage * pEnforcementPage = new
  651. CSaferEnforcementPropertyPage (
  652. m_pGPEInformation, this,
  653. m_bIsRSOP,
  654. bIsComputerType ?
  655. m_rsopObjectArrayComputer : m_rsopObjectArrayUser,
  656. bIsComputerType);
  657. if ( pEnforcementPage )
  658. {
  659. HPROPSHEETPAGE hEnforcementPage = MyCreatePropertySheetPage (&pEnforcementPage->m_psp);
  660. if ( hEnforcementPage )
  661. {
  662. hr = pCallback->AddPage (hEnforcementPage);
  663. ASSERT (SUCCEEDED (hr));
  664. if ( SUCCEEDED (hr) )
  665. {
  666. if ( m_bIsRSOP )
  667. {
  668. CPolicyPrecedencePropertyPage * pPrecedencePage =
  669. new CPolicyPrecedencePropertyPage (this,
  670. SAFER_HKLM_REGBASE,
  671. SAFER_TRANSPARENTENABLED_REGVALUE,
  672. bIsComputerType);
  673. if ( pPrecedencePage )
  674. {
  675. HPROPSHEETPAGE hPrecedencePage =
  676. MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  677. if ( hPrecedencePage )
  678. {
  679. hr = pCallback->AddPage (hPrecedencePage);
  680. ASSERT (SUCCEEDED (hr));
  681. if ( FAILED (hr) )
  682. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  683. }
  684. else
  685. delete pPrecedencePage;
  686. }
  687. else
  688. {
  689. hr = E_OUTOFMEMORY;
  690. }
  691. }
  692. }
  693. else
  694. {
  695. VERIFY (::DestroyPropertySheetPage (hEnforcementPage));
  696. }
  697. }
  698. else
  699. delete pEnforcementPage;
  700. }
  701. else
  702. {
  703. hr = E_OUTOFMEMORY;
  704. }
  705. }
  706. else
  707. hr = E_POINTER;
  708. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferEnforcementPropPages: 0x%x\n", hr);
  709. return hr;
  710. }
  711. HRESULT CCertMgrComponentData::AddSaferEntryPropertyPage (
  712. LPPROPERTYSHEETCALLBACK pCallback,
  713. CCertMgrCookie* pCookie,
  714. LPDATAOBJECT pDataObject,
  715. LONG_PTR lNotifyHandle)
  716. {
  717. _TRACE (1, L"Entering CCertMgrComponentData::AddSaferEntryPropertyPage\n");
  718. ASSERT (pCallback && pCookie);
  719. if ( !pCallback || !pCookie )
  720. return E_POINTER;
  721. HRESULT hr = S_OK;
  722. bool bIsComputer = false;
  723. switch (pCookie->m_objecttype)
  724. {
  725. case CERTMGR_SAFER_COMPUTER_ENTRY:
  726. bIsComputer = true;
  727. break;
  728. case CERTMGR_SAFER_USER_ENTRY:
  729. break;
  730. default:
  731. ASSERT (0);
  732. hr = E_FAIL;
  733. return hr;
  734. }
  735. CSaferEntry* pSaferEntry = dynamic_cast <CSaferEntry*> (pCookie);
  736. ASSERT (pSaferEntry);
  737. if ( pSaferEntry )
  738. {
  739. pSaferEntry->Refresh ();
  740. switch (pSaferEntry->GetType ())
  741. {
  742. case SAFER_ENTRY_TYPE_PATH:
  743. {
  744. CSaferEntryPathPropertyPage* pPage = new
  745. CSaferEntryPathPropertyPage (*pSaferEntry,
  746. lNotifyHandle, pDataObject,
  747. m_bIsRSOP, false, this, bIsComputer);
  748. if ( pPage )
  749. {
  750. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pPage->m_psp);
  751. if ( hPage )
  752. {
  753. hr = pCallback->AddPage (hPage);
  754. if ( FAILED (hr) )
  755. {
  756. VERIFY (::DestroyPropertySheetPage (hPage));
  757. }
  758. }
  759. else
  760. delete pPage;
  761. }
  762. else
  763. hr = E_OUTOFMEMORY;
  764. }
  765. break;
  766. case SAFER_ENTRY_TYPE_HASH:
  767. {
  768. CSaferEntryHashPropertyPage* pPage = new
  769. CSaferEntryHashPropertyPage (*pSaferEntry,
  770. lNotifyHandle, pDataObject,
  771. m_bIsRSOP, this, bIsComputer);
  772. if ( pPage )
  773. {
  774. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pPage->m_psp);
  775. if ( hPage )
  776. {
  777. hr = pCallback->AddPage (hPage);
  778. if ( FAILED (hr) )
  779. {
  780. VERIFY (::DestroyPropertySheetPage (hPage));
  781. }
  782. }
  783. else
  784. delete pPage;
  785. }
  786. else
  787. hr = E_OUTOFMEMORY;
  788. }
  789. break;
  790. case SAFER_ENTRY_TYPE_CERT:
  791. {
  792. CSaferEntries* pSaferEntries = 0;
  793. hr = pSaferEntry->GetSaferEntriesNode (&pSaferEntries);
  794. if ( SUCCEEDED (hr) )
  795. {
  796. CSaferEntryCertificatePropertyPage* pPage = new
  797. CSaferEntryCertificatePropertyPage (*pSaferEntry,
  798. pSaferEntries, lNotifyHandle, pDataObject,
  799. m_bIsRSOP, this, false, m_pGPEInformation, bIsComputer);
  800. if ( pPage )
  801. {
  802. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pPage->m_psp);
  803. if ( hPage )
  804. {
  805. hr = pCallback->AddPage (hPage);
  806. if ( FAILED (hr) )
  807. {
  808. VERIFY (::DestroyPropertySheetPage (hPage));
  809. }
  810. }
  811. else
  812. delete pPage;
  813. }
  814. else
  815. hr = E_OUTOFMEMORY;
  816. pSaferEntries->Release ();
  817. }
  818. }
  819. break;
  820. case SAFER_ENTRY_TYPE_URLZONE:
  821. {
  822. CSaferEntryInternetZonePropertyPage* pPage = new
  823. CSaferEntryInternetZonePropertyPage (*pSaferEntry,
  824. false, lNotifyHandle, pDataObject,
  825. m_bIsRSOP, this, bIsComputer);
  826. if ( pPage )
  827. {
  828. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pPage->m_psp);
  829. if ( hPage )
  830. {
  831. hr = pCallback->AddPage (hPage);
  832. if ( FAILED (hr) )
  833. {
  834. VERIFY (::DestroyPropertySheetPage (hPage));
  835. }
  836. }
  837. else
  838. delete pPage;
  839. }
  840. else
  841. hr = E_OUTOFMEMORY;
  842. }
  843. break;
  844. default:
  845. hr = E_FAIL;
  846. break;
  847. }
  848. if ( SUCCEEDED (hr) && m_bIsRSOP )
  849. {
  850. CString szValue;
  851. switch (pSaferEntry->GetType ())
  852. {
  853. case SAFER_ENTRY_TYPE_PATH:
  854. case SAFER_ENTRY_TYPE_HASH:
  855. case SAFER_ENTRY_TYPE_URLZONE:
  856. szValue = SAFER_IDS_ITEMDATA_REGVALUE;
  857. break;
  858. case SAFER_ENTRY_TYPE_CERT:
  859. szValue = STR_BLOB;
  860. break;
  861. default:
  862. ASSERT (0);
  863. break;
  864. }
  865. CPolicyPrecedencePropertyPage * pPrecedencePage =
  866. new CPolicyPrecedencePropertyPage (this,
  867. pSaferEntry->GetRSOPRegistryKey (),
  868. szValue,
  869. bIsComputer);
  870. if ( pPrecedencePage )
  871. {
  872. HPROPSHEETPAGE hPrecedencePage = MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  873. if ( hPrecedencePage )
  874. {
  875. hr = pCallback->AddPage (hPrecedencePage);
  876. ASSERT (SUCCEEDED (hr));
  877. if ( FAILED (hr) )
  878. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  879. }
  880. else
  881. delete pPrecedencePage;
  882. }
  883. else
  884. {
  885. hr = E_OUTOFMEMORY;
  886. }
  887. }
  888. }
  889. else
  890. hr = E_FAIL;
  891. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSaferEntryPropertyPage: 0x%x\n", hr);
  892. return hr;
  893. }
  894. bool CSaferWindowsExtension::FoundInRSOPFilter (BSTR bstrKey) const
  895. {
  896. static size_t nSaferKeyLen = wcslen (SAFER_HKLM_REGBASE);
  897. static size_t nSaferPKKeyLen =
  898. wcslen (CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH);
  899. static size_t nTrustedPublisherKeyLane =
  900. wcslen (CERT_TRUST_PUB_SAFER_GROUP_POLICY_TRUSTED_PUBLISHER_STORE_REGPATH);
  901. static size_t nDisallowedKeyLen =
  902. wcslen (CERT_TRUST_PUB_SAFER_GROUP_POLICY_DISALLOWED_STORE_REGPATH);
  903. if ( !_wcsnicmp (SAFER_HKLM_REGBASE, bstrKey, nSaferKeyLen) ||
  904. !_wcsnicmp (CERT_TRUST_PUB_SAFER_GROUP_POLICY_REGPATH, bstrKey,
  905. nSaferPKKeyLen) ||
  906. !_wcsnicmp (CERT_TRUST_PUB_SAFER_GROUP_POLICY_TRUSTED_PUBLISHER_STORE_REGPATH,
  907. bstrKey, nTrustedPublisherKeyLane) ||
  908. !_wcsnicmp (CERT_TRUST_PUB_SAFER_GROUP_POLICY_DISALLOWED_STORE_REGPATH,
  909. bstrKey, nDisallowedKeyLen) )
  910. {
  911. return true;
  912. }
  913. else
  914. return false;
  915. }
  916. HRESULT CCertMgrComponentData::SaferEnumerateLevels (bool bIsComputer)
  917. {
  918. _TRACE (1, L"Entering CCertMgrComponent::SaferEnumerateLevels ()\n");
  919. HRESULT hr = S_OK;
  920. if ( !m_pdwSaferLevels )
  921. {
  922. if ( m_pGPEInformation )
  923. {
  924. DWORD cbBuffer = 0;
  925. CPolicyKey policyKey (m_pGPEInformation,
  926. SAFER_HKLM_REGBASE,
  927. bIsComputer);
  928. SetRegistryScope (policyKey.GetKey (), bIsComputer);
  929. BOOL bRVal = SaferGetPolicyInformation(
  930. SAFER_SCOPEID_REGISTRY,
  931. SaferPolicyLevelList,
  932. cbBuffer,
  933. m_pdwSaferLevels,
  934. &cbBuffer,
  935. 0);
  936. if ( !bRVal && GetLastError () == ERROR_INSUFFICIENT_BUFFER )
  937. {
  938. DWORD nLevels = cbBuffer/sizeof (DWORD);
  939. m_pdwSaferLevels = new DWORD[nLevels+1];
  940. if ( m_pdwSaferLevels )
  941. {
  942. memset (m_pdwSaferLevels, NO_MORE_SAFER_LEVELS,
  943. sizeof (DWORD) * (nLevels + 1));
  944. bRVal = SaferGetPolicyInformation(
  945. SAFER_SCOPEID_REGISTRY,
  946. SaferPolicyLevelList,
  947. cbBuffer,
  948. m_pdwSaferLevels,
  949. &cbBuffer,
  950. 0);
  951. ASSERT (bRVal);
  952. if ( !bRVal )
  953. {
  954. DWORD dwErr = GetLastError ();
  955. hr = HRESULT_FROM_WIN32 (dwErr);
  956. _TRACE (0, L"SaferGetPolicyInformation(SAFER_SCOPEID_REGISTRY, SaferPolicyLevelList) failed: %d\n",
  957. dwErr);
  958. }
  959. }
  960. else
  961. hr = E_OUTOFMEMORY;
  962. }
  963. else if ( !bRVal )
  964. {
  965. ASSERT (0);
  966. DWORD dwErr = GetLastError ();
  967. hr = HRESULT_FROM_WIN32 (dwErr);
  968. _TRACE (0, L"SaferGetPolicyInformation(SAFER_SCOPEID_REGISTRY, SaferPolicyLevelList) failed: %d\n",
  969. dwErr);
  970. }
  971. }
  972. else
  973. {
  974. // Is RSOP
  975. const int RSOP_SAFER_LEVELS = 3; // SAFER_LEVELID_FULLYTRUSTED, SAFER_LEVELID_DISALLOWED + 1
  976. m_pdwSaferLevels = new DWORD[RSOP_SAFER_LEVELS];
  977. if ( m_pdwSaferLevels )
  978. {
  979. memset (m_pdwSaferLevels, NO_MORE_SAFER_LEVELS,
  980. sizeof (DWORD) * RSOP_SAFER_LEVELS);
  981. m_pdwSaferLevels[0] = SAFER_LEVELID_FULLYTRUSTED;
  982. m_pdwSaferLevels[1] = SAFER_LEVELID_DISALLOWED;
  983. }
  984. else
  985. hr = E_OUTOFMEMORY;
  986. }
  987. }
  988. _TRACE (-1, L"Leaving CCertMgrComponent::SaferEnumerateLevels (): 0x%x\n", hr);
  989. return hr;
  990. }