mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 16:33:02 -05:00
winfsp-tests: posix_map_sid_test
This commit is contained in:
parent
229c3f81fa
commit
7fbaa8d37c
@ -7,10 +7,10 @@
|
||||
*
|
||||
* [PERM]
|
||||
* https://technet.microsoft.com/en-us/library/bb463216.aspx
|
||||
* [IDMAP]
|
||||
* https://cygwin.com/cygwin-ug-net/ntsec.html
|
||||
* [WKSID]
|
||||
* https://support.microsoft.com/en-us/kb/243330
|
||||
* [IDMAP]
|
||||
* https://cygwin.com/cygwin-ug-net/ntsec.html
|
||||
* [NAME]
|
||||
* https://www.cygwin.com/cygwin-ug-net/using-specialnames.html
|
||||
*
|
||||
@ -255,7 +255,7 @@ FSP_API NTSTATUS FspPosixMapSidToUid(PSID Sid, PUINT32 PUid)
|
||||
* LogonSid is converted to the fixed uid 0xffe == 4094 and named
|
||||
* "OtherSession".
|
||||
*/
|
||||
else if (3 <= Count && 5 == SubAuthority0)
|
||||
else if (2 <= Count && 5 == SubAuthority0)
|
||||
{
|
||||
/*
|
||||
* Actually we do not support Logon SID's for translation.
|
||||
@ -273,7 +273,7 @@ FSP_API NTSTATUS FspPosixMapSidToUid(PSID Sid, PUINT32 PUid)
|
||||
* Accounts from a trusted domain of the machine's primary domain:
|
||||
* S-1-5-21-X-Y-Z-RID <=> uid/gid: trustPosixOffset(domain) + RID
|
||||
*/
|
||||
else if (3 <= Count && 21 == SubAuthority0)
|
||||
else if (5 <= Count && 21 == SubAuthority0)
|
||||
{
|
||||
InitOnceExecuteOnce(&FspPosixInitOnceV, FspPosixInitOnceF, 0, 0);
|
||||
|
||||
@ -300,7 +300,7 @@ FSP_API NTSTATUS FspPosixMapSidToUid(PSID Sid, PUINT32 PUid)
|
||||
* Other well-known SIDs in the NT_AUTHORITY domain (S-1-5-X-RID):
|
||||
* S-1-5-X-RID <=> uid/gid: 0x1000 * X + RID
|
||||
*/
|
||||
else if (3 == Count)
|
||||
else if (2 == Count)
|
||||
{
|
||||
*PUid = 0x1000 * SubAuthority0 + Rid;
|
||||
}
|
||||
|
@ -14,27 +14,63 @@ void posix_map_sid_test(void)
|
||||
{ L"S-1-1-0", 0x10100 },
|
||||
{ L"S-1-2-0", 0x10200 },
|
||||
{ L"S-1-2-1", 0x10201 },
|
||||
{ L"S-1-3-0", 0x10300 },
|
||||
{ L"S-1-3-1", 0x10301 },
|
||||
{ L"S-1-3-2", 0x10302 },
|
||||
{ L"S-1-3-3", 0x10303 },
|
||||
{ L"S-1-3-4", 0x10304 },
|
||||
{ L"S-1-5-80-0", 0x50000 },
|
||||
{ 0, 0 },
|
||||
};
|
||||
NTSTATUS Result;
|
||||
BOOL Success;
|
||||
PSID Sid;
|
||||
PWSTR SidStr;
|
||||
HANDLE Token;
|
||||
PTOKEN_USER UserInfo;
|
||||
DWORD UserInfoSize;
|
||||
PSID Sid0, Sid1;
|
||||
UINT32 Uid;
|
||||
|
||||
Success = OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &Token);
|
||||
ASSERT(Success);
|
||||
|
||||
Success = GetTokenInformation(Token, TokenUser, 0, 0, &UserInfoSize);
|
||||
ASSERT(!Success);
|
||||
ASSERT(ERROR_INSUFFICIENT_BUFFER == GetLastError());
|
||||
|
||||
UserInfo = malloc(UserInfoSize);
|
||||
ASSERT(0 != UserInfo);
|
||||
|
||||
Success = GetTokenInformation(Token, TokenUser, UserInfo, UserInfoSize, &UserInfoSize);
|
||||
ASSERT(Success);
|
||||
|
||||
Success = ConvertSidToStringSidW(UserInfo->User.Sid, &map[sizeof map / sizeof map[0] - 1].SidStr);
|
||||
ASSERT(Success);
|
||||
|
||||
free(UserInfo);
|
||||
|
||||
CloseHandle(Token);
|
||||
|
||||
for (size_t i = 0; sizeof map / sizeof map[0] > i; i++)
|
||||
{
|
||||
Result = FspPosixMapUidToSid(map[i].Uid, &Sid);
|
||||
ASSERT(NT_SUCCESS(Result));
|
||||
|
||||
Success = ConvertSidToStringSidW(Sid, &SidStr);
|
||||
Success = ConvertStringSidToSidW(map[i].SidStr, &Sid0);
|
||||
ASSERT(Success);
|
||||
ASSERT(0 == wcscmp(map[i].SidStr, SidStr));
|
||||
LocalFree(SidStr);
|
||||
|
||||
Result = FspPosixMapSidToUid(Sid, &map[i].Uid);
|
||||
Result = FspPosixMapSidToUid(Sid0, &Uid);
|
||||
ASSERT(NT_SUCCESS(Result));
|
||||
|
||||
FspDeleteSid(Sid, FspPosixMapUidToSid);
|
||||
if (0 != map[i].Uid)
|
||||
ASSERT(Uid == map[i].Uid);
|
||||
|
||||
Result = FspPosixMapUidToSid(Uid, &Sid1);
|
||||
ASSERT(NT_SUCCESS(Result));
|
||||
|
||||
ASSERT(EqualSid(Sid0, Sid1));
|
||||
|
||||
FspDeleteSid(Sid1, FspPosixMapUidToSid);
|
||||
LocalFree(Sid0);
|
||||
}
|
||||
|
||||
LocalFree(map[sizeof map / sizeof map[0] - 1].SidStr);
|
||||
}
|
||||
|
||||
void posix_tests(void)
|
||||
|
Loading…
x
Reference in New Issue
Block a user