3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/se/semgr.c
6 * PURPOSE: Security manager
8 * PROGRAMMERS: No programmer listed.
11 /* INCLUDES *****************************************************************/
15 #include <internal/debug.h>
17 #define TAG_SXPT TAG('S', 'X', 'P', 'T')
20 /* GLOBALS ******************************************************************/
22 PSE_EXPORTS EXPORTED SeExports
= NULL
;
24 static ERESOURCE SepSubjectContextLock
;
27 /* PROTOTYPES ***************************************************************/
29 static BOOLEAN
SepInitExports(VOID
);
32 /* FUNCTIONS ****************************************************************/
39 if (!SepInitSecurityIDs())
50 if (!SepInitExports())
53 /* Initialize the subject context lock */
54 ExInitializeResource(&SepSubjectContextLock
);
63 SepInitializeTokenImplementation();
72 OBJECT_ATTRIBUTES ObjectAttributes
;
74 HANDLE DirectoryHandle
;
78 /* Create '\Security' directory */
79 RtlInitUnicodeString(&Name
,
81 InitializeObjectAttributes(&ObjectAttributes
,
86 Status
= ZwCreateDirectoryObject(&DirectoryHandle
,
89 if (!NT_SUCCESS(Status
))
91 DPRINT1("Failed to create 'Security' directory!\n");
95 /* Create 'LSA_AUTHENTICATION_INITALIZED' event */
96 RtlInitUnicodeString(&Name
,
97 L
"\\LSA_AUTHENTICATION_INITALIZED");
98 InitializeObjectAttributes(&ObjectAttributes
,
103 Status
= ZwCreateEvent(&EventHandle
,
106 SynchronizationEvent
,
108 if (!NT_SUCCESS(Status
))
110 DPRINT1("Failed to create 'LSA_AUTHENTICATION_INITALIZED' event!\n");
111 NtClose(DirectoryHandle
);
115 ZwClose(EventHandle
);
116 ZwClose(DirectoryHandle
);
118 /* FIXME: Create SRM port and listener thread */
124 static BOOLEAN INIT_FUNCTION
127 SeExports
= ExAllocatePoolWithTag(NonPagedPool
,
130 if (SeExports
== NULL
)
133 SeExports
->SeCreateTokenPrivilege
= SeCreateTokenPrivilege
;
134 SeExports
->SeAssignPrimaryTokenPrivilege
= SeAssignPrimaryTokenPrivilege
;
135 SeExports
->SeLockMemoryPrivilege
= SeLockMemoryPrivilege
;
136 SeExports
->SeIncreaseQuotaPrivilege
= SeIncreaseQuotaPrivilege
;
137 SeExports
->SeUnsolicitedInputPrivilege
= SeUnsolicitedInputPrivilege
;
138 SeExports
->SeTcbPrivilege
= SeTcbPrivilege
;
139 SeExports
->SeSecurityPrivilege
= SeSecurityPrivilege
;
140 SeExports
->SeTakeOwnershipPrivilege
= SeTakeOwnershipPrivilege
;
141 SeExports
->SeLoadDriverPrivilege
= SeLoadDriverPrivilege
;
142 SeExports
->SeCreatePagefilePrivilege
= SeCreatePagefilePrivilege
;
143 SeExports
->SeIncreaseBasePriorityPrivilege
= SeIncreaseBasePriorityPrivilege
;
144 SeExports
->SeSystemProfilePrivilege
= SeSystemProfilePrivilege
;
145 SeExports
->SeSystemtimePrivilege
= SeSystemtimePrivilege
;
146 SeExports
->SeProfileSingleProcessPrivilege
= SeProfileSingleProcessPrivilege
;
147 SeExports
->SeCreatePermanentPrivilege
= SeCreatePermanentPrivilege
;
148 SeExports
->SeBackupPrivilege
= SeBackupPrivilege
;
149 SeExports
->SeRestorePrivilege
= SeRestorePrivilege
;
150 SeExports
->SeShutdownPrivilege
= SeShutdownPrivilege
;
151 SeExports
->SeDebugPrivilege
= SeDebugPrivilege
;
152 SeExports
->SeAuditPrivilege
= SeAuditPrivilege
;
153 SeExports
->SeSystemEnvironmentPrivilege
= SeSystemEnvironmentPrivilege
;
154 SeExports
->SeChangeNotifyPrivilege
= SeChangeNotifyPrivilege
;
155 SeExports
->SeRemoteShutdownPrivilege
= SeRemoteShutdownPrivilege
;
157 SeExports
->SeNullSid
= SeNullSid
;
158 SeExports
->SeWorldSid
= SeWorldSid
;
159 SeExports
->SeLocalSid
= SeLocalSid
;
160 SeExports
->SeCreatorOwnerSid
= SeCreatorOwnerSid
;
161 SeExports
->SeCreatorGroupSid
= SeCreatorGroupSid
;
162 SeExports
->SeNtAuthoritySid
= SeNtAuthoritySid
;
163 SeExports
->SeDialupSid
= SeDialupSid
;
164 SeExports
->SeNetworkSid
= SeNetworkSid
;
165 SeExports
->SeBatchSid
= SeBatchSid
;
166 SeExports
->SeInteractiveSid
= SeInteractiveSid
;
167 SeExports
->SeLocalSystemSid
= SeLocalSystemSid
;
168 SeExports
->SeAliasAdminsSid
= SeAliasAdminsSid
;
169 SeExports
->SeAliasUsersSid
= SeAliasUsersSid
;
170 SeExports
->SeAliasGuestsSid
= SeAliasGuestsSid
;
171 SeExports
->SeAliasPowerUsersSid
= SeAliasPowerUsersSid
;
172 SeExports
->SeAliasAccountOpsSid
= SeAliasAccountOpsSid
;
173 SeExports
->SeAliasSystemOpsSid
= SeAliasSystemOpsSid
;
174 SeExports
->SeAliasPrintOpsSid
= SeAliasPrintOpsSid
;
175 SeExports
->SeAliasBackupOpsSid
= SeAliasBackupOpsSid
;
181 VOID
SepReferenceLogonSession(PLUID AuthenticationId
)
186 VOID
SepDeReferenceLogonSession(PLUID AuthenticationId
)
196 SeCaptureSubjectContext(OUT PSECURITY_SUBJECT_CONTEXT SubjectContext
)
200 BOOLEAN EffectiveOnly
;
204 Thread
= PsGetCurrentThread();
207 SubjectContext
->ProcessAuditId
= 0;
208 SubjectContext
->PrimaryToken
= NULL
;
209 SubjectContext
->ClientToken
= NULL
;
210 SubjectContext
->ImpersonationLevel
= 0;
214 SubjectContext
->ProcessAuditId
= Thread
->ThreadsProcess
;
215 SubjectContext
->ClientToken
=
216 PsReferenceImpersonationToken(Thread
,
219 &SubjectContext
->ImpersonationLevel
);
220 SubjectContext
->PrimaryToken
= PsReferencePrimaryToken(Thread
->ThreadsProcess
);
229 SeLockSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext
)
233 KeEnterCriticalRegion();
234 ExAcquireResourceExclusiveLite(&SepSubjectContextLock
, TRUE
);
242 SeUnlockSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext
)
246 ExReleaseResourceLite(&SepSubjectContextLock
);
247 KeLeaveCriticalRegion();
255 SeReleaseSubjectContext(IN PSECURITY_SUBJECT_CONTEXT SubjectContext
)
259 if (SubjectContext
->PrimaryToken
!= NULL
)
261 ObDereferenceObject(SubjectContext
->PrimaryToken
);
264 if (SubjectContext
->ClientToken
!= NULL
)
266 ObDereferenceObject(SubjectContext
->ClientToken
);
275 SeDeassignSecurity(PSECURITY_DESCRIPTOR
*SecurityDescriptor
)
279 if (*SecurityDescriptor
!= NULL
)
281 ExFreePool(*SecurityDescriptor
);
282 *SecurityDescriptor
= NULL
;
285 return STATUS_SUCCESS
;
293 SeAssignSecurityEx(IN PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL
,
294 IN PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL
,
295 OUT PSECURITY_DESCRIPTOR
*NewDescriptor
,
296 IN GUID
*ObjectType OPTIONAL
,
297 IN BOOLEAN IsDirectoryObject
,
298 IN ULONG AutoInheritFlags
,
299 IN PSECURITY_SUBJECT_CONTEXT SubjectContext
,
300 IN PGENERIC_MAPPING GenericMapping
,
301 IN POOL_TYPE PoolType
)
304 return STATUS_NOT_IMPLEMENTED
;
309 * FUNCTION: Creates a security descriptor for a new object.
312 * ExplicitDescriptor =
314 * IsDirectoryObject =
323 SeAssignSecurity(PSECURITY_DESCRIPTOR ParentDescriptor OPTIONAL
,
324 PSECURITY_DESCRIPTOR ExplicitDescriptor OPTIONAL
,
325 PSECURITY_DESCRIPTOR
*NewDescriptor
,
326 BOOLEAN IsDirectoryObject
,
327 PSECURITY_SUBJECT_CONTEXT SubjectContext
,
328 PGENERIC_MAPPING GenericMapping
,
331 PSECURITY_DESCRIPTOR Descriptor
;
333 ULONG OwnerLength
= 0;
334 ULONG GroupLength
= 0;
335 ULONG DaclLength
= 0;
336 ULONG SaclLength
= 0;
347 /* Lock subject context */
348 SeLockSubjectContext(SubjectContext
);
350 if (SubjectContext
->ClientToken
!= NULL
)
352 Token
= SubjectContext
->ClientToken
;
356 Token
= SubjectContext
->PrimaryToken
;
360 /* Inherit the Owner SID */
361 if (ExplicitDescriptor
!= NULL
&& ExplicitDescriptor
->Owner
!= NULL
)
363 DPRINT("Use explicit owner sid!\n");
364 Owner
= ExplicitDescriptor
->Owner
;
366 if (ExplicitDescriptor
->Control
& SE_SELF_RELATIVE
)
368 Owner
= (PSID
)(((ULONG_PTR
)Owner
) + (ULONG_PTR
)ExplicitDescriptor
);
376 DPRINT("Use token owner sid!\n");
377 Owner
= Token
->UserAndGroups
[Token
->DefaultOwnerIndex
].Sid
;
381 DPRINT("Use default owner sid!\n");
382 Owner
= SeLocalSystemSid
;
385 Control
|= SE_OWNER_DEFAULTED
;
388 OwnerLength
= ROUND_UP(RtlLengthSid(Owner
), 4);
391 /* Inherit the Group SID */
392 if (ExplicitDescriptor
!= NULL
&& ExplicitDescriptor
->Group
!= NULL
)
394 DPRINT("Use explicit group sid!\n");
395 Group
= ExplicitDescriptor
->Group
;
396 if (ExplicitDescriptor
->Control
& SE_SELF_RELATIVE
)
398 Group
= (PSID
)(((ULONG_PTR
)Group
) + (ULONG_PTR
)ExplicitDescriptor
);
405 DPRINT("Use token group sid!\n");
406 Group
= Token
->PrimaryGroup
;
410 DPRINT("Use default group sid!\n");
411 Group
= SeLocalSystemSid
;
414 Control
|= SE_OWNER_DEFAULTED
;
417 GroupLength
= ROUND_UP(RtlLengthSid(Group
), 4);
420 /* Inherit the DACL */
421 if (ExplicitDescriptor
!= NULL
&&
422 (ExplicitDescriptor
->Control
& SE_DACL_PRESENT
) &&
423 !(ExplicitDescriptor
->Control
& SE_DACL_DEFAULTED
))
425 DPRINT("Use explicit DACL!\n");
426 Dacl
= ExplicitDescriptor
->Dacl
;
427 if (Dacl
!= NULL
&& (ExplicitDescriptor
->Control
& SE_SELF_RELATIVE
))
429 Dacl
= (PACL
)(((ULONG_PTR
)Dacl
) + (ULONG_PTR
)ExplicitDescriptor
);
432 Control
|= SE_DACL_PRESENT
;
434 else if (ParentDescriptor
!= NULL
&&
435 (ParentDescriptor
->Control
& SE_DACL_PRESENT
))
437 DPRINT("Use parent DACL!\n");
439 Dacl
= ParentDescriptor
->Dacl
;
440 if (Dacl
!= NULL
&& (ParentDescriptor
->Control
& SE_SELF_RELATIVE
))
442 Dacl
= (PACL
)(((ULONG_PTR
)Dacl
) + (ULONG_PTR
)ParentDescriptor
);
444 Control
|= (SE_DACL_PRESENT
| SE_DACL_DEFAULTED
);
446 else if (Token
!= NULL
&& Token
->DefaultDacl
!= NULL
)
448 DPRINT("Use token default DACL!\n");
450 Dacl
= Token
->DefaultDacl
;
451 Control
|= (SE_DACL_PRESENT
| SE_DACL_DEFAULTED
);
455 DPRINT("Use NULL DACL!\n");
457 Control
|= (SE_DACL_PRESENT
| SE_DACL_DEFAULTED
);
460 DaclLength
= (Dacl
!= NULL
) ? ROUND_UP(Dacl
->AclSize
, 4) : 0;
463 /* Inherit the SACL */
464 if (ExplicitDescriptor
!= NULL
&&
465 (ExplicitDescriptor
->Control
& SE_SACL_PRESENT
) &&
466 !(ExplicitDescriptor
->Control
& SE_SACL_DEFAULTED
))
468 DPRINT("Use explicit SACL!\n");
469 Sacl
= ExplicitDescriptor
->Sacl
;
470 if (Sacl
!= NULL
&& (ExplicitDescriptor
->Control
& SE_SELF_RELATIVE
))
472 Sacl
= (PACL
)(((ULONG_PTR
)Sacl
) + (ULONG_PTR
)ExplicitDescriptor
);
475 Control
|= SE_SACL_PRESENT
;
477 else if (ParentDescriptor
!= NULL
&&
478 (ParentDescriptor
->Control
& SE_SACL_PRESENT
))
480 DPRINT("Use parent SACL!\n");
482 Sacl
= ParentDescriptor
->Sacl
;
483 if (Sacl
!= NULL
&& (ParentDescriptor
->Control
& SE_SELF_RELATIVE
))
485 Sacl
= (PACL
)(((ULONG_PTR
)Sacl
) + (ULONG_PTR
)ParentDescriptor
);
487 Control
|= (SE_SACL_PRESENT
| SE_SACL_DEFAULTED
);
490 SaclLength
= (Sacl
!= NULL
) ? ROUND_UP(Sacl
->AclSize
, 4) : 0;
493 /* Allocate and initialize the new security descriptor */
494 Length
= sizeof(SECURITY_DESCRIPTOR
) +
495 OwnerLength
+ GroupLength
+ DaclLength
+ SaclLength
;
497 DPRINT("L: sizeof(SECURITY_DESCRIPTOR) %d OwnerLength %d GroupLength %d DaclLength %d SaclLength %d\n",
498 sizeof(SECURITY_DESCRIPTOR
),
504 Descriptor
= ExAllocatePool(NonPagedPool
,
506 RtlZeroMemory( Descriptor
, Length
);
508 if (Descriptor
== NULL
)
510 DPRINT1("ExAlloctePool() failed\n");
511 /* FIXME: Unlock subject context */
512 return STATUS_INSUFFICIENT_RESOURCES
;
515 RtlCreateSecurityDescriptor(Descriptor
,
516 SECURITY_DESCRIPTOR_REVISION
);
518 Descriptor
->Control
= Control
| SE_SELF_RELATIVE
;
520 Current
= (ULONG_PTR
)Descriptor
+ sizeof(SECURITY_DESCRIPTOR
);
524 RtlCopyMemory((PVOID
)Current
,
527 Descriptor
->Sacl
= (PACL
)((ULONG_PTR
)Current
- (ULONG_PTR
)Descriptor
);
528 Current
+= SaclLength
;
533 RtlCopyMemory((PVOID
)Current
,
536 Descriptor
->Dacl
= (PACL
)((ULONG_PTR
)Current
- (ULONG_PTR
)Descriptor
);
537 Current
+= DaclLength
;
540 if (OwnerLength
!= 0)
542 RtlCopyMemory((PVOID
)Current
,
545 Descriptor
->Owner
= (PSID
)((ULONG_PTR
)Current
- (ULONG_PTR
)Descriptor
);
546 Current
+= OwnerLength
;
547 DPRINT("Owner of %x at %x\n", Descriptor
, Descriptor
->Owner
);
550 DPRINT("Owner of %x is zero length\n", Descriptor
);
552 if (GroupLength
!= 0)
554 memmove((PVOID
)Current
,
557 Descriptor
->Group
= (PSID
)((ULONG_PTR
)Current
- (ULONG_PTR
)Descriptor
);
560 /* Unlock subject context */
561 SeUnlockSubjectContext(SubjectContext
);
563 *NewDescriptor
= Descriptor
;
565 DPRINT("Descrptor %x\n", Descriptor
);
566 ASSERT(RtlLengthSecurityDescriptor(Descriptor
));
568 return STATUS_SUCCESS
;
573 SepSidInToken(PACCESS_TOKEN _Token
,
577 PTOKEN Token
= (PTOKEN
)_Token
;
581 if (Token
->UserAndGroupCount
== 0)
586 for (i
=0; i
<Token
->UserAndGroupCount
; i
++)
588 if (RtlEqualSid(Sid
, Token
->UserAndGroups
[i
].Sid
))
590 if (Token
->UserAndGroups
[i
].Attributes
& SE_GROUP_ENABLED
)
604 * FUNCTION: Determines whether the requested access rights can be granted
605 * to an object protected by a security descriptor and an object owner
607 * SecurityDescriptor = Security descriptor protecting the object
608 * SubjectSecurityContext = Subject's captured security context
609 * SubjectContextLocked = Indicates the user's subject context is locked
610 * DesiredAccess = Access rights the caller is trying to acquire
611 * PreviouslyGrantedAccess = Specified the access rights already granted
613 * GenericMapping = Generic mapping associated with the object
614 * AccessMode = Access mode used for the check
615 * GrantedAccess (OUT) = On return specifies the access granted
616 * AccessStatus (OUT) = Status indicating why access was denied
617 * RETURNS: If access was granted, returns TRUE
622 SeAccessCheck(IN PSECURITY_DESCRIPTOR SecurityDescriptor
,
623 IN PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext
,
624 IN BOOLEAN SubjectContextLocked
,
625 IN ACCESS_MASK DesiredAccess
,
626 IN ACCESS_MASK PreviouslyGrantedAccess
,
627 OUT PPRIVILEGE_SET
* Privileges
,
628 IN PGENERIC_MAPPING GenericMapping
,
629 IN KPROCESSOR_MODE AccessMode
,
630 OUT PACCESS_MASK GrantedAccess
,
631 OUT PNTSTATUS AccessStatus
)
633 LUID_AND_ATTRIBUTES Privilege
;
634 ACCESS_MASK CurrentAccess
;
646 CurrentAccess
= PreviouslyGrantedAccess
;
648 if (SubjectContextLocked
== FALSE
)
650 SeLockSubjectContext(SubjectSecurityContext
);
653 Token
= SubjectSecurityContext
->ClientToken
?
654 SubjectSecurityContext
->ClientToken
: SubjectSecurityContext
->PrimaryToken
;
657 Status
= RtlGetDaclSecurityDescriptor(SecurityDescriptor
,
661 if (!NT_SUCCESS(Status
))
663 if (SubjectContextLocked
== FALSE
)
665 SeUnlockSubjectContext(SubjectSecurityContext
);
668 *AccessStatus
= Status
;
672 /* RULE 1: Grant desired access if the object is unprotected */
673 if (Present
== TRUE
&& Dacl
== NULL
)
675 if (SubjectContextLocked
== FALSE
)
677 SeUnlockSubjectContext(SubjectSecurityContext
);
680 *GrantedAccess
= DesiredAccess
;
681 *AccessStatus
= STATUS_SUCCESS
;
685 CurrentAccess
= PreviouslyGrantedAccess
;
687 /* RULE 2: Check token for 'take ownership' privilege */
688 Privilege
.Luid
= SeTakeOwnershipPrivilege
;
689 Privilege
.Attributes
= SE_PRIVILEGE_ENABLED
;
691 if (SepPrivilegeCheck(Token
,
694 PRIVILEGE_SET_ALL_NECESSARY
,
697 CurrentAccess
|= WRITE_OWNER
;
698 if (DesiredAccess
== CurrentAccess
)
700 if (SubjectContextLocked
== FALSE
)
702 SeUnlockSubjectContext(SubjectSecurityContext
);
705 *GrantedAccess
= CurrentAccess
;
706 *AccessStatus
= STATUS_SUCCESS
;
711 /* RULE 3: Check whether the token is the owner */
712 Status
= RtlGetOwnerSecurityDescriptor(SecurityDescriptor
,
715 if (!NT_SUCCESS(Status
))
717 DPRINT1("RtlGetOwnerSecurityDescriptor() failed (Status %lx)\n", Status
);
718 if (SubjectContextLocked
== FALSE
)
720 SeUnlockSubjectContext(SubjectSecurityContext
);
723 *AccessStatus
= Status
;
727 if (SepSidInToken(Token
, Sid
))
729 CurrentAccess
|= (READ_CONTROL
| WRITE_DAC
);
730 if (DesiredAccess
== CurrentAccess
)
732 if (SubjectContextLocked
== FALSE
)
734 SeUnlockSubjectContext(SubjectSecurityContext
);
737 *GrantedAccess
= CurrentAccess
;
738 *AccessStatus
= STATUS_SUCCESS
;
743 /* Fail if DACL is absent */
744 if (Present
== FALSE
)
746 if (SubjectContextLocked
== FALSE
)
748 SeUnlockSubjectContext(SubjectSecurityContext
);
752 *AccessStatus
= STATUS_ACCESS_DENIED
;
756 /* RULE 4: Grant rights according to the DACL */
757 CurrentAce
= (PACE
)(Dacl
+ 1);
758 for (i
= 0; i
< Dacl
->AceCount
; i
++)
760 Sid
= (PSID
)(CurrentAce
+ 1);
761 if (CurrentAce
->Header
.AceType
== ACCESS_DENIED_ACE_TYPE
)
763 if (SepSidInToken(Token
, Sid
))
765 if (SubjectContextLocked
== FALSE
)
767 SeUnlockSubjectContext(SubjectSecurityContext
);
771 *AccessStatus
= STATUS_ACCESS_DENIED
;
776 if (CurrentAce
->Header
.AceType
== ACCESS_ALLOWED_ACE_TYPE
)
778 if (SepSidInToken(Token
, Sid
))
780 CurrentAccess
|= CurrentAce
->AccessMask
;
785 if (SubjectContextLocked
== FALSE
)
787 SeUnlockSubjectContext(SubjectSecurityContext
);
790 DPRINT("CurrentAccess %08lx\n DesiredAccess %08lx\n",
791 CurrentAccess
, DesiredAccess
);
793 *GrantedAccess
= CurrentAccess
& DesiredAccess
;
796 (*GrantedAccess
== DesiredAccess
) ? STATUS_SUCCESS
: STATUS_ACCESS_DENIED
;
803 NtAccessCheck(IN PSECURITY_DESCRIPTOR SecurityDescriptor
,
804 IN HANDLE TokenHandle
,
805 IN ACCESS_MASK DesiredAccess
,
806 IN PGENERIC_MAPPING GenericMapping
,
807 OUT PPRIVILEGE_SET PrivilegeSet
,
808 OUT PULONG ReturnLength
,
809 OUT PACCESS_MASK GrantedAccess
,
810 OUT PNTSTATUS AccessStatus
)
812 SECURITY_SUBJECT_CONTEXT SubjectSecurityContext
;
813 KPROCESSOR_MODE PreviousMode
;
819 DPRINT("NtAccessCheck() called\n");
821 PreviousMode
= KeGetPreviousMode();
822 if (PreviousMode
== KernelMode
)
824 *GrantedAccess
= DesiredAccess
;
825 *AccessStatus
= STATUS_SUCCESS
;
826 return STATUS_SUCCESS
;
829 Status
= ObReferenceObjectByHandle(TokenHandle
,
835 if (!NT_SUCCESS(Status
))
837 DPRINT1("Failed to reference token (Status %lx)\n", Status
);
841 /* Check token type */
842 if (Token
->TokenType
!= TokenImpersonation
)
844 DPRINT1("No impersonation token\n");
845 ObDereferenceObject(Token
);
846 return STATUS_ACCESS_VIOLATION
;
849 /* Check impersonation level */
850 if (Token
->ImpersonationLevel
< SecurityAnonymous
)
852 DPRINT1("Invalid impersonation level\n");
853 ObDereferenceObject(Token
);
854 return STATUS_ACCESS_VIOLATION
;
857 RtlZeroMemory(&SubjectSecurityContext
,
858 sizeof(SECURITY_SUBJECT_CONTEXT
));
859 SubjectSecurityContext
.ClientToken
= Token
;
860 SubjectSecurityContext
.ImpersonationLevel
= Token
->ImpersonationLevel
;
862 /* Lock subject context */
863 SeLockSubjectContext(&SubjectSecurityContext
);
865 if (SeAccessCheck(SecurityDescriptor
,
866 &SubjectSecurityContext
,
876 Status
= *AccessStatus
;
880 Status
= STATUS_ACCESS_DENIED
;
883 /* Unlock subject context */
884 SeUnlockSubjectContext(&SubjectSecurityContext
);
886 ObDereferenceObject(Token
);
888 DPRINT("NtAccessCheck() done\n");