コード例 #1
0
        /// <summary>
        /// Get lease context according to leasekey and leasestate
        /// </summary>
        private Smb2CreateContextRequest[] GetLeaseContext(
            OplockLeaseType oplockLeaseType,
            Guid leaseKey,
            LeaseStateValues leaseState)
        {
            Smb2CreateContextRequest[] leaseContext = new Smb2CreateContextRequest[] { };

            if (oplockLeaseType == OplockLeaseType.LeaseV1)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);

                leaseContext = leaseContext.Append(
                    new Smb2CreateRequestLease
                {
                    LeaseKey   = leaseKey,
                    LeaseState = leaseState
                });
            }

            if (oplockLeaseType == OplockLeaseType.LeaseV2)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2);

                leaseContext = leaseContext.Append(
                    new Smb2CreateRequestLeaseV2
                {
                    LeaseKey   = leaseKey,
                    LeaseState = leaseState
                });
            }

            return(leaseContext);
        }
コード例 #2
0
        public void BVT_OpenSharedVHDSetByTargetSpecifier()
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	Client opens a shared virtual disk file and expects success.");
            OpenSharedVHD(TestConfig.NameOfSharedVHDS, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2);
            Guid snapshotId = Guid.NewGuid();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	Client sends the first tunnel operation SVHDX_META_OPERATION_START_REQUEST to create a snapshot.");
            CreateSnapshot(snapshotId);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3.	Client closes the file.");
            client.CloseSharedVirtualDisk();

            Smb2CreateEaBuffer        createEaBuffer = new Smb2CreateEaBuffer();
            FsccFileFullEaInformation eaInfo         = new FsccFileFullEaInformation();

            eaInfo.EaName  = RsvdConst.RSVD_TARGET_SPECIFIER_EA;
            eaInfo.EaValue = client.CreateTargetSpecifier(snapshotId);
            eaInfo.Flags   = FileFullEaInformation_Flags_Values.FILE_NEED_EA;
            createEaBuffer.FileFullEaInformations = new List <FsccFileFullEaInformation>();

            createEaBuffer.FileFullEaInformations.Add(eaInfo);

            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[] {
                createEaBuffer
            };

            CREATE_Response response;

            Smb2CreateContextResponse[] serverCreateContexts;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "4.	Client reopens the shared virtual disk file using a Target Specifier.");

            client.Connect(
                TestConfig.FileServerNameContainingSharedVHD,
                TestConfig.FileServerIPContainingSharedVHD,
                TestConfig.DomainName,
                TestConfig.UserName,
                TestConfig.UserPassword,
                TestConfig.DefaultSecurityPackage,
                TestConfig.UseServerGssToken,
                TestConfig.ShareContainingSharedVHD);

            RequestIdentifier = 0;
            uint status = client.OpenSharedVirtualDisk(
                TestConfig.NameOfSharedVHDS + fileNameSuffix,
                FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                contexts,
                out serverCreateContexts,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Open shared virtual disk file should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "5.	Client closes the file.");
            client.CloseSharedVirtualDisk();
        }
コード例 #3
0
        /// <summary>
        /// Get create context for PrepareOpen
        /// </summary>
        private Smb2CreateContextRequest[] GetPrepareOpenCreateContext(
            ModelHandleType modelHandleType,
            OplockLeaseType oplockLeaseType)
        {
            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[] { };
            contexts = GetPrepareOpenHandleContext(modelHandleType);
            contexts = ConcatContexts(contexts, GetPrepareOpenLeaseContext(oplockLeaseType));

            return(contexts);
        }
        public void BVT_OpenCloseSharedVHD_V2()
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	Client opens a shared virtual disk file with SMB2 create context SVHDX_OPEN_DEVICE_CONTEXT_V2 and expects success.");
            client.Connect(
                TestConfig.FileServerNameContainingSharedVHD,
                TestConfig.FileServerIPContainingSharedVHD,
                TestConfig.DomainName,
                TestConfig.UserName,
                TestConfig.UserPassword,
                TestConfig.DefaultSecurityPackage,
                TestConfig.UseServerGssToken,
                TestConfig.ShareContainingSharedVHD);

            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[]
            {
                new Smb2CreateSvhdxOpenDeviceContextV2
                {
                    Version                          = TestConfig.ServerServiceVersion,
                    OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                    InitiatorHostName                = TestConfig.InitiatorHostName,
                    InitiatorHostNameLength          = (ushort)(TestConfig.InitiatorHostName.Length * 2), // InitiatorHostName is a null-terminated Unicode UTF-16 string
                    VirtualDiskPropertiesInitialized = 0,
                    ServerServiceVersion             = 0,
                    VirtualSectorSize                = 0,
                    PhysicalSectorSize               = 0,
                    VirtualSize                      = 0
                }
            };

            CREATE_Response response;

            Smb2CreateContextResponse[] serverCreateContexts;
            uint status = client.OpenSharedVirtualDisk(
                TestConfig.NameOfSharedVHDX + fileNameSuffix,
                FsCreateOption.NONE,
                contexts,
                out serverCreateContexts,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Open shared virtual disk file should succeed, actual status: {0}",
                GetStatus(status));

            CheckOpenDeviceContext(serverCreateContexts);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	Client closes the file.");
            client.CloseSharedVirtualDisk();
        }
コード例 #5
0
        /// <summary>
        /// Get handle context for PrepareOpen
        /// </summary>
        private Smb2CreateContextRequest[] GetPrepareOpenHandleContext(
            ModelHandleType modelHandleType)
        {
            Smb2CreateContextRequest[] handleContext = new Smb2CreateContextRequest[] { };
            switch (modelHandleType)
            {
            case ModelHandleType.DurableHandleV1:
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                createGuid    = Guid.Empty;
                handleContext = handleContext.Append(new Smb2CreateDurableHandleRequest {
                        DurableRequest = createGuid
                    });
                return(handleContext);
            }

            case ModelHandleType.DurableHandleV2:
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                createGuid    = Guid.NewGuid();
                handleContext = handleContext.Append(new Smb2CreateDurableHandleRequestV2 {
                        CreateGuid = createGuid
                    });
                return(handleContext);
            }

            case ModelHandleType.PersistentHandle:
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                createGuid    = Guid.NewGuid();
                handleContext = handleContext.Append(
                    new Smb2CreateDurableHandleRequestV2
                    {
                        CreateGuid = createGuid,
                        Flags      = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                    });
                return(handleContext);
            }

            default:
                throw new InvalidOperationException("Unsupported handle type");
            }
        }
