Browse Source

SMB1FileStoreHelper: QueryInformation / SetInformation / QueryDirectory: Bugfix: Temporary handle was not closed

Tal Aloni 7 years ago
parent
commit
fd9a845fa2

+ 6 - 4
SMBLibrary/Server/SMB1/SMB1FileStoreHelper.QueryDirectory.cs

@@ -31,13 +31,15 @@ namespace SMBLibrary.Server.SMB1
                 string fileName = fileNamePattern.Substring(separatorIndex + 1);
                 object handle;
                 FileStatus fileStatus;
-                NTStatus createStatus = fileStore.CreateFile(out handle, out fileStatus, path, DirectoryAccessMask.FILE_LIST_DIRECTORY | DirectoryAccessMask.FILE_TRAVERSE, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, securityContext);
-                if (createStatus != NTStatus.STATUS_SUCCESS)
+                NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, DirectoryAccessMask.FILE_LIST_DIRECTORY | DirectoryAccessMask.FILE_TRAVERSE, 0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, securityContext);
+                if (status != NTStatus.STATUS_SUCCESS)
                 {
                     result = null;
-                    return createStatus;
+                    return status;
                 }
-                return fileStore.QueryDirectory(out result, handle, fileName, fileInformation);
+                status = fileStore.QueryDirectory(out result, handle, fileName, fileInformation);
+                fileStore.CloseFile(handle);
+                return status;
             }
             else
             {

+ 7 - 4
SMBLibrary/Server/SMB1/SMB1FileStoreHelper.cs

@@ -111,6 +111,7 @@ namespace SMBLibrary.Server.SMB1
             }
 
             fileInfo = NTFileStoreHelper.GetNetworkOpenInformation(fileStore, handle);
+            fileStore.CloseFile(handle);
             return NTStatus.STATUS_SUCCESS;
         }
 
@@ -118,10 +119,10 @@ namespace SMBLibrary.Server.SMB1
         {
             object handle;
             FileStatus fileStatus;
-            NTStatus openStatus = fileStore.CreateFile(out handle, out fileStatus, path, FileAccessMask.FILE_WRITE_ATTRIBUTES, (FileAttributes)0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
-            if (openStatus != NTStatus.STATUS_SUCCESS)
+            NTStatus status = fileStore.CreateFile(out handle, out fileStatus, path, FileAccessMask.FILE_WRITE_ATTRIBUTES, (FileAttributes)0, ShareAccess.FILE_SHARE_READ | ShareAccess.FILE_SHARE_WRITE, CreateDisposition.FILE_OPEN, 0, securityContext);
+            if (status != NTStatus.STATUS_SUCCESS)
             {
-                return openStatus;
+                return status;
             }
 
             FileBasicInformation basicInfo = new FileBasicInformation();
@@ -142,7 +143,9 @@ namespace SMBLibrary.Server.SMB1
                 basicInfo.FileAttributes |= FileAttributes.Archive;
             }
 
-            return fileStore.SetFileInformation(handle, basicInfo);
+            status = fileStore.SetFileInformation(handle, basicInfo);
+            fileStore.CloseFile(handle);
+            return status;
         }
 
         public static NTStatus SetInformation2(INTFileStore fileStore, object handle, DateTime? creationTime, DateTime? lastAccessTime, DateTime? lastWriteTime)