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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_epmapper_c.h"
24 #include "librpc/rpc/dcerpc_table.h"
25 #include "torture/rpc/rpc.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;
50 struct dcerpc_syntax_id syntax;
58 r.in.entry_handle = &handle;
59 r.out.entry_handle = &handle;
60 r.in.max_towers = 100;
61 r.out.num_towers = &num_towers;
63 dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &syntax);
65 printf("epm_Map results for '%s':\n",
66 idl_pipe_name(&syntax.uuid, syntax.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) */
137 static BOOL test_Lookup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
142 struct rpc_if_id_t iface;
143 struct policy_handle handle;
148 r.in.inquiry_type = 0;
150 r.in.interface_id = &iface;
151 r.in.vers_option = 0;
152 r.in.entry_handle = &handle;
153 r.out.entry_handle = &handle;
155 r.out.num_ents = &num_ents;
163 status = dcerpc_epm_Lookup(p, mem_ctx, &r);
164 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
168 printf("epm_Lookup returned %d events GUID %s\n",
169 *r.out.num_ents, GUID_string(mem_ctx, &handle.uuid));
171 for (i=0;i<*r.out.num_ents;i++) {
172 printf("\nFound '%s'\n", r.out.entries[i].annotation);
173 display_tower(mem_ctx, &r.out.entries[i].tower->tower);
174 if (r.out.entries[i].tower->tower.num_floors == 5) {
175 test_Map(p, mem_ctx, r.out.entries[i].tower);
178 } while (NT_STATUS_IS_OK(status) &&
180 *r.out.num_ents == r.in.max_ents &&
181 !policy_handle_empty(&handle));
183 if (!NT_STATUS_IS_OK(status)) {
184 printf("Lookup failed - %s\n", nt_errstr(status));
192 static BOOL test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
198 r.in.entries = entries;
200 status = dcerpc_epm_Delete(p, mem_ctx, &r);
201 if (NT_STATUS_IS_ERR(status)) {
202 printf("Delete failed - %s\n", nt_errstr(status));
206 if (r.out.result != 0) {
207 printf("Delete failed - %d\n", r.out.result);
214 static BOOL test_Insert(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
218 struct dcerpc_binding *bd;
222 r.in.entries = talloc_array(mem_ctx, struct epm_entry_t, 1);
223 ZERO_STRUCT(r.in.entries[0].object);
224 r.in.entries[0].annotation = "smbtorture endpoint";
225 status = dcerpc_parse_binding(mem_ctx, "ncalrpc:[SMBTORTURE]", &bd);
226 if (NT_STATUS_IS_ERR(status)) {
227 printf("Unable to generate dcerpc_binding struct\n");
231 r.in.entries[0].tower = talloc(mem_ctx, struct epm_twr_t);
233 status = dcerpc_binding_build_tower(mem_ctx, bd, &r.in.entries[0].tower->tower);
234 if (NT_STATUS_IS_ERR(status)) {
235 printf("Unable to build tower from binding struct\n");
241 status = dcerpc_epm_Insert(p, mem_ctx, &r);
242 if (NT_STATUS_IS_ERR(status)) {
243 printf("Insert failed - %s\n", nt_errstr(status));
247 if (r.out.result != 0) {
248 printf("Insert failed - %d\n", r.out.result);
249 printf("NOT CONSIDERING AS A FAILURE\n");
253 if (!test_Delete(p, mem_ctx, r.in.entries)) {
260 static BOOL test_InqObject(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
263 struct epm_InqObject r;
265 r.in.epm_object = talloc(mem_ctx, struct GUID);
266 *r.in.epm_object = dcerpc_table_epmapper.syntax_id.uuid;
268 status = dcerpc_epm_InqObject(p, mem_ctx, &r);
269 if (NT_STATUS_IS_ERR(status)) {
270 printf("InqObject failed - %s\n", nt_errstr(status));
277 BOOL torture_rpc_epmapper(struct torture_context *torture)
280 struct dcerpc_pipe *p;
284 mem_ctx = talloc_init("torture_rpc_epmapper");
286 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_epmapper);
287 if (!NT_STATUS_IS_OK(status)) {
288 talloc_free(mem_ctx);
292 if (!test_Lookup(p, mem_ctx)) {
296 if (!test_Insert(p, mem_ctx)) {
300 if (!test_InqObject(p, mem_ctx)) {
304 talloc_free(mem_ctx);