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.

223 lines
6.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000-2002.
  5. //
  6. // File: AddApprovalDlg.cpp
  7. //
  8. // Contents: Implementation of CAddApprovalDlg
  9. //
  10. //----------------------------------------------------------------------------
  11. // AddApprovalDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "certtmpl.h"
  15. #include "AddApprovalDlg.h"
  16. #include "PolicyOID.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. extern POLICY_OID_LIST g_policyOIDList;
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CAddApprovalDlg dialog
  25. CAddApprovalDlg::CAddApprovalDlg(CWnd* pParent, const PSTR* paszUsedApprovals)
  26. : CHelpDialog(CAddApprovalDlg::IDD, pParent),
  27. m_paszReturnedApprovals (0),
  28. m_paszUsedApprovals (paszUsedApprovals)
  29. {
  30. //{{AFX_DATA_INIT(CAddApprovalDlg)
  31. //}}AFX_DATA_INIT
  32. }
  33. CAddApprovalDlg::~CAddApprovalDlg()
  34. {
  35. if ( m_paszReturnedApprovals )
  36. {
  37. for (int nIndex = 0; m_paszReturnedApprovals[nIndex]; nIndex++)
  38. delete [] m_paszReturnedApprovals[nIndex];
  39. delete [] m_paszReturnedApprovals;
  40. }
  41. }
  42. void CAddApprovalDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CHelpDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CAddApprovalDlg)
  46. DDX_Control(pDX, IDC_APPROVAL_LIST, m_issuanceList);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CAddApprovalDlg, CHelpDialog)
  50. //{{AFX_MSG_MAP(CAddApprovalDlg)
  51. ON_LBN_SELCHANGE(IDC_APPROVAL_LIST, OnSelchangeApprovalList)
  52. ON_LBN_DBLCLK(IDC_APPROVAL_LIST, OnDblclkApprovalList)
  53. //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CAddApprovalDlg message handlers
  57. BOOL CAddApprovalDlg::OnInitDialog()
  58. {
  59. CHelpDialog::OnInitDialog();
  60. for (POSITION nextPos = g_policyOIDList.GetHeadPosition (); nextPos; )
  61. {
  62. CPolicyOID* pPolicyOID = g_policyOIDList.GetNext (nextPos);
  63. if ( pPolicyOID )
  64. {
  65. // If this is the Application OID dialog, show only application
  66. // OIDS, otherwise if this is the Issuance OID dialog, show only
  67. // issuance OIDs
  68. if ( pPolicyOID->IsIssuanceOID () )
  69. {
  70. bool bFound = false;
  71. // Don't display an approval that's already been used
  72. if ( m_paszUsedApprovals )
  73. {
  74. for (int nIndex = 0; m_paszUsedApprovals[nIndex]; nIndex++)
  75. {
  76. if ( !strcmp (pPolicyOID->GetOIDA (), m_paszUsedApprovals[nIndex]) )
  77. {
  78. bFound = true;
  79. break;
  80. }
  81. }
  82. }
  83. if ( !bFound )
  84. {
  85. int nIndex = m_issuanceList.AddString (pPolicyOID->GetDisplayName ());
  86. if ( nIndex >= 0 )
  87. {
  88. // security review 2/21/2002 BryanWal ok
  89. LPSTR pszOID = new char[strlen (pPolicyOID->GetOIDA ())+1];
  90. if ( pszOID )
  91. {
  92. strcpy (pszOID, pPolicyOID->GetOIDA ());
  93. m_issuanceList.SetItemDataPtr (nIndex, pszOID);
  94. }
  95. else
  96. break;
  97. }
  98. }
  99. }
  100. }
  101. }
  102. return TRUE; // return TRUE unless you set the focus to a control
  103. // EXCEPTION: OCX Property Pages should return FALSE
  104. }
  105. void CAddApprovalDlg::EnableControls()
  106. {
  107. GetDlgItem (IDOK)->EnableWindow (m_issuanceList.GetSelCount () > 0);
  108. }
  109. void CAddApprovalDlg::OnOK()
  110. {
  111. int nSelectedCnt = m_issuanceList.GetSelCount ();
  112. // allocate an array of PSTR pointers and set each item to an approval.
  113. // Set the last to NULL
  114. if ( nSelectedCnt )
  115. {
  116. int* pnSelItems = new int[nSelectedCnt];
  117. if ( pnSelItems )
  118. {
  119. if ( LB_ERR != m_issuanceList.GetSelItems (nSelectedCnt, pnSelItems) )
  120. {
  121. m_paszReturnedApprovals = new PSTR[nSelectedCnt+1];
  122. if ( m_paszReturnedApprovals )
  123. {
  124. // security review 2/21/2002 BryanWal ok
  125. ::ZeroMemory (m_paszReturnedApprovals, sizeof (PSTR) * (nSelectedCnt+1));
  126. for (int nIndex = 0; nIndex < nSelectedCnt; nIndex++)
  127. {
  128. PSTR pszPolicyOID = (PSTR) m_issuanceList.GetItemData (pnSelItems[nIndex]);
  129. if ( pszPolicyOID )
  130. {
  131. // security review 2/21/2002 BryanWal ok
  132. PSTR pNewStr = new char[strlen (pszPolicyOID) + 1];
  133. if ( pNewStr )
  134. {
  135. // security review 2/21/2002 BryanWal ok
  136. strcpy (pNewStr, pszPolicyOID);
  137. m_paszReturnedApprovals[nIndex] = pNewStr;
  138. }
  139. else
  140. break;
  141. }
  142. }
  143. }
  144. }
  145. delete [] pnSelItems;
  146. }
  147. }
  148. CHelpDialog::OnOK();
  149. }
  150. bool CAddApprovalDlg::ApprovalAlreadyUsed(PCSTR pszOID) const
  151. {
  152. bool bResult = false;
  153. if ( m_paszUsedApprovals )
  154. {
  155. for (int nIndex = 0; m_paszUsedApprovals[nIndex]; nIndex++)
  156. {
  157. if ( !strcmp (m_paszUsedApprovals[nIndex], pszOID) )
  158. {
  159. bResult = true;
  160. break;
  161. }
  162. }
  163. }
  164. return bResult;
  165. }
  166. void CAddApprovalDlg::DoContextHelp (HWND hWndControl)
  167. {
  168. _TRACE(1, L"Entering CAddApprovalDlg::DoContextHelp\n");
  169. switch (::GetDlgCtrlID (hWndControl))
  170. {
  171. case IDC_STATIC:
  172. break;
  173. default:
  174. // Display context help for a control
  175. if ( !::WinHelp (
  176. hWndControl,
  177. GetContextHelpFile (),
  178. HELP_WM_HELP,
  179. (DWORD_PTR) g_aHelpIDs_IDD_ADD_APPROVAL) )
  180. {
  181. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  182. }
  183. break;
  184. }
  185. _TRACE(-1, L"Leaving CAddApprovalDlg::DoContextHelp\n");
  186. }
  187. void CAddApprovalDlg::OnSelchangeApprovalList()
  188. {
  189. EnableControls ();
  190. }
  191. void CAddApprovalDlg::OnDblclkApprovalList()
  192. {
  193. OnOK ();
  194. }