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.

295 lines
9.2 KiB

  1. // OcarptMain.h : Declaration of the COcarptMain
  2. #ifndef __OCARPTMAIN_H_
  3. #define __OCARPTMAIN_H_
  4. #include "resource.h" // main symbols
  5. #include <atlctl.h>
  6. #include <time.h>
  7. #include "inetupld.h"
  8. #include <exdisp.h>
  9. #include <shlguid.h>
  10. #include <strsafe.h>
  11. #define _USE_WINHTTP 1
  12. #ifdef _USE_WINHTTP
  13. #include <winhttp.h>
  14. #include <winhttpi.h>
  15. #define MAX_URL_LENGTH 2176
  16. #else
  17. #include <wininet.h>
  18. #define MAX_URL_LENGTH INTERNET_MAX_URL_LENGTH
  19. #endif // _USE_WINHTTP
  20. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  21. /////////////////////////////////////////////////////////////////////////////
  22. // COcarptMain
  23. class ATL_NO_VTABLE COcarptMain :
  24. public CComObjectRootEx<CComSingleThreadModel>,
  25. public IDispatchImpl<IOcarptMain, &IID_IOcarptMain, &LIBID_OCARPTLib>,
  26. public CComControl<COcarptMain>,
  27. public IPersistStreamInitImpl<COcarptMain>,
  28. public IOleControlImpl<COcarptMain>,
  29. public IOleObjectImpl<COcarptMain>,
  30. public IOleInPlaceActiveObjectImpl<COcarptMain>,
  31. public IViewObjectExImpl<COcarptMain>,
  32. public IOleInPlaceObjectWindowlessImpl<COcarptMain>,
  33. public IPersistStorageImpl<COcarptMain>,
  34. public ISpecifyPropertyPagesImpl<COcarptMain>,
  35. public IQuickActivateImpl<COcarptMain>,
  36. public IDataObjectImpl<COcarptMain>,
  37. public IProvideClassInfo2Impl<&CLSID_OcarptMain, NULL, &LIBID_OCARPTLib>,
  38. public CComCoClass<COcarptMain, &CLSID_OcarptMain>,
  39. public IObjectSafetyImpl<COcarptMain, INTERFACESAFE_FOR_UNTRUSTED_CALLER
  40. |INTERFACESAFE_FOR_UNTRUSTED_DATA>
  41. {
  42. public:
  43. COcarptMain()
  44. {
  45. m_pUploadFile = NULL;
  46. m_b_SetSiteCalled = FALSE;
  47. }
  48. DECLARE_REGISTRY_RESOURCEID(IDR_OCARPTMAIN)
  49. DECLARE_PROTECT_FINAL_CONSTRUCT()
  50. BEGIN_COM_MAP(COcarptMain)
  51. COM_INTERFACE_ENTRY(IOcarptMain)
  52. COM_INTERFACE_ENTRY(IDispatch)
  53. COM_INTERFACE_ENTRY(IViewObjectEx)
  54. COM_INTERFACE_ENTRY(IViewObject2)
  55. COM_INTERFACE_ENTRY(IViewObject)
  56. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  57. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  58. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  59. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  60. COM_INTERFACE_ENTRY(IOleControl)
  61. COM_INTERFACE_ENTRY(IOleObject)
  62. COM_INTERFACE_ENTRY(IPersistStreamInit)
  63. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  64. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  65. COM_INTERFACE_ENTRY(IQuickActivate)
  66. COM_INTERFACE_ENTRY(IPersistStorage)
  67. COM_INTERFACE_ENTRY(IDataObject)
  68. COM_INTERFACE_ENTRY(IProvideClassInfo)
  69. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  70. COM_INTERFACE_ENTRY(IObjectSafety)
  71. END_COM_MAP()
  72. BEGIN_PROP_MAP(COcarptMain)
  73. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  74. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  75. // Example entries
  76. // PROP_ENTRY("Property Description", dispid, clsid)
  77. // PROP_PAGE(CLSID_StockColorPage)
  78. END_PROP_MAP()
  79. BEGIN_MSG_MAP(COcarptMain)
  80. CHAIN_MSG_MAP(CComControl<COcarptMain>)
  81. DEFAULT_REFLECTION_HANDLER()
  82. END_MSG_MAP()
  83. // Handler prototypes:
  84. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  85. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  86. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  87. // IViewObjectEx
  88. DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
  89. // IOcarptMain
  90. public:
  91. STDMETHOD(RetrieveFileContents)(/*[in]*/BSTR *FileName, /*[out,retval]*/ VARIANT *pvContents);
  92. STDMETHOD(ValidateDump)(/*[in]*/ BSTR *FileName, /*[out,retval]*/VARIANT *Result);
  93. STDMETHOD(Browse)(/*[in]*/ BSTR *pbstrTitle, /*[in]*/BSTR *Lang, /*[out,retval]*/ VARIANT *Path);
  94. STDMETHOD(Search)(/*[out,retval]*/ VARIANT *pvFileList);
  95. STDMETHOD(Upload)(/*[in]*/ BSTR *SourceFile, /*[in]*/BSTR *DestFile, /*[in]*/BSTR *Langage, /*[in]*/ BSTR *OptionCode, /*[in]*/ int ConvertToMini, /*[out,retval]*/ VARIANT *ReturnCode);
  96. STDMETHOD(GetUploadStatus)(/*[out,retval]*/ VARIANT *PercentDone);
  97. STDMETHOD(GetUploadResult)(/*[out,retval]*/ VARIANT *UploadResult);
  98. STDMETHOD(CancelUpload)(/*[out,retval]*/ VARIANT *ReturnCode);
  99. HRESULT OnDraw(ATL_DRAWINFO& di)
  100. {
  101. RECT& rc = *(RECT*)di.prcBounds;
  102. Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  103. SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
  104. LPCTSTR pszText = _T("");
  105. TextOut(di.hdcDraw,
  106. (rc.left + rc.right) / 2,
  107. (rc.top + rc.bottom) / 2,
  108. pszText,
  109. lstrlen(pszText));
  110. return S_OK;
  111. }
  112. STDMETHODIMP SetClientSite (IOleClientSite *pClientSite)
  113. {
  114. _spUnkSite = pClientSite;
  115. m_b_SetSiteCalled = TRUE;
  116. return S_OK;
  117. }
  118. STDMETHODIMP GetSite (REFIID riid, LPVOID* ppvSite)
  119. {
  120. if (m_b_SetSiteCalled)
  121. return _spUnkSite->QueryInterface(riid,ppvSite);
  122. else
  123. return E_FAIL;
  124. }
  125. bool InApprovedDomain()
  126. {
  127. TCHAR ourUrl[MAX_URL_LENGTH];
  128. return true;
  129. if (!GetOurUrl(ourUrl, sizeof ourUrl))
  130. return false;
  131. return IsApprovedDomain(ourUrl);
  132. }
  133. bool GetOurUrl(TCHAR* pszURL, int cbBuf)
  134. {
  135. HRESULT hr;
  136. CComPtr<IServiceProvider> spSrvProv;
  137. CComPtr<IWebBrowser2> spWebBrowser;
  138. hr = GetSite(IID_IServiceProvider, (void**)&spSrvProv);
  139. if (FAILED(hr))
  140. return false;
  141. hr = spSrvProv->QueryService(SID_SWebBrowserApp,
  142. IID_IWebBrowser2,
  143. (void**)&spWebBrowser);
  144. if (FAILED(hr))
  145. return false;
  146. CComBSTR bstrURL;
  147. if (FAILED(spWebBrowser->get_LocationURL(&bstrURL)))
  148. return false;
  149. #ifdef UNICODE
  150. StringCbCopy(pszURL, cbBuf, bstrURL);
  151. #else
  152. WideCharToMultiByte(CP_ACP, 0, bstrURL, -1, pszURL, cbBuf,
  153. NULL, NULL);
  154. #endif
  155. return true;
  156. }
  157. bool IsApprovedDomain(TCHAR* ourUrl)
  158. {
  159. // Only allow http access.
  160. // You can change this to allow file:// access.
  161. //
  162. if (GetScheme(ourUrl) != INTERNET_SCHEME_HTTPS)
  163. return false;
  164. TCHAR ourDomain[256];
  165. if (!GetDomain(ourUrl, ourDomain, sizeof(ourDomain)))
  166. return false;
  167. for (int i = 0; i < ARRAYSIZE(_approvedDomains); i++)
  168. {
  169. if (MatchDomains(const_cast<TCHAR*>(_approvedDomains[i]),
  170. ourDomain))
  171. {
  172. return true;
  173. }
  174. }
  175. return false;
  176. }
  177. INTERNET_SCHEME GetScheme(TCHAR* url)
  178. {
  179. TCHAR buf[32];
  180. URL_COMPONENTS uc;
  181. ZeroMemory(&uc, sizeof uc);
  182. uc.dwStructSize = sizeof uc;
  183. uc.lpszScheme = buf;
  184. uc.dwSchemeLength = sizeof buf;
  185. #ifdef _USE_WINHTTP
  186. if (WinHttpCrackUrl(url, lstrlen(url), ICU_DECODE, &uc))
  187. #else
  188. if (InternetCrackUrl(url, lstrlen(url), ICU_DECODE, &uc))
  189. #endif
  190. return uc.nScheme;
  191. else
  192. return INTERNET_SCHEME_UNKNOWN;
  193. }
  194. bool GetDomain(TCHAR* url, TCHAR* buf, int cbBuf)
  195. {
  196. URL_COMPONENTS uc;
  197. ZeroMemory(&uc, sizeof uc);
  198. uc.dwStructSize = sizeof uc;
  199. uc.lpszHostName = buf;
  200. uc.dwHostNameLength = cbBuf;
  201. #ifdef _USE_WINHTTP
  202. return (WinHttpCrackUrl(url, lstrlen(url), ICU_DECODE, &uc)
  203. #else
  204. return (InternetCrackUrl(url, lstrlen(url), ICU_DECODE, &uc)
  205. #endif
  206. != FALSE);
  207. }
  208. // Return if ourDomain is within approvedDomain.
  209. // approvedDomain must either match ourDomain
  210. // or be a suffix preceded by a dot.
  211. //
  212. bool MatchDomains(TCHAR* approvedDomain, TCHAR* ourDomain)
  213. {
  214. int apDomLen = lstrlen(approvedDomain);
  215. int ourDomLen = lstrlen(ourDomain);
  216. if (apDomLen > ourDomLen)
  217. return false;
  218. if (lstrcmpi(ourDomain+ourDomLen-apDomLen, approvedDomain)
  219. != 0)
  220. return false;
  221. if (apDomLen == ourDomLen)
  222. return true;
  223. if (ourDomain[ourDomLen - apDomLen - 1] == '.')
  224. return true;
  225. return false;
  226. }
  227. void GetFileHandle(wchar_t *FileName, HANDLE *hFile);
  228. BOOL DeleteTempDir(wchar_t *TempDirectory,wchar_t *FileName,wchar_t *CabName);
  229. BOOL CreateTempDir(wchar_t *TempDirectory);
  230. BOOL ConvertFullDumpInternal (BSTR *Source, BSTR *Destination);
  231. DWORD GetResponseURL(wchar_t *HostName, wchar_t *RemoteFileName, BOOL fFullDump, wchar_t *ResponseURL);
  232. private:
  233. static TCHAR* _approvedDomains[8];
  234. private:
  235. IOleClientSite *_spUnkSite;
  236. BOOL m_b_SetSiteCalled;
  237. POCA_UPLOADFILE m_pUploadFile;
  238. void FormatMiniDate(SYSTEMTIME *pTimeStruct, CComBSTR &strDate);
  239. void FormatDate(SYSTEMTIME *pTimeStruct, CComBSTR &strDate);
  240. void FormatDate(tm *pTimeStruct, CComBSTR &strDate);
  241. BOOL FindFullDumps( BSTR *FileLists);
  242. BOOL FindMiniDumps( BSTR *FileLists);
  243. BOOL ValidMiniDump(BSTR FileName);
  244. BOOL ValidMiniDump(LPCTSTR FileName);
  245. };
  246. #endif //__OCARPTMAIN_H_