From: pete scott Date: Wed, 24 Sep 2014 17:00:36 +0000 (-0600) Subject: Windows: Remove trailing slash on non-root directories X-Git-Tag: upstream/1.8.0_pre1^2~571 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=3f1465f8da47dc589cf27b1c4168ec0bce0fa5d6;p=packages%2Fo%2Fopenafs.git Windows: Remove trailing slash on non-root directories For the FileNameInformation and FilePhysicalNameInformation queries a trailing slash is required for the \\server\share\ path but is not required for directories below the root. Change-Id: Iabbe7daed4f60ad995c04c70dfb2992af095281e Reviewed-on: http://gerrit.openafs.org/11489 Tested-by: BuildBot Reviewed-by: Jeffrey Altman --- diff --git a/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp b/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp index ffb96c4fe..f2ea3404a 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp @@ -10002,3 +10002,29 @@ try_exit: return ntStatus; } + +BOOLEAN +AFSIsShareName( IN UNICODE_STRING *FileName) +{ + + BOOLEAN bIsShareName = TRUE; + USHORT usIndex = 1; // Skip the first \ + + // + // A share name will be of the form \Share so only a single \ at the beginning + // + + while( usIndex < FileName->Length/sizeof( WCHAR)) + { + + if( FileName->Buffer[ usIndex] == L'\\') + { + bIsShareName = FALSE; + break; + } + + usIndex++; + } + + return bIsShareName; +} \ No newline at end of file diff --git a/src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp b/src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp index 97cdb0cdf..6448dedc4 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp @@ -5263,7 +5263,6 @@ AFSGetFullFileName( IN AFSFcb *Fcb, ULONG ulCopyLength = 0; ULONG cchCopied = 0; BOOLEAN bAddTrailingSlash = FALSE; - BOOLEAN bAddLeadingSlash = FALSE; USHORT usFullNameLength = 0; __Enter @@ -5273,15 +5272,11 @@ AFSGetFullFileName( IN AFSFcb *Fcb, // Add a trailing slash for anything which is of the form \server\share // - if( Ccb->FullFileName.Length == 0 || - Ccb->FullFileName.Buffer[ 0] != L'\\') - { - bAddLeadingSlash = TRUE; - } - - if( Fcb->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY && - Ccb->FullFileName.Length > 0 && - Ccb->FullFileName.Buffer[ (Ccb->FullFileName.Length/sizeof( WCHAR)) - 1] != L'\\') + if( ( Fcb->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY || + Fcb->ObjectInformation->FileType == AFS_FILE_TYPE_MOUNTPOINT) && + Ccb->FullFileName.Length > sizeof( WCHAR) && + Ccb->FullFileName.Buffer[ (Ccb->FullFileName.Length/sizeof( WCHAR)) - 1] != L'\\' && + AFSIsShareName( &Ccb->FullFileName)) { bAddTrailingSlash = TRUE; } @@ -5290,11 +5285,6 @@ AFSGetFullFileName( IN AFSFcb *Fcb, AFSServerName.Length + Ccb->FullFileName.Length; - if( bAddLeadingSlash) - { - usFullNameLength += sizeof( WCHAR); - } - if( bAddTrailingSlash) { usFullNameLength += sizeof( WCHAR); @@ -5334,17 +5324,6 @@ AFSGetFullFileName( IN AFSFcb *Fcb, *RemainingLength -= AFSServerName.Length; cchCopied += AFSServerName.Length/sizeof( WCHAR); - if ( ulCopyLength > 0 && - bAddLeadingSlash) - { - - FileName[ cchCopied] = L'\\'; - - ulCopyLength -= sizeof( WCHAR); - *RemainingLength -= sizeof( WCHAR); - cchCopied++; - } - if( ulCopyLength >= Ccb->FullFileName.Length) { diff --git a/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h b/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h index 38de89625..d81f2884c 100644 --- a/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h +++ b/src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h @@ -1451,6 +1451,9 @@ NTSTATUS AFSRetrieveTargetFileInfo( IN PUNICODE_STRING TargetName, OUT AFSFileInfoCB *FileInfo); +BOOLEAN +AFSIsShareName( IN UNICODE_STRING *FileName); + // // AFSNameArray.cpp Prototypes //