Browse Source

SMBServer: Store the share name for each open file

Tal Aloni 7 years ago
parent
commit
4c84a297f8

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

@@ -14,12 +14,14 @@ namespace SMBLibrary.Server
     internal class OpenFileObject
     {
         public uint TreeID;
+        public string ShareName;
         public string Path;
         public object Handle;
 
-        public OpenFileObject(uint treeID, string path, object handle)
+        public OpenFileObject(uint treeID, string shareName, string path, object handle)
         {
             TreeID = treeID;
+            ShareName = shareName;
             Path = path;
             Handle = handle;
         }

+ 4 - 4
SMBLibrary/Server/ConnectionState/SMB1Session.cs

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

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

@@ -129,7 +129,7 @@ namespace SMBLibrary.Server
             return null;
         }
 
-        public FileID? AddOpenFile(uint treeID, string relativePath, object handle)
+        public FileID? AddOpenFile(uint treeID, string shareName, string relativePath, object handle)
         {
             ulong? volatileFileID = AllocateVolatileFileID();
             if (volatileFileID.HasValue)
@@ -141,7 +141,7 @@ namespace SMBLibrary.Server
                 fileID.Persistent = volatileFileID.Value;
                 lock (m_openFiles)
                 {
-                    m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, relativePath, handle));
+                    m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
                 }
                 return fileID;
             }

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

@@ -51,7 +51,7 @@ namespace SMBLibrary.Server.SMB1
             }
 
             state.LogToServer(Severity.Verbose, "Create: Opened '{0}{1}'.", share.Name, path);
-            ushort? fileID = session.AddOpenFile(header.TID, path, handle);
+            ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
             if (!fileID.HasValue)
             {
                 share.FileStore.CloseFile(handle);

+ 2 - 3
SMBLibrary/Server/SMB1/NotifyChangeHelper.cs

@@ -47,11 +47,10 @@ namespace SMBLibrary.Server.SMB1
                 SMB1Session session = connection.GetSession(asyncContext.UID);
                 if (session != null)
                 {
-                    ISMBShare share = session.GetConnectedTree(asyncContext.TID);
                     OpenFileObject openFile = session.GetOpenFileObject(asyncContext.FileID);
-                    if (share != null && openFile != null)
+                    if (openFile != null)
                     {
-                        connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. PID: {3}. MID: {4}.", share.Name, openFile.Path, status, asyncContext.PID, asyncContext.MID);
+                        connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. PID: {3}. MID: {4}.", openFile.ShareName, openFile.Path, status, asyncContext.PID, asyncContext.MID);
                     }
                 }
                 SMB1Header header = new SMB1Header();

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

@@ -64,7 +64,7 @@ namespace SMBLibrary.Server.SMB1
             }
 
             state.LogToServer(Severity.Verbose, "OpenAndX: Opened '{0}{1}'.", share.Name, path);
-            ushort? fileID = session.AddOpenFile(header.TID, path, handle);
+            ushort? fileID = session.AddOpenFile(header.TID, share.Name, path, handle);
             if (!fileID.HasValue)
             {
                 share.FileStore.CloseFile(handle);

+ 2 - 3
SMBLibrary/Server/SMB2/ChangeNotifyHelper.cs

@@ -48,11 +48,10 @@ namespace SMBLibrary.Server.SMB2
                 SMB2Session session = connection.GetSession(asyncContext.SessionID);
                 if (session != null)
                 {
-                    ISMBShare share = session.GetConnectedTree(asyncContext.TreeID);
                     OpenFileObject openFile = session.GetOpenFileObject(asyncContext.FileID);
-                    if (share != null && openFile != null)
+                    if (openFile != null)
                     {
-                        connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. AsyncID: {3}", share.Name, openFile.Path, status, asyncContext.AsyncID);
+                        connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. AsyncID: {3}", openFile.ShareName, openFile.Path, status, asyncContext.AsyncID);
                     }
                 }
 

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

@@ -45,7 +45,7 @@ namespace SMBLibrary.Server.SMB2
             }
 
             state.LogToServer(Severity.Verbose, "Create: Opened '{0}{1}'.", share.Name, path);
-            FileID? fileID = session.AddOpenFile(request.Header.TreeID, path, handle);
+            FileID? fileID = session.AddOpenFile(request.Header.TreeID, share.Name, path, handle);
             if (fileID == null)
             {
                 share.FileStore.CloseFile(handle);