diff options
author | Jeremy Allison <jra@samba.org> | 2004-05-14 22:07:43 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:53:46 -0500 |
commit | 31b9470996632d717c3c74482308e200906fdb8f (patch) | |
tree | 9c5fc8d0ce2efc4839b50601529ecfd492f773dc | |
parent | 2bc3b3bcec7900cda3841af95ab08e07c3d26c9d (diff) | |
download | samba-31b9470996632d717c3c74482308e200906fdb8f.tar.gz samba-31b9470996632d717c3c74482308e200906fdb8f.tar.bz2 samba-31b9470996632d717c3c74482308e200906fdb8f.zip |
r741: Test from Volker in RAW-OPEN for truncating a file containing locks.
Also added the same ad-hoc test is LOCK7.
Jeremy.
(This used to be commit 6cb21ccda3cb420171e2d5afb3842a6be4bd4d18)
-rw-r--r-- | source4/torture/raw/open.c | 77 | ||||
-rw-r--r-- | source4/torture/torture.c | 33 |
2 files changed, 109 insertions, 1 deletions
diff --git a/source4/torture/raw/open.c b/source4/torture/raw/open.c index 7c575fbe9a..f559632f23 100644 --- a/source4/torture/raw/open.c +++ b/source4/torture/raw/open.c @@ -740,6 +740,79 @@ done: return ret; } +/* + test RAW_OPEN_NTCREATEX with an already opened and byte range locked file + + I've got an application that does a similar sequence of ntcreate&x, + locking&x and another ntcreate&x with + open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the + second open. +*/ +static BOOL test_ntcreatex_brlocked(struct cli_state *cli, TALLOC_CTX *mem_ctx) +{ + union smb_open io, io1; + union smb_lock io2; + struct smb_lock_entry lock[1]; + const char *fname = BASEDIR "\\torture_ntcreatex.txt"; + NTSTATUS status; + BOOL ret = True; + + /* reasonable default parameters */ + io.generic.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.access_mask = 0x2019f; + 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_NON_DIRECTORY_FILE; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; + io.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC | + NTCREATEX_SECURITY_ALL; + io.ntcreatex.in.fname = fname; + + status = smb_raw_open(cli->tree, mem_ctx, &io); + CHECK_STATUS(status, NT_STATUS_OK); + + io2.lockx.level = RAW_LOCK_LOCKX; + io2.lockx.in.fnum = io.ntcreatex.out.fnum; + io2.lockx.in.mode = LOCKING_ANDX_LARGE_FILES; + io2.lockx.in.timeout = 0; + io2.lockx.in.ulock_cnt = 0; + io2.lockx.in.lock_cnt = 1; + lock[0].pid = cli->session->pid; + lock[0].offset = 0; + lock[0].count = 0x1; + io2.lockx.in.locks = &lock[0]; + status = smb_raw_lock(cli->tree, &io2); + CHECK_STATUS(status, NT_STATUS_OK); + + io1.generic.level = RAW_OPEN_NTCREATEX; + io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; + io1.ntcreatex.in.root_fid = 0; + io1.ntcreatex.in.access_mask = 0x20196; + io1.ntcreatex.in.alloc_size = 0; + io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; + io1.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE; + io1.ntcreatex.in.open_disposition = NTCREATEX_DISP_OVERWRITE_IF; + io1.ntcreatex.in.create_options = 0; + io1.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; + io1.ntcreatex.in.security_flags = NTCREATEX_SECURITY_DYNAMIC | + NTCREATEX_SECURITY_ALL; + io1.ntcreatex.in.fname = fname; + + status = smb_raw_open(cli->tree, mem_ctx, &io1); + CHECK_STATUS(status, NT_STATUS_OK); + + done: + cli_close(cli->tree, io.ntcreatex.out.fnum); + cli_close(cli->tree, io1.ntcreatex.out.fnum); + cli_unlink(cli->tree, fname); + return ret; +} /* test RAW_OPEN_MKNEW @@ -917,6 +990,10 @@ BOOL torture_raw_open(int dummy) return False; } + if (!test_ntcreatex_brlocked(cli, mem_ctx)) { + return False; + } + if (!test_open(cli, mem_ctx)) { ret = False; } diff --git a/source4/torture/torture.c b/source4/torture/torture.c index 09ab503274..78674990e8 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -1489,6 +1489,8 @@ static BOOL run_locktest7(int dummy) struct cli_state *cli1; const char *fname = "\\lockt7.lck"; int fnum1; + int fnum2; + size_t size; char buf[200]; BOOL correct = False; @@ -1603,11 +1605,38 @@ static BOOL run_locktest7(int dummy) goto fail; } - cli_unlock(cli1->tree, fnum1, 130, 0); + printf("Testing truncate of locked file.\n"); + + fnum2 = cli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE); + + if (fnum2 == -1) { + printf("Unable to truncate locked file.\n"); + correct = False; + goto fail; + } else { + printf("Truncated locked file.\n"); + } + + if (NT_STATUS_IS_ERR(cli_getatr(cli1->tree, fname, NULL, &size, NULL))) { + printf("getatr failed (%s)\n", cli_errstr(cli1->tree)); + correct = False; + goto fail; + } + + if (size != 0) { + printf("Unable to truncate locked file. Size was %u\n", size); + correct = False; + goto fail; + } + + cli1->session->pid = 1; + + cli_unlock(cli1->tree, fnum1, 130, 4); correct = True; fail: cli_close(cli1->tree, fnum1); + cli_close(cli1->tree, fnum2); cli_unlink(cli1->tree, fname); torture_close_connection(cli1); @@ -3225,7 +3254,9 @@ error_test60: } printf("non-io open test #7 passed.\n"); + error_test70: + cli_unlink(cli1->tree, fname); if (!torture_close_connection(cli1)) { |