#include "includes.h"
#include "system/shmem.h"
+#include "libsmb/namequery.h"
#include "wbc_async.h"
#include "torture/proto.h"
#include "libcli/security/security.h"
#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;
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 "
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);
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);
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:
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.
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");
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);
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);
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;
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;
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;
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);
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;
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... */
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;
}
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;
}
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;
}
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;
}
{"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},
{ "NTTRANS-CREATE", run_nttrans_create, 0},
{ "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
{ "CLI_ECHO", run_cli_echo, 0},
+ { "CLI_SPLICE", run_cli_splice, 0},
{ "TLDAP", run_tldap },
{ "STREAMERROR", run_streamerror },
{ "NOTIFY-BENCH", run_notify_bench },
{ "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 },
{ "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},
{ "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}};
/****************************************************************************