ServerResponseHelper.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (C) 2014 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
  14. {
  15. public partial class ServerResponseHelper
  16. {
  17. internal static SMBCommand GetCloseResponse(SMBHeader header, CloseRequest request, StateObject state)
  18. {
  19. string openedFilePath = state.GetOpenedFilePath(request.FID);
  20. if (openedFilePath == 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. CloseResponse response = new CloseResponse();
  27. return response;
  28. }
  29. internal static SMBCommand GetFindClose2Request(SMBHeader header, FindClose2Request request, StateObject state)
  30. {
  31. state.ReleaseSearchHandle(request.SearchHandle);
  32. return new FindClose2Response();
  33. }
  34. internal static EchoResponse GetEchoResponse(EchoRequest request, List<SMBCommand> sendQueue)
  35. {
  36. EchoResponse response = new EchoResponse();
  37. response.SequenceNumber = 0;
  38. response.SMBData = request.SMBData;
  39. for (int index = 1; index < request.EchoCount; index++)
  40. {
  41. EchoResponse echo = new EchoResponse();
  42. echo.SequenceNumber = (ushort)index;
  43. echo.SMBData = request.SMBData;
  44. sendQueue.Add(echo);
  45. }
  46. return response;
  47. }
  48. }
  49. }