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"
41 #include "param/provision.h"
43 struct test_become_dc_state {
44 struct libnet_context *ctx;
45 struct torture_context *tctx;
46 const char *netbios_name;
48 struct cli_credentials *machine_account;
49 struct dsdb_schema *self_made_schema;
50 const struct dsdb_schema *schema;
52 struct ldb_context *ldb;
55 uint32_t object_count;
56 struct drsuapi_DsReplicaObjectListItemEx *first_object;
57 struct drsuapi_DsReplicaObjectListItemEx *last_object;
60 const char *targetdir;
62 struct loadparm_context *lp_ctx;
65 static NTSTATUS test_become_dc_prepare_db(void *private_data,
66 const struct libnet_BecomeDC_PrepareDB *p)
68 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
69 struct provision_settings settings;
72 struct loadparm_context *lp_ctx = loadparm_init(s);
76 return NT_STATUS_NO_MEMORY;
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.server_dn_str = torture_join_server_dn_str(s->tj);
88 settings.machine_password = cli_credentials_get_password(s->machine_account);
89 settings.targetdir = s->targetdir;
91 status = provision_bare(s, s->lp_ctx, &settings);
93 smbconf = talloc_asprintf(lp_ctx, "%s/%s", s->targetdir, "/etc/smb.conf");
95 ok = lp_load(lp_ctx, smbconf);
97 DEBUG(0,("Failed load freshly generated smb.conf '%s'\n", smbconf));
98 return NT_STATUS_INVALID_PARAMETER;
101 s->ldb = ldb_wrap_connect(s, lp_ctx, lp_sam_url(lp_ctx),
102 system_session(s, lp_ctx),
105 DEBUG(0,("Failed to open '%s'\n", lp_sam_url(lp_ctx)));
106 return NT_STATUS_INTERNAL_DB_ERROR;
109 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
111 DEBUG(0,("Failed to set cached ntds invocationId\n"));
112 return NT_STATUS_FOOBAR;
114 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
116 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
117 return NT_STATUS_FOOBAR;
127 static NTSTATUS test_become_dc_check_options(void *private_data,
128 const struct libnet_BecomeDC_CheckOptions *o)
130 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
132 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n",
134 o->domain->netbios_name, o->domain->dns_name));
136 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
137 o->source_dsa->dns_name, o->source_dsa->site_name));
139 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
140 "\tschema object_version[%u]\n"
141 "\tdomain behavior_version[%u]\n"
142 "\tdomain w2k3_update_revision[%u]\n",
143 o->forest->crossref_behavior_version,
144 o->forest->schema_object_version,
145 o->domain->behavior_version,
146 o->domain->w2k3_update_revision));
151 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
152 const struct libnet_BecomeDC_StoreChunk *c)
155 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
156 uint32_t total_object_count;
157 uint32_t object_count;
158 struct drsuapi_DsReplicaObjectListItemEx *first_object;
159 struct drsuapi_DsReplicaObjectListItemEx *cur;
160 uint32_t linked_attributes_count;
161 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
162 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
163 struct dsdb_extended_replicated_objects *objs;
164 struct repsFromTo1 *s_dsa;
166 struct ldb_message *msg;
167 struct ldb_val prefixMap_val;
168 struct ldb_message_element *prefixMap_el;
169 struct ldb_val schemaInfo_val;
175 DEBUG(0,("Analyze and apply schema objects\n"));
177 s_dsa = talloc_zero(s, struct repsFromTo1);
178 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
179 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
180 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
182 switch (c->ctr_level) {
184 mapping_ctr = &c->ctr1->mapping_ctr;
185 total_object_count = c->ctr1->total_object_count;
186 object_count = s->schema_part.object_count;
187 first_object = s->schema_part.first_object;
188 linked_attributes_count = 0;
189 linked_attributes = NULL;
190 s_dsa->highwatermark = c->ctr1->new_highwatermark;
191 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
192 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
193 uptodateness_vector = NULL; /* TODO: map it */
196 mapping_ctr = &c->ctr6->mapping_ctr;
197 total_object_count = c->ctr6->total_object_count;
198 object_count = s->schema_part.object_count;
199 first_object = s->schema_part.first_object;
200 linked_attributes_count = 0; /* TODO: ! */
201 linked_attributes = NULL; /* TODO: ! */;
202 s_dsa->highwatermark = c->ctr6->new_highwatermark;
203 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
204 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
205 uptodateness_vector = c->ctr6->uptodateness_vector;
208 return NT_STATUS_INVALID_PARAMETER;
211 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
212 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
213 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
214 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
216 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
217 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
218 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
219 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
220 s_dsa->other_info->dns_name = tmp_dns_name;
222 for (cur = first_object; cur; cur = cur->next_object) {
223 bool is_attr = false;
224 bool is_class = false;
226 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
227 struct drsuapi_DsReplicaAttribute *a;
229 const char *oid = NULL;
231 a = &cur->object.attribute_ctr.attributes[i];
232 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
233 if (!W_ERROR_IS_OK(status)) {
234 return werror_to_ntstatus(status);
238 case DRSUAPI_ATTRIBUTE_objectClass:
239 for (j=0; j < a->value_ctr.num_values; j++) {
240 uint32_t val = 0xFFFFFFFF;
242 if (a->value_ctr.values[i].blob
243 && a->value_ctr.values[i].blob->length == 4) {
244 val = IVAL(a->value_ctr.values[i].blob->data,0);
247 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
250 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
262 struct dsdb_attribute *sa;
264 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
265 NT_STATUS_HAVE_NO_MEMORY(sa);
267 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
268 if (!W_ERROR_IS_OK(status)) {
269 return werror_to_ntstatus(status);
272 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
276 struct dsdb_class *sc;
278 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
279 NT_STATUS_HAVE_NO_MEMORY(sc);
281 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
282 if (!W_ERROR_IS_OK(status)) {
283 return werror_to_ntstatus(status);
286 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
290 /* attach the schema to the ldb */
291 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
292 if (ret != LDB_SUCCESS) {
293 return NT_STATUS_FOOBAR;
295 /* we don't want to access the self made schema anymore */
296 s->self_made_schema = NULL;
297 s->schema = dsdb_get_schema(s->ldb);
299 status = dsdb_extended_replicated_objects_commit(s->ldb,
304 linked_attributes_count,
310 if (!W_ERROR_IS_OK(status)) {
311 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
312 return werror_to_ntstatus(status);
315 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
316 for (i=0; i < objs->num_objects; i++) {
317 struct ldb_ldif ldif;
318 fprintf(stdout, "#\n");
319 ldif.changetype = LDB_CHANGETYPE_NONE;
320 ldif.msg = objs->objects[i].msg;
321 ldb_ldif_write_file(s->ldb, stdout, &ldif);
322 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
326 msg = ldb_msg_new(objs);
327 NT_STATUS_HAVE_NO_MEMORY(msg);
328 msg->dn = objs->partition_dn;
330 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
331 if (!W_ERROR_IS_OK(status)) {
332 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
333 return werror_to_ntstatus(status);
336 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
337 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
338 if (ret != LDB_SUCCESS) {
339 return NT_STATUS_FOOBAR;
341 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
343 ret = ldb_modify(s->ldb, msg);
344 if (ret != LDB_SUCCESS) {
345 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
346 return NT_STATUS_FOOBAR;
353 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
356 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
357 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", sam_ldb_path));
358 s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, sam_ldb_path,
359 system_session(s, s->tctx->lp_ctx),
362 DEBUG(0,("Failed to open '%s'\n",
364 return NT_STATUS_INTERNAL_DB_ERROR;
367 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
369 DEBUG(0,("Failed to set cached ntds invocationId\n"));
370 return NT_STATUS_FOOBAR;
372 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
374 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
375 return NT_STATUS_FOOBAR;
378 s->schema = dsdb_get_schema(s->ldb);
380 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
381 return NT_STATUS_FOOBAR;
387 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
388 const struct libnet_BecomeDC_StoreChunk *c)
390 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
392 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
393 uint32_t total_object_count;
394 uint32_t object_count;
395 struct drsuapi_DsReplicaObjectListItemEx *first_object;
396 struct drsuapi_DsReplicaObjectListItemEx *cur;
398 switch (c->ctr_level) {
400 mapping_ctr = &c->ctr1->mapping_ctr;
401 total_object_count = c->ctr1->total_object_count;
402 object_count = c->ctr1->object_count;
403 first_object = c->ctr1->first_object;
406 mapping_ctr = &c->ctr6->mapping_ctr;
407 total_object_count = c->ctr6->total_object_count;
408 object_count = c->ctr6->object_count;
409 first_object = c->ctr6->first_object;
412 return NT_STATUS_INVALID_PARAMETER;
415 if (total_object_count) {
416 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
417 c->partition->nc.dn, object_count, total_object_count));
419 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
420 c->partition->nc.dn, object_count));
424 s->self_made_schema = dsdb_new_schema(s, lp_iconv_convenience(s->lp_ctx));
426 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
428 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
429 if (!W_ERROR_IS_OK(status)) {
430 return werror_to_ntstatus(status);
433 s->schema = s->self_made_schema;
435 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
436 if (!W_ERROR_IS_OK(status)) {
437 return werror_to_ntstatus(status);
441 if (!s->schema_part.first_object) {
442 s->schema_part.object_count = object_count;
443 s->schema_part.first_object = talloc_steal(s, first_object);
445 s->schema_part.object_count += object_count;
446 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
449 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
450 s->schema_part.last_object = cur;
452 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
453 return test_apply_schema(s, c);
459 static NTSTATUS test_become_dc_store_chunk(void *private_data,
460 const struct libnet_BecomeDC_StoreChunk *c)
462 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
464 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
465 uint32_t total_object_count;
466 uint32_t object_count;
467 struct drsuapi_DsReplicaObjectListItemEx *first_object;
468 uint32_t linked_attributes_count;
469 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
470 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
471 struct dsdb_extended_replicated_objects *objs;
472 struct repsFromTo1 *s_dsa;
476 s_dsa = talloc_zero(s, struct repsFromTo1);
477 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
478 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
479 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
481 switch (c->ctr_level) {
483 mapping_ctr = &c->ctr1->mapping_ctr;
484 total_object_count = c->ctr1->total_object_count;
485 object_count = c->ctr1->object_count;
486 first_object = c->ctr1->first_object;
487 linked_attributes_count = 0;
488 linked_attributes = NULL;
489 s_dsa->highwatermark = c->ctr1->new_highwatermark;
490 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
491 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
492 uptodateness_vector = NULL; /* TODO: map it */
495 mapping_ctr = &c->ctr6->mapping_ctr;
496 total_object_count = c->ctr6->total_object_count;
497 object_count = c->ctr6->object_count;
498 first_object = c->ctr6->first_object;
499 linked_attributes_count = c->ctr6->linked_attributes_count;
500 linked_attributes = c->ctr6->linked_attributes;
501 s_dsa->highwatermark = c->ctr6->new_highwatermark;
502 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
503 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
504 uptodateness_vector = c->ctr6->uptodateness_vector;
507 return NT_STATUS_INVALID_PARAMETER;
510 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
511 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
512 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
513 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
515 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
516 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
517 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
518 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
519 s_dsa->other_info->dns_name = tmp_dns_name;
521 if (total_object_count) {
522 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
523 c->partition->nc.dn, object_count, total_object_count));
525 DEBUG(0,("Partition[%s] objects[%u]\n",
526 c->partition->nc.dn, object_count));
529 status = dsdb_extended_replicated_objects_commit(s->ldb,
534 linked_attributes_count,
540 if (!W_ERROR_IS_OK(status)) {
541 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
542 return werror_to_ntstatus(status);
545 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
546 for (i=0; i < objs->num_objects; i++) {
547 struct ldb_ldif ldif;
548 fprintf(stdout, "#\n");
549 ldif.changetype = LDB_CHANGETYPE_NONE;
550 ldif.msg = objs->objects[i].msg;
551 ldb_ldif_write_file(s->ldb, stdout, &ldif);
552 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
558 for (i=0; i < linked_attributes_count; i++) {
559 const struct dsdb_attribute *sa;
561 if (!linked_attributes[i].identifier) {
562 return NT_STATUS_FOOBAR;
565 if (!linked_attributes[i].value.blob) {
566 return NT_STATUS_FOOBAR;
569 sa = dsdb_attribute_by_attributeID_id(s->schema,
570 linked_attributes[i].attid);
572 return NT_STATUS_FOOBAR;
575 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
576 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
577 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
579 linked_attributes[i].value.blob->data,
580 linked_attributes[i].value.blob->length);
587 bool torture_net_become_dc(struct torture_context *torture)
591 struct libnet_BecomeDC b;
592 struct libnet_UnbecomeDC u;
593 struct test_become_dc_state *s;
594 struct ldb_message *msg;
599 char *location = NULL;
600 torture_assert_ntstatus_ok(torture, torture_temp_dir(torture, "libnet_BecomeDC", &location),
601 "torture_temp_dir should return NT_STATUS_OK" );
603 s = talloc_zero(torture, struct test_become_dc_state);
604 if (!s) return false;
607 s->lp_ctx = torture->lp_ctx;
609 s->netbios_name = lp_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc");
610 if (!s->netbios_name || !s->netbios_name[0]) {
611 s->netbios_name = "smbtorturedc";
614 s->targetdir = location;
616 /* Join domain as a member server. */
617 s->tj = torture_join_domain(torture, s->netbios_name,
619 &s->machine_account);
621 DEBUG(0, ("%s failed to join domain as workstation\n",
626 s->ctx = libnet_context_init(torture->ev, torture->lp_ctx);
627 s->ctx->cred = cmdline_credentials;
629 s->ldb = ldb_init(s);
632 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
633 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
634 b.in.domain_sid = torture_join_sid(s->tj);
635 b.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
636 b.in.dest_dsa_netbios_name = s->netbios_name;
638 b.in.callbacks.private_data = s;
639 b.in.callbacks.check_options = test_become_dc_check_options;
640 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
641 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
642 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
643 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;
645 status = libnet_BecomeDC(s->ctx, s, &b);
646 if (!NT_STATUS_IS_OK(status)) {
647 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
652 msg = ldb_msg_new(s);
654 printf("ldb_msg_new() failed\n");
658 msg->dn = ldb_dn_new(msg, s->ldb, "@ROOTDSE");
660 printf("ldb_msg_new(@ROOTDSE) failed\n");
665 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
666 if (ldb_ret != LDB_SUCCESS) {
667 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
672 for (i=0; i < msg->num_elements; i++) {
673 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
676 printf("mark ROOTDSE with isSynchronized=TRUE\n");
677 ldb_ret = ldb_modify(s->ldb, msg);
678 if (ldb_ret != LDB_SUCCESS) {
679 printf("ldb_modify() failed: %d\n", ldb_ret);
685 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
688 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
689 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path));
690 s->ldb = ldb_wrap_connect(s, s->lp_ctx, sam_ldb_path,
691 system_session(s, s->lp_ctx),
694 DEBUG(0,("Failed to open '%s'\n",
700 s->schema = dsdb_get_schema(s->ldb);
702 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
707 /* Make sure we get this from the command line */
708 if (lp_parm_bool(torture->lp_ctx, NULL, "become dc", "do not unjoin", false)) {
715 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
716 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
717 u.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
718 u.in.dest_dsa_netbios_name = s->netbios_name;
720 status = libnet_UnbecomeDC(s->ctx, s, &u);
721 if (!NT_STATUS_IS_OK(status)) {
722 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
727 torture_leave_domain(s->tj);