]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: torture: Add torture_deltree() for setup and teardown.
authorJeremy Allison <jra@samba.org>
Thu, 2 Dec 2021 21:47:07 +0000 (13:47 -0800)
committerRalph Boehme <slow@samba.org>
Thu, 9 Dec 2021 18:06:35 +0000 (18:06 +0000)
Not yet used.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/torture/proto.h
source3/torture/torture.c

index 65fa17523d80219a3f832951edc02f5d3ba617da..d4db60f9dde3fadb8517e41b2dbf65095c3d5fd5 100644 (file)
@@ -74,6 +74,7 @@ bool torture_ioctl_test(int dummy);
 bool torture_chkpath_test(int dummy);
 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli);
 void torture_conn_set_sockopt(struct cli_state *cli);
+void torture_deltree(struct cli_state *cli, const char *dname);
 
 /* The following definitions come from torture/utable.c  */
 
index 8cfa05dd5c2c60822776bdb4cb31e9d13f2664d5..60c4df730c509a9b9011b559df96497189d78da8 100644 (file)
@@ -458,6 +458,133 @@ void torture_conn_set_sockopt(struct cli_state *cli)
        smbXcli_conn_set_sockopt(cli->conn, sockops);
 }
 
+static NTSTATUS torture_delete_fn(struct file_info *finfo,
+                                 const char *pattern,
+                                 void *state)
+{
+       NTSTATUS status;
+       char *filename = NULL;
+       char *dirname = NULL;
+       char *p = NULL;
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct cli_state *cli = (struct cli_state *)state;
+
+       if (ISDOT(finfo->name) || ISDOTDOT(finfo->name)) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_OK;
+       }
+
+       dirname = talloc_strdup(frame, pattern);
+       if (dirname == NULL) {
+               TALLOC_FREE(frame);
+                return NT_STATUS_NO_MEMORY;
+        }
+        p = strrchr_m(dirname, '\\');
+        if (p != NULL) {
+                /* Remove the terminating '\' */
+                *p = '\0';
+        }
+        if (dirname[0] != '\0') {
+                filename = talloc_asprintf(frame,
+                                           "%s\\%s",
+                                           dirname,
+                                           finfo->name);
+        } else {
+                filename = talloc_asprintf(frame,
+                                           "%s",
+                                           finfo->name);
+        }
+        if (filename == NULL) {
+                TALLOC_FREE(frame);
+                return NT_STATUS_NO_MEMORY;
+        }
+       if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
+               char *subdirname = talloc_asprintf(frame,
+                                                  "%s\\*",
+                                                  filename);
+               if (subdirname == NULL) {
+                       TALLOC_FREE(frame);
+                       return NT_STATUS_NO_MEMORY;
+               }
+               status = cli_list(cli,
+                                 subdirname,
+                                 FILE_ATTRIBUTE_DIRECTORY |
+                                         FILE_ATTRIBUTE_HIDDEN |
+                                         FILE_ATTRIBUTE_SYSTEM,
+                                 torture_delete_fn,
+                                 cli);
+               if (NT_STATUS_IS_OK(status)) {
+                       printf("torture_delete_fn: cli_list "
+                               "of %s failed (%s)\n",
+                               subdirname,
+                               nt_errstr(status));
+                       TALLOC_FREE(frame);
+                       return status;
+               }
+               status = cli_rmdir(cli, filename);
+       } else {
+               status = cli_unlink(cli,
+                                   filename,
+                                   FILE_ATTRIBUTE_SYSTEM |
+                                       FILE_ATTRIBUTE_HIDDEN);
+       }
+       if (!NT_STATUS_IS_OK(status)) {
+               if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
+                       printf("torture_delete_fn: cli_rmdir"
+                               " of %s failed (%s)\n",
+                               filename,
+                               nt_errstr(status));
+               } else {
+                       printf("torture_delete_fn: cli_unlink"
+                               " of %s failed (%s)\n",
+                               filename,
+                               nt_errstr(status));
+               }
+       }
+       TALLOC_FREE(frame);
+       return status;
+}
+
+void torture_deltree(struct cli_state *cli, const char *dname)
+{
+       char *mask = NULL;
+       NTSTATUS status;
+
+       /* It might be a file */
+       (void)cli_unlink(cli,
+                        dname,
+                        FILE_ATTRIBUTE_SYSTEM |
+                               FILE_ATTRIBUTE_HIDDEN);
+
+       mask = talloc_asprintf(cli,
+                              "%s\\*",
+                              dname);
+       if (mask == NULL) {
+               printf("torture_deltree: talloc_asprintf failed\n");
+               return;
+       }
+
+       status = cli_list(cli,
+                       mask,
+                       FILE_ATTRIBUTE_DIRECTORY |
+                               FILE_ATTRIBUTE_HIDDEN|
+                               FILE_ATTRIBUTE_SYSTEM,
+                       torture_delete_fn,
+                       cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("torture_deltree: cli_list of %s failed (%s)\n",
+                       mask,
+                       nt_errstr(status));
+       }
+       TALLOC_FREE(mask);
+       status = cli_rmdir(cli, dname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("torture_deltree: cli_rmdir of %s failed (%s)\n",
+                       dname,
+                       nt_errstr(status));
+       }
+}
+
 /* check if the server produced the expected dos or nt error code */
 static bool check_both_error(int line, NTSTATUS status,
                             uint8_t eclass, uint32_t ecode, NTSTATUS nterr)