/// <summary> /// Deep copy constructor. /// </summary> public SmbOpenRequestPacket(SmbOpenRequestPacket packet) : base(packet) { this.InitDefaultValue(); this.smbParameters.WordCount = packet.SmbParameters.WordCount; this.smbParameters.AccessMode = packet.SmbParameters.AccessMode; this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes; 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 Open 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="accessMode">A 16-bit field for encoding the requested access mode. See section 3.2.4.5.1 /// for a discussion on sharing modes.</param> /// <param name="searchAttributes">SMB_FILE_ATTRIBUTES Specifies the type of file desired. This field is /// used as a search mask. Both the FileName and the SearchAttributes of a file MUST match for the file to /// be opened. </param> /// <param name="fileName">STRING A null-terminated string containing the file name of the file to be /// opened.</param> /// <returns> to create a Open request packet.</returns> public SmbOpenRequestPacket CreateOpenRequest( ushort messageId, ushort uid, ushort treeId, SmbFlags flags, SmbFlags2 flags2, AccessMode accessMode, SmbFileAttributes searchAttributes, string fileName) { if (fileName == null) { fileName = string.Empty; } SmbOpenRequestPacket packet = new SmbOpenRequestPacket(); packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_OPEN, messageId, uid, treeId, flags, flags2); SMB_COM_OPEN_Request_SMB_Parameters smbParameters = new SMB_COM_OPEN_Request_SMB_Parameters(); smbParameters.AccessMode = (ushort)accessMode; smbParameters.SearchAttributes = searchAttributes; smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord); SMB_COM_OPEN_Request_SMB_Data smbData = new SMB_COM_OPEN_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 SmbOpenResponsePacket CreateOpenResponse( CifsServerPerConnection connection, SmbOpenRequestPacket request, uint fileSize, UTime lastModified) { SmbOpenResponsePacket response = new SmbOpenResponsePacket(); response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request); SMB_COM_OPEN_Response_SMB_Parameters smbParameters = response.SmbParameters; smbParameters.AccessMode = request.SmbParameters.AccessMode; smbParameters.FID = (ushort)connection.GenerateFID(); smbParameters.FileAttrs = request.SmbParameters.SearchAttributes; smbParameters.FileSize = fileSize; smbParameters.LastModified = lastModified; smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2); response.SmbParameters = smbParameters; return response; }