2 * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18 * nor the names of their contributors may be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission from Kernel Drivers, LLC and Your File System, Inc.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // File: AFSNetworkProviderSupport.cpp
39 #include "AFSCommon.h"
42 AFSAddConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
43 IN OUT PULONG ResultStatus,
44 IN OUT ULONG_PTR *ReturnOutputBufferLength)
47 NTSTATUS ntStatus = STATUS_SUCCESS;
48 AFSProviderConnectionCB *pConnection = NULL, *pLastConnection = NULL;
49 UNICODE_STRING uniRemoteName;
50 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
55 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
56 AFS_TRACE_LEVEL_VERBOSE,
57 "AFSAddConnection Acquiring AFSProviderListLock lock %p EXCL %08lX\n",
58 &pRDRDevExt->Specific.RDR.ProviderListLock,
59 PsGetCurrentThread());
61 if( ConnectCB->AuthenticationId.QuadPart == 0)
64 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
66 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
67 AFS_TRACE_LEVEL_VERBOSE,
68 "AFSAddConnection Retrieved authentication id %I64X\n",
69 ConnectCB->AuthenticationId.QuadPart);
72 AFSAcquireExcl( &pRDRDevExt->Specific.RDR.ProviderListLock,
76 // Look for the connection
79 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
80 uniRemoteName.MaximumLength = uniRemoteName.Length;
82 uniRemoteName.Buffer = ConnectCB->RemoteName;
85 // Strip off any trailing slashes
88 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
91 uniRemoteName.Length -= sizeof( WCHAR);
94 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
96 while( pConnection != NULL)
99 if( pConnection->LocalName == ConnectCB->LocalName &&
100 pConnection->AuthenticationId.QuadPart == ConnectCB->AuthenticationId.QuadPart &&
101 RtlCompareUnicodeString( &uniRemoteName,
102 &pConnection->RemoteName,
109 pConnection = pConnection->fLink;
112 if( pConnection != NULL)
115 if( ConnectCB->LocalName != L'\0')
118 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
119 AFS_TRACE_LEVEL_VERBOSE,
120 "AFSAddConnection ALREADY_CONNECTED remote name %wZ Local %C authentication id %I64X\n",
122 ConnectCB->LocalName,
123 ConnectCB->AuthenticationId.QuadPart);
128 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
129 AFS_TRACE_LEVEL_VERBOSE,
130 "AFSAddConnection ALREADY_CONNECTED remote name %wZ Local (NULL) authentication id %I64X\n",
132 ConnectCB->AuthenticationId.QuadPart);
135 *ResultStatus = WN_ALREADY_CONNECTED;
137 *ReturnOutputBufferLength = sizeof( ULONG);
139 try_return( ntStatus);
143 // Validate the remote name
146 if( uniRemoteName.Length > 2 * sizeof( WCHAR) &&
147 uniRemoteName.Buffer[ 0] == L'\\' &&
148 uniRemoteName.Buffer[ 1] == L'\\')
151 uniRemoteName.Buffer = &uniRemoteName.Buffer[ 2];
153 uniRemoteName.Length -= (2 * sizeof( WCHAR));
156 if( uniRemoteName.Length >= AFSServerName.Length)
159 USHORT usLength = uniRemoteName.Length;
161 if (uniRemoteName.Buffer[AFSServerName.Length/sizeof( WCHAR)] != L'\\')
164 if( ConnectCB->LocalName != L'\0')
167 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
168 AFS_TRACE_LEVEL_VERBOSE,
169 "AFSAddConnection BAD_NETNAME 1 remote name %wZ Local %C authentication id %I64X\n",
171 ConnectCB->LocalName,
172 ConnectCB->AuthenticationId.QuadPart);
177 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
178 AFS_TRACE_LEVEL_VERBOSE,
179 "AFSAddConnection BAD_NETNAME 1 remote name %wZ Local (NULL) authentication id %I64X\n",
181 ConnectCB->AuthenticationId.QuadPart);
184 *ResultStatus = WN_BAD_NETNAME;
186 *ReturnOutputBufferLength = sizeof( ULONG);
188 try_return( ntStatus = STATUS_SUCCESS);
191 uniRemoteName.Length = AFSServerName.Length;
193 if( RtlCompareUnicodeString( &AFSServerName,
198 if( ConnectCB->LocalName != L'\0')
201 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
202 AFS_TRACE_LEVEL_VERBOSE,
203 "AFSAddConnection BAD_NETNAME 2 remote name %wZ Local %C authentication id %I64X\n",
205 ConnectCB->LocalName,
206 ConnectCB->AuthenticationId.QuadPart);
211 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
212 AFS_TRACE_LEVEL_VERBOSE,
213 "AFSAddConnection BAD_NETNAME 2 remote name %wZ Local (NULL) authentication id %I64X\n",
215 ConnectCB->AuthenticationId.QuadPart);
218 *ResultStatus = WN_BAD_NETNAME;
220 *ReturnOutputBufferLength = sizeof( ULONG);
222 try_return( ntStatus = STATUS_SUCCESS);
225 uniRemoteName.Length = usLength;
230 if( ConnectCB->LocalName != L'\0')
233 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
234 AFS_TRACE_LEVEL_VERBOSE,
235 "AFSAddConnection BAD_NETNAME 3 remote name %wZ Local %C authentication id %I64X\n",
237 ConnectCB->LocalName,
238 ConnectCB->AuthenticationId.QuadPart);
243 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
244 AFS_TRACE_LEVEL_VERBOSE,
245 "AFSAddConnection BAD_NETNAME 3 remote name %wZ Local (NULL) authentication id %I64X\n",
247 ConnectCB->AuthenticationId.QuadPart);
250 *ResultStatus = WN_BAD_NETNAME;
252 *ReturnOutputBufferLength = sizeof( ULONG);
254 try_return( ntStatus = STATUS_SUCCESS);
257 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
258 uniRemoteName.MaximumLength = uniRemoteName.Length;
260 uniRemoteName.Buffer = ConnectCB->RemoteName;
263 // Strip off any trailing slashes
266 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
269 uniRemoteName.Length -= sizeof( WCHAR);
273 // Allocate a new node and add it to our list
276 pConnection = (AFSProviderConnectionCB *)AFSExAllocatePoolWithTag( PagedPool,
277 sizeof( AFSProviderConnectionCB) +
278 uniRemoteName.Length,
281 if( pConnection == NULL)
284 *ResultStatus = WN_OUT_OF_MEMORY;
286 *ReturnOutputBufferLength = sizeof( ULONG);
288 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
291 RtlZeroMemory( pConnection,
292 sizeof( AFSProviderConnectionCB) + uniRemoteName.Length);
294 pConnection->LocalName = ConnectCB->LocalName;
296 pConnection->RemoteName.Length = uniRemoteName.Length;
297 pConnection->RemoteName.MaximumLength = pConnection->RemoteName.Length;
299 pConnection->RemoteName.Buffer = (WCHAR *)((char *)pConnection + sizeof( AFSProviderConnectionCB));
301 RtlCopyMemory( pConnection->RemoteName.Buffer,
302 uniRemoteName.Buffer,
303 pConnection->RemoteName.Length);
305 pConnection->Type = ConnectCB->Type;
307 pConnection->AuthenticationId = ConnectCB->AuthenticationId;
309 if( ConnectCB->LocalName != L'\0')
312 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
313 AFS_TRACE_LEVEL_VERBOSE,
314 "AFSAddConnection Adding connection remote name %wZ Local %C authentication id %I64X\n",
316 ConnectCB->LocalName,
317 ConnectCB->AuthenticationId.QuadPart);
322 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
323 AFS_TRACE_LEVEL_VERBOSE,
324 "AFSAddConnection Adding connection remote name %wZ Local (NULL) authentication id %I64X\n",
326 ConnectCB->AuthenticationId.QuadPart);
330 // Point to the component portion of the name
333 pConnection->ComponentName.Length = 0;
334 pConnection->ComponentName.MaximumLength = 0;
336 pConnection->ComponentName.Buffer = &pConnection->RemoteName.Buffer[ (pConnection->RemoteName.Length/sizeof( WCHAR)) - 1];
338 while( pConnection->ComponentName.Length <= pConnection->RemoteName.Length)
341 if( pConnection->ComponentName.Buffer[ 0] == L'\\')
344 pConnection->ComponentName.Buffer++;
349 pConnection->ComponentName.Length += sizeof( WCHAR);
350 pConnection->ComponentName.MaximumLength += sizeof( WCHAR);
352 pConnection->ComponentName.Buffer--;
356 // Go initialize the information about the connection
359 AFSInitializeConnectionInfo( pConnection,
363 // Insert the entry into our list
366 if( pRDRDevExt->Specific.RDR.ProviderConnectionList == NULL)
369 pRDRDevExt->Specific.RDR.ProviderConnectionList = pConnection;
375 // Get the end of the list
378 pLastConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
380 while( pLastConnection->fLink != NULL)
383 pLastConnection = pLastConnection->fLink;
386 pLastConnection->fLink = pConnection;
389 *ResultStatus = WN_SUCCESS;
391 *ReturnOutputBufferLength = sizeof( ULONG);
395 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
403 AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
404 IN OUT AFSCancelConnectionResultCB *ConnectionResult,
405 IN OUT ULONG_PTR *ReturnOutputBufferLength)
408 NTSTATUS ntStatus = STATUS_SUCCESS;
409 AFSProviderConnectionCB *pConnection = NULL, *pLastConnection = NULL;
410 UNICODE_STRING uniRemoteName;
411 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
416 ConnectionResult->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
418 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
419 AFS_TRACE_LEVEL_VERBOSE,
420 "AFSCancelConnection Acquiring AFSProviderListLock lock %p EXCL %08lX\n",
421 &pRDRDevExt->Specific.RDR.ProviderListLock,
422 PsGetCurrentThread());
424 if( ConnectCB->AuthenticationId.QuadPart == 0)
427 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
429 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
430 AFS_TRACE_LEVEL_VERBOSE,
431 "AFSCancelConnection Retrieved authentication id %I64X\n",
432 ConnectCB->AuthenticationId.QuadPart);
435 AFSAcquireExcl( &pRDRDevExt->Specific.RDR.ProviderListLock,
439 // Look for the connection
442 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
443 uniRemoteName.MaximumLength = uniRemoteName.Length;
445 uniRemoteName.Buffer = NULL;
447 if( uniRemoteName.Length > 0)
450 uniRemoteName.Buffer = ConnectCB->RemoteName;
453 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
455 while( pConnection != NULL)
458 if( ( ConnectCB->LocalName != L'\0' &&
459 pConnection->LocalName == ConnectCB->LocalName)
461 ( RtlCompareUnicodeString( &uniRemoteName,
462 &pConnection->RemoteName,
466 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
467 AFS_TRACE_LEVEL_VERBOSE,
468 "AFSCancelConnection Checking remote name %wZ to stored %wZ authentication id %I64X - %I64X\n",
470 &pConnection->RemoteName,
471 ConnectCB->AuthenticationId.QuadPart,
472 pConnection->AuthenticationId.QuadPart);
474 if( ConnectCB->AuthenticationId.QuadPart == pConnection->AuthenticationId.QuadPart &&
475 ( ConnectCB->LocalName == L'\0' ||
476 RtlCompareUnicodeString( &uniRemoteName,
477 &pConnection->RemoteName,
485 pLastConnection = pConnection;
487 pConnection = pConnection->fLink;
490 if( pConnection == NULL)
493 ConnectionResult->Status = WN_NOT_CONNECTED;
495 *ReturnOutputBufferLength = sizeof( AFSCancelConnectionResultCB);
497 try_return( ntStatus);
500 if( pLastConnection == NULL)
503 pRDRDevExt->Specific.RDR.ProviderConnectionList = pConnection->fLink;
508 pLastConnection->fLink = pConnection->fLink;
511 if( pConnection->Comment.Buffer != NULL)
514 AFSExFreePoolWithTag( pConnection->Comment.Buffer, 0);
517 ConnectionResult->LocalName = pConnection->LocalName;
519 AFSExFreePoolWithTag( pConnection, AFS_PROVIDER_CB);
521 ConnectionResult->Status = WN_SUCCESS;
523 *ReturnOutputBufferLength = sizeof( AFSCancelConnectionResultCB);
527 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
534 AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
535 IN OUT WCHAR *RemoteName,
536 IN ULONG RemoteNameBufferLength,
537 IN OUT ULONG_PTR *ReturnOutputBufferLength)
540 NTSTATUS ntStatus = STATUS_SUCCESS;
541 AFSProviderConnectionCB *pConnection = NULL;
542 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
547 if( ConnectCB->LocalName != L'\0')
550 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
551 AFS_TRACE_LEVEL_VERBOSE,
552 "AFSGetConnection Local %C authentication id %I64X\n",
553 ConnectCB->LocalName,
554 ConnectCB->AuthenticationId.QuadPart);
559 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
560 AFS_TRACE_LEVEL_VERBOSE,
561 "AFSGetConnection Local (NULL) authentication id %I64X\n",
562 ConnectCB->AuthenticationId.QuadPart);
565 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
566 AFS_TRACE_LEVEL_VERBOSE,
567 "AFSGetConnection Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
568 &pRDRDevExt->Specific.RDR.ProviderListLock,
569 PsGetCurrentThread());
571 if( ConnectCB->AuthenticationId.QuadPart == 0)
574 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
576 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
577 AFS_TRACE_LEVEL_VERBOSE,
578 "AFSGetConnection Retrieved authentication id %I64X\n",
579 ConnectCB->AuthenticationId.QuadPart);
582 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
586 // Look for the connection
589 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
591 while( pConnection != NULL)
594 if( pConnection->LocalName != L'\0')
597 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
598 AFS_TRACE_LEVEL_VERBOSE,
599 "AFSGetConnection Comparing passed in %C to %C authentication id %I64X - %I64X\n",
600 ConnectCB->LocalName,
601 pConnection->LocalName,
602 ConnectCB->AuthenticationId.QuadPart,
603 pConnection->AuthenticationId.QuadPart);
608 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
609 AFS_TRACE_LEVEL_VERBOSE,
610 "AFSGetConnection Comparing passed in %C to (NULL) authentication id %I64X - %I64X\n",
611 ConnectCB->LocalName,
612 ConnectCB->AuthenticationId.QuadPart,
613 pConnection->AuthenticationId.QuadPart);
616 if( pConnection->LocalName == ConnectCB->LocalName &&
617 pConnection->AuthenticationId.QuadPart == ConnectCB->AuthenticationId.QuadPart)
623 pConnection = pConnection->fLink;
626 if( pConnection == NULL)
629 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
630 AFS_TRACE_LEVEL_VERBOSE,
631 "AFSGetConnection INVALID_PARAMETER\n");
633 try_return( ntStatus = STATUS_INVALID_PARAMETER);
636 if( RemoteNameBufferLength < pConnection->RemoteName.Length)
639 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
640 AFS_TRACE_LEVEL_VERBOSE,
641 "AFSGetConnection INSUFFICIENT_RESOURCES\n");
643 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
646 RtlCopyMemory( RemoteName,
647 pConnection->RemoteName.Buffer,
648 pConnection->RemoteName.Length);
650 *ReturnOutputBufferLength = pConnection->RemoteName.Length;
654 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
661 AFSListConnections( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
662 IN ULONG ConnectionBufferLength,
663 IN OUT ULONG_PTR *ReturnOutputBufferLength)
666 NTSTATUS ntStatus = STATUS_SUCCESS;
667 AFSProviderConnectionCB *pConnection = NULL, *pRootConnection = NULL;
668 ULONG ulCopiedLength = 0, ulRemainingLength = ConnectionBufferLength;
669 ULONG ulScope, ulType;
670 UNICODE_STRING uniRemoteName, uniServerName, uniShareName, uniRemainingPath;
671 BOOLEAN bGlobalEnumeration = FALSE;
673 LARGE_INTEGER liAuthenticationID = {0,0};
674 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
680 // Save off some data before moving on
683 ulScope = ConnectCB->Scope;
685 ulType = ConnectCB->Type;
687 if( ConnectCB->AuthenticationId.QuadPart == 0)
690 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
692 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
693 AFS_TRACE_LEVEL_VERBOSE,
694 "AFSListConnections Retrieved authentication id %I64X\n",
695 ConnectCB->AuthenticationId.QuadPart);
698 liAuthenticationID.QuadPart = ConnectCB->AuthenticationId.QuadPart;
700 uniRemoteName.Length = 0;
701 uniRemoteName.MaximumLength = 0;
702 uniRemoteName.Buffer = NULL;
704 uniServerName.Length = 0;
705 uniServerName.MaximumLength = 0;
706 uniServerName.Buffer = NULL;
708 uniShareName.Length = 0;
709 uniShareName.MaximumLength = 0;
710 uniShareName.Buffer = NULL;
712 if( ConnectCB->RemoteNameLength > 0)
715 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
716 uniRemoteName.MaximumLength = uniRemoteName.Length + sizeof( WCHAR);
718 uniRemoteName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
719 uniRemoteName.MaximumLength,
720 AFS_NETWORK_PROVIDER_1_TAG);
722 if( uniRemoteName.Buffer == NULL)
725 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
728 RtlCopyMemory( uniRemoteName.Buffer,
729 ConnectCB->RemoteName,
730 uniRemoteName.Length);
732 if( uniRemoteName.Buffer[ 0] == L'\\' &&
733 uniRemoteName.Buffer[ 1] == L'\\')
736 uniRemoteName.Buffer = &uniRemoteName.Buffer[ 1];
738 uniRemoteName.Length -= sizeof( WCHAR);
741 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
744 uniRemoteName.Length -= sizeof( WCHAR);
747 FsRtlDissectName( uniRemoteName,
751 uniRemoteName = uniRemainingPath;
753 if( uniRemoteName.Length > 0)
756 FsRtlDissectName( uniRemoteName,
762 // If this is an enumeration of the global share name then
763 // adjust it to be the server name itself
766 if( uniShareName.Length == 0 ||
767 RtlCompareUnicodeString( &uniShareName,
772 bGlobalEnumeration = TRUE;
776 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
777 AFS_TRACE_LEVEL_VERBOSE,
778 "AFSListConnections Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
779 &pRDRDevExt->Specific.RDR.ProviderListLock,
780 PsGetCurrentThread());
782 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
786 // If this is a globalnet enumeration with no name then enumerate the server list
789 if( ulScope == RESOURCE_GLOBALNET)
792 if( uniServerName.Buffer == NULL)
795 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList;
801 // Go locate the root entry for the name passed in
804 if( bGlobalEnumeration)
807 if( pRDRDevExt->Specific.RDR.ProviderEnumerationList == NULL)
810 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
812 try_return( ntStatus);
815 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList->EnumerationList;
820 pRootConnection = AFSLocateEnumRootEntry( &uniShareName);
822 if( pRootConnection == NULL)
825 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
827 try_return( ntStatus);
831 // Need to handle these enumerations from the directory listing
834 ntStatus = AFSEnumerateConnection( ConnectCB,
836 ConnectionBufferLength,
844 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
847 ulIndex = ConnectCB->CurrentIndex;
849 while( pConnection != NULL)
852 if( bGlobalEnumeration &&
853 BooleanFlagOn( pConnection->Flags, AFS_CONNECTION_FLAG_GLOBAL_SHARE))
856 pConnection = pConnection->fLink;
861 if( ulScope != RESOURCE_GLOBALNET &&
862 !BooleanFlagOn( pConnection->Usage, RESOURCEUSAGE_ATTACHED))
865 pConnection = pConnection->fLink;
870 if( pConnection->LocalName != L'\0')
873 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
874 AFS_TRACE_LEVEL_VERBOSE,
875 "AFSListConnections Processing entry %wZ %C authentication id %I64X - %I64X Scope %08lX\n",
876 &pConnection->RemoteName,
877 pConnection->LocalName,
878 liAuthenticationID.QuadPart,
879 pConnection->AuthenticationId.QuadPart,
885 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
886 AFS_TRACE_LEVEL_VERBOSE,
887 "AFSListConnections Processing entry %wZ NULL LocalName authentication id %I64X - %I64X Scope %08lX\n",
888 &pConnection->RemoteName,
889 liAuthenticationID.QuadPart,
890 pConnection->AuthenticationId.QuadPart,
894 if( ulScope != RESOURCE_GLOBALNET &&
895 pConnection->AuthenticationId.QuadPart != liAuthenticationID.QuadPart)
898 pConnection = pConnection->fLink;
908 pConnection = pConnection->fLink;
913 if( ulRemainingLength < (ULONG)FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
914 pConnection->RemoteName.Length +
915 pConnection->Comment.Length)
921 ConnectCB->RemoteNameLength = pConnection->RemoteName.Length;
923 RtlCopyMemory( ConnectCB->RemoteName,
924 pConnection->RemoteName.Buffer,
925 pConnection->RemoteName.Length);
927 ConnectCB->LocalName = pConnection->LocalName;
929 ConnectCB->Type = pConnection->Type;
931 ConnectCB->Scope = pConnection->Scope;
933 if( !bGlobalEnumeration)
936 ConnectCB->Scope = RESOURCE_CONNECTED;
939 ConnectCB->DisplayType = pConnection->DisplayType;
941 ConnectCB->Usage = pConnection->Usage;
943 ConnectCB->CommentLength = pConnection->Comment.Length;
945 if( pConnection->Comment.Length > 0)
948 ConnectCB->CommentOffset = (ULONG)(FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
949 ConnectCB->RemoteNameLength);
951 RtlCopyMemory( (void *)((char *)ConnectCB + ConnectCB->CommentOffset),
952 pConnection->Comment.Buffer,
953 ConnectCB->CommentLength);
956 ulCopiedLength += FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
957 ConnectCB->RemoteNameLength +
958 ConnectCB->CommentLength;
960 ulRemainingLength -= FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
961 ConnectCB->RemoteNameLength +
962 ConnectCB->CommentLength;
964 ConnectCB = (AFSNetworkProviderConnectionCB *)((char *)ConnectCB +
965 FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
966 ConnectCB->RemoteNameLength +
967 ConnectCB->CommentLength);
969 pConnection = pConnection->fLink;
972 if( NT_SUCCESS( ntStatus))
975 *ReturnOutputBufferLength = ulCopiedLength;
978 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
982 if( uniRemoteName.Buffer != NULL)
985 AFSExFreePoolWithTag( uniRemoteName.Buffer, 0);
993 AFSInitializeConnectionInfo( IN AFSProviderConnectionCB *Connection,
994 IN ULONG DisplayType)
997 NTSTATUS ntStatus = STATUS_SUCCESS;
998 UNICODE_STRING uniName, uniComponentName, uniRemainingName;
1003 uniName = Connection->RemoteName;
1006 // Strip of the double leading slash if there is one
1009 if( uniName.Buffer[ 0] == L'\\' &&
1010 uniName.Buffer[ 1] == L'\\')
1013 uniName.Buffer = &uniName.Buffer[ 1];
1015 uniName.Length -= sizeof( WCHAR);
1019 FsRtlDissectName( uniName,
1024 // Initialize the information for the connection
1025 // First, if this is the server only then mark it accordingly
1028 if( uniRemainingName.Length == 0 ||
1029 DisplayType == RESOURCEDISPLAYTYPE_SERVER)
1032 Connection->Type = RESOURCETYPE_DISK;
1034 Connection->Scope = 0;
1036 Connection->DisplayType = RESOURCEDISPLAYTYPE_SERVER;
1038 Connection->Usage = RESOURCEUSAGE_CONTAINER;
1040 Connection->Comment.Length = 20;
1041 Connection->Comment.MaximumLength = 22;
1043 Connection->Comment.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1044 Connection->Comment.MaximumLength,
1045 AFS_NETWORK_PROVIDER_2_TAG);
1047 if( Connection->Comment.Buffer != NULL)
1050 RtlZeroMemory( Connection->Comment.Buffer,
1051 Connection->Comment.MaximumLength);
1053 RtlCopyMemory( Connection->Comment.Buffer,
1060 Connection->Comment.Length = 0;
1061 Connection->Comment.MaximumLength = 0;
1064 try_return( ntStatus);
1067 uniName = uniRemainingName;
1069 FsRtlDissectName( uniName,
1073 if( uniRemainingName.Length == 0 ||
1074 uniRemainingName.Buffer == NULL ||
1075 DisplayType == RESOURCEDISPLAYTYPE_SHARE)
1078 Connection->Type = RESOURCETYPE_DISK;
1080 Connection->DisplayType = RESOURCEDISPLAYTYPE_SHARE;
1082 Connection->Usage = RESOURCEUSAGE_CONNECTABLE;
1084 if( Connection->LocalName != L'\0')
1087 Connection->Usage |= RESOURCEUSAGE_ATTACHED;
1089 Connection->Scope = RESOURCE_CONNECTED;
1094 Connection->Usage |= RESOURCEUSAGE_NOLOCALDEVICE;
1096 Connection->Scope = RESOURCE_GLOBALNET;
1099 Connection->Comment.Length = 18;
1100 Connection->Comment.MaximumLength = 20;
1102 Connection->Comment.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1103 Connection->Comment.MaximumLength,
1104 AFS_NETWORK_PROVIDER_3_TAG);
1106 if( Connection->Comment.Buffer != NULL)
1109 RtlZeroMemory( Connection->Comment.Buffer,
1110 Connection->Comment.MaximumLength);
1112 RtlCopyMemory( Connection->Comment.Buffer,
1119 Connection->Comment.Length = 0;
1120 Connection->Comment.MaximumLength = 0;
1123 try_return( ntStatus);
1127 // This is a sub directory within a share
1130 Connection->Type = RESOURCETYPE_DISK;
1132 Connection->DisplayType = RESOURCEDISPLAYTYPE_DIRECTORY;
1134 Connection->Usage = RESOURCEUSAGE_CONNECTABLE;
1136 if( Connection->LocalName != L'\0')
1139 Connection->Usage |= RESOURCEUSAGE_ATTACHED;
1144 Connection->Usage |= RESOURCEUSAGE_NOLOCALDEVICE;
1147 Connection->Scope = RESOURCE_CONNECTED;
1149 Connection->Comment.Length = 26;
1150 Connection->Comment.MaximumLength = 28;
1152 Connection->Comment.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1153 Connection->Comment.MaximumLength,
1154 AFS_NETWORK_PROVIDER_4_TAG);
1156 if( Connection->Comment.Buffer != NULL)
1159 RtlZeroMemory( Connection->Comment.Buffer,
1160 Connection->Comment.MaximumLength);
1162 RtlCopyMemory( Connection->Comment.Buffer,
1169 Connection->Comment.Length = 0;
1170 Connection->Comment.MaximumLength = 0;
1181 AFSProviderConnectionCB *
1182 AFSLocateEnumRootEntry( IN UNICODE_STRING *RemoteName)
1185 AFSProviderConnectionCB *pConnection = NULL;
1186 UNICODE_STRING uniRemoteName = *RemoteName;
1187 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1192 if( pRDRDevExt->Specific.RDR.ProviderEnumerationList == NULL)
1195 try_return( pConnection);
1198 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList->EnumerationList;
1200 while( pConnection != NULL)
1203 if( RtlCompareUnicodeString( &uniRemoteName,
1204 &pConnection->ComponentName,
1211 pConnection = pConnection->fLink;
1223 AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
1224 IN AFSProviderConnectionCB *RootConnection,
1225 IN ULONG BufferLength,
1226 OUT PULONG CopiedLength)
1229 NTSTATUS ntStatus = STATUS_SUCCESS;
1230 ULONG ulCRC = 0, ulCopiedLength = 0;
1231 AFSDirectoryCB *pShareDirEntry = NULL;
1232 AFSDirectoryCB *pDirEntry = NULL, *pTargetDirEntry = NULL;
1239 if( AFSGlobalRoot == NULL)
1242 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1243 AFS_TRACE_LEVEL_ERROR,
1244 "AFSEnumerateConnection Global root not yet initialized\n");
1246 try_return( ntStatus = STATUS_DEVICE_NOT_READY);
1249 ulCRC = AFSGenerateCRC( &RootConnection->ComponentName,
1253 // Grab our tree lock shared
1256 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1257 AFS_TRACE_LEVEL_VERBOSE,
1258 "AFSEnumerateConnection Acquiring GlobalRoot DirectoryNodeHdr.TreeLock lock %p SHARED %08lX\n",
1259 AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
1260 PsGetCurrentThread());
1262 AFSAcquireShared( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
1266 // Locate the dir entry for this node
1269 ntStatus = AFSLocateCaseSensitiveDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
1273 if( pShareDirEntry == NULL ||
1274 !NT_SUCCESS( ntStatus))
1278 // Perform a case insensitive search
1281 ulCRC = AFSGenerateCRC( &RootConnection->ComponentName,
1284 ntStatus = AFSLocateCaseInsensitiveDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
1288 if( pShareDirEntry == NULL ||
1289 !NT_SUCCESS( ntStatus))
1292 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
1294 try_return( ntStatus);
1298 lCount = InterlockedIncrement( &pShareDirEntry->DirOpenReferenceCount);
1300 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1301 AFS_TRACE_LEVEL_VERBOSE,
1302 "AFSEnumerateConnection1 Increment count on %wZ DE %p Ccb %p Cnt %d\n",
1303 &pShareDirEntry->NameInformation.FileName,
1308 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
1311 // Setup the request to evaluate the entry
1314 ntStatus = AFSEvaluateRootEntry( pShareDirEntry,
1317 if( !NT_SUCCESS( ntStatus))
1320 try_return( ntStatus);
1323 AFSAcquireShared( pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
1327 // Enumerate the content
1330 pDirEntry = pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeListHead;
1332 ulIndex = ConnectCB->CurrentIndex;
1334 while( pDirEntry != NULL)
1342 pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
1347 if( BufferLength < (ULONG)FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1348 pDirEntry->NameInformation.FileName.Length)
1354 ConnectCB->LocalName = L'\0';
1356 ConnectCB->RemoteNameLength = pDirEntry->NameInformation.FileName.Length;
1358 RtlCopyMemory( ConnectCB->RemoteName,
1359 pDirEntry->NameInformation.FileName.Buffer,
1360 pDirEntry->NameInformation.FileName.Length);
1362 ConnectCB->Type = RESOURCETYPE_DISK;
1364 ConnectCB->Scope = RESOURCE_CONNECTED;
1366 if( BooleanFlagOn( pDirEntry->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
1369 ConnectCB->DisplayType = RESOURCEDISPLAYTYPE_DIRECTORY;
1374 ConnectCB->DisplayType = RESOURCEDISPLAYTYPE_FILE;
1377 ConnectCB->Usage = 0;
1379 ConnectCB->CommentLength = 0;
1381 ulCopiedLength += FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1382 pDirEntry->NameInformation.FileName.Length;
1384 BufferLength -= FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1385 pDirEntry->NameInformation.FileName.Length;
1387 ConnectCB = (AFSNetworkProviderConnectionCB *)((char *)ConnectCB +
1388 FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1389 ConnectCB->RemoteNameLength);
1391 pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
1394 lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
1396 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1397 AFS_TRACE_LEVEL_VERBOSE,
1398 "AFSEnumerateConnection Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
1399 &pTargetDirEntry->NameInformation.FileName,
1404 ASSERT( lCount >= 0);
1406 *CopiedLength = ulCopiedLength;
1408 AFSReleaseResource( pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1412 if( pShareDirEntry != NULL)
1414 lCount = InterlockedDecrement( &pShareDirEntry->DirOpenReferenceCount);
1416 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1417 AFS_TRACE_LEVEL_VERBOSE,
1418 "AFSEnumerateConnection1 Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
1419 &pShareDirEntry->NameInformation.FileName,
1424 ASSERT( lCount >= 0);
1432 AFSGetConnectionInfo( IN AFSNetworkProviderConnectionCB *ConnectCB,
1433 IN ULONG BufferLength,
1434 IN OUT ULONG_PTR *ReturnOutputBufferLength)
1437 NTSTATUS ntStatus = STATUS_SUCCESS;
1438 AFSProviderConnectionCB *pConnection = NULL, *pBestMatch = NULL;
1439 UNICODE_STRING uniRemoteName, uniServerName, uniShareName, uniRemainingPath, uniFullName, uniRemainingPathLocal;
1440 USHORT usNameLen = 0, usMaxNameLen = 0;
1441 BOOLEAN bEnumerationEntry = FALSE;
1442 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1447 uniServerName.Length = 0;
1448 uniServerName.MaximumLength = 0;
1449 uniServerName.Buffer = NULL;
1451 uniShareName.Length = 0;
1452 uniShareName.MaximumLength = 0;
1453 uniShareName.Buffer = NULL;
1455 uniRemainingPathLocal.Length = 0;
1456 uniRemainingPathLocal.MaximumLength = 0;
1457 uniRemainingPathLocal.Buffer = NULL;
1459 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
1460 uniRemoteName.MaximumLength = uniRemoteName.Length + sizeof( WCHAR);
1461 uniRemoteName.Buffer = (WCHAR *)ConnectCB->RemoteName;
1463 if( ConnectCB->LocalName != L'\0')
1466 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1467 AFS_TRACE_LEVEL_VERBOSE,
1468 "AFSGetConnectionInfo remote name %wZ Local %C authentication id %I64X\n",
1470 ConnectCB->LocalName,
1471 ConnectCB->AuthenticationId.QuadPart);
1476 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1477 AFS_TRACE_LEVEL_VERBOSE,
1478 "AFSGetConnectionInfo remote name %wZ Local (NULL) authentication id %I64X\n",
1480 ConnectCB->AuthenticationId.QuadPart);
1483 if( AFSGlobalRoot == NULL)
1486 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1487 AFS_TRACE_LEVEL_ERROR,
1488 "AFSGetConnectionInfo Global root not yet initialized\n");
1490 try_return( ntStatus = STATUS_DEVICE_NOT_READY);
1493 uniFullName = uniRemoteName;
1495 if( uniRemoteName.Buffer[ 0] == L'\\' &&
1496 uniRemoteName.Buffer[ 1] == L'\\')
1499 uniRemoteName.Buffer = &uniRemoteName.Buffer[ 1];
1501 uniRemoteName.Length -= sizeof( WCHAR);
1504 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
1507 uniRemoteName.Length -= sizeof( WCHAR);
1509 uniFullName.Length -= sizeof( WCHAR);
1512 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1513 AFS_TRACE_LEVEL_VERBOSE,
1514 "AFSGetConnectionInfo Processing name %wZ\n", &uniFullName);
1516 FsRtlDissectName( uniRemoteName,
1520 uniRemoteName = uniRemainingPath;
1522 if( uniRemoteName.Length > 0)
1525 FsRtlDissectName( uniRemoteName,
1530 if( RtlCompareUnicodeString( &uniServerName,
1535 try_return( ntStatus = STATUS_INVALID_PARAMETER);
1538 if ( uniRemainingPath.Length > 0 )
1542 // Add back in the leading \ since it was stripped off above
1545 uniRemainingPath.Length += sizeof( WCHAR);
1546 if( uniRemainingPath.Length > uniRemainingPath.MaximumLength)
1548 uniRemainingPath.MaximumLength += sizeof( WCHAR);
1551 uniRemainingPath.Buffer--;
1553 uniRemainingPathLocal.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1554 uniRemainingPath.Length,
1555 AFS_NETWORK_PROVIDER_5_TAG);
1557 if( uniRemainingPathLocal.Buffer == NULL)
1560 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1561 AFS_TRACE_LEVEL_VERBOSE,
1562 "AFSGetConnectionInfo INSUFFICIENT_RESOURCES\n");
1564 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1567 uniRemainingPathLocal.MaximumLength = uniRemainingPath.Length;
1568 uniRemainingPathLocal.Length = uniRemainingPath.Length;
1570 RtlCopyMemory( uniRemainingPathLocal.Buffer,
1571 uniRemainingPath.Buffer,
1572 uniRemainingPath.Length);
1575 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1576 AFS_TRACE_LEVEL_VERBOSE,
1577 "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
1578 &pRDRDevExt->Specific.RDR.ProviderListLock,
1579 PsGetCurrentThread());
1581 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
1585 // If this is the server then return information about the
1589 if( uniShareName.Length == 0 &&
1590 RtlCompareUnicodeString( &uniServerName,
1595 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList;
1601 // See if we can locate it on our connection list
1604 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
1606 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1607 AFS_TRACE_LEVEL_VERBOSE,
1608 "AFSGetConnectionInfo Searching for full name %wZ\n", &uniFullName);
1610 while( pConnection != NULL)
1613 if( usMaxNameLen < pConnection->RemoteName.Length &&
1614 pConnection->RemoteName.Length <= uniFullName.Length)
1617 usNameLen = uniFullName.Length;
1619 uniFullName.Length = pConnection->RemoteName.Length;
1621 if( pConnection->AuthenticationId.QuadPart == ConnectCB->AuthenticationId.QuadPart &&
1622 RtlCompareUnicodeString( &uniFullName,
1623 &pConnection->RemoteName,
1627 usMaxNameLen = pConnection->RemoteName.Length;
1629 pBestMatch = pConnection;
1631 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1632 AFS_TRACE_LEVEL_VERBOSE,
1633 "AFSGetConnectionInfo Found match for %wZ\n", &pConnection->RemoteName);
1636 uniFullName.Length = usNameLen;
1639 pConnection = pConnection->fLink;
1642 pConnection = pBestMatch;
1644 if( pConnection != NULL)
1647 bEnumerationEntry = TRUE;
1649 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1650 AFS_TRACE_LEVEL_VERBOSE,
1651 "AFSGetConnectionInfo Using best match for %wZ\n", &pConnection->RemoteName);
1654 if( pConnection == NULL)
1658 // Locate the entry for the share
1661 pConnection = AFSLocateEnumRootEntry( &uniShareName);
1665 if( pConnection == NULL)
1667 UNICODE_STRING uniFullName;
1668 AFSDirEnumEntry *pDirEnumEntry = NULL;
1670 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1671 AFS_TRACE_LEVEL_VERBOSE,
1672 "AFSGetConnectionInfo No connection for full name %wZ\n", &uniFullName);
1675 // Drop the lock, we will pick it up again later
1678 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
1681 // OK, ask the CM about this component name
1684 ntStatus = AFSEvaluateTargetByName( NULL,
1685 &AFSGlobalRoot->ObjectInformation,
1689 if( !NT_SUCCESS( ntStatus))
1692 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1693 AFS_TRACE_LEVEL_VERBOSE,
1694 "AFSGetConnectionInfo Evaluation Failed share name %wZ\n",
1697 try_return( ntStatus = STATUS_INVALID_PARAMETER);
1705 AFSExFreePoolWithTag( pDirEnumEntry, AFS_GENERIC_MEMORY_3_TAG);
1708 // The share name is valid
1709 // Allocate a new node and add it to our list
1711 uniFullName.MaximumLength = PAGE_SIZE;
1712 uniFullName.Length = 0;
1714 uniFullName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1715 uniFullName.MaximumLength,
1716 AFS_NETWORK_PROVIDER_6_TAG);
1718 if( uniFullName.Buffer == NULL)
1721 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1722 AFS_TRACE_LEVEL_VERBOSE,
1723 "AFSGetConnectionInfo INSUFFICIENT_RESOURCES\n");
1725 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1728 uniFullName.Buffer[ 0] = L'\\';
1729 uniFullName.Buffer[ 1] = L'\\';
1731 uniFullName.Length = 2 * sizeof( WCHAR);
1733 RtlCopyMemory( &uniFullName.Buffer[ 2],
1734 AFSServerName.Buffer,
1735 AFSServerName.Length);
1737 uniFullName.Length += AFSServerName.Length;
1739 uniFullName.Buffer[ uniFullName.Length/sizeof( WCHAR)] = L'\\';
1741 uniFullName.Length += sizeof( WCHAR);
1743 RtlCopyMemory( &uniFullName.Buffer[ uniFullName.Length/sizeof( WCHAR)],
1744 uniShareName.Buffer,
1745 uniShareName.Length);
1747 uniFullName.Length += uniShareName.Length;
1749 AFSAcquireExcl( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
1752 ntStatus = AFSAddConnectionEx( &uniFullName,
1753 RESOURCEDISPLAYTYPE_SHARE,
1756 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
1758 AFSExFreePoolWithTag( uniFullName.Buffer, 0);
1760 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1761 AFS_TRACE_LEVEL_VERBOSE,
1762 "AFSGetConnectionInfo Acquiring AFSProviderListLock lock %p SHARED %08lX\n",
1763 &pRDRDevExt->Specific.RDR.ProviderListLock,
1764 PsGetCurrentThread());
1766 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
1769 if ( NT_SUCCESS( ntStatus) )
1772 // Once again, locate the entry for the share we just created
1775 pConnection = AFSLocateEnumRootEntry( &uniShareName);
1780 if( pConnection == NULL)
1783 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1784 AFS_TRACE_LEVEL_ERROR,
1785 "AFSGetConnectionInfo Failed to locate entry for full name %wZ\n", &uniFullName);
1787 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
1789 try_return( ntStatus = STATUS_INVALID_PARAMETER);
1793 // Fill in the returned connection info block
1796 if( BufferLength < (ULONG)FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1797 pConnection->RemoteName.Length +
1798 pConnection->Comment.Length +
1799 uniRemainingPath.Length)
1802 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1803 AFS_TRACE_LEVEL_VERBOSE,
1804 "AFSGetConnectionInfo Buffer too small for full name %wZ\n",
1807 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
1809 try_return( ntStatus = STATUS_BUFFER_OVERFLOW);
1812 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1813 AFS_TRACE_LEVEL_VERBOSE,
1814 "AFSGetConnectionInfo Returning entry Scope %08lX partial name %wZ full name %wZ\n",
1815 pConnection->Scope, &pConnection->RemoteName, &uniFullName);
1817 ConnectCB->RemoteNameLength = pConnection->RemoteName.Length;
1819 if( !bEnumerationEntry)
1822 RtlCopyMemory( ConnectCB->RemoteName,
1824 pConnection->RemoteName.Length);
1829 RtlCopyMemory( ConnectCB->RemoteName,
1830 pConnection->RemoteName.Buffer,
1831 pConnection->RemoteName.Length);
1834 ConnectCB->LocalName = pConnection->LocalName;
1836 ConnectCB->Type = pConnection->Type;
1838 ConnectCB->Scope = pConnection->Scope;
1840 ConnectCB->DisplayType = pConnection->DisplayType;
1842 ConnectCB->Usage = pConnection->Usage;
1844 ConnectCB->CommentLength = pConnection->Comment.Length;
1846 ConnectCB->RemainingPathLength = uniRemainingPathLocal.Length;
1848 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1849 AFS_TRACE_LEVEL_VERBOSE,
1850 "AFSGetConnectionInfo Returning lengths: remote %u comment %u remaining %u\n",
1851 ConnectCB->RemoteNameLength,
1852 ConnectCB->CommentLength,
1853 ConnectCB->RemainingPathLength);
1855 if( ConnectCB->CommentLength > 0)
1858 ConnectCB->CommentOffset = (ULONG)(FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1859 ConnectCB->RemoteNameLength);
1861 RtlCopyMemory( (void *)((char *)ConnectCB + ConnectCB->CommentOffset),
1862 pConnection->Comment.Buffer,
1863 ConnectCB->CommentLength);
1866 if ( ConnectCB->RemainingPathLength > 0 )
1869 ConnectCB->RemainingPathOffset = (ULONG)(FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1870 ConnectCB->RemoteNameLength +
1871 ConnectCB->CommentLength);
1873 RtlCopyMemory( (void *)((char *)ConnectCB + ConnectCB->RemainingPathOffset),
1874 uniRemainingPathLocal.Buffer,
1875 uniRemainingPathLocal.Length);
1878 *ReturnOutputBufferLength = FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1879 ConnectCB->RemoteNameLength +
1880 ConnectCB->CommentLength +
1881 ConnectCB->RemainingPathLength;
1883 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
1887 if ( uniRemainingPathLocal.Buffer )
1890 AFSExFreePoolWithTag( uniRemainingPathLocal.Buffer, 0);
1898 AFSIsDriveMapped( IN WCHAR DriveMapping)
1901 BOOLEAN bDriveMapped = FALSE;
1902 AFSProviderConnectionCB *pConnection = NULL;
1903 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1908 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
1911 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
1913 while( pConnection != NULL)
1916 if( pConnection->LocalName != L'\0' &&
1917 RtlUpcaseUnicodeChar( pConnection->LocalName) == RtlUpcaseUnicodeChar( DriveMapping))
1920 bDriveMapped = TRUE;
1925 pConnection = pConnection->fLink;
1928 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
1931 return bDriveMapped;