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.

559 lines
16 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) Microsoft Corporation, 1995 - 1999
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. /////////////////////////////////////////////////////////////////////////////
  10. // Event handlers for IFrame::Notify
  11. HRESULT CSnapin::OnFolder(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  12. {
  13. ASSERT(FALSE);
  14. return S_OK;
  15. }
  16. HRESULT CSnapin::OnAddImages(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  17. {
  18. if (arg == 0)
  19. return E_INVALIDARG;
  20. // if cookie is from a different snapin
  21. // if (IsMyCookie(cookie) == FALSE)
  22. if (0)
  23. {
  24. // add the images for the scope tree only
  25. ::CBitmap bmp16x16;
  26. ::CBitmap bmp32x32;
  27. LPIMAGELIST lpImageList = reinterpret_cast<LPIMAGELIST>(arg);
  28. // Load the bitmaps from the dll
  29. bmp16x16.LoadBitmap(IDB_16x16);
  30. bmp32x32.LoadBitmap(IDB_32x32);
  31. // Set the images
  32. lpImageList->ImageListSetStrip(
  33. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  34. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  35. 0, RGB(255, 0, 255));
  36. lpImageList->Release();
  37. }
  38. else
  39. {
  40. ASSERT(m_pImageResult != NULL);
  41. ::CBitmap bmp16x16;
  42. ::CBitmap bmp32x32;
  43. // Load the bitmaps from the dll
  44. bmp16x16.LoadBitmap(IDB_16x16);
  45. bmp32x32.LoadBitmap(IDB_32x32);
  46. // Set the images
  47. m_pImageResult->ImageListSetStrip(reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp16x16)),
  48. reinterpret_cast<LONG_PTR*>(static_cast<HBITMAP>(bmp32x32)),
  49. 0, RGB(255, 0, 255));
  50. }
  51. return S_OK;
  52. }
  53. typedef IMessageView *LPMESSAGEVIEW;
  54. HRESULT CSnapin::OnShow(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  55. {
  56. CComponentDataImpl* pComp = dynamic_cast<CComponentDataImpl*>(m_pComponentData);
  57. CFolder* pFolder = pComp->FindObject(cookie);
  58. if ((cookie == NULL) || (pFolder == NULL))
  59. {
  60. return S_OK;
  61. }
  62. // Note - arg is TRUE when it is time to enumerate
  63. if (arg == TRUE)
  64. {
  65. m_pCurrentlySelectedScopeFolder = pFolder;
  66. // if list view on display
  67. if (m_CustomViewID == VIEW_DEFAULT_LV)
  68. {
  69. // Show the headers for this nodetype
  70. if (S_OK != InitializeHeaders(cookie))
  71. {
  72. // UNDONE: add informative "server down" result object
  73. goto done;
  74. }
  75. return Enumerate(cookie, param);
  76. }
  77. else if (m_CustomViewID == VIEW_ERROR_OCX)
  78. {
  79. HRESULT hr;
  80. CString strMessage;
  81. strMessage.LoadString(IDS_ERROR_CANNOT_LOAD_TEMPLATES);
  82. LPUNKNOWN pUnk = NULL;
  83. LPMESSAGEVIEW pMessageView = NULL;
  84. hr = m_pConsole->QueryResultView(&pUnk);
  85. _JumpIfError(hr, done, "QueryResultView IUnk");
  86. hr = pUnk->QueryInterface(IID_IMessageView, reinterpret_cast<void**>(&pMessageView));
  87. _JumpIfError(hr, done, "IID_IMessageView");
  88. pMessageView->SetIcon(Icon_Error);
  89. CAutoLPWSTR pwszErrorCode = BuildErrorMessage(pComp->GetCreateFolderHRESULT());
  90. pMessageView->SetTitleText(strMessage);
  91. pMessageView->SetBodyText(pwszErrorCode);
  92. pUnk->Release();
  93. pMessageView->Release();
  94. }
  95. }
  96. else
  97. {
  98. m_pCurrentlySelectedScopeFolder = NULL;
  99. // if list view is on display
  100. if (m_CustomViewID == VIEW_DEFAULT_LV)
  101. {
  102. RemoveResultItems(cookie);
  103. }
  104. // Free data associated with the result pane items, because
  105. // your node is no longer being displayed.
  106. // Note: The console will remove the items from the result pane
  107. }
  108. done:
  109. return S_OK;
  110. }
  111. HRESULT CSnapin::OnDelete(LPDATAOBJECT pDataObject, LPARAM arg, LPARAM param)
  112. {
  113. HRESULT hr;
  114. WCHAR ** aszCertTypesCurrentlySupported;
  115. WCHAR ** aszNewCertTypesSupported;
  116. WCHAR ** aszNameOfDeleteType;
  117. HRESULTITEM itemID;
  118. HWND hwndConsole;
  119. CTemplateList TemplateList;
  120. CString cstrMsg, cstrTitle;
  121. cstrMsg.LoadString(IDS_ASK_CONFIRM_DELETETEMPLATES);
  122. cstrTitle.LoadString(IDS_TITLE_ASK_CONFIRM_DELETETEMPLATES);
  123. HWND hwndMain = NULL;
  124. m_pConsole->GetMainWindow(&hwndMain);
  125. if (IDYES != MessageBox(
  126. hwndMain,
  127. (LPCWSTR)cstrMsg,
  128. (LPCWSTR)cstrTitle,
  129. MB_YESNO))
  130. return ERROR_CANCELLED;
  131. CWaitCursor hourglass;
  132. ASSERT(m_pResult != NULL); // make sure we QI'ed for the interface
  133. ASSERT(m_pComponentData != NULL);
  134. if(!IsMMCMultiSelectDataObject(pDataObject))
  135. {
  136. INTERNAL * pInternal = ExtractInternalFormat(pDataObject);
  137. if ((pInternal == NULL) ||
  138. (pInternal->m_cookie == NULL))
  139. {
  140. //ASSERT(FALSE);
  141. return S_OK;
  142. }
  143. CFolder* pFolder = reinterpret_cast<CFolder*>(pInternal->m_cookie);
  144. hr = RetrieveCATemplateList(
  145. pFolder->m_hCAInfo,
  146. TemplateList);
  147. if (FAILED(hr))
  148. {
  149. m_pConsole->GetMainWindow(&hwndConsole);
  150. MyErrorBox(hwndConsole, IDS_CERTTYPE_INFO_FAIL ,IDS_SNAPIN_NAME, hr);
  151. return hr;
  152. }
  153. ASSERT(pFolder != NULL);
  154. ASSERT(pFolder->m_hCertType != NULL);
  155. FOLDER_TYPES type = pFolder->GetType();
  156. if(type == CA_CERT_TYPE)
  157. {
  158. hr = RemoveFromCATemplateList(
  159. pFolder->m_hCAInfo,
  160. TemplateList,
  161. pFolder->m_hCertType);
  162. if (FAILED(hr))
  163. {
  164. m_pConsole->GetMainWindow(&hwndConsole);
  165. MyErrorBox(hwndConsole, IDS_CERTTYPE_INFO_FAIL ,IDS_SNAPIN_NAME, hr);
  166. return hr;
  167. }
  168. hr = UpdateCATemplateList(
  169. pFolder->m_hCAInfo,
  170. TemplateList);
  171. if (FAILED(hr))
  172. {
  173. m_pConsole->GetMainWindow(&hwndConsole);
  174. MyErrorBox(hwndConsole, IDS_DELETE_ERROR ,IDS_SNAPIN_NAME, hr);
  175. return hr;
  176. }
  177. hr = m_pResult->FindItemByLParam ((LPARAM)pFolder, &itemID);
  178. hr = m_pResult->DeleteItem (itemID, 0);
  179. delete(pFolder);
  180. }
  181. }
  182. else
  183. {
  184. // Is multiple select, get all selected items and paste each one
  185. MMC_COOKIE currentCookie = NULL;
  186. HCAINFO hCAInfo = NULL;
  187. CDataObject* pDO = dynamic_cast <CDataObject*>(pDataObject);
  188. ASSERT (pDO);
  189. if ( pDO )
  190. {
  191. INT i;
  192. bool fTemplateListRetrieved = false;
  193. for(i=pDO->QueryCookieCount()-1; i >= 0; i--)
  194. {
  195. hr = pDO->GetCookieAt(i, &currentCookie);
  196. if(hr != S_OK)
  197. {
  198. return hr;
  199. }
  200. CFolder* pFolder = reinterpret_cast<CFolder*>(currentCookie);
  201. if(!fTemplateListRetrieved)
  202. {
  203. hr = RetrieveCATemplateList(
  204. pFolder->m_hCAInfo,
  205. TemplateList);
  206. if (FAILED(hr))
  207. {
  208. m_pConsole->GetMainWindow(&hwndConsole);
  209. MyErrorBox(hwndConsole, IDS_CERTTYPE_INFO_FAIL ,IDS_SNAPIN_NAME, hr);
  210. return hr;
  211. }
  212. fTemplateListRetrieved = true;
  213. }
  214. ASSERT(pFolder != NULL);
  215. ASSERT(pFolder->m_hCertType != NULL);
  216. FOLDER_TYPES type = pFolder->GetType();
  217. if(type == CA_CERT_TYPE)
  218. {
  219. if(hCAInfo == NULL)
  220. {
  221. // Grab the CA this type belongs to.
  222. hCAInfo = pFolder->m_hCAInfo;
  223. }
  224. hr = RemoveFromCATemplateList(
  225. hCAInfo,
  226. TemplateList,
  227. pFolder->m_hCertType);
  228. if (FAILED(hr))
  229. {
  230. m_pConsole->GetMainWindow(&hwndConsole);
  231. MyErrorBox(hwndConsole, IDS_CERTTYPE_INFO_FAIL ,IDS_SNAPIN_NAME, hr);
  232. return hr;
  233. }
  234. hr = m_pResult->FindItemByLParam ((LPARAM)pFolder, &itemID);
  235. if(hr != S_OK)
  236. {
  237. return hr;
  238. }
  239. // We must delete the actual CFolder backing this item if we do this
  240. // or we leak.
  241. hr = m_pResult->DeleteItem (itemID, 0);
  242. if(hr != S_OK)
  243. {
  244. return hr;
  245. }
  246. hr = pDO->RemoveCookieAt(i);
  247. if(hr != S_OK)
  248. {
  249. return hr;
  250. }
  251. // Note, since this is a type folder, the CAInfo will not be closed on delete
  252. delete pFolder;
  253. }
  254. }
  255. if(hCAInfo)
  256. {
  257. hr = UpdateCATemplateList(
  258. hCAInfo,
  259. TemplateList);
  260. if (FAILED(hr))
  261. {
  262. m_pConsole->GetMainWindow(&hwndConsole);
  263. MyErrorBox(hwndConsole, IDS_DELETE_ERROR ,IDS_SNAPIN_NAME, hr);
  264. return hr;
  265. }
  266. }
  267. }
  268. }
  269. return S_OK;
  270. }
  271. HRESULT CSnapin::OnActivate(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  272. {
  273. return S_OK;
  274. }
  275. HRESULT CSnapin::OnResultItemClk(DATA_OBJECT_TYPES type, MMC_COOKIE cookie)
  276. {
  277. RESULT_DATA* pResult;
  278. DWORD* pdw = reinterpret_cast<DWORD*>(cookie);
  279. if (*pdw == RESULT_ITEM)
  280. {
  281. pResult = reinterpret_cast<RESULT_DATA*>(cookie);
  282. }
  283. return S_OK;
  284. }
  285. HRESULT CSnapin::OnMinimize(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  286. {
  287. return S_OK;
  288. }
  289. HRESULT CSnapin::OnPropertyChange(LPDATAOBJECT lpDataObject)
  290. {
  291. return S_OK;
  292. }
  293. HRESULT CSnapin::Enumerate(MMC_COOKIE cookie, HSCOPEITEM pParent)
  294. {
  295. return EnumerateResultPane(cookie);
  296. }
  297. HRESULT CSnapin::EnumerateResultPane(MMC_COOKIE cookie)
  298. {
  299. ASSERT(m_pResult != NULL); // make sure we QI'ed for the interface
  300. ASSERT(m_pComponentData != NULL);
  301. // don't bother enumerating base
  302. if (cookie == NULL)
  303. return S_FALSE;
  304. // Our static folders must be displayed in the result pane
  305. // by use because the console doesn't do it.
  306. CFolder* pFolder = dynamic_cast<CComponentDataImpl*>(m_pComponentData)->FindObject(cookie);
  307. // The dynamic folder must be in our list
  308. ASSERT(pFolder != NULL);
  309. FOLDER_TYPES type = pFolder->GetType();
  310. switch(type)
  311. {
  312. case STATIC:
  313. break;
  314. case POLICYSETTINGS:
  315. return AddCACertTypesToResults(pFolder);
  316. break;
  317. default:
  318. break;
  319. }
  320. return S_FALSE;
  321. }
  322. void CSnapin::RemoveResultItems(MMC_COOKIE cookie)
  323. {
  324. if (cookie == NULL)
  325. return;
  326. // Our static folders must be displayed in the result pane
  327. // by use because the console doesn't do it.
  328. CFolder* pFolder = dynamic_cast<CComponentDataImpl*>(m_pComponentData)->FindObject(cookie);
  329. // The dynamic folder must be in our list
  330. ASSERT(pFolder != NULL);
  331. FOLDER_TYPES type = pFolder->GetType();
  332. RESULTDATAITEM resultItem;
  333. ZeroMemory(&resultItem, sizeof(RESULTDATAITEM));
  334. // look for first rdi by index
  335. resultItem.mask = RDI_INDEX | RDI_PARAM; // fill in index & param
  336. resultItem.nIndex = 0;
  337. switch (type)
  338. {
  339. case POLICYSETTINGS:
  340. case SCE_EXTENSION:
  341. while (S_OK == m_pResult->GetItem(&resultItem))
  342. {
  343. CFolder* pResult = reinterpret_cast<CFolder*>(resultItem.lParam);
  344. resultItem.lParam = NULL;
  345. delete pResult;
  346. // next item
  347. resultItem.nIndex++;
  348. }
  349. break;
  350. default:
  351. break;
  352. }
  353. return;
  354. }
  355. HRESULT CSnapin::AddCACertTypesToResults(CFolder* pFolder)
  356. {
  357. HRESULT hr = S_OK;
  358. CFolder *pNewFolder;
  359. WCHAR ** aszCertTypeName;
  360. HWND hwndConsole;
  361. BOOL fMachine = FALSE;
  362. CTemplateList CATemplateList;
  363. CTemplateListEnum CATemplateListEnum(CATemplateList);
  364. CTemplateInfo *pTemplateInfo;
  365. HCERTTYPE hCertType;
  366. bool fNoCacheLookup = true;
  367. CWaitCursor WaitCursor;
  368. m_pConsole->GetMainWindow(&hwndConsole);
  369. hr = RetrieveCATemplateList(pFolder->m_hCAInfo, CATemplateList);
  370. if(FAILED(hr))
  371. {
  372. m_CustomViewID = VIEW_ERROR_OCX; // change the view type
  373. m_pConsole->SelectScopeItem(m_pCurrentlySelectedScopeFolder->m_pScopeItem->ID); // select this node again
  374. // done, let's bail and let the error page do its job
  375. return S_OK;
  376. }
  377. CATemplateListEnum.Reset();
  378. for(pTemplateInfo=CATemplateListEnum.Next();
  379. pTemplateInfo;
  380. pTemplateInfo=CATemplateListEnum.Next())
  381. {
  382. hCertType = pTemplateInfo->GetCertType();
  383. if(!hCertType)
  384. {
  385. CSASSERT(pTemplateInfo->GetName());
  386. hr = CAFindCertTypeByName(
  387. pTemplateInfo->GetName(),
  388. NULL,
  389. CT_ENUM_MACHINE_TYPES |
  390. CT_ENUM_USER_TYPES |
  391. (fNoCacheLookup?CT_FLAG_NO_CACHE_LOOKUP:0),
  392. &hCertType);
  393. if(FAILED(hr))
  394. {
  395. MyErrorBox(hwndConsole, IDS_CERTTYPE_INFO_FAIL ,IDS_SNAPIN_NAME, hr);
  396. _JumpErrorStr(hr, error, "CAFindCertTypeByName", pTemplateInfo->GetName());
  397. }
  398. fNoCacheLookup = false;
  399. }
  400. hr = CAGetCertTypeProperty(
  401. hCertType,
  402. CERTTYPE_PROP_FRIENDLY_NAME,
  403. &aszCertTypeName);
  404. if (FAILED(hr) || (aszCertTypeName == NULL))
  405. {
  406. MyErrorBox(hwndConsole, IDS_CERTTYPE_INFO_FAIL ,IDS_SNAPIN_NAME, hr);
  407. _JumpErrorStr(hr, error, "CAGetCertTypeProperty", pTemplateInfo->GetName());
  408. }
  409. pNewFolder = new CFolder();
  410. _JumpIfAllocFailed(pNewFolder, error);
  411. pNewFolder->Create(
  412. aszCertTypeName[0],
  413. IMGINDEX_CERTTYPE,
  414. IMGINDEX_CERTTYPE,
  415. RESULT_ITEM,
  416. CA_CERT_TYPE,
  417. FALSE);
  418. CAFreeCertTypeProperty(
  419. hCertType,
  420. aszCertTypeName);
  421. //
  422. // get the key usage string
  423. //
  424. GetIntendedUsagesString(hCertType, &(pNewFolder->m_szIntendedUsages));
  425. if (pNewFolder->m_szIntendedUsages == L"")
  426. {
  427. pNewFolder->m_szIntendedUsages.LoadString(IDS_ALL);
  428. }
  429. pNewFolder->m_hCertType = hCertType;
  430. pNewFolder->m_hCAInfo = pFolder->m_hCAInfo;
  431. RESULTDATAITEM resultItem;
  432. ZeroMemory(&resultItem, sizeof(RESULTDATAITEM));
  433. resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  434. resultItem.bScopeItem = FALSE;
  435. resultItem.itemID = (LONG_PTR) pNewFolder;
  436. resultItem.str = MMC_CALLBACK;
  437. resultItem.nImage = IMGINDEX_CERTTYPE;
  438. resultItem.lParam = reinterpret_cast<LPARAM>(pNewFolder);
  439. // add to result pane
  440. resultItem.nCol = 0;
  441. hr = m_pResult->InsertItem(&resultItem);
  442. _JumpIfError(hr, error, "InsertItem");
  443. }
  444. error:
  445. return hr;
  446. }