2 * PROJECT: Filesystem Filter Manager library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/fltlib/fltlib.c
6 * PROGRAMMERS: Ged Murphy (ged.murphy@reactos.org)
11 #define WIN32_NO_STATUS
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>
22 #include "wine/debug.h"
25 /* DATA ****************************************************************************/
27 WINE_DEFAULT_DEBUG_CHANNEL(fltlib
);
31 FilterLoadUnload(_In_z_ LPCWSTR lpFilterName
,
36 SendIoctl(_In_ HANDLE Handle
,
37 _In_ ULONG IoControlCode
,
38 _In_reads_bytes_opt_(BufferSize
) LPVOID lpInBuffer
,
39 _In_ DWORD BufferSize
);
42 /* PUBLIC FUNCTIONS ****************************************************************/
47 FilterLoad(_In_ LPCWSTR lpFilterName
)
49 return FilterLoadUnload(lpFilterName
, TRUE
);
55 FilterUnload(_In_ LPCWSTR lpFilterName
)
57 return FilterLoadUnload(lpFilterName
, FALSE
);
61 /* PRIVATE FUNCTIONS ****************************************************************/
64 NtStatusToHResult(_In_ NTSTATUS Status
)
67 hr
= RtlNtStatusToDosError(Status
);
68 if (hr
!= ERROR_SUCCESS
)
70 hr
= (ULONG
)hr
| 0x80070000;
77 FilterLoadUnload(_In_z_ LPCWSTR lpFilterName
,
80 PFILTER_NAME FilterName
;
86 /* Get a handle to the filter manager */
87 hFltMgr
= CreateFileW(L
"\\\\.\\fltmgr",
92 FILE_ATTRIBUTE_NORMAL
,
94 if (hFltMgr
== INVALID_HANDLE_VALUE
)
96 dwError
= GetLastError();
97 return HRESULT_FROM_WIN32(dwError
);
100 /* Calc and allocate a buffer to hold our filter name */
101 StringLength
= wcslen(lpFilterName
) * sizeof(WCHAR
);
102 BufferLength
= StringLength
+ sizeof(FILTER_NAME
);
103 FilterName
= RtlAllocateHeap(GetProcessHeap(),
106 if (FilterName
== NULL
)
108 CloseHandle(hFltMgr
);
109 return HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY
);
112 /* Build up the filter name */
113 FilterName
->Length
= StringLength
;
114 CopyMemory(FilterName
->FilterName
, lpFilterName
, StringLength
);
116 /* Tell the filter manager to load the filter for us */
117 dwError
= SendIoctl(hFltMgr
,
118 Load
? IOCTL_FILTER_LOAD
: IOCTL_FILTER_UNLOAD
,
122 /* Cleanup and bail*/
123 RtlFreeHeap(GetProcessHeap(), 0, FilterName
);
124 CloseHandle(hFltMgr
);
126 return HRESULT_FROM_WIN32(dwError
);
131 SendIoctl(_In_ HANDLE Handle
,
132 _In_ ULONG IoControlCode
,
133 _In_reads_bytes_opt_(BufferSize
) LPVOID lpInBuffer
,
134 _In_ DWORD BufferSize
)
136 IO_STATUS_BLOCK IoStatusBlock
;
139 Status
= NtDeviceIoControlFile(Handle
,
149 if (Status
== STATUS_PENDING
)
151 Status
= NtWaitForSingleObject(Handle
, FALSE
, NULL
);
152 if (NT_SUCCESS(Status
))
154 Status
= IoStatusBlock
.Status
;
158 return RtlNtStatusToDosError(Status
);
163 DllMain(_In_ HINSTANCE hinstDLL
,
165 _In_ LPVOID lpvReserved
)
169 case DLL_PROCESS_ATTACH
:
170 DisableThreadLibraryCalls(hinstDLL
);