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.

311 lines
6.9 KiB

  1. // stdafx.h : include file for standard system include files,
  2. // or project specific include files that are used frequently,
  3. // but are changed infrequently
  4. #if !defined(AFX_STDAFX_H__97A939A5_466D_43B0_9150_CFBCC67F024B__INCLUDED_)
  5. #define AFX_STDAFX_H__97A939A5_466D_43B0_9150_CFBCC67F024B__INCLUDED_
  6. #include <nt.h>
  7. #include <ntrtl.h>
  8. #include <nturtl.h>
  9. #include <ntddkbd.h>
  10. #include <ntddmou.h>
  11. #include <windows.h>
  12. #include <winbase.h>
  13. #include <winerror.h>
  14. #include <ntsecapi.h>
  15. #include <lmcons.h>
  16. #include <lm.h>
  17. #include <wtsapi32.h>
  18. #include <winsta.h>
  19. #include "license.h"
  20. #include "tlsapi.h"
  21. #include "lscsp.h"
  22. #include "safsessionresolver.h"
  23. #include "tsremdsk.h"
  24. #include "tsstl.h"
  25. #include "locks.h"
  26. #include "map.h"
  27. #include "myassert.h"
  28. #include "icshelpapi.h"
  29. #if _MSC_VER > 1000
  30. #pragma once
  31. #endif // _MSC_VER > 1000
  32. #ifndef STRICT
  33. #define STRICT
  34. #endif
  35. #ifndef _WIN32_WINNT
  36. #define _WIN32_WINNT 0x0400
  37. #endif
  38. #define _ATL_APARTMENT_THREADED
  39. #include <atlbase.h>
  40. //You may derive a class from CComModule and use it if you want to override
  41. //something, but do not change the name of _Module
  42. #ifndef DBG
  43. #define IDLE_SHUTDOWN_PERIOD 10 * 1000 * 60 // 10 min wait
  44. #define EXPIRE_HELPSESSION_PERIOD 60 * 60 * 1000 // Clean up help session every hrs
  45. #else
  46. #define IDLE_SHUTDOWN_PERIOD 1000 * 60 * 5 // 1 min. time out
  47. #define EXPIRE_HELPSESSION_PERIOD 5 * 60 * 1000 // Clean up help session every 5 min.
  48. #endif
  49. #define SESSMGR_NOCONNECTIONEVENT_NAME L"Global\\RemoteDesktopSessMgr"
  50. #define SERVICE_STARTUP_WAITHINT 1000*30 // 30 second wait
  51. #define REGKEY_SYSTEM_EVENTSOURCE L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\System"
  52. #define MAX_FETCHIPADDRESSRETRY 5
  53. #define DEFAULT_MAXTICKET_EXPIRY 30 * 24 * 60 * 60 // Default max. ticket valid period
  54. class CServiceModule : public CComModule
  55. {
  56. public:
  57. static DWORD WINAPI
  58. HandlerEx(
  59. DWORD dwControl,
  60. DWORD dwEventType,
  61. LPVOID lpEventData,
  62. LPVOID lpContext
  63. );
  64. HRESULT
  65. RegisterServer(
  66. FILE* pSetupLog,
  67. BOOL bRegTypeLib,
  68. BOOL bService
  69. );
  70. HRESULT
  71. UnregisterServer(FILE* pSetupLog);
  72. HRESULT
  73. RemoveEventViewerSource(
  74. FILE* pSetupLog
  75. );
  76. void
  77. Init(
  78. _ATL_OBJMAP_ENTRY* p,
  79. HINSTANCE h,
  80. UINT nServiceNameID,
  81. UINT nServiceDispNameID,
  82. UINT nServiceDescID,
  83. const GUID* plibid = NULL
  84. );
  85. void Start();
  86. void
  87. ServiceMain(
  88. DWORD dwArgc,
  89. LPTSTR* lpszArgv
  90. );
  91. void Handler(DWORD dwOpcode);
  92. void Run();
  93. BOOL IsInstalled(FILE* pSetupLog);
  94. BOOL Install(FILE* pSetupLog);
  95. BOOL Uninstall(FILE* pSetupLog);
  96. LONG Unlock();
  97. BOOL UpdateService(FILE* pSetupLog);
  98. void
  99. LogEventWithStatusCode(
  100. DWORD dwEventType,
  101. DWORD dwEventId,
  102. DWORD dwCode
  103. );
  104. void
  105. LogSessmgrEventLog(
  106. DWORD dwEventType,
  107. DWORD dwEventCode,
  108. CComBSTR& bstrNoviceDomain,
  109. CComBSTR& bstrNoviceAccount,
  110. CComBSTR& bstrRaType,
  111. CComBSTR& bstrExpertIPFromClient,
  112. CComBSTR& bstrExpertIPFromTS,
  113. DWORD dwErrCode
  114. );
  115. void
  116. SetServiceStatus(DWORD dwState);
  117. void
  118. SetupAsLocalServer();
  119. ULONG
  120. AddRef();
  121. ULONG
  122. Release();
  123. CServiceModule() : m_RefCount(0), CComModule() {}
  124. DWORD
  125. GetServiceStartupStatus()
  126. {
  127. return HRESULT_FROM_WIN32(m_dwServiceStartupStatus);
  128. }
  129. BOOL
  130. IsSuccessServiceStartup()
  131. {
  132. return ERROR_SUCCESS == m_dwServiceStartupStatus;
  133. }
  134. BOOL
  135. InitializeSessmgr();
  136. //Implementation
  137. private:
  138. static HANDLE gm_hIdle;
  139. static HANDLE gm_hIdleMonitorThread;
  140. static void WINAPI _ServiceMain(DWORD dwArgc, LPTSTR* lpszArgv);
  141. static void WINAPI _Handler(DWORD dwOpcode);
  142. static unsigned int WINAPI IdleMonitorThread( void* ptr );
  143. static unsigned int WINAPI GPMonitorThread( void* ptr );
  144. // data members
  145. public:
  146. //
  147. // Refer to CreateService() for 256
  148. //
  149. TCHAR m_szServiceDesc[257];
  150. TCHAR m_szServiceName[257];
  151. TCHAR m_szServiceDispName[257];
  152. SERVICE_STATUS_HANDLE m_hServiceStatus;
  153. SERVICE_STATUS m_status;
  154. DWORD dwThreadID;
  155. BOOL m_bService;
  156. CCriticalSection m_ModuleLock; // Global _Module lock
  157. long m_RefCount;
  158. BOOL m_Initialized;
  159. DWORD m_dwServiceStartupStatus;
  160. };
  161. extern CServiceModule _Module;
  162. #include <atlcom.h>
  163. #include "RAEventMsg.h"
  164. #include "sessmgr.h"
  165. #include "helper.h"
  166. #include "helptab.h"
  167. #include "helpmgr.h"
  168. #include "helpsess.h"
  169. #include "tsremdsk.h"
  170. #include "rderror.h"
  171. #ifndef AllocMemory
  172. #define AllocMemory(size) \
  173. LocalAlloc(LPTR, size)
  174. #endif
  175. #ifndef FreeMemory
  176. #define FreeMemory(ptr) \
  177. if(ptr) \
  178. { \
  179. LocalFree(ptr); \
  180. ptr=NULL; \
  181. }
  182. #endif
  183. #ifndef ReallocMemory
  184. #define ReallocMemory(ptr, size) \
  185. LocalReAlloc(ptr, size, LMEM_ZEROINIT)
  186. #endif
  187. #define REGKEYCONTROL_REMDSK REG_CONTROL_REMDSK
  188. #define CLASS_PRIVATE
  189. #define CLASS_PUBLIC
  190. #define CLASS_STATIC
  191. struct __declspec(uuid("A55737AB-5B26-4A21-99B7-6D0C606F515E")) SESSIONRESOLVER;
  192. #define SESSIONRESOLVERCLSID __uuidof(SESSIONRESOLVER)
  193. #define HELPSESSION_UNSOLICATED _TEXT("UnsolicitedHelp")
  194. #define HELPSESSION_NORMAL_RA _TEXT("SolicitedHelp")
  195. //
  196. // HYDRA_CERT_REG_KEY
  197. // HYDRA_X509_CERTIFICATE
  198. // X509_CERT_PUBLIC_KEY_NAME
  199. // defined in lscsp.h
  200. //
  201. #define REGKEY_TSX509_CERT _TEXT(HYDRA_CERT_REG_KEY)
  202. #define REGVALUE_TSX509_CERT _TEXT(HYDRA_X509_CERTIFICATE)
  203. #define LSA_TSX509_CERT_PUBLIC_KEY_NAME X509_CERT_PUBLIC_KEY_NAME
  204. //
  205. // Message for notify session logoff or disconnect,
  206. // WPARAM : Not use
  207. // LPARAM : the logoff or disconnecting session.
  208. //
  209. #define WM_SESSIONLOGOFFDISCONNECT (WM_APP + 1)
  210. //
  211. // Message for expiring help ticket
  212. // WPARAM : Not use
  213. // LPARAM : Not use
  214. //
  215. #define WM_EXPIREHELPSESSION (WM_SESSIONLOGOFFDISCONNECT + 1)
  216. //
  217. // Notification message to reload termsrv public key
  218. // WPARAM : Not use
  219. // LPARAM : Not use
  220. //
  221. #define WM_LOADTSPUBLICKEY (WM_EXPIREHELPSESSION + 1)
  222. //
  223. // Notification for rdsaddin terminates
  224. // WPARAM : Not use
  225. // LPARAM : Pointer to help session (ticket) object.
  226. //
  227. #define WM_HELPERRDSADDINEXIT (WM_LOADTSPUBLICKEY + 1)
  228. #define HELPACCOUNTPROPERLYSETUP \
  229. _TEXT("L$20ed87e2-3b82-4114-81f9-5e219ed4c481-SALEMHELPACCOUNT")
  230. //{{AFX_INSERT_LOCATION}}
  231. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  232. #endif // !defined(AFX_STDAFX_H__97A939A5_466D_43B0_9150_CFBCC67F024B__INCLUDED)