mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 08:53:01 -05:00
sys: FspUnicodePathIsValid: check and return stream type
This commit is contained in:
parent
4ccbd1bdf6
commit
c6967c737a
@ -179,6 +179,7 @@ static NTSTATUS FspFsvolCreateNoLock(
|
|||||||
FSP_FILE_NODE *FileNode, *RelatedFileNode;
|
FSP_FILE_NODE *FileNode, *RelatedFileNode;
|
||||||
FSP_FILE_DESC *FileDesc;
|
FSP_FILE_DESC *FileDesc;
|
||||||
UNICODE_STRING MainFileName = { 0 }, StreamPart = { 0 };
|
UNICODE_STRING MainFileName = { 0 }, StreamPart = { 0 };
|
||||||
|
ULONG StreamType = FspUnicodePathStreamTypeNone;
|
||||||
FSP_FSCTL_TRANSACT_REQ *Request;
|
FSP_FSCTL_TRANSACT_REQ *Request;
|
||||||
|
|
||||||
/* cannot open files by fileid */
|
/* cannot open files by fileid */
|
||||||
@ -276,7 +277,8 @@ static NTSTATUS FspFsvolCreateNoLock(
|
|||||||
|
|
||||||
/* check filename validity */
|
/* check filename validity */
|
||||||
if (!FspUnicodePathIsValid(&FileNode->FileName,
|
if (!FspUnicodePathIsValid(&FileNode->FileName,
|
||||||
FsvolDeviceExtension->VolumeParams.NamedStreams ? &StreamPart : 0))
|
FsvolDeviceExtension->VolumeParams.NamedStreams ? &StreamPart : 0,
|
||||||
|
&StreamType))
|
||||||
{
|
{
|
||||||
FspFileNodeDereference(FileNode);
|
FspFileNodeDereference(FileNode);
|
||||||
return STATUS_OBJECT_NAME_INVALID;
|
return STATUS_OBJECT_NAME_INVALID;
|
||||||
@ -291,7 +293,8 @@ static NTSTATUS FspFsvolCreateNoLock(
|
|||||||
(PUINT8)FileNode->FileName.Buffer + FileNode->FileName.Length);
|
(PUINT8)FileNode->FileName.Buffer + FileNode->FileName.Length);
|
||||||
|
|
||||||
FileNode->FileName.Length = (USHORT)
|
FileNode->FileName.Length = (USHORT)
|
||||||
((PUINT8)StreamPart.Buffer - (PUINT8)FileNode->FileName.Buffer + StreamPart.Length);
|
((PUINT8)StreamPart.Buffer - (PUINT8)FileNode->FileName.Buffer + StreamPart.Length -
|
||||||
|
(0 == StreamPart.Length) * sizeof(WCHAR));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check and remove any volume prefix */
|
/* check and remove any volume prefix */
|
||||||
@ -330,6 +333,16 @@ static NTSTATUS FspFsvolCreateNoLock(
|
|||||||
FileNode->FileName.Length -= sizeof(WCHAR);
|
FileNode->FileName.Length -= sizeof(WCHAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if a $DATA stream type, this cannot be a directory */
|
||||||
|
if (FspUnicodePathStreamTypeData == StreamType)
|
||||||
|
{
|
||||||
|
if (FlagOn(CreateOptions, FILE_DIRECTORY_FILE))
|
||||||
|
{
|
||||||
|
FspFileNodeDereference(FileNode);
|
||||||
|
return STATUS_NOT_A_DIRECTORY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* not all operations allowed on the root directory */
|
/* not all operations allowed on the root directory */
|
||||||
if (sizeof(WCHAR) == FileNode->FileName.Length &&
|
if (sizeof(WCHAR) == FileNode->FileName.Length &&
|
||||||
(FILE_CREATE == CreateDisposition ||
|
(FILE_CREATE == CreateDisposition ||
|
||||||
|
@ -423,9 +423,14 @@ BOOLEAN FspExpirationTimeValid2(UINT64 ExpirationTime, UINT64 CurrentTime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* utility */
|
/* utility */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
FspUnicodePathStreamTypeNone = 0,
|
||||||
|
FspUnicodePathStreamTypeData = 1,
|
||||||
|
};
|
||||||
PVOID FspAllocatePoolMustSucceed(POOL_TYPE PoolType, SIZE_T Size, ULONG Tag);
|
PVOID FspAllocatePoolMustSucceed(POOL_TYPE PoolType, SIZE_T Size, ULONG Tag);
|
||||||
PVOID FspAllocateIrpMustSucceed(CCHAR StackSize);
|
PVOID FspAllocateIrpMustSucceed(CCHAR StackSize);
|
||||||
BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart);
|
BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart, PULONG StreamType);
|
||||||
BOOLEAN FspUnicodePathIsValidPattern(PUNICODE_STRING Pattern);
|
BOOLEAN FspUnicodePathIsValidPattern(PUNICODE_STRING Pattern);
|
||||||
VOID FspUnicodePathSuffix(PUNICODE_STRING Path, PUNICODE_STRING Remain, PUNICODE_STRING Suffix);
|
VOID FspUnicodePathSuffix(PUNICODE_STRING Path, PUNICODE_STRING Remain, PUNICODE_STRING Suffix);
|
||||||
NTSTATUS FspCreateGuid(GUID *Guid);
|
NTSTATUS FspCreateGuid(GUID *Guid);
|
||||||
|
@ -1274,7 +1274,7 @@ NTSTATUS FspMainFileOpen(
|
|||||||
PFILE_OBJECT MainFileObject;
|
PFILE_OBJECT MainFileObject;
|
||||||
|
|
||||||
/* assert that the supplied name is actually a main file name */
|
/* assert that the supplied name is actually a main file name */
|
||||||
ASSERT(FspUnicodePathIsValid(MainFileName, 0));
|
ASSERT(FspUnicodePathIsValid(MainFileName, 0, 0));
|
||||||
|
|
||||||
*PMainFileHandle = 0;
|
*PMainFileHandle = 0;
|
||||||
*PMainFileObject = 0;
|
*PMainFileObject = 0;
|
||||||
|
@ -1114,7 +1114,7 @@ static NTSTATUS FspFsvolSetRenameInformation(
|
|||||||
if (FileNode->IsRootDirectory)
|
if (FileNode->IsRootDirectory)
|
||||||
/* cannot rename root directory */
|
/* cannot rename root directory */
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
if (!FspUnicodePathIsValid(&FileNode->FileName, 0))
|
if (!FspUnicodePathIsValid(&FileNode->FileName, 0, 0))
|
||||||
/* cannot rename streams (WinFsp limitation) */
|
/* cannot rename streams (WinFsp limitation) */
|
||||||
return STATUS_INVALID_PARAMETER;
|
return STATUS_INVALID_PARAMETER;
|
||||||
|
|
||||||
@ -1139,7 +1139,7 @@ static NTSTATUS FspFsvolSetRenameInformation(
|
|||||||
if (L'\\' == Suffix.Buffer[0])
|
if (L'\\' == Suffix.Buffer[0])
|
||||||
FspUnicodePathSuffix(&Suffix, &NewFileName, &Suffix);
|
FspUnicodePathSuffix(&Suffix, &NewFileName, &Suffix);
|
||||||
|
|
||||||
if (!FspUnicodePathIsValid(&Remain, 0) || !FspUnicodePathIsValid(&Suffix, 0))
|
if (!FspUnicodePathIsValid(&Remain, 0, 0) || !FspUnicodePathIsValid(&Suffix, 0, 0))
|
||||||
{
|
{
|
||||||
/* cannot rename streams (WinFsp limitation) */
|
/* cannot rename streams (WinFsp limitation) */
|
||||||
Result = STATUS_INVALID_PARAMETER;
|
Result = STATUS_INVALID_PARAMETER;
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
#include <sys/driver.h>
|
#include <sys/driver.h>
|
||||||
|
|
||||||
BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart);
|
BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart, PULONG StreamType);
|
||||||
BOOLEAN FspUnicodePathIsValidPattern(PUNICODE_STRING Pattern);
|
BOOLEAN FspUnicodePathIsValidPattern(PUNICODE_STRING Pattern);
|
||||||
VOID FspUnicodePathSuffix(PUNICODE_STRING Path, PUNICODE_STRING Remain, PUNICODE_STRING Suffix);
|
VOID FspUnicodePathSuffix(PUNICODE_STRING Path, PUNICODE_STRING Remain, PUNICODE_STRING Suffix);
|
||||||
NTSTATUS FspCreateGuid(GUID *Guid);
|
NTSTATUS FspCreateGuid(GUID *Guid);
|
||||||
@ -171,14 +171,17 @@ PVOID FspAllocateIrpMustSucceed(CCHAR StackSize)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart)
|
BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart, PULONG StreamType)
|
||||||
{
|
{
|
||||||
PAGED_CODE();
|
PAGED_CODE();
|
||||||
|
|
||||||
|
/* if StreamPart is not NULL, StreamType must also be not NULL */
|
||||||
|
ASSERT(0 == StreamPart || 0 != StreamType);
|
||||||
|
|
||||||
if (0 != Path->Length % sizeof(WCHAR))
|
if (0 != Path->Length % sizeof(WCHAR))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
PWSTR PathBgn, PathEnd, PathPtr;
|
PWSTR PathBgn, PathEnd, PathPtr, StreamTypeStr = 0;
|
||||||
UCHAR Flags = FSRTL_NTFS_LEGAL;
|
UCHAR Flags = FSRTL_NTFS_LEGAL;
|
||||||
ULONG Colons = 0;
|
ULONG Colons = 0;
|
||||||
WCHAR Char;
|
WCHAR Char;
|
||||||
@ -221,15 +224,17 @@ BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart)
|
|||||||
if (1 == Colons)
|
if (1 == Colons)
|
||||||
{
|
{
|
||||||
/* first time through: set up StreamPart */
|
/* first time through: set up StreamPart */
|
||||||
StreamPart->Length = StreamPart->MaximumLength =
|
StreamPart->Length = StreamPart->MaximumLength = (USHORT)
|
||||||
(USHORT)((PUINT8)PathEnd - (PUINT8)PathPtr);
|
((PUINT8)PathEnd - (PUINT8)PathPtr);
|
||||||
StreamPart->Buffer = PathPtr;
|
StreamPart->Buffer = PathPtr;
|
||||||
}
|
}
|
||||||
else if (2 == Colons)
|
else if (2 == Colons)
|
||||||
{
|
{
|
||||||
/* second time through: fix StreamPart length to not include 2nd colon */
|
/* second time through: fix StreamPart length to not include 2nd colon */
|
||||||
StreamPart->Length =
|
StreamPart->Length = (USHORT)
|
||||||
(USHORT)((PUINT8)PathPtr - (PUINT8)StreamPart->Buffer - 1);
|
((PUINT8)PathPtr - (PUINT8)StreamPart->Buffer - sizeof(WCHAR));
|
||||||
|
|
||||||
|
StreamTypeStr = PathPtr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (0x80 > Char && !FsRtlTestAnsiCharacter(Char, TRUE, FALSE, Flags))
|
else if (0x80 > Char && !FsRtlTestAnsiCharacter(Char, TRUE, FALSE, Flags))
|
||||||
@ -238,7 +243,31 @@ BOOLEAN FspUnicodePathIsValid(PUNICODE_STRING Path, PUNICODE_STRING StreamPart)
|
|||||||
PathPtr++;
|
PathPtr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
/* if we had no colons the path is valid */
|
||||||
|
if (0 == Colons)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
ASSERT(0 != StreamPart && 0 != StreamType);
|
||||||
|
|
||||||
|
*StreamType = FspUnicodePathStreamTypeNone;
|
||||||
|
|
||||||
|
/* if we had no stream type the path is valid if there was an actual stream name */
|
||||||
|
if (0 == StreamTypeStr)
|
||||||
|
return 0 != StreamPart->Length;
|
||||||
|
|
||||||
|
/* if we had a stream type the path is valid if the stream type was "$DATA" only */
|
||||||
|
if (StreamTypeStr + 5 == PathEnd &&
|
||||||
|
L'$' == StreamTypeStr[0] &&
|
||||||
|
L'D' == StreamTypeStr[1] &&
|
||||||
|
L'A' == StreamTypeStr[2] &&
|
||||||
|
L'T' == StreamTypeStr[3] &&
|
||||||
|
L'A' == StreamTypeStr[4])
|
||||||
|
{
|
||||||
|
*StreamType = FspUnicodePathStreamTypeData;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOLEAN FspUnicodePathIsValidPattern(PUNICODE_STRING Path)
|
BOOLEAN FspUnicodePathIsValidPattern(PUNICODE_STRING Path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user