r25554: Convert last instances of BOOL, True and False to the standard types.
[garming/samba-autobuild/.git] / source4 / torture / rpc / epmapper.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for epmapper rpc operations
4
5    Copyright (C) Andrew Tridgell 2003
6    
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.
11    
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.
16    
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/>.
19 */
20
21 #include "includes.h"
22 #include "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_epmapper_c.h"
24 #include "librpc/ndr/ndr_table.h"
25 #include "torture/rpc/rpc.h"
26
27
28 /*
29   display any protocol tower
30  */
31 static void display_tower(TALLOC_CTX *mem_ctx, struct epm_tower *twr)
32 {
33         int i;
34
35         for (i=0;i<twr->num_floors;i++) {
36                 printf(" %s", epm_floor_string(mem_ctx, &twr->floors[i]));
37         }
38         printf("\n");
39 }
40
41
42 static bool test_Map(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
43                      struct epm_twr_t *twr)
44 {
45         NTSTATUS status;
46         struct epm_Map r;
47         struct GUID uuid;
48         struct policy_handle handle;
49         int i;
50         struct ndr_syntax_id syntax;
51         uint32_t num_towers;
52
53         ZERO_STRUCT(uuid);
54         ZERO_STRUCT(handle);
55
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;
61         r.out.num_towers = &num_towers;
62
63         dcerpc_floor_get_lhs_data(&twr->tower.floors[0], &syntax);
64
65         printf("epm_Map results for '%s':\n", 
66                ndr_interface_name(&syntax.uuid, syntax.if_version));
67
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;
71
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;
75
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";
79
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);
85                         }
86                 }
87         }
88
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;
92
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);
98                         }
99                 }
100         }
101
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;
105
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);
111                         }
112                 }
113         }
114
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 = "";
118
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 = "";
122
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);
128                         }
129                 }
130         }
131
132         /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
133         
134         return true;
135 }
136
137 static bool test_Lookup(struct torture_context *tctx, 
138                                                 struct dcerpc_pipe *p)
139 {
140         NTSTATUS status;
141         struct epm_Lookup r;
142         struct GUID uuid;
143         struct rpc_if_id_t iface;
144         struct policy_handle handle;
145         uint32_t num_ents;
146
147         ZERO_STRUCT(handle);
148
149         r.in.inquiry_type = 0;
150         r.in.object = &uuid;
151         r.in.interface_id = &iface;
152         r.in.vers_option = 0;
153         r.in.entry_handle = &handle;
154         r.out.entry_handle = &handle;
155         r.in.max_ents = 10;
156         r.out.num_ents = &num_ents;
157
158         do {
159                 int i;
160
161                 ZERO_STRUCT(uuid);
162                 ZERO_STRUCT(iface);
163
164                 status = dcerpc_epm_Lookup(p, tctx, &r);
165                 if (!NT_STATUS_IS_OK(status) || r.out.result != 0) {
166                         break;
167                 }
168
169                 printf("epm_Lookup returned %d events GUID %s\n", 
170                        *r.out.num_ents, GUID_string(tctx, &handle.uuid));
171
172                 for (i=0;i<*r.out.num_ents;i++) {
173                         printf("\nFound '%s'\n", r.out.entries[i].annotation);
174                         display_tower(tctx, &r.out.entries[i].tower->tower);
175                         if (r.out.entries[i].tower->tower.num_floors == 5) {
176                                 test_Map(p, tctx, r.out.entries[i].tower);
177                         }
178                 }
179         } while (NT_STATUS_IS_OK(status) && 
180                  r.out.result == 0 && 
181                  *r.out.num_ents == r.in.max_ents &&
182                  !policy_handle_empty(&handle));
183
184         torture_assert_ntstatus_ok(tctx, status, "Lookup failed");
185
186         return true;
187 }
188
189 static bool test_Delete(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct epm_entry_t *entries)
190 {
191         NTSTATUS status;
192         struct epm_Delete r;
193
194         r.in.num_ents = 1;
195         r.in.entries = entries;
196         
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));
200                 return false;
201         }
202
203         if (r.out.result != 0) {
204                 printf("Delete failed - %d\n", r.out.result);
205                 return false;
206         }
207
208         return true;
209 }
210
211 static bool test_Insert(struct torture_context *tctx, 
212                                                 struct dcerpc_pipe *p)
213 {
214         NTSTATUS status;
215         struct epm_Insert r;
216         struct dcerpc_binding *bd;
217
218         r.in.num_ents = 1;
219
220         r.in.entries = talloc_array(tctx, 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(tctx, "ncalrpc:[SMBTORTURE]", &bd);
224         torture_assert_ntstatus_ok(tctx, status, 
225                                                            "Unable to generate dcerpc_binding struct");
226
227         r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
228
229         status = dcerpc_binding_build_tower(tctx, bd, &r.in.entries[0].tower->tower);
230         torture_assert_ntstatus_ok(tctx, status, 
231                                                            "Unable to build tower from binding struct");
232         
233         r.in.replace = 0;
234
235         status = dcerpc_epm_Insert(p, tctx, &r);
236         torture_assert_ntstatus_ok(tctx, status, "Insert failed");
237
238         torture_assert(tctx, r.out.result == 0, "Insert failed");
239
240         if (!test_Delete(p, tctx, r.in.entries)) {
241                 return false; 
242         }
243
244         return true;
245 }
246
247 static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p)
248 {
249         NTSTATUS status;
250         struct epm_InqObject r;
251
252         r.in.epm_object = talloc(tctx, struct GUID);
253         *r.in.epm_object = ndr_table_epmapper.syntax_id.uuid;
254
255         status = dcerpc_epm_InqObject(p, tctx, &r);
256         torture_assert_ntstatus_ok(tctx, status, "InqObject failed");
257
258         return true;
259 }
260
261 struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
262 {
263         struct torture_suite *suite = torture_suite_create(mem_ctx, "EPMAPPER");
264         struct torture_rpc_tcase *tcase;
265         
266         tcase = torture_suite_add_rpc_iface_tcase(suite, "epmapper", 
267                                                                                           &ndr_table_epmapper);
268
269         torture_rpc_tcase_add_test(tcase, "Lookup", test_Lookup);
270
271         torture_rpc_tcase_add_test(tcase, "Insert", test_Insert);
272
273         torture_rpc_tcase_add_test(tcase, "InqObject", test_InqObject);
274
275         return suite;
276 }