From 243537f7071a108950d5442a4f9f7ab0747ca080 Mon Sep 17 00:00:00 2001 From: pete scott Date: Thu, 25 Sep 2014 09:01:27 -0600 Subject: [PATCH] Windows: Check for RO and Open Target in rename 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 Reviewed-by: Jeffrey Altman --- src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp b/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp index 020a8c645..c795998a5 100644 --- a/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp +++ b/src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp @@ -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) { -- 2.39.5