当前位置: 首页>>代码示例>>C#>>正文


C# Smb2FunctionalClient.Create方法代码示例

本文整理汇总了C#中Smb2FunctionalClient.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Smb2FunctionalClient.Create方法的具体用法?C# Smb2FunctionalClient.Create怎么用?C# Smb2FunctionalClient.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Smb2FunctionalClient的用法示例。


在下文中一共展示了Smb2FunctionalClient.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BVT_SMB2Basic_CancelRegisteredChangeNotify

        public void BVT_SMB2Basic_CancelRegisteredChangeNotify()
        {
            uint status;
            string testDirectory = CreateTestDirectory(TestConfig.SutComputerName, TestConfig.BasicFileShare);
            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Test directory \"{0}\" was created on share \"{1}\"", testDirectory, TestConfig.BasicFileShare);

            client1 = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            client1.Smb2Client.ChangeNotifyResponseReceived += new Action<FILE_NOTIFY_INFORMATION[],Packet_Header,CHANGE_NOTIFY_Response>(OnChangeNotifyResponseReceived);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a client to create a file by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT; CREATE");
            client1.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
            status = client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            status = client1.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            uint treeId1;
            status = client1.TreeConnect(uncSharePath, out treeId1);
            Smb2CreateContextResponse[] serverCreateContexts;
            FILEID fileId1;
            status = client1.Create(
                treeId1,
                testDirectory,
                CreateOptions_Values.FILE_DIRECTORY_FILE,
                out fileId1,
                out serverCreateContexts);

            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                "Client starts to register CHANGE_NOTIFY on directory \"{0}\"", testDirectory);
            client1.ChangeNotify(treeId1, fileId1, CompletionFilter_Values.FILE_NOTIFY_CHANGE_LAST_ACCESS);

            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                "Client starts to cancel the registered CHANGE_NOTIFY on directory \"{0}\"", testDirectory);
            client1.Cancel();

            BaseTestSite.Assert.IsTrue(
                changeNotificationReceived.WaitOne(TestConfig.WaitTimeoutInMilliseconds),
                "Change notification should be received within {0} milliseconds", TestConfig.WaitTimeoutInMilliseconds);

            BaseTestSite.Assert.AreNotEqual(
                Smb2Status.STATUS_SUCCESS,
                receivedChangeNotifyHeader.Status, "CHANGE_NOTIFY is not expected to success after cancel, actually server returns {0}.",
                Smb2Status.GetStatusCode(receivedChangeNotifyHeader.Status));
            BaseTestSite.CaptureRequirementIfAreEqual(
                Smb2Status.STATUS_CANCELLED,
                receivedChangeNotifyHeader.Status,
                RequirementCategory.STATUS_CANCELLED.Id,
                RequirementCategory.STATUS_CANCELLED.Description);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF");
            client1.Close(treeId1, fileId1);
            client1.TreeDisconnect(treeId1);
            client1.LogOff();
        }
开发者ID:yazeng,项目名称:WindowsProtocolTestSuites,代码行数:59,代码来源:SMB2Basic.cs

示例2: OpenRequest

        public void OpenRequest(
            ClientGuidType clientGuidType,
            PathNameType pathNameType,
            CreateType createType,
            ShareType shareType,
            AppInstanceIdType appInstanceIdType)
        {
            Smb2FunctionalClient testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            uint treeId;
            string share;
            switch (shareType)
            {
                case ShareType.SameShare:
                    share = testConfig.BasicFileShare;
                    break;
                case ShareType.DifferentShareSameLocal:
                    share = testConfig.SameWithSMBBasic;
                    break;
                case ShareType.DifferentShareDifferentLocal:
                    share = testConfig.DifferentFromSMBBasic;
                    cleanFileInDifferentShare = true;
                    break;
                default:
                    throw new ArgumentException("shareType");
            }

            ConnectToShare(
                clientDialect,
                testClient,
                clientGuidType == ClientGuidType.SameClientGuid ? this.connection_ClientGuid : Guid.NewGuid(),
                share,
                out treeId);

            FILEID fileId;
            Smb2CreateContextResponse[] createContextResponse;
            uint status;
            string fileNameInOpen;
            if (pathNameType == PathNameType.SamePathName)
            {
                fileNameInOpen = fileName;
            }
            else
            {
                fileNameInOpen = fileName + different;
                cleanFileWithDifferentName = true;
            }

            status = testClient.Create(
                treeId,
                fileNameInOpen,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponse,
                createContexts: CreateContexts(appInstanceIdType, createType, false),
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) => { });

            // The file is not created, no need to delete.
            if (status != Smb2Status.STATUS_SUCCESS)
            {
                cleanFileInDifferentShare = false;
                cleanFileWithDifferentName = false;
            }

            testClient.Disconnect();
            testClient = null;

            // Check if the Open is closed.
            // If status is success, and fileId is the same with the previous one, then the Open is not closed.
            // Otherwise, use some other way to check if the Open is closed.
            bool ifClosed;
            if (status == Smb2Status.STATUS_SUCCESS && fileId.Persistent == this.open_FileId.Persistent)
                ifClosed = false;
            else
                ifClosed = CheckIfOpenClosed(clientDialect, createType);
            this.OpenResponse(ifClosed ? OpenStatus.OpenClosed : OpenStatus.OpenNotClosed);
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:77,代码来源:AppInstanceIdAdapter.cs

示例3: ValidateByteLockRangeFromAnotherClient

        /// <summary>
        /// Read and write file within byte lock range when the file is locked or unlocked
        /// </summary>
        /// <param name="isLocked">Set true to indicate that byte lock range is taken on the file</param>
        /// <param name="serverName">Name of file server to access</param>
        /// <param name="targetFileName">Target file name to read and write</param>
        private void ValidateByteLockRangeFromAnotherClient(bool isLocked, string serverName, string targetFileName)
        {
            uint status = 0;

            Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);

            client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            client.ConnectToServer(TestConfig.UnderlyingTransport, serverName, currentAccessIp);

            status = client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);

            status = client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                serverName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);

            uint treeId;
            status = client.TreeConnect(uncSharePath, out treeId);

            Smb2CreateContextResponse[] serverCreateContexts;
            FILEID fileId;
            status = client.Create(
                treeId,
                targetFileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts);

            string data;
            Random random = new Random();
            uint offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
            uint length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));
            status = client.Read(treeId, fileId, offset, length, out data);

            status = client.Write(treeId, fileId, contentWrite, checker: (header, response) => { });
            if (isLocked)
            {
                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    status,
                    "Write content to locked range of file from different client is not expected to success");
                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_FILE_LOCK_CONFLICT,
                    status,
                    RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
                    RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
            }
            else
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    status,
                    "Write content in file should succeed, actual status is {0}", Smb2Status.GetStatusCode(status));
            }
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:62,代码来源:FileServerFailoverWithLock.cs

示例4: OpenCreate

 /// <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) =>
         {
         });
 }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:25,代码来源:HandleAdapter.cs

示例5: CreateOpenFromClient

        /// <summary>
        /// Create an open from client, this include NEGOTIATE and SESSION_SETUP with server, TREE_CONNECT to the share and CREATE an open to file/directory
        /// </summary>
        /// <param name="client">Client used to take the operation</param>
        /// <param name="clientGuid">Client GUID for negotiation</param>
        /// <param name="targetName">File/directory name for the open</param>
        /// <param name="isDirectory">Set true if create open to a directory, set false if create open to a file</param>
        /// <param name="accessMask">Desired access when create the open</param>
        /// <param name="treeId">Out param for tree id used to connect to the share</param>
        /// <param name="fileId">Out param for file id that is associated with the open</param>
        /// <param name="shareAccess">Optional param for share access when create the open</param>
        /// <returns>Status value returned from CREATE request</returns>
        private uint CreateOpenFromClient(Smb2FunctionalClient client, Guid clientGuid, string targetName, bool isDirectory, LeaseStateValues requestLeaseState, AccessMask accessMask, out uint treeId, out FILEID fileId, ShareAccess_Values shareAccess = ShareAccess_Values.FILE_SHARE_DELETE | ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE)
        {
            #region Negotiate
            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "Client {0} sends NEGOTIATE request with the following capabilities: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES.", clientGuid.ToString());
            client.Negotiate(
                TestConfig.RequestDialects,
                TestConfig.IsSMB1NegotiateEnabled,
                capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
                clientGuid: clientGuid,
                checker: (Packet_Header header, NEGOTIATE_Response response) =>
                {
                    BaseTestSite.Assert.AreEqual(
                        Smb2Status.STATUS_SUCCESS,
                        header.Status,
                        "Negotiation is expected success, actually server returns {0}", Smb2Status.GetStatusCode(header.Status));

                    TestConfig.CheckNegotiateDialect(DialectRevision.Smb30, response);
                    TestConfig.CheckNegotiateCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING, response);
                });
            #endregion

            #region SESSION_SETUP
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client {0} sends SESSION_SETUP request.", clientGuid.ToString());
            status = client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            #endregion

            #region TREE_CONNECT to share
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client {0} sends TREE_CONNECT request.", clientGuid.ToString());
            status = client.TreeConnect(uncSharePath, out treeId);
            #endregion

            #region CREATE
            Smb2CreateContextResponse[] serverCreateContexts;
            CreateOptions_Values createOptions;

            if (isDirectory)
            {
                createOptions = CreateOptions_Values.FILE_DIRECTORY_FILE;
            }
            else
            {
                createOptions = CreateOptions_Values.FILE_NON_DIRECTORY_FILE;
            }

            // Include FILE_DELETE_ON_CLOSE if accessMask has DELETE
            if ((accessMask & AccessMask.DELETE) == AccessMask.DELETE)
            {
                createOptions = createOptions | CreateOptions_Values.FILE_DELETE_ON_CLOSE;
            }

            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "Client {0} sends CREATE request with the lease state in SMB2_CREATE_REQUEST_LEASE_V2 set to {1}.", clientGuid.ToString(), requestLeaseState);
            status = client.Create(
                treeId,
                targetName,
                createOptions,
                out fileId,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                new Smb2CreateContextRequest[]
                {
                    new Smb2CreateRequestLeaseV2
                    {
                        LeaseKey = clientGuid,
                        LeaseState = requestLeaseState
                    }
                },
                accessMask: accessMask,
                shareAccess: shareAccess,
                checker: (header, response) => { });

            return status;
            #endregion
        }
开发者ID:XiaotianLiuMS,项目名称:WindowsProtocolTestSuites,代码行数:93,代码来源:DirectoryLeasingExtendedTest.cs

示例6: ReconnectResilientHandle

        private void ReconnectResilientHandle(
            Smb2FunctionalClient client,
            Guid clientGuid,
            string fileName,
            FILEID fileId,
            NtStatus expectedReconnectStatus,
            string message)
        {
            uint treeId;
            ConnectToShare(
                client,
                clientGuid,
                out treeId);
            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Reconnect to resilient handle");

            Smb2CreateContextResponse[] createContextResponse;
            uint status = client.Create(
                treeId,
                fileName,
                CreateOptions_Values.NONE,
                out fileId,
                out createContextResponse,
                createContexts: new Smb2CreateContextRequest[]
                    {
                        new Smb2CreateDurableHandleReconnect()
                        {
                            Data = fileId
                        }
                    },
                checker: (header, response) =>
                {
                    // do nothing, skip the exception
                }
                );
            BaseTestSite.Assert.AreEqual<NtStatus>(
                expectedReconnectStatus,
                (NtStatus)status,
                message);
        }
开发者ID:XiaotianLiuMS,项目名称:WindowsProtocolTestSuites,代码行数:41,代码来源:ResilientOpenScavengerTimer.cs

示例7: CreateFile

        private void CreateFile(string uncShare, string fileName, int lengthInByte)
        {
            Site.Log.Add(
                LogEntryKind.Debug,
                "Create file {0} in share {1}", fileName, uncShare);

            Smb2FunctionalClient client = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            client.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress);

            client.CreditGoal = 32;

            client.Negotiate(
                new DialectRevision[] { ModelUtility.GetDialectRevision(config.MaxSmbVersionSupported) },
                testConfig.IsSMB1NegotiateEnabled,
                capabilityValue: Capabilities_Values.GLOBAL_CAP_LARGE_MTU);

            client.SessionSetup(
                testConfig.DefaultSecurityPackage,
                testConfig.SutComputerName,
                testConfig.AccountCredential,
                testConfig.UseServerGssToken);

            uint tId;
            client.TreeConnect(
                uncShare,
                out tId);

            Smb2CreateContextResponse[] serverCreateContexts;
            FILEID fId;
            client.Create(
                tId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fId,
                out serverCreateContexts);

            string content;
            if (isMultiCreditSupportedOnConnection)
            {
                content = Smb2Utility.CreateRandomStringInByte(lengthInByte);
                client.Write(tId, fId, content);
            }
            else
            {
                // Write several times if server does not support multi credit
                int writeTimes = lengthInByte / (64 * 1024);
                int rest = lengthInByte % (64 * 1024);
                ulong offset = 0;

                for (int time = 0; time < writeTimes; time++)
                {
                    content = Smb2Utility.CreateRandomString(64);
                    client.Write(tId, fId, content, offset);
                    offset += 64 * 1024;
                }

                if (rest != 0)
                {
                    content = Smb2Utility.CreateRandomStringInByte(rest);
                    client.Write(tId, fId, content, offset);
                }
            }

            client.Close(tId, fId);

            client.TreeDisconnect(tId);

            client.LogOff();

            client.Disconnect();

            Site.Log.Add(
                LogEntryKind.Debug,
                "Create file {0} in share {1}", fileName, uncShare);
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:75,代码来源:CreditMgmtAdapter.cs

示例8: FileOperation

        private void FileOperation(OplockFileOperation fileOperation, string fileName)
        {
            Site.Log.Add(LogEntryKind.Debug, "File operation on same file from another client");

            Smb2FunctionalClient clientForAnotherOpen = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            clientForAnotherOpen.ConnectToServer(testConfig.UnderlyingTransport, testConfig.SutComputerName, testConfig.SutIPAddress, testConfig.ClientNic1IPAddress);

            clientForAnotherOpen.Negotiate(new DialectRevision[]{negotiatedDialect}, testConfig.IsSMB1NegotiateEnabled);

            clientForAnotherOpen.SessionSetup(
                testConfig.DefaultSecurityPackage,
                server,
                testConfig.AccountCredential,
                testConfig.UseServerGssToken);

            uint treeIdForAnotherOpen;
            clientForAnotherOpen.TreeConnect(
                uncSharePath,
                out treeIdForAnotherOpen);

            FILEID fileIdForAnotherOpen;
            Smb2CreateContextResponse[] serverCreateContexts;

            clientForAnotherOpen.Create(
                treeIdForAnotherOpen,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdForAnotherOpen,
                out serverCreateContexts);

            if (fileOperation == OplockFileOperation.WriteFromAnotherOpen)
            {
                string writeContent = Smb2Utility.CreateRandomString(1);

                clientForAnotherOpen.Write(treeIdForAnotherOpen, fileIdForAnotherOpen, writeContent);
            }
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:37,代码来源:OplockAdapter.cs

示例9: SetSecurityDescriptor

        protected void SetSecurityDescriptor(string sharePath, string fileName, _SECURITY_DESCRIPTOR sd, SET_INFO_Request_AdditionalInformation_Values securityAttributesToApply)
        {
            Smb2FunctionalClient clientAdmin;
            clientAdmin = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientAdmin.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
            uint treeId;
            ConnectToShare(clientAdmin, TestConfig.AccountCredential, sharePath, out treeId);

            FILEID fileId;
            Smb2CreateContextResponse[] createContextResponses;
            clientAdmin.Create(treeId,
                fileName,
                fileName == null ? CreateOptions_Values.FILE_DIRECTORY_FILE : CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponses,
                accessMask: AccessMask.READ_CONTROL | AccessMask.WRITE_DAC | AccessMask.FILE_READ_ATTRIBUTES | AccessMask.WRITE_OWNER | AccessMask.ACCESS_SYSTEM_SECURITY,
                shareAccess: ShareAccess_Values.FILE_SHARE_DELETE | ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE,
                createDisposition: CreateDisposition_Values.FILE_OPEN);
            clientAdmin.SetSecurityDescriptor(treeId, fileId, securityAttributesToApply, sd);
            clientAdmin.Close(treeId, fileId);
            clientAdmin.TreeDisconnect(treeId);
            clientAdmin.Disconnect();
        }
开发者ID:Microsoft,项目名称:WindowsProtocolTestSuites,代码行数:23,代码来源:AuthorizationTestBase.cs

示例10: DeleteExistingFile

        protected void DeleteExistingFile(string sharePath, string fileName)
        {
            Smb2FunctionalClient clientAdmin;
            clientAdmin = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientAdmin.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
            uint treeId;
            ConnectToShare(clientAdmin, TestConfig.AccountCredential, sharePath, out treeId);

            FILEID fileId;
            Smb2CreateContextResponse[] createContextResponses;
            clientAdmin.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE | CreateOptions_Values.FILE_DELETE_ON_CLOSE,
                out fileId,
                out createContextResponses,
                accessMask: AccessMask.FILE_READ_ATTRIBUTES | AccessMask.DELETE,
                shareAccess: ShareAccess_Values.FILE_SHARE_DELETE,
                createDisposition: CreateDisposition_Values.FILE_OPEN);
            clientAdmin.Close(treeId, fileId);
            clientAdmin.TreeDisconnect(treeId);
            clientAdmin.Disconnect();
        }
开发者ID:Microsoft,项目名称:WindowsProtocolTestSuites,代码行数:23,代码来源:AuthorizationTestBase.cs

示例11: CreateNewFile

        protected void CreateNewFile(string sharePath, string fileName)
        {
            Smb2FunctionalClient clientAdmin;
            clientAdmin = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            clientAdmin.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);
            uint treeId;
            ConnectToShare(clientAdmin, TestConfig.AccountCredential, sharePath, out treeId);

            FILEID fileId;
            Smb2CreateContextResponse[] createContextResponses;
            clientAdmin.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponses,
                accessMask: AccessMask.FILE_READ_DATA | AccessMask.FILE_WRITE_DATA |
                            AccessMask.FILE_APPEND_DATA | AccessMask.FILE_READ_EA |
                            AccessMask.FILE_WRITE_EA | AccessMask.READ_CONTROL |
                            AccessMask.WRITE_DAC | AccessMask.FILE_READ_ATTRIBUTES |
                            AccessMask.FILE_WRITE_ATTRIBUTES | AccessMask.SYNCHRONIZE,
                shareAccess: ShareAccess_Values.NONE,
                createDisposition: CreateDisposition_Values.FILE_CREATE);
            clientAdmin.Close(treeId, fileId);
            clientAdmin.TreeDisconnect(treeId);
            clientAdmin.Disconnect();
        }
开发者ID:Microsoft,项目名称:WindowsProtocolTestSuites,代码行数:27,代码来源:AuthorizationTestBase.cs

示例12: OpenFile

        private void OpenFile(
            Smb2FunctionalClient client,
            Guid clientGuid,
            string fileName,
            bool isPersistentHandle,
            out Guid createGuid,
            out uint treeId,
            out FILEID fileId)
        {
            // connect to share
            ConnectToShare(
                client,
                clientGuid,
                out treeId);
            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Connect to share '{0}' on scaleout server '{1}'", testConfig.BasicFileShare, testConfig.SutComputerName);

            #region Construct Create Context
            List<Smb2CreateContextRequest> createContextList = new List<Smb2CreateContextRequest>();
            createGuid = Guid.Empty;
            if (isPersistentHandle)
            {
                // durable handle request context
                createGuid = Guid.NewGuid();
                createContextList.Add(new Smb2CreateDurableHandleRequestV2()
                        {
                            CreateGuid = createGuid,
                            Flags = CREATE_DURABLE_HANDLE_REQUEST_V2_Flags.DHANDLE_FLAG_PERSISTENT,
                            Timeout = 0 // default
                        });
            }
            #endregion

            // open file
            Smb2CreateContextResponse[] createContextResponses;
            client.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponses,
                createContexts: createContextList.ToArray<Smb2CreateContextRequest>()
            );
            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Create Open with file name '{0}'", fileName);

            #region check whether Persistent Handle is created successfully with current status
            if (isPersistentHandle)
            {
                BaseTestSite.Assert.IsTrue(
                    CheckDurableCreateContextResponse(createContextResponses),
                    "Create Response should contain Smb2CreateDurableHandleResponseV2.");
            }
            #endregion
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:57,代码来源:ResilientWithPersistentHandle.cs

示例13: TriggerBreakFromClient

        /// <summary>
        /// Attempt to trigger LeaseBreakNotification from a separate client
        /// </summary>
        /// <param name="client">Client to trigger LeaseBreakNotification</param>
        /// <param name="requestDialect">Negotiate dialects</param>
        /// <param name="serverName">Name of file server to access</param>
        /// <param name="isDirectory">True value indicating to open a directory, false for a file</param>
        /// <param name="requestedLeaseState">LeaseState when open the directory or file</param>
        /// <param name="accessMask">AccessMask when open the directory or file</param>
        private void TriggerBreakFromClient(
            Smb2FunctionalClient client,
            DialectRevision[] requestDialect,
            string serverName,
            bool isDirectory,
            LeaseStateValues requestedLeaseState,
            AccessMask accessMask)
        {
            BaseTestSite.Log.Add(LogEntryKind.Debug, "AfterFailover: Attempt to access same file/directory to trigger LeaseBreakNotification from a separate client with LeaseState {0} and AccessMask {1}", requestedLeaseState, accessMask);
            #region Negotiate
            status = client.Negotiate(
                requestDialect,
                TestConfig.IsSMB1NegotiateEnabled,
                capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES,
                checker: (Packet_Header header, NEGOTIATE_Response response) =>
                {
                    TestConfig.CheckNegotiateDialect(DialectRevision.Smb30, response);
                });
            #endregion

            #region SESSION_SETUP
            status = client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                serverName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            #endregion

            #region TREE_CONNECT to share
            uint treeId;
            status = client.TreeConnect(uncSharePath, out treeId);
            #endregion

            #region CREATE
            Smb2CreateContextResponse[] serverCreateContexts;
            FILEID fileId;
            status = client.Create(
                treeId, // To break lease on directory, create a new child item
                isDirectory ? testDirectory + @"\child.txt" : fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                new Smb2CreateContextRequest[]
                {
                    new Smb2CreateRequestLeaseV2
                    {
                        LeaseKey = Guid.NewGuid(),
                        LeaseState = requestedLeaseState
                    }
                },
                accessMask: accessMask,
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) => { });
            #endregion

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "AfterFailover: Finish triggering a LeaseBreakNotification from a separate client.");
        }
开发者ID:XiaotianLiuMS,项目名称:WindowsProtocolTestSuites,代码行数:69,代码来源:FileServerFailoverWithLeasing.cs

示例14: AppInstanceIdTest

        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()
//.........这里部分代码省略.........
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:101,代码来源:AppInstanceIdBasic.cs

示例15: PathNormalize

        // [MS-SMB2] 3.3.5.9   Receiving an SMB2 CREATE Request
        // If the request received has SMB2_FLAGS_DFS_OPERATIONS set in the Flags field of the SMB2 header, and TreeConnect.Share.IsDfs is TRUE, the server MUST verify the value of IsDfsCapable:
        // If IsDfsCapable is TRUE, the server MUST invoke the interface defined in [MS-DFSC] section 3.2.4.1 to normalize the path name by supplying the target path name.
        // [MS-DFSC] 3.2.4.1   Handling a Path Normalization Request
        // As specified in [MS-SMB2] section 3.3.5.9 and [MS-SMB] section 3.3.5.5, the SMB server invokes the DFS server to normalize the path name.
        // When DFS server matches the path name against DFS metadata:
        // If the path matches or contains a DFS link, the DFS server MUST respond to the path normalization request with STATUS_PATH_NOT_COVERED,
        //     indicating to the client to resolve the path by using a DFS link referral request.
        // Otherwise, the DFS server MUST change the path name to a path relative to the root of the namespace and return STATUS_SUCCESS.
        private void PathNormalize(bool containDFSLink)
        {
            smb2client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            smb2client.ConnectToServerOverTCP(TestConfig.SutIPAddress);
            smb2client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            smb2client.SessionSetup(TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);

            string dfsRootShare = Smb2Utility.GetUncPath(TestConfig.SutComputerName, TestConfig.StandaloneNamespace);
            smb2client.TreeConnect(dfsRootShare, out treeId);
            Smb2CreateContextResponse[] contextResp;

            // [MS-SMB2] 2.2.13   SMB2 CREATE Request
            // If SMB2_FLAGS_DFS_OPERATIONS is set in the Flags field of the SMB2 header,
            // the file name can be prefixed with DFS link information that will be removed during DFS name normalization as specified in section 3.3.5.9.
            string filaName = dfsRootShare + @"\";
            filaName += containDFSLink ? (TestConfig.DFSLink + @"\") : "";
            filaName += "PathNormalization_" + Guid.NewGuid();

            if (containDFSLink)
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends SMB2 create request to open a file in a DFS path contains DFS Link.");
            }
            else
            {
                BaseTestSite.Log.Add(LogEntryKind.TestStep, "Client sends SMB2 create request to open a file in a DFS path does not contain DFS Link.");
            }

            uint status = smb2client.Create(
                treeId,
                filaName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                Packet_Header_Flags_Values.FLAGS_DFS_OPERATIONS | Packet_Header_Flags_Values.FLAGS_SIGNED,
                out fileId,
                out contextResp,
                checker: (header, response) =>
                {
                    BaseTestSite.Log.Add(LogEntryKind.TestStep, "Verify server response.");
                    if (containDFSLink)
                    {
                        BaseTestSite.Assert.AreEqual(
                            (uint)NtStatus.STATUS_PATH_NOT_COVERED,
                            header.Status,
                            "DFS server matches the path name against DFS metadata. If the path matches or contains a DFS link, " +
                            "the DFS server MUST respond to the path normalization request with STATUS_PATH_NOT_COVERED, indicating to the client to resolve the path by using a DFS link referral request");
                    }
                    else
                    {
                        BaseTestSite.Assert.AreEqual(
                            Smb2Status.STATUS_SUCCESS,
                            header.Status,
                            "The DFS server MUST change the path name to a path relative to the root of the namespace and return STATUS_SUCCESS, actual status is {0}", Smb2Status.GetStatusCode(header.Status));
                    }
                });
        }
开发者ID:gitter-badger,项目名称:WindowsProtocolTestSuites,代码行数:66,代码来源:PathNormalization.cs


注:本文中的Smb2FunctionalClient.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。