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.

429 lines
8.4 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_HelpSessionName)(
  75. /*[out, retval]*/ BSTR *pVal
  76. );
  77. STDMETHOD(put_HelpSessionName)(
  78. /*[in]*/ BSTR newVal
  79. );
  80. STDMETHOD(put_HelpSessionPassword)(
  81. /*[in]*/ BSTR newVal
  82. );
  83. STDMETHOD(get_HelpSessionDescription)(
  84. /*[out, retval]*/ BSTR *pVal
  85. );
  86. STDMETHOD(put_HelpSessionDescription)(
  87. /*[in]*/ BSTR newVal
  88. );
  89. STDMETHOD(get_EnableResolver)(
  90. /*[out, retval]*/ BOOL* pVal
  91. );
  92. STDMETHOD(put_EnableResolver)(
  93. /*[in]*/ BOOL Val
  94. );
  95. STDMETHOD(get_HelpSessionCreateBlob)(
  96. /*[out, retval]*/ BSTR* pVal
  97. );
  98. STDMETHOD(put_HelpSessionCreateBlob)(
  99. /*[in]*/ BSTR Val
  100. );
  101. STDMETHOD(get_ResolverBlob)(
  102. /*[out, retval]*/ BSTR* pVal
  103. );
  104. STDMETHOD(put_ResolverBlob)(
  105. /*[in]*/ BSTR Val
  106. );
  107. STDMETHOD(get_UserHelpSessionRemoteDesktopSharingSetting)(
  108. /*[out, retval]*/ REMOTE_DESKTOP_SHARING_CLASS* pLevel
  109. );
  110. STDMETHOD(put_UserHelpSessionRemoteDesktopSharingSetting)(
  111. /*[in]*/ REMOTE_DESKTOP_SHARING_CLASS Level
  112. );
  113. STDMETHOD(get_UserPolicyRemoteDesktopSharingSetting)(
  114. /*[out, retval]*/ REMOTE_DESKTOP_SHARING_CLASS* pLevel
  115. )
  116. /*++
  117. --*/
  118. {
  119. DWORD dwStatus;
  120. if( NULL == pLevel )
  121. {
  122. dwStatus = ERROR_INVALID_PARAMETER;
  123. }
  124. else if( UNKNOWN_LOGONID != m_ulLogonId )
  125. {
  126. dwStatus = GetUserRDSLevel( m_ulLogonId, pLevel );
  127. }
  128. return HRESULT_FROM_WIN32( dwStatus );
  129. }
  130. STDMETHOD(get_AllowToGetHelp)(
  131. /*[out, retval]*/ BOOL* pVal
  132. );
  133. STDMETHOD(get_ConnectParms)(
  134. /*[out, ret]*/ BSTR* bstrConnectParms
  135. );
  136. STDMETHOD(DeleteHelp)();
  137. STDMETHOD(ResolveUserSession)(
  138. /*[in]*/ BSTR bstrResolverBlob,
  139. /*[in]*/ BSTR bstrExpertBlob,
  140. /*[in]*/ LONG CallerProcessId,
  141. /*[out]*/ ULONG_PTR* hHelpCtr,
  142. /*[out]*/ LONG* pResolverErrCode,
  143. /*[out, retval]*/ long* plUserSession
  144. );
  145. STDMETHOD(EnableUserSessionRdsSetting)(
  146. /*[in]*/ BOOL bEnable
  147. );
  148. HRESULT NotifyDisconnect();
  149. BOOL
  150. IsHelpSessionExpired();
  151. void
  152. SetHelpSessionFlag(
  153. IN ULONG flags
  154. )
  155. /*++
  156. --*/
  157. {
  158. m_ulHelpSessionFlag = flags;
  159. }
  160. ULONG
  161. GetHelpSessionFlag()
  162. /*++
  163. --*/
  164. {
  165. return m_ulHelpSessionFlag;
  166. }
  167. // Create an instance of help session object
  168. static HRESULT
  169. CreateInstance(
  170. IN CRemoteDesktopHelpSessionMgr* pMgr,
  171. IN CComBSTR& bstrClientSid,
  172. IN PHELPENTRY pHelp,
  173. OUT RemoteDesktopHelpSessionObj** ppRemoteDesktopHelpSession
  174. );
  175. //
  176. // Retrieve HelpAssisant session ID which is providing help
  177. // to this object
  178. ULONG
  179. GetHelperSessionId() {
  180. return m_ulHelperSessionId;
  181. }
  182. //
  183. // Convert ticket owner SID to domain\account
  184. //
  185. void
  186. ResolveTicketOwner();
  187. protected:
  188. HRESULT
  189. InitInstance(
  190. IN CRemoteDesktopHelpSessionMgr* pMgr,
  191. IN CComBSTR& bstrClientSid,
  192. IN PHELPENTRY pHelpEntry
  193. );
  194. private:
  195. void
  196. ResolveHelperInformation(
  197. ULONG HelperSessionId,
  198. CComBSTR& bstrExpertIpAddressFromClient,
  199. CComBSTR& bstrExpertIpAddressFromServer
  200. );
  201. HRESULT
  202. ResolveTicketOwnerInformation(
  203. CComBSTR& ownerSidString,
  204. CComBSTR& Domain,
  205. CComBSTR& UserAcc
  206. );
  207. VOID
  208. SetHelperSessionId( ULONG HelperSessionId ) {
  209. m_ulHelperSessionId = HelperSessionId;
  210. return;
  211. }
  212. BOOL
  213. IsClientSessionCreator();
  214. BOOL
  215. IsSessionValid()
  216. {
  217. return (FALSE == m_bDeleted && NULL != m_pHelpSession);
  218. }
  219. HRESULT
  220. ActivateSessionRDSSetting();
  221. HRESULT
  222. ResetSessionRDSSetting();
  223. HRESULT
  224. BeginUpdate();
  225. HRESULT
  226. CommitUpdate();
  227. HRESULT
  228. AbortUpdate();
  229. HRESULT
  230. put_UserLogonId(
  231. IN long newVal
  232. );
  233. HRESULT
  234. put_ICSPort(
  235. IN DWORD newVal
  236. );
  237. HRESULT
  238. put_UserSID(
  239. IN BSTR bstrUserSID
  240. )
  241. /*++
  242. --*/
  243. {
  244. HRESULT hRes = S_OK;
  245. MYASSERT( m_pHelpSession->m_UserSID->Length() == 0 );
  246. m_pHelpSession->m_UserSID = bstrUserSID;
  247. if( !((CComBSTR)m_pHelpSession->m_UserSID == bstrUserSID) )
  248. {
  249. hRes = E_OUTOFMEMORY;
  250. }
  251. return hRes;
  252. }
  253. BOOL
  254. IsEqualSid(
  255. IN const CComBSTR& bstrSid
  256. );
  257. BOOL
  258. IsCreatedByUserSession(
  259. IN const long lUserSessionId
  260. )
  261. /*++
  262. --*/
  263. {
  264. return m_ulLogonId == lUserSessionId;
  265. }
  266. BOOL
  267. VerifyUserSession(
  268. IN const CComBSTR& bstrUserSid,
  269. IN const CComBSTR& bstrSessPwd
  270. );
  271. BOOL
  272. IsUnsolicitedHelp()
  273. {
  274. DebugPrintf(
  275. _TEXT("Help Session Flag : 0x%08x\n"),
  276. m_ulHelpSessionFlag
  277. );
  278. return (m_ulHelpSessionFlag & HELPSESSIONFLAG_UNSOLICITEDHELP);
  279. }
  280. //
  281. // Help Session Object Lock.
  282. //
  283. CCriticalSection m_HelpSessionLock;
  284. //
  285. // Pointer to Help Entry in registry
  286. //
  287. PHELPENTRY m_pHelpSession;
  288. //
  289. // TS session ID or 0xFFFFFFFF
  290. //
  291. ULONG m_ulLogonId;
  292. CRemoteDesktopHelpSessionMgr* m_pSessMgr;
  293. BOOL m_bDeleted;
  294. //
  295. // calling client SID
  296. //
  297. CComBSTR m_bstrClientSid;
  298. //
  299. // Following is cached in this object in case our help is
  300. // expired.
  301. //
  302. CComBSTR m_bstrHelpSessionId;
  303. CComBSTR m_ResolverConnectBlob;
  304. CComBSTR m_HelpSessionOwnerSid;
  305. //
  306. // HelpAssistant session ID that is providing
  307. // help to this object or is pending user acceptance on
  308. // invitation
  309. //
  310. ULONG m_ulHelperSessionId;
  311. //
  312. // Cached ticket owner (domain\user account) and
  313. // helper information for event logging
  314. //
  315. EventLogInfo m_EventLogInfo;
  316. //
  317. // Various flag for this session
  318. //
  319. ULONG m_ulHelpSessionFlag;
  320. };
  321. #endif //__REMOTEDESKTOPHELPSESSION_H_