private void CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts) { // <9> Section 3.2.5.1: Windows Server 2012 R2 without [MSKB-3025091] doesn't return SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE. if (TestConfig.Platform == Platform.WindowsServer2012R2) { return; } foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContext") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; VerifyFieldInResponse("ServerVersion", TestConfig.ServerServiceVersion, openDeviceContext.Version); } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; VerifyFieldInResponse("ServerVersion", TestConfig.ServerServiceVersion, openDeviceContext.Version); VerifyFieldInResponse("SectorSize", TestConfig.PhysicalSectorSize, openDeviceContext.PhysicalSectorSize); VerifyFieldInResponse("VirtualSize", TestConfig.VirtualSize, openDeviceContext.VirtualSize); } } }
private bool CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts, RSVD_PROTOCOL_VERSION expectVersion) { if (servercreatecontexts == null) { return(false); } foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContext") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } } return(false); }
private bool CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts, RSVD_PROTOCOL_VERSION expectVersion) { if (servercreatecontexts == null) { if (expectVersion == RSVD_PROTOCOL_VERSION.RSVD_PROTOCOL_VERSION_1) { // <10> Section 3.2.5.1: Windows Server 2012 R2 without [MSKB-3025091] doesn't return SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE. // So if the open device context returns success, but without SVHDX_OPEN_DEVICE_CONTEXT_RESPONSE, the SUT may still support RSVD version 1. return(true); } else { return(false); } } try { foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponse") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; if ((openDeviceContext != null) && (openDeviceContext.Version == (uint)expectVersion)) { return(true); } } } } catch { return(false); } return(false); }
private void CheckOpenDeviceContext(Smb2CreateContextResponse[] servercreatecontexts) { foreach (var context in servercreatecontexts) { Type type = context.GetType(); if (type.Name == "Smb2CreateSvhdxOpenDeviceContext") { Smb2CreateSvhdxOpenDeviceContextResponse openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponse; VerifyFieldInResponse("ServerVersion", TestConfig.ServerServiceVersion, openDeviceContext.Version); } if (type.Name == "Smb2CreateSvhdxOpenDeviceContextResponseV2") { Smb2CreateSvhdxOpenDeviceContextResponseV2 openDeviceContext = context as Smb2CreateSvhdxOpenDeviceContextResponseV2; VerifyFieldInResponse("ServerVersion", TestConfig.ServerServiceVersion, openDeviceContext.Version); VerifyFieldInResponse("SectorSize", TestConfig.PhysicalSectorSize, openDeviceContext.PhysicalSectorSize); VerifyFieldInResponse("VirtualSize", TestConfig.VirtualSize, openDeviceContext.VirtualSize); } } }
/// <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); } }