/// <summary>
        /// Create Trans2SetFileSystemInformation requestfor client to set the file system information 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 = "transactOptions">
        /// A set of bit flags that alter the behavior of the requested operation. Unused bit fields MUST be set to  
        /// zero by the client sending the request, and MUST be ignored by the server receiving the request. The 
        /// client MAY set either or both of the following bit flags 
        /// </param>
        /// <param name = "timeOut">
        /// The maximum amount of time in milliseconds to wait for the operation to complete. The client SHOULD set  
        /// this to 0 to indicate that no time-out is given. If the operation does not complete within the specified  
        /// time, the server MAY abort the request and send a failure response. 
        /// </param>
        /// <param name = "isUsePathThrough">
        /// Indicates that the client is requesting a native Microsoft Windows® NT operating system information level, 
        /// as specified in section 3.2.4.7 and in [MS-FSCC] section 2.4. 
        /// </param>
        /// <param name = "informationLevel">
        /// Indicates that client specifies the information it is requesting. Server return different data based on 
        /// the client's request. 
        /// </param>
        /// <param name = "data">the information data to be set. </param>
        /// <returns>a set file information request packet </returns>
        private SmbTrans2SetFsInformationRequestPacket CreateTrans2SetFileSystemInformationRequest(
            ushort messageId,
            ushort sessionUid,
            ushort treeId,
            SmbHeader_Flags_Values flags,
            SmbHeader_Flags2_Values flags2,
            ushort fileId,
            Trans2SmbParametersFlags transactOptions,
            uint timeOut,
            bool isUsePathThrough,
            QueryFSInformationLevel informationLevel,
            byte[] data)
        {
            if (isUsePathThrough)
            {
                informationLevel = (QueryFSInformationLevel)
                    (informationLevel + SmbCapability.CONST_SMB_INFO_PASSTHROUGH);
            }

            SmbTrans2SetFsInformationRequestPacket packet =
                new SmbTrans2SetFsInformationRequestPacket(
                this.cifsClient.CreateTrans2SetFsInformationRequest(
                messageId, sessionUid, treeId, (SmbFlags)flags, (SmbFlags2)flags2,
                this.capability.MaxParameterCount, this.capability.MaxDataCount, this.capability.MaxSetupCount,
                transactOptions, timeOut, ""));

            // Set Trans2_Parameters
            TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Parameters trans2Parameters =
                new TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Parameters();
            trans2Parameters.FID = fileId;
            trans2Parameters.InformationLevel = informationLevel;

            // Set Trans2_Data
            TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Data trans2Data =
                new TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Data();
            trans2Data.Data = data;

            packet.Trans2Parameters = trans2Parameters;
            packet.Trans2Data = trans2Data;

            packet.UpdateCountAndOffset();

            return packet;
        }
 /// <summary>
 /// Deep copy constructor. 
 /// </summary>
 public SmbTrans2SetFsInformationRequestPacket(SmbTrans2SetFsInformationRequestPacket packet)
     : base(packet)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        /// TRANS2_SET_FS_INFORMATION Request.
        /// </summary>
        /// <param name="messageId">This is used to associate a response with a request.</param>
        /// <param name="sessionId">
        /// Set this value to 0 to request a new session setup, or set this value to a previously established session 
        /// identifier to request reauthenticate to an existing session.
        /// </param>
        /// <param name="treeId">
        /// This field identifies the subdirectory (or tree) (also referred as a share in this document) on the 
        /// server that the client is accessing.
        /// </param>
        /// <param name="isSigned">
        /// Indicate whether the SUT has message signing enabled or required.
        /// </param>
        /// <param name="isUsePassthrough">
        /// Indicate whether adding SMB_INFO_PASSTHROUGH in InformationLevel field of the request.
        /// </param>
        /// <param name="isRequireDisconnectTreeFlags">Indicate whether flags set to Disconnect_TID.</param>
        /// <param name="isRequireNoResponseFlags">Indicate whether flags set to NO_RESPONSE.</param>
        /// <param name="informationLevel">This can be used to query information from the server.</param>
        /// <param name="fid">The file identifier.</param>
        /// <param name="otherBits">If it contains other bits.</param>
        /// <param name="reserved">The reserved int value.</param>
        public void Trans2SetFsInfoRequest(
            int messageId,
            int sessionId,
            int treeId,
            bool isSigned,
            bool isUsePassthrough,
            bool isRequireDisconnectTreeFlags,
            bool isRequireNoResponseFlags,
            InformationLevel informationLevel,
            int fid,
            bool otherBits,
            int reserved)
        {
            #region Create Packet

            SmbTrans2SetFsInformationRequestPacket smbPacket = new SmbTrans2SetFsInformationRequestPacket();
            ushort uid = (ushort)this.uId[(uint)sessionId];
            ushort fileId = (ushort)this.fId[(uint)fid];

            NamespaceCifs.Trans2SmbParametersFlags transactOptions = NamespaceCifs.Trans2SmbParametersFlags.NONE;

            if (isRequireDisconnectTreeFlags && isRequireNoResponseFlags)
            {
                transactOptions = NamespaceCifs.Trans2SmbParametersFlags.DISCONNECT_TID
                    | NamespaceCifs.Trans2SmbParametersFlags.NO_RESPONSE;
            }

            if (isRequireDisconnectTreeFlags && !isRequireNoResponseFlags)
            {
                transactOptions = NamespaceCifs.Trans2SmbParametersFlags.DISCONNECT_TID;
            }

            if (!isRequireDisconnectTreeFlags && isRequireNoResponseFlags)
            {
                transactOptions = NamespaceCifs.Trans2SmbParametersFlags.NO_RESPONSE;
            }

            if (!isRequireDisconnectTreeFlags && !isRequireNoResponseFlags)
            {
                transactOptions = NamespaceCifs.Trans2SmbParametersFlags.NONE;
            }

            ushort level = this.informationLevelBytes[(ushort)informationLevel];
            if (isUsePassthrough)
            {
                level += InformationLevelPathThrouth;
            }
            // FILE_FS_CONTROL_INFORMATION data
            NamespaceFscc.FileFsControlInformation fileFsControlInformation =
                new NamespaceFscc.FileFsControlInformation();

            fileFsControlInformation.DefaultQuotaLimit = uint.MinValue;
            fileFsControlInformation.DefaultQuotaThreshold = uint.MinValue;

            fileFsControlInformation.FileSystemControlFlags =
                NamespaceFscc.FileSystemControlFlags_Values.FILE_VC_LOG_QUOTA_LIMIT;

            fileFsControlInformation.FreeSpaceStartFiltering = uint.MinValue;
            fileFsControlInformation.FreeSpaceStopFiltering = uint.MinValue;
            fileFsControlInformation.FreeSpaceThreshold = uint.MinValue;

            NamespaceFscc.FsccFileFsControlInformationRequestPacket fsControlPacket
                = new NamespaceFscc.FsccFileFsControlInformationRequestPacket();

            fsControlPacket.Payload = fileFsControlInformation;

            byte[] data = new byte[DataCount];
            data = fsControlPacket.ToBytes();

            smbPacket = this.smbClientStack.CreateTrans2SetFileSystemInformationRequest(
                fileId,
                transactOptions,
                (NamespaceCifs.QueryFSInformationLevel)level,
                data);

            NamespaceCifs.SMB_COM_TRANSACTION2_Request_SMB_Parameters smbParameters = smbPacket.SmbParameters;
            smbParameters.DataCount = DataCount;
            smbPacket.SmbParameters = smbParameters;

            if (isSigned)
            {
                NamespaceCifs.CifsClientPerConnection connection =
                    this.smbClientStack.Context.GetConnection(ConnectionId);

                NamespaceCifs.CifsClientPerSession session =
                    this.smbClientStack.Context.GetSession(ConnectionId, uid);

                smbPacket.Sign(connection.ClientNextSendSequenceNumber, session.SessionKey);
            }

            #endregion

            #region Send and Receive ExpectPacket

            this.smbClientStack.SendPacket(smbPacket);
            StackPacket response = this.smbClientStack.ExpectPacket(this.timeout);

            NamespaceCifs.SmbPacket smbPacketResponse = (NamespaceCifs.SmbPacket)response;

            this.QueryUidTable(smbPacketResponse);
            this.QueryTidTable(smbPacketResponse);

            VerifyTransport(smbPacketResponse);
            VerifyCommonMessageSyntax(smbPacketResponse);

            if (response.GetType() == typeof(SmbErrorResponsePacket))
            {
                SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket;
                NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader;

                if (smbErrorHeader.Status == (uint)MessageStatus.StatusInvalidInfoClass)
                {
                    smbErrorHeader.Status = (uint)MessageStatus.NotSupported;
                }

                //Workaround temp code (SetFsInfo Unknown Error TDQ)
                if (informationLevel == InformationLevel.FileFsControlInformaiton &&
                    !bool.Parse(Site.Properties["IsTDQ33016Fixed"]))
                {
                    this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, MessageStatus.AccessDenied);
                }
                else
                {
                    this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status);
                }
            }
            else
            {
                SmbTrans2SetFsInformationResponsePacket smbTrans2SetFsInformationPacket
                    = response as SmbTrans2SetFsInformationResponsePacket;

                NamespaceCifs.SmbHeader trans2SetFsInformationResponseHeader =
                    smbTrans2SetFsInformationPacket.SmbHeader;

                if (this.Trans2SetFsInfoResponse != null)
                {
                    this.Trans2SetFsInfoResponse(
                        trans2SetFsInformationResponseHeader.Mid + this.addMidMark,
                        this.QueryUidTable(smbPacketResponse),
                        this.QueryTidTable(smbPacketResponse),
                        (smbPacketResponse).IsSignRequired,
                        (MessageStatus)trans2SetFsInformationResponseHeader.Status);
                }
                else
                {
                    this.Trans2SetFsInfoResponseAdditional(
                        trans2SetFsInformationResponseHeader.Mid + this.addMidMark,
                        this.QueryUidTable(smbPacketResponse),
                        this.QueryTidTable(smbPacketResponse),
                        (smbPacketResponse).IsSignRequired,
                        (MessageStatus)trans2SetFsInformationResponseHeader.Status);
                }
            }

            #endregion
        }
