Esempio n. 1
0
        public void RequestOplockAndOperateFileRequest(
            RequestedOplockLevel_Values requestedOplockLevel,
            OplockFileOperation fileOperation,
            out OplockLevel_Values grantedOplockLevel,
            out OplockConfig c)
        {
            Smb2CreateContextResponse[] serverCreateContexts;
            string fileName = GetTestFileName(uncSharePath);

            OplockLevel_Values grantedTmp = OplockLevel_Values.OPLOCK_LEVEL_NONE;

            testClient.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts,
                requestedOplockLevel_Values: requestedOplockLevel,
                checker: (header, response) =>
            {
                grantedTmp = response.OplockLevel;
            });

            Site.Log.Add(LogEntryKind.Debug, "OplockLevel granted by server: {0}", grantedTmp);
            grantedOplockLevel = grantedTmp;
            c = oplockConfig;

            oplockLevelOnOpen = grantedTmp;

            fileOperationInvoker = new FileOperationDelegate(FileOperation);
            var task = Task.Run(() => fileOperationInvoker.Invoke(fileOperation, fileName));

            task.Wait(500);// Assume that notification will arrive in .5 sec if there's any
        }
Esempio n. 2
0
 public ModelCreateLeaseRequest(
     CreateOptions_Values createOptions,
     RequestedOplockLevel_Values requestedOplockLevel_Values,
     ModelCreateContextRequest leaseContext,
     LeaseContextType leaseContextType)
     : base(0)
 {
     this.CreateOptions        = createOptions;
     this.RequestedOplockLevel = requestedOplockLevel_Values;
     this.LeaseContext         = leaseContext;
     this.ContextType          = leaseContextType;
 }
Esempio n. 3
0
        public static void RequestOplockAndOperateFileCall(RequestedOplockLevel_Values requestedOplockLevel, OplockFileOperation fileOperation)
        {
            Condition.IsTrue(State == ModelState.Connected);
            Condition.IsNull(Request);

            // <46> Section 2.2.14: Windows-based clients never use exclusive oplocks. Because there are no situations where it would
            // require an exclusive oplock where it would not also require an SMB2_OPLOCK_LEVEL_BATCH, it always requests an SMB2_OPLOCK_LEVEL_BATCH.
            Condition.IsTrue(requestedOplockLevel != RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE &&
                             requestedOplockLevel != RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE &&
                             requestedOplockLevel != RequestedOplockLevel_Values.OPLOCK_LEVEL_EXCLUSIVE);

            Request = new ModelRequestOplockAndTriggerBreakRequest(requestedOplockLevel);
        }
        public uint Create(
            uint treeId,
            string fileName,
            CreateOptions_Values createOptions,
            out FILEID fileId,
            out Smb2CreateContextResponse[] serverCreateContexts,
            RequestedOplockLevel_Values requestedOplockLevel_Values = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
            Smb2CreateContextRequest[] createContexts = null,
            Packet_Header_Flags_Values headerFlag     = Packet_Header_Flags_Values.FLAGS_SIGNED,
            AccessMask accessMask                     = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE,
            ShareAccess_Values shareAccess            = ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE | ShareAccess_Values.FILE_SHARE_DELETE,
            ResponseChecker <CREATE_Response> checker = null,
            ushort creditRequest = 64)
        {
            Packet_Header   header;
            CREATE_Response createResponse;

            uint status = client.Create(
                1,
                creditRequest,
                headerFlag,
                messageId++,
                sessionId,
                treeId,
                fileName,
                accessMask,
                shareAccess,
                createOptions,
                CreateDisposition_Values.FILE_OPEN_IF,
                File_Attributes.NONE,
                ImpersonationLevel_Values.Impersonation,
                SecurityFlags_Values.NONE,
                requestedOplockLevel_Values,
                createContexts,
                out fileId,
                out serverCreateContexts,
                out header,
                out createResponse);

            InnerResponseChecker(checker, header, createResponse);

            grantedCredit = header.CreditRequestResponse;

            return(status);
        }
