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.

418 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. HelpSess.h
  5. Abstract:
  6. Declaration of the CRemoteDesktopHelpSession
  7. Author:
  8. HueiWang 2/17/2000
  9. --*/
  10. #ifndef __REMOTEDESKTOPHELPSESSION_H_
  11. #define __REMOTEDESKTOPHELPSESSION_H_
  12. #include "resource.h" // main symbols
  13. #include "policy.h"
  14. class CRemoteDesktopHelpSession;
  15. class CRemoteDesktopHelpSessionMgr;
  16. typedef struct __EventLogInfo {
  17. CComBSTR bstrNoviceDomain; // Ticket owner domain.
  18. CComBSTR bstrNoviceAccount; // Ticket owner account.
  19. CComBSTR bstrExpertIpAddressFromClient; // IP address passed from TS client
  20. CComBSTR bstrExpertIpAddressFromServer; // Retrieve from TermSrv, IOCTL call.
  21. } EventLogInfo;
  22. //#define ALLOW_ALL_ACCESS_SID _TEXT("bb6e1cb1-7ab3-4596-a7ef-c02f49dc5a90")
  23. #define UNKNOWN_LOGONID 0xFFFFFFFF
  24. #define UNKNOWN_LOGONID_STRING L"0"
  25. #define HELPSESSIONFLAG_UNSOLICITEDHELP 0x80000000
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CRemoteDesktopHelpSession
  28. class ATL_NO_VTABLE CRemoteDesktopHelpSession :
  29. public CComObjectRootEx<CComMultiThreadModel>,
  30. //public CComCoClass<CRemoteDesktopHelpSession, &CLSID_RemoteDesktopHelpSession>,
  31. public IDispatchImpl<IRemoteDesktopHelpSession, &IID_IRemoteDesktopHelpSession, &LIBID_RDSESSMGRLib>
  32. {
  33. friend class CRemoteDesktopHelpSessionMgr;
  34. public:
  35. CRemoteDesktopHelpSession();
  36. ~CRemoteDesktopHelpSession();
  37. DECLARE_REGISTRY_RESOURCEID(IDR_REMOTEDESKTOPHELPSESSION)
  38. DECLARE_PROTECT_FINAL_CONSTRUCT()
  39. BEGIN_COM_MAP(CRemoteDesktopHelpSession)
  40. COM_INTERFACE_ENTRY(IRemoteDesktopHelpSession)
  41. COM_INTERFACE_ENTRY(IDispatch)
  42. END_COM_MAP()
  43. HRESULT
  44. FinalConstruct()
  45. {
  46. ULONG count = _Module.AddRef();
  47. m_bDeleted = FALSE;
  48. DebugPrintf(
  49. _TEXT("Module AddRef by CRemoteDesktopHelpSession() %p %d...\n"),
  50. this,
  51. count
  52. );
  53. return S_OK;
  54. }
  55. void
  56. FinalRelease();
  57. // IRemoteDesktopHelpSession
  58. public:
  59. STDMETHOD(get_TimeOut)(
  60. /*[out, retval]*/ DWORD* Timeout
  61. );
  62. STDMETHOD(put_TimeOut)(
  63. /*[in]*/ DWORD Timeout
  64. );
  65. STDMETHOD(get_HelpSessionId)(
  66. /*[out, retval]*/ BSTR *pVal
  67. );
  68. STDMETHOD(get_UserLogonId)(
  69. /*[out, retval]*/ long *pVal
  70. );
  71. STDMETHOD(get_AssistantAccountName)(
  72. /*[out, retval]*/ BSTR *pVal
  73. );
  74. STDMETHOD(get_EnableResolver)(
  75. /*[out, retval]*/ BOOL* pVal
  76. );
  77. STDMETHOD(put_EnableResolver)(
  78. /*[in]*/ BOOL Val
  79. );
  80. STDMETHOD(get_HelpSessionCreateBlob)(
  81. /*[out, retval]*/ BSTR* pVal
  82. );
  83. STDMETHOD(put_HelpSessionCreateBlob)(
  84. /*[in]*/ BSTR Val
  85. );
  86. STDMETHOD(get_ResolverBlob)(
  87. /*[out, retval]*/ BSTR* pVal
  88. );
  89. STDMETHOD(put_ResolverBlob)(
  90. /*[in]*/ BSTR Val
  91. );
  92. STDMETHOD(get_UserHelpSessionRemoteDesktopSharingSetting)(
  93. /*[out, retval]*/ REMOTE_DESKTOP_SHARING_CLASS* pLevel
  94. );
  95. STDMETHOD(put_UserHelpSessionRemoteDesktopSharingSetting)(
  96. /*[in]*/ REMOTE_DESKTOP_SHARING_CLASS Level
  97. );
  98. STDMETHOD(get_UserPolicyRemoteDesktopSharingSetting)(
  99. /*[out, retval]*/ REMOTE_DESKTOP_SHARING_CLASS* pLevel
  100. )
  101. /*++
  102. --*/
  103. {
  104. DWORD dwStatus;
  105. if( NULL == pLevel )
  106. {
  107. dwStatus = ERROR_INVALID_PARAMETER;
  108. }
  109. else if( UNKNOWN_LOGONID != m_ulLogonId )
  110. {
  111. dwStatus = GetUserRDSLevel( m_ulLogonId, pLevel );
  112. }
  113. else
  114. {
  115. dwStatus = ERROR_FILE_NOT_FOUND;
  116. }
  117. return HRESULT_FROM_WIN32( dwStatus );
  118. }
  119. STDMETHOD(get_AllowToGetHelp)(
  120. /*[out, retval]*/ BOOL* pVal
  121. );
  122. STDMETHOD(get_ConnectParms)(
  123. /*[out, ret]*/ BSTR* bstrConnectParms
  124. );
  125. STDMETHOD(IsUserOwnerOfTicket)(
  126. /*[in]*/ BSTR SID,
  127. /* [out, retval] */ VARIANT_BOOL* pbUserIsOwner
  128. );
  129. STDMETHOD(DeleteHelp)();
  130. STDMETHOD(ResolveUserSession)(
  131. /*[in]*/ BSTR bstrResolverBlob,
  132. /*[in]*/ BSTR bstrExpertBlob,
  133. /*[in]*/ LONG CallerProcessId,
  134. /*[out]*/ ULONG_PTR* hHelpCtr,
  135. /*[out]*/ LONG* pResolverErrCode,
  136. /*[out, retval]*/ long* plUserSession
  137. );
  138. STDMETHOD(EnableUserSessionRdsSetting)(
  139. /*[in]*/ BOOL bEnable
  140. );
  141. HRESULT NotifyDisconnect();
  142. BOOL
  143. IsHelpSessionExpired();
  144. void
  145. SetHelpSessionFlag(
  146. IN ULONG flags
  147. )
  148. /*++
  149. --*/
  150. {
  151. m_ulHelpSessionFlag = flags;
  152. }
  153. ULONG
  154. GetHelpSessionFlag()
  155. /*++
  156. --*/
  157. {
  158. return m_ulHelpSessionFlag;
  159. }
  160. // Create an instance of help session object
  161. static HRESULT
  162. CreateInstance(
  163. IN CRemoteDesktopHelpSessionMgr* pMgr,
  164. IN CComBSTR& bstrClientSid,
  165. IN PHELPENTRY pHelp,
  166. OUT RemoteDesktopHelpSessionObj** ppRemoteDesktopHelpSession
  167. );
  168. //
  169. // Retrieve HelpAssisant session ID which is providing help
  170. // to this object
  171. ULONG
  172. GetHelperSessionId() {
  173. return m_ulHelperSessionId;
  174. }
  175. //
  176. // Convert ticket owner SID to domain\account
  177. //
  178. void
  179. ResolveTicketOwner();
  180. protected:
  181. HRESULT
  182. InitInstance(
  183. IN CRemoteDesktopHelpSessionMgr* pMgr,
  184. IN CComBSTR& bstrClientSid,
  185. IN PHELPENTRY pHelpEntry
  186. );
  187. private:
  188. void
  189. ResolveHelperInformation(
  190. ULONG HelperSessionId,
  191. CComBSTR& bstrExpertIpAddressFromClient,
  192. CComBSTR& bstrExpertIpAddressFromServer
  193. );
  194. HRESULT
  195. ResolveTicketOwnerInformation(
  196. CComBSTR& ownerSidString,
  197. CComBSTR& Domain,
  198. CComBSTR& UserAcc
  199. );
  200. VOID
  201. SetHelperSessionId( ULONG HelperSessionId ) {
  202. m_ulHelperSessionId = HelperSessionId;
  203. return;
  204. }
  205. BOOL
  206. IsClientSessionCreator();
  207. BOOL
  208. IsSessionValid()
  209. {
  210. return (FALSE == m_bDeleted && NULL != m_pHelpSession);
  211. }
  212. HRESULT
  213. ActivateSessionRDSSetting();
  214. HRESULT
  215. ResetSessionRDSSetting();
  216. HRESULT
  217. BeginUpdate();
  218. HRESULT
  219. CommitUpdate();
  220. HRESULT
  221. AbortUpdate();
  222. HRESULT
  223. put_UserLogonId(
  224. IN long newVal
  225. );
  226. HRESULT
  227. put_ICSPort(
  228. IN DWORD newVal
  229. );
  230. HRESULT
  231. put_UserSID(
  232. IN BSTR bstrUserSID
  233. )
  234. /*++
  235. --*/
  236. {
  237. HRESULT hRes = S_OK;
  238. MYASSERT( m_pHelpSession->m_UserSID->Length() == 0 );
  239. m_pHelpSession->m_UserSID = bstrUserSID;
  240. if( !((CComBSTR)m_pHelpSession->m_UserSID == bstrUserSID) )
  241. {
  242. hRes = E_OUTOFMEMORY;
  243. }
  244. return hRes;
  245. }
  246. BOOL
  247. IsEqualSid(
  248. IN const CComBSTR& bstrSid
  249. );
  250. BOOL
  251. IsCreatedByUserSession(
  252. IN const long lUserSessionId
  253. )
  254. /*++
  255. --*/
  256. {
  257. return m_ulLogonId == lUserSessionId;
  258. }
  259. BOOL
  260. VerifyUserSession(
  261. IN const CComBSTR& bstrUserSid,
  262. IN const CComBSTR& bstrSessPwd
  263. );
  264. BOOL
  265. IsUnsolicitedHelp()
  266. {
  267. DebugPrintf(
  268. _TEXT("Help Session Flag : 0x%08x\n"),
  269. m_ulHelpSessionFlag
  270. );
  271. return (m_ulHelpSessionFlag & HELPSESSIONFLAG_UNSOLICITEDHELP);
  272. }
  273. //
  274. // Help Session Object Lock.
  275. //
  276. CResourceLock m_HelpSessionLock;
  277. //
  278. // Pointer to Help Entry in registry
  279. //
  280. PHELPENTRY m_pHelpSession;
  281. //
  282. // TS session ID or 0xFFFFFFFF
  283. //
  284. ULONG m_ulLogonId;
  285. CRemoteDesktopHelpSessionMgr* m_pSessMgr;
  286. BOOL m_bDeleted;
  287. //
  288. // calling client SID
  289. //
  290. CComBSTR m_bstrClientSid;
  291. //
  292. // Following is cached in this object in case our help is
  293. // expired.
  294. //
  295. CComBSTR m_bstrHelpSessionId;
  296. CComBSTR m_ResolverConnectBlob;
  297. CComBSTR m_HelpSessionOwnerSid;
  298. //
  299. // HelpAssistant session ID that is providing
  300. // help to this object or is pending user acceptance on
  301. // invitation
  302. //
  303. ULONG m_ulHelperSessionId;
  304. //
  305. // Cached ticket owner (domain\user account) and
  306. // helper information for event logging
  307. //
  308. EventLogInfo m_EventLogInfo;
  309. //
  310. // Various flag for this session
  311. //
  312. ULONG m_ulHelpSessionFlag;
  313. };
  314. #endif //__REMOTEDESKTOPHELPSESSION_H_