ReactOS  0.4.14-dev-77-gd9e7c48
dispatch.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Drivers
3  * COPYRIGHT: See COPYING in the top level directory
4  * PURPOSE: Kernel Security Support Provider Interface Driver
5  *
6  * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include "ksecdd.h"
12 #include <ksecioctl.h>
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 
18 /* FUNCTIONS ******************************************************************/
19 
20 static
23  PVOID InfoBuffer,
26 {
27  PFILE_STANDARD_INFORMATION StandardInformation;
28 
29  /* Only FileStandardInformation is supported */
31  {
33  }
34 
35  /* Validate buffer size */
37  {
40  }
41 
42  /* Fill the structure */
43  StandardInformation = (PFILE_STANDARD_INFORMATION)InfoBuffer;
44  StandardInformation->AllocationSize.QuadPart = 0;
45  StandardInformation->EndOfFile.QuadPart = 0;
46  StandardInformation->NumberOfLinks = 1;
47  StandardInformation->DeletePending = FALSE;
48  StandardInformation->Directory = FALSE;
50 
51  return STATUS_SUCCESS;
52 }
53 
54 static
57  PVOID InfoBuffer,
60 {
61  PFILE_FS_DEVICE_INFORMATION DeviceInformation;
62 
63  /* Only FileFsDeviceInformation is supported */
65  {
67  }
68 
69  /* Validate buffer size */
71  {
74  }
75 
76  /* Fill the structure */
77  DeviceInformation = (PFILE_FS_DEVICE_INFORMATION)InfoBuffer;
78  DeviceInformation->DeviceType = FILE_DEVICE_NULL;
79  DeviceInformation->Characteristics = 0;
81 
82  return STATUS_SUCCESS;
83 }
84 
85 static
89  PVOID Buffer,
90  SIZE_T InputLength,
91  PSIZE_T OutputLength)
92 {
94 
102  {
103  /* Make sure we have a valid output buffer */
104  if ((Buffer == NULL) || (OutputLength == NULL))
105  {
107  }
108 
109  /* Check if the input is smaller than the output */
110  if (InputLength < *OutputLength)
111  {
112  /* We might have uninitialized memory, zero it out */
113  RtlSecureZeroMemory((PUCHAR)Buffer + InputLength,
114  *OutputLength - InputLength);
115  }
116  }
117 
118  /* Check ioctl code */
119  switch (IoControlCode)
120  {
122 
124  break;
125 
127 
128  Status = KsecGenRandom(Buffer, *OutputLength);
129  break;
130 
132 
134  *OutputLength,
136  break;
137 
139 
141  *OutputLength,
143  break;
144 
146 
148  *OutputLength,
150  break;
151 
153 
155  *OutputLength,
157  break;
158 
160 
162  *OutputLength,
164  break;
165 
167 
169  *OutputLength,
171  break;
172 
173  default:
174  DPRINT1("Unhandled control code 0x%lx\n", IoControlCode);
175  __debugbreak();
177  }
178 
179  return Status;
180 }
181 
182 NTSTATUS
183 NTAPI
186  PIRP Irp)
187 {
188  PIO_STACK_LOCATION IoStackLocation;
191  PVOID Buffer;
192  SIZE_T InputLength, OutputLength;
193  FILE_INFORMATION_CLASS FileInfoClass;
194  FS_INFORMATION_CLASS FsInfoClass;
196 
197  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
198 
199  switch (IoStackLocation->MajorFunction)
200  {
201  case IRP_MJ_CREATE:
202  case IRP_MJ_CLOSE:
203 
204  /* Just return success */
206  Information = 0;
207  break;
208 
209  case IRP_MJ_READ:
210 
211  /* There is nothing to read */
213  Information = 0;
214  break;
215 
216  case IRP_MJ_WRITE:
217 
218  /* Pretend to have written everything */
220  Information = IoStackLocation->Parameters.Write.Length;
221  break;
222 
224 
225  /* Extract the parameters */
226  Buffer = Irp->AssociatedIrp.SystemBuffer;
227  OutputLength = IoStackLocation->Parameters.QueryFile.Length;
228  FileInfoClass = IoStackLocation->Parameters.QueryFile.FileInformationClass;
229 
230  /* Call the internal function */
232  FileInfoClass,
233  &OutputLength);
234  Information = OutputLength;
235  break;
236 
238 
239  /* Extract the parameters */
240  Buffer = Irp->AssociatedIrp.SystemBuffer;
241  OutputLength = IoStackLocation->Parameters.QueryVolume.Length;
242  FsInfoClass = IoStackLocation->Parameters.QueryVolume.FsInformationClass;
243 
244  /* Call the internal function */
246  FsInfoClass,
247  &OutputLength);
248  Information = OutputLength;
249  break;
250 
252 
253  /* Extract the parameters */
254  InputLength = IoStackLocation->Parameters.DeviceIoControl.InputBufferLength;
255  OutputLength = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
256  IoControlCode = IoStackLocation->Parameters.DeviceIoControl.IoControlCode;
257 
258  /* Check for METHOD_OUT_DIRECT method */
260  (OutputLength != 0))
261  {
262  /* Use the provided MDL */
263  OutputLength = Irp->MdlAddress->ByteCount;
266  if (Buffer == NULL)
267  {
269  Information = 0;
270  break;
271  }
272  }
273  else
274  {
275  /* Otherwise this is METHOD_BUFFERED, use the SystemBuffer */
276  Buffer = Irp->AssociatedIrp.SystemBuffer;
277  }
278 
279  /* Call the internal function */
281  Buffer,
282  InputLength,
283  &OutputLength);
284  Information = OutputLength;
285  break;
286 
287  default:
288  DPRINT1("Unhandled major function %lu!\n",
289  IoStackLocation->MajorFunction);
290  ASSERT(FALSE);
292  }
293 
294  /* Return the information */
295  Irp->IoStatus.Status = Status;
296  Irp->IoStatus.Information = Information;
297 
298  /* Complete the request */
300 
301  return Status;
302 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1329
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG IoControlCode
Definition: fltkernel.h:1383
#define IOCTL_KSEC_RANDOM_FILL_BUFFER
Definition: ksecioctl.h:14
#define METHOD_FROM_CTL_CODE(ctrlCode)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define RTL_ENCRYPT_OPTION_CROSS_PROCESS
Definition: ksecdd.h:26
#define IOCTL_KSEC_DECRYPT_CROSS_PROCESS
Definition: ksecioctl.h:30
static NTSTATUS KsecQueryVolumeInformation(PVOID InfoBuffer, FS_INFORMATION_CLASS FsInformationClass, PSIZE_T BufferLength)
Definition: dispatch.c:56
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IOCTL_KSEC_DECRYPT_SAME_PROCESS
Definition: ksecioctl.h:22
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
#define FILE_DEVICE_NULL
Definition: winioctl.h:126
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
#define STATUS_END_OF_FILE
Definition: shellext.h:62
uint32_t ULONG_PTR
Definition: typedefs.h:63
ULONG_PTR * PSIZE_T
Definition: typedefs.h:78
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define IOCTL_KSEC_ENCRYPT_SAME_LOGON
Definition: ksecioctl.h:34
#define IOCTL_KSEC_DECRYPT_SAME_LOGON
Definition: ksecioctl.h:38
#define IOCTL_KSEC_REGISTER_LSA_PROCESS
Definition: ksecioctl.h:6
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
Definition: bufpool.h:45
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
enum _FSINFOCLASS FS_INFORMATION_CLASS
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
#define METHOD_OUT_DIRECT
Definition: nt_native.h:596
NTSTATUS NTAPI KsecDdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: dispatch.c:184
LARGE_INTEGER AllocationSize
Definition: propsheet.cpp:54
#define RTL_ENCRYPT_OPTION_SAME_PROCESS
Definition: ksecdd.h:25
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
#define FILE_STANDARD_INFORMATION
Definition: disk.h:54
struct _FILE_FS_DEVICE_INFORMATION FILE_FS_DEVICE_INFORMATION
#define RTL_ENCRYPT_OPTION_SAME_LOGON
Definition: ksecdd.h:27
struct _FILE_STANDARD_INFORMATION * PFILE_STANDARD_INFORMATION
Status
Definition: gdiplustypes.h:24
#define IOCTL_KSEC_ENCRYPT_SAME_PROCESS
Definition: ksecioctl.h:18
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS NTAPI KsecEncryptMemory(_Inout_ PVOID Buffer, _In_ ULONG Length, _In_ ULONG OptionFlags)
Definition: crypt.c:267
static NTSTATUS KsecQueryFileInformation(PVOID InfoBuffer, FILE_INFORMATION_CLASS FileInformationClass, PSIZE_T BufferLength)
Definition: dispatch.c:22
#define DPRINT1
Definition: precomp.h:8
#define FileStandardInformation
Definition: propsheet.cpp:61
#define IRP_MJ_READ
Definition: rdpdr.c:46
struct _FILE_FS_DEVICE_INFORMATION * PFILE_FS_DEVICE_INFORMATION
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
NTSTATUS NTAPI KsecGenRandom(PVOID Buffer, SIZE_T Length)
Definition: random.c:26
static NTSTATUS KsecDeviceControl(ULONG IoControlCode, PVOID Buffer, SIZE_T InputLength, PSIZE_T OutputLength)
Definition: dispatch.c:87
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
FORCEINLINE PVOID RtlSecureZeroMemory(_Out_writes_bytes_all_(Size) PVOID Pointer, _In_ SIZE_T Size)
Definition: rtlfuncs.h:3127
Iosb Information
Definition: create.c:4377
NTSTATUS NTAPI KsecDecryptMemory(_Inout_ PVOID Buffer, _In_ ULONG Length, _In_ ULONG OptionFlags)
Definition: crypt.c:302
LONGLONG QuadPart
Definition: typedefs.h:112
#define IOCTL_KSEC_ENCRYPT_CROSS_PROCESS
Definition: ksecioctl.h:26
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52