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 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 struct test_become_dc_state {
98 struct libnet_context *ctx;
99 const char *netbios_name;
100 struct test_join *tj;
101 struct cli_credentials *machine_account;
102 struct dsdb_schema *self_made_schema;
103 const struct dsdb_schema *schema;
105 struct ldb_context *ldb;
108 uint32_t object_count;
109 struct drsuapi_DsReplicaObjectListItemEx *first_object;
110 struct drsuapi_DsReplicaObjectListItemEx *last_object;
114 const char *samdb_ldb;
115 const char *domaindn_ldb;
116 const char *configdn_ldb;
117 const char *schemadn_ldb;
118 const char *secrets_ldb;
119 const char *secrets_keytab;
122 const char *computer_dn;
125 static NTSTATUS test_become_dc_check_options(void *private_data,
126 const struct libnet_BecomeDC_CheckOptions *o)
128 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
130 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n",
132 o->domain->netbios_name, o->domain->dns_name));
134 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n",
135 o->source_dsa->dns_name, o->source_dsa->site_name));
137 DEBUG(0,("Options:crossRef behavior_version[%u]\n"
138 "\tschema object_version[%u]\n"
139 "\tdomain behavior_version[%u]\n"
140 "\tdomain w2k3_update_revision[%u]\n",
141 o->forest->crossref_behavior_version,
142 o->forest->schema_object_version,
143 o->domain->behavior_version,
144 o->domain->w2k3_update_revision));
149 static NTSTATUS test_become_dc_prepare_db(void *private_data,
150 const struct libnet_BecomeDC_PrepareDB *p)
152 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
157 DEBUG(0,("New Server[%s] in Site[%s]\n",
158 p->dest_dsa->dns_name, p->dest_dsa->site_name));
160 DEBUG(0,("DSA Instance [%s]\n"
162 "\tinvocationId[%s]\n",
163 p->dest_dsa->ntds_dn_str,
164 GUID_string(s, &p->dest_dsa->ntds_guid),
165 GUID_string(s, &p->dest_dsa->invocation_id)));
167 DEBUG(0,("Pathes under PRIVATEDIR[%s]\n"
168 "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n",
172 s->path.secrets_keytab));
174 DEBUG(0,("Schema Partition[%s => %s]\n",
175 p->forest->schema_dn_str, s->path.schemadn_ldb));
177 DEBUG(0,("Config Partition[%s => %s]\n",
178 p->forest->config_dn_str, s->path.configdn_ldb));
180 DEBUG(0,("Domain Partition[%s => %s]\n",
181 p->domain->dn_str, s->path.domaindn_ldb));
183 ejs = talloc_asprintf(s,
184 "libinclude(\"base.js\");\n"
185 "libinclude(\"provision.js\");\n"
187 "function message() { print(vsprintf(arguments)); }\n"
189 "var subobj = provision_guess();\n"
190 "subobj.ROOTDN = \"%s\";\n"
191 "subobj.DOMAINDN = \"%s\";\n"
192 "subobj.DOMAINDN_LDB = \"%s\";\n"
193 "subobj.CONFIGDN = \"%s\";\n"
194 "subobj.CONFIGDN_LDB = \"%s\";\n"
195 "subobj.SCHEMADN = \"%s\";\n"
196 "subobj.SCHEMADN_LDB = \"%s\";\n"
197 "subobj.HOSTNAME = \"%s\";\n"
198 "subobj.DNSNAME = \"%s\";\n"
199 "subobj.DEFAULTSITE = \"%s\";\n"
201 "modules_list = new Array(\"rootdse\",\n"
203 " \"paged_results\",\n"
204 " \"server_sort\",\n"
205 " \"extended_dn\",\n"
208 " \"operational\",\n"
209 " \"objectclass\",\n"
211 " \"show_deleted\",\n"
213 "subobj.MODULES_LIST = join(\",\", modules_list);\n"
214 "subobj.DOMAINDN_MOD = \"pdc_fsmo,password_hash,repl_meta_data\";\n"
215 "subobj.CONFIGDN_MOD = \"naming_fsmo,repl_meta_data\";\n"
216 "subobj.SCHEMADN_MOD = \"schema_fsmo,repl_meta_data\";\n"
218 "subobj.KRBTGTPASS = \"_NOT_USED_\";\n"
219 "subobj.MACHINEPASS = \"%s\";\n"
220 "subobj.ADMINPASS = \"_NOT_USED_\";\n"
222 "var paths = provision_default_paths(subobj);\n"
223 "paths.samdb = \"%s\";\n"
224 "paths.secrets = \"%s\";\n"
225 "paths.keytab = \"%s\";\n"
227 "var system_session = system_session();\n"
229 "var ok = provision_become_dc(subobj, message, paths, system_session);\n"
233 p->forest->root_dn_str, /* subobj.ROOTDN */
234 p->domain->dn_str, /* subobj.DOMAINDN */
235 s->path.domaindn_ldb, /* subobj.DOMAINDN_LDB */
236 p->forest->config_dn_str, /* subobj.CONFIGDN */
237 s->path.configdn_ldb, /* subobj.CONFIGDN_LDB */
238 p->forest->schema_dn_str, /* subobj.SCHEMADN */
239 s->path.schemadn_ldb, /* subobj.SCHEMADN_LDB */
240 p->dest_dsa->netbios_name, /* subobj.HOSTNAME */
241 p->dest_dsa->dns_name, /* subobj.DNSNAME */
242 p->dest_dsa->site_name, /* subobj.DEFAULTSITE */
243 cli_credentials_get_password(s->machine_account),/* subobj.MACHINEPASS */
244 s->path.samdb_ldb, /* paths.samdb */
245 s->path.secrets_ldb, /* paths.secrets */
246 s->path.secrets_keytab); /* paths.keytab */
247 NT_STATUS_HAVE_NO_MEMORY(ejs);
249 ret = test_run_ejs(ejs);
251 DEBUG(0,("Failed to run ejs script: %d:\n%s",
254 return NT_STATUS_FOOBAR;
260 DEBUG(0,("Open the SAM LDB with system credentials: %s\n", s->path.samdb_ldb));
262 s->ldb = ldb_wrap_connect(s, s->path.samdb_ldb,
266 DEBUG(0,("Failed to open '%s'\n",
268 return NT_STATUS_INTERNAL_DB_ERROR;
271 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
273 DEBUG(0,("Failed to set cached ntds invocationId\n"));
274 return NT_STATUS_FOOBAR;
276 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
278 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
279 return NT_STATUS_FOOBAR;
285 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
286 const struct libnet_BecomeDC_StoreChunk *c)
289 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
290 uint32_t total_object_count;
291 uint32_t object_count;
292 struct drsuapi_DsReplicaObjectListItemEx *first_object;
293 struct drsuapi_DsReplicaObjectListItemEx *cur;
294 uint32_t linked_attributes_count;
295 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
296 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
297 struct dsdb_extended_replicated_objects *objs;
298 struct repsFromTo1 *s_dsa;
300 struct ldb_message *msg;
301 struct ldb_val prefixMap_val;
302 struct ldb_message_element *prefixMap_el;
303 struct ldb_val schemaInfo_val;
308 DEBUG(0,("Analyze and apply schema objects\n"));
310 s_dsa = talloc_zero(s, struct repsFromTo1);
311 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
312 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
313 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
315 switch (c->ctr_level) {
317 mapping_ctr = &c->ctr1->mapping_ctr;
318 total_object_count = c->ctr1->total_object_count;
319 object_count = s->schema_part.object_count;
320 first_object = s->schema_part.first_object;
321 linked_attributes_count = 0;
322 linked_attributes = NULL;
323 s_dsa->highwatermark = c->ctr1->new_highwatermark;
324 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
325 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
326 uptodateness_vector = NULL; /* TODO: map it */
329 mapping_ctr = &c->ctr6->mapping_ctr;
330 total_object_count = c->ctr6->total_object_count;
331 object_count = s->schema_part.object_count;
332 first_object = s->schema_part.first_object;
333 linked_attributes_count = 0; /* TODO: ! */
334 linked_attributes = NULL; /* TODO: ! */;
335 s_dsa->highwatermark = c->ctr6->new_highwatermark;
336 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
337 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
338 uptodateness_vector = c->ctr6->uptodateness_vector;
341 return NT_STATUS_INVALID_PARAMETER;
344 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
345 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
346 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
347 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
349 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
350 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
351 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
352 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
353 s_dsa->other_info->dns_name = tmp_dns_name;
355 for (cur = first_object; cur; cur = cur->next_object) {
356 bool is_attr = false;
357 bool is_class = false;
359 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
360 struct drsuapi_DsReplicaAttribute *a;
362 const char *oid = NULL;
364 a = &cur->object.attribute_ctr.attributes[i];
365 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
366 if (!W_ERROR_IS_OK(status)) {
367 return werror_to_ntstatus(status);
371 case DRSUAPI_ATTRIBUTE_objectClass:
372 for (j=0; j < a->value_ctr.num_values; j++) {
373 uint32_t val = 0xFFFFFFFF;
375 if (a->value_ctr.values[i].blob
376 && a->value_ctr.values[i].blob->length == 4) {
377 val = IVAL(a->value_ctr.values[i].blob->data,0);
380 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
383 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
395 struct dsdb_attribute *sa;
397 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
398 NT_STATUS_HAVE_NO_MEMORY(sa);
400 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
401 if (!W_ERROR_IS_OK(status)) {
402 return werror_to_ntstatus(status);
405 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
409 struct dsdb_class *sc;
411 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
412 NT_STATUS_HAVE_NO_MEMORY(sc);
414 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
415 if (!W_ERROR_IS_OK(status)) {
416 return werror_to_ntstatus(status);
419 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
423 /* attach the schema to the ldb */
424 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
425 if (ret != LDB_SUCCESS) {
426 return NT_STATUS_FOOBAR;
428 /* we don't want to access the self made schema anymore */
429 s->self_made_schema = NULL;
430 s->schema = dsdb_get_schema(s->ldb);
432 status = dsdb_extended_replicated_objects_commit(s->ldb,
437 linked_attributes_count,
443 if (!W_ERROR_IS_OK(status)) {
444 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
445 return werror_to_ntstatus(status);
448 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
449 for (i=0; i < objs->num_objects; i++) {
450 struct ldb_ldif ldif;
451 fprintf(stdout, "#\n");
452 ldif.changetype = LDB_CHANGETYPE_NONE;
453 ldif.msg = objs->objects[i].msg;
454 ldb_ldif_write_file(s->ldb, stdout, &ldif);
455 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
459 msg = ldb_msg_new(objs);
460 NT_STATUS_HAVE_NO_MEMORY(msg);
461 msg->dn = objs->partition_dn;
463 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
464 if (!W_ERROR_IS_OK(status)) {
465 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
466 return werror_to_ntstatus(status);
469 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
470 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
471 if (ret != LDB_SUCCESS) {
472 return NT_STATUS_FOOBAR;
474 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
476 ret = ldb_modify(s->ldb, msg);
477 if (ret != LDB_SUCCESS) {
478 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
479 return NT_STATUS_FOOBAR;
486 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
489 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", s->path.samdb_ldb));
490 s->ldb = ldb_wrap_connect(s, s->path.samdb_ldb,
494 DEBUG(0,("Failed to open '%s'\n",
496 return NT_STATUS_INTERNAL_DB_ERROR;
499 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
501 DEBUG(0,("Failed to set cached ntds invocationId\n"));
502 return NT_STATUS_FOOBAR;
504 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
506 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
507 return NT_STATUS_FOOBAR;
510 s->schema = dsdb_get_schema(s->ldb);
512 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
513 return NT_STATUS_FOOBAR;
519 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
520 const struct libnet_BecomeDC_StoreChunk *c)
522 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
524 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
525 uint32_t total_object_count;
526 uint32_t object_count;
527 struct drsuapi_DsReplicaObjectListItemEx *first_object;
528 struct drsuapi_DsReplicaObjectListItemEx *cur;
530 switch (c->ctr_level) {
532 mapping_ctr = &c->ctr1->mapping_ctr;
533 total_object_count = c->ctr1->total_object_count;
534 object_count = c->ctr1->object_count;
535 first_object = c->ctr1->first_object;
538 mapping_ctr = &c->ctr6->mapping_ctr;
539 total_object_count = c->ctr6->total_object_count;
540 object_count = c->ctr6->object_count;
541 first_object = c->ctr6->first_object;
544 return NT_STATUS_INVALID_PARAMETER;
547 if (total_object_count) {
548 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
549 c->partition->nc.dn, object_count, total_object_count));
551 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
552 c->partition->nc.dn, object_count));
556 s->self_made_schema = talloc_zero(s, struct dsdb_schema);
557 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
559 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
560 if (!W_ERROR_IS_OK(status)) {
561 return werror_to_ntstatus(status);
564 s->schema = s->self_made_schema;
566 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
567 if (!W_ERROR_IS_OK(status)) {
568 return werror_to_ntstatus(status);
572 if (!s->schema_part.first_object) {
573 s->schema_part.object_count = object_count;
574 s->schema_part.first_object = talloc_steal(s, first_object);
576 s->schema_part.object_count += object_count;
577 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
580 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
581 s->schema_part.last_object = cur;
583 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
584 return test_apply_schema(s, c);
590 static NTSTATUS test_become_dc_store_chunk(void *private_data,
591 const struct libnet_BecomeDC_StoreChunk *c)
593 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
595 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
596 uint32_t total_object_count;
597 uint32_t object_count;
598 struct drsuapi_DsReplicaObjectListItemEx *first_object;
599 uint32_t linked_attributes_count;
600 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
601 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
602 struct dsdb_extended_replicated_objects *objs;
603 struct repsFromTo1 *s_dsa;
607 s_dsa = talloc_zero(s, struct repsFromTo1);
608 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
609 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
610 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
612 switch (c->ctr_level) {
614 mapping_ctr = &c->ctr1->mapping_ctr;
615 total_object_count = c->ctr1->total_object_count;
616 object_count = c->ctr1->object_count;
617 first_object = c->ctr1->first_object;
618 linked_attributes_count = 0;
619 linked_attributes = NULL;
620 s_dsa->highwatermark = c->ctr1->new_highwatermark;
621 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
622 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
623 uptodateness_vector = NULL; /* TODO: map it */
626 mapping_ctr = &c->ctr6->mapping_ctr;
627 total_object_count = c->ctr6->total_object_count;
628 object_count = c->ctr6->object_count;
629 first_object = c->ctr6->first_object;
630 linked_attributes_count = c->ctr6->linked_attributes_count;
631 linked_attributes = c->ctr6->linked_attributes;
632 s_dsa->highwatermark = c->ctr6->new_highwatermark;
633 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
634 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
635 uptodateness_vector = c->ctr6->uptodateness_vector;
638 return NT_STATUS_INVALID_PARAMETER;
641 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
642 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
643 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
644 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
646 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
647 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
648 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
649 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
650 s_dsa->other_info->dns_name = tmp_dns_name;
652 if (total_object_count) {
653 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
654 c->partition->nc.dn, object_count, total_object_count));
656 DEBUG(0,("Partition[%s] objects[%u]\n",
657 c->partition->nc.dn, object_count));
660 status = dsdb_extended_replicated_objects_commit(s->ldb,
665 linked_attributes_count,
671 if (!W_ERROR_IS_OK(status)) {
672 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
673 return werror_to_ntstatus(status);
676 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
677 for (i=0; i < objs->num_objects; i++) {
678 struct ldb_ldif ldif;
679 fprintf(stdout, "#\n");
680 ldif.changetype = LDB_CHANGETYPE_NONE;
681 ldif.msg = objs->objects[i].msg;
682 ldb_ldif_write_file(s->ldb, stdout, &ldif);
683 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
689 for (i=0; i < linked_attributes_count; i++) {
690 const struct dsdb_attribute *sa;
692 if (!linked_attributes[i].identifier) {
693 return NT_STATUS_FOOBAR;
696 if (!linked_attributes[i].value.blob) {
697 return NT_STATUS_FOOBAR;
700 sa = dsdb_attribute_by_attributeID_id(s->schema,
701 linked_attributes[i].attid);
703 return NT_STATUS_FOOBAR;
706 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
707 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
708 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
710 linked_attributes[i].value.blob->data,
711 linked_attributes[i].value.blob->length);
718 static NTSTATUS test_become_dc_domain_chunk(void *private_data,
719 const struct libnet_BecomeDC_StoreChunk *c)
721 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
723 s->computer_dn = talloc_strdup(s, c->dest_dsa->computer_dn_str);
724 NT_STATUS_HAVE_NO_MEMORY(s->computer_dn);
726 return test_become_dc_store_chunk(private_data, c);
729 BOOL torture_net_become_dc(struct torture_context *torture)
733 struct libnet_BecomeDC b;
734 struct libnet_UnbecomeDC u;
735 struct test_become_dc_state *s;
736 struct ldb_message *msg;
740 s = talloc_zero(torture, struct test_become_dc_state);
741 if (!s) return False;
743 s->netbios_name = lp_parm_string(-1, "become dc", "smbtorture dc");
744 if (!s->netbios_name || !s->netbios_name[0]) {
745 s->netbios_name = "smbtorturedc";
748 s->path.samdb_ldb = talloc_asprintf(s, "%s_samdb.ldb", s->netbios_name);
749 if (!s->path.samdb_ldb) return false;
750 s->path.domaindn_ldb = talloc_asprintf(s, "%s_domain.ldb", s->netbios_name);
751 if (!s->path.domaindn_ldb) return false;
752 s->path.configdn_ldb = talloc_asprintf(s, "%s_config.ldb", s->netbios_name);
753 if (!s->path.configdn_ldb) return false;
754 s->path.schemadn_ldb = talloc_asprintf(s, "%s_schema.ldb", s->netbios_name);
755 if (!s->path.schemadn_ldb) return false;
756 s->path.secrets_ldb = talloc_asprintf(s, "%s_secrets.ldb", s->netbios_name);
757 if (!s->path.secrets_ldb) return false;
758 s->path.secrets_keytab = talloc_asprintf(s, "%s_secrets.keytab", s->netbios_name);
759 if (!s->path.secrets_keytab) return false;
761 /* Join domain as a member server. */
762 s->tj = torture_join_domain(s->netbios_name,
764 &s->machine_account);
766 DEBUG(0, ("%s failed to join domain as workstation\n",
771 s->ctx = libnet_context_init(event_context_init(s));
772 s->ctx->cred = cmdline_credentials;
774 s->ldb = ldb_init(s);
777 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
778 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
779 b.in.domain_sid = torture_join_sid(s->tj);
780 b.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
781 b.in.dest_dsa_netbios_name = s->netbios_name;
783 b.in.callbacks.private_data = s;
784 b.in.callbacks.check_options = test_become_dc_check_options;
785 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
786 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
787 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
788 b.in.callbacks.domain_chunk = test_become_dc_domain_chunk;
790 status = libnet_BecomeDC(s->ctx, s, &b);
791 if (!NT_STATUS_IS_OK(status)) {
792 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
797 msg = ldb_msg_new(s);
799 printf("ldb_msg_new() failed\n");
803 msg->dn = ldb_dn_new(msg, s->ldb, "cn=ROOTDSE");
805 printf("ldb_msg_new(cn=ROOTDSE) failed\n");
810 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
811 if (ldb_ret != LDB_SUCCESS) {
812 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
817 for (i=0; i < msg->num_elements; i++) {
818 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
821 printf("mark ROOTDSE with isSynchronized=TRUE\n");
822 ldb_ret = ldb_modify(s->ldb, msg);
823 if (ldb_ret != LDB_SUCCESS) {
824 printf("ldb_modify() failed: %d\n", ldb_ret);
830 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
833 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", s->path.samdb_ldb));
834 s->ldb = ldb_wrap_connect(s, s->path.samdb_ldb,
838 DEBUG(0,("Failed to open '%s'\n",
844 s->schema = dsdb_get_schema(s->ldb);
846 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
851 if (lp_parm_bool(-1, "become dc", "do not unjoin", false)) {
858 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
859 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
860 u.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
861 u.in.dest_dsa_netbios_name = s->netbios_name;
863 status = libnet_UnbecomeDC(s->ctx, s, &u);
864 if (!NT_STATUS_IS_OK(status)) {
865 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
870 torture_leave_domain(s->tj);