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.

418 lines
15 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File: SPMGR.H
  8. //
  9. // Contents: Common structures and functions for the SPMgr
  10. //
  11. //
  12. // History: 20 May 92 RichardW Documented existing stuff
  13. // 22 Jul 93 RichardW Revised to be the one include file
  14. // for the spm directory
  15. //
  16. //------------------------------------------------------------------------
  17. #ifndef __SPMGR_H__
  18. #define __SPMGR_H__
  19. #define SECURITY_WIN32
  20. #define SECURITY_PACKAGE
  21. #include <security.h>
  22. #include <secint.h>
  23. #include <spmlpc.h>
  24. #include <lsapmsgs.h> // event log events
  25. // SPM-wide structure definitions:
  26. // This is the function table for a security package. All functions are
  27. // dispatched through this table.
  28. struct _DLL_BINDING;
  29. // This is the Security Package Control structure. All control information
  30. // relating to packages is stored here.
  31. typedef struct _LSAP_SECURITY_PACKAGE {
  32. ULONG_PTR dwPackageID; // Assigned package ID
  33. DWORD PackageIndex; // Package Index in DLL
  34. DWORD fPackage; // Flags about the package
  35. DWORD fCapabilities; // Capabilities that the package reported
  36. DWORD dwRPCID; // RPC ID
  37. DWORD Version;
  38. DWORD TokenSize;
  39. DWORD ContextHandles ; // Number of outstanding contexts
  40. DWORD CredentialHandles ; // ditto for credentials
  41. LONG CallsInProgress ; // Number of calls to this package
  42. SECURITY_STRING Name; // Name of the package
  43. SECURITY_STRING Comment;
  44. struct _DLL_BINDING * pBinding; // Binding of DLL
  45. PSECPKG_EXTENDED_INFORMATION Thunks ; // Thunked Context levels
  46. LIST_ENTRY ScavengerList ;
  47. SECURITY_STRING WowClientDll ;
  48. SECPKG_FUNCTION_TABLE FunctionTable; // Dispatch table
  49. } LSAP_SECURITY_PACKAGE, * PLSAP_SECURITY_PACKAGE;
  50. #define SP_INVALID 0x00000001 // Package is now invalid for use
  51. #define SP_PREFERRED 0x00000002 // The preferred package
  52. #define SP_INFO 0x00000004 // Supports Extended Info
  53. #define SP_SHUTDOWN 0x00000008 // Shutdown has completed
  54. #define SP_WOW_SUPPORT 0x00000010 // Package can support WOW6432 clients
  55. #define StartCallToPackage( p ) \
  56. InterlockedIncrement( &((PLSAP_SECURITY_PACKAGE)(p))->CallsInProgress )
  57. #define EndCallToPackage( p ) \
  58. InterlockedDecrement( &((PLSAP_SECURITY_PACKAGE)(p))->CallsInProgress )
  59. typedef struct _DLL_BINDING {
  60. DWORD Flags; // Flags about the DLL
  61. HANDLE hInstance; // Instance Handle
  62. SECURITY_STRING Filename; // Full path name
  63. DWORD RefCount; // Reference Count
  64. DWORD PackageCount; // Number of Packages in DLL
  65. LSAP_SECURITY_PACKAGE Packages[1];
  66. } DLL_BINDING, * PDLL_BINDING;
  67. #define DLL_BUILTIN 0x00000001 // DLL is really built-in code
  68. #define DLL_SIGNED 0x00000002 // DLL is signed
  69. //
  70. // Ordinals to the function pointers, for validating calls
  71. //
  72. #define SP_ORDINAL_LSA_INIT 0
  73. #define SP_ORDINAL_LOGONUSER 1
  74. #define SP_ORDINAL_CALLPACKAGE 2
  75. #define SP_ORDINAL_LOGONTERMINATED 3
  76. #define SP_ORDINAL_CALLPACKAGEUNTRUSTED 4
  77. #define SP_ORDINAL_CALLPACKAGEPASSTHROUGH 5
  78. #define SP_ORDINAL_LOGONUSEREX 6
  79. #define SP_ORDINAL_LOGONUSEREX2 7
  80. #define SP_ORDINAL_INITIALIZE 8
  81. #define SP_ORDINAL_SHUTDOWN 9
  82. #define SP_ORDINAL_GETINFO 10
  83. #define SP_ORDINAL_ACCEPTCREDS 11
  84. #define SP_ORDINAL_ACQUIRECREDHANDLE 12
  85. #define SP_ORDINAL_QUERYCREDATTR 13
  86. #define SP_ORDINAL_FREECREDHANDLE 14
  87. #define SP_ORDINAL_SAVECRED 15
  88. #define SP_ORDINAL_GETCRED 16
  89. #define SP_ORDINAL_DELETECRED 17
  90. #define SP_ORDINAL_INITLSAMODECTXT 18
  91. #define SP_ORDINAL_ACCEPTLSAMODECTXT 19
  92. #define SP_ORDINAL_DELETECTXT 20
  93. #define SP_ORDINAL_APPLYCONTROLTOKEN 21
  94. #define SP_ORDINAL_GETUSERINFO 22
  95. #define SP_ORDINAL_GETEXTENDEDINFORMATION 23
  96. #define SP_ORDINAL_QUERYCONTEXTATTRIBUTES 24
  97. #define SP_ORDINAL_ADDCREDENTIALS 25
  98. #define SP_ORDINAL_SETEXTENDEDINFORMATION 26
  99. #define SP_ORDINAL_SETCONTEXTATTRIBUTES 27
  100. #define SP_MAX_TABLE_ORDINAL (SP_ORDINAL_SETCONTEXTATTRIBUTES + 1)
  101. #define SP_MAX_AUTHPKG_ORDINAL (SP_ORDINAL_LOGONUSEREX)
  102. #define SP_ORDINAL_MASK 0x0000FFFF
  103. #define SP_ITERATE_FILTER_WOW 0x00010000
  104. typedef struct _LsaState {
  105. DWORD cPackages ;
  106. DWORD cNewPackages ;
  107. } LsaState ;
  108. typedef enum _SECHANDLE_OPS {
  109. HandleSet, // Just set the new handle
  110. HandleReplace, // Replace the existing one
  111. HandleRemoveReplace // Remove provided, replace with provided
  112. } SECHANDLE_OPS ;
  113. typedef struct _LSA_TUNING_PARAMETERS {
  114. ULONG ThreadLifespan ; // lifespan for threads in gen. pool
  115. ULONG SubQueueLifespan ; // lifespan for dedicated threads
  116. ULONG Options ; // Option flags
  117. ULONG CritSecSpinCount ; // spin count of critical sections
  118. } LSA_TUNING_PARAMETERS, * PLSA_TUNING_PARAMETERS ;
  119. #define TUNE_SRV_HIGH_PRIORITY 0x00000001
  120. #define TUNE_TRIM_WORKING_SET 0x00000002
  121. #define TUNE_PRIVATE_HEAP 0x00000010
  122. //
  123. // Redefine IsOkayToExec
  124. //
  125. #define IsOkayToExec(x)
  126. // For some tracking purposes, the package ID for the SPMgr is a well known
  127. // constant:
  128. #define SPMGR_ID ((LSA_SEC_HANDLE) INVALID_HANDLE_VALUE)
  129. #define SPMGR_PKG_ID ((LSA_SEC_HANDLE) INVALID_HANDLE_VALUE)
  130. //
  131. // Value to pass to shutdown handler
  132. //
  133. #define SPM_SHUTDOWN_VALUE 0xD0
  134. //
  135. // Creating process name for LSA sessions
  136. //
  137. #define LSA_PROCESS_NAME L"LSA Server"
  138. //
  139. // ID of the primary package
  140. //
  141. #define PRIMARY_ID 0
  142. typedef struct _SpmExceptDbg {
  143. DWORD ThreadId;
  144. PVOID pInstruction;
  145. PVOID pMemory;
  146. ULONG_PTR Access;
  147. } SpmExceptDbg, * PSpmExceptDbg;
  148. //
  149. // Internal Exception Handling:
  150. //
  151. // If we hit an exception in a debug build, we store away some useful stuff
  152. // otherwise, we go to the default case:
  153. //
  154. LONG SpExceptionFilter(PVOID, EXCEPTION_POINTERS *);
  155. #define SP_EXCEPTION SpExceptionFilter(GetCurrentSession(), GetExceptionInformation())
  156. //
  157. // Include other component header files
  158. //
  159. #ifdef __cplusplus
  160. extern "C" {
  161. #endif
  162. #include "sesmgr.h" // Session manager support
  163. #include "sphelp.h" // Internal helper functions
  164. #include "protos.h" // Internal Prototypes
  165. #include "debug.h" // Debugging Support:
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. typedef struct _LSAP_DBG_LOG_CONTEXT {
  170. PSession Session ; // Session used
  171. SecHandle Handle ; // Handle used
  172. } LSAP_DBG_LOG_CONTEXT, *PLSAP_DBG_LOG_CONTEXT ;
  173. typedef struct _LSAP_API_LOG_ENTRY {
  174. ULONG MessageId ; // LPC Message ID
  175. ULONG ThreadId ; // Thread ID handling call
  176. PVOID pvMessage ; // LPC Message
  177. PVOID WorkItem ; // Work item for API
  178. LARGE_INTEGER QueueTime ; // Time Queued
  179. LARGE_INTEGER WorkTime ; // Work Time
  180. PVOID Reserved ; // Alignment
  181. LSAP_DBG_LOG_CONTEXT Context ; // Context
  182. } LSAP_API_LOG_ENTRY, * PLSAP_API_LOG_ENTRY ;
  183. typedef struct _LSAP_API_LOG {
  184. ULONG TotalSize ;
  185. ULONG Current ;
  186. ULONG ModSize ;
  187. ULONG Align ;
  188. LSAP_API_LOG_ENTRY Entries[ 1 ];
  189. } LSAP_API_LOG, * PLSAP_API_LOG ;
  190. PLSAP_API_LOG
  191. ApiLogCreate(
  192. ULONG Entries
  193. );
  194. PLSAP_API_LOG_ENTRY
  195. ApiLogAlloc(
  196. PLSAP_API_LOG Log
  197. );
  198. PLSAP_API_LOG_ENTRY
  199. ApiLogLocate(
  200. PLSAP_API_LOG Log,
  201. ULONG MessageId
  202. );
  203. #define DEFAULT_LOG_SIZE 32
  204. //#if DBG
  205. #define DBG_TRACK_API 1
  206. //#endif
  207. #if DBG_TRACK_API
  208. #define DBG_DISPATCH_PROLOGUE_EX( Entry, pMessage, CallInfo ) \
  209. if ( Entry ) \
  210. { \
  211. Entry->ThreadId = GetCurrentThreadId() ; \
  212. CallInfo.LogContext = & Entry->Context ; \
  213. GetSystemTimeAsFileTime( (LPFILETIME) &Entry->WorkTime ) ; \
  214. } \
  215. else \
  216. { \
  217. CallInfo.LogContext = NULL ; \
  218. }
  219. #define DBG_DISPATCH_PROLOGUE( Table, pMessage, CallInfo ) \
  220. PLSAP_API_LOG_ENTRY Entry ; \
  221. \
  222. Entry = ApiLogLocate( Table, ((PPORT_MESSAGE) pMessage)->MessageId ); \
  223. DBG_DISPATCH_PROLOGUE_EX( Entry, pMessage, CallInfo ) \
  224. #define DBG_DISPATCH_POSTLOGUE( Status, ApiCode ) \
  225. if ( Entry ) \
  226. { \
  227. LARGE_INTEGER EndTime ; \
  228. GetSystemTimeAsFileTime( (LPFILETIME) & EndTime ); \
  229. Entry->Reserved = ULongToPtr(Entry->ThreadId); \
  230. Entry->ThreadId = (DWORD) 0xFFFFFFFF ; \
  231. Entry->WorkItem = (PVOID) Status ; \
  232. Entry->pvMessage = (PVOID) ApiCode ; \
  233. Entry->QueueTime.QuadPart = EndTime.QuadPart ; \
  234. Entry->WorkTime.QuadPart = EndTime.QuadPart - Entry->WorkTime.QuadPart ; \
  235. }
  236. #else
  237. #define DBG_DISPATCH_PROLOGUE_EX( Entry, pMessage, CallInfo ) CallInfo.LogContext = NULL
  238. #define DBG_DISPATCH_PROLOGUE( Table, pApi, CallInfo ) CallInfo.LogContext = NULL
  239. #define DBG_DISPATCH_POSTLOGUE( Status, ApiCode )
  240. #endif
  241. typedef struct _LSA_CALL_INFO {
  242. PSPM_LPC_MESSAGE Message ;
  243. struct _LSA_CALL_INFO * PreviousCall ;
  244. PSession Session ;
  245. PLSAP_DBG_LOG_CONTEXT LogContext ;
  246. SECPKG_CALL_INFO CallInfo ;
  247. //
  248. // LogonId, ImpersonationLevel, Impersonating, Restricted
  249. // are considered valid CachedTokenInfo is TRUE
  250. //
  251. LUID LogonId ;
  252. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel;
  253. BOOLEAN Impersonating;
  254. BOOLEAN Restricted;
  255. BOOLEAN CachedTokenInfo;
  256. HANDLE InProcToken ;
  257. BOOL InProcCall ;
  258. ULONG Flags ;
  259. ULONG Allocs ;
  260. PKSEC_LSA_MEMORY_HEADER KMap ;
  261. PVOID Buffers[ MAX_BUFFERS_IN_CALL ];
  262. BYTE IpAddress[ LSAP_ADDRESS_LENGTH ];
  263. } LSA_CALL_INFO, * PLSA_CALL_INFO ;
  264. #define LsapGetCurrentCall() ((PLSA_CALL_INFO) TlsGetValue( dwCallInfo ))
  265. #define LsapSetCurrentCall(x) TlsSetValue( dwCallInfo, x )
  266. #define CALL_FLAG_IMPERSONATING 0x00000001
  267. #define CALL_FLAG_IN_PROC_CALL 0x00000002
  268. #define CALL_FLAG_SUPRESS_AUDIT 0x00000004
  269. #define CALL_FLAG_NO_HANDLE_CHK 0x00000008
  270. #define CALL_FLAG_KERNEL_POOL 0x00000010 // Kernel mode call, using pool
  271. #define CALL_FLAG_KMAP_USED 0x00000020 // KMap is valid
  272. //
  273. //BOOL
  274. //LsapIsBlockInKMap( KMap, Block )
  275. //
  276. #define LsapIsBlockInKMap( KMap, Block ) \
  277. ( KMap ? (((ULONG_PTR) KMap ^ (ULONG_PTR) Block ) < (ULONG_PTR) KMap->Commit) : FALSE )
  278. NTSTATUS
  279. InitializeDirectDispatcher(
  280. VOID
  281. );
  282. VOID
  283. LsapInitializeCallInfo(
  284. PLSA_CALL_INFO CallInfo,
  285. BOOL InProcess
  286. );
  287. NTSTATUS
  288. LsapBuildCallInfo(
  289. PSPM_LPC_MESSAGE pApiMessage,
  290. PLSA_CALL_INFO CallInfo,
  291. PHANDLE Impersonated,
  292. PSession * NewSession,
  293. PSession * OldSession
  294. );
  295. VOID
  296. LsapInternalBreak(
  297. VOID
  298. );
  299. #define LsapLogCallInfo( CallInfo, pSession, cHandle ) \
  300. if ( CallInfo && ( CallInfo->LogContext ) ) \
  301. { \
  302. CallInfo->LogContext->Session = pSession ; \
  303. CallInfo->LogContext->Handle = cHandle; \
  304. } \
  305. //
  306. // Global variables
  307. //
  308. extern LSA_SECPKG_FUNCTION_TABLE LsapSecpkgFunctionTable;
  309. // Dispatch table of helper functions
  310. extern LUID SystemLogonId; // System LogonID for packages.
  311. extern SECURITY_STRING MachineName; // Computer name
  312. extern HANDLE hStateChangeEvent; // Event set when the system state is changed
  313. extern HANDLE hShutdownEvent;
  314. extern LSA_CALL_INFO LsapDefaultCallInfo ;
  315. extern ULONG LsapPageSize ; // Set to the page size during init
  316. extern ULONG_PTR LsapUserModeLimit ; // Set the to max user mode address
  317. //
  318. // Thread Local Storage variables
  319. //
  320. // These are actually all indices into the tls area, accessed through the
  321. // TlsXxx functions. These are all initialized by the InitThreadData()
  322. // function
  323. //
  324. extern DWORD dwSession; // Session pointer
  325. extern DWORD dwExceptionInfo; // Gets a pointer to exception info
  326. extern DWORD dwThreadPackage; // Package ID for thread
  327. extern DWORD dwCallInfo ; // CallInfo pointer
  328. extern DWORD dwThreadHeap; // Heap assigned to current thread.
  329. // Last known workstation status:
  330. extern BOOLEAN SetupPhase; // If true, setup is running
  331. extern BOOL ShutdownBegun ; // when true, shutdown is running
  332. extern LSA_TUNING_PARAMETERS LsaTuningParameters ;
  333. extern LsaState lsState ;
  334. extern PWSTR * ppszPackages; // Contains a null terminated array of dll names
  335. extern PWSTR * ppszOldPkgs; // Contains a null terminated array of old pkgs
  336. //
  337. // Maximum size of a buffer that can be passed across an LPC call
  338. //
  339. #define LSAP_MAX_LPC_BUFFER_LENGTH (1024 * 1024)
  340. #endif // __SPMGR_H__