Esempio n. 5
0
 /// <summary>
 /// Create operation for PrepareOpen operation
 /// </summary>
 private void PrepareOpenCreate(
     Smb2FunctionalClient client,
     uint treeIdBeforeDisconnection,
     string fileName,
     out FILEID fileIdBeforDisconnection,
     out Smb2CreateContextResponse[] serverCreateContexts,
     RequestedOplockLevel_Values requestedOplocklevel,
     Smb2CreateContextRequest[] prepareContext)
 {
     client.Create(
         treeIdBeforeDisconnection,
         fileName,
         CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
         out fileIdBeforDisconnection,
         out serverCreateContexts,
         requestedOplocklevel,
         prepareContext,
         shareAccess: ShareAccess_Values.NONE,
         checker: (HASH_HEADER, response) =>
     {
     });
 }
Esempio n. 6
0
 /// <summary>
 /// Create operation for Open operation
 /// </summary>
 private uint OpenCreate(
     Smb2FunctionalClient client,
     uint treeIdAfterDisconnection,
     string fileName,
     out FILEID fileIdAfterDisconnection,
     out Smb2CreateContextResponse[] serverCreateContexts,
     RequestedOplockLevel_Values requestedOplocklevel,
     Smb2CreateContextRequest[] openContext)
 {
     return(client.Create(
                treeIdAfterDisconnection,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdAfterDisconnection,
                out serverCreateContexts,
                requestedOplocklevel,
                openContext,
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
     {
     }));
 }
        public void RequestOplockAndOperateFileRequest(
            RequestedOplockLevel_Values requestedOplockLevel,
            OplockFileOperation fileOperation,
            out OplockLevel_Values grantedOplockLevel,
            out OplockConfig c)
        {
            Smb2CreateContextResponse[] serverCreateContexts;
            string fileName = "OplockMBT_" + Guid.NewGuid().ToString();

            OplockLevel_Values grantedTmp = OplockLevel_Values.OPLOCK_LEVEL_NONE;

            testClient.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts,
                requestedOplockLevel_Values: requestedOplockLevel,
                checker: (header, response) =>
            {
                grantedTmp = response.OplockLevel;
            });

            Site.Log.Add(LogEntryKind.Debug, "OplockLevel granted by server: {0}", grantedTmp);
            grantedOplockLevel = grantedTmp;
            c = oplockConfig;

            oplockLevelOnOpen = grantedTmp;

            fileOperationInvoker = new FileOperationDelegate(FileOperation);
            fileOperationInvoker.BeginInvoke(fileOperation, fileName, null, null);

            // Assume that notification will arrive in .5 sec if there's any
            // Without such sleep, OplockBreakNotification would not be expected by SE
            Thread.Sleep(500);
        }
