ServerResponseHelper.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 System.IO;
  10. using System.Text;
  11. using SMBLibrary.SMB1;
  12. using Utilities;
  13. namespace SMBLibrary.Server.SMB1
  14. {
  15. public partial class ServerResponseHelper
  16. {
  17. internal static SMB1Command GetCloseResponse(SMB1Header header, CloseRequest request, ISMBShare share, SMB1ConnectionState state)
  18. {
  19. SMB1Session session = state.GetSession(header.UID);
  20. OpenFileObject openFile = session.GetOpenFileObject(request.FID);
  21. if (openFile == null)
  22. {
  23. header.Status = NTStatus.STATUS_SMB_BAD_FID;
  24. return new ErrorResponse(request.CommandName);
  25. }
  26. state.LogToServer(Severity.Verbose, "Close: Closing file '{0}'", openFile.Path);
  27. header.Status = share.FileStore.CloseFile(openFile.Handle);
  28. if (header.Status != NTStatus.STATUS_SUCCESS)
  29. {
  30. return new ErrorResponse(request.CommandName);
  31. }
  32. session.RemoveOpenFile(request.FID);
  33. return new CloseResponse();
  34. }
  35. internal static SMB1Command GetFindClose2Request(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. internal static EchoResponse GetEchoResponse(EchoRequest request, List<SMB1Command> sendQueue)
  42. {
  43. EchoResponse response = new EchoResponse();
  44. response.SequenceNumber = 0;
  45. response.SMBData = request.SMBData;
  46. for (int index = 1; index < request.EchoCount; index++)
  47. {
  48. EchoResponse echo = new EchoResponse();
  49. echo.SequenceNumber = (ushort)index;
  50. echo.SMBData = request.SMBData;
  51. sendQueue.Add(echo);
  52. }
  53. return response;
  54. }
  55. }
  56. }