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.

2023 lines
69 KiB

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