Esempio n. 8
0
        public void ReconnectOpenRequest(
            DurableV1ReconnectContext durableV1ReconnectContext,
            DurableV2ReconnectContext durableV2ReconnectContext,
            OplockLeaseType oplockLeaseType,
            LeaseKeyDifferentialType leaseKeyDifferentialType,
            ClientIdType clientIdType,
            CreateGuidType createGuidType)
        {
            if ((oplockLeaseType == OplockLeaseType.LeaseV1 || oplockLeaseType == OplockLeaseType.LeaseV2) &&
                !testConfig.IsLeasingSupported)
            {
                Site.Assert.Inconclusive("Test case is applicable in servers that support leasing.");
            }

            bool isSameLeaseKey   = (leaseKeyDifferentialType == LeaseKeyDifferentialType.SameLeaseKey);
            bool isSameClient     = (clientIdType == ClientIdType.SameClient);
            bool isSameCreateGuid = (createGuidType == CreateGuidType.SameCreateGuid);

            FILEID fileIdAfterDisconnection;

            Smb2CreateContextResponse[] serverCreateContexts;
            IPAddress targetIPAddress;
            string    targetServer;
            string    targetShare;

            #region Construct Create Contexts
            Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext(
                DurableV1RequestContext.DurableV1RequestContextNotExist,
                DurableV2RequestContext.DurableV2RequestContextNotExist,
                durableV1ReconnectContext,
                durableV2ReconnectContext,
                oplockLeaseType,
                isSameLeaseKey,
                isSameCreateGuid);
            #endregion

            #region Client reconnect to server

            Site.Log.Add(LogEntryKind.Debug, "Client reconnect to server");

            #region Reconnect to Common Share or CA Share
            if (!isCAShare)
            {
                targetIPAddress = testConfig.SutIPAddress;
                targetServer    = testConfig.SutComputerName;
                targetShare     = testConfig.BasicFileShare;
            }
            else
            {
                targetIPAddress = testConfig.CAShareServerIP;
                targetServer    = testConfig.CAShareServerName;
                targetShare     = testConfig.CAShareName;
            }

            // Connect to Server
            testClientAfterDisconnection            = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            testClientAfterDisconnection.CreditGoal = 10;
            testClientAfterDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress);

            // Negotiate
            testClientAfterDisconnection.Negotiate(
                requestDialect,
                testConfig.IsSMB1NegotiateEnabled,
                capabilityValue: clientCapabilities,
                // If the reconnect use the same client guid, then keep client guid the same value, otherwise use a new client guid.
                clientGuid: (isSameClient ? clientGuid : Guid.NewGuid()));

            uint status = testClientAfterDisconnection.SessionSetup(
                testConfig.DefaultSecurityPackage,
                targetServer,
                testConfig.AccountCredential,
                testConfig.UseServerGssToken);
            Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Reconnect Session Setup should be successful, actual status is {0}", Smb2Status.GetStatusCode(status));

            // TreeConnect
            testClientAfterDisconnection.TreeConnect(sharePath, out treeIdAfterDisconnection);

            #endregion

            #region Send Create request according to different context combination

            RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
            switch (oplockLeaseType)
            {
            case OplockLeaseType.NoOplockOrLease:
            {
                requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
            }
            break;

            case OplockLeaseType.BatchOplock:
            {
                requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
            }
            break;

            case OplockLeaseType.LeaseV1:
            case OplockLeaseType.LeaseV2:
            {
                requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
            }
            break;
            }

            status = OpenCreate(
                testClientAfterDisconnection,
                treeIdAfterDisconnection,
                fileName,
                out fileIdAfterDisconnection,
                out serverCreateContexts,
                requestedOplockLevel,
                smb2CreateContextRequest);

            #endregion

            DurableHandleResponseContext durableHandleResponse;
            LeaseResponseContext         leaseResponse;
            CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse);
            OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig);

            testClientAfterDisconnection.TreeDisconnect(treeIdAfterDisconnection);
            testClientAfterDisconnection.LogOff();

            #endregion
        }
