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;
117 const char *computer_dn;
120 static NTSTATUS test_become_dc_check_options(void *private_data,
121 const struct libnet_BecomeDC_CheckOptions *o)
123 DEBUG(0,("Become DC of Domain[%s]/[%s]\n",
124 o->domain->netbios_name, o->domain->dns_name));
126 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
127 o->source_dsa->dns_name, o->source_dsa->site_name));
129 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
130 "\tschema object_version[%u]\n"
131 "\tdomain behavior_version[%u]\n"
132 "\tdomain w2k3_update_revision[%u]\n",
133 o->forest->crossref_behavior_version,
134 o->forest->schema_object_version,
135 o->domain->behavior_version,
136 o->domain->w2k3_update_revision));
141 static NTSTATUS test_become_dc_prepare_db(void *private_data,
142 const struct libnet_BecomeDC_PrepareDB *p)
144 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
149 DEBUG(0,("New Server[%s] in Site[%s]\n",
150 p->dest_dsa->dns_name, p->dest_dsa->site_name));
152 DEBUG(0,("DSA Instance [%s]\n"
154 "\tinvocationId[%s]\n",
155 p->dest_dsa->ntds_dn_str,
156 GUID_string(s, &p->dest_dsa->ntds_guid),
157 GUID_string(s, &p->dest_dsa->invocation_id)));
159 DEBUG(0,("Schema Partition[%s]\n",
160 p->forest->schema_dn_str));
162 DEBUG(0,("Config Partition[%s]\n",
163 p->forest->config_dn_str));
165 DEBUG(0,("Domain Partition[%s]\n",
168 ejs = talloc_asprintf(s,
169 "libinclude(\"base.js\");\n"
170 "libinclude(\"provision.js\");\n"
172 "function message() { print(vsprintf(arguments)); }\n"
174 "var subobj = provision_guess();\n"
175 "subobj.ROOTDN = \"%s\";\n"
176 "subobj.DOMAINDN = \"%s\";\n"
177 "subobj.DOMAINDN_LDB = \"test_domain.ldb\";\n"
178 "subobj.CONFIGDN = \"%s\";\n"
179 "subobj.CONFIGDN_LDB = \"test_config.ldb\";\n"
180 "subobj.SCHEMADN = \"%s\";\n"
181 "subobj.SCHEMADN_LDB = \"test_schema.ldb\";\n"
182 "subobj.HOSTNAME = \"%s\";\n"
183 "subobj.DNSNAME = \"%s\";\n"
184 "subobj.DEFAULTSITE = \"%s\";\n"
186 "modules_list = new Array(\"rootdse\",\n"
188 " \"paged_results\",\n"
189 " \"server_sort\",\n"
190 " \"extended_dn\",\n"
193 " \"operational\",\n"
194 " \"objectclass\",\n"
196 " \"show_deleted\",\n"
198 "subobj.MODULES_LIST = join(\",\", modules_list);\n"
199 "subobj.DOMAINDN_MOD = \"pdc_fsmo,password_hash,repl_meta_data\";\n"
200 "subobj.CONFIGDN_MOD = \"naming_fsmo,repl_meta_data\";\n"
201 "subobj.SCHEMADN_MOD = \"schema_fsmo,repl_meta_data\";\n"
203 "subobj.KRBTGTPASS = \"test\";\n"
204 "subobj.MACHINEPASS = \"test\";\n"
205 "subobj.ADMINPASS = \"test\";\n"
207 "var paths = provision_default_paths(subobj);\n"
208 "paths.samdb = \"%s\";\n"
209 "paths.secrets = \"%s\";\n"
210 "paths.keytab = \"%s\";\n"
212 "var system_session = system_session();\n"
214 "var ok = provision_become_dc(subobj, message, paths, system_session);\n"
218 p->forest->root_dn_str, /* subobj.ROOTDN */
219 p->domain->dn_str, /* subobj.DOMAINDN */
220 p->forest->config_dn_str, /* subobj.CONFIGDN */
221 p->forest->schema_dn_str, /* subobj.SCHEMADN */
222 p->dest_dsa->netbios_name, /* subobj.HOSTNAME */
223 p->dest_dsa->dns_name, /* subobj.DNSNAME */
224 p->dest_dsa->site_name, /* subobj.DEFAULTSITE */
225 TORTURE_SAMDB_LDB, /* paths.samdb */
226 TORTURE_SECRETS_LDB, /* paths.secrets */
227 TORTURE_SECRETS_KEYTAB); /* paths.keytab */
228 NT_STATUS_HAVE_NO_MEMORY(ejs);
230 ret = test_run_ejs(ejs);
232 DEBUG(0,("Failed to run ejs script: %d:\n%s",
235 return NT_STATUS_FOOBAR;
241 DEBUG(0,("Open the SAM LDB with system credentials: %s\n", TORTURE_SAMDB_LDB));
243 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
247 DEBUG(0,("Failed to open '%s'\n",
249 return NT_STATUS_INTERNAL_DB_ERROR;
252 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
254 DEBUG(0,("Failed to set cached ntds invocationId\n"));
255 return NT_STATUS_FOOBAR;
257 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
259 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
260 return NT_STATUS_FOOBAR;
266 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
267 const struct libnet_BecomeDC_StoreChunk *c)
270 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
271 uint32_t total_object_count;
272 uint32_t object_count;
273 struct drsuapi_DsReplicaObjectListItemEx *first_object;
274 struct drsuapi_DsReplicaObjectListItemEx *cur;
275 uint32_t linked_attributes_count;
276 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
277 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
278 struct dsdb_extended_replicated_objects *objs;
279 struct repsFromTo1 *s_dsa;
281 struct ldb_message *msg;
282 struct ldb_val prefixMap_val;
283 struct ldb_message_element *prefixMap_el;
284 struct ldb_val schemaInfo_val;
289 DEBUG(0,("Analyze and apply schema objects\n"));
291 s_dsa = talloc_zero(s, struct repsFromTo1);
292 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
293 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
294 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
296 switch (c->ctr_level) {
298 mapping_ctr = &c->ctr1->mapping_ctr;
299 total_object_count = c->ctr1->total_object_count;
300 object_count = s->schema_part.object_count;
301 first_object = s->schema_part.first_object;
302 linked_attributes_count = 0;
303 linked_attributes = NULL;
304 s_dsa->highwatermark = c->ctr1->new_highwatermark;
305 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
306 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
307 uptodateness_vector = NULL; /* TODO: map it */
310 mapping_ctr = &c->ctr6->mapping_ctr;
311 total_object_count = c->ctr6->total_object_count;
312 object_count = s->schema_part.object_count;
313 first_object = s->schema_part.first_object;
314 linked_attributes_count = 0; /* TODO: ! */
315 linked_attributes = NULL; /* TODO: ! */;
316 s_dsa->highwatermark = c->ctr6->new_highwatermark;
317 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
318 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
319 uptodateness_vector = c->ctr6->uptodateness_vector;
322 return NT_STATUS_INVALID_PARAMETER;
325 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
326 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
327 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
328 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
330 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
331 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
332 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
333 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
334 s_dsa->other_info->dns_name = tmp_dns_name;
336 for (cur = first_object; cur; cur = cur->next_object) {
337 bool is_attr = false;
338 bool is_class = false;
340 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
341 struct drsuapi_DsReplicaAttribute *a;
343 const char *oid = NULL;
345 a = &cur->object.attribute_ctr.attributes[i];
346 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
347 if (!W_ERROR_IS_OK(status)) {
348 return werror_to_ntstatus(status);
352 case DRSUAPI_ATTRIBUTE_objectClass:
353 for (j=0; j < a->value_ctr.num_values; j++) {
354 uint32_t val = 0xFFFFFFFF;
356 if (a->value_ctr.values[i].blob
357 && a->value_ctr.values[i].blob->length == 4) {
358 val = IVAL(a->value_ctr.values[i].blob->data,0);
361 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
364 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
376 struct dsdb_attribute *sa;
378 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
379 NT_STATUS_HAVE_NO_MEMORY(sa);
381 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
382 if (!W_ERROR_IS_OK(status)) {
383 return werror_to_ntstatus(status);
386 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
390 struct dsdb_class *sc;
392 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
393 NT_STATUS_HAVE_NO_MEMORY(sc);
395 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
396 if (!W_ERROR_IS_OK(status)) {
397 return werror_to_ntstatus(status);
400 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
404 /* attach the schema to the ldb */
405 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
406 if (ret != LDB_SUCCESS) {
407 return NT_STATUS_FOOBAR;
409 /* we don't want to access the self made schema anymore */
410 s->self_made_schema = NULL;
411 s->schema = dsdb_get_schema(s->ldb);
413 status = dsdb_extended_replicated_objects_commit(s->ldb,
418 linked_attributes_count,
423 if (!W_ERROR_IS_OK(status)) {
424 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
425 return werror_to_ntstatus(status);
428 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
429 for (i=0; i < objs->num_objects; i++) {
430 struct ldb_ldif ldif;
431 fprintf(stdout, "#\n");
432 ldif.changetype = LDB_CHANGETYPE_NONE;
433 ldif.msg = objs->objects[i].msg;
434 ldb_ldif_write_file(s->ldb, stdout, &ldif);
435 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
439 msg = ldb_msg_new(objs);
440 NT_STATUS_HAVE_NO_MEMORY(msg);
441 msg->dn = objs->partition_dn;
443 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
444 if (!W_ERROR_IS_OK(status)) {
445 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
446 return werror_to_ntstatus(status);
449 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
450 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
451 if (ret != LDB_SUCCESS) {
452 return NT_STATUS_FOOBAR;
454 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
456 ret = ldb_modify(s->ldb, msg);
457 if (ret != LDB_SUCCESS) {
458 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
459 return NT_STATUS_FOOBAR;
466 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
469 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", TORTURE_SAMDB_LDB));
470 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
474 DEBUG(0,("Failed to open '%s'\n",
476 return NT_STATUS_INTERNAL_DB_ERROR;
479 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
481 DEBUG(0,("Failed to set cached ntds invocationId\n"));
482 return NT_STATUS_FOOBAR;
484 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
486 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
487 return NT_STATUS_FOOBAR;
490 s->schema = dsdb_get_schema(s->ldb);
492 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
493 return NT_STATUS_FOOBAR;
499 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
500 const struct libnet_BecomeDC_StoreChunk *c)
502 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
504 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
505 uint32_t total_object_count;
506 uint32_t object_count;
507 struct drsuapi_DsReplicaObjectListItemEx *first_object;
508 struct drsuapi_DsReplicaObjectListItemEx *cur;
510 switch (c->ctr_level) {
512 mapping_ctr = &c->ctr1->mapping_ctr;
513 total_object_count = c->ctr1->total_object_count;
514 object_count = c->ctr1->object_count;
515 first_object = c->ctr1->first_object;
518 mapping_ctr = &c->ctr6->mapping_ctr;
519 total_object_count = c->ctr6->total_object_count;
520 object_count = c->ctr6->object_count;
521 first_object = c->ctr6->first_object;
524 return NT_STATUS_INVALID_PARAMETER;
527 if (total_object_count) {
528 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
529 c->partition->nc.dn, object_count, total_object_count));
531 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
532 c->partition->nc.dn, object_count));
536 s->self_made_schema = talloc_zero(s, struct dsdb_schema);
537 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
539 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
540 if (!W_ERROR_IS_OK(status)) {
541 return werror_to_ntstatus(status);
544 s->schema = s->self_made_schema;
546 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
547 if (!W_ERROR_IS_OK(status)) {
548 return werror_to_ntstatus(status);
552 if (!s->schema_part.first_object) {
553 s->schema_part.object_count = object_count;
554 s->schema_part.first_object = talloc_steal(s, first_object);
556 s->schema_part.object_count += object_count;
557 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
560 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
561 s->schema_part.last_object = cur;
563 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
564 return test_apply_schema(s, c);
570 static NTSTATUS test_become_dc_store_chunk(void *private_data,
571 const struct libnet_BecomeDC_StoreChunk *c)
573 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
575 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
576 uint32_t total_object_count;
577 uint32_t object_count;
578 struct drsuapi_DsReplicaObjectListItemEx *first_object;
579 uint32_t linked_attributes_count;
580 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
581 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
582 struct dsdb_extended_replicated_objects *objs;
583 struct repsFromTo1 *s_dsa;
587 s_dsa = talloc_zero(s, struct repsFromTo1);
588 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
589 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
590 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
592 switch (c->ctr_level) {
594 mapping_ctr = &c->ctr1->mapping_ctr;
595 total_object_count = c->ctr1->total_object_count;
596 object_count = c->ctr1->object_count;
597 first_object = c->ctr1->first_object;
598 linked_attributes_count = 0;
599 linked_attributes = NULL;
600 s_dsa->highwatermark = c->ctr1->new_highwatermark;
601 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
602 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
603 uptodateness_vector = NULL; /* TODO: map it */
606 mapping_ctr = &c->ctr6->mapping_ctr;
607 total_object_count = c->ctr6->total_object_count;
608 object_count = c->ctr6->object_count;
609 first_object = c->ctr6->first_object;
610 linked_attributes_count = c->ctr6->linked_attributes_count;
611 linked_attributes = c->ctr6->linked_attributes;
612 s_dsa->highwatermark = c->ctr6->new_highwatermark;
613 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
614 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
615 uptodateness_vector = c->ctr6->uptodateness_vector;
618 return NT_STATUS_INVALID_PARAMETER;
621 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
622 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
623 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
624 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
626 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
627 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
628 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
629 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
630 s_dsa->other_info->dns_name = tmp_dns_name;
632 if (total_object_count) {
633 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
634 c->partition->nc.dn, object_count, total_object_count));
636 DEBUG(0,("Partition[%s] objects[%u]\n",
637 c->partition->nc.dn, object_count));
640 status = dsdb_extended_replicated_objects_commit(s->ldb,
645 linked_attributes_count,
650 if (!W_ERROR_IS_OK(status)) {
651 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
652 return werror_to_ntstatus(status);
655 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
656 for (i=0; i < objs->num_objects; i++) {
657 struct ldb_ldif ldif;
658 fprintf(stdout, "#\n");
659 ldif.changetype = LDB_CHANGETYPE_NONE;
660 ldif.msg = objs->objects[i].msg;
661 ldb_ldif_write_file(s->ldb, stdout, &ldif);
662 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
668 for (i=0; i < linked_attributes_count; i++) {
669 const struct dsdb_attribute *sa;
671 if (!linked_attributes[i].identifier) {
672 return NT_STATUS_FOOBAR;
675 if (!linked_attributes[i].value.blob) {
676 return NT_STATUS_FOOBAR;
679 sa = dsdb_attribute_by_attributeID_id(s->schema,
680 linked_attributes[i].attid);
682 return NT_STATUS_FOOBAR;
685 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
686 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
687 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
689 linked_attributes[i].value.blob->data,
690 linked_attributes[i].value.blob->length);
697 static NTSTATUS test_become_dc_domain_chunk(void *private_data,
698 const struct libnet_BecomeDC_StoreChunk *c)
700 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
702 s->computer_dn = talloc_strdup(s, c->dest_dsa->computer_dn_str);
703 NT_STATUS_HAVE_NO_MEMORY(s->computer_dn);
705 return test_become_dc_store_chunk(private_data, c);
708 static BOOL test_become_dc_set_test_passwords(struct test_become_dc_state *s)
710 struct ldb_message *msg;
713 printf("Set up \"test\" as password for the krbtgt, machine and administrator accounts\n");
716 * first krbtgt password
718 msg = ldb_msg_new(s);
719 if (!msg) return False;
721 msg->dn = ldb_dn_new_fmt(msg, s->ldb, "CN=krbtgt,CN=Users,%s",
722 ldb_dn_get_linearized(samdb_base_dn(s->ldb)));
723 if (!msg) return False;
725 ret = ldb_msg_add_string(msg, "sambaPassword", "test");
726 if (ret != LDB_SUCCESS) return False;
728 ret = samdb_replace(s->ldb, s, msg);
729 if (ret != LDB_SUCCESS) {
730 printf("failed to replace sambaPassword for '%s': %s\n",
731 ldb_dn_get_linearized(msg->dn),
738 * our machine account password
740 msg = ldb_msg_new(s);
741 if (!msg) return False;
743 msg->dn = ldb_dn_new(msg, s->ldb, s->computer_dn);
744 if (!msg) return False;
746 ret = ldb_msg_add_string(msg, "sambaPassword", "test");
747 if (ret != LDB_SUCCESS) return False;
749 ret = samdb_replace(s->ldb, s, msg);
750 if (ret != LDB_SUCCESS) {
751 printf("failed to replace sambaPassword for '%s': %s\n",
752 ldb_dn_get_linearized(msg->dn),
759 * the Administrator account password
761 msg = ldb_msg_new(s);
762 if (!msg) return False;
764 msg->dn = ldb_dn_new_fmt(msg, s->ldb, "CN=Administrator,CN=Users,%s",
765 ldb_dn_get_linearized(samdb_base_dn(s->ldb)));
766 if (!msg) return False;
768 ret = ldb_msg_add_string(msg, "sambaPassword", "test");
769 if (ret != LDB_SUCCESS) return False;
771 ret = samdb_replace(s->ldb, s, msg);
772 if (ret != LDB_SUCCESS) {
773 printf("failed to replace sambaPassword for '%s': %s\n",
774 ldb_dn_get_linearized(msg->dn),
783 BOOL torture_net_become_dc(struct torture_context *torture)
787 struct libnet_BecomeDC b;
788 struct libnet_UnbecomeDC u;
789 struct test_become_dc_state *s;
790 struct ldb_message *msg;
794 s = talloc_zero(torture, struct test_become_dc_state);
795 if (!s) return False;
797 /* Join domain as a member server. */
798 s->tj = torture_join_domain(TORTURE_NETBIOS_NAME,
800 &s->machine_account);
802 DEBUG(0, ("%s failed to join domain as workstation\n",
803 TORTURE_NETBIOS_NAME));
807 s->ctx = libnet_context_init(event_context_init(s));
808 s->ctx->cred = cmdline_credentials;
810 s->ldb = ldb_init(s);
813 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
814 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
815 b.in.domain_sid = torture_join_sid(s->tj);
816 b.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
817 b.in.dest_dsa_netbios_name = TORTURE_NETBIOS_NAME;
819 b.in.callbacks.private_data = s;
820 b.in.callbacks.check_options = test_become_dc_check_options;
821 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
822 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
823 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
824 b.in.callbacks.domain_chunk = test_become_dc_domain_chunk;
826 status = libnet_BecomeDC(s->ctx, s, &b);
827 if (!NT_STATUS_IS_OK(status)) {
828 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
833 msg = ldb_msg_new(s);
835 printf("ldb_msg_new() failed\n");
839 msg->dn = ldb_dn_new(msg, s->ldb, "cn=ROOTDSE");
841 printf("ldb_msg_new(cn=ROOTDSE) failed\n");
846 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
847 if (ldb_ret != LDB_SUCCESS) {
848 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
853 for (i=0; i < msg->num_elements; i++) {
854 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
857 printf("mark ROOTDSE with isSynchronized=TRUE\n");
858 ldb_ret = ldb_modify(s->ldb, msg);
859 if (ldb_ret != LDB_SUCCESS) {
860 printf("ldb_modify() failed: %d\n", ldb_ret);
866 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
869 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", TORTURE_SAMDB_LDB));
870 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
874 DEBUG(0,("Failed to open '%s'\n",
880 s->schema = dsdb_get_schema(s->ldb);
882 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
887 ret &= test_become_dc_set_test_passwords(s);
891 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
892 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
893 u.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
894 u.in.dest_dsa_netbios_name = TORTURE_NETBIOS_NAME;
896 status = libnet_UnbecomeDC(s->ctx, s, &u);
897 if (!NT_STATUS_IS_OK(status)) {
898 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
903 torture_leave_domain(s->tj);