TransactionSubcommandHelper.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.Text;
  10. using SMBLibrary.RPC;
  11. using SMBLibrary.SMB1;
  12. using SMBLibrary.Services;
  13. using Utilities;
  14. namespace SMBLibrary.Server
  15. {
  16. public class TransactionSubcommandHelper
  17. {
  18. internal static TransactionTransactNamedPipeResponse GetSubcommandResponse(SMB1Header header, TransactionTransactNamedPipeRequest subcommand, NamedPipeShare share, SMB1ConnectionState state)
  19. {
  20. string openedFilePath = state.GetOpenedFilePath(subcommand.FID);
  21. if (openedFilePath == null)
  22. {
  23. header.Status = NTStatus.STATUS_INVALID_HANDLE;
  24. return null;
  25. }
  26. TransactionTransactNamedPipeResponse response = new TransactionTransactNamedPipeResponse();
  27. RemoteService service = share.GetService(openedFilePath);
  28. if (service != null)
  29. {
  30. RPCPDU rpcRequest = RPCPDU.GetPDU(subcommand.WriteData);
  31. RPCPDU rpcReply = RemoteServiceHelper.GetRPCReply(rpcRequest, service);
  32. response.ReadData = rpcReply.GetBytes();
  33. return response;
  34. }
  35. // This code should not execute unless the request sequence is invalid
  36. header.Status = NTStatus.STATUS_INVALID_SMB;
  37. return null;
  38. }
  39. }
  40. }