#include "lib/util/asn1.h"
#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>
flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS;
}
- if (use_kerberos) {
- flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
- }
-
if (force_dos_errors) {
flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS;
}
sharename,
"?????",
torture_creds,
- flags,
- signing_state);
+ flags);
if (!NT_STATUS_IS_OK(status)) {
printf("failed to open share connection: //%s/%s port:%d - %s\n",
hostname, sharename, port_to_use, nt_errstr(status));
return ret;
}
+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,
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)
{
correct = False;
}
-#if 0
- /* ToDo - set allocation. JRA */
- if(!cli_set_allocation_size(cli1, fnum1, 0)) {
- printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
- return False;
- }
- if (!cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL,
- NULL, NULL)) {
- printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
- correct = False;
- }
- if (fsize != 0)
- printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
-#endif
-
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("close failed (%s)\n", nt_errstr(status));
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;
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_share(cli, orig_tcon, orig_share);
cli_shutdown(cli);
return False;
}
status = cli_close(cli, fnum1);
if (!NT_STATUS_IS_OK(status)) {
printf("close failed (%s)\n", nt_errstr(status));
+ cli_state_restore_tcon_share(cli, orig_tcon, orig_share);
+ cli_shutdown(cli);
return False;
}
status = cli_tdis(cli);
if (!NT_STATUS_IS_OK(status)) {
printf("secondary tdis failed (%s)\n", nt_errstr(status));
+ 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);
NULL, /* service */
NULL, /* service_type */
torture_creds,
- flags,
- signing_state);
+ flags);
if (!NT_STATUS_IS_OK(status)) {
printf("could not open connection\n");
static void alarm_handler_parent(int dummy)
{
- smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_OK);
+ smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_LOCAL_DISCONNECT);
}
-static void do_local_lock(int read_fd, int write_fd)
+static void do_local_lock(const char *fname, int read_fd, int write_fd)
{
int fd;
char c = '\0';
int ret;
local_pathname = talloc_asprintf(talloc_tos(),
- "%s/lockt9.lck", local_path);
+ "%s/%s", local_path, fname);
if (!local_pathname) {
printf("child: alloc fail\n");
exit(1);
exit(0);
}
-static bool run_locktest9(int dummy)
+static bool _run_locktest9X(const char *fname, int timeout)
{
struct cli_state *cli1;
- const char *fname = "\\lockt9.lck";
+ char *fpath = talloc_asprintf(talloc_tos(), "\\%s", fname);
uint16_t fnum;
bool correct = False;
int pipe_in[2], pipe_out[2];
double seconds;
NTSTATUS status;
- printf("starting locktest9\n");
+ printf("starting locktest9X: %s\n", fname);
if (local_path == NULL) {
- d_fprintf(stderr, "locktest9 must be given a local path via -l <localpath>\n");
+ d_fprintf(stderr, "locktest9X must be given a local path via -l <localpath>\n");
return false;
}
if (child_pid == 0) {
/* Child. */
- do_local_lock(pipe_out[0], pipe_in[1]);
+ do_local_lock(fname, pipe_out[0], pipe_in[1]);
exit(0);
}
smbXcli_conn_set_sockopt(cli1->conn, sockops);
- status = cli_openx(cli1, fname, O_RDWR, DENY_NONE,
+ status = cli_openx(cli1, fpath, O_RDWR, DENY_NONE,
&fnum);
if (!NT_STATUS_IS_OK(status)) {
d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status));
start = timeval_current();
- status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK);
+ status = cli_lock32(cli1, fnum, 0, 4, timeout, WRITE_LOCK);
if (!NT_STATUS_IS_OK(status)) {
d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was "
"%s\n", nt_errstr(status));
fail_nofd:
- printf("finished locktest9\n");
+ printf("finished locktest9X: %s\n", fname);
return correct;
}
+static bool run_locktest9a(int dummy)
+{
+ return _run_locktest9X("lock9a.dat", -1);
+}
+
+static bool run_locktest9b(int dummy)
+{
+ return _run_locktest9X("lock9b.dat", 10000);
+}
+
struct locktest10_state {
bool ok;
bool done;
ret = true;
done:
- torture_close_connection(cli);
+ if (cli != NULL) {
+ torture_close_connection(cli);
+ }
return ret;
}
ret = true;
done:
- torture_close_connection(cli);
+ if (cli != NULL) {
+ torture_close_connection(cli);
+ }
return ret;
}
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;
static bool check_attributes(struct cli_state *cli,
const char *fname,
- uint16_t expected_attrs)
+ uint32_t expected_attrs)
{
- uint16_t attrs = 0;
+ uint32_t attrs = 0;
NTSTATUS status = cli_getatr(cli,
fname,
&attrs,
return False;
}
+ /* Ensure we can't unlink with out-of-range (unknown) attribute. */
+ status = cli_unlink(cli, fname, 0x20000);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
+ correct = false;
+ goto out;
+ }
+
cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_openx(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
t2 = t-60*60*24; /* 1 day ago */
+ /* Ensure we can't set with out-of-range (unknown) attribute. */
+ status = cli_setatr(cli, fname, 0x20000, t2);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
+ correct = false;
+ goto out;
+ }
+
status = cli_setatr(cli, fname, 0, t2);
if (!NT_STATUS_IS_OK(status)) {
printf("setatr failed (%s)\n", nt_errstr(status));
cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
- /* Check cli_setpathinfo_basic() */
+ /* Check cli_setpathinfo_ext() */
/* Re-create the file. */
status = cli_openx(cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
}
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",
+ status = cli_setpathinfo_ext(
+ cli,
+ fname,
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* create */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* access */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* write */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* change */
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_HIDDEN |
+ FILE_ATTRIBUTE_READONLY);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_setpathinfo_ext failed with %s\n",
nt_errstr(status));
correct = false;
}
}
/* 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",
+ status = cli_setpathinfo_ext(
+ cli,
+ fname,
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* create */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* access */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* write */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* change */
+ FILE_ATTRIBUTE_NORMAL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_setpathinfo_ext failed with %s\n",
nt_errstr(status));
correct = false;
}
}
/* 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",
+ status = cli_setpathinfo_ext(
+ cli,
+ fname,
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* create */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* access */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* write */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* change */
+ (uint32_t)-1);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_setpathinfo_ext failed with %s\n",
nt_errstr(status));
correct = false;
}
}
/* 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",
+ status = cli_setpathinfo_ext(
+ cli,
+ fname,
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* create */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* access */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* write */
+ (struct timespec) { .tv_nsec = SAMBA_UTIME_OMIT }, /* change */
+ 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_setpathinfo_ext failed with %s\n",
nt_errstr(status));
correct = false;
}
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
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;
+ uint64_t ino;
printf("starting trans2 test\n");
return False;
}
+ if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ /* Ensure ino is zero, SMB2 gets a real one. */
+ ino = 0;
+ } else {
+ /* Ensure ino is -1, SMB1 never gets a real one. */
+ ino = (uint64_t)-1;
+ }
+
status = cli_get_fs_attr_info(cli, &fs_attr);
if (!NT_STATUS_IS_OK(status)) {
printf("ERROR: cli_get_fs_attr_info returned %s\n",
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
cli_close(cli, fnum);
status = cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
- &m_time_ts, &size, NULL, NULL);
+ &m_time_ts, &size, NULL, &ino);
if (!NT_STATUS_IS_OK(status)) {
printf("ERROR: qpathinfo2 failed (%s)\n", nt_errstr(status));
correct = False;
printf("This system appears to set a initial 0 write time\n");
correct = False;
}
+ if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ /* SMB2 should always return an inode. */
+ if (ino == 0) {
+ printf("SMB2 bad inode (0)\n");
+ correct = false;
+ }
+ } else {
+ /* SMB1 must always return zero here. */
+ if (ino != 0) {
+ printf("SMB1 bad inode (!0)\n");
+ correct = false;
+ }
+ }
}
cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
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);
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");
+struct delete_stream_state {
+ bool closed;
+};
- if (!torture_open_connection(&cli1, 0)) {
- return false;
- }
+static void delete_stream_unlinked(struct tevent_req *subreq);
+static void delete_stream_closed(struct tevent_req *subreq);
- smbXcli_conn_set_sockopt(cli1->conn, sockops);
+static struct tevent_req *delete_stream_send(
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct cli_state *cli,
+ const char *base_fname,
+ uint16_t stream_fnum)
+{
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct delete_stream_state *state = NULL;
- 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;
+ req = tevent_req_create(
+ mem_ctx, &state, struct delete_stream_state);
+ if (req == NULL) {
+ return NULL;
}
- 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;
+ subreq = cli_unlink_send(
+ state,
+ ev,
+ cli,
+ base_fname,
+ FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
}
+ tevent_req_set_callback(subreq, delete_stream_unlinked, req);
- 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;
+ subreq = cli_close_send(state, ev, cli, stream_fnum);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
}
+ tevent_req_set_callback(subreq, delete_stream_closed, req);
- status = cli_close(cli1, fnum1);
- if (!NT_STATUS_IS_OK(status)) {
- printf("close failed (%s)\n", nt_errstr(status));
- goto fail;
- }
+ return req;
+}
- printf("finished print delete test\n");
+static void delete_stream_unlinked(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct delete_stream_state *state = tevent_req_data(
+ req, struct delete_stream_state);
+ NTSTATUS status;
- correct = true;
+ status = cli_unlink_recv(subreq);
+ TALLOC_FREE(subreq);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
+ printf("cli_unlink returned %s\n",
+ nt_errstr(status));
+ tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
+ return;
+ }
+ if (!state->closed) {
+ /* close reply should have come in first */
+ printf("Not closed\n");
+ tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
+ return;
+ }
+ tevent_req_done(req);
+}
- fail:
+static void delete_stream_closed(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct delete_stream_state *state = tevent_req_data(
+ req, struct delete_stream_state);
+ NTSTATUS status;
- if (fnum1 != (uint16_t)-1) {
- cli_close(cli1, fnum1);
+ status = cli_close_recv(subreq);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
}
+ /* also waiting for the unlink to come back */
+ state->closed = true;
+}
- if (cli1 && !torture_close_connection(cli1)) {
- correct = false;
- }
- return correct;
+static NTSTATUS delete_stream_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
}
-/*
- Test wildcard delete.
- */
-static bool run_wild_deletetest(int dummy)
+static bool run_delete_stream(int dummy)
{
+ struct tevent_context *ev = NULL;
+ struct tevent_req *req = NULL;
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;
+ const char fname[] = "delete_stream";
+ const char fname_stream[] = "delete_stream:Zone.Identifier:$DATA";
+ uint16_t fnum1, fnum2;
NTSTATUS status;
+ bool ok;
- printf("starting wildcard delete test\n");
+ printf("Starting stream delete test\n");
- if (!torture_open_connection(&cli, 0)) {
+ ok = torture_open_connection(&cli, 0);
+ if (!ok) {
return false;
}
- smbXcli_conn_set_sockopt(cli->conn, sockops);
+ cli_setatr(cli, fname, 0, 0);
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
- 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;
+ /* Create the file. */
+ status = cli_ntcreate(
+ cli,
+ fname,
+ 0,
+ READ_CONTROL_ACCESS,
+ 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_CREATE,
+ 0x0,
+ 0x0,
+ &fnum1,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "cli_ntcreate of %s failed (%s)\n",
+ fname,
+ nt_errstr(status));
+ return false;
+ }
+ status = cli_close(cli, fnum1);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "cli_close of %s failed (%s)\n",
+ fname,
+ nt_errstr(status));
+ return false;
+ }
+
+ /* Now create the stream. */
+ status = cli_ntcreate(
+ cli,
+ fname_stream,
+ 0,
+ FILE_WRITE_DATA,
+ 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_CREATE,
+ 0x0,
+ 0x0,
+ &fnum1,
+ NULL);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "cli_ntcreate of %s failed (%s)\n",
+ fname_stream,
+ nt_errstr(status));
+ return false;
+ }
+
+ /* open it a second time */
+
+ status = cli_ntcreate(
+ cli,
+ fname_stream,
+ 0,
+ FILE_WRITE_DATA,
+ 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN,
+ 0x0,
+ 0x0,
+ &fnum2,
+ NULL);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "2nd cli_ntcreate of %s failed (%s)\n",
+ fname_stream,
+ nt_errstr(status));
+ return false;
+ }
+
+ ev = samba_tevent_context_init(talloc_tos());
+ if (ev == NULL) {
+ d_fprintf(stderr, "samba_tevent_context_init failed\n");
+ return false;
+ }
+
+ req = delete_stream_send(ev, ev, cli, fname, fnum1);
+ if (req == NULL) {
+ d_fprintf(stderr, "delete_stream_send failed\n");
+ return false;
+ }
+
+ ok = tevent_req_poll_ntstatus(req, ev, &status);
+ if (!ok) {
+ d_fprintf(stderr,
+ "tevent_req_poll_ntstatus failed: %s\n",
+ nt_errstr(status));
+ return false;
+ }
+
+ status = delete_stream_recv(req);
+ TALLOC_FREE(req);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "delete_stream failed: %s\n",
+ nt_errstr(status));
+ return false;
+ }
+
+ status = cli_close(cli, fnum2);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "close failed: %s\n",
+ nt_errstr(status));
+ return false;
+ }
+
+ status = cli_unlink(
+ cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr,
+ "unlink failed: %s\n",
+ nt_errstr(status));
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ 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;
}
- status = cli_openx(cli, fname, O_CREAT|O_RDONLY, DENY_NONE, &fnum1);
+
+ 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));
+ 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_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_unlink(cli, wunlink_name, 0);
+ status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
- printf("unlink of %s failed %s!\n",
- wunlink_name, nt_errstr(status));
+ printf("close failed (%s)\n", nt_errstr(status));
goto fail;
}
- printf("finished wildcard delete test\n");
+ printf("finished print 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 (fnum1 != (uint16_t)-1) {
+ cli_close(cli1, fnum1);
+ }
- if (cli && !torture_close_connection(cli)) {
+ if (cli1 && !torture_close_connection(cli1)) {
correct = false;
}
return correct;
const char *fname1 = "\\test1.txt";
bool correct = True;
uint16_t fnum1;
- uint16_t attr;
+ uint32_t attr;
NTSTATUS status;
printf("starting rename test\n");
}
-#if 0
- {
- uint16_t fnum2;
-
- if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
- printf("Fourth open failed - %s\n", cli_errstr(cli1));
- return False;
- }
- if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum2, true))) {
- printf("[8] setting delete_on_close on file failed !\n");
- return False;
- }
-
- if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {
- printf("close - 4 failed (%s)\n", cli_errstr(cli1));
- return False;
- }
- }
-#endif
-
status = cli_rename(cli1, fname, fname1, false);
if (!NT_STATUS_IS_OK(status)) {
printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status));
printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status));
}
- /*
- * Now check if the first name still exists ...
- */
-
- /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
- FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) {
- printf("Opening original file after rename of open file fails: %s\n",
- cli_errstr(cli1));
- }
- else {
- printf("Opening original file after rename of open file works ...\n");
- (void)cli_close(cli1, fnum2);
- } */
-
/*--*/
status = cli_close(cli1, fnum1);
if (!NT_STATUS_IS_OK(status)) {
return false;
}
+/*
+ * Test SMB1-specific open with SEC_FLAG_SYSTEM_SECURITY.
+ * Note this test only works with a user with SeSecurityPrivilege set.
+ *
+ * NB. This is also tested in samba3.base.createx_access
+ * but this makes it very explicit what we're looking for.
+ */
+static bool run_smb1_system_security(int dummy)
+{
+ static struct cli_state *cli = NULL;
+ const char *fname = "system_security.txt";
+ uint16_t fnum = (uint16_t)-1;
+ NTSTATUS status;
+ TALLOC_CTX *frame = NULL;
+
+ frame = talloc_stackframe();
+ printf("starting smb1 system security test\n");
+
+ /* SMB1 connection - torture_open_connection() forces this. */
+ if (!torture_open_connection(&cli, 0)) {
+ goto fail;
+ }
+
+ smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+ /* Start with a clean slate. */
+ cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ /* Create the test file. */
+ status = cli_ntcreate(cli,
+ fname,
+ 0,
+ GENERIC_ALL_ACCESS,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|
+ FILE_SHARE_DELETE,
+ FILE_CREATE,
+ 0,
+ 0,
+ &fnum,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Create of %s - %s\n", fname, nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_close(cli, fnum);
+
+ /* Open with SEC_FLAG_SYSTEM_SECURITY only. */
+ /*
+ * On SMB1 this succeeds - SMB2 it fails,
+ * see the SMB2-SACL test.
+ */
+ status = cli_ntcreate(cli,
+ fname,
+ 0,
+ SEC_FLAG_SYSTEM_SECURITY,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|
+ FILE_SHARE_DELETE,
+ FILE_OPEN,
+ 0,
+ 0,
+ &fnum,
+ NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Open of %s - %s\n", fname, nt_errstr(status));
+ goto fail;
+ }
+
+ status = cli_close(cli, fnum);
+
+ cli_unlink(cli, fname,
+ FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+ torture_close_connection(cli);
+ TALLOC_FREE(frame);
+ return true;
+
+ fail:
+
+ if (cli) {
+ if (fnum != (uint16_t)-1) {
+ cli_close(cli, fnum);
+ }
+ cli_unlink(cli, fname,
+ FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+ torture_close_connection(cli);
+ }
+
+ TALLOC_FREE(frame);
+ return false;
+}
+
static bool run_pipe_number(int dummy)
{
struct cli_state *cli1;
size_t nread;
const char *fname_windows = "windows_file";
uint16_t fnum2 = (uint16_t)-1;
+ bool ok;
printf("Starting simple POSIX open test\n");
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;
char *posix_acl_sym = NULL;
size_t posix_acl_len_sym = 0;
struct security_descriptor *sd = NULL;
- struct security_descriptor *sd_sym = NULL;
TALLOC_CTX *frame = NULL;
frame = talloc_stackframe();
goto out;
}
- /* Open a handle on the symlink. */
+ /* Try a stat-open on the symlink, should also fail. */
status = cli_ntcreate(cli,
sname,
0,
&fnum,
NULL);
- if (!NT_STATUS_IS_OK(status)) {
- printf("cli_posix_open of %s failed (%s)\n",
- sname,
- nt_errstr(status));
+ if (NT_STATUS_IS_OK(status)) {
+ printf("Stat-open of symlink succeeded (should fail)\n");
goto out;
}
- /* Get the Windows ACL on the symlink handle. Should fail */
- status = cli_query_secdesc(cli,
- fnum,
+ /* Get the POSIX ACL on the symlink pathname. Should fail. */
+ status = cli_posix_getacl(cli,
+ sname,
frame,
- &sd_sym);
+ &posix_acl_len_sym,
+ &posix_acl_sym);
if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
- printf("cli_query_secdesc on a symlink gave %s. "
- "Should be NT_STATUS_ACCESS_DENIED.\n",
- nt_errstr(status));
- goto out;
- }
-
- /* Get the POSIX ACL on the symlink pathname. Should fail. */
- status = cli_posix_getacl(cli,
- sname,
- frame,
- &posix_acl_len_sym,
- &posix_acl_sym);
-
- if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
- printf("cli_posix_getacl on a symlink gave %s. "
- "Should be NT_STATUS_ACCESS_DENIED.\n",
- nt_errstr(status));
- goto out;
- }
-
- /* Set the Windows ACL on the symlink handle. Should fail */
- status = cli_set_security_descriptor(cli,
- fnum,
- SECINFO_DACL,
- sd);
-
- if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
- printf("cli_query_secdesc on a symlink gave %s. "
+ printf("cli_posix_getacl on a symlink gave %s. "
"Should be NT_STATUS_ACCESS_DENIED.\n",
nt_errstr(status));
goto out;
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);
const char *fname = "\\openattr.file";
uint16_t fnum1;
bool correct = True;
- uint16_t attr;
+ uint32_t attr;
unsigned int i, j, k, l;
NTSTATUS status;
return correct;
}
-static NTSTATUS list_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS list_fn(struct file_info *finfo,
const char *name, void *state)
{
int *matched = (int *)state;
return correct;
}
-static NTSTATUS del_fn(const char *mnt, struct file_info *finfo, const char *mask,
+static NTSTATUS del_fn(struct file_info *finfo, const char *mask,
void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
return NT_STATUS_OK;
- if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
+ if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
if (!NT_STATUS_IS_OK(cli_rmdir(pcli, fname)))
printf("del_fn: failed to rmdir %s\n,", fname );
} else {
}
+/*
+ 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
*/
/*
- tries varients of chkpath
+ tries variants of chkpath
*/
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)) {
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;
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;
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)) {
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)) {
}
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);
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);
}
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);
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)){
uint16_t fnum;
fstring alt_name;
NTSTATUS status;
- time_t change_time, access_time, write_time;
- off_t size;
- uint16_t mode;
printf("starting mangle1 test\n");
if (!torture_open_connection(&cli, 0)) {
}
cli_close(cli, fnum);
- status = cli_qpathinfo1(cli, alt_name, &change_time, &access_time,
- &write_time, &size, &mode);
+ 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));
return true;
}
-static NTSTATUS mangle_illegal_list_shortname_fn(const char *mntpoint,
- struct file_info *f,
+static NTSTATUS mangle_illegal_list_shortname_fn(struct file_info *f,
const char *mask,
void *state)
{
return NT_STATUS_OBJECT_NAME_INVALID;
}
-static NTSTATUS mangle_illegal_list_name_fn(const char *mntpoint,
- struct file_info *f,
+static NTSTATUS mangle_illegal_list_name_fn(struct file_info *f,
const char *mask,
void *state)
{
return correct;
}
+static NTSTATUS msdfs_attribute_list_fn(struct file_info *finfo,
+ const char *mask,
+ void *private_data)
+{
+ uint32_t *p_attr = (uint32_t *)private_data;
+
+ if (strequal(finfo->name, test_filename)) {
+ *p_attr = finfo->attr;
+ }
+
+ return NT_STATUS_OK;
+}
+
+static bool run_msdfs_attribute(int dummy)
+{
+ static struct cli_state *cli;
+ bool correct = false;
+ uint32_t attr = 0;
+ NTSTATUS status;
+
+ printf("Starting MSDFS-ATTRIBUTE test\n");
+
+ if (test_filename == NULL || test_filename[0] == '\0') {
+ printf("MSDFS-ATTRIBUTE test "
+ "needs -f filename-of-msdfs-link\n");
+ return false;
+ }
+
+ /*
+ * NB. We use torture_open_connection_flags() not
+ * torture_open_connection() as the latter forces
+ * SMB1.
+ */
+ if (!torture_open_connection_flags(&cli, 0, 0)) {
+ return false;
+ }
+
+ smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+ status = cli_list(cli,
+ "*",
+ FILE_ATTRIBUTE_DIRECTORY,
+ msdfs_attribute_list_fn,
+ &attr);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_list failed with %s\n",
+ nt_errstr(status));
+ goto out;
+ }
+ if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) == 0) {
+ printf("file %s should have "
+ "FILE_ATTRIBUTE_REPARSE_POINT set. attr = 0x%x\n",
+ test_filename,
+ (unsigned int)attr);
+ goto out;
+ }
+
+ if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
+ printf("file %s should have "
+ "FILE_ATTRIBUTE_DIRECTORY set. attr = 0x%x\n",
+ test_filename,
+ (unsigned int)attr);
+ goto out;
+ }
+
+ correct = true;
+
+ out:
+
+ torture_close_connection(cli);
+ return correct;
+}
+
static bool run_cli_echo(int dummy)
{
struct cli_state *cli;
int16_t old_vuid;
int32_t old_cnum;
bool correct = True;
- struct smbXcli_tcon *orig_tcon = NULL;
+ struct smbXcli_tcon *tcon_copy = NULL;
NTSTATUS status;
printf("starting uid regression test\n");
}
old_cnum = cli_state_get_tid(cli);
- orig_tcon = cli_state_save_tcon(cli);
- if (orig_tcon == NULL) {
+ /*
+ * This is an SMB1-only test.
+ * Copy the tcon, not "save/restore".
+ *
+ * In SMB1 the cli_tdis() below frees
+ * cli->smb1.tcon so we need a copy
+ * of the struct to put back for the
+ * second tdis call with invalid vuid.
+ *
+ * This is a test-only hack. Real client code
+ * uses cli_state_save_tcon_share()/cli_state_restore_tcon_share().
+ */
+ tcon_copy = smbXcli_tcon_copy(cli, cli->smb1.tcon);
+ if (tcon_copy == NULL) {
correct = false;
goto out;
}
} else {
d_printf("First tdis failed (%s)\n", nt_errstr(status));
correct = false;
- cli_state_restore_tcon(cli, orig_tcon);
+ cli->smb1.tcon = tcon_copy;
goto out;
}
- cli_state_restore_tcon(cli, orig_tcon);
+ cli->smb1.tcon = tcon_copy;
cli_state_set_uid(cli, old_vuid);
cli_state_set_tid(cli, old_cnum);
static const char *illegal_chars = "*\\/?<>|\":";
static char force_shortname_chars[] = " +,.[];=\177";
-static NTSTATUS shortname_del_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS shortname_del_fn(struct file_info *finfo,
const char *mask, void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
return NT_STATUS_OK;
- if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
+ if (finfo->attr & FILE_ATTRIBUTE_DIRECTORY) {
status = cli_rmdir(pcli, fname);
if (!NT_STATUS_IS_OK(status)) {
printf("del_fn: failed to rmdir %s\n,", fname );
bool val;
};
-static NTSTATUS shortname_list_fn(const char *mnt, struct file_info *finfo,
+static NTSTATUS shortname_list_fn(struct file_info *finfo,
const char *name, void *state)
{
struct sn_state *s = (struct sn_state *)state;
ZERO_STRUCT(empty_control);
if (val != EXTENDED_NONE) {
- data = asn1_init(talloc_tos());
+ data = asn1_init(talloc_tos(), ASN1_MAX_TREE_DEPTH);
if (!data) {
return NULL;
struct timespec create_time1;
uint16_t fnum;
bool ret = false;
+ uint64_t ino;
if (!torture_open_connection(&cli, 0)) {
return false;
}
+ if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ /* Ensure ino is zero, SMB2 gets a real one. */
+ ino = 0;
+ } else {
+ /* Ensure ino is -1, SMB1 never gets a real one. */
+ ino = (uint64_t)-1;
+ }
+
cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
cli_rmdir(cli, dname);
}
status = cli_qpathinfo2(cli, dname, &create_time, NULL, NULL, NULL,
- NULL, NULL, NULL);
+ NULL, NULL, &ino);
if (!NT_STATUS_IS_OK(status)) {
printf("cli_qpathinfo2 returned %s\n",
nt_errstr(status));
goto out;
}
+ if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+ /* SMB2 should always return an inode. */
+ if (ino == 0) {
+ printf("SMB2 bad inode (0)\n");
+ goto out;
+ }
+ } else {
+ /* SMB1 must always return zero here. */
+ if (ino != 0) {
+ printf("SMB1 bad inode (!0)\n");
+ goto out;
+ }
+ }
+
/* Sleep 3 seconds, then create a file. */
sleep(3);
NTSTATUS status;
time_t change_time, access_time, write_time;
off_t size;
- uint16_t mode, fnum;
+ uint16_t fnum;
+ uint32_t attr;
bool ret = true;
if (!torture_open_connection(&cli, 0)) {
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)) {
}
status = cli_qpathinfo1(cli, streamname, &change_time, &access_time,
- &write_time, &size, &mode);
+ &write_time, &size, &attr);
if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
printf("pathinfo returned %s, expected "
"NT_STATUS_OBJECT_NAME_NOT_FOUND\n",
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)
+static NTSTATUS smb1_wild_mangle_list_fn(struct file_info *finfo,
+ const char *name,
+ void *state)
{
- 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);
+ char **mangled_name_return = (char **)state;
+ bool is_mangled = strchr(finfo->name, '~');
- env_tz = getenv("TZ");
- if(env_tz) {
- orig_tz = talloc_strdup(ctx, env_tz);
+ if (is_mangled) {
+ *mangled_name_return = talloc_strdup(NULL, finfo->name);
+ if (*mangled_name_return == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
}
- setenv("TZ", "UTC", 1);
+ return NT_STATUS_OK;
+}
- s = minimal_timeval_string(ctx, &tv, false);
+static bool run_smb1_wild_mangle_unlink_test(int dummy)
+{
+ static struct cli_state *cli_posix = NULL;
+ static struct cli_state *cli = NULL;
+ uint16_t fnum = (uint16_t)-1;
+ bool correct = false;
+ const char *dname = "smb1_wild_mangle_unlink";
+ const char *aname = "smb1_wild_mangle_unlink/a";
+ const char *star_name = "smb1_wild_mangle_unlink/*";
+ char *windows_unlink_name = NULL;
+ char *mangled_name = NULL;
+ NTSTATUS status;
- 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;
+ printf("Starting SMB1 wild mangle unlink test\n");
+
+ /* Open a Windows connection. */
+ if (!torture_open_connection(&cli, 0)) {
+ return false;
}
- TALLOC_FREE(s);
- if(orig_tz) {
- setenv("TZ", orig_tz, 1);
+ smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+ /* Open a POSIX connection. */
+ if (!torture_open_connection(&cli_posix, 0)) {
+ goto out;
}
- TALLOC_FREE(ctx);
- return result;
-}
+ smbXcli_conn_set_sockopt(cli_posix->conn, sockops);
-static bool run_local_substitute(int dummy)
-{
- bool ok = true;
+ status = torture_setup_unix_extensions(cli_posix);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("server doesn't support POSIX\n");
+ goto out;
+ }
- ok &= subst_test("%U", "bla", "", -1, -1, "bla");
- ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
- ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
- ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
- ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
- 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();
+ /* Start fresh. */
+ torture_deltree(cli, dname);
- /* Different captialization rules in sub_basic... */
+ /*
+ * Create two files - 'a' and '*'.
+ * We need POSIX extensions for this as '*'
+ * is not a valid Windows name.
+ */
- ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
- "blaDOM") == 0);
+ status = cli_mkdir(cli, dname);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_mkdir of %s returned %s\n",
+ dname,
+ nt_errstr(status));
+ goto out;
+ }
- return ok;
-}
+ status = cli_posix_open(cli_posix,
+ aname,
+ O_RDWR|O_CREAT|O_EXCL,
+ 0660,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_open (create) of %s returned %s\n",
+ aname,
+ nt_errstr(status));
+ goto out;
+ }
+ status = cli_close(cli_posix, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+ status = cli_posix_open(cli_posix,
+ star_name,
+ O_RDWR|O_CREAT|O_EXCL,
+ 0660,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_open (create) of %s returned %s\n",
+ star_name,
+ nt_errstr(status));
+ goto out;
+ }
+ status = cli_close(cli_posix, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
-static bool run_local_base64(int dummy)
-{
- int i;
- bool ret = true;
+ status = cli_list(cli,
+ star_name,
+ 0,
+ smb1_wild_mangle_list_fn,
+ &mangled_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_list of %s returned %s\n",
+ star_name,
+ nt_errstr(status));
+ goto out;
+ }
- for (i=1; i<2000; i++) {
- DATA_BLOB blob1, blob2;
- char *b64;
+ if (mangled_name == NULL) {
+ goto out;
+ }
- blob1.data = talloc_array(talloc_tos(), uint8_t, i);
- blob1.length = i;
- generate_random_buffer(blob1.data, blob1.length);
+ printf("mangled_name = %s\n",
+ mangled_name);
- b64 = base64_encode_data_blob(talloc_tos(), blob1);
- if (b64 == NULL) {
- d_fprintf(stderr, "base64_encode_data_blob failed "
- "for %d bytes\n", i);
- ret = false;
- }
- blob2 = base64_decode_data_blob(b64);
- TALLOC_FREE(b64);
+ /*
+ * Try a Windows unlink with the mangled name.
+ * This should *NOT* unlink the 'a' name.
+ */
- if (data_blob_cmp(&blob1, &blob2)) {
- d_fprintf(stderr, "data_blob_cmp failed for %d "
- "bytes\n", i);
- ret = false;
- }
- TALLOC_FREE(blob1.data);
- data_blob_free(&blob2);
+ windows_unlink_name = talloc_asprintf(cli_posix,
+ "%s\\%s",
+ dname,
+ mangled_name);
+
+ status = cli_unlink(cli, windows_unlink_name, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_unlink of %s returned %s\n",
+ windows_unlink_name,
+ nt_errstr(status));
+ goto out;
}
- return ret;
-}
-static void parse_fn(const struct gencache_timeout *t,
- DATA_BLOB blob,
- void *private_data)
-{
- return;
-}
+ /* Does 'a' still exist ? */
+ status = cli_posix_open(cli_posix,
+ aname,
+ O_RDONLY,
+ 0,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_open O_RNONLY of %s returned %s\n",
+ aname,
+ nt_errstr(status));
+ goto out;
+ }
+
+ status = cli_close(cli_posix, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ correct = true;
+
+ out:
+
+ TALLOC_FREE(windows_unlink_name);
+ TALLOC_FREE(mangled_name);
+
+ if (cli != NULL) {
+ torture_deltree(cli, dname);
+ torture_close_connection(cli);
+ }
+
+ if (cli_posix != NULL) {
+ torture_close_connection(cli_posix);
+ }
+
+ return correct;
+}
+
+static bool run_smb1_wild_mangle_rename_test(int dummy)
+{
+ static struct cli_state *cli_posix = NULL;
+ static struct cli_state *cli = NULL;
+ uint16_t fnum = (uint16_t)-1;
+ bool correct = false;
+ const char *dname = "smb1_wild_mangle_rename";
+ const char *fooname = "smb1_wild_mangle_rename/foo";
+ 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\\bar";
+ char *mangled_name = NULL;
+ NTSTATUS status;
+
+ printf("Starting SMB1 wild mangle rename test\n");
+
+ if (!torture_open_connection(&cli_posix, 0)) {
+ return false;
+ }
+
+ smbXcli_conn_set_sockopt(cli_posix->conn, sockops);
+
+ status = torture_setup_unix_extensions(cli_posix);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("server doesn't support POSIX\n");
+ return false;
+ }
+
+ /* Open a Windows connection. */
+ if (!torture_open_connection(&cli, 0)) {
+ goto out;
+ }
+
+ smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+ /* Ensure we start from fresh. */
+ torture_deltree(cli, dname);
+
+ /*
+ * Create two files - 'foo' and 'fo*'.
+ * We need POSIX extensions for this as 'fo*'
+ * is not a valid Windows name.
+ */
+
+ status = cli_posix_mkdir(cli_posix, dname, 0770);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_mkdir of %s returned %s\n",
+ dname,
+ nt_errstr(status));
+ goto out;
+ }
+
+ status = cli_posix_open(cli_posix,
+ fooname,
+ O_RDWR|O_CREAT|O_EXCL,
+ 0660,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_open (create) of %s returned %s\n",
+ fooname,
+ nt_errstr(status));
+ goto out;
+ }
+ status = cli_close(cli_posix, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+ status = cli_posix_open(cli_posix,
+ foostar_name,
+ O_RDWR|O_CREAT|O_EXCL,
+ 0660,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_open (create) of %s returned %s\n",
+ foostar_name,
+ nt_errstr(status));
+ goto out;
+ }
+ status = cli_close(cli_posix, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ /*
+ * Get the mangled name. We can re-use the
+ * previous smb1_wild_mangle_list_fn for this.
+ */
+
+ status = cli_list(cli,
+ wild_name,
+ 0,
+ smb1_wild_mangle_list_fn,
+ &mangled_name);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_list of %s returned %s\n",
+ wild_name,
+ nt_errstr(status));
+ goto out;
+ }
+
+ if (mangled_name == NULL) {
+ goto out;
+ }
+
+ printf("mangled_name = %s\n",
+ mangled_name);
+
+ /*
+ * Try a Windows rename with the mangled name.
+ * This should *NOT* rename the 'foo' name.
+ */
+
+ windows_rename_src = talloc_asprintf(cli_posix,
+ "%s\\%s",
+ dname,
+ mangled_name);
+
+ status = cli_rename(cli,
+ windows_rename_src,
+ windows_rename_dst,
+ false);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_rename of %s -> %s returned %s\n",
+ windows_rename_src,
+ windows_rename_dst,
+ nt_errstr(status));
+ goto out;
+ }
+
+ /* Does 'foo' still exist ? */
+ status = cli_posix_open(cli_posix,
+ fooname,
+ O_RDONLY,
+ 0,
+ &fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("cli_posix_open O_RNONLY of %s returned %s\n",
+ fooname,
+ nt_errstr(status));
+ goto out;
+ }
+
+ status = cli_close(cli_posix, fnum);
+ if (!NT_STATUS_IS_OK(status)) {
+ goto out;
+ }
+
+ correct = true;
+
+ out:
+
+ TALLOC_FREE(mangled_name);
+ TALLOC_FREE(windows_rename_src);
+
+ if (cli != NULL) {
+ torture_deltree(cli, dname);
+ torture_close_connection(cli);
+ }
+
+ torture_close_connection(cli_posix);
+
+ 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("%U", "bla", "", -1, -1, "bla");
+ ok &= subst_test("%u%U", "bla", "", -1, -1, "blabla");
+ ok &= subst_test("%g", "", "", -1, -1, "NO_GROUP");
+ ok &= subst_test("%G", "", "", -1, -1, "NO_GROUP");
+ ok &= subst_test("%g", "", "", -1, 0, gidtoname(0));
+ 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... */
+
+ ok &= (strcmp(talloc_sub_basic(talloc_tos(), "BLA", "dom", "%U%D"),
+ "blaDOM") == 0);
+
+ return ok;
+}
+
+static bool run_local_base64(int dummy)
+{
+ int i;
+ bool ret = true;
+
+ for (i=1; i<2000; i++) {
+ DATA_BLOB blob1, blob2;
+ char *b64;
+
+ blob1.data = talloc_array(talloc_tos(), uint8_t, i);
+ blob1.length = i;
+ generate_random_buffer(blob1.data, blob1.length);
+
+ b64 = base64_encode_data_blob(talloc_tos(), blob1);
+ if (b64 == NULL) {
+ d_fprintf(stderr, "base64_encode_data_blob failed "
+ "for %d bytes\n", i);
+ ret = false;
+ }
+ blob2 = base64_decode_data_blob(b64);
+ TALLOC_FREE(b64);
+
+ if (data_blob_cmp(&blob1, &blob2)) {
+ d_fprintf(stderr, "data_blob_cmp failed for %d "
+ "bytes\n", i);
+ ret = false;
+ }
+ TALLOC_FREE(blob1.data);
+ data_blob_free(&blob2);
+ }
+ return ret;
+}
+
+static void parse_fn(const struct gencache_timeout *t,
+ DATA_BLOB blob,
+ void *private_data)
+{
+ return;
+}
static bool run_local_gencache(int dummy)
{
return True;
}
-static bool rbt_testval(struct db_context *db, const char *key,
- const char *value)
+static bool rbt_testflags(struct db_context *db, const char *key,
+ const char *value)
{
- struct db_record *rec;
- TDB_DATA data = string_tdb_data(value);
bool ret = false;
NTSTATUS status;
- TDB_DATA dbvalue;
+ struct db_record *rec;
rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
if (rec == NULL) {
d_fprintf(stderr, "fetch_locked failed\n");
goto done;
}
- status = dbwrap_record_store(rec, data, 0);
+
+ status = dbwrap_record_store(rec, string_tdb_data(value), TDB_MODIFY);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ d_fprintf(stderr, "store TDB_MODIFY unexpected status: %s\n",
+ nt_errstr(status));
+ goto done;
+ }
+
+ status = dbwrap_record_store(rec, string_tdb_data("overwriteme"),
+ TDB_INSERT);
if (!NT_STATUS_IS_OK(status)) {
- d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
+ d_fprintf(stderr, "store TDB_INSERT failed: %s\n",
+ nt_errstr(status));
goto done;
}
- TALLOC_FREE(rec);
- rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
- if (rec == NULL) {
- d_fprintf(stderr, "second fetch_locked failed\n");
+ status = dbwrap_record_store(rec, string_tdb_data(value), TDB_INSERT);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+ d_fprintf(stderr, "store TDB_INSERT unexpected status: %s\n",
+ nt_errstr(status));
goto done;
}
- dbvalue = dbwrap_record_get_value(rec);
- if ((dbvalue.dsize != data.dsize)
- || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
- d_fprintf(stderr, "Got wrong data back\n");
+ status = dbwrap_record_store(rec, string_tdb_data(value), TDB_MODIFY);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "store TDB_MODIFY failed: %s\n",
+ nt_errstr(status));
goto done;
}
ret = true;
- done:
+done:
TALLOC_FREE(rec);
return ret;
}
-static int local_rbtree_traverse_read(struct db_record *rec, void *private_data)
-{
+static bool rbt_testval(struct db_context *db, const char *key,
+ const char *value)
+{
+ struct db_record *rec;
+ TDB_DATA data = string_tdb_data(value);
+ bool ret = false;
+ NTSTATUS status;
+ TDB_DATA dbvalue;
+
+ rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
+ if (rec == NULL) {
+ d_fprintf(stderr, "fetch_locked failed\n");
+ goto done;
+ }
+ status = dbwrap_record_store(rec, data, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "store failed: %s\n", nt_errstr(status));
+ goto done;
+ }
+ TALLOC_FREE(rec);
+
+ rec = dbwrap_fetch_locked(db, db, string_tdb_data(key));
+ if (rec == NULL) {
+ d_fprintf(stderr, "second fetch_locked failed\n");
+ goto done;
+ }
+
+ dbvalue = dbwrap_record_get_value(rec);
+ if ((dbvalue.dsize != data.dsize)
+ || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) {
+ d_fprintf(stderr, "Got wrong data back\n");
+ goto done;
+ }
+
+ ret = true;
+ done:
+ TALLOC_FREE(rec);
+ return ret;
+}
+
+static int local_rbtree_traverse_read(struct db_record *rec, void *private_data)
+{
int *count2 = (int *)private_data;
(*count2)++;
return 0;
return false;
}
- for (i=0; i<1000; i++) {
- char *key, *value;
+ if (!rbt_testflags(db, "firstkey", "firstval")) {
+ goto done;
+ }
- if (asprintf(&key, "key%ld", random()) == -1) {
- goto done;
- }
- if (asprintf(&value, "value%ld", random()) == -1) {
- SAFE_FREE(key);
- goto done;
- }
+ for (i = 0; i < 999; i++) {
+ char key[sizeof("key-9223372036854775807")];
+ char value[sizeof("value-9223372036854775807")];
+
+ snprintf(key, sizeof(key), "key%ld", random());
+ snprintf(value, sizeof(value) ,"value%ld", random());
if (!rbt_testval(db, key, value)) {
- SAFE_FREE(key);
- SAFE_FREE(value);
goto done;
}
- SAFE_FREE(value);
- if (asprintf(&value, "value%ld", random()) == -1) {
- SAFE_FREE(key);
- goto done;
- }
+ snprintf(value, sizeof(value) ,"value%ld", random());
if (!rbt_testval(db, key, value)) {
- SAFE_FREE(key);
- SAFE_FREE(value);
goto done;
}
-
- SAFE_FREE(key);
- SAFE_FREE(value);
}
ret = true;
{
char buf[17];
uint8_t src[8];
- int i;
+ size_t i;
for (i=0; i<sizeof(src); i++) {
src[i] = i;
static bool run_local_remove_duplicate_addrs2(int dummy)
{
- struct ip_service test_vector[28];
- int count, i;
+ struct samba_sockaddr test_vector[28];
+ size_t count, i;
/* Construct the sockaddr_storage test vector. */
for (i = 0; i < 28; i++) {
return false;
}
memset(&test_vector[i], '\0', sizeof(test_vector[i]));
- memcpy(&test_vector[i].ss,
+ memcpy(&test_vector[i].u.ss,
res->ai_addr,
res->ai_addrlen);
freeaddrinfo(res);
}
- count = remove_duplicate_addrs2(test_vector, i);
+ count = remove_duplicate_addrs2(test_vector, i);
+
+ if (count != 14) {
+ fprintf(stderr, "count wrong (%zu) should be 14\n",
+ count);
+ return false;
+ }
+
+ for (i = 0; i < count; i++) {
+ char addr[INET6_ADDRSTRLEN];
+
+ print_sockaddr(addr, sizeof(addr), &test_vector[i].u.ss);
+
+ if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) {
+ fprintf(stderr, "mismatch on [%zu] [%s] [%s]\n",
+ i,
+ addr,
+ remove_duplicate_addrs2_test_strings_result[i]);
+ return false;
+ }
+ }
+
+ printf("run_local_remove_duplicate_addrs2: success\n");
+ 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 bool run_local_canonicalize_path(int dummy)
+{
+ const char *src[] = {
+ "/foo/..",
+ "/..",
+ "/foo/bar/../baz",
+ "/foo/././",
+ "/../foo",
+ ".././././",
+ ".././././../../../boo",
+ "./..",
+ "/",
+ "/../../",
+ "/foo/../",
+ "/./././",
+ "/./././.",
+ "/.../././.",
+ "/./././.foo",
+ "/./././.foo.",
+ "/./././foo.",
+ "/foo/bar/..",
+ "/foo/bar/../baz/",
+ "////////////////",
+ "/////////./././././.",
+ "/./.././../.boo/../baz",
+ "/a/component/path",
+ "/a/component/path/",
+ "/a/component/path/..",
+ "/a/component/../path/",
+ "///a/./././///component/../////path/",
+ NULL
+ };
+ const char *dst[] = {
+ "/",
+ "/",
+ "/foo/baz",
+ "/foo",
+ "/foo",
+ "/",
+ "/boo",
+ "/",
+ "/",
+ "/",
+ "/",
+ "/",
+ "/",
+ "/...",
+ "/.foo",
+ "/.foo.",
+ "/foo.",
+ "/foo",
+ "/foo/baz",
+ "/",
+ "/",
+ "/baz",
+ "/a/component/path",
+ "/a/component/path",
+ "/a/component",
+ "/a/path",
+ "/a/path",
+ NULL
+ };
+ unsigned int i;
+
+ for (i = 0; src[i] != NULL; i++) {
+ char *d = canonicalize_absolute_path(talloc_tos(), src[i]);
+ if (d == NULL) {
+ perror("talloc fail\n");
+ return false;
+ }
+ if (strcmp(d, dst[i]) != 0) {
+ d_fprintf(stderr,
+ "canonicalize mismatch %s -> %s != %s",
+ src[i], d, dst[i]);
+ return false;
+ }
+ talloc_free(d);
+ }
+ 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);;
- if (count != 14) {
- fprintf(stderr, "count wrong (%d) should be 14\n",
- count);
+ req = smb1_negotiate_exit_send(ev, ev, conn);
+ if (req == NULL) {
+ d_fprintf(stderr, "smb1_negotiate_exit_send failed\n");
return false;
}
- for (i = 0; i < count; i++) {
- char addr[INET6_ADDRSTRLEN];
-
- print_sockaddr(addr, sizeof(addr), &test_vector[i].ss);
-
- if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) {
- fprintf(stderr, "mismatch on [%d] [%s] [%s]\n",
- i,
- addr,
- remove_duplicate_addrs2_test_strings_result[i]);
- 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;
}
- printf("run_local_remove_duplicate_addrs2: success\n");
+ 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_local_tdb_opener(int dummy)
+static bool run_smb1_negotiate_exit(int dummy)
{
- TDB_CONTEXT *t;
- unsigned v = 0;
+ struct tevent_context *ev;
+ struct smbXcli_conn *conn;
+ struct sockaddr_storage ss;
+ NTSTATUS status;
+ int fd;
+ bool ok;
- 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);
+ printf("Starting send SMB1 negotiate+exit.\n");
- v += 1;
- printf("\r%u", v);
+ ok = resolve_name(host, &ss, 0x20, true);
+ if (!ok) {
+ d_fprintf(stderr, "Could not resolve name %s\n", host);
+ return false;
}
- 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;
+ 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;
}
- val.dptr = (uint8_t *)&v;
- val.dsize = sizeof(v);
+ 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;
+ }
- while (1) {
- TDB_DATA data;
- int ret;
+ status = smbXcli_negprot(conn, 0, PROTOCOL_NT1, PROTOCOL_NT1);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_fprintf(stderr, "smbXcli_negprot failed!\n");
+ return false;
+ }
- ret = tdb_store(t, val, val, 0);
- if (ret != 0) {
- printf("%s\n", tdb_errorstr(t));
- }
- v += 1;
- printf("\r%u", v);
+ ev = samba_tevent_context_init(talloc_tos());
+ if (ev == NULL) {
+ d_fprintf(stderr, "samba_tevent_context_init failed\n");
+ return false;
+ }
- data = tdb_fetch(t, val);
- if (data.dptr != NULL) {
- SAFE_FREE(data.dptr);
- }
+ /*
+ * 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_local_canonicalize_path(int dummy)
+static bool run_smb1_negotiate_tcon(int dummy)
{
- const char *src[] = {
- "/foo/..",
- "/..",
- "/foo/bar/../baz",
- "/foo/././",
- "/../foo",
- ".././././",
- ".././././../../../boo",
- "./..",
- NULL
- };
- const char *dst[] = {
- "/",
- "/",
- "/foo/baz",
- "/foo",
- "/foo",
- "/",
- "/boo",
- "/",
- NULL
- };
- unsigned int i;
+ struct cli_state *cli = NULL;
+ uint16_t cnum = 0;
+ uint16_t max_xmit = 0;
+ NTSTATUS status;
- for (i = 0; src[i] != NULL; i++) {
- char *d = canonicalize_absolute_path(talloc_tos(), src[i]);
- if (d == NULL) {
- perror("talloc fail\n");
- return false;
- }
- if (strcmp(d, dst[i]) != 0) {
- d_fprintf(stderr,
- "canonicalize mismatch %s -> %s != %s",
- src[i], d, dst[i]);
- return false;
- }
- talloc_free(d);
+ 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;
}
}
conn = smbXcli_conn_create(talloc_tos(), fd, host, SMB_SIGNING_OFF, 0,
- NULL, 0);
+ NULL, 0, NULL);
if (conn == NULL) {
d_fprintf(stderr, "smbXcli_conn_create failed\n");
return false;
return true;
}
+
static double create_procs(bool (*fn)(int), bool *result)
{
int i, status;
.fn = run_locktest8,
},
{
- .name = "LOCK9",
- .fn = run_locktest9,
+ .name = "LOCK9A",
+ .fn = run_locktest9a,
+ },
+ {
+ .name = "LOCK9B",
+ .fn = run_locktest9b,
},
{
.name = "LOCK10",
.name = "POSIX-ACL-SHAREROOT",
.fn = run_posix_acl_shareroot_test,
},
+ {
+ .name = "POSIX-LS-WILDCARD",
+ .fn = run_posix_ls_wildcard_test,
+ },
+ {
+ .name = "POSIX-LS-SINGLE",
+ .fn = run_posix_ls_single_test,
+ },
+ {
+ .name = "POSIX-READLINK",
+ .fn = run_posix_readlink_test,
+ },
+ {
+ .name = "POSIX-STAT",
+ .fn = run_posix_stat_test,
+ },
+ {
+ .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,
},
+ {
+ .name = "SMB1-WILD-MANGLE-UNLINK",
+ .fn = run_smb1_wild_mangle_unlink_test,
+ },
+ {
+ .name = "SMB1-WILD-MANGLE-RENAME",
+ .fn = run_smb1_wild_mangle_rename_test,
+ },
{
.name = "CASE-INSENSITIVE-CREATE",
.fn = run_case_insensitive_create,
.fn = run_deletetest,
},
{
- .name = "DELETE-PRINT",
- .fn = run_delete_print_test,
+ .name = "DELETE-STREAM",
+ .fn = run_delete_stream,
},
{
- .name = "WILDDELETE",
- .fn = run_wild_deletetest,
+ .name = "DELETE-PRINT",
+ .fn = run_delete_print_test,
},
{
.name = "DELETE-LN",
.name = "LARGE_READX",
.fn = run_large_readx,
},
+ {
+ .name = "MSDFS-ATTRIBUTE",
+ .fn = run_msdfs_attribute,
+ },
{
.name = "NTTRANS-CREATE",
.fn = run_nttrans_create,
.name = "SMB2-DIR-FSYNC",
.fn = run_smb2_dir_fsync,
},
+ {
+ .name = "SMB2-PATH-SLASH",
+ .fn = run_smb2_path_slash,
+ },
+ {
+ .name = "SMB1-SYSTEM-SECURITY",
+ .fn = run_smb1_system_security,
+ },
+ {
+ .name = "SMB2-SACL",
+ .fn = run_smb2_sacl,
+ },
+ {
+ .name = "SMB2-QUOTA1",
+ .fn = run_smb2_quota1,
+ },
+ {
+ .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,
.name = "CLEANUP2",
.fn = run_cleanup2,
},
- {
- .name = "CLEANUP3",
- .fn = run_cleanup3,
- },
{
.name = "CLEANUP4",
.fn = run_cleanup4,
.name = "LOCAL-DBWRAP-WATCH2",
.fn = run_dbwrap_watch2,
},
+ {
+ .name = "LOCAL-DBWRAP-WATCH3",
+ .fn = run_dbwrap_watch3,
+ },
+ {
+ .name = "LOCAL-DBWRAP-WATCH4",
+ .fn = run_dbwrap_watch4,
+ },
{
.name = "LOCAL-DBWRAP-DO-LOCKED1",
.fn = run_dbwrap_do_locked1,
.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,
.fn = run_local_tdb_writer,
},
{
- .name = "LOCAL-DBWRAP-CTDB",
- .fn = run_local_dbwrap_ctdb,
+ .name = "LOCAL-DBWRAP-CTDB1",
+ .fn = run_local_dbwrap_ctdb1,
},
{
.name = "LOCAL-BENCH-PTHREADPOOL",
.name = "LOCAL-G-LOCK4",
.fn = run_g_lock4,
},
+ {
+ .name = "LOCAL-G-LOCK4A",
+ .fn = run_g_lock4a,
+ },
{
.name = "LOCAL-G-LOCK5",
.fn = run_g_lock5,
.name = "LOCAL-G-LOCK6",
.fn = run_g_lock6,
},
+ {
+ .name = "LOCAL-G-LOCK7",
+ .fn = run_g_lock7,
+ },
+ {
+ .name = "LOCAL-G-LOCK8",
+ .fn = run_g_lock8,
+ },
{
.name = "LOCAL-G-LOCK-PING-PONG",
.fn = run_g_lock_ping_pong,
.name = "hide-new-files-timeout",
.fn = run_hidenewfiles,
},
+ {
+ .name = "hide-new-files-timeout-showdirs",
+ .fn = run_hidenewfiles_showdirs,
+ },
+#ifdef CLUSTER_SUPPORT
+ {
+ .name = "ctdbd-conn1",
+ .fn = run_ctdbd_conn1,
+ },
+#endif
+ {
+ .name = "readdir-timestamp",
+ .fn = run_readdir_timestamp,
+ },
+ {
+ .name = "rpc-scale",
+ .fn = run_rpc_scale,
+ },
+ {
+ .name = "LOCAL-TDB-VALIDATE",
+ .fn = run_tdb_validate,
+ },
{
.name = NULL,
},