From 396997fb2258d80becb5f6202d126b3f96146f1c Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Tue, 7 Jun 2016 16:03:48 -0700 Subject: [PATCH] winfsp-tests: posix_map_path_test --- inc/winfsp/winfsp.h | 2 +- src/dll/posix.c | 14 +++++++------- tst/winfsp-tests/posix-test.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/inc/winfsp/winfsp.h b/inc/winfsp/winfsp.h index b841ced1..e775037c 100644 --- a/inc/winfsp/winfsp.h +++ b/inc/winfsp/winfsp.h @@ -850,7 +850,7 @@ FSP_API NTSTATUS FspPosixMapPermissionsToSecurityDescriptor( FSP_API NTSTATUS FspPosixMapSecurityDescriptorToPermissions( PSECURITY_DESCRIPTOR SecurityDescriptor, PUINT32 PUid, PUINT32 PGid, PUINT32 PMode); -FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, const char **PPosixPath); +FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath); FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPath); FSP_API VOID FspPosixDeletePath(void *Path); diff --git a/src/dll/posix.c b/src/dll/posix.c index 19fb86cf..dc609357 100644 --- a/src/dll/posix.c +++ b/src/dll/posix.c @@ -777,7 +777,7 @@ lasterror: * private use area in the U+F0XX range. * * The invalid maps are produced by the following Python script: - * reserved = ['<', '>', ':', '"', '/', '|', '?', '*'] + * reserved = ['<', '>', ':', '"', '\\', '|', '?', '*'] * l = [str(int(0 < i < 32 or chr(i) in reserved)) for i in xrange(0, 128)] * print "0x%08x" % int("".join(l[0:32]), 2) * print "0x%08x" % int("".join(l[32:64]), 2) @@ -787,12 +787,12 @@ lasterror: static UINT32 FspPosixInvalidPathChars[4] = { 0x7fffffff, - 0x2021002b, - 0x00000000, + 0x2020002b, + 0x00000008, 0x00000008, }; -FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, const char **PPosixPath) +FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath) { NTSTATUS Result; ULONG Size; @@ -817,7 +817,7 @@ FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, const char **P for (p = PosixPath, q = p; *p; p++) { - char c = *p; + unsigned char c = *p; if ('\\' == c) *q++ = '/'; @@ -826,7 +826,7 @@ FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, const char **P { c = ((p[1] & 0x3) << 6) | (p[2] & 0x3f); if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f)))) - *q++ = c; + *q++ = c, p += 2; else *q++ = *p++, *q++ = *p++, *q++ = *p; } @@ -862,7 +862,7 @@ FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWi if (0 == Size) goto lasterror; - WindowsPath = MemAlloc(Size); + WindowsPath = MemAlloc(Size * sizeof(WCHAR)); if (0 == PosixPath) { Result = STATUS_INSUFFICIENT_RESOURCES; diff --git a/tst/winfsp-tests/posix-test.c b/tst/winfsp-tests/posix-test.c index e1a2ba80..03c3df14 100644 --- a/tst/winfsp-tests/posix-test.c +++ b/tst/winfsp-tests/posix-test.c @@ -213,8 +213,39 @@ void posix_map_sd_test(void) } } +void posix_map_path_test(void) +{ + struct + { + PWSTR WindowsPath; + const char *PosixPath; + } map[] = + { + { L"\\foo\\bar", "/foo/bar" }, + { L"\\foo\xf03c\xf03e\xf03a\xf02f\xf05c\xf022\xf07c\xf03f\xf02a\\bar", "/foo<>:\xef\x80\xaf\\\"|?*/bar" }, + }; + NTSTATUS Result; + PWSTR WindowsPath; + char *PosixPath; + + for (size_t i = 0; sizeof map / sizeof map[0] > i; i++) + { + Result = FspPosixMapWindowsToPosixPath(map[i].WindowsPath, &PosixPath); + ASSERT(NT_SUCCESS(Result)); + ASSERT(0 == strcmp(map[i].PosixPath, PosixPath)); + + Result = FspPosixMapPosixToWindowsPath(map[i].PosixPath, &WindowsPath); + ASSERT(NT_SUCCESS(Result)); + ASSERT(0 == wcscmp(map[i].WindowsPath, WindowsPath)); + + FspPosixDeletePath(WindowsPath); + FspPosixDeletePath(PosixPath); + } +} + void posix_tests(void) { TEST(posix_map_sid_test); TEST(posix_map_sd_test); + TEST(posix_map_path_test); }