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.

190 lines
5.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 2002
  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, 55 },
  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. // NTRAID# 423366 DS Admin snapin - Name Mappings UI doesn't show issuer names correctly sometimes
  77. if ( !pszIssuer )
  78. pszIssuer = PchFindSimAttribute(pargzpsz, szSimIssuer, _T("CN="));
  79. // Finally, add the strings to the listview
  80. CString strSubject = m_strAnySubject;
  81. CString strIssuer = m_strAnyTrustedAuthority;
  82. if (pszSubject != NULL)
  83. strSimToUi(IN pszSubject, OUT &strSubject);
  84. if (pszIssuer != NULL)
  85. strSimToUi(IN pszIssuer, OUT &strIssuer);
  86. const LPCTSTR rgzpsz[] = { strSubject, strIssuer, NULL };
  87. ListView_AddStrings(m_hwndListview, IN rgzpsz, (LPARAM)pSimEntry);
  88. delete pargzpsz;
  89. } // AddSimEntry()
  90. BEGIN_MESSAGE_MAP(CSimX509PropPage, CSimPropPage)
  91. //{{AFX_MSG_MAP(CSimX509PropPage)
  92. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  93. ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
  94. //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96. void CSimX509PropPage::OnButtonAdd()
  97. {
  98. CThemeContextActivator activator;
  99. CString strFullPath;
  100. if (!UiGetCertificateFile(OUT &strFullPath))
  101. return;
  102. CCertificate cer;
  103. if (!cer.FLoadCertificate(strFullPath))
  104. return;
  105. CSimCertificateDlg dlg;
  106. dlg.m_uStringIdCaption = IDS_SIM_ADD_CERTIFICATE;
  107. cer.GetSimString(OUT &dlg.m_strData);
  108. if (IDOK != dlg.DoModal())
  109. return;
  110. CSimEntry * pSimEntry = m_pData->PAddSimEntry(dlg.m_strData);
  111. UpdateData(FALSE);
  112. ListView_SelectLParam(m_hwndListview, (LPARAM)pSimEntry);
  113. SetDirty();
  114. }
  115. void CSimX509PropPage::OnButtonEdit()
  116. {
  117. CThemeContextActivator activator;
  118. int iItem;
  119. CSimEntry * pSimEntry = (CSimEntry *)ListView_GetItemLParam(m_hwndListview, -1, OUT &iItem);
  120. if (pSimEntry == NULL || iItem < 0)
  121. {
  122. // No item selected
  123. return;
  124. }
  125. CSimCertificateDlg dlg;
  126. dlg.m_strData = pSimEntry->PchGetString();
  127. if (IDOK != dlg.DoModal())
  128. return;
  129. pSimEntry->SetString(dlg.m_strData);
  130. UpdateData(FALSE);
  131. ListView_SelectLParam(m_hwndListview, (LPARAM)pSimEntry);
  132. SetDirty();
  133. }
  134. BOOL CSimX509PropPage::OnApply()
  135. {
  136. if (!m_pData->FOnApply( GetSafeHwnd() ))
  137. {
  138. // Unable to write the information
  139. return FALSE;
  140. }
  141. UpdateData(FALSE);
  142. UpdateUI();
  143. return CPropertyPage::OnApply();
  144. }
  145. void CSimX509PropPage::DoContextHelp (HWND hWndControl)
  146. {
  147. TRACE0 ("Entering CSimX509PropPage::DoContextHelp\n");
  148. static const DWORD help_map[] =
  149. {
  150. IDC_EDIT_USER_ACCOUNT, IDH_EDIT_USER_ACCOUNT,
  151. IDC_LISTVIEW, IDH_LISTVIEW_X509,
  152. IDC_BUTTON_ADD, IDH_BUTTON_ADD,
  153. IDC_BUTTON_EDIT, IDH_BUTTON_EDIT,
  154. IDC_BUTTON_REMOVE, IDH_BUTTON_REMOVE,
  155. IDCANCEL, IDH_BUTTON_REMOVE, //IDH_CANCEL_BUTTON,
  156. IDOK, IDH_BUTTON_REMOVE, //IDH_OK_BUTTON,
  157. 0, 0
  158. };
  159. // Display context help for a control
  160. if ( !::WinHelp (
  161. hWndControl,
  162. DSADMIN_CONTEXT_HELP_FILE,
  163. HELP_WM_HELP,
  164. (DWORD_PTR) help_map) )
  165. {
  166. TRACE1 ("WinHelp () failed: 0x%x\n", GetLastError ());
  167. }
  168. TRACE0 ("Leaving CSimX509PropPage::DoContextHelp\n");
  169. }