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.

1033 lines
40 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1997-2002.
  6. //
  7. // File: ComponentDataMenus.cpp
  8. //
  9. // Contents: Implementation of menu stuff 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 "Certifct.h"
  19. #ifdef _DEBUG
  20. #ifndef ALPHA
  21. #define new DEBUG_NEW
  22. #endif
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. extern bool g_bSchemaIsW2K;
  27. ///////////////////////////////////////////////////////////////////////////////
  28. // IExtendContextMenu implementation
  29. //
  30. STDMETHODIMP CCertMgrComponentData::AddMenuItems (LPDATAOBJECT pDataObject,
  31. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  32. long *pInsertionAllowed)
  33. {
  34. if ( ((LPDATAOBJECT) -1) == pDataObject )
  35. return E_FAIL;
  36. _TRACE (1, L"Entering CCertMgrComponentData::AddMenuItems\n");
  37. HRESULT hr = S_OK;
  38. BOOL bIsFileView = !m_szFileName.IsEmpty ();
  39. CCertMgrCookie* pCookie = 0;
  40. LPDATAOBJECT pMSDO = ExtractMultiSelect (pDataObject);
  41. m_bMultipleObjectsSelected = false;
  42. if ( pMSDO )
  43. {
  44. m_bMultipleObjectsSelected = true;
  45. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pMSDO);
  46. ASSERT (pDO);
  47. if ( pDO )
  48. {
  49. // Get first cookie - all items should be the same?
  50. // Is this a valid assumption?
  51. // TODO: Verify
  52. pDO->Reset();
  53. if ( pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) == S_FALSE )
  54. return S_FALSE;
  55. }
  56. else
  57. return E_UNEXPECTED;
  58. }
  59. else
  60. pCookie = ConvertCookie (pDataObject);
  61. ASSERT (pCookie);
  62. if ( !pCookie )
  63. return E_UNEXPECTED;
  64. CertificateManagerObjectType objType = pCookie->m_objecttype;
  65. // Don't add any menu items if the computer is known not to be valid.
  66. if ( !m_fInvalidComputer )
  67. {
  68. // Don't add menu items if this is a serialized file
  69. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_TOP )
  70. {
  71. switch (objType)
  72. {
  73. case CERTMGR_CERTIFICATE:
  74. if ( !m_bMultipleObjectsSelected )
  75. {
  76. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  77. ASSERT (pCert);
  78. if ( pCert )
  79. {
  80. hr = AddSingleMenuItem (pContextMenuCallback,
  81. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  82. IDS_VIEW,
  83. IDS_VIEW_HINT,
  84. IDM_OPEN);
  85. }
  86. else
  87. hr = E_FAIL;
  88. }
  89. break;
  90. case CERTMGR_CRL:
  91. if ( !m_bMultipleObjectsSelected )
  92. hr = AddSingleMenuItem (pContextMenuCallback,
  93. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  94. IDS_VIEW,
  95. IDS_CRL_VIEW_HINT,
  96. IDM_OPEN);
  97. break;
  98. case CERTMGR_CTL:
  99. if ( !m_bMultipleObjectsSelected )
  100. hr = AddSingleMenuItem (pContextMenuCallback,
  101. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  102. IDS_VIEW,
  103. IDS_CTL_VIEW_HINT,
  104. IDM_OPEN);
  105. break;
  106. case CERTMGR_SNAPIN:
  107. if ( CERT_SYSTEM_STORE_CURRENT_USER != m_dwLocationPersist && m_hRootScopeItem )
  108. {
  109. hr = AddSingleMenuItem (pContextMenuCallback,
  110. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  111. IDS_CHANGE_COMPUTER,
  112. IDS_CHANGE_COMPUTER_HINT,
  113. IDM_TOP_CHANGE_COMPUTER);
  114. }
  115. // fall through
  116. case CERTMGR_PHYS_STORE:
  117. case CERTMGR_USAGE:
  118. case CERTMGR_LOG_STORE:
  119. ASSERT (!m_bMultipleObjectsSelected);
  120. hr = AddSingleMenuItem (pContextMenuCallback,
  121. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  122. IDS_FIND,
  123. IDS_FIND_HINT,
  124. IDM_TOP_FIND);
  125. break;
  126. case CERTMGR_LOG_STORE_RSOP:
  127. break;
  128. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  129. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  130. break;
  131. case CERTMGR_LOG_STORE_GPE:
  132. ASSERT (!m_bMultipleObjectsSelected);
  133. {
  134. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*>
  135. (pCookie);
  136. ASSERT (pStore);
  137. if ( pStore )
  138. {
  139. switch (pStore->GetStoreType ())
  140. {
  141. case TRUST_STORE:
  142. case ROOT_STORE:
  143. if ( pStore->GetStoreHandle () )
  144. {
  145. if ( !pStore->IsReadOnly () )
  146. hr = AddSingleMenuItem (pContextMenuCallback,
  147. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  148. IDS_IMPORT,
  149. IDS_IMPORT_HINT,
  150. IDM_TASK_IMPORT);
  151. pStore->Close ();
  152. }
  153. break;
  154. case EFS_STORE:
  155. if ( pStore->GetStoreHandle () )
  156. {
  157. if ( !pStore->IsReadOnly () )
  158. hr = AddSingleMenuItem (pContextMenuCallback,
  159. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  160. IDS_ADD_DATA_RECOVERY_AGENT,
  161. IDS_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  162. IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT);
  163. if ( !m_bMachineIsStandAlone )
  164. {
  165. if ( !pStore->IsReadOnly () )
  166. hr = AddSingleMenuItem (pContextMenuCallback,
  167. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  168. IDS_CREATE,
  169. IDS_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  170. IDM_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT);
  171. }
  172. pStore->Close ();
  173. }
  174. else if ( pStore->IsNullEFSPolicy () )
  175. {
  176. if ( !pStore->IsReadOnly () )
  177. hr = AddSingleMenuItem (pContextMenuCallback,
  178. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  179. IDS_ADD_DATA_RECOVERY_AGENT,
  180. IDS_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  181. IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT);
  182. if ( !m_bMachineIsStandAlone )
  183. {
  184. if ( !pStore->IsReadOnly () )
  185. hr = AddSingleMenuItem (pContextMenuCallback,
  186. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  187. IDS_CREATE,
  188. IDS_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  189. IDM_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT);
  190. }
  191. pStore->Close ();
  192. }
  193. break;
  194. default:
  195. break;
  196. }
  197. }
  198. }
  199. break;
  200. case CERTMGR_CRL_CONTAINER:
  201. case CERTMGR_CTL_CONTAINER:
  202. case CERTMGR_CERT_CONTAINER:
  203. ASSERT (!m_bMultipleObjectsSelected);
  204. break;
  205. case CERTMGR_SAFER_COMPUTER_LEVEL:
  206. case CERTMGR_SAFER_USER_LEVEL:
  207. if ( m_pGPEInformation )
  208. {
  209. CSaferLevel* pLevel = reinterpret_cast <CSaferLevel*>
  210. (pCookie);
  211. ASSERT (pLevel);
  212. if ( pLevel )
  213. {
  214. // RAID#265590 Safer Windows: "Set as default" menu
  215. // item is enabled in the context menu of a security
  216. // level when the security level is already the default.
  217. if ( ( SAFER_LEVELID_DISALLOWED == pLevel->GetLevel () ||
  218. SAFER_LEVELID_FULLYTRUSTED == pLevel->GetLevel () ||
  219. SAFER_LEVELID_NORMALUSER == pLevel->GetLevel ())
  220. && !pLevel->IsDefault () &&
  221. m_pGPEInformation)
  222. {
  223. hr = AddSingleMenuItem (pContextMenuCallback,
  224. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  225. IDS_SAFER_SET_DEFAULT,
  226. IDS_SAFER_SET_DEFAULT_HINT,
  227. IDM_SAFER_LEVEL_SET_DEFAULT);
  228. }
  229. }
  230. }
  231. break;
  232. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  233. case CERTMGR_SAFER_USER_ENTRIES:
  234. if ( m_pGPEInformation )
  235. hr = AddSaferNewEntryMenuItems (pContextMenuCallback,
  236. CCM_INSERTIONPOINTID_PRIMARY_TOP);
  237. break;
  238. case CERTMGR_SAFER_COMPUTER_ROOT:
  239. case CERTMGR_SAFER_USER_ROOT:
  240. {
  241. CSaferRootCookie* pSaferRootCookie = dynamic_cast <CSaferRootCookie*> (pCookie);
  242. if ( pSaferRootCookie )
  243. {
  244. // Don't add these menu options if the Safer node
  245. // hasn't been expanded at least once, otherwise, we
  246. // can't tell if there is already a safer policy or not.
  247. if ( !m_bIsRSOP && pSaferRootCookie->m_bExpandedOnce )
  248. {
  249. if ( pSaferRootCookie->m_bCreateSaferNodes )
  250. hr = AddSingleMenuItem (pContextMenuCallback,
  251. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  252. IDS_DELETE_SAFER_POLICY,
  253. IDS_DELETE_SAFER_POLICY_HINT,
  254. IDM_TOP_DELETE_NEW_SAFER_POLICY);
  255. else
  256. hr = AddSingleMenuItem (pContextMenuCallback,
  257. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  258. IDS_NEW_SAFER_POLICY,
  259. IDS_NEW_SAFER_POLICY_HINT,
  260. IDM_TOP_CREATE_NEW_SAFER_POLICY);
  261. }
  262. }
  263. }
  264. break;
  265. default:
  266. break;
  267. }
  268. }
  269. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_NEW )
  270. {
  271. if ( CERTMGR_LOG_STORE_GPE == objType )
  272. {
  273. ASSERT (!m_bMultipleObjectsSelected);
  274. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*>
  275. (pCookie);
  276. ASSERT (pStore);
  277. if ( pStore && pStore->GetStoreHandle () )
  278. {
  279. switch (pStore->GetStoreType ())
  280. {
  281. case TRUST_STORE:
  282. if ( !pStore->IsReadOnly () )
  283. hr = AddSingleMenuItem (pContextMenuCallback,
  284. CCM_INSERTIONPOINTID_PRIMARY_NEW,
  285. IDS_NEW_CTL,
  286. IDS_NEW_CTL_HINT,
  287. IDM_NEW_CTL);
  288. break;
  289. case ACRS_STORE:
  290. if ( !pStore->IsReadOnly () )
  291. hr = AddSingleMenuItem (pContextMenuCallback,
  292. CCM_INSERTIONPOINTID_PRIMARY_NEW,
  293. IDS_NEW_AUTO_CERT_REQUEST,
  294. IDS_NEW_AUTO_CERT_REQUEST_HINT,
  295. IDM_NEW_ACRS);
  296. break;
  297. case EFS_STORE:
  298. if ( !pStore->IsReadOnly () )
  299. hr = AddSingleMenuItem (pContextMenuCallback,
  300. CCM_INSERTIONPOINTID_PRIMARY_NEW,
  301. IDS_ENCRYPTED_RECOVERY_AGENT,
  302. IDS_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  303. IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT2);
  304. break;
  305. default:
  306. break;
  307. }
  308. pStore->Close ();
  309. }
  310. }
  311. }
  312. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_TASK )
  313. {
  314. switch (objType)
  315. {
  316. case CERTMGR_CERTIFICATE:
  317. if ( !m_bIsRSOP )
  318. {
  319. CCertificate* pCert =
  320. reinterpret_cast <CCertificate*> (pCookie);
  321. ASSERT (pCert);
  322. if ( pCert && pCert->GetCertStore () )
  323. {
  324. hr = AddCertificateTaskMenuItems (
  325. pContextMenuCallback,
  326. (pCert->GetStoreType () == MY_STORE),
  327. pCert->GetCertStore ()->IsReadOnly (),
  328. pCert);
  329. }
  330. }
  331. break;
  332. case CERTMGR_CRL:
  333. if ( !m_bMultipleObjectsSelected )
  334. {
  335. hr = AddSingleMenuItem (pContextMenuCallback,
  336. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  337. IDS_EXPORT,
  338. IDS_CRL_EXPORT_HINT,
  339. IDM_TASK_CRL_EXPORT);
  340. if ( !m_bIsRSOP )
  341. hr = AddSingleMenuItem (pContextMenuCallback,
  342. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  343. IDS_VIEW,
  344. IDS_VIEW_HINT,
  345. IDM_TASK_OPEN);
  346. }
  347. break;
  348. case CERTMGR_AUTO_CERT_REQUEST:
  349. if ( !m_bMultipleObjectsSelected && !m_bIsRSOP )
  350. {
  351. CAutoCertRequest* pAutoCert =
  352. reinterpret_cast <CAutoCertRequest*> (pCookie);
  353. ASSERT (pAutoCert);
  354. if ( pAutoCert )
  355. {
  356. if ( !pAutoCert->GetCertStore ().IsReadOnly () )
  357. hr = AddSingleMenuItem (pContextMenuCallback,
  358. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  359. IDS_EDIT,
  360. IDS_ACR_EDIT_HINT,
  361. IDM_EDIT_ACRS);
  362. }
  363. }
  364. break;
  365. case CERTMGR_CTL:
  366. if ( !m_bIsRSOP )
  367. {
  368. CCTL* pCTL =
  369. reinterpret_cast <CCTL*> (pCookie);
  370. ASSERT (pCTL);
  371. if ( pCTL )
  372. {
  373. hr = AddCTLTaskMenuItems (pContextMenuCallback, pCTL->GetCertStore ().IsReadOnly ());
  374. }
  375. }
  376. break;
  377. case CERTMGR_SNAPIN:
  378. ASSERT (!m_bMultipleObjectsSelected);
  379. hr = AddSingleMenuItem (pContextMenuCallback,
  380. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  381. IDS_FIND,
  382. IDS_FIND_HINT,
  383. IDM_TASK_FIND);
  384. if ( SUCCEEDED (hr) &&
  385. CERT_SYSTEM_STORE_CURRENT_USER != m_dwLocationPersist &&
  386. m_hRootScopeItem )
  387. {
  388. hr = AddSingleMenuItem (pContextMenuCallback,
  389. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  390. IDS_CHANGE_COMPUTER,
  391. IDS_CHANGE_COMPUTER_HINT,
  392. IDM_TASK_CHANGE_COMPUTER);
  393. }
  394. // must be targetting current user OR LOCAL machine, must be joined to domain
  395. if( SUCCEEDED (hr) &&
  396. !m_bMachineIsStandAlone &&
  397. ((CERT_SYSTEM_STORE_CURRENT_USER == m_dwLocationPersist) || (CERT_SYSTEM_STORE_LOCAL_MACHINE == m_dwLocationPersist)) &&
  398. IsLocalComputername (m_strMachineNamePersist))
  399. {
  400. // NTRAID# 451902 Certmgr: XP client in Win2K Schema --
  401. // should not give user option to pulse user autoenrollment
  402. if ( g_bSchemaIsW2K && CERT_SYSTEM_STORE_CURRENT_USER == m_dwLocationPersist )
  403. break;
  404. hr = AddSingleMenuItem (pContextMenuCallback,
  405. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  406. IDS_PULSEAUTOENROLL,
  407. IDS_PULSEAUTOENROLL_HINT,
  408. IDM_TASK_PULSEAUTOENROLL);
  409. }
  410. break;
  411. case CERTMGR_USAGE:
  412. ASSERT (!m_bMultipleObjectsSelected);
  413. hr = AddSingleMenuItem (pContextMenuCallback,
  414. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  415. IDS_FIND,
  416. IDS_FIND_HINT,
  417. IDM_TASK_FIND);
  418. if ( !bIsFileView )
  419. {
  420. // Bug 254166 Certificate snapin: options which permit remote machine enrollment/renewal must be removed
  421. if ( IsLocalComputername (m_strMachineNamePersist) && !m_bIsRSOP )
  422. {
  423. hr = AddSeparator (pContextMenuCallback);
  424. // NOTE: New certs will be added only to MY store.
  425. if ( !m_bMachineIsStandAlone && CERT_SYSTEM_STORE_SERVICES != m_dwLocationPersist )
  426. hr = AddSingleMenuItem (pContextMenuCallback,
  427. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  428. IDS_ENROLL_NEW_CERT,
  429. IDS_ENROLL_NEW_CERT_HINT,
  430. IDM_ENROLL_NEW_CERT);
  431. if ( SUCCEEDED (hr) )
  432. {
  433. hr = AddSingleMenuItem (pContextMenuCallback,
  434. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  435. IDS_IMPORT,
  436. IDS_IMPORT_HINT,
  437. IDM_TASK_IMPORT);
  438. }
  439. }
  440. }
  441. break;
  442. case CERTMGR_PHYS_STORE:
  443. ASSERT (!m_bMultipleObjectsSelected);
  444. hr = AddSingleMenuItem (pContextMenuCallback,
  445. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  446. IDS_FIND,
  447. IDS_FIND_HINT,
  448. IDM_TASK_FIND);
  449. if ( !bIsFileView && !m_bIsRSOP)
  450. {
  451. hr = AddSeparator (pContextMenuCallback);
  452. {
  453. CCertStore* pStore =
  454. reinterpret_cast <CCertStore*> (pCookie);
  455. ASSERT (pStore);
  456. if ( pStore && pStore->GetStoreHandle () )
  457. {
  458. // Bug 254166 Certificate snapin: options which permit remote machine enrollment/renewal must be removed
  459. if ( pStore->GetStoreType () == MY_STORE &&
  460. IsLocalComputername (m_szManagedComputer) &&
  461. !m_bMachineIsStandAlone )
  462. {
  463. if ( !pStore->IsReadOnly () && CERT_SYSTEM_STORE_SERVICES != m_dwLocationPersist )
  464. hr = AddSingleMenuItem (pContextMenuCallback,
  465. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  466. IDS_ENROLL_NEW_CERT,
  467. IDS_ENROLL_NEW_CERT_HINT,
  468. IDM_ENROLL_NEW_CERT);
  469. }
  470. if ( SUCCEEDED (hr) )
  471. if ( !pStore->IsReadOnly () )
  472. hr = AddSingleMenuItem (pContextMenuCallback,
  473. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  474. IDS_IMPORT,
  475. IDS_IMPORT_HINT,
  476. IDM_TASK_IMPORT);
  477. pStore->Close ();
  478. }
  479. }
  480. hr = AddSingleMenuItem (pContextMenuCallback,
  481. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  482. IDS_EXPORT_STORE,
  483. IDS_EXPORT_STORE_HINT,
  484. IDM_TASK_EXPORT_STORE);
  485. }
  486. break;
  487. case CERTMGR_LOG_STORE:
  488. ASSERT (!m_bMultipleObjectsSelected);
  489. hr = AddSingleMenuItem (pContextMenuCallback,
  490. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  491. IDS_FIND,
  492. IDS_FIND_HINT,
  493. IDM_TASK_FIND);
  494. if ( !bIsFileView && !m_bIsRSOP )
  495. {
  496. hr = AddSeparator (pContextMenuCallback);
  497. {
  498. CCertStore* pStore =
  499. reinterpret_cast <CCertStore*> (pCookie);
  500. ASSERT (pStore);
  501. if ( pStore && pStore->GetStoreHandle () )
  502. {
  503. // Bug 254166 Certificate snapin: options which permit remote machine enrollment/renewal must be removed
  504. if ( pStore->GetStoreType () == MY_STORE &&
  505. IsLocalComputername (m_szManagedComputer) &&
  506. !m_bMachineIsStandAlone )
  507. {
  508. if ( !pStore->IsReadOnly () && CERT_SYSTEM_STORE_SERVICES != m_dwLocationPersist )
  509. hr = AddSingleMenuItem (pContextMenuCallback,
  510. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  511. IDS_ENROLL_NEW_CERT,
  512. IDS_ENROLL_NEW_CERT_HINT,
  513. IDM_ENROLL_NEW_CERT);
  514. }
  515. if ( !pStore->IsReadOnly () )
  516. hr = AddSingleMenuItem (pContextMenuCallback,
  517. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  518. IDS_IMPORT,
  519. IDS_IMPORT_HINT,
  520. IDM_TASK_IMPORT);
  521. pStore->Close ();
  522. }
  523. }
  524. }
  525. break;
  526. case CERTMGR_LOG_STORE_RSOP:
  527. break;
  528. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  529. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  530. break;
  531. case CERTMGR_LOG_STORE_GPE:
  532. ASSERT (!m_bMultipleObjectsSelected);
  533. {
  534. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*>
  535. (pCookie);
  536. ASSERT (pStore);
  537. if ( pStore )
  538. {
  539. switch (pStore->GetStoreType ())
  540. {
  541. case TRUST_STORE:
  542. case ROOT_STORE:
  543. if ( pStore->GetStoreHandle () && !m_bIsRSOP )
  544. {
  545. if ( !pStore->IsReadOnly () )
  546. hr = AddSingleMenuItem (pContextMenuCallback,
  547. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  548. IDS_IMPORT,
  549. IDS_IMPORT_HINT,
  550. IDM_TASK_IMPORT);
  551. pStore->Close ();
  552. }
  553. break;
  554. case EFS_STORE:
  555. if ( pStore->GetStoreHandle () )
  556. {
  557. if ( !pStore->IsReadOnly () )
  558. hr = AddSingleMenuItem (pContextMenuCallback,
  559. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  560. IDS_ADD_DATA_RECOVERY_AGENT,
  561. IDS_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  562. IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT1);
  563. if ( !m_bMachineIsStandAlone )
  564. {
  565. if ( !pStore->IsReadOnly () )
  566. hr = AddSingleMenuItem (pContextMenuCallback,
  567. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  568. IDS_CREATE,
  569. IDS_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  570. IDM_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT);
  571. }
  572. hr = AddSingleMenuItem (pContextMenuCallback,
  573. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  574. IDS_DEL_POLICY,
  575. IDS_DEL_POLICY_HINT,
  576. IDM_DEL_POLICY);
  577. pStore->Close ();
  578. }
  579. else if ( pStore->IsNullEFSPolicy () )
  580. {
  581. if ( !pStore->IsReadOnly () )
  582. hr = AddSingleMenuItem (pContextMenuCallback,
  583. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  584. IDS_ADD_DATA_RECOVERY_AGENT,
  585. IDS_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  586. IDM_ADD_DOMAIN_ENCRYPTED_RECOVERY_AGENT1);
  587. if ( !m_bMachineIsStandAlone )
  588. {
  589. if ( !pStore->IsReadOnly () )
  590. hr = AddSingleMenuItem (pContextMenuCallback,
  591. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  592. IDS_CREATE,
  593. IDS_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT_HINT,
  594. IDM_CREATE_DOMAIN_ENCRYPTED_RECOVERY_AGENT);
  595. }
  596. hr = AddSingleMenuItem (pContextMenuCallback,
  597. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  598. IDS_INIT_POLICY,
  599. IDS_INIT_POLICY_HINT,
  600. IDM_INIT_POLICY);
  601. pStore->Close ();
  602. }
  603. break;
  604. default:
  605. break;
  606. }
  607. }
  608. }
  609. break;
  610. case CERTMGR_CRL_CONTAINER:
  611. ASSERT (!m_bMultipleObjectsSelected);
  612. break;
  613. case CERTMGR_CTL_CONTAINER:
  614. ASSERT (!m_bMultipleObjectsSelected);
  615. if ( !bIsFileView && !m_bIsRSOP )
  616. {
  617. CContainerCookie* pContainer =
  618. reinterpret_cast <CContainerCookie*> (pCookie);
  619. ASSERT (pContainer);
  620. if ( pContainer )
  621. {
  622. if ( !pContainer->GetCertStore ().IsReadOnly () )
  623. hr = AddSingleMenuItem (pContextMenuCallback,
  624. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  625. IDS_IMPORT,
  626. IDS_IMPORT_HINT,
  627. IDM_TASK_IMPORT);
  628. }
  629. }
  630. break;
  631. case CERTMGR_CERT_CONTAINER:
  632. ASSERT (!m_bMultipleObjectsSelected);
  633. if ( !bIsFileView && !m_bIsRSOP )
  634. {
  635. CContainerCookie* pContainer =
  636. reinterpret_cast <CContainerCookie*> (pCookie);
  637. ASSERT (pContainer);
  638. if ( pContainer )
  639. {
  640. // Bug 254166 Certificate snapin: options which permit remote machine enrollment/renewal must be removed
  641. if ( pContainer->GetStoreType () == MY_STORE &&
  642. IsLocalComputername (m_szManagedComputer) &&
  643. !m_bMachineIsStandAlone )
  644. {
  645. if ( !pContainer->GetCertStore ().IsReadOnly () && CERT_SYSTEM_STORE_SERVICES != m_dwLocationPersist)
  646. hr = AddSingleMenuItem (pContextMenuCallback,
  647. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  648. IDS_ENROLL_NEW_CERT,
  649. IDS_ENROLL_NEW_CERT_HINT,
  650. IDM_ENROLL_NEW_CERT);
  651. }
  652. if ( !pContainer->GetCertStore ().IsReadOnly () )
  653. hr = AddSingleMenuItem (pContextMenuCallback,
  654. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  655. IDS_IMPORT,
  656. IDS_IMPORT_HINT,
  657. IDM_TASK_IMPORT);
  658. }
  659. }
  660. break;
  661. case CERTMGR_SAFER_COMPUTER_LEVEL:
  662. case CERTMGR_SAFER_USER_LEVEL:
  663. if ( m_pGPEInformation )
  664. {
  665. CSaferLevel* pLevel = reinterpret_cast <CSaferLevel*>
  666. (pCookie);
  667. ASSERT (pLevel);
  668. if ( pLevel )
  669. {
  670. // RAID#265590 Safer Windows: "Set as default" menu
  671. // item is enabled in the context menu of a security
  672. // level when the security level is already the default.
  673. if ( (SAFER_LEVELID_DISALLOWED == pLevel->GetLevel () ||
  674. SAFER_LEVELID_FULLYTRUSTED == pLevel->GetLevel () ||
  675. SAFER_LEVELID_NORMALUSER == pLevel->GetLevel ())
  676. && !pLevel->IsDefault () )
  677. {
  678. hr = AddSingleMenuItem (pContextMenuCallback,
  679. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  680. IDS_SAFER_SET_DEFAULT,
  681. IDS_SAFER_SET_DEFAULT_HINT,
  682. IDM_SAFER_LEVEL_SET_DEFAULT);
  683. }
  684. }
  685. }
  686. break;
  687. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  688. case CERTMGR_SAFER_USER_ENTRIES:
  689. if ( m_pGPEInformation )
  690. hr = AddSaferNewEntryMenuItems (pContextMenuCallback,
  691. CCM_INSERTIONPOINTID_PRIMARY_TASK);
  692. break;
  693. case CERTMGR_SAFER_COMPUTER_ROOT:
  694. case CERTMGR_SAFER_USER_ROOT:
  695. {
  696. CSaferRootCookie* pSaferRootCookie = dynamic_cast <CSaferRootCookie*> (pCookie);
  697. if ( pSaferRootCookie )
  698. {
  699. // Don't add these menu options if the Safer node
  700. // hasn't been expanded at least once, otherwise, we
  701. // can't tell if there is already a safer policy or not.
  702. if ( !m_bIsRSOP && pSaferRootCookie->m_bExpandedOnce )
  703. {
  704. if ( pSaferRootCookie->m_bCreateSaferNodes )
  705. hr = AddSingleMenuItem (pContextMenuCallback,
  706. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  707. IDS_DELETE_SAFER_POLICY,
  708. IDS_DELETE_SAFER_POLICY_HINT,
  709. IDM_TASK_DELETE_NEW_SAFER_POLICY);
  710. else
  711. hr = AddSingleMenuItem (pContextMenuCallback,
  712. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  713. IDS_NEW_SAFER_POLICY,
  714. IDS_NEW_SAFER_POLICY_HINT,
  715. IDM_TASK_CREATE_NEW_SAFER_POLICY);
  716. }
  717. }
  718. }
  719. break;
  720. default:
  721. break;
  722. }
  723. }
  724. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_VIEW )
  725. {
  726. switch (objType)
  727. {
  728. case CERTMGR_CERTIFICATE:
  729. case CERTMGR_CRL:
  730. case CERTMGR_CTL:
  731. case CERTMGR_AUTO_CERT_REQUEST:
  732. break;
  733. case CERTMGR_SNAPIN:
  734. case CERTMGR_PHYS_STORE:
  735. case CERTMGR_USAGE:
  736. case CERTMGR_LOG_STORE:
  737. ASSERT (!m_bMultipleObjectsSelected);
  738. hr = AddSingleMenuItem (pContextMenuCallback,
  739. CCM_INSERTIONPOINTID_PRIMARY_VIEW,
  740. IDS_OPTIONS,
  741. IDS_OPTIONS_HINT,
  742. IDM_OPTIONS);
  743. break;
  744. default:
  745. break;
  746. }
  747. }
  748. }
  749. else
  750. {
  751. // Computer name is not valid. Only allow "Change Computer"
  752. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_TOP )
  753. {
  754. if ( CERTMGR_SNAPIN == objType )
  755. {
  756. if ( CERT_SYSTEM_STORE_CURRENT_USER != m_dwLocationPersist )
  757. {
  758. hr = AddSingleMenuItem (pContextMenuCallback,
  759. CCM_INSERTIONPOINTID_PRIMARY_TOP,
  760. IDS_CHANGE_COMPUTER,
  761. IDS_CHANGE_COMPUTER_HINT,
  762. IDM_TOP_CHANGE_COMPUTER);
  763. }
  764. }
  765. }
  766. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_TASK )
  767. {
  768. if ( CERTMGR_SNAPIN == objType )
  769. {
  770. if ( CERT_SYSTEM_STORE_CURRENT_USER != m_dwLocationPersist )
  771. {
  772. hr = AddSingleMenuItem (pContextMenuCallback,
  773. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  774. IDS_CHANGE_COMPUTER,
  775. IDS_CHANGE_COMPUTER_HINT,
  776. IDM_TASK_CHANGE_COMPUTER);
  777. }
  778. }
  779. }
  780. }
  781. _TRACE (-1, L"Leaving CCertMgrComponentData::AddMenuItems: 0x%x\n", hr);
  782. return hr;
  783. }
  784. HRESULT CCertMgrComponentData::AddCertificateTaskMenuItems (
  785. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  786. const bool bIsMyStore,
  787. bool bIsReadOnly,
  788. CCertificate* /*pCert*/)
  789. {
  790. _TRACE (1, L"Entering CCertMgrComponentData::AddCertificateTaskMenuItems\n");
  791. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  792. ASSERT (pContextMenuCallback);
  793. HRESULT hr = S_OK;
  794. if ( !m_bMultipleObjectsSelected )
  795. {
  796. hr = AddSingleMenuItem (pContextMenuCallback,
  797. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  798. IDS_VIEW,
  799. IDS_VIEW_HINT,
  800. IDM_TASK_OPEN);
  801. AddSeparator (pContextMenuCallback);
  802. if ( m_szFileName.IsEmpty () )
  803. {
  804. // Bug 254166 Certificate snapin: options which permit remote machine enrollment/renewal must be removed
  805. if ( bIsMyStore &&
  806. CERT_SYSTEM_STORE_SERVICES != m_dwLocationPersist &&
  807. IsLocalComputername (m_szManagedComputer) &&
  808. !m_bMachineIsStandAlone &&
  809. !bIsReadOnly )
  810. {
  811. hr = AddSingleMenuItem (pContextMenuCallback,
  812. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  813. IDS_ENROLL_CERT_WITH_NEW_KEY,
  814. IDS_ENROLL_CERT_WITH_NEW_KEY_HINT,
  815. IDM_ENROLL_NEW_CERT_NEW_KEY);
  816. hr = AddSingleMenuItem (pContextMenuCallback,
  817. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  818. IDS_ENROLL_CERT_WITH_SAME_KEY,
  819. IDS_ENROLL_CERT_WITH_SAME_KEY_HINT,
  820. IDM_ENROLL_NEW_CERT_SAME_KEY);
  821. hr = AddSingleMenuItem (pContextMenuCallback,
  822. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  823. IDS_RENEW_NEW_KEY,
  824. IDS_RENEW_NEW_KEY_HINT,
  825. IDM_TASK_RENEW_NEW_KEY);
  826. hr = AddSingleMenuItem (pContextMenuCallback,
  827. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  828. IDS_RENEW_SAME_KEY,
  829. IDS_RENEW_SAME_KEY_HINT,
  830. IDM_TASK_RENEW_SAME_KEY);
  831. }
  832. }
  833. }
  834. hr = AddSingleMenuItem (pContextMenuCallback,
  835. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  836. IDS_EXPORT,
  837. IDS_EXPORT_HINT,
  838. IDM_TASK_EXPORT);
  839. _TRACE (-1, L"Leaving CCertMgrComponentData::AddCertificateTaskMenuItems: 0x%x\n", hr);
  840. return hr;
  841. }
  842. HRESULT CCertMgrComponentData::AddCTLTaskMenuItems (LPCONTEXTMENUCALLBACK pContextMenuCallback, bool bIsReadOnly)
  843. {
  844. _TRACE (1, L"Entering CCertMgrComponentData::AddCTLTaskMenuItems\n");
  845. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  846. ASSERT (pContextMenuCallback);
  847. HRESULT hr = S_OK;
  848. if ( !m_bMultipleObjectsSelected )
  849. hr = AddSingleMenuItem (pContextMenuCallback,
  850. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  851. IDS_VIEW,
  852. IDS_CTL_VIEW_HINT,
  853. IDM_TASK_OPEN);
  854. hr = AddSingleMenuItem (pContextMenuCallback,
  855. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  856. IDS_EXPORT,
  857. IDS_EXPORT_HINT,
  858. IDM_TASK_CTL_EXPORT);
  859. if ( !m_bMultipleObjectsSelected && !bIsReadOnly )
  860. {
  861. hr = AddSingleMenuItem (pContextMenuCallback,
  862. CCM_INSERTIONPOINTID_PRIMARY_TASK,
  863. IDS_EDIT,
  864. IDS_CTL_EDIT_HINT,
  865. IDM_CTL_EDIT);
  866. }
  867. _TRACE (-1, L"Leaving CCertMgrComponentData::AddCTLTaskMenuItems: 0x%x\n", hr);
  868. return hr;
  869. }
  870. HRESULT CCertMgrComponentData::AddSeparator (LPCONTEXTMENUCALLBACK pContextMenuCallback)
  871. {
  872. _TRACE (1, L"Entering CCertMgrComponentData::AddSeparator\n");
  873. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  874. ASSERT (pContextMenuCallback);
  875. CONTEXTMENUITEM menuItem;
  876. // security review 2/22/2002 BryanWal ok
  877. ::ZeroMemory (&menuItem, sizeof (menuItem));
  878. menuItem.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  879. menuItem.fSpecialFlags = 0;
  880. menuItem.strName = _T ("Separator"); // Dummy name
  881. menuItem.strStatusBarText = _T ("Separator");// Dummy status text
  882. menuItem.lCommandID = ID_SEPARATOR; // Command ID
  883. menuItem.fFlags = MF_SEPARATOR; // most important the flag
  884. HRESULT hr = pContextMenuCallback->AddItem (&menuItem);
  885. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSeparator: 0x%x\n", hr);
  886. return hr;
  887. }
  888. HRESULT CCertMgrComponentData::AddSingleMenuItem (
  889. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  890. LONG lInsertionPointID,
  891. int menuTextID,
  892. int menuHintID,
  893. int menuID)
  894. {
  895. _TRACE (1, L"Entering CCertMgrComponentData::AddSingleMenuItem\n");
  896. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  897. ASSERT (pContextMenuCallback);
  898. if ( !pContextMenuCallback )
  899. return E_POINTER;
  900. switch (lInsertionPointID)
  901. {
  902. case CCM_INSERTIONPOINTID_PRIMARY_VIEW:
  903. case CCM_INSERTIONPOINTID_PRIMARY_TASK:
  904. case CCM_INSERTIONPOINTID_PRIMARY_TOP:
  905. case CCM_INSERTIONPOINTID_PRIMARY_NEW:
  906. break;
  907. default:
  908. ASSERT (0);
  909. return E_INVALIDARG;
  910. }
  911. ASSERT (menuTextID > 0);
  912. if ( menuTextID <= 0 )
  913. return E_INVALIDARG;
  914. ASSERT (menuHintID > 0);
  915. if ( menuHintID <= 0 )
  916. return E_INVALIDARG;
  917. ASSERT (menuID > MIN_MENU_ID && menuID < MAX_MENU_ID);
  918. if ( menuID <= MIN_MENU_ID || menuID >= MAX_MENU_ID )
  919. return E_INVALIDARG;
  920. HRESULT hr = S_OK;
  921. CONTEXTMENUITEM menuItem;
  922. CString szMenu;
  923. CString szHint;
  924. // unchanging settings
  925. // security review 2/22/2002 BryanWal ok
  926. ::ZeroMemory (&menuItem, sizeof (menuItem));
  927. menuItem.lInsertionPointID = lInsertionPointID;
  928. menuItem.fFlags = 0;
  929. VERIFY (szMenu.LoadString (menuTextID));
  930. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  931. VERIFY (szHint.LoadString (menuHintID));
  932. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  933. menuItem.lCommandID = menuID;
  934. hr = pContextMenuCallback->AddItem (&menuItem);
  935. ASSERT (SUCCEEDED (hr));
  936. _TRACE (-1, L"Leaving CCertMgrComponentData::AddSingleMenuItem: 0x%x\n", hr);
  937. return hr;
  938. }