2 * PROJECT: ReactOS Drivers
3 * COPYRIGHT: See COPYING in the top level directory
4 * PURPOSE: Kernel Security Support Provider Interface Driver
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
9 /* INCLUDES *******************************************************************/
12 #include <ksecioctl.h>
18 /* FUNCTIONS ******************************************************************/
22 KsecQueryFileInformation(
24 FILE_INFORMATION_CLASS FileInformationClass
,
27 PFILE_STANDARD_INFORMATION StandardInformation
;
29 /* Only FileStandardInformation is supported */
30 if (FileInformationClass
!= FileStandardInformation
)
32 return STATUS_INVALID_INFO_CLASS
;
35 /* Validate buffer size */
36 if (*BufferLength
< sizeof(FILE_STANDARD_INFORMATION
))
38 *BufferLength
= sizeof(FILE_STANDARD_INFORMATION
);
39 return STATUS_INFO_LENGTH_MISMATCH
;
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
);
51 return STATUS_SUCCESS
;
56 KsecQueryVolumeInformation(
58 FS_INFORMATION_CLASS FsInformationClass
,
61 PFILE_FS_DEVICE_INFORMATION DeviceInformation
;
63 /* Only FileFsDeviceInformation is supported */
64 if (FsInformationClass
!= FileFsDeviceInformation
)
66 return STATUS_INVALID_INFO_CLASS
;
69 /* Validate buffer size */
70 if (*BufferLength
< sizeof(FILE_FS_DEVICE_INFORMATION
))
72 *BufferLength
= sizeof(FILE_FS_DEVICE_INFORMATION
);
73 return STATUS_INFO_LENGTH_MISMATCH
;
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
);
82 return STATUS_SUCCESS
;
95 if ((IoControlCode
== IOCTL_KSEC_RANDOM_FILL_BUFFER
) ||
96 (IoControlCode
== IOCTL_KSEC_ENCRYPT_SAME_PROCESS
) ||
97 (IoControlCode
== IOCTL_KSEC_DECRYPT_SAME_PROCESS
) ||
98 (IoControlCode
== IOCTL_KSEC_ENCRYPT_CROSS_PROCESS
) ||
99 (IoControlCode
== IOCTL_KSEC_DECRYPT_CROSS_PROCESS
) ||
100 (IoControlCode
== IOCTL_KSEC_ENCRYPT_SAME_LOGON
) ||
101 (IoControlCode
== IOCTL_KSEC_DECRYPT_SAME_LOGON
))
103 /* Make sure we have a valid output buffer */
104 if ((Buffer
== NULL
) || (OutputLength
== NULL
))
106 return STATUS_INVALID_PARAMETER
;
109 /* Check if the input is smaller than the output */
110 if (InputLength
< *OutputLength
)
112 /* We might have uninitialized memory, zero it out */
113 RtlSecureZeroMemory((PUCHAR
)Buffer
+ InputLength
,
114 *OutputLength
- InputLength
);
118 /* Check ioctl code */
119 switch (IoControlCode
)
121 case IOCTL_KSEC_REGISTER_LSA_PROCESS
:
123 Status
= STATUS_SUCCESS
;
126 case IOCTL_KSEC_RANDOM_FILL_BUFFER
:
128 Status
= KsecGenRandom(Buffer
, *OutputLength
);
131 case IOCTL_KSEC_ENCRYPT_SAME_PROCESS
:
133 Status
= KsecEncryptMemory(Buffer
,
135 RTL_ENCRYPT_OPTION_SAME_PROCESS
);
138 case IOCTL_KSEC_DECRYPT_SAME_PROCESS
:
140 Status
= KsecDecryptMemory(Buffer
,
142 RTL_ENCRYPT_OPTION_SAME_PROCESS
);
145 case IOCTL_KSEC_ENCRYPT_CROSS_PROCESS
:
147 Status
= KsecEncryptMemory(Buffer
,
149 RTL_ENCRYPT_OPTION_CROSS_PROCESS
);
152 case IOCTL_KSEC_DECRYPT_CROSS_PROCESS
:
154 Status
= KsecDecryptMemory(Buffer
,
156 RTL_ENCRYPT_OPTION_CROSS_PROCESS
);
159 case IOCTL_KSEC_ENCRYPT_SAME_LOGON
:
161 Status
= KsecEncryptMemory(Buffer
,
163 RTL_ENCRYPT_OPTION_SAME_LOGON
);
166 case IOCTL_KSEC_DECRYPT_SAME_LOGON
:
168 Status
= KsecDecryptMemory(Buffer
,
170 RTL_ENCRYPT_OPTION_SAME_LOGON
);
174 DPRINT1("Unhandled control code 0x%lx\n", IoControlCode
);
176 return STATUS_INVALID_PARAMETER
;
185 PDEVICE_OBJECT DeviceObject
,
188 PIO_STACK_LOCATION IoStackLocation
;
189 ULONG_PTR Information
;
192 SIZE_T InputLength
, OutputLength
;
193 FILE_INFORMATION_CLASS FileInfoClass
;
194 FS_INFORMATION_CLASS FsInfoClass
;
197 IoStackLocation
= IoGetCurrentIrpStackLocation(Irp
);
199 switch (IoStackLocation
->MajorFunction
)
204 /* Just return success */
205 Status
= STATUS_SUCCESS
;
211 /* There is nothing to read */
212 Status
= STATUS_END_OF_FILE
;
218 /* Pretend to have written everything */
219 Status
= STATUS_SUCCESS
;
220 Information
= IoStackLocation
->Parameters
.Write
.Length
;
223 case IRP_MJ_QUERY_INFORMATION
:
225 /* Extract the parameters */
226 Buffer
= Irp
->AssociatedIrp
.SystemBuffer
;
227 OutputLength
= IoStackLocation
->Parameters
.QueryFile
.Length
;
228 FileInfoClass
= IoStackLocation
->Parameters
.QueryFile
.FileInformationClass
;
230 /* Call the internal function */
231 Status
= KsecQueryFileInformation(Buffer
,
234 Information
= OutputLength
;
237 case IRP_MJ_QUERY_VOLUME_INFORMATION
:
239 /* Extract the parameters */
240 Buffer
= Irp
->AssociatedIrp
.SystemBuffer
;
241 OutputLength
= IoStackLocation
->Parameters
.QueryVolume
.Length
;
242 FsInfoClass
= IoStackLocation
->Parameters
.QueryVolume
.FsInformationClass
;
244 /* Call the internal function */
245 Status
= KsecQueryVolumeInformation(Buffer
,
248 Information
= OutputLength
;
251 case IRP_MJ_DEVICE_CONTROL
:
253 /* Extract the parameters */
254 InputLength
= IoStackLocation
->Parameters
.DeviceIoControl
.InputBufferLength
;
255 OutputLength
= IoStackLocation
->Parameters
.DeviceIoControl
.OutputBufferLength
;
256 IoControlCode
= IoStackLocation
->Parameters
.DeviceIoControl
.IoControlCode
;
258 /* Check for METHOD_OUT_DIRECT method */
259 if ((METHOD_FROM_CTL_CODE(IoControlCode
) == METHOD_OUT_DIRECT
) &&
262 /* Use the provided MDL */
263 OutputLength
= Irp
->MdlAddress
->ByteCount
;
264 Buffer
= MmGetSystemAddressForMdlSafe(Irp
->MdlAddress
,
268 Status
= STATUS_INSUFFICIENT_RESOURCES
;
275 /* Otherwise this is METHOD_BUFFERED, use the SystemBuffer */
276 Buffer
= Irp
->AssociatedIrp
.SystemBuffer
;
279 /* Call the internal function */
280 Status
= KsecDeviceControl(IoControlCode
,
284 Information
= OutputLength
;
288 DPRINT1("Unhandled major function %lu!\n",
289 IoStackLocation
->MajorFunction
);
291 return STATUS_INVALID_DEVICE_REQUEST
;
294 /* Return the information */
295 Irp
->IoStatus
.Status
= Status
;
296 Irp
->IoStatus
.Information
= Information
;
298 /* Complete the request */
299 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);