2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1997-2003
5 Copyright (C) Jelmer Vernooij 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "auth/credentials/credentials.h"
23 #include "lib/cmdline/popt_common.h"
24 #include "librpc/rpc/dcerpc.h"
25 #include "torture/rpc/rpc.h"
26 #include "torture/torture.h"
27 #include "librpc/ndr/ndr_table.h"
28 #include "lib/util/dlinklist.h"
30 struct torture_rpc_tcase {
31 struct torture_tcase tcase;
32 const struct ndr_interface_table *table;
33 struct dcerpc_pipe *pipe;
36 NTSTATUS torture_rpc_binding(struct torture_context *tctx,
37 struct dcerpc_binding **binding)
40 const char *binding_string = torture_setting_string(tctx, "binding", NULL);
42 if (binding_string == NULL) {
43 torture_comment(tctx, "You must specify a ncacn binding string\n");
44 return NT_STATUS_INVALID_PARAMETER;
47 status = dcerpc_parse_binding(tctx, binding_string, binding);
48 if (NT_STATUS_IS_ERR(status)) {
49 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding_string));
56 /* open a rpc connection to the chosen binding string */
57 _PUBLIC_ NTSTATUS torture_rpc_connection(struct torture_context *tctx,
58 struct dcerpc_pipe **p,
59 const struct ndr_interface_table *table)
62 struct dcerpc_binding *binding;
64 status = torture_rpc_binding(tctx, &binding);
65 if (NT_STATUS_IS_ERR(status))
68 status = dcerpc_pipe_connect_b(tctx,
70 cmdline_credentials, NULL);
72 if (NT_STATUS_IS_ERR(status)) {
73 printf("Failed to connect to remote server: %s %s\n",
74 dcerpc_binding_string(tctx, binding), nt_errstr(status));
80 /* open a rpc connection to a specific transport */
81 NTSTATUS torture_rpc_connection_transport(struct torture_context *tctx,
82 struct dcerpc_pipe **p,
83 const struct ndr_interface_table *table,
84 enum dcerpc_transport_t transport,
85 uint32_t assoc_group_id)
88 struct dcerpc_binding *binding;
89 TALLOC_CTX *mem_ctx = talloc_named(tctx, 0, "torture_rpc_connection_smb");
91 status = torture_rpc_binding(tctx, &binding);
92 if (NT_STATUS_IS_ERR(status))
95 binding->transport = transport;
96 binding->assoc_group_id = assoc_group_id;
98 status = dcerpc_pipe_connect_b(mem_ctx, p, binding, table,
99 cmdline_credentials, NULL);
101 if (NT_STATUS_IS_OK(status)) {
102 *p = talloc_reference(tctx, *p);
106 talloc_free(mem_ctx);
110 static bool torture_rpc_setup_anonymous(struct torture_context *tctx,
113 struct cli_credentials *anon_credentials;
115 struct dcerpc_binding *binding;
116 struct torture_rpc_tcase *tcase = talloc_get_type(
117 tctx->active_tcase, struct torture_rpc_tcase);
119 status = torture_rpc_binding(tctx, &binding);
120 if (NT_STATUS_IS_ERR(status))
123 anon_credentials = cli_credentials_init_anon(tctx);
125 status = dcerpc_pipe_connect_b(tctx,
126 (struct dcerpc_pipe **)data,
129 anon_credentials, NULL);
131 torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
136 static bool torture_rpc_setup (struct torture_context *tctx, void **data)
139 struct torture_rpc_tcase *tcase = talloc_get_type(
140 tctx->active_tcase, struct torture_rpc_tcase);
142 status = torture_rpc_connection(tctx,
143 (struct dcerpc_pipe **)data,
144 (const struct ndr_interface_table *)tcase->table);
146 torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
151 static bool torture_rpc_teardown (struct torture_context *tcase, void *data)
157 _PUBLIC_ struct torture_rpc_tcase *torture_suite_add_anon_rpc_iface_tcase(struct torture_suite *suite,
159 const struct ndr_interface_table *table)
161 struct torture_rpc_tcase *tcase = talloc(suite, struct torture_rpc_tcase);
163 torture_suite_init_tcase(suite, (struct torture_tcase *)tcase, name);
165 tcase->tcase.setup = torture_rpc_setup_anonymous;
166 tcase->tcase.teardown = torture_rpc_teardown;
167 tcase->table = table;
173 _PUBLIC_ struct torture_rpc_tcase *torture_suite_add_rpc_iface_tcase(struct torture_suite *suite,
175 const struct ndr_interface_table *table)
177 struct torture_rpc_tcase *tcase = talloc(suite, struct torture_rpc_tcase);
179 torture_suite_init_tcase(suite, (struct torture_tcase *)tcase, name);
181 tcase->tcase.setup = torture_rpc_setup;
182 tcase->tcase.teardown = torture_rpc_teardown;
183 tcase->table = table;
188 static bool torture_rpc_wrap_test(struct torture_context *tctx,
189 struct torture_tcase *tcase,
190 struct torture_test *test)
192 bool (*fn) (struct torture_context *, struct dcerpc_pipe *);
196 return fn(tctx, (struct dcerpc_pipe *)tcase->data);
199 static bool torture_rpc_wrap_test_ex(struct torture_context *tctx,
200 struct torture_tcase *tcase,
201 struct torture_test *test)
203 bool (*fn) (struct torture_context *, struct dcerpc_pipe *, const void *);
207 return fn(tctx, (struct dcerpc_pipe *)tcase->data, test->data);
210 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test(
211 struct torture_rpc_tcase *tcase,
213 bool (*fn) (struct torture_context *, struct dcerpc_pipe *))
215 struct torture_test *test;
217 test = talloc(tcase, struct torture_test);
219 test->name = talloc_strdup(test, name);
220 test->description = NULL;
221 test->run = torture_rpc_wrap_test;
222 test->dangerous = false;
226 DLIST_ADD(tcase->tcase.tests, test);
231 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test_ex(
232 struct torture_rpc_tcase *tcase,
234 bool (*fn) (struct torture_context *, struct dcerpc_pipe *,
238 struct torture_test *test;
240 test = talloc(tcase, struct torture_test);
242 test->name = talloc_strdup(test, name);
243 test->description = NULL;
244 test->run = torture_rpc_wrap_test_ex;
245 test->dangerous = false;
246 test->data = userdata;
249 DLIST_ADD(tcase->tcase.tests, test);
254 NTSTATUS torture_rpc_init(void)
256 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "RPC");
262 torture_suite_add_simple_test(suite, "LSA", torture_rpc_lsa);
263 torture_suite_add_simple_test(suite, "LSALOOKUP", torture_rpc_lsa_lookup);
264 torture_suite_add_simple_test(suite, "LSA-GETUSER", torture_rpc_lsa_get_user);
265 torture_suite_add_simple_test(suite, "SECRETS", torture_rpc_lsa_secrets);
266 torture_suite_add_suite(suite, torture_rpc_echo());
267 torture_suite_add_simple_test(suite, "DFS", torture_rpc_dfs);
268 torture_suite_add_suite(suite, torture_rpc_unixinfo());
269 torture_suite_add_suite(suite, torture_rpc_eventlog());
270 torture_suite_add_suite(suite, torture_rpc_atsvc());
271 torture_suite_add_suite(suite, torture_rpc_wkssvc(suite));
272 torture_suite_add_suite(suite, torture_rpc_handles(suite));
273 torture_suite_add_suite(suite, torture_rpc_winreg(suite));
274 torture_suite_add_simple_test(suite, "SPOOLSS", torture_rpc_spoolss);
275 torture_suite_add_simple_test(suite, "SAMR", torture_rpc_samr);
276 torture_suite_add_simple_test(suite, "SAMR-USERS", torture_rpc_samr_users);
277 torture_suite_add_simple_test(suite, "SAMR-PASSWORDS", torture_rpc_samr_passwords);
278 torture_suite_add_simple_test(suite, "NETLOGON", torture_rpc_netlogon);
279 torture_suite_add_simple_test(suite, "SAMLOGON", torture_rpc_samlogon);
280 torture_suite_add_simple_test(suite, "SAMSYNC", torture_rpc_samsync);
281 torture_suite_add_simple_test(suite, "SCHANNEL", torture_rpc_schannel);
282 torture_suite_add_simple_test(suite, "SCHANNEL2", torture_rpc_schannel2);
283 torture_suite_add_suite(suite, torture_rpc_srvsvc(suite));
284 torture_suite_add_suite(suite, torture_rpc_svcctl(suite));
285 torture_suite_add_suite(suite, torture_rpc_epmapper(suite));
286 torture_suite_add_suite(suite, torture_rpc_initshutdown(suite));
287 torture_suite_add_suite(suite, torture_rpc_oxidresolve(suite));
288 torture_suite_add_suite(suite, torture_rpc_remact(suite));
289 torture_suite_add_simple_test(suite, "MGMT", torture_rpc_mgmt);
290 torture_suite_add_simple_test(suite, "SCANNER", torture_rpc_scanner);
291 torture_suite_add_simple_test(suite, "AUTOIDL", torture_rpc_autoidl);
292 torture_suite_add_simple_test(suite, "COUNTCALLS", torture_rpc_countcalls);
293 torture_suite_add_simple_test(suite, "MULTIBIND", torture_multi_bind);
294 torture_suite_add_simple_test(suite, "AUTHCONTEXT", torture_bind_authcontext);
295 torture_suite_add_simple_test(suite, "BINDSAMBA3", torture_bind_samba3);
296 torture_suite_add_simple_test(suite, "NETLOGSAMBA3", torture_netlogon_samba3);
297 torture_suite_add_simple_test(suite, "SAMBA3SESSIONKEY", torture_samba3_sessionkey);
298 torture_suite_add_simple_test(suite, "SAMBA3-SRVSVC", torture_samba3_rpc_srvsvc);
299 torture_suite_add_simple_test(suite, "SAMBA3-SHARESEC",
300 torture_samba3_rpc_sharesec);
301 torture_suite_add_simple_test(suite, "SAMBA3-GETUSERNAME",
302 torture_samba3_rpc_getusername);
303 torture_suite_add_simple_test(suite, "SAMBA3-LSA", torture_samba3_rpc_lsa);
304 torture_suite_add_simple_test(suite, "SAMBA3-SPOOLSS", torture_samba3_rpc_spoolss);
305 torture_suite_add_simple_test(suite, "SAMBA3-WKSSVC", torture_samba3_rpc_wkssvc);
306 torture_suite_add_simple_test(suite, "RPC-SAMBA3-WINREG", torture_samba3_rpc_winreg);
307 torture_suite_add_simple_test(suite, "DRSUAPI", torture_rpc_drsuapi);
308 torture_suite_add_simple_test(suite, "CRACKNAMES", torture_rpc_drsuapi_cracknames);
309 torture_suite_add_simple_test(suite, "DSSETUP", torture_rpc_dssetup);
310 torture_suite_add_simple_test(suite, "ALTERCONTEXT", torture_rpc_alter_context);
311 torture_suite_add_simple_test(suite, "JOIN", torture_rpc_join);
312 torture_suite_add_simple_test(suite, "DSSYNC", torture_rpc_dssync);
313 torture_suite_add_simple_test(suite, "BENCH-RPC", torture_bench_rpc);
314 torture_suite_add_simple_test(suite, "ASYNCBIND", torture_async_bind);
316 suite->description = talloc_strdup(suite, "DCE/RPC protocol and interface tests");
318 torture_register_suite(suite);