Example #1
0
        /// <summary>
        /// find the nt transaction packets
        /// </summary>
        /// <param name="command">the command of nt transaction</param>
        /// <param name="setup">the setup contains the sub command</param>
        /// <returns>the target nt transaction packet</returns>
        private static SmbPacket FindTheNtTransPacket(NtTransSubCommand command, byte[] setup)
        {
            SmbPacket smbPacket = null;

            switch (command)
            {
            case NtTransSubCommand.NT_TRANSACT_CREATE:
                smbPacket = new SmbNtTransactCreateRequestPacket();
                break;

            case NtTransSubCommand.NT_TRANSACT_RENAME:
                smbPacket = new SmbNtTransRenameRequestPacket();
                break;

            case NtTransSubCommand.NT_TRANSACT_IOCTL:
                NT_TRANSACT_IOCTL_SETUP subCommand = CifsMessageUtils.ToStuct <NT_TRANSACT_IOCTL_SETUP>(setup);
                switch ((NtTransFunctionCode)subCommand.FunctionCode)
                {
                case NtTransFunctionCode.FSCTL_SRV_ENUMERATE_SNAPSHOTS:
                    smbPacket = new SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket();
                    break;

                case NtTransFunctionCode.FSCTL_SRV_REQUEST_RESUME_KEY:
                    smbPacket = new SmbNtTransFsctlSrvRequestResumeKeyRequestPacket();
                    break;

                case NtTransFunctionCode.FSCTL_SRV_COPYCHUNK:
                    smbPacket = new SmbNtTransFsctlSrvCopyChunkRequestPacket();
                    break;

                default:
                    smbPacket = new SmbNtTransactIoctlRequestPacket();
                    break;
                }
                break;

            default:
                switch ((SmbNtTransSubCommand)command)
                {
                case SmbNtTransSubCommand.NT_TRANSACT_QUERY_QUOTA:
                    smbPacket = new SmbNtTransQueryQuotaRequestPacket();
                    break;

                case SmbNtTransSubCommand.NT_TRANSACT_SET_QUOTA:
                    smbPacket = new SmbNtTransSetQuotaRequestPacket();
                    break;
                }
                break;
            }

            return(smbPacket);
        }
        /// <summary>
        /// Create NTTransRename request for client to rename file 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 = "fileId">the valid file id to operation on, response by server. </param>
        /// <param name = "isReplaceIfExists">
        /// If this param is true and the target exists, the server SHOULD attempt to replace the target. 
        /// </param>
        /// <param name = "newFileName">The new name of file. </param>
        /// <returns>a nt transaction rename request packet </returns>
        private SmbNtTransRenameRequestPacket CreateNTTransRenameRequest(
            ushort messageId,
            ushort sessionUid,
            ushort treeId,
            SmbHeader_Flags_Values flags,
            SmbHeader_Flags2_Values flags2,
            ushort fileId,
            bool isReplaceIfExists,
            string newFileName)
        {
            SmbNtTransRenameRequestPacket packet = new SmbNtTransRenameRequestPacket(
                this.cifsClient.CreateNtTransactRenameRequest(
                messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2,
                this.capability.MaxSetupCount, this.capability.MaxParameterCount, this.capability.MaxDataCount));

            NT_TRANSACT_RENAME_Request_NT_Trans_Parameters ntTransParameters =
                packet.NtTransParameters;
            ntTransParameters.Fid = fileId;
            if (isReplaceIfExists)
            {
                ntTransParameters.RenameFlags = 0x01;
            }
            if (Capability.IsUnicode)
            {
                ntTransParameters.Pad1 = new byte[1];
            }
            ntTransParameters.NewName = CifsMessageUtils.ToSmbStringBytes(newFileName, this.capability.IsUnicode);

            packet.NtTransParameters = ntTransParameters;
            packet.UpdateCountAndOffset();

            return packet;
        }
        /// <summary>
        /// find the nt transaction packets
        /// </summary>
        /// <param name="command">the command of nt transaction</param>
        /// <param name="setup">the setup contains the sub command</param>
        /// <returns>the target nt transaction packet</returns>
        private static SmbPacket FindTheNtTransPacket(NtTransSubCommand command, byte[] setup)
        {
            SmbPacket smbPacket = null;
            switch (command)
            {
                case NtTransSubCommand.NT_TRANSACT_CREATE:
                    smbPacket = new SmbNtTransactCreateRequestPacket();
                    break;

                case NtTransSubCommand.NT_TRANSACT_RENAME:
                    smbPacket = new SmbNtTransRenameRequestPacket();
                    break;

                case NtTransSubCommand.NT_TRANSACT_IOCTL:
                    NT_TRANSACT_IOCTL_SETUP subCommand = CifsMessageUtils.ToStuct<NT_TRANSACT_IOCTL_SETUP>(setup);
                    switch ((NtTransFunctionCode)subCommand.FunctionCode)
                    {
                        case NtTransFunctionCode.FSCTL_SRV_ENUMERATE_SNAPSHOTS:
                            smbPacket = new SmbNtTransFsctlSrvEnumerateSnapshotsRequestPacket();
                            break;

                        case NtTransFunctionCode.FSCTL_SRV_REQUEST_RESUME_KEY:
                            smbPacket = new SmbNtTransFsctlSrvRequestResumeKeyRequestPacket();
                            break;

                        case NtTransFunctionCode.FSCTL_SRV_COPYCHUNK:
                            smbPacket = new SmbNtTransFsctlSrvCopyChunkRequestPacket();
                            break;

                        default:
                            smbPacket = new SmbNtTransactIoctlRequestPacket();
                            break;
                    }
                    break;

                default:
                    switch ((SmbNtTransSubCommand)command)
                    {
                        case SmbNtTransSubCommand.NT_TRANSACT_QUERY_QUOTA:
                            smbPacket = new SmbNtTransQueryQuotaRequestPacket();
                            break;

                        case SmbNtTransSubCommand.NT_TRANSACT_SET_QUOTA:
                            smbPacket = new SmbNtTransSetQuotaRequestPacket();
                            break;
                    }
                    break;
            }

            return smbPacket;
        }
 /// <summary>
 /// Deep copy constructor. 
 /// </summary>
 public SmbNtTransRenameRequestPacket(SmbNtTransRenameRequestPacket packet)
     : base(packet)
 {
 }
Example #5
0
 /// <summary>
 /// Deep copy constructor.
 /// </summary>
 public SmbNtTransRenameRequestPacket(SmbNtTransRenameRequestPacket packet)
     : base(packet)
 {
 }