s4:torture: send the TCONX_FLAG_EXTENDED_RESPONSE flag
[Samba/gebeck_regimport.git] / source4 / torture / smb2 / smb2.c
bloba396a2eda2c9502586297a06e1fee115b51bec39
1 /*
2 Unix SMB/CIFS implementation.
3 SMB torture tester
4 Copyright (C) Jelmer Vernooij 2006
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 "libcli/smb2/smb2.h"
23 #include "torture/smbtorture.h"
24 #include "torture/smb2/proto.h"
25 #include "../lib/util/dlinklist.h"
27 static bool wrap_simple_1smb2_test(struct torture_context *torture_ctx,
28 struct torture_tcase *tcase,
29 struct torture_test *test)
31 bool (*fn) (struct torture_context *, struct smb2_tree *);
32 bool ret;
33 struct smb2_tree *tree1;
34 TALLOC_CTX *mem_ctx = talloc_new(torture_ctx);
36 if (!torture_smb2_connection(torture_ctx, &tree1)) {
37 torture_fail(torture_ctx,
38 "Establishing SMB2 connection failed\n");
39 return false;
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.
48 talloc_steal(mem_ctx, tree1);
50 fn = test->fn;
52 ret = fn(torture_ctx, tree1);
54 talloc_free(mem_ctx);
56 return ret;
59 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 *))
64 struct torture_test *test;
65 struct torture_tcase *tcase;
67 tcase = torture_suite_add_tcase(suite, name);
69 test = talloc(tcase, struct torture_test);
71 test->name = talloc_strdup(test, name);
72 test->description = NULL;
73 test->run = wrap_simple_1smb2_test;
74 test->fn = run;
75 test->dangerous = false;
77 DLIST_ADD_END(tcase->tests, test, struct torture_test *);
79 return test;
83 static bool wrap_simple_2smb2_test(struct torture_context *torture_ctx,
84 struct torture_tcase *tcase,
85 struct torture_test *test)
87 bool (*fn) (struct torture_context *, struct smb2_tree *, struct smb2_tree *);
88 bool ret = false;
90 struct smb2_tree *tree1;
91 struct smb2_tree *tree2;
92 TALLOC_CTX *mem_ctx = talloc_new(torture_ctx);
94 if (!torture_smb2_connection(torture_ctx, &tree1)) {
95 torture_fail(torture_ctx,
96 "Establishing SMB2 connection failed\n");
97 goto done;
100 talloc_steal(mem_ctx, tree1);
102 if (!torture_smb2_connection(torture_ctx, &tree2)) {
103 torture_fail(torture_ctx,
104 "Establishing SMB2 connection failed\n");
105 goto done;
108 talloc_steal(mem_ctx, tree2);
110 fn = test->fn;
112 ret = fn(torture_ctx, tree1, tree2);
114 done:
115 /* the test may already have closed some of the connections */
116 talloc_free(mem_ctx);
118 return ret;
122 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 *))
128 struct torture_test *test;
129 struct torture_tcase *tcase;
131 tcase = torture_suite_add_tcase(suite, name);
133 test = talloc(tcase, struct torture_test);
135 test->name = talloc_strdup(test, name);
136 test->description = NULL;
137 test->run = wrap_simple_2smb2_test;
138 test->fn = run;
139 test->dangerous = false;
141 DLIST_ADD_END(tcase->tests, test, struct torture_test *);
143 return test;
146 NTSTATUS torture_smb2_init(void)
148 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "smb2");
149 torture_suite_add_simple_test(suite, "connect", torture_smb2_connect);
150 torture_suite_add_suite(suite, torture_smb2_scan_init());
151 torture_suite_add_simple_test(suite, "getinfo", torture_smb2_getinfo);
152 torture_suite_add_simple_test(suite, "setinfo", torture_smb2_setinfo);
153 torture_suite_add_suite(suite, torture_smb2_lock_init());
154 torture_suite_add_suite(suite, torture_smb2_read_init());
155 torture_suite_add_suite(suite, torture_smb2_create_init());
156 torture_suite_add_suite(suite, torture_smb2_acls_init());
157 torture_suite_add_suite(suite, torture_smb2_notify_init());
158 torture_suite_add_suite(suite, torture_smb2_durable_open_init());
159 torture_suite_add_suite(suite, torture_smb2_durable_v2_open_init());
160 torture_suite_add_suite(suite, torture_smb2_dir_init());
161 torture_suite_add_suite(suite, torture_smb2_lease_init());
162 torture_suite_add_suite(suite, torture_smb2_compound_init());
163 torture_suite_add_suite(suite, torture_smb2_oplocks_init());
164 torture_suite_add_suite(suite, torture_smb2_streams_init());
165 torture_suite_add_suite(suite, torture_smb2_ioctl_init());
166 torture_suite_add_suite(suite, torture_smb2_rename_init());
167 torture_suite_add_1smb2_test(suite, "bench-oplock", test_smb2_bench_oplock);
168 torture_suite_add_1smb2_test(suite, "hold-oplock", test_smb2_hold_oplock);
169 torture_suite_add_suite(suite, torture_smb2_session_init());
171 suite->description = talloc_strdup(suite, "SMB2-specific tests");
173 torture_register_suite(suite);
175 return NT_STATUS_OK;