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"
28 Test rename on files open with share delete and no share delete.
30 BOOL torture_test_rename(void)
32 struct smbcli_state *cli1;
33 const char *fname = "\\test.txt";
34 const char *fname1 = "\\test1.txt";
38 printf("starting rename test\n");
40 if (!torture_open_connection(&cli1)) {
44 smbcli_unlink(cli1->tree, fname);
45 smbcli_unlink(cli1->tree, fname1);
46 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
48 FILE_ATTRIBUTE_NORMAL,
49 NTCREATEX_SHARE_ACCESS_READ,
50 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
53 printf("(%s) First open failed - %s\n",
54 __location__, smbcli_errstr(cli1->tree));
58 if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) {
59 printf("First rename failed (this is correct) - %s\n", smbcli_errstr(cli1->tree));
61 printf("(%s) First rename succeeded - this should have failed !\n",
66 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
67 printf("(%s) close - 1 failed (%s)\n", __location__, smbcli_errstr(cli1->tree));
71 smbcli_unlink(cli1->tree, fname);
72 smbcli_unlink(cli1->tree, fname1);
73 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
75 FILE_ATTRIBUTE_NORMAL,
76 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ,
77 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
80 printf("(%s) Second open failed - %s\n", __location__, smbcli_errstr(cli1->tree));
84 if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) {
85 printf("(%s) Second rename failed - this should have succeeded - %s\n",
86 __location__, smbcli_errstr(cli1->tree));
89 printf("Second rename succeeded\n");
92 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
93 printf("(%s) close - 2 failed (%s)\n",
94 __location__, smbcli_errstr(cli1->tree));
98 smbcli_unlink(cli1->tree, fname);
99 smbcli_unlink(cli1->tree, fname1);
101 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
102 SEC_STD_READ_CONTROL,
103 FILE_ATTRIBUTE_NORMAL,
104 NTCREATEX_SHARE_ACCESS_NONE,
105 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
108 printf("(%s) Third open failed - %s\n", __location__, smbcli_errstr(cli1->tree));
113 if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) {
114 printf("(%s) Third rename failed - this should have succeeded - %s\n",
115 __location__, smbcli_errstr(cli1->tree));
118 printf("Third rename succeeded\n");
121 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
122 printf("(%s) close - 3 failed (%s)\n",
123 __location__, smbcli_errstr(cli1->tree));
127 smbcli_unlink(cli1->tree, fname);
128 smbcli_unlink(cli1->tree, fname1);
130 if (!torture_close_connection(cli1)) {