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"
32 struct dsdb_schema *dsdb_new_schema(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience)
34 struct dsdb_schema *schema = talloc_zero(mem_ctx, struct dsdb_schema);
39 schema->iconv_convenience = iconv_convenience;
44 WERROR dsdb_load_oid_mappings_drsuapi(struct dsdb_schema *schema, const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
48 schema->prefixes = talloc_array(schema, struct dsdb_schema_oid_prefix, ctr->num_mappings);
49 W_ERROR_HAVE_NO_MEMORY(schema->prefixes);
51 for (i=0, j=0; i < ctr->num_mappings; i++) {
52 if (ctr->mappings[i].oid.oid == NULL) {
53 return WERR_INVALID_PARAM;
56 if (strncasecmp(ctr->mappings[i].oid.oid, "ff", 2) == 0) {
57 if (ctr->mappings[i].id_prefix != 0) {
58 return WERR_INVALID_PARAM;
61 /* the magic value should be in the last array member */
62 if (i != (ctr->num_mappings - 1)) {
63 return WERR_INVALID_PARAM;
66 if (ctr->mappings[i].oid.__ndr_size != 21) {
67 return WERR_INVALID_PARAM;
70 schema->schema_info = talloc_strdup(schema, ctr->mappings[i].oid.oid);
71 W_ERROR_HAVE_NO_MEMORY(schema->schema_info);
73 /* the last array member should contain the magic value not a oid */
74 if (i == (ctr->num_mappings - 1)) {
75 return WERR_INVALID_PARAM;
78 schema->prefixes[j].id = ctr->mappings[i].id_prefix<<16;
79 schema->prefixes[j].oid = talloc_asprintf(schema->prefixes, "%s.",
80 ctr->mappings[i].oid.oid);
81 W_ERROR_HAVE_NO_MEMORY(schema->prefixes[j].oid);
82 schema->prefixes[j].oid_len = strlen(schema->prefixes[j].oid);
87 schema->num_prefixes = j;
91 WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
92 const struct ldb_val *prefixMap,
93 const struct ldb_val *schemaInfo)
96 enum ndr_err_code ndr_err;
97 struct prefixMapBlob pfm;
100 TALLOC_CTX *mem_ctx = talloc_new(schema);
101 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
103 ndr_err = ndr_pull_struct_blob(prefixMap, mem_ctx, schema->iconv_convenience, &pfm, (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
104 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
105 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
106 talloc_free(mem_ctx);
107 return ntstatus_to_werror(nt_status);
110 if (pfm.version != PREFIX_MAP_VERSION_DSDB) {
111 talloc_free(mem_ctx);
115 if (schemaInfo->length != 21 && schemaInfo->data[0] == 0xFF) {
116 talloc_free(mem_ctx);
120 /* append the schema info as last element */
121 pfm.ctr.dsdb.num_mappings++;
122 pfm.ctr.dsdb.mappings = talloc_realloc(mem_ctx, pfm.ctr.dsdb.mappings,
123 struct drsuapi_DsReplicaOIDMapping,
124 pfm.ctr.dsdb.num_mappings);
125 W_ERROR_HAVE_NO_MEMORY(pfm.ctr.dsdb.mappings);
127 schema_info = data_blob_hex_string(pfm.ctr.dsdb.mappings, schemaInfo);
128 W_ERROR_HAVE_NO_MEMORY(schema_info);
130 pfm.ctr.dsdb.mappings[pfm.ctr.dsdb.num_mappings - 1].id_prefix = 0;
131 pfm.ctr.dsdb.mappings[pfm.ctr.dsdb.num_mappings - 1].oid.__ndr_size = schemaInfo->length;
132 pfm.ctr.dsdb.mappings[pfm.ctr.dsdb.num_mappings - 1].oid.oid = schema_info;
134 /* call the drsuapi version */
135 status = dsdb_load_oid_mappings_drsuapi(schema, &pfm.ctr.dsdb);
136 talloc_free(mem_ctx);
138 W_ERROR_NOT_OK_RETURN(status);
143 WERROR dsdb_get_oid_mappings_drsuapi(const struct dsdb_schema *schema,
144 bool include_schema_info,
146 struct drsuapi_DsReplicaOIDMapping_Ctr **_ctr)
148 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
151 ctr = talloc(mem_ctx, struct drsuapi_DsReplicaOIDMapping_Ctr);
152 W_ERROR_HAVE_NO_MEMORY(ctr);
154 ctr->num_mappings = schema->num_prefixes;
155 if (include_schema_info) ctr->num_mappings++;
156 ctr->mappings = talloc_array(schema, struct drsuapi_DsReplicaOIDMapping, ctr->num_mappings);
157 W_ERROR_HAVE_NO_MEMORY(ctr->mappings);
159 for (i=0; i < schema->num_prefixes; i++) {
160 ctr->mappings[i].id_prefix = schema->prefixes[i].id>>16;
161 ctr->mappings[i].oid.oid = talloc_strndup(ctr->mappings,
162 schema->prefixes[i].oid,
163 schema->prefixes[i].oid_len - 1);
164 W_ERROR_HAVE_NO_MEMORY(ctr->mappings[i].oid.oid);
167 if (include_schema_info) {
168 ctr->mappings[i].id_prefix = 0;
169 ctr->mappings[i].oid.oid = talloc_strdup(ctr->mappings,
170 schema->schema_info);
171 W_ERROR_HAVE_NO_MEMORY(ctr->mappings[i].oid.oid);
178 WERROR dsdb_get_oid_mappings_ldb(const struct dsdb_schema *schema,
180 struct ldb_val *prefixMap,
181 struct ldb_val *schemaInfo)
184 enum ndr_err_code ndr_err;
185 struct drsuapi_DsReplicaOIDMapping_Ctr *ctr;
186 struct prefixMapBlob pfm;
188 status = dsdb_get_oid_mappings_drsuapi(schema, false, mem_ctx, &ctr);
189 W_ERROR_NOT_OK_RETURN(status);
191 pfm.version = PREFIX_MAP_VERSION_DSDB;
195 ndr_err = ndr_push_struct_blob(prefixMap, mem_ctx, schema->iconv_convenience, &pfm, (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
197 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
198 NTSTATUS nt_status = ndr_map_error2ntstatus(ndr_err);
199 return ntstatus_to_werror(nt_status);
202 *schemaInfo = strhex_to_data_blob(mem_ctx, schema->schema_info);
203 W_ERROR_HAVE_NO_MEMORY(schemaInfo->data);
208 WERROR dsdb_verify_oid_mappings_drsuapi(const struct dsdb_schema *schema, const struct drsuapi_DsReplicaOIDMapping_Ctr *ctr)
212 for (i=0; i < ctr->num_mappings; i++) {
213 if (ctr->mappings[i].oid.oid == NULL) {
214 return WERR_INVALID_PARAM;
217 if (strncasecmp(ctr->mappings[i].oid.oid, "ff", 2) == 0) {
218 if (ctr->mappings[i].id_prefix != 0) {
219 return WERR_INVALID_PARAM;
222 /* the magic value should be in the last array member */
223 if (i != (ctr->num_mappings - 1)) {
224 return WERR_INVALID_PARAM;
227 if (ctr->mappings[i].oid.__ndr_size != 21) {
228 return WERR_INVALID_PARAM;
231 if (strcasecmp(schema->schema_info, ctr->mappings[i].oid.oid) != 0) {
232 return WERR_DS_DRA_SCHEMA_MISMATCH;
235 /* the last array member should contain the magic value not a oid */
236 if (i == (ctr->num_mappings - 1)) {
237 return WERR_INVALID_PARAM;
240 for (j=0; j < schema->num_prefixes; j++) {
242 if (schema->prefixes[j].id != (ctr->mappings[i].id_prefix<<16)) {
246 oid_len = strlen(ctr->mappings[i].oid.oid);
248 if (oid_len != (schema->prefixes[j].oid_len - 1)) {
249 return WERR_DS_DRA_SCHEMA_MISMATCH;
252 if (strncmp(ctr->mappings[i].oid.oid, schema->prefixes[j].oid, oid_len) != 0) {
253 return WERR_DS_DRA_SCHEMA_MISMATCH;
259 if (j == schema->num_prefixes) {
260 return WERR_DS_DRA_SCHEMA_MISMATCH;
268 WERROR dsdb_map_oid2int(const struct dsdb_schema *schema, const char *in, uint32_t *out)
270 return dsdb_find_prefix_for_oid(schema->num_prefixes, schema->prefixes, in, out);
274 WERROR dsdb_map_int2oid(const struct dsdb_schema *schema, uint32_t in, TALLOC_CTX *mem_ctx, const char **out)
278 for (i=0; i < schema->num_prefixes; i++) {
280 if (schema->prefixes[i].id != (in & 0xFFFF0000)) {
284 val = talloc_asprintf(mem_ctx, "%s%u",
285 schema->prefixes[i].oid,
287 W_ERROR_HAVE_NO_MEMORY(val);
293 return WERR_DS_NO_MSDS_INTID;
297 * this function is called from within a ldb transaction from the schema_fsmo module
299 WERROR dsdb_create_prefix_mapping(struct ldb_context *ldb, struct dsdb_schema *schema, const char *full_oid)
302 uint32_t num_prefixes;
303 struct dsdb_schema_oid_prefix *prefixes;
307 mem_ctx = talloc_new(ldb);
308 W_ERROR_HAVE_NO_MEMORY(mem_ctx);
310 /* Read prefixes from disk*/
311 status = dsdb_read_prefixes_from_ldb( mem_ctx, ldb, &num_prefixes, &prefixes );
312 if (!W_ERROR_IS_OK(status)) {
313 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_read_prefixes_from_ldb: %s\n",
314 win_errstr(status)));
315 talloc_free(mem_ctx);
319 /* Check if there is a prefix for the oid in the prefixes array*/
320 status = dsdb_find_prefix_for_oid( num_prefixes, prefixes, full_oid, &out );
321 if (W_ERROR_IS_OK(status)) {
323 talloc_free(mem_ctx);
325 } else if (!W_ERROR_EQUAL(WERR_DS_NO_MSDS_INTID, status)) {
327 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_find_prefix_for_oid: %s\n",
328 win_errstr(status)));
329 talloc_free(mem_ctx);
333 /* Create the new mapping for the prefix of full_oid */
334 status = dsdb_prefix_map_update(mem_ctx, &num_prefixes, &prefixes, full_oid);
335 if (!W_ERROR_IS_OK(status)) {
336 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_prefix_map_update: %s\n",
337 win_errstr(status)));
338 talloc_free(mem_ctx);
342 /* Update prefixMap in ldb*/
343 status = dsdb_write_prefixes_to_ldb(mem_ctx, ldb, num_prefixes, prefixes);
344 if (!W_ERROR_IS_OK(status)) {
345 DEBUG(0,("dsdb_create_prefix_mapping: dsdb_write_prefixes_to_ldb: %s\n",
346 win_errstr(status)));
347 talloc_free(mem_ctx);
351 talloc_free(mem_ctx);
355 WERROR dsdb_prefix_map_update(TALLOC_CTX *mem_ctx, uint32_t *num_prefixes, struct dsdb_schema_oid_prefix **prefixes, const char *oid)
357 uint32_t new_num_prefixes, index_new_prefix, new_entry_id;
358 const char* lastDotOffset;
361 new_num_prefixes = *num_prefixes + 1;
362 index_new_prefix = *num_prefixes;
365 * this is the algorithm we use to create new mappings for now
367 * TODO: find what algorithm windows use
369 new_entry_id = (*num_prefixes)<<16;
371 /* Extract the prefix from the oid*/
372 lastDotOffset = strrchr(oid, '.');
373 if (lastDotOffset == NULL) {
374 DEBUG(0,("dsdb_prefix_map_update: failed to find the last dot\n"));
375 return WERR_NOT_FOUND;
378 /* Calculate the size of the remainig string that should be the prefix of it */
379 size = strlen(oid) - strlen(lastDotOffset);
381 DEBUG(0,("dsdb_prefix_map_update: size of the remaining string invalid\n"));
384 /* Add one because we need to copy the dot */
387 /* Create a spot in the prefixMap for one more prefix*/
388 (*prefixes) = talloc_realloc(mem_ctx, *prefixes, struct dsdb_schema_oid_prefix, new_num_prefixes);
389 W_ERROR_HAVE_NO_MEMORY(*prefixes);
391 /* Add the new prefix entry*/
392 (*prefixes)[index_new_prefix].id = new_entry_id;
393 (*prefixes)[index_new_prefix].oid = talloc_strndup(mem_ctx, oid, size);
394 (*prefixes)[index_new_prefix].oid_len = strlen((*prefixes)[index_new_prefix].oid);
396 /* Increase num_prefixes because new prefix has been added */
402 WERROR dsdb_find_prefix_for_oid(uint32_t num_prefixes, const struct dsdb_schema_oid_prefix *prefixes, const char *in, uint32_t *out)
406 for (i=0; i < num_prefixes; i++) {
411 if (strncmp(prefixes[i].oid, in, prefixes[i].oid_len) != 0) {
415 val_str = in + prefixes[i].oid_len;
419 if (val_str[0] == '\0') {
420 return WERR_INVALID_PARAM;
423 /* two '.' chars are invalid */
424 if (val_str[0] == '.') {
425 return WERR_INVALID_PARAM;
428 val = strtoul(val_str, &end_str, 10);
429 if (end_str[0] == '.' && end_str[1] != '\0') {
431 * if it's a '.' and not the last char
432 * then maybe an other mapping apply
435 } else if (end_str[0] != '\0') {
436 return WERR_INVALID_PARAM;
437 } else if (val > 0xFFFF) {
438 return WERR_INVALID_PARAM;
441 *out = prefixes[i].id | val;
445 return WERR_DS_NO_MSDS_INTID;
448 WERROR dsdb_write_prefixes_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
449 uint32_t num_prefixes,
450 const struct dsdb_schema_oid_prefix *prefixes)
452 struct ldb_message msg;
453 struct ldb_dn *schema_dn;
454 struct ldb_message_element el;
455 struct prefixMapBlob pm;
456 struct ldb_val ndr_blob;
457 enum ndr_err_code ndr_err;
461 schema_dn = samdb_schema_dn(ldb);
463 DEBUG(0,("dsdb_write_prefixes_to_ldb: no schema dn present\n"));
467 pm.version = PREFIX_MAP_VERSION_DSDB;
468 pm.ctr.dsdb.num_mappings = num_prefixes;
469 pm.ctr.dsdb.mappings = talloc_array(mem_ctx,
470 struct drsuapi_DsReplicaOIDMapping,
471 pm.ctr.dsdb.num_mappings);
472 if (!pm.ctr.dsdb.mappings) {
476 for (i=0; i < num_prefixes; i++) {
477 pm.ctr.dsdb.mappings[i].id_prefix = prefixes[i].id>>16;
478 pm.ctr.dsdb.mappings[i].oid.oid = talloc_strdup(pm.ctr.dsdb.mappings, prefixes[i].oid);
481 ndr_err = ndr_push_struct_blob(&ndr_blob, ldb,
482 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
484 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
485 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
490 el.values = &ndr_blob;
491 el.flags = LDB_FLAG_MOD_REPLACE;
492 el.name = talloc_strdup(mem_ctx, "prefixMap");
494 msg.dn = ldb_dn_copy(mem_ctx, schema_dn);
495 msg.num_elements = 1;
498 ret = ldb_modify( ldb, &msg );
500 DEBUG(0,("dsdb_write_prefixes_to_ldb: ldb_modify failed\n"));
507 WERROR dsdb_read_prefixes_from_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, uint32_t* num_prefixes, struct dsdb_schema_oid_prefix **prefixes)
509 struct prefixMapBlob *blob;
510 enum ndr_err_code ndr_err;
512 const struct ldb_val *prefix_val;
513 struct ldb_dn *schema_dn;
514 struct ldb_result *schema_res;
516 static const char *schema_attrs[] = {
521 schema_dn = samdb_schema_dn(ldb);
523 DEBUG(0,("dsdb_read_prefixes_from_ldb: no schema dn present\n"));
527 ret = ldb_search(ldb, mem_ctx, &schema_res, schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
528 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
529 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefix map present\n"));
530 talloc_free(schema_res);
532 } else if (ret != LDB_SUCCESS) {
533 DEBUG(0,("dsdb_read_prefixes_from_ldb: failed to search the schema head\n"));
534 talloc_free(schema_res);
538 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
540 DEBUG(0,("dsdb_read_prefixes_from_ldb: no prefixMap attribute found\n"));
541 talloc_free(schema_res);
545 blob = talloc(mem_ctx, struct prefixMapBlob);
546 W_ERROR_HAVE_NO_MEMORY(blob);
548 ndr_err = ndr_pull_struct_blob(prefix_val, blob,
549 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
551 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
552 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
553 DEBUG(0,("dsdb_read_prefixes_from_ldb: ndr_pull_struct_blob failed\n"));
555 talloc_free(schema_res);
559 talloc_free(schema_res);
561 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
562 DEBUG(0,("dsdb_read_prefixes_from_ldb: blob->version incorect\n"));
567 *num_prefixes = blob->ctr.dsdb.num_mappings;
568 *prefixes = talloc_array(mem_ctx, struct dsdb_schema_oid_prefix, *num_prefixes);
573 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
575 (*prefixes)[i].id = blob->ctr.dsdb.mappings[i].id_prefix<<16;
576 oid = talloc_strdup(mem_ctx, blob->ctr.dsdb.mappings[i].oid.oid);
577 (*prefixes)[i].oid = talloc_asprintf_append(oid, ".");
578 (*prefixes)[i].oid_len = strlen(blob->ctr.dsdb.mappings[i].oid.oid);
585 #define GET_STRING_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
586 (p)->elem = samdb_result_string(msg, attr, NULL);\
587 if (strict && (p)->elem == NULL) { \
588 d_printf("%s: %s == NULL\n", __location__, attr); \
589 return WERR_INVALID_PARAM; \
591 talloc_steal(mem_ctx, (p)->elem); \
594 #define GET_STRING_LIST_LDB(msg, attr, mem_ctx, p, elem, strict) do { \
595 int get_string_list_counter; \
596 struct ldb_message_element *get_string_list_el = ldb_msg_find_element(msg, attr); \
597 if (get_string_list_el == NULL) { \
599 d_printf("%s: %s == NULL\n", __location__, attr); \
600 return WERR_INVALID_PARAM; \
606 (p)->elem = talloc_array(mem_ctx, const char *, get_string_list_el->num_values + 1); \
607 for (get_string_list_counter=0; \
608 get_string_list_counter < get_string_list_el->num_values; \
609 get_string_list_counter++) { \
610 (p)->elem[get_string_list_counter] = talloc_strndup((p)->elem, \
611 (const char *)get_string_list_el->values[get_string_list_counter].data, \
612 get_string_list_el->values[get_string_list_counter].length); \
613 if (!(p)->elem[get_string_list_counter]) { \
614 d_printf("%s: talloc_strndup failed for %s\n", __location__, attr); \
617 (p)->elem[get_string_list_counter+1] = NULL; \
619 talloc_steal(mem_ctx, (p)->elem); \
622 #define GET_BOOL_LDB(msg, attr, p, elem, strict) do { \
624 str = samdb_result_string(msg, attr, NULL);\
627 d_printf("%s: %s == NULL\n", __location__, attr); \
628 return WERR_INVALID_PARAM; \
632 } else if (strcasecmp("TRUE", str) == 0) { \
634 } else if (strcasecmp("FALSE", str) == 0) { \
637 d_printf("%s: %s == %s\n", __location__, attr, str); \
638 return WERR_INVALID_PARAM; \
642 #define GET_UINT32_LDB(msg, attr, p, elem) do { \
643 (p)->elem = samdb_result_uint(msg, attr, 0);\
646 #define GET_GUID_LDB(msg, attr, p, elem) do { \
647 (p)->elem = samdb_result_guid(msg, attr);\
650 #define GET_BLOB_LDB(msg, attr, mem_ctx, p, elem) do { \
651 const struct ldb_val *_val;\
652 _val = ldb_msg_find_ldb_val(msg, attr);\
655 talloc_steal(mem_ctx, (p)->elem.data);\
657 ZERO_STRUCT((p)->elem);\
661 WERROR dsdb_attribute_from_ldb(const struct dsdb_schema *schema,
662 struct ldb_message *msg,
664 struct dsdb_attribute *attr)
668 GET_STRING_LDB(msg, "cn", mem_ctx, attr, cn, false);
669 GET_STRING_LDB(msg, "lDAPDisplayName", mem_ctx, attr, lDAPDisplayName, true);
670 GET_STRING_LDB(msg, "attributeID", mem_ctx, attr, attributeID_oid, true);
671 if (schema->num_prefixes == 0) {
672 /* set an invalid value */
673 attr->attributeID_id = 0xFFFFFFFF;
675 status = dsdb_map_oid2int(schema, attr->attributeID_oid, &attr->attributeID_id);
676 if (!W_ERROR_IS_OK(status)) {
677 DEBUG(0,("%s: '%s': unable to map attributeID %s: %s\n",
678 __location__, attr->lDAPDisplayName, attr->attributeID_oid,
679 win_errstr(status)));
683 GET_GUID_LDB(msg, "schemaIDGUID", attr, schemaIDGUID);
684 GET_UINT32_LDB(msg, "mAPIID", attr, mAPIID);
686 GET_GUID_LDB(msg, "attributeSecurityGUID", attr, attributeSecurityGUID);
688 GET_UINT32_LDB(msg, "searchFlags", attr, searchFlags);
689 GET_UINT32_LDB(msg, "systemFlags", attr, systemFlags);
690 GET_BOOL_LDB(msg, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
691 GET_UINT32_LDB(msg, "linkID", attr, linkID);
693 GET_STRING_LDB(msg, "attributeSyntax", mem_ctx, attr, attributeSyntax_oid, true);
694 if (schema->num_prefixes == 0) {
695 /* set an invalid value */
696 attr->attributeSyntax_id = 0xFFFFFFFF;
698 status = dsdb_map_oid2int(schema, attr->attributeSyntax_oid, &attr->attributeSyntax_id);
699 if (!W_ERROR_IS_OK(status)) {
700 DEBUG(0,("%s: '%s': unable to map attributeSyntax_ %s: %s\n",
701 __location__, attr->lDAPDisplayName, attr->attributeSyntax_oid,
702 win_errstr(status)));
706 GET_UINT32_LDB(msg, "oMSyntax", attr, oMSyntax);
707 GET_BLOB_LDB(msg, "oMObjectClass", mem_ctx, attr, oMObjectClass);
709 GET_BOOL_LDB(msg, "isSingleValued", attr, isSingleValued, true);
710 GET_UINT32_LDB(msg, "rangeLower", attr, rangeLower);
711 GET_UINT32_LDB(msg, "rangeUpper", attr, rangeUpper);
712 GET_BOOL_LDB(msg, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
714 GET_UINT32_LDB(msg, "schemaFlagsEx", attr, schemaFlagsEx);
715 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", mem_ctx, attr, msDs_Schema_Extensions);
717 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
718 GET_STRING_LDB(msg, "adminDisplayName", mem_ctx, attr, adminDisplayName, false);
719 GET_STRING_LDB(msg, "adminDescription", mem_ctx, attr, adminDescription, false);
720 GET_STRING_LDB(msg, "classDisplayName", mem_ctx, attr, classDisplayName, false);
721 GET_BOOL_LDB(msg, "isEphemeral", attr, isEphemeral, false);
722 GET_BOOL_LDB(msg, "isDefunct", attr, isDefunct, false);
723 GET_BOOL_LDB(msg, "systemOnly", attr, systemOnly, false);
725 attr->syntax = dsdb_syntax_for_attribute(attr);
727 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
733 WERROR dsdb_class_from_ldb(const struct dsdb_schema *schema,
734 struct ldb_message *msg,
736 struct dsdb_class *obj)
740 GET_STRING_LDB(msg, "cn", mem_ctx, obj, cn, false);
741 GET_STRING_LDB(msg, "lDAPDisplayName", mem_ctx, obj, lDAPDisplayName, true);
742 GET_STRING_LDB(msg, "governsID", mem_ctx, obj, governsID_oid, true);
743 if (schema->num_prefixes == 0) {
744 /* set an invalid value */
745 obj->governsID_id = 0xFFFFFFFF;
747 status = dsdb_map_oid2int(schema, obj->governsID_oid, &obj->governsID_id);
748 if (!W_ERROR_IS_OK(status)) {
749 DEBUG(0,("%s: '%s': unable to map governsID %s: %s\n",
750 __location__, obj->lDAPDisplayName, obj->governsID_oid,
751 win_errstr(status)));
755 GET_GUID_LDB(msg, "schemaIDGUID", obj, schemaIDGUID);
757 GET_UINT32_LDB(msg, "objectClassCategory", obj, objectClassCategory);
758 GET_STRING_LDB(msg, "rDNAttID", mem_ctx, obj, rDNAttID, false);
759 GET_STRING_LDB(msg, "defaultObjectCategory", mem_ctx, obj, defaultObjectCategory, true);
761 GET_STRING_LDB(msg, "subClassOf", mem_ctx, obj, subClassOf, true);
763 GET_STRING_LIST_LDB(msg, "systemAuxiliaryClass", mem_ctx, obj, systemAuxiliaryClass, false);
764 GET_STRING_LIST_LDB(msg, "auxiliaryClass", mem_ctx, obj, auxiliaryClass, false);
766 GET_STRING_LIST_LDB(msg, "systemMustContain", mem_ctx, obj, systemMustContain, false);
767 GET_STRING_LIST_LDB(msg, "systemMayContain", mem_ctx, obj, systemMayContain, false);
768 GET_STRING_LIST_LDB(msg, "mustContain", mem_ctx, obj, mustContain, false);
769 GET_STRING_LIST_LDB(msg, "mayContain", mem_ctx, obj, mayContain, false);
771 GET_STRING_LIST_LDB(msg, "systemPossSuperiors", mem_ctx, obj, systemPossSuperiors, false);
772 GET_STRING_LIST_LDB(msg, "possSuperiors", mem_ctx, obj, possSuperiors, false);
773 GET_STRING_LIST_LDB(msg, "possibleInferiors", mem_ctx, obj, possibleInferiors, false);
775 GET_STRING_LDB(msg, "defaultSecurityDescriptor", mem_ctx, obj, defaultSecurityDescriptor, false);
777 GET_UINT32_LDB(msg, "schemaFlagsEx", obj, schemaFlagsEx);
778 GET_BLOB_LDB(msg, "msDs-Schema-Extensions", mem_ctx, obj, msDs_Schema_Extensions);
780 GET_BOOL_LDB(msg, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
781 GET_STRING_LDB(msg, "adminDisplayName", mem_ctx, obj, adminDisplayName, false);
782 GET_STRING_LDB(msg, "adminDescription", mem_ctx, obj, adminDescription, false);
783 GET_STRING_LDB(msg, "classDisplayName", mem_ctx, obj, classDisplayName, false);
784 GET_BOOL_LDB(msg, "defaultHidingValue", obj, defaultHidingValue, false);
785 GET_BOOL_LDB(msg, "isDefunct", obj, isDefunct, false);
786 GET_BOOL_LDB(msg, "systemOnly", obj, systemOnly, false);
791 #define dsdb_oom(error_string, mem_ctx) *error_string = talloc_asprintf(mem_ctx, "dsdb out of memory at %s:%d\n", __FILE__, __LINE__)
793 int dsdb_schema_from_ldb_results(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
794 struct smb_iconv_convenience *iconv_convenience,
795 struct ldb_result *schema_res,
796 struct ldb_result *attrs_res, struct ldb_result *objectclass_res,
797 struct dsdb_schema **schema_out,
802 const struct ldb_val *prefix_val;
803 const struct ldb_val *info_val;
804 struct ldb_val info_val_default;
805 struct dsdb_schema *schema;
807 schema = dsdb_new_schema(mem_ctx, iconv_convenience);
809 dsdb_oom(error_string, mem_ctx);
810 return LDB_ERR_OPERATIONS_ERROR;
813 prefix_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "prefixMap");
815 *error_string = talloc_asprintf(mem_ctx,
816 "schema_fsmo_init: no prefixMap attribute found");
817 return LDB_ERR_CONSTRAINT_VIOLATION;
819 info_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
821 info_val_default = strhex_to_data_blob(mem_ctx, "FF0000000000000000000000000000000000000000");
822 if (!info_val_default.data) {
823 dsdb_oom(error_string, mem_ctx);
824 return LDB_ERR_OPERATIONS_ERROR;
826 info_val = &info_val_default;
829 status = dsdb_load_oid_mappings_ldb(schema, prefix_val, info_val);
830 if (!W_ERROR_IS_OK(status)) {
831 *error_string = talloc_asprintf(mem_ctx,
832 "schema_fsmo_init: failed to load oid mappings: %s",
834 return LDB_ERR_CONSTRAINT_VIOLATION;
837 for (i=0; i < attrs_res->count; i++) {
838 struct dsdb_attribute *sa;
840 sa = talloc_zero(schema, struct dsdb_attribute);
842 dsdb_oom(error_string, mem_ctx);
843 return LDB_ERR_OPERATIONS_ERROR;
846 status = dsdb_attribute_from_ldb(schema, attrs_res->msgs[i], sa, sa);
847 if (!W_ERROR_IS_OK(status)) {
848 *error_string = talloc_asprintf(mem_ctx,
849 "schema_fsmo_init: failed to load attribute definition: %s:%s",
850 ldb_dn_get_linearized(attrs_res->msgs[i]->dn),
852 return LDB_ERR_CONSTRAINT_VIOLATION;
855 DLIST_ADD_END(schema->attributes, sa, struct dsdb_attribute *);
858 for (i=0; i < objectclass_res->count; i++) {
859 struct dsdb_class *sc;
861 sc = talloc_zero(schema, struct dsdb_class);
863 dsdb_oom(error_string, mem_ctx);
864 return LDB_ERR_OPERATIONS_ERROR;
867 status = dsdb_class_from_ldb(schema, objectclass_res->msgs[i], sc, sc);
868 if (!W_ERROR_IS_OK(status)) {
869 *error_string = talloc_asprintf(mem_ctx,
870 "schema_fsmo_init: failed to load class definition: %s:%s",
871 ldb_dn_get_linearized(objectclass_res->msgs[i]->dn),
873 return LDB_ERR_CONSTRAINT_VIOLATION;
876 DLIST_ADD_END(schema->classes, sc, struct dsdb_class *);
879 schema->fsmo.master_dn = ldb_msg_find_attr_as_dn(ldb, schema, schema_res->msgs[0], "fSMORoleOwner");
880 if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), schema->fsmo.master_dn) == 0) {
881 schema->fsmo.we_are_master = true;
883 schema->fsmo.we_are_master = false;
886 DEBUG(5, ("schema_fsmo_init: we are master: %s\n",
887 (schema->fsmo.we_are_master?"yes":"no")));
889 *schema_out = schema;
893 /* This recursive load of the objectClasses presumes that they
894 * everything is in a strict subClassOf hirarchy.
896 * We load this in order so we produce certain outputs (such as the
897 * exported schema for openldap, and sorted objectClass attribute) 'in
900 static int fetch_oc_recursive(struct ldb_context *ldb, struct ldb_dn *schemadn,
902 struct ldb_result *search_from,
903 struct ldb_result *res_list)
907 for (i=0; i < search_from->count; i++) {
908 struct ldb_result *res;
909 const char *name = ldb_msg_find_attr_as_string(search_from->msgs[i],
910 "lDAPDisplayname", NULL);
912 ret = ldb_search(ldb, mem_ctx, &res,
913 schemadn, LDB_SCOPE_SUBTREE, NULL,
914 "(&(&(objectClass=classSchema)(subClassOf=%s))(!(lDAPDisplayName=%s)))",
916 if (ret != LDB_SUCCESS) {
920 res_list->msgs = talloc_realloc(res_list, res_list->msgs,
921 struct ldb_message *, res_list->count + 2);
922 if (!res_list->msgs) {
923 return LDB_ERR_OPERATIONS_ERROR;
925 res_list->msgs[res_list->count] = talloc_move(res_list,
926 &search_from->msgs[i]);
928 res_list->msgs[res_list->count] = NULL;
930 if (res->count > 0) {
931 ret = fetch_oc_recursive(ldb, schemadn, mem_ctx, res, res_list);
933 if (ret != LDB_SUCCESS) {
940 static int fetch_objectclass_schema(struct ldb_context *ldb, struct ldb_dn *schemadn,
942 struct ldb_result **objectclasses_res,
945 TALLOC_CTX *local_ctx = talloc_new(mem_ctx);
946 struct ldb_result *top_res, *ret_res;
949 return LDB_ERR_OPERATIONS_ERROR;
953 ret = ldb_search(ldb, local_ctx, &top_res,
954 schemadn, LDB_SCOPE_SUBTREE, NULL,
955 "(&(objectClass=classSchema)(lDAPDisplayName=top))");
956 if (ret != LDB_SUCCESS) {
957 *error_string = talloc_asprintf(mem_ctx,
958 "dsdb_schema: failed to search for top classSchema object: %s",
963 if (top_res->count != 1) {
964 *error_string = talloc_asprintf(mem_ctx,
965 "dsdb_schema: failed to find top classSchema object");
966 return LDB_ERR_NO_SUCH_OBJECT;
969 ret_res = talloc_zero(local_ctx, struct ldb_result);
971 return LDB_ERR_OPERATIONS_ERROR;
974 ret = fetch_oc_recursive(ldb, schemadn, local_ctx, top_res, ret_res);
976 if (ret != LDB_SUCCESS) {
980 *objectclasses_res = talloc_move(mem_ctx, &ret_res);
984 int dsdb_schema_from_schema_dn(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
985 struct smb_iconv_convenience *iconv_convenience,
986 struct ldb_dn *schema_dn,
987 struct dsdb_schema **schema,
988 char **error_string_out)
994 struct ldb_result *schema_res;
995 struct ldb_result *a_res;
996 struct ldb_result *c_res;
997 static const char *schema_attrs[] = {
1004 tmp_ctx = talloc_new(mem_ctx);
1006 dsdb_oom(error_string_out, mem_ctx);
1007 return LDB_ERR_OPERATIONS_ERROR;
1011 * setup the prefix mappings and schema info
1013 ret = ldb_search(ldb, tmp_ctx, &schema_res,
1014 schema_dn, LDB_SCOPE_BASE, schema_attrs, NULL);
1015 if (ret == LDB_ERR_NO_SUCH_OBJECT) {
1016 talloc_free(tmp_ctx);
1018 } else if (ret != LDB_SUCCESS) {
1019 *error_string_out = talloc_asprintf(mem_ctx,
1020 "dsdb_schema: failed to search the schema head: %s",
1021 ldb_errstring(ldb));
1022 talloc_free(tmp_ctx);
1025 if (schema_res->count != 1) {
1026 *error_string_out = talloc_asprintf(mem_ctx,
1027 "dsdb_schema: [%u] schema heads found on a base search",
1029 talloc_free(tmp_ctx);
1030 return LDB_ERR_CONSTRAINT_VIOLATION;
1034 * load the attribute definitions
1036 ret = ldb_search(ldb, tmp_ctx, &a_res,
1037 schema_dn, LDB_SCOPE_ONELEVEL, NULL,
1038 "(objectClass=attributeSchema)");
1039 if (ret != LDB_SUCCESS) {
1040 *error_string_out = talloc_asprintf(mem_ctx,
1041 "dsdb_schema: failed to search attributeSchema objects: %s",
1042 ldb_errstring(ldb));
1043 talloc_free(tmp_ctx);
1048 * load the objectClass definitions
1050 ret = fetch_objectclass_schema(ldb, schema_dn, tmp_ctx, &c_res, &error_string);
1051 if (ret != LDB_SUCCESS) {
1052 *error_string_out = talloc_asprintf(mem_ctx,
1053 "Failed to fetch objectClass schema elements: %s", error_string);
1054 talloc_free(tmp_ctx);
1058 ret = dsdb_schema_from_ldb_results(tmp_ctx, ldb,
1059 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
1060 schema_res, a_res, c_res, schema, &error_string);
1061 if (ret != LDB_SUCCESS) {
1062 *error_string_out = talloc_asprintf(mem_ctx,
1063 "dsdb_schema load failed: %s",
1065 talloc_free(tmp_ctx);
1068 talloc_steal(mem_ctx, *schema);
1069 talloc_free(tmp_ctx);
1075 static const struct {
1078 } name_mappings[] = {
1079 { "cn", "2.5.4.3" },
1080 { "name", "1.2.840.113556.1.4.1" },
1081 { "lDAPDisplayName", "1.2.840.113556.1.2.460" },
1082 { "attributeID", "1.2.840.113556.1.2.30" },
1083 { "schemaIDGUID", "1.2.840.113556.1.4.148" },
1084 { "mAPIID", "1.2.840.113556.1.2.49" },
1085 { "attributeSecurityGUID", "1.2.840.113556.1.4.149" },
1086 { "searchFlags", "1.2.840.113556.1.2.334" },
1087 { "systemFlags", "1.2.840.113556.1.4.375" },
1088 { "isMemberOfPartialAttributeSet", "1.2.840.113556.1.4.639" },
1089 { "linkID", "1.2.840.113556.1.2.50" },
1090 { "attributeSyntax", "1.2.840.113556.1.2.32" },
1091 { "oMSyntax", "1.2.840.113556.1.2.231" },
1092 { "oMObjectClass", "1.2.840.113556.1.2.218" },
1093 { "isSingleValued", "1.2.840.113556.1.2.33" },
1094 { "rangeLower", "1.2.840.113556.1.2.34" },
1095 { "rangeUpper", "1.2.840.113556.1.2.35" },
1096 { "extendedCharsAllowed", "1.2.840.113556.1.2.380" },
1097 { "schemaFlagsEx", "1.2.840.113556.1.4.120" },
1098 { "msDs-Schema-Extensions", "1.2.840.113556.1.4.1440" },
1099 { "showInAdvancedViewOnly", "1.2.840.113556.1.2.169" },
1100 { "adminDisplayName", "1.2.840.113556.1.2.194" },
1101 { "adminDescription", "1.2.840.113556.1.2.226" },
1102 { "classDisplayName", "1.2.840.113556.1.4.610" },
1103 { "isEphemeral", "1.2.840.113556.1.4.1212" },
1104 { "isDefunct", "1.2.840.113556.1.4.661" },
1105 { "systemOnly", "1.2.840.113556.1.4.170" },
1106 { "governsID", "1.2.840.113556.1.2.22" },
1107 { "objectClassCategory", "1.2.840.113556.1.2.370" },
1108 { "rDNAttID", "1.2.840.113556.1.2.26" },
1109 { "defaultObjectCategory", "1.2.840.113556.1.4.783" },
1110 { "subClassOf", "1.2.840.113556.1.2.21" },
1111 { "systemAuxiliaryClass", "1.2.840.113556.1.4.198" },
1112 { "systemPossSuperiors", "1.2.840.113556.1.4.195" },
1113 { "systemMustContain", "1.2.840.113556.1.4.197" },
1114 { "systemMayContain", "1.2.840.113556.1.4.196" },
1115 { "auxiliaryClass", "1.2.840.113556.1.2.351" },
1116 { "possSuperiors", "1.2.840.113556.1.2.8" },
1117 { "mustContain", "1.2.840.113556.1.2.24" },
1118 { "mayContain", "1.2.840.113556.1.2.25" },
1119 { "defaultSecurityDescriptor", "1.2.840.113556.1.4.224" },
1120 { "defaultHidingValue", "1.2.840.113556.1.4.518" },
1123 static struct drsuapi_DsReplicaAttribute *dsdb_find_object_attr_name(struct dsdb_schema *schema,
1124 struct drsuapi_DsReplicaObject *obj,
1130 const char *oid = NULL;
1132 for(i=0; i < ARRAY_SIZE(name_mappings); i++) {
1133 if (strcmp(name_mappings[i].name, name) != 0) continue;
1135 oid = name_mappings[i].oid;
1143 status = dsdb_map_oid2int(schema, oid, &id);
1144 if (!W_ERROR_IS_OK(status)) {
1148 for (i=0; i < obj->attribute_ctr.num_attributes; i++) {
1149 if (obj->attribute_ctr.attributes[i].attid != id) continue;
1152 return &obj->attribute_ctr.attributes[i];
1158 #define GET_STRING_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1159 struct drsuapi_DsReplicaAttribute *_a; \
1160 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1161 if (strict && !_a) { \
1162 d_printf("%s: %s == NULL\n", __location__, attr); \
1163 return WERR_INVALID_PARAM; \
1165 if (strict && _a->value_ctr.num_values != 1) { \
1166 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1167 _a->value_ctr.num_values); \
1168 return WERR_INVALID_PARAM; \
1170 if (_a && _a->value_ctr.num_values >= 1) { \
1172 _ret = convert_string_talloc(mem_ctx, s->iconv_convenience, CH_UTF16, CH_UNIX, \
1173 _a->value_ctr.values[0].blob->data, \
1174 _a->value_ctr.values[0].blob->length, \
1175 (void **)discard_const(&(p)->elem)); \
1177 DEBUG(0,("%s: invalid data!\n", attr)); \
1179 _a->value_ctr.values[0].blob->data, \
1180 _a->value_ctr.values[0].blob->length); \
1181 return WERR_FOOBAR; \
1188 #define GET_DN_DS(s, r, attr, mem_ctx, p, elem, strict) do { \
1189 struct drsuapi_DsReplicaAttribute *_a; \
1190 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1191 if (strict && !_a) { \
1192 d_printf("%s: %s == NULL\n", __location__, attr); \
1193 return WERR_INVALID_PARAM; \
1195 if (strict && _a->value_ctr.num_values != 1) { \
1196 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1197 _a->value_ctr.num_values); \
1198 return WERR_INVALID_PARAM; \
1200 if (strict && !_a->value_ctr.values[0].blob) { \
1201 d_printf("%s: %s data == NULL\n", __location__, attr); \
1202 return WERR_INVALID_PARAM; \
1204 if (_a && _a->value_ctr.num_values >= 1 \
1205 && _a->value_ctr.values[0].blob) { \
1206 struct drsuapi_DsReplicaObjectIdentifier3 _id3; \
1207 enum ndr_err_code _ndr_err; \
1208 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1209 mem_ctx, s->iconv_convenience, &_id3,\
1210 (ndr_pull_flags_fn_t)ndr_pull_drsuapi_DsReplicaObjectIdentifier3);\
1211 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1212 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1213 return ntstatus_to_werror(_nt_status); \
1215 (p)->elem = _id3.dn; \
1221 #define GET_BOOL_DS(s, r, attr, p, elem, strict) do { \
1222 struct drsuapi_DsReplicaAttribute *_a; \
1223 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1224 if (strict && !_a) { \
1225 d_printf("%s: %s == NULL\n", __location__, attr); \
1226 return WERR_INVALID_PARAM; \
1228 if (strict && _a->value_ctr.num_values != 1) { \
1229 d_printf("%s: %s num_values == %u\n", __location__, attr, \
1230 (unsigned int)_a->value_ctr.num_values); \
1231 return WERR_INVALID_PARAM; \
1233 if (strict && !_a->value_ctr.values[0].blob) { \
1234 d_printf("%s: %s data == NULL\n", __location__, attr); \
1235 return WERR_INVALID_PARAM; \
1237 if (strict && _a->value_ctr.values[0].blob->length != 4) { \
1238 d_printf("%s: %s length == %u\n", __location__, attr, \
1239 (unsigned int)_a->value_ctr.values[0].blob->length); \
1240 return WERR_INVALID_PARAM; \
1242 if (_a && _a->value_ctr.num_values >= 1 \
1243 && _a->value_ctr.values[0].blob \
1244 && _a->value_ctr.values[0].blob->length == 4) { \
1245 (p)->elem = (IVAL(_a->value_ctr.values[0].blob->data,0)?true:false);\
1247 (p)->elem = false; \
1251 #define GET_UINT32_DS(s, r, attr, p, elem) do { \
1252 struct drsuapi_DsReplicaAttribute *_a; \
1253 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1254 if (_a && _a->value_ctr.num_values >= 1 \
1255 && _a->value_ctr.values[0].blob \
1256 && _a->value_ctr.values[0].blob->length == 4) { \
1257 (p)->elem = IVAL(_a->value_ctr.values[0].blob->data,0);\
1263 #define GET_GUID_DS(s, r, attr, mem_ctx, p, elem) do { \
1264 struct drsuapi_DsReplicaAttribute *_a; \
1265 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1266 if (_a && _a->value_ctr.num_values >= 1 \
1267 && _a->value_ctr.values[0].blob \
1268 && _a->value_ctr.values[0].blob->length == 16) { \
1269 enum ndr_err_code _ndr_err; \
1270 _ndr_err = ndr_pull_struct_blob_all(_a->value_ctr.values[0].blob, \
1271 mem_ctx, s->iconv_convenience, &(p)->elem, \
1272 (ndr_pull_flags_fn_t)ndr_pull_GUID); \
1273 if (!NDR_ERR_CODE_IS_SUCCESS(_ndr_err)) { \
1274 NTSTATUS _nt_status = ndr_map_error2ntstatus(_ndr_err); \
1275 return ntstatus_to_werror(_nt_status); \
1278 ZERO_STRUCT((p)->elem);\
1282 #define GET_BLOB_DS(s, r, attr, mem_ctx, p, elem) do { \
1283 struct drsuapi_DsReplicaAttribute *_a; \
1284 _a = dsdb_find_object_attr_name(s, r, attr, NULL); \
1285 if (_a && _a->value_ctr.num_values >= 1 \
1286 && _a->value_ctr.values[0].blob) { \
1287 (p)->elem = *_a->value_ctr.values[0].blob;\
1288 talloc_steal(mem_ctx, (p)->elem.data); \
1290 ZERO_STRUCT((p)->elem);\
1294 WERROR dsdb_attribute_from_drsuapi(struct dsdb_schema *schema,
1295 struct drsuapi_DsReplicaObject *r,
1296 TALLOC_CTX *mem_ctx,
1297 struct dsdb_attribute *attr)
1301 GET_STRING_DS(schema, r, "name", mem_ctx, attr, cn, true);
1302 GET_STRING_DS(schema, r, "lDAPDisplayName", mem_ctx, attr, lDAPDisplayName, true);
1303 GET_UINT32_DS(schema, r, "attributeID", attr, attributeID_id);
1304 status = dsdb_map_int2oid(schema, attr->attributeID_id, mem_ctx, &attr->attributeID_oid);
1305 if (!W_ERROR_IS_OK(status)) {
1306 DEBUG(0,("%s: '%s': unable to map attributeID 0x%08X: %s\n",
1307 __location__, attr->lDAPDisplayName, attr->attributeID_id,
1308 win_errstr(status)));
1311 GET_GUID_DS(schema, r, "schemaIDGUID", mem_ctx, attr, schemaIDGUID);
1312 GET_UINT32_DS(schema, r, "mAPIID", attr, mAPIID);
1314 GET_GUID_DS(schema, r, "attributeSecurityGUID", mem_ctx, attr, attributeSecurityGUID);
1316 GET_UINT32_DS(schema, r, "searchFlags", attr, searchFlags);
1317 GET_UINT32_DS(schema, r, "systemFlags", attr, systemFlags);
1318 GET_BOOL_DS(schema, r, "isMemberOfPartialAttributeSet", attr, isMemberOfPartialAttributeSet, false);
1319 GET_UINT32_DS(schema, r, "linkID", attr, linkID);
1321 GET_UINT32_DS(schema, r, "attributeSyntax", attr, attributeSyntax_id);
1322 status = dsdb_map_int2oid(schema, attr->attributeSyntax_id, mem_ctx, &attr->attributeSyntax_oid);
1323 if (!W_ERROR_IS_OK(status)) {
1324 DEBUG(0,("%s: '%s': unable to map attributeSyntax 0x%08X: %s\n",
1325 __location__, attr->lDAPDisplayName, attr->attributeSyntax_id,
1326 win_errstr(status)));
1329 GET_UINT32_DS(schema, r, "oMSyntax", attr, oMSyntax);
1330 GET_BLOB_DS(schema, r, "oMObjectClass", mem_ctx, attr, oMObjectClass);
1332 GET_BOOL_DS(schema, r, "isSingleValued", attr, isSingleValued, true);
1333 GET_UINT32_DS(schema, r, "rangeLower", attr, rangeLower);
1334 GET_UINT32_DS(schema, r, "rangeUpper", attr, rangeUpper);
1335 GET_BOOL_DS(schema, r, "extendedCharsAllowed", attr, extendedCharsAllowed, false);
1337 GET_UINT32_DS(schema, r, "schemaFlagsEx", attr, schemaFlagsEx);
1338 GET_BLOB_DS(schema, r, "msDs-Schema-Extensions", mem_ctx, attr, msDs_Schema_Extensions);
1340 GET_BOOL_DS(schema, r, "showInAdvancedViewOnly", attr, showInAdvancedViewOnly, false);
1341 GET_STRING_DS(schema, r, "adminDisplayName", mem_ctx, attr, adminDisplayName, false);
1342 GET_STRING_DS(schema, r, "adminDescription", mem_ctx, attr, adminDescription, false);
1343 GET_STRING_DS(schema, r, "classDisplayName", mem_ctx, attr, classDisplayName, false);
1344 GET_BOOL_DS(schema, r, "isEphemeral", attr, isEphemeral, false);
1345 GET_BOOL_DS(schema, r, "isDefunct", attr, isDefunct, false);
1346 GET_BOOL_DS(schema, r, "systemOnly", attr, systemOnly, false);
1348 attr->syntax = dsdb_syntax_for_attribute(attr);
1349 if (!attr->syntax) {
1350 return WERR_DS_ATT_SCHEMA_REQ_SYNTAX;
1356 WERROR dsdb_class_from_drsuapi(struct dsdb_schema *schema,
1357 struct drsuapi_DsReplicaObject *r,
1358 TALLOC_CTX *mem_ctx,
1359 struct dsdb_class *obj)
1363 GET_STRING_DS(schema, r, "name", mem_ctx, obj, cn, true);
1364 GET_STRING_DS(schema, r, "lDAPDisplayName", mem_ctx, obj, lDAPDisplayName, true);
1365 GET_UINT32_DS(schema, r, "governsID", obj, governsID_id);
1366 status = dsdb_map_int2oid(schema, obj->governsID_id, mem_ctx, &obj->governsID_oid);
1367 if (!W_ERROR_IS_OK(status)) {
1368 DEBUG(0,("%s: '%s': unable to map governsID 0x%08X: %s\n",
1369 __location__, obj->lDAPDisplayName, obj->governsID_id,
1370 win_errstr(status)));
1373 GET_GUID_DS(schema, r, "schemaIDGUID", mem_ctx, obj, schemaIDGUID);
1375 GET_UINT32_DS(schema, r, "objectClassCategory", obj, objectClassCategory);
1376 GET_STRING_DS(schema, r, "rDNAttID", mem_ctx, obj, rDNAttID, false);
1377 GET_DN_DS(schema, r, "defaultObjectCategory", mem_ctx, obj, defaultObjectCategory, true);
1379 GET_STRING_DS(schema, r, "subClassOf", mem_ctx, obj, subClassOf, true);
1381 obj->systemAuxiliaryClass = NULL;
1382 obj->systemPossSuperiors = NULL;
1383 obj->systemMustContain = NULL;
1384 obj->systemMayContain = NULL;
1386 obj->auxiliaryClass = NULL;
1387 obj->possSuperiors = NULL;
1388 obj->mustContain = NULL;
1389 obj->mayContain = NULL;
1391 obj->possibleInferiors = NULL;
1393 GET_STRING_DS(schema, r, "defaultSecurityDescriptor", mem_ctx, obj, defaultSecurityDescriptor, false);
1395 GET_UINT32_DS(schema, r, "schemaFlagsEx", obj, schemaFlagsEx);
1396 GET_BLOB_DS(schema, r, "msDs-Schema-Extensions", mem_ctx, obj, msDs_Schema_Extensions);
1398 GET_BOOL_DS(schema, r, "showInAdvancedViewOnly", obj, showInAdvancedViewOnly, false);
1399 GET_STRING_DS(schema, r, "adminDisplayName", mem_ctx, obj, adminDisplayName, false);
1400 GET_STRING_DS(schema, r, "adminDescription", mem_ctx, obj, adminDescription, false);
1401 GET_STRING_DS(schema, r, "classDisplayName", mem_ctx, obj, classDisplayName, false);
1402 GET_BOOL_DS(schema, r, "defaultHidingValue", obj, defaultHidingValue, false);
1403 GET_BOOL_DS(schema, r, "isDefunct", obj, isDefunct, false);
1404 GET_BOOL_DS(schema, r, "systemOnly", obj, systemOnly, false);