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.

149 lines
3.7 KiB

  1. // ChooseCspPage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CertWiz.h"
  5. #include "ChooseCspPage.h"
  6. #include "Certificat.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CChooseCertPage property page
  14. IMPLEMENT_DYNCREATE(CChooseCspPage, CIISWizardPage)
  15. CChooseCspPage::CChooseCspPage(CCertificate * pCert)
  16. : CIISWizardPage(CChooseCspPage::IDD, IDS_CERTWIZ, TRUE),
  17. m_pCert(pCert)
  18. {
  19. //{{AFX_DATA_INIT(CChooseCspPage)
  20. // NOTE: the ClassWizard will add member initialization here
  21. //}}AFX_DATA_INIT
  22. }
  23. CChooseCspPage::~CChooseCspPage()
  24. {
  25. }
  26. void CChooseCspPage::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CIISWizardPage::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(CChooseCspPage)
  30. DDX_Control(pDX, IDC_CSP_LIST, m_List);
  31. //}}AFX_DATA_MAP
  32. }
  33. BEGIN_MESSAGE_MAP(CChooseCspPage, CIISWizardPage)
  34. //{{AFX_MSG_MAP(CChooseCspPage)
  35. ON_LBN_SELCHANGE(IDC_CSP_LIST, OnListSelChange)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CChooseCspPage message handlers
  40. LRESULT CChooseCspPage::OnWizardBack()
  41. {
  42. return IDD_PREV_PAGE;
  43. }
  44. LRESULT CChooseCspPage::OnWizardNext()
  45. {
  46. int index = m_List.GetCurSel();
  47. ASSERT(index != LB_ERR);
  48. m_List.GetText(index, m_pCert->m_CspName);
  49. m_pCert->m_CustomProviderType = (DWORD) m_List.GetItemData(index);
  50. return IDD_NEXT_PAGE;
  51. }
  52. BOOL CChooseCspPage::OnSetActive()
  53. {
  54. // If nothing is selected -- stay here
  55. if (!m_pCert->m_CspName.IsEmpty())
  56. {
  57. m_List.SelectString(-1, m_pCert->m_CspName);
  58. }
  59. SetWizardButtons(LB_ERR == m_List.GetCurSel() ?
  60. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  61. return CIISWizardPage::OnSetActive();
  62. }
  63. BOOL CChooseCspPage::OnInitDialog()
  64. {
  65. ASSERT(m_pCert != NULL);
  66. CIISWizardPage::OnInitDialog();
  67. CString str;
  68. BSTR bstrProvName = NULL;
  69. DWORD dwType, nProv;
  70. int j;
  71. HRESULT hr;
  72. // array of compatible CSP provider types (see wincrypt.h)
  73. DWORD IISProvType[] =
  74. {
  75. PROV_RSA_SCHANNEL,
  76. PROV_DH_SCHANNEL
  77. };
  78. IEnroll * pEnroll = m_pCert->GetEnrollObject();
  79. ASSERT(pEnroll != NULL);
  80. // Loop, for each Prov Type
  81. for (j = 0; j < (sizeof(IISProvType)/sizeof(DWORD)); j++)
  82. {
  83. nProv = 0;
  84. // check specific prov type
  85. dwType = IISProvType[j];
  86. // pEnroll is previously instantiated ICEnroll interface pointer
  87. hr = pEnroll->put_ProviderType(dwType);
  88. if (FAILED(hr))
  89. {
  90. TRACE(_T("Failed put_ProviderType - %x\n"), hr);
  91. goto error;
  92. }
  93. // enumerate the CSPs of this type
  94. int idx;
  95. while (S_OK == (hr = pEnroll->enumProvidersWStr(nProv, 0, &bstrProvName)))
  96. {
  97. TRACE(_T("Provider %ws (type %d )\n"), bstrProvName, dwType );
  98. // increment the index
  99. nProv++;
  100. // Free this string, so it can be re-used.
  101. idx = m_List.AddString(bstrProvName);
  102. m_List.SetItemData(idx, dwType);
  103. if (NULL != bstrProvName)
  104. {
  105. CoTaskMemFree(bstrProvName);
  106. bstrProvName = NULL;
  107. }
  108. }
  109. // Print message if provider type doesn't have any CSPs.
  110. if (0 == nProv)
  111. {
  112. TRACE(_T("There were no CSPs of type %d\n"), dwType );
  113. }
  114. }
  115. error:
  116. // Clean up resources, etc.
  117. if (NULL != bstrProvName)
  118. CoTaskMemFree(bstrProvName);
  119. return TRUE;
  120. }
  121. void CChooseCspPage::OnListSelChange()
  122. {
  123. SetWizardButtons(-1 == m_List.GetCurSel() ?
  124. PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  125. }