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.

233 lines
6.8 KiB

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