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.

6263 lines
218 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. // File: compdata.cpp
  8. //
  9. // Contents: Implementation of CCertMgrComponentData
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. USE_HANDLE_MACROS ("CERTMGR (compdata.cpp)")
  14. #include <gpedit.h>
  15. #include "compdata.h"
  16. #include "dataobj.h"
  17. #include "cookie.h"
  18. #include "snapmgr.h"
  19. #include "Certifct.h"
  20. #include "dlgs.h"
  21. #include "SelAcct.h"
  22. #include "FindDlg.h"
  23. #pragma warning(push, 3)
  24. #include <wintrust.h>
  25. #include <cryptui.h>
  26. #include <sceattch.h>
  27. #pragma warning(pop)
  28. #include "selservc.h"
  29. #include "acrgenpg.h"
  30. #include "acrspsht.h"
  31. #include "acrswlcm.h"
  32. #include "acrstype.h"
  33. #include "acrslast.h"
  34. #include "addsheet.h"
  35. #include "gpepage.h"
  36. #include "storegpe.h"
  37. #include "uuids.h"
  38. #include "StoreRSOP.h"
  39. #include "PolicyPrecedencePropertyPage.h"
  40. #include "AutoenrollmentPropertyPage.h"
  41. #include "SaferEntry.h"
  42. #include "SaferUtil.h"
  43. #include "SaferDefinedFileTypesPropertyPage.h"
  44. #include "EFSGeneralPropertyPage.h"
  45. #ifdef _DEBUG
  46. #ifndef ALPHA
  47. #define new DEBUG_NEW
  48. #endif
  49. #undef THIS_FILE
  50. static char THIS_FILE[] = __FILE__;
  51. #endif
  52. #include "stdcdata.cpp" // CComponentData implementation
  53. extern HINSTANCE g_hInstance;
  54. extern GUID g_guidExtension;
  55. extern GUID g_guidRegExt;
  56. extern GUID g_guidSnapin;
  57. //
  58. // CCertMgrComponentData
  59. //
  60. extern CString g_szFileName; // If not empty, was called from command-line.
  61. CCertMgrComponentData::CCertMgrComponentData ()
  62. : m_pRootCookie (0),
  63. m_activeViewPersist (IDM_STORE_VIEW),
  64. m_hRootScopeItem (0),
  65. m_bShowPhysicalStoresPersist (0),
  66. m_bShowArchivedCertsPersist (0),
  67. m_fAllowOverrideMachineName (0),
  68. m_dwFlagsPersist (0),
  69. m_dwLocationPersist (0),
  70. m_pResultData (0),
  71. m_pGPEInformation (0),
  72. m_pRSOPInformationComputer (0),
  73. m_pRSOPInformationUser (0),
  74. m_bIsUserAdministrator (FALSE),
  75. m_dwSCEMode (SCE_MODE_UNKNOWN),
  76. m_pHeader (0),
  77. m_bMultipleObjectsSelected (false) ,
  78. m_pCryptUIMMCCallbackStruct (0),
  79. m_pGPERootStore (0),
  80. m_pGPETrustStore (0),
  81. m_pFileBasedStore (0),
  82. m_pGPEACRSUserStore (0),
  83. m_pGPEACRSComputerStore (0),
  84. m_fInvalidComputer (false),
  85. m_bMachineIsStandAlone (true),
  86. m_pComponentConsole (0),
  87. m_bIsRSOP (false),
  88. m_pIWbemServicesComputer (0),
  89. m_pIWbemServicesUser (0),
  90. m_pbstrLanguage (SysAllocString (STR_WQL)),
  91. m_pbstrQuery (SysAllocString (STR_SELECT_STATEMENT)),
  92. m_pbstrValueName (SysAllocString (STR_PROP_VALUENAME)),
  93. m_pbstrRegistryKey (SysAllocString (STR_PROP_REGISTRYKEY)),
  94. m_pbstrValue (SysAllocString (STR_PROP_VALUE)),
  95. m_pbstrPrecedence (SysAllocString (STR_PROP_PRECEDENCE)),
  96. m_pbstrGPOid (SysAllocString (STR_PROP_GPOID)),
  97. m_dwRSOPFlagsComputer (0),
  98. m_dwRSOPFlagsUser (0),
  99. m_dwDefaultSaferLevel (0),
  100. m_pdwSaferLevels (0),
  101. m_bSaferSupported (false),
  102. m_nOpenSaferPageRefCount (0)
  103. {
  104. _TRACE (1, L"Entering CCertMgrComponentData::CCertMgrComponentData\n");
  105. m_pRootCookie = new CCertMgrCookie (CERTMGR_SNAPIN);
  106. // Get name of logged-in user
  107. DWORD dwSize = 0;
  108. BOOL bRet = ::GetUserName (0, &dwSize);
  109. if ( dwSize > 0 )
  110. {
  111. bRet = ::GetUserName (m_szLoggedInUser.GetBufferSetLength (dwSize), &dwSize);
  112. ASSERT (bRet);
  113. m_szLoggedInUser.ReleaseBuffer ();
  114. }
  115. // Get name of this computer
  116. dwSize = MAX_COMPUTERNAME_LENGTH + 1 ;
  117. bRet = ::GetComputerName (m_szThisComputer.GetBufferSetLength (MAX_COMPUTERNAME_LENGTH + 1 ), &dwSize);
  118. ASSERT (bRet);
  119. m_szThisComputer.ReleaseBuffer ();
  120. // Find out if logged-in users is an Administrator
  121. IsUserAdministrator (m_bIsUserAdministrator);
  122. if ( !g_szFileName.IsEmpty () )
  123. {
  124. m_szFileName = g_szFileName;
  125. g_szFileName = _T ("");
  126. m_dwLocationPersist = 0;
  127. }
  128. // Find out if we're joined to a domain.
  129. PDSROLE_PRIMARY_DOMAIN_INFO_BASIC pInfo = 0;
  130. DWORD dwErr = ::DsRoleGetPrimaryDomainInformation (
  131. 0,
  132. DsRolePrimaryDomainInfoBasic,
  133. (PBYTE*) &pInfo);
  134. if ( ERROR_SUCCESS == dwErr )
  135. {
  136. switch (pInfo->MachineRole)
  137. {
  138. case DsRole_RoleStandaloneWorkstation:
  139. case DsRole_RoleStandaloneServer:
  140. m_bMachineIsStandAlone = true;
  141. break;
  142. case DsRole_RoleMemberWorkstation:
  143. case DsRole_RoleMemberServer:
  144. case DsRole_RoleBackupDomainController:
  145. case DsRole_RolePrimaryDomainController:
  146. m_bMachineIsStandAlone = false;
  147. break;
  148. default:
  149. break;
  150. }
  151. }
  152. else
  153. {
  154. _TRACE (0, L"DsRoleGetPrimaryDomainInformation () failed: 0x%x\n", dwErr);
  155. }
  156. NetApiBufferFree (pInfo);
  157. _TRACE (-1, L"Leaving CCertMgrComponentData::CCertMgrComponentData\n");
  158. }
  159. CCertMgrComponentData::~CCertMgrComponentData ()
  160. {
  161. _TRACE (1, L"Entering CCertMgrComponentData::~CCertMgrComponentData\n");
  162. if ( m_pCryptUIMMCCallbackStruct )
  163. {
  164. ::MMCFreeNotifyHandle (m_pCryptUIMMCCallbackStruct->lNotifyHandle);
  165. ((LPDATAOBJECT)(m_pCryptUIMMCCallbackStruct->param))->Release ();
  166. ::GlobalFree (m_pCryptUIMMCCallbackStruct);
  167. m_pCryptUIMMCCallbackStruct = 0;
  168. }
  169. if ( m_pGPERootStore )
  170. {
  171. m_pGPERootStore->Release ();
  172. m_pGPERootStore = 0;
  173. }
  174. if ( m_pGPETrustStore )
  175. {
  176. m_pGPETrustStore->Release ();
  177. m_pGPETrustStore = 0;
  178. }
  179. if ( m_pFileBasedStore )
  180. {
  181. m_pFileBasedStore->Release ();
  182. m_pFileBasedStore = 0;
  183. }
  184. if ( m_pGPEACRSUserStore )
  185. {
  186. m_pGPEACRSUserStore->Release ();
  187. m_pGPEACRSUserStore = 0;
  188. }
  189. if ( m_pGPEACRSComputerStore )
  190. {
  191. m_pGPEACRSComputerStore->Release ();
  192. m_pGPEACRSComputerStore = 0;
  193. }
  194. CCookie& rootCookie = QueryBaseRootCookie ();
  195. while ( !rootCookie.m_listResultCookieBlocks.IsEmpty() )
  196. {
  197. (rootCookie.m_listResultCookieBlocks.RemoveHead())->Release();
  198. }
  199. if ( m_pGPEInformation )
  200. {
  201. m_pGPEInformation->Release ();
  202. m_pGPEInformation = 0;
  203. }
  204. if ( m_pRSOPInformationComputer )
  205. {
  206. m_pRSOPInformationComputer->Release ();
  207. m_pRSOPInformationComputer = 0;
  208. }
  209. if ( m_pRSOPInformationUser )
  210. {
  211. m_pRSOPInformationUser->Release ();
  212. m_pRSOPInformationUser = 0;
  213. }
  214. if ( m_pResultData )
  215. {
  216. m_pResultData->Release ();
  217. m_pResultData = 0;
  218. }
  219. if ( m_pComponentConsole )
  220. {
  221. SAFE_RELEASE (m_pComponentConsole);
  222. m_pComponentConsole = 0;
  223. }
  224. if (m_pbstrLanguage)
  225. SysFreeString (m_pbstrLanguage);
  226. if (m_pbstrQuery)
  227. SysFreeString (m_pbstrQuery);
  228. if (m_pbstrRegistryKey)
  229. SysFreeString (m_pbstrRegistryKey);
  230. if (m_pbstrValueName)
  231. SysFreeString (m_pbstrValueName);
  232. if (m_pbstrValue)
  233. SysFreeString (m_pbstrValue);
  234. if ( m_pbstrPrecedence )
  235. SysFreeString (m_pbstrPrecedence);
  236. if ( m_pbstrGPOid )
  237. SysFreeString (m_pbstrGPOid);
  238. int nIndex = 0;
  239. INT_PTR nUpperBound = m_rsopObjectArrayComputer.GetUpperBound ();
  240. while ( nUpperBound >= nIndex )
  241. {
  242. CRSOPObject* pCurrObject = m_rsopObjectArrayComputer.GetAt (nIndex);
  243. if ( pCurrObject )
  244. {
  245. delete pCurrObject;
  246. }
  247. nIndex++;
  248. }
  249. m_rsopObjectArrayComputer.RemoveAll ();
  250. nIndex = 0;
  251. nUpperBound = m_rsopObjectArrayUser.GetUpperBound ();
  252. while ( nUpperBound >= nIndex )
  253. {
  254. CRSOPObject* pCurrObject = m_rsopObjectArrayUser.GetAt (nIndex);
  255. if ( pCurrObject )
  256. {
  257. delete pCurrObject;
  258. }
  259. nIndex++;
  260. }
  261. m_rsopObjectArrayUser.RemoveAll ();
  262. if ( m_pIWbemServicesComputer )
  263. m_pIWbemServicesComputer->Release ();
  264. if ( m_pIWbemServicesUser )
  265. m_pIWbemServicesUser->Release ();
  266. if ( m_pRootCookie )
  267. m_pRootCookie->Release ();
  268. if ( m_pdwSaferLevels )
  269. delete m_pdwSaferLevels;
  270. _TRACE (-1, L"Leaving CCertMgrComponentData::~CCertMgrComponentData\n");
  271. }
  272. DEFINE_FORWARDS_MACHINE_NAME ( CCertMgrComponentData, (m_pRootCookie) )
  273. CCookie& CCertMgrComponentData::QueryBaseRootCookie ()
  274. {
  275. _TRACE (0, L"Entering and leaving CCertMgrComponentData::QueryBaseRootCookie\n");
  276. ASSERT (m_pRootCookie);
  277. return (CCookie&) *m_pRootCookie;
  278. }
  279. STDMETHODIMP CCertMgrComponentData::CreateComponent (LPCOMPONENT* ppComponent)
  280. {
  281. _TRACE (1, L"Entering CCertMgrComponentData::CreateComponent\n");
  282. ASSERT (ppComponent);
  283. CComObject<CCertMgrComponent>* pObject = 0;
  284. CComObject<CCertMgrComponent>::CreateInstance (&pObject);
  285. ASSERT (pObject);
  286. pObject->SetComponentDataPtr ( (CCertMgrComponentData*) this);
  287. HRESULT hr = pObject->QueryInterface (IID_PPV_ARG (IComponent, ppComponent));
  288. _TRACE (1, L"Entering CCertMgrComponentData::CreateComponent\n");
  289. return hr;
  290. }
  291. HRESULT CCertMgrComponentData::LoadIcons (LPIMAGELIST pImageList, BOOL /*fLoadLargeIcons*/)
  292. {
  293. _TRACE (1, L"Entering CCertMgrComponentData::LoadIcons\n");
  294. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  295. // Structure to map a Resource ID to an index of icon
  296. struct RESID2IICON
  297. {
  298. UINT uIconId; // Icon resource ID
  299. int iIcon; // Index of the icon in the image list
  300. };
  301. const static RESID2IICON rgzLoadIconList[] =
  302. {
  303. // Misc icons
  304. { IDI_CERTIFICATE, iIconCertificate },
  305. { IDI_CTL, iIconCTL },
  306. { IDI_CRL, iIconCRL },
  307. { IDI_AUTO_CERT_REQUEST, iIconAutoCertRequest },
  308. { IDI_AUTOENROLL, iIconAutoEnroll },
  309. { IDI_SAFER_LEVEL, iIconSaferLevel },
  310. { IDI_DEFAULT_SAFER_LEVEL, iIconDefaultSaferLevel },
  311. { IDI_SAFER_HASH_ENTRY, iIconSaferHashEntry },
  312. { IDI_SAFER_URL_ENTRY, iIconSaferURLEntry },
  313. { IDI_SAFER_NAME_ENTRY, iIconSaferNameEntry },
  314. { IDI_SETTINGS, iIconSettings },
  315. { IDI_SAFER_CERT_ENTRY, iIconSaferCertEntry },
  316. { 0, 0} // Must be last
  317. };
  318. for (int i = 0; rgzLoadIconList[i].uIconId != 0; i++)
  319. {
  320. HICON hIcon = ::LoadIcon (AfxGetInstanceHandle (),
  321. MAKEINTRESOURCE (rgzLoadIconList[i].uIconId));
  322. ASSERT (hIcon && "Icon ID not found in resources");
  323. /*HRESULT hr =*/ pImageList->ImageListSetIcon ( (PLONG_PTR) hIcon,
  324. rgzLoadIconList[i].iIcon);
  325. // ASSERT (SUCCEEDED (hr) && "Unable to add icon to ImageList");
  326. }
  327. _TRACE (-1, L"Leaving CCertMgrComponentData::LoadIcons\n");
  328. return S_OK;
  329. }
  330. HRESULT CCertMgrComponentData::OnNotifyExpand (LPDATAOBJECT pDataObject, BOOL bExpanding, HSCOPEITEM hParent)
  331. {
  332. _TRACE (1, L"Entering CCertMgrComponentData::OnNotifyExpand\n");
  333. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  334. CWaitCursor waitCursor;
  335. ASSERT (pDataObject && hParent && m_pConsoleNameSpace);
  336. if (!bExpanding)
  337. return S_OK;
  338. static bool bDomainVersionChecked = false;
  339. if ( !bDomainVersionChecked )
  340. {
  341. if ( !m_bMachineIsStandAlone ) // only check if joined to a domain
  342. CheckDomainVersion ();
  343. bDomainVersionChecked = true;
  344. }
  345. GUID guidObjectType;
  346. HRESULT hr = ExtractObjectTypeGUID (pDataObject, &guidObjectType);
  347. ASSERT (SUCCEEDED (hr));
  348. if ( IsSecurityConfigurationEditorNodetype (guidObjectType) )
  349. {
  350. hr = ExtractData (pDataObject, CCertMgrDataObject::m_CFSCEModeType,
  351. &m_dwSCEMode, sizeof (DWORD));
  352. ASSERT (SUCCEEDED (hr));
  353. if ( SUCCEEDED (hr) )
  354. {
  355. switch (m_dwSCEMode)
  356. {
  357. case SCE_MODE_DOMAIN_USER: // User Settings
  358. case SCE_MODE_OU_USER:
  359. case SCE_MODE_LOCAL_USER:
  360. case SCE_MODE_DOMAIN_COMPUTER: // Computer Settings
  361. case SCE_MODE_OU_COMPUTER:
  362. case SCE_MODE_LOCAL_COMPUTER:
  363. m_bIsRSOP = false;
  364. if ( !m_pGPEInformation )
  365. {
  366. IUnknown* pIUnknown = 0;
  367. hr = ExtractData (pDataObject,
  368. CCertMgrDataObject::m_CFSCE_GPTUnknown,
  369. &pIUnknown, sizeof (IUnknown*));
  370. ASSERT (SUCCEEDED (hr));
  371. if ( SUCCEEDED (hr) )
  372. {
  373. hr = pIUnknown->QueryInterface (
  374. IID_PPV_ARG (IGPEInformation, &m_pGPEInformation));
  375. ASSERT (SUCCEEDED (hr));
  376. #if DBG
  377. if ( SUCCEEDED (hr) )
  378. {
  379. const int cbLen = 512;
  380. WCHAR szName[cbLen];
  381. hr = m_pGPEInformation->GetName (szName, cbLen);
  382. if ( SUCCEEDED (hr) )
  383. {
  384. _TRACE (0, L"IGPEInformation::GetName () returned: %s",
  385. szName);
  386. }
  387. else
  388. {
  389. _TRACE (0, L"IGPEInformation::GetName () failed: 0x%x\n", hr);
  390. }
  391. }
  392. #endif
  393. pIUnknown->Release ();
  394. }
  395. }
  396. if ( SUCCEEDED (hr) )
  397. {
  398. switch (m_dwSCEMode)
  399. {
  400. case SCE_MODE_DOMAIN_USER:
  401. case SCE_MODE_OU_USER:
  402. case SCE_MODE_LOCAL_USER:
  403. hr = ExpandScopeNodes (NULL, hParent, _T (""),
  404. CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY, NODEID_User);
  405. break;
  406. case SCE_MODE_DOMAIN_COMPUTER:
  407. case SCE_MODE_OU_COMPUTER:
  408. case SCE_MODE_LOCAL_COMPUTER:
  409. hr = ExpandScopeNodes (NULL, hParent, _T (""),
  410. CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY, NODEID_Machine);
  411. break;
  412. default:
  413. ASSERT (0);
  414. hr = E_FAIL;
  415. break;
  416. }
  417. }
  418. break;
  419. case SCE_MODE_RSOP_USER:
  420. case SCE_MODE_RSOP_COMPUTER:
  421. m_bIsRSOP = true;
  422. hr = BuildWMIList (pDataObject, SCE_MODE_RSOP_COMPUTER == m_dwSCEMode);
  423. if ( SUCCEEDED (hr) )
  424. {
  425. switch (m_dwSCEMode)
  426. {
  427. case SCE_MODE_RSOP_USER:
  428. hr = ExpandScopeNodes (NULL, hParent, _T (""),
  429. CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY,
  430. NODEID_User);
  431. break;
  432. case SCE_MODE_RSOP_COMPUTER:
  433. hr = ExpandScopeNodes (NULL, hParent, _T (""),
  434. CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY,
  435. NODEID_Machine);
  436. break;
  437. default:
  438. ASSERT (0);
  439. hr = E_FAIL;
  440. break;
  441. }
  442. }
  443. break;
  444. default:
  445. // we are not extending other nodes
  446. break;
  447. }
  448. }
  449. return hr;
  450. }
  451. // Beyond this point we are not dealing with extension node types.
  452. {
  453. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  454. if ( pParentCookie )
  455. {
  456. hr = ExpandScopeNodes (pParentCookie, hParent, _T (""), 0, guidObjectType);
  457. }
  458. else
  459. hr = E_UNEXPECTED;
  460. }
  461. _TRACE (-1, L"Leaving CCertMgrComponentData::OnNotifyExpand: 0x%x\n", hr);
  462. return hr;
  463. }
  464. HRESULT CCertMgrComponentData::OnNotifyRelease (LPDATAOBJECT /*pDataObject*/, HSCOPEITEM hItem)
  465. {
  466. _TRACE (1, L"Entering CCertMgrComponentData::OnNotifyRelease\n");
  467. HRESULT hr = DeleteChildren (hItem);
  468. //
  469. // In RSoP, we may get called to refresh the scope pane when the query
  470. // is re-executed -- if this happens, current nodes will be removed and
  471. // we must reset all of our cached information. We reset the relevant
  472. // information below
  473. //
  474. if ( hItem && (!m_hRootScopeItem || m_hRootScopeItem == hItem) )
  475. {
  476. if ( m_pGPERootStore )
  477. {
  478. m_pGPERootStore->Release ();
  479. m_pGPERootStore = 0;
  480. }
  481. if ( m_pGPETrustStore )
  482. {
  483. m_pGPETrustStore->Release ();
  484. m_pGPETrustStore = 0;
  485. }
  486. if ( m_pGPEACRSComputerStore )
  487. {
  488. m_pGPEACRSComputerStore->Release ();
  489. m_pGPEACRSComputerStore = 0;
  490. }
  491. if ( m_pGPEACRSUserStore )
  492. {
  493. m_pGPEACRSUserStore->Release ();
  494. m_pGPEACRSUserStore = 0;
  495. }
  496. if ( m_pRSOPInformationComputer )
  497. {
  498. m_pRSOPInformationComputer->Release();
  499. m_pRSOPInformationComputer = 0;
  500. }
  501. if ( m_pRSOPInformationUser )
  502. {
  503. m_pRSOPInformationUser->Release();
  504. m_pRSOPInformationUser = 0;
  505. }
  506. }
  507. _TRACE (-1, L"Leaving CCertMgrComponentData::OnNotifyRelease: 0x%x\n", hr);
  508. return hr;
  509. }
  510. BSTR CCertMgrComponentData::QueryResultColumnText (CCookie& basecookie, int nCol)
  511. {
  512. // _TRACE (1, L"Entering CCertMgrComponentData::QueryResultColumnText\n");
  513. CCertMgrCookie& cookie = (CCertMgrCookie&) basecookie;
  514. BSTR strResult = L"";
  515. #ifndef UNICODE
  516. #error not ANSI-enabled
  517. #endif
  518. switch ( cookie.m_objecttype )
  519. {
  520. case CERTMGR_SNAPIN:
  521. case CERTMGR_USAGE:
  522. case CERTMGR_CRL_CONTAINER:
  523. case CERTMGR_CTL_CONTAINER:
  524. case CERTMGR_CERT_CONTAINER:
  525. case CERTMGR_CERT_POLICIES_USER:
  526. case CERTMGR_CERT_POLICIES_COMPUTER:
  527. case CERTMGR_SAFER_COMPUTER_ROOT:
  528. case CERTMGR_SAFER_USER_ROOT:
  529. case CERTMGR_SAFER_COMPUTER_LEVELS:
  530. case CERTMGR_SAFER_USER_LEVELS:
  531. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  532. case CERTMGR_SAFER_USER_ENTRIES:
  533. if ( 0 == nCol )
  534. strResult = const_cast<BSTR> (cookie.GetObjectName ());
  535. break;
  536. case CERTMGR_SAFER_COMPUTER_LEVEL:
  537. case CERTMGR_SAFER_USER_LEVEL:
  538. if ( 0 == nCol )
  539. strResult = const_cast<BSTR> (cookie.GetObjectName ());
  540. break;
  541. case CERTMGR_SAFER_COMPUTER_ENTRY:
  542. case CERTMGR_SAFER_USER_ENTRY:
  543. ASSERT (0);
  544. break;
  545. case CERTMGR_PHYS_STORE:
  546. case CERTMGR_LOG_STORE:
  547. case CERTMGR_LOG_STORE_GPE:
  548. case CERTMGR_LOG_STORE_RSOP:
  549. if (COLNUM_CERT_SUBJECT == nCol)
  550. {
  551. CCertStore* pStore = reinterpret_cast <CCertStore*> (&cookie);
  552. ASSERT (pStore);
  553. if ( pStore )
  554. {
  555. // NTRAID# 455988 PKP: RSOP mode depicts localized store
  556. // name under PublicKeyPolicies. Store names are different
  557. // in GP editor
  558. // if ( m_pGPEInformation || m_bIsRSOP )
  559. // strResult = const_cast<BSTR> (pStore->GetObjectName () );
  560. // else
  561. strResult = const_cast<BSTR> (pStore->GetLocalizedName ());
  562. }
  563. }
  564. break;
  565. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  566. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  567. ASSERT (0);
  568. break;
  569. case CERTMGR_CERTIFICATE:
  570. case CERTMGR_CRL:
  571. case CERTMGR_CTL:
  572. case CERTMGR_AUTO_CERT_REQUEST:
  573. _TRACE (0, L"CCertMgrComponentData::QueryResultColumnText bad parent type\n");
  574. ASSERT (0);
  575. break;
  576. default:
  577. ASSERT (0);
  578. break;
  579. }
  580. // _TRACE (-1, L"Leaving CCertMgrComponentData::QueryResultColumnText\n");
  581. return strResult;
  582. }
  583. int CCertMgrComponentData::QueryImage (CCookie& basecookie, BOOL /*fOpenImage*/)
  584. {
  585. // _TRACE (1, L"Entering CCertMgrComponentData::QueryImage\n");
  586. int nIcon = 0;
  587. CCertMgrCookie& cookie = (CCertMgrCookie&)basecookie;
  588. switch ( cookie.m_objecttype )
  589. {
  590. case CERTMGR_SNAPIN:
  591. nIcon = iIconCertificate;
  592. break;
  593. case CERTMGR_USAGE:
  594. case CERTMGR_PHYS_STORE:
  595. case CERTMGR_LOG_STORE:
  596. case CERTMGR_LOG_STORE_GPE:
  597. case CERTMGR_LOG_STORE_RSOP:
  598. case CERTMGR_CTL_CONTAINER:
  599. case CERTMGR_CERT_CONTAINER:
  600. case CERTMGR_CRL_CONTAINER:
  601. case CERTMGR_CERT_POLICIES_USER:
  602. case CERTMGR_CERT_POLICIES_COMPUTER:
  603. case CERTMGR_SAFER_COMPUTER_ROOT:
  604. case CERTMGR_SAFER_USER_ROOT:
  605. case CERTMGR_SAFER_COMPUTER_LEVELS:
  606. case CERTMGR_SAFER_USER_LEVELS:
  607. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  608. case CERTMGR_SAFER_USER_ENTRIES:
  609. break;
  610. case CERTMGR_CERTIFICATE:
  611. case CERTMGR_CRL:
  612. case CERTMGR_CTL:
  613. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  614. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  615. ASSERT (0); // not expected in scope pane
  616. break;
  617. default:
  618. _TRACE (0, L"CCertMgrComponentData::QueryImage bad parent type\n");
  619. ASSERT (0);
  620. break;
  621. }
  622. // _TRACE (-1, L"Leaving CCertMgrComponentData::QueryImage\n");
  623. return nIcon;
  624. }
  625. ///////////////////////////////////////////////////////////////////////////////
  626. /// IExtendPropertySheet
  627. STDMETHODIMP CCertMgrComponentData::QueryPagesFor (LPDATAOBJECT pDataObject)
  628. {
  629. _TRACE (1, L"Entering CCertMgrComponentData::QueryPagesFor\n");
  630. HRESULT hr = S_OK;
  631. ASSERT (pDataObject);
  632. if ( pDataObject )
  633. {
  634. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  635. hr = ExtractData (pDataObject,
  636. CCertMgrDataObject::m_CFDataObjectType,
  637. &dataobjecttype, sizeof (dataobjecttype));
  638. if ( SUCCEEDED (hr) )
  639. {
  640. switch (dataobjecttype)
  641. {
  642. case CCT_SNAPIN_MANAGER:
  643. if ( !m_bIsUserAdministrator )
  644. {
  645. // Non-admins may manage only their own certs
  646. m_dwLocationPersist = CERT_SYSTEM_STORE_CURRENT_USER;
  647. hr = S_FALSE;
  648. }
  649. break;
  650. case CCT_RESULT:
  651. {
  652. hr = S_FALSE;
  653. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  654. if ( pParentCookie )
  655. {
  656. switch (pParentCookie->m_objecttype)
  657. {
  658. case CERTMGR_CERTIFICATE:
  659. case CERTMGR_AUTO_CERT_REQUEST:
  660. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  661. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  662. case CERTMGR_SAFER_COMPUTER_LEVEL:
  663. case CERTMGR_SAFER_USER_LEVEL:
  664. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  665. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  666. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  667. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  668. case CERTMGR_SAFER_COMPUTER_ENTRY:
  669. case CERTMGR_SAFER_USER_ENTRY:
  670. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  671. case CERTMGR_SAFER_USER_ENFORCEMENT:
  672. hr = S_OK;
  673. break;
  674. case CERTMGR_CTL:
  675. if ( m_bIsRSOP )
  676. hr = S_OK;
  677. break;
  678. default:
  679. break;
  680. }
  681. }
  682. }
  683. break;
  684. case CCT_SCOPE:
  685. {
  686. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  687. if ( pParentCookie )
  688. {
  689. switch ( pParentCookie->m_objecttype )
  690. {
  691. case CERTMGR_LOG_STORE_GPE:
  692. case CERTMGR_LOG_STORE_RSOP:
  693. {
  694. CCertStore* pStore = reinterpret_cast <CCertStore*> (pParentCookie);
  695. ASSERT (pStore);
  696. if ( pStore )
  697. {
  698. switch (pStore->GetStoreType ())
  699. {
  700. case ROOT_STORE:
  701. case EFS_STORE:
  702. hr = S_OK;
  703. break;
  704. default:
  705. break;
  706. }
  707. }
  708. else
  709. hr = S_FALSE;
  710. }
  711. break;
  712. default:
  713. hr = S_FALSE;
  714. break;
  715. }
  716. }
  717. else
  718. {
  719. hr = S_FALSE;
  720. }
  721. }
  722. break;
  723. default:
  724. hr = S_FALSE;
  725. break;
  726. }
  727. }
  728. }
  729. else
  730. hr = E_POINTER;
  731. _TRACE (-1, L"Leaving CCertMgrComponentData::QueryPagesFor: 0x%x\n", hr);
  732. return hr;
  733. }
  734. STDMETHODIMP CCertMgrComponentData::CreatePropertyPages (
  735. LPPROPERTYSHEETCALLBACK pCallback,
  736. LONG_PTR handle, // This handle must be saved in the property page object to notify the parent when modified
  737. LPDATAOBJECT pDataObject)
  738. {
  739. _TRACE (1, L"Entering CCertMgrComponentData::CreatePropertyPages\n");
  740. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  741. HRESULT hr = S_OK;
  742. ASSERT (pCallback && pDataObject);
  743. if ( pCallback && pDataObject )
  744. {
  745. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  746. hr = ExtractData (pDataObject,
  747. CCertMgrDataObject::m_CFDataObjectType,
  748. &dataobjecttype, sizeof (dataobjecttype));
  749. switch (dataobjecttype)
  750. {
  751. case CCT_SNAPIN_MANAGER:
  752. hr = AddSnapMgrPropPages (pCallback);
  753. break;
  754. case CCT_RESULT:
  755. {
  756. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  757. if ( pParentCookie )
  758. {
  759. switch (pParentCookie->m_objecttype)
  760. {
  761. case CERTMGR_CERTIFICATE:
  762. {
  763. CCertificate* pCert = reinterpret_cast <CCertificate*> (pParentCookie);
  764. ASSERT (pCert);
  765. if ( pCert )
  766. {
  767. if ( pCert->IsCertStillInStore () )
  768. {
  769. // Anything, except ACRS
  770. hr = AddCertPropPages (pCert, pCallback,
  771. pDataObject, handle);
  772. }
  773. else
  774. {
  775. CString text;
  776. CString caption;
  777. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  778. VERIFY (text.LoadString (
  779. IDS_CANCEL_BECAUSE_CERT_HAS_BEEN_DELETED));
  780. int iRetVal = 0;
  781. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  782. MB_OK, &iRetVal)));
  783. m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  784. hr = E_FAIL;
  785. }
  786. }
  787. else
  788. hr = E_FAIL;
  789. }
  790. break;
  791. case CERTMGR_AUTO_CERT_REQUEST:
  792. {
  793. CAutoCertRequest* pACR = reinterpret_cast <CAutoCertRequest*> (pParentCookie);
  794. ASSERT (pACR);
  795. if ( pACR )
  796. {
  797. hr = AddACRSCTLPropPages (pACR, pCallback);
  798. }
  799. else
  800. hr = E_FAIL;
  801. }
  802. break;
  803. case CERTMGR_CTL:
  804. {
  805. CCTL* pCTL = reinterpret_cast <CCTL*> (pParentCookie);
  806. ASSERT (pCTL);
  807. if ( pCTL )
  808. {
  809. hr = AddCTLPropPages (pCTL, pCallback);
  810. }
  811. else
  812. hr = E_FAIL;
  813. }
  814. break;
  815. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  816. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  817. hr = AddAutoenrollmentSettingsPropPages (pCallback,
  818. CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS ==
  819. pParentCookie->m_objecttype);
  820. break;
  821. case CERTMGR_SAFER_COMPUTER_LEVEL:
  822. case CERTMGR_SAFER_USER_LEVEL:
  823. hr = AddSaferLevelPropPage (pCallback,
  824. dynamic_cast <CSaferLevel*>(pParentCookie),
  825. handle,
  826. pDataObject);
  827. break;
  828. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  829. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  830. hr = AddSaferTrustedPublisherPropPages (pCallback,
  831. CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS ==
  832. pParentCookie->m_objecttype);
  833. break;
  834. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  835. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  836. hr = AddSaferDefinedFileTypesPropPages (pCallback,
  837. CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES ==
  838. pParentCookie->m_objecttype);
  839. break;
  840. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  841. case CERTMGR_SAFER_USER_ENFORCEMENT:
  842. hr = AddSaferEnforcementPropPages (pCallback,
  843. CERTMGR_SAFER_COMPUTER_ENFORCEMENT ==
  844. pParentCookie->m_objecttype);
  845. break;
  846. case CERTMGR_SAFER_COMPUTER_ENTRY:
  847. case CERTMGR_SAFER_USER_ENTRY:
  848. hr = AddSaferEntryPropertyPage (pCallback,
  849. pParentCookie, pDataObject, handle);
  850. break;
  851. default:
  852. break;
  853. }
  854. }
  855. else
  856. hr = E_UNEXPECTED;
  857. }
  858. break;
  859. case CCT_SCOPE:
  860. {
  861. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  862. if ( pParentCookie )
  863. {
  864. switch ( pParentCookie->m_objecttype )
  865. {
  866. case CERTMGR_LOG_STORE_GPE:
  867. case CERTMGR_LOG_STORE_RSOP:
  868. {
  869. CCertStore* pStore = reinterpret_cast <CCertStore*> (pParentCookie);
  870. ASSERT (pStore);
  871. if ( pStore )
  872. {
  873. if ( ROOT_STORE == pStore->GetStoreType () )
  874. {
  875. hr = AddGPEStorePropPages (pCallback, pStore);
  876. }
  877. else if ( EFS_STORE == pStore->GetStoreType () )
  878. {
  879. hr = AddEFSSettingsPropPages (pCallback,
  880. pStore->IsMachineStore ());
  881. }
  882. }
  883. else
  884. hr = E_FAIL;
  885. }
  886. break;
  887. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  888. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  889. ASSERT (0);
  890. break;
  891. default:
  892. break;
  893. }
  894. }
  895. else
  896. hr = E_UNEXPECTED;
  897. }
  898. break;
  899. default:
  900. break;
  901. }
  902. }
  903. else
  904. hr = E_POINTER;
  905. _TRACE (-1, L"Leaving CCertMgrComponentData::CreatePropertyPages: 0x%x\n", hr);
  906. return hr;
  907. }
  908. HRESULT CCertMgrComponentData::AddSnapMgrPropPages (LPPROPERTYSHEETCALLBACK pCallback)
  909. {
  910. _TRACE (1, L"Entering CCertMgrComponentData::AddSnapMgrPropPages\n");
  911. HRESULT hr = S_OK;
  912. ASSERT (pCallback);
  913. if ( pCallback )
  914. {
  915. //
  916. // Note that once we have established that this is a CCT_SNAPIN_MANAGER cookie,
  917. // we don't care about its other properties. A CCT_SNAPIN_MANAGER cookie is
  918. // equivalent to a BOOL flag asking for the Node Properties page instead of a
  919. // managed object property page. JonN 10/9/96
  920. //
  921. if ( m_bIsUserAdministrator )
  922. {
  923. CSelectAccountPropPage * pSelAcctPage =
  924. new CSelectAccountPropPage (IsWindowsNT ());
  925. if ( pSelAcctPage )
  926. {
  927. pSelAcctPage->AssignLocationPtr (&m_dwLocationPersist);
  928. HPROPSHEETPAGE hSelAcctPage = MyCreatePropertySheetPage (&pSelAcctPage->m_psp);
  929. if ( hSelAcctPage )
  930. {
  931. hr = pCallback->AddPage (hSelAcctPage);
  932. ASSERT (SUCCEEDED (hr));
  933. if ( FAILED (hr) )
  934. VERIFY (::DestroyPropertySheetPage (hSelAcctPage));
  935. }
  936. else
  937. delete pSelAcctPage;
  938. }
  939. else
  940. {
  941. hr = E_OUTOFMEMORY;
  942. }
  943. // In Windows 95 or Windows 98,users will only be able to manage the
  944. // local machine.
  945. if ( IsWindowsNT () )
  946. {
  947. CCertMgrChooseMachinePropPage * pChooseMachinePage = new CCertMgrChooseMachinePropPage ();
  948. if ( pChooseMachinePage )
  949. {
  950. pChooseMachinePage->AssignLocationPtr (&m_dwLocationPersist);
  951. // Initialize state of object
  952. ASSERT (m_pRootCookie);
  953. if ( m_pRootCookie )
  954. {
  955. pChooseMachinePage->InitMachineName (m_pRootCookie->QueryTargetServer ());
  956. pChooseMachinePage->SetOutputBuffers (
  957. OUT &m_strMachineNamePersist,
  958. OUT &m_fAllowOverrideMachineName,
  959. OUT &m_pRootCookie->m_strMachineName); // Effective machine name
  960. HPROPSHEETPAGE hChooseMachinePage = MyCreatePropertySheetPage (&pChooseMachinePage->m_psp);
  961. if ( hChooseMachinePage )
  962. {
  963. hr = pCallback->AddPage (hChooseMachinePage);
  964. ASSERT (SUCCEEDED (hr));
  965. if ( FAILED (hr) )
  966. VERIFY (::DestroyPropertySheetPage (hChooseMachinePage));
  967. }
  968. else
  969. delete pChooseMachinePage;
  970. }
  971. }
  972. else
  973. {
  974. hr = E_OUTOFMEMORY;
  975. }
  976. CSelectServiceAccountPropPage* pServicePage = new
  977. CSelectServiceAccountPropPage (&m_szManagedServicePersist,
  978. &m_szManagedServiceDisplayName,
  979. m_strMachineNamePersist);
  980. if ( pServicePage )
  981. {
  982. // pServicePage->SetCaption (IDS_MS_CERT_MGR); // access violation when called
  983. HPROPSHEETPAGE hServicePage = MyCreatePropertySheetPage (&pServicePage->m_psp);
  984. if ( hServicePage )
  985. {
  986. hr = pCallback->AddPage (hServicePage);
  987. ASSERT (SUCCEEDED (hr));
  988. if ( FAILED (hr) )
  989. VERIFY (::DestroyPropertySheetPage (hServicePage));
  990. }
  991. else
  992. delete pServicePage;
  993. }
  994. else
  995. {
  996. hr = E_OUTOFMEMORY;
  997. }
  998. }
  999. }
  1000. else
  1001. {
  1002. // Non-administrators may view their own certs only.
  1003. m_dwLocationPersist = CERT_SYSTEM_STORE_CURRENT_USER;
  1004. }
  1005. }
  1006. else
  1007. hr = E_POINTER;
  1008. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSnapMgrPropPages: 0x%x\n", hr);
  1009. return hr;
  1010. }
  1011. HRESULT CCertMgrComponentData::AddACRSCTLPropPages (CAutoCertRequest* pACR, LPPROPERTYSHEETCALLBACK pCallback)
  1012. {
  1013. _TRACE (1, L"Entering CCertMgrComponentData::AddACRSCTLPropPages\n");
  1014. HRESULT hr = S_OK;
  1015. ASSERT (pACR && pCallback);
  1016. if ( pACR && pCallback )
  1017. {
  1018. CACRGeneralPage * pACRPage = new CACRGeneralPage (*pACR);
  1019. if ( pACRPage )
  1020. {
  1021. HPROPSHEETPAGE hACRPage = MyCreatePropertySheetPage (&pACRPage->m_psp);
  1022. if ( hACRPage )
  1023. {
  1024. hr = pCallback->AddPage (hACRPage);
  1025. ASSERT (SUCCEEDED (hr));
  1026. if ( FAILED (hr) )
  1027. VERIFY (::DestroyPropertySheetPage (hACRPage));
  1028. }
  1029. else
  1030. delete pACRPage;
  1031. }
  1032. else
  1033. {
  1034. hr = E_OUTOFMEMORY;
  1035. }
  1036. if ( m_bIsRSOP )
  1037. {
  1038. CString szSHA1Hash (L"\\ACRS\\CTLs\\");
  1039. szSHA1Hash += pACR->GetSHAHash ();
  1040. hr = FindRSOPObjectByHashAndDisplayPrecedencePage (szSHA1Hash,
  1041. pACR->GetCertStore ().IsComputerType (), pCallback);
  1042. }
  1043. }
  1044. else
  1045. hr = E_POINTER;
  1046. _TRACE (-1, L"Leaving CCertMgrComponentData::AddACRSCTLPropPages: 0x%x\n", hr);
  1047. return hr;
  1048. }
  1049. HRESULT CCertMgrComponentData::FindRSOPObjectByHashAndDisplayPrecedencePage (
  1050. const CString& szHash,
  1051. const bool bIsComputer,
  1052. LPPROPERTYSHEETCALLBACK pCallback)
  1053. {
  1054. HRESULT hr = S_OK;
  1055. CString szRegKey;
  1056. // NOTE: rsop object array is sorted first by registry key, then by precedence
  1057. const CRSOPObjectArray* pObjectArray =
  1058. bIsComputer ?
  1059. GetRSOPObjectArrayComputer () : GetRSOPObjectArrayUser ();
  1060. INT_PTR nUpperBound = pObjectArray->GetUpperBound ();
  1061. int nIndex = 0;
  1062. // The CTLs are identified by their SHA1 hash. Find the
  1063. // RSOP object containing this CTL's SHA1 hash value and
  1064. // use that to determine the precedence.
  1065. while ( nUpperBound >= nIndex )
  1066. {
  1067. CRSOPObject* pObject = pObjectArray->GetAt (nIndex);
  1068. if ( pObject )
  1069. {
  1070. if ( -1 != pObject->GetRegistryKey ().Find (szHash) )
  1071. {
  1072. // If value equals to "Blob" or "Blob0", then we've
  1073. // found our node
  1074. // security review 2/26/2002 BryanWal ok
  1075. if ( !wcscmp (STR_BLOB, pObject->GetValueName ()) ||
  1076. !wcscmp (STR_BLOB0, pObject->GetValueName ()) )
  1077. {
  1078. szRegKey = pObject->GetRegistryKey ();
  1079. break;
  1080. }
  1081. }
  1082. }
  1083. else
  1084. break;
  1085. nIndex++;
  1086. }
  1087. // Only show the property page if the correct RSOP object was found
  1088. if ( !szRegKey.IsEmpty () )
  1089. {
  1090. CPolicyPrecedencePropertyPage * pPrecedencePage =
  1091. new CPolicyPrecedencePropertyPage (this, szRegKey,
  1092. STR_BLOB,
  1093. bIsComputer);
  1094. if ( pPrecedencePage )
  1095. {
  1096. HPROPSHEETPAGE hPrecedencePage = MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  1097. if ( hPrecedencePage )
  1098. {
  1099. hr = pCallback->AddPage (hPrecedencePage);
  1100. ASSERT (SUCCEEDED (hr));
  1101. if ( FAILED (hr) )
  1102. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  1103. }
  1104. else
  1105. delete pPrecedencePage;
  1106. }
  1107. else
  1108. {
  1109. hr = E_OUTOFMEMORY;
  1110. }
  1111. }
  1112. return hr;
  1113. }
  1114. HRESULT CCertMgrComponentData::AddCTLPropPages (CCTL* pCTL, LPPROPERTYSHEETCALLBACK pCallback)
  1115. {
  1116. _TRACE (1, L"Entering CCertMgrComponentData::AddCTLPropPages\n");
  1117. HRESULT hr = S_OK;
  1118. ASSERT (pCTL && pCallback);
  1119. if ( pCTL && pCallback )
  1120. {
  1121. if ( m_bIsRSOP )
  1122. {
  1123. CString szSHA1Hash (L"\\Trust\\CTLs\\");
  1124. szSHA1Hash += pCTL->GetSHAHash ();
  1125. hr = FindRSOPObjectByHashAndDisplayPrecedencePage (szSHA1Hash,
  1126. pCTL->GetCertStore ().IsComputerType (), pCallback);
  1127. }
  1128. }
  1129. else
  1130. hr = E_POINTER;
  1131. _TRACE (-1, L"Leaving CCertMgrComponentData::AddCTLPropPages: 0x%x\n", hr);
  1132. return hr;
  1133. }
  1134. HRESULT CCertMgrComponentData::AddEFSSettingsPropPages (
  1135. LPPROPERTYSHEETCALLBACK pCallback,
  1136. bool fIsComputerType)
  1137. {
  1138. _TRACE (1, L"Entering CCertMgrComponentData::AddEFSSettingsPropPages\n");
  1139. HRESULT hr = S_OK;
  1140. ASSERT (pCallback);
  1141. if ( pCallback )
  1142. {
  1143. CEFSGeneralPropertyPage * pEFSPage = new CEFSGeneralPropertyPage (
  1144. this, fIsComputerType);
  1145. if ( pEFSPage )
  1146. {
  1147. HPROPSHEETPAGE hEFSPage = MyCreatePropertySheetPage (&pEFSPage->m_psp);
  1148. if ( hEFSPage )
  1149. {
  1150. hr = pCallback->AddPage (hEFSPage);
  1151. ASSERT (SUCCEEDED (hr));
  1152. if ( SUCCEEDED (hr) )
  1153. {
  1154. if ( m_bIsRSOP )
  1155. {
  1156. CString storePath = EFS_SETTINGS_REGPATH;
  1157. CPolicyPrecedencePropertyPage * pPrecedencePage =
  1158. new CPolicyPrecedencePropertyPage (this, storePath,
  1159. EFS_SETTINGS_REGVALUE,
  1160. fIsComputerType);
  1161. if ( pPrecedencePage )
  1162. {
  1163. HPROPSHEETPAGE hPrecedencePage = MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  1164. if ( hPrecedencePage )
  1165. {
  1166. hr = pCallback->AddPage (hPrecedencePage);
  1167. ASSERT (SUCCEEDED (hr));
  1168. if ( FAILED (hr) )
  1169. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  1170. }
  1171. else
  1172. delete pPrecedencePage;
  1173. }
  1174. else
  1175. {
  1176. hr = E_OUTOFMEMORY;
  1177. }
  1178. }
  1179. }
  1180. else
  1181. VERIFY (::DestroyPropertySheetPage (hEFSPage));
  1182. }
  1183. else
  1184. delete pEFSPage;
  1185. }
  1186. else
  1187. {
  1188. hr = E_OUTOFMEMORY;
  1189. }
  1190. }
  1191. else
  1192. hr = E_POINTER;
  1193. _TRACE (-1, L"Leaving CCertMgrComponentData::AddEFSSettingsPropPages: 0x%x\n", hr);
  1194. return hr;
  1195. }
  1196. HRESULT CCertMgrComponentData::AddAutoenrollmentSettingsPropPages (
  1197. LPPROPERTYSHEETCALLBACK pCallback,
  1198. bool fIsComputerType)
  1199. {
  1200. _TRACE (1, L"Entering CCertMgrComponentData::AddAutoenrollmentSettingsPropPages\n");
  1201. HRESULT hr = S_OK;
  1202. ASSERT (pCallback);
  1203. if ( pCallback )
  1204. {
  1205. CAutoenrollmentPropertyPage * pAutoEnrollmentPage = new CAutoenrollmentPropertyPage (
  1206. this, fIsComputerType);
  1207. if ( pAutoEnrollmentPage )
  1208. {
  1209. HPROPSHEETPAGE hAutoEnrollmentPage = MyCreatePropertySheetPage (&pAutoEnrollmentPage->m_psp);
  1210. if ( hAutoEnrollmentPage )
  1211. {
  1212. hr = pCallback->AddPage (hAutoEnrollmentPage);
  1213. ASSERT (SUCCEEDED (hr));
  1214. if ( SUCCEEDED (hr) )
  1215. {
  1216. if ( m_bIsRSOP )
  1217. {
  1218. CString storePath = AUTO_ENROLLMENT_KEY;
  1219. CPolicyPrecedencePropertyPage * pPrecedencePage =
  1220. new CPolicyPrecedencePropertyPage (this, storePath,
  1221. AUTO_ENROLLMENT_POLICY,
  1222. fIsComputerType);
  1223. if ( pPrecedencePage )
  1224. {
  1225. HPROPSHEETPAGE hPrecedencePage = MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  1226. if ( hPrecedencePage )
  1227. {
  1228. hr = pCallback->AddPage (hPrecedencePage);
  1229. ASSERT (SUCCEEDED (hr));
  1230. if ( FAILED (hr) )
  1231. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  1232. }
  1233. else
  1234. delete pPrecedencePage;
  1235. }
  1236. else
  1237. {
  1238. hr = E_OUTOFMEMORY;
  1239. }
  1240. }
  1241. }
  1242. else
  1243. VERIFY (::DestroyPropertySheetPage (hAutoEnrollmentPage));
  1244. }
  1245. else
  1246. delete pAutoEnrollmentPage;
  1247. }
  1248. else
  1249. {
  1250. hr = E_OUTOFMEMORY;
  1251. }
  1252. }
  1253. else
  1254. hr = E_POINTER;
  1255. _TRACE (-1, L"Leaving CCertMgrComponentData::AddAutoenrollmentSettingsPropPages: 0x%x\n", hr);
  1256. return hr;
  1257. }
  1258. HRESULT CCertMgrComponentData::AddGPEStorePropPages (
  1259. LPPROPERTYSHEETCALLBACK pCallback,
  1260. CCertStore* pStore)
  1261. {
  1262. _TRACE (1, L"Entering CCertMgrComponentData::AddGPEStorePropPages\n");
  1263. HRESULT hr = S_OK;
  1264. ASSERT (pCallback && pStore);
  1265. if ( !pCallback || !pStore)
  1266. return E_POINTER;
  1267. ASSERT (m_pGPEInformation || m_pRSOPInformationComputer || m_pRSOPInformationUser );
  1268. if ( !m_pGPEInformation && !m_pRSOPInformationComputer && !m_pRSOPInformationUser )
  1269. return E_UNEXPECTED;
  1270. bool bIsComputerType = pStore->IsMachineStore ();
  1271. CGPERootGeneralPage * pGPERootPage = new CGPERootGeneralPage (this, bIsComputerType);
  1272. if ( pGPERootPage )
  1273. {
  1274. HPROPSHEETPAGE hGPERootPage = MyCreatePropertySheetPage (&pGPERootPage->m_psp);
  1275. if ( hGPERootPage )
  1276. {
  1277. hr = pCallback->AddPage (hGPERootPage);
  1278. ASSERT (SUCCEEDED (hr));
  1279. if ( FAILED (hr) )
  1280. VERIFY (::DestroyPropertySheetPage (hGPERootPage));
  1281. }
  1282. else
  1283. delete pGPERootPage;
  1284. }
  1285. else
  1286. {
  1287. hr = E_OUTOFMEMORY;
  1288. }
  1289. if ( SUCCEEDED (hr) )
  1290. {
  1291. if ( m_bIsRSOP )
  1292. {
  1293. CString storePath = CERT_GROUP_POLICY_SYSTEM_STORE_REGPATH;
  1294. storePath += L"\\";
  1295. storePath += pStore->GetStoreName ();
  1296. CPolicyPrecedencePropertyPage * pPrecedencePage =
  1297. new CPolicyPrecedencePropertyPage (this, storePath,
  1298. CERT_PROT_ROOT_FLAGS_VALUE_NAME, bIsComputerType);
  1299. if ( pPrecedencePage )
  1300. {
  1301. HPROPSHEETPAGE hPrecedencePage = MyCreatePropertySheetPage (&pPrecedencePage->m_psp);
  1302. if ( hPrecedencePage )
  1303. {
  1304. hr = pCallback->AddPage (hPrecedencePage);
  1305. ASSERT (SUCCEEDED (hr));
  1306. if ( FAILED (hr) )
  1307. VERIFY (::DestroyPropertySheetPage (hPrecedencePage));
  1308. }
  1309. else
  1310. delete pPrecedencePage;
  1311. }
  1312. else
  1313. {
  1314. hr = E_OUTOFMEMORY;
  1315. }
  1316. }
  1317. }
  1318. _TRACE (-1, L"Leaving CCertMgrComponentData::AddGPEStorePropPages: 0x%x\n", hr);
  1319. return hr;
  1320. }
  1321. HRESULT CCertMgrComponentData::AddCertPropPages (
  1322. CCertificate * pCert,
  1323. LPPROPERTYSHEETCALLBACK pCallback,
  1324. LPDATAOBJECT pDataObject,
  1325. LONG_PTR lNotifyHandle)
  1326. {
  1327. _TRACE (1, L"Entering CCertMgrComponentData::AddCertPropPages\n");
  1328. HRESULT hr = S_OK;
  1329. CWaitCursor waitCursor;
  1330. ASSERT (pCert);
  1331. ASSERT (pCallback);
  1332. if ( pCert && pCallback )
  1333. {
  1334. PROPSHEETPAGEW* ppsp = 0;
  1335. DWORD dwPageCnt = 0;
  1336. CRYPTUI_VIEWCERTIFICATEPROPERTIES_STRUCT sps;
  1337. HCERTSTORE* pPropPageStores = new HCERTSTORE[1];
  1338. if ( pPropPageStores )
  1339. {
  1340. m_pCryptUIMMCCallbackStruct = (PCRYPTUI_MMCCALLBACK_STRUCT)
  1341. ::GlobalAlloc (GMEM_FIXED, sizeof (CRYPTUI_MMCCALLBACK_STRUCT));
  1342. if ( m_pCryptUIMMCCallbackStruct )
  1343. {
  1344. m_pCryptUIMMCCallbackStruct->pfnCallback = &MMCPropertyChangeNotify;
  1345. m_pCryptUIMMCCallbackStruct->lNotifyHandle = lNotifyHandle;
  1346. pDataObject->AddRef ();
  1347. m_pCryptUIMMCCallbackStruct->param = (LPARAM) pDataObject;
  1348. CCertStore* pStore = pCert->GetCertStore ();
  1349. if ( pStore )
  1350. {
  1351. pPropPageStores[0] = pStore->GetStoreHandle ();
  1352. // security review 2/26/2002 BryanWal ok
  1353. ::ZeroMemory (&sps, sizeof (sps));
  1354. sps.dwSize = sizeof (sps);
  1355. sps.pMMCCallback = m_pCryptUIMMCCallbackStruct;
  1356. sps.pCertContext = pCert->GetNewCertContext ();
  1357. sps.cStores = 1;
  1358. sps.rghStores = pPropPageStores;
  1359. // All dialogs should be read-only under RSOP
  1360. if ( m_bIsRSOP || pCert->IsReadOnly () )
  1361. sps.dwFlags |= CRYPTUI_DISABLE_EDITPROPERTIES;
  1362. _TRACE (0, L"Calling CryptUIGetCertificatePropertiesPages()\n");
  1363. BOOL bReturn = ::CryptUIGetCertificatePropertiesPages (
  1364. &sps,
  1365. NULL,
  1366. &ppsp,
  1367. &dwPageCnt);
  1368. ASSERT (bReturn);
  1369. if ( bReturn )
  1370. {
  1371. HPROPSHEETPAGE hPage = 0;
  1372. for (DWORD dwIndex = 0; dwIndex < dwPageCnt; dwIndex++)
  1373. {
  1374. _TRACE (0, L"Calling CreatePropertySheetPage()\n");
  1375. // Not necessary to call MyCreatePropertySheetPage here
  1376. // as these are not MFC-based property pages
  1377. hPage = ::CreatePropertySheetPage (&ppsp[dwIndex]);
  1378. if ( hPage )
  1379. {
  1380. hr = pCallback->AddPage (hPage);
  1381. ASSERT (SUCCEEDED (hr));
  1382. if ( FAILED (hr) )
  1383. {
  1384. VERIFY (::DestroyPropertySheetPage (hPage));
  1385. break;
  1386. }
  1387. }
  1388. else
  1389. {
  1390. hr = HRESULT_FROM_WIN32 (GetLastError ());
  1391. break;
  1392. }
  1393. }
  1394. }
  1395. else
  1396. {
  1397. hr = E_UNEXPECTED;
  1398. GlobalFree (m_pCryptUIMMCCallbackStruct);
  1399. ::CertFreeCertificateContext (sps.pCertContext);
  1400. }
  1401. }
  1402. }
  1403. else
  1404. {
  1405. hr = E_OUTOFMEMORY;
  1406. }
  1407. if ( E_OUTOFMEMORY == hr && ppsp )
  1408. free (ppsp); // source uses malloc
  1409. delete [] pPropPageStores;
  1410. }
  1411. else
  1412. hr = E_OUTOFMEMORY;
  1413. if ( m_bIsRSOP )
  1414. {
  1415. CString szSHA1Hash (L"\\Certificates\\");
  1416. szSHA1Hash += pCert->GetSHAHash ();
  1417. hr = FindRSOPObjectByHashAndDisplayPrecedencePage (szSHA1Hash,
  1418. pCert->GetCertStore ()->IsComputerType (),
  1419. pCallback);
  1420. }
  1421. }
  1422. else
  1423. hr = E_POINTER;
  1424. _TRACE (-1, L"Leaving CCertMgrComponentData::AddCertPropPages: 0x%x\n", hr);
  1425. return hr;
  1426. }
  1427. HRESULT CCertMgrComponentData::AddContainersToScopePane (
  1428. HSCOPEITEM hParent,
  1429. CCertMgrCookie& parentCookie,
  1430. bool bDeleteAndExpand)
  1431. {
  1432. _TRACE (1, L"Entering CCertMgrComponentData::AddContainersToScopePane\n");
  1433. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1434. LPCONSOLENAMESPACE2 pConsoleNameSpace2 = 0;
  1435. HRESULT hr = m_pConsoleNameSpace->QueryInterface (
  1436. IID_PPV_ARG (IConsoleNameSpace2, &pConsoleNameSpace2));
  1437. if ( SUCCEEDED (hr) && pConsoleNameSpace2 )
  1438. {
  1439. hr = pConsoleNameSpace2->Expand (hParent);
  1440. ASSERT (SUCCEEDED (hr));
  1441. pConsoleNameSpace2->Release ();
  1442. pConsoleNameSpace2 = 0;
  1443. }
  1444. if ( CERTMGR_PHYS_STORE == parentCookie.m_objecttype ||
  1445. (CERTMGR_LOG_STORE == parentCookie.m_objecttype && !m_bShowPhysicalStoresPersist) )
  1446. {
  1447. CCertStore* pStore =
  1448. reinterpret_cast <CCertStore*> (&parentCookie);
  1449. ASSERT (pStore);
  1450. if ( pStore )
  1451. {
  1452. CString objectName;
  1453. if ( pStore->ContainsCRLs () &&
  1454. !ContainerExists (hParent, CERTMGR_CRL_CONTAINER) )
  1455. {
  1456. VERIFY (objectName.LoadString (IDS_CERTIFICATE_REVOCATION_LIST));
  1457. hr = AddScopeNode (new CContainerCookie (
  1458. *pStore,
  1459. CERTMGR_CRL_CONTAINER,
  1460. pStore->QueryNonNULLMachineName (),
  1461. objectName), L"", hParent);
  1462. }
  1463. if ( SUCCEEDED (hr) && pStore->ContainsCTLs () &&
  1464. !ContainerExists (hParent, CERTMGR_CTL_CONTAINER) )
  1465. {
  1466. VERIFY (objectName.LoadString (IDS_CERTIFICATE_TRUST_LIST));
  1467. hr = AddScopeNode (new CContainerCookie (
  1468. *pStore,
  1469. CERTMGR_CTL_CONTAINER,
  1470. pStore->QueryNonNULLMachineName (),
  1471. objectName), L"", hParent);
  1472. }
  1473. if ( SUCCEEDED (hr) && pStore->ContainsCertificates () &&
  1474. !ContainerExists (hParent, CERTMGR_CERT_CONTAINER) )
  1475. {
  1476. VERIFY (objectName.LoadString (IDS_CERTIFICATES));
  1477. hr = AddScopeNode (new CContainerCookie (
  1478. *pStore,
  1479. CERTMGR_CERT_CONTAINER,
  1480. pStore->QueryNonNULLMachineName (),
  1481. objectName), L"", hParent);
  1482. }
  1483. }
  1484. else
  1485. hr = E_UNEXPECTED;
  1486. }
  1487. else if ( CERTMGR_LOG_STORE == parentCookie.m_objecttype && m_bShowPhysicalStoresPersist )
  1488. {
  1489. if ( bDeleteAndExpand )
  1490. {
  1491. hr = DeleteChildren (hParent);
  1492. if ( SUCCEEDED (hr) )
  1493. {
  1494. GUID guid;
  1495. hr = ExpandScopeNodes (&parentCookie, hParent, _T (""), 0, guid);
  1496. }
  1497. }
  1498. }
  1499. _TRACE (-1, L"Leaving CCertMgrComponentData::AddContainersToScopePane: 0x%x\n", hr);
  1500. return hr;
  1501. }
  1502. typedef struct _ENUM_ARG {
  1503. DWORD m_dwFlags;
  1504. LPCONSOLENAMESPACE m_pConsoleNameSpace;
  1505. HSCOPEITEM m_hParent;
  1506. CCertMgrComponentData* m_pCompData;
  1507. PCWSTR m_pcszMachineName;
  1508. CCertMgrCookie* m_pParentCookie;
  1509. SPECIAL_STORE_TYPE m_storeType;
  1510. LPCONSOLE m_pConsole;
  1511. } ENUM_ARG, *PENUM_ARG;
  1512. static BOOL WINAPI EnumPhyCallback (
  1513. IN const void *pvSystemStore,
  1514. IN DWORD dwFlags,
  1515. IN PCWSTR pwszStoreName,
  1516. IN PCERT_PHYSICAL_STORE_INFO pStoreInfo,
  1517. IN OPTIONAL void* /*pvReserved*/,
  1518. IN OPTIONAL void *pvArg
  1519. )
  1520. {
  1521. _TRACE (1, L"Entering EnumPhyCallback\n");
  1522. if ( ! (pStoreInfo->dwFlags & CERT_PHYSICAL_STORE_OPEN_DISABLE_FLAG) )
  1523. {
  1524. PENUM_ARG pEnumArg = (PENUM_ARG) pvArg;
  1525. SCOPEDATAITEM tSDItem;
  1526. // security review 2/26/2002 BryanWal ok
  1527. ::ZeroMemory (&tSDItem,sizeof (tSDItem));
  1528. tSDItem.mask = SDI_STR | SDI_IMAGE | SDI_STATE | SDI_PARAM | SDI_PARENT;
  1529. tSDItem.displayname = MMC_CALLBACK;
  1530. tSDItem.relativeID = pEnumArg->m_hParent;
  1531. tSDItem.nState = 0;
  1532. if ( pEnumArg->m_pCompData->ShowArchivedCerts () )
  1533. dwFlags |= CERT_STORE_ENUM_ARCHIVED_FLAG;
  1534. // Create new cookies
  1535. CCertStore* pNewCookie = new CCertStore (
  1536. CERTMGR_PHYS_STORE,
  1537. CERT_STORE_PROV_PHYSICAL,
  1538. dwFlags,
  1539. pEnumArg->m_pcszMachineName,
  1540. pwszStoreName, (PCWSTR) pvSystemStore, pwszStoreName,
  1541. pEnumArg->m_storeType,
  1542. dwFlags,
  1543. pEnumArg->m_pConsole);
  1544. if ( pNewCookie )
  1545. {
  1546. // pEnumArg->m_pParentCookie->m_listScopeCookieBlocks.AddHead (
  1547. // (CBaseCookieBlock*) pNewCookie);
  1548. // WARNING cookie cast
  1549. tSDItem.lParam = reinterpret_cast<LPARAM> ( (CCookie*) pNewCookie);
  1550. tSDItem.nImage = pEnumArg->m_pCompData->QueryImage (*pNewCookie, FALSE);
  1551. HRESULT hr = pEnumArg->m_pConsoleNameSpace->InsertItem (&tSDItem);
  1552. ASSERT (SUCCEEDED (hr));
  1553. if ( SUCCEEDED (hr) )
  1554. pNewCookie->m_hScopeItem = tSDItem.ID;
  1555. }
  1556. }
  1557. _TRACE (-1, L"Leaving EnumPhyCallback\n");
  1558. return TRUE;
  1559. }
  1560. HRESULT CCertMgrComponentData::AddPhysicalStoresToScopePane (HSCOPEITEM hParent, CCertMgrCookie& parentCookie, const SPECIAL_STORE_TYPE storeType)
  1561. {
  1562. _TRACE (1, L"Entering CCertMgrComponentData::AddPhysicalStoresToScopePane\n");
  1563. CWaitCursor cursor;
  1564. HRESULT hr = S_OK;
  1565. DWORD dwFlags = 0;
  1566. ENUM_ARG enumArg;
  1567. dwFlags &= ~CERT_SYSTEM_STORE_LOCATION_MASK;
  1568. dwFlags |= CERT_STORE_READONLY_FLAG | m_dwLocationPersist;
  1569. // security review 2/26/2002 BryanWal ok
  1570. ::ZeroMemory (&enumArg, sizeof (enumArg));
  1571. enumArg.m_dwFlags = dwFlags;
  1572. enumArg.m_pConsoleNameSpace = m_pConsoleNameSpace;
  1573. enumArg.m_hParent = hParent;
  1574. enumArg.m_pCompData = this;
  1575. enumArg.m_pcszMachineName = parentCookie.QueryNonNULLMachineName ();
  1576. enumArg.m_pParentCookie = &parentCookie;
  1577. enumArg.m_storeType = storeType;
  1578. enumArg.m_pConsole = m_pConsole;
  1579. if (!::CertEnumPhysicalStore (
  1580. (PWSTR) (PCWSTR) parentCookie.GetObjectName (),
  1581. dwFlags,
  1582. &enumArg,
  1583. EnumPhyCallback))
  1584. {
  1585. DWORD dwErr = GetLastError ();
  1586. DisplaySystemError (dwErr);
  1587. hr = HRESULT_FROM_WIN32 (dwErr);
  1588. }
  1589. _TRACE (-1, L"Leaving CCertMgrComponentData::AddPhysicalStoresToScopePane: 0x%x\n", hr);
  1590. return hr;
  1591. }
  1592. static BOOL WINAPI EnumIComponentDataSysCallback (
  1593. IN const void* pwszSystemStore,
  1594. IN DWORD dwFlags,
  1595. IN PCERT_SYSTEM_STORE_INFO /*pStoreInfo*/,
  1596. IN OPTIONAL void* /*pvReserved*/,
  1597. IN OPTIONAL void *pvArg
  1598. )
  1599. {
  1600. _TRACE (1, L"Entering EnumIComponentDataSysCallback\n");
  1601. PENUM_ARG pEnumArg = (PENUM_ARG) pvArg;
  1602. SCOPEDATAITEM tSDItem;
  1603. // security review 2/26/2002 BryanWal ok
  1604. ::ZeroMemory (&tSDItem,sizeof (tSDItem));
  1605. tSDItem.mask = SDI_STR | SDI_IMAGE | SDI_STATE | SDI_PARAM | SDI_PARENT;
  1606. tSDItem.displayname = MMC_CALLBACK;
  1607. tSDItem.relativeID = pEnumArg->m_hParent;
  1608. tSDItem.nState = 0;
  1609. // Create new cookies
  1610. SPECIAL_STORE_TYPE storeType = GetSpecialStoreType ((PWSTR) pwszSystemStore);
  1611. //
  1612. // We will not expose the ACRS store for machines or users. It is not
  1613. // interesting or useful at this level. All Auto Cert Requests should
  1614. // be managed only at the policy level.
  1615. //
  1616. if ( ACRS_STORE != storeType )
  1617. {
  1618. if ( pEnumArg->m_pCompData->ShowArchivedCerts () )
  1619. dwFlags |= CERT_STORE_ENUM_ARCHIVED_FLAG;
  1620. CCertStore* pNewCookie = new CCertStore (
  1621. CERTMGR_LOG_STORE,
  1622. CERT_STORE_PROV_SYSTEM,
  1623. dwFlags,
  1624. pEnumArg->m_pcszMachineName,
  1625. (PCWSTR) pwszSystemStore,
  1626. (PCWSTR) pwszSystemStore,
  1627. _T (""),
  1628. storeType,
  1629. pEnumArg->m_dwFlags,
  1630. pEnumArg->m_pConsole);
  1631. if ( pNewCookie )
  1632. {
  1633. pEnumArg->m_pParentCookie->m_listScopeCookieBlocks.AddHead (
  1634. (CBaseCookieBlock*) pNewCookie);
  1635. // WARNING cookie cast
  1636. tSDItem.lParam = reinterpret_cast<LPARAM> ( (CCookie*) pNewCookie);
  1637. tSDItem.nImage = pEnumArg->m_pCompData->QueryImage (*pNewCookie, FALSE);
  1638. HRESULT hr = pEnumArg->m_pConsoleNameSpace->InsertItem (&tSDItem);
  1639. ASSERT (SUCCEEDED (hr));
  1640. if ( SUCCEEDED (hr) )
  1641. pNewCookie->m_hScopeItem = tSDItem.ID;
  1642. }
  1643. }
  1644. _TRACE (-1, L"Leaving EnumIComponentDataSysCallback\n");
  1645. return TRUE;
  1646. }
  1647. HRESULT CCertMgrComponentData::AddLogicalStoresToScopePane (HSCOPEITEM hParent, CCertMgrCookie& parentCookie)
  1648. {
  1649. _TRACE (1, L"Entering CCertMgrComponentData::AddLogicalStoresToScopePane\n");
  1650. CWaitCursor cursor;
  1651. HRESULT hr = S_OK;
  1652. // If m_dwLocationPersist is 0 but the file name is empty, this means the
  1653. // user launched certmgr.msc without providing a target file. Launch
  1654. // certificates snapin as the current user instead.
  1655. if ( !m_dwLocationPersist )
  1656. {
  1657. if ( m_szFileName.IsEmpty () )
  1658. m_dwLocationPersist = CERT_SYSTEM_STORE_CURRENT_USER;
  1659. ChangeRootNodeName (L"");
  1660. }
  1661. DWORD dwFlags = m_dwLocationPersist;
  1662. ENUM_ARG enumArg;
  1663. // security review 2/26/2002 BryanWal ok
  1664. ::ZeroMemory (&enumArg, sizeof (enumArg));
  1665. enumArg.m_dwFlags = dwFlags;
  1666. enumArg.m_pConsoleNameSpace = m_pConsoleNameSpace;
  1667. enumArg.m_hParent = hParent;
  1668. enumArg.m_pCompData = this;
  1669. enumArg.m_pcszMachineName = parentCookie.QueryNonNULLMachineName ();
  1670. enumArg.m_pParentCookie = &parentCookie;
  1671. enumArg.m_pConsole = m_pConsole;
  1672. CString location;
  1673. void* pvPara = 0;
  1674. switch (m_dwLocationPersist)
  1675. {
  1676. case CERT_SYSTEM_STORE_CURRENT_USER:
  1677. case CERT_SYSTEM_STORE_LOCAL_MACHINE:
  1678. if ( !m_szManagedServicePersist.IsEmpty () )
  1679. m_szManagedServicePersist.Empty ();
  1680. break;
  1681. case CERT_SYSTEM_STORE_CURRENT_SERVICE:
  1682. case CERT_SYSTEM_STORE_SERVICES:
  1683. break;
  1684. case 0: // in the event of a file store
  1685. break;
  1686. default:
  1687. ASSERT (0);
  1688. break;
  1689. }
  1690. if ( !m_szManagedServicePersist.IsEmpty () )
  1691. {
  1692. if ( m_szManagedComputer.CompareNoCase (m_szThisComputer) ) //!=
  1693. {
  1694. location = m_szManagedComputer + _T ("\\") +
  1695. m_szManagedServicePersist;
  1696. pvPara = (void *) (PCWSTR) location;
  1697. }
  1698. else
  1699. pvPara = (void *) (PCWSTR) m_szManagedServicePersist;
  1700. }
  1701. else if ( m_szManagedComputer.CompareNoCase (m_szThisComputer) ) //!=
  1702. {
  1703. pvPara = (void *) (PCWSTR) m_szManagedComputer;
  1704. }
  1705. if ( m_szFileName.IsEmpty () )
  1706. {
  1707. // Ensure creation of MY store
  1708. HCERTSTORE hTempStore = ::CertOpenStore (CERT_STORE_PROV_SYSTEM,
  1709. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  1710. NULL,
  1711. dwFlags | CERT_STORE_SET_LOCALIZED_NAME_FLAG,
  1712. MY_SYSTEM_STORE_NAME);
  1713. if ( hTempStore ) // otherwise, store is read only
  1714. {
  1715. VERIFY (::CertCloseStore (hTempStore, CERT_CLOSE_STORE_CHECK_FLAG));
  1716. }
  1717. else
  1718. {
  1719. _TRACE (0, L"CertOpenStore (%s) failed: 0x%x\n",
  1720. MY_SYSTEM_STORE_NAME, GetLastError ());
  1721. }
  1722. if ( !::CertEnumSystemStore (dwFlags, pvPara, &enumArg,
  1723. EnumIComponentDataSysCallback) )
  1724. {
  1725. DWORD dwErr = GetLastError ();
  1726. CString text;
  1727. CString caption;
  1728. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  1729. if ( ERROR_ACCESS_DENIED == dwErr )
  1730. {
  1731. VERIFY (text.LoadString (IDS_NO_PERMISSION));
  1732. }
  1733. else
  1734. {
  1735. text.FormatMessage (IDS_CANT_ENUMERATE_SYSTEM_STORES, GetSystemMessage (dwErr));
  1736. }
  1737. int iRetVal = 0;
  1738. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  1739. MB_OK, &iRetVal)));
  1740. hr = HRESULT_FROM_WIN32 (dwErr);
  1741. if ( ERROR_BAD_NETPATH == dwErr )
  1742. {
  1743. m_fInvalidComputer = true;
  1744. }
  1745. }
  1746. }
  1747. else
  1748. {
  1749. // CertOpenStore with provider type of:
  1750. // CERT_STORE_PROV_FILE or CERT_STORE_PROV_FILENAME_A
  1751. // or CERT_STORE_PROV_FILENAME_W.
  1752. // See online documentation or wincrypt.h for more info.
  1753. // Create new cookies
  1754. dwFlags = 0;
  1755. if ( ShowArchivedCerts () )
  1756. dwFlags |= CERT_STORE_ENUM_ARCHIVED_FLAG;
  1757. ASSERT (!m_pFileBasedStore);
  1758. m_pFileBasedStore = new CCertStore (
  1759. CERTMGR_LOG_STORE,
  1760. CERT_STORE_PROV_FILENAME_W,
  1761. dwFlags,
  1762. parentCookie.QueryNonNULLMachineName (),
  1763. m_szFileName, m_szFileName, L"", NO_SPECIAL_TYPE,
  1764. m_dwLocationPersist,
  1765. m_pConsole);
  1766. if ( m_pFileBasedStore )
  1767. {
  1768. m_pFileBasedStore->AddRef ();
  1769. hr = AddScopeNode (m_pFileBasedStore,
  1770. L"", hParent);
  1771. }
  1772. else
  1773. {
  1774. hr = E_OUTOFMEMORY;
  1775. }
  1776. }
  1777. _TRACE (-1, L"Leaving CCertMgrComponentData::AddLogicalStoresToScopePane: 0x%x\n", hr);
  1778. return hr;
  1779. }
  1780. // If the callback returns FALSE, stops the enumeration.
  1781. BOOL EnumOIDInfo (PCCRYPT_OID_INFO pInfo, void *pvArg)
  1782. {
  1783. _TRACE (1, L"Entering EnumOIDInfo\n");
  1784. ENUM_ARG* pEnumArg = (ENUM_ARG*) pvArg;
  1785. SCOPEDATAITEM tSDItem;
  1786. // security review 2/26/2002 BryanWal ok
  1787. ::ZeroMemory (&tSDItem, sizeof (tSDItem));
  1788. tSDItem.mask = SDI_STR | SDI_IMAGE | SDI_STATE | SDI_PARAM | SDI_PARENT;
  1789. tSDItem.displayname = MMC_CALLBACK;
  1790. tSDItem.relativeID = pEnumArg->m_hParent;
  1791. tSDItem.nState = 0;
  1792. // See if this usage is already listed by name. If so, just add the
  1793. // additional OID, otherwise, create a new cookie.
  1794. CUsageCookie* pUsageCookie =
  1795. pEnumArg->m_pCompData->FindDuplicateUsage (pEnumArg->m_hParent,
  1796. pInfo->pwszName);
  1797. if ( !pUsageCookie )
  1798. {
  1799. pUsageCookie= new CUsageCookie (CERTMGR_USAGE,
  1800. pEnumArg->m_pcszMachineName,
  1801. pInfo->pwszName);
  1802. if ( pUsageCookie )
  1803. {
  1804. pEnumArg->m_pCompData->GetRootCookie ()->m_listScopeCookieBlocks.AddHead ( (CBaseCookieBlock*) pUsageCookie);
  1805. // WARNING cookie cast
  1806. tSDItem.mask |= SDI_CHILDREN;
  1807. tSDItem.cChildren = 0;
  1808. tSDItem.lParam = reinterpret_cast<LPARAM> ( (CCookie*) pUsageCookie);
  1809. tSDItem.nImage = pEnumArg->m_pCompData->QueryImage (*pUsageCookie, FALSE);
  1810. HRESULT hr = pEnumArg->m_pConsoleNameSpace->InsertItem (&tSDItem);
  1811. ASSERT (SUCCEEDED (hr));
  1812. }
  1813. }
  1814. pUsageCookie->AddOID (pInfo->pszOID);
  1815. _TRACE (-1, L"Leaving EnumOIDInfo\n");
  1816. return TRUE;
  1817. }
  1818. HRESULT CCertMgrComponentData::AddUsagesToScopePane (HSCOPEITEM hParent, CCertMgrCookie& parentCookie)
  1819. {
  1820. _TRACE (1, L"Entering CCertMgrComponentData::AddUsagesToScopePane\n");
  1821. HRESULT hr = S_OK;
  1822. ENUM_ARG enumArg;
  1823. // security review 2/26/2002 BryanWal ok
  1824. ::ZeroMemory (&enumArg, sizeof (enumArg));
  1825. enumArg.m_dwFlags = 0;
  1826. enumArg.m_pConsoleNameSpace = m_pConsoleNameSpace;
  1827. enumArg.m_hParent = hParent;
  1828. enumArg.m_pCompData = this;
  1829. enumArg.m_pcszMachineName = parentCookie.QueryNonNULLMachineName ();
  1830. enumArg.m_pParentCookie = &parentCookie;
  1831. enumArg.m_pConsole = m_pConsole;
  1832. BOOL bResult = ::CryptEnumOIDInfo (CRYPT_ENHKEY_USAGE_OID_GROUP_ID, 0,
  1833. &enumArg, EnumOIDInfo);
  1834. ASSERT (bResult);
  1835. _TRACE (-1, L"Leaving CCertMgrComponentData::AddUsagesToScopePane: 0x%x\n", hr);
  1836. return hr;
  1837. }
  1838. BOOL IsMMCMultiSelectDataObject(IDataObject* pDataObject)
  1839. {
  1840. _TRACE (1, L"Entering IsMMCMultiSelectDataObject\n");
  1841. if (pDataObject == NULL)
  1842. return FALSE;
  1843. CLIPFORMAT s_cf = 0;
  1844. if (s_cf == 0)
  1845. {
  1846. USES_CONVERSION;
  1847. // security review 2/26/2002 BryanWal ok
  1848. s_cf = (CLIPFORMAT)RegisterClipboardFormat(W2T(CCF_MMC_MULTISELECT_DATAOBJECT));
  1849. }
  1850. FORMATETC fmt = {s_cf, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  1851. BOOL bResult = ((pDataObject->QueryGetData(&fmt) == S_OK));
  1852. _TRACE (-1, L"Leaving IsMMCMultiSelectDataObject - return %d\n", bResult);
  1853. return bResult;
  1854. }
  1855. STDMETHODIMP CCertMgrComponentData::Command (long nCommandID, LPDATAOBJECT pDataObject)
  1856. {
  1857. _TRACE (1, L"Entering CCertMgrComponentData::Command\n");
  1858. HRESULT hr = S_OK;
  1859. switch (nCommandID)
  1860. {
  1861. case IDM_TASK_RENEW_SAME_KEY:
  1862. hr = OnRenew (pDataObject, false);
  1863. break;
  1864. case IDM_TASK_RENEW_NEW_KEY:
  1865. hr = OnRenew (pDataObject, true);
  1866. break;
  1867. case IDM_TASK_IMPORT:
  1868. hr = OnImport (pDataObject);
  1869. break;
  1870. case IDM_TASK_EXPORT:
  1871. hr = OnExport (pDataObject);
  1872. break;
  1873. case IDM_CTL_EDIT:
  1874. hr = OnCTLEdit (pDataObject);
  1875. break;
  1876. case IDM_EDIT_ACRS:
  1877. hr = OnACRSEdit (pDataObject);
  1878. break;
  1879. case IDM_NEW_CTL:
  1880. hr = OnNewCTL (pDataObject);
  1881. break;
  1882. case IDM_TASK_CTL_EXPORT:
  1883. case IDM_TASK_CRL_EXPORT:
  1884. hr = OnExport (pDataObject);
  1885. break;
  1886. case IDM_TASK_EXPORT_STORE:
  1887. hr = OnExport (pDataObject);
  1888. break;
  1889. case IDM_TOP_FIND:
  1890. case IDM_TASK_FIND:
  1891. hr = OnFind (pDataObject);
  1892. break;
  1893. case IDM_TASK_PULSEAUTOENROLL:
  1894. hr = OnPulseAutoEnroll();
  1895. break;
  1896. case IDM_TOP_CHANGE_COMPUTER:
  1897. case IDM_TASK_CHANGE_COMPUTER:
  1898. hr = OnChangeComputer (pDataObject);
  1899. break;
  1900. case IDM_ENROLL_NEW_CERT:
  1901. hr = OnEnroll (pDataObject, true);
  1902. break;
  1903. case IDM_ENROLL_NEW_CERT_SAME_KEY:
  1904. hr = OnEnroll (pDataObject, false);
  1905. break;
  1906. case IDM_ENROLL_NEW_CERT_NEW_KEY:
  1907. hr = OnEnroll (pDataObject, true);
  1908. break;
  1909. case IDM_OPTIONS:
  1910. hr = OnOptions (pDataObject);
  1911. break;
  1912. case IDM_INIT_POLICY:
  1913. hr = OnInitEFSPolicy (pDataObject);
  1914. break;
  1915. case IDM_DEL_POLICY:
  1916. {
  1917. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1918. CString text;
  1919. CString caption;
  1920. int iRetVal = 0;
  1921. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_EFS_POLICY));
  1922. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  1923. hr = m_pConsole->MessageBox (text, caption,
  1924. MB_YESNO, &iRetVal);
  1925. ASSERT (SUCCEEDED (hr));
  1926. if ( SUCCEEDED (hr) && IDYES == iRetVal )
  1927. hr = OnDeleteEFSPolicy (pDataObject, true);
  1928. }
  1929. break;
  1930. case IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT:
  1931. case IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT1:
  1932. case IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT2:
  1933. hr = OnAddDomainEncryptedDataRecoveryAgent (pDataObject);
  1934. break;
  1935. case IDM_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT:
  1936. hr = OnEnroll (pDataObject, true, false); // do not show UI
  1937. break;
  1938. case IDM_NEW_ACRS:
  1939. hr = OnNewACRS (pDataObject);
  1940. break;
  1941. case IDM_SAFER_LEVEL_SET_DEFAULT:
  1942. hr = OnSetSaferLevelDefault (pDataObject);
  1943. break;
  1944. case IDM_SAFER_NEW_ENTRY_PATH:
  1945. case IDM_SAFER_NEW_ENTRY_HASH:
  1946. case IDM_SAFER_NEW_ENTRY_CERTIFICATE:
  1947. case IDM_SAFER_NEW_ENTRY_INTERNET_ZONE:
  1948. hr = OnNewSaferEntry (nCommandID, pDataObject);
  1949. break;
  1950. case IDM_TOP_CREATE_NEW_SAFER_POLICY:
  1951. case IDM_TASK_CREATE_NEW_SAFER_POLICY:
  1952. hr = OnCreateNewSaferPolicy (pDataObject);
  1953. break;
  1954. case IDM_TOP_DELETE_NEW_SAFER_POLICY:
  1955. case IDM_TASK_DELETE_NEW_SAFER_POLICY:
  1956. hr = OnDeleteSaferPolicy (pDataObject);
  1957. break;
  1958. case -1: // Received on forward/back buttons from toolbar
  1959. break;
  1960. default:
  1961. ASSERT (0);
  1962. break;
  1963. }
  1964. _TRACE (-1, L"Leaving CCertMgrComponentData::Command: 0x%x\n", hr);
  1965. return hr;
  1966. }
  1967. HRESULT CCertMgrComponentData::OnNewACRS (LPDATAOBJECT pDataObject)
  1968. {
  1969. _TRACE (1, L"Entering CCertMgrComponentData::OnNewACRS\n");
  1970. ASSERT (pDataObject);
  1971. if ( !pDataObject )
  1972. return E_POINTER;
  1973. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1974. HRESULT hr = S_OK;
  1975. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1976. ASSERT (pCookie);
  1977. if ( pCookie )
  1978. {
  1979. if ( CERTMGR_LOG_STORE_GPE == pCookie->m_objecttype )
  1980. {
  1981. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (pCookie);
  1982. ASSERT (pStore);
  1983. if ( pStore )
  1984. {
  1985. HWND hwndConsole = 0;
  1986. hr = m_pConsole->GetMainWindow (&hwndConsole);
  1987. ASSERT (SUCCEEDED (hr));
  1988. if ( SUCCEEDED (hr) )
  1989. {
  1990. ACRSWizardPropertySheet sheet (pStore, NULL);
  1991. ACRSWizardWelcomePage welcomePage;
  1992. ACRSWizardTypePage typePage;
  1993. ACRSCompletionPage completionPage;
  1994. sheet.AddPage (&welcomePage);
  1995. sheet.AddPage (&typePage);
  1996. sheet.AddPage (&completionPage);
  1997. if ( sheet.DoWizard (hwndConsole) )
  1998. {
  1999. pStore->SetDirty ();
  2000. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  2001. ASSERT (SUCCEEDED (hr));
  2002. }
  2003. }
  2004. }
  2005. else
  2006. hr = E_UNEXPECTED;
  2007. }
  2008. else
  2009. hr = E_UNEXPECTED;
  2010. }
  2011. else
  2012. hr = E_UNEXPECTED;
  2013. _TRACE (-1, L"Leaving CCertMgrComponentData::OnNewACRS: 0x%x\n", hr);
  2014. return hr;
  2015. }
  2016. HRESULT CCertMgrComponentData::RefreshScopePane (LPDATAOBJECT pDataObject)
  2017. {
  2018. _TRACE (1, L"Entering CCertMgrComponentData::RefreshScopePane\n");
  2019. HRESULT hr = S_OK;
  2020. CCertMgrCookie* pCookie = 0;
  2021. if ( pDataObject )
  2022. pCookie = ConvertCookie (pDataObject);
  2023. if ( !pDataObject || pCookie )
  2024. {
  2025. // If m_hRootScopeItem is NULL, then this is an extension and we don't want to go in here.
  2026. if ( !pDataObject || (m_hRootScopeItem && pCookie->m_hScopeItem == m_hRootScopeItem) )
  2027. {
  2028. hr = DeleteScopeItems ();
  2029. ASSERT (SUCCEEDED (hr));
  2030. if ( 1 ) //SUCCEEDED (hr) )
  2031. {
  2032. GUID guid;
  2033. hr = ExpandScopeNodes (m_pRootCookie, m_hRootScopeItem,
  2034. _T (""), 0, guid);
  2035. }
  2036. else if ( E_UNEXPECTED == hr )
  2037. {
  2038. ASSERT (0);
  2039. }
  2040. else if ( E_INVALIDARG == hr )
  2041. {
  2042. ASSERT (0);
  2043. }
  2044. }
  2045. else
  2046. {
  2047. switch (pCookie->m_objecttype)
  2048. {
  2049. case CERTMGR_LOG_STORE_GPE:
  2050. case CERTMGR_LOG_STORE_RSOP:
  2051. case CERTMGR_USAGE:
  2052. case CERTMGR_LOG_STORE:
  2053. case CERTMGR_PHYS_STORE:
  2054. case CERTMGR_CRL_CONTAINER:
  2055. case CERTMGR_CTL_CONTAINER:
  2056. case CERTMGR_CERT_CONTAINER:
  2057. hr = DeleteChildren (pCookie->m_hScopeItem);
  2058. break;
  2059. default:
  2060. break;
  2061. }
  2062. }
  2063. }
  2064. _TRACE (-1, L"Leaving CCertMgrComponentData::RefreshScopePane: 0x%x\n", hr);
  2065. return hr;
  2066. }
  2067. HRESULT CCertMgrComponentData::ExpandScopeNodes (
  2068. CCertMgrCookie* pParentCookie,
  2069. HSCOPEITEM hParent,
  2070. const CString& strServerName,
  2071. DWORD dwLocation,
  2072. const GUID& guidObjectType)
  2073. {
  2074. _TRACE (1, L"Entering CCertMgrComponentData::ExpandScopeNodes\n");
  2075. ASSERT (hParent);
  2076. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2077. CWaitCursor waitCursor;
  2078. HRESULT hr = S_OK;
  2079. if ( pParentCookie )
  2080. {
  2081. CString objectName;
  2082. switch ( pParentCookie->m_objecttype )
  2083. {
  2084. // These node types have no children yet
  2085. case CERTMGR_SNAPIN:
  2086. // We don't expect the handle of the root scope item to change, ever!
  2087. ASSERT ( m_hRootScopeItem ? (m_hRootScopeItem == hParent) : 1);
  2088. if ( !m_hRootScopeItem )
  2089. m_hRootScopeItem = hParent;
  2090. switch (m_activeViewPersist)
  2091. {
  2092. case IDM_USAGE_VIEW:
  2093. hr = AddUsagesToScopePane (hParent, *pParentCookie);
  2094. break;
  2095. case IDM_STORE_VIEW:
  2096. hr = AddLogicalStoresToScopePane (hParent, *pParentCookie);
  2097. break;
  2098. default:
  2099. ASSERT (0);
  2100. hr = E_UNEXPECTED;
  2101. break;
  2102. }
  2103. break;
  2104. // This node type has no children
  2105. case CERTMGR_USAGE:
  2106. case CERTMGR_CRL_CONTAINER:
  2107. case CERTMGR_CTL_CONTAINER:
  2108. case CERTMGR_CERT_CONTAINER:
  2109. break;
  2110. case CERTMGR_PHYS_STORE:
  2111. // Create one each of a CRL_CONTAINER node, CTL_CONTAINER
  2112. // node and CERT container node.
  2113. hr = AddContainersToScopePane (hParent, *pParentCookie,
  2114. false);
  2115. break;
  2116. case CERTMGR_LOG_STORE_RSOP:
  2117. case CERTMGR_LOG_STORE_GPE:
  2118. // This is the Group Policy Editor extension
  2119. // This node type has no children
  2120. break;
  2121. case CERTMGR_LOG_STORE:
  2122. if ( m_bShowPhysicalStoresPersist )
  2123. {
  2124. SPECIAL_STORE_TYPE storeType = NO_SPECIAL_TYPE;
  2125. CCertStore* pCertStoreCookie =
  2126. reinterpret_cast <CCertStore*> (pParentCookie);
  2127. ASSERT (pCertStoreCookie);
  2128. if ( pCertStoreCookie )
  2129. storeType = pCertStoreCookie->GetStoreType ();
  2130. hr = AddPhysicalStoresToScopePane (hParent, *pParentCookie,
  2131. storeType);
  2132. }
  2133. else
  2134. {
  2135. // Create one each of a CRL_CONTAINER node, CTL_CONTAINER
  2136. // node and CERT container node.
  2137. hr = AddContainersToScopePane (hParent, *pParentCookie,
  2138. false);
  2139. }
  2140. break;
  2141. case CERTMGR_CERT_POLICIES_USER:
  2142. // Don't add these nodes for local machine policy
  2143. if ( SCE_MODE_LOCAL_COMPUTER != m_dwSCEMode )
  2144. {
  2145. // Add "Trusted Certificate Authorities"
  2146. VERIFY (objectName.LoadString (IDS_CERTIFICATE_TRUST_LISTS));
  2147. if ( SUCCEEDED (hr) )
  2148. {
  2149. if ( m_pGPEInformation )
  2150. {
  2151. hr = AddScopeNode (new CCertStoreGPE (
  2152. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2153. _T (""),
  2154. (PCWSTR) objectName,
  2155. TRUST_SYSTEM_STORE_NAME,
  2156. _T (""),
  2157. m_pGPEInformation,
  2158. NODEID_User,
  2159. m_pConsole),
  2160. strServerName,
  2161. hParent);
  2162. }
  2163. else if ( m_pRSOPInformationUser )
  2164. {
  2165. hr = AddScopeNode (new CCertStoreRSOP (
  2166. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2167. _T (""),
  2168. (PCWSTR) objectName,
  2169. TRUST_SYSTEM_STORE_NAME,
  2170. _T (""),
  2171. m_rsopObjectArrayUser,
  2172. NODEID_User,
  2173. m_pConsole),
  2174. strServerName,
  2175. hParent);
  2176. }
  2177. }
  2178. }
  2179. break;
  2180. case CERTMGR_CERT_POLICIES_COMPUTER:
  2181. // Add only this node for local machine policy
  2182. // Add "Encrypting File System"
  2183. VERIFY (objectName.LoadString (IDS_ENCRYPTING_FILE_SYSTEM_NODE_NAME));
  2184. if ( m_pGPEInformation )
  2185. {
  2186. hr = AddScopeNode (new CCertStoreGPE (
  2187. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2188. _T (""),
  2189. (PCWSTR) objectName,
  2190. EFS_SYSTEM_STORE_NAME,
  2191. _T (""),
  2192. m_pGPEInformation,
  2193. NODEID_Machine,
  2194. m_pConsole),
  2195. strServerName,
  2196. hParent);
  2197. }
  2198. else if ( m_pRSOPInformationComputer )
  2199. {
  2200. hr = AddScopeNode (new CCertStoreRSOP (
  2201. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2202. _T (""),
  2203. (PCWSTR) objectName,
  2204. EFS_SYSTEM_STORE_NAME,
  2205. _T (""),
  2206. m_rsopObjectArrayComputer,
  2207. NODEID_Machine,
  2208. m_pConsole),
  2209. strServerName,
  2210. hParent);
  2211. }
  2212. if ( SCE_MODE_LOCAL_COMPUTER != m_dwSCEMode )
  2213. {
  2214. // Add these policies if this is the domain policy
  2215. if ( SUCCEEDED (hr) )
  2216. {
  2217. // Add "Automatic Certificate Request Settings"
  2218. VERIFY (objectName.LoadString (IDS_AUTOMATIC_CERT_REQUEST_SETTINGS_NODE_NAME));
  2219. if ( m_pGPEInformation )
  2220. {
  2221. m_pGPEACRSComputerStore = new CCertStoreGPE (
  2222. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2223. _T (""),
  2224. (PCWSTR) objectName,
  2225. ACRS_SYSTEM_STORE_NAME,
  2226. _T (""),
  2227. m_pGPEInformation,
  2228. NODEID_Machine,
  2229. m_pConsole);
  2230. }
  2231. else if ( m_pRSOPInformationComputer )
  2232. {
  2233. m_pGPEACRSComputerStore = new CCertStoreRSOP (
  2234. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2235. _T (""),
  2236. (PCWSTR) objectName,
  2237. ACRS_SYSTEM_STORE_NAME,
  2238. _T (""),
  2239. m_rsopObjectArrayComputer,
  2240. NODEID_Machine,
  2241. m_pConsole);
  2242. }
  2243. if ( m_pGPEACRSComputerStore )
  2244. {
  2245. m_pGPEACRSComputerStore->AddRef ();
  2246. hr = AddScopeNode (m_pGPEACRSComputerStore,
  2247. strServerName, hParent);
  2248. }
  2249. else
  2250. {
  2251. hr = E_OUTOFMEMORY;
  2252. }
  2253. }
  2254. if ( SUCCEEDED (hr) )
  2255. {
  2256. // Add "Domain Root Certificate Authorities"
  2257. VERIFY (objectName.LoadString (IDS_DOMAIN_ROOT_CERT_AUTHS_NODE_NAME));
  2258. ASSERT (!m_pGPERootStore);
  2259. if ( m_pGPEInformation )
  2260. {
  2261. m_pGPERootStore = new CCertStoreGPE (
  2262. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2263. _T (""),
  2264. (PCWSTR) objectName,
  2265. ROOT_SYSTEM_STORE_NAME,
  2266. _T (""),
  2267. m_pGPEInformation,
  2268. NODEID_Machine,
  2269. m_pConsole);
  2270. }
  2271. else if ( m_pRSOPInformationComputer )
  2272. {
  2273. m_pGPERootStore = new CCertStoreRSOP (
  2274. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2275. _T (""),
  2276. (PCWSTR) objectName,
  2277. ROOT_SYSTEM_STORE_NAME,
  2278. _T (""),
  2279. m_rsopObjectArrayComputer,
  2280. NODEID_Machine,
  2281. m_pConsole);
  2282. }
  2283. if ( m_pGPERootStore )
  2284. {
  2285. m_pGPERootStore->AddRef ();
  2286. hr = AddScopeNode (m_pGPERootStore,
  2287. strServerName, hParent);
  2288. }
  2289. else
  2290. {
  2291. hr = E_OUTOFMEMORY;
  2292. }
  2293. }
  2294. if ( SUCCEEDED (hr) )
  2295. {
  2296. // Add "Trusted Certificate Authorities"
  2297. VERIFY (objectName.LoadString (IDS_CERTIFICATE_TRUST_LISTS));
  2298. ASSERT (!m_pGPETrustStore);
  2299. if ( m_pGPEInformation )
  2300. {
  2301. m_pGPETrustStore = new CCertStoreGPE (
  2302. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2303. _T (""),
  2304. (PCWSTR) objectName,
  2305. TRUST_SYSTEM_STORE_NAME,
  2306. _T (""),
  2307. m_pGPEInformation,
  2308. NODEID_Machine,
  2309. m_pConsole);
  2310. }
  2311. else if ( m_pRSOPInformationComputer )
  2312. {
  2313. m_pGPETrustStore = new CCertStoreRSOP (
  2314. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  2315. _T (""),
  2316. (PCWSTR) objectName,
  2317. TRUST_SYSTEM_STORE_NAME,
  2318. _T (""),
  2319. m_rsopObjectArrayComputer,
  2320. NODEID_Machine,
  2321. m_pConsole);
  2322. }
  2323. if ( m_pGPETrustStore )
  2324. {
  2325. m_pGPETrustStore->AddRef ();
  2326. hr = AddScopeNode (m_pGPETrustStore,
  2327. strServerName, hParent);
  2328. }
  2329. else
  2330. {
  2331. hr = E_OUTOFMEMORY;
  2332. }
  2333. }
  2334. }
  2335. break;
  2336. case CERTMGR_SAFER_COMPUTER_ROOT:
  2337. case CERTMGR_SAFER_USER_ROOT:
  2338. {
  2339. CSaferRootCookie* pSaferRootCookie =
  2340. dynamic_cast <CSaferRootCookie*> (pParentCookie);
  2341. if ( pSaferRootCookie )
  2342. {
  2343. pSaferRootCookie->m_bExpandedOnce = true;
  2344. bool bIsComputer =
  2345. (CERTMGR_SAFER_COMPUTER_ROOT == pParentCookie->m_objecttype);
  2346. if ( !m_bIsRSOP )
  2347. {
  2348. // Find out if Safer is supported by the OS
  2349. m_bSaferSupported = false;
  2350. SAFER_LEVEL_HANDLE hLevel = 0;
  2351. CPolicyKey policyKey (m_pGPEInformation,
  2352. SAFER_HKLM_REGBASE,
  2353. CERTMGR_SAFER_COMPUTER_ROOT == pParentCookie->m_objecttype);
  2354. SetRegistryScope (policyKey.GetKey (),
  2355. CERTMGR_SAFER_COMPUTER_ROOT == pParentCookie->m_objecttype);
  2356. BOOL bRVal = SaferCreateLevel (SAFER_SCOPEID_REGISTRY,
  2357. SAFER_LEVELID_FULLYTRUSTED,
  2358. SAFER_LEVEL_OPEN,
  2359. &hLevel,
  2360. policyKey.GetKey ());
  2361. if ( bRVal )
  2362. {
  2363. m_bSaferSupported = true;
  2364. VERIFY (SaferCloseLevel (hLevel));
  2365. }
  2366. else
  2367. {
  2368. DWORD dwErr = GetLastError ();
  2369. _TRACE (0, L"SaferCreateLevel () failed: 0x%x\n", dwErr);
  2370. }
  2371. // Install default file types
  2372. if ( m_bSaferSupported && m_pGPEInformation )
  2373. {
  2374. HKEY hGroupPolicyKey = 0;
  2375. hr = m_pGPEInformation->GetRegistryKey (
  2376. bIsComputer ?
  2377. GPO_SECTION_MACHINE : GPO_SECTION_USER,
  2378. &hGroupPolicyKey);
  2379. if ( SUCCEEDED (hr) )
  2380. {
  2381. // Check to see if safer defaults have already
  2382. // been defined. If not, prompt the user
  2383. // for confirmation. If the response is "no"
  2384. // then do not create the nodes
  2385. PCWSTR pszKeyName = bIsComputer ?
  2386. SAFER_COMPUTER_CODEIDS_REGKEY :
  2387. SAFER_USER_CODEIDS_REGKEY;
  2388. HKEY hCodeIDsKey = 0;
  2389. LONG lResult = RegOpenKeyEx (hGroupPolicyKey,
  2390. pszKeyName, 0, KEY_READ, &hCodeIDsKey);
  2391. if ( ERROR_FILE_NOT_FOUND == lResult )
  2392. {
  2393. pSaferRootCookie->m_bCreateSaferNodes = false;
  2394. ::RegCloseKey (hGroupPolicyKey);
  2395. break;
  2396. }
  2397. else if ( hCodeIDsKey )
  2398. {
  2399. ::RegCloseKey (hCodeIDsKey);
  2400. hCodeIDsKey = 0;
  2401. }
  2402. ::RegCloseKey (hGroupPolicyKey);
  2403. }
  2404. }
  2405. }
  2406. if ( m_bSaferSupported || m_bIsRSOP )
  2407. {
  2408. // Add "Levels" node
  2409. VERIFY (objectName.LoadString (IDS_SAFER_LEVELS_NODE_NAME));
  2410. hr = AddScopeNode (new CCertMgrCookie (
  2411. bIsComputer ?
  2412. CERTMGR_SAFER_COMPUTER_LEVELS : CERTMGR_SAFER_USER_LEVELS,
  2413. 0,
  2414. (PCWSTR) objectName), strServerName, hParent);
  2415. // Add "Entries" node
  2416. if ( SUCCEEDED (hr) )
  2417. {
  2418. VERIFY (objectName.LoadString (IDS_SAFER_ENTRIES_NODE_NAME));
  2419. hr = AddScopeNode (new CSaferEntries (
  2420. bIsComputer,
  2421. strServerName,
  2422. objectName,
  2423. m_pGPEInformation,
  2424. bIsComputer ? m_pRSOPInformationComputer : m_pRSOPInformationUser,
  2425. bIsComputer ? m_rsopObjectArrayComputer : m_rsopObjectArrayUser,
  2426. m_pConsole),
  2427. strServerName, hParent);
  2428. if ( SUCCEEDED (hr) )
  2429. {
  2430. hr = SaferEnumerateLevels (bIsComputer);
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. break;
  2437. case CERTMGR_SAFER_COMPUTER_LEVELS:
  2438. break;
  2439. case CERTMGR_SAFER_USER_LEVELS:
  2440. // TODO: Enumerate user levels
  2441. break;
  2442. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  2443. // TODO: Enumerate computer entries
  2444. break;
  2445. case CERTMGR_SAFER_USER_ENTRIES:
  2446. // TODO: Enumerate user entries
  2447. break;
  2448. case CERTMGR_CERTIFICATE: // not expected in scope pane
  2449. case CERTMGR_CRL:
  2450. case CERTMGR_CTL:
  2451. case CERTMGR_AUTO_CERT_REQUEST:
  2452. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  2453. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  2454. ASSERT (0);
  2455. hr = E_UNEXPECTED;
  2456. break;
  2457. default:
  2458. _TRACE (0, L"CCertMgrComponentData::EnumerateScopeChildren bad parent type\n");
  2459. ASSERT (0);
  2460. hr = S_OK;
  2461. break;
  2462. }
  2463. }
  2464. else
  2465. {
  2466. // If parentCookie not passed in, then this is an extension snap-in
  2467. m_dwLocationPersist = dwLocation;
  2468. if ( m_pGPEInformation || m_pRSOPInformationComputer || m_pRSOPInformationUser )
  2469. {
  2470. CString objectName;
  2471. if ( ::IsEqualGUID (guidObjectType, NODEID_Machine) )
  2472. {
  2473. if ( SUCCEEDED (hr) )
  2474. {
  2475. CLSID classID;
  2476. GetClassID (&classID);
  2477. if ( ::IsEqualGUID (classID, CLSID_CertificateManagerPKPOLExt) )
  2478. {
  2479. // Add "Public Key Policies" node
  2480. VERIFY (objectName.LoadString (IDS_PUBLIC_KEY_POLICIES_NODE_NAME));
  2481. hr = AddScopeNode (new CCertMgrCookie (
  2482. CERTMGR_CERT_POLICIES_COMPUTER,
  2483. 0,
  2484. (PCWSTR) objectName),
  2485. strServerName, hParent);
  2486. }
  2487. else if ( ::IsEqualGUID (classID, CLSID_SaferWindowsExtension) )
  2488. {
  2489. // Add "Software Restriction Policies" node
  2490. VERIFY (objectName.LoadString (IDS_SAFER_WINDOWS_NODE_NAME));
  2491. hr = AddScopeNode (new CSaferRootCookie (
  2492. CERTMGR_SAFER_COMPUTER_ROOT,
  2493. 0,
  2494. (PCWSTR) objectName),
  2495. strServerName, hParent);
  2496. }
  2497. }
  2498. }
  2499. else if ( ::IsEqualGUID (guidObjectType, NODEID_User) )
  2500. {
  2501. if ( SUCCEEDED (hr) )
  2502. {
  2503. CLSID classID;
  2504. GetClassID (&classID);
  2505. if ( ::IsEqualGUID (classID, CLSID_CertificateManagerPKPOLExt) )
  2506. {
  2507. // Add "Public Key Policies" node
  2508. VERIFY (objectName.LoadString (IDS_PUBLIC_KEY_POLICIES_NODE_NAME));
  2509. hr = AddScopeNode (new CCertMgrCookie (
  2510. CERTMGR_CERT_POLICIES_USER,
  2511. 0,
  2512. (PCWSTR) objectName), strServerName, hParent);
  2513. }
  2514. else if ( ::IsEqualGUID (classID, CLSID_SaferWindowsExtension) )
  2515. {
  2516. if ( SCE_MODE_LOCAL_USER != m_dwSCEMode )
  2517. {
  2518. // Add "Software Restriction Policies" node
  2519. VERIFY (objectName.LoadString (IDS_SAFER_WINDOWS_NODE_NAME));
  2520. hr = AddScopeNode (new CSaferRootCookie (
  2521. CERTMGR_SAFER_USER_ROOT,
  2522. 0,
  2523. (PCWSTR) objectName), strServerName, hParent);
  2524. }
  2525. }
  2526. }
  2527. }
  2528. }
  2529. }
  2530. _TRACE (-1, L"Leaving CCertMgrComponentData::ExpandScopeNodes: 0x%x\n", hr);
  2531. return hr;
  2532. }
  2533. HRESULT CCertMgrComponentData::DeleteScopeItems (HSCOPEITEM hScopeItem /* = 0 */)
  2534. {
  2535. _TRACE (1, L"Entering CCertMgrComponentData::DeleteScopeItems\n");
  2536. HRESULT hr = S_OK;
  2537. if ( m_pGPERootStore )
  2538. {
  2539. m_pGPERootStore->Release ();
  2540. m_pGPERootStore = 0;
  2541. }
  2542. if ( m_pGPETrustStore )
  2543. {
  2544. m_pGPETrustStore->Release ();
  2545. m_pGPETrustStore = 0;
  2546. }
  2547. if ( m_pGPEACRSComputerStore )
  2548. {
  2549. m_pGPEACRSComputerStore->Release ();
  2550. m_pGPEACRSComputerStore = 0;
  2551. }
  2552. if ( m_pGPEACRSUserStore )
  2553. {
  2554. m_pGPEACRSUserStore->Release ();
  2555. m_pGPEACRSUserStore = 0;
  2556. }
  2557. if ( m_pFileBasedStore )
  2558. {
  2559. m_pFileBasedStore->Release ();
  2560. m_pFileBasedStore = 0;
  2561. }
  2562. hr = DeleteChildren (hScopeItem ? hScopeItem : m_hRootScopeItem);
  2563. _TRACE (-1, L"Leaving CCertMgrComponentData::DeleteScopeItems: 0x%x\n", hr);
  2564. return hr;
  2565. }
  2566. HRESULT CCertMgrComponentData::DeleteChildren (HSCOPEITEM hParent)
  2567. {
  2568. _TRACE (1, L"Entering CCertMgrComponentData::DeleteChildren\n");
  2569. if ( !hParent )
  2570. return S_OK;
  2571. HSCOPEITEM hChild = 0;
  2572. HSCOPEITEM hNextChild = 0;
  2573. MMC_COOKIE lCookie = 0;
  2574. CCertMgrCookie* pCookie = 0;
  2575. HRESULT hr = S_OK;
  2576. CCookie& rootCookie = QueryBaseRootCookie ();
  2577. // Optimization: If we're deleting everything below the root, free all
  2578. // the result items here so we don't have to go looking for them later by
  2579. // store
  2580. if ( hParent == m_hRootScopeItem )
  2581. {
  2582. LPRESULTDATA pResultData = 0;
  2583. hr = GetResultData (&pResultData);
  2584. if ( SUCCEEDED (hr) )
  2585. {
  2586. hr = pResultData->DeleteAllRsltItems ();
  2587. if ( SUCCEEDED (hr) || E_UNEXPECTED == hr ) // returns E_UNEXPECTED if console shutting down
  2588. {
  2589. RemoveResultCookies (pResultData);
  2590. }
  2591. else
  2592. {
  2593. _TRACE (0, L"IResultData::DeleteAllRsltItems () failed: 0x%x\n", hr);
  2594. }
  2595. pResultData->Release ();
  2596. }
  2597. }
  2598. hr = m_pConsoleNameSpace->GetChildItem (hParent, &hChild, &lCookie);
  2599. ASSERT (SUCCEEDED (hr) || E_FAIL == hr); // appears to return E_FAIL when there are no children
  2600. while ( SUCCEEDED (hr) && hChild )
  2601. {
  2602. pCookie = reinterpret_cast <CCertMgrCookie*> (lCookie);
  2603. hr = DeleteChildren (hChild);
  2604. if ( !SUCCEEDED (hr) )
  2605. break;
  2606. hNextChild = 0;
  2607. hr = m_pConsoleNameSpace->GetNextItem (hChild, &hNextChild, &lCookie);
  2608. ASSERT (SUCCEEDED (hr));
  2609. hr = m_pConsoleNameSpace->DeleteItem (hChild, TRUE);
  2610. ASSERT (SUCCEEDED (hr));
  2611. switch (pCookie->m_objecttype)
  2612. {
  2613. case CERTMGR_LOG_STORE:
  2614. case CERTMGR_LOG_STORE_GPE:
  2615. case CERTMGR_LOG_STORE_RSOP:
  2616. case CERTMGR_PHYS_STORE:
  2617. {
  2618. // If this is a store, delete all the result nodes that belong to this
  2619. // store. We can tell if objects were enumerated from this store simply
  2620. // by comparing the store handles.
  2621. CCertStore* pStore = reinterpret_cast <CCertStore*> (pCookie);
  2622. ASSERT (pStore);
  2623. if ( pStore )
  2624. {
  2625. // If the store is not 'open' (it's HCERTSTORE handle is still '0')
  2626. // then we can skip checking this list. We haven't enumerated anything
  2627. // in this store.
  2628. if ( pStore->IsOpen () )
  2629. {
  2630. POSITION pos1 = 0;
  2631. POSITION pos2 = 0;
  2632. CBaseCookieBlock* pResultCookie = 0;
  2633. HCERTSTORE hStoreHandle = pStore->GetStoreHandle ();
  2634. // As an optimization, if DeleteChildren was originally called with
  2635. // the root scope item, all the result cookies have already been
  2636. // deleted since we're going to delete them all anyway.
  2637. for (pos1 = rootCookie.m_listResultCookieBlocks.GetHeadPosition();
  2638. (pos2 = pos1) != NULL; )
  2639. {
  2640. pResultCookie = rootCookie.m_listResultCookieBlocks.GetNext (pos1);
  2641. ASSERT (pResultCookie);
  2642. if ( pResultCookie )
  2643. {
  2644. hr = ReleaseResultCookie (pResultCookie,
  2645. rootCookie, hStoreHandle, pos2);
  2646. }
  2647. }
  2648. pStore->Close ();
  2649. }
  2650. }
  2651. }
  2652. // fall through
  2653. case CERTMGR_CRL_CONTAINER:
  2654. case CERTMGR_CTL_CONTAINER:
  2655. case CERTMGR_CERT_CONTAINER:
  2656. case CERTMGR_USAGE:
  2657. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  2658. case CERTMGR_SAFER_USER_ENTRIES:
  2659. {
  2660. POSITION pos1 = 0;
  2661. POSITION pos2 = 0;
  2662. CBaseCookieBlock* pResultCookie = 0;
  2663. // Find and remove this cookie from the scope cookie list
  2664. for (pos1 = rootCookie.m_listScopeCookieBlocks.GetHeadPosition();
  2665. pos1 != NULL; )
  2666. {
  2667. pos2 = pos1;
  2668. pResultCookie = rootCookie.m_listScopeCookieBlocks.GetNext (pos1);
  2669. ASSERT (pResultCookie);
  2670. if ( pResultCookie )
  2671. {
  2672. if ( pResultCookie->QueryBaseCookie (0) == pCookie )
  2673. {
  2674. rootCookie.m_listScopeCookieBlocks.RemoveAt (pos2);
  2675. pResultCookie->Release ();
  2676. break;
  2677. }
  2678. }
  2679. }
  2680. }
  2681. break;
  2682. default:
  2683. break;
  2684. }
  2685. hChild = hNextChild;
  2686. }
  2687. _TRACE (-1, L"Leaving CCertMgrComponentData::DeleteChildren: 0x%x\n", hr);
  2688. return hr;
  2689. }
  2690. CertificateManagerObjectType CCertMgrComponentData::GetObjectType (LPDATAOBJECT pDataObject)
  2691. {
  2692. _TRACE (1, L"Entering CCertMgrComponentData::GetObjectType\n");
  2693. CertificateManagerObjectType objType = CERTMGR_INVALID;
  2694. ASSERT (pDataObject);
  2695. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  2696. if ( ((CCertMgrCookie*) MMC_MULTI_SELECT_COOKIE) == pCookie )
  2697. objType = CERTMGR_MULTISEL;
  2698. else if ( pCookie )
  2699. objType = pCookie->m_objecttype;
  2700. _TRACE (-1, L"Leaving CCertMgrComponentData::GetObjectType\n");
  2701. return objType;
  2702. }
  2703. HRESULT CCertMgrComponentData::OnPulseAutoEnroll()
  2704. {
  2705. _TRACE (1, L"Entering CCertMgrComponentData::OnPulseAutoEnroll\n");
  2706. HRESULT hr = S_OK;
  2707. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2708. HANDLE hEvent = NULL;
  2709. LPWSTR wszEventName;
  2710. // pulse autoenroll event here, choose between machine or user
  2711. // user or machine pulse?
  2712. wszEventName = L"Global\\" MACHINE_AUTOENROLLMENT_TRIGGER_EVENT;
  2713. if (CERT_SYSTEM_STORE_CURRENT_USER == m_dwLocationPersist)
  2714. wszEventName = USER_AUTOENROLLMENT_TRIGGER_EVENT;
  2715. hEvent=OpenEvent(EVENT_MODIFY_STATE, false, wszEventName);
  2716. if (NULL==hEvent)
  2717. {
  2718. DWORD dwErr = GetLastError();
  2719. CString text;
  2720. CString caption;
  2721. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2722. text.FormatMessage (IDS_CANT_OPEN_AUTOENROLL_EVENT, GetSystemMessage (dwErr));
  2723. int iRetVal = 0;
  2724. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption, MB_OK, &iRetVal)));
  2725. hr=HRESULT_FROM_WIN32(dwErr);
  2726. _TRACE (0, L"OpenEvent(%s) failed with 0x%08X.\n", wszEventName, hr);
  2727. goto error;
  2728. }
  2729. if (!SetEvent(hEvent))
  2730. {
  2731. DWORD dwErr = GetLastError();
  2732. DisplaySystemError (dwErr);
  2733. hr=HRESULT_FROM_WIN32(dwErr);
  2734. _TRACE (0, L"SetEvent failed with 0x%08X.\n", hr);
  2735. goto error;
  2736. }
  2737. error:
  2738. if (NULL!=hEvent)
  2739. CloseHandle(hEvent);
  2740. _TRACE (-1, L"Leaving CCertMgrComponentData::OnPulseAutoEnroll: 0x%x\n", hr);
  2741. return hr;
  2742. }
  2743. HRESULT CCertMgrComponentData::OnFind (LPDATAOBJECT pDataObject)
  2744. {
  2745. _TRACE (1, L"Entering CCertMgrComponentData::OnFind\n");
  2746. HRESULT hr = S_OK;
  2747. ASSERT (pDataObject);
  2748. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2749. HWND hParent = 0;
  2750. ASSERT (pDataObject);
  2751. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  2752. if ( pParentCookie )
  2753. {
  2754. switch (pParentCookie->m_objecttype)
  2755. {
  2756. case CERTMGR_SNAPIN:
  2757. case CERTMGR_PHYS_STORE:
  2758. case CERTMGR_LOG_STORE:
  2759. case CERTMGR_LOG_STORE_GPE:
  2760. case CERTMGR_LOG_STORE_RSOP:
  2761. case CERTMGR_USAGE:
  2762. {
  2763. // Get parent window handle and attach to a CWnd object
  2764. hr = m_pConsole->GetMainWindow (&hParent);
  2765. ASSERT (SUCCEEDED (hr));
  2766. if ( SUCCEEDED (hr) )
  2767. {
  2768. CWnd parentWnd;
  2769. VERIFY (parentWnd.Attach (hParent));
  2770. CFindDialog findDlg (&parentWnd,
  2771. pParentCookie->QueryNonNULLMachineName (),
  2772. m_szFileName,
  2773. this);
  2774. CThemeContextActivator activator;
  2775. INT_PTR iReturn = findDlg.DoModal ();
  2776. ASSERT (-1 != iReturn && IDABORT != iReturn);
  2777. if ( -1 == iReturn || IDABORT == iReturn )
  2778. hr = E_UNEXPECTED;
  2779. else
  2780. {
  2781. if ( findDlg.ConsoleRefreshRequired () )
  2782. {
  2783. hr = m_pConsole->UpdateAllViews (pDataObject, 0,
  2784. HINT_REFRESH_STORES);
  2785. }
  2786. }
  2787. parentWnd.Detach ();
  2788. }
  2789. }
  2790. break;
  2791. case CERTMGR_CERTIFICATE:
  2792. case CERTMGR_CRL:
  2793. case CERTMGR_CTL:
  2794. case CERTMGR_AUTO_CERT_REQUEST:
  2795. ASSERT (0);
  2796. hr = E_UNEXPECTED;
  2797. break;
  2798. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  2799. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  2800. ASSERT (0);
  2801. break;
  2802. case CERTMGR_CRL_CONTAINER:
  2803. case CERTMGR_CTL_CONTAINER:
  2804. case CERTMGR_CERT_CONTAINER:
  2805. break;
  2806. default:
  2807. ASSERT (0);
  2808. hr = E_UNEXPECTED;
  2809. }
  2810. }
  2811. _TRACE (-1, L"Leaving CCertMgrComponentData::OnFind: 0x%x\n", hr);
  2812. return hr;
  2813. }
  2814. HRESULT CCertMgrComponentData::OnChangeComputer (LPDATAOBJECT pDataObject)
  2815. {
  2816. if ( !pDataObject )
  2817. return E_POINTER;
  2818. _TRACE (1, L"Entering CCertMgrComponentData::OnChangeComputer\n");
  2819. HRESULT hr = S_OK;
  2820. ASSERT (pDataObject);
  2821. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2822. ASSERT (pDataObject);
  2823. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  2824. if ( pParentCookie && CERTMGR_SNAPIN == pParentCookie->m_objecttype )
  2825. {
  2826. HWND hWndParent = NULL;
  2827. hr = m_pConsole->GetMainWindow (&hWndParent);
  2828. CString machineName;
  2829. hr = ComputerNameFromObjectPicker (hWndParent, machineName);
  2830. if ( S_OK == hr ) // S_FALSE means user pressed "Cancel"
  2831. {
  2832. machineName.MakeUpper ();
  2833. // added IsLocalComputername 1/27/99 JonN
  2834. // If the user chooses the local computer, treat that as if they had chosen
  2835. // "Local Computer" in Snapin Manager. This means that there is no way to
  2836. // reset the snapin to target explicitly at this computer without either
  2837. // reloading the snapin from Snapin Manager, or going to a different computer.
  2838. // When the Choose Target Computer UI is revised, we can make this more
  2839. // consistent with Snapin Manager.
  2840. if ( IsLocalComputername( machineName ) )
  2841. machineName = L"";
  2842. QueryRootCookie().SetMachineName (machineName);
  2843. // Set the persistent name. If we are managing the local computer
  2844. // this name should be empty.
  2845. m_strMachineNamePersist = machineName;
  2846. hr = ChangeRootNodeName (machineName);
  2847. if ( SUCCEEDED(hr) )
  2848. {
  2849. hr = m_pConsole->UpdateAllViews (pDataObject, 0, HINT_CHANGE_COMPUTER);
  2850. }
  2851. }
  2852. }
  2853. else
  2854. hr = E_UNEXPECTED;
  2855. _TRACE (-1, L"Leaving CCertMgrComponentData::OnChangeComputer: 0x%x\n", hr);
  2856. return hr;
  2857. }
  2858. HRESULT CCertMgrComponentData::IsUserAdministrator (BOOL & bIsAdministrator)
  2859. {
  2860. _TRACE (1, L"Entering CCertMgrComponentData::IsUserAdministrator\n");
  2861. HRESULT hr = S_OK;
  2862. DWORD dwErr = 0;
  2863. bIsAdministrator = FALSE;
  2864. if ( IsWindowsNT () )
  2865. {
  2866. PSID psidAdministrators;
  2867. SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
  2868. // security review 2/26/2002 BryanWal ok
  2869. BOOL bResult = ::AllocateAndInitializeSid (&siaNtAuthority, 2,
  2870. SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
  2871. 0, 0, 0, 0, 0, 0, &psidAdministrators);
  2872. if ( bResult )
  2873. {
  2874. bResult = CheckTokenMembership (0, psidAdministrators,
  2875. &bIsAdministrator);
  2876. ASSERT (bResult);
  2877. if ( !bResult )
  2878. {
  2879. dwErr = GetLastError ();
  2880. DisplaySystemError (dwErr);
  2881. hr = HRESULT_FROM_WIN32 (dwErr);
  2882. }
  2883. FreeSid (psidAdministrators);
  2884. }
  2885. else
  2886. {
  2887. dwErr = GetLastError ();
  2888. DisplaySystemError (dwErr);
  2889. hr = HRESULT_FROM_WIN32 (dwErr);
  2890. }
  2891. }
  2892. _TRACE (-1, L"Leaving CCertMgrComponentData::IsUserAdministrator: 0x%x\n", hr);
  2893. return hr;
  2894. }
  2895. void CCertMgrComponentData::DisplaySystemError (DWORD dwErr)
  2896. {
  2897. _TRACE (1, L"Entering CCertMgrComponentData::DisplaySystemError\n");
  2898. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2899. LPVOID lpMsgBuf;
  2900. // security review 2/26/2002 BryanWal ok - message is from system
  2901. ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  2902. NULL,
  2903. dwErr,
  2904. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  2905. (PWSTR) &lpMsgBuf, 0, NULL );
  2906. // Display the string.
  2907. CString caption;
  2908. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2909. int iRetVal = 0;
  2910. if ( m_pConsole )
  2911. {
  2912. HRESULT hr = m_pConsole->MessageBox ( (PWSTR) lpMsgBuf, caption,
  2913. MB_ICONWARNING | MB_OK, &iRetVal);
  2914. ASSERT (SUCCEEDED (hr));
  2915. }
  2916. else
  2917. {
  2918. CThemeContextActivator activator;
  2919. ::MessageBox (NULL, (PWSTR) lpMsgBuf, caption, MB_ICONWARNING | MB_OK);
  2920. }
  2921. // Free the buffer.
  2922. LocalFree (lpMsgBuf);
  2923. _TRACE (-1, L"Leaving CCertMgrComponentData::DisplaySystemError\n");
  2924. }
  2925. CString CCertMgrComponentData::GetCommandLineFileName () const
  2926. {
  2927. _TRACE (0, L"Entering and leaving CCertMgrComponentData::GetCommandLineFileName\n");
  2928. return m_szFileName;
  2929. }
  2930. //
  2931. // GetManagedComputer ()
  2932. //
  2933. // Returns the name of the managed computer. If we are managing the local machine
  2934. // returns an empty string. (As required by a number of Crypt32 APIs
  2935. //
  2936. CString CCertMgrComponentData::GetManagedComputer () const
  2937. {
  2938. _TRACE (0, L"Entering and leaving CCertMgrComponentData::GetManagedComputer\n");
  2939. if ( m_szManagedComputer.CompareNoCase (m_szThisComputer) ) // !=
  2940. {
  2941. return m_szManagedComputer;
  2942. }
  2943. else
  2944. return _T ("");
  2945. }
  2946. CString CCertMgrComponentData::GetManagedService () const
  2947. {
  2948. _TRACE (0, L"Entering and leaving CCertMgrComponentData::GetManagedService\n");
  2949. return m_szManagedServicePersist;
  2950. }
  2951. DWORD CCertMgrComponentData::GetLocation () const
  2952. {
  2953. _TRACE (0, L"Entering and leaving CCertMgrComponentData::GetLocation\n");
  2954. return m_dwLocationPersist;
  2955. }
  2956. LPCONSOLENAMESPACE CCertMgrComponentData::GetConsoleNameSpace () const
  2957. {
  2958. _TRACE (0, L"Entering and leaving CCertMgrComponentData::GetConsoleNameSpace\n");
  2959. return m_pConsoleNameSpace;
  2960. }
  2961. CUsageCookie* CCertMgrComponentData::FindDuplicateUsage (HSCOPEITEM hParent, PCWSTR pszName)
  2962. {
  2963. _TRACE (1, L"Entering CCertMgrComponentData::FindDuplicateUsage\n");
  2964. ASSERT (pszName);
  2965. if ( !pszName )
  2966. return 0;
  2967. CUsageCookie* pUsageCookie = 0;
  2968. MMC_COOKIE lCookie = 0;
  2969. HSCOPEITEM hChildItem = 0;
  2970. bool bFound = false;
  2971. HRESULT hr = m_pConsoleNameSpace->GetChildItem (hParent, &hChildItem, &lCookie);
  2972. ASSERT (SUCCEEDED (hr));
  2973. while ( hChildItem && SUCCEEDED (hr) )
  2974. {
  2975. pUsageCookie = reinterpret_cast <CUsageCookie*> (lCookie);
  2976. if ( !wcscoll (pszName, pUsageCookie->GetObjectName ()) )
  2977. {
  2978. bFound = true;
  2979. break;
  2980. }
  2981. hr = m_pConsoleNameSpace->GetNextItem (hChildItem, &hChildItem, &lCookie);
  2982. ASSERT (SUCCEEDED (hr));
  2983. }
  2984. _TRACE (-1, L"Leaving CCertMgrComponentData::FindDuplicateUsage\n");
  2985. if ( bFound )
  2986. return pUsageCookie;
  2987. else
  2988. return NULL;
  2989. }
  2990. bool CCertMgrComponentData::IsSecurityConfigurationEditorNodetype (const GUID& refguid) const
  2991. {
  2992. _TRACE (0, L"Entering and leaving CCertMgrComponentData::IsSecurityConfigurationEditorNodetype\n");
  2993. return ::IsEqualGUID (refguid, cNodetypeSceTemplate) ? true : false;
  2994. }
  2995. HRESULT CCertMgrComponentData::OnEnroll (
  2996. LPDATAOBJECT pDataObject,
  2997. bool bNewKey,
  2998. bool bShowUI /* = true */)
  2999. {
  3000. _TRACE (1, L"Entering CCertMgrComponentData::OnEnroll\n");
  3001. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  3002. ASSERT (pDataObject);
  3003. if ( !pDataObject )
  3004. return E_POINTER;
  3005. HRESULT hr = S_OK;
  3006. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  3007. if ( pParentCookie )
  3008. {
  3009. CCertStore* pStore = 0;
  3010. CCertificate* pCert = 0;
  3011. CCertStoreGPE* pGPEStore = 0;
  3012. bool bParentIsStoreOrContainer = false;
  3013. HSCOPEITEM hScopeItem = 0;
  3014. bool bEFSPolicyTurnedOn = false;
  3015. switch (pParentCookie->m_objecttype)
  3016. {
  3017. case CERTMGR_CERTIFICATE:
  3018. pCert = reinterpret_cast <CCertificate*> (pParentCookie);
  3019. ASSERT (pCert);
  3020. break;
  3021. case CERTMGR_PHYS_STORE:
  3022. case CERTMGR_LOG_STORE:
  3023. if ( !m_pGPEInformation ) // If we are not extending the GPE/SCE
  3024. {
  3025. hScopeItem = pParentCookie->m_hScopeItem; // = 0;
  3026. pStore = reinterpret_cast <CCertStore*> (pParentCookie);
  3027. ASSERT (pStore);
  3028. }
  3029. bParentIsStoreOrContainer = true;
  3030. break;
  3031. case CERTMGR_CERT_CONTAINER:
  3032. if ( !m_pGPEInformation ) // If we are not extending the GPE/SCE
  3033. {
  3034. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pParentCookie);
  3035. ASSERT (pContainer);
  3036. if ( pContainer )
  3037. {
  3038. MMC_COOKIE lCookie = 0;
  3039. hr = m_pConsoleNameSpace->GetParentItem (
  3040. pContainer->m_hScopeItem, &hScopeItem, &lCookie);
  3041. ASSERT (SUCCEEDED (hr));
  3042. pStore = &pContainer->GetCertStore ();
  3043. }
  3044. }
  3045. bParentIsStoreOrContainer = true;
  3046. break;
  3047. case CERTMGR_USAGE:
  3048. break;
  3049. case CERTMGR_LOG_STORE_RSOP:
  3050. ASSERT (0);
  3051. return E_FAIL;
  3052. break;
  3053. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  3054. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  3055. ASSERT (0);
  3056. break;
  3057. case CERTMGR_LOG_STORE_GPE:
  3058. pGPEStore = reinterpret_cast <CCertStoreGPE*> (pParentCookie);
  3059. ASSERT (pGPEStore);
  3060. if ( pGPEStore )
  3061. {
  3062. if ( pGPEStore->IsNullEFSPolicy () )
  3063. {
  3064. pGPEStore->AllowEmptyEFSPolicy ();
  3065. bEFSPolicyTurnedOn = true;
  3066. }
  3067. }
  3068. else
  3069. return E_FAIL;
  3070. break;
  3071. default:
  3072. ASSERT (0);
  3073. return E_UNEXPECTED;
  3074. }
  3075. HWND hwndParent = 0;
  3076. hr = m_pConsole->GetMainWindow (&hwndParent);
  3077. ASSERT (SUCCEEDED (hr));
  3078. CRYPTUI_WIZ_CERT_REQUEST_PVK_CERT pvkCert;
  3079. CRYPTUI_WIZ_CERT_REQUEST_PVK_NEW pvkNew;
  3080. CRYPTUI_WIZ_CERT_REQUEST_INFO certRequestInfo;
  3081. CRYPT_KEY_PROV_INFO provInfo;
  3082. // For EFS Recovery Agent
  3083. CRYPTUI_WIZ_CERT_TYPE certType;
  3084. PWSTR rgwszCertType = wszCERTTYPE_EFS_RECOVERY;
  3085. // security review 2/26/2002 BryanWal ok
  3086. ::ZeroMemory (&certRequestInfo, sizeof (certRequestInfo));
  3087. certRequestInfo.dwSize = sizeof (certRequestInfo);
  3088. certRequestInfo.dwPurpose = CRYPTUI_WIZ_CERT_ENROLL;
  3089. // User wants to manage user account
  3090. // pass in NULL to machine name and to account name
  3091. // User wants to manage local machine account
  3092. // pass in NULL for account name and result of ::GetComputerName ()
  3093. // to machine name
  3094. // User want to manage remote machine
  3095. // pass in NULL for account name and machine name for machineName
  3096. // User wants to manage remote account on remote machine
  3097. // pass in account name for accountName and machine name for machineName
  3098. switch (m_dwLocationPersist)
  3099. {
  3100. case CERT_SYSTEM_STORE_CURRENT_SERVICE:
  3101. case CERT_SYSTEM_STORE_SERVICES:
  3102. certRequestInfo.pwszMachineName = (PCWSTR) m_szManagedComputer;
  3103. certRequestInfo.pwszAccountName = (PCWSTR) m_szManagedServicePersist;
  3104. break;
  3105. case CERT_SYSTEM_STORE_CURRENT_USER:
  3106. certRequestInfo.pwszMachineName = NULL;
  3107. certRequestInfo.pwszAccountName = NULL;
  3108. break;
  3109. case CERT_SYSTEM_STORE_LOCAL_MACHINE:
  3110. certRequestInfo.pwszMachineName = (PCWSTR) m_szManagedComputer;
  3111. certRequestInfo.pwszAccountName = NULL;
  3112. break;
  3113. case CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY:
  3114. case CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY:
  3115. certRequestInfo.pwszMachineName = NULL;
  3116. certRequestInfo.pwszAccountName = NULL;
  3117. certRequestInfo.pwszDesStore = 0;
  3118. certRequestInfo.dwCertOpenStoreFlag = 0;
  3119. break;
  3120. default:
  3121. ASSERT (0);
  3122. return E_UNEXPECTED;
  3123. break;
  3124. }
  3125. if ( !pCert || bNewKey )
  3126. {
  3127. // Request a certificate with a new key
  3128. certRequestInfo.dwPvkChoice = CRYPTUI_WIZ_CERT_REQUEST_PVK_CHOICE_NEW;
  3129. // security review 2/26/2002 BryanWal ok
  3130. ::ZeroMemory (&pvkNew, sizeof (pvkNew));
  3131. pvkNew.dwSize = sizeof (pvkNew);
  3132. certRequestInfo.pPvkNew = &pvkNew;
  3133. if ( CERT_SYSTEM_STORE_LOCAL_MACHINE == m_dwLocationPersist )
  3134. {
  3135. // security review 2/26/2002 BryanWal ok
  3136. ::ZeroMemory (&provInfo, sizeof (provInfo));
  3137. provInfo.dwFlags = CRYPT_MACHINE_KEYSET;
  3138. pvkNew.pKeyProvInfo = &provInfo;
  3139. }
  3140. if ( pGPEStore && EFS_STORE == pGPEStore->GetStoreType () )
  3141. {
  3142. // This creates an Encryption Recovery Agent.
  3143. // security review 2/26/2002 BryanWal ok
  3144. ::ZeroMemory (&certType, sizeof (certType));
  3145. certType.dwSize = sizeof (CRYPTUI_WIZ_CERT_TYPE);
  3146. certType.cCertType = 1;
  3147. certType.rgwszCertType = &rgwszCertType;
  3148. certRequestInfo.dwCertChoice = CRYPTUI_WIZ_CERT_REQUEST_CERT_TYPE;
  3149. certRequestInfo.pCertType = &certType;
  3150. // security review 2/26/2002 BryanWal ok
  3151. ::ZeroMemory (&provInfo, sizeof (provInfo));
  3152. provInfo.pwszProvName = MS_DEF_PROV_W;
  3153. provInfo.dwProvType = PROV_RSA_FULL;
  3154. pvkNew.pKeyProvInfo = &provInfo;
  3155. pvkNew.dwGenKeyFlags = CRYPT_EXPORTABLE;
  3156. }
  3157. }
  3158. else
  3159. {
  3160. // Request a certificate with the same key as an existing certificate
  3161. if ( IsLocalComputername (m_szManagedComputer) )
  3162. {
  3163. // Find out if the cert has a private key before continuing.
  3164. DWORD dwFlags = 0;
  3165. if ( CERT_SYSTEM_STORE_LOCAL_MACHINE == m_dwLocationPersist )
  3166. dwFlags = CRYPT_FIND_MACHINE_KEYSET_FLAG;
  3167. if ( !::CryptFindCertificateKeyProvInfo (
  3168. pCert->GetCertContext (), dwFlags, 0) )
  3169. {
  3170. DWORD dwErr = GetLastError ();
  3171. _TRACE (0, L"CryptFindCertificateKeyProvInfo () failed: 0x%x\n",
  3172. dwErr);
  3173. CString text;
  3174. CString caption;
  3175. CThemeContextActivator activator;
  3176. text.FormatMessage (IDS_NO_PRIVATE_KEY,
  3177. GetSystemMessage (dwErr));
  3178. VERIFY (caption.LoadString (IDS_REQUEST_CERT_SAME_KEY));
  3179. ::MessageBox (hwndParent, text, caption, MB_OK);
  3180. return hr;
  3181. }
  3182. }
  3183. certRequestInfo.dwPvkChoice = CRYPTUI_WIZ_CERT_REQUEST_PVK_CHOICE_CERT;
  3184. // security review 2/26/2002 BryanWal ok
  3185. ::ZeroMemory (&pvkCert, sizeof (pvkCert));
  3186. pvkCert.dwSize = sizeof (pvkCert);
  3187. pvkCert.pCertContext = pCert->GetCertContext ();
  3188. certRequestInfo.pPvkCert = &pvkCert;
  3189. }
  3190. certRequestInfo.pwszCertDNName = NULL;
  3191. // Now that all the preliminaries are out of they way and the data is
  3192. // all set up, call the enrollment wizard.
  3193. DWORD status = 0;
  3194. PCCERT_CONTEXT pNewCertContext = 0;
  3195. BOOL bResult = FALSE;
  3196. CThemeContextActivator activator;
  3197. DWORD dwErr = 0;
  3198. while (1)
  3199. {
  3200. // this must be inside the while statement as bNewKey can change
  3201. DWORD dwFlags = 0;
  3202. if ( !bShowUI )
  3203. dwFlags |= CRYPTUI_WIZ_NO_UI;
  3204. if ( bNewKey )
  3205. dwFlags |= CRYPTUI_WIZ_CERT_REQUEST_REQUIRE_NEW_KEY;
  3206. bResult = ::CryptUIWizCertRequest (
  3207. dwFlags,
  3208. hwndParent,
  3209. NULL,
  3210. &certRequestInfo,
  3211. &pNewCertContext,
  3212. &status);
  3213. dwErr = GetLastError ();
  3214. if ( !bResult && NTE_TOKEN_KEYSET_STORAGE_FULL == HRESULT_FROM_WIN32 (dwErr) )
  3215. {
  3216. // NTRAID# 299089 Enrollment Wizard: Should return some
  3217. // meaningful message when users fail to enroll/renew on a
  3218. // smart card
  3219. if ( !bNewKey )
  3220. break;
  3221. CString text;
  3222. CString caption;
  3223. int iRetVal = 0;
  3224. VERIFY (text.LoadString (IDS_SMARTCARD_FULL_REUSE_PRIVATE_KEY));
  3225. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  3226. hr = m_pConsole->MessageBox (text, caption,
  3227. MB_YESNO, &iRetVal);
  3228. ASSERT (SUCCEEDED (hr));
  3229. if ( IDYES == iRetVal )
  3230. {
  3231. bNewKey = false;
  3232. }
  3233. else
  3234. break;
  3235. }
  3236. else
  3237. break;
  3238. }
  3239. if ( !bResult && !bShowUI )
  3240. {
  3241. CString text;
  3242. CString caption;
  3243. int iRetVal = 0;
  3244. text.FormatMessage (IDS_CANNOT_CREATE_DATA_RECOVERY_AGENT,
  3245. GetSystemMessage (dwErr));
  3246. VERIFY (caption.LoadString (IDS_PUBLIC_KEY_POLICIES_NODE_NAME));
  3247. if ( m_pConsole )
  3248. {
  3249. hr = m_pConsole->MessageBox (text, caption, MB_OK, &iRetVal);
  3250. ASSERT (SUCCEEDED (hr));
  3251. }
  3252. }
  3253. else if ( bResult && (CRYPTUI_WIZ_CERT_REQUEST_STATUS_SUCCEEDED == status) && pNewCertContext )
  3254. {
  3255. if ( bEFSPolicyTurnedOn )
  3256. {
  3257. // Force scope item selection to for call to
  3258. // IComponent::QueryResultViewType ()
  3259. hr = m_pComponentConsole->SelectScopeItem (pGPEStore->m_hScopeItem);
  3260. hr = m_pConsole->UpdateAllViews (pDataObject, 0, HINT_EFS_ADD_DEL_POLICY);
  3261. hr = OnNotifyExpand (pDataObject, TRUE, pGPEStore->m_hScopeItem);
  3262. }
  3263. ASSERT (!(pStore && pGPEStore)); // these can't both be true
  3264. if ( pStore )
  3265. {
  3266. pStore->IncrementCertCount ();
  3267. pStore->SetDirty ();
  3268. pStore->Resync ();
  3269. }
  3270. else if ( pGPEStore )
  3271. {
  3272. pGPEStore->InvalidateCertCount ();
  3273. pGPEStore->SetDirty ();
  3274. pGPEStore->Resync ();
  3275. if ( EFS_STORE == pGPEStore->GetStoreType () )
  3276. {
  3277. hr = CompleteEFSRecoveryAgent (pGPEStore, pNewCertContext);
  3278. }
  3279. }
  3280. else if ( pCert && pCert->GetCertStore ())
  3281. {
  3282. pCert->GetCertStore ()->Resync ();
  3283. }
  3284. if ( !m_pGPEInformation ) // If we are not extending the GPE/SCE
  3285. {
  3286. if ( bParentIsStoreOrContainer )
  3287. {
  3288. ASSERT (hScopeItem);
  3289. ASSERT (pStore);
  3290. hr = CreateContainers (hScopeItem, *pStore);
  3291. // Display the new cert only if the container node is selected
  3292. if ( CERTMGR_CERT_CONTAINER == pParentCookie->m_objecttype &&
  3293. pParentCookie->IsSelected () )
  3294. {
  3295. // Add certificate to result pane
  3296. RESULTDATAITEM rdItem;
  3297. CCookie& rootCookie = QueryBaseRootCookie ();
  3298. // security review 2/26/2002 BryanWal ok
  3299. ::ZeroMemory (&rdItem, sizeof (rdItem));
  3300. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM | RDI_STATE;
  3301. rdItem.nImage = iIconCertificate;
  3302. rdItem.nCol = 0;
  3303. rdItem.nState = LVIS_SELECTED | LVIS_FOCUSED;
  3304. rdItem.str = MMC_TEXTCALLBACK;
  3305. PCCERT_CONTEXT pFoundCertContext =
  3306. pStore->FindCertificate (0, CERT_FIND_EXISTING,
  3307. (void*) pNewCertContext, NULL);
  3308. if ( pFoundCertContext )
  3309. {
  3310. pCert = new CCertificate (pFoundCertContext, pStore);
  3311. if ( pCert )
  3312. {
  3313. rootCookie.m_listResultCookieBlocks.AddHead (pCert);
  3314. rdItem.lParam = (LPARAM) pCert;
  3315. pCert->m_resultDataID = m_pResultData;
  3316. hr = m_pResultData->InsertItem (&rdItem);
  3317. if ( FAILED (hr) )
  3318. {
  3319. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  3320. }
  3321. else
  3322. {
  3323. hr = DisplayCertificateCountByStore (
  3324. m_pComponentConsole, pStore, false);
  3325. }
  3326. }
  3327. else
  3328. hr = E_OUTOFMEMORY;
  3329. ::CertFreeCertificateContext (pFoundCertContext);
  3330. }
  3331. else
  3332. {
  3333. hr = HRESULT_FROM_WIN32 (GetLastError ());
  3334. }
  3335. ASSERT (SUCCEEDED (hr));
  3336. }
  3337. hr = DisplayCertificateCountByStore (m_pComponentConsole, pStore);
  3338. }
  3339. else
  3340. {
  3341. hr = m_pConsole->UpdateAllViews (pDataObject, 0,
  3342. HINT_CERT_ENROLLED_USAGE_MODE);
  3343. ASSERT (SUCCEEDED (hr));
  3344. }
  3345. }
  3346. else
  3347. {
  3348. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  3349. ASSERT (SUCCEEDED (hr));
  3350. hr = DisplayCertificateCountByStore (m_pComponentConsole, pGPEStore, true);
  3351. }
  3352. ::CertFreeCertificateContext (pNewCertContext);
  3353. }
  3354. else if ( bEFSPolicyTurnedOn )
  3355. {
  3356. // If we allowed policy creation just for this enrollment, but
  3357. // nothing was enrolled, go ahead and delete the policy.
  3358. hr = OnDeleteEFSPolicy (pDataObject, false);
  3359. }
  3360. }
  3361. else
  3362. hr = E_POINTER;
  3363. _TRACE (-1, L"Leaving CCertMgrComponentData::OnEnroll: 0x%x\n", hr);
  3364. return hr;
  3365. }
  3366. HRESULT RenewCertificate (
  3367. CCertificate* pCert,
  3368. bool bNewKey,
  3369. const CString& machineName,
  3370. DWORD dwLocation,
  3371. const CString& managedComputer,
  3372. const CString& managedService,
  3373. HWND hwndParent,
  3374. LPCONSOLE pConsole,
  3375. LPDATAOBJECT pDataObject)
  3376. {
  3377. HRESULT hr = S_OK;
  3378. if ( pCert )
  3379. {
  3380. CRYPTUI_WIZ_CERT_REQUEST_PVK_CERT pvkCert;
  3381. CRYPTUI_WIZ_CERT_REQUEST_PVK_NEW pvkNew;
  3382. CRYPTUI_WIZ_CERT_REQUEST_INFO certRequestInfo;
  3383. CRYPT_KEY_PROV_INFO provInfo;
  3384. // security review 2/26/2002 BryanWal ok
  3385. ::ZeroMemory (&certRequestInfo, sizeof (certRequestInfo));
  3386. certRequestInfo.dwSize = sizeof (certRequestInfo);
  3387. certRequestInfo.dwPurpose = CRYPTUI_WIZ_CERT_RENEW;
  3388. // User wants to manage user account
  3389. // pass in NULL to machine name and to account name
  3390. // User wants to manage local machine account
  3391. // pass in NULL for account name and result of ::GetComputerName ()
  3392. // to machine name
  3393. // User want to manage remote machine
  3394. // pass in NULL for account name and machine name for machineName
  3395. // User wants to manage remote account on remote machine
  3396. // pass in account name for accountName and machine name for machineName
  3397. // TODO: Ensure that this is NULL if the local machine
  3398. BOOL bIsLocalMachine = IsLocalComputername (machineName);
  3399. switch (dwLocation)
  3400. {
  3401. case CERT_SYSTEM_STORE_CURRENT_SERVICE:
  3402. case CERT_SYSTEM_STORE_SERVICES:
  3403. certRequestInfo.pwszMachineName = (PCWSTR) managedComputer;
  3404. certRequestInfo.pwszAccountName = (PCWSTR) managedService;
  3405. break;
  3406. case CERT_SYSTEM_STORE_CURRENT_USER:
  3407. certRequestInfo.pwszMachineName = NULL;
  3408. certRequestInfo.pwszAccountName = NULL;
  3409. break;
  3410. case CERT_SYSTEM_STORE_LOCAL_MACHINE:
  3411. certRequestInfo.pwszMachineName = (PCWSTR) managedComputer;
  3412. certRequestInfo.pwszAccountName = NULL;
  3413. break;
  3414. default:
  3415. ASSERT (0);
  3416. return E_UNEXPECTED;
  3417. break;
  3418. }
  3419. certRequestInfo.pRenewCertContext = pCert->GetCertContext ();
  3420. if ( bNewKey )
  3421. {
  3422. certRequestInfo.dwPvkChoice = CRYPTUI_WIZ_CERT_REQUEST_PVK_CHOICE_NEW;
  3423. // security review 2/26/2002 BryanWal ok
  3424. ::ZeroMemory (&pvkNew, sizeof (pvkNew));
  3425. pvkNew.dwSize = sizeof (pvkNew);
  3426. if ( CERT_SYSTEM_STORE_LOCAL_MACHINE == dwLocation )
  3427. {
  3428. // security review 2/26/2002 BryanWal ok
  3429. ::ZeroMemory (&provInfo, sizeof (provInfo));
  3430. provInfo.dwFlags = CRYPT_MACHINE_KEYSET;
  3431. pvkNew.pKeyProvInfo = &provInfo;
  3432. }
  3433. certRequestInfo.pPvkNew = &pvkNew;
  3434. }
  3435. else
  3436. {
  3437. if ( bIsLocalMachine )
  3438. {
  3439. DWORD dwFlags = 0;
  3440. if ( CERT_SYSTEM_STORE_LOCAL_MACHINE == dwLocation )
  3441. dwFlags = CRYPT_FIND_MACHINE_KEYSET_FLAG;
  3442. if ( !::CryptFindCertificateKeyProvInfo (
  3443. pCert->GetCertContext (), dwFlags, 0) )
  3444. {
  3445. DWORD dwErr = GetLastError ();
  3446. _TRACE (0, L"CryptFindCertificateKeyProvInfo () failed: 0x%x\n",
  3447. dwErr);
  3448. CString text;
  3449. CString caption;
  3450. CThemeContextActivator activator;
  3451. text.FormatMessage (IDS_NO_PRIVATE_KEY,
  3452. GetSystemMessage (dwErr));
  3453. VERIFY (caption.LoadString (IDS_RENEW_CERT_SAME_KEY));
  3454. ::MessageBox (hwndParent, text, caption, MB_OK);
  3455. return hr;
  3456. }
  3457. }
  3458. certRequestInfo.dwPvkChoice = CRYPTUI_WIZ_CERT_REQUEST_PVK_CHOICE_CERT;
  3459. // security review 2/26/2002 BryanWal ok
  3460. ::ZeroMemory (&pvkCert, sizeof (pvkCert));
  3461. pvkCert.dwSize = sizeof (pvkCert);
  3462. pvkCert.pCertContext = pCert->GetCertContext ();
  3463. certRequestInfo.pPvkCert = &pvkCert;
  3464. }
  3465. DWORD status = 0;
  3466. PCCERT_CONTEXT pNewCertContext = 0;
  3467. BOOL bResult = FALSE;
  3468. CThemeContextActivator activator;
  3469. while (1)
  3470. {
  3471. bResult = ::CryptUIWizCertRequest (
  3472. bNewKey ? CRYPTUI_WIZ_CERT_REQUEST_REQUIRE_NEW_KEY : 0,
  3473. hwndParent, NULL,
  3474. &certRequestInfo, &pNewCertContext, &status);
  3475. if ( !bResult && HRESULT_FROM_WIN32 (NTE_TOKEN_KEYSET_STORAGE_FULL) == GetLastError () )
  3476. {
  3477. // NTRAID# 299089 Enrollment Wizard: Should return some
  3478. // meaningful message when users fail to enroll/renew on a
  3479. // smart card
  3480. if ( !bNewKey )
  3481. break;
  3482. CString text;
  3483. CString caption;
  3484. int iRetVal = 0;
  3485. VERIFY (text.LoadString (IDS_SMARTCARD_FULL_REUSE_PRIVATE_KEY));
  3486. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  3487. if ( pConsole )
  3488. {
  3489. hr = pConsole->MessageBox (text, caption, MB_YESNO, &iRetVal);
  3490. ASSERT (SUCCEEDED (hr));
  3491. }
  3492. else
  3493. {
  3494. CThemeContextActivator activator;
  3495. iRetVal = ::MessageBox (hwndParent, text, caption, MB_OK);
  3496. }
  3497. if ( IDYES == iRetVal )
  3498. {
  3499. bNewKey = false;
  3500. }
  3501. else
  3502. break;
  3503. }
  3504. else
  3505. break;
  3506. }
  3507. if ( bResult && (CRYPTUI_WIZ_CERT_REQUEST_STATUS_SUCCEEDED == status) && pNewCertContext )
  3508. {
  3509. CCertStore* pStore = pCert->GetCertStore ();
  3510. if ( pStore )
  3511. {
  3512. pStore->SetDirty ();
  3513. pStore->Resync ();
  3514. if ( pConsole )
  3515. hr = pConsole->UpdateAllViews (pDataObject, 0, 0);
  3516. }
  3517. CertFreeCertificateContext (pNewCertContext);
  3518. ASSERT (SUCCEEDED (hr));
  3519. }
  3520. }
  3521. else
  3522. hr = E_POINTER;
  3523. return hr;
  3524. }
  3525. HRESULT CCertMgrComponentData::OnRenew (LPDATAOBJECT pDataObject, bool bNewKey)
  3526. {
  3527. _TRACE (1, L"Entering CCertMgrComponentData::OnRenew\n");
  3528. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  3529. HRESULT hr = S_OK;
  3530. HWND hwndParent = 0;
  3531. VERIFY (SUCCEEDED (m_pConsole->GetMainWindow (&hwndParent)));
  3532. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  3533. if ( pParentCookie && CERTMGR_CERTIFICATE == pParentCookie->m_objecttype )
  3534. {
  3535. CCertificate* pCert = reinterpret_cast <CCertificate*> (pParentCookie);
  3536. ASSERT (pCert);
  3537. if ( pCert )
  3538. {
  3539. hr = RenewCertificate (pCert, bNewKey, m_strMachineNamePersist,
  3540. m_dwLocationPersist, m_szManagedComputer,
  3541. m_szManagedServicePersist, hwndParent, m_pConsole, pDataObject);
  3542. }
  3543. }
  3544. else
  3545. hr = E_POINTER;
  3546. _TRACE (-1, L"Leaving CCertMgrComponentData::OnRenew: 0x%x\n", hr);
  3547. return hr;
  3548. }
  3549. CCertMgrCookie* CCertMgrComponentData::ConvertCookie (LPDATAOBJECT pDataObject)
  3550. {
  3551. CCertMgrCookie* pParentCookie = 0;
  3552. CCookie* pBaseParentCookie = 0;
  3553. HRESULT hr = ExtractData (pDataObject,
  3554. CCertMgrDataObject::m_CFRawCookie,
  3555. &pBaseParentCookie,
  3556. sizeof (pBaseParentCookie) );
  3557. if ( SUCCEEDED (hr) )
  3558. {
  3559. pParentCookie = ActiveCookie (pBaseParentCookie);
  3560. ASSERT (pParentCookie);
  3561. }
  3562. return pParentCookie;
  3563. }
  3564. HRESULT CCertMgrComponentData::OnImport (LPDATAOBJECT pDataObject)
  3565. {
  3566. _TRACE (1, L"Entering CCertMgrComponentData::OnImport\n");
  3567. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  3568. HRESULT hr = S_OK;
  3569. ASSERT (m_szFileName.IsEmpty ());
  3570. if ( !m_szFileName.IsEmpty () )
  3571. return E_UNEXPECTED;
  3572. ASSERT (pDataObject);
  3573. if ( !pDataObject )
  3574. return E_POINTER;
  3575. DWORD dwFlags = 0;
  3576. if ( CERT_SYSTEM_STORE_CURRENT_USER == m_dwLocationPersist )
  3577. {
  3578. // We're managing the user's certificate store
  3579. dwFlags |= CRYPTUI_WIZ_IMPORT_TO_CURRENTUSER;
  3580. }
  3581. else
  3582. {
  3583. // We're managing certificates on a machine
  3584. dwFlags |= CRYPTUI_WIZ_IMPORT_TO_LOCALMACHINE;
  3585. if ( !IsLocalComputername (m_szManagedComputer) )
  3586. {
  3587. // We're managing certificates on a remote machine
  3588. dwFlags |= CRYPTUI_WIZ_IMPORT_REMOTE_DEST_STORE;
  3589. }
  3590. }
  3591. HCERTSTORE hDestStore = 0;
  3592. CCertStore* pDestStore = 0;
  3593. HSCOPEITEM hScopeItem = 0;
  3594. int nOriginalCertCount = 0;
  3595. int nOriginalCTLCount = 0;
  3596. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  3597. if ( pParentCookie )
  3598. {
  3599. hScopeItem = pParentCookie->m_hScopeItem;
  3600. switch (pParentCookie->m_objecttype)
  3601. {
  3602. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  3603. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  3604. ASSERT (0);
  3605. break;
  3606. case CERTMGR_LOG_STORE_RSOP:
  3607. ASSERT (0);
  3608. return E_FAIL;
  3609. break;
  3610. case CERTMGR_LOG_STORE_GPE:
  3611. {
  3612. dwFlags |= CRYPTUI_WIZ_IMPORT_NO_CHANGE_DEST_STORE;
  3613. pDestStore = reinterpret_cast <CCertStore*> (pParentCookie);
  3614. ASSERT (pDestStore);
  3615. if ( pDestStore )
  3616. {
  3617. nOriginalCertCount = pDestStore->GetCertCount ();
  3618. hDestStore = pDestStore->GetStoreHandle ();
  3619. switch (pDestStore->GetStoreType ())
  3620. {
  3621. case ACRS_STORE:
  3622. break;
  3623. case TRUST_STORE:
  3624. dwFlags |= CRYPTUI_WIZ_IMPORT_ALLOW_CTL;
  3625. nOriginalCTLCount = pDestStore->GetCTLCount ();
  3626. break;
  3627. case ROOT_STORE:
  3628. dwFlags |= CRYPTUI_WIZ_IMPORT_ALLOW_CERT;
  3629. break;
  3630. case EFS_STORE:
  3631. break;
  3632. default:
  3633. ASSERT (0);
  3634. break;
  3635. }
  3636. }
  3637. else
  3638. hr = E_UNEXPECTED;
  3639. }
  3640. break;
  3641. case CERTMGR_LOG_STORE:
  3642. case CERTMGR_PHYS_STORE:
  3643. {
  3644. pDestStore = reinterpret_cast <CCertStore*> (pParentCookie);
  3645. ASSERT (pDestStore);
  3646. if ( pDestStore )
  3647. {
  3648. if ( TRUST_STORE == pDestStore->GetStoreType () )
  3649. nOriginalCTLCount = pDestStore->GetCTLCount ();
  3650. else
  3651. nOriginalCertCount = pDestStore->GetCertCount ();
  3652. hDestStore = pDestStore->GetStoreHandle ();
  3653. }
  3654. else
  3655. hr = E_UNEXPECTED;
  3656. }
  3657. break;
  3658. case CERTMGR_CERT_CONTAINER:
  3659. case CERTMGR_CTL_CONTAINER:
  3660. {
  3661. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pParentCookie);
  3662. ASSERT (pContainer);
  3663. if ( pContainer )
  3664. {
  3665. MMC_COOKIE lCookie = 0;
  3666. hr = m_pConsoleNameSpace->GetParentItem (
  3667. pContainer->m_hScopeItem, &hScopeItem, &lCookie);
  3668. ASSERT (SUCCEEDED (hr));
  3669. pDestStore = &pContainer->GetCertStore ();
  3670. if ( CERTMGR_CERT_CONTAINER == pParentCookie->m_objecttype )
  3671. nOriginalCertCount = pDestStore->GetCertCount ();
  3672. else
  3673. nOriginalCTLCount = pDestStore->GetCTLCount ();
  3674. hDestStore = pDestStore->GetStoreHandle ();
  3675. }
  3676. else
  3677. hr = E_UNEXPECTED;
  3678. }
  3679. break;
  3680. case CERTMGR_USAGE:
  3681. pDestStore = 0;
  3682. hDestStore = 0;
  3683. break;
  3684. default:
  3685. ASSERT (0);
  3686. hr = E_UNEXPECTED;
  3687. }
  3688. }
  3689. else
  3690. hr = E_UNEXPECTED;
  3691. if ( SUCCEEDED (hr) )
  3692. {
  3693. HWND hwndParent = 0;
  3694. hr = m_pConsole->GetMainWindow (&hwndParent);
  3695. ASSERT (SUCCEEDED (hr));
  3696. // Now that all the data is set up and everything is in readiness,
  3697. // call the Import Wizard
  3698. CThemeContextActivator activator;
  3699. BOOL bResult = ::CryptUIWizImport (dwFlags, hwndParent, 0, NULL, hDestStore);
  3700. if ( bResult )
  3701. {
  3702. bool bWizardCancelled = false;
  3703. CCertStore* pStore = 0;
  3704. switch (pParentCookie->m_objecttype)
  3705. {
  3706. case CERTMGR_LOG_STORE_RSOP:
  3707. ASSERT (0);
  3708. return E_FAIL;
  3709. break;
  3710. case CERTMGR_LOG_STORE_GPE:
  3711. case CERTMGR_LOG_STORE:
  3712. case CERTMGR_PHYS_STORE:
  3713. {
  3714. pStore = reinterpret_cast <CCertStore*> (pParentCookie);
  3715. ASSERT (pStore);
  3716. if ( pStore )
  3717. {
  3718. if ( TRUST_STORE == pStore->GetStoreType () )
  3719. {
  3720. if ( pStore->GetCTLCount () != nOriginalCTLCount )
  3721. {
  3722. pStore->SetDirty ();
  3723. hr = pStore->Commit ();
  3724. }
  3725. else
  3726. bWizardCancelled = true;
  3727. }
  3728. else
  3729. {
  3730. pStore->InvalidateCertCount ();
  3731. if ( pStore->GetCertCount () != nOriginalCertCount )
  3732. {
  3733. pStore->SetDirty ();
  3734. hr = pStore->Commit ();
  3735. }
  3736. else
  3737. bWizardCancelled = true;
  3738. }
  3739. }
  3740. else
  3741. hr = E_UNEXPECTED;
  3742. }
  3743. break;
  3744. case CERTMGR_CERT_CONTAINER:
  3745. case CERTMGR_CTL_CONTAINER:
  3746. {
  3747. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pParentCookie);
  3748. ASSERT (pContainer);
  3749. if ( pContainer )
  3750. {
  3751. pStore = &pContainer->GetCertStore ();
  3752. if ( CERTMGR_CERT_CONTAINER == pParentCookie->m_objecttype )
  3753. {
  3754. pStore->InvalidateCertCount ();
  3755. if ( pStore->GetCertCount () != nOriginalCertCount )
  3756. {
  3757. pStore->SetDirty ();
  3758. hr = pStore->Commit ();
  3759. }
  3760. else
  3761. bWizardCancelled = true;
  3762. }
  3763. else
  3764. {
  3765. if ( pStore->GetCTLCount () != nOriginalCTLCount )
  3766. {
  3767. pStore->SetDirty ();
  3768. hr = pStore->Commit ();
  3769. }
  3770. else
  3771. bWizardCancelled = true;
  3772. }
  3773. }
  3774. else
  3775. hr = E_UNEXPECTED;
  3776. }
  3777. break;
  3778. case CERTMGR_USAGE:
  3779. break;
  3780. default:
  3781. ASSERT (0);
  3782. hr = E_UNEXPECTED;
  3783. }
  3784. if ( !bWizardCancelled )
  3785. {
  3786. if ( pStore )
  3787. {
  3788. if ( SUCCEEDED (hr) )
  3789. pStore->Resync ();
  3790. }
  3791. if ( CERTMGR_LOG_STORE == pParentCookie->m_objecttype ||
  3792. (CERTMGR_LOG_STORE == pParentCookie->m_objecttype && !m_bShowPhysicalStoresPersist) )
  3793. {
  3794. if ( pStore )
  3795. hr = CreateContainers (hScopeItem, *pStore);
  3796. }
  3797. hr = m_pConsole->UpdateAllViews (pDataObject, 0, HINT_IMPORT);
  3798. ASSERT (SUCCEEDED (hr));
  3799. }
  3800. }
  3801. if ( pDestStore )
  3802. pDestStore->Close ();
  3803. }
  3804. _TRACE (-1, L"Leaving CCertMgrComponentData::OnImport: 0x%x\n", hr);
  3805. return hr;
  3806. }
  3807. HRESULT CCertMgrComponentData::OnExport (LPDATAOBJECT pDataObject)
  3808. {
  3809. _TRACE (1, L"Entering CCertMgrComponentData::OnExport\n");
  3810. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  3811. HRESULT hr = S_OK;
  3812. LPDATAOBJECT pMSDO = ExtractMultiSelect (pDataObject);
  3813. m_bMultipleObjectsSelected = false;
  3814. if ( pMSDO )
  3815. {
  3816. // Iterate through list of selected objects -
  3817. // Add them to a memory store
  3818. // Export to PFX file through wizard with new
  3819. // "export from store - certs only" flag
  3820. m_bMultipleObjectsSelected = true;
  3821. HCERTSTORE hCertStore = ::CertOpenStore (CERT_STORE_PROV_MEMORY,
  3822. 0, NULL, 0, NULL);
  3823. ASSERT (hCertStore);
  3824. if ( hCertStore )
  3825. {
  3826. CCertMgrCookie* pCookie = 0;
  3827. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pMSDO);
  3828. ASSERT (pDO);
  3829. if ( pDO )
  3830. {
  3831. BOOL bResult = FALSE;
  3832. pDO->Reset();
  3833. while (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) != S_FALSE)
  3834. {
  3835. if ( CERTMGR_CERTIFICATE == pCookie->m_objecttype )
  3836. {
  3837. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  3838. ASSERT (pCert);
  3839. if ( pCert )
  3840. {
  3841. bResult = ::CertAddCertificateContextToStore (
  3842. hCertStore,
  3843. ::CertDuplicateCertificateContext (pCert->GetCertContext ()),
  3844. CERT_STORE_ADD_NEW, 0);
  3845. ASSERT (bResult);
  3846. if ( !bResult )
  3847. break;
  3848. }
  3849. }
  3850. else if ( CERTMGR_CTL == pCookie->m_objecttype )
  3851. {
  3852. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  3853. ASSERT (pCTL);
  3854. if ( pCTL )
  3855. {
  3856. bResult = ::CertAddCTLContextToStore (
  3857. hCertStore,
  3858. ::CertDuplicateCTLContext (pCTL->GetCTLContext ()),
  3859. CERT_STORE_ADD_NEW, 0);
  3860. ASSERT (bResult);
  3861. if ( !bResult )
  3862. break;
  3863. }
  3864. }
  3865. }
  3866. // Call Export Wizard
  3867. CRYPTUI_WIZ_EXPORT_INFO cwi;
  3868. // security review 2/26/2002 BryanWal ok
  3869. ::ZeroMemory (&cwi, sizeof (cwi));
  3870. cwi.dwSize = sizeof (cwi);
  3871. cwi.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CERT_STORE;
  3872. cwi.hCertStore = hCertStore;
  3873. HWND hwndParent = 0;
  3874. hr = m_pConsole->GetMainWindow (&hwndParent);
  3875. ASSERT (SUCCEEDED (hr));
  3876. CThemeContextActivator activator;
  3877. bResult = ::CryptUIWizExport (
  3878. 0,
  3879. hwndParent,
  3880. 0,
  3881. &cwi,
  3882. NULL);
  3883. VERIFY (::CertCloseStore (hCertStore, CERT_CLOSE_STORE_CHECK_FLAG));
  3884. }
  3885. else
  3886. hr = E_FAIL;
  3887. return hr;
  3888. }
  3889. else
  3890. {
  3891. DWORD dwErr = GetLastError ();
  3892. _TRACE (0, L"CertOpenStore (%s) failed: 0x%x\n",
  3893. CERT_STORE_PROV_MEMORY, dwErr);
  3894. hr = HRESULT_FROM_WIN32 (dwErr);
  3895. return hr;
  3896. }
  3897. }
  3898. CRYPTUI_WIZ_EXPORT_INFO cwi;
  3899. CCertificate* pCert = 0;
  3900. CCRL* pCRL = 0;
  3901. CCTL* pCTL = 0;
  3902. CCertStore* pCertStore = 0;
  3903. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  3904. ASSERT (pCookie);
  3905. if ( !pCookie )
  3906. return E_UNEXPECTED;
  3907. // security review 2/26/2002 BryanWal ok
  3908. ::ZeroMemory (&cwi, sizeof (cwi));
  3909. cwi.dwSize = sizeof (cwi);
  3910. switch (pCookie->m_objecttype)
  3911. {
  3912. case CERTMGR_CERTIFICATE:
  3913. cwi.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CERT_CONTEXT;
  3914. pCert = reinterpret_cast <CCertificate*> (pCookie);
  3915. ASSERT (pCert);
  3916. if ( pCert )
  3917. cwi.pCertContext = pCert->GetCertContext ();
  3918. else
  3919. return E_UNEXPECTED;
  3920. break;
  3921. case CERTMGR_CRL:
  3922. cwi.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CRL_CONTEXT;
  3923. pCRL = reinterpret_cast <CCRL*> (pCookie);
  3924. ASSERT (pCRL);
  3925. if ( pCRL )
  3926. cwi.pCRLContext = pCRL->GetCRLContext ();
  3927. else
  3928. return E_UNEXPECTED;
  3929. break;
  3930. case CERTMGR_CTL:
  3931. cwi.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CTL_CONTEXT;
  3932. pCTL = reinterpret_cast <CCTL*> (pCookie);
  3933. ASSERT (pCTL);
  3934. if ( pCTL )
  3935. cwi.pCTLContext = pCTL->GetCTLContext ();
  3936. else
  3937. return E_UNEXPECTED;
  3938. break;
  3939. case CERTMGR_LOG_STORE:
  3940. case CERTMGR_PHYS_STORE:
  3941. cwi.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CERT_STORE;
  3942. pCertStore = reinterpret_cast <CCertStore*> (pCookie);
  3943. ASSERT (pCertStore);
  3944. if ( pCertStore )
  3945. cwi.hCertStore = pCertStore->GetStoreHandle ();
  3946. else
  3947. return E_UNEXPECTED;
  3948. break;
  3949. default:
  3950. ASSERT (0);
  3951. return E_UNEXPECTED;
  3952. }
  3953. HWND hwndParent = 0;
  3954. hr = m_pConsole->GetMainWindow (&hwndParent);
  3955. ASSERT (SUCCEEDED (hr));
  3956. CThemeContextActivator activator;
  3957. ::CryptUIWizExport (
  3958. 0,
  3959. hwndParent,
  3960. 0,
  3961. &cwi,
  3962. NULL);
  3963. if ( pCertStore )
  3964. pCertStore->Close ();
  3965. _TRACE (-1, L"Leaving CCertMgrComponentData::OnExport: 0x%x\n", hr);
  3966. return hr;
  3967. }
  3968. HRESULT CCertMgrComponentData::OnNewCTL (LPDATAOBJECT pDataObject)
  3969. {
  3970. _TRACE (1, L"Entering CCertMgrComponentData::OnNewCTL\n");
  3971. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  3972. ASSERT (pDataObject);
  3973. if ( !pDataObject )
  3974. return E_POINTER;
  3975. HRESULT hr = S_OK;
  3976. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  3977. ASSERT (pCookie);
  3978. if ( !pCookie )
  3979. return E_UNEXPECTED;
  3980. CCertStore* pStore = 0;
  3981. CContainerCookie* pCont = 0;
  3982. switch ( pCookie->m_objecttype )
  3983. {
  3984. case CERTMGR_CTL_CONTAINER:
  3985. {
  3986. pCont = reinterpret_cast <CContainerCookie*> (pCookie);
  3987. ASSERT (pCont);
  3988. if ( pCont )
  3989. {
  3990. pStore = &(pCont->GetCertStore ());
  3991. }
  3992. else
  3993. return E_UNEXPECTED;
  3994. }
  3995. break;
  3996. case CERTMGR_LOG_STORE_RSOP:
  3997. ASSERT (0);
  3998. return E_UNEXPECTED;
  3999. break;
  4000. case CERTMGR_LOG_STORE:
  4001. case CERTMGR_LOG_STORE_GPE:
  4002. case CERTMGR_PHYS_STORE:
  4003. {
  4004. pStore = reinterpret_cast <CCertStore*> (pCookie);
  4005. ASSERT (pStore);
  4006. if ( !pStore )
  4007. return E_UNEXPECTED;
  4008. }
  4009. break;
  4010. default:
  4011. ASSERT (0);
  4012. return E_UNEXPECTED;
  4013. }
  4014. ASSERT (pStore);
  4015. if ( !pStore )
  4016. return E_UNEXPECTED;
  4017. pStore->Lock ();
  4018. CRYPTUI_WIZ_BUILDCTL_DEST_INFO destInfo;
  4019. // security review 2/26/2002 BryanWal ok
  4020. ::ZeroMemory (&destInfo, sizeof (destInfo));
  4021. destInfo.dwSize = sizeof (destInfo);
  4022. destInfo.dwDestinationChoice = CRYPTUI_WIZ_BUILDCTL_DEST_CERT_STORE;
  4023. destInfo.hCertStore = pStore->GetStoreHandle ();
  4024. ASSERT (destInfo.hCertStore);
  4025. if ( !destInfo.hCertStore )
  4026. return E_UNEXPECTED;
  4027. HWND hwndParent = 0;
  4028. hr = m_pConsole->GetMainWindow (&hwndParent);
  4029. ASSERT (SUCCEEDED (hr));
  4030. PCCTL_CONTEXT pCTLContext = 0;
  4031. CThemeContextActivator activator;
  4032. BOOL bResult = ::CryptUIWizBuildCTL (
  4033. CRYPTUI_WIZ_BUILDCTL_SKIP_DESTINATION,
  4034. hwndParent,
  4035. 0,
  4036. NULL,
  4037. &destInfo,
  4038. &pCTLContext);
  4039. if ( bResult )
  4040. {
  4041. // If pCTLContext, then the wizard completed
  4042. if ( pCTLContext )
  4043. {
  4044. pStore->SetDirty ();
  4045. pStore->Commit ();
  4046. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  4047. ASSERT (SUCCEEDED (hr));
  4048. ::CertFreeCTLContext (pCTLContext);
  4049. }
  4050. }
  4051. pStore->Unlock ();
  4052. pStore->Close ();
  4053. _TRACE (-1, L"Leaving CCertMgrComponentData::OnNewCTL: 0x%x\n", hr);
  4054. return hr;
  4055. }
  4056. HRESULT CCertMgrComponentData::OnACRSEdit (LPDATAOBJECT pDataObject)
  4057. {
  4058. _TRACE (1, L"Entering CCertMgrComponentData::OnACRSEdit\n");
  4059. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  4060. HRESULT hr = S_OK;
  4061. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  4062. ASSERT (pCookie);
  4063. if ( !pCookie )
  4064. return E_UNEXPECTED;
  4065. switch ( pCookie->m_objecttype )
  4066. {
  4067. case CERTMGR_AUTO_CERT_REQUEST:
  4068. {
  4069. CAutoCertRequest* pACR = reinterpret_cast <CAutoCertRequest*> (pCookie);
  4070. ASSERT (pACR);
  4071. if ( pACR )
  4072. {
  4073. CCertStore& rStore = pACR->GetCertStore ();
  4074. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (&rStore);
  4075. ASSERT (pStore);
  4076. if ( pStore )
  4077. {
  4078. HWND hwndConsole = 0;
  4079. hr = m_pConsole->GetMainWindow (&hwndConsole);
  4080. ASSERT (SUCCEEDED (hr));
  4081. if ( SUCCEEDED (hr) )
  4082. {
  4083. ACRSWizardPropertySheet sheet (pStore, pACR);
  4084. ACRSWizardWelcomePage welcomePage;
  4085. ACRSWizardTypePage typePage;
  4086. ACRSCompletionPage completionPage;
  4087. sheet.AddPage (&welcomePage);
  4088. sheet.AddPage (&typePage);
  4089. sheet.AddPage (&completionPage);
  4090. if ( sheet.DoWizard (hwndConsole) )
  4091. {
  4092. pStore->SetDirty ();
  4093. hr = DeleteCTLFromResultPane (pACR, pDataObject);
  4094. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  4095. ASSERT (SUCCEEDED (hr));
  4096. }
  4097. }
  4098. }
  4099. else
  4100. hr = E_UNEXPECTED;
  4101. }
  4102. else
  4103. return E_UNEXPECTED;
  4104. }
  4105. break;
  4106. default:
  4107. ASSERT (0);
  4108. return E_UNEXPECTED;
  4109. }
  4110. _TRACE (-1, L"Leaving CCertMgrComponentData::OnACRSEdit: 0x%x\n", hr);
  4111. return hr;
  4112. }
  4113. HRESULT CCertMgrComponentData::OnCTLEdit (LPDATAOBJECT pDataObject)
  4114. {
  4115. _TRACE (1, L"Entering CCertMgrComponentData::OnCTLEdit\n");
  4116. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  4117. ASSERT (pDataObject);
  4118. if ( !pDataObject )
  4119. return E_POINTER;
  4120. HRESULT hr = S_OK;
  4121. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  4122. ASSERT (pCookie);
  4123. if ( !pCookie )
  4124. return E_UNEXPECTED;
  4125. switch ( pCookie->m_objecttype )
  4126. {
  4127. case CERTMGR_CTL:
  4128. {
  4129. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  4130. ASSERT (pCTL);
  4131. if ( pCTL )
  4132. {
  4133. CCertStore& rStore = pCTL->GetCertStore ();
  4134. CRYPTUI_WIZ_BUILDCTL_SRC_INFO srcInfo;
  4135. // security review 2/26/2002 BryanWal ok
  4136. ::ZeroMemory (&srcInfo, sizeof (srcInfo));
  4137. srcInfo.dwSize = sizeof (srcInfo);
  4138. srcInfo.pCTLContext = pCTL->GetCTLContext ();
  4139. srcInfo.dwSourceChoice = CRYPTUI_WIZ_BUILDCTL_SRC_EXISTING_CTL;
  4140. HWND hwndParent = 0;
  4141. hr = m_pConsole->GetMainWindow (&hwndParent);
  4142. ASSERT (SUCCEEDED (hr));
  4143. PCCTL_CONTEXT pNewCTLContext = 0;
  4144. CThemeContextActivator activator;
  4145. BOOL bResult = ::CryptUIWizBuildCTL (
  4146. CRYPTUI_WIZ_BUILDCTL_SKIP_DESTINATION,
  4147. hwndParent,
  4148. 0,
  4149. &srcInfo,
  4150. NULL,
  4151. &pNewCTLContext);
  4152. ASSERT (bResult);
  4153. if ( bResult && pNewCTLContext )
  4154. {
  4155. rStore.SetDirty ();
  4156. // Delete old CTL and add the new one.
  4157. if ( pCTL->DeleteFromStore () )
  4158. {
  4159. if ( !rStore.AddCTLContext (pNewCTLContext) )
  4160. {
  4161. DWORD dwErr = GetLastError ();
  4162. if ( CRYPT_E_EXISTS == dwErr )
  4163. {
  4164. CString text;
  4165. CString caption;
  4166. int iRetVal = 0;
  4167. VERIFY (text.LoadString (IDS_DUPLICATE_CTL));
  4168. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4169. hr = m_pConsole->MessageBox (text, caption,
  4170. MB_OK, &iRetVal);
  4171. ASSERT (SUCCEEDED (hr));
  4172. hr = E_FAIL;
  4173. }
  4174. else
  4175. {
  4176. DisplaySystemError (dwErr);
  4177. hr = HRESULT_FROM_WIN32 (dwErr);
  4178. }
  4179. }
  4180. rStore.Commit ();
  4181. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  4182. ASSERT (SUCCEEDED (hr));
  4183. }
  4184. else
  4185. {
  4186. DWORD dwErr = GetLastError ();
  4187. DisplaySystemError (dwErr);
  4188. hr = HRESULT_FROM_WIN32 (dwErr);
  4189. }
  4190. }
  4191. }
  4192. else
  4193. return E_UNEXPECTED;
  4194. }
  4195. break;
  4196. default:
  4197. ASSERT (0);
  4198. return E_UNEXPECTED;
  4199. }
  4200. _TRACE (-1, L"Leaving CCertMgrComponentData::OnCTLEdit: 0x%x\n", hr);
  4201. return hr;
  4202. }
  4203. HRESULT CCertMgrComponentData::OnAddDomainEncryptedDataRecoveryAgent (LPDATAOBJECT pDataObject)
  4204. {
  4205. _TRACE (1, L"Entering CCertMgrComponentData::OnAddDomainEncryptedDataRecoveryAgent\n");
  4206. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  4207. ASSERT (pDataObject);
  4208. if ( !pDataObject )
  4209. return E_POINTER;
  4210. HRESULT hr = S_OK;
  4211. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  4212. ASSERT (pCookie);
  4213. if ( pCookie )
  4214. {
  4215. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (pCookie);
  4216. ASSERT (pStore && EFS_STORE == pStore->GetStoreType ());
  4217. if ( pStore && EFS_STORE == pStore->GetStoreType () )
  4218. {
  4219. HWND hwndConsole = 0;
  4220. hr = m_pConsole->GetMainWindow (&hwndConsole);
  4221. ASSERT (SUCCEEDED (hr));
  4222. if ( SUCCEEDED (hr) )
  4223. {
  4224. CUsers EFSUsers;
  4225. CAddEFSWizSheet efsAddSheet (IDS_ADDTITLE, EFSUsers, m_bMachineIsStandAlone);
  4226. if ( efsAddSheet.DoWizard (hwndConsole) )
  4227. {
  4228. pStore->SetDirty ();
  4229. bool bWasEmpty = false;
  4230. CString szUserName;
  4231. CString szCertName;
  4232. PUSERSONFILE pUser = EFSUsers.StartEnum ();
  4233. if ( pStore->IsNullEFSPolicy () )
  4234. {
  4235. bWasEmpty = true;
  4236. pStore->AllowEmptyEFSPolicy ();
  4237. hr = m_pConsole->UpdateAllViews (pDataObject, 0, HINT_EFS_ADD_DEL_POLICY);
  4238. ASSERT (SUCCEEDED (hr));
  4239. }
  4240. // If the store is an empty store, we need to delete it before adding
  4241. // the first cert. Otherwise CertAddCertificateContextToStore () fails
  4242. // with E_ACCESS_DENIED
  4243. if ( 0 == pStore->GetCertCount () )
  4244. pStore->DeleteEFSPolicy (false);
  4245. while ( pUser )
  4246. {
  4247. hr = pStore->AddCertificateContext (
  4248. pUser->m_pCertContext, m_pConsole, false);
  4249. if ( SUCCEEDED (hr) )
  4250. {
  4251. pStore->AddCertToList (pUser->m_pCertContext, pUser->m_UserSid);
  4252. hr = ValidateCertChain (pUser->m_pCertContext);
  4253. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  4254. ASSERT (SUCCEEDED (hr));
  4255. }
  4256. else
  4257. break;
  4258. pUser = EFSUsers.GetNextUser (pUser, szUserName, szCertName);
  4259. }
  4260. pStore->Commit ();
  4261. hr = DisplayCertificateCountByStore (m_pComponentConsole, pStore, true);
  4262. if ( bWasEmpty )
  4263. {
  4264. // Force scope item selection to force call to
  4265. // IComponent::QueryResultViewType ()
  4266. hr = m_pComponentConsole->SelectScopeItem (pCookie->m_hScopeItem);
  4267. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  4268. hr = OnNotifyExpand (pDataObject, TRUE, pCookie->m_hScopeItem);
  4269. }
  4270. }
  4271. }
  4272. }
  4273. else
  4274. hr = E_UNEXPECTED;
  4275. }
  4276. _TRACE (-1, L"Leaving CCertMgrComponentData::OnAddDomainEncryptedDataRecoveryAgent: 0x%x\n", hr);
  4277. return hr;
  4278. }
  4279. // This code from Robert Reichel
  4280. /*++
  4281. Routine Description:
  4282. This routine returns the TOKEN_USER structure for the
  4283. current user, and optionally, the AuthenticationId from his
  4284. token.
  4285. Arguments:
  4286. AuthenticationId - Supplies an optional pointer to return the
  4287. AuthenticationId.
  4288. Return Value:
  4289. On success, returns a pointer to a TOKEN_USER structure.
  4290. On failure, returns NULL. Call GetLastError() for more
  4291. detailed error information.
  4292. --*/
  4293. PTOKEN_USER EfspGetTokenUser ()
  4294. {
  4295. _TRACE (1, L"Entering EfspGetTokenUser\n");
  4296. HANDLE hToken = 0;
  4297. DWORD dwReturnLength = 0;
  4298. PTOKEN_USER pTokenUser = NULL;
  4299. BOOL bResult = ::OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hToken);
  4300. if ( bResult )
  4301. {
  4302. // security review 2/26/2002 BryanWal ok
  4303. bResult = ::GetTokenInformation (
  4304. hToken,
  4305. TokenUser,
  4306. NULL,
  4307. 0,
  4308. &dwReturnLength);
  4309. if ( !bResult && dwReturnLength > 0 )
  4310. {
  4311. pTokenUser = (PTOKEN_USER) malloc (dwReturnLength);
  4312. if (pTokenUser)
  4313. {
  4314. // security review 2/26/2002 BryanWal ok
  4315. bResult = ::GetTokenInformation (
  4316. hToken,
  4317. TokenUser,
  4318. pTokenUser,
  4319. dwReturnLength,
  4320. &dwReturnLength);
  4321. if ( !bResult)
  4322. {
  4323. DWORD dwErr = GetLastError ();
  4324. DisplaySystemError (NULL, dwErr);
  4325. free (pTokenUser);
  4326. pTokenUser = NULL;
  4327. }
  4328. }
  4329. }
  4330. else
  4331. {
  4332. DWORD dwErr = GetLastError ();
  4333. DisplaySystemError (NULL, dwErr);
  4334. }
  4335. ::CloseHandle (hToken);
  4336. }
  4337. else
  4338. {
  4339. DWORD dwErr = GetLastError ();
  4340. DisplaySystemError (NULL, dwErr);
  4341. }
  4342. _TRACE (-1, L"Leaving EfspGetTokenUser\n");
  4343. return pTokenUser;
  4344. }
  4345. HRESULT CCertMgrComponentData::CompleteEFSRecoveryAgent(CCertStoreGPE* pStore, PCCERT_CONTEXT pCertContext)
  4346. {
  4347. _TRACE (1, L"Entering CCertMgrComponentData::CompleteEFSRecoveryAgent\n");
  4348. HRESULT hr = S_OK;
  4349. ASSERT (pCertContext);
  4350. if ( !pCertContext || !pStore )
  4351. return E_POINTER;
  4352. // This is using to Enroll to create a new EFS Recovery Agent.
  4353. // Get PSID of logged-in user and save to store
  4354. // If the store is an empty store, we need to delete it before adding
  4355. // the first cert. Otherwise CertAddCertificateContextToStore () fails
  4356. // with E_ACCESS_DENIED
  4357. if ( 0 == pStore->GetCertCount () )
  4358. pStore->DeleteEFSPolicy (false);
  4359. hr = pStore->AddCertificateContext (pCertContext, m_pConsole, false);
  4360. if ( SUCCEEDED (hr) )
  4361. {
  4362. pStore->Commit ();
  4363. PTOKEN_USER pTokenUser = ::EfspGetTokenUser ();
  4364. if ( pTokenUser )
  4365. {
  4366. pStore->AddCertToList (pCertContext, pTokenUser->User.Sid);
  4367. free (pTokenUser);
  4368. }
  4369. if ( SUCCEEDED (hr) )
  4370. {
  4371. hr = ValidateCertChain (pCertContext);
  4372. }
  4373. }
  4374. else
  4375. {
  4376. int iRetVal = 0;
  4377. CString text;
  4378. CString caption;
  4379. text.FormatMessage (IDS_CANT_ADD_CERT, pStore->GetLocalizedName (),
  4380. GetSystemMessage (hr));
  4381. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4382. m_pConsole->MessageBox (text, caption,
  4383. MB_OK | MB_ICONWARNING, &iRetVal);
  4384. }
  4385. // Exportable keys are not currently supported. We can uncomment this code if this
  4386. // feature becomes available again in the future.
  4387. /*
  4388. int iRetVal = 0;
  4389. CString text;
  4390. CString caption;
  4391. VERIFY (text.LoadString (IDS_EXPORT_AND_DELETE_EFS_KEY));
  4392. VERIFY (caption.LoadString (IDS_CREATE_AUTO_CERT_REQUEST));
  4393. hr = m_pConsole->MessageBox (text, caption,
  4394. MB_YESNO | MB_ICONQUESTION, &iRetVal);
  4395. ASSERT (SUCCEEDED (hr));
  4396. if ( SUCCEEDED (hr) && IDYES == iRetVal )
  4397. {
  4398. // Remove the private key from the cert.
  4399. hr = CertSetCertificateContextProperty (pCertContext,
  4400. CERT_KEY_PROV_INFO_PROP_ID, 0, 0);
  4401. ASSERT (SUCCEEDED (hr));
  4402. // Bring up the common file open dialog to get a filename
  4403. // and the standard password dialog to get a password so
  4404. // that I can write out the PFX file.
  4405. HWND hwndConsole = 0;
  4406. hr = m_pConsole->GetMainWindow (&hwndConsole);
  4407. ASSERT (SUCCEEDED (hr));
  4408. if ( SUCCEEDED (hr) )
  4409. {
  4410. CString szFilter;
  4411. VERIFY (szFilter.LoadString (IDS_SAVE_PFX_FILTER));
  4412. CWnd mainWindow;
  4413. if ( mainWindow.Attach (hwndConsole) )
  4414. {
  4415. CFileDialog* pFileDlg = new CFileDialog (FALSE, // use as File Save As
  4416. L"pfx", // default extension
  4417. NULL, // preferred file name
  4418. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_CREATEPROMPT | OFN_NOREADONLYRETURN,
  4419. (PCWSTR) szFilter,
  4420. &mainWindow);
  4421. if ( pFileDlg )
  4422. {
  4423. CThemeContextActivator activator;
  4424. if ( IDOK == pFileDlg->DoModal () )
  4425. {
  4426. CString pathName = pFileDlg->GetPathName ();
  4427. CRYPTUI_WIZ_EXPORT_INFO cwi;
  4428. CRYPTUI_WIZ_EXPORT_CERTCONTEXT_INFO cci;
  4429. ::ZeroMemory (&cwi, sizeof (cwi));
  4430. cwi.dwSize = sizeof (cwi);
  4431. cwi.pwszExportFileName = (PCWSTR) pathName;
  4432. cwi.dwSubjectChoice = CRYPTUI_WIZ_EXPORT_CERT_CONTEXT;
  4433. cwi.pCertContext = pCertContext;
  4434. ::ZeroMemory (&cci, sizeof (cci));
  4435. cci.dwSize = sizeof (cci);
  4436. cci.dwExportFormat = CRYPTUI_WIZ_EXPORT_FORMAT_PFX;
  4437. cci.fExportChain = TRUE;
  4438. cci.fExportPrivateKeys = TRUE;
  4439. CPassword passwordDlg;
  4440. // Launch password dialog
  4441. CThemeContextActivator activator;
  4442. if ( IDOK == passwordDlg.DoModal () )
  4443. {
  4444. if ( !wcslen (passwordDlg.GetPassword ()) )
  4445. {
  4446. // If password string is empty, pass NULL.
  4447. cci.pwszPassword = 0;
  4448. }
  4449. else
  4450. cci.pwszPassword = passwordDlg.GetPassword ();
  4451. CThemeContextActivator activator;
  4452. BOOL bResult = ::CryptUIWizExport (
  4453. CRYPTUI_WIZ_NO_UI,
  4454. 0, // hwndParent ignored
  4455. 0, // pwszWizardTitle ignored
  4456. &cwi,
  4457. (void*) &cci);
  4458. if ( bResult )
  4459. {
  4460. hr = DeleteKeyFromRSABASE (pCertContext);
  4461. }
  4462. else
  4463. {
  4464. DWORD dwErr = GetLastError ();
  4465. DisplaySystemError (dwErr);
  4466. }
  4467. }
  4468. }
  4469. delete pFileDlg;
  4470. }
  4471. else
  4472. {
  4473. hr = E_OUTOFMEMORY;
  4474. }
  4475. }
  4476. else
  4477. ASSERT (0);
  4478. VERIFY (mainWindow.Detach () == hwndConsole);
  4479. }
  4480. }
  4481. */
  4482. _TRACE (-1, L"Leaving CCertMgrComponentData::CompleteEFSRecoveryAgent: 0x%x\n", hr);
  4483. return hr;
  4484. }
  4485. HRESULT CCertMgrComponentData::AddScopeNode(CCertMgrCookie * pNewCookie, const CString & strServerName, HSCOPEITEM hParent)
  4486. {
  4487. _TRACE (1, L"Entering CCertMgrComponentData::AddScopeNode\n");
  4488. ASSERT (pNewCookie);
  4489. if ( !pNewCookie )
  4490. return E_POINTER;
  4491. HRESULT hr = S_OK;
  4492. SCOPEDATAITEM tSDItem;
  4493. // security review 2/26/2002 BryanWal ok
  4494. ::ZeroMemory (&tSDItem,sizeof (tSDItem));
  4495. tSDItem.mask = SDI_STR | SDI_IMAGE | SDI_STATE | SDI_PARAM | SDI_PARENT;
  4496. tSDItem.displayname = MMC_CALLBACK;
  4497. tSDItem.relativeID = hParent;
  4498. tSDItem.nState = 0;
  4499. switch (pNewCookie->m_objecttype)
  4500. {
  4501. case CERTMGR_USAGE:
  4502. case CERTMGR_CRL_CONTAINER:
  4503. case CERTMGR_CTL_CONTAINER:
  4504. case CERTMGR_CERT_CONTAINER:
  4505. case CERTMGR_LOG_STORE_GPE:
  4506. case CERTMGR_LOG_STORE_RSOP:
  4507. case CERTMGR_SAFER_COMPUTER_LEVELS:
  4508. case CERTMGR_SAFER_USER_LEVELS:
  4509. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  4510. case CERTMGR_SAFER_USER_ENTRIES:
  4511. tSDItem.mask |= SDI_CHILDREN;
  4512. tSDItem.cChildren = 0;
  4513. break;
  4514. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  4515. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  4516. ASSERT (0);
  4517. break;
  4518. default:
  4519. break;
  4520. }
  4521. if ( pNewCookie != m_pRootCookie && m_pRootCookie )
  4522. m_pRootCookie->m_listScopeCookieBlocks.AddHead ( (CBaseCookieBlock*) pNewCookie);
  4523. if ( !strServerName.IsEmpty () )
  4524. pNewCookie->m_strMachineName = strServerName;
  4525. tSDItem.lParam = reinterpret_cast<LPARAM> ( (CCookie*) pNewCookie);
  4526. tSDItem.nImage = QueryImage (*pNewCookie, FALSE);
  4527. hr = m_pConsoleNameSpace->InsertItem (&tSDItem);
  4528. if ( SUCCEEDED (hr) )
  4529. pNewCookie->m_hScopeItem = tSDItem.ID;
  4530. _TRACE (-1, L"Leaving CCertMgrComponentData::AddScopeNode: 0x%x\n", hr);
  4531. return hr;
  4532. }
  4533. HRESULT CCertMgrComponentData::DeleteKeyFromRSABASE(PCCERT_CONTEXT pCertContext)
  4534. {
  4535. _TRACE (1, L"Entering CCertMgrComponentData::DeleteKeyFromRSABASE\n");
  4536. ASSERT (pCertContext);
  4537. if ( !pCertContext )
  4538. return E_POINTER;
  4539. HRESULT hr = S_OK;
  4540. DWORD cbData = 0;
  4541. BOOL bResult = ::CertGetCertificateContextProperty (pCertContext,
  4542. CERT_KEY_PROV_INFO_PROP_ID, 0, &cbData);
  4543. ASSERT (bResult);
  4544. if ( bResult )
  4545. {
  4546. PCRYPT_KEY_PROV_INFO pKeyProvInfo = (PCRYPT_KEY_PROV_INFO) ::LocalAlloc (LPTR, cbData);
  4547. if ( pKeyProvInfo )
  4548. {
  4549. bResult = ::CertGetCertificateContextProperty (pCertContext,
  4550. CERT_KEY_PROV_INFO_PROP_ID, pKeyProvInfo, &cbData);
  4551. ASSERT (bResult);
  4552. if ( bResult )
  4553. {
  4554. HCRYPTPROV hProv = 0;
  4555. bResult = ::CryptAcquireContext (&hProv,
  4556. pKeyProvInfo->pwszContainerName,
  4557. pKeyProvInfo->pwszProvName,
  4558. pKeyProvInfo->dwProvType,
  4559. CRYPT_DELETEKEYSET);
  4560. ASSERT (bResult);
  4561. if ( !bResult )
  4562. {
  4563. DWORD dwErr = GetLastError ();
  4564. hr = HRESULT_FROM_WIN32 (dwErr);
  4565. DisplaySystemError (dwErr);
  4566. }
  4567. }
  4568. else
  4569. {
  4570. DWORD dwErr = GetLastError ();
  4571. hr = HRESULT_FROM_WIN32 (dwErr);
  4572. DisplaySystemError (dwErr);
  4573. }
  4574. ::LocalFree (pKeyProvInfo);
  4575. }
  4576. else
  4577. {
  4578. hr = E_OUTOFMEMORY;
  4579. }
  4580. }
  4581. else
  4582. {
  4583. DWORD dwErr = GetLastError ();
  4584. hr = HRESULT_FROM_WIN32 (dwErr);
  4585. DisplaySystemError (dwErr);
  4586. }
  4587. _TRACE (-1, L"Leaving CCertMgrComponentData::DeleteKeyFromRSABASE: 0x%x\n", hr);
  4588. return hr;
  4589. }
  4590. HRESULT CCertMgrComponentData::ReleaseResultCookie (
  4591. CBaseCookieBlock * pResultCookie,
  4592. CCookie& rootCookie,
  4593. HCERTSTORE hStoreHandle,
  4594. POSITION pos2)
  4595. {
  4596. // _TRACE (1, L"Entering CCertMgrComponentData::ReleaseResultCookie\n");
  4597. CCertMgrCookie* pCookie = reinterpret_cast <CCertMgrCookie*> (pResultCookie);
  4598. ASSERT (pCookie);
  4599. if ( pCookie )
  4600. {
  4601. switch (pCookie->m_objecttype)
  4602. {
  4603. case CERTMGR_CERTIFICATE:
  4604. {
  4605. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  4606. ASSERT (pCert);
  4607. if ( pCert && pCert->GetCertStore () )
  4608. {
  4609. if ( pCert->GetCertStore ()->GetStoreHandle () == hStoreHandle )
  4610. {
  4611. // pCookie and pCert point to the same object
  4612. pResultCookie = rootCookie.m_listResultCookieBlocks.GetAt (pos2);
  4613. ASSERT (pResultCookie);
  4614. rootCookie.m_listResultCookieBlocks.RemoveAt (pos2);
  4615. if ( pResultCookie )
  4616. {
  4617. pResultCookie->Release ();
  4618. }
  4619. }
  4620. pCert->GetCertStore ()->Close ();
  4621. }
  4622. }
  4623. break;
  4624. case CERTMGR_CTL:
  4625. case CERTMGR_AUTO_CERT_REQUEST:
  4626. {
  4627. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  4628. ASSERT (pCTL);
  4629. if ( pCTL )
  4630. {
  4631. if ( pCTL->GetCertStore ().GetStoreHandle () == hStoreHandle )
  4632. {
  4633. // pCookie and pCert point to the same object
  4634. pResultCookie = rootCookie.m_listResultCookieBlocks.GetAt (pos2);
  4635. ASSERT (pResultCookie);
  4636. rootCookie.m_listResultCookieBlocks.RemoveAt (pos2);
  4637. if ( pResultCookie )
  4638. {
  4639. pResultCookie->Release ();
  4640. }
  4641. }
  4642. pCTL->GetCertStore ().Close ();
  4643. }
  4644. }
  4645. break;
  4646. case CERTMGR_CRL:
  4647. {
  4648. CCRL* pCRL = reinterpret_cast <CCRL*> (pCookie);
  4649. ASSERT (pCRL);
  4650. if ( pCRL )
  4651. {
  4652. if ( pCRL->GetCertStore ().GetStoreHandle () == hStoreHandle )
  4653. {
  4654. // pCookie and pCert point to the same object
  4655. pResultCookie = rootCookie.m_listResultCookieBlocks.GetAt (pos2);
  4656. ASSERT (pResultCookie);
  4657. rootCookie.m_listResultCookieBlocks.RemoveAt (pos2);
  4658. if ( pResultCookie )
  4659. {
  4660. pResultCookie->Release ();
  4661. }
  4662. }
  4663. pCRL->GetCertStore ().Close ();
  4664. }
  4665. }
  4666. break;
  4667. default:
  4668. // _TRACE (0, L"CCertMgrComponentData::ReleaseResultCookie () - bad cookie type: 0x%x\n",
  4669. // pCookie->m_objecttype);
  4670. break;
  4671. }
  4672. }
  4673. // _TRACE (-1, L"Leaving CCertMgrComponentData::ReleaseResultCookie: S_OK\n");
  4674. return S_OK;
  4675. }
  4676. void CCertMgrComponentData::SetResultData(LPRESULTDATA pResultData)
  4677. {
  4678. _TRACE (1, L"Entering CCertMgrComponentData::SetResultData\n");
  4679. ASSERT (pResultData);
  4680. if ( pResultData && pResultData != m_pResultData )
  4681. {
  4682. if ( m_pResultData )
  4683. m_pResultData->Release ();
  4684. m_pResultData = pResultData;
  4685. m_pResultData->AddRef ();
  4686. }
  4687. _TRACE (-1, L"Leaving CCertMgrComponentData::SetResultData\n");
  4688. }
  4689. HRESULT CCertMgrComponentData::GetResultData(LPRESULTDATA* ppResultData)
  4690. {
  4691. HRESULT hr = S_OK;
  4692. if ( !ppResultData )
  4693. hr = E_POINTER;
  4694. else if ( !m_pResultData )
  4695. {
  4696. if ( m_pConsole )
  4697. {
  4698. hr = m_pConsole->QueryInterface(IID_PPV_ARG (IResultData, &m_pResultData));
  4699. _ASSERT (SUCCEEDED (hr));
  4700. }
  4701. else
  4702. hr = E_FAIL;
  4703. }
  4704. if ( SUCCEEDED (hr) && m_pResultData )
  4705. {
  4706. *ppResultData = m_pResultData;
  4707. m_pResultData->AddRef ();
  4708. }
  4709. return hr;
  4710. }
  4711. ///////////////////////////////////////////////////////////////////////////////
  4712. //
  4713. // Check to see if a child scope pane object exists of the desired type
  4714. // immediately below hParent
  4715. //
  4716. ///////////////////////////////////////////////////////////////////////////////
  4717. bool CCertMgrComponentData::ContainerExists(HSCOPEITEM hParent, CertificateManagerObjectType objectType)
  4718. {
  4719. _TRACE (1, L"Entering CCertMgrComponentData::ContainerExists\n");
  4720. bool bExists = false;
  4721. CCertMgrCookie* pCookie = 0;
  4722. HSCOPEITEM hChild = 0;
  4723. MMC_COOKIE lCookie = 0;
  4724. HRESULT hr = m_pConsoleNameSpace->GetChildItem (hParent,
  4725. &hChild, &lCookie);
  4726. ASSERT (SUCCEEDED (hr));
  4727. while ( SUCCEEDED (hr) && hChild )
  4728. {
  4729. pCookie = reinterpret_cast <CCertMgrCookie*> (lCookie);
  4730. ASSERT (pCookie);
  4731. if ( pCookie )
  4732. {
  4733. if ( pCookie->m_objecttype == objectType )
  4734. {
  4735. bExists = true;
  4736. break;
  4737. }
  4738. }
  4739. hr = m_pConsoleNameSpace->GetNextItem (hChild, &hChild, &lCookie);
  4740. ASSERT (SUCCEEDED (hr));
  4741. }
  4742. _TRACE (-1, L"Leaving CCertMgrComponentData::ContainerExists\n");
  4743. return bExists;
  4744. }
  4745. void CCertMgrComponentData::DisplayAccessDenied ()
  4746. {
  4747. _TRACE (1, L"Entering CCertMgrComponentData::DisplayAccessDenied\n");
  4748. DWORD dwErr = GetLastError ();
  4749. ASSERT (E_ACCESSDENIED == dwErr);
  4750. if ( E_ACCESSDENIED == dwErr )
  4751. {
  4752. LPVOID lpMsgBuf = 0;
  4753. // security review 2/26/2002 BryanWal ok
  4754. ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  4755. NULL,
  4756. GetLastError (),
  4757. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  4758. (PWSTR) &lpMsgBuf, 0, NULL );
  4759. // Display the string.
  4760. CString caption;
  4761. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4762. int iRetVal = 0;
  4763. VERIFY (SUCCEEDED (m_pConsole->MessageBox ( (PWSTR) lpMsgBuf, caption,
  4764. MB_ICONWARNING | MB_OK, &iRetVal)));
  4765. // Free the buffer.
  4766. LocalFree (lpMsgBuf);
  4767. }
  4768. _TRACE (-1, L"Leaving CCertMgrComponentData::DisplayAccessDenied\n");
  4769. }
  4770. HRESULT CCertMgrComponentData::DeleteCTLFromResultPane (CCTL * pCTL, LPDATAOBJECT pDataObject)
  4771. {
  4772. _TRACE (1, L"Entering CCertMgrComponentData::DeleteCTLFromResultPane\n");
  4773. ASSERT (pCTL);
  4774. ASSERT (pDataObject);
  4775. if ( !pCTL || !pDataObject )
  4776. return E_POINTER;
  4777. HRESULT hr = S_OK;
  4778. if ( pCTL->DeleteFromStore () )
  4779. {
  4780. hr = pCTL->GetCertStore ().Commit ();
  4781. ASSERT (SUCCEEDED (hr));
  4782. if ( SUCCEEDED (hr) )
  4783. {
  4784. HRESULTITEM itemID = 0;
  4785. hr = m_pResultData->FindItemByLParam ( (LPARAM) pCTL, &itemID);
  4786. if ( SUCCEEDED (hr) )
  4787. {
  4788. hr = m_pResultData->DeleteItem (itemID, 0);
  4789. ASSERT (SUCCEEDED (hr));
  4790. }
  4791. // If we can't succeed in removing this one item, then update the whole panel.
  4792. if ( !SUCCEEDED (hr) )
  4793. {
  4794. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  4795. }
  4796. }
  4797. }
  4798. else
  4799. {
  4800. DisplayAccessDenied ();
  4801. }
  4802. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::DeleteCTLFromResultPane: 0x%x\n", hr);
  4803. return hr;
  4804. }
  4805. CString CCertMgrComponentData::GetThisComputer() const
  4806. {
  4807. _TRACE (0, L"Entering and leaving CCertMgrComponentData::GetThisComputer\n");
  4808. return m_szThisComputer;
  4809. }
  4810. typedef struct _ENUM_LOG_ARG {
  4811. DWORD m_dwFlags;
  4812. CTypedPtrList<CPtrList, CCertStore*>* m_pStoreList;
  4813. PCWSTR m_pcszMachineName;
  4814. CCertMgrComponentData* m_pCompData;
  4815. LPCONSOLE m_pConsole;
  4816. } ENUM_LOG_ARG, *PENUM_LOG_ARG;
  4817. static BOOL WINAPI EnumLogCallback (
  4818. IN const void* pwszSystemStore,
  4819. IN DWORD dwFlags,
  4820. IN PCERT_SYSTEM_STORE_INFO /*pStoreInfo*/,
  4821. IN OPTIONAL void* /*pvReserved*/,
  4822. IN OPTIONAL void *pvArg
  4823. )
  4824. {
  4825. _TRACE (1, L"Entering EnumLogCallback\n");
  4826. BOOL bResult = TRUE;
  4827. PENUM_LOG_ARG pEnumArg = (PENUM_LOG_ARG) pvArg;
  4828. // Create new cookies
  4829. SPECIAL_STORE_TYPE storeType = GetSpecialStoreType ((PWSTR) pwszSystemStore);
  4830. //
  4831. // We will not expose the ACRS store for machines or users. It is not
  4832. // interesting or useful at this level. All Auto Cert Requests should
  4833. // be managed only at the policy level.
  4834. //
  4835. if ( ACRS_STORE != storeType )
  4836. {
  4837. if ( pEnumArg->m_pCompData->ShowArchivedCerts () )
  4838. dwFlags |= CERT_STORE_ENUM_ARCHIVED_FLAG;
  4839. CCertStore* pStore = new CCertStore (
  4840. CERTMGR_LOG_STORE,
  4841. CERT_STORE_PROV_SYSTEM,
  4842. dwFlags,
  4843. pEnumArg->m_pcszMachineName,
  4844. (PCWSTR) pwszSystemStore,
  4845. (PCWSTR) pwszSystemStore,
  4846. _T (""), storeType,
  4847. pEnumArg->m_dwFlags,
  4848. pEnumArg->m_pConsole);
  4849. if ( pStore )
  4850. {
  4851. pEnumArg->m_pStoreList->AddTail (pStore);
  4852. }
  4853. }
  4854. _TRACE (-1, L"Leaving EnumLogCallback\n");
  4855. return bResult;
  4856. }
  4857. HRESULT CCertMgrComponentData::EnumerateLogicalStores (CTypedPtrList<CPtrList, CCertStore*>* pStoreList)
  4858. {
  4859. _TRACE (1, L"Entering CCertMgrComponentData::EnumerateLogicalStores\n");
  4860. CWaitCursor cursor;
  4861. HRESULT hr = S_OK;
  4862. ENUM_LOG_ARG enumArg;
  4863. DWORD dwFlags = GetLocation ();
  4864. // security review 2/26/2002 BryanWal ok
  4865. ::ZeroMemory (&enumArg, sizeof (enumArg));
  4866. enumArg.m_dwFlags = dwFlags;
  4867. enumArg.m_pStoreList = pStoreList;
  4868. enumArg.m_pcszMachineName =
  4869. QueryRootCookie ().QueryNonNULLMachineName ();
  4870. enumArg.m_pCompData = this;
  4871. enumArg.m_pConsole = m_pConsole;
  4872. CString location;
  4873. void* pvPara = 0;
  4874. if ( !GetManagedService ().IsEmpty () )
  4875. {
  4876. if ( !GetManagedComputer ().IsEmpty () )
  4877. {
  4878. location = GetManagedComputer () + _T("\\") +
  4879. GetManagedComputer ();
  4880. pvPara = (void *) (PCWSTR) location;
  4881. }
  4882. else
  4883. pvPara = (void *) (PCWSTR) GetManagedService ();
  4884. }
  4885. else if ( !GetManagedComputer ().IsEmpty () )
  4886. {
  4887. pvPara = (void *) (PCWSTR) GetManagedComputer ();
  4888. }
  4889. CString fileName = GetCommandLineFileName ();
  4890. if ( fileName.IsEmpty () )
  4891. {
  4892. // Ensure creation of MY store
  4893. HCERTSTORE hTempStore = ::CertOpenStore (CERT_STORE_PROV_SYSTEM,
  4894. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  4895. NULL,
  4896. dwFlags | CERT_STORE_SET_LOCALIZED_NAME_FLAG,
  4897. MY_SYSTEM_STORE_NAME);
  4898. if ( hTempStore ) // otherwise, store is read only
  4899. {
  4900. VERIFY (::CertCloseStore (hTempStore, CERT_CLOSE_STORE_CHECK_FLAG));
  4901. }
  4902. else
  4903. {
  4904. _TRACE (0, L"CertOpenStore (%s) failed: 0x%x\n",
  4905. MY_SYSTEM_STORE_NAME, GetLastError ());
  4906. }
  4907. if ( !::CertEnumSystemStore (dwFlags, pvPara, &enumArg, EnumLogCallback) )
  4908. {
  4909. DWORD dwErr = GetLastError ();
  4910. CString text;
  4911. CString caption;
  4912. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4913. if ( ERROR_ACCESS_DENIED == dwErr )
  4914. {
  4915. VERIFY (text.LoadString (IDS_NO_PERMISSION));
  4916. }
  4917. else
  4918. {
  4919. text.FormatMessage (IDS_CANT_ENUMERATE_SYSTEM_STORES, GetSystemMessage (dwErr));
  4920. }
  4921. int iRetVal = 0;
  4922. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  4923. MB_OK, &iRetVal)));
  4924. hr = HRESULT_FROM_WIN32 (dwErr);
  4925. hr = HRESULT_FROM_WIN32 (dwErr);
  4926. }
  4927. }
  4928. else
  4929. {
  4930. // Create new cookies
  4931. dwFlags = 0;
  4932. // If there is a class file-based store, use that, otherwise allocate
  4933. // a new one.
  4934. CCertStore* pStore = m_pFileBasedStore;
  4935. if ( !pStore )
  4936. pStore = new CCertStore (
  4937. CERTMGR_LOG_STORE,
  4938. CERT_STORE_PROV_FILENAME_W,
  4939. dwFlags,
  4940. QueryRootCookie ().QueryNonNULLMachineName (),
  4941. fileName, fileName, _T (""), NO_SPECIAL_TYPE,
  4942. m_dwLocationPersist,
  4943. m_pConsole);
  4944. else
  4945. pStore->AddRef ();
  4946. if ( pStore )
  4947. {
  4948. pStoreList->AddTail (pStore);
  4949. }
  4950. }
  4951. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::EnumerateLogicalStores: 0x%x\n", hr);
  4952. return hr;
  4953. }
  4954. HRESULT CCertMgrComponentData::OnNotifyPreload(
  4955. LPDATAOBJECT /*lpDataObject*/,
  4956. HSCOPEITEM hRootScopeItem)
  4957. {
  4958. _TRACE (1, L"Entering CCertMgrComponentData::OnNotifyPreload\n");
  4959. ASSERT (m_fAllowOverrideMachineName);
  4960. HRESULT hr = S_OK;
  4961. QueryBaseRootCookie ().m_hScopeItem = hRootScopeItem;
  4962. // The machine name will be changed only if the stores are machine-based
  4963. // stores.
  4964. switch (m_dwLocationPersist)
  4965. {
  4966. case CERT_SYSTEM_STORE_LOCAL_MACHINE:
  4967. case CERT_SYSTEM_STORE_CURRENT_SERVICE:
  4968. case CERT_SYSTEM_STORE_SERVICES:
  4969. {
  4970. CString machineName = QueryRootCookie ().QueryNonNULLMachineName();
  4971. hr = ChangeRootNodeName (machineName);
  4972. }
  4973. break;
  4974. default:
  4975. break;
  4976. }
  4977. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::OnNotifyPreload: 0x%x\n", hr);
  4978. return hr;
  4979. }
  4980. ///////////////////////////////////////////////////////////////////////////////
  4981. //
  4982. // ChangeRootNodeName ()
  4983. //
  4984. // Purpose: Change the text of the root node
  4985. //
  4986. // Input: newName - the new machine name that the snapin manages
  4987. // Output: Returns S_OK on success
  4988. //
  4989. ///////////////////////////////////////////////////////////////////////////////
  4990. HRESULT CCertMgrComponentData::ChangeRootNodeName(const CString & newName)
  4991. {
  4992. _TRACE (1, L"Entering CCertMgrComponentData::ChangeRootNodeName\n");
  4993. if ( !QueryBaseRootCookie ().m_hScopeItem )
  4994. {
  4995. if ( m_hRootScopeItem )
  4996. QueryBaseRootCookie ().m_hScopeItem = m_hRootScopeItem;
  4997. else
  4998. return E_UNEXPECTED;
  4999. }
  5000. CString formattedName;
  5001. switch (m_dwLocationPersist)
  5002. {
  5003. case CERT_SYSTEM_STORE_LOCAL_MACHINE:
  5004. {
  5005. CString machineName (newName);
  5006. // If machineName is empty, then this manages the local machine. Get
  5007. // the local machine name. Then format the computer name with the snapin
  5008. // name
  5009. if ( IsLocalComputername (machineName) )
  5010. {
  5011. formattedName.LoadString (IDS_SCOPE_SNAPIN_TITLE_LOCAL_MACHINE);
  5012. m_szManagedComputer = L"";
  5013. }
  5014. else
  5015. {
  5016. machineName.MakeUpper ();
  5017. formattedName.FormatMessage (IDS_SCOPE_SNAPIN_TITLE_MACHINE, machineName);
  5018. m_szManagedComputer = machineName;
  5019. }
  5020. }
  5021. break;
  5022. case CERT_SYSTEM_STORE_CURRENT_SERVICE:
  5023. case CERT_SYSTEM_STORE_SERVICES:
  5024. {
  5025. CString machineName (newName);
  5026. // If machineName is empty, then this manages the local machine. Get
  5027. // the local machine name. Then format the computer name with the snapin
  5028. // name
  5029. if ( IsLocalComputername (machineName) )
  5030. {
  5031. // Get this machine name and add it to the string.
  5032. formattedName.FormatMessage (IDS_SCOPE_SNAPIN_TITLE_SERVICE_LOCAL_MACHINE,
  5033. m_szManagedServiceDisplayName);
  5034. m_szManagedComputer = L"";
  5035. }
  5036. else
  5037. {
  5038. formattedName.FormatMessage (IDS_SCOPE_SNAPIN_TITLE_SERVICE,
  5039. m_szManagedServiceDisplayName, machineName);
  5040. m_szManagedComputer = machineName;
  5041. }
  5042. }
  5043. break;
  5044. case CERT_SYSTEM_STORE_CURRENT_USER:
  5045. VERIFY (formattedName.LoadString (IDS_SCOPE_SNAPIN_TITLE_USER));
  5046. break;
  5047. case 0:
  5048. VERIFY (formattedName.LoadString (IDS_SCOPE_SNAPIN_TITLE_FILE));
  5049. break;
  5050. default:
  5051. return S_OK;
  5052. }
  5053. SCOPEDATAITEM item;
  5054. // security review 2/26/2002 BryanWal ok
  5055. ::ZeroMemory (&item, sizeof (item));
  5056. item.mask = SDI_STR;
  5057. item.displayname = (PWSTR) (PCWSTR) formattedName;
  5058. item.ID = QueryBaseRootCookie ().m_hScopeItem;
  5059. HRESULT hr = m_pConsoleNameSpace->SetItem (&item);
  5060. if ( FAILED (hr) )
  5061. {
  5062. _TRACE (0, L"IConsoleNameSpace2::SetItem () failed: 0x%x\n", hr);
  5063. }
  5064. if ( SUCCEEDED (hr) )
  5065. m_fInvalidComputer = false;
  5066. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::ChangeRootNodeName: 0x%x\n", hr);
  5067. return hr;
  5068. }
  5069. HRESULT CCertMgrComponentData::CreateContainers(
  5070. HSCOPEITEM hScopeItem,
  5071. CCertStore& rTargetStore)
  5072. {
  5073. _TRACE (1, L"Entering CCertMgrComponentData::CreateContainers\n");
  5074. HRESULT hr = S_OK;
  5075. // If the container was a cert store and it does not
  5076. // already have Certs/CRLs/CTLs, instantiate a new CRL container
  5077. // in the scope pane.
  5078. if ( -1 != hScopeItem )
  5079. {
  5080. SCOPEDATAITEM item;
  5081. // security review 2/26/2002 BryanWal ok
  5082. ::ZeroMemory (&item, sizeof (item));
  5083. item.mask = SDI_STATE;
  5084. item.nState = 0;
  5085. item.ID = hScopeItem;
  5086. hr = m_pConsoleNameSpace->SetItem (&item);
  5087. if ( FAILED (hr) )
  5088. {
  5089. _TRACE (0, L"IConsoleNameSpace2::SetItem () failed: 0x%x\n", hr);
  5090. }
  5091. if ( CERTMGR_LOG_STORE_GPE != rTargetStore.m_objecttype &&
  5092. CERTMGR_LOG_STORE_RSOP != rTargetStore.m_objecttype)
  5093. {
  5094. AddContainersToScopePane (hScopeItem,
  5095. rTargetStore, true);
  5096. }
  5097. }
  5098. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::CreateContainers: 0x%x\n", hr);
  5099. return hr;
  5100. }
  5101. HRESULT CCertMgrComponentData::OnOptions(LPDATAOBJECT pDataObject)
  5102. {
  5103. _TRACE (1, L"Entering CCertMgrComponentData::OnOptions\n");
  5104. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  5105. HWND hParent = 0;
  5106. // Get parent window handle and attach to a CWnd object
  5107. HRESULT hr = m_pConsole->GetMainWindow (&hParent);
  5108. ASSERT (SUCCEEDED (hr));
  5109. if ( SUCCEEDED (hr) )
  5110. {
  5111. int activeView = m_activeViewPersist;
  5112. BOOL bShowPhysicalStores = m_bShowPhysicalStoresPersist;
  5113. BOOL bShowArchivedCerts = m_bShowArchivedCertsPersist;
  5114. CWnd parentWnd;
  5115. VERIFY (parentWnd.Attach (hParent));
  5116. CViewOptionsDlg optionsDlg (&parentWnd,
  5117. this);
  5118. CThemeContextActivator activator;
  5119. INT_PTR iReturn = optionsDlg.DoModal ();
  5120. ASSERT (-1 != iReturn);
  5121. if ( -1 == iReturn )
  5122. hr = (HRESULT)iReturn;
  5123. if ( IDOK == iReturn )
  5124. {
  5125. long hint = 0;
  5126. if ( activeView != m_activeViewPersist )
  5127. {
  5128. hint |= HINT_CHANGE_VIEW_TYPE;
  5129. if ( IDM_USAGE_VIEW == m_activeViewPersist )
  5130. {
  5131. // view by usage
  5132. ASSERT (m_pHeader);
  5133. if ( m_pHeader && GetObjectType (pDataObject) == CERTMGR_SNAPIN )
  5134. {
  5135. CString str;
  5136. VERIFY (str.LoadString (IDS_COLUMN_PURPOSE) );
  5137. hr = m_pHeader->SetColumnText (0,
  5138. const_cast<PWSTR> ( (PCWSTR) str));
  5139. }
  5140. }
  5141. else
  5142. {
  5143. // View by stores
  5144. ASSERT (m_pHeader);
  5145. if ( m_pHeader && GetObjectType (pDataObject) == CERTMGR_SNAPIN )
  5146. {
  5147. CString str;
  5148. VERIFY (str.LoadString (IDS_COLUMN_LOG_CERTIFICATE_STORE));
  5149. hr = m_pHeader->SetColumnText (0,
  5150. const_cast<PWSTR> ( (PCWSTR) str));
  5151. }
  5152. }
  5153. }
  5154. if ( bShowPhysicalStores != m_bShowPhysicalStoresPersist )
  5155. hint |= HINT_CHANGE_STORE_TYPE;
  5156. if ( bShowArchivedCerts != m_bShowArchivedCertsPersist )
  5157. hint |= HINT_SHOW_ARCHIVE_CERTS;
  5158. if ( hint )
  5159. {
  5160. hr = m_pConsole->UpdateAllViews (pDataObject, 0, hint);
  5161. ASSERT (SUCCEEDED (hr));
  5162. m_fDirty = TRUE;
  5163. }
  5164. }
  5165. parentWnd.Detach ();
  5166. }
  5167. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::OnOptions: 0x%x\n", hr);
  5168. return hr;
  5169. }
  5170. bool CCertMgrComponentData::ShowArchivedCerts() const
  5171. {
  5172. _TRACE (0, L"Entering and leaving CCertMgrComponentData::ShowArchivedCerts\n");
  5173. if ( m_bShowArchivedCertsPersist )
  5174. return true;
  5175. else
  5176. return false;
  5177. }
  5178. HRESULT CCertMgrComponentData::OnPropertyChange (LPARAM param)
  5179. {
  5180. _TRACE (1, L"Entering CCertMgrComponentData::OnPropertyChange\n");
  5181. ASSERT (param);
  5182. if ( !param )
  5183. return E_FAIL;
  5184. HRESULT hr = S_OK;
  5185. LPDATAOBJECT pDataObject = reinterpret_cast<LPDATAOBJECT>(param);
  5186. bool bHandled = false;
  5187. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  5188. if ( pCookie )
  5189. {
  5190. switch (pCookie->m_objecttype)
  5191. {
  5192. case CERTMGR_SAFER_COMPUTER_ENTRY:
  5193. case CERTMGR_SAFER_USER_ENTRY:
  5194. {
  5195. HRESULTITEM itemID = 0;
  5196. if ( m_pResultData )
  5197. {
  5198. pCookie->Refresh ();
  5199. hr = m_pResultData->FindItemByLParam ( (LPARAM) pCookie, &itemID);
  5200. if ( SUCCEEDED (hr) )
  5201. {
  5202. hr = m_pResultData->UpdateItem (itemID);
  5203. if ( FAILED (hr) )
  5204. {
  5205. _TRACE (0, L"IResultData::UpdateItem () failed: 0x%x\n", hr);
  5206. }
  5207. }
  5208. else
  5209. {
  5210. _TRACE (0, L"IResultData::FindItemByLParam () failed: 0x%x\n", hr);
  5211. }
  5212. }
  5213. else
  5214. {
  5215. _TRACE (0, L"Unexpected error: m_pResultData was NULL\n");
  5216. hr = E_FAIL;
  5217. }
  5218. bHandled = true;
  5219. }
  5220. break;
  5221. case CERTMGR_SAFER_COMPUTER_LEVEL:
  5222. case CERTMGR_SAFER_USER_LEVEL:
  5223. if ( m_pConsole )
  5224. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  5225. break;
  5226. default:
  5227. break;
  5228. }
  5229. }
  5230. if ( !bHandled && m_pCryptUIMMCCallbackStruct )
  5231. {
  5232. if ( pDataObject == reinterpret_cast<LPDATAOBJECT>(m_pCryptUIMMCCallbackStruct->param) )
  5233. {
  5234. ::MMCFreeNotifyHandle (m_pCryptUIMMCCallbackStruct->lNotifyHandle);
  5235. pCookie = ConvertCookie (pDataObject);
  5236. if ( pCookie )
  5237. {
  5238. ASSERT (CERTMGR_CERTIFICATE == pCookie->m_objecttype);
  5239. if ( CERTMGR_CERTIFICATE == pCookie->m_objecttype )
  5240. {
  5241. CCertificate* pCert = reinterpret_cast<CCertificate*>(pCookie);
  5242. ASSERT (pCert);
  5243. if ( pCert && pCert->GetCertStore () )
  5244. {
  5245. pCert->GetCertStore ()->SetDirty ();
  5246. pCert->GetCertStore ()->Commit ();
  5247. pCert->GetCertStore ()->Close ();
  5248. }
  5249. }
  5250. }
  5251. pDataObject->Release ();
  5252. ::GlobalFree (m_pCryptUIMMCCallbackStruct);
  5253. m_pCryptUIMMCCallbackStruct = 0;
  5254. m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  5255. }
  5256. }
  5257. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::OnPropertyChange: 0x%x\n", hr);
  5258. return hr;
  5259. }
  5260. HRESULT CCertMgrComponentData::OnDeleteEFSPolicy(LPDATAOBJECT pDataObject, bool bCommitChanges)
  5261. {
  5262. _TRACE (1, L"Entering CCertMgrComponentData::OnDeleteEFSPolicy\n");
  5263. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  5264. ASSERT (pDataObject);
  5265. if ( !pDataObject )
  5266. return E_POINTER;
  5267. HRESULT hr = S_OK;
  5268. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  5269. ASSERT (pCookie);
  5270. if ( pCookie )
  5271. {
  5272. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (pCookie);
  5273. ASSERT (pStore && EFS_STORE == pStore->GetStoreType () && !pStore->IsNullEFSPolicy () );
  5274. if ( pStore && EFS_STORE == pStore->GetStoreType () && !pStore->IsNullEFSPolicy () )
  5275. {
  5276. pStore->DeleteEFSPolicy (bCommitChanges);
  5277. // Force scope item selection to force call to
  5278. // IComponent::QueryResultViewType ()
  5279. hr = m_pComponentConsole->SelectScopeItem (pStore->m_hScopeItem);
  5280. hr = m_pConsole->UpdateAllViews (pDataObject, 0, HINT_EFS_ADD_DEL_POLICY);
  5281. hr = OnNotifyExpand (pDataObject, TRUE, pStore->m_hScopeItem);
  5282. }
  5283. }
  5284. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::OnDeleteEFSPolicy: 0x%x\n", hr);
  5285. return hr;
  5286. }
  5287. HRESULT CCertMgrComponentData::OnInitEFSPolicy(LPDATAOBJECT pDataObject)
  5288. {
  5289. _TRACE (1, L"Entering CCertMgrComponentData::OnInitEFSPolicy\n");
  5290. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  5291. ASSERT (pDataObject);
  5292. if ( !pDataObject )
  5293. return E_POINTER;
  5294. HRESULT hr = S_OK;
  5295. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  5296. ASSERT (pCookie);
  5297. if ( pCookie )
  5298. {
  5299. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (pCookie);
  5300. ASSERT (pStore && EFS_STORE == pStore->GetStoreType () && pStore->IsNullEFSPolicy () );
  5301. if ( pStore && EFS_STORE == pStore->GetStoreType () && pStore->IsNullEFSPolicy () )
  5302. {
  5303. pStore->SetDirty ();
  5304. pStore->AllowEmptyEFSPolicy ();
  5305. pStore->PolicyChanged ();
  5306. pStore->Commit ();
  5307. hr = m_pConsole->UpdateAllViews (pDataObject, 0, HINT_EFS_ADD_DEL_POLICY);
  5308. }
  5309. }
  5310. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::OnInitEFSPolicy: 0x%x\n", hr);
  5311. return hr;
  5312. }
  5313. ///////////////////////////////////////////////////////////////////////////////
  5314. //
  5315. // CCertMgrComponentData::RemoveResultCookies
  5316. //
  5317. // Remove and delete all the result cookies corresponding to the LPRESULTDATA
  5318. // object passed in. Thus all cookies added to pResultData are released and
  5319. // removed from the master list.
  5320. //
  5321. ///////////////////////////////////////////////////////////////////////////////
  5322. void CCertMgrComponentData::RemoveResultCookies(LPRESULTDATA pResultData)
  5323. {
  5324. _TRACE (1, L"Entering CCertMgrComponentData::RemoveResultCookies\n");
  5325. CCertMgrCookie* pCookie = 0;
  5326. CCookie& rootCookie = QueryBaseRootCookie ();
  5327. POSITION curPos = 0;
  5328. for (POSITION nextPos = rootCookie.m_listResultCookieBlocks.GetHeadPosition (); nextPos; )
  5329. {
  5330. curPos = nextPos;
  5331. pCookie = reinterpret_cast <CCertMgrCookie*> (rootCookie.m_listResultCookieBlocks.GetNext (nextPos));
  5332. ASSERT (pCookie);
  5333. if ( pCookie )
  5334. {
  5335. if ( pCookie->m_resultDataID == pResultData )
  5336. {
  5337. pCookie->Release ();
  5338. rootCookie.m_listResultCookieBlocks.RemoveAt (curPos);
  5339. }
  5340. }
  5341. }
  5342. _TRACE (-1, L"Leaving CCertMgrComponentData::RemoveResultCookies\n");
  5343. }
  5344. HRESULT CCertMgrComponentData::ValidateCertChain(PCCERT_CONTEXT pCertContext)
  5345. {
  5346. _TRACE (1, L"Entering CCertMgrComponentData::ValidateCertChain\n");
  5347. HRESULT hr = S_OK;
  5348. ASSERT (pCertContext);
  5349. if ( !pCertContext )
  5350. return E_POINTER;
  5351. CERT_CONTEXT_LIST certChainList;
  5352. BOOL bValidated = GetCertificateChain (
  5353. const_cast<CERT_CONTEXT*>(pCertContext),
  5354. certChainList);
  5355. if ( !bValidated )
  5356. {
  5357. int iRetVal = 0;
  5358. CString text;
  5359. CString caption;
  5360. VERIFY (text.LoadString (IDS_CERT_COULD_NOT_BE_VALIDATED));
  5361. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  5362. hr = m_pConsole->MessageBox (text, caption,
  5363. MB_OK, &iRetVal);
  5364. }
  5365. // Clean up list
  5366. CERT_CONTEXT* pDeleteContext = 0;
  5367. while (!certChainList.IsEmpty () )
  5368. {
  5369. pDeleteContext = certChainList.RemoveHead ();
  5370. if ( pDeleteContext )
  5371. ::CertFreeCertificateContext (pCertContext);
  5372. }
  5373. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::ValidateCertChain: 0x%x\n", hr);
  5374. return hr;
  5375. }
  5376. HRESULT CCertMgrComponentData::RemoveCertChainFromPolicy(
  5377. PCCERT_CONTEXT pCertContext,
  5378. CERT_CONTEXT_LIST& certChainsThatCantBeDeleted)
  5379. {
  5380. _TRACE (1, L"Entering CCertMgrComponentData::RemoveCertChainFromPolicy\n");
  5381. HRESULT hr = S_OK;
  5382. ASSERT (pCertContext);
  5383. if ( !pCertContext )
  5384. return E_POINTER;
  5385. CERT_CONTEXT_LIST certChainList;
  5386. BOOL bValidated = GetCertificateChain (
  5387. const_cast<CERT_CONTEXT*>(pCertContext),
  5388. certChainList);
  5389. if ( bValidated )
  5390. {
  5391. // Add this cert context to the chain
  5392. certChainList.AddTail (
  5393. const_cast<CERT_CONTEXT*>
  5394. (::CertDuplicateCertificateContext (pCertContext)));
  5395. CCertStoreGPE CAStore (
  5396. CERT_SYSTEM_STORE_RELOCATE_FLAG,
  5397. _T (""),
  5398. _T (""),
  5399. CA_SYSTEM_STORE_NAME,
  5400. _T (""),
  5401. m_pGPEInformation,
  5402. NODEID_Machine,
  5403. m_pConsole);
  5404. for (POSITION pos = certChainList.GetHeadPosition (); pos;)
  5405. {
  5406. PCCERT_CONTEXT pCertChainContext = certChainList.GetNext (pos);
  5407. // Do not remove chain-certs whose EFS
  5408. // agents are still in the EFS store
  5409. bool bFound = false;
  5410. for (POSITION posND = certChainsThatCantBeDeleted.GetHeadPosition ();
  5411. posND; )
  5412. {
  5413. CERT_CONTEXT* pNonDelChainCertContext = certChainsThatCantBeDeleted.GetNext (posND);
  5414. if ( pNonDelChainCertContext )
  5415. {
  5416. if ( ::CertCompareCertificate (
  5417. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  5418. pCertChainContext->pCertInfo,
  5419. pNonDelChainCertContext->pCertInfo) )
  5420. {
  5421. bFound = true;
  5422. break;
  5423. }
  5424. }
  5425. }
  5426. // Was found in the list of certs that cant be deleted
  5427. // Try the next one.
  5428. if ( bFound )
  5429. continue;
  5430. // Wasn't found in the list that can't be deleted.
  5431. // Go ahead and delete
  5432. DWORD cbData = 20;
  5433. BYTE certHash[20];
  5434. BOOL bReturn = ::CertGetCertificateContextProperty (
  5435. pCertContext,
  5436. CERT_SHA1_HASH_PROP_ID,
  5437. certHash,
  5438. &cbData);
  5439. ASSERT (bReturn);
  5440. if ( bReturn )
  5441. {
  5442. CRYPT_DATA_BLOB blob = {sizeof (certHash), certHash};
  5443. PCCERT_CONTEXT pFoundCertContext = CertFindCertificateInStore(
  5444. CAStore.GetStoreHandle (),
  5445. 0,
  5446. 0,
  5447. CERT_FIND_SHA1_HASH,
  5448. &blob,
  5449. 0);
  5450. if ( pFoundCertContext )
  5451. {
  5452. ::CertDeleteCertificateFromStore (pFoundCertContext);
  5453. }
  5454. }
  5455. }
  5456. CAStore.Commit ();
  5457. }
  5458. // Clean up list
  5459. CERT_CONTEXT* pDeleteContext = 0;
  5460. while (!certChainList.IsEmpty () )
  5461. {
  5462. pDeleteContext = certChainList.RemoveHead ();
  5463. if ( pDeleteContext )
  5464. ::CertFreeCertificateContext (pCertContext);
  5465. }
  5466. _TRACE (-1, L"LeavingLeaving CCertMgrComponentData::RemoveCertChainFromPolicy: 0x%x\n", hr);
  5467. return hr;
  5468. }
  5469. STDMETHODIMP CCertMgrComponentData::GetLinkedTopics(LPOLESTR* lpCompiledHelpFiles)
  5470. {
  5471. HRESULT hr = S_OK;
  5472. if ( lpCompiledHelpFiles )
  5473. {
  5474. CString strLinkedTopic;
  5475. UINT nLen = ::GetSystemWindowsDirectory (strLinkedTopic.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  5476. strLinkedTopic.ReleaseBuffer();
  5477. if ( nLen )
  5478. {
  5479. strLinkedTopic += L"\\help\\";
  5480. strLinkedTopic += m_strLinkedHelpFile;
  5481. *lpCompiledHelpFiles = reinterpret_cast<LPOLESTR>
  5482. (CoTaskMemAlloc((strLinkedTopic.GetLength() + 1)* sizeof(wchar_t)));
  5483. if ( *lpCompiledHelpFiles )
  5484. {
  5485. // security review 2/26/2002 BryanWal ok
  5486. wcscpy(*lpCompiledHelpFiles, (PWSTR)(PCWSTR)strLinkedTopic);
  5487. }
  5488. else
  5489. hr = E_OUTOFMEMORY;
  5490. }
  5491. else
  5492. hr = E_FAIL;
  5493. }
  5494. else
  5495. return E_POINTER;
  5496. return hr;
  5497. }
  5498. STDMETHODIMP CCertMgrComponentData::GetHelpTopic(LPOLESTR* lpCompiledHelpFile)
  5499. {
  5500. return CComponentData::GetHelpTopic (lpCompiledHelpFile);
  5501. }