Line data Source code
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 "librpc/gen_ndr/ndr_epmapper_c.h"
23 : #include "librpc/ndr/ndr_table.h"
24 : #include "librpc/rpc/dcerpc_proto.h"
25 : #include "torture/rpc/torture_rpc.h"
26 : #include "lib/util/util_net.h"
27 : #include "librpc/rpc/rpc_common.h"
28 :
29 : /*
30 : display any protocol tower
31 : */
32 890 : static void display_tower(struct torture_context *tctx, struct epm_tower *twr)
33 : {
34 0 : int i;
35 :
36 5282 : for (i = 0; i < twr->num_floors; i++) {
37 4392 : torture_comment(tctx,
38 : " %s",
39 4392 : epm_floor_string(tctx, &twr->floors[i]));
40 : }
41 890 : torture_comment(tctx, "\n");
42 890 : }
43 :
44 5 : static bool test_Insert(struct torture_context *tctx,
45 : struct dcerpc_binding_handle *h,
46 : struct ndr_syntax_id object,
47 : const char *annotation,
48 : const struct dcerpc_binding *b)
49 : {
50 0 : struct epm_Insert r;
51 0 : NTSTATUS status;
52 :
53 5 : r.in.num_ents = 1;
54 5 : r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
55 :
56 5 : if (torture_setting_bool(tctx, "samba4", false)) {
57 3 : torture_skip(tctx, "Skip Insert test against Samba4");
58 : }
59 :
60 : /* FIXME zero */
61 2 : ZERO_STRUCT(r.in.entries[0].object);
62 2 : r.in.entries[0].annotation = annotation;
63 :
64 2 : r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
65 :
66 2 : status = dcerpc_binding_build_tower(tctx,
67 : b,
68 2 : &r.in.entries[0].tower->tower);
69 :
70 2 : torture_assert_ntstatus_ok(tctx,
71 : status,
72 : "Unable to build tower from binding struct");
73 2 : r.in.replace = 0;
74 :
75 : /* shoot! */
76 2 : status = dcerpc_epm_Insert_r(h, tctx, &r);
77 :
78 2 : if (NT_STATUS_IS_ERR(status)) {
79 2 : torture_comment(tctx,
80 : "epm_Insert failed - %s\n",
81 : nt_errstr(status));
82 2 : return false;
83 : }
84 :
85 0 : if (r.out.result != EPMAPPER_STATUS_OK) {
86 0 : torture_comment(tctx,
87 : "epm_Insert failed - internal error: 0x%.4x\n",
88 : r.out.result);
89 0 : return false;
90 : }
91 :
92 0 : return true;
93 : }
94 :
95 0 : static bool test_Delete(struct torture_context *tctx,
96 : struct dcerpc_binding_handle *h,
97 : const char *annotation,
98 : const struct dcerpc_binding *b)
99 : {
100 0 : NTSTATUS status;
101 0 : struct epm_Delete r;
102 :
103 0 : r.in.num_ents = 1;
104 0 : r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
105 :
106 0 : ZERO_STRUCT(r.in.entries[0].object);
107 0 : r.in.entries[0].annotation = annotation;
108 :
109 0 : r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
110 :
111 0 : status = dcerpc_binding_build_tower(tctx,
112 : b,
113 0 : &r.in.entries[0].tower->tower);
114 :
115 0 : torture_assert_ntstatus_ok(tctx,
116 : status,
117 : "Unable to build tower from binding struct");
118 0 : r.in.num_ents = 1;
119 :
120 0 : status = dcerpc_epm_Delete_r(h, tctx, &r);
121 0 : if (NT_STATUS_IS_ERR(status)) {
122 0 : torture_comment(tctx,
123 : "epm_Delete failed - %s\n",
124 : nt_errstr(status));
125 0 : return false;
126 : }
127 :
128 0 : if (r.out.result != EPMAPPER_STATUS_OK) {
129 0 : torture_comment(tctx,
130 : "epm_Delete failed - internal error: 0x%.4x\n",
131 : r.out.result);
132 0 : return false;
133 : }
134 :
135 0 : return true;
136 : }
137 :
138 3 : static bool test_Map_tcpip(struct torture_context *tctx,
139 : struct dcerpc_binding_handle *h,
140 : struct ndr_syntax_id map_syntax)
141 : {
142 0 : struct epm_Map r;
143 0 : struct GUID uuid;
144 0 : struct policy_handle entry_handle;
145 0 : struct ndr_syntax_id syntax;
146 0 : struct dcerpc_binding *map_binding;
147 0 : struct epm_twr_t map_tower;
148 0 : struct epm_twr_p_t towers[20];
149 0 : struct epm_tower t;
150 0 : uint32_t num_towers;
151 0 : uint32_t port;
152 0 : uint32_t i;
153 0 : long int p;
154 0 : const char *tmp;
155 0 : const char *ip;
156 0 : char *ptr;
157 0 : NTSTATUS status;
158 :
159 3 : torture_comment(tctx, "Testing epm_Map\n");
160 :
161 3 : ZERO_STRUCT(uuid);
162 3 : ZERO_STRUCT(entry_handle);
163 :
164 3 : r.in.object = &uuid;
165 3 : r.in.map_tower = &map_tower;
166 3 : r.in.entry_handle = &entry_handle;
167 3 : r.out.entry_handle = &entry_handle;
168 3 : r.in.max_towers = 10;
169 3 : r.out.towers = towers;
170 3 : r.out.num_towers = &num_towers;
171 :
172 : /* Create map tower */
173 3 : status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:[135]", &map_binding);
174 3 : torture_assert_ntstatus_ok(tctx, status,
175 : "epm_Map_tcpip failed: can't create map_binding");
176 :
177 3 : status = dcerpc_binding_set_abstract_syntax(map_binding, &map_syntax);
178 3 : torture_assert_ntstatus_ok(tctx, status,
179 : "epm_Map_tcpip failed: set map_syntax");
180 :
181 3 : status = dcerpc_binding_build_tower(tctx, map_binding,
182 : &map_tower.tower);
183 3 : torture_assert_ntstatus_ok(tctx, status,
184 : "epm_Map_tcpip failed: can't create map_tower");
185 :
186 3 : torture_comment(tctx,
187 : "epm_Map request for '%s':\n",
188 : ndr_interface_name(&map_syntax.uuid, map_syntax.if_version));
189 3 : display_tower(tctx, &r.in.map_tower->tower);
190 :
191 3 : status = dcerpc_epm_Map_r(h, tctx, &r);
192 :
193 3 : torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
194 3 : torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK,
195 : "epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK");
196 :
197 : /* Check the result */
198 0 : t = r.out.towers[0].twr->tower;
199 :
200 : /* Check if we got the correct RPC interface identifier */
201 0 : dcerpc_floor_get_uuid_full(&t.floors[0], &syntax);
202 0 : torture_assert(tctx, ndr_syntax_id_equal(&syntax, &map_syntax),
203 : "epm_Map_tcpip failed: Interface identifier mismatch");
204 :
205 0 : torture_comment(tctx,
206 : "epm_Map_tcpip response for '%s':\n",
207 : ndr_interface_name(&syntax.uuid, syntax.if_version));
208 :
209 0 : dcerpc_floor_get_uuid_full(&t.floors[1], &syntax);
210 0 : torture_assert(tctx, ndr_syntax_id_equal(&syntax, &ndr_transfer_syntax_ndr),
211 : "epm_Map_tcpip failed: floor 2 is not NDR encoded");
212 :
213 0 : torture_assert(tctx, t.floors[2].lhs.protocol == EPM_PROTOCOL_NCACN,
214 : "epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP");
215 :
216 0 : tmp = dcerpc_floor_get_rhs_data(tctx, &t.floors[3]);
217 0 : p = strtol(tmp, &ptr, 10);
218 0 : port = p & 0xffff;
219 0 : torture_assert(tctx, port > 1024 && port < 65535, "epm_Map_tcpip failed");
220 :
221 0 : ip = dcerpc_floor_get_rhs_data(tctx, &t.floors[4]);
222 0 : torture_assert(tctx, is_ipaddress(ip), "epm_Map_tcpip failed");
223 :
224 0 : for (i = 0; i < *r.out.num_towers; i++) {
225 0 : if (r.out.towers[i].twr) {
226 0 : display_tower(tctx, &t);
227 : }
228 : }
229 :
230 0 : return true;
231 : }
232 :
233 5 : static bool test_Map_full(struct torture_context *tctx,
234 : struct dcerpc_pipe *p)
235 : {
236 5 : const struct ndr_syntax_id obj = {
237 : { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
238 : 2
239 : };
240 5 : struct dcerpc_binding_handle *h = p->binding_handle;
241 5 : const char *annotation = "SMBTORTURE";
242 0 : struct dcerpc_binding *b;
243 0 : NTSTATUS status;
244 0 : bool ok;
245 :
246 5 : status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:216.83.154.106[41768]", &b);
247 5 : torture_assert_ntstatus_ok(tctx,
248 : status,
249 : "Unable to generate dcerpc_binding struct");
250 5 : status = dcerpc_binding_set_abstract_syntax(b, &obj);
251 5 : torture_assert_ntstatus_ok(tctx, status, "dcerpc_binding_set_abstract_syntax");
252 :
253 5 : ok = test_Insert(tctx, h, obj, annotation, b);
254 5 : torture_assert(tctx, ok, "test_Insert failed");
255 :
256 3 : ok = test_Map_tcpip(tctx, h, obj);
257 3 : torture_assert(tctx, ok, "test_Map_tcpip failed");
258 :
259 0 : ok = test_Delete(tctx, h, annotation, b);
260 0 : torture_assert(tctx, ok, "test_Delete failed");
261 :
262 0 : return true;
263 : }
264 :
265 190 : static bool test_Map_display(struct dcerpc_binding_handle *b,
266 : struct torture_context *tctx,
267 : struct epm_entry_t *entry)
268 :
269 : {
270 0 : NTSTATUS status;
271 190 : struct epm_twr_t *twr = entry->tower;
272 0 : struct epm_Map r;
273 190 : struct GUID uuid = entry->object;
274 0 : struct policy_handle handle;
275 0 : struct ndr_syntax_id syntax;
276 0 : uint32_t num_towers;
277 0 : uint32_t i;
278 :
279 190 : ZERO_STRUCT(handle);
280 :
281 190 : r.in.object = &uuid;
282 190 : r.in.map_tower = twr;
283 190 : r.in.entry_handle = &handle;
284 190 : r.out.entry_handle = &handle;
285 190 : r.in.max_towers = 10;
286 190 : r.out.num_towers = &num_towers;
287 :
288 190 : dcerpc_floor_get_uuid_full(&twr->tower.floors[0], &syntax);
289 :
290 190 : torture_comment(tctx,
291 : "epm_Map results for '%s':\n",
292 : ndr_interface_name(&syntax.uuid, syntax.if_version));
293 :
294 190 : status = dcerpc_epm_Map_r(b, tctx, &r);
295 190 : if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
296 392 : for (i=0;i<*r.out.num_towers;i++) {
297 202 : if (r.out.towers[i].twr) {
298 202 : display_tower(tctx, &r.out.towers[i].twr->tower);
299 : }
300 : }
301 : }
302 :
303 : /* RPC protocol identifier */
304 190 : twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN;
305 190 : twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0);
306 190 : twr->tower.floors[2].rhs.ncacn.minor_version = 0;
307 :
308 : /* Port address */
309 190 : twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP;
310 190 : twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
311 190 : twr->tower.floors[3].rhs.tcp.port = 0;
312 :
313 : /* Transport */
314 190 : twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP;
315 190 : twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
316 190 : twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0";
317 :
318 190 : status = dcerpc_epm_Map_r(b, tctx, &r);
319 190 : if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
320 348 : for (i=0;i<*r.out.num_towers;i++) {
321 174 : if (r.out.towers[i].twr) {
322 174 : display_tower(tctx, &r.out.towers[i].twr->tower);
323 : }
324 : }
325 : }
326 :
327 190 : twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP;
328 190 : twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
329 190 : twr->tower.floors[3].rhs.http.port = 0;
330 :
331 190 : status = dcerpc_epm_Map_r(b, tctx, &r);
332 190 : if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
333 120 : for (i=0;i<*r.out.num_towers;i++) {
334 60 : if (r.out.towers[i].twr) {
335 60 : display_tower(tctx, &r.out.towers[i].twr->tower);
336 : }
337 : }
338 : }
339 :
340 190 : twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP;
341 190 : twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
342 190 : twr->tower.floors[3].rhs.udp.port = 0;
343 :
344 190 : status = dcerpc_epm_Map_r(b, tctx, &r);
345 190 : if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
346 0 : for (i=0;i<*r.out.num_towers;i++) {
347 0 : if (r.out.towers[i].twr) {
348 0 : display_tower(tctx, &r.out.towers[i].twr->tower);
349 : }
350 : }
351 : }
352 :
353 190 : twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB;
354 190 : twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0);
355 190 : twr->tower.floors[3].rhs.smb.unc = "";
356 :
357 190 : twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS;
358 190 : twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0);
359 190 : twr->tower.floors[4].rhs.netbios.name = "";
360 :
361 190 : status = dcerpc_epm_Map_r(b, tctx, &r);
362 190 : if (NT_STATUS_IS_OK(status) && r.out.result == 0) {
363 390 : for (i = 0; i < *r.out.num_towers; i++) {
364 203 : if (r.out.towers[i].twr) {
365 203 : display_tower(tctx, &r.out.towers[i].twr->tower);
366 : }
367 : }
368 : }
369 :
370 : /* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */
371 :
372 190 : return true;
373 : }
374 :
375 5 : static bool test_Map_simple(struct torture_context *tctx,
376 : struct dcerpc_pipe *p)
377 : {
378 0 : NTSTATUS status;
379 0 : struct epm_Lookup r;
380 0 : struct policy_handle entry_handle;
381 5 : uint32_t num_ents = 0;
382 5 : struct dcerpc_binding_handle *h = p->binding_handle;
383 :
384 5 : ZERO_STRUCT(entry_handle);
385 :
386 5 : torture_comment(tctx, "Testing epm_Map\n");
387 :
388 : /* get all elements */
389 5 : r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
390 5 : r.in.object = NULL;
391 5 : r.in.interface_id = NULL;
392 5 : r.in.vers_option = RPC_C_VERS_ALL;
393 :
394 5 : r.in.entry_handle = &entry_handle;
395 5 : r.in.max_ents = 10;
396 :
397 5 : r.out.entry_handle = &entry_handle;
398 5 : r.out.num_ents = &num_ents;
399 :
400 0 : do {
401 0 : int i;
402 :
403 28 : status = dcerpc_epm_Lookup_r(h, tctx, &r);
404 28 : if (!NT_STATUS_IS_OK(status) ||
405 28 : r.out.result != EPMAPPER_STATUS_OK) {
406 : break;
407 : }
408 :
409 274 : for (i = 0; i < *r.out.num_ents; i++) {
410 248 : if (r.out.entries[i].tower->tower.num_floors == 5) {
411 190 : test_Map_display(h, tctx, &r.out.entries[i]);
412 : }
413 : }
414 52 : } while (NT_STATUS_IS_OK(status) &&
415 26 : r.out.result == EPMAPPER_STATUS_OK &&
416 52 : *r.out.num_ents == r.in.max_ents &&
417 23 : !ndr_policy_handle_empty(&entry_handle));
418 :
419 5 : torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed");
420 :
421 5 : torture_assert(tctx,
422 : ndr_policy_handle_empty(&entry_handle),
423 : "epm_Map_simple failed - The policy handle should be empty.");
424 :
425 2 : return true;
426 : }
427 :
428 5 : static bool test_LookupHandleFree(struct torture_context *tctx,
429 : struct dcerpc_binding_handle *h,
430 : struct policy_handle *entry_handle) {
431 0 : NTSTATUS status;
432 0 : struct epm_LookupHandleFree r;
433 :
434 5 : if (ndr_policy_handle_empty(entry_handle)) {
435 0 : torture_comment(tctx,
436 : "epm_LookupHandleFree failed - empty policy_handle\n");
437 0 : return false;
438 : }
439 :
440 5 : r.in.entry_handle = entry_handle;
441 5 : r.out.entry_handle = entry_handle;
442 :
443 5 : status = dcerpc_epm_LookupHandleFree_r(h, tctx, &r);
444 5 : if (NT_STATUS_IS_ERR(status)) {
445 0 : torture_comment(tctx,
446 : "epm_LookupHandleFree failed - %s\n",
447 : nt_errstr(status));
448 0 : return false;
449 : }
450 :
451 5 : if (r.out.result != EPMAPPER_STATUS_OK) {
452 0 : torture_comment(tctx,
453 : "epm_LookupHandleFree failed - internal error: "
454 : "0x%.4x\n",
455 : r.out.result);
456 0 : return false;
457 : }
458 :
459 5 : return true;
460 : }
461 :
462 5 : static bool test_Lookup_simple(struct torture_context *tctx,
463 : struct dcerpc_pipe *p)
464 : {
465 0 : NTSTATUS status;
466 0 : struct epm_Lookup r;
467 0 : struct policy_handle entry_handle;
468 5 : uint32_t num_ents = 0;
469 5 : struct dcerpc_binding_handle *h = p->binding_handle;
470 :
471 5 : ZERO_STRUCT(entry_handle);
472 :
473 5 : torture_comment(tctx, "Testing epm_Lookup\n");
474 :
475 : /* get all elements */
476 5 : r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
477 5 : r.in.object = NULL;
478 5 : r.in.interface_id = NULL;
479 5 : r.in.vers_option = RPC_C_VERS_ALL;
480 :
481 5 : r.in.entry_handle = &entry_handle;
482 5 : r.in.max_ents = 10;
483 :
484 5 : r.out.entry_handle = &entry_handle;
485 5 : r.out.num_ents = &num_ents;
486 :
487 0 : do {
488 0 : int i;
489 :
490 28 : status = dcerpc_epm_Lookup_r(h, tctx, &r);
491 28 : if (!NT_STATUS_IS_OK(status) ||
492 28 : r.out.result != EPMAPPER_STATUS_OK) {
493 : break;
494 : }
495 :
496 26 : torture_comment(tctx,
497 : "epm_Lookup returned %d events, entry_handle: %s\n",
498 26 : *r.out.num_ents,
499 : GUID_string(tctx, &entry_handle.uuid));
500 :
501 274 : for (i = 0; i < *r.out.num_ents; i++) {
502 496 : torture_comment(tctx,
503 : "\n Found '%s' Object[%s]\n",
504 248 : r.out.entries[i].annotation,
505 248 : GUID_string(tctx, &r.out.entries[i].object));
506 :
507 248 : display_tower(tctx, &r.out.entries[i].tower->tower);
508 : }
509 52 : } while (NT_STATUS_IS_OK(status) &&
510 26 : r.out.result == EPMAPPER_STATUS_OK &&
511 52 : *r.out.num_ents == r.in.max_ents &&
512 23 : !ndr_policy_handle_empty(&entry_handle));
513 :
514 5 : torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
515 5 : torture_assert(tctx, r.out.result == EPMAPPER_STATUS_NO_MORE_ENTRIES, "epm_Lookup failed");
516 :
517 2 : torture_assert(tctx,
518 : ndr_policy_handle_empty(&entry_handle),
519 : "epm_Lookup failed - The policy handle should be empty.");
520 :
521 2 : return true;
522 : }
523 :
524 : /*
525 : * This test starts a epm_Lookup request, but doesn't finish the
526 : * call terminates the search. So it will call epm_LookupHandleFree.
527 : */
528 5 : static bool test_Lookup_terminate_search(struct torture_context *tctx,
529 : struct dcerpc_pipe *p)
530 : {
531 0 : bool ok;
532 0 : NTSTATUS status;
533 0 : struct epm_Lookup r;
534 0 : struct policy_handle entry_handle;
535 5 : uint32_t i, num_ents = 0;
536 5 : struct dcerpc_binding_handle *h = p->binding_handle;
537 :
538 5 : ZERO_STRUCT(entry_handle);
539 :
540 5 : torture_comment(tctx, "Testing epm_Lookup and epm_LookupHandleFree\n");
541 :
542 : /* get all elements */
543 5 : r.in.inquiry_type = RPC_C_EP_ALL_ELTS;
544 5 : r.in.object = NULL;
545 5 : r.in.interface_id = NULL;
546 5 : r.in.vers_option = RPC_C_VERS_ALL;
547 :
548 5 : r.in.entry_handle = &entry_handle;
549 5 : r.in.max_ents = 2;
550 :
551 5 : r.out.entry_handle = &entry_handle;
552 5 : r.out.num_ents = &num_ents;
553 :
554 5 : status = dcerpc_epm_Lookup_r(h, tctx, &r);
555 :
556 5 : torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed");
557 5 : torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, "epm_Lookup failed");
558 :
559 5 : torture_comment(tctx,
560 : "epm_Lookup returned %d events, entry_handle: %s\n",
561 5 : *r.out.num_ents,
562 : GUID_string(tctx, &entry_handle.uuid));
563 :
564 15 : for (i = 0; i < *r.out.num_ents; i++) {
565 10 : torture_comment(tctx,
566 : "\n Found '%s'\n",
567 10 : r.out.entries[i].annotation);
568 : }
569 :
570 5 : ok = test_LookupHandleFree(tctx,
571 : h,
572 : &entry_handle);
573 5 : if (!ok) {
574 0 : return false;
575 : }
576 :
577 5 : return true;
578 : }
579 :
580 5 : static bool test_Insert_noreplace(struct torture_context *tctx,
581 : struct dcerpc_pipe *p)
582 : {
583 0 : bool ok;
584 0 : NTSTATUS status;
585 0 : struct epm_Insert r;
586 0 : struct dcerpc_binding *b;
587 5 : struct dcerpc_binding_handle *h = p->binding_handle;
588 :
589 5 : torture_comment(tctx, "Testing epm_Insert(noreplace) and epm_Delete\n");
590 :
591 5 : if (torture_setting_bool(tctx, "samba4", false)) {
592 3 : torture_skip(tctx, "Skip Insert test against Samba4");
593 : }
594 :
595 2 : r.in.num_ents = 1;
596 2 : r.in.entries = talloc_array(tctx, struct epm_entry_t, 1);
597 :
598 2 : ZERO_STRUCT(r.in.entries[0].object);
599 2 : r.in.entries[0].annotation = "smbtorture endpoint";
600 :
601 2 : status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &b);
602 2 : torture_assert_ntstatus_ok(tctx,
603 : status,
604 : "Unable to generate dcerpc_binding struct");
605 :
606 2 : r.in.entries[0].tower = talloc(tctx, struct epm_twr_t);
607 :
608 2 : status = dcerpc_binding_build_tower(tctx,
609 : b,
610 2 : &r.in.entries[0].tower->tower);
611 2 : torture_assert_ntstatus_ok(tctx,
612 : status,
613 : "Unable to build tower from binding struct");
614 2 : r.in.replace = 0;
615 :
616 2 : status = dcerpc_epm_Insert_r(h, tctx, &r);
617 2 : torture_assert_ntstatus_ok(tctx, status, "epm_Insert failed");
618 :
619 0 : torture_assert(tctx, r.out.result == 0, "epm_Insert failed");
620 :
621 0 : ok = test_Delete(tctx, h, "smbtorture", b);
622 0 : if (!ok) {
623 0 : return false;
624 : }
625 :
626 0 : return true;
627 : }
628 :
629 : #if 0
630 : /*
631 : * The MS-RPCE documentation states that this function isn't implemented and
632 : * SHOULD NOT be called by a client.
633 : */
634 : static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p)
635 : {
636 : NTSTATUS status;
637 : struct epm_InqObject r;
638 : struct dcerpc_binding_handle *b = p->binding_handle;
639 :
640 : r.in.epm_object = talloc(tctx, struct GUID);
641 : *r.in.epm_object = ndr_table_epmapper.syntax_id.uuid;
642 :
643 : status = dcerpc_epm_InqObject_r(b, tctx, &r);
644 : torture_assert_ntstatus_ok(tctx, status, "InqObject failed");
645 :
646 : return true;
647 : }
648 : #endif
649 :
650 2354 : struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx)
651 : {
652 2354 : struct torture_suite *suite = torture_suite_create(mem_ctx, "epmapper");
653 125 : struct torture_rpc_tcase *tcase;
654 :
655 2354 : tcase = torture_suite_add_rpc_iface_tcase(suite,
656 : "epmapper",
657 : &ndr_table_epmapper);
658 :
659 : /* This is a stack */
660 2354 : torture_rpc_tcase_add_test(tcase,
661 : "Map_simple",
662 : test_Map_simple);
663 2354 : torture_rpc_tcase_add_test(tcase,
664 : "Map_full",
665 : test_Map_full);
666 2354 : torture_rpc_tcase_add_test(tcase,
667 : "Lookup_simple",
668 : test_Lookup_simple);
669 2354 : torture_rpc_tcase_add_test(tcase,
670 : "Lookup_terminate_search",
671 : test_Lookup_terminate_search);
672 2354 : torture_rpc_tcase_add_test(tcase,
673 : "Insert_noreplace",
674 : test_Insert_noreplace);
675 :
676 2354 : return suite;
677 : }
678 :
679 : /* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */
|