chsvlib
chsv helper source code

◆ GetTokenGroups()

std::vector<AutoSID> Chusov::Win32::Security::GetTokenGroups ( HANDLE  hToken)

Returns a vector of managed pointers to security identifiers of groups which a principal described by the specified access token belongs to.

Parameters
[in]hTokenis a handle of the token describing a principal, which groups are returned by the function.
Returns
Returns an [std::vector] of managed AutoSID pointers to SID values of the groups, the principal, described by the token, belongs to.

SID values themselves use the same buffer to be contained. The data is written right after the last element of the returned array.

hToken must be opened with TOKEN_QUERY access right. Tokens returned by the GetCurrentImpersonationToken have one.

To avoid allocations the caller can use the Windows [GetTokenInformation] function together with the GetTokenGroupCount function to write the security identifiers onto pre allocated memory.

Exceptions
std::bad_allocThe function was unable to allocate the required amount of memory.
Chusov::Exceptions::ChsvCodeExceptionSystem-level error occurred.