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 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 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 map_binding.transport = NCACN_IP_TCP;
174 map_binding.object = map_syntax;
175 map_binding.host = "0.0.0.0";
176 map_binding.endpoint = "135";
178 status = dcerpc_binding_build_tower(tctx, &map_binding,
180 torture_assert_ntstatus_ok(tctx, status,
181 "epm_Map_tcpip failed: can't create map_tower");
183 torture_comment(tctx,
184 "epm_Map request for '%s':\n",
185 ndr_interface_name(&map_syntax.uuid, map_syntax.if_version));
186 display_tower(tctx, &r.in.map_tower->tower);
188 status = dcerpc_epm_Map_r(h, tctx, &r);
190 torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
191 torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK,
192 "epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK");
194 /* Check the result */
195 t = r.out.towers[0].twr->tower;
197 /* Check if we got the correct RPC interface identifier */
198 dcerpc_floor_get_lhs_data(&t.floors[0], &syntax);
199 torture_assert(tctx, ndr_syntax_id_equal(&syntax, &map_syntax),
200 "epm_Map_tcpip failed: Interface identifier mismatch");
202 torture_comment(tctx,
203 "epm_Map_tcpip response for '%s':\n",
204 ndr_interface_name(&syntax.uuid, syntax.if_version));
206 dcerpc_floor_get_lhs_data(&t.floors[1], &syntax);
207 torture_assert(tctx, ndr_syntax_id_equal(&syntax, &ndr_transfer_syntax_ndr),
208 "epm_Map_tcpip failed: floor 2 is not NDR encoded");
210 torture_assert(tctx, t.floors[2].lhs.protocol == EPM_PROTOCOL_NCACN,
211 "epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP");
213 tmp = dcerpc_floor_get_rhs_data(tctx, &t.floors[3]);
214 p = strtol(tmp, &ptr, 10);
216 torture_assert(tctx, port > 1024 && port < 65535, "epm_Map_tcpip failed");
218 ip = dcerpc_floor_get_rhs_data(tctx, &t.floors[4]);
219 torture_assert(tctx, is_ipaddress(ip), "epm_Map_tcpip failed");
221 for (i = 0; i < *r.out.num_towers; i++) {
222 if (r.out.towers[i].twr) {
223 display_tower(tctx, &t);
230 static bool test_Map_full(struct torture_context *tctx,
231 struct dcerpc_pipe *p)
233 const struct ndr_syntax_id obj = {
234 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
237 struct dcerpc_binding_handle *h = p->binding_handle;
238 const char *annotation = "SMBTORTURE";
239 struct dcerpc_binding *b;
243 status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:216.83.154.106[41768]", &b);
244 torture_assert_ntstatus_ok(tctx,
246 "Unable to generate dcerpc_binding struct");
249 ok = test_Insert(tctx, h, obj, annotation, b);
254 ok = test_Map_tcpip(tctx, h, obj);
259 ok = test_Delete(tctx, h, annotation, b);
267 static bool test_Map_display(struct dcerpc_binding_handle *b,
268 struct torture_context *tctx,
269 struct epm_twr_t *twr)
274 struct policy_handle handle;
275 struct ndr_syntax_id syntax;
283 r.in.map_tower = twr;
284 r.in.entry_handle = &handle;
285 r.out.entry_handle = &handle;
286 r.in.max_towers = 10;
287 r.out.num_towers = &num_towers;
289 dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &syntax);
291 torture_comment(tctx,
292 "epm_Map results for '%s':\n",
293 ndr_interface_name(&syntax.uuid, syntax.if_version));
295 /* RPC protocol identifier */
296 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
297 twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
298 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
301 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
302 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
303 twr->tower.floors[3].rhs.tcp.port = 0;
306 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
307 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
308 twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
310 status = dcerpc_epm_Map_r(b, tctx, &r);
311 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
312 for (i=0;i<*r.out.num_towers;i++) {
313 if (r.out.towers[i].twr) {
314 display_tower(tctx, &r.out.towers[i].twr->tower);
319 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
320 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
321 twr->tower.floors[3].rhs.http.port = 0;
323 status = dcerpc_epm_Map_r(b, tctx, &r);
324 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
325 for (i=0;i<*r.out.num_towers;i++) {
326 if (r.out.towers[i].twr) {
327 display_tower(tctx, &r.out.towers[i].twr->tower);
332 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
333 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
334 twr->tower.floors[3].rhs.http.port = 0;
336 status = dcerpc_epm_Map_r(b, tctx, &r);
337 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
338 for (i=0;i<*r.out.num_towers;i++) {
339 if (r.out.towers[i].twr) {
340 display_tower(tctx, &r.out.towers[i].twr->tower);
345 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
346 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
347 twr->tower.floors[3].rhs.smb.unc = "";
349 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
350 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
351 twr->tower.floors[4].rhs.netbios.name = "";
353 status = dcerpc_epm_Map_r(b, tctx, &r);
354 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
355 for (i = 0; i < *r.out.num_towers; i++) {
356 if (r.out.towers[i].twr) {
357 display_tower(tctx, &r.out.towers[i].twr->tower);
362 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
367 static bool test_Map_simple(struct torture_context *tctx,
368 struct dcerpc_pipe *p)
372 struct policy_handle entry_handle;
373 uint32_t num_ents = 0;
374 struct dcerpc_binding_handle *h = p->binding_handle;
376 ZERO_STRUCT(entry_handle);
378 torture_comment(tctx, "Testing epm_Map\n");
380 /* get all elements */
381 r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
383 r.in.interface_id = NULL;
384 r.in.vers_option = RPC_C_VERS_ALL;
386 r.in.entry_handle = &entry_handle;
389 r.out.entry_handle = &entry_handle;
390 r.out.num_ents = &num_ents;
395 status = dcerpc_epm_Lookup_r(h, tctx, &r);
396 if (!NT_STATUS_IS_OK(status) ||
397 r.out.result != EPMAPPER_STATUS_OK) {
401 for (i = 0; i < *r.out.num_ents; i++) {
402 if (r.out.entries[i].tower->tower.num_floors == 5) {
403 test_Map_display(h, tctx, r.out.entries[i].tower);
406 } while (NT_STATUS_IS_OK(status) &&
407 r.out.result == EPMAPPER_STATUS_OK &&
408 *r.out.num_ents == r.in.max_ents &&
409 !ndr_policy_handle_empty(&entry_handle));
411 torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
414 ndr_policy_handle_empty(&entry_handle),
415 "epm_Map_simple failed - The policy handle should be emtpy.");
420 static bool test_LookupHandleFree(struct torture_context *tctx,
421 struct dcerpc_binding_handle *h,
422 struct policy_handle *entry_handle) {
424 struct epm_LookupHandleFree r;
426 if (torture_setting_bool(tctx, "samba4", false)) {
427 torture_skip(tctx, "Skip Insert test against Samba4");
430 if (ndr_policy_handle_empty(entry_handle)) {
431 torture_comment(tctx,
432 "epm_LookupHandleFree failed - empty policy_handle\n");
436 r.in.entry_handle = entry_handle;
437 r.out.entry_handle = entry_handle;
439 status = dcerpc_epm_LookupHandleFree_r(h, tctx, &r);
440 if (NT_STATUS_IS_ERR(status)) {
441 torture_comment(tctx,
442 "epm_LookupHandleFree failed - %s\n",
447 if (r.out.result != EPMAPPER_STATUS_OK) {
448 torture_comment(tctx,
449 "epm_LookupHandleFree failed - internal error: "
458 static bool test_Lookup_simple(struct torture_context *tctx,
459 struct dcerpc_pipe *p)
463 struct policy_handle entry_handle;
464 uint32_t num_ents = 0;
465 struct dcerpc_binding_handle *h = p->binding_handle;
467 ZERO_STRUCT(entry_handle);
469 torture_comment(tctx, "Testing epm_Lookup\n");
471 /* get all elements */
472 r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
474 r.in.interface_id = NULL;
475 r.in.vers_option = RPC_C_VERS_ALL;
477 r.in.entry_handle = &entry_handle;
480 r.out.entry_handle = &entry_handle;
481 r.out.num_ents = &num_ents;
486 status = dcerpc_epm_Lookup_r(h, tctx, &r);
487 if (!NT_STATUS_IS_OK(status) ||
488 r.out.result != EPMAPPER_STATUS_OK) {
492 torture_comment(tctx,
493 "epm_Lookup returned %d events, entry_handle: %s\n",
495 GUID_string(tctx, &entry_handle.uuid));
497 for (i = 0; i < *r.out.num_ents; i++) {
498 torture_comment(tctx,
500 r.out.entries[i].annotation);
502 display_tower(tctx, &r.out.entries[i].tower->tower);
504 } while (NT_STATUS_IS_OK(status) &&
505 r.out.result == EPMAPPER_STATUS_OK &&
506 *r.out.num_ents == r.in.max_ents &&
507 !ndr_policy_handle_empty(&entry_handle));
509 torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
510 torture_assert(tctx, r.out.result == EPMAPPER_STATUS_NO_MORE_ENTRIES, "epm_Lookup failed");
513 ndr_policy_handle_empty(&entry_handle),
514 "epm_Lookup failed - The policy handle should be emtpy.");
520 * This test starts a epm_Lookup request, but doesn't finish the
521 * call terminates the search. So it will call epm_LookupHandleFree.
523 static bool test_Lookup_terminate_search(struct torture_context *tctx,
524 struct dcerpc_pipe *p)
529 struct policy_handle entry_handle;
530 uint32_t i, num_ents = 0;
531 struct dcerpc_binding_handle *h = p->binding_handle;
533 ZERO_STRUCT(entry_handle);
535 torture_comment(tctx, "Testing epm_Lookup and epm_LookupHandleFree\n");
537 /* get all elements */
538 r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
540 r.in.interface_id = NULL;
541 r.in.vers_option = RPC_C_VERS_ALL;
543 r.in.entry_handle = &entry_handle;
546 r.out.entry_handle = &entry_handle;
547 r.out.num_ents = &num_ents;
549 status = dcerpc_epm_Lookup_r(h, tctx, &r);
551 torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
552 torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, "epm_Lookup failed");
554 torture_comment(tctx,
555 "epm_Lookup returned %d events, entry_handle: %s\n",
557 GUID_string(tctx, &entry_handle.uuid));
559 for (i = 0; i < *r.out.num_ents; i++) {
560 torture_comment(tctx,
562 r.out.entries[i].annotation);
565 ok = test_LookupHandleFree(tctx,
575 static bool test_Insert_noreplace(struct torture_context *tctx,
576 struct dcerpc_pipe *p)
581 struct dcerpc_binding *b;
582 struct dcerpc_binding_handle *h = p->binding_handle;
584 torture_comment(tctx, "Testing epm_Insert(noreplace) and epm_Delete\n");
586 if (torture_setting_bool(tctx, "samba4", false)) {
587 torture_skip(tctx, "Skip Insert test against Samba4");
591 r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
593 ZERO_STRUCT(r.in.entries[0].object);
594 r.in.entries[0].annotation = "smbtorture endpoint";
596 status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &b);
597 torture_assert_ntstatus_ok(tctx,
599 "Unable to generate dcerpc_binding struct");
601 r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
603 status = dcerpc_binding_build_tower(tctx,
605 &r.in.entries[0].tower->tower);
606 torture_assert_ntstatus_ok(tctx,
608 "Unable to build tower from binding struct");
611 status = dcerpc_epm_Insert_r(h, tctx, &r);
612 torture_assert_ntstatus_ok(tctx, status, "epm_Insert failed");
614 torture_assert(tctx, r.out.result == 0, "epm_Insert failed");
616 ok = test_Delete(tctx, h, "smbtorture", b);
626 * The MS-RPCE documentation states that this function isn't implemented and
627 * SHOULD NOT be called by a client.
629 static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p)
632 struct epm_InqObject r;
633 struct dcerpc_binding_handle *b = p->binding_handle;
635 r.in.epm_object = talloc(tctx, struct GUID);
636 *r.in.epm_object = ndr_table_epmapper.syntax_id.uuid;
638 status = dcerpc_epm_InqObject_r(b, tctx, &r);
639 torture_assert_ntstatus_ok(tctx, status, "InqObject failed");
645 struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
647 struct torture_suite *suite = torture_suite_create(mem_ctx, "epmapper");
648 struct torture_rpc_tcase *tcase;
650 tcase = torture_suite_add_rpc_iface_tcase(suite,
652 &ndr_table_epmapper);
654 /* This is a stack */
655 torture_rpc_tcase_add_test(tcase,
658 torture_rpc_tcase_add_test(tcase,
661 torture_rpc_tcase_add_test(tcase,
664 torture_rpc_tcase_add_test(tcase,
665 "Lookup_terminate_search",
666 test_Lookup_terminate_search);
667 torture_rpc_tcase_add_test(tcase,
669 test_Insert_noreplace);
674 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */