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 WERROR
dsdb_load_oid_mappings_ldb(struct dsdb_schema
*schema
,
69 const struct ldb_val
*prefixMap
,
70 const struct ldb_val
*schemaInfo
)
73 enum ndr_err_code ndr_err
;
74 struct prefixMapBlob pfm
;
75 DATA_BLOB schema_info_blob
;
77 TALLOC_CTX
*mem_ctx
= talloc_new(schema
);
78 W_ERROR_HAVE_NO_MEMORY(mem_ctx
);
80 ndr_err
= ndr_pull_struct_blob(prefixMap
, mem_ctx
, schema
->iconv_convenience
, &pfm
, (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
);
84 return ntstatus_to_werror(nt_status
);
87 if (pfm
.version
!= PREFIX_MAP_VERSION_DSDB
) {
92 if (schemaInfo
->length
!= 21 && schemaInfo
->data
[0] == 0xFF) {
97 /* append the schema info as last element */
98 pfm
.ctr
.dsdb
.num_mappings
++;
99 pfm
.ctr
.dsdb
.mappings
= talloc_realloc(mem_ctx
, pfm
.ctr
.dsdb
.mappings
,
100 struct drsuapi_DsReplicaOIDMapping
,
101 pfm
.ctr
.dsdb
.num_mappings
);
102 W_ERROR_HAVE_NO_MEMORY(pfm
.ctr
.dsdb
.mappings
);
104 schema_info_blob
= data_blob_dup_talloc(pfm
.ctr
.dsdb
.mappings
, schemaInfo
);
105 W_ERROR_HAVE_NO_MEMORY(schema_info_blob
.data
);
107 pfm
.ctr
.dsdb
.mappings
[pfm
.ctr
.dsdb
.num_mappings
- 1].id_prefix
= 0;
108 pfm
.ctr
.dsdb
.mappings
[pfm
.ctr
.dsdb
.num_mappings
- 1].oid
.length
= schemaInfo
->length
;
109 pfm
.ctr
.dsdb
.mappings
[pfm
.ctr
.dsdb
.num_mappings
- 1].oid
.binary_oid
= schema_info_blob
.data
;
111 /* call the drsuapi version */
112 status
= dsdb_load_prefixmap_from_drsuapi(schema
, &pfm
.ctr
.dsdb
);
113 talloc_free(mem_ctx
);
115 W_ERROR_NOT_OK_RETURN(status
);
120 WERROR
dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema
*schema
,
121 bool include_schema_info
,
123 struct drsuapi_DsReplicaOIDMapping_Ctr
**_ctr
)
125 return dsdb_drsuapi_pfm_from_schema_pfm(schema
->prefixmap
,
126 include_schema_info
? schema
->schema_info
: NULL
,
130 WERROR
dsdb_get_oid_mappings_ldb(const struct dsdb_schema
*schema
,
132 struct ldb_val
*prefixMap
,
133 struct ldb_val
*schemaInfo
)
136 enum ndr_err_code ndr_err
;
137 struct drsuapi_DsReplicaOIDMapping_Ctr
*ctr
;
138 struct prefixMapBlob pfm
;
140 status
= dsdb_get_oid_mappings_drsuapi(schema
, false, mem_ctx
, &ctr
);
141 W_ERROR_NOT_OK_RETURN(status
);
143 pfm
.version
= PREFIX_MAP_VERSION_DSDB
;
147 ndr_err
= ndr_push_struct_blob(prefixMap
, mem_ctx
, schema
->iconv_convenience
, &pfm
, (ndr_push_flags_fn_t
)ndr_push_prefixMapBlob
);
149 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
150 NTSTATUS nt_status
= ndr_map_error2ntstatus(ndr_err
);
151 return ntstatus_to_werror(nt_status
);
154 *schemaInfo
= strhex_to_data_blob(mem_ctx
, schema
->schema_info
);
155 W_ERROR_HAVE_NO_MEMORY(schemaInfo
->data
);
162 * this function is called from within a ldb transaction from the schema_fsmo module
164 WERROR
dsdb_create_prefix_mapping(struct ldb_context
*ldb
, struct dsdb_schema
*schema
, const char *full_oid
)
167 uint32_t num_prefixes
;
168 struct dsdb_schema_oid_prefix
*prefixes
;
172 mem_ctx
= talloc_new(ldb
);
173 W_ERROR_HAVE_NO_MEMORY(mem_ctx
);
175 /* Read prefixes from disk*/
176 status
= dsdb_read_prefixes_from_ldb( mem_ctx
, ldb
, &num_prefixes
, &prefixes
);
177 if (!W_ERROR_IS_OK(status
)) {
178 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
179 win_errstr(status
)));
180 talloc_free(mem_ctx
);
184 /* Check if there is a prefix for the oid in the prefixes array*/
185 status
= dsdb_find_prefix_for_oid( num_prefixes
, prefixes
, full_oid
, &out
);
186 if (W_ERROR_IS_OK(status
)) {
188 talloc_free(mem_ctx
);
190 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID
, status
)) {
192 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
193 win_errstr(status
)));
194 talloc_free(mem_ctx
);
198 /* Create the new mapping for the prefix of full_oid */
199 status
= dsdb_prefix_map_update(mem_ctx
, &num_prefixes
, &prefixes
, full_oid
);
200 if (!W_ERROR_IS_OK(status
)) {
201 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_prefix_map_update: %s\n",
202 win_errstr(status
)));
203 talloc_free(mem_ctx
);
207 talloc_free(schema
->prefixes
);
208 schema
->prefixes
= talloc_steal(schema
, prefixes
);
209 schema
->num_prefixes
= num_prefixes
;
211 /* Update prefixMap in ldb*/
212 status
= dsdb_write_prefixes_from_schema_to_ldb(mem_ctx
, ldb
, schema
);
213 if (!W_ERROR_IS_OK(status
)) {
214 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
215 win_errstr(status
)));
216 talloc_free(mem_ctx
);
220 DEBUG(2,(__location__
" Added prefixMap %s - now have %u prefixes\n",
221 full_oid
, num_prefixes
));
223 talloc_free(mem_ctx
);
227 WERROR
dsdb_prefix_map_update(TALLOC_CTX
*mem_ctx
, uint32_t *num_prefixes
, struct dsdb_schema_oid_prefix
**prefixes
, const char *oid
)
229 uint32_t new_num_prefixes
, index_new_prefix
, new_entry_id
;
230 const char* lastDotOffset
;
233 new_num_prefixes
= *num_prefixes
+ 1;
234 index_new_prefix
= *num_prefixes
;
237 * this is the algorithm we use to create new mappings for now
239 * TODO: find what algorithm windows use
241 new_entry_id
= (*num_prefixes
)<<16;
243 /* Extract the prefix from the oid*/
244 lastDotOffset
= strrchr(oid
, '.');
245 if (lastDotOffset
== NULL
) {
246 DEBUG(0,("dsdb_prefix_map_update: failed to find the last dot\n"));
247 return WERR_NOT_FOUND
;
250 /* Calculate the size of the remainig string that should be the prefix of it */
251 size
= strlen(oid
) - strlen(lastDotOffset
);
253 DEBUG(0,("dsdb_prefix_map_update: size of the remaining string invalid\n"));
257 /* Create a spot in the prefixMap for one more prefix*/
258 (*prefixes
) = talloc_realloc(mem_ctx
, *prefixes
, struct dsdb_schema_oid_prefix
, new_num_prefixes
);
259 W_ERROR_HAVE_NO_MEMORY(*prefixes
);
261 /* Add the new prefix entry*/
262 (*prefixes
)[index_new_prefix
].id
= new_entry_id
;
263 (*prefixes
)[index_new_prefix
].oid
= talloc_strndup(mem_ctx
, oid
, size
);
264 (*prefixes
)[index_new_prefix
].oid_len
= strlen((*prefixes
)[index_new_prefix
].oid
);
266 /* Increase num_prefixes because new prefix has been added */
272 WERROR
dsdb_find_prefix_for_oid(uint32_t num_prefixes
, const struct dsdb_schema_oid_prefix
*prefixes
, const char *in
, uint32_t *out
)
280 /* make oid prefix, i.e. oid w/o last subidentifier */
281 pstr
= strrchr(in
, '.');
282 if (!pstr
) return WERR_INVALID_PARAM
;
283 if (pstr
< in
) return WERR_INVALID_PARAM
;
284 if ((pstr
- in
) < 4) return WERR_INVALID_PARAM
;
286 oid_prefix
= talloc_strndup(0, in
, pstr
- in
);
288 for (i
=0; i
< num_prefixes
; i
++) {
289 if (strcmp(prefixes
[i
].oid
, oid_prefix
) == 0) {
294 talloc_free(oid_prefix
);
296 if (i
< num_prefixes
) {
297 /* move next to '.' char */
300 val
= strtoul(pstr
, &end_str
, 10);
301 if (end_str
[0] != '\0') {
302 return WERR_INVALID_PARAM
;
303 } else if (val
> 0xFFFF) {
304 return WERR_INVALID_PARAM
;
307 *out
= prefixes
[i
].id
| val
;
311 DEBUG(5,(__location__
" Failed to find oid %s - have %u prefixes\n", in
, num_prefixes
));
313 return WERR_DS_NO_MSDS_INTID
;
316 WERROR
dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX
*mem_ctx
, struct ldb_context
*ldb
,
317 const struct dsdb_schema
*schema
)
319 struct ldb_message
*msg
= ldb_msg_new(mem_ctx
);
320 struct ldb_dn
*schema_dn
;
321 struct prefixMapBlob pm
;
322 struct ldb_val ndr_blob
;
323 enum ndr_err_code ndr_err
;
331 schema_dn
= samdb_schema_dn(ldb
);
333 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
337 pm
.version
= PREFIX_MAP_VERSION_DSDB
;
338 pm
.ctr
.dsdb
.num_mappings
= schema
->num_prefixes
;
339 pm
.ctr
.dsdb
.mappings
= talloc_array(msg
,
340 struct drsuapi_DsReplicaOIDMapping
,
341 pm
.ctr
.dsdb
.num_mappings
);
342 if (!pm
.ctr
.dsdb
.mappings
) {
347 for (i
=0; i
< schema
->num_prefixes
; i
++) {
350 if (!ber_write_partial_OID_String(pm
.ctr
.dsdb
.mappings
, &oid_blob
, schema
->prefixes
[i
].oid
)) {
351 DEBUG(0, ("write_partial_OID failed for %s", schema
->prefixes
[i
].oid
));
352 return WERR_INTERNAL_ERROR
;
355 pm
.ctr
.dsdb
.mappings
[i
].id_prefix
= schema
->prefixes
[i
].id
>>16;
356 pm
.ctr
.dsdb
.mappings
[i
].oid
.length
= oid_blob
.length
;
357 pm
.ctr
.dsdb
.mappings
[i
].oid
.binary_oid
= oid_blob
.data
;
360 ndr_err
= ndr_push_struct_blob(&ndr_blob
, msg
,
361 lp_iconv_convenience(ldb_get_opaque(ldb
, "loadparm")),
363 (ndr_push_flags_fn_t
)ndr_push_prefixMapBlob
);
364 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
370 ret
= ldb_msg_add_value(msg
, "prefixMap", &ndr_blob
, NULL
);
373 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
377 ret
= samdb_replace( ldb
, msg
, msg
);
381 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: samdb_replace failed\n"));
388 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
)
390 struct prefixMapBlob
*blob
;
391 enum ndr_err_code ndr_err
;
393 const struct ldb_val
*prefix_val
;
394 struct ldb_dn
*schema_dn
;
395 struct ldb_result
*schema_res
= NULL
;
397 static const char *schema_attrs
[] = {
402 schema_dn
= samdb_schema_dn(ldb
);
404 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
408 ret
= ldb_search(ldb
, mem_ctx
, &schema_res
, schema_dn
, LDB_SCOPE_BASE
, schema_attrs
, NULL
);
409 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
410 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
411 talloc_free(schema_res
);
413 } else if (ret
!= LDB_SUCCESS
) {
414 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
415 talloc_free(schema_res
);
419 prefix_val
= ldb_msg_find_ldb_val(schema_res
->msgs
[0], "prefixMap");
421 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
422 talloc_free(schema_res
);
426 blob
= talloc(mem_ctx
, struct prefixMapBlob
);
427 W_ERROR_HAVE_NO_MEMORY(blob
);
429 ndr_err
= ndr_pull_struct_blob(prefix_val
, blob
,
430 lp_iconv_convenience(ldb_get_opaque(ldb
, "loadparm")),
432 (ndr_pull_flags_fn_t
)ndr_pull_prefixMapBlob
);
433 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
434 DEBUG(0,("dsdb_read_prefixes_from_ldb: ndr_pull_struct_blob failed\n"));
436 talloc_free(schema_res
);
440 talloc_free(schema_res
);
442 if (blob
->version
!= PREFIX_MAP_VERSION_DSDB
) {
443 DEBUG(0,("dsdb_read_prefixes_from_ldb: blob->version incorect\n"));
448 *num_prefixes
= blob
->ctr
.dsdb
.num_mappings
;
449 *prefixes
= talloc_array(mem_ctx
, struct dsdb_schema_oid_prefix
, *num_prefixes
);
454 for (i
=0; i
< blob
->ctr
.dsdb
.num_mappings
; i
++) {
456 const char *partial_oid
;
458 oid_blob
= data_blob_const(blob
->ctr
.dsdb
.mappings
[i
].oid
.binary_oid
,
459 blob
->ctr
.dsdb
.mappings
[i
].oid
.length
);
461 if (!ber_read_partial_OID_String(mem_ctx
, oid_blob
, &partial_oid
)) {
462 DEBUG(0, ("ber_read_partial_OID failed on prefixMap item with id: 0x%X",
463 blob
->ctr
.dsdb
.mappings
[i
].id_prefix
));
465 return WERR_INVALID_PARAM
;
468 (*prefixes
)[i
].id
= blob
->ctr
.dsdb
.mappings
[i
].id_prefix
<<16;
469 (*prefixes
)[i
].oid
= partial_oid
;
470 (*prefixes
)[i
].oid_len
= strlen((*prefixes
)[i
].oid
);
478 this will be replaced with something that looks at the right part of
479 the schema once we know where unique indexing information is hidden
481 static bool dsdb_schema_unique_attribute(const char *attr
)
483 const char *attrs
[] = { "objectGUID", "objectSID" , NULL
};
485 for (i
=0;attrs
[i
];i
++) {
486 if (strcasecmp(attr
, attrs
[i
]) == 0) {
495 setup the ldb_schema_attribute field for a dsdb_attribute
497 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context
*ldb
,
498 struct dsdb_attribute
*attr
)
500 const char *syntax
= attr
->syntax
->ldb_syntax
;
501 const struct ldb_schema_syntax
*s
;
502 struct ldb_schema_attribute
*a
;
505 syntax
= attr
->syntax
->ldap_oid
;
508 s
= ldb_samba_syntax_by_lDAPDisplayName(ldb
, attr
->lDAPDisplayName
);
510 s
= ldb_samba_syntax_by_name(ldb
, syntax
);
513 s
= ldb_standard_syntax_by_name(ldb
, syntax
);
517 return LDB_ERR_OPERATIONS_ERROR
;
520 attr
->ldb_schema_attribute
= a
= talloc(attr
, struct ldb_schema_attribute
);
521 if (attr
->ldb_schema_attribute
== NULL
) {
523 return LDB_ERR_OPERATIONS_ERROR
;
526 a
->name
= attr
->lDAPDisplayName
;
530 if (dsdb_schema_unique_attribute(a
->name
)) {
531 a
->flags
|= LDB_ATTR_FLAG_UNIQUE_INDEX
;
533 if (attr
->isSingleValued
) {
534 a
->flags
|= LDB_ATTR_FLAG_SINGLE_VALUE
;
542 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
543 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
544 if (get_string_val == NULL) { \
546 d_printf("%s: %s == NULL\n", __location__, attr); \
547 return WERR_INVALID_PARAM; \
552 (p)->elem = talloc_strndup(mem_ctx, \
553 (const char *)get_string_val->data, \
554 get_string_val->length); \
556 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
562 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
563 int get_string_list_counter; \
564 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
565 if (get_string_list_el == NULL) { \
567 d_printf("%s: %s == NULL\n", __location__, attr); \
568 return WERR_INVALID_PARAM; \
574 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
575 for (get_string_list_counter=0; \
576 get_string_list_counter < get_string_list_el->num_values; \
577 get_string_list_counter++) { \
578 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
579 (const char *)get_string_list_el->values[get_string_list_counter].data, \
580 get_string_list_el->values[get_string_list_counter].length); \
581 if (!(p)->elem[get_string_list_counter]) { \
582 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
585 (p)->elem[get_string_list_counter+1] = NULL; \
587 talloc_steal(mem_ctx, (p)->elem); \
590 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
592 str = samdb_result_string(msg, attr, NULL);\
595 d_printf("%s: %s == NULL\n", __location__, attr); \
596 return WERR_INVALID_PARAM; \
600 } else if (strcasecmp("TRUE", str) == 0) { \
602 } else if (strcasecmp("FALSE", str) == 0) { \
605 d_printf("%s: %s == %s\n", __location__, attr, str); \
606 return WERR_INVALID_PARAM; \
610 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
611 (p)->elem = samdb_result_uint(msg, attr, 0);\
614 #define GET_UINT32_PTR_LDB(msg, attr, p, elem) do { \
615 uint64_t _v = samdb_result_uint64(msg, attr, UINT64_MAX);\
616 if (_v == UINT64_MAX) { \
618 } else if (_v > UINT32_MAX) { \
619 d_printf("%s: %s == 0x%llX\n", __location__, \
620 attr, (unsigned long long)_v); \
621 return WERR_INVALID_PARAM; \
623 (p)->elem = talloc(mem_ctx, uint32_t); \
625 d_printf("%s: talloc failed for %s\n", __location__, attr); \
628 *(p)->elem = (uint32_t)_v; \
632 #define GET_GUID_LDB(msg, attr, p, elem) do { \
633 (p)->elem = samdb_result_guid(msg, attr);\
636 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
637 const struct ldb_val *_val;\
638 _val = ldb_msg_find_ldb_val(msg, attr);\
641 talloc_steal(mem_ctx, (p)->elem.data);\
643 ZERO_STRUCT((p)->elem);\
647 WERROR
dsdb_attribute_from_ldb(struct ldb_context
*ldb
,
648 const struct dsdb_schema
*schema
,
649 struct ldb_message
*msg
,
651 struct dsdb_attribute
*attr
)
655 GET_STRING_LDB(msg
, "cn", mem_ctx
, attr
, cn
, false);
656 GET_STRING_LDB(msg
, "lDAPDisplayName", mem_ctx
, attr
, lDAPDisplayName
, true);
657 GET_STRING_LDB(msg
, "attributeID", mem_ctx
, attr
, attributeID_oid
, true);
658 if (schema
->num_prefixes
== 0) {
659 /* set an invalid value */
660 attr
->attributeID_id
= 0xFFFFFFFF;
662 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
,
663 attr
->attributeID_oid
,
664 &attr
->attributeID_id
);
665 if (!W_ERROR_IS_OK(status
)) {
666 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
667 __location__
, attr
->lDAPDisplayName
, attr
->attributeID_oid
,
668 win_errstr(status
)));
672 GET_GUID_LDB(msg
, "schemaIDGUID", attr
, schemaIDGUID
);
673 GET_UINT32_LDB(msg
, "mAPIID", attr
, mAPIID
);
675 GET_GUID_LDB(msg
, "attributeSecurityGUID", attr
, attributeSecurityGUID
);
677 GET_UINT32_LDB(msg
, "searchFlags", attr
, searchFlags
);
678 GET_UINT32_LDB(msg
, "systemFlags", attr
, systemFlags
);
679 GET_BOOL_LDB(msg
, "isMemberOfPartialAttributeSet", attr
, isMemberOfPartialAttributeSet
, false);
680 GET_UINT32_LDB(msg
, "linkID", attr
, linkID
);
682 GET_STRING_LDB(msg
, "attributeSyntax", mem_ctx
, attr
, attributeSyntax_oid
, true);
683 if (schema
->num_prefixes
== 0) {
684 /* set an invalid value */
685 attr
->attributeSyntax_id
= 0xFFFFFFFF;
687 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
,
688 attr
->attributeSyntax_oid
,
689 &attr
->attributeSyntax_id
);
690 if (!W_ERROR_IS_OK(status
)) {
691 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
692 __location__
, attr
->lDAPDisplayName
, attr
->attributeSyntax_oid
,
693 win_errstr(status
)));
697 GET_UINT32_LDB(msg
, "oMSyntax", attr
, oMSyntax
);
698 GET_BLOB_LDB(msg
, "oMObjectClass", mem_ctx
, attr
, oMObjectClass
);
700 GET_BOOL_LDB(msg
, "isSingleValued", attr
, isSingleValued
, true);
701 GET_UINT32_PTR_LDB(msg
, "rangeLower", attr
, rangeLower
);
702 GET_UINT32_PTR_LDB(msg
, "rangeUpper", attr
, rangeUpper
);
703 GET_BOOL_LDB(msg
, "extendedCharsAllowed", attr
, extendedCharsAllowed
, false);
705 GET_UINT32_LDB(msg
, "schemaFlagsEx", attr
, schemaFlagsEx
);
706 GET_BLOB_LDB(msg
, "msDs-Schema-Extensions", mem_ctx
, attr
, msDs_Schema_Extensions
);
708 GET_BOOL_LDB(msg
, "showInAdvancedViewOnly", attr
, showInAdvancedViewOnly
, false);
709 GET_STRING_LDB(msg
, "adminDisplayName", mem_ctx
, attr
, adminDisplayName
, false);
710 GET_STRING_LDB(msg
, "adminDescription", mem_ctx
, attr
, adminDescription
, false);
711 GET_STRING_LDB(msg
, "classDisplayName", mem_ctx
, attr
, classDisplayName
, false);
712 GET_BOOL_LDB(msg
, "isEphemeral", attr
, isEphemeral
, false);
713 GET_BOOL_LDB(msg
, "isDefunct", attr
, isDefunct
, false);
714 GET_BOOL_LDB(msg
, "systemOnly", attr
, systemOnly
, false);
716 attr
->syntax
= dsdb_syntax_for_attribute(attr
);
718 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
721 if (dsdb_schema_setup_ldb_schema_attribute(ldb
, attr
) != LDB_SUCCESS
) {
722 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
728 WERROR
dsdb_class_from_ldb(const struct dsdb_schema
*schema
,
729 struct ldb_message
*msg
,
731 struct dsdb_class
*obj
)
735 GET_STRING_LDB(msg
, "cn", mem_ctx
, obj
, cn
, false);
736 GET_STRING_LDB(msg
, "lDAPDisplayName", mem_ctx
, obj
, lDAPDisplayName
, true);
737 GET_STRING_LDB(msg
, "governsID", mem_ctx
, obj
, governsID_oid
, true);
738 if (schema
->num_prefixes
== 0) {
739 /* set an invalid value */
740 obj
->governsID_id
= 0xFFFFFFFF;
742 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
,
745 if (!W_ERROR_IS_OK(status
)) {
746 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
747 __location__
, obj
->lDAPDisplayName
, obj
->governsID_oid
,
748 win_errstr(status
)));
752 GET_GUID_LDB(msg
, "schemaIDGUID", obj
, schemaIDGUID
);
754 GET_UINT32_LDB(msg
, "objectClassCategory", obj
, objectClassCategory
);
755 GET_STRING_LDB(msg
, "rDNAttID", mem_ctx
, obj
, rDNAttID
, false);
756 GET_STRING_LDB(msg
, "defaultObjectCategory", mem_ctx
, obj
, defaultObjectCategory
, true);
758 GET_STRING_LDB(msg
, "subClassOf", mem_ctx
, obj
, subClassOf
, true);
760 GET_STRING_LIST_LDB(msg
, "systemAuxiliaryClass", mem_ctx
, obj
, systemAuxiliaryClass
, false);
761 GET_STRING_LIST_LDB(msg
, "auxiliaryClass", mem_ctx
, obj
, auxiliaryClass
, false);
763 GET_STRING_LIST_LDB(msg
, "systemMustContain", mem_ctx
, obj
, systemMustContain
, false);
764 GET_STRING_LIST_LDB(msg
, "systemMayContain", mem_ctx
, obj
, systemMayContain
, false);
765 GET_STRING_LIST_LDB(msg
, "mustContain", mem_ctx
, obj
, mustContain
, false);
766 GET_STRING_LIST_LDB(msg
, "mayContain", mem_ctx
, obj
, mayContain
, false);
768 GET_STRING_LIST_LDB(msg
, "systemPossSuperiors", mem_ctx
, obj
, systemPossSuperiors
, false);
769 GET_STRING_LIST_LDB(msg
, "possSuperiors", mem_ctx
, obj
, possSuperiors
, false);
771 GET_STRING_LDB(msg
, "defaultSecurityDescriptor", mem_ctx
, obj
, defaultSecurityDescriptor
, false);
773 GET_UINT32_LDB(msg
, "schemaFlagsEx", obj
, schemaFlagsEx
);
774 GET_BLOB_LDB(msg
, "msDs-Schema-Extensions", mem_ctx
, obj
, msDs_Schema_Extensions
);
776 GET_BOOL_LDB(msg
, "showInAdvancedViewOnly", obj
, showInAdvancedViewOnly
, false);
777 GET_STRING_LDB(msg
, "adminDisplayName", mem_ctx
, obj
, adminDisplayName
, false);
778 GET_STRING_LDB(msg
, "adminDescription", mem_ctx
, obj
, adminDescription
, false);
779 GET_STRING_LDB(msg
, "classDisplayName", mem_ctx
, obj
, classDisplayName
, false);
780 GET_BOOL_LDB(msg
, "defaultHidingValue", obj
, defaultHidingValue
, false);
781 GET_BOOL_LDB(msg
, "isDefunct", obj
, isDefunct
, false);
782 GET_BOOL_LDB(msg
, "systemOnly", obj
, systemOnly
, false);
787 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
790 Create a DSDB schema from the ldb results provided. This is called
791 directly when the schema is provisioned from an on-disk LDIF file, or
792 from dsdb_schema_from_schema_dn in schema_fsmo
795 int dsdb_schema_from_ldb_results(TALLOC_CTX
*mem_ctx
, struct ldb_context
*ldb
,
796 struct smb_iconv_convenience
*iconv_convenience
,
797 struct ldb_result
*schema_res
,
798 struct ldb_result
*attrs_res
, struct ldb_result
*objectclass_res
,
799 struct dsdb_schema
**schema_out
,
804 const struct ldb_val
*prefix_val
;
805 const struct ldb_val
*info_val
;
806 struct ldb_val info_val_default
;
807 struct dsdb_schema
*schema
;
809 schema
= dsdb_new_schema(mem_ctx
, iconv_convenience
);
811 dsdb_oom(error_string
, mem_ctx
);
812 return LDB_ERR_OPERATIONS_ERROR
;
815 prefix_val
= ldb_msg_find_ldb_val(schema_res
->msgs
[0], "prefixMap");
817 *error_string
= talloc_asprintf(mem_ctx
,
818 "schema_fsmo_init: no prefixMap attribute found");
819 DEBUG(0,(__location__
": %s\n", *error_string
));
820 return LDB_ERR_CONSTRAINT_VIOLATION
;
822 info_val
= ldb_msg_find_ldb_val(schema_res
->msgs
[0], "schemaInfo");
824 info_val_default
= strhex_to_data_blob(mem_ctx
, "FF0000000000000000000000000000000000000000");
825 if (!info_val_default
.data
) {
826 dsdb_oom(error_string
, mem_ctx
);
827 return LDB_ERR_OPERATIONS_ERROR
;
829 info_val
= &info_val_default
;
832 status
= dsdb_load_oid_mappings_ldb(schema
, prefix_val
, info_val
);
833 if (!W_ERROR_IS_OK(status
)) {
834 *error_string
= talloc_asprintf(mem_ctx
,
835 "schema_fsmo_init: failed to load oid mappings: %s",
837 DEBUG(0,(__location__
": %s\n", *error_string
));
838 return LDB_ERR_CONSTRAINT_VIOLATION
;
841 for (i
=0; i
< attrs_res
->count
; i
++) {
842 struct dsdb_attribute
*sa
;
844 sa
= talloc_zero(schema
, struct dsdb_attribute
);
846 dsdb_oom(error_string
, mem_ctx
);
847 return LDB_ERR_OPERATIONS_ERROR
;
850 status
= dsdb_attribute_from_ldb(ldb
, schema
, attrs_res
->msgs
[i
], sa
, sa
);
851 if (!W_ERROR_IS_OK(status
)) {
852 *error_string
= talloc_asprintf(mem_ctx
,
853 "schema_fsmo_init: failed to load attribute definition: %s:%s",
854 ldb_dn_get_linearized(attrs_res
->msgs
[i
]->dn
),
856 DEBUG(0,(__location__
": %s\n", *error_string
));
857 return LDB_ERR_CONSTRAINT_VIOLATION
;
860 DLIST_ADD(schema
->attributes
, sa
);
863 for (i
=0; i
< objectclass_res
->count
; i
++) {
864 struct dsdb_class
*sc
;
866 sc
= talloc_zero(schema
, struct dsdb_class
);
868 dsdb_oom(error_string
, mem_ctx
);
869 return LDB_ERR_OPERATIONS_ERROR
;
872 status
= dsdb_class_from_ldb(schema
, objectclass_res
->msgs
[i
], sc
, sc
);
873 if (!W_ERROR_IS_OK(status
)) {
874 *error_string
= talloc_asprintf(mem_ctx
,
875 "schema_fsmo_init: failed to load class definition: %s:%s",
876 ldb_dn_get_linearized(objectclass_res
->msgs
[i
]->dn
),
878 DEBUG(0,(__location__
": %s\n", *error_string
));
879 return LDB_ERR_CONSTRAINT_VIOLATION
;
882 DLIST_ADD(schema
->classes
, sc
);
885 schema
->fsmo
.master_dn
= ldb_msg_find_attr_as_dn(ldb
, schema
, schema_res
->msgs
[0], "fSMORoleOwner");
886 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb
), schema
->fsmo
.master_dn
) == 0) {
887 schema
->fsmo
.we_are_master
= true;
889 schema
->fsmo
.we_are_master
= false;
892 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
893 (schema
->fsmo
.we_are_master
?"yes":"no")));
895 *schema_out
= schema
;
900 static const struct {
903 } name_mappings
[] = {
905 { "name", "1.2.840.113556.1.4.1" },
906 { "lDAPDisplayName", "1.2.840.113556.1.2.460" },
907 { "attributeID", "1.2.840.113556.1.2.30" },
908 { "schemaIDGUID", "1.2.840.113556.1.4.148" },
909 { "mAPIID", "1.2.840.113556.1.2.49" },
910 { "attributeSecurityGUID", "1.2.840.113556.1.4.149" },
911 { "searchFlags", "1.2.840.113556.1.2.334" },
912 { "systemFlags", "1.2.840.113556.1.4.375" },
913 { "isMemberOfPartialAttributeSet", "1.2.840.113556.1.4.639" },
914 { "linkID", "1.2.840.113556.1.2.50" },
915 { "attributeSyntax", "1.2.840.113556.1.2.32" },
916 { "oMSyntax", "1.2.840.113556.1.2.231" },
917 { "oMObjectClass", "1.2.840.113556.1.2.218" },
918 { "isSingleValued", "1.2.840.113556.1.2.33" },
919 { "rangeLower", "1.2.840.113556.1.2.34" },
920 { "rangeUpper", "1.2.840.113556.1.2.35" },
921 { "extendedCharsAllowed", "1.2.840.113556.1.2.380" },
922 { "schemaFlagsEx", "1.2.840.113556.1.4.120" },
923 { "msDs-Schema-Extensions", "1.2.840.113556.1.4.1440" },
924 { "showInAdvancedViewOnly", "1.2.840.113556.1.2.169" },
925 { "adminDisplayName", "1.2.840.113556.1.2.194" },
926 { "adminDescription", "1.2.840.113556.1.2.226" },
927 { "classDisplayName", "1.2.840.113556.1.4.610" },
928 { "isEphemeral", "1.2.840.113556.1.4.1212" },
929 { "isDefunct", "1.2.840.113556.1.4.661" },
930 { "systemOnly", "1.2.840.113556.1.4.170" },
931 { "governsID", "1.2.840.113556.1.2.22" },
932 { "objectClassCategory", "1.2.840.113556.1.2.370" },
933 { "rDNAttID", "1.2.840.113556.1.2.26" },
934 { "defaultObjectCategory", "1.2.840.113556.1.4.783" },
935 { "subClassOf", "1.2.840.113556.1.2.21" },
936 { "systemAuxiliaryClass", "1.2.840.113556.1.4.198" },
937 { "systemPossSuperiors", "1.2.840.113556.1.4.195" },
938 { "systemMustContain", "1.2.840.113556.1.4.197" },
939 { "systemMayContain", "1.2.840.113556.1.4.196" },
940 { "auxiliaryClass", "1.2.840.113556.1.2.351" },
941 { "possSuperiors", "1.2.840.113556.1.2.8" },
942 { "mustContain", "1.2.840.113556.1.2.24" },
943 { "mayContain", "1.2.840.113556.1.2.25" },
944 { "defaultSecurityDescriptor", "1.2.840.113556.1.4.224" },
945 { "defaultHidingValue", "1.2.840.113556.1.4.518" },
948 static struct drsuapi_DsReplicaAttribute
*dsdb_find_object_attr_name(struct dsdb_schema
*schema
,
949 struct drsuapi_DsReplicaObject
*obj
,
955 const char *oid
= NULL
;
957 for(i
=0; i
< ARRAY_SIZE(name_mappings
); i
++) {
958 if (strcmp(name_mappings
[i
].name
, name
) != 0) continue;
960 oid
= name_mappings
[i
].oid
;
968 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
, oid
, &attid
);
969 if (!W_ERROR_IS_OK(status
)) {
973 for (i
=0; i
< obj
->attribute_ctr
.num_attributes
; i
++) {
974 if (obj
->attribute_ctr
.attributes
[i
].attid
!= attid
) continue;
977 return &obj
->attribute_ctr
.attributes
[i
];
983 #define GET_STRING_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
984 struct drsuapi_DsReplicaAttribute *_a; \
985 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
986 if (strict && !_a) { \
987 d_printf("%s: %s == NULL\n", __location__, attr); \
988 return WERR_INVALID_PARAM; \
990 if (strict && _a->value_ctr.num_values != 1) { \
991 d_printf("%s: %s num_values == %u\n", __location__, attr, \
992 _a->value_ctr.num_values); \
993 return WERR_INVALID_PARAM; \
995 if (_a && _a->value_ctr.num_values >= 1) { \
997 if (!convert_string_talloc_convenience(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \
998 _a->value_ctr.values[0].blob->data, \
999 _a->value_ctr.values[0].blob->length, \
1000 (void **)discard_const(&(p)->elem), &_ret, false)) { \
1001 DEBUG(0,("%s: invalid data!\n", attr)); \
1003 _a->value_ctr.values[0].blob->data, \
1004 _a->value_ctr.values[0].blob->length); \
1005 return WERR_FOOBAR; \
1012 #define GET_UINT32_LIST_DS(s, r, attr, mem_ctx, p, elem) do { \
1014 struct drsuapi_DsReplicaAttribute *_a; \
1015 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1016 (p)->elem = _a ? talloc_array(mem_ctx, uint32_t, _a->value_ctr.num_values + 1) : NULL; \
1017 for (list_counter=0; \
1018 _a && list_counter < _a->value_ctr.num_values; \
1020 if (_a->value_ctr.values[list_counter].blob->length != 4) { \
1021 return WERR_INVALID_PARAM; \
1023 (p)->elem[list_counter] = IVAL(_a->value_ctr.values[list_counter].blob->data, 0); \
1025 if (_a) (p)->elem[list_counter] = 0; \
1028 #define GET_DN_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1029 struct drsuapi_DsReplicaAttribute *_a; \
1030 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1031 if (strict && !_a) { \
1032 d_printf("%s: %s == NULL\n", __location__, attr); \
1033 return WERR_INVALID_PARAM; \
1035 if (strict && _a->value_ctr.num_values != 1) { \
1036 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1037 _a->value_ctr.num_values); \
1038 return WERR_INVALID_PARAM; \
1040 if (strict && !_a->value_ctr.values[0].blob) { \
1041 d_printf("%s: %s data == NULL\n", __location__, attr); \
1042 return WERR_INVALID_PARAM; \
1044 if (_a && _a->value_ctr.num_values >= 1 \
1045 && _a->value_ctr.values[0].blob) { \
1046 struct drsuapi_DsReplicaObjectIdentifier3 _id3; \
1047 enum ndr_err_code _ndr_err; \
1048 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1049 mem_ctx, s->iconv_convenience, &_id3,\
1050 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);\
1051 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1052 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1053 return ntstatus_to_werror(_nt_status); \
1055 (p)->elem = _id3.dn; \
1061 #define GET_BOOL_DS(s, r, attr, p, elem, strict) do { \
1062 struct drsuapi_DsReplicaAttribute *_a; \
1063 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1064 if (strict && !_a) { \
1065 d_printf("%s: %s == NULL\n", __location__, attr); \
1066 return WERR_INVALID_PARAM; \
1068 if (strict && _a->value_ctr.num_values != 1) { \
1069 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1070 (unsigned int)_a->value_ctr.num_values); \
1071 return WERR_INVALID_PARAM; \
1073 if (strict && !_a->value_ctr.values[0].blob) { \
1074 d_printf("%s: %s data == NULL\n", __location__, attr); \
1075 return WERR_INVALID_PARAM; \
1077 if (strict && _a->value_ctr.values[0].blob->length != 4) { \
1078 d_printf("%s: %s length == %u\n", __location__, attr, \
1079 (unsigned int)_a->value_ctr.values[0].blob->length); \
1080 return WERR_INVALID_PARAM; \
1082 if (_a && _a->value_ctr.num_values >= 1 \
1083 && _a->value_ctr.values[0].blob \
1084 && _a->value_ctr.values[0].blob->length == 4) { \
1085 (p)->elem = (IVAL(_a->value_ctr.values[0].blob->data,0)?true:false);\
1087 (p)->elem = false; \
1091 #define GET_UINT32_DS(s, r, attr, p, elem) do { \
1092 struct drsuapi_DsReplicaAttribute *_a; \
1093 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1094 if (_a && _a->value_ctr.num_values >= 1 \
1095 && _a->value_ctr.values[0].blob \
1096 && _a->value_ctr.values[0].blob->length == 4) { \
1097 (p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1103 #define GET_UINT32_PTR_DS(s, r, attr, p, elem) do { \
1104 struct drsuapi_DsReplicaAttribute *_a; \
1105 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1106 if (_a && _a->value_ctr.num_values >= 1 \
1107 && _a->value_ctr.values[0].blob \
1108 && _a->value_ctr.values[0].blob->length == 4) { \
1109 (p)->elem = talloc(mem_ctx, uint32_t); \
1111 d_printf("%s: talloc failed for %s\n", __location__, attr); \
1112 return WERR_NOMEM; \
1114 *(p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1120 #define GET_GUID_DS(s, r, attr, mem_ctx, p, elem) do { \
1121 struct drsuapi_DsReplicaAttribute *_a; \
1122 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1123 if (_a && _a->value_ctr.num_values >= 1 \
1124 && _a->value_ctr.values[0].blob \
1125 && _a->value_ctr.values[0].blob->length == 16) { \
1126 enum ndr_err_code _ndr_err; \
1127 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1128 mem_ctx, s->iconv_convenience, &(p)->elem, \
1129 (ndr_pull_flags_fn_t)ndr_pull_GUID); \
1130 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1131 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1132 return ntstatus_to_werror(_nt_status); \
1135 ZERO_STRUCT((p)->elem);\
1139 #define GET_BLOB_DS(s, r, attr, mem_ctx, p, elem) do { \
1140 struct drsuapi_DsReplicaAttribute *_a; \
1141 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1142 if (_a && _a->value_ctr.num_values >= 1 \
1143 && _a->value_ctr.values[0].blob) { \
1144 (p)->elem = *_a->value_ctr.values[0].blob;\
1145 talloc_steal(mem_ctx, (p)->elem.data); \
1147 ZERO_STRUCT((p)->elem);\
1151 WERROR
dsdb_attribute_from_drsuapi(struct ldb_context
*ldb
,
1152 struct dsdb_schema
*schema
,
1153 struct drsuapi_DsReplicaObject
*r
,
1154 TALLOC_CTX
*mem_ctx
,
1155 struct dsdb_attribute
*attr
)
1159 GET_STRING_DS(schema
, r
, "name", mem_ctx
, attr
, cn
, true);
1160 GET_STRING_DS(schema
, r
, "lDAPDisplayName", mem_ctx
, attr
, lDAPDisplayName
, true);
1161 GET_UINT32_DS(schema
, r
, "attributeID", attr
, attributeID_id
);
1162 status
= dsdb_schema_pfm_oid_from_attid(schema
->prefixmap
, attr
->attributeID_id
,
1163 mem_ctx
, &attr
->attributeID_oid
);
1164 if (!W_ERROR_IS_OK(status
)) {
1165 DEBUG(0,("%s: '%s': unable to map attributeID 0x%08X: %s\n",
1166 __location__
, attr
->lDAPDisplayName
, attr
->attributeID_id
,
1167 win_errstr(status
)));
1170 GET_GUID_DS(schema
, r
, "schemaIDGUID", mem_ctx
, attr
, schemaIDGUID
);
1171 GET_UINT32_DS(schema
, r
, "mAPIID", attr
, mAPIID
);
1173 GET_GUID_DS(schema
, r
, "attributeSecurityGUID", mem_ctx
, attr
, attributeSecurityGUID
);
1175 GET_UINT32_DS(schema
, r
, "searchFlags", attr
, searchFlags
);
1176 GET_UINT32_DS(schema
, r
, "systemFlags", attr
, systemFlags
);
1177 GET_BOOL_DS(schema
, r
, "isMemberOfPartialAttributeSet", attr
, isMemberOfPartialAttributeSet
, false);
1178 GET_UINT32_DS(schema
, r
, "linkID", attr
, linkID
);
1180 GET_UINT32_DS(schema
, r
, "attributeSyntax", attr
, attributeSyntax_id
);
1181 status
= dsdb_schema_pfm_oid_from_attid(schema
->prefixmap
, attr
->attributeSyntax_id
,
1182 mem_ctx
, &attr
->attributeSyntax_oid
);
1183 if (!W_ERROR_IS_OK(status
)) {
1184 DEBUG(0,("%s: '%s': unable to map attributeSyntax 0x%08X: %s\n",
1185 __location__
, attr
->lDAPDisplayName
, attr
->attributeSyntax_id
,
1186 win_errstr(status
)));
1189 GET_UINT32_DS(schema
, r
, "oMSyntax", attr
, oMSyntax
);
1190 GET_BLOB_DS(schema
, r
, "oMObjectClass", mem_ctx
, attr
, oMObjectClass
);
1192 GET_BOOL_DS(schema
, r
, "isSingleValued", attr
, isSingleValued
, true);
1193 GET_UINT32_PTR_DS(schema
, r
, "rangeLower", attr
, rangeLower
);
1194 GET_UINT32_PTR_DS(schema
, r
, "rangeUpper", attr
, rangeUpper
);
1195 GET_BOOL_DS(schema
, r
, "extendedCharsAllowed", attr
, extendedCharsAllowed
, false);
1197 GET_UINT32_DS(schema
, r
, "schemaFlagsEx", attr
, schemaFlagsEx
);
1198 GET_BLOB_DS(schema
, r
, "msDs-Schema-Extensions", mem_ctx
, attr
, msDs_Schema_Extensions
);
1200 GET_BOOL_DS(schema
, r
, "showInAdvancedViewOnly", attr
, showInAdvancedViewOnly
, false);
1201 GET_STRING_DS(schema
, r
, "adminDisplayName", mem_ctx
, attr
, adminDisplayName
, false);
1202 GET_STRING_DS(schema
, r
, "adminDescription", mem_ctx
, attr
, adminDescription
, false);
1203 GET_STRING_DS(schema
, r
, "classDisplayName", mem_ctx
, attr
, classDisplayName
, false);
1204 GET_BOOL_DS(schema
, r
, "isEphemeral", attr
, isEphemeral
, false);
1205 GET_BOOL_DS(schema
, r
, "isDefunct", attr
, isDefunct
, false);
1206 GET_BOOL_DS(schema
, r
, "systemOnly", attr
, systemOnly
, false);
1208 attr
->syntax
= dsdb_syntax_for_attribute(attr
);
1209 if (!attr
->syntax
) {
1210 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
1213 if (dsdb_schema_setup_ldb_schema_attribute(ldb
, attr
) != LDB_SUCCESS
) {
1214 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
1220 WERROR
dsdb_class_from_drsuapi(struct dsdb_schema
*schema
,
1221 struct drsuapi_DsReplicaObject
*r
,
1222 TALLOC_CTX
*mem_ctx
,
1223 struct dsdb_class
*obj
)
1227 GET_STRING_DS(schema
, r
, "name", mem_ctx
, obj
, cn
, true);
1228 GET_STRING_DS(schema
, r
, "lDAPDisplayName", mem_ctx
, obj
, lDAPDisplayName
, true);
1229 GET_UINT32_DS(schema
, r
, "governsID", obj
, governsID_id
);
1230 status
= dsdb_schema_pfm_oid_from_attid(schema
->prefixmap
, obj
->governsID_id
,
1231 mem_ctx
, &obj
->governsID_oid
);
1232 if (!W_ERROR_IS_OK(status
)) {
1233 DEBUG(0,("%s: '%s': unable to map governsID 0x%08X: %s\n",
1234 __location__
, obj
->lDAPDisplayName
, obj
->governsID_id
,
1235 win_errstr(status
)));
1238 GET_GUID_DS(schema
, r
, "schemaIDGUID", mem_ctx
, obj
, schemaIDGUID
);
1240 GET_UINT32_DS(schema
, r
, "objectClassCategory", obj
, objectClassCategory
);
1241 GET_STRING_DS(schema
, r
, "rDNAttID", mem_ctx
, obj
, rDNAttID
, false);
1242 GET_DN_DS(schema
, r
, "defaultObjectCategory", mem_ctx
, obj
, defaultObjectCategory
, true);
1244 GET_UINT32_DS(schema
, r
, "subClassOf", obj
, subClassOf_id
);
1246 GET_UINT32_LIST_DS(schema
, r
, "systemAuxiliaryClass", mem_ctx
, obj
, systemAuxiliaryClass_ids
);
1247 GET_UINT32_LIST_DS(schema
, r
, "auxiliaryClass", mem_ctx
, obj
, auxiliaryClass_ids
);
1249 GET_UINT32_LIST_DS(schema
, r
, "systemMustContain", mem_ctx
, obj
, systemMustContain_ids
);
1250 GET_UINT32_LIST_DS(schema
, r
, "systemMayContain", mem_ctx
, obj
, systemMayContain_ids
);
1251 GET_UINT32_LIST_DS(schema
, r
, "mustContain", mem_ctx
, obj
, mustContain_ids
);
1252 GET_UINT32_LIST_DS(schema
, r
, "mayContain", mem_ctx
, obj
, mayContain_ids
);
1254 GET_UINT32_LIST_DS(schema
, r
, "systemPossSuperiors", mem_ctx
, obj
, systemPossSuperiors_ids
);
1255 GET_UINT32_LIST_DS(schema
, r
, "possSuperiors", mem_ctx
, obj
, possSuperiors_ids
);
1257 GET_STRING_DS(schema
, r
, "defaultSecurityDescriptor", mem_ctx
, obj
, defaultSecurityDescriptor
, false);
1259 GET_UINT32_DS(schema
, r
, "schemaFlagsEx", obj
, schemaFlagsEx
);
1260 GET_BLOB_DS(schema
, r
, "msDs-Schema-Extensions", mem_ctx
, obj
, msDs_Schema_Extensions
);
1262 GET_BOOL_DS(schema
, r
, "showInAdvancedViewOnly", obj
, showInAdvancedViewOnly
, false);
1263 GET_STRING_DS(schema
, r
, "adminDisplayName", mem_ctx
, obj
, adminDisplayName
, false);
1264 GET_STRING_DS(schema
, r
, "adminDescription", mem_ctx
, obj
, adminDescription
, false);
1265 GET_STRING_DS(schema
, r
, "classDisplayName", mem_ctx
, obj
, classDisplayName
, false);
1266 GET_BOOL_DS(schema
, r
, "defaultHidingValue", obj
, defaultHidingValue
, false);
1267 GET_BOOL_DS(schema
, r
, "isDefunct", obj
, isDefunct
, false);
1268 GET_BOOL_DS(schema
, r
, "systemOnly", obj
, systemOnly
, false);