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.

333 lines
8.2 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. #include "helpids.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. const TColumnHeaderItem rgzColumnHeaderCertificateProperties[] =
  25. {
  26. { IDS_SIM_ATTRIBUTE, 18 },
  27. { IDS_SIM_INFORMATION, 82 },
  28. { 0, 0 },
  29. };
  30. /////////////////////////////////////////////////////////////////////////////
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CSimCertificateDlg dialog
  33. CSimCertificateDlg::CSimCertificateDlg(CWnd* pParent /*=NULL*/)
  34. : CDialogEx(CSimCertificateDlg::IDD, pParent),
  35. m_fCheckSubjectChanged (false)
  36. {
  37. //{{AFX_DATA_INIT(CSimCertificateDlg)
  38. m_fCheckIssuer = TRUE;
  39. m_fCheckSubject = FALSE;
  40. //}}AFX_DATA_INIT
  41. m_uStringIdCaption = 0;
  42. }
  43. void CSimCertificateDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CSimCertificateDlg)
  47. DDX_Check(pDX, IDC_CHECK_ISSUER, m_fCheckIssuer);
  48. DDX_Check(pDX, IDC_CHECK_SUBJECT, m_fCheckSubject);
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CSimCertificateDlg, CDialog)
  52. //{{AFX_MSG_MAP(CSimCertificateDlg)
  53. ON_BN_CLICKED(IDC_CHECK_ISSUER, OnCheckIssuer)
  54. ON_BN_CLICKED(IDC_CHECK_SUBJECT, OnCheckSubject)
  55. //}}AFX_MSG_MAP
  56. ON_MESSAGE(WM_HELP, OnHelp)
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////
  59. BOOL CSimCertificateDlg::OnInitDialog()
  60. {
  61. if (m_uStringIdCaption)
  62. {
  63. CString strCaption;
  64. VERIFY( strCaption.LoadString(m_uStringIdCaption) );
  65. SetWindowText(strCaption);
  66. }
  67. m_hwndListview = ::GetDlgItem(m_hWnd, IDC_LISTVIEW);
  68. ListView_AddColumnHeaders(m_hwndListview, rgzColumnHeaderCertificateProperties);
  69. PopulateListview();
  70. CDialog::OnInitDialog();
  71. UpdateUI();
  72. return TRUE;
  73. }
  74. /////////////////////////////////////////////////////////////////////
  75. void CSimCertificateDlg::PopulateListview()
  76. {
  77. LPTSTR * pargzpsz = 0; // Pointer to allocated array of pointer to strings
  78. LPCTSTR * pargzpszIssuer = 0;
  79. LPCTSTR * pargzpszSubject = 0;
  80. pargzpsz = SplitX509String(
  81. IN m_strData,
  82. OUT &pargzpszIssuer,
  83. OUT &pargzpszSubject,
  84. 0);
  85. if (pargzpsz == NULL)
  86. {
  87. TRACE1("CSimCertificateDlg::PopulateListview() - Error parsing string %s.\n",
  88. (LPCTSTR)m_strData);
  89. return;
  90. }
  91. AddListviewItems(IDS_SIM_ISSUER, pargzpszIssuer);
  92. if ( !AddListviewItems(IDS_SIM_SUBJECT, pargzpszSubject) )
  93. {
  94. GetDlgItem (IDC_CHECK_SUBJECT)->EnableWindow (FALSE);
  95. }
  96. m_fCheckIssuer = pargzpszIssuer[0] != NULL;
  97. m_fCheckSubject = pargzpszSubject[0] != NULL;
  98. delete pargzpsz;
  99. delete pargzpszIssuer;
  100. delete pargzpszSubject;
  101. } // CSimCertificateDlg::PopulateListview()
  102. /////////////////////////////////////////////////////////////////////
  103. // Routine to add multiple listview items to make a fake tree.
  104. //
  105. bool CSimCertificateDlg::AddListviewItems(
  106. UINT uStringId, // Issuer, Subject, AltSubject
  107. LPCTSTR rgzpsz[]) // Array of pointer to strings
  108. {
  109. ASSERT(rgzpsz != NULL);
  110. if (rgzpsz[0] == NULL)
  111. return false; // Empty array
  112. CString str;
  113. VERIFY( str.LoadString(uStringId) );
  114. CString strUI;
  115. strSimToUi(IN rgzpsz[0], OUT &strUI);
  116. LPCTSTR rgzpszT[] = { str, strUI, NULL };
  117. ListView_AddStrings(m_hwndListview, rgzpszT, (LPARAM)uStringId);
  118. rgzpszT[0] = _T(" ");
  119. for (int i = 1; rgzpsz[i] != NULL; i++)
  120. {
  121. strSimToUi(IN rgzpsz[i], OUT &strUI);
  122. rgzpszT[1] = strUI;
  123. ListView_AddStrings(m_hwndListview, rgzpszT);
  124. }
  125. return true;
  126. } // CSimCertificateDlg::AddListviewItems()
  127. /////////////////////////////////////////////////////////////////////
  128. void
  129. CSimCertificateDlg::OnOK()
  130. {
  131. CThemeContextActivator activator;
  132. LPTSTR * pargzpsz; // Pointer to allocated array of pointer to strings
  133. LPCTSTR * pargzpszIssuer;
  134. LPCTSTR * pargzpszSubject;
  135. pargzpsz = SplitX509String(
  136. IN m_strData,
  137. OUT &pargzpszIssuer,
  138. OUT &pargzpszSubject,
  139. 0);
  140. if (pargzpsz == NULL)
  141. return;
  142. LPCTSTR * prgzpszIssuerT = m_fCheckIssuer ? pargzpszIssuer : NULL;
  143. LPCTSTR * prgzpszSubjectT = 0;
  144. if ( m_fCheckSubject )
  145. {
  146. prgzpszSubjectT = pargzpszSubject;
  147. }
  148. else
  149. {
  150. if ( m_fCheckSubjectChanged )
  151. {
  152. CString text;
  153. CString caption;
  154. VERIFY (caption.LoadString (IDS_DSSNAPINNAME));
  155. VERIFY (text.LoadString (IDS_SIM_REMOVING_SUBJECT_AS_ID));
  156. if ( IDNO == MessageBox (text, caption, MB_ICONWARNING | MB_YESNO) )
  157. {
  158. if (pargzpsz != NULL)
  159. {
  160. delete pargzpsz;
  161. pargzpsz = NULL;
  162. }
  163. if (pargzpszIssuer != NULL)
  164. {
  165. delete pargzpszIssuer;
  166. pargzpszIssuer = NULL;
  167. }
  168. if (pargzpszSubject != NULL)
  169. {
  170. delete pargzpszSubject;
  171. pargzpszSubject = NULL;
  172. }
  173. return;
  174. }
  175. }
  176. prgzpszSubjectT = NULL;
  177. }
  178. CString strDataT; // Temporary string to hold the value
  179. int cSeparators; // Number of separators added to the contatenated string
  180. cSeparators = UnsplitX509String(
  181. OUT &strDataT,
  182. IN prgzpszIssuerT,
  183. IN prgzpszSubjectT,
  184. 0);
  185. if (pargzpsz != NULL)
  186. {
  187. delete pargzpsz;
  188. pargzpsz = NULL;
  189. }
  190. if (pargzpszIssuer != NULL)
  191. {
  192. delete pargzpszIssuer;
  193. pargzpszIssuer = NULL;
  194. }
  195. if (pargzpszSubject != NULL)
  196. {
  197. delete pargzpszSubject;
  198. pargzpszSubject = NULL;
  199. }
  200. if (cSeparators == 0)
  201. {
  202. // The resulting does not contains anything useful
  203. ReportErrorEx (GetSafeHwnd(),IDS_SIM_ERR_INVALID_MAPPING,S_OK,
  204. MB_OK | MB_ICONERROR, NULL, 0);
  205. return;
  206. }
  207. // The string seems valid, so keep it
  208. m_strData = strDataT;
  209. CDialog::OnOK();
  210. } // CSimCertificateDlg::OnOK()
  211. /////////////////////////////////////////////////////////////////////
  212. void CSimCertificateDlg::UpdateUI()
  213. {
  214. CheckDlgButton(IDC_CHECK_SUBJECT, m_fCheckSubject);
  215. }
  216. /////////////////////////////////////////////////////////////////////
  217. void CSimCertificateDlg::RefreshUI()
  218. {
  219. ListView_DeleteAllItems(m_hwndListview);
  220. PopulateListview();
  221. UpdateData(FALSE);
  222. UpdateUI();
  223. }
  224. void CSimCertificateDlg::OnCheckIssuer()
  225. {
  226. m_fCheckIssuer = IsDlgButtonChecked(IDC_CHECK_ISSUER);
  227. UpdateUI();
  228. }
  229. void CSimCertificateDlg::OnCheckSubject()
  230. {
  231. m_fCheckSubject = IsDlgButtonChecked(IDC_CHECK_SUBJECT);
  232. m_fCheckSubjectChanged = true;
  233. UpdateUI();
  234. }
  235. BOOL CSimCertificateDlg::OnHelp(WPARAM, LPARAM lParam)
  236. {
  237. TRACE0 ("Entering CSimCertificateDlg::OnHelp\n");
  238. const LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  239. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  240. {
  241. DoContextHelp ((HWND) pHelpInfo->hItemHandle);
  242. }
  243. TRACE0 ("Leaving CSimCertificateDlg::OnHelp\n");
  244. return TRUE;
  245. }
  246. void CSimCertificateDlg::DoContextHelp (HWND hWndControl)
  247. {
  248. TRACE0 ("Entering CSimCertificateDlg::DoContextHelp\n");
  249. switch (::GetDlgCtrlID (hWndControl))
  250. {
  251. case IDC_STATIC:
  252. break;
  253. default:
  254. {
  255. static const DWORD help_map[] =
  256. {
  257. IDC_LISTVIEW, IDH_SIMCERT_LISTVIEW,
  258. IDC_CHECK_ISSUER, IDH_SIMCERT_CHECK_ISSUER,
  259. IDC_CHECK_SUBJECT, IDH_SIMCERT_CHECK_SUBJECT,
  260. 0, 0
  261. };
  262. // Display context help for a control
  263. if ( !::WinHelp (
  264. hWndControl,
  265. DSADMIN_CONTEXT_HELP_FILE,
  266. HELP_WM_HELP,
  267. (DWORD_PTR) help_map) )
  268. {
  269. TRACE1 ("WinHelp () failed: 0x%x\n", GetLastError ());
  270. }
  271. }
  272. return;
  273. }
  274. TRACE0 ("Leaving CSimCertificateDlg::DoContextHelp\n");
  275. }