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.

216 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. RemoteDesktopServerHost
  5. Abstract:
  6. Author:
  7. Tad Brockway 02/00
  8. Revision History:
  9. --*/
  10. #ifndef __REMOTEDESKTOPSERVERHOST_H_
  11. #define __REMOTEDESKTOPSERVERHOST_H_
  12. #include <RemoteDesktopTopLevelObject.h>
  13. #include "resource.h"
  14. #include "RemoteDesktopSession.h"
  15. ///////////////////////////////////////////////////////
  16. //
  17. // CRemoteDesktopServerHost
  18. //
  19. class ATL_NO_VTABLE CRemoteDesktopServerHost :
  20. public CRemoteDesktopTopLevelObject,
  21. public CComObjectRootEx<CComSingleThreadModel>,
  22. public CComCoClass<CRemoteDesktopServerHost, &CLSID_SAFRemoteDesktopServerHost>,
  23. public IDispatchImpl<ISAFRemoteDesktopServerHost, &IID_ISAFRemoteDesktopServerHost, &LIBID_RDSSERVERHOSTLib>
  24. {
  25. private:
  26. CComPtr<IRemoteDesktopHelpSessionMgr> m_HelpSessionManager;
  27. PSID m_LocalSystemSID;
  28. //
  29. // TODO : If we turn RDSHOST to MTA, we need to have a CRITICAL_SECTION to
  30. // guard access to m_SessionMap, we are posting message to COM so only single
  31. // thread can be running.
  32. //
  33. //
  34. // Session Map
  35. //
  36. typedef struct SessionMapEntry
  37. {
  38. CComObject<CRemoteDesktopSession> *obj;
  39. DWORD ticketExpireTime;
  40. } SESSIONMAPENTRY, *PSESSIONMAPENTRY;
  41. typedef std::map<CComBSTR, PSESSIONMAPENTRY, CompareBSTR, CRemoteDesktopAllocator<PSESSIONMAPENTRY> > SessionMap;
  42. SessionMap m_SessionMap;
  43. //
  44. // Handle to expire ticket, can't use WM_TIMER
  45. // since timerproc does not take user parameter and even
  46. // our object is SINGLETON, it's hidden inside ATL, we could
  47. // use WaitableTimer but if we ever move rdshost into MTA,
  48. // we would get into problem of thread owning the timer, refer
  49. // to MSDN on CreateWaitableTimer().
  50. //
  51. HANDLE m_hTicketExpiration;
  52. HANDLE m_hTicketExpirationWaitObject;
  53. //
  54. // Next ticket expiration time, this value is absolute time.
  55. // we don't store object pointer because
  56. // 1) we still need to go through entire m_SessionMap to find the next ticket
  57. // to be expired.
  58. // 2) Might have multiple ticket need to be expired at the same time.
  59. // We can use STL multimap to store/sort based on ticket expiration time,
  60. // BUT do we really expect lots of ticket in cache at the same time???
  61. //
  62. DWORD m_ToBeExpireTicketExpirateTime;
  63. //
  64. // Performance reason, we might have multiple CloseRemoteDesktopSession() calls
  65. // come in and we don't want to loop thru entire m_SessionMap everytime.
  66. //
  67. BOOL m_ExpireMsgPosted;
  68. //
  69. // Return the Local System SID.
  70. //
  71. PSID GetLocalSystemSID() {
  72. if (m_LocalSystemSID == NULL) {
  73. DWORD result = CreateSystemSid(&m_LocalSystemSID);
  74. if (result != ERROR_SUCCESS) {
  75. SetLastError(result);
  76. m_LocalSystemSID = NULL;
  77. }
  78. }
  79. return m_LocalSystemSID;
  80. }
  81. HRESULT
  82. TranslateStringAddress(
  83. LPTSTR pszAddress,
  84. ULONG* pNetAddr
  85. );
  86. //
  87. // Static function to expire tickets.
  88. //
  89. HRESULT
  90. AddTicketToExpirationList(
  91. DWORD ticketExpireTime,
  92. CComObject<CRemoteDesktopSession> *pTicketObj
  93. );
  94. HRESULT
  95. DeleteRemoteDesktopSession(ISAFRemoteDesktopSession *session);
  96. public:
  97. CRemoteDesktopServerHost() {
  98. m_LocalSystemSID = NULL;
  99. m_hTicketExpiration = NULL;
  100. m_hTicketExpirationWaitObject = NULL;
  101. m_ToBeExpireTicketExpirateTime = INFINITE_TICKET_EXPIRATION;
  102. m_ExpireMsgPosted = FALSE;
  103. }
  104. ~CRemoteDesktopServerHost();
  105. HRESULT FinalConstruct();
  106. // There should be a single instance of this class for each server.
  107. DECLARE_CLASSFACTORY_SINGLETON(CRemoteDesktopServerHost);
  108. DECLARE_REGISTRY_RESOURCEID(IDR_REMOTEDESKTOPSERVERHOST)
  109. DECLARE_PROTECT_FINAL_CONSTRUCT()
  110. //
  111. // COM Interface Map
  112. //
  113. BEGIN_COM_MAP(CRemoteDesktopServerHost)
  114. COM_INTERFACE_ENTRY(ISAFRemoteDesktopServerHost)
  115. COM_INTERFACE_ENTRY(IDispatch)
  116. END_COM_MAP()
  117. public:
  118. HRESULT
  119. ExpirateTicketAndSetupNextExpiration();
  120. inline BOOL
  121. GetExpireMsgPosted() {
  122. return m_ExpireMsgPosted;
  123. }
  124. inline VOID
  125. SetExpireMsgPosted( BOOL bPosted ) {
  126. m_ExpireMsgPosted = bPosted;
  127. }
  128. static VOID
  129. TicketExpirationProc(
  130. LPVOID lpArg,
  131. BOOLEAN TimerOrWaitFired
  132. );
  133. //
  134. // ISAFRemoteDesktopServerHost Methods
  135. //
  136. STDMETHOD(CreateRemoteDesktopSession)(
  137. REMOTE_DESKTOP_SHARING_CLASS sharingClass,
  138. BOOL fEnableCallback,
  139. LONG timeOut,
  140. BSTR userHelpBlob,
  141. ISAFRemoteDesktopSession **session
  142. );
  143. STDMETHOD(CreateRemoteDesktopSessionEx)(
  144. REMOTE_DESKTOP_SHARING_CLASS sharingClass,
  145. BOOL bEnableCallback,
  146. LONG timeout,
  147. BSTR userHelpCreateBlob,
  148. LONG tsSessionID,
  149. BSTR userSID,
  150. ISAFRemoteDesktopSession **session
  151. );
  152. STDMETHOD(OpenRemoteDesktopSession)(
  153. BSTR parms,
  154. BSTR userSID,
  155. ISAFRemoteDesktopSession **session
  156. );
  157. STDMETHOD(CloseRemoteDesktopSession)(ISAFRemoteDesktopSession *session);
  158. STDMETHOD(ConnectToExpert)(
  159. /*[in]*/ BSTR connectParmToExpert,
  160. /*[in]*/ LONG timeout,
  161. /*[out, retval]*/ LONG* SafErrCode
  162. );
  163. void
  164. RemoteDesktopDisabled();
  165. //
  166. // Return the name of this class.
  167. //
  168. virtual const LPTSTR ClassName() {
  169. return TEXT("CRemoteDesktopServerHost");
  170. }
  171. };
  172. #endif //__REMOTEDESKTOPSERVERHOST_H_