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

2819 lines
82 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) Microsoft Corporation, 1995 - 1999
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. #include "setupids.h"
  10. #include "resource.h"
  11. #include "genpage.h"
  12. #include "chooser.h"
  13. #include "misc.h"
  14. #include "csdisp.h" // picker
  15. #include <esent.h> // database error
  16. #include <aclui.h>
  17. #include <atlimpl.cpp>
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. struct FOLDER_DATA
  23. {
  24. FOLDER_TYPES type;
  25. UINT iNameRscID;
  26. };
  27. static FOLDER_DATA SvrFuncFolderData[] =
  28. {
  29. {SERVERFUNC_CRL_PUBLICATION, IDS_CERTS_REVOKED},
  30. {SERVERFUNC_ISSUED_CERTIFICATES, IDS_CERTS_ISSUED},
  31. {SERVERFUNC_PENDING_CERTIFICATES, IDS_CERTS_PENDING},
  32. {SERVERFUNC_FAILED_CERTIFICATES, IDS_CERTS_FAILED},
  33. {SERVERFUNC_ALIEN_CERTIFICATES, IDS_CERTS_IMPORTED},
  34. };
  35. // keep this enum in synch with SvrFuncFolderData[]
  36. enum ENUM_FOLDERS
  37. {
  38. ENUM_FOLDER_CRL=0,
  39. ENUM_FOLDER_ISSUED,
  40. ENUM_FOLDER_PENDING,
  41. ENUM_FOLDER_FAILED,
  42. ENUM_FOLDER_ALIEN
  43. };
  44. // Array of view items to be inserted into the context menu.
  45. // keep this enum in synch with viewItems[]
  46. enum ENUM_TASK_STARTSTOP_ITEMS
  47. {
  48. ENUM_TASK_START=0,
  49. ENUM_TASK_STOP,
  50. ENUM_TASK_SEPERATOR,
  51. };
  52. MY_CONTEXTMENUITEM taskStartStop[] =
  53. {
  54. {
  55. {
  56. L"", L"",
  57. IDC_STARTSERVER, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, 0
  58. },
  59. IDS_TASKMENU_STARTSERVICE,
  60. IDS_TASKMENU_STATUSBAR_STARTSERVICE,
  61. },
  62. {
  63. {
  64. L"", L"",
  65. IDC_STOPSERVER, CCM_INSERTIONPOINTID_PRIMARY_TASK, 0, 0
  66. },
  67. IDS_TASKMENU_STOPSERVICE,
  68. IDS_TASKMENU_STATUSBAR_STOPSERVICE,
  69. },
  70. {
  71. { NULL, NULL, 0, 0, 0 },
  72. IDS_EMPTY,
  73. IDS_EMPTY,
  74. },
  75. };
  76. // Array of view items to be inserted into the context menu.
  77. // WARNING: keep this enum in synch with taskItems[]
  78. enum ENUM_TASK_ITEMS
  79. {
  80. ENUM_TASK_CRLPUB=0,
  81. ENUM_TASK_ATTREXTS_CRL,
  82. ENUM_TASK_ATTREXTS_ISS,
  83. ENUM_TASK_ATTREXTS_PEND,
  84. ENUM_TASK_ATTREXTS_FAIL,
  85. ENUM_TASK_DUMP_ASN_CRL,
  86. ENUM_TASK_DUMP_ASN_ISS,
  87. ENUM_TASK_DUMP_ASN_PEND,
  88. ENUM_TASK_DUMP_ASN_FAIL,
  89. ENUM_TASK_DUMP_ASN_ALIEN,
  90. ENUM_TASK_SEPERATOR1,
  91. ENUM_TASK_SEPERATOR4,
  92. ENUM_TASK_SUBMIT_REQUEST,
  93. ENUM_TASK_REVOKECERT,
  94. ENUM_TASK_RESUBMITREQ,
  95. ENUM_TASK_DENYREQ,
  96. ENUM_TASK_RESUBMITREQ2,
  97. ENUM_TASK_SEPERATOR2,
  98. ENUM_TASK_BACKUP,
  99. ENUM_TASK_RESTORE,
  100. ENUM_TASK_SEPERATOR3,
  101. ENUM_TASK_INSTALL,
  102. ENUM_TASK_REQUEST,
  103. ENUM_TASK_ROLLOVER,
  104. };
  105. TASKITEM taskItems[] =
  106. {
  107. { SERVERFUNC_CRL_PUBLICATION,
  108. 0,
  109. {
  110. {
  111. L"", L"",
  112. IDC_PUBLISHCRL, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  113. },
  114. IDS_TASKMENU_PUBLISHCRL,
  115. IDS_TASKMENU_STATUSBAR_PUBLISHCRL,
  116. }
  117. },
  118. /////////////////////
  119. // BEGIN ATTR/EXT
  120. { SERVERFUNC_CRL_PUBLICATION, // where
  121. TASKITEM_FLAG_RESULTITEM, // dwFlags
  122. {
  123. {
  124. L"", L"",
  125. IDC_VIEW_ATTR_EXT, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  126. },
  127. IDS_TASKMENU_VIEWATTREXT,
  128. IDS_TASKMENU_STATUSBAR_VIEWATTREXT,
  129. }
  130. },
  131. { SERVERFUNC_ISSUED_CERTIFICATES, // where
  132. TASKITEM_FLAG_RESULTITEM, // dwFlags
  133. {
  134. {
  135. L"", L"",
  136. IDC_VIEW_ATTR_EXT, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  137. },
  138. IDS_TASKMENU_VIEWATTREXT,
  139. IDS_TASKMENU_STATUSBAR_VIEWATTREXT,
  140. }
  141. },
  142. { SERVERFUNC_PENDING_CERTIFICATES, // where
  143. TASKITEM_FLAG_RESULTITEM, // dwFlags
  144. {
  145. {
  146. L"", L"",
  147. IDC_VIEW_ATTR_EXT, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  148. },
  149. IDS_TASKMENU_VIEWATTREXT,
  150. IDS_TASKMENU_STATUSBAR_VIEWATTREXT,
  151. }
  152. },
  153. { SERVERFUNC_FAILED_CERTIFICATES, // where
  154. TASKITEM_FLAG_RESULTITEM, // dwFlags
  155. {
  156. {
  157. L"", L"",
  158. IDC_VIEW_ATTR_EXT, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  159. },
  160. IDS_TASKMENU_VIEWATTREXT,
  161. IDS_TASKMENU_STATUSBAR_VIEWATTREXT,
  162. }
  163. },
  164. // END ATTR/EXT
  165. /////////////////////
  166. /////////////////////
  167. // BEGIN ENUM_TASK_DUMP_ASN*
  168. { SERVERFUNC_CRL_PUBLICATION, // where
  169. TASKITEM_FLAG_RESULTITEM, // dwFlags
  170. {
  171. {
  172. L"", L"",
  173. IDC_DUMP_ASN, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  174. },
  175. IDS_TASKMENU_DUMPASN,
  176. IDS_TASKMENU_STATUSBAR_DUMPASN,
  177. }
  178. },
  179. { SERVERFUNC_ISSUED_CERTIFICATES, // where
  180. TASKITEM_FLAG_RESULTITEM, // dwFlags
  181. {
  182. {
  183. L"", L"",
  184. IDC_DUMP_ASN, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  185. },
  186. IDS_TASKMENU_DUMPASN,
  187. IDS_TASKMENU_STATUSBAR_DUMPASN,
  188. }
  189. },
  190. { SERVERFUNC_PENDING_CERTIFICATES, // where
  191. TASKITEM_FLAG_RESULTITEM, // dwFlags
  192. {
  193. {
  194. L"", L"",
  195. IDC_DUMP_ASN, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  196. },
  197. IDS_TASKMENU_DUMPASN,
  198. IDS_TASKMENU_STATUSBAR_DUMPASN,
  199. }
  200. },
  201. { SERVERFUNC_FAILED_CERTIFICATES, // where
  202. TASKITEM_FLAG_RESULTITEM, // dwFlags
  203. {
  204. {
  205. L"", L"",
  206. IDC_DUMP_ASN, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  207. },
  208. IDS_TASKMENU_DUMPASN,
  209. IDS_TASKMENU_STATUSBAR_DUMPASN,
  210. }
  211. },
  212. { SERVERFUNC_ALIEN_CERTIFICATES, // where
  213. TASKITEM_FLAG_RESULTITEM, // dwFlags
  214. {
  215. {
  216. L"", L"",
  217. IDC_DUMP_ASN, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  218. },
  219. IDS_TASKMENU_DUMPASN,
  220. IDS_TASKMENU_STATUSBAR_DUMPASN,
  221. }
  222. },
  223. // END ENUM_TASK_DUMP_ASN*
  224. /////////////////////
  225. // seperator
  226. { SERVERFUNC_ALL_FOLDERS,
  227. TASKITEM_FLAG_RESULTITEM, // dwFlags
  228. {
  229. {
  230. L"", L"",
  231. 0, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, CCM_SPECIAL_SEPARATOR
  232. },
  233. IDS_EMPTY,
  234. IDS_EMPTY,
  235. }
  236. },
  237. // seperator
  238. { SERVER_INSTANCE,
  239. 0, // dwFlags
  240. {
  241. {
  242. L"", L"",
  243. 0, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, CCM_SPECIAL_SEPARATOR
  244. },
  245. IDS_EMPTY,
  246. IDS_EMPTY,
  247. }
  248. },
  249. { SERVER_INSTANCE,
  250. 0,
  251. {
  252. {
  253. L"", L"",
  254. IDC_SUBMITREQUEST, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  255. },
  256. IDS_TASKMENU_SUBMITREQUEST,
  257. IDS_TASKMENU_STATUSBAR_SUBMITREQUEST,
  258. }
  259. },
  260. { SERVERFUNC_ISSUED_CERTIFICATES,
  261. TASKITEM_FLAG_RESULTITEM, // dwFlags
  262. {
  263. {
  264. L"", L"",
  265. IDC_REVOKECERT, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  266. },
  267. IDS_TASKMENU_REVOKECERT,
  268. IDS_TASKMENU_STATUSBAR_REVOKECERT,
  269. }
  270. },
  271. { SERVERFUNC_PENDING_CERTIFICATES,
  272. TASKITEM_FLAG_RESULTITEM, // dwFlags
  273. {
  274. {
  275. L"", L"",
  276. IDC_RESUBMITREQUEST, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  277. },
  278. IDS_TASKMENU_RESUBMIT,
  279. IDS_TASKMENU_STATUSBAR_RESUBMIT,
  280. }
  281. },
  282. { SERVERFUNC_PENDING_CERTIFICATES,
  283. TASKITEM_FLAG_RESULTITEM, // dwFlags
  284. {
  285. {
  286. L"", L"",
  287. IDC_DENYREQUEST, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  288. },
  289. IDS_TASKMENU_DENYREQUEST,
  290. IDS_TASKMENU_STATUSBAR_DENYREQUEST,
  291. }
  292. },
  293. { SERVERFUNC_FAILED_CERTIFICATES,
  294. TASKITEM_FLAG_RESULTITEM, // dwFlags
  295. {
  296. {
  297. L"", L"",
  298. IDC_RESUBMITREQUEST, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  299. },
  300. IDS_TASKMENU_RESUBMIT,
  301. IDS_TASKMENU_STATUSBAR_RESUBMIT,
  302. }
  303. },
  304. // seperator
  305. { SERVERFUNC_ALL_FOLDERS,
  306. 0, // dwFlags
  307. {
  308. {
  309. L"", L"",
  310. 0, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, CCM_SPECIAL_SEPARATOR
  311. },
  312. IDS_EMPTY,
  313. IDS_EMPTY,
  314. }
  315. },
  316. { SERVER_INSTANCE,
  317. TASKITEM_FLAG_LOCALONLY,
  318. {
  319. {
  320. L"", L"",
  321. IDC_BACKUP_CA, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  322. },
  323. IDS_TASKMENU_BACKUP,
  324. IDS_TASKMENU_STATUSBAR_BACKUP,
  325. }
  326. },
  327. { SERVER_INSTANCE,
  328. TASKITEM_FLAG_LOCALONLY,
  329. {
  330. {
  331. L"", L"",
  332. IDC_RESTORE_CA, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  333. },
  334. IDS_TASKMENU_RESTORE,
  335. IDS_TASKMENU_STATUSBAR_RESTORE,
  336. }
  337. },
  338. // seperator
  339. { SERVER_INSTANCE,
  340. 0,
  341. {
  342. {
  343. L"", L"",
  344. 0, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, CCM_SPECIAL_SEPARATOR
  345. },
  346. IDS_EMPTY,
  347. IDS_EMPTY,
  348. }
  349. },
  350. { SERVER_INSTANCE,
  351. 0,
  352. {
  353. {
  354. L"", L"",
  355. IDC_INSTALL_CA, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  356. },
  357. IDS_TASKMENU_INSTALL_CA,
  358. IDS_TASKMENU_STATUSBAR_INSTALL_CA,
  359. }
  360. },
  361. { SERVER_INSTANCE,
  362. 0,
  363. {
  364. {
  365. L"", L"",
  366. IDC_REQUEST_CA, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_ENABLED, 0
  367. },
  368. IDS_TASKMENU_REQUEST_CA,
  369. IDS_TASKMENU_STATUSBAR_REQUEST_CA,
  370. }
  371. },
  372. { SERVER_INSTANCE,
  373. TASKITEM_FLAG_LOCALONLY,
  374. {
  375. {
  376. L"", L"",
  377. IDC_ROLLOVER_CA, CCM_INSERTIONPOINTID_PRIMARY_TASK, MF_GRAYED, 0
  378. },
  379. IDS_TASKMENU_ROLLOVER,
  380. IDS_TASKMENU_STATUSBAR_ROLLOVER,
  381. }
  382. },
  383. { NONE,
  384. FALSE,
  385. {
  386. { NULL, NULL, 0, 0, 0 },
  387. IDS_EMPTY,
  388. IDS_EMPTY,
  389. }
  390. }
  391. };
  392. // Array of view items to be inserted into the context menu.
  393. // keep this enum in synch with topItems[]
  394. enum ENUM_TOP_ITEMS
  395. {
  396. ENUM_TOP_REVOKEDOPEN=0,
  397. ENUM_TOP_ISSUEDOPEN,
  398. ENUM_TOP_ALIENOPEN,
  399. ENUM_RETARGET_SNAPIN,
  400. };
  401. TASKITEM topItems[] =
  402. {
  403. { SERVERFUNC_CRL_PUBLICATION,
  404. TASKITEM_FLAG_RESULTITEM, // dwFlags
  405. {
  406. {
  407. L"", L"",
  408. IDC_VIEW_CERT_PROPERTIES, CCM_INSERTIONPOINTID_PRIMARY_TOP, MF_ENABLED, CCM_SPECIAL_DEFAULT_ITEM
  409. },
  410. IDS_TOPMENU_OPEN,
  411. IDS_TOPMENU_STATUSBAR_OPEN,
  412. }
  413. },
  414. { SERVERFUNC_ISSUED_CERTIFICATES,
  415. TASKITEM_FLAG_RESULTITEM, // dwFlags
  416. {
  417. {
  418. L"", L"",
  419. IDC_VIEW_CERT_PROPERTIES, CCM_INSERTIONPOINTID_PRIMARY_TOP, MF_ENABLED, CCM_SPECIAL_DEFAULT_ITEM
  420. },
  421. IDS_TOPMENU_OPEN,
  422. IDS_TOPMENU_STATUSBAR_OPEN,
  423. }
  424. },
  425. { SERVERFUNC_ALIEN_CERTIFICATES,
  426. TASKITEM_FLAG_RESULTITEM, // dwFlags
  427. {
  428. {
  429. L"", L"",
  430. IDC_VIEW_CERT_PROPERTIES, CCM_INSERTIONPOINTID_PRIMARY_TOP, MF_ENABLED, CCM_SPECIAL_DEFAULT_ITEM
  431. },
  432. IDS_TOPMENU_OPEN,
  433. IDS_TOPMENU_STATUSBAR_OPEN,
  434. }
  435. },
  436. {
  437. MACHINE_INSTANCE,
  438. 0,
  439. {
  440. {
  441. L"", L"",
  442. IDC_RETARGET_SNAPIN, CCM_INSERTIONPOINTID_PRIMARY_TOP, MF_ENABLED, 0
  443. },
  444. IDS_RETARGET_SNAPIN,
  445. IDS_STATUSBAR_RETARGET_SNAPIN,
  446. }
  447. },
  448. { NONE,
  449. 0,
  450. {
  451. { NULL, NULL, 0, 0, 0 },
  452. IDS_EMPTY,
  453. IDS_EMPTY,
  454. }
  455. }
  456. };
  457. ///////////////////////////////////////////////////////////////////////////////
  458. // IComponentData implementation
  459. DEBUG_DECLARE_INSTANCE_COUNTER(CComponentDataImpl);
  460. CComponentDataImpl::CComponentDataImpl()
  461. : m_bIsDirty(TRUE), m_pScope(NULL), m_pConsole(NULL)
  462. #if DBG
  463. , m_bInitializedCD(false), m_bDestroyedCD(false)
  464. #endif
  465. {
  466. DEBUG_INCREMENT_INSTANCE_COUNTER(CComponentDataImpl);
  467. m_dwFlagsPersist = 0;
  468. m_pStaticRoot = NULL;
  469. m_pCurSelFolder = NULL;
  470. m_fScopeAlreadyEnumerated = FALSE;
  471. m_fSchemaWasResolved = FALSE; // resolve schema once per load
  472. // checked in ::Initialize, ::CreatePropertyPages
  473. m_pCertMachine = new CertSvrMachine;
  474. m_cLastKnownSchema = 0;
  475. m_rgcstrLastKnownSchema = NULL;
  476. m_rgltypeLastKnownSchema = NULL;
  477. m_rgfindexedLastKnownSchema = NULL;
  478. m_dwNextViewIndex = 0;
  479. }
  480. CComponentDataImpl::~CComponentDataImpl()
  481. {
  482. DEBUG_DECREMENT_INSTANCE_COUNTER(CComponentDataImpl);
  483. ASSERT(m_pScope == NULL);
  484. ASSERT(!m_bInitializedCD || m_bDestroyedCD);
  485. // Delete enumerated scope items
  486. // note: we don't own pCA memory, m_pCertMachine does
  487. POSITION pos = m_scopeItemList.GetHeadPosition();
  488. while (pos)
  489. delete m_scopeItemList.GetNext(pos);
  490. m_scopeItemList.RemoveAll();
  491. m_pCurSelFolder = NULL;
  492. m_fScopeAlreadyEnumerated = FALSE;
  493. if (m_pCertMachine)
  494. m_pCertMachine->Release();
  495. m_cLastKnownSchema = 0;
  496. if (m_rgcstrLastKnownSchema)
  497. delete [] m_rgcstrLastKnownSchema;
  498. if (m_rgltypeLastKnownSchema)
  499. delete [] m_rgltypeLastKnownSchema;
  500. if (m_rgfindexedLastKnownSchema)
  501. delete [] m_rgfindexedLastKnownSchema;
  502. }
  503. STDMETHODIMP_(ULONG)
  504. CComponentDataImpl::AddRef()
  505. {
  506. return InterlockedIncrement((LONG *) &_cRefs);
  507. }
  508. STDMETHODIMP_(ULONG)
  509. CComponentDataImpl::Release()
  510. {
  511. ULONG cRefsTemp;
  512. cRefsTemp = InterlockedDecrement((LONG *)&_cRefs);
  513. if (0 == cRefsTemp)
  514. {
  515. delete this;
  516. }
  517. return cRefsTemp;
  518. }
  519. int CComponentDataImpl::FindColIdx(IN LPCWSTR szHeading)
  520. {
  521. for (DWORD dw=0; dw<m_cLastKnownSchema; dw++)
  522. {
  523. if (m_rgcstrLastKnownSchema[dw].IsEqual(szHeading))
  524. return dw;
  525. }
  526. return -1;
  527. }
  528. HRESULT CComponentDataImpl::GetDBSchemaEntry(
  529. IN int iIndex,
  530. OUT OPTIONAL LPCWSTR* pszHeading,
  531. OUT OPTIONAL LONG* plType,
  532. OUT OPTIONAL BOOL* pfIndexed)
  533. {
  534. if (m_cLastKnownSchema<= (DWORD)iIndex)
  535. return HRESULT_FROM_WIN32(ERROR_INVALID_INDEX);
  536. if (pszHeading)
  537. *pszHeading = m_rgcstrLastKnownSchema[iIndex];
  538. if (plType)
  539. *plType = m_rgltypeLastKnownSchema[iIndex];
  540. if (pfIndexed)
  541. *pfIndexed = m_rgfindexedLastKnownSchema[iIndex];
  542. return S_OK;
  543. }
  544. HRESULT CComponentDataImpl::SetDBSchema(
  545. IN CString* rgcstr,
  546. LONG* rgtype,
  547. BOOL* rgfIndexed,
  548. DWORD cEntries)
  549. {
  550. if (m_rgcstrLastKnownSchema)
  551. delete [] m_rgcstrLastKnownSchema;
  552. m_rgcstrLastKnownSchema = rgcstr;
  553. if (m_rgltypeLastKnownSchema)
  554. delete [] m_rgltypeLastKnownSchema;
  555. m_rgltypeLastKnownSchema = rgtype;
  556. if (m_rgfindexedLastKnownSchema)
  557. delete [] m_rgfindexedLastKnownSchema;
  558. m_rgfindexedLastKnownSchema = rgfIndexed;
  559. m_cLastKnownSchema = cEntries;
  560. return S_OK;
  561. }
  562. STDMETHODIMP CComponentDataImpl::Initialize(LPUNKNOWN pUnknown)
  563. {
  564. // NOTA BENE: Init is called when a snap-in is being
  565. // created and has items to enumerate in the scope pane ... NOT BEFORE
  566. // Example: Add/Remove snapin, Add...
  567. // -> CComponentDataImpl will get called for CreatePropertyPages() before ::Initialize is called
  568. #if DBG
  569. m_bInitializedCD = true;
  570. #endif
  571. ASSERT(pUnknown != NULL);
  572. HRESULT hr;
  573. LPIMAGELIST lpScopeImage = NULL;
  574. CBitmap bmpResultStrip16x16, bmpResultStrip32x32;
  575. // Load resources
  576. if (!g_cResources.Load())
  577. {
  578. hr = GetLastError();
  579. _JumpError(hr, Ret, "Load Resources");
  580. }
  581. // create a per-instance id (failure not fatal)
  582. ResetPersistedColumnInformation();
  583. // MMC should only call ::Initialize once!
  584. // m_pCertMachine created in constructor, but verified here
  585. ASSERT(m_pCertMachine != NULL);
  586. _JumpIfOutOfMemory(hr, Ret, m_pCertMachine);
  587. // MMC should only call ::Initialize once!
  588. ASSERT(m_pScope == NULL);
  589. hr = pUnknown->QueryInterface(IID_IConsoleNameSpace2, reinterpret_cast<void**>(&m_pScope));
  590. _JumpIfError(hr, Ret, "QueryInterface IID_IConsoleNameSpace2");
  591. // add the images for the scope tree
  592. hr = pUnknown->QueryInterface(IID_IConsole2, reinterpret_cast<void**>(&m_pConsole));
  593. ASSERT(hr == S_OK);
  594. _JumpIfError(hr, Ret, "QueryInterface IID_IConsole2");
  595. hr = m_pConsole->QueryScopeImageList(&lpScopeImage);
  596. ASSERT(hr == S_OK);
  597. _JumpIfError(hr, Ret, "QueryScopeImageList");
  598. if ( (NULL == bmpResultStrip16x16.LoadBitmap(IDB_16x16)) ||
  599. (NULL == bmpResultStrip32x32.LoadBitmap(IDB_32x32)) )
  600. {
  601. hr = S_FALSE;
  602. _JumpError(hr, Ret, "LoadBitmap");
  603. }
  604. // Load the bitmaps from the dll
  605. lpScopeImage->ImageListSetStrip(reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmpResultStrip16x16)),
  606. reinterpret_cast<LONG_PTR *>(static_cast<HBITMAP>(bmpResultStrip32x32)),
  607. 0, RGB(255, 0, 255));
  608. _JumpIfError(hr, Ret, "ImageListSetStrip");
  609. Ret:
  610. if (lpScopeImage)
  611. lpScopeImage->Release();
  612. return hr;
  613. }
  614. STDMETHODIMP CComponentDataImpl::Destroy()
  615. {
  616. // release all references to the console here
  617. ASSERT(m_bInitializedCD);
  618. #if DBG
  619. m_bDestroyedCD = true;
  620. #endif
  621. SAFE_RELEASE(m_pScope);
  622. SAFE_RELEASE(m_pConsole);
  623. return S_OK;
  624. }
  625. STDMETHODIMP CComponentDataImpl::CreateComponent(LPCOMPONENT* ppComponent)
  626. {
  627. HRESULT hr = S_OK;
  628. ASSERT(ppComponent != NULL);
  629. CComObject<CSnapin>* pObject;
  630. CComObject<CSnapin>::CreateInstance(&pObject);
  631. ASSERT(pObject != NULL);
  632. _JumpIfOutOfMemory(hr, Ret, pObject);
  633. // Store IComponentData
  634. pObject->SetIComponentData(this);
  635. pObject->SetViewID(m_dwNextViewIndex++);
  636. hr = pObject->QueryInterface(IID_IComponent,
  637. reinterpret_cast<void**>(ppComponent));
  638. Ret:
  639. return hr;
  640. }
  641. STDMETHODIMP CComponentDataImpl::Notify(LPDATAOBJECT lpDataObject, MMC_NOTIFY_TYPE event, LPARAM arg, LPARAM param)
  642. {
  643. ASSERT(m_pScope != NULL);
  644. HRESULT hr = S_OK;
  645. INTERNAL* pInternal = NULL;
  646. MMC_COOKIE cookie = NULL;
  647. // handle events with (NULL == lpDataObject)
  648. switch(event)
  649. {
  650. case MMCN_PROPERTY_CHANGE:
  651. {
  652. // Notification from property page "notify change"
  653. //
  654. // arg == fIsScopeItem
  655. // lParam == page param value
  656. // return value unused
  657. if (param == CERTMMC_PROPERTY_CHANGE_REFRESHVIEWS)
  658. {
  659. m_pConsole->UpdateAllViews(
  660. lpDataObject,
  661. 0,
  662. 0);
  663. }
  664. goto Ret;
  665. }
  666. default: // all others
  667. break;
  668. }
  669. pInternal = ExtractInternalFormat(lpDataObject);
  670. if (pInternal == NULL)
  671. {
  672. return S_OK;
  673. }
  674. cookie = pInternal->m_cookie;
  675. FREE_DATA(pInternal);
  676. switch(event)
  677. {
  678. case MMCN_PASTE:
  679. DBGPRINT((DBG_SS_CERTMMC, "CComponentDataImpl::MMCN_PASTE"));
  680. break;
  681. case MMCN_DELETE:
  682. hr = OnDelete(cookie);
  683. break;
  684. case MMCN_REMOVE_CHILDREN:
  685. hr = OnRemoveChildren(arg);
  686. break;
  687. case MMCN_RENAME:
  688. hr = OnRename(cookie, arg, param);
  689. break;
  690. case MMCN_EXPAND:
  691. hr = OnExpand(lpDataObject, arg, param);
  692. break;
  693. case MMCN_PRELOAD:
  694. {
  695. if (NULL == cookie)
  696. {
  697. // base node
  698. // this call gave us time to load our dynamic base nodename (Certification Authority on %s)
  699. DisplayProperRootNodeName((HSCOPEITEM)arg);
  700. }
  701. }
  702. default:
  703. break;
  704. }
  705. Ret:
  706. return hr;
  707. }
  708. HRESULT CComponentDataImpl::DisplayProperRootNodeName(HSCOPEITEM hRoot)
  709. {
  710. // hRoot not optional
  711. if (hRoot == NULL)
  712. return E_POINTER;
  713. // if static root not yet set, save it (CASE: load from file)
  714. if (m_pStaticRoot == NULL)
  715. m_pStaticRoot = hRoot;
  716. // let us have time to load our dynamic base nodename (Certification Authority on %s)
  717. SCOPEDATAITEM item;
  718. item.mask = SDI_STR;
  719. item.ID = hRoot;
  720. CString cstrMachineName;
  721. CString cstrDisplayStr, cstrFormatStr, cstrMachine;
  722. cstrFormatStr.LoadString(IDS_NODENAME_FORMAT);
  723. if (m_pCertMachine->m_strMachineName.IsEmpty())
  724. cstrMachine.LoadString(IDS_LOCALMACHINE);
  725. else
  726. cstrMachine = m_pCertMachine->m_strMachineName;
  727. if (!cstrFormatStr.IsEmpty())
  728. {
  729. cstrMachineName.Format(cstrFormatStr, cstrMachine);
  730. item.displayname = (LPWSTR)(LPCWSTR)cstrMachineName;
  731. }
  732. else
  733. {
  734. // protect against null formatstring
  735. item.displayname = (LPWSTR)(LPCWSTR)cstrMachine;
  736. }
  737. m_pScope->SetItem (&item);
  738. return S_OK;
  739. }
  740. STDMETHODIMP CComponentDataImpl::QueryDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, LPDATAOBJECT* ppDataObject)
  741. {
  742. #ifdef _DEBUG
  743. if (cookie == 0)
  744. {
  745. ASSERT(type != CCT_RESULT);
  746. }
  747. else
  748. {
  749. ASSERT(type == CCT_SCOPE);
  750. DWORD dwItemType = *reinterpret_cast<DWORD*>(cookie);
  751. ASSERT((dwItemType == SCOPE_LEVEL_ITEM) || (dwItemType == CA_LEVEL_ITEM));
  752. }
  753. #endif
  754. return _QueryDataObject(cookie, type, -1, this, ppDataObject);
  755. }
  756. ///////////////////////////////////////////////////////////////////////////////
  757. //// ISnapinHelp interface
  758. STDMETHODIMP CComponentDataImpl::GetHelpTopic(LPOLESTR* lpCompiledHelpFile)
  759. {
  760. if (lpCompiledHelpFile == NULL)
  761. return E_POINTER;
  762. UINT cbWindows = 0;
  763. WCHAR szWindows[MAX_PATH];
  764. szWindows[0] = L'\0';
  765. cbWindows = GetSystemWindowsDirectory(szWindows, MAX_PATH);
  766. if (cbWindows == 0)
  767. return S_FALSE;
  768. cbWindows++; // include null term
  769. cbWindows *= sizeof(WCHAR); // make this bytes, not chars
  770. *lpCompiledHelpFile = (LPOLESTR) CoTaskMemAlloc(sizeof(HTMLHELP_COLLECTION_FILENAME) + cbWindows);
  771. if (*lpCompiledHelpFile == NULL)
  772. return E_OUTOFMEMORY;
  773. myRegisterMemFree(*lpCompiledHelpFile, CSM_COTASKALLOC); // this is freed by mmc, not our tracking
  774. USES_CONVERSION;
  775. wcscpy(*lpCompiledHelpFile, T2OLE(szWindows));
  776. wcscat(*lpCompiledHelpFile, T2OLE(HTMLHELP_COLLECTION_FILENAME));
  777. return S_OK;
  778. }
  779. // tells of other topics my chm links to
  780. STDMETHODIMP CComponentDataImpl::GetLinkedTopics(LPOLESTR* lpCompiledHelpFiles)
  781. {
  782. if (lpCompiledHelpFiles == NULL)
  783. return E_POINTER;
  784. UINT cbWindows = 0;
  785. WCHAR szWindows[MAX_PATH];
  786. szWindows[0] = L'\0';
  787. cbWindows = GetSystemWindowsDirectory(szWindows, MAX_PATH);
  788. if (cbWindows == 0)
  789. return S_FALSE;
  790. cbWindows++; // include null term
  791. cbWindows *= sizeof(WCHAR); // make this bytes, not chars
  792. *lpCompiledHelpFiles = (LPOLESTR) CoTaskMemAlloc(sizeof(HTMLHELP_COLLECTIONLINK_FILENAME) + cbWindows);
  793. if (*lpCompiledHelpFiles == NULL)
  794. return E_OUTOFMEMORY;
  795. myRegisterMemFree(*lpCompiledHelpFiles, CSM_COTASKALLOC); // this is freed by mmc, not our tracking
  796. USES_CONVERSION;
  797. wcscpy(*lpCompiledHelpFiles, T2OLE(szWindows));
  798. wcscat(*lpCompiledHelpFiles, T2OLE(HTMLHELP_COLLECTIONLINK_FILENAME));
  799. return S_OK;
  800. }
  801. ///////////////////////////////////////////////////////////////////////////////
  802. //// IPersistStream interface members
  803. STDMETHODIMP CComponentDataImpl::GetClassID(CLSID *pClassID)
  804. {
  805. ASSERT(pClassID != NULL);
  806. // Copy the CLSID for this snapin
  807. *pClassID = CLSID_Snapin;
  808. return S_OK;
  809. }
  810. STDMETHODIMP CComponentDataImpl::IsDirty()
  811. {
  812. // Always save / Always dirty.
  813. return ThisIsDirty() ? S_OK : S_FALSE;
  814. }
  815. STDMETHODIMP CComponentDataImpl::Load(IStream *pStm)
  816. {
  817. ASSERT(pStm);
  818. ASSERT(m_bInitializedCD);
  819. // Read the string
  820. BOOL fMachineOverrideFound = FALSE;
  821. DWORD dwVer;
  822. CertSvrCA* pDummyCA = NULL;
  823. HRESULT hr;
  824. // read version
  825. hr = ReadOfSize(pStm, &dwVer, sizeof(DWORD));
  826. _JumpIfError(hr, Ret, "Read dwVer");
  827. // flags is version-dependent
  828. if (VER_CCOMPDATA_SAVE_STREAM_3 == dwVer)
  829. {
  830. // version 3 includes file flags
  831. hr = ReadOfSize(pStm, &m_dwFlagsPersist, sizeof(DWORD));
  832. _JumpIfError(hr, Ret, "Read m_dwFlagsPersist");
  833. }
  834. else if (VER_CCOMPDATA_SAVE_STREAM_2 != dwVer)
  835. {
  836. // not version 2 or 3
  837. return STG_E_OLDFORMAT;
  838. }
  839. // load machine data
  840. hr = m_pCertMachine->Load(pStm);
  841. _JumpIfError(hr, Ret, "Load m_pCertMachine")
  842. if (m_dwFlagsPersist & CCOMPDATAIMPL_FLAGS_ALLOW_MACHINE_OVERRIDE)
  843. {
  844. // override m_pCertMachine->m_strMachineName (not to be persisted)
  845. LPWSTR lpCommandLine = GetCommandLine(); // no need to free
  846. DBGPRINT((DBG_SS_CERTMMC, "CComponentData::Load: Command line switch override enabled. Searching command line(%ws)\n", lpCommandLine));
  847. LPWSTR pszMachineStart, pszMachineEnd;
  848. // search for "/machine" in cmd line
  849. _wcsupr(lpCommandLine); // convert to uppercase
  850. pszMachineStart = wcsstr(lpCommandLine, WSZ_MACHINE_OVERRIDE_SWITCH);
  851. do // not a loop
  852. {
  853. if (NULL == pszMachineStart) // user did not override
  854. break;
  855. pszMachineStart += WSZARRAYSIZE(WSZ_MACHINE_OVERRIDE_SWITCH); // skip past "/machine:"
  856. //
  857. // Found the hint switch
  858. //
  859. pszMachineEnd = wcschr(pszMachineStart, L' '); // look for first space char, call this end
  860. if (NULL == pszMachineEnd)
  861. pszMachineEnd = &pszMachineStart[wcslen(pszMachineStart)]; // space not found in this string;
  862. m_pCertMachine->m_strMachineName = pszMachineStart;
  863. m_pCertMachine->m_strMachineName.SetAt(SAFE_SUBTRACT_POINTERS(pszMachineEnd, pszMachineStart), L'\0');
  864. DBGPRINT((DBG_SS_CERTMMC, "CComponentData::Load: Found machinename (%ws)\n", m_pCertMachine->m_strMachineName));
  865. fMachineOverrideFound = TRUE;
  866. } while (0);
  867. }
  868. if (!fMachineOverrideFound)
  869. {
  870. // Get CA count
  871. DWORD dwNumCAs;
  872. hr = ReadOfSize(pStm, &dwNumCAs, sizeof(DWORD));
  873. _JumpIfError(hr, Ret, "Load dwNumCAs");
  874. // for each CA, get folder data
  875. for (DWORD dwCA=0; dwCA< dwNumCAs; dwCA++)
  876. {
  877. CString cstrThisCA;
  878. DWORD dwParticularCA;
  879. hr = CStringLoad(cstrThisCA, pStm);
  880. _JumpIfError(hr, Ret, "CStringLoad");
  881. // create a dummy CA with the correct common name; we'll fix this later (see Synch CA)
  882. pDummyCA = new CertSvrCA(m_pCertMachine);
  883. _JumpIfOutOfMemory(hr, Ret, pDummyCA);
  884. pDummyCA->m_strCommonName = cstrThisCA;
  885. if (VER_CCOMPDATA_SAVE_STREAM_2 < dwVer)
  886. {
  887. m_fSchemaWasResolved = FALSE; // resolve schema once per CComponentData load
  888. // LOAD last known schema
  889. hr = ReadOfSize(pStm, &m_cLastKnownSchema, sizeof(DWORD));
  890. _JumpIfError(hr, Ret, "Load m_cLastKnownSchema");
  891. // alloc
  892. if (m_cLastKnownSchema != 0)
  893. {
  894. m_rgcstrLastKnownSchema = new CString[m_cLastKnownSchema];
  895. _JumpIfOutOfMemory(hr, Ret, m_rgcstrLastKnownSchema);
  896. for (unsigned int i=0; i<m_cLastKnownSchema; i++)
  897. {
  898. hr = CStringLoad(m_rgcstrLastKnownSchema[i], pStm);
  899. _JumpIfError(hr, Ret, "Load m_rgcstrLastKnownSchema");
  900. }
  901. }
  902. }
  903. // find out how many folders are in the stream under this CA
  904. DWORD dwNumFolders=0;
  905. hr = ReadOfSize(pStm, &dwNumFolders, sizeof(DWORD));
  906. _JumpIfError(hr, Ret, "Load dwNumFolders");
  907. // load each of these
  908. for(DWORD dwCount=0; dwCount<dwNumFolders; dwCount++)
  909. {
  910. CFolder* pFolder = new CFolder();
  911. _JumpIfOutOfMemory(hr, Ret, pFolder);
  912. // point at previously constructed dummy ca; we'll fix this later
  913. pFolder->m_pCertCA = pDummyCA;
  914. hr = pFolder->Load(pStm);
  915. _JumpIfError(hr, Ret, "Load CFolder");
  916. m_scopeItemList.AddTail(pFolder);
  917. }
  918. pDummyCA = NULL; // owned by at least one folder
  919. }
  920. }
  921. // version-dependent info
  922. if (VER_CCOMPDATA_SAVE_STREAM_2 < dwVer)
  923. {
  924. // per-instance guid for identifying columns uniquely
  925. hr = ReadOfSize(pStm, &m_guidInstance, sizeof(GUID));
  926. _JumpIfError(hr, Ret, "ReadOfSize instance guid");
  927. hr = ReadOfSize(pStm, &m_dwNextViewIndex, sizeof(DWORD));
  928. _JumpIfError(hr, Ret, "ReadOfSize view index");
  929. }
  930. Ret:
  931. if (pDummyCA)
  932. delete pDummyCA;
  933. ClearDirty();
  934. return hr;
  935. }
  936. STDMETHODIMP CComponentDataImpl::Save(IStream *pStm, BOOL fClearDirty)
  937. {
  938. ASSERT(pStm);
  939. ASSERT(m_bInitializedCD);
  940. HRESULT hr;
  941. DWORD dwVer;
  942. DWORD dwCA;
  943. DWORD dwNumCAs;
  944. #if DBG_CERTSRV
  945. bool fSaveConsole = false;
  946. LPWSTR lpCommandLine = GetCommandLine(); // no need to free
  947. _wcsupr(lpCommandLine); // convert to uppercase
  948. fSaveConsole = (NULL!=wcsstr(lpCommandLine, L"/certsrv_saveconsole"));
  949. #endif
  950. // Write the version
  951. dwVer = VER_CCOMPDATA_SAVE_STREAM_3;
  952. hr = WriteOfSize(pStm, &dwVer, sizeof(DWORD));
  953. _JumpIfError(hr, Ret, "Save dwVer");
  954. // write dwFlags (a VERSION 3 addition)
  955. hr = WriteOfSize(pStm, &m_dwFlagsPersist, sizeof(DWORD));
  956. _JumpIfError(hr, Ret, "pStm->Write m_dwFlagsPersist");
  957. #if DBG_CERTSRV
  958. if(fSaveConsole)
  959. m_pCertMachine->m_strMachineNamePersist.Empty();
  960. #endif
  961. hr = m_pCertMachine->Save(pStm, fClearDirty);
  962. _JumpIfError(hr, Ret, "Save m_pCertMachine");
  963. // save CA count
  964. dwNumCAs = m_pCertMachine->GetCaCount();
  965. hr = WriteOfSize(pStm, &dwNumCAs, sizeof(DWORD));
  966. _JumpIfError(hr, Ret, "pStm->Write dwNumCAs");
  967. // for each CA, save folder info
  968. for (dwCA=0; dwCA < dwNumCAs; dwCA++)
  969. {
  970. DWORD dwNumFolders=0;
  971. CString cstrThisCA, cstrThisCASave;
  972. cstrThisCASave = cstrThisCA = m_pCertMachine->GetCaCommonNameAtPos(dwCA);
  973. #if DBG_CERTSRV
  974. if(fSaveConsole)
  975. cstrThisCASave.Empty();
  976. #endif
  977. hr = CStringSave(cstrThisCASave, pStm, fClearDirty);
  978. _JumpIfError(hr, Ret, "CStringSave");
  979. // SAVE last known schema
  980. hr = WriteOfSize(pStm, &m_cLastKnownSchema, sizeof(DWORD));
  981. _JumpIfError(hr, Ret, "pStm->Write m_cLastKnownSchema");
  982. for (unsigned int i=0; i<m_cLastKnownSchema; i++)
  983. {
  984. hr = CStringSave(m_rgcstrLastKnownSchema[i], pStm, fClearDirty);
  985. _JumpIfError(hr, Ret, "CStringSave");
  986. }
  987. // walk through every folder, find how many folders to save
  988. POSITION pos = m_scopeItemList.GetHeadPosition();
  989. while(pos)
  990. {
  991. CFolder* pFolder = m_scopeItemList.GetNext(pos);
  992. if (pFolder->GetCA()->m_strCommonName.IsEqual(cstrThisCA))
  993. dwNumFolders++;
  994. }
  995. // write how many folders under this CA
  996. hr = WriteOfSize(pStm, &dwNumFolders, sizeof(DWORD));
  997. _JumpIfError(hr, Ret, "pStm->Write dwNumFolders");
  998. pos = m_scopeItemList.GetHeadPosition();
  999. while(pos)
  1000. {
  1001. CFolder* pFolder = m_scopeItemList.GetNext(pos);
  1002. if (pFolder->GetCA()->m_strCommonName.IsEqual(cstrThisCA))
  1003. {
  1004. hr = pFolder->Save(pStm, fClearDirty);
  1005. _JumpIfError(hr, Ret, "Save CFolder");
  1006. }
  1007. }
  1008. }
  1009. // per-instance guid for identifying columns uniquely
  1010. hr = WriteOfSize(pStm, &m_guidInstance, sizeof(GUID));
  1011. _JumpIfError(hr, Ret, "WriteOfSize instance guid");
  1012. hr = WriteOfSize(pStm, &m_dwNextViewIndex, sizeof(DWORD));
  1013. _JumpIfError(hr, Ret, "WriteOfSize view index");
  1014. Ret:
  1015. if (fClearDirty)
  1016. ClearDirty();
  1017. return hr;
  1018. }
  1019. STDMETHODIMP CComponentDataImpl::GetSizeMax(ULARGE_INTEGER *pcbSize)
  1020. {
  1021. ASSERT(pcbSize);
  1022. int iTotalSize=0;
  1023. // version
  1024. iTotalSize = sizeof(DWORD) + sizeof(m_dwFlagsPersist);
  1025. // machine info
  1026. int iSize;
  1027. m_pCertMachine->GetSizeMax(&iSize);
  1028. iTotalSize += iSize;
  1029. // CA count
  1030. iTotalSize += sizeof(DWORD);
  1031. DWORD dwNumCAs = m_pCertMachine->GetCaCount();
  1032. for (DWORD dwCA=0; dwCA < dwNumCAs; dwCA++)
  1033. {
  1034. DWORD dwNumFolders=0;
  1035. CString cstrThisCA;
  1036. cstrThisCA = m_pCertMachine->GetCaCommonNameAtPos(dwCA);
  1037. CStringGetSizeMax(cstrThisCA, &iSize);
  1038. iTotalSize += iSize;
  1039. // Number of folders under this CA
  1040. iTotalSize += sizeof(DWORD);
  1041. // walk through every folder, find how many folders to save
  1042. POSITION pos = m_scopeItemList.GetHeadPosition();
  1043. while(pos)
  1044. {
  1045. CFolder* pFolder = m_scopeItemList.GetNext(pos);
  1046. if (pFolder->GetCA()->m_strCommonName.IsEqual(cstrThisCA))
  1047. {
  1048. // folder size
  1049. pFolder->GetSizeMax(&iSize);
  1050. iTotalSize += iSize;
  1051. }
  1052. }
  1053. }
  1054. // per-instance guid for identifying columns uniquely
  1055. iTotalSize += sizeof(GUID);
  1056. // next View Index to assign
  1057. iTotalSize += sizeof(DWORD);
  1058. // size of string to be saved
  1059. pcbSize->QuadPart = iTotalSize;
  1060. return S_OK;
  1061. }
  1062. ///////////////////////////////////////////////////////////////////////////////
  1063. //// Notify handlers for IComponentData
  1064. HRESULT CComponentDataImpl::OnDelete(MMC_COOKIE cookie)
  1065. {
  1066. return S_OK;
  1067. }
  1068. HRESULT CComponentDataImpl::OnRemoveChildren(LPARAM arg)
  1069. {
  1070. return S_OK;
  1071. }
  1072. HRESULT CComponentDataImpl::OnRename(MMC_COOKIE cookie, LPARAM arg, LPARAM param)
  1073. {
  1074. // cookie is cookie
  1075. // arg is fRenamed (ask for permission/notify of rename)
  1076. // param (szNewName)
  1077. CFolder* pFolder = reinterpret_cast<CFolder*>(cookie);
  1078. BOOL fRenamed = (BOOL)arg;
  1079. if (!fRenamed)
  1080. {
  1081. if (pFolder)
  1082. return S_FALSE; // don't allow children to be renamed
  1083. else
  1084. return S_OK; // allow root to be renamed
  1085. }
  1086. LPOLESTR pszNewName = reinterpret_cast<LPOLESTR>(param);
  1087. if (pszNewName == NULL)
  1088. return E_INVALIDARG;
  1089. if (pFolder)
  1090. {
  1091. ASSERT(pFolder != NULL);
  1092. if (pFolder == NULL)
  1093. return E_INVALIDARG;
  1094. pFolder->SetName(pszNewName);
  1095. }
  1096. return S_OK;
  1097. }
  1098. HRESULT CComponentDataImpl::OnExpand(LPDATAOBJECT lpDataObject, LPARAM arg, LPARAM param)
  1099. {
  1100. if (arg == TRUE)
  1101. {
  1102. // Did Initialize get called?
  1103. ASSERT(m_pScope != NULL);
  1104. EnumerateScopePane(lpDataObject, param);
  1105. }
  1106. return S_OK;
  1107. }
  1108. HRESULT CComponentDataImpl::SynchDisplayedCAList(LPDATAOBJECT lpDataObject)
  1109. {
  1110. HRESULT hr;
  1111. BOOL fFound;
  1112. POSITION pos, nextpos;
  1113. DWORD dwKnownCAs;
  1114. m_fScopeAlreadyEnumerated = TRUE; // don't need to refresh view automagically from enum if we get here
  1115. // should never get here otherwise
  1116. ASSERT(m_pStaticRoot);
  1117. if (NULL == m_pStaticRoot)
  1118. return E_POINTER;
  1119. // select root node, delete all items in UI underneath (we'll readd if necessary)
  1120. hr = m_pConsole->SelectScopeItem(m_pStaticRoot);
  1121. _PrintIfError(hr, "SelectScopeItem");
  1122. hr = m_pScope->DeleteItem(m_pStaticRoot, FALSE); // remove everything from UI
  1123. _PrintIfError(hr, "DeleteItem");
  1124. // build knowledge of current CAs
  1125. // note: this may orphan some pCAs, but we'll catch it during cleanup
  1126. HWND hwndMain = NULL;
  1127. hr = m_pConsole->GetMainWindow(&hwndMain);
  1128. if (hr != S_OK)
  1129. hwndMain = NULL; // this should work
  1130. // this hr gets returned after we're done
  1131. hr = m_pCertMachine->PrepareData(hwndMain);
  1132. // don't fail out if PrepareData fails -- we still need to
  1133. // make the snapin state reflect no known nodes!
  1134. ASSERT((hr == S_OK) || (0 == m_pCertMachine->GetCaCount()) ); // make sure m_pCertMachine zeros itself
  1135. // Tasks
  1136. // #1: Remove folders in m_scopeItemList for CAs that no longer exist in m_pCertMachine.m_rgpCAList[]
  1137. // #2: Add folders to m_scopeItemList for CAs that now exist in m_pCertMachine.m_rgpCAList[]
  1138. // Task #1
  1139. // scour m_scopeItemList for entries we already know about, delete stale folders
  1140. for (pos = m_scopeItemList.GetHeadPosition(); (NULL != pos); )
  1141. {
  1142. // ASSERTION: every folder has an associated m_pCertCA
  1143. ASSERT(NULL != m_scopeItemList.GetAt(pos)->m_pCertCA);
  1144. nextpos = pos; // save next position off
  1145. fFound = FALSE;
  1146. // for each scope item, walk through m_rgpCAList looking for current
  1147. for (dwKnownCAs=0; dwKnownCAs<(DWORD)m_pCertMachine->m_CAList.GetSize(); dwKnownCAs++)
  1148. {
  1149. if (m_scopeItemList.GetAt(pos)->m_pCertCA->m_strCommonName.IsEqual(m_pCertMachine->GetCaCommonNameAtPos(dwKnownCAs)))
  1150. {
  1151. fFound = TRUE;
  1152. break;
  1153. }
  1154. }
  1155. CFolder* pFolder = m_scopeItemList.GetAt(pos);
  1156. ASSERT(pFolder); // this should never happen
  1157. if (pFolder == NULL)
  1158. {
  1159. hr = E_POINTER;
  1160. _JumpError(hr, Ret, "GetAt");
  1161. }
  1162. if (fFound)
  1163. {
  1164. // always point to latest pCA:
  1165. // NOTE: this allows for load to populate us with dummy CAs!
  1166. pFolder->m_pCertCA = m_pCertMachine->GetCaAtPos(dwKnownCAs);
  1167. // if base node, do insert (other nodes get inserted during Expand() notification)
  1168. if (SERVER_INSTANCE == pFolder->GetType())
  1169. BaseFolderInsertIntoScope(pFolder, pFolder->m_pCertCA);
  1170. // fwd to next elt
  1171. m_scopeItemList.GetNext(pos);
  1172. }
  1173. else // !fFound
  1174. {
  1175. // delete immediately from m_scopeItemList
  1176. m_scopeItemList.GetNext(nextpos);
  1177. delete pFolder; // destroy the elt
  1178. m_scopeItemList.RemoveAt(pos);
  1179. pos = nextpos; // restore next position
  1180. }
  1181. }
  1182. // Task #2
  1183. // scour m_pCertMachine[] for new entries, create default folders
  1184. for (dwKnownCAs=0; dwKnownCAs<(DWORD)m_pCertMachine->m_CAList.GetSize(); dwKnownCAs++)
  1185. {
  1186. fFound = FALSE;
  1187. for (pos = m_scopeItemList.GetHeadPosition(); (NULL != pos); m_scopeItemList.GetNext(pos))
  1188. {
  1189. if (m_scopeItemList.GetAt(pos)->m_pCertCA->m_strCommonName.IsEqual(m_pCertMachine->GetCaCommonNameAtPos(dwKnownCAs)))
  1190. {
  1191. fFound = TRUE;
  1192. break; // if matches something in the refreshed list, we're fine
  1193. }
  1194. }
  1195. // found?
  1196. if (!fFound)
  1197. {
  1198. CertSvrCA* pCA;
  1199. CFolder* pFolder;
  1200. pCA = m_pCertMachine->GetCaAtPos(dwKnownCAs);
  1201. if (NULL == pCA)
  1202. {
  1203. hr = E_POINTER;
  1204. _JumpError(hr, Ret, "m_pCertMachine->GetCaAtPos(iCAPos)");
  1205. }
  1206. // create base node, add to list, insert into scope pane
  1207. pFolder = new CFolder();
  1208. _JumpIfOutOfMemory(hr, Ret, pFolder);
  1209. m_scopeItemList.AddTail(pFolder);
  1210. hr = BaseFolderInsertIntoScope(pFolder, pCA);
  1211. _JumpIfError(hr, Ret, "BaseFolderInsertIntoScope");
  1212. // and create all template folders underneath
  1213. hr = CreateTemplateFolders(pCA);
  1214. _JumpIfError(hr, Ret, "CreateTemplateFolders");
  1215. }
  1216. else
  1217. {
  1218. // no need to do anything, ca is already known & inserted into scope
  1219. }
  1220. }
  1221. // BOGDANT
  1222. /*
  1223. // Task #3
  1224. // for each CA, offer to do any one-time per-CA upgrades
  1225. for (dwKnownCAs=0; dwKnownCAs<(DWORD)m_pCertMachine->m_CAList.GetSize(); dwKnownCAs++)
  1226. {
  1227. CertSvrCA* pCA;
  1228. CFolder* pFolder;
  1229. pCA = m_pCertMachine->GetCaAtPos(dwKnownCAs);
  1230. if (NULL == pCA)
  1231. {
  1232. hr = E_POINTER;
  1233. _JumpError(hr, Ret, "m_pCertMachine->GetCaAtPos(iCAPos)");
  1234. }
  1235. if (pCA->FDoesSecurityNeedUpgrade())
  1236. {
  1237. BOOL fIsDomainAdmin = FALSE;
  1238. CString cstrMsg, cstrTitle;
  1239. cstrMsg.LoadString(IDS_W2K_SECURITY_UPGRADE_DESCR);
  1240. cstrTitle.LoadString(IDS_W2K_UPGRADE_DETECTED_TITLE);
  1241. hr = IsUserDomainAdministrator(&fIsDomainAdmin);
  1242. _JumpIfError(hr, Ret, "IsUserDomainAdministrator");
  1243. if (fIsDomainAdmin)
  1244. {
  1245. // ask to upgrade security
  1246. // confirm this action
  1247. CString cstrTmp;
  1248. cstrTmp.LoadString(IDS_CONFIRM_W2K_SECURITY_UPGRADE);
  1249. cstrMsg += cstrTmp;
  1250. int iRet;
  1251. if ((S_OK == m_pConsole->MessageBox(cstrMsg, cstrTitle, MB_YESNO, &iRet)) &&
  1252. (iRet == IDYES))
  1253. {
  1254. // do stuff
  1255. hr = csiUpgradeCertSrvSecurity(
  1256. pCA->m_strCommonName,
  1257. IsEnterpriseCA(pCA->GetCAType()), // likely always enterprise, tho
  1258. TRUE, // write it to the DS
  1259. CS_UPGRADE_WIN2000);
  1260. _JumpIfError(hr, error, "csiUpgradeCertSrvSecurity");
  1261. hr = AddCAMachineToCertPublishers();
  1262. _JumpIfError(hr, error, "AddCAMachineToCertPublishers");
  1263. if (RestartService(hwndMain, pCA->m_pParentMachine))
  1264. {
  1265. // notify views: refresh service toolbar buttons
  1266. m_pConsole->UpdateAllViews(
  1267. lpDataObject,
  1268. 0,
  1269. 0);
  1270. }
  1271. error:
  1272. if (hr != S_OK)
  1273. DisplayGenericCertSrvError(m_pConsole, hr);
  1274. }
  1275. }
  1276. else
  1277. {
  1278. // just warn
  1279. CString cstrTmp;
  1280. cstrTmp.LoadString(IDS_BLOCK_W2K_SECURITY_UPGRADE);
  1281. cstrMsg += cstrTmp;
  1282. m_pConsole->MessageBoxW(cstrMsg, cstrTitle, MB_OK, NULL);
  1283. }
  1284. }
  1285. }
  1286. */
  1287. Ret:
  1288. return hr;
  1289. }
  1290. HRESULT CComponentDataImpl::BaseFolderInsertIntoScope(CFolder* pFolder, CertSvrCA* pCA)
  1291. {
  1292. HRESULT hr = S_OK;
  1293. int nImage;
  1294. HSCOPEITEM pParent = m_pStaticRoot; // we'll always be initialized by this time if parent exists
  1295. ASSERT(m_pStaticRoot);
  1296. if (NULL == m_pStaticRoot)
  1297. {
  1298. hr = E_POINTER;
  1299. _JumpError(hr, Ret, "m_pStaticRoot");
  1300. }
  1301. if ((NULL == pFolder) || (NULL == pCA))
  1302. {
  1303. hr = E_POINTER;
  1304. _JumpError(hr, Ret, "NULL ptr");
  1305. }
  1306. if (pCA->m_strCommonName.IsEmpty())
  1307. {
  1308. hr = E_POINTER;
  1309. _JumpError(hr, Ret, "m_strCommonName");
  1310. }
  1311. if (m_pCertMachine->IsCertSvrServiceRunning())
  1312. nImage = IMGINDEX_CERTSVR_RUNNING;
  1313. else
  1314. nImage = IMGINDEX_CERTSVR_STOPPED;
  1315. pFolder->SetScopeItemInformation(nImage, nImage);
  1316. pFolder->SetProperties(
  1317. pCA->m_strCommonName,
  1318. SCOPE_LEVEL_ITEM,
  1319. SERVER_INSTANCE,
  1320. TRUE);
  1321. pFolder->m_pCertCA = pCA; // fill this in as root
  1322. // Set the parent
  1323. pFolder->m_ScopeItem.mask |= SDI_PARENT;
  1324. pFolder->m_ScopeItem.relativeID = pParent;
  1325. // Set the folder as the cookie
  1326. pFolder->m_ScopeItem.mask |= SDI_PARAM;
  1327. pFolder->m_ScopeItem.lParam = reinterpret_cast<LPARAM>(pFolder);
  1328. pFolder->SetCookie(reinterpret_cast<MMC_COOKIE>(pFolder));
  1329. // insert SCOPE_LEVEL_ITEM into scope pane
  1330. m_pScope->InsertItem(&pFolder->m_ScopeItem);
  1331. // Note - On return, the ID member of 'm_ScopeItem'
  1332. // contains the handle to the newly inserted item!
  1333. ASSERT(pFolder->m_ScopeItem.ID != NULL);
  1334. Ret:
  1335. return hr;
  1336. }
  1337. HRESULT CComponentDataImpl::CreateTemplateFolders(CertSvrCA* pCA)
  1338. {
  1339. HRESULT hr = S_OK;
  1340. // add all template folders under it
  1341. for (int iUnder=0; iUnder < ARRAYLEN(SvrFuncFolderData); iUnder++)
  1342. {
  1343. // skip alien if svr doesn't support
  1344. if ((iUnder==ENUM_FOLDER_ALIEN) && !pCA->FDoesServerAllowForeignCerts())
  1345. continue;
  1346. CString cstrRsc;
  1347. cstrRsc.LoadString(SvrFuncFolderData[iUnder].iNameRscID);
  1348. CFolder* pFolder;
  1349. pFolder = new CFolder();
  1350. _JumpIfOutOfMemory(hr, Ret, pFolder);
  1351. pFolder->m_pCertCA = pCA;
  1352. pFolder->SetScopeItemInformation(IMGINDEX_FOLDER, IMGINDEX_FOLDER_OPEN);
  1353. pFolder->SetProperties(
  1354. cstrRsc,
  1355. CA_LEVEL_ITEM,
  1356. SvrFuncFolderData[iUnder].type,
  1357. FALSE);
  1358. m_scopeItemList.AddTail(pFolder);
  1359. }
  1360. Ret:
  1361. return hr;
  1362. }
  1363. void CComponentDataImpl::EnumerateScopePane(LPDATAOBJECT lpDataObject, HSCOPEITEM pParent)
  1364. {
  1365. ASSERT(m_pScope != NULL); // make sure we QI'ed for the interface
  1366. ASSERT(lpDataObject != NULL);
  1367. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1368. if (pInternal == NULL)
  1369. return;
  1370. MMC_COOKIE cookie = pInternal->m_cookie;
  1371. FREE_DATA(pInternal);
  1372. // Enumerate the scope pane
  1373. // return the folder object that represents the cookie
  1374. // Note - for large list, use dictionary
  1375. CFolder* pStatic = FindObject(cookie);
  1376. if (pStatic)
  1377. ASSERT(!pStatic->IsEnumerated());
  1378. if (NULL == cookie)
  1379. {
  1380. if (!m_fScopeAlreadyEnumerated) // if base node and we've never inserted nodes
  1381. {
  1382. // TASK: expand machine node
  1383. // Note - Each cookie in the scope pane represents a folder.
  1384. // Cache the HSCOPEITEM of the static root.
  1385. ASSERT(pParent != NULL);
  1386. m_pStaticRoot = pParent; // add/remove: EXPAND case
  1387. // synch folder list if asking to expand machine node
  1388. // SyncDisplayedCAList adds all necessary folders
  1389. HRESULT hr = SynchDisplayedCAList(lpDataObject);
  1390. if (hr != S_OK)
  1391. {
  1392. HWND hwnd;
  1393. DWORD dwErr2 = m_pConsole->GetMainWindow(&hwnd);
  1394. ASSERT(dwErr2 == ERROR_SUCCESS);
  1395. if (dwErr2 != ERROR_SUCCESS)
  1396. hwnd = NULL; // should work
  1397. if (((HRESULT)RPC_S_SERVER_UNAVAILABLE) == hr)
  1398. {
  1399. DisplayCertSrvErrorWithContext(hwnd, hr, IDS_SERVER_UNAVAILABLE);
  1400. }
  1401. else if(HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)==hr ||
  1402. ((HRESULT)ERROR_OLD_WIN_VERSION)==hr)
  1403. {
  1404. DisplayCertSrvErrorWithContext(hwnd, hr, IDS_OLD_CA);
  1405. }
  1406. else
  1407. {
  1408. DisplayGenericCertSrvError(hwnd, hr);
  1409. }
  1410. }
  1411. }
  1412. }
  1413. else
  1414. {
  1415. // TASK: expand non-machine node
  1416. if (NULL == pStatic)
  1417. return;
  1418. switch(pStatic->GetType())
  1419. {
  1420. case SERVER_INSTANCE:
  1421. {
  1422. // TASK: expand CA instance node
  1423. POSITION pos = m_scopeItemList.GetHeadPosition();
  1424. while(pos)
  1425. {
  1426. CFolder* pFolder;
  1427. pFolder = m_scopeItemList.GetNext(pos);
  1428. if (pFolder==NULL)
  1429. break;
  1430. // only expand folders that belong under the SERVER_INSTANCE
  1431. if (pFolder->m_itemType != CA_LEVEL_ITEM)
  1432. continue;
  1433. // and only those under the correct CA
  1434. if (pFolder->m_pCertCA != pStatic->m_pCertCA)
  1435. continue;
  1436. // Set the parent
  1437. pFolder->m_ScopeItem.relativeID = pParent;
  1438. // Set the folder as the cookie
  1439. pFolder->m_ScopeItem.mask |= SDI_PARAM;
  1440. pFolder->m_ScopeItem.lParam = reinterpret_cast<LPARAM>(pFolder);
  1441. pFolder->SetCookie(reinterpret_cast<MMC_COOKIE>(pFolder));
  1442. m_pScope->InsertItem(&pFolder->m_ScopeItem);
  1443. // Note - On return, the ID member of 'm_ScopeItem'
  1444. // contains the handle to the newly inserted item!
  1445. ASSERT(pFolder->m_ScopeItem.ID != NULL);
  1446. }
  1447. }
  1448. break;
  1449. default:
  1450. // TASK: expand nodes with no folders under them
  1451. break;
  1452. }
  1453. }
  1454. }
  1455. CFolder* CComponentDataImpl::FindObject(MMC_COOKIE cookie)
  1456. {
  1457. CFolder* pFolder = NULL;
  1458. POSITION pos = m_scopeItemList.GetHeadPosition();
  1459. while(pos)
  1460. {
  1461. pFolder = m_scopeItemList.GetNext(pos);
  1462. if (*pFolder == cookie)
  1463. return pFolder;
  1464. }
  1465. return NULL;
  1466. }
  1467. STDMETHODIMP CComponentDataImpl::GetDisplayInfo(SCOPEDATAITEM* pScopeDataItem)
  1468. {
  1469. ASSERT(pScopeDataItem != NULL);
  1470. if (pScopeDataItem == NULL)
  1471. return E_POINTER;
  1472. CFolder* pFolder = reinterpret_cast<CFolder*>(pScopeDataItem->lParam);
  1473. if ((pScopeDataItem->mask & SDI_STR) && (pFolder != NULL))
  1474. {
  1475. pScopeDataItem->displayname = pFolder->m_pszName;
  1476. }
  1477. // I was told by Ravi Rudrappa that these notifications
  1478. // would never be given. If it is given, move UpdateScopeIcons()
  1479. // functionality here!!!
  1480. ASSERT(0 == (pScopeDataItem->mask & SDI_IMAGE));
  1481. ASSERT(0 == (pScopeDataItem->mask & SDI_OPENIMAGE));
  1482. return S_OK;
  1483. }
  1484. STDMETHODIMP CComponentDataImpl::CompareObjects(LPDATAOBJECT lpDataObjectA, LPDATAOBJECT lpDataObjectB)
  1485. {
  1486. if (lpDataObjectA == NULL || lpDataObjectB == NULL)
  1487. return E_POINTER;
  1488. HRESULT hr = S_FALSE;
  1489. // Make sure both data object are mine
  1490. INTERNAL* pA = ExtractInternalFormat(lpDataObjectA);
  1491. INTERNAL* pB = ExtractInternalFormat(lpDataObjectA);
  1492. if (pA != NULL && pB != NULL)
  1493. hr = (*pA == *pB) ? S_OK : S_FALSE;
  1494. FREE_DATA(pA);
  1495. FREE_DATA(pB);
  1496. return hr;
  1497. }
  1498. /////////////////////////////////////////////////////////////////////////////
  1499. // IExtendPropertySheet Implementation
  1500. STDMETHODIMP CComponentDataImpl::CreatePropertyPages(LPPROPERTYSHEETCALLBACK lpProvider,
  1501. LONG_PTR handle,
  1502. LPDATAOBJECT lpIDataObject)
  1503. {
  1504. HRESULT hr = S_OK;
  1505. // Look at the data object and determine if this an extension or a primary
  1506. ASSERT(lpIDataObject != NULL);
  1507. PropertyPage* pBasePage;
  1508. INTERNAL* pInternal = ExtractInternalFormat(lpIDataObject);
  1509. if (pInternal == NULL)
  1510. return S_OK;
  1511. switch (pInternal->m_type)
  1512. {
  1513. case CCT_SNAPIN_MANAGER:
  1514. {
  1515. CChooseMachinePropPage* pPage = new CChooseMachinePropPage();
  1516. _JumpIfOutOfMemory(hr, Ret, pPage);
  1517. // this alloc might have failed (should be in ctor)
  1518. _JumpIfOutOfMemory(hr, Ret, m_pCertMachine);
  1519. pPage->SetCaption(IDS_SCOPE_MYCOMPUTER);
  1520. // Initialize state of object
  1521. pPage->InitMachineName(NULL);
  1522. // point to our member vars
  1523. pPage->SetOutputBuffers(
  1524. &m_pCertMachine->m_strMachineNamePersist,
  1525. &m_pCertMachine->m_strMachineName,
  1526. &m_dwFlagsPersist);
  1527. pBasePage = pPage;
  1528. // Object gets deleted when the page is destroyed
  1529. ASSERT(lpProvider != NULL);
  1530. ASSERT(pBasePage != NULL);
  1531. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1532. if (hPage == NULL)
  1533. {
  1534. hr = myHLastError();
  1535. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1536. }
  1537. lpProvider->AddPage(hPage);
  1538. break;
  1539. }
  1540. case CCT_SCOPE:
  1541. {
  1542. // if not base scope
  1543. if (0 != pInternal->m_cookie)
  1544. {
  1545. // switch on folder type
  1546. CFolder* pFolder = GetParentFolder(pInternal);
  1547. ASSERT(pFolder != NULL);
  1548. if (pFolder == NULL)
  1549. {
  1550. hr = E_POINTER;
  1551. _JumpError(hr, Ret, "GetParentFolder");
  1552. }
  1553. switch(pFolder->m_type)
  1554. {
  1555. case SERVER_INSTANCE:
  1556. {
  1557. //1
  1558. CSvrSettingsGeneralPage* pControlPage = new CSvrSettingsGeneralPage(pFolder->m_pCertCA);
  1559. if (pControlPage != NULL)
  1560. {
  1561. pControlPage->m_hConsoleHandle = handle; // only do this on primary
  1562. pBasePage = pControlPage;
  1563. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1564. if (hPage == NULL)
  1565. {
  1566. hr = myHLastError();
  1567. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1568. }
  1569. lpProvider->AddPage(hPage);
  1570. }
  1571. //2
  1572. {
  1573. CSvrSettingsPolicyPage* pPage = new CSvrSettingsPolicyPage(pControlPage);
  1574. if (pPage != NULL)
  1575. {
  1576. pBasePage = pPage;
  1577. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1578. if (hPage == NULL)
  1579. {
  1580. hr = myHLastError();
  1581. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1582. }
  1583. lpProvider->AddPage(hPage);
  1584. }
  1585. }
  1586. //3
  1587. {
  1588. CSvrSettingsExitPage* pPage = new CSvrSettingsExitPage(pControlPage);
  1589. if (pPage != NULL)
  1590. {
  1591. pBasePage = pPage;
  1592. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1593. if (hPage == NULL)
  1594. {
  1595. hr = myHLastError();
  1596. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1597. }
  1598. lpProvider->AddPage(hPage);
  1599. }
  1600. }
  1601. //4
  1602. {
  1603. // Centralized extensions page available only in whistler
  1604. if (pFolder->m_pCertCA->m_pParentMachine->FIsWhistlerMachine())
  1605. {
  1606. CSvrSettingsExtensionPage* pPage = new CSvrSettingsExtensionPage(pFolder->m_pCertCA, pControlPage);
  1607. if (pPage != NULL)
  1608. {
  1609. pBasePage = pPage;
  1610. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1611. if (hPage == NULL)
  1612. {
  1613. hr = myHLastError();
  1614. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1615. }
  1616. lpProvider->AddPage(hPage);
  1617. }
  1618. }
  1619. }
  1620. //5
  1621. {
  1622. CSvrSettingsStoragePage* pPage = new CSvrSettingsStoragePage(pControlPage);
  1623. if (pPage != NULL)
  1624. {
  1625. pBasePage = pPage;
  1626. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1627. if (hPage == NULL)
  1628. {
  1629. hr = myHLastError();
  1630. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1631. }
  1632. lpProvider->AddPage(hPage);
  1633. }
  1634. }
  1635. //6
  1636. {
  1637. // audit available only in whistler advanced server
  1638. if(pFolder->m_pCertCA->m_pParentMachine->FIsWhistlerMachine() && pFolder->m_pCertCA->FIsAdvancedServer())
  1639. {
  1640. CSvrSettingsCertManagersPage* pPage =
  1641. new CSvrSettingsCertManagersPage(pControlPage);
  1642. if (pPage != NULL)
  1643. {
  1644. pBasePage = pPage;
  1645. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1646. if (hPage == NULL)
  1647. {
  1648. hr = myHLastError();
  1649. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1650. }
  1651. lpProvider->AddPage(hPage);
  1652. }
  1653. }
  1654. }
  1655. //7
  1656. {
  1657. // audit available only in whistler advanced server
  1658. if(pFolder->m_pCertCA->m_pParentMachine->FIsWhistlerMachine() && pFolder->m_pCertCA->FIsAdvancedServer())
  1659. {
  1660. CSvrSettingsAuditFilterPage* pPage =
  1661. new CSvrSettingsAuditFilterPage(pControlPage);
  1662. if (pPage != NULL)
  1663. {
  1664. pBasePage = pPage;
  1665. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1666. if (hPage == NULL)
  1667. {
  1668. hr = myHLastError();
  1669. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1670. }
  1671. lpProvider->AddPage(hPage);
  1672. }
  1673. }
  1674. }
  1675. //8
  1676. {
  1677. // audit available only in whistler advanced server, enterprise
  1678. if(pFolder->m_pCertCA->m_pParentMachine->FIsWhistlerMachine() && pFolder->m_pCertCA->FIsAdvancedServer() && IsEnterpriseCA(pFolder->m_pCertCA->GetCAType()) )
  1679. {
  1680. CSvrSettingsKRAPage* pPage = new CSvrSettingsKRAPage(
  1681. pFolder->m_pCertCA,
  1682. pControlPage);
  1683. if (pPage != NULL)
  1684. {
  1685. pBasePage = pPage;
  1686. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1687. if (hPage == NULL)
  1688. {
  1689. hr = myHLastError();
  1690. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1691. }
  1692. lpProvider->AddPage(hPage);
  1693. }
  1694. }
  1695. }
  1696. //9
  1697. {
  1698. // if error, don't display this page
  1699. LPSECURITYINFO pCASecurity = NULL;
  1700. hr = CreateCASecurityInfo(pFolder->m_pCertCA, &pCASecurity);
  1701. _PrintIfError(hr, "CreateCASecurityInfo");
  1702. if (hr == S_OK)
  1703. {
  1704. // allow proppages to clean up security info
  1705. pControlPage->SetAllocedSecurityInfo(pCASecurity);
  1706. HPROPSHEETPAGE hPage = CreateSecurityPage(pCASecurity);
  1707. if (hPage == NULL)
  1708. {
  1709. hr = myHLastError();
  1710. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1711. }
  1712. lpProvider->AddPage(hPage);
  1713. }
  1714. }
  1715. hr = S_OK;
  1716. break;
  1717. }// end case SERVER_INSTANCE
  1718. case SERVERFUNC_CRL_PUBLICATION:
  1719. {
  1720. //1
  1721. CCRLPropPage* pControlPage = new CCRLPropPage(pFolder->m_pCertCA);
  1722. if (pControlPage != NULL)
  1723. {
  1724. pControlPage->m_hConsoleHandle = handle;
  1725. pBasePage = pControlPage;
  1726. // Object gets deleted when the page is destroyed
  1727. ASSERT(lpProvider != NULL);
  1728. ASSERT(pBasePage != NULL);
  1729. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1730. if (hPage == NULL)
  1731. {
  1732. hr = myHLastError();
  1733. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1734. }
  1735. lpProvider->AddPage(hPage);
  1736. }
  1737. //2
  1738. {
  1739. CCRLViewPage* pPage = new CCRLViewPage(pControlPage);
  1740. if (pPage != NULL)
  1741. {
  1742. pBasePage = pPage;
  1743. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pBasePage->m_psp);
  1744. if (hPage == NULL)
  1745. {
  1746. hr = myHLastError();
  1747. _JumpError(hr, Ret, "CreatePropertySheetPage");
  1748. }
  1749. lpProvider->AddPage(hPage);
  1750. }
  1751. }
  1752. break;
  1753. }
  1754. default:
  1755. break;
  1756. } // end switch(pFolder->m_type)
  1757. } // end switch(scope)
  1758. }
  1759. break;
  1760. default:
  1761. break;
  1762. }
  1763. Ret:
  1764. FREE_DATA(pInternal);
  1765. return hr;
  1766. }
  1767. STDMETHODIMP CComponentDataImpl::QueryPagesFor(LPDATAOBJECT lpDataObject)
  1768. {
  1769. BOOL bResult = FALSE;
  1770. INTERNAL* pInternal = ExtractInternalFormat(lpDataObject);
  1771. if (NULL == pInternal)
  1772. return S_FALSE;
  1773. if (pInternal->m_cookie != NULL)
  1774. {
  1775. CFolder* pFolder = GetParentFolder(pInternal);
  1776. if (pFolder != NULL)
  1777. {
  1778. switch(pFolder->m_type)
  1779. {
  1780. case SERVER_INSTANCE:
  1781. case SERVERFUNC_CRL_PUBLICATION:
  1782. bResult = TRUE;
  1783. default:
  1784. break;
  1785. }
  1786. }
  1787. }
  1788. else
  1789. {
  1790. // say YES to snapin manager
  1791. if (CCT_SNAPIN_MANAGER == pInternal->m_type)
  1792. bResult = TRUE;
  1793. }
  1794. FREE_DATA(pInternal);
  1795. return (bResult) ? S_OK : S_FALSE;
  1796. // Look at the data object and see if it an item in the scope pane
  1797. // return IsScopePaneNode(lpDataObject) ? S_OK : S_FALSE;
  1798. }
  1799. ///////////////////////////////////////////////////////////////////////////////
  1800. // IExtendContextMenu implementation
  1801. //
  1802. STDMETHODIMP CComponentDataImpl::AddMenuItems(LPDATAOBJECT pDataObject,
  1803. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1804. LONG *pInsertionAllowed)
  1805. {
  1806. HRESULT hr = S_OK;
  1807. // Note - snap-ins need to look at the data object and determine
  1808. // in what context, menu items need to be added. They must also
  1809. // observe the insertion allowed flags to see what items can be
  1810. // added.
  1811. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  1812. if (NULL == pInternal)
  1813. return S_OK;
  1814. BOOL fResultItem = (pInternal->m_type == CCT_RESULT);
  1815. BOOL fMultiSel = IsMMCMultiSelectDataObject(pDataObject);
  1816. CFolder* pFolder;
  1817. if (!fResultItem)
  1818. pFolder = GetParentFolder(pInternal);
  1819. else
  1820. {
  1821. // GetParent might work, but doesn't for virtual items...
  1822. ASSERT(m_pCurSelFolder);
  1823. pFolder = m_pCurSelFolder;
  1824. }
  1825. FOLDER_TYPES folderType = NONE;
  1826. if (pFolder == NULL)
  1827. folderType = MACHINE_INSTANCE;
  1828. else
  1829. folderType = pFolder->GetType();
  1830. // Loop through and add each of the "topItems"
  1831. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TOP)
  1832. {
  1833. // don't do for multisel
  1834. if (!fMultiSel)
  1835. {
  1836. TASKITEM* pm = topItems;
  1837. // Disable retarget if we haven't yet clicked on the static root. Otherwise,
  1838. // DisplayProperRootNodeName handles load-from-file
  1839. // MMCN_EXPAND handles add/remove and expanded
  1840. pm[ENUM_RETARGET_SNAPIN].myitem.item.fFlags = m_pStaticRoot ? MFS_ENABLED : MFS_GRAYED;
  1841. for (; pm->myitem.item.strName; pm++)
  1842. {
  1843. // does it match scope/result type?
  1844. if (fResultItem != ((pm->dwFlags & TASKITEM_FLAG_RESULTITEM) != 0) )
  1845. continue;
  1846. // does it match area it should be in?
  1847. // for each task, insert if matches the current folder
  1848. if ((pm->type != SERVERFUNC_ALL_FOLDERS) && (folderType != pm->type))
  1849. continue;
  1850. hr = pContextMenuCallback->AddItem(&pm->myitem.item);
  1851. _JumpIfError(hr, Ret, "AddItem");
  1852. }
  1853. }
  1854. }
  1855. // this is the end of the line if folder nonexistant
  1856. if (pFolder == NULL)
  1857. goto Ret;
  1858. // Loop through and add each of the view items
  1859. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_VIEW)
  1860. {
  1861. }
  1862. if (*pInsertionAllowed & CCM_INSERTIONALLOWED_TASK)
  1863. {
  1864. // ptr to tasks
  1865. TASKITEM* pm = taskItems;
  1866. BOOL fRunningLocally = m_pCertMachine->IsLocalMachine();
  1867. BOOL fSvcRunning = m_pCertMachine->IsCertSvrServiceRunning();
  1868. if ( IsAllowedStartStop(pFolder, m_pCertMachine) )
  1869. AddStartStopTasks(pContextMenuCallback, fSvcRunning);
  1870. // only fixup on server instance
  1871. if (folderType == SERVER_INSTANCE)
  1872. {
  1873. // fixup entries depending on install type/state
  1874. if (IsRootCA(pFolder->GetCA()->GetCAType())) // root ca?
  1875. {
  1876. pm[ENUM_TASK_INSTALL].myitem.item.fFlags = MFS_HIDDEN; // not available
  1877. pm[ENUM_TASK_REQUEST].myitem.item.fFlags = MFS_HIDDEN; // not available
  1878. pm[ENUM_TASK_ROLLOVER].myitem.item.fFlags = MFS_ENABLED;
  1879. }
  1880. else // sub ca
  1881. {
  1882. if (pFolder->GetCA()->FIsRequestOutstanding())
  1883. pm[ENUM_TASK_INSTALL].myitem.item.fFlags = MFS_ENABLED;
  1884. else
  1885. pm[ENUM_TASK_INSTALL].myitem.item.fFlags = MFS_HIDDEN;
  1886. if (pFolder->GetCA()->FIsIncompleteInstallation()) // incomplete
  1887. {
  1888. pm[ENUM_TASK_REQUEST].myitem.item.fFlags = MFS_ENABLED;
  1889. pm[ENUM_TASK_ROLLOVER].myitem.item.fFlags = MFS_HIDDEN; // not available
  1890. }
  1891. else // complete install
  1892. {
  1893. pm[ENUM_TASK_REQUEST].myitem.item.fFlags = MFS_HIDDEN; // not available
  1894. pm[ENUM_TASK_ROLLOVER].myitem.item.fFlags = MFS_ENABLED;
  1895. }
  1896. }
  1897. static bool fIsMember;
  1898. static bool fIsMemberChecked = false;
  1899. if(!fIsMemberChecked)
  1900. {
  1901. hr = IsCurrentUserBuiltinAdmin(&fIsMember);
  1902. if(S_OK==hr)
  1903. {
  1904. fIsMemberChecked = true;
  1905. }
  1906. }
  1907. // Hide renew/install CA cert item if not local admin or if we
  1908. // failed to figure it out. Ignore the error.
  1909. // !!! Post Whistler when we get renew CA cert to work for non
  1910. // local admin we should change the code here to hide the item
  1911. // based on the role that is allowed to do it.
  1912. if(S_OK != hr || !fIsMember)
  1913. {
  1914. pm[ENUM_TASK_ROLLOVER].myitem.item.fFlags = MFS_HIDDEN;
  1915. hr = S_OK;
  1916. }
  1917. }
  1918. // don't allow properties on multisel
  1919. pm[ENUM_TASK_ATTREXTS_CRL].myitem.item.fFlags = fMultiSel ? MFS_HIDDEN : MFS_ENABLED;
  1920. pm[ENUM_TASK_ATTREXTS_ISS].myitem.item.fFlags = fMultiSel ? MFS_HIDDEN : MFS_ENABLED;
  1921. pm[ENUM_TASK_ATTREXTS_PEND].myitem.item.fFlags = fMultiSel ? MFS_HIDDEN : MFS_ENABLED;
  1922. pm[ENUM_TASK_ATTREXTS_FAIL].myitem.item.fFlags = fMultiSel ? MFS_HIDDEN : MFS_ENABLED;
  1923. // insert all other tasks per folder
  1924. for (; pm->myitem.item.strName; pm++)
  1925. {
  1926. // does it match scope/result type?
  1927. if (fResultItem != ((pm->dwFlags & TASKITEM_FLAG_RESULTITEM) != 0))
  1928. continue;
  1929. // are we remote, and is it marked localonly? (not yes/no like other tests here)
  1930. if (((pm->dwFlags & TASKITEM_FLAG_LOCALONLY)) && (!fRunningLocally))
  1931. continue;
  1932. // does it match area it should be in?
  1933. // for each task, insert if matches the current folder
  1934. if ((pm->type != SERVERFUNC_ALL_FOLDERS) && (folderType != pm->type))
  1935. continue;
  1936. // is this task supposed to be hidden?
  1937. if (MFS_HIDDEN == pm->myitem.item.fFlags)
  1938. continue;
  1939. hr = pContextMenuCallback->AddItem(&pm->myitem.item);
  1940. _JumpIfError(hr, Ret, "AddItem");
  1941. }
  1942. }
  1943. Ret:
  1944. FREE_DATA(pInternal);
  1945. return hr;
  1946. }
  1947. BOOL CComponentDataImpl::AddStartStopTasks(
  1948. LPCONTEXTMENUCALLBACK pContextMenuCallback,
  1949. BOOL fSvcRunning)
  1950. {
  1951. HRESULT hr;
  1952. MY_CONTEXTMENUITEM* pm = taskStartStop;
  1953. pm[ENUM_TASK_START].item.fFlags = fSvcRunning ? MF_GRAYED : MF_ENABLED;
  1954. hr = pContextMenuCallback->AddItem(&pm[ENUM_TASK_START].item);
  1955. _JumpIfError(hr, Ret, "AddItem");
  1956. pm[ENUM_TASK_STOP].item.fFlags = fSvcRunning ? MF_ENABLED : MF_GRAYED;
  1957. hr = pContextMenuCallback->AddItem(&pm[ENUM_TASK_STOP].item);
  1958. _JumpIfError(hr, Ret, "AddItem");
  1959. Ret:
  1960. return (hr == ERROR_SUCCESS);
  1961. }
  1962. STDMETHODIMP CComponentDataImpl::Command(LONG nCommandID, LPDATAOBJECT pDataObject)
  1963. {
  1964. // Note - snap-ins need to look at the data object and determine
  1965. // in what context the command is being called.
  1966. HRESULT dwErr = S_OK;
  1967. INTERNAL* pInternal = ExtractInternalFormat(pDataObject);
  1968. ASSERT(pInternal);
  1969. if (NULL == pInternal)
  1970. return S_OK;
  1971. BOOL fMustRefresh = FALSE;
  1972. BOOL fPopup = TRUE;
  1973. CFolder* pFolder = GetParentFolder(pInternal);
  1974. // Handle each of the commands.
  1975. switch (nCommandID)
  1976. {
  1977. case IDC_STOPSERVER:
  1978. {
  1979. HWND hwndMain;
  1980. dwErr = m_pConsole->GetMainWindow(&hwndMain);
  1981. if (dwErr == S_OK)
  1982. dwErr = m_pCertMachine->CertSvrStartStopService(hwndMain, FALSE);
  1983. // notify views: refresh service toolbar buttons
  1984. fMustRefresh = TRUE;
  1985. break;
  1986. }
  1987. case IDC_STARTSERVER:
  1988. {
  1989. HWND hwndMain;
  1990. dwErr = m_pConsole->GetMainWindow(&hwndMain);
  1991. if (S_OK == dwErr)
  1992. dwErr = m_pCertMachine->CertSvrStartStopService(hwndMain, TRUE);
  1993. // check for ERROR_INSTALL_SUSPEND or HR(ERROR_INSTALL_SUSPEND)!!
  1994. if ((((HRESULT)ERROR_INSTALL_SUSPEND) == dwErr) || (HRESULT_FROM_WIN32(ERROR_INSTALL_SUSPEND) == dwErr))
  1995. {
  1996. CString cstrMsg, cstrTitle;
  1997. cstrMsg.LoadString(IDS_COMPLETE_HIERARCHY_INSTALL_MSG);
  1998. cstrTitle.LoadString(IDS_MSG_TITLE);
  1999. CertSvrCA* pCA;
  2000. for (DWORD i=0; i<m_pCertMachine->GetCaCount(); i++)
  2001. {
  2002. pCA = m_pCertMachine->GetCaAtPos(i);
  2003. // search for any/all incomplete hierarchies
  2004. if (pCA->FIsIncompleteInstallation())
  2005. {
  2006. int iRet;
  2007. WCHAR sz[512];
  2008. wsprintf(sz, (LPCWSTR)cstrMsg, (LPCWSTR)pCA->m_strCommonName, (LPCWSTR)pCA->m_strServer);
  2009. m_pConsole->MessageBox(
  2010. sz,
  2011. cstrTitle,
  2012. MB_YESNO,
  2013. &iRet);
  2014. if (IDYES != iRet)
  2015. break;
  2016. dwErr = CARequestInstallHierarchyWizard(pCA, hwndMain, FALSE, FALSE);
  2017. if (dwErr != S_OK)
  2018. {
  2019. // fPopup = FALSE;// sometimes no notification -- better to have 2 dlgs
  2020. break;
  2021. }
  2022. }
  2023. }
  2024. // my responsibility to start the service again
  2025. if (dwErr == S_OK)
  2026. dwErr = m_pCertMachine->CertSvrStartStopService(hwndMain, TRUE);
  2027. }
  2028. else if ((((HRESULT)ERROR_FILE_NOT_FOUND) == dwErr) || (HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) == dwErr))
  2029. {
  2030. // file not found error could be related to policy module
  2031. WCHAR const *pwsz = myGetErrorMessageText(dwErr, TRUE);
  2032. CString cstrFullMessage = pwsz;
  2033. if (NULL != pwsz)
  2034. {
  2035. LocalFree(const_cast<WCHAR *>(pwsz));
  2036. }
  2037. cstrFullMessage += L"\n\n";
  2038. CString cstrHelpfulMessage;
  2039. cstrHelpfulMessage.LoadString(IDS_POSSIBLEERROR_NO_POLICY_MODULE);
  2040. cstrFullMessage += cstrHelpfulMessage;
  2041. CString cstrTitle;
  2042. cstrTitle.LoadString(IDS_MSG_TITLE);
  2043. int iRet;
  2044. m_pConsole->MessageBox(
  2045. cstrFullMessage,
  2046. cstrTitle,
  2047. MB_OK,
  2048. &iRet);
  2049. dwErr = ERROR_SUCCESS;
  2050. }
  2051. // notify views: refresh service toolbar buttons
  2052. fMustRefresh = TRUE;
  2053. break;
  2054. }
  2055. case IDC_PUBLISHCRL:
  2056. {
  2057. ASSERT(pInternal->m_type != CCT_RESULT);
  2058. if (NULL == pFolder)
  2059. break;
  2060. HWND hwnd;
  2061. dwErr = m_pConsole->GetMainWindow(&hwnd);
  2062. ASSERT(dwErr == ERROR_SUCCESS);
  2063. if (dwErr != ERROR_SUCCESS)
  2064. hwnd = NULL; // should work
  2065. dwErr = PublishCRLWizard(pFolder->m_pCertCA, hwnd);
  2066. break;
  2067. // no refresh
  2068. }
  2069. case IDC_BACKUP_CA:
  2070. {
  2071. HWND hwnd;
  2072. dwErr = m_pConsole->GetMainWindow(&hwnd);
  2073. // NULL should work
  2074. if (S_OK != dwErr)
  2075. hwnd = NULL;
  2076. if (NULL == pFolder)
  2077. break;
  2078. dwErr = CABackupWizard(pFolder->GetCA(), hwnd);
  2079. // refresh the status of the CA -- may have started it during this operation
  2080. fMustRefresh = TRUE;
  2081. break;
  2082. }
  2083. case IDC_RESTORE_CA:
  2084. {
  2085. HWND hwnd;
  2086. dwErr = m_pConsole->GetMainWindow(&hwnd);
  2087. // NULL should work
  2088. if (S_OK != dwErr)
  2089. hwnd = NULL;
  2090. if (NULL == pFolder)
  2091. break;
  2092. dwErr = CARestoreWizard(pFolder->GetCA(), hwnd);
  2093. if ((myJetHResult(JET_errDatabaseDuplicate) == dwErr) ||
  2094. HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) == dwErr)
  2095. {
  2096. DisplayCertSrvErrorWithContext(hwnd, dwErr, IDS_ERR_RESTORE_OVER_EXISTING_DATABASE);
  2097. dwErr = S_OK;
  2098. }
  2099. if (HRESULT_FROM_WIN32(ERROR_DIRECTORY) == dwErr)
  2100. {
  2101. DisplayCertSrvErrorWithContext(hwnd, dwErr, IDS_ERR_RESTORE_OUT_OF_ORDER);
  2102. dwErr = S_OK;
  2103. }
  2104. // refresh after restore
  2105. fMustRefresh = TRUE;
  2106. break;
  2107. }
  2108. case IDC_SUBMITREQUEST:
  2109. {
  2110. HWND hwnd;
  2111. WCHAR szCmdLine[MAX_PATH], szSysDir[MAX_PATH];
  2112. STARTUPINFO sStartup;
  2113. ZeroMemory(&sStartup, sizeof(sStartup));
  2114. PROCESS_INFORMATION sProcess;
  2115. ZeroMemory(&sProcess, sizeof(sProcess));
  2116. sStartup.cb = sizeof(sStartup);
  2117. dwErr = m_pConsole->GetMainWindow(&hwnd);
  2118. // NULL should work
  2119. if (S_OK != dwErr)
  2120. hwnd = NULL;
  2121. if (NULL == pFolder)
  2122. break;
  2123. if (0 == GetSystemDirectory(szSysDir, ARRAYSIZE(szSysDir)))
  2124. {
  2125. dwErr = GetLastError();
  2126. break;
  2127. }
  2128. // exec "certutil -dump szReqFile szTempFile"
  2129. wsprintf(szCmdLine, L"%s\\certreq.exe -config \"%s\"", szSysDir, (LPCWSTR)pFolder->GetCA()->m_strConfig);
  2130. wcscat(szSysDir, L"\\certreq.exe");
  2131. if (!CreateProcess(
  2132. szSysDir, // exe
  2133. szCmdLine, // full cmd line
  2134. NULL,
  2135. NULL,
  2136. FALSE,
  2137. CREATE_NO_WINDOW,
  2138. NULL,
  2139. NULL,
  2140. &sStartup,
  2141. &sProcess))
  2142. {
  2143. dwErr = GetLastError();
  2144. break;
  2145. }
  2146. dwErr = S_OK;
  2147. break;
  2148. }
  2149. case IDC_INSTALL_CA:
  2150. case IDC_REQUEST_CA:
  2151. case IDC_ROLLOVER_CA:
  2152. {
  2153. HWND hwnd;
  2154. dwErr = m_pConsole->GetMainWindow(&hwnd);
  2155. // NULL should work
  2156. if (S_OK != dwErr)
  2157. hwnd = NULL;
  2158. if (NULL == pFolder)
  2159. {
  2160. dwErr = E_UNEXPECTED;
  2161. break;
  2162. }
  2163. dwErr = CARequestInstallHierarchyWizard(pFolder->GetCA(), hwnd, (nCommandID==IDC_ROLLOVER_CA), TRUE);
  2164. if (S_OK != dwErr)
  2165. {
  2166. // low level lib had popup
  2167. // fPopup = FALSE; // sometimes no notification -- better to have 2 dlgs
  2168. }
  2169. // notify views: refresh service toolbar buttons
  2170. fMustRefresh = TRUE;
  2171. break;
  2172. }
  2173. case IDC_RETARGET_SNAPIN:
  2174. {
  2175. HWND hwnd;
  2176. dwErr = m_pConsole->GetMainWindow(&hwnd);
  2177. // NULL should work
  2178. if (S_OK != dwErr)
  2179. hwnd = NULL;
  2180. // this should be base folder ONLY
  2181. if(pFolder != NULL)
  2182. {
  2183. dwErr = E_POINTER;
  2184. break;
  2185. }
  2186. CString strMachineNamePersist, strMachineName;
  2187. CChooseMachinePropPage* pPage = new CChooseMachinePropPage(); // autodelete proppage -- don't delete
  2188. if (pPage == NULL)
  2189. {
  2190. dwErr = E_OUTOFMEMORY;
  2191. break;
  2192. }
  2193. pPage->SetCaption(IDS_SCOPE_MYCOMPUTER);
  2194. // Initialize state of object
  2195. pPage->InitMachineName(NULL);
  2196. // populate UI
  2197. strMachineNamePersist = m_pCertMachine->m_strMachineNamePersist;
  2198. strMachineName = m_pCertMachine->m_strMachineName;
  2199. // point to our member vars
  2200. pPage->SetOutputBuffers(
  2201. &strMachineNamePersist,
  2202. &strMachineName,
  2203. &m_dwFlagsPersist);
  2204. ASSERT(pPage != NULL);
  2205. HPROPSHEETPAGE hPage = CreatePropertySheetPage(&pPage->m_psp);
  2206. if (hPage == NULL)
  2207. {
  2208. dwErr = E_UNEXPECTED;
  2209. break;
  2210. }
  2211. PROPSHEETHEADER sPsh;
  2212. ZeroMemory(&sPsh, sizeof(sPsh));
  2213. sPsh.dwSize = sizeof(sPsh);
  2214. sPsh.dwFlags = PSH_WIZARD;
  2215. sPsh.hwndParent = hwnd;
  2216. sPsh.hInstance = g_hInstance;
  2217. sPsh.nPages = 1;
  2218. sPsh.phpage = &hPage;
  2219. dwErr = (DWORD) PropertySheet(&sPsh);
  2220. if (dwErr == (HRESULT)-1)
  2221. {
  2222. // error
  2223. dwErr = GetLastError();
  2224. break;
  2225. }
  2226. if (dwErr == (HRESULT)0)
  2227. {
  2228. // cancel
  2229. break;
  2230. }
  2231. // we've grabbed the user's choice by now, finish retargetting
  2232. CertSvrMachine* pOldMachine = m_pCertMachine;
  2233. m_pCertMachine = new CertSvrMachine;
  2234. if (NULL == m_pCertMachine)
  2235. {
  2236. m_pCertMachine = pOldMachine;
  2237. break; // bail!
  2238. }
  2239. // copy to machine object
  2240. m_pCertMachine->m_strMachineNamePersist = strMachineNamePersist;
  2241. m_pCertMachine->m_strMachineName = strMachineName;
  2242. dwErr = DisplayProperRootNodeName(m_pStaticRoot); // fix display
  2243. _PrintIfError(dwErr, "DisplayProperRootNodeName");
  2244. dwErr = SynchDisplayedCAList(pDataObject); // add/remove folders
  2245. _PrintIfError(dwErr, "SynchDisplayedCAList");
  2246. // after Synch, we remove old machine -- there are no references left to it
  2247. if (pOldMachine)
  2248. pOldMachine->Release();
  2249. fMustRefresh = TRUE; // update folder icons, descriptions
  2250. break;
  2251. }
  2252. default:
  2253. ASSERT(FALSE); // Unknown command!
  2254. break;
  2255. }
  2256. FREE_DATA(pInternal);
  2257. if ((dwErr != ERROR_SUCCESS) &&
  2258. (dwErr != ERROR_CANCELLED) &&
  2259. (dwErr != HRESULT_FROM_WIN32(ERROR_CANCELLED)) &&
  2260. (dwErr != HRESULT_FROM_WIN32(ERROR_NOT_READY))
  2261. && fPopup)
  2262. {
  2263. HWND hwnd;
  2264. DWORD dwErr2 = m_pConsole->GetMainWindow(&hwnd);
  2265. ASSERT(dwErr2 == ERROR_SUCCESS);
  2266. if (dwErr2 != ERROR_SUCCESS)
  2267. hwnd = NULL; // should work
  2268. if (((HRESULT)RPC_S_SERVER_UNAVAILABLE) == dwErr)
  2269. {
  2270. DisplayCertSrvErrorWithContext(hwnd, dwErr, IDS_SERVER_UNAVAILABLE);
  2271. }
  2272. else if(HRESULT_FROM_WIN32(ERROR_OLD_WIN_VERSION)==dwErr ||
  2273. ((HRESULT)ERROR_OLD_WIN_VERSION)==dwErr)
  2274. {
  2275. DisplayCertSrvErrorWithContext(hwnd, dwErr, IDS_OLD_CA);
  2276. }
  2277. else
  2278. {
  2279. DisplayGenericCertSrvError(hwnd, dwErr);
  2280. }
  2281. }
  2282. // only do this once
  2283. if (fMustRefresh)
  2284. {
  2285. // notify views: refresh service toolbar buttons
  2286. m_pConsole->UpdateAllViews(
  2287. pDataObject,
  2288. 0,
  2289. 0);
  2290. }
  2291. return S_OK;
  2292. }
  2293. void CComponentDataImpl::UpdateScopeIcons()
  2294. {
  2295. CFolder* pFolder;
  2296. POSITION pos;
  2297. int nImage;
  2298. // walk through our internal list, modify, and resend to scope
  2299. pos = m_scopeItemList.GetHeadPosition();
  2300. while(pos)
  2301. {
  2302. pFolder = m_scopeItemList.GetNext(pos);
  2303. ASSERT(pFolder);
  2304. if (NULL == pFolder)
  2305. break;
  2306. // only modify server instances
  2307. if (pFolder->GetType() != SERVER_INSTANCE)
  2308. continue;
  2309. if (pFolder->m_pCertCA->m_pParentMachine->IsCertSvrServiceRunning())
  2310. nImage = IMGINDEX_CERTSVR_RUNNING;
  2311. else
  2312. nImage = IMGINDEX_CERTSVR_STOPPED;
  2313. // folder currently has these values defined, right?
  2314. ASSERT(pFolder->m_ScopeItem.mask & SDI_IMAGE);
  2315. ASSERT(pFolder->m_ScopeItem.mask & SDI_OPENIMAGE);
  2316. // These are the only values we wish to reset
  2317. pFolder->m_ScopeItem.mask = SDI_IMAGE | SDI_OPENIMAGE;
  2318. pFolder->m_ScopeItem.nImage = nImage;
  2319. pFolder->m_ScopeItem.nOpenImage = nImage;
  2320. // and send these changes back to scope
  2321. m_pScope->SetItem(&pFolder->m_ScopeItem);
  2322. }
  2323. return;
  2324. }