dll: fsctl: testing

This commit is contained in:
Bill Zissimopoulos 2015-11-30 17:30:00 -08:00
parent deffa692a6
commit f1dbfe2b74
2 changed files with 73 additions and 25 deletions

View File

@ -7,13 +7,16 @@
#include <winfsp/winfsp.h>
#include <winfsp/fsctl.h>
#include <strsafe.h>
#if !defined(NDEBUG)
#include <sddl.h>
#endif
#define GLOBALROOT L"\\\\?\\GLOBALROOT"
static inline VOID GlobalDevicePath(PWCHAR DevicePathBuf, SIZE_T DevicePathSize, PWSTR DevicePath)
{
StringCbPrintf(DevicePathBuf, DevicePathSize,
L'\\' == DevicePath[0] ? GLOBALROOT "%S" : GLOBALROOT "\\Device\\%S", DevicePath);
StringCbPrintfW(DevicePathBuf, DevicePathSize,
L'\\' == DevicePath[0] ? GLOBALROOT "%s" : GLOBALROOT "\\Device\\%s", DevicePath);
}
FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
@ -21,13 +24,13 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
PWCHAR VolumePathBuf, SIZE_T VolumePathSize)
{
NTSTATUS Result = STATUS_SUCCESS;
WCHAR DevicePathBuf[MAX_PATH];
FSP_FSCTL_VOLUME_PARAMS *ParamsBuf;
HANDLE Token;
PVOID DaclBuf = 0;
FSP_FSCTL_VOLUME_PARAMS *ParamsBuf = 0;
HANDLE Token = 0;
PTOKEN_DEFAULT_DACL DefaultDacl = 0;
SECURITY_DESCRIPTOR SecurityDescriptorStruct;
PSECURITY_DESCRIPTOR SecurityDescriptorBuf = 0;
PSECURITY_DESCRIPTOR SecurityDescriptorBuf;
DWORD SecurityDescriptorSize, Bytes;
WCHAR DevicePathBuf[MAX_PATH];
HANDLE DeviceHandle = INVALID_HANDLE_VALUE;
VolumePathBuf[0] = L'\0';
@ -39,30 +42,50 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
GetTokenInformation(Token, TokenDefaultDacl, 0, 0, &Bytes);
DaclBuf = malloc(Bytes);
if (0 == DaclBuf)
Bytes = 0;
if (!GetTokenInformation(Token, TokenDefaultDacl, 0, 0, &Bytes) &&
ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
DefaultDacl = malloc(Bytes);
if (0 == DefaultDacl)
{
CloseHandle(Token);
Result = STATUS_INSUFFICIENT_RESOURCES;
goto exit;
}
if (GetTokenInformation(Token, TokenDefaultDacl, DaclBuf, Bytes, &Bytes) &&
InitializeSecurityDescriptor(&SecurityDescriptorStruct, SECURITY_DESCRIPTOR_REVISION) &&
SetSecurityDescriptorDacl(&SecurityDescriptorStruct, TRUE, DaclBuf, FALSE))
{
SecurityDescriptor = &SecurityDescriptorStruct;
CloseHandle(Token);
}
else
if (!GetTokenInformation(Token, TokenDefaultDacl, DefaultDacl, Bytes, &Bytes) ||
!InitializeSecurityDescriptor(&SecurityDescriptorStruct, SECURITY_DESCRIPTOR_REVISION) ||
!SetSecurityDescriptorDacl(&SecurityDescriptorStruct, TRUE, DefaultDacl->DefaultDacl, FALSE))
{
Result = FspNtStatusFromWin32(GetLastError());
CloseHandle(Token);
goto exit;
}
SecurityDescriptor = &SecurityDescriptorStruct;
CloseHandle(Token);
Token = 0;
}
SecurityDescriptorSize = GetSecurityDescriptorLength(SecurityDescriptor);
#if !defined(NDEBUG)
{
PWSTR Sddl;
if (ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor,
SDDL_REVISION_1, DACL_SECURITY_INFORMATION, &Sddl, 0))
{
OutputDebugStringW(Sddl);
LocalFree(Sddl);
}
}
#endif
SecurityDescriptorSize = 0;
if (!MakeSelfRelativeSD(SecurityDescriptor, 0, &SecurityDescriptorSize) &&
ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
Result = FspNtStatusFromWin32(GetLastError());
goto exit;
}
ParamsBuf = malloc(sizeof *ParamsBuf + SecurityDescriptorSize);
if (0 == ParamsBuf)
{
@ -83,6 +106,8 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
if (INVALID_HANDLE_VALUE == DeviceHandle)
{
Result = FspNtStatusFromWin32(GetLastError());
if (STATUS_OBJECT_NAME_NOT_FOUND == Result)
Result = STATUS_NO_SUCH_DEVICE;
goto exit;
}
@ -95,10 +120,15 @@ FSP_API NTSTATUS FspFsctlCreateVolume(PWSTR DevicePath,
}
exit:
if (INVALID_HANDLE_VALUE != DeviceHandle)
CloseHandle(DeviceHandle);
free(SecurityDescriptorBuf);
free(DaclBuf);
if (0 != Token)
CloseHandle(Token);
free(ParamsBuf);
free(DefaultDacl);
return Result;
}
@ -118,6 +148,8 @@ FSP_API NTSTATUS FspFsctlOpenVolume(PWSTR VolumePath,
if (INVALID_HANDLE_VALUE == VolumeHandle)
{
Result = FspNtStatusFromWin32(GetLastError());
if (STATUS_OBJECT_NAME_NOT_FOUND == Result)
Result = STATUS_NO_SUCH_DEVICE;
goto exit;
}

View File

@ -2,15 +2,30 @@
#include <winfsp/fsctl.h>
#include <tlib/testsuite.h>
void mount_invalid_test(void)
{
NTSTATUS Result;
FSP_FSCTL_VOLUME_PARAMS Params = { 0 };
WCHAR VolumePath[MAX_PATH];
HANDLE VolumeHandle;
Params.SectorSize = 16384;
Result = FspFsctlCreateVolume(L"WinFsp.DoesNotExist", &Params, 0, VolumePath, sizeof VolumePath);
ASSERT(STATUS_NO_SUCH_DEVICE == Result);
Result = FspFsctlOpenVolume(L"\\Device\\Volume{31EF947D-B0F3-4A19-A4E7-BE0C1BE94886}.DoesNotExist", &VolumeHandle);
ASSERT(STATUS_NO_SUCH_DEVICE == Result);
}
void mount_dotest(PWSTR DeviceName)
{
NTSTATUS Result;
BOOLEAN Success;
FSP_FSCTL_VOLUME_PARAMS Params;
FSP_FSCTL_VOLUME_PARAMS Params = { 0 };
WCHAR VolumePath[MAX_PATH];
HANDLE VolumeHandle;
Params.SectorSize = (UINT16)65536;
Params.SectorSize = 16384;
Result = FspFsctlCreateVolume(DeviceName, &Params, 0, VolumePath, sizeof VolumePath);
ASSERT(STATUS_SUCCESS == Result);
@ -32,5 +47,6 @@ void mount_test(void)
void mount_tests(void)
{
TEST(mount_invalid_test);
TEST(mount_test);
}