ReactOS  0.4.14-dev-342-gdc047f9
filter.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: File system filter implementation of the original service.c file
5  * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6  * Ged Murphy <gedmurphy@reactos.org>
7  */
8 
9 //#include <fltuser.h>
10 #include <kmt_test.h>
11 #include "kmtest.h"
12 
13 #include <assert.h>
14 
15 #define SERVICE_ACCESS (SERVICE_START | SERVICE_STOP | DELETE)
16 
17 
18 
29 DWORD
32 {
33  HRESULT hResult;
35 
37 
38  hResult = FilterLoad(ServiceName);
39  Error = SCODE_CODE(hResult);
40 
41  return Error;
42 }
43 #if 0
44 
62 DWORD
63 KmtFltCreateAndStartService(
65  _In_z_ PCWSTR ServicePath,
66  _In_z_ PCWSTR DisplayName OPTIONAL,
67  _Out_ SC_HANDLE *ServiceHandle,
68  _In_ BOOLEAN RestartIfRunning)
69 {
71 
72  assert(ServiceHandle);
73 
74  Error = KmtFltCreateService(ServiceName, ServicePath, DisplayName, ServiceHandle);
75 
77  *ServiceHandle = OpenService(ScmHandle, ServiceName, SERVICE_ACCESS);
78 
80  goto cleanup;
81 
83 
85  goto cleanup;
86 
88 
89  if (!RestartIfRunning)
90  goto cleanup;
91 
93  if (Error)
94  goto cleanup;
95 
97  if (Error)
98  goto cleanup;
99 
100 cleanup:
101  assert(Error);
102  return Error;
103 }
104 #endif
105 
118 DWORD
121  _Out_ HANDLE *hPort)
122 {
123  HRESULT hResult;
124  DWORD Error;
125 
127  assert(hPort);
128 
130  0,
131  NULL,
132  0,
133  NULL,
134  hPort);
135  Error = SCODE_CODE(hResult);
136 
137  return Error;
138 }
139 
150 DWORD
152  _In_ HANDLE hPort)
153 {
155 
156  assert(hPort);
157 
158  if (!CloseHandle(hPort))
159  {
160  Error = GetLastError();
161  }
162 
163  return Error;
164 }
165 
186 DWORD
188  _In_ HANDLE hPort,
189  _In_reads_bytes_(dwInBufferSize) LPVOID InBuffer,
191  _Out_writes_bytes_to_opt_(dutBufferSize, *BytesReturned) LPVOID OutBuffer,
194 {
195  DWORD BytesRet;
196  HRESULT hResult;
197  DWORD Error;
198 
199  assert(hPort);
200  assert(InBuffer);
202 
203  if (BytesReturned) *BytesReturned = 0;
204 
205  hResult = FilterSendMessage(hPort,
206  InBuffer,
207  InBufferSize,
208  OutBuffer,
210  &BytesRet);
211 
212  Error = SCODE_CODE(hResult);
213  if (Error == ERROR_SUCCESS)
214  {
215  if (BytesRet)
216  {
217  *BytesReturned = BytesRet;
218  }
219  }
220 
221  return Error;
222 }
223 
240 DWORD
242  _In_ HANDLE hPort,
243  _Out_writes_bytes_(MessageBufferSize) PFILTER_MESSAGE_HEADER MessageBuffer,
244  _In_ DWORD MessageBufferSize,
245  _In_opt_ LPOVERLAPPED Overlapped)
246 {
247  HRESULT hResult;
248  DWORD Error;
249 
250  assert(hPort);
251  assert(MessageBuffer);
252 
253  hResult = FilterGetMessage(hPort,
254  MessageBuffer,
255  MessageBufferSize,
256  Overlapped);
257  Error = SCODE_CODE(hResult);
258  return Error;
259 }
260 
275 DWORD
277  _In_ HANDLE hPort,
278  _In_reads_bytes_(ReplyBufferSize) PFILTER_REPLY_HEADER ReplyBuffer,
279  _In_ DWORD ReplyBufferSize)
280 {
281  HRESULT hResult;
282  DWORD Error;
283 
284  hResult = FilterReplyMessage(hPort,
285  ReplyBuffer,
286  ReplyBufferSize);
287  Error = SCODE_CODE(hResult);
288  return Error;
289 }
290 
305 DWORD
307  _In_ HANDLE hPort,
308  _In_ LPOVERLAPPED Overlapped,
309  _Out_ LPDWORD BytesTransferred)
310 {
311  BOOL Success;
313 
314  *BytesTransferred = 0;
315 
316  Success = GetOverlappedResult(hPort, Overlapped, BytesTransferred, TRUE);
317  if (!Success)
318  {
319  Error = GetLastError();
320  }
321 
322  return Error;
323 }
324 
335 DWORD
338 {
339  HRESULT hResult;
341 
343 
344  hResult = FilterUnload(ServiceName);
345  Error = SCODE_CODE(hResult);
346 
347  return Error;
348 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD KmtFltSendMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID InBuffer, _In_ DWORD InBufferSize, _Out_writes_bytes_to_opt_(dutBufferSize, *BytesReturned) LPVOID OutBuffer, _In_ DWORD OutBufferSize, _Out_opt_ LPDWORD BytesReturned)
Definition: filter.c:187
#define _Out_writes_bytes_to_opt_(size, count)
Definition: no_sal2.h:375
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
#define SERVICE_ACCESS
Definition: filter.c:15
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
_Must_inspect_result_ HRESULT WINAPI FilterUnload(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:50
_Must_inspect_result_ HRESULT WINAPI FilterSendMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwInBufferSize) LPVOID lpInBuffer, _In_ DWORD dwInBufferSize, _Out_writes_bytes_to_opt_(dwOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer, _In_ DWORD dwOutBufferSize, _Out_ LPDWORD lpBytesReturned)
Definition: message.c:131
DWORD KmtFltCreateService(_In_z_ PCWSTR ServiceName, _In_z_ PCWSTR DisplayName, _Out_ SC_HANDLE *ServiceHandle)
Definition: fltsupport.c:63
#define OpenService
Definition: winsvc.h:576
#define _In_opt_
Definition: no_sal2.h:213
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define _Out_writes_bytes_(size)
Definition: no_sal2.h:370
#define _Out_
Definition: no_sal2.h:323
DWORD KmtFltGetMessageResult(_In_ HANDLE hPort, _In_ LPOVERLAPPED Overlapped, _Out_ LPDWORD BytesTransferred)
Definition: filter.c:306
_Must_inspect_result_ HRESULT WINAPI FilterConnectCommunicationPort(_In_ LPCWSTR lpPortName, _In_ DWORD dwOptions, _In_reads_bytes_opt_(wSizeOfContext) LPCVOID lpContext, _In_ WORD wSizeOfContext, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Outptr_ HANDLE *hPort)
Definition: message.c:25
_Must_inspect_result_ HRESULT WINAPI FilterGetMessage(_In_ HANDLE hPort, _Out_writes_bytes_(dwMessageBufferSize) PFILTER_MESSAGE_HEADER lpMessageBuffer, _In_ DWORD dwMessageBufferSize, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: message.c:150
#define _Out_opt_
Definition: no_sal2.h:339
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG InBufferSize
Definition: classpnp.h:429
LPTSTR ServiceName
Definition: ServiceMain.c:15
LONG HRESULT
Definition: typedefs.h:77
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
DWORD KmtFltLoad(_In_z_ PCWSTR ServiceName)
Definition: filter.c:30
_Must_inspect_result_ _In_ PFLT_PORT _In_ ULONG _Out_writes_bytes_opt_ ReplyLength PVOID ReplyBuffer
Definition: fltkernel.h:1903
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
DWORD KmtFltReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(ReplyBufferSize) PFILTER_REPLY_HEADER ReplyBuffer, _In_ DWORD ReplyBufferSize)
Definition: filter.c:276
#define _In_reads_bytes_(size)
Definition: no_sal2.h:229
#define _In_
Definition: no_sal2.h:204
#define _In_z_
Definition: no_sal2.h:239
DWORD KmtFltGetMessage(_In_ HANDLE hPort, _Out_writes_bytes_(MessageBufferSize) PFILTER_MESSAGE_HEADER MessageBuffer, _In_ DWORD MessageBufferSize, _In_opt_ LPOVERLAPPED Overlapped)
Definition: filter.c:241
_In_ FILTER_INFORMATION_CLASS _In_ ULONG _Out_ PULONG BytesReturned
Definition: fltkernel.h:1716
#define SCODE_CODE(sc)
Definition: winerror.h:77
uint32_t * LPDWORD
Definition: typedefs.h:57
DWORD KmtFltUnload(_In_z_ PCWSTR ServiceName)
Definition: filter.c:336
char * cleanup(char *str)
Definition: wpickclick.c:99
DWORD KmtFltConnect(_In_z_ PCWSTR ServiceName, _Out_ HANDLE *hPort)
Definition: filter.c:119
_Must_inspect_result_ HRESULT WINAPI FilterReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwReplyBufferSize) PFILTER_REPLY_HEADER lpReplyBuffer, _In_ DWORD dwReplyBufferSize)
Definition: message.c:165
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
_Must_inspect_result_ HRESULT WINAPI FilterLoad(_In_ LPCWSTR lpFilterName)
Definition: fltlib.c:42
DWORD KmtFltDisconnect(_In_ HANDLE hPort)
Definition: filter.c:151
static SC_HANDLE ScmHandle
Definition: service.c:30
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68