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 #define _WIN32_WINNT 0x0500
49 #define AFS_DEBUG_TRACE 1
51 #ifndef WNNC_NET_OPENAFS
52 #define WNNC_NET_OPENAFS 0x00390000
55 #include "AFSUserDefines.h"
56 #include "AFSUserIoctl.h"
57 #include "AFSUserStructs.h"
58 #include "AFSProvider.h"
59 #include "AFS_Npdll.h"
67 #define SCRATCHSZ 1024
73 ULONG _cdecl AFSDbgPrint( PWCHAR Format, ... );
75 #define WNNC_DRIVER( major, minor ) ( major * 0x00010000 + minor )
77 #define OPENAFS_PROVIDER_NAME L"OpenAFS Network"
78 #define OPENAFS_PROVIDER_NAME_LENGTH 30
80 #define MAX_PROVIDER_NAME_LENGTH 256
82 static ULONG cbProviderNameLength = OPENAFS_PROVIDER_NAME_LENGTH;
84 static wchar_t wszProviderName[MAX_PROVIDER_NAME_LENGTH+1] = OPENAFS_PROVIDER_NAME;
86 static BOOL bProviderNameRead = FALSE;
88 #define OPENAFS_SERVER_NAME L"AFS"
89 #define OPENAFS_SERVER_NAME_LENGTH 6
91 #define OPENAFS_SERVER_COMMENT L"AFS Root"
92 #define OPENAFS_SERVER_COMMENT_LENGTH 16
94 #define MAX_SERVER_NAME_LENGTH 30
96 static ULONG cbServerNameLength = 0;
98 static ULONG cbServerNameUNCLength = 0;
100 static ULONG cbServerCommentLength = OPENAFS_SERVER_COMMENT_LENGTH;
102 static wchar_t wszServerName[MAX_SERVER_NAME_LENGTH+1];
104 static wchar_t wszServerNameUNC[MAX_SERVER_NAME_LENGTH+3];
106 static wchar_t wszServerComment[] = OPENAFS_SERVER_COMMENT;
108 static BOOL bServerNameRead = FALSE;
111 AFSRetrieveAuthId( void);
114 ReadProviderNameString( void)
120 if ( bProviderNameRead )
123 code = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
124 L"SYSTEM\\CurrentControlSet\\Services\\AFSRedirector\\NetworkProvider",
125 0, KEY_QUERY_VALUE, &hk);
127 if ( code == ERROR_SUCCESS) {
129 dwLen = sizeof(wszProviderName);
131 code = RegQueryValueExW( hk, L"Name", NULL, NULL,
132 (LPBYTE) wszProviderName, &dwLen);
134 if ( code == ERROR_SUCCESS)
137 wszProviderName[MAX_PROVIDER_NAME_LENGTH] = '\0';
139 cbProviderNameLength = wcslen( wszProviderName) * sizeof( WCHAR);
145 bProviderNameRead = TRUE;
149 ReadServerNameString( void)
155 if ( bServerNameRead )
158 code = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
159 L"SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters",
160 0, KEY_QUERY_VALUE, &hk);
162 if ( code == ERROR_SUCCESS) {
164 dwLen = sizeof(wszProviderName);
166 code = RegQueryValueExW( hk, L"NetbiosName", NULL, NULL,
167 (LPBYTE) wszServerName, &dwLen);
169 if ( code == ERROR_SUCCESS)
172 wszServerName[MAX_SERVER_NAME_LENGTH] = '\0';
174 cbServerNameLength = wcslen( wszServerName) * sizeof( WCHAR);
176 wszServerNameUNC[0] = wszServerNameUNC[1] = L'\\';
178 memcpy(&wszServerNameUNC[2], wszServerName, (cbServerNameLength + 1) * sizeof( WCHAR));
180 cbServerNameUNCLength = cbServerNameLength + 2 * sizeof( WCHAR);
186 bServerNameRead = TRUE;
191 /* returns TRUE if the file system is disabled or not installed */
193 NPIsFSDisabled( void)
198 DWORD dwStart = SERVICE_DISABLED;
200 code = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
201 L"SYSTEM\\CurrentControlSet\\Services\\AFSRedirector",
202 0, KEY_QUERY_VALUE, &hk);
204 if ( code != ERROR_SUCCESS)
209 dwLen = sizeof(dwStart);
211 code = RegQueryValueExW( hk, L"Start", NULL, NULL,
212 (LPBYTE) &dwStart, &dwLen);
216 return ( dwStart == SERVICE_DISABLED);
220 #define try_return(S) { S; goto try_exit; }
226 typedef struct _UNICODE_STRING {
228 USHORT MaximumLength;
230 } UNICODE_STRING, *PUNICODE_STRING;
233 OpenRedirector( void);
235 typedef struct _AFS_ENUM_CB
250 // Recursively evaluate drivestr to find the final
251 // dos drive letter to which the source is mapped.
254 DriveSubstitution(LPCWSTR drivestr, LPWSTR subststr, size_t substlen)
257 WCHAR device[MAX_PATH + 1];
260 memset( subststr, 0, substlen);
261 drive[0] = drivestr[0];
262 drive[1] = drivestr[1];
265 if ( QueryDosDevice(drive, device, MAX_PATH) )
267 #ifdef AFS_DEBUG_TRACE
268 AFSDbgPrint( L"DriveSubstitution QueryDosDevice %s [%s -> %s]\n",
273 if ( device[0] == L'\\' &&
276 device[3] == L'\\' &&
277 iswalpha(device[4]) &&
280 drive[0] = device[4];
284 if ( !DriveSubstitution(drive, subststr, substlen) )
287 subststr[0] = drive[0];
297 hr = StringCchCat( subststr, substlen, &device[6]);
299 if ( SUCCEEDED(hr) && drivestr[2] )
301 hr = StringCchCat( subststr, substlen, &drivestr[2]);
304 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
307 #ifdef AFS_DEBUG_TRACE
308 AFSDbgPrint( L"DriveSubstitution %s -> %s\n",
315 else if ( device[0] == L'\\' &&
318 device[3] == L'\\' &&
327 hr = StringCbCopyN(&subststr[1], substlen - sizeof(WCHAR), &device[7], MAX_PATH);
329 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
333 hr = StringCchCat( subststr, substlen, &drivestr[2]);
340 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
343 #ifdef AFS_DEBUG_TRACE
344 AFSDbgPrint( L"DriveSubstitution %s -> %s\n",
352 #ifdef AFS_DEBUG_TRACE
353 AFSDbgPrint( L"DriveSubstitution StringCbCopyN 1 hr 0x%X\n",
357 else if ( _wcsnicmp( AFS_RDR_DEVICE_NAME, device, sizeof( AFS_RDR_DEVICE_NAME) / sizeof( WCHAR) - 1) == 0)
360 // \Device\AFSRedirector\;X:\\afs\cellname
363 hr = StringCbCopyN( subststr, substlen,
364 &device[3 + sizeof( AFS_RDR_DEVICE_NAME) / sizeof( WCHAR)],
365 MAX_PATH * sizeof( WCHAR));
367 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
372 hr = StringCchCat( subststr, substlen, &drivestr[2]);
379 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
382 #ifdef AFS_DEBUG_TRACE
383 AFSDbgPrint( L"DriveSubstitution %s -> %s\n",
391 #ifdef AFS_DEBUG_TRACE
392 AFSDbgPrint( L"DriveSubstitution StringCbCopyN 2 hr 0x%X\n",
397 #ifdef AFS_DEBUG_TRACE
398 AFSDbgPrint( L"DriveSubstitution no substitution or match %s !! %s\n",
405 #ifdef AFS_DEBUG_TRACE
406 AFSDbgPrint( L"DriveSubstitution QueryDosDevice failed %s gle 0x%X\n",
419 NPGetCapsQueryString( DWORD nIndex)
422 case WNNC_SPEC_VERSION:
423 return L"WNNC_SPEC_VERSION";
426 return L"WNNC_NET_TYPE";
428 case WNNC_DRIVER_VERSION:
429 return L"WNNC_DRIVER_VERSION";
434 case WNNC_CONNECTION:
435 return L"WNNC_CONNECTION";
438 return L"WNNC_DIALOG";
441 return L"WNNC_ADMIN";
443 case WNNC_ENUMERATION:
444 return L"WNNC_ENUMERATION";
447 return L"WNNC_START";
449 case WNNC_CONNECTION_FLAGS:
450 return L"WNNC_CONNECTION_FLAGS";
458 // This is the only function which must be exported, everything else is optional
463 NPGetCaps( DWORD nIndex )
468 #ifdef AFS_DEBUG_TRACE
469 AFSDbgPrint( L"NPGetCaps Index %u %s\n", nIndex,
470 NPGetCapsQueryString( nIndex));
474 case WNNC_SPEC_VERSION:
477 rc = WNNC_SPEC_VERSION51;
483 rc = WNNC_NET_OPENAFS;
487 case WNNC_DRIVER_VERSION:
490 rc = WNNC_DRIVER(1, 0);
494 case WNNC_CONNECTION:
499 // WNNC_CON_GETPERFORMANCE
503 rc = WNNC_CON_GETCONNECTIONS |
504 WNNC_CON_CANCELCONNECTION |
505 WNNC_CON_ADDCONNECTION |
506 WNNC_CON_ADDCONNECTION3;
511 case WNNC_ENUMERATION:
513 rc = WNNC_ENUM_LOCAL |
523 rc = WNNC_WAIT_FOR_START;
533 // WNNC_DLG_DEVICEMODE
534 // WNNC_DLG_PROPERTYDIALOG
535 // WNNC_DLG_SEARCHDIALOG
536 // WNNC_DLG_PERMISSIONEDITOR
539 rc = WNNC_DLG_FORMATNETWORKNAME |
540 WNNC_DLG_GETRESOURCEINFORMATION |
541 WNNC_DLG_GETRESOURCEPARENT;
560 // WNNC_ADM_GETDIRECTORYTYPE
561 // WNNC_ADM_DIRECTORYNOTIFY
562 // used by the old File Manager
573 NPAddConnection( LPNETRESOURCE lpNetResource,
578 #ifdef AFS_DEBUG_TRACE
579 AFSDbgPrint( L"NPAddConnection forwarding to NPAddConnection3\n");
581 return NPAddConnection3( NULL, lpNetResource, lpPassword, lpUserName, 0 );
586 NPAddConnection3( HWND hwndOwner,
587 LPNETRESOURCE lpNetResource,
593 DWORD dwStatus = WN_SUCCESS;
594 WCHAR wchRemoteName[MAX_PATH+1];
595 WCHAR wchLocalName[3];
596 DWORD dwCopyBytes = 0;
597 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
599 DWORD dwBufferSize = 0;
600 HANDLE hControlDevice = NULL;
601 HANDLE hToken = NULL;
602 LARGE_INTEGER liAuthId = {0,0};
606 if ( NPIsFSDisabled())
609 #ifdef AFS_DEBUG_TRACE
610 AFSDbgPrint( L"NPAddConnection3 AFSRDFS is disabled, returning WN_BAD_NETNAME\n");
613 return WN_BAD_NETNAME;
616 if ((lpNetResource->lpRemoteName == NULL) ||
617 (lpNetResource->lpRemoteName[0] != L'\\') ||
618 (lpNetResource->lpRemoteName[1] != L'\\') ||
619 ((lpNetResource->dwType != RESOURCETYPE_DISK) &&
620 (lpNetResource->dwType != RESOURCETYPE_ANY)))
623 #ifdef AFS_DEBUG_TRACE
624 AFSDbgPrint( L"NPAddConnection3 invalid input, returning WN_BAD_NETNAME\n");
626 return WN_BAD_NETNAME;
629 #ifdef AFS_DEBUG_TRACE
630 AFSDbgPrint( L"NPAddConnection3 processing\n");
632 if( lpNetResource->lpLocalName != NULL)
635 wchLocalName[0] = towupper(lpNetResource->lpLocalName[0]);
636 wchLocalName[1] = L':';
637 wchLocalName[2] = L'\0';
640 StringCchCopy(wchRemoteName, MAX_PATH+1, lpNetResource->lpRemoteName);
641 wchRemoteName[MAX_PATH] = L'\0';
644 // Allocate our buffer to pass to the redirector filter
647 dwBufferSize = sizeof( AFSNetworkProviderConnectionCB) + (wcslen( wchRemoteName) * sizeof( WCHAR));
649 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
651 if( pConnectCB == NULL)
654 try_return( dwStatus = WN_OUT_OF_MEMORY);
657 if( lpNetResource->lpLocalName != NULL)
660 pConnectCB->LocalName = towupper(wchLocalName[0]);
662 #ifdef AFS_DEBUG_TRACE
663 AFSDbgPrint( L"NPAddConnection3 Adding mapping for drive %s remote name %s\n",
671 pConnectCB->LocalName = L'\0';
673 #ifdef AFS_DEBUG_TRACE
674 AFSDbgPrint( L"NPAddConnection3 Adding mapping for NO drive remote name %s\n",
679 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
681 pConnectCB->RemoteNameLength = wcslen( wchRemoteName) * sizeof( WCHAR);
683 memcpy( pConnectCB->RemoteName,
685 pConnectCB->RemoteNameLength);
687 pConnectCB->Type = lpNetResource->dwType;
689 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
691 #ifdef AFS_DEBUG_TRACE
692 AFSDbgPrint( L"NPAddConnection3 Retrieved authentication id %08lX-%08lX\n",
693 pConnectCB->AuthenticationId.HighPart,
694 pConnectCB->AuthenticationId.LowPart);
697 hControlDevice = OpenRedirector();
699 if( hControlDevice == NULL)
702 #ifdef AFS_DEBUG_TRACE
703 AFSDbgPrint( L"NPAddConnection3 OpenRedirector failure, returning WN_NET_ERROR\n");
706 try_return( dwStatus = WN_NET_ERROR);
709 dwError = DeviceIoControl( hControlDevice,
710 IOCTL_AFS_ADD_CONNECTION,
720 #ifdef AFS_DEBUG_TRACE
721 AFSDbgPrint( L"NPAddConnection3 Failed to add connection to file system %d\n", GetLastError());
723 try_return( dwStatus = WN_OUT_OF_MEMORY);
727 // The status returned from the driver will indicate how it was handled
730 if( dwStatus == WN_SUCCESS &&
731 lpNetResource->lpLocalName != NULL)
734 WCHAR TempBuf[MAX_PATH+1];
736 if( !QueryDosDeviceW( wchLocalName,
741 if( GetLastError() != ERROR_FILE_NOT_FOUND)
744 #ifdef AFS_DEBUG_TRACE
745 AFSDbgPrint( L"NPAddConnection3 QueryDosDeviceW failed with file not found\n");
747 NPCancelConnection( wchLocalName, TRUE);
749 dwStatus = ERROR_ALREADY_ASSIGNED;
754 UNICODE_STRING uniConnectionName;
755 UNICODE_STRING uniDeviceName;
757 uniDeviceName.Length = (wcslen( AFS_RDR_DEVICE_NAME) * sizeof( WCHAR));
758 uniDeviceName.MaximumLength = uniDeviceName.Length;
759 uniDeviceName.Buffer = AFS_RDR_DEVICE_NAME;
762 // Create a symbolic link object to the device we are redirecting
765 uniConnectionName.MaximumLength = (USHORT)( uniDeviceName.Length +
766 pConnectCB->RemoteNameLength +
767 8 + // Local name and \;
768 sizeof(WCHAR)); // Space for NULL-termination.
771 // Don't include NULL-termination.
774 uniConnectionName.Length = uniConnectionName.MaximumLength - sizeof(WCHAR);
776 uniConnectionName.Buffer = LocalAlloc( LMEM_ZEROINIT,
777 uniConnectionName.MaximumLength);
779 if( uniConnectionName.Buffer == NULL)
782 try_return( dwStatus = GetLastError());
785 CopyMemory( uniConnectionName.Buffer,
786 uniDeviceName.Buffer,
787 uniDeviceName.Length);
789 StringCchCatW( uniConnectionName.Buffer,
790 uniConnectionName.MaximumLength,
793 StringCchCatW( uniConnectionName.Buffer,
794 uniConnectionName.MaximumLength,
797 StringCchCatW( uniConnectionName.Buffer,
798 uniConnectionName.MaximumLength,
801 #ifdef AFS_DEBUG_TRACE
802 AFSDbgPrint( L"NPAddConnection3 DefineDosDevice Local %s connection name %s\n",
804 uniConnectionName.Buffer);
807 if( !DefineDosDeviceW( DDD_RAW_TARGET_PATH |
808 DDD_NO_BROADCAST_SYSTEM,
810 uniConnectionName.Buffer))
812 #ifdef AFS_DEBUG_TRACE
813 AFSDbgPrint( L"NPAddConnection3 Failed to assign drive\n");
815 dwStatus = GetLastError();
820 dwStatus = WN_SUCCESS;
823 LocalFree( uniConnectionName.Buffer);
829 #ifdef AFS_DEBUG_TRACE
830 AFSDbgPrint( L"NPAddConnection3 QueryDosDeviceW %Z already existed\n", TempBuf);
832 NPCancelConnection( wchLocalName, TRUE);
834 dwStatus = ERROR_ALREADY_ASSIGNED;
840 if ( hControlDevice != NULL)
843 CloseHandle( hControlDevice);
846 if( pConnectCB != NULL)
849 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
858 NPCancelConnection( LPWSTR lpName,
862 WCHAR wchRemoteName[MAX_PATH+1];
863 DWORD dwRemoteNameLength = (MAX_PATH+1) * sizeof(WCHAR);
864 DWORD dwStatus = WN_NOT_CONNECTED;
865 DWORD dwCopyBytes = 0;
866 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
867 AFSCancelConnectionResultCB stCancelConn;
869 DWORD dwBufferSize = 0;
870 BOOL bLocalName = TRUE;
871 HANDLE hControlDevice = NULL;
872 WCHAR *pwchLocalName = NULL;
877 if ( NPIsFSDisabled())
880 #ifdef AFS_DEBUG_TRACE
881 AFSDbgPrint( L"NPCancelConnection AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
884 try_return( dwStatus = WN_NOT_CONNECTED);
887 if( *lpName == L'\\' &&
888 *(lpName + 1) == L'\\')
898 // Get the remote name for the connection, if we are handling it
901 dwStatus = NPGetConnection( lpName,
903 &dwRemoteNameLength);
905 if( dwStatus != WN_SUCCESS ||
906 dwRemoteNameLength == 0)
909 #ifdef AFS_DEBUG_TRACE
910 AFSDbgPrint( L"NPCancelConnection Status 0x%x NameLength %u, returning WN_NOT_CONNECTED\n",
911 dwStatus, dwRemoteNameLength);
913 try_return( dwStatus = WN_NOT_CONNECTED);
919 StringCchCopyW( wchRemoteName, MAX_PATH+1, lpName);
921 dwRemoteNameLength = (wcslen( wchRemoteName) * sizeof( WCHAR));
924 wchRemoteName[ dwRemoteNameLength/sizeof( WCHAR)] = L'\0';
926 dwBufferSize = sizeof( AFSNetworkProviderConnectionCB) + dwRemoteNameLength;
928 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
930 if( pConnectCB == NULL)
933 try_return( dwStatus = WN_OUT_OF_MEMORY);
939 pConnectCB->LocalName = towupper(lpName[0]);
944 pConnectCB->LocalName = L'\0';
947 pConnectCB->RemoteNameLength = (USHORT)dwRemoteNameLength;
949 StringCchCopyW( pConnectCB->RemoteName,
953 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
955 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
957 #ifdef AFS_DEBUG_TRACE
958 AFSDbgPrint( L"NPCancelConnection Retrieved authentication id %08lX-%08lX\n",
959 pConnectCB->AuthenticationId.HighPart,
960 pConnectCB->AuthenticationId.LowPart);
963 hControlDevice = OpenRedirector();
965 if( hControlDevice == NULL)
968 #ifdef AFS_DEBUG_TRACE
969 AFSDbgPrint( L"NPCancelConnection OpenRedirector failure, returning WN_NET_ERROR\n");
972 try_return( dwStatus = WN_NET_ERROR);
975 memset( &stCancelConn,
977 sizeof( AFSCancelConnectionResultCB));
979 dwError = DeviceIoControl( hControlDevice,
980 IOCTL_AFS_CANCEL_CONNECTION,
984 sizeof( AFSCancelConnectionResultCB),
990 #ifdef AFS_DEBUG_TRACE
991 DWORD gle = GetLastError();
993 AFSDbgPrint( L"NPCancelConnection Failed to cancel connection to file system - gle 0x%x\n", gle);
995 try_return( dwStatus = WN_NOT_CONNECTED);
998 dwStatus = stCancelConn.Status;
1000 #ifdef AFS_DEBUG_TRACE
1002 AFSDbgPrint( L"NPCancelConnection Cancel connection to file system - Name %s Status %08lX\n",
1007 if( dwStatus == WN_SUCCESS &&
1009 stCancelConn.LocalName != L'\0'))
1012 UNICODE_STRING uniConnectionName;
1013 UNICODE_STRING uniDeviceName;
1015 uniDeviceName.Length = (wcslen( AFS_RDR_DEVICE_NAME) * sizeof( WCHAR));
1016 uniDeviceName.MaximumLength = uniDeviceName.Length;
1017 uniDeviceName.Buffer = AFS_RDR_DEVICE_NAME;
1020 // Create a symbolic link object to the device we are redirecting
1023 uniConnectionName.MaximumLength = (USHORT)( uniDeviceName.Length +
1024 dwRemoteNameLength +
1025 8 + // Local name and \;
1026 sizeof(WCHAR)); // Space for NULL-termination.
1029 // Don't include NULL-termination.
1032 uniConnectionName.Length = uniConnectionName.MaximumLength - sizeof(WCHAR);
1034 uniConnectionName.Buffer = LocalAlloc( LMEM_ZEROINIT,
1035 uniConnectionName.MaximumLength);
1037 if( uniConnectionName.Buffer == NULL)
1040 try_return( dwStatus = GetLastError());
1043 CopyMemory( uniConnectionName.Buffer,
1044 uniDeviceName.Buffer,
1045 uniDeviceName.Length);
1047 StringCchCatW( uniConnectionName.Buffer,
1048 uniConnectionName.MaximumLength,
1054 WCHAR wchLocalName[ 3];
1056 wchLocalName[ 0] = stCancelConn.LocalName;
1058 wchLocalName[ 1] = L':';
1060 wchLocalName[ 2] = L'\0';
1062 StringCchCatW( uniConnectionName.Buffer,
1063 uniConnectionName.MaximumLength,
1066 pwchLocalName = wchLocalName;
1071 StringCchCatW( uniConnectionName.Buffer,
1072 uniConnectionName.MaximumLength,
1075 pwchLocalName = lpName;
1078 StringCchCatW( uniConnectionName.Buffer,
1079 uniConnectionName.MaximumLength,
1082 if( !DefineDosDevice( DDD_REMOVE_DEFINITION | DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE,
1084 uniConnectionName.Buffer))
1087 #ifdef AFS_DEBUG_TRACE
1088 DWORD gle = GetLastError();
1090 AFSDbgPrint( L"NPCancelConnection Failed to cancel connection to system - gle 0x%x Name %s connection %wZ\n",
1093 &uniConnectionName);
1098 #ifdef AFS_DEBUG_TRACE
1100 AFSDbgPrint( L"NPCancelConnection Canceled connection to system - Name %s connection %wZ\n",
1102 &uniConnectionName);
1109 if ( hControlDevice != NULL)
1112 CloseHandle( hControlDevice);
1116 if( pConnectCB != NULL)
1119 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1129 NPGetConnection( LPWSTR lpLocalName,
1130 LPWSTR lpRemoteName,
1131 LPDWORD lpBufferSize)
1134 DWORD dwStatus = WN_NOT_CONNECTED;
1135 WCHAR wchLocalName[3];
1136 WCHAR wchSubstName[MAX_PATH + 1];
1137 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
1139 DWORD dwBufferSize = 0;
1140 HANDLE hControlDevice = NULL;
1146 if ( NPIsFSDisabled())
1149 #ifdef AFS_DEBUG_TRACE
1150 AFSDbgPrint( L"NPGetConnection AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
1153 try_return( dwStatus = WN_NOT_CONNECTED);
1156 if( lstrlen( lpLocalName) == 0)
1158 #ifdef AFS_DEBUG_TRACE
1159 AFSDbgPrint( L"NPGetConnection No local name, returning WN_BAD_LOCALNAME\n");
1161 try_return( dwStatus = WN_BAD_LOCALNAME);
1164 if ( lpBufferSize == NULL)
1166 #ifdef AFS_DEBUG_TRACE
1167 AFSDbgPrint( L"NPGetConnection No output size, returning WN_BAD_LOCALNAME\n");
1169 try_return( dwStatus = WN_BAD_VALUE);
1172 dwPassedSize = *lpBufferSize;
1174 if ( !DriveSubstitution( lpLocalName, wchSubstName, sizeof( wchSubstName)))
1176 wchLocalName[0] = towupper(lpLocalName[0]);
1177 wchLocalName[1] = L':';
1178 wchLocalName[2] = L'\0';
1180 #ifdef AFS_DEBUG_TRACE
1181 AFSDbgPrint( L"NPGetConnection Requesting connection for %s\n",
1187 ReadServerNameString();
1189 if ( wchSubstName[0] != L'\\' &&
1190 wchSubstName[1] == L':')
1193 wchLocalName[0] = towupper(wchSubstName[0]);
1194 wchLocalName[1] = L':';
1195 wchLocalName[2] = L'\0';
1197 #ifdef AFS_DEBUG_TRACE
1198 AFSDbgPrint( L"NPGetConnection Requesting connection for drive substitution %s -> %s\n",
1203 else if ( _wcsnicmp( wchSubstName, wszServerNameUNC, cbServerNameUNCLength / sizeof( WCHAR)) == 0 &&
1204 ( wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == L'\\' ||
1205 wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == 0))
1211 #ifdef AFS_DEBUG_TRACE
1212 AFSDbgPrint( L"NPGetConnection drive substitution %s is AFS\n",
1216 if ( lpRemoteName == NULL ||
1220 *lpBufferSize = wcslen( wchSubstName) * sizeof( WCHAR) + sizeof( WCHAR);
1222 try_return( dwStatus = WN_MORE_DATA);
1226 hr = StringCbCopyN(lpRemoteName, *lpBufferSize, wchSubstName, sizeof( wchSubstName));
1231 for ( dwCount = 0, pwch = lpRemoteName; *pwch; pwch++ )
1233 if ( *pwch == L'\\' )
1247 *lpBufferSize = wcslen( lpRemoteName) * sizeof( WCHAR) + sizeof( WCHAR);
1249 try_return( dwStatus = WN_SUCCESS);
1251 else if ( hr == STRSAFE_E_INSUFFICIENT_BUFFER)
1254 *lpBufferSize = wcslen( wchSubstName) * sizeof( WCHAR) + sizeof( WCHAR);
1256 for ( dwCount = 0, pwch = lpRemoteName; *pwch; pwch++ )
1258 if ( *pwch == L'\\' )
1266 *lpBufferSize = wcslen( lpRemoteName) * sizeof( WCHAR) + sizeof( WCHAR);
1268 try_return( dwStatus = WN_SUCCESS);
1274 try_return( dwStatus = WN_MORE_DATA);
1279 #ifdef AFS_DEBUG_TRACE
1280 AFSDbgPrint( L"NPGetConnection StringCbCopyN failure 0x%X\n",
1283 try_return( dwStatus = WN_NET_ERROR);
1289 #ifdef AFS_DEBUG_TRACE
1290 AFSDbgPrint( L"NPGetConnection drive substitution %s is not AFS\n",
1293 try_return( dwStatus = WN_NOT_CONNECTED);
1297 #ifdef AFS_DEBUG_TRACE
1298 AFSDbgPrint( L"NPGetConnection Requesting connection for %s\n",
1302 dwBufferSize = 0x1000;
1304 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
1306 if( pConnectCB == NULL)
1309 try_return( dwStatus = WN_OUT_OF_MEMORY);
1312 pConnectCB->LocalName = towupper(wchLocalName[0]);
1314 pConnectCB->RemoteNameLength = 0;
1316 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
1318 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
1320 #ifdef AFS_DEBUG_TRACE
1321 AFSDbgPrint( L"NPGetConnection Retrieved authentication id %08lX-%08lX\n",
1322 pConnectCB->AuthenticationId.HighPart,
1323 pConnectCB->AuthenticationId.LowPart);
1326 hControlDevice = OpenRedirector();
1328 if( hControlDevice == NULL)
1331 #ifdef AFS_DEBUG_TRACE
1332 AFSDbgPrint( L"NPGetConnection OpenRedirector failure, returning WN_NET_ERROR\n");
1335 try_return( dwStatus = WN_NET_ERROR);
1338 dwError = DeviceIoControl( hControlDevice,
1339 IOCTL_AFS_GET_CONNECTION,
1349 #ifdef AFS_DEBUG_TRACE
1350 DWORD gle = GetLastError();
1352 AFSDbgPrint( L"NPGetConnection Failed to get connection from file system for local %s gle 0x%x\n",
1355 try_return( dwStatus = WN_NOT_CONNECTED);
1359 // IOCTL_AFS_GET_CONNECTION returns a counted string
1362 if( lpRemoteName == NULL ||
1363 *lpBufferSize + sizeof( WCHAR) > dwPassedSize)
1366 *lpBufferSize += sizeof( WCHAR);
1368 try_return( dwStatus = WN_MORE_DATA);
1371 memcpy( lpRemoteName,
1375 lpRemoteName[ *lpBufferSize/sizeof( WCHAR)] = L'\0';
1377 *lpBufferSize += sizeof( WCHAR);
1379 #ifdef AFS_DEBUG_TRACE
1380 AFSDbgPrint( L"NPGetConnection local %s remote %s\n",
1384 dwStatus = WN_SUCCESS;
1388 if ( hControlDevice != NULL)
1391 CloseHandle( hControlDevice);
1394 if( pConnectCB != NULL)
1397 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1406 NPGetConnection3( IN LPCWSTR lpLocalName,
1408 OUT LPVOID lpBuffer,
1409 IN OUT LPDWORD lpBufferSize)
1412 DWORD dwStatus = WN_NOT_CONNECTED;
1413 WCHAR wchLocalName[3];
1414 WCHAR wchSubstName[MAX_PATH + 1];
1415 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
1417 DWORD dwBufferSize = 0;
1418 HANDLE hControlDevice = NULL;
1420 DWORD *pConnectState =(DWORD *)lpBuffer;
1425 if ( NPIsFSDisabled())
1428 #ifdef AFS_DEBUG_TRACE
1429 AFSDbgPrint( L"NPGetConnection3 AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
1432 try_return( dwStatus = WN_NOT_CONNECTED);
1435 if( lstrlen( lpLocalName) == 0)
1437 #ifdef AFS_DEBUG_TRACE
1438 AFSDbgPrint( L"NPGetConnection3 No local name, returning WN_BAD_LOCALNAME\n");
1440 try_return( dwStatus = WN_BAD_LOCALNAME);
1444 // LanMan NPGetConnection3 only responds to level 1
1447 if ( dwLevel != 0x1)
1449 #ifdef AFS_DEBUG_TRACE
1450 AFSDbgPrint( L"NPGetConnection3 Level 0x%X returning WN_BAD_LEVEL\n", dwLevel);
1452 try_return( dwStatus = WN_BAD_LEVEL);
1455 if ( lpBufferSize == NULL)
1457 #ifdef AFS_DEBUG_TRACE
1458 AFSDbgPrint( L"NPGetConnection3 No output size, returning WN_BAD_VALUE\n");
1460 try_return( dwStatus = WN_BAD_VALUE);
1463 dwPassedSize = *lpBufferSize;
1465 if ( dwPassedSize == 0 ||
1469 *lpBufferSize = sizeof( DWORD);
1471 try_return( dwStatus = WN_MORE_DATA);
1474 if ( !DriveSubstitution( lpLocalName, wchSubstName, sizeof( wchSubstName)))
1476 wchLocalName[0] = towupper(lpLocalName[0]);
1477 wchLocalName[1] = L':';
1478 wchLocalName[2] = L'\0';
1480 #ifdef AFS_DEBUG_TRACE
1481 AFSDbgPrint( L"NPGetConnection3 Requesting connection for %s level 0x%X\n",
1489 ReadServerNameString();
1491 if ( wchSubstName[0] != L'\\' &&
1492 wchSubstName[1] == L':')
1495 wchLocalName[0] = towupper(wchSubstName[0]);
1496 wchLocalName[1] = L':';
1497 wchLocalName[2] = L'\0';
1499 #ifdef AFS_DEBUG_TRACE
1500 AFSDbgPrint( L"NPGetConnection3 Requesting connection for drive substitution %s -> %s level 0x%x\n",
1506 else if ( _wcsnicmp( wchSubstName, wszServerNameUNC, cbServerNameUNCLength / sizeof( WCHAR)) == 0 &&
1507 ( wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == L'\\' ||
1508 wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == 0))
1511 #ifdef AFS_DEBUG_TRACE
1512 AFSDbgPrint( L"NPGetConnection3 drive substitution %s is AFS return connected\n",
1515 *pConnectState = WNGETCON_CONNECTED;
1517 *lpBufferSize = sizeof( DWORD);
1519 try_return( dwStatus = WN_SUCCESS);
1524 #ifdef AFS_DEBUG_TRACE
1525 AFSDbgPrint( L"NPGetConnection3 drive substitution %s is not AFS return not connected\n",
1528 try_return( dwStatus = WN_NOT_CONNECTED);
1532 dwBufferSize = 0x1000;
1534 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
1536 if( pConnectCB == NULL)
1539 try_return( dwStatus = WN_OUT_OF_MEMORY);
1542 pConnectCB->LocalName = towupper(wchLocalName[0]);
1544 pConnectCB->RemoteNameLength = 0;
1546 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
1548 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
1550 #ifdef AFS_DEBUG_TRACE
1551 AFSDbgPrint( L"NPGetConnection3 Retrieved authentication id %08lX-%08lX\n",
1552 pConnectCB->AuthenticationId.HighPart,
1553 pConnectCB->AuthenticationId.LowPart);
1556 hControlDevice = OpenRedirector();
1558 if( hControlDevice == NULL)
1561 #ifdef AFS_DEBUG_TRACE
1562 AFSDbgPrint( L"NPGetConnection3 OpenRedirector failure, returning WN_NET_ERROR\n");
1565 try_return( dwStatus = WN_NET_ERROR);
1568 dwError = DeviceIoControl( hControlDevice,
1569 IOCTL_AFS_GET_CONNECTION,
1579 #ifdef AFS_DEBUG_TRACE
1580 DWORD gle = GetLastError();
1582 AFSDbgPrint( L"NPGetConnection3 Failed to get connection from file system for local %s gle 0x%x\n",
1585 try_return( dwStatus = WN_NOT_CONNECTED);
1588 *lpBufferSize = sizeof( DWORD);
1590 if( sizeof( DWORD) > dwPassedSize)
1593 try_return( dwStatus = WN_MORE_DATA);
1596 *pConnectState = WNGETCON_CONNECTED;
1598 #ifdef AFS_DEBUG_TRACE
1599 AFSDbgPrint( L"NPGetConnection3 local %s connect-state 0x%x\n",
1603 dwStatus = WN_SUCCESS;
1607 if ( hControlDevice != NULL)
1610 CloseHandle( hControlDevice);
1613 if( pConnectCB != NULL)
1616 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1625 NPGetConnectionPerformance( LPCWSTR lpRemoteName,
1626 LPNETCONNECTINFOSTRUCT lpNetConnectInfo)
1629 DWORD dwReturn = WN_SUCCESS;
1630 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
1631 DWORD dwBufferSize = 0;
1632 HANDLE hControlDevice = NULL;
1638 if ( NPIsFSDisabled())
1641 #ifdef AFS_DEBUG_TRACE
1642 AFSDbgPrint( L"NPGetConnectionPerformance AFSRDFS is disabled, returning WN_BAD_NETNAME\n");
1645 return WN_NO_NETWORK;
1648 AFSDbgPrint( L"NPGetConnectionPerformance Entry for remote connection %S\n",
1651 dwBufferSize = 0x1000;
1653 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
1655 if( pConnectCB == NULL)
1657 try_return( dwReturn = WN_OUT_OF_MEMORY);
1660 pConnectCB->RemoteNameLength = wcslen( lpRemoteName) * sizeof( WCHAR);
1662 StringCbCopy( pConnectCB->RemoteName,
1663 dwBufferSize - sizeof(AFSNetworkProviderConnectionCB),
1666 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
1668 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
1670 hControlDevice = OpenRedirector();
1672 if( hControlDevice == NULL)
1674 AFSDbgPrint( L"NPGetConnectionPerformance OpenRedirector failure, returning WN_NET_ERROR\n");
1676 try_return( dwReturn = WN_NET_ERROR);
1679 dwError = DeviceIoControl( hControlDevice,
1680 IOCTL_AFS_GET_CONNECTION_INFORMATION,
1690 #ifdef AFS_DEBUG_TRACE
1691 DWORD gle = GetLastError();
1693 AFSDbgPrint( L"NPGetConnectionPerformance Failed to get connection info from file system for remote %S gle 0x%x\n",
1697 try_return( dwReturn = WN_NOT_CONNECTED);
1700 lpNetConnectInfo->dwFlags = WNCON_DYNAMIC;
1702 lpNetConnectInfo->dwSpeed = 500;
1704 lpNetConnectInfo->dwDelay = 0;
1706 lpNetConnectInfo->dwOptDataSize = 0x1000;
1708 AFSDbgPrint( L"NPGetConnectionPerformance Successfully returned information for remote connection %S\n",
1713 if ( hControlDevice != NULL)
1715 CloseHandle( hControlDevice);
1718 if( pConnectCB != NULL)
1720 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1728 GetUsageString( DWORD dwUsage)
1730 static WCHAR Buffer[128] = L"";
1732 // RESOURCEUSAGE_CONNECTABLE 0x00000001
1733 // RESOURCEUSAGE_CONTAINER 0x00000002
1734 // RESOURCEUSAGE_NOLOCALDEVICE 0x00000004
1735 // RESOURCEUSAGE_SIBLING 0x00000008
1736 // RESOURCEUSAGE_ATTACHED 0x00000010
1737 // RESOURCEUSAGE_ALL (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED)
1738 // RESOURCEUSAGE_RESERVED 0x80000000
1743 if ( dwUsage == RESOURCEUSAGE_ALL )
1753 if ( dwUsage & RESOURCEUSAGE_CONNECTABLE )
1755 StringCbCat( Buffer, sizeof(Buffer), L"CONNECTABLE|");
1758 if ( dwUsage & RESOURCEUSAGE_CONTAINER )
1760 StringCbCat( Buffer, sizeof(Buffer), L"CONTAINER|");
1763 if ( dwUsage & RESOURCEUSAGE_NOLOCALDEVICE )
1765 StringCbCat( Buffer, sizeof(Buffer), L"NOLOCALDEVICE|");
1768 if ( dwUsage & RESOURCEUSAGE_SIBLING )
1770 StringCbCat( Buffer, sizeof(Buffer), L"SIBLING|");
1773 if ( dwUsage & RESOURCEUSAGE_ATTACHED )
1775 StringCbCat( Buffer, sizeof(Buffer), L"ATTACHED|");
1778 if ( dwUsage & RESOURCEUSAGE_RESERVED )
1780 StringCbCat( Buffer, sizeof(Buffer), L"RESERVED|");
1783 if ( dwUsage & ~(RESOURCEUSAGE_ALL|RESOURCEUSAGE_NOLOCALDEVICE|RESOURCEUSAGE_SIBLING|RESOURCEUSAGE_RESERVED) )
1785 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
1788 Buffer[lstrlen(Buffer)-1] = L'\0';
1794 GetTypeString( DWORD dwType)
1796 static WCHAR Buffer[128] = L"";
1799 // RESOURCETYPE_ANY 0x00000000
1800 // RESOURCETYPE_DISK 0x00000001
1801 // RESOURCETYPE_PRINT 0x00000002
1802 // RESOURCETYPE_RESERVED 0x00000008
1803 // RESOURCETYPE_UNKNOWN 0xFFFFFFFF
1808 if ( dwType == RESOURCETYPE_ANY )
1813 if ( dwType == RESOURCETYPE_UNKNOWN )
1818 if ( dwType & RESOURCETYPE_DISK )
1820 StringCbCat( Buffer, sizeof(Buffer), L"DISK|");
1823 if ( dwType & RESOURCETYPE_PRINT )
1825 StringCbCat( Buffer, sizeof(Buffer), L"PRINT|");
1828 if ( dwType & RESOURCETYPE_RESERVED )
1830 StringCbCat( Buffer, sizeof(Buffer), L"RESERVED|");
1833 if ( dwType & ~(RESOURCETYPE_DISK|RESOURCETYPE_PRINT|RESOURCETYPE_RESERVED) )
1835 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
1838 Buffer[lstrlen(Buffer)-1] = L'\0';
1844 GetScopeString( DWORD dwScope)
1846 static WCHAR Buffer[128] = L"";
1849 // RESOURCE_CONNECTED 0x00000001
1850 // RESOURCE_GLOBALNET 0x00000002
1851 // RESOURCE_REMEMBERED 0x00000003
1852 // RESOURCE_RECENT 0x00000004
1853 // RESOURCE_CONTEXT 0x00000005
1858 if ( dwScope == RESOURCE_CONNECTED )
1860 StringCbCat( Buffer, sizeof(Buffer), L"CONNECTED|");
1863 if ( dwScope == RESOURCE_GLOBALNET )
1865 StringCbCat( Buffer, sizeof(Buffer), L"GLOBALNET|");
1868 if ( dwScope == RESOURCE_REMEMBERED )
1870 StringCbCat( Buffer, sizeof(Buffer), L"REMEMBERED|");
1873 if ( dwScope == RESOURCE_RECENT )
1875 StringCbCat( Buffer, sizeof(Buffer), L"RECENT|");
1878 if ( dwScope == RESOURCE_CONTEXT )
1880 StringCbCat( Buffer, sizeof(Buffer), L"CONTEXT|");
1883 if ( dwScope & ~(RESOURCE_CONNECTED|RESOURCE_GLOBALNET|RESOURCE_REMEMBERED|RESOURCE_RECENT|RESOURCE_CONTEXT) )
1885 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
1888 Buffer[lstrlen(Buffer)-1] = L'\0';
1894 GetDisplayString( DWORD dwDisplay)
1897 // RESOURCEDISPLAYTYPE_GENERIC 0x00000000
1898 // RESOURCEDISPLAYTYPE_DOMAIN 0x00000001
1899 // RESOURCEDISPLAYTYPE_SERVER 0x00000002
1900 // RESOURCEDISPLAYTYPE_SHARE 0x00000003
1901 // RESOURCEDISPLAYTYPE_FILE 0x00000004
1902 // RESOURCEDISPLAYTYPE_GROUP 0x00000005
1903 // RESOURCEDISPLAYTYPE_NETWORK 0x00000006
1904 // RESOURCEDISPLAYTYPE_ROOT 0x00000007
1905 // RESOURCEDISPLAYTYPE_SHAREADMIN 0x00000008
1906 // RESOURCEDISPLAYTYPE_DIRECTORY 0x00000009
1907 // RESOURCEDISPLAYTYPE_TREE 0x0000000A
1908 // RESOURCEDISPLAYTYPE_NDSCONTAINER 0x0000000B
1911 switch ( dwDisplay ) {
1912 case RESOURCEDISPLAYTYPE_GENERIC:
1914 case RESOURCEDISPLAYTYPE_DOMAIN:
1916 case RESOURCEDISPLAYTYPE_SERVER:
1918 case RESOURCEDISPLAYTYPE_SHARE:
1920 case RESOURCEDISPLAYTYPE_FILE:
1922 case RESOURCEDISPLAYTYPE_GROUP:
1924 case RESOURCEDISPLAYTYPE_NETWORK:
1926 case RESOURCEDISPLAYTYPE_ROOT:
1928 case RESOURCEDISPLAYTYPE_SHAREADMIN:
1929 return L"SHAREADMIN";
1930 case RESOURCEDISPLAYTYPE_DIRECTORY:
1931 return L"DIRECTORY";
1932 case RESOURCEDISPLAYTYPE_TREE:
1934 case RESOURCEDISPLAYTYPE_NDSCONTAINER:
1935 return L"NDSCONTAINER";
1943 NPOpenEnum( DWORD dwScope,
1946 LPNETRESOURCE lpNetResource,
1950 DWORD dwStatus = WN_SUCCESS;
1951 AFSEnumerationCB *pEnumCB = NULL;
1953 #ifdef AFS_DEBUG_TRACE
1954 if ( lpNetResource == NULL)
1956 AFSDbgPrint( L"NPOpenEnum Scope %s Type %s Usage %s NetResource: (Null)\n",
1957 GetScopeString(dwScope), GetTypeString(dwType), GetUsageString(dwUsage));
1961 AFSDbgPrint( L"NPOpenEnum Scope %s Type %s Usage %s NetResource (0x%p): Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
1962 GetScopeString(dwScope),
1963 GetTypeString(dwType),
1964 GetUsageString(dwUsage),
1966 GetScopeString(lpNetResource->dwScope),
1967 GetTypeString(lpNetResource->dwType),
1968 GetDisplayString(lpNetResource->dwDisplayType),
1969 GetUsageString(lpNetResource->dwUsage),
1970 lpNetResource->lpLocalName,
1971 lpNetResource->lpRemoteName,
1972 lpNetResource->lpComment);
1978 dwUsage = RESOURCEUSAGE_ALL;
1982 if ( dwType == 0 || dwType == RESOURCEUSAGE_ATTACHED)
1984 dwType |= RESOURCETYPE_DISK | RESOURCETYPE_PRINT;
1988 *lphEnum = HeapAlloc( GetProcessHeap( ), HEAP_ZERO_MEMORY, sizeof( AFSEnumerationCB));
1990 if( *lphEnum == NULL)
1993 return WN_OUT_OF_MEMORY;
1996 pEnumCB = (AFSEnumerationCB *)*lphEnum;
1998 pEnumCB->CurrentIndex = 0;
2000 pEnumCB->Type = dwType;
2004 case RESOURCE_CONNECTED:
2007 pEnumCB->Scope = RESOURCE_CONNECTED;
2012 case RESOURCE_CONTEXT:
2015 pEnumCB->Scope = RESOURCE_CONTEXT;
2020 case RESOURCE_GLOBALNET:
2023 if( lpNetResource != NULL &&
2024 lpNetResource->lpRemoteName != NULL)
2027 pEnumCB->RemoteName = (WCHAR *)HeapAlloc( GetProcessHeap( ), HEAP_ZERO_MEMORY, 0x1000);
2029 if( pEnumCB->RemoteName == NULL)
2032 dwStatus = WN_OUT_OF_MEMORY;
2033 HeapFree( GetProcessHeap( ), 0, (PVOID) *lphEnum );
2039 StringCbCopy( pEnumCB->RemoteName,
2041 lpNetResource->lpRemoteName);
2046 pEnumCB->Scope = RESOURCE_GLOBALNET;
2053 #ifdef AFS_DEBUG_TRACE
2054 AFSDbgPrint( L"NPOpenEnum Processing (Scope %s 0x%x) Type %s Usage %s, returning WN_NOT_SUPPORTED\n",
2055 GetScopeString(dwScope), dwScope, GetTypeString(dwType), GetUsageString(dwUsage));
2058 dwStatus = WN_NOT_SUPPORTED;
2059 HeapFree( GetProcessHeap( ), 0, (PVOID) *lphEnum );
2071 NPEnumResource( HANDLE hEnum,
2074 LPDWORD lpBufferSize)
2077 DWORD dwStatus = WN_NO_MORE_ENTRIES; //WN_SUCCESS;
2079 ULONG EntriesCopied;
2080 ULONG EntriesRequested;
2082 LPNETRESOURCE pNetResource;
2084 ULONG SpaceAvailable;
2086 AFSNetworkProviderConnectionCB *pConnectionCB = NULL;
2087 void *pConnectionCBBase = NULL;
2089 UNICODE_STRING uniRemoteName;
2090 HANDLE hControlDevice = NULL;
2091 AFSEnumerationCB *pEnumCB = (AFSEnumerationCB *)hEnum;
2096 if ( lpBufferSize == NULL)
2098 #ifdef AFS_DEBUG_TRACE
2099 AFSDbgPrint( L"NPEnumResource No output size, returning WN_BAD_VALUE\n");
2101 try_return( dwStatus = WN_BAD_VALUE);
2104 ReadProviderNameString();
2106 pNetResource = (LPNETRESOURCE) lpBuffer;
2107 SpaceAvailable = *lpBufferSize;
2108 EntriesRequested = *lpcCount;
2109 *lpcCount = EntriesCopied = 0;
2110 StringZone = (PWCHAR) ((char *)lpBuffer + *lpBufferSize);
2112 #ifdef AFS_DEBUG_TRACE
2113 AFSDbgPrint( L"NPEnumResource Processing Remote name %s Scope %s Type %s Usage %s Index %d SpaceAvailable 0x%lX RequestedEntries %lu\n",
2114 pEnumCB->RemoteName ? pEnumCB->RemoteName : L"(Null)",
2115 GetScopeString(pEnumCB->Scope),
2116 GetTypeString(pEnumCB->Type),
2117 GetUsageString(pEnumCB->Type),
2118 pEnumCB->CurrentIndex,
2123 if ( NPIsFSDisabled())
2126 #ifdef AFS_DEBUG_TRACE
2127 AFSDbgPrint( L"NPEnumResource AFSRDFS is disabled, returning WN_NO_MORE_ENTRIES\n");
2130 try_return( dwStatus = WN_NO_MORE_ENTRIES);
2133 pConnectionCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 0x1000);
2135 if( pConnectionCB == NULL)
2138 #ifdef AFS_DEBUG_TRACE
2139 AFSDbgPrint( L"NPEnumResource Out of Memory\n");
2142 try_return( dwStatus = WN_OUT_OF_MEMORY);
2145 pConnectionCBBase = (void *)pConnectionCB;
2147 hControlDevice = OpenRedirector();
2149 if( hControlDevice == NULL)
2152 #ifdef AFS_DEBUG_TRACE
2153 AFSDbgPrint( L"NPEnumResource OpenRedirector failure, returning WN_NET_ERROR\n");
2156 try_return( dwStatus = WN_NET_ERROR);
2160 // Handle the special cases here
2161 // 0. Provider Network Root
2166 if ( pEnumCB->Scope == RESOURCE_GLOBALNET)
2169 ReadServerNameString();
2171 if ( pEnumCB->CurrentIndex == 0 &&
2172 pEnumCB->RemoteName == NULL)
2175 // Determine the space needed for this entry...
2177 SpaceNeeded = 2 * ( cbProviderNameLength + sizeof( WCHAR));
2179 uniRemoteName.Length = (USHORT)cbProviderNameLength;
2180 uniRemoteName.MaximumLength = uniRemoteName.Length;
2181 uniRemoteName.Buffer = wszProviderName;
2183 if( SpaceNeeded + sizeof( NETRESOURCE) > SpaceAvailable)
2186 *lpBufferSize = SpaceNeeded + sizeof( NETRESOURCE);
2188 #ifdef AFS_DEBUG_TRACE
2189 AFSDbgPrint( L"NPEnumResource Request MORE_DATA for entry %s Len %d\n",
2193 try_return( dwStatus = WN_MORE_DATA);
2196 #ifdef AFS_DEBUG_TRACE
2197 AFSDbgPrint( L"NPEnumResource Processing Entry %wZ\n",
2201 SpaceAvailable -= (SpaceNeeded + sizeof( NETRESOURCE));
2203 pNetResource->dwScope = RESOURCE_GLOBALNET;
2204 pNetResource->dwType = RESOURCETYPE_ANY;
2205 pNetResource->dwDisplayType = RESOURCEDISPLAYTYPE_NETWORK;
2206 pNetResource->dwUsage = RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED;
2208 // setup string area at opposite end of buffer
2209 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2211 pNetResource->lpLocalName = NULL;
2214 pNetResource->lpRemoteName = StringZone;
2216 StringCbCopy( StringZone,
2217 cbProviderNameLength + sizeof( WCHAR),
2220 StringZone += cbProviderNameLength / sizeof(WCHAR) + 1;
2222 pNetResource->lpComment = NULL;
2224 // copy provider name
2225 pNetResource->lpProvider = StringZone;
2226 StringCbCopy( StringZone,
2227 cbProviderNameLength + sizeof( WCHAR),
2230 StringZone += cbProviderNameLength / sizeof( WCHAR) + 1;
2232 #ifdef AFS_DEBUG_TRACE
2233 AFSDbgPrint( L"NPEnumResource Entry (0x%p) Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
2235 GetScopeString(pNetResource->dwScope),
2236 GetTypeString(pNetResource->dwType),
2237 GetDisplayString(pNetResource->dwDisplayType),
2238 GetUsageString(pNetResource->dwUsage),
2239 pNetResource->lpLocalName,
2240 pNetResource->lpRemoteName,
2241 pNetResource->lpComment);
2244 // setup the new end of buffer
2245 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2251 // do not change the index since we did not query the redirector
2252 pEnumCB->CurrentIndex = 0;
2254 // remember that we returned the provider name
2255 pEnumCB->RemoteName = (WCHAR *)HeapAlloc( GetProcessHeap( ), HEAP_ZERO_MEMORY, 0x1000);
2257 if( pEnumCB->RemoteName == NULL)
2260 try_return( dwStatus = WN_OUT_OF_MEMORY);
2265 StringCbCopy( pEnumCB->RemoteName,
2271 if ( pEnumCB->CurrentIndex == 0 &&
2272 lstrlen( pEnumCB->RemoteName) == cbProviderNameLength / sizeof( WCHAR) &&
2273 _wcsnicmp( pEnumCB->RemoteName, wszProviderName, cbProviderNameLength / sizeof( WCHAR)) == 0 &&
2274 EntriesCopied < EntriesRequested)
2278 // After the network provider entry comes the server entry
2281 // Determine the space needed for this entry...
2283 SpaceNeeded = cbProviderNameLength + cbServerNameUNCLength + cbServerCommentLength + 3 * sizeof( WCHAR);
2285 uniRemoteName.Length = (USHORT)cbServerNameUNCLength;
2286 uniRemoteName.MaximumLength = uniRemoteName.Length;
2287 uniRemoteName.Buffer = wszServerNameUNC;
2289 if( SpaceNeeded + sizeof( NETRESOURCE) > SpaceAvailable)
2292 *lpBufferSize = SpaceNeeded + sizeof( NETRESOURCE);
2294 #ifdef AFS_DEBUG_TRACE
2295 AFSDbgPrint( L"NPEnumResource Request MORE_DATA for entry %s Len %d\n",
2299 try_return( dwStatus = WN_MORE_DATA);
2302 #ifdef AFS_DEBUG_TRACE
2303 AFSDbgPrint( L"NPEnumResource Processing Entry %wZ\n",
2307 SpaceAvailable -= (SpaceNeeded + sizeof( NETRESOURCE));
2309 pNetResource->dwScope = 0;
2310 pNetResource->dwType = RESOURCETYPE_ANY;
2311 pNetResource->dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
2312 pNetResource->dwUsage = RESOURCEUSAGE_CONTAINER;
2314 // setup string area at opposite end of buffer
2315 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2317 pNetResource->lpLocalName = NULL;
2320 pNetResource->lpRemoteName = StringZone;
2322 StringCbCopy( StringZone,
2323 cbServerNameUNCLength + sizeof( WCHAR),
2326 StringZone += cbServerNameUNCLength / sizeof(WCHAR) + 1;
2329 pNetResource->lpComment = StringZone;
2331 StringCbCopy( StringZone,
2332 cbServerCommentLength + sizeof( WCHAR),
2335 StringZone += cbServerCommentLength / sizeof( WCHAR) + 1;
2337 // copy provider name
2338 pNetResource->lpProvider = StringZone;
2339 StringCbCopy( StringZone,
2340 cbProviderNameLength + sizeof( WCHAR),
2343 StringZone += cbProviderNameLength / sizeof( WCHAR) + 1;
2345 #ifdef AFS_DEBUG_TRACE
2346 AFSDbgPrint( L"NPEnumResource Entry (0x%p) Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
2348 GetScopeString(pNetResource->dwScope),
2349 GetTypeString(pNetResource->dwType),
2350 GetDisplayString(pNetResource->dwDisplayType),
2351 GetUsageString(pNetResource->dwUsage),
2352 pNetResource->lpLocalName,
2353 pNetResource->lpRemoteName,
2354 pNetResource->lpComment);
2357 // setup the new end of buffer
2358 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2364 // do not update the index because we did not query the redirector
2365 pEnumCB->CurrentIndex = 0;
2367 // remember that we returned the server
2368 StringCbCopy( pEnumCB->RemoteName,
2376 // Setup what we are going to ask for
2379 pConnectionCB->Scope = pEnumCB->Scope;
2381 pConnectionCB->Type = pEnumCB->Type;
2383 pConnectionCB->CurrentIndex = pEnumCB->CurrentIndex;
2385 pConnectionCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
2388 // If this is a RESOURCE_GLOBALNET enumeration then pass down the remote name if
2392 pConnectionCB->RemoteNameLength = 0;
2394 if( pEnumCB->Scope == RESOURCE_GLOBALNET &&
2395 pEnumCB->RemoteName != NULL)
2398 pConnectionCB->RemoteNameLength = wcslen( pEnumCB->RemoteName) * sizeof( WCHAR);
2400 StringCbCopy( pConnectionCB->RemoteName,
2401 (0x1000 - sizeof(AFSNetworkProviderConnectionCB)) + sizeof(WCHAR),
2402 pEnumCB->RemoteName);
2405 pConnectionCB->AuthenticationId = AFSRetrieveAuthId();
2407 #ifdef AFS_DEBUG_TRACE
2408 AFSDbgPrint( L"NPEnumResource Retrieved authentication id %08lX-%08lX\n",
2409 pConnectionCB->AuthenticationId.HighPart,
2410 pConnectionCB->AuthenticationId.LowPart);
2413 dwError = DeviceIoControl( hControlDevice,
2414 IOCTL_AFS_LIST_CONNECTIONS,
2424 #ifdef AFS_DEBUG_TRACE
2425 DWORD gle = GetLastError();
2427 AFSDbgPrint( L"NPEnumResource Failed to list connections from file system - gle 0x%x\n",
2430 try_return( dwStatus = WN_NOT_CONNECTED);
2433 if( dwCopyBytes == 0)
2436 #ifdef AFS_DEBUG_TRACE
2437 AFSDbgPrint( L"NPEnumResource No More Entries\n");
2439 try_return( dwStatus = WN_NO_MORE_ENTRIES);
2442 dwIndex = pEnumCB->CurrentIndex;
2444 while( EntriesCopied < EntriesRequested)
2447 uniRemoteName.Length = (USHORT)pConnectionCB->RemoteNameLength;
2448 uniRemoteName.MaximumLength = uniRemoteName.Length;
2449 uniRemoteName.Buffer = pConnectionCB->RemoteName;
2451 // Determine the space needed for this entry...
2455 if( pConnectionCB->LocalName != 0)
2458 SpaceNeeded += 3 * sizeof(WCHAR); // local name
2461 SpaceNeeded += pConnectionCB->RemoteNameLength + sizeof( WCHAR); // remote name
2463 if( pConnectionCB->CommentLength > 0)
2466 SpaceNeeded += pConnectionCB->CommentLength + sizeof( WCHAR); // comment
2469 SpaceNeeded += cbProviderNameLength + sizeof( WCHAR); // provider name
2471 if( SpaceNeeded + sizeof( NETRESOURCE) > SpaceAvailable)
2474 if (EntriesCopied == 0) {
2476 dwStatus = WN_MORE_DATA;
2478 *lpBufferSize = SpaceNeeded + sizeof( NETRESOURCE);
2480 #ifdef AFS_DEBUG_TRACE
2481 AFSDbgPrint( L"NPEnumResource Request MORE_DATA for entry %s Len %d\n",
2488 #ifdef AFS_DEBUG_TRACE
2489 AFSDbgPrint( L"NPEnumResource Return SUCCESS but more entries Index %d\n",
2493 dwStatus = WN_SUCCESS;
2499 SpaceAvailable -= (SpaceNeeded + sizeof( NETRESOURCE));
2501 pNetResource->dwScope = pConnectionCB->Scope;
2502 pNetResource->dwType = pConnectionCB->Type;
2504 pNetResource->dwDisplayType = pConnectionCB->DisplayType;
2506 if ( pNetResource->dwType == RESOURCETYPE_ANY &&
2507 pNetResource->dwDisplayType == RESOURCEDISPLAYTYPE_SHARE)
2510 pNetResource->dwType = RESOURCETYPE_DISK;
2512 pNetResource->dwUsage = pConnectionCB->Usage;
2514 // setup string area at opposite end of buffer
2515 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2518 if( pConnectionCB->LocalName != 0)
2521 pNetResource->lpLocalName = StringZone;
2522 *StringZone++ = towupper(pConnectionCB->LocalName);
2523 *StringZone++ = L':';
2524 *StringZone++ = L'\0';
2529 pNetResource->lpLocalName = NULL;
2532 #ifdef AFS_DEBUG_TRACE
2533 AFSDbgPrint( L"NPEnumResource Processing Entry %wZ\n",
2538 pNetResource->lpRemoteName = StringZone;
2540 CopyMemory( StringZone,
2541 pConnectionCB->RemoteName,
2542 pConnectionCB->RemoteNameLength);
2544 StringZone += (pConnectionCB->RemoteNameLength / sizeof(WCHAR));
2546 *StringZone++ = L'\0';
2549 if( pConnectionCB->CommentLength > 0)
2552 pNetResource->lpComment = StringZone;
2554 CopyMemory( StringZone,
2555 (void *)((char *)pConnectionCB + pConnectionCB->CommentOffset),
2556 pConnectionCB->CommentLength);
2558 StringZone += (pConnectionCB->CommentLength / sizeof(WCHAR));
2560 *StringZone++ = L'\0';
2565 pNetResource->lpComment = NULL;
2568 // copy provider name
2569 pNetResource->lpProvider = StringZone;
2570 StringCbCopy( StringZone,
2571 cbProviderNameLength + sizeof( WCHAR),
2574 StringZone += (cbProviderNameLength / sizeof( WCHAR) + 1);
2576 #ifdef AFS_DEBUG_TRACE
2577 AFSDbgPrint( L"NPEnumResource Entry (0x%p) Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
2579 GetScopeString(pNetResource->dwScope),
2580 GetTypeString(pNetResource->dwType),
2581 GetDisplayString(pNetResource->dwDisplayType),
2582 GetUsageString(pNetResource->dwUsage),
2583 pNetResource->lpLocalName,
2584 pNetResource->lpRemoteName,
2585 pNetResource->lpComment);
2588 // setup the new end of buffer
2589 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2597 dwCopyBytes -= FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
2598 pConnectionCB->RemoteNameLength +
2599 pConnectionCB->CommentLength;
2601 if( dwCopyBytes == 0)
2604 dwStatus = WN_SUCCESS;
2609 pConnectionCB = (AFSNetworkProviderConnectionCB *)((char *)pConnectionCB +
2610 FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
2611 pConnectionCB->RemoteNameLength +
2612 pConnectionCB->CommentLength);
2615 *lpcCount = EntriesCopied;
2617 // update entry index
2618 pEnumCB->CurrentIndex = dwIndex;
2620 #ifdef AFS_DEBUG_TRACE
2621 AFSDbgPrint( L"NPEnumResource Completed Count %d Index %d\n",
2628 if ( hControlDevice != NULL)
2631 CloseHandle( hControlDevice);
2634 if( pConnectionCBBase != NULL)
2637 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectionCBBase);
2646 Routine Description:
2648 This routine closes the handle for enumeration of resources.
2652 hEnum - the enumeration handle
2656 WN_SUCCESS if successful, otherwise the appropriate error
2660 The sample only supports the notion of enumerating connected shares
2665 NPCloseEnum( HANDLE hEnum )
2668 AFSEnumerationCB *pEnumCB = (AFSEnumerationCB *)hEnum;
2670 #ifdef AFS_DEBUG_TRACE
2671 AFSDbgPrint( L"NPCloseEnum\n");
2674 if( pEnumCB->RemoteName != NULL)
2677 HeapFree( GetProcessHeap( ), 0, (PVOID) pEnumCB->RemoteName);
2680 HeapFree( GetProcessHeap( ), 0, (PVOID) hEnum );
2686 NPGetResourceParent( LPNETRESOURCE lpNetResource,
2688 LPDWORD lpBufferSize )
2691 DWORD dwStatus = WN_ACCESS_DENIED;
2692 WCHAR *pwchRemoteName = NULL, *pwchSearch = NULL, *pwchSystem = NULL;
2693 LPNETRESOURCE lpOutResource = (LPNETRESOURCE) lpBuffer;
2695 if ( lpNetResource == NULL)
2697 #ifdef AFS_DEBUG_TRACE
2698 AFSDbgPrint( L"NPGetResourceParent NULL NETRESOURCE\n");
2700 return WN_MORE_DATA;
2703 if( lpNetResource->lpRemoteName == NULL)
2705 #ifdef AFS_DEBUG_TRACE
2706 AFSDbgPrint( L"NPGetResourceParent NULL NETRESOURCE\n");
2708 return WN_BAD_NETNAME;
2711 if ( lpNetResource->dwType != 0 &&
2712 lpNetResource->dwType != RESOURCETYPE_DISK)
2714 #ifdef AFS_DEBUG_TRACE
2715 AFSDbgPrint( L"NPGetResourceParent Bad dwType\n");
2717 return WN_BAD_VALUE;
2720 if ( lpBufferSize == NULL )
2723 #ifdef AFS_DEBUG_TRACE
2724 AFSDbgPrint( L"NPGetResourceParent Null lpBufferSize\n");
2726 return WN_BAD_VALUE;
2729 #ifdef AFS_DEBUG_TRACE
2730 AFSDbgPrint( L"NPGetResourceParent For remote name %s\n",
2731 lpNetResource->lpRemoteName);
2734 pwchRemoteName = lpNetResource->lpRemoteName;
2736 pwchSearch = pwchRemoteName + (wcslen( pwchRemoteName) - 1);
2738 while( pwchSearch != pwchRemoteName)
2741 if( *pwchSearch == L'\\')
2744 *pwchSearch = L'\0';
2752 if( pwchSearch != pwchRemoteName)
2755 #ifdef AFS_DEBUG_TRACE
2756 AFSDbgPrint( L"NPGetResourceParent Processing parent %s\n",
2757 lpNetResource->lpRemoteName);
2760 dwStatus = NPGetResourceInformation( lpNetResource,
2767 if ( lpOutResource == NULL ||
2768 *lpBufferSize < sizeof( NETRESOURCE) )
2770 *lpBufferSize = sizeof( NETRESOURCE);
2772 return WN_MORE_DATA;
2775 memset( lpOutResource, 0, sizeof( NETRESOURCE));
2785 NPGetResourceInformation( LPNETRESOURCE lpNetResource,
2787 LPDWORD lpBufferSize,
2788 LPWSTR *lplpSystem )
2791 DWORD dwStatus = WN_NOT_CONNECTED;
2792 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
2794 DWORD dwBufferSize = 0;
2795 HANDLE hControlDevice = NULL;
2796 NETRESOURCE *pNetResource = (NETRESOURCE *)lpBuffer;
2797 PWCHAR pStringZone = NULL;
2798 UNICODE_STRING uniRemoteName;
2799 DWORD ulRequiredLen = 0;
2810 ReadProviderNameString();
2812 if ( NPIsFSDisabled())
2815 #ifdef AFS_DEBUG_TRACE
2816 AFSDbgPrint( L"NPGetResourceInformation AFSRDFS is disabled, returning WN_BAD_NETNAME\n");
2819 try_return( dwStatus = WN_BAD_NETNAME);
2822 if ( lpNetResource == NULL ||
2823 lpBufferSize == NULL )
2826 #ifdef AFS_DEBUG_TRACE
2827 AFSDbgPrint( L"NPGetResourceInformaton Null lpNetResource or lpBufferSize\n");
2829 return WN_BAD_VALUE;
2832 if( lpNetResource->lpRemoteName == NULL)
2834 #ifdef AFS_DEBUG_TRACE
2835 AFSDbgPrint( L"NPGetResourceInformation No resource name\n");
2838 try_return( dwStatus = WN_NOT_CONNECTED);
2841 dwPassedSize = *lpBufferSize;
2843 dwBufferSize = 0x1000;
2845 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
2847 if( pConnectCB == NULL)
2850 try_return( dwStatus = WN_OUT_OF_MEMORY);
2853 pConnectCB->RemoteNameLength = wcslen( lpNetResource->lpRemoteName) * sizeof( WCHAR);
2855 StringCbCopy( pConnectCB->RemoteName,
2856 dwBufferSize - sizeof(AFSNetworkProviderConnectionCB),
2857 lpNetResource->lpRemoteName);
2859 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
2861 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
2863 #ifdef AFS_DEBUG_TRACE
2864 AFSDbgPrint( L"NPGetResourceInformation Retrieved authentication id %08lX-%08lX\n",
2865 pConnectCB->AuthenticationId.HighPart,
2866 pConnectCB->AuthenticationId.LowPart);
2869 hControlDevice = OpenRedirector();
2871 if( hControlDevice == NULL)
2874 #ifdef AFS_DEBUG_TRACE
2875 AFSDbgPrint( L"NPGetResourceInformation OpenRedirector failure, returning WN_NET_ERROR\n");
2878 try_return( dwStatus = WN_NET_ERROR);
2881 dwError = DeviceIoControl( hControlDevice,
2882 IOCTL_AFS_GET_CONNECTION_INFORMATION,
2892 #ifdef AFS_DEBUG_TRACE
2893 DWORD gle = GetLastError();
2895 AFSDbgPrint( L"NPGetResourceInformation Failed to get connection info from file system for local %s gle 0x%x\n",
2896 lpNetResource->lpRemoteName, gle);
2898 try_return( dwStatus = WN_BAD_NETNAME);
2901 uniRemoteName.Length = (USHORT)pConnectCB->RemoteNameLength;
2902 uniRemoteName.MaximumLength = uniRemoteName.Length;
2903 uniRemoteName.Buffer = pConnectCB->RemoteName;
2905 #ifdef AFS_DEBUG_TRACE
2906 AFSDbgPrint( L"NPGetResourceInformation For remote name %wZ Scope %08lX Type %08lX Usage %08lX\n",
2913 // Determine the space needed for this entry...
2915 ulRequiredLen = sizeof( NETRESOURCE);
2917 ulRequiredLen += pConnectCB->RemoteNameLength + sizeof( WCHAR);
2919 ulRequiredLen += pConnectCB->CommentLength + sizeof( WCHAR);
2921 ulRequiredLen += cbProviderNameLength + sizeof( WCHAR);
2923 ulRequiredLen += pConnectCB->RemainingPathLength + sizeof( WCHAR);
2925 if( pNetResource == NULL ||
2926 ulRequiredLen > dwPassedSize)
2929 *lpBufferSize = ulRequiredLen;
2931 try_return( dwStatus = WN_MORE_DATA);
2934 pStringZone = (PWCHAR) ((char *)lpBuffer + sizeof( NETRESOURCE));
2936 pNetResource->dwScope = 0 /* pConnectCB->Scope*/;
2937 pNetResource->dwType = 0 /* pConnectCB->Type */;
2939 pNetResource->dwDisplayType = pConnectCB->DisplayType;
2941 pNetResource->dwUsage = pConnectCB->Usage;
2943 pNetResource->lpLocalName = NULL;
2946 pNetResource->lpRemoteName = pStringZone;
2948 CopyMemory( pStringZone,
2949 pConnectCB->RemoteName,
2950 pConnectCB->RemoteNameLength);
2952 pStringZone += (pConnectCB->RemoteNameLength / sizeof(WCHAR));
2954 *pStringZone++ = L'\0';
2957 pNetResource->lpComment = pStringZone;
2959 CopyMemory( pStringZone,
2960 (void *)((char *)pConnectCB + pConnectCB->CommentOffset),
2961 pConnectCB->CommentLength);
2963 pStringZone += (pConnectCB->CommentLength / sizeof(WCHAR));
2965 *pStringZone++ = L'\0';
2967 // copy remaining path
2968 if (pConnectCB->RemainingPathLength > 0)
2970 *lplpSystem = pStringZone;
2972 CopyMemory( pStringZone,
2973 (void *)((char *)pConnectCB + pConnectCB->RemainingPathOffset),
2974 pConnectCB->RemainingPathLength);
2976 pStringZone += (pConnectCB->RemainingPathLength / sizeof(WCHAR));
2978 *pStringZone++ = L'\0';
2980 #ifdef AFS_DEBUG_TRACE
2981 AFSDbgPrint( L"NPGetResourceInformation For remote name %s returning remaining path %s\n",
2982 pNetResource->lpRemoteName,
2987 // copy provider name
2988 pNetResource->lpProvider = pStringZone;
2990 StringCbCopy( pStringZone,
2991 cbProviderNameLength + sizeof( WCHAR),
2994 pStringZone += (cbProviderNameLength / sizeof( WCHAR) + 1);
2996 *lpBufferSize = ulRequiredLen;
2998 dwStatus = WN_SUCCESS;
3002 if ( hControlDevice != NULL)
3005 CloseHandle( hControlDevice);
3008 if( pConnectCB != NULL)
3011 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
3019 SeparateRemainingPath( WCHAR * lpConnectionName, WCHAR **lppRemainingPath)
3026 // at this point the lpConnectionName contains the full name. We need to
3027 // truncate it to \\server\share and move the remaining path back one position.
3030 for ( pwch = lpConnectionName, dwCount = 0; *pwch; pwch++)
3032 if ( *pwch == L'\\')
3046 // Found the remaining path that must be moved
3049 *lppRemainingPath = pwch + 1;
3056 for ( ; *pwch; pwch++);
3059 // and work backwards moving the string
3060 // and then make sure that there is at least
3061 // a path separator.
3066 for ( ;pwch > *lppRemainingPath; pwch--)
3068 *pwch = *(pwch - 1);
3076 NPGetUniversalName( LPCWSTR lpLocalPath,
3079 LPDWORD lpBufferSize )
3081 DWORD dwStatus = WN_NOT_CONNECTED;
3082 WCHAR wchLocalName[3];
3083 WCHAR wchSubstName[MAX_PATH + 1];
3084 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
3086 DWORD dwBufferSize = 0;
3087 DWORD dwPassedSize = *lpBufferSize;
3088 DWORD dwRemainingLength = *lpBufferSize;
3089 HANDLE hControlDevice = NULL;
3090 DWORD dwLocalPathLength = 0;
3091 DWORD dwRemainingPathLength = 0;
3097 #ifdef AFS_DEBUG_TRACE
3098 AFSDbgPrint( L"NPGetUniversalName local path %s level 0x%X\n",
3099 lpLocalPath ? lpLocalPath : L"(Null)",
3103 if ( NPIsFSDisabled())
3106 #ifdef AFS_DEBUG_TRACE
3107 AFSDbgPrint( L"NPGetUniversalName AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
3110 try_return( dwStatus = WN_NOT_CONNECTED);
3113 dwLocalPathLength = lstrlen( lpLocalPath);
3115 dwRemainingPathLength = dwLocalPathLength - 2; // no drive letter
3117 if( dwLocalPathLength == 0)
3120 #ifdef AFS_DEBUG_TRACE
3121 AFSDbgPrint( L"NPGetUniversalName AFSRDFS is disabled, returning WN_BAD_LOCALNAME\n");
3124 try_return( dwStatus = WN_BAD_LOCALNAME);
3127 if( lpBuffer == NULL ||
3128 lpBufferSize == NULL)
3130 #ifdef AFS_DEBUG_TRACE
3131 AFSDbgPrint( L"NPGetUniversalName No output buffer or size\n");
3133 try_return( dwStatus = WN_BAD_VALUE);
3136 memset(lpBuffer, 0, dwPassedSize);
3138 if ( !DriveSubstitution( lpLocalPath, wchSubstName, sizeof( wchSubstName)))
3140 wchLocalName[0] = towupper(lpLocalPath[0]);
3141 wchLocalName[1] = L':';
3142 wchLocalName[2] = L'\0';
3144 #ifdef AFS_DEBUG_TRACE
3145 AFSDbgPrint( L"NPGetUniversalName Requesting UNC for %s level 0x%X\n",
3153 ReadServerNameString();
3155 if ( wchSubstName[0] != L'\\' &&
3156 wchSubstName[1] == L':')
3159 wchLocalName[0] = towupper(wchSubstName[0]);
3160 wchLocalName[1] = L':';
3161 wchLocalName[2] = L'\0';
3163 #ifdef AFS_DEBUG_TRACE
3164 AFSDbgPrint( L"NPGetUniversalName Requesting UNC for drive substitution %s -> %s\n",
3169 else if ( _wcsnicmp( wchSubstName, wszServerNameUNC, cbServerNameUNCLength / sizeof( WCHAR)) == 0 &&
3170 ( wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == L'\\' ||
3171 wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == 0))
3175 #ifdef AFS_DEBUG_TRACE
3176 AFSDbgPrint( L"NPGetUniversalName drive substitution %s is AFS; Level 0x%x BufferSize 0x%x\n",
3182 dwBufferSize = (wcslen( wchSubstName) + 1) * sizeof( WCHAR);
3184 switch( dwInfoLevel)
3187 case UNIVERSAL_NAME_INFO_LEVEL:
3190 UNIVERSAL_NAME_INFO *pUniversalInfo = (UNIVERSAL_NAME_INFO *)lpBuffer;
3192 *lpBufferSize = sizeof( UNIVERSAL_NAME_INFO) + dwBufferSize;
3194 if( dwPassedSize <= sizeof( UNIVERSAL_NAME_INFO))
3197 #ifdef AFS_DEBUG_TRACE
3198 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO) WN_MORE_DATA\n");
3201 try_return( dwStatus = WN_MORE_DATA);
3204 dwRemainingLength -= sizeof( UNIVERSAL_NAME_INFO);
3206 pUniversalInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( UNIVERSAL_NAME_INFO));
3208 memcpy( pUniversalInfo->lpUniversalName,
3210 min( dwBufferSize, dwRemainingLength));
3212 dwRemainingLength -= min( dwBufferSize, dwRemainingLength);
3214 #ifdef AFS_DEBUG_TRACE
3215 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO_LEVEL) lpBuffer: %p Name: (%p) \"%s\"\n",
3217 pUniversalInfo->lpUniversalName,
3218 pUniversalInfo->lpUniversalName);
3221 if ( dwPassedSize < *lpBufferSize)
3224 try_return( dwStatus = WN_MORE_DATA);
3227 try_return( dwStatus = WN_SUCCESS);
3230 case REMOTE_NAME_INFO_LEVEL:
3233 REMOTE_NAME_INFO *pRemoteInfo = (REMOTE_NAME_INFO *)lpBuffer;
3235 *lpBufferSize = sizeof( REMOTE_NAME_INFO) + 2 * dwBufferSize + sizeof( WCHAR);
3237 if( dwPassedSize <= sizeof( REMOTE_NAME_INFO))
3240 #ifdef AFS_DEBUG_TRACE
3241 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO) WN_MORE_DATA\n");
3244 try_return( dwStatus = WN_MORE_DATA);
3247 dwRemainingLength -= sizeof( REMOTE_NAME_INFO);
3249 pRemoteInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( REMOTE_NAME_INFO));
3251 memcpy( pRemoteInfo->lpUniversalName,
3253 min( dwRemainingLength, dwBufferSize));
3255 dwRemainingLength -= min( dwRemainingLength, dwBufferSize);
3257 #ifdef AFS_DEBUG_TRACE
3258 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) UNI lpBuffer: %p Name: (%p) \"%s\"\n",
3260 pRemoteInfo->lpUniversalName,
3261 pRemoteInfo->lpUniversalName);
3264 if ( dwRemainingLength > dwBufferSize + sizeof( WCHAR))
3266 pRemoteInfo->lpConnectionName = (LPTSTR)((char *)pRemoteInfo->lpUniversalName + dwBufferSize);
3268 memcpy( pRemoteInfo->lpConnectionName,
3270 min( dwRemainingLength, dwBufferSize));
3272 dwRemainingLength -= min( dwRemainingLength, dwBufferSize) - sizeof( WCHAR);
3274 SeparateRemainingPath( pRemoteInfo->lpConnectionName,
3275 &pRemoteInfo->lpRemainingPath);
3278 #ifdef AFS_DEBUG_TRACE
3279 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) CONN lpBuffer: %p Name: (%p) \"%s\"\n",
3281 pRemoteInfo->lpConnectionName,
3282 pRemoteInfo->lpConnectionName ? pRemoteInfo->lpConnectionName : L"(null)");
3284 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) REMAIN lpBuffer: %p Name: (%p) \"%s\"\n",
3286 pRemoteInfo->lpRemainingPath,
3287 pRemoteInfo->lpRemainingPath ? pRemoteInfo->lpRemainingPath : L"(null)");
3290 if ( dwPassedSize < *lpBufferSize)
3293 try_return( dwStatus = WN_MORE_DATA);
3296 try_return( dwStatus = WN_SUCCESS);
3300 #ifdef AFS_DEBUG_TRACE
3301 AFSDbgPrint( L"NPGetUniversalName (UNKNOWN: 0x%X) WN_BAD_VALUE\n",
3304 try_return( dwStatus = WN_BAD_VALUE);
3310 #ifdef AFS_DEBUG_TRACE
3311 AFSDbgPrint( L"NPGetUniversalName drive substitution %s is not AFS\n",
3314 try_return( dwStatus = WN_NOT_CONNECTED);
3318 dwBufferSize = 0x1000;
3320 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
3322 if( pConnectCB == NULL)
3324 try_return( dwStatus = WN_OUT_OF_MEMORY);
3327 pConnectCB->LocalName = towupper(wchLocalName[0]);
3329 pConnectCB->RemoteNameLength = 0;
3331 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
3333 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
3335 #ifdef AFS_DEBUG_TRACE
3336 AFSDbgPrint( L"NPGetUniversalName Retrieved authentication id %08lX-%08lX\n",
3337 pConnectCB->AuthenticationId.HighPart,
3338 pConnectCB->AuthenticationId.LowPart);
3341 hControlDevice = OpenRedirector();
3343 if( hControlDevice == NULL)
3346 try_return( dwStatus = WN_NET_ERROR);
3349 dwError = DeviceIoControl( hControlDevice,
3350 IOCTL_AFS_GET_CONNECTION,
3360 #ifdef AFS_DEBUG_TRACE
3361 DWORD gle = GetLastError();
3363 AFSDbgPrint( L"NPGetUniversalName Failed to get connection from file system for local %s gle 0x%x\n",
3366 try_return( dwStatus = WN_NOT_CONNECTED);
3369 switch( dwInfoLevel)
3372 case UNIVERSAL_NAME_INFO_LEVEL:
3375 UNIVERSAL_NAME_INFO *pUniversalInfo = (UNIVERSAL_NAME_INFO *)lpBuffer;
3377 *lpBufferSize = sizeof( UNIVERSAL_NAME_INFO) + dwBufferSize + sizeof( WCHAR);
3379 *lpBufferSize += dwRemainingPathLength * sizeof( WCHAR);
3381 if( dwPassedSize <= sizeof( UNIVERSAL_NAME_INFO))
3384 #ifdef AFS_DEBUG_TRACE
3385 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO) WN_MORE_DATA\n");
3388 try_return( dwStatus = WN_MORE_DATA);
3391 dwRemainingLength -= sizeof( UNIVERSAL_NAME_INFO);
3393 pUniversalInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( UNIVERSAL_NAME_INFO));
3395 pch = (char *)pUniversalInfo->lpUniversalName;
3399 min( dwBufferSize, dwRemainingLength));
3401 pch += min( dwBufferSize, dwRemainingLength);
3403 dwRemainingLength -= min( dwBufferSize + sizeof(WCHAR), dwRemainingLength);
3407 min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength));
3409 pch += min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength);
3411 dwRemainingLength -= min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength);
3413 #ifdef AFS_DEBUG_TRACE
3414 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO_LEVEL) lpBuffer: %p Name: (%p) \"%s\"\n",
3416 pUniversalInfo->lpUniversalName,
3417 pUniversalInfo->lpUniversalName);
3420 if ( dwPassedSize < *lpBufferSize)
3423 try_return( dwStatus = WN_MORE_DATA);
3426 try_return( dwStatus = WN_SUCCESS);
3429 case REMOTE_NAME_INFO_LEVEL:
3432 REMOTE_NAME_INFO *pRemoteInfo = (REMOTE_NAME_INFO *)lpBuffer;
3434 *lpBufferSize = sizeof( REMOTE_NAME_INFO) + (2 * dwBufferSize + sizeof( WCHAR)) + 2 * sizeof( WCHAR);
3436 *lpBufferSize += 2 * dwRemainingPathLength * sizeof( WCHAR);
3438 if( dwPassedSize <= sizeof( REMOTE_NAME_INFO))
3441 #ifdef AFS_DEBUG_TRACE
3442 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO) WN_MORE_DATA\n");
3445 try_return( dwStatus = WN_MORE_DATA);
3448 dwRemainingLength -= sizeof( REMOTE_NAME_INFO);
3450 pRemoteInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( REMOTE_NAME_INFO));
3452 pch = (char *)pRemoteInfo->lpUniversalName;
3456 min( dwBufferSize, dwRemainingLength));
3458 pch += min( dwBufferSize, dwRemainingLength);
3460 dwRemainingLength -= min( dwBufferSize + sizeof( WCHAR), dwRemainingLength);
3464 min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength));
3466 pch += min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3468 dwRemainingLength -= min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3470 #ifdef AFS_DEBUG_TRACE
3471 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) UNI lpBuffer: %p Name: (%p) \"%s\"\n",
3473 pRemoteInfo->lpUniversalName,
3474 pRemoteInfo->lpUniversalName);
3477 if ( dwRemainingLength > dwBufferSize + sizeof( WCHAR))
3479 pRemoteInfo->lpConnectionName = (LPWSTR)pch;
3483 min( dwBufferSize, dwRemainingLength));
3485 pch += min( dwBufferSize + sizeof( WCHAR), dwRemainingLength);
3487 dwRemainingLength -= min( dwBufferSize + sizeof( WCHAR), dwRemainingLength);
3491 if ( dwRemainingLength > dwRemainingPathLength + sizeof( WCHAR))
3493 pRemoteInfo->lpRemainingPath = (LPWSTR)pch;
3497 min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength));
3499 pch += min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3501 dwRemainingLength -= min((dwLocalPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3504 #ifdef AFS_DEBUG_TRACE
3505 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) CONN lpBuffer: %p Name: (%p) \"%s\"\n",
3507 pRemoteInfo->lpConnectionName,
3508 pRemoteInfo->lpConnectionName ? pRemoteInfo->lpConnectionName : L"(null)");
3510 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) REMAIN lpBuffer: %p Name: (%p) \"%s\"\n",
3512 pRemoteInfo->lpRemainingPath,
3513 pRemoteInfo->lpRemainingPath ? pRemoteInfo->lpRemainingPath : L"(null)");
3516 if ( dwPassedSize < *lpBufferSize)
3519 try_return( dwStatus = WN_MORE_DATA);
3522 try_return( dwStatus = WN_SUCCESS);
3526 #ifdef AFS_DEBUG_TRACE
3527 AFSDbgPrint( L"NPGetUniversalName (UNKNOWN: 0x%X) WN_BAD_VALUE\n",
3530 try_return( dwStatus = WN_BAD_VALUE);
3535 #ifdef AFS_DEBUG_TRACE
3536 AFSDbgPrint( L"NPGetUniversalName BufferSize 0x%X\n",
3539 if ( hControlDevice != NULL)
3542 CloseHandle( hControlDevice);
3545 if( pConnectCB != NULL)
3548 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
3557 GetFormatFlags( DWORD dwFlags)
3559 static WCHAR Buffer[128] = L"";
3562 // WNFMT_MULTILINE 0x01
3563 // WNFMT_ABBREVIATED 0x02
3564 // WNFMT_INENUM 0x10
3565 // WNFMT_CONNECTION 0x20
3570 if ( dwFlags & WNFMT_MULTILINE )
3572 StringCbCat( Buffer, sizeof(Buffer), L"MULTILINE|");
3575 if ( dwFlags & WNFMT_INENUM )
3577 StringCbCat( Buffer, sizeof(Buffer), L"ABBREVIATED|");
3580 if ( dwFlags & WNFMT_INENUM )
3582 StringCbCat( Buffer, sizeof(Buffer), L"INENUM|");
3585 if ( dwFlags & WNFMT_CONNECTION )
3587 StringCbCat( Buffer, sizeof(Buffer), L"CONNECTION|");
3590 if ( dwFlags & ~(WNFMT_MULTILINE|WNFMT_ABBREVIATED|WNFMT_INENUM|WNFMT_CONNECTION) )
3592 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
3595 Buffer[lstrlen(Buffer)-1] = L'\0';
3601 NPFormatNetworkName( LPTSTR lpRemoteName,
3602 LPTSTR lpFormattedName,
3605 DWORD dwAveCharPerLine)
3608 DWORD dwLen = 0, dwCurrentLen = 0;
3609 LPTSTR pCurrentName = lpRemoteName;
3611 #ifdef AFS_DEBUG_TRACE
3612 AFSDbgPrint( L"NPFormatNetworkName Remote %s Flags %s (0x%x) CharsPerLine %u\n",
3615 GetFormatFlags( dwFlags),
3621 // Walk back in the name until we hit a \
3624 dwLen = wcslen( lpRemoteName);
3626 pCurrentName += (dwLen - 1);
3628 if ( pCurrentName[ 0] != L'\\')
3634 if( pCurrentName[ 0] == L'\\')
3650 if( *lpnLength < dwCurrentLen * sizeof( WCHAR))
3653 *lpnLength = dwCurrentLen * sizeof( WCHAR);
3655 #ifdef AFS_DEBUG_TRACE
3656 AFSDbgPrint( L"NPFormatNetworkName remote name %s WN_MORE_DATA\n",
3660 return WN_MORE_DATA;
3663 StringCbCopy( lpFormattedName,
3667 *lpnLength = dwCurrentLen * sizeof( WCHAR);
3669 #ifdef AFS_DEBUG_TRACE
3670 AFSDbgPrint( L"NPFormatNetworkName remote name %s as %s\n",
3678 /************************************************************
3679 / Unsupported entry points
3680 /************************************************************/
3683 // AuthGroup processing is implemented in src/WINNT/afsd/afslogon.c
3688 LPCWSTR lpAuthentInfoType,
3689 LPVOID lpAuthentInfo,
3690 LPCWSTR lpPreviousAuthentInfoType,
3691 LPVOID lpPreviousAuthentInfo,
3692 LPWSTR lpStationName,
3693 LPVOID StationHandle,
3694 LPWSTR *lpLogonScript)
3697 #ifdef AFS_DEBUG_TRACE
3698 AFSDbgPrint( L"NPLogonNotify, returning WN_NOT_SUPPORTED\n");
3701 return WN_NOT_SUPPORTED;
3705 NPPasswordChangeNotify (
3706 LPCWSTR lpAuthentInfoType,
3707 LPVOID lpAuthentInfo,
3708 LPCWSTR lpPreviousAuthentInfoType,
3709 LPVOID lpPreviousAuthentInfo,
3710 LPWSTR lpStationName,
3711 LPVOID StationHandle,
3712 DWORD dwChangeInfo )
3715 #ifdef AFS_DEBUG_TRACE
3716 AFSDbgPrint( L"NPPasswordChangeNotify, returning WN_NOT_SUPPORTED\n");
3719 SetLastError( WN_NOT_SUPPORTED );
3721 return WN_NOT_SUPPORTED;
3725 NPGetUser( LPTSTR lpName,
3727 LPDWORD lpBufferSize)
3730 DWORD rc = WN_NOT_SUPPORTED;
3732 AFSDbgPrint( L"NPGetUser Entry Name %s\n", lpName);
3740 NPGetReconnectFlags( LPWSTR lpRemoteName,
3741 unsigned char *Parameter2)
3744 DWORD dwStatus = WN_NOT_SUPPORTED;
3746 AFSDbgPrint( L"NPGetReconnectFlags RemoteName %s\n",
3755 I_SystemFocusDialog( VOID)
3758 DWORD dwStatus = WN_NOT_SUPPORTED;
3760 AFSDbgPrint( L"I_SystemFocusDialog\n");
3765 /************************************************************
3766 / END Unsupported entry points
3767 /************************************************************/
3774 HANDLE hControlDevice = NULL;
3775 WCHAR wchError[ 256];
3777 hControlDevice = CreateFile( AFS_SYMLINK_W,
3778 GENERIC_READ | GENERIC_WRITE,
3779 FILE_SHARE_READ | FILE_SHARE_WRITE,
3785 if( hControlDevice == INVALID_HANDLE_VALUE)
3788 hControlDevice = NULL;
3789 #ifdef AFS_DEBUG_TRACE
3790 AFSDbgPrint( L"Failed to open control device error: %d\n",
3796 // only do this if you want network shares to fail to mount
3797 // when the file system is not yet ready
3801 AFSDriverStatusRespCB respCB;
3804 memset( &respCB, '\0', sizeof( AFSDriverStatusRespCB));
3806 if ( !DeviceIoControl( hControlDevice,
3807 IOCTL_AFS_STATUS_REQUEST,
3811 sizeof( AFSDriverStatusRespCB),
3814 dwBytes != sizeof(AFSDriverStatusRespCB) ||
3815 respCB.Status != AFS_DRIVER_STATUS_READY )
3818 CloseHandle( hControlDevice);
3820 hControlDevice = NULL;
3825 return hControlDevice;
3832 LARGE_INTEGER liAuthId = {0,0};
3833 HANDLE hToken = NULL;
3834 TOKEN_STATISTICS stTokenInfo;
3835 DWORD dwCopyBytes = 0;
3837 if ( !OpenThreadToken( GetCurrentThread(),
3839 FALSE, // Impersonation
3842 if( !OpenProcessToken( GetCurrentProcess(),
3847 #ifdef AFS_DEBUG_TRACE
3848 AFSDbgPrint( L"AFSRetrieveAuthId Failed to retrieve Thread and Process tokens 0x%X\n",
3855 #ifdef AFS_DEBUG_TRACE
3856 AFSDbgPrint( L"AFSRetrieveAuthId Retrieved Process Token\n");
3863 #ifdef AFS_DEBUG_TRACE
3864 AFSDbgPrint( L"AFSRetrieveAuthId Retrieved Thread Token\n");
3868 if ( hToken != NULL)
3871 if( !GetTokenInformation( hToken,
3874 sizeof( TOKEN_STATISTICS),
3878 #ifdef AFS_DEBUG_TRACE
3879 AFSDbgPrint( L"AFSRetrieveAuthId Failed to retrieve token information 0x%X\n",
3886 liAuthId.HighPart = stTokenInfo.AuthenticationId.HighPart;
3887 liAuthId.LowPart = stTokenInfo.AuthenticationId.LowPart;
3890 CloseHandle( hToken);
3899 static int init = 0;
3900 static BOOL debug = 0;
3905 if (RegOpenKey (HKEY_LOCAL_MACHINE,
3906 TEXT("SYSTEM\\CurrentControlSet\\Services\\AFSRedirector\\NetworkProvider"), &hk) == 0)
3908 DWORD dwSize = sizeof(BOOL);
3909 DWORD dwType = REG_DWORD;
3910 RegQueryValueEx (hk, TEXT("Debug"), NULL, &dwType, (PBYTE)&debug, &dwSize);
3927 WCHAR wszbuffer[512];
3933 va_start( marker, Format );
3935 StringCbPrintf( wszbuffer, sizeof(wszbuffer), L"[%d-%08X] ",
3941 GetCurrentThreadId());
3943 rc = StringCbVPrintfW( &wszbuffer[ 14], sizeof(wszbuffer) - 14, Format, marker);
3946 OutputDebugString( wszbuffer );
3948 OutputDebugString(L"AFSDbgPrint Failed to create string\n");
3950 return SUCCEEDED(rc) ? 1 : 0;