mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-22 08:23:05 -05:00
dll: FspPathPrefix(), FspPathSuffix(): better root handling
This commit is contained in:
parent
d8bb5bf976
commit
0cc5468764
@ -223,8 +223,8 @@ NTSTATUS FspAccessCheck(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
/*
|
/*
|
||||||
* Path Handling
|
* Path Handling
|
||||||
*/
|
*/
|
||||||
FSP_API VOID FspPathPrefix(PWSTR Path, PWSTR *PPrefix, PWSTR *PRemain);
|
FSP_API VOID FspPathPrefix(PWSTR Path, PWSTR *PPrefix, PWSTR *PRemain, PWSTR Root);
|
||||||
FSP_API VOID FspPathSuffix(PWSTR Path, PWSTR *PRemain, PWSTR *PSuffix);
|
FSP_API VOID FspPathSuffix(PWSTR Path, PWSTR *PRemain, PWSTR *PSuffix, PWSTR Root);
|
||||||
FSP_API VOID FspPathCombine(PWSTR Prefix, PWSTR Suffix);
|
FSP_API VOID FspPathCombine(PWSTR Prefix, PWSTR Suffix);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -56,7 +56,8 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
PWSTR Parent, Suffix, Prefix, Remain;
|
WCHAR Root[2] = L"\\", TraverseCheckRoot[2] = L"\\";
|
||||||
|
PWSTR FileName, Suffix, Prefix, Remain;
|
||||||
UINT32 FileAttributes;
|
UINT32 FileAttributes;
|
||||||
PSECURITY_DESCRIPTOR SecurityDescriptor = 0;
|
PSECURITY_DESCRIPTOR SecurityDescriptor = 0;
|
||||||
SIZE_T SecurityDescriptorSize;
|
SIZE_T SecurityDescriptorSize;
|
||||||
@ -67,7 +68,9 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
BOOL AccessStatus;
|
BOOL AccessStatus;
|
||||||
|
|
||||||
if (CheckParentDirectory)
|
if (CheckParentDirectory)
|
||||||
FspPathSuffix((PWSTR)Request->Buffer, &Parent, &Suffix);
|
FspPathSuffix((PWSTR)Request->Buffer, &FileName, &Suffix, Root);
|
||||||
|
else
|
||||||
|
FileName = (PWSTR)Request->Buffer;
|
||||||
|
|
||||||
SecurityDescriptorSize = 1024;
|
SecurityDescriptorSize = 1024;
|
||||||
SecurityDescriptor = MemAlloc(SecurityDescriptorSize);
|
SecurityDescriptor = MemAlloc(SecurityDescriptorSize);
|
||||||
@ -80,21 +83,20 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
if (Request->Req.Create.UserMode &&
|
if (Request->Req.Create.UserMode &&
|
||||||
AllowTraverseCheck && !Request->Req.Create.HasTraversePrivilege)
|
AllowTraverseCheck && !Request->Req.Create.HasTraversePrivilege)
|
||||||
{
|
{
|
||||||
Remain = (PWSTR)Request->Buffer;
|
Remain = (PWSTR)FileName;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
FspPathPrefix(Remain, &Prefix, &Remain);
|
FspPathPrefix(Remain, &Prefix, &Remain, TraverseCheckRoot);
|
||||||
if (L'\0' == Remain[0])
|
if (L'\0' == Remain[0])
|
||||||
{
|
{
|
||||||
FspPathCombine((PWSTR)Request->Buffer, Remain);
|
FspPathCombine(FileName, Remain);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Prefix = L'\0' == Prefix[0] ? L"\\" : (PWSTR)Request->Buffer;
|
|
||||||
Result = FspGetSecurity(FileSystem, Prefix, 0,
|
Result = FspGetSecurity(FileSystem, Prefix, 0,
|
||||||
&SecurityDescriptor, &SecurityDescriptorSize);
|
&SecurityDescriptor, &SecurityDescriptorSize);
|
||||||
|
|
||||||
FspPathCombine((PWSTR)Request->Buffer, Remain);
|
FspPathCombine(FileName, Remain);
|
||||||
|
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
{
|
{
|
||||||
@ -116,7 +118,7 @@ FSP_API NTSTATUS FspAccessCheckEx(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Result = FspGetSecurity(FileSystem, (PWSTR)Request->Buffer, &FileAttributes,
|
Result = FspGetSecurity(FileSystem, FileName, &FileAttributes,
|
||||||
&SecurityDescriptor, &SecurityDescriptorSize);
|
&SecurityDescriptor, &SecurityDescriptorSize);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -498,6 +500,7 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenTargetDirectory(FSP_FILE_SYSTEM *F
|
|||||||
FSP_FSCTL_TRANSACT_REQ *Request)
|
FSP_FSCTL_TRANSACT_REQ *Request)
|
||||||
{
|
{
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
WCHAR Root[2] = L"\\";
|
||||||
PWSTR Parent, Suffix;
|
PWSTR Parent, Suffix;
|
||||||
UINT32 GrantedAccess;
|
UINT32 GrantedAccess;
|
||||||
PVOID FileNode;
|
PVOID FileNode;
|
||||||
@ -509,11 +512,11 @@ static NTSTATUS FspFileSystemOpCreate_FileOpenTargetDirectory(FSP_FILE_SYSTEM *F
|
|||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
return FspFileSystemSendResponseWithStatus(FileSystem, Request, Result);
|
return FspFileSystemSendResponseWithStatus(FileSystem, Request, Result);
|
||||||
|
|
||||||
FspPathSuffix((PWSTR)Request->Buffer, &Parent, &Suffix);
|
|
||||||
FileNode = 0;
|
FileNode = 0;
|
||||||
memset(&FileInfo, 0, sizeof FileInfo);
|
memset(&FileInfo, 0, sizeof FileInfo);
|
||||||
|
FspPathSuffix((PWSTR)Request->Buffer, &Parent, &Suffix, Root);
|
||||||
Result = FileSystem->Interface->Open(FileSystem, Request,
|
Result = FileSystem->Interface->Open(FileSystem, Request,
|
||||||
(PWSTR)Request->Buffer, Request->Req.Create.CaseSensitive, Request->Req.Create.CreateOptions,
|
Parent, Request->Req.Create.CaseSensitive, Request->Req.Create.CreateOptions,
|
||||||
&FileNode, &FileInfo);
|
&FileNode, &FileInfo);
|
||||||
FspPathCombine((PWSTR)Request->Buffer, Suffix);
|
FspPathCombine((PWSTR)Request->Buffer, Suffix);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
|
@ -6,13 +6,15 @@
|
|||||||
|
|
||||||
#include <dll/library.h>
|
#include <dll/library.h>
|
||||||
|
|
||||||
FSP_API VOID FspPathPrefix(PWSTR Path, PWSTR *PPrefix, PWSTR *PRemain)
|
FSP_API VOID FspPathPrefix(PWSTR Path, PWSTR *PPrefix, PWSTR *PRemain, PWSTR Root)
|
||||||
{
|
{
|
||||||
PWSTR Pointer;
|
PWSTR Pointer;
|
||||||
|
|
||||||
for (Pointer = Path; *Pointer; Pointer++)
|
for (Pointer = Path; *Pointer; Pointer++)
|
||||||
if (L'\\' == *Pointer)
|
if (L'\\' == *Pointer)
|
||||||
{
|
{
|
||||||
|
if (0 != Root && Path == Pointer)
|
||||||
|
Path = Root;
|
||||||
*Pointer++ = L'\0';
|
*Pointer++ = L'\0';
|
||||||
for (; L'\\' == *Pointer; Pointer++)
|
for (; L'\\' == *Pointer; Pointer++)
|
||||||
;
|
;
|
||||||
@ -23,7 +25,7 @@ FSP_API VOID FspPathPrefix(PWSTR Path, PWSTR *PPrefix, PWSTR *PRemain)
|
|||||||
*PRemain = Pointer;
|
*PRemain = Pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
FSP_API VOID FspPathSuffix(PWSTR Path, PWSTR *PRemain, PWSTR *PSuffix)
|
FSP_API VOID FspPathSuffix(PWSTR Path, PWSTR *PRemain, PWSTR *PSuffix, PWSTR Root)
|
||||||
{
|
{
|
||||||
PWSTR Pointer, RemainEnd, Suffix = 0;
|
PWSTR Pointer, RemainEnd, Suffix = 0;
|
||||||
|
|
||||||
@ -41,6 +43,8 @@ FSP_API VOID FspPathSuffix(PWSTR Path, PWSTR *PRemain, PWSTR *PSuffix)
|
|||||||
*PRemain = Path;
|
*PRemain = Path;
|
||||||
if (Path < Suffix)
|
if (Path < Suffix)
|
||||||
{
|
{
|
||||||
|
if (0 != Root && Path == RemainEnd && L'\\' == *Path)
|
||||||
|
*PRemain = Root;
|
||||||
*RemainEnd = L'\0';
|
*RemainEnd = L'\0';
|
||||||
*PSuffix = Suffix;
|
*PSuffix = Suffix;
|
||||||
}
|
}
|
||||||
|
@ -133,10 +133,11 @@ static inline
|
|||||||
MEMFS_FILE_NODE *MemfsFileNodeMapGetParent(MEMFS_FILE_NODE_MAP *FileNodeMap, PWSTR FileName,
|
MEMFS_FILE_NODE *MemfsFileNodeMapGetParent(MEMFS_FILE_NODE_MAP *FileNodeMap, PWSTR FileName,
|
||||||
PNTSTATUS PResult)
|
PNTSTATUS PResult)
|
||||||
{
|
{
|
||||||
|
WCHAR Root[2] = L"\\";
|
||||||
PWSTR Remain, Suffix;
|
PWSTR Remain, Suffix;
|
||||||
FspPathSuffix(FileName, &Remain, &Suffix);
|
FspPathSuffix(FileName, &Remain, &Suffix, Root);
|
||||||
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->find(Remain);
|
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->find(Remain);
|
||||||
FspPathCombine(Remain, Suffix);
|
FspPathCombine(FileName, Suffix);
|
||||||
if (iter == FileNodeMap->end())
|
if (iter == FileNodeMap->end())
|
||||||
{
|
{
|
||||||
*PResult = STATUS_OBJECT_PATH_NOT_FOUND;
|
*PResult = STATUS_OBJECT_PATH_NOT_FOUND;
|
||||||
@ -179,13 +180,14 @@ static inline
|
|||||||
BOOLEAN MemfsFileNodeMapHasChild(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMFS_FILE_NODE *FileNode)
|
BOOLEAN MemfsFileNodeMapHasChild(MEMFS_FILE_NODE_MAP *FileNodeMap, MEMFS_FILE_NODE *FileNode)
|
||||||
{
|
{
|
||||||
BOOLEAN Result;
|
BOOLEAN Result;
|
||||||
|
WCHAR Root[2] = L"\\";
|
||||||
PWSTR Remain, Suffix;
|
PWSTR Remain, Suffix;
|
||||||
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->upper_bound(FileNode->FileName);
|
MEMFS_FILE_NODE_MAP::iterator iter = FileNodeMap->upper_bound(FileNode->FileName);
|
||||||
if (iter == FileNodeMap->end())
|
if (iter == FileNodeMap->end())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
FspPathSuffix(iter->second->FileName, &Remain, &Suffix);
|
FspPathSuffix(iter->second->FileName, &Remain, &Suffix, Root);
|
||||||
Result = 0 == MemfsFileNameCompare(Remain, FileNode->FileName);
|
Result = 0 == MemfsFileNameCompare(Remain, FileNode->FileName);
|
||||||
FspPathCombine(Remain, Suffix);
|
FspPathCombine(iter->second->FileName, Suffix);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +198,7 @@ static NTSTATUS GetVolumeInfo(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
MEMFS *Memfs = (MEMFS *)FileSystem->UserContext;
|
||||||
MEMFS_FILE_NODE *RootNode;
|
MEMFS_FILE_NODE *RootNode;
|
||||||
|
|
||||||
RootNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, L"");
|
RootNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, L"\\");
|
||||||
if (0 == RootNode)
|
if (0 == RootNode)
|
||||||
return STATUS_DISK_CORRUPT_ERROR;
|
return STATUS_DISK_CORRUPT_ERROR;
|
||||||
|
|
||||||
@ -218,9 +220,6 @@ static NTSTATUS GetSecurity(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
MEMFS_FILE_NODE *FileNode;
|
MEMFS_FILE_NODE *FileNode;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
if (L'\\' == FileName[0] && L'\0' == FileName[1])
|
|
||||||
FileName = L"";
|
|
||||||
|
|
||||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||||
if (0 == FileNode)
|
if (0 == FileNode)
|
||||||
{
|
{
|
||||||
@ -259,9 +258,6 @@ static NTSTATUS Create(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
BOOLEAN Inserted;
|
BOOLEAN Inserted;
|
||||||
|
|
||||||
if (L'\\' == FileName[0] && L'\0' == FileName[1])
|
|
||||||
FileName = L"";
|
|
||||||
|
|
||||||
if (CreateOptions & FILE_DIRECTORY_FILE)
|
if (CreateOptions & FILE_DIRECTORY_FILE)
|
||||||
AllocationSize = 0;
|
AllocationSize = 0;
|
||||||
|
|
||||||
@ -332,9 +328,6 @@ static NTSTATUS Open(FSP_FILE_SYSTEM *FileSystem,
|
|||||||
MEMFS_FILE_NODE *FileNode;
|
MEMFS_FILE_NODE *FileNode;
|
||||||
NTSTATUS Result;
|
NTSTATUS Result;
|
||||||
|
|
||||||
if (L'\\' == FileName[0] && L'\0' == FileName[1])
|
|
||||||
FileName = L"";
|
|
||||||
|
|
||||||
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
FileNode = MemfsFileNodeMapGet(Memfs->FileNodeMap, FileName);
|
||||||
if (0 == FileNode)
|
if (0 == FileNode)
|
||||||
{
|
{
|
||||||
@ -635,7 +628,7 @@ NTSTATUS MemfsCreate(ULONG Flags, ULONG FileInfoTimeout,
|
|||||||
* Create root directory.
|
* Create root directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Result = MemfsFileNodeCreate(L"", &RootNode);
|
Result = MemfsFileNodeCreate(L"\\", &RootNode);
|
||||||
if (!NT_SUCCESS(Result))
|
if (!NT_SUCCESS(Result))
|
||||||
{
|
{
|
||||||
MemfsDelete(Memfs);
|
MemfsDelete(Memfs);
|
||||||
|
@ -19,16 +19,17 @@ void path_prefix_test(void)
|
|||||||
L"foo\\\\\\bar\\\\baz",
|
L"foo\\\\\\bar\\\\baz",
|
||||||
L"foo\\\\\\bar\\\\baz\\",
|
L"foo\\\\\\bar\\\\baz\\",
|
||||||
L"foo\\\\\\bar\\\\baz\\\\",
|
L"foo\\\\\\bar\\\\baz\\\\",
|
||||||
|
L"foo",
|
||||||
};
|
};
|
||||||
PWSTR opaths[] =
|
PWSTR opaths[] =
|
||||||
{
|
{
|
||||||
L"", L"",
|
L"", L"",
|
||||||
L"", L"",
|
L"ROOT", L"",
|
||||||
L"", L"",
|
L"ROOT", L"",
|
||||||
L"", L"a",
|
L"ROOT", L"a",
|
||||||
L"", L"a",
|
L"ROOT", L"a",
|
||||||
L"", L"a\\",
|
L"ROOT", L"a\\",
|
||||||
L"", L"a\\\\",
|
L"ROOT", L"a\\\\",
|
||||||
L"a", L"",
|
L"a", L"",
|
||||||
L"a", L"",
|
L"a", L"",
|
||||||
L"a", L"b",
|
L"a", L"b",
|
||||||
@ -36,6 +37,7 @@ void path_prefix_test(void)
|
|||||||
L"foo", L"bar\\\\baz",
|
L"foo", L"bar\\\\baz",
|
||||||
L"foo", L"bar\\\\baz\\",
|
L"foo", L"bar\\\\baz\\",
|
||||||
L"foo", L"bar\\\\baz\\\\",
|
L"foo", L"bar\\\\baz\\\\",
|
||||||
|
L"foo", L"",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; sizeof ipaths / sizeof ipaths[0] > i; i++)
|
for (size_t i = 0; sizeof ipaths / sizeof ipaths[0] > i; i++)
|
||||||
@ -43,10 +45,10 @@ void path_prefix_test(void)
|
|||||||
PWSTR Prefix, Remain;
|
PWSTR Prefix, Remain;
|
||||||
WCHAR buf[32];
|
WCHAR buf[32];
|
||||||
wcscpy_s(buf, 32, ipaths[i]);
|
wcscpy_s(buf, 32, ipaths[i]);
|
||||||
FspPathPrefix(buf, &Prefix, &Remain);
|
FspPathPrefix(buf, &Prefix, &Remain, L"ROOT");
|
||||||
ASSERT(0 == wcscmp(opaths[2 * i + 0], Prefix));
|
ASSERT(0 == wcscmp(opaths[2 * i + 0], Prefix));
|
||||||
ASSERT(0 == wcscmp(opaths[2 * i + 1], Remain));
|
ASSERT(0 == wcscmp(opaths[2 * i + 1], Remain));
|
||||||
FspPathCombine(Prefix, Remain);
|
FspPathCombine(buf, Remain);
|
||||||
ASSERT(0 == wcscmp(ipaths[i], buf));
|
ASSERT(0 == wcscmp(ipaths[i], buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,14 +71,15 @@ void path_suffix_test(void)
|
|||||||
L"foo\\\\\\bar\\\\baz",
|
L"foo\\\\\\bar\\\\baz",
|
||||||
L"foo\\\\\\bar\\\\baz\\",
|
L"foo\\\\\\bar\\\\baz\\",
|
||||||
L"foo\\\\\\bar\\\\baz\\\\",
|
L"foo\\\\\\bar\\\\baz\\\\",
|
||||||
|
L"foo",
|
||||||
};
|
};
|
||||||
PWSTR opaths[] =
|
PWSTR opaths[] =
|
||||||
{
|
{
|
||||||
L"", L"",
|
L"", L"",
|
||||||
L"", L"",
|
L"ROOT", L"",
|
||||||
L"", L"",
|
L"ROOT", L"",
|
||||||
L"", L"a",
|
L"ROOT", L"a",
|
||||||
L"", L"a",
|
L"ROOT", L"a",
|
||||||
L"\\\\a", L"",
|
L"\\\\a", L"",
|
||||||
L"\\\\a", L"",
|
L"\\\\a", L"",
|
||||||
L"a", L"",
|
L"a", L"",
|
||||||
@ -86,6 +89,7 @@ void path_suffix_test(void)
|
|||||||
L"foo\\\\\\bar", L"baz",
|
L"foo\\\\\\bar", L"baz",
|
||||||
L"foo\\\\\\bar\\\\baz", L"",
|
L"foo\\\\\\bar\\\\baz", L"",
|
||||||
L"foo\\\\\\bar\\\\baz", L"",
|
L"foo\\\\\\bar\\\\baz", L"",
|
||||||
|
L"foo", L"",
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; sizeof ipaths / sizeof ipaths[0] > i; i++)
|
for (size_t i = 0; sizeof ipaths / sizeof ipaths[0] > i; i++)
|
||||||
@ -93,10 +97,10 @@ void path_suffix_test(void)
|
|||||||
PWSTR Remain, Suffix;
|
PWSTR Remain, Suffix;
|
||||||
WCHAR buf[32];
|
WCHAR buf[32];
|
||||||
wcscpy_s(buf, 32, ipaths[i]);
|
wcscpy_s(buf, 32, ipaths[i]);
|
||||||
FspPathSuffix(buf, &Remain, &Suffix);
|
FspPathSuffix(buf, &Remain, &Suffix, L"ROOT");
|
||||||
ASSERT(0 == wcscmp(opaths[2 * i + 0], Remain));
|
ASSERT(0 == wcscmp(opaths[2 * i + 0], Remain));
|
||||||
ASSERT(0 == wcscmp(opaths[2 * i + 1], Suffix));
|
ASSERT(0 == wcscmp(opaths[2 * i + 1], Suffix));
|
||||||
FspPathCombine(Remain, Suffix);
|
FspPathCombine(buf, Suffix);
|
||||||
ASSERT(0 == wcscmp(ipaths[i], buf));
|
ASSERT(0 == wcscmp(ipaths[i], buf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user