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 = \"_NOT_USED_\";\n"
204 "subobj.MACHINEPASS = \"%s\";\n"
205 "subobj.ADMINPASS = \"_NOT_USED_\";\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 cli_credentials_get_password(s->machine_account),/* subobj.MACHINEPASS */
226 TORTURE_SAMDB_LDB, /* paths.samdb */
227 TORTURE_SECRETS_LDB, /* paths.secrets */
228 TORTURE_SECRETS_KEYTAB); /* paths.keytab */
229 NT_STATUS_HAVE_NO_MEMORY(ejs);
231 ret = test_run_ejs(ejs);
233 DEBUG(0,("Failed to run ejs script: %d:\n%s",
236 return NT_STATUS_FOOBAR;
242 DEBUG(0,("Open the SAM LDB with system credentials: %s\n", TORTURE_SAMDB_LDB));
244 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
248 DEBUG(0,("Failed to open '%s'\n",
250 return NT_STATUS_INTERNAL_DB_ERROR;
253 ok = samdb_set_ntds_invocation_id(s->ldb, &p->dest_dsa->invocation_id);
255 DEBUG(0,("Failed to set cached ntds invocationId\n"));
256 return NT_STATUS_FOOBAR;
258 ok = samdb_set_ntds_objectGUID(s->ldb, &p->dest_dsa->ntds_guid);
260 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
261 return NT_STATUS_FOOBAR;
267 static NTSTATUS test_apply_schema(struct test_become_dc_state *s,
268 const struct libnet_BecomeDC_StoreChunk *c)
271 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
272 uint32_t total_object_count;
273 uint32_t object_count;
274 struct drsuapi_DsReplicaObjectListItemEx *first_object;
275 struct drsuapi_DsReplicaObjectListItemEx *cur;
276 uint32_t linked_attributes_count;
277 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
278 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
279 struct dsdb_extended_replicated_objects *objs;
280 struct repsFromTo1 *s_dsa;
282 struct ldb_message *msg;
283 struct ldb_val prefixMap_val;
284 struct ldb_message_element *prefixMap_el;
285 struct ldb_val schemaInfo_val;
290 DEBUG(0,("Analyze and apply schema objects\n"));
292 s_dsa = talloc_zero(s, struct repsFromTo1);
293 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
294 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
295 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
297 switch (c->ctr_level) {
299 mapping_ctr = &c->ctr1->mapping_ctr;
300 total_object_count = c->ctr1->total_object_count;
301 object_count = s->schema_part.object_count;
302 first_object = s->schema_part.first_object;
303 linked_attributes_count = 0;
304 linked_attributes = NULL;
305 s_dsa->highwatermark = c->ctr1->new_highwatermark;
306 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
307 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
308 uptodateness_vector = NULL; /* TODO: map it */
311 mapping_ctr = &c->ctr6->mapping_ctr;
312 total_object_count = c->ctr6->total_object_count;
313 object_count = s->schema_part.object_count;
314 first_object = s->schema_part.first_object;
315 linked_attributes_count = 0; /* TODO: ! */
316 linked_attributes = NULL; /* TODO: ! */;
317 s_dsa->highwatermark = c->ctr6->new_highwatermark;
318 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
319 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
320 uptodateness_vector = c->ctr6->uptodateness_vector;
323 return NT_STATUS_INVALID_PARAMETER;
326 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
327 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
328 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
329 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
331 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
332 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
333 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
334 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
335 s_dsa->other_info->dns_name = tmp_dns_name;
337 for (cur = first_object; cur; cur = cur->next_object) {
338 bool is_attr = false;
339 bool is_class = false;
341 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
342 struct drsuapi_DsReplicaAttribute *a;
344 const char *oid = NULL;
346 a = &cur->object.attribute_ctr.attributes[i];
347 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid);
348 if (!W_ERROR_IS_OK(status)) {
349 return werror_to_ntstatus(status);
353 case DRSUAPI_ATTRIBUTE_objectClass:
354 for (j=0; j < a->value_ctr.num_values; j++) {
355 uint32_t val = 0xFFFFFFFF;
357 if (a->value_ctr.values[i].blob
358 && a->value_ctr.values[i].blob->length == 4) {
359 val = IVAL(a->value_ctr.values[i].blob->data,0);
362 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) {
365 if (val == DRSUAPI_OBJECTCLASS_classSchema) {
377 struct dsdb_attribute *sa;
379 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute);
380 NT_STATUS_HAVE_NO_MEMORY(sa);
382 status = dsdb_attribute_from_drsuapi(s->self_made_schema, &cur->object, s, sa);
383 if (!W_ERROR_IS_OK(status)) {
384 return werror_to_ntstatus(status);
387 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *);
391 struct dsdb_class *sc;
393 sc = talloc_zero(s->self_made_schema, struct dsdb_class);
394 NT_STATUS_HAVE_NO_MEMORY(sc);
396 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc);
397 if (!W_ERROR_IS_OK(status)) {
398 return werror_to_ntstatus(status);
401 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *);
405 /* attach the schema to the ldb */
406 ret = dsdb_set_schema(s->ldb, s->self_made_schema);
407 if (ret != LDB_SUCCESS) {
408 return NT_STATUS_FOOBAR;
410 /* we don't want to access the self made schema anymore */
411 s->self_made_schema = NULL;
412 s->schema = dsdb_get_schema(s->ldb);
414 status = dsdb_extended_replicated_objects_commit(s->ldb,
419 linked_attributes_count,
425 if (!W_ERROR_IS_OK(status)) {
426 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
427 return werror_to_ntstatus(status);
430 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
431 for (i=0; i < objs->num_objects; i++) {
432 struct ldb_ldif ldif;
433 fprintf(stdout, "#\n");
434 ldif.changetype = LDB_CHANGETYPE_NONE;
435 ldif.msg = objs->objects[i].msg;
436 ldb_ldif_write_file(s->ldb, stdout, &ldif);
437 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
441 msg = ldb_msg_new(objs);
442 NT_STATUS_HAVE_NO_MEMORY(msg);
443 msg->dn = objs->partition_dn;
445 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val);
446 if (!W_ERROR_IS_OK(status)) {
447 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status)));
448 return werror_to_ntstatus(status);
451 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */
452 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el);
453 if (ret != LDB_SUCCESS) {
454 return NT_STATUS_FOOBAR;
456 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE;
458 ret = ldb_modify(s->ldb, msg);
459 if (ret != LDB_SUCCESS) {
460 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret)));
461 return NT_STATUS_FOOBAR;
468 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
471 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", TORTURE_SAMDB_LDB));
472 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
476 DEBUG(0,("Failed to open '%s'\n",
478 return NT_STATUS_INTERNAL_DB_ERROR;
481 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
483 DEBUG(0,("Failed to set cached ntds invocationId\n"));
484 return NT_STATUS_FOOBAR;
486 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
488 DEBUG(0,("Failed to set cached ntds objectGUID\n"));
489 return NT_STATUS_FOOBAR;
492 s->schema = dsdb_get_schema(s->ldb);
494 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
495 return NT_STATUS_FOOBAR;
501 static NTSTATUS test_become_dc_schema_chunk(void *private_data,
502 const struct libnet_BecomeDC_StoreChunk *c)
504 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
506 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
507 uint32_t total_object_count;
508 uint32_t object_count;
509 struct drsuapi_DsReplicaObjectListItemEx *first_object;
510 struct drsuapi_DsReplicaObjectListItemEx *cur;
512 switch (c->ctr_level) {
514 mapping_ctr = &c->ctr1->mapping_ctr;
515 total_object_count = c->ctr1->total_object_count;
516 object_count = c->ctr1->object_count;
517 first_object = c->ctr1->first_object;
520 mapping_ctr = &c->ctr6->mapping_ctr;
521 total_object_count = c->ctr6->total_object_count;
522 object_count = c->ctr6->object_count;
523 first_object = c->ctr6->first_object;
526 return NT_STATUS_INVALID_PARAMETER;
529 if (total_object_count) {
530 DEBUG(0,("Schema-DN[%s] objects[%u/%u]\n",
531 c->partition->nc.dn, object_count, total_object_count));
533 DEBUG(0,("Schema-DN[%s] objects[%u]\n",
534 c->partition->nc.dn, object_count));
538 s->self_made_schema = talloc_zero(s, struct dsdb_schema);
539 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
541 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr);
542 if (!W_ERROR_IS_OK(status)) {
543 return werror_to_ntstatus(status);
546 s->schema = s->self_made_schema;
548 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr);
549 if (!W_ERROR_IS_OK(status)) {
550 return werror_to_ntstatus(status);
554 if (!s->schema_part.first_object) {
555 s->schema_part.object_count = object_count;
556 s->schema_part.first_object = talloc_steal(s, first_object);
558 s->schema_part.object_count += object_count;
559 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object,
562 for (cur = first_object; cur->next_object; cur = cur->next_object) {}
563 s->schema_part.last_object = cur;
565 if (c->partition->highwatermark.tmp_highest_usn == c->partition->highwatermark.highest_usn) {
566 return test_apply_schema(s, c);
572 static NTSTATUS test_become_dc_store_chunk(void *private_data,
573 const struct libnet_BecomeDC_StoreChunk *c)
575 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
577 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
578 uint32_t total_object_count;
579 uint32_t object_count;
580 struct drsuapi_DsReplicaObjectListItemEx *first_object;
581 uint32_t linked_attributes_count;
582 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
583 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
584 struct dsdb_extended_replicated_objects *objs;
585 struct repsFromTo1 *s_dsa;
589 s_dsa = talloc_zero(s, struct repsFromTo1);
590 NT_STATUS_HAVE_NO_MEMORY(s_dsa);
591 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo);
592 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info);
594 switch (c->ctr_level) {
596 mapping_ctr = &c->ctr1->mapping_ctr;
597 total_object_count = c->ctr1->total_object_count;
598 object_count = c->ctr1->object_count;
599 first_object = c->ctr1->first_object;
600 linked_attributes_count = 0;
601 linked_attributes = NULL;
602 s_dsa->highwatermark = c->ctr1->new_highwatermark;
603 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid;
604 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id;
605 uptodateness_vector = NULL; /* TODO: map it */
608 mapping_ctr = &c->ctr6->mapping_ctr;
609 total_object_count = c->ctr6->total_object_count;
610 object_count = c->ctr6->object_count;
611 first_object = c->ctr6->first_object;
612 linked_attributes_count = c->ctr6->linked_attributes_count;
613 linked_attributes = c->ctr6->linked_attributes;
614 s_dsa->highwatermark = c->ctr6->new_highwatermark;
615 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid;
616 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id;
617 uptodateness_vector = c->ctr6->uptodateness_vector;
620 return NT_STATUS_INVALID_PARAMETER;
623 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE
624 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
625 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS;
626 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule));
628 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid);
629 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
630 tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name);
631 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
632 s_dsa->other_info->dns_name = tmp_dns_name;
634 if (total_object_count) {
635 DEBUG(0,("Partition[%s] objects[%u/%u]\n",
636 c->partition->nc.dn, object_count, total_object_count));
638 DEBUG(0,("Partition[%s] objects[%u]\n",
639 c->partition->nc.dn, object_count));
642 status = dsdb_extended_replicated_objects_commit(s->ldb,
647 linked_attributes_count,
653 if (!W_ERROR_IS_OK(status)) {
654 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
655 return werror_to_ntstatus(status);
658 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
659 for (i=0; i < objs->num_objects; i++) {
660 struct ldb_ldif ldif;
661 fprintf(stdout, "#\n");
662 ldif.changetype = LDB_CHANGETYPE_NONE;
663 ldif.msg = objs->objects[i].msg;
664 ldb_ldif_write_file(s->ldb, stdout, &ldif);
665 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
671 for (i=0; i < linked_attributes_count; i++) {
672 const struct dsdb_attribute *sa;
674 if (!linked_attributes[i].identifier) {
675 return NT_STATUS_FOOBAR;
678 if (!linked_attributes[i].value.blob) {
679 return NT_STATUS_FOOBAR;
682 sa = dsdb_attribute_by_attributeID_id(s->schema,
683 linked_attributes[i].attid);
685 return NT_STATUS_FOOBAR;
688 if (lp_parm_bool(-1, "become dc", "dump objects", False)) {
689 DEBUG(0,("# %s\n", sa->lDAPDisplayName));
690 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]);
692 linked_attributes[i].value.blob->data,
693 linked_attributes[i].value.blob->length);
700 static NTSTATUS test_become_dc_domain_chunk(void *private_data,
701 const struct libnet_BecomeDC_StoreChunk *c)
703 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state);
705 s->computer_dn = talloc_strdup(s, c->dest_dsa->computer_dn_str);
706 NT_STATUS_HAVE_NO_MEMORY(s->computer_dn);
708 return test_become_dc_store_chunk(private_data, c);
711 BOOL torture_net_become_dc(struct torture_context *torture)
715 struct libnet_BecomeDC b;
716 struct libnet_UnbecomeDC u;
717 struct test_become_dc_state *s;
718 struct ldb_message *msg;
722 s = talloc_zero(torture, struct test_become_dc_state);
723 if (!s) return False;
725 /* Join domain as a member server. */
726 s->tj = torture_join_domain(TORTURE_NETBIOS_NAME,
728 &s->machine_account);
730 DEBUG(0, ("%s failed to join domain as workstation\n",
731 TORTURE_NETBIOS_NAME));
735 s->ctx = libnet_context_init(event_context_init(s));
736 s->ctx->cred = cmdline_credentials;
738 s->ldb = ldb_init(s);
741 b.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
742 b.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
743 b.in.domain_sid = torture_join_sid(s->tj);
744 b.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
745 b.in.dest_dsa_netbios_name = TORTURE_NETBIOS_NAME;
747 b.in.callbacks.private_data = s;
748 b.in.callbacks.check_options = test_become_dc_check_options;
749 b.in.callbacks.prepare_db = test_become_dc_prepare_db;
750 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;
751 b.in.callbacks.config_chunk = test_become_dc_store_chunk;
752 b.in.callbacks.domain_chunk = test_become_dc_domain_chunk;
754 status = libnet_BecomeDC(s->ctx, s, &b);
755 if (!NT_STATUS_IS_OK(status)) {
756 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status));
761 msg = ldb_msg_new(s);
763 printf("ldb_msg_new() failed\n");
767 msg->dn = ldb_dn_new(msg, s->ldb, "cn=ROOTDSE");
769 printf("ldb_msg_new(cn=ROOTDSE) failed\n");
774 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE");
775 if (ldb_ret != LDB_SUCCESS) {
776 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret);
781 for (i=0; i < msg->num_elements; i++) {
782 msg->elements[i].flags = LDB_FLAG_MOD_REPLACE;
785 printf("mark ROOTDSE with isSynchronized=TRUE\n");
786 ldb_ret = ldb_modify(s->ldb, msg);
787 if (ldb_ret != LDB_SUCCESS) {
788 printf("ldb_modify() failed: %d\n", ldb_ret);
794 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */
797 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", TORTURE_SAMDB_LDB));
798 s->ldb = ldb_wrap_connect(s, TORTURE_SAMDB_LDB,
802 DEBUG(0,("Failed to open '%s'\n",
808 s->schema = dsdb_get_schema(s->ldb);
810 DEBUG(0,("Failed to get loaded dsdb_schema\n"));
815 if (lp_parm_bool(-1, "become dc", "donnot leave", False)) {
822 u.in.domain_dns_name = torture_join_dom_dns_name(s->tj);
823 u.in.domain_netbios_name = torture_join_dom_netbios_name(s->tj);
824 u.in.source_dsa_address = lp_parm_string(-1, "torture", "host");
825 u.in.dest_dsa_netbios_name = TORTURE_NETBIOS_NAME;
827 status = libnet_UnbecomeDC(s->ctx, s, &u);
828 if (!NT_STATUS_IS_OK(status)) {
829 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status));
834 torture_leave_domain(s->tj);