public ModelOpenFileRequest( DurableV1RequestContext durableV1RequestContext, DurableV2RequestContext durableV2RequestContext, DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext, OplockLeaseType oplockLeaseType, bool isSameLeaseKey, bool isSameClient, bool isSameCreateGuid) : base(0) { this.durableV1RequestContext = durableV1RequestContext; this.durableV2RequestContext = durableV2RequestContext; this.durableV1ReconnectContext = durableV1ReconnectContext; this.durableV2ReconnectContext = durableV2ReconnectContext; this.oplockLeaseType = oplockLeaseType; this.isSameLeaseKey = isSameLeaseKey; this.isSameClient = isSameClient; this.isSameCreateGuid = isSameCreateGuid; }
/// <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); }
public void OpenRequest( ModelDialectRevision clientMaxDialect, PersistentBitType persistentBit, CAShareType connectToCAShare, OplockLeaseType oplockLeaseType, DurableV1RequestContext durableV1RequestContext, DurableV2RequestContext durableV2RequestContext, DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext) { requestDialect = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL; if (persistentBit == PersistentBitType.PersistentBitSet) { clientCapabilities |= Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES; } clientGuid = Guid.NewGuid(); requestedContext = oplockLeaseType; isCAShare = (connectToCAShare == CAShareType.CAShare); IPAddress targetIPAddress; string targetServer; #region Connect to Common Share or CA Share if (!isCAShare) { sharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare); fileName = "PrepareHandle_ConnectTo_CommonShareFile_" + Guid.NewGuid() + ".txt"; targetIPAddress = testConfig.SutIPAddress; targetServer = testConfig.SutComputerName; } else { sharePath = Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName); fileName = "PrepareHandle_ConnectTo_CAShareFile_" + Guid.NewGuid().ToString() + ".txt"; targetIPAddress = testConfig.CAShareServerIP; targetServer = testConfig.CAShareServerName; } testClientBeforeDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClientBeforeDisconnection.CreditGoal = 20; testClientBeforeDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress); testClientBeforeDisconnection.Negotiate( requestDialect, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilities, clientGuid: clientGuid, checker: (header, response) => { if (Smb2Utility.IsSmb3xFamily(response.DialectRevision) && handleConfig.IsPersistentHandleSupported && persistentBit == PersistentBitType.PersistentBitSet) { Site.Assert.IsTrue( response.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES), "The server MUST set SMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " + "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles. " + "Actual capabilities are {0}", response.Capabilities); } }); testClientBeforeDisconnection.SessionSetup( testConfig.DefaultSecurityPackage, targetServer, testConfig.AccountCredential, testConfig.UseServerGssToken); testClientBeforeDisconnection.TreeConnect(sharePath, out treeIdBeforeDisconnection, delegate(Packet_Header responseHeader, TREE_CONNECT_Response response) { if (isCAShare) { if (!response.Capabilities.HasFlag(Share_Capabilities_Values.SHARE_CAP_CONTINUOUS_AVAILABILITY)) { // skip test case for CA share is invalid Site.Assert.Inconclusive("This test case is applicable only when CA share is valid."); } } }); #endregion #region Construct Create Contexts Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext( durableV1RequestContext, durableV2RequestContext, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, false, false); #endregion #region Send Create request according to different context combination RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; switch (oplockLeaseType) { case OplockLeaseType.NoOplockOrLease: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; } break; case OplockLeaseType.BatchOplock: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; } break; case OplockLeaseType.LeaseV1: case OplockLeaseType.LeaseV2: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; } FILEID fileId; Smb2CreateContextResponse[] serverCreateContexts; uint status = OpenCreate( testClientBeforeDisconnection, treeIdBeforeDisconnection, fileName, out fileId, out serverCreateContexts, requestedOplockLevel, smb2CreateContextRequest); #endregion DurableHandleResponseContext durableHandleResponse; LeaseResponseContext leaseResponse; CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse); OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig); testClientBeforeDisconnection.TreeDisconnect(treeIdAfterDisconnection, (header, response) => { }); testClientBeforeDisconnection.LogOff(); }
/// <summary> /// 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); }
public void ReconnectOpenRequest( DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext, OplockLeaseType oplockLeaseType, LeaseKeyDifferentialType leaseKeyDifferentialType, ClientIdType clientIdType, CreateGuidType createGuidType) { if ((oplockLeaseType == OplockLeaseType.LeaseV1 || oplockLeaseType == OplockLeaseType.LeaseV2) && !testConfig.IsLeasingSupported) { Site.Assert.Inconclusive("Test case is applicable in servers that support leasing."); } bool isSameLeaseKey = (leaseKeyDifferentialType == LeaseKeyDifferentialType.SameLeaseKey); bool isSameClient = (clientIdType == ClientIdType.SameClient); bool isSameCreateGuid = (createGuidType == CreateGuidType.SameCreateGuid); FILEID fileIdAfterDisconnection; Smb2CreateContextResponse[] serverCreateContexts; IPAddress targetIPAddress; string targetServer; string targetShare; #region Construct Create Contexts Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext( DurableV1RequestContext.DurableV1RequestContextNotExist, DurableV2RequestContext.DurableV2RequestContextNotExist, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, isSameLeaseKey, isSameCreateGuid); #endregion #region Client reconnect to server Site.Log.Add(LogEntryKind.Debug, "Client reconnect to server"); #region Reconnect to Common Share or CA Share if (!isCAShare) { targetIPAddress = testConfig.SutIPAddress; targetServer = testConfig.SutComputerName; targetShare = testConfig.BasicFileShare; } else { targetIPAddress = testConfig.CAShareServerIP; targetServer = testConfig.CAShareServerName; targetShare = testConfig.CAShareName; } // Connect to Server testClientAfterDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClientAfterDisconnection.CreditGoal = 10; testClientAfterDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress); // Negotiate testClientAfterDisconnection.Negotiate( requestDialect, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilities, // If the reconnect use the same client guid, then keep client guid the same value, otherwise use a new client guid. clientGuid: (isSameClient ? clientGuid : Guid.NewGuid())); uint status = testClientAfterDisconnection.SessionSetup( testConfig.DefaultSecurityPackage, targetServer, testConfig.AccountCredential, testConfig.UseServerGssToken); Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Reconnect Session Setup should be successful, actual status is {0}", Smb2Status.GetStatusCode(status)); // TreeConnect testClientAfterDisconnection.TreeConnect(sharePath, out treeIdAfterDisconnection); #endregion #region Send Create request according to different context combination RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; switch (oplockLeaseType) { case OplockLeaseType.NoOplockOrLease: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; } break; case OplockLeaseType.BatchOplock: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; } break; case OplockLeaseType.LeaseV1: case OplockLeaseType.LeaseV2: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; } status = OpenCreate( testClientAfterDisconnection, treeIdAfterDisconnection, fileName, out fileIdAfterDisconnection, out serverCreateContexts, requestedOplockLevel, smb2CreateContextRequest); #endregion DurableHandleResponseContext durableHandleResponse; LeaseResponseContext leaseResponse; CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse); OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig); testClientAfterDisconnection.TreeDisconnect(treeIdAfterDisconnection); testClientAfterDisconnection.LogOff(); #endregion }
public void OpenRequest( ModelDialectRevision clientMaxDialect, PersistentBitType persistentBit, CAShareType connectToCAShare, OplockLeaseType oplockLeaseType, DurableV1RequestContext durableV1RequestContext, DurableV2RequestContext durableV2RequestContext, DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext) { requestDialect = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(clientMaxDialect)); clientCapabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL; if (persistentBit == PersistentBitType.PersistentBitSet) { clientCapabilities |= Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES; } clientGuid = Guid.NewGuid(); requestedContext = oplockLeaseType; isCAShare = (connectToCAShare == CAShareType.CAShare); IPAddress targetIPAddress; string targetServer; #region Connect to Common Share or CA Share if (!isCAShare) { sharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare); fileName = "PrepareHandle_ConnectTo_CommonShareFile_" + Guid.NewGuid() + ".txt"; targetIPAddress = testConfig.SutIPAddress; targetServer = testConfig.SutComputerName; } else { sharePath = Smb2Utility.GetUncPath(testConfig.CAShareServerName, testConfig.CAShareName); fileName = "PrepareHandle_ConnectTo_CAShareFile_" + Guid.NewGuid().ToString() + ".txt"; targetIPAddress = testConfig.CAShareServerIP; targetServer = testConfig.CAShareServerName; } testClientBeforeDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClientBeforeDisconnection.CreditGoal = 20; testClientBeforeDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress); testClientBeforeDisconnection.Negotiate( requestDialect, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilities, clientGuid: clientGuid, checker: (header, response) => { if (Smb2Utility.IsSmb3xFamily(response.DialectRevision) && handleConfig.IsPersistentHandleSupported && persistentBit == PersistentBitType.PersistentBitSet) { Site.Assert.IsTrue( response.Capabilities.HasFlag(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES), "The server MUST set SMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " + "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles. " + "Actual capabilities are {0}", response.Capabilities); } }); testClientBeforeDisconnection.SessionSetup( testConfig.DefaultSecurityPackage, targetServer, testConfig.AccountCredential, testConfig.UseServerGssToken); testClientBeforeDisconnection.TreeConnect(sharePath, out treeIdBeforeDisconnection); #endregion #region Construct Create Contexts Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext( durableV1RequestContext, durableV2RequestContext, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, false, false); #endregion #region Send Create request according to different context combination RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; switch (oplockLeaseType) { case OplockLeaseType.NoOplockOrLease: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; } break; case OplockLeaseType.BatchOplock: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; } break; case OplockLeaseType.LeaseV1: case OplockLeaseType.LeaseV2: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; } FILEID fileId; Smb2CreateContextResponse[] serverCreateContexts; uint status = OpenCreate( testClientBeforeDisconnection, treeIdBeforeDisconnection, fileName, out fileId, out serverCreateContexts, requestedOplockLevel, smb2CreateContextRequest); #endregion DurableHandleResponseContext durableHandleResponse; LeaseResponseContext leaseResponse; CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse); OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig); testClientBeforeDisconnection.TreeDisconnect(treeIdAfterDisconnection, (header, response) => { }); testClientBeforeDisconnection.LogOff(); }
/// <summary> /// 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; }
/// <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; }
public void ReconnectOpenRequest( DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext, OplockLeaseType oplockLeaseType, LeaseKeyDifferentialType leaseKeyDifferentialType, ClientIdType clientIdType, CreateGuidType createGuidType) { if ((oplockLeaseType == OplockLeaseType.LeaseV1 || oplockLeaseType == OplockLeaseType.LeaseV2) && !testConfig.IsLeasingSupported) Site.Assert.Inconclusive("Test case is applicable in servers that support leasing."); bool isSameLeaseKey = (leaseKeyDifferentialType == LeaseKeyDifferentialType.SameLeaseKey); bool isSameClient = (clientIdType == ClientIdType.SameClient); bool isSameCreateGuid = (createGuidType == CreateGuidType.SameCreateGuid); FILEID fileIdAfterDisconnection; Smb2CreateContextResponse[] serverCreateContexts; IPAddress targetIPAddress; string targetServer; string targetShare; #region Construct Create Contexts Smb2CreateContextRequest[] smb2CreateContextRequest = GetOpenFileCreateContext( DurableV1RequestContext.DurableV1RequestContextNotExist, DurableV2RequestContext.DurableV2RequestContextNotExist, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, isSameLeaseKey, isSameCreateGuid); #endregion #region Client reconnect to server Site.Log.Add(LogEntryKind.Debug, "Client reconnect to server"); #region Reconnect to Common Share or CA Share if (!isCAShare) { targetIPAddress = testConfig.SutIPAddress; targetServer = testConfig.SutComputerName; targetShare = testConfig.BasicFileShare; } else { targetIPAddress = testConfig.CAShareServerIP; targetServer = testConfig.CAShareServerName; targetShare = testConfig.CAShareName; } // Connect to Server testClientAfterDisconnection = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site); testClientAfterDisconnection.CreditGoal = 10; testClientAfterDisconnection.ConnectToServer(testConfig.UnderlyingTransport, targetServer, targetIPAddress); // Negotiate testClientAfterDisconnection.Negotiate( requestDialect, testConfig.IsSMB1NegotiateEnabled, capabilityValue: clientCapabilities, // If the reconnect use the same client guid, then keep client guid the same value, otherwise use a new client guid. clientGuid: (isSameClient ? clientGuid : Guid.NewGuid())); uint status = testClientAfterDisconnection.SessionSetup( testConfig.DefaultSecurityPackage, targetServer, testConfig.AccountCredential, testConfig.UseServerGssToken); Site.Assert.AreEqual(Smb2Status.STATUS_SUCCESS, status, "Reconnect Session Setup should be successful, actual status is {0}", Smb2Status.GetStatusCode(status)); // TreeConnect testClientAfterDisconnection.TreeConnect(sharePath, out treeIdAfterDisconnection); #endregion #region Send Create request according to different context combination RequestedOplockLevel_Values requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; switch (oplockLeaseType) { case OplockLeaseType.NoOplockOrLease: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE; } break; case OplockLeaseType.BatchOplock: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_BATCH; } break; case OplockLeaseType.LeaseV1: case OplockLeaseType.LeaseV2: { requestedOplockLevel = RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE; } break; } status = OpenCreate( testClientAfterDisconnection, treeIdAfterDisconnection, fileName, out fileIdAfterDisconnection, out serverCreateContexts, requestedOplockLevel, smb2CreateContextRequest); #endregion DurableHandleResponseContext durableHandleResponse; LeaseResponseContext leaseResponse; CheckResponseContexts(serverCreateContexts, out durableHandleResponse, out leaseResponse); OpenResponse((ModelSmb2Status)status, durableHandleResponse, leaseResponse, handleConfig); testClientAfterDisconnection.TreeDisconnect(treeIdAfterDisconnection); testClientAfterDisconnection.LogOff(); #endregion }
public static void ReconnectOpenRequest( DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext, OplockLeaseType oplockLeaseType, LeaseKeyDifferentialType leaseKeyDifferentialType, ClientIdType clientIdType, CreateGuidType createGuidType) { // If lease does not exist, LeaseKeyDifferentialType and LeaseStateDifferentialType take no effect. So just fix their values. Condition.IfThen(oplockLeaseType != OplockLeaseType.LeaseV1 && oplockLeaseType != OplockLeaseType.LeaseV2, leaseKeyDifferentialType == LeaseKeyDifferentialType.SameLeaseKey); // If there is no durablev2 reconnect context, fix the value of CreateGuid. Condition.IfThen(durableV2ReconnectContext == DurableV2ReconnectContext.DurableV2ReconnectContextNotExist, createGuidType == CreateGuidType.SameCreateGuid); // Do not need to test the situation of both V1 and V2 reconnect contexts not existed. Condition.IsFalse(durableV1ReconnectContext == DurableV1ReconnectContext.DurableV1ReconnectContextNotExist && durableV2ReconnectContext == DurableV2ReconnectContext.DurableV2ReconnectContextNotExist); // Only the server implements the SMB 2.1 or SMB 3.x dialect family supports leasing Condition.IfThen(NegotiateDialect == DialectRevision.Smb2002, oplockLeaseType != OplockLeaseType.LeaseV1 && oplockLeaseType != OplockLeaseType.LeaseV2); // Lease V2 is only vaild for SMB 3.x dialect family. Condition.IfThen(NegotiateDialect == DialectRevision.Smb21, oplockLeaseType != OplockLeaseType.LeaseV2); // If leasing is not supported, do not test LeaseV1 or LeaseV2. Condition.IfThen(!Config.IsLeasingSupported, oplockLeaseType != OplockLeaseType.LeaseV1 && oplockLeaseType != OplockLeaseType.LeaseV2); // 3.3.5.9.10, 3.3.5.9.12 This section applies only to servers that implement the SMB 3.x dialect family. Condition.IfThen(!ModelUtility.IsSmb3xFamily(Config.MaxSmbVersionSupported), durableV2ReconnectContext == DurableV2ReconnectContext.DurableV2ReconnectContextNotExist); // Add restriction to limit the generated cases of model. Combination.Pairwise(durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, leaseKeyDifferentialType, clientIdType, createGuidType); Condition.IsNull(Request); Request = new ModelOpenFileRequest( DurableV1RequestContext.DurableV1RequestContextNotExist, DurableV2RequestContext.DurableV2RequestContextNotExist, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, leaseKeyDifferentialType == LeaseKeyDifferentialType.SameLeaseKey, clientIdType == ClientIdType.SameClient, createGuidType == CreateGuidType.SameCreateGuid); }
public static void OpenRequest( ModelDialectRevision clientMaxDialect, PersistentBitType persistentBit, CAShareType connectToCAShare, OplockLeaseType oplockLeaseType, DurableV1RequestContext durableV1RequestContext, DurableV2RequestContext durableV2RequestContext, DurableV1ReconnectContext durableV1ReconnectContext, DurableV2ReconnectContext durableV2ReconnectContext) { Condition.IsNull(Request); Condition.IsNull(Open); // CAShare, Persistent Handle and Durable Handle V2 are only applied for SMB 3.x family. Condition.IfThen(!ModelUtility.IsSmb3xFamily(Config.MaxSmbVersionSupported), connectToCAShare == CAShareType.NonCAShare); Condition.IfThen(!ModelUtility.IsSmb3xFamily(Config.MaxSmbVersionSupported), persistentBit == PersistentBitType.PersistentBitNotSet); Condition.IfThen(!ModelUtility.IsSmb3xFamily(Config.MaxSmbVersionSupported), durableV2RequestContext == DurableV2RequestContext.DurableV2RequestContextNotExist); Condition.IfThen(!ModelUtility.IsSmb3xFamily(Config.MaxSmbVersionSupported), durableV2ReconnectContext == DurableV2ReconnectContext.DurableV2ReconnectContextNotExist); Condition.IfThen(!ModelUtility.IsSmb3xFamily(Config.MaxSmbVersionSupported), oplockLeaseType != OplockLeaseType.LeaseV2); // If leasing is not supported, do not test LeaseV1 or LeaseV2. Condition.IfThen(!Config.IsLeasingSupported, oplockLeaseType != OplockLeaseType.LeaseV1 && oplockLeaseType != OplockLeaseType.LeaseV2); Combination.Pairwise( clientMaxDialect, persistentBit, connectToCAShare, oplockLeaseType, durableV1RequestContext, durableV2RequestContext, durableV1ReconnectContext, durableV2ReconnectContext); NegotiateDialect = ModelHelper.DetermineNegotiateDialect(clientMaxDialect, Config.MaxSmbVersionSupported); Share_IsCA = (connectToCAShare == CAShareType.CAShare); if (ModelUtility.IsSmb3xFamily(NegotiateDialect) && persistentBit == PersistentBitType.PersistentBitSet && Config.IsPersistentHandleSupported) { ModelHelper.Log(LogType.Requirement, "3.3.5.4: The Capabilities field MUST be set to a combination of zero or more of the following bit values, as specified in section 2.2.4:"); ModelHelper.Log(LogType.Requirement, "\tSMB2_GLOBAL_CAP_PERSISTENT_HANDLES if Connection.Dialect belongs to the SMB 3.x dialect family, " + "SMB2_GLOBAL_CAP_PERSISTENT_HANDLES is set in the Capabilities field of the request, and the server supports persistent handles."); ModelHelper.Log(LogType.TestInfo, "All the above conditions are met. So SMB2_DHANDLE_FLAG_PERSISTENT bit is set in Connection.ServerCapabilities."); ServerCapabilities_PersistentBitSet = true; } Request = new ModelOpenFileRequest( durableV1RequestContext, durableV2RequestContext, durableV1ReconnectContext, durableV2ReconnectContext, oplockLeaseType, false, false, false); }