public void CreateRequest(
            int messageId,
            int sessionId,
            int treeId,
            int desiredAccess,
            CreateDisposition createDisposition,
            [Domain("ImpersonationLevel")] int impersonationLevel,
            string fileName,
            ShareType shareType,
            bool isSigned,
            bool isOpenByFileId,
            bool isDirectoryFile,
            bool isMaximumAllowedSet)
        {
            #region Create Packet

            SmbNtCreateAndxRequestPacket smbPacket = new SmbNtCreateAndxRequestPacket();
            ushort uid = (ushort)this.uId[(uint)sessionId];
            ushort tid = (ushort)this.tId[(uint)treeId];
            string shareName = string.Empty;
            CreateFlags createFlags;
            bool isCreateDirectory = false;

            if (fileName != Site.Properties["SutShareExistFile"].ToString())
            {
                if (createDisposition == CreateDisposition.FileOpenIf)
                {
                    this.createActionInternal = this.createActionInternal.Add(CreateAction.FileCreated);
                    this.createActionInternal = this.createActionInternal.Add(CreateAction.FileDoesNotExist);
                }
            }

            if (shareType == ShareType.NamedPipe)
            {
                if (SmbAdapter.isMessageModePipe)
                {
                    shareName = Site.Properties["SutShareMessagePipe"];
                }
                else
                {
                    shareName = Site.Properties["SutShareStreamPipe"];
                }

                isCreateDirectory = false;
            }
            else
            {
                if (fileName == Site.Properties["SutShareTest1"])
                {
                    shareName = Site.Properties["SutShareTest1"];
                    isCreateDirectory = false;
                }
                else if (fileName == Site.Properties["SutShareTest2"])
                {
                    shareName = Site.Properties["SutShareTest2"];
                    isCreateDirectory = false;
                }
                else if (fileName == Site.Properties["SutShareExistFile"])
                {
                    shareName = Site.Properties["SutShareExistFile"];
                    isCreateDirectory = false;
                }
                else if (fileName.Contains("."))
                {
                    shareName = fileName;
                    isCreateDirectory = false;
                }
                else
                {
                    shareName = fileName;
                    isCreateDirectory = true;
                }
            }

            this.openedFileName = shareName;

            if (isCreateDirectory)
            {
                createFlags = CreateFlags.NT_CREATE_OPEN_TARGET_DIR | CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE;
            }
            else
            {
                createFlags = CreateFlags.NT_CREATE_REQUEST_EXTENDED_RESPONSE;
            }

            NamespaceCifs.NtTransactShareAccess shareAccess =
                (NamespaceCifs.NtTransactShareAccess)ushort.Parse(Site.Properties["SmbTransportShareAccess"]);

            NamespaceCifs.SMB_EXT_FILE_ATTR extFileAttributes = NamespaceCifs.SMB_EXT_FILE_ATTR.NONE;

            NamespaceCifs.NtTransactCreateDisposition ntCreateDisposition =
                (NamespaceCifs.NtTransactCreateDisposition)createDisposition;

            NtTransactCreateOptions createOption = NtTransactCreateOptions.FILE_DIRECTORY_FILE;
            if (isOpenByFileId && isDirectoryFile)
            {
                createOption =
                    NtTransactCreateOptions.FILE_OPEN_BY_FILE_ID | NtTransactCreateOptions.FILE_DIRECTORY_FILE;
            }

            if (isOpenByFileId && !isDirectoryFile)
            {
                createOption =
                    NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE | NtTransactCreateOptions.FILE_OPEN_BY_FILE_ID;
            }

            if (!isOpenByFileId && isDirectoryFile)
            {
                createOption = NtTransactCreateOptions.FILE_DIRECTORY_FILE;
            }

            if (!isOpenByFileId && !isDirectoryFile)
            {
                createOption = NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE;
            }

            NamespaceCifs.NtTransactDesiredAccess nTDesiredAccess =
                (NamespaceCifs.NtTransactDesiredAccess)desiredAccess;

            if (nTDesiredAccess == (
                NamespaceCifs.NtTransactDesiredAccess.FILE_READ_DATA
                | NamespaceCifs.NtTransactDesiredAccess.FILE_WRITE_DATA))
            {
                nTDesiredAccess = NamespaceCifs.NtTransactDesiredAccess.GENERIC_ALL;
            }

            if (isCreateDirectory)
            {
                nTDesiredAccess = Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs.NtTransactDesiredAccess.FILE_READ_DATA |
                    Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs.NtTransactDesiredAccess.FILE_READ_ATTRIBUTES |
                    Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs.NtTransactDesiredAccess.SYNCHRONIZE;
                shareAccess = NamespaceCifs.NtTransactShareAccess.FILE_SHARE_READ | NamespaceCifs.NtTransactShareAccess.FILE_SHARE_WRITE;
            }

            smbPacket = this.smbClientStack.CreateCreateRequest(
                tid,
                shareName,
                nTDesiredAccess,
                extFileAttributes,
                shareAccess,
                ntCreateDisposition,
                createOption,
                (NamespaceCifs.NtTransactImpersonationLevel)impersonationLevel,
                createFlags);

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

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

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

            #endregion

            #region Send and Receive ExpectPacket

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

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

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

            VerifyTransport(smbPacketResponse);
            VerifyCommonMessageSyntax(smbPacketResponse);

            if (response.GetType() == typeof(SmbErrorResponsePacket))
            {
                SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket;
                NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader;
                this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status);
            }
            else
            {
                SmbNtCreateAndxResponsePacket smbNtCreateAndXPacket = response as SmbNtCreateAndxResponsePacket;
                NamespaceCifs.SmbHeader ntCreateAndXResponseHeader = smbNtCreateAndXPacket.SmbHeader;

                SMB_COM_NT_CREATE_ANDX_Response_SMB_Parameters ntCreateAndXResponsePayload =
                    smbNtCreateAndXPacket.SmbParameters;

                this.smbFileId = ntCreateAndXResponsePayload.FID;

                int fidValue = (int)uint.MinValue;
                if (!this.fId.ContainsValue(ntCreateAndXResponsePayload.FID))
                {
                    int count = this.fId.Count;
                    this.fId.Add((uint)(count), ntCreateAndXResponsePayload.FID);
                    fidValue = count;
                }
                else
                {
                    foreach (uint key in this.fId.Keys)
                    {
                        if (this.fId[key] == ntCreateAndXResponsePayload.FID)
                        {
                            fidValue = (int)key;
                            break;
                        }
                    }
                }

                uint creatAction = ntCreateAndXResponsePayload.CreationAction;
                Microsoft.Modeling.Set<CreateAction> actionSet = new Microsoft.Modeling.Set<CreateAction>();
                if (creatAction == CreateActionSuperseded)
                {
                    actionSet = actionSet.Add(CreateAction.FileSuperseded);
                }

                if ((creatAction & CreateActionExists) == CreateActionExists)
                {
                    actionSet = actionSet.Add(CreateAction.FileExists);
                }

                if ((creatAction & CreateActionOpened) == CreateActionOpened)
                {
                    actionSet = actionSet.Add(CreateAction.FileOpened);
                    if (!actionSet.Contains(CreateAction.FileExists))
                    {
                        actionSet = actionSet.Add(CreateAction.FileExists);
                    }
                }

                if ((creatAction & CreateActionNotExists) == CreateActionNotExists)
                {
                    actionSet = actionSet.Add(CreateAction.FileDoesNotExist);
                }

                if ((creatAction & CreateActionCreated) == CreateActionCreated)
                {
                    actionSet = actionSet.Add(CreateAction.FileCreated);
                    if (!actionSet.Contains(CreateAction.FileDoesNotExist))
                    {
                        actionSet = actionSet.Add(CreateAction.FileDoesNotExist);
                    }
                }

                if ((creatAction & CreateActionOverwritten) == CreateActionOverwritten)
                {
                    actionSet = actionSet.Add(CreateAction.FileOverwritten);
                }

                bool isIdZero = false;
                bool isNoSubStreams = false;
                if (ntCreateAndXResponsePayload.ResourceType == NamespaceCifs.FileTypeValue.FileTypeDisk)
                {
                    if (SmbAdapter.FsType == FileSystemType.Ntfs.ToString())
                    {
                        isNoSubStreams = false;
                    }
                    else
                    {
                        isNoSubStreams = true;
                    }
                }

                if (SmbAdapter.ServiceShareType == ShareType.NamedPipe)
                {
                    isNoSubStreams = true;
                }

                bool isVolumnGuidZero = false;
                if (!this.checkWindowsImplementation)
                {
                    Site.Log.Add(
                        LogEntryKind.Comment,
                        @"isFileIdZero: {0};
                        isVolumnGUIDZero: {1}",
                        isIdZero,
                        isVolumnGuidZero);
                    isIdZero = true;
                    isVolumnGuidZero = true;
                }

                bool isNotionSupportedForCreate = Boolean.Parse(Site.Properties["IsNotionSupportedForCreate"]);
                bool isSerWantCliLeverageNewCap = Boolean.Parse(Site.Properties["IsSerWantCliLeverageNewCap"]);

                VerifyMessageSyntaxSmbComNtCreateAndXResponse(
                    smbNtCreateAndXPacket,
                    isSerWantCliLeverageNewCap);

                VerifyMessageSyntaxSmbComNtCreateAndXResponseForNotNotionSupported(
                    smbNtCreateAndXPacket,
                    isNotionSupportedForCreate);

                VerifyMessageSyntaxFileIdGeneration(smbNtCreateAndXPacket.SmbParameters.FileId);
                VerifyMessageSyntaxVolumeGUIDGeneration(smbNtCreateAndXPacket.SmbParameters.VolumeGUID);

                if (0x00000003 >= (uint)impersonationLevel)
                {
                    VerifyMessageSyntaxNtTransactCreateRequest(impersonationLevel);
                }

                VerifyMessageSyntaxAccessMasks(smbNtCreateAndXPacket, isDirectoryFile);

                uint computedMaximalAccessRights = (uint)Int32.Parse(Site.Properties["ComputedMaximalAccessRights"]);
                uint computedGuestMaximalAccessRights =
                    (uint)Int32.Parse(Site.Properties["ComputedGuestMaximalAccessRights"]);

                VerifyReceiveSmbComNtCreateAndXRequest(
                    (uint)smbPacket.SmbHeader.Flags,
                    smbNtCreateAndXPacket,
                    computedMaximalAccessRights,
                    computedGuestMaximalAccessRights,
                    impersonationLevel == (int)NamespaceCifs.NtTransactImpersonationLevel.SEC_ANONYMOUS ? true : false);

                //Workaround temp code (Invalid impersonation level)
                if ((string.Equals(Site.Properties["SutPlatformOS"], "Win2K8") && impersonationLevel == 4) &&
                    !bool.Parse(Site.Properties["IsTDI33006Fixed"]))
                {
                    this.ErrorResponse(ntCreateAndXResponseHeader.Mid + this.addMidMark, MessageStatus.BadImpersonationLevel);
                }
                else
                {
                    if (this.createActionInternal.Count == uint.MinValue)
                    {
                        this.CreateResponse(
                            ntCreateAndXResponseHeader.Mid + this.addMidMark,
                            this.QueryUidTable(smbPacketResponse),
                            this.QueryTidTable(smbPacketResponse),
                            fidValue,
                            smbPacketResponse.IsSignRequired,
                            actionSet,
                            isIdZero,
                            isVolumnGuidZero,
                            (ntCreateAndXResponsePayload.Directory == uint.MinValue),
                            true,
                            isNoSubStreams,
                            (MessageStatus)ntCreateAndXResponseHeader.Status);
                    }
                    else
                    {
                        this.CreateResponse(
                            ntCreateAndXResponseHeader.Mid + this.addMidMark,
                            this.QueryUidTable(smbPacketResponse),
                            this.QueryTidTable(smbPacketResponse),
                            fidValue,
                            (smbPacketResponse).IsSignRequired,
                            this.createActionInternal,
                            isIdZero,
                            isVolumnGuidZero,
                            (ntCreateAndXResponsePayload.Directory == 0),
                            true,
                            isNoSubStreams,
                            (MessageStatus)ntCreateAndXResponseHeader.Status);
                    }
                }
                this.createActionInternal = new Microsoft.Modeling.Set<CreateAction>();
            }

            #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
        }
        public void NtTransactCreateRequest(
            int messageId,
            int sessionId,
            int treeId,
            [Domain("ImpersonationLevel")] int impersonationLevel,
            [Domain("FileDomain")] string fileName,
            ShareType shareType,
            bool isSigned)
        {
            #region Create Packet

            SmbNtCreateAndxRequestPacket smbPacket = new SmbNtCreateAndxRequestPacket();

            ushort uid = (ushort)this.uId[(uint)sessionId];
            ushort tid = (ushort)this.tId[(uint)treeId];
            string shareName = string.Empty;
            if (shareType == ShareType.NamedPipe)
            {
                if (SmbAdapter.isMessageModePipe)
                {
                    shareName = Site.Properties["SutShareMessagePipe"];
                }
                else
                {
                    shareName = Site.Properties["SutShareStreamPipe"];
                }
            }
            else
            {
                if (fileName == Site.Properties["SutShareTest1"])
                {
                    shareName = Site.Properties["SutShareTest1"];
                }
                else if (fileName == Site.Properties["SutShareTest2"])
                {
                    shareName = Site.Properties["SutShareTest2"];
                }
                else if (fileName == Site.Properties["SutShareExistFile"])
                {
                    shareName = Site.Properties["SutShareExistFile"];
                }
                else if (fileName.Contains("."))
                {
                    shareName = fileName;
                }
                else
                {
                    shareName = fileName;
                }
            }

            this.openedFileName = shareName;
            uint nTDesiredAccess = (uint)NamespaceCifs.NtTransactDesiredAccess.GENERIC_ALL;

            NamespaceCifs.SMB_EXT_FILE_ATTR extFileAttributes = NamespaceCifs.SMB_EXT_FILE_ATTR.NONE;

            NtTransactCreateOptions createOption = NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE;

            smbPacket = this.smbClientStack.CreateCreateRequest(
                tid,
                shareName,
                (NamespaceCifs.NtTransactDesiredAccess)nTDesiredAccess,
                extFileAttributes,
                NamespaceCifs.NtTransactShareAccess.NONE,
                NamespaceCifs.NtTransactCreateDisposition.FILE_OPEN_IF,
                createOption,
                (NamespaceCifs.NtTransactImpersonationLevel)impersonationLevel,
                CreateFlags.NT_CREATE_REQUEST_OPLOCK);

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

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

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

            #endregion

            #region Send and Receive ExpectPacket

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

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

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

            VerifyTransport(smbPacketResponse);
            VerifyCommonMessageSyntax(smbPacketResponse);

            if (response.GetType() == typeof(SmbErrorResponsePacket))
            {
                SmbErrorResponsePacket smbErrorResponsePacket = response as SmbErrorResponsePacket;
                NamespaceCifs.SmbHeader smbErrorHeader = smbErrorResponsePacket.SmbHeader;
                this.ErrorResponse(smbErrorHeader.Mid + this.addMidMark, (MessageStatus)smbErrorHeader.Status);
            }
            else
            {
                SmbNtCreateAndxResponsePacket smbNtCreateAndXPacket = response as SmbNtCreateAndxResponsePacket;
                NamespaceCifs.SmbHeader ntCreateAndXResponseHeader = smbNtCreateAndXPacket.SmbHeader;

                SMB_COM_NT_CREATE_ANDX_Response_SMB_Parameters ntCreateAndXResponsePayload
                    = smbNtCreateAndXPacket.SmbParameters;

                this.smbFileId = ntCreateAndXResponsePayload.FID;

                if (!this.fId.ContainsValue(ntCreateAndXResponsePayload.FID))
                {
                    int count = this.fId.Count;
                    this.fId.Add((uint)(count), ntCreateAndXResponsePayload.FID);
                }
                else
                {
                    foreach (uint key in this.fId.Keys)
                    {
                        if (this.fId[key] == ntCreateAndXResponsePayload.FID)
                        {
                            break;
                        }
                    }
                }

                uint creatAction = ntCreateAndXResponsePayload.CreationAction;
                Microsoft.Modeling.Set<CreateAction> actionSet = new Microsoft.Modeling.Set<CreateAction>();
                if (creatAction == CreateActionSuperseded)
                {
                    actionSet = actionSet.Add(CreateAction.FileSuperseded);
                }

                if ((creatAction & CreateActionExists) == CreateActionExists)
                {
                    actionSet = actionSet.Add(CreateAction.FileExists);
                }

                if ((creatAction & CreateActionOpened) == CreateActionOpened)
                {
                    actionSet = actionSet.Add(CreateAction.FileOpened);
                    if (!actionSet.Contains(CreateAction.FileExists))
                    {
                        actionSet = actionSet.Add(CreateAction.FileExists);
                    }
                }

                if ((creatAction & CreateActionNotExists) == CreateActionNotExists)
                {
                    actionSet = actionSet.Add(CreateAction.FileDoesNotExist);
                }

                if ((creatAction & CreateActionCreated) == CreateActionCreated)
                {
                    actionSet = actionSet.Add(CreateAction.FileCreated);
                    if (!actionSet.Contains(CreateAction.FileDoesNotExist))
                    {
                        actionSet = actionSet.Add(CreateAction.FileDoesNotExist);
                    }
                }

                if ((creatAction & CreateActionOverwritten) == CreateActionOverwritten)
                {
                    actionSet = actionSet.Add(CreateAction.FileOverwritten);
                }

                bool isIDZero = false;
                bool isVolumnGuidZero = false;
                if (!this.checkWindowsImplementation)
                {
                    Site.Log.Add(
                        LogEntryKind.Comment,
                        @"isFileIdZero: {0};
                        isVolumnGUIDZero: {1}",
                        isIDZero,
                        isVolumnGuidZero);
                    isIDZero = true;
                    isVolumnGuidZero = true;
                }
                //Workaround temp code (Invalid impersonation level)
                if ((string.Equals(Site.Properties["SutPlatformOS"], "Win2K8") && impersonationLevel == 4)
                    && !bool.Parse(Site.Properties["IsTDI33006Fixed"]))
                {
                    this.ErrorResponse(ntCreateAndXResponseHeader.Mid + this.addMidMark, MessageStatus.BadImpersonationLevel);
                }
                else
                {
                    this.NtTransactCreateResponse(
                        ntCreateAndXResponseHeader.Mid + this.addMidMark,
                        QueryUidTable(smbPacketResponse),
                        QueryTidTable(smbPacketResponse),
                        isSigned,
                        (MessageStatus)ntCreateAndXResponseHeader.Status);
                }
            }

            #endregion
        }
        /// <summary>
        /// find the target packet.
        /// </summary>
        /// <param name="smbHeader">the header of smb packet</param>
        /// <param name="channel">the channel to access bytes</param>
        /// <returns>the target packet</returns>
        private static SmbPacket FindTheTargetPacket(SmbHeader smbHeader, Channel channel)
        {
            SmbPacket smbPacket = null;

            switch (smbHeader.Command)
            {
                case SmbCommand.SMB_COM_NEGOTIATE:
                        smbPacket = new SmbNegotiateRequestPacket();
                    break;

                case SmbCommand.SMB_COM_SESSION_SETUP_ANDX:
                    SmbHeader_Flags2_Values flags2 = (SmbHeader_Flags2_Values)smbHeader.Flags2;
                    if ((flags2 & SmbHeader_Flags2_Values.SMB_FLAGS2_EXTENDED_SECURITY)
                        == SmbHeader_Flags2_Values.SMB_FLAGS2_EXTENDED_SECURITY)
                    {
                        smbPacket = new Smb.SmbSessionSetupAndxRequestPacket();
                    }
                    else
                    {
                        smbPacket = new Cifs.SmbSessionSetupAndxRequestPacket();
                    }
                    break;

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

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

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

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

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

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

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

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

                case SmbCommand.SMB_COM_TRANSACTION:
                    SMB_COM_TRANSACTION_Request_SMB_Parameters transaction =
                        channel.Read<SMB_COM_TRANSACTION_Request_SMB_Parameters>();
                    if (transaction.SetupCount == 0)
                    {
                        smbPacket = new SmbTransRapRequestPacket();
                    }
                    else
                    {
                        smbPacket = FindTheTransactionPacket(
                            transaction.SetupCount, (TransSubCommand)transaction.Setup[0]);
                    }
                    break;

                case SmbCommand.SMB_COM_TRANSACTION2:
                    SMB_COM_TRANSACTION2_Request_SMB_Parameters transaction2 =
                        channel.Read<SMB_COM_TRANSACTION2_Request_SMB_Parameters>();
                    smbPacket = FindTheTrans2Packet((Trans2SubCommand)transaction2.Subcommand);
                    break;

                case SmbCommand.SMB_COM_NT_TRANSACT:
                    SMB_COM_NT_TRANSACT_Request_SMB_Parameters ntTransactoin =
                        channel.Read<SMB_COM_NT_TRANSACT_Request_SMB_Parameters>();
                    smbPacket = FindTheNtTransPacket(ntTransactoin.Function, CifsMessageUtils.ToBytesArray<ushort>(ntTransactoin.Setup));
                    break;

                default:
                    break;
            }

            return smbPacket;
        }
Example #5
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
        }
Example #6
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
        }
        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
        }
Example #9
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
        }