2 Unix SMB/CIFS implementation.
4 libnet_BecomeDC() tests
6 Copyright (C) Stefan (metze) Metzmacher 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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/cmdline/popt_common.h"
25 #include "torture/torture.h"
26 #include "torture/rpc/rpc.h"
27 #include "libnet/libnet.h"
28 #include "lib/events/events.h"
29 #include "dsdb/samdb/samdb.h"
30 #include "lib/util/dlinklist.h"
31 #include "lib/ldb/include/ldb.h"
32 #include "lib/ldb/include/ldb_errors.h"
33 #include "librpc/ndr/libndr.h"
34 #include "librpc/gen_ndr/ndr_drsuapi.h"
35 #include "librpc/gen_ndr/ndr_drsblobs.h"
36 #include "librpc/gen_ndr/ndr_misc.h"
37 #include "system/time.h"
38 #include "auth/auth.h"
39 #include "lib/db_wrap.h"
40 #include "lib/appweb/ejs/ejs.h"
41 #include "lib/appweb/ejs/ejsInternal.h"
42 #include "scripting/ejs/smbcalls.h"
47 static void test_ejs_exception(const char *reason)
49 Ejs *ep = ejsPtr(eid);
50 ejsSetErrorMsg(eid, "%s", reason);
51 fprintf(stderr, "%s", ep->error);
55 static int test_run_ejs(char *script)
60 TALLOC_CTX *mem_ctx = talloc_new(NULL);
61 struct MprVar *return_var;
65 if (ejsOpen(NULL, NULL, NULL) != 0) {
66 d_printf("ejsOpen(): unable to initialise EJS subsystem\n");
71 smb_setup_ejs_functions(test_ejs_exception);
73 if ((eid = ejsOpenEngine(handle, 0)) == (EjsId)-1) {
74 d_printf("smbscript: ejsOpenEngine(): unable to initialise an EJS engine\n");
79 mprSetVar(ejsGetGlobalObject(eid), "ARGV", mprList("ARGV", NULL));
82 if (ejsEvalScript(eid, script, &result, &emsg) == -1) {
83 d_printf("smbscript: ejsEvalScript(): %s\n", emsg);
84 if (ejs_error == 0) ejs_error = 127;
88 return_var = ejsGetReturnValue(eid);
89 ejs_error = mprVarToNumber(return_var);
97 #define TORTURE_NETBIOS_NAME "smbtorturedc"
98 #define TORTURE_SAMDB_LDB "test_samdb.ldb"
99 #define TORTURE_SECRETS_LDB "test_secrets.ldb"
100 #define TORTURE_SECRETS_KEYTAB "test_secrets.keytab"
102 struct test_become_dc_state {
103 struct libnet_context *ctx;
104 struct test_join *tj;
105 struct cli_credentials *machine_account;
106 struct dsdb_schema *self_made_schema;
107 const struct dsdb_schema *schema;
109 struct ldb_context *ldb;
112 uint32_t object_count;
113 struct drsuapi_DsReplicaObjectListItemEx *first_object;
114 struct drsuapi_DsReplicaObjectListItemEx *last_object;
118 static NTSTATUS test_become_dc_check_options(void *private_data,
119 const struct libnet_BecomeDC_CheckOptions *o)
121 DEBUG(0,("Become DC of Domain[%s]/[%s]\n",
122 o->domain->netbios_name, o->domain->dns_name));
124 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
125 o->source_dsa->dns_name, o->source_dsa->site_name));
127 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
128 "\tschema object_version[%u]\n"
129 "\tdomain behavior_version[%u]\n"
130 "\tdomain w2k3_update_revision[%u]\n",
131 o->forest->crossref_behavior_version,
132 o->forest->schema_object_version,
133 o->domain->behavior_version,
134 o->domain->w2k3_update_revision));
139 static NTSTATUS test_become_dc_prepare_db(void *private_data,
140 const struct libnet_BecomeDC_PrepareDB *p)
142 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
147 DEBUG(0,("New Server[%s] in Site[%s]\n",
148 p->dest_dsa->dns_name, p->dest_dsa->site_name));
150 DEBUG(0,("DSA Instance [%s]\n"
152 "\tinvocationId[%s]\n",
153 p->dest_dsa->ntds_dn_str,
154 GUID_string(s, &p->dest_dsa->ntds_guid),
155 GUID_string(s, &p->dest_dsa->invocation_id)));
157 DEBUG(0,("Schema Partition[%s]\n",
158 p->forest->schema_dn_str));
160 DEBUG(0,("Config Partition[%s]\n",
161 p->forest->config_dn_str));
163 DEBUG(0,("Domain Partition[%s]\n",
166 ejs = talloc_asprintf(s,
167 "libinclude(\"base.js\");\n"
168 "libinclude(\"provision.js\");\n"
170 "function message() { print(vsprintf(arguments)); }\n"
172 "var subobj = provision_guess();\n"
173 "subobj.ROOTDN = \"%s\";\n"
174 "subobj.DOMAINDN = \"%s\";\n"
175 "subobj.DOMAINDN_LDB = \"test_domain.ldb\";\n"
176 "subobj.CONFIGDN = \"%s\";\n"
177 "subobj.CONFIGDN_LDB = \"test_config.ldb\";\n"
178 "subobj.SCHEMADN = \"%s\";\n"
179 "subobj.SCHEMADN_LDB = \"test_schema.ldb\";\n"
180 "subobj.HOSTNAME = \"%s\";\n"
181 "subobj.DNSNAME = \"%s\";\n"
182 "subobj.DEFAULTSITE = \"%s\";\n"
184 "modules_list = new Array(\"rootdse\",\n"
186 " \"paged_results\",\n"
187 " \"server_sort\",\n"
188 " \"extended_dn\",\n"
191 " \"password_hash\",\n"
192 " \"operational\",\n"
193 " \"objectclass\",\n"
196 "subobj.MODULES_LIST = join(\",\", modules_list);\n"
197 "subobj.DOMAINDN_MOD = \"pdc_fsmo,repl_meta_data\";\n"
198 "subobj.CONFIGDN_MOD = \"naming_fsmo,repl_meta_data\";\n"
199 "subobj.SCHEMADN_MOD = \"schema_fsmo,repl_meta_data\";\n"
201 "subobj.KRBTGTPASS = \"test\";\n"
202 "subobj.MACHINEPASS = \"test\";\n"
203 "subobj.ADMINPASS = \"test\";\n"
205 "var paths = provision_default_paths(subobj);\n"
206 "paths.samdb = \"%s\";\n"
207 "paths.secrets = \"%s\";\n"
208 "paths.keytab = \"%s\";\n"
210 "var system_session = system_session();\n"
212 "var ok = provision_become_dc(subobj, message, paths, system_session);\n"
216 p->forest->root_dn_str, /* subobj.ROOTDN */
217 p->domain->dn_str, /* subobj.DOMAINDN */
218 p->forest->config_dn_str, /* subobj.CONFIGDN */
219 p->forest->schema_dn_str, /* subobj.SCHEMADN */
220 p->dest_dsa->netbios_name, /* subobj.HOSTNAME */
221 p->dest_dsa->dns_name, /* subobj.DNSNAME */
222 p->dest_dsa->site_name, /* subobj.DEFAULTSITE */
223 TORTURE_SAMDB_LDB, /* paths.samdb */
224 TORTURE_SECRETS_LDB, /* paths.secrets */
225 TORTURE_SECRETS_KEYTAB); /* paths.keytab */
226 NT_STATUS_HAVE_NO_MEMORY(ejs);
228 ret = test_run_ejs(ejs);
230 DEBUG(0,("Failed to run ejs script: %d:\n%s",
233 return NT_STATUS_FOOBAR;
239 DEBUG(0,("Open the SAM LDB with system credentials: %s\n", TORTURE_SAMDB_LDB));
241 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
245 DEBUG(0,("Failed to open '%s'\n",
247 return NT_STATUS_INTERNAL_DB_ERROR;
250 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
252 DEBUG(0,("Failed to set cached ntds invocationId\n"));
253 return NT_STATUS_FOOBAR;
255 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
257 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
258 return NT_STATUS_FOOBAR;
264 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
265 const struct libnet_BecomeDC_StoreChunk *c)
268 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
269 uint32_t total_object_count;
270 uint32_t object_count;
271 struct drsuapi_DsReplicaObjectListItemEx *first_object;
272 struct drsuapi_DsReplicaObjectListItemEx *cur;
273 uint32_t linked_attributes_count;
274 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
275 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
276 struct dsdb_extended_replicated_objects *objs;
277 struct repsFromTo1 *s_dsa;
279 struct ldb_message *msg;
280 struct ldb_val prefixMap_val;
281 struct ldb_message_element *prefixMap_el;
282 struct ldb_val schemaInfo_val;
287 DEBUG(0,("Analyze and apply schema objects\n"));
289 s_dsa = talloc_zero(s, struct repsFromTo1);
290 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
291 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
292 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
294 switch (c->ctr_level) {
296 mapping_ctr = &c->ctr1->mapping_ctr;
297 total_object_count = c->ctr1->total_object_count;
298 object_count = s->schema_part.object_count;
299 first_object = s->schema_part.first_object;
300 linked_attributes_count = 0;
301 linked_attributes = NULL;
302 s_dsa->highwatermark = c->ctr1->new_highwatermark;
303 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
304 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
305 uptodateness_vector = NULL; /* TODO: map it */
308 mapping_ctr = &c->ctr6->mapping_ctr;
309 total_object_count = c->ctr6->total_object_count;
310 object_count = s->schema_part.object_count;
311 first_object = s->schema_part.first_object;
312 linked_attributes_count = 0; /* TODO: ! */
313 linked_attributes = NULL; /* TODO: ! */;
314 s_dsa->highwatermark = c->ctr6->new_highwatermark;
315 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
316 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
317 uptodateness_vector = c->ctr6->uptodateness_vector;
320 return NT_STATUS_INVALID_PARAMETER;
323 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
324 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
325 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
326 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
328 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
329 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
330 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
331 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
332 s_dsa->other_info->dns_name = tmp_dns_name;
334 for (cur = first_object; cur; cur = cur->next_object) {
335 bool is_attr = false;
336 bool is_class = false;
338 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
339 struct drsuapi_DsReplicaAttribute *a;
341 const char *oid = NULL;
343 a = &cur->object.attribute_ctr.attributes[i];
344 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
345 if (!W_ERROR_IS_OK(status)) {
346 return werror_to_ntstatus(status);
350 case DRSUAPI_ATTRIBUTE_objectClass:
351 for (j=0; j < a->value_ctr.num_values; j++) {
352 uint32_t val = 0xFFFFFFFF;
354 if (a->value_ctr.values[i].blob
355 && a->value_ctr.values[i].blob->length == 4) {
356 val = IVAL(a->value_ctr.values[i].blob->data,0);
359 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
362 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
374 struct dsdb_attribute *sa;
376 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
377 NT_STATUS_HAVE_NO_MEMORY(sa);
379 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
380 if (!W_ERROR_IS_OK(status)) {
381 return werror_to_ntstatus(status);
384 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
388 struct dsdb_class *sc;
390 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
391 NT_STATUS_HAVE_NO_MEMORY(sc);
393 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
394 if (!W_ERROR_IS_OK(status)) {
395 return werror_to_ntstatus(status);
398 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
402 /* attach the schema to the ldb */
403 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
404 if (ret != LDB_SUCCESS) {
405 return NT_STATUS_FOOBAR;
407 /* we don't want to access the self made schema anymore */
408 s->self_made_schema = NULL;
409 s->schema = dsdb_get_schema(s->ldb);
411 status = dsdb_extended_replicated_objects_commit(s->ldb,
416 linked_attributes_count,
421 if (!W_ERROR_IS_OK(status)) {
422 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
423 return werror_to_ntstatus(status);
426 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
427 for (i=0; i < objs->num_objects; i++) {
428 struct ldb_ldif ldif;
429 fprintf(stdout, "#\n");
430 ldif.changetype = LDB_CHANGETYPE_NONE;
431 ldif.msg = objs->objects[i].msg;
432 ldb_ldif_write_file(s->ldb, stdout, &ldif);
433 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
437 msg = ldb_msg_new(objs);
438 NT_STATUS_HAVE_NO_MEMORY(msg);
439 msg->dn = objs->partition_dn;
441 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
442 if (!W_ERROR_IS_OK(status)) {
443 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
444 return werror_to_ntstatus(status);
447 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
448 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
449 if (ret != LDB_SUCCESS) {
450 return NT_STATUS_FOOBAR;
452 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
454 ret = ldb_modify(s->ldb, msg);
455 if (ret != LDB_SUCCESS) {
456 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
457 return NT_STATUS_FOOBAR;
464 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
467 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", TORTURE_SAMDB_LDB));
468 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
472 DEBUG(0,("Failed to open '%s'\n",
474 return NT_STATUS_INTERNAL_DB_ERROR;
477 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
479 DEBUG(0,("Failed to set cached ntds invocationId\n"));
480 return NT_STATUS_FOOBAR;
482 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
484 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
485 return NT_STATUS_FOOBAR;
488 s->schema = dsdb_get_schema(s->ldb);
490 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
491 return NT_STATUS_FOOBAR;
497 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
498 const struct libnet_BecomeDC_StoreChunk *c)
500 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
502 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
503 uint32_t total_object_count;
504 uint32_t object_count;
505 struct drsuapi_DsReplicaObjectListItemEx *first_object;
506 struct drsuapi_DsReplicaObjectListItemEx *cur;
508 switch (c->ctr_level) {
510 mapping_ctr = &c->ctr1->mapping_ctr;
511 total_object_count = c->ctr1->total_object_count;
512 object_count = c->ctr1->object_count;
513 first_object = c->ctr1->first_object;
516 mapping_ctr = &c->ctr6->mapping_ctr;
517 total_object_count = c->ctr6->total_object_count;
518 object_count = c->ctr6->object_count;
519 first_object = c->ctr6->first_object;
522 return NT_STATUS_INVALID_PARAMETER;
525 if (total_object_count) {
526 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
527 c->partition->nc.dn, object_count, total_object_count));
529 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
530 c->partition->nc.dn, object_count));
534 s->self_made_schema = talloc_zero(s, struct dsdb_schema);
535 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
537 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
538 if (!W_ERROR_IS_OK(status)) {
539 return werror_to_ntstatus(status);
542 s->schema = s->self_made_schema;
544 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
545 if (!W_ERROR_IS_OK(status)) {
546 return werror_to_ntstatus(status);
550 if (!s->schema_part.first_object) {
551 s->schema_part.object_count = object_count;
552 s->schema_part.first_object = talloc_steal(s, first_object);
554 s->schema_part.object_count += object_count;
555 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
558 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
559 s->schema_part.last_object = cur;
561 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
562 return test_apply_schema(s, c);
568 static NTSTATUS test_become_dc_store_chunk(void *private_data,
569 const struct libnet_BecomeDC_StoreChunk *c)
571 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
573 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
574 uint32_t total_object_count;
575 uint32_t object_count;
576 struct drsuapi_DsReplicaObjectListItemEx *first_object;
577 uint32_t linked_attributes_count;
578 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
579 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
580 struct dsdb_extended_replicated_objects *objs;
581 struct repsFromTo1 *s_dsa;
585 s_dsa = talloc_zero(s, struct repsFromTo1);
586 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
587 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
588 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
590 switch (c->ctr_level) {
592 mapping_ctr = &c->ctr1->mapping_ctr;
593 total_object_count = c->ctr1->total_object_count;
594 object_count = c->ctr1->object_count;
595 first_object = c->ctr1->first_object;
596 linked_attributes_count = 0;
597 linked_attributes = NULL;
598 s_dsa->highwatermark = c->ctr1->new_highwatermark;
599 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
600 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
601 uptodateness_vector = NULL; /* TODO: map it */
604 mapping_ctr = &c->ctr6->mapping_ctr;
605 total_object_count = c->ctr6->total_object_count;
606 object_count = c->ctr6->object_count;
607 first_object = c->ctr6->first_object;
608 linked_attributes_count = c->ctr6->linked_attributes_count;
609 linked_attributes = c->ctr6->linked_attributes;
610 s_dsa->highwatermark = c->ctr6->new_highwatermark;
611 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
612 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
613 uptodateness_vector = c->ctr6->uptodateness_vector;
616 return NT_STATUS_INVALID_PARAMETER;
619 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
620 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
621 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
622 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
624 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
625 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
626 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
627 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
628 s_dsa->other_info->dns_name = tmp_dns_name;
630 if (total_object_count) {
631 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
632 c->partition->nc.dn, object_count, total_object_count));
634 DEBUG(0,("Partition[%s] objects[%u]\n",
635 c->partition->nc.dn, object_count));
638 status = dsdb_extended_replicated_objects_commit(s->ldb,
643 linked_attributes_count,
648 if (!W_ERROR_IS_OK(status)) {
649 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
650 return werror_to_ntstatus(status);
653 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
654 for (i=0; i < objs->num_objects; i++) {
655 struct ldb_ldif ldif;
656 fprintf(stdout, "#\n");
657 ldif.changetype = LDB_CHANGETYPE_NONE;
658 ldif.msg = objs->objects[i].msg;
659 ldb_ldif_write_file(s->ldb, stdout, &ldif);
660 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
666 for (i=0; i < linked_attributes_count; i++) {
667 const struct dsdb_attribute *sa;
669 if (!linked_attributes[i].identifier) {
670 return NT_STATUS_FOOBAR;
673 if (!linked_attributes[i].value.blob) {
674 return NT_STATUS_FOOBAR;
677 sa = dsdb_attribute_by_attributeID_id(s->schema,
678 linked_attributes[i].attid);
680 return NT_STATUS_FOOBAR;
683 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
684 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
685 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
687 linked_attributes[i].value.blob->data,
688 linked_attributes[i].value.blob->length);
695 BOOL torture_net_become_dc(struct torture_context *torture)
699 struct libnet_BecomeDC b;
700 struct libnet_UnbecomeDC u;
701 struct test_become_dc_state *s;
702 struct ldb_message *msg;
706 s = talloc_zero(torture, struct test_become_dc_state);
707 if (!s) return False;
709 /* Join domain as a member server. */
710 s->tj = torture_join_domain(TORTURE_NETBIOS_NAME,
712 &s->machine_account);
714 DEBUG(0, ("%s failed to join domain as workstation\n",
715 TORTURE_NETBIOS_NAME));
719 s->ctx = libnet_context_init(event_context_init(s));
720 s->ctx->cred = cmdline_credentials;
722 s->ldb = ldb_init(s);
725 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
726 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
727 b.in.domain_sid = torture_join_sid(s->tj);
728 b.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
729 b.in.dest_dsa_netbios_name = TORTURE_NETBIOS_NAME;
731 b.in.callbacks.private_data = s;
732 b.in.callbacks.check_options = test_become_dc_check_options;
733 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
734 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
735 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
736 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;
738 status = libnet_BecomeDC(s->ctx, s, &b);
739 if (!NT_STATUS_IS_OK(status)) {
740 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
745 msg = ldb_msg_new(s);
747 printf("ldb_msg_new() failed\n");
751 msg->dn = ldb_dn_new(msg, s->ldb, "cn=ROOTDSE");
753 printf("ldb_msg_new(cn=ROOTDSE) failed\n");
758 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
759 if (ldb_ret != LDB_SUCCESS) {
760 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
765 for (i=0; i < msg->num_elements; i++) {
766 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
769 printf("mark ROOTDSE with isSynchronized=TRUE\n");
770 ldb_ret = ldb_modify(s->ldb, msg);
771 if (ldb_ret != LDB_SUCCESS) {
772 printf("ldb_modify() failed: %d\n", ldb_ret);
778 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
781 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", TORTURE_SAMDB_LDB));
782 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
786 DEBUG(0,("Failed to open '%s'\n",
792 s->schema = dsdb_get_schema(s->ldb);
794 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
801 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
802 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
803 u.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
804 u.in.dest_dsa_netbios_name = TORTURE_NETBIOS_NAME;
806 status = libnet_UnbecomeDC(s->ctx, s, &u);
807 if (!NT_STATUS_IS_OK(status)) {
808 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
813 torture_leave_domain(s->tj);