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"
29 display any protocol tower
31 static void display_tower(struct torture_context *tctx, struct epm_tower *twr)
35 for (i = 0; i < twr->num_floors; i++) {
38 epm_floor_string(tctx, &twr->floors[i]));
40 torture_comment(tctx, "\n");
43 static bool test_Insert(struct torture_context *tctx,
44 struct dcerpc_binding_handle *h,
45 struct ndr_syntax_id object,
46 const char *annotation,
47 struct dcerpc_binding *b)
53 r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
55 if (torture_setting_bool(tctx, "samba4", false)) {
56 torture_skip(tctx, "Skip Insert test against Samba4");
60 ZERO_STRUCT(r.in.entries[0].object);
61 r.in.entries[0].annotation = annotation;
63 r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
65 status = dcerpc_binding_build_tower(tctx,
67 &r.in.entries[0].tower->tower);
69 torture_assert_ntstatus_ok(tctx,
71 "Unable to build tower from binding struct");
75 status = dcerpc_epm_Insert_r(h, tctx, &r);
77 if (NT_STATUS_IS_ERR(status)) {
79 "epm_Insert failed - %s\n",
84 if (r.out.result != EPMAPPER_STATUS_OK) {
86 "epm_Insert failed - internal error: 0x%.4x\n",
94 static bool test_Delete(struct torture_context *tctx,
95 struct dcerpc_binding_handle *h,
96 const char *annotation,
97 struct dcerpc_binding *b)
103 r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
105 ZERO_STRUCT(r.in.entries[0].object);
106 r.in.entries[0].annotation = annotation;
108 r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
110 status = dcerpc_binding_build_tower(tctx,
112 &r.in.entries[0].tower->tower);
114 torture_assert_ntstatus_ok(tctx,
116 "Unable to build tower from binding struct");
119 status = dcerpc_epm_Delete_r(h, tctx, &r);
120 if (NT_STATUS_IS_ERR(status)) {
121 torture_comment(tctx,
122 "epm_Delete failed - %s\n",
127 if (r.out.result != EPMAPPER_STATUS_OK) {
128 torture_comment(tctx,
129 "epm_Delete failed - internal error: 0x%.4x\n",
137 static bool test_Map_tcpip(struct torture_context *tctx,
138 struct dcerpc_binding_handle *h,
139 struct ndr_syntax_id map_syntax)
143 struct policy_handle entry_handle;
144 struct ndr_syntax_id syntax;
145 struct dcerpc_binding map_binding;
146 struct epm_twr_t map_tower;
147 struct epm_twr_p_t towers[20];
158 torture_comment(tctx, "Testing epm_Map\n");
161 ZERO_STRUCT(entry_handle);
164 r.in.map_tower = &map_tower;
165 r.in.entry_handle = &entry_handle;
166 r.out.entry_handle = &entry_handle;
167 r.in.max_towers = 10;
168 r.out.towers = towers;
169 r.out.num_towers = &num_towers;
171 /* Create map tower */
172 map_binding.transport = NCACN_IP_TCP;
173 map_binding.object = map_syntax;
174 map_binding.host = "0.0.0.0";
175 map_binding.endpoint = "135";
177 status = dcerpc_binding_build_tower(tctx, &map_binding,
179 torture_assert_ntstatus_ok(tctx, status,
180 "epm_Map_tcpip failed: can't create map_tower");
182 torture_comment(tctx,
183 "epm_Map request for '%s':\n",
184 ndr_interface_name(&map_syntax.uuid, map_syntax.if_version));
185 display_tower(tctx, &r.in.map_tower->tower);
187 status = dcerpc_epm_Map_r(h, tctx, &r);
189 torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
190 torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK,
191 "epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK");
193 /* Check the result */
194 t = r.out.towers[0].twr->tower;
196 /* Check if we got the correct RPC interface identifier */
197 dcerpc_floor_get_lhs_data(&t.floors[0], &syntax);
198 torture_assert(tctx, ndr_syntax_id_equal(&syntax, &map_syntax),
199 "epm_Map_tcpip failed: Interface identifier mismatch");
201 torture_comment(tctx,
202 "epm_Map_tcpip response for '%s':\n",
203 ndr_interface_name(&syntax.uuid, syntax.if_version));
205 dcerpc_floor_get_lhs_data(&t.floors[1], &syntax);
206 torture_assert(tctx, ndr_syntax_id_equal(&syntax, &ndr_transfer_syntax),
207 "epm_Map_tcpip failed: floor 2 is not NDR encoded");
209 torture_assert(tctx, t.floors[2].lhs.protocol == EPM_PROTOCOL_NCACN,
210 "epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP");
212 tmp = dcerpc_floor_get_rhs_data(tctx, &t.floors[3]);
213 p = strtol(tmp, &ptr, 10);
215 torture_assert(tctx, port > 1024 && port < 65535, "epm_Map_tcpip failed");
217 ip = dcerpc_floor_get_rhs_data(tctx, &t.floors[4]);
218 torture_assert(tctx, is_ipaddress(ip), "epm_Map_tcpip failed");
220 for (i = 0; i < *r.out.num_towers; i++) {
221 if (r.out.towers[i].twr) {
222 display_tower(tctx, &t);
229 static bool test_Map_full(struct torture_context *tctx,
230 struct dcerpc_pipe *p)
232 const struct ndr_syntax_id obj = {
233 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
236 struct dcerpc_binding_handle *h = p->binding_handle;
237 const char *annotation = "SMBTORTURE";
238 struct dcerpc_binding *b;
242 status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:216.83.154.106[41768]", &b);
243 torture_assert_ntstatus_ok(tctx,
245 "Unable to generate dcerpc_binding struct");
248 ok = test_Insert(tctx, h, obj, annotation, b);
253 ok = test_Map_tcpip(tctx, h, obj);
258 ok = test_Delete(tctx, h, annotation, b);
266 static bool test_Map_display(struct dcerpc_binding_handle *b,
267 struct torture_context *tctx,
268 struct epm_twr_t *twr)
273 struct policy_handle handle;
274 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_lhs_data(&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 /* RPC protocol identifier */
295 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
296 twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
297 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
300 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
301 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
302 twr->tower.floors[3].rhs.tcp.port = 0;
305 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
306 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
307 twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
309 status = dcerpc_epm_Map_r(b, tctx, &r);
310 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
311 for (i=0;i<*r.out.num_towers;i++) {
312 if (r.out.towers[i].twr) {
313 display_tower(tctx, &r.out.towers[i].twr->tower);
318 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
319 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
320 twr->tower.floors[3].rhs.http.port = 0;
322 status = dcerpc_epm_Map_r(b, tctx, &r);
323 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
324 for (i=0;i<*r.out.num_towers;i++) {
325 if (r.out.towers[i].twr) {
326 display_tower(tctx, &r.out.towers[i].twr->tower);
331 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
332 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
333 twr->tower.floors[3].rhs.http.port = 0;
335 status = dcerpc_epm_Map_r(b, tctx, &r);
336 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
337 for (i=0;i<*r.out.num_towers;i++) {
338 if (r.out.towers[i].twr) {
339 display_tower(tctx, &r.out.towers[i].twr->tower);
344 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
345 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
346 twr->tower.floors[3].rhs.smb.unc = "";
348 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
349 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
350 twr->tower.floors[4].rhs.netbios.name = "";
352 status = dcerpc_epm_Map_r(b, tctx, &r);
353 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
354 for (i = 0; i < *r.out.num_towers; i++) {
355 if (r.out.towers[i].twr) {
356 display_tower(tctx, &r.out.towers[i].twr->tower);
361 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
366 static bool test_Map_simple(struct torture_context *tctx,
367 struct dcerpc_pipe *p)
371 struct policy_handle entry_handle;
372 uint32_t num_ents = 0;
373 struct dcerpc_binding_handle *h = p->binding_handle;
375 ZERO_STRUCT(entry_handle);
377 torture_comment(tctx, "Testing epm_Map\n");
379 /* get all elements */
380 r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
382 r.in.interface_id = NULL;
383 r.in.vers_option = RPC_C_VERS_ALL;
385 r.in.entry_handle = &entry_handle;
388 r.out.entry_handle = &entry_handle;
389 r.out.num_ents = &num_ents;
394 status = dcerpc_epm_Lookup_r(h, tctx, &r);
395 if (!NT_STATUS_IS_OK(status) ||
396 r.out.result != EPMAPPER_STATUS_OK) {
400 for (i = 0; i < *r.out.num_ents; i++) {
401 if (r.out.entries[i].tower->tower.num_floors == 5) {
402 test_Map_display(h, tctx, r.out.entries[i].tower);
405 } while (NT_STATUS_IS_OK(status) &&
406 r.out.result == EPMAPPER_STATUS_OK &&
407 *r.out.num_ents == r.in.max_ents &&
408 !policy_handle_empty(&entry_handle));
410 torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
413 policy_handle_empty(&entry_handle),
414 "epm_Map_simple failed - The policy handle should be emtpy.");
419 static bool test_LookupHandleFree(struct torture_context *tctx,
420 struct dcerpc_binding_handle *h,
421 struct policy_handle *entry_handle) {
423 struct epm_LookupHandleFree r;
425 if (torture_setting_bool(tctx, "samba4", false)) {
426 torture_skip(tctx, "Skip Insert test against Samba4");
429 if (policy_handle_empty(entry_handle)) {
430 torture_comment(tctx,
431 "epm_LookupHandleFree failed - empty policy_handle\n");
435 r.in.entry_handle = entry_handle;
436 r.out.entry_handle = entry_handle;
438 status = dcerpc_epm_LookupHandleFree_r(h, tctx, &r);
439 if (NT_STATUS_IS_ERR(status)) {
440 torture_comment(tctx,
441 "epm_LookupHandleFree failed - %s\n",
446 if (r.out.result != EPMAPPER_STATUS_OK) {
447 torture_comment(tctx,
448 "epm_LookupHandleFree failed - internal error: "
457 static bool test_Lookup_simple(struct torture_context *tctx,
458 struct dcerpc_pipe *p)
462 struct policy_handle entry_handle;
463 uint32_t num_ents = 0;
464 struct dcerpc_binding_handle *h = p->binding_handle;
466 ZERO_STRUCT(entry_handle);
468 torture_comment(tctx, "Testing epm_Lookup\n");
470 /* get all elements */
471 r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
473 r.in.interface_id = NULL;
474 r.in.vers_option = RPC_C_VERS_ALL;
476 r.in.entry_handle = &entry_handle;
479 r.out.entry_handle = &entry_handle;
480 r.out.num_ents = &num_ents;
485 status = dcerpc_epm_Lookup_r(h, tctx, &r);
486 if (!NT_STATUS_IS_OK(status) ||
487 r.out.result != EPMAPPER_STATUS_OK) {
491 torture_comment(tctx,
492 "epm_Lookup returned %d events, entry_handle: %s\n",
494 GUID_string(tctx, &entry_handle.uuid));
496 for (i = 0; i < *r.out.num_ents; i++) {
497 torture_comment(tctx,
499 r.out.entries[i].annotation);
501 display_tower(tctx, &r.out.entries[i].tower->tower);
503 } while (NT_STATUS_IS_OK(status) &&
504 r.out.result == EPMAPPER_STATUS_OK &&
505 *r.out.num_ents == r.in.max_ents &&
506 !policy_handle_empty(&entry_handle));
508 torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
509 torture_assert(tctx, r.out.result == EPMAPPER_STATUS_NO_MORE_ENTRIES, "epm_Lookup failed");
512 policy_handle_empty(&entry_handle),
513 "epm_Lookup failed - The policy handle should be emtpy.");
519 * This test starts a epm_Lookup request, but doesn't finish the
520 * call terminates the search. So it will call epm_LookupHandleFree.
522 static bool test_Lookup_terminate_search(struct torture_context *tctx,
523 struct dcerpc_pipe *p)
528 struct policy_handle entry_handle;
529 uint32_t i, num_ents = 0;
530 struct dcerpc_binding_handle *h = p->binding_handle;
532 ZERO_STRUCT(entry_handle);
534 torture_comment(tctx, "Testing epm_Lookup and epm_LookupHandleFree\n");
536 /* get all elements */
537 r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
539 r.in.interface_id = NULL;
540 r.in.vers_option = RPC_C_VERS_ALL;
542 r.in.entry_handle = &entry_handle;
545 r.out.entry_handle = &entry_handle;
546 r.out.num_ents = &num_ents;
548 status = dcerpc_epm_Lookup_r(h, tctx, &r);
550 torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
551 torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, "epm_Lookup failed");
553 torture_comment(tctx,
554 "epm_Lookup returned %d events, entry_handle: %s\n",
556 GUID_string(tctx, &entry_handle.uuid));
558 for (i = 0; i < *r.out.num_ents; i++) {
559 torture_comment(tctx,
561 r.out.entries[i].annotation);
564 ok = test_LookupHandleFree(tctx,
574 static bool test_Insert_noreplace(struct torture_context *tctx,
575 struct dcerpc_pipe *p)
580 struct dcerpc_binding *b;
581 struct dcerpc_binding_handle *h = p->binding_handle;
583 torture_comment(tctx, "Testing epm_Insert(noreplace) and epm_Delete\n");
585 if (torture_setting_bool(tctx, "samba4", false)) {
586 torture_skip(tctx, "Skip Insert test against Samba4");
590 r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
592 ZERO_STRUCT(r.in.entries[0].object);
593 r.in.entries[0].annotation = "smbtorture endpoint";
595 status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &b);
596 torture_assert_ntstatus_ok(tctx,
598 "Unable to generate dcerpc_binding struct");
600 r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
602 status = dcerpc_binding_build_tower(tctx,
604 &r.in.entries[0].tower->tower);
605 torture_assert_ntstatus_ok(tctx,
607 "Unable to build tower from binding struct");
610 status = dcerpc_epm_Insert_r(h, tctx, &r);
611 torture_assert_ntstatus_ok(tctx, status, "epm_Insert failed");
613 torture_assert(tctx, r.out.result == 0, "epm_Insert failed");
615 ok = test_Delete(tctx, h, "smbtorture", b);
625 * The MS-RPCE documentation states that this function isn't implemented and
626 * SHOULD NOT be called by a client.
628 static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p)
631 struct epm_InqObject r;
632 struct dcerpc_binding_handle *b = p->binding_handle;
634 r.in.epm_object = talloc(tctx, struct GUID);
635 *r.in.epm_object = ndr_table_epmapper.syntax_id.uuid;
637 status = dcerpc_epm_InqObject_r(b, tctx, &r);
638 torture_assert_ntstatus_ok(tctx, status, "InqObject failed");
644 struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
646 struct torture_suite *suite = torture_suite_create(mem_ctx, "epmapper");
647 struct torture_rpc_tcase *tcase;
649 tcase = torture_suite_add_rpc_iface_tcase(suite,
651 &ndr_table_epmapper);
653 torture_rpc_tcase_add_test(tcase,
655 test_Insert_noreplace);
656 torture_rpc_tcase_add_test(tcase,
657 "Lookup_terminate_search",
658 test_Lookup_terminate_search);
659 torture_rpc_tcase_add_test(tcase,
662 torture_rpc_tcase_add_test(tcase,
665 torture_rpc_tcase_add_test(tcase,
672 /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */