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.

282 lines
6.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: simcert.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. /////////////////////////////////////////////////////////////////////
  11. // SimCert.cpp - Implementation of SIM Certificate Dialog
  12. //
  13. // HISTORY
  14. // 05-Jul-97 t-danm Creation.
  15. /////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "common.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. const TColumnHeaderItem rgzColumnHeaderCertificateProperties[] =
  24. {
  25. { IDS_SIM_ATTRIBUTE, 18 },
  26. { IDS_SIM_INFORMATION, 75 },
  27. { 0, 0 },
  28. };
  29. /////////////////////////////////////////////////////////////////////////////
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CSimCertificateDlg dialog
  32. CSimCertificateDlg::CSimCertificateDlg(CWnd* pParent /*=NULL*/)
  33. : CDialogEx(CSimCertificateDlg::IDD, pParent),
  34. m_fCheckSubjectChanged (false)
  35. {
  36. //{{AFX_DATA_INIT(CSimCertificateDlg)
  37. m_fCheckIssuer = TRUE;
  38. m_fCheckSubject = FALSE;
  39. //}}AFX_DATA_INIT
  40. m_uStringIdCaption = 0;
  41. }
  42. void CSimCertificateDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CSimCertificateDlg)
  46. DDX_Check(pDX, IDC_CHECK_ISSUER, m_fCheckIssuer);
  47. DDX_Check(pDX, IDC_CHECK_SUBJECT, m_fCheckSubject);
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CSimCertificateDlg, CDialog)
  51. //{{AFX_MSG_MAP(CSimCertificateDlg)
  52. ON_BN_CLICKED(IDC_CHECK_ISSUER, OnCheckIssuer)
  53. ON_BN_CLICKED(IDC_CHECK_SUBJECT, OnCheckSubject)
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////
  57. BOOL CSimCertificateDlg::OnInitDialog()
  58. {
  59. if (m_uStringIdCaption)
  60. {
  61. CString strCaption;
  62. VERIFY( strCaption.LoadString(m_uStringIdCaption) );
  63. SetWindowText(strCaption);
  64. }
  65. m_hwndListview = ::GetDlgItem(m_hWnd, IDC_LISTVIEW);
  66. ListView_AddColumnHeaders(m_hwndListview, rgzColumnHeaderCertificateProperties);
  67. PopulateListview();
  68. CDialog::OnInitDialog();
  69. UpdateUI();
  70. return TRUE;
  71. }
  72. /////////////////////////////////////////////////////////////////////
  73. void CSimCertificateDlg::PopulateListview()
  74. {
  75. LPTSTR * pargzpsz = 0; // Pointer to allocated array of pointer to strings
  76. LPCTSTR * pargzpszIssuer = 0;
  77. LPCTSTR * pargzpszSubject = 0;
  78. pargzpsz = SplitX509String(
  79. IN m_strData,
  80. OUT &pargzpszIssuer,
  81. OUT &pargzpszSubject,
  82. 0);
  83. if (pargzpsz == NULL)
  84. {
  85. TRACE1("CSimCertificateDlg::PopulateListview() - Error parsing string %s.\n",
  86. (LPCTSTR)m_strData);
  87. return;
  88. }
  89. AddListviewItems(IDS_SIM_ISSUER, pargzpszIssuer);
  90. if ( !AddListviewItems(IDS_SIM_SUBJECT, pargzpszSubject) )
  91. {
  92. GetDlgItem (IDC_CHECK_SUBJECT)->EnableWindow (FALSE);
  93. }
  94. m_fCheckIssuer = pargzpszIssuer[0] != NULL;
  95. m_fCheckSubject = pargzpszSubject[0] != NULL;
  96. delete pargzpsz;
  97. delete pargzpszIssuer;
  98. delete pargzpszSubject;
  99. } // CSimCertificateDlg::PopulateListview()
  100. /////////////////////////////////////////////////////////////////////
  101. // Routine to add multiple listview items to make a fake tree.
  102. //
  103. bool CSimCertificateDlg::AddListviewItems(
  104. UINT uStringId, // Issuer, Subject, AltSubject
  105. LPCTSTR rgzpsz[]) // Array of pointer to strings
  106. {
  107. ASSERT(rgzpsz != NULL);
  108. if (rgzpsz[0] == NULL)
  109. return false; // Empty array
  110. CString str;
  111. VERIFY( str.LoadString(uStringId) );
  112. CString strUI;
  113. strSimToUi(IN rgzpsz[0], OUT &strUI);
  114. LPCTSTR rgzpszT[] = { str, strUI, NULL };
  115. ListView_AddStrings(m_hwndListview, rgzpszT, (LPARAM)uStringId);
  116. rgzpszT[0] = _T(" ");
  117. for (int i = 1; rgzpsz[i] != NULL; i++)
  118. {
  119. strSimToUi(IN rgzpsz[i], OUT &strUI);
  120. rgzpszT[1] = strUI;
  121. ListView_AddStrings(m_hwndListview, rgzpszT);
  122. }
  123. return true;
  124. } // CSimCertificateDlg::AddListviewItems()
  125. /////////////////////////////////////////////////////////////////////
  126. void
  127. CSimCertificateDlg::OnOK()
  128. {
  129. LPTSTR * pargzpsz; // Pointer to allocated array of pointer to strings
  130. LPCTSTR * pargzpszIssuer;
  131. LPCTSTR * pargzpszSubject;
  132. pargzpsz = SplitX509String(
  133. IN m_strData,
  134. OUT &pargzpszIssuer,
  135. OUT &pargzpszSubject,
  136. 0);
  137. if (pargzpsz == NULL)
  138. return;
  139. LPCTSTR * prgzpszIssuerT = m_fCheckIssuer ? pargzpszIssuer : NULL;
  140. LPCTSTR * prgzpszSubjectT = 0;
  141. if ( m_fCheckSubject )
  142. {
  143. prgzpszSubjectT = pargzpszSubject;
  144. }
  145. else
  146. {
  147. if ( m_fCheckSubjectChanged )
  148. {
  149. CString text;
  150. CString caption;
  151. VERIFY (caption.LoadString (IDS_DSSNAPINNAME));
  152. VERIFY (text.LoadString (IDS_SIM_REMOVING_SUBJECT_AS_ID));
  153. if ( IDNO == MessageBox (text, caption, MB_ICONWARNING | MB_YESNO) )
  154. {
  155. if (pargzpsz != NULL)
  156. {
  157. delete pargzpsz;
  158. pargzpsz = NULL;
  159. }
  160. if (pargzpszIssuer != NULL)
  161. {
  162. delete pargzpszIssuer;
  163. pargzpszIssuer = NULL;
  164. }
  165. if (pargzpszSubject != NULL)
  166. {
  167. delete pargzpszSubject;
  168. pargzpszSubject = NULL;
  169. }
  170. return;
  171. }
  172. }
  173. prgzpszSubjectT = NULL;
  174. }
  175. CString strDataT; // Temporary string to hold the value
  176. int cSeparators; // Number of separators added to the contatenated string
  177. cSeparators = UnsplitX509String(
  178. OUT &strDataT,
  179. IN prgzpszIssuerT,
  180. IN prgzpszSubjectT,
  181. 0);
  182. if (pargzpsz != NULL)
  183. {
  184. delete pargzpsz;
  185. pargzpsz = NULL;
  186. }
  187. if (pargzpszIssuer != NULL)
  188. {
  189. delete pargzpszIssuer;
  190. pargzpszIssuer = NULL;
  191. }
  192. if (pargzpszSubject != NULL)
  193. {
  194. delete pargzpszSubject;
  195. pargzpszSubject = NULL;
  196. }
  197. if (cSeparators == 0)
  198. {
  199. // The resulting does not contains anything useful
  200. ReportErrorEx (GetSafeHwnd(),IDS_SIM_ERR_INVALID_MAPPING,S_OK,
  201. MB_OK | MB_ICONERROR, NULL, 0);
  202. return;
  203. }
  204. // The string seems valid, so keep it
  205. m_strData = strDataT;
  206. CDialog::OnOK();
  207. } // CSimCertificateDlg::OnOK()
  208. /////////////////////////////////////////////////////////////////////
  209. void CSimCertificateDlg::UpdateUI()
  210. {
  211. CheckDlgButton(IDC_CHECK_SUBJECT, m_fCheckSubject);
  212. }
  213. /////////////////////////////////////////////////////////////////////
  214. void CSimCertificateDlg::RefreshUI()
  215. {
  216. ListView_DeleteAllItems(m_hwndListview);
  217. PopulateListview();
  218. UpdateData(FALSE);
  219. UpdateUI();
  220. }
  221. void CSimCertificateDlg::OnCheckIssuer()
  222. {
  223. m_fCheckIssuer = IsDlgButtonChecked(IDC_CHECK_ISSUER);
  224. UpdateUI();
  225. }
  226. void CSimCertificateDlg::OnCheckSubject()
  227. {
  228. m_fCheckSubject = IsDlgButtonChecked(IDC_CHECK_SUBJECT);
  229. m_fCheckSubjectChanged = true;
  230. UpdateUI();
  231. }