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 talloc_free(temp_ctx);
84 DEBUG(0,("_dsdb_prefixmap_from_ldb_val: Failed to parse prefixmap of length %u: %s\n",
85 (unsigned int)pfm_ldb_val->length, ndr_map_error2string(ndr_err)));
86 talloc_free(temp_ctx);
87 return ntstatus_to_werror(nt_status);
90 if (pfm_blob.version != PREFIX_MAP_VERSION_DSDB) {
91 DEBUG(0,("_dsdb_prefixmap_from_ldb_val: pfm_blob->version %u incorrect\n", (unsigned int)pfm_blob.version));
92 talloc_free(temp_ctx);
93 return WERR_VERSION_PARSE_ERROR;
96 /* call the drsuapi version */
97 werr = dsdb_schema_pfm_from_drsuapi_pfm(&pfm_blob.ctr.dsdb, false, mem_ctx, _pfm, NULL);
98 if (!W_ERROR_IS_OK(werr)) {
99 DEBUG(0, (__location__ " dsdb_schema_pfm_from_drsuapi_pfm failed: %s\n", win_errstr(werr)));
100 talloc_free(temp_ctx);
104 talloc_free(temp_ctx);
109 WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
110 const struct ldb_val *prefixMap,
111 const struct ldb_val *schemaInfo)
114 const char *schema_info;
115 struct dsdb_schema_prefixmap *pfm;
116 struct dsdb_schema_info *schi;
119 mem_ctx = talloc_new(schema);
120 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
122 /* parse schemaInfo blob to verify it is valid */
123 werr = dsdb_schema_info_from_blob(schemaInfo, mem_ctx, &schi);
124 if (!W_ERROR_IS_OK(werr)) {
125 DEBUG(0, (__location__ " dsdb_schema_info_from_blob failed: %s\n", win_errstr(werr)));
126 talloc_free(mem_ctx);
130 /* fetch prefixMap */
131 werr = _dsdb_prefixmap_from_ldb_val(prefixMap,
133 if (!W_ERROR_IS_OK(werr)) {
134 DEBUG(0, (__location__ " _dsdb_prefixmap_from_ldb_val failed: %s\n", win_errstr(werr)));
135 talloc_free(mem_ctx);
139 /* decode schema_info */
140 schema_info = hex_encode_talloc(mem_ctx,
144 talloc_free(mem_ctx);
148 /* store prefixMap and schema_info into cached Schema */
149 talloc_free(schema->prefixmap);
150 schema->prefixmap = talloc_steal(schema, pfm);
152 talloc_free(discard_const(schema->schema_info));
153 schema->schema_info = talloc_steal(schema, schema_info);
155 /* clean up locally allocated mem */
156 talloc_free(mem_ctx);
161 WERROR dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema *schema,
162 bool include_schema_info,
164 struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
166 return dsdb_drsuapi_pfm_from_schema_pfm(schema->prefixmap,
167 include_schema_info ? schema->schema_info : NULL,
171 WERROR dsdb_get_drsuapi_prefixmap_as_blob(const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr,
173 struct ldb_val *prefixMap)
175 struct prefixMapBlob pfm;
176 enum ndr_err_code ndr_err;
177 pfm.version = PREFIX_MAP_VERSION_DSDB;
181 ndr_err = ndr_push_struct_blob(prefixMap, mem_ctx, &pfm,
182 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
183 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
184 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
185 return ntstatus_to_werror(nt_status);
190 WERROR dsdb_get_oid_mappings_ldb(const struct dsdb_schema *schema,
192 struct ldb_val *prefixMap,
193 struct ldb_val *schemaInfo)
196 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
198 status = dsdb_get_oid_mappings_drsuapi(schema, false, mem_ctx, &ctr);
199 W_ERROR_NOT_OK_RETURN(status);
201 status = dsdb_get_drsuapi_prefixmap_as_blob(ctr, mem_ctx, prefixMap);
203 W_ERROR_NOT_OK_RETURN(status);
205 *schemaInfo = strhex_to_data_blob(mem_ctx, schema->schema_info);
206 W_ERROR_HAVE_NO_MEMORY(schemaInfo->data);
213 * this function is called from within a ldb transaction from the schema_fsmo module
215 WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
220 struct dsdb_schema_prefixmap *pfm;
222 mem_ctx = talloc_new(ldb);
223 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
225 /* Read prefixes from disk*/
226 status = dsdb_read_prefixes_from_ldb(ldb, mem_ctx, &pfm);
227 if (!W_ERROR_IS_OK(status)) {
228 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
229 win_errstr(status)));
230 talloc_free(mem_ctx);
234 /* Check if there is a prefix for the oid in the prefixes array*/
235 status = dsdb_schema_pfm_find_oid(pfm, full_oid, NULL);
236 if (W_ERROR_IS_OK(status)) {
238 talloc_free(mem_ctx);
240 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
242 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
243 win_errstr(status)));
244 talloc_free(mem_ctx);
248 /* Create the new mapping for the prefix of full_oid */
249 status = dsdb_schema_pfm_make_attid(pfm, full_oid, &attid);
250 if (!W_ERROR_IS_OK(status)) {
251 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_schema_pfm_make_attid: %s\n",
252 win_errstr(status)));
253 talloc_free(mem_ctx);
257 talloc_unlink(schema, schema->prefixmap);
258 schema->prefixmap = talloc_steal(schema, pfm);
260 /* Update prefixMap in ldb*/
261 status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
262 if (!W_ERROR_IS_OK(status)) {
263 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
264 win_errstr(status)));
265 talloc_free(mem_ctx);
269 DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
270 full_oid, schema->prefixmap->length));
272 talloc_free(mem_ctx);
277 WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
278 const struct dsdb_schema *schema)
282 struct ldb_message *msg;
283 struct ldb_dn *schema_dn;
284 struct prefixMapBlob pfm_blob;
285 struct ldb_val ndr_blob;
286 enum ndr_err_code ndr_err;
287 TALLOC_CTX *temp_ctx;
288 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
290 schema_dn = ldb_get_schema_basedn(ldb);
292 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
296 temp_ctx = talloc_new(mem_ctx);
297 W_ERROR_HAVE_NO_MEMORY(temp_ctx);
299 /* convert schema_prefixMap to prefixMap blob */
300 status = dsdb_get_oid_mappings_drsuapi(schema, false, temp_ctx, &ctr);
301 if (!W_ERROR_IS_OK(status)) {
302 talloc_free(temp_ctx);
306 pfm_blob.version = PREFIX_MAP_VERSION_DSDB;
307 pfm_blob.ctr.dsdb = *ctr;
309 ndr_err = ndr_push_struct_blob(&ndr_blob, temp_ctx,
311 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
312 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
313 talloc_free(temp_ctx);
317 /* write serialized prefixMap into LDB */
318 msg = ldb_msg_new(temp_ctx);
320 talloc_free(temp_ctx);
325 ldb_ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL);
327 talloc_free(temp_ctx);
328 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
332 ldb_ret = dsdb_replace(ldb, msg, DSDB_FLAG_AS_SYSTEM);
334 talloc_free(temp_ctx);
337 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: dsdb_replace failed\n"));
344 WERROR dsdb_read_prefixes_from_ldb(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap **_pfm)
348 const struct ldb_val *prefix_val;
349 struct ldb_dn *schema_dn;
350 struct ldb_result *schema_res = NULL;
351 static const char *schema_attrs[] = {
356 schema_dn = ldb_get_schema_basedn(ldb);
358 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
362 ldb_ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
363 if (ldb_ret == LDB_ERR_NO_SUCH_OBJECT) {
364 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
365 talloc_free(schema_res);
367 } else if (ldb_ret != LDB_SUCCESS) {
368 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
369 talloc_free(schema_res);
373 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
375 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
376 talloc_free(schema_res);
380 werr = _dsdb_prefixmap_from_ldb_val(prefix_val,
383 talloc_free(schema_res);
384 W_ERROR_NOT_OK_RETURN(werr);
390 this will be replaced with something that looks at the right part of
391 the schema once we know where unique indexing information is hidden
393 static bool dsdb_schema_unique_attribute(const char *attr)
395 const char *attrs[] = { "objectGUID", "objectSID" , NULL };
397 for (i=0;attrs[i];i++) {
398 if (strcasecmp(attr, attrs[i]) == 0) {
407 setup the ldb_schema_attribute field for a dsdb_attribute
409 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
410 struct dsdb_attribute *attr)
412 const char *syntax = attr->syntax->ldb_syntax;
413 const struct ldb_schema_syntax *s;
414 struct ldb_schema_attribute *a;
417 syntax = attr->syntax->ldap_oid;
420 s = ldb_samba_syntax_by_lDAPDisplayName(ldb, attr->lDAPDisplayName);
422 s = ldb_samba_syntax_by_name(ldb, syntax);
425 s = ldb_standard_syntax_by_name(ldb, syntax);
429 return LDB_ERR_OPERATIONS_ERROR;
432 attr->ldb_schema_attribute = a = talloc(attr, struct ldb_schema_attribute);
433 if (attr->ldb_schema_attribute == NULL) {
435 return LDB_ERR_OPERATIONS_ERROR;
438 a->name = attr->lDAPDisplayName;
442 if (dsdb_schema_unique_attribute(a->name)) {
443 a->flags |= LDB_ATTR_FLAG_UNIQUE_INDEX;
445 if (attr->isSingleValued) {
446 a->flags |= LDB_ATTR_FLAG_SINGLE_VALUE;
454 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
455 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
456 if (get_string_val == NULL) { \
458 d_printf("%s: %s == NULL\n", __location__, attr); \
459 return WERR_INVALID_PARAM; \
464 (p)->elem = talloc_strndup(mem_ctx, \
465 (const char *)get_string_val->data, \
466 get_string_val->length); \
468 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
474 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem) do { \
475 int get_string_list_counter; \
476 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
477 /* We may get empty attributes over the replication channel */ \
478 if (get_string_list_el == NULL || get_string_list_el->num_values == 0) { \
482 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
483 for (get_string_list_counter=0; \
484 get_string_list_counter < get_string_list_el->num_values; \
485 get_string_list_counter++) { \
486 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
487 (const char *)get_string_list_el->values[get_string_list_counter].data, \
488 get_string_list_el->values[get_string_list_counter].length); \
489 if (!(p)->elem[get_string_list_counter]) { \
490 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
493 (p)->elem[get_string_list_counter+1] = NULL; \
495 talloc_steal(mem_ctx, (p)->elem); \
498 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
500 str = samdb_result_string(msg, attr, NULL);\
503 d_printf("%s: %s == NULL\n", __location__, attr); \
504 return WERR_INVALID_PARAM; \
508 } else if (strcasecmp("TRUE", str) == 0) { \
510 } else if (strcasecmp("FALSE", str) == 0) { \
513 d_printf("%s: %s == %s\n", __location__, attr, str); \
514 return WERR_INVALID_PARAM; \
518 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
519 (p)->elem = samdb_result_uint(msg, attr, 0);\
522 #define GET_UINT32_PTR_LDB(msg, attr, mem_ctx, p, elem) do { \
523 uint64_t _v = samdb_result_uint64(msg, attr, UINT64_MAX);\
524 if (_v == UINT64_MAX) { \
526 } else if (_v > UINT32_MAX) { \
527 d_printf("%s: %s == 0x%llX\n", __location__, \
528 attr, (unsigned long long)_v); \
529 return WERR_INVALID_PARAM; \
531 (p)->elem = talloc(mem_ctx, uint32_t); \
533 d_printf("%s: talloc failed for %s\n", __location__, attr); \
536 *(p)->elem = (uint32_t)_v; \
540 #define GET_GUID_LDB(msg, attr, p, elem) do { \
541 (p)->elem = samdb_result_guid(msg, attr);\
544 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
545 const struct ldb_val *_val;\
546 _val = ldb_msg_find_ldb_val(msg, attr);\
549 talloc_steal(mem_ctx, (p)->elem.data);\
551 ZERO_STRUCT((p)->elem);\
555 WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
556 struct dsdb_schema *schema,
557 struct ldb_message *msg)
560 struct dsdb_attribute *attr = talloc_zero(schema, struct dsdb_attribute);
565 GET_STRING_LDB(msg, "cn", attr, attr, cn, false);
566 GET_STRING_LDB(msg, "lDAPDisplayName", attr, attr, lDAPDisplayName, true);
567 GET_STRING_LDB(msg, "attributeID", attr, attr, attributeID_oid, true);
568 if (!schema->prefixmap || schema->prefixmap->length == 0) {
569 /* set an invalid value */
570 attr->attributeID_id = 0xFFFFFFFF;
572 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
573 attr->attributeID_oid,
574 &attr->attributeID_id);
575 if (!W_ERROR_IS_OK(status)) {
576 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
577 __location__, attr->lDAPDisplayName, attr->attributeID_oid,
578 win_errstr(status)));
582 /* fetch msDS-IntId to be used in resolving ATTRTYP values */
583 GET_UINT32_LDB(msg, "msDS-IntId", attr, msDS_IntId);
585 GET_GUID_LDB(msg, "schemaIDGUID", attr, schemaIDGUID);
586 GET_UINT32_LDB(msg, "mAPIID", attr, mAPIID);
588 GET_GUID_LDB(msg, "attributeSecurityGUID", attr, attributeSecurityGUID);
590 GET_GUID_LDB(msg, "objectGUID", attr, objectGUID);
592 GET_UINT32_LDB(msg, "searchFlags", attr, searchFlags);
593 GET_UINT32_LDB(msg, "systemFlags", attr, systemFlags);
594 GET_BOOL_LDB(msg, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
595 GET_UINT32_LDB(msg, "linkID", attr, linkID);
597 GET_STRING_LDB(msg, "attributeSyntax", attr, attr, attributeSyntax_oid, true);
598 if (!schema->prefixmap || schema->prefixmap->length == 0) {
599 /* set an invalid value */
600 attr->attributeSyntax_id = 0xFFFFFFFF;
602 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
603 attr->attributeSyntax_oid,
604 &attr->attributeSyntax_id);
605 if (!W_ERROR_IS_OK(status)) {
606 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
607 __location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
608 win_errstr(status)));
612 GET_UINT32_LDB(msg, "oMSyntax", attr, oMSyntax);
613 GET_BLOB_LDB(msg, "oMObjectClass", attr, attr, oMObjectClass);
615 GET_BOOL_LDB(msg, "isSingleValued", attr, isSingleValued, true);
616 GET_UINT32_PTR_LDB(msg, "rangeLower", attr, attr, rangeLower);
617 GET_UINT32_PTR_LDB(msg, "rangeUpper", attr, attr, rangeUpper);
618 GET_BOOL_LDB(msg, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
620 GET_UINT32_LDB(msg, "schemaFlagsEx", attr, schemaFlagsEx);
621 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", attr, attr, msDs_Schema_Extensions);
623 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
624 GET_STRING_LDB(msg, "adminDisplayName", attr, attr, adminDisplayName, false);
625 GET_STRING_LDB(msg, "adminDescription", attr, attr, adminDescription, false);
626 GET_STRING_LDB(msg, "classDisplayName", attr, attr, classDisplayName, false);
627 GET_BOOL_LDB(msg, "isEphemeral", attr, isEphemeral, false);
628 GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
629 GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
631 attr->syntax = dsdb_syntax_for_attribute(attr);
633 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
634 attr->lDAPDisplayName));
635 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
638 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
639 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
640 attr->lDAPDisplayName));
641 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
644 DLIST_ADD(schema->attributes, attr);
648 WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
649 struct ldb_message *msg)
652 struct dsdb_class *obj = talloc_zero(schema, struct dsdb_class);
656 GET_STRING_LDB(msg, "cn", obj, obj, cn, false);
657 GET_STRING_LDB(msg, "lDAPDisplayName", obj, obj, lDAPDisplayName, true);
658 GET_STRING_LDB(msg, "governsID", obj, obj, governsID_oid, true);
659 if (!schema->prefixmap || schema->prefixmap->length == 0) {
660 /* set an invalid value */
661 obj->governsID_id = 0xFFFFFFFF;
663 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
666 if (!W_ERROR_IS_OK(status)) {
667 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
668 __location__, obj->lDAPDisplayName, obj->governsID_oid,
669 win_errstr(status)));
673 GET_GUID_LDB(msg, "schemaIDGUID", obj, schemaIDGUID);
674 GET_GUID_LDB(msg, "objectGUID", obj, objectGUID);
676 GET_UINT32_LDB(msg, "objectClassCategory", obj, objectClassCategory);
677 GET_STRING_LDB(msg, "rDNAttID", obj, obj, rDNAttID, false);
678 GET_STRING_LDB(msg, "defaultObjectCategory", obj, obj, defaultObjectCategory, true);
680 GET_STRING_LDB(msg, "subClassOf", obj, obj, subClassOf, true);
682 GET_STRING_LIST_LDB(msg, "systemAuxiliaryClass", obj, obj, systemAuxiliaryClass);
683 GET_STRING_LIST_LDB(msg, "auxiliaryClass", obj, obj, auxiliaryClass);
685 GET_STRING_LIST_LDB(msg, "systemMustContain", obj, obj, systemMustContain);
686 GET_STRING_LIST_LDB(msg, "systemMayContain", obj, obj, systemMayContain);
687 GET_STRING_LIST_LDB(msg, "mustContain", obj, obj, mustContain);
688 GET_STRING_LIST_LDB(msg, "mayContain", obj, obj, mayContain);
690 GET_STRING_LIST_LDB(msg, "systemPossSuperiors", obj, obj, systemPossSuperiors);
691 GET_STRING_LIST_LDB(msg, "possSuperiors", obj, obj, possSuperiors);
693 GET_STRING_LDB(msg, "defaultSecurityDescriptor", obj, obj, defaultSecurityDescriptor, false);
695 GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
696 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", obj, obj, msDs_Schema_Extensions);
698 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
699 GET_STRING_LDB(msg, "adminDisplayName", obj, obj, adminDisplayName, false);
700 GET_STRING_LDB(msg, "adminDescription", obj, obj, adminDescription, false);
701 GET_STRING_LDB(msg, "classDisplayName", obj, obj, classDisplayName, false);
702 GET_BOOL_LDB(msg, "defaultHidingValue", obj, defaultHidingValue, false);
703 GET_BOOL_LDB(msg, "isDefunct", obj, isDefunct, false);
704 GET_BOOL_LDB(msg, "systemOnly", obj, systemOnly, false);
706 DLIST_ADD(schema->classes, obj);
710 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
713 Create a DSDB schema from the ldb results provided. This is called
714 directly when the schema is provisioned from an on-disk LDIF file, or
715 from dsdb_schema_from_schema_dn in schema_fsmo
718 int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
719 struct ldb_result *schema_res,
720 struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
721 struct dsdb_schema **schema_out,
726 const struct ldb_val *prefix_val;
727 const struct ldb_val *info_val;
728 struct ldb_val info_val_default;
729 struct dsdb_schema *schema;
731 schema = dsdb_new_schema(mem_ctx);
733 dsdb_oom(error_string, mem_ctx);
734 return LDB_ERR_OPERATIONS_ERROR;
737 schema->base_dn = talloc_steal(schema, schema_res->msgs[0]->dn);
739 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
741 *error_string = talloc_asprintf(mem_ctx,
742 "schema_fsmo_init: no prefixMap attribute found");
743 DEBUG(0,(__location__ ": %s\n", *error_string));
744 return LDB_ERR_CONSTRAINT_VIOLATION;
746 info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
748 status = dsdb_schema_info_blob_new(mem_ctx, &info_val_default);
749 if (!W_ERROR_IS_OK(status)) {
750 *error_string = talloc_asprintf(mem_ctx,
751 "schema_fsmo_init: dsdb_schema_info_blob_new() failed - %s",
753 DEBUG(0,(__location__ ": %s\n", *error_string));
754 return LDB_ERR_OPERATIONS_ERROR;
756 info_val = &info_val_default;
759 status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
760 if (!W_ERROR_IS_OK(status)) {
761 *error_string = talloc_asprintf(mem_ctx,
762 "schema_fsmo_init: failed to load oid mappings: %s",
764 DEBUG(0,(__location__ ": %s\n", *error_string));
765 return LDB_ERR_CONSTRAINT_VIOLATION;
768 for (i=0; i < attrs_res->count; i++) {
769 status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i]);
770 if (!W_ERROR_IS_OK(status)) {
771 *error_string = talloc_asprintf(mem_ctx,
772 "schema_fsmo_init: failed to load attribute definition: %s:%s",
773 ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
775 DEBUG(0,(__location__ ": %s\n", *error_string));
776 return LDB_ERR_CONSTRAINT_VIOLATION;
780 for (i=0; i < objectclass_res->count; i++) {
781 status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i]);
782 if (!W_ERROR_IS_OK(status)) {
783 *error_string = talloc_asprintf(mem_ctx,
784 "schema_fsmo_init: failed to load class definition: %s:%s",
785 ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
787 DEBUG(0,(__location__ ": %s\n", *error_string));
788 return LDB_ERR_CONSTRAINT_VIOLATION;
792 schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
793 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
794 schema->fsmo.we_are_master = true;
796 schema->fsmo.we_are_master = false;
799 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
800 (schema->fsmo.we_are_master?"yes":"no")));
802 *schema_out = schema;