2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2008
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.
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.
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/>.
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
29 #include "librpc/gen_ndr/ndr_security.h"
31 #define CHECK_STATUS(status, correct) do { \
32 if (!NT_STATUS_EQUAL(status, correct)) { \
33 printf("(%s) Incorrect status %s - should be %s\n", \
34 __location__, nt_errstr(status), nt_errstr(correct)); \
39 #define CHECK_VALUE(v, correct) do { \
40 if ((v) != (correct)) { \
41 printf("(%s) Incorrect value %s=%d - should be %d\n", \
42 __location__, #v, v, correct); \
47 static bool test_read(struct torture_context *torture, struct smb2_tree *tree)
54 TALLOC_CTX *tmp_ctx = talloc_new(tree);
58 status = torture_smb2_testfile(tree, "lock1.txt", &h);
59 CHECK_STATUS(status, NT_STATUS_OK);
61 status = smb2_util_write(tree, h, buf, 0, ARRAY_SIZE(buf));
62 CHECK_STATUS(status, NT_STATUS_OK);
65 rd.in.file.handle = h;
70 status = smb2_read(tree, tmp_ctx, &rd);
71 CHECK_STATUS(status, NT_STATUS_OK);
72 CHECK_VALUE(rd.out.data.length, 10);
76 rd.in.offset = sizeof(buf);
77 status = smb2_read(tree, tmp_ctx, &rd);
78 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
82 rd.in.offset = sizeof(buf);
83 status = smb2_read(tree, tmp_ctx, &rd);
84 CHECK_STATUS(status, NT_STATUS_OK);
85 CHECK_VALUE(rd.out.data.length, 0);
89 rd.in.offset = sizeof(buf);
90 status = smb2_read(tree, tmp_ctx, &rd);
91 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
95 rd.in.offset = sizeof(buf) - 1;
96 status = smb2_read(tree, tmp_ctx, &rd);
97 CHECK_STATUS(status, NT_STATUS_OK);
98 CHECK_VALUE(rd.out.data.length, 1);
102 rd.in.offset = sizeof(buf) - 1;
103 status = smb2_read(tree, tmp_ctx, &rd);
104 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
106 rd.in.min_count = 0x10000;
109 status = smb2_read(tree, tmp_ctx, &rd);
110 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
112 rd.in.min_count = 0x10000 - 2;
115 status = smb2_read(tree, tmp_ctx, &rd);
116 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
118 rd.in.min_count = 10;
121 status = smb2_read(tree, tmp_ctx, &rd);
122 CHECK_STATUS(status, NT_STATUS_END_OF_FILE);
125 talloc_free(tmp_ctx);
129 /* basic testing of SMB2 read
131 struct torture_suite *torture_smb2_read_init(void)
133 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "READ");
135 torture_suite_add_1smb2_test(suite, "READ", test_read);
137 suite->description = talloc_strdup(suite, "SMB2-READ tests");