#include "lib/events/events.h"
#include "dsdb/samdb/samdb.h"
#include "../lib/util/dlinklist.h"
-#include "lib/ldb/include/ldb.h"
-#include "lib/ldb/include/ldb_errors.h"
+#include <ldb.h>
+#include <ldb_errors.h>
#include "librpc/ndr/libndr.h"
#include "librpc/gen_ndr/ndr_drsuapi.h"
#include "librpc/gen_ndr/ndr_drsblobs.h"
#include "auth/credentials/credentials.h"
#include "param/param.h"
#include "param/provision.h"
-#include "libcli/security/dom_sid.h"
+#include "libcli/security/security.h"
#include "dsdb/common/util.h"
/*
* converted, because we may not know them yet */
struct dsdb_schema *self_made_schema;
- /* 2nd pass, with full ID->OID->name table */
- struct dsdb_schema *self_corrected_schema;
-
/* prefixMap in LDB format, from the remote DRS server */
DATA_BLOB prefixmap_blob;
const struct dsdb_schema *schema;
s->lp_ctx = lp_ctx;
s->provision_schema = dsdb_get_schema(s->ldb, s);
s->schema = s->provision_schema;
+ s->netbios_name = lpcfg_netbios_name(lp_ctx);
+ s->domain_name = lpcfg_workgroup(lp_ctx);
+ s->realm = lpcfg_realm(lp_ctx);
return s;
}
settings.server_dn_str = p->dest_dsa->server_dn_str;
settings.machine_password = generate_random_password(s, 16, 255);
settings.targetdir = s->targetdir;
-
+ settings.use_ntvfs = true;
status = provision_bare(s, s->lp_ctx, &settings, &result);
if (!NT_STATUS_IS_OK(status)) {
}
s->ldb = talloc_steal(s, result.samdb);
- s->lp_ctx = talloc_steal(s, result.lp_ctx);
+ s->lp_ctx = talloc_reparent(talloc_parent(result.lp_ctx), s, result.lp_ctx);
s->provision_schema = dsdb_get_schema(s->ldb, s);
s->server_dn_str = talloc_steal(s, p->dest_dsa->server_dn_str);
static NTSTATUS libnet_vampire_cb_apply_schema(struct libnet_vampire_cb_state *s,
const struct libnet_BecomeDC_StoreChunk *c)
{
+ struct schema_list {
+ struct schema_list *next, *prev;
+ const struct drsuapi_DsReplicaObjectListItemEx *obj;
+ };
+
WERROR status;
+ struct dsdb_schema_prefixmap *pfm_remote;
const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
- uint32_t object_count;
+ struct schema_list *schema_list = NULL, *schema_list_item, *schema_list_next_item;
+ struct dsdb_schema *working_schema;
+ struct dsdb_schema *provision_schema;
+ uint32_t object_count = 0;
struct drsuapi_DsReplicaObjectListItemEx *first_object;
const struct drsuapi_DsReplicaObjectListItemEx *cur;
uint32_t linked_attributes_count;
struct ldb_message *msg;
struct ldb_message_element *prefixMap_el;
uint32_t i;
- int ret;
+ int ret, pass_no;
bool ok;
uint64_t seq_num;
+ uint32_t ignore_attids[] = {
+ DRSUAPI_ATTID_auxiliaryClass,
+ DRSUAPI_ATTID_mayContain,
+ DRSUAPI_ATTID_mustContain,
+ DRSUAPI_ATTID_possSuperiors,
+ DRSUAPI_ATTID_systemPossSuperiors,
+ DRSUAPI_ATTID_INVALID
+ };
DEBUG(0,("Analyze and apply schema objects\n"));
default:
return NT_STATUS_INVALID_PARAMETER;
}
+ /* We must set these up to ensure the replMetaData is written
+ * correctly, before our NTDS Settings entry is replicated */
+ ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
+ if (!ok) {
+ DEBUG(0,("Failed to set cached ntds invocationId\n"));
+ return NT_STATUS_FOOBAR;
+ }
+ ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
+ if (!ok) {
+ DEBUG(0,("Failed to set cached ntds objectGUID\n"));
+ return NT_STATUS_FOOBAR;
+ }
+
+
+ status = dsdb_schema_pfm_from_drsuapi_pfm(mapping_ctr, true,
+ s, &pfm_remote, NULL);
+ if (!W_ERROR_IS_OK(status)) {
+ DEBUG(0,(__location__ ": Failed to decode remote prefixMap: %s",
+ win_errstr(status)));
+ return werror_to_ntstatus(status);
+ }
s_dsa->replica_flags = DRSUAPI_DRS_WRIT_REP
| DRSUAPI_DRS_INIT_SYNC
NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name);
s_dsa->other_info->dns_name = tmp_dns_name;
- schema_ldb = provision_get_schema(s, s->lp_ctx, &s->prefixmap_blob);
+ schema_ldb = provision_get_schema(s, s->lp_ctx,
+ c->forest->schema_dn_str,
+ &s->prefixmap_blob);
if (!schema_ldb) {
- DEBUG(0,("Failed to re-load from local provision using remote prefixMap. Will continue with local prefixMap\n"));
- s->provision_schema = dsdb_get_schema(s->ldb, s);
+ DEBUG(0,("Failed to re-load from local provision using remote prefixMap. "
+ "Will continue with local prefixMap\n"));
+ provision_schema = dsdb_get_schema(s->ldb, s);
} else {
- s->provision_schema = dsdb_get_schema(schema_ldb, s);
- ret = dsdb_reference_schema(s->ldb, s->provision_schema, false);
+ provision_schema = dsdb_get_schema(schema_ldb, s);
+ ret = dsdb_reference_schema(s->ldb, provision_schema, false);
if (ret != LDB_SUCCESS) {
DEBUG(0,("Failed to attach schema from local provision using remote prefixMap."));
return NT_STATUS_UNSUCCESSFUL;
talloc_free(schema_ldb);
}
- s->provision_schema->relax_OID_conversions = true;
+ /* create a list of objects yet to be converted */
+ for (cur = first_object; cur; cur = cur->next_object) {
+ schema_list_item = talloc(s, struct schema_list);
+ schema_list_item->obj = cur;
+ DLIST_ADD_END(schema_list, schema_list_item, struct schema_list);
+ }
+
+ /* resolve objects until all are resolved and in local schema */
+ pass_no = 1;
+ working_schema = provision_schema;
- /* Now convert the schema elements, using the schema we loaded locally */
- for (i=0, cur = first_object; cur; cur = cur->next_object, i++) {
- struct dsdb_extended_replicated_object object;
+ while (schema_list) {
+ uint32_t converted_obj_count = 0;
+ uint32_t failed_obj_count = 0;
TALLOC_CTX *tmp_ctx = talloc_new(s);
NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
- /* Convert the objects into LDB messages using the
- * provision schema, and either the provision or DRS
- * prefix map - it should not matter, as these are
- * just schema objects, so the critical parts. At
- * most we would mix up the mayContain etc for new
- * schema classes */
- status = dsdb_convert_object_ex(s->ldb, s->provision_schema,
- cur, c->gensec_skey,
- tmp_ctx, &object);
- if (!W_ERROR_IS_OK(status)) {
- DEBUG(1,("Warning: Failed to convert schema object %s into ldb msg\n", cur->object.identifier->dn));
- } else {
- /* Convert the schema from ldb_message format
- * (OIDs as OID strings) into schema, using
- * the remote prefixMap */
- status = dsdb_schema_set_el_from_ldb_msg(s->ldb, s->self_made_schema, object.msg);
+ for (schema_list_item = schema_list; schema_list_item; schema_list_item=schema_list_next_item) {
+ struct dsdb_extended_replicated_object object;
+
+ cur = schema_list_item->obj;
+
+ /* Save the next item, now we have saved out
+ * the current one, so we can DLIST_REMOVE it
+ * safely */
+ schema_list_next_item = schema_list_item->next;
+
+ /*
+ * Convert the objects into LDB messages using the
+ * schema we have so far. It's ok if we fail to convert
+ * an object. We should convert more objects on next pass.
+ */
+ status = dsdb_convert_object_ex(s->ldb, working_schema, pfm_remote,
+ cur, c->gensec_skey,
+ ignore_attids,
+ 0,
+ tmp_ctx, &object);
if (!W_ERROR_IS_OK(status)) {
- DEBUG(1,("Warning: failed to convert object %s into a schema element: %s\n",
- ldb_dn_get_linearized(object.msg->dn),
- win_errstr(status)));
+ DEBUG(1,("Warning: Failed to convert schema object %s into ldb msg\n",
+ cur->object.identifier->dn));
+
+ failed_obj_count++;
+ } else {
+ /*
+ * Convert the schema from ldb_message format
+ * (OIDs as OID strings) into schema, using
+ * the remote prefixMap
+ */
+ status = dsdb_schema_set_el_from_ldb_msg(s->ldb,
+ s->self_made_schema,
+ object.msg);
+ if (!W_ERROR_IS_OK(status)) {
+ DEBUG(1,("Warning: failed to convert object %s into a schema element: %s\n",
+ ldb_dn_get_linearized(object.msg->dn),
+ win_errstr(status)));
+ failed_obj_count++;
+ } else {
+ DLIST_REMOVE(schema_list, schema_list_item);
+ converted_obj_count++;
+ }
}
}
talloc_free(tmp_ctx);
- }
- /* attach the schema we just brought over DRS to the ldb, so we can use it in dsdb_convert_object_ex below */
- ret = dsdb_set_schema(s->ldb, s->self_made_schema);
- if (ret != LDB_SUCCESS) {
- DEBUG(0,("Failed to attach 1st pass schema from DRS.\n"));
- return NT_STATUS_FOOBAR;
- }
+ DEBUG(4,("Schema load pass %d: %d/%d of %d objects left to be converted.\n",
+ pass_no, failed_obj_count, converted_obj_count, object_count));
+ pass_no++;
- /* Now convert the schema elements again, using the schema we loaded over DRS */
- for (i=0, cur = first_object; cur; cur = cur->next_object, i++) {
- struct dsdb_extended_replicated_object object;
- TALLOC_CTX *tmp_ctx = talloc_new(s);
- NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
+ /* check if we converted any objects in this pass */
+ if (converted_obj_count == 0) {
+ DEBUG(0,("Can't continue Schema load: didn't manage to convert any objects: all %d remaining of %d objects failed to convert\n", failed_obj_count, object_count));
+ return NT_STATUS_INTERNAL_ERROR;
+ }
- /* Convert the objects into LDB messages using the
- * self_made_schema, and the DRS prefix map. We now
- * know the full schema int->OID->name mapping, so we
- * can get it right this time */
- status = dsdb_convert_object_ex(s->ldb, s->self_made_schema,
- cur, c->gensec_skey,
- tmp_ctx, &object);
- if (!W_ERROR_IS_OK(status)) {
- DEBUG(0,("ERROR: Failed to convert schema object %s into ldb msg\n", cur->object.identifier->dn));
- } else {
- /* Convert the schema from ldb_message format
- * (OIDs as OID strings) into schema, using
- * the remote prefixMap, now that we know
- * names for all the schema elements (from the
- * first conversion) */
- status = dsdb_schema_set_el_from_ldb_msg(s->ldb, s->self_corrected_schema, object.msg);
- if (!W_ERROR_IS_OK(status)) {
- DEBUG(0,("ERROR: failed to convert object %s into a schema element: %s\n",
- ldb_dn_get_linearized(object.msg->dn),
- win_errstr(status)));
+ if (schema_list) {
+ /* prepare for another cycle */
+ working_schema = s->self_made_schema;
+
+ ret = dsdb_setup_sorted_accessors(s->ldb, working_schema);
+ if (LDB_SUCCESS != ret) {
+ DEBUG(0,("Failed to create schema-cache indexes!\n"));
+ return NT_STATUS_INTERNAL_ERROR;
}
}
- talloc_free(tmp_ctx);
- }
+ };
- /* We don't want to use the s->self_made_schema any more */
- s->self_made_schema = NULL;
+ /* free temp objects for 1st conversion phase */
+ talloc_unlink(s, provision_schema);
+ TALLOC_FREE(schema_list);
- /* attach the schema we just brought over DRS to the ldb */
- ret = dsdb_set_schema(s->ldb, s->self_corrected_schema);
+ /*
+ * attach the schema we just brought over DRS to the ldb,
+ * so we can use it in dsdb_convert_object_ex below
+ */
+ ret = dsdb_set_schema(s->ldb, s->self_made_schema);
if (ret != LDB_SUCCESS) {
- DEBUG(0,("Failed to attach 2nd pass (corrected) schema from DRS.\n"));
+ DEBUG(0,("Failed to attach working schema from DRS.\n"));
return NT_STATUS_FOOBAR;
}
/* we don't want to access the self made schema anymore */
- s->schema = s->self_corrected_schema;
- s->self_corrected_schema = NULL;
+ s->schema = s->self_made_schema;
+ s->self_made_schema = NULL;
/* Now convert the schema elements again, using the schema we finalised, ready to actually import */
- status = dsdb_extended_replicated_objects_convert(s->ldb,
- c->partition->nc.dn,
- mapping_ctr,
- object_count,
- first_object,
- linked_attributes_count,
- linked_attributes,
- s_dsa,
- uptodateness_vector,
- c->gensec_skey,
- s, &schema_objs);
+ status = dsdb_replicated_objects_convert(s->ldb,
+ s->schema,
+ c->partition->nc.dn,
+ mapping_ctr,
+ object_count,
+ first_object,
+ linked_attributes_count,
+ linked_attributes,
+ s_dsa,
+ uptodateness_vector,
+ c->gensec_skey,
+ 0,
+ s, &schema_objs);
if (!W_ERROR_IS_OK(status)) {
DEBUG(0,("Failed to convert objects when trying to import over DRS (2nd pass, to store remote schema): %s\n", win_errstr(status)));
return werror_to_ntstatus(status);
}
}
- status = dsdb_extended_replicated_objects_commit(s->ldb, schema_objs, &seq_num);
+ status = dsdb_replicated_objects_commit(s->ldb, NULL, schema_objs, &seq_num);
if (!W_ERROR_IS_OK(status)) {
DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
return werror_to_ntstatus(status);
* somehow updated the prefixMap during this transaction */
prefixMap_el->flags = LDB_FLAG_MOD_ADD;
- ret = ldb_modify(s->ldb, msg);
+ ret = dsdb_modify(s->ldb, msg, DSDB_FLAG_AS_SYSTEM);
if (ret != LDB_SUCCESS) {
DEBUG(0,("Failed to add prefixMap: %s\n", ldb_errstring(s->ldb)));
return NT_STATUS_FOOBAR;
talloc_free(s_dsa);
talloc_free(schema_objs);
- /* We must set these up to ensure the replMetaData is written
- * correctly, before our NTDS Settings entry is replicated */
- ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id);
- if (!ok) {
- DEBUG(0,("Failed to set cached ntds invocationId\n"));
- return NT_STATUS_FOOBAR;
- }
- ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid);
- if (!ok) {
- DEBUG(0,("Failed to set cached ntds objectGUID\n"));
- return NT_STATUS_FOOBAR;
- }
-
s->schema = dsdb_get_schema(s->ldb, s);
if (!s->schema) {
DEBUG(0,("Failed to get loaded dsdb_schema\n"));
WERROR status;
const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
uint32_t nc_object_count;
+ uint32_t nc_total_received = 0;
uint32_t object_count;
struct drsuapi_DsReplicaObjectListItemEx *first_object;
struct drsuapi_DsReplicaObjectListItemEx *cur;
uint32_t nc_linked_attributes_count;
uint32_t linked_attributes_count;
- struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
switch (c->ctr_level) {
case 1:
first_object = c->ctr1->first_object;
nc_linked_attributes_count = 0;
linked_attributes_count = 0;
- linked_attributes = NULL;
break;
case 6:
mapping_ctr = &c->ctr6->mapping_ctr;
first_object = c->ctr6->first_object;
nc_linked_attributes_count = c->ctr6->nc_linked_attributes_count;
linked_attributes_count = c->ctr6->linked_attributes_count;
- linked_attributes = c->ctr6->linked_attributes;
break;
default:
return NT_STATUS_INVALID_PARAMETER;
}
+ if (!s->schema_part.first_object) {
+ nc_total_received = object_count;
+ } else {
+ nc_total_received = s->schema_part.object_count + object_count;
+ }
if (nc_object_count) {
DEBUG(0,("Schema-DN[%s] objects[%u/%u] linked_values[%u/%u]\n",
- c->partition->nc.dn, object_count, nc_object_count,
+ c->partition->nc.dn, nc_total_received, nc_object_count,
linked_attributes_count, nc_linked_attributes_count));
} else {
DEBUG(0,("Schema-DN[%s] objects[%u] linked_values[%u]\n",
- c->partition->nc.dn, object_count, linked_attributes_count));
+ c->partition->nc.dn, nc_total_received, linked_attributes_count));
}
if (!s->self_made_schema) {
* other. */
s->self_made_schema = dsdb_new_schema(s);
NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema);
- s->self_corrected_schema = dsdb_new_schema(s);
- NT_STATUS_HAVE_NO_MEMORY(s->self_corrected_schema);
- status = dsdb_load_prefixmap_from_drsuapi(s->self_made_schema, mapping_ctr);
- if (!W_ERROR_IS_OK(status)) {
- return werror_to_ntstatus(status);
- }
+ s->self_made_schema->base_dn = ldb_dn_new(s->self_made_schema,
+ s->ldb,
+ c->forest->schema_dn_str);
+ NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema->base_dn);
- status = dsdb_load_prefixmap_from_drsuapi(s->self_corrected_schema, mapping_ctr);
+ status = dsdb_load_prefixmap_from_drsuapi(s->self_made_schema, mapping_ctr);
if (!W_ERROR_IS_OK(status)) {
return werror_to_ntstatus(status);
}
{
struct libnet_vampire_cb_state *s = talloc_get_type(private_data, struct libnet_vampire_cb_state);
WERROR status;
+ struct dsdb_schema *schema;
const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr;
uint32_t nc_object_count;
uint32_t object_count;
struct drsuapi_DsReplicaLinkedAttribute *linked_attributes;
const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector;
struct dsdb_extended_replicated_objects *objs;
+ uint32_t req_replica_flags;
struct repsFromTo1 *s_dsa;
char *tmp_dns_name;
uint32_t i;
uint64_t seq_num;
+ bool is_exop = false;
s_dsa = talloc_zero(s, struct repsFromTo1);
NT_STATUS_HAVE_NO_MEMORY(s_dsa);
return NT_STATUS_INVALID_PARAMETER;
}
+ switch (c->req_level) {
+ case 0:
+ /* none */
+ req_replica_flags = 0;
+ break;
+ case 5:
+ if (c->req5->extended_op != DRSUAPI_EXOP_NONE) {
+ is_exop = true;
+ }
+ req_replica_flags = c->req5->replica_flags;
+ break;
+ case 8:
+ if (c->req8->extended_op != DRSUAPI_EXOP_NONE) {
+ is_exop = true;
+ }
+ req_replica_flags = c->req8->replica_flags;
+ break;
+ case 10:
+ if (c->req10->extended_op != DRSUAPI_EXOP_NONE) {
+ is_exop = true;
+ }
+ req_replica_flags = c->req10->replica_flags;
+ break;
+ default:
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (req_replica_flags & DRSUAPI_DRS_CRITICAL_ONLY) {
+ /*
+ * If we only replicate the critical objects
+ * we should not remember what we already
+ * got, as it is incomplete.
+ */
+ ZERO_STRUCT(s_dsa->highwatermark);
+ uptodateness_vector = NULL;
+ }
+
+ /* TODO: avoid hardcoded flags */
s_dsa->replica_flags = DRSUAPI_DRS_WRIT_REP
| DRSUAPI_DRS_INIT_SYNC
| DRSUAPI_DRS_PER_SYNC;
}
s->total_objects += object_count;
- if (nc_object_count) {
- DEBUG(0,("Partition[%s] objects[%u/%u] linked_values[%u/%u]\n",
- c->partition->nc.dn, s->total_objects, nc_object_count,
- linked_attributes_count, nc_linked_attributes_count));
+ if (is_exop) {
+ if (nc_object_count) {
+ DEBUG(0,("Exop on[%s] objects[%u/%u] linked_values[%u/%u]\n",
+ c->partition->nc.dn, s->total_objects, nc_object_count,
+ linked_attributes_count, nc_linked_attributes_count));
+ } else {
+ DEBUG(0,("Exop on[%s] objects[%u] linked_values[%u]\n",
+ c->partition->nc.dn, s->total_objects, linked_attributes_count));
+ }
} else {
- DEBUG(0,("Partition[%s] objects[%u] linked_values[%u]\n",
- c->partition->nc.dn, s->total_objects, linked_attributes_count));
- }
-
-
- status = dsdb_extended_replicated_objects_convert(s->ldb,
- c->partition->nc.dn,
- mapping_ctr,
- object_count,
- first_object,
- linked_attributes_count,
- linked_attributes,
- s_dsa,
- uptodateness_vector,
- c->gensec_skey,
- s, &objs);
+ if (nc_object_count) {
+ DEBUG(0,("Partition[%s] objects[%u/%u] linked_values[%u/%u]\n",
+ c->partition->nc.dn, s->total_objects, nc_object_count,
+ linked_attributes_count, nc_linked_attributes_count));
+ } else {
+ DEBUG(0,("Partition[%s] objects[%u] linked_values[%u]\n",
+ c->partition->nc.dn, s->total_objects, linked_attributes_count));
+ }
+ }
+
+
+ schema = dsdb_get_schema(s->ldb, NULL);
+ if (!schema) {
+ DEBUG(0,(__location__ ": Schema is not loaded yet!\n"));
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ status = dsdb_replicated_objects_convert(s->ldb,
+ schema,
+ c->partition->nc.dn,
+ mapping_ctr,
+ object_count,
+ first_object,
+ linked_attributes_count,
+ linked_attributes,
+ s_dsa,
+ uptodateness_vector,
+ c->gensec_skey,
+ 0,
+ s, &objs);
if (!W_ERROR_IS_OK(status)) {
DEBUG(0,("Failed to convert objects: %s\n", win_errstr(status)));
return werror_to_ntstatus(status);
NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data);
}
}
- status = dsdb_extended_replicated_objects_commit(s->ldb,
- objs, &seq_num);
+ status = dsdb_replicated_objects_commit(s->ldb, NULL, objs, &seq_num);
if (!W_ERROR_IS_OK(status)) {
DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status)));
return werror_to_ntstatus(status);
const struct dsdb_attribute *sa;
if (!linked_attributes[i].identifier) {
- return NT_STATUS_FOOBAR;
+ DEBUG(0, ("No linked attribute identifier\n"));
+ return NT_STATUS_FOOBAR;
}
if (!linked_attributes[i].value.blob) {
- return NT_STATUS_FOOBAR;
+ DEBUG(0, ("No linked attribute value\n"));
+ return NT_STATUS_FOOBAR;
}
sa = dsdb_attribute_by_attributeID_id(s->schema,
linked_attributes[i].attid);
if (!sa) {
+ DEBUG(0, ("Unable to find attribute via attribute id %d\n", linked_attributes[i].attid));
return NT_STATUS_FOOBAR;
}