Ejemplo n.º 4
0
        /// <summary>
        /// TRANS2_SET_FS_INFORMATION request additional.
        /// </summary>
        /// <param name="messageId">This is used to associate a response with a request.</param>
        /// <param name="sessionId">
        /// Set this value to 0 to request a new session setup, or set this value to a previously established session 
        /// identifier to request reauthenticate to an existing session.
        /// </param>
        /// <param name="treeId">
        /// This field identifies the subdirectory (or tree) (also referred as a share in this document) on the 
        /// server that the client is accessing.
        /// </param>
        /// <param name="fid">The file identifier.</param>
        /// <param name="isSigned">
        /// Indicate whether the SUT has message signing enabled or required.
        /// </param>
        /// <param name="informationLevel">This can be used to query information from the server.</param>
        /// <param name="requestPara">Trans2SetFSInfo response parameter.</param>
        public void Trans2SetFsInfoRequestAdditional(
            int messageId,
            int sessionId,
            int treeId,
            int fid,
            bool isSigned,
            [Domain("InfoLevelSetByFS")] InformationLevel informationLevel,
            Trans2SetFsInfoResponseParameter requestPara)
        {
            #region Create Packet

            SmbTrans2SetFsInformationRequestPacket smbPacket = new SmbTrans2SetFsInformationRequestPacket();
            ushort uid = (ushort)this.uId[(uint)sessionId];
            ushort fileId = (ushort)this.fId[(uint)fid];

            NamespaceCifs.Trans2SmbParametersFlags transactOptions = NamespaceCifs.Trans2SmbParametersFlags.NONE;

            ushort level = ushort.MaxValue;
            if (informationLevel != InformationLevel.Invalid)
            {
                level = this.informationLevelBytes[(ushort)informationLevel];
                //This field MUST be a pass-through Information Level
                this.smbClientStack.Capability.IsUsePathThrough = true;
            }
            else
            {
                level = this.informationLevelBytes[(ushort)InformationLevel.FileFsControlInformaiton];
                //This field MUST be a pass-through Information Level
                this.smbClientStack.Capability.IsUsePathThrough = false;
            }

            byte[] data = new byte[DataCount];

            smbPacket = this.smbClientStack.CreateTrans2SetFileSystemInformationRequest(
                fileId,
                transactOptions,
                (NamespaceCifs.QueryFSInformationLevel)level,
                data);

            bool isInvalidFileId = false;
            if (requestPara == Trans2SetFsInfoResponseParameter.FileIdErrror)
            {
                isInvalidFileId = true;
            }

            if (isInvalidFileId)
            {
                TRANS2_SET_FILE_SYSTEM_INFORMATION_Request_Trans2_Parameters trans2Parameters =
                    smbPacket.Trans2Parameters;

                trans2Parameters.FID = ushort.MaxValue;
                smbPacket.Trans2Parameters = trans2Parameters;
            }

            if (isSigned)
            {
                NamespaceCifs.CifsClientPerConnection connection =
                    this.smbClientStack.Context.GetConnection(ConnectionId);

                NamespaceCifs.CifsClientPerSession session =
                    this.smbClientStack.Context.GetSession(ConnectionId, uid);

                smbPacket.Sign(connection.ClientNextSendSequenceNumber, session.SessionKey);
            }

            #endregion

            #region Send and Receive ExpectPacket

            this.smbClientStack.SendPacket(smbPacket);
            StackPacket response = this.smbClientStack.ExpectPacket(this.timeout);

            NamespaceCifs.SmbPacket smbPacketResponse = (NamespaceCifs.SmbPacket)response;

            this.QueryUidTable(smbPacketResponse);
            this.QueryTidTable(smbPacketResponse);

            VerifyTransport(smbPacketResponse);
            VerifyCommonMessageSyntax(smbPacketResponse);

            if (response.GetType() == typeof(SmbErrorResponsePacket))
            {
                SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket;
                NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader;

                if (smbErrorHeader.Status == (uint)MessageStatus.StatusInvalidInfoClass)
                {
                    smbErrorHeader.Status = (uint)MessageStatus.NotSupported;
                }

                //Workaround temp code (How to trigger the error Status_Data_Error)
                if ((informationLevel == InformationLevel.FileFsControlInformaiton) &&
                    !bool.Parse(Site.Properties["IsTDQ49846Fixed"]))
                {
                    smbErrorHeader.Status = (uint)MessageStatus.StatusDataError;
                }
                this.ErrorTrans2SetFsInfoResponseAdditional(
                    smbErrorHeader.Mid + this.addMidMark,
                    (MessageStatus)smbErrorHeader.Status);
            }
            else
            {
                SmbTrans2SetFsInformationResponsePacket smbTrans2SetFsInformationPacket
                    = response as SmbTrans2SetFsInformationResponsePacket;
                NamespaceCifs.SmbHeader trans2SetFsInformationResponseHeader = smbTrans2SetFsInformationPacket.SmbHeader;

                this.Trans2SetFsInfoResponseAdditional(
                    trans2SetFsInformationResponseHeader.Mid + this.addMidMark,
                    this.QueryUidTable(smbPacketResponse),
                    this.QueryTidTable(smbPacketResponse),
                    (smbPacketResponse).IsSignRequired,
                    (MessageStatus)trans2SetFsInformationResponseHeader.Status);
            }

            #endregion
        }
        /// <summary>
        /// find the transaction2 packet.
        /// </summary>
        /// <param name="command">the command of transaction2 packet.</param>
        /// <returns>the target transaction2 packet</returns>
        private static SmbPacket FindTheTrans2Packet(Trans2SubCommand command)
        {
            SmbPacket smbPacket = null;
            switch ((Trans2SubCommand)command)
            {
                case Trans2SubCommand.TRANS2_FIND_FIRST2:
                    smbPacket = new SmbTrans2FindFirst2RequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_FIND_NEXT2:
                    smbPacket = new SmbTrans2FindNext2RequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_QUERY_FS_INFORMATION:
                    smbPacket = new SmbTrans2QueryFsInformationRequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_SET_FS_INFORMATION:
                    smbPacket = new SmbTrans2SetFsInformationRequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_QUERY_PATH_INFORMATION:
                    smbPacket = new SmbTrans2QueryPathInformationRequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_SET_PATH_INFORMATION:
                    smbPacket = new SmbTrans2SetPathInformationRequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_QUERY_FILE_INFORMATION:
                    smbPacket = new SmbTrans2QueryFileInformationRequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_SET_FILE_INFORMATION:
                    smbPacket = new SmbTrans2SetFileInformationRequestPacket();
                    break;

                case Trans2SubCommand.TRANS2_GET_DFS_REFERRAL:
                    smbPacket = new SmbTrans2GetDfsReferralRequestPacket();
                    break;

                default:
                    break;
            }
            return smbPacket;
        }