From 4c29389c045ec6489b10cb64aab394d21fe884ed Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 19 Sep 2011 10:09:34 +0200 Subject: s3:torture: add a new test SMB2-TCON-DEPENDENCE Signed-off-by: Stefan Metzmacher --- source3/torture/test_smb2.c | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) (limited to 'source3/torture/test_smb2.c') diff --git a/source3/torture/test_smb2.c b/source3/torture/test_smb2.c index 04aa072adc4..4a3b42c8ea0 100644 --- a/source3/torture/test_smb2.c +++ b/source3/torture/test_smb2.c @@ -609,3 +609,107 @@ bool run_smb2_session_reconnect(int dummy) return true; } + +bool run_smb2_tcon_dependence(int dummy) +{ + struct cli_state *cli; + NTSTATUS status; + uint64_t fid_persistent, fid_volatile; + const char *hello = "Hello, world\n"; + uint8_t *result; + uint32_t nread; + + printf("Starting SMB2-TCON-DEPENDENCE\n"); + + if (!torture_init_connection(&cli)) { + return false; + } + cli->smb2.pid = 0xFEFF; + + status = smbXcli_negprot(cli->conn, cli->timeout, + PROTOCOL_SMB2_02, PROTOCOL_SMB2_22); + if (!NT_STATUS_IS_OK(status)) { + printf("smbXcli_negprot returned %s\n", nt_errstr(status)); + return false; + } + + status = cli_session_setup(cli, username, + password, strlen(password), + password, strlen(password), + workgroup); + if (!NT_STATUS_IS_OK(status)) { + printf("cli_session_setup returned %s\n", nt_errstr(status)); + return false; + } + + status = cli_tree_connect(cli, share, "?????", "", 0); + if (!NT_STATUS_IS_OK(status)) { + printf("cli_tree_connect returned %s\n", nt_errstr(status)); + return false; + } + + status = smb2cli_create(cli, "tcon_depedence.txt", + SMB2_OPLOCK_LEVEL_NONE, /* oplock_level, */ + SMB2_IMPERSONATION_IMPERSONATION, /* impersonation_level, */ + SEC_STD_ALL | SEC_FILE_ALL, /* desired_access, */ + FILE_ATTRIBUTE_NORMAL, /* file_attributes, */ + FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, /* share_access, */ + FILE_CREATE, /* create_disposition, */ + FILE_DELETE_ON_CLOSE, /* create_options, */ + NULL, /* smb2_create_blobs *blobs */ + &fid_persistent, + &fid_volatile); + if (!NT_STATUS_IS_OK(status)) { + printf("smb2cli_create on cli %s\n", nt_errstr(status)); + return false; + } + + status = smb2cli_write(cli, strlen(hello), 0, fid_persistent, + fid_volatile, 0, 0, (const uint8_t *)hello); + if (!NT_STATUS_IS_OK(status)) { + printf("smb2cli_write returned %s\n", nt_errstr(status)); + return false; + } + + status = smb2cli_flush(cli, fid_persistent, fid_volatile); + if (!NT_STATUS_IS_OK(status)) { + printf("smb2cli_flush returned %s\n", nt_errstr(status)); + return false; + } + + status = smb2cli_read(cli, 0x10000, 0, fid_persistent, + fid_volatile, 2, 0, + talloc_tos(), &result, &nread); + if (!NT_STATUS_IS_OK(status)) { + printf("smb2cli_read returned %s\n", nt_errstr(status)); + return false; + } + + if (nread != strlen(hello)) { + printf("smb2cli_read returned %d bytes, expected %d\n", + (int)nread, (int)strlen(hello)); + return false; + } + + if (memcmp(hello, result, nread) != 0) { + printf("smb2cli_read returned '%s', expected '%s'\n", + result, hello); + return false; + } + + /* check behaviour with wrong tid... */ + + cli->smb2.tid++; + + status = smb2cli_read(cli, 0x10000, 0, fid_persistent, + fid_volatile, 2, 0, + talloc_tos(), &result, &nread); + if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) { + printf("smb2cli_read returned %s\n", nt_errstr(status)); + return false; + } + + cli->smb2.tid--; + + return true; +} -- cgit