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.

262 lines
6.8 KiB

  1. // SelectOIDDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "certtmpl.h"
  5. #include "SelectOIDDlg.h"
  6. #include "NewApplicationOIDDlg.h"
  7. #include "NewIssuanceOIDDlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSelectOIDDlg dialog
  15. extern POLICY_OID_LIST g_policyOIDList;
  16. CSelectOIDDlg::CSelectOIDDlg(CWnd* pParent, PCERT_EXTENSION pCertExtension,
  17. const bool bIsEKU,
  18. const PSTR* paszUsedOIDs)
  19. : CHelpDialog(CSelectOIDDlg::IDD, pParent),
  20. m_pCertExtension (pCertExtension),
  21. m_bIsEKU (bIsEKU),
  22. m_paszUsedOIDs (paszUsedOIDs),
  23. m_paszReturnedOIDs (0),
  24. m_paszReturnedFriendlyNames (0)
  25. {
  26. //{{AFX_DATA_INIT(CSelectOIDDlg)
  27. //}}AFX_DATA_INIT
  28. }
  29. CSelectOIDDlg::~CSelectOIDDlg()
  30. {
  31. if ( m_paszReturnedOIDs )
  32. delete [] m_paszReturnedOIDs;
  33. if ( m_paszReturnedFriendlyNames )
  34. delete [] m_paszReturnedFriendlyNames;
  35. }
  36. void CSelectOIDDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CHelpDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CSelectOIDDlg)
  40. DDX_Control(pDX, IDC_OID_LIST, m_oidList);
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CSelectOIDDlg, CHelpDialog)
  44. //{{AFX_MSG_MAP(CSelectOIDDlg)
  45. ON_BN_CLICKED(IDC_NEW_OID, OnNewOid)
  46. ON_LBN_SELCHANGE(IDC_OID_LIST, OnSelchangeOidList)
  47. ON_WM_DESTROY()
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CSelectOIDDlg message handlers
  52. void CSelectOIDDlg::OnNewOid()
  53. {
  54. INT_PTR iRet = 0;
  55. CString szFriendlyName;
  56. CString szOID;
  57. if ( m_bIsEKU )
  58. {
  59. CNewApplicationOIDDlg dlg (this);
  60. CThemeContextActivator activator;
  61. iRet = dlg.DoModal ();
  62. if (IDOK == iRet )
  63. {
  64. szFriendlyName = dlg.m_oidFriendlyName;
  65. szOID = dlg.m_oidValue;
  66. }
  67. }
  68. else
  69. {
  70. CNewIssuanceOIDDlg dlg (this);
  71. CThemeContextActivator activator;
  72. iRet = dlg.DoModal ();
  73. if (IDOK == iRet )
  74. {
  75. szFriendlyName = dlg.m_oidFriendlyName;
  76. szOID = dlg.m_oidValue;
  77. }
  78. }
  79. if ( IDOK == iRet )
  80. {
  81. CPolicyOID* pPolicyOID = new CPolicyOID (szOID, szFriendlyName,
  82. m_bIsEKU ? CERT_OID_TYPE_APPLICATION_POLICY : CERT_OID_TYPE_ISSUER_POLICY);
  83. if ( pPolicyOID )
  84. {
  85. g_policyOIDList.AddTail (pPolicyOID);
  86. int nIndex = m_oidList.AddString (szFriendlyName);
  87. if ( nIndex >= 0 )
  88. {
  89. m_oidList.SetItemData (nIndex, (DWORD_PTR) new CString (szOID));
  90. VERIFY (LB_ERR != m_oidList.SetSel (nIndex, TRUE));
  91. EnableControls ();
  92. }
  93. }
  94. }
  95. }
  96. BOOL CSelectOIDDlg::OnInitDialog()
  97. {
  98. CHelpDialog::OnInitDialog();
  99. CString text;
  100. if ( m_bIsEKU )
  101. VERIFY (text.LoadString (IDS_ALL_APPLICATION_OIDS));
  102. else
  103. {
  104. VERIFY (text.LoadString (IDS_ADD_ISSUANCE_POLICY));
  105. SetWindowText (text);
  106. VERIFY (text.LoadString (IDS_ADD_ISSUANCE_POLICY_HINT));
  107. SetDlgItemText (IDC_ADD_POLICY_HINT, text);
  108. VERIFY (text.LoadString (IDS_ALL_ISSUANCE_OIDS));
  109. }
  110. SetDlgItemText (IDC_OID_TYPE, text);
  111. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  112. {
  113. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  114. if ( pPolicyOID )
  115. {
  116. // If this is the Application OID dialog, show only application
  117. // OIDS, otherwise if this is the Issuance OID dialog, show only
  118. // issuance OIDs
  119. if ( (m_bIsEKU && pPolicyOID->IsApplicationOID ()) ||
  120. (!m_bIsEKU && pPolicyOID->IsIssuanceOID ()) )
  121. {
  122. bool bFound = false;
  123. // Don't display an OID that's already been used
  124. if ( m_paszUsedOIDs )
  125. {
  126. for (int nIndex = 0; m_paszUsedOIDs[nIndex]; nIndex++)
  127. {
  128. if ( !strcmp (pPolicyOID->GetOIDA (), m_paszUsedOIDs[nIndex]) )
  129. {
  130. bFound = true;
  131. break;
  132. }
  133. }
  134. }
  135. if ( !bFound )
  136. {
  137. int nIndex = m_oidList.AddString (pPolicyOID->GetDisplayName ());
  138. if ( nIndex >= 0 )
  139. {
  140. m_oidList.SetItemData (nIndex,
  141. (DWORD_PTR) new CString (pPolicyOID->GetOIDW ()));
  142. }
  143. }
  144. }
  145. }
  146. }
  147. EnableControls ();
  148. return TRUE; // return TRUE unless you set the focus to a control
  149. // EXCEPTION: OCX Property Pages should return FALSE
  150. }
  151. void CSelectOIDDlg::DoContextHelp (HWND hWndControl)
  152. {
  153. _TRACE(1, L"Entering CSelectOIDDlg::DoContextHelp\n");
  154. switch (::GetDlgCtrlID (hWndControl))
  155. {
  156. case IDC_OID_TYPE:
  157. case IDC_STATIC:
  158. break;
  159. default:
  160. // Display context help for a control
  161. if ( !::WinHelp (
  162. hWndControl,
  163. GetContextHelpFile (),
  164. HELP_WM_HELP,
  165. (DWORD_PTR) g_aHelpIDs_IDD_SELECT_OIDS) )
  166. {
  167. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  168. }
  169. break;
  170. }
  171. _TRACE(-1, L"Leaving CSelectOIDDlg::DoContextHelp\n");
  172. }
  173. void CSelectOIDDlg::OnOK()
  174. {
  175. UpdateData (TRUE);
  176. int nSelCnt = m_oidList.GetSelCount ();
  177. if ( nSelCnt > 0 )
  178. {
  179. int* pnSelItems = new int[nSelCnt];
  180. if ( pnSelItems )
  181. {
  182. if ( LB_ERR != m_oidList.GetSelItems (nSelCnt, pnSelItems) )
  183. {
  184. m_paszReturnedOIDs = new CString[nSelCnt+1];
  185. if ( m_paszReturnedOIDs )
  186. {
  187. m_paszReturnedFriendlyNames = new CString[nSelCnt+1];
  188. if ( m_paszReturnedFriendlyNames )
  189. {
  190. for (int nIndex = 0; nIndex < nSelCnt; nIndex++)
  191. {
  192. m_paszReturnedOIDs[nIndex] = *(CString*) m_oidList.GetItemData (pnSelItems[nIndex]);
  193. m_oidList.GetText (pnSelItems[nIndex], m_paszReturnedFriendlyNames[nIndex]);
  194. }
  195. }
  196. }
  197. }
  198. delete [] pnSelItems;
  199. }
  200. }
  201. CHelpDialog::OnOK();
  202. }
  203. void CSelectOIDDlg::EnableControls ()
  204. {
  205. int nSel = m_oidList.GetSelCount ();
  206. GetDlgItem (IDOK)->EnableWindow (nSel >= 0);
  207. }
  208. void CSelectOIDDlg::OnSelchangeOidList()
  209. {
  210. EnableControls ();
  211. }
  212. void CSelectOIDDlg::OnDestroy()
  213. {
  214. CHelpDialog::OnDestroy();
  215. int nCnt = m_oidList.GetCount ();
  216. for (int nIndex = 0; nIndex < nCnt; nIndex++)
  217. {
  218. CString* pszOID = (CString*) m_oidList.GetItemData (nIndex);
  219. if ( pszOID )
  220. delete pszOID;
  221. }
  222. }