60 DPRINT1(
"NtOpenProcessToken() failed (Status %lx)\n",
Status);
77 Status = ZwDuplicateToken(ProcessToken,
96 DPRINT1(
"NtSetInformationThread() failed (Status %lx)\n",
Status);
120 HANDLE ImpersonationToken = 0, ProcessToken;
148 State->OldImpersonationToken = 0;
225 Status = ZwDuplicateToken(ProcessToken,
230 &ImpersonationToken);
250 State->Token = ImpersonationToken;
266 State->NewPrivileges->PrivilegeCount = NumPriv;
267 for (
i = 0;
i < NumPriv; ++
i)
270 State->NewPrivileges->Privileges[
i].Luid.HighPart = 0;
275 OldSize =
sizeof(
State->OldPrivBuffer);
286 if (
State->OldPrivileges)
288 DPRINT(
"Allocated old privileges: %p\n",
State->OldPrivileges);
316 *ReturnedState =
State;
321 DPRINT(
"RtlAcquirePrivilege succeed!\n");
353 DPRINT(
"RtlAcquirePrivilege() failed with status: %lx\n",
Status);
368 DPRINT(
"RtlReleasePrivilege(%p)\n", ReturnedState);
384 if (
State->OldImpersonationToken)
401 DPRINT(
"Releasing old privileges: %p\n",
State->OldPrivileges);
428 DPRINT(
"RtlAdjustPrivilege() called\n");
446 DPRINT1(
"Retrieving token handle failed (Status %lx)\n",
Status);
466 DPRINT1(
"Failed to assign all privileges\n");
472 DPRINT1(
"NtAdjustPrivilegesToken() failed (Status %lx)\n",
Status);
485 DPRINT(
"RtlAdjustPrivilege() done\n");
490#if (NTDDI_VERSION >= NTDDI_VISTA) || (DLL_EXPORT_VERSION >= _WIN32_WINNT_VISTA)
522 UINT64 PrivilegesToKeepBitmap;
530 DPRINT(
"RtlRemovePrivileges(%p, %p, %u)\n",
TokenHandle, PrivilegesToKeep, PrivilegeCount);
533 PrivilegesToKeepBitmap = 0;
536 for (
i = 0;
i < PrivilegeCount;
i++)
542 PrivilegesToKeepBitmap |= (1ULL << PrivilegesToKeep[
i]);
563 if (PrivilegesToKeepBitmap & (1ULL <<
Privilege.QuadPart))
565 PrivilegesToKeepBitmap &= ~(1ULL <<
Privilege.QuadPart);
573 if (PrivilegesToKeepBitmap)
#define STATUS_PRIVILEGE_NOT_HELD
unsigned long long UINT64
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
#define NT_SUCCESS(StatCode)
@ ThreadImpersonationToken
static const WCHAR Cleanup[]
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
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
enum _SECURITY_IMPERSONATION_LEVEL SECURITY_IMPERSONATION_LEVEL
struct _SECURITY_QUALITY_OF_SERVICE SECURITY_QUALITY_OF_SERVICE
#define SE_MIN_WELL_KNOWN_PRIVILEGE
#define SE_MAX_WELL_KNOWN_PRIVILEGE
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
_In_ ACCESS_MASK _In_ ULONG _Out_ PHANDLE TokenHandle
NTSYSAPI NTSTATUS NTAPI ZwOpenThreadToken(_In_ HANDLE ThreadHandle, _In_ ACCESS_MASK DesiredAccess, _In_ BOOLEAN OpenAsSelf, _Out_ PHANDLE TokenHandle)
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
struct _RTL_ACQUIRE_STATE * PRTL_ACQUIRE_STATE
#define RTL_ACQUIRE_PRIVILEGE_IMPERSONATE
#define RTL_ACQUIRE_PRIVILEGE_PROCESS
_Must_inspect_result_ NTSYSAPI NTSTATUS NTAPI ZwAdjustPrivilegesToken(_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)
#define _In_reads_opt_(s)
#define NtCurrentProcess()
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
#define STATUS_NOT_ALL_ASSIGNED
NTSTATUS NTAPI RtlAdjustPrivilege(IN ULONG Privilege, IN BOOLEAN Enable, IN BOOLEAN CurrentThread, OUT PBOOLEAN Enabled)
VOID NTAPI RtlReleasePrivilege(IN PVOID ReturnedState)
NTSTATUS NTAPI RtlAcquirePrivilege(IN PULONG Privilege, IN ULONG NumPriv, IN ULONG Flags, OUT PVOID *ReturnedState)
NTSTATUS NTAPI RtlpOpenThreadToken(IN ACCESS_MASK DesiredAccess, OUT PHANDLE TokenHandle)
NTSTATUS NTAPI RtlRemovePrivileges(_In_ HANDLE TokenHandle, _In_reads_opt_(PrivilegeCount) _When_(PrivilegeCount !=0, _Notnull_) PULONG PrivilegesToKeep, _In_ ULONG PrivilegeCount)
Removes all privileges in the specified access token.
NTSTATUS NTAPI RtlImpersonateSelf(IN SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
#define STATUS_BUFFER_TOO_SMALL
PVOID SecurityQualityOfService
SECURITY_CONTEXT_TRACKING_MODE ContextTrackingMode
SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
#define STATUS_INVALID_PARAMETER
BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable)
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
_Must_inspect_result_ _In_ ULONG Flags
_Out_ PBOOLEAN _Out_ PBOOLEAN _Out_ PSECURITY_IMPERSONATION_LEVEL ImpersonationLevel
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
#define TOKEN_ADJUST_PRIVILEGES
struct _TOKEN_PRIVILEGES TOKEN_PRIVILEGES
struct _TOKEN_PRIVILEGES * PTOKEN_PRIVILEGES
#define TOKEN_IMPERSONATE
#define SE_PRIVILEGE_ENABLED
#define SE_PRIVILEGE_REMOVED
NTSYSAPI NTSTATUS NTAPI ZwOpenProcessToken(_In_ HANDLE ProcessHandle, _In_ ACCESS_MASK DesiredAccess, _Out_ PHANDLE TokenHandle)
#define NtCurrentThread()