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 /* open a rpc connection to the chosen binding string */
37 _PUBLIC_ NTSTATUS torture_rpc_connection(struct torture_context *tctx,
38 struct dcerpc_pipe **p,
39 const struct ndr_interface_table *table)
42 const char *binding = torture_setting_string(tctx, "binding", NULL);
45 printf("You must specify a ncacn binding string\n");
46 return NT_STATUS_INVALID_PARAMETER;
49 status = dcerpc_pipe_connect(tctx,
51 cmdline_credentials, NULL);
53 if (!NT_STATUS_IS_OK(status)) {
54 printf("Failed to connect to remote server: %s %s\n", binding, nt_errstr(status));
60 /* open a rpc connection to a specific transport */
61 NTSTATUS torture_rpc_connection_transport(struct torture_context *tctx,
62 struct dcerpc_pipe **p,
63 const struct ndr_interface_table *table,
64 enum dcerpc_transport_t transport,
65 uint32_t assoc_group_id)
68 const char *binding = torture_setting_string(tctx, "binding", NULL);
69 struct dcerpc_binding *b;
70 TALLOC_CTX *mem_ctx = talloc_named(tctx, 0, "torture_rpc_connection_smb");
73 printf("You must specify a ncacn binding string\n");
75 return NT_STATUS_INVALID_PARAMETER;
78 status = dcerpc_parse_binding(mem_ctx, binding, &b);
79 if (!NT_STATUS_IS_OK(status)) {
80 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding));
85 b->transport = transport;
86 b->assoc_group_id = assoc_group_id;
88 status = dcerpc_pipe_connect_b(mem_ctx, p, b, table,
89 cmdline_credentials, NULL);
91 if (NT_STATUS_IS_OK(status)) {
92 *p = talloc_reference(tctx, *p);
100 static bool torture_rpc_setup_anonymous(struct torture_context *tctx,
103 struct cli_credentials *anon_credentials;
105 const char *binding = torture_setting_string(tctx, "binding", NULL);
106 struct torture_rpc_tcase *tcase = talloc_get_type(
107 tctx->active_tcase, struct torture_rpc_tcase);
109 anon_credentials = cli_credentials_init_anon(tctx);
111 status = dcerpc_pipe_connect(tctx,
112 (struct dcerpc_pipe **)data,
115 anon_credentials, NULL);
117 torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
122 static bool torture_rpc_setup (struct torture_context *tctx, void **data)
125 struct torture_rpc_tcase *tcase = talloc_get_type(
126 tctx->active_tcase, struct torture_rpc_tcase);
128 status = torture_rpc_connection(tctx,
129 (struct dcerpc_pipe **)data,
130 (const struct ndr_interface_table *)tcase->table);
132 torture_assert_ntstatus_ok(tctx, status, "Error connecting to server");
137 static bool torture_rpc_teardown (struct torture_context *tcase, void *data)
143 _PUBLIC_ struct torture_rpc_tcase *torture_suite_add_anon_rpc_iface_tcase(struct torture_suite *suite,
145 const struct ndr_interface_table *table)
147 struct torture_rpc_tcase *tcase = talloc(suite, struct torture_rpc_tcase);
149 torture_suite_init_tcase(suite, (struct torture_tcase *)tcase, name);
151 tcase->tcase.setup = torture_rpc_setup_anonymous;
152 tcase->tcase.teardown = torture_rpc_teardown;
153 tcase->table = table;
159 _PUBLIC_ struct torture_rpc_tcase *torture_suite_add_rpc_iface_tcase(struct torture_suite *suite,
161 const struct ndr_interface_table *table)
163 struct torture_rpc_tcase *tcase = talloc(suite, struct torture_rpc_tcase);
165 torture_suite_init_tcase(suite, (struct torture_tcase *)tcase, name);
167 tcase->tcase.setup = torture_rpc_setup;
168 tcase->tcase.teardown = torture_rpc_teardown;
169 tcase->table = table;
174 static bool torture_rpc_wrap_test(struct torture_context *tctx,
175 struct torture_tcase *tcase,
176 struct torture_test *test)
178 bool (*fn) (struct torture_context *, struct dcerpc_pipe *);
182 return fn(tctx, (struct dcerpc_pipe *)tcase->data);
185 static bool torture_rpc_wrap_test_ex(struct torture_context *tctx,
186 struct torture_tcase *tcase,
187 struct torture_test *test)
189 bool (*fn) (struct torture_context *, struct dcerpc_pipe *, const void *);
193 return fn(tctx, (struct dcerpc_pipe *)tcase->data, test->data);
196 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test(
197 struct torture_rpc_tcase *tcase,
199 bool (*fn) (struct torture_context *, struct dcerpc_pipe *))
201 struct torture_test *test;
203 test = talloc(tcase, struct torture_test);
205 test->name = talloc_strdup(test, name);
206 test->description = NULL;
207 test->run = torture_rpc_wrap_test;
208 test->dangerous = false;
212 DLIST_ADD(tcase->tcase.tests, test);
217 _PUBLIC_ struct torture_test *torture_rpc_tcase_add_test_ex(
218 struct torture_rpc_tcase *tcase,
220 bool (*fn) (struct torture_context *, struct dcerpc_pipe *,
224 struct torture_test *test;
226 test = talloc(tcase, struct torture_test);
228 test->name = talloc_strdup(test, name);
229 test->description = NULL;
230 test->run = torture_rpc_wrap_test_ex;
231 test->dangerous = false;
232 test->data = userdata;
235 DLIST_ADD(tcase->tcase.tests, test);
240 NTSTATUS torture_rpc_init(void)
242 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "RPC");
248 torture_suite_add_simple_test(suite, "LSA", torture_rpc_lsa);
249 torture_suite_add_simple_test(suite, "LSALOOKUP", torture_rpc_lsa_lookup);
250 torture_suite_add_simple_test(suite, "LSA-GETUSER", torture_rpc_lsa_get_user);
251 torture_suite_add_simple_test(suite, "SECRETS", torture_rpc_lsa_secrets);
252 torture_suite_add_suite(suite, torture_rpc_echo());
253 torture_suite_add_suite(suite, torture_rpc_dfs());
254 torture_suite_add_suite(suite, torture_rpc_unixinfo());
255 torture_suite_add_suite(suite, torture_rpc_eventlog());
256 torture_suite_add_suite(suite, torture_rpc_atsvc());
257 torture_suite_add_suite(suite, torture_rpc_wkssvc());
258 torture_suite_add_suite(suite, torture_rpc_handles(suite));
259 torture_suite_add_suite(suite, torture_rpc_winreg(suite));
260 torture_suite_add_simple_test(suite, "SPOOLSS", torture_rpc_spoolss);
261 torture_suite_add_simple_test(suite, "SAMR", torture_rpc_samr);
262 torture_suite_add_simple_test(suite, "SAMR-USERS", torture_rpc_samr_users);
263 torture_suite_add_simple_test(suite, "SAMR-PASSWORDS", torture_rpc_samr_passwords);
264 torture_suite_add_simple_test(suite, "NETLOGON", torture_rpc_netlogon);
265 torture_suite_add_simple_test(suite, "SAMLOGON", torture_rpc_samlogon);
266 torture_suite_add_simple_test(suite, "SAMSYNC", torture_rpc_samsync);
267 torture_suite_add_simple_test(suite, "SCHANNEL", torture_rpc_schannel);
268 torture_suite_add_simple_test(suite, "SCHANNEL2", torture_rpc_schannel2);
269 torture_suite_add_suite(suite, torture_rpc_srvsvc(suite));
270 torture_suite_add_suite(suite, torture_rpc_svcctl(suite));
271 torture_suite_add_simple_test(suite, "EPMAPPER", torture_rpc_epmapper);
272 torture_suite_add_simple_test(suite, "INITSHUTDOWN", torture_rpc_initshutdown);
273 torture_suite_add_simple_test(suite, "OXIDRESOLVE", torture_rpc_oxidresolve);
274 torture_suite_add_simple_test(suite, "REMACT", torture_rpc_remact);
275 torture_suite_add_simple_test(suite, "MGMT", torture_rpc_mgmt);
276 torture_suite_add_simple_test(suite, "SCANNER", torture_rpc_scanner);
277 torture_suite_add_simple_test(suite, "AUTOIDL", torture_rpc_autoidl);
278 torture_suite_add_simple_test(suite, "COUNTCALLS", torture_rpc_countcalls);
279 torture_suite_add_simple_test(suite, "MULTIBIND", torture_multi_bind);
280 torture_suite_add_simple_test(suite, "AUTHCONTEXT", torture_bind_authcontext);
281 torture_suite_add_simple_test(suite, "BINDSAMBA3", torture_bind_samba3);
282 torture_suite_add_simple_test(suite, "NETLOGSAMBA3", torture_netlogon_samba3);
283 torture_suite_add_simple_test(suite, "SAMBA3SESSIONKEY", torture_samba3_sessionkey);
284 torture_suite_add_simple_test(suite, "SAMBA3-SRVSVC", torture_samba3_rpc_srvsvc);
285 torture_suite_add_simple_test(suite, "SAMBA3-SHARESEC",
286 torture_samba3_rpc_sharesec);
287 torture_suite_add_simple_test(suite, "SAMBA3-GETUSERNAME",
288 torture_samba3_rpc_getusername);
289 torture_suite_add_simple_test(suite, "SAMBA3-LSA", torture_samba3_rpc_lsa);
290 torture_suite_add_simple_test(suite, "SAMBA3-SPOOLSS", torture_samba3_rpc_spoolss);
291 torture_suite_add_simple_test(suite, "SAMBA3-WKSSVC", torture_samba3_rpc_wkssvc);
292 torture_suite_add_simple_test(suite, "RPC-SAMBA3-WINREG", torture_samba3_rpc_winreg);
293 torture_suite_add_simple_test(suite, "DRSUAPI", torture_rpc_drsuapi);
294 torture_suite_add_simple_test(suite, "CRACKNAMES", torture_rpc_drsuapi_cracknames);
295 torture_suite_add_simple_test(suite, "ROT", torture_rpc_rot);
296 torture_suite_add_simple_test(suite, "DSSETUP", torture_rpc_dssetup);
297 torture_suite_add_simple_test(suite, "ALTERCONTEXT", torture_rpc_alter_context);
298 torture_suite_add_simple_test(suite, "JOIN", torture_rpc_join);
299 torture_suite_add_simple_test(suite, "DSSYNC", torture_rpc_dssync);
300 torture_suite_add_simple_test(suite, "BENCH-RPC", torture_bench_rpc);
301 torture_suite_add_simple_test(suite, "ASYNCBIND", torture_async_bind);
303 suite->description = talloc_strdup(suite, "DCE/RPC protocol and interface tests");
305 torture_register_suite(suite);