summaryrefslogtreecommitdiff
path: root/source4/torture/raw
diff options
context:
space:
mode:
Diffstat (limited to 'source4/torture/raw')
-rw-r--r--source4/torture/raw/notify.c152
-rw-r--r--source4/torture/raw/rename.c86
-rw-r--r--source4/torture/raw/samba3misc.c3
-rw-r--r--source4/torture/raw/streams.c121
4 files changed, 359 insertions, 3 deletions
diff --git a/source4/torture/raw/notify.c b/source4/torture/raw/notify.c
index 82f7d18323..3ffc58dbe6 100644
--- a/source4/torture/raw/notify.c
+++ b/source4/torture/raw/notify.c
@@ -561,7 +561,7 @@ static bool test_notify_mask(struct smbcli_state *cli, struct torture_context *t
tv = timeval_current_ofs(1000, 0);
t = timeval_to_nttime(&tv);
-
+
/*
get a handle on the directory
*/
@@ -1283,6 +1283,152 @@ done:
return ret;
}
+/*
+ Test response when cached server events exceed single NT NOTFIY response
+ packet size.
+*/
+static bool test_notify_overflow(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+ bool ret = true;
+ NTSTATUS status;
+ union smb_notify notify;
+ union smb_open io;
+ int fnum, fnum2;
+ int count = 100;
+ struct smbcli_request *req1;
+ int i;
+
+ printf("TESTING CHANGE NOTIFY EVENT OVERFLOW\n");
+
+ /* get a handle on the directory */
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.root_fid = 0;
+ io.ntcreatex.in.flags = 0;
+ io.ntcreatex.in.access_mask = SEC_FILE_ALL;
+ io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+ io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE;
+ io.ntcreatex.in.alloc_size = 0;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+ io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.ntcreatex.in.security_flags = 0;
+ io.ntcreatex.in.fname = BASEDIR;
+
+ status = smb_raw_open(cli->tree, mem_ctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ /* ask for a change notify, on name changes. */
+ notify.nttrans.level = RAW_NOTIFY_NTTRANS;
+ notify.nttrans.in.buffer_size = 1000;
+ notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_NAME;
+ notify.nttrans.in.file.fnum = fnum;
+
+ notify.nttrans.in.recursive = true;
+ req1 = smb_raw_changenotify_send(cli->tree, &notify);
+
+ /* cancel initial requests so the buffer is setup */
+ smb_raw_ntcancel(req1);
+ status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
+ CHECK_STATUS(status, NT_STATUS_CANCELLED);
+
+ /* open a lot of files, filling up the server side notify buffer */
+ printf("testing overflowed buffer notify on create of %d files\n",
+ count);
+ for (i=0;i<count;i++) {
+ char *fname = talloc_asprintf(cli, BASEDIR "\\test%d.txt", i);
+ int fnum2 = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR,
+ DENY_NONE);
+ if (fnum2 == -1) {
+ printf("Failed to create %s - %s\n",
+ fname, smbcli_errstr(cli->tree));
+ ret = false;
+ goto done;
+ }
+ talloc_free(fname);
+ smbcli_close(cli->tree, fnum2);
+ }
+
+ /* expect that 0 events will be returned with NT_STATUS_OK */
+ req1 = smb_raw_changenotify_send(cli->tree, &notify);
+ status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VAL(notify.nttrans.out.num_changes, 0);
+
+done:
+ smb_raw_exit(cli->session);
+ return ret;
+}
+
+/*
+ Test if notifications are returned for changes to the base directory.
+ They shouldn't be.
+*/
+static bool test_notify_basedir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+{
+ bool ret = true;
+ NTSTATUS status;
+ union smb_notify notify;
+ union smb_open io;
+ int fnum, fnum2;
+ int count = 100;
+ struct smbcli_request *req1;
+ int i;
+
+ printf("TESTING CHANGE NOTIFY BASEDIR EVENTS\n");
+
+ /* get a handle on the directory */
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.root_fid = 0;
+ io.ntcreatex.in.flags = 0;
+ io.ntcreatex.in.access_mask = SEC_FILE_ALL;
+ io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+ io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+ NTCREATEX_SHARE_ACCESS_WRITE;
+ io.ntcreatex.in.alloc_size = 0;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+ io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.ntcreatex.in.security_flags = 0;
+ io.ntcreatex.in.fname = BASEDIR;
+
+ status = smb_raw_open(cli->tree, mem_ctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ /* create a test file that will also be modified */
+ smbcli_close(cli->tree, smbcli_open(cli->tree, BASEDIR "\\tname1",
+ O_CREAT, 0));
+
+ /* ask for a change notify, on attribute changes. */
+ notify.nttrans.level = RAW_NOTIFY_NTTRANS;
+ notify.nttrans.in.buffer_size = 1000;
+ notify.nttrans.in.completion_filter = FILE_NOTIFY_CHANGE_ATTRIBUTES;
+ notify.nttrans.in.file.fnum = fnum;
+ notify.nttrans.in.recursive = true;
+
+ req1 = smb_raw_changenotify_send(cli->tree, &notify);
+
+ /* set attribute on the base dir */
+ smbcli_setatr(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN, 0);
+
+ /* set attribute on a file to assure we receive a notification */
+ smbcli_setatr(cli->tree, BASEDIR "\\tname1", FILE_ATTRIBUTE_HIDDEN, 0);
+ msleep(200);
+
+ /* check how many responses were given, expect only 1 for the file */
+ status = smb_raw_changenotify_recv(req1, mem_ctx, &notify);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ CHECK_VAL(notify.nttrans.out.num_changes, 1);
+ CHECK_VAL(notify.nttrans.out.changes[0].action, NOTIFY_ACTION_MODIFIED);
+ CHECK_WSTR(notify.nttrans.out.changes[0].name, "tname1", STR_UNICODE);
+
+done:
+ smb_raw_exit(cli->session);
+ return ret;
+}
+
/*
basic testing of change notify
*/
@@ -1291,7 +1437,7 @@ bool torture_raw_notify(struct torture_context *torture,
struct smbcli_state *cli2)
{
bool ret = true;
-
+
if (!torture_setup_dir(cli, BASEDIR)) {
return false;
}
@@ -1307,6 +1453,8 @@ bool torture_raw_notify(struct torture_context *torture,
ret &= test_notify_tcp_dis(torture);
ret &= test_notify_double(cli, torture);
ret &= test_notify_tree(cli, torture);
+ ret &= test_notify_overflow(cli, torture);
+ ret &= test_notify_basedir(cli, torture);
smb_raw_exit(cli->session);
smbcli_deltree(cli->tree, BASEDIR);
diff --git a/source4/torture/raw/rename.c b/source4/torture/raw/rename.c
index 9d629f0bbf..951d91a684 100644
--- a/source4/torture/raw/rename.c
+++ b/source4/torture/raw/rename.c
@@ -516,6 +516,91 @@ done:
return ret;
}
+/*
+ test dir rename.
+*/
+static bool test_dir_rename(struct torture_context *tctx, struct smbcli_state *cli)
+{
+ union smb_open io;
+ union smb_rename ren_io;
+ NTSTATUS status;
+ const char *dname1 = BASEDIR "\\dir_for_rename";
+ const char *dname2 = BASEDIR "\\renamed_dir";
+ const char *fname = BASEDIR "\\dir_for_rename\\file.txt";
+ bool ret = true;
+ int fnum = -1;
+
+ printf("Checking rename on a directory containing an open file.\n");
+
+ if (!torture_setup_dir(cli, BASEDIR)) {
+ return false;
+ }
+
+ /* create a directory */
+ smbcli_rmdir(cli->tree, dname1);
+ smbcli_rmdir(cli->tree, dname2);
+ smbcli_unlink(cli->tree, dname1);
+ smbcli_unlink(cli->tree, dname2);
+
+ ZERO_STRUCT(io);
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+ io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+ io.ntcreatex.in.alloc_size = 0;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+ io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+ io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+ io.ntcreatex.in.fname = dname1;
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ fnum = io.ntcreatex.out.file.fnum;
+ smbcli_close(cli->tree, fnum);
+
+ /* Now create and hold open a file. */
+ ZERO_STRUCT(io);
+
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
+ io.ntcreatex.in.root_fid = 0;
+ io.ntcreatex.in.alloc_size = 0;
+ io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+ io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+ io.ntcreatex.in.create_options = 0;
+ io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.ntcreatex.in.security_flags = 0;
+ io.ntcreatex.in.fname = fname;
+
+ /* Create the file. */
+
+ status = smb_raw_open(cli->tree, tctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+ fnum = io.ntcreatex.out.file.fnum;
+
+ /* Now try and rename the directory. */
+
+ ZERO_STRUCT(ren_io);
+ ren_io.generic.level = RAW_RENAME_RENAME;
+ ren_io.rename.in.pattern1 = dname1;
+ ren_io.rename.in.pattern2 = dname2;
+ ren_io.rename.in.attrib = 0;
+
+ status = smb_raw_rename(cli->tree, &ren_io);
+ CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
+
+done:
+
+ if (fnum != -1) {
+ smbcli_close(cli->tree, fnum);
+ }
+ smb_raw_exit(cli->session);
+ smbcli_deltree(cli->tree, BASEDIR);
+ return ret;
+}
+
extern bool test_trans2rename(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2);
extern bool test_nttransrename(struct torture_context *tctx, struct smbcli_state *cli1);
@@ -533,6 +618,7 @@ struct torture_suite *torture_raw_rename(TALLOC_CTX *mem_ctx)
torture_suite_add_1smb_test(suite, "nttransrename", test_nttransrename);
torture_suite_add_1smb_test(suite, "ntrename", test_ntrename);
torture_suite_add_1smb_test(suite, "osxrename", test_osxrename);
+ torture_suite_add_1smb_test(suite, "directory rename", test_dir_rename);
return suite;
}
diff --git a/source4/torture/raw/samba3misc.c b/source4/torture/raw/samba3misc.c
index 8cdccb3906..c4c790cb0a 100644
--- a/source4/torture/raw/samba3misc.c
+++ b/source4/torture/raw/samba3misc.c
@@ -672,6 +672,9 @@ bool torture_samba3_caseinsensitive(struct torture_context *torture)
/*
* Check that Samba3 correctly deals with conflicting posix byte range locks
* on an underlying file
+ *
+ * Note: This test depends on "posix locking = yes".
+ * Note: To run this test, use "--option=torture:localdir=<LOCALDIR>"
*/
bool torture_samba3_posixtimedlock(struct torture_context *tctx)
diff --git a/source4/torture/raw/streams.c b/source4/torture/raw/streams.c
index 0622e0809d..d0d21ccc06 100644
--- a/source4/torture/raw/streams.c
+++ b/source4/torture/raw/streams.c
@@ -1454,7 +1454,7 @@ static bool test_stream_create_disposition(struct torture_context *tctx,
status = smb_raw_open(cli->tree, mem_ctx, &io);
CHECK_STATUS(status, NT_STATUS_OK);
smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
- if (!check_stream_list(cli, fname, 2, &default_stream_name)) {
+ if (!check_stream_list(cli, fname, 1, &default_stream_name)) {
goto done;
}
@@ -1535,6 +1535,121 @@ static bool test_stream_large_streaminfo(struct torture_context *tctx,
return ret;
}
+/* Test the effect of setting attributes on a stream. */
+static bool test_stream_attributes(struct torture_context *tctx,
+ struct smbcli_state *cli,
+ TALLOC_CTX *mem_ctx)
+{
+ bool ret = true;
+ NTSTATUS status;
+ union smb_open io;
+ const char *fname = BASEDIR "\\stream_attr.txt";
+ const char *stream = "Stream One:$DATA";
+ const char *fname_stream;
+ int fnum = -1;
+ union smb_fileinfo finfo;
+ union smb_setfileinfo sfinfo;
+ time_t basetime = (time(NULL) - 86400) & ~1;
+
+ printf ("(%s) testing attribute setting on stream\n", __location__);
+
+ fname_stream = talloc_asprintf(mem_ctx, "%s:%s", fname, stream);
+
+ /* Create a file with a stream with attribute FILE_ATTRIBUTE_ARCHIVE. */
+ ret = create_file_with_stream(tctx, cli, mem_ctx, fname,
+ fname_stream);
+ if (!ret) {
+ goto done;
+ }
+
+ ZERO_STRUCT(finfo);
+ finfo.generic.level = RAW_FILEINFO_BASIC_INFO;
+ finfo.generic.in.file.path = fname;
+ status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ if (finfo.basic_info.out.attrib != FILE_ATTRIBUTE_ARCHIVE) {
+ printf("(%s) Incorrect attrib %x - should be %x\n", \
+ __location__, (unsigned int)finfo.basic_info.out.attrib,
+ (unsigned int)FILE_ATTRIBUTE_ARCHIVE);
+ ret = false;
+ goto done;
+ }
+
+ /* Now open the stream name. */
+
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.root_fid = 0;
+ io.ntcreatex.in.flags = 0;
+ io.ntcreatex.in.access_mask = (SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|
+ SEC_FILE_APPEND_DATA|SEC_STD_READ_CONTROL|SEC_FILE_WRITE_ATTRIBUTE);
+ io.ntcreatex.in.create_options = 0;
+ io.ntcreatex.in.file_attr = 0;
+ io.ntcreatex.in.share_access = 0;
+ io.ntcreatex.in.alloc_size = 0;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+ io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.ntcreatex.in.security_flags = 0;
+ io.ntcreatex.in.fname = fname_stream;
+
+ status = smb_raw_open(cli->tree, mem_ctx, &io);
+ CHECK_STATUS(status, NT_STATUS_OK);
+
+ fnum = io.ntcreatex.out.file.fnum;
+
+ /* Change the attributes + time on the stream fnum. */
+ ZERO_STRUCT(sfinfo);
+ sfinfo.basic_info.in.attrib = FILE_ATTRIBUTE_READONLY;
+ unix_to_nt_time(&sfinfo.basic_info.in.write_time, basetime);
+
+ sfinfo.generic.level = RAW_SFILEINFO_BASIC_INFORMATION;
+ sfinfo.generic.in.file.fnum = fnum;
+ status = smb_raw_setfileinfo(cli->tree, &sfinfo);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
+ printf("(%s) %s - %s (should be %s)\n", __location__, "SETATTR",
+ nt_errstr(status), nt_errstr(NT_STATUS_OK));
+ ret = false;
+ goto done;
+ }
+
+ smbcli_close(cli->tree, fnum);
+ fnum = -1;
+
+ ZERO_STRUCT(finfo);
+ finfo.generic.level = RAW_FILEINFO_ALL_INFO;
+ finfo.generic.in.file.path = fname;
+ status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("(%s) %s pathinfo - %s\n", __location__, "SETATTRE", nt_errstr(status));
+ ret = false;
+ goto done;
+ }
+
+ if (finfo.all_info.out.attrib != FILE_ATTRIBUTE_READONLY) {
+ printf("(%s) attrib incorrect. Was 0x%x, should be 0x%x\n",
+ __location__,
+ (unsigned int)finfo.all_info.out.attrib,
+ (unsigned int)FILE_ATTRIBUTE_READONLY);
+ ret = false;
+ goto done;
+ }
+
+ if (nt_time_to_unix(finfo.all_info.out.write_time) != basetime) {
+ printf("(%s) time incorrect.\n",
+ __location__);
+ ret = false;
+ goto done;
+ }
+
+ done:
+
+ if (fnum != -1) {
+ smbcli_close(cli->tree, fnum);
+ }
+ smbcli_unlink(cli->tree, fname);
+ return ret;
+}
+
/*
basic testing of streams calls
*/
@@ -1566,6 +1681,10 @@ bool torture_raw_streams(struct torture_context *torture,
smb_raw_exit(cli->session);
ret &= test_stream_create_disposition(torture, cli, torture);
smb_raw_exit(cli->session);
+
+ ret &= test_stream_attributes(torture, cli, torture);
+ smb_raw_exit(cli->session);
+
/* ret &= test_stream_large_streaminfo(torture, cli, torture); */
/* smb_raw_exit(cli->session); */