ReactOS 0.4.16-dev-106-g10b08aa
fltlib.c
Go to the documentation of this file.
1/*
2* PROJECT: Filesystem Filter Manager library
3* LICENSE: GPL - See COPYING in the top level directory
4* FILE: dll/win32/fltlib/fltlib.c
5* PURPOSE:
6* PROGRAMMERS: Ged Murphy (ged.murphy@reactos.org)
7*/
8
9#include <stdarg.h>
10
11#define WIN32_NO_STATUS
12
13#include <windef.h>
14#include <winbase.h>
15
16#define NTOS_MODE_USER
17#include <ndk/iofuncs.h>
18#include <ndk/obfuncs.h>
19#include <ndk/rtlfuncs.h>
20#include <fltmgr_shared.h>
21
22/* DATA ****************************************************************************/
23
24static
27 _In_ BOOL Load);
28
29static
35
36
37/* PUBLIC FUNCTIONS ****************************************************************/
38
42FilterLoad(_In_ LPCWSTR lpFilterName)
43{
44 return FilterLoadUnload(lpFilterName, TRUE);
45}
46
51{
52 return FilterLoadUnload(lpFilterName, FALSE);
53}
54
55
56/* PRIVATE FUNCTIONS ****************************************************************/
57
60{
61 HRESULT hr;
63 if (hr != ERROR_SUCCESS)
64 {
65 hr = (ULONG)hr | 0x80070000;
66 }
67 return hr;
68}
69
70static
73 _In_ BOOL Load)
74{
75 PFILTER_NAME FilterName;
76 HANDLE hFltMgr;
77 SIZE_T StringLength;
79 DWORD dwError;
80
81 /* Get a handle to the filter manager */
82 hFltMgr = CreateFileW(L"\\\\.\\fltmgr",
85 NULL,
88 &hFltMgr);
89 if (hFltMgr == INVALID_HANDLE_VALUE)
90 {
91 dwError = GetLastError();
92 return HRESULT_FROM_WIN32(dwError);
93 }
94
95 /* Calc and allocate a buffer to hold our filter name */
96 StringLength = wcslen(lpFilterName) * sizeof(WCHAR);
97 BufferLength = StringLength + sizeof(FILTER_NAME);
98 FilterName = RtlAllocateHeap(GetProcessHeap(),
99 0,
101 if (FilterName == NULL)
102 {
103 CloseHandle(hFltMgr);
105 }
106
107 /* Build up the filter name */
108 FilterName->Length = StringLength;
109 CopyMemory(FilterName->FilterName, lpFilterName, StringLength);
110
111 /* Tell the filter manager to load the filter for us */
112 dwError = SendIoctl(hFltMgr,
114 FilterName,
116
117 /* Cleanup and bail*/
118 RtlFreeHeap(GetProcessHeap(), 0, FilterName);
119 CloseHandle(hFltMgr);
120
121 return HRESULT_FROM_WIN32(dwError);
122}
123
124static
125DWORD
130{
133
135 NULL,
136 NULL,
137 NULL,
140 lpInBuffer,
142 NULL,
143 0);
144 if (Status == STATUS_PENDING)
145 {
147 if (NT_SUCCESS(Status))
148 {
150 }
151 }
152
154}
155
156BOOL
157WINAPI
161{
162 switch (dwReason)
163 {
166 break;
167 }
168
169 return TRUE;
170}
LONG NTSTATUS
Definition: precomp.h:26
DWORD dwReason
Definition: misc.cpp:141
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD dwReason, _In_ LPVOID lpvReserved)
Definition: fltlib.c:158
static HRESULT FilterLoadUnload(_In_z_ LPCWSTR lpFilterName, _In_ BOOL Load)
Definition: fltlib.c:72
HRESULT NtStatusToHResult(_In_ NTSTATUS Status)
Definition: fltlib.c:59
_Must_inspect_result_ HRESULT WINAPI FilterLoad(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:42
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50
static DWORD SendIoctl(_In_ HANDLE Handle, _In_ ULONG IoControlCode, _In_reads_bytes_opt_(BufferSize) LPVOID lpInBuffer, _In_ DWORD BufferSize)
Definition: fltlib.c:126
#define IOCTL_FILTER_UNLOAD
Definition: fltmgr_shared.h:4
#define IOCTL_FILTER_LOAD
Definition: fltmgr_shared.h:3
struct _FILTER_NAME FILTER_NAME
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
static IN DWORD IN LPVOID lpvReserved
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define _In_z_
Definition: ms_sal.h:313
#define _Must_inspect_result_
Definition: ms_sal.h:558
#define _In_
Definition: ms_sal.h:308
#define _In_reads_bytes_opt_(size)
Definition: ms_sal.h:322
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)
#define GENERIC_WRITE
Definition: nt_native.h:90
#define STATUS_PENDING
Definition: ntstatus.h:82
#define L(x)
Definition: ntvdm.h:50
HRESULT hr
Definition: shlfolder.c:183
WCHAR FilterName[1]
Definition: fltmgr_shared.h:19
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFREQUEST _In_ size_t _In_ size_t _In_ ULONG IoControlCode
Definition: wdfio.h:325
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1710
#define WINAPI
Definition: msvc.h:6
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185