CloseHelper.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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.");
  22. header.Status = NTStatus.STATUS_SMB_BAD_FID;
  23. return new ErrorResponse(request.CommandName);
  24. }
  25. state.LogToServer(Severity.Information, "Close: Closing '{0}{1}'", share.Name, openFile.Path);
  26. header.Status = share.FileStore.CloseFile(openFile.Handle);
  27. if (header.Status != NTStatus.STATUS_SUCCESS)
  28. {
  29. return new ErrorResponse(request.CommandName);
  30. }
  31. session.RemoveOpenFile(request.FID);
  32. return new CloseResponse();
  33. }
  34. internal static SMB1Command GetFindClose2Response(SMB1Header header, FindClose2Request request, SMB1ConnectionState state)
  35. {
  36. SMB1Session session = state.GetSession(header.UID);
  37. session.RemoveOpenSearch(request.SearchHandle);
  38. return new FindClose2Response();
  39. }
  40. }
  41. }