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.

818 lines
27 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. tokenp.h
  5. Abstract:
  6. This module contains the internal (private) declarations needed by the
  7. TOKEN object routines.
  8. It also contains global variables needed by the TOKEN object routines.
  9. Author:
  10. Jim Kelly (JimK) 18-May-1990
  11. Revision History:
  12. v10: robertre
  13. Added SepAccessCheck and SepPrivilegeCheck prototypes
  14. v11: robertre
  15. Added parameter to SepAccessCheck
  16. --*/
  17. #ifndef _TOKENP_
  18. #define _TOKENP_
  19. //#define TOKEN_DEBUG
  20. #include "ntos.h"
  21. #include "sep.h"
  22. #include "seopaque.h"
  23. /////////////////////////////////////////////////////////////////////////
  24. // //
  25. // Token Diagnostics //
  26. // //
  27. /////////////////////////////////////////////////////////////////////////
  28. #if DBG
  29. #define TOKEN_DIAGNOSTICS_ENABLED 1
  30. #endif // DBG
  31. //
  32. // These definitions are useful diagnostics aids
  33. //
  34. #if TOKEN_DIAGNOSTICS_ENABLED
  35. //
  36. // Test for enabled diagnostic
  37. //
  38. #define IF_TOKEN_GLOBAL( FlagName ) \
  39. if (TokenGlobalFlag & (TOKEN_DIAG_##FlagName))
  40. //
  41. // Diagnostics print statement
  42. //
  43. #define TokenDiagPrint( FlagName, _Text_ ) \
  44. IF_TOKEN_GLOBAL( FlagName ) \
  45. DbgPrint _Text_
  46. #else // !TOKEN_DIAGNOSTICS_ENABLED
  47. //
  48. // No diagnostics included in build
  49. //
  50. //
  51. // Test for diagnostics enabled
  52. //
  53. #define IF_TOKEN_GLOBAL( FlagName ) if (FALSE)
  54. //
  55. // Diagnostics print statement (expands to no-op)
  56. //
  57. #define TokenDiagPrint( FlagName, _Text_ ) ;
  58. #endif // TOKEN_DIAGNOSTICS_ENABLED
  59. //
  60. // The following flags enable or disable various diagnostic
  61. // capabilities within token code. These flags are set in
  62. // TokenGlobalFlag (only available within a DBG system).
  63. //
  64. //
  65. // TOKEN_LOCKS - Display information about acquisition and freeing
  66. // of token locks.
  67. //
  68. #define TOKEN_DIAG_TOKEN_LOCKS ((ULONG) 0x00000001L)
  69. /////////////////////////////////////////////////////////////////////////
  70. // //
  71. // Token Related Constants //
  72. // //
  73. /////////////////////////////////////////////////////////////////////////
  74. //
  75. // By default, a token is charged the following for its dynamic component.
  76. // The dynamic component houses the default ACL and primary group ID.
  77. // If the size of these parameters passed upon token creation are larger
  78. // than this default, then the larger value will be charged.
  79. //
  80. #define TOKEN_DEFAULT_DYNAMIC_CHARGE 500
  81. //
  82. // AuditPolicy bit array is arranged with 4 bits for each audit category.
  83. // The bit ordering for each category is:
  84. // Success Include, Success Exclude, Failure Include, Failure Exclude
  85. // The number of tokens that have audit policies
  86. // are tracked in SepTokenPolicyCounter. This is done so that when all tokens
  87. // with policies are gone (ie SepTokenPolicyCounter == 0) the routines that
  88. // decide if an audit should be generated can execute faster.
  89. //
  90. typedef struct _SEP_AUDIT_POLICY_CATEGORIES {
  91. ULONG System : 4;
  92. ULONG Logon : 4;
  93. ULONG ObjectAccess : 4;
  94. ULONG PrivilegeUse : 4;
  95. ULONG DetailedTracking : 4;
  96. ULONG PolicyChange : 4;
  97. ULONG AccountManagement : 4;
  98. ULONG DirectoryServiceAccess : 4;
  99. ULONG AccountLogon : 4;
  100. } SEP_AUDIT_POLICY_CATEGORIES, *PSEP_AUDIT_POLICY_CATEGORIES;
  101. typedef struct _SEP_AUDIT_POLICY_OVERLAY {
  102. ULONGLONG PolicyBits : 36;
  103. ULONGLONG SetBit : 1;
  104. } SEP_AUDIT_POLICY_OVERLAY, *PSEP_AUDIT_POLICY_OVERLAY;
  105. typedef struct _SEP_AUDIT_POLICY {
  106. union {
  107. SEP_AUDIT_POLICY_CATEGORIES PolicyElements;
  108. SEP_AUDIT_POLICY_OVERLAY PolicyOverlay;
  109. ULONGLONG Overlay;
  110. };
  111. } SEP_AUDIT_POLICY, *PSEP_AUDIT_POLICY;
  112. /////////////////////////////////////////////////////////////////////////
  113. // //
  114. // Token Object Body //
  115. // //
  116. /////////////////////////////////////////////////////////////////////////
  117. //
  118. // Tokens have three parts:
  119. //
  120. // Fixed part of body,
  121. // Variable part of body,
  122. // Dynamic part (not in body).
  123. //
  124. // The fixed and variable parts are allocated in a single block of memory.
  125. // The dynamic part is a separately allocated block of memory.
  126. //
  127. // The fixed part of the body contains the fixed length fields. These
  128. // are defined in the TOKEN data type.
  129. //
  130. // The variable part of the body is variable in length and contains
  131. // privileges and user/group SIDs. This part is variable in length
  132. // between different token objects, but does not change once established
  133. // for an individual token.
  134. //
  135. // The dynamic part is used to house default discretionary ACL information
  136. // and the primary group ID.
  137. //
  138. // Pictorially, a token looks like:
  139. //
  140. // ============== +---------------+
  141. // ^ | |
  142. // | | |
  143. // | | |
  144. // | | DynamicPart o-----------+
  145. // | |- - - - - - - -| |
  146. // +-----o Privileges | |
  147. // Token | |- - - - - - - -| |
  148. // Body | +--o UserAndGroups | |
  149. // | | | |- - - - - - - -| |
  150. // | | +--o RestrictedSids| \|/
  151. // | | | |- - - - - - - -| +---------------------+
  152. // | | | | PrimaryGroup o------->| [Primary Group SID] |
  153. // | | | |- - - - - - - -| | o |
  154. // | | | | DefaultAcl o---+ | o |
  155. // | | | |- - - - - - - -| | | o |
  156. // | | | | o | | |- - - - - - - - - - -|
  157. // | | | | o | +--->| [ Default Acl ] |
  158. // v | | | o | | o |
  159. // ==============| | |===============| | o |
  160. // ^ | +->| SIDs Array | | o |
  161. // | | | [User SID ] | +---------------------+
  162. // | | | [Group SID ] |
  163. // | | [Group SID ] |
  164. // Variable | | [Rest. Sid ] |
  165. // Part | | o |
  166. // | |- - - - - - - -|
  167. // | +---->| Privileges |
  168. // | | Array |
  169. // v | |
  170. // ============== +---------------+
  171. //
  172. // WARNING: The positions of fields illustrated in this picture are not
  173. // intented to reflect their actual or even relative positions
  174. // within the real data structures. The exception to this is
  175. // that THE USER SID IS THE FIRST SID IN THE UserAndGroups
  176. // ARRAY.
  177. //
  178. //
  179. // ! ! ! ! IMPORTANT ! ! ! !
  180. //
  181. // The access validation routines assume the SIDs are arranged
  182. // in a particular order within the variable part of the token.
  183. // Any changes to the order of the SIDs must be coordinated with
  184. // corresponding changes to the access validation routines.
  185. //
  186. // ! ! ! ! ! ! ! ! ! ! !
  187. typedef struct _TOKEN {
  188. //
  189. // Fields arranged by size to preserve alignment.
  190. // Large fields before small fields.
  191. //
  192. //
  193. // The following fields are either ReadOnly or ReadWrite.
  194. // ReadOnly fields may be referenced any time a pointer to the
  195. // token is still valid. ReadWrite fields may only be referenced
  196. // when the TokenLock is held.
  197. // The dynamic part of the token (pointed to by the DynamicPart field)
  198. // is also protected by the token lock.
  199. //
  200. // ReadOnly fields are marked Ro: in their comment.
  201. // ReadWrite fields are marked Wr: in their comment.
  202. //
  203. TOKEN_SOURCE TokenSource; // Ro: 16-Bytes
  204. LUID TokenId; // Ro: 8-Bytes
  205. LUID AuthenticationId; // Ro: 8-Bytes
  206. LUID ParentTokenId; // Ro: 8-Bytes
  207. LARGE_INTEGER ExpirationTime; // Ro: 8-Bytes
  208. PERESOURCE TokenLock; // Ro:
  209. SEP_AUDIT_POLICY AuditPolicy; // RW: 8 bytes
  210. //
  211. // Each time the security information in a token is changed, the
  212. // following ID is changed. Fields that cause this field to be
  213. // updated are marked as (Mod) in their comment field.
  214. //
  215. LUID ModifiedId; // Wr: 8-Bytes
  216. ULONG SessionId; // Wr: 4-bytes
  217. ULONG UserAndGroupCount; // Ro: 4-Bytes
  218. ULONG RestrictedSidCount; // Ro: 4-Bytes
  219. ULONG PrivilegeCount; // Ro: 4-Bytes
  220. ULONG VariableLength; // Ro: 4-Bytes
  221. ULONG DynamicCharged; // Ro: 4-Bytes
  222. ULONG DynamicAvailable; // Wr: 4-Bytes (Mod)
  223. ULONG DefaultOwnerIndex; // Wr: 4-Bytes (Mod)
  224. PSID_AND_ATTRIBUTES UserAndGroups; // Wr: 4-Bytes (Mod)
  225. PSID_AND_ATTRIBUTES RestrictedSids; // Ro: 4-Bytes
  226. PSID PrimaryGroup; // Wr: 4-Bytes (Mod)
  227. PLUID_AND_ATTRIBUTES Privileges; // Wr: 4-Bytes (Mod)
  228. PULONG DynamicPart; // Wr: 4-Bytes (Mod)
  229. PACL DefaultDacl; // Wr: 4-Bytes (Mod)
  230. TOKEN_TYPE TokenType; // Ro: 1-Byte
  231. SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; // Ro: 1-Byte
  232. UCHAR TokenFlags; // Rw: 4-Bytes
  233. BOOLEAN TokenInUse; // Wr: 1-Byte
  234. PSECURITY_TOKEN_PROXY_DATA ProxyData; // Ro: 4-Bytes
  235. PSECURITY_TOKEN_AUDIT_DATA AuditData; // Ro: 4-Bytes
  236. //
  237. // Pointer to the referenced logon session. Protected by the token
  238. // lock and only valid when TOKEN_SESSION_NOT_REFERENCED is clear.
  239. //
  240. PSEP_LOGON_SESSION_REFERENCES LogonSession; // Rw: Ptr
  241. //
  242. // Originating information for allowing certain impersonation operations
  243. // later
  244. //
  245. LUID OriginatingLogonSession ; // Rw: 8 bytes (set by LSA)
  246. #if DBG || TOKEN_LEAK_MONITOR
  247. #define TRACE_SIZE 30
  248. //
  249. // This code is for tracking token leaks, in conjunction with !obtrace.
  250. //
  251. HANDLE ProcessCid; // Cid of creator process
  252. HANDLE ThreadCid; // Cid of creator thread
  253. UCHAR ImageFileName[16]; // Image name of creator process
  254. ULONG CreateMethod; // Either 0xC (SepCreateToken) 0xD (SepDuplicateToken) or 0xF (SepFilterToken)
  255. ULONG_PTR CreateTrace[TRACE_SIZE]; // Stack backtrace that created this token (usermode part is first 20 nonzero stack entries)
  256. LONG Count; // This is the nth token created with watch method
  257. LONG CaptureCount; // This is the # of SeCaptureSubjectContext - SeReleaseSubjectContext
  258. #endif
  259. //
  260. // This marks the beginning of the variable part of the token.
  261. // It must follow all other fields in the token.
  262. //
  263. ULONG VariablePart; // Wr: 4-Bytes (Mod)
  264. } TOKEN, * PTOKEN;
  265. //
  266. // Where:
  267. //
  268. // TokenSource - Information provided by the executive component that
  269. // requested the logon that the token represents.
  270. //
  271. //
  272. // TokenId - Is an LUID value. Each token object has a uniquely
  273. // assigned LUID.
  274. //
  275. //
  276. // AuthenticationId - Is the LUID assigned by the domain controller for
  277. // the logon session.
  278. //
  279. //
  280. // ExpirationTime - Not yet supported in NT.
  281. //
  282. //
  283. // ModifiedId - Is an LUID which is changed each time a modification is
  284. // made to this token which changes the security semantics of the
  285. // token. This includes enabling/disabling privileges and groups
  286. // and changing default ACLs, et cetera. Any token which is a
  287. // duplicate of this token will have the same ModifiedId (until
  288. // one or the other is changed). This does not cover changes to
  289. // non-security semantics fields, like TokenInUse.
  290. //
  291. //
  292. // UserAndGroupCount - Indicates the number of user/group IDs in this token.
  293. // This value must be at least 1. A value of 1 indicates a user
  294. // ID with no supplemental group IDs. A value of 5 indicates a
  295. // user ID and 4 supplemental group IDs.
  296. //
  297. // PrivilegeCount - Indicates how many privileges are included in
  298. // this token. May be zero or larger.
  299. //
  300. // TokenType - Indicates which type of token this token object is.
  301. //
  302. // ImpersonationLevel - For TokenImpersonation type tokens, this field
  303. // indicates the impersonation level. For TokenPrimary type tokens,
  304. // this field is ignored.
  305. //
  306. // DynamicCharged - Indicates how much pool quota has been charged
  307. // for the dynamic portion of this token.
  308. //
  309. // DynamicAvailable - Indicates how much of the charged quota is still
  310. // available for use. This is modified when pool associated
  311. // with the dynamic portion of the token is allocated or freed,
  312. // such as when the default DACL or primary group is replaced.
  313. //
  314. //
  315. // DefaultOwnerIndex - If non-zero, identifies an ID that has explicitly
  316. // been established as the default owner for this token. If it is zero,
  317. // the standard default (user ID) is used as the default owner.
  318. //
  319. // UserAndGroups - Points to an array of SID_AND_ATTRIBUTES. The first
  320. // element in this array is the token's user ID. Any additional
  321. // elements are those of groups. The number of entries in this
  322. // array is one greater than
  323. //
  324. // PrimaryGroup - Points to an SID that is to be used as the primary
  325. // group of the token. There are no value restrictions
  326. // placed upon what can be used as a primary group. This
  327. // SID is not one of user or group IDs (although it may have the
  328. // same value as one of those IDs).
  329. //
  330. // Privileges - Points to an array of privileges represented as
  331. // LUID_AND_ATTRIBUTES. The number of elements in this array
  332. // is contained in the PrivilegesCount field.
  333. //
  334. // TokenInUse - Is a boolean that indicates whether a primary token
  335. // is already in use by a process. This field value is only
  336. // valid for primary tokens.
  337. //
  338. // ProxyData - Optionally points to a Proxy data structure, containing
  339. // the information to be passed to AVR routines by file systems.
  340. // This field being non-null identifies the token as a proxy token.
  341. //
  342. // AuditData - Optionally points to an Audit data structure, containing
  343. // global auditing data for this subject.
  344. //
  345. // NOTE: Access to this field is guarded by the global
  346. // PROCESS SECURITY FIELDS LOCK.
  347. // VariablePart - Is the beginning of the variable part of the token.
  348. //
  349. ////////////////////////////////////////////////////////////////////////
  350. //
  351. // Internal version of Object Type list
  352. //
  353. ////////////////////////////////////////////////////////////////////////
  354. typedef struct _IOBJECT_TYPE_LIST {
  355. USHORT Level;
  356. USHORT Flags;
  357. #define OBJECT_SUCCESS_AUDIT 0x1
  358. #define OBJECT_FAILURE_AUDIT 0x2
  359. GUID ObjectType;
  360. LONG ParentIndex;
  361. ULONG Remaining;
  362. ULONG CurrentGranted;
  363. ULONG CurrentDenied;
  364. } IOBJECT_TYPE_LIST, *PIOBJECT_TYPE_LIST;
  365. NTSTATUS
  366. SeCaptureObjectTypeList (
  367. IN POBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  368. IN ULONG ObjectTypeListLength,
  369. IN KPROCESSOR_MODE RequestorMode,
  370. OUT PIOBJECT_TYPE_LIST *CapturedObjectTypeList
  371. );
  372. VOID
  373. SeFreeCapturedObjectTypeList(
  374. IN PVOID ObjectTypeList
  375. );
  376. /////////////////////////////////////////////////////////////////////////
  377. // //
  378. // Token Specific Macros //
  379. // //
  380. /////////////////////////////////////////////////////////////////////////
  381. #ifndef TOKEN_DIAGNOSTICS_ENABLED
  382. #define SepAcquireTokenReadLock(T) KeEnterCriticalRegion(); \
  383. ExAcquireResourceSharedLite((T)->TokenLock, TRUE)
  384. #define SepAcquireTokenWriteLock(T) KeEnterCriticalRegion(); \
  385. ExAcquireResourceExclusiveLite((T)->TokenLock, TRUE)
  386. #define SepReleaseTokenReadLock(T) ExReleaseResourceLite((T)->TokenLock); \
  387. KeLeaveCriticalRegion()
  388. #else // TOKEN_DIAGNOSTICS_ENABLED
  389. #define SepAcquireTokenReadLock(T) if (TokenGlobalFlag & TOKEN_DIAG_TOKEN_LOCKS) { \
  390. DbgPrint("SE (Token): Acquiring Token READ Lock for access to token 0x%lx\n", (T)); \
  391. } \
  392. KeEnterCriticalRegion(); \
  393. ExAcquireResourceSharedLite((T)->TokenLock, TRUE)
  394. #define SepAcquireTokenWriteLock(T) if (TokenGlobalFlag & TOKEN_DIAG_TOKEN_LOCKS) { \
  395. DbgPrint("SE (Token): Acquiring Token WRITE Lock for access to token 0x%lx ********************* EXCLUSIVE *****\n", (T)); \
  396. } \
  397. KeEnterCriticalRegion(); \
  398. ExAcquireResourceExclusiveLite((T)->TokenLock, TRUE)
  399. #define SepReleaseTokenReadLock(T) if (TokenGlobalFlag & TOKEN_DIAG_TOKEN_LOCKS) { \
  400. DbgPrint("SE (Token): Releasing Token Lock for access to token 0x%lx\n", (T)); \
  401. } \
  402. ExReleaseResourceLite((T)->TokenLock); \
  403. KeLeaveCriticalRegion()
  404. #endif // TOKEN_DIAGNOSTICS_ENABLED
  405. #define SepReleaseTokenWriteLock(T,M) \
  406. { \
  407. if ((M)) { \
  408. ExAllocateLocallyUniqueId( &((PTOKEN)(T))->ModifiedId ); \
  409. } \
  410. SepReleaseTokenReadLock( T ); \
  411. }
  412. //
  413. // Reference individual privilege attribute flags of any privilege array
  414. //
  415. // P - is a pointer to an array of privileges (PLUID_AND_ATTRIBUTES)
  416. // I - is the index of the privilege
  417. // A - is the name of the attribute desired (e.g., Enabled, EnabledByDefault, etc. )
  418. //
  419. #define SepArrayPrivilegeAttributes(P,I) ( (P)[I].Attributes )
  420. //
  421. // Reference individual privilege attribute flags of token privileges
  422. //
  423. // T - is a pointer to a token
  424. // I - is the index of the privilege
  425. // A - is the name of the attribute desired (e.g., Enabled, EnabledByDefault, etc. )
  426. //
  427. #define SepTokenPrivilegeAttributes(T,I) ( (T)->Privileges[I].Attributes )
  428. //
  429. // Reference individual group attribute flags of any group array
  430. //
  431. // G - is a pointer to the array of groups (SID_AND_ATTRIBUTES[])
  432. // I - is the index of the group
  433. //
  434. #define SepArrayGroupAttributes(G,I) ( (G)[I].Attributes )
  435. //
  436. // Reference individual group attribute flags of token groups
  437. //
  438. // T - is a pointer to a token
  439. // I - is the index of the group
  440. //
  441. #define SepTokenGroupAttributes(T,I) ( (T)->UserAndGroups[I].Attributes )
  442. ////////////////////////////////////////////////////////////////////////
  443. // //
  444. // Private Routine Declarations //
  445. // //
  446. ////////////////////////////////////////////////////////////////////////
  447. NTSTATUS
  448. SepAdjustGroups(
  449. IN PTOKEN Token,
  450. IN BOOLEAN MakeChanges,
  451. IN BOOLEAN ResetToDefault,
  452. IN ULONG GroupCount OPTIONAL,
  453. IN PSID_AND_ATTRIBUTES NewState OPTIONAL,
  454. OUT PTOKEN_GROUPS PreviousState OPTIONAL,
  455. OUT PSID SidBuffer OPTIONAL,
  456. OUT PULONG ReturnLength,
  457. OUT PULONG ChangeCount,
  458. OUT PBOOLEAN ChangesMade
  459. );
  460. NTSTATUS
  461. SepAdjustPrivileges(
  462. IN PTOKEN Token,
  463. IN BOOLEAN MakeChanges,
  464. IN BOOLEAN DisableAllPrivileges,
  465. IN ULONG PrivilegeCount OPTIONAL,
  466. IN PLUID_AND_ATTRIBUTES NewState OPTIONAL,
  467. OUT PTOKEN_PRIVILEGES PreviousState OPTIONAL,
  468. OUT PULONG ReturnLength,
  469. OUT PULONG ChangeCount,
  470. OUT PBOOLEAN ChangesMade
  471. );
  472. VOID
  473. SepAppendDefaultDacl(
  474. IN PTOKEN Token,
  475. IN PACL PAcl
  476. );
  477. VOID
  478. SepAppendPrimaryGroup(
  479. IN PTOKEN Token,
  480. IN PSID PSid
  481. );
  482. NTSTATUS
  483. SepDuplicateToken(
  484. IN PTOKEN ExistingToken,
  485. IN POBJECT_ATTRIBUTES ObjectAttributes,
  486. IN BOOLEAN EffectiveOnly,
  487. IN TOKEN_TYPE TokenType,
  488. IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel OPTIONAL,
  489. IN KPROCESSOR_MODE RequestorMode,
  490. OUT PTOKEN *DuplicateToken
  491. );
  492. NTSTATUS
  493. SepFilterToken(
  494. IN PTOKEN ExistingToken,
  495. IN KPROCESSOR_MODE RequestorMode,
  496. IN ULONG Flags,
  497. IN ULONG GroupCount,
  498. IN PSID_AND_ATTRIBUTES GroupsToDisable OPTIONAL,
  499. IN ULONG PrivilegeCount,
  500. IN PLUID_AND_ATTRIBUTES PrivilegesToDelete OPTIONAL,
  501. IN ULONG SidCount,
  502. IN PSID_AND_ATTRIBUTES RestrictedSids OPTIONAL,
  503. IN ULONG SidLength,
  504. OUT PTOKEN * FilteredToken
  505. );
  506. BOOLEAN
  507. SepSidInSidAndAttributes (
  508. IN PSID_AND_ATTRIBUTES SidAndAttributes,
  509. IN ULONG SidCount,
  510. IN PSID PrincipalSelfSid,
  511. IN PSID Sid
  512. );
  513. VOID
  514. SepRemoveDisabledGroupsAndPrivileges(
  515. IN PTOKEN Token,
  516. IN ULONG Flags,
  517. IN ULONG GroupCount,
  518. IN PSID_AND_ATTRIBUTES GroupsToDisable,
  519. IN ULONG PrivilegeCount,
  520. IN PLUID_AND_ATTRIBUTES PrivilegesToDelete
  521. );
  522. VOID
  523. SepFreeDefaultDacl(
  524. IN PTOKEN Token
  525. );
  526. VOID
  527. SepFreePrimaryGroup(
  528. IN PTOKEN Token
  529. );
  530. NTSTATUS
  531. SepExpandDynamic(
  532. IN PTOKEN Token,
  533. IN ULONG NewLength
  534. );
  535. BOOLEAN
  536. SepIdAssignableAsOwner(
  537. IN PTOKEN Token,
  538. IN ULONG Index
  539. );
  540. VOID
  541. SepMakeTokenEffectiveOnly(
  542. IN PTOKEN Token
  543. );
  544. BOOLEAN
  545. SepTokenInitialization( VOID );
  546. VOID
  547. SepTokenDeleteMethod (
  548. IN PVOID Token
  549. );
  550. //
  551. // These are here because if they are placed in sep.h, we don't
  552. // have the PTOKEN datatype available.
  553. //
  554. BOOLEAN
  555. SepPrivilegeCheck(
  556. IN PTOKEN Token,
  557. IN OUT PLUID_AND_ATTRIBUTES RequiredPrivileges,
  558. IN ULONG RequiredPrivilegeCount,
  559. IN ULONG PrivilegeSetControl,
  560. IN KPROCESSOR_MODE PreviousMode
  561. );
  562. BOOLEAN
  563. SepAccessCheck (
  564. IN PSECURITY_DESCRIPTOR SecurityDescriptor,
  565. IN PSID PrincipalSelfSid,
  566. IN PTOKEN PrimaryToken,
  567. IN PTOKEN ClientToken OPTIONAL,
  568. IN ACCESS_MASK DesiredAccess,
  569. IN PIOBJECT_TYPE_LIST ObjectTypeList OPTIONAL,
  570. IN ULONG ObjectTypeListLength,
  571. IN PGENERIC_MAPPING GenericMapping,
  572. IN ACCESS_MASK PreviouslyGrantedAccess,
  573. IN KPROCESSOR_MODE PreviousMode,
  574. OUT PACCESS_MASK GrantedAccess,
  575. OUT PPRIVILEGE_SET *Privileges OPTIONAL,
  576. OUT PNTSTATUS AccessStatus,
  577. IN BOOLEAN ReturnResultList,
  578. OUT PBOOLEAN ReturnSomeAccessGranted,
  579. OUT PBOOLEAN ReturnSomeAccessDenied
  580. );
  581. BOOLEAN
  582. SepObjectInTypeList (
  583. IN GUID *ObjectType,
  584. IN PIOBJECT_TYPE_LIST ObjectTypeList,
  585. IN ULONG ObjectTypeListLength,
  586. OUT PULONG ReturnedIndex
  587. );
  588. VOID
  589. SepModifyTokenPolicyCounter(
  590. PSEP_AUDIT_POLICY TokenPolicy,
  591. BOOLEAN bIncrement
  592. );
  593. NTSTATUS
  594. FORCEINLINE
  595. SepDuplicateLogonSessionReference(
  596. IN PTOKEN NewToken,
  597. IN PTOKEN ExistingToken
  598. )
  599. {
  600. PSEP_LOGON_SESSION_REFERENCES LogonSession;
  601. LONG NewRef;
  602. NTSTATUS Status;
  603. //
  604. // Obtain the logon session reference. If the existing token
  605. // has a reference then use that to obtain a new one. Otherwise
  606. // Look up the session the slow way.
  607. //
  608. if ((ExistingToken->TokenFlags & TOKEN_SESSION_NOT_REFERENCED) == 0) {
  609. LogonSession = ExistingToken->LogonSession;
  610. NewToken->LogonSession = LogonSession;
  611. NewRef = InterlockedIncrement (&LogonSession->ReferenceCount);
  612. ASSERT (NewRef > 1);
  613. return STATUS_SUCCESS;
  614. } else {
  615. Status = SepReferenceLogonSession (&ExistingToken->AuthenticationId,
  616. &NewToken->LogonSession);
  617. if (!NT_SUCCESS (Status)) {
  618. NewToken->TokenFlags |= TOKEN_SESSION_NOT_REFERENCED;
  619. NewToken->LogonSession = NULL;
  620. }
  621. return Status;
  622. }
  623. }
  624. VOID
  625. FORCEINLINE
  626. SepDeReferenceLogonSessionDirect(
  627. IN PSEP_LOGON_SESSION_REFERENCES LogonSession
  628. )
  629. {
  630. LONG OldValue;
  631. LUID LogonId;
  632. while (1) {
  633. OldValue = LogonSession->ReferenceCount;
  634. ASSERT (OldValue > 0);
  635. if (OldValue == 1) {
  636. LogonId = LogonSession->LogonId;
  637. SepDeReferenceLogonSession (&LogonId);
  638. break;
  639. }
  640. if (InterlockedCompareExchange (&LogonSession->ReferenceCount, OldValue-1, OldValue) == OldValue) {
  641. break;
  642. }
  643. }
  644. }
  645. #ifdef TOKEN_DEBUG
  646. VOID
  647. SepDumpToken(
  648. IN PTOKEN T
  649. );
  650. #endif //TOKEN_DEBUG
  651. ////////////////////////////////////////////////////////////////////////
  652. // //
  653. // Global Variables //
  654. // //
  655. ////////////////////////////////////////////////////////////////////////
  656. extern const GENERIC_MAPPING SepTokenMapping;
  657. extern POBJECT_TYPE SeTokenObjectType;
  658. //extern ERESOURCE SepTokenLock;
  659. #ifdef TOKEN_DIAGNOSTICS_ENABLED
  660. extern ULONG TokenGlobalFlag;
  661. #endif // TOKEN_DIAGNOSTICS_ENABLED
  662. #endif // _TOKENP_