VirtualBox

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

Last change on this file since 54647 was 51997, checked in by vboxsync, 11 years ago

include,Main,Additions: SHFLSTRING cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.3 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
172 Log(("VBOXSF: MRxCreateVNetRoot: initialize NET_ROOT\n"));
173
174 pNetRoot->MRxNetRootState = MRX_NET_ROOT_STATE_GOOD;
175
176 RootNameLength = pNetRoot->pNetRootName->Length - pSrvCall->pSrvCallName->Length;
177 if (RootNameLength < sizeof(WCHAR))
178 {
179 /* Refuse a netroot path with an empty shared folder name */
180 Log(("VBOXSF: MRxCreateVNetRoot: Empty shared folder name!\n"));
181 pNetRoot->MRxNetRootState = MRX_NET_ROOT_STATE_ERROR;
182
183 Status = STATUS_BAD_NETWORK_NAME;
184 goto l_Exit;
185 }
186
187 RootNameLength -= sizeof(WCHAR); /* Remove leading backslash. */
188 pRootName = (PWCHAR)(pNetRoot->pNetRootName->Buffer + (pSrvCall->pSrvCallName->Length / sizeof(WCHAR)));
189 pRootName++; /* Remove leading backslash. */
190
191 /* Strip the trailing \0. Sometimes there is one, sometimes not... */
192 if ( RootNameLength >= sizeof(WCHAR)
193 && pRootName[RootNameLength / sizeof(WCHAR) - 1] == 0)
194 RootNameLength -= sizeof(WCHAR);
195
196 if (!pNetRootExtension->phgcmClient)
197 {
198 Log(("VBOXSF: MRxCreateVNetRoot: Initialize netroot length = %d, name = %.*ls\n",
199 RootNameLength, RootNameLength / sizeof(WCHAR), pRootName));
200
201 Status = vbsfShflStringFromUnicodeAlloc(&ParsedPath, pRootName, (uint16_t)RootNameLength);
202 if (Status != STATUS_SUCCESS)
203 {
204 goto l_Exit;
205 }
206
207 vboxRC = vboxCallMapFolder(&pDeviceExtension->hgcmClient, ParsedPath, &pNetRootExtension->map);
208 vbsfFreeNonPagedMem(ParsedPath);
209 if (vboxRC != VINF_SUCCESS)
210 {
211 Log(("VBOXSF: MRxCreateVNetRoot: vboxCallMapFolder failed with %d\n", vboxRC));
212 Status = STATUS_BAD_NETWORK_NAME;
213 }
214 else
215 {
216 Status = STATUS_SUCCESS;
217 pNetRootExtension->phgcmClient = &pDeviceExtension->hgcmClient;
218 }
219 }
220 }
221 else
222 Log(("VBOXSF: MRxCreateVNetRoot: Creating V_NET_ROOT on existing NET_ROOT!\n"));
223
224 vbsfUpdateNetRoot(pNetRoot);
225
226l_Exit:
227 if (Status != STATUS_PENDING)
228 {
229 Log(("VBOXSF: MRxCreateVNetRoot: Returning 0x%08X\n", Status));
230 pCreateNetRootContext->VirtualNetRootStatus = Status;
231 if (fInitializeNetRoot)
232 pCreateNetRootContext->NetRootStatus = Status;
233 else
234 pCreateNetRootContext->NetRootStatus = STATUS_SUCCESS;
235
236 /* Inform RDBSS. */
237 pCreateNetRootContext->Callback(pCreateNetRootContext);
238
239 /* RDBSS expects this. */
240 Status = STATUS_PENDING;
241 }
242
243 Log(("VBOXSF: MRxCreateVNetRoot: Returned STATUS_PENDING\n"));
244 return Status;
245}
246
247NTSTATUS VBoxMRxFinalizeVNetRoot(IN PMRX_V_NET_ROOT pVNetRoot,
248 IN PBOOLEAN ForceDisconnect)
249{
250 Log(("VBOXSF: MRxFinalizeVNetRoot: V_NET_ROOT %p, NET_ROOT %p\n",
251 pVNetRoot, pVNetRoot->pNetRoot));
252
253 return STATUS_SUCCESS;
254}
255
256NTSTATUS VBoxMRxFinalizeNetRoot(IN PMRX_NET_ROOT pNetRoot,
257 IN PBOOLEAN ForceDisconnect)
258{
259 PMRX_VBOX_NETROOT_EXTENSION pNetRootExtension = VBoxMRxGetNetRootExtension(pNetRoot);
260
261 Log(("VBOXSF: MRxFinalizeNetRoot: NET_ROOT %p\n", pNetRoot));
262
263 if (pNetRootExtension->phgcmClient)
264 {
265 int vboxRC = vboxCallUnmapFolder(pNetRootExtension->phgcmClient, &pNetRootExtension->map);
266 if (vboxRC != VINF_SUCCESS)
267 Log(("VBOXSF: MRxFinalizeVNetRoot: vboxCallUnmapFolder failed with %d\n",
268 vboxRC));
269 pNetRootExtension->phgcmClient = NULL;
270 }
271
272 return STATUS_SUCCESS;
273}
274
275VOID VBoxMRxExtractNetRootName(IN PUNICODE_STRING FilePathName,
276 IN PMRX_SRV_CALL SrvCall,
277 OUT PUNICODE_STRING NetRootName,
278 OUT PUNICODE_STRING RestOfName OPTIONAL)
279{
280 int cChars = FilePathName->Length/sizeof(WCHAR);
281 int iNetRoot;
282 int i;
283
284 /* Split "\vboxsvr\share\path" to
285 * NetRootName = "\share"
286 * RestOfName = "\path"
287 *
288 * Note that SrvCall->pSrvCallName contains "\vboxsrv".
289 */
290
291 Log(("VBOXSF: MRxExtractNetRootName: [%.*ls], RestOfName %p\n",
292 FilePathName->Length/sizeof(WCHAR), FilePathName->Buffer, RestOfName));
293
294 /* Assume that the server prefix is OK.
295 * iNetRoot points to the first char after server name, the delimiter.
296 */
297 iNetRoot = SrvCall->pSrvCallName->Length/sizeof(WCHAR);
298
299 /* Find the NetRoot length: end of FilePathName or the next delimiter. */
300 i = iNetRoot;
301 while (i < cChars)
302 {
303 if ( FilePathName->Buffer[i] == L'\\'
304 && i > iNetRoot)
305 {
306 break;
307 }
308 i++;
309 }
310
311 Log(("VBOXSF: MRxExtractNetRootName: cChars %d, iNetRoot %d, iRest %d\n",
312 cChars, iNetRoot, i));
313
314 NetRootName->Buffer = &FilePathName->Buffer[iNetRoot];
315 NetRootName->Length = (USHORT)((i - iNetRoot) * sizeof(WCHAR));
316 NetRootName->MaximumLength = NetRootName->Length;
317
318 Log(("VBOXSF: MRxExtractNetRootName: Srv = %.*ls, Root = %.*ls\n",
319 SrvCall->pSrvCallName->Length / sizeof(WCHAR), SrvCall->pSrvCallName->Buffer,
320 NetRootName->Length / sizeof(WCHAR), NetRootName->Buffer));
321
322 if (RestOfName)
323 {
324 RestOfName->Buffer = &FilePathName->Buffer[i];
325 RestOfName->Length = (USHORT)((cChars - i) * sizeof(WCHAR));
326 RestOfName->MaximumLength = RestOfName->Length;
327
328 Log(("VBOXSF: MRxExtractNetRootName: Rest = %.*ls\n",
329 RestOfName->Length / sizeof(WCHAR), RestOfName->Buffer));
330 }
331}
332
333static VOID vbsfExecuteCreateSrvCall(PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext)
334{
335 NTSTATUS Status;
336 PWCHAR pSrvName = 0;
337 BOOLEAN Verifier;
338
339 PMRX_SRVCALL_CALLBACK_CONTEXT SCCBC = pCallbackContext;
340 PMRX_SRVCALLDOWN_STRUCTURE SrvCalldownStructure = (PMRX_SRVCALLDOWN_STRUCTURE)(SCCBC->SrvCalldownStructure);
341 PMRX_SRV_CALL pSrvCall = SrvCalldownStructure->SrvCall;
342
343 /* Validate the server name with the test name of 'vboxsvr'. */
344 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Connection Name %.*ls Length: %d, pSrvCall = %p\n",
345 pSrvCall->pSrvCallName->Length / sizeof(WCHAR), pSrvCall->pSrvCallName->Buffer, pSrvCall->pSrvCallName->Length, pSrvCall));
346
347 if (pSrvCall->pPrincipalName && pSrvCall->pPrincipalName->Length)
348 {
349 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Principal name = %.*ls\n",
350 pSrvCall->pPrincipalName->Length / sizeof(WCHAR), pSrvCall->pPrincipalName->Buffer));
351 }
352
353 if (pSrvCall->pDomainName && pSrvCall->pDomainName->Length)
354 {
355 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Domain name = %.*ls\n",
356 pSrvCall->pDomainName->Length / sizeof(WCHAR), pSrvCall->pDomainName->Buffer));
357 }
358
359 if (pSrvCall->pSrvCallName->Length >= 14)
360 {
361 pSrvName = pSrvCall->pSrvCallName->Buffer;
362
363 Verifier = (pSrvName[0] == L'\\');
364 Verifier &= (pSrvName[1] == L'V') || (pSrvName[1] == L'v');
365 Verifier &= (pSrvName[2] == L'B') || (pSrvName[2] == L'b');
366 Verifier &= (pSrvName[3] == L'O') || (pSrvName[3] == L'o');
367 Verifier &= (pSrvName[4] == L'X') || (pSrvName[4] == L'x');
368 Verifier &= (pSrvName[5] == L'S') || (pSrvName[5] == L's');
369 /* Both vboxsvr & vboxsrv are now accepted */
370 if ((pSrvName[6] == L'V') || (pSrvName[6] == L'v'))
371 {
372 Verifier &= (pSrvName[6] == L'V') || (pSrvName[6] == L'v');
373 Verifier &= (pSrvName[7] == L'R') || (pSrvName[7] == L'r');
374 }
375 else
376 {
377 Verifier &= (pSrvName[6] == L'R') || (pSrvName[6] == L'r');
378 Verifier &= (pSrvName[7] == L'V') || (pSrvName[7] == L'v');
379 }
380 Verifier &= (pSrvName[8] == L'\\') || (pSrvName[8] == 0);
381 }
382 else
383 Verifier = FALSE;
384
385 if (Verifier)
386 {
387 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Verifier succeeded!\n"));
388 Status = STATUS_SUCCESS;
389 }
390 else
391 {
392 Log(("VBOXSF: vbsfExecuteCreateSrvCall: Verifier failed!\n"));
393 Status = STATUS_BAD_NETWORK_PATH;
394 }
395
396 SCCBC->Status = Status;
397 SrvCalldownStructure->CallBack(SCCBC);
398}
399
400NTSTATUS VBoxMRxCreateSrvCall(PMRX_SRV_CALL pSrvCall,
401 PMRX_SRVCALL_CALLBACK_CONTEXT pCallbackContext)
402{
403 PMRX_SRVCALLDOWN_STRUCTURE SrvCalldownStructure = (PMRX_SRVCALLDOWN_STRUCTURE)(pCallbackContext->SrvCalldownStructure);
404
405 Log(("VBOXSF: MRxCreateSrvCall: %p.\n", pSrvCall));
406
407 if (IoGetCurrentProcess() == RxGetRDBSSProcess())
408 {
409 Log(("VBOXSF: MRxCreateSrvCall: Called in context of RDBSS process\n"));
410
411 vbsfExecuteCreateSrvCall(pCallbackContext);
412 }
413 else
414 {
415 NTSTATUS Status;
416
417 Log(("VBOXSF: MRxCreateSrvCall: Dispatching to worker thread\n"));
418
419 Status = RxDispatchToWorkerThread(VBoxMRxDeviceObject, DelayedWorkQueue,
420 (PWORKER_THREAD_ROUTINE)vbsfExecuteCreateSrvCall,
421 pCallbackContext);
422
423 if (Status == STATUS_SUCCESS)
424 Log(("VBOXSF: MRxCreateSrvCall: queued\n"));
425 else
426 {
427 pCallbackContext->Status = Status;
428 SrvCalldownStructure->CallBack(pCallbackContext);
429 }
430 }
431
432 /* RDBSS expect this. */
433 return STATUS_PENDING;
434}
435
436NTSTATUS VBoxMRxFinalizeSrvCall (PMRX_SRV_CALL pSrvCall,
437 BOOLEAN Force)
438{
439 Log(("VBOXSF: MRxFinalizeSrvCall %p, ctx = %p.\n", pSrvCall, pSrvCall->Context));
440
441 pSrvCall->Context = NULL;
442
443 return STATUS_SUCCESS;
444}
445
446NTSTATUS VBoxMRxSrvCallWinnerNotify(IN PMRX_SRV_CALL pSrvCall,
447 IN BOOLEAN ThisMinirdrIsTheWinner,
448 IN OUT PVOID pSrvCallContext)
449{
450 NTSTATUS Status = STATUS_SUCCESS;
451
452 Log(("VBOXSF: MRxSrvCallWinnerNotify: pSrvCall %p, pSrvCall->Ctx %p, winner %d, context %p\n",
453 pSrvCall, pSrvCall->Context, ThisMinirdrIsTheWinner, pSrvCallContext));
454
455 /* Set it to not NULL. */
456 pSrvCall->Context = pSrvCall;
457
458 return STATUS_SUCCESS;
459}
Note: See TracBrowser for help on using the repository browser.

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