ReactOS  0.4.14-dev-41-g31d7680
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 
24 static
25 HRESULT
26 FilterLoadUnload(_In_z_ LPCWSTR lpFilterName,
27  _In_ BOOL Load);
28 
29 static
30 DWORD
35 
36 
37 /* PUBLIC FUNCTIONS ****************************************************************/
38 
40 HRESULT
41 WINAPI
42 FilterLoad(_In_ LPCWSTR lpFilterName)
43 {
44  return FilterLoadUnload(lpFilterName, TRUE);
45 }
46 
48 HRESULT
49 WINAPI
50 FilterUnload(_In_ LPCWSTR lpFilterName)
51 {
52  return FilterLoadUnload(lpFilterName, FALSE);
53 }
54 
55 
56 /* PRIVATE FUNCTIONS ****************************************************************/
57 
58 HRESULT
60 {
61  HRESULT hr;
63  if (hr != ERROR_SUCCESS)
64  {
65  hr = (ULONG)hr | 0x80070000;
66  }
67  return hr;
68 }
69 
70 static
71 HRESULT
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,
100  BufferLength);
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,
115  BufferLength);
116 
117  /* Cleanup and bail*/
118  RtlFreeHeap(GetProcessHeap(), 0, FilterName);
119  CloseHandle(hFltMgr);
120 
121  return HRESULT_FROM_WIN32(dwError);
122 }
123 
124 static
125 DWORD
130 {
133 
135  NULL,
136  NULL,
137  NULL,
138  &IoStatusBlock,
140  lpInBuffer,
141  BufferSize,
142  NULL,
143  0);
144  if (Status == STATUS_PENDING)
145  {
147  if (NT_SUCCESS(Status))
148  {
150  }
151  }
152 
154 }
155 
156 BOOL
157 WINAPI
161 {
162  switch (dwReason)
163  {
164  case DLL_PROCESS_ATTACH:
165  DisableThreadLibraryCalls(hinstDLL);
166  break;
167  }
168 
169  return TRUE;
170 }
#define _Must_inspect_result_
Definition: no_sal2.h:314
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define _In_reads_bytes_opt_(size)
Definition: no_sal2.h:230
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
HRESULT NtStatusToHResult(_In_ NTSTATUS Status)
Definition: fltlib.c:59
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
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)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
static IN DWORD IN LPVOID lpvReserved
#define IOCTL_FILTER_UNLOAD
Definition: fltmgr_shared.h:4
DWORD dwReason
Definition: misc.cpp:154
BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD dwReason, _In_ LPVOID lpvReserved)
Definition: fltlib.c:158
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
_In_ HANDLE Handle
Definition: extypes.h:390
#define GetProcessHeap()
Definition: compat.h:395
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:8
#define CopyMemory
Definition: winbase.h:1633
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
static HRESULT FilterLoadUnload(_In_z_ LPCWSTR lpFilterName, _In_ BOOL Load)
Definition: fltlib.c:72
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
struct _FILTER_NAME FILTER_NAME
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define _In_
Definition: no_sal2.h:204
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define _In_z_
Definition: no_sal2.h:239
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static DWORD SendIoctl(_In_ HANDLE Handle, _In_ ULONG IoControlCode, _In_reads_bytes_opt_(BufferSize) LPVOID lpInBuffer, _In_ DWORD BufferSize)
Definition: fltlib.c:126
#define CreateFileW
Definition: compat.h:400
unsigned int ULONG
Definition: retypes.h:1
_Must_inspect_result_ HRESULT WINAPI FilterLoad(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:42
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IOCTL_FILTER_LOAD
Definition: fltmgr_shared.h:3
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
NTSYSAPI NTSTATUS NTAPI NtWaitForSingleObject(IN HANDLE hObject, IN BOOLEAN bAlertable, IN PLARGE_INTEGER Timeout)