CloseHelper.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. share.FileStore.CloseFile(openFile.Handle);
  25. session.RemoveOpenFile(request.FileId.Persistent);
  26. CloseResponse response = new CloseResponse();
  27. if (request.PostQueryAttributes)
  28. {
  29. FileNetworkOpenInformation fileInfo = NTFileStoreHelper.GetNetworkOpenInformation(share.FileStore, openFile.Path, session.SecurityContext);
  30. if (fileInfo != null)
  31. {
  32. response.CreationTime = fileInfo.CreationTime;
  33. response.LastAccessTime = fileInfo.LastAccessTime;
  34. response.LastWriteTime = fileInfo.LastWriteTime;
  35. response.ChangeTime = fileInfo.ChangeTime;
  36. response.AllocationSize = fileInfo.AllocationSize;
  37. response.EndofFile = fileInfo.EndOfFile;
  38. response.FileAttributes = fileInfo.FileAttributes;
  39. }
  40. }
  41. return response;
  42. }
  43. }
  44. }