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.

861 lines
30 KiB

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