selftest: Test hide new files timeout
[amitay/samba.git] / source3 / torture / torture.c
index 4661da95d78d52a3221bbc1336354da86a98c3fe..22810f081b843a10089053459245f6b0c52bed88 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include "system/shmem.h"
+#include "libsmb/namequery.h"
 #include "wbc_async.h"
 #include "torture/proto.h"
 #include "libcli/security/security.h"
@@ -31,7 +32,6 @@
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_open.h"
 #include "dbwrap/dbwrap_rbt.h"
-#include "talloc_dict.h"
 #include "async_smb.h"
 #include "libsmb/libsmb.h"
 #include "libsmb/clirap.h"
@@ -43,6 +43,9 @@
 #include "../libcli/smb/smbXcli_base.h"
 #include "lib/util/sys_rw_data.h"
 #include "lib/util/base64.h"
+#include "lib/util/time.h"
+#include "lib/crypto/md5.h"
+#include "lib/gencache.h"
 
 extern char *optarg;
 extern int optind;
@@ -326,16 +329,11 @@ bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
 
 static bool torture_open_connection_share(struct cli_state **c,
                                   const char *hostname, 
-                                  const char *sharename)
+                                  const char *sharename,
+                                  int flags)
 {
-       int flags = 0;
        NTSTATUS status;
 
-       if (use_oplocks)
-               flags |= CLI_FULL_CONNECTION_OPLOCKS;
-       if (use_level_II_oplocks)
-               flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
-
        status = cli_full_connection_creds(c,
                                           myname,
                                           hostname,
@@ -361,7 +359,7 @@ static bool torture_open_connection_share(struct cli_state **c,
        return True;
 }
 
-bool torture_open_connection(struct cli_state **c, int conn_index)
+bool torture_open_connection_flags(struct cli_state **c, int conn_index, int flags)
 {
        char **unc_list = NULL;
        int num_unc_names = 0;
@@ -383,14 +381,28 @@ bool torture_open_connection(struct cli_state **c, int conn_index)
                        exit(1);
                }
 
-               result = torture_open_connection_share(c, h, s);
+               result = torture_open_connection_share(c, h, s, flags);
 
                /* h, s were copied earlier */
                TALLOC_FREE(unc_list);
                return result;
        }
 
-       return torture_open_connection_share(c, host, share);
+       return torture_open_connection_share(c, host, share, flags);
+}
+
+bool torture_open_connection(struct cli_state **c, int conn_index)
+{
+       int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
+
+       if (use_oplocks) {
+               flags |= CLI_FULL_CONNECTION_OPLOCKS;
+       }
+       if (use_level_II_oplocks) {
+               flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
+       }
+
+       return torture_open_connection_flags(c, conn_index, flags);
 }
 
 bool torture_init_connection(struct cli_state **pcli)
@@ -1301,7 +1313,8 @@ static bool run_tcon_test(int dummy)
        static struct cli_state *cli;
        const char *fname = "\\tcontest.tmp";
        uint16_t fnum1;
-       uint16_t cnum1, cnum2, cnum3;
+       uint32_t cnum1, cnum2, cnum3;
+       struct smbXcli_tcon *orig_tcon = NULL;
        uint16_t vuid1, vuid2;
        char buf[4];
        bool ret = True;
