diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-11-15 06:55:27 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:05:50 -0500 |
commit | 4719461a07a5494f01b4295e6f9e0479ea8e96a0 (patch) | |
tree | 8ef728266f20f0aff2651241cfe598d6b6751535 | |
parent | 42b70367433dfe835a80fbc5ac50bb6d3babbae3 (diff) | |
download | samba-4719461a07a5494f01b4295e6f9e0479ea8e96a0.tar.gz samba-4719461a07a5494f01b4295e6f9e0479ea8e96a0.tar.bz2 samba-4719461a07a5494f01b4295e6f9e0479ea8e96a0.zip |
r3746: added RAW-STREAMS and RAW-EAS tests to smbtorture
(This used to be commit 5ed3d68d20860bdedcfeb2461af570aedc689674)
-rw-r--r-- | source4/torture/config.mk | 2 | ||||
-rw-r--r-- | source4/torture/raw/eas.c | 215 | ||||
-rw-r--r-- | source4/torture/raw/streams.c | 194 | ||||
-rw-r--r-- | source4/torture/torture.c | 2 |
4 files changed, 413 insertions, 0 deletions
diff --git a/source4/torture/config.mk b/source4/torture/config.mk index bd006ebb57..5aa621bdb5 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -46,6 +46,8 @@ ADD_OBJ_FILES = \ torture/raw/write.o \ torture/raw/lock.o \ torture/raw/rename.o \ + torture/raw/eas.o \ + torture/raw/streams.o \ torture/raw/seek.o REQUIRED_SUBSYSTEMS = \ LIBSMB diff --git a/source4/torture/raw/eas.c b/source4/torture/raw/eas.c new file mode 100644 index 0000000000..63792f92da --- /dev/null +++ b/source4/torture/raw/eas.c @@ -0,0 +1,215 @@ +/* + Unix SMB/CIFS implementation. + + test DOS extended attributes + + Copyright (C) Andrew Tridgell 2004 + + 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" +#include "libcli/raw/libcliraw.h" + +#define BASEDIR "\\testeas" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, correct)) { \ + printf("(%s) Incorrect status %s - should be %s\n", \ + __location__, nt_errstr(status), nt_errstr(correct)); \ + ret = False; \ + goto done; \ + }} while (0) + +/* + check that an EA has the right value +*/ +static BOOL check_ea(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, + const char *fname, const char *eaname, const char *value) +{ + union smb_fileinfo info; + NTSTATUS status; + BOOL ret = True; + int i; + + info.all_eas.level = RAW_FILEINFO_ALL_EAS; + info.all_eas.in.fname = fname; + + status = smb_raw_pathinfo(cli->tree, mem_ctx, &info); + CHECK_STATUS(status, NT_STATUS_OK); + + for (i=0;i<info.all_eas.out.num_eas;i++) { + if (StrCaseCmp(eaname, info.all_eas.out.eas[i].name.s) == 0) { + if (value == NULL) { + printf("attr '%s' should not be present\n", eaname); + return False; + } + if (strlen(value) == info.all_eas.out.eas[i].value.length && + memcmp(value, + info.all_eas.out.eas[i].value.data, + info.all_eas.out.eas[i].value.length) == 0) { + return True; + } else { + printf("attr '%s' has wrong value '%*.*s'\n", + eaname, + info.all_eas.out.eas[i].value.length, + info.all_eas.out.eas[i].value.length, + info.all_eas.out.eas[i].value.data); + ret = False; + goto done; + } + } + } + + if (value != NULL) { + printf("attr '%s' not found\n", eaname); + ret = False; + } + +done: + return ret; +} + +static DATA_BLOB data_blob_string_const(const char *str) +{ + DATA_BLOB blob; + blob.data = discard_const(str); + blob.length = strlen(str); + return blob; +} + + +static BOOL test_eas(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + NTSTATUS status; + union smb_setfileinfo setfile; + union smb_open io; + const char *fname = BASEDIR "\\ea.txt"; + BOOL ret = True; + int fnum; + + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + io.ntcreatex.in.create_options = 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.alloc_size = 0; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = fname; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL); + + printf("Adding first EA\n"); + setfile.generic.level = RAW_SFILEINFO_EA_SET; + setfile.generic.file.fnum = fnum; + setfile.ea_set.in.ea.flags = 0; + setfile.ea_set.in.ea.name.s = "EAONE"; + setfile.ea_set.in.ea.value = data_blob_string_const("VALUE1"); + + status = smb_raw_setfileinfo(cli->tree, &setfile); + CHECK_STATUS(status, NT_STATUS_OK); + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1"); + + setfile.ea_set.in.ea.name.s = "SECONDEA"; + setfile.ea_set.in.ea.value = data_blob_string_const("ValueTwo"); + + printf("Adding second EA\n"); + status = smb_raw_setfileinfo(cli->tree, &setfile); + CHECK_STATUS(status, NT_STATUS_OK); + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1"); + ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", "ValueTwo"); + + printf("Modifying 2nd EA\n"); + setfile.ea_set.in.ea.value = data_blob_string_const(" Changed Value"); + status = smb_raw_setfileinfo(cli->tree, &setfile); + CHECK_STATUS(status, NT_STATUS_OK); + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1"); + ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", " Changed Value"); + + printf("Setting a NULL EA\n"); + setfile.ea_set.in.ea.value = data_blob(NULL, 0); + setfile.ea_set.in.ea.name.s = "NULLEA"; + status = smb_raw_setfileinfo(cli->tree, &setfile); + CHECK_STATUS(status, NT_STATUS_OK); + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", "VALUE1"); + ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", " Changed Value"); + ret &= check_ea(cli, mem_ctx, fname, "NULLEA", NULL); + + printf("Deleting first EA\n"); + setfile.ea_set.in.ea.flags = 0; + setfile.ea_set.in.ea.name.s = "EAONE"; + setfile.ea_set.in.ea.value = data_blob(NULL, 0); + status = smb_raw_setfileinfo(cli->tree, &setfile); + CHECK_STATUS(status, NT_STATUS_OK); + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL); + ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", " Changed Value"); + + printf("Deleting second EA\n"); + setfile.ea_set.in.ea.flags = 0; + setfile.ea_set.in.ea.name.s = "SECONDEA"; + setfile.ea_set.in.ea.value = data_blob(NULL, 0); + status = smb_raw_setfileinfo(cli->tree, &setfile); + CHECK_STATUS(status, NT_STATUS_OK); + + ret &= check_ea(cli, mem_ctx, fname, "EAONE", NULL); + ret &= check_ea(cli, mem_ctx, fname, "SECONDEA", NULL); + +done: + smbcli_close(cli->tree, fnum); + return True; +} + +/* + basic testing of EA calls +*/ +BOOL torture_raw_eas(void) +{ + struct smbcli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_eas"); + + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + + ret &= test_eas(cli, mem_ctx); + + smb_raw_exit(cli->session); + smbcli_deltree(cli->tree, BASEDIR); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/raw/streams.c b/source4/torture/raw/streams.c new file mode 100644 index 0000000000..4614367abf --- /dev/null +++ b/source4/torture/raw/streams.c @@ -0,0 +1,194 @@ +/* + Unix SMB/CIFS implementation. + + test alternate data streams + + Copyright (C) Andrew Tridgell 2004 + + 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" +#include "libcli/raw/libcliraw.h" + +#define BASEDIR "\\teststreams" + +#define CHECK_STATUS(status, correct) do { \ + if (!NT_STATUS_EQUAL(status, 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("(%s) Incorrect value %s=%d - should be %d\n", \ + __location__, #v, v, correct); \ + ret = False; \ + }} while (0) + +/* + check that a stream has the right contents +*/ +static BOOL check_stream(struct smbcli_state *cli, TALLOC_CTX *mem_ctx, + const char *fname, const char *sname, + const char *value) +{ + int fnum; + const char *full_name; + char *buf; + ssize_t ret; + + full_name = talloc_asprintf(mem_ctx, "%s:%s", fname, sname); + + fnum = smbcli_open(cli->tree, full_name, O_RDONLY, DENY_NONE); + + if (value == NULL) { + if (fnum != -1) { + printf("should have failed stream open of %s\n", full_name); + return False; + } + return True; + } + + if (fnum == -1) { + printf("Failed to open stream '%s' - %s\n", + full_name, smbcli_errstr(cli->tree)); + return False; + } + + buf = talloc(mem_ctx, strlen(value)+11); + + ret = smbcli_read(cli->tree, fnum, buf, 0, strlen(value)+11); + if (ret != strlen(value)) { + printf("Failed to read %d bytes from stream '%s' - got %d\n", + strlen(value), full_name, ret); + return False; + } + + if (memcmp(buf, value, strlen(value)) != 0) { + printf("Bad data in stream\n"); + return False; + } + + smbcli_close(cli->tree, fnum); + return True; +} + +/* + test basic io on streams +*/ +static BOOL test_stream_io(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) +{ + NTSTATUS status; + union smb_open io; + const char *fname = BASEDIR "\\stream.txt"; + const char *sname1, *sname2; + BOOL ret = True; + int fnum, fnum2; + ssize_t retsize; + + sname1 = talloc_asprintf(mem_ctx, "%s:%s", fname, "Stream One"); + + printf("opening non-existant directory stream\n"); + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED; + 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_CREATE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = sname1; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY); + + printf("creating a stream on a non-existant file\n"); + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.fname = sname1; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + ret &= check_stream(cli, mem_ctx, fname, "Stream One", NULL); + + printf("writing to stream\n"); + retsize = smbcli_write(cli->tree, fnum, 0, "test data", 0, 9); + CHECK_VALUE(retsize, 9); + + smbcli_close(cli->tree, fnum); + + ret &= check_stream(cli, mem_ctx, fname, "Stream One", "test data"); + + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + fnum = io.ntcreatex.out.fnum; + + printf("modifying stream\n"); + retsize = smbcli_write(cli->tree, fnum, 0, "MORE DATA ", 5, 10); + CHECK_VALUE(retsize, 10); + + smbcli_close(cli->tree, fnum); + + ret &= check_stream(cli, mem_ctx, fname, "Stream One", "test MORE DATA "); + + printf("deleting stream\n"); + status = smbcli_unlink(cli->tree, sname1); + CHECK_STATUS(status, NT_STATUS_OK); + + printf("deleting file\n"); + status = smbcli_unlink(cli->tree, fname); + CHECK_STATUS(status, NT_STATUS_OK); + +done: + smbcli_close(cli->tree, fnum); + return True; +} + +/* + basic testing of streams calls +*/ +BOOL torture_raw_streams(void) +{ + struct smbcli_state *cli; + BOOL ret = True; + TALLOC_CTX *mem_ctx; + + if (!torture_open_connection(&cli)) { + return False; + } + + mem_ctx = talloc_init("torture_raw_streams"); + + if (!torture_setup_dir(cli, BASEDIR)) { + return False; + } + + ret &= test_stream_io(cli, mem_ctx); + + smb_raw_exit(cli->session); + smbcli_deltree(cli->tree, BASEDIR); + + torture_close_connection(cli); + talloc_destroy(mem_ctx); + return ret; +} diff --git a/source4/torture/torture.c b/source4/torture/torture.c index 9db2f7f6bc..bc3b5f545f 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -2419,6 +2419,8 @@ static struct { {"RAW-CONTEXT", torture_raw_context, 0}, {"RAW-RENAME", torture_raw_rename, 0}, {"RAW-SEEK", torture_raw_seek, 0}, + {"RAW-EAS", torture_raw_eas, 0}, + {"RAW-STREAMS", torture_raw_streams, 0}, {"RAW-RAP", torture_raw_rap, 0}, /* protocol scanners */ |