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.

960 lines
29 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File: SPMLPC.H
  8. //
  9. // Contents: Defines for the LPC to the SPMgr
  10. //
  11. //
  12. // History: 2 Mar 94 MikeSw Created
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef __SPMLPC_H__
  16. #define __SPMLPC_H__
  17. //
  18. // Pickup the LSA lpc messages for compatiblity
  19. //
  20. #pragma warning(disable:4200)
  21. #include <efsstruc.h>
  22. #include <aup.h>
  23. #define SPM_PORTNAME L"\\LsaAuthenticationPort"
  24. #define SPM_EVENTNAME L"\\SECURITY\\LSA_AUTHENTICATION_INITIALIZED"
  25. #define SPM_AUTH_PKG_FLAG 0x00001000
  26. //
  27. // Buffers that will fit into the message are placed in there and the
  28. // their pointers will be replaced with this value. Since all buffers and
  29. // strings are sent with their lengths, to unpack the data move pull out the
  30. // buffers in the order they are listed in the API message.
  31. //
  32. // Since all buffers must be passed from VM, any address above 0x80000000
  33. // will not be confused for an address
  34. //
  35. #define SEC_PACKED_BUFFER_VALUE (IntToPtr(0xFFFFFFFF))
  36. //
  37. // Max secbuffers allowed in a SecBufferDesc
  38. //
  39. #define MAX_SECBUFFERS 10
  40. //
  41. // This bit gets set in the SecurityMode word, indicating that the DLL
  42. // is running in the LSA process. The DLL will turn around and get the
  43. // direct dispatch routine, and avoid the whole LPC issue
  44. //
  45. #define LSA_MODE_SAME_PROCESS 0x00010000
  46. //
  47. // This flag is added to the version information in a SecBufferDesc to
  48. // indicate that the memory is already mapped to the LSA.
  49. //
  50. #define LSA_MEMORY_KERNEL_MAP 0x80000000
  51. #define LSA_SECBUFFER_VERSION_MASK 0x0000FFFF
  52. //
  53. // Conditional type definition for Wow64 environment. The LPC messages
  54. // are kept "native" size, so pointers are full size. The WOW environment
  55. // will do the thunking. LPC messages are defined with types that are
  56. // always the correct size using these "aliases".
  57. //
  58. #ifdef BUILD_WOW64
  59. #pragma message("Building for WOW64")
  60. #define ALIGN_WOW64 __declspec(align(8))
  61. #define GET_WOW64_PTR(_Wow64Ptr_) PtrToUlong(_Wow64Ptr_)
  62. #define POINTER_FORMAT "%I64X"
  63. #if 0
  64. typedef WCHAR * __ptr64 PWSTR_LPC ;
  65. typedef VOID * __ptr64 PVOID_LPC ;
  66. #else
  67. typedef ULONGLONG PWSTR_LPC ;
  68. typedef ULONGLONG PVOID_LPC ;
  69. typedef ULONGLONG PSID_LPC ;
  70. #endif
  71. typedef struct _SECURITY_STRING_WOW64 {
  72. USHORT Length ;
  73. USHORT MaximumLength ;
  74. PWSTR_LPC Buffer ;
  75. } SECURITY_STRING_WOW64, * PSECURITY_STRING_WOW64 ;
  76. typedef struct _SEC_HANDLE_WOW64 {
  77. PVOID_LPC dwLower ;
  78. PVOID_LPC dwUpper ;
  79. } SEC_HANDLE_WOW64, * PSEC_HANDLE_WOW64 ;
  80. typedef struct _SEC_BUFFER_WOW64 {
  81. unsigned long cbBuffer ;
  82. unsigned long BufferType ;
  83. PVOID_LPC pvBuffer ;
  84. } SEC_BUFFER_WOW64, * PSEC_BUFFER_WOW64 ;
  85. typedef struct _SEC_BUFFER_DESC_WOW64 {
  86. unsigned long ulVersion ;
  87. unsigned long cBuffers ;
  88. PVOID_LPC pBuffers ;
  89. } SEC_BUFFER_DESC_WOW64, * PSEC_BUFFER_DESC_WOW64 ;
  90. typedef struct _SECPKG_INFO_WOW64 {
  91. ULONG fCapabilities;
  92. USHORT wVersion;
  93. USHORT wRPCID;
  94. ULONG cbMaxToken;
  95. PWSTR_LPC Name;
  96. PWSTR_LPC Comment;
  97. }
  98. SECPKG_INFO_WOW64, * PSECPKG_INFO_WOW64;
  99. typedef struct _SECPKGCONTEXT_NEGOTIATIONINFOWOW64
  100. {
  101. PVOID_LPC pPackageInfo64;
  102. ULONG NegotiationState;
  103. }
  104. SECPKGCONTEXT_NEGOTIATIONINFOWOW64, *PSECPKGCONTEXT_NEGOTIATIONINFOWOW64;
  105. typedef struct _SECURITY_USER_DATA_WOW64 {
  106. SECURITY_STRING_WOW64 UserName;
  107. SECURITY_STRING_WOW64 LogonDomainName;
  108. SECURITY_STRING_WOW64 LogonServer;
  109. PSID_LPC pSid;
  110. }
  111. SECURITY_USER_DATA_WOW64, * PSECURITY_USER_DATA_WOW64;
  112. typedef SECURITY_STRING_WOW64 SECURITY_STRING_LPC ;
  113. typedef SEC_HANDLE_WOW64 SEC_HANDLE_LPC ;
  114. typedef SEC_BUFFER_DESC_WOW64 SEC_BUFFER_DESC_LPC ;
  115. typedef SEC_BUFFER_WOW64 SEC_BUFFER_LPC ;
  116. typedef PVOID_LPC LSA_SEC_HANDLE_LPC ;
  117. #define SecpSecurityStringToLpc( L, S ) \
  118. (L)->Length = (S)->Length ; \
  119. (L)->MaximumLength = (S)->MaximumLength ; \
  120. (L)->Buffer = (PWSTR_LPC) GET_WOW64_PTR(((S)->Buffer)) ;
  121. #define SecpLpcStringToSecurityString( S, L ) \
  122. (S)->Length = (L)->Length ; \
  123. (S)->MaximumLength = (L)->MaximumLength ; \
  124. (S)->Buffer = (PWSTR) ( (L)->Buffer ); \
  125. #define SecpSecBufferToLpc( L, S )\
  126. (L)->cbBuffer = (S)->cbBuffer ; \
  127. (L)->BufferType = (S)->BufferType ; \
  128. (L)->pvBuffer = (PVOID_LPC) GET_WOW64_PTR((S)->pvBuffer) ;
  129. #define SecpLpcBufferToSecBuffer( S, L ) \
  130. (S)->cbBuffer = (L)->cbBuffer ; \
  131. (S)->BufferType = (L)->BufferType ; \
  132. (S)->pvBuffer = (PVOID) (L)->pvBuffer ;
  133. #define SecpSecBufferDescToLpc( L, S )\
  134. (L)->ulVersion = (S)->ulVersion ; \
  135. (L)->cBuffers = (S)->cBuffers ; \
  136. (L)->pBuffers = (PVOID_LPC) GET_WOW64_PTR((S)->pBuffers) ;
  137. #define SecpLpcBufferDescToSecBufferDesc( S, L ) \
  138. (S)->ulVersion = (L)->ulVersion ; \
  139. (S)->cBuffers = (L)->cBuffers ; \
  140. (S)->pBuffers = (PSecBuffer) (L)->pBuffers ;
  141. #define SecpSecPkgInfoToLpc( L, S ) \
  142. (L)->fCapabilities = (S)->fCapabilities ; \
  143. (L)->wVersion = (S)->wVersion ; \
  144. (L)->wRPCID = (S)->wRPCID ; \
  145. (L)->cbMaxToken = (S)->cbMaxToken ; \
  146. (L)->Name = (PWSTR_LPC) (S)->Name ; \
  147. (L)->Comment = (PWSTR_LPC) GET_WOW64_PTR((S)->Comment) ;
  148. #define SecpLpcPkgInfoToSecPkgInfo( S, L ) \
  149. (S)->fCapabilities = (L)->fCapabilities ; \
  150. (S)->wVersion = (L)->wVersion ; \
  151. (S)->wRPCID = (L)->wRPCID ; \
  152. (S)->cbMaxToken = (L)->cbMaxToken ; \
  153. (S)->Name = (SEC_WCHAR *) (L)->Name ; \
  154. (S)->Comment = (SEC_WCHAR *) (L)->Comment ;
  155. #else
  156. #define ALIGN_WOW64
  157. #define POINTER_FORMAT "%p"
  158. typedef SECURITY_STRING SECURITY_STRING_LPC ;
  159. typedef PVOID PVOID_LPC ;
  160. typedef SecHandle SEC_HANDLE_LPC ;
  161. typedef SecBufferDesc SEC_BUFFER_DESC_LPC ;
  162. typedef SecBuffer SEC_BUFFER_LPC ;
  163. typedef PWSTR PWSTR_LPC ;
  164. typedef LSA_SEC_HANDLE LSA_SEC_HANDLE_LPC ;
  165. #define SecpSecurityStringToLpc( L, S ) \
  166. *(L) = *(S) ;
  167. #define SecpLpcStringToSecurityString( S, L ) \
  168. *(S) = *(L) ;
  169. #define SecpSecBufferToLpc( L, S ) \
  170. *(L) = *(S) ;
  171. #define SecpLpcBufferToSecBuffer( S, L ) \
  172. *(S) = *(L) ;
  173. #define SecpSecBufferDescToLpc( L, S ) \
  174. *(L) = *(S) ;
  175. #define SecpLpcBufferDescToSecBufferDesc( S, L ) \
  176. *(S) = *(L) ;
  177. #endif
  178. typedef SEC_HANDLE_LPC CRED_HANDLE_LPC, * PCRED_HANDLE_LPC ;
  179. typedef SEC_HANDLE_LPC CONTEXT_HANDLE_LPC, * PCONTEXT_HANDLE_LPC ;
  180. typedef SEC_HANDLE_LPC * PSEC_HANDLE_LPC ;
  181. typedef SEC_BUFFER_LPC * PSEC_BUFFER_LPC ;
  182. //
  183. // Connection specific data types
  184. //
  185. //
  186. // The following are message structures for internal routines, such as
  187. // synchronization and state messages
  188. //
  189. #define PACKAGEINFO_THUNKS 16
  190. typedef struct _SEC_PACKAGE_BINDING_INFO_LPC {
  191. SECURITY_STRING_LPC PackageName;
  192. SECURITY_STRING_LPC Comment;
  193. SECURITY_STRING_LPC ModuleName;
  194. ULONG PackageIndex;
  195. ULONG fCapabilities;
  196. ULONG Flags;
  197. ULONG RpcId;
  198. ULONG Version;
  199. ULONG TokenSize;
  200. ULONG ContextThunksCount ;
  201. ULONG ContextThunks[ PACKAGEINFO_THUNKS ] ;
  202. } SEC_PACKAGE_BINDING_INFO_LPC, * PSEC_PACKAGE_BINDING_INFO_LPC ;
  203. #ifdef BUILD_WOW64
  204. typedef struct _SEC_PACKAGE_BINDING_INFO {
  205. SECURITY_STRING PackageName;
  206. SECURITY_STRING Comment;
  207. SECURITY_STRING ModuleName;
  208. ULONG PackageIndex;
  209. ULONG fCapabilities;
  210. ULONG Flags;
  211. ULONG RpcId;
  212. ULONG Version;
  213. ULONG TokenSize;
  214. ULONG ContextThunksCount ;
  215. ULONG ContextThunks[ PACKAGEINFO_THUNKS ] ;
  216. } SEC_PACKAGE_BINDING_INFO, * PSEC_PACKAGE_BINDING_INFO ;
  217. #else
  218. typedef SEC_PACKAGE_BINDING_INFO_LPC SEC_PACKAGE_BINDING_INFO ;
  219. typedef SEC_PACKAGE_BINDING_INFO_LPC * PSEC_PACKAGE_BINDING_INFO ;
  220. #endif
  221. #define PACKAGEINFO_BUILTIN 0x00000001
  222. #define PACKAGEINFO_AUTHPKG 0x00000002
  223. #define PACKAGEINFO_SIGNED 0x00000004
  224. typedef struct _SPMGetBindingAPI {
  225. LSA_SEC_HANDLE_LPC ulPackageId;
  226. SEC_PACKAGE_BINDING_INFO_LPC BindingInfo;
  227. } SPMGetBindingAPI;
  228. //
  229. // Internal SetSession API.
  230. // not supported in Wow64
  231. //
  232. typedef struct _SPMSetSession {
  233. ULONG Request;
  234. ULONG_PTR Argument ;
  235. ULONG_PTR Response;
  236. PVOID ResponsePtr;
  237. PVOID Extra ;
  238. } SPMSetSessionAPI;
  239. #define SETSESSION_GET_STATUS 0x00000001
  240. #define SETSESSION_ADD_WORKQUEUE 0x00000002
  241. #define SETSESSION_REMOVE_WORKQUEUE 0x00000003
  242. #define SETSESSION_GET_DISPATCH 0x00000004
  243. typedef struct _SPMFindPackageAPI {
  244. SECURITY_STRING_LPC ssPackageName;
  245. LSA_SEC_HANDLE_LPC ulPackageId;
  246. } SPMFindPackageAPI;
  247. // The following are message structures. Not surprisingly, they look a
  248. // lot like the API signatures. Keep that in mind.
  249. // EnumeratePackages API
  250. typedef struct _SPMEnumPackagesAPI {
  251. ULONG cPackages; // OUT
  252. PSecPkgInfo pPackages; // OUT
  253. } SPMEnumPackagesAPI;
  254. //
  255. // Credential APIs
  256. //
  257. // AcquireCredentialsHandle API
  258. typedef struct _SPMAcquireCredsAPI {
  259. SECURITY_STRING_LPC ssPrincipal; // IN
  260. SECURITY_STRING_LPC ssSecPackage; // IN
  261. ULONG fCredentialUse; // IN
  262. LUID LogonID; // IN
  263. PVOID_LPC pvAuthData; // IN
  264. PVOID_LPC pvGetKeyFn; // IN
  265. PVOID_LPC ulGetKeyArgument; // IN
  266. CRED_HANDLE_LPC hCredential; // OUT
  267. TimeStamp tsExpiry; // OUT
  268. SEC_BUFFER_LPC AuthData ; // IN
  269. } SPMAcquireCredsAPI;
  270. // EstablishCredentials API
  271. // not supported in Wow64
  272. typedef struct _SPMEstablishCredsAPI {
  273. SECURITY_STRING Name; // IN
  274. SECURITY_STRING Package; // IN
  275. ULONG cbKey; // IN
  276. PUCHAR pbKey; // IN
  277. CredHandle hCredentials; // OUT
  278. TimeStamp tsExpiry; // OUT
  279. } SPMEstablishCredsAPI;
  280. // FreeCredentialsHandle API
  281. typedef struct _SPMFreeCredHandleAPI {
  282. CRED_HANDLE_LPC hCredential;
  283. } SPMFreeCredHandleAPI;
  284. //
  285. // Context APIs
  286. //
  287. // InitializeSecurityContext API
  288. typedef struct _SPMInitSecContextAPI {
  289. CRED_HANDLE_LPC hCredential; // IN
  290. CONTEXT_HANDLE_LPC hContext; // IN
  291. SECURITY_STRING_LPC ssTarget; // IN
  292. ULONG fContextReq; // IN
  293. ULONG dwReserved1; // IN
  294. ULONG TargetDataRep; // IN
  295. SEC_BUFFER_DESC_LPC sbdInput; // IN
  296. ULONG dwReserved2; // IN
  297. CONTEXT_HANDLE_LPC hNewContext; // OUT
  298. SEC_BUFFER_DESC_LPC sbdOutput; // IN OUT
  299. ULONG fContextAttr; // OUT
  300. TimeStamp tsExpiry; // OUT
  301. BOOLEAN MappedContext; // OUT
  302. SEC_BUFFER_LPC ContextData; // OUT
  303. SEC_BUFFER_LPC sbData[0]; // IN
  304. } SPMInitContextAPI;
  305. // AcceptSecurityContext API
  306. typedef struct _SPMAcceptContextAPI {
  307. CRED_HANDLE_LPC hCredential; // IN
  308. CONTEXT_HANDLE_LPC hContext; // IN
  309. SEC_BUFFER_DESC_LPC sbdInput; // IN
  310. ULONG fContextReq; // IN
  311. ULONG TargetDataRep; // IN
  312. CHAR IpAddress[LSAP_ADDRESS_LENGTH]; // IN
  313. CONTEXT_HANDLE_LPC hNewContext; // OUT
  314. SEC_BUFFER_DESC_LPC sbdOutput; // IN OUT
  315. ULONG fContextAttr; // OUT
  316. TimeStamp tsExpiry; // OUT
  317. BOOLEAN MappedContext; // OUT
  318. SEC_BUFFER_LPC ContextData; // OUT
  319. SEC_BUFFER_LPC sbData[0]; // IN OUT
  320. } SPMAcceptContextAPI;
  321. //
  322. // ApplyControlToken API
  323. //
  324. typedef struct _SPMApplyTokenAPI {
  325. CONTEXT_HANDLE_LPC hContext ;
  326. SEC_BUFFER_DESC_LPC sbdInput ;
  327. SEC_BUFFER_LPC sbInputBuffer[ MAX_SECBUFFERS ];
  328. } SPMApplyTokenAPI;
  329. // DeleteContext API
  330. typedef struct _SPMDeleteContextAPI {
  331. CONTEXT_HANDLE_LPC hContext; // IN - Context to delete
  332. } SPMDeleteContextAPI;
  333. //
  334. // Miscelanneous, extension APIs
  335. //
  336. // QueryPackage API
  337. typedef struct _SPMQueryPackageAPI {
  338. SECURITY_STRING_LPC ssPackageName;
  339. PSecPkgInfo pPackageInfo;
  340. } SPMQueryPackageAPI;
  341. // GetSecurityUserInfo
  342. // not supported in Wow64
  343. typedef struct _SPMGetUserInfoAPI {
  344. LUID LogonId; // IN
  345. ULONG fFlags; // IN
  346. PSecurityUserData pUserInfo; // OUT
  347. } SPMGetUserInfoAPI;
  348. //
  349. // Credentials APIs. Not used.
  350. //
  351. typedef struct _SPMGetCredsAPI {
  352. CredHandle hCredentials; // IN
  353. SecBuffer Credentials; // OUT
  354. } SPMGetCredsAPI;
  355. typedef struct _SPMSaveCredsAPI {
  356. CredHandle hCredentials; // IN
  357. SecBuffer Credentials; // IN
  358. } SPMSaveCredsAPI;
  359. typedef struct _SPMQueryCredAttributesAPI {
  360. CRED_HANDLE_LPC hCredentials;
  361. ULONG ulAttribute;
  362. PVOID_LPC pBuffer;
  363. ULONG Allocs ;
  364. PVOID_LPC Buffers[MAX_BUFFERS_IN_CALL];
  365. } SPMQueryCredAttributesAPI;
  366. typedef struct _SPMAddPackageAPI {
  367. SECURITY_STRING_LPC Package;
  368. ULONG OptionsFlags;
  369. } SPMAddPackageAPI ;
  370. typedef struct _SPMDeletePackageAPI {
  371. SECURITY_STRING_LPC Package;
  372. } SPMDeletePackageAPI ;
  373. typedef struct _SPMQueryContextAttrAPI {
  374. CONTEXT_HANDLE_LPC hContext ;
  375. ULONG ulAttribute ;
  376. PVOID_LPC pBuffer ;
  377. ULONG Allocs ;
  378. PVOID_LPC Buffers[MAX_BUFFERS_IN_CALL];
  379. } SPMQueryContextAttrAPI ;
  380. typedef struct _SPMSetContextAttrAPI {
  381. CONTEXT_HANDLE_LPC hContext ;
  382. ULONG ulAttribute ;
  383. PVOID_LPC pBuffer ;
  384. ULONG cbBuffer;
  385. } SPMSetContextAttrAPI ;
  386. //
  387. // Kernel mode EFS API. None of these are Wow64
  388. //
  389. typedef struct _SPMEfsGenerateKeyAPI {
  390. PVOID EfsStream;
  391. PVOID DirectoryEfsStream;
  392. ULONG DirectoryEfsStreamLength;
  393. PVOID Fek;
  394. ULONG BufferLength;
  395. PVOID BufferBase;
  396. } SPMEfsGenerateKeyAPI;
  397. typedef struct _SPMEfsGenerateDirEfsAPI {
  398. PVOID DirectoryEfsStream;
  399. ULONG DirectoryEfsStreamLength;
  400. PVOID EfsStream;
  401. PVOID BufferBase;
  402. ULONG BufferLength;
  403. } SPMEfsGenerateDirEfsAPI;
  404. typedef struct _SPMEfsDecryptFekAPI {
  405. PVOID Fek;
  406. PVOID EfsStream;
  407. ULONG EfsStreamLength;
  408. ULONG OpenType;
  409. PVOID NewEfs;
  410. PVOID BufferBase;
  411. ULONG BufferLength;
  412. } SPMEfsDecryptFekAPI;
  413. typedef struct _SPMEfsGenerateSessionKeyAPI {
  414. PVOID InitDataExg;
  415. } SPMEfsGenerateSessionKeyAPI;
  416. //
  417. // Usermode policy change notifications
  418. //
  419. //
  420. // Note: Instead of a HANDLE structure use a ULONG64 for EventHandle member
  421. // to guarantee that passed value will be 64 bits. If not, in Wow64 the passed
  422. // handle will be 32 bits, while the server side expects it to be 64 bits.
  423. // Therefore always extend the handle to a 64 bit variable.
  424. //
  425. typedef struct _SPMLsaPolicyChangeNotifyAPI {
  426. ULONG Options;
  427. BOOLEAN Register;
  428. ULONG64 EventHandle;
  429. POLICY_NOTIFICATION_INFORMATION_CLASS NotifyInfoClass;
  430. } SPMLsaPolicyChangeNotifyAPI;
  431. typedef struct _SPMCallbackAPI {
  432. ULONG Type;
  433. PVOID_LPC CallbackFunction;
  434. PVOID_LPC Argument1;
  435. PVOID_LPC Argument2;
  436. SEC_BUFFER_LPC Input ;
  437. SEC_BUFFER_LPC Output ;
  438. } SPMCallbackAPI ;
  439. #define SPM_CALLBACK_INTERNAL 0x00000001 // Handled by the security DLL
  440. #define SPM_CALLBACK_GETKEY 0x00000002 // Getkey function being called
  441. #define SPM_CALLBACK_PACKAGE 0x00000003 // Package function
  442. #define SPM_CALLBACK_EXPORT 0x00000004 // Ptr to string
  443. //
  444. // Fast name lookup
  445. //
  446. typedef struct _SPMGetUserNameXAPI {
  447. ULONG Options ;
  448. SECURITY_STRING_LPC Name;
  449. } SPMGetUserNameXAPI ;
  450. #define SPM_NAME_OPTION_MASK 0xFFFF0000
  451. #define SPM_NAME_OPTION_NT4_ONLY 0x00010000 // GetUserNameX only, not Ex
  452. #define SPM_NAME_OPTION_FLUSH 0x00020000
  453. //
  454. // AddCredential API.
  455. //
  456. typedef struct _SPMAddCredential {
  457. CRED_HANDLE_LPC hCredentials ;
  458. SECURITY_STRING_LPC ssPrincipal; // IN
  459. SECURITY_STRING_LPC ssSecPackage; // IN
  460. ULONG fCredentialUse; // IN
  461. LUID LogonID; // IN
  462. PVOID_LPC pvAuthData; // IN
  463. PVOID_LPC pvGetKeyFn; // IN
  464. PVOID_LPC ulGetKeyArgument; // IN
  465. TimeStamp tsExpiry; // OUT
  466. } SPMAddCredentialAPI ;
  467. typedef struct _SPMEnumLogonSession {
  468. PVOID_LPC LogonSessionList ; // OUT
  469. ULONG LogonSessionCount ; // OUT
  470. } SPMEnumLogonSessionAPI ;
  471. typedef struct _SPMGetLogonSessionData {
  472. LUID LogonId ; // IN
  473. PVOID_LPC LogonSessionInfo ; // OUT
  474. } SPMGetLogonSessionDataAPI ;
  475. //
  476. // Internal codes:
  477. //
  478. #define SPM_CALLBACK_ADDRESS_CHECK 1 // Setting up shared buffer
  479. #define SPM_CALLBACK_SHUTDOWN 2 // Inproc shutdown notification
  480. //
  481. // SID translation APIs (for kmode callers, primarily)
  482. //
  483. typedef struct _SPMLookupAccountSidX {
  484. PVOID_LPC Sid; // IN
  485. SECURITY_STRING_LPC Name ; // OUT
  486. SECURITY_STRING_LPC Domain ; // OUT
  487. SID_NAME_USE NameUse ; // OUT
  488. } SPMLookupAccountSidXAPI ;
  489. typedef struct _SPMLookupAccountNameX {
  490. SECURITY_STRING_LPC Name ; // IN
  491. SECURITY_STRING_LPC Domain ; // OUT
  492. PVOID_LPC Sid ; // OUT
  493. SID_NAME_USE NameUse ; // OUT
  494. } SPMLookupAccountNameXAPI ;
  495. typedef struct _SPMLookupWellKnownSid {
  496. WELL_KNOWN_SID_TYPE SidType ;
  497. PVOID_LPC Sid ;
  498. } SPMLookupWellKnownSidAPI ;
  499. // this is the wrapper for all messages.
  500. typedef union {
  501. SPMGetBindingAPI GetBinding;
  502. SPMSetSessionAPI SetSession;
  503. SPMFindPackageAPI FindPackage;
  504. SPMEnumPackagesAPI EnumPackages;
  505. SPMAcquireCredsAPI AcquireCreds;
  506. SPMEstablishCredsAPI EstablishCreds;
  507. SPMFreeCredHandleAPI FreeCredHandle;
  508. SPMInitContextAPI InitContext;
  509. SPMAcceptContextAPI AcceptContext;
  510. SPMApplyTokenAPI ApplyToken;
  511. SPMDeleteContextAPI DeleteContext;
  512. SPMQueryPackageAPI QueryPackage;
  513. SPMGetUserInfoAPI GetUserInfo;
  514. SPMGetCredsAPI GetCreds;
  515. SPMSaveCredsAPI SaveCreds;
  516. SPMQueryCredAttributesAPI QueryCredAttributes;
  517. SPMAddPackageAPI AddPackage;
  518. SPMDeletePackageAPI DeletePackage ;
  519. SPMEfsGenerateKeyAPI EfsGenerateKey;
  520. SPMEfsGenerateDirEfsAPI EfsGenerateDirEfs;
  521. SPMEfsDecryptFekAPI EfsDecryptFek;
  522. SPMEfsGenerateSessionKeyAPI EfsGenerateSessionKey;
  523. SPMQueryContextAttrAPI QueryContextAttr ;
  524. SPMCallbackAPI Callback ;
  525. SPMLsaPolicyChangeNotifyAPI LsaPolicyChangeNotify;
  526. SPMGetUserNameXAPI GetUserNameX ;
  527. SPMAddCredentialAPI AddCredential ;
  528. SPMEnumLogonSessionAPI EnumLogonSession ;
  529. SPMGetLogonSessionDataAPI GetLogonSessionData ;
  530. SPMSetContextAttrAPI SetContextAttr ;
  531. SPMLookupAccountSidXAPI LookupAccountSidX ;
  532. SPMLookupAccountNameXAPI LookupAccountNameX ;
  533. SPMLookupWellKnownSidAPI LookupWellKnownSid ;
  534. } SPM_API;
  535. //
  536. // This extends the range of LSA functions with the SPM functions
  537. //
  538. typedef enum _SPM_API_NUMBER {
  539. SPMAPI_GetBinding = (LsapAuMaxApiNumber + 1),
  540. SPMAPI_SetSession,
  541. SPMAPI_FindPackage,
  542. SPMAPI_EnumPackages,
  543. SPMAPI_AcquireCreds,
  544. SPMAPI_EstablishCreds,
  545. SPMAPI_FreeCredHandle,
  546. SPMAPI_InitContext,
  547. SPMAPI_AcceptContext,
  548. SPMAPI_ApplyToken,
  549. SPMAPI_DeleteContext,
  550. SPMAPI_QueryPackage,
  551. SPMAPI_GetUserInfo,
  552. SPMAPI_GetCreds,
  553. SPMAPI_SaveCreds,
  554. SPMAPI_QueryCredAttributes,
  555. SPMAPI_AddPackage,
  556. SPMAPI_DeletePackage,
  557. SPMAPI_EfsGenerateKey,
  558. SPMAPI_EfsGenerateDirEfs,
  559. SPMAPI_EfsDecryptFek,
  560. SPMAPI_EfsGenerateSessionKey,
  561. SPMAPI_Callback,
  562. SPMAPI_QueryContextAttr,
  563. SPMAPI_LsaPolicyChangeNotify,
  564. SPMAPI_GetUserNameX,
  565. SPMAPI_AddCredential,
  566. SPMAPI_EnumLogonSession,
  567. SPMAPI_GetLogonSessionData,
  568. SPMAPI_SetContextAttr,
  569. SPMAPI_LookupAccountNameX,
  570. SPMAPI_LookupAccountSidX,
  571. SPMAPI_LookupWellKnownSid,
  572. SPMAPI_MaxApiNumber
  573. } SPM_API_NUMBER, *PSPM_API_NUMBER;
  574. //
  575. // These are the valid flags to set in the fAPI field
  576. //
  577. #define SPMAPI_FLAG_ERROR_RET 0x0001 // Indicates an error return
  578. #define SPMAPI_FLAG_MEMORY 0x0002 // Memory was allocated in client
  579. #define SPMAPI_FLAG_PREPACK 0x0004 // Data packed in bData field
  580. #define SPMAPI_FLAG_GETSTATE 0x0008 // driver should call GetState
  581. #define SPMAPI_FLAG_ANSI_CALL 0x0010 // Called via ANSI stub
  582. #define SPMAPI_FLAG_HANDLE_CHG 0x0020 // A handle was changed
  583. #define SPMAPI_FLAG_CALLBACK 0x0040 // Callback to calling process
  584. #define SPMAPI_FLAG_ALLOCS 0x0080 // VM Allocs were placed in prepack
  585. #define SPMAPI_FLAG_EXEC_NOW 0x0100 // Execute in LPC thread
  586. #define SPMAPI_FLAG_WIN32_ERROR 0x0200 // Status is a win32 error
  587. #define SPMAPI_FLAG_KMAP_MEM 0x0400 // Call contains buffers in the kmap
  588. //
  589. // This structure contains all the information needed for SPM api's
  590. //
  591. typedef struct _SPMLPCAPI {
  592. USHORT fAPI ;
  593. USHORT VMOffset ;
  594. PVOID_LPC ContextPointer ;
  595. SPM_API API;
  596. } SPMLPCAPI, * PSPMLPCAPI;
  597. //
  598. // This union contains all the info for LSA api's
  599. //
  600. typedef union {
  601. LSAP_LOOKUP_PACKAGE_ARGS LookupPackage;
  602. LSAP_LOGON_USER_ARGS LogonUser;
  603. LSAP_CALL_PACKAGE_ARGS CallPackage;
  604. } LSA_API;
  605. //
  606. // This union contains both SPM and LSA api's
  607. //
  608. typedef union _SPM_LSA_ARGUMENTS {
  609. LSA_API LsaArguments;
  610. SPMLPCAPI SpmArguments;
  611. } SPM_LSA_ARGUMENTS, *PSPM_LSA_ARGUMENTS;
  612. //
  613. // For performance, some APIs will attempt to pack small parameters in the
  614. // message being sent to the SPM, rather than have the SPM read it out of
  615. // their memory. So, this value defines how much data can be stuck in the
  616. // message.
  617. //
  618. // Two items are defined here. One, CBAPIHDR, is the size of everything
  619. // in the message except the packed data. The other, CBPREPACK, is the
  620. // left over space. I subtract 4 at the end to avoid potential boundary
  621. // problems with an LPC message.
  622. //
  623. #define CBAPIHDR (sizeof(PORT_MESSAGE) + sizeof(ULONG) + sizeof(HRESULT) + \
  624. sizeof(SPM_LSA_ARGUMENTS))
  625. #define CBPREPACK (PORT_MAXIMUM_MESSAGE_LENGTH - CBAPIHDR - sizeof( PVOID_LPC ))
  626. #define NUM_SECBUFFERS ( CBPREPACK / sizeof(SecBuffer) )
  627. //
  628. // This structure is sent over during an API call rather than a connect
  629. // message
  630. //
  631. typedef struct _SPM_API_MESSAGE {
  632. SPM_API_NUMBER dwAPI;
  633. HRESULT scRet;
  634. SPM_LSA_ARGUMENTS Args;
  635. UCHAR bData[CBPREPACK];
  636. } SPM_API_MESSAGE, *PSPM_API_MESSAGE;
  637. #define SecBaseMessageSize( Api ) \
  638. ( sizeof( SPM_API_NUMBER ) + sizeof( HRESULT ) + \
  639. ( sizeof( SPM_LSA_ARGUMENTS ) - sizeof( SPM_API ) + \
  640. sizeof( SPM##Api##API ) ) )
  641. //
  642. // This is the actual message sent over LPC - it contains both the
  643. // connection request information and the api message
  644. //
  645. typedef struct _SPM_LPC_MESSAGE {
  646. PORT_MESSAGE pmMessage;
  647. union {
  648. LSAP_AU_REGISTER_CONNECT_INFO ConnectionRequest;
  649. SPM_API_MESSAGE ApiMessage;
  650. };
  651. } SPM_LPC_MESSAGE, *PSPM_LPC_MESSAGE;
  652. //
  653. // Macros to help prepare LPC messages
  654. //
  655. #ifdef SECURITY_USERMODE
  656. #define PREPARE_MESSAGE_EX( Message, Api, Flags, Context ) \
  657. RtlZeroMemory( &(Message), sizeof( SPM_LSA_ARGUMENTS ) + sizeof( PORT_MESSAGE ) ); \
  658. (Message).pmMessage.u1.s1.DataLength = \
  659. ( sizeof( SPM_API_NUMBER ) + sizeof( HRESULT ) + \
  660. ( sizeof( SPM_LSA_ARGUMENTS ) - sizeof( SPM_API ) + \
  661. sizeof( SPM##Api##API ) ) ); \
  662. (Message).pmMessage.u1.s1.TotalLength = (Message).pmMessage.u1.s1.DataLength + \
  663. sizeof( PORT_MESSAGE ); \
  664. (Message).pmMessage.u2.ZeroInit = 0L; \
  665. (Message).ApiMessage.scRet = 0L; \
  666. (Message).ApiMessage.dwAPI = SPMAPI_##Api ; \
  667. (Message).ApiMessage.Args.SpmArguments.fAPI = (USHORT)(Flags); \
  668. (Message).ApiMessage.Args.SpmArguments.ContextPointer = (Context);
  669. #else
  670. #define PREPARE_MESSAGE_EX( Message, Api, Flags, Context ) \
  671. RtlZeroMemory( &(Message), sizeof( SPM_LSA_ARGUMENTS ) + sizeof( PORT_MESSAGE ) ); \
  672. (Message).pmMessage.u1.s1.DataLength = \
  673. ( sizeof( SPM_API_NUMBER ) + sizeof( HRESULT ) + \
  674. ( sizeof( SPM_LSA_ARGUMENTS ) - sizeof( SPM_API ) + \
  675. sizeof( SPM##Api##API ) ) ); \
  676. (Message).pmMessage.u1.s1.TotalLength = (Message).pmMessage.u1.s1.DataLength + \
  677. sizeof( PORT_MESSAGE ); \
  678. (Message).pmMessage.u2.ZeroInit = 0L; \
  679. (Message).ApiMessage.scRet = 0L; \
  680. (Message).ApiMessage.dwAPI = SPMAPI_##Api ; \
  681. (Message).ApiMessage.Args.SpmArguments.fAPI = (USHORT)(Flags); \
  682. (Message).ApiMessage.Args.SpmArguments.ContextPointer = (Context); \
  683. (Message).pmMessage.u2.s2.Type |= LPC_KERNELMODE_MESSAGE;
  684. #endif
  685. #define PREPARE_MESSAGE(Message, Api) PREPARE_MESSAGE_EX(Message, Api, 0, 0 )
  686. #define LPC_MESSAGE_ARGS( Message, Api )\
  687. ( & (Message).ApiMessage.Args.SpmArguments.API.Api )
  688. #define LPC_MESSAGE_ARGSP( Message, Api )\
  689. ( & (Message)->ApiMessage.Args.SpmArguments.API.Api )
  690. #define DECLARE_ARGS( ArgPointer, Message, Api )\
  691. SPM##Api##API * ArgPointer = & (Message).ApiMessage.Args.SpmArguments.API.Api
  692. #define DECLARE_ARGSP( ArgPointer, Message, Api)\
  693. SPM##Api##API * ArgPointer = & (Message)->ApiMessage.Args.SpmArguments.API.Api
  694. #define PREPACK_START FIELD_OFFSET( SPM_LPC_MESSAGE, ApiMessage.bData )
  695. #define LPC_DATA_LENGTH( Length )\
  696. (USHORT) ((PREPACK_START) + (Length) - sizeof( PORT_MESSAGE ) )
  697. #define LPC_TOTAL_LENGTH( Length )\
  698. (USHORT) ((PREPACK_START) + (Length))
  699. BOOLEAN
  700. FORCEINLINE
  701. SecLpcIsPointerInMessage(
  702. PSPM_LPC_MESSAGE Message,
  703. PVOID_LPC Pointer
  704. )
  705. {
  706. ULONG_PTR P ;
  707. ULONG_PTR B ;
  708. P = (ULONG_PTR) Pointer ;
  709. B = (ULONG_PTR) ((ULONG_PTR) Message->ApiMessage.bData) - (ULONG_PTR) Message ;
  710. return ( ( P >= B ) && (P < B + CBPREPACK ) );
  711. }
  712. PVOID_LPC
  713. FORCEINLINE
  714. SecLpcFixupPointer(
  715. PSPM_LPC_MESSAGE Message,
  716. PVOID_LPC Pointer
  717. )
  718. {
  719. return (PVOID_LPC) ((PUCHAR) Message + (ULONG_PTR) Pointer );
  720. }
  721. //
  722. // Prototype for the direct dispatch function:
  723. //
  724. typedef NTSTATUS (SEC_ENTRY LSA_DISPATCH_FN)(
  725. PSPM_LPC_MESSAGE );
  726. typedef LSA_DISPATCH_FN * PLSA_DISPATCH_FN;
  727. //
  728. // structs used to manage memory shared between the LSA and KSEC driver
  729. //
  730. #define LSA_MAX_KMAP_SIZE 65535
  731. //
  732. // This structure describes a chunk of pool that has been copied into
  733. // a kmap buffer. The original pool address and the location in the
  734. // kmap are here, as is the size of the chunk. On IA64, this ends up
  735. // with a wasted 32bit padding area
  736. //
  737. typedef struct _KSEC_LSA_POOL_MAP {
  738. PVOID_LPC Pool ; // Region of pool
  739. USHORT Offset ; // Offset into kmap
  740. USHORT Size ; // size of chunk
  741. } KSEC_LSA_POOL_MAP, PKSEC_LSA_POOL_MAP ;
  742. #define KSEC_LSA_MAX_MAPS 4
  743. typedef struct _KSEC_LSA_MEMORY_HEADER {
  744. ULONG Size ; // Size of the reserved region
  745. ULONG Commit ; // Size of the committed space
  746. ULONG Consumed ; // Amount consumed
  747. USHORT Preserve ; // Size of the area to keep for ksec
  748. USHORT MapCount ; // number of entries in array
  749. KSEC_LSA_POOL_MAP PoolMap[ KSEC_LSA_MAX_MAPS ];
  750. } KSEC_LSA_MEMORY_HEADER, * PKSEC_LSA_MEMORY_HEADER ;
  751. //
  752. // This buffer type is used to indicate the header in the
  753. // message from the driver to the LSA. It is ignored if
  754. // the call did not originate from kernel mode
  755. //
  756. #define SECBUFFER_KMAP_HEADER 0x00008001
  757. #pragma warning(default:4200)
  758. #endif // __SPMLPC_H__