TransactionSubcommandHelper.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.Text;
  10. using SMBLibrary.RPC;
  11. using SMBLibrary.SMB1;
  12. using SMBLibrary.Services;
  13. using Utilities;
  14. namespace SMBLibrary.Server.SMB1
  15. {
  16. public class TransactionSubcommandHelper
  17. {
  18. internal static TransactionTransactNamedPipeResponse GetSubcommandResponse(SMB1Header header, TransactionTransactNamedPipeRequest subcommand, ISMBShare share, SMB1ConnectionState state)
  19. {
  20. SMB1Session session = state.GetSession(header.UID);
  21. OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
  22. if (openFile == null)
  23. {
  24. header.Status = NTStatus.STATUS_INVALID_HANDLE;
  25. return null;
  26. }
  27. int maxOutputLength = UInt16.MaxValue;
  28. byte[] output;
  29. header.Status = share.FileStore.DeviceIOControl(openFile.Handle, (uint)IoControlCode.FSCTL_PIPE_TRANSCEIVE, subcommand.WriteData, out output, maxOutputLength);
  30. if (header.Status != NTStatus.STATUS_SUCCESS)
  31. {
  32. return null;
  33. }
  34. TransactionTransactNamedPipeResponse response = new TransactionTransactNamedPipeResponse();
  35. response.ReadData = output;
  36. return response;
  37. }
  38. }
  39. }