コード例 #6
0
        public void BVT_OpenCloseSharedVHD_V1()
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	Client opens a shared virtual disk file with SMB2 create context SVHDX_OPEN_DEVICE_CONTEXT and expects success.");
            client.Connect(
                TestConfig.FileServerNameContainingSharedVHD,
                TestConfig.FileServerIPContainingSharedVHD,
                TestConfig.DomainName,
                TestConfig.UserName,
                TestConfig.UserPassword,
                TestConfig.DefaultSecurityPackage,
                TestConfig.UseServerGssToken,
                TestConfig.ShareContainingSharedVHD);

            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[]
            {
                new Smb2CreateSvhdxOpenDeviceContext
                {
                    Version = TestConfig.ServerServiceVersion,
                    OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                    InitiatorHostName = TestConfig.InitiatorHostName,
                    InitiatorHostNameLength = (ushort)(TestConfig.InitiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                }
            };

            CREATE_Response response;
            Smb2CreateContextResponse[] serverCreateContexts;
            uint status = client.OpenSharedVirtualDisk(
                TestConfig.NameOfSharedVHDX + fileNameSuffix,
                FsCreateOption.NONE,
                contexts,
                out serverCreateContexts,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Open shared virtual disk file should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	Client closes the file.");
            client.CloseSharedVirtualDisk();
        }
コード例 #7
0
        /// <summary>
        /// Get handle context for OpenFile
        /// </summary>
        private Smb2CreateContextRequest[] GetOpenFileCreateContext(
            DurableV1RequestContext durableV1RequestContext,
            DurableV2RequestContext durableV2RequestContext,
            DurableV1ReconnectContext durableV1ReconnectContext,
            DurableV2ReconnectContext durableV2ReconnectContext,
            OplockLeaseType oplockLeaseType,
            bool isSameLeaseKey,
            bool isSameCreateGuid)
        {
            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[] { };
            contexts = GetOpenFileHandleContext(
                durableV1RequestContext,
                durableV2RequestContext,
                durableV1ReconnectContext,
                durableV2ReconnectContext,
                isSameCreateGuid);

            contexts = ConcatContexts(contexts, GetOpenFileLeaseContext(
                                          oplockLeaseType,
                                          isSameLeaseKey));

            return(contexts);
        }
コード例 #8
0
        /// <summary>
        /// Concat two contexts arrays
        /// </summary>
        private Smb2CreateContextRequest[] ConcatContexts(
            Smb2CreateContextRequest[] firstContext,
            Smb2CreateContextRequest[] secondContext)
        {
            foreach (var context in secondContext)
            {
                firstContext = firstContext.Append(context);
            }

            return firstContext;
        }
コード例 #9
0
        public void TestFileLeasing(Smb2CreateContextRequest leaseContext)
        {
            #region Add Event Handler
            client1.Smb2Client.LeaseBreakNotificationReceived += new Action<Packet_Header, LEASE_BREAK_Notification_Packet>(base.OnLeaseBreakNotificationReceived);
            clientToAckLeaseBreak = client1;
            #endregion

            #region Client1 Open a File with Lease RWH
            BaseTestSite.Log.Add(LogEntryKind.TestStep,
                "Start the first client to create a file by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE (with context: {0})",
                leaseContext is Smb2CreateRequestLease ? "LeaseV1" : "LeaseV2");
            client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client1.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client1TreeId;
            client1.TreeConnect(sharePath, out client1TreeId);
            FILEID client1FileId;
            Smb2CreateContextResponse[] createContextResponse;
            client1.Create(client1TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client1FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                new Smb2CreateContextRequest[]
                {
                    leaseContext
                }
                );
            #endregion

            #region Check Response Contexts

            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            System.Threading.Timer timer = new System.Threading.Timer(CheckBreakNotification, client1TreeId, 0, Timeout.Infinite);

            #region Lease Break RWH => RH
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a second client to create the same file with the first client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE");
            expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING;
            client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client2.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client2TreeId;
            client2.TreeConnect(sharePath, out client2TreeId);
            FILEID client2FileId;
            client2.Create(client2TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client2FileId, out createContextResponse);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends LEASE_BREAK_ACKNOWLEDGEMENT request to break lease state to RH after receiving LEASE_BREAK_NOTIFICATION response from server.");
            #endregion

            #region Lease BreakRH => NONE
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The second client sends WRITE request.");
            expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_NONE;
            byte[] data = { 0 };
            client2.Write(client2TreeId, client2FileId, data);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends LEASE_BREAK_ACKNOWLEDGEMENT request to break lease state to NONE after receiving LEASE_BREAK_NOTIFICATION response from server.");
            #endregion

            #region Tear Down Clients
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client1.Close(client1TreeId, client1FileId);
            client1.TreeDisconnect(client1TreeId);
            client1.LogOff();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client2.Close(client2TreeId, client2FileId);
            client2.TreeDisconnect(client2TreeId);
            client2.LogOff();
            #endregion
        }
コード例 #10
0
        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
        }
コード例 #11
0
        /// <summary>
        /// Connect to the share VHD file.
        /// </summary>
        private bool TestRsvdVersion(
            string vhdxName,
            string share,
            RSVD_PROTOCOL_VERSION version)
        {
            using (RsvdClient client = new RsvdClient(new TimeSpan(0, 0, defaultTimeoutInSeconds)))
            {
                CREATE_Response             response;
                Smb2CreateContextResponse[] serverContexts;
                client.Connect(SUTName, SUTIpAddress, Credential.DomainName, Credential.AccountName, Credential.Password, SecurityPackageType, true, share);

                Smb2CreateContextRequest[] contexts;
                if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2)
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContextV2
                        {
                            Version                          = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2,
                            OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName                = initiatorHostName,
                            InitiatorHostNameLength          = (ushort)(initiatorHostName.Length * 2), // InitiatorHostName is a null-terminated Unicode UTF-16 string
                            VirtualDiskPropertiesInitialized = 0,
                            ServerServiceVersion             = 0,
                            VirtualSectorSize                = 0,
                            PhysicalSectorSize               = 0,
                            VirtualSize                      = 0
                        }
                    };
                }
                else
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContext
                        {
                            Version                 = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
                            OriginatorFlags         = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName       = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                        }
                    };
                }

                uint status;
                status = client.OpenSharedVirtualDisk(
                    vhdxName,
                    TestTools.StackSdk.FileAccessService.FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                    contexts,
                    out serverContexts,
                    out response);

                bool result = false;

                if (status != Smb2Status.STATUS_SUCCESS)
                {
                    result = false;
                    logWriter.AddLog(LogLevel.Information, string.Format("{0} is found not supported.", version));
                    return(result);
                }

                result = CheckOpenDeviceContext(serverContexts, version);
                client.CloseSharedVirtualDisk();

                return(result);
            }
        }
コード例 #12
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) =>
         {
         });
 }
コード例 #13
0
        /// <summary>
        /// Get handle context for PrepareOpen
        /// </summary>
        private Smb2CreateContextRequest[] GetPrepareOpenHandleContext(
            ModelHandleType modelHandleType)
        {
            Smb2CreateContextRequest[] handleContext = new Smb2CreateContextRequest[] { };
            switch (modelHandleType)
            {
                case ModelHandleType.DurableHandleV1:
                    {
                        testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                        createGuid = Guid.Empty;
                        handleContext = handleContext.Append(new Smb2CreateDurableHandleRequest { DurableRequest = createGuid });
                        return handleContext;
                    }
                case ModelHandleType.DurableHandleV2:
                    {
                        testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                        createGuid = Guid.NewGuid();
                        handleContext = handleContext.Append(new Smb2CreateDurableHandleRequestV2 { CreateGuid = createGuid });
                        return handleContext;
                    }
                case ModelHandleType.PersistentHandle:
                    {
                        testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                        createGuid = Guid.NewGuid();
                        handleContext = handleContext.Append(
                            new Smb2CreateDurableHandleRequestV2
                            {
                                CreateGuid = createGuid,
                                Flags = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                            });
                        return handleContext;
                    }
                default:
                    throw new InvalidOperationException("Unsupported handle type");
            }
        }
コード例 #14
0
        /// <summary>
        /// Get create context for OpenFile
        /// </summary>
        private Smb2CreateContextRequest[] GetOpenFileHandleContext(
            DurableV1RequestContext durableV1RequestContext,
            DurableV2RequestContext durableV2RequestContext,
            DurableV1ReconnectContext durableV1ReconnectContext,
            DurableV2ReconnectContext durableV2ReconnectContext,
            bool isSameCreateGuid)
        {
            Smb2CreateContextRequest[] handleContext = new Smb2CreateContextRequest[] { };

            if (durableV1RequestContext == DurableV1RequestContext.DurableV1RequestContextExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                handleContext = handleContext.Append(
                    new Smb2CreateDurableHandleRequest
                    {
                        DurableRequest = isSameCreateGuid ? Guid.Empty : Guid.NewGuid(),
                    });
            }
            if (durableV2RequestContext != DurableV2RequestContext.DurableV2RequestContextNotExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                if (durableV2RequestContext == DurableV2RequestContext.DurableV2RequestContextExistWithoutPersistent)
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleRequestV2
                        {
                            CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                        });
                }
                else
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleRequestV2
                        {
                            CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                            Flags = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                        });
                }
            }
            if (durableV1ReconnectContext == DurableV1ReconnectContext.DurableV1ReconnectContextExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_RECONNECT);

                handleContext = handleContext.Append(
                    new Smb2CreateDurableHandleReconnect
                    {
                        Data = new FILEID { Persistent = fileIdBeforDisconnection.Persistent }
                    });
            }
            if (durableV2ReconnectContext != DurableV2ReconnectContext.DurableV2ReconnectContextNotExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2);

                if (durableV2ReconnectContext == DurableV2ReconnectContext.DurableV2ReconnectContextExistWithoutPersistent)
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleReconnectV2
                        {
                            CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                            FileId = new FILEID { Persistent = fileIdBeforDisconnection.Persistent }
                        });
                }
                else
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleReconnectV2
                        {
                            CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                            Flags = CREATE_DURABLE_HANDLE_RECONNECT_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                            FileId = new FILEID { Persistent = fileIdBeforDisconnection.Persistent }
                        });
                }
            }

            return handleContext;
        }
