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

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

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;
            if (packet.smbData.OldFileName != null)
            {
                this.smbData.OldFileName = new byte[packet.smbData.OldFileName.Length];
                Array.Copy(packet.smbData.OldFileName,
                    this.smbData.OldFileName, packet.smbData.OldFileName.Length);
            }
            else
            {
                this.smbData.OldFileName = new byte[0];
            }
            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;
            if (packet.smbData.NewFileName != null)
            {
                this.smbData.NewFileName = new byte[packet.smbData.NewFileName.Length];
                Array.Copy(packet.smbData.NewFileName,
                    this.smbData.NewFileName, packet.smbData.NewFileName.Length);
            }
            else
            {
                this.smbData.NewFileName = new byte[0];
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbNtRenameRequestPacket(SmbNtRenameRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

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

            this.smbData.ByteCount     = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;
            if (packet.smbData.OldFileName != null)
            {
                this.smbData.OldFileName = new byte[packet.smbData.OldFileName.Length];
                Array.Copy(packet.smbData.OldFileName,
                           this.smbData.OldFileName, packet.smbData.OldFileName.Length);
            }
            else
            {
                this.smbData.OldFileName = new byte[0];
            }
            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;
            if (packet.smbData.NewFileName != null)
            {
                this.smbData.NewFileName = new byte[packet.smbData.NewFileName.Length];
                Array.Copy(packet.smbData.NewFileName,
                           this.smbData.NewFileName, packet.smbData.NewFileName.Length);
            }
            else
            {
                this.smbData.NewFileName = new byte[0];
            }
        }
        /// <summary>
        /// to create a NtRename 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 attributes that the target file(s) MUST have.</param>
        /// <param name="informationLevel">the NtRenameInformationLevel of the operation.</param>
        /// <param name="oldFileName">the full path name of the file to be manipulated.</param>
        /// <param name="newFileName">the new full path name to be assigned to the  file provided in OldFileName 
        /// or the full path into which the file is to be moved.</param>
        /// <returns>a NtRename request packet</returns>
        public SmbNtRenameRequestPacket CreateNtRenameRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            SmbFileAttributes searchAttributes,
            NtRenameInformationLevel informationLevel,
            string oldFileName,
            string newFileName)
        {
            if (oldFileName == null)
            {
                oldFileName = string.Empty;
            }
            if (newFileName == null)
            {
                newFileName = string.Empty;
            }

            SmbNtRenameRequestPacket packet = new SmbNtRenameRequestPacket();

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

            SMB_COM_NT_RENAME_Request_SMB_Parameters smbParameters = new SMB_COM_NT_RENAME_Request_SMB_Parameters();
            smbParameters.SearchAttributes = searchAttributes;
            smbParameters.InformationLevel = informationLevel;
            smbParameters.Reserved = 0;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_NT_RENAME_Request_SMB_Data smbData = new SMB_COM_NT_RENAME_Request_SMB_Data();
            smbData.BufferFormat1 = (byte)DataBufferFormat.SmbString;
            smbData.OldFileName = CifsMessageUtils.ToSmbStringBytes(oldFileName,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.BufferFormat2 = (byte)DataBufferFormat.SmbString;

            if ((flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
            {
                // if Unicode, add 1 byte pad for align on 16-bits.
                smbData.NewFileName = new byte[1 + (newFileName.Length + 1) * 2];
                Array.Copy(CifsMessageUtils.ToSmbStringBytes(newFileName, true), 0, smbData.NewFileName, 1,
                    (newFileName.Length + 1) * 2);
            }
            else
            {
                smbData.NewFileName = CifsMessageUtils.ToSmbStringBytes(newFileName, false);
            }
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat1) + smbData.OldFileName.Length
                + Marshal.SizeOf(smbData.BufferFormat2) + smbData.NewFileName.Length);

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

            return packet;
        }
        public SmbNtRenameResponsePacket CreateNtRenameResponse(
            CifsServerPerConnection connection,
            SmbNtRenameRequestPacket request)
        {
            SmbNtRenameResponsePacket response = new SmbNtRenameResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            return response;
        }