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.

698 lines
26 KiB

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