Browse Source

OpenFileObject: Added FileAccess property

Tal Aloni 7 years ago
parent
commit
b978e0b8cc

+ 11 - 1
SMBLibrary/Server/ConnectionState/OpenFileObject.cs

@@ -16,14 +16,16 @@ namespace SMBLibrary.Server
         private string m_shareName;
         private string m_path;
         private object m_handle;
+        private FileAccess m_fileAccess;
         private DateTime m_openedDT;
 
-        public OpenFileObject(uint treeID, string shareName, string path, object handle)
+        public OpenFileObject(uint treeID, string shareName, string path, object handle, FileAccess fileAccess)
         {
             m_treeID = treeID;
             m_shareName = shareName;
             m_path = path;
             m_handle = handle;
+            m_fileAccess = fileAccess;
             m_openedDT = DateTime.Now;
         }
 
@@ -63,6 +65,14 @@ namespace SMBLibrary.Server
             }
         }
 
+        public FileAccess FileAccess
+        {
+            get
+            {
+                return m_fileAccess;
+            }
+        }
+
         public DateTime OpenedDT
         {
             get

+ 3 - 8
SMBLibrary/Server/ConnectionState/SMB1Session.cs

@@ -88,21 +88,16 @@ namespace SMBLibrary.Server
             return m_connectedTrees.ContainsKey(treeID);
         }
 
-        /// <param name="relativePath">Should include the path relative to the share</param>
+        /// <param name="relativePath">The path relative to the share</param>
         /// <returns>FileID</returns>
-        public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath)
-        {
-            return AddOpenFile(treeID, shareName, relativePath, null);
-        }
-
-        public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath, object handle)
+        public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath, object handle, FileAccess fileAccess)
         {
             lock (m_connection)
             {
                 ushort? fileID = m_connection.AllocateFileID();
                 if (fileID.HasValue)
                 {
-                    m_openFiles.Add(fileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
+                    m_openFiles.Add(fileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle, fileAccess));
                 }
                 return fileID;
             }

+ 2 - 2
SMBLibrary/Server/ConnectionState/SMB2Session.cs

@@ -130,7 +130,7 @@ namespace SMBLibrary.Server
             return null;
         }
 
-        public FileID? AddOpenFile(uint treeID, string shareName, string relativePath, object handle)
+        public FileID? AddOpenFile(uint treeID, string shareName, string relativePath, object handle, FileAccess fileAccess)
         {
             lock (m_openFiles)
             {
@@ -142,7 +142,7 @@ namespace SMBLibrary.Server
                     // [MS-SMB2] FileId.Persistent MUST be set to Open.DurableFileId.
                     // Note: We don't support durable handles so we use volatileFileID.
                     fileID.Persistent = volatileFileID.Value;
-                    m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
+                    m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle, fileAccess));
                     return fileID;
                 }
             }

+ 2 - 1
SMBLibrary/Server/SMB1/NTCreateHelper.cs

@@ -50,7 +50,8 @@ namespace SMBLibrary.Server.SMB1
                 return new ErrorResponse(request.CommandName);
             }
 
-            ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
+            FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess);
+            ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle, fileAccess);
             if (!fileID.HasValue)
             {
                 share.FileStore.CloseFile(handle);

+ 2 - 1
SMBLibrary/Server/SMB1/OpenAndXHelper.cs

@@ -63,7 +63,8 @@ namespace SMBLibrary.Server.SMB1
                 return new ErrorResponse(request.CommandName);
             }
 
-            ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
+            FileAccess fileAccess = ToFileAccess(request.AccessMode.AccessMode);
+            ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle, fileAccess);
             if (!fileID.HasValue)
             {
                 share.FileStore.CloseFile(handle);

+ 2 - 1
SMBLibrary/Server/SMB2/CreateHelper.cs

@@ -44,7 +44,8 @@ namespace SMBLibrary.Server.SMB2
                 return new ErrorResponse(request.CommandName, createStatus);
             }
 
-            FileID? fileID = session.AddOpenFile(request.Header.TreeID, share.Name, path, handle);
+            FileAccess fileAccess = NTFileStoreHelper.ToFileAccess(desiredAccess);
+            FileID? fileID = session.AddOpenFile(request.Header.TreeID, share.Name, path, handle, fileAccess);
             if (fileID == null)
             {
                 share.FileStore.CloseFile(handle);