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 *torture)
33 struct smbcli_state *cli1;
34 const char *fname = "\\test.txt";
35 const char *fname1 = "\\test1.txt";
39 printf("starting rename test\n");
41 if (!torture_open_connection(&cli1)) {
45 smbcli_unlink(cli1->tree, fname);
46 smbcli_unlink(cli1->tree, fname1);
47 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
49 FILE_ATTRIBUTE_NORMAL,
50 NTCREATEX_SHARE_ACCESS_READ,
51 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
54 printf("(%s) First open failed - %s\n",
55 __location__, smbcli_errstr(cli1->tree));
59 if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) {
60 printf("First rename failed (this is correct) - %s\n", smbcli_errstr(cli1->tree));
62 printf("(%s) First rename succeeded - this should have failed !\n",
67 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
68 printf("(%s) close - 1 failed (%s)\n", __location__, smbcli_errstr(cli1->tree));
72 smbcli_unlink(cli1->tree, fname);
73 smbcli_unlink(cli1->tree, fname1);
74 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
76 FILE_ATTRIBUTE_NORMAL,
77 NTCREATEX_SHARE_ACCESS_DELETE|NTCREATEX_SHARE_ACCESS_READ,
78 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
81 printf("(%s) Second open failed - %s\n", __location__, smbcli_errstr(cli1->tree));
85 if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) {
86 printf("(%s) Second rename failed - this should have succeeded - %s\n",
87 __location__, smbcli_errstr(cli1->tree));
90 printf("Second rename succeeded\n");
93 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
94 printf("(%s) close - 2 failed (%s)\n",
95 __location__, smbcli_errstr(cli1->tree));
99 smbcli_unlink(cli1->tree, fname);
100 smbcli_unlink(cli1->tree, fname1);
102 fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
103 SEC_STD_READ_CONTROL,
104 FILE_ATTRIBUTE_NORMAL,
105 NTCREATEX_SHARE_ACCESS_NONE,
106 NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
109 printf("(%s) Third open failed - %s\n", __location__, smbcli_errstr(cli1->tree));
114 if (NT_STATUS_IS_ERR(smbcli_rename(cli1->tree, fname, fname1))) {
115 printf("(%s) Third rename failed - this should have succeeded - %s\n",
116 __location__, smbcli_errstr(cli1->tree));
119 printf("Third rename succeeded\n");
122 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
123 printf("(%s) close - 3 failed (%s)\n",
124 __location__, smbcli_errstr(cli1->tree));
128 smbcli_unlink(cli1->tree, fname);
129 smbcli_unlink(cli1->tree, fname1);
131 if (!torture_close_connection(cli1)) {