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.

404 lines
13 KiB

  1. // CertWizCtl.cpp : Implementation of the CCertWizCtrl ActiveX Control class.
  2. #include "stdafx.h"
  3. #include "CertWiz.h"
  4. #include "CertWizCtl.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. IMPLEMENT_DYNCREATE(CCertWizCtrl, COleControl)
  11. /////////////////////////////////////////////////////////////////////////////
  12. // Message map
  13. BEGIN_MESSAGE_MAP(CCertWizCtrl, COleControl)
  14. //{{AFX_MSG_MAP(CCertWizCtrl)
  15. // NOTE - ClassWizard will add and remove message map entries
  16. // DO NOT EDIT what you see in these blocks of generated code !
  17. //}}AFX_MSG_MAP
  18. ON_MESSAGE(OCM_COMMAND, OnOcmCommand)
  19. ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
  20. END_MESSAGE_MAP()
  21. /////////////////////////////////////////////////////////////////////////////
  22. // Dispatch map
  23. BEGIN_DISPATCH_MAP(CCertWizCtrl, COleControl)
  24. //{{AFX_DISPATCH_MAP(CCertWizCtrl)
  25. DISP_FUNCTION(CCertWizCtrl, "SetMachineName", SetMachineName, VT_EMPTY, VTS_BSTR)
  26. DISP_FUNCTION(CCertWizCtrl, "SetServerInstance", SetServerInstance, VT_EMPTY, VTS_BSTR)
  27. DISP_STOCKFUNC_DOCLICK()
  28. //}}AFX_DISPATCH_MAP
  29. END_DISPATCH_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Event map
  32. BEGIN_EVENT_MAP(CCertWizCtrl, COleControl)
  33. //{{AFX_EVENT_MAP(CCertWizCtrl)
  34. //}}AFX_EVENT_MAP
  35. END_EVENT_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Property pages
  38. // TODO: Add more property pages as needed. Remember to increase the count!
  39. //BEGIN_PROPPAGEIDS(CCertWizCtrl, 1)
  40. // PROPPAGEID(CCertWizPropPage::guid)
  41. //END_PROPPAGEIDS(CCertWizCtrl)
  42. /////////////////////////////////////////////////////////////////////////////
  43. // Initialize class factory and guid
  44. IMPLEMENT_OLECREATE_EX(CCertWizCtrl, "CERTWIZ.CertWizCtrl.1",
  45. 0xd4be8632, 0xc85, 0x11d2, 0x91, 0xb1, 0, 0xc0, 0x4f, 0x8c, 0x87, 0x61)
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Type library ID and version
  48. IMPLEMENT_OLETYPELIB(CCertWizCtrl, _tlid, _wVerMajor, _wVerMinor)
  49. /////////////////////////////////////////////////////////////////////////////
  50. // Interface IDs
  51. const IID BASED_CODE IID_DCertWiz =
  52. { 0xd4be8630, 0xc85, 0x11d2, { 0x91, 0xb1, 0, 0xc0, 0x4f, 0x8c, 0x87, 0x61 } };
  53. const IID BASED_CODE IID_DCertWizEvents =
  54. { 0xd4be8631, 0xc85, 0x11d2, { 0x91, 0xb1, 0, 0xc0, 0x4f, 0x8c, 0x87, 0x61 } };
  55. /////////////////////////////////////////////////////////////////////////////
  56. // Control type information
  57. static const DWORD BASED_CODE _dwCertWizOleMisc =
  58. OLEMISC_INVISIBLEATRUNTIME |
  59. OLEMISC_SETCLIENTSITEFIRST |
  60. OLEMISC_INSIDEOUT |
  61. OLEMISC_CANTLINKINSIDE |
  62. OLEMISC_RECOMPOSEONRESIZE;
  63. IMPLEMENT_OLECTLTYPE(CCertWizCtrl, IDS_CERTWIZ, _dwCertWizOleMisc)
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CCertWizCtrl::CCertWizCtrlFactory::UpdateRegistry -
  66. // Adds or removes system registry entries for CCertWizCtrl
  67. BOOL CCertWizCtrl::CCertWizCtrlFactory::UpdateRegistry(BOOL bRegister)
  68. {
  69. // TODO: Verify that your control follows apartment-model threading rules.
  70. // Refer to MFC TechNote 64 for more information.
  71. // If your control does not conform to the apartment-model rules, then
  72. // you must modify the code below, changing the 6th parameter from
  73. // afxRegApartmentThreading to 0.
  74. if (bRegister)
  75. return AfxOleRegisterControlClass(
  76. AfxGetInstanceHandle(),
  77. m_clsid,
  78. m_lpszProgID,
  79. IDS_CERTWIZ,
  80. IDB_CERTWIZ,
  81. afxRegApartmentThreading,
  82. _dwCertWizOleMisc,
  83. _tlid,
  84. _wVerMajor,
  85. _wVerMinor);
  86. else
  87. return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CCertWizCtrl::CCertWizCtrl - Constructor
  91. CCertWizCtrl::CCertWizCtrl()
  92. {
  93. InitializeIIDs(&IID_DCertWiz, &IID_DCertWizEvents);
  94. // TODO: Initialize your control's instance data here.
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CCertWizCtrl::~CCertWizCtrl - Destructor
  98. CCertWizCtrl::~CCertWizCtrl()
  99. {
  100. // TODO: Cleanup your control's instance data here.
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. // CCertWizCtrl::OnDraw - Drawing function
  104. void CCertWizCtrl::OnDraw(
  105. CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
  106. {
  107. DoSuperclassPaint(pdc, rcBounds);
  108. }
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CCertWizCtrl::DoPropExchange - Persistence support
  111. void CCertWizCtrl::DoPropExchange(CPropExchange* pPX)
  112. {
  113. ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
  114. COleControl::DoPropExchange(pPX);
  115. // TODO: Call PX_ functions for each persistent custom property.
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CCertWizCtrl::GetControlFlags -
  119. // Flags to customize MFC's implementation of ActiveX controls.
  120. //
  121. // For information on using these flags, please see MFC technical note
  122. // #nnn, "Optimizing an ActiveX Control".
  123. DWORD CCertWizCtrl::GetControlFlags()
  124. {
  125. DWORD dwFlags = COleControl::GetControlFlags();
  126. // The control can activate without creating a window.
  127. // TODO: when writing the control's message handlers, avoid using
  128. // the m_hWnd member variable without first checking that its
  129. // value is non-NULL.
  130. dwFlags |= windowlessActivate;
  131. return dwFlags;
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CCertWizCtrl::OnResetState - Reset control to default state
  135. void CCertWizCtrl::OnResetState()
  136. {
  137. COleControl::OnResetState(); // Resets defaults found in DoPropExchange
  138. // TODO: Reset any other control state here.
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CCertWizCtrl::PreCreateWindow - Modify parameters for CreateWindowEx
  142. BOOL CCertWizCtrl::PreCreateWindow(CREATESTRUCT& cs)
  143. {
  144. cs.lpszClass = _T("BUTTON");
  145. return COleControl::PreCreateWindow(cs);
  146. }
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CCertWizCtrl::IsSubclassedControl - This is a subclassed control
  149. BOOL CCertWizCtrl::IsSubclassedControl()
  150. {
  151. return TRUE;
  152. }
  153. /////////////////////////////////////////////////////////////////////////////
  154. // CCertWizCtrl::OnOcmCommand - Handle command messages
  155. LRESULT CCertWizCtrl::OnOcmCommand(WPARAM wParam, LPARAM lParam)
  156. {
  157. #ifdef _WIN32
  158. WORD wNotifyCode = HIWORD(wParam);
  159. #else
  160. WORD wNotifyCode = HIWORD(lParam);
  161. #endif
  162. // TODO: Switch on wNotifyCode here.
  163. return 0;
  164. }
  165. /////////////////////////////////////////////////////////////////////////////
  166. // CCertWizCtrl message handlers
  167. #include "WelcomePage.h"
  168. #include "FinalPages.h"
  169. #include "CertContentsPages.h"
  170. #include "GetWhatPage.h"
  171. #include "ChooseCAType.h"
  172. #include "SecuritySettingsPage.h"
  173. #include "ChooseCspPage.h"
  174. #include "OrgInfoPage.h"
  175. #include "SiteNamePage.h"
  176. #include "GeoInfoPage.h"
  177. #include "ChooseFileName.h"
  178. #include "ChooseOnlinePage.h"
  179. #include "WhatToDoPendingPage.h"
  180. #include "ManageCertPage.h"
  181. #include "ChooseCertPage.h"
  182. #include "KeyPasswordPage.h"
  183. #include "Certificat.h"
  184. #include "CopyMoveCertRemotePage.h"
  185. #include "ChooseServerPages.h"
  186. #include "ChooseServerSitePages.h"
  187. #include "sslportpage.h"
  188. void CCertWizCtrl::OnClick(USHORT iButton)
  189. {
  190. CIISWizardSheet propsheet(IDB_WIZ_LEFT, IDB_WIZ_TOP);
  191. CCertificate * cert = new CCertificate;
  192. ASSERT(!m_InstanceName.IsEmpty());
  193. cert->m_WebSiteInstanceName = m_InstanceName;
  194. cert->m_MachineName = m_MachineName;
  195. VERIFY(cert->Init());
  196. CWelcomePage welcome_page(cert);
  197. CGetWhatPage get_what_page(cert);
  198. CChooseCAType choose_ca_page(cert);
  199. CSecuritySettingsPage security_settings_page(cert);
  200. CChooseCspPage csp_page(cert);
  201. COrgInfoPage org_info_page(cert);
  202. CSiteNamePage site_name_page(cert);
  203. CGeoInfoPage geo_info_page(cert);
  204. CChooseReqFile choose_reqfile_name(cert);
  205. CChooseReqFileRenew choose_reqfile_name_renew(cert);
  206. CChooseRespFile choose_respfile_name(cert);
  207. CChooseKeyFile choose_keyfile_name(cert);
  208. CRequestToFilePage check_request(cert);
  209. CRequestToFilePageRenew check_request_renew(cert);
  210. CFinalToFilePage final_tofile_page(&cert->m_hResult, cert);
  211. CChooseOnlinePage choose_online(cert);
  212. COnlineRequestSubmit online_request_dump(cert);
  213. CWhatToDoPendingPage what_pending(cert);
  214. CInstallRespPage install_resp(cert);
  215. CManageCertPage manage_cert(cert);
  216. CFinalInstalledPage final_install(&cert->m_hResult, cert);
  217. CRemoveCertPage remove_cert(cert);
  218. CFinalRemovePage final_remove(&cert->m_hResult, cert);
  219. CReplaceCertPage replace_cert(cert);
  220. CFinalReplacedPage final_replace(&cert->m_hResult, cert);
  221. CChooseCertPage choose_cert(cert);
  222. CInstallCertPage install_cert(cert);
  223. CRequestCancelPage cancel_request(cert);
  224. CFinalCancelPage final_cancel(&cert->m_hResult, cert);
  225. CKeyPasswordPage key_password_page(cert);
  226. CInstallKeyPage install_key(cert);
  227. // new stuff for iis6
  228. CCopyMoveCertFromRemotePage copy_move_from_cert_remote_page(cert);
  229. CCopyMoveCertToRemotePage copy_move_to_cert_remote_page(cert);
  230. CChooseImportPFXFile choose_import_pfx_file_name(cert);
  231. CChooseExportPFXFile choose_export_pfx_file_name(cert);
  232. CImportPFXPasswordPage import_pfx_password_name(cert);
  233. CExportPFXPasswordPage export_pfx_password_name(cert);
  234. CInstallImportPFXPage install_import_pfx_key(cert);
  235. CInstallExportPFXPage install_export_pfx_key(cert);
  236. CFinalInstalledImportPFXPage final_import_pfx(&cert->m_hResult, cert);
  237. CFinalInstalledExportPFXPage final_export_pfx(&cert->m_hResult, cert);
  238. CChooseServerPages choose_server_name(cert);
  239. CChooseServerSitePages choose_server_site_name(cert);
  240. CChooseServerPagesTo choose_server_name_to(cert);
  241. CChooseServerSitePagesTo choose_server_site_name_to(cert);
  242. CInstallCopyFromRemotePage install_copy_from_remote(cert);
  243. CInstallMoveFromRemotePage install_move_from_remote(cert);
  244. CInstallCopyToRemotePage install_copy_to_remote(cert);
  245. CInstallMoveToRemotePage install_move_to_remote(cert);
  246. CFinalInstalledCopyFromRemotePage final_copy_from_remote(&cert->m_hResult, cert);
  247. CFinalInstalledMoveFromRemotePage final_move_from_remote(&cert->m_hResult, cert);
  248. CFinalInstalledCopyToRemotePage final_copy_to_remote(&cert->m_hResult, cert);
  249. CFinalInstalledMoveToRemotePage final_move_to_remote(&cert->m_hResult, cert);
  250. #ifdef ENABLE_W3SVC_SSL_PAGE
  251. // SSL only for iis sites
  252. CSSLPortPage choose_ssl_port(cert);
  253. #endif
  254. propsheet.AddPage(&welcome_page);
  255. propsheet.AddPage(&get_what_page);
  256. propsheet.AddPage(&choose_ca_page);
  257. propsheet.AddPage(&security_settings_page);
  258. propsheet.AddPage(&csp_page);
  259. propsheet.AddPage(&org_info_page);
  260. propsheet.AddPage(&site_name_page);
  261. propsheet.AddPage(&geo_info_page);
  262. propsheet.AddPage(&choose_reqfile_name);
  263. propsheet.AddPage(&choose_reqfile_name_renew);
  264. propsheet.AddPage(&choose_respfile_name);
  265. propsheet.AddPage(&choose_keyfile_name);
  266. propsheet.AddPage(&check_request);
  267. propsheet.AddPage(&check_request_renew);
  268. propsheet.AddPage(&final_tofile_page);
  269. propsheet.AddPage(&choose_online);
  270. propsheet.AddPage(&online_request_dump);
  271. propsheet.AddPage(&what_pending);
  272. propsheet.AddPage(&install_resp);
  273. propsheet.AddPage(&manage_cert);
  274. propsheet.AddPage(&final_install);
  275. propsheet.AddPage(&remove_cert);
  276. propsheet.AddPage(&final_remove);
  277. propsheet.AddPage(&choose_cert);
  278. propsheet.AddPage(&replace_cert);
  279. propsheet.AddPage(&final_replace);
  280. propsheet.AddPage(&install_cert);
  281. propsheet.AddPage(&cancel_request);
  282. propsheet.AddPage(&final_cancel);
  283. propsheet.AddPage(&key_password_page);
  284. propsheet.AddPage(&install_key);
  285. // new stuff for iis6
  286. propsheet.AddPage(&copy_move_from_cert_remote_page);
  287. propsheet.AddPage(&copy_move_to_cert_remote_page);
  288. propsheet.AddPage(&choose_import_pfx_file_name);
  289. propsheet.AddPage(&choose_export_pfx_file_name);
  290. propsheet.AddPage(&import_pfx_password_name);
  291. propsheet.AddPage(&export_pfx_password_name);
  292. propsheet.AddPage(&install_import_pfx_key);
  293. propsheet.AddPage(&install_export_pfx_key);
  294. propsheet.AddPage(&final_import_pfx);
  295. propsheet.AddPage(&final_export_pfx);
  296. propsheet.AddPage(&choose_server_name);
  297. propsheet.AddPage(&choose_server_site_name);
  298. propsheet.AddPage(&choose_server_name_to);
  299. propsheet.AddPage(&choose_server_site_name_to);
  300. propsheet.AddPage(&install_copy_from_remote);
  301. propsheet.AddPage(&install_move_from_remote);
  302. propsheet.AddPage(&install_copy_to_remote);
  303. propsheet.AddPage(&install_move_to_remote);
  304. propsheet.AddPage(&final_copy_from_remote);
  305. propsheet.AddPage(&final_move_from_remote);
  306. propsheet.AddPage(&final_copy_to_remote);
  307. propsheet.AddPage(&final_move_to_remote);
  308. #ifdef ENABLE_W3SVC_SSL_PAGE
  309. propsheet.AddPage(&choose_ssl_port);
  310. #endif
  311. if (IDCANCEL != propsheet.DoModal())
  312. {
  313. // save our settings to the Registry
  314. VERIFY(cert->SaveSettings());
  315. }
  316. delete cert;
  317. }
  318. void CCertWizCtrl::SetMachineName(LPCTSTR MachineName)
  319. {
  320. m_MachineName = MachineName;
  321. }
  322. void CCertWizCtrl::SetServerInstance(LPCTSTR InstanceName)
  323. {
  324. m_InstanceName = InstanceName;
  325. }