summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/torture/basic/attr.c196
-rw-r--r--source4/torture/config.mk3
-rw-r--r--source4/torture/raw/write.c224
-rw-r--r--source4/torture/torture.c168
4 files changed, 310 insertions, 281 deletions
diff --git a/source4/torture/basic/attr.c b/source4/torture/basic/attr.c
new file mode 100644
index 0000000000..df93efaeaf
--- /dev/null
+++ b/source4/torture/basic/attr.c
@@ -0,0 +1,196 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ openattr tester
+
+ Copyright (C) Andrew Tridgell 2003
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+
+extern int torture_failures;
+
+#define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
+
+
+static const uint32_t open_attrs_table[] = {
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_ATTRIBUTE_ARCHIVE,
+ FILE_ATTRIBUTE_READONLY,
+ FILE_ATTRIBUTE_HIDDEN,
+ FILE_ATTRIBUTE_SYSTEM,
+
+ FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
+ FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
+ FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
+ FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
+ FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
+ FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
+
+ FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
+ FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
+ FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
+ FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
+};
+
+struct trunc_open_results {
+ uint_t num;
+ uint32_t init_attr;
+ uint32_t trunc_attr;
+ uint32_t result_attr;
+};
+
+static const struct trunc_open_results attr_results[] = {
+ { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
+ { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
+ { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
+ { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
+ { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
+ { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
+ { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
+ { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
+ { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
+ { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
+ { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
+ { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
+ { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
+ { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
+ { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
+ { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
+ { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
+ { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
+ { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
+ { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
+ { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
+ { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
+ { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
+ { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
+ { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
+ { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
+};
+
+
+BOOL torture_openattrtest(int dummy)
+{
+ struct smbcli_state *cli1;
+ const char *fname = "\\openattr.file";
+ int fnum1;
+ BOOL correct = True;
+ uint16_t attr;
+ uint_t i, j, k, l;
+ int failures = 0;
+
+ printf("starting open attr test\n");
+
+ if (!torture_open_connection(&cli1)) {
+ return False;
+ }
+
+ for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
+ smbcli_setatr(cli1->tree, fname, 0, 0);
+ smbcli_unlink(cli1->tree, fname);
+ fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
+ NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
+
+ if (fnum1 == -1) {
+ printf("open %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree));
+ return False;
+ }
+
+ if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
+ printf("close %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree));
+ return False;
+ }
+
+ for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
+ fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
+ SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
+ open_attrs_table[j],
+ NTCREATEX_SHARE_ACCESS_NONE,
+ NTCREATEX_DISP_OVERWRITE, 0, 0);
+
+ if (fnum1 == -1) {
+ for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
+ if (attr_results[l].num == k) {
+ printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
+ k, open_attrs_table[i],
+ open_attrs_table[j],
+ fname, NT_STATUS_V(smbcli_nt_error(cli1->tree)), smbcli_errstr(cli1->tree));
+ correct = False;
+ CHECK_MAX_FAILURES(error_exit);
+ }
+ }
+ if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
+ printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
+ k, open_attrs_table[i], open_attrs_table[j],
+ smbcli_errstr(cli1->tree));
+ correct = False;
+ CHECK_MAX_FAILURES(error_exit);
+ }
+#if 0
+ printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
+#endif
+ k++;
+ continue;
+ }
+
+ if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
+ printf("close %d (2) of %s failed (%s)\n", j, fname, smbcli_errstr(cli1->tree));
+ return False;
+ }
+
+ if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL))) {
+ printf("getatr(2) failed (%s)\n", smbcli_errstr(cli1->tree));
+ return False;
+ }
+
+#if 0
+ printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
+ k, open_attrs_table[i], open_attrs_table[j], attr );
+#endif
+
+ for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
+ if (attr_results[l].num == k) {
+ if (attr != attr_results[l].result_attr ||
+ open_attrs_table[i] != attr_results[l].init_attr ||
+ open_attrs_table[j] != attr_results[l].trunc_attr) {
+ printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
+ k, open_attrs_table[i],
+ open_attrs_table[j],
+ (uint_t)attr,
+ attr_results[l].result_attr);
+ correct = False;
+ CHECK_MAX_FAILURES(error_exit);
+ }
+ break;
+ }
+ }
+ k++;
+ }
+ }
+error_exit:
+ smbcli_setatr(cli1->tree, fname, 0, 0);
+ smbcli_unlink(cli1->tree, fname);
+
+ printf("open attr test %s.\n", correct ? "passed" : "failed");
+
+ if (!torture_close_connection(cli1)) {
+ correct = False;
+ }
+ return correct;
+}
+
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index a21543647f..20f0f7bbc5 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -14,7 +14,8 @@ ADD_OBJ_FILES = \
torture/basic/secleak.o \
torture/basic/rename.o \
torture/basic/dir.o \
- torture/basic/delete.o
+ torture/basic/delete.o \
+ torture/basic/attr.o
REQUIRED_SUBSYSTEMS = \
LIBSMB
# End SUBSYSTEM TORTURE_BASIC
diff --git a/source4/torture/raw/write.c b/source4/torture/raw/write.c
index 8b4de9c7e7..6ac92af528 100644
--- a/source4/torture/raw/write.c
+++ b/source4/torture/raw/write.c
@@ -22,22 +22,22 @@
#define CHECK_STATUS(status, correct) do { \
if (!NT_STATUS_EQUAL(status, correct)) { \
- printf("(%d) Incorrect status %s - should be %s\n", \
- __LINE__, nt_errstr(status), nt_errstr(correct)); \
+ printf("(%s) Incorrect status %s - should be %s\n", \
+ __location__, nt_errstr(status), nt_errstr(correct)); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_VALUE(v, correct) do { \
if ((v) != (correct)) { \
- printf("(%d) Incorrect value %s=%d - should be %d\n", \
- __LINE__, #v, v, correct); \
+ printf("(%s) Incorrect value %s=%d - should be %d\n", \
+ __location__, #v, v, correct); \
ret = False; \
goto done; \
}} while (0)
#define CHECK_BUFFER(buf, seed, len) do { \
- if (!check_buffer(buf, seed, len, __LINE__)) { \
+ if (!check_buffer(buf, seed, len, __location__)) { \
ret = False; \
goto done; \
}} while (0)
@@ -48,8 +48,8 @@
status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
CHECK_STATUS(status, NT_STATUS_OK); \
if ((v) != finfo.all_info.out.field) { \
- printf("(%d) wrong value for field %s %.0f - %.0f\n", \
- __LINE__, #field, (double)v, (double)finfo.all_info.out.field); \
+ printf("(%s) wrong value for field %s %.0f - %.0f\n", \
+ __location__, #field, (double)v, (double)finfo.all_info.out.field); \
dump_all_info(mem_ctx, &finfo); \
ret = False; \
}} while (0)
@@ -83,15 +83,15 @@ static void setup_buffer(char *buf, uint_t seed, int len)
/*
check a random buffer based on a seed
*/
-static BOOL check_buffer(char *buf, uint_t seed, int len, int line)
+static BOOL check_buffer(char *buf, uint_t seed, int len, const char *location)
{
int i;
srandom(seed);
for (i=0;i<len;i++) {
char v = random();
if (buf[i] != v) {
- printf("Buffer incorrect at line %d! ofs=%d buf=0x%x correct=0x%x\n",
- line, i, buf[i], v);
+ printf("Buffer incorrect at %s! ofs=%d buf=0x%x correct=0x%x\n",
+ location, i, buf[i], v);
return False;
}
}
@@ -151,7 +151,7 @@ static BOOL test_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -170,7 +170,7 @@ static BOOL test_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -201,7 +201,7 @@ static BOOL test_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, io.write.in.offset, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -269,7 +269,7 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -288,7 +288,7 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -321,7 +321,7 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
printf("Trying locked region\n");
cli->session->pid++;
if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 3, 1, 0, WRITE_LOCK))) {
- printf("Failed to lock file at %d\n", __LINE__);
+ printf("Failed to lock file at %s\n", __location__);
ret = False;
goto done;
}
@@ -349,7 +349,7 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -363,19 +363,23 @@ static BOOL test_writex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
io.writex.in.offset = ((uint64_t)1) << i;
io.writex.in.data = buf;
status = smb_raw_write(cli->tree, &io);
+ if (i>40 &&
+ NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
+ break;
+ }
CHECK_STATUS(status, NT_STATUS_OK);
CHECK_VALUE(io.writex.out.nwritten, 4000);
CHECK_ALL_INFO(io.writex.in.count + (uint64_t)io.writex.in.offset, size);
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, io.writex.in.offset, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
CHECK_BUFFER(buf, seed+1, 4000);
}
-
+ printf("limit is 2^%d\n", i);
setup_buffer(buf, seed, maxsize);
@@ -437,7 +441,7 @@ static BOOL test_writeunlock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
status = smb_raw_write(cli->tree, &io);
CHECK_STATUS(status, NT_STATUS_RANGE_NOT_LOCKED);
if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -453,7 +457,7 @@ static BOOL test_writeunlock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -477,7 +481,7 @@ static BOOL test_writeunlock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -510,7 +514,7 @@ static BOOL test_writeunlock(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, io.writeunlock.in.offset, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -585,7 +589,7 @@ static BOOL test_writeclose(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
io.writeclose.in.fnum = fnum;
if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -602,7 +606,7 @@ static BOOL test_writeclose(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 13) != 13) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -627,7 +631,7 @@ static BOOL test_writeclose(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, 0, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -661,7 +665,7 @@ static BOOL test_writeclose(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
memset(buf, 0, maxsize);
if (smbcli_read(cli->tree, fnum, buf, io.writeclose.in.offset, 4000) != 4000) {
- printf("read failed at %d\n", __LINE__);
+ printf("read failed at %s\n", __location__);
ret = False;
goto done;
}
@@ -773,8 +777,10 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
const char *fname = BASEDIR "\\torture_file.txt";
NTSTATUS status;
int fnum1 = -1;
+ int fnum2;
BOOL ret = True;
ssize_t written;
+ struct smbcli_state *cli2=NULL;
printf("Testing finfo update on close\n");
@@ -804,77 +810,83 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
written = smbcli_write(cli->tree, fnum1, 0, "x", 0, 1);
if (written != 1) {
+ printf("(%s) written gave %d - should have been 1\n",
+ __location__, written);
ret = False;
goto done;
}
- {
- struct smbcli_state *cli2;
- int fnum2;
-
- if (!torture_open_connection(&cli2)) {
- return False;
- }
-
- fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
- if (fnum2 == -1) {
- ret = False;
- goto done;
- }
-
- written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
-
- if (written != 1) {
- ret = False;
- goto done;
- }
-
- finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
- finfo2.basic_info.in.fname = fname;
-
- status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2);
-
- if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0, ("fileinfo failed: %s\n", nt_errstr(status)));
- ret = False;
- goto done;
- }
-
- if (finfo1.basic_info.out.create_time !=
- finfo2.basic_info.out.create_time) {
- ret = False;
- goto done;
- }
-
- if (finfo1.basic_info.out.access_time !=
- finfo2.basic_info.out.access_time) {
- ret = False;
- goto done;
- }
-
- if (finfo1.basic_info.out.write_time !=
- finfo2.basic_info.out.write_time) {
- ret = False;
- goto done;
- }
-
- if (finfo1.basic_info.out.change_time !=
- finfo2.basic_info.out.change_time) {
- ret = False;
- goto done;
- }
-
- /* One of the two following calls updates the qpathinfo. */
-
- /* If you had skipped the smbcli_write on fnum2, it would
- * *not* have updated the stat on disk */
+ if (!torture_open_connection(&cli2)) {
+ return False;
+ }
- smbcli_close(cli2->tree, fnum2);
- torture_close_connection(cli2);
+ fnum2 = smbcli_open(cli2->tree, fname, O_RDWR, DENY_NONE);
+ if (fnum2 == -1) {
+ printf("(%s) failed to open 2nd time - %s\n",
+ __location__, smbcli_errstr(cli2->tree));
+ ret = False;
+ goto done;
+ }
+
+ written = smbcli_write(cli2->tree, fnum2, 0, "x", 0, 1);
+
+ if (written != 1) {
+ printf("(%s) written gave %d - should have been 1\n",
+ __location__, written);
+ ret = False;
+ goto done;
}
+
+ finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
+ finfo2.basic_info.in.fname = fname;
+
+ status = smb_raw_pathinfo(cli2->tree, mem_ctx, &finfo2);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0, ("(%s) fileinfo failed: %s\n",
+ __location__, nt_errstr(status)));
+ ret = False;
+ goto done;
+ }
+
+ if (finfo1.basic_info.out.create_time !=
+ finfo2.basic_info.out.create_time) {
+ printf("(%s) create_time changed\n", __location__);
+ ret = False;
+ goto done;
+ }
+
+ if (finfo1.basic_info.out.access_time !=
+ finfo2.basic_info.out.access_time) {
+ printf("(%s) access_time changed\n", __location__);
+ ret = False;
+ goto done;
+ }
+
+ if (finfo1.basic_info.out.write_time !=
+ finfo2.basic_info.out.write_time) {
+ printf("(%s) write_time changed\n", __location__);
+ ret = False;
+ goto done;
+ }
+
+ if (finfo1.basic_info.out.change_time !=
+ finfo2.basic_info.out.change_time) {
+ printf("(%s) change_time changed\n", __location__);
+ ret = False;
+ goto done;
+ }
+
+ /* One of the two following calls updates the qpathinfo. */
+
+ /* If you had skipped the smbcli_write on fnum2, it would
+ * *not* have updated the stat on disk */
+
+ smbcli_close(cli2->tree, fnum2);
+ torture_close_connection(cli2);
+ cli2 = NULL;
/* This call is only for the people looking at ethereal :-) */
-
finfo2.basic_info.level = RAW_FILEINFO_BASIC_INFO;
finfo2.basic_info.in.fname = fname;
@@ -891,6 +903,9 @@ static BOOL test_finfo_after_write(struct smbcli_state *cli, TALLOC_CTX *mem_ctx
smbcli_close(cli->tree, fnum1);
smbcli_unlink(cli->tree, fname);
smbcli_deltree(cli->tree, BASEDIR);
+ if (cli2 != NULL) {
+ torture_close_connection(cli2);
+ }
return ret;
}
@@ -910,29 +925,12 @@ BOOL torture_raw_write(int dummy)
mem_ctx = talloc_init("torture_raw_write");
- if (!test_finfo_after_write(cli, mem_ctx)) {
- ret = False;
- }
-
- if (!test_delayed_write_update(cli, mem_ctx)) {
- ret = False;
- }
-
- if (!test_write(cli, mem_ctx)) {
- ret = False;
- }
-
- if (!test_writeunlock(cli, mem_ctx)) {
- ret = False;
- }
-
- if (!test_writeclose(cli, mem_ctx)) {
- ret = False;
- }
-
- if (!test_writex(cli, mem_ctx)) {
- ret = False;
- }
+ ret &= test_finfo_after_write(cli, mem_ctx);
+ ret &= test_delayed_write_update(cli, mem_ctx);
+ ret &= test_write(cli, mem_ctx);
+ ret &= test_writeunlock(cli, mem_ctx);
+ ret &= test_writeclose(cli, mem_ctx);
+ ret &= test_writex(cli, mem_ctx);
torture_close_connection(cli);
talloc_destroy(mem_ctx);
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index 8822d12f01..d969a51404 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -2082,172 +2082,6 @@ error_test80:
}
-static uint32_t open_attrs_table[] = {
- FILE_ATTRIBUTE_NORMAL,
- FILE_ATTRIBUTE_ARCHIVE,
- FILE_ATTRIBUTE_READONLY,
- FILE_ATTRIBUTE_HIDDEN,
- FILE_ATTRIBUTE_SYSTEM,
-
- FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
- FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
- FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
- FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
- FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
- FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
-
- FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
- FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
- FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
- FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
-};
-
-struct trunc_open_results {
- uint_t num;
- uint32_t init_attr;
- uint32_t trunc_attr;
- uint32_t result_attr;
-};
-
-static struct trunc_open_results attr_results[] = {
- { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
- { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
- { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
- { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
- { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
- { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
- { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
- { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
- { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
- { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
- { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
- { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
- { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
- { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
- { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
- { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
- { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
- { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
- { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
- { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
- { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
- { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
- { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
- { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
- { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
- { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
-};
-
-static BOOL run_openattrtest(int dummy)
-{
- struct smbcli_state *cli1;
- const char *fname = "\\openattr.file";
- int fnum1;
- BOOL correct = True;
- uint16_t attr;
- uint_t i, j, k, l;
- int failures = 0;
-
- printf("starting open attr test\n");
-
- if (!torture_open_connection(&cli1)) {
- return False;
- }
-
- for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) {
- smbcli_setatr(cli1->tree, fname, 0, 0);
- smbcli_unlink(cli1->tree, fname);
- fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_WRITE_DATA, open_attrs_table[i],
- NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
-
- if (fnum1 == -1) {
- printf("open %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree));
- return False;
- }
-
- if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
- printf("close %d (1) of %s failed (%s)\n", i, fname, smbcli_errstr(cli1->tree));
- return False;
- }
-
- for (j = 0; j < ARRAY_SIZE(open_attrs_table); j++) {
- fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
- SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
- open_attrs_table[j],
- NTCREATEX_SHARE_ACCESS_NONE,
- NTCREATEX_DISP_OVERWRITE, 0, 0);
-
- if (fnum1 == -1) {
- for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
- if (attr_results[l].num == k) {
- printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
- k, open_attrs_table[i],
- open_attrs_table[j],
- fname, NT_STATUS_V(smbcli_nt_error(cli1->tree)), smbcli_errstr(cli1->tree));
- correct = False;
- CHECK_MAX_FAILURES(error_exit);
- }
- }
- if (NT_STATUS_V(smbcli_nt_error(cli1->tree)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
- printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
- k, open_attrs_table[i], open_attrs_table[j],
- smbcli_errstr(cli1->tree));
- correct = False;
- CHECK_MAX_FAILURES(error_exit);
- }
-#if 0
- printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
-#endif
- k++;
- continue;
- }
-
- if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
- printf("close %d (2) of %s failed (%s)\n", j, fname, smbcli_errstr(cli1->tree));
- return False;
- }
-
- if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, &attr, NULL, NULL))) {
- printf("getatr(2) failed (%s)\n", smbcli_errstr(cli1->tree));
- return False;
- }
-
-#if 0
- printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
- k, open_attrs_table[i], open_attrs_table[j], attr );
-#endif
-
- for (l = 0; l < ARRAY_SIZE(attr_results); l++) {
- if (attr_results[l].num == k) {
- if (attr != attr_results[l].result_attr ||
- open_attrs_table[i] != attr_results[l].init_attr ||
- open_attrs_table[j] != attr_results[l].trunc_attr) {
- printf("[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
- k, open_attrs_table[i],
- open_attrs_table[j],
- (uint_t)attr,
- attr_results[l].result_attr);
- correct = False;
- CHECK_MAX_FAILURES(error_exit);
- }
- break;
- }
- }
- k++;
- }
- }
-error_exit:
- smbcli_setatr(cli1->tree, fname, 0, 0);
- smbcli_unlink(cli1->tree, fname);
-
- printf("open attr test %s.\n", correct ? "passed" : "failed");
-
- if (!torture_close_connection(cli1)) {
- correct = False;
- }
- return correct;
-}
-
/*
sees what IOCTLs are supported
*/
@@ -2597,7 +2431,7 @@ static struct {
{"BASE-DELETE", torture_test_delete, 0},
{"BASE-PROPERTIES", run_properties, 0},
{"BASE-MANGLE", torture_mangle, 0},
- {"BASE-OPENATTR", run_openattrtest, 0},
+ {"BASE-OPENATTR", torture_openattrtest, 0},
{"BASE-CHARSET", torture_charset, 0},
{"BASE-CHKPATH", torture_chkpath_test, 0},
{"BASE-SECLEAK", torture_sec_leak, 0},