libsmb: Move cli_raw_ioctl() to torture3
[samba.git] / source3 / torture / torture.c
index a46a252bc1963033f70367a88199fae3d564f350..bfce1c9dcd659df64c6d52b885678b7b082a8565 100644 (file)
@@ -51,6 +51,7 @@
 #include "lib/param/param.h"
 #include "auth/gensec/gensec.h"
 #include "lib/util/string_wrappers.h"
+#include "source3/lib/substitute.h"
 
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
@@ -457,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)
@@ -528,6 +656,54 @@ static bool check_error(int line, NTSTATUS status,
        return True;
 }
 
+NTSTATUS cli_qpathinfo1(struct cli_state *cli,
+                       const char *fname,
+                       time_t *change_time,
+                       time_t *access_time,
+                       time_t *write_time,
+                       off_t *size,
+                       uint32_t *pattr)
+{
+       int timezone = smb1cli_conn_server_time_zone(cli->conn);
+       time_t (*date_fn)(const void *buf, int serverzone) = NULL;
+       uint8_t *rdata = NULL;
+       uint32_t num_rdata;
+       NTSTATUS status;
+
+       status = cli_qpathinfo(talloc_tos(),
+                              cli,
+                              fname,
+                              SMB_INFO_STANDARD,
+                              22,
+                              CLI_BUFFER_SIZE,
+                              &rdata,
+                              &num_rdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       if (cli->win95) {
+               date_fn = make_unix_date;
+       } else {
+               date_fn = make_unix_date2;
+       }
+
+       if (change_time) {
+               *change_time = date_fn(rdata + 0, timezone);
+       }
+       if (access_time) {
+               *access_time = date_fn(rdata + 4, timezone);
+       }
+       if (write_time) {
+               *write_time = date_fn(rdata + 8, timezone);
+       }
+       if (size) {
+               *size = PULL_LE_U32(rdata, 12);
+       }
+       if (pattr) {
+               *pattr = PULL_LE_U16(rdata, l1_attrFile);
+       }
+       return NT_STATUS_OK;
+}
 
 static bool wait_lock(struct cli_state *c, int fnum, uint32_t offset, uint32_t len)
 {
@@ -1307,6 +1483,7 @@ static bool run_tcon_test(int dummy)
        uint16_t fnum1;
        uint32_t cnum1, cnum2, cnum3;
        struct smbXcli_tcon *orig_tcon = NULL;
+       char *orig_share = NULL;
        uint16_t vuid1, vuid2;
        char buf[4];
        bool ret = True;
@@ -1338,16 +1515,13 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
-       orig_tcon = cli_state_save_tcon(cli);
-       if (orig_tcon == NULL) {
-               return false;
-       }
+       cli_state_save_tcon_share(cli, &orig_tcon, &orig_share);
 
        status = cli_tree_connect_creds(cli, share, "?????", torture_creds);
        if (!NT_STATUS_IS_OK(status)) {
                printf("%s refused 2nd tree connect (%s)\n", host,
                       nt_errstr(status));
-               cli_state_restore_tcon(cli, orig_tcon);
+               cli_state_restore_tcon_share(cli, orig_tcon, orig_share);
                cli_shutdown(cli);
                return False;
        }
@@ -1400,7 +1574,7 @@ static bool run_tcon_test(int dummy)
        status = cli_close(cli, fnum1);
        if (!NT_STATUS_IS_OK(status)) {
                printf("close failed (%s)\n", nt_errstr(status));
-               cli_state_restore_tcon(cli, orig_tcon);
+               cli_state_restore_tcon_share(cli, orig_tcon, orig_share);
                cli_shutdown(cli);
                return False;
        }
@@ -1410,12 +1584,12 @@ static bool run_tcon_test(int dummy)
        status = cli_tdis(cli);
        if (!NT_STATUS_IS_OK(status)) {
                printf("secondary tdis failed (%s)\n", nt_errstr(status));
-               cli_state_restore_tcon(cli, orig_tcon);
+               cli_state_restore_tcon_share(cli, orig_tcon, orig_share);
                cli_shutdown(cli);
                return False;
        }
 
-       cli_state_restore_tcon(cli, orig_tcon);
+       cli_state_restore_tcon_share(cli, orig_tcon, orig_share);
 
        cli_state_set_tid(cli, cnum1);
 
@@ -3825,8 +3999,15 @@ static bool run_negprot_nowait(int dummy)
        for (i=0;i<50000;i++) {
                struct tevent_req *req;
 
-               req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout,
-                                          PROTOCOL_CORE, PROTOCOL_NT1, 0);
+               req = smbXcli_negprot_send(
+                       ev,
+                       ev,
+                       cli->conn,
+                       cli->timeout,
+                       PROTOCOL_CORE,
+                       PROTOCOL_NT1,
+                       0,
+                       NULL);
                if (req == NULL) {
                        TALLOC_FREE(ev);
                        return false;
@@ -4205,6 +4386,50 @@ static bool run_attrtest(int dummy)
        return correct;
 }
 
+static NTSTATUS cli_qfilename(
+       struct cli_state *cli,
+       uint16_t fnum,
+       TALLOC_CTX *mem_ctx,
+       char **_name)
+{
+       uint16_t recv_flags2;
+       uint8_t *rdata;
+       uint32_t num_rdata;
+       NTSTATUS status;
+       char *name = NULL;
+       uint32_t namelen;
+
+       status = cli_qfileinfo(talloc_tos(), cli, fnum,
+                              SMB_QUERY_FILE_NAME_INFO,
+                              4, CLI_BUFFER_SIZE, &recv_flags2,
+                              &rdata, &num_rdata);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       namelen = IVAL(rdata, 0);
+       if (namelen > (num_rdata - 4)) {
+               TALLOC_FREE(rdata);
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+
+       pull_string_talloc(mem_ctx,
+                          (const char *)rdata,
+                          recv_flags2,
+                          &name,
+                          rdata + 4,
+                          namelen,
+                          STR_UNICODE);
+       if (name == NULL) {
+               status = map_nt_error_from_unix(errno);
+               TALLOC_FREE(rdata);
+               return status;
+       }
+
+       *_name = name;
+       TALLOC_FREE(rdata);
+       return NT_STATUS_OK;
+}
 
 /*
   This checks a couple of trans2 calls
@@ -4219,7 +4444,7 @@ static bool run_trans2test(int dummy)
        const char *fname = "\\trans2.tst";
        const char *dname = "\\trans2";
        const char *fname2 = "\\trans2\\trans2.tst";
-       char *pname;
+       char *pname = NULL;
        bool correct = True;
        NTSTATUS status;
        uint32_t fs_attr;
@@ -5669,7 +5894,7 @@ static bool run_deletetest(int dummy)
 
   fail:
        /* FIXME: This will crash if we aborted before cli2 got
-        * intialized, because these functions don't handle
+        * initialized, because these functions don't handle
         * uninitialized connections. */
 
        if (fnum1 != (uint16_t)-1) cli_close(cli1, fnum1);
@@ -5993,71 +6218,6 @@ static bool run_delete_print_test(int dummy)
        return correct;
 }
 
-/*
-  Test wildcard delete.
- */
-static bool run_wild_deletetest(int dummy)
-{
-       struct cli_state *cli = NULL;
-       const char *dname = "\\WTEST";
-       const char *fname = "\\WTEST\\A";
-       const char *wunlink_name = "\\WTEST\\*";
-       uint16_t fnum1 = (uint16_t)-1;
-       bool correct = false;
-       NTSTATUS status;
-
-       printf("starting wildcard delete test\n");
-
-       if (!torture_open_connection(&cli, 0)) {
-               return false;
-       }
-
-       smbXcli_conn_set_sockopt(cli->conn, sockops);
-
-       cli_unlink(cli, fname, 0);
-       cli_rmdir(cli, dname);
-       status = cli_mkdir(cli, dname);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("mkdir of %s failed %s!\n", dname, nt_errstr(status));
-               goto fail;
-       }
-       status = cli_openx(cli, fname, O_CREAT|O_RDONLY, DENY_NONE, &fnum1);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("open of %s failed %s!\n", fname, nt_errstr(status));
-               goto fail;
-       }
-       status = cli_close(cli, fnum1);
-       fnum1 = -1;
-
-       /*
-        * Note the unlink attribute-type of zero. This should
-        * map into FILE_ATTRIBUTE_NORMAL at the server even
-        * on a wildcard delete.
-        */
-
-       status = cli_unlink(cli, wunlink_name, 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("unlink of %s failed %s!\n",
-                       wunlink_name, nt_errstr(status));
-               goto fail;
-       }
-
-       printf("finished wildcard delete test\n");
-
-       correct = true;
-
-  fail:
-
-       if (fnum1 != (uint16_t)-1) cli_close(cli, fnum1);
-       cli_unlink(cli, fname, 0);
-       cli_rmdir(cli, dname);
-
-       if (cli && !torture_close_connection(cli)) {
-               correct = false;
-       }
-       return correct;
-}
-
 static bool run_deletetest_ln(int dummy)
 {
        struct cli_state *cli;
@@ -7651,6 +7811,7 @@ static bool run_simple_posix_open_test(int dummy)
        size_t nread;
        const char *fname_windows = "windows_file";
        uint16_t fnum2 = (uint16_t)-1;
+       bool ok;
 
        printf("Starting simple POSIX open test\n");
 
@@ -7919,18 +8080,19 @@ static bool run_simple_posix_open_test(int dummy)
        if (NT_STATUS_IS_OK(status)) {
                printf("POSIX open of %s succeeded (should have failed)\n", sname);
                goto out;
-       } else {
-               if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath,
-                               NT_STATUS_OBJECT_PATH_NOT_FOUND)) {
-                       printf("POSIX open of %s should have failed "
-                               "with NT_STATUS_OBJECT_PATH_NOT_FOUND, "
-                               "failed with %s instead.\n",
-                               sname, nt_errstr(status));
-                       goto out;
-               }
+       }
+       ok = check_both_error(
+               __LINE__, status, ERRDOS, ERRbadpath,
+               NT_STATUS_OBJECT_NAME_NOT_FOUND);
+       if (!ok) {
+               printf("POSIX open of %s should have failed "
+                      "with NT_STATUS_OBJECT_NAME_NOT_FOUND, "
+                      "failed with %s instead.\n",
+                      sname, nt_errstr(status));
+               goto out;
        }
 
