#include "includes.h"
#include "dsdb/samdb/samdb.h"
#include "dsdb/common/util.h"
-#include "lib/ldb/include/ldb_errors.h"
+#include <ldb_errors.h>
#include "../lib/util/dlinklist.h"
#include "librpc/gen_ndr/ndr_misc.h"
#include "librpc/gen_ndr/ndr_drsuapi.h"
#include "librpc/gen_ndr/ndr_drsblobs.h"
#include "param/param.h"
-#include "lib/ldb/include/ldb_module.h"
+#include <ldb_module.h>
#include "../lib/util/asn1.h"
return schema;
}
+struct dsdb_schema *dsdb_schema_copy_shallow(TALLOC_CTX *mem_ctx,
+ struct ldb_context *ldb,
+ const struct dsdb_schema *schema)
+{
+ int ret;
+ struct dsdb_class *cls;
+ struct dsdb_attribute *attr;
+ struct dsdb_schema *schema_copy;
+
+ schema_copy = dsdb_new_schema(mem_ctx);
+ if (!schema_copy) {
+ return NULL;
+ }
+
+ /* schema base_dn */
+ schema_copy->base_dn = ldb_dn_copy(schema_copy, schema->base_dn);
+ if (!schema_copy->base_dn) {
+ goto failed;
+ }
+
+ /* copy prexiMap & schemaInfo */
+ schema_copy->prefixmap = dsdb_schema_pfm_copy_shallow(schema_copy,
+ schema->prefixmap);
+ if (!schema_copy->prefixmap) {
+ goto failed;
+ }
+
+ schema_copy->schema_info = talloc_strdup(schema_copy, schema->schema_info);
+
+ /* copy classes and attributes*/
+ for (cls = schema->classes; cls; cls = cls->next) {
+ struct dsdb_class *class_copy = talloc_memdup(schema_copy,
+ cls, sizeof(*cls));
+ if (!class_copy) {
+ goto failed;
+ }
+ DLIST_ADD(schema_copy->classes, class_copy);
+ }
+ schema_copy->num_classes = schema->num_classes;
+
+ for (attr = schema->attributes; attr; attr = attr->next) {
+ struct dsdb_attribute *a_copy = talloc_memdup(schema_copy,
+ attr, sizeof(*attr));
+ if (!a_copy) {
+ goto failed;
+ }
+ DLIST_ADD(schema_copy->attributes, a_copy);
+ }
+ schema_copy->num_attributes = schema->num_attributes;
+
+ /* rebuild indexes */
+ ret = dsdb_setup_sorted_accessors(ldb, schema_copy);
+ if (ret != LDB_SUCCESS) {
+ goto failed;
+ }
+
+ /* leave reload_seq_number = 0 so it will be refresh ASAP */
+ schema_copy->refresh_fn = schema->refresh_fn;
+ schema_copy->loaded_from_module = schema->loaded_from_module;
+
+ return schema_copy;
+
+failed:
+ talloc_free(schema_copy);
+ return NULL;
+}
+
WERROR dsdb_load_prefixmap_from_drsuapi(struct dsdb_schema *schema,
const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
(ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
- talloc_free(temp_ctx);
DEBUG(0,("_dsdb_prefixmap_from_ldb_val: Failed to parse prefixmap of length %u: %s\n",
(unsigned int)pfm_ldb_val->length, ndr_map_error2string(ndr_err)));
talloc_free(temp_ctx);
/* prefix found*/
talloc_free(mem_ctx);
return status;
- } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
+ } else if (!W_ERROR_EQUAL(status, WERR_NOT_FOUND)) {
/* error */
DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
win_errstr(status)));
const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
if (get_string_val == NULL) { \
if (strict) { \
- d_printf("%s: %s == NULL\n", __location__, attr); \
+ d_printf("%s: %s == NULL in %s\n", __location__, attr, ldb_dn_get_linearized(msg->dn)); \
return WERR_INVALID_PARAM; \
} else { \
(p)->elem = NULL; \
#define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
const char *str; \
- str = samdb_result_string(msg, attr, NULL);\
+ str = ldb_msg_find_attr_as_string(msg, attr, NULL);\
if (str == NULL) { \
if (strict) { \
d_printf("%s: %s == NULL\n", __location__, attr); \
} while (0)
#define GET_UINT32_LDB(msg, attr, p, elem) do { \
- (p)->elem = samdb_result_uint(msg, attr, 0);\
+ (p)->elem = ldb_msg_find_attr_as_uint(msg, attr, 0);\
} while (0)
#define GET_UINT32_PTR_LDB(msg, attr, mem_ctx, p, elem) do { \
- uint64_t _v = samdb_result_uint64(msg, attr, UINT64_MAX);\
+ uint64_t _v = ldb_msg_find_attr_as_uint64(msg, attr, UINT64_MAX);\
if (_v == UINT64_MAX) { \
(p)->elem = NULL; \
} else if (_v > UINT32_MAX) { \
GET_STRING_LDB(msg, "attributeID", attr, attr, attributeID_oid, true);
if (!schema->prefixmap || schema->prefixmap->length == 0) {
/* set an invalid value */
- attr->attributeID_id = 0xFFFFFFFF;
+ attr->attributeID_id = DRSUAPI_ATTID_INVALID;
} else {
status = dsdb_schema_pfm_make_attid(schema->prefixmap,
attr->attributeID_oid,
GET_STRING_LDB(msg, "attributeSyntax", attr, attr, attributeSyntax_oid, true);
if (!schema->prefixmap || schema->prefixmap->length == 0) {
/* set an invalid value */
- attr->attributeSyntax_id = 0xFFFFFFFF;
+ attr->attributeSyntax_id = DRSUAPI_ATTID_INVALID;
} else {
- status = dsdb_schema_pfm_make_attid(schema->prefixmap,
- attr->attributeSyntax_oid,
- &attr->attributeSyntax_id);
+ status = dsdb_schema_pfm_attid_from_oid(schema->prefixmap,
+ attr->attributeSyntax_oid,
+ &attr->attributeSyntax_id);
if (!W_ERROR_IS_OK(status)) {
DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
__location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
}
if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
- DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
- attr->lDAPDisplayName));
+ DEBUG(0,(__location__ ": Unknown schema syntax for %s - ldb_syntax: %s, ldap_oid: %s\n",
+ attr->lDAPDisplayName,
+ attr->syntax->ldb_syntax,
+ attr->syntax->ldap_oid));
return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
}
GET_STRING_LDB(msg, "governsID", obj, obj, governsID_oid, true);
if (!schema->prefixmap || schema->prefixmap->length == 0) {
/* set an invalid value */
- obj->governsID_id = 0xFFFFFFFF;
+ obj->governsID_id = DRSUAPI_ATTID_INVALID;
} else {
status = dsdb_schema_pfm_make_attid(schema->prefixmap,
obj->governsID_oid,
GET_STRING_LDB(msg, "defaultSecurityDescriptor", obj, obj, defaultSecurityDescriptor, false);
GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
+ GET_UINT32_LDB(msg, "systemFlags", obj, systemFlags);
GET_BLOB_LDB(msg, "msDs-Schema-Extensions", obj, obj, msDs_Schema_Extensions);
GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
#define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
/*
+ Fill a DSDB schema from the ldb results provided. This is called
+ directly when a schema must be created with a pre-initialised prefixMap
+*/
+
+int dsdb_load_ldb_results_into_schema(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
+ struct dsdb_schema *schema,
+ struct ldb_result *attrs_class_res,
+ char **error_string)
+{
+ unsigned int i;
+
+ for (i=0; i < attrs_class_res->count; i++) {
+ WERROR status = dsdb_schema_set_el_from_ldb_msg(ldb, schema, attrs_class_res->msgs[i]);
+ if (!W_ERROR_IS_OK(status)) {
+ *error_string = talloc_asprintf(mem_ctx,
+ "dsdb_load_ldb_results_into_schema: failed to load attribute or class definition: %s:%s",
+ ldb_dn_get_linearized(attrs_class_res->msgs[i]->dn),
+ win_errstr(status));
+ DEBUG(0,(__location__ ": %s\n", *error_string));
+ return LDB_ERR_CONSTRAINT_VIOLATION;
+ }
+ }
+
+ return LDB_SUCCESS;
+}
+
+/*
Create a DSDB schema from the ldb results provided. This is called
directly when the schema is provisioned from an on-disk LDIF file, or
from dsdb_schema_from_schema_dn in schema_fsmo
int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
struct ldb_result *schema_res,
- struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
+ struct ldb_result *attrs_class_res,
struct dsdb_schema **schema_out,
char **error_string)
{
WERROR status;
- unsigned int i;
const struct ldb_val *prefix_val;
const struct ldb_val *info_val;
struct ldb_val info_val_default;
struct dsdb_schema *schema;
+ int ret;
schema = dsdb_new_schema(mem_ctx);
if (!schema) {
return LDB_ERR_CONSTRAINT_VIOLATION;
}
- for (i=0; i < attrs_res->count; i++) {
- status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i]);
- if (!W_ERROR_IS_OK(status)) {
- *error_string = talloc_asprintf(mem_ctx,
- "schema_fsmo_init: failed to load attribute definition: %s:%s",
- ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
- win_errstr(status));
- DEBUG(0,(__location__ ": %s\n", *error_string));
- return LDB_ERR_CONSTRAINT_VIOLATION;
- }
- }
-
- for (i=0; i < objectclass_res->count; i++) {
- status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i]);
- if (!W_ERROR_IS_OK(status)) {
- *error_string = talloc_asprintf(mem_ctx,
- "schema_fsmo_init: failed to load class definition: %s:%s",
- ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
- win_errstr(status));
- DEBUG(0,(__location__ ": %s\n", *error_string));
- return LDB_ERR_CONSTRAINT_VIOLATION;
- }
+ ret = dsdb_load_ldb_results_into_schema(mem_ctx, ldb, schema, attrs_class_res, error_string);
+ if (ret != LDB_SUCCESS) {
+ return ret;
}
schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");