ReactOS  0.4.13-dev-257-gfabbd7c
message.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/message.c
5 * PURPOSE: Handles messaging to and from the filter manager
6 * PROGRAMMERS: Ged Murphy (ged.murphy@reactos.org)
7 */
8 
9 #define WIN32_NO_STATUS
10 #include <windef.h>
11 #include <winbase.h>
12 
13 #define NTOS_MODE_USER
14 #include <ndk/iofuncs.h>
15 #include <ndk/obfuncs.h>
16 #include <ndk/rtlfuncs.h>
17 #include <fltuser.h>
18 #include <fltmgr_shared.h>
19 
20 #include "fltlib.h"
21 
23 HRESULT
24 WINAPI
27  _In_reads_bytes_opt_(wSizeOfContext) LPCVOID lpContext,
28  _In_ WORD wSizeOfContext,
29  _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
30  _Outptr_ HANDLE *hPort)
31 {
34  PFILTER_PORT_DATA PortData;
38  SIZE_T PortNameSize;
40  PCHAR Ptr;
42  HRESULT hr;
43 
44  *hPort = INVALID_HANDLE_VALUE;
45 
46  /* Sanity check */
47  if (lpContext && wSizeOfContext == 0)
48  {
49  return E_INVALIDARG;
50  }
51 
52  /* Get the length of the port name */
53  PortNameSize = wcslen(lpPortName) * sizeof(WCHAR);
54 
55  /* Calculate and allocate the size of the required buffer */
56  BufferSize = sizeof(FILTER_PORT_DATA) + PortNameSize + wSizeOfContext;
57  PortData = RtlAllocateHeap(GetProcessHeap(), 0, BufferSize);
58  if (PortData == NULL) return E_OUTOFMEMORY;
59 
60  /* Clear out the buffer and find the end of the fixed struct */
61  RtlZeroMemory(PortData, BufferSize);
62  Ptr = (PCHAR)(PortData + 1);
63 
64  PortData->Size = BufferSize;
65  PortData->Options = dwOptions;
66 
67  /* Setup the port name */
68  RtlInitUnicodeString(&PortName, lpPortName);
69  PortData->PortName.Buffer = (PWCH)Ptr;
70  PortData->PortName.MaximumLength = PortNameSize;
72  Ptr += PortData->PortName.Length;
73 
74  /* Check if we were given a context */
75  if (lpContext)
76  {
77  /* Add that into the buffer too */
78  PortData->Context = Ptr;
79  RtlCopyMemory(PortData->Context, lpContext, wSizeOfContext);
80  }
81 
82  /* Initialize the object attributes */
83  RtlInitUnicodeString(&DeviceName, L"\\Global??\\FltMgrMsg");
85  &DeviceName,
87  NULL,
88  NULL);
89 
90  /* Check if we were passed any security attributes */
91  if (lpSecurityAttributes)
92  {
93  /* Add these manually and update the flags if we were asked to make it inheritable */
94  ObjectAttributes.SecurityDescriptor = lpSecurityAttributes->lpSecurityDescriptor;
95  if (lpSecurityAttributes->bInheritHandle)
96  {
97  ObjectAttributes.Attributes |= OBJ_INHERIT;
98  }
99  }
100 
101  /* Now get a handle to the device */
105  &IoStatusBlock,
106  0,
107  0,
108  0,
109  FILE_OPEN_IF,
110  0,
111  PortData,
112  BufferSize);
113  if (NT_SUCCESS(Status))
114  {
115  *hPort = FileHandle;
116  hr = S_OK;
117  }
118  else
119  {
121  }
122 
123  /* Cleanup and return */
124  RtlFreeHeap(GetProcessHeap(), 0, PortData);
125  return hr;
126 }
127 
129 HRESULT
130 WINAPI
132  _In_reads_bytes_(dwInBufferSize) LPVOID lpInBuffer,
133  _In_ DWORD dwInBufferSize,
134  _Out_writes_bytes_to_opt_(dwOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer,
135  _In_ DWORD dwOutBufferSize,
137 {
138  UNREFERENCED_PARAMETER(hPort);
139  UNREFERENCED_PARAMETER(lpInBuffer);
140  UNREFERENCED_PARAMETER(dwInBufferSize);
141  UNREFERENCED_PARAMETER(lpOutBuffer);
142  UNREFERENCED_PARAMETER(dwOutBufferSize);
144  return E_NOTIMPL;
145 }
146 
148 HRESULT
149 WINAPI
151  _Out_writes_bytes_(dwMessageBufferSize) PFILTER_MESSAGE_HEADER lpMessageBuffer,
152  _In_ DWORD dwMessageBufferSize,
154 {
155  UNREFERENCED_PARAMETER(hPort);
156  UNREFERENCED_PARAMETER(lpMessageBuffer);
157  UNREFERENCED_PARAMETER(dwMessageBufferSize);
159  return E_NOTIMPL;
160 }
161 
163 HRESULT
164 WINAPI
166  _In_reads_bytes_(dwReplyBufferSize) PFILTER_REPLY_HEADER lpReplyBuffer,
167  _In_ DWORD dwReplyBufferSize)
168 {
169  UNREFERENCED_PARAMETER(hPort);
170  UNREFERENCED_PARAMETER(lpReplyBuffer);
171  UNREFERENCED_PARAMETER(dwReplyBufferSize);
172  return E_NOTIMPL;
173 }
signed char * PCHAR
Definition: retypes.h:7
DWORD dwOptions
Definition: solitaire.cpp:23
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define _Must_inspect_result_
Definition: no_sal2.h:314
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define FILE_OPEN_IF
Definition: from_kernel.h:56
HRESULT hr
Definition: shlfolder.c:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define _Out_writes_bytes_to_opt_(size, count)
Definition: no_sal2.h:375
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define _In_reads_bytes_opt_(size)
Definition: no_sal2.h:230
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
HRESULT NtStatusToHResult(_In_ NTSTATUS Status)
Definition: fltlib.c:59
#define _Outptr_
Definition: no_sal2.h:396
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_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
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define _In_opt_
Definition: no_sal2.h:213
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
HANDLE FileHandle
Definition: stats.c:38
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define FILE_READ_DATA
Definition: nt_native.h:628
#define E_INVALIDARG
Definition: ddrawi.h:101
smooth NULL
Definition: ftsmooth.c:416
#define _Out_writes_bytes_(size)
Definition: no_sal2.h:370
#define _Out_
Definition: no_sal2.h:323
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define PCHAR
Definition: match.c:90
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
_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 GetProcessHeap()
Definition: compat.h:395
NTSTATUS NTAPI NtCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG CreateDisposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LONG HRESULT
Definition: typedefs.h:77
#define OBJ_INHERIT
Definition: winternl.h:225
#define WINAPI
Definition: msvc.h:8
#define BufferSize
Definition: classpnp.h:419
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
WCHAR * PWCH
Definition: ntbasedef.h:417
static const WCHAR L[]
Definition: oid.c:1250
#define SYNCHRONIZE
Definition: nt_native.h:61
#define _In_reads_bytes_(size)
Definition: no_sal2.h:229
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define S_OK
Definition: intsafe.h:59
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
#define E_NOTIMPL
Definition: ddrawi.h:99
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
_In_ DWORD _In_ DWORD _In_ DWORD _Out_ LPDWORD lpBytesReturned
Definition: winddi.h:1704
CONST void * LPCVOID
Definition: windef.h:191
uint32_t * LPDWORD
Definition: typedefs.h:57
UNICODE_STRING PortName
Definition: fltmgr_shared.h:28
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ HRESULT WINAPI FilterReplyMessage(_In_ HANDLE hPort, _In_reads_bytes_(dwReplyBufferSize) PFILTER_REPLY_HEADER lpReplyBuffer, _In_ DWORD dwReplyBufferSize)
Definition: message.c:165
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define _Inout_opt_
Definition: no_sal2.h:258
struct _FILTER_PORT_DATA FILTER_PORT_DATA
IN PUNICODE_STRING PortName
Definition: conport.c:35