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 2 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 "system/network.h"
24 #include "librpc/gen_ndr/ndr_epmapper.h"
28 display any protocol tower
30 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
34 for (i=0;i<twr->num_floors;i++) {
35 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
41 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
42 struct epm_twr_t *twr)
48 struct policy_handle handle;
58 r.in.entry_handle = &handle;
59 r.out.entry_handle = &handle;
60 r.in.max_towers = 100;
62 dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &if_uuid, &if_version);
63 uuid_str = GUID_string(mem_ctx, &if_uuid);
65 printf("epm_Map results for '%s':\n",
66 idl_pipe_name(uuid_str, 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 dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
142 struct rpc_if_id_t iface;
143 struct policy_handle handle;
147 r.in.inquiry_type = 0;
149 r.in.interface_id = &iface;
150 r.in.vers_option = 0;
151 r.in.entry_handle = &handle;
152 r.out.entry_handle = &handle;
161 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
162 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
166 printf("epm_Lookup returned %d events GUID %s\n",
167 r.out.num_ents, GUID_string(mem_ctx, &handle.uuid));
169 for (i=0;i<r.out.num_ents;i++) {
170 printf("\nFound '%s'\n", r.out.entries[i].annotation);
171 display_tower(mem_ctx, &r.out.entries[i].tower->tower);
172 if (r.out.entries[i].tower->tower.num_floors == 5) {
173 test_Map(p, mem_ctx, r.out.entries[i].tower);
176 } while (NT_STATUS_IS_OK(status) &&
178 r.out.num_ents == r.in.max_ents &&
179 !policy_handle_empty(&handle));
181 if (!NT_STATUS_IS_OK(status)) {
182 printf("Lookup failed - %s\n", nt_errstr(status));
190 static BOOL test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
196 r.in.entries = entries;
198 status = dcerpc_epm_Delete(p, mem_ctx, &r);
199 if (NT_STATUS_IS_ERR(status)) {
200 printf("Delete failed - %s\n", nt_errstr(status));
204 if (r.out.result != 0) {
205 printf("Delete failed - %d\n", r.out.result);
212 static BOOL test_Insert(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
216 struct dcerpc_binding *bd;
220 r.in.entries = talloc_array(mem_ctx, 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(mem_ctx, "ncalrpc:[SMBTORTURE]", &bd);
224 if (NT_STATUS_IS_ERR(status)) {
225 printf("Unable to generate dcerpc_binding struct\n");
229 r.in.entries[0].tower = talloc(mem_ctx, struct epm_twr_t);
231 status = dcerpc_binding_build_tower(mem_ctx, bd, &r.in.entries[0].tower->tower);
232 if (NT_STATUS_IS_ERR(status)) {
233 printf("Unable to build tower from binding struct\n");
239 status = dcerpc_epm_Insert(p, mem_ctx, &r);
240 if (NT_STATUS_IS_ERR(status)) {
241 printf("Insert failed - %s\n", nt_errstr(status));
245 if (r.out.result != 0) {
246 printf("Insert failed - %d\n", r.out.result);
247 printf("NOT CONSIDERING AS A FAILURE\n");
251 if (!test_Delete(p, mem_ctx, r.in.entries)) {
258 static BOOL test_InqObject(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
261 struct epm_InqObject r;
263 r.in.epm_object = talloc(mem_ctx, struct GUID);
264 GUID_from_string(DCERPC_EPMAPPER_UUID, r.in.epm_object);
266 status = dcerpc_epm_InqObject(p, mem_ctx, &r);
267 if (NT_STATUS_IS_ERR(status)) {
268 printf("InqObject failed - %s\n", nt_errstr(status));
275 BOOL torture_rpc_epmapper(void)
278 struct dcerpc_pipe *p;
282 mem_ctx = talloc_init("torture_rpc_epmapper");
284 status = torture_rpc_connection(&p,
285 DCERPC_EPMAPPER_NAME,
286 DCERPC_EPMAPPER_UUID,
287 DCERPC_EPMAPPER_VERSION);
288 if (!NT_STATUS_IS_OK(status)) {
292 if (!test_Lookup(p, mem_ctx)) {
296 if (!test_Insert(p, mem_ctx)) {
300 if (!test_InqObject(p, mem_ctx)) {
304 talloc_free(mem_ctx);
306 torture_rpc_close(p);