[KSECDD]
[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
13 #define NDEBUG
14 #include <debug.h>
15
16
17 /* FUNCTIONS ******************************************************************/
18
19 static
20 NTSTATUS
21 KsecQueryFileInformation(
22 PVOID InfoBuffer,
23 FILE_INFORMATION_CLASS FileInformationClass,
24 PSIZE_T BufferLength)
25 {
26 PFILE_STANDARD_INFORMATION StandardInformation;
27
28 /* Only FileStandardInformation is supported */
29 if (FileInformationClass != FileStandardInformation)
30 {
31 return STATUS_INVALID_INFO_CLASS;
32 }
33
34 /* Validate buffer size */
35 if (*BufferLength >= sizeof(FILE_STANDARD_INFORMATION))
36 {
37 *BufferLength = sizeof(FILE_STANDARD_INFORMATION);
38 return STATUS_INFO_LENGTH_MISMATCH;
39 }
40
41 /* Fill the structure */
42 StandardInformation = (PFILE_STANDARD_INFORMATION)InfoBuffer;
43 StandardInformation->AllocationSize.QuadPart = 0;
44 StandardInformation->EndOfFile.QuadPart = 0;
45 StandardInformation->NumberOfLinks = 1;
46 StandardInformation->DeletePending = FALSE;
47 StandardInformation->Directory = FALSE;
48 *BufferLength = sizeof(FILE_STANDARD_INFORMATION);
49
50 return STATUS_SUCCESS;
51 }
52
53 static
54 NTSTATUS
55 KsecQueryVolumeInformation(
56 PVOID InfoBuffer,
57 FS_INFORMATION_CLASS FsInformationClass,
58 PSIZE_T BufferLength)
59 {
60 PFILE_FS_DEVICE_INFORMATION DeviceInformation;
61
62 /* Only FileFsDeviceInformation is supported */
63 if (FsInformationClass == FileFsDeviceInformation)
64 {
65 return STATUS_INVALID_INFO_CLASS;
66 }
67
68 /* Validate buffer size */
69 if (*BufferLength < sizeof(FILE_FS_DEVICE_INFORMATION))
70 {
71 *BufferLength = sizeof(FILE_FS_DEVICE_INFORMATION);
72 return STATUS_INFO_LENGTH_MISMATCH;
73 }
74
75 /* Fill the structure */
76 DeviceInformation = (PFILE_FS_DEVICE_INFORMATION)InfoBuffer;
77 DeviceInformation->DeviceType = FILE_DEVICE_NULL;
78 DeviceInformation->Characteristics = 0;
79 *BufferLength = sizeof(FILE_FS_DEVICE_INFORMATION);
80
81 return STATUS_SUCCESS;
82 }
83
84 NTSTATUS
85 NTAPI
86 KsecDdDispatch(
87 PDEVICE_OBJECT DeviceObject,
88 PIRP Irp)
89 {
90 PIO_STACK_LOCATION IoStackLocation;
91 ULONG_PTR Information;
92 NTSTATUS Status;
93 PVOID Buffer;
94 SIZE_T OutputLength;
95 FILE_INFORMATION_CLASS FileInfoClass;
96 FS_INFORMATION_CLASS FsInfoClass;
97
98 IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
99
100 switch (IoStackLocation->MajorFunction)
101 {
102 case IRP_MJ_CREATE:
103 case IRP_MJ_CLOSE:
104
105 /* Just return success */
106 Status = STATUS_SUCCESS;
107 Information = 0;
108 break;
109
110 case IRP_MJ_READ:
111
112 /* There is nothing to read */
113 Status = STATUS_END_OF_FILE;
114 Information = 0;
115 break;
116
117 case IRP_MJ_WRITE:
118
119 /* Pretend to have written everything */
120 Status = STATUS_SUCCESS;
121 Information = IoStackLocation->Parameters.Write.Length;
122 break;
123
124 case IRP_MJ_QUERY_INFORMATION:
125
126 /* Extract the parameters */
127 Buffer = Irp->AssociatedIrp.SystemBuffer;
128 OutputLength = IoStackLocation->Parameters.QueryFile.Length;
129 FileInfoClass = IoStackLocation->Parameters.QueryFile.FileInformationClass;
130
131 /* Call the internal function */
132 Status = KsecQueryFileInformation(Buffer,
133 FileInfoClass,
134 &OutputLength);
135 Information = OutputLength;
136 break;
137
138 case IRP_MJ_QUERY_VOLUME_INFORMATION:
139
140 /* Extract the parameters */
141 Buffer = Irp->AssociatedIrp.SystemBuffer;
142 OutputLength = IoStackLocation->Parameters.QueryVolume.Length;
143 FsInfoClass = IoStackLocation->Parameters.QueryVolume.FsInformationClass;
144
145 /* Call the internal function */
146 Status = KsecQueryVolumeInformation(Buffer,
147 FsInfoClass,
148 &OutputLength);
149 Information = OutputLength;
150 break;
151
152 default:
153 DPRINT1("Unhandled major function %lu!\n",
154 IoStackLocation->MajorFunction);
155 ASSERT(FALSE);
156 }
157
158 /* Return the information */
159 Irp->IoStatus.Status = Status;
160 Irp->IoStatus.Information = Information;
161
162 /* Complete the request */
163 IoCompleteRequest(Irp, IO_NO_INCREMENT);
164
165 return Status;
166 }