summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-02-22 01:08:19 +0000
committerJeremy Allison <jra@samba.org>2003-02-22 01:08:19 +0000
commitca2e9955764fa0bec3ace1fc049f13bb8e2961ac (patch)
treeed744d8c99e0356391f2d6dca61e2785967ccc8a
parent301ebd6324138b9628638c0020597227d0cbf959 (diff)
downloadsamba-ca2e9955764fa0bec3ace1fc049f13bb8e2961ac.tar.gz
samba-ca2e9955764fa0bec3ace1fc049f13bb8e2961ac.tar.bz2
samba-ca2e9955764fa0bec3ace1fc049f13bb8e2961ac.zip
New locktest7 code based on patch from "Srikanta Shivanna" <sshivanna@pillardata.com>
Jeremy. (This used to be commit caf298c3808cbdd683e884b32b7a0538505a3066)
-rw-r--r--source3/torture/torture.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 97e864de96..fe53baae7e 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -1569,6 +1569,139 @@ static BOOL run_locktest6(int dummy)
return True;
}
+static BOOL run_locktest7(int dummy)
+{
+ static struct cli_state cli1;
+ const char *fname = "\\lockt7.lck";
+ int fnum1;
+ char buf[200];
+ BOOL correct = False;
+
+ if (!torture_open_connection(&cli1)) {
+ return False;
+ }
+
+ cli_sockopt(&cli1, sockops);
+
+ printf("starting locktest7\n");
+
+ cli_unlink(&cli1, fname);
+
+ fnum1 = cli_open(&cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
+
+ memset(buf, 0, sizeof(buf));
+
+ if (cli_write(&cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
+ printf("Failed to create file\n");
+ goto fail;
+ }
+
+ cli_setpid(&cli1, 1);
+
+ if (!cli_lock(&cli1, fnum1, 130, 4, 0, READ_LOCK)) {
+ printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(&cli1));
+ goto fail;
+ } else {
+ printf("pid1 successfully locked range 130:4 for READ\n");
+ }
+
+ if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) {
+ printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1));
+ goto fail;
+ } else {
+ printf("pid1 successfully read the range 130:4\n");
+ }
+
+ if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) {
+ printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1));
+ if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
+ printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
+ goto fail;
+ }
+ } else {
+ printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
+ goto fail;
+ }
+
+ cli_setpid(&cli1, 2);
+
+ if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) {
+ printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1));
+ } else {
+ printf("pid2 successfully read the range 130:4\n");
+ }
+
+ if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) {
+ printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1));
+ if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
+ printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
+ goto fail;
+ }
+ } else {
+ printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
+ goto fail;
+ }
+
+ cli_setpid(&cli1, 1);
+ cli_unlock(&cli1, fnum1, 130, 4);
+
+ if (!cli_lock(&cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
+ printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(&cli1));
+ goto fail;
+ } else {
+ printf("pid1 successfully locked range 130:4 for WRITE\n");
+ }
+
+ if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) {
+ printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1));
+ goto fail;
+ } else {
+ printf("pid1 successfully read the range 130:4\n");
+ }
+
+ if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) {
+ printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1));
+ goto fail;
+ } else {
+ printf("pid1 successfully wrote to the range 130:4\n");
+ }
+
+ cli_setpid(&cli1, 2);
+
+ if (cli_read(&cli1, fnum1, buf, 130, 4) != 4) {
+ printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(&cli1));
+ if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
+ printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
+ goto fail;
+ }
+ } else {
+ printf("pid2 successfully read the range 130:4 (should be denied)\n");
+ goto fail;
+ }
+
+ if (cli_write(&cli1, fnum1, 0, buf, 130, 4) != 4) {
+ printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(&cli1));
+ if (NT_STATUS_V(cli_nt_error(&cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
+ printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
+ goto fail;
+ }
+ } else {
+ printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
+ goto fail;
+ }
+
+ cli_unlock(&cli1, fnum1, 130, 0);
+ correct = True;
+
+fail:
+ cli_close(&cli1, fnum1);
+ cli_unlink(&cli1, fname);
+ torture_close_connection(&cli1);
+
+ printf("finished locktest7\n");
+ return correct;
+}
+
/*
test whether fnums and tids open on one VC are available on another (a major
security hole)
@@ -3956,6 +4089,7 @@ static struct {
{"LOCK4", run_locktest4, 0},
{"LOCK5", run_locktest5, 0},
{"LOCK6", run_locktest6, 0},
+ {"LOCK7", run_locktest7, 0},
{"UNLINK", run_unlinktest, 0},
{"BROWSE", run_browsetest, 0},
{"ATTR", run_attrtest, 0},