Improved SID (search handle) allocation mechanism

This commit is contained in:
Tal Aloni 2017-01-13 11:19:46 +02:00
parent 86c50e45fd
commit b12a340d70
2 changed files with 20 additions and 13 deletions

View file

@ -270,16 +270,23 @@ 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;
}
ushort searchHandle = m_nextSearchHandle;
m_nextSearchHandle++;
if (!OpenSearches.ContainsKey(searchHandle))
{
m_nextSearchHandle = (ushort)(searchHandle + 1);
return searchHandle;
}
}
return null;
}
public void ReleaseSearchHandle(ushort searchHandle)
{

View file

@ -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);
}