CloseHelper.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using SMBLibrary.SMB2;
  11. using Utilities;
  12. namespace SMBLibrary.Server.SMB2
  13. {
  14. public class CloseHelper
  15. {
  16. internal static SMB2Command GetCloseResponse(CloseRequest request, ISMBShare share, SMB2ConnectionState state)
  17. {
  18. SMB2Session session = state.GetSession(request.Header.SessionID);
  19. OpenFileObject openFile = session.GetOpenFileObject(request.FileId.Persistent);
  20. if (openFile == null)
  21. {
  22. return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
  23. }
  24. string path = openFile.Path;
  25. session.RemoveOpenFile(request.FileId.Persistent);
  26. CloseResponse response = new CloseResponse();
  27. if (request.PostQueryAttributes)
  28. {
  29. if (share is NamedPipeShare)
  30. {
  31. response.FileAttributes = FileAttributes.Temporary;
  32. }
  33. else // FileSystemShare
  34. {
  35. IFileSystem fileSystem = ((FileSystemShare)share).FileSystem;
  36. FileSystemEntry entry = fileSystem.GetEntry(path);
  37. if (entry != null)
  38. {
  39. response.CreationTime = entry.CreationTime;
  40. response.LastAccessTime = entry.LastAccessTime;
  41. response.LastWriteTime = entry.LastWriteTime;
  42. response.ChangeTime = entry.LastWriteTime;
  43. response.AllocationSize = (long)NTFileSystemHelper.GetAllocationSize(entry.Size);
  44. response.EndofFile = (long)entry.Size;
  45. response.FileAttributes = NTFileSystemHelper.GetFileAttributes(entry);
  46. }
  47. }
  48. }
  49. return response;
  50. }
  51. }
  52. }