-       status = cli_posix_readlink(cli1, sname, talloc_tos(), &target);
+       status = cli_readlink(cli1, sname, talloc_tos(), &target, NULL, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status));
                goto out;
@@ -8866,6 +9028,11 @@ static bool run_posix_blocking_lock(int dummy)
                return false;
        }
 
+       status = torture_setup_unix_extensions(cli2);
+       if (!NT_STATUS_IS_OK(status)) {
+               return false;
+       }
+
        cli_setatr(cli1, fname, 0, 0);
        cli_posix_unlink(cli1, fname);
 
@@ -9733,6 +9900,42 @@ static NTSTATUS del_fn(struct file_info *finfo, const char *mask,
 }
 
 
+/*
+   send a raw ioctl - used by the torture code
+*/
+static NTSTATUS cli_raw_ioctl(struct cli_state *cli,
+                             uint16_t fnum,
+                             uint32_t code,
+                             DATA_BLOB *blob)
+{
+       uint16_t vwv[3];
+       NTSTATUS status;
+
+       PUSH_LE_U16(vwv + 0, 0, fnum);
+       PUSH_LE_U16(vwv + 1, 0, code >> 16);
+       PUSH_LE_U16(vwv + 2, 0, (code & 0xFFFF));
+
+       status = cli_smb(talloc_tos(),
+                        cli,
+                        SMBioctl,
+                        0,
+                        3,
+                        vwv,
+                        0,
+                        NULL,
+                        NULL,
+                        0,
+                        NULL,
+                        NULL,
+                        NULL,
+                        NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       *blob = data_blob_null;
+       return NT_STATUS_OK;
+}
+
 /*
   sees what IOCTLs are supported
  */
@@ -9789,7 +9992,7 @@ bool torture_ioctl_test(int dummy)
 
 
 /*
-  tries varients of chkpath
+  tries variants of chkpath
  */
 bool torture_chkpath_test(int dummy)
 {
@@ -9805,9 +10008,7 @@ bool torture_chkpath_test(int dummy)
        printf("starting chkpath test\n");
 
        /* cleanup from an old run */
-       cli_rmdir(cli, "\\chkpath.dir\\dir2");
-       cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-       cli_rmdir(cli, "\\chkpath.dir");
+       torture_deltree(cli, "\\chkpath.dir");
 
        status = cli_mkdir(cli, "\\chkpath.dir");
        if (!NT_STATUS_IS_OK(status)) {
@@ -9868,9 +10069,7 @@ bool torture_chkpath_test(int dummy)
                ret = False;
        }
 
-       cli_rmdir(cli, "\\chkpath.dir\\dir2");
-       cli_unlink(cli, "\\chkpath.dir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-       cli_rmdir(cli, "\\chkpath.dir");
+       torture_deltree(cli, "\\chkpath.dir");
 
        if (!torture_close_connection(cli)) {
                return False;
@@ -9885,8 +10084,7 @@ static bool run_eatest(int dummy)
        const char *fname = "\\eatest.txt";
        bool correct = True;
        uint16_t fnum;
-       int i;
-       size_t num_eas;
+       size_t i, num_eas;
        struct ea_struct *ea_list = NULL;
        TALLOC_CTX *mem_ctx = talloc_init("eatest");
        NTSTATUS status;
@@ -9913,7 +10111,7 @@ static bool run_eatest(int dummy)
        for (i = 0; i < 10; i++) {
                fstring ea_name, ea_val;
 
-               slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
+               slprintf(ea_name, sizeof(ea_name), "EA_%zu", i);
                memset(ea_val, (char)i+1, i+1);
                status = cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1);
                if (!NT_STATUS_IS_OK(status)) {
@@ -9928,7 +10126,7 @@ static bool run_eatest(int dummy)
        for (i = 0; i < 10; i++) {
                fstring ea_name, ea_val;
 
-               slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
+               slprintf(ea_name, sizeof(ea_name), "EA_%zu", i+10);
                memset(ea_val, (char)i+1, i+1);
                status = cli_set_ea_path(cli, fname, ea_name, ea_val, i+1);
                if (!NT_STATUS_IS_OK(status)) {
@@ -9953,13 +10151,13 @@ static bool run_eatest(int dummy)
        }
 
        for (i = 0; i < num_eas; i++) {
-               printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
+               printf("%zu: ea_name = %s. Val = ", i, ea_list[i].name);
                dump_data(0, ea_list[i].value.data,
                          ea_list[i].value.length);
        }
 
        /* Setting EA's to zero length deletes them. Test this */
-       printf("Now deleting all EA's - case indepenent....\n");
+       printf("Now deleting all EA's - case independent....\n");
 
 #if 1
        cli_set_ea_path(cli, fname, "", "", 0);
@@ -9985,7 +10183,7 @@ static bool run_eatest(int dummy)
 
        printf("num_eas = %d\n", (int)num_eas);
        for (i = 0; i < num_eas; i++) {
-               printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
+               printf("%zu: ea_name = %s. Val = ", i, ea_list[i].name);
                dump_data(0, ea_list[i].value.data,
                          ea_list[i].value.length);
        }
@@ -10062,7 +10260,7 @@ static bool run_dirtest1(int dummy)
                correct = False;
 
        /* Ensure if we have the "must have" bits we only see the
-        * relevent entries.
+        * relevant entries.
         */
        num_seen = 0;
        cli_list_old(cli, "\\LISTDIR\\*", (FILE_ATTRIBUTE_DIRECTORY<<8)|FILE_ATTRIBUTE_DIRECTORY, list_fn, &num_seen);
@@ -10586,10 +10784,9 @@ static void torture_createdels_done(struct tevent_req *subreq)
                subreq, struct tevent_req);
        struct torture_createdels_state *state = tevent_req_data(
                req, struct torture_createdels_state);
-       size_t num_parallel = talloc_array_length(state->reqs);
+       size_t i, num_parallel = talloc_array_length(state->reqs);
        NTSTATUS status;
        char *name;
-       int i;
 
        status = torture_createdel_recv(subreq);
        if (!NT_STATUS_IS_OK(status)){
@@ -10842,9 +11039,6 @@ static bool run_mangle1(int dummy)
        uint16_t fnum;
        fstring alt_name;
        NTSTATUS status;
-       time_t change_time, access_time, write_time;
-       off_t size;
-       uint32_t attr;
 
        printf("starting mangle1 test\n");
        if (!torture_open_connection(&cli, 0)) {
@@ -10878,8 +11072,7 @@ static bool run_mangle1(int dummy)
        }
        cli_close(cli, fnum);
 
-       status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
-                               &write_time, &size, &attr);
+       status = cli_qpathinfo1(cli, alt_name, NULL, NULL, NULL, NULL, NULL);
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("cli_qpathinfo1(%s) failed: %s\n", alt_name,
                         nt_errstr(status));
@@ -11741,7 +11934,7 @@ static bool run_uid_regression_test(int dummy)
         * second tdis call with invalid vuid.
         *
         * This is a test-only hack. Real client code
-        * uses cli_state_save_tcon()/cli_state_restore_tcon().
+        * uses cli_state_save_tcon_share()/cli_state_restore_tcon_share().
         */
        tcon_copy = smbXcli_tcon_copy(cli, cli->smb1.tcon);
        if (tcon_copy == NULL) {
@@ -12340,8 +12533,7 @@ static bool run_streamerror(int dummy)
                return false;
        }
 
-       cli_unlink(cli, "\\testdir_streamerror\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-       cli_rmdir(cli, dname);
+       torture_deltree(cli, dname);
 
        status = cli_mkdir(cli, dname);
        if (!NT_STATUS_IS_OK(status)) {
@@ -12686,10 +12878,7 @@ static bool run_smb1_wild_mangle_unlink_test(int dummy)
        }
 
        /* Start fresh. */
-       cli_unlink(cli,
-               star_name,
-               FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-       cli_rmdir(cli, dname);
+       torture_deltree(cli, dname);
 
        /*
         * Create two files - 'a' and '*'.
@@ -12799,10 +12988,7 @@ static bool run_smb1_wild_mangle_unlink_test(int dummy)
        TALLOC_FREE(mangled_name);
 
        if (cli != NULL) {
-               cli_unlink(cli,
-                       star_name,
-                       FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-               cli_rmdir(cli, dname);
+               torture_deltree(cli, dname);
                torture_close_connection(cli);
        }
 
@@ -12824,7 +13010,7 @@ static bool run_smb1_wild_mangle_rename_test(int dummy)
        const char *foostar_name = "smb1_wild_mangle_rename/fo*";
        const char *wild_name = "smb1_wild_mangle_rename/*";
        char *windows_rename_src = NULL;
-       const char *windows_rename_dst = "smb1_wild_mangle_rename\\ba*";
+       const char *windows_rename_dst = "smb1_wild_mangle_rename\\bar";
        char *mangled_name = NULL;
        NTSTATUS status;
 
@@ -12850,10 +13036,7 @@ static bool run_smb1_wild_mangle_rename_test(int dummy)
        smbXcli_conn_set_sockopt(cli->conn, sockops);
 
        /* Ensure we start from fresh. */
-       cli_unlink(cli,
-               wild_name,
-               FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
-       cli_posix_rmdir(cli_posix, dname);
+       torture_deltree(cli, dname);
 
        /*
         * Create two files - 'foo' and 'fo*'.
@@ -12972,13 +13155,10 @@ static bool run_smb1_wild_mangle_rename_test(int dummy)
        TALLOC_FREE(windows_rename_src);
 
        if (cli != NULL) {
-               cli_unlink(cli,
-                       wild_name,
-                       FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               torture_deltree(cli, dname);
                torture_close_connection(cli);
        }
 
-       cli_posix_rmdir(cli_posix, dname);
        torture_close_connection(cli_posix);
 
        return correct;
@@ -14292,7 +14472,7 @@ static bool run_local_hex_encode_buf(int dummy)
 {
        char buf[17];
        uint8_t src[8];
-       int i;
+       size_t i;
 
        for (i=0; i<sizeof(src); i++) {
                src[i] = i;
@@ -14545,6 +14725,395 @@ static bool run_local_canonicalize_path(int dummy)
        }
        return true;
 }
+struct session_setup_nt1_truncated_state {
+       uint16_t vwv[13];
+       uint8_t bytes[20];
+};
+
+static void smb1_session_setup_nt1_truncated_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb1_session_setup_nt1_truncated_send(
+               TALLOC_CTX *mem_ctx,
+               struct tevent_context *ev,
+               struct smbXcli_conn *conn)
+{
+       uint16_t *vwv = NULL;
+       uint8_t *bytes = NULL;
+       const char *pass = "12345678";
+       const char *uname = "z";
+       struct session_setup_nt1_truncated_state *state = NULL;
+       struct tevent_req *req = NULL;
+       struct tevent_req *subreq = NULL;
+
+       req = tevent_req_create(mem_ctx,
+                               &state,
+                               struct session_setup_nt1_truncated_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       vwv = &state->vwv[0];
+       bytes = &state->bytes[0];
+
+       SCVAL(vwv+0,  0, 0xff);
+       SCVAL(vwv+0,  1, 0);
+       SSVAL(vwv+1,  0, 0);
+       SSVAL(vwv+2,  0, 8192);
+       SSVAL(vwv+3,  0, 2);
+       SSVAL(vwv+4,  0, 1);
+       SIVAL(vwv+5,  0, 0);
+       SSVAL(vwv+7,  0, strlen(pass)); /* OEMPasswordLen */
+       SSVAL(vwv+8,  0, 0); /* UnicodePasswordLen */
+       SSVAL(vwv+9,  0, 0); /* reserved */
+       SSVAL(vwv+10, 0, 0); /* reserved */
+       SIVAL(vwv+11, 0, CAP_STATUS32);
+
+       memcpy(bytes, pass, strlen(pass));
+       bytes += strlen(pass);
+       memcpy(bytes, uname, strlen(uname)+1);
+
+       subreq = smb1cli_req_send(state, ev, conn,
+                                 SMBsesssetupX,
+                                 0, /*  additional_flags */
+                                 0, /*  clear_flags */
+                                 0, /*  additional_flags2 */
+                                 0, /*  clear_flags2 */
+                                 10000, /* timeout_msec */
+                                 getpid(),
+                                 NULL, /* tcon */
+                                 NULL, /* session */
+                                 13, /* wct */
+                                 state->vwv,
+                                 strlen(pass), /* Truncate length at password. */
+                                 state->bytes);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq,
+                               smb1_session_setup_nt1_truncated_done,
+                               req);
+       return req;
+}
+
+static void smb1_session_setup_nt1_truncated_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req =
+               tevent_req_callback_data(subreq,
+               struct tevent_req);
+       struct session_setup_nt1_truncated_state *state =
+               tevent_req_data(req,
+               struct session_setup_nt1_truncated_state);
+       NTSTATUS status;
+       struct smb1cli_req_expected_response expected[] = {
+       {
+               .status = NT_STATUS_OK,
+               .wct    = 3,
+       },
+       };
+
+       status = smb1cli_req_recv(subreq, state,
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 NULL, /* pvwv_offset */
+                                 NULL,
+                                 NULL,
+                                 NULL, /* pbytes_offset */
+                                 NULL,
+                                 expected, ARRAY_SIZE(expected));
+       TALLOC_FREE(subreq);
+       if (tevent_req_nterror(req, status)) {
+               return;
+       }
+       tevent_req_done(req);
+}
+
+static NTSTATUS smb1_session_setup_nt1_truncated_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+static bool run_smb1_truncated_sesssetup(int dummy)
+{
+       struct tevent_context *ev;
+       struct tevent_req *req;
+       struct smbXcli_conn *conn;
+       struct sockaddr_storage ss;
+       NTSTATUS status;
+       int fd;
+       bool ok;
+
+       printf("Starting send truncated SMB1 sesssetup.\n");
+
+       ok = resolve_name(host, &ss, 0x20, true);
+       if (!ok) {
+               d_fprintf(stderr, "Could not resolve name %s\n", host);
+               return false;
+       }
+
+       status = open_socket_out(&ss, 445, 10000, &fd);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "open_socket_out failed: %s\n",
+                         nt_errstr(status));
+               return false;
+       }
+
+       conn = smbXcli_conn_create(talloc_tos(), fd, host, SMB_SIGNING_OFF, 0,
+                                  NULL, 0, NULL);
+       if (conn == NULL) {
+               d_fprintf(stderr, "smbXcli_conn_create failed\n");
+               return false;
+       }
+
+       status = smbXcli_negprot(conn, 0, PROTOCOL_NT1, PROTOCOL_NT1);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "smbXcli_negprot failed!\n");
+               return false;
+       }
+
+       ev = samba_tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               d_fprintf(stderr, "samba_tevent_context_init failed\n");
+               return false;
+       }
+
+       req = smb1_session_setup_nt1_truncated_send(ev, ev, conn);
+       if (req == NULL) {
+               d_fprintf(stderr, "smb1_session_setup_nt1_truncated_send failed\n");
+               return false;
+       }
+
+       ok = tevent_req_poll_ntstatus(req, ev, &status);
+       if (!ok) {
+               d_fprintf(stderr, "tevent_req_poll failed with status %s\n",
+                       nt_errstr(status));
+               return false;
+       }
+
+       status = smb1_session_setup_nt1_truncated_recv(req);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "smb1_session_setup_nt1_truncated_recv returned "
+                         "%s, expected NT_STATUS_OK\n",
+                         nt_errstr(status));
+               return false;
+       }
+
+       TALLOC_FREE(conn);
+       return true;
+}
+
+struct smb1_negotiate_exit_state {
+       int dummy;
+};
+
+static void smb1_negotiate_exit_done(struct tevent_req *subreq);
+
+static struct tevent_req *smb1_negotiate_exit_send(
+               TALLOC_CTX *mem_ctx,
+               struct tevent_context *ev,
+               struct smbXcli_conn *conn)
+{
+       struct smb1_negotiate_exit_state *state = NULL;
+       struct tevent_req *req = NULL;
+       struct tevent_req *subreq = NULL;
+
+       req = tevent_req_create(mem_ctx,
+                               &state,
+                               struct smb1_negotiate_exit_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       subreq = smb1cli_req_send(state, ev, conn,
+                                 SMBexit,
+                                 0, /*  additional_flags */
+                                 0, /*  clear_flags */
+                                 0, /*  additional_flags2 */
+                                 0, /*  clear_flags2 */
+                                 10000, /* timeout_msec */
+                                 getpid(),
+                                 NULL, /* tcon */
+                                 NULL, /* session */
+                                 0, /* wct */
+                                 NULL,
+                                 0,
+                                 NULL);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq,
+                               smb1_negotiate_exit_done,
+                               req);
+       return req;
+}
+
+static void smb1_negotiate_exit_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req =
+               tevent_req_callback_data(subreq,
+               struct tevent_req);
+       struct smb1_negotiate_exit_state *state =
+               tevent_req_data(req,
+               struct smb1_negotiate_exit_state);
+       NTSTATUS status;
+       struct smb1cli_req_expected_response expected[] = {
+       {
+               .status = NT_STATUS_OK,
+               .wct    = 0,
+       },
+       };
+
+       status = smb1cli_req_recv(subreq, state,
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 NULL, /* pvwv_offset */
+                                 NULL,
+                                 NULL,
+                                 NULL, /* pbytes_offset */
+                                 NULL,
+                                 expected, ARRAY_SIZE(expected));
+       TALLOC_FREE(subreq);
+       if (tevent_req_nterror(req, status)) {
+               return;
+       }
+       tevent_req_done(req);
+}
+
+static NTSTATUS smb1_negotiate_exit_recv(struct tevent_req *req)
+{
+       return tevent_req_simple_recv_ntstatus(req);
+}
+
+static bool do_smb1_exit(TALLOC_CTX *mem_ctx,
+                        struct tevent_context *ev,
+                        struct smbXcli_conn *conn)
+{
+       struct tevent_req *req;
+       bool ok;
+       NTSTATUS status;
+       NTSTATUS expected_status = NT_STATUS_DOS(ERRSRV, ERRinvnid);;
+
+       req = smb1_negotiate_exit_send(ev, ev, conn);
+       if (req == NULL) {
+               d_fprintf(stderr, "smb1_negotiate_exit_send failed\n");
+               return false;
+       }
+
+       ok = tevent_req_poll_ntstatus(req, ev, &status);
+       if (!ok) {
+               d_fprintf(stderr, "tevent_req_poll failed with status %s\n",
+                       nt_errstr(status));
+               return false;
+       }
+
+       status = smb1_negotiate_exit_recv(req);
+       if (!NT_STATUS_EQUAL(status, expected_status)) {
+               d_fprintf(stderr, "smb1_negotiate_exit_recv returned "
+                         "%s, expected ERRSRV, ERRinvnid\n",
+                         nt_errstr(status));
+               return false;
+       }
+       return true;
+}
+
+static bool run_smb1_negotiate_exit(int dummy)
+{
+       struct tevent_context *ev;
+       struct smbXcli_conn *conn;
+       struct sockaddr_storage ss;
+       NTSTATUS status;
+       int fd;
+       bool ok;
+
+       printf("Starting send SMB1 negotiate+exit.\n");
+
+       ok = resolve_name(host, &ss, 0x20, true);
+       if (!ok) {
+               d_fprintf(stderr, "Could not resolve name %s\n", host);
+               return false;
+       }
+
+       status = open_socket_out(&ss, 445, 10000, &fd);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "open_socket_out failed: %s\n",
+                         nt_errstr(status));
+               return false;
+       }
+
+       conn = smbXcli_conn_create(talloc_tos(), fd, host, SMB_SIGNING_OFF, 0,
+                                  NULL, 0, NULL);
+       if (conn == NULL) {
+               d_fprintf(stderr, "smbXcli_conn_create failed\n");
+               return false;
+       }
+
+       status = smbXcli_negprot(conn, 0, PROTOCOL_NT1, PROTOCOL_NT1);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "smbXcli_negprot failed!\n");
+               return false;
+       }
+
+       ev = samba_tevent_context_init(talloc_tos());
+       if (ev == NULL) {
+               d_fprintf(stderr, "samba_tevent_context_init failed\n");
+               return false;
+       }
+
+       /*
+        * Call do_smb1_exit twice to catch a server crash, the
+        * server sends the first return code then crashes.
+        */
+       ok = do_smb1_exit(ev, ev, conn);
+       if (!ok) {
+               d_fprintf(stderr, "do_smb1_exit (1) failed\n");
+               return false;
+       }
+       ok = do_smb1_exit(ev, ev, conn);
+       if (!ok) {
+               d_fprintf(stderr, "do_smb1_exit (2) failed\n");
+               return false;
+       }
+
+       TALLOC_FREE(conn);
+       return true;
+}
+
+static bool run_smb1_negotiate_tcon(int dummy)
+{
+       struct cli_state *cli = NULL;
+       uint16_t cnum = 0;
+       uint16_t max_xmit = 0;
+       NTSTATUS status;
+
+       printf("Starting send SMB1 negotiate+tcon.\n");
+       cli = open_nbt_connection();
+       if (cli == NULL) {
+               d_fprintf(stderr, "open_nbt_connection failed!\n");
+               return false;
+       }
+       smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+       status = smbXcli_negprot(cli->conn, 0, PROTOCOL_NT1, PROTOCOL_NT1);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "smbXcli_negprot failed %s!\n",
+                       nt_errstr(status));
+               return false;
+       }
+        status = cli_raw_tcon(cli,
+                             share,
+                             "",
+                             "?????",
+                             &max_xmit,
+                             &cnum);
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
+               d_fprintf(stderr, "cli_raw_tcon failed - got %s "
+                       "(should get NT_STATUS_ACCESS_DENIED)!\n",
+                       nt_errstr(status));
+               return false;
+       }
+       return true;
+}
 
 static bool run_ign_bad_negprot(int dummy)
 {
@@ -14621,6 +15190,7 @@ static bool run_ign_bad_negprot(int dummy)
        return true;
 }
 
