s4-torture: using async dcerpc for witness async notifications.
[Samba.git] / source4 / torture / rpc / witness.c
blobf040e0b9ea4b314f559d19e15c747da98ed6beb5
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for rpc witness operations
5 Copyright (C) Guenther Deschner 2015
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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "torture/rpc/torture_rpc.h"
24 #include "librpc/gen_ndr/ndr_witness_c.h"
25 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
26 #include "librpc/gen_ndr/ndr_clusapi_c.h"
27 #include "param/param.h"
28 #include <tevent.h>
30 struct torture_test_clusapi_state {
31 struct dcerpc_pipe *p;
34 struct torture_test_witness_state {
35 const char *net_name;
36 const char *share_name;
37 struct witness_interfaceList *list;
38 struct policy_handle context_handle;
39 struct torture_test_clusapi_state clusapi;
42 static bool test_witness_GetInterfaceList(struct torture_context *tctx,
43 struct dcerpc_pipe *p,
44 void *data)
46 struct dcerpc_binding_handle *b = p->binding_handle;
47 struct witness_GetInterfaceList r;
48 struct witness_interfaceList *l;
49 struct torture_test_witness_state *state =
50 (struct torture_test_witness_state *)data;
52 r.out.interface_list = &l;
54 torture_assert_ntstatus_ok(tctx,
55 dcerpc_witness_GetInterfaceList_r(b, tctx, &r),
56 "GetInterfaceList failed");
58 torture_assert_werr_ok(tctx,
59 r.out.result,
60 "GetInterfaceList failed");
62 state->list = l;
64 return true;
67 static bool find_sofs_share(struct torture_context *tctx,
68 const char **sofs_sharename)
70 struct dcerpc_pipe *p;
71 struct dcerpc_binding_handle *b;
72 struct srvsvc_NetShareEnumAll r;
73 struct srvsvc_NetShareInfoCtr info_ctr;
74 struct srvsvc_NetShareCtr1 ctr1;
75 uint32_t resume_handle = 0;
76 uint32_t totalentries = 0;
77 int i;
79 torture_assert_ntstatus_ok(tctx,
80 torture_rpc_connection_transport(tctx, &p, &ndr_table_srvsvc,
81 NCACN_NP, 0),
82 "failed to setup srvsvc connection");
84 b = p->binding_handle;
86 ZERO_STRUCT(ctr1);
88 info_ctr.level = 1;
89 info_ctr.ctr.ctr1 = &ctr1;
91 r.in.server_unc = dcerpc_server_name(p);
92 r.in.max_buffer = -1;
93 r.in.info_ctr = &info_ctr;
94 r.in.resume_handle = &resume_handle;
95 r.out.totalentries = &totalentries;
96 r.out.info_ctr = &info_ctr;
97 r.out.resume_handle = &resume_handle;
99 torture_assert_ntstatus_ok(tctx,
100 dcerpc_srvsvc_NetShareEnumAll_r(b, tctx, &r),
101 "failed to call srvsvc_NetShareEnumAll");
103 torture_assert_werr_ok(tctx,
104 r.out.result,
105 "failed to call srvsvc_NetShareEnumAll");
107 for (i=0; i < r.out.info_ctr->ctr.ctr1->count; i++) {
109 if (r.out.info_ctr->ctr.ctr1->array[i].type == STYPE_CLUSTER_SOFS) {
110 *sofs_sharename = talloc_strdup(tctx, r.out.info_ctr->ctr.ctr1->array[i].name);
111 if (*sofs_sharename == NULL) {
112 return false;
114 torture_comment(tctx, "using SOFS share: %s\n", *sofs_sharename);
115 return true;
117 if (r.out.info_ctr->ctr.ctr1->array[i].type == STYPE_DISKTREE) {
118 *sofs_sharename = talloc_strdup(tctx, r.out.info_ctr->ctr.ctr1->array[i].name);
119 if (*sofs_sharename == NULL) {
120 return false;
122 torture_comment(tctx, "assuming SOFS share: %s\n", *sofs_sharename);
123 return true;
127 return false;
130 static bool init_witness_test_state(struct torture_context *tctx,
131 struct dcerpc_pipe *p,
132 struct torture_test_witness_state *state)
134 if (state->net_name == NULL) {
135 state->net_name = lpcfg_parm_string(tctx->lp_ctx, NULL, "torture", "net_name");
138 if (state->list == NULL) {
139 torture_assert(tctx,
140 test_witness_GetInterfaceList(tctx, p, state),
141 "failed to retrieve GetInterfaceList");
144 if (state->share_name == NULL) {
145 find_sofs_share(tctx, &state->share_name);
148 return true;
151 static bool test_witness_UnRegister_with_handle(struct torture_context *tctx,
152 struct dcerpc_pipe *p,
153 struct policy_handle *context_handle)
155 struct dcerpc_binding_handle *b = p->binding_handle;
156 struct witness_UnRegister r;
158 r.in.context_handle = *context_handle;
160 torture_assert_ntstatus_ok(tctx,
161 dcerpc_witness_UnRegister_r(b, tctx, &r),
162 "UnRegister failed");
164 torture_assert_werr_ok(tctx,
165 r.out.result,
166 "UnRegister failed");
168 /* make sure we are not able/allowed to reuse context handles after they
169 * have been unregistered */
171 torture_assert_ntstatus_ok(tctx,
172 dcerpc_witness_UnRegister_r(b, tctx, &r),
173 "UnRegister failed");
175 torture_assert_werr_equal(tctx,
176 r.out.result,
177 WERR_INVALID_PARAM,
178 "UnRegister failed");
180 return true;
183 static bool test_witness_UnRegister(struct torture_context *tctx,
184 struct dcerpc_pipe *p,
185 void *data)
187 /* acquire handle and free afterwards */
188 return true;
191 static bool get_ip_address_from_interface(struct torture_context *tctx,
192 struct witness_interfaceInfo *i,
193 const char **ip_address)
195 if (i->flags & WITNESS_INFO_IPv4_VALID) {
196 *ip_address = talloc_strdup(tctx, i->ipv4);
197 torture_assert(tctx, *ip_address, "talloc_strdup failed");
198 return true;
201 if (i->flags & WITNESS_INFO_IPv6_VALID) {
202 *ip_address = talloc_strdup(tctx, i->ipv6);
203 torture_assert(tctx, *ip_address, "talloc_strdup failed");
204 return true;
207 return false;
210 static bool check_valid_interface(struct torture_context *tctx,
211 struct witness_interfaceInfo *i)
213 /* continue looking for an interface that allows witness
214 * registration */
215 if (!(i->flags & WITNESS_INFO_WITNESS_IF)) {
216 return false;
219 /* witness should be available of course */
220 if (i->state != WITNESS_STATE_AVAILABLE) {
221 return false;
224 return true;
227 static bool test_witness_Register(struct torture_context *tctx,
228 struct dcerpc_pipe *p,
229 void *data)
231 struct dcerpc_binding_handle *b = p->binding_handle;
232 struct witness_Register r;
233 struct policy_handle context_handle;
234 struct torture_test_witness_state *state =
235 (struct torture_test_witness_state *)data;
236 int i;
238 struct {
239 enum witness_version version;
240 const char *net_name;
241 const char *ip_address;
242 const char *client_computer_name;
243 NTSTATUS expected_status;
244 WERROR expected_result;
245 } tests[] = {
247 .version = 0,
248 .expected_status = NT_STATUS_OK,
249 .expected_result = WERR_REVISION_MISMATCH
251 .version = 1,
252 .expected_status = NT_STATUS_OK,
253 .expected_result = WERR_REVISION_MISMATCH
255 .version = 123456,
256 .expected_status = NT_STATUS_OK,
257 .expected_result = WERR_REVISION_MISMATCH
259 .version = -1,
260 .expected_status = NT_STATUS_OK,
261 .expected_result = WERR_REVISION_MISMATCH
263 .version = WITNESS_V2,
264 .expected_status = NT_STATUS_OK,
265 .expected_result = WERR_REVISION_MISMATCH
267 .version = WITNESS_V1,
268 .net_name = "",
269 .ip_address = "",
270 .client_computer_name = "",
271 .expected_status = NT_STATUS_OK,
272 .expected_result = WERR_INVALID_PARAM
274 .version = WITNESS_V1,
275 .net_name = NULL,
276 .ip_address = NULL,
277 .client_computer_name = lpcfg_netbios_name(tctx->lp_ctx),
278 .expected_status = NT_STATUS_OK,
279 .expected_result = WERR_INVALID_PARAM
281 .version = WITNESS_V2,
282 .net_name = NULL,
283 .ip_address = NULL,
284 .client_computer_name = lpcfg_netbios_name(tctx->lp_ctx),
285 .expected_status = NT_STATUS_OK,
286 .expected_result = WERR_REVISION_MISMATCH
288 .version = WITNESS_V1,
289 .net_name = dcerpc_server_name(p),
290 .ip_address = NULL,
291 .client_computer_name = lpcfg_netbios_name(tctx->lp_ctx),
292 .expected_status = NT_STATUS_OK,
293 .expected_result = WERR_INVALID_PARAM
298 for (i=0; i < ARRAY_SIZE(tests); i++) {
300 ZERO_STRUCT(r);
302 r.out.context_handle = &context_handle;
304 r.in.version = tests[i].version;
305 r.in.net_name = tests[i].net_name;
306 r.in.ip_address = tests[i].ip_address;
307 r.in.client_computer_name = tests[i].client_computer_name;
309 torture_assert_ntstatus_equal(tctx,
310 dcerpc_witness_Register_r(b, tctx, &r),
311 tests[i].expected_status,
312 "Register failed");
314 torture_assert_werr_equal(tctx,
315 r.out.result,
316 tests[i].expected_result,
317 "Register failed");
319 if (W_ERROR_IS_OK(r.out.result)) {
321 /* we have a handle, make sure to unregister it */
322 torture_assert(tctx,
323 test_witness_UnRegister_with_handle(tctx, p, r.out.context_handle),
324 "Failed to unregister");
328 init_witness_test_state(tctx, p, state);
330 for (i=0; state->list && i < state->list->num_interfaces; i++) {
332 const char *ip_address;
333 struct witness_interfaceInfo interface = state->list->interfaces[i];
335 if (!check_valid_interface(tctx, &interface)) {
336 continue;
339 torture_assert(tctx,
340 get_ip_address_from_interface(tctx, &interface, &ip_address),
341 "failed to get ip_address from interface");
343 r.in.version = WITNESS_V1;
344 r.in.net_name = state->net_name;
345 r.in.ip_address = ip_address;
347 torture_assert_ntstatus_ok(tctx,
348 dcerpc_witness_Register_r(b, tctx, &r),
349 "Register failed");
351 torture_assert_werr_ok(tctx,
352 r.out.result,
353 "Register failed");
355 torture_assert(tctx,
356 test_witness_UnRegister_with_handle(tctx, p, r.out.context_handle),
357 "Failed to unregister");
360 return true;
363 static bool test_witness_RegisterEx(struct torture_context *tctx,
364 struct dcerpc_pipe *p,
365 void *data)
367 struct dcerpc_binding_handle *b = p->binding_handle;
368 struct witness_RegisterEx r;
369 struct policy_handle context_handle;
370 struct torture_test_witness_state *state =
371 (struct torture_test_witness_state *)data;
372 int i;
374 struct {
375 enum witness_version version;
376 const char *net_name;
377 const char *ip_address;
378 const char *client_computer_name;
379 NTSTATUS expected_status;
380 WERROR expected_result;
381 } tests[] = {
383 .version = 0,
384 .expected_status = NT_STATUS_OK,
385 .expected_result = WERR_REVISION_MISMATCH
387 .version = 1,
388 .expected_status = NT_STATUS_OK,
389 .expected_result = WERR_REVISION_MISMATCH
391 .version = 123456,
392 .expected_status = NT_STATUS_OK,
393 .expected_result = WERR_REVISION_MISMATCH
395 .version = -1,
396 .expected_status = NT_STATUS_OK,
397 .expected_result = WERR_REVISION_MISMATCH
399 .version = WITNESS_V1,
400 .expected_status = NT_STATUS_OK,
401 .expected_result = WERR_REVISION_MISMATCH
403 .version = WITNESS_V2,
404 .net_name = "",
405 .ip_address = "",
406 .client_computer_name = "",
407 .expected_status = NT_STATUS_OK,
408 .expected_result = WERR_INVALID_PARAM
410 .version = WITNESS_V2,
411 .net_name = NULL,
412 .ip_address = NULL,
413 .client_computer_name = lpcfg_netbios_name(tctx->lp_ctx),
414 .expected_status = NT_STATUS_OK,
415 .expected_result = WERR_INVALID_PARAM
417 .version = WITNESS_V1,
418 .net_name = NULL,
419 .ip_address = NULL,
420 .client_computer_name = lpcfg_netbios_name(tctx->lp_ctx),
421 .expected_status = NT_STATUS_OK,
422 .expected_result = WERR_REVISION_MISMATCH
424 .version = WITNESS_V2,
425 .net_name = dcerpc_server_name(p),
426 .ip_address = NULL,
427 .client_computer_name = lpcfg_netbios_name(tctx->lp_ctx),
428 .expected_status = NT_STATUS_OK,
429 .expected_result = WERR_INVALID_PARAM
434 for (i=0; i < ARRAY_SIZE(tests); i++) {
436 ZERO_STRUCT(r);
438 r.out.context_handle = &context_handle;
440 r.in.version = tests[i].version;
441 r.in.net_name = tests[i].net_name;
442 r.in.ip_address = tests[i].ip_address;
443 r.in.client_computer_name = tests[i].client_computer_name;
445 torture_assert_ntstatus_equal(tctx,
446 dcerpc_witness_RegisterEx_r(b, tctx, &r),
447 tests[i].expected_status,
448 "RegisterEx failed");
450 torture_assert_werr_equal(tctx,
451 r.out.result,
452 tests[i].expected_result,
453 "RegisterEx failed");
455 if (W_ERROR_IS_OK(r.out.result)) {
457 /* we have a handle, make sure to unregister it */
458 torture_assert(tctx,
459 test_witness_UnRegister_with_handle(tctx, p, r.out.context_handle),
460 "Failed to unregister");
464 init_witness_test_state(tctx, p, state);
466 for (i=0; state->list && i < state->list->num_interfaces; i++) {
468 const char *ip_address;
469 struct witness_interfaceInfo interface = state->list->interfaces[i];
471 if (!check_valid_interface(tctx, &interface)) {
472 continue;
475 torture_assert(tctx,
476 get_ip_address_from_interface(tctx, &interface, &ip_address),
477 "failed to get ip_address from interface");
479 r.in.version = WITNESS_V2;
480 r.in.net_name = state->net_name;
481 r.in.ip_address = ip_address;
484 * a valid request with an invalid sharename fails with
485 * WERR_INVALID_STATE
487 r.in.share_name = "any_invalid_share_name";
489 torture_assert_ntstatus_ok(tctx,
490 dcerpc_witness_RegisterEx_r(b, tctx, &r),
491 "RegisterEx failed");
493 torture_assert_werr_equal(tctx,
494 r.out.result,
495 WERR_INVALID_STATE,
496 "RegisterEx failed");
498 r.in.share_name = NULL;
500 torture_assert_ntstatus_ok(tctx,
501 dcerpc_witness_RegisterEx_r(b, tctx, &r),
502 "RegisterEx failed");
504 torture_assert_werr_ok(tctx,
505 r.out.result,
506 "RegisterEx failed");
508 torture_assert(tctx,
509 test_witness_UnRegister_with_handle(tctx, p, r.out.context_handle),
510 "Failed to unregister");
513 return true;
516 static bool setup_clusapi_connection(struct torture_context *tctx,
517 struct torture_test_witness_state *s)
519 NTSTATUS status;
521 if (s->clusapi.p) {
522 return true;
525 status = torture_rpc_connection_transport(tctx, &s->clusapi.p, &ndr_table_clusapi, NCACN_IP_TCP, 0);
526 if (!NT_STATUS_IS_OK(status)) {
527 torture_comment(tctx, "clusapi interface not available\n");
528 return true;
531 return true;
534 #if 0
535 static bool cluster_get_nodes(struct torture_context *tctx,
536 struct torture_test_witness_state *s)
538 struct clusapi_CreateEnum r;
539 struct ENUM_LIST *ReturnEnum;
540 WERROR rpc_status;
541 struct dcerpc_binding_handle *b;
543 torture_assert(tctx,
544 setup_clusapi_connection(tctx, s),
545 "failed to setup clusapi connection");
547 b = s->clusapi.p->binding_handle;
549 r.in.dwType = CLUSTER_ENUM_NODE;
550 r.out.ReturnEnum = &ReturnEnum;
551 r.out.rpc_status = &rpc_status;
553 torture_assert_ntstatus_ok(tctx,
554 dcerpc_clusapi_CreateEnum_r(b, tctx, &r),
555 "failed to enumerate nodes");
557 return true;
559 #endif
561 static bool test_GetResourceState_int(struct torture_context *tctx,
562 struct dcerpc_pipe *p,
563 struct policy_handle *hResource,
564 enum clusapi_ClusterResourceState *State)
566 struct dcerpc_binding_handle *b = p->binding_handle;
567 struct clusapi_GetResourceState r;
568 const char *NodeName;
569 const char *GroupName;
570 WERROR rpc_status;
572 r.in.hResource = *hResource;
573 r.out.State = State;
574 r.out.NodeName = &NodeName;
575 r.out.GroupName = &GroupName;
576 r.out.rpc_status = &rpc_status;
578 torture_assert_ntstatus_ok(tctx,
579 dcerpc_clusapi_GetResourceState_r(b, tctx, &r),
580 "GetResourceState failed");
581 torture_assert_werr_ok(tctx,
582 r.out.result,
583 "GetResourceState failed");
585 return true;
588 static bool toggle_cluster_resource_state(struct torture_context *tctx,
589 struct dcerpc_pipe *p,
590 const char *resource_name)
592 struct policy_handle hResource;
593 enum clusapi_ClusterResourceState State;
595 torture_assert(tctx,
596 test_OpenResource_int(tctx, p, resource_name, &hResource),
597 "failed to open resource");
598 torture_assert(tctx,
599 test_GetResourceState_int(tctx, p, &hResource, &State),
600 "failed to query resource state");
602 switch (State) {
603 case ClusterResourceOffline:
604 if (!test_OnlineResource_int(tctx, p, &hResource)) {
605 test_CloseResource_int(tctx, p, &hResource);
606 torture_warning(tctx, "failed to set resource online");
607 return false;
609 break;
610 case ClusterResourceOnline:
611 if (!test_OfflineResource_int(tctx, p, &hResource)) {
612 test_CloseResource_int(tctx, p, &hResource);
613 torture_warning(tctx, "failed to set resource offline");
614 return false;
616 break;
618 default:
619 break;
622 test_CloseResource_int(tctx, p, &hResource);
624 return true;
627 static bool test_witness_AsyncNotify(struct torture_context *tctx,
628 struct dcerpc_pipe *p,
629 void *data)
631 struct dcerpc_binding_handle *b = p->binding_handle;
632 struct witness_AsyncNotify r;
633 struct witness_notifyResponse *response;
634 struct torture_test_witness_state *state =
635 (struct torture_test_witness_state *)data;
636 int i;
638 init_witness_test_state(tctx, p, state);
640 setup_clusapi_connection(tctx, state);
642 for (i=0; state->list && i < state->list->num_interfaces; i++) {
644 const char *ip_address;
645 struct witness_interfaceInfo interface = state->list->interfaces[i];
646 struct witness_Register reg;
647 struct tevent_req *req;
649 if (!check_valid_interface(tctx, &interface)) {
650 continue;
653 torture_assert(tctx,
654 get_ip_address_from_interface(tctx, &interface, &ip_address),
655 "failed to get ip_address from interface");
657 reg.in.version = WITNESS_V1;
658 reg.in.net_name = state->net_name;
659 reg.in.ip_address = ip_address;
660 reg.in.client_computer_name = lpcfg_netbios_name(tctx->lp_ctx);
661 reg.out.context_handle = &state->context_handle;
663 torture_assert_ntstatus_ok(tctx,
664 dcerpc_witness_Register_r(b, tctx, &reg),
665 "Register failed");
667 torture_assert_werr_ok(tctx,
668 reg.out.result,
669 "Register failed");
671 r.in.context_handle = state->context_handle;
672 r.out.response = &response;
674 req = dcerpc_witness_AsyncNotify_r_send(tctx, tctx->ev, b, &r);
675 torture_assert(tctx, req, "failed to create request");
677 torture_assert(tctx,
678 toggle_cluster_resource_state(tctx, state->clusapi.p, state->net_name),
679 "failed to toggle cluster resource state");
681 torture_assert(tctx,
682 tevent_req_poll(req, tctx->ev),
683 "failed to call event loop");
685 torture_assert_ntstatus_ok(tctx,
686 dcerpc_witness_AsyncNotify_r_recv(req, tctx),
687 "failed to receive reply");
689 torture_assert(tctx,
690 test_witness_UnRegister_with_handle(tctx, p, &state->context_handle),
691 "Failed to unregister");
693 ZERO_STRUCT(state->context_handle);
696 return true;
699 static bool test_do_witness_RegisterEx(struct torture_context *tctx,
700 struct dcerpc_binding_handle *b,
701 uint32_t version,
702 const char *net_name,
703 const char *share_name,
704 const char *ip_address,
705 const char *client_computer_name,
706 uint32_t flags,
707 uint32_t timeout,
708 struct policy_handle *context_handle)
710 struct witness_RegisterEx r;
712 r.in.version = version;
713 r.in.net_name = net_name;
714 r.in.share_name = NULL;
715 r.in.ip_address = ip_address;
716 r.in.client_computer_name = client_computer_name;
717 r.in.flags = flags;
718 r.in.timeout = timeout;
719 r.out.context_handle = context_handle;
721 torture_assert_ntstatus_ok(tctx,
722 dcerpc_witness_RegisterEx_r(b, tctx, &r),
723 "RegisterEx failed");
725 torture_assert_werr_ok(tctx,
726 r.out.result,
727 "RegisterEx failed");
729 return true;
732 static void torture_subunit_report_time(struct torture_context *tctx)
734 struct timespec tp;
735 struct tm *tmp;
736 char timestr[200];
738 if (clock_gettime(CLOCK_REALTIME, &tp) != 0) {
739 torture_comment(tctx, "failed to call clock_gettime");
740 return;
743 tmp = localtime(&tp.tv_sec);
744 if (!tmp) {
745 torture_comment(tctx, "failed to call localtime");
746 return;
749 if (strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp) <= 0) {
750 torture_comment(tctx, "failed to call strftime");
751 return;
754 torture_comment(tctx, "time: %s.%06ld\n", timestr, tp.tv_nsec / 1000);
757 static bool test_witness_AsyncNotify_timeouts(struct torture_context *tctx,
758 struct dcerpc_pipe *p,
759 void *data)
761 struct dcerpc_binding_handle *b = p->binding_handle;
762 struct witness_AsyncNotify r;
763 struct witness_notifyResponse *response;
764 struct torture_test_witness_state *state =
765 (struct torture_test_witness_state *)data;
766 int i;
768 init_witness_test_state(tctx, p, state);
770 setup_clusapi_connection(tctx, state);
772 for (i=0; state->list && i < state->list->num_interfaces; i++) {
774 const char *ip_address;
775 struct witness_interfaceInfo interface = state->list->interfaces[i];
776 uint32_t timeouts[] = {
777 0, 1, 10, 100, 120
779 int t;
780 uint32_t old_timeout;
782 if (!check_valid_interface(tctx, &interface)) {
783 continue;
786 torture_assert(tctx,
787 get_ip_address_from_interface(tctx, &interface, &ip_address),
788 "failed to get ip_address from interface");
790 for (t=0; t < ARRAY_SIZE(timeouts); t++) {
792 torture_comment(tctx, "Testing Async Notify with timeout of %d milliseconds", timeouts[t]);
794 torture_assert(tctx,
795 test_do_witness_RegisterEx(tctx, b,
796 WITNESS_V2,
797 state->net_name,
798 NULL,
799 ip_address,
800 lpcfg_netbios_name(tctx->lp_ctx),
802 timeouts[t],
803 &state->context_handle),
804 "failed to RegisterEx");
806 r.in.context_handle = state->context_handle;
807 r.out.response = &response;
809 old_timeout = dcerpc_binding_handle_set_timeout(b, UINT_MAX);
811 torture_subunit_report_time(tctx);
813 torture_assert_ntstatus_ok(tctx,
814 dcerpc_witness_AsyncNotify_r(b, tctx, &r),
815 "AsyncNotify failed");
816 torture_assert_werr_equal(tctx,
817 r.out.result,
818 WERR_TIMEOUT,
819 "AsyncNotify failed");
821 torture_subunit_report_time(tctx);
823 dcerpc_binding_handle_set_timeout(b, old_timeout);
825 torture_assert(tctx,
826 test_witness_UnRegister_with_handle(tctx, p, &state->context_handle),
827 "Failed to unregister");
829 ZERO_STRUCT(state->context_handle);
833 return true;
836 struct torture_suite *torture_rpc_witness(TALLOC_CTX *mem_ctx)
838 struct torture_rpc_tcase *tcase;
839 struct torture_suite *suite = torture_suite_create(mem_ctx, "witness");
840 struct torture_test_witness_state *state;
842 tcase = torture_suite_add_rpc_iface_tcase(suite, "witness",
843 &ndr_table_witness);
845 state = talloc_zero(tcase, struct torture_test_witness_state);
847 torture_rpc_tcase_add_test_ex(tcase, "GetInterfaceList",
848 test_witness_GetInterfaceList, state);
849 torture_rpc_tcase_add_test_ex(tcase, "Register",
850 test_witness_Register, state);
851 torture_rpc_tcase_add_test_ex(tcase, "UnRegister",
852 test_witness_UnRegister, state);
853 torture_rpc_tcase_add_test_ex(tcase, "RegisterEx",
854 test_witness_RegisterEx, state);
855 torture_rpc_tcase_add_test_ex(tcase, "AsyncNotify",
856 test_witness_AsyncNotify, state);
857 torture_rpc_tcase_add_test_ex(tcase, "AsyncNotify_timeouts",
858 test_witness_AsyncNotify_timeouts, state);
860 return suite;