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 "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_epmapper_c.h"
25 #include "librpc/rpc/dcerpc_table.h"
26 #include "torture/rpc/rpc.h"
30 display any protocol tower
32 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
36 for (i=0;i<twr->num_floors;i++) {
37 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
43 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
44 struct epm_twr_t *twr)
49 struct policy_handle handle;
51 struct dcerpc_syntax_id syntax;
59 r.in.entry_handle = &handle;
60 r.out.entry_handle = &handle;
61 r.in.max_towers = 100;
62 r.out.num_towers = &num_towers;
64 dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &syntax);
66 printf("epm_Map results for '%s':\n",
67 idl_pipe_name(&syntax.uuid, syntax.if_version));
69 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
70 twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
71 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
73 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
74 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
75 twr->tower.floors[3].rhs.tcp.port = 0;
77 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
78 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
79 twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
81 status = dcerpc_epm_Map(p, mem_ctx, &r);
82 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
83 for (i=0;i<*r.out.num_towers;i++) {
84 if (r.out.towers[i].twr) {
85 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
90 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
91 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
92 twr->tower.floors[3].rhs.http.port = 0;
94 status = dcerpc_epm_Map(p, mem_ctx, &r);
95 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
96 for (i=0;i<*r.out.num_towers;i++) {
97 if (r.out.towers[i].twr) {
98 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
103 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
104 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
105 twr->tower.floors[3].rhs.http.port = 0;
107 status = dcerpc_epm_Map(p, mem_ctx, &r);
108 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
109 for (i=0;i<*r.out.num_towers;i++) {
110 if (r.out.towers[i].twr) {
111 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
116 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
117 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
118 twr->tower.floors[3].rhs.smb.unc = "";
120 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
121 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
122 twr->tower.floors[4].rhs.netbios.name = "";
124 status = dcerpc_epm_Map(p, mem_ctx, &r);
125 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
126 for (i=0;i<*r.out.num_towers;i++) {
127 if (r.out.towers[i].twr) {
128 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
133 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
138 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
143 struct rpc_if_id_t iface;
144 struct policy_handle handle;
149 r.in.inquiry_type = 0;
151 r.in.interface_id = &iface;
152 r.in.vers_option = 0;
153 r.in.entry_handle = &handle;
154 r.out.entry_handle = &handle;
156 r.out.num_ents = &num_ents;
164 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
165 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
169 printf("epm_Lookup returned %d events GUID %s\n",
170 *r.out.num_ents, GUID_string(mem_ctx, &handle.uuid));
172 for (i=0;i<*r.out.num_ents;i++) {
173 printf("\nFound '%s'\n", r.out.entries[i].annotation);
174 display_tower(mem_ctx, &r.out.entries[i].tower->tower);
175 if (r.out.entries[i].tower->tower.num_floors == 5) {
176 test_Map(p, mem_ctx, r.out.entries[i].tower);
179 } while (NT_STATUS_IS_OK(status) &&
181 *r.out.num_ents == r.in.max_ents &&
182 !policy_handle_empty(&handle));
184 if (!NT_STATUS_IS_OK(status)) {
185 printf("Lookup failed - %s\n", nt_errstr(status));
193 static BOOL test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
199 r.in.entries = entries;
201 status = dcerpc_epm_Delete(p, mem_ctx, &r);
202 if (NT_STATUS_IS_ERR(status)) {
203 printf("Delete failed - %s\n", nt_errstr(status));
207 if (r.out.result != 0) {
208 printf("Delete failed - %d\n", r.out.result);
215 static BOOL test_Insert(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
219 struct dcerpc_binding *bd;
223 r.in.entries = talloc_array(mem_ctx, struct epm_entry_t, 1);
224 ZERO_STRUCT(r.in.entries[0].object);
225 r.in.entries[0].annotation = "smbtorture endpoint";
226 status = dcerpc_parse_binding(mem_ctx, "ncalrpc:[SMBTORTURE]", &bd);
227 if (NT_STATUS_IS_ERR(status)) {
228 printf("Unable to generate dcerpc_binding struct\n");
232 r.in.entries[0].tower = talloc(mem_ctx, struct epm_twr_t);
234 status = dcerpc_binding_build_tower(mem_ctx, bd, &r.in.entries[0].tower->tower);
235 if (NT_STATUS_IS_ERR(status)) {
236 printf("Unable to build tower from binding struct\n");
242 status = dcerpc_epm_Insert(p, mem_ctx, &r);
243 if (NT_STATUS_IS_ERR(status)) {
244 printf("Insert failed - %s\n", nt_errstr(status));
248 if (r.out.result != 0) {
249 printf("Insert failed - %d\n", r.out.result);
250 printf("NOT CONSIDERING AS A FAILURE\n");
254 if (!test_Delete(p, mem_ctx, r.in.entries)) {
261 static BOOL test_InqObject(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
264 struct epm_InqObject r;
266 r.in.epm_object = talloc(mem_ctx, struct GUID);
267 *r.in.epm_object = dcerpc_table_epmapper.syntax_id.uuid;
269 status = dcerpc_epm_InqObject(p, mem_ctx, &r);
270 if (NT_STATUS_IS_ERR(status)) {
271 printf("InqObject failed - %s\n", nt_errstr(status));
278 BOOL torture_rpc_epmapper(struct torture_context *torture)
281 struct dcerpc_pipe *p;
285 mem_ctx = talloc_init("torture_rpc_epmapper");
287 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_epmapper);
288 if (!NT_STATUS_IS_OK(status)) {
289 talloc_free(mem_ctx);
293 if (!test_Lookup(p, mem_ctx)) {
297 if (!test_Insert(p, mem_ctx)) {
301 if (!test_InqObject(p, mem_ctx)) {
305 talloc_free(mem_ctx);