mirror of
https://github.com/winfsp/winfsp.git
synced 2025-06-15 00:02:46 -05:00
sys: check and remove volume prefix when mounted as a network file system
This commit is contained in:
@ -169,12 +169,13 @@ static NTSTATUS FspFsvolCreate(
|
||||
|
||||
/* check for trailing backslash */
|
||||
if (sizeof(WCHAR) * 2/* not empty or root */ <= FileName.Length &&
|
||||
L'\\' == FileName.Buffer[FileName.Length / 2 - 1])
|
||||
L'\\' == FileName.Buffer[FileName.Length / sizeof(WCHAR) - 1])
|
||||
{
|
||||
FileName.Length -= sizeof(WCHAR);
|
||||
HasTrailingBackslash = TRUE;
|
||||
|
||||
if (sizeof(WCHAR) * 2 <= FileName.Length && L'\\' == FileName.Buffer[FileName.Length / 2 - 1])
|
||||
if (sizeof(WCHAR) * 2 <= FileName.Length &&
|
||||
L'\\' == FileName.Buffer[FileName.Length / sizeof(WCHAR) - 1])
|
||||
return STATUS_OBJECT_NAME_INVALID;
|
||||
}
|
||||
if (HasTrailingBackslash && !FlagOn(CreateOptions, FILE_DIRECTORY_FILE))
|
||||
@ -260,6 +261,23 @@ static NTSTATUS FspFsvolCreate(
|
||||
Result = RtlAppendUnicodeStringToString(&FileNode->FileName, &FileName);
|
||||
ASSERT(NT_SUCCESS(Result));
|
||||
|
||||
/* check and remove any volume prefix */
|
||||
if (0 < FsvolDeviceExtension->VolumePrefix.Length)
|
||||
{
|
||||
if (FileNode->FileName.Length <= FsvolDeviceExtension->VolumePrefix.Length ||
|
||||
!RtlEqualMemory(FileNode->FileName.Buffer, FsvolDeviceExtension->VolumePrefix.Buffer,
|
||||
FsvolDeviceExtension->VolumePrefix.Length) ||
|
||||
'\\' != FileNode->FileName.Buffer[FsvolDeviceExtension->VolumePrefix.Length / sizeof(WCHAR)])
|
||||
{
|
||||
FspFileNodeDereference(FileNode);
|
||||
return STATUS_OBJECT_PATH_NOT_FOUND;
|
||||
}
|
||||
|
||||
FileNode->FileName.Length -= FsvolDeviceExtension->VolumePrefix.Length;
|
||||
FileNode->FileName.MaximumLength -= FsvolDeviceExtension->VolumePrefix.Length;
|
||||
FileNode->FileName.Buffer += FsvolDeviceExtension->VolumePrefix.Length / sizeof(WCHAR);
|
||||
}
|
||||
|
||||
Result = FspFileDescCreate(&FileDesc);
|
||||
if (!NT_SUCCESS(Result))
|
||||
{
|
||||
|
@ -451,6 +451,7 @@ typedef struct
|
||||
FSP_DELAYED_WORK_ITEM DeleteVolumeDelayedWorkItem;
|
||||
ERESOURCE DeleteResource;
|
||||
FSP_FSCTL_VOLUME_PARAMS VolumeParams;
|
||||
UNICODE_STRING VolumePrefix;
|
||||
FSP_IOQ *Ioq;
|
||||
KSPIN_LOCK ExpirationLock;
|
||||
WORK_QUEUE_ITEM ExpirationWorkItem;
|
||||
|
@ -102,7 +102,7 @@ NTSTATUS FspVolumeCreate(
|
||||
VolumeParams.IrpCapacity = FspFsctlIrpCapacityDefault;
|
||||
if (FILE_DEVICE_NETWORK_FILE_SYSTEM == FsctlDeviceObject->DeviceType)
|
||||
{
|
||||
VolumeParams.Prefix[sizeof VolumeParams.Prefix / 2 - 1] = L'\0';
|
||||
VolumeParams.Prefix[sizeof VolumeParams.Prefix / sizeof(WCHAR) - 1] = L'\0';
|
||||
for (; L'\0' != VolumeParams.Prefix[PrefixLength]; PrefixLength++)
|
||||
;
|
||||
for (; 0 < PrefixLength && L'\\' == VolumeParams.Prefix[PrefixLength - 1]; PrefixLength--)
|
||||
@ -155,6 +155,9 @@ NTSTATUS FspVolumeCreate(
|
||||
FsvolDeviceExtension->FsctlDeviceObject = FsctlDeviceObject;
|
||||
FsvolDeviceExtension->FsvrtDeviceObject = FsvrtDeviceObject;
|
||||
FsvolDeviceExtension->VolumeParams = VolumeParams;
|
||||
if (FILE_DEVICE_NETWORK_FILE_SYSTEM == FsctlDeviceObject->DeviceType)
|
||||
RtlInitUnicodeString(&FsvolDeviceExtension->VolumePrefix,
|
||||
FsvolDeviceExtension->VolumeParams.Prefix);
|
||||
RtlInitEmptyUnicodeString(&FsvolDeviceExtension->VolumeName,
|
||||
FsvolDeviceExtension->VolumeNameBuf, sizeof FsvolDeviceExtension->VolumeNameBuf);
|
||||
RtlCopyUnicodeString(&FsvolDeviceExtension->VolumeName, &VolumeName);
|
||||
@ -424,7 +427,6 @@ NTSTATUS FspVolumeRedirQueryPathEx(
|
||||
|
||||
NTSTATUS Result;
|
||||
FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension = FspFsvolDeviceExtension(FsvolDeviceObject);
|
||||
UNICODE_STRING Prefix;
|
||||
|
||||
/* acquire our DeleteResource */
|
||||
ExAcquireResourceExclusiveLite(&FsvolDeviceExtension->DeleteResource, TRUE);
|
||||
@ -432,13 +434,14 @@ NTSTATUS FspVolumeRedirQueryPathEx(
|
||||
Result = STATUS_BAD_NETWORK_PATH;
|
||||
if (!FspIoqStopped(FsvolDeviceExtension->Ioq))
|
||||
{
|
||||
RtlInitUnicodeString(&Prefix, FsvolDeviceExtension->VolumeParams.Prefix);
|
||||
if (Prefix.Length <= QueryPathRequest->PathName.Length &&
|
||||
RtlEqualMemory(Prefix.Buffer, QueryPathRequest->PathName.Buffer, Prefix.Length) &&
|
||||
(Prefix.Length == QueryPathRequest->PathName.Length ||
|
||||
'\\' == QueryPathRequest->PathName.Buffer[Prefix.Length / 2]))
|
||||
if (0 < FsvolDeviceExtension->VolumePrefix.Length &&
|
||||
QueryPathRequest->PathName.Length >= FsvolDeviceExtension->VolumePrefix.Length &&
|
||||
RtlEqualMemory(QueryPathRequest->PathName.Buffer,
|
||||
FsvolDeviceExtension->VolumePrefix.Buffer, FsvolDeviceExtension->VolumePrefix.Length) &&
|
||||
(QueryPathRequest->PathName.Length == FsvolDeviceExtension->VolumePrefix.Length ||
|
||||
'\\' == QueryPathRequest->PathName.Buffer[FsvolDeviceExtension->VolumePrefix.Length / sizeof(WCHAR)]))
|
||||
{
|
||||
QueryPathResponse->LengthAccepted = Prefix.Length;
|
||||
QueryPathResponse->LengthAccepted = FsvolDeviceExtension->VolumePrefix.Length;
|
||||
|
||||
Irp->IoStatus.Information = 0;
|
||||
Result = STATUS_SUCCESS;
|
||||
|
Reference in New Issue
Block a user