Windows: Check for RO and Open Target in rename
authorpete scott <pscott@kerneldrivers.com>
Thu, 25 Sep 2014 15:01:27 +0000 (09:01 -0600)
committerJeffrey Altman <jaltman@your-file-system.com>
Fri, 3 Oct 2014 06:56:50 +0000 (02:56 -0400)
During a file rename operation, check to see if the target file
has the DOS readonly attribute set or has a non-zero reference
count.  If yes, the request must be failed.  The error status
depends upon the state of the pending delete flag.  Either
STATUS_PENDING_DELETE or STATUS_ACCESS_DENIED.

Change-Id: I90fa1ea54176f96ca3052ee2b774b1179642e2ef
Reviewed-on: http://gerrit.openafs.org/11506
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

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

index 020a8c6..c795998 100644 (file)
@@ -2876,6 +2876,50 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( lCount >= 0);
 
+           //
+           // Need to acquire the ObjectInfoLock while checking for the Fcb OpenRefCount so we don't race with
+           // a tear down worker thread on the Fcb
+           //
+
+           AFSAcquireShared( &pTargetDirEntry->ObjectInformation->NonPagedInfo->ObjectInfoLock,
+                             TRUE);
+
+           //
+           // Check there are no current opens on the target
+           //
+
+           if( BooleanFlagOn( pTargetDirEntry->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_READONLY) ||
+               ( pTargetDirEntry->ObjectInformation->Fcb != NULL &&
+                 pTargetDirEntry->ObjectInformation->Fcb->OpenReferenceCount != 0))
+           {
+
+               //
+               // Return the correct error code
+               //
+
+               if( BooleanFlagOn( pTargetDirEntry->Flags, AFS_DIR_ENTRY_PENDING_DELETE))
+               {
+                   ntStatus = STATUS_DELETE_PENDING;
+               }
+               else
+               {
+                   ntStatus = STATUS_ACCESS_DENIED;
+               }
+
+               AFSReleaseResource( &pTargetDirEntry->ObjectInformation->NonPagedInfo->ObjectInfoLock);
+
+               AFSDbgTrace(( AFS_SUBSYSTEM_FILE_PROCESSING,
+                             AFS_TRACE_LEVEL_ERROR,
+                             "AFSSetRenameInfo Attempt to rename %s Target %wZ Status %08lX\n",
+                             BooleanFlagOn( pTargetDirEntry->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_READONLY)?"ReadOnly":"Open",
+                             &pTargetDirEntry->NameInformation.FileName,
+                             ntStatus));
+
+               try_return( ntStatus);
+           }
+
+           AFSReleaseResource( &pTargetDirEntry->ObjectInformation->NonPagedInfo->ObjectInfoLock);
+
             if( !bReplaceIfExists)
             {