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.

292 lines
9.1 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. typedef HRESULT (LSAP_SESSION_RUNDOWN_FN)(
  82. struct _Session * Session,
  83. PVOID Parameter
  84. );
  85. typedef LSAP_SESSION_RUNDOWN_FN * PLSAP_SESSION_RUNDOWN_FN ;
  86. typedef struct _LSAP_SESSION_RUNDOWN {
  87. LIST_ENTRY List ;
  88. PLSAP_SESSION_RUNDOWN_FN Rundown ;
  89. PVOID Parameter ;
  90. } LSAP_SESSION_RUNDOWN, * PLSAP_SESSION_RUNDOWN ;
  91. typedef struct _LSAP_SHARED_SESSION_DATA {
  92. PVOID CredTable ;
  93. PVOID ContextTable ;
  94. PLSAP_TASK_QUEUE pQueue ;
  95. PHANDLE_PACKAGE CredHandlePackage ;
  96. PHANDLE_PACKAGE ContextHandlePackage ;
  97. ULONG cRefs ;
  98. } LSAP_SHARED_SESSION_DATA, * PLSAP_SHARED_SESSION_DATA ;
  99. typedef struct _Session {
  100. LIST_ENTRY List ;
  101. DWORD dwProcessID; // ID of the calling process
  102. PLSAP_SHARED_SESSION_DATA SharedData ; // Shared data for kernel sessions
  103. HANDLE hPort; // Comm port used by this ses
  104. DWORD fSession; // Flags
  105. HANDLE hProcess; // Handle to the process
  106. CRITICAL_SECTION SessionLock; // Session Lock
  107. LONG RefCount; // Reference Count
  108. DWORD ThreadId; // Dedicated Thread (possible)
  109. LPWSTR ClientProcessName; // name of the registering process
  110. ULONG SessionId; // Hydra Session Id
  111. LIST_ENTRY SectionList; // List of sharedsections
  112. LIST_ENTRY RundownList ; // List of rundown hooks
  113. LONGLONG CallCount ; // Calls processed
  114. ULONG Tick ; // Tick Count last snap
  115. LSAP_SHARED_SESSION_DATA DefaultData ;
  116. } Session, * PSession;
  117. #define SESFLAG_TCB_PRIV 0x00000002 // Client has TCB privilege
  118. #define SESFLAG_CLONE 0x00000004 // Assumed identity
  119. #define SESFLAG_IMPERSONATE 0x00000008 // Session is an impersonation
  120. #define SESFLAG_UNTRUSTED 0x00000020 // Session didn't require TCB priv
  121. #define SESFLAG_INPROC 0x00000040 // Session is an inprocess clone
  122. #define SESFLAG_DEFAULT 0x00000100 // Default session for inactive
  123. #define SESFLAG_UNLOADING 0x00000200 // Session called SpmUnload
  124. #define SESFLAG_CLEANUP 0x00000800 // Session is being deleted
  125. #define SESFLAG_KERNEL 0x00001000 // Handle list is shared kernel-mode list
  126. #define SESFLAG_MAYBEKERNEL 0x00004000 // might be kernel (see sesmgr.cxx)
  127. #define SESFLAG_EFS 0x00008000 // EFS session
  128. #define SESFLAG_WOW_PROCESS 0x00020000 // WOW64 Process
  129. extern PSession pDefaultSession;
  130. extern PSession pEfsSession ;
  131. extern LSAP_TASK_QUEUE GlobalQueue;
  132. BOOL
  133. InitSessionManager( void);
  134. VOID
  135. LsapFindEfsSession(
  136. VOID
  137. );
  138. VOID
  139. LsapUpdateEfsSession(
  140. PSession pSession
  141. );
  142. HRESULT
  143. CreateSession( CLIENT_ID * pCid,
  144. BOOL fOpenImmediate,
  145. PWCHAR ClientProcessName,
  146. ULONG Flags,
  147. PSession * ppSession);
  148. HRESULT
  149. CloneSession( PSession pOriginalSession,
  150. PSession * ppSession,
  151. ULONG Flags );
  152. void
  153. FreeSession(PSession pSession);
  154. VOID
  155. SpmpReferenceSession(
  156. PSession pSession);
  157. VOID
  158. SpmpDereferenceSession(
  159. PSession pSession);
  160. VOID
  161. LsapSessionDisconnect(
  162. PSession pSession
  163. );
  164. BOOL
  165. AddRundown( PSession pSession,
  166. PLSAP_SESSION_RUNDOWN_FN RundownFn,
  167. PVOID pvParameter);
  168. BOOL
  169. DelRundown( PSession pSession,
  170. PLSAP_SESSION_RUNDOWN_FN RundownFn
  171. );
  172. BOOLEAN
  173. AddCredHandle( PSession pSession,
  174. PCredHandle phCred,
  175. ULONG Flags );
  176. BOOLEAN
  177. AddContextHandle( PSession pSession,
  178. PCtxtHandle phContext,
  179. ULONG Flags);
  180. NTSTATUS
  181. ValidateContextHandle(
  182. PSession pSession,
  183. PCtxtHandle phContext,
  184. PVOID * pKey
  185. );
  186. VOID
  187. DerefContextHandle(
  188. PSession pSession,
  189. PCtxtHandle phContext,
  190. PVOID Key OPTIONAL
  191. );
  192. NTSTATUS
  193. ValidateAndDerefContextHandle(
  194. PSession pSession,
  195. PCtxtHandle phContext
  196. );
  197. NTSTATUS
  198. ValidateCredHandle(
  199. PSession pSession,
  200. PCtxtHandle phCred,
  201. PVOID * pKey
  202. );
  203. VOID
  204. DerefCredHandle(
  205. PSession pSession,
  206. PCtxtHandle phCred,
  207. PVOID Key OPTIONAL
  208. );
  209. NTSTATUS
  210. ValidateAndDerefCredHandle(
  211. PSession pSession,
  212. PCtxtHandle phCred
  213. );
  214. //
  215. // PSession
  216. // GetCurrentSession( VOID );
  217. //
  218. #define GetCurrentSession() ((PSession) TlsGetValue( dwSession ))
  219. //
  220. // VOID
  221. // SetCurrentSession( PSession pSession );
  222. //
  223. #define SetCurrentSession( p ) TlsSetValue( dwSession, (PVOID) p )
  224. //
  225. // VOID
  226. // LockSession( PSession pSession );
  227. //
  228. #define LockSession( p ) RtlEnterCriticalSection( &(((PSession) p)->SessionLock) )
  229. //
  230. // VOID
  231. // UnlockSession( PSession pSession );
  232. //
  233. #define UnlockSession( p ) RtlLeaveCriticalSection( &(((PSession) p)->SessionLock) )
  234. #define GetCurrentPackageId() ((ULONG_PTR) TlsGetValue(dwThreadPackage))
  235. #ifdef LSAP_VERIFY_PACKAGE_ID
  236. extern BOOL RefSetCurrentPackageId(DWORD dwPackageId);
  237. #define SetCurrentPackageId(p) RefSetCurrentPackageId((DWORD) p)
  238. #else
  239. #define SetCurrentPackageId(p) TlsSetValue(dwThreadPackage, (PVOID)p)
  240. #endif // LSAP_VERIFY_PACKAGE_ID
  241. #ifdef __cplusplus
  242. } // extern C
  243. #endif
  244. #endif // __SESMGR_H__