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_provision.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;
60 const char *samdb_ldb;
61 const char *domaindn_ldb;
62 const char *configdn_ldb;
63 const char *schemadn_ldb;
64 const char *secrets_ldb;
65 const char *templates_ldb;
66 const char *secrets_keytab;
67 const char *dns_keytab;
71 static NTSTATUS test_become_dc_prepare_db(void *private_data,
72 const struct libnet_BecomeDC_PrepareDB *p)
74 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
75 struct provision_settings settings;
77 settings.dns_name = p->dest_dsa->dns_name;
78 settings.site_name = p->dest_dsa->site_name;
79 settings.root_dn_str = p->forest->root_dn_str;
80 settings.domain_dn_str = p->domain->dn_str;
81 settings.config_dn_str = p->forest->config_dn_str;
82 settings.schema_dn_str = p->forest->schema_dn_str;
83 settings.invocation_id = &p->dest_dsa->invocation_id;
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.ntds_guid = &p->dest_dsa->ntds_guid;
88 settings.ntds_dn_str = p->dest_dsa->ntds_dn_str;
89 settings.machine_password = cli_credentials_get_password(s->machine_account);
90 settings.samdb_ldb = s->path.samdb_ldb;
91 settings.secrets_ldb = s->path.secrets_ldb;
92 settings.secrets_keytab = s->path.secrets_keytab;
93 settings.schemadn_ldb = s->path.schemadn_ldb;
94 settings.configdn_ldb = s->path.configdn_ldb;
95 settings.domaindn_ldb = s->path.domaindn_ldb;
97 return provision_bare(s, s->tctx->lp_ctx, &settings);
100 static NTSTATUS test_become_dc_check_options(void *private_data,
101 const struct libnet_BecomeDC_CheckOptions *o)
103 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
105 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n",
107 o->domain->netbios_name, o->domain->dns_name));
109 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
110 o->source_dsa->dns_name, o->source_dsa->site_name));
112 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
113 "\tschema object_version[%u]\n"
114 "\tdomain behavior_version[%u]\n"
115 "\tdomain w2k3_update_revision[%u]\n",
116 o->forest->crossref_behavior_version,
117 o->forest->schema_object_version,
118 o->domain->behavior_version,
119 o->domain->w2k3_update_revision));
124 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
125 const struct libnet_BecomeDC_StoreChunk *c)
128 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
129 uint32_t total_object_count;
130 uint32_t object_count;
131 struct drsuapi_DsReplicaObjectListItemEx *first_object;
132 struct drsuapi_DsReplicaObjectListItemEx *cur;
133 uint32_t linked_attributes_count;
134 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
135 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
136 struct dsdb_extended_replicated_objects *objs;
137 struct repsFromTo1 *s_dsa;
139 struct ldb_message *msg;
140 struct ldb_val prefixMap_val;
141 struct ldb_message_element *prefixMap_el;
142 struct ldb_val schemaInfo_val;
147 DEBUG(0,("Analyze and apply schema objects\n"));
149 s_dsa = talloc_zero(s, struct repsFromTo1);
150 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
151 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
152 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
154 switch (c->ctr_level) {
156 mapping_ctr = &c->ctr1->mapping_ctr;
157 total_object_count = c->ctr1->total_object_count;
158 object_count = s->schema_part.object_count;
159 first_object = s->schema_part.first_object;
160 linked_attributes_count = 0;
161 linked_attributes = NULL;
162 s_dsa->highwatermark = c->ctr1->new_highwatermark;
163 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
164 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
165 uptodateness_vector = NULL; /* TODO: map it */
168 mapping_ctr = &c->ctr6->mapping_ctr;
169 total_object_count = c->ctr6->total_object_count;
170 object_count = s->schema_part.object_count;
171 first_object = s->schema_part.first_object;
172 linked_attributes_count = 0; /* TODO: ! */
173 linked_attributes = NULL; /* TODO: ! */;
174 s_dsa->highwatermark = c->ctr6->new_highwatermark;
175 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
176 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
177 uptodateness_vector = c->ctr6->uptodateness_vector;
180 return NT_STATUS_INVALID_PARAMETER;
183 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
184 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
185 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
186 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
188 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
189 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
190 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
191 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
192 s_dsa->other_info->dns_name = tmp_dns_name;
194 for (cur = first_object; cur; cur = cur->next_object) {
195 bool is_attr = false;
196 bool is_class = false;
198 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
199 struct drsuapi_DsReplicaAttribute *a;
201 const char *oid = NULL;
203 a = &cur->object.attribute_ctr.attributes[i];
204 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
205 if (!W_ERROR_IS_OK(status)) {
206 return werror_to_ntstatus(status);
210 case DRSUAPI_ATTRIBUTE_objectClass:
211 for (j=0; j < a->value_ctr.num_values; j++) {
212 uint32_t val = 0xFFFFFFFF;
214 if (a->value_ctr.values[i].blob
215 && a->value_ctr.values[i].blob->length == 4) {
216 val = IVAL(a->value_ctr.values[i].blob->data,0);
219 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
222 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
234 struct dsdb_attribute *sa;
236 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
237 NT_STATUS_HAVE_NO_MEMORY(sa);
239 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
240 if (!W_ERROR_IS_OK(status)) {
241 return werror_to_ntstatus(status);
244 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
248 struct dsdb_class *sc;
250 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
251 NT_STATUS_HAVE_NO_MEMORY(sc);
253 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
254 if (!W_ERROR_IS_OK(status)) {
255 return werror_to_ntstatus(status);
258 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
262 /* attach the schema to the ldb */
263 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
264 if (ret != LDB_SUCCESS) {
265 return NT_STATUS_FOOBAR;
267 /* we don't want to access the self made schema anymore */
268 s->self_made_schema = NULL;
269 s->schema = dsdb_get_schema(s->ldb);
271 status = dsdb_extended_replicated_objects_commit(s->ldb,
276 linked_attributes_count,
282 if (!W_ERROR_IS_OK(status)) {
283 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
284 return werror_to_ntstatus(status);
287 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
288 for (i=0; i < objs->num_objects; i++) {
289 struct ldb_ldif ldif;
290 fprintf(stdout, "#\n");
291 ldif.changetype = LDB_CHANGETYPE_NONE;
292 ldif.msg = objs->objects[i].msg;
293 ldb_ldif_write_file(s->ldb, stdout, &ldif);
294 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
298 msg = ldb_msg_new(objs);
299 NT_STATUS_HAVE_NO_MEMORY(msg);
300 msg->dn = objs->partition_dn;
302 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
303 if (!W_ERROR_IS_OK(status)) {
304 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
305 return werror_to_ntstatus(status);
308 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
309 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
310 if (ret != LDB_SUCCESS) {
311 return NT_STATUS_FOOBAR;
313 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
315 ret = ldb_modify(s->ldb, msg);
316 if (ret != LDB_SUCCESS) {
317 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
318 return NT_STATUS_FOOBAR;
325 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
328 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", s->path.samdb_ldb));
329 s->ldb = ldb_wrap_connect(s, s->tctx->lp_ctx, s->path.samdb_ldb,
330 system_session(s, s->tctx->lp_ctx),
333 DEBUG(0,("Failed to open '%s'\n",
335 return NT_STATUS_INTERNAL_DB_ERROR;
338 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
340 DEBUG(0,("Failed to set cached ntds invocationId\n"));
341 return NT_STATUS_FOOBAR;
343 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
345 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
346 return NT_STATUS_FOOBAR;
349 s->schema = dsdb_get_schema(s->ldb);
351 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
352 return NT_STATUS_FOOBAR;
358 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
359 const struct libnet_BecomeDC_StoreChunk *c)
361 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
363 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
364 uint32_t total_object_count;
365 uint32_t object_count;
366 struct drsuapi_DsReplicaObjectListItemEx *first_object;
367 struct drsuapi_DsReplicaObjectListItemEx *cur;
369 switch (c->ctr_level) {
371 mapping_ctr = &c->ctr1->mapping_ctr;
372 total_object_count = c->ctr1->total_object_count;
373 object_count = c->ctr1->object_count;
374 first_object = c->ctr1->first_object;
377 mapping_ctr = &c->ctr6->mapping_ctr;
378 total_object_count = c->ctr6->total_object_count;
379 object_count = c->ctr6->object_count;
380 first_object = c->ctr6->first_object;
383 return NT_STATUS_INVALID_PARAMETER;
386 if (total_object_count) {
387 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
388 c->partition->nc.dn, object_count, total_object_count));
390 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
391 c->partition->nc.dn, object_count));
395 s->self_made_schema = talloc_zero(s, struct dsdb_schema);
396 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
398 status = dsdb_load_oid_mappings_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_verify_oid_mappings_drsuapi(s->schema, 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->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
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 total_object_count;
436 uint32_t object_count;
437 struct drsuapi_DsReplicaObjectListItemEx *first_object;
438 uint32_t linked_attributes_count;
439 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
440 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
441 struct dsdb_extended_replicated_objects *objs;
442 struct repsFromTo1 *s_dsa;
446 s_dsa = talloc_zero(s, struct repsFromTo1);
447 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
448 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
449 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
451 switch (c->ctr_level) {
453 mapping_ctr = &c->ctr1->mapping_ctr;
454 total_object_count = c->ctr1->total_object_count;
455 object_count = c->ctr1->object_count;
456 first_object = c->ctr1->first_object;
457 linked_attributes_count = 0;
458 linked_attributes = NULL;
459 s_dsa->highwatermark = c->ctr1->new_highwatermark;
460 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
461 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
462 uptodateness_vector = NULL; /* TODO: map it */
465 mapping_ctr = &c->ctr6->mapping_ctr;
466 total_object_count = c->ctr6->total_object_count;
467 object_count = c->ctr6->object_count;
468 first_object = c->ctr6->first_object;
469 linked_attributes_count = c->ctr6->linked_attributes_count;
470 linked_attributes = c->ctr6->linked_attributes;
471 s_dsa->highwatermark = c->ctr6->new_highwatermark;
472 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
473 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
474 uptodateness_vector = c->ctr6->uptodateness_vector;
477 return NT_STATUS_INVALID_PARAMETER;
480 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
481 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
482 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
483 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
485 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
486 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
487 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
488 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
489 s_dsa->other_info->dns_name = tmp_dns_name;
491 if (total_object_count) {
492 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
493 c->partition->nc.dn, object_count, total_object_count));
495 DEBUG(0,("Partition[%s] objects[%u]\n",
496 c->partition->nc.dn, object_count));
499 status = dsdb_extended_replicated_objects_commit(s->ldb,
504 linked_attributes_count,
510 if (!W_ERROR_IS_OK(status)) {
511 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
512 return werror_to_ntstatus(status);
515 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
516 for (i=0; i < objs->num_objects; i++) {
517 struct ldb_ldif ldif;
518 fprintf(stdout, "#\n");
519 ldif.changetype = LDB_CHANGETYPE_NONE;
520 ldif.msg = objs->objects[i].msg;
521 ldb_ldif_write_file(s->ldb, stdout, &ldif);
522 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
528 for (i=0; i < linked_attributes_count; i++) {
529 const struct dsdb_attribute *sa;
531 if (!linked_attributes[i].identifier) {
532 return NT_STATUS_FOOBAR;
535 if (!linked_attributes[i].value.blob) {
536 return NT_STATUS_FOOBAR;
539 sa = dsdb_attribute_by_attributeID_id(s->schema,
540 linked_attributes[i].attid);
542 return NT_STATUS_FOOBAR;
545 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) {
546 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
547 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
549 linked_attributes[i].value.blob->data,
550 linked_attributes[i].value.blob->length);
557 bool torture_net_become_dc(struct torture_context *torture)
561 struct libnet_BecomeDC b;
562 struct libnet_UnbecomeDC u;
563 struct test_become_dc_state *s;
564 struct ldb_message *msg;
568 s = talloc_zero(torture, struct test_become_dc_state);
569 if (!s) return false;
573 s->netbios_name = lp_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc");
574 if (!s->netbios_name || !s->netbios_name[0]) {
575 s->netbios_name = "smbtorturedc";
578 s->path.samdb_ldb = talloc_asprintf(s, "%s_samdb.ldb", s->netbios_name);
579 if (!s->path.samdb_ldb) return false;
580 s->path.domaindn_ldb = talloc_asprintf(s, "%s_domain.ldb", s->netbios_name);
581 if (!s->path.domaindn_ldb) return false;
582 s->path.configdn_ldb = talloc_asprintf(s, "%s_config.ldb", s->netbios_name);
583 if (!s->path.configdn_ldb) return false;
584 s->path.schemadn_ldb = talloc_asprintf(s, "%s_schema.ldb", s->netbios_name);
585 if (!s->path.schemadn_ldb) return false;
586 s->path.secrets_ldb = talloc_asprintf(s, "%s_secrets.ldb", s->netbios_name);
587 if (!s->path.secrets_ldb) return false;
588 s->path.templates_ldb = talloc_asprintf(s, "%s_templates.ldb", s->netbios_name);
589 if (!s->path.templates_ldb) return false;
590 s->path.secrets_keytab = talloc_asprintf(s, "%s_secrets.keytab", s->netbios_name);
591 if (!s->path.secrets_keytab) return false;
592 s->path.dns_keytab = talloc_asprintf(s, "%s_dns.keytab", s->netbios_name);
593 if (!s->path.dns_keytab) return false;
595 /* Join domain as a member server. */
596 s->tj = torture_join_domain(torture, s->netbios_name,
598 &s->machine_account);
600 DEBUG(0, ("%s failed to join domain as workstation\n",
605 s->ctx = libnet_context_init(torture->ev, torture->lp_ctx);
606 s->ctx->cred = cmdline_credentials;
608 s->ldb = ldb_init(s);
611 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
612 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
613 b.in.domain_sid = torture_join_sid(s->tj);
614 b.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
615 b.in.dest_dsa_netbios_name = s->netbios_name;
617 b.in.callbacks.private_data = s;
618 b.in.callbacks.check_options = test_become_dc_check_options;
619 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
620 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
621 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
622 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;
624 status = libnet_BecomeDC(s->ctx, s, &b);
625 if (!NT_STATUS_IS_OK(status)) {
626 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
631 msg = ldb_msg_new(s);
633 printf("ldb_msg_new() failed\n");
637 msg->dn = ldb_dn_new(msg, s->ldb, "@ROOTDSE");
639 printf("ldb_msg_new(@ROOTDSE) failed\n");
644 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
645 if (ldb_ret != LDB_SUCCESS) {
646 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
651 for (i=0; i < msg->num_elements; i++) {
652 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
655 printf("mark ROOTDSE with isSynchronized=TRUE\n");
656 ldb_ret = ldb_modify(s->ldb, msg);
657 if (ldb_ret != LDB_SUCCESS) {
658 printf("ldb_modify() failed: %d\n", ldb_ret);
664 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
667 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", s->path.samdb_ldb));
668 s->ldb = ldb_wrap_connect(s, torture->lp_ctx, s->path.samdb_ldb,
669 system_session(s, torture->lp_ctx),
672 DEBUG(0,("Failed to open '%s'\n",
678 s->schema = dsdb_get_schema(s->ldb);
680 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
685 if (lp_parm_bool(torture->lp_ctx, NULL, "become dc", "do not unjoin", false)) {
692 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
693 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
694 u.in.source_dsa_address = torture_setting_string(torture, "host", NULL);
695 u.in.dest_dsa_netbios_name = s->netbios_name;
697 status = libnet_UnbecomeDC(s->ctx, s, &u);
698 if (!NT_STATUS_IS_OK(status)) {
699 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
704 torture_leave_domain(s->tj);