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 "lib/ldb/include/ldb_errors.h"
26 #include "../lib/util/dlinklist.h"
27 #include "librpc/gen_ndr/ndr_misc.h"
28 #include "librpc/gen_ndr/ndr_drsuapi.h"
29 #include "librpc/gen_ndr/ndr_drsblobs.h"
30 #include "param/param.h"
31 #include "lib/ldb/include/ldb_module.h"
32 #include "../lib/util/asn1.h"
34 static WERROR dsdb_read_prefixes_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, uint32_t* num_prefixes, struct dsdb_schema_oid_prefix **prefixes);
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);
43 schema->iconv_convenience = iconv_convenience;
48 WERROR dsdb_load_prefixmap_from_drsuapi(struct dsdb_schema *schema,
49 const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
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;
68 static WERROR _dsdb_prefixmap_from_ldb_val(const struct ldb_val *pfm_ldb_val,
69 struct smb_iconv_convenience *iconv_convenience,
71 struct dsdb_schema_prefixmap **_pfm)
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);
103 WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
104 const struct ldb_val *prefixMap,
105 const struct ldb_val *schemaInfo)
108 const char *schema_info;
109 struct dsdb_schema_prefixmap *pfm;
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,
127 W_ERROR_NOT_OK_RETURN(status);
129 /* decode schema_info */
130 schema_info = hex_encode_talloc(mem_ctx,
134 talloc_free(mem_ctx);
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);
151 WERROR dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema *schema,
152 bool include_schema_info,
154 struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
156 return dsdb_drsuapi_pfm_from_schema_pfm(schema->prefixmap,
157 include_schema_info ? schema->schema_info : NULL,
161 WERROR dsdb_get_oid_mappings_ldb(const struct dsdb_schema *schema,
163 struct ldb_val *prefixMap,
164 struct ldb_val *schemaInfo)
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;
178 ndr_err = ndr_push_struct_blob(prefixMap, mem_ctx, schema->iconv_convenience, &pfm, (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);
185 *schemaInfo = strhex_to_data_blob(mem_ctx, schema->schema_info);
186 W_ERROR_HAVE_NO_MEMORY(schemaInfo->data);
193 * this function is called from within a ldb transaction from the schema_fsmo module
195 WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
198 uint32_t num_prefixes;
199 struct dsdb_schema_oid_prefix *prefixes;
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( mem_ctx, ldb, &num_prefixes, &prefixes );
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);
215 /* Check if there is a prefix for the oid in the prefixes array*/
216 status = dsdb_find_prefix_for_oid( num_prefixes, prefixes, full_oid, &out );
217 if (W_ERROR_IS_OK(status)) {
219 talloc_free(mem_ctx);
221 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
223 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
224 win_errstr(status)));
225 talloc_free(mem_ctx);
229 /* Create the new mapping for the prefix of full_oid */
230 status = dsdb_prefix_map_update(mem_ctx, &num_prefixes, &prefixes, full_oid);
231 if (!W_ERROR_IS_OK(status)) {
232 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_prefix_map_update: %s\n",
233 win_errstr(status)));
234 talloc_free(mem_ctx);
238 talloc_free(schema->prefixes);
239 schema->prefixes = talloc_steal(schema, prefixes);
240 schema->num_prefixes = num_prefixes;
242 /* Update prefixMap in ldb*/
243 status = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, ldb, schema);
244 if (!W_ERROR_IS_OK(status)) {
245 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
246 win_errstr(status)));
247 talloc_free(mem_ctx);
251 DEBUG(2,(__location__ " Added prefixMap %s - now have %u prefixes\n",
252 full_oid, num_prefixes));
254 talloc_free(mem_ctx);
258 WERROR dsdb_prefix_map_update(TALLOC_CTX *mem_ctx, uint32_t *num_prefixes, struct dsdb_schema_oid_prefix **prefixes, const char *oid)
260 uint32_t new_num_prefixes, index_new_prefix, new_entry_id;
261 const char* lastDotOffset;
264 new_num_prefixes = *num_prefixes + 1;
265 index_new_prefix = *num_prefixes;
268 * this is the algorithm we use to create new mappings for now
270 * TODO: find what algorithm windows use
272 new_entry_id = (*num_prefixes)<<16;
274 /* Extract the prefix from the oid*/
275 lastDotOffset = strrchr(oid, '.');
276 if (lastDotOffset == NULL) {
277 DEBUG(0,("dsdb_prefix_map_update: failed to find the last dot\n"));
278 return WERR_NOT_FOUND;
281 /* Calculate the size of the remainig string that should be the prefix of it */
282 size = strlen(oid) - strlen(lastDotOffset);
284 DEBUG(0,("dsdb_prefix_map_update: size of the remaining string invalid\n"));
288 /* Create a spot in the prefixMap for one more prefix*/
289 (*prefixes) = talloc_realloc(mem_ctx, *prefixes, struct dsdb_schema_oid_prefix, new_num_prefixes);
290 W_ERROR_HAVE_NO_MEMORY(*prefixes);
292 /* Add the new prefix entry*/
293 (*prefixes)[index_new_prefix].id = new_entry_id;
294 (*prefixes)[index_new_prefix].oid = talloc_strndup(mem_ctx, oid, size);
295 (*prefixes)[index_new_prefix].oid_len = strlen((*prefixes)[index_new_prefix].oid);
297 /* Increase num_prefixes because new prefix has been added */
303 WERROR dsdb_find_prefix_for_oid(uint32_t num_prefixes, const struct dsdb_schema_oid_prefix *prefixes, const char *in, uint32_t *out)
311 /* make oid prefix, i.e. oid w/o last subidentifier */
312 pstr = strrchr(in, '.');
313 if (!pstr) return WERR_INVALID_PARAM;
314 if (pstr < in) return WERR_INVALID_PARAM;
315 if ((pstr - in) < 4) return WERR_INVALID_PARAM;
317 oid_prefix = talloc_strndup(0, in, pstr - in);
319 for (i=0; i < num_prefixes; i++) {
320 if (strcmp(prefixes[i].oid, oid_prefix) == 0) {
325 talloc_free(oid_prefix);
327 if (i < num_prefixes) {
328 /* move next to '.' char */
331 val = strtoul(pstr, &end_str, 10);
332 if (end_str[0] != '\0') {
333 return WERR_INVALID_PARAM;
334 } else if (val > 0xFFFF) {
335 return WERR_INVALID_PARAM;
338 *out = prefixes[i].id | val;
342 DEBUG(5,(__location__ " Failed to find oid %s - have %u prefixes\n", in, num_prefixes));
344 return WERR_DS_NO_MSDS_INTID;
347 WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
348 const struct dsdb_schema *schema)
350 struct ldb_message *msg = ldb_msg_new(mem_ctx);
351 struct ldb_dn *schema_dn;
352 struct prefixMapBlob pm;
353 struct ldb_val ndr_blob;
354 enum ndr_err_code ndr_err;
362 schema_dn = samdb_schema_dn(ldb);
364 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
368 pm.version = PREFIX_MAP_VERSION_DSDB;
369 pm.ctr.dsdb.num_mappings = schema->num_prefixes;
370 pm.ctr.dsdb.mappings = talloc_array(msg,
371 struct drsuapi_DsReplicaOIDMapping,
372 pm.ctr.dsdb.num_mappings);
373 if (!pm.ctr.dsdb.mappings) {
378 for (i=0; i < schema->num_prefixes; i++) {
381 if (!ber_write_partial_OID_String(pm.ctr.dsdb.mappings, &oid_blob, schema->prefixes[i].oid)) {
382 DEBUG(0, ("write_partial_OID failed for %s", schema->prefixes[i].oid));
383 return WERR_INTERNAL_ERROR;
386 pm.ctr.dsdb.mappings[i].id_prefix = schema->prefixes[i].id>>16;
387 pm.ctr.dsdb.mappings[i].oid.length = oid_blob.length;
388 pm.ctr.dsdb.mappings[i].oid.binary_oid = oid_blob.data;
391 ndr_err = ndr_push_struct_blob(&ndr_blob, msg,
392 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
394 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
395 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
401 ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL);
404 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
408 ret = samdb_replace( ldb, msg, msg );
412 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: samdb_replace failed\n"));
419 static WERROR dsdb_read_prefixes_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, uint32_t* num_prefixes, struct dsdb_schema_oid_prefix **prefixes)
421 struct prefixMapBlob *blob;
422 enum ndr_err_code ndr_err;
424 const struct ldb_val *prefix_val;
425 struct ldb_dn *schema_dn;
426 struct ldb_result *schema_res = NULL;
428 static const char *schema_attrs[] = {
433 schema_dn = samdb_schema_dn(ldb);
435 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
439 ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
440 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
441 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
442 talloc_free(schema_res);
444 } else if (ret != LDB_SUCCESS) {
445 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
446 talloc_free(schema_res);
450 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
452 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
453 talloc_free(schema_res);
457 blob = talloc(mem_ctx, struct prefixMapBlob);
458 W_ERROR_HAVE_NO_MEMORY(blob);
460 ndr_err = ndr_pull_struct_blob(prefix_val, blob,
461 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
463 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
464 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
465 DEBUG(0,("dsdb_read_prefixes_from_ldb: ndr_pull_struct_blob failed\n"));
467 talloc_free(schema_res);
471 talloc_free(schema_res);
473 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
474 DEBUG(0,("dsdb_read_prefixes_from_ldb: blob->version incorect\n"));
479 *num_prefixes = blob->ctr.dsdb.num_mappings;
480 *prefixes = talloc_array(mem_ctx, struct dsdb_schema_oid_prefix, *num_prefixes);
485 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
487 const char *partial_oid;
489 oid_blob = data_blob_const(blob->ctr.dsdb.mappings[i].oid.binary_oid,
490 blob->ctr.dsdb.mappings[i].oid.length);
492 if (!ber_read_partial_OID_String(mem_ctx, oid_blob, &partial_oid)) {
493 DEBUG(0, ("ber_read_partial_OID failed on prefixMap item with id: 0x%X",
494 blob->ctr.dsdb.mappings[i].id_prefix));
496 return WERR_INVALID_PARAM;
499 (*prefixes)[i].id = blob->ctr.dsdb.mappings[i].id_prefix<<16;
500 (*prefixes)[i].oid = partial_oid;
501 (*prefixes)[i].oid_len = strlen((*prefixes)[i].oid);
509 this will be replaced with something that looks at the right part of
510 the schema once we know where unique indexing information is hidden
512 static bool dsdb_schema_unique_attribute(const char *attr)
514 const char *attrs[] = { "objectGUID", "objectSID" , NULL };
516 for (i=0;attrs[i];i++) {
517 if (strcasecmp(attr, attrs[i]) == 0) {
526 setup the ldb_schema_attribute field for a dsdb_attribute
528 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context *ldb,
529 struct dsdb_attribute *attr)
531 const char *syntax = attr->syntax->ldb_syntax;
532 const struct ldb_schema_syntax *s;
533 struct ldb_schema_attribute *a;
536 syntax = attr->syntax->ldap_oid;
539 s = ldb_samba_syntax_by_lDAPDisplayName(ldb, attr->lDAPDisplayName);
541 s = ldb_samba_syntax_by_name(ldb, syntax);
544 s = ldb_standard_syntax_by_name(ldb, syntax);
548 return LDB_ERR_OPERATIONS_ERROR;
551 attr->ldb_schema_attribute = a = talloc(attr, struct ldb_schema_attribute);
552 if (attr->ldb_schema_attribute == NULL) {
554 return LDB_ERR_OPERATIONS_ERROR;
557 a->name = attr->lDAPDisplayName;
561 if (dsdb_schema_unique_attribute(a->name)) {
562 a->flags |= LDB_ATTR_FLAG_UNIQUE_INDEX;
564 if (attr->isSingleValued) {
565 a->flags |= LDB_ATTR_FLAG_SINGLE_VALUE;
573 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
574 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
575 if (get_string_val == NULL) { \
577 d_printf("%s: %s == NULL\n", __location__, attr); \
578 return WERR_INVALID_PARAM; \
583 (p)->elem = talloc_strndup(mem_ctx, \
584 (const char *)get_string_val->data, \
585 get_string_val->length); \
587 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
593 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
594 int get_string_list_counter; \
595 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
596 if (get_string_list_el == NULL) { \
598 d_printf("%s: %s == NULL\n", __location__, attr); \
599 return WERR_INVALID_PARAM; \
605 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
606 for (get_string_list_counter=0; \
607 get_string_list_counter < get_string_list_el->num_values; \
608 get_string_list_counter++) { \
609 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
610 (const char *)get_string_list_el->values[get_string_list_counter].data, \
611 get_string_list_el->values[get_string_list_counter].length); \
612 if (!(p)->elem[get_string_list_counter]) { \
613 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
616 (p)->elem[get_string_list_counter+1] = NULL; \
618 talloc_steal(mem_ctx, (p)->elem); \
621 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
623 str = samdb_result_string(msg, attr, NULL);\
626 d_printf("%s: %s == NULL\n", __location__, attr); \
627 return WERR_INVALID_PARAM; \
631 } else if (strcasecmp("TRUE", str) == 0) { \
633 } else if (strcasecmp("FALSE", str) == 0) { \
636 d_printf("%s: %s == %s\n", __location__, attr, str); \
637 return WERR_INVALID_PARAM; \
641 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
642 (p)->elem = samdb_result_uint(msg, attr, 0);\
645 #define GET_UINT32_PTR_LDB(msg, attr, p, elem) do { \
646 uint64_t _v = samdb_result_uint64(msg, attr, UINT64_MAX);\
647 if (_v == UINT64_MAX) { \
649 } else if (_v > UINT32_MAX) { \
650 d_printf("%s: %s == 0x%llX\n", __location__, \
651 attr, (unsigned long long)_v); \
652 return WERR_INVALID_PARAM; \
654 (p)->elem = talloc(mem_ctx, uint32_t); \
656 d_printf("%s: talloc failed for %s\n", __location__, attr); \
659 *(p)->elem = (uint32_t)_v; \
663 #define GET_GUID_LDB(msg, attr, p, elem) do { \
664 (p)->elem = samdb_result_guid(msg, attr);\
667 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
668 const struct ldb_val *_val;\
669 _val = ldb_msg_find_ldb_val(msg, attr);\
672 talloc_steal(mem_ctx, (p)->elem.data);\
674 ZERO_STRUCT((p)->elem);\
678 WERROR dsdb_attribute_from_ldb(struct ldb_context *ldb,
679 const struct dsdb_schema *schema,
680 struct ldb_message *msg,
682 struct dsdb_attribute *attr)
686 GET_STRING_LDB(msg, "cn", mem_ctx, attr, cn, false);
687 GET_STRING_LDB(msg, "lDAPDisplayName", mem_ctx, attr, lDAPDisplayName, true);
688 GET_STRING_LDB(msg, "attributeID", mem_ctx, attr, attributeID_oid, true);
689 if (schema->num_prefixes == 0) {
690 /* set an invalid value */
691 attr->attributeID_id = 0xFFFFFFFF;
693 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
694 attr->attributeID_oid,
695 &attr->attributeID_id);
696 if (!W_ERROR_IS_OK(status)) {
697 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
698 __location__, attr->lDAPDisplayName, attr->attributeID_oid,
699 win_errstr(status)));
703 GET_GUID_LDB(msg, "schemaIDGUID", attr, schemaIDGUID);
704 GET_UINT32_LDB(msg, "mAPIID", attr, mAPIID);
706 GET_GUID_LDB(msg, "attributeSecurityGUID", attr, attributeSecurityGUID);
708 GET_UINT32_LDB(msg, "searchFlags", attr, searchFlags);
709 GET_UINT32_LDB(msg, "systemFlags", attr, systemFlags);
710 GET_BOOL_LDB(msg, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
711 GET_UINT32_LDB(msg, "linkID", attr, linkID);
713 GET_STRING_LDB(msg, "attributeSyntax", mem_ctx, attr, attributeSyntax_oid, true);
714 if (schema->num_prefixes == 0) {
715 /* set an invalid value */
716 attr->attributeSyntax_id = 0xFFFFFFFF;
718 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
719 attr->attributeSyntax_oid,
720 &attr->attributeSyntax_id);
721 if (!W_ERROR_IS_OK(status)) {
722 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
723 __location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
724 win_errstr(status)));
728 GET_UINT32_LDB(msg, "oMSyntax", attr, oMSyntax);
729 GET_BLOB_LDB(msg, "oMObjectClass", mem_ctx, attr, oMObjectClass);
731 GET_BOOL_LDB(msg, "isSingleValued", attr, isSingleValued, true);
732 GET_UINT32_PTR_LDB(msg, "rangeLower", attr, rangeLower);
733 GET_UINT32_PTR_LDB(msg, "rangeUpper", attr, rangeUpper);
734 GET_BOOL_LDB(msg, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
736 GET_UINT32_LDB(msg, "schemaFlagsEx", attr, schemaFlagsEx);
737 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", mem_ctx, attr, msDs_Schema_Extensions);
739 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
740 GET_STRING_LDB(msg, "adminDisplayName", mem_ctx, attr, adminDisplayName, false);
741 GET_STRING_LDB(msg, "adminDescription", mem_ctx, attr, adminDescription, false);
742 GET_STRING_LDB(msg, "classDisplayName", mem_ctx, attr, classDisplayName, false);
743 GET_BOOL_LDB(msg, "isEphemeral", attr, isEphemeral, false);
744 GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
745 GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
747 attr->syntax = dsdb_syntax_for_attribute(attr);
749 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
752 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
753 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
759 WERROR dsdb_class_from_ldb(const struct dsdb_schema *schema,
760 struct ldb_message *msg,
762 struct dsdb_class *obj)
766 GET_STRING_LDB(msg, "cn", mem_ctx, obj, cn, false);
767 GET_STRING_LDB(msg, "lDAPDisplayName", mem_ctx, obj, lDAPDisplayName, true);
768 GET_STRING_LDB(msg, "governsID", mem_ctx, obj, governsID_oid, true);
769 if (schema->num_prefixes == 0) {
770 /* set an invalid value */
771 obj->governsID_id = 0xFFFFFFFF;
773 status = dsdb_schema_pfm_make_attid(schema->prefixmap,
776 if (!W_ERROR_IS_OK(status)) {
777 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
778 __location__, obj->lDAPDisplayName, obj->governsID_oid,
779 win_errstr(status)));
783 GET_GUID_LDB(msg, "schemaIDGUID", obj, schemaIDGUID);
785 GET_UINT32_LDB(msg, "objectClassCategory", obj, objectClassCategory);
786 GET_STRING_LDB(msg, "rDNAttID", mem_ctx, obj, rDNAttID, false);
787 GET_STRING_LDB(msg, "defaultObjectCategory", mem_ctx, obj, defaultObjectCategory, true);
789 GET_STRING_LDB(msg, "subClassOf", mem_ctx, obj, subClassOf, true);
791 GET_STRING_LIST_LDB(msg, "systemAuxiliaryClass", mem_ctx, obj, systemAuxiliaryClass, false);
792 GET_STRING_LIST_LDB(msg, "auxiliaryClass", mem_ctx, obj, auxiliaryClass, false);
794 GET_STRING_LIST_LDB(msg, "systemMustContain", mem_ctx, obj, systemMustContain, false);
795 GET_STRING_LIST_LDB(msg, "systemMayContain", mem_ctx, obj, systemMayContain, false);
796 GET_STRING_LIST_LDB(msg, "mustContain", mem_ctx, obj, mustContain, false);
797 GET_STRING_LIST_LDB(msg, "mayContain", mem_ctx, obj, mayContain, false);
799 GET_STRING_LIST_LDB(msg, "systemPossSuperiors", mem_ctx, obj, systemPossSuperiors, false);
800 GET_STRING_LIST_LDB(msg, "possSuperiors", mem_ctx, obj, possSuperiors, false);
802 GET_STRING_LDB(msg, "defaultSecurityDescriptor", mem_ctx, obj, defaultSecurityDescriptor, false);
804 GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
805 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", mem_ctx, obj, msDs_Schema_Extensions);
807 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
808 GET_STRING_LDB(msg, "adminDisplayName", mem_ctx, obj, adminDisplayName, false);
809 GET_STRING_LDB(msg, "adminDescription", mem_ctx, obj, adminDescription, false);
810 GET_STRING_LDB(msg, "classDisplayName", mem_ctx, obj, classDisplayName, false);
811 GET_BOOL_LDB(msg, "defaultHidingValue", obj, defaultHidingValue, false);
812 GET_BOOL_LDB(msg, "isDefunct", obj, isDefunct, false);
813 GET_BOOL_LDB(msg, "systemOnly", obj, systemOnly, false);
818 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
821 Create a DSDB schema from the ldb results provided. This is called
822 directly when the schema is provisioned from an on-disk LDIF file, or
823 from dsdb_schema_from_schema_dn in schema_fsmo
826 int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
827 struct smb_iconv_convenience *iconv_convenience,
828 struct ldb_result *schema_res,
829 struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
830 struct dsdb_schema **schema_out,
835 const struct ldb_val *prefix_val;
836 const struct ldb_val *info_val;
837 struct ldb_val info_val_default;
838 struct dsdb_schema *schema;
840 schema = dsdb_new_schema(mem_ctx, iconv_convenience);
842 dsdb_oom(error_string, mem_ctx);
843 return LDB_ERR_OPERATIONS_ERROR;
846 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
848 *error_string = talloc_asprintf(mem_ctx,
849 "schema_fsmo_init: no prefixMap attribute found");
850 DEBUG(0,(__location__ ": %s\n", *error_string));
851 return LDB_ERR_CONSTRAINT_VIOLATION;
853 info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
855 info_val_default = strhex_to_data_blob(mem_ctx, "FF0000000000000000000000000000000000000000");
856 if (!info_val_default.data) {
857 dsdb_oom(error_string, mem_ctx);
858 return LDB_ERR_OPERATIONS_ERROR;
860 info_val = &info_val_default;
863 status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
864 if (!W_ERROR_IS_OK(status)) {
865 *error_string = talloc_asprintf(mem_ctx,
866 "schema_fsmo_init: failed to load oid mappings: %s",
868 DEBUG(0,(__location__ ": %s\n", *error_string));
869 return LDB_ERR_CONSTRAINT_VIOLATION;
872 for (i=0; i < attrs_res->count; i++) {
873 struct dsdb_attribute *sa;
875 sa = talloc_zero(schema, struct dsdb_attribute);
877 dsdb_oom(error_string, mem_ctx);
878 return LDB_ERR_OPERATIONS_ERROR;
881 status = dsdb_attribute_from_ldb(ldb, schema, attrs_res->msgs[i], sa, sa);
882 if (!W_ERROR_IS_OK(status)) {
883 *error_string = talloc_asprintf(mem_ctx,
884 "schema_fsmo_init: failed to load attribute definition: %s:%s",
885 ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
887 DEBUG(0,(__location__ ": %s\n", *error_string));
888 return LDB_ERR_CONSTRAINT_VIOLATION;
891 DLIST_ADD(schema->attributes, sa);
894 for (i=0; i < objectclass_res->count; i++) {
895 struct dsdb_class *sc;
897 sc = talloc_zero(schema, struct dsdb_class);
899 dsdb_oom(error_string, mem_ctx);
900 return LDB_ERR_OPERATIONS_ERROR;
903 status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i], sc, sc);
904 if (!W_ERROR_IS_OK(status)) {
905 *error_string = talloc_asprintf(mem_ctx,
906 "schema_fsmo_init: failed to load class definition: %s:%s",
907 ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
909 DEBUG(0,(__location__ ": %s\n", *error_string));
910 return LDB_ERR_CONSTRAINT_VIOLATION;
913 DLIST_ADD(schema->classes, sc);
916 schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
917 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
918 schema->fsmo.we_are_master = true;
920 schema->fsmo.we_are_master = false;
923 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
924 (schema->fsmo.we_are_master?"yes":"no")));
926 *schema_out = schema;
931 static const struct {
934 } name_mappings[] = {
936 { "name", "1.2.840.113556.1.4.1" },
937 { "lDAPDisplayName", "1.2.840.113556.1.2.460" },
938 { "attributeID", "1.2.840.113556.1.2.30" },
939 { "schemaIDGUID", "1.2.840.113556.1.4.148" },
940 { "mAPIID", "1.2.840.113556.1.2.49" },
941 { "attributeSecurityGUID", "1.2.840.113556.1.4.149" },
942 { "searchFlags", "1.2.840.113556.1.2.334" },
943 { "systemFlags", "1.2.840.113556.1.4.375" },
944 { "isMemberOfPartialAttributeSet", "1.2.840.113556.1.4.639" },
945 { "linkID", "1.2.840.113556.1.2.50" },
946 { "attributeSyntax", "1.2.840.113556.1.2.32" },
947 { "oMSyntax", "1.2.840.113556.1.2.231" },
948 { "oMObjectClass", "1.2.840.113556.1.2.218" },
949 { "isSingleValued", "1.2.840.113556.1.2.33" },
950 { "rangeLower", "1.2.840.113556.1.2.34" },
951 { "rangeUpper", "1.2.840.113556.1.2.35" },
952 { "extendedCharsAllowed", "1.2.840.113556.1.2.380" },
953 { "schemaFlagsEx", "1.2.840.113556.1.4.120" },
954 { "msDs-Schema-Extensions", "1.2.840.113556.1.4.1440" },
955 { "showInAdvancedViewOnly", "1.2.840.113556.1.2.169" },
956 { "adminDisplayName", "1.2.840.113556.1.2.194" },
957 { "adminDescription", "1.2.840.113556.1.2.226" },
958 { "classDisplayName", "1.2.840.113556.1.4.610" },
959 { "isEphemeral", "1.2.840.113556.1.4.1212" },
960 { "isDefunct", "1.2.840.113556.1.4.661" },
961 { "systemOnly", "1.2.840.113556.1.4.170" },
962 { "governsID", "1.2.840.113556.1.2.22" },
963 { "objectClassCategory", "1.2.840.113556.1.2.370" },
964 { "rDNAttID", "1.2.840.113556.1.2.26" },
965 { "defaultObjectCategory", "1.2.840.113556.1.4.783" },
966 { "subClassOf", "1.2.840.113556.1.2.21" },
967 { "systemAuxiliaryClass", "1.2.840.113556.1.4.198" },
968 { "systemPossSuperiors", "1.2.840.113556.1.4.195" },
969 { "systemMustContain", "1.2.840.113556.1.4.197" },
970 { "systemMayContain", "1.2.840.113556.1.4.196" },
971 { "auxiliaryClass", "1.2.840.113556.1.2.351" },
972 { "possSuperiors", "1.2.840.113556.1.2.8" },
973 { "mustContain", "1.2.840.113556.1.2.24" },
974 { "mayContain", "1.2.840.113556.1.2.25" },
975 { "defaultSecurityDescriptor", "1.2.840.113556.1.4.224" },
976 { "defaultHidingValue", "1.2.840.113556.1.4.518" },
979 static struct drsuapi_DsReplicaAttribute *dsdb_find_object_attr_name(struct dsdb_schema *schema,
980 struct drsuapi_DsReplicaObject *obj,
986 const char *oid = NULL;
988 for(i=0; i < ARRAY_SIZE(name_mappings); i++) {
989 if (strcmp(name_mappings[i].name, name) != 0) continue;
991 oid = name_mappings[i].oid;
999 status = dsdb_schema_pfm_make_attid(schema->prefixmap, oid, &attid);
1000 if (!W_ERROR_IS_OK(status)) {
1004 for (i=0; i < obj->attribute_ctr.num_attributes; i++) {
1005 if (obj->attribute_ctr.attributes[i].attid != attid) continue;
1008 return &obj->attribute_ctr.attributes[i];
1014 #define GET_STRING_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1015 struct drsuapi_DsReplicaAttribute *_a; \
1016 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1017 if (strict && !_a) { \
1018 d_printf("%s: %s == NULL\n", __location__, attr); \
1019 return WERR_INVALID_PARAM; \
1021 if (strict && _a->value_ctr.num_values != 1) { \
1022 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1023 _a->value_ctr.num_values); \
1024 return WERR_INVALID_PARAM; \
1026 if (_a && _a->value_ctr.num_values >= 1) { \
1028 if (!convert_string_talloc_convenience(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \
1029 _a->value_ctr.values[0].blob->data, \
1030 _a->value_ctr.values[0].blob->length, \
1031 (void **)discard_const(&(p)->elem), &_ret, false)) { \
1032 DEBUG(0,("%s: invalid data!\n", attr)); \
1034 _a->value_ctr.values[0].blob->data, \
1035 _a->value_ctr.values[0].blob->length); \
1036 return WERR_FOOBAR; \
1043 #define GET_UINT32_LIST_DS(s, r, attr, mem_ctx, p, elem) do { \
1045 struct drsuapi_DsReplicaAttribute *_a; \
1046 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1047 (p)->elem = _a ? talloc_array(mem_ctx, uint32_t, _a->value_ctr.num_values + 1) : NULL; \
1048 for (list_counter=0; \
1049 _a && list_counter < _a->value_ctr.num_values; \
1051 if (_a->value_ctr.values[list_counter].blob->length != 4) { \
1052 return WERR_INVALID_PARAM; \
1054 (p)->elem[list_counter] = IVAL(_a->value_ctr.values[list_counter].blob->data, 0); \
1056 if (_a) (p)->elem[list_counter] = 0; \
1059 #define GET_DN_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1060 struct drsuapi_DsReplicaAttribute *_a; \
1061 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1062 if (strict && !_a) { \
1063 d_printf("%s: %s == NULL\n", __location__, attr); \
1064 return WERR_INVALID_PARAM; \
1066 if (strict && _a->value_ctr.num_values != 1) { \
1067 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1068 _a->value_ctr.num_values); \
1069 return WERR_INVALID_PARAM; \
1071 if (strict && !_a->value_ctr.values[0].blob) { \
1072 d_printf("%s: %s data == NULL\n", __location__, attr); \
1073 return WERR_INVALID_PARAM; \
1075 if (_a && _a->value_ctr.num_values >= 1 \
1076 && _a->value_ctr.values[0].blob) { \
1077 struct drsuapi_DsReplicaObjectIdentifier3 _id3; \
1078 enum ndr_err_code _ndr_err; \
1079 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1080 mem_ctx, s->iconv_convenience, &_id3,\
1081 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);\
1082 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1083 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1084 return ntstatus_to_werror(_nt_status); \
1086 (p)->elem = _id3.dn; \
1092 #define GET_BOOL_DS(s, r, attr, p, elem, strict) do { \
1093 struct drsuapi_DsReplicaAttribute *_a; \
1094 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1095 if (strict && !_a) { \
1096 d_printf("%s: %s == NULL\n", __location__, attr); \
1097 return WERR_INVALID_PARAM; \
1099 if (strict && _a->value_ctr.num_values != 1) { \
1100 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1101 (unsigned int)_a->value_ctr.num_values); \
1102 return WERR_INVALID_PARAM; \
1104 if (strict && !_a->value_ctr.values[0].blob) { \
1105 d_printf("%s: %s data == NULL\n", __location__, attr); \
1106 return WERR_INVALID_PARAM; \
1108 if (strict && _a->value_ctr.values[0].blob->length != 4) { \
1109 d_printf("%s: %s length == %u\n", __location__, attr, \
1110 (unsigned int)_a->value_ctr.values[0].blob->length); \
1111 return WERR_INVALID_PARAM; \
1113 if (_a && _a->value_ctr.num_values >= 1 \
1114 && _a->value_ctr.values[0].blob \
1115 && _a->value_ctr.values[0].blob->length == 4) { \
1116 (p)->elem = (IVAL(_a->value_ctr.values[0].blob->data,0)?true:false);\
1118 (p)->elem = false; \
1122 #define GET_UINT32_DS(s, r, attr, p, elem) do { \
1123 struct drsuapi_DsReplicaAttribute *_a; \
1124 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1125 if (_a && _a->value_ctr.num_values >= 1 \
1126 && _a->value_ctr.values[0].blob \
1127 && _a->value_ctr.values[0].blob->length == 4) { \
1128 (p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1134 #define GET_UINT32_PTR_DS(s, r, attr, p, elem) do { \
1135 struct drsuapi_DsReplicaAttribute *_a; \
1136 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1137 if (_a && _a->value_ctr.num_values >= 1 \
1138 && _a->value_ctr.values[0].blob \
1139 && _a->value_ctr.values[0].blob->length == 4) { \
1140 (p)->elem = talloc(mem_ctx, uint32_t); \
1142 d_printf("%s: talloc failed for %s\n", __location__, attr); \
1143 return WERR_NOMEM; \
1145 *(p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1151 #define GET_GUID_DS(s, r, attr, mem_ctx, p, elem) do { \
1152 struct drsuapi_DsReplicaAttribute *_a; \
1153 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1154 if (_a && _a->value_ctr.num_values >= 1 \
1155 && _a->value_ctr.values[0].blob \
1156 && _a->value_ctr.values[0].blob->length == 16) { \
1157 enum ndr_err_code _ndr_err; \
1158 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1159 mem_ctx, s->iconv_convenience, &(p)->elem, \
1160 (ndr_pull_flags_fn_t)ndr_pull_GUID); \
1161 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1162 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1163 return ntstatus_to_werror(_nt_status); \
1166 ZERO_STRUCT((p)->elem);\
1170 #define GET_BLOB_DS(s, r, attr, mem_ctx, p, elem) do { \
1171 struct drsuapi_DsReplicaAttribute *_a; \
1172 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1173 if (_a && _a->value_ctr.num_values >= 1 \
1174 && _a->value_ctr.values[0].blob) { \
1175 (p)->elem = *_a->value_ctr.values[0].blob;\
1176 talloc_steal(mem_ctx, (p)->elem.data); \
1178 ZERO_STRUCT((p)->elem);\
1182 WERROR dsdb_attribute_from_drsuapi(struct ldb_context *ldb,
1183 struct dsdb_schema *schema,
1184 struct drsuapi_DsReplicaObject *r,
1185 TALLOC_CTX *mem_ctx,
1186 struct dsdb_attribute *attr)
1190 GET_STRING_DS(schema, r, "name", mem_ctx, attr, cn, true);
1191 GET_STRING_DS(schema, r, "lDAPDisplayName", mem_ctx, attr, lDAPDisplayName, true);
1192 GET_UINT32_DS(schema, r, "attributeID", attr, attributeID_id);
1193 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attr->attributeID_id,
1194 mem_ctx, &attr->attributeID_oid);
1195 if (!W_ERROR_IS_OK(status)) {
1196 DEBUG(0,("%s: '%s': unable to map attributeID 0x%08X: %s\n",
1197 __location__, attr->lDAPDisplayName, attr->attributeID_id,
1198 win_errstr(status)));
1201 GET_GUID_DS(schema, r, "schemaIDGUID", mem_ctx, attr, schemaIDGUID);
1202 GET_UINT32_DS(schema, r, "mAPIID", attr, mAPIID);
1204 GET_GUID_DS(schema, r, "attributeSecurityGUID", mem_ctx, attr, attributeSecurityGUID);
1206 GET_UINT32_DS(schema, r, "searchFlags", attr, searchFlags);
1207 GET_UINT32_DS(schema, r, "systemFlags", attr, systemFlags);
1208 GET_BOOL_DS(schema, r, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
1209 GET_UINT32_DS(schema, r, "linkID", attr, linkID);
1211 GET_UINT32_DS(schema, r, "attributeSyntax", attr, attributeSyntax_id);
1212 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, attr->attributeSyntax_id,
1213 mem_ctx, &attr->attributeSyntax_oid);
1214 if (!W_ERROR_IS_OK(status)) {
1215 DEBUG(0,("%s: '%s': unable to map attributeSyntax 0x%08X: %s\n",
1216 __location__, attr->lDAPDisplayName, attr->attributeSyntax_id,
1217 win_errstr(status)));
1220 GET_UINT32_DS(schema, r, "oMSyntax", attr, oMSyntax);
1221 GET_BLOB_DS(schema, r, "oMObjectClass", mem_ctx, attr, oMObjectClass);
1223 GET_BOOL_DS(schema, r, "isSingleValued", attr, isSingleValued, true);
1224 GET_UINT32_PTR_DS(schema, r, "rangeLower", attr, rangeLower);
1225 GET_UINT32_PTR_DS(schema, r, "rangeUpper", attr, rangeUpper);
1226 GET_BOOL_DS(schema, r, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
1228 GET_UINT32_DS(schema, r, "schemaFlagsEx", attr, schemaFlagsEx);
1229 GET_BLOB_DS(schema, r, "msDs-Schema-Extensions", mem_ctx, attr, msDs_Schema_Extensions);
1231 GET_BOOL_DS(schema, r, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
1232 GET_STRING_DS(schema, r, "adminDisplayName", mem_ctx, attr, adminDisplayName, false);
1233 GET_STRING_DS(schema, r, "adminDescription", mem_ctx, attr, adminDescription, false);
1234 GET_STRING_DS(schema, r, "classDisplayName", mem_ctx, attr, classDisplayName, false);
1235 GET_BOOL_DS(schema, r, "isEphemeral", attr, isEphemeral, false);
1236 GET_BOOL_DS(schema, r, "isDefunct", attr, isDefunct, false);
1237 GET_BOOL_DS(schema, r, "systemOnly", attr, systemOnly, false);
1239 attr->syntax = dsdb_syntax_for_attribute(attr);
1240 if (!attr->syntax) {
1241 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
1244 if (dsdb_schema_setup_ldb_schema_attribute(ldb, attr) != LDB_SUCCESS) {
1245 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
1251 WERROR dsdb_class_from_drsuapi(struct dsdb_schema *schema,
1252 struct drsuapi_DsReplicaObject *r,
1253 TALLOC_CTX *mem_ctx,
1254 struct dsdb_class *obj)
1258 GET_STRING_DS(schema, r, "name", mem_ctx, obj, cn, true);
1259 GET_STRING_DS(schema, r, "lDAPDisplayName", mem_ctx, obj, lDAPDisplayName, true);
1260 GET_UINT32_DS(schema, r, "governsID", obj, governsID_id);
1261 status = dsdb_schema_pfm_oid_from_attid(schema->prefixmap, obj->governsID_id,
1262 mem_ctx, &obj->governsID_oid);
1263 if (!W_ERROR_IS_OK(status)) {
1264 DEBUG(0,("%s: '%s': unable to map governsID 0x%08X: %s\n",
1265 __location__, obj->lDAPDisplayName, obj->governsID_id,
1266 win_errstr(status)));
1269 GET_GUID_DS(schema, r, "schemaIDGUID", mem_ctx, obj, schemaIDGUID);
1271 GET_UINT32_DS(schema, r, "objectClassCategory", obj, objectClassCategory);
1272 GET_STRING_DS(schema, r, "rDNAttID", mem_ctx, obj, rDNAttID, false);
1273 GET_DN_DS(schema, r, "defaultObjectCategory", mem_ctx, obj, defaultObjectCategory, true);
1275 GET_UINT32_DS(schema, r, "subClassOf", obj, subClassOf_id);
1277 GET_UINT32_LIST_DS(schema, r, "systemAuxiliaryClass", mem_ctx, obj, systemAuxiliaryClass_ids);
1278 GET_UINT32_LIST_DS(schema, r, "auxiliaryClass", mem_ctx, obj, auxiliaryClass_ids);
1280 GET_UINT32_LIST_DS(schema, r, "systemMustContain", mem_ctx, obj, systemMustContain_ids);
1281 GET_UINT32_LIST_DS(schema, r, "systemMayContain", mem_ctx, obj, systemMayContain_ids);
1282 GET_UINT32_LIST_DS(schema, r, "mustContain", mem_ctx, obj, mustContain_ids);
1283 GET_UINT32_LIST_DS(schema, r, "mayContain", mem_ctx, obj, mayContain_ids);
1285 GET_UINT32_LIST_DS(schema, r, "systemPossSuperiors", mem_ctx, obj, systemPossSuperiors_ids);
1286 GET_UINT32_LIST_DS(schema, r, "possSuperiors", mem_ctx, obj, possSuperiors_ids);
1288 GET_STRING_DS(schema, r, "defaultSecurityDescriptor", mem_ctx, obj, defaultSecurityDescriptor, false);
1290 GET_UINT32_DS(schema, r, "schemaFlagsEx", obj, schemaFlagsEx);
1291 GET_BLOB_DS(schema, r, "msDs-Schema-Extensions", mem_ctx, obj, msDs_Schema_Extensions);
1293 GET_BOOL_DS(schema, r, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
1294 GET_STRING_DS(schema, r, "adminDisplayName", mem_ctx, obj, adminDisplayName, false);
1295 GET_STRING_DS(schema, r, "adminDescription", mem_ctx, obj, adminDescription, false);
1296 GET_STRING_DS(schema, r, "classDisplayName", mem_ctx, obj, classDisplayName, false);
1297 GET_BOOL_DS(schema, r, "defaultHidingValue", obj, defaultHidingValue, false);
1298 GET_BOOL_DS(schema, r, "isDefunct", obj, isDefunct, false);
1299 GET_BOOL_DS(schema, r, "systemOnly", obj, systemOnly, false);