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, ... );
76 NPGetConnectionCommon( LPWSTR lpLocalName,
81 #define WNNC_DRIVER( major, minor ) ( major * 0x00010000 + minor )
83 #define OPENAFS_PROVIDER_NAME L"OpenAFS Network"
84 #define OPENAFS_PROVIDER_NAME_LENGTH 30
86 #define MAX_PROVIDER_NAME_LENGTH 256
88 static ULONG cbProviderNameLength = OPENAFS_PROVIDER_NAME_LENGTH;
90 static wchar_t wszProviderName[MAX_PROVIDER_NAME_LENGTH+1] = OPENAFS_PROVIDER_NAME;
92 static BOOL bProviderNameRead = FALSE;
94 #define OPENAFS_SERVER_NAME L"AFS"
95 #define OPENAFS_SERVER_NAME_LENGTH 6
97 #define OPENAFS_SERVER_COMMENT L"AFS Root"
98 #define OPENAFS_SERVER_COMMENT_LENGTH 16
100 #define MAX_SERVER_NAME_LENGTH 30
102 static ULONG cbServerNameLength = 0;
104 static ULONG cbServerNameUNCLength = 0;
106 static ULONG cbServerCommentLength = OPENAFS_SERVER_COMMENT_LENGTH;
108 static wchar_t wszServerName[MAX_SERVER_NAME_LENGTH+1];
110 static wchar_t wszServerNameUNC[MAX_SERVER_NAME_LENGTH+3];
112 static wchar_t wszServerComment[] = OPENAFS_SERVER_COMMENT;
114 static BOOL bServerNameRead = FALSE;
117 AFSRetrieveAuthId( void);
120 ReadProviderNameString( void)
126 if ( bProviderNameRead )
129 code = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
130 L"SYSTEM\\CurrentControlSet\\Services\\AFSRedirector\\NetworkProvider",
131 0, KEY_QUERY_VALUE, &hk);
133 if ( code == ERROR_SUCCESS) {
135 dwLen = sizeof(wszProviderName);
137 code = RegQueryValueExW( hk, L"Name", NULL, NULL,
138 (LPBYTE) wszProviderName, &dwLen);
140 if ( code == ERROR_SUCCESS)
143 wszProviderName[MAX_PROVIDER_NAME_LENGTH] = '\0';
145 cbProviderNameLength = wcslen( wszProviderName) * sizeof( WCHAR);
151 bProviderNameRead = TRUE;
155 ReadServerNameString( void)
161 if ( bServerNameRead )
164 code = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
165 L"SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters",
166 0, KEY_QUERY_VALUE, &hk);
168 if ( code == ERROR_SUCCESS) {
170 dwLen = sizeof(wszProviderName);
172 code = RegQueryValueExW( hk, L"NetbiosName", NULL, NULL,
173 (LPBYTE) wszServerName, &dwLen);
175 if ( code == ERROR_SUCCESS)
178 wszServerName[MAX_SERVER_NAME_LENGTH] = '\0';
180 cbServerNameLength = wcslen( wszServerName) * sizeof( WCHAR);
182 wszServerNameUNC[0] = wszServerNameUNC[1] = L'\\';
184 memcpy(&wszServerNameUNC[2], wszServerName, (cbServerNameLength + 1) * sizeof( WCHAR));
186 cbServerNameUNCLength = cbServerNameLength + 2 * sizeof( WCHAR);
192 bServerNameRead = TRUE;
197 /* returns TRUE if the file system is disabled or not installed */
199 NPIsFSDisabled( void)
204 DWORD dwStart = SERVICE_DISABLED;
206 code = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
207 L"SYSTEM\\CurrentControlSet\\Services\\AFSRedirector",
208 0, KEY_QUERY_VALUE, &hk);
210 if ( code != ERROR_SUCCESS)
215 dwLen = sizeof(dwStart);
217 code = RegQueryValueExW( hk, L"Start", NULL, NULL,
218 (LPBYTE) &dwStart, &dwLen);
222 return ( dwStart == SERVICE_DISABLED);
226 #define try_return(S) { S; goto try_exit; }
232 typedef struct _UNICODE_STRING {
234 USHORT MaximumLength;
236 } UNICODE_STRING, *PUNICODE_STRING;
239 OpenRedirector( void);
241 typedef struct _AFS_ENUM_CB
256 // Recursively evaluate drivestr to find the final
257 // dos drive letter to which the source is mapped.
260 DriveSubstitution(LPCWSTR drivestr, LPWSTR subststr, size_t substlen)
263 WCHAR device[MAX_PATH + 1];
266 memset( subststr, 0, substlen);
267 drive[0] = drivestr[0];
268 drive[1] = drivestr[1];
271 if ( QueryDosDevice(drive, device, MAX_PATH) )
273 #ifdef AFS_DEBUG_TRACE
274 AFSDbgPrint( L"DriveSubstitution QueryDosDevice %s [%s -> %s]\n",
279 if ( device[0] == L'\\' &&
282 device[3] == L'\\' &&
283 iswalpha(device[4]) &&
286 drive[0] = device[4];
290 if ( !DriveSubstitution(drive, subststr, substlen) )
293 subststr[0] = drive[0];
303 hr = StringCchCat( subststr, substlen, &device[6]);
305 if ( SUCCEEDED(hr) && drivestr[2] )
307 hr = StringCchCat( subststr, substlen, &drivestr[2]);
310 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
313 #ifdef AFS_DEBUG_TRACE
314 AFSDbgPrint( L"DriveSubstitution %s -> %s\n",
321 else if ( device[0] == L'\\' &&
324 device[3] == L'\\' &&
333 hr = StringCbCopyN(&subststr[1], substlen - sizeof(WCHAR), &device[7], MAX_PATH);
335 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
339 hr = StringCchCat( subststr, substlen, &drivestr[2]);
346 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
349 #ifdef AFS_DEBUG_TRACE
350 AFSDbgPrint( L"DriveSubstitution %s -> %s\n",
358 #ifdef AFS_DEBUG_TRACE
359 AFSDbgPrint( L"DriveSubstitution StringCbCopyN 1 hr 0x%X\n",
363 else if ( _wcsnicmp( AFS_RDR_DEVICE_NAME, device, sizeof( AFS_RDR_DEVICE_NAME) / sizeof( WCHAR) - 1) == 0)
366 // \Device\AFSRedirector\;X:\\afs\cellname
369 hr = StringCbCopyN( subststr, substlen,
370 &device[3 + sizeof( AFS_RDR_DEVICE_NAME) / sizeof( WCHAR)],
371 MAX_PATH * sizeof( WCHAR));
373 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
378 hr = StringCchCat( subststr, substlen, &drivestr[2]);
385 if ( SUCCEEDED(hr) || hr == STRSAFE_E_INSUFFICIENT_BUFFER)
388 #ifdef AFS_DEBUG_TRACE
389 AFSDbgPrint( L"DriveSubstitution %s -> %s\n",
397 #ifdef AFS_DEBUG_TRACE
398 AFSDbgPrint( L"DriveSubstitution StringCbCopyN 2 hr 0x%X\n",
403 #ifdef AFS_DEBUG_TRACE
404 AFSDbgPrint( L"DriveSubstitution no substitution or match %s !! %s\n",
411 #ifdef AFS_DEBUG_TRACE
412 AFSDbgPrint( L"DriveSubstitution QueryDosDevice failed %s gle 0x%X\n",
425 NPGetCapsQueryString( DWORD nIndex)
428 case WNNC_SPEC_VERSION:
429 return L"WNNC_SPEC_VERSION";
432 return L"WNNC_NET_TYPE";
434 case WNNC_DRIVER_VERSION:
435 return L"WNNC_DRIVER_VERSION";
440 case WNNC_CONNECTION:
441 return L"WNNC_CONNECTION";
444 return L"WNNC_DIALOG";
447 return L"WNNC_ADMIN";
449 case WNNC_ENUMERATION:
450 return L"WNNC_ENUMERATION";
453 return L"WNNC_START";
455 case WNNC_CONNECTION_FLAGS:
456 return L"WNNC_CONNECTION_FLAGS";
464 // This is the only function which must be exported, everything else is optional
469 NPGetCaps( DWORD nIndex )
474 #ifdef AFS_DEBUG_TRACE
475 AFSDbgPrint( L"NPGetCaps Index %u %s\n", nIndex,
476 NPGetCapsQueryString( nIndex));
480 case WNNC_SPEC_VERSION:
483 rc = WNNC_SPEC_VERSION51;
489 rc = WNNC_NET_OPENAFS;
493 case WNNC_DRIVER_VERSION:
496 rc = WNNC_DRIVER(1, 0);
500 case WNNC_CONNECTION:
505 // WNNC_CON_GETPERFORMANCE
509 rc = WNNC_CON_GETCONNECTIONS |
510 WNNC_CON_CANCELCONNECTION |
511 WNNC_CON_ADDCONNECTION |
512 WNNC_CON_ADDCONNECTION3;
517 case WNNC_ENUMERATION:
519 rc = WNNC_ENUM_LOCAL |
529 rc = WNNC_WAIT_FOR_START;
539 // WNNC_DLG_DEVICEMODE
540 // WNNC_DLG_PROPERTYDIALOG
541 // WNNC_DLG_SEARCHDIALOG
542 // WNNC_DLG_PERMISSIONEDITOR
545 rc = WNNC_DLG_FORMATNETWORKNAME |
546 WNNC_DLG_GETRESOURCEINFORMATION |
547 WNNC_DLG_GETRESOURCEPARENT;
566 // WNNC_ADM_GETDIRECTORYTYPE
567 // WNNC_ADM_DIRECTORYNOTIFY
568 // used by the old File Manager
579 NPAddConnection( LPNETRESOURCE lpNetResource,
584 #ifdef AFS_DEBUG_TRACE
585 AFSDbgPrint( L"NPAddConnection forwarding to NPAddConnection3\n");
587 return NPAddConnection3( NULL, lpNetResource, lpPassword, lpUserName, 0 );
592 NPAddConnection3( HWND hwndOwner,
593 LPNETRESOURCE lpNetResource,
599 DWORD dwStatus = WN_SUCCESS;
600 WCHAR wchRemoteName[MAX_PATH+1];
601 WCHAR wchLocalName[3];
602 DWORD dwCopyBytes = 0;
603 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
605 DWORD dwBufferSize = 0;
606 HANDLE hControlDevice = NULL;
607 HANDLE hToken = NULL;
608 LARGE_INTEGER liAuthId = {0,0};
612 if ( NPIsFSDisabled())
615 #ifdef AFS_DEBUG_TRACE
616 AFSDbgPrint( L"NPAddConnection3 AFSRDFS is disabled, returning WN_BAD_NETNAME\n");
619 return WN_BAD_NETNAME;
622 if ((lpNetResource->lpRemoteName == NULL) ||
623 (lpNetResource->lpRemoteName[0] != L'\\') ||
624 (lpNetResource->lpRemoteName[1] != L'\\') ||
625 ((lpNetResource->dwType != RESOURCETYPE_DISK) &&
626 (lpNetResource->dwType != RESOURCETYPE_ANY)))
629 #ifdef AFS_DEBUG_TRACE
630 AFSDbgPrint( L"NPAddConnection3 invalid input, returning WN_BAD_NETNAME\n");
632 return WN_BAD_NETNAME;
635 #ifdef AFS_DEBUG_TRACE
636 AFSDbgPrint( L"NPAddConnection3 processing\n");
638 if( lpNetResource->lpLocalName != NULL)
641 wchLocalName[0] = towupper(lpNetResource->lpLocalName[0]);
642 wchLocalName[1] = L':';
643 wchLocalName[2] = L'\0';
646 StringCchCopy(wchRemoteName, MAX_PATH+1, lpNetResource->lpRemoteName);
647 wchRemoteName[MAX_PATH] = L'\0';
650 // Allocate our buffer to pass to the redirector filter
653 dwBufferSize = sizeof( AFSNetworkProviderConnectionCB) + (wcslen( wchRemoteName) * sizeof( WCHAR));
655 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
657 if( pConnectCB == NULL)
660 try_return( dwStatus = WN_OUT_OF_MEMORY);
663 if( lpNetResource->lpLocalName != NULL)
666 pConnectCB->LocalName = towupper(wchLocalName[0]);
668 #ifdef AFS_DEBUG_TRACE
669 AFSDbgPrint( L"NPAddConnection3 Adding mapping for drive %s remote name %s\n",
677 pConnectCB->LocalName = L'\0';
679 #ifdef AFS_DEBUG_TRACE
680 AFSDbgPrint( L"NPAddConnection3 Adding mapping for NO drive remote name %s\n",
685 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
687 pConnectCB->RemoteNameLength = wcslen( wchRemoteName) * sizeof( WCHAR);
689 memcpy( pConnectCB->RemoteName,
691 pConnectCB->RemoteNameLength);
693 pConnectCB->Type = lpNetResource->dwType;
695 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
697 #ifdef AFS_DEBUG_TRACE
698 AFSDbgPrint( L"NPAddConnection3 Retrieved authentication id %08lX-%08lX\n",
699 pConnectCB->AuthenticationId.HighPart,
700 pConnectCB->AuthenticationId.LowPart);
703 hControlDevice = OpenRedirector();
705 if( hControlDevice == NULL)
708 #ifdef AFS_DEBUG_TRACE
709 AFSDbgPrint( L"NPAddConnection3 OpenRedirector failure, returning WN_NET_ERROR\n");
712 try_return( dwStatus = WN_NET_ERROR);
715 dwError = DeviceIoControl( hControlDevice,
716 IOCTL_AFS_ADD_CONNECTION,
726 #ifdef AFS_DEBUG_TRACE
727 AFSDbgPrint( L"NPAddConnection3 Failed to add connection to file system %d\n", GetLastError());
729 try_return( dwStatus = WN_OUT_OF_MEMORY);
733 // The status returned from the driver will indicate how it was handled
736 if( dwStatus == WN_SUCCESS &&
737 lpNetResource->lpLocalName != NULL)
740 WCHAR TempBuf[MAX_PATH+1];
742 if( !QueryDosDeviceW( wchLocalName,
747 if( GetLastError() != ERROR_FILE_NOT_FOUND)
750 #ifdef AFS_DEBUG_TRACE
751 AFSDbgPrint( L"NPAddConnection3 QueryDosDeviceW failed with file not found\n");
753 NPCancelConnection( wchLocalName, TRUE);
755 dwStatus = ERROR_ALREADY_ASSIGNED;
760 UNICODE_STRING uniConnectionName;
761 UNICODE_STRING uniDeviceName;
763 uniDeviceName.Length = (wcslen( AFS_RDR_DEVICE_NAME) * sizeof( WCHAR));
764 uniDeviceName.MaximumLength = uniDeviceName.Length;
765 uniDeviceName.Buffer = AFS_RDR_DEVICE_NAME;
768 // Create a symbolic link object to the device we are redirecting
771 uniConnectionName.MaximumLength = (USHORT)( uniDeviceName.Length +
772 pConnectCB->RemoteNameLength +
773 8 + // Local name and \;
774 sizeof(WCHAR)); // Space for NULL-termination.
777 // Don't include NULL-termination.
780 uniConnectionName.Length = uniConnectionName.MaximumLength - sizeof(WCHAR);
782 uniConnectionName.Buffer = LocalAlloc( LMEM_ZEROINIT,
783 uniConnectionName.MaximumLength);
785 if( uniConnectionName.Buffer == NULL)
788 try_return( dwStatus = GetLastError());
791 CopyMemory( uniConnectionName.Buffer,
792 uniDeviceName.Buffer,
793 uniDeviceName.Length);
795 StringCchCatW( uniConnectionName.Buffer,
796 uniConnectionName.MaximumLength,
799 StringCchCatW( uniConnectionName.Buffer,
800 uniConnectionName.MaximumLength,
803 StringCchCatW( uniConnectionName.Buffer,
804 uniConnectionName.MaximumLength,
807 #ifdef AFS_DEBUG_TRACE
808 AFSDbgPrint( L"NPAddConnection3 DefineDosDevice Local %s connection name %s\n",
810 uniConnectionName.Buffer);
813 if( !DefineDosDeviceW( DDD_RAW_TARGET_PATH |
814 DDD_NO_BROADCAST_SYSTEM,
816 uniConnectionName.Buffer))
818 #ifdef AFS_DEBUG_TRACE
819 AFSDbgPrint( L"NPAddConnection3 Failed to assign drive\n");
821 dwStatus = GetLastError();
826 #ifdef AFS_DEBUG_TRACE
827 AFSDbgPrint( L"NPAddConnection3 QueryDosDeviceW assigned drive %s\n", wchLocalName);
830 dwStatus = WN_SUCCESS;
833 LocalFree( uniConnectionName.Buffer);
839 #ifdef AFS_DEBUG_TRACE
840 AFSDbgPrint( L"NPAddConnection3 QueryDosDeviceW %Z already existed\n", TempBuf);
842 NPCancelConnection( wchLocalName, TRUE);
844 dwStatus = ERROR_ALREADY_ASSIGNED;
850 if ( hControlDevice != NULL)
853 CloseHandle( hControlDevice);
856 if( pConnectCB != NULL)
859 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
868 NPCancelConnection( LPWSTR lpName,
872 WCHAR wchRemoteName[MAX_PATH+1];
873 DWORD dwRemoteNameLength = (MAX_PATH+1) * sizeof(WCHAR);
874 DWORD dwStatus = WN_NOT_CONNECTED;
875 DWORD dwCopyBytes = 0;
876 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
877 AFSCancelConnectionResultCB stCancelConn;
879 DWORD dwBufferSize = 0;
880 BOOL bLocalName = TRUE;
881 HANDLE hControlDevice = NULL;
882 WCHAR wchLocalName[ 3];
883 WCHAR *pwchLocalName = NULL;
888 if ( NPIsFSDisabled())
891 #ifdef AFS_DEBUG_TRACE
892 AFSDbgPrint( L"NPCancelConnection AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
895 try_return( dwStatus = WN_NOT_CONNECTED);
898 if( *lpName == L'\\' &&
899 *(lpName + 1) == L'\\')
904 wchLocalName[0] = L'\0';
906 StringCchCopyW( wchRemoteName, MAX_PATH+1, lpName);
908 dwRemoteNameLength = (wcslen( wchRemoteName) * sizeof( WCHAR));
913 wchLocalName[0] = towupper(lpName[0]);
914 wchLocalName[1] = L':';
915 wchLocalName[2] = L'\0';
918 // Get the remote name for the connection, if we are handling it
921 dwStatus = NPGetConnectionCommon( wchLocalName,
926 if( dwStatus != WN_SUCCESS ||
927 dwRemoteNameLength == 0)
930 #ifdef AFS_DEBUG_TRACE
931 AFSDbgPrint( L"NPCancelConnection Status 0x%x NameLength %u, returning WN_NOT_CONNECTED\n",
932 dwStatus, dwRemoteNameLength);
934 try_return( dwStatus = WN_NOT_CONNECTED);
938 // NPGetConnection returns the buffer size not the length without NUL
940 dwRemoteNameLength -= sizeof( WCHAR);
943 wchRemoteName[ dwRemoteNameLength/sizeof( WCHAR)] = L'\0';
945 #ifdef AFS_DEBUG_TRACE
946 AFSDbgPrint( L"NPCancelConnection Attempting to cancel '%s' -> '%s'\n",
947 wchLocalName, wchRemoteName);
950 dwBufferSize = sizeof( AFSNetworkProviderConnectionCB) + dwRemoteNameLength;
952 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
954 if( pConnectCB == NULL)
957 try_return( dwStatus = WN_OUT_OF_MEMORY);
963 pConnectCB->LocalName = wchLocalName[0];
968 pConnectCB->LocalName = L'\0';
971 pConnectCB->RemoteNameLength = (USHORT)dwRemoteNameLength;
973 StringCchCopyW( pConnectCB->RemoteName,
977 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
979 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
981 #ifdef AFS_DEBUG_TRACE
982 AFSDbgPrint( L"NPCancelConnection Retrieved authentication id %08lX-%08lX\n",
983 pConnectCB->AuthenticationId.HighPart,
984 pConnectCB->AuthenticationId.LowPart);
987 hControlDevice = OpenRedirector();
989 if( hControlDevice == NULL)
992 #ifdef AFS_DEBUG_TRACE
993 AFSDbgPrint( L"NPCancelConnection OpenRedirector failure, returning WN_NET_ERROR\n");
996 try_return( dwStatus = WN_NET_ERROR);
999 memset( &stCancelConn,
1001 sizeof( AFSCancelConnectionResultCB));
1003 dwError = DeviceIoControl( hControlDevice,
1004 IOCTL_AFS_CANCEL_CONNECTION,
1008 sizeof( AFSCancelConnectionResultCB),
1014 #ifdef AFS_DEBUG_TRACE
1015 DWORD gle = GetLastError();
1017 AFSDbgPrint( L"NPCancelConnection DeviceIoControl failed - gle 0x%x\n", gle);
1019 try_return( dwStatus = WN_NOT_CONNECTED);
1022 dwStatus = stCancelConn.Status;
1024 #ifdef AFS_DEBUG_TRACE
1025 if ( dwStatus == WN_NOT_CONNECTED )
1028 AFSDbgPrint( L"NPCancelConnection Cancel connection to file system - Name %s Status WN_NOT_CONNECTED\n",
1034 AFSDbgPrint( L"NPCancelConnection Cancel connection to file system - Name %s Status %08lX\n",
1040 if( dwStatus == WN_SUCCESS &&
1042 stCancelConn.LocalName != L'\0'))
1045 UNICODE_STRING uniConnectionName;
1046 UNICODE_STRING uniDeviceName;
1048 uniDeviceName.Length = (wcslen( AFS_RDR_DEVICE_NAME) * sizeof( WCHAR));
1049 uniDeviceName.MaximumLength = uniDeviceName.Length;
1050 uniDeviceName.Buffer = AFS_RDR_DEVICE_NAME;
1053 // Create a symbolic link object to the device we are redirecting
1056 uniConnectionName.MaximumLength = (USHORT)( uniDeviceName.Length +
1057 dwRemoteNameLength +
1058 8 + // Local name and \;
1059 sizeof(WCHAR)); // Space for NULL-termination.
1062 // Don't include NULL-termination.
1065 uniConnectionName.Length = uniConnectionName.MaximumLength - sizeof(WCHAR);
1067 uniConnectionName.Buffer = LocalAlloc( LMEM_ZEROINIT,
1068 uniConnectionName.MaximumLength);
1070 if( uniConnectionName.Buffer == NULL)
1073 try_return( dwStatus = GetLastError());
1076 CopyMemory( uniConnectionName.Buffer,
1077 uniDeviceName.Buffer,
1078 uniDeviceName.Length);
1080 StringCchCatW( uniConnectionName.Buffer,
1081 uniConnectionName.MaximumLength,
1087 wchLocalName[ 0] = stCancelConn.LocalName;
1089 wchLocalName[ 1] = L':';
1091 wchLocalName[ 2] = L'\0';
1093 StringCchCatW( uniConnectionName.Buffer,
1094 uniConnectionName.MaximumLength,
1097 pwchLocalName = wchLocalName;
1102 StringCchCatW( uniConnectionName.Buffer,
1103 uniConnectionName.MaximumLength,
1106 pwchLocalName = lpName;
1109 StringCchCatW( uniConnectionName.Buffer,
1110 uniConnectionName.MaximumLength,
1113 if( !DefineDosDevice( DDD_REMOVE_DEFINITION | DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE,
1115 uniConnectionName.Buffer))
1118 #ifdef AFS_DEBUG_TRACE
1119 DWORD gle = GetLastError();
1121 AFSDbgPrint( L"NPCancelConnection Failed to cancel connection to system - gle 0x%x Name %s connection %wZ\n",
1124 &uniConnectionName);
1129 #ifdef AFS_DEBUG_TRACE
1131 AFSDbgPrint( L"NPCancelConnection Canceled connection to system - Name %s connection %wZ\n",
1133 &uniConnectionName);
1140 if ( hControlDevice != NULL)
1143 CloseHandle( hControlDevice);
1147 if( pConnectCB != NULL)
1150 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1160 NPGetConnection( LPWSTR lpLocalName,
1161 LPWSTR lpRemoteName,
1162 LPDWORD lpBufferSize)
1165 return NPGetConnectionCommon( lpLocalName,
1173 NPGetConnectionCommon( LPWSTR lpLocalName,
1174 LPWSTR lpRemoteName,
1175 LPDWORD lpBufferSize,
1179 DWORD dwStatus = WN_NOT_CONNECTED;
1180 WCHAR wchLocalName[3];
1181 WCHAR wchSubstName[MAX_PATH + 1];
1182 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
1184 DWORD dwBufferSize = 0;
1185 HANDLE hControlDevice = NULL;
1191 if ( NPIsFSDisabled())
1194 #ifdef AFS_DEBUG_TRACE
1195 AFSDbgPrint( L"NPGetConnection AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
1198 try_return( dwStatus = WN_NOT_CONNECTED);
1201 if( lstrlen( lpLocalName) == 0)
1203 #ifdef AFS_DEBUG_TRACE
1204 AFSDbgPrint( L"NPGetConnection No local name, returning WN_BAD_LOCALNAME\n");
1206 try_return( dwStatus = WN_BAD_LOCALNAME);
1209 if ( lpBufferSize == NULL)
1211 #ifdef AFS_DEBUG_TRACE
1212 AFSDbgPrint( L"NPGetConnection No output size, returning WN_BAD_LOCALNAME\n");
1214 try_return( dwStatus = WN_BAD_VALUE);
1217 dwPassedSize = *lpBufferSize;
1219 if ( !bDriveSubstOk ||
1220 !DriveSubstitution( lpLocalName, wchSubstName, sizeof( wchSubstName)))
1222 wchLocalName[0] = towupper(lpLocalName[0]);
1223 wchLocalName[1] = L':';
1224 wchLocalName[2] = L'\0';
1226 #ifdef AFS_DEBUG_TRACE
1227 AFSDbgPrint( L"NPGetConnection Requesting connection for %s\n",
1233 ReadServerNameString();
1235 if ( wchSubstName[0] != L'\\' &&
1236 wchSubstName[1] == L':')
1239 wchLocalName[0] = towupper(wchSubstName[0]);
1240 wchLocalName[1] = L':';
1241 wchLocalName[2] = L'\0';
1243 #ifdef AFS_DEBUG_TRACE
1244 AFSDbgPrint( L"NPGetConnection Requesting connection for drive substitution %s -> %s\n",
1249 else if ( _wcsnicmp( wchSubstName, wszServerNameUNC, cbServerNameUNCLength / sizeof( WCHAR)) == 0 &&
1250 ( wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == L'\\' ||
1251 wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == 0))
1257 #ifdef AFS_DEBUG_TRACE
1258 AFSDbgPrint( L"NPGetConnection drive substitution %s is AFS\n",
1262 if ( lpRemoteName == NULL ||
1266 *lpBufferSize = wcslen( wchSubstName) * sizeof( WCHAR) + sizeof( WCHAR);
1268 try_return( dwStatus = WN_MORE_DATA);
1272 hr = StringCbCopyN(lpRemoteName, *lpBufferSize, wchSubstName, sizeof( wchSubstName));
1277 for ( dwCount = 0, pwch = lpRemoteName; *pwch; pwch++ )
1279 if ( *pwch == L'\\' )
1293 *lpBufferSize = wcslen( lpRemoteName) * sizeof( WCHAR) + sizeof( WCHAR);
1295 try_return( dwStatus = WN_SUCCESS);
1297 else if ( hr == STRSAFE_E_INSUFFICIENT_BUFFER)
1300 *lpBufferSize = wcslen( wchSubstName) * sizeof( WCHAR) + sizeof( WCHAR);
1302 for ( dwCount = 0, pwch = lpRemoteName; *pwch; pwch++ )
1304 if ( *pwch == L'\\' )
1312 *lpBufferSize = wcslen( lpRemoteName) * sizeof( WCHAR) + sizeof( WCHAR);
1314 try_return( dwStatus = WN_SUCCESS);
1320 try_return( dwStatus = WN_MORE_DATA);
1325 #ifdef AFS_DEBUG_TRACE
1326 AFSDbgPrint( L"NPGetConnection StringCbCopyN failure 0x%X\n",
1329 try_return( dwStatus = WN_NET_ERROR);
1335 #ifdef AFS_DEBUG_TRACE
1336 AFSDbgPrint( L"NPGetConnection drive substitution %s is not AFS\n",
1339 try_return( dwStatus = WN_NOT_CONNECTED);
1343 #ifdef AFS_DEBUG_TRACE
1344 AFSDbgPrint( L"NPGetConnection Requesting connection for %s\n",
1348 dwBufferSize = 0x1000;
1350 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
1352 if( pConnectCB == NULL)
1355 try_return( dwStatus = WN_OUT_OF_MEMORY);
1358 pConnectCB->LocalName = towupper(wchLocalName[0]);
1360 pConnectCB->RemoteNameLength = 0;
1362 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
1364 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
1366 #ifdef AFS_DEBUG_TRACE
1367 AFSDbgPrint( L"NPGetConnection Retrieved authentication id %08lX-%08lX\n",
1368 pConnectCB->AuthenticationId.HighPart,
1369 pConnectCB->AuthenticationId.LowPart);
1372 hControlDevice = OpenRedirector();
1374 if( hControlDevice == NULL)
1377 #ifdef AFS_DEBUG_TRACE
1378 AFSDbgPrint( L"NPGetConnection OpenRedirector failure, returning WN_NET_ERROR\n");
1381 try_return( dwStatus = WN_NET_ERROR);
1384 dwError = DeviceIoControl( hControlDevice,
1385 IOCTL_AFS_GET_CONNECTION,
1395 #ifdef AFS_DEBUG_TRACE
1396 DWORD gle = GetLastError();
1398 AFSDbgPrint( L"NPGetConnection Failed to get connection from file system for local %s gle 0x%x\n",
1401 try_return( dwStatus = WN_NOT_CONNECTED);
1405 // IOCTL_AFS_GET_CONNECTION returns a counted string
1408 if( lpRemoteName == NULL ||
1409 *lpBufferSize + sizeof( WCHAR) > dwPassedSize)
1412 *lpBufferSize += sizeof( WCHAR);
1414 try_return( dwStatus = WN_MORE_DATA);
1417 memcpy( lpRemoteName,
1421 lpRemoteName[ *lpBufferSize/sizeof( WCHAR)] = L'\0';
1423 *lpBufferSize += sizeof( WCHAR);
1425 #ifdef AFS_DEBUG_TRACE
1426 AFSDbgPrint( L"NPGetConnection local %s remote %s\n",
1430 dwStatus = WN_SUCCESS;
1434 if ( hControlDevice != NULL)
1437 CloseHandle( hControlDevice);
1440 if( pConnectCB != NULL)
1443 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1452 NPGetConnection3( IN LPCWSTR lpLocalName,
1454 OUT LPVOID lpBuffer,
1455 IN OUT LPDWORD lpBufferSize)
1458 DWORD dwStatus = WN_NOT_CONNECTED;
1459 WCHAR wchLocalName[3];
1460 WCHAR wchSubstName[MAX_PATH + 1];
1461 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
1463 DWORD dwBufferSize = 0;
1464 HANDLE hControlDevice = NULL;
1466 DWORD *pConnectState =(DWORD *)lpBuffer;
1471 if ( NPIsFSDisabled())
1474 #ifdef AFS_DEBUG_TRACE
1475 AFSDbgPrint( L"NPGetConnection3 AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
1478 try_return( dwStatus = WN_NOT_CONNECTED);
1481 if( lstrlen( lpLocalName) == 0)
1483 #ifdef AFS_DEBUG_TRACE
1484 AFSDbgPrint( L"NPGetConnection3 No local name, returning WN_BAD_LOCALNAME\n");
1486 try_return( dwStatus = WN_BAD_LOCALNAME);
1490 // LanMan NPGetConnection3 only responds to level 1
1493 if ( dwLevel != 0x1)
1495 #ifdef AFS_DEBUG_TRACE
1496 AFSDbgPrint( L"NPGetConnection3 Level 0x%X returning WN_BAD_LEVEL\n", dwLevel);
1498 try_return( dwStatus = WN_BAD_LEVEL);
1501 if ( lpBufferSize == NULL)
1503 #ifdef AFS_DEBUG_TRACE
1504 AFSDbgPrint( L"NPGetConnection3 No output size, returning WN_BAD_VALUE\n");
1506 try_return( dwStatus = WN_BAD_VALUE);
1509 dwPassedSize = *lpBufferSize;
1511 if ( dwPassedSize == 0 ||
1515 *lpBufferSize = sizeof( DWORD);
1517 try_return( dwStatus = WN_MORE_DATA);
1520 if ( !DriveSubstitution( lpLocalName, wchSubstName, sizeof( wchSubstName)))
1522 wchLocalName[0] = towupper(lpLocalName[0]);
1523 wchLocalName[1] = L':';
1524 wchLocalName[2] = L'\0';
1526 #ifdef AFS_DEBUG_TRACE
1527 AFSDbgPrint( L"NPGetConnection3 Requesting connection for %s level 0x%X\n",
1535 ReadServerNameString();
1537 if ( wchSubstName[0] != L'\\' &&
1538 wchSubstName[1] == L':')
1541 wchLocalName[0] = towupper(wchSubstName[0]);
1542 wchLocalName[1] = L':';
1543 wchLocalName[2] = L'\0';
1545 #ifdef AFS_DEBUG_TRACE
1546 AFSDbgPrint( L"NPGetConnection3 Requesting connection for drive substitution %s -> %s level 0x%x\n",
1552 else if ( _wcsnicmp( wchSubstName, wszServerNameUNC, cbServerNameUNCLength / sizeof( WCHAR)) == 0 &&
1553 ( wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == L'\\' ||
1554 wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == 0))
1557 #ifdef AFS_DEBUG_TRACE
1558 AFSDbgPrint( L"NPGetConnection3 drive substitution %s is AFS return connected\n",
1561 *pConnectState = WNGETCON_CONNECTED;
1563 *lpBufferSize = sizeof( DWORD);
1565 try_return( dwStatus = WN_SUCCESS);
1570 #ifdef AFS_DEBUG_TRACE
1571 AFSDbgPrint( L"NPGetConnection3 drive substitution %s is not AFS return not connected\n",
1574 try_return( dwStatus = WN_NOT_CONNECTED);
1578 dwBufferSize = 0x1000;
1580 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
1582 if( pConnectCB == NULL)
1585 try_return( dwStatus = WN_OUT_OF_MEMORY);
1588 pConnectCB->LocalName = towupper(wchLocalName[0]);
1590 pConnectCB->RemoteNameLength = 0;
1592 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
1594 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
1596 #ifdef AFS_DEBUG_TRACE
1597 AFSDbgPrint( L"NPGetConnection3 Retrieved authentication id %08lX-%08lX\n",
1598 pConnectCB->AuthenticationId.HighPart,
1599 pConnectCB->AuthenticationId.LowPart);
1602 hControlDevice = OpenRedirector();
1604 if( hControlDevice == NULL)
1607 #ifdef AFS_DEBUG_TRACE
1608 AFSDbgPrint( L"NPGetConnection3 OpenRedirector failure, returning WN_NET_ERROR\n");
1611 try_return( dwStatus = WN_NET_ERROR);
1614 dwError = DeviceIoControl( hControlDevice,
1615 IOCTL_AFS_GET_CONNECTION,
1625 #ifdef AFS_DEBUG_TRACE
1626 DWORD gle = GetLastError();
1628 AFSDbgPrint( L"NPGetConnection3 Failed to get connection from file system for local %s gle 0x%x\n",
1631 try_return( dwStatus = WN_NOT_CONNECTED);
1634 *lpBufferSize = sizeof( DWORD);
1636 if( sizeof( DWORD) > dwPassedSize)
1639 try_return( dwStatus = WN_MORE_DATA);
1642 *pConnectState = WNGETCON_CONNECTED;
1644 #ifdef AFS_DEBUG_TRACE
1645 AFSDbgPrint( L"NPGetConnection3 local %s connect-state 0x%x\n",
1649 dwStatus = WN_SUCCESS;
1653 if ( hControlDevice != NULL)
1656 CloseHandle( hControlDevice);
1659 if( pConnectCB != NULL)
1662 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1671 NPGetConnectionPerformance( LPCWSTR lpRemoteName,
1672 LPNETCONNECTINFOSTRUCT lpNetConnectInfo)
1675 DWORD dwReturn = WN_SUCCESS;
1676 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
1677 DWORD dwBufferSize = 0;
1678 HANDLE hControlDevice = NULL;
1684 if ( NPIsFSDisabled())
1687 #ifdef AFS_DEBUG_TRACE
1688 AFSDbgPrint( L"NPGetConnectionPerformance AFSRDFS is disabled, returning WN_BAD_NETNAME\n");
1691 return WN_NO_NETWORK;
1694 AFSDbgPrint( L"NPGetConnectionPerformance Entry for remote connection %S\n",
1697 dwBufferSize = 0x1000;
1699 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
1701 if( pConnectCB == NULL)
1703 try_return( dwReturn = WN_OUT_OF_MEMORY);
1706 pConnectCB->RemoteNameLength = wcslen( lpRemoteName) * sizeof( WCHAR);
1708 StringCbCopy( pConnectCB->RemoteName,
1709 dwBufferSize - sizeof(AFSNetworkProviderConnectionCB),
1712 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
1714 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
1716 hControlDevice = OpenRedirector();
1718 if( hControlDevice == NULL)
1720 AFSDbgPrint( L"NPGetConnectionPerformance OpenRedirector failure, returning WN_NET_ERROR\n");
1722 try_return( dwReturn = WN_NET_ERROR);
1725 dwError = DeviceIoControl( hControlDevice,
1726 IOCTL_AFS_GET_CONNECTION_INFORMATION,
1736 #ifdef AFS_DEBUG_TRACE
1737 DWORD gle = GetLastError();
1739 AFSDbgPrint( L"NPGetConnectionPerformance Failed to get connection info from file system for remote %S gle 0x%x\n",
1743 try_return( dwReturn = WN_NOT_CONNECTED);
1746 lpNetConnectInfo->dwFlags = WNCON_DYNAMIC;
1748 lpNetConnectInfo->dwSpeed = 500;
1750 lpNetConnectInfo->dwDelay = 0;
1752 lpNetConnectInfo->dwOptDataSize = 0x1000;
1754 AFSDbgPrint( L"NPGetConnectionPerformance Successfully returned information for remote connection %S\n",
1759 if ( hControlDevice != NULL)
1761 CloseHandle( hControlDevice);
1764 if( pConnectCB != NULL)
1766 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
1774 GetUsageString( DWORD dwUsage)
1776 static WCHAR Buffer[128] = L"";
1778 // RESOURCEUSAGE_CONNECTABLE 0x00000001
1779 // RESOURCEUSAGE_CONTAINER 0x00000002
1780 // RESOURCEUSAGE_NOLOCALDEVICE 0x00000004
1781 // RESOURCEUSAGE_SIBLING 0x00000008
1782 // RESOURCEUSAGE_ATTACHED 0x00000010
1783 // RESOURCEUSAGE_ALL (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_ATTACHED)
1784 // RESOURCEUSAGE_RESERVED 0x80000000
1789 if ( dwUsage == RESOURCEUSAGE_ALL )
1799 if ( dwUsage & RESOURCEUSAGE_CONNECTABLE )
1801 StringCbCat( Buffer, sizeof(Buffer), L"CONNECTABLE|");
1804 if ( dwUsage & RESOURCEUSAGE_CONTAINER )
1806 StringCbCat( Buffer, sizeof(Buffer), L"CONTAINER|");
1809 if ( dwUsage & RESOURCEUSAGE_NOLOCALDEVICE )
1811 StringCbCat( Buffer, sizeof(Buffer), L"NOLOCALDEVICE|");
1814 if ( dwUsage & RESOURCEUSAGE_SIBLING )
1816 StringCbCat( Buffer, sizeof(Buffer), L"SIBLING|");
1819 if ( dwUsage & RESOURCEUSAGE_ATTACHED )
1821 StringCbCat( Buffer, sizeof(Buffer), L"ATTACHED|");
1824 if ( dwUsage & RESOURCEUSAGE_RESERVED )
1826 StringCbCat( Buffer, sizeof(Buffer), L"RESERVED|");
1829 if ( dwUsage & ~(RESOURCEUSAGE_ALL|RESOURCEUSAGE_NOLOCALDEVICE|RESOURCEUSAGE_SIBLING|RESOURCEUSAGE_RESERVED) )
1831 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
1834 Buffer[lstrlen(Buffer)-1] = L'\0';
1840 GetTypeString( DWORD dwType)
1842 static WCHAR Buffer[128] = L"";
1845 // RESOURCETYPE_ANY 0x00000000
1846 // RESOURCETYPE_DISK 0x00000001
1847 // RESOURCETYPE_PRINT 0x00000002
1848 // RESOURCETYPE_RESERVED 0x00000008
1849 // RESOURCETYPE_UNKNOWN 0xFFFFFFFF
1854 if ( dwType == RESOURCETYPE_ANY )
1859 if ( dwType == RESOURCETYPE_UNKNOWN )
1864 if ( dwType & RESOURCETYPE_DISK )
1866 StringCbCat( Buffer, sizeof(Buffer), L"DISK|");
1869 if ( dwType & RESOURCETYPE_PRINT )
1871 StringCbCat( Buffer, sizeof(Buffer), L"PRINT|");
1874 if ( dwType & RESOURCETYPE_RESERVED )
1876 StringCbCat( Buffer, sizeof(Buffer), L"RESERVED|");
1879 if ( dwType & ~(RESOURCETYPE_DISK|RESOURCETYPE_PRINT|RESOURCETYPE_RESERVED) )
1881 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
1884 Buffer[lstrlen(Buffer)-1] = L'\0';
1890 GetScopeString( DWORD dwScope)
1892 static WCHAR Buffer[128] = L"";
1895 // RESOURCE_CONNECTED 0x00000001
1896 // RESOURCE_GLOBALNET 0x00000002
1897 // RESOURCE_REMEMBERED 0x00000003
1898 // RESOURCE_RECENT 0x00000004
1899 // RESOURCE_CONTEXT 0x00000005
1904 if ( dwScope == RESOURCE_CONNECTED )
1906 StringCbCat( Buffer, sizeof(Buffer), L"CONNECTED|");
1909 if ( dwScope == RESOURCE_GLOBALNET )
1911 StringCbCat( Buffer, sizeof(Buffer), L"GLOBALNET|");
1914 if ( dwScope == RESOURCE_REMEMBERED )
1916 StringCbCat( Buffer, sizeof(Buffer), L"REMEMBERED|");
1919 if ( dwScope == RESOURCE_RECENT )
1921 StringCbCat( Buffer, sizeof(Buffer), L"RECENT|");
1924 if ( dwScope == RESOURCE_CONTEXT )
1926 StringCbCat( Buffer, sizeof(Buffer), L"CONTEXT|");
1929 if ( dwScope & ~(RESOURCE_CONNECTED|RESOURCE_GLOBALNET|RESOURCE_REMEMBERED|RESOURCE_RECENT|RESOURCE_CONTEXT) )
1931 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
1934 Buffer[lstrlen(Buffer)-1] = L'\0';
1940 GetDisplayString( DWORD dwDisplay)
1943 // RESOURCEDISPLAYTYPE_GENERIC 0x00000000
1944 // RESOURCEDISPLAYTYPE_DOMAIN 0x00000001
1945 // RESOURCEDISPLAYTYPE_SERVER 0x00000002
1946 // RESOURCEDISPLAYTYPE_SHARE 0x00000003
1947 // RESOURCEDISPLAYTYPE_FILE 0x00000004
1948 // RESOURCEDISPLAYTYPE_GROUP 0x00000005
1949 // RESOURCEDISPLAYTYPE_NETWORK 0x00000006
1950 // RESOURCEDISPLAYTYPE_ROOT 0x00000007
1951 // RESOURCEDISPLAYTYPE_SHAREADMIN 0x00000008
1952 // RESOURCEDISPLAYTYPE_DIRECTORY 0x00000009
1953 // RESOURCEDISPLAYTYPE_TREE 0x0000000A
1954 // RESOURCEDISPLAYTYPE_NDSCONTAINER 0x0000000B
1957 switch ( dwDisplay ) {
1958 case RESOURCEDISPLAYTYPE_GENERIC:
1960 case RESOURCEDISPLAYTYPE_DOMAIN:
1962 case RESOURCEDISPLAYTYPE_SERVER:
1964 case RESOURCEDISPLAYTYPE_SHARE:
1966 case RESOURCEDISPLAYTYPE_FILE:
1968 case RESOURCEDISPLAYTYPE_GROUP:
1970 case RESOURCEDISPLAYTYPE_NETWORK:
1972 case RESOURCEDISPLAYTYPE_ROOT:
1974 case RESOURCEDISPLAYTYPE_SHAREADMIN:
1975 return L"SHAREADMIN";
1976 case RESOURCEDISPLAYTYPE_DIRECTORY:
1977 return L"DIRECTORY";
1978 case RESOURCEDISPLAYTYPE_TREE:
1980 case RESOURCEDISPLAYTYPE_NDSCONTAINER:
1981 return L"NDSCONTAINER";
1989 NPOpenEnum( DWORD dwScope,
1992 LPNETRESOURCE lpNetResource,
1996 DWORD dwStatus = WN_SUCCESS;
1997 AFSEnumerationCB *pEnumCB = NULL;
1999 #ifdef AFS_DEBUG_TRACE
2000 if ( lpNetResource == NULL)
2002 AFSDbgPrint( L"NPOpenEnum Scope %s Type %s Usage %s NetResource: (Null)\n",
2003 GetScopeString(dwScope), GetTypeString(dwType), GetUsageString(dwUsage));
2007 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",
2008 GetScopeString(dwScope),
2009 GetTypeString(dwType),
2010 GetUsageString(dwUsage),
2012 GetScopeString(lpNetResource->dwScope),
2013 GetTypeString(lpNetResource->dwType),
2014 GetDisplayString(lpNetResource->dwDisplayType),
2015 GetUsageString(lpNetResource->dwUsage),
2016 lpNetResource->lpLocalName,
2017 lpNetResource->lpRemoteName,
2018 lpNetResource->lpComment);
2024 dwUsage = RESOURCEUSAGE_ALL;
2028 if ( dwType == 0 || dwType == RESOURCEUSAGE_ATTACHED)
2030 dwType |= RESOURCETYPE_DISK | RESOURCETYPE_PRINT;
2034 *lphEnum = HeapAlloc( GetProcessHeap( ), HEAP_ZERO_MEMORY, sizeof( AFSEnumerationCB));
2036 if( *lphEnum == NULL)
2039 return WN_OUT_OF_MEMORY;
2042 pEnumCB = (AFSEnumerationCB *)*lphEnum;
2044 pEnumCB->CurrentIndex = 0;
2046 pEnumCB->Type = dwType;
2050 case RESOURCE_CONNECTED:
2053 pEnumCB->Scope = RESOURCE_CONNECTED;
2058 case RESOURCE_CONTEXT:
2061 pEnumCB->Scope = RESOURCE_CONTEXT;
2066 case RESOURCE_GLOBALNET:
2069 if( lpNetResource != NULL &&
2070 lpNetResource->lpRemoteName != NULL)
2073 pEnumCB->RemoteName = (WCHAR *)HeapAlloc( GetProcessHeap( ), HEAP_ZERO_MEMORY, 0x1000);
2075 if( pEnumCB->RemoteName == NULL)
2078 dwStatus = WN_OUT_OF_MEMORY;
2079 HeapFree( GetProcessHeap( ), 0, (PVOID) *lphEnum );
2085 StringCbCopy( pEnumCB->RemoteName,
2087 lpNetResource->lpRemoteName);
2092 pEnumCB->Scope = RESOURCE_GLOBALNET;
2099 #ifdef AFS_DEBUG_TRACE
2100 AFSDbgPrint( L"NPOpenEnum Processing (Scope %s 0x%x) Type %s Usage %s, returning WN_NOT_SUPPORTED\n",
2101 GetScopeString(dwScope), dwScope, GetTypeString(dwType), GetUsageString(dwUsage));
2104 dwStatus = WN_NOT_SUPPORTED;
2105 HeapFree( GetProcessHeap( ), 0, (PVOID) *lphEnum );
2117 NPEnumResource( HANDLE hEnum,
2120 LPDWORD lpBufferSize)
2123 DWORD dwStatus = WN_NO_MORE_ENTRIES; //WN_SUCCESS;
2125 ULONG EntriesCopied;
2126 ULONG EntriesRequested;
2128 LPNETRESOURCE pNetResource;
2130 ULONG SpaceAvailable;
2132 AFSNetworkProviderConnectionCB *pConnectionCB = NULL;
2133 void *pConnectionCBBase = NULL;
2135 UNICODE_STRING uniRemoteName;
2136 HANDLE hControlDevice = NULL;
2137 AFSEnumerationCB *pEnumCB = (AFSEnumerationCB *)hEnum;
2142 if ( lpBufferSize == NULL)
2144 #ifdef AFS_DEBUG_TRACE
2145 AFSDbgPrint( L"NPEnumResource No output size, returning WN_BAD_VALUE\n");
2147 try_return( dwStatus = WN_BAD_VALUE);
2150 ReadProviderNameString();
2152 pNetResource = (LPNETRESOURCE) lpBuffer;
2153 SpaceAvailable = *lpBufferSize;
2154 EntriesRequested = *lpcCount;
2155 *lpcCount = EntriesCopied = 0;
2156 StringZone = (PWCHAR) ((char *)lpBuffer + *lpBufferSize);
2158 #ifdef AFS_DEBUG_TRACE
2159 AFSDbgPrint( L"NPEnumResource Processing Remote name %s Scope %s Type %s Usage %s Index %d SpaceAvailable 0x%lX RequestedEntries %lu\n",
2160 pEnumCB->RemoteName ? pEnumCB->RemoteName : L"(Null)",
2161 GetScopeString(pEnumCB->Scope),
2162 GetTypeString(pEnumCB->Type),
2163 GetUsageString(pEnumCB->Type),
2164 pEnumCB->CurrentIndex,
2169 if ( NPIsFSDisabled())
2172 #ifdef AFS_DEBUG_TRACE
2173 AFSDbgPrint( L"NPEnumResource AFSRDFS is disabled, returning WN_NO_MORE_ENTRIES\n");
2176 try_return( dwStatus = WN_NO_MORE_ENTRIES);
2179 pConnectionCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 0x1000);
2181 if( pConnectionCB == NULL)
2184 #ifdef AFS_DEBUG_TRACE
2185 AFSDbgPrint( L"NPEnumResource Out of Memory\n");
2188 try_return( dwStatus = WN_OUT_OF_MEMORY);
2191 pConnectionCBBase = (void *)pConnectionCB;
2193 hControlDevice = OpenRedirector();
2195 if( hControlDevice == NULL)
2198 #ifdef AFS_DEBUG_TRACE
2199 AFSDbgPrint( L"NPEnumResource OpenRedirector failure, returning WN_NET_ERROR\n");
2202 try_return( dwStatus = WN_NET_ERROR);
2206 // Handle the special cases here
2207 // 0. Provider Network Root
2212 if ( pEnumCB->Scope == RESOURCE_GLOBALNET)
2215 ReadServerNameString();
2217 if ( pEnumCB->CurrentIndex == 0 &&
2218 pEnumCB->RemoteName == NULL)
2221 // Determine the space needed for this entry...
2223 SpaceNeeded = 2 * ( cbProviderNameLength + sizeof( WCHAR));
2225 uniRemoteName.Length = (USHORT)cbProviderNameLength;
2226 uniRemoteName.MaximumLength = uniRemoteName.Length;
2227 uniRemoteName.Buffer = wszProviderName;
2229 if( SpaceNeeded + sizeof( NETRESOURCE) > SpaceAvailable)
2232 *lpBufferSize = SpaceNeeded + sizeof( NETRESOURCE);
2234 #ifdef AFS_DEBUG_TRACE
2235 AFSDbgPrint( L"NPEnumResource Request MORE_DATA for entry %s Len %d\n",
2239 try_return( dwStatus = WN_MORE_DATA);
2242 #ifdef AFS_DEBUG_TRACE
2243 AFSDbgPrint( L"NPEnumResource Processing Entry %wZ\n",
2247 SpaceAvailable -= (SpaceNeeded + sizeof( NETRESOURCE));
2249 pNetResource->dwScope = RESOURCE_GLOBALNET;
2250 pNetResource->dwType = RESOURCETYPE_ANY;
2251 pNetResource->dwDisplayType = RESOURCEDISPLAYTYPE_NETWORK;
2252 pNetResource->dwUsage = RESOURCEUSAGE_CONTAINER | RESOURCEUSAGE_RESERVED;
2254 // setup string area at opposite end of buffer
2255 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2257 pNetResource->lpLocalName = NULL;
2260 pNetResource->lpRemoteName = StringZone;
2262 StringCbCopy( StringZone,
2263 cbProviderNameLength + sizeof( WCHAR),
2266 StringZone += cbProviderNameLength / sizeof(WCHAR) + 1;
2268 pNetResource->lpComment = NULL;
2270 // copy provider name
2271 pNetResource->lpProvider = StringZone;
2272 StringCbCopy( StringZone,
2273 cbProviderNameLength + sizeof( WCHAR),
2276 StringZone += cbProviderNameLength / sizeof( WCHAR) + 1;
2278 #ifdef AFS_DEBUG_TRACE
2279 AFSDbgPrint( L"NPEnumResource Entry (0x%p) Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
2281 GetScopeString(pNetResource->dwScope),
2282 GetTypeString(pNetResource->dwType),
2283 GetDisplayString(pNetResource->dwDisplayType),
2284 GetUsageString(pNetResource->dwUsage),
2285 pNetResource->lpLocalName,
2286 pNetResource->lpRemoteName,
2287 pNetResource->lpComment);
2290 // setup the new end of buffer
2291 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2297 // do not change the index since we did not query the redirector
2298 pEnumCB->CurrentIndex = 0;
2300 // remember that we returned the provider name
2301 pEnumCB->RemoteName = (WCHAR *)HeapAlloc( GetProcessHeap( ), HEAP_ZERO_MEMORY, 0x1000);
2303 if( pEnumCB->RemoteName == NULL)
2306 try_return( dwStatus = WN_OUT_OF_MEMORY);
2311 StringCbCopy( pEnumCB->RemoteName,
2317 if ( pEnumCB->CurrentIndex == 0 &&
2318 lstrlen( pEnumCB->RemoteName) == cbProviderNameLength / sizeof( WCHAR) &&
2319 _wcsnicmp( pEnumCB->RemoteName, wszProviderName, cbProviderNameLength / sizeof( WCHAR)) == 0 &&
2320 EntriesCopied < EntriesRequested)
2324 // After the network provider entry comes the server entry
2327 // Determine the space needed for this entry...
2329 SpaceNeeded = cbProviderNameLength + cbServerNameUNCLength + cbServerCommentLength + 3 * sizeof( WCHAR);
2331 uniRemoteName.Length = (USHORT)cbServerNameUNCLength;
2332 uniRemoteName.MaximumLength = uniRemoteName.Length;
2333 uniRemoteName.Buffer = wszServerNameUNC;
2335 if( SpaceNeeded + sizeof( NETRESOURCE) > SpaceAvailable)
2338 *lpBufferSize = SpaceNeeded + sizeof( NETRESOURCE);
2340 #ifdef AFS_DEBUG_TRACE
2341 AFSDbgPrint( L"NPEnumResource Request MORE_DATA for entry %s Len %d\n",
2345 try_return( dwStatus = WN_MORE_DATA);
2348 #ifdef AFS_DEBUG_TRACE
2349 AFSDbgPrint( L"NPEnumResource Processing Entry %wZ\n",
2353 SpaceAvailable -= (SpaceNeeded + sizeof( NETRESOURCE));
2355 pNetResource->dwScope = 0;
2356 pNetResource->dwType = RESOURCETYPE_ANY;
2357 pNetResource->dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
2358 pNetResource->dwUsage = RESOURCEUSAGE_CONTAINER;
2360 // setup string area at opposite end of buffer
2361 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2363 pNetResource->lpLocalName = NULL;
2366 pNetResource->lpRemoteName = StringZone;
2368 StringCbCopy( StringZone,
2369 cbServerNameUNCLength + sizeof( WCHAR),
2372 StringZone += cbServerNameUNCLength / sizeof(WCHAR) + 1;
2375 pNetResource->lpComment = StringZone;
2377 StringCbCopy( StringZone,
2378 cbServerCommentLength + sizeof( WCHAR),
2381 StringZone += cbServerCommentLength / sizeof( WCHAR) + 1;
2383 // copy provider name
2384 pNetResource->lpProvider = StringZone;
2385 StringCbCopy( StringZone,
2386 cbProviderNameLength + sizeof( WCHAR),
2389 StringZone += cbProviderNameLength / sizeof( WCHAR) + 1;
2391 #ifdef AFS_DEBUG_TRACE
2392 AFSDbgPrint( L"NPEnumResource Entry (0x%p) Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
2394 GetScopeString(pNetResource->dwScope),
2395 GetTypeString(pNetResource->dwType),
2396 GetDisplayString(pNetResource->dwDisplayType),
2397 GetUsageString(pNetResource->dwUsage),
2398 pNetResource->lpLocalName,
2399 pNetResource->lpRemoteName,
2400 pNetResource->lpComment);
2403 // setup the new end of buffer
2404 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2410 // do not update the index because we did not query the redirector
2411 pEnumCB->CurrentIndex = 0;
2413 // remember that we returned the server
2414 StringCbCopy( pEnumCB->RemoteName,
2422 // Setup what we are going to ask for
2425 pConnectionCB->Scope = pEnumCB->Scope;
2427 pConnectionCB->Type = pEnumCB->Type;
2429 pConnectionCB->CurrentIndex = pEnumCB->CurrentIndex;
2431 pConnectionCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
2434 // If this is a RESOURCE_GLOBALNET enumeration then pass down the remote name if
2438 pConnectionCB->RemoteNameLength = 0;
2440 if( pEnumCB->Scope == RESOURCE_GLOBALNET &&
2441 pEnumCB->RemoteName != NULL)
2444 pConnectionCB->RemoteNameLength = wcslen( pEnumCB->RemoteName) * sizeof( WCHAR);
2446 StringCbCopy( pConnectionCB->RemoteName,
2447 (0x1000 - sizeof(AFSNetworkProviderConnectionCB)) + sizeof(WCHAR),
2448 pEnumCB->RemoteName);
2451 pConnectionCB->AuthenticationId = AFSRetrieveAuthId();
2453 #ifdef AFS_DEBUG_TRACE
2454 AFSDbgPrint( L"NPEnumResource Retrieved authentication id %08lX-%08lX\n",
2455 pConnectionCB->AuthenticationId.HighPart,
2456 pConnectionCB->AuthenticationId.LowPart);
2459 dwError = DeviceIoControl( hControlDevice,
2460 IOCTL_AFS_LIST_CONNECTIONS,
2470 #ifdef AFS_DEBUG_TRACE
2471 DWORD gle = GetLastError();
2473 AFSDbgPrint( L"NPEnumResource Failed to list connections from file system - gle 0x%x\n",
2476 try_return( dwStatus = WN_NOT_CONNECTED);
2479 if( dwCopyBytes == 0)
2482 #ifdef AFS_DEBUG_TRACE
2483 AFSDbgPrint( L"NPEnumResource No More Entries\n");
2485 try_return( dwStatus = WN_NO_MORE_ENTRIES);
2488 dwIndex = pEnumCB->CurrentIndex;
2490 while( EntriesCopied < EntriesRequested)
2493 uniRemoteName.Length = (USHORT)pConnectionCB->RemoteNameLength;
2494 uniRemoteName.MaximumLength = uniRemoteName.Length;
2495 uniRemoteName.Buffer = pConnectionCB->RemoteName;
2497 // Determine the space needed for this entry...
2501 if( pConnectionCB->LocalName != 0)
2504 SpaceNeeded += 3 * sizeof(WCHAR); // local name
2507 SpaceNeeded += pConnectionCB->RemoteNameLength + sizeof( WCHAR); // remote name
2509 if( pConnectionCB->CommentLength > 0)
2512 SpaceNeeded += pConnectionCB->CommentLength + sizeof( WCHAR); // comment
2515 SpaceNeeded += cbProviderNameLength + sizeof( WCHAR); // provider name
2517 if( SpaceNeeded + sizeof( NETRESOURCE) > SpaceAvailable)
2520 if (EntriesCopied == 0) {
2522 dwStatus = WN_MORE_DATA;
2524 *lpBufferSize = SpaceNeeded + sizeof( NETRESOURCE);
2526 #ifdef AFS_DEBUG_TRACE
2527 AFSDbgPrint( L"NPEnumResource Request MORE_DATA for entry %s Len %d\n",
2534 #ifdef AFS_DEBUG_TRACE
2535 AFSDbgPrint( L"NPEnumResource Return SUCCESS but more entries Index %d\n",
2539 dwStatus = WN_SUCCESS;
2545 SpaceAvailable -= (SpaceNeeded + sizeof( NETRESOURCE));
2547 pNetResource->dwScope = pConnectionCB->Scope;
2548 pNetResource->dwType = pConnectionCB->Type;
2550 pNetResource->dwDisplayType = pConnectionCB->DisplayType;
2552 if ( pNetResource->dwType == RESOURCETYPE_ANY &&
2553 pNetResource->dwDisplayType == RESOURCEDISPLAYTYPE_SHARE)
2556 pNetResource->dwType = RESOURCETYPE_DISK;
2558 pNetResource->dwUsage = pConnectionCB->Usage;
2560 // setup string area at opposite end of buffer
2561 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2564 if( pConnectionCB->LocalName != 0)
2567 pNetResource->lpLocalName = StringZone;
2568 *StringZone++ = towupper(pConnectionCB->LocalName);
2569 *StringZone++ = L':';
2570 *StringZone++ = L'\0';
2575 pNetResource->lpLocalName = NULL;
2578 #ifdef AFS_DEBUG_TRACE
2579 AFSDbgPrint( L"NPEnumResource Processing Entry %wZ\n",
2584 pNetResource->lpRemoteName = StringZone;
2586 CopyMemory( StringZone,
2587 pConnectionCB->RemoteName,
2588 pConnectionCB->RemoteNameLength);
2590 StringZone += (pConnectionCB->RemoteNameLength / sizeof(WCHAR));
2592 *StringZone++ = L'\0';
2595 if( pConnectionCB->CommentLength > 0)
2598 pNetResource->lpComment = StringZone;
2600 CopyMemory( StringZone,
2601 (void *)((char *)pConnectionCB + pConnectionCB->CommentOffset),
2602 pConnectionCB->CommentLength);
2604 StringZone += (pConnectionCB->CommentLength / sizeof(WCHAR));
2606 *StringZone++ = L'\0';
2611 pNetResource->lpComment = NULL;
2614 // copy provider name
2615 pNetResource->lpProvider = StringZone;
2616 StringCbCopy( StringZone,
2617 cbProviderNameLength + sizeof( WCHAR),
2620 StringZone += (cbProviderNameLength / sizeof( WCHAR) + 1);
2622 #ifdef AFS_DEBUG_TRACE
2623 AFSDbgPrint( L"NPEnumResource Entry (0x%p) Scope %s Type %s Display %s Usage %s Local %s Remote \"%s\" Comment \"%s\"\n",
2625 GetScopeString(pNetResource->dwScope),
2626 GetTypeString(pNetResource->dwType),
2627 GetDisplayString(pNetResource->dwDisplayType),
2628 GetUsageString(pNetResource->dwUsage),
2629 pNetResource->lpLocalName,
2630 pNetResource->lpRemoteName,
2631 pNetResource->lpComment);
2634 // setup the new end of buffer
2635 StringZone = (PWCHAR)( (PBYTE) StringZone - SpaceNeeded);
2643 dwCopyBytes -= FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
2644 pConnectionCB->RemoteNameLength +
2645 pConnectionCB->CommentLength;
2647 if( dwCopyBytes == 0)
2650 dwStatus = WN_SUCCESS;
2655 pConnectionCB = (AFSNetworkProviderConnectionCB *)((char *)pConnectionCB +
2656 FIELD_OFFSET( AFSNetworkProviderConnectionCB, RemoteName) +
2657 pConnectionCB->RemoteNameLength +
2658 pConnectionCB->CommentLength);
2661 *lpcCount = EntriesCopied;
2663 // update entry index
2664 pEnumCB->CurrentIndex = dwIndex;
2666 #ifdef AFS_DEBUG_TRACE
2667 AFSDbgPrint( L"NPEnumResource Completed Count %d Index %d\n",
2674 if ( hControlDevice != NULL)
2677 CloseHandle( hControlDevice);
2680 if( pConnectionCBBase != NULL)
2683 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectionCBBase);
2692 Routine Description:
2694 This routine closes the handle for enumeration of resources.
2698 hEnum - the enumeration handle
2702 WN_SUCCESS if successful, otherwise the appropriate error
2706 The sample only supports the notion of enumerating connected shares
2711 NPCloseEnum( HANDLE hEnum )
2714 AFSEnumerationCB *pEnumCB = (AFSEnumerationCB *)hEnum;
2716 #ifdef AFS_DEBUG_TRACE
2717 AFSDbgPrint( L"NPCloseEnum\n");
2720 if( pEnumCB->RemoteName != NULL)
2723 HeapFree( GetProcessHeap( ), 0, (PVOID) pEnumCB->RemoteName);
2726 HeapFree( GetProcessHeap( ), 0, (PVOID) hEnum );
2732 NPGetResourceParent( LPNETRESOURCE lpNetResource,
2734 LPDWORD lpBufferSize )
2737 DWORD dwStatus = WN_ACCESS_DENIED;
2738 WCHAR *pwchRemoteName = NULL, *pwchSearch = NULL, *pwchSystem = NULL;
2739 LPNETRESOURCE lpOutResource = (LPNETRESOURCE) lpBuffer;
2741 if ( lpNetResource == NULL)
2743 #ifdef AFS_DEBUG_TRACE
2744 AFSDbgPrint( L"NPGetResourceParent NULL NETRESOURCE\n");
2746 return WN_MORE_DATA;
2749 if( lpNetResource->lpRemoteName == NULL)
2751 #ifdef AFS_DEBUG_TRACE
2752 AFSDbgPrint( L"NPGetResourceParent NULL NETRESOURCE\n");
2754 return WN_BAD_NETNAME;
2757 if ( lpNetResource->dwType != 0 &&
2758 lpNetResource->dwType != RESOURCETYPE_DISK)
2760 #ifdef AFS_DEBUG_TRACE
2761 AFSDbgPrint( L"NPGetResourceParent Bad dwType\n");
2763 return WN_BAD_VALUE;
2766 if ( lpBufferSize == NULL )
2769 #ifdef AFS_DEBUG_TRACE
2770 AFSDbgPrint( L"NPGetResourceParent Null lpBufferSize\n");
2772 return WN_BAD_VALUE;
2775 #ifdef AFS_DEBUG_TRACE
2776 AFSDbgPrint( L"NPGetResourceParent For remote name %s\n",
2777 lpNetResource->lpRemoteName);
2780 pwchRemoteName = lpNetResource->lpRemoteName;
2782 pwchSearch = pwchRemoteName + (wcslen( pwchRemoteName) - 1);
2784 while( pwchSearch != pwchRemoteName)
2787 if( *pwchSearch == L'\\')
2790 *pwchSearch = L'\0';
2798 if( pwchSearch != pwchRemoteName)
2801 #ifdef AFS_DEBUG_TRACE
2802 AFSDbgPrint( L"NPGetResourceParent Processing parent %s\n",
2803 lpNetResource->lpRemoteName);
2806 dwStatus = NPGetResourceInformation( lpNetResource,
2813 if ( lpOutResource == NULL ||
2814 *lpBufferSize < sizeof( NETRESOURCE) )
2816 *lpBufferSize = sizeof( NETRESOURCE);
2818 return WN_MORE_DATA;
2821 memset( lpOutResource, 0, sizeof( NETRESOURCE));
2831 NPGetResourceInformation( LPNETRESOURCE lpNetResource,
2833 LPDWORD lpBufferSize,
2834 LPWSTR *lplpSystem )
2837 DWORD dwStatus = WN_NOT_CONNECTED;
2838 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
2840 DWORD dwBufferSize = 0;
2841 HANDLE hControlDevice = NULL;
2842 NETRESOURCE *pNetResource = (NETRESOURCE *)lpBuffer;
2843 PWCHAR pStringZone = NULL;
2844 UNICODE_STRING uniRemoteName;
2845 DWORD ulRequiredLen = 0;
2856 ReadProviderNameString();
2858 if ( NPIsFSDisabled())
2861 #ifdef AFS_DEBUG_TRACE
2862 AFSDbgPrint( L"NPGetResourceInformation AFSRDFS is disabled, returning WN_BAD_NETNAME\n");
2865 try_return( dwStatus = WN_BAD_NETNAME);
2868 if ( lpNetResource == NULL ||
2869 lpBufferSize == NULL )
2872 #ifdef AFS_DEBUG_TRACE
2873 AFSDbgPrint( L"NPGetResourceInformaton Null lpNetResource or lpBufferSize\n");
2875 return WN_BAD_VALUE;
2878 if( lpNetResource->lpRemoteName == NULL)
2880 #ifdef AFS_DEBUG_TRACE
2881 AFSDbgPrint( L"NPGetResourceInformation No resource name\n");
2884 try_return( dwStatus = WN_NOT_CONNECTED);
2887 dwPassedSize = *lpBufferSize;
2889 dwBufferSize = 0x1000;
2891 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
2893 if( pConnectCB == NULL)
2896 try_return( dwStatus = WN_OUT_OF_MEMORY);
2899 pConnectCB->RemoteNameLength = wcslen( lpNetResource->lpRemoteName) * sizeof( WCHAR);
2901 StringCbCopy( pConnectCB->RemoteName,
2902 dwBufferSize - sizeof(AFSNetworkProviderConnectionCB),
2903 lpNetResource->lpRemoteName);
2905 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
2907 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
2909 #ifdef AFS_DEBUG_TRACE
2910 AFSDbgPrint( L"NPGetResourceInformation Retrieved authentication id %08lX-%08lX\n",
2911 pConnectCB->AuthenticationId.HighPart,
2912 pConnectCB->AuthenticationId.LowPart);
2915 hControlDevice = OpenRedirector();
2917 if( hControlDevice == NULL)
2920 #ifdef AFS_DEBUG_TRACE
2921 AFSDbgPrint( L"NPGetResourceInformation OpenRedirector failure, returning WN_NET_ERROR\n");
2924 try_return( dwStatus = WN_NET_ERROR);
2927 dwError = DeviceIoControl( hControlDevice,
2928 IOCTL_AFS_GET_CONNECTION_INFORMATION,
2938 #ifdef AFS_DEBUG_TRACE
2939 DWORD gle = GetLastError();
2941 AFSDbgPrint( L"NPGetResourceInformation Failed to get connection info from file system for local %s gle 0x%x\n",
2942 lpNetResource->lpRemoteName, gle);
2944 try_return( dwStatus = WN_BAD_NETNAME);
2947 uniRemoteName.Length = (USHORT)pConnectCB->RemoteNameLength;
2948 uniRemoteName.MaximumLength = uniRemoteName.Length;
2949 uniRemoteName.Buffer = pConnectCB->RemoteName;
2951 #ifdef AFS_DEBUG_TRACE
2952 AFSDbgPrint( L"NPGetResourceInformation For remote name %wZ Scope %08lX Type %08lX Usage %08lX\n",
2959 // Determine the space needed for this entry...
2961 ulRequiredLen = sizeof( NETRESOURCE);
2963 ulRequiredLen += pConnectCB->RemoteNameLength + sizeof( WCHAR);
2965 ulRequiredLen += pConnectCB->CommentLength + sizeof( WCHAR);
2967 ulRequiredLen += cbProviderNameLength + sizeof( WCHAR);
2969 ulRequiredLen += pConnectCB->RemainingPathLength + sizeof( WCHAR);
2971 if( pNetResource == NULL ||
2972 ulRequiredLen > dwPassedSize)
2975 *lpBufferSize = ulRequiredLen;
2977 try_return( dwStatus = WN_MORE_DATA);
2980 pStringZone = (PWCHAR) ((char *)lpBuffer + sizeof( NETRESOURCE));
2982 pNetResource->dwScope = 0 /* pConnectCB->Scope*/;
2983 pNetResource->dwType = 0 /* pConnectCB->Type */;
2985 pNetResource->dwDisplayType = pConnectCB->DisplayType;
2987 pNetResource->dwUsage = pConnectCB->Usage;
2989 pNetResource->lpLocalName = NULL;
2992 pNetResource->lpRemoteName = pStringZone;
2994 CopyMemory( pStringZone,
2995 pConnectCB->RemoteName,
2996 pConnectCB->RemoteNameLength);
2998 pStringZone += (pConnectCB->RemoteNameLength / sizeof(WCHAR));
3000 *pStringZone++ = L'\0';
3003 pNetResource->lpComment = pStringZone;
3005 CopyMemory( pStringZone,
3006 (void *)((char *)pConnectCB + pConnectCB->CommentOffset),
3007 pConnectCB->CommentLength);
3009 pStringZone += (pConnectCB->CommentLength / sizeof(WCHAR));
3011 *pStringZone++ = L'\0';
3013 // copy remaining path
3014 if (pConnectCB->RemainingPathLength > 0)
3016 *lplpSystem = pStringZone;
3018 CopyMemory( pStringZone,
3019 (void *)((char *)pConnectCB + pConnectCB->RemainingPathOffset),
3020 pConnectCB->RemainingPathLength);
3022 pStringZone += (pConnectCB->RemainingPathLength / sizeof(WCHAR));
3024 *pStringZone++ = L'\0';
3026 #ifdef AFS_DEBUG_TRACE
3027 AFSDbgPrint( L"NPGetResourceInformation For remote name %s returning remaining path %s\n",
3028 pNetResource->lpRemoteName,
3033 // copy provider name
3034 pNetResource->lpProvider = pStringZone;
3036 StringCbCopy( pStringZone,
3037 cbProviderNameLength + sizeof( WCHAR),
3040 pStringZone += (cbProviderNameLength / sizeof( WCHAR) + 1);
3042 *lpBufferSize = ulRequiredLen;
3044 dwStatus = WN_SUCCESS;
3048 if ( hControlDevice != NULL)
3051 CloseHandle( hControlDevice);
3054 if( pConnectCB != NULL)
3057 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
3065 SeparateRemainingPath( WCHAR * lpConnectionName, WCHAR **lppRemainingPath)
3072 // at this point the lpConnectionName contains the full name. We need to
3073 // truncate it to \\server\share and move the remaining path back one position.
3076 for ( pwch = lpConnectionName, dwCount = 0; *pwch; pwch++)
3078 if ( *pwch == L'\\')
3092 // Found the remaining path that must be moved
3095 *lppRemainingPath = pwch + 1;
3102 for ( ; *pwch; pwch++);
3105 // and work backwards moving the string
3106 // and then make sure that there is at least
3107 // a path separator.
3112 for ( ;pwch > *lppRemainingPath; pwch--)
3114 *pwch = *(pwch - 1);
3122 NPGetUniversalName( LPCWSTR lpLocalPath,
3125 LPDWORD lpBufferSize )
3127 DWORD dwStatus = WN_NOT_CONNECTED;
3128 WCHAR wchLocalName[3];
3129 WCHAR wchSubstName[MAX_PATH + 1];
3130 AFSNetworkProviderConnectionCB *pConnectCB = NULL;
3132 DWORD dwBufferSize = 0;
3133 DWORD dwPassedSize = *lpBufferSize;
3134 DWORD dwRemainingLength = *lpBufferSize;
3135 HANDLE hControlDevice = NULL;
3136 DWORD dwLocalPathLength = 0;
3137 DWORD dwRemainingPathLength = 0;
3143 #ifdef AFS_DEBUG_TRACE
3144 AFSDbgPrint( L"NPGetUniversalName local path %s level 0x%X\n",
3145 lpLocalPath ? lpLocalPath : L"(Null)",
3149 if ( NPIsFSDisabled())
3152 #ifdef AFS_DEBUG_TRACE
3153 AFSDbgPrint( L"NPGetUniversalName AFSRDFS is disabled, returning WN_NOT_CONNECTED\n");
3156 try_return( dwStatus = WN_NOT_CONNECTED);
3159 dwLocalPathLength = lstrlen( lpLocalPath);
3161 dwRemainingPathLength = dwLocalPathLength - 2; // no drive letter
3163 if( dwLocalPathLength == 0)
3166 #ifdef AFS_DEBUG_TRACE
3167 AFSDbgPrint( L"NPGetUniversalName AFSRDFS is disabled, returning WN_BAD_LOCALNAME\n");
3170 try_return( dwStatus = WN_BAD_LOCALNAME);
3173 if( lpBuffer == NULL ||
3174 lpBufferSize == NULL)
3176 #ifdef AFS_DEBUG_TRACE
3177 AFSDbgPrint( L"NPGetUniversalName No output buffer or size\n");
3179 try_return( dwStatus = WN_BAD_VALUE);
3182 memset(lpBuffer, 0, dwPassedSize);
3184 if ( !DriveSubstitution( lpLocalPath, wchSubstName, sizeof( wchSubstName)))
3186 wchLocalName[0] = towupper(lpLocalPath[0]);
3187 wchLocalName[1] = L':';
3188 wchLocalName[2] = L'\0';
3190 #ifdef AFS_DEBUG_TRACE
3191 AFSDbgPrint( L"NPGetUniversalName Requesting UNC for %s level 0x%X\n",
3199 ReadServerNameString();
3201 if ( wchSubstName[0] != L'\\' &&
3202 wchSubstName[1] == L':')
3205 wchLocalName[0] = towupper(wchSubstName[0]);
3206 wchLocalName[1] = L':';
3207 wchLocalName[2] = L'\0';
3209 #ifdef AFS_DEBUG_TRACE
3210 AFSDbgPrint( L"NPGetUniversalName Requesting UNC for drive substitution %s -> %s\n",
3215 else if ( _wcsnicmp( wchSubstName, wszServerNameUNC, cbServerNameUNCLength / sizeof( WCHAR)) == 0 &&
3216 ( wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == L'\\' ||
3217 wchSubstName[cbServerNameUNCLength / sizeof( WCHAR)] == 0))
3221 #ifdef AFS_DEBUG_TRACE
3222 AFSDbgPrint( L"NPGetUniversalName drive substitution %s is AFS; Level 0x%x BufferSize 0x%x\n",
3228 dwBufferSize = (wcslen( wchSubstName) + 1) * sizeof( WCHAR);
3230 switch( dwInfoLevel)
3233 case UNIVERSAL_NAME_INFO_LEVEL:
3236 UNIVERSAL_NAME_INFO *pUniversalInfo = (UNIVERSAL_NAME_INFO *)lpBuffer;
3238 *lpBufferSize = sizeof( UNIVERSAL_NAME_INFO) + dwBufferSize;
3240 if( dwPassedSize <= sizeof( UNIVERSAL_NAME_INFO))
3243 #ifdef AFS_DEBUG_TRACE
3244 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO) WN_MORE_DATA\n");
3247 try_return( dwStatus = WN_MORE_DATA);
3250 dwRemainingLength -= sizeof( UNIVERSAL_NAME_INFO);
3252 pUniversalInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( UNIVERSAL_NAME_INFO));
3254 memcpy( pUniversalInfo->lpUniversalName,
3256 min( dwBufferSize, dwRemainingLength));
3258 dwRemainingLength -= min( dwBufferSize, dwRemainingLength);
3260 #ifdef AFS_DEBUG_TRACE
3261 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO_LEVEL) lpBuffer: %p Name: (%p) \"%s\"\n",
3263 pUniversalInfo->lpUniversalName,
3264 pUniversalInfo->lpUniversalName);
3267 if ( dwPassedSize < *lpBufferSize)
3270 try_return( dwStatus = WN_MORE_DATA);
3273 try_return( dwStatus = WN_SUCCESS);
3276 case REMOTE_NAME_INFO_LEVEL:
3279 REMOTE_NAME_INFO *pRemoteInfo = (REMOTE_NAME_INFO *)lpBuffer;
3281 *lpBufferSize = sizeof( REMOTE_NAME_INFO) + 2 * dwBufferSize + sizeof( WCHAR);
3283 if( dwPassedSize <= sizeof( REMOTE_NAME_INFO))
3286 #ifdef AFS_DEBUG_TRACE
3287 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO) WN_MORE_DATA\n");
3290 try_return( dwStatus = WN_MORE_DATA);
3293 dwRemainingLength -= sizeof( REMOTE_NAME_INFO);
3295 pRemoteInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( REMOTE_NAME_INFO));
3297 memcpy( pRemoteInfo->lpUniversalName,
3299 min( dwRemainingLength, dwBufferSize));
3301 dwRemainingLength -= min( dwRemainingLength, dwBufferSize);
3303 #ifdef AFS_DEBUG_TRACE
3304 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) UNI lpBuffer: %p Name: (%p) \"%s\"\n",
3306 pRemoteInfo->lpUniversalName,
3307 pRemoteInfo->lpUniversalName);
3310 if ( dwRemainingLength > dwBufferSize + sizeof( WCHAR))
3312 pRemoteInfo->lpConnectionName = (LPTSTR)((char *)pRemoteInfo->lpUniversalName + dwBufferSize);
3314 memcpy( pRemoteInfo->lpConnectionName,
3316 min( dwRemainingLength, dwBufferSize));
3318 dwRemainingLength -= min( dwRemainingLength, dwBufferSize) - sizeof( WCHAR);
3320 SeparateRemainingPath( pRemoteInfo->lpConnectionName,
3321 &pRemoteInfo->lpRemainingPath);
3324 #ifdef AFS_DEBUG_TRACE
3325 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) CONN lpBuffer: %p Name: (%p) \"%s\"\n",
3327 pRemoteInfo->lpConnectionName,
3328 pRemoteInfo->lpConnectionName ? pRemoteInfo->lpConnectionName : L"(null)");
3330 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) REMAIN lpBuffer: %p Name: (%p) \"%s\"\n",
3332 pRemoteInfo->lpRemainingPath,
3333 pRemoteInfo->lpRemainingPath ? pRemoteInfo->lpRemainingPath : L"(null)");
3336 if ( dwPassedSize < *lpBufferSize)
3339 try_return( dwStatus = WN_MORE_DATA);
3342 try_return( dwStatus = WN_SUCCESS);
3346 #ifdef AFS_DEBUG_TRACE
3347 AFSDbgPrint( L"NPGetUniversalName (UNKNOWN: 0x%X) WN_BAD_VALUE\n",
3350 try_return( dwStatus = WN_BAD_VALUE);
3356 #ifdef AFS_DEBUG_TRACE
3357 AFSDbgPrint( L"NPGetUniversalName drive substitution %s is not AFS\n",
3360 try_return( dwStatus = WN_NOT_CONNECTED);
3364 dwBufferSize = 0x1000;
3366 pConnectCB = (AFSNetworkProviderConnectionCB *)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwBufferSize);
3368 if( pConnectCB == NULL)
3370 try_return( dwStatus = WN_OUT_OF_MEMORY);
3373 pConnectCB->LocalName = towupper(wchLocalName[0]);
3375 pConnectCB->RemoteNameLength = 0;
3377 pConnectCB->Version = AFS_NETWORKPROVIDER_INTERFACE_VERSION_1;
3379 pConnectCB->AuthenticationId = AFSRetrieveAuthId();
3381 #ifdef AFS_DEBUG_TRACE
3382 AFSDbgPrint( L"NPGetUniversalName Retrieved authentication id %08lX-%08lX\n",
3383 pConnectCB->AuthenticationId.HighPart,
3384 pConnectCB->AuthenticationId.LowPart);
3387 hControlDevice = OpenRedirector();
3389 if( hControlDevice == NULL)
3392 try_return( dwStatus = WN_NET_ERROR);
3395 dwError = DeviceIoControl( hControlDevice,
3396 IOCTL_AFS_GET_CONNECTION,
3406 #ifdef AFS_DEBUG_TRACE
3407 DWORD gle = GetLastError();
3409 AFSDbgPrint( L"NPGetUniversalName Failed to get connection from file system for local %s gle 0x%x\n",
3412 try_return( dwStatus = WN_NOT_CONNECTED);
3415 switch( dwInfoLevel)
3418 case UNIVERSAL_NAME_INFO_LEVEL:
3421 UNIVERSAL_NAME_INFO *pUniversalInfo = (UNIVERSAL_NAME_INFO *)lpBuffer;
3423 *lpBufferSize = sizeof( UNIVERSAL_NAME_INFO) + dwBufferSize + sizeof( WCHAR);
3425 *lpBufferSize += dwRemainingPathLength * sizeof( WCHAR);
3427 if( dwPassedSize <= sizeof( UNIVERSAL_NAME_INFO))
3430 #ifdef AFS_DEBUG_TRACE
3431 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO) WN_MORE_DATA\n");
3434 try_return( dwStatus = WN_MORE_DATA);
3437 dwRemainingLength -= sizeof( UNIVERSAL_NAME_INFO);
3439 pUniversalInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( UNIVERSAL_NAME_INFO));
3441 pch = (char *)pUniversalInfo->lpUniversalName;
3445 min( dwBufferSize, dwRemainingLength));
3447 pch += min( dwBufferSize, dwRemainingLength);
3449 dwRemainingLength -= min( dwBufferSize + sizeof(WCHAR), dwRemainingLength);
3453 min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength));
3455 pch += min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength);
3457 dwRemainingLength -= min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength);
3459 #ifdef AFS_DEBUG_TRACE
3460 AFSDbgPrint( L"NPGetUniversalName (UNIVERSAL_NAME_INFO_LEVEL) lpBuffer: %p Name: (%p) \"%s\"\n",
3462 pUniversalInfo->lpUniversalName,
3463 pUniversalInfo->lpUniversalName);
3466 if ( dwPassedSize < *lpBufferSize)
3469 try_return( dwStatus = WN_MORE_DATA);
3472 try_return( dwStatus = WN_SUCCESS);
3475 case REMOTE_NAME_INFO_LEVEL:
3478 REMOTE_NAME_INFO *pRemoteInfo = (REMOTE_NAME_INFO *)lpBuffer;
3480 *lpBufferSize = sizeof( REMOTE_NAME_INFO) + (2 * dwBufferSize + sizeof( WCHAR)) + 2 * sizeof( WCHAR);
3482 *lpBufferSize += 2 * dwRemainingPathLength * sizeof( WCHAR);
3484 if( dwPassedSize <= sizeof( REMOTE_NAME_INFO))
3487 #ifdef AFS_DEBUG_TRACE
3488 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO) WN_MORE_DATA\n");
3491 try_return( dwStatus = WN_MORE_DATA);
3494 dwRemainingLength -= sizeof( REMOTE_NAME_INFO);
3496 pRemoteInfo->lpUniversalName = (LPTSTR)((char *)lpBuffer + sizeof( REMOTE_NAME_INFO));
3498 pch = (char *)pRemoteInfo->lpUniversalName;
3502 min( dwBufferSize, dwRemainingLength));
3504 pch += min( dwBufferSize, dwRemainingLength);
3506 dwRemainingLength -= min( dwBufferSize + sizeof( WCHAR), dwRemainingLength);
3510 min(dwRemainingPathLength * sizeof( WCHAR), dwRemainingLength));
3512 pch += min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3514 dwRemainingLength -= min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3516 #ifdef AFS_DEBUG_TRACE
3517 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) UNI lpBuffer: %p Name: (%p) \"%s\"\n",
3519 pRemoteInfo->lpUniversalName,
3520 pRemoteInfo->lpUniversalName);
3523 if ( dwRemainingLength > dwBufferSize + sizeof( WCHAR))
3525 pRemoteInfo->lpConnectionName = (LPWSTR)pch;
3529 min( dwBufferSize, dwRemainingLength));
3531 pch += min( dwBufferSize + sizeof( WCHAR), dwRemainingLength);
3533 dwRemainingLength -= min( dwBufferSize + sizeof( WCHAR), dwRemainingLength);
3537 if ( dwRemainingLength > dwRemainingPathLength + sizeof( WCHAR))
3539 pRemoteInfo->lpRemainingPath = (LPWSTR)pch;
3543 min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength));
3545 pch += min((dwRemainingPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3547 dwRemainingLength -= min((dwLocalPathLength + 1) * sizeof( WCHAR), dwRemainingLength);
3550 #ifdef AFS_DEBUG_TRACE
3551 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) CONN lpBuffer: %p Name: (%p) \"%s\"\n",
3553 pRemoteInfo->lpConnectionName,
3554 pRemoteInfo->lpConnectionName ? pRemoteInfo->lpConnectionName : L"(null)");
3556 AFSDbgPrint( L"NPGetUniversalName (REMOTE_NAME_INFO_LEVEL) REMAIN lpBuffer: %p Name: (%p) \"%s\"\n",
3558 pRemoteInfo->lpRemainingPath,
3559 pRemoteInfo->lpRemainingPath ? pRemoteInfo->lpRemainingPath : L"(null)");
3562 if ( dwPassedSize < *lpBufferSize)
3565 try_return( dwStatus = WN_MORE_DATA);
3568 try_return( dwStatus = WN_SUCCESS);
3572 #ifdef AFS_DEBUG_TRACE
3573 AFSDbgPrint( L"NPGetUniversalName (UNKNOWN: 0x%X) WN_BAD_VALUE\n",
3576 try_return( dwStatus = WN_BAD_VALUE);
3581 #ifdef AFS_DEBUG_TRACE
3582 AFSDbgPrint( L"NPGetUniversalName BufferSize 0x%X\n",
3585 if ( hControlDevice != NULL)
3588 CloseHandle( hControlDevice);
3591 if( pConnectCB != NULL)
3594 HeapFree( GetProcessHeap( ), 0, (PVOID) pConnectCB);
3603 GetFormatFlags( DWORD dwFlags)
3605 static WCHAR Buffer[128] = L"";
3608 // WNFMT_MULTILINE 0x01
3609 // WNFMT_ABBREVIATED 0x02
3610 // WNFMT_INENUM 0x10
3611 // WNFMT_CONNECTION 0x20
3616 if ( dwFlags & WNFMT_MULTILINE )
3618 StringCbCat( Buffer, sizeof(Buffer), L"MULTILINE|");
3621 if ( dwFlags & WNFMT_INENUM )
3623 StringCbCat( Buffer, sizeof(Buffer), L"ABBREVIATED|");
3626 if ( dwFlags & WNFMT_INENUM )
3628 StringCbCat( Buffer, sizeof(Buffer), L"INENUM|");
3631 if ( dwFlags & WNFMT_CONNECTION )
3633 StringCbCat( Buffer, sizeof(Buffer), L"CONNECTION|");
3636 if ( dwFlags & ~(WNFMT_MULTILINE|WNFMT_ABBREVIATED|WNFMT_INENUM|WNFMT_CONNECTION) )
3638 StringCbCat( Buffer, sizeof(Buffer), L"UNKNOWN|");
3641 Buffer[lstrlen(Buffer)-1] = L'\0';
3647 NPFormatNetworkName( LPTSTR lpRemoteName,
3648 LPTSTR lpFormattedName,
3651 DWORD dwAveCharPerLine)
3654 DWORD dwLen = 0, dwCurrentLen = 0;
3655 LPTSTR pCurrentName = lpRemoteName;
3657 #ifdef AFS_DEBUG_TRACE
3658 AFSDbgPrint( L"NPFormatNetworkName Remote %s Flags %s (0x%x) CharsPerLine %u\n",
3661 GetFormatFlags( dwFlags),
3667 // Walk back in the name until we hit a \
3670 dwLen = wcslen( lpRemoteName);
3672 pCurrentName += (dwLen - 1);
3674 if ( pCurrentName[ 0] != L'\\')
3680 if( pCurrentName[ 0] == L'\\')
3696 if( *lpnLength < dwCurrentLen * sizeof( WCHAR))
3699 *lpnLength = dwCurrentLen * sizeof( WCHAR);
3701 #ifdef AFS_DEBUG_TRACE
3702 AFSDbgPrint( L"NPFormatNetworkName remote name %s WN_MORE_DATA\n",
3706 return WN_MORE_DATA;
3709 StringCbCopy( lpFormattedName,
3713 *lpnLength = dwCurrentLen * sizeof( WCHAR);
3715 #ifdef AFS_DEBUG_TRACE
3716 AFSDbgPrint( L"NPFormatNetworkName remote name %s as %s\n",
3724 /************************************************************
3725 / Unsupported entry points
3726 /************************************************************/
3729 // AuthGroup processing is implemented in src/WINNT/afsd/afslogon.c
3734 LPCWSTR lpAuthentInfoType,
3735 LPVOID lpAuthentInfo,
3736 LPCWSTR lpPreviousAuthentInfoType,
3737 LPVOID lpPreviousAuthentInfo,
3738 LPWSTR lpStationName,
3739 LPVOID StationHandle,
3740 LPWSTR *lpLogonScript)
3743 #ifdef AFS_DEBUG_TRACE
3744 AFSDbgPrint( L"NPLogonNotify, returning WN_NOT_SUPPORTED\n");
3747 return WN_NOT_SUPPORTED;
3751 NPPasswordChangeNotify (
3752 LPCWSTR lpAuthentInfoType,
3753 LPVOID lpAuthentInfo,
3754 LPCWSTR lpPreviousAuthentInfoType,
3755 LPVOID lpPreviousAuthentInfo,
3756 LPWSTR lpStationName,
3757 LPVOID StationHandle,
3758 DWORD dwChangeInfo )
3761 #ifdef AFS_DEBUG_TRACE
3762 AFSDbgPrint( L"NPPasswordChangeNotify, returning WN_NOT_SUPPORTED\n");
3765 SetLastError( WN_NOT_SUPPORTED );
3767 return WN_NOT_SUPPORTED;
3771 NPGetUser( LPTSTR lpName,
3773 LPDWORD lpBufferSize)
3776 DWORD rc = WN_NOT_SUPPORTED;
3778 AFSDbgPrint( L"NPGetUser Entry Name %s\n", lpName);
3786 NPGetReconnectFlags( LPWSTR lpRemoteName,
3787 unsigned char *Parameter2)
3790 DWORD dwStatus = WN_NOT_SUPPORTED;
3792 AFSDbgPrint( L"NPGetReconnectFlags RemoteName %s\n",
3801 I_SystemFocusDialog( VOID)
3804 DWORD dwStatus = WN_NOT_SUPPORTED;
3806 AFSDbgPrint( L"I_SystemFocusDialog\n");
3811 /************************************************************
3812 / END Unsupported entry points
3813 /************************************************************/
3820 HANDLE hControlDevice = NULL;
3821 WCHAR wchError[ 256];
3823 hControlDevice = CreateFile( AFS_SYMLINK_W,
3824 GENERIC_READ | GENERIC_WRITE,
3825 FILE_SHARE_READ | FILE_SHARE_WRITE,
3831 if( hControlDevice == INVALID_HANDLE_VALUE)
3834 hControlDevice = NULL;
3835 #ifdef AFS_DEBUG_TRACE
3836 AFSDbgPrint( L"Failed to open control device error: %d\n",
3842 // only do this if you want network shares to fail to mount
3843 // when the file system is not yet ready
3847 AFSDriverStatusRespCB respCB;
3850 memset( &respCB, '\0', sizeof( AFSDriverStatusRespCB));
3852 if ( !DeviceIoControl( hControlDevice,
3853 IOCTL_AFS_STATUS_REQUEST,
3857 sizeof( AFSDriverStatusRespCB),
3860 dwBytes != sizeof(AFSDriverStatusRespCB) ||
3861 respCB.Status != AFS_DRIVER_STATUS_READY )
3864 CloseHandle( hControlDevice);
3866 hControlDevice = NULL;
3871 return hControlDevice;
3878 LARGE_INTEGER liAuthId = {0,0};
3879 HANDLE hToken = NULL;
3880 TOKEN_STATISTICS stTokenInfo;
3881 DWORD dwCopyBytes = 0;
3883 if ( !OpenThreadToken( GetCurrentThread(),
3885 FALSE, // Impersonation
3888 if( !OpenProcessToken( GetCurrentProcess(),
3893 #ifdef AFS_DEBUG_TRACE
3894 AFSDbgPrint( L"AFSRetrieveAuthId Failed to retrieve Thread and Process tokens 0x%X\n",
3901 #ifdef AFS_DEBUG_TRACE
3902 AFSDbgPrint( L"AFSRetrieveAuthId Retrieved Process Token\n");
3909 #ifdef AFS_DEBUG_TRACE
3910 AFSDbgPrint( L"AFSRetrieveAuthId Retrieved Thread Token\n");
3914 if ( hToken != NULL)
3917 if( !GetTokenInformation( hToken,
3920 sizeof( TOKEN_STATISTICS),
3924 #ifdef AFS_DEBUG_TRACE
3925 AFSDbgPrint( L"AFSRetrieveAuthId Failed to retrieve token information 0x%X\n",
3932 liAuthId.HighPart = stTokenInfo.AuthenticationId.HighPart;
3933 liAuthId.LowPart = stTokenInfo.AuthenticationId.LowPart;
3936 CloseHandle( hToken);
3945 static int init = 0;
3946 static BOOL debug = 0;
3951 if (RegOpenKey (HKEY_LOCAL_MACHINE,
3952 TEXT("SYSTEM\\CurrentControlSet\\Services\\AFSRedirector\\NetworkProvider"), &hk) == 0)
3954 DWORD dwSize = sizeof(BOOL);
3955 DWORD dwType = REG_DWORD;
3956 RegQueryValueEx (hk, TEXT("Debug"), NULL, &dwType, (PBYTE)&debug, &dwSize);
3973 WCHAR wszbuffer[512];
3979 va_start( marker, Format );
3981 StringCbPrintf( wszbuffer, sizeof(wszbuffer), L"[%d-%08X] ",
3987 GetCurrentThreadId());
3989 rc = StringCbVPrintfW( &wszbuffer[ 14], sizeof(wszbuffer) - 14, Format, marker);
3992 OutputDebugString( wszbuffer );
3994 OutputDebugString(L"AFSDbgPrint Failed to create string\n");
3996 return SUCCEEDED(rc) ? 1 : 0;