From a160606616cae6e047d97d4e86f075ebe8c2e366 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Fri, 11 May 2012 19:24:54 -0400 Subject: [PATCH] Windows: Permit Media Player to work with mapped drives Windows Media Player was failing to play media files from mapped drives if the mapping was to a directory several levels below \\afs\cellname\. The code to permit SUBST drive letters to work got in the way during NPGetConnection processing. Try to get the connection info without the drive substitution logic. Try again with the drive substitution if the result is no connection present. FIXES 130757 Change-Id: I0c2037d1d8f4c6cf82fbff7d4baee995b5124b39 Reviewed-on: http://gerrit.openafs.org/7402 Tested-by: BuildBot Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/afsrdr/npdll/AFS_Npdll.c | 129 +++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 9 deletions(-) diff --git a/src/WINNT/afsrdr/npdll/AFS_Npdll.c b/src/WINNT/afsrdr/npdll/AFS_Npdll.c index 3915a50411..312e42d838 100644 --- a/src/WINNT/afsrdr/npdll/AFS_Npdll.c +++ b/src/WINNT/afsrdr/npdll/AFS_Npdll.c @@ -78,6 +78,26 @@ NPGetConnectionCommon( LPWSTR lpLocalName, LPDWORD lpBufferSize, BOOL bDriveSubstOk); +static DWORD APIENTRY +NPGetConnection3Common( LPCWSTR lpLocalName, + DWORD dwLevel, + LPVOID lpBuffer, + LPDWORD lpBufferSize, + BOOL bDriveSubstOk); + +static DWORD APIENTRY +NPGetUniversalNameCommon( LPCWSTR lpLocalPath, + DWORD dwInfoLevel, + LPVOID lpBuffer, + LPDWORD lpBufferSize, + BOOL bDriveSubstOk); + +static BOOL +DriveSubstitution( LPCWSTR drivestr, + LPWSTR subststr, + size_t substlen, + DWORD * pStatus); + #define WNNC_DRIVER( major, minor ) ( major * 0x00010000 + minor ) #define OPENAFS_PROVIDER_NAME L"OpenAFS Network" @@ -1240,10 +1260,29 @@ NPGetConnection( LPWSTR lpLocalName, LPDWORD lpBufferSize) { - return NPGetConnectionCommon( lpLocalName, - lpRemoteName, - lpBufferSize, - TRUE); + DWORD dwBufferSize = *lpBufferSize; + DWORD dwStatus; + + dwStatus = NPGetConnectionCommon( lpLocalName, + lpRemoteName, + &dwBufferSize, + FALSE); + + if ( dwStatus == WN_NOT_CONNECTED) + { + + dwStatus = NPGetConnectionCommon( lpLocalName, + lpRemoteName, + lpBufferSize, + TRUE); + } + else + { + + *lpBufferSize = dwBufferSize; + } + + return dwStatus; } DWORD @@ -1529,14 +1568,49 @@ try_exit: return dwStatus; } -DWORD -APIENTRY +DWORD APIENTRY NPGetConnection3( IN LPCWSTR lpLocalName, IN DWORD dwLevel, OUT LPVOID lpBuffer, IN OUT LPDWORD lpBufferSize) { + DWORD dwBufferSize = *lpBufferSize; + DWORD dwStatus; + + dwStatus = NPGetConnection3Common( lpLocalName, + dwLevel, + lpBuffer, + &dwBufferSize, + FALSE); + + if ( dwStatus == WN_NOT_CONNECTED) + { + + dwStatus = NPGetConnection3Common( lpLocalName, + dwLevel, + lpBuffer, + lpBufferSize, + TRUE); + } + else + { + + *lpBufferSize = dwBufferSize; + } + + return dwStatus; +} + + +static DWORD APIENTRY +NPGetConnection3Common( IN LPCWSTR lpLocalName, + IN DWORD dwLevel, + OUT LPVOID lpBuffer, + IN OUT LPDWORD lpBufferSize, + IN BOOL bDriveSubstOk) +{ + DWORD dwStatus = WN_NOT_CONNECTED; WCHAR wchLocalName[3]; WCHAR wchSubstName[1024 + 26]; @@ -1599,7 +1673,8 @@ NPGetConnection3( IN LPCWSTR lpLocalName, try_return( dwStatus = WN_MORE_DATA); } - if ( !DriveSubstitution( lpLocalName, wchSubstName, sizeof( wchSubstName), &dwStatus)) + if ( !bDriveSubstOk || + !DriveSubstitution( lpLocalName, wchSubstName, sizeof( wchSubstName), &dwStatus)) { wchLocalName[0] = towupper(lpLocalName[0]); wchLocalName[1] = L':'; @@ -3223,7 +3298,42 @@ DWORD APIENTRY NPGetUniversalName( LPCWSTR lpLocalPath, DWORD dwInfoLevel, LPVOID lpBuffer, - LPDWORD lpBufferSize ) + LPDWORD lpBufferSize) +{ + + DWORD dwBufferSize = *lpBufferSize; + DWORD dwStatus; + + dwStatus = NPGetUniversalNameCommon( lpLocalPath, + dwInfoLevel, + lpBuffer, + &dwBufferSize, + FALSE); + + if ( dwStatus == WN_NOT_CONNECTED) + { + + dwStatus = NPGetUniversalNameCommon( lpLocalPath, + dwInfoLevel, + lpBuffer, + lpBufferSize, + TRUE); + } + else + { + + *lpBufferSize = dwBufferSize; + } + + return dwStatus; +} + +static DWORD APIENTRY +NPGetUniversalNameCommon( LPCWSTR lpLocalPath, + DWORD dwInfoLevel, + LPVOID lpBuffer, + LPDWORD lpBufferSize, + BOOL bDriveSubstOk) { DWORD dwStatus = WN_NOT_CONNECTED; WCHAR wchLocalName[3]; @@ -3295,7 +3405,8 @@ NPGetUniversalName( LPCWSTR lpLocalPath, memset(lpBuffer, 0, dwPassedSize); - if ( !DriveSubstitution( lpLocalPath, pwchSubstName, dwSubstNameLength, &dwStatus)) + if ( !bDriveSubstOk || + !DriveSubstitution( lpLocalPath, pwchSubstName, dwSubstNameLength, &dwStatus)) { wchLocalName[0] = towupper(lpLocalPath[0]); wchLocalName[1] = L':';