diff --git a/SMBLibrary/Server/Helpers/NTFileSystemHelper.Find.cs b/SMBLibrary/Server/Helpers/NTFileSystemHelper.Find.cs index 6ef0fd2..432308e 100644 --- a/SMBLibrary/Server/Helpers/NTFileSystemHelper.Find.cs +++ b/SMBLibrary/Server/Helpers/NTFileSystemHelper.Find.cs @@ -13,34 +13,8 @@ namespace SMBLibrary.Server { public partial class NTFileSystemHelper { - // Filename pattern examples: - // '\Directory' - Get the directory entry - // '\Directory\*' - List the directory files - // '\Directory\s*' - List the directory files starting with s (cmd.exe will use this syntax when entering 's' and hitting tab for autocomplete) - // '\Directory\<.inf' (Update driver will use this syntax) - // '\Directory\exefile"*' (cmd.exe will use this syntax when entering an exe without its extension, explorer will use this opening a directory from the run menu) - /// The filename pattern to search for. This field MAY contain wildcard characters - /// null if the path does not exist - /// - public static NTStatus FindEntries(out List entries, IFileSystem fileSystem, string fileNamePattern) - { - int separatorIndex = fileNamePattern.LastIndexOf('\\'); - if (separatorIndex >= 0) - { - string path = fileNamePattern.Substring(0, separatorIndex + 1); - string expression = fileNamePattern.Substring(separatorIndex + 1); - return FindEntries(out entries, fileSystem, path, expression); - } - else - { - entries = null; - return NTStatus.STATUS_INVALID_PARAMETER; - } - } - - /// Expression as described in [MS-FSA] 2.1.4.4 - /// null if the path does not exist - public static NTStatus FindEntries(out List entries, IFileSystem fileSystem, string path, string expression) + /// Expression as described in [MS-FSA] 2.1.4.4 + public static NTStatus FindEntries(out List entries, IFileSystem fileSystem, string path, string fileName) { entries = null; FileSystemEntry entry = fileSystem.GetEntry(path); @@ -49,12 +23,17 @@ namespace SMBLibrary.Server return NTStatus.STATUS_NO_SUCH_FILE; } - if (expression == String.Empty) + if (!entry.IsDirectory) { return NTStatus.STATUS_INVALID_PARAMETER; } - bool findExactName = !ContainsWildcardCharacters(expression); + if (fileName == String.Empty) + { + return NTStatus.STATUS_INVALID_PARAMETER; + } + + bool findExactName = !ContainsWildcardCharacters(fileName); if (!findExactName) { @@ -68,7 +47,7 @@ namespace SMBLibrary.Server return status; ; } - entries = GetFiltered(entries, expression); + entries = GetFiltered(entries, fileName); // Windows will return "." and ".." when enumerating directory files. // The SMB1 / SMB2 specifications mandate that when zero entries are found, the server SHOULD / MUST return STATUS_NO_SUCH_FILE. @@ -84,7 +63,7 @@ namespace SMBLibrary.Server else { path = FileSystem.GetDirectoryPath(path); - entry = fileSystem.GetEntry(path + expression); + entry = fileSystem.GetEntry(path + fileName); if (entry == null) { return NTStatus.STATUS_NO_SUCH_FILE; diff --git a/SMBLibrary/Server/SMB1/SMB1FileSystemHelper.Find.cs b/SMBLibrary/Server/SMB1/SMB1FileSystemHelper.Find.cs index 3a8e938..9c23ade 100644 --- a/SMBLibrary/Server/SMB1/SMB1FileSystemHelper.Find.cs +++ b/SMBLibrary/Server/SMB1/SMB1FileSystemHelper.Find.cs @@ -14,6 +14,30 @@ namespace SMBLibrary.Server.SMB1 { public partial class SMB1FileSystemHelper { + // Filename pattern examples: + // '\Directory' - Get the directory entry + // '\Directory\*' - List the directory files + // '\Directory\s*' - List the directory files starting with s (cmd.exe will use this syntax when entering 's' and hitting tab for autocomplete) + // '\Directory\<.inf' (Update driver will use this syntax) + // '\Directory\exefile"*' (cmd.exe will use this syntax when entering an exe without its extension, explorer will use this opening a directory from the run menu) + /// The filename pattern to search for. This field MAY contain wildcard characters + /// + public static NTStatus FindEntries(out List entries, IFileSystem fileSystem, string fileNamePattern) + { + int separatorIndex = fileNamePattern.LastIndexOf('\\'); + if (separatorIndex >= 0) + { + string path = fileNamePattern.Substring(0, separatorIndex + 1); + string fileName = fileNamePattern.Substring(separatorIndex + 1); + return NTFileSystemHelper.FindEntries(out entries, fileSystem, path, fileName); + } + else + { + entries = null; + return NTStatus.STATUS_INVALID_PARAMETER; + } + } + /// public static FindInformationList GetFindInformationList(List entries, FindInformationLevel informationLevel, bool isUnicode, bool returnResumeKeys, int maxLength) { diff --git a/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs b/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs index 26d6899..11d9c24 100644 --- a/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs +++ b/SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs @@ -22,7 +22,7 @@ namespace SMBLibrary.Server.SMB1 string fileNamePattern = subcommand.FileName; List entries; - NTStatus searchStatus = NTFileSystemHelper.FindEntries(out entries, fileSystem, fileNamePattern); + NTStatus searchStatus = SMB1FileSystemHelper.FindEntries(out entries, fileSystem, fileNamePattern); if (searchStatus != NTStatus.STATUS_SUCCESS) { state.LogToServer(Severity.Verbose, "FindFirst2: Searched for '{0}', NTStatus: {1}", fileNamePattern, searchStatus.ToString());