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.
26 display any protocol tower
28 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_towers *twr)
33 for (i=0;i<twr->num_floors;i++) {
34 struct epm_lhs *lhs = &twr->floors[i].lhs;
35 struct epm_rhs *rhs = &twr->floors[i].rhs;
36 switch (lhs->protocol) {
37 case EPM_PROTOCOL_NCACN_DNET_NSP:
41 case EPM_PROTOCOL_UUID:
42 uuid = GUID_string(mem_ctx, &lhs->info.uuid.uuid);
43 if (strcasecmp(uuid, NDR_GUID) == 0) {
46 printf(" uuid %s/0x%02x", uuid, lhs->info.uuid.version);
50 case EPM_PROTOCOL_NCACN_RPC_C:
54 case EPM_PROTOCOL_NCACN_IP:
56 if (rhs->rhs_data.length == 4) {
58 in.s_addr = IVAL(rhs->rhs_data.data, 0);
59 printf("%s", inet_ntoa(in));
63 case EPM_PROTOCOL_NCACN_PIPE:
64 printf(" PIPE:%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
67 case EPM_PROTOCOL_NCACN_SMB:
68 printf(" SMB:%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
71 case EPM_PROTOCOL_NCACN_NETBIOS:
72 printf(" NetBIOS:%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
75 case EPM_PROTOCOL_NCACN_NB_NB:
79 case EPM_PROTOCOL_NCACN_SPX:
84 case EPM_PROTOCOL_NCACN_NB_IPX:
89 printf(" UNK(1):%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
92 case EPM_PROTOCOL_NCACN_HTTP:
94 if (rhs->rhs_data.length == 2) {
95 printf("%d", RSVAL(rhs->rhs_data.data, 0));
99 case EPM_PROTOCOL_NCACN_TCP:
100 /* what is the difference between this and 0x1f? */
102 if (rhs->rhs_data.length == 2) {
103 printf("%d", RSVAL(rhs->rhs_data.data, 0));
107 case EPM_PROTOCOL_NCADG_UDP:
112 printf(" UNK(%02x):", lhs->protocol);
113 if (rhs->rhs_data.length == 2) {
114 printf("%d", RSVAL(rhs->rhs_data.data, 0));
123 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
124 struct epm_twr_t *twr)
129 const char *uuid_str;
130 struct policy_handle handle;
137 r.in.map_tower = twr;
138 r.in.entry_handle = &handle;
139 r.out.entry_handle = &handle;
140 r.in.max_towers = 100;
142 if (twr->towers.num_floors != 5) {
143 printf(" tower has %d floors - skipping test_Map\n", twr->towers.num_floors);
147 uuid_str = GUID_string(mem_ctx, &twr->towers.floors[0].lhs.info.uuid.uuid);
149 printf("epm_Map results for '%s':\n",
150 idl_pipe_name(uuid_str, twr->towers.floors[0].lhs.info.uuid.version));
152 twr->towers.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN_RPC_C;
153 twr->towers.floors[2].lhs.info.lhs_data = data_blob(NULL, 0);
154 twr->towers.floors[2].rhs.rhs_data = data_blob_talloc_zero(p->mem_ctx, 2);
156 twr->towers.floors[3].lhs.protocol = EPM_PROTOCOL_NCACN_TCP;
157 twr->towers.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
158 twr->towers.floors[3].rhs.rhs_data = data_blob_talloc_zero(p->mem_ctx, 2);
160 twr->towers.floors[4].lhs.protocol = EPM_PROTOCOL_NCACN_IP;
161 twr->towers.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
162 twr->towers.floors[4].rhs.rhs_data = data_blob_talloc_zero(p->mem_ctx, 4);
164 status = dcerpc_epm_Map(p, mem_ctx, &r);
165 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
166 for (i=0;i<r.out.num_towers;i++) {
167 if (r.out.towers[i].twr) {
168 display_tower(mem_ctx, &r.out.towers[i].twr->towers);
173 twr->towers.floors[3].lhs.protocol = EPM_PROTOCOL_NCACN_HTTP;
174 twr->towers.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
175 twr->towers.floors[3].rhs.rhs_data = data_blob_talloc_zero(p->mem_ctx, 2);
177 status = dcerpc_epm_Map(p, mem_ctx, &r);
178 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
179 for (i=0;i<r.out.num_towers;i++) {
180 if (r.out.towers[i].twr) {
181 display_tower(mem_ctx, &r.out.towers[i].twr->towers);
186 twr->towers.floors[3].lhs.protocol = EPM_PROTOCOL_NCACN_SMB;
187 twr->towers.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
188 twr->towers.floors[3].rhs.rhs_data = data_blob_talloc_zero(p->mem_ctx, 2);
190 twr->towers.floors[4].lhs.protocol = EPM_PROTOCOL_NCACN_NETBIOS;
191 twr->towers.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
192 twr->towers.floors[4].rhs.rhs_data = data_blob_talloc_zero(p->mem_ctx, 2);
194 status = dcerpc_epm_Map(p, mem_ctx, &r);
195 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
196 for (i=0;i<r.out.num_towers;i++) {
197 if (r.out.towers[i].twr) {
198 display_tower(mem_ctx, &r.out.towers[i].twr->towers);
206 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
211 struct rpc_if_id_t iface;
212 struct policy_handle handle;
218 r.in.inquiry_type = 0;
220 r.in.interface_id = &iface;
221 r.in.vers_option = 0;
222 r.in.entry_handle = &handle;
223 r.out.entry_handle = &handle;
228 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
229 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
232 for (i=0;i<r.out.num_ents;i++) {
233 printf("\nFound '%s'\n", r.out.entries[i].annotation);
234 display_tower(mem_ctx, &r.out.entries[i].tower->towers);
235 test_Map(p, mem_ctx, r.out.entries[i].tower);
237 } while (NT_STATUS_IS_OK(status) &&
239 r.out.num_ents == r.in.max_ents);
241 if (!NT_STATUS_IS_OK(status)) {
242 printf("Lookup failed - %s\n", nt_errstr(status));
250 BOOL torture_rpc_epmapper(int dummy)
253 struct dcerpc_pipe *p;
257 mem_ctx = talloc_init("torture_rpc_epmapper");
259 status = torture_rpc_connection(&p,
260 DCERPC_EPMAPPER_NAME,
261 DCERPC_EPMAPPER_UUID,
262 DCERPC_EPMAPPER_VERSION);
263 if (!NT_STATUS_IS_OK(status)) {
267 if (!test_Lookup(p, mem_ctx)) {
271 talloc_destroy(mem_ctx);
273 torture_rpc_close(p);