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.

356 lines
10 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File: SesMgr.h
  8. //
  9. // Contents: "Session" manager structures.
  10. //
  11. //
  12. // History: 27 May 92 RichardW Created from ether
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef __SESMGR_H__
  16. #define __SESMGR_H__
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include "handle.h"
  21. //
  22. // Forward definition so that we can reference it
  23. //
  24. struct _Session;
  25. //
  26. // Shared Section structure. This allows packages to create shared
  27. // sections with client processes.
  28. //
  29. typedef struct _LSAP_SHARED_SECTION {
  30. LIST_ENTRY List; // List of sections for a session
  31. PVOID Base; // Base pointer
  32. HANDLE Heap; // Heap handle
  33. struct _Session * Session; // Session pointer
  34. HANDLE Section; // Handle to section object
  35. } LSAP_SHARED_SECTION, * PLSAP_SHARED_SECTION ;
  36. typedef struct _LSAP_THREAD_TASK {
  37. LIST_ENTRY Next;
  38. struct _Session * pSession;
  39. LPTHREAD_START_ROUTINE pFunction;
  40. PVOID pvParameter;
  41. } LSAP_THREAD_TASK, * PLSAP_THREAD_TASK;
  42. typedef enum _LSAP_TASK_QUEUE_TYPE {
  43. QueueShared, // Queue shared by many threads
  44. QueueSingle, // Queue owned/run by single thread
  45. QueueShareRead, // Queue with dedicated thread, but
  46. // linked to other queue
  47. QueueZombie // Queue pending deletion
  48. } LSAP_TASK_QUEUE_TYPE;
  49. typedef struct _LSAP_TASK_QUEUE {
  50. LSAP_TASK_QUEUE_TYPE Type; // Type of Queue
  51. HANDLE hSemaphore; // Semaphore to gate access
  52. CRITICAL_SECTION Lock; // Per-q lock
  53. LONG Tasks; // Number of Tasks
  54. LIST_ENTRY pTasks; // List of tasks
  55. struct _LSAP_TASK_QUEUE * pNext; // Next Queue
  56. struct _LSAP_TASK_QUEUE * pShared; // Shared Queue
  57. LONG TotalThreads; // Total Threads (for Shared)
  58. LONG IdleThreads; // Idle Threads (for Shared)
  59. struct _LSAP_TASK_QUEUE * pOriginal; // "Parent" queue for shareread
  60. struct _Session * OwnerSession; // Owning session record
  61. LONGLONG TaskCounter; // Total number of tasks
  62. LONGLONG QueuedCounter; // Total number queued
  63. HANDLE StartSync; // Event for start syncing
  64. LONG MissedTasks; // Number of tasks grabbed by other threads
  65. LONG ReqThread ; // Number of times had to start another thd
  66. LONG MaxThreads ; // Max # threads
  67. LONG TaskHighWater ; // Max # tasks
  68. } LSAP_TASK_QUEUE, * PLSAP_TASK_QUEUE;
  69. typedef
  70. NTSTATUS (LSAP_SESSION_CONNECT_FN)(
  71. struct _Session * Session,
  72. PVOID Parameter
  73. );
  74. typedef LSAP_SESSION_CONNECT_FN * PLSAP_SESSION_CONNECT_FN ;
  75. typedef struct _LSAP_SESSION_CONNECT {
  76. LIST_ENTRY List ;
  77. PLSAP_SESSION_CONNECT_FN Callback ;
  78. ULONG ConnectFilter ;
  79. PVOID Parameter ;
  80. } LSAP_SESSION_CONNECT, * PLSAP_SESSION_CONNECT ;
  81. #define SESSION_CONNECT_TRUSTED 0x00000001
  82. #define SESSION_CONNECT_UNTRUSTED 0x00000002
  83. #define SESSION_CONNECT_KERNEL 0x00000004
  84. typedef HRESULT (LSAP_SESSION_RUNDOWN_FN)(
  85. struct _Session * Session,
  86. PVOID Parameter
  87. );
  88. typedef LSAP_SESSION_RUNDOWN_FN * PLSAP_SESSION_RUNDOWN_FN ;
  89. typedef struct _LSAP_SESSION_RUNDOWN {
  90. LIST_ENTRY List ;
  91. PLSAP_SESSION_RUNDOWN_FN Rundown ;
  92. PVOID Parameter ;
  93. } LSAP_SESSION_RUNDOWN, * PLSAP_SESSION_RUNDOWN ;
  94. typedef struct _LSAP_SHARED_SESSION_DATA {
  95. PVOID CredTable ;
  96. PVOID ContextTable ;
  97. PLSAP_TASK_QUEUE pQueue ;
  98. PHANDLE_PACKAGE CredHandlePackage ;
  99. PHANDLE_PACKAGE ContextHandlePackage ;
  100. ULONG cRefs ;
  101. } LSAP_SHARED_SESSION_DATA, * PLSAP_SHARED_SESSION_DATA ;
  102. typedef struct _Session {
  103. LIST_ENTRY List ;
  104. DWORD dwProcessID; // ID of the calling process
  105. PLSAP_SHARED_SESSION_DATA SharedData ; // Shared data for kernel sessions
  106. HANDLE hPort; // Comm port used by this ses
  107. DWORD fSession; // Flags
  108. HANDLE hProcess; // Handle to the process
  109. CRITICAL_SECTION SessionLock; // Session Lock
  110. LONG RefCount; // Reference Count
  111. PVOID pvStats; // Statistics
  112. PVOID NegotiateData; // Reserved for negotiate support
  113. DWORD ThreadId; // Dedicated Thread (possible)
  114. LPWSTR ClientProcessName; // name of the registering process
  115. ULONG SessionId; // Hydra Session Id
  116. LIST_ENTRY SectionList; // List of sharedsections
  117. LIST_ENTRY RundownList ; // List of rundown hooks
  118. LONGLONG CallCount ; // Calls processed
  119. ULONG Tick ; // Tick Count last snap
  120. LSAP_SHARED_SESSION_DATA DefaultData ;
  121. } Session, * PSession;
  122. #define SESFLAG_TASK_QUEUE 0x00000001 // Session has thread and queue
  123. #define SESFLAG_TCB_PRIV 0x00000002 // Client has TCB privilege
  124. #define SESFLAG_CLONE 0x00000004 // Assumed identity
  125. #define SESFLAG_IMPERSONATE 0x00000008 // Session is an impersonation
  126. #define SESFLAG_DESKTOP 0x00000010 // Session is using user's desktop
  127. #define SESFLAG_UNTRUSTED 0x00000020 // Session didn't require TCB priv
  128. #define SESFLAG_INPROC 0x00000040 // Session is an inprocess clone
  129. #define SESFLAG_AUTONOMOUS 0x00000080 // Autonomous thread
  130. #define SESFLAG_DEFAULT 0x00000100 // Default session for inactive
  131. #define SESFLAG_UNLOADING 0x00000200 // Session called SpmUnload
  132. #define SESFLAG_SCAVENGER 0x00000400 // Scavenger thread
  133. #define SESFLAG_CLEANUP 0x00000800 // Session is being deleted
  134. #define SESFLAG_KERNEL 0x00001000 // Handle list is shared kernel-mode list
  135. #define SESFLAG_RESTRICTED 0x00002000 // caller has a restricted token
  136. #define SESFLAG_MAYBEKERNEL 0x00004000 // might be kernel (see sesmgr.cxx)
  137. #define SESFLAG_EFS 0x00008000 // EFS session
  138. #define SESFLAG_SHADOW 0x00010000 // Shadow session until the real connection
  139. #define SESFLAG_WOW_PROCESS 0x00020000 // WOW64 Process
  140. extern PSession pDefaultSession;
  141. extern PSession pEfsSession ;
  142. extern LSAP_TASK_QUEUE GlobalQueue;
  143. BOOL
  144. InitSessionManager( void);
  145. VOID
  146. LsapFindEfsSession(
  147. VOID
  148. );
  149. VOID
  150. LsapUpdateEfsSession(
  151. PSession pSession
  152. );
  153. HRESULT
  154. CreateSession( CLIENT_ID * pCid,
  155. BOOL fOpenImmediate,
  156. PWCHAR ClientProcessName,
  157. ULONG Flags,
  158. PSession * ppSession);
  159. HRESULT
  160. CloneSession( PSession pOriginalSession,
  161. PSession * ppSession,
  162. ULONG Flags );
  163. NTSTATUS
  164. CreateShadowSession(
  165. DWORD ProcessId,
  166. PSession * NewSession
  167. );
  168. void
  169. FreeSession(PSession pSession);
  170. VOID
  171. SpmpReferenceSession(
  172. PSession pSession);
  173. VOID
  174. SpmpDereferenceSession(
  175. PSession pSession);
  176. VOID
  177. LsapSessionDisconnect(
  178. PSession pSession
  179. );
  180. BOOL
  181. AddRundown( PSession pSession,
  182. PLSAP_SESSION_RUNDOWN_FN RundownFn,
  183. PVOID pvParameter);
  184. BOOL
  185. DelRundown( PSession pSession,
  186. PLSAP_SESSION_RUNDOWN_FN RundownFn
  187. );
  188. BOOL
  189. AddConnectionHook(
  190. PLSAP_SESSION_CONNECT_FN ConnectFn,
  191. PVOID Parameter,
  192. ULONG Filter
  193. );
  194. BOOLEAN
  195. AddCredHandle( PSession pSession,
  196. PCredHandle phCred,
  197. ULONG Flags );
  198. BOOLEAN
  199. AddContextHandle( PSession pSession,
  200. PCtxtHandle phContext,
  201. ULONG Flags);
  202. NTSTATUS
  203. ValidateContextHandle(
  204. PSession pSession,
  205. PCtxtHandle phContext,
  206. PVOID * pKey
  207. );
  208. VOID
  209. DerefContextHandle(
  210. PSession pSession,
  211. PCtxtHandle phContext,
  212. PVOID Key OPTIONAL
  213. );
  214. NTSTATUS
  215. ValidateAndDerefContextHandle(
  216. PSession pSession,
  217. PCtxtHandle phContext
  218. );
  219. NTSTATUS
  220. ValidateCredHandle(
  221. PSession pSession,
  222. PCtxtHandle phCred,
  223. PVOID * pKey
  224. );
  225. VOID
  226. DerefCredHandle(
  227. PSession pSession,
  228. PCtxtHandle phCred,
  229. PVOID Key OPTIONAL
  230. );
  231. NTSTATUS
  232. ValidateAndDerefCredHandle(
  233. PSession pSession,
  234. PCtxtHandle phCred
  235. );
  236. BOOL
  237. LsapMoveContextHandle(
  238. PSecHandle Handle,
  239. PSession OriginatingSession,
  240. PSession DestinationSession
  241. );
  242. BOOL
  243. LsapMoveCredHandle(
  244. PSecHandle Handle,
  245. PSession OriginatingSession,
  246. PSession DestinationSession
  247. );
  248. BOOL
  249. GetMeClientDesktop(void);
  250. void
  251. DoneWithClientDesktop(void);
  252. //
  253. // PSession
  254. // GetCurrentSession( VOID );
  255. //
  256. #define GetCurrentSession() ((PSession) TlsGetValue( dwSession ))
  257. //
  258. // VOID
  259. // SetCurrentSession( PSession pSession );
  260. //
  261. #define SetCurrentSession( p ) TlsSetValue( dwSession, (PVOID) p )
  262. //
  263. // VOID
  264. // LockSession( PSession pSession );
  265. //
  266. #define LockSession( p ) RtlEnterCriticalSection( &(((PSession) p)->SessionLock) )
  267. //
  268. // VOID
  269. // UnlockSession( PSession pSession );
  270. //
  271. #define UnlockSession( p ) RtlLeaveCriticalSection( &(((PSession) p)->SessionLock) )
  272. #ifndef WIN32_CHICAGO
  273. #define GetCurrentPackageId() ((ULONG_PTR) TlsGetValue(dwThreadPackage))
  274. #ifdef LSAP_VERIFY_PACKAGE_ID
  275. extern BOOL RefSetCurrentPackageId(DWORD dwPackageId);
  276. #define SetCurrentPackageId(p) RefSetCurrentPackageId((DWORD) p)
  277. #else
  278. #define SetCurrentPackageId(p) TlsSetValue(dwThreadPackage, (PVOID)p)
  279. #endif // LSAP_VERIFY_PACKAGE_ID
  280. #else
  281. #define GetCurrentPackageId() 1
  282. #define SetCurrentPackageId(p)
  283. #endif // WIN32_CHICAGO
  284. VOID
  285. SesEnumPerfData(VOID);
  286. #ifdef __cplusplus
  287. } // extern C
  288. #endif
  289. #endif // __SESMGR_H__