diff --git a/build/VStudio/testing/winfsp-tests.vcxproj b/build/VStudio/testing/winfsp-tests.vcxproj
index 8cd4bdd6..316d64ab 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj
+++ b/build/VStudio/testing/winfsp-tests.vcxproj
@@ -191,6 +191,7 @@
+
diff --git a/build/VStudio/testing/winfsp-tests.vcxproj.filters b/build/VStudio/testing/winfsp-tests.vcxproj.filters
index 54a96231..bb32ce4c 100644
--- a/build/VStudio/testing/winfsp-tests.vcxproj.filters
+++ b/build/VStudio/testing/winfsp-tests.vcxproj.filters
@@ -58,6 +58,9 @@
Source
+
+ Source
+
diff --git a/src/dll/library.c b/src/dll/library.c
index be83b315..a601c31b 100644
--- a/src/dll/library.c
+++ b/src/dll/library.c
@@ -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;
diff --git a/src/dll/library.h b/src/dll/library.h
index f32f1e44..0f3402f7 100644
--- a/src/dll/library.h
+++ b/src/dll/library.h
@@ -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);
diff --git a/src/dll/posix.c b/src/dll/posix.c
index 1d7cd880..e87130ef 100644
--- a/src/dll/posix.c
+++ b/src/dll/posix.c
@@ -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;
}
diff --git a/tst/winfsp-tests/posix-test.c b/tst/winfsp-tests/posix-test.c
new file mode 100644
index 00000000..f3883dac
--- /dev/null
+++ b/tst/winfsp-tests/posix-test.c
@@ -0,0 +1,43 @@
+#include
+#include
+#include
+
+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);
+}
diff --git a/tst/winfsp-tests/winfsp-tests.c b/tst/winfsp-tests/winfsp-tests.c
index 6967e1d6..c343a83c 100644
--- a/tst/winfsp-tests/winfsp-tests.c
+++ b/tst/winfsp-tests/winfsp-tests.c
@@ -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);