/// <summary> /// Deep copy constructor. /// </summary> public SmbSetInformationRequestPacket(SmbSetInformationRequestPacket packet) : base(packet) { this.InitDefaultValue(); this.smbParameters.WordCount = packet.SmbParameters.WordCount; this.smbParameters.FileAttributes = packet.SmbParameters.FileAttributes; this.smbParameters.LastWriteTime = new UTime(); this.smbParameters.LastWriteTime.Time = packet.SmbParameters.LastWriteTime.Time; if (packet.smbParameters.Reserved != null) { this.smbParameters.Reserved = new ushort[packet.smbParameters.Reserved.Length]; Array.Copy(packet.smbParameters.Reserved, this.smbParameters.Reserved, packet.smbParameters.Reserved.Length); } else { this.smbParameters.Reserved = new ushort[0]; } this.smbData.ByteCount = packet.SmbData.ByteCount; this.smbData.BufferFormat = packet.SmbData.BufferFormat; if (packet.smbData.FileName != null) { this.smbData.FileName = new byte[packet.smbData.FileName.Length]; Array.Copy(packet.smbData.FileName, this.smbData.FileName, packet.smbData.FileName.Length); } else { this.smbData.FileName = new byte[0]; } }
/// <summary> /// to create a SetInformation 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="fileAttributes">This field is a 16 bit unsigned bit field encoded as /// SMB_FILE_ATTRIBUTES</param> /// <param name="lastWriteTime">The time of the last write to the file</param> /// <param name="fileName">A null-terminated string that represents the fully qualified name of the file /// relative to the supplied TID. This is the file for which attributes are set.</param> /// <returns>a SetInformation request packet</returns> public SmbSetInformationRequestPacket CreateSetInformationRequest( ushort messageId, ushort uid, ushort treeId, SmbFlags flags, SmbFlags2 flags2, SmbFileAttributes fileAttributes, UTime lastWriteTime, string fileName) { if (fileName == null) { fileName = string.Empty; } SmbSetInformationRequestPacket packet = new SmbSetInformationRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_SET_INFORMATION, messageId, uid, treeId, flags, flags2); SMB_COM_SET_INFORMATION_Request_SMB_Parameters smbParameters; smbParameters = new SMB_COM_SET_INFORMATION_Request_SMB_Parameters(); smbParameters.FileAttributes = fileAttributes; smbParameters.LastWriteTime = lastWriteTime; smbParameters.Reserved = new ushort[5]; // the correct length of Reserved word is always 5. smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_SET_INFORMATION_Request_SMB_Parameters>( smbParameters) / NumBytesOfWord); SMB_COM_SET_INFORMATION_Request_SMB_Data smbData = new SMB_COM_SET_INFORMATION_Request_SMB_Data(); smbData.BufferFormat = (byte)DataBufferFormat.SmbString; smbData.FileName = CifsMessageUtils.ToSmbStringBytes(fileName, (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE); smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat) + smbData.FileName.Length); packet.SmbParameters = smbParameters; packet.SmbData = smbData; return packet; }
public SmbSetInformationResponsePacket CreateSetInformationResponse( CifsServerPerConnection connection, SmbSetInformationRequestPacket request) { SmbSetInformationResponsePacket response = new SmbSetInformationResponsePacket(); response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request); return response; }