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.

284 lines
8.2 KiB

  1. // ChooseServerSite.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "certwiz.h"
  5. #include "Certificat.h"
  6. #include "CertUtil.h"
  7. #include "ChooseServerSite.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. #define COL_SITE_INSTANCE 0
  14. #define COL_SITE_DESC 1
  15. #define COL_SITE_INSTANCE_WID 50
  16. #define COL_SITE_DESC_WID 100
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CChooseServerSite
  19. CChooseServerSite::CChooseServerSite(BOOL bShowOnlyCertSites, CString& strSiteReturned,CCertificate * pCert,IN CWnd * pParent OPTIONAL)
  20. : CDialog(CChooseServerSite::IDD,pParent)
  21. {
  22. m_ShowOnlyCertSites = bShowOnlyCertSites;
  23. m_strSiteReturned = strSiteReturned;
  24. m_pCert = pCert;
  25. //{{AFX_DATA_INIT(CChooseServerSite)
  26. //}}AFX_DATA_INIT
  27. }
  28. CChooseServerSite::~CChooseServerSite()
  29. {
  30. }
  31. void CChooseServerSite::DoDataExchange(CDataExchange* pDX)
  32. {
  33. CDialog::DoDataExchange(pDX);
  34. //{{AFX_DATA_MAP(CChooseServerSite)
  35. DDX_Control(pDX, IDC_SITE_LIST, m_ServerSiteList);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CChooseServerSite, CDialog)
  39. //{{AFX_MSG_MAP(CChooseServerSite)
  40. ON_NOTIFY(NM_CLICK, IDC_SITE_LIST, OnClickSiteList)
  41. ON_NOTIFY(NM_DBLCLK, IDC_SITE_LIST, OnDblClickSiteList)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CChooseServerSite message handlers
  46. BOOL CChooseServerSite::OnInitDialog()
  47. {
  48. CDialog::OnInitDialog();
  49. HRESULT hr;
  50. CString MachineName_Remote;
  51. CString UserName_Remote;
  52. CString UserPassword_Remote;
  53. CMapStringToString MetabaseSiteKeyWithSiteDescValueList;
  54. CStringListEx strlDataPaths;
  55. CCertListCtrl* pControl = (CCertListCtrl *)CWnd::FromHandle(GetDlgItem(IDC_SITE_LIST)->m_hWnd);
  56. CRect rcControl;
  57. pControl->GetClientRect(&rcControl);
  58. // make the list have column headers
  59. CString str;
  60. str= _T("");
  61. str.LoadString(IDS_SITE_NUM_COLUMN);
  62. m_ServerSiteList.InsertColumn(COL_SITE_INSTANCE, str, LVCFMT_LEFT, COL_SITE_INSTANCE_WID);
  63. str.LoadString(IDS_WEB_SITE_COLUMN);
  64. m_ServerSiteList.InsertColumn(COL_SITE_DESC, str, LVCFMT_LEFT, rcControl.Width() - COL_SITE_INSTANCE_WID);
  65. m_ServerSiteList.AdjustStyle();
  66. // Use machine/username/userpassword
  67. // to connect to the machine
  68. // and enumerate all the sites on that machine.
  69. // return back a string1=string2 pair
  70. // string1 = /w3svc/1
  71. // string2 = "site description"
  72. // present a dialog so the user can choose which one they want...
  73. // m_ServerSiteInstance = /w3svc/1
  74. // m_ServerSiteDescription = "site description"
  75. MachineName_Remote = m_pCert->m_MachineName_Remote;
  76. UserName_Remote = m_pCert->m_UserName_Remote;
  77. UserPassword_Remote = m_pCert->m_UserPassword_Remote;
  78. if (m_ShowOnlyCertSites)
  79. {
  80. hr = EnumSitesWithCertInstalled(MachineName_Remote,UserName_Remote,UserPassword_Remote,&strlDataPaths);
  81. }
  82. else
  83. {
  84. hr = EnumSites(MachineName_Remote,UserName_Remote,UserPassword_Remote,&strlDataPaths);
  85. }
  86. if (strlDataPaths.IsEmpty())
  87. {
  88. //IISDebugOutput(_T("strlDataPaths IsEmpty()!!!!!!\n"));
  89. }
  90. else
  91. {
  92. POSITION pos;
  93. CString name;
  94. CString value = _T("");
  95. CString SiteInstance;
  96. int item = 0;
  97. LV_ITEMW lvi;
  98. //
  99. // set up the fields in the list view item struct that don't change from item to item
  100. //
  101. memset(&lvi, 0, sizeof(LV_ITEMW));
  102. lvi.mask = LVIF_TEXT;
  103. // loop thru the list and display all the stuff on a dialog box...
  104. pos = strlDataPaths.GetHeadPosition();
  105. while (pos)
  106. {
  107. int i = 0;
  108. name = strlDataPaths.GetAt(pos);
  109. value = _T("");
  110. SiteInstance.Format(_T("%d"), CMetabasePath::GetInstanceNumber(name));
  111. lvi.iItem = item;
  112. lvi.iSubItem = COL_SITE_INSTANCE;
  113. lvi.pszText = (LPTSTR)(LPCTSTR)SiteInstance;
  114. lvi.cchTextMax = SiteInstance.GetLength();
  115. i = m_ServerSiteList.InsertItem(&lvi);
  116. ASSERT(i != -1);
  117. lvi.iItem = i;
  118. lvi.iSubItem = COL_SITE_DESC;
  119. lvi.pszText = (LPTSTR)(LPCTSTR)value;
  120. lvi.cchTextMax = value.GetLength();
  121. VERIFY(m_ServerSiteList.SetItem(&lvi));
  122. // set item data with the pointer to the Strings
  123. CString * pDataItemString = new CString(name);
  124. VERIFY(m_ServerSiteList.SetItemData(item, (LONG_PTR)pDataItemString));
  125. item++;
  126. strlDataPaths.GetNext(pos);
  127. }
  128. FillListWithMetabaseSiteDesc();
  129. }
  130. return TRUE;
  131. }
  132. BOOL CChooseServerSite::FillListWithMetabaseSiteDesc()
  133. {
  134. int count = m_ServerSiteList.GetItemCount();
  135. CString strMetabaseKey;
  136. CString value = _T("");
  137. CString strDescription;
  138. HRESULT hr = E_FAIL;
  139. CString MachineName_Remote;
  140. CString UserName_Remote;
  141. CString UserPassword_Remote;
  142. MachineName_Remote = m_pCert->m_MachineName_Remote;
  143. UserName_Remote = m_pCert->m_UserName_Remote;
  144. UserPassword_Remote = m_pCert->m_UserPassword_Remote;
  145. CString * pMetabaseKey;
  146. for (int index = 0; index < count; index++)
  147. {
  148. pMetabaseKey = (CString *) m_ServerSiteList.GetItemData(index);
  149. if (pMetabaseKey)
  150. {
  151. strMetabaseKey = *pMetabaseKey;
  152. // Go get the site's description;
  153. if (TRUE == GetServerComment(MachineName_Remote,UserName_Remote,UserPassword_Remote,strMetabaseKey,strDescription,&hr))
  154. {
  155. value = strDescription;
  156. }
  157. else
  158. {
  159. value = strMetabaseKey;
  160. }
  161. m_ServerSiteList.SetItemText(index, COL_SITE_DESC,value);
  162. }
  163. }
  164. return TRUE;
  165. }
  166. void CChooseServerSite::OnDblClickSiteList(NMHDR* pNMHDR, LRESULT* pResult)
  167. {
  168. // Get the hash for the certificate that is clicked on...
  169. m_Index = m_ServerSiteList.GetSelectedIndex();
  170. if (m_Index != -1)
  171. {
  172. // Get the metabase key..
  173. CString * pMetabaseKey = NULL;
  174. pMetabaseKey = (CString *) m_ServerSiteList.GetItemData(m_Index);
  175. if (pMetabaseKey)
  176. {
  177. m_strSiteReturned = *pMetabaseKey;
  178. // use the metabase key to lookup the hash
  179. // find cert in store
  180. CRYPT_HASH_BLOB * pHash = NULL;
  181. HRESULT hr;
  182. // go lookup the certhash from the metabase
  183. if (0 == _tcsicmp(m_pCert->m_MachineName_Remote,m_pCert->m_MachineName))
  184. {
  185. pHash = GetInstalledCertHash(m_pCert->m_MachineName_Remote,m_strSiteReturned,m_pCert->GetEnrollObject(),&hr);
  186. if (pHash)
  187. {
  188. ViewCertificateDialog(pHash,m_hWnd);
  189. if (pHash){CoTaskMemFree(pHash);}
  190. }
  191. }
  192. }
  193. }
  194. return;
  195. }
  196. void CChooseServerSite::OnOK()
  197. {
  198. m_Index = m_ServerSiteList.GetSelectedIndex();
  199. m_strSiteReturned = _T("");
  200. if (m_Index != -1)
  201. {
  202. CString * pMetabaseKey = NULL;
  203. pMetabaseKey = (CString *) m_ServerSiteList.GetItemData(m_Index);
  204. if (pMetabaseKey)
  205. {
  206. m_strSiteReturned = *pMetabaseKey;
  207. if (m_ShowOnlyCertSites)
  208. {
  209. // check if the returned site has an exportable certificate on it...
  210. if (FALSE == IsCertExportableOnRemoteMachine(m_pCert->m_MachineName_Remote,m_pCert->m_UserName_Remote,m_pCert->m_UserPassword_Remote,m_strSiteReturned))
  211. {
  212. // tell the user that certificat that they chose is not exportable.
  213. CString buf;
  214. buf.LoadString(IDS_CERT_NOT_EXPORTABLE);
  215. AfxMessageBox(buf, MB_OK);
  216. return;
  217. }
  218. }
  219. }
  220. }
  221. CDialog::OnOK();
  222. }
  223. void CChooseServerSite::OnClickSiteList(NMHDR* pNMHDR, LRESULT* pResult)
  224. {
  225. //SetWizardButtons(-1 == m_ServerSiteList.GetSelectedIndex() ? PSWIZB_BACK : PSWIZB_BACK | PSWIZB_NEXT);
  226. m_Index = m_ServerSiteList.GetSelectedIndex();
  227. *pResult = 0;
  228. }
  229. void CChooseServerSite::OnDestroy()
  230. {
  231. // before dialog will be desroyed we need to delete all
  232. // the item data pointers
  233. int count = m_ServerSiteList.GetItemCount();
  234. for (int index = 0; index < count; index++)
  235. {
  236. CString * pData = (CString *) m_ServerSiteList.GetItemData(index);
  237. delete pData;
  238. }
  239. CDialog::OnDestroy();
  240. }