1 | /* $Id: vbsf.cpp 78326 2019-04-26 14:45:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Windows Guest Shared Folders - File System Driver initialization and generic routines
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include "vbsf.h"
|
---|
23 |
|
---|
24 |
|
---|
25 | /*********************************************************************************************************************************
|
---|
26 | * Structures and Typedefs *
|
---|
27 | *********************************************************************************************************************************/
|
---|
28 | /**
|
---|
29 | * The current state of the driver.
|
---|
30 | */
|
---|
31 | typedef enum _MRX_VBOX_STATE_
|
---|
32 | {
|
---|
33 | MRX_VBOX_STARTABLE,
|
---|
34 | MRX_VBOX_START_IN_PROGRESS,
|
---|
35 | MRX_VBOX_STARTED
|
---|
36 | } MRX_VBOX_STATE, *PMRX_VBOX_STATE;
|
---|
37 |
|
---|
38 |
|
---|
39 | /*********************************************************************************************************************************
|
---|
40 | * Global Variables *
|
---|
41 | *********************************************************************************************************************************/
|
---|
42 | static MRX_VBOX_STATE VBoxMRxState = MRX_VBOX_STARTABLE;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * The VBoxSF dispatch table.
|
---|
46 | */
|
---|
47 | static struct _MINIRDR_DISPATCH VBoxMRxDispatch;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * The VBoxSF device object.
|
---|
51 | */
|
---|
52 | PRDBSS_DEVICE_OBJECT VBoxMRxDeviceObject;
|
---|
53 |
|
---|
54 | /** The shared folder service client structure. */
|
---|
55 | VBGLSFCLIENT g_SfClient;
|
---|
56 | /** VMMDEV_HVF_XXX (set during init). */
|
---|
57 | uint32_t g_fHostFeatures = 0;
|
---|
58 | /** Last valid shared folders function number. */
|
---|
59 | uint32_t g_uSfLastFunction = SHFL_FN_SET_FILE_SIZE;
|
---|
60 | /** Shared folders features (SHFL_FEATURE_XXX). */
|
---|
61 | uint64_t g_fSfFeatures = 0;
|
---|
62 |
|
---|
63 |
|
---|
64 | /*********************************************************************************************************************************
|
---|
65 | * Exported Functions *
|
---|
66 | *********************************************************************************************************************************/
|
---|
67 | RT_C_DECLS_BEGIN
|
---|
68 | NTSTATUS _stdcall DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath);
|
---|
69 | RT_C_DECLS_END
|
---|
70 |
|
---|
71 |
|
---|
72 | static NTSTATUS VBoxMRxFsdDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
|
---|
73 | {
|
---|
74 | NTSTATUS Status;
|
---|
75 | #ifdef LOG_ENABLED
|
---|
76 | PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
---|
77 | Log(("VBOXSF: MRxFsdDispatch: major %d, minor %d: %s\n",
|
---|
78 | IrpSp->MajorFunction, IrpSp->MinorFunction, vbsfNtMajorFunctionName(IrpSp->MajorFunction, IrpSp->MinorFunction)));
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | if (DeviceObject != (PDEVICE_OBJECT)VBoxMRxDeviceObject)
|
---|
82 | {
|
---|
83 | Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
84 | Irp->IoStatus.Information = 0;
|
---|
85 | IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
---|
86 |
|
---|
87 | Log(("VBOXSF: MRxFsdDispatch: Invalid device request detected %p %p\n",
|
---|
88 | DeviceObject, (PDEVICE_OBJECT)VBoxMRxDeviceObject));
|
---|
89 |
|
---|
90 | return STATUS_INVALID_DEVICE_REQUEST;
|
---|
91 | }
|
---|
92 |
|
---|
93 | Status = RxFsdDispatch((PRDBSS_DEVICE_OBJECT)VBoxMRxDeviceObject, Irp);
|
---|
94 | Log(("VBOXSF: MRxFsdDispatch: Returned 0x%X\n", Status));
|
---|
95 | return Status;
|
---|
96 | }
|
---|
97 |
|
---|
98 | static void VBoxMRxUnload(IN PDRIVER_OBJECT DriverObject)
|
---|
99 | {
|
---|
100 | NTSTATUS Status;
|
---|
101 | UNICODE_STRING UserModeDeviceName;
|
---|
102 |
|
---|
103 | Log(("VBOXSF: MRxUnload\n"));
|
---|
104 |
|
---|
105 | if (VBoxMRxDeviceObject)
|
---|
106 | {
|
---|
107 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension;
|
---|
108 | pDeviceExtension = (PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)VBoxMRxDeviceObject + sizeof(RDBSS_DEVICE_OBJECT));
|
---|
109 | }
|
---|
110 |
|
---|
111 | if (VBoxMRxDeviceObject)
|
---|
112 | {
|
---|
113 | PRX_CONTEXT RxContext;
|
---|
114 | RxContext = RxCreateRxContext(NULL, VBoxMRxDeviceObject, RX_CONTEXT_FLAG_IN_FSP);
|
---|
115 |
|
---|
116 | if (RxContext != NULL)
|
---|
117 | {
|
---|
118 | Status = RxStopMinirdr(RxContext, &RxContext->PostRequest);
|
---|
119 |
|
---|
120 | if (Status == STATUS_SUCCESS)
|
---|
121 | {
|
---|
122 | MRX_VBOX_STATE State;
|
---|
123 |
|
---|
124 | State = (MRX_VBOX_STATE)InterlockedCompareExchange((LONG *)&VBoxMRxState, MRX_VBOX_STARTABLE, MRX_VBOX_STARTED);
|
---|
125 |
|
---|
126 | if (State != MRX_VBOX_STARTABLE)
|
---|
127 | Status = STATUS_REDIRECTOR_STARTED;
|
---|
128 | }
|
---|
129 |
|
---|
130 | RxDereferenceAndDeleteRxContext(RxContext);
|
---|
131 | }
|
---|
132 | else
|
---|
133 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
134 |
|
---|
135 | RxUnregisterMinirdr(VBoxMRxDeviceObject);
|
---|
136 | }
|
---|
137 |
|
---|
138 | RtlInitUnicodeString(&UserModeDeviceName, DD_MRX_VBOX_USERMODE_SHADOW_DEV_NAME_U);
|
---|
139 | Status = IoDeleteSymbolicLink(&UserModeDeviceName);
|
---|
140 | if (Status != STATUS_SUCCESS)
|
---|
141 | Log(("VBOXSF: MRxUnload: IoDeleteSymbolicLink Status 0x%08X\n", Status));
|
---|
142 |
|
---|
143 | RxUnload(DriverObject);
|
---|
144 |
|
---|
145 | VbglR0SfDisconnect(&g_SfClient);
|
---|
146 | VbglR0SfTerm();
|
---|
147 |
|
---|
148 | Log(("VBOXSF: MRxUnload: VBoxSF.sys driver object %p unloaded\n", DriverObject));
|
---|
149 | }
|
---|
150 |
|
---|
151 | static void vbsfInitMRxDispatch(void)
|
---|
152 | {
|
---|
153 | Log(("VBOXSF: vbsfInitMRxDispatch: Called.\n"));
|
---|
154 |
|
---|
155 | ZeroAndInitializeNodeType(&VBoxMRxDispatch, RDBSS_NTC_MINIRDR_DISPATCH, sizeof(MINIRDR_DISPATCH));
|
---|
156 |
|
---|
157 | VBoxMRxDispatch.MRxFlags = (RDBSS_MANAGE_NET_ROOT_EXTENSION | RDBSS_MANAGE_FOBX_EXTENSION);
|
---|
158 |
|
---|
159 | VBoxMRxDispatch.MRxSrvCallSize = 0;
|
---|
160 | VBoxMRxDispatch.MRxNetRootSize = sizeof(MRX_VBOX_NETROOT_EXTENSION);
|
---|
161 | VBoxMRxDispatch.MRxVNetRootSize = 0;
|
---|
162 | VBoxMRxDispatch.MRxFcbSize = 0;
|
---|
163 | VBoxMRxDispatch.MRxSrvOpenSize = 0;
|
---|
164 | VBoxMRxDispatch.MRxFobxSize = sizeof(MRX_VBOX_FOBX);
|
---|
165 |
|
---|
166 | VBoxMRxDispatch.MRxStart = VBoxMRxStart;
|
---|
167 | VBoxMRxDispatch.MRxStop = VBoxMRxStop;
|
---|
168 |
|
---|
169 | VBoxMRxDispatch.MRxCreate = VBoxMRxCreate;
|
---|
170 | VBoxMRxDispatch.MRxCollapseOpen = VBoxMRxCollapseOpen;
|
---|
171 | VBoxMRxDispatch.MRxShouldTryToCollapseThisOpen = VBoxMRxShouldTryToCollapseThisOpen;
|
---|
172 | VBoxMRxDispatch.MRxFlush = VBoxMRxFlush;
|
---|
173 | VBoxMRxDispatch.MRxTruncate = VBoxMRxTruncate;
|
---|
174 | VBoxMRxDispatch.MRxCleanupFobx = VBoxMRxCleanupFobx;
|
---|
175 | VBoxMRxDispatch.MRxCloseSrvOpen = VBoxMRxCloseSrvOpen;
|
---|
176 | VBoxMRxDispatch.MRxDeallocateForFcb = VBoxMRxDeallocateForFcb;
|
---|
177 | VBoxMRxDispatch.MRxDeallocateForFobx = VBoxMRxDeallocateForFobx;
|
---|
178 | VBoxMRxDispatch.MRxForceClosed = VBoxMRxForceClosed;
|
---|
179 |
|
---|
180 | VBoxMRxDispatch.MRxQueryDirectory = VBoxMRxQueryDirectory;
|
---|
181 | VBoxMRxDispatch.MRxQueryFileInfo = VBoxMRxQueryFileInfo;
|
---|
182 | VBoxMRxDispatch.MRxSetFileInfo = VBoxMRxSetFileInfo;
|
---|
183 | VBoxMRxDispatch.MRxSetFileInfoAtCleanup = VBoxMRxSetFileInfoAtCleanup;
|
---|
184 | VBoxMRxDispatch.MRxQueryEaInfo = VBoxMRxQueryEaInfo;
|
---|
185 | VBoxMRxDispatch.MRxSetEaInfo = VBoxMRxSetEaInfo;
|
---|
186 | VBoxMRxDispatch.MRxQuerySdInfo = VBoxMRxQuerySdInfo;
|
---|
187 | VBoxMRxDispatch.MRxSetSdInfo = VBoxMRxSetSdInfo;
|
---|
188 | VBoxMRxDispatch.MRxQueryVolumeInfo = VBoxMRxQueryVolumeInfo;
|
---|
189 |
|
---|
190 | VBoxMRxDispatch.MRxComputeNewBufferingState = VBoxMRxComputeNewBufferingState;
|
---|
191 |
|
---|
192 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_READ] = VBoxMRxRead;
|
---|
193 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_WRITE] = VBoxMRxWrite;
|
---|
194 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_SHAREDLOCK] = VBoxMRxLocks;
|
---|
195 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_EXCLUSIVELOCK] = VBoxMRxLocks;
|
---|
196 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_UNLOCK] = VBoxMRxLocks;
|
---|
197 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_UNLOCK_MULTIPLE] = VBoxMRxLocks;
|
---|
198 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_FSCTL] = VBoxMRxFsCtl;
|
---|
199 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_IOCTL] = VBoxMRxIoCtl;
|
---|
200 | VBoxMRxDispatch.MRxLowIOSubmit[LOWIO_OP_NOTIFY_CHANGE_DIRECTORY] = VBoxMRxNotifyChangeDirectory;
|
---|
201 |
|
---|
202 | VBoxMRxDispatch.MRxExtendForCache = VBoxMRxExtendStub;
|
---|
203 | VBoxMRxDispatch.MRxExtendForNonCache = VBoxMRxExtendStub;
|
---|
204 | VBoxMRxDispatch.MRxCompleteBufferingStateChangeRequest = VBoxMRxCompleteBufferingStateChangeRequest;
|
---|
205 |
|
---|
206 | VBoxMRxDispatch.MRxCreateVNetRoot = VBoxMRxCreateVNetRoot;
|
---|
207 | VBoxMRxDispatch.MRxFinalizeVNetRoot = VBoxMRxFinalizeVNetRoot;
|
---|
208 | VBoxMRxDispatch.MRxFinalizeNetRoot = VBoxMRxFinalizeNetRoot;
|
---|
209 | VBoxMRxDispatch.MRxUpdateNetRootState = VBoxMRxUpdateNetRootState;
|
---|
210 | VBoxMRxDispatch.MRxExtractNetRootName = VBoxMRxExtractNetRootName;
|
---|
211 |
|
---|
212 | VBoxMRxDispatch.MRxCreateSrvCall = VBoxMRxCreateSrvCall;
|
---|
213 | VBoxMRxDispatch.MRxSrvCallWinnerNotify = VBoxMRxSrvCallWinnerNotify;
|
---|
214 | VBoxMRxDispatch.MRxFinalizeSrvCall = VBoxMRxFinalizeSrvCall;
|
---|
215 |
|
---|
216 | VBoxMRxDispatch.MRxDevFcbXXXControlFile = VBoxMRxDevFcbXXXControlFile;
|
---|
217 |
|
---|
218 | Log(("VBOXSF: vbsfInitMRxDispatch: Success.\n"));
|
---|
219 | return;
|
---|
220 | }
|
---|
221 |
|
---|
222 | static BOOL vboxIsPrefixOK (const WCHAR *FilePathName, ULONG PathNameLength)
|
---|
223 | {
|
---|
224 | BOOL PrefixOK;
|
---|
225 |
|
---|
226 | /* The FilePathName here looks like: \vboxsrv\... */
|
---|
227 | if (PathNameLength >= 8 * sizeof (WCHAR)) /* Number of bytes in '\vboxsrv' unicode string. */
|
---|
228 | {
|
---|
229 | PrefixOK = (FilePathName[0] == L'\\');
|
---|
230 | PrefixOK &= (FilePathName[1] == L'V') || (FilePathName[1] == L'v');
|
---|
231 | PrefixOK &= (FilePathName[2] == L'B') || (FilePathName[2] == L'b');
|
---|
232 | PrefixOK &= (FilePathName[3] == L'O') || (FilePathName[3] == L'o');
|
---|
233 | PrefixOK &= (FilePathName[4] == L'X') || (FilePathName[4] == L'x');
|
---|
234 | PrefixOK &= (FilePathName[5] == L'S') || (FilePathName[5] == L's');
|
---|
235 | /* Both vboxsvr & vboxsrv are now accepted */
|
---|
236 | if ((FilePathName[6] == L'V') || (FilePathName[6] == L'v'))
|
---|
237 | {
|
---|
238 | PrefixOK &= (FilePathName[6] == L'V') || (FilePathName[6] == L'v');
|
---|
239 | PrefixOK &= (FilePathName[7] == L'R') || (FilePathName[7] == L'r');
|
---|
240 | }
|
---|
241 | else
|
---|
242 | {
|
---|
243 | PrefixOK &= (FilePathName[6] == L'R') || (FilePathName[6] == L'r');
|
---|
244 | PrefixOK &= (FilePathName[7] == L'V') || (FilePathName[7] == L'v');
|
---|
245 | }
|
---|
246 | if (PathNameLength > 8 * sizeof (WCHAR))
|
---|
247 | {
|
---|
248 | /* There is something after '\vboxsrv'. */
|
---|
249 | PrefixOK &= (FilePathName[8] == L'\\') || (FilePathName[8] == 0);
|
---|
250 | }
|
---|
251 | }
|
---|
252 | else
|
---|
253 | PrefixOK = FALSE;
|
---|
254 |
|
---|
255 | return PrefixOK;
|
---|
256 | }
|
---|
257 |
|
---|
258 | static NTSTATUS VBoxMRXDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
|
---|
259 | {
|
---|
260 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
261 |
|
---|
262 | QUERY_PATH_REQUEST *pReq = NULL;
|
---|
263 | QUERY_PATH_REQUEST_EX *pReqEx = NULL;
|
---|
264 | QUERY_PATH_RESPONSE *pResp = NULL;
|
---|
265 |
|
---|
266 | BOOL PrefixOK = FALSE;
|
---|
267 |
|
---|
268 | PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
|
---|
269 |
|
---|
270 | /* Make a local copy, it will be needed after the Irp completion. */
|
---|
271 | ULONG IoControlCode = pStack->Parameters.DeviceIoControl.IoControlCode;
|
---|
272 |
|
---|
273 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = (PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)pDevObj + sizeof(RDBSS_DEVICE_OBJECT));
|
---|
274 |
|
---|
275 | Log(("VBOXSF: MRXDeviceControl: pDevObj %p, pDeviceExtension %p, code %x\n",
|
---|
276 | pDevObj, pDevObj->DeviceExtension, IoControlCode));
|
---|
277 |
|
---|
278 | switch (IoControlCode)
|
---|
279 | {
|
---|
280 | case IOCTL_REDIR_QUERY_PATH_EX: /* Vista */
|
---|
281 | case IOCTL_REDIR_QUERY_PATH: /* XP and earlier */
|
---|
282 | {
|
---|
283 | /* This IOCTL is intercepted for 2 reasons:
|
---|
284 | * 1) Claim the vboxsvr and vboxsrv prefixes. All name-based operations for them
|
---|
285 | * will be routed to the VBox provider automatically without any prefix resolution
|
---|
286 | * since the prefix is already in the prefix cache.
|
---|
287 | * 2) Reject other prefixes immediately to speed up the UNC path resolution a bit,
|
---|
288 | * because RDBSS will not be involved then.
|
---|
289 | */
|
---|
290 |
|
---|
291 | const WCHAR *FilePathName = NULL;
|
---|
292 | ULONG PathNameLength = 0;
|
---|
293 |
|
---|
294 | if (pIrp->RequestorMode != KernelMode)
|
---|
295 | {
|
---|
296 | /* MSDN: Network redirectors should only honor kernel-mode senders of this IOCTL, by verifying
|
---|
297 | * that RequestorMode member of the IRP structure is KernelMode.
|
---|
298 | */
|
---|
299 | Log(("VBOXSF: MRxDeviceControl: IOCTL_REDIR_QUERY_PATH(_EX): not kernel mode!!!\n",
|
---|
300 | pStack->Parameters.DeviceIoControl.InputBufferLength));
|
---|
301 | /* Continue to RDBSS. */
|
---|
302 | break;
|
---|
303 | }
|
---|
304 |
|
---|
305 | if (IoControlCode == IOCTL_REDIR_QUERY_PATH)
|
---|
306 | {
|
---|
307 | Log(("VBOXSF: MRxDeviceControl: IOCTL_REDIR_QUERY_PATH: Called (pid %x).\n", IoGetCurrentProcess()));
|
---|
308 |
|
---|
309 | if (pStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(QUERY_PATH_REQUEST))
|
---|
310 | {
|
---|
311 | Log(("VBOXSF: MRxDeviceControl: IOCTL_REDIR_QUERY_PATH: short input buffer %d.\n",
|
---|
312 | pStack->Parameters.DeviceIoControl.InputBufferLength));
|
---|
313 | /* Continue to RDBSS. */
|
---|
314 | break;
|
---|
315 | }
|
---|
316 |
|
---|
317 | pReq = (QUERY_PATH_REQUEST *)pStack->Parameters.DeviceIoControl.Type3InputBuffer;
|
---|
318 |
|
---|
319 | Log(("VBOXSF: MRxDeviceControl: PathNameLength = %d.\n", pReq->PathNameLength));
|
---|
320 | Log(("VBOXSF: MRxDeviceControl: SecurityContext = %p.\n", pReq->SecurityContext));
|
---|
321 | Log(("VBOXSF: MRxDeviceControl: FilePathName = %.*ls.\n", pReq->PathNameLength / sizeof (WCHAR), pReq->FilePathName));
|
---|
322 |
|
---|
323 | FilePathName = pReq->FilePathName;
|
---|
324 | PathNameLength = pReq->PathNameLength;
|
---|
325 | }
|
---|
326 | else
|
---|
327 | {
|
---|
328 | Log(("VBOXSF: MRxDeviceControl: IOCTL_REDIR_QUERY_PATH_EX: Called.\n"));
|
---|
329 |
|
---|
330 | if (pStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(QUERY_PATH_REQUEST_EX))
|
---|
331 | {
|
---|
332 | Log(("VBOXSF: MRxDeviceControl: IOCTL_REDIR_QUERY_PATH_EX: short input buffer %d.\n",
|
---|
333 | pStack->Parameters.DeviceIoControl.InputBufferLength));
|
---|
334 | /* Continue to RDBSS. */
|
---|
335 | break;
|
---|
336 | }
|
---|
337 |
|
---|
338 | pReqEx = (QUERY_PATH_REQUEST_EX *)pStack->Parameters.DeviceIoControl.Type3InputBuffer;
|
---|
339 |
|
---|
340 | Log(("VBOXSF: MRxDeviceControl: pSecurityContext = %p.\n", pReqEx->pSecurityContext));
|
---|
341 | Log(("VBOXSF: MRxDeviceControl: EaLength = %d.\n", pReqEx->EaLength));
|
---|
342 | Log(("VBOXSF: MRxDeviceControl: pEaBuffer = %p.\n", pReqEx->pEaBuffer));
|
---|
343 | Log(("VBOXSF: MRxDeviceControl: PathNameLength = %d.\n", pReqEx->PathName.Length));
|
---|
344 | Log(("VBOXSF: MRxDeviceControl: FilePathName = %.*ls.\n", pReqEx->PathName.Length / sizeof (WCHAR), pReqEx->PathName.Buffer));
|
---|
345 |
|
---|
346 | FilePathName = pReqEx->PathName.Buffer;
|
---|
347 | PathNameLength = pReqEx->PathName.Length;
|
---|
348 | }
|
---|
349 |
|
---|
350 | pResp = (QUERY_PATH_RESPONSE *)pIrp->UserBuffer;
|
---|
351 |
|
---|
352 | PrefixOK = vboxIsPrefixOK (FilePathName, PathNameLength);
|
---|
353 | Log(("VBOXSF: MRxDeviceControl PrefixOK %d\n", PrefixOK));
|
---|
354 |
|
---|
355 | if (!PrefixOK)
|
---|
356 | {
|
---|
357 | /* Immediately fail the IOCTL with STATUS_BAD_NETWORK_NAME as recommended by MSDN.
|
---|
358 | * No need to involve RDBSS.
|
---|
359 | */
|
---|
360 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
361 |
|
---|
362 | pIrp->IoStatus.Status = Status;
|
---|
363 | pIrp->IoStatus.Information = 0;
|
---|
364 |
|
---|
365 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
366 |
|
---|
367 | Log(("VBOXSF: MRxDeviceControl: returned STATUS_BAD_NETWORK_NAME\n"));
|
---|
368 | return Status;
|
---|
369 | }
|
---|
370 |
|
---|
371 | Log(("VBOXSF: MRxDeviceControl pResp %p verifying the path.\n", pResp));
|
---|
372 | if (pResp)
|
---|
373 | {
|
---|
374 | /* Always claim entire \vboxsrv prefix. The LengthAccepted initially is equal to entire path.
|
---|
375 | * Here it is assigned to the length of \vboxsrv prefix.
|
---|
376 | */
|
---|
377 | pResp->LengthAccepted = 8 * sizeof (WCHAR);
|
---|
378 |
|
---|
379 | Status = STATUS_SUCCESS;
|
---|
380 |
|
---|
381 | pIrp->IoStatus.Status = Status;
|
---|
382 | pIrp->IoStatus.Information = 0;
|
---|
383 |
|
---|
384 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
385 |
|
---|
386 | Log(("VBOXSF: MRxDeviceControl: claiming the path.\n"));
|
---|
387 | return Status;
|
---|
388 | }
|
---|
389 |
|
---|
390 | /* No pResp pointer, should not happen. Just a precaution. */
|
---|
391 | Status = STATUS_INVALID_PARAMETER;
|
---|
392 |
|
---|
393 | pIrp->IoStatus.Status = Status;
|
---|
394 | pIrp->IoStatus.Information = 0;
|
---|
395 |
|
---|
396 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
397 |
|
---|
398 | Log(("VBOXSF: MRxDeviceControl: returned STATUS_INVALID_PARAMETER\n"));
|
---|
399 | return Status;
|
---|
400 | }
|
---|
401 |
|
---|
402 | default:
|
---|
403 | break;
|
---|
404 | }
|
---|
405 |
|
---|
406 | /* Pass the IOCTL to RDBSS. */
|
---|
407 | if (pDeviceExtension && pDeviceExtension->pfnRDBSSDeviceControl)
|
---|
408 | {
|
---|
409 | Log(("VBOXSF: MRxDeviceControl calling RDBSS %p\n", pDeviceExtension->pfnRDBSSDeviceControl));
|
---|
410 | Status = pDeviceExtension->pfnRDBSSDeviceControl (pDevObj, pIrp);
|
---|
411 | Log(("VBOXSF: MRxDeviceControl RDBSS status 0x%08X\n", Status));
|
---|
412 | }
|
---|
413 | else
|
---|
414 | {
|
---|
415 | /* No RDBSS, should not happen. Just a precaution. */
|
---|
416 | Status = STATUS_NOT_IMPLEMENTED;
|
---|
417 |
|
---|
418 | pIrp->IoStatus.Status = Status;
|
---|
419 | pIrp->IoStatus.Information = 0;
|
---|
420 |
|
---|
421 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
422 |
|
---|
423 | Log(("VBOXSF: MRxDeviceControl: returned STATUS_NOT_IMPLEMENTED\n"));
|
---|
424 | }
|
---|
425 |
|
---|
426 | return Status;
|
---|
427 | }
|
---|
428 |
|
---|
429 | /**
|
---|
430 | * Intercepts IRP_MJ_CREATE to workaround a RDBSS quirk.
|
---|
431 | *
|
---|
432 | * Our RDBSS library will return STATUS_OBJECT_NAME_INVALID when FILE_NON_DIRECTORY_FILE
|
---|
433 | * is set and the path ends with a slash. NTFS and FAT will fail with
|
---|
434 | * STATUS_OBJECT_NAME_NOT_FOUND if the final component does not exist or isn't a directory,
|
---|
435 | * STATUS_OBJECT_PATH_NOT_FOUND if some path component doesn't exist or isn't a directory,
|
---|
436 | * or STATUS_ACCESS_DENIED if the final component is a directory.
|
---|
437 | *
|
---|
438 | * So, our HACK is to drop the trailing slash and set an unused flag in the ShareAccess
|
---|
439 | * parameter to tell vbsfProcessCreate about it.
|
---|
440 | *
|
---|
441 | */
|
---|
442 | static NTSTATUS VBoxHookMjCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
|
---|
443 | {
|
---|
444 | PMRX_VBOX_DEVICE_EXTENSION pDevExt = (PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)pDevObj + sizeof(RDBSS_DEVICE_OBJECT));
|
---|
445 | PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
|
---|
446 | PFILE_OBJECT pFileObj = pStack->FileObject;
|
---|
447 | NTSTATUS rcNt;
|
---|
448 |
|
---|
449 | Log(("VBOXSF: VBoxHookMjCreate: pDevObj %p, pDevExt %p, pFileObj %p, options %#x, attr %#x, share %#x, ealength %#x, secctx %p\n",
|
---|
450 | pDevObj, pDevObj->DeviceExtension, pFileObj, pStack->Parameters.Create.Options, pStack->Parameters.Create.FileAttributes,
|
---|
451 | pStack->Parameters.Create.ShareAccess, pStack->Parameters.Create.EaLength, pStack->Parameters.Create.SecurityContext));
|
---|
452 | if (pFileObj)
|
---|
453 | Log(("VBOXSF: VBoxHookMjCreate: FileName=%.*ls\n", pFileObj->FileName.Length / sizeof(WCHAR), pFileObj->FileName.Buffer));
|
---|
454 |
|
---|
455 | /*
|
---|
456 | * Check if we need to apply the hack. If we do, we grab a reference to
|
---|
457 | * the file object to be absolutely sure it's around for the cleanup work.
|
---|
458 | */
|
---|
459 | AssertMsg(!(pStack->Parameters.Create.ShareAccess & VBOX_MJ_CREATE_SLASH_HACK), ("%#x\n", pStack->Parameters.Create.ShareAccess));
|
---|
460 | if ( (pStack->Parameters.Create.Options & (FILE_NON_DIRECTORY_FILE | FILE_DIRECTORY_FILE)) == FILE_NON_DIRECTORY_FILE
|
---|
461 | && pFileObj
|
---|
462 | && pFileObj->FileName.Length > 18
|
---|
463 | && pFileObj->FileName.Buffer
|
---|
464 | && pFileObj->FileName.Buffer[pFileObj->FileName.Length / sizeof(WCHAR) - 1] == '\\'
|
---|
465 | && pFileObj->FileName.Buffer[pFileObj->FileName.Length / sizeof(WCHAR) - 2] != '\\')
|
---|
466 | {
|
---|
467 | NTSTATUS rcNtRef = ObReferenceObjectByPointer(pFileObj, (ACCESS_MASK)0, *IoFileObjectType, KernelMode);
|
---|
468 | pFileObj->FileName.Length -= 2;
|
---|
469 | pStack->Parameters.Create.ShareAccess |= VBOX_MJ_CREATE_SLASH_HACK; /* secret flag for vbsfProcessCreate */
|
---|
470 |
|
---|
471 | rcNt = pDevExt->pfnRDBSSCreate(pDevObj, pIrp);
|
---|
472 |
|
---|
473 | if (rcNt != STATUS_PENDING)
|
---|
474 | pStack->Parameters.Create.ShareAccess &= ~VBOX_MJ_CREATE_SLASH_HACK;
|
---|
475 | if (NT_SUCCESS(rcNtRef))
|
---|
476 | {
|
---|
477 | pFileObj->FileName.Length += 2;
|
---|
478 | ObDereferenceObject(pFileObj);
|
---|
479 | }
|
---|
480 |
|
---|
481 | Log(("VBOXSF: VBoxHookMjCreate: returns %#x (hacked; rcNtRef=%#x)\n", rcNt, rcNtRef));
|
---|
482 | }
|
---|
483 | /*
|
---|
484 | * No hack needed.
|
---|
485 | */
|
---|
486 | else
|
---|
487 | {
|
---|
488 | rcNt = pDevExt->pfnRDBSSCreate(pDevObj, pIrp);
|
---|
489 | Log(("VBOXSF: VBoxHookMjCreate: returns %#x\n", rcNt));
|
---|
490 | }
|
---|
491 | return rcNt;
|
---|
492 | }
|
---|
493 |
|
---|
494 | NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
|
---|
495 | IN PUNICODE_STRING RegistryPath)
|
---|
496 | {
|
---|
497 | NTSTATUS Status;
|
---|
498 | UNICODE_STRING VBoxMRxName;
|
---|
499 | UNICODE_STRING UserModeDeviceName;
|
---|
500 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = NULL;
|
---|
501 | ULONG i;
|
---|
502 | int vrc;
|
---|
503 |
|
---|
504 | Log(("VBOXSF: DriverEntry: Driver object %p\n", DriverObject));
|
---|
505 |
|
---|
506 | if (!DriverObject)
|
---|
507 | {
|
---|
508 | Log(("VBOXSF: DriverEntry: driver object is NULL.\n"));
|
---|
509 | return STATUS_UNSUCCESSFUL;
|
---|
510 | }
|
---|
511 |
|
---|
512 | /* Initialize VBox subsystem. */
|
---|
513 | vrc = VbglR0SfInit();
|
---|
514 | if (RT_FAILURE(vrc))
|
---|
515 | {
|
---|
516 | Log(("VBOXSF: DriverEntry: ERROR while initializing VBox subsystem (%Rrc)!\n", vrc));
|
---|
517 | return STATUS_UNSUCCESSFUL;
|
---|
518 | }
|
---|
519 |
|
---|
520 | /* Connect the HGCM client */
|
---|
521 | vrc = VbglR0SfConnect(&g_SfClient);
|
---|
522 | if (RT_FAILURE(vrc))
|
---|
523 | {
|
---|
524 | Log(("VBOXSF: DriverEntry: ERROR while connecting to host (%Rrc)!\n",
|
---|
525 | vrc));
|
---|
526 | VbglR0SfTerm();
|
---|
527 | return STATUS_UNSUCCESSFUL;
|
---|
528 | }
|
---|
529 |
|
---|
530 | vrc = VbglR0QueryHostFeatures(&g_fHostFeatures);
|
---|
531 | if (RT_FAILURE(vrc))
|
---|
532 | {
|
---|
533 | LogRel(("vboxsf: VbglR0QueryHostFeatures failed: vrc=%Rrc (ignored)\n", vrc));
|
---|
534 | g_fHostFeatures = 0;
|
---|
535 | }
|
---|
536 | VbglR0SfHostReqQueryFeaturesSimple(&g_fSfFeatures, &g_uSfLastFunction);
|
---|
537 | LogRel(("VBoxSF: g_fHostFeatures=%#x g_fSfFeatures=%#RX64 g_uSfLastFunction=%u\n",
|
---|
538 | g_fHostFeatures, g_fSfFeatures, g_uSfLastFunction));
|
---|
539 |
|
---|
540 | /* Init the driver object. */
|
---|
541 | DriverObject->DriverUnload = VBoxMRxUnload;
|
---|
542 | for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
|
---|
543 | {
|
---|
544 | DriverObject->MajorFunction[i] = (PDRIVER_DISPATCH)VBoxMRxFsdDispatch;
|
---|
545 | }
|
---|
546 |
|
---|
547 | /* Forward to RDBSS. */
|
---|
548 | Status = RxDriverEntry(DriverObject, RegistryPath);
|
---|
549 | if (Status != STATUS_SUCCESS)
|
---|
550 | {
|
---|
551 | Log(("VBOXSF: DriverEntry: RxDriverEntry failed: 0x%08X\n", Status));
|
---|
552 | goto failure;
|
---|
553 | }
|
---|
554 |
|
---|
555 | __try
|
---|
556 | {
|
---|
557 | Log(("VBOXSF: DriverEntry: RxRegisterMinirdr: calling VBoxMRxDeviceObject %p\n",
|
---|
558 | VBoxMRxDeviceObject));
|
---|
559 |
|
---|
560 | RtlInitUnicodeString(&VBoxMRxName, DD_MRX_VBOX_FS_DEVICE_NAME_U);
|
---|
561 |
|
---|
562 | /* Don use RX_REGISTERMINI_FLAG_DONT_PROVIDE_UNCS or else
|
---|
563 | * UNC mappings don't work (including Windows explorer browsing).
|
---|
564 | */
|
---|
565 | Status = RxRegisterMinirdr(&VBoxMRxDeviceObject,
|
---|
566 | DriverObject,
|
---|
567 | &VBoxMRxDispatch,
|
---|
568 | RX_REGISTERMINI_FLAG_DONT_PROVIDE_MAILSLOTS,
|
---|
569 | &VBoxMRxName,
|
---|
570 | sizeof(MRX_VBOX_DEVICE_EXTENSION),
|
---|
571 | FILE_DEVICE_NETWORK_FILE_SYSTEM,
|
---|
572 | FILE_REMOTE_DEVICE);
|
---|
573 |
|
---|
574 | Log(("VBOXSF: DriverEntry: RxRegisterMinirdr: returned 0x%08X VBoxMRxDeviceObject %p\n",
|
---|
575 | Status, VBoxMRxDeviceObject));
|
---|
576 |
|
---|
577 | if (Status!=STATUS_SUCCESS)
|
---|
578 | {
|
---|
579 | Log(("VBOXSF: DriverEntry: RxRegisterMinirdr failed: 0x%08X\n", Status ));
|
---|
580 | try_return((void)Status);
|
---|
581 | }
|
---|
582 |
|
---|
583 | /* Init the device extension.
|
---|
584 | * NOTE: the device extension actually points to fields
|
---|
585 | * in the RDBSS_DEVICE_OBJECT. Our space is past the end
|
---|
586 | * of this struct!!
|
---|
587 | */
|
---|
588 | pDeviceExtension = (PMRX_VBOX_DEVICE_EXTENSION)((PBYTE)VBoxMRxDeviceObject + sizeof(RDBSS_DEVICE_OBJECT));
|
---|
589 |
|
---|
590 | pDeviceExtension->pDeviceObject = VBoxMRxDeviceObject;
|
---|
591 |
|
---|
592 | for (i = 0; i < RT_ELEMENTS(pDeviceExtension->cLocalConnections); i++)
|
---|
593 | {
|
---|
594 | pDeviceExtension->cLocalConnections[i] = FALSE;
|
---|
595 | }
|
---|
596 |
|
---|
597 | /* Mutex for synchronizining our connection list */
|
---|
598 | ExInitializeFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
599 |
|
---|
600 | /* The device object has been created. Need to setup a symbolic
|
---|
601 | * link so that the device may be accessed from a Win32 user mode
|
---|
602 | * application.
|
---|
603 | */
|
---|
604 |
|
---|
605 | RtlInitUnicodeString(&UserModeDeviceName, DD_MRX_VBOX_USERMODE_SHADOW_DEV_NAME_U);
|
---|
606 | Log(("VBOXSF: DriverEntry: Calling IoCreateSymbolicLink\n"));
|
---|
607 | Status = IoCreateSymbolicLink(&UserModeDeviceName, &VBoxMRxName);
|
---|
608 | if (Status != STATUS_SUCCESS)
|
---|
609 | {
|
---|
610 | Log(("VBOXSF: DriverEntry: IoCreateSymbolicLink: 0x%08X\n",
|
---|
611 | Status));
|
---|
612 | try_return((void)Status);
|
---|
613 | }
|
---|
614 | Log(("VBOXSF: DriverEntry: Symbolic link created.\n"));
|
---|
615 |
|
---|
616 | /*
|
---|
617 | * Build the dispatch tables for the minirdr
|
---|
618 | */
|
---|
619 | vbsfInitMRxDispatch();
|
---|
620 |
|
---|
621 | try_exit:
|
---|
622 | ;
|
---|
623 | }
|
---|
624 | __finally
|
---|
625 | {
|
---|
626 | ;
|
---|
627 | }
|
---|
628 |
|
---|
629 | if (Status != STATUS_SUCCESS)
|
---|
630 | {
|
---|
631 | Log(("VBOXSF: DriverEntry: VBoxSF.sys failed to start with Status = 0x%08X\n",
|
---|
632 | Status));
|
---|
633 | goto failure;
|
---|
634 | }
|
---|
635 |
|
---|
636 | AssertPtr(pDeviceExtension);
|
---|
637 |
|
---|
638 | /* The redirector driver must intercept the IOCTL to avoid VBOXSVR name resolution
|
---|
639 | * by other redirectors. These additional name resolutions cause long delays.
|
---|
640 | */
|
---|
641 | Log(("VBOXSF: DriverEntry: VBoxMRxDeviceObject = %p, rdbss %p, devext %p\n",
|
---|
642 | VBoxMRxDeviceObject, DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL], pDeviceExtension));
|
---|
643 | pDeviceExtension->pfnRDBSSDeviceControl = DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL];
|
---|
644 | DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxMRXDeviceControl;
|
---|
645 |
|
---|
646 | /* Intercept IRP_MJ_CREATE to fix incorrect (wrt NTFS, FAT, ++) return
|
---|
647 | * codes for NtOpenFile("r:\\asdf\\", FILE_NON_DIRECTORY_FILE).
|
---|
648 | */
|
---|
649 | pDeviceExtension->pfnRDBSSCreate = DriverObject->MajorFunction[IRP_MJ_CREATE];
|
---|
650 | DriverObject->MajorFunction[IRP_MJ_CREATE] = VBoxHookMjCreate;
|
---|
651 |
|
---|
652 |
|
---|
653 | /** @todo start the redirector here RxStartMiniRdr. */
|
---|
654 |
|
---|
655 | Log(("VBOXSF: DriverEntry: Init successful!\n"));
|
---|
656 | return STATUS_SUCCESS;
|
---|
657 |
|
---|
658 | failure:
|
---|
659 |
|
---|
660 | Log(("VBOXSF: DriverEntry: Failure! Status = 0x%08X\n", Status));
|
---|
661 |
|
---|
662 | VbglR0SfDisconnect(&g_SfClient);
|
---|
663 | VbglR0SfTerm();
|
---|
664 |
|
---|
665 | if (VBoxMRxDeviceObject)
|
---|
666 | {
|
---|
667 | RxUnregisterMinirdr(VBoxMRxDeviceObject);
|
---|
668 | VBoxMRxDeviceObject = NULL;
|
---|
669 | }
|
---|
670 |
|
---|
671 | return Status;
|
---|
672 | }
|
---|
673 |
|
---|
674 | NTSTATUS VBoxMRxStart(PRX_CONTEXT RxContext, IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject)
|
---|
675 | {
|
---|
676 | NTSTATUS Status;
|
---|
677 | MRX_VBOX_STATE CurrentState;
|
---|
678 | RT_NOREF(RxContext, RxDeviceObject);
|
---|
679 |
|
---|
680 | Log(("VBOXSF: MRxStart\n"));
|
---|
681 |
|
---|
682 | CurrentState = (MRX_VBOX_STATE)InterlockedCompareExchange((PLONG)&VBoxMRxState, MRX_VBOX_STARTED, MRX_VBOX_START_IN_PROGRESS);
|
---|
683 |
|
---|
684 | if (CurrentState == MRX_VBOX_START_IN_PROGRESS)
|
---|
685 | {
|
---|
686 | Log(("VBOXSF: MRxStart: Start in progress -> started\n"));
|
---|
687 | Status = STATUS_SUCCESS;
|
---|
688 | }
|
---|
689 | else if (VBoxMRxState == MRX_VBOX_STARTED)
|
---|
690 | {
|
---|
691 | Log(("VBOXSF: MRxStart: Already started\n"));
|
---|
692 | Status = STATUS_REDIRECTOR_STARTED;
|
---|
693 | }
|
---|
694 | else
|
---|
695 | {
|
---|
696 | Log(("VBOXSF: MRxStart: Bad state! VBoxMRxState = %d\n", VBoxMRxState));
|
---|
697 | Status = STATUS_UNSUCCESSFUL;
|
---|
698 | }
|
---|
699 |
|
---|
700 | return Status;
|
---|
701 | }
|
---|
702 |
|
---|
703 | NTSTATUS VBoxMRxStop(PRX_CONTEXT RxContext, IN OUT PRDBSS_DEVICE_OBJECT RxDeviceObject)
|
---|
704 | {
|
---|
705 | RT_NOREF(RxContext, RxDeviceObject);
|
---|
706 | Log(("VBOXSF: MRxStop\n"));
|
---|
707 | return STATUS_SUCCESS;
|
---|
708 | }
|
---|
709 |
|
---|
710 | NTSTATUS VBoxMRxIoCtl(IN OUT PRX_CONTEXT RxContext)
|
---|
711 | {
|
---|
712 | RT_NOREF(RxContext);
|
---|
713 | Log(("VBOXSF: MRxIoCtl: IoControlCode = 0x%08X\n", RxContext->LowIoContext.ParamsFor.FsCtl.FsControlCode));
|
---|
714 | return STATUS_INVALID_DEVICE_REQUEST;
|
---|
715 | }
|
---|
716 |
|
---|
717 | NTSYSAPI NTSTATUS NTAPI ZwSetSecurityObject(IN HANDLE Handle,
|
---|
718 | IN SECURITY_INFORMATION SecurityInformation,
|
---|
719 | IN PSECURITY_DESCRIPTOR SecurityDescriptor);
|
---|
720 |
|
---|
721 | NTSTATUS VBoxMRxDevFcbXXXControlFile(IN OUT PRX_CONTEXT RxContext)
|
---|
722 | {
|
---|
723 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
724 | RxCaptureFobx;
|
---|
725 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
726 | PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
|
---|
727 |
|
---|
728 | Log(("VBOXSF: MRxDevFcbXXXControlFile: MajorFunction = 0x%02X\n",
|
---|
729 | RxContext->MajorFunction));
|
---|
730 |
|
---|
731 | switch (RxContext->MajorFunction)
|
---|
732 | {
|
---|
733 | case IRP_MJ_FILE_SYSTEM_CONTROL:
|
---|
734 | {
|
---|
735 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IRP_MN_USER_FS_REQUEST: 0x%08X\n",
|
---|
736 | LowIoContext->ParamsFor.FsCtl.MinorFunction));
|
---|
737 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
738 | break;
|
---|
739 | }
|
---|
740 |
|
---|
741 | case IRP_MJ_DEVICE_CONTROL:
|
---|
742 | {
|
---|
743 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IRP_MJ_DEVICE_CONTROL: InputBuffer %p/%d, OutputBuffer %p/%d\n",
|
---|
744 | LowIoContext->ParamsFor.IoCtl.pInputBuffer,
|
---|
745 | LowIoContext->ParamsFor.IoCtl.InputBufferLength,
|
---|
746 | LowIoContext->ParamsFor.IoCtl.pOutputBuffer,
|
---|
747 | LowIoContext->ParamsFor.IoCtl.OutputBufferLength));
|
---|
748 |
|
---|
749 | switch (LowIoContext->ParamsFor.IoCtl.IoControlCode)
|
---|
750 | {
|
---|
751 | case IOCTL_MRX_VBOX_ADDCONN:
|
---|
752 | {
|
---|
753 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_ADDCONN\n"));
|
---|
754 | Status = vbsfNtCreateConnection(RxContext, &RxContext->PostRequest);
|
---|
755 | break;
|
---|
756 | }
|
---|
757 |
|
---|
758 | case IOCTL_MRX_VBOX_DELCONN:
|
---|
759 | {
|
---|
760 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_DELCONN\n"));
|
---|
761 | Status = vbsfNtDeleteConnection(RxContext, &RxContext->PostRequest);
|
---|
762 | break;
|
---|
763 | }
|
---|
764 |
|
---|
765 | case IOCTL_MRX_VBOX_GETLIST:
|
---|
766 | {
|
---|
767 | ULONG cbOut = LowIoContext->ParamsFor.IoCtl.OutputBufferLength;
|
---|
768 | uint8_t *pu8Out = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pOutputBuffer;
|
---|
769 |
|
---|
770 | BOOLEAN fLocked = FALSE;
|
---|
771 |
|
---|
772 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETLIST\n"));
|
---|
773 |
|
---|
774 | RxContext->InformationToReturn = 0;
|
---|
775 |
|
---|
776 | if ( !pDeviceExtension
|
---|
777 | || cbOut < _MRX_MAX_DRIVE_LETTERS)
|
---|
778 | {
|
---|
779 | Status = STATUS_INVALID_PARAMETER;
|
---|
780 | break;
|
---|
781 | }
|
---|
782 |
|
---|
783 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETLIST: Copying local connections\n"));
|
---|
784 |
|
---|
785 | fLocked = ExTryToAcquireFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
786 |
|
---|
787 | __try
|
---|
788 | {
|
---|
789 | RtlCopyMemory(pu8Out, pDeviceExtension->cLocalConnections, _MRX_MAX_DRIVE_LETTERS);
|
---|
790 | RxContext->InformationToReturn = _MRX_MAX_DRIVE_LETTERS;
|
---|
791 | }
|
---|
792 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
793 | {
|
---|
794 | Status = STATUS_INVALID_PARAMETER;
|
---|
795 | }
|
---|
796 |
|
---|
797 | if (fLocked)
|
---|
798 | {
|
---|
799 | ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
800 | fLocked = FALSE;
|
---|
801 | }
|
---|
802 |
|
---|
803 | break;
|
---|
804 | }
|
---|
805 |
|
---|
806 | /*
|
---|
807 | * Returns the root IDs of shared folder mappings.
|
---|
808 | */
|
---|
809 | case IOCTL_MRX_VBOX_GETGLOBALLIST:
|
---|
810 | {
|
---|
811 | ULONG cbOut = LowIoContext->ParamsFor.IoCtl.OutputBufferLength;
|
---|
812 | uint8_t *pu8Out = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pOutputBuffer;
|
---|
813 |
|
---|
814 | int vrc;
|
---|
815 | SHFLMAPPING mappings[_MRX_MAX_DRIVE_LETTERS];
|
---|
816 | uint32_t cMappings = RT_ELEMENTS(mappings);
|
---|
817 |
|
---|
818 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALLIST\n"));
|
---|
819 |
|
---|
820 | RxContext->InformationToReturn = 0;
|
---|
821 |
|
---|
822 | if ( !pDeviceExtension
|
---|
823 | || cbOut < _MRX_MAX_DRIVE_LETTERS)
|
---|
824 | {
|
---|
825 | Status = STATUS_INVALID_PARAMETER;
|
---|
826 | break;
|
---|
827 | }
|
---|
828 |
|
---|
829 | vrc = VbglR0SfQueryMappings(&g_SfClient, mappings, &cMappings);
|
---|
830 | if (vrc == VINF_SUCCESS)
|
---|
831 | {
|
---|
832 | __try
|
---|
833 | {
|
---|
834 | uint32_t i;
|
---|
835 |
|
---|
836 | RtlZeroMemory(pu8Out, _MRX_MAX_DRIVE_LETTERS);
|
---|
837 |
|
---|
838 | for (i = 0; i < RT_MIN(cMappings, cbOut); i++)
|
---|
839 | {
|
---|
840 | pu8Out[i] = mappings[i].root;
|
---|
841 | pu8Out[i] |= 0x80; /* mark active */ /** @todo fix properly */
|
---|
842 | }
|
---|
843 |
|
---|
844 | RxContext->InformationToReturn = _MRX_MAX_DRIVE_LETTERS;
|
---|
845 | }
|
---|
846 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
847 | {
|
---|
848 | Status = STATUS_INVALID_PARAMETER;
|
---|
849 | }
|
---|
850 | }
|
---|
851 | else
|
---|
852 | {
|
---|
853 | Status = vbsfNtVBoxStatusToNt(vrc);
|
---|
854 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALLIST failed: 0x%08X\n",
|
---|
855 | Status));
|
---|
856 | }
|
---|
857 |
|
---|
858 | break;
|
---|
859 | }
|
---|
860 |
|
---|
861 | /*
|
---|
862 | * Translates a local connection name (e.g. drive "S:") to the
|
---|
863 | * corresponding remote name (e.g. \\vboxsrv\share).
|
---|
864 | */
|
---|
865 | case IOCTL_MRX_VBOX_GETCONN:
|
---|
866 | {
|
---|
867 | ULONG cbConnectName = LowIoContext->ParamsFor.IoCtl.InputBufferLength;
|
---|
868 | PWCHAR pwcConnectName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pInputBuffer;
|
---|
869 | ULONG cbRemoteName = LowIoContext->ParamsFor.IoCtl.OutputBufferLength;
|
---|
870 | PWCHAR pwcRemoteName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pOutputBuffer;
|
---|
871 |
|
---|
872 | BOOLEAN fMutexAcquired = FALSE;
|
---|
873 |
|
---|
874 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN\n"));
|
---|
875 |
|
---|
876 | RxContext->InformationToReturn = 0;
|
---|
877 |
|
---|
878 | if ( !pDeviceExtension
|
---|
879 | || cbConnectName < sizeof(WCHAR))
|
---|
880 | {
|
---|
881 | Status = STATUS_INVALID_PARAMETER;
|
---|
882 | break;
|
---|
883 | }
|
---|
884 |
|
---|
885 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Looking up connection name and connections\n"));
|
---|
886 |
|
---|
887 | __try
|
---|
888 | {
|
---|
889 | uint32_t idx = *pwcConnectName - L'A';
|
---|
890 |
|
---|
891 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: ConnectName = %.*ls, Len = %d, Index = %d\n",
|
---|
892 | cbConnectName / sizeof(WCHAR), pwcConnectName, cbConnectName, idx));
|
---|
893 |
|
---|
894 | if (idx < RTL_NUMBER_OF(pDeviceExtension->wszLocalConnectionName))
|
---|
895 | {
|
---|
896 | ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
897 | fMutexAcquired = TRUE;
|
---|
898 |
|
---|
899 | if (pDeviceExtension->wszLocalConnectionName[idx])
|
---|
900 | {
|
---|
901 | ULONG cbLocalConnectionName = pDeviceExtension->wszLocalConnectionName[idx]->Length;
|
---|
902 |
|
---|
903 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: LocalConnectionName = %.*ls\n",
|
---|
904 | cbLocalConnectionName / sizeof(WCHAR), pDeviceExtension->wszLocalConnectionName[idx]->Buffer));
|
---|
905 |
|
---|
906 | if ((pDeviceExtension->cLocalConnections[idx]) && (cbLocalConnectionName <= cbRemoteName))
|
---|
907 | {
|
---|
908 | RtlZeroMemory(pwcRemoteName, cbRemoteName);
|
---|
909 | RtlCopyMemory(pwcRemoteName,
|
---|
910 | pDeviceExtension->wszLocalConnectionName[idx]->Buffer,
|
---|
911 | cbLocalConnectionName);
|
---|
912 |
|
---|
913 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Remote name = %.*ls, Len = %d\n",
|
---|
914 | cbLocalConnectionName / sizeof(WCHAR), pwcRemoteName, cbLocalConnectionName));
|
---|
915 | }
|
---|
916 | else
|
---|
917 | {
|
---|
918 | Status = STATUS_BUFFER_TOO_SMALL;
|
---|
919 | }
|
---|
920 |
|
---|
921 | RxContext->InformationToReturn = cbLocalConnectionName;
|
---|
922 | }
|
---|
923 | else
|
---|
924 | {
|
---|
925 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: LocalConnectionName is NULL!\n"));
|
---|
926 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
927 | }
|
---|
928 | }
|
---|
929 | else
|
---|
930 | {
|
---|
931 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETCONN: Index is invalid!\n"));
|
---|
932 | Status = STATUS_INVALID_PARAMETER;
|
---|
933 | }
|
---|
934 | }
|
---|
935 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
936 | {
|
---|
937 | Status = STATUS_INVALID_PARAMETER;
|
---|
938 | }
|
---|
939 |
|
---|
940 | if (fMutexAcquired)
|
---|
941 | {
|
---|
942 | ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
943 | fMutexAcquired = FALSE;
|
---|
944 | }
|
---|
945 |
|
---|
946 | break;
|
---|
947 | }
|
---|
948 |
|
---|
949 | case IOCTL_MRX_VBOX_GETGLOBALCONN:
|
---|
950 | {
|
---|
951 | ULONG cbConnectId = LowIoContext->ParamsFor.IoCtl.InputBufferLength;
|
---|
952 | uint8_t *pu8ConnectId = (uint8_t *)LowIoContext->ParamsFor.IoCtl.pInputBuffer;
|
---|
953 | ULONG cbRemoteName = LowIoContext->ParamsFor.IoCtl.OutputBufferLength;
|
---|
954 | PWCHAR pwcRemoteName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pOutputBuffer;
|
---|
955 |
|
---|
956 | int vrc;
|
---|
957 | PSHFLSTRING pString;
|
---|
958 |
|
---|
959 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN\n"));
|
---|
960 |
|
---|
961 | RxContext->InformationToReturn = 0;
|
---|
962 |
|
---|
963 | if ( !pDeviceExtension
|
---|
964 | || cbConnectId < sizeof(uint8_t))
|
---|
965 | {
|
---|
966 | Status = STATUS_INVALID_PARAMETER;
|
---|
967 | break;
|
---|
968 | }
|
---|
969 |
|
---|
970 | /* Allocate empty string where the host can store cbRemoteName bytes. */
|
---|
971 | Status = vbsfNtShflStringFromUnicodeAlloc(&pString, NULL, (uint16_t)cbRemoteName);
|
---|
972 | if (Status != STATUS_SUCCESS)
|
---|
973 | break;
|
---|
974 |
|
---|
975 | __try
|
---|
976 | {
|
---|
977 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Connection ID = %d\n",
|
---|
978 | *pu8ConnectId));
|
---|
979 |
|
---|
980 | vrc = VbglR0SfQueryMapName(&g_SfClient,
|
---|
981 | *pu8ConnectId & ~0x80 /** @todo fix properly */,
|
---|
982 | pString, ShflStringSizeOfBuffer(pString));
|
---|
983 | if ( vrc == VINF_SUCCESS
|
---|
984 | && pString->u16Length < cbRemoteName)
|
---|
985 | {
|
---|
986 | RtlCopyMemory(pwcRemoteName, pString->String.ucs2, pString->u16Length);
|
---|
987 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_GETGLOBALCONN: Returned name = %.*ls, Len = %d\n",
|
---|
988 | pString->u16Length / sizeof(WCHAR), pwcRemoteName, pString->u16Length));
|
---|
989 | RxContext->InformationToReturn = pString->u16Length;
|
---|
990 | }
|
---|
991 | else
|
---|
992 | {
|
---|
993 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
994 | }
|
---|
995 | }
|
---|
996 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
997 | {
|
---|
998 | Status = STATUS_INVALID_PARAMETER;
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | vbsfNtFreeNonPagedMem(pString);
|
---|
1002 |
|
---|
1003 | break;
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | case IOCTL_MRX_VBOX_START:
|
---|
1007 | {
|
---|
1008 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: capFobx %p\n",
|
---|
1009 | capFobx));
|
---|
1010 |
|
---|
1011 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: process: current 0x%X, RDBSS 0x%X\n",
|
---|
1012 | IoGetCurrentProcess(), RxGetRDBSSProcess()));
|
---|
1013 |
|
---|
1014 | switch (VBoxMRxState)
|
---|
1015 | {
|
---|
1016 | case MRX_VBOX_STARTABLE:
|
---|
1017 |
|
---|
1018 | Log(("VBOXSF: MRxDevFcbXXXControlFile: MRX_VBOX_STARTABLE\n"));
|
---|
1019 |
|
---|
1020 | if (capFobx)
|
---|
1021 | {
|
---|
1022 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
1023 | break;;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | InterlockedCompareExchange((PLONG)&VBoxMRxState, MRX_VBOX_START_IN_PROGRESS, MRX_VBOX_STARTABLE);
|
---|
1027 |
|
---|
1028 | case MRX_VBOX_START_IN_PROGRESS:
|
---|
1029 | Status = RxStartMinirdr(RxContext, &RxContext->PostRequest);
|
---|
1030 |
|
---|
1031 | Log(("VBOXSF: MRxDevFcbXXXControlFile: MRX_VBOX_START_IN_PROGRESS RxStartMiniRdr Status 0x%08X, post %d\n",
|
---|
1032 | Status, RxContext->PostRequest));
|
---|
1033 |
|
---|
1034 | if (Status == STATUS_REDIRECTOR_STARTED)
|
---|
1035 | {
|
---|
1036 | Status = STATUS_SUCCESS;
|
---|
1037 | break;
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | if ( Status == STATUS_PENDING
|
---|
1041 | && RxContext->PostRequest == TRUE)
|
---|
1042 | {
|
---|
1043 | /* Will be restarted in RDBSS process. */
|
---|
1044 | Status = STATUS_MORE_PROCESSING_REQUIRED;
|
---|
1045 | break;
|
---|
1046 | }
|
---|
1047 |
|
---|
1048 | /* Allow restricted users to use shared folders; works only in XP and Vista. (@@todo hack) */
|
---|
1049 | if (Status == STATUS_SUCCESS)
|
---|
1050 | {
|
---|
1051 | SECURITY_DESCRIPTOR SecurityDescriptor;
|
---|
1052 | OBJECT_ATTRIBUTES InitializedAttributes;
|
---|
1053 | HANDLE hDevice;
|
---|
1054 | IO_STATUS_BLOCK IoStatusBlock;
|
---|
1055 | UNICODE_STRING UserModeDeviceName;
|
---|
1056 |
|
---|
1057 | RtlInitUnicodeString(&UserModeDeviceName, DD_MRX_VBOX_USERMODE_SHADOW_DEV_NAME_U);
|
---|
1058 |
|
---|
1059 | /* Create empty security descriptor */
|
---|
1060 | RtlZeroMemory (&SecurityDescriptor, sizeof (SecurityDescriptor));
|
---|
1061 | Status = RtlCreateSecurityDescriptor(&SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
|
---|
1062 | if (Status != STATUS_SUCCESS)
|
---|
1063 | {
|
---|
1064 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: MRX_VBOX_START_IN_PROGRESS: RtlCreateSecurityDescriptor failed with 0x%08X!\n",
|
---|
1065 | Status));
|
---|
1066 | return Status;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | RtlZeroMemory (&InitializedAttributes, sizeof (InitializedAttributes));
|
---|
1070 | InitializeObjectAttributes(&InitializedAttributes, &UserModeDeviceName, OBJ_KERNEL_HANDLE, 0, 0);
|
---|
1071 |
|
---|
1072 | /* Open our symbolic link device name */
|
---|
1073 | Status = ZwOpenFile(&hDevice, WRITE_DAC, &InitializedAttributes, &IoStatusBlock, 0, 0);
|
---|
1074 | if (Status != STATUS_SUCCESS)
|
---|
1075 | {
|
---|
1076 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: MRX_VBOX_START_IN_PROGRESS: ZwOpenFile %ls failed with 0x%08X!\n",
|
---|
1077 | DD_MRX_VBOX_USERMODE_SHADOW_DEV_NAME_U, Status));
|
---|
1078 | return Status;
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | /* Override the discretionary access control list (DACL) settings */
|
---|
1082 | Status = ZwSetSecurityObject(hDevice, DACL_SECURITY_INFORMATION, &SecurityDescriptor);
|
---|
1083 | if (Status != STATUS_SUCCESS)
|
---|
1084 | {
|
---|
1085 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: MRX_VBOX_START_IN_PROGRESS: ZwSetSecurityObject failed with 0x%08X!\n",
|
---|
1086 | Status));
|
---|
1087 | return Status;
|
---|
1088 | }
|
---|
1089 |
|
---|
1090 | Status = ZwClose(hDevice);
|
---|
1091 | if (Status != STATUS_SUCCESS)
|
---|
1092 | {
|
---|
1093 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: MRX_VBOX_START_IN_PROGRESS: ZwClose failed with 0x%08X\n",
|
---|
1094 | Status));
|
---|
1095 | return Status;
|
---|
1096 | }
|
---|
1097 | }
|
---|
1098 | break;
|
---|
1099 |
|
---|
1100 | case MRX_VBOX_STARTED:
|
---|
1101 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: MRX_VBOX_STARTED: Already started\n"));
|
---|
1102 | Status = STATUS_SUCCESS;
|
---|
1103 | break;
|
---|
1104 |
|
---|
1105 | default:
|
---|
1106 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: Invalid state (%d)!\n",
|
---|
1107 | VBoxMRxState));
|
---|
1108 | Status = STATUS_INVALID_PARAMETER;
|
---|
1109 | break;
|
---|
1110 | }
|
---|
1111 |
|
---|
1112 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_START: Returned 0x%08X\n",
|
---|
1113 | Status));
|
---|
1114 | break;
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | case IOCTL_MRX_VBOX_STOP:
|
---|
1118 | {
|
---|
1119 | MRX_VBOX_STATE CurrentState;
|
---|
1120 |
|
---|
1121 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_STOP: capFobx %p\n",
|
---|
1122 | capFobx));
|
---|
1123 |
|
---|
1124 | if (capFobx)
|
---|
1125 | {
|
---|
1126 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
1127 | break;
|
---|
1128 | }
|
---|
1129 |
|
---|
1130 | if (RxContext->RxDeviceObject->NumberOfActiveFcbs > 0)
|
---|
1131 | {
|
---|
1132 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_STOP: Open handles = %d\n",
|
---|
1133 | RxContext->RxDeviceObject->NumberOfActiveFcbs));
|
---|
1134 | Status = STATUS_REDIRECTOR_HAS_OPEN_HANDLES;
|
---|
1135 | break;
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | CurrentState = (MRX_VBOX_STATE)InterlockedCompareExchange((PLONG) & VBoxMRxState, MRX_VBOX_STARTABLE, MRX_VBOX_STARTED);
|
---|
1139 |
|
---|
1140 | Status = RxStopMinirdr(RxContext, &RxContext->PostRequest);
|
---|
1141 | Log(("VBOXSF: MRxDevFcbXXXControlFile: IOCTL_MRX_VBOX_STOP: Returned 0x%08X\n",
|
---|
1142 | Status));
|
---|
1143 |
|
---|
1144 | if (Status == STATUS_PENDING && RxContext->PostRequest == TRUE)
|
---|
1145 | Status = STATUS_MORE_PROCESSING_REQUIRED;
|
---|
1146 | break;
|
---|
1147 | }
|
---|
1148 |
|
---|
1149 | default:
|
---|
1150 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
1151 | break;
|
---|
1152 | }
|
---|
1153 | break;
|
---|
1154 | }
|
---|
1155 |
|
---|
1156 | case IRP_MJ_INTERNAL_DEVICE_CONTROL:
|
---|
1157 | {
|
---|
1158 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
1159 | break;
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | default:
|
---|
1163 | Log(("VBOXSF: MRxDevFcbXXXControlFile: unimplemented major function 0x%02X\n",
|
---|
1164 | RxContext->MajorFunction));
|
---|
1165 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
1166 | break;
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | Log(("VBOXSF: MRxDevFcbXXXControlFile: Status = 0x%08X, Info = 0x%08X\n",
|
---|
1170 | Status, RxContext->InformationToReturn));
|
---|
1171 |
|
---|
1172 | return Status;
|
---|
1173 | }
|
---|
1174 |
|
---|
1175 | static NTSTATUS vbsfVerifyConnectionName(PUNICODE_STRING ConnectionName)
|
---|
1176 | {
|
---|
1177 | /* Check that the connection name is valid:
|
---|
1178 | * "\Device\VBoxMiniRdr\;X:\vboxsvr\sf"
|
---|
1179 | */
|
---|
1180 | NTSTATUS Status = STATUS_BAD_NETWORK_NAME;
|
---|
1181 |
|
---|
1182 | ULONG i;
|
---|
1183 | PWCHAR pwc;
|
---|
1184 | PWCHAR pwc1;
|
---|
1185 |
|
---|
1186 | static PWCHAR spwszPrefix = L"\\Device\\VBoxMiniRdr\\;";
|
---|
1187 |
|
---|
1188 | /* Unicode chars in the string. */
|
---|
1189 | ULONG cConnectionName = ConnectionName->Length / sizeof(WCHAR);
|
---|
1190 | ULONG cRemainingName;
|
---|
1191 |
|
---|
1192 | /* Check that the name starts with correct prefix. */
|
---|
1193 | pwc1 = &spwszPrefix[0];
|
---|
1194 | pwc = ConnectionName->Buffer;
|
---|
1195 | for (i = 0; i < cConnectionName; i++, pwc1++, pwc++)
|
---|
1196 | {
|
---|
1197 | if (*pwc1 == 0 || *pwc == 0 || *pwc1 != *pwc)
|
---|
1198 | break;
|
---|
1199 | }
|
---|
1200 |
|
---|
1201 | cRemainingName = cConnectionName - i;
|
---|
1202 |
|
---|
1203 | Log(("VBOXSF: vbsfVerifyConnectionName: prefix %d remaining %d [%.*ls]\n",
|
---|
1204 | *pwc1 == 0, cRemainingName, cRemainingName, &ConnectionName->Buffer[i]));
|
---|
1205 |
|
---|
1206 | if (*pwc1 == 0)
|
---|
1207 | {
|
---|
1208 | /* pwc should point to a drive letter followed by ':\' that is at least 3 chars more. */
|
---|
1209 | if (cRemainingName >= 3)
|
---|
1210 | {
|
---|
1211 | if ( pwc[0] >= L'A' && pwc[0] <= L'Z'
|
---|
1212 | && pwc[1] == L':')
|
---|
1213 | {
|
---|
1214 | pwc += 2;
|
---|
1215 | cRemainingName -= 2;
|
---|
1216 |
|
---|
1217 | /** @todo should also check that the drive letter corresponds to the name. */
|
---|
1218 | if (vboxIsPrefixOK(pwc, cRemainingName * sizeof (WCHAR)))
|
---|
1219 | Status = STATUS_SUCCESS;
|
---|
1220 | }
|
---|
1221 | }
|
---|
1222 | }
|
---|
1223 |
|
---|
1224 | return Status;
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | static HANDLE vbsfOpenConnectionHandle(PUNICODE_STRING ConnectionName, NTSTATUS *prcNt)
|
---|
1228 | {
|
---|
1229 | NTSTATUS Status;
|
---|
1230 | IO_STATUS_BLOCK IoStatusBlock;
|
---|
1231 | OBJECT_ATTRIBUTES ObjectAttributes;
|
---|
1232 |
|
---|
1233 | HANDLE Handle = INVALID_HANDLE_VALUE;
|
---|
1234 |
|
---|
1235 | Log(("VBOXSF: vbsfOpenConnectionHandle: ConnectionName = %.*ls\n",
|
---|
1236 | ConnectionName->Length / sizeof(WCHAR), ConnectionName->Buffer));
|
---|
1237 |
|
---|
1238 | Status = vbsfVerifyConnectionName(ConnectionName);
|
---|
1239 |
|
---|
1240 | if (NT_SUCCESS(Status))
|
---|
1241 | {
|
---|
1242 | /* Have to create a OBJ_KERNEL_HANDLE. Otherwise the driver verifier on Windows 7 bugchecks. */
|
---|
1243 | InitializeObjectAttributes(&ObjectAttributes,
|
---|
1244 | ConnectionName,
|
---|
1245 | OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
---|
1246 | NULL,
|
---|
1247 | NULL);
|
---|
1248 |
|
---|
1249 | Status = ZwCreateFile(&Handle,
|
---|
1250 | SYNCHRONIZE,
|
---|
1251 | &ObjectAttributes,
|
---|
1252 | &IoStatusBlock,
|
---|
1253 | NULL,
|
---|
1254 | FILE_ATTRIBUTE_NORMAL,
|
---|
1255 | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
---|
1256 | FILE_OPEN_IF,
|
---|
1257 | FILE_CREATE_TREE_CONNECTION | FILE_SYNCHRONOUS_IO_NONALERT,
|
---|
1258 | NULL,
|
---|
1259 | 0);
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | if ( Status != STATUS_SUCCESS
|
---|
1263 | || Handle == INVALID_HANDLE_VALUE)
|
---|
1264 | {
|
---|
1265 | Log(("VBOXSF: vbsfOpenConnectionHandle: ZwCreateFile failed status 0x%08X or invalid handle!\n", Status));
|
---|
1266 | if (prcNt)
|
---|
1267 | *prcNt = !NT_SUCCESS(Status) ? Status : STATUS_UNSUCCESSFUL;
|
---|
1268 | Handle = INVALID_HANDLE_VALUE;
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | return Handle;
|
---|
1272 | }
|
---|
1273 |
|
---|
1274 | NTSTATUS vbsfNtCreateConnection(IN PRX_CONTEXT RxContext, OUT PBOOLEAN PostToFsp)
|
---|
1275 | {
|
---|
1276 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1277 |
|
---|
1278 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension;
|
---|
1279 |
|
---|
1280 | PLOWIO_CONTEXT LowIoContext;
|
---|
1281 | ULONG cbConnectName;
|
---|
1282 | PWCHAR pwcConnectName;
|
---|
1283 |
|
---|
1284 | HANDLE Handle;
|
---|
1285 | UNICODE_STRING FileName;
|
---|
1286 |
|
---|
1287 | BOOLEAN fMutexAcquired = FALSE;
|
---|
1288 |
|
---|
1289 | Log(("VBOXSF: vbsfNtCreateConnection\n"));
|
---|
1290 |
|
---|
1291 | if (!BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT))
|
---|
1292 | {
|
---|
1293 | Log(("VBOXSF: vbsfNtCreateConnection: post to file system process\n"));
|
---|
1294 | *PostToFsp = TRUE;
|
---|
1295 | return STATUS_PENDING;
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
1299 | if (!pDeviceExtension)
|
---|
1300 | return STATUS_INVALID_PARAMETER;
|
---|
1301 |
|
---|
1302 | LowIoContext = &RxContext->LowIoContext;
|
---|
1303 | cbConnectName = LowIoContext->ParamsFor.IoCtl.InputBufferLength;
|
---|
1304 | pwcConnectName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pInputBuffer;
|
---|
1305 |
|
---|
1306 | if (cbConnectName == 0 || !pwcConnectName)
|
---|
1307 | {
|
---|
1308 | Log(("VBOXSF: vbsfNtCreateConnection: Connection name / length is invalid!\n"));
|
---|
1309 | return STATUS_INVALID_PARAMETER;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | __try
|
---|
1313 | {
|
---|
1314 | Log(("VBOXSF: vbsfNtCreateConnection: Name = %.*ls, Len = %d\n",
|
---|
1315 | cbConnectName / sizeof(WCHAR), pwcConnectName, cbConnectName));
|
---|
1316 |
|
---|
1317 | FileName.Buffer = pwcConnectName;
|
---|
1318 | FileName.Length = (USHORT)cbConnectName;
|
---|
1319 | FileName.MaximumLength = (USHORT)cbConnectName;
|
---|
1320 |
|
---|
1321 | Handle = vbsfOpenConnectionHandle(&FileName, NULL);
|
---|
1322 |
|
---|
1323 | if (Handle != INVALID_HANDLE_VALUE)
|
---|
1324 | {
|
---|
1325 | PWCHAR pwc;
|
---|
1326 | ULONG i;
|
---|
1327 |
|
---|
1328 | ZwClose(Handle);
|
---|
1329 |
|
---|
1330 | /* Skip the "\Device\VBoxMiniRdr\;X:" of the string "\Device\VBoxMiniRdr\;X:\vboxsrv\sf" */
|
---|
1331 | pwc = pwcConnectName;
|
---|
1332 | for (i = 0; i < cbConnectName; i += sizeof(WCHAR))
|
---|
1333 | {
|
---|
1334 | if (*pwc == L':')
|
---|
1335 | break;
|
---|
1336 | pwc++;
|
---|
1337 | }
|
---|
1338 |
|
---|
1339 | if (i >= sizeof(WCHAR) && i < cbConnectName)
|
---|
1340 | {
|
---|
1341 | pwc--; /* Go back to the drive letter, "X" for example. */
|
---|
1342 |
|
---|
1343 | if (*pwc >= L'A' && *pwc <= L'Z') /* Are we in range? */
|
---|
1344 | {
|
---|
1345 | uint32_t idx = *pwc - L'A'; /* Get the index based on the driver letter numbers (26). */
|
---|
1346 |
|
---|
1347 | if (idx >= RTL_NUMBER_OF(pDeviceExtension->cLocalConnections))
|
---|
1348 | {
|
---|
1349 | Log(("VBOXSF: vbsfNtCreateConnection: Index 0x%x is invalid!\n",
|
---|
1350 | idx));
|
---|
1351 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
1352 | }
|
---|
1353 | else
|
---|
1354 | {
|
---|
1355 | ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
1356 | fMutexAcquired = TRUE;
|
---|
1357 |
|
---|
1358 | if (pDeviceExtension->wszLocalConnectionName[idx] != NULL)
|
---|
1359 | {
|
---|
1360 | Log(("VBOXSF: vbsfNtCreateConnection: LocalConnectionName at index %d is NOT empty!\n",
|
---|
1361 | idx));
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | pDeviceExtension->wszLocalConnectionName[idx] = (PUNICODE_STRING)vbsfNtAllocNonPagedMem(sizeof(UNICODE_STRING) + cbConnectName);
|
---|
1365 |
|
---|
1366 | if (!pDeviceExtension->wszLocalConnectionName[idx])
|
---|
1367 | {
|
---|
1368 | Log(("VBOXSF: vbsfNtCreateConnection: LocalConnectionName at index %d NOT allocated!\n",
|
---|
1369 | idx));
|
---|
1370 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
1371 | }
|
---|
1372 | else
|
---|
1373 | {
|
---|
1374 | PUNICODE_STRING pRemoteName = pDeviceExtension->wszLocalConnectionName[idx];
|
---|
1375 |
|
---|
1376 | pRemoteName->Buffer = (PWSTR)(pRemoteName + 1);
|
---|
1377 | pRemoteName->Length = (USHORT)(cbConnectName - i - sizeof(WCHAR));
|
---|
1378 | pRemoteName->MaximumLength = pRemoteName->Length;
|
---|
1379 | RtlCopyMemory(&pRemoteName->Buffer[0], pwc+2, pRemoteName->Length);
|
---|
1380 |
|
---|
1381 | Log(("VBOXSF: vbsfNtCreateConnection: RemoteName %.*ls, Len = %d\n",
|
---|
1382 | pRemoteName->Length / sizeof(WCHAR), pRemoteName->Buffer, pRemoteName->Length));
|
---|
1383 |
|
---|
1384 | pDeviceExtension->cLocalConnections[idx] = TRUE;
|
---|
1385 | }
|
---|
1386 |
|
---|
1387 | ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
1388 | fMutexAcquired = FALSE;
|
---|
1389 | }
|
---|
1390 | }
|
---|
1391 | }
|
---|
1392 | else
|
---|
1393 | {
|
---|
1394 | Log(("VBOXSF: vbsfNtCreateConnection: bad format\n"));
|
---|
1395 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
1396 | }
|
---|
1397 | }
|
---|
1398 | else
|
---|
1399 | {
|
---|
1400 | Log(("VBOXSF: vbsfNtCreateConnection: connection was not found\n"));
|
---|
1401 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
1402 | }
|
---|
1403 | }
|
---|
1404 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
1405 | {
|
---|
1406 | Status = STATUS_INVALID_PARAMETER;
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | if (fMutexAcquired)
|
---|
1410 | {
|
---|
1411 | ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
1412 | fMutexAcquired = FALSE;
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 | return Status;
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | NTSTATUS vbsfNtDeleteConnection(IN PRX_CONTEXT RxContext, OUT PBOOLEAN PostToFsp)
|
---|
1419 | {
|
---|
1420 | NTSTATUS Status;
|
---|
1421 | UNICODE_STRING FileName;
|
---|
1422 | HANDLE Handle;
|
---|
1423 | PLOWIO_CONTEXT LowIoContext;
|
---|
1424 | PWCHAR pwcConnectName;
|
---|
1425 | ULONG cbConnectName;
|
---|
1426 | PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension;
|
---|
1427 |
|
---|
1428 | BOOLEAN fMutexAcquired = FALSE;
|
---|
1429 |
|
---|
1430 | Log(("VBOXSF: vbsfNtDeleteConnection\n"));
|
---|
1431 |
|
---|
1432 | if (!BooleanFlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT))
|
---|
1433 | {
|
---|
1434 | Log(("VBOXSF: vbsfNtDeleteConnection: post to file system process\n"));
|
---|
1435 | *PostToFsp = TRUE;
|
---|
1436 | return STATUS_PENDING;
|
---|
1437 | }
|
---|
1438 |
|
---|
1439 | LowIoContext = &RxContext->LowIoContext;
|
---|
1440 | pwcConnectName = (PWCHAR)LowIoContext->ParamsFor.IoCtl.pInputBuffer;
|
---|
1441 | cbConnectName = LowIoContext->ParamsFor.IoCtl.InputBufferLength;
|
---|
1442 |
|
---|
1443 | pDeviceExtension = VBoxMRxGetDeviceExtension(RxContext);
|
---|
1444 | if (!pDeviceExtension)
|
---|
1445 | return STATUS_INVALID_PARAMETER;
|
---|
1446 |
|
---|
1447 | __try
|
---|
1448 | {
|
---|
1449 | Log(("VBOXSF: vbsfNtDeleteConnection: pwcConnectName = %.*ls\n",
|
---|
1450 | cbConnectName / sizeof(WCHAR), pwcConnectName));
|
---|
1451 |
|
---|
1452 | FileName.Buffer = pwcConnectName;
|
---|
1453 | FileName.Length = (USHORT)cbConnectName;
|
---|
1454 | FileName.MaximumLength = (USHORT)cbConnectName;
|
---|
1455 |
|
---|
1456 | Handle = vbsfOpenConnectionHandle(&FileName, &Status);
|
---|
1457 | if (Handle != INVALID_HANDLE_VALUE)
|
---|
1458 | {
|
---|
1459 | PFILE_OBJECT pFileObject;
|
---|
1460 | Status = ObReferenceObjectByHandle(Handle, 0L, NULL, KernelMode, (PVOID *)&pFileObject, NULL);
|
---|
1461 |
|
---|
1462 | Log(("VBOXSF: vbsfNtDeleteConnection: ObReferenceObjectByHandle Status 0x%08X\n",
|
---|
1463 | Status));
|
---|
1464 |
|
---|
1465 | if (NT_SUCCESS(Status))
|
---|
1466 | {
|
---|
1467 | PFOBX Fobx = (PFOBX)pFileObject->FsContext2;
|
---|
1468 | Log(("VBOXSF: vbsfNtDeleteConnection: Fobx %p\n", Fobx));
|
---|
1469 |
|
---|
1470 | if (Fobx && NodeType(Fobx) == RDBSS_NTC_V_NETROOT)
|
---|
1471 | {
|
---|
1472 | PV_NET_ROOT VNetRoot = (PV_NET_ROOT)Fobx;
|
---|
1473 |
|
---|
1474 | #ifdef __cplusplus /* C version points at NET_ROOT, C++ points at MRX_NET_ROOT. Weird. */
|
---|
1475 | Status = RxFinalizeConnection((PNET_ROOT)VNetRoot->pNetRoot, VNetRoot, TRUE);
|
---|
1476 | #else
|
---|
1477 | Status = RxFinalizeConnection(VNetRoot->NetRoot, VNetRoot, TRUE);
|
---|
1478 | #endif
|
---|
1479 | }
|
---|
1480 | else
|
---|
1481 | {
|
---|
1482 | Log(("VBOXSF: vbsfNtDeleteConnection: wrong FsContext2\n"));
|
---|
1483 | Status = STATUS_INVALID_DEVICE_REQUEST;
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | ObDereferenceObject(pFileObject);
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | ZwClose(Handle);
|
---|
1490 |
|
---|
1491 | if (NT_SUCCESS(Status))
|
---|
1492 | {
|
---|
1493 | PWCHAR pwc;
|
---|
1494 | ULONG i;
|
---|
1495 |
|
---|
1496 | /* Skip the "\Device\VBoxMiniRdr\;X:" of the string "\Device\VBoxMiniRdr\;X:\vboxsrv\sf" */
|
---|
1497 | pwc = pwcConnectName;
|
---|
1498 | for (i = 0; i < cbConnectName; i += sizeof(WCHAR))
|
---|
1499 | {
|
---|
1500 | if (*pwc == L':')
|
---|
1501 | {
|
---|
1502 | break;
|
---|
1503 | }
|
---|
1504 | pwc++;
|
---|
1505 | }
|
---|
1506 |
|
---|
1507 | if (i >= sizeof(WCHAR) && i < cbConnectName)
|
---|
1508 | {
|
---|
1509 | pwc--;
|
---|
1510 |
|
---|
1511 | if (*pwc >= L'A' && *pwc <= L'Z')
|
---|
1512 | {
|
---|
1513 | uint32_t idx = *pwc - L'A';
|
---|
1514 |
|
---|
1515 | if (idx >= RTL_NUMBER_OF(pDeviceExtension->cLocalConnections))
|
---|
1516 | {
|
---|
1517 | Log(("VBOXSF: vbsfNtDeleteConnection: Index 0x%x is invalid!\n",
|
---|
1518 | idx));
|
---|
1519 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
1520 | }
|
---|
1521 | else
|
---|
1522 | {
|
---|
1523 | ExAcquireFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
1524 | fMutexAcquired = TRUE;
|
---|
1525 |
|
---|
1526 | pDeviceExtension->cLocalConnections[idx] = FALSE;
|
---|
1527 |
|
---|
1528 | /* Free saved name */
|
---|
1529 | if (pDeviceExtension->wszLocalConnectionName[idx])
|
---|
1530 | {
|
---|
1531 | vbsfNtFreeNonPagedMem(pDeviceExtension->wszLocalConnectionName[idx]);
|
---|
1532 | pDeviceExtension->wszLocalConnectionName[idx] = NULL;
|
---|
1533 | }
|
---|
1534 |
|
---|
1535 | ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
1536 | fMutexAcquired = FALSE;
|
---|
1537 |
|
---|
1538 | Log(("VBOXSF: vbsfNtDeleteConnection: deleted index 0x%x\n",
|
---|
1539 | idx));
|
---|
1540 | }
|
---|
1541 | }
|
---|
1542 | }
|
---|
1543 | else
|
---|
1544 | {
|
---|
1545 | Log(("VBOXSF: vbsfNtCreateConnection: bad format\n"));
|
---|
1546 | Status = STATUS_BAD_NETWORK_NAME;
|
---|
1547 | }
|
---|
1548 | }
|
---|
1549 | }
|
---|
1550 | }
|
---|
1551 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
1552 | {
|
---|
1553 | Status = STATUS_INVALID_PARAMETER;
|
---|
1554 | }
|
---|
1555 |
|
---|
1556 | if (fMutexAcquired)
|
---|
1557 | {
|
---|
1558 | ExReleaseFastMutex(&pDeviceExtension->mtxLocalCon);
|
---|
1559 | fMutexAcquired = FALSE;
|
---|
1560 | }
|
---|
1561 |
|
---|
1562 | Log(("VBOXSF: vbsfNtDeleteConnection: Status 0x%08X\n", Status));
|
---|
1563 | return Status;
|
---|
1564 | }
|
---|
1565 |
|
---|
1566 | NTSTATUS VBoxMRxQueryEaInfo(IN OUT PRX_CONTEXT RxContext)
|
---|
1567 | {
|
---|
1568 | RT_NOREF(RxContext);
|
---|
1569 | Log(("VBOXSF: MRxQueryEaInfo: Ea buffer len remaining is %d\n", RxContext->Info.LengthRemaining));
|
---|
1570 | return STATUS_SUCCESS;
|
---|
1571 | }
|
---|
1572 |
|
---|
1573 | NTSTATUS VBoxMRxSetEaInfo(IN OUT PRX_CONTEXT RxContext)
|
---|
1574 | {
|
---|
1575 | RT_NOREF(RxContext);
|
---|
1576 | Log(("VBOXSF: MRxSetEaInfo\n"));
|
---|
1577 | return STATUS_NOT_IMPLEMENTED;
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | NTSTATUS VBoxMRxFsCtl(IN OUT PRX_CONTEXT RxContext)
|
---|
1581 | {
|
---|
1582 | RT_NOREF(RxContext);
|
---|
1583 | Log(("VBOXSF: MRxFsCtl\n"));
|
---|
1584 | return STATUS_INVALID_DEVICE_REQUEST;
|
---|
1585 | }
|
---|
1586 |
|
---|
1587 | NTSTATUS VBoxMRxNotifyChangeDirectory(IN OUT PRX_CONTEXT RxContext)
|
---|
1588 | {
|
---|
1589 | RT_NOREF(RxContext);
|
---|
1590 | Log(("VBOXSF: MRxNotifyChangeDirectory\n"));
|
---|
1591 | return STATUS_NOT_IMPLEMENTED;
|
---|
1592 | }
|
---|
1593 |
|
---|
1594 | static NTSTATUS vbsfQuerySdInfo(PVOID pvBuffer, ULONG cbBuffer, SECURITY_INFORMATION SecurityInformation, ULONG *pcbOut)
|
---|
1595 | {
|
---|
1596 | /* What a public SMB share would return. */
|
---|
1597 | static SID_IDENTIFIER_AUTHORITY sIA = SECURITY_NT_AUTHORITY;
|
---|
1598 | #define SUB_AUTHORITY_COUNT 2
|
---|
1599 | static const ULONG saSubAuthorityOwner[] = { SECURITY_NT_NON_UNIQUE, DOMAIN_USER_RID_GUEST };
|
---|
1600 | static const ULONG saSubAuthorityGroup[] = { SECURITY_NT_NON_UNIQUE, DOMAIN_GROUP_RID_GUESTS };
|
---|
1601 |
|
---|
1602 | SECURITY_DESCRIPTOR_RELATIVE *pSD = (SECURITY_DESCRIPTOR_RELATIVE *)pvBuffer;
|
---|
1603 | ULONG cbSD = 0; /* Size of returned security descriptor. */
|
---|
1604 | ULONG cbAdd; /* How many bytes to add to the buffer for each component of the security descriptor. */
|
---|
1605 |
|
---|
1606 | cbAdd = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
|
---|
1607 | if (cbSD + cbAdd <= cbBuffer)
|
---|
1608 | {
|
---|
1609 | pSD->Revision = SECURITY_DESCRIPTOR_REVISION1;
|
---|
1610 | pSD->Sbz1 = 0;
|
---|
1611 | pSD->Control = SE_SELF_RELATIVE;
|
---|
1612 | pSD->Owner = 0;
|
---|
1613 | pSD->Group = 0;
|
---|
1614 | pSD->Sacl = 0;
|
---|
1615 | pSD->Dacl = 0;
|
---|
1616 | }
|
---|
1617 | cbSD += cbAdd;
|
---|
1618 |
|
---|
1619 | if (SecurityInformation & OWNER_SECURITY_INFORMATION)
|
---|
1620 | {
|
---|
1621 | cbAdd = RT_UOFFSETOF(SID, SubAuthority) + SUB_AUTHORITY_COUNT * sizeof(ULONG);
|
---|
1622 | if (cbSD + cbAdd <= cbBuffer)
|
---|
1623 | {
|
---|
1624 | SID *pSID = (SID *)((uint8_t *)pSD + cbSD);
|
---|
1625 | pSID->Revision = 1;
|
---|
1626 | pSID->SubAuthorityCount = SUB_AUTHORITY_COUNT;
|
---|
1627 | pSID->IdentifierAuthority = sIA;
|
---|
1628 | memcpy(pSID->SubAuthority, saSubAuthorityOwner, SUB_AUTHORITY_COUNT * sizeof(ULONG));
|
---|
1629 |
|
---|
1630 | pSD->Owner = cbSD;
|
---|
1631 | }
|
---|
1632 | cbSD += cbAdd;
|
---|
1633 | }
|
---|
1634 |
|
---|
1635 | if (SecurityInformation & GROUP_SECURITY_INFORMATION)
|
---|
1636 | {
|
---|
1637 | cbAdd = RT_UOFFSETOF(SID, SubAuthority) + SUB_AUTHORITY_COUNT * sizeof(ULONG);
|
---|
1638 | if (cbSD + cbAdd <= cbBuffer)
|
---|
1639 | {
|
---|
1640 | SID *pSID = (SID *)((uint8_t *)pSD + cbSD);
|
---|
1641 | pSID->Revision = 1;
|
---|
1642 | pSID->SubAuthorityCount = SUB_AUTHORITY_COUNT;
|
---|
1643 | pSID->IdentifierAuthority = sIA;
|
---|
1644 | memcpy(pSID->SubAuthority, saSubAuthorityGroup, SUB_AUTHORITY_COUNT * sizeof(ULONG));
|
---|
1645 |
|
---|
1646 | pSD->Group = cbSD;
|
---|
1647 | }
|
---|
1648 | cbSD += cbAdd;
|
---|
1649 | }
|
---|
1650 |
|
---|
1651 | #undef SUB_AUTHORITY_COUNT
|
---|
1652 |
|
---|
1653 | *pcbOut = cbSD;
|
---|
1654 | return STATUS_SUCCESS;
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | NTSTATUS VBoxMRxQuerySdInfo(IN OUT PRX_CONTEXT RxContext)
|
---|
1658 | {
|
---|
1659 | NTSTATUS Status;
|
---|
1660 |
|
---|
1661 | PVOID pvBuffer = RxContext->Info.Buffer;
|
---|
1662 | ULONG cbBuffer = RxContext->Info.LengthRemaining;
|
---|
1663 | SECURITY_INFORMATION SecurityInformation = RxContext->QuerySecurity.SecurityInformation;
|
---|
1664 |
|
---|
1665 | ULONG cbSD = 0;
|
---|
1666 |
|
---|
1667 | Log(("VBOXSF: MRxQuerySdInfo: Buffer %p, Length %d, SecurityInformation 0x%x\n",
|
---|
1668 | pvBuffer, cbBuffer, SecurityInformation));
|
---|
1669 |
|
---|
1670 | Status = vbsfQuerySdInfo(pvBuffer, cbBuffer, SecurityInformation, &cbSD);
|
---|
1671 | if (NT_SUCCESS(Status))
|
---|
1672 | {
|
---|
1673 | RxContext->InformationToReturn = cbSD;
|
---|
1674 | if (RxContext->InformationToReturn > cbBuffer)
|
---|
1675 | {
|
---|
1676 | Status = STATUS_BUFFER_OVERFLOW;
|
---|
1677 | }
|
---|
1678 | }
|
---|
1679 |
|
---|
1680 | Log(("VBOXSF: MRxQuerySdInfo: Status 0x%08X, InformationToReturn %d\n",
|
---|
1681 | Status, RxContext->InformationToReturn));
|
---|
1682 | return Status;
|
---|
1683 | }
|
---|
1684 |
|
---|
1685 | NTSTATUS VBoxMRxSetSdInfo(IN OUT struct _RX_CONTEXT * RxContext)
|
---|
1686 | {
|
---|
1687 | RT_NOREF(RxContext);
|
---|
1688 | Log(("VBOXSF: MRxSetSdInfo\n"));
|
---|
1689 | return STATUS_NOT_IMPLEMENTED;
|
---|
1690 | }
|
---|
1691 |
|
---|
1692 | /*
|
---|
1693 | * WML stubs which are referenced by rdbsslib.
|
---|
1694 | */
|
---|
1695 | extern "C" NTSTATUS WmlTinySystemControl(IN OUT PVOID pWmiLibInfo, IN PVOID pDevObj, IN PVOID pIrp)
|
---|
1696 | {
|
---|
1697 | RT_NOREF(pWmiLibInfo, pDevObj, pIrp);
|
---|
1698 | return STATUS_WMI_GUID_NOT_FOUND;
|
---|
1699 | }
|
---|
1700 |
|
---|
1701 | extern "C" ULONG WmlTrace(IN ULONG ulType, IN PVOID pTraceUuid, IN ULONG64 ullLogger, ...)
|
---|
1702 | {
|
---|
1703 | RT_NOREF(ulType, pTraceUuid, ullLogger);
|
---|
1704 | return STATUS_SUCCESS;
|
---|
1705 | }
|
---|
1706 |
|
---|