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

View File

@ -2,15 +2,30 @@
#include <winfsp/fsctl.h> #include <winfsp/fsctl.h>
#include <tlib/testsuite.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) void mount_dotest(PWSTR DeviceName)
{ {
NTSTATUS Result; NTSTATUS Result;
BOOLEAN Success; BOOLEAN Success;
FSP_FSCTL_VOLUME_PARAMS Params; FSP_FSCTL_VOLUME_PARAMS Params = { 0 };
WCHAR VolumePath[MAX_PATH]; WCHAR VolumePath[MAX_PATH];
HANDLE VolumeHandle; HANDLE VolumeHandle;
Params.SectorSize = (UINT16)65536; Params.SectorSize = 16384;
Result = FspFsctlCreateVolume(DeviceName, &Params, 0, VolumePath, sizeof VolumePath); Result = FspFsctlCreateVolume(DeviceName, &Params, 0, VolumePath, sizeof VolumePath);
ASSERT(STATUS_SUCCESS == Result); ASSERT(STATUS_SUCCESS == Result);
@ -32,5 +47,6 @@ void mount_test(void)
void mount_tests(void) void mount_tests(void)
{ {
TEST(mount_invalid_test);
TEST(mount_test); TEST(mount_test);
} }