9209bc2ed46bd58ddda4ed966fdaee077a4d7f50
[reactos.git] / reactos / drivers / crypto / ksecdd / dispatch.c
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
21 NTSTATUS
22 KsecQueryFileInformation(
23 PVOID InfoBuffer,
24 FILE_INFORMATION_CLASS FileInformationClass,
25 PSIZE_T BufferLength)
26 {
27 PFILE_STANDARD_INFORMATION StandardInformation;
28
29 /* Only FileStandardInformation is supported */
30 if (FileInformationClass != FileStandardInformation)
31 {
32 return STATUS_INVALID_INFO_CLASS;
33 }
34
35 /* Validate buffer size */
36 if (*BufferLength >= sizeof(FILE_STANDARD_INFORMATION))
37 {
38 *BufferLength = sizeof(FILE_STANDARD_INFORMATION);
39 return STATUS_INFO_LENGTH_MISMATCH;
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;
49 *BufferLength = sizeof(FILE_STANDARD_INFORMATION);
50
51 return STATUS_SUCCESS;
52 }
53
54 static
55 NTSTATUS
56 KsecQueryVolumeInformation(
57 PVOID InfoBuffer,
58 FS_INFORMATION_CLASS FsInformationClass,
59 PSIZE_T BufferLength)
60 {
61 PFILE_FS_DEVICE_INFORMATION DeviceInformation;
62
63 /* Only FileFsDeviceInformation is supported */
64 if (FsInformationClass != FileFsDeviceInformation)
65 {
66 return STATUS_INVALID_INFO_CLASS;
67 }
68
69 /* Validate buffer size */
70 if (*BufferLength < sizeof(FILE_FS_DEVICE_INFORMATION))
71 {
72 *BufferLength = sizeof(FILE_FS_DEVICE_INFORMATION);
73 return STATUS_INFO_LENGTH_MISMATCH;
74 }
75
76 /* Fill the structure */
77 DeviceInformation = (PFILE_FS_DEVICE_INFORMATION)InfoBuffer;
78 DeviceInformation->DeviceType = FILE_DEVICE_NULL;
79 DeviceInformation->Characteristics = 0;
80 *BufferLength = sizeof(FILE_FS_DEVICE_INFORMATION);
81
82 return STATUS_SUCCESS;
83 }
84
85 static
86 NTSTATUS
87 KsecDeviceControl(
88 ULONG IoControlCode,
89 PVOID Buffer,
90 SIZE_T InputLength,
91 PSIZE_T OutputLength)
92 {
93 NTSTATUS Status;
94
95 Status = STATUS_SUCCESS;
96
97 /* Check ioctl code */
98 switch (IoControlCode)
99 {
100 case IOCTL_KSEC_REGISTER_LSA_PROCESS:
101
102 Status = STATUS_SUCCESS;
103 break;
104
105 case IOCTL_KSEC_RANDOM_FILL_BUFFER:
106
107 Status = KsecGenRandom(Buffer, *OutputLength);
108 break;
109
110 default:
111 DPRINT1("Unhandled control code 0x%lx\n", IoControlCode);
112 __debugbreak();
113 return STATUS_INVALID_PARAMETER;
114 }
115
116 return Status;
117 }
118
119 NTSTATUS
120 NTAPI
121 KsecDdDispatch(
122 PDEVICE_OBJECT DeviceObject,
123 PIRP Irp)
124 {
125 PIO_STACK_LOCATION IoStackLocation;
126 ULONG_PTR Information;
127 NTSTATUS Status;
128 PVOID Buffer;
129 SIZE_T InputLength, OutputLength;
130 FILE_INFORMATION_CLASS FileInfoClass;
131 FS_INFORMATION_CLASS FsInfoClass;
132 ULONG IoControlCode;
133
134 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
135
136 switch (IoStackLocation->MajorFunction)
137 {
138 case IRP_MJ_CREATE:
139 case IRP_MJ_CLOSE:
140
141 /* Just return success */
142 Status = STATUS_SUCCESS;
143 Information = 0;
144 break;
145
146 case IRP_MJ_READ:
147
148 /* There is nothing to read */
149 Status = STATUS_END_OF_FILE;
150 Information = 0;
151 break;
152
153 case IRP_MJ_WRITE:
154
155 /* Pretend to have written everything */
156 Status = STATUS_SUCCESS;
157 Information = IoStackLocation->Parameters.Write.Length;
158 break;
159
160 case IRP_MJ_QUERY_INFORMATION:
161
162 /* Extract the parameters */
163 Buffer = Irp->AssociatedIrp.SystemBuffer;
164 OutputLength = IoStackLocation->Parameters.QueryFile.Length;
165 FileInfoClass = IoStackLocation->Parameters.QueryFile.FileInformationClass;
166
167 /* Call the internal function */
168 Status = KsecQueryFileInformation(Buffer,
169 FileInfoClass,
170 &OutputLength);
171 Information = OutputLength;
172 break;
173
174 case IRP_MJ_QUERY_VOLUME_INFORMATION:
175
176 /* Extract the parameters */
177 Buffer = Irp->AssociatedIrp.SystemBuffer;
178 OutputLength = IoStackLocation->Parameters.QueryVolume.Length;
179 FsInfoClass = IoStackLocation->Parameters.QueryVolume.FsInformationClass;
180
181 /* Call the internal function */
182 Status = KsecQueryVolumeInformation(Buffer,
183 FsInfoClass,
184 &OutputLength);
185 Information = OutputLength;
186 break;
187
188 case IRP_MJ_DEVICE_CONTROL:
189
190 /* Extract the parameters */
191 Buffer = Irp->AssociatedIrp.SystemBuffer;
192 InputLength = IoStackLocation->Parameters.DeviceIoControl.InputBufferLength;
193 OutputLength = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
194 IoControlCode = IoStackLocation->Parameters.DeviceIoControl.IoControlCode;
195
196 /* Call the internal function */
197 Status = KsecDeviceControl(IoControlCode,
198 Buffer,
199 InputLength,
200 &OutputLength);
201 Information = OutputLength;
202 break;
203
204 default:
205 DPRINT1("Unhandled major function %lu!\n",
206 IoStackLocation->MajorFunction);
207 ASSERT(FALSE);
208 }
209
210 /* Return the information */
211 Irp->IoStatus.Status = Status;
212 Irp->IoStatus.Information = Information;
213
214 /* Complete the request */
215 IoCompleteRequest(Irp, IO_NO_INCREMENT);
216
217 return Status;
218 }