/// <summary> /// Construct a related Close Packet in the chain /// </summary> private Smb2CloseRequestPacket ConstructRelatedClosePacket() { var closePacket = new Smb2CloseRequestPacket(); closePacket.Header.Command = Smb2Command.CLOSE; closePacket.Header.Flags = Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS; closePacket.Header.SessionId = 0xFFFFFFFFFFFFFFFF; closePacket.Header.TreeId = 0xFFFFFFFF; closePacket.PayLoad.FileId = FILEID.Invalid; return(closePacket); }
private void Compound_RelatedRequests(string fileName, bool isEncrypted) { BaseTestSite.Log.Add(LogEntryKind.TestStep, "Initialize the test client."); Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite); uint treeId; BaseTestSite.Log.Add(LogEntryKind.TestStep, "Connect to the SMB2 basic share by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT."); ConnectToShare(client, out treeId); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Construct Create packet."); Smb2CreateRequestPacket createPacket = ConstructCreatePacket(client.SessionId, treeId, fileName); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Construct Write packet, flag FLAGS_RELATED_OPERATIONS is set."); Smb2WriteRequestPacket writePacket = ConstructRelatedWritePacket(); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Construct Close packet, flag FLAGS_RELATED_OPERATIONS is set."); Smb2CloseRequestPacket closePacket = ConstructRelatedClosePacket(); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Send {0}compounded Create, Write and Close requests to SUT.", isEncrypted ? "encrypted " : ""); List <Smb2SinglePacket> requestPackets = new List <Smb2SinglePacket>(); requestPackets.Add(createPacket); requestPackets.Add(writePacket); requestPackets.Add(closePacket); if (isEncrypted) { // Enable encryption client.EnableSessionSigningAndEncryption(enableSigning: testConfig.SendSignedRequest, enableEncryption: true); } List <Smb2SinglePacket> responsePackets = client.SendAndReceiveCompoundPacket(requestPackets); BaseTestSite.Log.Add(LogEntryKind.TestStep, "Verify responses to the compounded request."); foreach (var responsePacket in responsePackets) { if (TestConfig.Platform == Platform.WindowsServer2016 && responsePacket.Header.Status != Smb2Status.STATUS_SUCCESS) { } else { BaseTestSite.Assert.AreEqual( Smb2Status.STATUS_SUCCESS, responsePacket.Header.Status, "{0} should succeed, actual status is {1}", responsePacket.Header.Command, Smb2Status.GetStatusCode(responsePacket.Header.Status)); } } client.TreeDisconnect(treeId); client.LogOff(); client.Disconnect(); }
/// <summary> /// Construct a related Close Packet in the chain /// </summary> private Smb2CloseRequestPacket ConstructRelatedClosePacket(ulong sessionId, uint treeId) { var closePacket = new Smb2CloseRequestPacket(); closePacket.Header.Command = Smb2Command.CLOSE; // The client MUST construct the subsequent request as it would do normally. // For any subsequent requests the client MUST set SMB2_FLAGS_RELATED_OPERATIONS in the Flags field of the SMB2 header to indicate that it is using the SessionId, // TreeId, and FileId supplied in the previous request(or generated by the server in processing that request). // For an operation compounded with an SMB2 CREATE request, the FileId field SHOULD be set to { 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF }. closePacket.Header.Flags = Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS; closePacket.Header.SessionId = sessionId; closePacket.Header.TreeId = treeId; closePacket.PayLoad.FileId = FILEID.Invalid; return(closePacket); }
/// <summary> /// Construct a related Close Packet in the chain /// </summary> private Smb2CloseRequestPacket ConstructRelatedClosePacket() { var closePacket = new Smb2CloseRequestPacket(); closePacket.Header.Command = Smb2Command.CLOSE; closePacket.Header.Flags = Packet_Header_Flags_Values.FLAGS_RELATED_OPERATIONS; closePacket.Header.SessionId = 0xFFFFFFFFFFFFFFFF; closePacket.Header.TreeId = 0xFFFFFFFF; closePacket.PayLoad.FileId = FILEID.Invalid; return closePacket; }