source: branches/samba-3.5.x/source4/torture/rpc/drsuapi.c

Last change on this file was 414, checked in by Herwig Bauernfeind, 16 years ago

Samba 3.5.0: Initial import

File size: 22.0 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 DRSUapi tests
5
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Stefan (metze) Metzmacher 2004
8 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005-2006
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#include "includes.h"
25#include "torture/torture.h"
26#include "librpc/gen_ndr/ndr_drsuapi_c.h"
27#include "torture/rpc/rpc.h"
28#include "param/param.h"
29
30#define TEST_MACHINE_NAME "torturetest"
31
32bool test_DsBind(struct dcerpc_pipe *p,
33 struct torture_context *tctx,
34 struct DsPrivate *priv)
35{
36 NTSTATUS status;
37 struct drsuapi_DsBind r;
38
39 GUID_from_string(DRSUAPI_DS_BIND_GUID, &priv->bind_guid);
40
41 r.in.bind_guid = &priv->bind_guid;
42 r.in.bind_info = NULL;
43 r.out.bind_handle = &priv->bind_handle;
44
45 torture_comment(tctx, "testing DsBind\n");
46
47 status = dcerpc_drsuapi_DsBind(p, tctx, &r);
48 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsBind");
49
50 return true;
51}
52
53static bool test_DsGetDomainControllerInfo(struct torture_context *tctx,
54 struct DsPrivate *priv)
55{
56 NTSTATUS status;
57 struct dcerpc_pipe *p = priv->pipe;
58 struct drsuapi_DsGetDomainControllerInfo r;
59 union drsuapi_DsGetDCInfoCtr ctr;
60 int32_t level_out = 0;
61 bool found = false;
62 int i, j, k;
63
64 struct {
65 const char *name;
66 WERROR expected;
67 } names[] = {
68 {
69 .name = torture_join_dom_netbios_name(priv->join),
70 .expected = WERR_OK
71 },
72 {
73 .name = torture_join_dom_dns_name(priv->join),
74 .expected = WERR_OK
75 },
76 {
77 .name = "__UNKNOWN_DOMAIN__",
78 .expected = WERR_DS_OBJ_NOT_FOUND
79 },
80 {
81 .name = "unknown.domain.samba.example.com",
82 .expected = WERR_DS_OBJ_NOT_FOUND
83 },
84 };
85 int levels[] = {1, 2};
86 int level;
87
88 for (i=0; i < ARRAY_SIZE(levels); i++) {
89 for (j=0; j < ARRAY_SIZE(names); j++) {
90 union drsuapi_DsGetDCInfoRequest req;
91 level = levels[i];
92 r.in.bind_handle = &priv->bind_handle;
93 r.in.level = 1;
94 r.in.req = &req;
95
96 r.in.req->req1.domain_name = names[j].name;
97 r.in.req->req1.level = level;
98
99 r.out.ctr = &ctr;
100 r.out.level_out = &level_out;
101
102 torture_comment(tctx,
103 "testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
104 r.in.req->req1.level, r.in.req->req1.domain_name);
105
106 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, tctx, &r);
107 torture_assert_ntstatus_ok(tctx, status,
108 "dcerpc_drsuapi_DsGetDomainControllerInfo with dns domain failed");
109 torture_assert_werr_equal(tctx,
110 r.out.result, names[j].expected,
111 "DsGetDomainControllerInfo level with dns domain failed");
112
113 if (!W_ERROR_IS_OK(r.out.result)) {
114 /* If this was an error, we can't read the result structure */
115 continue;
116 }
117
118 torture_assert_int_equal(tctx,
119 r.in.req->req1.level, *r.out.level_out,
120 "dcerpc_drsuapi_DsGetDomainControllerInfo in/out level differs");
121
122 switch (level) {
123 case 1:
124 for (k=0; k < r.out.ctr->ctr1.count; k++) {
125 if (strcasecmp_m(r.out.ctr->ctr1.array[k].netbios_name,
126 torture_join_netbios_name(priv->join)) == 0) {
127 found = true;
128 break;
129 }
130 }
131 break;
132 case 2:
133 for (k=0; k < r.out.ctr->ctr2.count; k++) {
134 if (strcasecmp_m(r.out.ctr->ctr2.array[k].netbios_name,
135 torture_join_netbios_name(priv->join)) == 0) {
136 found = true;
137 priv->dcinfo = r.out.ctr->ctr2.array[k];
138 break;
139 }
140 }
141 break;
142 }
143 torture_assert(tctx, found,
144 "dcerpc_drsuapi_DsGetDomainControllerInfo: Failed to find the domain controller we just created during the join");
145 }
146 }
147
148 r.in.bind_handle = &priv->bind_handle;
149 r.in.level = 1;
150
151 r.out.ctr = &ctr;
152 r.out.level_out = &level_out;
153
154 r.in.req->req1.domain_name = "__UNKNOWN_DOMAIN__"; /* This is clearly ignored for this level */
155 r.in.req->req1.level = -1;
156
157 torture_comment(tctx, "testing DsGetDomainControllerInfo level %d on domainname '%s'\n",
158 r.in.req->req1.level, r.in.req->req1.domain_name);
159
160 status = dcerpc_drsuapi_DsGetDomainControllerInfo(p, tctx, &r);
161
162 torture_assert_ntstatus_ok(tctx, status,
163 "dcerpc_drsuapi_DsGetDomainControllerInfo with dns domain failed");
164 torture_assert_werr_ok(tctx, r.out.result,
165 "DsGetDomainControllerInfo with dns domain failed");
166
167 {
168 const char *dc_account = talloc_asprintf(tctx, "%s\\%s$",
169 torture_join_dom_netbios_name(priv->join),
170 priv->dcinfo.netbios_name);
171 torture_comment(tctx, "%s: Enum active LDAP sessions searching for %s\n", __func__, dc_account);
172 for (k=0; k < r.out.ctr->ctr01.count; k++) {
173 if (strcasecmp_m(r.out.ctr->ctr01.array[k].client_account,
174 dc_account)) {
175 found = true;
176 break;
177 }
178 }
179 torture_assert(tctx, found,
180 "dcerpc_drsuapi_DsGetDomainControllerInfo level: Failed to find the domain controller in last logon records");
181 }
182
183
184 return true;
185}
186
187static bool test_DsWriteAccountSpn(struct torture_context *tctx,
188 struct DsPrivate *priv)
189{
190 NTSTATUS status;
191 struct dcerpc_pipe *p = priv->pipe;
192 struct drsuapi_DsWriteAccountSpn r;
193 union drsuapi_DsWriteAccountSpnRequest req;
194 struct drsuapi_DsNameString names[2];
195 union drsuapi_DsWriteAccountSpnResult res;
196 int32_t level_out;
197
198 r.in.bind_handle = &priv->bind_handle;
199 r.in.level = 1;
200 r.in.req = &req;
201
202 torture_comment(tctx, "testing DsWriteAccountSpn\n");
203
204 r.in.req->req1.operation = DRSUAPI_DS_SPN_OPERATION_ADD;
205 r.in.req->req1.unknown1 = 0;
206 r.in.req->req1.object_dn = priv->dcinfo.computer_dn;
207 r.in.req->req1.count = 2;
208 r.in.req->req1.spn_names = names;
209 names[0].str = talloc_asprintf(tctx, "smbtortureSPN/%s",priv->dcinfo.netbios_name);
210 names[1].str = talloc_asprintf(tctx, "smbtortureSPN/%s",priv->dcinfo.dns_name);
211
212 r.out.res = &res;
213 r.out.level_out = &level_out;
214
215 status = dcerpc_drsuapi_DsWriteAccountSpn(p, tctx, &r);
216 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsWriteAccountSpn");
217
218 r.in.req->req1.operation = DRSUAPI_DS_SPN_OPERATION_DELETE;
219 r.in.req->req1.unknown1 = 0;
220
221 status = dcerpc_drsuapi_DsWriteAccountSpn(p, tctx, &r);
222 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsWriteAccountSpn");
223
224 return true;
225}
226
227static bool test_DsReplicaGetInfo(struct torture_context *tctx,
228 struct DsPrivate *priv)
229{
230 NTSTATUS status;
231 struct dcerpc_pipe *p = priv->pipe;
232 struct drsuapi_DsReplicaGetInfo r;
233 union drsuapi_DsReplicaGetInfoRequest req;
234 union drsuapi_DsReplicaInfo info;
235 enum drsuapi_DsReplicaInfoType info_type;
236 int i;
237 struct {
238 int32_t level;
239 int32_t infotype;
240 const char *obj_dn;
241 } array[] = {
242 {
243 DRSUAPI_DS_REPLICA_GET_INFO,
244 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS,
245 NULL
246 },{
247 DRSUAPI_DS_REPLICA_GET_INFO,
248 DRSUAPI_DS_REPLICA_INFO_CURSORS,
249 NULL
250 },{
251 DRSUAPI_DS_REPLICA_GET_INFO,
252 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA,
253 NULL
254 },{
255 DRSUAPI_DS_REPLICA_GET_INFO,
256 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_CONNECT_FAILURES,
257 NULL
258 },{
259 DRSUAPI_DS_REPLICA_GET_INFO,
260 DRSUAPI_DS_REPLICA_INFO_KCC_DSA_LINK_FAILURES,
261 NULL
262 },{
263 DRSUAPI_DS_REPLICA_GET_INFO,
264 DRSUAPI_DS_REPLICA_INFO_PENDING_OPS,
265 NULL
266 },{
267 DRSUAPI_DS_REPLICA_GET_INFO2,
268 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA,
269 NULL
270 },{
271 DRSUAPI_DS_REPLICA_GET_INFO2,
272 DRSUAPI_DS_REPLICA_INFO_CURSORS2,
273 NULL
274 },{
275 DRSUAPI_DS_REPLICA_GET_INFO2,
276 DRSUAPI_DS_REPLICA_INFO_CURSORS3,
277 NULL
278 },{
279 DRSUAPI_DS_REPLICA_GET_INFO2,
280 DRSUAPI_DS_REPLICA_INFO_OBJ_METADATA2,
281 NULL
282 },{
283 DRSUAPI_DS_REPLICA_GET_INFO2,
284 DRSUAPI_DS_REPLICA_INFO_ATTRIBUTE_VALUE_METADATA2,
285 NULL
286 },{
287 DRSUAPI_DS_REPLICA_GET_INFO2,
288 DRSUAPI_DS_REPLICA_INFO_NEIGHBORS02,
289 NULL
290 },{
291 DRSUAPI_DS_REPLICA_GET_INFO2,
292 DRSUAPI_DS_REPLICA_INFO_CONNECTIONS04,
293 "__IGNORED__"
294 },{
295 DRSUAPI_DS_REPLICA_GET_INFO2,
296 DRSUAPI_DS_REPLICA_INFO_CURSORS05,
297 NULL
298 },{
299 DRSUAPI_DS_REPLICA_GET_INFO2,
300 DRSUAPI_DS_REPLICA_INFO_06,
301 NULL
302 }
303 };
304
305 if (torture_setting_bool(tctx, "samba4", false)) {
306 torture_comment(tctx, "skipping DsReplicaGetInfo test against Samba4\n");
307 return true;
308 }
309
310 r.in.bind_handle = &priv->bind_handle;
311 r.in.req = &req;
312
313 for (i=0; i < ARRAY_SIZE(array); i++) {
314 const char *object_dn;
315
316 torture_comment(tctx, "testing DsReplicaGetInfo level %d infotype %d\n",
317 array[i].level, array[i].infotype);
318
319 object_dn = (array[i].obj_dn ? array[i].obj_dn : priv->domain_obj_dn);
320
321 r.in.level = array[i].level;
322 switch(r.in.level) {
323 case DRSUAPI_DS_REPLICA_GET_INFO:
324 r.in.req->req1.info_type = array[i].infotype;
325 r.in.req->req1.object_dn = object_dn;
326 ZERO_STRUCT(r.in.req->req1.guid1);
327 break;
328 case DRSUAPI_DS_REPLICA_GET_INFO2:
329 r.in.req->req2.info_type = array[i].infotype;
330 r.in.req->req2.object_dn = object_dn;
331 ZERO_STRUCT(r.in.req->req2.guid1);
332 r.in.req->req2.unknown1 = 0;
333 r.in.req->req2.string1 = NULL;
334 r.in.req->req2.string2 = NULL;
335 r.in.req->req2.unknown2 = 0;
336 break;
337 }
338
339 r.out.info = &info;
340 r.out.info_type = &info_type;
341
342 status = dcerpc_drsuapi_DsReplicaGetInfo(p, tctx, &r);
343 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
344 if (!NT_STATUS_IS_OK(status) && p->last_fault_code == DCERPC_FAULT_INVALID_TAG) {
345 torture_comment(tctx,
346 "DsReplicaGetInfo level %d and/or infotype %d not supported by server\n",
347 array[i].level, array[i].infotype);
348 } else {
349 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaGetInfo");
350 }
351 }
352
353 return true;
354}
355
356static bool test_DsReplicaSync(struct torture_context *tctx,
357 struct DsPrivate *priv)
358{
359 NTSTATUS status;
360 struct dcerpc_pipe *p = priv->pipe;
361 int i;
362 struct drsuapi_DsReplicaSync r;
363 struct drsuapi_DsReplicaObjectIdentifier nc;
364 struct GUID null_guid;
365 struct dom_sid null_sid;
366 struct {
367 int32_t level;
368 } array[] = {
369 {
370 1
371 }
372 };
373
374 if (!torture_setting_bool(tctx, "dangerous", false)) {
375 torture_comment(tctx, "DsReplicaSync disabled - enable dangerous tests to use\n");
376 return true;
377 }
378
379 if (torture_setting_bool(tctx, "samba4", false)) {
380 torture_comment(tctx, "skipping DsReplicaSync test against Samba4\n");
381 return true;
382 }
383
384 ZERO_STRUCT(null_guid);
385 ZERO_STRUCT(null_sid);
386
387 r.in.bind_handle = &priv->bind_handle;
388
389 for (i=0; i < ARRAY_SIZE(array); i++) {
390 torture_comment(tctx, "testing DsReplicaSync level %d\n",
391 array[i].level);
392
393 r.in.level = array[i].level;
394 switch(r.in.level) {
395 case 1:
396 nc.guid = null_guid;
397 nc.sid = null_sid;
398 nc.dn = priv->domain_obj_dn?priv->domain_obj_dn:"";
399
400 r.in.req.req1.naming_context = &nc;
401 r.in.req.req1.source_dsa_guid = priv->dcinfo.ntds_guid;
402 r.in.req.req1.other_info = NULL;
403 r.in.req.req1.options = 16;
404 break;
405 }
406
407 status = dcerpc_drsuapi_DsReplicaSync(p, tctx, &r);
408 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaSync");
409 }
410
411 return true;
412}
413
414static bool test_DsReplicaUpdateRefs(struct torture_context *tctx,
415 struct DsPrivate *priv)
416{
417 NTSTATUS status;
418 struct dcerpc_pipe *p = priv->pipe;
419 int i;
420 struct drsuapi_DsReplicaUpdateRefs r;
421 struct drsuapi_DsReplicaObjectIdentifier nc;
422 struct GUID null_guid;
423 struct dom_sid null_sid;
424 struct {
425 int32_t level;
426 } array[] = {
427 {
428 1
429 }
430 };
431
432 if (torture_setting_bool(tctx, "samba4", false)) {
433 torture_comment(tctx, "skipping DsReplicaUpdateRefs test against Samba4\n");
434 return true;
435 }
436
437 ZERO_STRUCT(null_guid);
438 ZERO_STRUCT(null_sid);
439
440 r.in.bind_handle = &priv->bind_handle;
441
442 for (i=0; i < ARRAY_SIZE(array); i++) {
443 torture_comment(tctx, "testing DsReplicaUpdateRefs level %d\n",
444 array[i].level);
445
446 r.in.level = array[i].level;
447 switch(r.in.level) {
448 case 1:
449 nc.guid = null_guid;
450 nc.sid = null_sid;
451 nc.dn = priv->domain_obj_dn ? priv->domain_obj_dn : "";
452
453 r.in.req.req1.naming_context = &nc;
454 r.in.req.req1.dest_dsa_dns_name = talloc_asprintf(tctx, "__some_dest_dsa_guid_string._msdn.%s",
455 priv->domain_dns_name);
456 r.in.req.req1.dest_dsa_guid = null_guid;
457 r.in.req.req1.options = 0;
458 break;
459 }
460
461 status = dcerpc_drsuapi_DsReplicaUpdateRefs(p, tctx, &r);
462 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsReplicaUpdateRefs");
463 }
464
465 return true;
466}
467
468static bool test_DsGetNCChanges(struct torture_context *tctx,
469 struct DsPrivate *priv)
470{
471 NTSTATUS status;
472 struct dcerpc_pipe *p = priv->pipe;
473 int i;
474 struct drsuapi_DsGetNCChanges r;
475 union drsuapi_DsGetNCChangesRequest req;
476 union drsuapi_DsGetNCChangesCtr ctr;
477 struct drsuapi_DsReplicaObjectIdentifier nc;
478 struct GUID null_guid;
479 struct dom_sid null_sid;
480 int32_t level_out;
481 struct {
482 int32_t level;
483 } array[] = {
484 {
485 5
486 },
487 {
488 8
489 }
490 };
491
492 if (torture_setting_bool(tctx, "samba4", false)) {
493 torture_comment(tctx, "skipping DsGetNCChanges test against Samba4\n");
494 return true;
495 }
496
497 ZERO_STRUCT(null_guid);
498 ZERO_STRUCT(null_sid);
499
500 for (i=0; i < ARRAY_SIZE(array); i++) {
501 torture_comment(tctx,
502 "testing DsGetNCChanges level %d\n",
503 array[i].level);
504
505 r.in.bind_handle = &priv->bind_handle;
506 r.in.level = array[i].level;
507 r.out.level_out = &level_out;
508 r.out.ctr = &ctr;
509
510 switch (r.in.level) {
511 case 5:
512 nc.guid = null_guid;
513 nc.sid = null_sid;
514 nc.dn = priv->domain_obj_dn ? priv->domain_obj_dn : "";
515
516 r.in.req = &req;
517 r.in.req->req5.destination_dsa_guid = GUID_random();
518 r.in.req->req5.source_dsa_invocation_id = null_guid;
519 r.in.req->req5.naming_context = &nc;
520 r.in.req->req5.highwatermark.tmp_highest_usn = 0;
521 r.in.req->req5.highwatermark.reserved_usn = 0;
522 r.in.req->req5.highwatermark.highest_usn = 0;
523 r.in.req->req5.uptodateness_vector = NULL;
524 r.in.req->req5.replica_flags = 0;
525 if (lp_parm_bool(tctx->lp_ctx, NULL, "drsuapi", "compression", false)) {
526 r.in.req->req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
527 }
528 r.in.req->req5.max_object_count = 0;
529 r.in.req->req5.max_ndr_size = 0;
530 r.in.req->req5.extended_op = DRSUAPI_EXOP_NONE;
531 r.in.req->req5.fsmo_info = 0;
532
533 break;
534 case 8:
535 nc.guid = null_guid;
536 nc.sid = null_sid;
537 nc.dn = priv->domain_obj_dn ? priv->domain_obj_dn : "";
538
539 r.in.req = &req;
540 r.in.req->req8.destination_dsa_guid = GUID_random();
541 r.in.req->req8.source_dsa_invocation_id = null_guid;
542 r.in.req->req8.naming_context = &nc;
543 r.in.req->req8.highwatermark.tmp_highest_usn = 0;
544 r.in.req->req8.highwatermark.reserved_usn = 0;
545 r.in.req->req8.highwatermark.highest_usn = 0;
546 r.in.req->req8.uptodateness_vector = NULL;
547 r.in.req->req8.replica_flags = 0;
548 if (lp_parm_bool(tctx->lp_ctx, NULL, "drsuapi", "compression", false)) {
549 r.in.req->req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
550 }
551 if (lp_parm_bool(tctx->lp_ctx, NULL, "drsuapi", "neighbour_writeable", true)) {
552 r.in.req->req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
553 }
554 r.in.req->req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
555 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
556 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
557 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
558 ;
559 r.in.req->req8.max_object_count = 402;
560 r.in.req->req8.max_ndr_size = 402116;
561 r.in.req->req8.extended_op = DRSUAPI_EXOP_NONE;
562 r.in.req->req8.fsmo_info = 0;
563 r.in.req->req8.partial_attribute_set = NULL;
564 r.in.req->req8.partial_attribute_set_ex = NULL;
565 r.in.req->req8.mapping_ctr.num_mappings = 0;
566 r.in.req->req8.mapping_ctr.mappings = NULL;
567
568 break;
569 }
570
571 status = dcerpc_drsuapi_DsGetNCChanges(p, tctx, &r);
572 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsGetNCChanges");
573 }
574
575 return true;
576}
577
578bool test_QuerySitesByCost(struct torture_context *tctx,
579 struct DsPrivate *priv)
580{
581 NTSTATUS status;
582 struct dcerpc_pipe *p = priv->pipe;
583 struct drsuapi_QuerySitesByCost r;
584 union drsuapi_QuerySitesByCostRequest req;
585
586 const char *my_site = "Default-First-Site-Name";
587 const char *remote_site1 = "smbtorture-nonexisting-site1";
588 const char *remote_site2 = "smbtorture-nonexisting-site2";
589
590 req.req1.site_from = talloc_strdup(tctx, my_site);
591 req.req1.num_req = 2;
592 req.req1.site_to = talloc_zero_array(tctx, const char *, 2);
593 req.req1.site_to[0] = talloc_strdup(tctx, remote_site1);
594 req.req1.site_to[1] = talloc_strdup(tctx, remote_site2);
595 req.req1.flags = 0;
596
597 r.in.bind_handle = &priv->bind_handle;
598 r.in.level = 1;
599 r.in.req = &req;
600
601 status = dcerpc_drsuapi_QuerySitesByCost(p, tctx, &r);
602 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_QuerySitesByCost");
603
604 if (W_ERROR_IS_OK(r.out.result)) {
605 torture_assert_werr_equal(tctx,
606 r.out.ctr->ctr1.info[0].error_code, WERR_DS_OBJ_NOT_FOUND,
607 "dcerpc_drsuapi_QuerySitesByCost");
608 torture_assert_werr_equal(tctx,
609 r.out.ctr->ctr1.info[1].error_code, WERR_DS_OBJ_NOT_FOUND,
610 "dcerpc_drsuapi_QuerySitesByCost expected error_code WERR_DS_OBJ_NOT_FOUND");
611
612 torture_assert_int_equal(tctx,
613 r.out.ctr->ctr1.info[0].site_cost, -1,
614 "dcerpc_drsuapi_QuerySitesByCost");
615 torture_assert_int_equal(tctx,
616 r.out.ctr->ctr1.info[1].site_cost, -1,
617 "dcerpc_drsuapi_QuerySitesByCost exptected site cost");
618 }
619
620 return true;
621
622
623}
624
625bool test_DsUnbind(struct dcerpc_pipe *p,
626 struct torture_context *tctx,
627 struct DsPrivate *priv)
628{
629 NTSTATUS status;
630 struct drsuapi_DsUnbind r;
631
632 r.in.bind_handle = &priv->bind_handle;
633 r.out.bind_handle = &priv->bind_handle;
634
635 torture_comment(tctx, "testing DsUnbind\n");
636
637 status = dcerpc_drsuapi_DsUnbind(p, tctx, &r);
638 torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsUnbind");
639
640 return true;
641}
642
643
644/**
645 * Helper func to collect DC information for testing purposes.
646 * This function is almost identical to test_DsGetDomainControllerInfo
647 */
648bool torture_rpc_drsuapi_get_dcinfo(struct torture_context *torture,
649 struct DsPrivate *priv)
650{
651 NTSTATUS status;
652 int32_t level_out = 0;
653 struct drsuapi_DsGetDomainControllerInfo r;
654 union drsuapi_DsGetDCInfoCtr ctr;
655 int j, k;
656 const char *names[] = {
657 torture_join_dom_netbios_name(priv->join),
658 torture_join_dom_dns_name(priv->join)};
659
660 for (j=0; j < ARRAY_SIZE(names); j++) {
661 union drsuapi_DsGetDCInfoRequest req;
662 r.in.bind_handle = &priv->bind_handle;
663 r.in.level = 1;
664 r.in.req = &req;
665
666 r.in.req->req1.domain_name = names[j];
667 r.in.req->req1.level = 2;
668
669 r.out.ctr = &ctr;
670 r.out.level_out = &level_out;
671
672 status = dcerpc_drsuapi_DsGetDomainControllerInfo(priv->pipe, torture, &r);
673 if (!NT_STATUS_IS_OK(status)) {
674 continue;
675 }
676 if (!W_ERROR_IS_OK(r.out.result)) {
677 /* If this was an error, we can't read the result structure */
678 continue;
679 }
680
681 for (k=0; k < r.out.ctr->ctr2.count; k++) {
682 if (strcasecmp_m(r.out.ctr->ctr2.array[k].netbios_name,
683 torture_join_netbios_name(priv->join)) == 0) {
684 priv->dcinfo = r.out.ctr->ctr2.array[k];
685 return true;
686 }
687 }
688 }
689
690 return false;
691}
692
693/**
694 * Common test case setup function to be used
695 * in DRS suit of test when appropriate
696 */
697bool torture_drsuapi_tcase_setup_common(struct torture_context *tctx, struct DsPrivate *priv)
698{
699 NTSTATUS status;
700 struct cli_credentials *machine_credentials;
701
702 torture_assert(tctx, priv, "Invalid argument");
703
704 torture_comment(tctx, "Create DRSUAPI pipe\n");
705 status = torture_rpc_connection(tctx,
706 &priv->pipe,
707 &ndr_table_drsuapi);
708 torture_assert(tctx, NT_STATUS_IS_OK(status), "Unable to connect to DRSUAPI pipe");
709
710 torture_comment(tctx, "About to join domain\n");
711 priv->join = torture_join_domain(tctx, TEST_MACHINE_NAME, ACB_SVRTRUST,
712 &machine_credentials);
713 torture_assert(tctx, priv->join, "Failed to join as BDC");
714
715 if (!test_DsBind(priv->pipe, tctx, priv)) {
716 /* clean up */
717 torture_drsuapi_tcase_teardown_common(tctx, priv);
718 torture_fail(tctx, "Failed execute test_DsBind()");
719 }
720
721 /* try collect some information for testing */
722 torture_rpc_drsuapi_get_dcinfo(tctx, priv);
723
724 return true;
725}
726
727/**
728 * Common test case teardown function to be used
729 * in DRS suit of test when appropriate
730 */
731bool torture_drsuapi_tcase_teardown_common(struct torture_context *tctx, struct DsPrivate *priv)
732{
733 if (priv->join) {
734 torture_leave_domain(tctx, priv->join);
735 }
736
737 return true;
738}
739
740/**
741 * Test case setup for DRSUAPI test case
742 */
743static bool torture_drsuapi_tcase_setup(struct torture_context *tctx, void **data)
744{
745 struct DsPrivate *priv;
746
747 *data = priv = talloc_zero(tctx, struct DsPrivate);
748
749 return torture_drsuapi_tcase_setup_common(tctx, priv);
750}
751
752/**
753 * Test case tear-down for DRSUAPI test case
754 */
755static bool torture_drsuapi_tcase_teardown(struct torture_context *tctx, void *data)
756{
757 bool ret;
758 struct DsPrivate *priv = talloc_get_type(data, struct DsPrivate);
759
760 ret = torture_drsuapi_tcase_teardown_common(tctx, priv);
761
762 talloc_free(priv);
763 return ret;
764}
765
766/**
767 * DRSUAPI test case implementation
768 */
769void torture_rpc_drsuapi_tcase(struct torture_suite *suite)
770{
771 typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
772
773 struct torture_test *test;
774 struct torture_tcase *tcase = torture_suite_add_tcase(suite, "DRSUAPI");
775
776 torture_tcase_set_fixture(tcase,
777 torture_drsuapi_tcase_setup,
778 torture_drsuapi_tcase_teardown);
779
780#if 0
781 test = torture_tcase_add_simple_test(tcase, "QuerySitesByCost", (run_func)test_QuerySitesByCost);
782#endif
783
784 test = torture_tcase_add_simple_test(tcase, "DsGetDomainControllerInfo", (run_func)test_DsGetDomainControllerInfo);
785
786 test = torture_tcase_add_simple_test(tcase, "DsCrackNames", (run_func)test_DsCrackNames);
787
788 test = torture_tcase_add_simple_test(tcase, "DsWriteAccountSpn", (run_func)test_DsWriteAccountSpn);
789
790 test = torture_tcase_add_simple_test(tcase, "DsReplicaGetInfo", (run_func)test_DsReplicaGetInfo);
791
792 test = torture_tcase_add_simple_test(tcase, "DsReplicaSync", (run_func)test_DsReplicaSync);
793
794 test = torture_tcase_add_simple_test(tcase, "DsReplicaUpdateRefs", (run_func)test_DsReplicaUpdateRefs);
795
796 test = torture_tcase_add_simple_test(tcase, "DsGetNCChanges", (run_func)test_DsGetNCChanges);
797}
Note: See TracBrowser for help on using the repository browser.