/// <summary> /// Deep copy constructor. /// </summary> public SmbIoctlResponsePacket(SmbIoctlResponsePacket packet) : base(packet) { this.InitDefaultValue(); this.smbParameters.WordCount = packet.SmbParameters.WordCount; this.smbParameters.TotalParameterCount = packet.SmbParameters.TotalParameterCount; this.smbParameters.TotalDataCount = packet.SmbParameters.TotalDataCount; this.smbParameters.ParameterCount = packet.SmbParameters.ParameterCount; this.smbParameters.ParameterOffset = packet.SmbParameters.ParameterOffset; this.smbParameters.ParameterDisplacement = packet.SmbParameters.ParameterDisplacement; this.smbParameters.DataCount = packet.SmbParameters.DataCount; this.smbParameters.DataOffset = packet.SmbParameters.DataOffset; this.smbParameters.DataDisplacement = packet.SmbParameters.DataDisplacement; this.smbData.ByteCount = packet.SmbData.ByteCount; if (packet.smbData.Pad1 != null) { this.smbData.Pad1 = new byte[packet.smbData.Pad1.Length]; Array.Copy(packet.smbData.Pad1, this.smbData.Pad1, packet.smbData.Pad1.Length); } else { this.smbData.Pad1 = new byte[0]; } if (packet.smbData.Parameters != null) { this.smbData.Parameters = new byte[packet.smbData.Parameters.Length]; Array.Copy(packet.smbData.Parameters, this.smbData.Parameters, packet.smbData.Parameters.Length); } else { this.smbData.Parameters = new byte[0]; } if (packet.smbData.Pad2 != null) { this.smbData.Pad2 = new byte[packet.smbData.Pad2.Length]; Array.Copy(packet.smbData.Pad2, this.smbData.Pad2, packet.smbData.Pad2.Length); } else { this.smbData.Pad2 = new byte[0]; } if (packet.smbData.Data != null) { this.smbData.Data = new byte[packet.smbData.Data.Length]; Array.Copy(packet.smbData.Data, this.smbData.Data, packet.smbData.Data.Length); } else { this.smbData.Data = new byte[0]; } }
/// <summary> /// server response the IO control request from client. /// </summary> /// <param name="open">the file open between server and client</param> /// <param name="controlCode">The file system control code</param> /// <param name="data">The information about this IO control</param> public override void SendIoControlResponse(IFileServiceServerOpen open, FsCtlCode controlCode, byte[] data) { CifsServerPerConnection connection = open.TreeConnect.Session.Connection as CifsServerPerConnection; foreach (SmbIoctlRequestPacket request in connection.PendingRequestTable) { if (request != null && request.SmbHeader.Uid == open.TreeConnect.Session.SessionId && request.SmbHeader.Tid == open.TreeConnect.TreeConnectId && request.SmbParameters.FID == open.FileId) { SmbIoctlResponsePacket response = this.cifsServer.CreateIoctlResponse(connection, request, null, data); this.cifsServer.SendPacket(response, connection); return; } } }
public SmbIoctlResponsePacket CreateIoctlResponse( CifsServerPerConnection connection, SmbIoctlRequestPacket request, byte[] parameters, byte[] data) { parameters = parameters ?? new byte[0]; data = data ?? new byte[0]; SmbIoctlResponsePacket response = new SmbIoctlResponsePacket(); response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request); int pad1Offset = response.HeaderSize + Marshal.SizeOf(response.SmbParameters) + Marshal.SizeOf(response.SmbData.ByteCount); SMB_COM_IOCTL_Response_SMB_Parameters smbParameters = response.SmbParameters; smbParameters.TotalParameterCount = (ushort)parameters.Length; smbParameters.ParameterCount = (ushort)parameters.Length; smbParameters.TotalDataCount = (ushort)data.Length; smbParameters.DataCount = (ushort)data.Length; smbParameters.ParameterOffset = (ushort)((pad1Offset + 3) & ~3); smbParameters.DataOffset = (ushort)((smbParameters.ParameterOffset + parameters.Length + 3) & ~3); smbParameters.DataDisplacement = 0x0000; smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2); response.SmbParameters = smbParameters; SMB_COM_IOCTL_Response_SMB_Data smbData = response.SmbData; smbData.Pad1 = new byte[response.SmbParameters.ParameterOffset - pad1Offset]; smbData.Parameters = parameters; smbData.Pad2 = new byte[response.SmbParameters.DataOffset - response.SmbParameters.ParameterOffset - parameters.Length]; smbData.Data = data; smbData.ByteCount = (ushort)(response.SmbParameters.DataOffset - pad1Offset + data.Length); response.SmbData = smbData; return response; }