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.

864 lines
18 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ausrvp.h
  5. Abstract:
  6. This module contains AUTHENTICATION related data structures and
  7. API definitions that are private to the Local Security Authority
  8. (LSA) server.
  9. Author:
  10. Jim Kelly (JimK) 21-February-1991
  11. Revision History:
  12. --*/
  13. #ifndef _AUSRVP_
  14. #define _AUSRVP_
  15. //#define LSAP_AU_TRACK_CONTEXT
  16. //#define LSAP_AU_TRACK_THREADS
  17. //#define LSAP_AU_TRACK_LOGONS
  18. #include <nt.h>
  19. #include <ntrtl.h>
  20. #include <nturtl.h>
  21. #include <ntlsa.h>
  22. #include <stdlib.h>
  23. #include "lsasrvp.h"
  24. #include <aup.h>
  25. #include <samrpc.h>
  26. #include <ntdsapi.h>
  27. #include "spmgr.h"
  28. #include <secur32p.h>
  29. #include "logons.h"
  30. #include <credp.hxx>
  31. /////////////////////////////////////////////////////////////////////////
  32. // //
  33. // AU specific constants //
  34. // //
  35. /////////////////////////////////////////////////////////////////////////
  36. //
  37. // The filter/augmentor routines use the following bits in a mask
  38. // to track properties of IDs during logon. These bits have the following
  39. // meaning:
  40. //
  41. // LSAP_AU_SID_PROP_ALLOCATED - Indicates the SID was allocated within
  42. // the filter routine. If an error occurs, this allows allocated
  43. // IDs to be deallocated. Otherwise, the caller must deallocate
  44. // them.
  45. //
  46. // LSAP_AU_SID_COPY - Indicates the SID must be copied before returning.
  47. // This typically indicates that the pointed-to SID is a global
  48. // variable for use throughout LSA or that the SID is being referenced
  49. // from another structure (such as an existing TokenInformation structure).
  50. //
  51. // LSAP_AU_SID_PROP_HIGH_RATE - Indicates it is expected that the SID
  52. // will typically be used in ACLs to grant access. This is useful
  53. // to know when arranging SIDs. Placing the IDs that will have a
  54. // high chance of granting access at the front of the list of SIDs
  55. // will reduce the amount of time spent in access validation routines
  56. // after logon.
  57. //
  58. #define LSAP_AU_SID_PROP_ALLOCATED (0x00000001L)
  59. #define LSAP_AU_SID_PROP_COPY (0x00000002L)
  60. #define LSAP_AU_SID_PROP_HIGH_RATE (0x00000004L)
  61. /////////////////////////////////////////////////////////////////////////
  62. // //
  63. // Macro definitions //
  64. // //
  65. /////////////////////////////////////////////////////////////////////////
  66. //
  67. // Macros to gain exclusive access to protected global authentication
  68. // data structures
  69. //
  70. #define LsapAuLock() (RtlEnterCriticalSection(&LsapAuLock))
  71. #define LsapAuUnlock() (RtlLeaveCriticalSection(&LsapAuLock))
  72. /////////////////////////////////////////////////////////////////////////
  73. // //
  74. // Type definitions //
  75. // //
  76. /////////////////////////////////////////////////////////////////////////
  77. //
  78. // This data structure is used to house logon process information.
  79. //
  80. typedef struct _LSAP_LOGON_PROCESS {
  81. //
  82. // Links - Used to link contexts together. This must be the
  83. // first field of the context block.
  84. //
  85. LIST_ENTRY Links;
  86. //
  87. // ReferenceCount - Used to prevent this context from being
  88. // deleted prematurely.
  89. //
  90. ULONG References;
  91. //
  92. // ClientProcess - A handle to the client process. This handle is
  93. // used to perform virtual memory operations within the client
  94. // process (allocate, deallocate, read, write).
  95. //
  96. HANDLE ClientProcess;
  97. //
  98. // CommPort - A handle to the LPC communication port created to
  99. // communicate with this client. this port must be closed
  100. // when the client deregisters.
  101. //
  102. HANDLE CommPort;
  103. //
  104. // TrustedClient - If TRUE, the caller has TCB privilege and may
  105. // call any API. If FALSE, the caller may only call
  106. // LookupAuthenticatePackage and CallPackage, which is converted
  107. // to LsaApCallPackageUntrusted.
  108. //
  109. BOOLEAN TrustedClient;
  110. //
  111. // Name of the logon process.
  112. //
  113. WCHAR LogonProcessName[1];
  114. } LSAP_LOGON_PROCESS, *PLSAP_LOGON_PROCESS;
  115. //
  116. // This structure should be treated as opaque by non-LSA code.
  117. // It is used to maintain client information related to individual
  118. // requests. A public data structure (LSA_CLIENT_REQUEST) is
  119. // typecast to this type by LSA code.
  120. //
  121. typedef struct _LSAP_CLIENT_REQUEST {
  122. //
  123. // Request - Points to the request message received from the
  124. // client.
  125. //
  126. PLSAP_AU_API_MESSAGE Request;
  127. } LSAP_CLIENT_REQUEST, *PLSAP_CLIENT_REQUEST;
  128. //
  129. // The dispatch table of services which are provided by
  130. // authentication packages.
  131. //
  132. typedef struct _LSAP_PACKAGE_TABLE {
  133. PLSA_AP_INITIALIZE_PACKAGE LsapApInitializePackage;
  134. PLSA_AP_LOGON_USER LsapApLogonUser;
  135. PLSA_AP_CALL_PACKAGE LsapApCallPackage;
  136. PLSA_AP_LOGON_TERMINATED LsapApLogonTerminated;
  137. PLSA_AP_CALL_PACKAGE_UNTRUSTED LsapApCallPackageUntrusted;
  138. PLSA_AP_LOGON_USER_EX LsapApLogonUserEx;
  139. } LSAP_PACKAGE_TABLE, *PLSA_PACKAGE_TABLE;
  140. //
  141. // Used to house information about each loaded authentication package
  142. //
  143. typedef struct _LSAP_PACKAGE_CONTEXT {
  144. PSTRING Name;
  145. LSAP_PACKAGE_TABLE PackageApi;
  146. } LSAP_PACKAGE_CONTEXT, *PLSAP_PACKAGE_CONTEXT;
  147. //
  148. // Rather than keep authentication package contexts in a linked list,
  149. // they are pointed to via an array of pointers. This is practical
  150. // because there will never be more than a handful of authentication
  151. // packages in any particular system, and because authentication packages
  152. // are never unloaded.
  153. //
  154. typedef struct _LSAP_PACKAGE_ARRAY {
  155. PLSAP_PACKAGE_CONTEXT Package[ANYSIZE_ARRAY];
  156. } LSAP_PACKAGE_ARRAY, *PLSAP_PACKAGE_ARRAY;
  157. //
  158. // Logon Session & Credential management data structures.
  159. //
  160. // Credentials are kept in a structure that looks like:
  161. //
  162. // +------+ +------+
  163. // LsapLogonSessions->| Logon|---->| Logon|------> o o o
  164. // | Id | | Id |
  165. // | * | | * |
  166. // +---|--+ +---|--+
  167. // |
  168. // | +-----+ +-----+
  169. // +-->| Auth|------>| Auth|
  170. // | Cred| | Cred|
  171. // |- - -| |- - -|
  172. // | Cred| | . |
  173. // | List| | . |
  174. // | * | | . |
  175. // +--|--+ +-----+
  176. // |
  177. // +------> +------------+
  178. // | NextCred | -----> o o o
  179. // |- - - - - - |
  180. // | Primary Key|--->(PrimaryKeyvalue)
  181. // |- - - - - - |
  182. // | Credential |
  183. // | Value |--->(CredentialValue)
  184. // +------------+
  185. //
  186. //
  187. //
  188. typedef struct _LSAP_CREDENTIALS {
  189. struct _LSAP_CREDENTIALS *NextCredentials;
  190. STRING PrimaryKey;
  191. STRING Credentials;
  192. } LSAP_CREDENTIALS, *PLSAP_CREDENTIALS;
  193. typedef struct _LSAP_PACKAGE_CREDENTIALS {
  194. struct _LSAP_PACKAGE_CREDENTIALS *NextPackage;
  195. //
  196. // Package that created (and owns) these credentials
  197. //
  198. ULONG PackageId;
  199. //
  200. // List of credentials associated with this package
  201. //
  202. PLSAP_CREDENTIALS Credentials;
  203. } LSAP_PACKAGE_CREDENTIALS, *PLSAP_PACKAGE_CREDENTIALS;
  204. #define LSAP_MAX_DS_NAMES (DS_DNS_DOMAIN_NAME + 1)
  205. typedef struct _LSAP_DS_NAME_MAP {
  206. LARGE_INTEGER ExpirationTime ;
  207. ULONG RefCount ;
  208. UNICODE_STRING Name ;
  209. } LSAP_DS_NAME_MAP, * PLSAP_DS_NAME_MAP ;
  210. typedef struct _LSAP_LOGON_SESSION {
  211. //
  212. // List maintained for enumeration
  213. //
  214. LIST_ENTRY List ;
  215. //
  216. // Each record represents just one logon session
  217. //
  218. LUID LogonId;
  219. //
  220. // For audit purposes, we keep an account name, authenticating
  221. // authority name, and User SID for each logon session.
  222. //
  223. UNICODE_STRING AccountName;
  224. UNICODE_STRING AuthorityName;
  225. UNICODE_STRING ProfilePath;
  226. PSID UserSid;
  227. SECURITY_LOGON_TYPE LogonType;
  228. //
  229. // Session ID
  230. //
  231. ULONG Session ;
  232. //
  233. // Logon Time
  234. //
  235. LARGE_INTEGER LogonTime ;
  236. //
  237. // purported logon server.
  238. //
  239. UNICODE_STRING LogonServer;
  240. //
  241. // The authentication packages that have credentials associated
  242. // with this logon session each have their own record in the following
  243. // linked list.
  244. //
  245. // Access serialized by AuCredLock
  246. //
  247. PLSAP_PACKAGE_CREDENTIALS Packages;
  248. //
  249. // License Server Handle.
  250. //
  251. // Null if the license server need not be notified upon logoff.
  252. //
  253. HANDLE LicenseHandle;
  254. //
  255. // Handle to the token associated with this session.
  256. //
  257. // Access serialized by LogonSessionListLock
  258. //
  259. HANDLE TokenHandle;
  260. //
  261. // Creating Package
  262. //
  263. ULONG_PTR CreatingPackage;
  264. //
  265. // Create trace info:
  266. //
  267. ULONG Process ;
  268. ULONG ContextAttr ;
  269. //
  270. // Credential Sets for this logon session.
  271. //
  272. CREDENTIAL_SETS CredentialSets;
  273. //
  274. // Access serialized by LogonSessionListLock
  275. //
  276. PLSAP_DS_NAME_MAP DsNames[ LSAP_MAX_DS_NAMES ];
  277. //
  278. // Logon GUID
  279. //
  280. // This is used by Kerberos package for auditing.
  281. // (please see function header for LsaIGetLogonGuid for more info)
  282. //
  283. GUID LogonGuid;
  284. } LSAP_LOGON_SESSION, *PLSAP_LOGON_SESSION;
  285. /////////////////////////////////////////////////////////////////////////
  286. // //
  287. // Internal API definitions //
  288. // //
  289. /////////////////////////////////////////////////////////////////////////
  290. //
  291. // Logon process context management services
  292. //
  293. NTSTATUS
  294. LsapAuInitializeContextMgr(
  295. VOID
  296. );
  297. VOID
  298. LsapAuAddClientContext(
  299. PLSAP_LOGON_PROCESS Context
  300. );
  301. BOOLEAN
  302. LsapAuReferenceClientContext(
  303. PLSAP_CLIENT_REQUEST ClientRequest,
  304. BOOLEAN RemoveContext,
  305. PBOOLEAN TrustedClient
  306. );
  307. VOID
  308. LsapAuDereferenceClientContext(
  309. PLSAP_LOGON_PROCESS Context
  310. );
  311. //
  312. // Authentication client loop and dispatch routines
  313. //
  314. NTSTATUS
  315. LsapAuListenLoop( // Listen for connections from logon processes
  316. IN PVOID ThreadParameter
  317. );
  318. NTSTATUS
  319. LsapAuServerLoop( // Wait for logon process calls & dispatch them
  320. IN PVOID ThreadParameter
  321. );
  322. BOOLEAN
  323. LsapAuLoopInitialize(
  324. VOID
  325. );
  326. typedef
  327. NTSTATUS // Template dispatch routine
  328. (* PLSAP_AU_API_DISPATCH)(
  329. IN OUT PLSAP_CLIENT_REQUEST ClientRequest
  330. );
  331. NTSTATUS
  332. LsapAuApiDispatchLogonUser( // LsaLogonUser() dispatch routine
  333. IN OUT PLSAP_CLIENT_REQUEST ClientRequest
  334. );
  335. NTSTATUS
  336. LsapAuApiDispatchCallPackage( // LsaCallAuthenticationPackage() dispatch routine
  337. IN OUT PLSAP_CLIENT_REQUEST ClientRequest
  338. );
  339. //
  340. // Client process virtual memory routines
  341. //
  342. NTSTATUS
  343. LsapAllocateClientBuffer (
  344. IN PLSA_CLIENT_REQUEST ClientRequest,
  345. IN ULONG LengthRequired,
  346. OUT PVOID *ClientBaseAddress
  347. );
  348. NTSTATUS
  349. LsapFreeClientBuffer (
  350. IN PLSA_CLIENT_REQUEST ClientRequest,
  351. IN PVOID ClientBaseAddress OPTIONAL
  352. );
  353. NTSTATUS
  354. LsapCopyToClientBuffer (
  355. IN PLSA_CLIENT_REQUEST ClientRequest,
  356. IN ULONG Length,
  357. IN PVOID ClientBaseAddress,
  358. IN PVOID BufferToCopy
  359. );
  360. NTSTATUS
  361. LsapCopyFromClientBuffer (
  362. IN PLSA_CLIENT_REQUEST ClientRequest,
  363. IN ULONG Length,
  364. IN PVOID BufferToCopy,
  365. IN PVOID ClientBaseAddress
  366. );
  367. //
  368. // Logon session routines
  369. //
  370. BOOLEAN
  371. LsapLogonSessionInitialize();
  372. NTSTATUS
  373. LsapCreateLogonSession(
  374. IN PLUID LogonId
  375. );
  376. NTSTATUS
  377. LsapDeleteLogonSession (
  378. IN PLUID LogonId
  379. );
  380. PLSAP_LOGON_SESSION
  381. LsapLocateLogonSession(
  382. PLUID LogonId
  383. );
  384. VOID
  385. LsapReleaseLogonSession(
  386. PLSAP_LOGON_SESSION LogonSession
  387. );
  388. NTSTATUS
  389. LsapSetLogonSessionAccountInfo(
  390. IN PLUID LogonId,
  391. IN PUNICODE_STRING AccountName,
  392. IN PUNICODE_STRING AuthorityName,
  393. IN OPTIONAL PUNICODE_STRING ProfilePath,
  394. IN PSID * UserSid,
  395. IN SECURITY_LOGON_TYPE LogonType,
  396. IN PSECPKG_PRIMARY_CRED PrimaryCredentials OPTIONAL
  397. );
  398. NTSTATUS
  399. LsapGetLogonSessionAccountInfo(
  400. IN PLUID LogonId,
  401. OUT PUNICODE_STRING AccountName,
  402. OUT PUNICODE_STRING AuthorityName
  403. );
  404. VOID
  405. LsapDerefDsNameMap(
  406. PLSAP_DS_NAME_MAP Map
  407. );
  408. NTSTATUS
  409. LsapGetNameForLogonSession(
  410. PLSAP_LOGON_SESSION LogonSession,
  411. ULONG NameType,
  412. PLSAP_DS_NAME_MAP * Map,
  413. BOOL LocalOnly
  414. );
  415. NTSTATUS
  416. LsapSetSessionToken(
  417. IN HANDLE InputTokenHandle,
  418. IN PLUID LogonId
  419. );
  420. NTSTATUS
  421. LsapOpenTokenByLogonId(
  422. IN PLUID LogonId,
  423. OUT HANDLE *RetTokenHandle
  424. );
  425. PLSAP_DS_NAME_MAP
  426. LsapGetNameForLocalSystem(
  427. VOID
  428. );
  429. //
  430. // Credentials routines
  431. //
  432. NTSTATUS
  433. LsapAddCredential(
  434. IN PLUID LogonId,
  435. IN ULONG AuthenticationPackage,
  436. IN PSTRING PrimaryKeyValue,
  437. IN PSTRING Credentials
  438. );
  439. NTSTATUS
  440. LsapGetCredentials(
  441. IN PLUID LogonId,
  442. IN ULONG AuthenticationPackage,
  443. IN OUT PULONG QueryContext,
  444. IN BOOLEAN RetrieveAllCredentials,
  445. IN PSTRING PrimaryKeyValue,
  446. OUT PULONG PrimaryKeyLength,
  447. IN PSTRING Credentials
  448. );
  449. NTSTATUS
  450. LsapDeleteCredential(
  451. IN PLUID LogonId,
  452. IN ULONG AuthenticationPackage,
  453. IN PSTRING PrimaryKeyValue
  454. );
  455. PLSAP_PACKAGE_CREDENTIALS
  456. LsapGetPackageCredentials(
  457. IN PLSAP_LOGON_SESSION LogonSession,
  458. IN ULONG PackageId,
  459. IN BOOLEAN CreateIfNecessary
  460. );
  461. VOID
  462. LsapFreePackageCredentialList(
  463. IN PLSAP_PACKAGE_CREDENTIALS PackageCredentialList
  464. );
  465. VOID
  466. LsapFreeCredentialList(
  467. IN PLSAP_CREDENTIALS CredentialList
  468. );
  469. NTSTATUS
  470. LsapReturnCredential(
  471. IN PLSAP_CREDENTIALS SourceCredentials,
  472. IN PSTRING TargetCredentials,
  473. IN BOOLEAN ReturnPrimaryKey,
  474. IN PSTRING PrimaryKeyValue OPTIONAL,
  475. OUT PULONG PrimaryKeyLength OPTIONAL
  476. );
  477. //
  478. // Logon process related services
  479. //
  480. NTSTATUS
  481. LsapValidLogonProcess(
  482. IN PVOID ConnectionRequest,
  483. IN ULONG RequestLength,
  484. IN PCLIENT_ID ClientId,
  485. OUT PLUID LogonId,
  486. OUT PULONG Flags
  487. );
  488. //
  489. // Authentication package routines
  490. //
  491. VOID
  492. LsapAuLogonTerminatedPackages(
  493. IN PLUID LogonId
  494. );
  495. NTSTATUS
  496. LsaCallLicenseServer(
  497. IN PWCHAR LogonProcessName,
  498. IN PUNICODE_STRING AccountName,
  499. IN PUNICODE_STRING DomainName OPTIONAL,
  500. IN BOOLEAN IsAdmin,
  501. OUT HANDLE *LicenseHandle
  502. );
  503. VOID
  504. LsaFreeLicenseHandle(
  505. IN HANDLE LicenseHandle
  506. );
  507. //
  508. // Miscellaneous other routines
  509. // (LsapAuInit() is the link to the rest of LSA and resides in lsap.h)
  510. //
  511. BOOLEAN
  512. LsapWellKnownValueInit(
  513. VOID
  514. );
  515. BOOLEAN
  516. LsapEnableCreateTokenPrivilege(
  517. VOID
  518. );
  519. NTSTATUS
  520. LsapCreateNullToken(
  521. IN PLUID LogonId,
  522. IN PTOKEN_SOURCE TokenSource,
  523. IN PLSA_TOKEN_INFORMATION_NULL TokenInformationNull,
  524. OUT PHANDLE Token
  525. );
  526. NTSTATUS
  527. LsapCreateV2Token(
  528. IN PLUID LogonId,
  529. IN PTOKEN_SOURCE TokenSource,
  530. IN PLSA_TOKEN_INFORMATION_V2 TokenInformationV2,
  531. IN TOKEN_TYPE TokenType,
  532. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel,
  533. OUT PHANDLE Token
  534. );
  535. NTSTATUS
  536. LsapCaptureClientTokenGroups(
  537. IN PLSAP_CLIENT_REQUEST ClientRequest,
  538. IN ULONG GroupCount,
  539. IN PTOKEN_GROUPS ClientTokenGroups,
  540. IN PTOKEN_GROUPS *CapturedTokenGroups
  541. );
  542. NTSTATUS
  543. LsapBuildDefaultTokenGroups(
  544. PLSAP_LOGON_USER_ARGS Arguments
  545. );
  546. VOID
  547. LsapFreeTokenGroups(
  548. IN PTOKEN_GROUPS TokenGroups
  549. );
  550. VOID
  551. LsapFreeTokenPrivileges(
  552. IN PTOKEN_PRIVILEGES TokenPrivileges OPTIONAL
  553. );
  554. VOID
  555. LsapFreeTokenInformationNull(
  556. IN PLSA_TOKEN_INFORMATION_NULL TokenInformationNull
  557. );
  558. VOID
  559. LsapFreeTokenInformationV1(
  560. IN PLSA_TOKEN_INFORMATION_V1 TokenInformationV1
  561. );
  562. VOID
  563. LsapFreeTokenInformationV2(
  564. IN PLSA_TOKEN_INFORMATION_V2 TokenInformationV2
  565. );
  566. NTSTATUS
  567. LsapAuUserLogonPolicyFilter(
  568. IN SECURITY_LOGON_TYPE LogonType,
  569. IN PLSA_TOKEN_INFORMATION_TYPE TokenInformationType,
  570. IN PVOID *TokenInformation,
  571. IN PTOKEN_GROUPS LocalGroups,
  572. OUT PQUOTA_LIMITS QuotaLimits,
  573. OUT PPRIVILEGE_SET *PrivilegesAssigned
  574. );
  575. /////////////////////////////////////////////////////////////////////////
  576. // //
  577. // Global variables of the LSA server //
  578. // //
  579. /////////////////////////////////////////////////////////////////////////
  580. //
  581. // Well known LUIDs
  582. //
  583. extern LUID LsapSystemLogonId;
  584. extern LUID LsapAnonymousLogonId;
  585. //
  586. // Well known privilege values
  587. //
  588. extern LUID LsapCreateTokenPrivilege;
  589. extern LUID LsapAssignPrimaryTokenPrivilege;
  590. extern LUID LsapLockMemoryPrivilege;
  591. extern LUID LsapIncreaseQuotaPrivilege;
  592. extern LUID LsapUnsolicitedInputPrivilege;
  593. extern LUID LsapTcbPrivilege;
  594. extern LUID LsapSecurityPrivilege;
  595. extern LUID LsapTakeOwnershipPrivilege;
  596. //
  597. // Strings needed for auditing.
  598. //
  599. extern UNICODE_STRING LsapLsaAuName;
  600. extern UNICODE_STRING LsapRegisterLogonServiceName;
  601. //
  602. // The following information pertains to the use of the local SAM
  603. // for authentication.
  604. //
  605. // Length of typical Sids of members of the Account or Built-In Domains
  606. extern ULONG LsapAccountDomainMemberSidLength,
  607. LsapBuiltinDomainMemberSidLength;
  608. // Sub-Authority Counts for members of the Account or Built-In Domains
  609. extern UCHAR LsapAccountDomainSubCount,
  610. LsapBuiltinDomainSubCount;
  611. // Typical Sids for members of Account or Built-in Domains
  612. extern PSID LsapAccountDomainMemberSid,
  613. LsapBuiltinDomainMemberSid;
  614. #endif // _AUSRVP_