2 Unix SMB/CIFS implementation.
4 libnet_BecomeDC() tests
6 Copyright (C) Stefan Metzmacher <metze@samba.org> 2006
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "lib/cmdline/popt_common.h"
24 #include "torture/torture.h"
25 #include "torture/rpc/rpc.h"
26 #include "libnet/libnet.h"
27 #include "lib/events/events.h"
28 #include "dsdb/samdb/samdb.h"
29 #include "lib/util/dlinklist.h"
30 #include "lib/ldb/include/ldb.h"
31 #include "lib/ldb/include/ldb_errors.h"
32 #include "librpc/ndr/libndr.h"
33 #include "librpc/gen_ndr/ndr_drsuapi.h"
34 #include "librpc/gen_ndr/ndr_drsblobs.h"
35 #include "librpc/gen_ndr/ndr_misc.h"
36 #include "system/time.h"
37 #include "lib/ldb_wrap.h"
38 #include "auth/auth.h"
39 #include "param/param.h"
40 #include "torture/util.h"
42 struct test_become_dc_state {
43 struct libnet_context *ctx;
44 struct torture_context *tctx;
45 const char *netbios_name;
47 struct cli_credentials *machine_account;
48 struct dsdb_schema *self_made_schema;
49 const struct dsdb_schema *schema;
51 struct ldb_context *ldb;
54 uint32_t object_count;
55 struct drsuapi_DsReplicaObjectListItemEx *first_object;
56 struct drsuapi_DsReplicaObjectListItemEx *last_object;
59 const char *targetdir;
61 struct loadparm_context *lp_ctx;
64 static NTSTATUS test_become_dc_prepare_db(void *private_data,
65 const struct libnet_BecomeDC_PrepareDB *p)
67 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
68 struct provision_settings settings;
71 struct loadparm_context *lp_ctx = loadparm_init(s);
75 return NT_STATUS_NO_MEMORY;
78 settings.dns_name = p->dest_dsa->dns_name;
79 settings.site_name = p->dest_dsa->site_name;
80 settings.root_dn_str = p->forest->root_dn_str;
81 settings.domain_dn_str = p->domain->dn_str;
82 settings.config_dn_str = p->forest->config_dn_str;
83 settings.schema_dn_str = p->forest->schema_dn_str;
84 settings.netbios_name = p->dest_dsa->netbios_name;
85 settings.realm = torture_join_dom_dns_name(s->tj);
86 settings.domain = torture_join_dom_netbios_name(s->tj);
87 settings.machine_password = cli_credentials_get_password(s->machine_account);
88 settings.targetdir = s->targetdir;
90 status = provision_bare(s, s->lp_ctx, &settings);
92 smbconf = talloc_asprintf(lp_ctx, "%s/%s", s->targetdir, "/etc/smb.conf");
94 ok = lp_load(lp_ctx, smbconf);
96 DEBUG(0,("Failed load freshly generated smb.conf '%s'\n", smbconf));
97 return NT_STATUS_INVALID_PARAMETER;
100 s->ldb = ldb_wrap_connect(s, lp_ctx, lp_sam_url(lp_ctx),
101 system_session(s, lp_ctx),
104 DEBUG(0,("Failed to open '%s'\n", lp_sam_url(lp_ctx)));
105 return NT_STATUS_INTERNAL_DB_ERROR;
108 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
110 DEBUG(0,("Failed to set cached ntds invocationId\n"));
111 return NT_STATUS_FOOBAR;
113 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
115 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
116 return NT_STATUS_FOOBAR;
126 static NTSTATUS test_become_dc_check_options(void *private_data,
127 const struct libnet_BecomeDC_CheckOptions *o)
129 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
131 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n",
133 o->domain->netbios_name, o->domain->dns_name));
135 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
136 o->source_dsa->dns_name, o->source_dsa->site_name));
138 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
139 "\tschema object_version[%u]\n"
140 "\tdomain behavior_version[%u]\n"
141 "\tdomain w2k3_update_revision[%u]\n",
142 o->forest->crossref_behavior_version,
143 o->forest->schema_object_version,
144 o->domain->behavior_version,
145 o->domain->w2k3_update_revision));
150 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
151 const struct libnet_BecomeDC_StoreChunk *c)
154 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
155 uint32_t total_object_count;
156 uint32_t object_count;
157 struct drsuapi_DsReplicaObjectListItemEx *first_object;
158 struct drsuapi_DsReplicaObjectListItemEx *cur;
159 uint32_t linked_attributes_count;
160 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
161 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
162 struct dsdb_extended_replicated_objects *objs;
163 struct repsFromTo1 *s_dsa;
165 struct ldb_message *msg;
166 struct ldb_val prefixMap_val;
167 struct ldb_message_element *prefixMap_el;
168 struct ldb_val schemaInfo_val;
174 DEBUG(0,("Analyze and apply schema objects\n"));
176 s_dsa = talloc_zero(s, struct repsFromTo1);
177 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
178 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
179 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
181 switch (c->ctr_level) {
183 mapping_ctr = &c->ctr1->mapping_ctr;
184 total_object_count = c->ctr1->total_object_count;
185 object_count = s->schema_part.object_count;
186 first_object = s->schema_part.first_object;
187 linked_attributes_count = 0;
188 linked_attributes = NULL;
189 s_dsa->highwatermark = c->ctr1->new_highwatermark;
190 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
191 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
192 uptodateness_vector = NULL; /* TODO: map it */
195 mapping_ctr = &c->ctr6->mapping_ctr;
196 total_object_count = c->ctr6->total_object_count;
197 object_count = s->schema_part.object_count;
198 first_object = s->schema_part.first_object;
199 linked_attributes_count = 0; /* TODO: ! */
200 linked_attributes = NULL; /* TODO: ! */;
201 s_dsa->highwatermark = c->ctr6->new_highwatermark;
202 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
203 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
204 uptodateness_vector = c->ctr6->uptodateness_vector;
207 return NT_STATUS_INVALID_PARAMETER;
210 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
211 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
212 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
213 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
215 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
216 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
217 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
218 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
219 s_dsa->other_info->dns_name = tmp_dns_name;
221 for (cur = first_object; cur; cur = cur->next_object) {
222 bool is_attr = false;
223 bool is_class = false;
225 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
226 struct drsuapi_DsReplicaAttribute *a;
228 const char *oid = NULL;
230 a = &cur->object.attribute_ctr.attributes[i];
231 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
232 if (!W_ERROR_IS_OK(status)) {
233 return werror_to_ntstatus(status);
237 case DRSUAPI_ATTRIBUTE_objectClass:
238 for (j=0; j < a->value_ctr.num_values; j++) {
239 uint32_t val = 0xFFFFFFFF;
241 if (a->value_ctr.values[i].blob
242 && a->value_ctr.values[i].blob->length == 4) {
243 val = IVAL(a->value_ctr.values[i].blob->data,0);
246 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
249 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
261 struct dsdb_attribute *sa;
263 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
264 NT_STATUS_HAVE_NO_MEMORY(sa);
266 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
267 if (!W_ERROR_IS_OK(status)) {
268 return werror_to_ntstatus(status);
271 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
275 struct dsdb_class *sc;
277 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
278 NT_STATUS_HAVE_NO_MEMORY(sc);
280 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
281 if (!W_ERROR_IS_OK(status)) {
282 return werror_to_ntstatus(status);
285 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
289 /* attach the schema to the ldb */
290 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
291 if (ret != LDB_SUCCESS) {
292 return NT_STATUS_FOOBAR;
294 /* we don't want to access the self made schema anymore */
295 s->self_made_schema = NULL;
296 s->schema = dsdb_get_schema(s->ldb);
298 status = dsdb_extended_replicated_objects_commit(s->ldb,
303 linked_attributes_count,
309 if (!W_ERROR_IS_OK(status)) {
310 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
311 return werror_to_ntstatus(status);
314 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
315 for (i=0; i < objs->num_objects; i++) {
316 struct ldb_ldif ldif;
317 fprintf(stdout, "#\n");
318 ldif.changetype = LDB_CHANGETYPE_NONE;
319 ldif.msg = objs->objects[i].msg;
320 ldb_ldif_write_file(s->ldb, stdout, &ldif);
321 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
325 msg = ldb_msg_new(objs);
326 NT_STATUS_HAVE_NO_MEMORY(msg);
327 msg->dn = objs->partition_dn;
329 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
330 if (!W_ERROR_IS_OK(status)) {
331 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
332 return werror_to_ntstatus(status);
335 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
336 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
337 if (ret != LDB_SUCCESS) {
338 return NT_STATUS_FOOBAR;
340 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
342 ret = ldb_modify(s->ldb, msg);
343 if (ret != LDB_SUCCESS) {
344 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
345 return NT_STATUS_FOOBAR;
352 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
355 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
356 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", sam_ldb_path));
357 s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, sam_ldb_path,
358 system_session(s, s->tctx->lp_ctx),
361 DEBUG(0,("Failed to open '%s'\n",
363 return NT_STATUS_INTERNAL_DB_ERROR;
366 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
368 DEBUG(0,("Failed to set cached ntds invocationId\n"));
369 return NT_STATUS_FOOBAR;
371 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
373 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
374 return NT_STATUS_FOOBAR;
377 s->schema = dsdb_get_schema(s->ldb);
379 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
380 return NT_STATUS_FOOBAR;
386 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
387 const struct libnet_BecomeDC_StoreChunk *c)
389 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
391 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
392 uint32_t total_object_count;
393 uint32_t object_count;
394 struct drsuapi_DsReplicaObjectListItemEx *first_object;
395 struct drsuapi_DsReplicaObjectListItemEx *cur;
397 switch (c->ctr_level) {
399 mapping_ctr = &c->ctr1->mapping_ctr;
400 total_object_count = c->ctr1->total_object_count;
401 object_count = c->ctr1->object_count;
402 first_object = c->ctr1->first_object;
405 mapping_ctr = &c->ctr6->mapping_ctr;
406 total_object_count = c->ctr6->total_object_count;
407 object_count = c->ctr6->object_count;
408 first_object = c->ctr6->first_object;
411 return NT_STATUS_INVALID_PARAMETER;
414 if (total_object_count) {
415 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
416 c->partition->nc.dn, object_count, total_object_count));
418 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
419 c->partition->nc.dn, object_count));
423 s->self_made_schema = dsdb_new_schema(s, lp_iconv_convenience(s->lp_ctx));
425 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
427 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
428 if (!W_ERROR_IS_OK(status)) {
429 return werror_to_ntstatus(status);
432 s->schema = s->self_made_schema;
434 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
435 if (!W_ERROR_IS_OK(status)) {
436 return werror_to_ntstatus(status);
440 if (!s->schema_part.first_object) {
441 s->schema_part.object_count = object_count;
442 s->schema_part.first_object = talloc_steal(s, first_object);
444 s->schema_part.object_count += object_count;
445 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
448 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
449 s->schema_part.last_object = cur;
451 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
452 return test_apply_schema(s, c);
458 static NTSTATUS test_become_dc_store_chunk(void *private_data,
459 const struct libnet_BecomeDC_StoreChunk *c)
461 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
463 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
464 uint32_t total_object_count;
465 uint32_t object_count;
466 struct drsuapi_DsReplicaObjectListItemEx *first_object;
467 uint32_t linked_attributes_count;
468 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
469 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
470 struct dsdb_extended_replicated_objects *objs;
471 struct repsFromTo1 *s_dsa;
475 s_dsa = talloc_zero(s, struct repsFromTo1);
476 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
477 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
478 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
480 switch (c->ctr_level) {
482 mapping_ctr = &c->ctr1->mapping_ctr;
483 total_object_count = c->ctr1->total_object_count;
484 object_count = c->ctr1->object_count;
485 first_object = c->ctr1->first_object;
486 linked_attributes_count = 0;
487 linked_attributes = NULL;
488 s_dsa->highwatermark = c->ctr1->new_highwatermark;
489 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
490 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
491 uptodateness_vector = NULL; /* TODO: map it */
494 mapping_ctr = &c->ctr6->mapping_ctr;
495 total_object_count = c->ctr6->total_object_count;
496 object_count = c->ctr6->object_count;
497 first_object = c->ctr6->first_object;
498 linked_attributes_count = c->ctr6->linked_attributes_count;
499 linked_attributes = c->ctr6->linked_attributes;
500 s_dsa->highwatermark = c->ctr6->new_highwatermark;
501 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
502 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
503 uptodateness_vector = c->ctr6->uptodateness_vector;
506 return NT_STATUS_INVALID_PARAMETER;
509 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
510 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
511 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
512 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
514 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
515 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
516 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
517 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
518 s_dsa->other_info->dns_name = tmp_dns_name;
520 if (total_object_count) {
521 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
522 c->partition->nc.dn, object_count, total_object_count));
524 DEBUG(0,("Partition[%s] objects[%u]\n",
525 c->partition->nc.dn, object_count));
528 status = dsdb_extended_replicated_objects_commit(s->ldb,
533 linked_attributes_count,
539 if (!W_ERROR_IS_OK(status)) {
540 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
541 return werror_to_ntstatus(status);
544 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
545 for (i=0; i < objs->num_objects; i++) {
546 struct ldb_ldif ldif;
547 fprintf(stdout, "#\n");
548 ldif.changetype = LDB_CHANGETYPE_NONE;
549 ldif.msg = objs->objects[i].msg;
550 ldb_ldif_write_file(s->ldb, stdout, &ldif);
551 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
557 for (i=0; i < linked_attributes_count; i++) {
558 const struct dsdb_attribute *sa;
560 if (!linked_attributes[i].identifier) {
561 return NT_STATUS_FOOBAR;
564 if (!linked_attributes[i].value.blob) {
565 return NT_STATUS_FOOBAR;
568 sa = dsdb_attribute_by_attributeID_id(s->schema,
569 linked_attributes[i].attid);
571 return NT_STATUS_FOOBAR;
574 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
575 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
576 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
578 linked_attributes[i].value.blob->data,
579 linked_attributes[i].value.blob->length);
586 bool torture_net_become_dc(struct torture_context *torture)
590 struct libnet_BecomeDC b;
591 struct libnet_UnbecomeDC u;
592 struct test_become_dc_state *s;
593 struct ldb_message *msg;
598 char *location = NULL;
599 torture_assert_ntstatus_ok(torture, torture_temp_dir(torture, "libnet_BecomeDC", &location),
600 "torture_temp_dir should return NT_STATUS_OK" );
602 s = talloc_zero(torture, struct test_become_dc_state);
603 if (!s) return false;
606 s->lp_ctx = torture->lp_ctx;
608 s->netbios_name = lp_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc");
609 if (!s->netbios_name || !s->netbios_name[0]) {
610 s->netbios_name = "smbtorturedc";
613 s->targetdir = location;
615 /* Join domain as a member server. */
616 s->tj = torture_join_domain(torture, s->netbios_name,
618 &s->machine_account);
620 DEBUG(0, ("%s failed to join domain as workstation\n",
625 s->ctx = libnet_context_init(torture->ev, torture->lp_ctx);
626 s->ctx->cred = cmdline_credentials;
628 s->ldb = ldb_init(s);
631 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
632 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
633 b.in.domain_sid = torture_join_sid(s->tj);
634 b.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
635 b.in.dest_dsa_netbios_name = s->netbios_name;
637 b.in.callbacks.private_data = s;
638 b.in.callbacks.check_options = test_become_dc_check_options;
639 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
640 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
641 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
642 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;
644 status = libnet_BecomeDC(s->ctx, s, &b);
645 if (!NT_STATUS_IS_OK(status)) {
646 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
651 msg = ldb_msg_new(s);
653 printf("ldb_msg_new() failed\n");
657 msg->dn = ldb_dn_new(msg, s->ldb, "@ROOTDSE");
659 printf("ldb_msg_new(@ROOTDSE) failed\n");
664 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
665 if (ldb_ret != LDB_SUCCESS) {
666 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
671 for (i=0; i < msg->num_elements; i++) {
672 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
675 printf("mark ROOTDSE with isSynchronized=TRUE\n");
676 ldb_ret = ldb_modify(s->ldb, msg);
677 if (ldb_ret != LDB_SUCCESS) {
678 printf("ldb_modify() failed: %d\n", ldb_ret);
684 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
687 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
688 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path));
689 s->ldb = ldb_wrap_connect(s, s->lp_ctx, sam_ldb_path,
690 system_session(s, s->lp_ctx),
693 DEBUG(0,("Failed to open '%s'\n",
699 s->schema = dsdb_get_schema(s->ldb);
701 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
706 /* Make sure we get this from the command line */
707 if (lp_parm_bool(toture->lp_ctx, NULL, "become dc", "do not unjoin", false)) {
714 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
715 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
716 u.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
717 u.in.dest_dsa_netbios_name = s->netbios_name;
719 status = libnet_UnbecomeDC(s->ctx, s, &u);
720 if (!NT_STATUS_IS_OK(status)) {
721 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
726 torture_leave_domain(s->tj);