Switching groups with newgrp - how to get the new group with |GetTokenInformation()| ?

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Feb 22 19:11:25 GMT 2024


On Feb 22 18:38, Roland Mainz via Cygwin wrote:
> Hi!
> 
> ----
> 
> If I switch the current user's group with /usr/bin/newgrp, how can a
> (native) Win32 process use
> |GetTokenInformation(GetCurrentThreadToken(), ...)| to find out which
> group is the new "current group" (e.g. which |TokenInformationClass|
> should I use) ?

  PSID sidbuf = (PSID) alloca (SECURITY_MAX_SID_SIZE);
  NTSTATUS status;
  ULONG size;

  status = NtQueryInformationToken (hProcToken, TokenPrimaryGroup,
                                    sidbuf, SECURITY_MAX_SID_SIZE,
				    &size);


Corinna


More information about the Cygwin mailing list