Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#define NO_SYSLOG
-
#include "includes.h"
+extern char *optarg;
+extern int optind;
+
static fstring host, workgroup, share, password, username, myname;
static int max_protocol = PROTOCOL_NT1;
static const char *sockops="TCP_NODELAY";
void start_timer(void)
{
- gettimeofday(&tp1,NULL);
+ GetTimeOfDay(&tp1);
}
double end_timer(void)
{
- gettimeofday(&tp2,NULL);
+ GetTimeOfDay(&tp2);
return((tp2.tv_sec - tp1.tv_sec) +
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
int shmid;
void *ret;
- shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
+ shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
if (shmid == -1) {
printf("can't get shared memory\n");
exit(1);
uint8 eclass, uint32 ecode, NTSTATUS nterr)
{
if (cli_is_dos_error(c)) {
- uint8 class;
+ uint8 cclass;
uint32 num;
/* Check DOS error */
- cli_dos_error(c, &class, &num);
+ cli_dos_error(c, &cclass, &num);
- if (eclass != class || ecode != num) {
+ if (eclass != cclass || ecode != num) {
printf("unexpected error code class=%d code=%d\n",
- (int)class, (int)num);
+ (int)cclass, (int)num);
printf(" expected %d/%d %s (line=%d)\n",
(int)eclass, (int)ecode, nt_errstr(nterr), line);
return False;
{
fnum = cli_open(c, lockfname, O_RDONLY,
DENY_NONE);
- msleep(10);
+ smb_msleep(10);
}
if (fnum == -1) {
printf("second open read-only of %s failed (%s)\n",
sizeof(buf)-count);
if (sent < 0)
{
- printf("read failed offset:%d size:%d (%s)\n",
- count, sizeof(buf)-count,
- cli_errstr(c));
+ printf("read failed offset:%d size:%ld (%s)\n",
+ count, (unsigned long)sizeof(buf)-count,
+ cli_errstr(c));
correct = False;
sent = 0;
}
if (memcmp(buf_rd+count, buf+count, sent) != 0)
{
printf("read/write compare failed\n");
- printf("offset: %d req %d recvd %d\n",
- count, sizeof(buf)-count, sent);
+ printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
correct = False;
break;
}
printf("%d\r", i); fflush(stdout);
}
- generate_random_buffer(buf, buf_size, False);
+ generate_random_buffer(buf, buf_size);
if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
printf("write failed (%s)\n", cli_errstr(c1));
if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
printf("read failed (%s)\n", cli_errstr(c2));
- printf("read %d, expected %d\n", bytes_read, buf_size);
+ printf("read %d, expected %ld\n", bytes_read,
+ (unsigned long)buf_size);
correct = False;
break;
}
static BOOL run_readwritetest(int dummy)
{
static struct cli_state *cli1, *cli2;
- BOOL test1, test2;
+ BOOL test1, test2 = False;
if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
return False;
static struct cli_state *cli1;
int fnum1;
const char *lockfname = "\\large.dat";
- size_t fsize;
+ SMB_OFF_T fsize;
char buf[126*1024];
BOOL correct = True;
}
if (fsize == sizeof(buf))
- printf("readwritelarge test 1 succeeded (size = %x)\n", fsize);
+ printf("readwritelarge test 1 succeeded (size = %lx)\n",
+ (unsigned long)fsize);
else {
- printf("readwritelarge test 1 failed (size = %x)\n", fsize);
+ printf("readwritelarge test 1 failed (size = %lx)\n",
+ (unsigned long)fsize);
correct = False;
}
}
if (fsize == sizeof(buf))
- printf("readwritelarge test 2 succeeded (size = %x)\n", fsize);
+ printf("readwritelarge test 2 succeeded (size = %lx)\n",
+ (unsigned long)fsize);
else {
- printf("readwritelarge test 2 failed (size = %x)\n", fsize);
+ printf("readwritelarge test 2 failed (size = %lx)\n",
+ (unsigned long)fsize);
correct = False;
}
{
struct cli_state *cli;
int i;
- fstring fname;
pstring line;
char cname[20];
FILE *f;
nb_setup(cli);
- slprintf(cname,sizeof(fname), "client%d", client);
+ slprintf(cname,sizeof(cname)-1, "client%d", client);
f = fopen(client_txt, "r");
lock_timeout = (1 + (random() % 20));
printf("Testing lock timeout with timeout=%u\n", lock_timeout);
t1 = time(NULL);
- if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 500, WRITE_LOCK)) {
+ if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
printf("lock3 succeeded! This is a locking bug\n");
return False;
} else {
static BOOL run_maxfidtest(int dummy)
{
struct cli_state *cli;
- const char *template = "\\maxfid.%d.%d";
+ const char *ftemplate = "\\maxfid.%d.%d";
fstring fname;
int fnums[0x11000], i;
int retries=4;
cli_sockopt(cli, sockops);
for (i=0; i<0x11000; i++) {
- slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
+ slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
if ((fnums[i] = cli_open(cli, fname,
O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
-1) {
printf("cleaning up\n");
for (;i>=0;i--) {
- slprintf(fname,sizeof(fname)-1,template, i,(int)getpid());
+ slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
cli_close(cli, fnums[i]);
if (!cli_unlink(cli, fname)) {
printf("unlink of %s failed (%s)\n",
{
struct cli_state *cli;
int fnum;
- size_t size;
+ SMB_OFF_T size;
time_t c_time, a_time, m_time, w_time, m_time2;
const char *fname = "\\trans2.tst";
const char *dname = "\\trans2";
static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
{
- char buf[4096];
+ char *buf = NULL;
+ uint32 len;
BOOL correct = True;
- memset(buf, 0xff, sizeof(buf));
-
- if (!cli_qfileinfo_test(pcli, fnum, level, buf)) {
+ if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
correct = False;
} else {
- printf("qfileinfo: level %d\n", level);
- dump_data(0, buf, 256);
+ printf("qfileinfo: level %d, len = %u\n", level, len);
+ dump_data(0, buf, len);
printf("\n");
}
+ SAFE_FREE(buf);
return correct;
}
sleep(2);
- /* Ensure cli1 processes the break. */
+ /* Ensure cli1 processes the break. Empty file should always return 0
+ * bytes. */
- if (cli_read(cli1, fnum1, buf, 0, 4) != 4) {
+ if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
correct = False;
}
*/
static BOOL run_deletetest(int dummy)
{
- struct cli_state *cli1;
- struct cli_state *cli2;
+ struct cli_state *cli1 = NULL;
+ struct cli_state *cli2 = NULL;
const char *fname = "\\delete.file";
int fnum1 = -1;
int fnum2 = -1;
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname);
- fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_DELETE, FILE_OVERWRITE_IF,
+ fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ 0, FILE_OVERWRITE_IF,
FILE_DELETE_ON_CLOSE, 0);
if (fnum1 == -1) {
correct = False;
goto fail;
}
-
+
+#if 0 /* JRATEST */
+ {
+ uint32 *accinfo = NULL;
+ uint32 len;
+ cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
+ if (accinfo)
+ printf("access mode = 0x%lx\n", *accinfo);
+ SAFE_FREE(accinfo);
+ }
+#endif
+
if (!cli_close(cli1, fnum1)) {
printf("[1] close failed (%s)\n", cli_errstr(cli1));
correct = False;
FILE_OVERWRITE_IF, 0, 0);
if (fnum1 == -1) {
- printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
correct = False;
goto fail;
}
FILE_OPEN, 0, 0);
if (fnum2 == -1) {
- printf("[8] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+ printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
correct = False;
goto fail;
}
correct = False;
} else
printf("tenth delete on close test succeeded.\n");
+
+ cli_setatr(cli1, fname, 0, 0);
+ cli_unlink(cli1, fname);
+
+ /* What error do we get when attempting to open a read-only file with
+ delete access ? */
+
+ /* Create a readonly file. */
+ fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
+ FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
+ if (fnum1 == -1) {
+ printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
+ correct = False;
+ goto fail;
+ }
+
+ if (!cli_close(cli1, fnum1)) {
+ printf("[11] close failed (%s)\n", cli_errstr(cli1));
+ correct = False;
+ goto fail;
+ }
+
+ /* Now try open for delete access. */
+ fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
+ 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OVERWRITE_IF, 0, 0);
+
+ if (fnum1 != -1) {
+ printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
+ cli_close(cli1, fnum1);
+ goto fail;
+ correct = False;
+ } else {
+ NTSTATUS nterr = cli_nt_error(cli1);
+ if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
+ printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
+ goto fail;
+ correct = False;
+ } else {
+ printf("eleventh delete on close test succeeded.\n");
+ }
+ }
+
printf("finished delete test\n");
fail:
* intialized, because these functions don't handle
* uninitialized connections. */
- cli_close(cli1, fnum1);
- cli_close(cli1, fnum2);
+ if (fnum1 != -1) cli_close(cli1, fnum1);
+ if (fnum2 != -1) cli_close(cli1, fnum2);
cli_setatr(cli1, fname, 0, 0);
cli_unlink(cli1, fname);
- if (!torture_close_connection(cli1)) {
+ if (cli1 && !torture_close_connection(cli1)) {
correct = False;
}
- if (!torture_close_connection(cli2)) {
+ if (cli2 && !torture_close_connection(cli2)) {
correct = False;
}
return correct;
}
if (!cli_rename(cli1, fname, fname1)) {
- printf("First rename failed (this is correct) - %s\n", cli_errstr(cli1));
+ printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
} else {
- printf("First rename succeeded - this should have failed !\n");
+ printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
correct = False;
}
}
if (!cli_rename(cli1, fname, fname1)) {
- printf("Second rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
+ printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
correct = False;
} else {
- printf("Second rename succeeded\n");
+ printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
}
if (!cli_close(cli1, fnum1)) {
#endif
if (!cli_rename(cli1, fname, fname1)) {
- printf("Third rename failed - this should have succeeded - %s\n", cli_errstr(cli1));
+ printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
correct = False;
} else {
- printf("Third rename succeeded\n");
+ printf("Third rename succeeded (SHARE_NONE)\n");
}
if (!cli_close(cli1, fnum1)) {
cli_unlink(cli1, fname);
cli_unlink(cli1, fname1);
+ /*----*/
+
+ fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
+
+ if (fnum1 == -1) {
+ printf("Fourth open failed - %s\n", cli_errstr(cli1));
+ return False;
+ }
+
+ if (!cli_rename(cli1, fname, fname1)) {
+ printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
+ } else {
+ printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
+ correct = False;
+ }
+
+ if (!cli_close(cli1, fnum1)) {
+ printf("close - 4 failed (%s)\n", cli_errstr(cli1));
+ return False;
+ }
+
+ cli_unlink(cli1, fname);
+ cli_unlink(cli1, fname1);
+
+ /*--*/
+
+ fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
+
+ if (fnum1 == -1) {
+ printf("Fifth open failed - %s\n", cli_errstr(cli1));
+ return False;
+ }
+
+ if (!cli_rename(cli1, fname, fname1)) {
+ printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
+ correct = False;
+ } else {
+ printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
+ }
+
+ /*
+ * Now check if the first name still exists ...
+ */
+
+ /*fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
+
+ if (fnum2 == -1) {
+ 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);
+ } */
+
+ /*--*/
+
+
+ if (!cli_close(cli1, fnum1)) {
+ printf("close - 5 failed (%s)\n", cli_errstr(cli1));
+ return False;
+ }
+
+ cli_unlink(cli1, fname);
+ cli_unlink(cli1, fname1);
+
if (!torture_close_connection(cli1)) {
correct = False;
}
const char *fname = "\\readonly.file";
int fnum1, fnum2;
char buf[20];
- size_t fsize;
+ SMB_OFF_T fsize;
BOOL correct = True;
char *tmp_path;
return correct;
}
-static void list_fn(file_info *finfo, const char *name, void *state)
+static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
{
}
return correct;
}
-static void del_fn(file_info *finfo, const char *mask, void *state)
+static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
{
struct cli_state *pcli = (struct cli_state *)state;
fstring fname;
return ret;
}
+static BOOL run_eatest(int dummy)
+{
+ static struct cli_state *cli;
+ const char *fname = "\\eatest.txt";
+ BOOL correct = True;
+ int fnum, i;
+ size_t num_eas;
+ struct ea_struct *ea_list = NULL;
+ TALLOC_CTX *mem_ctx = talloc_init("eatest");
+
+ printf("starting eatest\n");
+
+ if (!torture_open_connection(&cli)) {
+ return False;
+ }
+
+ cli_unlink(cli, fname);
+ fnum = cli_nt_create_full(cli, fname, 0,
+ FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
+ FILE_SHARE_NONE, FILE_OVERWRITE_IF,
+ 0x4044, 0);
+
+ if (fnum == -1) {
+ printf("open failed - %s\n", cli_errstr(cli));
+ return False;
+ }
+ for (i = 0; i < 10; i++) {
+ fstring ea_name, ea_val;
+ slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
+ memset(ea_val, (char)i+1, i+1);
+ if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
+ printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+ return False;
+ }
+ }
+
+ cli_close(cli, fnum);
+ for (i = 0; i < 10; i++) {
+ fstring ea_name, ea_val;
+
+ slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
+ memset(ea_val, (char)i+1, i+1);
+ if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
+ printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+ return False;
+ }
+ }
+
+ if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
+ printf("ea_get list failed - %s\n", cli_errstr(cli));
+ correct = False;
+ }
+
+ printf("num_eas = %d\n", num_eas);
+
+ if (num_eas != 20) {
+ printf("Should be 20 EA's stored... failing.\n");
+ correct = False;
+ }
+
+ for (i = 0; i < num_eas; i++) {
+ printf("%d: 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");
+
+ for (i = 0; i < 20; i++) {
+ fstring ea_name;
+ slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
+ if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
+ printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
+ return False;
+ }
+ }
+
+ if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
+ printf("ea_get list failed - %s\n", cli_errstr(cli));
+ correct = False;
+ }
+
+ printf("num_eas = %d\n", num_eas);
+ for (i = 0; i < num_eas; i++) {
+ printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
+ dump_data(0, ea_list[i].value.data, ea_list[i].value.length);
+ }
+
+ if (num_eas != 0) {
+ printf("deleting EA's failed.\n");
+ correct = False;
+ }
+
+ /* Try and delete a non existant EA. */
+ if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
+ printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
+ correct = False;
+ }
+
+ talloc_destroy(mem_ctx);
+ if (!torture_close_connection(cli)) {
+ correct = False;
+ }
+
+ return correct;
+}
static BOOL run_dirtest1(int dummy)
{
printf("pid %d failed to start\n", (int)getpid());
_exit(1);
}
- msleep(10);
+ smb_msleep(10);
}
child_status[i] = getpid();
- while (child_status[i] && end_timer() < 5) msleep(2);
+ while (child_status[i] && end_timer() < 5) smb_msleep(2);
child_status_out[i] = fn(i);
_exit(0);
if (child_status[i]) synccount++;
}
if (synccount == nprocs) break;
- msleep(10);
+ smb_msleep(10);
} while (end_timer() < 30);
if (synccount != nprocs) {
{"IOCTL", torture_ioctl_test, 0},
{"CHKPATH", torture_chkpath_test, 0},
{"FDSESS", run_fdsesstest, 0},
+ { "EATEST", run_eatest, 0},
{NULL, NULL, 0}};
{
BOOL ret = True;
BOOL result = True;
+ BOOL found = False;
int i;
double t;
if (strequal(name,"ALL")) {
for (i=0;torture_ops[i].name;i++) {
run_test(torture_ops[i].name);
}
+ found = True;
}
for (i=0;torture_ops[i].name;i++) {
(unsigned)random());
if (strequal(name, torture_ops[i].name)) {
+ found = True;
printf("Running %s\n", name);
if (torture_ops[i].flags & FLAG_MULTIPROC) {
t = create_procs(torture_ops[i].fn, &result);
printf("%s took %g secs\n\n", name, t);
}
}
+
+ if (!found) {
+ printf("Did not find a test named %s\n", name);
+ ret = False;
+ }
+
return ret;
}
{
int i;
+ printf("WARNING samba4 test suite is much more complete nowadays.\n");
+ printf("Please use samba4 torture.\n\n");
+
printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
printf("\t-d debuglevel\n");
char *p;
int gotuser = 0;
int gotpass = 0;
- extern char *optarg;
- extern int optind;
BOOL correct = True;
dbf = x_stdout;
printf("host=%s share=%s user=%s myname=%s\n",
host, share, username, myname);
- if (argc == 1) {
+ if (argc == optind) {
correct = run_test("ALL");
} else {
- for (i=1;i<argc;i++) {
+ for (i=optind;i<argc;i++) {
if (!run_test(argv[i])) {
correct = False;
}