r1654: rename cli_ -> smbcli_
[jelmer/samba4-debian.git] / source / torture / raw / chkpath.c
1 /* 
2    Unix SMB/CIFS implementation.
3    chkpath individual 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 BASEDIR "\\rawchkpath"
24
25 #define CHECK_STATUS(status, correct) do { \
26         if (!NT_STATUS_EQUAL(status, correct)) { \
27                 printf("(%d) Incorrect status %s - should be %s\n", \
28                        __LINE__, nt_errstr(status), nt_errstr(correct)); \
29                 ret = False; \
30                 goto done; \
31         }} while (0)
32
33
34 static BOOL test_chkpath(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
35 {
36         struct smb_chkpath io;
37         NTSTATUS status;
38         BOOL ret = True;
39         int fnum = -1;
40
41         io.in.path = BASEDIR;
42
43         status = smb_raw_chkpath(cli->tree, &io);
44         CHECK_STATUS(status, NT_STATUS_OK);
45
46         io.in.path = BASEDIR "\\nodir";
47         status = smb_raw_chkpath(cli->tree, &io);
48         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
49
50         fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\test.txt");
51         if (fnum == -1) {
52                 printf("failed to open test.txt - %s\n", smbcli_errstr(cli->tree));
53                 ret = False;
54                 goto done;
55         }
56
57         io.in.path = BASEDIR "\\test.txt";
58         printf("testing %s\n", io.in.path);
59         status = smb_raw_chkpath(cli->tree, &io);
60         CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
61         
62         if (!torture_set_file_attribute(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN)) {
63                 printf("failed to set basedir hidden\n");
64                 ret = False;
65                 goto done;
66         }
67
68         io.in.path = BASEDIR;
69         printf("testing %s\n", io.in.path);
70         status = smb_raw_chkpath(cli->tree, &io);
71         CHECK_STATUS(status, NT_STATUS_OK);
72
73         io.in.path = "";
74         printf("testing %s\n", io.in.path);
75         status = smb_raw_chkpath(cli->tree, &io);
76         CHECK_STATUS(status, NT_STATUS_OK);
77
78         io.in.path = ".";
79         printf("testing %s\n", io.in.path);
80         status = smb_raw_chkpath(cli->tree, &io);
81         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
82
83         io.in.path = "\\";
84         printf("testing %s\n", io.in.path);
85         status = smb_raw_chkpath(cli->tree, &io);
86         CHECK_STATUS(status, NT_STATUS_OK);
87
88         io.in.path = "\\.";
89         printf("testing %s\n", io.in.path);
90         status = smb_raw_chkpath(cli->tree, &io);
91         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
92
93         io.in.path = "\\..";
94         printf("testing %s\n", io.in.path);
95         status = smb_raw_chkpath(cli->tree, &io);
96         CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
97
98         io.in.path = BASEDIR "\\.";
99         printf("testing %s\n", io.in.path);
100         status = smb_raw_chkpath(cli->tree, &io);
101         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
102
103         io.in.path = BASEDIR "\\..";
104         printf("testing %s\n", io.in.path);
105         status = smb_raw_chkpath(cli->tree, &io);
106         CHECK_STATUS(status, NT_STATUS_OK);
107
108         io.in.path = BASEDIR "\\nt\\Visual Studio\\VB98\\vb600";
109         printf("testing %s\n", io.in.path);
110         status = smb_raw_chkpath(cli->tree, &io);
111         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
112
113         io.in.path = BASEDIR "\\nt\\Visual Studio\\VB98\\vb6.exe";
114         printf("testing %s\n", io.in.path);
115         status = smb_raw_chkpath(cli->tree, &io);
116         CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
117
118         io.in.path = BASEDIR "\\nt\\Visual Studio\\VB98\\vb6.exe\\3";
119         printf("testing %s\n", io.in.path);
120         status = smb_raw_chkpath(cli->tree, &io);
121         CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_NOT_FOUND);
122
123         io.in.path = BASEDIR "\\nt\\Visual Studio\\*\\vb6.exe\\3";
124         printf("testing %s\n", io.in.path);
125         status = smb_raw_chkpath(cli->tree, &io);
126         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
127
128 done:
129         smbcli_close(cli->tree, fnum);
130         return ret;
131 }
132
133 /* 
134    basic testing of chkpath calls 
135 */
136 BOOL torture_raw_chkpath(int dummy)
137 {
138         struct smbcli_state *cli;
139         BOOL ret = True;
140         int fnum;
141         TALLOC_CTX *mem_ctx;
142
143         if (!torture_open_connection(&cli)) {
144                 return False;
145         }
146
147         mem_ctx = talloc_init("torture_raw_chkpath");
148
149         if (smbcli_deltree(cli->tree, BASEDIR) == -1) {
150                 printf("Failed to clean " BASEDIR "\n");
151                 return False;
152         }
153         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
154                 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
155                 return False;
156         }
157
158         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR "\\nt"))) {
159                 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
160                 return False;
161         }
162
163         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR "\\nt\\Visual Studio"))) {
164                 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
165                 return False;
166         }
167
168         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR "\\nt\\Visual Studio\\VB98"))) {
169                 printf("Failed to create " BASEDIR " - %s\n", smbcli_errstr(cli->tree));
170                 return False;
171         }
172
173         fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\nt\\Visual Studio\\VB98\\vb6.exe");
174         if (fnum == -1) {
175                 printf("failed to open \\nt\\Visual Studio\\VB98\\vb6.exe - %s\n", smbcli_errstr(cli->tree));
176                 ret = False;
177                 goto done;
178         }
179
180         if (!test_chkpath(cli, mem_ctx)) {
181                 ret = False;
182         }
183
184  done:
185
186         smb_raw_exit(cli->session);
187         smbcli_deltree(cli->tree, BASEDIR);
188
189         torture_close_connection(cli);
190         talloc_destroy(mem_ctx);
191         return ret;
192 }