2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define CHECK_STATUS(status, correct) do { \
24 if (!NT_STATUS_EQUAL(status, correct)) { \
25 printf("(%d) Incorrect status %s - should be %s\n", \
26 __LINE__, nt_errstr(status), nt_errstr(correct)); \
31 #define BASEDIR "\\testrename"
36 static BOOL test_mv(struct cli_state *cli, TALLOC_CTX *mem_ctx)
42 const char *fname1 = BASEDIR "\\test1.txt";
43 const char *fname2 = BASEDIR "\\test2.txt";
45 if (cli_deltree(cli, BASEDIR) == -1 ||
46 !cli_mkdir(cli, BASEDIR)) {
47 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli));
51 printf("Trying simple rename\n");
53 fnum = create_complex_file(cli, mem_ctx, fname1);
55 io.in.pattern1 = fname1;
56 io.in.pattern2 = fname2;
59 status = smb_raw_rename(cli->tree, &io);
60 CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
62 smb_raw_exit(cli->session);
63 status = smb_raw_rename(cli->tree, &io);
64 CHECK_STATUS(status, NT_STATUS_OK);
67 printf("trying wildcard rename\n");
68 io.in.pattern1 = BASEDIR "\\*.txt";
69 io.in.pattern2 = fname1;
71 status = smb_raw_rename(cli->tree, &io);
72 CHECK_STATUS(status, NT_STATUS_OK);
74 printf("and again\n");
75 status = smb_raw_rename(cli->tree, &io);
76 CHECK_STATUS(status, NT_STATUS_OK);
78 printf("Trying extension change\n");
79 io.in.pattern1 = BASEDIR "\\*.txt";
80 io.in.pattern2 = BASEDIR "\\*.bak";
81 status = smb_raw_rename(cli->tree, &io);
82 CHECK_STATUS(status, NT_STATUS_OK);
84 status = smb_raw_rename(cli->tree, &io);
85 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
87 printf("Checking attrib handling\n");
88 torture_set_file_attribute(cli->tree, BASEDIR "\\test1.bak", FILE_ATTRIBUTE_HIDDEN);
89 io.in.pattern1 = BASEDIR "\\test1.bak";
90 io.in.pattern2 = BASEDIR "\\*.txt";
92 status = smb_raw_rename(cli->tree, &io);
93 CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
95 io.in.attrib = FILE_ATTRIBUTE_HIDDEN;
96 status = smb_raw_rename(cli->tree, &io);
97 CHECK_STATUS(status, NT_STATUS_OK);
100 smb_raw_exit(cli->session);
101 cli_deltree(cli, BASEDIR);
107 basic testing of rename calls
109 BOOL torture_raw_rename(int dummy)
111 struct cli_state *cli;
115 if (!torture_open_connection(&cli)) {
119 mem_ctx = talloc_init("torture_raw_rename");
121 if (!test_mv(cli, mem_ctx)) {
125 torture_close_connection(cli);
126 talloc_destroy(mem_ctx);