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.

1207 lines
42 KiB

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