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.

264 lines
8.7 KiB

  1. // CerClient.h : Declaration of the CCerClient
  2. #ifndef __CERCLIENT_H_
  3. #define __CERCLIENT_H_
  4. #include "resource.h" // main symbols
  5. #include <atlctl.h>
  6. #include <stdio.h>
  7. #include <Wininet.h>
  8. #include <exdisp.h>
  9. #include <shlguid.h>
  10. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CCerClient
  13. class ATL_NO_VTABLE CCerClient :
  14. public CComObjectRootEx<CComSingleThreadModel>,
  15. public IDispatchImpl<ICerClient, &IID_ICerClient, &LIBID_CERUPLOADLib>,
  16. public CComControl<CCerClient>,
  17. public IPersistStreamInitImpl<CCerClient>,
  18. public IOleControlImpl<CCerClient>,
  19. public IOleObjectImpl<CCerClient>,
  20. public IOleInPlaceActiveObjectImpl<CCerClient>,
  21. public IViewObjectExImpl<CCerClient>,
  22. public IOleInPlaceObjectWindowlessImpl<CCerClient>,
  23. public IPersistStorageImpl<CCerClient>,
  24. public ISpecifyPropertyPagesImpl<CCerClient>,
  25. public IQuickActivateImpl<CCerClient>,
  26. public IDataObjectImpl<CCerClient>,
  27. public IProvideClassInfo2Impl<&CLSID_CerClient, NULL, &LIBID_CERUPLOADLib>,
  28. public CComCoClass<CCerClient, &CLSID_CerClient>,
  29. public IObjectSafetyImpl<CCerClient, INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA >
  30. {
  31. public:
  32. CCerClient()
  33. {
  34. }
  35. DECLARE_REGISTRY_RESOURCEID(IDR_CERCLIENT)
  36. DECLARE_PROTECT_FINAL_CONSTRUCT()
  37. BEGIN_COM_MAP(CCerClient)
  38. COM_INTERFACE_ENTRY(ICerClient)
  39. COM_INTERFACE_ENTRY(IDispatch)
  40. COM_INTERFACE_ENTRY(IViewObjectEx)
  41. COM_INTERFACE_ENTRY(IViewObject2)
  42. COM_INTERFACE_ENTRY(IViewObject)
  43. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  44. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  45. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  46. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  47. COM_INTERFACE_ENTRY(IOleControl)
  48. COM_INTERFACE_ENTRY(IOleObject)
  49. COM_INTERFACE_ENTRY(IPersistStreamInit)
  50. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  51. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  52. COM_INTERFACE_ENTRY(IQuickActivate)
  53. COM_INTERFACE_ENTRY(IPersistStorage)
  54. COM_INTERFACE_ENTRY(IDataObject)
  55. COM_INTERFACE_ENTRY(IProvideClassInfo)
  56. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  57. COM_INTERFACE_ENTRY(IObjectSafety)
  58. END_COM_MAP()
  59. BEGIN_PROP_MAP(CCerClient)
  60. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  61. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  62. // Example entries
  63. // PROP_ENTRY("Property Description", dispid, clsid)
  64. // PROP_PAGE(CLSID_StockColorPage)
  65. END_PROP_MAP()
  66. BEGIN_MSG_MAP(CCerClient)
  67. CHAIN_MSG_MAP(CComControl<CCerClient>)
  68. DEFAULT_REFLECTION_HANDLER()
  69. END_MSG_MAP()
  70. // Handler prototypes:
  71. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  72. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  73. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  74. // IViewObjectEx
  75. DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
  76. // ICerClient
  77. public:
  78. STDMETHOD(GetSuccessCount)(/*[in]*/BSTR *Path, /*[in]*/BSTR *TransID, /*[out,retval]*/ VARIANT *RetVal);
  79. STDMETHOD(Upload1)(/*[in]*/BSTR *Path, /*[in]*/BSTR *TransID, /*[in]*/BSTR *FileName, /*[in]*/BSTR *IncidentID, /*[in]*/BSTR *RedirParam, /*[in]*/BSTR *Type, /*[out,retval]*/ VARIANT *RetCode);
  80. STDMETHOD(EndTransaction)(/*[in]*/BSTR *SharePath,/*[in]*/BSTR *TransID, /*[out,retval]*/ VARIANT *RetCode);
  81. STDMETHOD(RetryFile1)(/*[in]*/BSTR *Path,/*[in]*/BSTR *TransID,/*[in]*/BSTR *FileName,/*[in]*/BSTR *IncidentID, /*[in]*/BSTR *RedirParam,/*[out,retval]*/ VARIANT *RetCode);
  82. STDMETHOD(GetAllComputerNames)(/*[in]*/BSTR *Path, /*[in]*/BSTR *TransID, /*[in]*/ BSTR* FileList, /*[out,retval]*/ VARIANT *ReturnList);
  83. STDMETHOD(GetCompuerNames)(/*[in]*/BSTR *Path, /*[in]*/BSTR *TransID,/*[in]*/BSTR *FileList,/*[out,retval]*/VARIANT *RetFileList);
  84. STDMETHOD(Browse)(/*[in]*/BSTR *WindowTitle, /*[out,retval]*/ VARIANT *Path);
  85. STDMETHOD(GetFileNames)(/*[in]*/BSTR *Path, /*[in]*/BSTR *TransID, /*[in]*/ VARIANT *Count, /*[out,retval]*/ VARIANT *FileList);
  86. STDMETHOD(RetryFile)(/*[in]*/ BSTR *Path, /*[in]*/ BSTR *TransID, /*[in]*/ BSTR FileName, /*[out,retval]*/ VARIANT * RetCode);
  87. STDMETHOD(RetryTransaction)(/*[in]*/ BSTR *Path, /*[in]*/BSTR *TransID, /*[in]*/ BSTR *FileName, /*[out,retval]*/ VARIANT * RetVal);
  88. STDMETHOD(Upload)(/*[in]*/ BSTR *Path, /*[in]*/ BSTR *TransID, /*[in]*/BSTR *FileName, /*[in]*/ BSTR*IncidentID, /*[in]*/ BSTR *RedirParam, /*[out,retval]*/ VARIANT *RetCode);
  89. STDMETHOD(GetFileCount)(/*[in]*/ BSTR *bstrSharePath, /*[in]*/ BSTR *bstrTransactID, /*[in]*/ VARIANT *iMaxCount, /*[out,retval]*/ VARIANT *RetVal);
  90. HRESULT OnDraw(ATL_DRAWINFO& di)
  91. {
  92. RECT& rc = *(RECT*)di.prcBounds;
  93. Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);
  94. SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
  95. LPCTSTR pszText = _T("ATL 3.0 : CerClient");
  96. TextOut(di.hdcDraw,
  97. (rc.left + rc.right) / 2,
  98. (rc.top + rc.bottom) / 2,
  99. pszText,
  100. lstrlen(pszText));
  101. return S_OK;
  102. }
  103. STDMETHODIMP SetClientSite (IOleClientSite *pClientSite)
  104. {
  105. _spUnkSite = pClientSite;
  106. return S_OK;
  107. }
  108. STDMETHODIMP GetSite (REFIID riid, LPVOID* ppvSite)
  109. {
  110. return _spUnkSite->QueryInterface(riid,ppvSite);
  111. }
  112. bool InApprovedDomain()
  113. {
  114. char ourUrl[INTERNET_MAX_URL_LENGTH];
  115. if (!GetOurUrl(ourUrl, sizeof ourUrl))
  116. return false;
  117. return IsApprovedDomain(ourUrl);
  118. }
  119. bool GetOurUrl(char* pszURL, int cbBuf)
  120. {
  121. HRESULT hr;
  122. CComPtr<IServiceProvider> spSrvProv;
  123. CComPtr<IWebBrowser2> spWebBrowser;
  124. if (_spUnkSite == NULL)
  125. return false;
  126. hr = GetSite(IID_IServiceProvider, (void**)&spSrvProv);
  127. if (FAILED(hr))
  128. return false;
  129. hr = spSrvProv->QueryService(SID_SWebBrowserApp,
  130. IID_IWebBrowser2,
  131. (void**)&spWebBrowser);
  132. if (FAILED(hr))
  133. return false;
  134. CComBSTR bstrURL;
  135. if (FAILED(spWebBrowser->get_LocationURL(&bstrURL)))
  136. return false;
  137. WideCharToMultiByte(CP_ACP, 0, bstrURL, -1, pszURL, cbBuf,
  138. NULL, NULL);
  139. return true;
  140. }
  141. bool IsApprovedDomain(char* ourUrl)
  142. {
  143. // Only allow http access.
  144. // You can change this to allow file:// access.
  145. //
  146. if (GetScheme(ourUrl) != INTERNET_SCHEME_HTTPS)
  147. return false;
  148. char ourDomain[256];
  149. if (!GetDomain(ourUrl, ourDomain, sizeof(ourDomain)))
  150. return false;
  151. for (int i = 0; i < ARRAYSIZE(_approvedDomains); i++)
  152. {
  153. if (MatchDomains(const_cast<char*>(_approvedDomains[i]),
  154. ourDomain))
  155. {
  156. return true;
  157. }
  158. }
  159. return false;
  160. }
  161. INTERNET_SCHEME GetScheme(char* url)
  162. {
  163. char buf[32];
  164. URL_COMPONENTS uc;
  165. ZeroMemory(&uc, sizeof uc);
  166. uc.dwStructSize = sizeof uc;
  167. uc.lpszScheme = buf;
  168. uc.dwSchemeLength = sizeof buf;
  169. if (InternetCrackUrl(url, lstrlen(url), ICU_DECODE, &uc))
  170. return uc.nScheme;
  171. else
  172. return INTERNET_SCHEME_UNKNOWN;
  173. }
  174. bool GetDomain(char* url, char* buf, int cbBuf)
  175. {
  176. URL_COMPONENTS uc;
  177. ZeroMemory(&uc, sizeof uc);
  178. uc.dwStructSize = sizeof uc;
  179. uc.lpszHostName = buf;
  180. uc.dwHostNameLength = cbBuf;
  181. return (InternetCrackUrl(url, lstrlen(url), ICU_DECODE, &uc)
  182. != FALSE);
  183. }
  184. // Return if ourDomain is within approvedDomain.
  185. // approvedDomain must either match ourDomain
  186. // or be a suffix preceded by a dot.
  187. //
  188. bool MatchDomains(char* approvedDomain, char* ourDomain)
  189. {
  190. int apDomLen = lstrlen(approvedDomain);
  191. int ourDomLen = lstrlen(ourDomain);
  192. if (apDomLen > ourDomLen)
  193. return false;
  194. if (lstrcmpi(ourDomain+ourDomLen-apDomLen, approvedDomain)
  195. != 0)
  196. return false;
  197. if (apDomLen == ourDomLen)
  198. return true;
  199. if (ourDomain[ourDomLen - apDomLen - 1] == '.')
  200. return true;
  201. return false;
  202. }
  203. private:
  204. static char* _approvedDomains[6];
  205. private:
  206. IOleClientSite *_spUnkSite;
  207. DWORD GetComputerNameFromCSV(wchar_t *CsvFileName,
  208. wchar_t *FileName,
  209. wchar_t *ComputerName
  210. );
  211. int GetUploadServerName (wchar_t *RedirectorParam,
  212. wchar_t *Language,
  213. wchar_t *ServerName
  214. );
  215. DWORD GetMachineName(wchar_t *Path, wchar_t *FileName, wchar_t *MachineName);
  216. int GetNewFileNameFromCSV(wchar_t *Path, wchar_t *transid, wchar_t *FileName,wchar_t *NewFileName);
  217. };
  218. #endif //__CERCLIENT_H_