ServerResponseHelper.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. OpenedFileObject openedFile = state.GetOpenedFileObject(request.FID);
  20. if (openedFile == null)
  21. {
  22. header.Status = NTStatus.STATUS_SMB_BAD_FID;
  23. return new ErrorResponse(CommandName.SMB_COM_CLOSE);
  24. }
  25. state.RemoveOpenedFile(request.FID);
  26. if (openedFile.DeleteOnClose && share is FileSystemShare)
  27. {
  28. try
  29. {
  30. ((FileSystemShare)share).FileSystem.Delete(openedFile.Path);
  31. }
  32. catch
  33. {
  34. System.Diagnostics.Debug.Print("[{0}] Close: Cannot delete '{1}'", DateTime.Now.ToString("HH:mm:ss:ffff"), openedFile.Path);
  35. }
  36. }
  37. CloseResponse response = new CloseResponse();
  38. return response;
  39. }
  40. internal static SMB1Command GetFindClose2Request(SMB1Header header, FindClose2Request request, SMB1ConnectionState state)
  41. {
  42. state.ReleaseSearchHandle(request.SearchHandle);
  43. return new FindClose2Response();
  44. }
  45. internal static EchoResponse GetEchoResponse(EchoRequest request, List<SMB1Command> sendQueue)
  46. {
  47. EchoResponse response = new EchoResponse();
  48. response.SequenceNumber = 0;
  49. response.SMBData = request.SMBData;
  50. for (int index = 1; index < request.EchoCount; index++)
  51. {
  52. EchoResponse echo = new EchoResponse();
  53. echo.SequenceNumber = (ushort)index;
  54. echo.SMBData = request.SMBData;
  55. sendQueue.Add(echo);
  56. }
  57. return response;
  58. }
  59. }
  60. }