2 Unix SMB/CIFS implementation.
4 test suite for SMB2 compounded requests
6 Copyright (C) Stefan Metzmacher 2009
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 "librpc/gen_ndr/security.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
29 #define CHECK_STATUS(status, correct) do { \
30 if (!NT_STATUS_EQUAL(status, correct)) { \
31 torture_result(tctx, TORTURE_FAIL, __location__": Incorrect status %s - should be %s", \
32 nt_errstr(status), nt_errstr(correct)); \
37 static bool test_compound_related1(struct torture_context *tctx,
38 struct smb2_tree *tree)
40 struct smb2_handle hd;
41 struct smb2_create cr;
43 const char *fname = "compound_related1.dat";
46 struct smb2_request *req[2];
49 smb2_transport_credits_ask_num(tree->session->transport, 2);
51 smb2_util_unlink(tree, fname);
53 smb2_transport_credits_ask_num(tree->session->transport, 1);
56 cr.in.security_flags = 0x00;
57 cr.in.oplock_level = 0;
58 cr.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
59 cr.in.create_flags = 0x00000000;
60 cr.in.reserved = 0x00000000;
61 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
62 cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
63 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
64 NTCREATEX_SHARE_ACCESS_WRITE |
65 NTCREATEX_SHARE_ACCESS_DELETE;
66 cr.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
67 cr.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
68 NTCREATEX_OPTIONS_ASYNC_ALERT |
69 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
73 smb2_transport_compound_start(tree->session->transport, 2);
75 req[0] = smb2_create_send(tree, &cr);
77 smb2_transport_compound_set_related(tree->session->transport, true);
79 hd.data[0] = UINT64_MAX;
80 hd.data[1] = UINT64_MAX;
83 cl.in.file.handle = hd;
84 req[1] = smb2_close_send(tree, &cl);
86 status = smb2_create_recv(req[0], tree, &cr);
87 CHECK_STATUS(status, NT_STATUS_OK);
88 status = smb2_close_recv(req[1], &cl);
89 CHECK_STATUS(status, NT_STATUS_OK);
91 smb2_util_unlink(tree, fname);
96 static bool test_compound_related2(struct torture_context *tctx,
97 struct smb2_tree *tree)
99 struct smb2_handle hd;
100 struct smb2_create cr;
102 const char *fname = "compound_related2.dat";
103 struct smb2_close cl;
105 struct smb2_request *req[5];
107 smb2_transport_credits_ask_num(tree->session->transport, 5);
109 smb2_util_unlink(tree, fname);
111 smb2_transport_credits_ask_num(tree->session->transport, 1);
114 cr.in.security_flags = 0x00;
115 cr.in.oplock_level = 0;
116 cr.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
117 cr.in.create_flags = 0x00000000;
118 cr.in.reserved = 0x00000000;
119 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
120 cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
121 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
122 NTCREATEX_SHARE_ACCESS_WRITE |
123 NTCREATEX_SHARE_ACCESS_DELETE;
124 cr.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
125 cr.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
126 NTCREATEX_OPTIONS_ASYNC_ALERT |
127 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
131 smb2_transport_compound_start(tree->session->transport, 5);
133 req[0] = smb2_create_send(tree, &cr);
135 hd.data[0] = UINT64_MAX;
136 hd.data[1] = UINT64_MAX;
138 smb2_transport_compound_set_related(tree->session->transport, true);
141 cl.in.file.handle = hd;
142 req[1] = smb2_close_send(tree, &cl);
143 req[2] = smb2_close_send(tree, &cl);
144 req[3] = smb2_close_send(tree, &cl);
145 req[4] = smb2_close_send(tree, &cl);
147 status = smb2_create_recv(req[0], tree, &cr);
148 CHECK_STATUS(status, NT_STATUS_OK);
149 status = smb2_close_recv(req[1], &cl);
150 CHECK_STATUS(status, NT_STATUS_OK);
151 status = smb2_close_recv(req[2], &cl);
152 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
153 status = smb2_close_recv(req[3], &cl);
154 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
155 status = smb2_close_recv(req[4], &cl);
156 CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
158 smb2_util_unlink(tree, fname);
163 static bool test_compound_unrelated1(struct torture_context *tctx,
164 struct smb2_tree *tree)
166 struct smb2_handle hd;
167 struct smb2_create cr;
169 const char *fname = "compound_unrelated1.dat";
170 struct smb2_close cl;
172 struct smb2_request *req[5];
176 smb2_transport_credits_ask_num(tree->session->transport, 5);
178 smb2_util_unlink(tree, fname);
180 smb2_transport_credits_ask_num(tree->session->transport, 1);
183 cr.in.security_flags = 0x00;
184 cr.in.oplock_level = 0;
185 cr.in.impersonation_level = NTCREATEX_IMPERSONATION_IMPERSONATION;
186 cr.in.create_flags = 0x00000000;
187 cr.in.reserved = 0x00000000;
188 cr.in.desired_access = SEC_RIGHTS_FILE_ALL;
189 cr.in.file_attributes = FILE_ATTRIBUTE_NORMAL;
190 cr.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
191 NTCREATEX_SHARE_ACCESS_WRITE |
192 NTCREATEX_SHARE_ACCESS_DELETE;
193 cr.in.create_disposition = NTCREATEX_DISP_OPEN_IF;
194 cr.in.create_options = NTCREATEX_OPTIONS_SEQUENTIAL_ONLY |
195 NTCREATEX_OPTIONS_ASYNC_ALERT |
196 NTCREATEX_OPTIONS_NON_DIRECTORY_FILE |
200 smb2_transport_compound_start(tree->session->transport, 5);
202 req[0] = smb2_create_send(tree, &cr);
204 hd.data[0] = UINT64_MAX;
205 hd.data[1] = UINT64_MAX;
208 cl.in.file.handle = hd;
209 req[1] = smb2_close_send(tree, &cl);
210 req[2] = smb2_close_send(tree, &cl);
211 req[3] = smb2_close_send(tree, &cl);
212 req[4] = smb2_close_send(tree, &cl);
214 status = smb2_create_recv(req[0], tree, &cr);
215 CHECK_STATUS(status, NT_STATUS_OK);
216 status = smb2_close_recv(req[1], &cl);
217 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
218 status = smb2_close_recv(req[2], &cl);
219 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
220 status = smb2_close_recv(req[3], &cl);
221 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
222 status = smb2_close_recv(req[4], &cl);
223 CHECK_STATUS(status, NT_STATUS_FILE_CLOSED);
225 smb2_util_unlink(tree, fname);
230 struct torture_suite *torture_smb2_compound_init(void)
232 struct torture_suite *suite =
233 torture_suite_create(talloc_autofree_context(), "COMPOUND");
235 torture_suite_add_1smb2_test(suite, "RELATED1", test_compound_related1);
236 torture_suite_add_1smb2_test(suite, "RELATED2", test_compound_related2);
237 torture_suite_add_1smb2_test(suite, "UNRELATED1", test_compound_unrelated1);
239 suite->description = talloc_strdup(suite, "SMB2-COMPOUND tests");