Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6529 lines
244 KiB

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