dll: fuse: correctly handle NFS_SPECFILE_LNK reparse points, which are in POSIX UTF-16 format

This commit is contained in:
Bill Zissimopoulos 2016-09-14 10:36:52 -07:00
parent 10635db99b
commit cbcea380ef
3 changed files with 48 additions and 26 deletions

View File

@ -1195,8 +1195,20 @@ FSP_API NTSTATUS FspPosixMapPermissionsToSecurityDescriptor(
FSP_API NTSTATUS FspPosixMapSecurityDescriptorToPermissions( FSP_API NTSTATUS FspPosixMapSecurityDescriptorToPermissions(
PSECURITY_DESCRIPTOR SecurityDescriptor, PSECURITY_DESCRIPTOR SecurityDescriptor,
PUINT32 PUid, PUINT32 PGid, PUINT32 PMode); PUINT32 PUid, PUINT32 PGid, PUINT32 PMode);
FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath); FSP_API NTSTATUS FspPosixMapWindowsToPosixPathEx(PWSTR WindowsPath, char **PPosixPath,
FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPath); BOOLEAN Translate);
FSP_API NTSTATUS FspPosixMapPosixToWindowsPathEx(const char *PosixPath, PWSTR *PWindowsPath,
BOOLEAN Translate);
static inline
NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath)
{
return FspPosixMapWindowsToPosixPathEx(WindowsPath, PPosixPath, TRUE);
}
static inline
NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPath)
{
return FspPosixMapPosixToWindowsPathEx(PosixPath, PWindowsPath, TRUE);
}
FSP_API VOID FspPosixDeletePath(void *Path); FSP_API VOID FspPosixDeletePath(void *Path);
/* /*

View File

@ -1999,6 +1999,7 @@ static NTSTATUS fsp_fuse_intf_SetReparsePoint(FSP_FILE_SYSTEM *FileSystem,
} }
else else
{ {
/* the PATH is in POSIX format (UTF-16 encoding) */
ReparseTargetPath = (PVOID)(ReparseData->GenericReparseBuffer.DataBuffer + 8); ReparseTargetPath = (PVOID)(ReparseData->GenericReparseBuffer.DataBuffer + 8);
ReparseTargetPathLength = ReparseData->ReparseDataLength - 8; ReparseTargetPathLength = ReparseData->ReparseDataLength - 8;
} }
@ -2010,7 +2011,8 @@ static NTSTATUS fsp_fuse_intf_SetReparsePoint(FSP_FILE_SYSTEM *FileSystem,
* From this point forward we must jump to the EXIT label on failure. * From this point forward we must jump to the EXIT label on failure.
*/ */
Result = FspPosixMapWindowsToPosixPath(TargetPath, &PosixTargetPath); Result = FspPosixMapWindowsToPosixPathEx(TargetPath, &PosixTargetPath,
IO_REPARSE_TAG_SYMLINK == ReparseData->ReparseTag);
if (!NT_SUCCESS(Result)) if (!NT_SUCCESS(Result))
goto exit; goto exit;
@ -2029,7 +2031,7 @@ static NTSTATUS fsp_fuse_intf_SetReparsePoint(FSP_FILE_SYSTEM *FileSystem,
} }
else else
{ {
switch (*(PULONG)ReparseData->GenericReparseBuffer.DataBuffer) switch (*(PUINT64)ReparseData->GenericReparseBuffer.DataBuffer)
{ {
case NFS_SPECFILE_FIFO: case NFS_SPECFILE_FIFO:
Mode = (Mode & ~0170000) | 0010000; Mode = (Mode & ~0170000) | 0010000;

View File

@ -805,7 +805,8 @@ static UINT32 FspPosixInvalidPathChars[4] =
0x00000008, 0x00000008,
}; };
FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixPath) FSP_API NTSTATUS FspPosixMapWindowsToPosixPathEx(PWSTR WindowsPath, char **PPosixPath,
BOOLEAN Translate)
{ {
NTSTATUS Result; NTSTATUS Result;
ULONG Size; ULONG Size;
@ -828,25 +829,28 @@ FSP_API NTSTATUS FspPosixMapWindowsToPosixPath(PWSTR WindowsPath, char **PPosixP
if (0 == Size) if (0 == Size)
goto lasterror; goto lasterror;
for (p = PosixPath, q = p; *p; p++) if (Translate)
{ {
unsigned char c = *p; for (p = PosixPath, q = p; *p; p++)
if ('\\' == c)
*q++ = '/';
/* encode characters in the Unicode private use area: U+F0XX -> XX */
else if (0xef == c && 0x80 == (0xfc & p[1]) && 0x80 == (0xc0 & p[2]))
{ {
c = ((p[1] & 0x3) << 6) | (p[2] & 0x3f); unsigned char c = *p;
if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f))))
*q++ = c, p += 2; if ('\\' == c)
*q++ = '/';
/* encode characters in the Unicode private use area: U+F0XX -> XX */
else if (0xef == c && 0x80 == (0xfc & p[1]) && 0x80 == (0xc0 & p[2]))
{
c = ((p[1] & 0x3) << 6) | (p[2] & 0x3f);
if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f))))
*q++ = c, p += 2;
else
*q++ = *p++, *q++ = *p++, *q++ = *p;
}
else else
*q++ = *p++, *q++ = *p++, *q++ = *p; *q++ = c;
} }
else *q = '\0';
*q++ = c;
} }
*q = '\0';
*PPosixPath = PosixPath; *PPosixPath = PosixPath;
@ -863,7 +867,8 @@ lasterror:
goto exit; goto exit;
} }
FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWindowsPath) FSP_API NTSTATUS FspPosixMapPosixToWindowsPathEx(const char *PosixPath, PWSTR *PWindowsPath,
BOOLEAN Translate)
{ {
NTSTATUS Result; NTSTATUS Result;
ULONG Size; ULONG Size;
@ -886,14 +891,17 @@ FSP_API NTSTATUS FspPosixMapPosixToWindowsPath(const char *PosixPath, PWSTR *PWi
if (0 == Size) if (0 == Size)
goto lasterror; goto lasterror;
for (p = WindowsPath; *p; p++) if (Translate)
{ {
WCHAR c = *p; for (p = WindowsPath; *p; p++)
{
WCHAR c = *p;
if (L'/' == c) if (L'/' == c)
*p = L'\\'; *p = L'\\';
else if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f)))) else if (128 > c && (FspPosixInvalidPathChars[c >> 5] & (0x80000000 >> (c & 0x1f))))
*p |= 0xf000; *p |= 0xf000;
}
} }
*PWindowsPath = WindowsPath; *PWindowsPath = WindowsPath;