chsvlib
chsv helper source code

◆ GetTokenInformation() [2/2]

std::unique_ptr<void, Chusov::Memory::raw_delete_t<void> > Chusov::Win32::Security::GetTokenInformation ( HANDLE  hToken,
TOKEN_INFORMATION_CLASS  TokenInformationClass 
)

Allocates and fills a buffer with requested token information.

Parameters
[in]hTokenis a Windows handle of the token, which information is retrieved.
[in]TokenInformationClassis a value of the Windows TOKEN_INFORMATION_CLASS enumeration, specifying what information is to be retrieved.
Returns
Returns a smart (std::unique_ptr) generic pointer to a buffer containing the requested information.

The function is a simple wrap over the Windows GetTokenInformation function. It encapsulates a retrieving of a necessary buffer size, an allocation of the buffer, and reading the requested information.

If TokenInformationClass specifies TokenSource, the hToken must be opened with TOKEN_QUERY_SOURCE access right. For all other TokenInformationClass values, the handle must have TOKEN_QUERY access. Token handles, retrieved by calls to the GetCurrentImpersonationToken function, have both of these access rights.

Exceptions
std::bad_allocThe function was unable to allocate the required amount of memory.
Chusov::Exceptions::ChsvCodeExceptionSystem-level error occurred.
See also
GetTokenInformation_spec_ret_type "template <TOKEN_INFORMATION_CLASS TokeInformationClass> AutoTokeninformation<TokeInformationClass> GetTokenInformation".