@@ -1333,6 +1346,11 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
+       orig_tcon = cli_state_save_tcon(cli);
+       if (orig_tcon == NULL) {
+               return false;
+       }
+
        status = cli_tree_connect_creds(cli, share, "?????", torture_creds);
        if (!NT_STATUS_IS_OK(status)) {
                printf("%s refused 2nd tree connect (%s)\n", host,
@@ -1400,6 +1418,8 @@ static bool run_tcon_test(int dummy)
                return False;
        }
 
+       cli_state_restore_tcon(cli, orig_tcon);
+
        cli_state_set_tid(cli, cnum1);
 
        if (!torture_close_connection(cli)) {
@@ -1462,7 +1482,8 @@ static bool tcon_devtest(struct cli_state *cli,
 
        if (NT_STATUS_IS_OK(expected_error)) {
                if (NT_STATUS_IS_OK(status)) {
-                       if (strcmp(cli->dev, return_devtype) == 0) {
+                       if (return_devtype != NULL &&
+                           strequal(cli->dev, return_devtype)) {
                                ret = True;
                        } else { 
                                printf("tconX to share %s with type %s "
@@ -1502,7 +1523,7 @@ static bool tcon_devtest(struct cli_state *cli,
 static bool run_tcon_devtype_test(int dummy)
 {
        static struct cli_state *cli1 = NULL;
-       int flags = 0;
+       int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
        NTSTATUS status;
        bool ret = True;
 
@@ -2140,7 +2161,7 @@ static bool run_locktest5(int dummy)
        ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, False);
 
-       printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
+       printf("a different process %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
 
        /* Unlock the process 2 lock. */
        cli_unlock(cli2, fnum2, 0, 4);
@@ -2149,7 +2170,7 @@ static bool run_locktest5(int dummy)
        ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, False);
 
-       printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
+       printf("the same process on a different fnum %s get a read lock\n", ret?"can":"cannot");
 
        /* Unlock the process 1 fnum3 lock. */
        cli_unlock(cli1, fnum3, 0, 4);
@@ -2192,7 +2213,7 @@ static bool run_locktest5(int dummy)
        ret = NT_STATUS_IS_OK(status);
        EXPECTED(ret, True);
 
-       printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
+       printf("a different process %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
 
 
  fail:
@@ -2764,8 +2785,8 @@ static bool run_fdsesstest(int dummy)
        struct cli_state *cli;
        uint16_t new_vuid;
        uint16_t saved_vuid;
-       uint16_t new_cnum;
-       uint16_t saved_cnum;
+       uint32_t new_cnum;
+       uint32_t saved_cnum;
        const char *fname = "\\fdsess.tst";
        const char *fname1 = "\\fdsess1.tst";
        uint16_t fnum1;
@@ -3145,6 +3166,29 @@ static bool run_browsetest(int dummy)
 
 }
 
+static bool check_attributes(struct cli_state *cli,
+                               const char *fname,
+                               uint16_t expected_attrs)
+{
+       uint16_t attrs = 0;
+       NTSTATUS status = cli_getatr(cli,
+                               fname,
+                               &attrs,
+                               NULL,
+                               NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_getatr failed with %s\n",
+                       nt_errstr(status));
+               return false;
+       }
+       if (attrs != expected_attrs) {
+               printf("Attributes incorrect 0x%x, should be 0x%x\n",
+                       (unsigned int)attrs,
+                       (unsigned int)expected_attrs);
+               return false;
+       }
+       return true;
+}
 
 /*
   This checks how the getatr calls works
@@ -3175,7 +3219,7 @@ static bool run_attrtest(int dummy)
                correct = False;
        }
 
-       if (abs(t - time(NULL)) > 60*60*24*10) {
+       if (labs(t - time(NULL)) > 60*60*24*10) {
                printf("ERROR: SMBgetatr bug. time is %s",
                       ctime(&t));
                t = time(NULL);
@@ -3205,6 +3249,120 @@ static bool run_attrtest(int dummy)
 
        cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
 
+       /* Check cli_setpathinfo_basic() */
+       /* Re-create the file. */
+       status = cli_openx(cli, fname,
+                       O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("Failed to recreate %s (%s)\n",
+                       fname, nt_errstr(status));
+               correct = false;
+       }
+       cli_close(cli, fnum);
+
+       status = cli_setpathinfo_basic(cli,
+                                       fname,
+                                       0, /* create */
+                                       0, /* access */
+                                       0, /* write */
+                                       0, /* change */
+                                       FILE_ATTRIBUTE_SYSTEM |
+                                       FILE_ATTRIBUTE_HIDDEN |
+                                       FILE_ATTRIBUTE_READONLY);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_setpathinfo_basic failed with %s\n",
+                       nt_errstr(status));
+               correct = false;
+       }
+
+       /* Check attributes are correct. */
+       correct = check_attributes(cli,
+                       fname,
+                       FILE_ATTRIBUTE_SYSTEM |
+                       FILE_ATTRIBUTE_HIDDEN |
+                       FILE_ATTRIBUTE_READONLY);
+       if (correct == false) {
+               goto out;
+       }
+
+       /* Setting to FILE_ATTRIBUTE_NORMAL should be ignored. */
+       status = cli_setpathinfo_basic(cli,
+                                       fname,
+                                       0, /* create */
+                                       0, /* access */
+                                       0, /* write */
+                                       0, /* change */
+                                       FILE_ATTRIBUTE_NORMAL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_setpathinfo_basic failed with %s\n",
+                       nt_errstr(status));
+               correct = false;
+       }
+
+       /* Check attributes are correct. */
+       correct = check_attributes(cli,
+                       fname,
+                       FILE_ATTRIBUTE_SYSTEM |
+                       FILE_ATTRIBUTE_HIDDEN |
+                       FILE_ATTRIBUTE_READONLY);
+       if (correct == false) {
+               goto out;
+       }
+
+       /* Setting to (uint16_t)-1 should also be ignored. */
+       status = cli_setpathinfo_basic(cli,
+                                       fname,
+                                       0, /* create */
+                                       0, /* access */
+                                       0, /* write */
+                                       0, /* change */
+                                       (uint16_t)-1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_setpathinfo_basic failed with %s\n",
+                       nt_errstr(status));
+               correct = false;
+       }
+
+       /* Check attributes are correct. */
+       correct = check_attributes(cli,
+                       fname,
+                       FILE_ATTRIBUTE_SYSTEM |
+                       FILE_ATTRIBUTE_HIDDEN |
+                       FILE_ATTRIBUTE_READONLY);
+       if (correct == false) {
+               goto out;
+       }
+
+       /* Setting to 0 should clear them all. */
+       status = cli_setpathinfo_basic(cli,
+                                       fname,
+                                       0, /* create */
+                                       0, /* access */
+                                       0, /* write */
+                                       0, /* change */
+                                       0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_setpathinfo_basic failed with %s\n",
+                       nt_errstr(status));
+               correct = false;
+       }
+
+       /* Check attributes are correct. */
+       correct = check_attributes(cli,
+                       fname,
+                       FILE_ATTRIBUTE_NORMAL);
+       if (correct == false) {
+               goto out;
+       }
+
+  out:
+
+       cli_unlink(cli,
+               fname,
+               FILE_ATTRIBUTE_SYSTEM |
+               FILE_ATTRIBUTE_HIDDEN|
+               FILE_ATTRIBUTE_READONLY);
+
        if (!torture_close_connection(cli)) {
                correct = False;
        }
@@ -3292,13 +3450,13 @@ static bool run_trans2test(int dummy)
                        printf("modify time=%s", ctime(&m_time));
                        printf("This system appears to have sticky create times\n");
                }
-               if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
+               if ((labs(a_time - t) > 60) && (a_time % (60*60) == 0)) {
                        printf("access time=%s", ctime(&a_time));
                        printf("This system appears to set a midnight access time\n");
                        correct = False;
                }
 
-               if (abs(m_time - t) > 60*60*24*7) {
+               if (labs(m_time - t) > 60*60*24*7) {
                        printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
                        correct = False;
                }
@@ -4405,6 +4563,78 @@ static bool run_deletetest(int dummy)
        return correct;
 }
 
+/*
+  Exercise delete on close semantics - use on the PRINT1 share in torture
+  testing.
+ */
+static bool run_delete_print_test(int dummy)
+{
+       struct cli_state *cli1 = NULL;
+       const char *fname = "print_delete.file";
+       uint16_t fnum1 = (uint16_t)-1;
+       bool correct = false;
+       const char *buf = "print file data\n";
+       NTSTATUS status;
+
+       printf("starting print delete test\n");
+
+       if (!torture_open_connection(&cli1, 0)) {
+               return false;
+       }
+
+       smbXcli_conn_set_sockopt(cli1->conn, sockops);
+
+       status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,
+                             FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                             0, 0, &fnum1, NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("open of %s failed (%s)\n",
+                       fname,
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       status = cli_writeall(cli1,
+                       fnum1,
+                       0,
+                       (const uint8_t *)buf,
+                       0, /* offset */
+                       strlen(buf), /* size */
+                       NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("writing print file data failed (%s)\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       status = cli_nt_delete_on_close(cli1, fnum1, true);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("setting delete_on_close failed (%s)\n",
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("close failed (%s)\n", nt_errstr(status));
+               goto fail;
+       }
+
+       printf("finished print delete test\n");
+
+       correct = true;
+
+  fail:
+
+       if (fnum1 != (uint16_t)-1) {
+               cli_close(cli1, fnum1);
+       }
+
+       if (cli1 && !torture_close_connection(cli1)) {
+               correct = false;
+       }
+       return correct;
+}
 
 /*
   Test wildcard delete.
@@ -5066,7 +5296,7 @@ static bool run_rename_access(int dummy)
        }
 
        if (cli) {
-               if (fnum != (uint64_t)-1) {
+               if (fnum != (uint16_t)-1) {
                        cli_close(cli, fnum);
                }
                cli_unlink(cli, src,
@@ -7891,6 +8121,7 @@ static bool run_chain1(int dummy)
        struct tevent_req *reqs[3], *smbreqs[3];
        bool done = false;
        const char *str = "foobar";
+       const char *fname = "\\test_chain";
        NTSTATUS status;
 
        printf("starting chain1 test\n");
@@ -7900,7 +8131,9 @@ static bool run_chain1(int dummy)
 
        smbXcli_conn_set_sockopt(cli1->conn, sockops);
 
-       reqs[0] = cli_openx_create(talloc_tos(), evt, cli1, "\\test",
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       reqs[0] = cli_openx_create(talloc_tos(), evt, cli1, fname,
                                  O_CREAT|O_RDWR, 0, &smbreqs[0]);
        if (reqs[0] == NULL) return false;
        tevent_req_set_callback(reqs[0], chain1_open_completion, NULL);
@@ -7912,7 +8145,7 @@ static bool run_chain1(int dummy)
        if (reqs[1] == NULL) return false;
        tevent_req_set_callback(reqs[1], chain1_write_completion, NULL);
 
-       reqs[2] = cli_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
+       reqs[2] = cli_smb1_close_create(talloc_tos(), evt, cli1, 0, &smbreqs[2]);
        if (reqs[2] == NULL) return false;
        tevent_req_set_callback(reqs[2], chain1_close_completion, &done);
 
@@ -7952,10 +8185,11 @@ static bool run_chain2(int dummy)
        struct tevent_req *reqs[2], *smbreqs[2];
        bool done = false;
        NTSTATUS status;
+       int flags = CLI_FULL_CONNECTION_FORCE_SMB1;
 
        printf("starting chain2 test\n");
        status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL,
-                                     port_to_use, SMB_SIGNING_DEFAULT, 0);
+                                     port_to_use, SMB_SIGNING_DEFAULT, flags);
        if (!NT_STATUS_IS_OK(status)) {
                return False;
        }
@@ -9011,12 +9245,164 @@ static bool run_cli_echo(int dummy)
        return NT_STATUS_IS_OK(status);
 }
 
+static int splice_status(off_t written, void *priv)
+{
+        return true;
+}
+
+static bool run_cli_splice(int dummy)
+{
+       uint8_t *buf = NULL;
+       struct cli_state *cli1 = NULL;
+       bool correct = false;
+       const char *fname_src = "\\splice_src.dat";
+       const char *fname_dst = "\\splice_dst.dat";
+       NTSTATUS status;
+       uint16_t fnum1 = UINT16_MAX;
+       uint16_t fnum2 = UINT16_MAX;
+       size_t file_size = 2*1024*1024;
+       size_t splice_size = 1*1024*1024 + 713;
+       MD5_CTX md5_ctx;
+       uint8_t digest1[16], digest2[16];
+       off_t written = 0;
+       size_t nread = 0;
+       TALLOC_CTX *frame = talloc_stackframe();
+
+       printf("starting cli_splice test\n");
+
+       if (!torture_open_connection(&cli1, 0)) {
+               goto out;
+       }
+
+       cli_unlink(cli1, fname_src,
+               FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli1, fname_dst,
+               FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       /* Create a file */
+       status = cli_ntcreate(cli1, fname_src, 0, GENERIC_ALL_ACCESS,
+                       FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                       0, 0, &fnum1, NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("open %s failed: %s\n", fname_src, nt_errstr(status));
+               goto out;
+       }
+
+       /* Write file_size bytes - must be bigger than splice_size. */
+       buf = talloc_zero_array(frame, uint8_t, file_size);
+       if (buf == NULL) {
+               d_printf("talloc_fail\n");
+               goto out;
+       }
+
+       /* Fill it with random numbers. */
+       generate_random_buffer(buf, file_size);
+
+       /* MD5 the first 1MB + 713 bytes. */
+       MD5Init(&md5_ctx);
+       MD5Update(&md5_ctx, buf, splice_size);
+       MD5Final(digest1, &md5_ctx);
+
+       status = cli_writeall(cli1,
+                             fnum1,
+                             0,
+                             buf,
+                             0,
+                             file_size,
+                             NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_writeall failed: %s\n", nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_ntcreate(cli1, fname_dst, 0, GENERIC_ALL_ACCESS,
+                       FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+                       0, 0, &fnum2, NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("open %s failed: %s\n", fname_dst, nt_errstr(status));
+               goto out;
+       }
+
+       /* Now splice 1MB + 713 bytes. */
+       status = cli_splice(cli1,
+                               cli1,
+                               fnum1,
+                               fnum2,
+                               splice_size,
+                               0,
+                               0,
+                               &written,
+                               splice_status,
+                               NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_splice failed: %s\n", nt_errstr(status));
+               goto out;
+       }
+
+       /* Clear the old buffer. */
+       memset(buf, '\0', file_size);
+
+       /* Read the new file. */
+       status = cli_read(cli1, fnum2, (char *)buf, 0, splice_size, &nread);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("cli_read failed: %s\n", nt_errstr(status));
+               goto out;
+       }
+       if (nread != splice_size) {
+               d_printf("bad read of 0x%x, should be 0x%x\n",
+                       (unsigned int)nread,
+                       (unsigned int)splice_size);
+               goto out;
+       }
+
+       /* MD5 the first 1MB + 713 bytes. */
+       MD5Init(&md5_ctx);
+       MD5Update(&md5_ctx, buf, splice_size);
+       MD5Final(digest2, &md5_ctx);
+
+       /* Must be the same. */
+       if (memcmp(digest1, digest2, 16) != 0) {
+               d_printf("bad MD5 compare\n");
+               goto out;
+       }
+
+       correct = true;
+       printf("Success on cli_splice test\n");
+
+  out:
+
+       if (cli1) {
+               if (fnum1 != UINT16_MAX) {
+                       cli_close(cli1, fnum1);
+               }
+               if (fnum2 != UINT16_MAX) {
+                       cli_close(cli1, fnum2);
+               }
+
+               cli_unlink(cli1, fname_src,
+                       FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+               cli_unlink(cli1, fname_dst,
+                       FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+               if (!torture_close_connection(cli1)) {
+                       correct = false;
+               }
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
+
 static bool run_uid_regression_test(int dummy)
 {
        static struct cli_state *cli;
        int16_t old_vuid;
-       int16_t old_cnum;
+       int32_t old_cnum;
        bool correct = True;
+       struct smbXcli_tcon *orig_tcon = NULL;
        NTSTATUS status;
 
        printf("starting uid regression test\n");
@@ -9057,6 +9443,11 @@ static bool run_uid_regression_test(int dummy)
        }
 
        old_cnum = cli_state_get_tid(cli);
+       orig_tcon = cli_state_save_tcon(cli);
+       if (orig_tcon == NULL) {
+               correct = false;
+               goto out;
+       }
 
        /* Now try a SMBtdis with the invald vuid set to zero. */
        cli_state_set_uid(cli, 0);
@@ -9069,9 +9460,11 @@ static bool run_uid_regression_test(int dummy)
        } else {
                d_printf("First tdis failed (%s)\n", nt_errstr(status));
                correct = false;
+               cli_state_restore_tcon(cli, orig_tcon);
                goto out;
        }
 
+       cli_state_restore_tcon(cli, orig_tcon);
        cli_state_set_uid(cli, old_vuid);
        cli_state_set_tid(cli, old_cnum);
 
@@ -9368,8 +9761,8 @@ https://bugzilla.samba.org/show_bug.cgi?id=7084
 static bool run_dir_createtime(int dummy)
 {
        struct cli_state *cli;
-       const char *dname = "\\testdir";
-       const char *fname = "\\testdir\\testfile";
+       const char *dname = "\\testdir_createtime";
+       const char *fname = "\\testdir_createtime\\testfile";
        NTSTATUS status;
        struct timespec create_time;
        struct timespec create_time1;
@@ -9436,9 +9829,9 @@ static bool run_dir_createtime(int dummy)
 static bool run_streamerror(int dummy)
 {
        struct cli_state *cli;
-       const char *dname = "\\testdir";
+       const char *dname = "\\testdir_streamerror";
        const char *streamname =
-               "testdir:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
+               "testdir_streamerror:{4c8cc155-6c1e-11d1-8e41-00c04fb9386d}:$DATA";
        NTSTATUS status;
        time_t change_time, access_time, write_time;
        off_t size;
@@ -9449,7 +9842,7 @@ static bool run_streamerror(int dummy)
                return false;
        }
 
-       cli_unlink(cli, "\\testdir\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+       cli_unlink(cli, "\\testdir_streamerror\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
        cli_rmdir(cli, dname);
 
        status = cli_mkdir(cli, dname);
@@ -9743,6 +10136,54 @@ static bool run_symlink_open_test(int dummy)
        return correct;
 }
 
+/*
+ * Only testing minimal time strings, as the others
+ * need (locale-dependent) guessing at what strftime does and
+ * even may differ in builds.
+ */
+static bool timesubst_test(void)
+{
+       TALLOC_CTX *ctx = NULL;
+       /* Sa 23. Dez 04:33:20 CET 2017 */
+       const struct timeval tv = { 1514000000, 123 };
+       const char* expect_minimal = "20171223_033320";
+       const char* expect_minus   = "20171223_033320_000123";
+       char *s;
+       char *env_tz, *orig_tz = NULL;
+       bool result = true;
+
+       ctx = talloc_new(NULL);
+
+       env_tz = getenv("TZ");
+       if(env_tz) {
+               orig_tz = talloc_strdup(ctx, env_tz);
+       }
+       setenv("TZ", "UTC", 1);
+
+       s = minimal_timeval_string(ctx, &tv, false);
+
+       if(!s || strcmp(s, expect_minimal)) {
+               printf("minimal_timeval_string(ctx, tv, false) returned [%s], expected "
+                      "[%s]\n", s ? s : "<nil>", expect_minimal);
+               result = false;
+       }
+       TALLOC_FREE(s);
+       s = minimal_timeval_string(ctx, &tv, true);
+       if(!s || strcmp(s, expect_minus)) {
+               printf("minimal_timeval_string(ctx, tv, true) returned [%s], expected "
+                      "[%s]\n", s ? s : "<nil>", expect_minus);
+               result = false;
+       }
+       TALLOC_FREE(s);
+
+       if(orig_tz) {
+               setenv("TZ", orig_tz, 1);
+       }
+
+       TALLOC_FREE(ctx);
+       return result;
+}
+
 static bool run_local_substitute(int dummy)
 {
        bool ok = true;
@@ -9755,6 +10196,10 @@ static bool run_local_substitute(int dummy)
        ok &= subst_test("%G", "", "", -1, 0, gidtoname(0));
        ok &= subst_test("%D%u", "u", "dom", -1, 0, "domu");
        ok &= subst_test("%i %I", "", "", -1, -1, "0.0.0.0 0.0.0.0");
+       ok &= subst_test("%j %J", "", "", -1, -1, "0_0_0_0 0_0_0_0");
+       /* Substitution depends on current time, so better test the underlying
+          formatting function. At least covers %t. */
+       ok &= timesubst_test();
 
        /* Different captialization rules in sub_basic... */
 
@@ -9797,7 +10242,9 @@ static bool run_local_base64(int dummy)
        return ret;
 }
 
-static void parse_fn(time_t timeout, DATA_BLOB blob, void *private_data)
+static void parse_fn(const struct gencache_timeout *t,
+                    DATA_BLOB blob,
+                    void *private_data)
 {
        return;
 }
@@ -9871,7 +10318,7 @@ static bool run_local_gencache(int dummy)
        blob = data_blob_string_const_null("bar");
        tm = time(NULL) + 60;
 
-       if (!gencache_set_data_blob("foo", &blob, tm)) {
+       if (!gencache_set_data_blob("foo", blob, tm)) {
                d_printf("%s: gencache_set_data_blob() failed\n", __location__);
                return False;
        }
@@ -9910,7 +10357,7 @@ static bool run_local_gencache(int dummy)
        blob.data = (uint8_t *)&v;
        blob.length = sizeof(v);
 
-       if (!gencache_set_data_blob("blob", &blob, tm)) {
+       if (!gencache_set_data_blob("blob", blob, tm)) {
                d_printf("%s: gencache_set_data_blob() failed\n",
                         __location__);
                return false;
@@ -10151,61 +10598,6 @@ failed:
        return false;
 }
 
-
-struct talloc_dict_test {
-       int content;
-};
-
-static int talloc_dict_traverse_fn(DATA_BLOB key, void *data, void *priv)
-{
-       int *count = (int *)priv;
-       *count += 1;
-       return 0;
-}
-
-static bool run_local_talloc_dict(int dummy)
-{
-       struct talloc_dict *dict;
-       struct talloc_dict_test *t;
-       int key, count, res;
-       bool ok;
-
-       dict = talloc_dict_init(talloc_tos());
-       if (dict == NULL) {
-               return false;
-       }
-
-       t = talloc(talloc_tos(), struct talloc_dict_test);
-       if (t == NULL) {
-               return false;
-       }
-
-       key = 1;
-       t->content = 1;
-       ok = talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), &t);
-       if (!ok) {
-               return false;
-       }
-
-       count = 0;
-       res = talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count);
-       if (res == -1) {
-               return false;
-       }
-
-       if (count != 1) {
-               return false;
-       }
-
-       if (count != res) {
-               return false;
-       }
-
-       TALLOC_FREE(dict);
-
-       return true;
-}
-
 static bool run_local_string_to_sid(int dummy) {
        struct dom_sid sid;
 
@@ -10554,15 +10946,25 @@ static bool data_blob_equal(DATA_BLOB a, DATA_BLOB b)
 static bool run_local_memcache(int dummy)
 {
        struct memcache *cache;
-       DATA_BLOB k1, k2;
-       DATA_BLOB d1, d2, d3;
-       DATA_BLOB v1, v2, v3;
+       DATA_BLOB k1, k2, k3;
+       DATA_BLOB d1, d3;
+       DATA_BLOB v1, v3;
 
        TALLOC_CTX *mem_ctx;
+       char *ptr1 = NULL;
+       char *ptr2 = NULL;
+
        char *str1, *str2;
        size_t size1, size2;
        bool ret = false;
 
+       mem_ctx = talloc_init("foo");
+       if (mem_ctx == NULL) {
+               return false;
+       }
+
+       /* STAT_CACHE TESTS */
+
        cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
 
        if (cache == NULL) {
@@ -10571,14 +10973,13 @@ static bool run_local_memcache(int dummy)
        }
 
        d1 = data_blob_const("d1", 2);
-       d2 = data_blob_const("d2", 2);
        d3 = data_blob_const("d3", 2);
 
        k1 = data_blob_const("d1", 2);
        k2 = data_blob_const("d2", 2);
+       k3 = data_blob_const("d3", 2);
 
        memcache_add(cache, STAT_CACHE, k1, d1);
-       memcache_add(cache, GETWD_CACHE, k2, d2);
 
        if (!memcache_lookup(cache, STAT_CACHE, k1, &v1)) {
                printf("could not find k1\n");
@@ -10588,40 +10989,79 @@ static bool run_local_memcache(int dummy)
                return false;
        }
 
-       if (!memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
-               printf("could not find k2\n");
+       memcache_add(cache, STAT_CACHE, k1, d3);
+
+       if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
+               printf("could not find replaced k1\n");
                return false;
        }
-       if (!data_blob_equal(d2, v2)) {
+       if (!data_blob_equal(d3, v3)) {
                return false;
        }
 
-       memcache_add(cache, STAT_CACHE, k1, d3);
+       TALLOC_FREE(cache);
 
-       if (!memcache_lookup(cache, STAT_CACHE, k1, &v3)) {
-               printf("could not find replaced k1\n");
+       /* GETWD_CACHE TESTS */
+       str1 = talloc_strdup(mem_ctx, "string1");
+       if (str1 == NULL) {
                return false;
        }
-       if (!data_blob_equal(d3, v3)) {
+       ptr2 = str1; /* Keep an alias for comparison. */
+
+       str2 = talloc_strdup(mem_ctx, "string2");
+       if (str2 == NULL) {
                return false;
        }
 
-       memcache_add(cache, GETWD_CACHE, k1, d1);
+       cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100);
+       if (cache == NULL) {
+               printf("memcache_init failed\n");
+               return false;
+       }
 
-       if (memcache_lookup(cache, GETWD_CACHE, k2, &v2)) {
+       memcache_add_talloc(cache, GETWD_CACHE, k2, &str1);
+       /* str1 == NULL now. */
+       ptr1 = memcache_lookup_talloc(cache, GETWD_CACHE, k2);
+       if (ptr1 == NULL) {
+               printf("could not find k2\n");
+               return false;
+       }
+       if (ptr1 != ptr2) {
+               printf("fetch of k2 got wrong string\n");
+               return false;
+       }
+
+       /* Add a blob to ensure k2 gets purged. */
+       d3 = data_blob_talloc_zero(mem_ctx, 180);
+       memcache_add(cache, STAT_CACHE, k3, d3);
+
+       ptr2 = memcache_lookup_talloc(cache, GETWD_CACHE, k2);
+       if (ptr2 != NULL) {
                printf("Did find k2, should have been purged\n");
                return false;
        }
 
        TALLOC_FREE(cache);
-
-       cache = memcache_init(NULL, 0);
+       TALLOC_FREE(mem_ctx);
 
        mem_ctx = talloc_init("foo");
+       if (mem_ctx == NULL) {
+               return false;
+       }
+
+       cache = memcache_init(NULL, 0);
+       if (cache == NULL) {
+               return false;
+       }
 
        str1 = talloc_strdup(mem_ctx, "string1");
+       if (str1 == NULL) {
+               return false;
+       }
        str2 = talloc_strdup(mem_ctx, "string2");
-
+       if (str2 == NULL) {
+               return false;
+       }
        memcache_add_talloc(cache, SINGLETON_CACHE_TALLOC,
                            data_blob_string_const("torture"), &str1);
        size1 = talloc_total_size(cache);
@@ -10708,59 +11148,6 @@ static bool run_wbclient_multi_ping(int dummy)
        return result;
 }
 
-static void getaddrinfo_finished(struct tevent_req *req)
-{
-       char *name = (char *)tevent_req_callback_data_void(req);
-       struct addrinfo *ainfo;
-       int res;
-
-       res = getaddrinfo_recv(req, &ainfo);
-       if (res != 0) {
-               d_printf("gai(%s) returned %s\n", name, gai_strerror(res));
-               return;
-       }
-       d_printf("gai(%s) succeeded\n", name);
-       freeaddrinfo(ainfo);
-}
-
-static bool run_getaddrinfo_send(int dummy)
-{
-       TALLOC_CTX *frame = talloc_stackframe();
-       struct fncall_context *ctx;
-       struct tevent_context *ev;
-       bool result = false;
-       const char *names[4] = { "www.samba.org", "notfound.samba.org",
-                                "www.slashdot.org", "heise.de" };
-       struct tevent_req *reqs[4];
-       int i;
-
-       ev = samba_tevent_context_init(frame);
-       if (ev == NULL) {
-               goto fail;
-       }
-
-       ctx = fncall_context_init(frame, 4);
-
-       for (i=0; i<ARRAY_SIZE(names); i++) {
-               reqs[i] = getaddrinfo_send(frame, ev, ctx, names[i], NULL,
-                                          NULL);
-               if (reqs[i] == NULL) {
-                       goto fail;
-               }
-               tevent_req_set_callback(reqs[i], getaddrinfo_finished,
-                                       discard_const_p(void, names[i]));
-       }
-
-       for (i=0; i<ARRAY_SIZE(reqs); i++) {
-               tevent_loop_once(ev);
-       }
-
-       result = true;
-fail:
-       TALLOC_FREE(frame);
-       return result;
-}
-
 static bool dbtrans_inc(struct db_context *db)
 {
        struct db_record *rec;
@@ -10903,17 +11290,17 @@ static bool run_local_dbtrans(int dummy)
 
 /*
  * Just a dummy test to be run under a debugger. There's no real way
- * to inspect the tevent_select specific function from outside of
- * tevent_select.c.
+ * to inspect the tevent_poll specific function from outside of
+ * tevent_poll.c.
  */
 
-static bool run_local_tevent_select(int dummy)
+static bool run_local_tevent_poll(int dummy)
 {
        struct tevent_context *ev;
        struct tevent_fd *fd1, *fd2;
        bool result = false;
 
-       ev = tevent_context_init_byname(NULL, "select");
+       ev = tevent_context_init_byname(NULL, "poll");
        if (ev == NULL) {
                d_fprintf(stderr, "tevent_context_init_byname failed\n");
                goto fail;
@@ -11154,7 +11541,7 @@ static bool run_local_canonicalize_path(int dummy)
                }
                if (strcmp(d, dst[i]) != 0) {
                        d_fprintf(stderr,
-                               "canonicalize missmatch %s -> %s != %s",
+                               "canonicalize mismatch %s -> %s != %s",
                                src[i], d, dst[i]);
                        return false;
                }
@@ -11394,6 +11781,7 @@ static struct {
        {"RENAME-ACCESS", run_rename_access, 0},
        {"OWNER-RIGHTS", run_owner_rights, 0},
        {"DELETE", run_deletetest, 0},
+       {"DELETE-PRINT", run_delete_print_test, 0},
        {"WILDDELETE", run_wild_deletetest, 0},
        {"DELETE-LN", run_deletetest_ln, 0},
        {"PROPERTIES", run_properties, 0},
@@ -11421,7 +11809,7 @@ static struct {
        { "NTTRANS-CREATE", run_nttrans_create, 0},
        { "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
        { "CLI_ECHO", run_cli_echo, 0},
-       { "GETADDRINFO", run_getaddrinfo_send, 0},
+       { "CLI_SPLICE", run_cli_splice, 0},
        { "TLDAP", run_tldap },
        { "STREAMERROR", run_streamerror },
        { "NOTIFY-BENCH", run_notify_bench },
@@ -11433,11 +11821,13 @@ static struct {
        { "NOTIFY-ONLINE", run_notify_online },
        { "SMB2-BASIC", run_smb2_basic },
        { "SMB2-NEGPROT", run_smb2_negprot },
+       { "SMB2-ANONYMOUS", run_smb2_anonymous },
        { "SMB2-SESSION-RECONNECT", run_smb2_session_reconnect },
        { "SMB2-TCON-DEPENDENCE", run_smb2_tcon_dependence },
        { "SMB2-MULTI-CHANNEL", run_smb2_multi_channel },
        { "SMB2-SESSION-REAUTH", run_smb2_session_reauth },
        { "SMB2-FTRUNCATE", run_smb2_ftruncate },
+       { "SMB2-DIR-FSYNC", run_smb2_dir_fsync },
        { "CLEANUP1", run_cleanup1 },
        { "CLEANUP2", run_cleanup2 },
        { "CLEANUP3", run_cleanup3 },
@@ -11446,9 +11836,9 @@ static struct {
        { "PIDHIGH", run_pidhigh },
        { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
        { "LOCAL-GENCACHE", run_local_gencache, 0},
-       { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0},
        { "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 },
        { "LOCAL-DBWRAP-WATCH2", run_dbwrap_watch2, 0 },
+       { "LOCAL-DBWRAP-DO-LOCKED1", run_dbwrap_do_locked1, 0 },
        { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 },
        { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 },
        { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 },
@@ -11457,6 +11847,7 @@ static struct {
        { "LOCAL-MESSAGING-FDPASS2", run_messaging_fdpass2, 0 },
        { "LOCAL-MESSAGING-FDPASS2a", run_messaging_fdpass2a, 0 },
        { "LOCAL-MESSAGING-FDPASS2b", run_messaging_fdpass2b, 0 },
+       { "LOCAL-MESSAGING-SEND-ALL", run_messaging_send_all, 0 },
        { "LOCAL-BASE64", run_local_base64, 0},
        { "LOCAL-RBTREE", run_local_rbtree, 0},
        { "LOCAL-MEMCACHE", run_local_memcache, 0},
@@ -11466,7 +11857,7 @@ static struct {
        { "LOCAL-sid_to_string", run_local_sid_to_string, 0},
        { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0},
        { "LOCAL-DBTRANS", run_local_dbtrans, 0},
-       { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0},
+       { "LOCAL-TEVENT-POLL", run_local_tevent_poll, 0},
        { "LOCAL-CONVERT-STRING", run_local_convert_string, 0},
        { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0},
        { "LOCAL-hex_encode_buf", run_local_hex_encode_buf, 0},
@@ -11480,19 +11871,16 @@ static struct {
        { "LOCAL-G-LOCK1", run_g_lock1, 0 },
        { "LOCAL-G-LOCK2", run_g_lock2, 0 },
        { "LOCAL-G-LOCK3", run_g_lock3, 0 },
+       { "LOCAL-G-LOCK4", run_g_lock4, 0 },
+       { "LOCAL-G-LOCK5", run_g_lock5, 0 },
+       { "LOCAL-G-LOCK6", run_g_lock6, 0 },
+       { "LOCAL-G-LOCK-PING-PONG", run_g_lock_ping_pong, 0 },
        { "LOCAL-CANONICALIZE-PATH", run_local_canonicalize_path, 0 },
+       { "LOCAL-NAMEMAP-CACHE1", run_local_namemap_cache1, 0 },
        { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 },
+       { "hide-new-files-timeout", run_hidenewfiles, 0 },
        {NULL, NULL, 0}};
 
-/*
- * dummy function to satisfy linker dependency
- */
-struct tevent_context *winbind_event_context(void);
-struct tevent_context *winbind_event_context(void)
-{
-       return NULL;
-}
-
 /****************************************************************************
 run a specified test or "ALL"
 ****************************************************************************/