Esempio n. 9
0
        public void PrepareOpen(
            ModelDialectRevision clientMaxDialect,
            PersistentBitType persistentBit,
            CAShareType connectToCAShare,
            ModelHandleType modelHandleType,
            OplockLeaseType oplockLeaseType)
        {
            // Lease V2 cases only apply on the server implements SMB 3.x family.
            if (oplockLeaseType == OplockLeaseType.LeaseV2)
            {
                testConfig.CheckDialect(DialectRevision.Smb30);
            }

            // Lease V1 cases only apply on the server implements SMB 2.1 and 3.x family.
            if (oplockLeaseType == OplockLeaseType.LeaseV1)
            {
                testConfig.CheckDialect(DialectRevision.Smb21);
            }

            if ((oplockLeaseType == OplockLeaseType.LeaseV1 || oplockLeaseType == OplockLeaseType.LeaseV2) &&
                !testConfig.IsLeasingSupported)
            {
                Site.Assert.Inconclusive("Test case is applicable in servers that support leasing.");
            }

            requestDialect     = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect));
            clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING |
                                 Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL;
            if (persistentBit == PersistentBitType.PersistentBitSet)
            {
                clientCapabilities |= Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES;
            }

            clientGuid       = Guid.NewGuid();
            requestedContext = oplockLeaseType;
            isCAShare        = (connectToCAShare == CAShareType.CAShare);
            IPAddress targetIPAddress;
            string    targetServer;

            #region Connect to Common Share or CA Share
            if (!isCAShare)
            {
                sharePath       = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare);
                fileName        = "PrepareHandle_ConnectTo_CommonShareFile_" + Guid.NewGuid() + ".txt";
                targetIPAddress = testConfig.SutIPAddress;
                targetServer    = testConfig.SutComputerName;
            }
            else
            {
                sharePath       = Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName);
                fileName        = "PrepareHandle_ConnectTo_CAShareFile_" + Guid.NewGuid().ToString() + ".txt";
                targetIPAddress = testConfig.CAShareServerIP;
                targetServer    = testConfig.CAShareServerName;
            }

            testClientBeforeDisconnection            = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            testClientBeforeDisconnection.CreditGoal = 20;
            testClientBeforeDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress);

            testClientBeforeDisconnection.Negotiate(
                requestDialect,
                testConfig.IsSMB1NegotiateEnabled,
                capabilityValue: clientCapabilities,
                clientGuid: clientGuid,
                checker: (header, response) =>
            {
                if (Smb2Utility.IsSmb3xFamily(response.DialectRevision) &&
                    handleConfig.IsPersistentHandleSupported &&
                    persistentBit == PersistentBitType.PersistentBitSet)
                {
                    Site.Assert.IsTrue(
                        response.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES),
                        "The server MUST set SMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " +
                        "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles. " +
                        "Actual capabilities are {0}", response.Capabilities);
                }
            });

            testClientBeforeDisconnection.SessionSetup(
                testConfig.DefaultSecurityPackage,
                targetServer,
                testConfig.AccountCredential,
                testConfig.UseServerGssToken);

            testClientBeforeDisconnection.TreeConnect(sharePath, out treeIdBeforeDisconnection);

            #endregion

            #region Create operation according to the handle type and context
            Smb2CreateContextRequest[]  prepareRequestContext = null;
            Smb2CreateContextResponse[] serverCreateContexts  = null;
            RequestedOplockLevel_Values requestedOplockLevel  = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;

            switch (oplockLeaseType)
            {
            case OplockLeaseType.LeaseV1:
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);

                prepareRequestContext = GetPrepareOpenCreateContext(modelHandleType, oplockLeaseType);
                requestedOplockLevel  = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
            }
            break;

            case OplockLeaseType.LeaseV2:
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2);

                prepareRequestContext = GetPrepareOpenCreateContext(modelHandleType, oplockLeaseType);
                requestedOplockLevel  = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
            }
            break;

            case OplockLeaseType.BatchOplock:
            {
                prepareRequestContext = GetPrepareOpenHandleContext(modelHandleType);
                requestedOplockLevel  = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
            }
            break;

            case OplockLeaseType.NoOplockOrLease:
            {
                prepareRequestContext = GetPrepareOpenHandleContext(modelHandleType);
                requestedOplockLevel  = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
            }
            break;
            }

            PrepareOpenCreate(
                testClientBeforeDisconnection,
                treeIdBeforeDisconnection,
                fileName,
                out fileIdBeforDisconnection,
                out serverCreateContexts,
                requestedOplockLevel,
                prepareRequestContext);

            #endregion
        }
 /// <summary>
 /// Create operation for PrepareOpen operation
 /// </summary>
 private void PrepareOpenCreate(
     Smb2FunctionalClient client,
     uint treeIdBeforeDisconnection,
     string fileName,
     out FILEID fileIdBeforDisconnection,
     out Smb2CreateContextResponse[] serverCreateContexts,
     RequestedOplockLevel_Values requestedOplocklevel,
     Smb2CreateContextRequest[] prepareContext)
 {
     client.Create(
         treeIdBeforeDisconnection,
         fileName,
         CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
         out fileIdBeforDisconnection,
         out serverCreateContexts,
         requestedOplocklevel,
         prepareContext,
         shareAccess: ShareAccess_Values.NONE,
         checker: (HASH_HEADER, response) =>
         {
         });
 }
 public ModelCreateLeaseRequest(
     CreateOptions_Values createOptions,
     RequestedOplockLevel_Values requestedOplockLevel_Values,
     ModelCreateContextRequest leaseContext,
     LeaseContextType leaseContextType)
     : base(0)
 {
     this.CreateOptions = createOptions;
     this.RequestedOplockLevel = requestedOplockLevel_Values;
     this.LeaseContext = leaseContext;
     this.ContextType = leaseContextType;
 }
        public void RequestOplockAndOperateFileRequest(
            RequestedOplockLevel_Values requestedOplockLevel,
            OplockFileOperation fileOperation,
            out OplockLevel_Values grantedOplockLevel,
            out OplockConfig c)
        {
            Smb2CreateContextResponse[] serverCreateContexts;
            string fileName = "OplockMBT_"+ Guid.NewGuid().ToString();

            OplockLevel_Values grantedTmp = OplockLevel_Values.OPLOCK_LEVEL_NONE;
            testClient.Create(
                    treeId,
                    fileName,
                    CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                    out fileId,
                    out serverCreateContexts,
                    requestedOplockLevel_Values: requestedOplockLevel,
                    checker: (header, response) =>
                    {
                        grantedTmp = response.OplockLevel;
                    });

            Site.Log.Add(LogEntryKind.Debug, "OplockLevel granted by server: {0}", grantedTmp);
            grantedOplockLevel = grantedTmp;
            c = oplockConfig;

            oplockLevelOnOpen = grantedTmp;

            fileOperationInvoker = new FileOperationDelegate(FileOperation);
            fileOperationInvoker.BeginInvoke(fileOperation, fileName, null, null);

            // Assume that notification will arrive in .5 sec if there's any
            // Without such sleep, OplockBreakNotification would not be expected by SE
            Thread.Sleep(500);
        }
        public static void RequestOplockAndOperateFileCall(RequestedOplockLevel_Values requestedOplockLevel, OplockFileOperation fileOperation)
        {
            Condition.IsTrue(State == ModelState.Connected);
            Condition.IsNull(Request);

            // <46> Section 2.2.14: Windows-based clients never use exclusive oplocks. Because there are no situations where it would
            // require an exclusive oplock where it would not also require an SMB2_OPLOCK_LEVEL_BATCH, it always requests an SMB2_OPLOCK_LEVEL_BATCH.
            Condition.IsTrue(requestedOplockLevel != RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE
                && requestedOplockLevel != RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE
                && requestedOplockLevel != RequestedOplockLevel_Values.OPLOCK_LEVEL_EXCLUSIVE);

            Request = new ModelRequestOplockAndTriggerBreakRequest(requestedOplockLevel);
        }
        public void PrepareOpen(ModelDialectRevision clientMaxDialect, DurableHandle durableHandle)
        {
            prepareOpenClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            clientGuid        = Guid.NewGuid();
            DialectRevision[] dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect));

            // Connect to Share
            ConnectToShare(
                Site,
                testConfig,
                prepareOpenClient,
                dialects,
                clientGuid,
                testConfig.AccountCredential,
                out dialect,
                out treeId);
            Site.Assert.AreEqual(
                ModelUtility.GetDialectRevision(clientMaxDialect),
                dialect,
                "DialectRevision {0} is expected", ModelUtility.GetDialectRevision(clientMaxDialect));

            // SMB2 Create
            RequestedOplockLevel_Values opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;

            Smb2CreateContextRequest[] createContextRequests = new Smb2CreateContextRequest[0];
            createGuid = Guid.Empty;

            if (durableHandle == DurableHandle.DurableHandle)
            {// durable handle request context with batch opLock
                opLockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
                createGuid  = Guid.NewGuid();

                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                createContextRequests = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateDurableHandleRequest
                    {
                        DurableRequest = createGuid
                    }
                };
            }

            // create
            Smb2CreateContextResponse[] createContextResponse;
            prepareOpenClient.Create(
                treeId,
                GetTestFileName(Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare)),
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponse,
                requestedOplockLevel_Values: opLockLevel,
                createContexts: createContextRequests,
                checker: (header, response) =>
            {
                Site.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should succeed", header.Command);

                if (durableHandle == DurableHandle.DurableHandle)
                {
                    Site.Assert.AreEqual <OplockLevel_Values>(
                        OplockLevel_Values.OPLOCK_LEVEL_BATCH,
                        response.OplockLevel,
                        "OplockLevel should be OPLOCK_LEVEL_BATCH if Durable Handle");
                }
            }
                );

            if (durableHandle == DurableHandle.DurableHandle)
            {
                // check whether response contain Durable Context
                Site.Assert.IsTrue(
                    ContainDurableHandleResponse(createContextResponse),
                    "Durable Handle Response should be in the Create response.");
            }
        }
