s4:schema - Change also here counters to "unsigned" where needed
[Samba/cd1.git] / source4 / dsdb / schema / schema_init.c
blob949c1ea06930ee8761b4be2e252819fe4b8bcadb
1 /*
2 Unix SMB/CIFS mplementation.
3 DSDB schema header
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/>.
23 #include "includes.h"
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, struct smb_iconv_convenience *iconv_convenience)
38 struct dsdb_schema *schema = talloc_zero(mem_ctx, struct dsdb_schema);
39 if (!schema) {
40 return NULL;
43 schema->iconv_convenience = iconv_convenience;
44 return schema;
48 WERROR dsdb_load_prefixmap_from_drsuapi(struct dsdb_schema *schema,
49 const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
51 WERROR werr;
52 const char *schema_info;
53 struct dsdb_schema_prefixmap *pfm;
55 werr = dsdb_schema_pfm_from_drsuapi_pfm(ctr, true, schema, &pfm, &schema_info);
56 W_ERROR_NOT_OK_RETURN(werr);
58 /* set loaded prefixMap */
59 talloc_free(schema->prefixmap);
60 schema->prefixmap = pfm;
62 talloc_free(discard_const(schema->schema_info));
63 schema->schema_info = schema_info;
65 return WERR_OK;
68 static WERROR _dsdb_prefixmap_from_ldb_val(const struct ldb_val *pfm_ldb_val,
69 struct smb_iconv_convenience *iconv_convenience,
70 TALLOC_CTX *mem_ctx,
71 struct dsdb_schema_prefixmap **_pfm)
73 WERROR werr;
74 enum ndr_err_code ndr_err;
75 struct prefixMapBlob pfm_blob;
77 TALLOC_CTX *temp_ctx = talloc_new(mem_ctx);
78 W_ERROR_HAVE_NO_MEMORY(temp_ctx);
80 ndr_err = ndr_pull_struct_blob(pfm_ldb_val, temp_ctx,
81 iconv_convenience, &pfm_blob,
82 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
83 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
84 NTSTATUS nt_status = ndr_map_error2ntstatus(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 incorrect\n"));
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);
98 talloc_free(temp_ctx);
100 return werr;
103 WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
104 const struct ldb_val *prefixMap,
105 const struct ldb_val *schemaInfo)
107 WERROR status;
108 const char *schema_info;
109 struct dsdb_schema_prefixmap *pfm;
110 TALLOC_CTX *mem_ctx;
112 /* verify input params */
113 if (schemaInfo->length != 21) {
114 return WERR_INVALID_PARAMETER;
116 if (schemaInfo->data[0] != 0xFF) {
117 return WERR_INVALID_PARAMETER;
120 mem_ctx = talloc_new(schema);
121 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
123 /* fetch prefixMap */
124 status = _dsdb_prefixmap_from_ldb_val(prefixMap,
125 schema->iconv_convenience,
126 mem_ctx, &pfm);
127 W_ERROR_NOT_OK_RETURN(status);
129 /* decode schema_info */
130 schema_info = hex_encode_talloc(mem_ctx,
131 schemaInfo->data,
132 schemaInfo->length);
133 if (!schema_info) {
134 talloc_free(mem_ctx);
135 return WERR_NOMEM;
138 /* store prefixMap and schema_info into cached Schema */
139 talloc_free(schema->prefixmap);
140 schema->prefixmap = talloc_steal(schema, pfm);
142 talloc_free(discard_const(schema->schema_info));
143 schema->schema_info = talloc_steal(schema, schema_info);
145 /* clean up locally allocated mem */
146 talloc_free(mem_ctx);
148 return WERR_OK;
151 WERROR dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema *schema,
152 bool include_schema_info,
153 TALLOC_CTX *mem_ctx,
154 struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
156 return dsdb_drsuapi_pfm_from_schema_pfm(schema->prefixmap,
157 include_schema_info ? schema->schema_info : NULL,
158 mem_ctx, _ctr);
161 WERROR dsdb_get_oid_mappings_ldb(const struct dsdb_schema *schema,
162 TALLOC_CTX *mem_ctx,
163 struct ldb_val *prefixMap,
164 struct ldb_val *schemaInfo)
166 WERROR status;
167 enum ndr_err_code ndr_err;
168 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
169 struct prefixMapBlob pfm;
171 status = dsdb_get_oid_mappings_drsuapi(schema, false, mem_ctx, &ctr);
172 W_ERROR_NOT_OK_RETURN(status);
174 pfm.version = PREFIX_MAP_VERSION_DSDB;
175 pfm.reserved = 0;
176 pfm.ctr.dsdb = *ctr;
178 ndr_err = ndr_push_struct_blob(prefixMap, mem_ctx, schema->iconv_convenience, &pfm,
179 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
180 talloc_free(ctr);
181 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
182 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
183 return ntstatus_to_werror(nt_status);
186 *schemaInfo = strhex_to_data_blob(mem_ctx, schema->schema_info);
187 W_ERROR_HAVE_NO_MEMORY(schemaInfo->data);
189 return WERR_OK;
194 * this function is called from within a ldb transaction from the schema_fsmo module
196 WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
198 WERROR status;
199 uint32_t attid;
200 TALLOC_CTX *mem_ctx;
201 struct dsdb_schema_prefixmap *pfm;
203 mem_ctx = talloc_new(ldb);
204 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
206 /* Read prefixes from disk*/
207 status = dsdb_read_prefixes_from_ldb(ldb, mem_ctx, &pfm);
208 if (!W_ERROR_IS_OK(status)) {
209 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
210 win_errstr(status)));
211 talloc_free(mem_ctx);
212 return status;
215 /* Check if there is a prefix for the oid in the prefixes array*/
216 status = dsdb_schema_pfm_find_oid(pfm, full_oid, NULL);
217 if (W_ERROR_IS_OK(status)) {
218 /* prefix found*/
219 talloc_free(mem_ctx);
220 return status;
221 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
222 /* error */
223 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
224 win_errstr(status)));
225 talloc_free(mem_ctx);
226 return status;
229 /* Create the new mapping for the prefix of full_oid */
230 status = dsdb_schema_pfm_make_attid(pfm, full_oid, &attid);
231 if (!W_ERROR_IS_OK(status)) {
232 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_schema_pfm_make_attid: %s\n",
233 win_errstr(status)));
234 talloc_free(mem_ctx);
235 return status;
238 talloc_unlink(schema, schema->prefixmap);
239 schema->prefixmap = talloc_steal(schema, pfm);
241 /* Update prefixMap in ldb*/
242 status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
243 if (!W_ERROR_IS_OK(status)) {
244 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
245 win_errstr(status)));
246 talloc_free(mem_ctx);
247 return status;
250 DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
251 full_oid, schema->prefixmap->length));
253 talloc_free(mem_ctx);
254 return status;
258 WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
259 const struct dsdb_schema *schema)
261 WERROR status;
262 int ldb_ret;
263 struct ldb_message *msg;
264 struct ldb_dn *schema_dn;
265 struct prefixMapBlob pfm_blob;
266 struct ldb_val ndr_blob;
267 enum ndr_err_code ndr_err;
268 TALLOC_CTX *temp_ctx;
269 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
271 schema_dn = samdb_schema_dn(ldb);
272 if (!schema_dn) {
273 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
274 return WERR_FOOBAR;
277 temp_ctx = talloc_new(mem_ctx);
278 W_ERROR_HAVE_NO_MEMORY(temp_ctx);
280 /* convert schema_prefixMap to prefixMap blob */
281 status = dsdb_get_oid_mappings_drsuapi(schema, false, temp_ctx, &ctr);
282 if (!W_ERROR_IS_OK(status)) {
283 talloc_free(temp_ctx);
284 return status;
287 pfm_blob.version = PREFIX_MAP_VERSION_DSDB;
288 pfm_blob.ctr.dsdb = *ctr;
290 ndr_err = ndr_push_struct_blob(&ndr_blob, temp_ctx,
291 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
292 &pfm_blob,
293 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
294 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
295 talloc_free(temp_ctx);
296 return WERR_FOOBAR;
299 /* write serialized prefixMap into LDB */
300 msg = ldb_msg_new(temp_ctx);
301 if (!msg) {
302 talloc_free(temp_ctx);
303 return WERR_NOMEM;
306 msg->dn = schema_dn;
307 ldb_ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL);
308 if (ldb_ret != 0) {
309 talloc_free(temp_ctx);
310 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
311 return WERR_NOMEM;
314 ldb_ret = dsdb_replace(ldb, msg, DSDB_FLAG_AS_SYSTEM);
316 talloc_free(temp_ctx);
318 if (ldb_ret != 0) {
319 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: dsdb_replace failed\n"));
320 return WERR_FOOBAR;
323 return WERR_OK;
326 WERROR dsdb_read_prefixes_from_ldb(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct dsdb_schema_prefixmap **_pfm)
328 WERROR werr;
329 int ldb_ret;
330 const struct ldb_val *prefix_val;
331 struct smb_iconv_convenience *iconv_convenience;
332 struct ldb_dn *schema_dn;
333 struct ldb_result *schema_res = NULL;
334 static const char *schema_attrs[] = {
335 "prefixMap",
336 NULL
339 schema_dn = samdb_schema_dn(ldb);
340 if (!schema_dn) {
341 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
342 return WERR_FOOBAR;
345 ldb_ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
346 if (ldb_ret == LDB_ERR_NO_SUCH_OBJECT) {
347 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
348 talloc_free(schema_res);
349 return WERR_FOOBAR;
350 } else if (ldb_ret != LDB_SUCCESS) {
351 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
352 talloc_free(schema_res);
353 return WERR_FOOBAR;
356 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
357 if (!prefix_val) {
358 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
359 talloc_free(schema_res);
360 return WERR_FOOBAR;
363 iconv_convenience = lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm"));
365 werr = _dsdb_prefixmap_from_ldb_val(prefix_val,
366 iconv_convenience,
367 mem_ctx,
368 _pfm);
369 talloc_free(schema_res);
370 W_ERROR_NOT_OK_RETURN(werr);
372 return WERR_OK;
376 this will be replaced with something that looks at the right part of
377 the schema once we know where unique indexing information is hidden
379 static bool dsdb_schema_unique_attribute(const char *attr)
381 const char *attrs[] = { "objectGUID", "objectSID" , NULL };
382 unsigned int i;
383 for (i=0;attrs[i];i++) {
384 if (strcasecmp(attr, attrs[i]) == 0) {
385 return true;
388 return false;
393 setup the ldb_schema_attribute field for a dsdb_attribute
395 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
396 struct dsdb_attribute *attr)
398 const char *syntax = attr->syntax->ldb_syntax;
399 const struct ldb_schema_syntax *s;
400 struct ldb_schema_attribute *a;
402 if (!syntax) {
403 syntax = attr->syntax->ldap_oid;
406 s = ldb_samba_syntax_by_lDAPDisplayName(ldb, attr->lDAPDisplayName);
407 if (s == NULL) {
408 s = ldb_samba_syntax_by_name(ldb, syntax);
410 if (s == NULL) {
411 s = ldb_standard_syntax_by_name(ldb, syntax);
414 if (s == NULL) {
415 return LDB_ERR_OPERATIONS_ERROR;
418 attr->ldb_schema_attribute = a = talloc(attr, struct ldb_schema_attribute);
419 if (attr->ldb_schema_attribute == NULL) {
420 ldb_oom(ldb);
421 return LDB_ERR_OPERATIONS_ERROR;
424 a->name = attr->lDAPDisplayName;
425 a->flags = 0;
426 a->syntax = s;
428 if (dsdb_schema_unique_attribute(a->name)) {
429 a->flags |= LDB_ATTR_FLAG_UNIQUE_INDEX;
431 if (attr->isSingleValued) {
432 a->flags |= LDB_ATTR_FLAG_SINGLE_VALUE;
436 return LDB_SUCCESS;
440 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
441 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
442 if (get_string_val == NULL) { \
443 if (strict) { \
444 d_printf("%s: %s == NULL\n", __location__, attr); \
445 return WERR_INVALID_PARAM; \
446 } else { \
447 (p)->elem = NULL; \
449 } else { \
450 (p)->elem = talloc_strndup(mem_ctx, \
451 (const char *)get_string_val->data, \
452 get_string_val->length); \
453 if (!(p)->elem) { \
454 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
455 return WERR_NOMEM; \
458 } while (0)
460 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
461 int get_string_list_counter; \
462 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
463 if (get_string_list_el == NULL) { \
464 if (strict) { \
465 d_printf("%s: %s == NULL\n", __location__, attr); \
466 return WERR_INVALID_PARAM; \
467 } else { \
468 (p)->elem = NULL; \
469 break; \
472 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
473 for (get_string_list_counter=0; \
474 get_string_list_counter < get_string_list_el->num_values; \
475 get_string_list_counter++) { \
476 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
477 (const char *)get_string_list_el->values[get_string_list_counter].data, \
478 get_string_list_el->values[get_string_list_counter].length); \
479 if (!(p)->elem[get_string_list_counter]) { \
480 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
481 return WERR_NOMEM; \
483 (p)->elem[get_string_list_counter+1] = NULL; \
485 talloc_steal(mem_ctx, (p)->elem); \
486 } while (0)
488 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
489 const char *str; \
490 str = samdb_result_string(msg, attr, NULL);\
491 if (str == NULL) { \
492 if (strict) { \
493 d_printf("%s: %s == NULL\n", __location__, attr); \
494 return WERR_INVALID_PARAM; \
495 } else { \
496 (p)->elem = false; \
498 } else if (strcasecmp("TRUE", str) == 0) { \
499 (p)->elem = true; \
500 } else if (strcasecmp("FALSE", str) == 0) { \
501 (p)->elem = false; \
502 } else { \
503 d_printf("%s: %s == %s\n", __location__, attr, str); \
504 return WERR_INVALID_PARAM; \
506 } while (0)
508 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
509 (p)->elem = samdb_result_uint(msg, attr, 0);\
510 } while (0)
512 #define GET_UINT32_PTR_LDB(msg, attr, mem_ctx, p, elem) do { \
513 uint64_t _v = samdb_result_uint64(msg, attr, UINT64_MAX);\
514 if (_v == UINT64_MAX) { \
515 (p)->elem = NULL; \
516 } else if (_v > UINT32_MAX) { \
517 d_printf("%s: %s == 0x%llX\n", __location__, \
518 attr, (unsigned long long)_v); \
519 return WERR_INVALID_PARAM; \
520 } else { \
521 (p)->elem = talloc(mem_ctx, uint32_t); \
522 if (!(p)->elem) { \
523 d_printf("%s: talloc failed for %s\n", __location__, attr); \
524 return WERR_NOMEM; \
526 *(p)->elem = (uint32_t)_v; \
528 } while (0)
530 #define GET_GUID_LDB(msg, attr, p, elem) do { \
531 (p)->elem = samdb_result_guid(msg, attr);\
532 } while (0)
534 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
535 const struct ldb_val *_val;\
536 _val = ldb_msg_find_ldb_val(msg, attr);\
537 if (_val) {\
538 (p)->elem = *_val;\
539 talloc_steal(mem_ctx, (p)->elem.data);\
540 } else {\
541 ZERO_STRUCT((p)->elem);\
543 } while (0)
545 WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
546 struct dsdb_schema *schema,
547 struct ldb_message *msg)
549 WERROR status;
550 struct dsdb_attribute *attr = talloc_zero(schema, struct dsdb_attribute);
551 if (!attr) {
552 return WERR_NOMEM;
555 GET_STRING_LDB(msg, "cn", attr, attr, cn, false);
556 GET_STRING_LDB(msg, "lDAPDisplayName", attr, attr, lDAPDisplayName, true);
557 GET_STRING_LDB(msg, "attributeID", attr, attr, attributeID_oid, true);
558 if (!schema->prefixmap || schema->prefixmap->length == 0) {
559 /* set an invalid value */
560 attr->attributeID_id = 0xFFFFFFFF;
561 } else {
562 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
563 attr->attributeID_oid,
564 &attr->attributeID_id);
565 if (!W_ERROR_IS_OK(status)) {
566 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
567 __location__, attr->lDAPDisplayName, attr->attributeID_oid,
568 win_errstr(status)));
569 return status;
572 /* fetch msDS-IntId to be used in resolving ATTRTYP values */
573 GET_UINT32_LDB(msg, "msDS-IntId", attr, msDS_IntId);
575 GET_GUID_LDB(msg, "schemaIDGUID", attr, schemaIDGUID);
576 GET_UINT32_LDB(msg, "mAPIID", attr, mAPIID);
578 GET_GUID_LDB(msg, "attributeSecurityGUID", attr, attributeSecurityGUID);
580 GET_GUID_LDB(msg, "objectGUID", attr, objectGUID);
582 GET_UINT32_LDB(msg, "searchFlags", attr, searchFlags);
583 GET_UINT32_LDB(msg, "systemFlags", attr, systemFlags);
584 GET_BOOL_LDB(msg, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
585 GET_UINT32_LDB(msg, "linkID", attr, linkID);
587 GET_STRING_LDB(msg, "attributeSyntax", attr, attr, attributeSyntax_oid, true);
588 if (!schema->prefixmap || schema->prefixmap->length == 0) {
589 /* set an invalid value */
590 attr->attributeSyntax_id = 0xFFFFFFFF;
591 } else {
592 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
593 attr->attributeSyntax_oid,
594 &attr->attributeSyntax_id);
595 if (!W_ERROR_IS_OK(status)) {
596 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
597 __location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
598 win_errstr(status)));
599 return status;
602 GET_UINT32_LDB(msg, "oMSyntax", attr, oMSyntax);
603 GET_BLOB_LDB(msg, "oMObjectClass", attr, attr, oMObjectClass);
605 GET_BOOL_LDB(msg, "isSingleValued", attr, isSingleValued, true);
606 GET_UINT32_PTR_LDB(msg, "rangeLower", attr, attr, rangeLower);
607 GET_UINT32_PTR_LDB(msg, "rangeUpper", attr, attr, rangeUpper);
608 GET_BOOL_LDB(msg, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
610 GET_UINT32_LDB(msg, "schemaFlagsEx", attr, schemaFlagsEx);
611 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", attr, attr, msDs_Schema_Extensions);
613 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
614 GET_STRING_LDB(msg, "adminDisplayName", attr, attr, adminDisplayName, false);
615 GET_STRING_LDB(msg, "adminDescription", attr, attr, adminDescription, false);
616 GET_STRING_LDB(msg, "classDisplayName", attr, attr, classDisplayName, false);
617 GET_BOOL_LDB(msg, "isEphemeral", attr, isEphemeral, false);
618 GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
619 GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
621 attr->syntax = dsdb_syntax_for_attribute(attr);
622 if (!attr->syntax) {
623 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
624 attr->lDAPDisplayName));
625 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
628 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
629 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
630 attr->lDAPDisplayName));
631 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
634 DLIST_ADD(schema->attributes, attr);
635 return WERR_OK;
638 WERROR dsdb_class_from_ldb(struct dsdb_schema *schema,
639 struct ldb_message *msg)
641 WERROR status;
642 struct dsdb_class *obj = talloc_zero(schema, struct dsdb_class);
643 if (!obj) {
644 return WERR_NOMEM;
646 GET_STRING_LDB(msg, "cn", obj, obj, cn, false);
647 GET_STRING_LDB(msg, "lDAPDisplayName", obj, obj, lDAPDisplayName, true);
648 GET_STRING_LDB(msg, "governsID", obj, obj, governsID_oid, true);
649 if (!schema->prefixmap || schema->prefixmap->length == 0) {
650 /* set an invalid value */
651 obj->governsID_id = 0xFFFFFFFF;
652 } else {
653 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
654 obj->governsID_oid,
655 &obj->governsID_id);
656 if (!W_ERROR_IS_OK(status)) {
657 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
658 __location__, obj->lDAPDisplayName, obj->governsID_oid,
659 win_errstr(status)));
660 return status;
663 GET_GUID_LDB(msg, "schemaIDGUID", obj, schemaIDGUID);
664 GET_GUID_LDB(msg, "objectGUID", obj, objectGUID);
666 GET_UINT32_LDB(msg, "objectClassCategory", obj, objectClassCategory);
667 GET_STRING_LDB(msg, "rDNAttID", obj, obj, rDNAttID, false);
668 GET_STRING_LDB(msg, "defaultObjectCategory", obj, obj, defaultObjectCategory, true);
670 GET_STRING_LDB(msg, "subClassOf", obj, obj, subClassOf, true);
672 GET_STRING_LIST_LDB(msg, "systemAuxiliaryClass", obj, obj, systemAuxiliaryClass, false);
673 GET_STRING_LIST_LDB(msg, "auxiliaryClass", obj, obj, auxiliaryClass, false);
675 GET_STRING_LIST_LDB(msg, "systemMustContain", obj, obj, systemMustContain, false);
676 GET_STRING_LIST_LDB(msg, "systemMayContain", obj, obj, systemMayContain, false);
677 GET_STRING_LIST_LDB(msg, "mustContain", obj, obj, mustContain, false);
678 GET_STRING_LIST_LDB(msg, "mayContain", obj, obj, mayContain, false);
680 GET_STRING_LIST_LDB(msg, "systemPossSuperiors", obj, obj, systemPossSuperiors, false);
681 GET_STRING_LIST_LDB(msg, "possSuperiors", obj, obj, possSuperiors, false);
683 GET_STRING_LDB(msg, "defaultSecurityDescriptor", obj, obj, defaultSecurityDescriptor, false);
685 GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
686 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", obj, obj, msDs_Schema_Extensions);
688 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
689 GET_STRING_LDB(msg, "adminDisplayName", obj, obj, adminDisplayName, false);
690 GET_STRING_LDB(msg, "adminDescription", obj, obj, adminDescription, false);
691 GET_STRING_LDB(msg, "classDisplayName", obj, obj, classDisplayName, false);
692 GET_BOOL_LDB(msg, "defaultHidingValue", obj, defaultHidingValue, false);
693 GET_BOOL_LDB(msg, "isDefunct", obj, isDefunct, false);
694 GET_BOOL_LDB(msg, "systemOnly", obj, systemOnly, false);
696 DLIST_ADD(schema->classes, obj);
697 return WERR_OK;
700 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
703 Create a DSDB schema from the ldb results provided. This is called
704 directly when the schema is provisioned from an on-disk LDIF file, or
705 from dsdb_schema_from_schema_dn in schema_fsmo
708 int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
709 struct smb_iconv_convenience *iconv_convenience,
710 struct ldb_result *schema_res,
711 struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
712 struct dsdb_schema **schema_out,
713 char **error_string)
715 WERROR status;
716 unsigned int i;
717 const struct ldb_val *prefix_val;
718 const struct ldb_val *info_val;
719 struct ldb_val info_val_default;
720 struct dsdb_schema *schema;
722 schema = dsdb_new_schema(mem_ctx, iconv_convenience);
723 if (!schema) {
724 dsdb_oom(error_string, mem_ctx);
725 return LDB_ERR_OPERATIONS_ERROR;
728 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
729 if (!prefix_val) {
730 *error_string = talloc_asprintf(mem_ctx,
731 "schema_fsmo_init: no prefixMap attribute found");
732 DEBUG(0,(__location__ ": %s\n", *error_string));
733 return LDB_ERR_CONSTRAINT_VIOLATION;
735 info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
736 if (!info_val) {
737 info_val_default = strhex_to_data_blob(mem_ctx, "FF0000000000000000000000000000000000000000");
738 if (!info_val_default.data) {
739 dsdb_oom(error_string, mem_ctx);
740 return LDB_ERR_OPERATIONS_ERROR;
742 info_val = &info_val_default;
745 status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
746 if (!W_ERROR_IS_OK(status)) {
747 *error_string = talloc_asprintf(mem_ctx,
748 "schema_fsmo_init: failed to load oid mappings: %s",
749 win_errstr(status));
750 DEBUG(0,(__location__ ": %s\n", *error_string));
751 return LDB_ERR_CONSTRAINT_VIOLATION;
754 for (i=0; i < attrs_res->count; i++) {
755 status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i]);
756 if (!W_ERROR_IS_OK(status)) {
757 *error_string = talloc_asprintf(mem_ctx,
758 "schema_fsmo_init: failed to load attribute definition: %s:%s",
759 ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
760 win_errstr(status));
761 DEBUG(0,(__location__ ": %s\n", *error_string));
762 return LDB_ERR_CONSTRAINT_VIOLATION;
766 for (i=0; i < objectclass_res->count; i++) {
767 status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i]);
768 if (!W_ERROR_IS_OK(status)) {
769 *error_string = talloc_asprintf(mem_ctx,
770 "schema_fsmo_init: failed to load class definition: %s:%s",
771 ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
772 win_errstr(status));
773 DEBUG(0,(__location__ ": %s\n", *error_string));
774 return LDB_ERR_CONSTRAINT_VIOLATION;
778 schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
779 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
780 schema->fsmo.we_are_master = true;
781 } else {
782 schema->fsmo.we_are_master = false;
785 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
786 (schema->fsmo.we_are_master?"yes":"no")));
788 *schema_out = schema;
789 return LDB_SUCCESS;
793 static const struct {
794 const char *name;
795 const char *oid;
796 } name_mappings[] = {
797 { "cn", "2.5.4.3" },
798 { "name", "1.2.840.113556.1.4.1" },
799 { "lDAPDisplayName", "1.2.840.113556.1.2.460" },
800 { "attributeID", "1.2.840.113556.1.2.30" },
801 { "schemaIDGUID", "1.2.840.113556.1.4.148" },
802 { "mAPIID", "1.2.840.113556.1.2.49" },
803 { "attributeSecurityGUID", "1.2.840.113556.1.4.149" },
804 { "searchFlags", "1.2.840.113556.1.2.334" },
805 { "systemFlags", "1.2.840.113556.1.4.375" },
806 { "isMemberOfPartialAttributeSet", "1.2.840.113556.1.4.639" },
807 { "linkID", "1.2.840.113556.1.2.50" },
808 { "attributeSyntax", "1.2.840.113556.1.2.32" },
809 { "oMSyntax", "1.2.840.113556.1.2.231" },
810 { "oMObjectClass", "1.2.840.113556.1.2.218" },
811 { "isSingleValued", "1.2.840.113556.1.2.33" },
812 { "rangeLower", "1.2.840.113556.1.2.34" },
813 { "rangeUpper", "1.2.840.113556.1.2.35" },
814 { "extendedCharsAllowed", "1.2.840.113556.1.2.380" },
815 { "schemaFlagsEx", "1.2.840.113556.1.4.120" },
816 { "msDs-Schema-Extensions", "1.2.840.113556.1.4.1440" },
817 { "showInAdvancedViewOnly", "1.2.840.113556.1.2.169" },
818 { "adminDisplayName", "1.2.840.113556.1.2.194" },
819 { "adminDescription", "1.2.840.113556.1.2.226" },
820 { "classDisplayName", "1.2.840.113556.1.4.610" },
821 { "isEphemeral", "1.2.840.113556.1.4.1212" },
822 { "isDefunct", "1.2.840.113556.1.4.661" },
823 { "systemOnly", "1.2.840.113556.1.4.170" },
824 { "governsID", "1.2.840.113556.1.2.22" },
825 { "objectClassCategory", "1.2.840.113556.1.2.370" },
826 { "rDNAttID", "1.2.840.113556.1.2.26" },
827 { "defaultObjectCategory", "1.2.840.113556.1.4.783" },
828 { "subClassOf", "1.2.840.113556.1.2.21" },
829 { "systemAuxiliaryClass", "1.2.840.113556.1.4.198" },
830 { "systemPossSuperiors", "1.2.840.113556.1.4.195" },
831 { "systemMustContain", "1.2.840.113556.1.4.197" },
832 { "systemMayContain", "1.2.840.113556.1.4.196" },
833 { "auxiliaryClass", "1.2.840.113556.1.2.351" },
834 { "possSuperiors", "1.2.840.113556.1.2.8" },
835 { "mustContain", "1.2.840.113556.1.2.24" },
836 { "mayContain", "1.2.840.113556.1.2.25" },
837 { "defaultSecurityDescriptor", "1.2.840.113556.1.4.224" },
838 { "defaultHidingValue", "1.2.840.113556.1.4.518" },
839 { "msDS-IntId", "1.2.840.113556.1.4.1716" },
842 static struct drsuapi_DsReplicaAttribute *dsdb_find_object_attr_name(struct dsdb_schema *schema,
843 struct drsuapi_DsReplicaObject *obj,
844 const char *name,
845 uint32_t *idx)
847 WERROR status;
848 unsigned int i;
849 uint32_t attid;
850 const char *oid = NULL;
852 for(i=0; i < ARRAY_SIZE(name_mappings); i++) {
853 if (strcmp(name_mappings[i].name, name) != 0) continue;
855 oid = name_mappings[i].oid;
856 break;
859 if (!oid) {
860 return NULL;
863 status = dsdb_schema_pfm_make_attid(schema->prefixmap, oid, &attid);
864 if (!W_ERROR_IS_OK(status)) {
865 return NULL;
868 for (i=0; i < obj->attribute_ctr.num_attributes; i++) {
869 if (obj->attribute_ctr.attributes[i].attid != attid) continue;
871 if (idx) *idx = i;
872 return &obj->attribute_ctr.attributes[i];
875 return NULL;
878 #define GET_STRING_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
879 struct drsuapi_DsReplicaAttribute *_a; \
880 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
881 if (strict && !_a) { \
882 d_printf("%s: %s == NULL\n", __location__, attr); \
883 return WERR_INVALID_PARAM; \
885 if (strict && _a->value_ctr.num_values != 1) { \
886 d_printf("%s: %s num_values == %u\n", __location__, attr, \
887 _a->value_ctr.num_values); \
888 return WERR_INVALID_PARAM; \
890 if (_a && _a->value_ctr.num_values >= 1) { \
891 size_t _ret; \
892 if (!convert_string_talloc_convenience(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \
893 _a->value_ctr.values[0].blob->data, \
894 _a->value_ctr.values[0].blob->length, \
895 (void **)discard_const(&(p)->elem), &_ret, false)) { \
896 DEBUG(0,("%s: invalid data!\n", attr)); \
897 dump_data(0, \
898 _a->value_ctr.values[0].blob->data, \
899 _a->value_ctr.values[0].blob->length); \
900 return WERR_FOOBAR; \
902 } else { \
903 (p)->elem = NULL; \
905 } while (0)
907 #define GET_UINT32_LIST_DS(s, r, attr, mem_ctx, p, elem) do { \
908 unsigned int list_counter; \
909 struct drsuapi_DsReplicaAttribute *_a; \
910 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
911 (p)->elem = _a ? talloc_array(mem_ctx, uint32_t, _a->value_ctr.num_values + 1) : NULL; \
912 for (list_counter=0; \
913 _a && list_counter < _a->value_ctr.num_values; \
914 list_counter++) { \
915 if (_a->value_ctr.values[list_counter].blob->length != 4) { \
916 return WERR_INVALID_PARAM; \
918 (p)->elem[list_counter] = IVAL(_a->value_ctr.values[list_counter].blob->data, 0); \
920 if (_a) (p)->elem[list_counter] = 0; \
921 } while (0)
923 #define GET_BOOL_DS(s, r, attr, p, elem, strict) do { \
924 struct drsuapi_DsReplicaAttribute *_a; \
925 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
926 if (strict && !_a) { \
927 d_printf("%s: %s == NULL\n", __location__, attr); \
928 return WERR_INVALID_PARAM; \
930 if (strict && _a->value_ctr.num_values != 1) { \
931 d_printf("%s: %s num_values == %u\n", __location__, attr, \
932 (unsigned int)_a->value_ctr.num_values); \
933 return WERR_INVALID_PARAM; \
935 if (strict && !_a->value_ctr.values[0].blob) { \
936 d_printf("%s: %s data == NULL\n", __location__, attr); \
937 return WERR_INVALID_PARAM; \
939 if (strict && _a->value_ctr.values[0].blob->length != 4) { \
940 d_printf("%s: %s length == %u\n", __location__, attr, \
941 (unsigned int)_a->value_ctr.values[0].blob->length); \
942 return WERR_INVALID_PARAM; \
944 if (_a && _a->value_ctr.num_values >= 1 \
945 && _a->value_ctr.values[0].blob \
946 && _a->value_ctr.values[0].blob->length == 4) { \
947 (p)->elem = (IVAL(_a->value_ctr.values[0].blob->data,0)?true:false);\
948 } else { \
949 (p)->elem = false; \
951 } while (0)
953 #define GET_UINT32_DS(s, r, attr, p, elem, def_val) do { \
954 struct drsuapi_DsReplicaAttribute *_a; \
955 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
956 if (_a && _a->value_ctr.num_values >= 1 \
957 && _a->value_ctr.values[0].blob \
958 && _a->value_ctr.values[0].blob->length == 4) { \
959 (p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
960 } else { \
961 (p)->elem = def_val; \
963 } while (0)
965 #define GET_UINT32_PTR_DS(s, r, attr, p, elem) do { \
966 struct drsuapi_DsReplicaAttribute *_a; \
967 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
968 if (_a && _a->value_ctr.num_values >= 1 \
969 && _a->value_ctr.values[0].blob \
970 && _a->value_ctr.values[0].blob->length == 4) { \
971 (p)->elem = talloc(mem_ctx, uint32_t); \
972 if (!(p)->elem) { \
973 d_printf("%s: talloc failed for %s\n", __location__, attr); \
974 return WERR_NOMEM; \
976 *(p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
977 } else { \
978 (p)->elem = NULL; \
980 } while (0)
982 #define GET_GUID_DS(s, r, attr, mem_ctx, p, elem) do { \
983 struct drsuapi_DsReplicaAttribute *_a; \
984 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
985 if (_a && _a->value_ctr.num_values >= 1 \
986 && _a->value_ctr.values[0].blob \
987 && _a->value_ctr.values[0].blob->length == 16) { \
988 NTSTATUS _nt_status = GUID_from_ndr_blob(_a->value_ctr.values[0].blob, &(p)->elem); \
989 if (!NT_STATUS_IS_OK(_nt_status)) { \
990 return ntstatus_to_werror(_nt_status); \
992 } else { \
993 ZERO_STRUCT((p)->elem);\
995 } while (0)
997 #define GET_BLOB_DS(s, r, attr, mem_ctx, p, elem) do { \
998 struct drsuapi_DsReplicaAttribute *_a; \
999 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1000 if (_a && _a->value_ctr.num_values >= 1 \
1001 && _a->value_ctr.values[0].blob) { \
1002 (p)->elem = *_a->value_ctr.values[0].blob;\
1003 talloc_steal(mem_ctx, (p)->elem.data); \
1004 } else { \
1005 ZERO_STRUCT((p)->elem);\
1007 } while (0)
1009 WERROR dsdb_attribute_from_drsuapi(struct ldb_context *ldb,
1010 struct dsdb_schema *schema,
1011 struct drsuapi_DsReplicaObject *r,
1012 TALLOC_CTX *mem_ctx,
1013 struct dsdb_attribute *attr)
1015 WERROR status;
1017 GET_STRING_DS(schema, r, "name", mem_ctx, attr, cn, true);
1018 GET_STRING_DS(schema, r, "lDAPDisplayName", mem_ctx, attr, lDAPDisplayName, true);
1019 GET_UINT32_DS(schema, r, "attributeID", attr, attributeID_id, 0xFFFFFFFF);
1020 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attr->attributeID_id,
1021 mem_ctx, &attr->attributeID_oid);
1022 if (!W_ERROR_IS_OK(status)) {
1023 DEBUG(0,("%s: '%s': unable to map attributeID 0x%08X: %s\n",
1024 __location__, attr->lDAPDisplayName, attr->attributeID_id,
1025 win_errstr(status)));
1026 return status;
1028 /* fetch msDS-IntId to be used in resolving ATTRTYP values */
1029 GET_UINT32_DS(schema, r, "msDS-IntId", attr, msDS_IntId, 0);
1031 GET_GUID_DS(schema, r, "schemaIDGUID", mem_ctx, attr, schemaIDGUID);
1032 GET_UINT32_DS(schema, r, "mAPIID", attr, mAPIID, 0);
1034 GET_GUID_DS(schema, r, "attributeSecurityGUID", mem_ctx, attr, attributeSecurityGUID);
1036 attr->objectGUID = r->identifier->guid;
1038 GET_UINT32_DS(schema, r, "searchFlags", attr, searchFlags, 0);
1039 GET_UINT32_DS(schema, r, "systemFlags", attr, systemFlags, 0);
1040 GET_BOOL_DS(schema, r, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
1041 GET_UINT32_DS(schema, r, "linkID", attr, linkID, 0);
1043 GET_UINT32_DS(schema, r, "attributeSyntax", attr, attributeSyntax_id, 0xFFFFFFFF);
1044 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attr->attributeSyntax_id,
1045 mem_ctx, &attr->attributeSyntax_oid);
1046 if (!W_ERROR_IS_OK(status)) {
1047 DEBUG(0,("%s: '%s': unable to map attributeSyntax 0x%08X: %s\n",
1048 __location__, attr->lDAPDisplayName, attr->attributeSyntax_id,
1049 win_errstr(status)));
1050 return status;
1052 GET_UINT32_DS(schema, r, "oMSyntax", attr, oMSyntax, 0);
1053 GET_BLOB_DS(schema, r, "oMObjectClass", mem_ctx, attr, oMObjectClass);
1055 GET_BOOL_DS(schema, r, "isSingleValued", attr, isSingleValued, true);
1056 GET_UINT32_PTR_DS(schema, r, "rangeLower", attr, rangeLower);
1057 GET_UINT32_PTR_DS(schema, r, "rangeUpper", attr, rangeUpper);
1058 GET_BOOL_DS(schema, r, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
1060 GET_UINT32_DS(schema, r, "schemaFlagsEx", attr, schemaFlagsEx, 0);
1061 GET_BLOB_DS(schema, r, "msDs-Schema-Extensions", mem_ctx, attr, msDs_Schema_Extensions);
1063 GET_BOOL_DS(schema, r, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
1064 GET_STRING_DS(schema, r, "adminDisplayName", mem_ctx, attr, adminDisplayName, false);
1065 GET_STRING_DS(schema, r, "adminDescription", mem_ctx, attr, adminDescription, false);
1066 GET_STRING_DS(schema, r, "classDisplayName", mem_ctx, attr, classDisplayName, false);
1067 GET_BOOL_DS(schema, r, "isEphemeral", attr, isEphemeral, false);
1068 GET_BOOL_DS(schema, r, "isDefunct", attr, isDefunct, false);
1069 GET_BOOL_DS(schema, r, "systemOnly", attr, systemOnly, false);
1071 attr->syntax = dsdb_syntax_for_attribute(attr);
1072 if (!attr->syntax) {
1073 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
1074 attr->lDAPDisplayName));
1075 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
1078 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
1079 DEBUG(0,(__location__ ": Unknown schema syntax for %s\n",
1080 attr->lDAPDisplayName));
1081 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
1084 return WERR_OK;
1087 WERROR dsdb_class_from_drsuapi(struct ldb_context *ldb,
1088 struct dsdb_schema *schema,
1089 struct drsuapi_DsReplicaObject *r,
1090 TALLOC_CTX *mem_ctx,
1091 struct dsdb_class *obj)
1093 WERROR status;
1094 struct drsuapi_DsReplicaAttribute *attr;
1095 DATA_BLOB blob;
1097 GET_STRING_DS(schema, r, "name", mem_ctx, obj, cn, true);
1098 GET_STRING_DS(schema, r, "lDAPDisplayName", mem_ctx, obj, lDAPDisplayName, true);
1099 GET_UINT32_DS(schema, r, "governsID", obj, governsID_id, 0xFFFFFFFF);
1100 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, obj->governsID_id,
1101 mem_ctx, &obj->governsID_oid);
1102 if (!W_ERROR_IS_OK(status)) {
1103 DEBUG(0,("%s: '%s': unable to map governsID 0x%08X: %s\n",
1104 __location__, obj->lDAPDisplayName, obj->governsID_id,
1105 win_errstr(status)));
1106 return status;
1108 GET_GUID_DS(schema, r, "schemaIDGUID", mem_ctx, obj, schemaIDGUID);
1110 obj->objectGUID = r->identifier->guid;
1112 GET_UINT32_DS(schema, r, "objectClassCategory", obj, objectClassCategory, 0);
1113 GET_STRING_DS(schema, r, "rDNAttID", mem_ctx, obj, rDNAttID, false);
1115 attr = dsdb_find_object_attr_name(schema, r, "defaultObjectCategory", NULL);
1117 if (!attr || attr->value_ctr.num_values != 1 || !attr->value_ctr.values[0].blob) {
1118 d_printf("%s: no defaultObjectCategory supplied\n", __location__);
1119 return WERR_INVALID_PARAM;
1122 status = dsdb_syntax_one_DN_drsuapi_to_ldb(mem_ctx, ldb, find_syntax_map_by_standard_oid(LDB_SYNTAX_DN),
1123 schema->iconv_convenience, attr->value_ctr.values[0].blob, &blob);
1124 if (!W_ERROR_IS_OK(status)) {
1125 return status;
1127 obj->defaultObjectCategory = (char *)blob.data;
1129 GET_UINT32_DS(schema, r, "subClassOf", obj, subClassOf_id, 0);
1131 GET_UINT32_LIST_DS(schema, r, "systemAuxiliaryClass", mem_ctx, obj, systemAuxiliaryClass_ids);
1132 GET_UINT32_LIST_DS(schema, r, "auxiliaryClass", mem_ctx, obj, auxiliaryClass_ids);
1134 GET_UINT32_LIST_DS(schema, r, "systemMustContain", mem_ctx, obj, systemMustContain_ids);
1135 GET_UINT32_LIST_DS(schema, r, "systemMayContain", mem_ctx, obj, systemMayContain_ids);
1136 GET_UINT32_LIST_DS(schema, r, "mustContain", mem_ctx, obj, mustContain_ids);
1137 GET_UINT32_LIST_DS(schema, r, "mayContain", mem_ctx, obj, mayContain_ids);
1139 GET_UINT32_LIST_DS(schema, r, "systemPossSuperiors", mem_ctx, obj, systemPossSuperiors_ids);
1140 GET_UINT32_LIST_DS(schema, r, "possSuperiors", mem_ctx, obj, possSuperiors_ids);
1142 GET_STRING_DS(schema, r, "defaultSecurityDescriptor", mem_ctx, obj, defaultSecurityDescriptor, false);
1144 GET_UINT32_DS(schema, r, "schemaFlagsEx", obj, schemaFlagsEx, 0);
1145 GET_BLOB_DS(schema, r, "msDs-Schema-Extensions", mem_ctx, obj, msDs_Schema_Extensions);
1147 GET_BOOL_DS(schema, r, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
1148 GET_STRING_DS(schema, r, "adminDisplayName", mem_ctx, obj, adminDisplayName, false);
1149 GET_STRING_DS(schema, r, "adminDescription", mem_ctx, obj, adminDescription, false);
1150 GET_STRING_DS(schema, r, "classDisplayName", mem_ctx, obj, classDisplayName, false);
1151 GET_BOOL_DS(schema, r, "defaultHidingValue", obj, defaultHidingValue, false);
1152 GET_BOOL_DS(schema, r, "isDefunct", obj, isDefunct, false);
1153 GET_BOOL_DS(schema, r, "systemOnly", obj, systemOnly, false);
1155 return WERR_OK;