Пример #1
0
 /// <summary>
 /// Verify whether the two response are equal or not
 /// </summary>
 /// <param name="response"> The First Response </param>
 /// <param name="response2"> The Second Response </param>
 private bool VerifyTreeConnectResponse(
     SmbTreeConnectAndxResponsePacket response,
     SmbTreeConnectAndxResponsePacket response2)
 {
     return((response.IsSignRequired == response2.IsSignRequired) &&
            (response.PacketType == response2.PacketType) &&
            (response.SmbData.ByteCount == response2.SmbData.ByteCount) &&
            CompareArrayEquals(response.SmbData.NativeFileSystem, response.SmbData.NativeFileSystem) &&
            CompareArrayEquals(response.SmbData.Service, response.SmbData.Service)
            & (response.SmbParameters.AndXCommand == response2.SmbParameters.AndXCommand) &&
            (response.SmbParameters.AndXOffset == response2.SmbParameters.AndXOffset) &&
            (response.SmbParameters.AndXReserved == response2.SmbParameters.AndXReserved) &&
            (response.SmbParameters.GuestMaximalShareAccessRights ==
             response2.SmbParameters.GuestMaximalShareAccessRights) &&
            (response.SmbParameters.MaximalShareAccessRights == response2.SmbParameters.MaximalShareAccessRights) &&
            (response.SmbParameters.OptionalSupport == response2.SmbParameters.OptionalSupport) &&
            (response.SmbParameters.WordCount == response2.SmbParameters.WordCount));
 }
        /// <summary>
        /// Create  SMB_COM_TREE_CONNECT_ANDX Server Response 
        /// </summary>
        /// <param name="connection">the connection identified the client</param>
        /// <param name = "treeId">
        /// This field identifies the subdirectory (or tree) (also referred to as a share in this document) on the 
        /// server that the client is accessing 
        /// </param>
        /// <param name = "service">The Service field indicates the type of resource the client is accessing </param>
        /// <param name = "nativeFileSystem">
        /// The name of the file system on the local resource that is being connected to 
        /// </param>
        /// <returns>The SmbTreeConnectAndXResponsePacket </returns>
        /// <exception cref="ArgumentNullException">connection must not be null</exception>
        public virtual SmbTreeConnectAndxResponsePacket CreateSmbComTreeConnectResponse(
            SmbServerConnection connection,
            ushort treeId,
            string service,
            string nativeFileSystem)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            SmbTreeConnectAndxResponsePacket packet = new SmbTreeConnectAndxResponsePacket();

            // get the request packet
            SmbPacket request = connection.GetRequestPacket(connection.MessageId);

            // create smb packet header
            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(
                SmbCommand.SMB_COM_TREE_CONNECT_ANDX,
                connection.ProcessId, connection.MessageId, request.SmbHeader.Uid, treeId,
                (SmbFlags)connection.Capability.Flag, (SmbFlags2)connection.Capability.Flags2);

            // update smb parameters
            SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Parameters smbParameters = packet.SmbParameters;

            smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.OptionalSupport = connection.OptionalSupport;
            smbParameters.MaximalShareAccessRights = connection.MaximalShareAccessRights;
            smbParameters.GuestMaximalShareAccessRights = connection.GuestMaximalShareAccessRights;

            smbParameters.WordCount = (byte)(CifsMessageUtils.GetSize<SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Parameters>(
                smbParameters) / SmbCapability.NUM_BYTES_OF_WORD);

            // update smb data
            SMB_COM_TREE_CONNECT_ANDX_Response_SMB_Data smbData = packet.SmbData;

            smbData.Service = CifsMessageUtils.ToSmbStringBytes(service, false);
            smbData.NativeFileSystem = CifsMessageUtils.ToSmbStringBytes(nativeFileSystem, connection.Capability.IsUnicode);

            // update smbData.ByteCount
            smbData.ByteCount = 0;
            if (smbData.Service != null)
            {
                smbData.ByteCount += (ushort)smbData.Service.Length;
            }
            if (smbData.NativeFileSystem != null)
            {
                smbData.ByteCount += (ushort)smbData.NativeFileSystem.Length;
            }

            // store the parameters and data to packet.
            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;

            return packet;
        }
        private void VerifyReceiveSmbComTreeConnectAndXRequest(
            SmbTreeConnectAndxResponsePacket response,
            bool isRequestExtResponse,
            uint computedMaxRights,
            ushort computedOptionalSupport,
            bool isGuestAccountSupported,
            bool isSupportExtSignature)
        {
            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R8300");

            // The implementation of CIFS is ensured by protocol SDK, and it couldn't be expressed in code.
            // Here capture it direcly.
            Site.CaptureRequirement(
                8300,
                @"[In Protocol Details] An SMB implementation MUST implement CIFS, as specified by section 3 of the
                [MS-CIFS] specification.");

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R30109");

            // Since the algorithm is coded by protocol SDK, it will make sure that the SUT calculate the
            // maximal share access rights for the user, which requests the tree connect using the algorithm described
            // in the TD. Here capture this requirement directly.
            Site.CaptureRequirement(
                30109,
                @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request] Requesting Extended Information: The server MUST
                calculate the maximal share access rights for the user that requests the tree connect using the
                following algorithm
                [MaxRights = 0x00000000
                IF Server.Share.SecurityDescriptor == NULL
                  MaxRights = 0xFFFFFFFF
                ELSE
                  FOR EACH AccessBit value defined in section 2.2.1.4
                    Compute access for the user, using Server.Share.SecurityDescriptor and
                     Server.Session.SecurityContext, as described in [MS-DTYP] section 2.5.2.1.
                    IF access was granted
                      MaxRights = MaxRights | AccessBit;
                    END IF
                  END FOR
                END IF].");

            // If isSupportExtSignature is TRUE, it means it's the Extended Information.
            if (isSupportExtSignature)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R30110");

                //
                // Verify MS-SMB requirement: MS-SMB_R30110.
                //
                // This is the server internal behavior, if MaximalShareAccessRights is not null, it means the server
                // under test has set ACCESS_MASK in MaximalShareAccessRights.
                Site.CaptureRequirementIfIsNotNull(
                    response.SmbParameters.MaximalShareAccessRights,
                    30110,
                    @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request] Requesting Extended Information: The
                    computed MaxRights ACCESS_MASK MUST be placed in the SMB_Parameters.Words.MaximalShareAccessRights
                    of the response.");
            }

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R4828");

            //
            // Verify MS-SMB requirement: MS-SMB_R4828.
            //
            // Using the same algorithm is the server internal behavior. If GuestMaximalShareAccessRights is not null,
            // it means the SUT has set it.
            Site.CaptureRequirementIfIsNotNull(
                response.SmbParameters.GuestMaximalShareAccessRights,
                4828,
                @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request]Requesting Extended Information: Using the same
                algorithm, the SMB_Parameters.Words.GuestMaximalAccessRights field of the response MUST be set to the
                calculated highest access rights the guest account has on this share.");

            if (isRequestExtResponse)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R30107");

                // Since response is of type SmbTreeConnectAndxResponsePacket, so if
                // TREE_CONNECT_ANDX_EXTENDED_RESPONSE is set, this requirement is verified. Here capture it directly.
                Site.CaptureRequirement(
                    30107,
                    @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request] Requesting Extended Information: If the
                    TREE_CONNECT_ANDX_EXTENDED_RESPONSE is set in the Flags field of the SMB_COM_TREE_CONNECT_ANDX
                    request, then the server MUST respond with the structure specified in section 2.2.4.7.2.");
            }

            // if isSupportExtSignature is TRUE, it means it's the Extended Information.
            if (isSupportExtSignature)
            {
                //
                // The following statement code will be run only when debugging.
                //

                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R30108 the OptionalSupport is {0}",
                    response.SmbParameters.OptionalSupport);

                //
                // Verify MS-SMB requirement: MS-SMB_R30108.
                //
                // 0x0001 is the value of SMB_SUPPORT_SEARCH_BITS
                // 0x0002 is the value of SMB_SHARE_IS_IN_DFS
                // 0x000c is the value of SMB_CSC_MASK
                // 0x0010 is the value of SMB_UNIQUE_FILE_NAME
                // 0x0020 is the value of SMB_EXTENDED_SIGNATURES
                // if the sever only set these bits of OptionalSupport, it means the SUT populate
                // OptionalSupport.
                ushort optionalSupportFlags = 0x0001 | 0x0002 | 0x000c | 0x0010 | 0x0020;
                bool isR30108Satisfied = (0x0000
                    == (response.SmbParameters.OptionalSupport & (ushort)~optionalSupportFlags));

                Site.CaptureRequirementIfIsTrue(
                    isR30108Satisfied,
                    30108,
                    @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request] Requesting Extended Information: The server
                    MUST populate the SMB_Parameters.Words.OptionalSupport field of the response with a value of
                    Server.Share. OptionalSupport.");
            }

            // isGuestAccountSupported means if the system support the guest account.
            if (!isGuestAccountSupported)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R2356");

                //
                // Verify MS-SMB requirement: MS-SMB_R2356.
                //
                Site.CaptureRequirementIfAreEqual<uint>(
                    0,
                    response.SmbParameters.GuestMaximalShareAccessRights,
                    2356,
                    @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request]Requesting Extended Information: If the system
                    does not support the guest account, then it MUST set GuestMaximalAccessRights to zero.");
            }
        }
        /// <summary>
        /// Verify Access Masks.
        /// </summary>
        /// <param name="smbTreeConnectAndxPacket">Packets for SmbTreeConnectAndxPacket Response.</param>
        /// <param name="shareType">To judge if the share type is the Printer</param>
        private void VerifyMessageSystaxAccessMasksForPrinter(
            SmbTreeConnectAndxResponsePacket smbTreeConnectAndxPacket,
            ShareType shareType)
        {
            if (shareType == ShareType.Printer)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R109080");
                //
                // Verify MS-SMB requirement: MS-SMB_R109080.
                //
                bool isContainFILE_WRITE_DATA = (smbTreeConnectAndxPacket.SmbParameters.MaximalShareAccessRights &
                    (uint)CIFS.NtTransactDesiredAccess.FILE_WRITE_DATA) == (uint)CIFS.NtTransactDesiredAccess.FILE_WRITE_DATA;
                bool isContainFile_APPEND_DATA = (smbTreeConnectAndxPacket.SmbParameters.MaximalShareAccessRights &
                    (uint)CIFS.NtTransactDesiredAccess.FILE_APPEND_DATA) == (uint)CIFS.NtTransactDesiredAccess.FILE_APPEND_DATA;
                bool isContainGENERIC_WRITE = (smbTreeConnectAndxPacket.SmbParameters.MaximalShareAccessRights &
                    (uint)CIFS.NtTransactDesiredAccess.GENERIC_WRITE) == (uint)CIFS.NtTransactDesiredAccess.GENERIC_WRITE;
                bool isContainValue = isContainFILE_WRITE_DATA || isContainFile_APPEND_DATA || isContainGENERIC_WRITE;

                // If the value has at least one of the following: FILE_WRITE_DATA, FILE_APPEND_DATA, or GENERIC_WRITE,
                // then the isContainValue equals true, this requirement is captured.
                Site.CaptureRequirementIfIsTrue(
                    isContainValue,
                    109080,
                    "[In File_Pipe_Printer_Access_Mask]File_Pipe_Printer_Access_Mask (4 bytes): For a printer, the value MUST have at least one of the following: FILE_WRITE_DATA, FILE_APPEND_DATA, or GENERIC_WRITE.");
            }
        }
        private void VerifyMessageSyntaxSmbComTreeConnectResponse(
            SmbTreeConnectAndxResponsePacket response,
            bool isNotionSupported,
            bool isShi1005Set,
            bool isNoAliasingSet,
            bool isShortFileNameDisabled,
            int allowedGuestAccess,
            bool isRequestExtResponse)
        {
            if (isRequestExtResponse)
            {
                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R376");

                //
                // Verify MS-SMB requirement: MS-SMB_R376.
                //
                Site.CaptureRequirementIfAreEqual<byte>(
                    0x07,
                    response.SmbParameters.WordCount,
                    376,
                    @"[In Server Response Extensions]WordCount (1 byte):  The value of this field MUST be 0x07.");

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R35644,OptionalSupport:{0}",
                    response.SmbParameters.OptionalSupport);

                //
                // Verify MS-SMB requirement: MS-SMB_R35644.
                //
                bool isVerifyR35644 = (((response.SmbParameters.OptionalSupport & 0x0001) == 0x0001)
                    || ((response.SmbParameters.OptionalSupport & 0x0002) == 0x0002)
                    || ((response.SmbParameters.OptionalSupport & 0x000C) == 0x000C)
                    || ((response.SmbParameters.OptionalSupport & 0x0010) == 0x0010)
                    || ((response.SmbParameters.OptionalSupport & 0x0020) == 0x0020));

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR35644,
                    35644,
                    @"[In Server Response Extensions]OptionalSupport (2 bytes):Combination of the following flags [
                    SMB_SUPPORT_SEARCH_BITS 0x0001,
                    SMB_SHARE_IS_IN_DFS 0x0002,
                    SMB_CSC_MASK 0x000C,
                    SMB_UNIQUE_FILE_NAME 0x0010,
                    SMB_EXTENDED_SIGNATURES 0x0020]
                    MUST be supported. ");

                //
                // Verify requirement MS-SMB_R505644 and MS-SMB_R515644
                //
                string isR505644Implementated = Site.Properties.Get("SHOULDMAYR505644Implementation");
                ushort optionalSupportFlags = 0x0001 | 0x0002 | 0x000c | 0x0010 | 0x0020;
                bool isR515644Satisfied = (0 == (response.SmbParameters.OptionalSupport & (ushort)~optionalSupportFlags));

                if (isWindows)
                {
                    //
                    // The following statement code will be run only when debugging.
                    //
                    Site.Log.Add(LogEntryKind.Debug,
                        @"Verify MS-SMB_R515644,OptionalSupport:{0}",
                        response.SmbParameters.OptionalSupport);

                    //
                    // Verify MS-SMB requirement: MS-SMB_R515644.
                    //
                    Site.CaptureRequirementIfIsTrue(
                        isR515644Satisfied,
                        515644,
                        @"[In Server Response Extensions]OptionalSupport (2 bytes): The server is set them to zero in
                        Windows.");
                    if (null == isR505644Implementated)
                    {
                        Site.Properties.Add("SHOULDMAYR505644Implementation", Boolean.TrueString);
                        isR505644Implementated = Boolean.TrueString;
                    }
                }

                if (null != isR505644Implementated)
                {
                    bool implemented = Boolean.Parse(isR505644Implementated);
                    bool isSatisfied = isR515644Satisfied;

                    //
                    // The following statement code will be run only when debugging.
                    //
                    Site.Log.Add(LogEntryKind.Debug,
                        @"Verify MS-SMB_R505644,OptionalSupport:{0}",
                        response.SmbParameters.OptionalSupport);

                    //
                    // Verify MS-SMB requirement: MS-SMB_R505644.
                    //
                    Site.CaptureRequirementIfAreEqual<Boolean>(
                        implemented,
                        isSatisfied,
                        505644,
                        String.Format("[In Server Response Extensions]OptionalSupport (2 bytes): The server SHOULD set " +
                        "them to zero. This requirement is {0}implemented", implemented ? "" : "not "));
                }

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R5651");

                //
                // Verify MS-SMB requirement: MS-SMB_R5651.
                //
                // The latter half of the requirement is explaining the content of MaximalShareAccessRights field which
                // is informative.So here verify this requirement partially, only verify the byte size of
                // MaximalShareAccessRights field.
                Site.CaptureRequirementIfAreEqual<int>(
                    4,
                    Marshal.SizeOf(response.SmbParameters.MaximalShareAccessRights),
                    5651,
                    @"[In Server Response Extensions]MaximalShareAccessRights (4 bytes): This field MUST specify the
                    maximum rights that the user has to this share based on the security enforced by the share.");

                //
                // Verify MS-SMB requirement: MS-SMB_R5652.
                //
                // If the field is encoded in an AccessMask format, then only the flags listed in section 2.2.1.4
                // could be set, and the other unused flags is set to 0.
                // AccessMask is a uint variable which represent that all the flags listed
                // in section2.2.1.4 were set to 1.
                // So the bit-or result of the field with AccessMask should be equal to AccessMask,
                // otherwise it means the flags not listed in section 2.2.1.4 was set, which is invalid.
                Site.CaptureRequirementIfAreEqual<uint>(
                    0,
                    ~AccessMask & response.SmbParameters.MaximalShareAccessRights,
                    5652,
                    "[In Server Response ExtensionsMaximalShareAccessRights (4 bytes): This field MUST be encoded in " +
                    "an AccessMask format, as specified in section 2.2.1.4.");

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R5653");

                //
                // Verify MS-SMB requirement: MS-SMB_R5653.
                //
                // The latter half of requirement is explaining the content of GuestMaximalShareAccessRights field
                // which is informative. So verify this requirement partially. Only verify the byte size of
                // GuestMaximalShareAccessRights field.
                Site.CaptureRequirementIfAreEqual<int>(
                    4,
                    Marshal.SizeOf(response.SmbParameters.GuestMaximalShareAccessRights),
                    5653,
                    @"[In Server Response Extensions]GuestMaximalShareAccessRights (4 bytes): This field MUST specify
                    the maximum rights that the guest account has on this share based on the security enforced by the
                    share.");

                // isNotionSupported means if implementations support the notion of a guest account
                if (!isNotionSupported)
                {
                    //
                    // The following statement code will be run only when debugging.
                    //
                    Site.Log.Add(LogEntryKind.Debug,
                        @"Verify MS-SMB_R5656");

                    //
                    // Verify MS-SMB requirement: MS-SMB_R5656.
                    //
                    Site.CaptureRequirementIfAreEqual<uint>(
                        0,
                        response.SmbParameters.GuestMaximalShareAccessRights,
                        5656,
                        @"[In Server Response Extensions]GuestMaximalShareAccessRights (4 bytes): Implementations that
                        do not support the notion of a guest account MUST set this field to zero, which implies no
                        access.");
                }

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R105656");

                //
                // Verify MS-SMB requirement: MS-SMB_R105656.
                //
                // If the field is encoded in an AccessMask format, then only the flags listed
                // in section 2.2.1.4 could be set, and the other unused flags is set to 0.
                // AccessMask is a uint variable which represent that all the flags listed
                // in section2.2.1.4 were set to 1.
                // So the bit-or result of the field with AccessMask should be equal to AccessMask,
                // otherwise it means the flags not listed in section 2.2.1.4 was set, which is invalid.
                Site.CaptureRequirementIfAreEqual<uint>(
                    0,
                    ~AccessMask & response.SmbParameters.GuestMaximalShareAccessRights,
                    105656,
                    "[In Server Response Extensions]GuestMaximalShareAccessRights (4 bytes):" +
                    "This field MUST be encoded in an AccessMask format, as specified in section 2.2.1.4.");

                //
                // The following statement code will be run only when debugging.
                //
                Site.Log.Add(LogEntryKind.Debug,
                    @"Verify MS-SMB_R9623,GuestMaximalShareAccessRights:{0}",
                    response.SmbParameters.GuestMaximalShareAccessRights);

                //
                // Verify MS-SMB requirement: MS-SMB_R9623.
                //
                // isNotionSupported means whether implementation supports the notion of a guest account.
                // allowedGuestAccess means the access allowed for the guest account.
                bool isVerifyR9623 = isNotionSupported
                    || ((uint)allowedGuestAccess == response.SmbParameters.GuestMaximalShareAccessRights);

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR9623,
                    9623,
                    @"<50> Section 2.2.4.7.2: Windows-based clients and servers support the notion of a guest account
                    and set this field to the access allowed for the guest account.");
            }

            //
            // The following statement code will be run only when debugging.
            //
            Site.Log.Add(LogEntryKind.Debug,
                @"Verify MS-SMB_R5617");

            // If the requirement above have been verified, it means the SUT has sent the response as the
            // format.
            Site.CaptureRequirement(
                5617,
                @"[In Server Response Extensions]When a server returns extended information, the response takes
                the following format.");
        }
        public void TraditionalTestCase_IgnoreFields_Tree_04_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create a SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            #region Set the request parameters

            StackCifs.SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Parameters treeconnectRequestSmbParameters
                = treeconnectRequest.SmbParameters;

            // The Flags field is set to:TREE_CONNECT_ANDX_DISCONNECT_TID(0x0001),
            // TREE_CONNECT_ANDX_EXTENDED_SIGNATURES(0x0004), TREE_CONNECT_ANDX_EXTENDED_RESPONSE(0x0008).
            treeconnectRequestSmbParameters.Flags =
                (ushort)(treeconnectRequestSmbParameters.Flags & SmbTreeConnectAndxFlags);

            treeconnectRequest.SmbParameters = treeconnectRequestSmbParameters;

            #endregion

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect a response in the timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            path = Site.Properties["SutNtfsShare1FullName"];
            treeconnectRequest = smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            //The bits not listed in TD 2.2.4.7.1 of Flags field set to 0.
            //Other fields set according to TD.
            treeconnectRequestSmbParameters = treeconnectRequest.SmbParameters;

            // The Flags field is set to:TREE_CONNECT_ANDX_DISCONNECT_TID(0x0001),
            // TREE_CONNECT_ANDX_EXTENDED_SIGNATURES(0x0004), TREE_CONNECT_ANDX_EXTENDED_RESPONSE(0x0008).
            treeconnectRequestSmbParameters.Flags =
                (ushort)(treeconnectRequestSmbParameters.Flags & SmbTreeConnectAndxFlags);

            treeconnectRequest.SmbParameters = treeconnectRequestSmbParameters;

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in the timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse2 = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse2.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Capture requirement r5596

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R5596");

            //
            // Verify MS-SMB requirement: MS-SMB_R5596
            //
            bool isVerifyR5596 = VerifyTreeConnectResponse(treeConnectResponse, treeConnectResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR5596,
                5596,
                @"[In Client Request Extensions]Flags (2 bytes):
                whatever these values are, the server's reply is the same.");

            #endregion
        }
        public void TraditionalTestCase_NetServerEnum3_06()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            string path = Site.Properties["SutNamedPipeFullName"];

            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            #endregion

            #region SMB transaction
            // System.Text.ASCIIEncoding.ASCII.GetBytes("WrLehDZz");
            byte[] paramDesc = new byte[] { 0x57, 0x72, 0x4c, 0x65, 0x68, 0x44, 0x7a, 0x7a, 0x00 };

            byte[] dataDesc            = new byte[] { 0x42, 0x31, 0x36, 0x42, 0x42, 0x44, 0x7a, 0x00 };
            byte[] rapParamsAndAuxDesc = new byte[] { 0x01, 0x00, 0xFF, 0xFF };

            byte[] rapInData = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0x45, 0x4e, 0x44, 0x50,
                                            0x4f, 0x49, 0x4e, 0x54, 0x30, 0x31, 0x00 };

            SmbTransRapRequestPacket netServerEnmum2Request =
                smbClientStack.CreateTransNamedRapRequest(treeConnectResponse.SmbHeader.Tid,
                                                          StackCifs.TransSmbParametersFlags.NONE,
                                                          (ushort)0x00D7,
                                                          paramDesc,
                                                          dataDesc,
                                                          rapParamsAndAuxDesc, rapInData);
            smbClientStack.SendPacket(netServerEnmum2Request);
            response = smbClientStack.ExpectPacket(timeout);
            #endregion
        }
        public void TraditionalTestCase_IgnoreFields_CopyChunk_05()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            string path = Site.Properties["SutNtfsShare1FullName"];

            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            #endregion

            #region Send the NT_CREATE_ANDX request

            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest1"];
            smbClientStack.Capability.Flag |= SmbHeader_Flags_Values.OPLOCK;

            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.FILE_READ_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_EA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_ATTRIBUTES
                    | StackCifs.NtTransactDesiredAccess.FILE_WRITE_DATA,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_OPEN_REPARSE_POINT
                    | NtTransactCreateOptions.FILE_SEQUENTIAL_ONLY
                    | NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the NT_CREATE_ANDX request

            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            ushort fileId1   = createResponse.SmbParameters.FID;
            uint   offset    = uint.Parse(Site.Properties["SmbTransportWriteOffset"].ToString());
            byte[] writeData = new byte[17000];

            for (int i = 0; i < writeData.Length; i++)
            {
                writeData[i] = (byte)'a';
            }

            SmbWriteAndxRequestPacket writeRequest = smbClientStack.CreateWriteRequest(fileId1, offset, writeData);

            smbClientStack.SendPacket(writeRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the WRITE_ANDX request

            SmbWriteAndxResponsePacket writeAndxResponsePacket = response as SmbWriteAndxResponsePacket;
            string fileName2 = Site.Properties["SutShareTest2"];

            SmbNtCreateAndxRequestPacket createSecondRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName2,
                    StackCifs.NtTransactDesiredAccess.FILE_READ_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_WRITE_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_APPEND_DATA,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_OPEN_REPARSE_POINT
                    | NtTransactCreateOptions.FILE_SEQUENTIAL_ONLY
                    | NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPBATCH);

            smbClientStack.SendPacket(createSecondRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the NT_CREATE_ANDX

            SmbNtCreateAndxResponsePacket createSecondResponse = (SmbNtCreateAndxResponsePacket)response;
            ushort fileId2 = createSecondResponse.SmbParameters.FID;

            SmbNtTransFsctlSrvRequestResumeKeyRequestPacket nTTransIOCtlRequestResumeKeyRequest =
                smbClientStack.CreateNTTransIOCtlRequestResumeKeyRequest(fileId1, true, 0);

            StackCifs.SmbHeader smbHeader = nTTransIOCtlRequestResumeKeyRequest.SmbHeader;
            smbHeader.Uid = sessionUid;
            smbHeader.Tid = treeId;
            nTTransIOCtlRequestResumeKeyRequest.SmbHeader = smbHeader;

            smbClientStack.SendPacket(nTTransIOCtlRequestResumeKeyRequest);
            response = smbClientStack.ExpectPacket(timeout);

            SmbNtTransFsctlSrvRequestResumeKeyResponsePacket nTTransIOCtlRequestResumeKeyResponse =
                (SmbNtTransFsctlSrvRequestResumeKeyResponsePacket)response;

            #endregion

            #region Send the NT_TRANS_IO_CTL request

            bool   isFsctl            = true;
            byte   isFlags            = (byte)0;
            byte[] copychunkResumeKey = nTTransIOCtlRequestResumeKeyResponse.NtTransData.ResumeKey;

            nTTransIOCtlRequestResumeKeyRequest =
                smbClientStack.CreateNTTransIOCtlRequestResumeKeyRequest(fileId1, true, 0);

            smbHeader     = nTTransIOCtlRequestResumeKeyRequest.SmbHeader;
            smbHeader.Uid = sessionUid;
            smbHeader.Tid = treeId;
            nTTransIOCtlRequestResumeKeyRequest.SmbHeader = smbHeader;

            smbClientStack.SendPacket(nTTransIOCtlRequestResumeKeyRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Capture requirement r9074

            nTTransIOCtlRequestResumeKeyResponse =
                (SmbNtTransFsctlSrvRequestResumeKeyResponsePacket)response;
            byte[] copychunkResumeKey2 = nTTransIOCtlRequestResumeKeyResponse.NtTransData.ResumeKey;

            // Compare copychunkResumeKey and copychunkResumeKey2, if same, capture 9074
            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R9074");

            //
            // Verify MS-SMB requirement: MS-SMB_R9074
            //
            bool isVerifyR9074 = CompareArrayEquals(copychunkResumeKey, copychunkResumeKey2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR9074,
                9074,
                @"[In Copychunk Resume Key Generation] The generation of Copychunk Resume Keys MUST satisfy the 
                following constraints:The Copychunk Resume Key MUST remain valid for the lifetime of the open file 
                on the server.");

            #endregion

            #region Send the NT_TRANSACT_COPY_CHUNK_List request

            NT_TRANSACT_COPY_CHUNK_List list = new NT_TRANSACT_COPY_CHUNK_List();
            list.Length            = (uint)64;
            list.SourceOffset      = (ulong)0;
            list.DestinationOffset = (ulong)0;

            SmbNtTransFsctlSrvCopyChunkRequestPacket nTTransIOCtlCopyChunkRequest =
                smbClientStack.CreateNTTransIOCtlCopyChunkRequest(fileId2, isFsctl, isFlags, copychunkResumeKey, list);

            smbClientStack.SendPacket(nTTransIOCtlCopyChunkRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Send the NT_TRANSACT_COPY_CHUNK_Request_NT_Trans_Data request

            SmbNtTransFsctlSrvCopyChunkResponsePacket nTTransIOCtlCopyChunkResponse1 =
                (SmbNtTransFsctlSrvCopyChunkResponsePacket)response;

            list.Length            = (uint)64;
            list.SourceOffset      = (ulong)0;
            list.DestinationOffset = (ulong)0;
            list.Reserved          = 0xFFFF;

            nTTransIOCtlCopyChunkRequest =
                smbClientStack.CreateNTTransIOCtlCopyChunkRequest(fileId2, isFsctl, isFlags, copychunkResumeKey, list);
            NT_TRANSACT_COPY_CHUNK_Request_NT_Trans_Data TransData = nTTransIOCtlCopyChunkRequest.NtTransData;

            TransData.Unused = 0xFFFF;
            nTTransIOCtlCopyChunkRequest.NtTransData = TransData;

            smbClientStack.SendPacket(nTTransIOCtlCopyChunkRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Capture requirements R109390

            SmbNtTransFsctlSrvCopyChunkResponsePacket nTTransIOCtlCopyChunkResponse2 =
                (SmbNtTransFsctlSrvCopyChunkResponsePacket)response;

            // Compare 2 copy chunckResponse
            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109390");

            //
            // Verify MS-SMB requirement: MS-SMB_R109390
            //
            bool isVerifyR109390 = VerifyResponse(nTTransIOCtlCopyChunkResponse1, nTTransIOCtlCopyChunkResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109390,
                109390,
                @"[In  Client Request Extensions]Reserved (4 bytes):
                reply is the same whether zero or non-zero is used this field.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109396");

            //
            // Verify MS-SMB requirement: MS-SMB_R109396
            //
            bool isVerifyR109396 = VerifyResponse(nTTransIOCtlCopyChunkResponse1, nTTransIOCtlCopyChunkResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109396,
                109396,
                @"[In SRV_COPYCHUNK]Reserved (4 bytes):
                reply is the same whether zero or non-zero is used in this field.");

            #endregion

            #region Send the SMB_NT_TRANS_FSCTL_SRV request request

            nTTransIOCtlRequestResumeKeyRequest =
                smbClientStack.CreateNTTransIOCtlRequestResumeKeyRequest(fileId2, true, 0);

            smbHeader     = nTTransIOCtlRequestResumeKeyRequest.SmbHeader;
            smbHeader.Uid = sessionUid;
            smbHeader.Tid = treeId;
            nTTransIOCtlRequestResumeKeyRequest.SmbHeader = smbHeader;

            smbClientStack.SendPacket(nTTransIOCtlRequestResumeKeyRequest);
            response = smbClientStack.ExpectPacket(timeout);

            #endregion

            #region Capture reuqirements R9073

            nTTransIOCtlRequestResumeKeyResponse =
                (SmbNtTransFsctlSrvRequestResumeKeyResponsePacket)response;

            byte[] copychunkResumeKey3 = nTTransIOCtlRequestResumeKeyResponse.NtTransData.ResumeKey;

            //
            // Add the comment information for debugging
            //
            Site.Log.Add(
                LogEntryKind.Comment,
                @"Verify MS-SMB_R9073");

            //
            // Verify MS-SMB requirement: MS-SMB_R9073
            //
            bool isVerifyR9073 = CompareArrayEquals(copychunkResumeKey, copychunkResumeKey3);

            Site.CaptureRequirementIfIsFalse(
                isVerifyR9073,
                9073,
                @"[In Copychunk Resume Key Generation]
                The generation of Copychunk Resume Keys MUST satisfy the following constraints:
                The Copychunk Resume Key MUST be unique on the SMB server for a given open file on a server.");

            #endregion

            #region Disconnect the tree, session and connection.

            // TreeDisconnect
            SmbTreeDisconnectRequestPacket treeDisconnectRequest =
                smbClientStack.CreateTreeDisconnectRequest(treeId);

            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            // LogOff
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }
        protected override SmbPacket CreateSmbResponsePacket(
            SmbPacket request,
            SmbHeader smbHeader,
            Channel channel)
        {
            SmbPacket smbPacket = null;

            // error packet
            SmbStatus packetStatus = (SmbStatus)smbHeader.Status;

            // error packet
            if (packetStatus != SmbStatus.STATUS_SUCCESS &&
                    packetStatus != SmbStatus.STATUS_MORE_PROCESSING_REQUIRED &&
                    packetStatus != SmbStatus.STATUS_BUFFER_OVERFLOW)
            {
                smbPacket = new SmbErrorResponsePacket();
                smbPacket.SmbHeader = smbHeader;

                return smbPacket;
            }

            // success packet
            switch (smbHeader.Command)
            {
                case SmbCommand.SMB_COM_NEGOTIATE:
                    if (smbClient.Capability.IsSupportsExtendedSecurity)
                    {
                        smbPacket = new SmbNegotiateResponsePacket();
                    }
                    else
                    {
                        smbPacket = new SmbNegotiateImplicitNtlmResponsePacket();
                    }
                    break;

                case SmbCommand.SMB_COM_SESSION_SETUP_ANDX:
                    if (smbClient.Capability.IsSupportsExtendedSecurity)
                    {
                        smbPacket = new SmbSessionSetupAndxResponsePacket();
                    }
                    else
                    {
                        smbPacket = new SmbSessionSetupImplicitNtlmAndxResponsePacket();
                    }
                    break;

                case SmbCommand.SMB_COM_TREE_CONNECT_ANDX:
                    smbPacket = new SmbTreeConnectAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_TREE_DISCONNECT:
                    smbPacket = new SmbTreeDisconnectResponsePacket();
                    break;

                case SmbCommand.SMB_COM_LOGOFF_ANDX:
                    smbPacket = new SmbLogoffAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_NT_CREATE_ANDX:
                    smbPacket = new SmbNtCreateAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_CLOSE:
                    smbPacket = new SmbCloseResponsePacket();
                    break;

                case SmbCommand.SMB_COM_OPEN_ANDX:
                    smbPacket = new SmbOpenAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_WRITE_ANDX:
                    smbPacket = new SmbWriteAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_READ_ANDX:
                    smbPacket = new SmbReadAndxResponsePacket();
                    break;

                case SmbCommand.SMB_COM_TRANSACTION:
                    smbPacket = this.CreateTransactionResponsePacket(request, smbHeader, channel);

                    break;

                case SmbCommand.SMB_COM_TRANSACTION2:
                    smbPacket = this.CreateTransaction2ResponsePacket(request, smbHeader, channel);

                    break;

                case SmbCommand.SMB_COM_NT_TRANSACT:
                    smbPacket = this.CreateNtTransactionResponsePacket(request, smbHeader, channel);

                    break;

                default:
                    break;

            }
            if (smbPacket != null)
            {
                smbPacket.SmbHeader = smbHeader;
                return smbPacket;
            }

            return base.CreateSmbResponsePacket(request, smbHeader, channel);
        }
Пример #10
0
        public void TraditionalTestCase_IgnoreFields_SET_FILE_09_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;
            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the Create request.
            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest2"];
            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_ALL,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_IDENTIFY,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the SMB_COM_NT_CREATE_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check if server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the TRANS2_SET_FILE_INFORMATION request

            // Create a TRANS2_SET_FILE_INFORMATION request.
            ushort fileId = createResponse.SmbParameters.FID;
            StackFscc.FileLinkInformation fileLinkInformation = new StackFscc.FileLinkInformation();

            // 1 indicates that if the link already exists, it should be replaced with the new link.
            fileLinkInformation.ReplaceIfExists = 1;

            // The Reserved filed is a 7 bytes array
            fileLinkInformation.Reserved = new byte[7];

            // The name of the newly created link.
            fileLinkInformation.FileName       = Encoding.Unicode.GetBytes("wl.txt.lnk");
            fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length;

            // 0 indicates a network operations.
            fileLinkInformation.RootDirectory = 0;

            StackFscc.FsccFileLinkInformationRequestPacket linkPacket =
                new StackFscc.FsccFileLinkInformationRequestPacket();

            linkPacket.Payload = TypeMarshal.ToBytes <StackFscc.FileLinkInformation>(fileLinkInformation);
            byte[] data = linkPacket.ToBytes();
            smbClientStack.Capability.IsUsePassThrough = false;

            // Create a TRANS2_SET_FILE_INFORMATION Request.
            SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest =
                smbClientStack.CreateTrans2SetFileInformationRequest(
                    fileId,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    StackCifs.SetInformationLevel.SMB_INFO_STANDARD,
                    data);

            // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(trans2SetFileInformationRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "TRANS2_SET_FILE_INFORMATION response should not be null.");

            // Check whether server returns a TRANS2_SET_FILE_INFORMATION response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTrans2SetFileInformationResponsePacket),
                "TRANS2_SET_FILE_INFORMATION response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse =
                (SmbTrans2SetFileInformationResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                trans2SetFileInformationResponse.SmbHeader.Status,
                "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS.");

            #endregion

            #region Send the TRANS2_SET_FILE_INFORMATION request

            StackFscc.FsccFileLinkInformationRequestPacket linkPacket2 =
                new StackFscc.FsccFileLinkInformationRequestPacket();
            fileLinkInformation = new StackFscc.FileLinkInformation();

            // 1 indicates that if the link already exists, it should be replaced with the new link.
            fileLinkInformation.ReplaceIfExists = 1;

            // The Reserved filed is a 7 bytes array
            fileLinkInformation.Reserved = new byte[7];

            // The name of the newly created link.
            fileLinkInformation.FileName       = Encoding.Unicode.GetBytes("wl.txt.lnk");
            fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length;

            // 0 indicates a network operations.
            fileLinkInformation.RootDirectory = 0;

            linkPacket2.Payload = TypeMarshal.ToBytes <StackFscc.FileLinkInformation>(fileLinkInformation);
            smbClientStack.Capability.IsUsePassThrough = false;

            // Create a TRANS2_SET_FILE_INFORMATION request.
            SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest2 =
                smbClientStack.CreateTrans2SetFileInformationRequest(
                    fileId,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    StackCifs.SetInformationLevel.SMB_INFO_STANDARD,
                    linkPacket2.ToBytes());

            // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(trans2SetFileInformationRequest2);
            StackPacket response2 = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response2,
                "TRANS2_SET_FILE_INFORMATION response should not be null.");

            // Check whether server returns a TRANS2_SET_FILE_INFORMATION response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTrans2SetFileInformationResponsePacket),
                "TRANS2_SET_FILE_INFORMATION response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse2 =
                (SmbTrans2SetFileInformationResponsePacket)response2;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                trans2SetFileInformationResponse.SmbHeader.Status,
                "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS.");

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_DISCONNECT request

            // Create the SMB_COM_TREE_DISCONNECT request.
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            // Send the TreeDisconnect request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            // Check whether server returns a SMB_COM_TREE_DISCONNECT response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_LOGOFF_ANDX request

            // Create the SMB_COM_LOGOFF_ANDX request.
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            // Send the LogOff request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            // Check whether server returns a response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion

            #region Capture requirement r109590

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109590");

            //
            // Verify MS-SMB requirement: MS-SMB_R109590
            //
            bool isVerifyR109590 =
                VerifyisVerifyTrans2SetFileInformation(
                    trans2SetFileInformationResponse,
                    trans2SetFileInformationResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109590,
                109590,
                @"<77> Section 2.2.8.4: Reserved (3 bytes): reply is the same whether zero or non-zero");

            #endregion
        }
Пример #11
0
        public void TraditionalTestCase_IgnoreFields_Create_01_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionSetupResponse.SmbHeader.Uid, path);

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(treeconnectRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

                #region Capture requirements r11008

                // Check the response validity by verifying the Status field in the SMB Header packet.
                SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket;;

                // Add the debug information
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R11008");

                //
                // Verify MS-SMB requirement: MS-SMB_R11008
                //

                // When the session setup is in-progress, the client should have not been granted access, then expects a STATUS_ACCESS_DENIED from server
                Site.CaptureRequirementIfAreEqual <uint>(
                    (uint)MessageStatus.AccessDenied,
                    smbErrorResponsePacket.SmbHeader.Status,
                    11008,
                    @"[In Receiving an SMB_COM_TREE_CONNECT_ANDX Request] If no access is granted for the client on this share, 
                the server MUST fail the request with STATUS_ACCESS_DENIED.");

                #endregion
            }

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            path = Site.Properties["SutNtfsShare1FullName"];
            treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the Create request.
            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest2"];
            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            #region Set the request parameters

            StackCifs.SMB_COM_NT_CREATE_ANDX_Request_SMB_Parameters createRequestSmbParameters =
                createRequest.SmbParameters;

            // Reserved bits in ExtFileAttributes field set to 0.
            createRequestSmbParameters.ExtFileAttributes = 0;

            // Set the Flags field with
            // NT_CREATE_REQUEST_OPLOCK, NT_CREATE_OPEN_TARGET_DIR and NT_CREATE_REQUEST_EXTENDED_RESPONSE.
            createRequestSmbParameters.Flags = createRequestSmbParameters.Flags & (uint)(
                CreateFlags.NT_CREATE_REQUEST_OPLOCK
                | CreateFlags.NT_CREATE_OPEN_TARGET_DIR
                | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE);

            createRequest.SmbParameters = createRequestSmbParameters;

            #endregion

            // Send the SMB_COM_NT_CREATE_ANDX request with the File_Open_If flag and expect the response
            // in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check if server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_CLOSE request

            // Create the Close request.
            ushort fileId = createResponse.SmbParameters.FID;
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the Create request.
            createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            #region Set the request parameters

            createRequestSmbParameters = createRequest.SmbParameters;

            // The ExtFileAttributes field is set to ATTR_READONLY(0x001).
            createRequestSmbParameters.ExtFileAttributes = 1;

            // Set the Flags field with
            // NT_CREATE_REQUEST_OPLOCK, NT_CREATE_OPEN_TARGET_DIR and NT_CREATE_REQUEST_EXTENDED_RESPONSE.
            createRequestSmbParameters.Flags = createRequestSmbParameters.Flags & (uint)(
                CreateFlags.NT_CREATE_REQUEST_OPLOCK
                | CreateFlags.NT_CREATE_OPEN_TARGET_DIR
                | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE);

            createRequest.SmbParameters = createRequestSmbParameters;

            #endregion

            // Send the Create request with the File_Open_If flag and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse2 = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse2.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #region Capture requirements r109027, r109243

            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109027");

            //
            // Verify MS-SMB requirement: MS-SMB_R109027
            //
            bool isVerifyR109027 = VerifyCreateResponse(createResponse, createResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109027,
                109027,
                @"[In Extended File Attribute (SMB_EXT_FILE_ATTR) Extensions]Reserved 0xFFFF8048:
                Reply is the same no matter what value is used.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109243");

            //
            // Verify MS-SMB requirement: MS-SMB_R109243
            //
            bool isVerifyR109243 = VerifyCreateResponse(createResponse, createResponse2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109243,
                109243,
                @"[In Client Request Extensions]Flags (4 bytes):
                For Unused bits, reply is the same no matter what value is used.");

            #endregion

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse2.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            createRequest = smbClientStack.CreateCreateRequest(
                treeId,
                fileName,
                StackCifs.NtTransactDesiredAccess.GENERIC_READ
                | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                StackCifs.SMB_EXT_FILE_ATTR.NONE,
                StackCifs.NtTransactShareAccess.NONE,
                StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                NtTransactCreateOptions.FILE_OPEN_REQUIRING_OPLOCK,
                StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the Create request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse3 = (SmbNtCreateAndxResponsePacket)response;

            if (sutOsVersion == Platform.Win7 || sutOsVersion == Platform.Win2K8R2)
            {
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    createResponse3.SmbHeader.Status,
                    "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

                #region Cpature requirements r9459

                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R9459");

                //
                // Verify MS-SMB requirement: MS-SMB_R9459
                //
                bool isVerifyR9549 = createResponse3.SmbHeader.Status == (uint)SmbStatus.STATUS_SUCCESS;

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR9549,
                    9549,
                    @"<51> Section 2.2.4.9.1: Windows 7 and Windows Server 2008 R2 also support 
                    two new CreateOptions flags:FILE_OPEN_REQUIRING_OPLOCK (0x00010000),FILE_DISALLOW_EXCLUSIVE (0x00020000).");

                #endregion
            }

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse3.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            fileName      = Site.Properties["SutShareTest2"];
            createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            #region Set the request parameters

            createRequestSmbParameters = createRequest.SmbParameters;
            createRequestSmbParameters.ExtFileAttributes = 0;

            // Set the Flags field with
            // NT_CREATE_REQUEST_OPLOCK, NT_CREATE_OPEN_TARGET_DIR and NT_CREATE_REQUEST_EXTENDED_RESPONSE.
            createRequestSmbParameters.Flags = createRequestSmbParameters.Flags & (uint)(
                CreateFlags.NT_CREATE_REQUEST_OPLOCK
                | CreateFlags.NT_CREATE_OPEN_TARGET_DIR
                | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE);

            createRequest.SmbParameters = createRequestSmbParameters;

            #endregion

            // Send the Create request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse4 = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse4.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #region Cpature requirements r109550, r5227, r405227

            if (sutOsVersion == Platform.Win7 || sutOsVersion == Platform.Win2K8R2)
            {
                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109550");

                //
                // Verify MS-SMB requirement: MS-SMB_R109550
                //
                bool isVerifyR109550 = VerifyCreateResponse(createResponse3, createResponse4);

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR109550,
                    109550,
                    @"<51> Section 2.2.4.9.1:FILE_OPEN_REQUIRING_OPLOCK (0x00010000) 
                reply from Windows 7 and Windows Server 2008 R2  is the same 
                whether zero or non-zero is used in this field.");
            }

            // As all the marked Unused fields that have been ignored are verified, this RS is covered by it.
            Site.CaptureRequirement(
                5227,
                @"[In Message Syntax]Unless otherwise noted, 
                 whatever the values of fields marked as Unused are, reply is the same upon receipt.");

            // As all the unused or reserved bits in bit fields that are ignored, this RS can be verified directly.
            Site.CaptureRequirement(
                405227,
                @"[In Message Syntax]Unless otherwise noted, 
                 whatever the values of unused or reserved bits in bit fields  are, reply is the same upon receipt.");

            #endregion

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse4.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            createRequest = smbClientStack.CreateCreateRequest(
                treeId,
                fileName,
                StackCifs.NtTransactDesiredAccess.GENERIC_READ
                | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                StackCifs.SMB_EXT_FILE_ATTR.NONE,
                StackCifs.NtTransactShareAccess.NONE,
                StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                NtTransactCreateOptions.FILE_DISALLOW_EXCLUSIVE,
                StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the Create request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse5 = (SmbNtCreateAndxResponsePacket)response;

            if (sutOsVersion == Platform.Win7 || sutOsVersion == Platform.Win2K8R2)
            {
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    createResponse5.SmbHeader.Status,
                    "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

                #region Cpature requirements r9459, r119551

                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R9459");

                //
                // Verify MS-SMB requirement: MS-SMB_R9459
                //
                bool isVerifyR9549 = createResponse5.SmbHeader.Status == (uint)SmbStatus.STATUS_SUCCESS;

                Site.CaptureRequirementIfIsTrue(
                    isVerifyR9549,
                    9549,
                    @"<51> Section 2.2.4.9.1: Windows 7 and Windows Server 2008 R2 also support 
                    two new CreateOptions flags:FILE_OPEN_REQUIRING_OPLOCK (0x00010000),FILE_DISALLOW_EXCLUSIVE (0x00020000).");

                //
                // Add the comment information for debugging
                //
                Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R119551");

                //
                // Verify MS-SMB requirement: MS-SMB_R119551
                //
                bool isVerifyR119551 = VerifyCreateResponse(createResponse4, createResponse5);
                Site.CaptureRequirementIfIsTrue(
                    isVerifyR119551,
                    119551,
                    @"<51> Section 2.2.4.9.1: FILE_DISALLOW_EXCLUSIVE (0x00020000) reply from Windows 7 
                and Windows Server 2008 R2 is the same whether zero or non-zero is used in this field.");

                #endregion
            }

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            fileId       = createResponse5.SmbParameters.FID;
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_DISCONNECT request

            // Create the SMB_COM_TREE_DISCONNECT request.
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            // Send the TreeDisconnect request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            // Check whether server returns a SMB_COM_TREE_DISCONNECT response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_LOGOFF_ANDX request

            // Create the SMB_COM_LOGOFF_ANDX request.
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            // Send the LogOff request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_LOGOFF_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }
 /// <summary>
 /// Deep copy constructor. 
 /// </summary>
 public SmbTreeConnectAndxResponsePacket(SmbTreeConnectAndxResponsePacket packet)
     : base(packet)
 {
 }
        public void TraditionalTestCase_IgnoreFields_QueryQuota_06_Case()
        {
            // StartSidOffset (4 bytes):  If StartSidLength is non-zero,
            // then this field MUST represent the offset from the start of the NT_Trans_Data to the specific SidList entry
            // at which to begin user quota information enumeration.
            // Otherwise, this field SHOULD be set to zero and MUST be ignored by the server.

            // This case sets it to 2 and see if the server ignores it.

            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create a SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create a SMB_COM_NT_CREATE_ANDX request.
            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest2"];
            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_ALL,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the SMB_COM_NT_CREATE_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check if server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the NT_TRANSACT_QUERY_QUOTA request

            // 0 indicates that there is no SidList.
            int sidListLength = 0;

            // 0 indicates that there is no StartSid.
            int startSidLength = 0;

            // Set StartSidOffset to 2
            int startSidOffset = 2;

            // Create a NT_TRANSACT_QUERY_QUOTA request.
            ushort fileId = createResponse.SmbParameters.FID;
            byte   length = createResponse.SmbParameters.WordCount;
            SmbNtTransQueryQuotaRequestPacket nTTransQueryQuotaRequest =
                smbClientStack.CreateNTTransQueryQuotaRequest(
                    fileId,
                    true,
                    false,
                    sidListLength,
                    startSidLength,
                    startSidOffset);

            // Send the NT_TRANSACT_QUERY_QUOTA request and expect a response in the timeout milliseconds.
            smbClientStack.SendPacket(nTTransQueryQuotaRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "NT_TRANSACT_QUERY_QUOTA response should not be null.");

            // Check whether server returns a NT_TRANSACT_QUERY_QUOTA response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtTransQueryQuotaResponsePacket),
                "NT_TRANSACT_QUERY_QUOTA response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtTransQueryQuotaResponsePacket nTTransQueryQuotaResponse = (SmbNtTransQueryQuotaResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                nTTransQueryQuotaResponse.SmbHeader.Status,
                "NT_TRANSACT_QUERY_QUOTA response status should be SUCCESS.");

            // Check the response validity by verifying the ParameterCount field in the response.
            Site.Assert.AreEqual <uint>(
                4,
                nTTransQueryQuotaResponse.SmbParameters.ParameterCount,
                "parameterCount should be 4 in the nTTransQueryQuota response");

            #endregion

            #region Send the SMB_CLOSE request

            // Create the SMB_CLOSE request.
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            // Send the Close request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                @"SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                @"SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                @"SMB_CLOSE response status should be SUCCESS.");
            #endregion

            #region Send the SMB_COM_TREE_DISCONNECT request

            // Create the SMB_COM_TREE_DISCONNECT request.
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            // Send the TreeDisconnect request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            // Check whether server returns a SMB_COM_TREE_DISCONNECT response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_LOGOFF_ANDX request

            // Create the SMB_COM_LOGOFF_ANDX request.
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            // Send the LogOff request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_LOGOFF_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }
        public void TraditionalTestCase_IgnoreFields_FIND_FIRST2_02_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server return a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // TreeConnect
            string path = Site.Properties["SutNtfsShare1FullName"];

            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(
                    sessionUid,
                    path);

            smbClientStack.SendPacket(treeconnectRequest);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");
            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            ushort treeId = treeConnectResponse.SmbHeader.Tid;

            // The file name can be any string.
            string fileName = "Dir1";

            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_ALL,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            smbClientStack.SendPacket(createRequest);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");
            #endregion

            #region Send the TRANS2_FIND_FIRST2 request
            ushort searchCount = ushort.Parse(Site.Properties["SmbTransportSearchCount"]);
            ushort fileId      = createResponse.SmbParameters.FID;
            byte   length      = createResponse.SmbParameters.WordCount;
            SmbTrans2FindFirst2RequestPacket Trans2FindFirst2Request =
                smbClientStack.CreateTrans2FindFirst2Request(
                    treeId,
                    fileName,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    searchCount,
                    StackCifs.Trans2FindFlags.SMB_FIND_CONTINUE_FROM_LAST,
                    (StackCifs.SmbFileAttributes) 0x10,
                    StackCifs.Trans2FindFirst2SearchStorageType.FILE_DIRECTORY_FILE,
                    true,
                    true,
                    FindInformationLevel.SMB_INFO_STANDARD);

            smbClientStack.SendPacket(Trans2FindFirst2Request);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "TRANS2_FIND_FIRST2 response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTrans2FindFirst2ResponsePacket),
                "TRANS2_FIND_FIRST2 response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2FindFirst2ResponsePacket trans2FindFirst2Response = (SmbTrans2FindFirst2ResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                trans2FindFirst2Response.SmbHeader.Status,
                "TRANS2_FIND_FIRST2 response status should be SUCCESS.");

            #endregion

            #region Send the TRANS2_FIND_NEXT2 request

            ushort searchId = trans2FindFirst2Response.Trans2Parameters.SID;

            // Trans2FindNext2
            uint resumeKey = 0;

            SmbTrans2FindNext2RequestPacket trans2FindNext2Request =
                smbClientStack.CreateTrans2FindNext2Request(
                    treeId,
                    fileName,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    searchCount,
                    searchId,
                    resumeKey,
                    StackCifs.Trans2FindFlags.SMB_FIND_CONTINUE_FROM_LAST,
                    false,
                    true,
                    FindInformationLevel.SMB_INFO_STANDARD);

            smbClientStack.SendPacket(trans2FindNext2Request);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "TRANS2_FIND_NEXT2 response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTrans2FindNext2ResponsePacket),
                "TRANS2_FIND_NEXT2 response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2FindNext2ResponsePacket smbTrans2FindNext2ResponsePacket1 =
                (SmbTrans2FindNext2ResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                smbTrans2FindNext2ResponsePacket1.SmbHeader.Status,
                "TRANS2_FIND_NEXT2 response status should be SUCCESS.");

            #endregion

            #region Send the TRANS2_FIND_FIRST2

            SmbTrans2FindFirst2RequestPacket Trans2FindFirst2Request2 =
                smbClientStack.CreateTrans2FindFirst2Request(
                    treeId,
                    fileName,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    searchCount,
                    StackCifs.Trans2FindFlags.SMB_FIND_CONTINUE_FROM_LAST,
                    (StackCifs.SmbFileAttributes) 0x7F,
                    StackCifs.Trans2FindFirst2SearchStorageType.FILE_DIRECTORY_FILE,
                    true,
                    true,
                    FindInformationLevel.SMB_INFO_STANDARD);

            smbClientStack.SendPacket(Trans2FindFirst2Request2);

            StackPacket response2 = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response2,
                "TRANS2_FIND_FIRST2 response should not be null.");

            Site.Assert.IsInstanceOfType(
                response2,
                typeof(SmbTrans2FindFirst2ResponsePacket),
                "TRANS2_FIND_FIRST2 response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2FindFirst2ResponsePacket trans2FindFirst2Response2 = (SmbTrans2FindFirst2ResponsePacket)response2;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                trans2FindFirst2Response2.SmbHeader.Status,
                "TRANS2_FIND_FIRST2 response status should be SUCCESS.");

            ushort searchId2 = trans2FindFirst2Response2.Trans2Parameters.SID;

            SmbTrans2FindNext2RequestPacket trans2FindNext2Request2 =
                smbClientStack.CreateTrans2FindNext2Request(
                    treeId,
                    fileName,
                    StackCifs.Trans2SmbParametersFlags.NONE,
                    searchCount,
                    searchId2,
                    resumeKey,
                    StackCifs.Trans2FindFlags.SMB_FIND_CONTINUE_FROM_LAST,
                    false,
                    true,
                    FindInformationLevel.SMB_INFO_STANDARD);

            smbClientStack.SendPacket(trans2FindNext2Request2);

            response2 = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response2,
                "TRANS2_FIND_NEXT2 response should not be null.");

            Site.Assert.IsInstanceOfType(
                response2,
                typeof(SmbTrans2FindNext2ResponsePacket),
                "TRANS2_FIND_NEXT2 response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTrans2FindNext2ResponsePacket smbTrans2FindNext2ResponsePacket2 =
                (SmbTrans2FindNext2ResponsePacket)response2;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                smbTrans2FindNext2ResponsePacket2.SmbHeader.Status,
                "TRANS2_FIND_NEXT2 response status should be SUCCESS.");

            #endregion

            #region Capture requirements r109033, r109056

            // if they are the same, verify R109033(R9033) and R109056(R9056).

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109033");

            //
            // Verify MS-SMB requirement: MS-SMB_R109033
            //
            bool isVerifyR109033 =
                VerifySmbTrans2FindNext2ResponsePacket(
                    smbTrans2FindNext2ResponsePacket1,
                    smbTrans2FindNext2ResponsePacket2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109033,
                109033,
                @"[In File System Attribute Extensions]
                Whatever the value of it[any bit that is not listed in this section] is, 
                the receiver's reply is the same.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109056");

            //
            // Verify MS-SMB requirement: MS-SMB_R109056
            //
            bool isVerifyR109056 =
                VerifySmbTrans2FindNext2ResponsePacket(
                    smbTrans2FindNext2ResponsePacket1,
                    smbTrans2FindNext2ResponsePacket2);

            Site.CaptureRequirementIfIsTrue(
                isVerifyR109056,
                109056,
                @"[In File System Attribute Extensions] whatever the values of Reserved 0xFE007E00: 
               replies are the same no matter what value is used when the message is received.");

            #endregion

            #region Send the SMB_CLOSE request


            // Close
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            smbClientStack.SendPacket(CloseRequest);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            // TreeDisconnect
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            smbClientStack.SendPacket(treeDisconnectRequest);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_LOGOFF_ANDX request

            // LogOff
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            smbClientStack.SendPacket(logoffRequest);

            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }
Пример #15
0
        public void TraditionalTestCase_Disconnect_14_Case()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateRequest.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED,
            // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS.
            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.IsTrue(
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED ||
                (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            // Create the second SMB_COM_SESSION_SETUP_ANDX request.
            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;
            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds.
                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");

                // Check the response validity by verifying the Status field in the SMB Header packet.
                sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
                Site.Assert.AreEqual <uint>(
                    (uint)SmbStatus.STATUS_SUCCESS,
                    sessionSetupResponse.SmbHeader.Status,
                    "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");
            }

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            // Create the SMB_COM_TREE_CONNECT_ANDX request.
            string path = Site.Properties["SutNtfsShare1FullName"];
            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            #region Set the request parameters

            StackCifs.SMB_COM_TREE_CONNECT_ANDX_Request_SMB_Parameters treeconnectRequestSmbParameters =
                treeconnectRequest.SmbParameters;

            treeconnectRequestSmbParameters.Flags =
                (ushort)(treeconnectRequestSmbParameters.Flags
                         | (ushort)StackSmb.TreeConnectFlags.TREE_CONNECT_ANDX_DISCONNECT_TID);

            treeconnectRequest.SmbParameters = treeconnectRequestSmbParameters;

            #endregion

            // Send the SMB_COM_TREE_CONNECT_ANDX request and expect a response in the timeout milliseconds.
            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            // Create the SMB_COM_NT_CREATE_ANDX request.
            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest2"];
            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.GENERIC_READ
                    | StackCifs.NtTransactDesiredAccess.GENERIC_WRITE,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.NONE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            // Send the SMB_COM_NT_CREATE_ANDX request and expect a response in the timeout milliseconds.
            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the NT_TRANSACT_QUERY_QUOTA request

            // 0 indicates that there is no SidList.
            int sidListLength = 0;

            // 0 indicates that there is no StartSid.
            int startSidLength = 0;

            // 90 represents the offset of the StartSid in the parameter buffer.
            int startSidOffset = 90;

            // Create the NT_TRANSACT_QUERY_QUOTA request.
            ushort fileId = createResponse.SmbParameters.FID;
            SmbNtTransQueryQuotaRequestPacket nTTransQueryQuotaRequest =
                smbClientStack.CreateNTTransQueryQuotaRequest(
                    fileId,
                    true,
                    false,
                    sidListLength,
                    startSidLength,
                    startSidOffset);

            // Send the NT_TRANSACT_QUERY_QUOTA request and expect a response in the timeout milliseconds.
            smbClientStack.SendPacket(nTTransQueryQuotaRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "NT_TRANSACT_QUERY_QUOTA response should not be null.");

            // Check whether server returns a NT_TRANSACT_QUERY_QUOTA response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtTransQueryQuotaResponsePacket),
                "NT_TRANSACT_QUERY_QUOTA response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtTransQueryQuotaResponsePacket nTTransQueryQuotaResponse = (SmbNtTransQueryQuotaResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                nTTransQueryQuotaResponse.SmbHeader.Status,
                "NT_TRANSACT_QUERY_QUOTA response status should be SUCCESS.");

            // Check the response validity by verifying the ParameterCount field in the response.
            Site.Assert.AreEqual <uint>(
                4,
                nTTransQueryQuotaResponse.SmbParameters.ParameterCount,
                "parameterCount should be 4 in the nTTransQueryQuota response");

            #endregion

            #region Capture requirement r10357

            // according to  theTD , 0x0001 is the value of, TREE_CONNECT_ANDX_DISCONNECT_TID.
            if (((uint)nTTransQueryQuotaRequest.SmbHeader.Flags & 0x0001) == 0x0001)
            {
                // The logic above has disconnect the tree connect specified by the TID
                // in the SMB header of the request. this RS has been verified as it.
                Site.CaptureRequirement(
                    10357,
                    @"[In Client Request Extensions,TREE_CONNECT_ANDX_DISCONNECT_TID]
                    If set, the tree connect specified by the TID in the SMB header of the request is 
                    disconnected when the server sends the response in Windows.");
            }

            #endregion

            #region Disconnect

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }
        public void TraditionalTestCase_LARGE_Read_Write_10()
        {
            #region Connect to the specified server

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            // Create a SMB_COM_NEGOTIATE request.
            SmbNegotiateRequestPacket negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds.
            smbClientStack.SendPacket(negotiateRequest);
            StackPacket response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateResponse.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the first SMB_COM_SESSION_SETUP_ANDX  Request

            SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse(
                typeof(SmbSecurityPackage),
                Site.Properties["SmbSecurityPackageType"] as string,
                true);

            // Create the first SMB_COM_SESSION_SETUP_ANDX request.
            SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest =
                smbClientStack.CreateFirstSessionSetupRequest(
                    smbSecurityPackage,
                    serverName,
                    domainName,
                    userName,
                    password);

            #region Set up the request parameters

            SMB_COM_SESSION_SETUP_ANDX_Request_SMB_Parameters sessionSetupParam = sessionSetupAndxRequest.SmbParameters;
            sessionSetupParam.Capabilities       |= 0xC000;
            sessionSetupAndxRequest.SmbParameters = sessionSetupParam;

            #endregion

            smbClientStack.SendPacket(sessionSetupAndxRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;

            #endregion

            #region Send the second SMB_COM_SESSION_SETUP_ANDX  request

            ushort sessionUid = sessionSetupResponse.SmbHeader.Uid;

            if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED)
            {
                SmbSessionSetupAndxRequestPacket secondSessionSetupRequest =
                    smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage);

                sessionSetupParam = sessionSetupAndxRequest.SmbParameters;
                sessionSetupParam.Capabilities       |= 0xC000;
                sessionSetupAndxRequest.SmbParameters = sessionSetupParam;

                smbClientStack.SendPacket(secondSessionSetupRequest);
                response = smbClientStack.ExpectPacket(timeout);

                // Check whether server returns a response.
                Site.Assert.IsNotNull(
                    response,
                    "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

                // Check whether server returns a SMB_COM_SESSION_SETUP_ANDX response.
                Site.Assert.IsInstanceOfType(
                    response,
                    typeof(SmbSessionSetupAndxResponsePacket),
                    "SMB_COM_SESSION_SETUP_ANDX response should be received.");
            }

            // Check the response validity by verifying the Status field in the SMB Header packet.
            sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                sessionSetupResponse.SmbHeader.Status,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            string path = Site.Properties["SutNtfsShare1FullName"];

            SmbTreeConnectAndxRequestPacket treeconnectRequest =
                smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_NT_CREATE_ANDX request

            ushort treeId   = treeConnectResponse.SmbHeader.Tid;
            string fileName = Site.Properties["SutShareTest1"];
            smbClientStack.Capability.Flag |= SmbHeader_Flags_Values.OPLOCK;

            SmbNtCreateAndxRequestPacket createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.FILE_READ_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_WRITE_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_EA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_ATTRIBUTES,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_OPEN_REPARSE_POINT
                    | NtTransactCreateOptions.FILE_SEQUENTIAL_ONLY
                    | NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_WRITE_ADNX request

            ushort fileId = createResponse.SmbParameters.FID;
            //0xFFFE is the max vaule can be written by protocol SDK once call.
            byte[] writeData = new byte[0xFFFE];

            for (int i = 0; i < writeData.Length; i++)
            {
                writeData[i] = (byte)'a';
            }

            SmbWriteAndxRequestPacket writeRequest = smbClientStack.CreateWriteRequest(fileId, 0, writeData, 0x10000);

            smbClientStack.SendPacket(writeRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_WRITE_ADNX response should not be null.");

            // Check whether server returns a SMB_WRITE_ADNX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbWriteAndxResponsePacket),
                "SMB_WRITE_ADNX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbWriteAndxResponsePacket writeResponse = (SmbWriteAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                writeResponse.SmbHeader.Status,
                "SMB_WRITE_ADNX response status should be SUCCESS.");

            #endregion

            #region Verify R6002, R6003

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug,
                         @"Verify MS-SMB_R6003");

            //
            // Verify MS-SMB requirement: MS-SMB_R6003
            //
            Site.CaptureRequirementIfAreEqual <ushort>(
                1,
                writeResponse.SmbParameters.CountHigh,
                6003,
                @"[In Server Response Extensions]CountHigh (2 bytes): If the number of bytes written is equal to 0x00010000( 64 kilobytes),
                 then the server MUST set the two most significant bytes of the length in the CountHigh field.");

            //
            // Add the debug information
            //
            Site.Log.Add(LogEntryKind.Debug,
                         @"Verify MS-SMB_R6002");

            //
            // Verify MS-SMB requirement: MS-SMB_R6002
            //
            Site.CaptureRequirementIfAreEqual <ushort>(
                0,
                writeResponse.SmbParameters.Count,
                6002,
                @"[In Server Response Extensions]CountHigh (2 bytes): If the number of bytes written is equal to 0x00010000( 64 kilobytes),
                 then the server MUST set the two least significant bytes of the length in the Count field of the request.");

            #endregion

            #region Send the SMB_READ_ANDX request

            SmbReadAndxRequestPacket readRequest = smbClientStack.CreateReadRequest(fileId, 17000, 0);

            smbClientStack.SendPacket(readRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_READ_ANDX response should not be null.");

            // Check whether server returns a SMB_READ_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbReadAndxResponsePacket),
                "SMB_READ_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbReadAndxResponsePacket readResponse = (SmbReadAndxResponsePacket)response;

            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                readResponse.SmbHeader.Status,
                "SMB_READ_ANDX response status should be SUCCESS.");

            #endregion

            #region Capture requirements R109957, R9957, R106932

            bool isRequestExt = ((treeconnectRequest.SmbParameters.Flags & 0x0008) == 0x0008);

            if (isRequestExt)
            {
                if (((uint)sessionSetupAndxRequest.SmbParameters.Capabilities & (uint)Capabilities.CapLargeReadx)
                    == (uint)Capabilities.CapLargeReadx)
                {
                    //
                    // Add the debug information
                    //
                    Site.Log.Add(LogEntryKind.Debug,
                                 @"Verify MS-SMB_R9957,ByteCount is {0},
                        MaxBufferSize is {1}",
                                 readResponse.SmbData.ByteCount,
                                 negotiateResponse.SmbParameters.MaxBufferSize);

                    //
                    // Verify MS-SMB requirement: MS-SMB_R9957
                    //
                    Site.CaptureRequirementIfIsTrue(
                        readResponse.SmbData.ByteCount > negotiateResponse.SmbParameters.MaxBufferSize,
                        9957,
                        @"[In Extended Security Response]MaxBufferSize (4 bytes): 
                         The only exceptions in which this maximum buffer size MUST be exceeded are: 
                         When the SMB_COM_WRITE_ANDX command is used and the client and server both support 
                         the CAP_LARGE_WRITEX capability (see the Capabilities field for more information).");

                    //
                    // Add the debug information
                    //
                    Site.Log.Add(LogEntryKind.Debug,
                                 @"Verify MS-SMB_R109957,ByteCount is {0},
                        MaxBufferSize is {1}",
                                 readResponse.SmbData.ByteCount,
                                 negotiateResponse.SmbParameters.MaxBufferSize);

                    //
                    // Verify MS-SMB requirement: MS-SMB_R109957
                    //
                    Site.CaptureRequirementIfIsTrue(
                        readResponse.SmbData.ByteCount > negotiateResponse.SmbParameters.MaxBufferSize,
                        109957,
                        @"[In Extended Security Response]MaxBufferSize (4 bytes): 
                         The exceptions in which this maximum buffer size MUST be exceeded are:
                         When the SMB_COM_WRITE_ANDX command is used and the client and server both support 
                         the CAP_LARGE_WRITEX capability (see the Capabilities field for more information).");

                    // this RS has been covered by the R9957 logic
                    Site.CaptureRequirement(
                        5402,
                        @"When this capability is set by the server (and set by the client in the
                        SMB_COM_SESSION_SETUP_ANDX request), then the maximum server buffer size for 
                        sending data can exceed the MaxBufferSize field.");

                    // this RS has been covered by the R9957 logic
                    Site.CaptureRequirement(
                        206932,
                        @"<32> Section 2.2.4.5.2.1:Windows-based clients and servers support CAP_LARGE_READX, 
                        which permits file transfers larger than the negotiated MaxBufferSize.");

                    //
                    // Add the debug information
                    //
                    Site.Log.Add(LogEntryKind.Comment, "Verify MS-SMB_R106932");

                    //
                    // Verify MS-SMB requirement: MS-SMB_R106932
                    //
                    Site.CaptureRequirementIfIsTrue(
                        Convert.ToInt32(readResponse.SmbData.ByteCount) < 65536,
                        106932,
                        @"<32> Section 2.2.4.5.2.1: With CAP_LARGE_READX enabled, 
                         Windows-based servers set this limit to 64 kilobytes. ");
                }
            }

            #endregion

            #region Disconnect the tree, session and connection.

            // Close1
            SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            // TreeDisconnect
            SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            // LogOff
            SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);

            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                "SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                "SmbClient should not receive any packet after Disconnect method is called.");

            #endregion

            #region Connect

            smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize);

            #endregion

            #region Send the Negotiate request

            smbClientStack.Capability.IsSupportsExtendedSecurity = false;

            negotiateRequest =
                smbClientStack.CreateNegotiateRequest(
                    StackSmb.SignState.NONE,
                    new string[] {
                DialectNameString.PCNET1,
                DialectNameString.LANMAN10,
                DialectNameString.WFW10,
                DialectNameString.LANMAN12,
                DialectNameString.LANMAN21,
                DialectNameString.NTLANMAN
            });

            smbClientStack.SendPacket(negotiateRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NEGOTIATE response should not be null.");

            // Check whether server returns a SMB_COM_NEGOTIATE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNegotiateImplicitNtlmResponsePacket),
                "SMB_COM_NEGOTIATE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            SmbNegotiateImplicitNtlmResponsePacket negotiateImpNtlmResponse
                = (SmbNegotiateImplicitNtlmResponsePacket)response;

            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                negotiateImpNtlmResponse.SmbHeader.Status,
                "SMB_COM_NEGOTIATE response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_SESSION_SETUP_ANDX request

            SmbSessionSetupImplicitNtlmAndxRequestPacket sessionSetupImpNtlmRequest =
                smbClientStack.CreateSessionSetupImplicitNtlmRequest(
                    ImplicitNtlmVersion.NtlmVersion1,
                    domainName,
                    userName,
                    password);

            smbClientStack.SendPacket(sessionSetupImpNtlmRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_SESSION_SETUP_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_SESSION_SETUP_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbSessionSetupImplicitNtlmAndxResponsePacket),
                "SMB_COM_SESSION_SETUP_ANDX response should be received.");

            SmbSessionSetupImplicitNtlmAndxResponsePacket sessionSetupImpNtlmResponse =
                (SmbSessionSetupImplicitNtlmAndxResponsePacket)response;

            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                sessionSetupImpNtlmResponse.SmbHeader.Status,
                "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS.");

            #endregion

            #region Send the SMB_COM_TREE_CONNECT_ANDX request

            sessionUid         = sessionSetupImpNtlmResponse.SmbHeader.Uid;
            path               = Site.Properties["SutNtfsShare1FullName"];
            treeconnectRequest = smbClientStack.CreateTreeConnectRequest(sessionUid, path);

            smbClientStack.SendPacket(treeconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_CONNECT_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeConnectAndxResponsePacket),
                "SMB_COM_TREE_CONNECT_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeConnectResponse.SmbHeader.Status,
                "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS.");

            treeId   = treeConnectResponse.SmbHeader.Tid;
            fileName = Site.Properties["SutShareTest1"];
            smbClientStack.Capability.Flag |= SmbHeader_Flags_Values.OPLOCK;

            #endregion

            #region Send the SMB_NT_CREATE_ANDX request

            createRequest =
                smbClientStack.CreateCreateRequest(
                    treeId,
                    fileName,
                    StackCifs.NtTransactDesiredAccess.FILE_READ_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_WRITE_DATA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_EA
                    | StackCifs.NtTransactDesiredAccess.FILE_READ_ATTRIBUTES,
                    StackCifs.SMB_EXT_FILE_ATTR.NONE,
                    StackCifs.NtTransactShareAccess.FILE_SHARE_READ
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE
                    | StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE,
                    StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                    NtTransactCreateOptions.FILE_OPEN_REPARSE_POINT
                    | NtTransactCreateOptions.FILE_SEQUENTIAL_ONLY
                    | NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE,
                    StackCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS,
                    CreateFlags.NT_CREATE_REQUEST_OPLOCK);

            smbClientStack.SendPacket(createRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_NT_CREATE_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_NT_CREATE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbNtCreateAndxResponsePacket),
                "SMB_COM_NT_CREATE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            createResponse = (SmbNtCreateAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                createResponse.SmbHeader.Status,
                "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS.");

            fileId = createResponse.SmbParameters.FID;

            #endregion

            #region Send the SMB_WRITE_ANDX request

            writeRequest = smbClientStack.CreateWriteRequest(fileId, 0, writeData);

            smbClientStack.SendPacket(writeRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server returns a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_WRITE_ANDX response should not be null.");

            // Check whether server returns a SMB_WRITE_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbWriteAndxResponsePacket),
                "SMB_WRITE_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            writeResponse = (SmbWriteAndxResponsePacket)response;

            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                writeResponse.SmbHeader.Status,
                "SMB_WRITE_ANDX response status should be SUCCESS.");

            #endregion

            #region Capture requirement r9207

            // according to TD , the following condition means non-Extension
            if (((uint)negotiateRequest.SmbHeader.Flags2 & 0x0800) == 0)
            {
                //
                // Add the debug information
                //
                Site.Log.Add(
                    LogEntryKind.Debug,
                    @"Verify MS-SMB_R9207,
                    ByteCount is {0},
                    MaxBufferSize is {1}",
                    writeResponse.SmbParameters.Count,
                    negotiateResponse.SmbParameters.MaxBufferSize);

                //
                // Verify MS-SMB requirement: MS-SMB_R9957
                //
                Site.CaptureRequirementIfIsTrue(
                    writeResponse.SmbParameters.Count > negotiateResponse.SmbParameters.MaxBufferSize,
                    9207,
                    @"[In Non-Extended Security Response]MaxBufferSize (4 bytes): 
                     The only exceptions in which this maximum buffer size MUST be exceeded are:
                     When the SMB_COM_WRITE_ANDX command is used and both the client and server support the 
                     CAP_LARGE_WRITEX capability (see the Capabilities field for more information).");
            }

            #endregion

            #region Disconnect the tree, session and connection.

            // Close1
            CloseRequest = smbClientStack.CreateCloseRequest(fileId);

            smbClientStack.SendPacket(CloseRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_CLOSE response should not be null.");

            // Check whether server returns a SMB_CLOSE response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbCloseResponsePacket),
                "SMB_CLOSE response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            closeResponse = (SmbCloseResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                closeResponse.SmbHeader.Status,
                "SMB_CLOSE response status should be SUCCESS.");

            // TreeDisconnect
            treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId);

            smbClientStack.SendPacket(treeDisconnectRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_TREE_DISCONNECT response should not be null.");

            // Check whether server returns a SMB_COM_TREE_DISCONNECT response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbTreeDisconnectResponsePacket),
                "SMB_COM_TREE_DISCONNECT response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                treeDisconnectResponse.SmbHeader.Status,
                @"SMB_COM_TREE_DISCONNECT response status should be SUCCESS.");

            // LogOff
            logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid);
            smbClientStack.SendPacket(logoffRequest);
            response = smbClientStack.ExpectPacket(timeout);

            // Check whether server return a response.
            Site.Assert.IsNotNull(
                response,
                "SMB_COM_LOGOFF_ANDX response should not be null.");

            // Check whether server returns a SMB_COM_LOGOFF_ANDX response.
            Site.Assert.IsInstanceOfType(
                response,
                typeof(SmbLogoffAndxResponsePacket),
                "SMB_COM_LOGOFF_ANDX response should be received.");

            // Check the response validity by verifying the Status field in the SMB Header packet.
            logoffResponse = (SmbLogoffAndxResponsePacket)response;
            Site.Assert.AreEqual <uint>(
                (uint)SmbStatus.STATUS_SUCCESS,
                logoffResponse.SmbHeader.Status,
                @"SMB_COM_LOGOFF_ANDX response status should be SUCCESS.");

            // Disconnect
            smbClientStack.Disconnect();

            Site.Assert.IsFalse(
                smbClientStack.IsDataAvailable,
                @"SmbClient should not receive any packet after Disconnect method is called.");

            #endregion
        }