public void TraditionalTestCase_IgnoreFields_SET_FILE_09_Case() { #region Connect to the specified server smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize); #endregion #region Send the Negotiate request // Create a SMB_COM_NEGOTIATE request. SmbNegotiateRequestPacket negotiateRequest = smbClientStack.CreateNegotiateRequest( StackSmb.SignState.NONE, new string[] { DialectNameString.PCNET1, DialectNameString.LANMAN10, DialectNameString.WFW10, DialectNameString.LANMAN12, DialectNameString.LANMAN21, DialectNameString.NTLANMAN }); // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds. smbClientStack.SendPacket(negotiateRequest); StackPacket response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_NEGOTIATE response should not be null."); // Check whether server returns a SMB_COM_NEGOTIATE response. Site.Assert.IsInstanceOfType( response, typeof(SmbNegotiateResponsePacket), "SMB_COM_NEGOTIATE response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, negotiateRequest.SmbHeader.Status, "SMB_COM_NEGOTIATE response status should be SUCCESS."); #endregion #region Send the first SMB_COM_SESSION_SETUP_ANDX Request SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse( typeof(SmbSecurityPackage), Site.Properties["SmbSecurityPackageType"] as string, true); // Create the first SMB_COM_SESSION_SETUP_ANDX request. SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest = smbClientStack.CreateFirstSessionSetupRequest( smbSecurityPackage, serverName, domainName, userName, password); // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(sessionSetupAndxRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server return a response. Site.Assert.IsNotNull( response, "SMB_COM_SESSION_SETUP_ANDX response should not be null."); // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbSessionSetupAndxResponsePacket), "SMB_COM_SESSION_SETUP_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED, // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS. SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response; Site.Assert.IsTrue( (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED || (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS, "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS."); #endregion #region Send the second SMB_COM_SESSION_SETUP_ANDX request // Create the second SMB_COM_SESSION_SETUP_ANDX request. ushort sessionUid = sessionSetupResponse.SmbHeader.Uid; if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED) { SmbSessionSetupAndxRequestPacket secondSessionSetupRequest = smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage); // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(secondSessionSetupRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_SESSION_SETUP_ANDX response should not be null."); // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbSessionSetupAndxResponsePacket), "SMB_COM_SESSION_SETUP_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, sessionSetupResponse.SmbHeader.Status, "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS."); } #endregion #region Send the SMB_COM_TREE_CONNECT_ANDX request // Create the SMB_COM_TREE_CONNECT_ANDX request. string path = Site.Properties["SutNtfsShare1FullName"]; SmbTreeConnectAndxRequestPacket treeconnectRequest = smbClientStack.CreateTreeConnectRequest(sessionUid, path); // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(treeconnectRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_TREE_CONNECT_ANDX response should not be null."); // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbTreeConnectAndxResponsePacket), "SMB_COM_TREE_CONNECT_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, treeConnectResponse.SmbHeader.Status, "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS."); #endregion #region Send the SMB_COM_NT_CREATE_ANDX request // Create the Create request. ushort treeId = treeConnectResponse.SmbHeader.Tid; string fileName = Site.Properties["SutShareTest2"]; SmbNtCreateAndxRequestPacket createRequest = smbClientStack.CreateCreateRequest( treeId, fileName, StackCifs.NtTransactDesiredAccess.GENERIC_ALL, StackCifs.SMB_EXT_FILE_ATTR.NONE, StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE | StackCifs.NtTransactShareAccess.FILE_SHARE_READ | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE, StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF, NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE, StackCifs.NtTransactImpersonationLevel.SEC_IDENTIFY, CreateFlags.NT_CREATE_REQUEST_OPLOCK); // Send the SMB_COM_NT_CREATE_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(createRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_NT_CREATE_ANDX response should not be null."); // Check if server returns a SMB_COM_NT_CREATE_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbNtCreateAndxResponsePacket), "SMB_COM_NT_CREATE_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, createResponse.SmbHeader.Status, "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS."); #endregion #region Send the TRANS2_SET_FILE_INFORMATION request // Create a TRANS2_SET_FILE_INFORMATION request. ushort fileId = createResponse.SmbParameters.FID; StackFscc.FileLinkInformation fileLinkInformation = new StackFscc.FileLinkInformation(); // 1 indicates that if the link already exists, it should be replaced with the new link. fileLinkInformation.ReplaceIfExists = 1; // The Reserved filed is a 7 bytes array fileLinkInformation.Reserved = new byte[7]; // The name of the newly created link. fileLinkInformation.FileName = Encoding.Unicode.GetBytes("wl.txt.lnk"); fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length; // 0 indicates a network operations. fileLinkInformation.RootDirectory = 0; StackFscc.FsccFileLinkInformationRequestPacket linkPacket = new StackFscc.FsccFileLinkInformationRequestPacket(); linkPacket.Payload = TypeMarshal.ToBytes<StackFscc.FileLinkInformation>(fileLinkInformation); byte[] data = linkPacket.ToBytes(); smbClientStack.Capability.IsUsePathThrough = false; // Create a TRANS2_SET_FILE_INFORMATION Request. SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest = smbClientStack.CreateTrans2SetFileInformationRequest( fileId, StackCifs.Trans2SmbParametersFlags.NONE, StackCifs.SetInformationLevel.SMB_INFO_STANDARD, data); // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds. smbClientStack.SendPacket(trans2SetFileInformationRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "TRANS2_SET_FILE_INFORMATION response should not be null."); // Check whether server returns a TRANS2_SET_FILE_INFORMATION response. Site.Assert.IsInstanceOfType( response, typeof(SmbTrans2SetFileInformationResponsePacket), "TRANS2_SET_FILE_INFORMATION response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse = (SmbTrans2SetFileInformationResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, trans2SetFileInformationResponse.SmbHeader.Status, "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS."); #endregion #region Send the TRANS2_SET_FILE_INFORMATION request StackFscc.FsccFileLinkInformationRequestPacket linkPacket2 = new StackFscc.FsccFileLinkInformationRequestPacket(); fileLinkInformation = new StackFscc.FileLinkInformation(); // 1 indicates that if the link already exists, it should be replaced with the new link. fileLinkInformation.ReplaceIfExists = 1; // The Reserved filed is a 7 bytes array fileLinkInformation.Reserved = new byte[7]; // The name of the newly created link. fileLinkInformation.FileName = Encoding.Unicode.GetBytes("wl.txt.lnk"); fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length; // 0 indicates a network operations. fileLinkInformation.RootDirectory = 0; linkPacket2.Payload = TypeMarshal.ToBytes<StackFscc.FileLinkInformation>(fileLinkInformation); smbClientStack.Capability.IsUsePathThrough = false; // Create a TRANS2_SET_FILE_INFORMATION request. SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest2 = smbClientStack.CreateTrans2SetFileInformationRequest( fileId, StackCifs.Trans2SmbParametersFlags.NONE, StackCifs.SetInformationLevel.SMB_INFO_STANDARD, linkPacket2.ToBytes()); // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds. smbClientStack.SendPacket(trans2SetFileInformationRequest2); StackPacket response2 = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response2, "TRANS2_SET_FILE_INFORMATION response should not be null."); // Check whether server returns a TRANS2_SET_FILE_INFORMATION response. Site.Assert.IsInstanceOfType( response, typeof(SmbTrans2SetFileInformationResponsePacket), "TRANS2_SET_FILE_INFORMATION response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse2 = (SmbTrans2SetFileInformationResponsePacket)response2; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, trans2SetFileInformationResponse.SmbHeader.Status, "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS."); #endregion #region Send the SMB_CLOSE request // Create the SMB_CLOSE request. SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId); // Send the Close request and expect the response in timeout milliseconds. smbClientStack.SendPacket(CloseRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_CLOSE response should not be null."); // Check whether server returns a SMB_CLOSE response. Site.Assert.IsInstanceOfType( response, typeof(SmbCloseResponsePacket), "SMB_CLOSE response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, closeResponse.SmbHeader.Status, "SMB_CLOSE response status should be SUCCESS."); #endregion #region Send the SMB_COM_TREE_DISCONNECT request // Create the SMB_COM_TREE_DISCONNECT request. SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId); // Send the TreeDisconnect request and expect the response in timeout milliseconds. smbClientStack.SendPacket(treeDisconnectRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_TREE_DISCONNECT response should not be null."); // Check whether server returns a SMB_COM_TREE_DISCONNECT response. Site.Assert.IsInstanceOfType( response, typeof(SmbTreeDisconnectResponsePacket), "SMB_COM_TREE_DISCONNECT response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, treeDisconnectResponse.SmbHeader.Status, "SMB_COM_TREE_DISCONNECT response status should be SUCCESS."); #endregion #region Send the SMB_COM_LOGOFF_ANDX request // Create the SMB_COM_LOGOFF_ANDX request. SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid); // Send the LogOff request and expect the response in timeout milliseconds. smbClientStack.SendPacket(logoffRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_LOGOFF_ANDX response should not be null."); // Check whether server returns a response. Site.Assert.IsInstanceOfType( response, typeof(SmbLogoffAndxResponsePacket), "SMB_COM_LOGOFF_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response; Site.Assert.AreEqual<uint>( (uint)SmbStatus.STATUS_SUCCESS, logoffResponse.SmbHeader.Status, "SMB_COM_LOGOFF_ANDX response status should be SUCCESS."); #endregion #region Disconnect // Disconnect smbClientStack.Disconnect(); Site.Assert.IsFalse( smbClientStack.IsDataAvailable, "SmbClient should not receive any packet after Disconnect method is called."); #endregion #region Capture requirement r109590 // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109590"); // // Verify MS-SMB requirement: MS-SMB_R109590 // bool isVerifyR109590 = VerifyisVerifyTrans2SetFileInformation( trans2SetFileInformationResponse, trans2SetFileInformationResponse2); Site.CaptureRequirementIfIsTrue( isVerifyR109590, 109590, @"<77> Section 2.2.8.4: Reserved (3 bytes): reply is the same whether zero or non-zero"); #endregion }
public void TraditionalTestCase_IgnoreFields_SET_FILE_09_Case() { #region Connect to the specified server smbClientStack.Connect(serverName, serverPort, ipVersion, bufferSize); #endregion #region Send the Negotiate request // Create a SMB_COM_NEGOTIATE request. SmbNegotiateRequestPacket negotiateRequest = smbClientStack.CreateNegotiateRequest( StackSmb.SignState.NONE, new string[] { DialectNameString.PCNET1, DialectNameString.LANMAN10, DialectNameString.WFW10, DialectNameString.LANMAN12, DialectNameString.LANMAN21, DialectNameString.NTLANMAN }); // Send the SMB_COM_NEGOTIATE request and expect the response in timeout milliseconds. smbClientStack.SendPacket(negotiateRequest); StackPacket response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_NEGOTIATE response should not be null."); // Check whether server returns a SMB_COM_NEGOTIATE response. Site.Assert.IsInstanceOfType( response, typeof(SmbNegotiateResponsePacket), "SMB_COM_NEGOTIATE response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbNegotiateResponsePacket negotiateResponse = (SmbNegotiateResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, negotiateRequest.SmbHeader.Status, "SMB_COM_NEGOTIATE response status should be SUCCESS."); #endregion #region Send the first SMB_COM_SESSION_SETUP_ANDX Request SmbSecurityPackage smbSecurityPackage = (SmbSecurityPackage)Enum.Parse( typeof(SmbSecurityPackage), Site.Properties["SmbSecurityPackageType"] as string, true); // Create the first SMB_COM_SESSION_SETUP_ANDX request. SmbSessionSetupAndxRequestPacket sessionSetupAndxRequest = smbClientStack.CreateFirstSessionSetupRequest( smbSecurityPackage, serverName, domainName, userName, password); // Send the first SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(sessionSetupAndxRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server return a response. Site.Assert.IsNotNull( response, "SMB_COM_SESSION_SETUP_ANDX response should not be null."); // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbSessionSetupAndxResponsePacket), "SMB_COM_SESSION_SETUP_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. // If SMB SecurityPackage type is NTLM, the expected SUCCESS response status is STATUS_MORE_PROCESSING_REQUIRED, // else if SMB SecurityPackage type is Kerberos, the expected SUCCESS response status is STATUS_SUCCESS. SmbSessionSetupAndxResponsePacket sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response; Site.Assert.IsTrue( (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED || (int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_SUCCESS, "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS."); #endregion #region Send the second SMB_COM_SESSION_SETUP_ANDX request // Create the second SMB_COM_SESSION_SETUP_ANDX request. ushort sessionUid = sessionSetupResponse.SmbHeader.Uid; if ((int)sessionSetupResponse.SmbHeader.Status == (int)SmbStatus.STATUS_MORE_PROCESSING_REQUIRED) { SmbSessionSetupAndxRequestPacket secondSessionSetupRequest = smbClientStack.CreateSecondSessionSetupRequest(sessionUid, smbSecurityPackage); // Send the second SMB_COM_SESSION_SETUP_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(secondSessionSetupRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_SESSION_SETUP_ANDX response should not be null."); // Check whether server returns a the SMB_COM_SESSION_SETUP_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbSessionSetupAndxResponsePacket), "SMB_COM_SESSION_SETUP_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. sessionSetupResponse = (SmbSessionSetupAndxResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, sessionSetupResponse.SmbHeader.Status, "SMB_COM_SESSION_SETUP_ANDX response status should be SUCCESS."); } #endregion #region Send the SMB_COM_TREE_CONNECT_ANDX request // Create the SMB_COM_TREE_CONNECT_ANDX request. string path = Site.Properties["SutNtfsShare1FullName"]; SmbTreeConnectAndxRequestPacket treeconnectRequest = smbClientStack.CreateTreeConnectRequest(sessionUid, path); // Send the SMB_COM_TREE_CONNECT_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(treeconnectRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_TREE_CONNECT_ANDX response should not be null."); // Check whether server returns a SMB_COM_TREE_CONNECT_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbTreeConnectAndxResponsePacket), "SMB_COM_TREE_CONNECT_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTreeConnectAndxResponsePacket treeConnectResponse = (SmbTreeConnectAndxResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, treeConnectResponse.SmbHeader.Status, "SMB_COM_TREE_CONNECT_ANDX response status should be SUCCESS."); #endregion #region Send the SMB_COM_NT_CREATE_ANDX request // Create the Create request. ushort treeId = treeConnectResponse.SmbHeader.Tid; string fileName = Site.Properties["SutShareTest2"]; SmbNtCreateAndxRequestPacket createRequest = smbClientStack.CreateCreateRequest( treeId, fileName, StackCifs.NtTransactDesiredAccess.GENERIC_ALL, StackCifs.SMB_EXT_FILE_ATTR.NONE, StackCifs.NtTransactShareAccess.FILE_SHARE_DELETE | StackCifs.NtTransactShareAccess.FILE_SHARE_READ | StackCifs.NtTransactShareAccess.FILE_SHARE_WRITE, StackCifs.NtTransactCreateDisposition.FILE_OPEN_IF, NtTransactCreateOptions.FILE_NON_DIRECTORY_FILE, StackCifs.NtTransactImpersonationLevel.SEC_IDENTIFY, CreateFlags.NT_CREATE_REQUEST_OPLOCK); // Send the SMB_COM_NT_CREATE_ANDX request and expect the response in timeout milliseconds. smbClientStack.SendPacket(createRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_NT_CREATE_ANDX response should not be null."); // Check if server returns a SMB_COM_NT_CREATE_ANDX response. Site.Assert.IsInstanceOfType( response, typeof(SmbNtCreateAndxResponsePacket), "SMB_COM_NT_CREATE_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbNtCreateAndxResponsePacket createResponse = (SmbNtCreateAndxResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, createResponse.SmbHeader.Status, "SMB_COM_NT_CREATE_ANDX response status should be SUCCESS."); #endregion #region Send the TRANS2_SET_FILE_INFORMATION request // Create a TRANS2_SET_FILE_INFORMATION request. ushort fileId = createResponse.SmbParameters.FID; StackFscc.FileLinkInformation fileLinkInformation = new StackFscc.FileLinkInformation(); // 1 indicates that if the link already exists, it should be replaced with the new link. fileLinkInformation.ReplaceIfExists = 1; // The Reserved filed is a 7 bytes array fileLinkInformation.Reserved = new byte[7]; // The name of the newly created link. fileLinkInformation.FileName = Encoding.Unicode.GetBytes("wl.txt.lnk"); fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length; // 0 indicates a network operations. fileLinkInformation.RootDirectory = 0; StackFscc.FsccFileLinkInformationRequestPacket linkPacket = new StackFscc.FsccFileLinkInformationRequestPacket(); linkPacket.Payload = TypeMarshal.ToBytes <StackFscc.FileLinkInformation>(fileLinkInformation); byte[] data = linkPacket.ToBytes(); smbClientStack.Capability.IsUsePassThrough = false; // Create a TRANS2_SET_FILE_INFORMATION Request. SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest = smbClientStack.CreateTrans2SetFileInformationRequest( fileId, StackCifs.Trans2SmbParametersFlags.NONE, StackCifs.SetInformationLevel.SMB_INFO_STANDARD, data); // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds. smbClientStack.SendPacket(trans2SetFileInformationRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "TRANS2_SET_FILE_INFORMATION response should not be null."); // Check whether server returns a TRANS2_SET_FILE_INFORMATION response. Site.Assert.IsInstanceOfType( response, typeof(SmbTrans2SetFileInformationResponsePacket), "TRANS2_SET_FILE_INFORMATION response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse = (SmbTrans2SetFileInformationResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, trans2SetFileInformationResponse.SmbHeader.Status, "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS."); #endregion #region Send the TRANS2_SET_FILE_INFORMATION request StackFscc.FsccFileLinkInformationRequestPacket linkPacket2 = new StackFscc.FsccFileLinkInformationRequestPacket(); fileLinkInformation = new StackFscc.FileLinkInformation(); // 1 indicates that if the link already exists, it should be replaced with the new link. fileLinkInformation.ReplaceIfExists = 1; // The Reserved filed is a 7 bytes array fileLinkInformation.Reserved = new byte[7]; // The name of the newly created link. fileLinkInformation.FileName = Encoding.Unicode.GetBytes("wl.txt.lnk"); fileLinkInformation.FileNameLength = (uint)fileLinkInformation.FileName.Length; // 0 indicates a network operations. fileLinkInformation.RootDirectory = 0; linkPacket2.Payload = TypeMarshal.ToBytes <StackFscc.FileLinkInformation>(fileLinkInformation); smbClientStack.Capability.IsUsePassThrough = false; // Create a TRANS2_SET_FILE_INFORMATION request. SmbTrans2SetFileInformationRequestPacket trans2SetFileInformationRequest2 = smbClientStack.CreateTrans2SetFileInformationRequest( fileId, StackCifs.Trans2SmbParametersFlags.NONE, StackCifs.SetInformationLevel.SMB_INFO_STANDARD, linkPacket2.ToBytes()); // Send the TRANS2_SET_FILE_INFORMATION request and expect the response in timeout milliseconds. smbClientStack.SendPacket(trans2SetFileInformationRequest2); StackPacket response2 = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response2, "TRANS2_SET_FILE_INFORMATION response should not be null."); // Check whether server returns a TRANS2_SET_FILE_INFORMATION response. Site.Assert.IsInstanceOfType( response, typeof(SmbTrans2SetFileInformationResponsePacket), "TRANS2_SET_FILE_INFORMATION response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTrans2SetFileInformationResponsePacket trans2SetFileInformationResponse2 = (SmbTrans2SetFileInformationResponsePacket)response2; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, trans2SetFileInformationResponse.SmbHeader.Status, "TRANS2_SET_FILE_INFORMATION response status should be SUCCESS."); #endregion #region Send the SMB_CLOSE request // Create the SMB_CLOSE request. SmbCloseRequestPacket CloseRequest = smbClientStack.CreateCloseRequest(fileId); // Send the Close request and expect the response in timeout milliseconds. smbClientStack.SendPacket(CloseRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_CLOSE response should not be null."); // Check whether server returns a SMB_CLOSE response. Site.Assert.IsInstanceOfType( response, typeof(SmbCloseResponsePacket), "SMB_CLOSE response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbCloseResponsePacket closeResponse = (SmbCloseResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, closeResponse.SmbHeader.Status, "SMB_CLOSE response status should be SUCCESS."); #endregion #region Send the SMB_COM_TREE_DISCONNECT request // Create the SMB_COM_TREE_DISCONNECT request. SmbTreeDisconnectRequestPacket treeDisconnectRequest = smbClientStack.CreateTreeDisconnectRequest(treeId); // Send the TreeDisconnect request and expect the response in timeout milliseconds. smbClientStack.SendPacket(treeDisconnectRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_TREE_DISCONNECT response should not be null."); // Check whether server returns a SMB_COM_TREE_DISCONNECT response. Site.Assert.IsInstanceOfType( response, typeof(SmbTreeDisconnectResponsePacket), "SMB_COM_TREE_DISCONNECT response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbTreeDisconnectResponsePacket treeDisconnectResponse = (SmbTreeDisconnectResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, treeDisconnectResponse.SmbHeader.Status, "SMB_COM_TREE_DISCONNECT response status should be SUCCESS."); #endregion #region Send the SMB_COM_LOGOFF_ANDX request // Create the SMB_COM_LOGOFF_ANDX request. SmbLogoffAndxRequestPacket logoffRequest = smbClientStack.CreateLogoffRequest(sessionUid); // Send the LogOff request and expect the response in timeout milliseconds. smbClientStack.SendPacket(logoffRequest); response = smbClientStack.ExpectPacket(timeout); // Check whether server returns a response. Site.Assert.IsNotNull( response, "SMB_COM_LOGOFF_ANDX response should not be null."); // Check whether server returns a response. Site.Assert.IsInstanceOfType( response, typeof(SmbLogoffAndxResponsePacket), "SMB_COM_LOGOFF_ANDX response should be received."); // Check the response validity by verifying the Status field in the SMB Header packet. SmbLogoffAndxResponsePacket logoffResponse = (SmbLogoffAndxResponsePacket)response; Site.Assert.AreEqual <uint>( (uint)SmbStatus.STATUS_SUCCESS, logoffResponse.SmbHeader.Status, "SMB_COM_LOGOFF_ANDX response status should be SUCCESS."); #endregion #region Disconnect // Disconnect smbClientStack.Disconnect(); Site.Assert.IsFalse( smbClientStack.IsDataAvailable, "SmbClient should not receive any packet after Disconnect method is called."); #endregion #region Capture requirement r109590 // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-SMB_R109590"); // // Verify MS-SMB requirement: MS-SMB_R109590 // bool isVerifyR109590 = VerifyisVerifyTrans2SetFileInformation( trans2SetFileInformationResponse, trans2SetFileInformationResponse2); Site.CaptureRequirementIfIsTrue( isVerifyR109590, 109590, @"<77> Section 2.2.8.4: Reserved (3 bytes): reply is the same whether zero or non-zero"); #endregion }
/// <summary> /// Verify the message syntax in FILE_LINK_INFORMATION /// </summary> /// <param name="fileLinkInformation">A FileLinkInformation type structure.</param> /// <param name="isLinkCreationOperationFail">A bool variable that means the link creation operation fail.</param> /// <param name="isLinkExists">A variable to indicate the link already exists.</param> /// <param name="isNetworkOperations">A variable to indicate that is a network operations</param> /// <param name="isLinkCreatedIndiffDirectory">A variable that means the link is to be created in a different /// directory from the file that is being linked to.</param> /// <param name="isSpecifyFullPathName">A bool variable that means this member(FileName) specifies the full /// path name for the link to be created.</param> /// <param name="isSpecifyOnlyFileName">A bool variable that means this member(FileName) specifies only the /// file name for the link to be created.</param> public void VerifyMessageSyntaxFileLinkInformation( FileLinkInformation fileLinkInformation, bool isLinkCreationOperationFail, bool isLinkExists, bool isNetworkOperations, bool isLinkCreatedIndiffDirectory, bool isSpecifyFullPathName, bool isSpecifyOnlyFileName) { Site.DefaultProtocolDocShortName = "MS-FSCC"; if (fileLinkInformation.RootDirectory.Equals(null) && isLinkCreatedIndiffDirectory) { // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1380,the value of FileName is {0}", fileLinkInformation.FileName); // // Verify MS-FSCC requirement: MS-FSCC_R1380 // Site.CaptureRequirementIfIsTrue( isSpecifyFullPathName, 1380, @"[In FILE_LINK_INFORMATION]FileName (variable): If the RootDirectory member is NULL, and the link is to be created in a different directory from the file that is being linked to, this member specifies the full path name for the link to be created."); } else { // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1381,the value of FileName is {0}", fileLinkInformation.FileName); // // Verify MS-FSCC requirement: MS-FSCC_R1381 // Site.CaptureRequirementIfIsTrue( isSpecifyOnlyFileName, 1381, @"[In FILE_LINK_INFORMATION]FileName (variable): Otherwise[If opposite to the condition: the RootDirectory member is NULL, and the link is to be created in a different directory from the file that is being linked to], it specifies only the file name."); } // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1377,the value of FileNameLength is {0}", fileLinkInformation.FileNameLength); // // Verify MS-FSCC requirement: MS-FSCC_R1377 // bool isVerifyR1377 = (Marshal.SizeOf(fileLinkInformation.FileNameLength) == 4) && (fileLinkInformation.FileNameLength == fileLinkInformation.FileName.Length); Site.CaptureRequirementIfIsTrue( isVerifyR1377, 1377, @"[In FILE_LINK_INFORMATION]FileNameLength (4 bytes): A 32-bit unsigned integer that contains the length, in bytes, of the FileName field."); // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1370,the value of ReplaceIfExists is {0}", fileLinkInformation.ReplaceIfExists); // // Verify MS-FSCC requirement: MS-FSCC_R1370 // // 8 bits equal 1 byte. bool isVerifyR1370 = (Marshal.SizeOf(fileLinkInformation.ReplaceIfExists) == 1) && (fileLinkInformation.ReplaceIfExists == 1); Site.CaptureRequirementIfIsTrue( isVerifyR1370, 1370, @"[In FILE_LINK_INFORMATION]ReplaceIfExists (1 byte): An 8-bit field that is set to 1 to indicate that if the link already exists, it should be replaced with the new link."); // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1375"); // // Verify MS-FSCC requirement: MS-FSCC_R1375 // // 64 bits equal 8 bytes. // "contains ..." is informative, not verify Site.CaptureRequirementIfAreEqual<int>( 8, Marshal.SizeOf((ulong)fileLinkInformation.RootDirectory), 1375, @"[In FILE_LINK_INFORMATION]RootDirectory (8 bytes): A 64-bit unsigned integer that contains the file handle for the directory where the link is to be created."); // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1378,the length of FileName is {0}", fileLinkInformation.FileName.Length); // // Verify MS-FSCC requirement: MS-FSCC_R1378 // // Every unicode character occupy two bit // So the length must be a even number. bool isVerifyR1378 = (fileLinkInformation.FileName.Length % 2 == 0); Site.CaptureRequirementIfIsTrue( isVerifyR1378, 1378, @"[In FILE_LINK_INFORMATION]FileName (variable): A sequence of Unicode characters containing the name to be assigned to the newly created link."); // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1415"); // // Verify MS-FSCC requirement: MS-FSCC_R1415 // Site.CaptureRequirementIfAreEqual<uint>( fileLinkInformation.FileNameLength, (uint)fileLinkInformation.FileName.Length, 1415, @"[In FILE_LINK_INFORMATION]FileName (variable): This field MUST be handled as a sequence of FileNameLength bytes."); // Check if the caller wants the link creation operation to fail // and if the link already exists. if (isLinkCreationOperationFail && isLinkExists) { // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1371"); // // Verify MS-FSCC requirement: MS-FSCC_R1371 // Site.CaptureRequirementIfAreEqual<Byte>( 0, fileLinkInformation.ReplaceIfExists, 1371, @"[In FILE_LINK_INFORMATION]ReplaceIfExists (1 byte): MUST be set to 0 if the caller wants the link creation operation to fail if the link already exists."); } // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1373"); // // Verify MS-FSCC requirement: MS-FSCC_R1373 // // When the field is not null then means it can contain any value, so can capture this requirement just by verifying this field is not null Site.CaptureRequirementIfIsNotNull( fileLinkInformation.Reserved, 1373, @"[In FILE_LINK_INFORMATION]Reserved (7 bytes): This field can contain any value."); // Check if is for network operations if (isNetworkOperations) { // // Add the debug information // Site.Log.Add(LogEntryKind.Debug, "Verify MS-FSCC_R1376"); // // Verify MS-FSCC requirement: MS-FSCC_R1376 // // From the definition of FileLinkInformation_RootDirectory_Values, // V1 equals 0. Site.CaptureRequirementIfAreEqual<FileLinkInformation_RootDirectory_Values>( FileLinkInformation_RootDirectory_Values.V1, fileLinkInformation.RootDirectory, 1376, @"[In FILE_LINK_INFORMATION]RootDirectory (8 bytes): For network operations, this value MUST be zero."); } Site.DefaultProtocolDocShortName = Site.Properties["ProtocolShortName"]; }