Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1974 lines
64 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1997-2001.
  6. //
  7. // File: compdata.cpp
  8. //
  9. // Contents: Implementation of CCertTmplComponentData
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. USE_HANDLE_MACROS ("CERTTMPL (compdata.cpp)")
  14. #include "compdata.h"
  15. #include "dataobj.h"
  16. #include "cookie.h"
  17. #include "uuids.h"
  18. #include "TemplateGeneralPropertyPage.h"
  19. #include "TemplateV1RequestPropertyPage.h"
  20. #include "TemplateV2RequestPropertyPage.h"
  21. #include "TemplateV1SubjectNamePropertyPage.h"
  22. #include "TemplateV2SubjectNamePropertyPage.h"
  23. #include "TemplateV2AuthenticationPropertyPage.h"
  24. #include "TemplateV2SupercedesPropertyPage.h"
  25. #include "TemplateExtensionsPropertyPage.h"
  26. #include "SecurityPropertyPage.h"
  27. #include "TemplatePropertySheet.h"
  28. #include "ViewOIDDlg.h"
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34. #include "dbg.h"
  35. #include "stdcdata.cpp" // CComponentData implementation
  36. extern HINSTANCE g_hInstance;
  37. POLICY_OID_LIST g_policyOIDList;
  38. BOOL CALLBACK AddPageProc(HPROPSHEETPAGE hPage, LPARAM pCall);
  39. extern bool g_bSchemaIsW2K;
  40. //
  41. // CCertTmplComponentData
  42. //
  43. CCertTmplComponentData::CCertTmplComponentData ()
  44. : m_RootCookie (CERTTMPL_SNAPIN),
  45. m_hRootScopeItem (0),
  46. m_pResultData (0),
  47. m_bIsUserAdministrator (FALSE),
  48. m_pHeader (0),
  49. m_bMultipleObjectsSelected (false),
  50. m_dwNumCertTemplates (0),
  51. m_pComponentConsole (0),
  52. m_fUseCache (false),
  53. m_bSchemaChecked (false)
  54. {
  55. _TRACE (1, L"Entering CCertTmplComponentData::CCertTmplComponentData\n");
  56. // Get name of logged-in user
  57. DWORD dwSize = 0;
  58. ::GetUserName (0, &dwSize);
  59. BOOL bRet = ::GetUserName (m_szLoggedInUser.GetBufferSetLength (dwSize), &dwSize);
  60. _ASSERT (bRet);
  61. m_szLoggedInUser.ReleaseBuffer ();
  62. // Get name of this computer
  63. dwSize = MAX_COMPUTERNAME_LENGTH + 1 ;
  64. bRet = ::GetComputerName (m_szThisComputer.GetBufferSetLength (MAX_COMPUTERNAME_LENGTH + 1 ), &dwSize);
  65. _ASSERT (bRet);
  66. m_szThisComputer.ReleaseBuffer ();
  67. // Find out if logged-in users is an Administrator
  68. HRESULT hr = IsUserAdministrator (m_bIsUserAdministrator);
  69. _ASSERT (SUCCEEDED (hr));
  70. // default help file name.
  71. SetHtmlHelpFileName (CERTTMPL_HTML_HELP_FILE);
  72. // Find out if we're joined to a domain.
  73. PDSROLE_PRIMARY_DOMAIN_INFO_BASIC pInfo = 0;
  74. DWORD dwErr = ::DsRoleGetPrimaryDomainInformation (
  75. 0,
  76. DsRolePrimaryDomainInfoBasic,
  77. (PBYTE*) &pInfo);
  78. if ( ERROR_SUCCESS == dwErr )
  79. {
  80. if ( pInfo->Flags & DSROLE_PRIMARY_DS_RUNNING ||
  81. pInfo->Flags & DSROLE_PRIMARY_DOMAIN_GUID_PRESENT )
  82. {
  83. m_szThisDomainDns = pInfo->DomainNameDns;
  84. m_RootCookie.SetManagedDomainDNSName (m_szThisDomainDns);
  85. m_szThisDomainFlat = pInfo->DomainNameFlat;
  86. }
  87. }
  88. else
  89. {
  90. _TRACE (0, L"DsRoleGetPrimaryDomainInformation () failed: 0x%x\n", dwErr);
  91. }
  92. NetApiBufferFree (pInfo);
  93. _TRACE (-1, L"Leaving CCertTmplComponentData::CCertTmplComponentData\n");
  94. }
  95. CCertTmplComponentData::~CCertTmplComponentData ()
  96. {
  97. _TRACE (1, L"Entering CCertTmplComponentData::~CCertTmplComponentData\n");
  98. CCookie& rootCookie = QueryBaseRootCookie ();
  99. while ( !rootCookie.m_listResultCookieBlocks.IsEmpty() )
  100. {
  101. (rootCookie.m_listResultCookieBlocks.RemoveHead())->Release();
  102. }
  103. if ( m_pResultData )
  104. {
  105. m_pResultData->Release ();
  106. m_pResultData = 0;
  107. }
  108. if ( m_pComponentConsole )
  109. {
  110. SAFE_RELEASE (m_pComponentConsole);
  111. m_pComponentConsole = 0;
  112. }
  113. _TRACE (-1, L"Leaving CCertTmplComponentData::~CCertTmplComponentData\n");
  114. }
  115. DEFINE_FORWARDS_MACHINE_NAME ( CCertTmplComponentData, (&m_RootCookie) )
  116. CCookie& CCertTmplComponentData::QueryBaseRootCookie ()
  117. {
  118. return (CCookie&) m_RootCookie;
  119. }
  120. STDMETHODIMP CCertTmplComponentData::CreateComponent (LPCOMPONENT* ppComponent)
  121. {
  122. _TRACE (1, L"Entering CCertTmplComponentData::CreateComponent\n");
  123. _ASSERT (ppComponent);
  124. CComObject<CCertTmplComponent>* pObject = 0;
  125. CComObject<CCertTmplComponent>::CreateInstance (&pObject);
  126. _ASSERT (pObject);
  127. pObject->SetComponentDataPtr ( (CCertTmplComponentData*) this);
  128. _TRACE (-1, L"Leaving CCertTmplComponentData::CreateComponent\n");
  129. return pObject->QueryInterface (IID_PPV_ARG (IComponent, ppComponent));
  130. }
  131. HRESULT CCertTmplComponentData::LoadIcons (LPIMAGELIST pImageList, BOOL /*fLoadLargeIcons*/)
  132. {
  133. _TRACE (1, L"Entering CCertTmplComponentData::LoadIcons\n");
  134. // Structure to map a Resource ID to an index of icon
  135. struct RESID2IICON
  136. {
  137. UINT uIconId; // Icon resource ID
  138. int iIcon; // Index of the icon in the image list
  139. };
  140. const static RESID2IICON rgzLoadIconList[] =
  141. {
  142. // Misc icons
  143. { IDI_CERT_TEMPLATEV1, iIconCertTemplateV1 },
  144. { IDI_CERT_TEMPLATEV2, iIconCertTemplateV2 },
  145. { 0, 0} // Must be last
  146. };
  147. for (int i = 0; rgzLoadIconList[i].uIconId != 0; i++)
  148. {
  149. HICON hIcon = ::LoadIcon (AfxGetInstanceHandle (),
  150. MAKEINTRESOURCE (rgzLoadIconList[i].uIconId));
  151. _ASSERT (hIcon && "Icon ID not found in resources");
  152. HRESULT hr = pImageList->ImageListSetIcon ( (PLONG_PTR) hIcon,
  153. rgzLoadIconList[i].iIcon);
  154. _ASSERT (SUCCEEDED (hr) && "Unable to add icon to ImageList");
  155. }
  156. _TRACE (-1, L"Leaving CCertTmplComponentData::LoadIcons\n");
  157. return S_OK;
  158. }
  159. HRESULT CCertTmplComponentData::OnNotifyExpand (LPDATAOBJECT pDataObject, BOOL bExpanding, HSCOPEITEM hParent)
  160. {
  161. _TRACE (1, L"Entering CCertTmplComponentData::OnNotifyExpand\n");
  162. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  163. HRESULT hr = S_OK;
  164. CWaitCursor waitCursor;
  165. _ASSERT (pDataObject && hParent && m_pConsoleNameSpace);
  166. if ( bExpanding )
  167. {
  168. // Need to check schema first before getting OIDs (sets g_bSchemaIsW2K)
  169. if ( !m_bSchemaChecked )
  170. {
  171. InstallWindows2002CertTemplates ();
  172. m_bSchemaChecked = true;
  173. }
  174. if ( 0 == g_policyOIDList.GetCount () )
  175. {
  176. hr = GetEnterpriseOIDs ();
  177. if ( FAILED (hr) )
  178. {
  179. if ( HRESULT_FROM_WIN32 (ERROR_DS_NO_SUCH_OBJECT) == hr )
  180. g_bSchemaIsW2K = true;
  181. if ( !g_bSchemaIsW2K )
  182. {
  183. CString caption;
  184. CString text;
  185. VERIFY (caption.LoadString (IDS_CERTTMPL));
  186. text.FormatMessage (IDS_CANNOT_LOAD_OID_LIST, GetSystemMessage (hr));
  187. int iRetVal = 0;
  188. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  189. MB_ICONWARNING | MB_OK, &iRetVal)));
  190. }
  191. else
  192. hr = S_OK;
  193. }
  194. }
  195. GUID guidObjectType;
  196. hr = ExtractObjectTypeGUID (pDataObject, &guidObjectType);
  197. _ASSERT (SUCCEEDED (hr));
  198. // Beyond this point we are not dealing with extension node types.
  199. {
  200. CCertTmplCookie* pParentCookie = ConvertCookie (pDataObject);
  201. if ( pParentCookie )
  202. {
  203. hr = ExpandScopeNodes (pParentCookie, hParent, guidObjectType, pDataObject);
  204. }
  205. else
  206. hr = E_UNEXPECTED;
  207. }
  208. }
  209. else
  210. hr = S_OK;
  211. _TRACE (-1, L"Leaving CCertTmplComponentData::OnNotifyExpand: 0x%x\n", hr);
  212. return hr;
  213. }
  214. HRESULT CCertTmplComponentData::OnNotifyRelease (LPDATAOBJECT /*pDataObject*/, HSCOPEITEM hItem)
  215. {
  216. _TRACE (1, L"Entering CCertTmplComponentData::OnNotifyRelease\n");
  217. // _ASSERT ( IsExtensionSnapin () );
  218. // This might also happen if I expand a node and then remove
  219. // the snapin via Snapin Manager
  220. HRESULT hr = DeleteChildren (hItem);
  221. _TRACE (-1, L"Leaving CCertTmplComponentData::OnNotifyRelease: 0x%x\n", hr);
  222. return hr;
  223. }
  224. // global space to store the string handed back to GetDisplayInfo ()
  225. // CODEWORK should use "bstr" for ANSI-ization
  226. CString g_strResultColumnText;
  227. BSTR CCertTmplComponentData::QueryResultColumnText (CCookie& basecookie, int /*nCol*/)
  228. {
  229. BSTR strResult = L"";
  230. CCertTmplCookie& cookie = (CCertTmplCookie&) basecookie;
  231. #ifndef UNICODE
  232. #error not ANSI-enabled
  233. #endif
  234. switch ( cookie.m_objecttype )
  235. {
  236. case CERTTMPL_SNAPIN:
  237. break;
  238. case CERTTMPL_CERT_TEMPLATE:
  239. _ASSERT (0);
  240. break;
  241. default:
  242. break;
  243. }
  244. return strResult;
  245. }
  246. int CCertTmplComponentData::QueryImage (CCookie& basecookie, BOOL /*fOpenImage*/)
  247. {
  248. int nIcon = 0;
  249. CCertTmplCookie& cookie = (CCertTmplCookie&)basecookie;
  250. switch ( cookie.m_objecttype )
  251. {
  252. case CERTTMPL_SNAPIN:
  253. nIcon = iIconCertTemplateV2;
  254. break;
  255. case CERTTMPL_CERT_TEMPLATE:
  256. {
  257. CCertTemplate& rCertTemplate = (CCertTemplate&) cookie;
  258. if ( 1 == rCertTemplate.GetType () )
  259. nIcon = iIconCertTemplateV1;
  260. else
  261. nIcon = iIconCertTemplateV2;
  262. }
  263. break;
  264. default:
  265. _TRACE (0, L"CCertTmplComponentData::QueryImage bad parent type\n");
  266. break;
  267. }
  268. return nIcon;
  269. }
  270. ///////////////////////////////////////////////////////////////////////////////
  271. /// IExtendPropertySheet
  272. STDMETHODIMP CCertTmplComponentData::QueryPagesFor (LPDATAOBJECT pDataObject)
  273. {
  274. _TRACE (1, L"Entering CCertTmplComponentData::QueryPagesFor\n");
  275. HRESULT hr = S_OK;
  276. _ASSERT (pDataObject);
  277. if ( pDataObject )
  278. {
  279. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  280. hr = ::ExtractData (pDataObject,
  281. CCertTemplatesDataObject::m_CFDataObjectType,
  282. &dataobjecttype, sizeof (dataobjecttype));
  283. if ( SUCCEEDED (hr) )
  284. {
  285. switch (dataobjecttype)
  286. {
  287. case CCT_SNAPIN_MANAGER:
  288. hr = S_FALSE;
  289. break;
  290. case CCT_RESULT:
  291. {
  292. hr = S_FALSE;
  293. CCertTmplCookie* pParentCookie = ConvertCookie (pDataObject);
  294. if ( pParentCookie )
  295. {
  296. switch (pParentCookie->m_objecttype)
  297. {
  298. case CERTTMPL_CERT_TEMPLATE:
  299. hr = S_OK;
  300. break;
  301. default:
  302. break;
  303. }
  304. }
  305. }
  306. break;
  307. case CCT_SCOPE:
  308. hr = S_FALSE;
  309. break;
  310. default:
  311. hr = S_FALSE;
  312. break;
  313. }
  314. }
  315. }
  316. else
  317. hr = E_POINTER;
  318. _TRACE (-1, L"Leaving CCertTmplComponentData::QueryPagesFor: 0x%x\n", hr);
  319. return hr;
  320. }
  321. STDMETHODIMP CCertTmplComponentData::CreatePropertyPages (
  322. LPPROPERTYSHEETCALLBACK pCallback,
  323. LONG_PTR lNotifyHandle, // This handle must be saved in the property page object to notify the parent when modified
  324. LPDATAOBJECT pDataObject)
  325. {
  326. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  327. _TRACE (1, L"Entering CCertTmplComponentData::CreatePropertyPages\n");
  328. HRESULT hr = S_OK;
  329. _ASSERT (pCallback && pDataObject);
  330. if ( pCallback && pDataObject )
  331. {
  332. DATA_OBJECT_TYPES dataobjecttype = CCT_SCOPE;
  333. hr = ::ExtractData (pDataObject,
  334. CCertTemplatesDataObject::m_CFDataObjectType,
  335. &dataobjecttype, sizeof (dataobjecttype));
  336. switch (dataobjecttype)
  337. {
  338. case CCT_SNAPIN_MANAGER:
  339. break;
  340. case CCT_RESULT:
  341. {
  342. CCertTmplCookie* pParentCookie = ConvertCookie (pDataObject);
  343. if ( pParentCookie )
  344. {
  345. switch (pParentCookie->m_objecttype)
  346. {
  347. case CERTTMPL_CERT_TEMPLATE:
  348. {
  349. CCertTemplate* pCertTemplate =
  350. dynamic_cast <CCertTemplate*> (pParentCookie);
  351. _ASSERT (pCertTemplate);
  352. if ( pCertTemplate )
  353. {
  354. hr = AddCertTemplatePropPages (pCertTemplate,
  355. pCallback, lNotifyHandle);
  356. }
  357. else
  358. hr = E_FAIL;
  359. }
  360. break;
  361. default:
  362. _ASSERT (0);
  363. break;
  364. }
  365. }
  366. else
  367. hr = E_UNEXPECTED;
  368. }
  369. break;
  370. case CCT_SCOPE:
  371. {
  372. CCertTmplCookie* pParentCookie = ConvertCookie (pDataObject);
  373. if ( pParentCookie )
  374. {
  375. }
  376. else
  377. hr = E_UNEXPECTED;
  378. }
  379. break;
  380. default:
  381. break;
  382. }
  383. }
  384. else
  385. hr = E_POINTER;
  386. _TRACE (-1, L"Leaving CCertTmplComponentData::CreatePropertyPages: 0x%x\n", hr);
  387. return hr;
  388. }
  389. BOOL IsMMCMultiSelectDataObject(IDataObject* pDataObject)
  390. {
  391. if (pDataObject == NULL)
  392. return FALSE;
  393. static UINT s_cf = 0;
  394. if (s_cf == 0)
  395. {
  396. USES_CONVERSION;
  397. s_cf = RegisterClipboardFormat(W2T(CCF_MMC_MULTISELECT_DATAOBJECT));
  398. }
  399. FORMATETC fmt = {(CLIPFORMAT)s_cf, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  400. return (pDataObject->QueryGetData(&fmt) == S_OK);
  401. }
  402. ///////////////////////////////////////////////////////////////////////////////
  403. // IExtendContextMenu implementation
  404. //
  405. STDMETHODIMP CCertTmplComponentData::AddMenuItems (LPDATAOBJECT pDataObject,
  406. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  407. long *pInsertionAllowed)
  408. {
  409. _TRACE (1, L"Entering CCertTmplComponentData::AddMenuItems\n");
  410. HRESULT hr = S_OK;
  411. CCertTmplCookie* pCookie = 0;
  412. LPDATAOBJECT pMSDO = ExtractMultiSelect (pDataObject);
  413. m_bMultipleObjectsSelected = false;
  414. if ( pMSDO )
  415. {
  416. m_bMultipleObjectsSelected = true;
  417. CCertTemplatesDataObject* pDO = dynamic_cast <CCertTemplatesDataObject*>(pMSDO);
  418. _ASSERT (pDO);
  419. if ( pDO )
  420. {
  421. // Get first cookie - all items should be the same?
  422. // Is this a valid assumption?
  423. // TODO: Verify
  424. pDO->Reset();
  425. if ( pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) == S_FALSE )
  426. return S_FALSE;
  427. }
  428. else
  429. return E_UNEXPECTED;
  430. }
  431. else
  432. pCookie = ConvertCookie (pDataObject);
  433. _ASSERT (pCookie);
  434. if ( !pCookie )
  435. return E_UNEXPECTED;
  436. CertTmplObjectType objType = pCookie->m_objecttype;
  437. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_TOP )
  438. {
  439. switch (objType)
  440. {
  441. case CERTTMPL_CERT_TEMPLATE:
  442. if ( !m_bMultipleObjectsSelected )
  443. {
  444. CCertTemplate* pCertTemplate = dynamic_cast <CCertTemplate*> (pCookie);
  445. _ASSERT (pCertTemplate);
  446. if ( pCertTemplate )
  447. {
  448. if ( !g_bSchemaIsW2K )
  449. {
  450. hr = AddCloneTemplateMenuItem (pContextMenuCallback,
  451. CCM_INSERTIONPOINTID_PRIMARY_TOP);
  452. if ( SUCCEEDED (hr) )
  453. {
  454. hr = AddReEnrollAllCertsMenuItem (pContextMenuCallback,
  455. CCM_INSERTIONPOINTID_PRIMARY_TOP);
  456. }
  457. }
  458. }
  459. else
  460. hr = E_FAIL;
  461. }
  462. break;
  463. case CERTTMPL_SNAPIN:
  464. _ASSERT (!m_bMultipleObjectsSelected);
  465. hr = AddViewOIDsMenuItem (pContextMenuCallback,
  466. CCM_INSERTIONPOINTID_PRIMARY_TOP);
  467. break;
  468. default:
  469. break;
  470. }
  471. }
  472. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_NEW )
  473. {
  474. }
  475. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_TASK )
  476. {
  477. switch (objType)
  478. {
  479. case CERTTMPL_CERT_TEMPLATE:
  480. if ( !m_bMultipleObjectsSelected )
  481. {
  482. CCertTemplate* pCertTemplate = dynamic_cast <CCertTemplate*> (pCookie);
  483. _ASSERT (pCertTemplate);
  484. if ( pCertTemplate )
  485. {
  486. if ( !g_bSchemaIsW2K )
  487. {
  488. hr = AddCloneTemplateMenuItem (pContextMenuCallback,
  489. CCM_INSERTIONPOINTID_PRIMARY_TASK);
  490. if ( SUCCEEDED (hr) )
  491. {
  492. hr = AddReEnrollAllCertsMenuItem (pContextMenuCallback,
  493. CCM_INSERTIONPOINTID_PRIMARY_TASK);
  494. }
  495. }
  496. }
  497. else
  498. hr = E_FAIL;
  499. }
  500. break;
  501. case CERTTMPL_SNAPIN:
  502. _ASSERT (!m_bMultipleObjectsSelected);
  503. hr = AddViewOIDsMenuItem (pContextMenuCallback,
  504. CCM_INSERTIONPOINTID_PRIMARY_TASK);
  505. break;
  506. }
  507. }
  508. if ( *pInsertionAllowed & CCM_INSERTIONALLOWED_VIEW )
  509. {
  510. switch (objType)
  511. {
  512. case CERTTMPL_SNAPIN:
  513. _ASSERT (!m_bMultipleObjectsSelected);
  514. break;
  515. case CERTTMPL_CERT_TEMPLATE:
  516. _ASSERT (0);
  517. break;
  518. default:
  519. break;
  520. }
  521. }
  522. _TRACE (-1, L"Leaving CCertTmplComponentData::AddMenuItems: 0x%x\n", hr);
  523. return hr;
  524. }
  525. STDMETHODIMP CCertTmplComponentData::Command (long nCommandID, LPDATAOBJECT pDataObject)
  526. {
  527. HRESULT hr = S_OK;
  528. switch (nCommandID)
  529. {
  530. case IDM_CLONE_TEMPLATE:
  531. hr = OnCloneTemplate (pDataObject);
  532. break;
  533. case IDM_REENROLL_ALL_CERTS:
  534. hr = OnReEnrollAllCerts (pDataObject);
  535. break;
  536. case IDM_VIEW_OIDS:
  537. OnViewOIDs ();
  538. break;
  539. case -1: // Received on forward/back buttons from toolbar
  540. break;
  541. default:
  542. _ASSERT (0);
  543. break;
  544. }
  545. return hr;
  546. }
  547. HRESULT CCertTmplComponentData::RefreshScopePane (LPDATAOBJECT pDataObject)
  548. {
  549. _TRACE (1, L"Entering CCertTmplComponentData::RefreshScopePane\n");
  550. HRESULT hr = S_OK;
  551. CCertTmplCookie* pCookie = 0;
  552. if ( pDataObject )
  553. pCookie = ConvertCookie (pDataObject);
  554. if ( !pDataObject || pCookie )
  555. {
  556. hr = DeleteScopeItems ();
  557. _ASSERT (SUCCEEDED (hr));
  558. GUID guid;
  559. hr = ExpandScopeNodes (&m_RootCookie, m_hRootScopeItem, guid, pDataObject);
  560. }
  561. _TRACE (-1, L"Leaving CCertTmplComponentData::RefreshScopePane: 0x%x\n", hr);
  562. return hr;
  563. }
  564. HRESULT CCertTmplComponentData::ExpandScopeNodes (
  565. CCertTmplCookie* pParentCookie,
  566. HSCOPEITEM hParent,
  567. const GUID& /*guidObjectType*/,
  568. LPDATAOBJECT /*pDataObject*/)
  569. {
  570. _TRACE (1, L"Entering CCertTmplComponentData::ExpandScopeNodes\n");
  571. _ASSERT (hParent);
  572. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  573. CWaitCursor waitCursor;
  574. HRESULT hr = S_OK;
  575. if ( pParentCookie )
  576. {
  577. CString objectName;
  578. switch ( pParentCookie->m_objecttype )
  579. {
  580. // These node types have no children yet
  581. case CERTTMPL_SNAPIN:
  582. // We don't expect the handle of the root scope item to change, ever!
  583. _ASSERT ( m_hRootScopeItem ? (m_hRootScopeItem == hParent) : 1);
  584. if ( !m_hRootScopeItem )
  585. m_hRootScopeItem = hParent;
  586. break;
  587. case CERTTMPL_CERT_TEMPLATE:
  588. _ASSERT (0);
  589. break;
  590. // This node type has no children
  591. default:
  592. _TRACE (0, L"CCertTmplComponentData::EnumerateScopeChildren bad parent type\n");
  593. hr = S_OK;
  594. break;
  595. }
  596. }
  597. else
  598. {
  599. // If parentCookie not passed in, then this is an extension snap-in
  600. }
  601. _TRACE (-1, L"Leaving CCertTmplComponentData::ExpandScopeNodes: 0x%x\n", hr);
  602. return hr;
  603. }
  604. HRESULT CCertTmplComponentData::DeleteScopeItems ()
  605. {
  606. _TRACE (1, L"Entering CCertTmplComponentData::DeleteScopeItems\n");
  607. HRESULT hr = S_OK;
  608. hr = DeleteChildren (m_hRootScopeItem);
  609. _TRACE (-1, L"Leaving CCertTmplComponentData::DeleteScopeItems: 0x%x\n", hr);
  610. return hr;
  611. }
  612. HRESULT CCertTmplComponentData::DeleteChildren (HSCOPEITEM hParent)
  613. {
  614. _TRACE (1, L"Entering CCertTmplComponentData::DeleteChildren\n");
  615. HRESULT hr = S_OK;
  616. if ( hParent )
  617. {
  618. HSCOPEITEM hChild = 0;
  619. HSCOPEITEM hNextChild = 0;
  620. MMC_COOKIE lCookie = 0;
  621. // Optimization: If we're deleting everything below the root, free all
  622. // the result items here so we don't have to go looking for them later by
  623. // store
  624. if ( hParent == m_hRootScopeItem )
  625. {
  626. LPRESULTDATA pResultData = 0;
  627. hr = GetResultData (&pResultData);
  628. if ( SUCCEEDED (hr) )
  629. {
  630. hr = pResultData->DeleteAllRsltItems ();
  631. if ( SUCCEEDED (hr) || E_UNEXPECTED == hr ) // returns E_UNEXPECTED if console shutting down
  632. {
  633. RemoveResultCookies (pResultData);
  634. }
  635. pResultData->Release ();
  636. }
  637. }
  638. hr = m_pConsoleNameSpace->GetChildItem (hParent, &hChild, &lCookie);
  639. _ASSERT (SUCCEEDED (hr) || E_FAIL == hr); // appears to return E_FAIL when there are no children
  640. while ( SUCCEEDED (hr) && hChild )
  641. {
  642. hr = m_pConsoleNameSpace->GetNextItem (hChild, &hNextChild, &lCookie);
  643. _ASSERT (SUCCEEDED (hr));
  644. hr = DeleteChildren (hChild);
  645. _ASSERT (SUCCEEDED (hr));
  646. if ( SUCCEEDED (hr) )
  647. {
  648. m_pConsoleNameSpace->DeleteItem (hChild, TRUE);
  649. }
  650. hChild = hNextChild;
  651. }
  652. }
  653. _TRACE (-1, L"Leaving CCertTmplComponentData::DeleteChildren: 0x%x\n", hr);
  654. return hr;
  655. }
  656. CertTmplObjectType CCertTmplComponentData::GetObjectType (LPDATAOBJECT pDataObject)
  657. {
  658. _ASSERT (pDataObject);
  659. CCertTmplCookie* pCookie = ConvertCookie (pDataObject);
  660. if ( ((CCertTmplCookie*) MMC_MULTI_SELECT_COOKIE) == pCookie )
  661. return CERTTMPL_MULTISEL;
  662. else if ( pCookie )
  663. return pCookie->m_objecttype;
  664. return CERTTMPL_INVALID;
  665. }
  666. HRESULT CCertTmplComponentData::IsUserAdministrator (BOOL & bIsAdministrator)
  667. {
  668. HRESULT hr = S_OK;
  669. DWORD dwErr = 0;
  670. bIsAdministrator = FALSE;
  671. if ( IsWindowsNT () )
  672. {
  673. PSID psidAdministrators;
  674. SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
  675. BOOL bResult = AllocateAndInitializeSid (&siaNtAuthority, 2,
  676. SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
  677. 0, 0, 0, 0, 0, 0, &psidAdministrators);
  678. _ASSERT (bResult);
  679. if ( bResult )
  680. {
  681. bResult = CheckTokenMembership (0, psidAdministrators,
  682. &bIsAdministrator);
  683. _ASSERT (bResult);
  684. if ( !bResult )
  685. {
  686. dwErr = GetLastError ();
  687. DisplaySystemError (dwErr);
  688. hr = HRESULT_FROM_WIN32 (dwErr);
  689. }
  690. FreeSid (psidAdministrators);
  691. }
  692. else
  693. {
  694. dwErr = GetLastError ();
  695. DisplaySystemError (dwErr);
  696. hr = HRESULT_FROM_WIN32 (dwErr);
  697. }
  698. }
  699. return hr;
  700. }
  701. void CCertTmplComponentData::DisplaySystemError (DWORD dwErr)
  702. {
  703. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  704. LPVOID lpMsgBuf;
  705. FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  706. NULL,
  707. dwErr,
  708. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  709. (PWSTR) &lpMsgBuf, 0, NULL );
  710. // Display the string.
  711. CString caption;
  712. VERIFY (caption.LoadString (IDS_CERTTMPL));
  713. int iRetVal = 0;
  714. if ( m_pConsole )
  715. {
  716. HRESULT hr = m_pConsole->MessageBox ( (PWSTR) lpMsgBuf, caption,
  717. MB_ICONWARNING | MB_OK, &iRetVal);
  718. _ASSERT (SUCCEEDED (hr));
  719. }
  720. else
  721. {
  722. CThemeContextActivator activator;
  723. ::MessageBox (NULL, (PWSTR) lpMsgBuf, caption, MB_ICONWARNING | MB_OK);
  724. }
  725. // Free the buffer.
  726. LocalFree (lpMsgBuf);
  727. }
  728. HRESULT CCertTmplComponentData::AddSeparator (LPCONTEXTMENUCALLBACK pContextMenuCallback)
  729. {
  730. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  731. _ASSERT (pContextMenuCallback);
  732. CONTEXTMENUITEM menuItem;
  733. ::ZeroMemory (&menuItem, sizeof (menuItem));
  734. menuItem.lInsertionPointID = CCM_INSERTIONPOINTID_PRIMARY_TASK;
  735. menuItem.fSpecialFlags = 0;
  736. menuItem.strName = _T ("Separator"); // Dummy name
  737. menuItem.strStatusBarText = _T ("Separator");// Dummy status text
  738. menuItem.lCommandID = ID_SEPARATOR; // Command ID
  739. menuItem.fFlags = MF_SEPARATOR; // most important the flag
  740. HRESULT hr = pContextMenuCallback->AddItem (&menuItem);
  741. // _ASSERT (SUCCEEDED (hr));
  742. return hr;
  743. }
  744. LPCONSOLENAMESPACE CCertTmplComponentData::GetConsoleNameSpace () const
  745. {
  746. return m_pConsoleNameSpace;
  747. }
  748. CCertTmplCookie* CCertTmplComponentData::ConvertCookie (LPDATAOBJECT pDataObject)
  749. {
  750. CCertTmplCookie* pParentCookie = 0;
  751. CCookie* pBaseParentCookie = 0;
  752. HRESULT hr = ::ExtractData (pDataObject,
  753. CCertTemplatesDataObject::m_CFRawCookie,
  754. &pBaseParentCookie,
  755. sizeof (pBaseParentCookie) );
  756. if ( SUCCEEDED (hr) )
  757. {
  758. pParentCookie = ActiveCookie (pBaseParentCookie);
  759. _ASSERT (pParentCookie);
  760. }
  761. return pParentCookie;
  762. }
  763. HRESULT CCertTmplComponentData::AddScopeNode(CCertTmplCookie * pNewCookie, HSCOPEITEM hParent)
  764. {
  765. _TRACE (1, L"Entering CCertTmplComponentData::AddScopeNode\n");
  766. _ASSERT (pNewCookie);
  767. HRESULT hr = S_OK;
  768. if ( pNewCookie )
  769. {
  770. SCOPEDATAITEM tSDItem;
  771. ::ZeroMemory (&tSDItem,sizeof (tSDItem));
  772. tSDItem.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE |
  773. SDI_STATE | SDI_PARAM | SDI_PARENT | SDI_CHILDREN;
  774. tSDItem.displayname = MMC_CALLBACK;
  775. tSDItem.relativeID = hParent;
  776. tSDItem.nState = 0;
  777. tSDItem.cChildren = 0;
  778. if ( pNewCookie != &m_RootCookie )
  779. m_RootCookie.m_listScopeCookieBlocks.AddHead ( (CBaseCookieBlock*) pNewCookie);
  780. tSDItem.lParam = reinterpret_cast<LPARAM> ( (CCookie*) pNewCookie);
  781. tSDItem.nImage = QueryImage (*pNewCookie, FALSE);
  782. tSDItem.nOpenImage = QueryImage (*pNewCookie, FALSE);
  783. hr = m_pConsoleNameSpace->InsertItem (&tSDItem);
  784. if ( SUCCEEDED (hr) )
  785. pNewCookie->m_hScopeItem = tSDItem.ID;
  786. }
  787. else
  788. hr = E_POINTER;
  789. _TRACE (-1, L"Leaving CCertTmplComponentData::AddScopeNode: 0x%x\n", hr);
  790. return hr;
  791. }
  792. HRESULT CCertTmplComponentData::ReleaseResultCookie (
  793. CBaseCookieBlock * pResultCookie,
  794. CCookie& /*rootCookie*/,
  795. POSITION /*pos2*/)
  796. {
  797. _TRACE (1, L"Entering CCertTmplComponentData::ReleaseResultCookie\n");
  798. CCertTmplCookie* pCookie = dynamic_cast <CCertTmplCookie*> (pResultCookie);
  799. _ASSERT (pCookie);
  800. if ( pCookie )
  801. {
  802. switch (pCookie->m_objecttype)
  803. {
  804. case CERTTMPL_CERT_TEMPLATE:
  805. _ASSERT (0);
  806. break;
  807. default:
  808. _ASSERT (0);
  809. break;
  810. }
  811. }
  812. _TRACE (-1, L"Leaving CCertTmplComponentData::ReleaseResultCookie\n");
  813. return S_OK;
  814. }
  815. void CCertTmplComponentData::SetResultData(LPRESULTDATA pResultData)
  816. {
  817. _ASSERT (pResultData);
  818. if ( pResultData && !m_pResultData )
  819. {
  820. m_pResultData = pResultData;
  821. m_pResultData->AddRef ();
  822. }
  823. }
  824. HRESULT CCertTmplComponentData::GetResultData(LPRESULTDATA* ppResultData)
  825. {
  826. HRESULT hr = S_OK;
  827. if ( !ppResultData )
  828. hr = E_POINTER;
  829. else if ( !m_pResultData )
  830. {
  831. if ( m_pConsole )
  832. {
  833. hr = m_pConsole->QueryInterface(IID_PPV_ARG (IResultData, &m_pResultData));
  834. _ASSERT (SUCCEEDED (hr));
  835. }
  836. else
  837. hr = E_FAIL;
  838. }
  839. if ( SUCCEEDED (hr) && m_pResultData )
  840. {
  841. *ppResultData = m_pResultData;
  842. m_pResultData->AddRef ();
  843. }
  844. return hr;
  845. }
  846. void CCertTmplComponentData::DisplayAccessDenied ()
  847. {
  848. DWORD dwErr = GetLastError ();
  849. _ASSERT (E_ACCESSDENIED == dwErr);
  850. if ( E_ACCESSDENIED == dwErr )
  851. {
  852. LPVOID lpMsgBuf;
  853. FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  854. NULL,
  855. GetLastError (),
  856. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  857. (PWSTR) &lpMsgBuf, 0, NULL );
  858. // Display the string.
  859. CString caption;
  860. VERIFY (caption.LoadString (IDS_CERTTMPL));
  861. int iRetVal = 0;
  862. VERIFY (SUCCEEDED (m_pConsole->MessageBox ( (PWSTR) lpMsgBuf, caption,
  863. MB_ICONWARNING | MB_OK, &iRetVal)));
  864. // Free the buffer.
  865. LocalFree (lpMsgBuf);
  866. }
  867. }
  868. CString CCertTmplComponentData::GetThisComputer() const
  869. {
  870. return m_szThisComputer;
  871. }
  872. HRESULT CCertTmplComponentData::OnPropertyChange (LPARAM param)
  873. {
  874. _TRACE (1, L"Entering CCertTmplComponentData::OnPropertyChange\n");
  875. _ASSERT (param);
  876. HRESULT hr = S_OK;
  877. if ( param )
  878. {
  879. CCertTmplCookie* pCookie = reinterpret_cast<CCertTmplCookie*> (param);
  880. if ( pCookie )
  881. {
  882. switch (pCookie->m_objecttype)
  883. {
  884. case CERTTMPL_CERT_TEMPLATE:
  885. {
  886. HRESULTITEM itemID = 0;
  887. hr = pCookie->m_resultDataID->FindItemByLParam ((LPARAM) pCookie, &itemID);
  888. _ASSERT (SUCCEEDED (hr));
  889. if ( SUCCEEDED (hr) )
  890. {
  891. hr = m_pResultData->UpdateItem (itemID);
  892. _ASSERT (SUCCEEDED (hr));
  893. }
  894. }
  895. break;
  896. default:
  897. break;
  898. }
  899. }
  900. }
  901. else
  902. hr = E_FAIL;
  903. _TRACE (-1, L"Leaving CCertTmplComponentData::OnPropertyChange: 0x%x\n", hr);
  904. return hr;
  905. }
  906. ///////////////////////////////////////////////////////////////////////////////
  907. //
  908. // CCertTmplComponentData::RemoveResultCookies
  909. //
  910. // Remove and delete all the result cookies corresponding to the LPRESULTDATA
  911. // object passed in. Thus all cookies added to pResultData are released and
  912. // removed from the master list.
  913. //
  914. ///////////////////////////////////////////////////////////////////////////////
  915. void CCertTmplComponentData::RemoveResultCookies(LPRESULTDATA pResultData)
  916. {
  917. _TRACE (1, L"Entering CCertTmplComponentData::RemoveResultCookies\n");
  918. CCertTmplCookie* pCookie = 0;
  919. CCookie& rootCookie = QueryBaseRootCookie ();
  920. POSITION curPos = 0;
  921. for (POSITION nextPos = rootCookie.m_listResultCookieBlocks.GetHeadPosition (); nextPos; )
  922. {
  923. curPos = nextPos;
  924. pCookie = dynamic_cast <CCertTmplCookie*> (rootCookie.m_listResultCookieBlocks.GetNext (nextPos));
  925. _ASSERT (pCookie);
  926. if ( pCookie )
  927. {
  928. if ( pCookie->m_resultDataID == pResultData )
  929. {
  930. pCookie->Release ();
  931. rootCookie.m_listResultCookieBlocks.RemoveAt (curPos);
  932. }
  933. }
  934. }
  935. _TRACE (-1, L"Leaving CCertTmplComponentData::RemoveResultCookies\n");
  936. }
  937. HRESULT CCertTmplComponentData::AddVersion1CertTemplatePropPages (CCertTemplate* pCertTemplate, LPPROPERTYSHEETCALLBACK pCallback)
  938. {
  939. _TRACE (1, L"Entering CCertTmplComponentData::AddVersion1CertTemplatePropPages\n");
  940. HRESULT hr = S_OK;
  941. _ASSERT (pCertTemplate && pCallback);
  942. if ( pCertTemplate && pCallback )
  943. {
  944. _ASSERT (1 == pCertTemplate->GetType ());
  945. // Add General page
  946. CTemplateGeneralPropertyPage * pGeneralPage = new CTemplateGeneralPropertyPage (
  947. *pCertTemplate, this);
  948. if ( pGeneralPage )
  949. {
  950. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pGeneralPage->m_psp);
  951. _ASSERT (hPage);
  952. hr = pCallback->AddPage (hPage);
  953. _ASSERT (SUCCEEDED (hr));
  954. }
  955. else
  956. {
  957. hr = E_OUTOFMEMORY;
  958. }
  959. // Add Request page only if subject is not a CA
  960. if ( SUCCEEDED (hr) && !pCertTemplate->SubjectIsCA () )
  961. {
  962. CTemplateV1RequestPropertyPage * pRequestPage =
  963. new CTemplateV1RequestPropertyPage (*pCertTemplate);
  964. if ( pRequestPage )
  965. {
  966. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pRequestPage->m_psp);
  967. _ASSERT (hPage);
  968. hr = pCallback->AddPage (hPage);
  969. _ASSERT (SUCCEEDED (hr));
  970. }
  971. else
  972. {
  973. hr = E_OUTOFMEMORY;
  974. }
  975. }
  976. // Add Subject Name page only if subject is not a CA
  977. if ( SUCCEEDED (hr) && !pCertTemplate->SubjectIsCA () )
  978. {
  979. CTemplateV1SubjectNamePropertyPage * pSubjectNamePage =
  980. new CTemplateV1SubjectNamePropertyPage (*pCertTemplate);
  981. if ( pSubjectNamePage )
  982. {
  983. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pSubjectNamePage->m_psp);
  984. _ASSERT (hPage);
  985. hr = pCallback->AddPage (hPage);
  986. _ASSERT (SUCCEEDED (hr));
  987. }
  988. else
  989. {
  990. hr = E_OUTOFMEMORY;
  991. }
  992. }
  993. // Add extensions page - always add this page last (except for security)
  994. if ( SUCCEEDED (hr) )
  995. {
  996. CTemplateExtensionsPropertyPage * pExtensionsPage =
  997. new CTemplateExtensionsPropertyPage (*pCertTemplate,
  998. pGeneralPage->m_bIsDirty);
  999. if ( pExtensionsPage )
  1000. {
  1001. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pExtensionsPage->m_psp);
  1002. _ASSERT (hPage);
  1003. hr = pCallback->AddPage (hPage);
  1004. _ASSERT (SUCCEEDED (hr));
  1005. }
  1006. else
  1007. {
  1008. hr = E_OUTOFMEMORY;
  1009. }
  1010. }
  1011. // Add security page
  1012. if ( SUCCEEDED (hr) )
  1013. {
  1014. // if error, don't display this page
  1015. LPSECURITYINFO pCertTemplateSecurity = NULL;
  1016. hr = CreateCertTemplateSecurityInfo (pCertTemplate,
  1017. &pCertTemplateSecurity);
  1018. if ( SUCCEEDED (hr) )
  1019. {
  1020. // save the pCASecurity pointer for later releasing
  1021. pGeneralPage->SetAllocedSecurityInfo (pCertTemplateSecurity);
  1022. HPROPSHEETPAGE hPage = CreateSecurityPage (pCertTemplateSecurity);
  1023. if (hPage == NULL)
  1024. {
  1025. hr = HRESULT_FROM_WIN32 (GetLastError());
  1026. _TRACE (0, L"CreateSecurityPage () failed: 0x%x\n", hr);
  1027. }
  1028. hr = pCallback->AddPage (hPage);
  1029. _ASSERT (SUCCEEDED (hr));
  1030. }
  1031. }
  1032. }
  1033. _TRACE (-1, L"Leaving CCertTmplComponentData::AddVersion1CertTemplatePropPages: 0x%x\n", hr);
  1034. return hr;
  1035. }
  1036. HRESULT CCertTmplComponentData::AddVersion2CertTemplatePropPages (CCertTemplate* pCertTemplate, LPPROPERTYSHEETCALLBACK pCallback, LONG_PTR lNotifyHandle)
  1037. {
  1038. _TRACE (1, L"Entering CCertTmplComponentData::AddVersion2CertTemplatePropPages\n");
  1039. HRESULT hr = S_OK;
  1040. _ASSERT (pCertTemplate && pCallback);
  1041. if ( pCertTemplate && pCallback )
  1042. {
  1043. _ASSERT (2 == pCertTemplate->GetType ());
  1044. int nPage = 0;
  1045. // Add General page
  1046. CTemplateGeneralPropertyPage * pGeneralPage = new CTemplateGeneralPropertyPage (
  1047. *pCertTemplate, this);
  1048. if ( pGeneralPage )
  1049. {
  1050. pGeneralPage->m_lNotifyHandle = lNotifyHandle;
  1051. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pGeneralPage->m_psp);
  1052. _ASSERT (hPage);
  1053. hr = pCallback->AddPage (hPage);
  1054. _ASSERT (SUCCEEDED (hr));
  1055. }
  1056. else
  1057. {
  1058. hr = E_OUTOFMEMORY;
  1059. }
  1060. // Add Request page only if subject is not a CA
  1061. if ( SUCCEEDED (hr) && !pCertTemplate->SubjectIsCA () )
  1062. {
  1063. CTemplateV2RequestPropertyPage * pRequestPage =
  1064. new CTemplateV2RequestPropertyPage (*pCertTemplate,
  1065. pGeneralPage->m_bIsDirty);
  1066. if ( pRequestPage )
  1067. {
  1068. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pRequestPage->m_psp);
  1069. _ASSERT (hPage);
  1070. hr = pCallback->AddPage (hPage);
  1071. _ASSERT (SUCCEEDED (hr));
  1072. if ( SUCCEEDED (hr) )
  1073. {
  1074. nPage++;
  1075. pGeneralPage->SetV2RequestPageNumber (nPage);
  1076. }
  1077. }
  1078. else
  1079. {
  1080. hr = E_OUTOFMEMORY;
  1081. }
  1082. }
  1083. // Add Subject Name page only if subject is not a CA
  1084. if ( SUCCEEDED (hr) && !pCertTemplate->SubjectIsCA () )
  1085. {
  1086. CTemplateV2SubjectNamePropertyPage * pSubjectNamePage =
  1087. new CTemplateV2SubjectNamePropertyPage (*pCertTemplate,
  1088. pGeneralPage->m_bIsDirty);
  1089. if ( pSubjectNamePage )
  1090. {
  1091. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pSubjectNamePage->m_psp);
  1092. _ASSERT (hPage);
  1093. hr = pCallback->AddPage (hPage);
  1094. _ASSERT (SUCCEEDED (hr));
  1095. if ( SUCCEEDED (hr) )
  1096. nPage++;
  1097. }
  1098. else
  1099. {
  1100. hr = E_OUTOFMEMORY;
  1101. }
  1102. }
  1103. // Add Authentication Name page
  1104. if ( SUCCEEDED (hr) )
  1105. {
  1106. CTemplateV2AuthenticationPropertyPage * pAuthenticationPage =
  1107. new CTemplateV2AuthenticationPropertyPage (*pCertTemplate,
  1108. pGeneralPage->m_bIsDirty);
  1109. if ( pAuthenticationPage )
  1110. {
  1111. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pAuthenticationPage->m_psp);
  1112. _ASSERT (hPage);
  1113. hr = pCallback->AddPage (hPage);
  1114. _ASSERT (SUCCEEDED (hr));
  1115. if ( SUCCEEDED (hr) )
  1116. {
  1117. nPage++;
  1118. pGeneralPage->SetV2AuthPageNumber (nPage);
  1119. }
  1120. }
  1121. else
  1122. {
  1123. hr = E_OUTOFMEMORY;
  1124. }
  1125. }
  1126. // Add Superceded page
  1127. if ( SUCCEEDED (hr) )
  1128. {
  1129. CTemplateV2SupercedesPropertyPage * pSupercededPage =
  1130. new CTemplateV2SupercedesPropertyPage (*pCertTemplate,
  1131. pGeneralPage->m_bIsDirty,
  1132. this);
  1133. if ( pSupercededPage )
  1134. {
  1135. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pSupercededPage->m_psp);
  1136. _ASSERT (hPage);
  1137. hr = pCallback->AddPage (hPage);
  1138. _ASSERT (SUCCEEDED (hr));
  1139. }
  1140. else
  1141. {
  1142. hr = E_OUTOFMEMORY;
  1143. }
  1144. }
  1145. // Add extensions page - always add this page last (except for security)
  1146. if ( SUCCEEDED (hr) )
  1147. {
  1148. CTemplateExtensionsPropertyPage * pExtensionsPage =
  1149. new CTemplateExtensionsPropertyPage (*pCertTemplate,
  1150. pGeneralPage->m_bIsDirty);
  1151. if ( pExtensionsPage )
  1152. {
  1153. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pExtensionsPage->m_psp);
  1154. _ASSERT (hPage);
  1155. hr = pCallback->AddPage (hPage);
  1156. _ASSERT (SUCCEEDED (hr));
  1157. }
  1158. else
  1159. {
  1160. hr = E_OUTOFMEMORY;
  1161. }
  1162. }
  1163. // Add security page
  1164. if ( SUCCEEDED (hr) )
  1165. {
  1166. // if error, don't display this page
  1167. LPSECURITYINFO pCertTemplateSecurity = NULL;
  1168. hr = CreateCertTemplateSecurityInfo (pCertTemplate,
  1169. &pCertTemplateSecurity);
  1170. if ( SUCCEEDED (hr) )
  1171. {
  1172. // save the pCertTemplateSecurity pointer for later releasing
  1173. pGeneralPage->SetAllocedSecurityInfo (pCertTemplateSecurity);
  1174. HPROPSHEETPAGE hPage = CreateSecurityPage (pCertTemplateSecurity);
  1175. if (hPage == NULL)
  1176. {
  1177. hr = HRESULT_FROM_WIN32 (GetLastError());
  1178. _TRACE (0, L"CreateSecurityPage () failed: 0x%x\n", hr);
  1179. }
  1180. hr = pCallback->AddPage (hPage);
  1181. _ASSERT (SUCCEEDED (hr));
  1182. }
  1183. }
  1184. }
  1185. _TRACE (-1, L"Leaving CCertTmplComponentData::AddVersion2CertTemplatePropPages: 0x%x\n", hr);
  1186. return hr;
  1187. }
  1188. HRESULT CCertTmplComponentData::AddCertTemplatePropPages (
  1189. CCertTemplate* pCertTemplate,
  1190. LPPROPERTYSHEETCALLBACK pCallback,
  1191. LONG_PTR lNotifyHandle)
  1192. {
  1193. _TRACE (1, L"Entering CCertTmplComponentData::AddCertTemplatePropPages\n");
  1194. HRESULT hr = S_OK;
  1195. _ASSERT (pCertTemplate && pCallback);
  1196. if ( pCertTemplate && pCallback )
  1197. {
  1198. switch (pCertTemplate->GetType ())
  1199. {
  1200. case 1:
  1201. hr = AddVersion1CertTemplatePropPages (pCertTemplate, pCallback);
  1202. break;
  1203. case 2:
  1204. hr = AddVersion2CertTemplatePropPages (pCertTemplate, pCallback, lNotifyHandle);
  1205. break;
  1206. default:
  1207. _ASSERT (0);
  1208. break;
  1209. }
  1210. }
  1211. else
  1212. hr = E_POINTER;
  1213. _TRACE(-1, L"Leaving CCertTmplComponentData::AddCertTemplatePropPages: 0x%x\n", hr);
  1214. return hr;
  1215. }
  1216. /////////////////////////////////////////////////////////////////////////////
  1217. // IExtendPropertySheet Implementation
  1218. //+----------------------------------------------------------------------------
  1219. //
  1220. // Function: AddPageProc
  1221. //
  1222. // Synopsis: The IShellPropSheetExt->AddPages callback.
  1223. //
  1224. //-----------------------------------------------------------------------------
  1225. BOOL CALLBACK
  1226. AddPageProc(HPROPSHEETPAGE hPage, LPARAM pCall)
  1227. {
  1228. TRACE(_T("xx.%03x> AddPageProc()\n"), GetCurrentThreadId());
  1229. HRESULT hr = ((LPPROPERTYSHEETCALLBACK)pCall)->AddPage(hPage);
  1230. return hr == S_OK;
  1231. }
  1232. HRESULT CCertTmplComponentData::AddCloneTemplateMenuItem(LPCONTEXTMENUCALLBACK pContextMenuCallback, LONG lInsertionPointID)
  1233. {
  1234. _TRACE (1, L"Entering CCertTmplComponentData::AddCloneTemplateMenuItem\n");
  1235. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1236. _ASSERT (pContextMenuCallback);
  1237. HRESULT hr = S_OK;
  1238. CONTEXTMENUITEM menuItem;
  1239. CString szMenu;
  1240. CString szHint;
  1241. ::ZeroMemory (&menuItem, sizeof (menuItem));
  1242. menuItem.lInsertionPointID = lInsertionPointID;
  1243. menuItem.fFlags = 0;
  1244. menuItem.fSpecialFlags = 0;
  1245. VERIFY (szMenu.LoadString (IDS_CLONE_TEMPLATE));
  1246. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  1247. VERIFY (szHint.LoadString (IDS_CLONE_TEMPLATE_HINT));
  1248. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  1249. menuItem.lCommandID = IDM_CLONE_TEMPLATE;
  1250. hr = pContextMenuCallback->AddItem (&menuItem);
  1251. _ASSERT (SUCCEEDED (hr));
  1252. _TRACE (-1, L"Leaving CCertTmplComponentData::AddCloneTemplateMenuItem\n");
  1253. return hr;
  1254. }
  1255. HRESULT CCertTmplComponentData::AddReEnrollAllCertsMenuItem(LPCONTEXTMENUCALLBACK pContextMenuCallback, LONG lInsertionPointID)
  1256. {
  1257. _TRACE (1, L"Entering CCertTmplComponentData::AddReEnrollAllCertsMenuItem\n");
  1258. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1259. _ASSERT (pContextMenuCallback);
  1260. HRESULT hr = S_OK;
  1261. CONTEXTMENUITEM menuItem;
  1262. CString szMenu;
  1263. CString szHint;
  1264. ::ZeroMemory (&menuItem, sizeof (menuItem));
  1265. menuItem.lInsertionPointID = lInsertionPointID;
  1266. menuItem.fFlags = 0;
  1267. menuItem.fSpecialFlags = 0;
  1268. VERIFY (szMenu.LoadString (IDS_REENROLL_ALL_CERTS));
  1269. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  1270. VERIFY (szHint.LoadString (IDS_REENROLL_ALL_CERTS_HINT));
  1271. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  1272. menuItem.lCommandID = IDM_REENROLL_ALL_CERTS;
  1273. hr = pContextMenuCallback->AddItem (&menuItem);
  1274. _ASSERT (SUCCEEDED (hr));
  1275. _TRACE (-1, L"Leaving CCertTmplComponentData::AddReEnrollAllCertsMenuItem\n");
  1276. return hr;
  1277. }
  1278. HRESULT CCertTmplComponentData::RefreshServer()
  1279. {
  1280. // Delete all the scope items and result items, attempt recreate the
  1281. // server and force a reexpansion
  1282. HRESULT hr = DeleteScopeItems ();
  1283. if ( m_pResultData )
  1284. {
  1285. m_pResultData->DeleteAllRsltItems ();
  1286. }
  1287. HWND hWndConsole = 0;
  1288. m_pConsole->GetMainWindow (&hWndConsole);
  1289. GUID guid;
  1290. hr = ExpandScopeNodes (
  1291. &(m_RootCookie), m_hRootScopeItem,
  1292. guid);
  1293. return hr;
  1294. }
  1295. ///////////////////////////////////////////////////////////////////////////////
  1296. //
  1297. // ChangeRootNodeName ()
  1298. //
  1299. // Purpose: Change the text of the root node
  1300. //
  1301. // Input: newName - the new machine name that the snapin manages
  1302. // Output: Returns S_OK on success
  1303. //
  1304. ///////////////////////////////////////////////////////////////////////////////
  1305. HRESULT CCertTmplComponentData::ChangeRootNodeName()
  1306. {
  1307. _TRACE (1, L"Entering CCertTmplComponentData::ChangeRootNodeName\n");
  1308. if ( !QueryBaseRootCookie ().m_hScopeItem )
  1309. {
  1310. if ( m_hRootScopeItem )
  1311. QueryBaseRootCookie ().m_hScopeItem = m_hRootScopeItem;
  1312. else
  1313. return E_UNEXPECTED;
  1314. }
  1315. CString formattedName;
  1316. if ( m_szManagedDomain.IsEmpty () )
  1317. formattedName.FormatMessage (IDS_CERTTMPL_ROOT_NODE_NAME, m_szThisDomainDns);
  1318. else
  1319. formattedName.FormatMessage (IDS_CERTTMPL_ROOT_NODE_NAME, m_szManagedDomain);
  1320. SCOPEDATAITEM item;
  1321. ::ZeroMemory (&item, sizeof (SCOPEDATAITEM));
  1322. item.mask = SDI_STR;
  1323. item.displayname = (PWSTR) (PCWSTR) formattedName;
  1324. item.ID = QueryBaseRootCookie ().m_hScopeItem;
  1325. HRESULT hr = m_pConsoleNameSpace->SetItem (&item);
  1326. if ( FAILED (hr) )
  1327. {
  1328. _TRACE (0, L"IConsoleNameSpace2::SetItem () failed: 0x%x\n", hr);
  1329. }
  1330. _TRACE (-1, L"Leaving CCertTmplComponentData::ChangeRootNodeName: 0x%x\n", hr);
  1331. return hr;
  1332. }
  1333. HRESULT CCertTmplComponentData::OnNotifyPreload(LPDATAOBJECT /*pDataObject*/, HSCOPEITEM hRootScopeItem)
  1334. {
  1335. _TRACE (1, L"Entering CCertTmplComponentData::OnNotifyPreload\n");
  1336. HRESULT hr = S_OK;
  1337. QueryBaseRootCookie ().m_hScopeItem = hRootScopeItem;
  1338. hr = ChangeRootNodeName ();
  1339. _TRACE (-1, L"Leaving CCertTmplComponentData::OnNotifyPreload: 0x%x\n", hr);
  1340. return hr;
  1341. }
  1342. // Help on IComponentData just returns the file and no particular topic
  1343. STDMETHODIMP CCertTmplComponentData::GetHelpTopic(LPOLESTR* lpCompiledHelpFile)
  1344. {
  1345. if (lpCompiledHelpFile == NULL)
  1346. return E_INVALIDARG;
  1347. CString szHelpFilePath;
  1348. HRESULT hr = GetHtmlHelpFilePath( szHelpFilePath );
  1349. if ( FAILED(hr) )
  1350. return hr;
  1351. *lpCompiledHelpFile = reinterpret_cast <LPOLESTR> (
  1352. CoTaskMemAlloc ((szHelpFilePath.GetLength () + 1) * sizeof (wchar_t)));
  1353. if ( NULL == *lpCompiledHelpFile )
  1354. return E_OUTOFMEMORY;
  1355. USES_CONVERSION;
  1356. wcscpy (*lpCompiledHelpFile, T2OLE ((LPTSTR)(LPCTSTR) szHelpFilePath));
  1357. return S_OK;
  1358. }
  1359. HRESULT CCertTmplComponentData::GetHtmlHelpFilePath( CString& strref ) const
  1360. {
  1361. UINT nLen = ::GetSystemWindowsDirectory (strref.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  1362. strref.ReleaseBuffer();
  1363. if (0 == nLen)
  1364. {
  1365. _ASSERT(FALSE);
  1366. return E_FAIL;
  1367. }
  1368. strref += CERTTMPL_HELP_PATH;
  1369. strref += CERTTMPL_HTML_HELP_FILE;
  1370. return S_OK;
  1371. }
  1372. HRESULT CCertTmplComponentData::OnReEnrollAllCerts (LPDATAOBJECT pDataObject)
  1373. {
  1374. _TRACE (1, L"Entering CCertTmplComponentData::OnReEnrollAllCerts");
  1375. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1376. HRESULT hr = S_OK;
  1377. if ( pDataObject )
  1378. {
  1379. CCertTmplCookie* pCookie = ConvertCookie (pDataObject);
  1380. if ( pCookie )
  1381. {
  1382. _ASSERT (CERTTMPL_CERT_TEMPLATE == pCookie->m_objecttype);
  1383. CCertTemplate* pCertTemplate = dynamic_cast <CCertTemplate*> (pCookie);
  1384. if ( pCertTemplate )
  1385. {
  1386. hr = pCertTemplate->IncrementMajorVersion ();
  1387. if ( SUCCEEDED (hr) )
  1388. {
  1389. // Don't increment minor version - was set to 0 in
  1390. // IncrementMajorVersion
  1391. hr = pCertTemplate->SaveChanges (false);
  1392. if ( SUCCEEDED (hr) )
  1393. {
  1394. HRESULTITEM itemID = 0;
  1395. hr = pCookie->m_resultDataID->FindItemByLParam ((LPARAM) pCookie, &itemID);
  1396. _ASSERT (SUCCEEDED (hr));
  1397. if ( SUCCEEDED (hr) )
  1398. {
  1399. hr = m_pResultData->UpdateItem (itemID);
  1400. _ASSERT (SUCCEEDED (hr));
  1401. }
  1402. }
  1403. }
  1404. }
  1405. else
  1406. hr = E_FAIL;
  1407. }
  1408. else
  1409. hr = E_FAIL;
  1410. }
  1411. else
  1412. hr = E_POINTER;
  1413. _TRACE (-1, L"Leaving CCertTmplComponentData::OnReEnrollAllCerts");
  1414. return hr;
  1415. }
  1416. HRESULT CCertTmplComponentData::OnCloneTemplate (LPDATAOBJECT pDataObject)
  1417. {
  1418. _TRACE (1, L"Entering CCertTmplComponentData::OnCloneTemplate");
  1419. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1420. HRESULT hr = S_OK;
  1421. CWaitCursor waitCursor;
  1422. if ( pDataObject )
  1423. {
  1424. CCertTmplCookie* pCookie = ConvertCookie (pDataObject);
  1425. if ( pCookie )
  1426. {
  1427. _ASSERT (CERTTMPL_CERT_TEMPLATE == pCookie->m_objecttype);
  1428. CCertTemplate* pOldTemplate = dynamic_cast <CCertTemplate*> (pCookie);
  1429. if ( pOldTemplate )
  1430. {
  1431. static PCWSTR pszDomainController = L"DomainController";
  1432. static PCWSTR pszComputer = L"Machine";
  1433. bool bIsComputerOrDC = pOldTemplate->GetTemplateName () == pszDomainController ||
  1434. pOldTemplate->GetTemplateName () == pszComputer;
  1435. HWND hWndConsole = 0;
  1436. m_pConsole->GetMainWindow (&hWndConsole);
  1437. CWnd mainWindow;
  1438. mainWindow.Attach (hWndConsole);
  1439. CCertTemplate* pNewTemplate = new CCertTemplate (*pOldTemplate,
  1440. true, false, m_fUseCache);
  1441. if ( pNewTemplate )
  1442. {
  1443. // Generate a unique name for the new template
  1444. int nCopy = 1;
  1445. CString newName;
  1446. while ( 1 )
  1447. {
  1448. if ( 1 == nCopy )
  1449. {
  1450. newName.FormatMessage (IDS_COPY_OF_TEMPLATE,
  1451. (PCWSTR) pOldTemplate->GetDisplayName ());
  1452. }
  1453. else
  1454. {
  1455. newName.FormatMessage (IDS_COPY_X_OF_TEMPLATE, nCopy,
  1456. (PCWSTR) pOldTemplate->GetDisplayName ());
  1457. }
  1458. HCERTTYPE hCertType = 0;
  1459. HRESULT hr1 = CAFindCertTypeByName (newName,
  1460. NULL,
  1461. CT_ENUM_MACHINE_TYPES | CT_ENUM_USER_TYPES | CT_FLAG_NO_CACHE_LOOKUP,
  1462. &hCertType);
  1463. _TRACE (0, L"checking to see if %s exists: %s\n",
  1464. (PCWSTR) newName,
  1465. SUCCEEDED (hr) ? L"was found" : L"was not found");
  1466. if ( SUCCEEDED (hr1) )
  1467. {
  1468. hr1 = CACloseCertType (hCertType);
  1469. if ( FAILED (hr1) )
  1470. {
  1471. _TRACE (0, L"CACloseCertType () failed: 0x%x", hr);
  1472. }
  1473. // This one exists, try another.
  1474. nCopy++;
  1475. continue;
  1476. }
  1477. else
  1478. {
  1479. // This one does not exist. Use it as the new name.
  1480. break;
  1481. }
  1482. }
  1483. if ( SUCCEEDED (hr) )
  1484. {
  1485. hr = pNewTemplate->Clone (*pOldTemplate,
  1486. newName, newName);
  1487. if ( SUCCEEDED (hr) )
  1488. {
  1489. CString title;
  1490. VERIFY (title.LoadString (IDS_PROPERTIES_OF_NEW_TEMPLATE));
  1491. CTemplatePropertySheet propSheet (title, *pNewTemplate, &mainWindow);
  1492. CTemplateGeneralPropertyPage* pGeneralPage =
  1493. new CTemplateGeneralPropertyPage (
  1494. *pNewTemplate,
  1495. this);
  1496. if ( pGeneralPage )
  1497. {
  1498. propSheet.AddPage (pGeneralPage);
  1499. int nPage = 0;
  1500. // Add Request and Subject pages if subject is not a CA
  1501. if ( !pNewTemplate->SubjectIsCA () )
  1502. {
  1503. propSheet.AddPage (new CTemplateV2RequestPropertyPage (
  1504. *pNewTemplate, pGeneralPage->m_bIsDirty));
  1505. nPage++;
  1506. pGeneralPage->SetV2RequestPageNumber (nPage);
  1507. propSheet.AddPage (new CTemplateV2SubjectNamePropertyPage (
  1508. *pNewTemplate, pGeneralPage->m_bIsDirty,
  1509. bIsComputerOrDC));
  1510. nPage++;
  1511. }
  1512. propSheet.AddPage (new CTemplateV2AuthenticationPropertyPage (
  1513. *pNewTemplate, pGeneralPage->m_bIsDirty));
  1514. nPage++;
  1515. pGeneralPage->SetV2AuthPageNumber (nPage);
  1516. propSheet.AddPage (new CTemplateV2SupercedesPropertyPage (
  1517. *pNewTemplate, pGeneralPage->m_bIsDirty,
  1518. this));
  1519. // Add template extension page - always add this page last (except for security)
  1520. propSheet.AddPage (new CTemplateExtensionsPropertyPage (
  1521. *pNewTemplate, pGeneralPage->m_bIsDirty));
  1522. CThemeContextActivator activator;
  1523. INT_PTR iResult = propSheet.DoModal ();
  1524. switch (iResult)
  1525. {
  1526. case IDOK:
  1527. {
  1528. hr = pNewTemplate->DoAutoEnrollmentPendingSave ();
  1529. // unselect old template
  1530. HRESULTITEM itemID = 0;
  1531. ASSERT (m_pResultData);
  1532. if ( m_pResultData )
  1533. {
  1534. hr = m_pResultData->FindItemByLParam (
  1535. (LPARAM) pCookie, &itemID);
  1536. ASSERT (SUCCEEDED (hr));
  1537. if ( SUCCEEDED (hr) )
  1538. {
  1539. RESULTDATAITEM rdItem;
  1540. ::ZeroMemory (&rdItem, sizeof (RESULTDATAITEM));
  1541. rdItem.itemID = itemID;
  1542. rdItem.mask = RDI_STATE;
  1543. rdItem.nState &= ~(LVIS_FOCUSED | LVIS_SELECTED);
  1544. hr = m_pResultData->SetItem (&rdItem);
  1545. if ( SUCCEEDED (hr) )
  1546. {
  1547. hr = m_pResultData->UpdateItem (itemID);
  1548. ASSERT (SUCCEEDED (hr));
  1549. }
  1550. }
  1551. }
  1552. else
  1553. hr = E_FAIL;
  1554. // Add certificate template to result pane
  1555. RESULTDATAITEM rdItem;
  1556. CCookie& rootCookie = QueryBaseRootCookie ();
  1557. ::ZeroMemory (&rdItem, sizeof (rdItem));
  1558. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM | RDI_STATE;
  1559. rdItem.nImage = iIconCertTemplateV2;
  1560. rdItem.nCol = 0;
  1561. rdItem.nState = LVIS_SELECTED | LVIS_FOCUSED;
  1562. rdItem.str = MMC_TEXTCALLBACK;
  1563. rootCookie.m_listResultCookieBlocks.AddHead (pNewTemplate);
  1564. rdItem.lParam = (LPARAM) pNewTemplate;
  1565. pNewTemplate->m_resultDataID = m_pResultData;
  1566. hr = m_pResultData->InsertItem (&rdItem);
  1567. if ( FAILED (hr) )
  1568. {
  1569. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  1570. }
  1571. else
  1572. {
  1573. m_dwNumCertTemplates++;
  1574. DisplayObjectCountInStatusBar (
  1575. m_pConsole,
  1576. m_dwNumCertTemplates);
  1577. pNewTemplate = 0;
  1578. }
  1579. }
  1580. break;
  1581. case IDCANCEL:
  1582. // Delete cloned template
  1583. if ( pNewTemplate->CanBeDeletedOnCancel () )
  1584. hr = pNewTemplate->Delete ();
  1585. else // was created - let's update
  1586. {
  1587. hr = pNewTemplate->DoAutoEnrollmentPendingSave ();
  1588. // Add certificate template to result pane
  1589. RESULTDATAITEM rdItem;
  1590. CCookie& rootCookie = QueryBaseRootCookie ();
  1591. ::ZeroMemory (&rdItem, sizeof (rdItem));
  1592. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM | RDI_STATE;
  1593. rdItem.nImage = iIconCertTemplateV2;
  1594. rdItem.nCol = 0;
  1595. rdItem.nState = LVIS_SELECTED | LVIS_FOCUSED;
  1596. rdItem.str = MMC_TEXTCALLBACK;
  1597. rootCookie.m_listResultCookieBlocks.AddHead (pNewTemplate);
  1598. rdItem.lParam = (LPARAM) pNewTemplate;
  1599. pNewTemplate->m_resultDataID = m_pResultData;
  1600. hr = m_pResultData->InsertItem (&rdItem);
  1601. if ( FAILED (hr) )
  1602. {
  1603. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  1604. }
  1605. else
  1606. {
  1607. m_dwNumCertTemplates++;
  1608. DisplayObjectCountInStatusBar (
  1609. m_pConsole,
  1610. m_dwNumCertTemplates);
  1611. pNewTemplate = 0;
  1612. }
  1613. }
  1614. break;
  1615. }
  1616. }
  1617. else
  1618. hr = E_OUTOFMEMORY;
  1619. }
  1620. else
  1621. {
  1622. CString caption;
  1623. CString text;
  1624. VERIFY (caption.LoadString (IDS_CERTTMPL));
  1625. text.FormatMessage (IDS_UNABLE_TO_CLONE_TEMPLATE,
  1626. pOldTemplate->GetDisplayName (),
  1627. GetSystemMessage (hr));
  1628. int iRetVal = 0;
  1629. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  1630. MB_ICONWARNING | MB_OK, &iRetVal)));
  1631. }
  1632. }
  1633. if ( pNewTemplate )
  1634. delete pNewTemplate;
  1635. }
  1636. else
  1637. hr = E_OUTOFMEMORY;
  1638. mainWindow.Detach ();
  1639. }
  1640. else
  1641. hr = E_UNEXPECTED;
  1642. }
  1643. else
  1644. hr = E_FAIL;
  1645. }
  1646. else
  1647. hr = E_POINTER;
  1648. _TRACE (-1, L"Leaving CCertTmplComponentData::OnCloneTemplate");
  1649. return hr;
  1650. }
  1651. HRESULT CCertTmplComponentData::AddViewOIDsMenuItem (
  1652. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1653. LONG lInsertionPointID)
  1654. {
  1655. _TRACE (1, L"Entering CCertTmplComponentData::AddViewOIDsMenuItem\n");
  1656. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1657. _ASSERT (pContextMenuCallback);
  1658. HRESULT hr = S_OK;
  1659. CONTEXTMENUITEM menuItem;
  1660. CString szMenu;
  1661. CString szHint;
  1662. ::ZeroMemory (&menuItem, sizeof (menuItem));
  1663. menuItem.lInsertionPointID = lInsertionPointID;
  1664. menuItem.fFlags = 0;
  1665. menuItem.fSpecialFlags = 0;
  1666. VERIFY (szMenu.LoadString (IDS_VIEW_OIDS));
  1667. menuItem.strName = (PWSTR) (PCWSTR) szMenu;
  1668. VERIFY (szHint.LoadString (IDS_VIEW_OIDS_HINT));
  1669. menuItem.strStatusBarText = (PWSTR) (PCWSTR) szHint;
  1670. menuItem.lCommandID = IDM_VIEW_OIDS;
  1671. hr = pContextMenuCallback->AddItem (&menuItem);
  1672. _ASSERT (SUCCEEDED (hr));
  1673. _TRACE (-1, L"Leaving CCertTmplComponentData::AddViewOIDsMenuItem\n");
  1674. return hr;
  1675. }
  1676. void CCertTmplComponentData::OnViewOIDs ()
  1677. {
  1678. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1679. HWND hWndConsole = 0;
  1680. m_pConsole->GetMainWindow (&hWndConsole);
  1681. CWnd mainWindow;
  1682. mainWindow.Attach (hWndConsole);
  1683. CViewOIDDlg dlg (&mainWindow);
  1684. CThemeContextActivator activator;
  1685. dlg.DoModal ();
  1686. mainWindow.Detach ();
  1687. }