VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/SharedFolders/driver/net.c@ 51593

Last change on this file since 51593 was 51254, checked in by vboxsync, 11 years ago

Additions/SharedFolders: fixed ShflStringInitBuffer(), do really use this function for initializing the SHFLSTRING content; some cosmetcis

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
1/** @file
2 *
3 * VirtualBox Windows Guest Shared Folders
4 *
5 * File System Driver network redirector subsystem routines
6 */
7
8/*
9 * Copyright (C) 2012 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "vbsf.h"
21
22NTSTATUS VBoxMRxUpdateNetRootState(IN OUT PMRX_NET_ROOT pNetRoot)
23{
24 Log(("VBOXSF: MRxUpdateNetRootState\n"));
25 return STATUS_NOT_IMPLEMENTED;
26}
27
28static void vbsfUpdateNetRoot(PMRX_NET_ROOT pNetRoot)
29{
30 Log(("VBOXSF: vbsfUpdateNetRoot: NetRoot = 0x%x Type = 0x%x\n",
31 pNetRoot, pNetRoot->Type));
32
33 switch (pNetRoot->Type)
34 {
35 case NET_ROOT_DISK:
36 pNetRoot->DeviceType = RxDeviceType(DISK);
37 break;
38 case NET_ROOT_PIPE:
39 pNetRoot->DeviceType = RxDeviceType(NAMED_PIPE);
40 break;
41 case NET_ROOT_COMM:
42 pNetRoot->DeviceType = RxDeviceType(SERIAL_PORT);
43 break;
44 case NET_ROOT_PRINT:
45 pNetRoot->DeviceType = RxDeviceType(PRINTER);
46 break;
47 case NET_ROOT_MAILSLOT:
48 pNetRoot->DeviceType = RxDeviceType(MAILSLOT);
49 break;
50 case NET_ROOT_WILD:
51 /* We get this type when for example Windows Media player opens an MP3 file.
52 * This NetRoot has the same remote path (\\vboxsrv\dir) as other NetRoots,
53 * which were created earlier and which were NET_ROOT_DISK.
54 *
55 * In the beginning of the function (UpdateNetRoot) the DDK sample sets
56 * pNetRoot->Type of newly created NetRoots using a value previously
57 * pstored in a NetRootExtension. One NetRootExtensions is used for a single
58 * remote path and reused by a few NetRoots, if they point to the same path.
59 *
60 * To simplify things we just set the type to DISK here (we do not support
61 * anything else anyway), and update the DeviceType correspondingly.
62 */
63 pNetRoot->Type = NET_ROOT_DISK;
64 pNetRoot->DeviceType = RxDeviceType(DISK);
65 break;
66 default:
67 AssertMsgFailed(("VBOXSF: vbsfUpdateNetRoot: Invalid net root type! Type = 0x%x\n",
68 pNetRoot->Type));
69 break;
70 }
71
72 Log(("VBOXSF: vbsfUpdateNetRoot: leaving pNetRoot->DeviceType = 0x%x\n",
73 pNetRoot->DeviceType));
74}
75
76NTSTATUS VBoxMRxCreateVNetRoot(IN PMRX_CREATENETROOT_CONTEXT pCreateNetRootContext)
77{
78 NTSTATUS Status;
79
80 PMRX_V_NET_ROOT pVNetRoot = (PMRX_V_NET_ROOT)pCreateNetRootContext->pVNetRoot;
81
82 PMRX_VBOX_DEVICE_EXTENSION pDeviceExtension = VBoxMRxGetDeviceExtension(pCreateNetRootContext->RxContext);
83 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(pVNetRoot->pNetRoot);
84
85 PMRX_NET_ROOT pNetRoot = pVNetRoot->pNetRoot;
86 PMRX_SRV_CALL pSrvCall = pNetRoot->pSrvCall;
87
88 BOOLEAN fInitializeNetRoot = FALSE;
89
90 Log(("VBOXSF: MRxCreateVNetRoot: pNetRoot = %p, pNetRootExtension = %p, name = [%.*ls]\n",
91 pNetRoot, pNetRootExtension, pNetRoot->pNetRootName->Length / sizeof(WCHAR), pNetRoot->pNetRootName->Buffer));
92
93 /* IMPORTANT:
94 *
95 * This function must always call 'pCreateNetRootContext->Callback(pCreateNetRootContext)' before
96 * returning and then return STATUS_PENDING. Otherwise Win64 will hang.
97 */
98
99 if (pNetRoot->Type == NET_ROOT_PIPE)
100 {
101 /* VBoxSF claims everything which starts with '\vboxsrv'.
102 *
103 * So sometimes the system tries to open \vboxsrv\ipc$ pipe for DFS
104 * and fails the application call if an unexpected code is returned.
105 *
106 * According to MSDN: The Windows client returns STATUS_MORE_PROCESSING_REQUIRED to the calling
107 * application to indicate that the path does not correspond to a DFS Namespace.
108 */
109 pVNetRoot->Context = NULL;
110
111 if (pNetRoot->pNetRootName->Length >= 13 * sizeof (WCHAR)) /* Number of bytes in '\vboxsrv\ipc$' unicode string. */
112 {
113 const WCHAR *Suffix = &pNetRoot->pNetRootName->Buffer[8]; /* Number of chars in '\vboxsrv' */
114
115 if ( Suffix[0] == L'\\'
116 && (Suffix[1] == L'I' || Suffix[1] == L'i')
117 && (Suffix[2] == L'P' || Suffix[2] == L'p')
118 && (Suffix[3] == L'C' || Suffix[3] == L'c')
119 && Suffix[4] == L'$'
120 )
121 {
122 if ( pNetRoot->pNetRootName->Length == 13 * sizeof (WCHAR)
123 || (Suffix[5] == L'\\' || Suffix[5] == 0)
124 )
125 {
126 /* It is '\vboxsrv\IPC$[\*]'. */
127 Log(("VBOXSF: MRxCreateVNetRoot: IPC$\n"));
128 Status = STATUS_MORE_PROCESSING_REQUIRED;
129 goto l_Exit;
130 }
131 }
132 }
133
134 /* Fail all other pipe open requests. */
135 Log(("VBOXSF: MRxCreateVNetRoot: Pipe open not supported!\n"));
136 Status = STATUS_NOT_SUPPORTED;
137 goto l_Exit;
138 }
139 else if (pNetRoot->Type == NET_ROOT_MAILSLOT)
140 {
141 Log(("VBOXSF: MRxCreateVNetRoot: Mailslot open not supported!\n"));
142 pVNetRoot->Context = NULL;
143 Status = STATUS_NOT_SUPPORTED;
144 goto l_Exit;
145 }
146
147 if (!pNetRoot->Context)
148 {
149 /* MRxNetRootSize is not zero in VBoxSF, so it is expected
150 * that the Context, which is NetRootExtension, is already allocated.
151 */
152 Log(("VBOXSF: MRxCreateVNetRoot: NULL netroot context\n"));
153 pVNetRoot->Context = NULL;
154 Status = STATUS_NOT_SUPPORTED;
155 goto l_Exit;
156 }
157
158 /* Detect an already initialized NetRoot.
159 * pNetRootExtension is actually the pNetRoot->Context and it is not NULL.
160 */
161 fInitializeNetRoot = (pNetRootExtension->phgcmClient == NULL);
162
163 Status = STATUS_SUCCESS;
164
165 if (fInitializeNetRoot)
166 {
167 PWCHAR pRootName;
168 ULONG RootNameLength;
169 int vboxRC;
170 PSHFLSTRING ParsedPath = 0;
171 ULONG ParsedPathSize;
172
173 Log(("VBOXSF: MRxCreateVNetRoot: initialize NET_ROOT\n"));
174
175 pNetRoot->MRxNetRootState = MRX_NET_ROOT_STATE_GOOD;
176
177 RootNameLength = pNetRoot->pNetRootName->Length - pSrvCall->pSrvCallName->Length;
178 if (RootNameLength < sizeof(WCHAR))
179 {
180 /* Refuse a netroot path with an empty shared folder name */
181 Log(("VBOXSF: MRxCreateVNetRoot: Empty shared folder name!\n"));
182 pNetRoot->MRxNetRootState = MRX_NET_ROOT_STATE_ERROR;
183
184 Status = STATUS_BAD_NETWORK_NAME;
185 goto l_Exit;
186 }
187
188 RootNameLength -= sizeof(WCHAR); /* Remove leading backslash. */
189 pRootName = (PWCHAR)(pNetRoot->pNetRootName->Buffer + (pSrvCall->pSrvCallName->Length / sizeof(WCHAR)));
190 pRootName++; /* Remove leading backslash. */
191
192 /* Strip the trailing \0. Sometimes there is one, sometimes not... */
193 if ( RootNameLength >= sizeof(WCHAR)
194 && pRootName[RootNameLength / sizeof(WCHAR) - 1] == 0)
195 RootNameLength -= sizeof(WCHAR);
196
197 if (!pNetRootExtension->phgcmClient)
198 {
199 Log(("VBOXSF: MRxCreateVNetRoot: Initialize netroot length = %d, name = %.*ls\n",
200 RootNameLength, RootNameLength / sizeof(WCHAR), pRootName));
201
202 /* Calculate the length required for parsed path. */
203 ParsedPathSize = sizeof(SHFLSTRING) + RootNameLength + sizeof(WCHAR);
204 ParsedPath = (PSHFLSTRING)vbsfAllocNonPagedMem(ParsedPathSize);
205 if (!ParsedPath)
206 {
207 Status = STATUS_INSUFFICIENT_RESOURCES;
208 goto l_Exit;
209 }
210 memset(ParsedPath, 0, ParsedPathSize);
211 if (!ShflStringInitBuffer(ParsedPath, ParsedPathSize))
212 {
213 vbsfFreeNonPagedMem(ParsedPath);
214 Status = STATUS_INSUFFICIENT_RESOURCES;
215 goto l_Exit;
216 }
217 ParsedPath->u16Length = ParsedPath->u16Size - sizeof(WCHAR); /* without terminating null */
218 RtlCopyMemory(ParsedPath->String.ucs2, pRootName, ParsedPath->u16Length);
219
220 vboxRC = vboxCallMapFolder(&pDeviceExtension->hgcmClient, ParsedPath, &pNetRootExtension->map);
221 vbsfFreeNonPagedMem(ParsedPath);
222 if (vboxRC != VINF_SUCCESS)
223 {
224 Log(("VBOXSF: MRxCreateVNetRoot: vboxCallMapFolder failed with %d\n", vboxRC));
225 Status = STATUS_BAD_NETWORK_NAME;
226 }
227 else
228 {
229 Status = STATUS_SUCCESS;
230 pNetRootExtension->phgcmClient = &pDeviceExtension->hgcmClient;
231 }
232 }
233 }
234 else
235 Log(("VBOXSF: MRxCreateVNetRoot: Creating V_NET_ROOT on existing NET_ROOT!\n"));
236
237 vbsfUpdateNetRoot(pNetRoot);
238
239l_Exit:
240 if (Status != STATUS_PENDING)
241 {
242 Log(("VBOXSF: MRxCreateVNetRoot: Returning 0x%08X\n", Status));
243 pCreateNetRootContext->VirtualNetRootStatus = Status;
244 if (fInitializeNetRoot)
245 pCreateNetRootContext->NetRootStatus = Status;
246 else
247 pCreateNetRootContext->NetRootStatus = STATUS_SUCCESS;
248
249 /* Inform RDBSS. */
250 pCreateNetRootContext->Callback(pCreateNetRootContext);
251
252 /* RDBSS expects this. */
253 Status = STATUS_PENDING;
254 }
255
256 Log(("VBOXSF: MRxCreateVNetRoot: Returned STATUS_PENDING\n"));
257 return Status;
258}
259
260NTSTATUS VBoxMRxFinalizeVNetRoot(IN PMRX_V_NET_ROOT pVNetRoot,
261 IN PBOOLEAN ForceDisconnect)
262{
263 Log(("VBOXSF: MRxFinalizeVNetRoot: V_NET_ROOT %p, NET_ROOT %p\n",
264 pVNetRoot, pVNetRoot->pNetRoot));
265
266 return STATUS_SUCCESS;
267}
268
269NTSTATUS VBoxMRxFinalizeNetRoot(IN PMRX_NET_ROOT pNetRoot,
270 IN PBOOLEAN ForceDisconnect)
271{
272 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(pNetRoot);
273
274 Log(("VBOXSF: MRxFinalizeNetRoot: NET_ROOT %p\n", pNetRoot));
275
276 if (pNetRootExtension->phgcmClient)
277 {
278 int vboxRC = vboxCallUnmapFolder(pNetRootExtension->phgcmClient, &pNetRootExtension->map);
279 if (vboxRC != VINF_SUCCESS)
280 Log(("VBOXSF: MRxFinalizeVNetRoot: vboxCallUnmapFolder failed with %d\n",
281 vboxRC));
282 pNetRootExtension->phgcmClient = NULL;
283 }
284
285 return STATUS_SUCCESS;
286}
287
288VOID VBoxMRxExtractNetRootName(IN PUNICODE_STRING FilePathName,
289 IN PMRX_SRV_CALL SrvCall,
290 OUT PUNICODE_STRING NetRootName,
291 OUT PUNICODE_STRING RestOfName OPTIONAL)
292{
293 int cChars = FilePathName->Length/sizeof(WCHAR);
294 int iNetRoot;
295 int i;
296
297 /* Split "\vboxsvr\share\path" to
298 * NetRootName = "\share"
299 * RestOfName = "\path"
300 *
301 * Note that SrvCall->pSrvCallName contains "\vboxsrv".
302 */
303
304 Log(("VBOXSF: MRxExtractNetRootName: [%.*ls], RestOfName %p\n",
305 FilePathName->Length/sizeof(WCHAR), FilePathName->Buffer, RestOfName));
306
307 /* Assume that the server prefix is OK.
308 * iNetRoot points to the first char after server name, the delimiter.
309 */
310 iNetRoot = SrvCall->pSrvCallName->Length/sizeof(WCHAR);
311
312 /* Find the NetRoot length: end of FilePathName or the next delimiter. */
313 i = iNetRoot;
314 while (i < cChars)
315 {
316 if ( FilePathName->Buffer[i] == L'\\'
317 && i > iNetRoot)
318 {
319 break;
320 }
321 i++;
322 }
323
324 Log(("VBOXSF: MRxExtractNetRootName: cChars %d, iNetRoot %d, iRest %d\n",
325 cChars, iNetRoot, i));
326
327 NetRootName->Buffer = &FilePathName->Buffer[iNetRoot];
328 NetRootName->Length = (USHORT)((i - iNetRoot) * sizeof(WCHAR));
329 NetRootName->MaximumLength = NetRootName->Length;
330
331 Log(("VBOXSF: MRxExtractNetRootName: Srv = %.*ls, Root = %.*ls\n",
332 SrvCall->pSrvCallName->Length / sizeof(WCHAR), SrvCall->pSrvCallName->Buffer,
333 NetRootName->Length / sizeof(WCHAR), NetRootName->Buffer));
334
335 if (RestOfName)
336 {
337 RestOfName->Buffer = &FilePathName->Buffer[i];
338 RestOfName->Length = (USHORT)((cChars - i) * sizeof(WCHAR));
339 RestOfName->MaximumLength = RestOfName->Length;
340
341 Log(("VBOXSF: MRxExtractNetRootName: Rest = %.*ls\n",
342 RestOfName->Length / sizeof(WCHAR), RestOfName->Buffer));
343 }
344}
345
346static VOID vbsfExecuteCreateSrvCall(PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext)
347{
348 NTSTATUS Status;
349 PWCHAR pSrvName = 0;
350 BOOLEAN Verifier;
351
352 PMRX_SRVCALL_CALLBACK_CONTEXT SCCBC = pCallbackContext;
353 PMRX_SRVCALLDOWN_STRUCTURE SrvCalldownStructure = (PMRX_SRVCALLDOWN_STRUCTURE)(SCCBC->SrvCalldownStructure);
354 PMRX_SRV_CALL pSrvCall = SrvCalldownStructure->SrvCall;
355
356 /* Validate the server name with the test name of 'vboxsvr'. */
357 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Connection Name %.*ls Length: %d, pSrvCall = %p\n",
358 pSrvCall->pSrvCallName->Length / sizeof(WCHAR), pSrvCall->pSrvCallName->Buffer, pSrvCall->pSrvCallName->Length, pSrvCall));
359
360 if (pSrvCall->pPrincipalName && pSrvCall->pPrincipalName->Length)
361 {
362 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Principal name = %.*ls\n",
363 pSrvCall->pPrincipalName->Length / sizeof(WCHAR), pSrvCall->pPrincipalName->Buffer));
364 }
365
366 if (pSrvCall->pDomainName && pSrvCall->pDomainName->Length)
367 {
368 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Domain name = %.*ls\n",
369 pSrvCall->pDomainName->Length / sizeof(WCHAR), pSrvCall->pDomainName->Buffer));
370 }
371
372 if (pSrvCall->pSrvCallName->Length >= 14)
373 {
374 pSrvName = pSrvCall->pSrvCallName->Buffer;
375
376 Verifier = (pSrvName[0] == L'\\');
377 Verifier &= (pSrvName[1] == L'V') || (pSrvName[1] == L'v');
378 Verifier &= (pSrvName[2] == L'B') || (pSrvName[2] == L'b');
379 Verifier &= (pSrvName[3] == L'O') || (pSrvName[3] == L'o');
380 Verifier &= (pSrvName[4] == L'X') || (pSrvName[4] == L'x');
381 Verifier &= (pSrvName[5] == L'S') || (pSrvName[5] == L's');
382 /* Both vboxsvr & vboxsrv are now accepted */
383 if ((pSrvName[6] == L'V') || (pSrvName[6] == L'v'))
384 {
385 Verifier &= (pSrvName[6] == L'V') || (pSrvName[6] == L'v');
386 Verifier &= (pSrvName[7] == L'R') || (pSrvName[7] == L'r');
387 }
388 else
389 {
390 Verifier &= (pSrvName[6] == L'R') || (pSrvName[6] == L'r');
391 Verifier &= (pSrvName[7] == L'V') || (pSrvName[7] == L'v');
392 }
393 Verifier &= (pSrvName[8] == L'\\') || (pSrvName[8] == 0);
394 }
395 else
396 Verifier = FALSE;
397
398 if (Verifier)
399 {
400 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Verifier succeeded!\n"));
401 Status = STATUS_SUCCESS;
402 }
403 else
404 {
405 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Verifier failed!\n"));
406 Status = STATUS_BAD_NETWORK_PATH;
407 }
408
409 SCCBC->Status = Status;
410 SrvCalldownStructure->CallBack(SCCBC);
411}
412
413NTSTATUS VBoxMRxCreateSrvCall(PMRX_SRV_CALL pSrvCall,
414 PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext)
415{
416 PMRX_SRVCALLDOWN_STRUCTURE SrvCalldownStructure = (PMRX_SRVCALLDOWN_STRUCTURE)(pCallbackContext->SrvCalldownStructure);
417
418 Log(("VBOXSF: MRxCreateSrvCall: %p.\n", pSrvCall));
419
420 if (IoGetCurrentProcess() == RxGetRDBSSProcess())
421 {
422 Log(("VBOXSF: MRxCreateSrvCall: Called in context of RDBSS process\n"));
423
424 vbsfExecuteCreateSrvCall(pCallbackContext);
425 }
426 else
427 {
428 NTSTATUS Status;
429
430 Log(("VBOXSF: MRxCreateSrvCall: Dispatching to worker thread\n"));
431
432 Status = RxDispatchToWorkerThread(VBoxMRxDeviceObject, DelayedWorkQueue,
433 (PWORKER_THREAD_ROUTINE)vbsfExecuteCreateSrvCall,
434 pCallbackContext);
435
436 if (Status == STATUS_SUCCESS)
437 Log(("VBOXSF: MRxCreateSrvCall: queued\n"));
438 else
439 {
440 pCallbackContext->Status = Status;
441 SrvCalldownStructure->CallBack(pCallbackContext);
442 }
443 }
444
445 /* RDBSS expect this. */
446 return STATUS_PENDING;
447}
448
449NTSTATUS VBoxMRxFinalizeSrvCall (PMRX_SRV_CALL pSrvCall,
450 BOOLEAN Force)
451{
452 Log(("VBOXSF: MRxFinalizeSrvCall %p, ctx = %p.\n", pSrvCall, pSrvCall->Context));
453
454 pSrvCall->Context = NULL;
455
456 return STATUS_SUCCESS;
457}
458
459NTSTATUS VBoxMRxSrvCallWinnerNotify(IN PMRX_SRV_CALL pSrvCall,
460 IN BOOLEAN ThisMinirdrIsTheWinner,
461 IN OUT PVOID pSrvCallContext)
462{
463 NTSTATUS Status = STATUS_SUCCESS;
464
465 Log(("VBOXSF: MRxSrvCallWinnerNotify: pSrvCall %p, pSrvCall->Ctx %p, winner %d, context %p\n",
466 pSrvCall, pSrvCall->Context, ThisMinirdrIsTheWinner, pSrvCallContext));
467
468 /* Set it to not NULL. */
469 pSrvCall->Context = pSrvCall;
470
471 return STATUS_SUCCESS;
472}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette