public static void SetupConnection(ModelDialectRevision maxSmbVersionClientSupported, ClientSupportDirectoryLeasingType clientSupportDirectoryLeasingType) { Condition.IsTrue(state == ModelState.Initialized); // Current leasing only supports to test leasing on the file. So limit the exploration. Condition.IsTrue(clientSupportDirectoryLeasingType == ClientSupportDirectoryLeasingType.ClientNotSupportDirectoryLeasing); request = null; negotiateDialect = DialectRevision.Smb2Unknown; smb2Lease = null; negotiateDialect = ModelHelper.DetermineNegotiateDialect(maxSmbVersionClientSupported, config.MaxSmbVersionSupported); state = ModelState.Connected; }
public static void CreateResponse(ModelSmb2Status status, ReturnLeaseContextType returnLeaseContextType, uint leaseState, LeaseFlagsValues leaseFlags, LeasingConfig c) { Condition.IsTrue(state == ModelState.Connected); ModelCreateLeaseRequest createRequest = ModelHelper.RetrieveOutstandingRequest<ModelCreateLeaseRequest>(ref request); Condition.IsTrue(config.IsDirectoryLeasingSupported == c.IsDirectoryLeasingSupported); Condition.IsTrue(config.IsLeasingSupported == c.IsLeasingSupported); if (!c.IsLeasingSupported) { ModelHelper.Log( LogType.Requirement, "3.3.5.9: If the server does not support leasing and RequestedOplockLevel is set to SMB2_OPLOCK_LEVEL_LEASE, the server MUST ignore the \"RqLs\" create context."); ModelHelper.Log(LogType.TestInfo, "The above conditions are met."); ModelHelper.Log(LogType.TestTag, TestTag.Compatibility); Condition.IsTrue(returnLeaseContextType == ReturnLeaseContextType.ReturnLeaseContextNotIncluded); return; } if ((negotiateDialect == DialectRevision.Smb21 || Smb2Utility.IsSmb3xFamily(negotiateDialect)) && c.IsLeasingSupported && (createRequest.ContextType == LeaseContextType.LeaseV1)) // the DataLength field equals 0x20 { ModelHelper.Log( LogType.Requirement, "3.3.5.9: If the server supports leasing, the name of the create context is \"RqLs\" as defined in section 2.2.13.2, " + "and RequestedOplockLevel is set to SMB2_OPLOCK_LEVEL_LEASE, the server MUST do the following:"); ModelHelper.Log( LogType.Requirement, "\tIf Connection.Dialect is \"2.100\" or belongs to the \"3.x\" dialect family, and the DataLength field equals 0x20, " + "the server MUST attempt to acquire a lease on the open from the underlying object store as described in section 3.3.5.9.8."); ModelHelper.Log(LogType.TestInfo, "All the above conditions are met."); // 3.3.5.9.8 Handling the SMB2_CREATE_REQUEST_LEASE Create Context #region Handle SMB2_CREATE_REQUEST_LEASE Condition.IsTrue(returnLeaseContextType == ReturnLeaseContextType.ReturnLeaseContextIncluded); ModelCreateRequestLease requestLease = null; requestLease = createRequest.LeaseContext as ModelCreateRequestLease; smb2Lease = new Smb2Lease(); if (Smb2Utility.IsSmb3xFamily(negotiateDialect)) { ModelHelper.Log(LogType.Requirement, "3.3.5.9.8: If Connection.Dialect belongs to the SMB 3.x dialect family, Lease.Version is set to 1."); smb2Lease.Version = 1; } if (requestLease.LeaseState != smb2Lease.LeaseState && ((~requestLease.LeaseState) & smb2Lease.LeaseState) == 0 && !smb2Lease.Breaking) { ModelHelper.Log( LogType.Requirement, "3.3.5.9.8: If the lease state requested is a superset of Lease.LeaseState and Lease.Breaking is FALSE, " + "the server MUST request promotion of the lease state from the underlying object store to the new caching state."); ModelHelper.Log(LogType.TestInfo, "The above conditions are met."); //If the object store succeeds this request, Lease.LeaseState MUST be set to the new caching state. smb2Lease.LeaseState = requestLease.LeaseState; } // LeaseState MUST be set to Lease.LeaseState. Condition.IsTrue((uint)leaseState == smb2Lease.LeaseState); #endregion Condition.IsTrue(status == Smb2Status.STATUS_SUCCESS); return; } if (Smb2Utility.IsSmb3xFamily(negotiateDialect) && c.IsLeasingSupported && (createRequest.ContextType == LeaseContextType.LeaseV2)) // the DataLength field equals 0x34 { ModelHelper.Log( LogType.Requirement, "3.3.5.9: If the server supports leasing, the name of the create context is \"RqLs\" as defined in section 2.2.13.2, " + "and RequestedOplockLevel is set to SMB2_OPLOCK_LEVEL_LEASE, the server MUST do the following:"); ModelHelper.Log( LogType.Requirement, "\tIf Connection.Dialect belongs to the \"3.x\" dialect family, and the DataLength field equals 0x34, " + "the server MUST attempt to acquire a lease on the open from the underlying object store, as described in section 3.3.5.9.11."); ModelHelper.Log(LogType.TestInfo, "All the above conditions are met."); // 3.3.5.9.11 Handling the SMB2_CREATE_REQUEST_LEASE_V2 Create Context #region Handle SMB2_CREATE_REQUEST_LEASE_V2 Condition.IsTrue(returnLeaseContextType == ReturnLeaseContextType.ReturnLeaseContextIncluded); ModelCreateRequestLeaseV2 requestLease = null; requestLease = createRequest.LeaseContext as ModelCreateRequestLeaseV2; smb2Lease = new Smb2Lease(2); // To reduce parameters and states, use CreateOptions instead of FileAttributes here, as we assume settings in CreateOptions and FileAtributes are consistent. if (createRequest.CreateOptions.HasFlag(CreateOptions_Values.FILE_DIRECTORY_FILE) && (requestLease.LeaseState & (uint)LeaseStateValues.SMB2_LEASE_WRITE_CACHING) != 0) { ModelHelper.Log( LogType.Requirement, "3.3.5.9.11: If the FileAttributes field in the request indicates that this operation is on a directory and " + "LeaseState includes SMB2_LEASE_WRITE_CACHING, the server MUST clear the bit SMB2_LEASE_WRITE_CACHING in the LeaseState field."); ModelHelper.Log(LogType.TestInfo, "SMB2_LEASE_WRITE_CACHING is cleared."); requestLease.LeaseState &= ~(uint)LeaseStateValues.SMB2_LEASE_WRITE_CACHING; } if (requestLease.LeaseState != smb2Lease.LeaseState && ((~requestLease.LeaseState) & smb2Lease.LeaseState) == 0 && !smb2Lease.Breaking) { ModelHelper.Log( LogType.Requirement, "3.3.5.9.8: If the lease state requested is a superset of Lease.LeaseState and Lease.Breaking is FALSE, " + "the server MUST request promotion of the lease state from the underlying object store to the new caching state.<271> " + "If the object store succeeds this request, Lease.LeaseState MUST be set to the new caching state."); smb2Lease.LeaseState = requestLease.LeaseState; // The server MUST increment Lease.Epoch by 1. ModelHelper.Log(LogType.TestInfo, "Lease.Epoch is incremented by 1."); smb2Lease.Epoch++; } // LeaseState MUST be set to Lease.LeaseState. Condition.IsTrue((uint)leaseState == smb2Lease.LeaseState); if (requestLease.LeaseFlags.HasFlag(LeaseFlagsValues.SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET)) { ModelHelper.Log( LogType.Requirement, "3.3.5.9.11: If SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET bit is set in the Flags field of the request, " + "ParentLeaseKey MUST be set to the ParentLeaseKey in the request and SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET bit MUST be set in the Flags field of the response."); ModelHelper.Log(LogType.TestInfo, "SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET bit is set."); Condition.IsTrue(leaseFlags.HasFlag(LeaseFlagsValues.SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET)); } #endregion Condition.IsTrue(status == Smb2Status.STATUS_SUCCESS); return; } Condition.IsTrue(returnLeaseContextType == ReturnLeaseContextType.ReturnLeaseContextNotIncluded); Condition.IsTrue(leaseState == (uint)LeaseStateValues.SMB2_LEASE_NONE); Condition.IsTrue(leaseFlags == LeaseFlagsValues.NONE); Condition.IsTrue(status == Smb2Status.STATUS_SUCCESS); }