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
, 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
);
161 WERROR
dsdb_map_int2oid(const struct dsdb_schema
*schema
, uint32_t in
, TALLOC_CTX
*mem_ctx
, const char **out
)
165 for (i
=0; i
< schema
->num_prefixes
; i
++) {
167 if (schema
->prefixes
[i
].id
!= (in
& 0xFFFF0000)) {
171 val
= talloc_asprintf(mem_ctx
, "%s.%u",
172 schema
->prefixes
[i
].oid
,
174 W_ERROR_HAVE_NO_MEMORY(val
);
180 return WERR_DS_NO_MSDS_INTID
;
184 * this function is called from within a ldb transaction from the schema_fsmo module
186 WERROR
dsdb_create_prefix_mapping(struct ldb_context
*ldb
, struct dsdb_schema
*schema
, const char *full_oid
)
189 uint32_t num_prefixes
;
190 struct dsdb_schema_oid_prefix
*prefixes
;
194 mem_ctx
= talloc_new(ldb
);
195 W_ERROR_HAVE_NO_MEMORY(mem_ctx
);
197 /* Read prefixes from disk*/
198 status
= dsdb_read_prefixes_from_ldb( mem_ctx
, ldb
, &num_prefixes
, &prefixes
);
199 if (!W_ERROR_IS_OK(status
)) {
200 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
201 win_errstr(status
)));
202 talloc_free(mem_ctx
);
206 /* Check if there is a prefix for the oid in the prefixes array*/
207 status
= dsdb_find_prefix_for_oid( num_prefixes
, prefixes
, full_oid
, &out
);
208 if (W_ERROR_IS_OK(status
)) {
210 talloc_free(mem_ctx
);
212 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID
, status
)) {
214 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
215 win_errstr(status
)));
216 talloc_free(mem_ctx
);
220 /* Create the new mapping for the prefix of full_oid */
221 status
= dsdb_prefix_map_update(mem_ctx
, &num_prefixes
, &prefixes
, full_oid
);
222 if (!W_ERROR_IS_OK(status
)) {
223 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_prefix_map_update: %s\n",
224 win_errstr(status
)));
225 talloc_free(mem_ctx
);
229 talloc_free(schema
->prefixes
);
230 schema
->prefixes
= talloc_steal(schema
, prefixes
);
231 schema
->num_prefixes
= num_prefixes
;
233 /* Update prefixMap in ldb*/
234 status
= dsdb_write_prefixes_from_schema_to_ldb(mem_ctx
, ldb
, schema
);
235 if (!W_ERROR_IS_OK(status
)) {
236 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
237 win_errstr(status
)));
238 talloc_free(mem_ctx
);
242 DEBUG(2,(__location__
" Added prefixMap %s - now have %u prefixes\n",
243 full_oid
, num_prefixes
));
245 talloc_free(mem_ctx
);
249 WERROR
dsdb_prefix_map_update(TALLOC_CTX
*mem_ctx
, uint32_t *num_prefixes
, struct dsdb_schema_oid_prefix
**prefixes
, const char *oid
)
251 uint32_t new_num_prefixes
, index_new_prefix
, new_entry_id
;
252 const char* lastDotOffset
;
255 new_num_prefixes
= *num_prefixes
+ 1;
256 index_new_prefix
= *num_prefixes
;
259 * this is the algorithm we use to create new mappings for now
261 * TODO: find what algorithm windows use
263 new_entry_id
= (*num_prefixes
)<<16;
265 /* Extract the prefix from the oid*/
266 lastDotOffset
= strrchr(oid
, '.');
267 if (lastDotOffset
== NULL
) {
268 DEBUG(0,("dsdb_prefix_map_update: failed to find the last dot\n"));
269 return WERR_NOT_FOUND
;
272 /* Calculate the size of the remainig string that should be the prefix of it */
273 size
= strlen(oid
) - strlen(lastDotOffset
);
275 DEBUG(0,("dsdb_prefix_map_update: size of the remaining string invalid\n"));
279 /* Create a spot in the prefixMap for one more prefix*/
280 (*prefixes
) = talloc_realloc(mem_ctx
, *prefixes
, struct dsdb_schema_oid_prefix
, new_num_prefixes
);
281 W_ERROR_HAVE_NO_MEMORY(*prefixes
);
283 /* Add the new prefix entry*/
284 (*prefixes
)[index_new_prefix
].id
= new_entry_id
;
285 (*prefixes
)[index_new_prefix
].oid
= talloc_strndup(mem_ctx
, oid
, size
);
286 (*prefixes
)[index_new_prefix
].oid_len
= strlen((*prefixes
)[index_new_prefix
].oid
);
288 /* Increase num_prefixes because new prefix has been added */
294 WERROR
dsdb_find_prefix_for_oid(uint32_t num_prefixes
, const struct dsdb_schema_oid_prefix
*prefixes
, const char *in
, uint32_t *out
)
302 /* make oid prefix, i.e. oid w/o last subidentifier */
303 pstr
= strrchr(in
, '.');
304 if (!pstr
) return WERR_INVALID_PARAM
;
305 if (pstr
< in
) return WERR_INVALID_PARAM
;
306 if ((pstr
- in
) < 4) return WERR_INVALID_PARAM
;
308 oid_prefix
= talloc_strndup(0, in
, pstr
- in
);
310 for (i
=0; i
< num_prefixes
; i
++) {
311 if (strcmp(prefixes
[i
].oid
, oid_prefix
) == 0) {
316 talloc_free(oid_prefix
);
318 if (i
< num_prefixes
) {
319 /* move next to '.' char */
322 val
= strtoul(pstr
, &end_str
, 10);
323 if (end_str
[0] != '\0') {
324 return WERR_INVALID_PARAM
;
325 } else if (val
> 0xFFFF) {
326 return WERR_INVALID_PARAM
;
329 *out
= prefixes
[i
].id
| val
;
333 DEBUG(5,(__location__
" Failed to find oid %s - have %u prefixes\n", in
, num_prefixes
));
335 return WERR_DS_NO_MSDS_INTID
;
338 WERROR
dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX
*mem_ctx
, struct ldb_context
*ldb
,
339 const struct dsdb_schema
*schema
)
341 struct ldb_message
*msg
= ldb_msg_new(mem_ctx
);
342 struct ldb_dn
*schema_dn
;
343 struct prefixMapBlob pm
;
344 struct ldb_val ndr_blob
;
345 enum ndr_err_code ndr_err
;
353 schema_dn
= samdb_schema_dn(ldb
);
355 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n"));
359 pm
.version
= PREFIX_MAP_VERSION_DSDB
;
360 pm
.ctr
.dsdb
.num_mappings
= schema
->num_prefixes
;
361 pm
.ctr
.dsdb
.mappings
= talloc_array(msg
,
362 struct drsuapi_DsReplicaOIDMapping
,
363 pm
.ctr
.dsdb
.num_mappings
);
364 if (!pm
.ctr
.dsdb
.mappings
) {
369 for (i
=0; i
< schema
->num_prefixes
; i
++) {
372 if (!ber_write_partial_OID_String(pm
.ctr
.dsdb
.mappings
, &oid_blob
, schema
->prefixes
[i
].oid
)) {
373 DEBUG(0, ("write_partial_OID failed for %s", schema
->prefixes
[i
].oid
));
374 return WERR_INTERNAL_ERROR
;
377 pm
.ctr
.dsdb
.mappings
[i
].id_prefix
= schema
->prefixes
[i
].id
>>16;
378 pm
.ctr
.dsdb
.mappings
[i
].oid
.length
= oid_blob
.length
;
379 pm
.ctr
.dsdb
.mappings
[i
].oid
.binary_oid
= oid_blob
.data
;
382 ndr_err
= ndr_push_struct_blob(&ndr_blob
, msg
,
383 lp_iconv_convenience(ldb_get_opaque(ldb
, "loadparm")),
385 (ndr_push_flags_fn_t
)ndr_push_prefixMapBlob
);
386 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
392 ret
= ldb_msg_add_value(msg
, "prefixMap", &ndr_blob
, NULL
);
395 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
399 ret
= samdb_replace( ldb
, msg
, msg
);
403 DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: samdb_replace failed\n"));
410 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
)
412 struct prefixMapBlob
*blob
;
413 enum ndr_err_code ndr_err
;
415 const struct ldb_val
*prefix_val
;
416 struct ldb_dn
*schema_dn
;
417 struct ldb_result
*schema_res
= NULL
;
419 static const char *schema_attrs
[] = {
424 schema_dn
= samdb_schema_dn(ldb
);
426 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
430 ret
= ldb_search(ldb
, mem_ctx
, &schema_res
, schema_dn
, LDB_SCOPE_BASE
, schema_attrs
, NULL
);
431 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
432 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
433 talloc_free(schema_res
);
435 } else if (ret
!= LDB_SUCCESS
) {
436 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
437 talloc_free(schema_res
);
441 prefix_val
= ldb_msg_find_ldb_val(schema_res
->msgs
[0], "prefixMap");
443 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
444 talloc_free(schema_res
);
448 blob
= talloc(mem_ctx
, struct prefixMapBlob
);
449 W_ERROR_HAVE_NO_MEMORY(blob
);
451 ndr_err
= ndr_pull_struct_blob(prefix_val
, blob
,
452 lp_iconv_convenience(ldb_get_opaque(ldb
, "loadparm")),
454 (ndr_pull_flags_fn_t
)ndr_pull_prefixMapBlob
);
455 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
456 DEBUG(0,("dsdb_read_prefixes_from_ldb: ndr_pull_struct_blob failed\n"));
458 talloc_free(schema_res
);
462 talloc_free(schema_res
);
464 if (blob
->version
!= PREFIX_MAP_VERSION_DSDB
) {
465 DEBUG(0,("dsdb_read_prefixes_from_ldb: blob->version incorect\n"));
470 *num_prefixes
= blob
->ctr
.dsdb
.num_mappings
;
471 *prefixes
= talloc_array(mem_ctx
, struct dsdb_schema_oid_prefix
, *num_prefixes
);
476 for (i
=0; i
< blob
->ctr
.dsdb
.num_mappings
; i
++) {
478 const char *partial_oid
;
480 oid_blob
= data_blob_const(blob
->ctr
.dsdb
.mappings
[i
].oid
.binary_oid
,
481 blob
->ctr
.dsdb
.mappings
[i
].oid
.length
);
483 if (!ber_read_partial_OID_String(mem_ctx
, oid_blob
, &partial_oid
)) {
484 DEBUG(0, ("ber_read_partial_OID failed on prefixMap item with id: 0x%X",
485 blob
->ctr
.dsdb
.mappings
[i
].id_prefix
));
487 return WERR_INVALID_PARAM
;
490 (*prefixes
)[i
].id
= blob
->ctr
.dsdb
.mappings
[i
].id_prefix
<<16;
491 (*prefixes
)[i
].oid
= partial_oid
;
492 (*prefixes
)[i
].oid_len
= strlen((*prefixes
)[i
].oid
);
500 this will be replaced with something that looks at the right part of
501 the schema once we know where unique indexing information is hidden
503 static bool dsdb_schema_unique_attribute(const char *attr
)
505 const char *attrs
[] = { "objectGUID", "objectSID" , NULL
};
507 for (i
=0;attrs
[i
];i
++) {
508 if (strcasecmp(attr
, attrs
[i
]) == 0) {
517 setup the ldb_schema_attribute field for a dsdb_attribute
519 static int dsdb_schema_setup_ldb_schema_attribute(struct ldb_context
*ldb
,
520 struct dsdb_attribute
*attr
)
522 const char *syntax
= attr
->syntax
->ldb_syntax
;
523 const struct ldb_schema_syntax
*s
;
524 struct ldb_schema_attribute
*a
;
527 syntax
= attr
->syntax
->ldap_oid
;
530 s
= ldb_samba_syntax_by_lDAPDisplayName(ldb
, attr
->lDAPDisplayName
);
532 s
= ldb_samba_syntax_by_name(ldb
, syntax
);
535 s
= ldb_standard_syntax_by_name(ldb
, syntax
);
539 return LDB_ERR_OPERATIONS_ERROR
;
542 attr
->ldb_schema_attribute
= a
= talloc(attr
, struct ldb_schema_attribute
);
543 if (attr
->ldb_schema_attribute
== NULL
) {
545 return LDB_ERR_OPERATIONS_ERROR
;
548 a
->name
= attr
->lDAPDisplayName
;
552 if (dsdb_schema_unique_attribute(a
->name
)) {
553 a
->flags
|= LDB_ATTR_FLAG_UNIQUE_INDEX
;
555 if (attr
->isSingleValued
) {
556 a
->flags
|= LDB_ATTR_FLAG_SINGLE_VALUE
;
564 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
565 const struct ldb_val *get_string_val = ldb_msg_find_ldb_val(msg, attr); \
566 if (get_string_val == NULL) { \
568 d_printf("%s: %s == NULL\n", __location__, attr); \
569 return WERR_INVALID_PARAM; \
574 (p)->elem = talloc_strndup(mem_ctx, \
575 (const char *)get_string_val->data, \
576 get_string_val->length); \
578 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
584 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
585 int get_string_list_counter; \
586 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
587 if (get_string_list_el == NULL) { \
589 d_printf("%s: %s == NULL\n", __location__, attr); \
590 return WERR_INVALID_PARAM; \
596 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
597 for (get_string_list_counter=0; \
598 get_string_list_counter < get_string_list_el->num_values; \
599 get_string_list_counter++) { \
600 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
601 (const char *)get_string_list_el->values[get_string_list_counter].data, \
602 get_string_list_el->values[get_string_list_counter].length); \
603 if (!(p)->elem[get_string_list_counter]) { \
604 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
607 (p)->elem[get_string_list_counter+1] = NULL; \
609 talloc_steal(mem_ctx, (p)->elem); \
612 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
614 str = samdb_result_string(msg, attr, NULL);\
617 d_printf("%s: %s == NULL\n", __location__, attr); \
618 return WERR_INVALID_PARAM; \
622 } else if (strcasecmp("TRUE", str) == 0) { \
624 } else if (strcasecmp("FALSE", str) == 0) { \
627 d_printf("%s: %s == %s\n", __location__, attr, str); \
628 return WERR_INVALID_PARAM; \
632 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
633 (p)->elem = samdb_result_uint(msg, attr, 0);\
636 #define GET_UINT32_PTR_LDB(msg, attr, p, elem) do { \
637 uint64_t _v = samdb_result_uint64(msg, attr, UINT64_MAX);\
638 if (_v == UINT64_MAX) { \
640 } else if (_v > UINT32_MAX) { \
641 d_printf("%s: %s == 0x%llX\n", __location__, \
642 attr, (unsigned long long)_v); \
643 return WERR_INVALID_PARAM; \
645 (p)->elem = talloc(mem_ctx, uint32_t); \
647 d_printf("%s: talloc failed for %s\n", __location__, attr); \
650 *(p)->elem = (uint32_t)_v; \
654 #define GET_GUID_LDB(msg, attr, p, elem) do { \
655 (p)->elem = samdb_result_guid(msg, attr);\
658 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
659 const struct ldb_val *_val;\
660 _val = ldb_msg_find_ldb_val(msg, attr);\
663 talloc_steal(mem_ctx, (p)->elem.data);\
665 ZERO_STRUCT((p)->elem);\
669 WERROR
dsdb_attribute_from_ldb(struct ldb_context
*ldb
,
670 const struct dsdb_schema
*schema
,
671 struct ldb_message
*msg
,
673 struct dsdb_attribute
*attr
)
677 GET_STRING_LDB(msg
, "cn", mem_ctx
, attr
, cn
, false);
678 GET_STRING_LDB(msg
, "lDAPDisplayName", mem_ctx
, attr
, lDAPDisplayName
, true);
679 GET_STRING_LDB(msg
, "attributeID", mem_ctx
, attr
, attributeID_oid
, true);
680 if (schema
->num_prefixes
== 0) {
681 /* set an invalid value */
682 attr
->attributeID_id
= 0xFFFFFFFF;
684 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
,
685 attr
->attributeID_oid
,
686 &attr
->attributeID_id
);
687 if (!W_ERROR_IS_OK(status
)) {
688 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
689 __location__
, attr
->lDAPDisplayName
, attr
->attributeID_oid
,
690 win_errstr(status
)));
694 GET_GUID_LDB(msg
, "schemaIDGUID", attr
, schemaIDGUID
);
695 GET_UINT32_LDB(msg
, "mAPIID", attr
, mAPIID
);
697 GET_GUID_LDB(msg
, "attributeSecurityGUID", attr
, attributeSecurityGUID
);
699 GET_UINT32_LDB(msg
, "searchFlags", attr
, searchFlags
);
700 GET_UINT32_LDB(msg
, "systemFlags", attr
, systemFlags
);
701 GET_BOOL_LDB(msg
, "isMemberOfPartialAttributeSet", attr
, isMemberOfPartialAttributeSet
, false);
702 GET_UINT32_LDB(msg
, "linkID", attr
, linkID
);
704 GET_STRING_LDB(msg
, "attributeSyntax", mem_ctx
, attr
, attributeSyntax_oid
, true);
705 if (schema
->num_prefixes
== 0) {
706 /* set an invalid value */
707 attr
->attributeSyntax_id
= 0xFFFFFFFF;
709 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
,
710 attr
->attributeSyntax_oid
,
711 &attr
->attributeSyntax_id
);
712 if (!W_ERROR_IS_OK(status
)) {
713 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
714 __location__
, attr
->lDAPDisplayName
, attr
->attributeSyntax_oid
,
715 win_errstr(status
)));
719 GET_UINT32_LDB(msg
, "oMSyntax", attr
, oMSyntax
);
720 GET_BLOB_LDB(msg
, "oMObjectClass", mem_ctx
, attr
, oMObjectClass
);
722 GET_BOOL_LDB(msg
, "isSingleValued", attr
, isSingleValued
, true);
723 GET_UINT32_PTR_LDB(msg
, "rangeLower", attr
, rangeLower
);
724 GET_UINT32_PTR_LDB(msg
, "rangeUpper", attr
, rangeUpper
);
725 GET_BOOL_LDB(msg
, "extendedCharsAllowed", attr
, extendedCharsAllowed
, false);
727 GET_UINT32_LDB(msg
, "schemaFlagsEx", attr
, schemaFlagsEx
);
728 GET_BLOB_LDB(msg
, "msDs-Schema-Extensions", mem_ctx
, attr
, msDs_Schema_Extensions
);
730 GET_BOOL_LDB(msg
, "showInAdvancedViewOnly", attr
, showInAdvancedViewOnly
, false);
731 GET_STRING_LDB(msg
, "adminDisplayName", mem_ctx
, attr
, adminDisplayName
, false);
732 GET_STRING_LDB(msg
, "adminDescription", mem_ctx
, attr
, adminDescription
, false);
733 GET_STRING_LDB(msg
, "classDisplayName", mem_ctx
, attr
, classDisplayName
, false);
734 GET_BOOL_LDB(msg
, "isEphemeral", attr
, isEphemeral
, false);
735 GET_BOOL_LDB(msg
, "isDefunct", attr
, isDefunct
, false);
736 GET_BOOL_LDB(msg
, "systemOnly", attr
, systemOnly
, false);
738 attr
->syntax
= dsdb_syntax_for_attribute(attr
);
740 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
743 if (dsdb_schema_setup_ldb_schema_attribute(ldb
, attr
) != LDB_SUCCESS
) {
744 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
750 WERROR
dsdb_class_from_ldb(const struct dsdb_schema
*schema
,
751 struct ldb_message
*msg
,
753 struct dsdb_class
*obj
)
757 GET_STRING_LDB(msg
, "cn", mem_ctx
, obj
, cn
, false);
758 GET_STRING_LDB(msg
, "lDAPDisplayName", mem_ctx
, obj
, lDAPDisplayName
, true);
759 GET_STRING_LDB(msg
, "governsID", mem_ctx
, obj
, governsID_oid
, true);
760 if (schema
->num_prefixes
== 0) {
761 /* set an invalid value */
762 obj
->governsID_id
= 0xFFFFFFFF;
764 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
,
767 if (!W_ERROR_IS_OK(status
)) {
768 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
769 __location__
, obj
->lDAPDisplayName
, obj
->governsID_oid
,
770 win_errstr(status
)));
774 GET_GUID_LDB(msg
, "schemaIDGUID", obj
, schemaIDGUID
);
776 GET_UINT32_LDB(msg
, "objectClassCategory", obj
, objectClassCategory
);
777 GET_STRING_LDB(msg
, "rDNAttID", mem_ctx
, obj
, rDNAttID
, false);
778 GET_STRING_LDB(msg
, "defaultObjectCategory", mem_ctx
, obj
, defaultObjectCategory
, true);
780 GET_STRING_LDB(msg
, "subClassOf", mem_ctx
, obj
, subClassOf
, true);
782 GET_STRING_LIST_LDB(msg
, "systemAuxiliaryClass", mem_ctx
, obj
, systemAuxiliaryClass
, false);
783 GET_STRING_LIST_LDB(msg
, "auxiliaryClass", mem_ctx
, obj
, auxiliaryClass
, false);
785 GET_STRING_LIST_LDB(msg
, "systemMustContain", mem_ctx
, obj
, systemMustContain
, false);
786 GET_STRING_LIST_LDB(msg
, "systemMayContain", mem_ctx
, obj
, systemMayContain
, false);
787 GET_STRING_LIST_LDB(msg
, "mustContain", mem_ctx
, obj
, mustContain
, false);
788 GET_STRING_LIST_LDB(msg
, "mayContain", mem_ctx
, obj
, mayContain
, false);
790 GET_STRING_LIST_LDB(msg
, "systemPossSuperiors", mem_ctx
, obj
, systemPossSuperiors
, false);
791 GET_STRING_LIST_LDB(msg
, "possSuperiors", mem_ctx
, obj
, possSuperiors
, false);
793 GET_STRING_LDB(msg
, "defaultSecurityDescriptor", mem_ctx
, obj
, defaultSecurityDescriptor
, false);
795 GET_UINT32_LDB(msg
, "schemaFlagsEx", obj
, schemaFlagsEx
);
796 GET_BLOB_LDB(msg
, "msDs-Schema-Extensions", mem_ctx
, obj
, msDs_Schema_Extensions
);
798 GET_BOOL_LDB(msg
, "showInAdvancedViewOnly", obj
, showInAdvancedViewOnly
, false);
799 GET_STRING_LDB(msg
, "adminDisplayName", mem_ctx
, obj
, adminDisplayName
, false);
800 GET_STRING_LDB(msg
, "adminDescription", mem_ctx
, obj
, adminDescription
, false);
801 GET_STRING_LDB(msg
, "classDisplayName", mem_ctx
, obj
, classDisplayName
, false);
802 GET_BOOL_LDB(msg
, "defaultHidingValue", obj
, defaultHidingValue
, false);
803 GET_BOOL_LDB(msg
, "isDefunct", obj
, isDefunct
, false);
804 GET_BOOL_LDB(msg
, "systemOnly", obj
, systemOnly
, false);
809 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
812 Create a DSDB schema from the ldb results provided. This is called
813 directly when the schema is provisioned from an on-disk LDIF file, or
814 from dsdb_schema_from_schema_dn in schema_fsmo
817 int dsdb_schema_from_ldb_results(TALLOC_CTX
*mem_ctx
, struct ldb_context
*ldb
,
818 struct smb_iconv_convenience
*iconv_convenience
,
819 struct ldb_result
*schema_res
,
820 struct ldb_result
*attrs_res
, struct ldb_result
*objectclass_res
,
821 struct dsdb_schema
**schema_out
,
826 const struct ldb_val
*prefix_val
;
827 const struct ldb_val
*info_val
;
828 struct ldb_val info_val_default
;
829 struct dsdb_schema
*schema
;
831 schema
= dsdb_new_schema(mem_ctx
, iconv_convenience
);
833 dsdb_oom(error_string
, mem_ctx
);
834 return LDB_ERR_OPERATIONS_ERROR
;
837 prefix_val
= ldb_msg_find_ldb_val(schema_res
->msgs
[0], "prefixMap");
839 *error_string
= talloc_asprintf(mem_ctx
,
840 "schema_fsmo_init: no prefixMap attribute found");
841 DEBUG(0,(__location__
": %s\n", *error_string
));
842 return LDB_ERR_CONSTRAINT_VIOLATION
;
844 info_val
= ldb_msg_find_ldb_val(schema_res
->msgs
[0], "schemaInfo");
846 info_val_default
= strhex_to_data_blob(mem_ctx
, "FF0000000000000000000000000000000000000000");
847 if (!info_val_default
.data
) {
848 dsdb_oom(error_string
, mem_ctx
);
849 return LDB_ERR_OPERATIONS_ERROR
;
851 info_val
= &info_val_default
;
854 status
= dsdb_load_oid_mappings_ldb(schema
, prefix_val
, info_val
);
855 if (!W_ERROR_IS_OK(status
)) {
856 *error_string
= talloc_asprintf(mem_ctx
,
857 "schema_fsmo_init: failed to load oid mappings: %s",
859 DEBUG(0,(__location__
": %s\n", *error_string
));
860 return LDB_ERR_CONSTRAINT_VIOLATION
;
863 for (i
=0; i
< attrs_res
->count
; i
++) {
864 struct dsdb_attribute
*sa
;
866 sa
= talloc_zero(schema
, struct dsdb_attribute
);
868 dsdb_oom(error_string
, mem_ctx
);
869 return LDB_ERR_OPERATIONS_ERROR
;
872 status
= dsdb_attribute_from_ldb(ldb
, schema
, attrs_res
->msgs
[i
], sa
, sa
);
873 if (!W_ERROR_IS_OK(status
)) {
874 *error_string
= talloc_asprintf(mem_ctx
,
875 "schema_fsmo_init: failed to load attribute definition: %s:%s",
876 ldb_dn_get_linearized(attrs_res
->msgs
[i
]->dn
),
878 DEBUG(0,(__location__
": %s\n", *error_string
));
879 return LDB_ERR_CONSTRAINT_VIOLATION
;
882 DLIST_ADD(schema
->attributes
, sa
);
885 for (i
=0; i
< objectclass_res
->count
; i
++) {
886 struct dsdb_class
*sc
;
888 sc
= talloc_zero(schema
, struct dsdb_class
);
890 dsdb_oom(error_string
, mem_ctx
);
891 return LDB_ERR_OPERATIONS_ERROR
;
894 status
= dsdb_class_from_ldb(schema
, objectclass_res
->msgs
[i
], sc
, sc
);
895 if (!W_ERROR_IS_OK(status
)) {
896 *error_string
= talloc_asprintf(mem_ctx
,
897 "schema_fsmo_init: failed to load class definition: %s:%s",
898 ldb_dn_get_linearized(objectclass_res
->msgs
[i
]->dn
),
900 DEBUG(0,(__location__
": %s\n", *error_string
));
901 return LDB_ERR_CONSTRAINT_VIOLATION
;
904 DLIST_ADD(schema
->classes
, sc
);
907 schema
->fsmo
.master_dn
= ldb_msg_find_attr_as_dn(ldb
, schema
, schema_res
->msgs
[0], "fSMORoleOwner");
908 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb
), schema
->fsmo
.master_dn
) == 0) {
909 schema
->fsmo
.we_are_master
= true;
911 schema
->fsmo
.we_are_master
= false;
914 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
915 (schema
->fsmo
.we_are_master
?"yes":"no")));
917 *schema_out
= schema
;
922 static const struct {
925 } name_mappings
[] = {
927 { "name", "1.2.840.113556.1.4.1" },
928 { "lDAPDisplayName", "1.2.840.113556.1.2.460" },
929 { "attributeID", "1.2.840.113556.1.2.30" },
930 { "schemaIDGUID", "1.2.840.113556.1.4.148" },
931 { "mAPIID", "1.2.840.113556.1.2.49" },
932 { "attributeSecurityGUID", "1.2.840.113556.1.4.149" },
933 { "searchFlags", "1.2.840.113556.1.2.334" },
934 { "systemFlags", "1.2.840.113556.1.4.375" },
935 { "isMemberOfPartialAttributeSet", "1.2.840.113556.1.4.639" },
936 { "linkID", "1.2.840.113556.1.2.50" },
937 { "attributeSyntax", "1.2.840.113556.1.2.32" },
938 { "oMSyntax", "1.2.840.113556.1.2.231" },
939 { "oMObjectClass", "1.2.840.113556.1.2.218" },
940 { "isSingleValued", "1.2.840.113556.1.2.33" },
941 { "rangeLower", "1.2.840.113556.1.2.34" },
942 { "rangeUpper", "1.2.840.113556.1.2.35" },
943 { "extendedCharsAllowed", "1.2.840.113556.1.2.380" },
944 { "schemaFlagsEx", "1.2.840.113556.1.4.120" },
945 { "msDs-Schema-Extensions", "1.2.840.113556.1.4.1440" },
946 { "showInAdvancedViewOnly", "1.2.840.113556.1.2.169" },
947 { "adminDisplayName", "1.2.840.113556.1.2.194" },
948 { "adminDescription", "1.2.840.113556.1.2.226" },
949 { "classDisplayName", "1.2.840.113556.1.4.610" },
950 { "isEphemeral", "1.2.840.113556.1.4.1212" },
951 { "isDefunct", "1.2.840.113556.1.4.661" },
952 { "systemOnly", "1.2.840.113556.1.4.170" },
953 { "governsID", "1.2.840.113556.1.2.22" },
954 { "objectClassCategory", "1.2.840.113556.1.2.370" },
955 { "rDNAttID", "1.2.840.113556.1.2.26" },
956 { "defaultObjectCategory", "1.2.840.113556.1.4.783" },
957 { "subClassOf", "1.2.840.113556.1.2.21" },
958 { "systemAuxiliaryClass", "1.2.840.113556.1.4.198" },
959 { "systemPossSuperiors", "1.2.840.113556.1.4.195" },
960 { "systemMustContain", "1.2.840.113556.1.4.197" },
961 { "systemMayContain", "1.2.840.113556.1.4.196" },
962 { "auxiliaryClass", "1.2.840.113556.1.2.351" },
963 { "possSuperiors", "1.2.840.113556.1.2.8" },
964 { "mustContain", "1.2.840.113556.1.2.24" },
965 { "mayContain", "1.2.840.113556.1.2.25" },
966 { "defaultSecurityDescriptor", "1.2.840.113556.1.4.224" },
967 { "defaultHidingValue", "1.2.840.113556.1.4.518" },
970 static struct drsuapi_DsReplicaAttribute
*dsdb_find_object_attr_name(struct dsdb_schema
*schema
,
971 struct drsuapi_DsReplicaObject
*obj
,
977 const char *oid
= NULL
;
979 for(i
=0; i
< ARRAY_SIZE(name_mappings
); i
++) {
980 if (strcmp(name_mappings
[i
].name
, name
) != 0) continue;
982 oid
= name_mappings
[i
].oid
;
990 status
= dsdb_schema_pfm_make_attid(schema
->prefixmap
, oid
, &attid
);
991 if (!W_ERROR_IS_OK(status
)) {
995 for (i
=0; i
< obj
->attribute_ctr
.num_attributes
; i
++) {
996 if (obj
->attribute_ctr
.attributes
[i
].attid
!= attid
) continue;
999 return &obj
->attribute_ctr
.attributes
[i
];
1005 #define GET_STRING_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1006 struct drsuapi_DsReplicaAttribute *_a; \
1007 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1008 if (strict && !_a) { \
1009 d_printf("%s: %s == NULL\n", __location__, attr); \
1010 return WERR_INVALID_PARAM; \
1012 if (strict && _a->value_ctr.num_values != 1) { \
1013 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1014 _a->value_ctr.num_values); \
1015 return WERR_INVALID_PARAM; \
1017 if (_a && _a->value_ctr.num_values >= 1) { \
1019 if (!convert_string_talloc_convenience(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \
1020 _a->value_ctr.values[0].blob->data, \
1021 _a->value_ctr.values[0].blob->length, \
1022 (void **)discard_const(&(p)->elem), &_ret, false)) { \
1023 DEBUG(0,("%s: invalid data!\n", attr)); \
1025 _a->value_ctr.values[0].blob->data, \
1026 _a->value_ctr.values[0].blob->length); \
1027 return WERR_FOOBAR; \
1034 #define GET_UINT32_LIST_DS(s, r, attr, mem_ctx, p, elem) do { \
1036 struct drsuapi_DsReplicaAttribute *_a; \
1037 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1038 (p)->elem = _a ? talloc_array(mem_ctx, uint32_t, _a->value_ctr.num_values + 1) : NULL; \
1039 for (list_counter=0; \
1040 _a && list_counter < _a->value_ctr.num_values; \
1042 if (_a->value_ctr.values[list_counter].blob->length != 4) { \
1043 return WERR_INVALID_PARAM; \
1045 (p)->elem[list_counter] = IVAL(_a->value_ctr.values[list_counter].blob->data, 0); \
1047 if (_a) (p)->elem[list_counter] = 0; \
1050 #define GET_DN_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1051 struct drsuapi_DsReplicaAttribute *_a; \
1052 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1053 if (strict && !_a) { \
1054 d_printf("%s: %s == NULL\n", __location__, attr); \
1055 return WERR_INVALID_PARAM; \
1057 if (strict && _a->value_ctr.num_values != 1) { \
1058 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1059 _a->value_ctr.num_values); \
1060 return WERR_INVALID_PARAM; \
1062 if (strict && !_a->value_ctr.values[0].blob) { \
1063 d_printf("%s: %s data == NULL\n", __location__, attr); \
1064 return WERR_INVALID_PARAM; \
1066 if (_a && _a->value_ctr.num_values >= 1 \
1067 && _a->value_ctr.values[0].blob) { \
1068 struct drsuapi_DsReplicaObjectIdentifier3 _id3; \
1069 enum ndr_err_code _ndr_err; \
1070 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1071 mem_ctx, s->iconv_convenience, &_id3,\
1072 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);\
1073 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1074 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1075 return ntstatus_to_werror(_nt_status); \
1077 (p)->elem = _id3.dn; \
1083 #define GET_BOOL_DS(s, r, attr, p, elem, strict) do { \
1084 struct drsuapi_DsReplicaAttribute *_a; \
1085 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1086 if (strict && !_a) { \
1087 d_printf("%s: %s == NULL\n", __location__, attr); \
1088 return WERR_INVALID_PARAM; \
1090 if (strict && _a->value_ctr.num_values != 1) { \
1091 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1092 (unsigned int)_a->value_ctr.num_values); \
1093 return WERR_INVALID_PARAM; \
1095 if (strict && !_a->value_ctr.values[0].blob) { \
1096 d_printf("%s: %s data == NULL\n", __location__, attr); \
1097 return WERR_INVALID_PARAM; \
1099 if (strict && _a->value_ctr.values[0].blob->length != 4) { \
1100 d_printf("%s: %s length == %u\n", __location__, attr, \
1101 (unsigned int)_a->value_ctr.values[0].blob->length); \
1102 return WERR_INVALID_PARAM; \
1104 if (_a && _a->value_ctr.num_values >= 1 \
1105 && _a->value_ctr.values[0].blob \
1106 && _a->value_ctr.values[0].blob->length == 4) { \
1107 (p)->elem = (IVAL(_a->value_ctr.values[0].blob->data,0)?true:false);\
1109 (p)->elem = false; \
1113 #define GET_UINT32_DS(s, r, attr, p, elem) do { \
1114 struct drsuapi_DsReplicaAttribute *_a; \
1115 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1116 if (_a && _a->value_ctr.num_values >= 1 \
1117 && _a->value_ctr.values[0].blob \
1118 && _a->value_ctr.values[0].blob->length == 4) { \
1119 (p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1125 #define GET_UINT32_PTR_DS(s, r, attr, p, elem) do { \
1126 struct drsuapi_DsReplicaAttribute *_a; \
1127 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1128 if (_a && _a->value_ctr.num_values >= 1 \
1129 && _a->value_ctr.values[0].blob \
1130 && _a->value_ctr.values[0].blob->length == 4) { \
1131 (p)->elem = talloc(mem_ctx, uint32_t); \
1133 d_printf("%s: talloc failed for %s\n", __location__, attr); \
1134 return WERR_NOMEM; \
1136 *(p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1142 #define GET_GUID_DS(s, r, attr, mem_ctx, p, elem) do { \
1143 struct drsuapi_DsReplicaAttribute *_a; \
1144 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1145 if (_a && _a->value_ctr.num_values >= 1 \
1146 && _a->value_ctr.values[0].blob \
1147 && _a->value_ctr.values[0].blob->length == 16) { \
1148 enum ndr_err_code _ndr_err; \
1149 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1150 mem_ctx, s->iconv_convenience, &(p)->elem, \
1151 (ndr_pull_flags_fn_t)ndr_pull_GUID); \
1152 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1153 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1154 return ntstatus_to_werror(_nt_status); \
1157 ZERO_STRUCT((p)->elem);\
1161 #define GET_BLOB_DS(s, r, attr, mem_ctx, p, elem) do { \
1162 struct drsuapi_DsReplicaAttribute *_a; \
1163 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1164 if (_a && _a->value_ctr.num_values >= 1 \
1165 && _a->value_ctr.values[0].blob) { \
1166 (p)->elem = *_a->value_ctr.values[0].blob;\
1167 talloc_steal(mem_ctx, (p)->elem.data); \
1169 ZERO_STRUCT((p)->elem);\
1173 WERROR
dsdb_attribute_from_drsuapi(struct ldb_context
*ldb
,
1174 struct dsdb_schema
*schema
,
1175 struct drsuapi_DsReplicaObject
*r
,
1176 TALLOC_CTX
*mem_ctx
,
1177 struct dsdb_attribute
*attr
)
1181 GET_STRING_DS(schema
, r
, "name", mem_ctx
, attr
, cn
, true);
1182 GET_STRING_DS(schema
, r
, "lDAPDisplayName", mem_ctx
, attr
, lDAPDisplayName
, true);
1183 GET_UINT32_DS(schema
, r
, "attributeID", attr
, attributeID_id
);
1184 status
= dsdb_map_int2oid(schema
, attr
->attributeID_id
, mem_ctx
, &attr
->attributeID_oid
);
1185 if (!W_ERROR_IS_OK(status
)) {
1186 DEBUG(0,("%s: '%s': unable to map attributeID 0x%08X: %s\n",
1187 __location__
, attr
->lDAPDisplayName
, attr
->attributeID_id
,
1188 win_errstr(status
)));
1191 GET_GUID_DS(schema
, r
, "schemaIDGUID", mem_ctx
, attr
, schemaIDGUID
);
1192 GET_UINT32_DS(schema
, r
, "mAPIID", attr
, mAPIID
);
1194 GET_GUID_DS(schema
, r
, "attributeSecurityGUID", mem_ctx
, attr
, attributeSecurityGUID
);
1196 GET_UINT32_DS(schema
, r
, "searchFlags", attr
, searchFlags
);
1197 GET_UINT32_DS(schema
, r
, "systemFlags", attr
, systemFlags
);
1198 GET_BOOL_DS(schema
, r
, "isMemberOfPartialAttributeSet", attr
, isMemberOfPartialAttributeSet
, false);
1199 GET_UINT32_DS(schema
, r
, "linkID", attr
, linkID
);
1201 GET_UINT32_DS(schema
, r
, "attributeSyntax", attr
, attributeSyntax_id
);
1202 status
= dsdb_map_int2oid(schema
, attr
->attributeSyntax_id
, mem_ctx
, &attr
->attributeSyntax_oid
);
1203 if (!W_ERROR_IS_OK(status
)) {
1204 DEBUG(0,("%s: '%s': unable to map attributeSyntax 0x%08X: %s\n",
1205 __location__
, attr
->lDAPDisplayName
, attr
->attributeSyntax_id
,
1206 win_errstr(status
)));
1209 GET_UINT32_DS(schema
, r
, "oMSyntax", attr
, oMSyntax
);
1210 GET_BLOB_DS(schema
, r
, "oMObjectClass", mem_ctx
, attr
, oMObjectClass
);
1212 GET_BOOL_DS(schema
, r
, "isSingleValued", attr
, isSingleValued
, true);
1213 GET_UINT32_PTR_DS(schema
, r
, "rangeLower", attr
, rangeLower
);
1214 GET_UINT32_PTR_DS(schema
, r
, "rangeUpper", attr
, rangeUpper
);
1215 GET_BOOL_DS(schema
, r
, "extendedCharsAllowed", attr
, extendedCharsAllowed
, false);
1217 GET_UINT32_DS(schema
, r
, "schemaFlagsEx", attr
, schemaFlagsEx
);
1218 GET_BLOB_DS(schema
, r
, "msDs-Schema-Extensions", mem_ctx
, attr
, msDs_Schema_Extensions
);
1220 GET_BOOL_DS(schema
, r
, "showInAdvancedViewOnly", attr
, showInAdvancedViewOnly
, false);
1221 GET_STRING_DS(schema
, r
, "adminDisplayName", mem_ctx
, attr
, adminDisplayName
, false);
1222 GET_STRING_DS(schema
, r
, "adminDescription", mem_ctx
, attr
, adminDescription
, false);
1223 GET_STRING_DS(schema
, r
, "classDisplayName", mem_ctx
, attr
, classDisplayName
, false);
1224 GET_BOOL_DS(schema
, r
, "isEphemeral", attr
, isEphemeral
, false);
1225 GET_BOOL_DS(schema
, r
, "isDefunct", attr
, isDefunct
, false);
1226 GET_BOOL_DS(schema
, r
, "systemOnly", attr
, systemOnly
, false);
1228 attr
->syntax
= dsdb_syntax_for_attribute(attr
);
1229 if (!attr
->syntax
) {
1230 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
1233 if (dsdb_schema_setup_ldb_schema_attribute(ldb
, attr
) != LDB_SUCCESS
) {
1234 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX
;
1240 WERROR
dsdb_class_from_drsuapi(struct dsdb_schema
*schema
,
1241 struct drsuapi_DsReplicaObject
*r
,
1242 TALLOC_CTX
*mem_ctx
,
1243 struct dsdb_class
*obj
)
1247 GET_STRING_DS(schema
, r
, "name", mem_ctx
, obj
, cn
, true);
1248 GET_STRING_DS(schema
, r
, "lDAPDisplayName", mem_ctx
, obj
, lDAPDisplayName
, true);
1249 GET_UINT32_DS(schema
, r
, "governsID", obj
, governsID_id
);
1250 status
= dsdb_map_int2oid(schema
, obj
->governsID_id
, mem_ctx
, &obj
->governsID_oid
);
1251 if (!W_ERROR_IS_OK(status
)) {
1252 DEBUG(0,("%s: '%s': unable to map governsID 0x%08X: %s\n",
1253 __location__
, obj
->lDAPDisplayName
, obj
->governsID_id
,
1254 win_errstr(status
)));
1257 GET_GUID_DS(schema
, r
, "schemaIDGUID", mem_ctx
, obj
, schemaIDGUID
);
1259 GET_UINT32_DS(schema
, r
, "objectClassCategory", obj
, objectClassCategory
);
1260 GET_STRING_DS(schema
, r
, "rDNAttID", mem_ctx
, obj
, rDNAttID
, false);
1261 GET_DN_DS(schema
, r
, "defaultObjectCategory", mem_ctx
, obj
, defaultObjectCategory
, true);
1263 GET_UINT32_DS(schema
, r
, "subClassOf", obj
, subClassOf_id
);
1265 GET_UINT32_LIST_DS(schema
, r
, "systemAuxiliaryClass", mem_ctx
, obj
, systemAuxiliaryClass_ids
);
1266 GET_UINT32_LIST_DS(schema
, r
, "auxiliaryClass", mem_ctx
, obj
, auxiliaryClass_ids
);
1268 GET_UINT32_LIST_DS(schema
, r
, "systemMustContain", mem_ctx
, obj
, systemMustContain_ids
);
1269 GET_UINT32_LIST_DS(schema
, r
, "systemMayContain", mem_ctx
, obj
, systemMayContain_ids
);
1270 GET_UINT32_LIST_DS(schema
, r
, "mustContain", mem_ctx
, obj
, mustContain_ids
);
1271 GET_UINT32_LIST_DS(schema
, r
, "mayContain", mem_ctx
, obj
, mayContain_ids
);
1273 GET_UINT32_LIST_DS(schema
, r
, "systemPossSuperiors", mem_ctx
, obj
, systemPossSuperiors_ids
);
1274 GET_UINT32_LIST_DS(schema
, r
, "possSuperiors", mem_ctx
, obj
, possSuperiors_ids
);
1276 GET_STRING_DS(schema
, r
, "defaultSecurityDescriptor", mem_ctx
, obj
, defaultSecurityDescriptor
, false);
1278 GET_UINT32_DS(schema
, r
, "schemaFlagsEx", obj
, schemaFlagsEx
);
1279 GET_BLOB_DS(schema
, r
, "msDs-Schema-Extensions", mem_ctx
, obj
, msDs_Schema_Extensions
);
1281 GET_BOOL_DS(schema
, r
, "showInAdvancedViewOnly", obj
, showInAdvancedViewOnly
, false);
1282 GET_STRING_DS(schema
, r
, "adminDisplayName", mem_ctx
, obj
, adminDisplayName
, false);
1283 GET_STRING_DS(schema
, r
, "adminDescription", mem_ctx
, obj
, adminDescription
, false);
1284 GET_STRING_DS(schema
, r
, "classDisplayName", mem_ctx
, obj
, classDisplayName
, false);
1285 GET_BOOL_DS(schema
, r
, "defaultHidingValue", obj
, defaultHidingValue
, false);
1286 GET_BOOL_DS(schema
, r
, "isDefunct", obj
, isDefunct
, false);
1287 GET_BOOL_DS(schema
, r
, "systemOnly", obj
, systemOnly
, false);