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)
35 for (i=0;i<twr->num_floors;i++) {
36 struct epm_lhs *lhs = &twr->floors[i].lhs;
37 union epm_rhs *rhs = &twr->floors[i].rhs;
39 switch(lhs->protocol) {
40 case EPM_PROTOCOL_UUID:
41 uuid = GUID_string(mem_ctx, &lhs->info.uuid.uuid);
42 if (strcasecmp(uuid, NDR_GUID) == 0) {
45 printf(" uuid %s/0x%02x", uuid, lhs->info.uuid.version);
49 case EPM_PROTOCOL_NCACN:
53 case EPM_PROTOCOL_NCADG:
57 case EPM_PROTOCOL_NCALRPC:
61 case EPM_PROTOCOL_DNET_NSP:
69 in.addr = htonl(rhs->ip.address);
70 printf("%s", sys_inet_ntoa(in));
74 case EPM_PROTOCOL_PIPE:
75 printf(" PIPE:%s", rhs->pipe.path);
78 case EPM_PROTOCOL_SMB:
79 printf(" SMB:%s", rhs->smb.unc);
82 case EPM_PROTOCOL_UNIX_DS:
83 printf(" Unix:%s", rhs->unix_ds.path);
86 case EPM_PROTOCOL_NETBIOS:
87 printf(" NetBIOS:%s", rhs->netbios.name);
90 case EPM_PROTOCOL_NETBEUI:
94 case EPM_PROTOCOL_SPX:
98 case EPM_PROTOCOL_NB_IPX:
102 case EPM_PROTOCOL_HTTP:
103 printf(" HTTP:%d", rhs->http.port);
106 case EPM_PROTOCOL_TCP:
107 /* what is the difference between this and 0x1f? */
108 printf(" TCP:%d", rhs->tcp.port);
111 case EPM_PROTOCOL_UDP:
112 printf(" UDP:%d", rhs->udp.port);
116 printf(" UNK(%02x):", lhs->protocol);
117 if (rhs->unknown.length == 2) {
118 printf("%d", RSVAL(rhs->unknown.data, 0));
127 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
128 struct epm_twr_t *twr)
133 const char *uuid_str;
134 struct policy_handle handle;
141 r.in.map_tower = twr;
142 r.in.entry_handle = &handle;
143 r.out.entry_handle = &handle;
144 r.in.max_towers = 100;
146 uuid_str = GUID_string(mem_ctx, &twr->tower.floors[0].lhs.info.uuid.uuid);
148 printf("epm_Map results for '%s':\n",
149 idl_pipe_name(uuid_str, twr->tower.floors[0].lhs.info.uuid.version));
151 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
152 twr->tower.floors[2].lhs.info.lhs_data = data_blob(NULL, 0);
153 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
155 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
156 twr->tower.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
157 twr->tower.floors[3].rhs.tcp.port = 0;
159 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
160 twr->tower.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
161 twr->tower.floors[4].rhs.ip.address = 0;
163 status = dcerpc_epm_Map(p, mem_ctx, &r);
164 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
165 for (i=0;i<r.out.num_towers;i++) {
166 if (r.out.towers[i].twr) {
167 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
172 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
173 twr->tower.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
174 twr->tower.floors[3].rhs.http.port = 0;
176 status = dcerpc_epm_Map(p, mem_ctx, &r);
177 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
178 for (i=0;i<r.out.num_towers;i++) {
179 if (r.out.towers[i].twr) {
180 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
185 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
186 twr->tower.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
187 twr->tower.floors[3].rhs.http.port = 0;
189 status = dcerpc_epm_Map(p, mem_ctx, &r);
190 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
191 for (i=0;i<r.out.num_towers;i++) {
192 if (r.out.towers[i].twr) {
193 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
198 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
199 twr->tower.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
200 twr->tower.floors[3].rhs.smb.unc = "";
202 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
203 twr->tower.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
204 twr->tower.floors[4].rhs.netbios.name = "";
206 status = dcerpc_epm_Map(p, mem_ctx, &r);
207 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
208 for (i=0;i<r.out.num_towers;i++) {
209 if (r.out.towers[i].twr) {
210 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
215 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
220 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
225 struct rpc_if_id_t iface;
226 struct policy_handle handle;
232 r.in.inquiry_type = 0;
234 r.in.interface_id = &iface;
235 r.in.vers_option = 0;
236 r.in.entry_handle = &handle;
237 r.out.entry_handle = &handle;
242 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
243 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
246 for (i=0;i<r.out.num_ents;i++) {
247 printf("\nFound '%s'\n", r.out.entries[i].annotation);
248 display_tower(mem_ctx, &r.out.entries[i].tower->tower);
249 if (r.out.entries[i].tower->tower.num_floors == 5) {
250 test_Map(p, mem_ctx, r.out.entries[i].tower);
253 } while (NT_STATUS_IS_OK(status) &&
255 r.out.num_ents == r.in.max_ents);
257 if (!NT_STATUS_IS_OK(status)) {
258 printf("Lookup failed - %s\n", nt_errstr(status));
266 BOOL torture_rpc_epmapper(void)
269 struct dcerpc_pipe *p;
273 mem_ctx = talloc_init("torture_rpc_epmapper");
275 status = torture_rpc_connection(&p,
276 DCERPC_EPMAPPER_NAME,
277 DCERPC_EPMAPPER_UUID,
278 DCERPC_EPMAPPER_VERSION);
279 if (!NT_STATUS_IS_OK(status)) {
283 if (!test_Lookup(p, mem_ctx)) {
287 talloc_destroy(mem_ctx);
289 torture_rpc_close(p);