Start to implement fltmgr tests [WIP] (#52)

[FLTMGR]
- Partially implement registering contexts
- Add a misc file which contains stubs of the APIs needed in the test suite
- Export some APIs needed by the test suite

[KMTESTS]
- Create a File System Mini-filter wrapper to host drivers for the filter manager tests
- Add a test file which will be used for testing that mini-filters load correctly
- Add a test file which will be used to write tests for IRP_MJ_CREATE requests
This commit is contained in:
Ged Murphy 2017-10-12 15:32:30 +01:00 committed by GitHub
parent 5d0a122ff6
commit 9d15fb9279
16 changed files with 1139 additions and 8 deletions

View file

@ -1,2 +1,2 @@
#add_subdirectory(fltmgr)
add_subdirectory(fltmgr)
add_subdirectory(mountmgr)

View file

@ -5,6 +5,7 @@ list(APPEND SOURCE
Interface.c
Lib.c
Messaging.c
Misc.c
Object.c
${CMAKE_CURRENT_BINARY_DIR}/fltmgr.def
fltmgr.h)

View file

@ -27,7 +27,7 @@ static
NTSTATUS
SetupContextHeader(
_In_ PFLT_FILTER Filter,
_In_ PFLT_CONTEXT_REGISTRATION ContextPtr,
_In_ PCFLT_CONTEXT_REGISTRATION ContextPtr,
_Out_ PALLOCATE_CONTEXT_HEADER ContextHeader
);
@ -43,9 +43,102 @@ NTSTATUS
FltpRegisterContexts(_In_ PFLT_FILTER Filter,
_In_ const FLT_CONTEXT_REGISTRATION *Context)
{
UNREFERENCED_PARAMETER(Filter);
UNREFERENCED_PARAMETER(Context);
return STATUS_NOT_IMPLEMENTED;
PCFLT_CONTEXT_REGISTRATION ContextPtr;
PALLOCATE_CONTEXT_HEADER ContextHeader, Prev;
PVOID Buffer;
ULONG BufferSize = 0;
USHORT i;
NTSTATUS Status;
/* Loop through all entries in the context registration array */
ContextPtr = Context;
while (ContextPtr)
{
/* Bail if we found the terminator */
if (ContextPtr->ContextType == FLT_CONTEXT_END)
break;
/* Make sure we have a valid context */
if (IsContextTypeValid(ContextPtr->ContextType))
{
/* Each context is backed by a crtl struct. Reserve space for it */
BufferSize += sizeof(STREAM_LIST_CTRL);
}
/* Move to the next entry */
ContextPtr++;
}
/* Bail if we found no valid registration requests */
if (BufferSize == 0)
{
return STATUS_SUCCESS;
}
/* Allocate the pool that'll hold the context crtl structs */
Buffer = ExAllocatePoolWithTag(NonPagedPool, BufferSize, FM_TAG_CONTEXT_REGISTA);
if (!Buffer) return STATUS_INSUFFICIENT_RESOURCES;
RtlZeroMemory(Buffer, BufferSize);
/* Setup our loop data */
ContextHeader = Buffer;
Prev = NULL;
Status = STATUS_SUCCESS;
for (i = 0; i < MAX_CONTEXT_TYPES; i++)
{
ContextPtr = (PFLT_CONTEXT_REGISTRATION)Context;
while (ContextPtr)
{
/* We don't support variable sized contents yet */
FLT_ASSERT(ContextPtr->Size != FLT_VARIABLE_SIZED_CONTEXTS);
/* Bail if we found the terminator */
if (ContextPtr->ContextType == FLT_CONTEXT_END)
break;
/* Size and pooltag are only checked when ContextAllocateCallback is null */
if (ContextPtr->ContextAllocateCallback == FALSE && ContextPtr->PoolTag == FALSE)
{
Status = STATUS_FLT_INVALID_CONTEXT_REGISTRATION;
goto Quit;
}
/* Make sure we have a valid context */
if (IsContextTypeValid(ContextPtr->ContextType))
{
Status = SetupContextHeader(Filter, ContextPtr, ContextHeader);
if (NT_SUCCESS(Status))
{
if (Prev)
{
Prev->Next = ContextHeader;
}
Filter->SupportedContexts[i] = ContextHeader;
}
}
Prev = ContextHeader;
/* Move to the next entry */
ContextPtr++;
}
}
Quit:
if (NT_SUCCESS(Status))
{
Filter->SupportedContextsListHead = Buffer;
}
else
{
ExFreePoolWithTag(Buffer, FM_TAG_CONTEXT_REGISTA);
//FIXME: Cleanup anything that SetupContextHeader may have allocated
}
return Status;
}
@ -72,7 +165,7 @@ IsContextTypeValid(_In_ FLT_CONTEXT_TYPE ContextType)
static
NTSTATUS
SetupContextHeader(_In_ PFLT_FILTER Filter,
_In_ PFLT_CONTEXT_REGISTRATION ContextPtr,
_In_ PCFLT_CONTEXT_REGISTRATION ContextPtr,
_Out_ PALLOCATE_CONTEXT_HEADER ContextHeader)
{
return 0;

View file

@ -17,6 +17,18 @@
/* DATA *********************************************************************/
#define VALID_FAST_IO_DISPATCH_HANDLER(_FastIoDispatchPtr, _FieldName) \
(((_FastIoDispatchPtr) != NULL) && \
(((_FastIoDispatchPtr)->SizeOfFastIoDispatch) >= \
(FIELD_OFFSET(FAST_IO_DISPATCH, _FieldName) + sizeof(void *))) && \
((_FastIoDispatchPtr)->_FieldName != NULL))
#define IS_MY_DEVICE_OBJECT(_devObj) \
(((_devObj) != NULL) && \
((_devObj)->DriverObject == Dispatcher::DriverObject) && \
((_devObj)->DeviceExtension != NULL))
DRIVER_INITIALIZE DriverEntry;
NTSTATUS
NTAPI

View file

@ -125,7 +125,7 @@ FltCreateCommunicationPort(_In_ PFLT_FILTER Filter,
FltObjectDereference(Filter);
}
return STATUS_NOT_IMPLEMENTED;
return Status;
}
_IRQL_requires_max_(PASSIVE_LEVEL)

View file

@ -0,0 +1,56 @@
/*
* PROJECT: Filesystem Filter Manager
* LICENSE: GPL - See COPYING in the top level directory
* FILE: drivers/filters/fltmgr/Misc.c
* PURPOSE: Uncataloged functions
* PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include "fltmgr.h"
#include "fltmgrint.h"
#define NDEBUG
#include <debug.h>
/* DATA *********************************************************************/
/* EXPORTED FUNCTIONS ******************************************************/
NTSTATUS
FLTAPI
FltBuildDefaultSecurityDescriptor(
_Outptr_ PSECURITY_DESCRIPTOR *SecurityDescriptor,
_In_ ACCESS_MASK DesiredAccess
)
{
UNREFERENCED_PARAMETER(SecurityDescriptor);
UNREFERENCED_PARAMETER(DesiredAccess);
return 0;
}
VOID
FLTAPI
FltFreeSecurityDescriptor(
_In_ PSECURITY_DESCRIPTOR SecurityDescriptor
)
{
UNREFERENCED_PARAMETER(SecurityDescriptor);
}
NTSTATUS
FLTAPI
FltGetDiskDeviceObject(
_In_ PFLT_VOLUME Volume,
_Outptr_ PDEVICE_OBJECT *DiskDeviceObject
)
{
UNREFERENCED_PARAMETER(Volume);
UNREFERENCED_PARAMETER(DiskDeviceObject);
return 0;
}

View file

@ -2,4 +2,9 @@
@ stdcall FltRegisterFilter(ptr ptr ptr)
@ stdcall FltUnregisterFilter(ptr)
@ stdcall FltCloseCommunicationPort(ptr)
@ stdcall FltStartFiltering(ptr)
@ stdcall FltCreateCommunicationPort(ptr ptr ptr ptr ptr ptr ptr long)
@ stdcall FltBuildDefaultSecurityDescriptor(ptr long)
@ stdcall FltFreeSecurityDescriptor(ptr)
@ stdcall FltGetDiskDeviceObject(ptr ptr)