r5209: Fix the endpoint mapper to work with IPX endpoints (which
[Samba/gebeck_regimport.git] / source4 / torture / rpc / epmapper.c
blobeecfdb3f89892695d81f8fc642610094f17791dc
1 /*
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.
22 #include "includes.h"
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)
32 int i;
34 for (i=0;i<twr->num_floors;i++) {
35 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
37 printf("\n");
41 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
42 struct epm_twr_t *twr)
44 NTSTATUS status;
45 struct epm_Map r;
46 struct GUID uuid;
47 const char *uuid_str;
48 struct policy_handle handle;
49 int i;
50 struct GUID if_uuid;
51 uint16_t if_version;
53 ZERO_STRUCT(uuid);
54 ZERO_STRUCT(handle);
56 r.in.object = &uuid;
57 r.in.map_tower = twr;
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) */
134 return True;
137 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
139 NTSTATUS status;
140 struct epm_Lookup r;
141 struct GUID uuid;
142 struct rpc_if_id_t iface;
143 struct policy_handle handle;
145 ZERO_STRUCT(handle);
147 r.in.inquiry_type = 0;
148 r.in.object = &uuid;
149 r.in.interface_id = &iface;
150 r.in.vers_option = 0;
151 r.in.entry_handle = &handle;
152 r.out.entry_handle = &handle;
153 r.in.max_ents = 10;
155 do {
156 int i;
158 ZERO_STRUCT(uuid);
159 ZERO_STRUCT(iface);
161 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
162 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
163 break;
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) &&
177 r.out.result == 0 &&
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));
183 return False;
187 return True;
190 static BOOL test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
192 NTSTATUS status;
193 struct epm_Delete r;
195 r.in.num_ents = 1;
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));
201 return False;
204 if (r.out.result != 0) {
205 printf("Delete failed - %d\n", r.out.result);
206 return False;
209 return True;
212 static BOOL test_Insert(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
214 NTSTATUS status;
215 struct epm_Insert r;
216 struct dcerpc_binding bd;
218 r.in.num_ents = 1;
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");
226 return False;
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");
234 return False;
237 r.in.replace = 0;
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));
242 return False;
245 if (r.out.result != 0) {
246 printf("Insert failed - %d\n", r.out.result);
247 printf("NOT CONSIDERING AS A FAILURE\n");
248 return True;
251 if (!test_Delete(p, mem_ctx, r.in.entries)) {
252 return False;
255 return True;
258 static BOOL test_InqObject(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
260 NTSTATUS status;
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));
269 return False;
272 return True;
275 BOOL torture_rpc_epmapper(void)
277 NTSTATUS status;
278 struct dcerpc_pipe *p;
279 TALLOC_CTX *mem_ctx;
280 BOOL ret = True;
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)) {
289 return False;
292 if (!test_Lookup(p, mem_ctx)) {
293 ret = False;
296 if (!test_Insert(p, mem_ctx)) {
297 ret = False;
300 if (!test_InqObject(p, mem_ctx)) {
301 ret = False;
304 talloc_free(mem_ctx);
306 torture_rpc_close(p);
308 return ret;