Esempio n. 15
0
 public ModelRequestOplockAndTriggerBreakRequest(RequestedOplockLevel_Values requestedOplockLevel)
     : base(0)
 {
     this.RequestedOplockLevel = requestedOplockLevel;
 }
        private void FillParameters(ReplayModelLeaseState leaseState,
                                    ReplayModelRequestedOplockLevel requestedOplockLevel,
                                    ReplayModelDurableHandle modelDurableHandle,
                                    Guid createGuid,
                                    Guid leaseKey,
                                    out LeaseStateValues requestLeaseState,
                                    out RequestedOplockLevel_Values oplockLevel,
                                    out Smb2CreateContextRequest[] contexts)
        {
            #region Fill lease state
            switch (leaseState)
            {
            case ReplayModelLeaseState.LeaseStateNotIncludeH:
                requestLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING;
                break;

            case ReplayModelLeaseState.LeaseStateIncludeH:
                requestLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_WRITE_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING;
                break;

            default:
                requestLeaseState = LeaseStateValues.SMB2_LEASE_NONE;
                break;
            }
            #endregion

            #region Fill oplockLevel and lease context
            contexts = new Smb2CreateContextRequest[] { };
            switch (requestedOplockLevel)
            {
            case ReplayModelRequestedOplockLevel.OplockLevelLeaseV1:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);

                oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
                contexts    = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateRequestLease
                    {
                        LeaseKey   = leaseKey,
                        LeaseState = requestLeaseState,
                        LeaseFlags = (uint)LeaseFlagsValues.NONE
                    }
                };
                break;

            case ReplayModelRequestedOplockLevel.OplockLevelLeaseV2:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2);

                oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
                contexts    = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateRequestLeaseV2
                    {
                        LeaseKey   = leaseKey,
                        LeaseState = requestLeaseState,
                        LeaseFlags = (uint)LeaseFlagsValues.NONE
                    }
                };
                break;

            case ReplayModelRequestedOplockLevel.OplockLevelBatch:
                oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
                break;

            case ReplayModelRequestedOplockLevel.OplockLevelII:
                oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_II;
                break;

            default:
                oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
                break;
            }
            #endregion

            #region Fill handle context
            switch (modelDurableHandle)
            {
            case ReplayModelDurableHandle.DurableHandleV1:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                contexts = Smb2Utility.Append <Smb2CreateContextRequest>(contexts,
                                                                         new Smb2CreateDurableHandleRequest
                {
                });
                break;

            case ReplayModelDurableHandle.DurableHandleV2:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                contexts = Smb2Utility.Append <Smb2CreateContextRequest>(contexts,
                                                                         new Smb2CreateDurableHandleRequestV2
                {
                    CreateGuid = createGuid,
                    Timeout    = 120 * 1000,
                });
                break;

            case ReplayModelDurableHandle.DurableHandleV2Persistent:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                contexts = Smb2Utility.Append <Smb2CreateContextRequest>(contexts,
                                                                         new Smb2CreateDurableHandleRequestV2
                {
                    CreateGuid = createGuid,
                    Flags      = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                    Timeout    = 120 * 1000,
                });
                break;

            default:
                break;
            }
            #endregion
        }
