mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-08-24 16:00:47 +02:00
Improved SID (search handle) allocation mechanism
This commit is contained in:
parent
86c50e45fd
commit
b12a340d70
2 changed files with 20 additions and 13 deletions
|
@ -270,15 +270,22 @@ namespace SMBLibrary.Server
|
|||
}
|
||||
}
|
||||
|
||||
public ushort AllocateSearchHandle()
|
||||
public ushort? AllocateSearchHandle()
|
||||
{
|
||||
while (OpenSearches.ContainsKey(m_nextSearchHandle) || m_nextSearchHandle == 0 || m_nextSearchHandle == 0xFFFF)
|
||||
for (ushort offset = 0; offset < UInt16.MaxValue; offset++)
|
||||
{
|
||||
m_nextSearchHandle++;
|
||||
ushort searchHandle = (ushort)(m_nextSearchHandle + offset);
|
||||
if (searchHandle == 0 || searchHandle == 0xFFFF)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!OpenSearches.ContainsKey(searchHandle))
|
||||
{
|
||||
m_nextSearchHandle = (ushort)(searchHandle + 1);
|
||||
return searchHandle;
|
||||
}
|
||||
}
|
||||
ushort searchHandle = m_nextSearchHandle;
|
||||
m_nextSearchHandle++;
|
||||
return searchHandle;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ReleaseSearchHandle(ushort searchHandle)
|
||||
|
|
|
@ -40,12 +40,6 @@ namespace SMBLibrary.Server.SMB1
|
|||
}
|
||||
bool exactNameWithoutExtension = searchPattern.Contains("\"");
|
||||
|
||||
if (state.OpenSearches.Count > SMB1ConnectionState.MaxSearches)
|
||||
{
|
||||
header.Status = NTStatus.STATUS_OS2_NO_MORE_SIDS;
|
||||
return null;
|
||||
}
|
||||
|
||||
FileSystemEntry entry = fileSystem.GetEntry(path);
|
||||
if (entry == null)
|
||||
{
|
||||
|
@ -128,7 +122,13 @@ namespace SMBLibrary.Server.SMB1
|
|||
}
|
||||
else
|
||||
{
|
||||
response.SID = state.AllocateSearchHandle();
|
||||
ushort? searchHandle = state.AllocateSearchHandle();
|
||||
if (!searchHandle.HasValue)
|
||||
{
|
||||
header.Status = NTStatus.STATUS_OS2_NO_MORE_SIDS;
|
||||
return null;
|
||||
}
|
||||
response.SID = searchHandle.Value;
|
||||
entries.RemoveRange(0, returnCount);
|
||||
state.OpenSearches.Add(response.SID, entries);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue