2 Unix SMB/CIFS implementation.
3 test suite for epmapper rpc operations
5 Copyright (C) Andrew Tridgell 2003
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 "librpc/gen_ndr/ndr_epmapper_c.h"
23 #include "librpc/ndr/ndr_table.h"
24 #include "librpc/rpc/dcerpc_proto.h"
25 #include "torture/rpc/torture_rpc.h"
26 #include "lib/util/util_net.h"
27 #include "librpc/rpc/rpc_common.h"
30 display any protocol tower
32 static void display_tower(struct torture_context
*tctx
, struct epm_tower
*twr
)
36 for (i
= 0; i
< twr
->num_floors
; i
++) {
39 epm_floor_string(tctx
, &twr
->floors
[i
]));
41 torture_comment(tctx
, "\n");
44 static bool test_Insert(struct torture_context
*tctx
,
45 struct dcerpc_binding_handle
*h
,
46 struct ndr_syntax_id object
,
47 const char *annotation
,
48 const struct dcerpc_binding
*b
)
54 r
.in
.entries
= talloc_array(tctx
, struct epm_entry_t
, 1);
56 if (torture_setting_bool(tctx
, "samba4", false)) {
57 torture_skip(tctx
, "Skip Insert test against Samba4");
61 ZERO_STRUCT(r
.in
.entries
[0].object
);
62 r
.in
.entries
[0].annotation
= annotation
;
64 r
.in
.entries
[0].tower
= talloc(tctx
, struct epm_twr_t
);
66 status
= dcerpc_binding_build_tower(tctx
,
68 &r
.in
.entries
[0].tower
->tower
);
70 torture_assert_ntstatus_ok(tctx
,
72 "Unable to build tower from binding struct");
76 status
= dcerpc_epm_Insert_r(h
, tctx
, &r
);
78 if (NT_STATUS_IS_ERR(status
)) {
80 "epm_Insert failed - %s\n",
85 if (r
.out
.result
!= EPMAPPER_STATUS_OK
) {
87 "epm_Insert failed - internal error: 0x%.4x\n",
95 static bool test_Delete(struct torture_context
*tctx
,
96 struct dcerpc_binding_handle
*h
,
97 const char *annotation
,
98 const struct dcerpc_binding
*b
)
104 r
.in
.entries
= talloc_array(tctx
, struct epm_entry_t
, 1);
106 ZERO_STRUCT(r
.in
.entries
[0].object
);
107 r
.in
.entries
[0].annotation
= annotation
;
109 r
.in
.entries
[0].tower
= talloc(tctx
, struct epm_twr_t
);
111 status
= dcerpc_binding_build_tower(tctx
,
113 &r
.in
.entries
[0].tower
->tower
);
115 torture_assert_ntstatus_ok(tctx
,
117 "Unable to build tower from binding struct");
120 status
= dcerpc_epm_Delete_r(h
, tctx
, &r
);
121 if (NT_STATUS_IS_ERR(status
)) {
122 torture_comment(tctx
,
123 "epm_Delete failed - %s\n",
128 if (r
.out
.result
!= EPMAPPER_STATUS_OK
) {
129 torture_comment(tctx
,
130 "epm_Delete failed - internal error: 0x%.4x\n",
138 static bool test_Map_tcpip(struct torture_context
*tctx
,
139 struct dcerpc_binding_handle
*h
,
140 struct ndr_syntax_id map_syntax
)
144 struct policy_handle entry_handle
;
145 struct ndr_syntax_id syntax
;
146 struct dcerpc_binding
*map_binding
;
147 struct epm_twr_t map_tower
;
148 struct epm_twr_p_t towers
[20];
159 torture_comment(tctx
, "Testing epm_Map\n");
162 ZERO_STRUCT(entry_handle
);
165 r
.in
.map_tower
= &map_tower
;
166 r
.in
.entry_handle
= &entry_handle
;
167 r
.out
.entry_handle
= &entry_handle
;
168 r
.in
.max_towers
= 10;
169 r
.out
.towers
= towers
;
170 r
.out
.num_towers
= &num_towers
;
172 /* Create map tower */
173 status
= dcerpc_parse_binding(tctx
, "ncacn_ip_tcp:[135]", &map_binding
);
174 torture_assert_ntstatus_ok(tctx
, status
,
175 "epm_Map_tcpip failed: can't create map_binding");
177 status
= dcerpc_binding_set_abstract_syntax(map_binding
, &map_syntax
);
178 torture_assert_ntstatus_ok(tctx
, status
,
179 "epm_Map_tcpip failed: set map_syntax");
181 status
= dcerpc_binding_build_tower(tctx
, map_binding
,
183 torture_assert_ntstatus_ok(tctx
, status
,
184 "epm_Map_tcpip failed: can't create map_tower");
186 torture_comment(tctx
,
187 "epm_Map request for '%s':\n",
188 ndr_interface_name(&map_syntax
.uuid
, map_syntax
.if_version
));
189 display_tower(tctx
, &r
.in
.map_tower
->tower
);
191 status
= dcerpc_epm_Map_r(h
, tctx
, &r
);
193 torture_assert_ntstatus_ok(tctx
, status
, "epm_Map_simple failed");
194 torture_assert(tctx
, r
.out
.result
== EPMAPPER_STATUS_OK
,
195 "epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK");
197 /* Check the result */
198 t
= r
.out
.towers
[0].twr
->tower
;
200 /* Check if we got the correct RPC interface identifier */
201 dcerpc_floor_get_uuid_full(&t
.floors
[0], &syntax
);
202 torture_assert(tctx
, ndr_syntax_id_equal(&syntax
, &map_syntax
),
203 "epm_Map_tcpip failed: Interface identifier mismatch");
205 torture_comment(tctx
,
206 "epm_Map_tcpip response for '%s':\n",
207 ndr_interface_name(&syntax
.uuid
, syntax
.if_version
));
209 dcerpc_floor_get_uuid_full(&t
.floors
[1], &syntax
);
210 torture_assert(tctx
, ndr_syntax_id_equal(&syntax
, &ndr_transfer_syntax_ndr
),
211 "epm_Map_tcpip failed: floor 2 is not NDR encoded");
213 torture_assert(tctx
, t
.floors
[2].lhs
.protocol
== EPM_PROTOCOL_NCACN
,
214 "epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP");
216 tmp
= dcerpc_floor_get_rhs_data(tctx
, &t
.floors
[3]);
217 p
= strtol(tmp
, &ptr
, 10);
219 torture_assert(tctx
, port
> 1024 && port
< 65535, "epm_Map_tcpip failed");
221 ip
= dcerpc_floor_get_rhs_data(tctx
, &t
.floors
[4]);
222 torture_assert(tctx
, is_ipaddress(ip
), "epm_Map_tcpip failed");
224 for (i
= 0; i
< *r
.out
.num_towers
; i
++) {
225 if (r
.out
.towers
[i
].twr
) {
226 display_tower(tctx
, &t
);
233 static bool test_Map_full(struct torture_context
*tctx
,
234 struct dcerpc_pipe
*p
)
236 const struct ndr_syntax_id obj
= {
237 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
240 struct dcerpc_binding_handle
*h
= p
->binding_handle
;
241 const char *annotation
= "SMBTORTURE";
242 struct dcerpc_binding
*b
;
246 status
= dcerpc_parse_binding(tctx
, "ncacn_ip_tcp:216.83.154.106[41768]", &b
);
247 torture_assert_ntstatus_ok(tctx
,
249 "Unable to generate dcerpc_binding struct");
250 status
= dcerpc_binding_set_abstract_syntax(b
, &obj
);
251 torture_assert_ntstatus_ok(tctx
, status
, "dcerpc_binding_set_abstract_syntax");
253 ok
= test_Insert(tctx
, h
, obj
, annotation
, b
);
254 torture_assert(tctx
, ok
, "test_Insert failed");
256 ok
= test_Map_tcpip(tctx
, h
, obj
);
257 torture_assert(tctx
, ok
, "test_Map_tcpip failed");
259 ok
= test_Delete(tctx
, h
, annotation
, b
);
260 torture_assert(tctx
, ok
, "test_Delete failed");
265 static bool test_Map_display(struct dcerpc_binding_handle
*b
,
266 struct torture_context
*tctx
,
267 struct epm_entry_t
*entry
)
271 struct epm_twr_t
*twr
= entry
->tower
;
273 struct GUID uuid
= entry
->object
;
274 struct policy_handle handle
;
275 struct ndr_syntax_id syntax
;
282 r
.in
.map_tower
= twr
;
283 r
.in
.entry_handle
= &handle
;
284 r
.out
.entry_handle
= &handle
;
285 r
.in
.max_towers
= 10;
286 r
.out
.num_towers
= &num_towers
;
288 dcerpc_floor_get_uuid_full(&twr
->tower
.floors
[0], &syntax
);
290 torture_comment(tctx
,
291 "epm_Map results for '%s':\n",
292 ndr_interface_name(&syntax
.uuid
, syntax
.if_version
));
294 status
= dcerpc_epm_Map_r(b
, tctx
, &r
);
295 if (NT_STATUS_IS_OK(status
) && r
.out
.result
== 0) {
296 for (i
=0;i
<*r
.out
.num_towers
;i
++) {
297 if (r
.out
.towers
[i
].twr
) {
298 display_tower(tctx
, &r
.out
.towers
[i
].twr
->tower
);
303 /* RPC protocol identifier */
304 twr
->tower
.floors
[2].lhs
.protocol
= EPM_PROTOCOL_NCACN
;
305 twr
->tower
.floors
[2].lhs
.lhs_data
= data_blob(NULL
, 0);
306 twr
->tower
.floors
[2].rhs
.ncacn
.minor_version
= 0;
309 twr
->tower
.floors
[3].lhs
.protocol
= EPM_PROTOCOL_TCP
;
310 twr
->tower
.floors
[3].lhs
.lhs_data
= data_blob(NULL
, 0);
311 twr
->tower
.floors
[3].rhs
.tcp
.port
= 0;
314 twr
->tower
.floors
[4].lhs
.protocol
= EPM_PROTOCOL_IP
;
315 twr
->tower
.floors
[4].lhs
.lhs_data
= data_blob(NULL
, 0);
316 twr
->tower
.floors
[4].rhs
.ip
.ipaddr
= "0.0.0.0";
318 status
= dcerpc_epm_Map_r(b
, tctx
, &r
);
319 if (NT_STATUS_IS_OK(status
) && r
.out
.result
== 0) {
320 for (i
=0;i
<*r
.out
.num_towers
;i
++) {
321 if (r
.out
.towers
[i
].twr
) {
322 display_tower(tctx
, &r
.out
.towers
[i
].twr
->tower
);
327 twr
->tower
.floors
[3].lhs
.protocol
= EPM_PROTOCOL_HTTP
;
328 twr
->tower
.floors
[3].lhs
.lhs_data
= data_blob(NULL
, 0);
329 twr
->tower
.floors
[3].rhs
.http
.port
= 0;
331 status
= dcerpc_epm_Map_r(b
, tctx
, &r
);
332 if (NT_STATUS_IS_OK(status
) && r
.out
.result
== 0) {
333 for (i
=0;i
<*r
.out
.num_towers
;i
++) {
334 if (r
.out
.towers
[i
].twr
) {
335 display_tower(tctx
, &r
.out
.towers
[i
].twr
->tower
);
340 twr
->tower
.floors
[3].lhs
.protocol
= EPM_PROTOCOL_UDP
;
341 twr
->tower
.floors
[3].lhs
.lhs_data
= data_blob(NULL
, 0);
342 twr
->tower
.floors
[3].rhs
.udp
.port
= 0;
344 status
= dcerpc_epm_Map_r(b
, tctx
, &r
);
345 if (NT_STATUS_IS_OK(status
) && r
.out
.result
== 0) {
346 for (i
=0;i
<*r
.out
.num_towers
;i
++) {
347 if (r
.out
.towers
[i
].twr
) {
348 display_tower(tctx
, &r
.out
.towers
[i
].twr
->tower
);
353 twr
->tower
.floors
[3].lhs
.protocol
= EPM_PROTOCOL_SMB
;
354 twr
->tower
.floors
[3].lhs
.lhs_data
= data_blob(NULL
, 0);
355 twr
->tower
.floors
[3].rhs
.smb
.unc
= "";
357 twr
->tower
.floors
[4].lhs
.protocol
= EPM_PROTOCOL_NETBIOS
;
358 twr
->tower
.floors
[4].lhs
.lhs_data
= data_blob(NULL
, 0);
359 twr
->tower
.floors
[4].rhs
.netbios
.name
= "";
361 status
= dcerpc_epm_Map_r(b
, tctx
, &r
);
362 if (NT_STATUS_IS_OK(status
) && r
.out
.result
== 0) {
363 for (i
= 0; i
< *r
.out
.num_towers
; i
++) {
364 if (r
.out
.towers
[i
].twr
) {
365 display_tower(tctx
, &r
.out
.towers
[i
].twr
->tower
);
370 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
375 static bool test_Map_simple(struct torture_context
*tctx
,
376 struct dcerpc_pipe
*p
)
380 struct policy_handle entry_handle
;
381 uint32_t num_ents
= 0;
382 struct dcerpc_binding_handle
*h
= p
->binding_handle
;
384 ZERO_STRUCT(entry_handle
);
386 torture_comment(tctx
, "Testing epm_Map\n");
388 /* get all elements */
389 r
.in
.inquiry_type
= RPC_C_EP_ALL_ELTS
;
391 r
.in
.interface_id
= NULL
;
392 r
.in
.vers_option
= RPC_C_VERS_ALL
;
394 r
.in
.entry_handle
= &entry_handle
;
397 r
.out
.entry_handle
= &entry_handle
;
398 r
.out
.num_ents
= &num_ents
;
403 status
= dcerpc_epm_Lookup_r(h
, tctx
, &r
);
404 if (!NT_STATUS_IS_OK(status
) ||
405 r
.out
.result
!= EPMAPPER_STATUS_OK
) {
409 for (i
= 0; i
< *r
.out
.num_ents
; i
++) {
410 if (r
.out
.entries
[i
].tower
->tower
.num_floors
== 5) {
411 test_Map_display(h
, tctx
, &r
.out
.entries
[i
]);
414 } while (NT_STATUS_IS_OK(status
) &&
415 r
.out
.result
== EPMAPPER_STATUS_OK
&&
416 *r
.out
.num_ents
== r
.in
.max_ents
&&
417 !ndr_policy_handle_empty(&entry_handle
));
419 torture_assert_ntstatus_ok(tctx
, status
, "epm_Map_simple failed");
422 ndr_policy_handle_empty(&entry_handle
),
423 "epm_Map_simple failed - The policy handle should be empty.");
428 static bool test_LookupHandleFree(struct torture_context
*tctx
,
429 struct dcerpc_binding_handle
*h
,
430 struct policy_handle
*entry_handle
) {
432 struct epm_LookupHandleFree r
;
434 if (ndr_policy_handle_empty(entry_handle
)) {
435 torture_comment(tctx
,
436 "epm_LookupHandleFree failed - empty policy_handle\n");
440 r
.in
.entry_handle
= entry_handle
;
441 r
.out
.entry_handle
= entry_handle
;
443 status
= dcerpc_epm_LookupHandleFree_r(h
, tctx
, &r
);
444 if (NT_STATUS_IS_ERR(status
)) {
445 torture_comment(tctx
,
446 "epm_LookupHandleFree failed - %s\n",
451 if (r
.out
.result
!= EPMAPPER_STATUS_OK
) {
452 torture_comment(tctx
,
453 "epm_LookupHandleFree failed - internal error: "
462 static bool test_Lookup_simple(struct torture_context
*tctx
,
463 struct dcerpc_pipe
*p
)
467 struct policy_handle entry_handle
;
468 uint32_t num_ents
= 0;
469 struct dcerpc_binding_handle
*h
= p
->binding_handle
;
471 ZERO_STRUCT(entry_handle
);
473 torture_comment(tctx
, "Testing epm_Lookup\n");
475 /* get all elements */
476 r
.in
.inquiry_type
= RPC_C_EP_ALL_ELTS
;
478 r
.in
.interface_id
= NULL
;
479 r
.in
.vers_option
= RPC_C_VERS_ALL
;
481 r
.in
.entry_handle
= &entry_handle
;
484 r
.out
.entry_handle
= &entry_handle
;
485 r
.out
.num_ents
= &num_ents
;
490 status
= dcerpc_epm_Lookup_r(h
, tctx
, &r
);
491 if (!NT_STATUS_IS_OK(status
) ||
492 r
.out
.result
!= EPMAPPER_STATUS_OK
) {
496 torture_comment(tctx
,
497 "epm_Lookup returned %d events, entry_handle: %s\n",
499 GUID_string(tctx
, &entry_handle
.uuid
));
501 for (i
= 0; i
< *r
.out
.num_ents
; i
++) {
502 torture_comment(tctx
,
503 "\n Found '%s' Object[%s]\n",
504 r
.out
.entries
[i
].annotation
,
505 GUID_string(tctx
, &r
.out
.entries
[i
].object
));
507 display_tower(tctx
, &r
.out
.entries
[i
].tower
->tower
);
509 } while (NT_STATUS_IS_OK(status
) &&
510 r
.out
.result
== EPMAPPER_STATUS_OK
&&
511 *r
.out
.num_ents
== r
.in
.max_ents
&&
512 !ndr_policy_handle_empty(&entry_handle
));
514 torture_assert_ntstatus_ok(tctx
, status
, "epm_Lookup failed");
515 torture_assert(tctx
, r
.out
.result
== EPMAPPER_STATUS_NO_MORE_ENTRIES
, "epm_Lookup failed");
518 ndr_policy_handle_empty(&entry_handle
),
519 "epm_Lookup failed - The policy handle should be empty.");
525 * This test starts a epm_Lookup request, but doesn't finish the
526 * call terminates the search. So it will call epm_LookupHandleFree.
528 static bool test_Lookup_terminate_search(struct torture_context
*tctx
,
529 struct dcerpc_pipe
*p
)
534 struct policy_handle entry_handle
;
535 uint32_t i
, num_ents
= 0;
536 struct dcerpc_binding_handle
*h
= p
->binding_handle
;
538 ZERO_STRUCT(entry_handle
);
540 torture_comment(tctx
, "Testing epm_Lookup and epm_LookupHandleFree\n");
542 /* get all elements */
543 r
.in
.inquiry_type
= RPC_C_EP_ALL_ELTS
;
545 r
.in
.interface_id
= NULL
;
546 r
.in
.vers_option
= RPC_C_VERS_ALL
;
548 r
.in
.entry_handle
= &entry_handle
;
551 r
.out
.entry_handle
= &entry_handle
;
552 r
.out
.num_ents
= &num_ents
;
554 status
= dcerpc_epm_Lookup_r(h
, tctx
, &r
);
556 torture_assert_ntstatus_ok(tctx
, status
, "epm_Lookup failed");
557 torture_assert(tctx
, r
.out
.result
== EPMAPPER_STATUS_OK
, "epm_Lookup failed");
559 torture_comment(tctx
,
560 "epm_Lookup returned %d events, entry_handle: %s\n",
562 GUID_string(tctx
, &entry_handle
.uuid
));
564 for (i
= 0; i
< *r
.out
.num_ents
; i
++) {
565 torture_comment(tctx
,
567 r
.out
.entries
[i
].annotation
);
570 ok
= test_LookupHandleFree(tctx
,
580 static bool test_Insert_noreplace(struct torture_context
*tctx
,
581 struct dcerpc_pipe
*p
)
586 struct dcerpc_binding
*b
;
587 struct dcerpc_binding_handle
*h
= p
->binding_handle
;
589 torture_comment(tctx
, "Testing epm_Insert(noreplace) and epm_Delete\n");
591 if (torture_setting_bool(tctx
, "samba4", false)) {
592 torture_skip(tctx
, "Skip Insert test against Samba4");
596 r
.in
.entries
= talloc_array(tctx
, struct epm_entry_t
, 1);
598 ZERO_STRUCT(r
.in
.entries
[0].object
);
599 r
.in
.entries
[0].annotation
= "smbtorture endpoint";
601 status
= dcerpc_parse_binding(tctx
, "ncalrpc:[SMBTORTURE]", &b
);
602 torture_assert_ntstatus_ok(tctx
,
604 "Unable to generate dcerpc_binding struct");
606 r
.in
.entries
[0].tower
= talloc(tctx
, struct epm_twr_t
);
608 status
= dcerpc_binding_build_tower(tctx
,
610 &r
.in
.entries
[0].tower
->tower
);
611 torture_assert_ntstatus_ok(tctx
,
613 "Unable to build tower from binding struct");
616 status
= dcerpc_epm_Insert_r(h
, tctx
, &r
);
617 torture_assert_ntstatus_ok(tctx
, status
, "epm_Insert failed");
619 torture_assert(tctx
, r
.out
.result
== 0, "epm_Insert failed");
621 ok
= test_Delete(tctx
, h
, "smbtorture", b
);
631 * The MS-RPCE documentation states that this function isn't implemented and
632 * SHOULD NOT be called by a client.
634 static bool test_InqObject(struct torture_context
*tctx
, struct dcerpc_pipe
*p
)
637 struct epm_InqObject r
;
638 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
640 r
.in
.epm_object
= talloc(tctx
, struct GUID
);
641 *r
.in
.epm_object
= ndr_table_epmapper
.syntax_id
.uuid
;
643 status
= dcerpc_epm_InqObject_r(b
, tctx
, &r
);
644 torture_assert_ntstatus_ok(tctx
, status
, "InqObject failed");
650 struct torture_suite
*torture_rpc_epmapper(TALLOC_CTX
*mem_ctx
)
652 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "epmapper");
653 struct torture_rpc_tcase
*tcase
;
655 tcase
= torture_suite_add_rpc_iface_tcase(suite
,
657 &ndr_table_epmapper
);
659 /* This is a stack */
660 torture_rpc_tcase_add_test(tcase
,
663 torture_rpc_tcase_add_test(tcase
,
666 torture_rpc_tcase_add_test(tcase
,
669 torture_rpc_tcase_add_test(tcase
,
670 "Lookup_terminate_search",
671 test_Lookup_terminate_search
);
672 torture_rpc_tcase_add_test(tcase
,
674 test_Insert_noreplace
);
679 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */