Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : SMB torture tester
4 : Copyright (C) Jelmer Vernooij 2006
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 3 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, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include "includes.h"
21 : #include "libcli/smb2/smb2.h"
22 :
23 : #include "torture/smbtorture.h"
24 : #include "torture/smb2/proto.h"
25 : #include "../lib/util/dlinklist.h"
26 :
27 3014 : static bool wrap_simple_1smb2_test(struct torture_context *torture_ctx,
28 : struct torture_tcase *tcase,
29 : struct torture_test *test)
30 : {
31 121 : bool (*fn) (struct torture_context *, struct smb2_tree *);
32 121 : bool ret;
33 121 : struct smb2_tree *tree1;
34 3014 : TALLOC_CTX *mem_ctx = talloc_new(torture_ctx);
35 :
36 3014 : if (!torture_smb2_connection(torture_ctx, &tree1)) {
37 0 : torture_fail(torture_ctx,
38 : "Establishing SMB2 connection failed\n");
39 : return false;
40 : }
41 :
42 : /*
43 : * This is a trick:
44 : * The test might close the connection. If we steal the tree context
45 : * before that and free the parent instead of tree directly, we avoid
46 : * a double free error.
47 : */
48 3014 : talloc_steal(mem_ctx, tree1);
49 :
50 3014 : fn = test->fn;
51 :
52 3014 : ret = fn(torture_ctx, tree1);
53 :
54 3014 : talloc_free(mem_ctx);
55 :
56 3014 : return ret;
57 : }
58 :
59 1144044 : struct torture_test *torture_suite_add_1smb2_test(struct torture_suite *suite,
60 : const char *name,
61 : bool (*run)(struct torture_context *,
62 : struct smb2_tree *))
63 : {
64 60750 : struct torture_test *test;
65 60750 : struct torture_tcase *tcase;
66 :
67 1144044 : tcase = torture_suite_add_tcase(suite, name);
68 :
69 1144044 : test = talloc(tcase, struct torture_test);
70 :
71 1144044 : test->name = talloc_strdup(test, name);
72 1144044 : test->description = NULL;
73 1144044 : test->run = wrap_simple_1smb2_test;
74 1144044 : test->fn = run;
75 1144044 : test->dangerous = false;
76 :
77 1144044 : DLIST_ADD_END(tcase->tests, test);
78 :
79 1144044 : return test;
80 : }
81 :
82 :
83 396 : static bool wrap_simple_2smb2_test(struct torture_context *torture_ctx,
84 : struct torture_tcase *tcase,
85 : struct torture_test *test)
86 : {
87 0 : bool (*fn) (struct torture_context *, struct smb2_tree *, struct smb2_tree *);
88 396 : bool ret = false;
89 :
90 0 : struct smb2_tree *tree1;
91 0 : struct smb2_tree *tree2;
92 396 : TALLOC_CTX *mem_ctx = talloc_new(torture_ctx);
93 :
94 396 : if (!torture_smb2_connection(torture_ctx, &tree1)) {
95 0 : torture_fail(torture_ctx,
96 : "Establishing SMB2 connection failed\n");
97 : goto done;
98 : }
99 :
100 396 : talloc_steal(mem_ctx, tree1);
101 :
102 396 : if (!torture_smb2_connection(torture_ctx, &tree2)) {
103 0 : torture_fail(torture_ctx,
104 : "Establishing SMB2 connection failed\n");
105 : goto done;
106 : }
107 :
108 396 : talloc_steal(mem_ctx, tree2);
109 :
110 396 : fn = test->fn;
111 :
112 396 : ret = fn(torture_ctx, tree1, tree2);
113 :
114 396 : done:
115 : /* the test may already have closed some of the connections */
116 396 : talloc_free(mem_ctx);
117 :
118 396 : return ret;
119 : }
120 :
121 :
122 240108 : struct torture_test *torture_suite_add_2smb2_test(struct torture_suite *suite,
123 : const char *name,
124 : bool (*run)(struct torture_context *,
125 : struct smb2_tree *,
126 : struct smb2_tree *))
127 : {
128 12750 : struct torture_test *test;
129 12750 : struct torture_tcase *tcase;
130 :
131 240108 : tcase = torture_suite_add_tcase(suite, name);
132 :
133 240108 : test = talloc(tcase, struct torture_test);
134 :
135 240108 : test->name = talloc_strdup(test, name);
136 240108 : test->description = NULL;
137 240108 : test->run = wrap_simple_2smb2_test;
138 240108 : test->fn = run;
139 240108 : test->dangerous = false;
140 :
141 240108 : DLIST_ADD_END(tcase->tests, test);
142 :
143 240108 : return test;
144 : }
145 :
146 2354 : NTSTATUS torture_smb2_init(TALLOC_CTX *ctx)
147 : {
148 2354 : struct torture_suite *suite = torture_suite_create(ctx, "smb2");
149 2354 : torture_suite_add_simple_test(suite, "connect", torture_smb2_connect);
150 2354 : torture_suite_add_suite(suite, torture_smb2_scan_init(suite));
151 2354 : torture_suite_add_suite(suite, torture_smb2_getinfo_init(suite));
152 2354 : torture_suite_add_simple_test(suite, "setinfo", torture_smb2_setinfo);
153 2354 : torture_suite_add_suite(suite, torture_smb2_lock_init(suite));
154 2354 : torture_suite_add_suite(suite, torture_smb2_read_init(suite));
155 2354 : torture_suite_add_suite(suite, torture_smb2_aio_delay_init(suite));
156 2354 : torture_suite_add_suite(suite, torture_smb2_bench_init(suite));
157 2354 : torture_suite_add_suite(suite, torture_smb2_create_init(suite));
158 2354 : torture_suite_add_suite(suite, torture_smb2_twrp_init(suite));
159 2354 : torture_suite_add_suite(suite, torture_smb2_fileid_init(suite));
160 2354 : torture_suite_add_suite(suite, torture_smb2_acls_init(suite));
161 2354 : torture_suite_add_suite(suite, torture_smb2_acls_non_canonical_init(suite));
162 2354 : torture_suite_add_suite(suite, torture_smb2_notify_init(suite));
163 2354 : torture_suite_add_suite(suite, torture_smb2_notify_inotify_init(suite));
164 2354 : torture_suite_add_suite(suite,
165 : torture_smb2_notify_disabled_init(suite));
166 2354 : torture_suite_add_suite(suite, torture_smb2_durable_open_init(suite));
167 2354 : torture_suite_add_suite(suite,
168 : torture_smb2_durable_open_disconnect_init(suite));
169 2354 : torture_suite_add_suite(suite,
170 : torture_smb2_durable_v2_open_init(suite));
171 2354 : torture_suite_add_suite(suite,
172 : torture_smb2_durable_v2_delay_init(suite));
173 2354 : torture_suite_add_suite(suite, torture_smb2_dir_init(suite));
174 2354 : torture_suite_add_suite(suite, torture_smb2_lease_init(suite));
175 2354 : torture_suite_add_suite(suite, torture_smb2_compound_init(suite));
176 2354 : torture_suite_add_suite(suite, torture_smb2_compound_find_init(suite));
177 2354 : torture_suite_add_suite(suite, torture_smb2_compound_async_init(suite));
178 2354 : torture_suite_add_suite(suite, torture_smb2_oplocks_init(suite));
179 2354 : torture_suite_add_suite(suite, torture_smb2_kernel_oplocks_init(suite));
180 2354 : torture_suite_add_suite(suite, torture_smb2_streams_init(suite));
181 2354 : torture_suite_add_suite(suite, torture_smb2_ioctl_init(suite));
182 2354 : torture_suite_add_simple_test(suite, "set-sparse-ioctl",
183 : test_ioctl_set_sparse);
184 2354 : torture_suite_add_simple_test(suite, "zero-data-ioctl",
185 : test_ioctl_zero_data);
186 2354 : torture_suite_add_simple_test(suite, "ioctl-on-stream",
187 : test_ioctl_alternate_data_stream);
188 2354 : torture_suite_add_suite(suite, torture_smb2_rename_init(suite));
189 2354 : torture_suite_add_suite(suite, torture_smb2_sharemode_init(suite));
190 2354 : torture_suite_add_1smb2_test(suite, "hold-oplock", test_smb2_hold_oplock);
191 2354 : torture_suite_add_suite(suite, torture_smb2_session_init(suite));
192 2354 : torture_suite_add_suite(suite, torture_smb2_session_req_sign_init(suite));
193 2354 : torture_suite_add_suite(suite, torture_smb2_replay_init(suite));
194 2354 : torture_suite_add_simple_test(suite, "dosmode", torture_smb2_dosmode);
195 2354 : torture_suite_add_simple_test(suite, "async_dosmode", torture_smb2_async_dosmode);
196 2354 : torture_suite_add_simple_test(suite, "maxfid", torture_smb2_maxfid);
197 2354 : torture_suite_add_simple_test(suite, "hold-sharemode",
198 : torture_smb2_hold_sharemode);
199 2354 : torture_suite_add_simple_test(suite, "check-sharemode",
200 : torture_smb2_check_sharemode);
201 2354 : torture_suite_add_suite(suite, torture_smb2_crediting_init(suite));
202 :
203 2354 : torture_suite_add_suite(suite, torture_smb2_doc_init(suite));
204 2354 : torture_suite_add_suite(suite, torture_smb2_multichannel_init(suite));
205 2354 : torture_suite_add_suite(suite, torture_smb2_samba3misc_init(suite));
206 2354 : torture_suite_add_suite(suite, torture_smb2_timestamps_init(suite));
207 2354 : torture_suite_add_suite(suite, torture_smb2_timestamp_resolution_init(suite));
208 2354 : torture_suite_add_1smb2_test(suite, "openattr", torture_smb2_openattrtest);
209 2354 : torture_suite_add_1smb2_test(suite, "winattr", torture_smb2_winattrtest);
210 2354 : torture_suite_add_1smb2_test(suite, "winattr2", torture_smb2_winattr2);
211 2354 : torture_suite_add_1smb2_test(suite, "sdread", torture_smb2_sdreadtest);
212 2354 : torture_suite_add_suite(suite, torture_smb2_readwrite_init(suite));
213 2354 : torture_suite_add_suite(suite, torture_smb2_max_allowed(suite));
214 2354 : torture_suite_add_1smb2_test(suite, "tcon", run_tcon_test);
215 2354 : torture_suite_add_1smb2_test(suite, "mkdir", torture_smb2_mkdir);
216 2354 : torture_suite_add_suite(suite, torture_smb2_name_mangling_init(suite));
217 :
218 2354 : torture_suite_add_suite(suite, torture_smb2_charset(suite));
219 2354 : torture_suite_add_1smb2_test(suite, "secleak", torture_smb2_sec_leak);
220 2354 : torture_suite_add_1smb2_test(suite, "session-id", run_sessidtest);
221 2354 : torture_suite_add_suite(suite, torture_smb2_deny_init(suite));
222 2354 : torture_suite_add_suite(suite, torture_smb2_ea(suite));
223 2354 : torture_suite_add_suite(suite, torture_smb2_create_no_streams_init(suite));
224 :
225 2354 : suite->description = talloc_strdup(suite, "SMB2-specific tests");
226 :
227 2354 : torture_register_suite(ctx, suite);
228 :
229 2354 : return NT_STATUS_OK;
230 : }
|