pysmbd: Add SMB_ACL_EXECUTE to the mask set by make_simple_acl()
[Samba/gebeck_regimport.git] / source4 / torture / raw / seek.c
blob6bac828942763153eab2ad2a348acc41741fb199
1 /*
2 Unix SMB/CIFS implementation.
3 seek test suite
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 3 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, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "libcli/libcli.h"
23 #include "torture/util.h"
24 #include "torture/raw/proto.h"
26 #define CHECK_STATUS(status, correct) do { \
27 if (!NT_STATUS_EQUAL(status, correct)) { \
28 printf("(%d) Incorrect status %s - should be %s\n", \
29 __LINE__, nt_errstr(status), nt_errstr(correct)); \
30 ret = false; \
31 goto done; \
32 }} while (0)
34 #define CHECK_VALUE(v, correct) do { \
35 if ((v) != (correct)) { \
36 printf("(%d) Incorrect value %s=%d - should be %d\n", \
37 __LINE__, #v, (int)v, (int)correct); \
38 ret = false; \
39 goto done; \
40 }} while (0)
42 #define BASEDIR "\\testseek"
45 test seek ops
47 static bool test_seek(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
49 union smb_seek io;
50 union smb_fileinfo finfo;
51 union smb_setfileinfo sfinfo;
52 NTSTATUS status;
53 bool ret = true;
54 int fnum, fnum2;
55 const char *fname = BASEDIR "\\test.txt";
56 uint8_t c[2];
58 if (!torture_setup_dir(cli, BASEDIR)) {
59 return false;
62 fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
63 if (fnum == -1) {
64 printf("Failed to open test.txt - %s\n", smbcli_errstr(cli->tree));
65 ret = false;
66 goto done;
69 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
70 finfo.position_information.in.file.fnum = fnum;
72 printf("Trying bad handle\n");
73 io.lseek.in.file.fnum = fnum+1;
74 io.lseek.in.mode = SEEK_MODE_START;
75 io.lseek.in.offset = 0;
76 status = smb_raw_seek(cli->tree, &io);
77 CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
79 printf("Trying simple seek\n");
80 io.lseek.in.file.fnum = fnum;
81 io.lseek.in.mode = SEEK_MODE_START;
82 io.lseek.in.offset = 17;
83 status = smb_raw_seek(cli->tree, &io);
84 CHECK_STATUS(status, NT_STATUS_OK);
85 CHECK_VALUE(io.lseek.out.offset, 17);
86 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
87 CHECK_STATUS(status, NT_STATUS_OK);
88 CHECK_VALUE(finfo.position_information.out.position, 0);
90 printf("Trying relative seek\n");
91 io.lseek.in.file.fnum = fnum;
92 io.lseek.in.mode = SEEK_MODE_CURRENT;
93 io.lseek.in.offset = -3;
94 status = smb_raw_seek(cli->tree, &io);
95 CHECK_STATUS(status, NT_STATUS_OK);
96 CHECK_VALUE(io.lseek.out.offset, 14);
98 printf("Trying end seek\n");
99 io.lseek.in.file.fnum = fnum;
100 io.lseek.in.mode = SEEK_MODE_END;
101 io.lseek.in.offset = 0;
102 status = smb_raw_seek(cli->tree, &io);
103 CHECK_STATUS(status, NT_STATUS_OK);
104 finfo.generic.level = RAW_FILEINFO_ALL_INFO;
105 finfo.all_info.in.file.fnum = fnum;
106 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
107 CHECK_STATUS(status, NT_STATUS_OK);
108 CHECK_VALUE(io.lseek.out.offset, finfo.all_info.out.size);
110 printf("Trying max seek\n");
111 io.lseek.in.file.fnum = fnum;
112 io.lseek.in.mode = SEEK_MODE_START;
113 io.lseek.in.offset = -1;
114 status = smb_raw_seek(cli->tree, &io);
115 CHECK_STATUS(status, NT_STATUS_OK);
116 CHECK_VALUE(io.lseek.out.offset, 0xffffffff);
118 printf("Testing position information change\n");
119 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
120 finfo.position_information.in.file.fnum = fnum;
121 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
122 CHECK_STATUS(status, NT_STATUS_OK);
123 CHECK_VALUE(finfo.position_information.out.position, 0);
125 printf("Trying max overflow\n");
126 io.lseek.in.file.fnum = fnum;
127 io.lseek.in.mode = SEEK_MODE_CURRENT;
128 io.lseek.in.offset = 1000;
129 status = smb_raw_seek(cli->tree, &io);
130 CHECK_STATUS(status, NT_STATUS_OK);
131 CHECK_VALUE(io.lseek.out.offset, 999);
133 printf("Testing position information change\n");
134 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
135 finfo.position_information.in.file.fnum = fnum;
136 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
137 CHECK_STATUS(status, NT_STATUS_OK);
138 CHECK_VALUE(finfo.position_information.out.position, 0);
140 printf("trying write to update offset\n");
141 ZERO_STRUCT(c);
142 if (smbcli_write(cli->tree, fnum, 0, c, 0, 2) != 2) {
143 printf("Write failed - %s\n", smbcli_errstr(cli->tree));
144 ret = false;
145 goto done;
148 printf("Testing position information change\n");
149 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
150 finfo.position_information.in.file.fnum = fnum;
151 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
152 CHECK_STATUS(status, NT_STATUS_OK);
153 CHECK_VALUE(finfo.position_information.out.position, 0);
155 io.lseek.in.file.fnum = fnum;
156 io.lseek.in.mode = SEEK_MODE_CURRENT;
157 io.lseek.in.offset = 0;
158 status = smb_raw_seek(cli->tree, &io);
159 CHECK_STATUS(status, NT_STATUS_OK);
160 CHECK_VALUE(io.lseek.out.offset, 2);
162 if (smbcli_read(cli->tree, fnum, c, 0, 1) != 1) {
163 printf("Read failed - %s\n", smbcli_errstr(cli->tree));
164 ret = false;
165 goto done;
168 printf("Testing position information change\n");
169 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
170 finfo.position_information.in.file.fnum = fnum;
171 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
172 CHECK_STATUS(status, NT_STATUS_OK);
173 CHECK_VALUE(finfo.position_information.out.position, 1);
175 status = smb_raw_seek(cli->tree, &io);
176 CHECK_STATUS(status, NT_STATUS_OK);
177 CHECK_VALUE(io.lseek.out.offset, 1);
179 printf("Testing position information\n");
180 fnum2 = smbcli_open(cli->tree, fname, O_RDWR, DENY_NONE);
181 if (fnum2 == -1) {
182 printf("2nd open failed - %s\n", smbcli_errstr(cli->tree));
183 ret = false;
184 goto done;
186 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
187 sfinfo.position_information.in.file.fnum = fnum2;
188 sfinfo.position_information.in.position = 25;
189 status = smb_raw_setfileinfo(cli->tree, &sfinfo);
190 CHECK_STATUS(status, NT_STATUS_OK);
192 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
193 finfo.position_information.in.file.fnum = fnum2;
194 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
195 CHECK_STATUS(status, NT_STATUS_OK);
196 CHECK_VALUE(finfo.position_information.out.position, 25);
198 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
199 finfo.position_information.in.file.fnum = fnum;
200 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
201 CHECK_STATUS(status, NT_STATUS_OK);
202 CHECK_VALUE(finfo.position_information.out.position, 1);
204 printf("position_information via paths\n");
206 sfinfo.generic.level = RAW_SFILEINFO_POSITION_INFORMATION;
207 sfinfo.position_information.in.file.path = fname;
208 sfinfo.position_information.in.position = 32;
209 status = smb_raw_setpathinfo(cli->tree, &sfinfo);
210 CHECK_STATUS(status, NT_STATUS_OK);
212 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
213 finfo.position_information.in.file.fnum = fnum2;
214 status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
215 CHECK_STATUS(status, NT_STATUS_OK);
216 CHECK_VALUE(finfo.position_information.out.position, 25);
218 finfo.generic.level = RAW_FILEINFO_POSITION_INFORMATION;
219 finfo.position_information.in.file.path = fname;
220 status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
221 CHECK_STATUS(status, NT_STATUS_OK);
222 CHECK_VALUE(finfo.position_information.out.position, 0);
225 done:
226 smb_raw_exit(cli->session);
227 smbcli_deltree(cli->tree, BASEDIR);
228 return ret;
233 basic testing of seek calls
235 bool torture_raw_seek(struct torture_context *torture, struct smbcli_state *cli)
237 bool ret = true;
239 ret &= test_seek(cli, torture);
241 return ret;