Repository navigation
TokenHasRestrictions: documented DWORD vs observed one-byte output #2308
Replies: 2 comments 4 replies
|
Adding a standalone C++ source draft for review (attached), to make the earlier TokenHasRestrictions observation easier to inspect independently of Python. Status: NOT BUILT / NOT NATIVE-TESTED. The previously reported measurements did not come from this source. Known draft limitation: same_stats() compares ImpersonationLevel even for a primary token. That comparison needs correction before this can be considered a ready-to-run reproduction. The attached source is preserved unchanged. I am seeking clarification of the supported class-21 output layout and valid initialized bytes when a successful call reports ReturnLength=1 with a four-byte buffer. No one-byte compatibility rule has been adopted. |
|
Based on some internal discussion, it sounds like the documentation is wrong and should say that it returns BOOLEAN but that the BOOLEAN pointer must be DWORD-aligned. If you would like to file an issue in this repo or on the docs, that will help us track getting it fixed. |
Uh oh!
There was an error while loading. Please reload this page.
I am asking for Win32 output-type/documentation guidance, not reporting a confirmed win32metadata bug. Please redirect this question if another team or repository owns the contract.
The Microsoft TOKEN_INFORMATION_CLASS documentation describes TokenHasRestrictions (class 21) as returning a DWORD. In one completed read-only Windows x64 diagnostic, both GetTokenInformation calls succeeded with a four-byte output buffer but reported ReturnLength = 1:
Each output and ReturnLength occupied the aligned middle DWORD of a separate 20-byte allocation, with eight guard bytes on either side. Guards stayed intact. The same current-process primary token was opened with TOKEN_QUERY only. Four complete TokenStatistics observations matched across the experiment. No privilege or security-setting changes were made.
Environment: Windows x64, 64-bit CPython 3.12.14, elevated interactive local context; PowerShell 7.6.5 launched the diagnostic. The binding was ctypes.WinDLL("advapi32.dll", use_last_error=True, winmode=0x800), with [HANDLE(void*), int32, void*, uint32, uint32*] -> int32 BOOL. DWORD/BOOL sizes were checked as 4, pointer size as 8. The exact Windows edition/build was NOT recorded and is not inferred. This is a description of the completed experiment, not an independently compiled C/C++ reproduction.
Only offset 0 visibly changed. Offsets 1-3 retained different caller-initialized patterns and have not been treated as valid returned DWORD bytes. We do not infer a universal one-byte ABI or the exact physical write count. The seeded last-error value was unchanged after success and was not interpreted as a failure.
Questions:
No one-byte compatibility rule has been adopted. Only sanitized observations are included; no account names, private SIDs, local paths, token identifiers, credentials or raw security records.
Official references:
https://learn.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-token_information_class
https://learn.microsoft.com/en-us/windows/win32/api/securitybaseapi/nf-securitybaseapi-gettokeninformation
All reactions