VirtualBox

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

Last change on this file since 58195 was 58195, checked in by vboxsync, 9 years ago

VBoxGuestR0LibSharedFolders: Prefixed functions ('vbox' wasn't a very good one). Hope I found all places these functions are called...

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