Add DuplicateTokenEx()

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
2022-10-14 14:24:27 +02:00
parent 3cf2e96b07
commit bd5c1fdd9d
2 changed files with 36 additions and 0 deletions

View File

@@ -2414,6 +2414,21 @@ static BOOL OpenProcessToken(_In_ HANDLE ProcessHandle, _In_ DWORD DesiredAccess
return FALSE;
}
///
/// Creates a new access token that duplicates an existing token. This function can create either a primary token or an impersonation token.
///
/// \sa [DuplicateTokenEx function](https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-duplicatetokenex)
///
static BOOL DuplicateTokenEx(_In_ HANDLE hExistingToken, _In_ DWORD dwDesiredAccess, _In_opt_ LPSECURITY_ATTRIBUTES lpTokenAttributes, _In_ SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, _In_ TOKEN_TYPE TokenType, _Inout_ winstd::win_handle<NULL> &NewToken)
{
HANDLE h;
if (DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, &h)) {
NewToken.attach(h);
return TRUE;
}
return FALSE;
}
#pragma warning(pop)
/// @}