Better handling of Transaction2SetFileInformation requests

This commit is contained in:
Tal Aloni 2016-12-27 02:39:25 +02:00
parent 0eecde7152
commit 2da05e979b

View file

@ -281,6 +281,8 @@ namespace SMBLibrary.Server
return null; return null;
} }
OpenedFileObject fileObject = state.GetOpenedFileObject(subcommand.FID);
Transaction2SetFileInformationResponse response = new Transaction2SetFileInformationResponse(); Transaction2SetFileInformationResponse response = new Transaction2SetFileInformationResponse();
switch (subcommand.InformationLevel) switch (subcommand.InformationLevel)
{ {
@ -370,8 +372,13 @@ namespace SMBLibrary.Server
return null; return null;
} }
if (fileObject.Stream != null)
{
fileObject.Stream.Close();
}
try try
{ {
System.Diagnostics.Debug.Print("[{0}] NTCreate: Deleting file '{1}'", DateTime.Now.ToString("HH:mm:ss:ffff"), openedFilePath);
share.FileSystem.Delete(openedFilePath); share.FileSystem.Delete(openedFilePath);
} }
catch (IOException) catch (IOException)
@ -395,9 +402,7 @@ namespace SMBLibrary.Server
ulong allocationSize = ((SetFileAllocationInfo)subcommand.SetInfo).AllocationSize; ulong allocationSize = ((SetFileAllocationInfo)subcommand.SetInfo).AllocationSize;
try try
{ {
Stream stream = share.FileSystem.OpenFile(openedFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); fileObject.Stream.SetLength((long)allocationSize);
stream.SetLength((long)allocationSize);
stream.Close();
} }
catch (IOException) catch (IOException)
{ {
@ -414,9 +419,7 @@ namespace SMBLibrary.Server
ulong endOfFile = ((SetFileEndOfFileInfo)subcommand.SetInfo).EndOfFile; ulong endOfFile = ((SetFileEndOfFileInfo)subcommand.SetInfo).EndOfFile;
try try
{ {
Stream stream = share.FileSystem.OpenFile(openedFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); fileObject.Stream.SetLength((long)endOfFile);
stream.SetLength((long)endOfFile);
stream.Close();
} }
catch (IOException) catch (IOException)
{ {