コード例 #15
0
        public void BVT_OpenSharedVHDSetByTargetSpecifier()
        {
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "1.	Client opens a shared virtual disk file and expects success.");
            OpenSharedVHD(TestConfig.NameOfSharedVHDS, RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2);
            Guid snapshotId = Guid.NewGuid();
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "2.	Client sends the first tunnel operation SVHDX_META_OPERATION_START_REQUEST to create a snapshot.");
            CreateSnapshot(snapshotId);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "3.	Client closes the file.");
            client.CloseSharedVirtualDisk();

            Smb2CreateEaBuffer createEaBuffer = new Smb2CreateEaBuffer();
            FsccFileFullEaInformation eaInfo = new FsccFileFullEaInformation();
            eaInfo.EaName = RsvdConst.RSVD_TARGET_SPECIFIER_EA;
            eaInfo.EaValue = client.CreateTargetSpecifier(snapshotId);
            eaInfo.Flags = FileFullEaInformation_Flags_Values.FILE_NEED_EA;
            createEaBuffer.FileFullEaInformations = new Modeling.Sequence<FsccFileFullEaInformation>();

            createEaBuffer.FileFullEaInformations = createEaBuffer.FileFullEaInformations.Add(eaInfo);

            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[]{
                    createEaBuffer};

            CREATE_Response response;
            Smb2CreateContextResponse[] serverCreateContexts;

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "4.	Client reopens the shared virtual disk file using a Target Specifier.");

            client.Connect(
                TestConfig.FileServerNameContainingSharedVHD,
                TestConfig.FileServerIPContainingSharedVHD,
                TestConfig.DomainName,
                TestConfig.UserName,
                TestConfig.UserPassword,
                TestConfig.DefaultSecurityPackage,
                TestConfig.UseServerGssToken,
                TestConfig.ShareContainingSharedVHD);

            RequestIdentifier = 0;
            uint status = client.OpenSharedVirtualDisk(
                TestConfig.NameOfSharedVHDS + fileNameSuffix,
                FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                contexts,
                out serverCreateContexts,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Open shared virtual disk file should succeed, actual status: {0}",
                GetStatus(status));

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "5.	Client closes the file.");
            client.CloseSharedVirtualDisk();
        }
コード例 #16
0
        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.");
            }
        }
コード例 #17
0
        private void SendCreateRequestWithSpecificAppInstanceversion(
            Smb2FunctionalClient client,
            Guid appInstanceId,
            ulong?appInstanceVersionHigh,
            ulong?appInstanceVersionLow,
            DialectRevision dialect,
            uint expectedCreateResponseStatus,
            out uint treeId,
            out FILEID fileId
            )
        {
            #region Client connects to Server
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client connects to the file server by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT");
            client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic1IPAddress);
            client.Negotiate(Smb2Utility.GetDialects(dialect), TestConfig.IsSMB1NegotiateEnabled);
            client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);

            client.TreeConnect(uncSharePath, out treeId);

            Smb2CreateContextResponse[]  serverCreateContexts;
            Smb2CreateAppInstanceVersion appInstanceVersion = new Smb2CreateAppInstanceVersion();
            Smb2CreateContextRequest[]   clientCreateContexts;

            if (appInstanceVersionHigh.HasValue && appInstanceVersionLow.HasValue)
            {
                appInstanceVersion.AppInstanceVersionHigh = appInstanceVersionHigh.Value;
                appInstanceVersion.AppInstanceVersionLow  = appInstanceVersionLow.Value;
                clientCreateContexts =
                    new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = appInstanceId
                    },
                    appInstanceVersion
                };
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with AppInstanceVersionHigh = {0}, AppInstanceVersionLow = {1}.", appInstanceVersion.AppInstanceVersionHigh, appInstanceVersion.AppInstanceVersionLow);
            }
            else
            {
                clientCreateContexts =
                    new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = appInstanceId
                    }
                };
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request without AppInstanceVersion.");
            }

            client.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                clientCreateContexts,
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
            {
                BaseTestSite.Assert.AreEqual(
                    expectedCreateResponseStatus,
                    header.Status,
                    (expectedCreateResponseStatus == Smb2Status.STATUS_SUCCESS ?
                     "The open will be closed. Create should succeed. Actually server returns with {0}."
                        : "The open cannot be closed. Create should not succeed. Actually server returns with {0}."),
                    Smb2Status.GetStatusCode(header.Status));
            });

            #endregion
        }
コード例 #18
0
        private void AppInstanceIdTest(bool sameAppInstanceId, bool containCreateDurableContext)
        {
            string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb);

            #region Client 1 Connect to Server
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the first client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT");
            clientForInitialOpen = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientForInitialOpen.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic1IPAddress);
            clientForInitialOpen.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            clientForInitialOpen.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            uint treeIdForInitialOpen;
            clientForInitialOpen.TreeConnect(sharePath, out treeIdForInitialOpen);

            Guid appInstanceId = Guid.NewGuid();
            FILEID fileIdForInitialOpen;
            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "The first client sends CREATE request for exclusive open with SMB2_CREATE_APP_INSTANCE_ID create context.");
            Smb2CreateContextResponse[] serverCreateContexts;
            Smb2CreateContextRequest[] createContextsRequestForInitialOpen = null;
            if (containCreateDurableContext)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is also included in the CREATE request.");
                createContextsRequestForInitialOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateDurableHandleRequestV2
                    {
                         CreateGuid = Guid.NewGuid()
                    },
                    new Smb2CreateAppInstanceId
                    {
                         AppInstanceId = appInstanceId
                    }
                };
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is not included in the CREATE request.");
                createContextsRequestForInitialOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                         AppInstanceId = appInstanceId
                    }
                };
            }

            clientForInitialOpen.Create(
                treeIdForInitialOpen,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdForInitialOpen,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                createContextsRequestForInitialOpen,
                shareAccess: ShareAccess_Values.NONE);
            #endregion

            #region Client 2 Connect to Server

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the second client by sending the following requests: NEGOTIATE; SESSION-SETUP; TREE_CONNECT");
            clientForReOpen = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientForReOpen.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic2IPAddress);
            clientForReOpen.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            clientForReOpen.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            uint treeIdForReOpen;
            clientForReOpen.TreeConnect(sharePath, out treeIdForReOpen);

            FILEID fileIdForReOpen;
            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "The second client sends CREATE request for exclusive open with the {0} SMB2_CREATE_APP_INSTANCE_ID of the first client.", sameAppInstanceId ? "same" : "different");
            Smb2CreateContextRequest[] createContextsRequestForReOpen = null;
            if (containCreateDurableContext)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is also included in the CREATE request.");
                createContextsRequestForReOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateDurableHandleRequestV2
                    {
                         CreateGuid = Guid.NewGuid()
                    },
                    new Smb2CreateAppInstanceId
                    {
                         AppInstanceId = sameAppInstanceId ? appInstanceId : Guid.NewGuid()
                    }
                };
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is not included in the CREATE request.");
                createContextsRequestForReOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                         AppInstanceId = sameAppInstanceId ? appInstanceId : Guid.NewGuid()
                    }
                };
            }

            clientForReOpen.Create(
                treeIdForReOpen,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdForReOpen,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                createContextsRequestForReOpen,
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
                {
                    if (sameAppInstanceId)
                    {
                        BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status, "The second client should create the open successfully.");
                    }
                    else
                    {
                        BaseTestSite.Assert.AreNotEqual(Smb2Status.STATUS_SUCCESS, header.Status, "The second client should not create the open successfully.");
                    }
                });

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends another WRITE request.");

            if (sameAppInstanceId)
            {
                clientForInitialOpen.Write(treeIdForInitialOpen, fileIdForInitialOpen, content,
                    checker: (header, response) =>
                    {
                        BaseTestSite.Assert.AreNotEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "The initial open is closed. Write should not succeed. Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                        BaseTestSite.CaptureRequirementIfAreEqual(
                            Smb2Status.STATUS_FILE_CLOSED,
                            header.Status,
                            RequirementCategory.STATUS_FILE_CLOSED.Id,
                            RequirementCategory.STATUS_FILE_CLOSED.Description);
                    });

                // The first open is closed, no need to do clean up job.
                // Clean up the second client.
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF; DISCONNECT");
                clientForReOpen.Close(treeIdForReOpen, fileIdForReOpen);
                clientForReOpen.TreeDisconnect(treeIdForReOpen);
                clientForReOpen.LogOff();
                clientForReOpen.Disconnect();
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "The initial open is not closed. Write should succeed.");
                clientForInitialOpen.Write(treeIdForInitialOpen, fileIdForInitialOpen, content);

                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF");
                clientForInitialOpen.Close(treeIdForInitialOpen, fileIdForInitialOpen);
                clientForInitialOpen.TreeDisconnect(treeIdForInitialOpen);
                clientForInitialOpen.LogOff();

                // The second client doesn't create the open succesfully, so no need to close the open.
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: TREE_DISCONNECT; LOG_OFF; DISCONNECT");
                clientForReOpen.TreeDisconnect(treeIdForReOpen);
                clientForReOpen.LogOff();
                clientForReOpen.Disconnect();
            }

            #endregion
        }
