Windows: Retrieve file attributes on symlinks
authorPeter Scott <pscott@kerneldrivers.com>
Wed, 2 Nov 2011 14:23:48 +0000 (10:23 -0400)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Wed, 2 Nov 2011 18:04:50 +0000 (11:04 -0700)
When a component is a symlink, correctly retrieve file
attributes during a query file information request.

FIXES 130283

Change-Id: I0e9a576ca57acf9c65a5dc0eac8c9d65ddf6ab6f
Reviewed-on: http://gerrit.openafs.org/5782
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp

index c08a020..bd98b3e 100644 (file)
@@ -745,6 +745,12 @@ AFSQueryBasicInfo( IN PIRP Irp,
 {
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
+    ULONG ulFileAttribs = 0;
+    AFSCcb *pCcb = NULL;
+    IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
+    AFSFileInfoCB stFileInfo;
+    AFSDirectoryCB *pParentDirectoryCB = NULL;
+    UNICODE_STRING uniParentPath;
 
     if( *Length >= sizeof( FILE_BASIC_INFORMATION))
     {
@@ -752,24 +758,47 @@ AFSQueryBasicInfo( IN PIRP Irp,
         RtlZeroMemory( Buffer,
                        *Length);
 
+        ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
+
+        if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
+        {
+
+            pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
+
+            pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
+
+            AFSRetrieveParentPath( &pCcb->FullFileName,
+                                   &uniParentPath);
+
+            RtlZeroMemory( &stFileInfo,
+                           sizeof( AFSFileInfoCB));
+
+            if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
+                                                       DirectoryCB,
+                                                       &uniParentPath,
+                                                       NULL,
+                                                       &stFileInfo)))
+            {
+                ulFileAttribs = stFileInfo.FileAttributes;
+            }
+        }
+
         Buffer->CreationTime = DirectoryCB->ObjectInformation->CreationTime;
         Buffer->LastAccessTime = DirectoryCB->ObjectInformation->LastAccessTime;
         Buffer->LastWriteTime = DirectoryCB->ObjectInformation->LastWriteTime;
         Buffer->ChangeTime = DirectoryCB->ObjectInformation->ChangeTime;
-        Buffer->FileAttributes = DirectoryCB->ObjectInformation->FileAttributes;
+        Buffer->FileAttributes = ulFileAttribs;
 
         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
-                 BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))
+            BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))
         {
 
             if ( Buffer->FileAttributes != FILE_ATTRIBUTE_NORMAL)
             {
-
                 Buffer->FileAttributes |= FILE_ATTRIBUTE_HIDDEN;
             }
             else
             {
-
                 Buffer->FileAttributes = FILE_ATTRIBUTE_HIDDEN;
             }
         }
@@ -793,9 +822,12 @@ AFSQueryStandardInfo( IN PIRP Irp,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
-    AFSFileInfoCB stFileInformation;
     AFSCcb *pCcb = NULL;
     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
+    AFSFileInfoCB stFileInfo;
+    AFSDirectoryCB *pParentDirectoryCB = NULL;
+    UNICODE_STRING uniParentPath;
+    ULONG ulFileAttribs = 0;
 
     if( *Length >= sizeof( FILE_STANDARD_INFORMATION))
     {
@@ -808,14 +840,36 @@ AFSQueryStandardInfo( IN PIRP Irp,
         Buffer->NumberOfLinks = 1;
         Buffer->DeletePending = BooleanFlagOn( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
 
-        RtlZeroMemory( &stFileInformation,
-                       sizeof( AFSFileInfoCB));
-
         Buffer->AllocationSize.QuadPart = (ULONGLONG)((DirectoryCB->ObjectInformation->AllocationSize.QuadPart/PAGE_SIZE) + 1) * PAGE_SIZE;
 
         Buffer->EndOfFile = DirectoryCB->ObjectInformation->EndOfFile;
 
-        Buffer->Directory = BooleanFlagOn( DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_DIRECTORY);
+        ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
+
+        if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
+        {
+
+            pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
+
+            pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
+
+            AFSRetrieveParentPath( &pCcb->FullFileName,
+                                   &uniParentPath);
+
+            RtlZeroMemory( &stFileInfo,
+                           sizeof( AFSFileInfoCB));
+
+            if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
+                                                       DirectoryCB,
+                                                       &uniParentPath,
+                                                       NULL,
+                                                       &stFileInfo)))
+            {
+                ulFileAttribs = stFileInfo.FileAttributes;
+            }
+        }
+
+        Buffer->Directory = BooleanFlagOn( ulFileAttribs, FILE_ATTRIBUTE_DIRECTORY);
 
         *Length -= sizeof( FILE_STANDARD_INFORMATION);
     }
