/// <summary> /// convert the payload of transaction packet from base class format to sub class format, that is /// Cifs to Smb format. /// </summary> /// <param name = "baseClassFormatPayload">the base class format, Cifs format </param> /// <returns>the sub class format, Smb format </returns> internal static SMB_COM_TRANSACTION_Request_SMB_Parameters_Mailslot ConvertTransactionMailslotPacketPayload( SMB_COM_TRANSACTION_Request_SMB_Parameters baseClassFormatPayload) { Smb.SMB_COM_TRANSACTION_Request_SMB_Parameters_Mailslot subClassFormatPayload = new Smb.SMB_COM_TRANSACTION_Request_SMB_Parameters_Mailslot(); subClassFormatPayload.WordCount = baseClassFormatPayload.WordCount; subClassFormatPayload.TotalParameterCount = baseClassFormatPayload.TotalParameterCount; subClassFormatPayload.TotalDataCount = baseClassFormatPayload.TotalDataCount; subClassFormatPayload.MaxParameterCount = baseClassFormatPayload.MaxParameterCount; subClassFormatPayload.MaxDataCount = baseClassFormatPayload.MaxDataCount; subClassFormatPayload.MaxSetupCount = baseClassFormatPayload.MaxSetupCount; subClassFormatPayload.Reserved1 = baseClassFormatPayload.Reserved1; subClassFormatPayload.Flags = baseClassFormatPayload.Flags; subClassFormatPayload.Timeout = baseClassFormatPayload.Timeout; subClassFormatPayload.Reserved2 = baseClassFormatPayload.Reserved2; subClassFormatPayload.ParameterCount = baseClassFormatPayload.ParameterCount; subClassFormatPayload.ParameterOffset = baseClassFormatPayload.ParameterOffset; subClassFormatPayload.DataCount = baseClassFormatPayload.DataCount; subClassFormatPayload.DataOffset = baseClassFormatPayload.DataOffset; subClassFormatPayload.SetupCount = baseClassFormatPayload.SetupCount; subClassFormatPayload.Reserved3 = baseClassFormatPayload.Reserved3; subClassFormatPayload.Subcommand = baseClassFormatPayload.Setup[0]; subClassFormatPayload.Priority = baseClassFormatPayload.Setup[1]; subClassFormatPayload.Class = (SmbTransMailslotClass)baseClassFormatPayload.Setup[2]; return subClassFormatPayload; }
/// <summary> /// Create TransNamedRap request for client to send a rap request to server. /// </summary> /// <param name = "messageId">the id of message, used to identity the request and the server response. </param> /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param> /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param> /// <param name = "flags"> /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. /// </param> /// <param name = "flags2"> /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate /// various client and server capabilities. /// </param> /// <param name = "transactOptions"> /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The /// client MAY set either or both of the following bit flags /// </param> /// <param name="rapOPCode"> /// The operation code for the particular operation. For more information on valid operation codes, see 2.5.4. /// </param> /// <param name="paramDesc"> /// This value MUST be a null-terminated ASCII descriptor string. The server SHOULD validate that the ParamDesc /// value passed by the client matches what is specified by the RAPOpcode. The following table specifies the /// descriptor character and the notation for each data type. /// </param> /// <param name="dataDesc"> /// (Optional) If this value is specified, it MUST be a null-terminated ASCII descriptor string that describes /// the contents of the data returned to the client. Certain RAPOpcodes specify a DataDesc field; for a list /// of Remote Administration Protocol commands that specify a DataDesc field, see section 2.5.5. /// </param> /// <param name="rapParamsAndAuxDesc"> /// This field combines the following fields, because each of their length is unknown:<para/> /// RAPParams: Remote Administration Protocol command-specific parameters, as specified in sections 2.5.5, 2.5.6, 2.5.7, /// 2.5.8, and 2.5.9.<para/> /// AuxDesc: (Optional) If this value is specified, it MUST be a null-terminated ASCII descriptor string that describes /// auxiliary data returned to the client. If no AuxDesc field is specified for the Remote Administration /// Protocol command, this field MUST NOT be present. For the origin of the descriptor string values, see /// section 4.2. /// </param> /// <param name="rapInData"> /// Additional data for the Remote Administration Protocol request. This field MUST be present in the /// NetPrintJobSetInfoRequest command. This field cannot be present in any other command. /// </param> /// <param name = "timeOut"> /// The maximum amount of time in milliseconds to wait for the operation to complete. The client SHOULD set /// this to 0 to indicate that no time-out is given. If the operation does not complete within the specified /// time, the server MAY abort the request and send a failure response. /// </param> /// <returns>a named rap request packet </returns> private SmbTransRapRequestPacket CreateTransNamedRapRequest( ushort messageId, ushort sessionUid, ushort treeId, SmbHeader_Flags_Values flags, SmbHeader_Flags2_Values flags2, TransSmbParametersFlags transactOptions, ushort rapOPCode, byte[] paramDesc, byte[] dataDesc, byte[] rapParamsAndAuxDesc, byte[] rapInData, uint timeOut) { SmbTransRapRequestPacket packet = new SmbTransRapRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TRANSACTION, messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2); // Set Smb Parameters SMB_COM_TRANSACTION_Request_SMB_Parameters smbParameters = new SMB_COM_TRANSACTION_Request_SMB_Parameters(); smbParameters.MaxParameterCount = this.capability.MaxParameterCount; smbParameters.MaxDataCount = this.capability.MaxDataCount; smbParameters.MaxSetupCount = this.capability.MaxSetupCount; smbParameters.Flags = transactOptions; smbParameters.Timeout = timeOut; smbParameters.SetupCount = 0; // the correct count in word of the Setup is always 0. smbParameters.Setup = new ushort[0]; smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION_Request_SMB_Parameters>( smbParameters) / SmbCapability.NUM_BYTES_OF_WORD); // Set Smb Data SMB_COM_TRANSACTION_Request_SMB_Data smbData = new SMB_COM_TRANSACTION_Request_SMB_Data(); smbData.Name = CifsMessageUtils.ToSmbStringBytes("", this.capability.IsUnicode); // Set Transaction Parameters TRANSACTION_Rap_Request_Trans_Parameters transParameters = new TRANSACTION_Rap_Request_Trans_Parameters(); transParameters.RapOPCode = rapOPCode; transParameters.ParamDesc = paramDesc; transParameters.DataDesc = dataDesc; transParameters.RAPParamsAndAuxDesc = rapParamsAndAuxDesc; // Set Transaction Data TRANSACTION_Rap_Request_Trans_Data transData = new TRANSACTION_Rap_Request_Trans_Data(); transData.RAPInData = rapInData; packet.SmbParameters = smbParameters; packet.SmbData = smbData; packet.TransParameters = transParameters; packet.TransData = transData; packet.UpdateCountAndOffset(); // update TransactionSubCommand in SmbGlobalContext, record the transact action this.capability.TransactionSubCommand = TransSubCommandExtended.TRANS_EXT_RAP; return packet; }
/// <summary> /// to decode the smb parameters: from the general SmbParameters to the concrete Smb Parameters. /// </summary> protected override void DecodeParameters() { this.smbParameters = TypeMarshal.ToStruct<SMB_COM_TRANSACTION_Request_SMB_Parameters>( TypeMarshal.ToBytes(this.smbParametersBlock)); }
/// <summary> /// Create TransMailslotWrite request for client to write data to mailslot on server. /// </summary> /// <param name = "messageId">the id of message, used to identity the request and the server response. </param> /// <param name = "sessionUid">the valid session id, must be response by server of the session setup request. </param> /// <param name = "treeId">the valid tree connect id, must be response by server of the tree connect. </param> /// <param name = "flags"> /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. /// </param> /// <param name = "flags2"> /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate /// various client and server capabilities. /// </param> /// <param name = "mailslotName">The name of maislot to write to. </param> /// <param name = "transactOptions"> /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The /// client MAY set either or both of the following bit flags /// </param> /// <param name = "timeOut"> /// The maximum amount of time in milliseconds to wait for the operation to complete. The client SHOULD set /// this to 0 to indicate that no time-out is given. If the operation does not complete within the specified /// time, the server MAY abort the request and send a failure response. /// </param> /// <param name = "writeData">The data to write to mailslot. </param> /// <param name = "priority"> /// This field MUST be in the range of 0 to 9. The larger value being the higher priority. /// </param> /// <param name = "className"> /// The third setup word and the class of the mailslot request. This value MUST be set to one of the following /// values. /// </param> /// <returns>a write mailslot request packet </returns> private SmbTransMailslotWriteRequestPacket CreateTransMailslotWriteRequest( ushort messageId, ushort sessionUid, ushort treeId, SmbHeader_Flags_Values flags, SmbHeader_Flags2_Values flags2, string mailslotName, TransSmbParametersFlags transactOptions, uint timeOut, byte[] writeData, ushort priority, SmbTransMailslotClass className) { if (mailslotName == null) { mailslotName = string.Empty; } SmbTransMailslotWriteRequestPacket packet = new SmbTransMailslotWriteRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TRANSACTION, messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2); // Set Smb Parameters SMB_COM_TRANSACTION_Request_SMB_Parameters smbParameters = new SMB_COM_TRANSACTION_Request_SMB_Parameters(); smbParameters.MaxParameterCount = this.capability.MaxParameterCount; smbParameters.MaxDataCount = this.capability.MaxDataCount; smbParameters.MaxSetupCount = this.capability.MaxSetupCount; smbParameters.Flags = transactOptions; smbParameters.Timeout = timeOut; smbParameters.SetupCount = 3; // the correct count in word of the Setup is always 3. smbParameters.Setup = new ushort[3]; smbParameters.Setup[0] = (ushort)TransSubCommand.TRANS_MAILSLOT_WRITE; smbParameters.Setup[1] = (ushort)priority; smbParameters.Setup[2] = (ushort)className; smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION_Request_SMB_Parameters>( smbParameters) / SmbCapability.NUM_BYTES_OF_WORD); // Set Smb Data SMB_COM_TRANSACTION_Request_SMB_Data smbData = new SMB_COM_TRANSACTION_Request_SMB_Data(); smbData.Name = CifsMessageUtils.ToSmbStringBytes(mailslotName, this.capability.IsUnicode); smbData.Trans_Data = writeData; packet.SmbParameters = smbParameters; packet.SmbData = smbData; packet.UpdateCountAndOffset(); // update TransactionSubCommand in SmbGlobalContext, record the transact action this.capability.TransactionSubCommand = TransSubCommandExtended.TRANS_EXT_MAILSLOT_WRITE; return packet; }
/// <summary> /// to create a TransWriteNmpipe request packet. /// </summary> /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a /// request.</param> /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param> /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is /// accessing.</param> /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the /// message</param> /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the /// message. Unspecified bits are reserved and MUST be zero.</param> /// <param name="maxParameterCount">The maximum number of parameter bytes that the client will accept in the /// transaction reply. The server MUST NOT return more than this number of parameter bytes.</param> /// <param name="maxDataCount">The maximum number of data bytes that the client will accept in the transaction /// reply. The server MUST NOT return more than this number of data bytes.</param> /// <param name="maxSetupCount">Maximum number of setup bytes that the client will accept in the transaction /// reply. The server MUST NOT return more than this number of setup bytes</param> /// <param name="smbParametersflags">A set of bit flags that alter the behavior of the requested /// operation</param> /// <param name="timeout">The value of this field MUST be the maximum number of milliseconds the server SHOULD /// wait for completion of the transaction before generating a timeout and returning a response to the /// client. </param> /// <param name="fid">MUST contain a valid FID obtained from a previously successful SMB open command.</param> /// <param name="writeData">This field MUST contain the bytes to be written to the named pipe as part of the /// transacted operation.</param> /// <param name="name">The pathname of the mailslot or named pipe to which the transaction subcommand applies /// or a client supplied identifier that provides a name for the transaction.</param> /// <returns>a TransWriteNmpipe request packet</returns> public SmbTransWriteNmpipeRequestPacket CreateTransWriteNmpipeRequest( ushort messageId, ushort uid, ushort treeId, SmbFlags flags, SmbFlags2 flags2, ushort maxParameterCount, ushort maxDataCount, byte maxSetupCount, TransSmbParametersFlags smbParametersflags, uint timeout, ushort fid, byte[] writeData, string name) { if (writeData == null) { writeData = new byte[0]; } if (name == null) { name = string.Empty; } SmbTransWriteNmpipeRequestPacket packet = new SmbTransWriteNmpipeRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_TRANSACTION, messageId, uid, treeId, flags, flags2); // Set Smb Parameters SMB_COM_TRANSACTION_Request_SMB_Parameters smbParameters = new SMB_COM_TRANSACTION_Request_SMB_Parameters(); smbParameters.MaxParameterCount = maxParameterCount; smbParameters.MaxDataCount = maxDataCount; smbParameters.MaxSetupCount = maxSetupCount; smbParameters.Flags = smbParametersflags; smbParameters.Timeout = timeout; smbParameters.SetupCount = 2; // the correct count in word of the Setup is always 2. smbParameters.Setup = new ushort[2]; smbParameters.Setup[0] = (ushort)TransSubCommand.TRANS_WRITE_NMPIPE; smbParameters.Setup[1] = fid; smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TRANSACTION_Request_SMB_Parameters>( smbParameters) / NumBytesOfWord); // Set Smb Data SMB_COM_TRANSACTION_Request_SMB_Data smbData = new SMB_COM_TRANSACTION_Request_SMB_Data(); smbData.Name = CifsMessageUtils.ToSmbStringBytes(name, (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE); // Set Trans_Data TRANS_WRITE_NMPIPE_Request_Trans_Data transData = new TRANS_WRITE_NMPIPE_Request_Trans_Data(); transData.WriteData = writeData; packet.SmbParameters = smbParameters; packet.SmbData = smbData; packet.TransData = transData; packet.UpdateCountAndOffset(); return packet; }