Blame src/token/ntapi_tt_token_privilege.c

5f1999
/********************************************************/
5f1999
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
5f1999
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
5f1999
/********************************************************/
5f1999
5f1999
#include <psxtypes/psxtypes.h>
5f1999
#include <ntapi/nt_object.h>
5f1999
#include <ntapi/nt_token.h>
5f1999
#include <ntapi/ntapi.h>
5f1999
#include "ntapi_impl.h"
5f1999
5f1999
5f1999
static int32_t __stdcall __set_token_privilege(
5f1999
	__in	void *		htoken,
5f1999
	__in	uint32_t	privilege,
5f1999
	__in	int		attribute)
5f1999
{
5f1999
	uintptr_t		buffer[64];
5f1999
	nt_token_privileges *	tokprivs;
5f1999
5f1999
	/* reasonable scope */
5f1999
	if (privilege > 255)
5f1999
		return NT_STATUS_INVALID_PARAMETER;
5f1999
5f1999
	/* buffer */
5f1999
	__ntapi->tt_aligned_block_memset(
5f1999
		buffer,0,sizeof(buffer));
5f1999
5f1999
	tokprivs = (nt_token_privileges *)buffer;
5f1999
5f1999
	/* token privileges */
5f1999
	tokprivs->privilege_count = 1;
5f1999
5f1999
	tokprivs->privileges[0].attributes = attribute;
5f1999
	tokprivs->privileges[0].luid.low   = privilege;
5f1999
	tokprivs->privileges[0].luid.high  = 0;
5f1999
5f1999
	/* set */
5f1999
	return __ntapi->zw_adjust_privileges_token(
5f1999
		htoken,0,
5f1999
		tokprivs,sizeof(buffer),
5f1999
		0,0);
5f1999
}
5f1999
5f1999
5f1999
int32_t __stdcall __ntapi_tt_enable_token_privilege(
5f1999
	__in	void *		htoken,
5f1999
	__in	uint32_t	privilege)
5f1999
{
5f1999
	return __set_token_privilege(
5f1999
		htoken,
5f1999
		privilege,
5f1999
		NT_SE_ENABLE_PRIVILEGE);
5f1999
}
5f1999
5f1999
int32_t __stdcall __ntapi_tt_disable_token_privilege(
5f1999
	__in	void *		htoken,
5f1999
	__in	uint32_t	privilege)
5f1999
{
5f1999
	return __set_token_privilege(
5f1999
		htoken,
5f1999
		privilege,
5f1999
		NT_SE_DISABLE_PRIVILEGE);
5f1999
}