first public release of samba4 code
[bbaumbach/samba-autobuild/.git] / source4 / torture / raw / rename.c
1 /* 
2    Unix SMB/CIFS implementation.
3    rename test suite
4    Copyright (C) Andrew Tridgell 2003
5    
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.
10    
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.
15    
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.
19 */
20
21 #include "includes.h"
22
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)); \
27                 ret = False; \
28                 goto done; \
29         }} while (0)
30
31 #define BASEDIR "\\testrename"
32
33 /*
34   test SMBmv ops
35 */
36 static BOOL test_mv(struct cli_state *cli, TALLOC_CTX *mem_ctx)
37 {
38         struct smb_rename io;
39         NTSTATUS status;
40         BOOL ret = True;
41         int fnum;
42         const char *fname1 = BASEDIR "\\test1.txt";
43         const char *fname2 = BASEDIR "\\test2.txt";
44
45         if (cli_deltree(cli, BASEDIR) == -1 ||
46             !cli_mkdir(cli, BASEDIR)) {
47                 printf("Unable to setup %s - %s\n", BASEDIR, cli_errstr(cli));
48                 return False;
49         }
50
51         printf("Trying simple rename\n");
52
53         fnum = create_complex_file(cli, mem_ctx, fname1);
54         
55         io.in.pattern1 = fname1;
56         io.in.pattern2 = fname2;
57         io.in.attrib = 0;
58         
59         status = smb_raw_rename(cli->tree, &io);
60         CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
61         
62         smb_raw_exit(cli->session);
63         status = smb_raw_rename(cli->tree, &io);
64         CHECK_STATUS(status, NT_STATUS_OK);
65
66
67         printf("trying wildcard rename\n");
68         io.in.pattern1 = BASEDIR "\\*.txt";
69         io.in.pattern2 = fname1;
70         
71         status = smb_raw_rename(cli->tree, &io);
72         CHECK_STATUS(status, NT_STATUS_OK);
73
74         printf("and again\n");
75         status = smb_raw_rename(cli->tree, &io);
76         CHECK_STATUS(status, NT_STATUS_OK);
77
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);
83
84         status = smb_raw_rename(cli->tree, &io);
85         CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
86
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";
91         io.in.attrib = 0;
92         status = smb_raw_rename(cli->tree, &io);
93         CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE);
94
95         io.in.attrib = FILE_ATTRIBUTE_HIDDEN;
96         status = smb_raw_rename(cli->tree, &io);
97         CHECK_STATUS(status, NT_STATUS_OK);
98
99 done:
100         smb_raw_exit(cli->session);
101         cli_deltree(cli, BASEDIR);
102         return ret;
103 }
104
105
106 /* 
107    basic testing of rename calls
108 */
109 BOOL torture_raw_rename(int dummy)
110 {
111         struct cli_state *cli;
112         BOOL ret = True;
113         TALLOC_CTX *mem_ctx;
114
115         if (!torture_open_connection(&cli)) {
116                 return False;
117         }
118
119         mem_ctx = talloc_init("torture_raw_rename");
120
121         if (!test_mv(cli, mem_ctx)) {
122                 ret = False;
123         }
124
125         torture_close_connection(cli);
126         talloc_destroy(mem_ctx);
127         return ret;
128 }