1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | SMB2 read test suite
|
---|
5 |
|
---|
6 | Copyright (C) Andrew Tridgell 2008
|
---|
7 |
|
---|
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 3 of the License, or
|
---|
11 | (at your option) any later version.
|
---|
12 |
|
---|
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.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License
|
---|
19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "includes.h"
|
---|
23 | #include "libcli/smb2/smb2.h"
|
---|
24 | #include "libcli/smb2/smb2_calls.h"
|
---|
25 |
|
---|
26 | #include "torture/torture.h"
|
---|
27 | #include "torture/smb2/proto.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | #define CHECK_STATUS(status, correct) do { \
|
---|
31 | if (!NT_STATUS_EQUAL(status, correct)) { \
|
---|
32 | printf("(%s) Incorrect status %s - should be %s\n", \
|
---|
33 | __location__, nt_errstr(status), nt_errstr(correct)); \
|
---|
34 | ret = false; \
|
---|
35 | goto done; \
|
---|
36 | }} while (0)
|
---|
37 |
|
---|
38 | #define CHECK_VALUE(v, correct) do { \
|
---|
39 | if ((v) != (correct)) { \
|
---|
40 | printf("(%s) Incorrect value %s=%u - should be %u\n", \
|
---|
41 | __location__, #v, (unsigned)v, (unsigned)correct); \
|
---|
42 | ret = false; \
|
---|
43 | goto done; \
|
---|
44 | }} while (0)
|
---|
45 |
|
---|
46 | #define FNAME "smb2_readtest.dat"
|
---|
47 | #define DNAME "smb2_readtest.dir"
|
---|
48 |
|
---|
49 | static bool test_read_eof(struct torture_context *torture, struct smb2_tree *tree)
|
---|
50 | {
|
---|
51 | bool ret = true;
|
---|
52 | NTSTATUS status;
|
---|
53 | struct smb2_handle h;
|
---|
54 | uint8_t buf[64*1024];
|
---|
55 | struct smb2_read rd;
|
---|
56 | TALLOC_CTX *tmp_ctx = talloc_new(tree);
|
---|
57 |
|
---|
58 | ZERO_STRUCT(buf);
|
---|
59 |
|
---|
60 | status = torture_smb2_testfile(tree, FNAME, &h);
|
---|
61 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
62 |
|
---|
63 | status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
|
---|
64 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
65 |
|
---|
66 | ZERO_STRUCT(rd);
|
---|
67 | rd.in.file.handle = h;
|
---|
68 | rd.in.length = 10;
|
---|
69 | rd.in.offset = 0;
|
---|
70 | rd.in.min_count = 1;
|
---|
71 |
|
---|
72 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
73 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
74 | CHECK_VALUE(rd.out.data.length, 10);
|
---|
75 |
|
---|
76 | rd.in.min_count = 0;
|
---|
77 | rd.in.length = 10;
|
---|
78 | rd.in.offset = sizeof(buf);
|
---|
79 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
80 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
81 |
|
---|
82 | rd.in.min_count = 0;
|
---|
83 | rd.in.length = 0;
|
---|
84 | rd.in.offset = sizeof(buf);
|
---|
85 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
86 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
87 | CHECK_VALUE(rd.out.data.length, 0);
|
---|
88 |
|
---|
89 | rd.in.min_count = 1;
|
---|
90 | rd.in.length = 0;
|
---|
91 | rd.in.offset = sizeof(buf);
|
---|
92 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
93 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
94 |
|
---|
95 | rd.in.min_count = 0;
|
---|
96 | rd.in.length = 2;
|
---|
97 | rd.in.offset = sizeof(buf) - 1;
|
---|
98 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
99 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
100 | CHECK_VALUE(rd.out.data.length, 1);
|
---|
101 |
|
---|
102 | rd.in.min_count = 2;
|
---|
103 | rd.in.length = 1;
|
---|
104 | rd.in.offset = sizeof(buf) - 1;
|
---|
105 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
106 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
107 |
|
---|
108 | rd.in.min_count = 0x10000;
|
---|
109 | rd.in.length = 1;
|
---|
110 | rd.in.offset = 0;
|
---|
111 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
112 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
113 |
|
---|
114 | rd.in.min_count = 0x10000 - 2;
|
---|
115 | rd.in.length = 1;
|
---|
116 | rd.in.offset = 0;
|
---|
117 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
118 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
119 |
|
---|
120 | rd.in.min_count = 10;
|
---|
121 | rd.in.length = 5;
|
---|
122 | rd.in.offset = 0;
|
---|
123 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
124 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
125 |
|
---|
126 | done:
|
---|
127 | talloc_free(tmp_ctx);
|
---|
128 | return ret;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | static bool test_read_position(struct torture_context *torture, struct smb2_tree *tree)
|
---|
133 | {
|
---|
134 | bool ret = true;
|
---|
135 | NTSTATUS status;
|
---|
136 | struct smb2_handle h;
|
---|
137 | uint8_t buf[64*1024];
|
---|
138 | struct smb2_read rd;
|
---|
139 | TALLOC_CTX *tmp_ctx = talloc_new(tree);
|
---|
140 | union smb_fileinfo info;
|
---|
141 |
|
---|
142 | ZERO_STRUCT(buf);
|
---|
143 |
|
---|
144 | status = torture_smb2_testfile(tree, FNAME, &h);
|
---|
145 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
146 |
|
---|
147 | status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
|
---|
148 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
149 |
|
---|
150 | ZERO_STRUCT(rd);
|
---|
151 | rd.in.file.handle = h;
|
---|
152 | rd.in.length = 10;
|
---|
153 | rd.in.offset = 0;
|
---|
154 | rd.in.min_count = 1;
|
---|
155 |
|
---|
156 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
157 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
158 | CHECK_VALUE(rd.out.data.length, 10);
|
---|
159 |
|
---|
160 | info.generic.level = RAW_FILEINFO_SMB2_ALL_INFORMATION;
|
---|
161 | info.generic.in.file.handle = h;
|
---|
162 |
|
---|
163 | status = smb2_getinfo_file(tree, tmp_ctx, &info);
|
---|
164 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
165 | if (torture_setting_bool(torture, "windows", false)) {
|
---|
166 | CHECK_VALUE(info.all_info2.out.position, 0);
|
---|
167 | } else {
|
---|
168 | CHECK_VALUE(info.all_info2.out.position, 10);
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | done:
|
---|
173 | talloc_free(tmp_ctx);
|
---|
174 | return ret;
|
---|
175 | }
|
---|
176 |
|
---|
177 | static bool test_read_dir(struct torture_context *torture, struct smb2_tree *tree)
|
---|
178 | {
|
---|
179 | bool ret = true;
|
---|
180 | NTSTATUS status;
|
---|
181 | struct smb2_handle h;
|
---|
182 | struct smb2_read rd;
|
---|
183 | TALLOC_CTX *tmp_ctx = talloc_new(tree);
|
---|
184 |
|
---|
185 | status = torture_smb2_testdir(tree, DNAME, &h);
|
---|
186 | if (!NT_STATUS_IS_OK(status)) {
|
---|
187 | printf(__location__ " Unable to create test directory '%s' - %s\n", DNAME, nt_errstr(status));
|
---|
188 | return false;
|
---|
189 | }
|
---|
190 |
|
---|
191 | ZERO_STRUCT(rd);
|
---|
192 | rd.in.file.handle = h;
|
---|
193 | rd.in.length = 10;
|
---|
194 | rd.in.offset = 0;
|
---|
195 | rd.in.min_count = 1;
|
---|
196 |
|
---|
197 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
198 | CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
|
---|
199 |
|
---|
200 | rd.in.min_count = 11;
|
---|
201 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
202 | CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
|
---|
203 |
|
---|
204 | rd.in.length = 0;
|
---|
205 | rd.in.min_count = 2592;
|
---|
206 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
207 | if (torture_setting_bool(torture, "windows", false)) {
|
---|
208 | CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
|
---|
209 | } else {
|
---|
210 | CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
|
---|
211 | }
|
---|
212 |
|
---|
213 | rd.in.length = 0;
|
---|
214 | rd.in.min_count = 0;
|
---|
215 | rd.in.channel = 0;
|
---|
216 | status = smb2_read(tree, tmp_ctx, &rd);
|
---|
217 | if (torture_setting_bool(torture, "windows", false)) {
|
---|
218 | CHECK_STATUS(status, NT_STATUS_OK);
|
---|
219 | } else {
|
---|
220 | CHECK_STATUS(status, NT_STATUS_INVALID_DEVICE_REQUEST);
|
---|
221 | }
|
---|
222 |
|
---|
223 | done:
|
---|
224 | talloc_free(tmp_ctx);
|
---|
225 | return ret;
|
---|
226 | }
|
---|
227 |
|
---|
228 |
|
---|
229 | /*
|
---|
230 | basic testing of SMB2 read
|
---|
231 | */
|
---|
232 | struct torture_suite *torture_smb2_read_init(void)
|
---|
233 | {
|
---|
234 | struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "read");
|
---|
235 |
|
---|
236 | torture_suite_add_1smb2_test(suite, "eof", test_read_eof);
|
---|
237 | torture_suite_add_1smb2_test(suite, "position", test_read_position);
|
---|
238 | torture_suite_add_1smb2_test(suite, "dir", test_read_dir);
|
---|
239 |
|
---|
240 | suite->description = talloc_strdup(suite, "SMB2-READ tests");
|
---|
241 |
|
---|
242 | return suite;
|
---|
243 | }
|
---|
244 |
|
---|