コード例 #19
0
        public void CreateRequest(
            CreateFileNameType fileNameType,
            CreateOptionsFileOpenReparsePointType fileOpenReparsePointType,
            CreateOptionsFileDeleteOnCloseType fileDeleteOnCloseType,
            CreateContextType contextType,
            ImpersonationLevelType impersonationType,
            CreateFileType fileType)
        {
            #region Header
            Packet_Header_Flags_Values headerFlag = testConfig.SendSignedRequest ? Packet_Header_Flags_Values.FLAGS_SIGNED : Packet_Header_Flags_Values.NONE;

            #endregion

            #region File Name
            string fileName = GetFileName(fileNameType);
            #endregion

            #region CreateOptions
            CreateOptions_Values createOptions = fileType == CreateFileType.DirectoryFile ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            if (fileOpenReparsePointType == CreateOptionsFileOpenReparsePointType.FileOpenReparsePointSet)
                createOptions |= CreateOptions_Values.FILE_OPEN_REPARSE_POINT;
            if (fileDeleteOnCloseType == CreateOptionsFileDeleteOnCloseType.FileDeteteOnCloseSet)
                createOptions |= CreateOptions_Values.FILE_DELETE_ON_CLOSE;
            #endregion

            #region CreateContexts
            Smb2CreateContextRequest[] createContexts = new Smb2CreateContextRequest[] { };
            Create_ContextType = contextType;
            switch (contextType)
            {
                case CreateContextType.NoCreateContext:
                    break;
                case CreateContextType.InvalidCreateContext:
                case CreateContextType.InvalidCreateContextSize:
                    testClient.BeforeSendingPacket(ReplacePacketByInvalidCreateContext);
                    break;
                case CreateContextType.ValidCreateContext:
                    testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_QUERY_ON_DISK_ID);

                    createContexts = createContexts.Append(new Smb2CreateQueryOnDiskId());
                    break;

                default:
                    throw new ArgumentException("contextType");
            }
            #endregion

            #region ImpersonationLevel
            ImpersonationLevel_Values impersonation = ImpersonationLevel_Values.Impersonation;
            if (impersonationType == ImpersonationLevelType.InvalidImpersonationLevel)
            {
                impersonation = (ImpersonationLevel_Values)0x00000004; //Non-existed impersonation level
            }

            #endregion

            #region DesiredAccess
            AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;
            #endregion

            Smb2CreateContextResponse[] contextResponse;

            uint status = testClient.Create(
                treeId,
                fileName,
                createOptions,
                headerFlag,
                out fileID,
                out contextResponse,
                createContexts: createContexts,
                accessMask: accessMask,
                checker: (header, response) => { },
                impersonationLevel: impersonation);

            CreateResponse((ModelSmb2Status)status, createCloseConfig);
        }
コード例 #20
0
        /// <summary>
        /// Get lease context according to leasekey and leasestate
        /// </summary>
        private Smb2CreateContextRequest[] GetLeaseContext(
            OplockLeaseType oplockLeaseType,
            Guid leaseKey,
            LeaseStateValues leaseState)
        {
            Smb2CreateContextRequest[] leaseContext = new Smb2CreateContextRequest[] { };

            if (oplockLeaseType == OplockLeaseType.LeaseV1)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);

                leaseContext = leaseContext.Append(
                    new Smb2CreateRequestLease
                    {
                        LeaseKey = leaseKey,
                        LeaseState = leaseState
                    });
            }

            if (oplockLeaseType == OplockLeaseType.LeaseV2)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2);

                leaseContext = leaseContext.Append(
                    new Smb2CreateRequestLeaseV2
                    {
                        LeaseKey = leaseKey,
                        LeaseState = leaseState
                    });
            }

            return leaseContext;
        }
コード例 #21
0
        /// <summary>
        /// Get handle context for OpenFile
        /// </summary>
        private Smb2CreateContextRequest[] GetOpenFileCreateContext(
            DurableV1RequestContext durableV1RequestContext,
            DurableV2RequestContext durableV2RequestContext,
            DurableV1ReconnectContext durableV1ReconnectContext,
            DurableV2ReconnectContext durableV2ReconnectContext,
            OplockLeaseType oplockLeaseType,
            bool isSameLeaseKey,
            bool isSameCreateGuid)
        {
            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[] { };
            contexts = GetOpenFileHandleContext(
                            durableV1RequestContext,
                            durableV2RequestContext,
                            durableV1ReconnectContext,
                            durableV2ReconnectContext,
                            isSameCreateGuid);

            contexts = ConcatContexts(contexts, GetOpenFileLeaseContext(
                oplockLeaseType,
                isSameLeaseKey));

            return contexts;
        }
