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;
118 /* verify schemaInfo blob is valid one */
119 if (!dsdb_schema_info_blob_is_valid(schemaInfo)) {
120 DEBUG(0,(__location__": dsdb_schema_info_blob_is_valid() failed.\n"));
121 return WERR_INVALID_PARAMETER;
124 mem_ctx = talloc_new(schema);
125 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
127 /* fetch prefixMap */
128 werr = _dsdb_prefixmap_from_ldb_val(prefixMap,
130 if (!W_ERROR_IS_OK(werr)) {
131 DEBUG(0, (__location__ " _dsdb_prefixmap_from_ldb_val failed: %s\n", win_errstr(werr)));
132 talloc_free(mem_ctx);
136 /* decode schema_info */
137 schema_info = hex_encode_talloc(mem_ctx,
141 talloc_free(mem_ctx);
145 /* store prefixMap and schema_info into cached Schema */
146 talloc_free(schema->prefixmap);
147 schema->prefixmap = talloc_steal(schema, pfm);
149 talloc_free(discard_const(schema->schema_info));
150 schema->schema_info = talloc_steal(schema, schema_info);
152 /* clean up locally allocated mem */
153 talloc_free(mem_ctx);
158 WERROR dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema *schema,
159 bool include_schema_info,
161 struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
163 return dsdb_drsuapi_pfm_from_schema_pfm(schema->prefixmap,
164 include_schema_info ? schema->schema_info : NULL,
168 WERROR dsdb_get_drsuapi_prefixmap_as_blob(const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr,
170 struct ldb_val *prefixMap)
172 struct prefixMapBlob pfm;
173 enum ndr_err_code ndr_err;
174 pfm.version = PREFIX_MAP_VERSION_DSDB;
178 ndr_err = ndr_push_struct_blob(prefixMap, mem_ctx, &pfm,
179 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
180 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
181 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
182 return ntstatus_to_werror(nt_status);
187 WERROR dsdb_get_oid_mappings_ldb(const struct dsdb_schema *schema,
189 struct ldb_val *prefixMap,
190 struct ldb_val *schemaInfo)
193 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
195 status = dsdb_get_oid_mappings_drsuapi(schema, false, mem_ctx, &ctr);
196 W_ERROR_NOT_OK_RETURN(status);
198 status = dsdb_get_drsuapi_prefixmap_as_blob(ctr, mem_ctx, prefixMap);
200 W_ERROR_NOT_OK_RETURN(status);
202 *schemaInfo = strhex_to_data_blob(mem_ctx, schema->schema_info);
203 W_ERROR_HAVE_NO_MEMORY(schemaInfo->data);
210 * this function is called from within a ldb transaction from the schema_fsmo module
212 WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
217 struct dsdb_schema_prefixmap *pfm;
219 mem_ctx = talloc_new(ldb);
220 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
222 /* Read prefixes from disk*/
223 status = dsdb_read_prefixes_from_ldb(ldb, mem_ctx, &pfm);
224 if (!W_ERROR_IS_OK(status)) {
225 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
226 win_errstr(status)));
227 talloc_free(mem_ctx);
231 /* Check if there is a prefix for the oid in the prefixes array*/
232 status = dsdb_schema_pfm_find_oid(pfm, full_oid, NULL);
233 if (W_ERROR_IS_OK(status)) {
235 talloc_free(mem_ctx);
237 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
239 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
240 win_errstr(status)));
241 talloc_free(mem_ctx);
245 /* Create the new mapping for the prefix of full_oid */
246 status = dsdb_schema_pfm_make_attid(pfm, full_oid, &attid);
247 if (!W_ERROR_IS_OK(status)) {
248 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_schema_pfm_make_attid: %s\n",
249 win_errstr(status)));
250 talloc_free(mem_ctx);
254 talloc_unlink(schema, schema->prefixmap);
255 schema->prefixmap = talloc_steal(schema, pfm);
257 /* Update prefixMap in ldb*/
258 status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
259 if (!W_ERROR_IS_OK(status)) {
260 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
261 win_errstr(status)));
262 talloc_free(mem_ctx);
266 DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
267 full_oid, schema->prefixmap->length));
269 talloc_free(mem_ctx);
274 WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
275 const struct dsdb_schema *schema)
279 struct ldb_message *msg;
280 struct ldb_dn *schema_dn;
281 struct prefixMapBlob pfm_blob;
282 struct ldb_val ndr_blob;
283 enum ndr_err_code ndr_err;
284 TALLOC_CTX *temp_ctx;
285 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
287 schema_dn = ldb_get_schema_basedn(ldb);
289 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
293 temp_ctx = talloc_new(mem_ctx);
294 W_ERROR_HAVE_NO_MEMORY(temp_ctx);
296 /* convert schema_prefixMap to prefixMap blob */
297 status = dsdb_get_oid_mappings_drsuapi(schema, false, temp_ctx, &ctr);
298 if (!W_ERROR_IS_OK(status)) {
299 talloc_free(temp_ctx);
303 pfm_blob.version = PREFIX_MAP_VERSION_DSDB;
304 pfm_blob.ctr.dsdb = *ctr;
306 ndr_err = ndr_push_struct_blob(&ndr_blob, temp_ctx,
308 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
309 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
310 talloc_free(temp_ctx);
314 /* write serialized prefixMap into LDB */
315 msg = ldb_msg_new(temp_ctx);
317 talloc_free(temp_ctx);
322 ldb_ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL);
324 talloc_free(temp_ctx);
325 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
329 ldb_ret = dsdb_replace(ldb, msg, DSDB_FLAG_AS_SYSTEM);
331 talloc_free(temp_ctx);
334 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: dsdb_replace failed\n"));
341 WERROR dsdb_read_prefixes_from_ldb(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap **_pfm)
345 const struct ldb_val *prefix_val;
346 struct ldb_dn *schema_dn;
347 struct ldb_result *schema_res = NULL;
348 static const char *schema_attrs[] = {
353 schema_dn = ldb_get_schema_basedn(ldb);
355 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
359 ldb_ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
360 if (ldb_ret == LDB_ERR_NO_SUCH_OBJECT) {
361 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
362 talloc_free(schema_res);
364 } else if (ldb_ret != LDB_SUCCESS) {
365 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
366 talloc_free(schema_res);
370 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
372 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
373 talloc_free(schema_res);
377 werr = _dsdb_prefixmap_from_ldb_val(prefix_val,
380 talloc_free(schema_res);
381 W_ERROR_NOT_OK_RETURN(werr);
387 this will be replaced with something that looks at the right part of
388 the schema once we know where unique indexing information is hidden
390 static bool dsdb_schema_unique_attribute(const char *attr)
392 const char *attrs[] = { "objectGUID", "objectSid" , NULL };
394 for (i=0;attrs[i];i++) {
395 if (strcasecmp(attr, attrs[i]) == 0) {
404 setup the ldb_schema_attribute field for a dsdb_attribute
406 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
407 struct dsdb_attribute *attr)
409 const char *syntax = attr->syntax->ldb_syntax;
410 const struct ldb_schema_syntax *s;
411 struct ldb_schema_attribute *a;
414 syntax = attr->syntax->ldap_oid;
417 s = ldb_samba_syntax_by_lDAPDisplayName(ldb, attr->lDAPDisplayName);
419 s = ldb_samba_syntax_by_name(ldb, syntax);
422 s = ldb_standard_syntax_by_name(ldb, syntax);
426 return ldb_operr(ldb);
429 attr->ldb_schema_attribute = a = talloc(attr, struct ldb_schema_attribute);
430 if (attr->ldb_schema_attribute == NULL) {
434 a->name = attr->lDAPDisplayName;
438 if (dsdb_schema_unique_attribute(a->name)) {
439 a->flags |= LDB_ATTR_FLAG_UNIQUE_INDEX;
441 if (attr->isSingleValued) {
442 a->flags |= LDB_ATTR_FLAG_SINGLE_VALUE;
450 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
451 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
452 if (get_string_val == NULL) { \
454 d_printf("%s: %s == NULL\n", __location__, attr); \
455 return WERR_INVALID_PARAM; \
460 (p)->elem = talloc_strndup(mem_ctx, \
461 (const char *)get_string_val->data, \
462 get_string_val->length); \
464 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
470 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem) do { \
471 int get_string_list_counter; \
472 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
473 /* We may get empty attributes over the replication channel */ \
474 if (get_string_list_el == NULL || get_string_list_el->num_values == 0) { \
478 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
479 for (get_string_list_counter=0; \
480 get_string_list_counter < get_string_list_el->num_values; \
481 get_string_list_counter++) { \
482 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
483 (const char *)get_string_list_el->values[get_string_list_counter].data, \
484 get_string_list_el->values[get_string_list_counter].length); \
485 if (!(p)->elem[get_string_list_counter]) { \
486 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
489 (p)->elem[get_string_list_counter+1] = NULL; \
491 talloc_steal(mem_ctx, (p)->elem); \
494 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
496 str = ldb_msg_find_attr_as_string(msg, attr, NULL);\
499 d_printf("%s: %s == NULL\n", __location__, attr); \
500 return WERR_INVALID_PARAM; \
504 } else if (strcasecmp("TRUE", str) == 0) { \
506 } else if (strcasecmp("FALSE", str) == 0) { \
509 d_printf("%s: %s == %s\n", __location__, attr, str); \
510 return WERR_INVALID_PARAM; \
514 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
515 (p)->elem = ldb_msg_find_attr_as_uint(msg, attr, 0);\
518 #define GET_UINT32_PTR_LDB(msg, attr, mem_ctx, p, elem) do { \
519 uint64_t _v = ldb_msg_find_attr_as_uint64(msg, attr, UINT64_MAX);\
520 if (_v == UINT64_MAX) { \
522 } else if (_v > UINT32_MAX) { \
523 d_printf("%s: %s == 0x%llX\n", __location__, \
524 attr, (unsigned long long)_v); \
525 return WERR_INVALID_PARAM; \
527 (p)->elem = talloc(mem_ctx, uint32_t); \
529 d_printf("%s: talloc failed for %s\n", __location__, attr); \
532 *(p)->elem = (uint32_t)_v; \
536 #define GET_GUID_LDB(msg, attr, p, elem) do { \
537 (p)->elem = samdb_result_guid(msg, attr);\
540 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
541 const struct ldb_val *_val;\
542 _val = ldb_msg_find_ldb_val(msg, attr);\
545 talloc_steal(mem_ctx, (p)->elem.data);\
547 ZERO_STRUCT((p)->elem);\
551 WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
552 struct dsdb_schema *schema,
553 struct ldb_message *msg)
556 struct dsdb_attribute *attr = talloc_zero(schema, struct dsdb_attribute);
561 GET_STRING_LDB(msg, "cn", attr, attr, cn, false);
562 GET_STRING_LDB(msg, "lDAPDisplayName", attr, attr, lDAPDisplayName, true);
563 GET_STRING_LDB(msg, "attributeID", attr, attr, attributeID_oid, true);
564 if (!schema->prefixmap || schema->prefixmap->length == 0) {
565 /* set an invalid value */
566 attr->attributeID_id = 0xFFFFFFFF;
568 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
569 attr->attributeID_oid,
570 &attr->attributeID_id);
571 if (!W_ERROR_IS_OK(status)) {
572 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
573 __location__, attr->lDAPDisplayName, attr->attributeID_oid,
574 win_errstr(status)));
578 /* fetch msDS-IntId to be used in resolving ATTRTYP values */
579 GET_UINT32_LDB(msg, "msDS-IntId", attr, msDS_IntId);
581 GET_GUID_LDB(msg, "schemaIDGUID", attr, schemaIDGUID);
582 GET_UINT32_LDB(msg, "mAPIID", attr, mAPIID);
584 GET_GUID_LDB(msg, "attributeSecurityGUID", attr, attributeSecurityGUID);
586 GET_GUID_LDB(msg, "objectGUID", attr, objectGUID);
588 GET_UINT32_LDB(msg, "searchFlags", attr, searchFlags);
589 GET_UINT32_LDB(msg, "systemFlags", attr, systemFlags);
590 GET_BOOL_LDB(msg, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
591 GET_UINT32_LDB(msg, "linkID", attr, linkID);
593 GET_STRING_LDB(msg, "attributeSyntax", attr, attr, attributeSyntax_oid, true);
594 if (!schema->prefixmap || schema->prefixmap->length == 0) {
595 /* set an invalid value */
596 attr->attributeSyntax_id = 0xFFFFFFFF;
598 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
599 attr->attributeSyntax_oid,
600 &attr->attributeSyntax_id);
601 if (!W_ERROR_IS_OK(status)) {
602 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
603 __location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
604 win_errstr(status)));
608 GET_UINT32_LDB(msg, "oMSyntax", attr, oMSyntax);
609 GET_BLOB_LDB(msg, "oMObjectClass", attr, attr, oMObjectClass);
611 GET_BOOL_LDB(msg, "isSingleValued", attr, isSingleValued, true);
612 GET_UINT32_PTR_LDB(msg, "rangeLower", attr, attr, rangeLower);
613 GET_UINT32_PTR_LDB(msg, "rangeUpper", attr, attr, rangeUpper);
614 GET_BOOL_LDB(msg, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
616 GET_UINT32_LDB(msg, "schemaFlagsEx", attr, schemaFlagsEx);
617 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", attr, attr, msDs_Schema_Extensions);
619 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
620 GET_STRING_LDB(msg, "adminDisplayName", attr, attr, adminDisplayName, false);
621 GET_STRING_LDB(msg, "adminDescription", attr, attr, adminDescription, false);
622 GET_STRING_LDB(msg, "classDisplayName", attr, attr, classDisplayName, false);
623 GET_BOOL_LDB(msg, "isEphemeral", attr, isEphemeral, false);
624 GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
625 GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
627 attr->syntax = dsdb_syntax_for_attribute(attr);
629 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
630 attr->lDAPDisplayName));
631 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
634 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
635 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
636 attr->lDAPDisplayName));
637 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
640 DLIST_ADD(schema->attributes, attr);
644 WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
645 struct ldb_message *msg)
648 struct dsdb_class *obj = talloc_zero(schema, struct dsdb_class);
652 GET_STRING_LDB(msg, "cn", obj, obj, cn, false);
653 GET_STRING_LDB(msg, "lDAPDisplayName", obj, obj, lDAPDisplayName, true);
654 GET_STRING_LDB(msg, "governsID", obj, obj, governsID_oid, true);
655 if (!schema->prefixmap || schema->prefixmap->length == 0) {
656 /* set an invalid value */
657 obj->governsID_id = 0xFFFFFFFF;
659 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
662 if (!W_ERROR_IS_OK(status)) {
663 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
664 __location__, obj->lDAPDisplayName, obj->governsID_oid,
665 win_errstr(status)));
669 GET_GUID_LDB(msg, "schemaIDGUID", obj, schemaIDGUID);
670 GET_GUID_LDB(msg, "objectGUID", obj, objectGUID);
672 GET_UINT32_LDB(msg, "objectClassCategory", obj, objectClassCategory);
673 GET_STRING_LDB(msg, "rDNAttID", obj, obj, rDNAttID, false);
674 GET_STRING_LDB(msg, "defaultObjectCategory", obj, obj, defaultObjectCategory, true);
676 GET_STRING_LDB(msg, "subClassOf", obj, obj, subClassOf, true);
678 GET_STRING_LIST_LDB(msg, "systemAuxiliaryClass", obj, obj, systemAuxiliaryClass);
679 GET_STRING_LIST_LDB(msg, "auxiliaryClass", obj, obj, auxiliaryClass);
681 GET_STRING_LIST_LDB(msg, "systemMustContain", obj, obj, systemMustContain);
682 GET_STRING_LIST_LDB(msg, "systemMayContain", obj, obj, systemMayContain);
683 GET_STRING_LIST_LDB(msg, "mustContain", obj, obj, mustContain);
684 GET_STRING_LIST_LDB(msg, "mayContain", obj, obj, mayContain);
686 GET_STRING_LIST_LDB(msg, "systemPossSuperiors", obj, obj, systemPossSuperiors);
687 GET_STRING_LIST_LDB(msg, "possSuperiors", obj, obj, possSuperiors);
689 GET_STRING_LDB(msg, "defaultSecurityDescriptor", obj, obj, defaultSecurityDescriptor, false);
691 GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
692 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", obj, obj, msDs_Schema_Extensions);
694 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
695 GET_STRING_LDB(msg, "adminDisplayName", obj, obj, adminDisplayName, false);
696 GET_STRING_LDB(msg, "adminDescription", obj, obj, adminDescription, false);
697 GET_STRING_LDB(msg, "classDisplayName", obj, obj, classDisplayName, false);
698 GET_BOOL_LDB(msg, "defaultHidingValue", obj, defaultHidingValue, false);
699 GET_BOOL_LDB(msg, "isDefunct", obj, isDefunct, false);
700 GET_BOOL_LDB(msg, "systemOnly", obj, systemOnly, false);
702 DLIST_ADD(schema->classes, obj);
706 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
709 Create a DSDB schema from the ldb results provided. This is called
710 directly when the schema is provisioned from an on-disk LDIF file, or
711 from dsdb_schema_from_schema_dn in schema_fsmo
714 int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
715 struct ldb_result *schema_res,
716 struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
717 struct dsdb_schema **schema_out,
722 const struct ldb_val *prefix_val;
723 const struct ldb_val *info_val;
724 struct ldb_val info_val_default;
725 struct dsdb_schema *schema;
727 schema = dsdb_new_schema(mem_ctx);
729 dsdb_oom(error_string, mem_ctx);
730 return ldb_operr(ldb);
733 schema->base_dn = talloc_steal(schema, schema_res->msgs[0]->dn);
735 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
737 *error_string = talloc_asprintf(mem_ctx,
738 "schema_fsmo_init: no prefixMap attribute found");
739 DEBUG(0,(__location__ ": %s\n", *error_string));
740 return LDB_ERR_CONSTRAINT_VIOLATION;
742 info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
744 status = dsdb_schema_info_blob_new(mem_ctx, &info_val_default);
745 if (!W_ERROR_IS_OK(status)) {
746 *error_string = talloc_asprintf(mem_ctx,
747 "schema_fsmo_init: dsdb_schema_info_blob_new() failed - %s",
749 DEBUG(0,(__location__ ": %s\n", *error_string));
750 return ldb_operr(ldb);
752 info_val = &info_val_default;
755 status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
756 if (!W_ERROR_IS_OK(status)) {
757 *error_string = talloc_asprintf(mem_ctx,
758 "schema_fsmo_init: failed to load oid mappings: %s",
760 DEBUG(0,(__location__ ": %s\n", *error_string));
761 return LDB_ERR_CONSTRAINT_VIOLATION;
764 for (i=0; i < attrs_res->count; i++) {
765 status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i]);
766 if (!W_ERROR_IS_OK(status)) {
767 *error_string = talloc_asprintf(mem_ctx,
768 "schema_fsmo_init: failed to load attribute definition: %s:%s",
769 ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
771 DEBUG(0,(__location__ ": %s\n", *error_string));
772 return LDB_ERR_CONSTRAINT_VIOLATION;
776 for (i=0; i < objectclass_res->count; i++) {
777 status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i]);
778 if (!W_ERROR_IS_OK(status)) {
779 *error_string = talloc_asprintf(mem_ctx,
780 "schema_fsmo_init: failed to load class definition: %s:%s",
781 ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
783 DEBUG(0,(__location__ ": %s\n", *error_string));
784 return LDB_ERR_CONSTRAINT_VIOLATION;
788 schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
789 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
790 schema->fsmo.we_are_master = true;
792 schema->fsmo.we_are_master = false;
795 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
796 (schema->fsmo.we_are_master?"yes":"no")));
798 *schema_out = schema;