2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/libcli.h"
25 #include "torture/torture.h"
26 #include "torture/util.h"
29 Test rename on files open with share delete and no share delete.
31 BOOL torture_test_rename(struct torture_context *tctx,
32 struct smbcli_state *cli1)
34 const char *fname = "\\test.txt";
35 const char *fname1 = "\\test1.txt";
38 smbcli_unlink(cli1->tree, fname);
39 smbcli_unlink(cli1->tree, fname1);
40 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
42 FILE_ATTRIBUTE_NORMAL,
43 NTCREATEX_SHARE_ACCESS_READ,
44 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
46 torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "First open failed - %s",
47 smbcli_errstr(cli1->tree)));
49 torture_assert(tctx, NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1)),
50 "First rename succeeded - this should have failed !");
52 torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
53 talloc_asprintf(tctx, "close - 1 failed (%s)", smbcli_errstr(cli1->tree)));
55 smbcli_unlink(cli1->tree, fname);
56 smbcli_unlink(cli1->tree, fname1);
57 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
59 FILE_ATTRIBUTE_NORMAL,
60 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ,
61 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
63 torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx,
64 "Second open failed - %s", smbcli_errstr(cli1->tree)));
66 torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1),
68 "Second rename failed - this should have succeeded - %s",
69 smbcli_errstr(cli1->tree)));
71 torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
73 "close - 2 failed (%s)", smbcli_errstr(cli1->tree)));
75 smbcli_unlink(cli1->tree, fname);
76 smbcli_unlink(cli1->tree, fname1);
78 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
80 FILE_ATTRIBUTE_NORMAL,
81 NTCREATEX_SHARE_ACCESS_NONE,
82 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
84 torture_assert(tctx, fnum1 != -1, talloc_asprintf(tctx, "Third open failed - %s",
85 smbcli_errstr(cli1->tree)));
87 torture_assert_ntstatus_ok(tctx, smbcli_rename(cli1->tree, fname, fname1),
88 talloc_asprintf(tctx, "Third rename failed - this should have succeeded - %s",
89 smbcli_errstr(cli1->tree)));
91 torture_assert_ntstatus_ok(tctx, smbcli_close(cli1->tree, fnum1),
92 talloc_asprintf(tctx, "close - 3 failed (%s)", smbcli_errstr(cli1->tree)));
94 smbcli_unlink(cli1->tree, fname);
95 smbcli_unlink(cli1->tree, fname1);