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;
70 struct provision_result result;
73 struct loadparm_context *lp_ctx = loadparm_init(s);
77 return NT_STATUS_NO_MEMORY;
80 settings.site_name = p->dest_dsa->site_name;
81 settings.root_dn_str = p->forest->root_dn_str;
82 settings.domain_dn_str = p->domain->dn_str;
83 settings.config_dn_str = p->forest->config_dn_str;
84 settings.schema_dn_str = p->forest->schema_dn_str;
85 settings.netbios_name = p->dest_dsa->netbios_name;
86 settings.realm = torture_join_dom_dns_name(s->tj);
87 settings.domain = torture_join_dom_netbios_name(s->tj);
88 settings.server_dn_str = torture_join_server_dn_str(s->tj);
89 settings.machine_password = cli_credentials_get_password(s->machine_account);
90 settings.targetdir = s->targetdir;
92 status = provision_bare(s, s->lp_ctx, &settings, &result);
94 smbconf = talloc_asprintf(lp_ctx, "%s/%s", s->targetdir, "/etc/smb.conf");
96 ok = lp_load(lp_ctx, smbconf);
98 DEBUG(0,("Failed load freshly generated smb.conf '%s'\n", smbconf));
99 return NT_STATUS_INVALID_PARAMETER;
102 s->ldb = ldb_wrap_connect(s, lp_ctx, lp_sam_url(lp_ctx),
103 system_session(s, lp_ctx),
106 DEBUG(0,("Failed to open '%s'\n", lp_sam_url(lp_ctx)));
107 return NT_STATUS_INTERNAL_DB_ERROR;
110 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
112 DEBUG(0,("Failed to set cached ntds invocationId\n"));
113 return NT_STATUS_FOOBAR;
115 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
117 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
118 return NT_STATUS_FOOBAR;
128 static NTSTATUS test_become_dc_check_options(void *private_data,
129 const struct libnet_BecomeDC_CheckOptions *o)
131 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
133 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n",
135 o->domain->netbios_name, o->domain->dns_name));
137 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
138 o->source_dsa->dns_name, o->source_dsa->site_name));
140 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
141 "\tschema object_version[%u]\n"
142 "\tdomain behavior_version[%u]\n"
143 "\tdomain w2k3_update_revision[%u]\n",
144 o->forest->crossref_behavior_version,
145 o->forest->schema_object_version,
146 o->domain->behavior_version,
147 o->domain->w2k3_update_revision));
152 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
153 const struct libnet_BecomeDC_StoreChunk *c)
156 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
157 uint32_t total_object_count;
158 uint32_t object_count;
159 struct drsuapi_DsReplicaObjectListItemEx *first_object;
160 struct drsuapi_DsReplicaObjectListItemEx *cur;
161 uint32_t linked_attributes_count;
162 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
163 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
164 struct dsdb_extended_replicated_objects *objs;
165 struct repsFromTo1 *s_dsa;
167 struct ldb_message *msg;
168 struct ldb_val prefixMap_val;
169 struct ldb_message_element *prefixMap_el;
170 struct ldb_val schemaInfo_val;
176 DEBUG(0,("Analyze and apply schema objects\n"));
178 s_dsa = talloc_zero(s, struct repsFromTo1);
179 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
180 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
181 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
183 switch (c->ctr_level) {
185 mapping_ctr = &c->ctr1->mapping_ctr;
186 total_object_count = c->ctr1->total_object_count;
187 object_count = s->schema_part.object_count;
188 first_object = s->schema_part.first_object;
189 linked_attributes_count = 0;
190 linked_attributes = NULL;
191 s_dsa->highwatermark = c->ctr1->new_highwatermark;
192 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
193 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
194 uptodateness_vector = NULL; /* TODO: map it */
197 mapping_ctr = &c->ctr6->mapping_ctr;
198 total_object_count = c->ctr6->total_object_count;
199 object_count = s->schema_part.object_count;
200 first_object = s->schema_part.first_object;
201 linked_attributes_count = 0; /* TODO: ! */
202 linked_attributes = NULL; /* TODO: ! */;
203 s_dsa->highwatermark = c->ctr6->new_highwatermark;
204 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
205 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
206 uptodateness_vector = c->ctr6->uptodateness_vector;
209 return NT_STATUS_INVALID_PARAMETER;
212 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
213 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
214 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
215 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
217 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
218 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
219 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
220 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
221 s_dsa->other_info->dns_name = tmp_dns_name;
223 for (cur = first_object; cur; cur = cur->next_object) {
224 bool is_attr = false;
225 bool is_class = false;
227 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
228 struct drsuapi_DsReplicaAttribute *a;
230 const char *oid = NULL;
232 a = &cur->object.attribute_ctr.attributes[i];
233 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
234 if (!W_ERROR_IS_OK(status)) {
235 return werror_to_ntstatus(status);
239 case DRSUAPI_ATTRIBUTE_objectClass:
240 for (j=0; j < a->value_ctr.num_values; j++) {
241 uint32_t val = 0xFFFFFFFF;
243 if (a->value_ctr.values[i].blob
244 && a->value_ctr.values[i].blob->length == 4) {
245 val = IVAL(a->value_ctr.values[i].blob->data,0);
248 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
251 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
263 struct dsdb_attribute *sa;
265 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
266 NT_STATUS_HAVE_NO_MEMORY(sa);
268 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
269 if (!W_ERROR_IS_OK(status)) {
270 return werror_to_ntstatus(status);
273 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
277 struct dsdb_class *sc;
279 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
280 NT_STATUS_HAVE_NO_MEMORY(sc);
282 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
283 if (!W_ERROR_IS_OK(status)) {
284 return werror_to_ntstatus(status);
287 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
291 /* attach the schema to the ldb */
292 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
293 if (ret != LDB_SUCCESS) {
294 return NT_STATUS_FOOBAR;
296 /* we don't want to access the self made schema anymore */
297 s->self_made_schema = NULL;
298 s->schema = dsdb_get_schema(s->ldb);
300 status = dsdb_extended_replicated_objects_commit(s->ldb,
305 linked_attributes_count,
311 if (!W_ERROR_IS_OK(status)) {
312 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
313 return werror_to_ntstatus(status);
316 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
317 for (i=0; i < objs->num_objects; i++) {
318 struct ldb_ldif ldif;
319 fprintf(stdout, "#\n");
320 ldif.changetype = LDB_CHANGETYPE_NONE;
321 ldif.msg = objs->objects[i].msg;
322 ldb_ldif_write_file(s->ldb, stdout, &ldif);
323 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
327 msg = ldb_msg_new(objs);
328 NT_STATUS_HAVE_NO_MEMORY(msg);
329 msg->dn = objs->partition_dn;
331 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
332 if (!W_ERROR_IS_OK(status)) {
333 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
334 return werror_to_ntstatus(status);
337 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
338 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
339 if (ret != LDB_SUCCESS) {
340 return NT_STATUS_FOOBAR;
342 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
344 ret = ldb_modify(s->ldb, msg);
345 if (ret != LDB_SUCCESS) {
346 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
347 return NT_STATUS_FOOBAR;
354 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
357 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
358 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", sam_ldb_path));
359 s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, sam_ldb_path,
360 system_session(s, s->tctx->lp_ctx),
363 DEBUG(0,("Failed to open '%s'\n",
365 return NT_STATUS_INTERNAL_DB_ERROR;
368 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
370 DEBUG(0,("Failed to set cached ntds invocationId\n"));
371 return NT_STATUS_FOOBAR;
373 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
375 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
376 return NT_STATUS_FOOBAR;
379 s->schema = dsdb_get_schema(s->ldb);
381 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
382 return NT_STATUS_FOOBAR;
388 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
389 const struct libnet_BecomeDC_StoreChunk *c)
391 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
393 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
394 uint32_t total_object_count;
395 uint32_t object_count;
396 struct drsuapi_DsReplicaObjectListItemEx *first_object;
397 struct drsuapi_DsReplicaObjectListItemEx *cur;
399 switch (c->ctr_level) {
401 mapping_ctr = &c->ctr1->mapping_ctr;
402 total_object_count = c->ctr1->total_object_count;
403 object_count = c->ctr1->object_count;
404 first_object = c->ctr1->first_object;
407 mapping_ctr = &c->ctr6->mapping_ctr;
408 total_object_count = c->ctr6->total_object_count;
409 object_count = c->ctr6->object_count;
410 first_object = c->ctr6->first_object;
413 return NT_STATUS_INVALID_PARAMETER;
416 if (total_object_count) {
417 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
418 c->partition->nc.dn, object_count, total_object_count));
420 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
421 c->partition->nc.dn, object_count));
425 s->self_made_schema = dsdb_new_schema(s, lp_iconv_convenience(s->lp_ctx));
427 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
429 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
430 if (!W_ERROR_IS_OK(status)) {
431 return werror_to_ntstatus(status);
434 s->schema = s->self_made_schema;
436 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
437 if (!W_ERROR_IS_OK(status)) {
438 return werror_to_ntstatus(status);
442 if (!s->schema_part.first_object) {
443 s->schema_part.object_count = object_count;
444 s->schema_part.first_object = talloc_steal(s, first_object);
446 s->schema_part.object_count += object_count;
447 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
450 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
451 s->schema_part.last_object = cur;
453 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
454 return test_apply_schema(s, c);
460 static NTSTATUS test_become_dc_store_chunk(void *private_data,
461 const struct libnet_BecomeDC_StoreChunk *c)
463 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
465 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
466 uint32_t total_object_count;
467 uint32_t object_count;
468 struct drsuapi_DsReplicaObjectListItemEx *first_object;
469 uint32_t linked_attributes_count;
470 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
471 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
472 struct dsdb_extended_replicated_objects *objs;
473 struct repsFromTo1 *s_dsa;
477 s_dsa = talloc_zero(s, struct repsFromTo1);
478 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
479 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
480 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
482 switch (c->ctr_level) {
484 mapping_ctr = &c->ctr1->mapping_ctr;
485 total_object_count = c->ctr1->total_object_count;
486 object_count = c->ctr1->object_count;
487 first_object = c->ctr1->first_object;
488 linked_attributes_count = 0;
489 linked_attributes = NULL;
490 s_dsa->highwatermark = c->ctr1->new_highwatermark;
491 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
492 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
493 uptodateness_vector = NULL; /* TODO: map it */
496 mapping_ctr = &c->ctr6->mapping_ctr;
497 total_object_count = c->ctr6->total_object_count;
498 object_count = c->ctr6->object_count;
499 first_object = c->ctr6->first_object;
500 linked_attributes_count = c->ctr6->linked_attributes_count;
501 linked_attributes = c->ctr6->linked_attributes;
502 s_dsa->highwatermark = c->ctr6->new_highwatermark;
503 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
504 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
505 uptodateness_vector = c->ctr6->uptodateness_vector;
508 return NT_STATUS_INVALID_PARAMETER;
511 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
512 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
513 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
514 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
516 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
517 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
518 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
519 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
520 s_dsa->other_info->dns_name = tmp_dns_name;
522 if (total_object_count) {
523 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
524 c->partition->nc.dn, object_count, total_object_count));
526 DEBUG(0,("Partition[%s] objects[%u]\n",
527 c->partition->nc.dn, object_count));
530 status = dsdb_extended_replicated_objects_commit(s->ldb,
535 linked_attributes_count,
541 if (!W_ERROR_IS_OK(status)) {
542 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
543 return werror_to_ntstatus(status);
546 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
547 for (i=0; i < objs->num_objects; i++) {
548 struct ldb_ldif ldif;
549 fprintf(stdout, "#\n");
550 ldif.changetype = LDB_CHANGETYPE_NONE;
551 ldif.msg = objs->objects[i].msg;
552 ldb_ldif_write_file(s->ldb, stdout, &ldif);
553 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
559 for (i=0; i < linked_attributes_count; i++) {
560 const struct dsdb_attribute *sa;
562 if (!linked_attributes[i].identifier) {
563 return NT_STATUS_FOOBAR;
566 if (!linked_attributes[i].value.blob) {
567 return NT_STATUS_FOOBAR;
570 sa = dsdb_attribute_by_attributeID_id(s->schema,
571 linked_attributes[i].attid);
573 return NT_STATUS_FOOBAR;
576 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
577 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
578 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
580 linked_attributes[i].value.blob->data,
581 linked_attributes[i].value.blob->length);
588 bool torture_net_become_dc(struct torture_context *torture)
592 struct libnet_BecomeDC b;
593 struct libnet_UnbecomeDC u;
594 struct test_become_dc_state *s;
595 struct ldb_message *msg;
600 char *location = NULL;
601 torture_assert_ntstatus_ok(torture, torture_temp_dir(torture, "libnet_BecomeDC", &location),
602 "torture_temp_dir should return NT_STATUS_OK" );
604 s = talloc_zero(torture, struct test_become_dc_state);
605 if (!s) return false;
608 s->lp_ctx = torture->lp_ctx;
610 s->netbios_name = lp_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc");
611 if (!s->netbios_name || !s->netbios_name[0]) {
612 s->netbios_name = "smbtorturedc";
615 s->targetdir = location;
617 /* Join domain as a member server. */
618 s->tj = torture_join_domain(torture, s->netbios_name,
620 &s->machine_account);
622 DEBUG(0, ("%s failed to join domain as workstation\n",
627 s->ctx = libnet_context_init(torture->ev, torture->lp_ctx);
628 s->ctx->cred = cmdline_credentials;
630 s->ldb = ldb_init(s);
633 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
634 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
635 b.in.domain_sid = torture_join_sid(s->tj);
636 b.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
637 b.in.dest_dsa_netbios_name = s->netbios_name;
639 b.in.callbacks.private_data = s;
640 b.in.callbacks.check_options = test_become_dc_check_options;
641 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
642 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
643 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
644 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;
646 status = libnet_BecomeDC(s->ctx, s, &b);
647 if (!NT_STATUS_IS_OK(status)) {
648 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
653 msg = ldb_msg_new(s);
655 printf("ldb_msg_new() failed\n");
659 msg->dn = ldb_dn_new(msg, s->ldb, "@ROOTDSE");
661 printf("ldb_msg_new(@ROOTDSE) failed\n");
666 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
667 if (ldb_ret != LDB_SUCCESS) {
668 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
673 for (i=0; i < msg->num_elements; i++) {
674 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
677 printf("mark ROOTDSE with isSynchronized=TRUE\n");
678 ldb_ret = ldb_modify(s->ldb, msg);
679 if (ldb_ret != LDB_SUCCESS) {
680 printf("ldb_modify() failed: %d\n", ldb_ret);
686 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
689 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
690 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path));
691 s->ldb = ldb_wrap_connect(s, s->lp_ctx, sam_ldb_path,
692 system_session(s, s->lp_ctx),
695 DEBUG(0,("Failed to open '%s'\n",
701 s->schema = dsdb_get_schema(s->ldb);
703 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
708 /* Make sure we get this from the command line */
709 if (lp_parm_bool(torture->lp_ctx, NULL, "become dc", "do not unjoin", false)) {
716 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
717 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
718 u.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
719 u.in.dest_dsa_netbios_name = s->netbios_name;
721 status = libnet_UnbecomeDC(s->ctx, s, &u);
722 if (!NT_STATUS_IS_OK(status)) {
723 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
728 torture_leave_domain(s->tj);