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.

436 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. m_rCertTemplate.SubjectNameIncludesEMail(false); //NTRAID# 435818, YangGao, 7/25/2001
  178. break;
  179. case NAME_TYPE_FULL_DN:
  180. m_rCertTemplate.SubjectNameMustBeCN (false);
  181. m_rCertTemplate.SubjectNameMustBeFullDN (true);
  182. // NTRAID# 313588 CertTMPL: If subject name format = none,
  183. // sub alt name should be marked as critical for D.C.A. cert
  184. // template.
  185. m_rCertTemplate.ModifyCriticalExtensions (szOID_SUBJECT_ALT_NAME,
  186. false);
  187. break;
  188. case NAME_TYPE_CN_ONLY:
  189. m_rCertTemplate.SubjectNameMustBeCN (true);
  190. m_rCertTemplate.SubjectNameMustBeFullDN (false);
  191. // NTRAID# 313588 CertTMPL: If subject name format = none,
  192. // sub alt name should be marked as critical for D.C.A. cert
  193. // template.
  194. m_rCertTemplate.ModifyCriticalExtensions (szOID_SUBJECT_ALT_NAME,
  195. false);
  196. break;
  197. default:
  198. ASSERT (0);
  199. break;
  200. }
  201. }
  202. EnableControls ();
  203. }
  204. void CTemplateV2SubjectNamePropertyPage::OnSubjectNameBuiltByCa()
  205. {
  206. SetModified ();
  207. SendDlgItemMessage (IDC_SUBJECT_NAME_SUPPLIED_IN_REQUEST, BM_SETCHECK, BST_UNCHECKED);
  208. m_rbIsDirty = true;
  209. m_rCertTemplate.RequireSubjectInRequest (false);
  210. EnableControls ();
  211. }
  212. void CTemplateV2SubjectNamePropertyPage::OnSubjectNameSuppliedInRequest()
  213. {
  214. SetModified ();
  215. SendDlgItemMessage (IDC_SUBJECT_NAME_BUILT_BY_CA, BM_SETCHECK, BST_UNCHECKED);
  216. m_rbIsDirty = true;
  217. m_rCertTemplate.RequireSubjectInRequest (true);
  218. // Clear all "built by CA" settings
  219. int nCnt = m_nameCombo.GetCount ();
  220. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  221. {
  222. if ( NAME_TYPE_NONE == m_nameCombo.GetItemData (nIndex) )
  223. {
  224. m_nameCombo.SetCurSel (nIndex);
  225. break;
  226. }
  227. }
  228. SetSettingsForNameTypeNone ();
  229. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_GETCHECK) )
  230. {
  231. SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_SETCHECK, BST_UNCHECKED);
  232. m_rCertTemplate.SubjectNameIncludesEMail (false);
  233. }
  234. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK) &&
  235. CanUncheckLastSetting (IDC_EMAIL_IN_ALT) )
  236. {
  237. SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_SETCHECK, BST_UNCHECKED);
  238. m_rCertTemplate.AltNameIncludesEMail (false);
  239. }
  240. if ( BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK) &&
  241. CanUncheckLastSetting (IDC_DNS_NAME) )
  242. {
  243. m_rCertTemplate.AltNameIncludesDNS (false);
  244. SendDlgItemMessage (IDC_DNS_NAME, BM_SETCHECK, BST_UNCHECKED);
  245. }
  246. if ( BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK) &&
  247. CanUncheckLastSetting (IDC_UPN) )
  248. {
  249. m_rCertTemplate.AltNameIncludesUPN (false);
  250. SendDlgItemMessage (IDC_UPN, BM_SETCHECK, BST_UNCHECKED);
  251. }
  252. if ( BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK) &&
  253. CanUncheckLastSetting (IDC_SPN) )
  254. {
  255. m_rCertTemplate.AltNameIncludesSPN (false);
  256. SendDlgItemMessage (IDC_SPN, BM_SETCHECK, BST_UNCHECKED);
  257. }
  258. EnableControls ();
  259. }
  260. void CTemplateV2SubjectNamePropertyPage::OnDnsName()
  261. {
  262. if ( CanUncheckLastSetting (IDC_DNS_NAME) )
  263. {
  264. m_rCertTemplate.AltNameIncludesDNS (
  265. BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK));
  266. }
  267. SetModified ();
  268. m_rbIsDirty = true;
  269. }
  270. void CTemplateV2SubjectNamePropertyPage::OnEmailInAlt()
  271. {
  272. if ( CanUncheckLastSetting (IDC_EMAIL_IN_ALT) )
  273. {
  274. m_rCertTemplate.AltNameIncludesEMail (
  275. BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK));
  276. }
  277. SetModified ();
  278. m_rbIsDirty = true;
  279. }
  280. void CTemplateV2SubjectNamePropertyPage::OnEmailInSub()
  281. {
  282. m_rCertTemplate.SubjectNameIncludesEMail (
  283. BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_SUB, BM_GETCHECK));
  284. SetModified ();
  285. m_rbIsDirty = true;
  286. }
  287. void CTemplateV2SubjectNamePropertyPage::OnSpn()
  288. {
  289. if ( CanUncheckLastSetting (IDC_SPN) )
  290. {
  291. m_rCertTemplate.AltNameIncludesSPN (
  292. BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK));
  293. }
  294. SetModified ();
  295. m_rbIsDirty = true;
  296. }
  297. void CTemplateV2SubjectNamePropertyPage::OnUpn()
  298. {
  299. if ( CanUncheckLastSetting (IDC_UPN) )
  300. {
  301. m_rCertTemplate.AltNameIncludesUPN (
  302. BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK));
  303. }
  304. SetModified ();
  305. m_rbIsDirty = true;
  306. }
  307. bool CTemplateV2SubjectNamePropertyPage::CanUncheckLastSetting(int ctrlID)
  308. {
  309. bool bResult = true;
  310. // If request is to be built by CA and "none" is selected for subject name,
  311. // ensure that at least one of the alt-name options is checked
  312. // If the control in question is now unchecked, verify that at least
  313. // one other is checked
  314. if ( BST_UNCHECKED == SendDlgItemMessage (ctrlID, BM_GETCHECK) )
  315. {
  316. if ( BST_CHECKED == SendDlgItemMessage (IDC_SUBJECT_NAME_BUILT_BY_CA, BM_GETCHECK) )
  317. {
  318. int nSel = m_nameCombo.GetCurSel ();
  319. if ( nSel >= 0 )
  320. {
  321. if ( NAME_TYPE_NONE == m_nameCombo.GetItemData (nSel) )
  322. {
  323. int nCntChecked = 0;
  324. if ( BST_CHECKED == SendDlgItemMessage (IDC_EMAIL_IN_ALT, BM_GETCHECK) )
  325. nCntChecked++;
  326. if ( BST_CHECKED == SendDlgItemMessage (IDC_DNS_NAME, BM_GETCHECK) )
  327. nCntChecked++;
  328. if ( BST_CHECKED == SendDlgItemMessage (IDC_UPN, BM_GETCHECK) )
  329. nCntChecked++;
  330. if ( BST_CHECKED == SendDlgItemMessage (IDC_SPN, BM_GETCHECK) )
  331. nCntChecked++;
  332. if ( 0 == nCntChecked )
  333. {
  334. CString text;
  335. CString caption;
  336. CThemeContextActivator activator;
  337. VERIFY (caption.LoadString (IDS_CERTTMPL));
  338. VERIFY (text.LoadString (IDS_AT_LEAST_1_NAME_OPTION_MUST_BE_CHECKED));
  339. MessageBox (text, caption, MB_OK);
  340. bResult = false;
  341. SendDlgItemMessage (ctrlID, BM_SETCHECK, BST_CHECKED);
  342. }
  343. }
  344. }
  345. }
  346. }
  347. return bResult;
  348. }
  349. void CTemplateV2SubjectNamePropertyPage::DoContextHelp (HWND hWndControl)
  350. {
  351. _TRACE(1, L"Entering CTemplateV2SubjectNamePropertyPage::DoContextHelp\n");
  352. switch (::GetDlgCtrlID (hWndControl))
  353. {
  354. case IDC_STATIC:
  355. break;
  356. default:
  357. // Display context help for a control
  358. if ( !::WinHelp (
  359. hWndControl,
  360. GetContextHelpFile (),
  361. HELP_WM_HELP,
  362. (DWORD_PTR) g_aHelpIDs_IDD_TEMPLATE_V2_SUBJECT_NAME) )
  363. {
  364. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  365. }
  366. break;
  367. }
  368. _TRACE(-1, L"Leaving CTemplateV2SubjectNamePropertyPage::DoContextHelp\n");
  369. }