r863: Added test to ensure an open and locked file can be truncated by a second open.
authorJeremy Allison <jra@samba.org>
Mon, 24 May 2004 23:40:50 +0000 (23:40 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:56:13 +0000 (12:56 -0500)
This was something the Samba3 server previously got wrong.
Jeremy.
(This used to be commit 2cb4ed271b87a5c145a5f3f64c7f82c9e73753a1)

source4/torture/torture.c

index a3669129de81187bfe30df3dda718154e5c5304e..9ba90a103d3aa69f2e4007b4aac5c2ce75bc3988 100644 (file)
@@ -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)) {