implemented IsTokenRestricted(), inspired by a patch to winehq by James Hawkins

svn path=/trunk/; revision=15958
This commit is contained in:
Thomas Bluemel 2005-06-17 09:46:29 +00:00
parent a50fde81ae
commit f6e5d12f4c
2 changed files with 68 additions and 1 deletions

View file

@ -319,7 +319,7 @@ InitiateSystemShutdownA@20
InitiateSystemShutdownW@20
;InstallApplication
IsTextUnicode@12=NTDLL.RtlIsTextUnicode
;IsTokenRestricted
IsTokenRestricted@4
;IsTokenUntrusted
IsValidAcl@4
IsValidSecurityDescriptor@4

View file

@ -401,4 +401,71 @@ ByeBye:
return Result;
}
BOOL STDCALL
IsTokenRestricted(HANDLE TokenHandle)
{
ULONG RetLength;
PTOKEN_GROUPS lpGroups;
NTSTATUS Status;
BOOL Ret = FALSE;
/* determine the required buffer size and allocate enough memory to read the
list of restricted SIDs */
Status = NtQueryInformationToken(TokenHandle,
TokenRestrictedSids,
NULL,
0,
&RetLength);
if (Status != STATUS_BUFFER_TOO_SMALL)
{
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
AllocAndReadRestrictedSids:
lpGroups = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(),
0,
RetLength);
if (lpGroups == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
/* actually read the list of the restricted SIDs */
Status = NtQueryInformationToken(TokenHandle,
TokenRestrictedSids,
lpGroups,
RetLength,
&RetLength);
if (NT_SUCCESS(Status))
{
Ret = (lpGroups->GroupCount != 0);
}
else if (Status == STATUS_BUFFER_TOO_SMALL)
{
/* looks like the token was modified in the meanwhile, let's just try again */
HeapFree(GetProcessHeap(),
0,
lpGroups);
goto AllocAndReadRestrictedSids;
}
else
{
SetLastError(RtlNtStatusToDosError(Status));
}
/* free allocated memory */
HeapFree(GetProcessHeap(),
0,
lpGroups);
return Ret;
}
/* EOF */