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.

435 lines
14 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: TemplateV2SubjectNamePropertyPage.cpp
  7. //
  8. // Contents: Implementation of CTemplateV2SubjectNamePropertyPage
  9. //
  10. //----------------------------------------------------------------------------
  11. // TemplateV2SubjectNamePropertyPage.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "TemplateV2SubjectNamePropertyPage.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CTemplateV2SubjectNamePropertyPage property page
  22. CTemplateV2SubjectNamePropertyPage::CTemplateV2SubjectNamePropertyPage(
  23. CCertTemplate& rCertTemplate, bool& rbIsDirty, bool bIsComputerOrDC)
  24. : CHelpPropertyPage(CTemplateV2SubjectNamePropertyPage::IDD),
  25. m_rCertTemplate (rCertTemplate),
  26. m_rbIsDirty (rbIsDirty),
  27. m_bIsComputerOrDC (bIsComputerOrDC)
  28. {
  29. //{{AFX_DATA_INIT(CTemplateV2SubjectNamePropertyPage)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. m_rCertTemplate.AddRef ();
  33. }
  34. CTemplateV2SubjectNamePropertyPage::~CTemplateV2SubjectNamePropertyPage()
  35. {
  36. m_rCertTemplate.Release ();
  37. }
  38. void CTemplateV2SubjectNamePropertyPage::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CHelpPropertyPage::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CTemplateV2SubjectNamePropertyPage)
  42. DDX_Control(pDX, IDC_SUBJECT_NAME_NAME_COMBO, m_nameCombo);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CTemplateV2SubjectNamePropertyPage, CHelpPropertyPage)
  46. //{{AFX_MSG_MAP(CTemplateV2SubjectNamePropertyPage)
  47. ON_BN_CLICKED(IDC_SUBJECT_AND_SUBJECT_ALT_NAME, OnSubjectAndSubjectAltName)
  48. ON_CBN_SELCHANGE(IDC_SUBJECT_NAME_NAME_COMBO, OnSelchangeSubjectNameNameCombo)
  49. ON_BN_CLICKED(IDC_SUBJECT_NAME_BUILT_BY_CA, OnSubjectNameBuiltByCa)
  50. ON_BN_CLICKED(IDC_SUBJECT_NAME_SUPPLIED_IN_REQUEST, OnSubjectNameSuppliedInRequest)
  51. ON_BN_CLICKED(IDC_DNS_NAME, OnDnsName)
  52. ON_BN_CLICKED(IDC_EMAIL_IN_ALT, OnEmailInAlt)
  53. ON_BN_CLICKED(IDC_EMAIL_IN_SUB, OnEmailInSub)
  54. ON_BN_CLICKED(IDC_SPN, OnSpn)
  55. ON_BN_CLICKED(IDC_UPN, OnUpn)
  56. ON_WM_KILLFOCUS()
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CTemplateV2SubjectNamePropertyPage message handlers
  61. void CTemplateV2SubjectNamePropertyPage::OnSubjectAndSubjectAltName()
  62. {
  63. EnableControls ();
  64. }
  65. void CTemplateV2SubjectNamePropertyPage::EnableControls()
  66. {
  67. BOOL bEnable = FALSE;
  68. if ( m_rCertTemplate.ReadOnly () )
  69. {
  70. bEnable = FALSE;
  71. GetDlgItem (IDC_SUBJECT_NAME_SUPPLIED_IN_REQUEST)->EnableWindow (FALSE);
  72. GetDlgItem (IDC_SUBJECT_NAME_BUILT_BY_CA)->EnableWindow (FALSE);
  73. }
  74. else if ( BST_CHECKED == SendDlgItemMessage (IDC_SUBJECT_NAME_BUILT_BY_CA, BM_GETCHECK) )
  75. bEnable = TRUE;
  76. GetDlgItem (IDC_SUBJECT_NAME_NAME_COMBO)->EnableWindow (bEnable);
  77. GetDlgItem (IDC_SUBJECT_NAME_NAME_LABEL)->EnableWindow (bEnable);
  78. GetDlgItem (IDC_EMAIL_IN_ALT)->EnableWindow (bEnable);
  79. GetDlgItem (IDC_DNS_NAME)->EnableWindow (bEnable); // removed for bug 253823 "&& !m_bIsComputerOrDC);"
  80. GetDlgItem (IDC_UPN)->EnableWindow (bEnable);
  81. GetDlgItem (IDC_SPN)->EnableWindow (bEnable);
  82. BOOL bEnableEmailInSub = FALSE;
  83. if ( bEnable )
  84. {
  85. int nSel = m_nameCombo.GetCurSel ();
  86. if ( nSel >= 0 )
  87. {
  88. if ( NAME_TYPE_NONE != m_nameCombo.GetItemData (nSel) )
  89. bEnableEmailInSub = TRUE;
  90. }
  91. }
  92. GetDlgItem (IDC_EMAIL_IN_SUB)->EnableWindow (bEnableEmailInSub);
  93. if ( !bEnableEmailInSub )
  94. SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_SETCHECK, BST_UNCHECKED);
  95. }
  96. BOOL CTemplateV2SubjectNamePropertyPage::OnInitDialog()
  97. {
  98. CHelpPropertyPage::OnInitDialog ();
  99. // Initialize Combo Box
  100. CString text;
  101. VERIFY (text.LoadString (IDS_SUBJECT_NAME_NONE));
  102. int nIndex = m_nameCombo.AddString (text);
  103. if ( nIndex >= 0 )
  104. {
  105. m_nameCombo.SetCurSel (nIndex); // set by default
  106. m_nameCombo.SetItemData (nIndex, (DWORD_PTR) NAME_TYPE_NONE);
  107. }
  108. VERIFY (text.LoadString (IDS_FULL_DN));
  109. nIndex = m_nameCombo.AddString (text);
  110. if ( nIndex >= 0 )
  111. {
  112. m_nameCombo.SetItemData (nIndex, (DWORD_PTR) NAME_TYPE_FULL_DN);
  113. if ( m_rCertTemplate.SubjectNameMustBeFullDN () )
  114. m_nameCombo.SetCurSel (nIndex);
  115. }
  116. VERIFY (text.LoadString (IDS_CN_ONLY));
  117. nIndex = m_nameCombo.AddString (text);
  118. if ( nIndex >= 0 )
  119. {
  120. m_nameCombo.SetItemData (nIndex, (DWORD_PTR) NAME_TYPE_CN_ONLY);
  121. if ( m_rCertTemplate.SubjectNameMustBeCN () )
  122. m_nameCombo.SetCurSel (nIndex);
  123. }
  124. // Initialize Radio buttons
  125. if ( m_rCertTemplate.RequireSubjectInRequest () )
  126. SendDlgItemMessage (IDC_SUBJECT_NAME_SUPPLIED_IN_REQUEST, BM_SETCHECK, BST_CHECKED);
  127. else
  128. SendDlgItemMessage (IDC_SUBJECT_NAME_BUILT_BY_CA, BM_SETCHECK, BST_CHECKED);
  129. // Initialize Check boxes
  130. if ( m_rCertTemplate.SubjectNameIncludesEMail () )
  131. SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_SETCHECK, BST_CHECKED);
  132. if ( m_rCertTemplate.AltNameIncludesDNS () )
  133. SendDlgItemMessage (IDC_DNS_NAME, BM_SETCHECK, BST_CHECKED);
  134. if ( m_rCertTemplate.AltNameIncludesEMail () )
  135. SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_SETCHECK, BST_CHECKED);
  136. if ( m_rCertTemplate.AltNameIncludesUPN () )
  137. SendDlgItemMessage (IDC_UPN, BM_SETCHECK, BST_CHECKED);
  138. if ( m_rCertTemplate.AltNameIncludesSPN () )
  139. SendDlgItemMessage (IDC_SPN, BM_SETCHECK, BST_CHECKED);
  140. EnableControls ();
  141. return TRUE;
  142. }
  143. void CTemplateV2SubjectNamePropertyPage::SetSettingsForNameTypeNone ()
  144. {
  145. m_rCertTemplate.SubjectNameMustBeCN (false);
  146. m_rCertTemplate.SubjectNameMustBeFullDN (false);
  147. int nCntChecked = 0;
  148. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK) )
  149. nCntChecked++;
  150. if ( BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK) )
  151. nCntChecked++;
  152. if ( BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK) )
  153. nCntChecked++;
  154. if ( BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK) )
  155. nCntChecked++;
  156. if ( 0 == nCntChecked )
  157. {
  158. m_rCertTemplate.AltNameIncludesUPN (true);
  159. SendDlgItemMessage (IDC_UPN, BM_SETCHECK, BST_CHECKED);
  160. }
  161. // NTRAID# 313588 CertTMPL: If subject name format = none,
  162. // sub alt name should be marked as critical for D.C.A. cert
  163. // template.
  164. m_rCertTemplate.ModifyCriticalExtensions (szOID_SUBJECT_ALT_NAME, true);
  165. }
  166. void CTemplateV2SubjectNamePropertyPage::OnSelchangeSubjectNameNameCombo()
  167. {
  168. SetModified ();
  169. m_rbIsDirty = true;
  170. int nSel = m_nameCombo.GetCurSel ();
  171. if ( nSel >= 0 )
  172. {
  173. switch (m_nameCombo.GetItemData (nSel) )
  174. {
  175. case NAME_TYPE_NONE:
  176. SetSettingsForNameTypeNone ();
  177. break;
  178. case NAME_TYPE_FULL_DN:
  179. m_rCertTemplate.SubjectNameMustBeCN (false);
  180. m_rCertTemplate.SubjectNameMustBeFullDN (true);
  181. // NTRAID# 313588 CertTMPL: If subject name format = none,
  182. // sub alt name should be marked as critical for D.C.A. cert
  183. // template.
  184. m_rCertTemplate.ModifyCriticalExtensions (szOID_SUBJECT_ALT_NAME,
  185. false);
  186. break;
  187. case NAME_TYPE_CN_ONLY:
  188. m_rCertTemplate.SubjectNameMustBeCN (true);
  189. m_rCertTemplate.SubjectNameMustBeFullDN (false);
  190. // NTRAID# 313588 CertTMPL: If subject name format = none,
  191. // sub alt name should be marked as critical for D.C.A. cert
  192. // template.
  193. m_rCertTemplate.ModifyCriticalExtensions (szOID_SUBJECT_ALT_NAME,
  194. false);
  195. break;
  196. default:
  197. ASSERT (0);
  198. break;
  199. }
  200. }
  201. EnableControls ();
  202. }
  203. void CTemplateV2SubjectNamePropertyPage::OnSubjectNameBuiltByCa()
  204. {
  205. SetModified ();
  206. SendDlgItemMessage (IDC_SUBJECT_NAME_SUPPLIED_IN_REQUEST, BM_SETCHECK, BST_UNCHECKED);
  207. m_rbIsDirty = true;
  208. m_rCertTemplate.RequireSubjectInRequest (false);
  209. EnableControls ();
  210. }
  211. void CTemplateV2SubjectNamePropertyPage::OnSubjectNameSuppliedInRequest()
  212. {
  213. SetModified ();
  214. SendDlgItemMessage (IDC_SUBJECT_NAME_BUILT_BY_CA, BM_SETCHECK, BST_UNCHECKED);
  215. m_rbIsDirty = true;
  216. m_rCertTemplate.RequireSubjectInRequest (true);
  217. // Clear all "built by CA" settings
  218. int nCnt = m_nameCombo.GetCount ();
  219. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  220. {
  221. if ( NAME_TYPE_NONE == m_nameCombo.GetItemData (nIndex) )
  222. {
  223. m_nameCombo.SetCurSel (nIndex);
  224. break;
  225. }
  226. }
  227. SetSettingsForNameTypeNone ();
  228. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_GETCHECK) )
  229. {
  230. SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_SETCHECK, BST_UNCHECKED);
  231. m_rCertTemplate.SubjectNameIncludesEMail (false);
  232. }
  233. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK) &&
  234. CanUncheckLastSetting (IDC_EMAIL_IN_ALT) )
  235. {
  236. SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_SETCHECK, BST_UNCHECKED);
  237. m_rCertTemplate.AltNameIncludesEMail (false);
  238. }
  239. if ( BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK) &&
  240. CanUncheckLastSetting (IDC_DNS_NAME) )
  241. {
  242. m_rCertTemplate.AltNameIncludesDNS (false);
  243. SendDlgItemMessage (IDC_DNS_NAME, BM_SETCHECK, BST_UNCHECKED);
  244. }
  245. if ( BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK) &&
  246. CanUncheckLastSetting (IDC_UPN) )
  247. {
  248. m_rCertTemplate.AltNameIncludesUPN (false);
  249. SendDlgItemMessage (IDC_UPN, BM_SETCHECK, BST_UNCHECKED);
  250. }
  251. if ( BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK) &&
  252. CanUncheckLastSetting (IDC_SPN) )
  253. {
  254. m_rCertTemplate.AltNameIncludesSPN (false);
  255. SendDlgItemMessage (IDC_SPN, BM_SETCHECK, BST_UNCHECKED);
  256. }
  257. EnableControls ();
  258. }
  259. void CTemplateV2SubjectNamePropertyPage::OnDnsName()
  260. {
  261. if ( CanUncheckLastSetting (IDC_DNS_NAME) )
  262. {
  263. m_rCertTemplate.AltNameIncludesDNS (
  264. BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK));
  265. }
  266. SetModified ();
  267. m_rbIsDirty = true;
  268. }
  269. void CTemplateV2SubjectNamePropertyPage::OnEmailInAlt()
  270. {
  271. if ( CanUncheckLastSetting (IDC_EMAIL_IN_ALT) )
  272. {
  273. m_rCertTemplate.AltNameIncludesEMail (
  274. BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK));
  275. }
  276. SetModified ();
  277. m_rbIsDirty = true;
  278. }
  279. void CTemplateV2SubjectNamePropertyPage::OnEmailInSub()
  280. {
  281. m_rCertTemplate.SubjectNameIncludesEMail (
  282. BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_GETCHECK));
  283. SetModified ();
  284. m_rbIsDirty = true;
  285. }
  286. void CTemplateV2SubjectNamePropertyPage::OnSpn()
  287. {
  288. if ( CanUncheckLastSetting (IDC_SPN) )
  289. {
  290. m_rCertTemplate.AltNameIncludesSPN (
  291. BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK));
  292. }
  293. SetModified ();
  294. m_rbIsDirty = true;
  295. }
  296. void CTemplateV2SubjectNamePropertyPage::OnUpn()
  297. {
  298. if ( CanUncheckLastSetting (IDC_UPN) )
  299. {
  300. m_rCertTemplate.AltNameIncludesUPN (
  301. BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK));
  302. }
  303. SetModified ();
  304. m_rbIsDirty = true;
  305. }
  306. bool CTemplateV2SubjectNamePropertyPage::CanUncheckLastSetting(int ctrlID)
  307. {
  308. bool bResult = true;
  309. // If request is to be built by CA and "none" is selected for subject name,
  310. // ensure that at least one of the alt-name options is checked
  311. // If the control in question is now unchecked, verify that at least
  312. // one other is checked
  313. if ( BST_UNCHECKED == SendDlgItemMessage (ctrlID, BM_GETCHECK) )
  314. {
  315. if ( BST_CHECKED == SendDlgItemMessage (IDC_SUBJECT_NAME_BUILT_BY_CA, BM_GETCHECK) )
  316. {
  317. int nSel = m_nameCombo.GetCurSel ();
  318. if ( nSel >= 0 )
  319. {
  320. if ( NAME_TYPE_NONE == m_nameCombo.GetItemData (nSel) )
  321. {
  322. int nCntChecked = 0;
  323. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK) )
  324. nCntChecked++;
  325. if ( BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK) )
  326. nCntChecked++;
  327. if ( BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK) )
  328. nCntChecked++;
  329. if ( BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK) )
  330. nCntChecked++;
  331. if ( 0 == nCntChecked )
  332. {
  333. CString text;
  334. CString caption;
  335. CThemeContextActivator activator;
  336. VERIFY (caption.LoadString (IDS_CERTTMPL));
  337. VERIFY (text.LoadString (IDS_AT_LEAST_1_NAME_OPTION_MUST_BE_CHECKED));
  338. MessageBox (text, caption, MB_OK);
  339. bResult = false;
  340. SendDlgItemMessage (ctrlID, BM_SETCHECK, BST_CHECKED);
  341. }
  342. }
  343. }
  344. }
  345. }
  346. return bResult;
  347. }
  348. void CTemplateV2SubjectNamePropertyPage::DoContextHelp (HWND hWndControl)
  349. {
  350. _TRACE(1, L"Entering CTemplateV2SubjectNamePropertyPage::DoContextHelp\n");
  351. switch (::GetDlgCtrlID (hWndControl))
  352. {
  353. case IDC_STATIC:
  354. break;
  355. default:
  356. // Display context help for a control
  357. if ( !::WinHelp (
  358. hWndControl,
  359. GetContextHelpFile (),
  360. HELP_WM_HELP,
  361. (DWORD_PTR) g_aHelpIDs_IDD_TEMPLATE_V2_SUBJECT_NAME) )
  362. {
  363. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  364. }
  365. break;
  366. }
  367. _TRACE(-1, L"Leaving CTemplateV2SubjectNamePropertyPage::DoContextHelp\n");
  368. }