CloseHelper.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. internal 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);
  20. if (openFile == null)
  21. {
  22. return new ErrorResponse(request.CommandName, NTStatus.STATUS_FILE_CLOSED);
  23. }
  24. NTStatus closeStatus = share.FileStore.CloseFile(openFile.Handle);
  25. if (closeStatus != NTStatus.STATUS_SUCCESS)
  26. {
  27. return new ErrorResponse(request.CommandName, closeStatus);
  28. }
  29. session.RemoveOpenFile(request.FileId);
  30. CloseResponse response = new CloseResponse();
  31. if (request.PostQueryAttributes)
  32. {
  33. FileNetworkOpenInformation fileInfo = NTFileStoreHelper.GetNetworkOpenInformation(share.FileStore, openFile.Path, session.SecurityContext);
  34. if (fileInfo != null)
  35. {
  36. response.CreationTime = fileInfo.CreationTime;
  37. response.LastAccessTime = fileInfo.LastAccessTime;
  38. response.LastWriteTime = fileInfo.LastWriteTime;
  39. response.ChangeTime = fileInfo.ChangeTime;
  40. response.AllocationSize = fileInfo.AllocationSize;
  41. response.EndofFile = fileInfo.EndOfFile;
  42. response.FileAttributes = fileInfo.FileAttributes;
  43. }
  44. }
  45. return response;
  46. }
  47. }
  48. }