@@ -1240,6 +1294,12 @@ AFSQueryNetworkInfo( IN PIRP Irp,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
+    AFSCcb *pCcb = NULL;
+    PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
+    AFSFileInfoCB stFileInfo;
+    AFSDirectoryCB *pParentDirectoryCB = NULL;
+    UNICODE_STRING uniParentPath;
+    ULONG ulFileAttribs = 0;
 
     RtlZeroMemory( Buffer,
                    *Length);
@@ -1247,6 +1307,31 @@ AFSQueryNetworkInfo( IN PIRP Irp,
     if( *Length >= sizeof( FILE_NETWORK_OPEN_INFORMATION))
     {
 
+        ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
+
+        if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
+        {
+
+            pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
+
+            pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
+
+            AFSRetrieveParentPath( &pCcb->FullFileName,
+                                   &uniParentPath);
+
+            RtlZeroMemory( &stFileInfo,
+                           sizeof( AFSFileInfoCB));
+
+            if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
+                                                       DirectoryCB,
+                                                       &uniParentPath,
+                                                       NULL,
+                                                       &stFileInfo)))
+            {
+                ulFileAttribs = stFileInfo.FileAttributes;
+            }
+        }
+
         Buffer->CreationTime.QuadPart = DirectoryCB->ObjectInformation->CreationTime.QuadPart;
         Buffer->LastAccessTime.QuadPart = DirectoryCB->ObjectInformation->LastAccessTime.QuadPart;
         Buffer->LastWriteTime.QuadPart = DirectoryCB->ObjectInformation->LastWriteTime.QuadPart;
@@ -1255,7 +1340,7 @@ AFSQueryNetworkInfo( IN PIRP Irp,
         Buffer->AllocationSize.QuadPart = DirectoryCB->ObjectInformation->AllocationSize.QuadPart;
         Buffer->EndOfFile.QuadPart = DirectoryCB->ObjectInformation->EndOfFile.QuadPart;
 
-        Buffer->FileAttributes = DirectoryCB->ObjectInformation->FileAttributes;
+        Buffer->FileAttributes = ulFileAttribs;
 
         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
             BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))
@@ -1364,6 +1449,12 @@ AFSQueryAttribTagInfo( IN PIRP Irp,
     NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
     ULONG ulCopyLength = 0;
     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
+    AFSCcb *pCcb = NULL;
+    PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
+    AFSFileInfoCB stFileInfo;
+    AFSDirectoryCB *pParentDirectoryCB = NULL;
+    UNICODE_STRING uniParentPath;
+    ULONG ulFileAttribs = 0;
 
     if( *Length >= sizeof( FILE_ATTRIBUTE_TAG_INFORMATION))
     {
@@ -1371,7 +1462,32 @@ AFSQueryAttribTagInfo( IN PIRP Irp,
         RtlZeroMemory( Buffer,
                        *Length);
 
-        Buffer->FileAttributes = DirectoryCB->ObjectInformation->FileAttributes;
+        ulFileAttribs = DirectoryCB->ObjectInformation->FileAttributes;
+
+        if( DirectoryCB->ObjectInformation->FileType == AFS_FILE_TYPE_SYMLINK)
+        {
+
+            pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
+
+            pParentDirectoryCB = AFSGetParentEntry( pCcb->NameArray);
+
+            AFSRetrieveParentPath( &pCcb->FullFileName,
+                                   &uniParentPath);
+
+            RtlZeroMemory( &stFileInfo,
+                           sizeof( AFSFileInfoCB));
+
+            if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
+                                                       DirectoryCB,
+                                                       &uniParentPath,
+                                                       NULL,
+                                                       &stFileInfo)))
+            {
+                ulFileAttribs = stFileInfo.FileAttributes;
+            }
+        }
+
+        Buffer->FileAttributes = ulFileAttribs;
 
         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
             BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_HIDE_DOT_NAMES))