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 "lib/cmdline/popt_common.h"
23 #include "torture/rpc/torture_rpc.h"
24 #include "torture/smbtorture.h"
25 #include "librpc/ndr/ndr_table.h"
26 #include "../lib/util/dlinklist.h"
28 static bool torture_rpc_teardown (struct torture_context
*tcase
,
31 struct torture_rpc_tcase_data
*tcase_data
=
32 (struct torture_rpc_tcase_data
*)data
;
33 if (tcase_data
->join_ctx
!= NULL
)
34 torture_leave_domain(tcase
, tcase_data
->join_ctx
);
35 talloc_free(tcase_data
);
40 * Obtain the DCE/RPC binding context associated with a torture context.
42 * @param tctx Torture context
43 * @param binding Pointer to store DCE/RPC binding
45 NTSTATUS
torture_rpc_binding(struct torture_context
*tctx
,
46 struct dcerpc_binding
**binding
)
49 const char *binding_string
= torture_setting_string(tctx
, "binding",
52 if (binding_string
== NULL
) {
54 "You must specify a DCE/RPC binding string\n");
55 return NT_STATUS_INVALID_PARAMETER
;
58 status
= dcerpc_parse_binding(tctx
, binding_string
, binding
);
59 if (NT_STATUS_IS_ERR(status
)) {
60 DEBUG(0,("Failed to parse dcerpc binding '%s'\n",
69 * open a rpc connection to the chosen binding string
71 _PUBLIC_ NTSTATUS
torture_rpc_connection(struct torture_context
*tctx
,
72 struct dcerpc_pipe
**p
,
73 const struct ndr_interface_table
*table
)
76 struct dcerpc_binding
*binding
;
80 status
= torture_rpc_binding(tctx
, &binding
);
81 if (NT_STATUS_IS_ERR(status
))
84 status
= dcerpc_pipe_connect_b(tctx
,
86 cmdline_credentials
, tctx
->ev
, tctx
->lp_ctx
);
88 if (NT_STATUS_IS_ERR(status
)) {
89 printf("Failed to connect to remote server: %s %s\n",
90 dcerpc_binding_string(tctx
, binding
), nt_errstr(status
));
97 * open a rpc connection to a specific transport
99 NTSTATUS
torture_rpc_connection_transport(struct torture_context
*tctx
,
100 struct dcerpc_pipe
**p
,
101 const struct ndr_interface_table
*table
,
102 enum dcerpc_transport_t transport
,
103 uint32_t assoc_group_id
)
106 struct dcerpc_binding
*binding
;
108 status
= torture_rpc_binding(tctx
, &binding
);
109 if (NT_STATUS_IS_ERR(status
))
112 binding
->transport
= transport
;
113 binding
->assoc_group_id
= assoc_group_id
;
115 status
= dcerpc_pipe_connect_b(tctx
, p
, binding
, table
,
116 cmdline_credentials
, tctx
->ev
, tctx
->lp_ctx
);
118 if (NT_STATUS_IS_ERR(status
)) {
125 static bool torture_rpc_setup_machine_workstation(struct torture_context
*tctx
,
129 struct dcerpc_binding
*binding
;
130 struct torture_rpc_tcase
*tcase
= talloc_get_type(tctx
->active_tcase
,
131 struct torture_rpc_tcase
);
132 struct torture_rpc_tcase_data
*tcase_data
;
134 status
= torture_rpc_binding(tctx
, &binding
);
135 if (NT_STATUS_IS_ERR(status
))
138 *data
= tcase_data
= talloc_zero(tctx
, struct torture_rpc_tcase_data
);
139 tcase_data
->credentials
= cmdline_credentials
;
140 tcase_data
->join_ctx
= torture_join_domain(tctx
, tcase
->machine_name
,
142 &tcase_data
->credentials
);
143 if (tcase_data
->join_ctx
== NULL
)
144 torture_fail(tctx
, "Failed to join as WORKSTATION");
146 status
= dcerpc_pipe_connect_b(tctx
,
150 tcase_data
->credentials
, tctx
->ev
, tctx
->lp_ctx
);
152 torture_assert_ntstatus_ok(tctx
, status
, "Error connecting to server");
154 return NT_STATUS_IS_OK(status
);
157 static bool torture_rpc_setup_machine_bdc(struct torture_context
*tctx
,
161 struct dcerpc_binding
*binding
;
162 struct torture_rpc_tcase
*tcase
= talloc_get_type(tctx
->active_tcase
,
163 struct torture_rpc_tcase
);
164 struct torture_rpc_tcase_data
*tcase_data
;
166 status
= torture_rpc_binding(tctx
, &binding
);
167 if (NT_STATUS_IS_ERR(status
))
170 *data
= tcase_data
= talloc_zero(tctx
, struct torture_rpc_tcase_data
);
171 tcase_data
->credentials
= cmdline_credentials
;
172 tcase_data
->join_ctx
= torture_join_domain(tctx
, tcase
->machine_name
,
174 &tcase_data
->credentials
);
175 if (tcase_data
->join_ctx
== NULL
)
176 torture_fail(tctx
, "Failed to join as BDC");
178 status
= dcerpc_pipe_connect_b(tctx
,
182 tcase_data
->credentials
, tctx
->ev
, tctx
->lp_ctx
);
184 torture_assert_ntstatus_ok(tctx
, status
, "Error connecting to server");
186 return NT_STATUS_IS_OK(status
);
189 _PUBLIC_
struct torture_rpc_tcase
*torture_suite_add_machine_workstation_rpc_iface_tcase(
190 struct torture_suite
*suite
,
192 const struct ndr_interface_table
*table
,
193 const char *machine_name
)
195 struct torture_rpc_tcase
*tcase
= talloc(suite
,
196 struct torture_rpc_tcase
);
198 torture_suite_init_rpc_tcase(suite
, tcase
, name
, table
);
200 tcase
->machine_name
= talloc_strdup(tcase
, machine_name
);
201 tcase
->tcase
.setup
= torture_rpc_setup_machine_workstation
;
202 tcase
->tcase
.teardown
= torture_rpc_teardown
;
207 _PUBLIC_
struct torture_rpc_tcase
*torture_suite_add_machine_bdc_rpc_iface_tcase(
208 struct torture_suite
*suite
,
210 const struct ndr_interface_table
*table
,
211 const char *machine_name
)
213 struct torture_rpc_tcase
*tcase
= talloc(suite
,
214 struct torture_rpc_tcase
);
216 torture_suite_init_rpc_tcase(suite
, tcase
, name
, table
);
218 tcase
->machine_name
= talloc_strdup(tcase
, machine_name
);
219 tcase
->tcase
.setup
= torture_rpc_setup_machine_bdc
;
220 tcase
->tcase
.teardown
= torture_rpc_teardown
;
225 _PUBLIC_
bool torture_suite_init_rpc_tcase(struct torture_suite
*suite
,
226 struct torture_rpc_tcase
*tcase
,
228 const struct ndr_interface_table
*table
)
230 if (!torture_suite_init_tcase(suite
, (struct torture_tcase
*)tcase
, name
))
233 tcase
->table
= table
;
238 static bool torture_rpc_setup_anonymous(struct torture_context
*tctx
,
242 struct dcerpc_binding
*binding
;
243 struct torture_rpc_tcase_data
*tcase_data
;
244 struct torture_rpc_tcase
*tcase
= talloc_get_type(tctx
->active_tcase
,
245 struct torture_rpc_tcase
);
247 status
= torture_rpc_binding(tctx
, &binding
);
248 if (NT_STATUS_IS_ERR(status
))
251 *data
= tcase_data
= talloc_zero(tctx
, struct torture_rpc_tcase_data
);
252 tcase_data
->credentials
= cli_credentials_init_anon(tctx
);
254 status
= dcerpc_pipe_connect_b(tctx
,
258 tcase_data
->credentials
, tctx
->ev
, tctx
->lp_ctx
);
260 torture_assert_ntstatus_ok(tctx
, status
, "Error connecting to server");
262 return NT_STATUS_IS_OK(status
);
265 static bool torture_rpc_setup (struct torture_context
*tctx
, void **data
)
268 struct torture_rpc_tcase
*tcase
= talloc_get_type(
269 tctx
->active_tcase
, struct torture_rpc_tcase
);
270 struct torture_rpc_tcase_data
*tcase_data
;
272 *data
= tcase_data
= talloc_zero(tctx
, struct torture_rpc_tcase_data
);
273 tcase_data
->credentials
= cmdline_credentials
;
275 status
= torture_rpc_connection(tctx
,
279 torture_assert_ntstatus_ok(tctx
, status
, "Error connecting to server");
281 return NT_STATUS_IS_OK(status
);
286 _PUBLIC_
struct torture_rpc_tcase
*torture_suite_add_anon_rpc_iface_tcase(struct torture_suite
*suite
,
288 const struct ndr_interface_table
*table
)
290 struct torture_rpc_tcase
*tcase
= talloc(suite
, struct torture_rpc_tcase
);
292 torture_suite_init_rpc_tcase(suite
, tcase
, name
, table
);
294 tcase
->tcase
.setup
= torture_rpc_setup_anonymous
;
295 tcase
->tcase
.teardown
= torture_rpc_teardown
;
301 _PUBLIC_
struct torture_rpc_tcase
*torture_suite_add_rpc_iface_tcase(struct torture_suite
*suite
,
303 const struct ndr_interface_table
*table
)
305 struct torture_rpc_tcase
*tcase
= talloc(suite
, struct torture_rpc_tcase
);
307 torture_suite_init_rpc_tcase(suite
, tcase
, name
, table
);
309 tcase
->tcase
.setup
= torture_rpc_setup
;
310 tcase
->tcase
.teardown
= torture_rpc_teardown
;
315 static bool torture_rpc_wrap_test(struct torture_context
*tctx
,
316 struct torture_tcase
*tcase
,
317 struct torture_test
*test
)
319 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*);
320 struct torture_rpc_tcase_data
*tcase_data
=
321 (struct torture_rpc_tcase_data
*)tcase
->data
;
325 return fn(tctx
, tcase_data
->pipe
);
328 static bool torture_rpc_wrap_test_ex(struct torture_context
*tctx
,
329 struct torture_tcase
*tcase
,
330 struct torture_test
*test
)
332 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*, const void *);
333 struct torture_rpc_tcase_data
*tcase_data
=
334 (struct torture_rpc_tcase_data
*)tcase
->data
;
338 return fn(tctx
, tcase_data
->pipe
, test
->data
);
342 static bool torture_rpc_wrap_test_creds(struct torture_context
*tctx
,
343 struct torture_tcase
*tcase
,
344 struct torture_test
*test
)
346 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*, struct cli_credentials
*);
347 struct torture_rpc_tcase_data
*tcase_data
=
348 (struct torture_rpc_tcase_data
*)tcase
->data
;
352 return fn(tctx
, tcase_data
->pipe
, tcase_data
->credentials
);
355 static bool torture_rpc_wrap_test_join(struct torture_context
*tctx
,
356 struct torture_tcase
*tcase
,
357 struct torture_test
*test
)
359 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*, struct cli_credentials
*, struct test_join
*);
360 struct torture_rpc_tcase_data
*tcase_data
=
361 (struct torture_rpc_tcase_data
*)tcase
->data
;
365 return fn(tctx
, tcase_data
->pipe
, tcase_data
->credentials
, tcase_data
->join_ctx
);
368 _PUBLIC_
struct torture_test
*torture_rpc_tcase_add_test(
369 struct torture_rpc_tcase
*tcase
,
371 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*))
373 struct torture_test
*test
;
375 test
= talloc(tcase
, struct torture_test
);
377 test
->name
= talloc_strdup(test
, name
);
378 test
->description
= NULL
;
379 test
->run
= torture_rpc_wrap_test
;
380 test
->dangerous
= false;
384 DLIST_ADD(tcase
->tcase
.tests
, test
);
389 _PUBLIC_
struct torture_test
*torture_rpc_tcase_add_test_creds(
390 struct torture_rpc_tcase
*tcase
,
392 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*, struct cli_credentials
*))
394 struct torture_test
*test
;
396 test
= talloc(tcase
, struct torture_test
);
398 test
->name
= talloc_strdup(test
, name
);
399 test
->description
= NULL
;
400 test
->run
= torture_rpc_wrap_test_creds
;
401 test
->dangerous
= false;
405 DLIST_ADD(tcase
->tcase
.tests
, test
);
410 _PUBLIC_
struct torture_test
*torture_rpc_tcase_add_test_join(
411 struct torture_rpc_tcase
*tcase
,
413 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*,
414 struct cli_credentials
*, struct test_join
*))
416 struct torture_test
*test
;
418 test
= talloc(tcase
, struct torture_test
);
420 test
->name
= talloc_strdup(test
, name
);
421 test
->description
= NULL
;
422 test
->run
= torture_rpc_wrap_test_join
;
423 test
->dangerous
= false;
427 DLIST_ADD(tcase
->tcase
.tests
, test
);
432 _PUBLIC_
struct torture_test
*torture_rpc_tcase_add_test_ex(
433 struct torture_rpc_tcase
*tcase
,
435 bool (*fn
) (struct torture_context
*, struct dcerpc_pipe
*,
439 struct torture_test
*test
;
441 test
= talloc(tcase
, struct torture_test
);
443 test
->name
= talloc_strdup(test
, name
);
444 test
->description
= NULL
;
445 test
->run
= torture_rpc_wrap_test_ex
;
446 test
->dangerous
= false;
447 test
->data
= userdata
;
450 DLIST_ADD(tcase
->tcase
.tests
, test
);
455 NTSTATUS
torture_rpc_init(void)
457 struct torture_suite
*suite
= torture_suite_create(talloc_autofree_context(), "rpc");
461 torture_suite_add_simple_test(suite
, "lsa", torture_rpc_lsa
);
462 torture_suite_add_simple_test(suite
, "lsalookup", torture_rpc_lsa_lookup
);
463 torture_suite_add_simple_test(suite
, "lsa-getuser", torture_rpc_lsa_get_user
);
464 torture_suite_add_suite(suite
, torture_rpc_lsa_lookup_sids(suite
));
465 torture_suite_add_suite(suite
, torture_rpc_lsa_lookup_names(suite
));
466 torture_suite_add_suite(suite
, torture_rpc_lsa_secrets(suite
));
467 torture_suite_add_suite(suite
, torture_rpc_lsa_trusted_domains(suite
));
468 torture_suite_add_suite(suite
, torture_rpc_lsa_forest_trust(suite
));
469 torture_suite_add_suite(suite
, torture_rpc_lsa_privileges(suite
));
470 torture_suite_add_suite(suite
, torture_rpc_echo(suite
));
471 torture_suite_add_suite(suite
, torture_rpc_dfs(suite
));
472 torture_suite_add_suite(suite
, torture_rpc_frsapi(suite
));
473 torture_suite_add_suite(suite
, torture_rpc_unixinfo(suite
));
474 torture_suite_add_suite(suite
, torture_rpc_eventlog(suite
));
475 torture_suite_add_suite(suite
, torture_rpc_atsvc(suite
));
476 torture_suite_add_suite(suite
, torture_rpc_wkssvc(suite
));
477 torture_suite_add_suite(suite
, torture_rpc_handles(suite
));
478 torture_suite_add_suite(suite
, torture_rpc_object_uuid(suite
));
479 torture_suite_add_suite(suite
, torture_rpc_winreg(suite
));
480 torture_suite_add_suite(suite
, torture_rpc_spoolss(suite
));
481 #ifdef AD_DC_BUILD_IS_ENABLED
482 torture_suite_add_suite(suite
, torture_rpc_spoolss_notify(suite
));
483 torture_suite_add_suite(suite
, torture_rpc_spoolss_win(suite
));
485 torture_suite_add_suite(suite
, torture_rpc_spoolss_driver(suite
));
486 torture_suite_add_suite(suite
, torture_rpc_spoolss_access(suite
));
487 torture_suite_add_simple_test(suite
, "samr", torture_rpc_samr
);
488 torture_suite_add_simple_test(suite
, "samr.users", torture_rpc_samr_users
);
489 torture_suite_add_simple_test(suite
, "samr.passwords", torture_rpc_samr_passwords
);
490 torture_suite_add_suite(suite
, torture_rpc_netlogon(suite
));
491 torture_suite_add_suite(suite
, torture_rpc_netlogon_s3(suite
));
492 torture_suite_add_suite(suite
, torture_rpc_netlogon_admin(suite
));
493 torture_suite_add_suite(suite
, torture_rpc_remote_pac(suite
));
494 torture_suite_add_simple_test(suite
, "samlogon", torture_rpc_samlogon
);
495 torture_suite_add_simple_test(suite
, "samsync", torture_rpc_samsync
);
496 torture_suite_add_simple_test(suite
, "schannel", torture_rpc_schannel
);
497 torture_suite_add_simple_test(suite
, "schannel2", torture_rpc_schannel2
);
498 torture_suite_add_simple_test(suite
, "bench-schannel1", torture_rpc_schannel_bench1
);
499 torture_suite_add_suite(suite
, torture_rpc_srvsvc(suite
));
500 torture_suite_add_suite(suite
, torture_rpc_svcctl(suite
));
501 torture_suite_add_suite(suite
, torture_rpc_samr_accessmask(suite
));
502 torture_suite_add_suite(suite
, torture_rpc_samr_workstation_auth(suite
));
503 torture_suite_add_suite(suite
, torture_rpc_samr_passwords_pwdlastset(suite
));
504 torture_suite_add_suite(suite
, torture_rpc_samr_passwords_badpwdcount(suite
));
505 torture_suite_add_suite(suite
, torture_rpc_samr_passwords_lockout(suite
));
506 torture_suite_add_suite(suite
, torture_rpc_samr_user_privileges(suite
));
507 torture_suite_add_suite(suite
, torture_rpc_samr_large_dc(suite
));
508 torture_suite_add_suite(suite
, torture_rpc_samr_priv(suite
));
509 torture_suite_add_suite(suite
, torture_rpc_epmapper(suite
));
510 torture_suite_add_suite(suite
, torture_rpc_initshutdown(suite
));
511 torture_suite_add_suite(suite
, torture_rpc_oxidresolve(suite
));
512 torture_suite_add_suite(suite
, torture_rpc_remact(suite
));
513 torture_suite_add_simple_test(suite
, "mgmt", torture_rpc_mgmt
);
514 torture_suite_add_simple_test(suite
, "scanner", torture_rpc_scanner
);
515 torture_suite_add_simple_test(suite
, "autoidl", torture_rpc_autoidl
);
516 torture_suite_add_simple_test(suite
, "countcalls", torture_rpc_countcalls
);
517 torture_suite_add_simple_test(suite
, "multibind", torture_multi_bind
);
518 torture_suite_add_simple_test(suite
, "authcontext", torture_bind_authcontext
);
519 torture_suite_add_suite(suite
, torture_rpc_samba3(suite
));
520 torture_rpc_drsuapi_tcase(suite
);
521 torture_rpc_drsuapi_cracknames_tcase(suite
);
522 torture_suite_add_suite(suite
, torture_rpc_dssetup(suite
));
523 torture_suite_add_suite(suite
, torture_rpc_browser(suite
));
524 torture_suite_add_simple_test(suite
, "altercontext", torture_rpc_alter_context
);
525 torture_suite_add_simple_test(suite
, "join", torture_rpc_join
);
526 torture_drs_rpc_dsgetinfo_tcase(suite
);
527 torture_suite_add_simple_test(suite
, "bench-rpc", torture_bench_rpc
);
528 torture_suite_add_simple_test(suite
, "asyncbind", torture_async_bind
);
529 torture_suite_add_suite(suite
, torture_rpc_ntsvcs(suite
));
530 torture_suite_add_suite(suite
, torture_rpc_bind(suite
));
531 #ifdef AD_DC_BUILD_IS_ENABLED /* Add Heimdal-specific KDC test */
532 torture_suite_add_suite(suite
, torture_rpc_backupkey(suite
));
534 torture_suite_add_suite(suite
, torture_rpc_fsrvp(suite
));
536 suite
->description
= talloc_strdup(suite
, "DCE/RPC protocol and interface tests");
538 torture_register_suite(suite
);