コード例 #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);
        }
コード例 #2
0
        /// <summary>
        /// Do IO control on remote server
        /// </summary>
        /// <param name="ctlCode">The control code</param>
        /// <param name="isFsCtl">Indicate if the control code is a file system control code</param>
        /// <param name="input">The input data of io control</param>
        /// <param name="output">The output data of io control</param>
        /// <returns>
        /// a uint value that specifies the status of response packet.
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Thrown when meet an transport error</exception>
        private uint InternalIoControl(uint ctlCode, bool isFsCtl, byte[] input, out byte[] output)
        {
            SmbNtTransactIoctlRequestPacket request =
                smbClient.CreateNTTransIOCtlRequest(this.fid, isFsCtl, 0x00, ctlCode, input);

            if (this.isSignRequired)
            {
                request.Sign(this.NextSequenceNumber, this.sessionKey);
            }

            uint status = 0;
            SmbNtTransactIoctlResponsePacket response =
                this.SendAndExpectSmbPacket(request, internalTimeout, out status) as SmbNtTransactIoctlResponsePacket;

            output = null;
            if (response != null)
            {
                output = response.NtTransData.Data;
            }

            return(SmbMessageUtils.CheckStatus(status));
        }