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/rpc.h"
29 display any protocol tower
31 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
35 for (i=0;i<twr->num_floors;i++) {
36 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
42 static bool test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
43 struct epm_twr_t *twr)
48 struct policy_handle handle;
50 struct ndr_syntax_id syntax;
58 r.in.entry_handle = &handle;
59 r.out.entry_handle = &handle;
60 r.in.max_towers = 100;
61 r.out.num_towers = &num_towers;
63 dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &syntax);
65 printf("epm_Map results for '%s':\n",
66 ndr_interface_name(&syntax.uuid, syntax.if_version));
68 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
69 twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
70 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
72 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
73 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
74 twr->tower.floors[3].rhs.tcp.port = 0;
76 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
77 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
78 twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
80 status = dcerpc_epm_Map(p, mem_ctx, &r);
81 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
82 for (i=0;i<*r.out.num_towers;i++) {
83 if (r.out.towers[i].twr) {
84 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
89 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
90 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
91 twr->tower.floors[3].rhs.http.port = 0;
93 status = dcerpc_epm_Map(p, mem_ctx, &r);
94 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
95 for (i=0;i<*r.out.num_towers;i++) {
96 if (r.out.towers[i].twr) {
97 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
102 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
103 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
104 twr->tower.floors[3].rhs.http.port = 0;
106 status = dcerpc_epm_Map(p, mem_ctx, &r);
107 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
108 for (i=0;i<*r.out.num_towers;i++) {
109 if (r.out.towers[i].twr) {
110 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
115 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
116 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
117 twr->tower.floors[3].rhs.smb.unc = "";
119 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
120 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
121 twr->tower.floors[4].rhs.netbios.name = "";
123 status = dcerpc_epm_Map(p, mem_ctx, &r);
124 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
125 for (i=0;i<*r.out.num_towers;i++) {
126 if (r.out.towers[i].twr) {
127 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
132 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
137 static bool test_Lookup(struct torture_context *tctx,
138 struct dcerpc_pipe *p)
143 struct rpc_if_id_t iface;
144 struct policy_handle handle;
149 r.in.inquiry_type = 0;
151 r.in.interface_id = &iface;
152 r.in.vers_option = 0;
153 r.in.entry_handle = &handle;
154 r.out.entry_handle = &handle;
156 r.out.num_ents = &num_ents;
164 status = dcerpc_epm_Lookup(p, tctx, &r);
165 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
169 printf("epm_Lookup returned %d events GUID %s\n",
170 *r.out.num_ents, GUID_string(tctx, &handle.uuid));
172 for (i=0;i<*r.out.num_ents;i++) {
173 printf("\nFound '%s'\n", r.out.entries[i].annotation);
174 display_tower(tctx, &r.out.entries[i].tower->tower);
175 if (r.out.entries[i].tower->tower.num_floors == 5) {
176 test_Map(p, tctx, r.out.entries[i].tower);
179 } while (NT_STATUS_IS_OK(status) &&
181 *r.out.num_ents == r.in.max_ents &&
182 !policy_handle_empty(&handle));
184 torture_assert_ntstatus_ok(tctx, status, "Lookup failed");
189 static bool test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
195 r.in.entries = entries;
197 status = dcerpc_epm_Delete(p, mem_ctx, &r);
198 if (NT_STATUS_IS_ERR(status)) {
199 printf("Delete failed - %s\n", nt_errstr(status));
203 if (r.out.result != 0) {
204 printf("Delete failed - %d\n", r.out.result);
211 static bool test_Insert(struct torture_context *tctx,
212 struct dcerpc_pipe *p)
216 struct dcerpc_binding *bd;
220 r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
221 ZERO_STRUCT(r.in.entries[0].object);
222 r.in.entries[0].annotation = "smbtorture endpoint";
223 status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &bd);
224 torture_assert_ntstatus_ok(tctx, status,
225 "Unable to generate dcerpc_binding struct");
227 r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
229 status = dcerpc_binding_build_tower(tctx, bd, &r.in.entries[0].tower->tower);
230 torture_assert_ntstatus_ok(tctx, status,
231 "Unable to build tower from binding struct");
235 status = dcerpc_epm_Insert(p, tctx, &r);
236 torture_assert_ntstatus_ok(tctx, status, "Insert failed");
238 torture_assert(tctx, r.out.result == 0, "Insert failed");
240 if (!test_Delete(p, tctx, r.in.entries)) {
247 static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p)
250 struct epm_InqObject r;
252 r.in.epm_object = talloc(tctx, struct GUID);
253 *r.in.epm_object = ndr_table_epmapper.syntax_id.uuid;
255 status = dcerpc_epm_InqObject(p, tctx, &r);
256 torture_assert_ntstatus_ok(tctx, status, "InqObject failed");
261 struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
263 struct torture_suite *suite = torture_suite_create(mem_ctx, "EPMAPPER");
264 struct torture_rpc_tcase *tcase;
266 tcase = torture_suite_add_rpc_iface_tcase(suite, "epmapper",
267 &ndr_table_epmapper);
269 torture_rpc_tcase_add_test(tcase, "Lookup", test_Lookup);
270 torture_rpc_tcase_add_test(tcase, "Insert", test_Insert);
271 torture_rpc_tcase_add_test(tcase, "InqObject", test_InqObject);