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.
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 "param/param.h"
28 struct torture_test_witness_state
{
30 const char *share_name
;
31 struct witness_interfaceList
*list
;
32 struct policy_handle context_handle
;
35 static bool test_witness_GetInterfaceList(struct torture_context
*tctx
,
36 struct dcerpc_pipe
*p
,
39 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
40 struct witness_GetInterfaceList r
;
41 struct witness_interfaceList
*l
;
42 struct torture_test_witness_state
*state
=
43 (struct torture_test_witness_state
*)data
;
45 r
.out
.interface_list
= &l
;
47 torture_assert_ntstatus_ok(tctx
,
48 dcerpc_witness_GetInterfaceList_r(b
, tctx
, &r
),
49 "GetInterfaceList failed");
51 torture_assert_werr_ok(tctx
,
53 "GetInterfaceList failed");
60 static bool find_sofs_share(struct torture_context
*tctx
,
61 const char **sofs_sharename
)
63 struct dcerpc_pipe
*p
;
64 struct dcerpc_binding_handle
*b
;
65 struct srvsvc_NetShareEnumAll r
;
66 struct srvsvc_NetShareInfoCtr info_ctr
;
67 struct srvsvc_NetShareCtr1 ctr1
;
68 uint32_t resume_handle
= 0;
69 uint32_t totalentries
= 0;
72 torture_assert_ntstatus_ok(tctx
,
73 torture_rpc_connection_transport(tctx
, &p
, &ndr_table_srvsvc
,
75 "failed to setup srvsvc connection");
77 b
= p
->binding_handle
;
82 info_ctr
.ctr
.ctr1
= &ctr1
;
84 r
.in
.server_unc
= dcerpc_server_name(p
);
86 r
.in
.info_ctr
= &info_ctr
;
87 r
.in
.resume_handle
= &resume_handle
;
88 r
.out
.totalentries
= &totalentries
;
89 r
.out
.info_ctr
= &info_ctr
;
90 r
.out
.resume_handle
= &resume_handle
;
92 torture_assert_ntstatus_ok(tctx
,
93 dcerpc_srvsvc_NetShareEnumAll_r(b
, tctx
, &r
),
94 "failed to call srvsvc_NetShareEnumAll");
96 torture_assert_werr_ok(tctx
,
98 "failed to call srvsvc_NetShareEnumAll");
100 for (i
=0; i
< r
.out
.info_ctr
->ctr
.ctr1
->count
; i
++) {
102 if (r
.out
.info_ctr
->ctr
.ctr1
->array
[i
].type
== STYPE_CLUSTER_SOFS
) {
103 *sofs_sharename
= talloc_strdup(tctx
, r
.out
.info_ctr
->ctr
.ctr1
->array
[i
].name
);
104 if (*sofs_sharename
== NULL
) {
107 torture_comment(tctx
, "using SOFS share: %s\n", *sofs_sharename
);
110 if (r
.out
.info_ctr
->ctr
.ctr1
->array
[i
].type
== STYPE_DISKTREE
) {
111 *sofs_sharename
= talloc_strdup(tctx
, r
.out
.info_ctr
->ctr
.ctr1
->array
[i
].name
);
112 if (*sofs_sharename
== NULL
) {
115 torture_comment(tctx
, "assuming SOFS share: %s\n", *sofs_sharename
);
123 static bool init_witness_test_state(struct torture_context
*tctx
,
124 struct dcerpc_pipe
*p
,
125 struct torture_test_witness_state
*state
)
127 if (state
->net_name
== NULL
) {
128 state
->net_name
= lpcfg_parm_string(tctx
->lp_ctx
, NULL
, "torture", "net_name");
131 if (state
->list
== NULL
) {
133 test_witness_GetInterfaceList(tctx
, p
, state
),
134 "failed to retrieve GetInterfaceList");
137 if (state
->share_name
== NULL
) {
138 find_sofs_share(tctx
, &state
->share_name
);
144 static bool test_witness_UnRegister_with_handle(struct torture_context
*tctx
,
145 struct dcerpc_pipe
*p
,
146 struct policy_handle
*context_handle
)
148 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
149 struct witness_UnRegister r
;
151 r
.in
.context_handle
= *context_handle
;
153 torture_assert_ntstatus_ok(tctx
,
154 dcerpc_witness_UnRegister_r(b
, tctx
, &r
),
155 "UnRegister failed");
157 torture_assert_werr_ok(tctx
,
159 "UnRegister failed");
161 /* make sure we are not able/allowed to reuse context handles after they
162 * have been unregistered */
164 torture_assert_ntstatus_ok(tctx
,
165 dcerpc_witness_UnRegister_r(b
, tctx
, &r
),
166 "UnRegister failed");
168 torture_assert_werr_equal(tctx
,
171 "UnRegister failed");
176 static bool test_witness_UnRegister(struct torture_context
*tctx
,
177 struct dcerpc_pipe
*p
,
180 /* acquire handle and free afterwards */
184 static bool get_ip_address_from_interface(struct torture_context
*tctx
,
185 struct witness_interfaceInfo
*i
,
186 const char **ip_address
)
188 if (i
->flags
& WITNESS_INFO_IPv4_VALID
) {
189 *ip_address
= talloc_strdup(tctx
, i
->ipv4
);
190 torture_assert(tctx
, *ip_address
, "talloc_strdup failed");
194 if (i
->flags
& WITNESS_INFO_IPv6_VALID
) {
195 *ip_address
= talloc_strdup(tctx
, i
->ipv6
);
196 torture_assert(tctx
, *ip_address
, "talloc_strdup failed");
203 static bool check_valid_interface(struct torture_context
*tctx
,
204 struct witness_interfaceInfo
*i
)
206 /* continue looking for an interface that allows witness
208 if (!(i
->flags
& WITNESS_INFO_WITNESS_IF
)) {
212 /* witness should be available of course */
213 if (i
->state
!= WITNESS_STATE_AVAILABLE
) {
220 static bool test_witness_Register(struct torture_context
*tctx
,
221 struct dcerpc_pipe
*p
,
224 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
225 struct witness_Register r
;
226 struct policy_handle context_handle
;
227 struct torture_test_witness_state
*state
=
228 (struct torture_test_witness_state
*)data
;
232 enum witness_version version
;
233 const char *net_name
;
234 const char *ip_address
;
235 const char *client_computer_name
;
236 NTSTATUS expected_status
;
237 WERROR expected_result
;
241 .expected_status
= NT_STATUS_OK
,
242 .expected_result
= WERR_REVISION_MISMATCH
245 .expected_status
= NT_STATUS_OK
,
246 .expected_result
= WERR_REVISION_MISMATCH
249 .expected_status
= NT_STATUS_OK
,
250 .expected_result
= WERR_REVISION_MISMATCH
253 .expected_status
= NT_STATUS_OK
,
254 .expected_result
= WERR_REVISION_MISMATCH
256 .version
= WITNESS_V2
,
257 .expected_status
= NT_STATUS_OK
,
258 .expected_result
= WERR_REVISION_MISMATCH
260 .version
= WITNESS_V1
,
263 .client_computer_name
= "",
264 .expected_status
= NT_STATUS_OK
,
265 .expected_result
= WERR_INVALID_PARAM
267 .version
= WITNESS_V1
,
270 .client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
),
271 .expected_status
= NT_STATUS_OK
,
272 .expected_result
= WERR_INVALID_PARAM
274 .version
= WITNESS_V2
,
277 .client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
),
278 .expected_status
= NT_STATUS_OK
,
279 .expected_result
= WERR_REVISION_MISMATCH
281 .version
= WITNESS_V1
,
282 .net_name
= dcerpc_server_name(p
),
283 .ip_address
= NULL
, /* "99192.168.44.45" */
284 .client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
),
285 .expected_status
= NT_STATUS_OK
,
286 .expected_result
= WERR_INVALID_PARAM
291 for (i
=0; i
< ARRAY_SIZE(tests
); i
++) {
295 r
.out
.context_handle
= &context_handle
;
297 r
.in
.version
= tests
[i
].version
;
298 r
.in
.net_name
= tests
[i
].net_name
;
299 r
.in
.ip_address
= tests
[i
].ip_address
;
300 r
.in
.client_computer_name
= tests
[i
].client_computer_name
;
302 torture_assert_ntstatus_equal(tctx
,
303 dcerpc_witness_Register_r(b
, tctx
, &r
),
304 tests
[i
].expected_status
,
307 torture_assert_werr_equal(tctx
,
309 tests
[i
].expected_result
,
312 if (W_ERROR_IS_OK(r
.out
.result
)) {
314 /* we have a handle, make sure to unregister it */
316 test_witness_UnRegister_with_handle(tctx
, p
, r
.out
.context_handle
),
317 "Failed to unregister");
321 init_witness_test_state(tctx
, p
, state
);
323 for (i
=0; state
->list
&& i
< state
->list
->num_interfaces
; i
++) {
325 const char *ip_address
;
326 struct witness_interfaceInfo interface
= state
->list
->interfaces
[i
];
328 if (!check_valid_interface(tctx
, &interface
)) {
333 get_ip_address_from_interface(tctx
, &interface
, &ip_address
),
334 "failed to get ip_address from interface");
336 r
.in
.version
= WITNESS_V1
;
337 r
.in
.net_name
= state
->net_name
;
338 r
.in
.ip_address
= ip_address
;
340 torture_assert_ntstatus_ok(tctx
,
341 dcerpc_witness_Register_r(b
, tctx
, &r
),
344 torture_assert_werr_ok(tctx
,
349 test_witness_UnRegister_with_handle(tctx
, p
, r
.out
.context_handle
),
350 "Failed to unregister");
356 static bool test_witness_RegisterEx(struct torture_context
*tctx
,
357 struct dcerpc_pipe
*p
,
360 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
361 struct witness_RegisterEx r
;
362 struct policy_handle context_handle
;
363 struct torture_test_witness_state
*state
=
364 (struct torture_test_witness_state
*)data
;
368 enum witness_version version
;
369 const char *net_name
;
370 const char *ip_address
;
371 const char *client_computer_name
;
372 NTSTATUS expected_status
;
373 WERROR expected_result
;
377 .expected_status
= NT_STATUS_OK
,
378 .expected_result
= WERR_REVISION_MISMATCH
381 .expected_status
= NT_STATUS_OK
,
382 .expected_result
= WERR_REVISION_MISMATCH
385 .expected_status
= NT_STATUS_OK
,
386 .expected_result
= WERR_REVISION_MISMATCH
389 .expected_status
= NT_STATUS_OK
,
390 .expected_result
= WERR_REVISION_MISMATCH
392 .version
= WITNESS_V1
,
393 .expected_status
= NT_STATUS_OK
,
394 .expected_result
= WERR_REVISION_MISMATCH
396 .version
= WITNESS_V2
,
399 .client_computer_name
= "",
400 .expected_status
= NT_STATUS_OK
,
401 .expected_result
= WERR_INVALID_PARAM
403 .version
= WITNESS_V2
,
406 .client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
),
407 .expected_status
= NT_STATUS_OK
,
408 .expected_result
= WERR_INVALID_PARAM
410 .version
= WITNESS_V1
,
413 .client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
),
414 .expected_status
= NT_STATUS_OK
,
415 .expected_result
= WERR_REVISION_MISMATCH
417 .version
= WITNESS_V2
,
418 .net_name
= dcerpc_server_name(p
),
419 .ip_address
= NULL
, /* "99192.168.44.45" */
420 .client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
),
421 .expected_status
= NT_STATUS_OK
,
422 .expected_result
= WERR_INVALID_PARAM
427 for (i
=0; i
< ARRAY_SIZE(tests
); i
++) {
431 r
.out
.context_handle
= &context_handle
;
433 r
.in
.version
= tests
[i
].version
;
434 r
.in
.net_name
= tests
[i
].net_name
;
435 r
.in
.ip_address
= tests
[i
].ip_address
;
436 r
.in
.client_computer_name
= tests
[i
].client_computer_name
;
438 torture_assert_ntstatus_equal(tctx
,
439 dcerpc_witness_RegisterEx_r(b
, tctx
, &r
),
440 tests
[i
].expected_status
,
441 "RegisterEx failed");
443 torture_assert_werr_equal(tctx
,
445 tests
[i
].expected_result
,
446 "RegisterEx failed");
448 if (W_ERROR_IS_OK(r
.out
.result
)) {
450 /* we have a handle, make sure to unregister it */
452 test_witness_UnRegister_with_handle(tctx
, p
, r
.out
.context_handle
),
453 "Failed to unregister");
457 init_witness_test_state(tctx
, p
, state
);
459 for (i
=0; state
->list
&& i
< state
->list
->num_interfaces
; i
++) {
461 const char *ip_address
;
462 struct witness_interfaceInfo interface
= state
->list
->interfaces
[i
];
464 if (!check_valid_interface(tctx
, &interface
)) {
469 get_ip_address_from_interface(tctx
, &interface
, &ip_address
),
470 "failed to get ip_address from interface");
472 r
.in
.version
= WITNESS_V2
;
473 r
.in
.net_name
= state
->net_name
;
474 r
.in
.ip_address
= ip_address
;
477 * a valid request with an invalid sharename fails with
480 r
.in
.share_name
= "any_invalid_share_name";
482 torture_assert_ntstatus_ok(tctx
,
483 dcerpc_witness_RegisterEx_r(b
, tctx
, &r
),
484 "RegisterEx failed");
486 torture_assert_werr_equal(tctx
,
489 "RegisterEx failed");
491 r
.in
.share_name
= NULL
;
493 torture_assert_ntstatus_ok(tctx
,
494 dcerpc_witness_RegisterEx_r(b
, tctx
, &r
),
495 "RegisterEx failed");
497 torture_assert_werr_ok(tctx
,
499 "RegisterEx failed");
502 test_witness_UnRegister_with_handle(tctx
, p
, r
.out
.context_handle
),
503 "Failed to unregister");
509 /* for this test to run, we need to have some basic clusapi client support
510 * first, so that we can programmatically change something in the cluster and
511 * then receive async notifications - Guenther */
513 static bool test_witness_AsyncNotify(struct torture_context
*tctx
,
514 struct dcerpc_pipe
*p
,
517 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
518 struct witness_AsyncNotify r
;
519 struct witness_notifyResponse
*response
;
520 struct torture_test_witness_state
*state
=
521 (struct torture_test_witness_state
*)data
;
524 torture_skip(tctx
, "skipping witness_AsyncNotify test");
526 init_witness_test_state(tctx
, p
, state
);
528 for (i
=0; state
->list
&& i
< state
->list
->num_interfaces
; i
++) {
530 const char *ip_address
;
531 struct witness_interfaceInfo interface
= state
->list
->interfaces
[i
];
532 struct witness_Register reg
;
534 if (!check_valid_interface(tctx
, &interface
)) {
539 get_ip_address_from_interface(tctx
, &interface
, &ip_address
),
540 "failed to get ip_address from interface");
542 reg
.in
.version
= WITNESS_V1
;
543 reg
.in
.net_name
= state
->net_name
;
544 reg
.in
.ip_address
= ip_address
;
545 reg
.in
.client_computer_name
= lpcfg_netbios_name(tctx
->lp_ctx
);
546 reg
.out
.context_handle
= &state
->context_handle
;
548 torture_assert_ntstatus_ok(tctx
,
549 dcerpc_witness_Register_r(b
, tctx
, ®
),
552 torture_assert_werr_ok(tctx
,
556 r
.in
.context_handle
= state
->context_handle
;
557 r
.out
.response
= &response
;
559 torture_assert_ntstatus_ok(tctx
,
560 dcerpc_witness_AsyncNotify_r(b
, tctx
, &r
),
561 "AsyncNotify failed");
564 test_witness_UnRegister_with_handle(tctx
, p
, &state
->context_handle
),
565 "Failed to unregister");
567 ZERO_STRUCT(state
->context_handle
);
573 struct torture_suite
*torture_rpc_witness(TALLOC_CTX
*mem_ctx
)
575 struct torture_rpc_tcase
*tcase
;
576 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "witness");
577 struct torture_test_witness_state
*state
;
579 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "witness",
582 state
= talloc_zero(tcase
, struct torture_test_witness_state
);
584 torture_rpc_tcase_add_test_ex(tcase
, "GetInterfaceList",
585 test_witness_GetInterfaceList
, state
);
586 torture_rpc_tcase_add_test_ex(tcase
, "Register",
587 test_witness_Register
, state
);
588 torture_rpc_tcase_add_test_ex(tcase
, "UnRegister",
589 test_witness_UnRegister
, state
);
590 torture_rpc_tcase_add_test_ex(tcase
, "RegisterEx",
591 test_witness_RegisterEx
, state
);
592 torture_rpc_tcase_add_test_ex(tcase
, "AsyncNotify",
593 test_witness_AsyncNotify
, state
);