Esempio n. 17
0
        public void OpenRequest(
            ModelDialectRevision clientMaxDialect,
            PersistentBitType persistentBit,
            CAShareType connectToCAShare,
            OplockLeaseType oplockLeaseType,
            DurableV1RequestContext durableV1RequestContext,
            DurableV2RequestContext durableV2RequestContext,
            DurableV1ReconnectContext durableV1ReconnectContext,
            DurableV2ReconnectContext durableV2ReconnectContext)
        {
            requestDialect     = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect));
            clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING |
                                 Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL;
            if (persistentBit == PersistentBitType.PersistentBitSet)
            {
                clientCapabilities |= Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES;
            }

            clientGuid       = Guid.NewGuid();
            requestedContext = oplockLeaseType;
            isCAShare        = (connectToCAShare == CAShareType.CAShare);
            IPAddress targetIPAddress;
            string    targetServer;

            #region Connect to Common Share or CA Share
            if (!isCAShare)
            {
                sharePath       = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare);
                fileName        = "PrepareHandle_ConnectTo_CommonShareFile_" + Guid.NewGuid() + ".txt";
                targetIPAddress = testConfig.SutIPAddress;
                targetServer    = testConfig.SutComputerName;
            }
            else
            {
                sharePath       = Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName);
                fileName        = "PrepareHandle_ConnectTo_CAShareFile_" + Guid.NewGuid().ToString() + ".txt";
                targetIPAddress = testConfig.CAShareServerIP;
                targetServer    = testConfig.CAShareServerName;
            }

            testClientBeforeDisconnection            = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            testClientBeforeDisconnection.CreditGoal = 20;
            testClientBeforeDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress);

            testClientBeforeDisconnection.Negotiate(
                requestDialect,
                testConfig.IsSMB1NegotiateEnabled,
                capabilityValue: clientCapabilities,
                clientGuid: clientGuid,
                checker: (header, response) =>
            {
                if (Smb2Utility.IsSmb3xFamily(response.DialectRevision) &&
                    handleConfig.IsPersistentHandleSupported &&
                    persistentBit == PersistentBitType.PersistentBitSet)
                {
                    Site.Assert.IsTrue(
                        response.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES),
                        "The server MUST set SMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " +
                        "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles. " +
                        "Actual capabilities are {0}", response.Capabilities);
                }
            });

            testClientBeforeDisconnection.SessionSetup(
                testConfig.DefaultSecurityPackage,
                targetServer,
                testConfig.AccountCredential,
                testConfig.UseServerGssToken);

            testClientBeforeDisconnection.TreeConnect(sharePath, out treeIdBeforeDisconnection, delegate(Packet_Header responseHeader, TREE_CONNECT_Response response)
            {
                if (isCAShare)
                {
                    if (!response.Capabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY))
                    {
                        // skip test case for CA share is invalid
                        Site.Assert.Inconclusive("This test case is applicable only when CA share is valid.");
                    }
                }
            });

            #endregion

            #region Construct Create Contexts
            Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext(
                durableV1RequestContext,
                durableV2RequestContext,
                durableV1ReconnectContext,
                durableV2ReconnectContext,
                oplockLeaseType,
                false,
                false);
            #endregion

            #region Send Create request according to different context combination
            RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
            switch (oplockLeaseType)
            {
            case OplockLeaseType.NoOplockOrLease:
            {
                requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
            }
            break;

            case OplockLeaseType.BatchOplock:
            {
                requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
            }
            break;

            case OplockLeaseType.LeaseV1:
            case OplockLeaseType.LeaseV2:
            {
                requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
            }
            break;
            }

            FILEID fileId;
            Smb2CreateContextResponse[] serverCreateContexts;
            uint status = OpenCreate(
                testClientBeforeDisconnection,
                treeIdBeforeDisconnection,
                fileName,
                out fileId,
                out serverCreateContexts,
                requestedOplockLevel,
                smb2CreateContextRequest);

            #endregion

            DurableHandleResponseContext durableHandleResponse;
            LeaseResponseContext         leaseResponse;
            CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse);
            OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig);

            testClientBeforeDisconnection.TreeDisconnect(treeIdAfterDisconnection, (header, response) => { });
            testClientBeforeDisconnection.LogOff();
        }
 /// <summary>
 /// Create operation for Open operation
 /// </summary>
 private uint OpenCreate(
     Smb2FunctionalClient client,
     uint treeIdAfterDisconnection,
     string fileName,
     out FILEID fileIdAfterDisconnection,
     out Smb2CreateContextResponse[] serverCreateContexts,
     RequestedOplockLevel_Values requestedOplocklevel,
     Smb2CreateContextRequest[] openContext)
 {
     return client.Create(
         treeIdAfterDisconnection,
         fileName,
         CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
         out fileIdAfterDisconnection,
         out serverCreateContexts,
         requestedOplocklevel,
         openContext,
         shareAccess: ShareAccess_Values.NONE,
         checker: (header, response) =>
         {
         });
 }
 public ModelRequestOplockAndTriggerBreakRequest(RequestedOplockLevel_Values requestedOplockLevel)
     : base(0)
 {
     this.RequestedOplockLevel = requestedOplockLevel;
 }
        private void FillParameters(ReplayModelLeaseState leaseState, 
            ReplayModelRequestedOplockLevel requestedOplockLevel,
            ReplayModelDurableHandle modelDurableHandle,
            Guid createGuid,
            Guid leaseKey,
            out LeaseStateValues requestLeaseState,
            out RequestedOplockLevel_Values oplockLevel,
            out Smb2CreateContextRequest[] contexts)
        {
            #region Fill lease state
            switch (leaseState)
            {
                case ReplayModelLeaseState.LeaseStateNotIncludeH:
                    requestLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING;
                    break;
                case ReplayModelLeaseState.LeaseStateIncludeH:
                    requestLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_WRITE_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING;
                    break;
                default:
                    requestLeaseState = LeaseStateValues.SMB2_LEASE_NONE;
                    break;
            }
            #endregion

            #region Fill oplockLevel and lease context
            contexts = new Smb2CreateContextRequest[] { };
            switch (requestedOplockLevel)
            {
                case ReplayModelRequestedOplockLevel.OplockLevelLeaseV1:
                    testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);

                    oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateRequestLease
                        {
                            LeaseKey = leaseKey,
                            LeaseState = requestLeaseState,
                            LeaseFlags = (uint)LeaseFlagsValues.NONE
                        }
                    };
                    break;
                case ReplayModelRequestedOplockLevel.OplockLevelLeaseV2:
                    testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2);

                    oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE;
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateRequestLeaseV2
                        {
                            LeaseKey = leaseKey,
                            LeaseState = requestLeaseState,
                            LeaseFlags = (uint)LeaseFlagsValues.NONE
                        }
                    };
                    break;
                case ReplayModelRequestedOplockLevel.OplockLevelBatch:
                    oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH;
                    break;
                case ReplayModelRequestedOplockLevel.OplockLevelII:
                    oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_II;
                    break;
                default:
                    oplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE;
                    break;
            }
            #endregion

            #region Fill handle context
            switch (modelDurableHandle)
            {
                case ReplayModelDurableHandle.DurableHandleV1:
                    testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                    contexts = Smb2Utility.Append<Smb2CreateContextRequest>(contexts,
                            new Smb2CreateDurableHandleRequest
                            {
                            });
                    break;
                case ReplayModelDurableHandle.DurableHandleV2:
                    testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                    contexts = Smb2Utility.Append<Smb2CreateContextRequest>(contexts,
                            new Smb2CreateDurableHandleRequestV2
                            {
                                CreateGuid = createGuid,
                                Timeout = 120 * 1000,
                            });
                    break;
                case ReplayModelDurableHandle.DurableHandleV2Persistent:
                    testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                    contexts = Smb2Utility.Append<Smb2CreateContextRequest>(contexts,
                            new Smb2CreateDurableHandleRequestV2
                            {
                                CreateGuid = createGuid,
                                Flags = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                                Timeout = 120 * 1000,
                            });
                    break;
                default:
                    break;
            }
            #endregion
        }