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/rpc/rpc.h"
25 #include "libnet/libnet.h"
26 #include "dsdb/samdb/samdb.h"
27 #include "../lib/util/dlinklist.h"
28 #include "librpc/gen_ndr/ndr_drsuapi.h"
29 #include "librpc/gen_ndr/ndr_drsblobs.h"
30 #include "system/time.h"
31 #include "lib/ldb_wrap.h"
32 #include "auth/auth.h"
33 #include "param/param.h"
34 #include "param/provision.h"
35 #include "libcli/resolve/resolve.h"
37 struct test_become_dc_state {
38 struct libnet_context *ctx;
39 struct torture_context *tctx;
40 const char *netbios_name;
42 struct cli_credentials *machine_account;
43 struct dsdb_schema *self_made_schema;
44 const struct dsdb_schema *schema;
46 struct ldb_context *ldb;
49 uint32_t object_count;
50 struct drsuapi_DsReplicaObjectListItemEx *first_object;
51 struct drsuapi_DsReplicaObjectListItemEx *last_object;
54 const char *targetdir;
56 struct loadparm_context *lp_ctx;
59 static NTSTATUS test_become_dc_prepare_db(void *private_data,
60 const struct libnet_BecomeDC_PrepareDB *p)
62 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
63 struct provision_settings settings;
64 struct provision_result result;
67 settings.site_name = p->dest_dsa->site_name;
68 settings.root_dn_str = p->forest->root_dn_str;
69 settings.domain_dn_str = p->domain->dn_str;
70 settings.config_dn_str = p->forest->config_dn_str;
71 settings.schema_dn_str = p->forest->schema_dn_str;
72 settings.server_dn_str = torture_join_server_dn_str(s->tj);
73 settings.invocation_id = &p->dest_dsa->invocation_id;
74 settings.netbios_name = p->dest_dsa->netbios_name;
75 settings.host_ip = NULL;
76 settings.realm = torture_join_dom_dns_name(s->tj);
77 settings.domain = torture_join_dom_netbios_name(s->tj);
78 settings.ntds_dn_str = p->dest_dsa->ntds_dn_str;
79 settings.machine_password = cli_credentials_get_password(s->machine_account);
80 settings.targetdir = s->targetdir;
82 status = provision_bare(s, s->lp_ctx, &settings, &result);
84 s->ldb = result.samdb;
85 s->lp_ctx = result.lp_ctx;
91 static NTSTATUS test_become_dc_check_options(void *private_data,
92 const struct libnet_BecomeDC_CheckOptions *o)
94 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
96 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n",
98 o->domain->netbios_name, o->domain->dns_name));
100 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
101 o->source_dsa->dns_name, o->source_dsa->site_name));
103 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
104 "\tschema object_version[%u]\n"
105 "\tdomain behavior_version[%u]\n"
106 "\tdomain w2k3_update_revision[%u]\n",
107 o->forest->crossref_behavior_version,
108 o->forest->schema_object_version,
109 o->domain->behavior_version,
110 o->domain->w2k3_update_revision));
115 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
116 const struct libnet_BecomeDC_StoreChunk *c)
119 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
120 uint32_t object_count;
121 struct drsuapi_DsReplicaObjectListItemEx *first_object;
122 struct drsuapi_DsReplicaObjectListItemEx *cur;
123 uint32_t linked_attributes_count;
124 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
125 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
126 struct dsdb_extended_replicated_objects *objs;
127 struct repsFromTo1 *s_dsa;
129 struct ldb_message *msg;
130 struct ldb_val prefixMap_val;
131 struct ldb_message_element *prefixMap_el;
132 struct ldb_val schemaInfo_val;
139 DEBUG(0,("Analyze and apply schema objects\n"));
141 s_dsa = talloc_zero(s, struct repsFromTo1);
142 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
143 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
144 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
146 switch (c->ctr_level) {
148 mapping_ctr = &c->ctr1->mapping_ctr;
149 object_count = s->schema_part.object_count;
150 first_object = s->schema_part.first_object;
151 linked_attributes_count = 0;
152 linked_attributes = NULL;
153 s_dsa->highwatermark = c->ctr1->new_highwatermark;
154 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
155 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
156 uptodateness_vector = NULL; /* TODO: map it */
159 mapping_ctr = &c->ctr6->mapping_ctr;
160 object_count = s->schema_part.object_count;
161 first_object = s->schema_part.first_object;
162 linked_attributes_count = 0; /* TODO: ! */
163 linked_attributes = NULL; /* TODO: ! */;
164 s_dsa->highwatermark = c->ctr6->new_highwatermark;
165 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
166 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
167 uptodateness_vector = c->ctr6->uptodateness_vector;
170 return NT_STATUS_INVALID_PARAMETER;
173 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
174 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
175 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
176 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
178 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
179 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
180 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
181 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
182 s_dsa->other_info->dns_name = tmp_dns_name;
184 for (cur = first_object; cur; cur = cur->next_object) {
185 bool is_attr = false;
186 bool is_class = false;
188 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
189 struct drsuapi_DsReplicaAttribute *a;
191 const char *oid = NULL;
193 a = &cur->object.attribute_ctr.attributes[i];
194 status = dsdb_schema_pfm_oid_from_attid(s->self_made_schema->prefixmap,
196 if (!W_ERROR_IS_OK(status)) {
197 return werror_to_ntstatus(status);
201 case DRSUAPI_ATTRIBUTE_objectClass:
202 for (j=0; j < a->value_ctr.num_values; j++) {
203 uint32_t val = 0xFFFFFFFF;
205 if (a->value_ctr.values[i].blob
206 && a->value_ctr.values[i].blob->length == 4) {
207 val = IVAL(a->value_ctr.values[i].blob->data,0);
210 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
213 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
225 struct dsdb_attribute *sa;
227 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
228 NT_STATUS_HAVE_NO_MEMORY(sa);
230 status = dsdb_attribute_from_drsuapi(s->ldb, s->self_made_schema, &cur->object, s, sa);
231 if (!W_ERROR_IS_OK(status)) {
232 return werror_to_ntstatus(status);
235 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
239 struct dsdb_class *sc;
241 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
242 NT_STATUS_HAVE_NO_MEMORY(sc);
244 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
245 if (!W_ERROR_IS_OK(status)) {
246 return werror_to_ntstatus(status);
249 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
253 /* attach the schema to the ldb */
254 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
255 if (ret != LDB_SUCCESS) {
256 return NT_STATUS_FOOBAR;
258 /* we don't want to access the self made schema anymore */
259 s->self_made_schema = NULL;
260 s->schema = dsdb_get_schema(s->ldb);
262 status = dsdb_extended_replicated_objects_commit(s->ldb,
267 linked_attributes_count,
273 if (!W_ERROR_IS_OK(status)) {
274 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
275 return werror_to_ntstatus(status);
278 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
279 for (i=0; i < objs->num_objects; i++) {
280 struct ldb_ldif ldif;
281 fprintf(stdout, "#\n");
282 ldif.changetype = LDB_CHANGETYPE_NONE;
283 ldif.msg = objs->objects[i].msg;
284 ldb_ldif_write_file(s->ldb, stdout, &ldif);
285 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
289 msg = ldb_msg_new(objs);
290 NT_STATUS_HAVE_NO_MEMORY(msg);
291 msg->dn = objs->partition_dn;
293 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
294 if (!W_ERROR_IS_OK(status)) {
295 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
296 return werror_to_ntstatus(status);
299 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
300 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
301 if (ret != LDB_SUCCESS) {
302 return NT_STATUS_FOOBAR;
304 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
306 ret = ldb_modify(s->ldb, msg);
307 if (ret != LDB_SUCCESS) {
308 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
309 return NT_STATUS_FOOBAR;
316 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
319 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
320 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", sam_ldb_path));
321 s->ldb = ldb_wrap_connect(s, s->tctx->ev, s->tctx->lp_ctx, sam_ldb_path,
322 system_session(s->tctx->lp_ctx),
325 DEBUG(0,("Failed to open '%s'\n",
327 return NT_STATUS_INTERNAL_DB_ERROR;
330 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
332 DEBUG(0,("Failed to set cached ntds invocationId\n"));
333 return NT_STATUS_FOOBAR;
335 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
337 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
338 return NT_STATUS_FOOBAR;
341 s->schema = dsdb_get_schema(s->ldb);
343 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
344 return NT_STATUS_FOOBAR;
350 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
351 const struct libnet_BecomeDC_StoreChunk *c)
353 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
355 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
356 uint32_t nc_object_count;
357 uint32_t object_count;
358 struct drsuapi_DsReplicaObjectListItemEx *first_object;
359 struct drsuapi_DsReplicaObjectListItemEx *cur;
360 uint32_t nc_linked_attributes_count;
361 uint32_t linked_attributes_count;
363 switch (c->ctr_level) {
365 mapping_ctr = &c->ctr1->mapping_ctr;
366 nc_object_count = c->ctr1->extended_ret; /* maybe w2k send this unexpected? */
367 object_count = c->ctr1->object_count;
368 first_object = c->ctr1->first_object;
369 nc_linked_attributes_count = 0;
370 linked_attributes_count = 0;
373 mapping_ctr = &c->ctr6->mapping_ctr;
374 nc_object_count = c->ctr6->nc_object_count;
375 object_count = c->ctr6->object_count;
376 first_object = c->ctr6->first_object;
377 nc_linked_attributes_count = c->ctr6->nc_linked_attributes_count;
378 linked_attributes_count = c->ctr6->linked_attributes_count;
381 return NT_STATUS_INVALID_PARAMETER;
384 if (nc_object_count) {
385 DEBUG(0,("Schema-DN[%s] objects[%u/%u] linked_values[%u/%u]\n",
386 c->partition->nc.dn, object_count, nc_object_count,
387 linked_attributes_count, nc_linked_attributes_count));
389 DEBUG(0,("Schema-DN[%s] objects[%u] linked_values[%u\n",
390 c->partition->nc.dn, object_count, linked_attributes_count));
394 s->self_made_schema = dsdb_new_schema(s, lp_iconv_convenience(s->lp_ctx));
396 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
398 status = dsdb_load_prefixmap_from_drsuapi(s->self_made_schema, mapping_ctr);
399 if (!W_ERROR_IS_OK(status)) {
400 return werror_to_ntstatus(status);
403 s->schema = s->self_made_schema;
405 status = dsdb_schema_pfm_contains_drsuapi_pfm(s->schema->prefixmap, mapping_ctr);
406 if (!W_ERROR_IS_OK(status)) {
407 return werror_to_ntstatus(status);
411 if (!s->schema_part.first_object) {
412 s->schema_part.object_count = object_count;
413 s->schema_part.first_object = talloc_steal(s, first_object);
415 s->schema_part.object_count += object_count;
416 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
419 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
420 s->schema_part.last_object = cur;
422 if (!c->partition->more_data) {
423 return test_apply_schema(s, c);
429 static NTSTATUS test_become_dc_store_chunk(void *private_data,
430 const struct libnet_BecomeDC_StoreChunk *c)
432 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
434 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
435 uint32_t nc_object_count;
436 uint32_t object_count;
437 struct drsuapi_DsReplicaObjectListItemEx *first_object;
438 uint32_t nc_linked_attributes_count;
439 uint32_t linked_attributes_count;
440 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
441 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
442 struct dsdb_extended_replicated_objects *objs;
443 struct repsFromTo1 *s_dsa;
448 s_dsa = talloc_zero(s, struct repsFromTo1);
449 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
450 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
451 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
453 switch (c->ctr_level) {
455 mapping_ctr = &c->ctr1->mapping_ctr;
456 nc_object_count = c->ctr1->extended_ret; /* maybe w2k send this unexpected? */
457 object_count = c->ctr1->object_count;
458 first_object = c->ctr1->first_object;
459 nc_linked_attributes_count = 0;
460 linked_attributes_count = 0;
461 linked_attributes = NULL;
462 s_dsa->highwatermark = c->ctr1->new_highwatermark;
463 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
464 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
465 uptodateness_vector = NULL; /* TODO: map it */
468 mapping_ctr = &c->ctr6->mapping_ctr;
469 nc_object_count = c->ctr6->nc_object_count;
470 object_count = c->ctr6->object_count;
471 first_object = c->ctr6->first_object;
472 nc_linked_attributes_count = c->ctr6->nc_linked_attributes_count;
473 linked_attributes_count = c->ctr6->linked_attributes_count;
474 linked_attributes = c->ctr6->linked_attributes;
475 s_dsa->highwatermark = c->ctr6->new_highwatermark;
476 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
477 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
478 uptodateness_vector = c->ctr6->uptodateness_vector;
481 return NT_STATUS_INVALID_PARAMETER;
484 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
485 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
486 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
487 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
489 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
490 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
491 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
492 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
493 s_dsa->other_info->dns_name = tmp_dns_name;
495 if (nc_object_count) {
496 DEBUG(0,("Partition[%s] objects[%u/%u] linked_values[%u/%u]\n",
497 c->partition->nc.dn, object_count, nc_object_count,
498 linked_attributes_count, nc_linked_attributes_count));
500 DEBUG(0,("Partition[%s] objects[%u] linked_values[%u\n",
501 c->partition->nc.dn, object_count, linked_attributes_count));
504 status = dsdb_extended_replicated_objects_commit(s->ldb,
509 linked_attributes_count,
515 if (!W_ERROR_IS_OK(status)) {
516 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
517 return werror_to_ntstatus(status);
520 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
521 for (i=0; i < objs->num_objects; i++) {
522 struct ldb_ldif ldif;
523 fprintf(stdout, "#\n");
524 ldif.changetype = LDB_CHANGETYPE_NONE;
525 ldif.msg = objs->objects[i].msg;
526 ldb_ldif_write_file(s->ldb, stdout, &ldif);
527 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
533 for (i=0; i < linked_attributes_count; i++) {
534 const struct dsdb_attribute *sa;
536 if (!linked_attributes[i].identifier) {
537 return NT_STATUS_FOOBAR;
540 if (!linked_attributes[i].value.blob) {
541 return NT_STATUS_FOOBAR;
544 sa = dsdb_attribute_by_attributeID_id(s->schema,
545 linked_attributes[i].attid);
547 return NT_STATUS_FOOBAR;
550 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
551 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
552 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
554 linked_attributes[i].value.blob->data,
555 linked_attributes[i].value.blob->length);
562 bool torture_net_become_dc(struct torture_context *torture)
566 struct libnet_BecomeDC b;
567 struct libnet_UnbecomeDC u;
568 struct test_become_dc_state *s;
569 struct ldb_message *msg;
574 struct nbt_name name;
576 char *location = NULL;
577 torture_assert_ntstatus_ok(torture, torture_temp_dir(torture, "libnet_BecomeDC", &location),
578 "torture_temp_dir should return NT_STATUS_OK" );
580 s = talloc_zero(torture, struct test_become_dc_state);
581 if (!s) return false;
584 s->lp_ctx = torture->lp_ctx;
586 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL));
588 /* do an initial name resolution to find its IP */
589 status = resolve_name(lp_resolve_context(torture->lp_ctx),
590 &name, torture, &address, torture->ev);
591 if (!NT_STATUS_IS_OK(status)) {
592 printf("Failed to resolve %s - %s\n",
593 name.name, nt_errstr(status));
597 s->netbios_name = lp_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc");
598 if (!s->netbios_name || !s->netbios_name[0]) {
599 s->netbios_name = "smbtorturedc";
602 s->targetdir = location;
604 /* Join domain as a member server. */
605 s->tj = torture_join_domain(torture, s->netbios_name,
607 &s->machine_account);
609 DEBUG(0, ("%s failed to join domain as workstation\n",
614 s->ctx = libnet_context_init(torture->ev, torture->lp_ctx);
615 s->ctx->cred = cmdline_credentials;
617 s->ldb = ldb_init(s, torture->ev);
620 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
621 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
622 b.in.domain_sid = torture_join_sid(s->tj);
623 b.in.source_dsa_address = address;
624 b.in.dest_dsa_netbios_name = s->netbios_name;
626 b.in.callbacks.private_data = s;
627 b.in.callbacks.check_options = test_become_dc_check_options;
628 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
629 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
630 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
631 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;
633 status = libnet_BecomeDC(s->ctx, s, &b);
634 if (!NT_STATUS_IS_OK(status)) {
635 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
640 msg = ldb_msg_new(s);
642 printf("ldb_msg_new() failed\n");
646 msg->dn = ldb_dn_new(msg, s->ldb, "@ROOTDSE");
648 printf("ldb_msg_new(@ROOTDSE) failed\n");
653 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
654 if (ldb_ret != LDB_SUCCESS) {
655 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
660 for (i=0; i < msg->num_elements; i++) {
661 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
664 printf("mark ROOTDSE with isSynchronized=TRUE\n");
665 ldb_ret = ldb_modify(s->ldb, msg);
666 if (ldb_ret != LDB_SUCCESS) {
667 printf("ldb_modify() failed: %d\n", ldb_ret);
673 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
676 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb");
677 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path));
678 s->ldb = ldb_wrap_connect(s, s->tctx->ev, s->lp_ctx, sam_ldb_path,
679 system_session(s->lp_ctx),
682 DEBUG(0,("Failed to open '%s'\n",
688 s->schema = dsdb_get_schema(s->ldb);
690 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
695 /* Make sure we get this from the command line */
696 if (lp_parm_bool(torture->lp_ctx, NULL, "become dc", "do not unjoin", false)) {
703 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
704 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
705 u.in.source_dsa_address = address;
706 u.in.dest_dsa_netbios_name = s->netbios_name;
708 status = libnet_UnbecomeDC(s->ctx, s, &u);
709 if (!NT_STATUS_IS_OK(status)) {
710 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
715 torture_leave_domain(torture, s->tj);