CloseHelper.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright (C) 2014-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 SMBLibrary.SMB1;
  10. using Utilities;
  11. namespace SMBLibrary.Server.SMB1
  12. {
  13. internal class CloseHelper
  14. {
  15. internal static SMB1Command GetCloseResponse(SMB1Header header, CloseRequest request, ISMBShare share, SMB1ConnectionState state)
  16. {
  17. SMB1Session session = state.GetSession(header.UID);
  18. OpenFileObject openFile = session.GetOpenFileObject(request.FID);
  19. if (openFile == null)
  20. {
  21. state.LogToServer(Severity.Verbose, "Close failed. Invalid FID. (UID: {0}, TID: {1}, FID: {2})", header.UID, header.TID, request.FID);
  22. header.Status = NTStatus.STATUS_SMB_BAD_FID;
  23. return new ErrorResponse(request.CommandName);
  24. }
  25. header.Status = share.FileStore.CloseFile(openFile.Handle);
  26. if (header.Status != NTStatus.STATUS_SUCCESS)
  27. {
  28. state.LogToServer(Severity.Information, "Close: Closing '{0}{1}' failed. NTStatus: {2}. (UID: {3}, TID: {4}, FID: {5})", share.Name, openFile.Path, header.Status, header.UID, header.TID, request.FID);
  29. return new ErrorResponse(request.CommandName);
  30. }
  31. state.LogToServer(Severity.Information, "Close: Closed '{0}{1}'. (UID: {2}, TID: {3}, FID: {4})", share.Name, openFile.Path, header.UID, header.TID, request.FID);
  32. session.RemoveOpenFile(request.FID);
  33. return new CloseResponse();
  34. }
  35. internal static SMB1Command GetFindClose2Response(SMB1Header header, FindClose2Request request, SMB1ConnectionState state)
  36. {
  37. SMB1Session session = state.GetSession(header.UID);
  38. session.RemoveOpenSearch(request.SearchHandle);
  39. return new FindClose2Response();
  40. }
  41. }
  42. }