コード例 #22
0
        /// <summary>
        /// Connect to the share VHD file.
        /// </summary>
        private bool TestRsvdVersion(
            string vhdxName,
            string share,
            RSVD_PROTOCOL_VERSION version)
        {
            using (RsvdClient client = new RsvdClient(new TimeSpan(0, 0, defaultTimeoutInSeconds)))
            {
                CREATE_Response             response;
                Smb2CreateContextResponse[] serverContexts;
                client.Connect(SUTName, SUTIpAddress, Credential.DomainName, Credential.AccountName, Credential.Password, SecurityPackageType, true, share);

                Smb2CreateContextRequest[] contexts;
                if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2)
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContextV2
                        {
                            Version                          = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2,
                            OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName                = initiatorHostName,
                            InitiatorHostNameLength          = (ushort)(initiatorHostName.Length * 2), // InitiatorHostName is a null-terminated Unicode UTF-16 string
                            VirtualDiskPropertiesInitialized = 0,
                            ServerServiceVersion             = 0,
                            VirtualSectorSize                = 0,
                            PhysicalSectorSize               = 0,
                            VirtualSize                      = 0
                        }
                    };
                    foreach (Smb2CreateSvhdxOpenDeviceContextV2 context in contexts)
                    {
                        logWriter.AddLog(DetectLogLevel.Information, @"OpenSharedVirtualDisk request was sent with context: ");
                        logWriter.AddLog(DetectLogLevel.Information, @"Version: " + context.Version.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"OriginatorFlags: " + context.OriginatorFlags.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName: " + context.InitiatorHostName.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength: " + context.InitiatorHostNameLength.ToString());
                    }
                }
                else
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContext
                        {
                            Version                 = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
                            OriginatorFlags         = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName       = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                        }
                    };
                    foreach (Smb2CreateSvhdxOpenDeviceContext context in contexts)
                    {
                        logWriter.AddLog(DetectLogLevel.Information, @"OpenSharedVirtualDisk request was sent with context: ");
                        logWriter.AddLog(DetectLogLevel.Information, @"Version: " + context.Version.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"OriginatorFlags: " + context.OriginatorFlags.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName: " + context.InitiatorHostName.ToString());
                        logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength: " + context.InitiatorHostNameLength.ToString());
                    }
                }

                uint status;
                status = client.OpenSharedVirtualDisk(
                    vhdxName,
                    TestTools.StackSdk.FileAccessService.FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                    contexts,
                    out serverContexts,
                    out response);

                logWriter.AddLog(DetectLogLevel.Information, @"Get OpenSharedVirtualDisk response with status: " + status);

                if (serverContexts == null)
                {
                    logWriter.AddLog(DetectLogLevel.Information, @"The response does not contain any server contexts.");
                }
                else
                {
                    foreach (Smb2CreateContextResponse ctx in serverContexts)
                    {
                        Type type = ctx.GetType();
                        if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponse")
                        {
                            logWriter.AddLog(DetectLogLevel.Information, @"Server response context is Smb2CreateSvhdxOpenDeviceContextResponse. ");

                            Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = ctx as Smb2CreateSvhdxOpenDeviceContextResponse;
                            logWriter.AddLog(DetectLogLevel.Information, @"Version is: " + openDeviceContext.Version.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName is: " + openDeviceContext.InitiatorHostName.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength is: " + openDeviceContext.InitiatorHostNameLength.ToString());
                        }

                        if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2")
                        {
                            logWriter.AddLog(DetectLogLevel.Information, @"Server response context is Smb2CreateSvhdxOpenDeviceContextResponseV2. ");

                            Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = ctx as Smb2CreateSvhdxOpenDeviceContextResponseV2;
                            logWriter.AddLog(DetectLogLevel.Information, @"Version is: " + openDeviceContext.Version.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostName is: " + openDeviceContext.InitiatorHostName.ToString());
                            logWriter.AddLog(DetectLogLevel.Information, @"InitiatorHostNameLength is: " + openDeviceContext.InitiatorHostNameLength.ToString());
                        }
                    }
                }

                bool result = false;

                if (status != Smb2Status.STATUS_SUCCESS)
                {
                    result = false;
                    logWriter.AddLog(DetectLogLevel.Information, @"Get status " + status + @" from server response.");
                    logWriter.AddLog(DetectLogLevel.Information, @"The RSVD version " + version + @" is found not supported by server.");
                    return(result);
                }

                result = CheckOpenDeviceContext(serverContexts, version);
                client.CloseSharedVirtualDisk();

                return(result);
            }
        }
コード例 #23
0
        /// <summary>
        /// Get create context for PrepareOpen
        /// </summary>
        private Smb2CreateContextRequest[] GetPrepareOpenCreateContext(
            ModelHandleType modelHandleType,
            OplockLeaseType oplockLeaseType)
        {
            Smb2CreateContextRequest[] contexts = new Smb2CreateContextRequest[] { };
            contexts = GetPrepareOpenHandleContext(modelHandleType);
            contexts = ConcatContexts(contexts, GetPrepareOpenLeaseContext(oplockLeaseType));

            return contexts;
        }
コード例 #24
0
        public void TestFileLeasingKey(Smb2CreateContextRequest leaseContext)
        {
            #region Add Event Handler
            client1.Smb2Client.LeaseBreakNotificationReceived += new Action <Packet_Header, LEASE_BREAK_Notification_Packet>(base.OnLeaseBreakNotificationReceived);
            clientToAckLeaseBreak = client1;
            #endregion

            #region Client1 Open a File with Lease RWH
            BaseTestSite.Log.Add(LogEntryKind.TestStep,
                                 "Start the first client to create a file by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE (with context: {0})",
                                 leaseContext is Smb2CreateRequestLease ? "LeaseV1" : "LeaseV2");
            client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client1.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client1TreeId;
            client1.TreeConnect(sharePath, out client1TreeId);
            FILEID client1FileId;
            Smb2CreateContextResponse[] createContextResponse;
            client1.Create(client1TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client1FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                leaseContext
            }
                           );
            #endregion

            #region Check Response Contexts of Client1

            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            // Create a task to invoke CheckBreakNotification to check whether server will send out lease break notification or not, no acknowledgement required
            var checkFirstBreakNotificationTask = Task.Run(() => CheckBreakNotification(client1TreeId, false));

            #region Start a second client to request lease by using the same lease key with the first client
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a second client to create the same file with the first client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE");
            client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client2.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client2TreeId;
            client2.TreeConnect(sharePath, out client2TreeId);
            FILEID client2FileId;
            client2.Create(client2TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client2FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                leaseContext
            }
                           );
            #endregion

            #region Check Response Contexts of Client2
            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            #region The first client send write request
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends WRITE request.");
            byte[] data = { 0 };
            client1.Write(client1TreeId, client1FileId, data);
            #endregion

            #region The second client send write request
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The second client sends WRITE request.");
            client2.Write(client2TreeId, client2FileId, data);
            #endregion

            #region Check whether the server will send lease break notification
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client will not receive lease break notification since the second client is using the same lease key");
            checkFirstBreakNotificationTask.Wait(TestConfig.WaitTimeoutInMilliseconds);
            #endregion

            #region Tear Down Clients
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client1.Close(client1TreeId, client1FileId);
            client1.TreeDisconnect(client1TreeId);
            client1.LogOff();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client2.Close(client2TreeId, client2FileId);
            client2.TreeDisconnect(client2TreeId);
            client2.LogOff();
            #endregion
        }
コード例 #25
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) =>
         {
         });
 }
コード例 #26
0
        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
            fileName = "ResilientHandlePrepareOpen_" + Guid.NewGuid() + ".txt";
            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,
                fileName,
                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.");
            }
        }
