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.

897 lines
33 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2002.
  5. //
  6. // File: TemplateV2AuthenticationPropertyPage.cpp
  7. //
  8. // Contents: Implementation of CTemplateV2AuthenticationPropertyPage
  9. //
  10. //----------------------------------------------------------------------------
  11. // TemplateV2AuthenticationPropertyPage.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "certtmpl.h"
  15. #include "TemplateV2AuthenticationPropertyPage.h"
  16. #include "AddApprovalDlg.h"
  17. #include "PolicyOID.h"
  18. extern POLICY_OID_LIST g_policyOIDList;
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CTemplateV2AuthenticationPropertyPage property page
  26. CTemplateV2AuthenticationPropertyPage::CTemplateV2AuthenticationPropertyPage(
  27. CCertTemplate& rCertTemplate,
  28. bool& rbIsDirty)
  29. : CHelpPropertyPage(CTemplateV2AuthenticationPropertyPage::IDD),
  30. m_rCertTemplate (rCertTemplate),
  31. m_curApplicationSel (LB_ERR),
  32. m_rbIsDirty (rbIsDirty)
  33. {
  34. //{{AFX_DATA_INIT(CTemplateV2AuthenticationPropertyPage)
  35. //}}AFX_DATA_INIT
  36. m_rCertTemplate.AddRef ();
  37. }
  38. CTemplateV2AuthenticationPropertyPage::~CTemplateV2AuthenticationPropertyPage()
  39. {
  40. m_rCertTemplate.Release ();
  41. }
  42. void CTemplateV2AuthenticationPropertyPage::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CHelpPropertyPage::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CTemplateV2AuthenticationPropertyPage)
  46. DDX_Control(pDX, IDC_APPLICATION_POLICIES, m_applicationPolicyCombo);
  47. DDX_Control(pDX, IDC_POLICY_TYPES, m_policyTypeCombo);
  48. DDX_Control(pDX, IDC_ISSUANCE_POLICIES, m_issuanceList);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CTemplateV2AuthenticationPropertyPage, CHelpPropertyPage)
  52. //{{AFX_MSG_MAP(CTemplateV2AuthenticationPropertyPage)
  53. ON_BN_CLICKED(IDC_ADD_APPROVAL, OnAddApproval)
  54. ON_BN_CLICKED(IDC_REMOVE_APPROVAL, OnRemoveApproval)
  55. ON_EN_CHANGE(IDC_NUM_SIG_REQUIRED_EDIT, OnChangeNumSigRequiredEdit)
  56. ON_BN_CLICKED(IDC_REENROLLMENT_REQUIRES_VALID_CERT, OnAllowReenrollment)
  57. ON_BN_CLICKED(IDC_PEND_ALL_REQUESTS, OnPendAllRequests)
  58. ON_LBN_SELCHANGE(IDC_ISSUANCE_POLICIES, OnSelchangeIssuancePolicies)
  59. ON_CBN_SELCHANGE(IDC_POLICY_TYPES, OnSelchangePolicyTypes)
  60. ON_CBN_SELCHANGE(IDC_APPLICATION_POLICIES, OnSelchangeApplicationPolicies)
  61. ON_WM_DESTROY()
  62. ON_BN_CLICKED(IDC_NUM_SIG_REQUIRED_CHECK, OnNumSigRequiredCheck)
  63. ON_BN_CLICKED(IDC_REENROLLMENT_SAME_AS_ENROLLMENT, OnReenrollmentSameAsEnrollment)
  64. //}}AFX_MSG_MAP
  65. END_MESSAGE_MAP()
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CTemplateV2AuthenticationPropertyPage message handlers
  68. enum {
  69. POLICY_TYPE_ISSUANCE = 0,
  70. POLICY_TYPE_APPLICATION,
  71. POLICY_TYPE_APPLICATION_AND_ISSUANCE
  72. };
  73. BOOL CTemplateV2AuthenticationPropertyPage::OnInitDialog()
  74. {
  75. _TRACE (1, L"Entering CTemplateV2AuthenticationPropertyPage::OnInitDialog\n");
  76. CHelpPropertyPage::OnInitDialog ();
  77. // Initialize Application Policy combo
  78. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  79. {
  80. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  81. if ( pPolicyOID )
  82. {
  83. // If this is the Application OID dialog, show only application
  84. // OIDS, otherwise if this is the Issuance OID dialog, show only
  85. // issuance OIDs
  86. if ( pPolicyOID->IsApplicationOID () )
  87. {
  88. // Bug 262925 CERTSRV: "All Application Policies should be
  89. // removed from Issuance Requirements tab for a cert template
  90. if ( 0 != strcmp (szOID_ANY_APPLICATION_POLICY, pPolicyOID->GetOIDA ()) )
  91. {
  92. int nIndex = m_applicationPolicyCombo.AddString (pPolicyOID->GetDisplayName ());
  93. if ( nIndex >= 0 )
  94. {
  95. // security review 2/20/2002 BryanWal ok GetOIDA () returns L"" if empty
  96. LPSTR pszOID = new char[strlen (pPolicyOID->GetOIDA ())+1];
  97. if ( pszOID )
  98. {
  99. // security review 2/20/2002 BryanWal ok
  100. strcpy (pszOID, pPolicyOID->GetOIDA ());
  101. m_applicationPolicyCombo.SetItemDataPtr (nIndex, pszOID);
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. // Check for and add pending requests
  109. if ( m_rCertTemplate.PendAllRequests () )
  110. SendDlgItemMessage (IDC_PEND_ALL_REQUESTS, BM_SETCHECK, BST_CHECKED);
  111. // Get the RA Issuance Policies and add them to the issuance list
  112. int nRAPolicyIndex = 0;
  113. CString szRAPolicyOID;
  114. while ( SUCCEEDED (m_rCertTemplate.GetRAIssuancePolicy (nRAPolicyIndex, szRAPolicyOID)) )
  115. {
  116. CString policyName;
  117. // ISSUE
  118. // RAID 547613 Security: cert templates - CPolicyDlg::OnInitDialog() - methodize all unicode to mbcs conversion
  119. // security review 2/20/2002 BryanWal ok
  120. int nLen = WideCharToMultiByte(
  121. CP_ACP, // code page
  122. 0, // performance and mapping flags
  123. (PCWSTR) szRAPolicyOID, // wide-character string
  124. -1, // number of chars in string
  125. 0, // buffer for new string
  126. 0, // size of buffer - if 0 causes to return required len including NULL terminator
  127. 0, // default for unmappable chars
  128. 0); // set when default char used
  129. if ( nLen > 0 )
  130. {
  131. PSTR pszAnsiBuf = new char[nLen];
  132. if ( pszAnsiBuf )
  133. {
  134. // security review 2/20/2002 BryanWal ok
  135. ZeroMemory (pszAnsiBuf, nLen);
  136. // security review 2/20/2002 BryanWal ok
  137. nLen = WideCharToMultiByte(
  138. CP_ACP, // code page
  139. 0, // performance and mapping flags
  140. (PCWSTR) szRAPolicyOID, // wide-character string
  141. -1, // -1 - calculate length of null-terminated string automatically
  142. pszAnsiBuf, // buffer for new string
  143. nLen, // size of buffer
  144. 0, // default for unmappable chars
  145. 0); // set when default char used
  146. if ( nLen )
  147. {
  148. if ( MyGetOIDInfoA (policyName, pszAnsiBuf) )
  149. {
  150. int nIndex = m_issuanceList.AddString (policyName);
  151. if ( nIndex >= 0 )
  152. m_issuanceList.SetItemData (nIndex, (DWORD_PTR) pszAnsiBuf);
  153. }
  154. }
  155. else
  156. {
  157. _TRACE (0, L"WideCharToMultiByte (%s) failed: 0x%x\n",
  158. (PCWSTR) szRAPolicyOID, GetLastError ());
  159. }
  160. }
  161. else
  162. break;
  163. }
  164. else
  165. {
  166. _TRACE (0, L"WideCharToMultiByte (%s) failed: 0x%x\n",
  167. (PCWSTR) szRAPolicyOID, GetLastError ());
  168. }
  169. nRAPolicyIndex++;
  170. }
  171. // Get the RA Application policy and select it
  172. // in the application combo
  173. nRAPolicyIndex = 0;
  174. while ( SUCCEEDED (m_rCertTemplate.GetRAApplicationPolicy (nRAPolicyIndex, szRAPolicyOID)) )
  175. {
  176. CString policyName;
  177. int nLen = WideCharToMultiByte(
  178. CP_ACP, // code page
  179. 0, // performance and mapping flags
  180. (PCWSTR) szRAPolicyOID, // wide-character string
  181. -1, // -1 - calculate length of null-terminated string automatically
  182. 0, // buffer for new string
  183. 0, // size of buffer - if 0 then API returns length including null terminator
  184. 0, // default for unmappable chars
  185. 0); // set when default char used
  186. if ( nLen > 0 )
  187. {
  188. PSTR pszAnsiBuf = new char[nLen];
  189. if ( pszAnsiBuf )
  190. {
  191. // security review 2/20/2002 BryanWal ok
  192. ZeroMemory (pszAnsiBuf, nLen);
  193. nLen = WideCharToMultiByte(
  194. CP_ACP, // code page
  195. 0, // performance and mapping flags
  196. (PCWSTR) szRAPolicyOID, // wide-character string
  197. -1, // -1 - calculate length of null-terminated string automatically
  198. pszAnsiBuf, // buffer for new string
  199. nLen, // size of buffer
  200. 0, // default for unmappable chars
  201. 0); // set when default char used
  202. if ( nLen )
  203. {
  204. if ( MyGetOIDInfoA (policyName, pszAnsiBuf) )
  205. {
  206. int nIndex = m_applicationPolicyCombo.FindStringExact (-1, policyName);
  207. if ( nIndex >= 0 )
  208. m_applicationPolicyCombo.SetCurSel (nIndex);
  209. m_curApplicationSel = nIndex;
  210. break;
  211. }
  212. }
  213. else
  214. {
  215. _TRACE (0, L"WideCharToMultiByte (%s) failed: 0x%x\n",
  216. (PCWSTR) szRAPolicyOID, GetLastError ());
  217. }
  218. delete [] pszAnsiBuf;
  219. }
  220. else
  221. break;
  222. }
  223. else
  224. {
  225. _TRACE (0, L"WideCharToMultiByte (%s) failed: 0x%x\n",
  226. (PCWSTR) szRAPolicyOID, GetLastError ());
  227. }
  228. nRAPolicyIndex++;
  229. }
  230. // Initialize "Policy Type" combo box
  231. CString text;
  232. int nApplicationSel = m_applicationPolicyCombo.GetCurSel ();
  233. int nIssuanceCnt = m_issuanceList.GetCount ();
  234. VERIFY (text.LoadString (IDS_ISSUANCE_POLICY));
  235. int nIndex = m_policyTypeCombo.AddString (text);
  236. if ( nIndex >= 0 )
  237. {
  238. m_policyTypeCombo.SetItemData (nIndex, POLICY_TYPE_ISSUANCE);
  239. if ( LB_ERR == nApplicationSel && nIssuanceCnt > 0 )
  240. m_policyTypeCombo.SetCurSel (nIndex);
  241. }
  242. VERIFY (text.LoadString (IDS_APPLICATION_POLICY));
  243. nIndex = m_policyTypeCombo.AddString (text);
  244. if ( nIndex >= 0 )
  245. {
  246. m_policyTypeCombo.SetItemData (nIndex, POLICY_TYPE_APPLICATION);
  247. if ( nApplicationSel >= 0 && 0 == nIssuanceCnt )
  248. m_policyTypeCombo.SetCurSel (nIndex);
  249. }
  250. VERIFY (text.LoadString (IDS_APPLICATION_AND_ISSUANCE_POLICY));
  251. nIndex = m_policyTypeCombo.AddString (text);
  252. if ( nIndex >= 0 )
  253. {
  254. m_policyTypeCombo.SetItemData (nIndex, POLICY_TYPE_APPLICATION_AND_ISSUANCE);
  255. if ( nApplicationSel >= 0 && nIssuanceCnt > 0 )
  256. m_policyTypeCombo.SetCurSel (nIndex);
  257. }
  258. DWORD dwNumSignatures = 0;
  259. if ( SUCCEEDED (m_rCertTemplate.GetRANumSignaturesRequired (dwNumSignatures)) )
  260. SetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT, dwNumSignatures);
  261. if ( dwNumSignatures > 0 )
  262. SendDlgItemMessage (IDC_NUM_SIG_REQUIRED_CHECK, BM_SETCHECK, BST_CHECKED);
  263. if ( m_rCertTemplate.ReenrollmentValidWithPreviousApproval () )
  264. SendDlgItemMessage (IDC_REENROLLMENT_REQUIRES_VALID_CERT, BM_SETCHECK, BST_CHECKED);
  265. else
  266. SendDlgItemMessage (IDC_REENROLLMENT_SAME_AS_ENROLLMENT, BM_SETCHECK, BST_CHECKED);
  267. EnableControls ();
  268. _TRACE (-1, L"Leaving CTemplateV2AuthenticationPropertyPage::OnInitDialog\n");
  269. return TRUE;
  270. }
  271. void CTemplateV2AuthenticationPropertyPage::OnAddApproval()
  272. {
  273. // Create the list of already added approvals. These will not be displayed
  274. // in the Add Approval dialog.
  275. int nCnt = m_issuanceList.GetCount ();
  276. PSTR* paszUsedApprovals = 0;
  277. // allocate an array of PSTR pointers and add each item.
  278. // Set the last to NULL
  279. if ( nCnt )
  280. {
  281. paszUsedApprovals = new PSTR[nCnt+1];
  282. if ( paszUsedApprovals )
  283. {
  284. // security review 2/20/2002 BryanWal ok
  285. ::ZeroMemory (paszUsedApprovals, sizeof (PSTR) * (nCnt+1));
  286. while (--nCnt >= 0)
  287. {
  288. PSTR pszPolicyOID = (PSTR) m_issuanceList.GetItemData (nCnt);
  289. if ( pszPolicyOID )
  290. {
  291. // security review 2/20/2002 BryanWal ok
  292. PSTR pNewStr = new char[strlen (pszPolicyOID) + 1];
  293. if ( pNewStr )
  294. {
  295. // security review 2/20/2002 BryanWal ok
  296. strcpy (pNewStr, pszPolicyOID);
  297. paszUsedApprovals[nCnt] = pNewStr;
  298. }
  299. else
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. CAddApprovalDlg dlg (this, paszUsedApprovals);
  306. CThemeContextActivator activator;
  307. if ( IDOK == dlg.DoModal () && dlg.m_paszReturnedApprovals )
  308. {
  309. for (int nIndex = 0; dlg.m_paszReturnedApprovals[nIndex]; nIndex++)
  310. {
  311. SetModified ();
  312. m_rbIsDirty = true;
  313. // Add to template RA list
  314. CString szRAPolicyOID (dlg.m_paszReturnedApprovals[nIndex]);
  315. HRESULT hr = m_rCertTemplate.ModifyRAIssuancePolicyList (szRAPolicyOID, true);
  316. ASSERT (SUCCEEDED (hr));
  317. if ( SUCCEEDED (hr) )
  318. {
  319. // Add to list
  320. CString policyName;
  321. if ( MyGetOIDInfoA (policyName, dlg.m_paszReturnedApprovals[nIndex]) )
  322. {
  323. int nAddedIndex = m_issuanceList.AddString (policyName);
  324. if ( nAddedIndex >= 0 )
  325. {
  326. // security review 2/20/2002 BryanWal ok
  327. PSTR pszAnsiBuf = new char[strlen (dlg.m_paszReturnedApprovals[nIndex]) + 1];
  328. if ( pszAnsiBuf )
  329. {
  330. // security review 2/20/2002 BryanWal ok
  331. strcpy (pszAnsiBuf, dlg.m_paszReturnedApprovals[nIndex]);
  332. m_issuanceList.SetItemData (nAddedIndex, (DWORD_PTR) pszAnsiBuf);
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }
  339. if ( paszUsedApprovals )
  340. {
  341. for (int nIndex = 0; paszUsedApprovals[nIndex]; nIndex++)
  342. delete [] paszUsedApprovals[nIndex];
  343. delete [] paszUsedApprovals;
  344. }
  345. EnableControls ();
  346. }
  347. void CTemplateV2AuthenticationPropertyPage::OnRemoveApproval()
  348. {
  349. int nSelCnt = m_issuanceList.GetSelCount ();
  350. int* pnSelIndexes = new int[nSelCnt];
  351. if ( pnSelIndexes )
  352. {
  353. m_issuanceList.GetSelItems (nSelCnt, pnSelIndexes);
  354. for (int nIndex = nSelCnt-1; nIndex >= 0; nIndex--)
  355. {
  356. PSTR pszPolicyOID = (PSTR) m_issuanceList.GetItemData (pnSelIndexes[nIndex]);
  357. if ( pszPolicyOID )
  358. {
  359. HRESULT hr = m_rCertTemplate.ModifyRAIssuancePolicyList (pszPolicyOID, false);
  360. if ( SUCCEEDED (hr) )
  361. VERIFY (m_issuanceList.DeleteString (pnSelIndexes[nIndex]));
  362. else
  363. {
  364. CString text;
  365. CString caption;
  366. CThemeContextActivator activator;
  367. VERIFY (caption.LoadString (IDS_CERTTMPL));
  368. // security review 2/20/2002 BryanWal ok
  369. text.FormatMessage (IDS_CANNOT_DELETE_ISSUANCE_RA, GetSystemMessage (hr));
  370. MessageBox (text, caption, MB_OK | MB_ICONWARNING);
  371. delete [] pszPolicyOID;
  372. }
  373. }
  374. }
  375. delete [] pnSelIndexes;
  376. }
  377. SetModified ();
  378. m_rbIsDirty = true;
  379. GetDlgItem (IDC_ADD_APPROVAL)->SetFocus ();
  380. EnableControls ();
  381. }
  382. void CTemplateV2AuthenticationPropertyPage::EnableControls()
  383. {
  384. if ( m_rCertTemplate.ReadOnly () )
  385. {
  386. GetDlgItem (IDC_PEND_ALL_REQUESTS)->EnableWindow (FALSE);
  387. m_policyTypeCombo.EnableWindow (FALSE);
  388. m_issuanceList.EnableWindow (FALSE);
  389. m_applicationPolicyCombo.EnableWindow (FALSE);
  390. GetDlgItem (IDC_ADD_APPROVAL)->EnableWindow (FALSE);
  391. GetDlgItem (IDC_REMOVE_APPROVAL)->EnableWindow (FALSE);
  392. GetDlgItem (IDC_NUM_SIG_REQUIRED_EDIT)->EnableWindow (FALSE);
  393. GetDlgItem (IDC_REENROLLMENT_REQUIRES_VALID_CERT)->EnableWindow (FALSE);
  394. GetDlgItem (IDC_REENROLLMENT_SAME_AS_ENROLLMENT)->EnableWindow (FALSE);
  395. GetDlgItem (IDC_NUM_SIG_REQUIRED_CHECK)->EnableWindow (FALSE);
  396. }
  397. else
  398. {
  399. BOOL bEnable = (BST_CHECKED == SendDlgItemMessage (IDC_NUM_SIG_REQUIRED_CHECK, BM_GETCHECK));
  400. EnablePolicyControls (bEnable);
  401. if ( bEnable )
  402. {
  403. int nCnt = m_issuanceList.GetCount ();
  404. int nSel = m_issuanceList.GetSelCount ();
  405. switch (m_policyTypeCombo.GetItemData (m_policyTypeCombo.GetCurSel ()))
  406. {
  407. case POLICY_TYPE_ISSUANCE:
  408. m_issuanceList.EnableWindow (TRUE);
  409. GetDlgItem (IDC_ADD_APPROVAL)->EnableWindow (TRUE);
  410. GetDlgItem (IDC_REMOVE_APPROVAL)->EnableWindow (TRUE);
  411. GetDlgItem (IDC_ISSUANCE_POLICY_LABEL)->EnableWindow (TRUE);
  412. m_applicationPolicyCombo.EnableWindow (FALSE);
  413. GetDlgItem (IDC_APP_POLICY_LABEL)->EnableWindow (FALSE);
  414. break;
  415. case POLICY_TYPE_APPLICATION:
  416. m_issuanceList.EnableWindow (FALSE);
  417. GetDlgItem (IDC_ADD_APPROVAL)->EnableWindow (FALSE);
  418. GetDlgItem (IDC_REMOVE_APPROVAL)->EnableWindow (FALSE);
  419. GetDlgItem (IDC_ISSUANCE_POLICY_LABEL)->EnableWindow (FALSE);
  420. m_applicationPolicyCombo.EnableWindow (TRUE);
  421. GetDlgItem (IDC_APP_POLICY_LABEL)->EnableWindow (TRUE);
  422. break;
  423. case POLICY_TYPE_APPLICATION_AND_ISSUANCE:
  424. m_issuanceList.EnableWindow (TRUE);
  425. GetDlgItem (IDC_ADD_APPROVAL)->EnableWindow (TRUE);
  426. GetDlgItem (IDC_REMOVE_APPROVAL)->EnableWindow (nSel > 0 && nCnt > nSel);
  427. GetDlgItem (IDC_ISSUANCE_POLICY_LABEL)->EnableWindow (TRUE);
  428. m_applicationPolicyCombo.EnableWindow (TRUE);
  429. GetDlgItem (IDC_APP_POLICY_LABEL)->EnableWindow (TRUE);
  430. break;
  431. default: // nothing selected
  432. m_issuanceList.EnableWindow (FALSE);
  433. GetDlgItem (IDC_ADD_APPROVAL)->EnableWindow (FALSE);
  434. GetDlgItem (IDC_REMOVE_APPROVAL)->EnableWindow (FALSE);
  435. GetDlgItem (IDC_ISSUANCE_POLICY_LABEL)->EnableWindow (FALSE);
  436. m_applicationPolicyCombo.EnableWindow (FALSE);
  437. GetDlgItem (IDC_APP_POLICY_LABEL)->EnableWindow (FALSE);
  438. break;
  439. }
  440. }
  441. if ( BST_CHECKED == SendDlgItemMessage (IDC_PEND_ALL_REQUESTS,
  442. BM_GETCHECK) ||
  443. BST_CHECKED == SendDlgItemMessage (IDC_NUM_SIG_REQUIRED_CHECK,
  444. BM_GETCHECK) )
  445. {
  446. GetDlgItem (IDC_REENROLLMENT_SAME_AS_ENROLLMENT)->EnableWindow (TRUE);
  447. GetDlgItem (IDC_REENROLLMENT_REQUIRES_VALID_CERT)->EnableWindow (TRUE);
  448. }
  449. else
  450. {
  451. GetDlgItem (IDC_REENROLLMENT_SAME_AS_ENROLLMENT)->EnableWindow (FALSE);
  452. SendDlgItemMessage (IDC_REENROLLMENT_SAME_AS_ENROLLMENT,
  453. BM_SETCHECK, BST_CHECKED);
  454. SendDlgItemMessage (IDC_REENROLLMENT_REQUIRES_VALID_CERT,
  455. BM_SETCHECK, BST_UNCHECKED);
  456. m_rCertTemplate.SetReenrollmentValidWithPreviousApproval (false);
  457. GetDlgItem (IDC_REENROLLMENT_REQUIRES_VALID_CERT)->EnableWindow (FALSE);
  458. }
  459. }
  460. }
  461. void CTemplateV2AuthenticationPropertyPage::OnChangeNumSigRequiredEdit()
  462. {
  463. static bool bProcessingOnChangeNumSigRequiredEdit = false;
  464. if ( !bProcessingOnChangeNumSigRequiredEdit )
  465. {
  466. bProcessingOnChangeNumSigRequiredEdit = true;
  467. CString szText;
  468. if ( GetDlgItemText (IDC_NUM_SIG_REQUIRED_EDIT, szText) > 0 )
  469. {
  470. DWORD dwNumSignatures = GetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT);
  471. DWORD dwFormerNumSignatures = 0;
  472. m_rCertTemplate.GetRANumSignaturesRequired (dwFormerNumSignatures);
  473. if ( dwFormerNumSignatures != dwNumSignatures )
  474. {
  475. HRESULT hr = m_rCertTemplate.SetRANumSignaturesRequired (dwNumSignatures);
  476. if ( SUCCEEDED (hr) )
  477. {
  478. if ( 0 == dwFormerNumSignatures ||
  479. 0 == dwNumSignatures )
  480. {
  481. OnNumSigRequiredCheck();
  482. }
  483. SetModified ();
  484. m_rbIsDirty = true;
  485. }
  486. }
  487. }
  488. bProcessingOnChangeNumSigRequiredEdit = false;
  489. }
  490. }
  491. void CTemplateV2AuthenticationPropertyPage::OnAllowReenrollment()
  492. {
  493. HRESULT hr = m_rCertTemplate.SetReenrollmentValidWithPreviousApproval (
  494. BST_CHECKED == SendDlgItemMessage (IDC_REENROLLMENT_REQUIRES_VALID_CERT, BM_GETCHECK));
  495. if ( SUCCEEDED (hr) )
  496. {
  497. SetModified ();
  498. m_rbIsDirty = true;
  499. }
  500. }
  501. void CTemplateV2AuthenticationPropertyPage::DoContextHelp (HWND hWndControl)
  502. {
  503. _TRACE(1, L"Entering CTemplateV2AuthenticationPropertyPage::DoContextHelp\n");
  504. switch (::GetDlgCtrlID (hWndControl))
  505. {
  506. case IDC_STATIC:
  507. break;
  508. default:
  509. // Display context help for a control
  510. if ( !::WinHelp (
  511. hWndControl,
  512. GetContextHelpFile (),
  513. HELP_WM_HELP,
  514. (DWORD_PTR) g_aHelpIDs_IDD_TEMPLATE_V2_AUTHENTICATION) )
  515. {
  516. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  517. }
  518. break;
  519. }
  520. _TRACE(-1, L"Leaving CTemplateV2AuthenticationPropertyPage::DoContextHelp\n");
  521. }
  522. void CTemplateV2AuthenticationPropertyPage::OnPendAllRequests()
  523. {
  524. m_rCertTemplate.SetPendAllRequests (
  525. BST_CHECKED == SendDlgItemMessage (IDC_PEND_ALL_REQUESTS, BM_GETCHECK));
  526. SetModified ();
  527. m_rbIsDirty = true;
  528. EnableControls ();
  529. }
  530. void CTemplateV2AuthenticationPropertyPage::OnSelchangeIssuancePolicies()
  531. {
  532. EnableControls ();
  533. }
  534. void CTemplateV2AuthenticationPropertyPage::OnSelchangePolicyTypes()
  535. {
  536. SetModified ();
  537. m_rbIsDirty = true;
  538. switch (m_policyTypeCombo.GetItemData (m_policyTypeCombo.GetCurSel ()))
  539. {
  540. case POLICY_TYPE_ISSUANCE:
  541. {
  542. // Unselect the application policy and inform the user that
  543. // an issuance policy must be added if there aren't any
  544. int nSel = m_applicationPolicyCombo.GetCurSel ();
  545. if ( nSel >= 0 )
  546. {
  547. PSTR pszOID = (PSTR) m_applicationPolicyCombo.GetItemDataPtr (nSel);
  548. if ( pszOID )
  549. {
  550. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, false);
  551. _ASSERT (SUCCEEDED (hr));
  552. if ( SUCCEEDED (hr) )
  553. {
  554. SetModified ();
  555. m_rbIsDirty = true;
  556. }
  557. }
  558. m_applicationPolicyCombo.SetCurSel (LB_ERR);
  559. m_curApplicationSel = LB_ERR;
  560. }
  561. }
  562. break;
  563. case POLICY_TYPE_APPLICATION:
  564. {
  565. // Select an application policy, if necessary and remove
  566. // the issuance policies
  567. int nSel = m_applicationPolicyCombo.GetCurSel ();
  568. if ( LB_ERR == nSel )
  569. {
  570. m_applicationPolicyCombo.SetCurSel (0);
  571. nSel = m_applicationPolicyCombo.GetCurSel ();
  572. m_curApplicationSel = nSel;
  573. if ( nSel >= 0 )
  574. {
  575. PSTR pszOID = (PSTR) m_applicationPolicyCombo.GetItemDataPtr (nSel);
  576. if ( pszOID )
  577. {
  578. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, true);
  579. _ASSERT (SUCCEEDED (hr));
  580. if ( SUCCEEDED (hr) )
  581. {
  582. SetModified ();
  583. m_rbIsDirty = true;
  584. }
  585. }
  586. }
  587. }
  588. ClearIssuanceList ();
  589. }
  590. break;
  591. case POLICY_TYPE_APPLICATION_AND_ISSUANCE:
  592. {
  593. // Select an application policy, if necessary and inform the user
  594. // that an issuance policy must be added, if there aren't any.
  595. int nSel = m_applicationPolicyCombo.GetCurSel ();
  596. if ( LB_ERR == nSel )
  597. {
  598. m_applicationPolicyCombo.SetCurSel (0);
  599. nSel = m_applicationPolicyCombo.GetCurSel ();
  600. m_curApplicationSel = nSel;
  601. if ( nSel >= 0 )
  602. {
  603. PSTR pszOID = (PSTR) m_applicationPolicyCombo.GetItemDataPtr (nSel);
  604. if ( pszOID )
  605. {
  606. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, true);
  607. _ASSERT (SUCCEEDED (hr));
  608. if ( SUCCEEDED (hr) )
  609. {
  610. SetModified ();
  611. m_rbIsDirty = true;
  612. }
  613. }
  614. }
  615. }
  616. }
  617. break;
  618. default: // nothing selected
  619. break;
  620. }
  621. EnableControls ();
  622. }
  623. void CTemplateV2AuthenticationPropertyPage::OnSelchangeApplicationPolicies()
  624. {
  625. int nNewSel = m_applicationPolicyCombo.GetCurSel ();
  626. // Remove the old application OID and add the new one
  627. if ( m_curApplicationSel != nNewSel )
  628. {
  629. if ( LB_ERR != m_curApplicationSel )
  630. {
  631. LPSTR pszOID = (LPSTR) m_applicationPolicyCombo.GetItemDataPtr (m_curApplicationSel);
  632. if ( pszOID )
  633. {
  634. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, false);
  635. _ASSERT (SUCCEEDED (hr));
  636. }
  637. }
  638. if ( LB_ERR != nNewSel )
  639. {
  640. LPSTR pszOID = (LPSTR) m_applicationPolicyCombo.GetItemDataPtr (nNewSel);
  641. if ( pszOID )
  642. {
  643. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, true);
  644. _ASSERT (SUCCEEDED (hr));
  645. }
  646. }
  647. SetModified ();
  648. m_rbIsDirty = true;
  649. m_curApplicationSel = nNewSel;
  650. }
  651. }
  652. void CTemplateV2AuthenticationPropertyPage::OnDestroy()
  653. {
  654. int nCnt = m_issuanceList.GetCount ();
  655. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  656. {
  657. PSTR pszBuf = (PSTR) m_issuanceList.GetItemData (nIndex);
  658. if ( pszBuf )
  659. delete [] pszBuf;
  660. }
  661. nCnt = m_applicationPolicyCombo.GetCount ();
  662. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  663. {
  664. PSTR pszOID = (PSTR) m_applicationPolicyCombo.GetItemDataPtr (nIndex);
  665. if ( pszOID )
  666. delete [] pszOID;
  667. }
  668. CHelpPropertyPage::OnDestroy();
  669. }
  670. void CTemplateV2AuthenticationPropertyPage::OnNumSigRequiredCheck()
  671. {
  672. static bProcessingOnNumSigRequiredCheck = false;
  673. if ( !bProcessingOnNumSigRequiredCheck ) // to prevent reentrancy
  674. {
  675. bProcessingOnNumSigRequiredCheck = true;
  676. if ( BST_UNCHECKED == SendDlgItemMessage (IDC_NUM_SIG_REQUIRED_CHECK, BM_GETCHECK) )
  677. {
  678. if ( 0 != GetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT) )
  679. SetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT, 0);
  680. // NTRAID# 369551 CertTmpl:UI does not clean up changed settings
  681. // clear out policy type combo, application policy combo and issuance
  682. // policy list
  683. m_policyTypeCombo.SetCurSel (-1);
  684. m_policyTypeCombo.Clear ();
  685. // Clear application policy
  686. int nCurSel = m_applicationPolicyCombo.GetCurSel ();
  687. if ( LB_ERR != nCurSel )
  688. {
  689. // Remove the old application OID
  690. LPSTR pszOID = (LPSTR) m_applicationPolicyCombo.GetItemDataPtr (nCurSel);
  691. if ( pszOID )
  692. {
  693. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, false);
  694. _ASSERT (SUCCEEDED (hr));
  695. }
  696. }
  697. m_applicationPolicyCombo.SetCurSel (-1);
  698. m_curApplicationSel = -1;
  699. m_applicationPolicyCombo.Clear ();
  700. // Clear issuance policy
  701. ClearIssuanceList ();
  702. }
  703. else if ( 0 == GetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT) )
  704. SetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT, 1);
  705. if ( GetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT) > 0 )
  706. {
  707. // NTRAID# 397330 Certificate Template MMC: Add wrong RA
  708. // application policy OID for a cloned template
  709. m_curApplicationSel = 0;
  710. m_policyTypeCombo.SetCurSel (0);
  711. m_applicationPolicyCombo.SetCurSel (0);
  712. LPSTR pszOID = (LPSTR) m_applicationPolicyCombo.GetItemDataPtr (0);
  713. if ( pszOID )
  714. {
  715. HRESULT hr = m_rCertTemplate.ModifyRAApplicationPolicyList (pszOID, true);
  716. _ASSERT (SUCCEEDED (hr));
  717. }
  718. }
  719. EnableControls ();
  720. bProcessingOnNumSigRequiredCheck = false;
  721. }
  722. }
  723. void CTemplateV2AuthenticationPropertyPage::EnablePolicyControls (BOOL& bEnable)
  724. {
  725. GetDlgItem (IDC_NUM_SIG_REQUIRED_EDIT)->EnableWindow (bEnable);
  726. if ( bEnable )
  727. {
  728. if ( GetDlgItemInt (IDC_NUM_SIG_REQUIRED_EDIT) < 1 )
  729. bEnable = false;
  730. }
  731. GetDlgItem (IDC_POLICY_TYPES_LABEL)->EnableWindow (bEnable);
  732. GetDlgItem (IDC_POLICY_TYPES)->EnableWindow (bEnable);
  733. GetDlgItem (IDC_APP_POLICY_LABEL)->EnableWindow (bEnable);
  734. GetDlgItem (IDC_APPLICATION_POLICIES)->EnableWindow (bEnable);
  735. GetDlgItem (IDC_ISSUANCE_POLICY_LABEL)->EnableWindow (bEnable);
  736. GetDlgItem (IDC_ISSUANCE_POLICIES)->EnableWindow (bEnable);
  737. GetDlgItem (IDC_ADD_APPROVAL)->EnableWindow (bEnable);
  738. GetDlgItem (IDC_REMOVE_APPROVAL)->EnableWindow (bEnable);
  739. }
  740. BOOL CTemplateV2AuthenticationPropertyPage::OnKillActive()
  741. {
  742. switch (m_policyTypeCombo.GetItemData (m_policyTypeCombo.GetCurSel ()))
  743. {
  744. case POLICY_TYPE_ISSUANCE:
  745. {
  746. // Inform the user that
  747. // an issuance policy must be added if there aren't any
  748. m_rCertTemplate.IssuancePoliciesRequired (
  749. (0 == m_issuanceList.GetCount ()) ? true : false);
  750. }
  751. break;
  752. case POLICY_TYPE_APPLICATION_AND_ISSUANCE:
  753. {
  754. // Inform the user
  755. // that an issuance policy must be added, if there aren't any.
  756. m_rCertTemplate.IssuancePoliciesRequired (
  757. (0 == m_issuanceList.GetCount ()) ? true : false);
  758. }
  759. break;
  760. case POLICY_TYPE_APPLICATION:
  761. default: // nothing selected
  762. m_rCertTemplate.IssuancePoliciesRequired (false);
  763. break;
  764. }
  765. return CHelpPropertyPage::OnKillActive();
  766. }
  767. void CTemplateV2AuthenticationPropertyPage::OnReenrollmentSameAsEnrollment()
  768. {
  769. HRESULT hr = m_rCertTemplate.SetReenrollmentValidWithPreviousApproval (
  770. BST_CHECKED == SendDlgItemMessage (IDC_REENROLLMENT_REQUIRES_VALID_CERT, BM_GETCHECK));
  771. if ( SUCCEEDED (hr) )
  772. {
  773. SetModified ();
  774. m_rbIsDirty = true;
  775. }
  776. }
  777. void CTemplateV2AuthenticationPropertyPage::ClearIssuanceList ()
  778. {
  779. int nCnt = m_issuanceList.GetCount ();
  780. for (int nIndex = nCnt-1; nIndex >= 0; nIndex--)
  781. {
  782. LPSTR pszOID = (LPSTR) m_issuanceList.GetItemDataPtr (nIndex);
  783. if ( pszOID )
  784. {
  785. HRESULT hr = m_rCertTemplate.ModifyRAIssuancePolicyList (pszOID, false);
  786. if ( SUCCEEDED (hr) )
  787. {
  788. m_issuanceList.DeleteString (nIndex);
  789. delete [] pszOID;
  790. SetModified ();
  791. m_rbIsDirty = true;
  792. }
  793. else
  794. {
  795. _ASSERT (0);
  796. break;
  797. }
  798. }
  799. }
  800. }