winfsp-tests: posix_map_sid_test

This commit is contained in:
Bill Zissimopoulos 2016-06-05 00:34:44 -07:00
parent 9ccb394b04
commit 229c3f81fa
7 changed files with 61 additions and 3 deletions

View File

@ -191,6 +191,7 @@
<ClCompile Include="..\..\..\tst\winfsp-tests\memfs-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\mount-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\path-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\posix-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\rdwr-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\security-test.c" />
<ClCompile Include="..\..\..\tst\winfsp-tests\timeout-test.c" />

View File

@ -58,6 +58,9 @@
<ClCompile Include="..\..\..\tst\winfsp-tests\fuse-opt-test.c">
<Filter>Source</Filter>
</ClCompile>
<ClCompile Include="..\..\..\tst\winfsp-tests\posix-test.c">
<Filter>Source</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\ext\tlib\testsuite.h">

View File

@ -41,6 +41,7 @@ BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
*/
Dynamic = 0 == Reserved;
FspNtStatusInitialize(Dynamic);
FspPosixInitialize(Dynamic);
FspEventLogInitialize(Dynamic);
FspFileSystemInitialize(Dynamic);
FspServiceInitialize(Dynamic);
@ -62,6 +63,7 @@ BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
FspServiceFinalize(Dynamic);
FspFileSystemFinalize(Dynamic);
FspEventLogFinalize(Dynamic);
FspPosixFinalize(Dynamic);
FspNtStatusFinalize(Dynamic);
break;

View File

@ -38,6 +38,8 @@
VOID FspNtStatusInitialize(BOOLEAN Dynamic);
VOID FspNtStatusFinalize(BOOLEAN Dynamic);
VOID FspPosixInitialize(BOOLEAN Dynamic);
VOID FspPosixFinalize(BOOLEAN Dynamic);
VOID FspEventLogInitialize(BOOLEAN Dynamic);
VOID FspEventLogFinalize(BOOLEAN Dynamic);
VOID FspFileSystemInitialize(BOOLEAN Dynamic);

View File

@ -160,6 +160,8 @@ FSP_API NTSTATUS FspPosixMapUidToSid(UINT32 Uid, PSID *PSid)
*/
else if (0x30000 <= Uid && Uid < 0x40000)
{
InitOnceExecuteOnce(&FspPosixInitOnceV, FspPosixInitOnceF, 0, 0);
if (5 == FspAccountDomainSid->IdentifierAuthority.Value[5] &&
4 == FspAccountDomainSid->SubAuthorityCount)
{
@ -173,6 +175,8 @@ FSP_API NTSTATUS FspPosixMapUidToSid(UINT32 Uid, PSID *PSid)
}
else if (0x100000 <= Uid && Uid < 0x200000)
{
InitOnceExecuteOnce(&FspPosixInitOnceV, FspPosixInitOnceF, 0, 0);
if (5 == FspPrimaryDomainSid->IdentifierAuthority.Value[5] &&
4 == FspPrimaryDomainSid->SubAuthorityCount)
{
@ -194,21 +198,21 @@ FSP_API NTSTATUS FspPosixMapUidToSid(UINT32 Uid, PSID *PSid)
* S-1-16-RID <=> uid/gid: 0x60000 + RID
*/
else if (0x60000 <= Uid && Uid < 0x70000)
*PSid = FspPosixCreateSid(5, 2, 16, Uid - 0x60000);
*PSid = FspPosixCreateSid(16, 1, Uid - 0x60000);
/* [IDMAP]
* Other well-known SIDs:
* S-1-X-Y <=> uid/gid: 0x10000 + 0x100 * X + Y
*/
else if (0x10000 <= Uid && Uid < 0x11000)
*PSid = FspPosixCreateSid(5, 2, (Uid - 0x10000) >> 8, (Uid - 0x10000) & 0xff);
*PSid = FspPosixCreateSid((Uid - 0x10000) >> 8, 1, (Uid - 0x10000) & 0xff);
/* [IDMAP]
* 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 (0x1000 <= Uid && Uid < 0x100000)
*PSid = FspPosixCreateSid(5, 5, Uid >> 12, Uid & 0xfff);
*PSid = FspPosixCreateSid(5, 2, Uid >> 12, Uid & 0xfff);
if (0 == *PSid)
return STATUS_NONE_MAPPED;
@ -356,10 +360,12 @@ FSP_API NTSTATUS FspPosixMapPermissionsToSecurityDescriptor(
UINT32 Uid, UINT32 Gid, UINT32 Mode,
PSECURITY_DESCRIPTOR *PSecurityDescriptor)
{
return STATUS_NOT_IMPLEMENTED;
}
FSP_API NTSTATUS FspPosixMapSecurityDescriptorToPermissions(
PSECURITY_DESCRIPTOR SecurityDescriptor,
PUINT32 PUid, PUINT32 PGid, PUINT32 PMode)
{
return STATUS_NOT_IMPLEMENTED;
}

View File

@ -0,0 +1,43 @@
#include <winfsp/winfsp.h>
#include <tlib/testsuite.h>
#include <sddl.h>
void posix_map_sid_test(void)
{
struct
{
PWSTR SidStr;
UINT32 Uid;
} map[] =
{
{ L"S-1-0-0", 0x10000 },
{ L"S-1-1-0", 0x10100 },
{ L"S-1-2-0", 0x10200 },
{ L"S-1-2-1", 0x10201 },
};
NTSTATUS Result;
BOOL Success;
PSID Sid;
PWSTR SidStr;
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);
ASSERT(Success);
ASSERT(0 == wcscmp(map[i].SidStr, SidStr));
LocalFree(SidStr);
Result = FspPosixMapSidToUid(Sid, &map[i].Uid);
ASSERT(NT_SUCCESS(Result));
FspDeleteSid(Sid, FspPosixMapUidToSid);
}
}
void posix_tests(void)
{
TEST(posix_map_sid_test);
}

View File

@ -7,6 +7,7 @@ int WinFspNetTests = 1;
int main(int argc, char *argv[])
{
TESTSUITE(fuse_opt_tests);
TESTSUITE(posix_tests);
TESTSUITE(eventlog_tests);
TESTSUITE(path_tests);
TESTSUITE(mount_tests);