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.h"
25 #include "librpc/rpc/dcerpc_table.h"
29 display any protocol tower
31 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
35 for (i=0;i<twr->num_floors;i++) {
36 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
42 static BOOL test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
43 struct epm_twr_t *twr)
48 struct policy_handle handle;
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);
64 printf("epm_Map results for '%s':\n",
65 idl_pipe_name(&if_uuid, if_version));
67 twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
68 twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
69 twr->tower.floors[2].rhs.ncacn.minor_version = 0;
71 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
72 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
73 twr->tower.floors[3].rhs.tcp.port = 0;
75 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
76 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
77 twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
79 status = dcerpc_epm_Map(p, mem_ctx, &r);
80 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
81 for (i=0;i<r.out.num_towers;i++) {
82 if (r.out.towers[i].twr) {
83 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
88 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
89 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
90 twr->tower.floors[3].rhs.http.port = 0;
92 status = dcerpc_epm_Map(p, mem_ctx, &r);
93 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
94 for (i=0;i<r.out.num_towers;i++) {
95 if (r.out.towers[i].twr) {
96 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
101 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
102 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
103 twr->tower.floors[3].rhs.http.port = 0;
105 status = dcerpc_epm_Map(p, mem_ctx, &r);
106 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
107 for (i=0;i<r.out.num_towers;i++) {
108 if (r.out.towers[i].twr) {
109 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
114 twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
115 twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
116 twr->tower.floors[3].rhs.smb.unc = "";
118 twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
119 twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
120 twr->tower.floors[4].rhs.netbios.name = "";
122 status = dcerpc_epm_Map(p, mem_ctx, &r);
123 if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
124 for (i=0;i<r.out.num_towers;i++) {
125 if (r.out.towers[i].twr) {
126 display_tower(mem_ctx, &r.out.towers[i].twr->tower);
131 /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
136 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
141 struct rpc_if_id_t iface;
142 struct policy_handle handle;
146 r.in.inquiry_type = 0;
148 r.in.interface_id = &iface;
149 r.in.vers_option = 0;
150 r.in.entry_handle = &handle;
151 r.out.entry_handle = &handle;
160 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
161 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
165 printf("epm_Lookup returned %d events GUID %s\n",
166 r.out.num_ents, GUID_string(mem_ctx, &handle.uuid));
168 for (i=0;i<r.out.num_ents;i++) {
169 printf("\nFound '%s'\n", r.out.entries[i].annotation);
170 display_tower(mem_ctx, &r.out.entries[i].tower->tower);
171 if (r.out.entries[i].tower->tower.num_floors == 5) {
172 test_Map(p, mem_ctx, r.out.entries[i].tower);
175 } while (NT_STATUS_IS_OK(status) &&
177 r.out.num_ents == r.in.max_ents &&
178 !policy_handle_empty(&handle));
180 if (!NT_STATUS_IS_OK(status)) {
181 printf("Lookup failed - %s\n", nt_errstr(status));
189 static BOOL test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
195 r.in.entries = entries;
197 status = dcerpc_epm_Delete(p, mem_ctx, &r);
198 if (NT_STATUS_IS_ERR(status)) {
199 printf("Delete failed - %s\n", nt_errstr(status));
203 if (r.out.result != 0) {
204 printf("Delete failed - %d\n", r.out.result);
211 static BOOL test_Insert(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
215 struct dcerpc_binding *bd;
219 r.in.entries = talloc_array(mem_ctx, struct epm_entry_t, 1);
220 ZERO_STRUCT(r.in.entries[0].object);
221 r.in.entries[0].annotation = "smbtorture endpoint";
222 status = dcerpc_parse_binding(mem_ctx, "ncalrpc:[SMBTORTURE]", &bd);
223 if (NT_STATUS_IS_ERR(status)) {
224 printf("Unable to generate dcerpc_binding struct\n");
228 r.in.entries[0].tower = talloc(mem_ctx, struct epm_twr_t);
230 status = dcerpc_binding_build_tower(mem_ctx, bd, &r.in.entries[0].tower->tower);
231 if (NT_STATUS_IS_ERR(status)) {
232 printf("Unable to build tower from binding struct\n");
238 status = dcerpc_epm_Insert(p, mem_ctx, &r);
239 if (NT_STATUS_IS_ERR(status)) {
240 printf("Insert failed - %s\n", nt_errstr(status));
244 if (r.out.result != 0) {
245 printf("Insert failed - %d\n", r.out.result);
246 printf("NOT CONSIDERING AS A FAILURE\n");
250 if (!test_Delete(p, mem_ctx, r.in.entries)) {
257 static BOOL test_InqObject(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
260 struct epm_InqObject r;
262 r.in.epm_object = talloc(mem_ctx, struct GUID);
263 *r.in.epm_object = dcerpc_table_epmapper.uuid;
265 status = dcerpc_epm_InqObject(p, mem_ctx, &r);
266 if (NT_STATUS_IS_ERR(status)) {
267 printf("InqObject failed - %s\n", nt_errstr(status));
274 BOOL torture_rpc_epmapper(void)
277 struct dcerpc_pipe *p;
281 mem_ctx = talloc_init("torture_rpc_epmapper");
283 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_epmapper);
284 if (!NT_STATUS_IS_OK(status)) {
285 talloc_free(mem_ctx);
289 if (!test_Lookup(p, mem_ctx)) {
293 if (!test_Insert(p, mem_ctx)) {
297 if (!test_InqObject(p, mem_ctx)) {
301 talloc_free(mem_ctx);