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.

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