コード例 #27
0
        /// <summary>
        /// Create a file with create context
        /// </summary>
        /// <param name="fileName">Name of the file</param>
        /// <param name="desiredAccess">The desired access</param>
        /// <param name="shareAccess">Sharing mode for the open</param>
        /// <param name="impersonationLevel">The impersonation level</param>
        /// <param name="fileAttribute">The file attribute, this field is only valid when create file.</param>
        /// <param name="createDisposition">Defines the action the server MUST take if the file that is specified in the name field already exists</param>
        /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
        /// <param name="contextRequest">Create contexts to be sent in the create request</param>
        /// <param name="status">Status of the response packet</param>
        /// <param name="serverCreateContexts">Create contexts to be received in the create response</param>
        /// <param name="contextResponse">Create response payload to be received in the create response</param>
        public void Create(
            string fileName,
            FsFileDesiredAccess desiredAccess,
            ShareAccess_Values shareAccess,
            FsImpersonationLevel impersonationLevel,
            FsFileAttribute fileAttribute,
            FsCreateDisposition createDisposition,
            FsCreateOption createOption,
            Smb2CreateContextRequest[] contextRequest,
            out uint status,
            out Smb2CreateContextResponse[] serverCreateContexts,
            out CREATE_Response createResponse)
        {
            if (createOption.HasFlag(FsCreateOption.FILE_DIRECTORY_FILE))
            {
                throw new ArgumentException("createOption can not contain FILE_DIRECTORY_FILE when creating file.");
            }

            Packet_Header header;

            status = client.Create(
                        1,
                        1,
                        headerFlags,
                        messageId++,
                        sessionId,
                        treeId,
                        fileName,
                        (AccessMask)desiredAccess,
                        shareAccess,
                        (CreateOptions_Values)createOption,
                        (CreateDisposition_Values)createDisposition,
                        (File_Attributes)fileAttribute,
                        (ImpersonationLevel_Values)impersonationLevel,
                        SecurityFlags_Values.NONE,
                        RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                        contextRequest,
                        out fileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
        }
コード例 #28
0
        private void SendCreateRequestWithSpecificAppInstanceversion(
            Smb2FunctionalClient client,
            Guid appInstanceId,
            ulong? appInstanceVersionHigh,
            ulong? appInstanceVersionLow,
            DialectRevision dialect,
            uint expectedCreateResponseStatus,
            out uint treeId,
            out FILEID fileId
            )
        {
            #region Client connects to Server
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client connects to the file server by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT");
            client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic1IPAddress);
            client.Negotiate(Smb2Utility.GetDialects(dialect), TestConfig.IsSMB1NegotiateEnabled);
            client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);

            client.TreeConnect(uncSharePath, out treeId);

            Smb2CreateContextResponse[] serverCreateContexts;
            Smb2CreateAppInstanceVersion appInstanceVersion = new Smb2CreateAppInstanceVersion();
            Smb2CreateContextRequest[] clientCreateContexts;

            if (appInstanceVersionHigh.HasValue && appInstanceVersionLow.HasValue)
            {
                appInstanceVersion.AppInstanceVersionHigh = appInstanceVersionHigh.Value;
                appInstanceVersion.AppInstanceVersionLow = appInstanceVersionLow.Value;
                clientCreateContexts =
                new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = appInstanceId
                    },
                    appInstanceVersion
                };
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request with AppInstanceVersionHigh = {0}, AppInstanceVersionLow = {1}.", appInstanceVersion.AppInstanceVersionHigh, appInstanceVersion.AppInstanceVersionLow);
            }
            else
            {
                clientCreateContexts =
                new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = appInstanceId
                    }
                };
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends CREATE request without AppInstanceVersion.");
            }

            client.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                clientCreateContexts,
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
                {
                    BaseTestSite.Assert.AreEqual(
                        expectedCreateResponseStatus,
                        header.Status,
                        (expectedCreateResponseStatus == Smb2Status.STATUS_SUCCESS ?
                        "The open will be closed. Create should succeed. Actually server returns with {0}."
                        : "The open cannot be closed. Create should not succeed. Actually server returns with {0}."),
                        Smb2Status.GetStatusCode(header.Status));
                });

            #endregion
        }
コード例 #29
0
        public void TestFileLeasing(Smb2CreateContextRequest leaseContext)
        {
            #region Add Event Handler
            client1.Smb2Client.LeaseBreakNotificationReceived += new Action <Packet_Header, LEASE_BREAK_Notification_Packet>(base.OnLeaseBreakNotificationReceived);
            clientToAckLeaseBreak = client1;
            #endregion

            #region Client1 Open a File with Lease RWH
            BaseTestSite.Log.Add(LogEntryKind.TestStep,
                                 "Start the first client to create a file by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE (with context: {0})",
                                 leaseContext is Smb2CreateRequestLease ? "LeaseV1" : "LeaseV2");
            client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client1.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client1TreeId;
            client1.TreeConnect(sharePath, out client1TreeId);
            FILEID client1FileId;
            Smb2CreateContextResponse[] createContextResponse;
            client1.Create(client1TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client1FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                leaseContext
            }
                           );
            #endregion

            #region Check Response Contexts

            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            System.Threading.Timer timer = new System.Threading.Timer(CheckBreakNotification, client1TreeId, 0, Timeout.Infinite);

            #region Lease Break RWH => RH
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a second client to create the same file with the first client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE");
            expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING;
            client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client2.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client2TreeId;
            client2.TreeConnect(sharePath, out client2TreeId);
            FILEID client2FileId;
            client2.Create(client2TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client2FileId, out createContextResponse);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends LEASE_BREAK_ACKNOWLEDGEMENT request to break lease state to RH after receiving LEASE_BREAK_NOTIFICATION response from server.");
            #endregion

            #region Lease BreakRH => NONE
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The second client sends WRITE request.");
            expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_NONE;
            byte[] data = { 0 };
            client2.Write(client2TreeId, client2FileId, data);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends LEASE_BREAK_ACKNOWLEDGEMENT request to break lease state to NONE after receiving LEASE_BREAK_NOTIFICATION response from server.");
            #endregion

            #region Tear Down Clients
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client1.Close(client1TreeId, client1FileId);
            client1.TreeDisconnect(client1TreeId);
            client1.LogOff();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client2.Close(client2TreeId, client2FileId);
            client2.TreeDisconnect(client2TreeId);
            client2.LogOff();
            #endregion
        }
コード例 #30
0
        public void SendRequestContext(Smb2CreateContextRequest client1RequestLease, Smb2CreateContextRequest client2RequestLease, out Smb2CreateContextResponse client1ResponseLease,
                                       out Smb2CreateContextResponse client2ResponseLease, bool isBothClientDirectory = false, bool isClient1ParentDirectory = false, bool expectServerBreakNotification = false)
        {
            string client1FileName;
            string client2FileName;

            GenerateFileNames(isBothClientDirectory, isClient1ParentDirectory, out client1FileName, out client2FileName);

            #region Add Event Handler

            client1.Smb2Client.LeaseBreakNotificationReceived += new Action <Packet_Header, LEASE_BREAK_Notification_Packet>(OnLeaseBreakNotificationReceived);
            clientToAckLeaseBreak = client1;

            #endregion

            #region Client1 (LeaseOpen) Open a File with Lease RWH or Directory with RH

            BaseTestSite.Log.Add(LogEntryKind.TestStep,
                                 "Start the first client to create a file by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE (with LeaseV2 context)");
            SetupClientConnection(client1, out client1TreeId);
            Smb2CreateContextResponse[] createContextResponse;
            client1.Create(client1TreeId, client1FileName, isBothClientDirectory || isClient1ParentDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                           out client1FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                client1RequestLease
            },
                           checker: (Packet_Header header, CREATE_Response response) =>
            {
                if (response.OplockLevel != OplockLevel_Values.OPLOCK_LEVEL_LEASE)
                {
                    BaseTestSite.Assume.Inconclusive("Server OPLOCK Level is: {0}, expected: {1} indicating support for leasing.", response.OplockLevel, OplockLevel_Values.OPLOCK_LEVEL_LEASE);
                }
            }
                           );

            #endregion

            // Get response lease for Client1 (LeaseOpen)
            client1ResponseLease = (createContextResponse != null) ? createContextResponse.First() : new Smb2CreateResponseLease();


            #region Start a second client (OperationOpen) to request lease by using the same lease key with the first client
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a second client to create the same file with the first client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE");
            SetupClientConnection(client2, out client2TreeId);
            client2.Create(client2TreeId, client2FileName, isBothClientDirectory ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client2FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                client2RequestLease
            },
                           checker: (Packet_Header header, CREATE_Response response) =>
            {
                if (response.OplockLevel != OplockLevel_Values.OPLOCK_LEVEL_LEASE)
                {
                    BaseTestSite.Assume.Inconclusive("Server OPLOCK Level is: {0}, expected: {1} indicating support for leasing.", response.OplockLevel, OplockLevel_Values.OPLOCK_LEVEL_LEASE);
                }
            }
                           );

            #endregion

            // Check whether server will send out lease break notification or not
            CheckBreakNotification(expectServerBreakNotification);

            // Get response lease for Client2 (OperationOpen)
            client2ResponseLease = createContextResponse.First();
        }
