2 Unix SMB/CIFS mplementation.
5 Copyright (C) Stefan Metzmacher <metze@samba.org> 2006-2007
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006-2008
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 3 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, see <http://www.gnu.org/licenses/>.
24 #include "dsdb/samdb/samdb.h"
25 #include "dsdb/common/util.h"
26 #include "lib/ldb/include/ldb_errors.h"
27 #include "../lib/util/dlinklist.h"
28 #include "librpc/gen_ndr/ndr_misc.h"
29 #include "librpc/gen_ndr/ndr_drsuapi.h"
30 #include "librpc/gen_ndr/ndr_drsblobs.h"
31 #include "param/param.h"
32 #include "lib/ldb/include/ldb_module.h"
33 #include "../lib/util/asn1.h"
36 struct dsdb_schema *dsdb_new_schema(TALLOC_CTX *mem_ctx)
38 struct dsdb_schema *schema = talloc_zero(mem_ctx, struct dsdb_schema);
47 WERROR dsdb_load_prefixmap_from_drsuapi(struct dsdb_schema *schema,
48 const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
51 const char *schema_info;
52 struct dsdb_schema_prefixmap *pfm;
54 werr = dsdb_schema_pfm_from_drsuapi_pfm(ctr, true, schema, &pfm, &schema_info);
55 W_ERROR_NOT_OK_RETURN(werr);
57 /* set loaded prefixMap */
58 talloc_free(schema->prefixmap);
59 schema->prefixmap = pfm;
61 talloc_free(discard_const(schema->schema_info));
62 schema->schema_info = schema_info;
67 static WERROR _dsdb_prefixmap_from_ldb_val(const struct ldb_val *pfm_ldb_val,
69 struct dsdb_schema_prefixmap **_pfm)
72 enum ndr_err_code ndr_err;
73 struct prefixMapBlob pfm_blob;
75 TALLOC_CTX *temp_ctx = talloc_new(mem_ctx);
76 W_ERROR_HAVE_NO_MEMORY(temp_ctx);
78 ndr_err = ndr_pull_struct_blob(pfm_ldb_val, temp_ctx,
80 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
81 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
82 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
83 DEBUG(0,("_dsdb_prefixmap_from_ldb_val: Failed to parse prefixmap of length %u: %s\n",
84 (unsigned int)pfm_ldb_val->length, ndr_map_error2string(ndr_err)));
85 talloc_free(temp_ctx);
86 return ntstatus_to_werror(nt_status);
89 if (pfm_blob.version != PREFIX_MAP_VERSION_DSDB) {
90 DEBUG(0,("_dsdb_prefixmap_from_ldb_val: pfm_blob->version %u incorrect\n", (unsigned int)pfm_blob.version));
91 talloc_free(temp_ctx);
92 return WERR_VERSION_PARSE_ERROR;
95 /* call the drsuapi version */
96 werr = dsdb_schema_pfm_from_drsuapi_pfm(&pfm_blob.ctr.dsdb, false, mem_ctx, _pfm, NULL);
97 if (!W_ERROR_IS_OK(werr)) {
98 DEBUG(0, (__location__ " dsdb_schema_pfm_from_drsuapi_pfm failed: %s\n", win_errstr(werr)));
99 talloc_free(temp_ctx);
103 talloc_free(temp_ctx);
108 WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
109 const struct ldb_val *prefixMap,
110 const struct ldb_val *schemaInfo)
113 const char *schema_info;
114 struct dsdb_schema_prefixmap *pfm;
117 /* verify schemaInfo blob is valid one */
118 if (!dsdb_schema_info_blob_is_valid(schemaInfo)) {
119 DEBUG(0,(__location__": dsdb_schema_info_blob_is_valid() failed.\n"));
120 return WERR_INVALID_PARAMETER;
123 mem_ctx = talloc_new(schema);
124 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
126 /* fetch prefixMap */
127 werr = _dsdb_prefixmap_from_ldb_val(prefixMap,
129 if (!W_ERROR_IS_OK(werr)) {
130 DEBUG(0, (__location__ " _dsdb_prefixmap_from_ldb_val failed: %s\n", win_errstr(werr)));
131 talloc_free(mem_ctx);
135 /* decode schema_info */
136 schema_info = hex_encode_talloc(mem_ctx,
140 talloc_free(mem_ctx);
144 /* store prefixMap and schema_info into cached Schema */
145 talloc_free(schema->prefixmap);
146 schema->prefixmap = talloc_steal(schema, pfm);
148 talloc_free(discard_const(schema->schema_info));
149 schema->schema_info = talloc_steal(schema, schema_info);
151 /* clean up locally allocated mem */
152 talloc_free(mem_ctx);
157 WERROR dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema *schema,
158 bool include_schema_info,
160 struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
162 return dsdb_drsuapi_pfm_from_schema_pfm(schema->prefixmap,
163 include_schema_info ? schema->schema_info : NULL,
167 WERROR dsdb_get_drsuapi_prefixmap_as_blob(const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr,
169 struct ldb_val *prefixMap)
171 struct prefixMapBlob pfm;
172 enum ndr_err_code ndr_err;
173 pfm.version = PREFIX_MAP_VERSION_DSDB;
177 ndr_err = ndr_push_struct_blob(prefixMap, mem_ctx, &pfm,
178 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
179 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
180 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
181 return ntstatus_to_werror(nt_status);
186 WERROR dsdb_get_oid_mappings_ldb(const struct dsdb_schema *schema,
188 struct ldb_val *prefixMap,
189 struct ldb_val *schemaInfo)
192 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
194 status = dsdb_get_oid_mappings_drsuapi(schema, false, mem_ctx, &ctr);
195 W_ERROR_NOT_OK_RETURN(status);
197 status = dsdb_get_drsuapi_prefixmap_as_blob(ctr, mem_ctx, prefixMap);
199 W_ERROR_NOT_OK_RETURN(status);
201 *schemaInfo = strhex_to_data_blob(mem_ctx, schema->schema_info);
202 W_ERROR_HAVE_NO_MEMORY(schemaInfo->data);
209 * this function is called from within a ldb transaction from the schema_fsmo module
211 WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
216 struct dsdb_schema_prefixmap *pfm;
218 mem_ctx = talloc_new(ldb);
219 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
221 /* Read prefixes from disk*/
222 status = dsdb_read_prefixes_from_ldb(ldb, mem_ctx, &pfm);
223 if (!W_ERROR_IS_OK(status)) {
224 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
225 win_errstr(status)));
226 talloc_free(mem_ctx);
230 /* Check if there is a prefix for the oid in the prefixes array*/
231 status = dsdb_schema_pfm_find_oid(pfm, full_oid, NULL);
232 if (W_ERROR_IS_OK(status)) {
234 talloc_free(mem_ctx);
236 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
238 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
239 win_errstr(status)));
240 talloc_free(mem_ctx);
244 /* Create the new mapping for the prefix of full_oid */
245 status = dsdb_schema_pfm_make_attid(pfm, full_oid, &attid);
246 if (!W_ERROR_IS_OK(status)) {
247 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_schema_pfm_make_attid: %s\n",
248 win_errstr(status)));
249 talloc_free(mem_ctx);
253 talloc_unlink(schema, schema->prefixmap);
254 schema->prefixmap = talloc_steal(schema, pfm);
256 /* Update prefixMap in ldb*/
257 status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
258 if (!W_ERROR_IS_OK(status)) {
259 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
260 win_errstr(status)));
261 talloc_free(mem_ctx);
265 DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
266 full_oid, schema->prefixmap->length));
268 talloc_free(mem_ctx);
273 WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
274 const struct dsdb_schema *schema)
278 struct ldb_message *msg;
279 struct ldb_dn *schema_dn;
280 struct prefixMapBlob pfm_blob;
281 struct ldb_val ndr_blob;
282 enum ndr_err_code ndr_err;
283 TALLOC_CTX *temp_ctx;
284 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
286 schema_dn = ldb_get_schema_basedn(ldb);
288 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
292 temp_ctx = talloc_new(mem_ctx);
293 W_ERROR_HAVE_NO_MEMORY(temp_ctx);
295 /* convert schema_prefixMap to prefixMap blob */
296 status = dsdb_get_oid_mappings_drsuapi(schema, false, temp_ctx, &ctr);
297 if (!W_ERROR_IS_OK(status)) {
298 talloc_free(temp_ctx);
302 pfm_blob.version = PREFIX_MAP_VERSION_DSDB;
303 pfm_blob.ctr.dsdb = *ctr;
305 ndr_err = ndr_push_struct_blob(&ndr_blob, temp_ctx,
307 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
308 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
309 talloc_free(temp_ctx);
313 /* write serialized prefixMap into LDB */
314 msg = ldb_msg_new(temp_ctx);
316 talloc_free(temp_ctx);
321 ldb_ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL);
323 talloc_free(temp_ctx);
324 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
328 ldb_ret = dsdb_replace(ldb, msg, DSDB_FLAG_AS_SYSTEM);
330 talloc_free(temp_ctx);
333 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: dsdb_replace failed\n"));
340 WERROR dsdb_read_prefixes_from_ldb(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap **_pfm)
344 const struct ldb_val *prefix_val;
345 struct ldb_dn *schema_dn;
346 struct ldb_result *schema_res = NULL;
347 static const char *schema_attrs[] = {
352 schema_dn = ldb_get_schema_basedn(ldb);
354 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
358 ldb_ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
359 if (ldb_ret == LDB_ERR_NO_SUCH_OBJECT) {
360 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
361 talloc_free(schema_res);
363 } else if (ldb_ret != LDB_SUCCESS) {
364 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
365 talloc_free(schema_res);
369 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
371 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
372 talloc_free(schema_res);
376 werr = _dsdb_prefixmap_from_ldb_val(prefix_val,
379 talloc_free(schema_res);
380 W_ERROR_NOT_OK_RETURN(werr);
386 this will be replaced with something that looks at the right part of
387 the schema once we know where unique indexing information is hidden
389 static bool dsdb_schema_unique_attribute(const char *attr)
391 const char *attrs[] = { "objectGUID", "objectSid" , NULL };
393 for (i=0;attrs[i];i++) {
394 if (strcasecmp(attr, attrs[i]) == 0) {
403 setup the ldb_schema_attribute field for a dsdb_attribute
405 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
406 struct dsdb_attribute *attr)
408 const char *syntax = attr->syntax->ldb_syntax;
409 const struct ldb_schema_syntax *s;
410 struct ldb_schema_attribute *a;
413 syntax = attr->syntax->ldap_oid;
416 s = ldb_samba_syntax_by_lDAPDisplayName(ldb, attr->lDAPDisplayName);
418 s = ldb_samba_syntax_by_name(ldb, syntax);
421 s = ldb_standard_syntax_by_name(ldb, syntax);
425 return ldb_operr(ldb);
428 attr->ldb_schema_attribute = a = talloc(attr, struct ldb_schema_attribute);
429 if (attr->ldb_schema_attribute == NULL) {
433 a->name = attr->lDAPDisplayName;
437 if (dsdb_schema_unique_attribute(a->name)) {
438 a->flags |= LDB_ATTR_FLAG_UNIQUE_INDEX;
440 if (attr->isSingleValued) {
441 a->flags |= LDB_ATTR_FLAG_SINGLE_VALUE;
449 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
450 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
451 if (get_string_val == NULL) { \
453 d_printf("%s: %s == NULL\n", __location__, attr); \
454 return WERR_INVALID_PARAM; \
459 (p)->elem = talloc_strndup(mem_ctx, \
460 (const char *)get_string_val->data, \
461 get_string_val->length); \
463 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
469 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem) do { \
470 int get_string_list_counter; \
471 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
472 /* We may get empty attributes over the replication channel */ \
473 if (get_string_list_el == NULL || get_string_list_el->num_values == 0) { \
477 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
478 for (get_string_list_counter=0; \
479 get_string_list_counter < get_string_list_el->num_values; \
480 get_string_list_counter++) { \
481 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
482 (const char *)get_string_list_el->values[get_string_list_counter].data, \
483 get_string_list_el->values[get_string_list_counter].length); \
484 if (!(p)->elem[get_string_list_counter]) { \
485 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
488 (p)->elem[get_string_list_counter+1] = NULL; \
490 talloc_steal(mem_ctx, (p)->elem); \
493 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
495 str = ldb_msg_find_attr_as_string(msg, attr, NULL);\
498 d_printf("%s: %s == NULL\n", __location__, attr); \
499 return WERR_INVALID_PARAM; \
503 } else if (strcasecmp("TRUE", str) == 0) { \
505 } else if (strcasecmp("FALSE", str) == 0) { \
508 d_printf("%s: %s == %s\n", __location__, attr, str); \
509 return WERR_INVALID_PARAM; \
513 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
514 (p)->elem = ldb_msg_find_attr_as_uint(msg, attr, 0);\
517 #define GET_UINT32_PTR_LDB(msg, attr, mem_ctx, p, elem) do { \
518 uint64_t _v = ldb_msg_find_attr_as_uint64(msg, attr, UINT64_MAX);\
519 if (_v == UINT64_MAX) { \
521 } else if (_v > UINT32_MAX) { \
522 d_printf("%s: %s == 0x%llX\n", __location__, \
523 attr, (unsigned long long)_v); \
524 return WERR_INVALID_PARAM; \
526 (p)->elem = talloc(mem_ctx, uint32_t); \
528 d_printf("%s: talloc failed for %s\n", __location__, attr); \
531 *(p)->elem = (uint32_t)_v; \
535 #define GET_GUID_LDB(msg, attr, p, elem) do { \
536 (p)->elem = samdb_result_guid(msg, attr);\
539 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
540 const struct ldb_val *_val;\
541 _val = ldb_msg_find_ldb_val(msg, attr);\
544 talloc_steal(mem_ctx, (p)->elem.data);\
546 ZERO_STRUCT((p)->elem);\
550 WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
551 struct dsdb_schema *schema,
552 struct ldb_message *msg)
555 struct dsdb_attribute *attr = talloc_zero(schema, struct dsdb_attribute);
560 GET_STRING_LDB(msg, "cn", attr, attr, cn, false);
561 GET_STRING_LDB(msg, "lDAPDisplayName", attr, attr, lDAPDisplayName, true);
562 GET_STRING_LDB(msg, "attributeID", attr, attr, attributeID_oid, true);
563 if (!schema->prefixmap || schema->prefixmap->length == 0) {
564 /* set an invalid value */
565 attr->attributeID_id = 0xFFFFFFFF;
567 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
568 attr->attributeID_oid,
569 &attr->attributeID_id);
570 if (!W_ERROR_IS_OK(status)) {
571 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
572 __location__, attr->lDAPDisplayName, attr->attributeID_oid,
573 win_errstr(status)));
577 /* fetch msDS-IntId to be used in resolving ATTRTYP values */
578 GET_UINT32_LDB(msg, "msDS-IntId", attr, msDS_IntId);
580 GET_GUID_LDB(msg, "schemaIDGUID", attr, schemaIDGUID);
581 GET_UINT32_LDB(msg, "mAPIID", attr, mAPIID);
583 GET_GUID_LDB(msg, "attributeSecurityGUID", attr, attributeSecurityGUID);
585 GET_GUID_LDB(msg, "objectGUID", attr, objectGUID);
587 GET_UINT32_LDB(msg, "searchFlags", attr, searchFlags);
588 GET_UINT32_LDB(msg, "systemFlags", attr, systemFlags);
589 GET_BOOL_LDB(msg, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
590 GET_UINT32_LDB(msg, "linkID", attr, linkID);
592 GET_STRING_LDB(msg, "attributeSyntax", attr, attr, attributeSyntax_oid, true);
593 if (!schema->prefixmap || schema->prefixmap->length == 0) {
594 /* set an invalid value */
595 attr->attributeSyntax_id = 0xFFFFFFFF;
597 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
598 attr->attributeSyntax_oid,
599 &attr->attributeSyntax_id);
600 if (!W_ERROR_IS_OK(status)) {
601 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
602 __location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
603 win_errstr(status)));
607 GET_UINT32_LDB(msg, "oMSyntax", attr, oMSyntax);
608 GET_BLOB_LDB(msg, "oMObjectClass", attr, attr, oMObjectClass);
610 GET_BOOL_LDB(msg, "isSingleValued", attr, isSingleValued, true);
611 GET_UINT32_PTR_LDB(msg, "rangeLower", attr, attr, rangeLower);
612 GET_UINT32_PTR_LDB(msg, "rangeUpper", attr, attr, rangeUpper);
613 GET_BOOL_LDB(msg, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
615 GET_UINT32_LDB(msg, "schemaFlagsEx", attr, schemaFlagsEx);
616 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", attr, attr, msDs_Schema_Extensions);
618 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
619 GET_STRING_LDB(msg, "adminDisplayName", attr, attr, adminDisplayName, false);
620 GET_STRING_LDB(msg, "adminDescription", attr, attr, adminDescription, false);
621 GET_STRING_LDB(msg, "classDisplayName", attr, attr, classDisplayName, false);
622 GET_BOOL_LDB(msg, "isEphemeral", attr, isEphemeral, false);
623 GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
624 GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
626 attr->syntax = dsdb_syntax_for_attribute(attr);
628 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
629 attr->lDAPDisplayName));
630 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
633 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
634 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
635 attr->lDAPDisplayName));
636 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
639 DLIST_ADD(schema->attributes, attr);
643 WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
644 struct ldb_message *msg)
647 struct dsdb_class *obj = talloc_zero(schema, struct dsdb_class);
651 GET_STRING_LDB(msg, "cn", obj, obj, cn, false);
652 GET_STRING_LDB(msg, "lDAPDisplayName", obj, obj, lDAPDisplayName, true);
653 GET_STRING_LDB(msg, "governsID", obj, obj, governsID_oid, true);
654 if (!schema->prefixmap || schema->prefixmap->length == 0) {
655 /* set an invalid value */
656 obj->governsID_id = 0xFFFFFFFF;
658 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
661 if (!W_ERROR_IS_OK(status)) {
662 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
663 __location__, obj->lDAPDisplayName, obj->governsID_oid,
664 win_errstr(status)));
668 GET_GUID_LDB(msg, "schemaIDGUID", obj, schemaIDGUID);
669 GET_GUID_LDB(msg, "objectGUID", obj, objectGUID);
671 GET_UINT32_LDB(msg, "objectClassCategory", obj, objectClassCategory);
672 GET_STRING_LDB(msg, "rDNAttID", obj, obj, rDNAttID, false);
673 GET_STRING_LDB(msg, "defaultObjectCategory", obj, obj, defaultObjectCategory, true);
675 GET_STRING_LDB(msg, "subClassOf", obj, obj, subClassOf, true);
677 GET_STRING_LIST_LDB(msg, "systemAuxiliaryClass", obj, obj, systemAuxiliaryClass);
678 GET_STRING_LIST_LDB(msg, "auxiliaryClass", obj, obj, auxiliaryClass);
680 GET_STRING_LIST_LDB(msg, "systemMustContain", obj, obj, systemMustContain);
681 GET_STRING_LIST_LDB(msg, "systemMayContain", obj, obj, systemMayContain);
682 GET_STRING_LIST_LDB(msg, "mustContain", obj, obj, mustContain);
683 GET_STRING_LIST_LDB(msg, "mayContain", obj, obj, mayContain);
685 GET_STRING_LIST_LDB(msg, "systemPossSuperiors", obj, obj, systemPossSuperiors);
686 GET_STRING_LIST_LDB(msg, "possSuperiors", obj, obj, possSuperiors);
688 GET_STRING_LDB(msg, "defaultSecurityDescriptor", obj, obj, defaultSecurityDescriptor, false);
690 GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
691 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", obj, obj, msDs_Schema_Extensions);
693 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
694 GET_STRING_LDB(msg, "adminDisplayName", obj, obj, adminDisplayName, false);
695 GET_STRING_LDB(msg, "adminDescription", obj, obj, adminDescription, false);
696 GET_STRING_LDB(msg, "classDisplayName", obj, obj, classDisplayName, false);
697 GET_BOOL_LDB(msg, "defaultHidingValue", obj, defaultHidingValue, false);
698 GET_BOOL_LDB(msg, "isDefunct", obj, isDefunct, false);
699 GET_BOOL_LDB(msg, "systemOnly", obj, systemOnly, false);
701 DLIST_ADD(schema->classes, obj);
705 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
708 Create a DSDB schema from the ldb results provided. This is called
709 directly when the schema is provisioned from an on-disk LDIF file, or
710 from dsdb_schema_from_schema_dn in schema_fsmo
713 int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
714 struct ldb_result *schema_res,
715 struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
716 struct dsdb_schema **schema_out,
721 const struct ldb_val *prefix_val;
722 const struct ldb_val *info_val;
723 struct ldb_val info_val_default;
724 struct dsdb_schema *schema;
726 schema = dsdb_new_schema(mem_ctx);
728 dsdb_oom(error_string, mem_ctx);
729 return ldb_operr(ldb);
732 schema->base_dn = talloc_steal(schema, schema_res->msgs[0]->dn);
734 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
736 *error_string = talloc_asprintf(mem_ctx,
737 "schema_fsmo_init: no prefixMap attribute found");
738 DEBUG(0,(__location__ ": %s\n", *error_string));
739 return LDB_ERR_CONSTRAINT_VIOLATION;
741 info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
743 status = dsdb_schema_info_blob_new(mem_ctx, &info_val_default);
744 if (!W_ERROR_IS_OK(status)) {
745 *error_string = talloc_asprintf(mem_ctx,
746 "schema_fsmo_init: dsdb_schema_info_blob_new() failed - %s",
748 DEBUG(0,(__location__ ": %s\n", *error_string));
749 return ldb_operr(ldb);
751 info_val = &info_val_default;
754 status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
755 if (!W_ERROR_IS_OK(status)) {
756 *error_string = talloc_asprintf(mem_ctx,
757 "schema_fsmo_init: failed to load oid mappings: %s",
759 DEBUG(0,(__location__ ": %s\n", *error_string));
760 return LDB_ERR_CONSTRAINT_VIOLATION;
763 for (i=0; i < attrs_res->count; i++) {
764 status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i]);
765 if (!W_ERROR_IS_OK(status)) {
766 *error_string = talloc_asprintf(mem_ctx,
767 "schema_fsmo_init: failed to load attribute definition: %s:%s",
768 ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
770 DEBUG(0,(__location__ ": %s\n", *error_string));
771 return LDB_ERR_CONSTRAINT_VIOLATION;
775 for (i=0; i < objectclass_res->count; i++) {
776 status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i]);
777 if (!W_ERROR_IS_OK(status)) {
778 *error_string = talloc_asprintf(mem_ctx,
779 "schema_fsmo_init: failed to load class definition: %s:%s",
780 ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
782 DEBUG(0,(__location__ ": %s\n", *error_string));
783 return LDB_ERR_CONSTRAINT_VIOLATION;
787 schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
788 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
789 schema->fsmo.we_are_master = true;
791 schema->fsmo.we_are_master = false;
794 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
795 (schema->fsmo.we_are_master?"yes":"no")));
797 *schema_out = schema;