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.

183 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: simprop1.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // SimProp1.cpp
  11. #include "stdafx.h"
  12. #include "common.h"
  13. #include "helpids.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. const TColumnHeaderItem rgzColumnHeader[] =
  20. {
  21. { IDS_SIM_CERTIFICATE_FOR, 45 },
  22. { IDS_SIM_ISSUED_BY, 45 },
  23. { 0, 0 },
  24. };
  25. /////////////////////////////////////////////////////////////////////////////
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CSimX509PropPage property page
  28. // IMPLEMENT_DYNCREATE(CSimX509PropPage, CSimPropPage)
  29. CSimX509PropPage::CSimX509PropPage() : CSimPropPage(CSimX509PropPage::IDD)
  30. {
  31. //{{AFX_DATA_INIT(CSimX509PropPage)
  32. // NOTE: the ClassWizard will add member initialization here
  33. //}}AFX_DATA_INIT
  34. m_prgzColumnHeader = rgzColumnHeader;
  35. VERIFY( m_strAnySubject.LoadString(IDS_SIM_ANY_SUBJECT) );
  36. VERIFY( m_strAnyTrustedAuthority.LoadString(IDS_SIM_ANY_TRUSTED_AUTHORITY) );
  37. }
  38. CSimX509PropPage::~CSimX509PropPage()
  39. {
  40. }
  41. void CSimX509PropPage::DoDataExchange(CDataExchange* pDX)
  42. {
  43. ASSERT(m_pData != NULL);
  44. CSimPropPage::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CSimX509PropPage)
  46. // NOTE: the ClassWizard will add DDX and DDV calls here
  47. //}}AFX_DATA_MAP
  48. if (!pDX->m_bSaveAndValidate)
  49. {
  50. // Fill in the listview
  51. ListView_DeleteAllItems(m_hwndListview);
  52. for (CSimEntry * pSimEntry = m_pData->m_pSimEntryList;
  53. pSimEntry != NULL;
  54. pSimEntry = pSimEntry->m_pNext)
  55. {
  56. AddSimEntry(pSimEntry);
  57. } // for
  58. ListView_SelectItem(m_hwndListview, 0);
  59. } // if
  60. } // DoDataExchange()
  61. /////////////////////////////////////////////////////////////////////
  62. void CSimX509PropPage::AddSimEntry(CSimEntry * pSimEntry)
  63. {
  64. ASSERT(pSimEntry != NULL);
  65. if (pSimEntry->m_eDialogTarget != eX509)
  66. return;
  67. LPTSTR * pargzpsz; // Pointer to allocated array of pointer to strings
  68. pargzpsz = ParseSimString(pSimEntry->PchGetString());
  69. if (pargzpsz == NULL)
  70. return; // Error parsing string
  71. ASSERT(0 == lstrcmpi(pargzpsz[0], szX509));
  72. // Find out the Subject
  73. LPCTSTR pszSubject = PchFindSimAttribute(pargzpsz, szSimSubject, _T("CN="));
  74. // Find out the Issuer
  75. LPCTSTR pszIssuer = PchFindSimAttribute(pargzpsz, szSimIssuer, _T("OU="));
  76. // Finally, add the strings to the listview
  77. CString strSubject = m_strAnySubject;
  78. CString strIssuer = m_strAnyTrustedAuthority;
  79. if (pszSubject != NULL)
  80. strSimToUi(IN pszSubject, OUT &strSubject);
  81. if (pszIssuer != NULL)
  82. strSimToUi(IN pszIssuer, OUT &strIssuer);
  83. const LPCTSTR rgzpsz[] = { strSubject, strIssuer, NULL };
  84. ListView_AddStrings(m_hwndListview, IN rgzpsz, (LPARAM)pSimEntry);
  85. delete pargzpsz;
  86. } // AddSimEntry()
  87. BEGIN_MESSAGE_MAP(CSimX509PropPage, CSimPropPage)
  88. //{{AFX_MSG_MAP(CSimX509PropPage)
  89. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  90. ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  91. //}}AFX_MSG_MAP
  92. END_MESSAGE_MAP()
  93. void CSimX509PropPage::OnButtonAdd()
  94. {
  95. CString strFullPath;
  96. if (!UiGetCertificateFile(OUT &strFullPath))
  97. return;
  98. CCertificate cer;
  99. if (!cer.FLoadCertificate(strFullPath))
  100. return;
  101. CSimCertificateDlg dlg;
  102. dlg.m_uStringIdCaption = IDS_SIM_ADD_CERTIFICATE;
  103. cer.GetSimString(OUT &dlg.m_strData);
  104. if (IDOK != dlg.DoModal())
  105. return;
  106. CSimEntry * pSimEntry = m_pData->PAddSimEntry(dlg.m_strData);
  107. UpdateData(FALSE);
  108. ListView_SelectLParam(m_hwndListview, (LPARAM)pSimEntry);
  109. SetDirty();
  110. }
  111. void CSimX509PropPage::OnButtonEdit()
  112. {
  113. int iItem;
  114. CSimEntry * pSimEntry = (CSimEntry *)ListView_GetItemLParam(m_hwndListview, -1, OUT &iItem);
  115. if (pSimEntry == NULL || iItem < 0)
  116. {
  117. // No item selected
  118. return;
  119. }
  120. CSimCertificateDlg dlg;
  121. dlg.m_strData = pSimEntry->PchGetString();
  122. if (IDOK != dlg.DoModal())
  123. return;
  124. pSimEntry->SetString(dlg.m_strData);
  125. UpdateData(FALSE);
  126. ListView_SelectLParam(m_hwndListview, (LPARAM)pSimEntry);
  127. SetDirty();
  128. }
  129. BOOL CSimX509PropPage::OnApply()
  130. {
  131. if (!m_pData->FOnApply( GetSafeHwnd() ))
  132. {
  133. // Unable to write the information
  134. return FALSE;
  135. }
  136. UpdateData(FALSE);
  137. UpdateUI();
  138. return CPropertyPage::OnApply();
  139. }
  140. void CSimX509PropPage::DoContextHelp (HWND hWndControl)
  141. {
  142. TRACE0 ("Entering CSimX509PropPage::DoContextHelp\n");
  143. static const DWORD help_map[] =
  144. {
  145. IDC_EDIT_USER_ACCOUNT, IDH_EDIT_USER_ACCOUNT,
  146. IDC_LISTVIEW, IDH_LISTVIEW_X509,
  147. IDC_BUTTON_ADD, IDH_BUTTON_ADD,
  148. IDC_BUTTON_EDIT, IDH_BUTTON_EDIT,
  149. IDC_BUTTON_REMOVE, IDH_BUTTON_REMOVE,
  150. IDCANCEL, IDH_BUTTON_REMOVE, //IDH_CANCEL_BUTTON,
  151. IDOK, IDH_BUTTON_REMOVE, //IDH_OK_BUTTON,
  152. 0, 0
  153. };
  154. // Display context help for a control
  155. if ( !::WinHelp (
  156. hWndControl,
  157. DSADMIN_CONTEXT_HELP_FILE,
  158. HELP_WM_HELP,
  159. (DWORD_PTR) help_map) )
  160. {
  161. TRACE1 ("WinHelp () failed: 0x%x\n", GetLastError ());
  162. }
  163. TRACE0 ("Leaving CSimX509PropPage::DoContextHelp\n");
  164. }