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.

6086 lines
180 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2001.
  5. //
  6. // File: cmponent.cpp
  7. //
  8. // Contents: Implementation of CCertMgrComponent
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include <gpedit.h>
  13. #include <wintrust.h>
  14. #include <sceattch.h>
  15. #include "compdata.h" // CCertMgrComponentData
  16. #include "dataobj.h"
  17. #include "cmponent.h" // CCertMgrComponent
  18. #include "storegpe.h"
  19. #include "users.h"
  20. #include "addsheet.h"
  21. #include "StoreRSOP.h"
  22. #include "SaferEntry.h"
  23. #ifdef _DEBUG
  24. #ifndef ALPHA
  25. #define new DEBUG_NEW
  26. #endif
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. USE_HANDLE_MACROS ("CERTMGR (cmponent.cpp)")
  31. #include "stdcmpnt.cpp" // CComponent
  32. extern bool g_bSchemaIsW2K;
  33. extern GUID g_guidExtension;
  34. extern GUID g_guidRegExt;
  35. extern GUID g_guidSnapin;
  36. // CERTMGR_USAGE, CERTMGR_USAGE, CERTMGR_USAGE, CERTMGR_CERT_CONTAINER
  37. UINT m_aColumns0[CERT_NUM_COLS+1] =
  38. {IDS_COLUMN_SUBJECT, IDS_COLUMN_ISSUER, IDS_COLUMN_EXPIRATION_DATE,
  39. IDS_COLUMN_PURPOSE, IDS_COLUMN_FRIENDLY_NAME, IDS_COLUMN_STATUS,
  40. IDS_COLUMN_TEMPLATE_NAME, 0};
  41. // CERTMGR_SNAPIN
  42. UINT m_aColumns1[2] =
  43. {IDS_COLUMN_LOG_CERTIFICATE_STORE,0};
  44. // CERTMGR_CERTIFICATE, CERTMGR_CRL, CERTMGR_CTL
  45. UINT m_aColumns2[2] =
  46. {0,0};
  47. // CERTMGR_CRL_CONTAINER
  48. UINT m_aColumns3[4] =
  49. {IDS_COLUMN_ISSUER, IDS_COLUMN_EFFECTIVE_DATE, IDS_COLUMN_NEXT_UPDATE, 0};
  50. // CERTMGR_CTL_CONTAINER
  51. UINT m_aColumns4[6] =
  52. {IDS_COLUMN_ISSUER, IDS_COLUMN_EFFECTIVE_DATE, IDS_COLUMN_PURPOSE, IDS_COLUMN_FRIENDLY_NAME, 0};
  53. UINT m_aColumns5[2] =
  54. {IDS_COLUMN_OBJECT_TYPE, 0};
  55. // CERTMGR_SAFER_USER_LEVELS, CERTMGR_SAFER_COMPUTER_LEVELS
  56. UINT m_aColumns6[SAFER_LEVELS_NUM_COLS+1] =
  57. {IDS_COLUMN_NAME, IDS_COLUMN_DESCRIPTION, 0};
  58. // CERTMGR_SAFER_USER_ENTRIES, CERTMGR_SAFER_COMPUTER_ENTRIES
  59. UINT m_aColumns7[SAFER_ENTRIES_NUM_COLS+1] =
  60. {IDS_COLUMN_NAME, IDS_COLUMN_TYPE, IDS_COLUMN_LEVEL, IDS_COLUMN_DESCRIPTION, IDS_COLUMN_LAST_MODIFIED_DATE, 0};
  61. UINT* m_Columns[CERTMGR_NUMTYPES] =
  62. {
  63. m_aColumns1, // CERTMGR_SNAPIN
  64. m_aColumns2, // CERTMGR_CERTIFICATE (result)
  65. m_aColumns5, // CERTMGR_LOG_STORE
  66. m_aColumns5, // CERTMGR_PHYS_STORE
  67. m_aColumns0, // CERTMGR_USAGE
  68. m_aColumns3, // CERTMGR_CRL_CONTAINER
  69. m_aColumns4, // CERTMGR_CTL_CONTAINER
  70. m_aColumns0, // CERTMGR_CERT_CONTAINER
  71. m_aColumns2, // CERTMGR_CRL (result)
  72. m_aColumns2, // CERTMGR_CTL (result)
  73. m_aColumns2, // CERTMGR_AUTO_CERT_REQUEST
  74. m_aColumns5, // CERTMGR_CERT_POLICIES_USER,
  75. m_aColumns5, // CERTMGR_CERT_POLICIES_COMPUTER,
  76. m_aColumns5, // CERTMGR_LOG_STORE_GPE
  77. m_aColumns5, // CERTMGR_LOG_STORE_RSOP
  78. m_aColumns1, // CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS
  79. m_aColumns1, // CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS
  80. m_aColumns5, // CERTMGR_SAFER_COMPUTER_ROOT
  81. m_aColumns5, // CERTMGR_SAFER_USER_ROOT
  82. m_aColumns6, // CERTMGR_SAFER_COMPUTER_LEVELS
  83. m_aColumns6, // CERTMGR_SAFER_USER_LEVELS
  84. m_aColumns7, // CERTMGR_SAFER_COMPUTER_ENTRIES
  85. m_aColumns7, // CERTMGR_SAFER_USER_ENTRIES
  86. m_aColumns2, // CERTMGR_SAFER_COMPUTER_LEVEL,
  87. m_aColumns2, // CERTMGR_SAFER_USER_LEVEL,
  88. m_aColumns2, // CERTMGR_SAFER_COMPUTER_ENTRY,
  89. m_aColumns2, // CERTMGR_SAFER_USER_ENTRY,
  90. m_aColumns2, // CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS
  91. m_aColumns2, // CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS
  92. m_aColumns2, // CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES
  93. m_aColumns2, // CERTMGR_SAFER_USER_DEFINED_FILE_TYPES
  94. m_aColumns2, // CERTMGR_SAFER_USER_ENFORCEMENT
  95. m_aColumns2 // CERTMGR_SAFER_COMPUTER_ENFORCEMENT
  96. };
  97. UINT** g_aColumns = 0; // for framework
  98. int** g_aColumnWidths = 0; // for framework
  99. const int SINGLE_COL_WIDTH = 450;
  100. CCertMgrComponent::CCertMgrComponent ()
  101. : m_pViewedCookie (NULL),
  102. m_bUsageStoresEnumerated (false),
  103. m_pPastedDO (NULL),
  104. m_bShowArchivedCertsStateWhenLogStoresEnumerated (false),
  105. m_nSelectedCertColumn (0),
  106. m_nSelectedCRLColumn (0),
  107. m_nSelectedCTLColumn (0),
  108. m_nSelectedSaferEntryColumn (0),
  109. m_pLastUsageCookie (0),
  110. m_pControlbar (0),
  111. m_pToolbar (0)
  112. {
  113. AFX_MANAGE_STATE (AfxGetStaticModuleState ( ));
  114. _TRACE (1, L"Entering CCertMgrComponent::CCertMgrComponent\n");
  115. const int ISSUED_TO_BY_WIDTH = 200;
  116. const int FRIENDLY_NAME_WIDTH = 125;
  117. const int DATE_WIDTH = 100;
  118. const int PURPOSE_WIDTH = 125;
  119. const int STATUS_WIDTH = 50;
  120. const int TEMPLATE_WIDTH = 100;
  121. const int SAFER_LEVEL_NAME_WIDTH = 150;
  122. const int SAFER_LEVEL_DESCRIPTION_WIDTH = 400;
  123. const int SAFER_ENTRY_NAME_WIDTH = 250;
  124. const int SAFER_ENTRY_TYPE_WIDTH = 75;
  125. const int SAFER_ENTRY_LEVEL_WIDTH = 100;
  126. const int SAFER_ENTRY_DESCRIPTION_WIDTH = 200;
  127. const int SAFER_ENTRY_LAST_MODIFIED_DATE_WIDTH = 200;
  128. ::ZeroMemory (m_ColumnWidths, sizeof (UINT*) * CERTMGR_NUMTYPES);
  129. m_ColumnWidths[CERTMGR_SNAPIN] = new UINT[1];
  130. if ( m_ColumnWidths[CERTMGR_SNAPIN] )
  131. m_ColumnWidths[CERTMGR_SNAPIN][0] = SINGLE_COL_WIDTH;
  132. m_ColumnWidths[CERTMGR_USAGE] = new UINT[CERT_NUM_COLS];
  133. if ( m_ColumnWidths[CERTMGR_USAGE] )
  134. {
  135. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_SUBJECT] = ISSUED_TO_BY_WIDTH; // issued to
  136. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_ISSUER] = ISSUED_TO_BY_WIDTH; // issued by
  137. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_EXPIRATION_DATE] = DATE_WIDTH; // expiration date
  138. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_PURPOSE] = PURPOSE_WIDTH; // purpose
  139. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_CERT_NAME] = FRIENDLY_NAME_WIDTH; // friendly name
  140. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_STATUS] = STATUS_WIDTH; // status
  141. m_ColumnWidths[CERTMGR_USAGE][COLNUM_CERT_TEMPLATE] = TEMPLATE_WIDTH; // template
  142. }
  143. m_ColumnWidths[CERTMGR_PHYS_STORE] = new UINT[1];
  144. if ( m_ColumnWidths[CERTMGR_PHYS_STORE] )
  145. m_ColumnWidths[CERTMGR_PHYS_STORE][0] = SINGLE_COL_WIDTH;
  146. m_ColumnWidths[CERTMGR_LOG_STORE] = new UINT[1];
  147. if ( m_ColumnWidths[CERTMGR_LOG_STORE] )
  148. m_ColumnWidths[CERTMGR_LOG_STORE][0] = SINGLE_COL_WIDTH;
  149. m_ColumnWidths[CERTMGR_CERTIFICATE] = new UINT[1];
  150. if ( m_ColumnWidths[CERTMGR_CERTIFICATE] )
  151. m_ColumnWidths[CERTMGR_CERTIFICATE][0] = SINGLE_COL_WIDTH;
  152. m_ColumnWidths[CERTMGR_CRL_CONTAINER] = new UINT[CRL_NUM_COLS];
  153. if ( m_ColumnWidths[CERTMGR_CRL_CONTAINER] )
  154. {
  155. m_ColumnWidths[CERTMGR_CRL_CONTAINER][0] = ISSUED_TO_BY_WIDTH; // issued by
  156. m_ColumnWidths[CERTMGR_CRL_CONTAINER][1] = DATE_WIDTH; // effective date
  157. m_ColumnWidths[CERTMGR_CRL_CONTAINER][2] = DATE_WIDTH; // next update
  158. }
  159. m_ColumnWidths[CERTMGR_CTL_CONTAINER] = new UINT[CTL_NUM_COLS];
  160. if ( m_ColumnWidths[CERTMGR_CTL_CONTAINER] )
  161. {
  162. m_ColumnWidths[CERTMGR_CTL_CONTAINER][0] = ISSUED_TO_BY_WIDTH; // issued by
  163. m_ColumnWidths[CERTMGR_CTL_CONTAINER][1] = DATE_WIDTH; // effective date
  164. m_ColumnWidths[CERTMGR_CTL_CONTAINER][2] = PURPOSE_WIDTH; // purpose
  165. m_ColumnWidths[CERTMGR_CTL_CONTAINER][3] = FRIENDLY_NAME_WIDTH; // friendly name
  166. }
  167. m_ColumnWidths[CERTMGR_CERT_CONTAINER] = new UINT[CERT_NUM_COLS];
  168. if ( m_ColumnWidths[CERTMGR_CERT_CONTAINER] )
  169. {
  170. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_SUBJECT] = ISSUED_TO_BY_WIDTH; // issued to
  171. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_ISSUER] = ISSUED_TO_BY_WIDTH; // issued by
  172. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_EXPIRATION_DATE] = DATE_WIDTH; // expiration date
  173. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_PURPOSE] = PURPOSE_WIDTH; // purpose
  174. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_CERT_NAME] = FRIENDLY_NAME_WIDTH;// friendly name
  175. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_STATUS] = STATUS_WIDTH; // status
  176. m_ColumnWidths[CERTMGR_CERT_CONTAINER][COLNUM_CERT_TEMPLATE] = TEMPLATE_WIDTH; // template
  177. }
  178. m_ColumnWidths[CERTMGR_CRL] = new UINT[1];
  179. if ( m_ColumnWidths[CERTMGR_CRL] )
  180. m_ColumnWidths[CERTMGR_CRL][0] = SINGLE_COL_WIDTH;
  181. m_ColumnWidths[CERTMGR_CTL] = new UINT[1];
  182. if ( m_ColumnWidths[CERTMGR_CTL] )
  183. m_ColumnWidths[CERTMGR_CTL][0] = SINGLE_COL_WIDTH;
  184. m_ColumnWidths[CERTMGR_LOG_STORE_GPE] = new UINT[1];
  185. if ( m_ColumnWidths[CERTMGR_LOG_STORE_GPE] )
  186. m_ColumnWidths[CERTMGR_LOG_STORE_GPE][0] = SINGLE_COL_WIDTH;
  187. m_ColumnWidths[CERTMGR_LOG_STORE_RSOP] = new UINT[1];
  188. if ( m_ColumnWidths[CERTMGR_LOG_STORE_RSOP] )
  189. m_ColumnWidths[CERTMGR_LOG_STORE_RSOP][0] = SINGLE_COL_WIDTH;
  190. m_ColumnWidths[CERTMGR_AUTO_CERT_REQUEST] = new UINT[1];
  191. if ( m_ColumnWidths[CERTMGR_AUTO_CERT_REQUEST] )
  192. m_ColumnWidths[CERTMGR_AUTO_CERT_REQUEST][0] = SINGLE_COL_WIDTH;
  193. m_ColumnWidths[CERTMGR_CERT_POLICIES_USER] = new UINT[1];
  194. if ( m_ColumnWidths[CERTMGR_CERT_POLICIES_USER] )
  195. m_ColumnWidths[CERTMGR_CERT_POLICIES_USER][0] = SINGLE_COL_WIDTH;
  196. m_ColumnWidths[CERTMGR_CERT_POLICIES_COMPUTER] = new UINT[1];
  197. if ( m_ColumnWidths[CERTMGR_CERT_POLICIES_COMPUTER] )
  198. m_ColumnWidths[CERTMGR_CERT_POLICIES_COMPUTER][0] = SINGLE_COL_WIDTH;
  199. m_ColumnWidths[CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS] = new UINT[1];
  200. if ( m_ColumnWidths[CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS] )
  201. m_ColumnWidths[CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS][0] = SINGLE_COL_WIDTH;
  202. m_ColumnWidths[CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS] = new UINT[1];
  203. if ( m_ColumnWidths[CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS] )
  204. m_ColumnWidths[CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS][0] = SINGLE_COL_WIDTH;
  205. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ROOT] = new UINT[1];
  206. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ROOT] )
  207. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ROOT][0] = SINGLE_COL_WIDTH;
  208. m_ColumnWidths[CERTMGR_SAFER_USER_ROOT] = new UINT[1];
  209. if ( m_ColumnWidths[CERTMGR_SAFER_USER_ROOT] )
  210. m_ColumnWidths[CERTMGR_SAFER_USER_ROOT][0] = SINGLE_COL_WIDTH;
  211. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVELS] = new UINT[SAFER_LEVELS_NUM_COLS];
  212. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVELS] )
  213. {
  214. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVELS][COLNUM_SAFER_LEVEL_NAME] = SAFER_LEVEL_NAME_WIDTH;
  215. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVELS][COLNUM_SAFER_LEVEL_DESCRIPTION] = SAFER_LEVEL_DESCRIPTION_WIDTH;
  216. }
  217. m_ColumnWidths[CERTMGR_SAFER_USER_LEVELS] = new UINT[SAFER_LEVELS_NUM_COLS];
  218. if ( m_ColumnWidths[CERTMGR_SAFER_USER_LEVELS] )
  219. {
  220. m_ColumnWidths[CERTMGR_SAFER_USER_LEVELS][COLNUM_SAFER_LEVEL_NAME] = SAFER_LEVEL_NAME_WIDTH;
  221. m_ColumnWidths[CERTMGR_SAFER_USER_LEVELS][COLNUM_SAFER_LEVEL_DESCRIPTION] = SAFER_LEVEL_DESCRIPTION_WIDTH;
  222. }
  223. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES] = new UINT[SAFER_ENTRIES_NUM_COLS];
  224. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES] )
  225. {
  226. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES][COLNUM_SAFER_ENTRIES_NAME] = SAFER_ENTRY_NAME_WIDTH;
  227. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES][COLNUM_SAFER_ENTRIES_TYPE] = SAFER_ENTRY_TYPE_WIDTH;
  228. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES][COLNUM_SAFER_ENTRIES_LEVEL] = SAFER_ENTRY_LEVEL_WIDTH;
  229. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES][COLNUM_SAFER_ENTRIES_DESCRIPTION] = SAFER_ENTRY_DESCRIPTION_WIDTH;
  230. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRIES][COLNUM_SAFER_ENTRIES_LAST_MODIFIED_DATE] = SAFER_ENTRY_LAST_MODIFIED_DATE_WIDTH;
  231. }
  232. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES] = new UINT[SAFER_ENTRIES_NUM_COLS];
  233. if ( m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES] )
  234. {
  235. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES][COLNUM_SAFER_ENTRIES_NAME] = SAFER_ENTRY_NAME_WIDTH;
  236. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES][COLNUM_SAFER_ENTRIES_TYPE] = SAFER_ENTRY_TYPE_WIDTH;
  237. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES][COLNUM_SAFER_ENTRIES_LEVEL] = SAFER_ENTRY_LEVEL_WIDTH;
  238. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES][COLNUM_SAFER_ENTRIES_DESCRIPTION] = SAFER_ENTRY_DESCRIPTION_WIDTH;
  239. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRIES][COLNUM_SAFER_ENTRIES_LAST_MODIFIED_DATE] = SAFER_ENTRY_LAST_MODIFIED_DATE_WIDTH;
  240. }
  241. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVEL] = new UINT[1];
  242. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVEL] )
  243. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_LEVEL][0] = SINGLE_COL_WIDTH;
  244. m_ColumnWidths[CERTMGR_SAFER_USER_LEVEL] = new UINT[1];
  245. if ( m_ColumnWidths[CERTMGR_SAFER_USER_LEVEL] )
  246. m_ColumnWidths[CERTMGR_SAFER_USER_LEVEL][0] = SINGLE_COL_WIDTH;
  247. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRY] = new UINT[1];
  248. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRY] )
  249. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENTRY][0] = SINGLE_COL_WIDTH;
  250. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRY] = new UINT[1];
  251. if ( m_ColumnWidths[CERTMGR_SAFER_USER_ENTRY] )
  252. m_ColumnWidths[CERTMGR_SAFER_USER_ENTRY][0] = SINGLE_COL_WIDTH;
  253. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS] = new UINT[1];
  254. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS] )
  255. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS][0] = SINGLE_COL_WIDTH;
  256. m_ColumnWidths[CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS] = new UINT[1];
  257. if ( m_ColumnWidths[CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS] )
  258. m_ColumnWidths[CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS][0] = SINGLE_COL_WIDTH;
  259. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES] = new UINT[1];
  260. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES] )
  261. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES][0] = SINGLE_COL_WIDTH;
  262. m_ColumnWidths[CERTMGR_SAFER_USER_DEFINED_FILE_TYPES] = new UINT[1];
  263. if ( m_ColumnWidths[CERTMGR_SAFER_USER_DEFINED_FILE_TYPES] )
  264. m_ColumnWidths[CERTMGR_SAFER_USER_DEFINED_FILE_TYPES][0] = SINGLE_COL_WIDTH;
  265. m_ColumnWidths[CERTMGR_SAFER_USER_ENFORCEMENT] = new UINT[1];
  266. if ( m_ColumnWidths[CERTMGR_SAFER_USER_ENFORCEMENT] )
  267. m_ColumnWidths[CERTMGR_SAFER_USER_ENFORCEMENT][0] = SINGLE_COL_WIDTH;
  268. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENFORCEMENT] = new UINT[1];
  269. if ( m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENFORCEMENT] )
  270. m_ColumnWidths[CERTMGR_SAFER_COMPUTER_ENFORCEMENT][0] = SINGLE_COL_WIDTH;
  271. _TRACE (-1, L"Leaving CCertMgrComponent::CCertMgrComponent\n");
  272. }
  273. CCertMgrComponent::~CCertMgrComponent ()
  274. {
  275. _TRACE (1, L"Entering CCertMgrComponent::~CCertMgrComponent\n");
  276. VERIFY ( SUCCEEDED (ReleaseAll ()) );
  277. CloseAndReleaseUsageStores ();
  278. for (int i = 0; i < CERTMGR_NUMTYPES; i++)
  279. {
  280. if ( m_ColumnWidths[i] )
  281. delete [] m_ColumnWidths[i];
  282. }
  283. if ( m_pLastUsageCookie )
  284. m_pLastUsageCookie->Release ();
  285. if ( m_pToolbar )
  286. m_pToolbar->Release ();
  287. if ( m_pControlbar )
  288. m_pControlbar->Release ();
  289. _TRACE (-1, L"Leaving CCertMgrComponent::~CCertMgrComponent\n");
  290. }
  291. HRESULT CCertMgrComponent::ReleaseAll ()
  292. {
  293. _TRACE (1, L"Entering CCertMgrComponent::ReleaseAll\n");
  294. HRESULT hr = CComponent::ReleaseAll ();
  295. _TRACE (-1, L"Leaving CCertMgrComponent::ReleaseAll: 0x%x\n", hr);
  296. return hr;
  297. }
  298. /////////////////////////////////////////////////////////////////////////////
  299. // IComponent Implementation
  300. HRESULT CCertMgrComponent::LoadStrings ()
  301. {
  302. _TRACE (1, L"Entering CCertMgrComponent::LoadStrings\n");
  303. _TRACE (-1, L"Leaving CCertMgrComponent::LoadStrings\n");
  304. return S_OK;
  305. }
  306. HRESULT CCertMgrComponent::LoadColumns ( CCertMgrCookie* pcookie )
  307. {
  308. _TRACE (1, L"Entering CCertMgrComponent::LoadColumns\n");
  309. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  310. TEST_NONNULL_PTR_PARAM (pcookie);
  311. HRESULT hr = S_OK;
  312. CString str;
  313. switch ( pcookie->m_objecttype )
  314. {
  315. case CERTMGR_SNAPIN:
  316. if ( IDM_STORE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  317. VERIFY (str.LoadString (IDS_COLUMN_LOG_CERTIFICATE_STORE) );
  318. else
  319. VERIFY (str.LoadString (IDS_COLUMN_PURPOSE) );
  320. hr = m_pHeader->InsertColumn (0,
  321. const_cast<LPWSTR> ((LPCWSTR) str), LVCFMT_LEFT, m_ColumnWidths
  322. [CERTMGR_SNAPIN][0]);
  323. break;
  324. case CERTMGR_LOG_STORE:
  325. if ( QueryComponentDataRef ().m_bShowPhysicalStoresPersist )
  326. VERIFY (str.LoadString (IDS_COLUMN_PHYS_CERTIFICATE_STORE) );
  327. else
  328. VERIFY (str.LoadString (IDS_COLUMN_OBJECT_TYPE) );
  329. hr = m_pHeader->InsertColumn (0,
  330. const_cast<LPWSTR> ((LPCWSTR) str), LVCFMT_LEFT,
  331. m_ColumnWidths[CERTMGR_LOG_STORE][0]);
  332. break;
  333. case CERTMGR_LOG_STORE_GPE:
  334. {
  335. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (pcookie);
  336. if ( pStore )
  337. {
  338. switch (pStore->GetStoreType ())
  339. {
  340. case EFS_STORE:
  341. if ( pStore->IsNullEFSPolicy () )
  342. {
  343. VERIFY (str.LoadString (IDS_STATUS));
  344. hr = m_pHeader->InsertColumn (0,
  345. const_cast<LPWSTR> ((LPCWSTR) str), LVCFMT_LEFT,
  346. SINGLE_COL_WIDTH);
  347. }
  348. else
  349. hr = LoadColumnsFromArrays ( (INT) (CERTMGR_CERT_CONTAINER));
  350. break;
  351. case ROOT_STORE:
  352. hr = LoadColumnsFromArrays ( (INT) (CERTMGR_CERT_CONTAINER));
  353. break;
  354. case TRUST_STORE:
  355. hr = LoadColumnsFromArrays ( (INT) (CERTMGR_CTL_CONTAINER));
  356. break;
  357. case ACRS_STORE:
  358. VERIFY (str.LoadString (IDS_COLUMN_AUTO_CERT_REQUEST));
  359. hr = m_pHeader->InsertColumn (0,
  360. const_cast<LPWSTR> ((LPCWSTR) str), LVCFMT_LEFT,
  361. m_ColumnWidths[CERTMGR_AUTO_CERT_REQUEST][0]);
  362. break;
  363. default:
  364. break;
  365. }
  366. }
  367. else
  368. {
  369. _TRACE (0, L"Unexpected error: reinterpret_cast <CCertStoreGPE*> (pcookie) failed.\n");
  370. hr = E_UNEXPECTED;
  371. }
  372. }
  373. break;
  374. case CERTMGR_LOG_STORE_RSOP:
  375. {
  376. CCertStoreRSOP* pStore = reinterpret_cast <CCertStoreRSOP*> (pcookie);
  377. if ( pStore )
  378. {
  379. switch (pStore->GetStoreType ())
  380. {
  381. case EFS_STORE:
  382. if ( pStore->IsNullEFSPolicy () )
  383. {
  384. VERIFY (str.LoadString (IDS_STATUS));
  385. hr = m_pHeader->InsertColumn (0,
  386. const_cast<LPWSTR> ((LPCWSTR) str), LVCFMT_LEFT,
  387. SINGLE_COL_WIDTH);
  388. }
  389. else
  390. hr = LoadColumnsFromArrays ( (INT) (CERTMGR_CERT_CONTAINER));
  391. break;
  392. case ROOT_STORE:
  393. hr = LoadColumnsFromArrays ( (INT) (CERTMGR_CERT_CONTAINER));
  394. break;
  395. case TRUST_STORE:
  396. hr = LoadColumnsFromArrays ( (INT) (CERTMGR_CTL_CONTAINER));
  397. break;
  398. case ACRS_STORE:
  399. VERIFY (str.LoadString (IDS_COLUMN_AUTO_CERT_REQUEST));
  400. hr = m_pHeader->InsertColumn (0,
  401. const_cast<LPWSTR> ((LPCWSTR) str), LVCFMT_LEFT,
  402. m_ColumnWidths[CERTMGR_AUTO_CERT_REQUEST][0]);
  403. break;
  404. default:
  405. break;
  406. }
  407. }
  408. else
  409. {
  410. _TRACE (0, L"Unexpected error: reinterpret_cast <CCertStoreGPE*> (pcookie) failed.\n");
  411. hr = E_UNEXPECTED;
  412. }
  413. }
  414. break;
  415. default:
  416. hr = LoadColumnsFromArrays ( (INT) (pcookie->m_objecttype));
  417. break;
  418. }
  419. _TRACE (-1, L"Leaving CCertMgrComponent::LoadColumns: 0x%x\n", hr);
  420. return hr;
  421. }
  422. /* This is generated by UpdateAllViews () */
  423. HRESULT CCertMgrComponent::OnViewChange (LPDATAOBJECT pDataObject, LPARAM /*data*/, LPARAM hint)
  424. {
  425. _TRACE (1, L"Entering CCertMgrComponent::OnViewChange\n");
  426. HRESULT hr = S_OK;
  427. if ( pDataObject )
  428. {
  429. if ( HINT_CERT_ENROLLED_USAGE_MODE & hint )
  430. {
  431. // Force reenumeration of usage stores
  432. m_bUsageStoresEnumerated = false;
  433. }
  434. if ( (HINT_CHANGE_VIEW_TYPE & hint) ||
  435. (HINT_CHANGE_STORE_TYPE & hint) ||
  436. (HINT_SHOW_ARCHIVE_CERTS & hint) ||
  437. (HINT_CHANGE_COMPUTER & hint) ||
  438. (HINT_REFRESH_STORES & hint) )
  439. {
  440. hr = QueryComponentDataRef ().RefreshScopePane (0);
  441. }
  442. else if ( HINT_EFS_ADD_DEL_POLICY & hint )
  443. {
  444. // Delete existing columns and add new columns
  445. if ( m_pResultData )
  446. {
  447. m_pResultData->DeleteAllRsltItems ();
  448. }
  449. else
  450. {
  451. _TRACE (0, L"Unexpected error: m_pResultData was NULL\n");
  452. }
  453. do {
  454. hr = m_pHeader->DeleteColumn (0);
  455. } while ( SUCCEEDED (hr) );
  456. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  457. if ( pCookie )
  458. hr = LoadColumns (pCookie);
  459. else
  460. {
  461. _TRACE (0, L"Unexpected error: ConvertCookie () returned NULL\n");
  462. hr = E_UNEXPECTED;
  463. }
  464. }
  465. else if ( (HINT_PASTE_COOKIE & hint) ||
  466. (HINT_IMPORT & hint) )
  467. {
  468. // Do nothing
  469. }
  470. else
  471. {
  472. hr = QueryComponentDataRef ().RefreshScopePane (pDataObject);
  473. if ( IDM_USAGE_VIEW == QueryComponentDataRef ().m_activeViewPersist &&
  474. m_pLastUsageCookie)
  475. {
  476. hr = DisplayCertificateCountByUsage (
  477. m_pLastUsageCookie->GetObjectName (),
  478. m_pLastUsageCookie->GetCertCount ());
  479. }
  480. }
  481. if ( SUCCEEDED (hr) )
  482. {
  483. hr = RefreshResultPane ();
  484. }
  485. CCertMgrComponentData& compData = QueryComponentDataRef ();
  486. CCertMgrCookie* pCookie = compData.ConvertCookie (pDataObject);
  487. if ( pCookie )
  488. {
  489. switch (pCookie->m_objecttype)
  490. {
  491. case CERTMGR_CERTIFICATE:
  492. {
  493. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  494. if ( pCert )
  495. {
  496. if ( IDM_STORE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  497. {
  498. hr = DisplayCertificateCountByStore (m_pConsole,
  499. pCert->GetCertStore ());
  500. }
  501. else
  502. {
  503. ASSERT (m_pLastUsageCookie);
  504. if ( m_pLastUsageCookie )
  505. {
  506. hr = DisplayCertificateCountByUsage (
  507. m_pLastUsageCookie->GetObjectName (),
  508. m_pLastUsageCookie->GetCertCount ());
  509. }
  510. }
  511. }
  512. }
  513. break;
  514. case CERTMGR_LOG_STORE:
  515. case CERTMGR_PHYS_STORE:
  516. case CERTMGR_LOG_STORE_GPE:
  517. case CERTMGR_LOG_STORE_RSOP:
  518. {
  519. CCertStore* pStore = reinterpret_cast <CCertStore*> (pCookie);
  520. if ( pStore )
  521. {
  522. pStore->GetStoreHandle (); // to initialize read-only flag
  523. if ( pStore->IsReadOnly () )
  524. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  525. else
  526. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  527. hr = DisplayCertificateCountByStore (m_pConsole, pStore,
  528. (CERTMGR_LOG_STORE_GPE == pCookie->m_objecttype ||
  529. CERTMGR_LOG_STORE_RSOP == pCookie->m_objecttype));
  530. pStore->Close ();
  531. }
  532. else
  533. hr = E_UNEXPECTED;
  534. }
  535. break;
  536. case CERTMGR_USAGE:
  537. {
  538. CUsageCookie* pUsage = reinterpret_cast <CUsageCookie*> (pCookie);
  539. if ( pUsage )
  540. {
  541. hr = DisplayCertificateCountByUsage (pCookie->GetObjectName (),
  542. pUsage->GetCertCount ());
  543. }
  544. else
  545. hr = E_UNEXPECTED;
  546. }
  547. break;
  548. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  549. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  550. ASSERT (0);
  551. break;
  552. case CERTMGR_SNAPIN:
  553. case CERTMGR_CRL_CONTAINER:
  554. case CERTMGR_CTL_CONTAINER:
  555. case CERTMGR_CERT_CONTAINER:
  556. case CERTMGR_CRL:
  557. case CERTMGR_CTL:
  558. case CERTMGR_AUTO_CERT_REQUEST:
  559. case CERTMGR_CERT_POLICIES_USER:
  560. case CERTMGR_CERT_POLICIES_COMPUTER:
  561. default:
  562. {
  563. IConsole2* pConsole2 = 0;
  564. hr = m_pConsole->QueryInterface (
  565. IID_PPV_ARG(IConsole2, &pConsole2));
  566. if (SUCCEEDED (hr))
  567. {
  568. hr = pConsole2->SetStatusText (L"");
  569. if ( !SUCCEEDED (hr) )
  570. {
  571. _TRACE (0, L"IConsole2::SetStatusText () failed: %x", hr);
  572. }
  573. pConsole2->Release ();
  574. }
  575. }
  576. break;
  577. }
  578. }
  579. }
  580. else
  581. {
  582. hr = E_POINTER;
  583. _TRACE (0, L"Unexpected error: paramater pDataObject was NULL\n");
  584. }
  585. _TRACE (-1, L"Leaving CCertMgrComponent::OnViewChange: 0x%x\n", hr);
  586. return hr;
  587. }
  588. HRESULT CCertMgrComponent::Show ( CCookie* pcookie, LPARAM arg, HSCOPEITEM /*hScopeItem*/, LPDATAOBJECT /*pDataObject*/)
  589. {
  590. _TRACE (1, L"Entering CCertMgrComponent::Show\n");
  591. HRESULT hr = S_OK;
  592. TEST_NONNULL_PTR_PARAM (pcookie);
  593. if ( !arg )
  594. {
  595. if ( !m_pResultData )
  596. {
  597. _TRACE (0, L"Unexpected error: m_pResultData was NULL\n");
  598. return E_UNEXPECTED;
  599. }
  600. m_pViewedCookie = reinterpret_cast <CCertMgrCookie*> (pcookie);
  601. if ( m_pViewedCookie )
  602. hr = SaveWidths (m_pViewedCookie);
  603. m_pViewedCookie = 0;
  604. return S_OK;
  605. }
  606. if ( m_pResultData )
  607. {
  608. m_pResultData->ModifyViewStyle (MMC_ENSUREFOCUSVISIBLE,
  609. (MMC_RESULT_VIEW_STYLE) 0);
  610. }
  611. m_pViewedCookie = reinterpret_cast <CCertMgrCookie*> (pcookie);
  612. if ( m_pViewedCookie )
  613. {
  614. // Load default columns and widths
  615. LoadColumns (m_pViewedCookie);
  616. // Restore persisted column widths
  617. switch (m_pViewedCookie->m_objecttype)
  618. {
  619. case CERTMGR_SNAPIN:
  620. case CERTMGR_USAGE:
  621. case CERTMGR_PHYS_STORE:
  622. case CERTMGR_LOG_STORE:
  623. case CERTMGR_CRL_CONTAINER:
  624. case CERTMGR_CTL_CONTAINER:
  625. case CERTMGR_CERT_CONTAINER:
  626. case CERTMGR_LOG_STORE_GPE:
  627. case CERTMGR_LOG_STORE_RSOP:
  628. case CERTMGR_CERT_POLICIES_USER:
  629. case CERTMGR_CERT_POLICIES_COMPUTER:
  630. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  631. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  632. break;
  633. case CERTMGR_CERTIFICATE:
  634. case CERTMGR_CRL:
  635. case CERTMGR_CTL:
  636. case CERTMGR_AUTO_CERT_REQUEST:
  637. default:
  638. _TRACE (0, L"Invalid or unexpected m_objecttype in switch: 0x%x\n", m_pViewedCookie->m_objecttype);
  639. break;
  640. }
  641. hr = PopulateListbox (m_pViewedCookie);
  642. }
  643. _TRACE (-1, L"Leaving CCertMgrComponent::Show: 0x%x\n", hr);
  644. return hr;
  645. }
  646. HRESULT CCertMgrComponent::Show ( CCookie* pcookie, LPARAM arg, HSCOPEITEM hScopeItem)
  647. {
  648. _TRACE (1, L"Entering CCertMgrComponent::Show\n");
  649. _TRACE (0, L"Unexpected: We should never enter this method.\n");
  650. _TRACE (-1, L"Leaving CCertMgrComponent::Show\n");
  651. return Show (pcookie, arg, hScopeItem, 0);
  652. }
  653. HRESULT CCertMgrComponent::OnNotifyAddImages (
  654. LPDATAOBJECT /*pDataObject*/,
  655. LPIMAGELIST lpImageList,
  656. HSCOPEITEM /*hSelectedItem*/)
  657. {
  658. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyAddImages\n");
  659. long lViewMode = 0;
  660. HRESULT hr = S_OK;
  661. if ( m_pResultData )
  662. {
  663. QueryComponentDataRef ().SetResultData (m_pResultData);
  664. hr = m_pResultData->GetViewMode (&lViewMode);
  665. if ( SUCCEEDED (hr) )
  666. {
  667. BOOL bLoadLargeIcons = (LVS_ICON == lViewMode);
  668. hr = QueryComponentDataRef ().LoadIcons (lpImageList, bLoadLargeIcons);
  669. }
  670. }
  671. else
  672. {
  673. _TRACE (0, L"Unexpected error: m_pResultData is NULL\n");
  674. hr = E_UNEXPECTED;
  675. }
  676. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyAddImages: 0x%x\n", hr);
  677. return hr;
  678. }
  679. HRESULT CCertMgrComponent::EnumCertificates (CCertStore& rCertStore)
  680. {
  681. _TRACE (1, L"Entering CCertMgrComponent::EnumCertificates\n");
  682. CWaitCursor cursor;
  683. PCCERT_CONTEXT pCertContext = 0;
  684. HRESULT hr = 0;
  685. CCertificate* pCert = 0;
  686. RESULTDATAITEM rdItem;
  687. CCookie& rootCookie = QueryComponentDataRef ().QueryBaseRootCookie ();
  688. ::ZeroMemory (&rdItem, sizeof (rdItem));
  689. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  690. rdItem.nImage = iIconCertificate;
  691. rdItem.nCol = 0;
  692. rdItem.str = MMC_TEXTCALLBACK;
  693. // Iterate through the list of certificates in the system store,
  694. // allocate new certificates with the CERT_CONTEXT returned,
  695. // and store them in the certificate list.
  696. while ( 1 )
  697. {
  698. pCertContext = rCertStore.EnumCertificates (pCertContext);
  699. if ( !pCertContext )
  700. {
  701. if ( EFS_STORE == rCertStore.GetStoreType () )
  702. {
  703. if ( rCertStore.IsNullEFSPolicy () )
  704. {
  705. CString name;
  706. VERIFY (name.LoadString (IDS_NO_POLICY_DEFINED));
  707. CCertMgrCookie* pNewCookie = new CCertMgrCookie (
  708. CERTMGR_NULL_POLICY, 0, (LPCWSTR) name);
  709. if ( pNewCookie )
  710. {
  711. rootCookie.m_listResultCookieBlocks.AddHead (pNewCookie);
  712. ::ZeroMemory (&rdItem, sizeof (rdItem));
  713. rdItem.mask = RDI_STR | RDI_PARAM;
  714. rdItem.str = MMC_TEXTCALLBACK;
  715. rdItem.lParam = (LPARAM) pNewCookie;
  716. pNewCookie->m_resultDataID = m_pResultData;
  717. hr = m_pResultData->InsertItem (&rdItem);
  718. }
  719. else
  720. {
  721. hr = E_OUTOFMEMORY;
  722. break;
  723. }
  724. }
  725. }
  726. break;
  727. }
  728. pCert =
  729. new CCertificate (pCertContext, &rCertStore);
  730. if ( !pCert )
  731. {
  732. hr = E_OUTOFMEMORY;
  733. break;
  734. }
  735. rootCookie.m_listResultCookieBlocks.AddHead (pCert);
  736. rdItem.lParam = (LPARAM) pCert;
  737. pCert->m_resultDataID = m_pResultData;
  738. hr = m_pResultData->InsertItem (&rdItem);
  739. if ( FAILED (hr) )
  740. {
  741. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  742. }
  743. }
  744. rCertStore.Close ();
  745. _TRACE (-1, L"Leaving CCertMgrComponent::EnumCertificates: 0x%x\n", hr);
  746. return hr;
  747. }
  748. HRESULT CCertMgrComponent::PopulateListbox (CCertMgrCookie* pCookie)
  749. {
  750. _TRACE (1, L"Entering CCertMgrComponent::PopulateListbox\n");
  751. if ( !pCookie )
  752. return E_POINTER;
  753. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  754. HRESULT hr = S_OK;
  755. CWaitCursor cursor;
  756. CCertMgrComponentData& dataRef = QueryComponentDataRef ();
  757. switch ( pCookie->m_objecttype )
  758. {
  759. case CERTMGR_PHYS_STORE:
  760. case CERTMGR_LOG_STORE:
  761. break;
  762. case CERTMGR_LOG_STORE_GPE:
  763. case CERTMGR_LOG_STORE_RSOP:
  764. {
  765. CCertStore* pStore = reinterpret_cast <CCertStore*> (pCookie);
  766. if ( pStore )
  767. {
  768. switch (pStore->GetStoreType () )
  769. {
  770. case EFS_STORE:
  771. case ROOT_STORE:
  772. hr = EnumCertificates (*pStore);
  773. if ( SUCCEEDED (hr) )
  774. {
  775. m_currResultNodeType = CERTMGR_CERTIFICATE;
  776. m_pResultData->Sort (m_nSelectedCertColumn, 0,
  777. (long) m_currResultNodeType);
  778. }
  779. break;
  780. case ACRS_STORE:
  781. hr = EnumCTLs (*pStore);
  782. if ( SUCCEEDED (hr) )
  783. {
  784. m_currResultNodeType = CERTMGR_AUTO_CERT_REQUEST;
  785. m_pResultData->Sort (m_nSelectedCTLColumn, 0,
  786. (long) m_currResultNodeType);
  787. }
  788. break;
  789. case TRUST_STORE:
  790. hr = EnumCTLs (*pStore);
  791. if ( SUCCEEDED (hr) )
  792. {
  793. m_currResultNodeType = CERTMGR_CTL;
  794. m_pResultData->Sort (m_nSelectedCTLColumn, 0,
  795. (long) m_currResultNodeType);
  796. }
  797. break;
  798. default:
  799. _TRACE (0, L"Error: Unexpected store type: 0x%x\n", pStore->GetStoreType ());
  800. hr = E_UNEXPECTED;
  801. break;
  802. }
  803. if ( SUCCEEDED (hr) )
  804. hr = DisplayCertificateCountByStore (m_pConsole, pStore, true);
  805. }
  806. else
  807. hr = E_POINTER;
  808. }
  809. break;
  810. case CERTMGR_CERT_CONTAINER:
  811. {
  812. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pCookie);
  813. if ( pContainer )
  814. {
  815. hr = EnumCertificates (pContainer->GetCertStore ());
  816. if ( SUCCEEDED (hr) )
  817. {
  818. m_currResultNodeType = CERTMGR_CERTIFICATE;
  819. m_pResultData->Sort (m_nSelectedCertColumn, 0,
  820. (long) m_currResultNodeType);
  821. hr = DisplayCertificateCountByStore (m_pConsole, &pContainer->GetCertStore (), false);
  822. }
  823. }
  824. }
  825. break;
  826. case CERTMGR_USAGE:
  827. {
  828. CUsageCookie* pUsageCookie = reinterpret_cast <CUsageCookie*> (pCookie);
  829. if ( pUsageCookie )
  830. {
  831. hr = EnumCertsByUsage (pUsageCookie);
  832. if ( SUCCEEDED (hr) )
  833. {
  834. m_currResultNodeType = CERTMGR_CERTIFICATE;
  835. m_pResultData->Sort (m_nSelectedCertColumn, 0,
  836. (long) m_currResultNodeType);
  837. }
  838. }
  839. }
  840. break;
  841. case CERTMGR_CRL_CONTAINER:
  842. {
  843. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pCookie);
  844. if ( pContainer )
  845. {
  846. PCCRL_CONTEXT pCRLContext = 0;
  847. CCRL* pCRL = 0;
  848. RESULTDATAITEM rdItem;
  849. CCookie& rootCookie = dataRef.QueryBaseRootCookie ();
  850. ::ZeroMemory (&rdItem, sizeof (rdItem));
  851. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  852. rdItem.nImage = iIconCRL;
  853. rdItem.nCol = 0;
  854. // Iterate through the list of certificates in the system store,
  855. // allocate new certificates with the CERT_CONTEXT returned,
  856. // and store them in the certificate list.
  857. DWORD dwFlags = 0;
  858. while ( 1 )
  859. {
  860. pCRLContext = pContainer->GetCertStore ().GetCRL (NULL,
  861. pCRLContext, &dwFlags);
  862. if ( !pCRLContext )
  863. break;
  864. pCRL =
  865. new CCRL (pCRLContext, pContainer->GetCertStore ());
  866. if ( !pCRL )
  867. {
  868. hr = E_OUTOFMEMORY;
  869. break;
  870. }
  871. rootCookie.m_listResultCookieBlocks.AddHead (pCRL);
  872. rdItem.str = MMC_TEXTCALLBACK;
  873. rdItem.lParam = (LPARAM) pCRL;
  874. pCRL->m_resultDataID = m_pResultData;
  875. hr = m_pResultData->InsertItem (&rdItem);
  876. if ( FAILED (hr) )
  877. {
  878. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  879. }
  880. }
  881. if ( SUCCEEDED (hr) )
  882. {
  883. m_currResultNodeType = CERTMGR_CRL;
  884. m_pResultData->Sort (m_nSelectedCRLColumn, 0,
  885. (long) m_currResultNodeType);
  886. }
  887. }
  888. }
  889. break;
  890. case CERTMGR_CTL_CONTAINER:
  891. {
  892. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pCookie);
  893. if ( pContainer )
  894. {
  895. hr = EnumCTLs (pContainer->GetCertStore ());
  896. if ( SUCCEEDED (hr) )
  897. {
  898. m_currResultNodeType = CERTMGR_CTL;
  899. m_pResultData->Sort (m_nSelectedCTLColumn, 0,
  900. (long) m_currResultNodeType);
  901. hr = DisplayCertificateCountByStore (m_pConsole, &pContainer->GetCertStore (), false);
  902. }
  903. }
  904. }
  905. break;
  906. case CERTMGR_CERT_POLICIES_USER:
  907. case CERTMGR_CERT_POLICIES_COMPUTER:
  908. // Only this node if machine is joined to a Whistler or later domain
  909. if ( !dataRef.m_bMachineIsStandAlone && !g_bSchemaIsW2K )
  910. {
  911. RESULTDATAITEM rdItem;
  912. CCookie& rootCookie = dataRef.QueryBaseRootCookie ();
  913. ::ZeroMemory (&rdItem, sizeof (rdItem));
  914. rdItem.mask = RDI_STR | RDI_PARAM | RDI_IMAGE;
  915. rdItem.nImage = iIconAutoEnroll;
  916. rdItem.nCol = 0;
  917. CString objectName;
  918. VERIFY (objectName.LoadString (IDS_PKP_AUTOENROLLMENT_SETTINGS));
  919. CCertMgrCookie* pNewCookie = new CCertMgrCookie (
  920. CERTMGR_CERT_POLICIES_COMPUTER == pCookie->m_objecttype ?
  921. CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS :
  922. CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS,
  923. pCookie->QueryNonNULLMachineName (),
  924. objectName);
  925. if ( !pNewCookie )
  926. {
  927. hr = E_OUTOFMEMORY;
  928. break;
  929. }
  930. rootCookie.m_listResultCookieBlocks.AddHead (pNewCookie);
  931. rdItem.str = MMC_TEXTCALLBACK ;
  932. rdItem.lParam = (LPARAM) pNewCookie;
  933. pNewCookie->m_resultDataID = m_pResultData;
  934. hr = m_pResultData->InsertItem (&rdItem);
  935. if ( FAILED (hr) )
  936. {
  937. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  938. }
  939. }
  940. break;
  941. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  942. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  943. ASSERT (0);
  944. break;
  945. case CERTMGR_SAFER_COMPUTER_LEVELS:
  946. {
  947. CPolicyKey policyKey (dataRef.m_pGPEInformation,
  948. SAFER_HKLM_REGBASE, true);
  949. hr = AddSaferLevels (true,
  950. pCookie->QueryNonNULLMachineName (), policyKey.GetKey ());
  951. }
  952. break;
  953. case CERTMGR_SAFER_USER_LEVELS:
  954. {
  955. CPolicyKey policyKey (dataRef.m_pGPEInformation,
  956. SAFER_HKLM_REGBASE, false);
  957. hr = AddSaferLevels (false,
  958. pCookie->QueryNonNULLMachineName (), policyKey.GetKey ());
  959. }
  960. break;
  961. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  962. case CERTMGR_SAFER_USER_ENTRIES:
  963. {
  964. CSaferEntries* pSaferEntries = dynamic_cast <CSaferEntries*> (pCookie);
  965. if ( pSaferEntries )
  966. {
  967. hr = SaferEnumerateEntries (
  968. CERTMGR_SAFER_COMPUTER_ENTRIES == pCookie->m_objecttype,
  969. pSaferEntries);
  970. if (SUCCEEDED (hr) )
  971. m_pResultData->Sort (m_nSelectedCertColumn, 0,
  972. (long) m_currResultNodeType);
  973. }
  974. }
  975. break;
  976. case CERTMGR_SAFER_COMPUTER_ROOT:
  977. case CERTMGR_SAFER_USER_ROOT:
  978. {
  979. CSaferRootCookie* pSaferRootCookie = dynamic_cast <CSaferRootCookie*> (pCookie);
  980. if ( pSaferRootCookie )
  981. {
  982. if ( (pSaferRootCookie->m_bCreateSaferNodes && dataRef.m_bSaferSupported)
  983. || dataRef.m_bIsRSOP )
  984. {
  985. RESULTDATAITEM rdItem;
  986. CCookie& rootCookie = dataRef.QueryBaseRootCookie ();
  987. ::ZeroMemory (&rdItem, sizeof (rdItem));
  988. rdItem.mask = RDI_STR | RDI_PARAM | RDI_IMAGE;
  989. rdItem.nImage = iIconSettings;
  990. rdItem.nCol = 0;
  991. CString objectName;
  992. CCertMgrCookie* pNewCookie = 0;
  993. if ( SUCCEEDED (hr) )
  994. {
  995. VERIFY (objectName.LoadString (IDS_SAFER_ENFORCEMENT));
  996. pNewCookie = new CCertMgrCookie (
  997. CERTMGR_SAFER_COMPUTER_ROOT == pCookie->m_objecttype ?
  998. CERTMGR_SAFER_COMPUTER_ENFORCEMENT :
  999. CERTMGR_SAFER_USER_ENFORCEMENT,
  1000. pCookie->QueryNonNULLMachineName (),
  1001. objectName);
  1002. if ( !pNewCookie )
  1003. {
  1004. hr = E_OUTOFMEMORY;
  1005. break;
  1006. }
  1007. rootCookie.m_listResultCookieBlocks.AddHead (pNewCookie);
  1008. rdItem.str = MMC_TEXTCALLBACK ;
  1009. rdItem.lParam = (LPARAM) pNewCookie;
  1010. pNewCookie->m_resultDataID = m_pResultData;
  1011. hr = m_pResultData->InsertItem (&rdItem);
  1012. if ( FAILED (hr) )
  1013. {
  1014. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  1015. }
  1016. }
  1017. if ( SUCCEEDED (hr) )
  1018. {
  1019. VERIFY (objectName.LoadString (IDS_SAFER_DEFINED_FILE_TYPES));
  1020. pNewCookie = new CCertMgrCookie (
  1021. CERTMGR_SAFER_COMPUTER_ROOT == pCookie->m_objecttype ?
  1022. CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES :
  1023. CERTMGR_SAFER_USER_DEFINED_FILE_TYPES,
  1024. pCookie->QueryNonNULLMachineName (),
  1025. objectName);
  1026. if ( !pNewCookie )
  1027. {
  1028. hr = E_OUTOFMEMORY;
  1029. break;
  1030. }
  1031. rootCookie.m_listResultCookieBlocks.AddHead (pNewCookie);
  1032. rdItem.str = MMC_TEXTCALLBACK ;
  1033. rdItem.lParam = (LPARAM) pNewCookie;
  1034. pNewCookie->m_resultDataID = m_pResultData;
  1035. hr = m_pResultData->InsertItem (&rdItem);
  1036. if ( FAILED (hr) )
  1037. {
  1038. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  1039. }
  1040. }
  1041. if ( SUCCEEDED (hr) )
  1042. {
  1043. VERIFY (objectName.LoadString (IDS_SAFER_TRUSTED_PUBLISHERS));
  1044. pNewCookie = new CCertMgrCookie (
  1045. CERTMGR_SAFER_COMPUTER_ROOT == pCookie->m_objecttype ?
  1046. CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS :
  1047. CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS,
  1048. pCookie->QueryNonNULLMachineName (),
  1049. objectName);
  1050. if ( !pNewCookie )
  1051. {
  1052. hr = E_OUTOFMEMORY;
  1053. break;
  1054. }
  1055. rootCookie.m_listResultCookieBlocks.AddHead (pNewCookie);
  1056. rdItem.str = MMC_TEXTCALLBACK ;
  1057. rdItem.lParam = (LPARAM) pNewCookie;
  1058. pNewCookie->m_resultDataID = m_pResultData;
  1059. hr = m_pResultData->InsertItem (&rdItem);
  1060. if ( FAILED (hr) )
  1061. {
  1062. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  1063. }
  1064. }
  1065. }
  1066. else
  1067. {
  1068. CComPtr<IUnknown> spUnknown;
  1069. hr = m_pConsole->QueryResultView(&spUnknown);
  1070. if ( SUCCEEDED (hr) )
  1071. {
  1072. CComPtr<IMessageView> spMessageView;
  1073. hr = spUnknown->QueryInterface (IID_PPV_ARG (IMessageView, &spMessageView));
  1074. if (SUCCEEDED(hr))
  1075. {
  1076. CString szTitle;
  1077. CString szMessage;
  1078. VERIFY (szTitle.LoadString (IDS_SAFER_NO_POLICY_TITLE));
  1079. VERIFY (szMessage.LoadString (IDS_SAFER_NO_POLICY_TEXT));
  1080. spMessageView->SetTitleText (szTitle);
  1081. spMessageView->SetBodyText (szMessage);
  1082. spMessageView->SetIcon (Icon_Warning);
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. break;
  1089. default:
  1090. break;
  1091. }
  1092. _TRACE (-1, L"Leaving CCertMgrComponent::PopulateListbox: 0x%x\n", hr);
  1093. return hr;
  1094. }
  1095. HRESULT CCertMgrComponent::RefreshResultPane ()
  1096. {
  1097. _TRACE (1, L"Entering CCertMgrComponent::RefreshResultPane\n");
  1098. HRESULT hr = S_OK;
  1099. if ( m_pResultData )
  1100. {
  1101. // Does this return E_UNEXPECTED when there are no items?
  1102. HRESULT hr1 = m_pResultData->DeleteAllRsltItems ();
  1103. if ( FAILED (hr1) )
  1104. {
  1105. _TRACE (0, L"IResultData::DeleteAllRsltItems () failed: 0x%x\n", hr1);
  1106. }
  1107. }
  1108. else
  1109. {
  1110. _TRACE (0, L"Unexpected error: m_pResultData is NULL\n");
  1111. hr = E_UNEXPECTED;
  1112. }
  1113. if ( m_pViewedCookie )
  1114. {
  1115. hr = PopulateListbox (m_pViewedCookie);
  1116. }
  1117. _TRACE (-1, L"Leaving CCertMgrComponent::RefreshResultPane: 0x%x\n", hr);
  1118. return hr;
  1119. }
  1120. STDMETHODIMP CCertMgrComponent::GetDisplayInfo (RESULTDATAITEM * pResult)
  1121. {
  1122. // _TRACE (1, L"Entering CCertMgrComponent::GetDisplayInfo\n");
  1123. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  1124. HRESULT hr = S_OK;
  1125. if ( pResult && !pResult->bScopeItem ) //&& (pResult->mask & RDI_PARAM) )
  1126. {
  1127. CCookie* pResultCookie = reinterpret_cast<CCookie*> (pResult->lParam);
  1128. ASSERT (pResultCookie);
  1129. if ( !pResultCookie || IsBadWritePtr ((LPVOID) pResultCookie, sizeof (CCookie)) )
  1130. return E_UNEXPECTED;
  1131. CCookie* pActiveCookie = ActiveBaseCookie (pResultCookie);
  1132. ASSERT (pActiveCookie);
  1133. if ( !pActiveCookie || IsBadWritePtr ((LPVOID) pActiveCookie, sizeof (CCookie)) )
  1134. return E_UNEXPECTED;
  1135. CCertMgrCookie* pCookie = reinterpret_cast <CCertMgrCookie*>(pActiveCookie);
  1136. ASSERT (pCookie);
  1137. switch (pCookie->m_objecttype)
  1138. {
  1139. case CERTMGR_SAFER_COMPUTER_LEVELS:
  1140. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  1141. case CERTMGR_SAFER_USER_LEVELS:
  1142. case CERTMGR_SAFER_USER_ENTRIES:
  1143. // iIconSaferHashEntry
  1144. // iIconSaferURLEntry
  1145. // iIconSaferNameEntry
  1146. ASSERT (0);
  1147. break;
  1148. case CERTMGR_SAFER_COMPUTER_LEVEL:
  1149. case CERTMGR_SAFER_USER_LEVEL:
  1150. if (pResult->mask & RDI_STR)
  1151. {
  1152. if ( COLNUM_SAFER_LEVEL_NAME == pResult->nCol )
  1153. {
  1154. m_szDisplayInfoResult = pCookie->GetObjectName ();
  1155. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1156. }
  1157. else if ( COLNUM_SAFER_LEVEL_DESCRIPTION == pResult->nCol )
  1158. {
  1159. CSaferLevel* pLevel = dynamic_cast <CSaferLevel*> (pCookie);
  1160. if ( pLevel )
  1161. {
  1162. m_szDisplayInfoResult = pLevel->GetDescription ();
  1163. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1164. }
  1165. }
  1166. }
  1167. if ( pResult->mask & RDI_IMAGE )
  1168. {
  1169. CSaferLevel* pLevel = dynamic_cast <CSaferLevel*> (pCookie);
  1170. if ( pLevel && pLevel->IsDefault () )
  1171. {
  1172. QueryComponentDataRef ().m_dwDefaultSaferLevel =
  1173. pLevel->GetLevel ();
  1174. pResult->nImage = iIconDefaultSaferLevel;
  1175. }
  1176. else
  1177. pResult->nImage = iIconSaferLevel;
  1178. }
  1179. break;
  1180. case CERTMGR_SAFER_COMPUTER_ENTRY:
  1181. case CERTMGR_SAFER_USER_ENTRY:
  1182. if (pResult->mask & RDI_STR)
  1183. {
  1184. CSaferEntry* pSaferEntry = dynamic_cast <CSaferEntry*> (pCookie);
  1185. if ( pSaferEntry )
  1186. {
  1187. switch (pResult->nCol)
  1188. {
  1189. case COLNUM_SAFER_ENTRIES_NAME:
  1190. m_szDisplayInfoResult = pSaferEntry->GetDisplayName ();
  1191. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1192. break;
  1193. case COLNUM_SAFER_ENTRIES_TYPE:
  1194. m_szDisplayInfoResult = pSaferEntry->GetTypeString ();
  1195. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1196. break;
  1197. case COLNUM_SAFER_ENTRIES_LEVEL:
  1198. m_szDisplayInfoResult = pSaferEntry->GetLevelFriendlyName ();
  1199. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1200. break;
  1201. case COLNUM_SAFER_ENTRIES_DESCRIPTION:
  1202. m_szDisplayInfoResult = pSaferEntry->GetDescription ();
  1203. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1204. break;
  1205. case COLNUM_SAFER_ENTRIES_LAST_MODIFIED_DATE:
  1206. m_szDisplayInfoResult = pSaferEntry->GetShortLastModified ();
  1207. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1208. break;
  1209. default:
  1210. ASSERT (0);
  1211. break;
  1212. }
  1213. }
  1214. }
  1215. if ( pResult->mask & RDI_IMAGE )
  1216. {
  1217. CSaferEntry* pEntry = dynamic_cast <CSaferEntry*> (pCookie);
  1218. if ( pEntry )
  1219. {
  1220. switch (pEntry->GetType () )
  1221. {
  1222. case SAFER_ENTRY_TYPE_HASH:
  1223. pResult->nImage = iIconSaferHashEntry;
  1224. break;
  1225. case SAFER_ENTRY_TYPE_PATH:
  1226. pResult->nImage = iIconSaferNameEntry;
  1227. break;
  1228. case SAFER_ENTRY_TYPE_URLZONE:
  1229. pResult->nImage = iIconSaferURLEntry;
  1230. break;
  1231. case SAFER_ENTRY_TYPE_CERT:
  1232. pResult->nImage = iIconSaferCertEntry;
  1233. break;
  1234. default:
  1235. ASSERT (0);
  1236. break;
  1237. }
  1238. }
  1239. }
  1240. break;
  1241. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  1242. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  1243. if (pResult->mask & RDI_STR)
  1244. {
  1245. if ( 0 == pResult->nCol )
  1246. {
  1247. m_szDisplayInfoResult = pCookie->GetObjectName ();
  1248. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1249. }
  1250. }
  1251. if (pResult->mask & RDI_IMAGE)
  1252. pResult->nImage = iIconAutoEnroll;
  1253. break;
  1254. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  1255. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  1256. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  1257. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  1258. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  1259. case CERTMGR_SAFER_USER_ENFORCEMENT:
  1260. if (pResult->mask & RDI_STR)
  1261. {
  1262. if ( 0 == pResult->nCol )
  1263. {
  1264. m_szDisplayInfoResult = pCookie->GetObjectName ();
  1265. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1266. }
  1267. }
  1268. if (pResult->mask & RDI_IMAGE)
  1269. pResult->nImage = iIconSettings;
  1270. break;
  1271. case CERTMGR_NULL_POLICY:
  1272. if (pResult->mask & RDI_STR)
  1273. {
  1274. if ( 0 == pResult->nCol )
  1275. {
  1276. m_szDisplayInfoResult = pCookie->GetObjectName ();
  1277. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1278. }
  1279. }
  1280. break;
  1281. case CERTMGR_CERTIFICATE:
  1282. {
  1283. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  1284. ASSERT (pCert);
  1285. if ( pCert )
  1286. {
  1287. if (pResult->mask & RDI_STR)
  1288. {
  1289. // Note: text is first stored in class variable so that the buffer is
  1290. // somewhat persistent. Copying the buffer pointer directly to the
  1291. // pResult->str would result in the buffer being freed before the pointer
  1292. // is used.
  1293. switch (pResult->nCol)
  1294. {
  1295. case COLNUM_CERT_ISSUER:
  1296. m_szDisplayInfoResult = pCert->GetIssuerName ();
  1297. if ( m_szDisplayInfoResult.IsEmpty () )
  1298. {
  1299. m_szDisplayInfoResult = pCert->GetAlternateIssuerName ();
  1300. if ( m_szDisplayInfoResult.IsEmpty () )
  1301. SetTextNotAvailable ();
  1302. }
  1303. break;
  1304. case COLNUM_CERT_SUBJECT:
  1305. m_szDisplayInfoResult = pCert->GetSubjectName ();
  1306. if ( m_szDisplayInfoResult.IsEmpty () )
  1307. {
  1308. m_szDisplayInfoResult = pCert->GetAlternateSubjectName ();
  1309. if ( m_szDisplayInfoResult.IsEmpty () )
  1310. SetTextNotAvailable ();
  1311. }
  1312. break;
  1313. case COLNUM_CERT_EXPIRATION_DATE:
  1314. m_szDisplayInfoResult = pCert->GetValidNotAfter ();
  1315. break;
  1316. case COLNUM_CERT_PURPOSE:
  1317. m_szDisplayInfoResult = pCert->GetEnhancedKeyUsage ();
  1318. break;
  1319. case COLNUM_CERT_CERT_NAME:
  1320. m_szDisplayInfoResult = pCert->GetFriendlyName ();
  1321. break;
  1322. case COLNUM_CERT_STATUS:
  1323. m_szDisplayInfoResult = pCert->FormatStatus ();
  1324. break;
  1325. // NTRAID# 247237 Cert UI: Cert Snapin: Certificates snapin should show template name
  1326. case COLNUM_CERT_TEMPLATE:
  1327. m_szDisplayInfoResult = pCert->GetTemplateName ();
  1328. break;
  1329. default:
  1330. ASSERT (0);
  1331. break;
  1332. }
  1333. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1334. }
  1335. if (pResult->mask & RDI_IMAGE)
  1336. pResult->nImage = iIconCertificate;
  1337. }
  1338. }
  1339. break;
  1340. case CERTMGR_CTL:
  1341. {
  1342. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  1343. ASSERT (pCTL);
  1344. if ( pCTL )
  1345. {
  1346. if (pResult->mask & RDI_STR)
  1347. {
  1348. // Note: text is first stored in class variable so that the buffer is
  1349. // somewhat persistent. Copying the buffer pointer directly to the
  1350. // pResult->str would result in the buffer being freed before the pointer
  1351. // is used.
  1352. switch (pResult->nCol)
  1353. {
  1354. case COLNUM_CTL_ISSUER:
  1355. m_szDisplayInfoResult = pCTL->GetIssuerName ();
  1356. if ( m_szDisplayInfoResult.IsEmpty () )
  1357. {
  1358. SetTextNotAvailable ();
  1359. }
  1360. break;
  1361. case COLNUM_CTL_EFFECTIVE_DATE:
  1362. m_szDisplayInfoResult = pCTL->GetEffectiveDate ();
  1363. if ( m_szDisplayInfoResult.IsEmpty () )
  1364. {
  1365. SetTextNotAvailable ();
  1366. }
  1367. break;
  1368. case COLNUM_CTL_PURPOSE:
  1369. m_szDisplayInfoResult = pCTL->GetPurpose ();
  1370. if ( m_szDisplayInfoResult.IsEmpty () )
  1371. {
  1372. SetTextNotAvailable ();
  1373. }
  1374. break;
  1375. case COLNUM_CTL_FRIENDLY_NAME:
  1376. m_szDisplayInfoResult = pCTL->GetFriendlyName ();
  1377. if ( m_szDisplayInfoResult.IsEmpty () )
  1378. {
  1379. SetTextNotAvailable ();
  1380. }
  1381. break;
  1382. default:
  1383. ASSERT (0);
  1384. break;
  1385. }
  1386. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1387. }
  1388. if (pResult->mask & RDI_IMAGE)
  1389. pResult->nImage = iIconCTL;
  1390. }
  1391. }
  1392. break;
  1393. case CERTMGR_CRL:
  1394. {
  1395. CCRL* pCRL = reinterpret_cast <CCRL*> (pCookie);
  1396. ASSERT (pCRL);
  1397. if ( pCRL )
  1398. {
  1399. if (pResult->mask & RDI_STR)
  1400. {
  1401. // Note: text is first stored in class variable so that the buffer is
  1402. // somewhat persistent. Copying the buffer pointer directly to the
  1403. // pResult->str would result in the buffer being freed before the pointer
  1404. // is used.
  1405. switch (pResult->nCol)
  1406. {
  1407. case COLNUM_CRL_ISSUER:
  1408. m_szDisplayInfoResult = pCRL->GetIssuerName ();
  1409. if ( m_szDisplayInfoResult.IsEmpty () )
  1410. {
  1411. SetTextNotAvailable ();
  1412. }
  1413. break;
  1414. case COLNUM_CRL_EFFECTIVE_DATE:
  1415. m_szDisplayInfoResult = pCRL->GetEffectiveDate ();
  1416. if ( m_szDisplayInfoResult.IsEmpty () )
  1417. {
  1418. SetTextNotAvailable ();
  1419. }
  1420. break;
  1421. case COLNUM_CRL_NEXT_UPDATE:
  1422. m_szDisplayInfoResult = pCRL->GetNextUpdate ();
  1423. if ( m_szDisplayInfoResult.IsEmpty () )
  1424. {
  1425. SetTextNotAvailable ();
  1426. }
  1427. break;
  1428. default:
  1429. ASSERT (0);
  1430. break;
  1431. }
  1432. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1433. }
  1434. if (pResult->mask & RDI_IMAGE)
  1435. pResult->nImage = iIconCRL;
  1436. }
  1437. }
  1438. break;
  1439. case CERTMGR_AUTO_CERT_REQUEST:
  1440. {
  1441. CAutoCertRequest* pACR = reinterpret_cast <CAutoCertRequest*> (pCookie);
  1442. ASSERT (pACR);
  1443. if ( pACR )
  1444. {
  1445. if (pResult->mask & RDI_STR)
  1446. {
  1447. // Note: text is first stored in class variable so that the buffer is
  1448. // somewhat persistent. Copying the buffer pointer directly to the
  1449. // pResult->str would result in the buffer being freed before the pointer
  1450. // is used.
  1451. switch (pResult->nCol)
  1452. {
  1453. case 0:
  1454. {
  1455. CString name;
  1456. if ( SUCCEEDED (pACR->GetCertTypeName (name)) )
  1457. m_szDisplayInfoResult = name;
  1458. else
  1459. SetTextNotAvailable ();
  1460. }
  1461. break;
  1462. default:
  1463. ASSERT (0);
  1464. break;
  1465. }
  1466. pResult->str = const_cast<LPWSTR> ( (LPCWSTR) m_szDisplayInfoResult);
  1467. }
  1468. if (pResult->mask & RDI_IMAGE)
  1469. pResult->nImage = iIconAutoCertRequest;
  1470. }
  1471. }
  1472. break;
  1473. }
  1474. }
  1475. else
  1476. hr = CComponent::GetDisplayInfo (pResult);
  1477. return hr;
  1478. }
  1479. ///////////////////////////////////////////////////////////////////////////////
  1480. // IExtendContextMenu implementation
  1481. //
  1482. STDMETHODIMP CCertMgrComponent::AddMenuItems (LPDATAOBJECT pDataObject,
  1483. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1484. long *pInsertionAllowed)
  1485. {
  1486. _TRACE (1, L"Entering CCertMgrComponent::AddMenuItems\n");
  1487. HRESULT hr = S_OK;
  1488. hr = QueryComponentDataRef ().AddMenuItems (pDataObject,
  1489. pContextMenuCallback, pInsertionAllowed);
  1490. _TRACE (-1, L"Leaving CCertMgrComponent::AddMenuItems: 0x%x\n", hr);
  1491. return hr;
  1492. }
  1493. STDMETHODIMP CCertMgrComponent::Command (long nCommandID, LPDATAOBJECT pDataObject)
  1494. {
  1495. _TRACE (1, L"Entering CCertMgrComponent::Command\n");
  1496. HRESULT hr = S_OK;
  1497. switch (nCommandID)
  1498. {
  1499. case IDM_OPEN:
  1500. case IDM_TASK_OPEN:
  1501. hr = OnOpen (pDataObject);
  1502. break;
  1503. default:
  1504. hr = QueryComponentDataRef ().Command (nCommandID, pDataObject);
  1505. break;
  1506. }
  1507. _TRACE (-1, L"Leaving CCertMgrComponent::Command: 0x%x\n", hr);
  1508. return hr;
  1509. }
  1510. HRESULT CCertMgrComponent::OnNotifyDblClick (LPDATAOBJECT pDataObject)
  1511. {
  1512. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyDblClick\n");
  1513. HRESULT hr = S_OK;
  1514. ASSERT (pDataObject);
  1515. CCertMgrCookie* pParentCookie =
  1516. QueryComponentDataRef ().ConvertCookie (pDataObject);
  1517. if ( pParentCookie )
  1518. {
  1519. switch ( pParentCookie->m_objecttype )
  1520. {
  1521. case CERTMGR_SNAPIN:
  1522. case CERTMGR_USAGE:
  1523. case CERTMGR_PHYS_STORE:
  1524. case CERTMGR_LOG_STORE:
  1525. case CERTMGR_LOG_STORE_GPE:
  1526. case CERTMGR_LOG_STORE_RSOP:
  1527. case CERTMGR_CRL_CONTAINER:
  1528. case CERTMGR_CTL_CONTAINER:
  1529. case CERTMGR_CERT_CONTAINER:
  1530. case CERTMGR_AUTO_CERT_REQUEST:
  1531. case CERTMGR_CERT_POLICIES_USER:
  1532. case CERTMGR_CERT_POLICIES_COMPUTER:
  1533. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  1534. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  1535. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  1536. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  1537. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  1538. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  1539. case CERTMGR_SAFER_COMPUTER_LEVEL:
  1540. case CERTMGR_SAFER_USER_LEVEL:
  1541. case CERTMGR_SAFER_COMPUTER_ENTRY:
  1542. case CERTMGR_SAFER_USER_ENTRY:
  1543. case CERTMGR_SAFER_USER_ROOT:
  1544. case CERTMGR_SAFER_USER_ENTRIES:
  1545. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  1546. case CERTMGR_SAFER_USER_LEVELS:
  1547. case CERTMGR_SAFER_COMPUTER_LEVELS:
  1548. case CERTMGR_SAFER_COMPUTER_ROOT:
  1549. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  1550. case CERTMGR_SAFER_USER_ENFORCEMENT:
  1551. hr = S_FALSE;
  1552. break;
  1553. case CERTMGR_CERTIFICATE:
  1554. {
  1555. CCertificate* pCert = reinterpret_cast <CCertificate*> (pParentCookie);
  1556. ASSERT (pCert);
  1557. if ( pCert )
  1558. hr = LaunchCommonCertDialog (pCert);
  1559. else
  1560. hr = E_UNEXPECTED;
  1561. }
  1562. hr = S_OK;
  1563. break;
  1564. case CERTMGR_CTL:
  1565. {
  1566. CCTL* pCTL = reinterpret_cast <CCTL*> (pParentCookie);
  1567. ASSERT (pCTL);
  1568. if ( pCTL )
  1569. hr = LaunchCommonCTLDialog (pCTL);
  1570. else
  1571. hr = E_UNEXPECTED;
  1572. }
  1573. hr = S_OK;
  1574. break;
  1575. case CERTMGR_CRL:
  1576. {
  1577. CCRL* pCRL = reinterpret_cast <CCRL*> (pParentCookie);
  1578. ASSERT (pCRL);
  1579. if ( pCRL )
  1580. hr = LaunchCommonCRLDialog (pCRL);
  1581. else
  1582. hr = E_UNEXPECTED;
  1583. }
  1584. hr = S_OK;
  1585. break;
  1586. default:
  1587. _TRACE (0, L"CCertMgrComponentData::EnumerateScopeChildren bad parent type\n");
  1588. ASSERT (FALSE);
  1589. hr = S_OK;
  1590. break;
  1591. }
  1592. }
  1593. else
  1594. hr = E_UNEXPECTED;
  1595. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyDblClick: 0x%x\n", hr);
  1596. return hr;
  1597. }
  1598. HRESULT CCertMgrComponent::OnNotifySelect (LPDATAOBJECT pDataObject, BOOL fSelected)
  1599. {
  1600. _TRACE (0, L"Entering CCertMgrComponent::OnNotifySelect - fSelected == %d.\n", fSelected);
  1601. ASSERT (m_pConsoleVerb && 0xdddddddd != (UINT_PTR) m_pConsoleVerb);
  1602. if ( !m_pConsoleVerb || 0xdddddddd == (UINT_PTR) m_pConsoleVerb )
  1603. return E_FAIL;
  1604. HRESULT hr = S_OK;
  1605. CCertMgrComponentData& compData = QueryComponentDataRef ();
  1606. BOOL bIsFileView = !(compData.m_szFileName.IsEmpty ());
  1607. // Don't add menu items if this is a serialized file
  1608. CertificateManagerObjectType objectType = compData.GetObjectType (pDataObject);
  1609. switch (objectType)
  1610. {
  1611. case CERTMGR_SNAPIN:
  1612. if ( fSelected )
  1613. {
  1614. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1615. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1616. }
  1617. else
  1618. {
  1619. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1620. }
  1621. m_currResultNodeType = CERTMGR_INVALID;
  1622. break;
  1623. case CERTMGR_USAGE:
  1624. m_currResultNodeType = CERTMGR_CERTIFICATE;
  1625. {
  1626. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1627. if ( pCookie )
  1628. {
  1629. CUsageCookie* pUsage = reinterpret_cast <CUsageCookie*> (pCookie);
  1630. ASSERT (pUsage);
  1631. if ( pUsage )
  1632. {
  1633. if ( m_pLastUsageCookie )
  1634. m_pLastUsageCookie->Release ();
  1635. m_pLastUsageCookie = pUsage;
  1636. m_pLastUsageCookie->AddRef ();
  1637. hr = DisplayCertificateCountByUsage (pCookie->GetObjectName (),
  1638. pUsage->GetCertCount ());
  1639. }
  1640. else
  1641. hr = E_UNEXPECTED;
  1642. }
  1643. else
  1644. hr = E_UNEXPECTED;
  1645. }
  1646. if ( fSelected )
  1647. {
  1648. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1649. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1650. }
  1651. else
  1652. {
  1653. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1654. }
  1655. break;
  1656. case CERTMGR_PHYS_STORE:
  1657. case CERTMGR_LOG_STORE:
  1658. if ( fSelected )
  1659. {
  1660. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1661. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1662. }
  1663. else
  1664. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1665. if ( !bIsFileView )
  1666. {
  1667. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1668. if ( pCookie )
  1669. {
  1670. CCertStore* pStore = reinterpret_cast <CCertStore*> (pCookie);
  1671. ASSERT (pStore);
  1672. if ( pStore )
  1673. {
  1674. pStore->GetStoreHandle (); // to initialize read-only flag
  1675. if ( pStore->IsReadOnly () ) //|| !fSelected)
  1676. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  1677. else
  1678. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  1679. if ( fSelected )
  1680. hr = DisplayCertificateCountByStore (m_pConsole, pStore);
  1681. pStore->Close ();
  1682. }
  1683. else
  1684. hr = E_UNEXPECTED;
  1685. }
  1686. else
  1687. hr = E_UNEXPECTED;
  1688. }
  1689. m_currResultNodeType = CERTMGR_INVALID;
  1690. break;
  1691. case CERTMGR_LOG_STORE_GPE:
  1692. case CERTMGR_LOG_STORE_RSOP:
  1693. if ( fSelected && CERTMGR_LOG_STORE_RSOP != QueryComponentDataRef ().GetObjectType (pDataObject) )
  1694. {
  1695. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1696. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1697. }
  1698. else
  1699. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1700. if ( !bIsFileView )
  1701. {
  1702. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1703. if ( pCookie )
  1704. {
  1705. CCertStoreGPE* pStore = reinterpret_cast <CCertStoreGPE*> (pCookie);
  1706. ASSERT (pStore);
  1707. if ( pStore )
  1708. {
  1709. hr = DisplayCertificateCountByStore (m_pConsole, pStore, true);
  1710. switch (pStore->GetStoreType ())
  1711. {
  1712. case ROOT_STORE:
  1713. if ( fSelected )
  1714. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1715. else
  1716. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  1717. m_currResultNodeType = CERTMGR_CERTIFICATE;
  1718. break;
  1719. case EFS_STORE:
  1720. if ( fSelected )
  1721. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1722. else
  1723. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  1724. m_currResultNodeType = CERTMGR_CERTIFICATE;
  1725. break;
  1726. case TRUST_STORE:
  1727. if ( compData.m_bIsRSOP )
  1728. {
  1729. if ( fSelected )
  1730. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1731. else
  1732. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  1733. }
  1734. m_currResultNodeType = CERTMGR_CTL;
  1735. break;
  1736. case ACRS_STORE:
  1737. if ( compData.m_bIsRSOP )
  1738. {
  1739. if ( fSelected )
  1740. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1741. else
  1742. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  1743. }
  1744. m_currResultNodeType = CERTMGR_AUTO_CERT_REQUEST;
  1745. break;
  1746. default:
  1747. ASSERT (0);
  1748. m_currResultNodeType = CERTMGR_INVALID;
  1749. break;
  1750. }
  1751. if ( pStore->IsReadOnly () ) //|| !fSelected )
  1752. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  1753. else if ( ACRS_STORE != pStore->GetStoreType () )
  1754. {
  1755. // Do not allow cut and paste for ACRS store.
  1756. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  1757. if ( !fSelected &&
  1758. CERTMGR_LOG_STORE_GPE != pStore->m_objecttype )
  1759. {
  1760. pStore->Commit ();
  1761. }
  1762. }
  1763. }
  1764. else
  1765. hr = E_UNEXPECTED;
  1766. }
  1767. else
  1768. hr = E_UNEXPECTED;
  1769. }
  1770. break;
  1771. case CERTMGR_CERTIFICATE:
  1772. {
  1773. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1774. ASSERT (pCookie);
  1775. if ( pCookie )
  1776. {
  1777. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  1778. ASSERT (pCert);
  1779. if ( pCert )
  1780. {
  1781. if ( fSelected )
  1782. {
  1783. if ( IDM_STORE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  1784. {
  1785. hr = DisplayCertificateCountByStore (
  1786. m_pConsole, pCert->GetCertStore ());
  1787. }
  1788. else
  1789. {
  1790. // Display by count in each purpose
  1791. ASSERT (m_pLastUsageCookie);
  1792. if ( m_pLastUsageCookie )
  1793. {
  1794. hr = DisplayCertificateCountByUsage (
  1795. m_pLastUsageCookie->GetObjectName (),
  1796. m_pLastUsageCookie->GetCertCount ());
  1797. }
  1798. }
  1799. }
  1800. if ( fSelected )
  1801. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, TRUE);
  1802. else
  1803. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, FALSE);
  1804. if ( !bIsFileView )
  1805. {
  1806. if ( fSelected )
  1807. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1808. else
  1809. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  1810. CCertStore* pCertStore = pCert->GetCertStore ();
  1811. if ( pCertStore )
  1812. {
  1813. if ( pCertStore->IsReadOnly () || !fSelected )
  1814. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  1815. else
  1816. {
  1817. if ( pCert->CanDelete () )
  1818. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, TRUE);
  1819. else
  1820. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  1821. if ( !fSelected &&
  1822. CERTMGR_LOG_STORE_GPE == pCertStore->m_objecttype )
  1823. {
  1824. pCertStore->Commit ();
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. else
  1831. hr = E_UNEXPECTED;
  1832. }
  1833. else
  1834. hr = E_UNEXPECTED;
  1835. }
  1836. m_currResultNodeType = CERTMGR_CERTIFICATE;
  1837. break;
  1838. case CERTMGR_CRL_CONTAINER:
  1839. if ( fSelected )
  1840. {
  1841. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1842. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1843. }
  1844. else
  1845. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1846. if ( !bIsFileView )
  1847. {
  1848. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1849. if ( pCookie )
  1850. {
  1851. CContainerCookie* pCont = reinterpret_cast <CContainerCookie*> (pCookie);
  1852. ASSERT (pCont);
  1853. if ( pCont )
  1854. {
  1855. if ( pCont->GetCertStore ().IsReadOnly () ) //|| !fSelected )
  1856. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  1857. else
  1858. {
  1859. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  1860. if ( !fSelected )
  1861. pCont->GetCertStore ().Commit ();
  1862. }
  1863. }
  1864. else
  1865. hr = E_UNEXPECTED;
  1866. }
  1867. else
  1868. hr = E_UNEXPECTED;
  1869. }
  1870. m_currResultNodeType = CERTMGR_CRL;
  1871. break;
  1872. case CERTMGR_CTL_CONTAINER:
  1873. if ( fSelected )
  1874. {
  1875. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1876. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1877. }
  1878. else
  1879. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1880. if ( !bIsFileView )
  1881. {
  1882. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1883. if ( pCookie )
  1884. {
  1885. CContainerCookie* pCont = reinterpret_cast <CContainerCookie*> (pCookie);
  1886. ASSERT (pCont);
  1887. if ( pCont )
  1888. {
  1889. if ( pCont->GetCertStore ().IsReadOnly () ) //|| !fSelected )
  1890. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  1891. else
  1892. {
  1893. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  1894. if ( !fSelected )
  1895. pCont->GetCertStore ().Commit ();
  1896. }
  1897. }
  1898. else
  1899. hr = E_UNEXPECTED;
  1900. }
  1901. else
  1902. hr = E_UNEXPECTED;
  1903. }
  1904. m_currResultNodeType = CERTMGR_CTL;
  1905. break;
  1906. case CERTMGR_CERT_CONTAINER:
  1907. if ( fSelected )
  1908. {
  1909. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  1910. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  1911. }
  1912. else
  1913. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  1914. if ( !bIsFileView )
  1915. {
  1916. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1917. if ( pCookie )
  1918. {
  1919. CContainerCookie* pCont = reinterpret_cast <CContainerCookie*> (pCookie);
  1920. ASSERT (pCont);
  1921. if ( pCont )
  1922. {
  1923. if ( fSelected )
  1924. hr = DisplayCertificateCountByStore (
  1925. m_pConsole, &pCont->GetCertStore ());
  1926. if ( pCont->GetCertStore ().IsReadOnly () ) //|| !fSelected )
  1927. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  1928. else
  1929. {
  1930. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  1931. if ( !fSelected )
  1932. pCont->GetCertStore ().Commit ();
  1933. }
  1934. }
  1935. else
  1936. hr = E_UNEXPECTED;
  1937. }
  1938. else
  1939. hr = E_UNEXPECTED;
  1940. }
  1941. m_currResultNodeType = CERTMGR_CERTIFICATE;
  1942. break;
  1943. case CERTMGR_CRL:
  1944. if ( fSelected )
  1945. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, TRUE);
  1946. else
  1947. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, FALSE);
  1948. {
  1949. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1950. if ( pCookie )
  1951. {
  1952. CCRL* pCRL = reinterpret_cast <CCRL*> (pCookie);
  1953. ASSERT (pCRL);
  1954. if ( pCRL )
  1955. {
  1956. if ( pCRL->GetCertStore ().IsReadOnly () || !fSelected )
  1957. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  1958. else
  1959. {
  1960. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, TRUE);
  1961. if ( !fSelected &&
  1962. CERTMGR_LOG_STORE_GPE == pCRL->GetCertStore ().m_objecttype )
  1963. {
  1964. pCRL->GetCertStore ().Commit ();
  1965. }
  1966. }
  1967. }
  1968. else
  1969. hr = E_UNEXPECTED;
  1970. }
  1971. else
  1972. hr = E_UNEXPECTED;
  1973. }
  1974. m_currResultNodeType = CERTMGR_CRL;
  1975. break;
  1976. case CERTMGR_AUTO_CERT_REQUEST:
  1977. if ( fSelected )
  1978. {
  1979. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  1980. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_PROPERTIES);
  1981. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, TRUE);
  1982. }
  1983. else
  1984. {
  1985. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  1986. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, FALSE);
  1987. }
  1988. {
  1989. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  1990. if ( pCookie )
  1991. {
  1992. CAutoCertRequest* pAutoCert = reinterpret_cast <CAutoCertRequest*> (pCookie);
  1993. ASSERT (pAutoCert);
  1994. if ( pAutoCert )
  1995. {
  1996. if ( pAutoCert->GetCertStore ().IsReadOnly () || !fSelected )
  1997. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  1998. else
  1999. {
  2000. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, TRUE);
  2001. if ( !fSelected &&
  2002. CERTMGR_LOG_STORE_GPE == pAutoCert->GetCertStore ().m_objecttype )
  2003. {
  2004. pAutoCert->GetCertStore ().Commit ();
  2005. }
  2006. }
  2007. }
  2008. else
  2009. hr = E_UNEXPECTED;
  2010. }
  2011. else
  2012. hr = E_UNEXPECTED;
  2013. }
  2014. m_currResultNodeType = CERTMGR_AUTO_CERT_REQUEST;
  2015. break;
  2016. case CERTMGR_CTL:
  2017. if ( !bIsFileView )
  2018. {
  2019. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  2020. if ( pCookie )
  2021. {
  2022. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  2023. ASSERT (pCTL);
  2024. if ( pCTL )
  2025. {
  2026. if ( pCTL->GetCertStore ().IsReadOnly () || !fSelected )
  2027. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  2028. else
  2029. {
  2030. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, TRUE);
  2031. if ( !fSelected &&
  2032. CERTMGR_LOG_STORE_GPE == pCTL->GetCertStore ().m_objecttype )
  2033. {
  2034. pCTL->GetCertStore ().Commit ();
  2035. }
  2036. }
  2037. // Don't allow auto cert requests to be copied. They can't be
  2038. // pasted anywhere.
  2039. if ( ACRS_STORE != pCTL->GetCertStore ().GetStoreType () )
  2040. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, TRUE);
  2041. }
  2042. else
  2043. hr = E_UNEXPECTED;
  2044. }
  2045. else
  2046. hr = E_UNEXPECTED;
  2047. }
  2048. m_currResultNodeType = CERTMGR_CTL;
  2049. break;
  2050. case CERTMGR_CERT_POLICIES_COMPUTER:
  2051. case CERTMGR_CERT_POLICIES_USER:
  2052. m_currResultNodeType = CERTMGR_INVALID;
  2053. if ( fSelected )
  2054. {
  2055. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  2056. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  2057. }
  2058. else
  2059. {
  2060. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  2061. }
  2062. break;
  2063. case CERTMGR_MULTISEL:
  2064. {
  2065. if ( fSelected )
  2066. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, TRUE);
  2067. else
  2068. m_pConsoleVerb->SetVerbState (MMC_VERB_COPY, ENABLED, FALSE);
  2069. bool bDeleteSet = false;
  2070. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pDataObject);
  2071. ASSERT (pDO);
  2072. if ( pDO )
  2073. {
  2074. // Is multiple select, get all selected items and delete - confirm
  2075. // first deletion only.
  2076. CCertMgrCookie* pCookie = 0;
  2077. pDO->Reset();
  2078. while (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) != S_FALSE)
  2079. {
  2080. if ( CERTMGR_CERTIFICATE == pCookie->m_objecttype )
  2081. {
  2082. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  2083. ASSERT (pCert);
  2084. if ( (pCert && !pCert->CanDelete ()) || !fSelected )
  2085. {
  2086. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  2087. bDeleteSet = true;
  2088. break;
  2089. }
  2090. }
  2091. else
  2092. break;
  2093. }
  2094. }
  2095. if ( !bDeleteSet && fSelected )
  2096. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, TRUE);
  2097. }
  2098. m_currResultNodeType = CERTMGR_MULTISEL;
  2099. break;
  2100. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  2101. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  2102. case CERTMGR_SAFER_COMPUTER_LEVEL:
  2103. case CERTMGR_SAFER_USER_LEVEL:
  2104. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  2105. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  2106. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  2107. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  2108. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  2109. case CERTMGR_SAFER_USER_ENFORCEMENT:
  2110. if ( fSelected )
  2111. {
  2112. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  2113. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_PROPERTIES);
  2114. }
  2115. else
  2116. {
  2117. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  2118. }
  2119. break;
  2120. case CERTMGR_SAFER_COMPUTER_ENTRY:
  2121. case CERTMGR_SAFER_USER_ENTRY:
  2122. if ( fSelected )
  2123. {
  2124. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, TRUE);
  2125. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_PROPERTIES);
  2126. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, TRUE);
  2127. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  2128. }
  2129. else
  2130. {
  2131. m_pConsoleVerb->SetVerbState (MMC_VERB_PROPERTIES, ENABLED, FALSE);
  2132. m_pConsoleVerb->SetVerbState (MMC_VERB_DELETE, ENABLED, FALSE);
  2133. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  2134. }
  2135. break;
  2136. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  2137. case CERTMGR_SAFER_USER_ENTRIES:
  2138. if ( fSelected )
  2139. {
  2140. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, TRUE);
  2141. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, TRUE);
  2142. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  2143. }
  2144. else
  2145. {
  2146. m_pConsoleVerb->SetVerbState (MMC_VERB_REFRESH, ENABLED, FALSE);
  2147. m_pConsoleVerb->SetVerbState (MMC_VERB_PASTE, ENABLED, FALSE);
  2148. }
  2149. break;
  2150. case CERTMGR_SAFER_COMPUTER_LEVELS:
  2151. case CERTMGR_SAFER_USER_LEVELS:
  2152. if ( fSelected )
  2153. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  2154. break;
  2155. case CERTMGR_SAFER_COMPUTER_ROOT:
  2156. case CERTMGR_SAFER_USER_ROOT:
  2157. if ( fSelected )
  2158. m_pConsoleVerb->SetDefaultVerb (MMC_VERB_OPEN);
  2159. {
  2160. CString szStatusText;
  2161. if ( !QueryComponentDataRef ().m_bSaferSupported )
  2162. {
  2163. szStatusText.LoadString (IDS_SAFER_NOT_SUPPORTED);
  2164. }
  2165. IConsole2* pConsole2 = 0;
  2166. hr = m_pConsole->QueryInterface (
  2167. IID_PPV_ARG(IConsole2, &pConsole2));
  2168. if (SUCCEEDED (hr))
  2169. {
  2170. hr = pConsole2->SetStatusText (const_cast <LPOLESTR>((PCWSTR) szStatusText));
  2171. if ( !SUCCEEDED (hr) )
  2172. {
  2173. _TRACE (0, L"IConsole::SetStatusText () failed: %x", hr);
  2174. }
  2175. pConsole2->Release ();
  2176. }
  2177. }
  2178. break;
  2179. default:
  2180. m_currResultNodeType = CERTMGR_INVALID;
  2181. hr = E_UNEXPECTED;
  2182. break;
  2183. }
  2184. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifySelect: 0x%x\n", hr);
  2185. return hr;
  2186. }
  2187. STDMETHODIMP CCertMgrComponent::CreatePropertyPages (
  2188. LPPROPERTYSHEETCALLBACK pCallBack,
  2189. LONG_PTR handle, // This handle must be saved in the property page object to notify the parent when modified
  2190. LPDATAOBJECT pDataObject)
  2191. {
  2192. _TRACE (1, L"Entering CCertMgrComponent::CreatePropertyPages\n");
  2193. HRESULT hr = S_OK;
  2194. hr = QueryComponentDataRef ().CreatePropertyPages (pCallBack, handle, pDataObject);
  2195. _TRACE (-1, L"Leaving CCertMgrComponent::CreatePropertyPages: 0x%x\n", hr);
  2196. return hr;
  2197. }
  2198. STDMETHODIMP CCertMgrComponent::QueryPagesFor (LPDATAOBJECT pDataObject)
  2199. {
  2200. _TRACE (1, L"Entering CCertMgrComponent::QueryPagesFor\n");
  2201. HRESULT hr = S_OK;
  2202. hr = QueryComponentDataRef ().QueryPagesFor (pDataObject);
  2203. _TRACE (-1, L"Leaving CCertMgrComponent::QueryPagesFor: 0x%x\n", hr);
  2204. return hr;
  2205. }
  2206. HRESULT CCertMgrComponent::OnNotifyRefresh (LPDATAOBJECT pDataObject)
  2207. {
  2208. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyRefresh\n");
  2209. ASSERT (pDataObject);
  2210. if ( !pDataObject )
  2211. return E_POINTER;
  2212. HRESULT hr = S_OK;
  2213. CCertMgrCookie* pCookie = ConvertCookie (pDataObject);
  2214. if ( !pCookie )
  2215. return E_UNEXPECTED;
  2216. CCertMgrComponentData& dataRef = QueryComponentDataRef ();
  2217. switch (pCookie->m_objecttype)
  2218. {
  2219. case CERTMGR_CERT_POLICIES_USER:
  2220. case CERTMGR_CERT_POLICIES_COMPUTER:
  2221. if ( dataRef.m_bIsRSOP )
  2222. {
  2223. // Delete all the scope items and force a reexpansion
  2224. hr = dataRef.DeleteScopeItems (pCookie->m_hScopeItem);
  2225. hr = dataRef.BuildWMIList (0,
  2226. CERTMGR_CERT_POLICIES_COMPUTER == pCookie->m_objecttype);
  2227. if ( SUCCEEDED (hr) )
  2228. {
  2229. GUID guid;
  2230. hr = dataRef.ExpandScopeNodes (
  2231. pCookie, pCookie->m_hScopeItem,
  2232. _T (""), 0, guid);
  2233. }
  2234. }
  2235. break;
  2236. case CERTMGR_SNAPIN:
  2237. {
  2238. // Close and release the usage stores if any.
  2239. CloseAndReleaseUsageStores ();
  2240. m_bUsageStoresEnumerated = false;
  2241. // Delete all the scope items and force a reexpansion
  2242. hr = dataRef.DeleteScopeItems ();
  2243. if ( dataRef.m_bIsRSOP )
  2244. {
  2245. ASSERT (0); // do we ever hit this?
  2246. hr = dataRef.BuildWMIList (0, true);
  2247. }
  2248. if ( SUCCEEDED (hr) )
  2249. {
  2250. GUID guid;
  2251. hr = dataRef.ExpandScopeNodes (
  2252. dataRef.m_pRootCookie, dataRef.m_hRootScopeItem,
  2253. _T (""), 0, guid);
  2254. }
  2255. }
  2256. break;
  2257. case CERTMGR_PHYS_STORE:
  2258. case CERTMGR_LOG_STORE:
  2259. {
  2260. CCertStore* pCertStore = reinterpret_cast <CCertStore*> (pCookie);
  2261. ASSERT (pCertStore);
  2262. if ( pCertStore )
  2263. pCertStore->Resync ();
  2264. HSCOPEITEM hScopeItem = pCookie->m_hScopeItem;
  2265. ASSERT (hScopeItem);
  2266. if ( hScopeItem )
  2267. {
  2268. hr = dataRef.DeleteChildren (hScopeItem);
  2269. GUID guid;
  2270. hr = dataRef.ExpandScopeNodes (
  2271. pCookie, hScopeItem, _T (""), 0, guid);
  2272. if ( SUCCEEDED (hr) )
  2273. {
  2274. hr = RefreshResultPane ();
  2275. ASSERT (SUCCEEDED (hr));
  2276. }
  2277. }
  2278. }
  2279. break;
  2280. case CERTMGR_CRL_CONTAINER:
  2281. case CERTMGR_CTL_CONTAINER:
  2282. case CERTMGR_CERT_CONTAINER:
  2283. {
  2284. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pCookie);
  2285. ASSERT (pContainer);
  2286. if ( pContainer )
  2287. {
  2288. pContainer->GetCertStore ().Resync ();
  2289. }
  2290. }
  2291. hr = RefreshResultPane ();
  2292. ASSERT (SUCCEEDED (hr));
  2293. break;
  2294. case CERTMGR_LOG_STORE_GPE:
  2295. {
  2296. CCertStore* pCertStore = reinterpret_cast <CCertStore*> (pCookie);
  2297. ASSERT (pCertStore);
  2298. if ( pCertStore )
  2299. pCertStore->Resync ();
  2300. }
  2301. hr = RefreshResultPane ();
  2302. ASSERT (SUCCEEDED (hr));
  2303. break;
  2304. case CERTMGR_LOG_STORE_RSOP:
  2305. // must be refreshed at root node
  2306. ASSERT (0);
  2307. break;
  2308. case CERTMGR_USAGE:
  2309. // Close all the stores. This will force them to be
  2310. // re-enumerated later.
  2311. CloseAndReleaseUsageStores ();
  2312. m_bUsageStoresEnumerated = false;
  2313. hr = RefreshResultPane ();
  2314. ASSERT (SUCCEEDED (hr));
  2315. break;
  2316. case CERTMGR_AUTO_CERT_REQUEST:
  2317. hr = RefreshResultPane ();
  2318. ASSERT (SUCCEEDED (hr));
  2319. break;
  2320. case CERTMGR_CERTIFICATE:
  2321. {
  2322. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  2323. ASSERT (pCert);
  2324. if ( pCert )
  2325. {
  2326. CCertStore* pStore = pCert->GetCertStore ();
  2327. if ( pStore )
  2328. pStore->Resync ();
  2329. }
  2330. }
  2331. hr = RefreshResultItem (pCookie);
  2332. ASSERT (SUCCEEDED (hr));
  2333. break;
  2334. case CERTMGR_CTL:
  2335. {
  2336. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  2337. ASSERT (pCTL);
  2338. if ( pCTL )
  2339. {
  2340. pCTL->GetCertStore ().Resync ();
  2341. }
  2342. }
  2343. hr = RefreshResultItem (pCookie);
  2344. ASSERT (SUCCEEDED (hr));
  2345. break;
  2346. case CERTMGR_CRL:
  2347. {
  2348. CCRL* pCRL = reinterpret_cast <CCRL*> (pCookie);
  2349. ASSERT (pCRL);
  2350. if ( pCRL )
  2351. {
  2352. pCRL->GetCertStore ().Resync ();
  2353. }
  2354. }
  2355. hr = RefreshResultItem (pCookie);
  2356. ASSERT (SUCCEEDED (hr));
  2357. break;
  2358. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  2359. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  2360. ASSERT (0);
  2361. break;
  2362. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  2363. case CERTMGR_SAFER_USER_ENTRIES:
  2364. {
  2365. bool bAllowRefresh = true;
  2366. RESULTDATAITEM rdItem;
  2367. ::ZeroMemory (&rdItem, sizeof (RESULTDATAITEM));
  2368. rdItem.nIndex = -1;
  2369. rdItem.mask = RDI_STATE | RDI_PARAM | RDI_INDEX;
  2370. do
  2371. {
  2372. hr = m_pResultData->GetNextItem (&rdItem);
  2373. if ( SUCCEEDED (hr) )
  2374. {
  2375. CCertMgrCookie* pCurrCookie = (CCertMgrCookie*) rdItem.lParam;
  2376. if ( pCurrCookie )
  2377. {
  2378. if ( pCurrCookie->HasOpenPropertyPages () )
  2379. {
  2380. CString text;
  2381. CString caption;
  2382. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2383. VERIFY (text.LoadString (IDS_CANT_REFRESH_PAGES_OPEN));
  2384. int iRetVal = 0;
  2385. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  2386. MB_OK, &iRetVal)));
  2387. bAllowRefresh = false;
  2388. break;
  2389. }
  2390. }
  2391. }
  2392. } while ( SUCCEEDED (hr) && -1 != rdItem.nIndex );
  2393. if ( !bAllowRefresh )
  2394. break;
  2395. }
  2396. hr = RefreshResultPane ();
  2397. ASSERT (SUCCEEDED (hr));
  2398. break;
  2399. case CERTMGR_SAFER_COMPUTER_ENTRY:
  2400. case CERTMGR_SAFER_USER_ENTRY:
  2401. hr = RefreshResultPane ();
  2402. ASSERT (SUCCEEDED (hr));
  2403. break;
  2404. default:
  2405. ASSERT (0);
  2406. hr = E_UNEXPECTED;
  2407. break;
  2408. }
  2409. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyRefresh: 0x%x\n", hr);
  2410. return hr;
  2411. }
  2412. void CCertMgrComponent::SetTextNotAvailable ()
  2413. {
  2414. _TRACE (1, L"Entering CCertMgrComponent::SetTextNotAvailable\n");
  2415. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2416. m_szDisplayInfoResult.LoadString (IDS_NOT_AVAILABLE);
  2417. _TRACE (-1, L"Leaving CCertMgrComponent::SetTextNotAvailable\n");
  2418. }
  2419. HRESULT CCertMgrComponent::DeleteCookie (
  2420. CCertMgrCookie* pCookie,
  2421. LPDATAOBJECT pDataObject,
  2422. bool bRequestConfirmation,
  2423. bool bIsMultipleSelect,
  2424. bool bDoCommit)
  2425. {
  2426. _TRACE (1, L"Entering CCertMgrComponent::DeleteCookie\n");
  2427. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  2428. HRESULT hr = S_OK;
  2429. CString text;
  2430. CString caption;
  2431. int iRetVal = IDYES;
  2432. switch (pCookie->m_objecttype)
  2433. {
  2434. case CERTMGR_CERTIFICATE:
  2435. {
  2436. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  2437. ASSERT (pCert);
  2438. if ( pCert )
  2439. {
  2440. if ( bRequestConfirmation )
  2441. {
  2442. switch ( pCert->GetStoreType () )
  2443. {
  2444. case ROOT_STORE:
  2445. if ( bIsMultipleSelect )
  2446. {
  2447. if ( IDM_USAGE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  2448. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MULT_CERT_BY_PURPOSE));
  2449. else
  2450. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_ROOT_MULTI_CERT));
  2451. }
  2452. else
  2453. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_ROOT_CERT));
  2454. break;
  2455. case CA_STORE:
  2456. if ( bIsMultipleSelect )
  2457. {
  2458. if ( IDM_USAGE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  2459. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MULT_CERT_BY_PURPOSE));
  2460. else
  2461. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_CA_MULTI_CERT));
  2462. }
  2463. else
  2464. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_CA_CERT));
  2465. break;
  2466. case MY_STORE:
  2467. if ( bIsMultipleSelect )
  2468. {
  2469. if ( IDM_USAGE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  2470. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MULT_CERT_BY_PURPOSE));
  2471. else
  2472. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MY_MULTI_CERT));
  2473. }
  2474. else
  2475. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MY_CERT));
  2476. break;
  2477. default:
  2478. if ( bIsMultipleSelect )
  2479. {
  2480. if ( IDM_USAGE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  2481. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MULT_CERT_BY_PURPOSE));
  2482. else
  2483. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MULTI));
  2484. }
  2485. else
  2486. VERIFY (text.LoadString (IDS_CONFIRM_DELETE));
  2487. break;
  2488. }
  2489. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2490. hr = m_pConsole->MessageBox (text, caption, MB_ICONWARNING | MB_YESNO, &iRetVal);
  2491. ASSERT (SUCCEEDED (hr));
  2492. }
  2493. if ( IDYES == iRetVal )
  2494. {
  2495. CWaitCursor waitCursor;
  2496. pCert->GetCertStore (); // to initialize handle
  2497. hr = DeleteCertFromResultPane (pCert, pDataObject, bDoCommit);
  2498. }
  2499. else
  2500. hr = E_FAIL;
  2501. }
  2502. }
  2503. break;
  2504. case CERTMGR_CRL:
  2505. {
  2506. CCRL* pCRL = reinterpret_cast <CCRL*> (pCookie);
  2507. ASSERT (pCRL);
  2508. if ( pCRL )
  2509. {
  2510. if ( m_pPastedDO != pDataObject )
  2511. {
  2512. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_CRL));
  2513. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2514. hr = m_pConsole->MessageBox (text, caption, MB_ICONWARNING | MB_YESNO, &iRetVal);
  2515. ASSERT (SUCCEEDED (hr));
  2516. }
  2517. if ( IDYES == iRetVal )
  2518. {
  2519. CWaitCursor waitCursor;
  2520. hr = DeleteCRLFromResultPane (pCRL, pDataObject);
  2521. if ( SUCCEEDED (hr) )
  2522. pCRL->GetCertStore ().Commit ();
  2523. }
  2524. else
  2525. hr = E_FAIL;
  2526. }
  2527. }
  2528. break;
  2529. case CERTMGR_CTL:
  2530. {
  2531. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  2532. ASSERT (pCTL);
  2533. if ( pCTL )
  2534. {
  2535. if ( bRequestConfirmation )
  2536. {
  2537. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_CTL));
  2538. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2539. hr = m_pConsole->MessageBox (text, caption, MB_ICONWARNING | MB_YESNO, &iRetVal);
  2540. ASSERT (SUCCEEDED (hr));
  2541. }
  2542. if ( IDYES == iRetVal )
  2543. {
  2544. CWaitCursor waitCursor;
  2545. hr = QueryComponentDataRef ().DeleteCTLFromResultPane (pCTL,
  2546. pDataObject);
  2547. if ( SUCCEEDED (hr) )
  2548. {
  2549. pCTL->GetCertStore ().Commit ();
  2550. }
  2551. }
  2552. else
  2553. hr = E_FAIL;
  2554. }
  2555. }
  2556. break;
  2557. case CERTMGR_AUTO_CERT_REQUEST:
  2558. {
  2559. CAutoCertRequest* pACR = reinterpret_cast <CAutoCertRequest*> (pCookie);
  2560. ASSERT (pACR);
  2561. if ( pACR )
  2562. {
  2563. if ( bRequestConfirmation )
  2564. {
  2565. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_ACR));
  2566. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2567. hr = m_pConsole->MessageBox (text, caption, MB_ICONWARNING | MB_YESNO, &iRetVal);
  2568. ASSERT (SUCCEEDED (hr));
  2569. }
  2570. if ( IDYES == iRetVal )
  2571. {
  2572. hr = QueryComponentDataRef ().DeleteCTLFromResultPane (pACR,
  2573. pDataObject);
  2574. if ( SUCCEEDED (hr) )
  2575. {
  2576. pACR->GetCertStore ().Commit ();
  2577. }
  2578. }
  2579. else
  2580. hr = E_FAIL;
  2581. }
  2582. }
  2583. break;
  2584. case CERTMGR_SAFER_COMPUTER_ENTRY:
  2585. case CERTMGR_SAFER_USER_ENTRY:
  2586. {
  2587. CSaferEntry* pSaferEntry = reinterpret_cast <CSaferEntry*> (pCookie);
  2588. ASSERT (pSaferEntry);
  2589. if ( pSaferEntry )
  2590. {
  2591. if ( bRequestConfirmation )
  2592. {
  2593. if ( bIsMultipleSelect )
  2594. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_MULTI_SAFER_ENTRY));
  2595. else
  2596. VERIFY (text.LoadString (IDS_CONFIRM_DELETE_SAFER_ENTRY));
  2597. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_NODE_NAME));
  2598. hr = m_pConsole->MessageBox (text, caption, MB_ICONWARNING | MB_YESNO, &iRetVal);
  2599. ASSERT (SUCCEEDED (hr));
  2600. }
  2601. if ( IDYES == iRetVal )
  2602. {
  2603. CWaitCursor waitCursor;
  2604. hr = DeleteSaferEntryFromResultPane (pSaferEntry, pDataObject, bDoCommit);
  2605. }
  2606. else
  2607. hr = E_FAIL;
  2608. }
  2609. }
  2610. break;
  2611. default:
  2612. ASSERT (0);
  2613. hr = E_UNEXPECTED;
  2614. break;
  2615. }
  2616. _TRACE (-1, L"Leaving CCertMgrComponent::DeleteCookie: 0x%x\n", hr);
  2617. return hr;
  2618. }
  2619. HRESULT CCertMgrComponent::OnNotifyDelete (LPDATAOBJECT pDataObject)
  2620. {
  2621. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyDelete\n");
  2622. ASSERT (pDataObject);
  2623. if ( !pDataObject )
  2624. return E_POINTER;
  2625. HRESULT hr = S_OK;
  2626. CCertMgrCookie* pCookie =
  2627. QueryComponentDataRef ().ConvertCookie (pDataObject);
  2628. if ( pCookie )
  2629. {
  2630. CWaitCursor waitCursor;
  2631. if ( ((CCertMgrCookie*) MMC_MULTI_SELECT_COOKIE) == pCookie )
  2632. {
  2633. // Is multiple select, get all selected items and paste each one
  2634. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pDataObject);
  2635. ASSERT (pDO);
  2636. if ( pDO )
  2637. {
  2638. // Is multiple select, get all selected items and delete - confirm
  2639. // first deletion only. Don't commit until all are deleted.
  2640. bool bRequestConfirmation = true;
  2641. CCertStore* pCertStore = 0;
  2642. // NTRAID# 129428 Cert UI: Cert snapin: Deleting large
  2643. // number of certificates from the stores takes over 3 minutes
  2644. // Change this to false to do commit only at end.
  2645. bool bDoCommit = false;
  2646. pDO->Reset();
  2647. while (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) != S_FALSE &&
  2648. SUCCEEDED (hr) )
  2649. {
  2650. if ( pCookie->HasOpenPropertyPages () )
  2651. {
  2652. CString text;
  2653. CString caption;
  2654. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2655. text.FormatMessage (IDS_CANT_DELETE_OBJECT_PAGES_OPEN,
  2656. pCookie->GetObjectName ());
  2657. int iRetVal = 0;
  2658. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  2659. MB_OK, &iRetVal)));
  2660. hr = E_FAIL;
  2661. break;
  2662. }
  2663. }
  2664. if ( SUCCEEDED (hr) )
  2665. {
  2666. // If this is the store view, don't commit with each delete but commit
  2667. // all at once at the end.
  2668. pDO->Reset();
  2669. while (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) != S_FALSE &&
  2670. SUCCEEDED (hr) )
  2671. {
  2672. if ( bRequestConfirmation ) // first time through
  2673. {
  2674. if ( CERTMGR_SAFER_COMPUTER_ENTRY == pCookie->m_objecttype ||
  2675. CERTMGR_SAFER_USER_ENTRY == pCookie->m_objecttype )
  2676. {
  2677. }
  2678. // Get the affected store. The store is the same for all the
  2679. // certs in the list if the view mode is by store
  2680. else if ( IDM_STORE_VIEW == QueryComponentDataRef ().m_activeViewPersist )
  2681. {
  2682. bDoCommit = false;
  2683. switch (pCookie->m_objecttype)
  2684. {
  2685. case CERTMGR_CERTIFICATE:
  2686. {
  2687. CCertificate* pCert = dynamic_cast<CCertificate*> (pCookie);
  2688. if ( pCert )
  2689. {
  2690. pCertStore = pCert->GetCertStore ();
  2691. }
  2692. }
  2693. break;
  2694. case CERTMGR_CRL:
  2695. {
  2696. CCRL* pCRL = dynamic_cast<CCRL*> (pCookie);
  2697. if ( pCRL )
  2698. pCertStore = &(pCRL->GetCertStore ());
  2699. }
  2700. break;
  2701. case CERTMGR_CTL:
  2702. {
  2703. CCTL* pCTL = dynamic_cast<CCTL*> (pCookie);
  2704. if ( pCTL )
  2705. pCertStore = &(pCTL->GetCertStore ());
  2706. }
  2707. break;
  2708. case CERTMGR_AUTO_CERT_REQUEST:
  2709. {
  2710. CAutoCertRequest* pAutoCertReq = dynamic_cast <CAutoCertRequest*> (pCookie);
  2711. if ( pAutoCertReq )
  2712. pCertStore = &(pAutoCertReq->GetCertStore ());
  2713. }
  2714. break;
  2715. default:
  2716. ASSERT (0);
  2717. break;
  2718. }
  2719. }
  2720. }
  2721. hr = DeleteCookie (pCookie, pDataObject, bRequestConfirmation, true, bDoCommit);
  2722. bRequestConfirmation = false;
  2723. }
  2724. if ( pCertStore )
  2725. {
  2726. hr = pCertStore->Commit ();
  2727. if ( SUCCEEDED (hr) )
  2728. pCertStore->Resync ();
  2729. }
  2730. else if ( QueryComponentDataRef ().m_pGPEInformation &&
  2731. (CERTMGR_SAFER_COMPUTER_ENTRY == pCookie->m_objecttype ||
  2732. CERTMGR_SAFER_USER_ENTRY == pCookie->m_objecttype ) )
  2733. {
  2734. hr = QueryComponentDataRef ().m_pGPEInformation->PolicyChanged (
  2735. CERTMGR_SAFER_COMPUTER_ENTRY == pCookie->m_objecttype ? TRUE : FALSE,
  2736. FALSE, &g_guidExtension, &g_guidSnapin);
  2737. hr = QueryComponentDataRef ().m_pGPEInformation->PolicyChanged (
  2738. CERTMGR_SAFER_COMPUTER_ENTRY == pCookie->m_objecttype ? TRUE : FALSE,
  2739. FALSE, &g_guidRegExt, &g_guidSnapin);
  2740. }
  2741. }
  2742. }
  2743. }
  2744. else
  2745. {
  2746. if ( pCookie->HasOpenPropertyPages () )
  2747. {
  2748. CString text;
  2749. CString caption;
  2750. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2751. text.FormatMessage (IDS_CANT_DELETE_OBJECT_PAGES_OPEN,
  2752. pCookie->GetObjectName ());
  2753. int iRetVal = 0;
  2754. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  2755. MB_OK, &iRetVal)));
  2756. hr = E_FAIL;
  2757. }
  2758. else
  2759. {
  2760. // If m_pPastedDO == pDataObject then this delete is the
  2761. // result of a paste.
  2762. // In that event, we don't want a confirmation message.
  2763. hr = DeleteCookie (pCookie, pDataObject, m_pPastedDO != pDataObject, false, true);
  2764. }
  2765. }
  2766. }
  2767. if ( m_pPastedDO == pDataObject )
  2768. m_pPastedDO = 0;
  2769. // if ( SUCCEEDED (hr) )
  2770. // hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  2771. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyDelete: 0x%x\n", hr);
  2772. return hr;
  2773. }
  2774. HRESULT CCertMgrComponent::DeleteCertFromResultPane (
  2775. CCertificate * pCert,
  2776. LPDATAOBJECT pDataObject,
  2777. bool bDoCommit)
  2778. {
  2779. _TRACE (1, L"Entering CCertMgrComponent::DeleteCertFromResultPane\n");
  2780. HRESULT hr = S_OK;
  2781. if ( pCert->DeleteFromStore (bDoCommit) )
  2782. {
  2783. if ( IDM_USAGE_VIEW == QueryComponentDataRef ().m_activeViewPersist && m_pLastUsageCookie )
  2784. {
  2785. m_pLastUsageCookie->SetCertCount (m_pLastUsageCookie->GetCertCount () - 1);
  2786. }
  2787. HRESULTITEM itemID;
  2788. hr = m_pResultData->FindItemByLParam ( (LPARAM) pCert, &itemID);
  2789. if ( SUCCEEDED (hr) )
  2790. {
  2791. hr = m_pResultData->DeleteItem (itemID, 0);
  2792. }
  2793. // If we can't succeed in removing this one item, then update the whole panel.
  2794. if ( !SUCCEEDED (hr) )
  2795. {
  2796. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  2797. }
  2798. }
  2799. else
  2800. {
  2801. DWORD dwErr = GetLastError ();
  2802. CString text;
  2803. CString caption;
  2804. CCertStore* pStore = pCert->GetCertStore ();
  2805. if ( pStore )
  2806. {
  2807. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2808. text.FormatMessage (IDS_CANT_DELETE_CERT_FROM_SYSTEM_STORE,
  2809. pStore->GetLocalizedName (),
  2810. GetSystemMessage (dwErr));
  2811. int iRetVal = 0;
  2812. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  2813. MB_OK, &iRetVal)));
  2814. }
  2815. hr = HRESULT_FROM_WIN32 (dwErr);
  2816. }
  2817. _TRACE (-1, L"Leaving CCertMgrComponent::DeleteCertFromResultPane: 0x%x\n", hr);
  2818. return hr;
  2819. }
  2820. HRESULT CCertMgrComponent::DeleteCRLFromResultPane (CCRL * pCRL, LPDATAOBJECT pDataObject)
  2821. {
  2822. _TRACE (1, L"Entering CCertMgrComponent::DeleteCRLFromResultPane\n");
  2823. HRESULT hr = S_OK;
  2824. if ( pCRL->DeleteFromStore () )
  2825. {
  2826. hr = pCRL->GetCertStore ().Commit ();
  2827. ASSERT (SUCCEEDED (hr));
  2828. if ( SUCCEEDED (hr) )
  2829. {
  2830. HRESULTITEM itemID;
  2831. hr = m_pResultData->FindItemByLParam ( (LPARAM) pCRL, &itemID);
  2832. if ( SUCCEEDED (hr) )
  2833. {
  2834. hr = m_pResultData->DeleteItem (itemID, 0);
  2835. }
  2836. else
  2837. {
  2838. _TRACE (0, L"IResultData::FindItemByLParam () failed: 0x%x (%s)\n",
  2839. hr, (PCWSTR) GetSystemMessage (hr));
  2840. }
  2841. // If we can't succeed in removing this one item, then update the whole panel.
  2842. if ( !SUCCEEDED (hr) )
  2843. {
  2844. hr = m_pConsole->UpdateAllViews (pDataObject, 0, 0);
  2845. }
  2846. }
  2847. }
  2848. else
  2849. {
  2850. DisplayAccessDenied ();
  2851. }
  2852. _TRACE (-1, L"Leaving CCertMgrComponent::DeleteCRLFromResultPane: 0x%x\n", hr);
  2853. return hr;
  2854. }
  2855. typedef struct _ENUM_ARG {
  2856. DWORD dwFlags;
  2857. CCertMgrComponent* m_pComp;
  2858. LPCWSTR m_pcszMachineName;
  2859. LPCONSOLE m_pConsole;
  2860. } ENUM_ARG, *PENUM_ARG;
  2861. static BOOL WINAPI EnumIComponentSysCallback (
  2862. IN const void* pwszSystemStore,
  2863. IN DWORD dwFlags,
  2864. IN PCERT_SYSTEM_STORE_INFO /*pStoreInfo*/,
  2865. IN OPTIONAL void* /*pvReserved*/,
  2866. IN OPTIONAL void* pvArg
  2867. )
  2868. {
  2869. _TRACE (1, L"Entering EnumIComponentSysCallback\n");
  2870. PENUM_ARG pEnumArg = (PENUM_ARG) pvArg;
  2871. // Create new cookies
  2872. SPECIAL_STORE_TYPE storeType = GetSpecialStoreType ((LPWSTR) pwszSystemStore);
  2873. if ( pEnumArg->m_pComp->QueryComponentDataRef ().ShowArchivedCerts () )
  2874. dwFlags |= CERT_STORE_ENUM_ARCHIVED_FLAG;
  2875. //
  2876. // We will not expose the ACRS store for machines or users. It is not
  2877. // interesting or useful at this level. All Auto Cert Requests should
  2878. // be managed only at the policy level.
  2879. //
  2880. if ( ACRS_STORE != storeType )
  2881. {
  2882. CCertStore* pNewCookie = new CCertStore (
  2883. CERTMGR_LOG_STORE,
  2884. CERT_STORE_PROV_SYSTEM,
  2885. dwFlags,
  2886. pEnumArg->m_pcszMachineName,
  2887. (LPCWSTR) pwszSystemStore,
  2888. (LPCWSTR) pwszSystemStore,
  2889. _T (""),
  2890. storeType,
  2891. dwFlags,
  2892. pEnumArg->m_pConsole);
  2893. if ( pNewCookie )
  2894. pEnumArg->m_pComp->m_usageStoreList.AddTail (pNewCookie);
  2895. }
  2896. _TRACE (-1, L"Leaving EnumIComponentSysCallback\n");
  2897. return TRUE;
  2898. }
  2899. HRESULT CCertMgrComponent::EnumerateLogicalStores (CCertMgrCookie& parentCookie)
  2900. {
  2901. _TRACE (1, L"Entering CCertMgrComponent::EnumerateLogicalStores\n");
  2902. CWaitCursor cursor;
  2903. HRESULT hr = S_OK;
  2904. ENUM_ARG enumArg;
  2905. CCertMgrComponentData& compData = QueryComponentDataRef ();
  2906. DWORD dwFlags = compData.GetLocation ();
  2907. ::ZeroMemory (&enumArg, sizeof (enumArg));
  2908. enumArg.dwFlags = dwFlags;
  2909. enumArg.m_pComp = this;
  2910. enumArg.m_pcszMachineName = parentCookie.QueryNonNULLMachineName ();
  2911. enumArg.m_pConsole = m_pConsole;
  2912. CString location;
  2913. void* pvPara = 0;
  2914. // empty out the store list first
  2915. CCertStore* pCertStore = 0;
  2916. while (!m_usageStoreList.IsEmpty () )
  2917. {
  2918. pCertStore = m_usageStoreList.RemoveHead ();
  2919. ASSERT (pCertStore);
  2920. if ( pCertStore )
  2921. {
  2922. pCertStore->SetDirty ();
  2923. pCertStore->Commit ();
  2924. pCertStore->Release ();
  2925. }
  2926. }
  2927. if ( !compData.GetManagedService ().IsEmpty () )
  2928. {
  2929. if ( !compData.GetManagedComputer ().IsEmpty () )
  2930. {
  2931. location = compData.GetManagedComputer () + _T("\\") +
  2932. compData.GetManagedComputer ();
  2933. pvPara = (void *) (LPCWSTR) location;
  2934. }
  2935. else
  2936. pvPara = (void *) (LPCWSTR) compData.GetManagedService ();
  2937. }
  2938. else if ( !compData.GetManagedComputer ().IsEmpty () )
  2939. {
  2940. pvPara = (void *) (LPCWSTR) compData.GetManagedComputer ();
  2941. }
  2942. CString fileName = compData.GetCommandLineFileName ();
  2943. if ( fileName.IsEmpty () )
  2944. {
  2945. // Ensure creation of MY store
  2946. HCERTSTORE hTempStore = ::CertOpenStore (CERT_STORE_PROV_SYSTEM,
  2947. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, NULL,
  2948. dwFlags | CERT_STORE_SET_LOCALIZED_NAME_FLAG,
  2949. MY_SYSTEM_STORE_NAME);
  2950. if ( hTempStore ) // otherwise, store is read only
  2951. {
  2952. VERIFY (::CertCloseStore (hTempStore, CERT_CLOSE_STORE_CHECK_FLAG));
  2953. }
  2954. else
  2955. {
  2956. _TRACE (0, L"CertOpenStore (%s) failed: 0x%x\n",
  2957. MY_SYSTEM_STORE_NAME, GetLastError ());
  2958. }
  2959. if ( !::CertEnumSystemStore (dwFlags, pvPara, &enumArg,
  2960. EnumIComponentSysCallback) )
  2961. {
  2962. DWORD dwErr = GetLastError ();
  2963. CString text;
  2964. CString caption;
  2965. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  2966. if ( ERROR_ACCESS_DENIED == dwErr )
  2967. {
  2968. VERIFY (text.LoadString (IDS_NO_PERMISSION));
  2969. }
  2970. else
  2971. {
  2972. text.FormatMessage (IDS_CANT_ENUMERATE_SYSTEM_STORES, GetSystemMessage (dwErr));
  2973. }
  2974. int iRetVal = 0;
  2975. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  2976. MB_OK, &iRetVal)));
  2977. hr = HRESULT_FROM_WIN32 (dwErr);
  2978. }
  2979. }
  2980. else
  2981. {
  2982. // Create new cookies
  2983. CCertStore* pNewCookie = new CCertStore (
  2984. CERTMGR_LOG_STORE,
  2985. CERT_STORE_PROV_FILENAME_W,
  2986. 0, //dwFlags,
  2987. parentCookie.QueryNonNULLMachineName (),
  2988. fileName, fileName, _T (""), NO_SPECIAL_TYPE,
  2989. QueryComponentDataRef ().GetLocation (),
  2990. m_pConsole);
  2991. if ( pNewCookie )
  2992. m_usageStoreList.AddTail (pNewCookie);
  2993. }
  2994. _TRACE (-1, L"Leaving CCertMgrComponent::EnumerateLogicalStores: 0x%x\n", hr);
  2995. return hr;
  2996. }
  2997. HRESULT CCertMgrComponent::EnumCertsByUsage (CUsageCookie * pUsageCookie)
  2998. {
  2999. _TRACE (1, L"Entering CCertMgrComponent::EnumCertsByUsage\n");
  3000. ASSERT (pUsageCookie);
  3001. if ( !pUsageCookie )
  3002. return E_POINTER;
  3003. CCertMgrComponentData& compData = QueryComponentDataRef ();
  3004. HRESULT hr = m_pResultData->DeleteAllRsltItems ();
  3005. if ( SUCCEEDED (hr) )
  3006. {
  3007. compData.RemoveResultCookies (m_pResultData);
  3008. }
  3009. if ( m_bShowArchivedCertsStateWhenLogStoresEnumerated !=
  3010. compData.ShowArchivedCerts () )
  3011. {
  3012. m_bShowArchivedCertsStateWhenLogStoresEnumerated =
  3013. compData.ShowArchivedCerts ();
  3014. m_bUsageStoresEnumerated = false;
  3015. CloseAndReleaseUsageStores ();
  3016. }
  3017. // Enumerate system stores, if not already done
  3018. if ( !m_bUsageStoresEnumerated && pUsageCookie )
  3019. {
  3020. hr = EnumerateLogicalStores (*pUsageCookie);
  3021. m_bUsageStoresEnumerated = true;
  3022. }
  3023. // Iterate through stores and find certs for given Oid.
  3024. CCertStore* pCertStore = 0;
  3025. CCookie& rootCookie = compData.QueryBaseRootCookie ();
  3026. int nCertCount = 0;
  3027. for (POSITION pos = m_usageStoreList.GetHeadPosition (); pos; )
  3028. {
  3029. pCertStore = m_usageStoreList.GetNext (pos);
  3030. ASSERT (pCertStore);
  3031. if ( pCertStore )
  3032. {
  3033. int nOIDCount = pUsageCookie->GetOIDCount ();
  3034. ASSERT (nOIDCount > 0);
  3035. if ( nOIDCount <= 0 )
  3036. continue;
  3037. CERT_ENHKEY_USAGE enhKeyUsage;
  3038. enhKeyUsage.cUsageIdentifier = nOIDCount;
  3039. enhKeyUsage.rgpszUsageIdentifier = new LPSTR [nOIDCount];
  3040. if ( enhKeyUsage.rgpszUsageIdentifier )
  3041. {
  3042. for (int nIndex = 0; nIndex < nOIDCount; nIndex++)
  3043. {
  3044. enhKeyUsage.rgpszUsageIdentifier[nIndex] =
  3045. (!nIndex) ?
  3046. pUsageCookie->GetFirstOID () :
  3047. pUsageCookie->GetNextOID ();
  3048. }
  3049. PCCERT_CONTEXT pPrevCertContext = 0;
  3050. PCCERT_CONTEXT pCertContext = 0;
  3051. CCertificate* pCert = 0;
  3052. DWORD dwErr = 0;
  3053. RESULTDATAITEM rdItem;
  3054. void* pvPara = (void *) &enhKeyUsage;
  3055. ::ZeroMemory (&rdItem, sizeof (rdItem));
  3056. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  3057. rdItem.nImage = iIconCertificate;
  3058. rdItem.nCol = 0;
  3059. bool bDone = false;
  3060. while ( !bDone )
  3061. {
  3062. pCertContext = pCertStore->FindCertificate (
  3063. CERT_FIND_VALID_ENHKEY_USAGE_FLAG |
  3064. CERT_FIND_OPTIONAL_ENHKEY_USAGE_FLAG, // | CERT_FIND_OR_ENHKEY_USAGE_FLAG ,
  3065. CERT_FIND_ENHKEY_USAGE,
  3066. pvPara,
  3067. pPrevCertContext);
  3068. if ( !pCertContext )
  3069. {
  3070. dwErr = GetLastError ();
  3071. switch (dwErr)
  3072. {
  3073. case CRYPT_E_NOT_FOUND: // We're done. No more certificates.
  3074. break;
  3075. case 0: // no error to display
  3076. break;
  3077. case E_INVALIDARG:
  3078. if ( !pCertStore->GetStoreHandle () )
  3079. {
  3080. CString text;
  3081. CString caption;
  3082. int iRetVal = IDNO;
  3083. text.FormatMessage
  3084. (IDS_CANNOT_OPEN_CERT_STORE_TO_FIND_CERT_BY_PURPOSE,
  3085. pCertStore->GetLocalizedName ());
  3086. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  3087. hr = m_pConsole->MessageBox (text, caption,
  3088. MB_ICONWARNING | MB_OK, &iRetVal);
  3089. break;
  3090. }
  3091. // fall through
  3092. default:
  3093. compData.DisplaySystemError (dwErr);
  3094. break;
  3095. }
  3096. bDone = true;
  3097. continue;
  3098. }
  3099. pCert =
  3100. new CCertificate (pCertContext, pCertStore);
  3101. if ( !pCert )
  3102. {
  3103. // Do this twice. Must reduce ref count by 2
  3104. ::CertFreeCertificateContext (pCertContext);
  3105. ::CertFreeCertificateContext (pCertContext);
  3106. hr = E_OUTOFMEMORY;
  3107. break;
  3108. }
  3109. nCertCount++;
  3110. rootCookie.m_listResultCookieBlocks.AddHead (pCert);
  3111. rdItem.str = MMC_CALLBACK;
  3112. rdItem.lParam = (LPARAM) pCert;
  3113. pCert->m_resultDataID = m_pResultData;
  3114. hr = m_pResultData->InsertItem (&rdItem);
  3115. ASSERT (SUCCEEDED (hr));
  3116. pPrevCertContext = pCertContext;
  3117. }
  3118. pCertStore->Close ();
  3119. delete [] enhKeyUsage.rgpszUsageIdentifier;
  3120. }
  3121. else
  3122. {
  3123. hr = E_OUTOFMEMORY;
  3124. break;
  3125. }
  3126. }
  3127. }
  3128. pUsageCookie->SetCertCount (nCertCount);
  3129. hr = DisplayCertificateCountByUsage (
  3130. pUsageCookie->GetObjectName (),
  3131. pUsageCookie->GetCertCount ());
  3132. _TRACE (-1, L"Leaving CCertMgrComponent::EnumCertsByUsage: 0x%x\n", hr);
  3133. return hr;
  3134. }
  3135. // This compare is used to sort the items in the listview
  3136. //
  3137. // Parameters:
  3138. //
  3139. // lUserParam - user param passed in when IResultData::Sort () was called
  3140. // cookieA - first item to compare
  3141. // cookieB - second item to compare
  3142. // pnResult [in, out]- contains the col on entry,
  3143. // -1, 0, 1 based on comparison for return value.
  3144. //
  3145. // Note: Assume sort is ascending when comparing.
  3146. STDMETHODIMP CCertMgrComponent::Compare (
  3147. LPARAM /*lUserParam*/,
  3148. MMC_COOKIE cookieA,
  3149. MMC_COOKIE cookieB,
  3150. int* pnResult)
  3151. {
  3152. HRESULT hr = S_OK;
  3153. if ( pnResult && cookieA && cookieB )
  3154. {
  3155. int colNum = *pnResult;
  3156. if ( CERTMGR_MULTISEL == m_currResultNodeType )
  3157. {
  3158. CCertMgrCookie* pCookie = reinterpret_cast<CCertMgrCookie*> (cookieA);
  3159. if ( pCookie )
  3160. {
  3161. switch (pCookie->m_objecttype)
  3162. {
  3163. case CERTMGR_CERTIFICATE:
  3164. m_currResultNodeType = CERTMGR_CERTIFICATE;
  3165. break;
  3166. case CERTMGR_CTL:
  3167. m_currResultNodeType = CERTMGR_CTL;
  3168. break;
  3169. case CERTMGR_CRL:
  3170. m_currResultNodeType = CERTMGR_CRL;
  3171. break;
  3172. default:
  3173. break;
  3174. }
  3175. }
  3176. }
  3177. CCertMgrCookie* pCookieA = reinterpret_cast <CCertificate*> (cookieA);
  3178. CCertMgrCookie* pCookieB = reinterpret_cast <CCertificate*> (cookieB);
  3179. switch (m_currResultNodeType)
  3180. {
  3181. case CERTMGR_CERTIFICATE:
  3182. {
  3183. ASSERT (CERTMGR_CERTIFICATE == pCookieA->m_objecttype &&
  3184. CERTMGR_CERTIFICATE == pCookieB->m_objecttype);
  3185. if ( CERTMGR_CERTIFICATE == pCookieA->m_objecttype &&
  3186. CERTMGR_CERTIFICATE == pCookieB->m_objecttype )
  3187. {
  3188. m_nSelectedCertColumn = colNum;
  3189. CCertificate* pCertA = reinterpret_cast <CCertificate*> (cookieA);
  3190. CCertificate* pCertB = reinterpret_cast <CCertificate*> (cookieB);
  3191. switch ( colNum )
  3192. {
  3193. case COLNUM_CERT_SUBJECT:
  3194. *pnResult = LocaleStrCmp (pCertA->GetSubjectName (),
  3195. pCertB->GetSubjectName ());
  3196. break;
  3197. case COLNUM_CERT_ISSUER:
  3198. *pnResult = LocaleStrCmp (pCertA->GetIssuerName (),
  3199. pCertB->GetIssuerName ());
  3200. break;
  3201. case COLNUM_CERT_EXPIRATION_DATE:
  3202. *pnResult = pCertA->CompareExpireDate (*pCertB);
  3203. break;
  3204. case COLNUM_CERT_PURPOSE:
  3205. *pnResult = LocaleStrCmp (pCertA->GetEnhancedKeyUsage (),
  3206. pCertB->GetEnhancedKeyUsage ());
  3207. break;
  3208. case COLNUM_CERT_CERT_NAME:
  3209. *pnResult = LocaleStrCmp (pCertA->GetFriendlyName (),
  3210. pCertB->GetFriendlyName ());
  3211. break;
  3212. case COLNUM_CERT_STATUS:
  3213. *pnResult = LocaleStrCmp (pCertA->FormatStatus (),
  3214. pCertB->FormatStatus ());
  3215. break;
  3216. // NTRAID# 247237 Cert UI: Cert Snapin: Certificates snapin should show template name
  3217. case COLNUM_CERT_TEMPLATE:
  3218. *pnResult = LocaleStrCmp (pCertA->GetTemplateName (),
  3219. pCertB->GetTemplateName ());
  3220. break;
  3221. default:
  3222. ASSERT (0);
  3223. break;
  3224. }
  3225. }
  3226. }
  3227. break;
  3228. case CERTMGR_CRL:
  3229. {
  3230. ASSERT (CERTMGR_CRL == pCookieA->m_objecttype &&
  3231. CERTMGR_CRL == pCookieB->m_objecttype);
  3232. if ( CERTMGR_CRL == pCookieA->m_objecttype &&
  3233. CERTMGR_CRL == pCookieB->m_objecttype )
  3234. {
  3235. m_nSelectedCRLColumn = colNum;
  3236. CCRL* pCRLA = reinterpret_cast <CCRL*> (cookieA);
  3237. CCRL* pCRLB = reinterpret_cast <CCRL*> (cookieB);
  3238. switch ( colNum )
  3239. {
  3240. case COLNUM_CRL_EFFECTIVE_DATE:
  3241. *pnResult = pCRLA->CompareEffectiveDate (*pCRLB);
  3242. break;
  3243. case COLNUM_CRL_ISSUER:
  3244. *pnResult = LocaleStrCmp (pCRLA->GetIssuerName (),
  3245. pCRLB->GetIssuerName ());
  3246. break;
  3247. case COLNUM_CRL_NEXT_UPDATE:
  3248. *pnResult = pCRLA->CompareNextUpdate (*pCRLB);
  3249. break;
  3250. default:
  3251. ASSERT (0);
  3252. break;
  3253. }
  3254. }
  3255. }
  3256. break;
  3257. case CERTMGR_CTL:
  3258. {
  3259. ASSERT (CERTMGR_CTL == pCookieA->m_objecttype &&
  3260. CERTMGR_CTL == pCookieB->m_objecttype);
  3261. if ( CERTMGR_CTL == pCookieA->m_objecttype &&
  3262. CERTMGR_CTL == pCookieB->m_objecttype )
  3263. {
  3264. m_nSelectedCTLColumn = colNum;
  3265. CCTL* pCTLA = reinterpret_cast <CCTL*> (cookieA);
  3266. CCTL* pCTLB = reinterpret_cast <CCTL*> (cookieB);
  3267. switch ( colNum )
  3268. {
  3269. case COLNUM_CTL_ISSUER:
  3270. *pnResult = LocaleStrCmp (pCTLA->GetIssuerName (),
  3271. pCTLB->GetIssuerName ());
  3272. break;
  3273. case COLNUM_CTL_EFFECTIVE_DATE:
  3274. *pnResult = pCTLA->CompareEffectiveDate (*pCTLB);
  3275. break;
  3276. case COLNUM_CTL_PURPOSE:
  3277. *pnResult = LocaleStrCmp (pCTLA->GetPurpose (),
  3278. pCTLB->GetPurpose ());
  3279. break;
  3280. case COLNUM_CTL_FRIENDLY_NAME:
  3281. default:
  3282. ASSERT (0);
  3283. break;
  3284. }
  3285. }
  3286. }
  3287. break;
  3288. case CERTMGR_AUTO_CERT_REQUEST:
  3289. {
  3290. ASSERT (CERTMGR_AUTO_CERT_REQUEST == pCookieA->m_objecttype &&
  3291. CERTMGR_AUTO_CERT_REQUEST == pCookieB->m_objecttype);
  3292. if ( CERTMGR_AUTO_CERT_REQUEST == pCookieA->m_objecttype &&
  3293. CERTMGR_AUTO_CERT_REQUEST == pCookieB->m_objecttype )
  3294. {
  3295. CAutoCertRequest* pAutoCertA = reinterpret_cast <CAutoCertRequest*> (cookieA);
  3296. CAutoCertRequest* pAutoCertB = reinterpret_cast <CAutoCertRequest*> (cookieB);
  3297. switch ( colNum )
  3298. {
  3299. case 0:
  3300. {
  3301. CString strA;
  3302. CString strB;
  3303. VERIFY (SUCCEEDED (pAutoCertA->GetCertTypeName (strA)));
  3304. VERIFY (SUCCEEDED (pAutoCertB->GetCertTypeName (strB)));
  3305. *pnResult = LocaleStrCmp (strA, strB);
  3306. }
  3307. break;
  3308. default:
  3309. ASSERT (0);
  3310. break;
  3311. }
  3312. }
  3313. }
  3314. case CERTMGR_SAFER_COMPUTER_ENTRY:
  3315. case CERTMGR_SAFER_USER_ENTRY:
  3316. {
  3317. CSaferEntry* pSaferEntryA = reinterpret_cast <CSaferEntry*> (cookieA);
  3318. CSaferEntry* pSaferEntryB = reinterpret_cast <CSaferEntry*> (cookieB);
  3319. m_nSelectedSaferEntryColumn = colNum;
  3320. switch (colNum)
  3321. {
  3322. case COLNUM_SAFER_ENTRIES_NAME:
  3323. *pnResult = LocaleStrCmp (pSaferEntryA->GetObjectName (),
  3324. pSaferEntryB->GetObjectName ());
  3325. break;
  3326. case COLNUM_SAFER_ENTRIES_TYPE:
  3327. *pnResult = LocaleStrCmp (pSaferEntryA->GetTypeString (),
  3328. pSaferEntryB->GetTypeString ());
  3329. break;
  3330. case COLNUM_SAFER_ENTRIES_LEVEL:
  3331. *pnResult = LocaleStrCmp (pSaferEntryA->GetLevelFriendlyName (),
  3332. pSaferEntryB->GetLevelFriendlyName ());
  3333. break;
  3334. case COLNUM_SAFER_ENTRIES_DESCRIPTION:
  3335. *pnResult = LocaleStrCmp (pSaferEntryA->GetDescription (),
  3336. pSaferEntryB->GetDescription ());
  3337. break;
  3338. case COLNUM_SAFER_ENTRIES_LAST_MODIFIED_DATE:
  3339. *pnResult = pSaferEntryA->CompareLastModified (*pSaferEntryB);
  3340. break;
  3341. }
  3342. }
  3343. break;
  3344. default:
  3345. break;
  3346. }
  3347. }
  3348. return hr;
  3349. }
  3350. HRESULT CCertMgrComponent::EnumCTLs (CCertStore& rCertStore)
  3351. {
  3352. _TRACE (1, L"Entering CCertMgrComponent::EnumCTLs\n");
  3353. CCertMgrComponentData& compdata = QueryComponentDataRef ();
  3354. RESULTDATAITEM rdItem;
  3355. CWaitCursor cursor;
  3356. PCCTL_CONTEXT pCTLContext = 0;
  3357. HRESULT hr = 0;
  3358. CCTL* pCTL = 0;
  3359. CCookie& rootCookie = compdata.QueryBaseRootCookie ();
  3360. CTypedPtrList<CPtrList, CCertStore*> storeList;
  3361. // Only enumerate the logical stores if this is not the GPE or RSOP. If it is the
  3362. // GPE, add the Trust and Root store.
  3363. if ( !compdata.m_pGPEInformation && !compdata.m_bIsRSOP )
  3364. {
  3365. hr = compdata.EnumerateLogicalStores (&storeList);
  3366. ASSERT (SUCCEEDED (hr));
  3367. }
  3368. else
  3369. {
  3370. if ( compdata.m_pGPERootStore )
  3371. {
  3372. compdata.m_pGPERootStore->AddRef ();
  3373. storeList.AddTail (compdata.m_pGPERootStore);
  3374. }
  3375. if ( compdata.m_pGPETrustStore )
  3376. {
  3377. compdata.m_pGPETrustStore->AddRef ();
  3378. storeList.AddTail (compdata.m_pGPETrustStore);
  3379. }
  3380. }
  3381. if ( compdata.m_pFileBasedStore )
  3382. {
  3383. compdata.m_pFileBasedStore->AddRef ();
  3384. storeList.AddTail (compdata.m_pFileBasedStore);
  3385. }
  3386. ::ZeroMemory (&rdItem, sizeof (rdItem));
  3387. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
  3388. rdItem.nCol = 0; // Must always be 0
  3389. while ( 1 )
  3390. {
  3391. pCTLContext = rCertStore.EnumCTLs (pCTLContext);
  3392. if ( !pCTLContext )
  3393. break;
  3394. if ( ACRS_STORE == rCertStore.GetStoreType () )
  3395. {
  3396. pCTL =
  3397. new CAutoCertRequest (pCTLContext, rCertStore);
  3398. }
  3399. else
  3400. {
  3401. pCTL =
  3402. new CCTL (pCTLContext, rCertStore, CERTMGR_CTL, &storeList);
  3403. }
  3404. if ( !pCTL )
  3405. {
  3406. hr = E_OUTOFMEMORY;
  3407. break;
  3408. }
  3409. if ( ACRS_STORE != rCertStore.GetStoreType () )
  3410. rdItem.nImage = iIconCTL;
  3411. else
  3412. rdItem.nImage = 0;
  3413. rootCookie.m_listResultCookieBlocks.AddHead (pCTL);
  3414. rdItem.str = MMC_TEXTCALLBACK;
  3415. rdItem.lParam = (LPARAM) pCTL;
  3416. pCTL->m_resultDataID = m_pResultData;
  3417. hr = m_pResultData->InsertItem (&rdItem);
  3418. ASSERT (SUCCEEDED (hr));
  3419. }
  3420. rCertStore.Close ();
  3421. CCertStore* pStore = 0;
  3422. // Clean up store list
  3423. while (!storeList.IsEmpty () )
  3424. {
  3425. pStore = storeList.RemoveHead ();
  3426. ASSERT (pStore);
  3427. if ( pStore )
  3428. {
  3429. pStore->Close ();
  3430. pStore->Release ();
  3431. }
  3432. }
  3433. _TRACE (-1, L"Leaving CCertMgrComponent::EnumCTLs: 0x%x\n", hr);
  3434. return hr;
  3435. }
  3436. STDMETHODIMP CCertMgrComponent::Notify (LPDATAOBJECT pDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  3437. {
  3438. _TRACE (1, L"Entering CCertMgrComponent::Notify\n");
  3439. HRESULT hr = S_OK;
  3440. switch (event)
  3441. {
  3442. case MMCN_CUTORMOVE:
  3443. hr = OnNotifyCutOrMove (arg);
  3444. break;
  3445. case MMCN_QUERY_PASTE:
  3446. hr = OnNotifyQueryPaste (pDataObject, arg, param);
  3447. break;
  3448. case MMCN_PASTE:
  3449. hr = OnNotifyPaste (pDataObject, arg, param);
  3450. break;
  3451. case MMCN_SHOW:
  3452. // CODEWORK this is hacked together quickly
  3453. {
  3454. CCookie* pCookie = NULL;
  3455. hr = ExtractData (pDataObject,
  3456. CDataObject::m_CFRawCookie,
  3457. &pCookie,
  3458. sizeof(pCookie));
  3459. if ( SUCCEEDED (hr) )
  3460. {
  3461. hr = Show (ActiveBaseCookie (pCookie), arg,
  3462. (HSCOPEITEM) param, pDataObject);
  3463. }
  3464. }
  3465. break;
  3466. case MMCN_CANPASTE_OUTOFPROC:
  3467. hr = OnNotifyCanPasteOutOfProc (reinterpret_cast<LPBOOL>(param));
  3468. break;
  3469. default:
  3470. hr = CComponent::Notify (pDataObject, event, arg, param);
  3471. }
  3472. _TRACE (-1, L"Leaving CCertMgrComponent::Notify: 0x%x\n", hr);
  3473. return hr;
  3474. }
  3475. void CCertMgrComponent::DisplayAccessDenied ()
  3476. {
  3477. _TRACE (1, L"Entering CCertMgrComponent::DisplayAccessDenied\n");
  3478. DWORD dwErr = GetLastError ();
  3479. ASSERT (E_ACCESSDENIED == dwErr);
  3480. if ( E_ACCESSDENIED == dwErr )
  3481. {
  3482. LPVOID lpMsgBuf;
  3483. FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  3484. NULL,
  3485. GetLastError (),
  3486. MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  3487. (LPWSTR) &lpMsgBuf, 0, NULL );
  3488. // Display the string.
  3489. CString caption;
  3490. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  3491. int iRetVal = 0;
  3492. VERIFY (SUCCEEDED (m_pConsole->MessageBox ( (LPWSTR) lpMsgBuf, caption,
  3493. MB_ICONWARNING | MB_OK, &iRetVal)));
  3494. // Free the buffer.
  3495. LocalFree (lpMsgBuf);
  3496. }
  3497. _TRACE (-1, L"Leaving CCertMgrComponent::DisplayAccessDenied\n");
  3498. }
  3499. HRESULT CCertMgrComponent::OnNotifyPaste (LPDATAOBJECT pDataObject, LPARAM arg, LPARAM param)
  3500. {
  3501. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyPaste\n");
  3502. ASSERT (pDataObject && arg);
  3503. if ( !pDataObject || !arg )
  3504. return E_POINTER;
  3505. HRESULT hr = S_OK;
  3506. CCertMgrComponentData& dataRef = QueryComponentDataRef ();
  3507. HSCOPEITEM hScopeItem = -1;
  3508. bool bContainsCerts = false;
  3509. bool bContainsCTLs = false;
  3510. bool bContainsCRLs = false;
  3511. CCertMgrCookie* pTargetCookie = dataRef.ConvertCookie (pDataObject);
  3512. ASSERT (pTargetCookie);
  3513. if ( pTargetCookie )
  3514. {
  3515. CCertStore* pCertStore = 0;
  3516. SPECIAL_STORE_TYPE storeType = NO_SPECIAL_TYPE;
  3517. switch (pTargetCookie->m_objecttype)
  3518. {
  3519. case CERTMGR_PHYS_STORE:
  3520. case CERTMGR_LOG_STORE:
  3521. case CERTMGR_LOG_STORE_GPE:
  3522. case CERTMGR_LOG_STORE_RSOP:
  3523. {
  3524. pCertStore = reinterpret_cast <CCertStore*>
  3525. (pTargetCookie);
  3526. ASSERT (pCertStore);
  3527. if ( pCertStore )
  3528. {
  3529. storeType = pCertStore->GetStoreType ();
  3530. hScopeItem = pCertStore->m_hScopeItem;
  3531. bContainsCerts = pCertStore->ContainsCertificates ();
  3532. bContainsCRLs = pCertStore->ContainsCRLs ();
  3533. bContainsCTLs = pCertStore->ContainsCTLs ();
  3534. ASSERT (-1 != hScopeItem);
  3535. }
  3536. else
  3537. hr = E_POINTER;
  3538. }
  3539. break;
  3540. case CERTMGR_CRL_CONTAINER:
  3541. {
  3542. bContainsCRLs = true;
  3543. CContainerCookie* pCont = reinterpret_cast <CContainerCookie*>
  3544. (pTargetCookie);
  3545. ASSERT (pCont);
  3546. if ( pCont )
  3547. {
  3548. pCertStore = &(pCont->GetCertStore ());
  3549. storeType = pCont->GetStoreType ();
  3550. }
  3551. else
  3552. hr = E_POINTER;
  3553. }
  3554. break;
  3555. case CERTMGR_CTL_CONTAINER:
  3556. {
  3557. bContainsCTLs = true;
  3558. CContainerCookie* pCont = reinterpret_cast <CContainerCookie*>
  3559. (pTargetCookie);
  3560. ASSERT (pCont);
  3561. if ( pCont )
  3562. {
  3563. pCertStore = &(pCont->GetCertStore ());
  3564. storeType = pCont->GetStoreType ();
  3565. }
  3566. else
  3567. hr = E_POINTER;
  3568. }
  3569. break;
  3570. case CERTMGR_CERT_CONTAINER:
  3571. {
  3572. bContainsCerts = true;
  3573. CContainerCookie* pCont = reinterpret_cast <CContainerCookie*>
  3574. (pTargetCookie);
  3575. ASSERT (pCont);
  3576. if ( pCont )
  3577. {
  3578. pCertStore = &(pCont->GetCertStore ());
  3579. storeType = pCont->GetStoreType ();
  3580. }
  3581. else
  3582. hr = E_POINTER;
  3583. }
  3584. break;
  3585. case CERTMGR_CERTIFICATE:
  3586. {
  3587. CCertificate* pCert = reinterpret_cast <CCertificate*> (pTargetCookie);
  3588. ASSERT (pCert);
  3589. if ( pCert )
  3590. {
  3591. pCertStore = pCert->GetCertStore ();
  3592. storeType = pCert->GetStoreType ();
  3593. }
  3594. else
  3595. hr = E_POINTER;
  3596. }
  3597. break;
  3598. case CERTMGR_CRL:
  3599. {
  3600. CCRL* pCRL = reinterpret_cast <CCRL*> (pTargetCookie);
  3601. ASSERT (pCRL);
  3602. if ( pCRL )
  3603. {
  3604. pCertStore = &(pCRL->GetCertStore ());
  3605. }
  3606. else
  3607. hr = E_POINTER;
  3608. }
  3609. break;
  3610. case CERTMGR_CTL:
  3611. {
  3612. CCTL* pCTL = reinterpret_cast <CCTL*> (pTargetCookie);
  3613. ASSERT (pCTL);
  3614. if ( pCTL )
  3615. {
  3616. pCertStore = &(pCTL->GetCertStore ());
  3617. }
  3618. else
  3619. hr = E_POINTER;
  3620. }
  3621. break;
  3622. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  3623. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  3624. ASSERT (0);
  3625. break;
  3626. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  3627. case CERTMGR_SAFER_USER_ENTRIES:
  3628. {
  3629. param = 0; // do not allow cut/move of originating cert
  3630. CSaferEntries* pSaferEntries = dynamic_cast <CSaferEntries*> (pTargetCookie);
  3631. if ( pSaferEntries )
  3632. {
  3633. CCertStore* pGPEStore = 0;
  3634. bool bIsComputer =
  3635. (CERTMGR_SAFER_COMPUTER_ENTRIES == pTargetCookie->m_objecttype);
  3636. DWORD dwDefaultLevelID = CSaferLevel::ReturnDefaultLevel (
  3637. dataRef.m_pGPEInformation,
  3638. bIsComputer ? true : false,
  3639. bIsComputer ? dataRef.m_rsopObjectArrayComputer : dataRef.m_rsopObjectArrayUser);
  3640. if ( SAFER_LEVELID_DISALLOWED== dwDefaultLevelID )
  3641. hr = pSaferEntries->GetTrustedPublishersStore (&pGPEStore);
  3642. else
  3643. hr = pSaferEntries->GetDisallowedStore (&pGPEStore);
  3644. if ( SUCCEEDED (hr) )
  3645. {
  3646. pCertStore = pGPEStore;
  3647. }
  3648. }
  3649. }
  3650. break;
  3651. default:
  3652. hr = E_UNEXPECTED;
  3653. break;
  3654. }
  3655. if ( !SUCCEEDED (hr) )
  3656. return hr;
  3657. CCertMgrCookie* pPastedCookie =
  3658. dataRef.ConvertCookie ((LPDATAOBJECT) arg);
  3659. if ( pPastedCookie && pCertStore )
  3660. {
  3661. if ( ((CCertMgrCookie*) MMC_MULTI_SELECT_COOKIE) == pPastedCookie )
  3662. {
  3663. LPDATAOBJECT* ppDO = reinterpret_cast<LPDATAOBJECT*>((LPDATAOBJECT) param);
  3664. CCookiePtrArray rgCookiesCopied;
  3665. // Is multiple select, get all selected items and paste each one
  3666. LPDATAOBJECT pMSDO = (LPDATAOBJECT) arg;
  3667. if ( pMSDO )
  3668. {
  3669. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pMSDO);
  3670. ASSERT (pDO);
  3671. if ( pDO )
  3672. {
  3673. bool bRequestConfirmation = true;
  3674. CCertMgrCookie* pCookie = 0;
  3675. pDO->Reset();
  3676. while (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) != S_FALSE)
  3677. {
  3678. hr = PasteCookie (pCookie, pTargetCookie, *pCertStore,
  3679. storeType, bContainsCerts, bContainsCRLs, bContainsCTLs,
  3680. hScopeItem, bRequestConfirmation, true);
  3681. if ( SUCCEEDED (hr) && ppDO && S_FALSE != hr )
  3682. rgCookiesCopied.Add (pCookie);
  3683. else if ( FAILED (hr) )
  3684. break;
  3685. bRequestConfirmation = false;
  3686. }
  3687. }
  3688. else
  3689. return E_UNEXPECTED;
  3690. }
  3691. else
  3692. return E_UNEXPECTED;
  3693. if ( pCertStore && SUCCEEDED (hr) )
  3694. {
  3695. pCertStore->Commit ();
  3696. }
  3697. else
  3698. pCertStore->Resync ();
  3699. if ( !bContainsCerts )
  3700. {
  3701. // not necessary for certs - they're
  3702. //added to the end
  3703. m_pConsole->UpdateAllViews (pDataObject, 0, HINT_PASTE_COOKIE);
  3704. }
  3705. if ( !ppDO )
  3706. return S_OK;
  3707. *ppDO = 0;
  3708. if ( rgCookiesCopied.GetSize () == 0 )
  3709. return S_FALSE;
  3710. CComObject<CCertMgrDataObject>* pObject = 0;
  3711. hr = CComObject<CCertMgrDataObject>::CreateInstance(&pObject);
  3712. ASSERT(SUCCEEDED(hr));
  3713. if (FAILED(hr))
  3714. return hr;
  3715. ASSERT(pObject != NULL);
  3716. if (pObject == NULL)
  3717. return E_OUTOFMEMORY;
  3718. hr = pObject->Initialize (
  3719. pPastedCookie,
  3720. CCT_UNINITIALIZED,
  3721. FALSE,
  3722. 0,
  3723. L"",
  3724. L"",
  3725. L"",
  3726. dataRef);
  3727. for (int i=0; i < rgCookiesCopied.GetSize(); ++i)
  3728. {
  3729. pObject->AddCookie(rgCookiesCopied[i]);
  3730. }
  3731. hr = pObject->QueryInterface(
  3732. IID_PPV_ARG (IDataObject, ppDO));
  3733. return hr;
  3734. }
  3735. else
  3736. {
  3737. hr = PasteCookie (pPastedCookie, pTargetCookie, *pCertStore,
  3738. storeType, bContainsCerts, bContainsCRLs, bContainsCTLs,
  3739. hScopeItem, true, false);
  3740. if ( pCertStore && SUCCEEDED (hr) )
  3741. {
  3742. if ( param ) // a non-NULL value indicates that a cut/move is desired
  3743. {
  3744. LPDATAOBJECT srcDO = (LPDATAOBJECT) arg;
  3745. LPDATAOBJECT* ppDO = reinterpret_cast<LPDATAOBJECT*>(param);
  3746. hr = srcDO->QueryInterface(
  3747. IID_PPV_ARG (IDataObject, ppDO));
  3748. }
  3749. m_pPastedDO = (LPDATAOBJECT) arg;
  3750. pCertStore->Commit ();
  3751. }
  3752. else
  3753. pCertStore->Resync ();
  3754. if ( !bContainsCerts )
  3755. {
  3756. // not necessary for certs - they're
  3757. //added to the end
  3758. m_pConsole->UpdateAllViews (pDataObject, 0, HINT_PASTE_COOKIE);
  3759. }
  3760. }
  3761. }
  3762. }
  3763. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyPaste: 0x%x\n", hr);
  3764. return hr;
  3765. }
  3766. HRESULT CCertMgrComponent::PasteCookie (
  3767. CCertMgrCookie* pPastedCookie,
  3768. CCertMgrCookie* pTargetCookie,
  3769. CCertStore& rCertStore,
  3770. SPECIAL_STORE_TYPE storeType,
  3771. bool bContainsCerts,
  3772. bool bContainsCRLs,
  3773. bool bContainsCTLs,
  3774. HSCOPEITEM hScopeItem,
  3775. bool bRequestConfirmation,
  3776. bool bIsMultipleSelect)
  3777. {
  3778. _TRACE (1, L"Entering CCertMgrComponent::PasteCookie\n");
  3779. HRESULT hr = S_OK;
  3780. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  3781. switch (pPastedCookie->m_objecttype)
  3782. {
  3783. case CERTMGR_CERTIFICATE:
  3784. {
  3785. CCertificate* pCert = reinterpret_cast <CCertificate*>(pPastedCookie);
  3786. ASSERT (pCert);
  3787. if ( pCert )
  3788. {
  3789. DWORD dwFlags = 0;
  3790. CCertStore* pStore = pCert->GetCertStore ();
  3791. if ( pStore )
  3792. {
  3793. if ( CERT_SYSTEM_STORE_LOCAL_MACHINE == QueryComponentDataRef ().m_dwLocationPersist )
  3794. dwFlags = CRYPT_FIND_MACHINE_KEYSET_FLAG;
  3795. bool bDeletePrivateKey = DeletePrivateKey (rCertStore, *pStore);
  3796. if ( bRequestConfirmation &&
  3797. pCert->GetStoreType () == MY_STORE &&
  3798. bDeletePrivateKey &&
  3799. ::CryptFindCertificateKeyProvInfo (
  3800. pCert->GetCertContext (), dwFlags, 0) )
  3801. {
  3802. CString text;
  3803. CString caption;
  3804. int iRetVal = IDNO;
  3805. if ( bIsMultipleSelect )
  3806. VERIFY (text.LoadString (IDS_WARNING_MULTI_CERT_COPY_W_PRIVATE_KEY_MULTI));
  3807. else
  3808. VERIFY (text.LoadString (IDS_WARNING_CERT_COPY_W_PRIVATE_KEY));
  3809. VERIFY (caption.LoadString (IDS_CERTIFICATE_COPY));
  3810. hr = m_pConsole->MessageBox (text, caption,
  3811. MB_ICONWARNING | MB_YESNO, &iRetVal);
  3812. ASSERT (SUCCEEDED (hr));
  3813. if ( iRetVal == IDNO )
  3814. return E_FAIL;
  3815. }
  3816. hr = CopyPastedCert (pCert, rCertStore, storeType, bDeletePrivateKey,
  3817. pTargetCookie);
  3818. if ( SUCCEEDED (hr) && S_FALSE != hr )
  3819. {
  3820. hr = pTargetCookie->Commit ();
  3821. if ( SUCCEEDED (hr) )
  3822. {
  3823. if ( !bContainsCerts )
  3824. hr = QueryComponentDataRef ().CreateContainers (
  3825. hScopeItem, rCertStore);
  3826. }
  3827. }
  3828. }
  3829. }
  3830. else
  3831. hr = E_POINTER;
  3832. }
  3833. break;
  3834. case CERTMGR_CRL:
  3835. {
  3836. CCRL* pCRL = reinterpret_cast <CCRL*>(pPastedCookie);
  3837. ASSERT (pCRL);
  3838. if ( pCRL )
  3839. {
  3840. hr = CopyPastedCRL (pCRL, rCertStore);
  3841. if ( SUCCEEDED (hr) )
  3842. {
  3843. pTargetCookie->Commit ();
  3844. if ( !bContainsCRLs )
  3845. hr = QueryComponentDataRef ().CreateContainers (hScopeItem,
  3846. rCertStore);
  3847. }
  3848. }
  3849. else
  3850. hr = E_POINTER;
  3851. }
  3852. break;
  3853. case CERTMGR_CTL:
  3854. {
  3855. CCTL* pCTL = reinterpret_cast <CCTL*>(pPastedCookie);
  3856. ASSERT (pCTL);
  3857. if ( pCTL )
  3858. {
  3859. hr = CopyPastedCTL (pCTL, rCertStore);
  3860. if ( SUCCEEDED (hr) )
  3861. {
  3862. pTargetCookie->Commit ();
  3863. if ( !bContainsCTLs )
  3864. hr = QueryComponentDataRef ().CreateContainers (hScopeItem,
  3865. rCertStore);
  3866. }
  3867. }
  3868. else
  3869. hr = E_POINTER;
  3870. }
  3871. break;
  3872. case CERTMGR_AUTO_CERT_REQUEST:
  3873. {
  3874. CAutoCertRequest* pAutoCert = reinterpret_cast <CAutoCertRequest*>(pPastedCookie);
  3875. ASSERT (pAutoCert);
  3876. if ( pAutoCert )
  3877. {
  3878. hr = CopyPastedCTL (pAutoCert, rCertStore);
  3879. if ( SUCCEEDED (hr) )
  3880. {
  3881. pTargetCookie->Commit ();
  3882. if ( !bContainsCTLs )
  3883. hr = QueryComponentDataRef ().CreateContainers (hScopeItem,
  3884. rCertStore);
  3885. }
  3886. }
  3887. else
  3888. hr = E_POINTER;
  3889. }
  3890. break;
  3891. default:
  3892. break;
  3893. }
  3894. _TRACE (-1, L"Leaving CCertMgrComponent::PasteCookie: 0x%x\n", hr);
  3895. return hr;
  3896. }
  3897. HRESULT CCertMgrComponent::OnNotifyQueryPaste(
  3898. LPDATAOBJECT pDataObject,
  3899. LPARAM arg,
  3900. LPARAM /*param*/)
  3901. {
  3902. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyQueryPaste\n");
  3903. ASSERT (pDataObject && arg);
  3904. if ( !pDataObject || !arg )
  3905. return E_POINTER;
  3906. HRESULT hr = S_FALSE;
  3907. CCertMgrComponentData& dataRef = QueryComponentDataRef ();
  3908. CCertMgrCookie* pTargetCookie = dataRef.ConvertCookie (pDataObject);
  3909. ASSERT (pTargetCookie);
  3910. if ( pTargetCookie )
  3911. {
  3912. CCertMgrCookie* pPastedCookie =
  3913. dataRef.ConvertCookie ((LPDATAOBJECT) arg);
  3914. if ( pPastedCookie )
  3915. {
  3916. // If this is multi-selection, get the first selected object
  3917. // and substitute it for the pasted cookie.
  3918. if ( ((CCertMgrCookie*) MMC_MULTI_SELECT_COOKIE) == pPastedCookie )
  3919. {
  3920. LPDATAOBJECT pMSDO = (LPDATAOBJECT) arg;
  3921. if ( pMSDO )
  3922. {
  3923. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pMSDO);
  3924. ASSERT (pDO);
  3925. if ( pDO )
  3926. {
  3927. pDO->Reset();
  3928. if (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pPastedCookie), NULL) == S_FALSE)
  3929. {
  3930. return E_UNEXPECTED;
  3931. }
  3932. }
  3933. else
  3934. return E_UNEXPECTED;
  3935. }
  3936. else
  3937. return E_UNEXPECTED;
  3938. }
  3939. switch (pPastedCookie->m_objecttype)
  3940. {
  3941. case CERTMGR_CERTIFICATE:
  3942. switch (pTargetCookie->m_objecttype)
  3943. {
  3944. case CERTMGR_PHYS_STORE:
  3945. case CERTMGR_LOG_STORE:
  3946. {
  3947. CCertStore* pTargetStore = reinterpret_cast <CCertStore*> (pTargetCookie);
  3948. if ( pTargetStore )
  3949. {
  3950. CCertStore* pSourceStore =
  3951. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  3952. if ( pSourceStore )
  3953. {
  3954. if ( pTargetStore->IsReadOnly () )
  3955. hr = S_FALSE;
  3956. else if ( *pSourceStore == *pTargetStore )
  3957. hr = S_FALSE;
  3958. else
  3959. hr = S_OK;
  3960. }
  3961. else
  3962. hr = E_UNEXPECTED;
  3963. }
  3964. else
  3965. hr = E_UNEXPECTED;
  3966. }
  3967. break;
  3968. case CERTMGR_CERT_CONTAINER:
  3969. {
  3970. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pTargetCookie);
  3971. if ( pContainer )
  3972. {
  3973. CCertStore* pSourceStore =
  3974. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  3975. if ( pSourceStore )
  3976. {
  3977. if ( pContainer->GetCertStore ().IsReadOnly () )
  3978. hr = S_FALSE;
  3979. else if ( *pSourceStore == pContainer->GetCertStore () )
  3980. hr = S_FALSE;
  3981. else
  3982. hr = S_OK;
  3983. }
  3984. else
  3985. hr = E_UNEXPECTED;
  3986. }
  3987. else
  3988. hr = E_UNEXPECTED;
  3989. }
  3990. break;
  3991. case CERTMGR_CERTIFICATE:
  3992. {
  3993. CCertificate* pCert = reinterpret_cast <CCertificate*> (pTargetCookie);
  3994. if ( pCert )
  3995. {
  3996. CCertStore* pSourceStore =
  3997. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  3998. CCertStore* pTargetStore = pCert->GetCertStore ();
  3999. if ( pSourceStore && pTargetStore )
  4000. {
  4001. if ( pTargetStore->IsReadOnly () )
  4002. hr = S_FALSE;
  4003. else if ( *pSourceStore == *pTargetStore )
  4004. hr = S_FALSE;
  4005. else
  4006. hr = S_OK;
  4007. }
  4008. else
  4009. hr = E_UNEXPECTED;
  4010. }
  4011. else
  4012. hr = E_UNEXPECTED;
  4013. }
  4014. break;
  4015. case CERTMGR_LOG_STORE_GPE:
  4016. {
  4017. CCertStoreGPE* pTargetStore =
  4018. reinterpret_cast <CCertStoreGPE*> (pTargetCookie);
  4019. ASSERT (pTargetStore);
  4020. if ( pTargetStore )
  4021. {
  4022. CCertStore* pSourceStore =
  4023. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  4024. if ( pSourceStore )
  4025. {
  4026. if ( *pSourceStore == *pTargetStore )
  4027. hr = S_FALSE;
  4028. else if ( pTargetStore->CanContain (pPastedCookie->m_objecttype) &&
  4029. !pTargetStore->IsReadOnly () )
  4030. hr = S_OK;
  4031. else
  4032. hr = S_OK;
  4033. }
  4034. else
  4035. hr = E_UNEXPECTED;
  4036. }
  4037. else
  4038. hr = E_UNEXPECTED;
  4039. }
  4040. break;
  4041. case CERTMGR_LOG_STORE_RSOP:
  4042. {
  4043. CCertStoreRSOP* pTargetStore =
  4044. reinterpret_cast <CCertStoreRSOP*> (pTargetCookie);
  4045. ASSERT (pTargetStore);
  4046. if ( pTargetStore )
  4047. {
  4048. CCertStore* pSourceStore =
  4049. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  4050. if ( pSourceStore )
  4051. {
  4052. if ( *pSourceStore == *pTargetStore )
  4053. hr = S_FALSE;
  4054. else if ( pTargetStore->CanContain (pPastedCookie->m_objecttype) &&
  4055. !pTargetStore->IsReadOnly () )
  4056. hr = S_OK;
  4057. else
  4058. hr = S_OK;
  4059. }
  4060. else
  4061. hr = E_UNEXPECTED;
  4062. }
  4063. else
  4064. hr = E_UNEXPECTED;
  4065. }
  4066. break;
  4067. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  4068. case CERTMGR_SAFER_USER_ENTRIES:
  4069. hr = S_OK;
  4070. break;
  4071. default:
  4072. break;
  4073. }
  4074. break;
  4075. case CERTMGR_CRL:
  4076. switch (pTargetCookie->m_objecttype)
  4077. {
  4078. case CERTMGR_PHYS_STORE:
  4079. case CERTMGR_LOG_STORE:
  4080. {
  4081. CCertStore* pTargetStore = reinterpret_cast <CCertStore*> (pTargetCookie);
  4082. if ( pTargetStore )
  4083. {
  4084. CCertStore& rSourceStore =
  4085. reinterpret_cast <CCRL*> (pPastedCookie)->GetCertStore ();
  4086. if ( pTargetStore->IsReadOnly () )
  4087. hr = S_FALSE;
  4088. else if ( rSourceStore == *pTargetStore )
  4089. hr = S_FALSE;
  4090. else
  4091. hr = S_OK;
  4092. }
  4093. else
  4094. hr = E_UNEXPECTED;
  4095. }
  4096. break;
  4097. case CERTMGR_CRL_CONTAINER:
  4098. {
  4099. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pTargetCookie);
  4100. if ( pContainer )
  4101. {
  4102. CCertStore& rSourceStore =
  4103. reinterpret_cast <CCRL*> (pPastedCookie)->GetCertStore ();
  4104. if ( pContainer->GetCertStore ().IsReadOnly () )
  4105. hr = S_FALSE;
  4106. else if ( rSourceStore == pContainer->GetCertStore () )
  4107. hr = S_FALSE;
  4108. else
  4109. hr = S_OK;
  4110. }
  4111. else
  4112. hr = E_UNEXPECTED;
  4113. }
  4114. break;
  4115. case CERTMGR_CRL:
  4116. {
  4117. CCRL* pCRL = reinterpret_cast <CCRL*> (pTargetCookie);
  4118. if ( pCRL )
  4119. {
  4120. CCertStore* pSourceStore =
  4121. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  4122. CCertStore& rTargetStore = pCRL->GetCertStore ();
  4123. if ( pSourceStore )
  4124. {
  4125. if ( rTargetStore.IsReadOnly () )
  4126. hr = S_FALSE;
  4127. else if ( *pSourceStore == rTargetStore )
  4128. hr = S_FALSE;
  4129. else
  4130. hr = S_OK;
  4131. }
  4132. else
  4133. hr = E_UNEXPECTED;
  4134. }
  4135. else
  4136. hr = E_UNEXPECTED;
  4137. }
  4138. break;
  4139. default:
  4140. break;
  4141. }
  4142. break;
  4143. case CERTMGR_CTL:
  4144. switch (pTargetCookie->m_objecttype)
  4145. {
  4146. case CERTMGR_PHYS_STORE:
  4147. case CERTMGR_LOG_STORE:
  4148. {
  4149. CCertStore* pTargetStore = reinterpret_cast <CCertStore*> (pTargetCookie);
  4150. if ( pTargetStore )
  4151. {
  4152. CCertStore& rSourceStore =
  4153. reinterpret_cast <CCTL*> (pPastedCookie)->GetCertStore ();
  4154. if ( pTargetStore->IsReadOnly () )
  4155. hr = S_FALSE;
  4156. else if ( rSourceStore == *pTargetStore )
  4157. hr = S_FALSE;
  4158. else
  4159. hr = S_OK;
  4160. }
  4161. else
  4162. hr = E_UNEXPECTED;
  4163. }
  4164. break;
  4165. case CERTMGR_CTL_CONTAINER:
  4166. {
  4167. CContainerCookie* pContainer = reinterpret_cast <CContainerCookie*> (pTargetCookie);
  4168. if ( pContainer )
  4169. {
  4170. CCertStore& rSourceStore =
  4171. reinterpret_cast <CCTL*> (pPastedCookie)->GetCertStore ();
  4172. if ( pContainer->GetCertStore ().IsReadOnly () )
  4173. hr = S_FALSE;
  4174. else if ( rSourceStore == pContainer->GetCertStore () )
  4175. hr = S_FALSE;
  4176. else
  4177. hr = S_OK;
  4178. }
  4179. else
  4180. hr = E_UNEXPECTED;
  4181. }
  4182. break;
  4183. case CERTMGR_CTL:
  4184. {
  4185. CCTL* pCTL = reinterpret_cast <CCTL*> (pTargetCookie);
  4186. if ( pCTL )
  4187. {
  4188. CCertStore* pSourceStore =
  4189. reinterpret_cast <CCertificate*> (pPastedCookie)->GetCertStore ();
  4190. CCertStore& rTargetStore = pCTL->GetCertStore ();
  4191. if ( pSourceStore )
  4192. {
  4193. if ( rTargetStore.IsReadOnly () )
  4194. hr = S_FALSE;
  4195. else if ( *pSourceStore == rTargetStore )
  4196. hr = S_FALSE;
  4197. else
  4198. hr = S_OK;
  4199. }
  4200. else
  4201. hr = E_UNEXPECTED;
  4202. }
  4203. else
  4204. hr = E_UNEXPECTED;
  4205. }
  4206. break;
  4207. case CERTMGR_LOG_STORE_GPE:
  4208. case CERTMGR_LOG_STORE_RSOP:
  4209. {
  4210. CCertStore* pTargetStore =
  4211. reinterpret_cast <CCertStore*> (pTargetCookie);
  4212. ASSERT (pTargetStore);
  4213. if ( pTargetStore )
  4214. {
  4215. CCertStore& rSourceStore =
  4216. reinterpret_cast <CCTL*> (pPastedCookie)->GetCertStore ();
  4217. if ( rSourceStore == *pTargetStore )
  4218. hr = S_FALSE;
  4219. else if ( pTargetStore->CanContain (pPastedCookie->m_objecttype) &&
  4220. !pTargetStore->IsReadOnly () )
  4221. hr = S_OK;
  4222. else
  4223. hr = S_OK;
  4224. }
  4225. else
  4226. hr = E_UNEXPECTED;
  4227. }
  4228. break;
  4229. default:
  4230. break;
  4231. }
  4232. break;
  4233. case CERTMGR_AUTO_CERT_REQUEST:
  4234. switch (pTargetCookie->m_objecttype)
  4235. {
  4236. case CERTMGR_LOG_STORE_GPE:
  4237. case CERTMGR_LOG_STORE_RSOP:
  4238. {
  4239. CCertStore* pTargetStore =
  4240. reinterpret_cast <CCertStore*> (pTargetCookie);
  4241. ASSERT (pTargetStore);
  4242. if ( pTargetStore )
  4243. {
  4244. if ( ACRS_STORE == pTargetStore->GetStoreType () &&
  4245. !pTargetStore->IsReadOnly ())
  4246. hr = S_OK;
  4247. }
  4248. else
  4249. hr = E_UNEXPECTED;
  4250. }
  4251. break;
  4252. default:
  4253. break;
  4254. }
  4255. break;
  4256. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  4257. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  4258. ASSERT (0);
  4259. break;
  4260. default:
  4261. break;
  4262. }
  4263. }
  4264. }
  4265. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyQueryPaste: 0x%x\n", hr);
  4266. return hr;
  4267. }
  4268. HRESULT CCertMgrComponent::CopyPastedCert(
  4269. CCertificate * pCert,
  4270. CCertStore& rCertStore,
  4271. const SPECIAL_STORE_TYPE /*storeType*/,
  4272. bool bDeletePrivateKey,
  4273. CCertMgrCookie* pTargetCookie)
  4274. {
  4275. _TRACE (1, L"Entering CCertMgrComponent::CopyPastedCert\n");
  4276. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  4277. HRESULT hr = S_OK;
  4278. ASSERT (pCert);
  4279. if ( pCert )
  4280. {
  4281. PCCERT_CONTEXT pCertContext = pCert->GetCertContext ();
  4282. ASSERT (pCertContext);
  4283. if ( pCertContext )
  4284. {
  4285. hr = rCertStore.AddCertificateContext (pCertContext,
  4286. m_pConsole, bDeletePrivateKey);
  4287. if ( FAILED (hr) && S_FALSE != hr )
  4288. {
  4289. if ( HRESULT_FROM_WIN32 (CRYPT_E_EXISTS) != hr )
  4290. {
  4291. CString text;
  4292. CString caption;
  4293. int iRetVal = 0;
  4294. if ( E_INVALIDARG == hr && !rCertStore.GetStoreHandle () )
  4295. {
  4296. text.FormatMessage (IDS_CERT_CANNOT_BE_PASTED_CANT_OPEN_STORE,
  4297. rCertStore.GetLocalizedName ());
  4298. }
  4299. else
  4300. {
  4301. text.FormatMessage (IDS_CERT_CANNOT_BE_PASTED,
  4302. rCertStore.GetLocalizedName (),
  4303. GetSystemMessage (hr));
  4304. }
  4305. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4306. m_pConsole->MessageBox (text, caption,
  4307. MB_OK, &iRetVal);
  4308. }
  4309. }
  4310. else
  4311. {
  4312. if ( CERTMGR_CERT_CONTAINER == pTargetCookie->m_objecttype )
  4313. {
  4314. CContainerCookie* pContainerCookie = dynamic_cast <CContainerCookie*> (pTargetCookie);
  4315. if ( pContainerCookie )
  4316. {
  4317. CCertStore* pOriginatingStore = pCert->GetCertStore ();
  4318. if ( pContainerCookie->GetCertStore ().GetStoreName () ==
  4319. pOriginatingStore->GetStoreName () )
  4320. {
  4321. // Add certificate to result pane
  4322. RESULTDATAITEM rdItem;
  4323. CCookie& rootCookie =
  4324. QueryComponentDataRef ().QueryBaseRootCookie ();
  4325. ::ZeroMemory (&rdItem, sizeof (rdItem));
  4326. rdItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM | RDI_STATE;
  4327. rdItem.nImage = iIconCertificate;
  4328. rdItem.nCol = 0;
  4329. rdItem.nState = LVIS_SELECTED | LVIS_FOCUSED;
  4330. rdItem.str = MMC_TEXTCALLBACK;
  4331. CCertificate* pNewCert = new CCertificate (
  4332. ::CertDuplicateCertificateContext (pCertContext),
  4333. &rCertStore);
  4334. if ( pNewCert )
  4335. {
  4336. rootCookie.m_listResultCookieBlocks.AddHead (pNewCert);
  4337. rdItem.lParam = (LPARAM) pNewCert;
  4338. pCert->m_resultDataID = m_pResultData;
  4339. hr = m_pResultData->InsertItem (&rdItem);
  4340. if ( FAILED (hr) )
  4341. {
  4342. _TRACE (0, L"IResultData::InsertItem () failed: 0x%x\n", hr);
  4343. }
  4344. else
  4345. {
  4346. hr = DisplayCertificateCountByStore (m_pConsole,
  4347. &rCertStore, false);
  4348. }
  4349. }
  4350. else
  4351. hr = E_OUTOFMEMORY;
  4352. ASSERT (SUCCEEDED (hr));
  4353. }
  4354. }
  4355. }
  4356. }
  4357. }
  4358. else
  4359. hr = E_UNEXPECTED;
  4360. }
  4361. else
  4362. hr = E_POINTER;
  4363. _TRACE (-1, L"Leaving CCertMgrComponent::CopyPastedCert: 0x%x\n", hr);
  4364. return hr;
  4365. }
  4366. HRESULT CCertMgrComponent::CopyPastedCTL(CCTL * pCTL, CCertStore& rCertStore)
  4367. {
  4368. _TRACE (1, L"Entering CCertMgrComponent::CopyPastedCTL\n");
  4369. HRESULT hr = S_OK;
  4370. ASSERT (pCTL);
  4371. if ( pCTL )
  4372. {
  4373. PCCTL_CONTEXT pCTLContext = pCTL->GetCTLContext ();
  4374. ASSERT (pCTLContext);
  4375. if ( pCTLContext )
  4376. {
  4377. bool bResult = rCertStore.AddCTLContext (pCTLContext);
  4378. if ( !bResult )
  4379. {
  4380. DWORD dwErr = GetLastError ();
  4381. if ( CRYPT_E_EXISTS == dwErr )
  4382. {
  4383. CString text;
  4384. CString caption;
  4385. int iRetVal = 0;
  4386. VERIFY (text.LoadString (IDS_DUPLICATE_CTL));
  4387. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4388. hr = m_pConsole->MessageBox (text, caption,
  4389. MB_OK, &iRetVal);
  4390. ASSERT (SUCCEEDED (hr));
  4391. hr = E_FAIL;
  4392. }
  4393. else
  4394. {
  4395. ASSERT (0);
  4396. hr = HRESULT_FROM_WIN32 (dwErr);
  4397. }
  4398. }
  4399. }
  4400. else
  4401. hr = E_UNEXPECTED;
  4402. }
  4403. else
  4404. hr = E_POINTER;
  4405. _TRACE (-1, L"Leaving CCertMgrComponent::CopyPastedCTL: 0x%x\n", hr);
  4406. return hr;
  4407. }
  4408. HRESULT CCertMgrComponent::CopyPastedCRL(CCRL * pCRL, CCertStore& rCertStore)
  4409. {
  4410. _TRACE (1, L"Entering CCertMgrComponent::CopyPastedCRL\n");
  4411. AFX_MANAGE_STATE (AfxGetStaticModuleState ());
  4412. HRESULT hr = S_OK;
  4413. ASSERT (pCRL);
  4414. if ( pCRL )
  4415. {
  4416. PCCRL_CONTEXT pCRLContext = pCRL->GetCRLContext ();
  4417. ASSERT (pCRLContext);
  4418. if ( pCRLContext )
  4419. {
  4420. bool bResult = rCertStore.AddCRLContext (pCRLContext);
  4421. if ( !bResult )
  4422. {
  4423. DWORD dwErr = GetLastError ();
  4424. if ( CRYPT_E_EXISTS == dwErr )
  4425. {
  4426. CString text;
  4427. CString caption;
  4428. int iRetVal = 0;
  4429. VERIFY (text.LoadString (IDS_DUPLICATE_CRL));
  4430. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4431. hr = m_pConsole->MessageBox (text, caption,
  4432. MB_OK, &iRetVal);
  4433. ASSERT (SUCCEEDED (hr));
  4434. hr = E_FAIL;
  4435. }
  4436. else
  4437. {
  4438. ASSERT (0);
  4439. hr = HRESULT_FROM_WIN32 (dwErr);
  4440. }
  4441. }
  4442. }
  4443. else
  4444. hr = E_UNEXPECTED;
  4445. }
  4446. else
  4447. hr = E_POINTER;
  4448. _TRACE (-1, L"Leaving CCertMgrComponent::CopyPastedCRL: 0x%x\n", hr);
  4449. return hr;
  4450. }
  4451. STDMETHODIMP CCertMgrComponent::GetResultViewType(MMC_COOKIE cookie,
  4452. BSTR* ppViewType,
  4453. long* pViewOptions)
  4454. {
  4455. _TRACE (1, L"Entering CCertMgrComponent::GetResultViewType\n");
  4456. HRESULT hr = S_FALSE;
  4457. CCertMgrCookie* pScopeCookie = reinterpret_cast <CCertMgrCookie*> (cookie);
  4458. if ( pScopeCookie )
  4459. {
  4460. switch (pScopeCookie->m_objecttype)
  4461. {
  4462. case CERTMGR_CERT_CONTAINER:
  4463. case CERTMGR_CTL_CONTAINER:
  4464. case CERTMGR_CRL_CONTAINER:
  4465. case CERTMGR_LOG_STORE_GPE:
  4466. case CERTMGR_LOG_STORE_RSOP:
  4467. case CERTMGR_USAGE:
  4468. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  4469. case CERTMGR_SAFER_USER_ENTRIES:
  4470. *pViewOptions |= MMC_VIEW_OPTIONS_MULTISELECT;
  4471. *ppViewType = NULL;
  4472. break;
  4473. case CERTMGR_SAFER_COMPUTER_ROOT:
  4474. case CERTMGR_SAFER_USER_ROOT:
  4475. {
  4476. CSaferRootCookie* pSaferRootCookie = dynamic_cast <CSaferRootCookie*> (pScopeCookie);
  4477. if ( pSaferRootCookie )
  4478. {
  4479. if ( pSaferRootCookie->m_bCreateSaferNodes )
  4480. {
  4481. *pViewOptions |= MMC_VIEW_OPTIONS_MULTISELECT;
  4482. *ppViewType = NULL;
  4483. }
  4484. else
  4485. {
  4486. *pViewOptions = MMC_VIEW_OPTIONS_NOLISTVIEWS;
  4487. LPOLESTR psz = NULL;
  4488. StringFromCLSID(CLSID_MessageView, &psz);
  4489. USES_CONVERSION;
  4490. if (psz != NULL)
  4491. {
  4492. *ppViewType = psz;
  4493. hr = S_OK;
  4494. }
  4495. }
  4496. }
  4497. }
  4498. break;
  4499. default:
  4500. *ppViewType = NULL;
  4501. break;
  4502. }
  4503. }
  4504. _TRACE (-1, L"Leaving CCertMgrComponent::GetResultViewType: 0x%x\n", hr);
  4505. return hr;
  4506. }
  4507. STDMETHODIMP CCertMgrComponent::Initialize(LPCONSOLE lpConsole)
  4508. {
  4509. _TRACE (1, L"Entering CCertMgrComponent::Initialize\n");
  4510. HRESULT hr = CComponent::Initialize (lpConsole);
  4511. if ( SUCCEEDED (hr) )
  4512. {
  4513. ASSERT (m_pHeader);
  4514. QueryComponentDataRef ().m_pHeader = m_pHeader;
  4515. if ( lpConsole )
  4516. {
  4517. if ( QueryComponentDataRef ().m_pComponentConsole )
  4518. SAFE_RELEASE (QueryComponentDataRef ().m_pComponentConsole);
  4519. QueryComponentDataRef ().m_pComponentConsole = m_pConsole;
  4520. QueryComponentDataRef ().m_pComponentConsole->AddRef ();
  4521. }
  4522. }
  4523. _TRACE (-1, L"Leaving CCertMgrComponent::Initialize: 0x%x\n", hr);
  4524. return hr;
  4525. }
  4526. HRESULT CCertMgrComponent::LoadColumnsFromArrays (INT objecttype )
  4527. {
  4528. _TRACE (1, L"Entering CCertMgrComponent::LoadColumnsFromArrays\n");
  4529. ASSERT (m_pHeader);
  4530. CString str;
  4531. for ( INT i = 0; 0 != m_Columns[objecttype][i]; i++)
  4532. {
  4533. VERIFY(str.LoadString (m_Columns[objecttype][i]));
  4534. m_pHeader->InsertColumn(i, const_cast<LPWSTR>((LPCWSTR)str), LVCFMT_LEFT,
  4535. m_ColumnWidths[objecttype][i]);
  4536. }
  4537. _TRACE (-1, L"Leaving CCertMgrComponent::LoadColumnsFromArrays: S_OK\n");
  4538. return S_OK;
  4539. }
  4540. HRESULT CCertMgrComponent::SaveWidths(CCertMgrCookie * pCookie)
  4541. {
  4542. _TRACE (1, L"Entering CCertMgrComponent::SaveWidths\n");
  4543. HRESULT hr = S_OK;
  4544. m_fDirty = TRUE;
  4545. ASSERT (pCookie);
  4546. if ( pCookie )
  4547. {
  4548. switch (m_pViewedCookie->m_objecttype)
  4549. {
  4550. case CERTMGR_SNAPIN:
  4551. case CERTMGR_USAGE:
  4552. case CERTMGR_PHYS_STORE:
  4553. case CERTMGR_LOG_STORE:
  4554. case CERTMGR_CRL_CONTAINER:
  4555. case CERTMGR_CTL_CONTAINER:
  4556. case CERTMGR_CERT_CONTAINER:
  4557. case CERTMGR_LOG_STORE_GPE:
  4558. case CERTMGR_LOG_STORE_RSOP:
  4559. case CERTMGR_CERT_POLICIES_USER:
  4560. case CERTMGR_CERT_POLICIES_COMPUTER:
  4561. case CERTMGR_SAFER_COMPUTER_ROOT:
  4562. case CERTMGR_SAFER_USER_ROOT:
  4563. case CERTMGR_SAFER_COMPUTER_LEVELS:
  4564. case CERTMGR_SAFER_USER_LEVELS:
  4565. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  4566. case CERTMGR_SAFER_USER_ENTRIES:
  4567. {
  4568. const UINT* pColumns = m_Columns[m_pViewedCookie->m_objecttype];
  4569. ASSERT(pColumns);
  4570. int nWidth = 0;
  4571. for (UINT iIndex = 0; iIndex < pColumns[iIndex]; iIndex++)
  4572. {
  4573. hr = m_pHeader->GetColumnWidth ((int) iIndex, &nWidth);
  4574. if ( SUCCEEDED (hr) )
  4575. {
  4576. m_ColumnWidths[m_pViewedCookie->m_objecttype][iIndex] =
  4577. (UINT) nWidth;
  4578. }
  4579. else
  4580. break;
  4581. }
  4582. }
  4583. break;
  4584. case CERTMGR_CERTIFICATE:
  4585. case CERTMGR_CRL:
  4586. case CERTMGR_CTL:
  4587. case CERTMGR_AUTO_CERT_REQUEST:
  4588. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  4589. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  4590. case CERTMGR_SAFER_COMPUTER_LEVEL:
  4591. case CERTMGR_SAFER_USER_LEVEL:
  4592. case CERTMGR_SAFER_COMPUTER_ENTRY:
  4593. case CERTMGR_SAFER_USER_ENTRY:
  4594. default:
  4595. ASSERT (0);
  4596. break;
  4597. }
  4598. }
  4599. else
  4600. hr = E_POINTER;
  4601. _TRACE (-1, L"Leaving CCertMgrComponent::SaveWidths: 0x%x\n", hr);
  4602. return hr;
  4603. }
  4604. ///////////////////////////////////////////////////////////////////////////////
  4605. #define _dwMagicword 10000 // Internal version number
  4606. STDMETHODIMP CCertMgrComponent::Load(IStream __RPC_FAR *pIStream)
  4607. {
  4608. _TRACE (1, L"Entering CCertMgrComponent::Load\n");
  4609. HRESULT hr = S_OK;
  4610. #ifndef DONT_PERSIST
  4611. ASSERT (pIStream);
  4612. XSafeInterfacePtr<IStream> pIStreamSafePtr( pIStream );
  4613. // Read the magic word from the stream
  4614. DWORD dwMagicword = 0;
  4615. hr = pIStream->Read (&dwMagicword, sizeof(dwMagicword), NULL);
  4616. if ( FAILED(hr) )
  4617. {
  4618. ASSERT( FALSE );
  4619. return hr;
  4620. }
  4621. if (dwMagicword != _dwMagicword)
  4622. {
  4623. // We have a version mismatch
  4624. _TRACE (0, L"INFO: CCertMgrComponentData::Load() - Wrong Magicword. You need to re-save your .msc file.\n");
  4625. return E_FAIL;
  4626. }
  4627. int numCols = 0;
  4628. for (int iIndex = 0; iIndex < CERTMGR_NUMTYPES && SUCCEEDED (hr); iIndex++)
  4629. {
  4630. switch (iIndex)
  4631. {
  4632. case CERTMGR_USAGE:
  4633. case CERTMGR_CERT_CONTAINER:
  4634. numCols = CERT_NUM_COLS;
  4635. break;
  4636. case CERTMGR_CRL_CONTAINER:
  4637. numCols = CRL_NUM_COLS;
  4638. break;
  4639. case CERTMGR_CTL_CONTAINER:
  4640. numCols = CTL_NUM_COLS;
  4641. break;
  4642. case CERTMGR_SNAPIN:
  4643. case CERTMGR_PHYS_STORE:
  4644. case CERTMGR_LOG_STORE:
  4645. case CERTMGR_LOG_STORE_GPE:
  4646. case CERTMGR_LOG_STORE_RSOP:
  4647. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  4648. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  4649. case CERTMGR_SAFER_COMPUTER_ROOT:
  4650. case CERTMGR_SAFER_USER_ROOT:
  4651. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  4652. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  4653. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  4654. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  4655. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  4656. case CERTMGR_SAFER_USER_ENFORCEMENT:
  4657. numCols = 1;
  4658. break;
  4659. case CERTMGR_SAFER_COMPUTER_LEVELS:
  4660. case CERTMGR_SAFER_USER_LEVELS:
  4661. numCols = SAFER_LEVELS_NUM_COLS;
  4662. break;
  4663. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  4664. case CERTMGR_SAFER_USER_ENTRIES:
  4665. numCols = SAFER_ENTRIES_NUM_COLS;
  4666. break;
  4667. case CERTMGR_CERTIFICATE:
  4668. case CERTMGR_CRL:
  4669. case CERTMGR_CTL:
  4670. case CERTMGR_AUTO_CERT_REQUEST:
  4671. case CERTMGR_CERT_POLICIES_USER:
  4672. case CERTMGR_CERT_POLICIES_COMPUTER:
  4673. case CERTMGR_SAFER_COMPUTER_LEVEL:
  4674. case CERTMGR_SAFER_USER_LEVEL:
  4675. case CERTMGR_SAFER_COMPUTER_ENTRY:
  4676. case CERTMGR_SAFER_USER_ENTRY:
  4677. continue;
  4678. default:
  4679. ASSERT (0);
  4680. break;
  4681. }
  4682. for (int colNum = 0; colNum < numCols; colNum++)
  4683. {
  4684. hr = pIStream->Read (&(m_ColumnWidths[iIndex][colNum]),
  4685. sizeof (UINT), NULL);
  4686. ASSERT (SUCCEEDED (hr));
  4687. if ( FAILED(hr) )
  4688. {
  4689. ASSERT (FALSE);
  4690. break;
  4691. }
  4692. }
  4693. }
  4694. #endif
  4695. _TRACE (-1, L"Leaving CCertMgrComponent::Load: 0x%x\n", hr);
  4696. return S_OK;
  4697. }
  4698. ///////////////////////////////////////////////////////////////////////////////
  4699. STDMETHODIMP CCertMgrComponent::Save(
  4700. IStream __RPC_FAR *pIStream,
  4701. BOOL /*fSameAsLoad*/)
  4702. {
  4703. _TRACE (1, L"Entering CCertMgrComponent::Save\n");
  4704. HRESULT hr = S_OK;
  4705. #ifndef DONT_PERSIST
  4706. ASSERT (pIStream);
  4707. XSafeInterfacePtr<IStream> pIStreamSafePtr (pIStream);
  4708. // Store the magic word to the stream
  4709. DWORD dwMagicword = _dwMagicword;
  4710. hr = pIStream->Write (&dwMagicword, sizeof(dwMagicword), NULL);
  4711. ASSERT (SUCCEEDED (hr));
  4712. if ( FAILED (hr) )
  4713. return hr;
  4714. int numCols = 0;
  4715. for (int iIndex = 0; iIndex < CERTMGR_NUMTYPES && SUCCEEDED (hr); iIndex++)
  4716. {
  4717. switch (iIndex)
  4718. {
  4719. case CERTMGR_USAGE:
  4720. case CERTMGR_CERT_CONTAINER:
  4721. numCols = CERT_NUM_COLS;
  4722. break;
  4723. case CERTMGR_CRL_CONTAINER:
  4724. numCols = CRL_NUM_COLS;
  4725. break;
  4726. case CERTMGR_CTL_CONTAINER:
  4727. numCols = CTL_NUM_COLS;
  4728. break;
  4729. case CERTMGR_SNAPIN:
  4730. case CERTMGR_PHYS_STORE:
  4731. case CERTMGR_LOG_STORE:
  4732. case CERTMGR_LOG_STORE_GPE:
  4733. case CERTMGR_LOG_STORE_RSOP:
  4734. case CERTMGR_CERT_POLICIES_USER:
  4735. case CERTMGR_CERT_POLICIES_COMPUTER:
  4736. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  4737. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  4738. case CERTMGR_SAFER_COMPUTER_ROOT:
  4739. case CERTMGR_SAFER_USER_ROOT:
  4740. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  4741. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  4742. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  4743. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  4744. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  4745. case CERTMGR_SAFER_USER_ENFORCEMENT:
  4746. numCols = 1;
  4747. break;
  4748. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  4749. case CERTMGR_SAFER_USER_ENTRIES:
  4750. numCols = SAFER_ENTRIES_NUM_COLS;
  4751. break;
  4752. case CERTMGR_SAFER_COMPUTER_LEVELS:
  4753. case CERTMGR_SAFER_USER_LEVELS:
  4754. numCols = SAFER_LEVELS_NUM_COLS;
  4755. break;
  4756. case CERTMGR_CERTIFICATE:
  4757. case CERTMGR_CRL:
  4758. case CERTMGR_CTL:
  4759. case CERTMGR_AUTO_CERT_REQUEST:
  4760. case CERTMGR_SAFER_COMPUTER_LEVEL:
  4761. case CERTMGR_SAFER_USER_LEVEL:
  4762. case CERTMGR_SAFER_COMPUTER_ENTRY:
  4763. case CERTMGR_SAFER_USER_ENTRY:
  4764. continue;
  4765. default:
  4766. ASSERT (0);
  4767. break;
  4768. }
  4769. for (int colNum = 0; colNum < numCols; colNum++)
  4770. {
  4771. hr = pIStream->Write (&(m_ColumnWidths[iIndex][colNum]),
  4772. sizeof (UINT), NULL);
  4773. ASSERT (SUCCEEDED (hr));
  4774. if ( FAILED(hr) )
  4775. {
  4776. ASSERT (FALSE);
  4777. break;
  4778. }
  4779. }
  4780. }
  4781. #endif
  4782. _TRACE (-1, L"Leaving CCertMgrComponent::Save: 0x%x\n", hr);
  4783. return S_OK;
  4784. }
  4785. HRESULT CCertMgrComponent::OnNotifyCutOrMove(LPARAM arg)
  4786. {
  4787. _TRACE (1, L"Entering CCertMgrComponent::OnNotifyCutOrMove\n");
  4788. if ( !arg )
  4789. return E_POINTER;
  4790. LPDATAOBJECT pDataObject = reinterpret_cast <IDataObject*> (arg);
  4791. ASSERT (pDataObject);
  4792. if ( !pDataObject )
  4793. return E_UNEXPECTED;
  4794. HRESULT hr = S_OK;
  4795. CCertMgrCookie* pCookie =
  4796. QueryComponentDataRef ().ConvertCookie (pDataObject);
  4797. if ( pCookie )
  4798. {
  4799. if ( ((CCertMgrCookie*) MMC_MULTI_SELECT_COOKIE) == pCookie )
  4800. {
  4801. CCertMgrDataObject* pDO = reinterpret_cast <CCertMgrDataObject*>(pDataObject);
  4802. ASSERT (pDO);
  4803. if ( pDO )
  4804. {
  4805. // CCertStore& rCertStore = pCookie->GetCertStore ();
  4806. pDO->Reset();
  4807. while (pDO->Next(1, reinterpret_cast<MMC_COOKIE*>(&pCookie), NULL) != S_FALSE)
  4808. {
  4809. hr = DeleteCookie (pCookie, pDataObject, false, true, false);
  4810. }
  4811. // hr = rCertStore.Commit ();
  4812. // if ( SUCCEEDED (hr) )
  4813. // rCertStore.Resync ();
  4814. }
  4815. else
  4816. hr = E_FAIL;
  4817. }
  4818. else
  4819. {
  4820. hr = DeleteCookie (pCookie, pDataObject, false, false, true);
  4821. }
  4822. if ( SUCCEEDED (hr) )
  4823. RefreshResultPane ();
  4824. }
  4825. _TRACE (-1, L"Leaving CCertMgrComponent::OnNotifyCutOrMove: 0x%x\n", hr);
  4826. return hr;
  4827. }
  4828. CCertMgrCookie* CCertMgrComponent::ConvertCookie(LPDATAOBJECT pDataObject)
  4829. {
  4830. CCertMgrCookie* pCookie = 0;
  4831. pCookie = QueryComponentDataRef ().ConvertCookie (pDataObject);
  4832. return pCookie;
  4833. }
  4834. HRESULT CCertMgrComponent::OnOpen (LPDATAOBJECT pDataObject)
  4835. {
  4836. _TRACE (1, L"Entering CCertMgrComponent::OnOpen\n");
  4837. HRESULT hr = S_OK;
  4838. ASSERT (pDataObject);
  4839. CCertMgrCookie* pParentCookie = ConvertCookie (pDataObject);
  4840. if ( pParentCookie )
  4841. {
  4842. switch (pParentCookie->m_objecttype)
  4843. {
  4844. case CERTMGR_CERTIFICATE:
  4845. {
  4846. CCertificate* pCert = reinterpret_cast <CCertificate*> (pParentCookie);
  4847. ASSERT (pCert);
  4848. if ( pCert )
  4849. {
  4850. hr = LaunchCommonCertDialog (pCert);
  4851. }
  4852. else
  4853. hr = E_UNEXPECTED;
  4854. }
  4855. break;
  4856. case CERTMGR_CTL:
  4857. {
  4858. CCTL* pCTL = reinterpret_cast <CCTL*> (pParentCookie);
  4859. ASSERT (pCTL);
  4860. if ( pCTL )
  4861. {
  4862. hr = LaunchCommonCTLDialog (pCTL);
  4863. if ( SUCCEEDED (hr) )
  4864. hr = RefreshResultItem (pParentCookie);
  4865. }
  4866. else
  4867. hr = E_UNEXPECTED;
  4868. }
  4869. break;
  4870. case CERTMGR_CRL:
  4871. {
  4872. CCRL* pCRL = reinterpret_cast <CCRL*> (pParentCookie);
  4873. ASSERT (pCRL);
  4874. if ( pCRL )
  4875. {
  4876. hr = LaunchCommonCRLDialog (pCRL);
  4877. if ( SUCCEEDED (hr) )
  4878. hr = RefreshResultItem (pParentCookie);
  4879. }
  4880. else
  4881. hr = E_UNEXPECTED;
  4882. }
  4883. break;
  4884. break;
  4885. default:
  4886. ASSERT (0);
  4887. break;
  4888. }
  4889. }
  4890. else
  4891. hr = E_UNEXPECTED;
  4892. _TRACE (-1, L"Leaving CCertMgrComponent::OnOpen: 0x%x\n", hr);
  4893. return hr;
  4894. }
  4895. HRESULT CCertMgrComponent::LaunchCommonCertDialog (CCertificate* pCert)
  4896. {
  4897. _TRACE (1, L"Entering CCertMgrComponent::LaunchCommonCertDialog\n");
  4898. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  4899. ASSERT (pCert);
  4900. if ( !pCert )
  4901. return E_POINTER;
  4902. CWaitCursor waitCursor;
  4903. HWND hwndParent = 0;
  4904. HRESULT hr = m_pConsole->GetMainWindow (&hwndParent);
  4905. ASSERT (SUCCEEDED (hr));
  4906. CCertMgrComponentData& dataRef = QueryComponentDataRef ();
  4907. CTypedPtrList<CPtrList, CCertStore*> storeList;
  4908. // Add the Root store first on a remote machine.
  4909. if ( !IsLocalComputername (dataRef.GetManagedComputer ()) )
  4910. {
  4911. storeList.AddTail (new CCertStore (CERTMGR_LOG_STORE,
  4912. CERT_STORE_PROV_SYSTEM,
  4913. CERT_SYSTEM_STORE_LOCAL_MACHINE,
  4914. (LPCWSTR) dataRef.GetManagedComputer (),
  4915. ROOT_SYSTEM_STORE_NAME,
  4916. ROOT_SYSTEM_STORE_NAME,
  4917. _T (""), ROOT_STORE,
  4918. CERT_SYSTEM_STORE_LOCAL_MACHINE,
  4919. m_pConsole));
  4920. }
  4921. hr = dataRef.EnumerateLogicalStores (&storeList);
  4922. if ( SUCCEEDED (hr) )
  4923. {
  4924. POSITION pos = 0;
  4925. POSITION prevPos = 0;
  4926. // Validate store handles
  4927. for (pos = storeList.GetHeadPosition ();
  4928. pos;)
  4929. {
  4930. prevPos = pos;
  4931. CCertStore* pStore = storeList.GetNext (pos);
  4932. ASSERT (pStore);
  4933. if ( pStore )
  4934. {
  4935. // Do not open the userDS store
  4936. if ( USERDS_STORE == pStore->GetStoreType () )
  4937. {
  4938. storeList.RemoveAt (prevPos);
  4939. pStore->Release ();
  4940. pStore = 0;
  4941. }
  4942. else
  4943. {
  4944. if ( !pStore->GetStoreHandle () )
  4945. {
  4946. int iRetVal = 0;
  4947. CString caption;
  4948. CString text;
  4949. text.FormatMessage (IDS_CANT_OPEN_STORE_AND_FAIL, pStore->GetLocalizedName ());
  4950. VERIFY (caption.LoadString (IDS_CERTIFICATE_MANAGER));
  4951. hr = E_FAIL;
  4952. VERIFY (SUCCEEDED (m_pConsole->MessageBox (text, caption,
  4953. MB_ICONWARNING | MB_OK, &iRetVal)));
  4954. break;
  4955. }
  4956. }
  4957. }
  4958. }
  4959. // Proceed only if all handles are valid
  4960. if ( SUCCEEDED (hr) )
  4961. {
  4962. CRYPTUI_VIEWCERTIFICATE_STRUCT vcs;
  4963. ::ZeroMemory (&vcs, sizeof (vcs));
  4964. vcs.dwSize = sizeof (vcs);
  4965. vcs.hwndParent = hwndParent;
  4966. // Set these flags only on a remote machine.
  4967. if ( !IsLocalComputername (dataRef.GetManagedComputer ()) )
  4968. vcs.dwFlags = CRYPTUI_DONT_OPEN_STORES | CRYPTUI_WARN_UNTRUSTED_ROOT;
  4969. else
  4970. vcs.dwFlags = 0;
  4971. // All dialogs should be read-only under RSOP
  4972. if ( dataRef.m_bIsRSOP || pCert->IsReadOnly () )
  4973. vcs.dwFlags |= CRYPTUI_DISABLE_EDITPROPERTIES;
  4974. vcs.pCertContext = pCert->GetNewCertContext ();
  4975. vcs.cStores = (DWORD)storeList.GetCount ();
  4976. vcs.rghStores = new HCERTSTORE[vcs.cStores];
  4977. if ( vcs.rghStores )
  4978. {
  4979. CCertStore* pStore = 0;
  4980. DWORD index = 0;
  4981. for (pos = storeList.GetHeadPosition ();
  4982. pos && index < vcs.cStores;
  4983. index++)
  4984. {
  4985. pStore = storeList.GetNext (pos);
  4986. ASSERT (pStore);
  4987. if ( pStore )
  4988. {
  4989. vcs.rghStores[index] = pStore->GetStoreHandle ();
  4990. }
  4991. }
  4992. BOOL fPropertiesChanged = FALSE;
  4993. _TRACE (0, L"Calling CryptUIDlgViewCertificate()\n");
  4994. CThemeContextActivator activator;
  4995. BOOL bResult = ::CryptUIDlgViewCertificate (&vcs, &fPropertiesChanged);
  4996. if ( bResult )
  4997. {
  4998. if ( fPropertiesChanged )
  4999. {
  5000. pStore = pCert->GetCertStore ();
  5001. if ( pStore )
  5002. {
  5003. pStore->SetDirty ();
  5004. pStore->Commit ();
  5005. pStore->Close ();
  5006. if ( IDM_USAGE_VIEW == dataRef.m_activeViewPersist )
  5007. {
  5008. // In case purposes were changed and the cert needs to be removed
  5009. RefreshResultPane ();
  5010. }
  5011. else
  5012. RefreshResultItem (pCert);
  5013. }
  5014. }
  5015. }
  5016. delete vcs.rghStores;
  5017. }
  5018. else
  5019. hr = E_OUTOFMEMORY;
  5020. }
  5021. while (!storeList.IsEmpty () )
  5022. {
  5023. CCertStore* pStore = storeList.RemoveHead ();
  5024. if ( pStore )
  5025. {
  5026. pStore->Close ();
  5027. pStore->Release ();
  5028. }
  5029. }
  5030. }
  5031. _TRACE (-1, L"Leaving CCertMgrComponent::LaunchCommonCertDialog: 0x%x\n", hr);
  5032. return hr;
  5033. }
  5034. HRESULT CCertMgrComponent::RefreshResultItem (CCertMgrCookie* pCookie)
  5035. {
  5036. _TRACE (1, L"Entering CCertMgrComponent::RefreshResultItem\n");
  5037. HRESULT hr = S_OK;
  5038. if ( pCookie )
  5039. {
  5040. HRESULTITEM itemID = 0;
  5041. if ( m_pResultData )
  5042. {
  5043. pCookie->Refresh ();
  5044. hr = m_pResultData->FindItemByLParam ( (LPARAM) pCookie, &itemID);
  5045. if ( SUCCEEDED (hr) )
  5046. {
  5047. hr = m_pResultData->UpdateItem (itemID);
  5048. if ( FAILED (hr) )
  5049. {
  5050. _TRACE (0, L"IResultData::UpdateItem () failed: 0x%x\n", hr);
  5051. }
  5052. }
  5053. else
  5054. {
  5055. _TRACE (0, L"IResultData::FindItemByLParam () failed: 0x%x\n", hr);
  5056. }
  5057. }
  5058. else
  5059. {
  5060. _TRACE (0, L"Unexpected error: m_pResultData was NULL\n");
  5061. hr = E_FAIL;
  5062. }
  5063. }
  5064. else
  5065. {
  5066. _TRACE (0, L"Unexpected error: pCookie parameter was NULL\n");
  5067. hr = E_POINTER;
  5068. }
  5069. _TRACE (-1, L"Leaving CCertMgrComponent::RefreshResultItem: 0x%x\n", hr);
  5070. return hr;
  5071. }
  5072. HRESULT CCertMgrComponent::LaunchCommonCTLDialog (CCTL* pCTL)
  5073. {
  5074. _TRACE (1, L"Entering CCertMgrComponent::LaunchCommonCTLDialog\n");
  5075. HRESULT hr = S_OK;
  5076. if ( pCTL )
  5077. {
  5078. CRYPTUI_VIEWCTL_STRUCT vcs;
  5079. HWND hwndParent = 0;
  5080. hr = m_pConsole->GetMainWindow (&hwndParent);
  5081. if ( FAILED (hr) )
  5082. {
  5083. _TRACE (0, L"IConsole::GetMainWindow () failed: 0x%x\n", hr);
  5084. }
  5085. ::ZeroMemory (&vcs, sizeof (vcs));
  5086. vcs.dwSize = sizeof (vcs);
  5087. vcs.hwndParent = hwndParent;
  5088. vcs.dwFlags = 0;
  5089. // All dialogs should be read-only under RSOP
  5090. if ( QueryComponentDataRef ().m_bIsRSOP )
  5091. vcs.dwFlags |= CRYPTUI_DISABLE_EDITPROPERTIES;
  5092. vcs.pCTLContext = pCTL->GetCTLContext ();
  5093. CThemeContextActivator activator;
  5094. VERIFY (::CryptUIDlgViewCTL (&vcs));
  5095. }
  5096. else
  5097. hr = E_POINTER;
  5098. _TRACE (-1, L"Leaving CCertMgrComponent::LaunchCommonCTLDialog: 0x%x\n", hr);
  5099. return hr;
  5100. }
  5101. HRESULT CCertMgrComponent::LaunchCommonCRLDialog (CCRL* pCRL)
  5102. {
  5103. _TRACE (1, L"Entering CCertMgrComponent::LaunchCommonCRLDialog\n");
  5104. ASSERT (pCRL);
  5105. CRYPTUI_VIEWCRL_STRUCT vcs;
  5106. HWND hwndParent;
  5107. HRESULT hr = m_pConsole->GetMainWindow (&hwndParent);
  5108. ASSERT (SUCCEEDED (hr));
  5109. ::ZeroMemory (&vcs, sizeof (vcs));
  5110. vcs.dwSize = sizeof (vcs);
  5111. vcs.hwndParent = hwndParent;
  5112. vcs.dwFlags = 0;
  5113. // All dialogs should be read-only under RSOP
  5114. if ( QueryComponentDataRef ().m_bIsRSOP )
  5115. vcs.dwFlags |= CRYPTUI_DISABLE_EDITPROPERTIES;
  5116. vcs.pCRLContext = pCRL->GetCRLContext ();
  5117. CThemeContextActivator activator;
  5118. VERIFY (::CryptUIDlgViewCRL (&vcs));
  5119. _TRACE (-1, L"Leaving CCertMgrComponent::LaunchCommonCRLDialog: 0x%x\n", hr);
  5120. return hr;
  5121. }
  5122. void CCertMgrComponent::CloseAndReleaseUsageStores()
  5123. {
  5124. _TRACE (1, L"Entering CCertMgrComponent::CloseAndReleaseUsageStores\n");
  5125. CCertStore* pCertStore = 0;
  5126. while (!m_usageStoreList.IsEmpty () )
  5127. {
  5128. pCertStore = m_usageStoreList.RemoveHead ();
  5129. ASSERT (pCertStore);
  5130. if ( pCertStore )
  5131. pCertStore->Release ();
  5132. }
  5133. _TRACE (-1, L"Leaving CCertMgrComponent::CloseAndReleaseUsageStores\n");
  5134. }
  5135. bool CCertMgrComponent::DeletePrivateKey(CCertStore& rCertStoreDest, CCertStore& rCertStoreSrc)
  5136. {
  5137. _TRACE (1, L"Entering CCertMgrComponent::DeletePrivateKey\n");
  5138. bool bDeletePrivateKey = false;
  5139. // Do not copy the private key if the stores are on different machines or
  5140. // if the destination store is in the GPO.
  5141. if ( rCertStoreDest.m_strMachineName != rCertStoreSrc.m_strMachineName )
  5142. bDeletePrivateKey = true;
  5143. else if ( !rCertStoreDest.GetLocation () ) // Store is GPO store
  5144. bDeletePrivateKey = true;
  5145. _TRACE (-1, L"Leaving CCertMgrComponent::DeletePrivateKey\n");
  5146. return bDeletePrivateKey;
  5147. }
  5148. /////////////////////////////////////////////////////////////////////
  5149. // Virtual function called by CComponent::IComponent::Notify(MMCN_PROPERTY_CHANGE)
  5150. // OnPropertyChange() is generated by MMCPropertyChangeNotify( param )
  5151. HRESULT CCertMgrComponent::OnPropertyChange (LPARAM param)
  5152. {
  5153. _TRACE (1, L"Entering CCertMgrComponent::OnPropertyChange\n");
  5154. HRESULT hr = S_OK;
  5155. hr = QueryComponentDataRef ().OnPropertyChange (param);
  5156. _TRACE (-1, L"Leaving CCertMgrComponent::OnPropertyChange: 0x%x\n", hr);
  5157. return hr;
  5158. }
  5159. HRESULT CCertMgrComponent::DisplayCertificateCountByUsage(const CString & usageName, int nCertCnt) const
  5160. {
  5161. _TRACE (1, L"Entering CCertMgrComponent::DisplayCertificateCountByUsage\n");
  5162. AFX_MANAGE_STATE (AfxGetStaticModuleState ( ));
  5163. ASSERT (!usageName.IsEmpty ());
  5164. ASSERT (nCertCnt >= 0);
  5165. IConsole2* pConsole2 = 0;
  5166. HRESULT hr = m_pConsole->QueryInterface (
  5167. IID_PPV_ARG (IConsole2, &pConsole2));
  5168. if (SUCCEEDED (hr))
  5169. {
  5170. CString statusText;
  5171. switch (nCertCnt)
  5172. {
  5173. case 0:
  5174. statusText.FormatMessage (IDS_STATUS_NO_CERTS_USAGE, usageName);
  5175. break;
  5176. case 1:
  5177. statusText.FormatMessage (IDS_STATUS_ONE_CERT_USAGE, usageName);
  5178. break;
  5179. default:
  5180. WCHAR wszCertCount[16];
  5181. AfxFormatString2 (statusText, IDS_STATUS_X_CERTS_USAGE,
  5182. _itow (nCertCnt, wszCertCount, 10), (LPCWSTR) usageName);
  5183. break;
  5184. }
  5185. hr = pConsole2->SetStatusText ((LPWSTR)(LPCWSTR) statusText);
  5186. pConsole2->Release ();
  5187. }
  5188. _TRACE (-1, L"Leaving CCertMgrComponent::DisplayCertificateCountByUsage: 0x%x\n", hr);
  5189. return hr;
  5190. }
  5191. HRESULT CCertMgrComponent::OnNotifySnapinHelp (LPDATAOBJECT pDataObject)
  5192. {
  5193. HRESULT hr = S_OK;
  5194. CComQIPtr<IDisplayHelp,&IID_IDisplayHelp> spDisplayHelp = m_pConsole;
  5195. if ( !!spDisplayHelp )
  5196. {
  5197. CString strHelpTopic;
  5198. UINT nLen = ::GetSystemWindowsDirectory (strHelpTopic.GetBufferSetLength(2 * MAX_PATH), 2 * MAX_PATH);
  5199. strHelpTopic.ReleaseBuffer();
  5200. if ( nLen )
  5201. {
  5202. /*
  5203. * Help on the stores / purposes should start HTML help with Certficate Manager / Concepts / Understanding Certificate Manager / Certificate stores.
  5204. topic is CMconcepts.chm::/sag_CMunCertStor.htm
  5205. * Help on the Certificates / CTL / CRL nodes on the scope pane should open Certificate Manager / Concepts / Understanding Certificate Manager.
  5206. topic is CMconcepts.chm::/sag_CMunderstandWks.htm
  5207. * Help on certificates / CTL / CRL objects on the result pane should open Certificate Manager / Concepts / Using Certificate Manager.
  5208. topic is CMconcepts.chm::/sag_CMusingWks.htm
  5209. * Help on the Certificate Manager node should launch help with Certificate Manager.
  5210. topic is CMconcepts.chm::/sag_CMtopNode.htm
  5211. */
  5212. CString helpFile;
  5213. CString helpTopic;
  5214. CCertMgrComponentData& compData = QueryComponentDataRef ();
  5215. CCertMgrCookie* pCookie = compData.ConvertCookie (pDataObject);
  5216. if ( pCookie )
  5217. {
  5218. switch (pCookie->m_objecttype)
  5219. {
  5220. case CERTMGR_LOG_STORE_GPE:
  5221. case CERTMGR_LOG_STORE_RSOP:
  5222. case CERTMGR_CERT_POLICIES_USER:
  5223. case CERTMGR_CERT_POLICIES_COMPUTER:
  5224. case CERTMGR_AUTO_CERT_REQUEST:
  5225. case CERTMGR_PKP_AUTOENROLLMENT_COMPUTER_SETTINGS:
  5226. case CERTMGR_PKP_AUTOENROLLMENT_USER_SETTINGS:
  5227. helpFile = PKP_LINKED_HELP_FILE;
  5228. helpTopic = PKP_HELP_TOPIC;
  5229. break;
  5230. case CERTMGR_LOG_STORE:
  5231. case CERTMGR_PHYS_STORE:
  5232. case CERTMGR_USAGE:
  5233. helpFile = CM_LINKED_HELP_FILE;
  5234. helpTopic = CM_HELP_TOPIC;
  5235. break;
  5236. case CERTMGR_CRL_CONTAINER:
  5237. case CERTMGR_CTL_CONTAINER:
  5238. case CERTMGR_CERT_CONTAINER:
  5239. helpFile = CM_LINKED_HELP_FILE;
  5240. helpTopic = CM_HELP_TOPIC;
  5241. break;
  5242. case CERTMGR_CERTIFICATE:
  5243. {
  5244. CCertificate* pCert = reinterpret_cast <CCertificate*> (pCookie);
  5245. if ( pCert )
  5246. {
  5247. CCertStore* pStore = pCert->GetCertStore ();
  5248. if ( pStore )
  5249. {
  5250. if ( EFS_STORE == pStore->GetStoreType () )
  5251. {
  5252. helpFile = PKP_LINKED_HELP_FILE;
  5253. helpTopic = PKP_HELP_TOPIC;
  5254. }
  5255. else
  5256. {
  5257. helpFile = CM_LINKED_HELP_FILE;
  5258. helpTopic = CM_HELP_TOPIC;
  5259. }
  5260. }
  5261. }
  5262. }
  5263. break;
  5264. case CERTMGR_CRL:
  5265. {
  5266. CCRL* pCRL = reinterpret_cast <CCRL*> (pCookie);
  5267. if ( pCRL )
  5268. {
  5269. if ( EFS_STORE == pCRL->GetCertStore ().GetStoreType () )
  5270. {
  5271. helpFile = PKP_LINKED_HELP_FILE;
  5272. helpTopic = PKP_HELP_TOPIC;
  5273. }
  5274. else
  5275. {
  5276. helpFile = CM_LINKED_HELP_FILE;
  5277. helpTopic = CM_HELP_TOPIC;
  5278. }
  5279. }
  5280. }
  5281. break;
  5282. case CERTMGR_CTL:
  5283. {
  5284. CCTL* pCTL = reinterpret_cast <CCTL*> (pCookie);
  5285. if ( pCTL )
  5286. {
  5287. if ( EFS_STORE == pCTL->GetCertStore ().GetStoreType () )
  5288. {
  5289. helpFile = PKP_LINKED_HELP_FILE;
  5290. helpTopic = PKP_HELP_TOPIC;
  5291. }
  5292. else
  5293. {
  5294. helpFile = CM_LINKED_HELP_FILE;
  5295. helpTopic = CM_HELP_TOPIC;
  5296. }
  5297. }
  5298. }
  5299. break;
  5300. case CERTMGR_SAFER_COMPUTER_ROOT:
  5301. case CERTMGR_SAFER_USER_ROOT:
  5302. case CERTMGR_SAFER_COMPUTER_LEVELS:
  5303. case CERTMGR_SAFER_USER_LEVELS:
  5304. case CERTMGR_SAFER_COMPUTER_ENTRIES:
  5305. case CERTMGR_SAFER_USER_ENTRIES:
  5306. case CERTMGR_SAFER_COMPUTER_LEVEL:
  5307. case CERTMGR_SAFER_USER_LEVEL:
  5308. case CERTMGR_SAFER_COMPUTER_ENTRY:
  5309. case CERTMGR_SAFER_USER_ENTRY:
  5310. case CERTMGR_SAFER_COMPUTER_TRUSTED_PUBLISHERS:
  5311. case CERTMGR_SAFER_USER_TRUSTED_PUBLISHERS:
  5312. case CERTMGR_SAFER_COMPUTER_DEFINED_FILE_TYPES:
  5313. case CERTMGR_SAFER_USER_DEFINED_FILE_TYPES:
  5314. case CERTMGR_SAFER_COMPUTER_ENFORCEMENT:
  5315. case CERTMGR_SAFER_USER_ENFORCEMENT:
  5316. helpFile = SAFER_WINDOWS_LINKED_HELP_FILE;
  5317. helpTopic = SAFER_HELP_TOPIC;
  5318. break;
  5319. case CERTMGR_SNAPIN:
  5320. default:
  5321. helpFile = CM_LINKED_HELP_FILE;
  5322. helpTopic = CM_HELP_TOPIC;
  5323. break;
  5324. }
  5325. }
  5326. strHelpTopic += L"\\help\\";
  5327. strHelpTopic += helpFile;
  5328. strHelpTopic += L"::/";
  5329. strHelpTopic += helpTopic;
  5330. hr = spDisplayHelp->ShowTopic ((LPWSTR)(LPCWSTR) strHelpTopic);
  5331. }
  5332. else
  5333. hr = E_FAIL;
  5334. }
  5335. else
  5336. {
  5337. hr = E_UNEXPECTED;
  5338. }
  5339. return hr;
  5340. }
  5341. HRESULT CCertMgrComponent::SetControlbar(
  5342. /* [in] */ LPCONTROLBAR /*pControlbar*/)
  5343. {
  5344. /*
  5345. HRESULT hr = S_OK;
  5346. // if we've got a cached toolbar, release it
  5347. if (m_pToolbar) {
  5348. m_pToolbar->Release();
  5349. m_pToolbar = NULL;
  5350. }
  5351. // if we've got a cached control bar, release it
  5352. if (m_pControlbar) {
  5353. m_pControlbar->Release();
  5354. m_pControlbar = NULL;
  5355. }
  5356. //
  5357. // Install new pieces if necessary
  5358. //
  5359. // if a new one came in, cache and AddRef
  5360. if (pControlbar)
  5361. {
  5362. m_pControlbar = pControlbar;
  5363. m_pControlbar->AddRef();
  5364. CThemeContextActivator activator;
  5365. hr = m_pControlbar->Create(TOOLBAR, // type of control
  5366. dynamic_cast<IExtendControlbar *>(this),
  5367. reinterpret_cast<IUnknown **>(&m_pToolbar));
  5368. _ASSERT(SUCCEEDED(hr));
  5369. if ( SUCCEEDED (hr) )
  5370. {
  5371. m_pToolbar->AddRef();
  5372. // add the bitmap to the toolbar
  5373. HBITMAP hbmp = LoadBitmap (MAKEINTRESOURCE(IDR_TOOLBAR1));
  5374. hr = m_pToolbar->AddBitmap (3, hbmp, 16, 16,
  5375. RGB(0, 128, 128)); //NOTE, hardcoded value 3
  5376. _ASSERT(SUCCEEDED(hr));
  5377. // Add the buttons to the toolbar
  5378. hr = m_pToolbar->AddButtons(ARRAYLEN(SnapinButtons1),
  5379. SnapinButtons1);
  5380. _ASSERT(SUCCEEDED(hr));
  5381. }
  5382. }
  5383. return hr;
  5384. */
  5385. return E_NOTIMPL;
  5386. }
  5387. HRESULT CCertMgrComponent::ControlbarNotify(
  5388. MMC_NOTIFY_TYPE /*event*/, // user action
  5389. LPARAM /*arg*/, // depends on the event parameter
  5390. LPARAM /*param*/) // depends on the event parameter
  5391. {
  5392. return E_NOTIMPL;
  5393. }