/// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbDeleteRequestPacket(SmbDeleteRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            if (packet.smbData.BufferFormatAndFileName != null)
            {
                this.smbData.BufferFormatAndFileName = new byte[packet.smbData.BufferFormatAndFileName.Length];
                Array.Copy(packet.smbData.BufferFormatAndFileName, this.smbData.BufferFormatAndFileName,
                    packet.smbData.BufferFormatAndFileName.Length);
            }
            else
            {
                this.smbData.BufferFormatAndFileName = new byte[0];
            }
        }
Example #2
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbDeleteRequestPacket(SmbDeleteRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount        = packet.SmbParameters.WordCount;
            this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            if (packet.smbData.BufferFormatAndFileName != null)
            {
                this.smbData.BufferFormatAndFileName = new byte[packet.smbData.BufferFormatAndFileName.Length];
                Array.Copy(packet.smbData.BufferFormatAndFileName, this.smbData.BufferFormatAndFileName,
                           packet.smbData.BufferFormatAndFileName.Length);
            }
            else
            {
                this.smbData.BufferFormatAndFileName = new byte[0];
            }
        }
        /// <summary>
        /// to create a Delete 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="searchAttributes">The file attributes of the file(s) to be deleted. If the value of this
        /// field is zero, then only normal files MUST be matched for deletion.  If the System or Hidden attributes
        /// MUST be specified, then entries with those attributes are matched in addition to the normal files.  
        /// Read-only files MAY NOT be deleted. The read-only attribute of the file MUST be cleared before the file
        /// MAY be deleted.</param>
        /// <param name="fileNames">The pathname of the file(s) to be deleted, relative to the supplied TID. Wildcards
        /// MAY be used in the filename component of the path.</param>
        /// <returns>a Delete request packet</returns>
        public SmbDeleteRequestPacket CreateDeleteRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            SmbFileAttributes searchAttributes,
            string[] fileNames)
        {
            if (fileNames == null)
            {
                fileNames = new string[0];
            }

            SmbDeleteRequestPacket packet = new SmbDeleteRequestPacket();

            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_DELETE,
                messageId, uid, treeId, flags, flags2);

            SMB_COM_DELETE_Request_SMB_Parameters smbParameters = new SMB_COM_DELETE_Request_SMB_Parameters();
            smbParameters.SearchAttributes = searchAttributes;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_DELETE_Request_SMB_Data smbData = new SMB_COM_DELETE_Request_SMB_Data();
            smbData.ByteCount = 0;
            smbData.BufferFormatAndFileName = new byte[0];
            bool isUnicode = (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE;
            const int bufferFormatSize = 1; // the size in bytes of BufferFormat is always 1.
            const int nullTerminalSize = 1; // the num of null Terminal character is always 1.
            foreach (string file in fileNames)
            {
                if (isUnicode)
                {
                    smbData.ByteCount += (byte)(bufferFormatSize + (file.Length + nullTerminalSize) * 2);
                }
                else
                {
                    smbData.ByteCount += (byte)(bufferFormatSize + (file.Length + nullTerminalSize));
                }
            }
            smbData.BufferFormatAndFileName = new byte[smbData.ByteCount];
            int index = 0;
            foreach (string file in fileNames)
            {
                smbData.BufferFormatAndFileName[index++] = (byte)DataBufferFormat.SmbString;
                byte[] fileNameBytes = CifsMessageUtils.ToSmbStringBytes(file, isUnicode);
                Array.Copy(fileNameBytes, 0, smbData.BufferFormatAndFileName, index, fileNameBytes.Length);
                index += fileNameBytes.Length;
            }

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
        public SmbDeleteResponsePacket CreateDeleteResponse(
            CifsServerPerConnection connection,
            SmbDeleteRequestPacket request)
        {
            SmbDeleteResponsePacket response = new SmbDeleteResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            return response;
        }