From a96ccb70224b20379c401052023d6e8eecd15357 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 24 May 2004 23:40:50 +0000 Subject: r863: Added test to ensure an open and locked file can be truncated by a second open. This was something the Samba3 server previously got wrong. Jeremy. (This used to be commit 2cb4ed271b87a5c145a5f3f64c7f82c9e73753a1) --- source4/torture/torture.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'source4/torture') diff --git a/source4/torture/torture.c b/source4/torture/torture.c index a3669129de..9ba90a103d 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -3257,6 +3257,78 @@ error_test60: error_test70: + printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n"); + + cli_unlink(cli1->tree, fname); + + fnum1 = cli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE); + if (fnum1 == -1) { + printf("(8) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1->tree)); + return False; + } + + /* write 20 bytes. */ + + memset(buf, '\0', 20); + + if (cli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) { + printf("(8) write failed (%s)\n", cli_errstr(cli1->tree)); + correct = False; + } + + /* Ensure size == 20. */ + if (NT_STATUS_IS_ERR(cli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) { + printf("(8) getatr (1) failed (%s)\n", cli_errstr(cli1->tree)); + CHECK_MAX_FAILURES(error_test80); + return False; + } + + if (fsize != 20) { + printf("(8) file size != 20\n"); + CHECK_MAX_FAILURES(error_test80); + return False; + } + + /* Get an exclusive lock on the open file. */ + if (NT_STATUS_IS_ERR(cli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) { + printf("(8) lock1 failed (%s)\n", cli_errstr(cli1->tree)); + CHECK_MAX_FAILURES(error_test80); + return False; + } + + fnum2 = cli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); + if (fnum1 == -1) { + printf("(8) open (2) of %s with truncate failed (%s)\n", fname, cli_errstr(cli1->tree)); + return False; + } + + /* Ensure size == 0. */ + if (NT_STATUS_IS_ERR(cli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) { + printf("(8) getatr (2) failed (%s)\n", cli_errstr(cli1->tree)); + CHECK_MAX_FAILURES(error_test80); + return False; + } + + if (fsize != 0) { + printf("(8) file size != 0\n"); + CHECK_MAX_FAILURES(error_test80); + return False; + } + + if (NT_STATUS_IS_ERR(cli_close(cli1->tree, fnum1))) { + printf("(8) close1 failed (%s)\n", cli_errstr(cli1->tree)); + return False; + } + + if (NT_STATUS_IS_ERR(cli_close(cli1->tree, fnum2))) { + printf("(8) close1 failed (%s)\n", cli_errstr(cli1->tree)); + return False; + } + +error_test80: + + printf("open test #8 passed.\n"); + cli_unlink(cli1->tree, fname); if (!torture_close_connection(cli1)) { -- cgit