static bool use_multishare_conn = False;
static bool do_encrypt;
static const char *local_path = NULL;
-static int signing_state = SMB_SIGNING_DEFAULT;
+static enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT;
char *test_filename;
bool torture_showall = False;
bool ret = false;
uint8_t message_type;
uint8_t error;
- struct event_context *ev;
+ struct tevent_context *ev;
struct tevent_req *req;
frame = talloc_stackframe();
goto fail;
}
- ev = event_context_init(frame);
+ ev = samba_tevent_context_init(frame);
if (ev == NULL) {
goto fail;
}
printf("starting negprot nowait test\n");
- ev = tevent_context_init(talloc_tos());
+ ev = samba_tevent_context_init(talloc_tos());
if (ev == NULL) {
return false;
}
correct = False;
}
+ SAFE_FREE(rparam);
+ SAFE_FREE(rdata);
+
printf("finished random ipc test\n");
return correct;
return false;
}
- ev = tevent_context_init(talloc_tos());
+ ev = samba_tevent_context_init(talloc_tos());
if (ev == NULL) {
printf("tevent_context_init failed\n");
return false;
const char *fname = "\\delete.file";
uint16_t fnum1 = (uint16_t)-1;
uint16_t fnum2 = (uint16_t)-1;
- bool correct = True;
+ bool correct = false;
NTSTATUS status;
printf("starting delete test\n");
FILE_DELETE_ON_CLOSE, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[1] close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1);
if (NT_STATUS_IS_OK(status)) {
printf("[1] open of %s succeeded (should fail)\n", fname);
- correct = False;
goto fail;
}
FILE_OVERWRITE_IF, 0, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (!NT_STATUS_IS_OK(status)) {
printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[2] close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[2] close failed (%s)\n", nt_errstr(status));
- correct = False;
- goto fail;
}
cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
- } else
- printf("second delete on close test succeeded.\n");
+ goto fail;
+ }
+
+ printf("second delete on close test succeeded.\n");
/* Test 3 - ... */
cli_setatr(cli1, fname, 0, 0);
FILE_OVERWRITE_IF, 0, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
FILE_OPEN, 0, 0, &fnum2);
if (NT_STATUS_IS_OK(status)) {
printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
- correct = False;
goto fail;
}
FILE_OPEN, 0, 0, &fnum2);
if (!NT_STATUS_IS_OK(status)) {
printf("[3] open - 3 of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (!NT_STATUS_IS_OK(status)) {
printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[3] close 1 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum2);
if (!NT_STATUS_IS_OK(status)) {
printf("[3] close 2 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
printf("[3] close failed (%s)\n", nt_errstr(status));
}
cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
- correct = False;
goto fail;
- } else
- printf("third delete on close test succeeded.\n");
+ }
+
+ printf("third delete on close test succeeded.\n");
/* Test 4 ... */
cli_setatr(cli1, fname, 0, 0);
FILE_OVERWRITE_IF, 0, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
FILE_OPEN, 0, 0, &fnum2);
if (!NT_STATUS_IS_OK(status)) {
printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum2);
if (!NT_STATUS_IS_OK(status)) {
printf("[4] close - 1 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (!NT_STATUS_IS_OK(status)) {
printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
FILE_OPEN, 0, 0, &fnum2);
if (NT_STATUS_IS_OK(status)) {
printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
- correct = False;
goto fail;
- } else
- printf("fourth delete on close test succeeded.\n");
+ }
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[4] close - 2 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
+ printf("fourth delete on close test succeeded.\n");
+
/* Test 5 ... */
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
status = cli_openx(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (NT_STATUS_IS_OK(status)) {
printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[5] close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
if (!NT_STATUS_IS_OK(status)) {
printf("[6] open of %s failed (%s)\n", fname,
nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (NT_STATUS_IS_OK(status)) {
printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[6] close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
0, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (!NT_STATUS_IS_OK(status)) {
printf("[7] setting delete_on_close on file failed !\n");
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("[7] unsetting delete_on_close on file failed !\n");
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[7] close - 1 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[7] close - 2 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
printf("seventh delete on close test succeeded.\n");
- /* Test 7 ... */
+ /* Test 8 ... */
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
if (!torture_open_connection(&cli2, 1)) {
printf("[8] failed to open second connection.\n");
- correct = False;
goto fail;
}
FILE_OVERWRITE_IF, 0, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
FILE_OPEN, 0, 0, &fnum2);
if (!NT_STATUS_IS_OK(status)) {
printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_nt_delete_on_close(cli1, fnum1, true);
if (!NT_STATUS_IS_OK(status)) {
printf("[8] setting delete_on_close on file failed !\n");
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[8] close - 1 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli2, fnum2);
if (!NT_STATUS_IS_OK(status)) {
printf("[8] close - 2 failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
if (NT_STATUS_IS_OK(status)) {
printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
goto fail;
- correct = False;
- } else
- printf("eighth delete on close test succeeded.\n");
+ }
+
+ printf("eighth delete on close test succeeded.\n");
+
+ /* Test 9 ... */
/* This should fail - we need to set DELETE_ACCESS. */
status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
FILE_DELETE_ON_CLOSE, 0, &fnum1);
if (NT_STATUS_IS_OK(status)) {
printf("[9] open of %s succeeded should have failed!\n", fname);
- correct = False;
goto fail;
}
printf("ninth delete on close test succeeded.\n");
+ /* Test 10 ... */
+
status = cli_ntcreate(cli1, fname, 0,
FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[10] close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
if (NT_STATUS_IS_OK(status)) {
printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
goto fail;
- correct = False;
- } else
- printf("tenth delete on close test succeeded.\n");
+ }
+
+ printf("tenth delete on close test succeeded.\n");
+
+ /* Test 11 ... */
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
- /* What error do we get when attempting to open a read-only file with
- delete access ? */
+ /* Can we open a read-only file with delete access? */
/* Create a readonly file. */
status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
FILE_OVERWRITE_IF, 0, 0, &fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status));
- correct = False;
goto fail;
}
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("[11] close failed (%s)\n", nt_errstr(status));
- correct = False;
goto fail;
}
FILE_READ_ATTRIBUTES|DELETE_ACCESS,
0,
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
- FILE_OVERWRITE_IF, 0, 0, &fnum1);
+ FILE_OPEN, 0, 0, &fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[11] open of %s failed: %s\n", fname, nt_errstr(status));
+ goto fail;
+ }
+
+ cli_close(cli1, fnum1);
+
+ printf("eleventh delete on close test succeeded.\n");
+
+ /*
+ * Test 12
+ * like test 4 but with initial delete on close
+ */
+
+ cli_setatr(cli1, fname, 0, 0);
+ cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ status = cli_ntcreate(cli1, fname, 0,
+ FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OVERWRITE_IF,
+ FILE_DELETE_ON_CLOSE, 0, &fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] open 1 of %s failed (%s)\n", fname, nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN, 0, 0, &fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] open 2 of %s failed(%s).\n", fname, nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_close(cli1, fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] close 1 failed (%s)\n", nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_nt_delete_on_close(cli1, fnum1, true);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] setting delete_on_close failed (%s)\n", nt_errstr(status));
+ goto fail;
+ }
+
+ /* This should fail - no more opens once delete on close set. */
+ status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN, 0, 0, &fnum2);
if (NT_STATUS_IS_OK(status)) {
- printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
- cli_close(cli1, fnum1);
+ printf("[12] open 3 of %s succeeded - should fail).\n", fname);
goto fail;
- correct = False;
- } else {
- if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
- printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(status));
- goto fail;
- correct = False;
- } else {
- printf("eleventh delete on close test succeeded.\n");
- }
}
+ status = cli_nt_delete_on_close(cli1, fnum1, false);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] unsetting delete_on_close failed (%s)\n", nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN, 0, 0, &fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] open 4 of %s failed (%s)\n", fname, nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_close(cli1, fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] close 2 failed (%s)\n", nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_close(cli1, fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("[12] close 3 failed (%s)\n", nt_errstr(status));
+ goto fail;
+ }
+
+ /*
+ * setting delete on close on the handle does
+ * not unset the initial delete on close...
+ */
+ status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OPEN, 0, 0, &fnum2);
+ if (NT_STATUS_IS_OK(status)) {
+ printf("[12] open 5 of %s succeeded - should fail).\n", fname);
+ goto fail;
+ } else if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ printf("ntcreate returned %s, expected "
+ "NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ printf("twelfth delete on close test succeeded.\n");
+
+
printf("finished delete test\n");
+ correct = true;
+
fail:
/* FIXME: This will crash if we aborted before cli2 got
* intialized, because these functions don't handle
bool correct = false;
NTSTATUS status;
size_t nread;
+ const char *fname_windows = "windows_file";
+ uint16_t fnum2 = (uint16_t)-1;
printf("Starting simple POSIX open test\n");
cli_posix_unlink(cli1, hname);
cli_setatr(cli1, sname, 0, 0);
cli_posix_unlink(cli1, sname);
+ cli_setatr(cli1, fname_windows, 0, 0);
+ cli_posix_unlink(cli1, fname_windows);
/* Create a directory. */
status = cli_posix_mkdir(cli1, dname, 0777);
goto out;
}
+ /*
+ * Now create a Windows file, and attempt a POSIX unlink.
+ * This should fail with a sharing violation but due to:
+ *
+ * [Bug 9571] Unlink after open causes smbd to panic
+ *
+ * ensure we've fixed the lock ordering violation.
+ */
+
+ status = cli_ntcreate(cli1, fname_windows, 0,
+ FILE_READ_DATA|FILE_WRITE_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_CREATE,
+ 0x0, 0x0, &fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Windows create of %s failed (%s)\n", fname_windows,
+ nt_errstr(status));
+ goto out;
+ }
+
+ /* Now try posix_unlink. */
+ status = cli_posix_unlink(cli1, fname_windows);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
+ printf("POSIX unlink of %s should fail "
+ "with NT_STATUS_SHARING_VIOLATION "
+ "got %s instead !\n",
+ fname_windows,
+ nt_errstr(status));
+ goto out;
+ }
+
+ cli_close(cli1, fnum2);
+
printf("Simple POSIX open test passed\n");
correct = true;
fnum1 = (uint16_t)-1;
}
+ if (fnum2 != (uint16_t)-1) {
+ cli_close(cli1, fnum2);
+ fnum2 = (uint16_t)-1;
+ }
+
cli_setatr(cli1, sname, 0, 0);
cli_posix_unlink(cli1, sname);
cli_setatr(cli1, hname, 0, 0);
cli_posix_unlink(cli1, fname);
cli_setatr(cli1, dname, 0, 0);
cli_posix_rmdir(cli1, dname);
+ cli_setatr(cli1, fname_windows, 0, 0);
+ cli_posix_unlink(cli1, fname_windows);
if (!torture_close_connection(cli1)) {
correct = false;
static bool run_chain1(int dummy)
{
struct cli_state *cli1;
- struct event_context *evt = event_context_init(NULL);
+ struct tevent_context *evt = samba_tevent_context_init(NULL);
struct tevent_req *reqs[3], *smbreqs[3];
bool done = false;
const char *str = "foobar";
static bool run_chain2(int dummy)
{
struct cli_state *cli1;
- struct event_context *evt = event_context_init(NULL);
+ struct tevent_context *evt = samba_tevent_context_init(NULL);
struct tevent_req *reqs[2], *smbreqs[2];
bool done = false;
NTSTATUS status;
num_unc_names = 1;
}
- ev = tevent_context_init(talloc_tos());
+ ev = samba_tevent_context_init(talloc_tos());
if (ev == NULL) {
d_printf("tevent_context_init failed\n");
return false;
return ret;
}
+static size_t calc_expected_return(struct cli_state *cli, size_t len_requested)
+{
+ size_t max_pdu = 0x1FFFF;
+
+ if (cli->server_posix_capabilities & CIFS_UNIX_LARGE_READ_CAP) {
+ max_pdu = 0xFFFFFF;
+ }
+
+ if (smb1cli_conn_signing_is_active(cli->conn)) {
+ max_pdu = 0x1FFFF;
+ }
+
+ if (smb1cli_conn_encryption_on(cli->conn)) {
+ max_pdu = CLI_BUFFER_SIZE;
+ }
+
+ if ((len_requested & 0xFFFF0000) == 0xFFFF0000) {
+ len_requested &= 0xFFFF;
+ }
+
+ return MIN(len_requested, max_pdu - (MIN_SMB_SIZE + VWV(12)));
+}
+
+static bool check_read_call(struct cli_state *cli,
+ uint16_t fnum,
+ uint8_t *buf,
+ size_t len_requested)
+{
+ NTSTATUS status;
+ struct tevent_req *subreq = NULL;
+ ssize_t len_read = 0;
+ size_t len_expected = 0;
+ struct tevent_context *ev = NULL;
+
+ ev = samba_tevent_context_init(talloc_tos());
+ if (ev == NULL) {
+ return false;
+ }
+
+ subreq = cli_read_andx_send(talloc_tos(),
+ ev,
+ cli,
+ fnum,
+ 0,
+ len_requested);
+
+ if (!tevent_req_poll_ntstatus(subreq, ev, &status)) {
+ return false;
+ }
+
+ status = cli_read_andx_recv(subreq, &len_read, &buf);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_read_andx_recv failed: %s\n", nt_errstr(status));
+ return false;
+ }
+
+ TALLOC_FREE(subreq);
+ TALLOC_FREE(ev);
+
+ len_expected = calc_expected_return(cli, len_requested);
+
+ if (len_expected > 0x10000 && len_read == 0x10000) {
+ /* Windows servers only return a max of 0x10000,
+ doesn't matter if you set CAP_LARGE_READX in
+ the client sessionsetupX call or not. */
+ d_printf("Windows server - returned 0x10000 on a read of 0x%x\n",
+ (unsigned int)len_requested);
+ } else if (len_read != len_expected) {
+ d_printf("read of 0x%x failed: got 0x%x, expected 0x%x\n",
+ (unsigned int)len_requested,
+ (unsigned int)len_read,
+ (unsigned int)len_expected);
+ return false;
+ } else {
+ d_printf("Correct read reply.\n");
+ }
+
+ return true;
+}
+
+/* Test large readX variants. */
+static bool large_readx_tests(struct cli_state *cli,
+ uint16_t fnum,
+ uint8_t *buf)
+{
+ /* A read of 0xFFFF0001 should *always* return 1 byte. */
+ if (check_read_call(cli, fnum, buf, 0xFFFF0001) == false) {
+ return false;
+ }
+ /* A read of 0x10000 should return 0x10000 bytes. */
+ if (check_read_call(cli, fnum, buf, 0x10000) == false) {
+ return false;
+ }
+ /* A read of 0x10000 should return 0x10001 bytes. */
+ if (check_read_call(cli, fnum, buf, 0x10001) == false) {
+ return false;
+ }
+ /* A read of 0x1FFFF - (MIN_SMB_SIZE + VWV(12) should return
+ the requested number of bytes. */
+ if (check_read_call(cli, fnum, buf, 0x1FFFF - (MIN_SMB_SIZE + VWV(12))) == false) {
+ return false;
+ }
+ /* A read of 1MB should return 1MB bytes (on Samba). */
+ if (check_read_call(cli, fnum, buf, 0x100000) == false) {
+ return false;
+ }
+
+ if (check_read_call(cli, fnum, buf, 0x20001) == false) {
+ return false;
+ }
+ if (check_read_call(cli, fnum, buf, 0x22000001) == false) {
+ return false;
+ }
+ if (check_read_call(cli, fnum, buf, 0xFFFE0001) == false) {
+ return false;
+ }
+ return true;
+}
+
+static bool run_large_readx(int dummy)
+{
+ uint8_t *buf = NULL;
+ struct cli_state *cli1 = NULL;
+ struct cli_state *cli2 = NULL;
+ bool correct = false;
+ const char *fname = "\\large_readx.dat";
+ NTSTATUS status;
+ uint16_t fnum1 = UINT16_MAX;
+ uint32_t normal_caps = 0;
+ size_t file_size = 20*1024*1024;
+ TALLOC_CTX *frame = talloc_stackframe();
+ size_t i;
+ struct {
+ const char *name;
+ enum smb_signing_setting signing_setting;
+ enum protocol_types protocol;
+ } runs[] = {
+ {
+ .name = "NT1",
+ .signing_setting = SMB_SIGNING_IF_REQUIRED,
+ .protocol = PROTOCOL_NT1,
+ },{
+ .name = "NT1 - SIGNING_REQUIRED",
+ .signing_setting = SMB_SIGNING_REQUIRED,
+ .protocol = PROTOCOL_NT1,
+ },
+ };
+
+ printf("starting large_readx test\n");
+
+ if (!torture_open_connection(&cli1, 0)) {
+ goto out;
+ }
+
+ normal_caps = smb1cli_conn_capabilities(cli1->conn);
+
+ if (!(normal_caps & CAP_LARGE_READX)) {
+ d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
+ (unsigned int)normal_caps);
+ goto out;
+ }
+
+ /* Create a file of size 4MB. */
+ status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,
+ FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,
+ 0, 0, &fnum1);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("open %s failed: %s\n", fname, nt_errstr(status));
+ goto out;
+ }
+
+ /* Write file_size bytes. */
+ buf = talloc_zero_array(frame, uint8_t, file_size);
+ if (buf == NULL) {
+ goto out;
+ }
+
+ 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_close(cli1, fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_close failed: %s\n", nt_errstr(status));
+ goto out;
+ }
+
+ fnum1 = UINT16_MAX;
+
+ for (i=0; i < ARRAY_SIZE(runs); i++) {
+ enum smb_signing_setting saved_signing_setting = signing_state;
+ uint16_t fnum2 = -1;
+
+ if (do_encrypt &&
+ (runs[i].signing_setting == SMB_SIGNING_REQUIRED))
+ {
+ d_printf("skip[%u] - %s\n", (unsigned)i, runs[i].name);
+ continue;
+ }
+
+ d_printf("run[%u] - %s\n", (unsigned)i, runs[i].name);
+
+ signing_state = runs[i].signing_setting;
+ cli2 = open_nbt_connection();
+ signing_state = saved_signing_setting;
+ if (cli2 == NULL) {
+ goto out;
+ }
+
+ status = smbXcli_negprot(cli2->conn,
+ cli2->timeout,
+ runs[i].protocol,
+ runs[i].protocol);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ status = cli_session_setup(cli2,
+ username,
+ password,
+ strlen(password)+1,
+ password,
+ strlen(password)+1,
+ workgroup);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ status = cli_tree_connect(cli2,
+ share,
+ "?????",
+ password,
+ strlen(password)+1);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ cli_set_timeout(cli2, 120000); /* set a really long timeout (2 minutes) */
+
+ normal_caps = smb1cli_conn_capabilities(cli2->conn);
+
+ if (!(normal_caps & CAP_LARGE_READX)) {
+ d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n",
+ (unsigned int)normal_caps);
+ goto out;
+ }
+
+ if (do_encrypt) {
+ if (force_cli_encryption(cli2, share) == false) {
+ goto out;
+ }
+ } else if (SERVER_HAS_UNIX_CIFS(cli2)) {
+ uint16_t major, minor;
+ uint32_t caplow, caphigh;
+
+ status = cli_unix_extensions_version(cli2,
+ &major, &minor,
+ &caplow, &caphigh);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+ }
+
+ status = cli_ntcreate(cli2, fname, 0, FILE_READ_DATA,
+ FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN,
+ 0, 0, &fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Second open %s failed: %s\n", fname, nt_errstr(status));
+ goto out;
+ }
+
+ /* All reads must return less than file_size bytes. */
+ if (!large_readx_tests(cli2, fnum2, buf)) {
+ goto out;
+ }
+
+ status = cli_close(cli2, fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_close failed: %s\n", nt_errstr(status));
+ goto out;
+ }
+ fnum2 = -1;
+
+ if (!torture_close_connection(cli2)) {
+ goto out;
+ }
+ cli2 = NULL;
+ }
+
+ correct = true;
+ printf("Success on large_readx test\n");
+
+ out:
+
+ if (cli2) {
+ if (!torture_close_connection(cli2)) {
+ correct = false;
+ }
+ }
+
+ if (cli1) {
+ if (fnum1 != UINT16_MAX) {
+ status = cli_close(cli1, fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("cli_close failed: %s\n", nt_errstr(status));
+ }
+ fnum1 = UINT16_MAX;
+ }
+
+ status = cli_unlink(cli1, fname,
+ FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("unlink failed (%s)\n", nt_errstr(status));
+ }
+
+ if (!torture_close_connection(cli1)) {
+ correct = false;
+ }
+ }
+
+ TALLOC_FREE(frame);
+
+ printf("finished large_readx test\n");
+ return correct;
+}
+
static bool run_cli_echo(int dummy)
{
struct cli_state *cli;
}
d_printf("defaultNamingContext: %s\n", basedn);
- ev = tevent_context_init(talloc_tos());
+ ev = samba_tevent_context_init(talloc_tos());
if (ev == NULL) {
d_printf("tevent_context_init failed\n");
return false;
printf("allowing S-1-5-32-545-abc\n");
return false;
}
+ if (string_to_sid(&sid, "S-300-5-32-545")) {
+ printf("allowing S-300-5-32-545\n");
+ return false;
+ }
+ if (string_to_sid(&sid, "S-1-0xfffffffffffffe-32-545")) {
+ printf("allowing S-1-0xfffffffffffffe-32-545\n");
+ return false;
+ }
+ if (string_to_sid(&sid, "S-1-0xffffffffffff-5294967297-545")) {
+ printf("allowing S-1-0xffffffffffff-5294967297-545\n");
+ return false;
+ }
+ if (!string_to_sid(&sid, "S-1-0xfffffffffffe-32-545")) {
+ printf("could not parse S-1-0xfffffffffffe-32-545\n");
+ return false;
+ }
if (!string_to_sid(&sid, "S-1-5-32-545")) {
printf("could not parse S-1-5-32-545\n");
return false;
return true;
}
+static bool sid_to_string_test(char *expected) {
+ char *str;
+ bool res = true;
+ struct dom_sid sid;
+
+ if (!string_to_sid(&sid, expected)) {
+ printf("could not parse %s\n", expected);
+ return false;
+ }
+
+ str = dom_sid_string(NULL, &sid);
+ if (strcmp(str, expected)) {
+ printf("Comparison failed (%s != %s)\n", str, expected);
+ res = false;
+ }
+ TALLOC_FREE(str);
+ return res;
+}
+
+static bool run_local_sid_to_string(int dummy) {
+ if (!sid_to_string_test("S-1-0xffffffffffff-1-1-1-1-1-1-1-1-1-1-1-1"))
+ return false;
+ if (!sid_to_string_test("S-1-545"))
+ return false;
+ if (!sid_to_string_test("S-255-3840-1-1-1-1"))
+ return false;
+ return true;
+}
+
static bool run_local_binary_to_sid(int dummy) {
struct dom_sid *sid = talloc(NULL, struct dom_sid);
static const char good_binary_sid[] = {
/*
* upper-case the type field
*/
- strupper_m(strchr_m(stream, ':')+1);
+ (void)strupper_m(strchr_m(stream, ':')+1);
}
done:
static bool run_local_wbclient(int dummy)
{
- struct event_context *ev;
+ struct tevent_context *ev;
struct wb_context **wb_ctx;
struct winbindd_request wb_req;
bool result = false;
struct tevent_req *reqs[4];
int i;
- ev = event_context_init(frame);
+ ev = samba_tevent_context_init(frame);
if (ev == NULL) {
goto fail;
}
return true;
}
+static bool run_local_tdb_opener(int dummy)
+{
+ TDB_CONTEXT *t;
+ unsigned v = 0;
+
+ while (1) {
+ t = tdb_open("test.tdb", 1000, TDB_CLEAR_IF_FIRST,
+ O_RDWR|O_CREAT, 0755);
+ if (t == NULL) {
+ perror("tdb_open failed");
+ return false;
+ }
+ tdb_close(t);
+
+ v += 1;
+ printf("\r%u", v);
+ }
+ return true;
+}
+
+static bool run_local_tdb_writer(int dummy)
+{
+ TDB_CONTEXT *t;
+ unsigned v = 0;
+ TDB_DATA val;
+
+ t = tdb_open("test.tdb", 1000, 0, O_RDWR|O_CREAT, 0755);
+ if (t == 0) {
+ perror("tdb_open failed");
+ return 1;
+ }
+
+ val.dptr = (uint8_t *)&v;
+ val.dsize = sizeof(v);
+
+ while (1) {
+ TDB_DATA data;
+ int ret;
+
+ ret = tdb_store(t, val, val, 0);
+ if (ret != 0) {
+ printf("%s\n", tdb_errorstr(t));
+ }
+ v += 1;
+ printf("\r%u", v);
+
+ data = tdb_fetch(t, val);
+ if (data.dptr != NULL) {
+ SAFE_FREE(data.dptr);
+ }
+ }
+ return true;
+}
+
static double create_procs(bool (*fn)(int), bool *result)
{
int i, status;
{ "CHAIN2", run_chain2, 0},
{ "CHAIN3", run_chain3, 0},
{ "WINDOWS-WRITE", run_windows_write, 0},
+ { "LARGE_READX", run_large_readx, 0},
{ "NTTRANS-CREATE", run_nttrans_create, 0},
{ "NTTRANS-FSCTL", run_nttrans_fsctl, 0},
{ "CLI_ECHO", run_cli_echo, 0},
{ "LOCAL-STREAM-NAME", run_local_stream_name, 0},
{ "LOCAL-WBCLIENT", run_local_wbclient, 0},
{ "LOCAL-string_to_sid", run_local_string_to_sid, 0},
+ { "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-hex_encode_buf", run_local_hex_encode_buf, 0},
{ "LOCAL-IDMAP-TDB-COMMON", run_idmap_tdb_common_test, 0},
{ "LOCAL-remove_duplicate_addrs2", run_local_remove_duplicate_addrs2, 0},
+ { "local-tdb-opener", run_local_tdb_opener, 0 },
+ { "local-tdb-writer", run_local_tdb_writer, 0 },
+ { "LOCAL-DBWRAP-CTDB", run_local_dbwrap_ctdb, 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"
setup_logging("smbtorture", DEBUG_STDOUT);
load_case_tables();
+ fault_setup();
if (is_default_dyn_CONFIGFILE()) {
if(getenv("SMB_CONF_PATH")) {
if(use_kerberos && !gotuser) gotpass = True;
while (!gotpass) {
- p = getpass("Password:");
- if (p) {
- fstrcpy(password, p);
+ char pwd[256] = {0};
+ int rc;
+
+ rc = samba_getpass("Password:", pwd, sizeof(pwd), false, false);
+ if (rc == 0) {
+ fstrcpy(password, pwd);
gotpass = 1;
}
}