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.

658 lines
23 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2001.
  5. //
  6. // File: PolicyDlg.cpp
  7. //
  8. // Contents: Implementation of CPolicyDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // PolicyDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "PolicyDlg.h"
  15. #include "SelectOIDDlg.h"
  16. #include "NewApplicationOIDDlg.h"
  17. #include "NewIssuanceOIDDlg.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CPolicyDlg property page
  25. CPolicyDlg::CPolicyDlg(CWnd* pParent,
  26. CCertTemplate& rCertTemplate,
  27. PCERT_EXTENSION pCertExtension)
  28. : CHelpDialog(CPolicyDlg::IDD, pParent),
  29. m_rCertTemplate (rCertTemplate),
  30. m_pCertExtension (pCertExtension),
  31. m_bIsEKU ( !_stricmp (szOID_ENHANCED_KEY_USAGE, pCertExtension->pszObjId) ? true : false),
  32. m_bIsApplicationPolicy ( !_stricmp (szOID_APPLICATION_CERT_POLICIES, pCertExtension->pszObjId) ? true : false),
  33. m_bModified (false)
  34. {
  35. //{{AFX_DATA_INIT(CPolicyDlg)
  36. // NOTE: the ClassWizard will add member initialization here
  37. //}}AFX_DATA_INIT
  38. }
  39. CPolicyDlg::~CPolicyDlg()
  40. {
  41. }
  42. void CPolicyDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CHelpDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CPolicyDlg)
  46. DDX_Control(pDX, IDC_POLICIES_LIST, m_policyList);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CPolicyDlg, CHelpDialog)
  50. //{{AFX_MSG_MAP(CPolicyDlg)
  51. ON_WM_CANCELMODE()
  52. ON_BN_CLICKED(IDC_ADD_POLICY, OnAddPolicy)
  53. ON_BN_CLICKED(IDC_REMOVE_POLICY, OnRemovePolicy)
  54. ON_BN_CLICKED(IDC_POLICY_CRITICAL, OnPolicyCritical)
  55. ON_WM_DESTROY()
  56. ON_LBN_SELCHANGE(IDC_POLICIES_LIST, OnSelchangePoliciesList)
  57. ON_BN_CLICKED(IDC_EDIT_POLICY, OnEditPolicy)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CPolicyDlg message handlers
  62. BOOL CPolicyDlg::OnInitDialog()
  63. {
  64. _TRACE (1, L"Entering CPolicyDlg::OnInitDialog\n");
  65. CHelpDialog::OnInitDialog();
  66. CString text;
  67. if ( m_bIsEKU )
  68. {
  69. VERIFY (text.LoadString (IDS_EDIT_APPLICATION_POLICIES_EXTENSION));
  70. SetWindowText (text);
  71. VERIFY (text.LoadString (IDS_EFFECTIVE_APPLICATION_POLICIES));
  72. int nEKUIndex = 0;
  73. CString szEKU;
  74. while ( SUCCEEDED (m_rCertTemplate.GetEnhancedKeyUsage (nEKUIndex, szEKU)) )
  75. {
  76. int nLen = WideCharToMultiByte(
  77. CP_ACP, // code page
  78. 0, // performance and mapping flags
  79. (PCWSTR) szEKU, // wide-character string
  80. (int) wcslen (szEKU), // number of chars in string
  81. 0, // buffer for new string
  82. 0, // size of buffer
  83. 0, // default for unmappable chars
  84. 0); // set when default char used
  85. if ( nLen > 0 )
  86. {
  87. nLen++; // account for Null terminator
  88. PSTR pszAnsiBuf = new CHAR[nLen];
  89. if ( pszAnsiBuf )
  90. {
  91. ZeroMemory (pszAnsiBuf, nLen*sizeof(CHAR));
  92. nLen = WideCharToMultiByte(
  93. CP_ACP, // code page
  94. 0, // performance and mapping flags
  95. (PCWSTR) szEKU, // wide-character string
  96. (int) wcslen (szEKU), // number of chars in string
  97. pszAnsiBuf, // buffer for new string
  98. nLen, // size of buffer
  99. 0, // default for unmappable chars
  100. 0); // set when default char used
  101. if ( nLen )
  102. {
  103. CString szEKUName;
  104. if ( MyGetOIDInfoA (szEKUName, pszAnsiBuf) )
  105. {
  106. int nIndex = m_policyList.AddString (szEKUName);
  107. if ( nIndex >= 0 )
  108. {
  109. m_policyList.SetItemDataPtr (nIndex, pszAnsiBuf);
  110. }
  111. }
  112. }
  113. }
  114. }
  115. nEKUIndex++;
  116. }
  117. }
  118. else if ( m_bIsApplicationPolicy )
  119. {
  120. VERIFY (text.LoadString (IDS_EDIT_APPLICATION_POLICIES_EXTENSION));
  121. SetWindowText (text);
  122. VERIFY (text.LoadString (IDS_EFFECTIVE_APPLICATION_POLICIES));
  123. int nAppPolicyIndex = 0;
  124. CString szAppPolicy;
  125. while ( SUCCEEDED (m_rCertTemplate.GetApplicationPolicy (nAppPolicyIndex, szAppPolicy)) )
  126. {
  127. int nLen = WideCharToMultiByte(
  128. CP_ACP, // code page
  129. 0, // performance and mapping flags
  130. (PCWSTR) szAppPolicy, // wide-character string
  131. (int) wcslen (szAppPolicy), // number of chars in string
  132. 0, // buffer for new string
  133. 0, // size of buffer
  134. 0, // default for unmappable chars
  135. 0); // set when default char used
  136. if ( nLen > 0 )
  137. {
  138. nLen++; // account for Null terminator
  139. PSTR pszAnsiBuf = new CHAR[nLen];
  140. if ( pszAnsiBuf )
  141. {
  142. ZeroMemory (pszAnsiBuf, nLen*sizeof(CHAR));
  143. nLen = WideCharToMultiByte(
  144. CP_ACP, // code page
  145. 0, // performance and mapping flags
  146. (PCWSTR) szAppPolicy, // wide-character string
  147. (int) wcslen (szAppPolicy), // number of chars in string
  148. pszAnsiBuf, // buffer for new string
  149. nLen, // size of buffer
  150. 0, // default for unmappable chars
  151. 0); // set when default char used
  152. if ( nLen )
  153. {
  154. CString szAppPolicyName;
  155. if ( MyGetOIDInfoA (szAppPolicyName, pszAnsiBuf) )
  156. {
  157. int nIndex = m_policyList.AddString (szAppPolicyName);
  158. if ( nIndex >= 0 )
  159. {
  160. m_policyList.SetItemDataPtr (nIndex, pszAnsiBuf);
  161. }
  162. }
  163. }
  164. }
  165. }
  166. nAppPolicyIndex++;
  167. }
  168. }
  169. else
  170. {
  171. VERIFY (text.LoadString (IDS_EDIT_ISSUANCE_POLICIES_EXTENSION));
  172. SetWindowText (text);
  173. VERIFY (text.LoadString (IDS_ISSUANCE_POLICIES_HINT));
  174. SetDlgItemText (IDC_POLICIES_HINT, text);
  175. VERIFY (text.LoadString (IDS_EFFECTIVE_ISSUANCE_POLICIES));
  176. int nCertPolicyIndex = 0;
  177. CString szCertPolicy;
  178. while ( SUCCEEDED (m_rCertTemplate.GetCertPolicy (nCertPolicyIndex, szCertPolicy)) )
  179. {
  180. int nLen = WideCharToMultiByte(
  181. CP_ACP, // code page
  182. 0, // performance and mapping flags
  183. (PCWSTR) szCertPolicy, // wide-character string
  184. (int) wcslen (szCertPolicy), // number of chars in string
  185. 0, // buffer for new string
  186. 0, // size of buffer
  187. 0, // default for unmappable chars
  188. 0); // set when default char used
  189. if ( nLen > 0 )
  190. {
  191. nLen++; // account for Null terminator
  192. PSTR pszAnsiBuf = new CHAR[nLen];
  193. if ( pszAnsiBuf )
  194. {
  195. ZeroMemory (pszAnsiBuf, nLen*sizeof(CHAR));
  196. nLen = WideCharToMultiByte(
  197. CP_ACP, // code page
  198. 0, // performance and mapping flags
  199. (PCWSTR) szCertPolicy, // wide-character string
  200. (int) wcslen (szCertPolicy), // number of chars in string
  201. pszAnsiBuf, // buffer for new string
  202. nLen, // size of buffer
  203. 0, // default for unmappable chars
  204. 0); // set when default char used
  205. if ( nLen )
  206. {
  207. CString szPolicyName;
  208. if ( MyGetOIDInfoA (szPolicyName, pszAnsiBuf) )
  209. {
  210. int nIndex = m_policyList.AddString (szPolicyName);
  211. if ( nIndex >= 0 )
  212. {
  213. m_policyList.SetItemDataPtr (nIndex, pszAnsiBuf);
  214. }
  215. }
  216. }
  217. }
  218. }
  219. nCertPolicyIndex++;
  220. }
  221. }
  222. SetDlgItemText (IDD_POLICIES_LABEL, text);
  223. if ( 1 == m_rCertTemplate.GetType () )
  224. {
  225. GetDlgItem (IDC_POLICY_CRITICAL)->EnableWindow (FALSE);
  226. GetDlgItem (IDD_POLICIES_LABEL)->EnableWindow (FALSE);
  227. GetDlgItem (IDC_POLICIES_LIST)->EnableWindow (FALSE);
  228. GetDlgItem (IDC_ADD_POLICY)->EnableWindow (FALSE);
  229. GetDlgItem (IDC_REMOVE_POLICY)->EnableWindow (FALSE);
  230. }
  231. bool bCritical = false;
  232. PWSTR pszOID = 0;
  233. if ( m_bIsEKU )
  234. pszOID = TEXT (szOID_ENHANCED_KEY_USAGE);
  235. else if ( m_bIsApplicationPolicy )
  236. pszOID = TEXT (szOID_APPLICATION_CERT_POLICIES);
  237. else
  238. pszOID = TEXT (szOID_CERT_POLICIES);
  239. if ( SUCCEEDED (m_rCertTemplate.IsExtensionCritical (
  240. pszOID,
  241. bCritical)) && bCritical )
  242. {
  243. SendDlgItemMessage (IDC_POLICY_CRITICAL, BM_SETCHECK, BST_CHECKED);
  244. }
  245. EnableControls ();
  246. _TRACE (-1, L"Leaving CPolicyDlg::OnInitDialog\n");
  247. return TRUE; // return TRUE unless you set the focus to a control
  248. // EXCEPTION: OCX Property Pages should return FALSE
  249. }
  250. void CPolicyDlg::OnCancelMode()
  251. {
  252. CHelpDialog::OnCancelMode();
  253. if ( m_pCertExtension->fCritical )
  254. SendDlgItemMessage (IDC_POLICY_CRITICAL, BM_SETCHECK, BST_CHECKED);
  255. }
  256. void CPolicyDlg::OnAddPolicy()
  257. {
  258. // Create the list of already added OIDs. These will not be displayed
  259. // in the Select OID dialog.
  260. int nCnt = m_policyList.GetCount ();
  261. PSTR* paszUsedOIDs = 0;
  262. // allocate an array of PSTR pointers and add each item.
  263. // Set the last to NULL
  264. if ( nCnt )
  265. {
  266. paszUsedOIDs = new PSTR[nCnt+1];
  267. if ( paszUsedOIDs )
  268. {
  269. ::ZeroMemory (paszUsedOIDs, sizeof (PSTR) * (nCnt+1));
  270. while (--nCnt >= 0)
  271. {
  272. PSTR pszOID = (PSTR) m_policyList.GetItemData (nCnt);
  273. if ( pszOID )
  274. {
  275. PSTR pNewStr = new CHAR[strlen (pszOID) + 1];
  276. if ( pNewStr )
  277. {
  278. strcpy (pNewStr, pszOID);
  279. paszUsedOIDs[nCnt] = pNewStr;
  280. }
  281. else
  282. break;
  283. }
  284. }
  285. }
  286. }
  287. CSelectOIDDlg dlg (this, m_pCertExtension, m_bIsEKU || m_bIsApplicationPolicy,
  288. paszUsedOIDs);
  289. CThemeContextActivator activator;
  290. if ( IDOK == dlg.DoModal () )
  291. {
  292. if ( dlg.m_paszReturnedOIDs && dlg.m_paszReturnedFriendlyNames )
  293. {
  294. for (int nIndex = 0; !dlg.m_paszReturnedOIDs[nIndex].IsEmpty (); nIndex++)
  295. {
  296. int nLen = WideCharToMultiByte(
  297. CP_ACP, // code page
  298. 0, // performance and mapping flags
  299. (PCWSTR) dlg.m_paszReturnedOIDs[nIndex], // wide-character string
  300. (int) wcslen (dlg.m_paszReturnedOIDs[nIndex]), // number of chars in string
  301. 0, // buffer for new string
  302. 0, // size of buffer
  303. 0, // default for unmappable chars
  304. 0); // set when default char used
  305. if ( nLen > 0 )
  306. {
  307. nLen++; // account for Null terminator
  308. PSTR pszAnsiBuf = new CHAR[nLen];
  309. if ( pszAnsiBuf )
  310. {
  311. ZeroMemory (pszAnsiBuf, nLen*sizeof(CHAR));
  312. nLen = WideCharToMultiByte(
  313. CP_ACP, // code page
  314. 0, // performance and mapping flags
  315. (PCWSTR) dlg.m_paszReturnedOIDs[nIndex], // wide-character string
  316. (int) wcslen (dlg.m_paszReturnedOIDs[nIndex]), // number of chars in string
  317. pszAnsiBuf, // buffer for new string
  318. nLen, // size of buffer
  319. 0, // default for unmappable chars
  320. 0); // set when default char used
  321. if ( nLen )
  322. {
  323. int nAddedIndex = m_policyList.AddString (dlg.m_paszReturnedFriendlyNames[nIndex]);
  324. if ( nAddedIndex >= 0 )
  325. {
  326. m_policyList.SetItemDataPtr (nAddedIndex, pszAnsiBuf);
  327. m_policyList.SetSel (nAddedIndex, TRUE);
  328. m_bModified = true;
  329. EnableControls ();
  330. }
  331. }
  332. else
  333. {
  334. _TRACE (0, L"WideCharToMultiByte (%s) failed: 0x%x\n",
  335. (PCWSTR) dlg.m_paszReturnedOIDs[nIndex], GetLastError ());
  336. }
  337. }
  338. }
  339. else
  340. {
  341. _TRACE (0, L"WideCharToMultiByte (%s) failed: 0x%x\n",
  342. (PCWSTR) dlg.m_paszReturnedOIDs[nIndex], GetLastError ());
  343. }
  344. }
  345. }
  346. }
  347. // clean up
  348. if ( paszUsedOIDs )
  349. {
  350. for (int nIndex = 0; paszUsedOIDs[nIndex]; nIndex++)
  351. delete [] paszUsedOIDs[nIndex];
  352. delete [] paszUsedOIDs;
  353. }
  354. }
  355. void CPolicyDlg::OnRemovePolicy()
  356. {
  357. int nSelCnt = m_policyList.GetSelCount ();
  358. if ( nSelCnt > 0 )
  359. {
  360. int* pnSelIndexes = new int[nSelCnt];
  361. if ( pnSelIndexes )
  362. {
  363. if ( LB_ERR != m_policyList.GetSelItems (nSelCnt, pnSelIndexes) )
  364. {
  365. for (int nIndex = nSelCnt - 1; nIndex >= 0; nIndex--)
  366. {
  367. PSTR pszOID = (PSTR) m_policyList.GetItemDataPtr (pnSelIndexes[nIndex]);
  368. if ( pszOID )
  369. delete [] pszOID;
  370. m_policyList.DeleteString (pnSelIndexes[nIndex]);
  371. }
  372. m_bModified = true;
  373. }
  374. delete [] pnSelIndexes;
  375. }
  376. }
  377. EnableControls ();
  378. }
  379. void CPolicyDlg::EnableControls()
  380. {
  381. if ( 1 == m_rCertTemplate.GetType () )
  382. {
  383. GetDlgItem (IDOK)->EnableWindow (FALSE);
  384. GetDlgItem (IDC_REMOVE_POLICY)->EnableWindow (FALSE);
  385. GetDlgItem (IDC_ADD_POLICY)->EnableWindow (FALSE);
  386. GetDlgItem (IDC_POLICY_CRITICAL)->EnableWindow (FALSE);
  387. GetDlgItem (IDC_EDIT_POLICY)->EnableWindow (FALSE);
  388. }
  389. else
  390. {
  391. GetDlgItem (IDOK)->EnableWindow (m_bModified && !m_rCertTemplate.ReadOnly ());
  392. GetDlgItem (IDC_REMOVE_POLICY)->EnableWindow (
  393. m_policyList.GetSelCount () > 0 && !m_rCertTemplate.ReadOnly ());
  394. GetDlgItem (IDC_ADD_POLICY)->EnableWindow (!m_rCertTemplate.ReadOnly ());
  395. GetDlgItem (IDC_POLICY_CRITICAL)->EnableWindow (!m_rCertTemplate.ReadOnly ());
  396. GetDlgItem (IDC_EDIT_POLICY)->EnableWindow (
  397. m_policyList.GetSelCount () == 1 && !m_rCertTemplate.ReadOnly ());
  398. }
  399. }
  400. void CPolicyDlg::OnPolicyCritical()
  401. {
  402. m_bModified = true;
  403. EnableControls ();
  404. }
  405. void CPolicyDlg::OnDestroy()
  406. {
  407. CHelpDialog::OnDestroy();
  408. int nCnt = m_policyList.GetCount ();
  409. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  410. {
  411. PSTR pszOID = (PSTR) m_policyList.GetItemDataPtr (nIndex);
  412. if ( pszOID )
  413. delete [] pszOID;
  414. }
  415. }
  416. void CPolicyDlg::OnSelchangePoliciesList()
  417. {
  418. EnableControls ();
  419. }
  420. void CPolicyDlg::DoContextHelp (HWND hWndControl)
  421. {
  422. _TRACE(1, L"Entering CPolicyDlg::DoContextHelp\n");
  423. switch (::GetDlgCtrlID (hWndControl))
  424. {
  425. case IDD_POLICIES_LABEL:
  426. break;
  427. default:
  428. // Display context help for a control
  429. if ( !::WinHelp (
  430. hWndControl,
  431. GetContextHelpFile (),
  432. HELP_WM_HELP,
  433. (DWORD_PTR) g_aHelpIDs_IDD_POLICY) )
  434. {
  435. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  436. }
  437. break;
  438. }
  439. _TRACE(-1, L"Leaving CPolicyDlg::DoContextHelp\n");
  440. }
  441. void CPolicyDlg::OnEditPolicy()
  442. {
  443. int nSel = this->m_policyList.GetCurSel ();
  444. if ( nSel >= 0 )
  445. {
  446. CString szDisplayName;
  447. m_policyList.GetText (nSel, szDisplayName);
  448. PSTR pszOID = (PSTR) m_policyList.GetItemDataPtr (nSel);
  449. if ( pszOID )
  450. {
  451. CString newDisplayName;
  452. INT_PTR iRet = 0;
  453. if ( m_bIsEKU || m_bIsApplicationPolicy)
  454. {
  455. CNewApplicationOIDDlg dlg (this, szDisplayName, pszOID);
  456. CThemeContextActivator activator;
  457. iRet = dlg.DoModal ();
  458. if ( IDOK == iRet )
  459. newDisplayName = dlg.m_oidFriendlyName;
  460. }
  461. else
  462. {
  463. PWSTR pszCPS = 0;
  464. CString strOID = pszOID;
  465. HRESULT hr = CAOIDGetProperty(
  466. strOID,
  467. CERT_OID_PROPERTY_CPS,
  468. &pszCPS);
  469. if ( SUCCEEDED (hr) ||
  470. HRESULT_FROM_WIN32 (ERROR_FILE_NOT_FOUND) == hr ||
  471. HRESULT_FROM_WIN32 (ERROR_DS_OBJ_NOT_FOUND) == hr ||
  472. HRESULT_FROM_WIN32 (ERROR_INVALID_PARAMETER) == hr )
  473. {
  474. CNewIssuanceOIDDlg dlg (this, szDisplayName, pszOID,
  475. pszCPS);
  476. CThemeContextActivator activator;
  477. iRet = dlg.DoModal ();
  478. if ( IDOK == iRet )
  479. newDisplayName = dlg.m_oidFriendlyName;
  480. }
  481. else
  482. {
  483. DWORD dwErr = HRESULT_CODE (hr);
  484. if ( ERROR_INVALID_PARAMETER != dwErr )
  485. {
  486. CString text;
  487. CString caption;
  488. CThemeContextActivator activator;
  489. VERIFY (caption.LoadString (IDS_CERTTMPL));
  490. text.FormatMessage (IDS_CANNOT_READ_CPS, GetSystemMessage (hr));
  491. MessageBox (text, caption, MB_OK);
  492. _TRACE (0, L"CAOIDGetProperty (CERT_OID_PROPERTY_CPS) failed: 0x%x\n", hr);
  493. }
  494. }
  495. }
  496. if ( IDOK == iRet )
  497. {
  498. if ( szDisplayName != newDisplayName )
  499. {
  500. m_policyList.DeleteString (nSel);
  501. int nIndex = m_policyList.AddString (newDisplayName);
  502. if ( nIndex >= 0 )
  503. m_policyList.SetItemDataPtr (nIndex, pszOID);
  504. }
  505. }
  506. }
  507. }
  508. }
  509. void CPolicyDlg::OnOK()
  510. {
  511. // Create the list of OIDs.
  512. int nCnt = m_policyList.GetCount ();
  513. PWSTR* paszEKUs = 0;
  514. // allocate an array of PSTR pointers and add each item.
  515. // Set the last to NULL
  516. if ( nCnt )
  517. {
  518. paszEKUs = new PWSTR[nCnt+1];
  519. if ( paszEKUs )
  520. {
  521. ::ZeroMemory (paszEKUs, sizeof (PWSTR) * (nCnt+1));
  522. while (--nCnt >= 0)
  523. {
  524. PSTR pszOID = (PSTR) m_policyList.GetItemData (nCnt);
  525. if ( pszOID )
  526. {
  527. PWSTR pNewStr = 0;
  528. int nLen = ::MultiByteToWideChar (CP_ACP, 0, pszOID, -1, NULL, 0);
  529. ASSERT (nLen);
  530. if ( nLen )
  531. {
  532. pNewStr = new WCHAR[nLen];
  533. if ( pNewStr )
  534. {
  535. nLen = ::MultiByteToWideChar (CP_ACP, 0, pszOID, -1,
  536. pNewStr, nLen);
  537. ASSERT (nLen);
  538. if ( nLen )
  539. {
  540. paszEKUs[nCnt] = pNewStr;
  541. }
  542. }
  543. }
  544. }
  545. }
  546. }
  547. }
  548. CThemeContextActivator activator;
  549. bool bCritical = BST_CHECKED == SendDlgItemMessage (
  550. IDC_POLICY_CRITICAL, BM_GETCHECK);
  551. HRESULT hr = S_OK;
  552. if ( m_bIsEKU )
  553. {
  554. hr = m_rCertTemplate.SetEnhancedKeyUsage (paszEKUs, bCritical);
  555. if ( FAILED (hr) )
  556. {
  557. CString text;
  558. CString caption;
  559. VERIFY (caption.LoadString (IDS_CERTTMPL));
  560. text.FormatMessage (IDS_CANNOT_SAVE_EKU_EXTENSION, GetSystemMessage (hr));
  561. MessageBox (text, caption, MB_OK);
  562. }
  563. }
  564. else if ( m_bIsApplicationPolicy )
  565. {
  566. hr = m_rCertTemplate.SetApplicationPolicy (paszEKUs, bCritical);
  567. if ( FAILED (hr) )
  568. {
  569. CString text;
  570. CString caption;
  571. VERIFY (caption.LoadString (IDS_CERTTMPL));
  572. text.FormatMessage (IDS_CANNOT_SAVE_APPLICATION_POLICY_EXTENSION, GetSystemMessage (hr));
  573. MessageBox (text, caption, MB_OK);
  574. }
  575. }
  576. else
  577. {
  578. hr = m_rCertTemplate.SetCertPolicy (paszEKUs, bCritical);
  579. if ( FAILED (hr) )
  580. {
  581. CString text;
  582. CString caption;
  583. VERIFY (caption.LoadString (IDS_CERTTMPL));
  584. text.FormatMessage (IDS_CANNOT_SAVE_CERT_POLICY_EXTENSION, GetSystemMessage (hr));
  585. MessageBox (text, caption, MB_OK);
  586. }
  587. }
  588. // clean up
  589. if ( paszEKUs )
  590. {
  591. for (int nIndex = 0; paszEKUs[nIndex]; nIndex++)
  592. delete [] paszEKUs[nIndex];
  593. delete [] paszEKUs;
  594. }
  595. if ( SUCCEEDED (hr) )
  596. CHelpDialog::OnOK();
  597. }