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;
51 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
56 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
57 AFS_TRACE_LEVEL_VERBOSE,
58 "AFSAddConnection Acquiring AFSProviderListLock lock %08lX EXCL %08lX\n",
59 &pRDRDevExt->Specific.RDR.ProviderListLock,
60 PsGetCurrentThread());
62 if( ConnectCB->AuthenticationId.QuadPart == 0)
65 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
67 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
68 AFS_TRACE_LEVEL_VERBOSE,
69 "AFSAddConnection Retrieved authentication id %I64X\n",
70 ConnectCB->AuthenticationId.QuadPart);
73 AFSAcquireExcl( &pRDRDevExt->Specific.RDR.ProviderListLock,
77 // Look for the connection
80 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
81 uniRemoteName.MaximumLength = uniRemoteName.Length;
83 uniRemoteName.Buffer = ConnectCB->RemoteName;
86 // Strip off any trailing slashes
89 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
92 uniRemoteName.Length -= sizeof( WCHAR);
95 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
97 while( pConnection != NULL)
100 if( pConnection->LocalName == ConnectCB->LocalName &&
101 pConnection->AuthenticationId.QuadPart == ConnectCB->AuthenticationId.QuadPart &&
102 RtlCompareUnicodeString( &uniRemoteName,
103 &pConnection->RemoteName,
110 pConnection = pConnection->fLink;
113 if( pConnection != NULL)
116 if( ConnectCB->LocalName != L'\0')
119 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
120 AFS_TRACE_LEVEL_VERBOSE,
121 "AFSAddConnection ALREADY_CONNECTED remote name %wZ Local %C authentication id %I64X\n",
123 ConnectCB->LocalName,
124 ConnectCB->AuthenticationId.QuadPart);
129 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
130 AFS_TRACE_LEVEL_VERBOSE,
131 "AFSAddConnection ALREADY_CONNECTED remote name %wZ Local (NULL) authentication id %I64X\n",
133 ConnectCB->AuthenticationId.QuadPart);
136 *ResultStatus = WN_ALREADY_CONNECTED;
138 *ReturnOutputBufferLength = sizeof( ULONG);
140 try_return( ntStatus);
144 // Validate the remote name
147 if( uniRemoteName.Length > 2 * sizeof( WCHAR) &&
148 uniRemoteName.Buffer[ 0] == L'\\' &&
149 uniRemoteName.Buffer[ 1] == L'\\')
152 uniRemoteName.Buffer = &uniRemoteName.Buffer[ 2];
154 uniRemoteName.Length -= (2 * sizeof( WCHAR));
157 if( uniRemoteName.Length >= AFSServerName.Length)
160 USHORT usLength = uniRemoteName.Length;
162 if (uniRemoteName.Buffer[AFSServerName.Length/sizeof( WCHAR)] != L'\\')
165 if( ConnectCB->LocalName != L'\0')
168 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
169 AFS_TRACE_LEVEL_VERBOSE,
170 "AFSAddConnection BAD_NETNAME 1 remote name %wZ Local %C authentication id %I64X\n",
172 ConnectCB->LocalName,
173 ConnectCB->AuthenticationId.QuadPart);
178 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
179 AFS_TRACE_LEVEL_VERBOSE,
180 "AFSAddConnection BAD_NETNAME 1 remote name %wZ Local (NULL) authentication id %I64X\n",
182 ConnectCB->AuthenticationId.QuadPart);
185 *ResultStatus = WN_BAD_NETNAME;
187 *ReturnOutputBufferLength = sizeof( ULONG);
189 try_return( ntStatus = STATUS_SUCCESS);
192 uniRemoteName.Length = AFSServerName.Length;
194 if( RtlCompareUnicodeString( &AFSServerName,
199 if( ConnectCB->LocalName != L'\0')
202 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
203 AFS_TRACE_LEVEL_VERBOSE,
204 "AFSAddConnection BAD_NETNAME 2 remote name %wZ Local %C authentication id %I64X\n",
206 ConnectCB->LocalName,
207 ConnectCB->AuthenticationId.QuadPart);
212 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
213 AFS_TRACE_LEVEL_VERBOSE,
214 "AFSAddConnection BAD_NETNAME 2 remote name %wZ Local (NULL) authentication id %I64X\n",
216 ConnectCB->AuthenticationId.QuadPart);
219 *ResultStatus = WN_BAD_NETNAME;
221 *ReturnOutputBufferLength = sizeof( ULONG);
223 try_return( ntStatus = STATUS_SUCCESS);
226 uniRemoteName.Length = usLength;
231 if( ConnectCB->LocalName != L'\0')
234 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
235 AFS_TRACE_LEVEL_VERBOSE,
236 "AFSAddConnection BAD_NETNAME 3 remote name %wZ Local %C authentication id %I64X\n",
238 ConnectCB->LocalName,
239 ConnectCB->AuthenticationId.QuadPart);
244 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
245 AFS_TRACE_LEVEL_VERBOSE,
246 "AFSAddConnection BAD_NETNAME 3 remote name %wZ Local (NULL) authentication id %I64X\n",
248 ConnectCB->AuthenticationId.QuadPart);
251 *ResultStatus = WN_BAD_NETNAME;
253 *ReturnOutputBufferLength = sizeof( ULONG);
255 try_return( ntStatus = STATUS_SUCCESS);
258 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
259 uniRemoteName.MaximumLength = uniRemoteName.Length;
261 uniRemoteName.Buffer = ConnectCB->RemoteName;
264 // Strip off any trailing slashes
267 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
270 uniRemoteName.Length -= sizeof( WCHAR);
274 // Allocate a new node and add it to our list
277 pConnection = (AFSProviderConnectionCB *)AFSExAllocatePoolWithTag( PagedPool,
278 sizeof( AFSProviderConnectionCB) +
279 uniRemoteName.Length,
282 if( pConnection == NULL)
285 *ResultStatus = WN_OUT_OF_MEMORY;
287 *ReturnOutputBufferLength = sizeof( ULONG);
289 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
292 RtlZeroMemory( pConnection,
293 sizeof( AFSProviderConnectionCB) + uniRemoteName.Length);
295 pConnection->LocalName = ConnectCB->LocalName;
297 pConnection->RemoteName.Length = uniRemoteName.Length;
298 pConnection->RemoteName.MaximumLength = pConnection->RemoteName.Length;
300 pConnection->RemoteName.Buffer = (WCHAR *)((char *)pConnection + sizeof( AFSProviderConnectionCB));
302 RtlCopyMemory( pConnection->RemoteName.Buffer,
303 uniRemoteName.Buffer,
304 pConnection->RemoteName.Length);
306 pConnection->Type = ConnectCB->Type;
308 pConnection->AuthenticationId = ConnectCB->AuthenticationId;
310 if( ConnectCB->LocalName != L'\0')
313 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
314 AFS_TRACE_LEVEL_VERBOSE,
315 "AFSAddConnection Adding connection remote name %wZ Local %C authentication id %I64X\n",
317 ConnectCB->LocalName,
318 ConnectCB->AuthenticationId.QuadPart);
323 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
324 AFS_TRACE_LEVEL_VERBOSE,
325 "AFSAddConnection Adding connection remote name %wZ Local (NULL) authentication id %I64X\n",
327 ConnectCB->AuthenticationId.QuadPart);
331 // Point to the component portion of the name
334 pConnection->ComponentName.Length = 0;
335 pConnection->ComponentName.MaximumLength = 0;
337 pConnection->ComponentName.Buffer = &pConnection->RemoteName.Buffer[ (pConnection->RemoteName.Length/sizeof( WCHAR)) - 1];
339 while( pConnection->ComponentName.Length <= pConnection->RemoteName.Length)
342 if( pConnection->ComponentName.Buffer[ 0] == L'\\')
345 pConnection->ComponentName.Buffer++;
350 pConnection->ComponentName.Length += sizeof( WCHAR);
351 pConnection->ComponentName.MaximumLength += sizeof( WCHAR);
353 pConnection->ComponentName.Buffer--;
357 // Go initialize the information about the connection
360 AFSInitializeConnectionInfo( pConnection,
364 // Insert the entry into our list
367 if( pRDRDevExt->Specific.RDR.ProviderConnectionList == NULL)
370 pRDRDevExt->Specific.RDR.ProviderConnectionList = pConnection;
376 // Get the end of the list
379 pLastConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
381 while( pLastConnection->fLink != NULL)
384 pLastConnection = pLastConnection->fLink;
387 pLastConnection->fLink = pConnection;
390 *ResultStatus = WN_SUCCESS;
392 *ReturnOutputBufferLength = sizeof( ULONG);
396 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
404 AFSCancelConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
405 IN OUT AFSCancelConnectionResultCB *ConnectionResult,
406 IN OUT ULONG_PTR *ReturnOutputBufferLength)
409 NTSTATUS ntStatus = STATUS_SUCCESS;
410 AFSProviderConnectionCB *pConnection = NULL, *pLastConnection = NULL;
411 UNICODE_STRING uniRemoteName;
412 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
417 ConnectionResult->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
419 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
420 AFS_TRACE_LEVEL_VERBOSE,
421 "AFSCancelConnection Acquiring AFSProviderListLock lock %08lX EXCL %08lX\n",
422 &pRDRDevExt->Specific.RDR.ProviderListLock,
423 PsGetCurrentThread());
425 if( ConnectCB->AuthenticationId.QuadPart == 0)
428 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
430 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
431 AFS_TRACE_LEVEL_VERBOSE,
432 "AFSCancelConnection Retrieved authentication id %I64X\n",
433 ConnectCB->AuthenticationId.QuadPart);
436 AFSAcquireExcl( &pRDRDevExt->Specific.RDR.ProviderListLock,
440 // Look for the connection
443 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
444 uniRemoteName.MaximumLength = uniRemoteName.Length;
446 uniRemoteName.Buffer = NULL;
448 if( uniRemoteName.Length > 0)
451 uniRemoteName.Buffer = ConnectCB->RemoteName;
454 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
456 while( pConnection != NULL)
459 if( ( ConnectCB->LocalName != L'\0' &&
460 pConnection->LocalName == ConnectCB->LocalName)
462 ( RtlCompareUnicodeString( &uniRemoteName,
463 &pConnection->RemoteName,
467 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
468 AFS_TRACE_LEVEL_VERBOSE,
469 "AFSCancelConnection Checking remote name %wZ to stored %wZ authentication id %I64X - %I64X\n",
471 &pConnection->RemoteName,
472 ConnectCB->AuthenticationId.QuadPart,
473 pConnection->AuthenticationId.QuadPart);
475 if( ConnectCB->AuthenticationId.QuadPart == pConnection->AuthenticationId.QuadPart &&
476 ( ConnectCB->LocalName == L'\0' ||
477 RtlCompareUnicodeString( &uniRemoteName,
478 &pConnection->RemoteName,
486 pLastConnection = pConnection;
488 pConnection = pConnection->fLink;
491 if( pConnection == NULL)
494 ConnectionResult->Status = WN_NOT_CONNECTED;
496 *ReturnOutputBufferLength = sizeof( AFSCancelConnectionResultCB);
498 try_return( ntStatus);
501 if( pLastConnection == NULL)
504 pRDRDevExt->Specific.RDR.ProviderConnectionList = pConnection->fLink;
509 pLastConnection->fLink = pConnection->fLink;
512 if( pConnection->Comment.Buffer != NULL)
515 AFSExFreePoolWithTag( pConnection->Comment.Buffer, 0);
518 ConnectionResult->LocalName = pConnection->LocalName;
520 AFSExFreePoolWithTag( pConnection, AFS_PROVIDER_CB);
522 ConnectionResult->Status = WN_SUCCESS;
524 *ReturnOutputBufferLength = sizeof( AFSCancelConnectionResultCB);
528 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
535 AFSGetConnection( IN AFSNetworkProviderConnectionCB *ConnectCB,
536 IN OUT WCHAR *RemoteName,
537 IN ULONG RemoteNameBufferLength,
538 IN OUT ULONG_PTR *ReturnOutputBufferLength)
541 NTSTATUS ntStatus = STATUS_SUCCESS;
542 AFSProviderConnectionCB *pConnection = NULL;
543 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
548 if( ConnectCB->LocalName != L'\0')
551 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
552 AFS_TRACE_LEVEL_VERBOSE,
553 "AFSGetConnection Local %C authentication id %I64X\n",
554 ConnectCB->LocalName,
555 ConnectCB->AuthenticationId.QuadPart);
560 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
561 AFS_TRACE_LEVEL_VERBOSE,
562 "AFSGetConnection Local (NULL) authentication id %I64X\n",
563 ConnectCB->AuthenticationId.QuadPart);
566 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
567 AFS_TRACE_LEVEL_VERBOSE,
568 "AFSGetConnection Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
569 &pRDRDevExt->Specific.RDR.ProviderListLock,
570 PsGetCurrentThread());
572 if( ConnectCB->AuthenticationId.QuadPart == 0)
575 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
577 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
578 AFS_TRACE_LEVEL_VERBOSE,
579 "AFSGetConnection Retrieved authentication id %I64X\n",
580 ConnectCB->AuthenticationId.QuadPart);
583 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
587 // Look for the connection
590 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
592 while( pConnection != NULL)
595 if( pConnection->LocalName != L'\0')
598 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
599 AFS_TRACE_LEVEL_VERBOSE,
600 "AFSGetConnection Comparing passed in %C to %C authentication id %I64X - %I64X\n",
601 ConnectCB->LocalName,
602 pConnection->LocalName,
603 ConnectCB->AuthenticationId.QuadPart,
604 pConnection->AuthenticationId.QuadPart);
609 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
610 AFS_TRACE_LEVEL_VERBOSE,
611 "AFSGetConnection Comparing passed in %C to (NULL) authentication id %I64X - %I64X\n",
612 ConnectCB->LocalName,
613 ConnectCB->AuthenticationId.QuadPart,
614 pConnection->AuthenticationId.QuadPart);
617 if( pConnection->LocalName == ConnectCB->LocalName &&
618 pConnection->AuthenticationId.QuadPart == ConnectCB->AuthenticationId.QuadPart)
624 pConnection = pConnection->fLink;
627 if( pConnection == NULL)
630 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
631 AFS_TRACE_LEVEL_VERBOSE,
632 "AFSGetConnection INVALID_PARAMETER\n");
634 try_return( ntStatus = STATUS_INVALID_PARAMETER);
637 if( RemoteNameBufferLength < pConnection->RemoteName.Length)
640 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
641 AFS_TRACE_LEVEL_VERBOSE,
642 "AFSGetConnection INSUFFICIENT_RESOURCES\n");
644 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
647 RtlCopyMemory( RemoteName,
648 pConnection->RemoteName.Buffer,
649 pConnection->RemoteName.Length);
651 *ReturnOutputBufferLength = pConnection->RemoteName.Length;
655 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
662 AFSListConnections( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
663 IN ULONG ConnectionBufferLength,
664 IN OUT ULONG_PTR *ReturnOutputBufferLength)
667 NTSTATUS ntStatus = STATUS_SUCCESS;
668 AFSProviderConnectionCB *pConnection = NULL, *pRootConnection = NULL;
669 ULONG ulCopiedLength = 0, ulRemainingLength = ConnectionBufferLength;
670 ULONG ulScope, ulType;
671 UNICODE_STRING uniRemoteName, uniServerName, uniShareName, uniRemainingPath;
672 BOOLEAN bGlobalEnumeration = FALSE;
674 LARGE_INTEGER liAuthenticationID = {0,0};
675 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
681 // Save off some data before moving on
684 ulScope = ConnectCB->Scope;
686 ulType = ConnectCB->Type;
688 if( ConnectCB->AuthenticationId.QuadPart == 0)
691 ConnectCB->AuthenticationId = AFSGetAuthenticationId();
693 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
694 AFS_TRACE_LEVEL_VERBOSE,
695 "AFSListConnections Retrieved authentication id %I64X\n",
696 ConnectCB->AuthenticationId.QuadPart);
699 liAuthenticationID.QuadPart = ConnectCB->AuthenticationId.QuadPart;
701 uniRemoteName.Length = 0;
702 uniRemoteName.MaximumLength = 0;
703 uniRemoteName.Buffer = NULL;
705 uniServerName.Length = 0;
706 uniServerName.MaximumLength = 0;
707 uniServerName.Buffer = NULL;
709 uniShareName.Length = 0;
710 uniShareName.MaximumLength = 0;
711 uniShareName.Buffer = NULL;
713 if( ConnectCB->RemoteNameLength > 0)
716 uniRemoteName.Length = (USHORT)ConnectCB->RemoteNameLength;
717 uniRemoteName.MaximumLength = uniRemoteName.Length + sizeof( WCHAR);
719 uniRemoteName.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
720 uniRemoteName.MaximumLength,
721 AFS_NETWORK_PROVIDER_1_TAG);
723 if( uniRemoteName.Buffer == NULL)
726 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
729 RtlCopyMemory( uniRemoteName.Buffer,
730 ConnectCB->RemoteName,
731 uniRemoteName.Length);
733 if( uniRemoteName.Buffer[ 0] == L'\\' &&
734 uniRemoteName.Buffer[ 1] == L'\\')
737 uniRemoteName.Buffer = &uniRemoteName.Buffer[ 1];
739 uniRemoteName.Length -= sizeof( WCHAR);
742 if( uniRemoteName.Buffer[ (uniRemoteName.Length/sizeof( WCHAR)) - 1] == L'\\')
745 uniRemoteName.Length -= sizeof( WCHAR);
748 FsRtlDissectName( uniRemoteName,
752 uniRemoteName = uniRemainingPath;
754 if( uniRemoteName.Length > 0)
757 FsRtlDissectName( uniRemoteName,
763 // If this is an enumeration of the global share name then
764 // adjust it to be the server name itself
767 if( uniShareName.Length == 0 ||
768 RtlCompareUnicodeString( &uniShareName,
773 bGlobalEnumeration = TRUE;
777 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
778 AFS_TRACE_LEVEL_VERBOSE,
779 "AFSListConnections Acquiring AFSProviderListLock lock %08lX SHARED %08lX\n",
780 &pRDRDevExt->Specific.RDR.ProviderListLock,
781 PsGetCurrentThread());
783 AFSAcquireShared( &pRDRDevExt->Specific.RDR.ProviderListLock,
787 // If this is a globalnet enumeration with no name then enumerate the server list
790 if( ulScope == RESOURCE_GLOBALNET)
793 if( uniServerName.Buffer == NULL)
796 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList;
802 // Go locate the root entry for the name passed in
805 if( bGlobalEnumeration)
808 if( pRDRDevExt->Specific.RDR.ProviderEnumerationList == NULL)
811 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
813 try_return( ntStatus);
816 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList->EnumerationList;
821 pRootConnection = AFSLocateEnumRootEntry( &uniShareName);
823 if( pRootConnection == NULL)
826 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
828 try_return( ntStatus);
832 // Need to handle these enumerations from the directory listing
835 ntStatus = AFSEnumerateConnection( ConnectCB,
837 ConnectionBufferLength,
845 pConnection = pRDRDevExt->Specific.RDR.ProviderConnectionList;
848 ulIndex = ConnectCB->CurrentIndex;
850 while( pConnection != NULL)
853 if( bGlobalEnumeration &&
854 BooleanFlagOn( pConnection->Flags, AFS_CONNECTION_FLAG_GLOBAL_SHARE))
857 pConnection = pConnection->fLink;
862 if( ulScope != RESOURCE_GLOBALNET &&
863 !BooleanFlagOn( pConnection->Usage, RESOURCEUSAGE_ATTACHED))
866 pConnection = pConnection->fLink;
871 if( pConnection->LocalName != L'\0')
874 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
875 AFS_TRACE_LEVEL_VERBOSE,
876 "AFSListConnections Processing entry %wZ %C authentication id %I64X - %I64X Scope %08lX\n",
877 &pConnection->RemoteName,
878 pConnection->LocalName,
879 liAuthenticationID.QuadPart,
880 pConnection->AuthenticationId.QuadPart,
886 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
887 AFS_TRACE_LEVEL_VERBOSE,
888 "AFSListConnections Processing entry %wZ NULL LocalName authentication id %I64X - %I64X Scope %08lX\n",
889 &pConnection->RemoteName,
890 liAuthenticationID.QuadPart,
891 pConnection->AuthenticationId.QuadPart,
895 if( ulScope != RESOURCE_GLOBALNET &&
896 pConnection->AuthenticationId.QuadPart != liAuthenticationID.QuadPart)
899 pConnection = pConnection->fLink;
909 pConnection = pConnection->fLink;
914 if( ulRemainingLength < (ULONG)FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
915 pConnection->RemoteName.Length +
916 pConnection->Comment.Length)
922 ConnectCB->RemoteNameLength = pConnection->RemoteName.Length;
924 RtlCopyMemory( ConnectCB->RemoteName,
925 pConnection->RemoteName.Buffer,
926 pConnection->RemoteName.Length);
928 ConnectCB->LocalName = pConnection->LocalName;
930 ConnectCB->Type = pConnection->Type;
932 ConnectCB->Scope = pConnection->Scope;
934 if( !bGlobalEnumeration)
937 ConnectCB->Scope = RESOURCE_CONNECTED;
940 ConnectCB->DisplayType = pConnection->DisplayType;
942 ConnectCB->Usage = pConnection->Usage;
944 ConnectCB->CommentLength = pConnection->Comment.Length;
946 if( pConnection->Comment.Length > 0)
949 ConnectCB->CommentOffset = (ULONG)(FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
950 ConnectCB->RemoteNameLength);
952 RtlCopyMemory( (void *)((char *)ConnectCB + ConnectCB->CommentOffset),
953 pConnection->Comment.Buffer,
954 ConnectCB->CommentLength);
957 ulCopiedLength += FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
958 ConnectCB->RemoteNameLength +
959 ConnectCB->CommentLength;
961 ulRemainingLength -= FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
962 ConnectCB->RemoteNameLength +
963 ConnectCB->CommentLength;
965 ConnectCB = (AFSNetworkProviderConnectionCB *)((char *)ConnectCB +
966 FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
967 ConnectCB->RemoteNameLength +
968 ConnectCB->CommentLength);
970 pConnection = pConnection->fLink;
973 if( NT_SUCCESS( ntStatus))
976 *ReturnOutputBufferLength = ulCopiedLength;
979 AFSReleaseResource( &pRDRDevExt->Specific.RDR.ProviderListLock);
983 if( uniRemoteName.Buffer != NULL)
986 AFSExFreePoolWithTag( uniRemoteName.Buffer, 0);
994 AFSInitializeConnectionInfo( IN AFSProviderConnectionCB *Connection,
995 IN ULONG DisplayType)
998 NTSTATUS ntStatus = STATUS_SUCCESS;
999 UNICODE_STRING uniName, uniComponentName, uniRemainingName;
1004 uniName = Connection->RemoteName;
1007 // Strip of the double leading slash if there is one
1010 if( uniName.Buffer[ 0] == L'\\' &&
1011 uniName.Buffer[ 1] == L'\\')
1014 uniName.Buffer = &uniName.Buffer[ 1];
1016 uniName.Length -= sizeof( WCHAR);
1020 FsRtlDissectName( uniName,
1025 // Initialize the information for the connection
1026 // First, if this is the server only then mark it accordingly
1029 if( uniRemainingName.Length == 0 ||
1030 DisplayType == RESOURCEDISPLAYTYPE_SERVER)
1033 Connection->Type = RESOURCETYPE_DISK;
1035 Connection->Scope = 0;
1037 Connection->DisplayType = RESOURCEDISPLAYTYPE_SERVER;
1039 Connection->Usage = RESOURCEUSAGE_CONTAINER;
1041 Connection->Comment.Length = 20;
1042 Connection->Comment.MaximumLength = 22;
1044 Connection->Comment.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1045 Connection->Comment.MaximumLength,
1046 AFS_NETWORK_PROVIDER_2_TAG);
1048 if( Connection->Comment.Buffer != NULL)
1051 RtlZeroMemory( Connection->Comment.Buffer,
1052 Connection->Comment.MaximumLength);
1054 RtlCopyMemory( Connection->Comment.Buffer,
1061 Connection->Comment.Length = 0;
1062 Connection->Comment.MaximumLength = 0;
1065 try_return( ntStatus);
1068 uniName = uniRemainingName;
1070 FsRtlDissectName( uniName,
1074 if( uniRemainingName.Length == 0 ||
1075 uniRemainingName.Buffer == NULL ||
1076 DisplayType == RESOURCEDISPLAYTYPE_SHARE)
1079 Connection->Type = RESOURCETYPE_DISK;
1081 Connection->DisplayType = RESOURCEDISPLAYTYPE_SHARE;
1083 Connection->Usage = RESOURCEUSAGE_CONNECTABLE;
1085 if( Connection->LocalName != L'\0')
1088 Connection->Usage |= RESOURCEUSAGE_ATTACHED;
1090 Connection->Scope = RESOURCE_CONNECTED;
1095 Connection->Usage |= RESOURCEUSAGE_NOLOCALDEVICE;
1097 Connection->Scope = RESOURCE_GLOBALNET;
1100 Connection->Comment.Length = 18;
1101 Connection->Comment.MaximumLength = 20;
1103 Connection->Comment.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1104 Connection->Comment.MaximumLength,
1105 AFS_NETWORK_PROVIDER_3_TAG);
1107 if( Connection->Comment.Buffer != NULL)
1110 RtlZeroMemory( Connection->Comment.Buffer,
1111 Connection->Comment.MaximumLength);
1113 RtlCopyMemory( Connection->Comment.Buffer,
1120 Connection->Comment.Length = 0;
1121 Connection->Comment.MaximumLength = 0;
1124 try_return( ntStatus);
1128 // This is a sub directory within a share
1131 Connection->Type = RESOURCETYPE_DISK;
1133 Connection->DisplayType = RESOURCEDISPLAYTYPE_DIRECTORY;
1135 Connection->Usage = RESOURCEUSAGE_CONNECTABLE;
1137 if( Connection->LocalName != L'\0')
1140 Connection->Usage |= RESOURCEUSAGE_ATTACHED;
1145 Connection->Usage |= RESOURCEUSAGE_NOLOCALDEVICE;
1148 Connection->Scope = RESOURCE_CONNECTED;
1150 Connection->Comment.Length = 26;
1151 Connection->Comment.MaximumLength = 28;
1153 Connection->Comment.Buffer = (WCHAR *)AFSExAllocatePoolWithTag( PagedPool,
1154 Connection->Comment.MaximumLength,
1155 AFS_NETWORK_PROVIDER_4_TAG);
1157 if( Connection->Comment.Buffer != NULL)
1160 RtlZeroMemory( Connection->Comment.Buffer,
1161 Connection->Comment.MaximumLength);
1163 RtlCopyMemory( Connection->Comment.Buffer,
1170 Connection->Comment.Length = 0;
1171 Connection->Comment.MaximumLength = 0;
1182 AFSProviderConnectionCB *
1183 AFSLocateEnumRootEntry( IN UNICODE_STRING *RemoteName)
1186 AFSProviderConnectionCB *pConnection = NULL;
1187 UNICODE_STRING uniServerName, uniRemoteName = *RemoteName;
1188 AFSDeviceExt *pRDRDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1193 if( pRDRDevExt->Specific.RDR.ProviderEnumerationList == NULL)
1196 try_return( pConnection);
1199 pConnection = pRDRDevExt->Specific.RDR.ProviderEnumerationList->EnumerationList;
1201 while( pConnection != NULL)
1204 if( RtlCompareUnicodeString( &uniRemoteName,
1205 &pConnection->ComponentName,
1212 pConnection = pConnection->fLink;
1224 AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
1225 IN AFSProviderConnectionCB *RootConnection,
1226 IN ULONG BufferLength,
1227 OUT PULONG CopiedLength)
1230 NTSTATUS ntStatus = STATUS_SUCCESS;
1231 AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1232 ULONG ulCRC = 0, ulCopiedLength = 0;
1233 AFSDirectoryCB *pShareDirEntry = NULL;
1234 AFSDirectoryCB *pDirEntry = NULL, *pTargetDirEntry = NULL;
1236 BOOLEAN bContinueProcessing = TRUE;
1237 AFSFileInfoCB stFileInformation;
1243 if( AFSGlobalRoot == NULL)
1246 AFSDbgLogMsg( AFS_SUBSYSTEM_NETWORK_PROVIDER,
1247 AFS_TRACE_LEVEL_ERROR,
1248 "AFSEnumerateConnection Global root not yet initialized\n");
1250 try_return( ntStatus = STATUS_DEVICE_NOT_READY);
1253 ulCRC = AFSGenerateCRC( &RootConnection->ComponentName,
1257 // Grab our tree lock shared
1260 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
1261 AFS_TRACE_LEVEL_VERBOSE,
1262 "AFSEnumerateConnection Acquiring GlobalRoot DirectoryNodeHdr.TreeLock lock %08lX SHARED %08lX\n",
1263 AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
1264 PsGetCurrentThread());
1266 AFSAcquireShared( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock,
1270 // Locate the dir entry for this node
1273 ntStatus = AFSLocateCaseSensitiveDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
1277 if( pShareDirEntry == NULL ||
1278 !NT_SUCCESS( ntStatus))
1282 // Perform a case insensitive search
1285 ulCRC = AFSGenerateCRC( &RootConnection->ComponentName,
1288 ntStatus = AFSLocateCaseInsensitiveDirEntry( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
1292 if( pShareDirEntry == NULL ||
1293 !NT_SUCCESS( ntStatus))
1296 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
1298 try_return( ntStatus);
1302 lCount = InterlockedIncrement( &pShareDirEntry->OpenReferenceCount);
1304 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1305 AFS_TRACE_LEVEL_VERBOSE,
1306 "AFSEnumerateConnection1 Increment count on %wZ DE %p Ccb %p Cnt %d\n",
1307 &pShareDirEntry->NameInformation.FileName,
1312 AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
1315 // Setup the request to evaluate the entry
1318 ntStatus = AFSEvaluateRootEntry( pShareDirEntry,
1321 if( !NT_SUCCESS( ntStatus))
1324 try_return( ntStatus);
1327 AFSAcquireShared( pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
1331 // Enumerate the content
1334 pDirEntry = pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeListHead;
1336 ulIndex = ConnectCB->CurrentIndex;
1338 while( pDirEntry != NULL)
1346 pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
1351 if( BufferLength < (ULONG)FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1352 pDirEntry->NameInformation.FileName.Length)
1358 ConnectCB->LocalName = L'\0';
1360 ConnectCB->RemoteNameLength = pDirEntry->NameInformation.FileName.Length;
1362 RtlCopyMemory( ConnectCB->RemoteName,
1363 pDirEntry->NameInformation.FileName.Buffer,
1364 pDirEntry->NameInformation.FileName.Length);
1366 ConnectCB->Type = RESOURCETYPE_DISK;
1368 ConnectCB->Scope = RESOURCE_CONNECTED;
1370 if( BooleanFlagOn( pDirEntry->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
1373 ConnectCB->DisplayType = RESOURCEDISPLAYTYPE_DIRECTORY;
1378 ConnectCB->DisplayType = RESOURCEDISPLAYTYPE_FILE;
1381 ConnectCB->Usage = 0;
1383 ConnectCB->CommentLength = 0;
1385 ulCopiedLength += FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1386 pDirEntry->NameInformation.FileName.Length;
1388 BufferLength -= FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1389 pDirEntry->NameInformation.FileName.Length;
1391 ConnectCB = (AFSNetworkProviderConnectionCB *)((char *)ConnectCB +
1392 FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
1393 ConnectCB->RemoteNameLength);
1395 pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
1398 lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
1400 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1401 AFS_TRACE_LEVEL_VERBOSE,
1402 "AFSEnumerateConnection Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
1403 &pTargetDirEntry->NameInformation.FileName,
1408 *CopiedLength = ulCopiedLength;
1410 AFSReleaseResource( pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
1414 if( pShareDirEntry != NULL)
1416 lCount = InterlockedDecrement( &pShareDirEntry->OpenReferenceCount);
1418 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
1419 AFS_TRACE_LEVEL_VERBOSE,
1420 "AFSEnumerateConnection1 Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
1421 &pShareDirEntry->NameInformation.FileName,
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 %08lX 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 %08lX 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;