66 ULONG i,
j, PrivilegeCount, ChangeCount, NewAttributes;
76 for (
i = 0;
i <
Token->PrivilegeCount;
i++)
79 if (DisableAllPrivileges)
82 NewAttributes =
Token->Privileges[
i].Attributes & ~SE_PRIVILEGE_ENABLED;
87 for (
j = 0;
j < NewStateCount;
j++)
92 DPRINT(
"Found privilege\n");
95 NewAttributes = NewState[
j].Attributes;
97 NewAttributes |=
Token->Privileges[
i].Attributes & ~SE_PRIVILEGE_ENABLED;
105 if (
j == NewStateCount)
116 if (
Token->Privileges[
i].Attributes != NewAttributes)
132 Token->Privileges[
i].Attributes &= ~SE_PRIVILEGE_ENABLED;
146 Token->Privileges[
i].Attributes = NewAttributes;
161 *ChangedPrivileges = ChangeCount;
164 if (!DisableAllPrivileges && (PrivilegeCount < NewStateCount))
256 ULONG GroupsInToken, GroupsInList;
257 ULONG ChangeCount, GroupsCount, NewAttributes;
265 *ChangesMade =
FALSE;
270 for (GroupsInToken = 0; GroupsInToken <
Token->UserAndGroupCount; GroupsInToken++)
273 if (ResetToDefaultStates)
297 NewAttributes =
Token->UserAndGroups[GroupsInToken].Attributes & ~SE_GROUP_ENABLED;
303 for (GroupsInList = 0; GroupsInList < NewStateCount; GroupsInList++)
307 &NewState[GroupsInList].Sid))
319 DPRINT1(
"SepAdjustGroups(): The SID group is mandatory!\n");
334 DPRINT1(
"SepAdjustGroups(): The SID group is for use deny only!\n");
339 NewAttributes = NewState[GroupsInList].Attributes;
341 NewAttributes =
Token->UserAndGroups[GroupsInToken].Attributes & ~SE_GROUP_ENABLED;
346 if (GroupsInList == NewStateCount)
357 if (
Token->UserAndGroups[GroupsInToken].Attributes != NewAttributes)
364 if (PreviousGroupsState !=
NULL)
366 PreviousGroupsState->Groups[ChangeCount] =
Token->UserAndGroups[GroupsInToken];
373 Token->UserAndGroups[GroupsInToken].Attributes = NewAttributes;
384 if (PreviousGroupsState !=
NULL)
386 PreviousGroupsState->GroupCount = ChangeCount;
390 *ChangedGroups = ChangeCount;
393 if (!ResetToDefaultStates && (GroupsCount < NewStateCount))
401 DPRINT1(
"SepAdjustGroups(): The token hasn't all the groups assigned!\n");
464 ULONG CapturedCount = 0;
465 ULONG CapturedLength = 0;
466 ULONG NewStateSize = 0;
473 DPRINT(
"NtAdjustPrivilegesToken() called\n");
476 if (DisableAllPrivileges ==
FALSE && NewState ==
NULL)
485 if (DisableAllPrivileges ==
FALSE)
490 CapturedCount = NewState->PrivilegeCount;
513 if (DisableAllPrivileges ==
FALSE)
514 CapturedCount = NewState->PrivilegeCount;
518 if (DisableAllPrivileges ==
FALSE)
553 DPRINT1(
"Failed to reference token (Status 0x%lx)\n",
Status);
556 if (CapturedPrivileges !=
NULL)
571 DisableAllPrivileges,
611 DisableAllPrivileges,
638 if (CapturedPrivileges !=
NULL)
645 DPRINT(
"NtAdjustPrivilegesToken() done\n");
708 ULONG CapturedCount = 0;
709 ULONG CapturedLength = 0;
710 ULONG NewStateSize = 0;
723 if (!ResetToDefault && !NewState)
725 DPRINT1(
"NtAdjustGroupsToken(): The caller hasn't provided any list of groups to adjust!\n");
741 CapturedCount = NewState->GroupCount;
768 CapturedCount = NewState->GroupCount;
795 DPRINT1(
"NtAdjustGroupsToken(): Failed to capture the NewState list of groups (Status 0x%lx)\n",
Status);
810 DPRINT1(
"NtAdjustGroupsToken(): Failed to reference the token (Status 0x%lx)\n",
Status);
812 if (CapturedGroups !=
NULL)
900 if (CapturedGroups !=
NULL)
#define NT_SUCCESS(StatCode)
static const WCHAR Cleanup[]
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
#define ExGetPreviousMode
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
#define EXCEPTION_EXECUTE_HANDLER
#define KeGetPreviousMode()
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
NTSYSAPI BOOLEAN NTAPI RtlEqualSid(_In_ PSID Sid1, _In_ PSID Sid2)
#define SE_GROUP_USE_FOR_DENY_ONLY
#define SE_GROUP_MANDATORY
#define SE_GROUP_ENABLED_BY_DEFAULT
#define _Must_inspect_result_
#define _Out_writes_bytes_to_opt_(s, c)
VOID NTAPI ExAllocateLocallyUniqueId(OUT LUID *LocallyUniqueId)
VOID SepRemovePrivilegeToken(_Inout_ PTOKEN Token, _In_ ULONG Index)
Removes a privilege from the token.
VOID NTAPI SeReleaseSidAndAttributesArray(_In_ _Post_invalid_ PSID_AND_ATTRIBUTES CapturedSidAndAttributes, _In_ KPROCESSOR_MODE AccessMode, _In_ BOOLEAN CaptureIfKernel)
Releases a captured SID with attributes.
VOID NTAPI SeReleaseLuidAndAttributesArray(_In_ PLUID_AND_ATTRIBUTES Privilege, _In_ KPROCESSOR_MODE PreviousMode, _In_ BOOLEAN CaptureIfKernel)
Releases a LUID with attributes structure.
VOID SepUpdateSinglePrivilegeFlagToken(_Inout_ PTOKEN Token, _In_ ULONG Index)
Updates the token's flags based upon the privilege that the token has been granted....
#define SepAcquireTokenLockExclusive(Token)
NTSTATUS NTAPI SeCaptureSidAndAttributesArray(_In_ PSID_AND_ATTRIBUTES SrcSidAndAttributes, _In_ ULONG AttributeCount, _In_ KPROCESSOR_MODE PreviousMode, _In_opt_ PVOID AllocatedMem, _In_ ULONG AllocatedLength, _In_ POOL_TYPE PoolType, _In_ BOOLEAN CaptureIfKernel, _Out_ PSID_AND_ATTRIBUTES *CapturedSidAndAttributes, _Out_ PULONG ResultLength)
Captures a SID with attributes.
#define SepReleaseTokenLock(Token)
NTSTATUS NTAPI SeCaptureLuidAndAttributesArray(_In_ PLUID_AND_ATTRIBUTES Src, _In_ ULONG PrivilegeCount, _In_ KPROCESSOR_MODE PreviousMode, _In_ PLUID_AND_ATTRIBUTES AllocatedMem, _In_ ULONG AllocatedLength, _In_ POOL_TYPE PoolType, _In_ BOOLEAN CaptureIfKernel, _Out_ PLUID_AND_ATTRIBUTES *Dest, _Inout_ PULONG Length)
POBJECT_TYPE SeTokenObjectType
#define STATUS_NOT_ALL_ASSIGNED
#define STATUS_CANT_DISABLE_MANDATORY
#define STATUS_CANT_ENABLE_DENY_ONLY
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
#define _SEH2_GetExceptionCode()
#define _SEH2_EXCEPT(...)
#define _SEH2_YIELD(__stmt)
#define STATUS_BUFFER_TOO_SMALL
BOOL ApplyChanges(HWND hwndDlg)
static NTSTATUS SepAdjustGroups(_In_ PTOKEN Token, _In_opt_ PSID_AND_ATTRIBUTES NewState, _In_ ULONG NewStateCount, _In_ BOOLEAN ApplyChanges, _In_ BOOLEAN ResetToDefaultStates, _Out_ PBOOLEAN ChangesMade, _Out_opt_ PTOKEN_GROUPS PreviousGroupsState, _Out_ PULONG ChangedGroups)
Private routine that iterates over the groups of an access token to be adjusted as per on request by ...
static NTSTATUS SepAdjustPrivileges(_Inout_ PTOKEN Token, _In_ BOOLEAN DisableAllPrivileges, _In_opt_ PLUID_AND_ATTRIBUTES NewState, _In_ ULONG NewStateCount, _Out_opt_ PTOKEN_PRIVILEGES PreviousState, _In_ BOOLEAN ApplyChanges, _Out_ PULONG ChangedPrivileges, _Out_ PBOOLEAN ChangesMade)
Removes a certain amount of privileges of a token based upon the request by the caller.
_Must_inspect_result_ __kernel_entry NTSTATUS NTAPI NtAdjustPrivilegesToken(_In_ HANDLE TokenHandle, _In_ BOOLEAN DisableAllPrivileges, _In_opt_ PTOKEN_PRIVILEGES NewState, _In_ ULONG BufferLength, _Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_PRIVILEGES PreviousState, _When_(PreviousState!=NULL, _Out_) PULONG ReturnLength)
Removes a certain amount of privileges of a token based upon the request by the caller.
NTSTATUS NTAPI NtAdjustGroupsToken(_In_ HANDLE TokenHandle, _In_ BOOLEAN ResetToDefault, _In_ PTOKEN_GROUPS NewState, _In_ ULONG BufferLength, _Out_writes_bytes_to_opt_(BufferLength, *ReturnLength) PTOKEN_GROUPS PreviousState, _When_(PreviousState !=NULL, _Out_) PULONG ReturnLength)
Changes the list of groups by enabling or disabling them in an access token. Unlike NtAdjustPrivilege...
#define FIELD_OFFSET(t, f)
#define STATUS_INVALID_PARAMETER
_In_ WDF_POWER_DEVICE_STATE PreviousState
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
_In_ ULONG _Out_opt_ PULONG RequiredLength
#define ObDereferenceObject
#define RtlEqualLuid(Luid1, Luid2)
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
_In_ KPROCESSOR_MODE PreviousMode
#define TOKEN_ADJUST_PRIVILEGES
#define TOKEN_ADJUST_GROUPS
#define SE_PRIVILEGE_ENABLED
#define SE_PRIVILEGE_REMOVED