r12154: Torture test for bug # 3303.
authorVolker Lendecke <vlendec@samba.org>
Fri, 9 Dec 2005 21:49:11 +0000 (21:49 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:47:15 +0000 (13:47 -0500)
Jeremy, to run this against Samba3 at all you need to insert a "goto line 957"
in line 548. Without this we fail some tests before # 16 and bail out.

While looking at it, you wanted to fix the directory-based ones a while
ago.... :-))

Volker

source/torture/basic/delete.c

index 60db6a78ed4b4c6397b9f1ff1295d5361dabe07b..d1ee98941c6199d2112cf7abd89ac1bf635dcb80 100644 (file)
@@ -148,6 +148,7 @@ BOOL torture_test_delete(void)
        struct smbcli_state *cli1;
        struct smbcli_state *cli2 = NULL;
        const char *fname = "\\delete.file";
+       const char *fname_new = "\\delete.new";
        const char *dirname = "\\delete.dir";
        int fnum1 = -1;
        int fnum2 = -1;
@@ -951,6 +952,130 @@ BOOL torture_test_delete(void)
 
        printf("fifteenth delete on close test succeeded.\n");
 
+       /* Test 16: delete on close under rename */
+
+       smbcli_setatr(cli1->tree, fname, 0, 0);
+       smbcli_unlink(cli1->tree, fname);
+       smbcli_unlink(cli1->tree, fname_new);
+       
+       fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
+                                     SEC_FILE_READ_DATA,
+                                     FILE_ATTRIBUTE_NORMAL, 
+                                     NTCREATEX_SHARE_ACCESS_READ|
+                                     NTCREATEX_SHARE_ACCESS_WRITE|
+                                     NTCREATEX_SHARE_ACCESS_DELETE,
+                                     NTCREATEX_DISP_OVERWRITE_IF,
+                                     0, 0);
+
+       if (fnum1 == -1) {
+               printf("(%s) open - 1 of %s failed (%s)\n", 
+                      __location__, fname, smbcli_errstr(cli1->tree));
+               correct = False;
+               goto fail;
+       }
+
+       status = smbcli_rename(cli2->tree, fname, fname_new);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(%s) renaming failed: %s !\n",
+                      __location__, nt_errstr(status));
+               correct = False;
+               goto fail;
+       }
+
+       fnum2 = smbcli_nt_create_full(cli2->tree, fname_new, 0, 
+                                     SEC_GENERIC_ALL,
+                                     FILE_ATTRIBUTE_NORMAL, 
+                                     NTCREATEX_SHARE_ACCESS_READ|
+                                     NTCREATEX_SHARE_ACCESS_WRITE|
+                                     NTCREATEX_SHARE_ACCESS_DELETE,
+                                     NTCREATEX_DISP_OVERWRITE_IF,
+                                     0, 0);
+
+       if (fnum2 == -1) {
+               printf("(%s) open - 1 of %s failed (%s)\n", 
+                      __location__, fname_new, smbcli_errstr(cli1->tree));
+               correct = False;
+               goto fail;
+       }
+
+       status = smbcli_nt_delete_on_close(cli2->tree, fnum2, True);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("(%s) setting delete_on_close on file failed !\n",
+                      __location__);
+               correct = False;
+               goto fail;
+       }
+
+       smbcli_close(cli2->tree, fnum2);
+
+       /* The file should be around under the new name, there's a second
+        * handle open */
+
+       if (!check_delete_on_close(cli1, fnum1, fname_new, True)) {
+               printf("(%s) checking delete on close on file %s failed!\n",
+                      __location__, fname_new);
+               correct = False;
+               goto fail;
+       }
+
+       fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, 
+                                     SEC_GENERIC_ALL,
+                                     FILE_ATTRIBUTE_NORMAL, 
+                                     NTCREATEX_SHARE_ACCESS_READ|
+                                     NTCREATEX_SHARE_ACCESS_WRITE|
+                                     NTCREATEX_SHARE_ACCESS_DELETE,
+                                     NTCREATEX_DISP_OVERWRITE_IF,
+                                     0, 0);
+
+       if (fnum2 == -1) {
+               printf("(%s) open - 1 of %s failed (%s)\n", 
+                      __location__, fname, smbcli_errstr(cli1->tree));
+               correct = False;
+               goto fail;
+       }
+
+       smbcli_close(cli2->tree, fnum2);
+       smbcli_close(cli1->tree, fnum1);
+
+       fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
+                                     SEC_FILE_READ_EA,
+                                     FILE_ATTRIBUTE_NORMAL, 
+                                     NTCREATEX_SHARE_ACCESS_READ|
+                                     NTCREATEX_SHARE_ACCESS_WRITE|
+                                     NTCREATEX_SHARE_ACCESS_DELETE,
+                                     NTCREATEX_DISP_OPEN,
+                                     0, 0);
+
+       if (fnum1 == -1) {
+               printf("(%s) open - 1 of %s failed (%s)\n", 
+                      __location__, fname, smbcli_errstr(cli1->tree));
+               correct = False;
+               goto fail;
+       }
+
+       smbcli_close(cli1->tree, fnum1);
+
+       fnum1 = smbcli_nt_create_full(cli1->tree, fname_new, 0, 
+                                     SEC_FILE_READ_EA,
+                                     FILE_ATTRIBUTE_NORMAL, 
+                                     NTCREATEX_SHARE_ACCESS_READ|
+                                     NTCREATEX_SHARE_ACCESS_WRITE|
+                                     NTCREATEX_SHARE_ACCESS_DELETE,
+                                     NTCREATEX_DISP_OPEN,
+                                     0, 0);
+
+       if (fnum1 != -1) {
+               printf("(%s) smbcli_open succeeded, should have "
+                      "failed\n", __location__);
+               smbcli_close(cli1->tree, fnum1);
+               correct = False;
+               goto fail;
+       }
+
+       printf("sixteenth delete on close test succeeded.\n");
+
        printf("finished delete test\n");
 
   fail: