ServerResponseHelper.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. internal 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.Information, "Close: Closing '{0}{1}'", share.Name, 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 List<SMB1Command> GetEchoResponse(EchoRequest request)
  42. {
  43. List<SMB1Command> response = new List<SMB1Command>();
  44. for (int index = 0; index < request.EchoCount; index++)
  45. {
  46. EchoResponse echo = new EchoResponse();
  47. echo.SequenceNumber = (ushort)index;
  48. echo.SMBData = request.SMBData;
  49. response.Add(echo);
  50. }
  51. return response;
  52. }
  53. }
  54. }