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 "librpc/gen_ndr/ndr_epmapper.h"
27 display any protocol tower
29 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
33 for (i=0;i<twr->num_floors;i++) {
34 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
40 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
41 struct epm_twr_t *twr)
46 struct policy_handle handle;
56 r.in.entry_handle = &handle;
57 r.out.entry_handle = &handle;
58 r.in.max_towers = 100;
60 dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &if_uuid, &if_version);
62 printf("epm_Map results for '%s':\n",
63 idl_pipe_name(&if_uuid, if_version));
65 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
66 twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
67 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
69 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
70 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
71 twr->tower.floors[3].rhs.tcp.port = 0;
73 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
74 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
75 twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
77 status = dcerpc_epm_Map(p, mem_ctx, &r);
78 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
79 for (i=0;i<r.out.num_towers;i++) {
80 if (r.out.towers[i].twr) {
81 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
86 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
87 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
88 twr->tower.floors[3].rhs.http.port = 0;
90 status = dcerpc_epm_Map(p, mem_ctx, &r);
91 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
92 for (i=0;i<r.out.num_towers;i++) {
93 if (r.out.towers[i].twr) {
94 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
99 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
100 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
101 twr->tower.floors[3].rhs.http.port = 0;
103 status = dcerpc_epm_Map(p, mem_ctx, &r);
104 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
105 for (i=0;i<r.out.num_towers;i++) {
106 if (r.out.towers[i].twr) {
107 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
112 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
113 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
114 twr->tower.floors[3].rhs.smb.unc = "";
116 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
117 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
118 twr->tower.floors[4].rhs.netbios.name = "";
120 status = dcerpc_epm_Map(p, mem_ctx, &r);
121 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
122 for (i=0;i<r.out.num_towers;i++) {
123 if (r.out.towers[i].twr) {
124 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
129 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
134 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
139 struct rpc_if_id_t iface;
140 struct policy_handle handle;
144 r.in.inquiry_type = 0;
146 r.in.interface_id = &iface;
147 r.in.vers_option = 0;
148 r.in.entry_handle = &handle;
149 r.out.entry_handle = &handle;
158 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
159 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
163 printf("epm_Lookup returned %d events GUID %s\n",
164 r.out.num_ents, GUID_string(mem_ctx, &handle.uuid));
166 for (i=0;i<r.out.num_ents;i++) {
167 printf("\nFound '%s'\n", r.out.entries[i].annotation);
168 display_tower(mem_ctx, &r.out.entries[i].tower->tower);
169 if (r.out.entries[i].tower->tower.num_floors == 5) {
170 test_Map(p, mem_ctx, r.out.entries[i].tower);
173 } while (NT_STATUS_IS_OK(status) &&
175 r.out.num_ents == r.in.max_ents &&
176 !policy_handle_empty(&handle));
178 if (!NT_STATUS_IS_OK(status)) {
179 printf("Lookup failed - %s\n", nt_errstr(status));
187 static BOOL test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
193 r.in.entries = entries;
195 status = dcerpc_epm_Delete(p, mem_ctx, &r);
196 if (NT_STATUS_IS_ERR(status)) {
197 printf("Delete failed - %s\n", nt_errstr(status));
201 if (r.out.result != 0) {
202 printf("Delete failed - %d\n", r.out.result);
209 static BOOL test_Insert(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
213 struct dcerpc_binding *bd;
217 r.in.entries = talloc_array(mem_ctx, struct epm_entry_t, 1);
218 ZERO_STRUCT(r.in.entries[0].object);
219 r.in.entries[0].annotation = "smbtorture endpoint";
220 status = dcerpc_parse_binding(mem_ctx, "ncalrpc:[SMBTORTURE]", &bd);
221 if (NT_STATUS_IS_ERR(status)) {
222 printf("Unable to generate dcerpc_binding struct\n");
226 r.in.entries[0].tower = talloc(mem_ctx, struct epm_twr_t);
228 status = dcerpc_binding_build_tower(mem_ctx, bd, &r.in.entries[0].tower->tower);
229 if (NT_STATUS_IS_ERR(status)) {
230 printf("Unable to build tower from binding struct\n");
236 status = dcerpc_epm_Insert(p, mem_ctx, &r);
237 if (NT_STATUS_IS_ERR(status)) {
238 printf("Insert failed - %s\n", nt_errstr(status));
242 if (r.out.result != 0) {
243 printf("Insert failed - %d\n", r.out.result);
244 printf("NOT CONSIDERING AS A FAILURE\n");
248 if (!test_Delete(p, mem_ctx, r.in.entries)) {
255 static BOOL test_InqObject(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
258 struct epm_InqObject r;
260 r.in.epm_object = talloc(mem_ctx, struct GUID);
261 *r.in.epm_object = dcerpc_table_epmapper.uuid;
263 status = dcerpc_epm_InqObject(p, mem_ctx, &r);
264 if (NT_STATUS_IS_ERR(status)) {
265 printf("InqObject failed - %s\n", nt_errstr(status));
272 BOOL torture_rpc_epmapper(void)
275 struct dcerpc_pipe *p;
279 mem_ctx = talloc_init("torture_rpc_epmapper");
281 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_epmapper);
282 if (!NT_STATUS_IS_OK(status)) {
283 talloc_free(mem_ctx);
287 if (!test_Lookup(p, mem_ctx)) {
291 if (!test_Insert(p, mem_ctx)) {
295 if (!test_InqObject(p, mem_ctx)) {
299 talloc_free(mem_ctx);