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.

216 lines
6.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2002.
  5. //
  6. // File: BasicConstraintsDlg.cpp
  7. //
  8. // Contents: Implementation of CBasicConstraintsDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // BasicConstraintsDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "BasicConstraintsDlg.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CBasicConstraintsDlg property page
  22. CBasicConstraintsDlg::CBasicConstraintsDlg(CWnd* pParent,
  23. CCertTemplate& rCertTemplate,
  24. PCERT_EXTENSION pCertExtension)
  25. : CHelpDialog(CBasicConstraintsDlg::IDD, pParent),
  26. m_rCertTemplate (rCertTemplate),
  27. m_pCertExtension (pCertExtension),
  28. m_bModified (false),
  29. m_pBCInfo (0),
  30. m_cbInfo (0)
  31. {
  32. //{{AFX_DATA_INIT(CBasicConstraintsDlg)
  33. // NOTE: the ClassWizard will add member initialization here
  34. //}}AFX_DATA_INIT
  35. m_rCertTemplate.AddRef ();
  36. }
  37. CBasicConstraintsDlg::~CBasicConstraintsDlg()
  38. {
  39. if ( m_pBCInfo )
  40. LocalFree (m_pBCInfo);
  41. m_rCertTemplate.Release ();
  42. }
  43. void CBasicConstraintsDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CHelpDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CBasicConstraintsDlg)
  47. // NOTE: the ClassWizard will add DDX and DDV calls here
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CBasicConstraintsDlg, CHelpDialog)
  51. //{{AFX_MSG_MAP(CBasicConstraintsDlg)
  52. ON_WM_CANCELMODE()
  53. ON_BN_CLICKED(IDC_BASIC_CONSTRAINTS_CRITICAL, OnBasicConstraintsCritical)
  54. ON_BN_CLICKED(IDC_ONLY_ISSUE_END_ENTITIES, OnOnlyIssueEndEntities)
  55. //}}AFX_MSG_MAP
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CBasicConstraintsDlg message handlers
  59. BOOL CBasicConstraintsDlg::OnInitDialog()
  60. {
  61. _TRACE (1, L"Entering CBasicConstraintsDlg::OnInitDialog\n");
  62. CHelpDialog::OnInitDialog();
  63. if ( m_pCertExtension->fCritical )
  64. SendDlgItemMessage (IDC_BASIC_CONSTRAINTS_CRITICAL, BM_SETCHECK, BST_CHECKED);
  65. if ( 1 == m_rCertTemplate.GetType () )
  66. {
  67. GetDlgItem (IDC_BASIC_CONSTRAINTS_CRITICAL)->EnableWindow (FALSE);
  68. GetDlgItem (IDC_ONLY_ISSUE_END_ENTITIES)->EnableWindow (FALSE);
  69. }
  70. if ( CryptDecodeObject (
  71. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  72. szOID_BASIC_CONSTRAINTS2,
  73. m_pCertExtension->Value.pbData,
  74. m_pCertExtension->Value.cbData,
  75. 0,
  76. 0,
  77. &m_cbInfo) )
  78. {
  79. m_pBCInfo = (PCERT_BASIC_CONSTRAINTS2_INFO) ::LocalAlloc (
  80. LPTR, m_cbInfo);
  81. if ( m_pBCInfo )
  82. {
  83. if ( CryptDecodeObject (
  84. X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
  85. szOID_BASIC_CONSTRAINTS2,
  86. m_pCertExtension->Value.pbData,
  87. m_pCertExtension->Value.cbData,
  88. 0,
  89. m_pBCInfo,
  90. &m_cbInfo) )
  91. {
  92. if ( m_pBCInfo->fPathLenConstraint )
  93. SendDlgItemMessage (IDC_ONLY_ISSUE_END_ENTITIES, BM_SETCHECK, BST_CHECKED);
  94. }
  95. else
  96. {
  97. _TRACE (0, L"CryptDecodeObjectEx (szOID_BASIC_CONSTRAINTS2) failed: 0x%x\n", GetLastError ());
  98. }
  99. }
  100. }
  101. else
  102. {
  103. DWORD dwErr = GetLastError ();
  104. CString text;
  105. CString caption;
  106. CThemeContextActivator activator;
  107. VERIFY (caption.LoadString (IDS_CERTTMPL));
  108. // security review 2/21/2002 BryanWal ok
  109. text.FormatMessage (IDS_CANNOT_READ_BASIC_CONSTRAINTS, GetSystemMessage (dwErr));
  110. MessageBox (text, caption, MB_ICONWARNING);
  111. _TRACE (0, L"CryptDecodeObjectEx (szOID_BASIC_CONSTRAINTS2) failed: 0x%x\n", dwErr);
  112. }
  113. EnableControls ();
  114. _TRACE (-1, L"Leaving CBasicConstraintsDlg::OnInitDialog\n");
  115. return TRUE; // return TRUE unless you set the focus to a control
  116. // EXCEPTION: OCX Property Pages should return FALSE
  117. }
  118. void CBasicConstraintsDlg::OnBasicConstraintsCritical()
  119. {
  120. m_pCertExtension->fCritical = BST_CHECKED == SendDlgItemMessage (IDC_BASIC_CONSTRAINTS_CRITICAL, BM_GETCHECK);
  121. m_bModified = true;
  122. EnableControls ();
  123. }
  124. void CBasicConstraintsDlg::EnableControls()
  125. {
  126. if ( 1 == m_rCertTemplate.GetType () )
  127. {
  128. GetDlgItem (IDOK)->EnableWindow (FALSE);
  129. GetDlgItem (IDC_BASIC_CONSTRAINTS_CRITICAL)->EnableWindow (FALSE);
  130. GetDlgItem (IDC_ONLY_ISSUE_END_ENTITIES)->EnableWindow (FALSE);
  131. }
  132. else
  133. {
  134. GetDlgItem (IDOK)->EnableWindow (m_bModified && !m_rCertTemplate.ReadOnly ());
  135. GetDlgItem (IDC_BASIC_CONSTRAINTS_CRITICAL)->EnableWindow (!m_rCertTemplate.ReadOnly ());
  136. GetDlgItem (IDC_ONLY_ISSUE_END_ENTITIES)->EnableWindow (!m_rCertTemplate.ReadOnly ());
  137. }
  138. }
  139. void CBasicConstraintsDlg::OnOnlyIssueEndEntities()
  140. {
  141. m_bModified = true;
  142. EnableControls ();
  143. }
  144. void CBasicConstraintsDlg::DoContextHelp (HWND hWndControl)
  145. {
  146. _TRACE(1, L"Entering CBasicConstraintsDlg::DoContextHelp\n");
  147. switch (::GetDlgCtrlID (hWndControl))
  148. {
  149. case IDC_STATIC:
  150. break;
  151. default:
  152. // Display context help for a control
  153. if ( !::WinHelp (
  154. hWndControl,
  155. GetContextHelpFile (),
  156. HELP_WM_HELP,
  157. (DWORD_PTR) g_aHelpIDs_IDD_BASIC_CONSTRAINTS) )
  158. {
  159. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  160. }
  161. break;
  162. }
  163. _TRACE(-1, L"Leaving CBasicConstraintsDlg::DoContextHelp\n");
  164. }
  165. void CBasicConstraintsDlg::OnOK()
  166. {
  167. if ( m_pBCInfo )
  168. {
  169. if ( BST_CHECKED == SendDlgItemMessage (IDC_ONLY_ISSUE_END_ENTITIES, BM_GETCHECK) )
  170. {
  171. m_pBCInfo->dwPathLenConstraint = 0;
  172. m_pBCInfo->fPathLenConstraint = TRUE;
  173. }
  174. else
  175. {
  176. m_pBCInfo->dwPathLenConstraint = (DWORD) -1;
  177. m_pBCInfo->fPathLenConstraint = FALSE;
  178. }
  179. bool bCritical = BST_CHECKED == SendDlgItemMessage (
  180. IDC_BASIC_CONSTRAINTS_CRITICAL, BM_GETCHECK);
  181. HRESULT hr = m_rCertTemplate.SetBasicConstraints (m_pBCInfo, bCritical);
  182. if ( FAILED (hr) )
  183. return;
  184. }
  185. else
  186. return;
  187. CHelpDialog::OnOK();
  188. }