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.

278 lines
7.7 KiB

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