+
 static double create_procs(bool (*fn)(int), bool *result)
 {
        int i, status;
@@ -14951,6 +15521,26 @@ static struct {
                .name  = "POSIX-SYMLINK-PARENT",
                .fn    = run_posix_symlink_parent_test,
        },
+       {
+               .name  = "POSIX-SYMLINK-CHMOD",
+               .fn    = run_posix_symlink_chmod_test,
+       },
+       {
+               .name  = "POSIX-SYMLINK-RENAME",
+               .fn    = run_posix_symlink_rename_test,
+       },
+       {
+               .name  = "POSIX-DIR-DEFAULT-ACL",
+               .fn    = run_posix_dir_default_acl_test,
+       },
+       {
+               .name  = "POSIX-SYMLINK-GETPATHINFO",
+               .fn    = run_posix_symlink_getpathinfo_test,
+       },
+       {
+               .name  = "POSIX-SYMLINK-SETPATHINFO",
+               .fn    = run_posix_symlink_setpathinfo_test,
+       },
        {
                .name  = "WINDOWS-BAD-SYMLINK",
                .fn    = run_symlink_open_test,
@@ -15017,10 +15607,6 @@ static struct {
                .name  = "DELETE-PRINT",
                .fn    = run_delete_print_test,
        },
-       {
-               .name  = "WILDDELETE",
-               .fn    = run_wild_deletetest,
-       },
        {
                .name  = "DELETE-LN",
                .fn    = run_deletetest_ln,
@@ -15225,6 +15811,66 @@ static struct {
                .name  = "SMB2-STREAM-ACL",
                .fn    = run_smb2_stream_acl,
        },
+       {
+               .name  = "SMB2-LIST-DIR-ASYNC",
+               .fn    = run_list_dir_async_test,
+       },
+       {
+               .name  = "SMB2-DEL-ON-CLOSE-NONEMPTY",
+               .fn    = run_delete_on_close_non_empty,
+       },
+       {
+               .name  = "SMB2-DEL-ON-CLOSE-NONWRITE-DELETE-YES",
+               .fn    = run_delete_on_close_nonwrite_delete_yes_test,
+       },
+       {
+               .name  = "SMB2-DEL-ON-CLOSE-NONWRITE-DELETE-NO",
+               .fn    = run_delete_on_close_nonwrite_delete_no_test,
+       },
+       {
+               .name  = "SMB2-DFS-PATHS",
+               .fn    = run_smb2_dfs_paths,
+       },
+       {
+               .name  = "SMB2-NON-DFS-SHARE",
+               .fn    = run_smb2_non_dfs_share,
+       },
+       {
+               .name  = "SMB2-DFS-SHARE-NON-DFS-PATH",
+               .fn    = run_smb2_dfs_share_non_dfs_path,
+       },
+       {
+               .name  = "SMB2-DFS-FILENAME-LEADING-BACKSLASH",
+               .fn    = run_smb2_dfs_filename_leading_backslash,
+       },
+       {
+               .name  = "SMB1-TRUNCATED-SESSSETUP",
+               .fn    = run_smb1_truncated_sesssetup,
+       },
+       {
+               .name  = "SMB1-NEGOTIATE-EXIT",
+               .fn    = run_smb1_negotiate_exit,
+       },
+       {
+               .name  = "SMB1-NEGOTIATE-TCON",
+               .fn    = run_smb1_negotiate_tcon,
+       },
+       {
+               .name  = "SMB1-DFS-PATHS",
+               .fn    = run_smb1_dfs_paths,
+       },
+       {
+               .name  = "SMB1-DFS-SEARCH-PATHS",
+               .fn    = run_smb1_dfs_search_paths,
+       },
+       {
+               .name  = "SMB1-DFS-OPERATIONS",
+               .fn    = run_smb1_dfs_operations,
+       },
+       {
+               .name  = "SMB1-DFS-BADPATH",
+               .fn    = run_smb1_dfs_check_badpath,
+       },
        {
                .name  = "CLEANUP1",
                .fn    = run_cleanup1,
@@ -15325,6 +15971,14 @@ static struct {
                .name  = "LOCAL-STREAM-NAME",
                .fn    = run_local_stream_name,
        },
+       {
+               .name  = "LOCAL-STR-MATCH-MSWILD",
+               .fn    = run_str_match_mswild,
+       },
+       {
+               .name  = "LOCAL-STR-MATCH-REGEX-SUB1",
+               .fn    = run_str_match_regex_sub1,
+       },
        {
                .name  = "WBCLIENT-MULTI-PING",
                .fn    = run_wbclient_multi_ping,
@@ -15449,6 +16103,10 @@ static struct {
                .name  = "hide-new-files-timeout",
                .fn    = run_hidenewfiles,
        },
+       {
+               .name  = "hide-new-files-timeout-showdirs",
+               .fn    = run_hidenewfiles_showdirs,
+       },
 #ifdef CLUSTER_SUPPORT
        {
                .name  = "ctdbd-conn1",
@@ -15459,6 +16117,14 @@ static struct {
                .name  = "readdir-timestamp",
                .fn    = run_readdir_timestamp,
        },
+       {
+               .name  = "rpc-scale",
+               .fn    = run_rpc_scale,
+       },
+       {
+               .name  = "LOCAL-TDB-VALIDATE",
+               .fn    = run_tdb_validate,
+       },
        {
                .name = NULL,
        },