コード例 #31
0
        /// <summary>
        /// Get create context for OpenFile
        /// </summary>
        private Smb2CreateContextRequest[] GetOpenFileHandleContext(
            DurableV1RequestContext durableV1RequestContext,
            DurableV2RequestContext durableV2RequestContext,
            DurableV1ReconnectContext durableV1ReconnectContext,
            DurableV2ReconnectContext durableV2ReconnectContext,
            bool isSameCreateGuid)
        {
            Smb2CreateContextRequest[] handleContext = new Smb2CreateContextRequest[] { };

            if (durableV1RequestContext == DurableV1RequestContext.DurableV1RequestContextExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST);

                handleContext = handleContext.Append(
                    new Smb2CreateDurableHandleRequest
                {
                    DurableRequest = isSameCreateGuid ? Guid.Empty : Guid.NewGuid(),
                });
            }
            if (durableV2RequestContext != DurableV2RequestContext.DurableV2RequestContextNotExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2);

                if (durableV2RequestContext == DurableV2RequestContext.DurableV2RequestContextExistWithoutPersistent)
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleRequestV2
                    {
                        CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                    });
                }
                else
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleRequestV2
                    {
                        CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                        Flags      = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                    });
                }
            }
            if (durableV1ReconnectContext == DurableV1ReconnectContext.DurableV1ReconnectContextExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_RECONNECT);

                handleContext = handleContext.Append(
                    new Smb2CreateDurableHandleReconnect
                {
                    Data = new FILEID {
                        Persistent = fileIdBeforDisconnection.Persistent
                    }
                });
            }
            if (durableV2ReconnectContext != DurableV2ReconnectContext.DurableV2ReconnectContextNotExist)
            {
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2);

                if (durableV2ReconnectContext == DurableV2ReconnectContext.DurableV2ReconnectContextExistWithoutPersistent)
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleReconnectV2
                    {
                        CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                        FileId     = new FILEID {
                            Persistent = fileIdBeforDisconnection.Persistent
                        }
                    });
                }
                else
                {
                    handleContext = handleContext.Append(
                        new Smb2CreateDurableHandleReconnectV2
                    {
                        CreateGuid = isSameCreateGuid ? createGuid : Guid.NewGuid(),
                        Flags      = CREATE_DURABLE_HANDLE_RECONNECT_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                        FileId     = new FILEID {
                            Persistent = fileIdBeforDisconnection.Persistent
                        }
                    });
                }
            }

            return(handleContext);
        }
コード例 #32
0
        private void AppInstanceIdTest(bool sameAppInstanceId, bool containCreateDurableContext)
        {
            string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb);

            #region Client 1 Connect to Server
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the first client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT");
            clientForInitialOpen = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientForInitialOpen.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic1IPAddress);
            clientForInitialOpen.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            clientForInitialOpen.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            uint treeIdForInitialOpen;
            clientForInitialOpen.TreeConnect(sharePath, out treeIdForInitialOpen);

            Guid   appInstanceId = Guid.NewGuid();
            FILEID fileIdForInitialOpen;
            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "The first client sends CREATE request for exclusive open with SMB2_CREATE_APP_INSTANCE_ID create context.");
            Smb2CreateContextResponse[] serverCreateContexts;
            Smb2CreateContextRequest[]  createContextsRequestForInitialOpen = null;
            if (containCreateDurableContext)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is also included in the CREATE request.");
                createContextsRequestForInitialOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateDurableHandleRequestV2
                    {
                        CreateGuid = Guid.NewGuid()
                    },
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = appInstanceId
                    }
                };
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is not included in the CREATE request.");
                createContextsRequestForInitialOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = appInstanceId
                    }
                };
            }

            clientForInitialOpen.Create(
                treeIdForInitialOpen,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdForInitialOpen,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                createContextsRequestForInitialOpen,
                shareAccess: ShareAccess_Values.NONE);
            #endregion

            #region Client 2 Connect to Server

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the second client by sending the following requests: NEGOTIATE; SESSION-SETUP; TREE_CONNECT");
            clientForReOpen = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientForReOpen.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress, TestConfig.ClientNic2IPAddress);
            clientForReOpen.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            clientForReOpen.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            uint treeIdForReOpen;
            clientForReOpen.TreeConnect(sharePath, out treeIdForReOpen);

            FILEID fileIdForReOpen;
            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "The second client sends CREATE request for exclusive open with the {0} SMB2_CREATE_APP_INSTANCE_ID of the first client.", sameAppInstanceId ? "same" : "different");
            Smb2CreateContextRequest[] createContextsRequestForReOpen = null;
            if (containCreateDurableContext)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is also included in the CREATE request.");
                createContextsRequestForReOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateDurableHandleRequestV2
                    {
                        CreateGuid = Guid.NewGuid()
                    },
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = sameAppInstanceId ? appInstanceId : Guid.NewGuid()
                    }
                };
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 create context is not included in the CREATE request.");
                createContextsRequestForReOpen = new Smb2CreateContextRequest[] {
                    new Smb2CreateAppInstanceId
                    {
                        AppInstanceId = sameAppInstanceId ? appInstanceId : Guid.NewGuid()
                    }
                };
            }

            clientForReOpen.Create(
                treeIdForReOpen,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdForReOpen,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                createContextsRequestForReOpen,
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
            {
                if (sameAppInstanceId)
                {
                    BaseTestSite.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, header.Status, "The second client should create the open successfully.");
                }
                else
                {
                    BaseTestSite.Assert.AreNotEqual(Smb2Status.STATUS_SUCCESS, header.Status, "The second client should not create the open successfully.");
                }
            });

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends another WRITE request.");

            if (sameAppInstanceId)
            {
                clientForInitialOpen.Write(treeIdForInitialOpen, fileIdForInitialOpen, content,
                                           checker: (header, response) =>
                {
                    BaseTestSite.Assert.AreNotEqual(
                        Smb2Status.STATUS_SUCCESS,
                        header.Status,
                        "The initial open is closed. Write should not succeed. Actually server returns with {0}.", Smb2Status.GetStatusCode(header.Status));
                    BaseTestSite.CaptureRequirementIfAreEqual(
                        Smb2Status.STATUS_FILE_CLOSED,
                        header.Status,
                        RequirementCategory.STATUS_FILE_CLOSED.Id,
                        RequirementCategory.STATUS_FILE_CLOSED.Description);
                });

                // The first open is closed, no need to do clean up job.
                // Clean up the second client.
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF; DISCONNECT");
                clientForReOpen.Close(treeIdForReOpen, fileIdForReOpen);
                clientForReOpen.TreeDisconnect(treeIdForReOpen);
                clientForReOpen.LogOff();
                clientForReOpen.Disconnect();
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "The initial open is not closed. Write should succeed.");
                clientForInitialOpen.Write(treeIdForInitialOpen, fileIdForInitialOpen, content);

                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF");
                clientForInitialOpen.Close(treeIdForInitialOpen, fileIdForInitialOpen);
                clientForInitialOpen.TreeDisconnect(treeIdForInitialOpen);
                clientForInitialOpen.LogOff();

                // The second client doesn't create the open succesfully, so no need to close the open.
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: TREE_DISCONNECT; LOG_OFF; DISCONNECT");
                clientForReOpen.TreeDisconnect(treeIdForReOpen);
                clientForReOpen.LogOff();
                clientForReOpen.Disconnect();
            }

            #endregion
        }
コード例 #33
0
        public void CreateRequest(
            CreateFileNameType fileNameType,
            CreateOptionsFileOpenReparsePointType fileOpenReparsePointType,
            CreateOptionsFileDeleteOnCloseType fileDeleteOnCloseType,
            CreateContextType contextType,
            ImpersonationLevelType impersonationType,
            CreateFileType fileType)
        {
            #region Header
            Packet_Header_Flags_Values headerFlag = testConfig.SendSignedRequest ? Packet_Header_Flags_Values.FLAGS_SIGNED : Packet_Header_Flags_Values.NONE;

            #endregion

            #region File Name
            string fileName = GetFileName(fileNameType);
            #endregion

            #region CreateOptions
            CreateOptions_Values createOptions = fileType == CreateFileType.DirectoryFile ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            if (fileOpenReparsePointType == CreateOptionsFileOpenReparsePointType.FileOpenReparsePointSet)
            {
                createOptions |= CreateOptions_Values.FILE_OPEN_REPARSE_POINT;
            }
            if (fileDeleteOnCloseType == CreateOptionsFileDeleteOnCloseType.FileDeteteOnCloseSet)
            {
                createOptions |= CreateOptions_Values.FILE_DELETE_ON_CLOSE;
            }
            #endregion

            #region CreateContexts
            Smb2CreateContextRequest[] createContexts = new Smb2CreateContextRequest[] { };
            Create_ContextType = contextType;
            switch (contextType)
            {
            case CreateContextType.NoCreateContext:
                break;

            case CreateContextType.InvalidCreateContext:
            case CreateContextType.InvalidCreateContextSize:
                testClient.BeforeSendingPacket(ReplacePacketByInvalidCreateContext);
                break;

            case CreateContextType.ValidCreateContext:
                testConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_QUERY_ON_DISK_ID);

                createContexts = createContexts.Append(new Smb2CreateQueryOnDiskId());
                break;

            default:
                throw new ArgumentException("contextType");
            }
            #endregion

            #region ImpersonationLevel
            ImpersonationLevel_Values impersonation = ImpersonationLevel_Values.Impersonation;
            if (impersonationType == ImpersonationLevelType.InvalidImpersonationLevel)
            {
                impersonation = (ImpersonationLevel_Values)0x00000004; //Non-existed impersonation level
            }

            #endregion

            #region DesiredAccess
            AccessMask accessMask = AccessMask.GENERIC_READ | AccessMask.GENERIC_WRITE | AccessMask.DELETE;
            #endregion

            Smb2CreateContextResponse[] contextResponse;

            uint status = testClient.Create(
                treeId,
                fileName,
                createOptions,
                headerFlag,
                out fileID,
                out contextResponse,
                createContexts: createContexts,
                accessMask: accessMask,
                checker: (header, response) => { },
                impersonationLevel: impersonation);

            CreateResponse((ModelSmb2Status)status, createCloseConfig);
        }
コード例 #34
0
        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
        }
コード例 #35
0
        /// <summary>
        /// Open the shared virtual disk file.
        /// </summary>
        /// <param name="fileName">The virtual disk file name to be used</param>
        /// <param name="requestId">OpenRequestId, same with other operations' request id</param>
        /// <param name="hasInitiatorId">If the SVHDX_OPEN_DEVICE_CONTEXT contains InitiatorId</param>
        /// <param name="rsvdClient">The instance of rsvd client. NULL stands for the default client</param>
        public void OpenSharedVHD(string fileName, ulong?requestId = null, bool hasInitiatorId = true, RsvdClient rsvdClient = null)
        {
            if (rsvdClient == null)
            {
                rsvdClient = this.client;
            }

            rsvdClient.Connect(
                TestConfig.FileServerNameContainingSharedVHD,
                TestConfig.FileServerIPContainingSharedVHD,
                TestConfig.DomainName,
                TestConfig.UserName,
                TestConfig.UserPassword,
                TestConfig.DefaultSecurityPackage,
                TestConfig.UseServerGssToken,
                TestConfig.ShareContainingSharedVHD);

            Smb2CreateContextRequest[] contexts = null;
            if (TestConfig.ServerServiceVersion == (uint)0x00000001)
            {
                contexts = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateSvhdxOpenDeviceContext
                    {
                        Version                 = TestConfig.ServerServiceVersion,
                        OriginatorFlags         = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                        InitiatorHostName       = TestConfig.InitiatorHostName,
                        InitiatorHostNameLength = (ushort)(TestConfig.InitiatorHostName.Length * 2),
                        OpenRequestId           = requestId == null ? ((ulong)new System.Random().Next()) : requestId.Value,
                        InitiatorId             = hasInitiatorId ? Guid.NewGuid():Guid.Empty,
                        HasInitiatorId          = hasInitiatorId
                    }
                };
            }
            else if (TestConfig.ServerServiceVersion == (uint)0x00000002)
            {
                contexts = new Smb2CreateContextRequest[]
                {
                    new Smb2CreateSvhdxOpenDeviceContextV2
                    {
                        Version                          = TestConfig.ServerServiceVersion,
                        OriginatorFlags                  = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                        InitiatorHostName                = TestConfig.InitiatorHostName,
                        InitiatorHostNameLength          = (ushort)(TestConfig.InitiatorHostName.Length * 2),
                        OpenRequestId                    = requestId == null ? ((ulong)new System.Random().Next()) : requestId.Value,
                        InitiatorId                      = hasInitiatorId ? Guid.NewGuid():Guid.Empty,
                        HasInitiatorId                   = hasInitiatorId,
                        VirtualDiskPropertiesInitialized = 0,
                        ServerServiceVersion             = 0,
                        VirtualSize                      = 0,
                        PhysicalSectorSize               = 0,
                        VirtualSectorSize                = 0
                    }
                };
            }
            else
            {
                throw new ArgumentException("The ServerServiceVersion {0} is not supported.", "Version");
            }

            CREATE_Response response;

            Smb2CreateContextResponse[] serverContextResponse;
            uint status = rsvdClient.OpenSharedVirtualDisk(
                fileName + fileNameSuffix,
                FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                contexts,
                out serverContextResponse,
                out response);

            BaseTestSite.Assert.AreEqual(
                (uint)Smb2Status.STATUS_SUCCESS,
                status,
                "Open shared virtual disk file should succeed, actual status: {0}",
                GetStatus(status));
        }
コード例 #36
0
        /// <summary>
        /// Connect to the share VHD file.
        /// </summary>
        private bool TestRsvdVersion(
            string vhdxName,
            string share,
            RSVD_PROTOCOL_VERSION version)
        {
            using (RsvdClient client = new RsvdClient(new TimeSpan(0, 0, defaultTimeoutInSeconds)))
            {
                CREATE_Response response;
                Smb2CreateContextResponse[] serverContexts;
                client.Connect(SUTName, SUTIpAddress, Credential.DomainName, Credential.AccountName, Credential.Password, SecurityPackageType, true, share);

                Smb2CreateContextRequest[] contexts;
                if (version == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2)
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContextV2
                        {
                            Version = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_2,
                            OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2),  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                            VirtualDiskPropertiesInitialized = 0,
                            ServerServiceVersion = 0,
                            VirtualSectorSize = 0,
                            PhysicalSectorSize = 0,
                            VirtualSize = 0
                        }
                    };
                }
                else
                {
                    contexts = new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateSvhdxOpenDeviceContext
                        {
                            Version = (uint)RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1,
                            OriginatorFlags = (uint)OriginatorFlag.SVHDX_ORIGINATOR_PVHDPARSER,
                            InitiatorHostName = initiatorHostName,
                            InitiatorHostNameLength = (ushort)(initiatorHostName.Length * 2)  // InitiatorHostName is a null-terminated Unicode UTF-16 string
                        }
                    };
                }

                uint status;
                status = client.OpenSharedVirtualDisk(
                    vhdxName,
                    TestTools.StackSdk.FileAccessService.FsCreateOption.FILE_NO_INTERMEDIATE_BUFFERING,
                    contexts,
                    out serverContexts,
                    out response);

                bool result = false;

                if (status != Smb2Status.STATUS_SUCCESS)
                {
                    result = false;
                    logWriter.AddLog(LogLevel.Information, string.Format("{0} is found not supported.", version));
                    return result;
                }

                result = CheckOpenDeviceContext(serverContexts, version);
                client.CloseSharedVirtualDisk();

                return result;
            }
        }