Minor refactoring

This commit is contained in:
Tal Aloni 2017-01-19 22:57:46 +02:00
parent 0a6a4fcf44
commit 859e939cff
2 changed files with 26 additions and 28 deletions

View file

@ -14,6 +14,24 @@ namespace SMBLibrary.Server.SMB1
{ {
public partial class SMB1FileSystemHelper public partial class SMB1FileSystemHelper
{ {
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
public static FindInformationList GetFindInformationList(List<FileSystemEntry> entries, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys, int maxLength)
{
FindInformationList result = new FindInformationList();
for (int index = 0; index < entries.Count; index++)
{
FindInformation infoEntry = GetFindInformation(entries[index], informationLevel, isUnicode, returnResumeKeys);
result.Add(infoEntry);
if (result.GetLength(isUnicode) > maxLength)
{
result.RemoveAt(result.Count - 1);
break;
}
}
return result;
}
/// <exception cref="SMBLibrary.UnsupportedInformationLevelException"></exception>
public static FindInformation GetFindInformation(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys) public static FindInformation GetFindInformation(FileSystemEntry entry, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys)
{ {
switch (informationLevel) switch (informationLevel)

View file

@ -29,6 +29,7 @@ namespace SMBLibrary.Server.SMB1
header.Status = searchStatus; header.Status = searchStatus;
return null; return null;
} }
// We ignore SearchAttributes
state.LogToServer(Severity.Verbose, "FindFirst2: Searched for '{0}', found {1} matching entries", fileNamePattern, entries.Count); state.LogToServer(Severity.Verbose, "FindFirst2: Searched for '{0}', found {1} matching entries", fileNamePattern, entries.Count);
// [MS-CIFS] If no matching entries are found, the server SHOULD fail the request with STATUS_NO_SUCH_FILE. // [MS-CIFS] If no matching entries are found, the server SHOULD fail the request with STATUS_NO_SUCH_FILE.
@ -40,18 +41,9 @@ namespace SMBLibrary.Server.SMB1
bool returnResumeKeys = (subcommand.Flags & FindFlags.SMB_FIND_RETURN_RESUME_KEYS) > 0; bool returnResumeKeys = (subcommand.Flags & FindFlags.SMB_FIND_RETURN_RESUME_KEYS) > 0;
int entriesToReturn = Math.Min(subcommand.SearchCount, entries.Count); int entriesToReturn = Math.Min(subcommand.SearchCount, entries.Count);
// We ignore SearchAttributes List<FileSystemEntry> temp = entries.GetRange(0, entriesToReturn);
FindInformationList findInformationList = new FindInformationList(); int maxLength = (int)state.GetMaxDataCount(header.PID).Value;
for (int index = 0; index < entriesToReturn; index++) FindInformationList findInformationList = SMB1FileSystemHelper.GetFindInformationList(temp, subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys, maxLength);
{
FindInformation infoEntry = SMB1FileSystemHelper.GetFindInformation(entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys);
findInformationList.Add(infoEntry);
if (findInformationList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID))
{
findInformationList.RemoveAt(findInformationList.Count - 1);
break;
}
}
int returnCount = findInformationList.Count; int returnCount = findInformationList.Count;
Transaction2FindFirst2Response response = new Transaction2FindFirst2Response(); Transaction2FindFirst2Response response = new Transaction2FindFirst2Response();
response.SetFindInformationList(findInformationList, header.UnicodeFlag); response.SetFindInformationList(findInformationList, header.UnicodeFlag);
@ -88,22 +80,10 @@ namespace SMBLibrary.Server.SMB1
} }
bool returnResumeKeys = (subcommand.Flags & FindFlags.SMB_FIND_RETURN_RESUME_KEYS) > 0; bool returnResumeKeys = (subcommand.Flags & FindFlags.SMB_FIND_RETURN_RESUME_KEYS) > 0;
FindInformationList findInformationList = new FindInformationList(); int maxLength = (int)state.GetMaxDataCount(header.PID).Value;
for (int index = openSearch.EnumerationLocation; index < openSearch.Entries.Count; index++) int maxCount = Math.Min(openSearch.Entries.Count - openSearch.EnumerationLocation, subcommand.SearchCount);
{ List<FileSystemEntry> temp = openSearch.Entries.GetRange(openSearch.EnumerationLocation, maxCount);
FindInformation infoEntry = SMB1FileSystemHelper.GetFindInformation(openSearch.Entries[index], subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys); FindInformationList findInformationList = SMB1FileSystemHelper.GetFindInformationList(temp, subcommand.InformationLevel, header.UnicodeFlag, returnResumeKeys, maxLength);
findInformationList.Add(infoEntry);
if (findInformationList.GetLength(header.UnicodeFlag) > state.GetMaxDataCount(header.PID))
{
findInformationList.RemoveAt(findInformationList.Count - 1);
break;
}
if (findInformationList.Count == subcommand.SearchCount)
{
break;
}
}
int returnCount = findInformationList.Count; int returnCount = findInformationList.Count;
Transaction2FindNext2Response response = new Transaction2FindNext2Response(); Transaction2FindNext2Response response = new Transaction2FindNext2Response();
response.SetFindInformationList(findInformationList, header.UnicodeFlag); response.SetFindInformationList(findInformationList, header.UnicodeFlag);