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_UUID:
38 uuid = GUID_string(mem_ctx, &lhs->info.uuid.uuid);
39 if (strcasecmp(uuid, NDR_GUID) == 0) {
42 printf(" uuid %s/0x%02x", uuid, lhs->info.uuid.version);
46 case EPM_PROTOCOL_RPC_C:
52 if (rhs->rhs_data.length == 4) {
54 in.s_addr = IVAL(rhs->rhs_data.data, 0);
55 printf("%s", inet_ntoa(in));
59 case EPM_PROTOCOL_PIPE:
60 printf(" PIPE:%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
63 case EPM_PROTOCOL_SMB:
64 printf(" SMB:%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
67 case EPM_PROTOCOL_NETBIOS:
68 printf(" NetBIOS:%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
72 printf(" UNK(1):%.*s", rhs->rhs_data.length, rhs->rhs_data.data);
75 case EPM_PROTOCOL_HTTP:
77 if (rhs->rhs_data.length == 2) {
78 printf("%d", RSVAL(rhs->rhs_data.data, 0));
82 case EPM_PROTOCOL_TCP:
83 /* what is the difference between this and 0x1f? */
85 if (rhs->rhs_data.length == 2) {
86 printf("%d", RSVAL(rhs->rhs_data.data, 0));
91 printf(" UNK(%02x):", lhs->protocol);
92 if (rhs->rhs_data.length == 2) {
93 printf("%d", RSVAL(rhs->rhs_data.data, 0));
102 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
103 struct epm_twr_t *twr)
108 const char *uuid_str;
109 struct policy_handle handle;
116 r.in.map_tower = twr;
117 r.in.entry_handle = &handle;
118 r.out.entry_handle = &handle;
119 r.in.max_towers = 100;
121 if (twr->towers.num_floors != 5) {
122 printf(" tower has %d floors - skipping test_Map\n", twr->towers.num_floors);
126 uuid_str = GUID_string(mem_ctx, &twr->towers.floors[0].lhs.info.uuid.uuid);
128 printf("epm_Map results for '%s':\n",
129 idl_pipe_name(uuid_str, twr->towers.floors[0].lhs.info.uuid.version));
131 twr->towers.floors[2].lhs.protocol = EPM_PROTOCOL_RPC_C;
132 twr->towers.floors[2].lhs.info.lhs_data = data_blob(NULL, 0);
133 twr->towers.floors[2].rhs.rhs_data = data_blob_talloc(p->mem_ctx, NULL, 2);
135 twr->towers.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
136 twr->towers.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
137 twr->towers.floors[3].rhs.rhs_data = data_blob_talloc(p->mem_ctx, NULL, 2);
139 twr->towers.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
140 twr->towers.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
141 twr->towers.floors[4].rhs.rhs_data = data_blob_talloc(p->mem_ctx, NULL, 4);
143 status = dcerpc_epm_Map(p, mem_ctx, &r);
144 if (NT_STATUS_IS_OK(status) && r.out.status == 0) {
145 for (i=0;i<r.out.num_towers;i++) {
146 if (r.out.towers[i].twr) {
147 display_tower(mem_ctx, &r.out.towers[i].twr->towers);
152 twr->towers.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
153 twr->towers.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
154 twr->towers.floors[3].rhs.rhs_data = data_blob_talloc(p->mem_ctx, NULL, 2);
156 status = dcerpc_epm_Map(p, mem_ctx, &r);
157 if (NT_STATUS_IS_OK(status) && r.out.status == 0) {
158 for (i=0;i<r.out.num_towers;i++) {
159 if (r.out.towers[i].twr) {
160 display_tower(mem_ctx, &r.out.towers[i].twr->towers);
165 twr->towers.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
166 twr->towers.floors[3].lhs.info.lhs_data = data_blob(NULL, 0);
167 twr->towers.floors[3].rhs.rhs_data = data_blob_talloc(p->mem_ctx, NULL, 2);
169 twr->towers.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
170 twr->towers.floors[4].lhs.info.lhs_data = data_blob(NULL, 0);
171 twr->towers.floors[4].rhs.rhs_data = data_blob_talloc(p->mem_ctx, NULL, 2);
173 status = dcerpc_epm_Map(p, mem_ctx, &r);
174 if (NT_STATUS_IS_OK(status) && r.out.status == 0) {
175 for (i=0;i<r.out.num_towers;i++) {
176 if (r.out.towers[i].twr) {
177 display_tower(mem_ctx, &r.out.towers[i].twr->towers);
185 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
190 struct rpc_if_id_t iface;
191 struct policy_handle handle;
197 r.in.inquiry_type = 0;
199 r.in.interface_id = &iface;
200 r.in.vers_option = 0;
201 r.in.entry_handle = &handle;
202 r.out.entry_handle = &handle;
207 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
208 if (!NT_STATUS_IS_OK(status) || r.out.status != 0) {
211 for (i=0;i<r.out.num_ents;i++) {
212 printf("\nFound '%s'\n", r.out.entries[i].annotation);
213 display_tower(mem_ctx, &r.out.entries[i].tower->towers);
214 test_Map(p, mem_ctx, r.out.entries[i].tower);
216 } while (NT_STATUS_IS_OK(status) &&
218 r.out.num_ents == r.in.max_ents);
220 if (!NT_STATUS_IS_OK(status)) {
221 printf("Lookup failed - %s\n", nt_errstr(status));
229 BOOL torture_rpc_epmapper(int dummy)
232 struct dcerpc_pipe *p;
236 mem_ctx = talloc_init("torture_rpc_epmapper");
238 status = torture_rpc_connection(&p,
239 DCERPC_EPMAPPER_NAME,
240 DCERPC_EPMAPPER_UUID,
241 DCERPC_EPMAPPER_VERSION);
242 if (!NT_STATUS_IS_OK(status)) {
246 p->flags |= DCERPC_DEBUG_PRINT_BOTH;
248 if (!test_Lookup(p, mem_ctx)) {
252 talloc_destroy(mem_ctx);
254 torture_rpc_close(p);