mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-14 05:15:03 +02:00
Server: Corrected synchronization of SMB1Session and SMB2Session TreeID and FileID allocation methods
This commit is contained in:
parent
5276088159
commit
7eda93f5da
2 changed files with 38 additions and 34 deletions
|
@ -41,6 +41,8 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
|
||||
public ushort? AddConnectedTree(ISMBShare share)
|
||||
{
|
||||
lock (m_connection)
|
||||
{
|
||||
ushort? treeID = m_connection.AllocateTreeID();
|
||||
if (treeID.HasValue)
|
||||
|
@ -49,6 +51,7 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
return treeID;
|
||||
}
|
||||
}
|
||||
|
||||
public ISMBShare GetConnectedTree(ushort treeID)
|
||||
{
|
||||
|
@ -63,7 +66,7 @@ namespace SMBLibrary.Server
|
|||
m_connectedTrees.TryGetValue(treeID, out share);
|
||||
if (share != null)
|
||||
{
|
||||
lock (m_openFiles)
|
||||
lock (m_connection)
|
||||
{
|
||||
List<ushort> fileIDList = new List<ushort>(m_openFiles.Keys);
|
||||
foreach (ushort fileID in fileIDList)
|
||||
|
@ -75,10 +78,10 @@ namespace SMBLibrary.Server
|
|||
m_openFiles.Remove(fileID);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_connectedTrees.Remove(treeID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTreeConnected(ushort treeID)
|
||||
{
|
||||
|
@ -93,17 +96,17 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
|
||||
public ushort? AddOpenFile(ushort treeID, string shareName, string relativePath, object handle)
|
||||
{
|
||||
lock (m_connection)
|
||||
{
|
||||
ushort? fileID = m_connection.AllocateFileID();
|
||||
if (fileID.HasValue)
|
||||
{
|
||||
lock (m_openFiles)
|
||||
{
|
||||
m_openFiles.Add(fileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
|
||||
}
|
||||
}
|
||||
return fileID;
|
||||
}
|
||||
}
|
||||
|
||||
public OpenFileObject GetOpenFileObject(ushort fileID)
|
||||
{
|
||||
|
@ -114,7 +117,7 @@ namespace SMBLibrary.Server
|
|||
|
||||
public void RemoveOpenFile(ushort fileID)
|
||||
{
|
||||
lock (m_openFiles)
|
||||
lock (m_connection)
|
||||
{
|
||||
m_openFiles.Remove(fileID);
|
||||
}
|
||||
|
@ -123,7 +126,7 @@ namespace SMBLibrary.Server
|
|||
public List<string> ListOpenFiles()
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
lock (m_openFiles)
|
||||
lock (m_connection)
|
||||
{
|
||||
foreach (OpenFileObject openFile in m_openFiles.Values)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
|
||||
public uint? AddConnectedTree(ISMBShare share)
|
||||
{
|
||||
lock (m_connectedTrees)
|
||||
{
|
||||
uint? treeID = AllocateTreeID();
|
||||
if (treeID.HasValue)
|
||||
|
@ -69,17 +71,13 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
return treeID;
|
||||
}
|
||||
}
|
||||
|
||||
public ISMBShare GetConnectedTree(uint treeID)
|
||||
{
|
||||
if (m_connectedTrees.ContainsKey(treeID))
|
||||
{
|
||||
return m_connectedTrees[treeID];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ISMBShare result;
|
||||
m_connectedTrees.TryGetValue(treeID, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void DisconnectTree(uint treeID)
|
||||
|
@ -101,9 +99,12 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
}
|
||||
}
|
||||
lock (m_connectedTrees)
|
||||
{
|
||||
m_connectedTrees.Remove(treeID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsTreeConnected(uint treeID)
|
||||
{
|
||||
|
@ -130,6 +131,8 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
|
||||
public FileID? AddOpenFile(uint treeID, string shareName, string relativePath, object handle)
|
||||
{
|
||||
lock (m_openFiles)
|
||||
{
|
||||
ulong? volatileFileID = AllocateVolatileFileID();
|
||||
if (volatileFileID.HasValue)
|
||||
|
@ -139,12 +142,10 @@ 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;
|
||||
lock (m_openFiles)
|
||||
{
|
||||
m_openFiles.Add(volatileFileID.Value, new OpenFileObject(treeID, shareName, relativePath, handle));
|
||||
}
|
||||
return fileID;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue