2 ldb database library - ldif handlers for Samba
4 Copyright (C) Andrew Tridgell 2005
5 Copyright (C) Andrew Bartlett 2006-2009
6 Copyright (C) Matthias Dieter Wallnöfer 2009
7 ** NOTE! The following LGPL license applies to the ldb
8 ** library. This does NOT imply that all of Samba is released
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 3 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include "lib/ldb/include/ldb.h"
27 #include "lib/ldb/include/ldb_module.h"
28 #include "ldb_handlers.h"
29 #include "dsdb/samdb/samdb.h"
30 #include "librpc/gen_ndr/ndr_security.h"
31 #include "librpc/gen_ndr/ndr_misc.h"
32 #include "librpc/gen_ndr/ndr_drsblobs.h"
33 #include "librpc/ndr/libndr.h"
34 #include "libcli/security/security.h"
35 #include "param/param.h"
36 #include "../lib/util/asn1.h"
39 use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob
41 static int ldif_write_NDR(struct ldb_context *ldb, void *mem_ctx,
42 const struct ldb_val *in, struct ldb_val *out,
44 ndr_pull_flags_fn_t pull_fn,
45 ndr_print_fn_t print_fn)
48 enum ndr_err_code err;
49 if (!(ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY)) {
50 return ldb_handler_copy(ldb, mem_ctx, in, out);
52 p = talloc_size(mem_ctx, struct_size);
53 err = ndr_pull_struct_blob(in, mem_ctx,
54 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
56 if (err != NDR_ERR_SUCCESS) {
58 out->data = (uint8_t *)talloc_strdup(mem_ctx, "<Unable to decode binary data>");
59 out->length = strlen((const char *)out->data);
62 out->data = (uint8_t *)ndr_print_struct_string(mem_ctx, print_fn, "NDR", p);
64 if (out->data == NULL) {
65 return ldb_handler_copy(ldb, mem_ctx, in, out);
67 out->length = strlen((char *)out->data);
72 convert a ldif formatted objectSid to a NDR formatted blob
74 static int ldif_read_objectSid(struct ldb_context *ldb, void *mem_ctx,
75 const struct ldb_val *in, struct ldb_val *out)
77 enum ndr_err_code ndr_err;
79 sid = dom_sid_parse_length(mem_ctx, in);
83 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, sid,
84 (ndr_push_flags_fn_t)ndr_push_dom_sid);
86 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
93 convert a NDR formatted blob to a ldif formatted objectSid
95 int ldif_write_objectSid(struct ldb_context *ldb, void *mem_ctx,
96 const struct ldb_val *in, struct ldb_val *out)
99 enum ndr_err_code ndr_err;
101 sid = talloc(mem_ctx, struct dom_sid);
105 ndr_err = ndr_pull_struct_blob_all(in, sid, NULL, sid,
106 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
107 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
111 *out = data_blob_string_const(dom_sid_string(mem_ctx, sid));
113 if (out->data == NULL) {
119 bool ldif_comparision_objectSid_isString(const struct ldb_val *v)
125 if (strncmp("S-", (const char *)v->data, 2) != 0) return false;
131 compare two objectSids
133 static int ldif_comparison_objectSid(struct ldb_context *ldb, void *mem_ctx,
134 const struct ldb_val *v1, const struct ldb_val *v2)
136 if (ldif_comparision_objectSid_isString(v1) && ldif_comparision_objectSid_isString(v2)) {
137 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
138 } else if (ldif_comparision_objectSid_isString(v1)
139 && !ldif_comparision_objectSid_isString(v2)) {
142 if (ldif_read_objectSid(ldb, mem_ctx, v1, &v) != 0) {
143 /* Perhaps not a string after all */
144 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
146 ret = ldb_comparison_binary(ldb, mem_ctx, &v, v2);
149 } else if (!ldif_comparision_objectSid_isString(v1)
150 && ldif_comparision_objectSid_isString(v2)) {
153 if (ldif_read_objectSid(ldb, mem_ctx, v2, &v) != 0) {
154 /* Perhaps not a string after all */
155 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
157 ret = ldb_comparison_binary(ldb, mem_ctx, v1, &v);
161 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
165 canonicalise a objectSid
167 static int ldif_canonicalise_objectSid(struct ldb_context *ldb, void *mem_ctx,
168 const struct ldb_val *in, struct ldb_val *out)
170 if (ldif_comparision_objectSid_isString(in)) {
171 if (ldif_read_objectSid(ldb, mem_ctx, in, out) != 0) {
172 /* Perhaps not a string after all */
173 return ldb_handler_copy(ldb, mem_ctx, in, out);
177 return ldb_handler_copy(ldb, mem_ctx, in, out);
180 static int extended_dn_read_SID(struct ldb_context *ldb, void *mem_ctx,
181 const struct ldb_val *in, struct ldb_val *out)
184 enum ndr_err_code ndr_err;
185 if (ldif_comparision_objectSid_isString(in)) {
186 if (ldif_read_objectSid(ldb, mem_ctx, in, out) == 0) {
191 /* Perhaps not a string after all */
192 *out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
198 (*out).length = strhex_to_str((char *)out->data, out->length,
199 (const char *)in->data, in->length);
201 /* Check it looks like a SID */
202 ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &sid,
203 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
204 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
211 convert a ldif formatted objectGUID to a NDR formatted blob
213 static int ldif_read_objectGUID(struct ldb_context *ldb, void *mem_ctx,
214 const struct ldb_val *in, struct ldb_val *out)
219 status = GUID_from_data_blob(in, &guid);
220 if (!NT_STATUS_IS_OK(status)) {
224 status = GUID_to_ndr_blob(&guid, mem_ctx, out);
225 if (!NT_STATUS_IS_OK(status)) {
232 convert a NDR formatted blob to a ldif formatted objectGUID
234 static int ldif_write_objectGUID(struct ldb_context *ldb, void *mem_ctx,
235 const struct ldb_val *in, struct ldb_val *out)
240 status = GUID_from_ndr_blob(in, &guid);
241 if (!NT_STATUS_IS_OK(status)) {
244 out->data = (uint8_t *)GUID_string(mem_ctx, &guid);
245 if (out->data == NULL) {
248 out->length = strlen((const char *)out->data);
252 static bool ldif_comparision_objectGUID_isString(const struct ldb_val *v)
254 if (v->length != 36 && v->length != 38) return false;
256 /* Might be a GUID string, can't be a binary GUID (fixed 16 bytes) */
260 static int extended_dn_read_GUID(struct ldb_context *ldb, void *mem_ctx,
261 const struct ldb_val *in, struct ldb_val *out)
266 if (in->length == 36 && ldif_read_objectGUID(ldb, mem_ctx, in, out) == 0) {
270 /* Try as 'hex' form */
271 if (in->length != 32) {
275 *out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
281 (*out).length = strhex_to_str((char *)out->data, out->length,
282 (const char *)in->data, in->length);
284 /* Check it looks like a GUID */
285 status = GUID_from_ndr_blob(out, &guid);
286 if (!NT_STATUS_IS_OK(status)) {
294 compare two objectGUIDs
296 static int ldif_comparison_objectGUID(struct ldb_context *ldb, void *mem_ctx,
297 const struct ldb_val *v1, const struct ldb_val *v2)
299 if (ldif_comparision_objectGUID_isString(v1) && ldif_comparision_objectGUID_isString(v2)) {
300 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
301 } else if (ldif_comparision_objectGUID_isString(v1)
302 && !ldif_comparision_objectGUID_isString(v2)) {
305 if (ldif_read_objectGUID(ldb, mem_ctx, v1, &v) != 0) {
306 /* Perhaps it wasn't a valid string after all */
307 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
309 ret = ldb_comparison_binary(ldb, mem_ctx, &v, v2);
312 } else if (!ldif_comparision_objectGUID_isString(v1)
313 && ldif_comparision_objectGUID_isString(v2)) {
316 if (ldif_read_objectGUID(ldb, mem_ctx, v2, &v) != 0) {
317 /* Perhaps it wasn't a valid string after all */
318 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
320 ret = ldb_comparison_binary(ldb, mem_ctx, v1, &v);
324 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
328 canonicalise a objectGUID
330 static int ldif_canonicalise_objectGUID(struct ldb_context *ldb, void *mem_ctx,
331 const struct ldb_val *in, struct ldb_val *out)
333 if (ldif_comparision_objectGUID_isString(in)) {
334 if (ldif_read_objectGUID(ldb, mem_ctx, in, out) != 0) {
335 /* Perhaps it wasn't a valid string after all */
336 return ldb_handler_copy(ldb, mem_ctx, in, out);
340 return ldb_handler_copy(ldb, mem_ctx, in, out);
345 convert a ldif (SDDL) formatted ntSecurityDescriptor to a NDR formatted blob
347 static int ldif_read_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx,
348 const struct ldb_val *in, struct ldb_val *out)
350 struct security_descriptor *sd;
351 enum ndr_err_code ndr_err;
353 sd = talloc(mem_ctx, struct security_descriptor);
358 ndr_err = ndr_pull_struct_blob(in, sd, NULL, sd,
359 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
360 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
361 /* If this does not parse, then it is probably SDDL, and we should try it that way */
363 const struct dom_sid *sid = samdb_domain_sid(ldb);
365 sd = sddl_decode(mem_ctx, (const char *)in->data, sid);
371 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, sd,
372 (ndr_push_flags_fn_t)ndr_push_security_descriptor);
374 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
382 convert a NDR formatted blob to a ldif formatted ntSecurityDescriptor (SDDL format)
384 static int ldif_write_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx,
385 const struct ldb_val *in, struct ldb_val *out)
387 struct security_descriptor *sd;
388 enum ndr_err_code ndr_err;
390 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
391 return ldif_write_NDR(ldb, mem_ctx, in, out,
392 sizeof(struct security_descriptor),
393 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor,
394 (ndr_print_fn_t)ndr_print_security_descriptor);
398 sd = talloc(mem_ctx, struct security_descriptor);
402 /* We can't use ndr_pull_struct_blob_all because this contains relative pointers */
403 ndr_err = ndr_pull_struct_blob(in, sd, NULL, sd,
404 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
405 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
409 out->data = (uint8_t *)sddl_encode(mem_ctx, sd, NULL);
411 if (out->data == NULL) {
414 out->length = strlen((const char *)out->data);
419 canonicalise an objectCategory. We use the short form as the cannoical form:
420 cn=Person,cn=Schema,cn=Configuration,<basedn> becomes 'person'
423 static int ldif_canonicalise_objectCategory(struct ldb_context *ldb, void *mem_ctx,
424 const struct ldb_val *in, struct ldb_val *out)
426 struct ldb_dn *dn1 = NULL;
427 const struct dsdb_schema *schema = dsdb_get_schema(ldb);
428 const struct dsdb_class *sclass;
429 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
431 return LDB_ERR_OPERATIONS_ERROR;
435 talloc_free(tmp_ctx);
436 *out = data_blob_talloc(mem_ctx, in->data, in->length);
437 if (in->data && !out->data) {
438 return LDB_ERR_OPERATIONS_ERROR;
442 dn1 = ldb_dn_from_ldb_val(tmp_ctx, ldb, in);
443 if ( ! ldb_dn_validate(dn1)) {
444 const char *lDAPDisplayName = talloc_strndup(tmp_ctx, (char *)in->data, in->length);
445 sclass = dsdb_class_by_lDAPDisplayName(schema, lDAPDisplayName);
447 struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb,
448 sclass->defaultObjectCategory);
449 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn));
450 talloc_free(tmp_ctx);
453 return LDB_ERR_OPERATIONS_ERROR;
457 *out = data_blob_talloc(mem_ctx, in->data, in->length);
458 talloc_free(tmp_ctx);
460 if (in->data && !out->data) {
461 return LDB_ERR_OPERATIONS_ERROR;
466 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn1));
467 talloc_free(tmp_ctx);
470 return LDB_ERR_OPERATIONS_ERROR;
475 static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx,
476 const struct ldb_val *v1,
477 const struct ldb_val *v2)
479 return ldb_any_comparison(ldb, mem_ctx, ldif_canonicalise_objectCategory,
484 convert a ldif formatted prefixMap to a NDR formatted blob
486 static int ldif_read_prefixMap(struct ldb_context *ldb, void *mem_ctx,
487 const struct ldb_val *in, struct ldb_val *out)
489 struct prefixMapBlob *blob;
490 enum ndr_err_code ndr_err;
491 char *string, *line, *p, *oid;
494 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
496 if (tmp_ctx == NULL) {
500 blob = talloc_zero(tmp_ctx, struct prefixMapBlob);
506 blob->version = PREFIX_MAP_VERSION_DSDB;
508 string = talloc_strndup(mem_ctx, (const char *)in->data, in->length);
509 if (string == NULL) {
515 while (line && line[0]) {
520 p=strchr(line, '\n');
525 /* allow a traling seperator */
530 blob->ctr.dsdb.mappings = talloc_realloc(blob,
531 blob->ctr.dsdb.mappings,
532 struct drsuapi_DsReplicaOIDMapping,
533 blob->ctr.dsdb.num_mappings+1);
534 if (!blob->ctr.dsdb.mappings) {
535 talloc_free(tmp_ctx);
539 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].id_prefix = strtoul(line, &oid, 10);
542 talloc_free(tmp_ctx);
546 /* we know there must be at least ":" */
549 if (!ber_write_partial_OID_String(blob->ctr.dsdb.mappings, &oid_blob, oid)) {
550 talloc_free(tmp_ctx);
553 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].oid.length = oid_blob.length;
554 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].oid.binary_oid = oid_blob.data;
556 blob->ctr.dsdb.num_mappings++;
558 /* Now look past the terminator we added above */
566 ndr_err = ndr_push_struct_blob(out, mem_ctx,
567 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
569 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
570 talloc_free(tmp_ctx);
571 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
578 convert a NDR formatted blob to a ldif formatted prefixMap
580 static int ldif_write_prefixMap(struct ldb_context *ldb, void *mem_ctx,
581 const struct ldb_val *in, struct ldb_val *out)
583 struct prefixMapBlob *blob;
584 enum ndr_err_code ndr_err;
588 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
589 return ldif_write_NDR(ldb, mem_ctx, in, out,
590 sizeof(struct prefixMapBlob),
591 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob,
592 (ndr_print_fn_t)ndr_print_prefixMapBlob);
596 blob = talloc(mem_ctx, struct prefixMapBlob);
600 ndr_err = ndr_pull_struct_blob_all(in, blob,
601 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
603 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
604 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
607 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
610 string = talloc_strdup(mem_ctx, "");
611 if (string == NULL) {
615 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
617 const char *partial_oid = NULL;
620 string = talloc_asprintf_append(string, ";");
623 oid_blob = data_blob_const(blob->ctr.dsdb.mappings[i].oid.binary_oid,
624 blob->ctr.dsdb.mappings[i].oid.length);
625 if (!ber_read_partial_OID_String(blob, oid_blob, &partial_oid)) {
626 DEBUG(0, ("ber_read_partial_OID failed on prefixMap item with id: 0x%X",
627 blob->ctr.dsdb.mappings[i].id_prefix));
630 string = talloc_asprintf_append(string, "%u:%s",
631 blob->ctr.dsdb.mappings[i].id_prefix,
633 talloc_free(discard_const(partial_oid));
634 if (string == NULL) {
640 *out = data_blob_string_const(string);
648 static bool ldif_comparision_prefixMap_isString(const struct ldb_val *v)
654 if (IVAL(v->data, 0) == PREFIX_MAP_VERSION_DSDB) {
662 canonicalise a prefixMap
664 static int ldif_canonicalise_prefixMap(struct ldb_context *ldb, void *mem_ctx,
665 const struct ldb_val *in, struct ldb_val *out)
667 if (ldif_comparision_prefixMap_isString(in)) {
668 return ldif_read_prefixMap(ldb, mem_ctx, in, out);
670 return ldb_handler_copy(ldb, mem_ctx, in, out);
673 static int ldif_comparison_prefixMap(struct ldb_context *ldb, void *mem_ctx,
674 const struct ldb_val *v1,
675 const struct ldb_val *v2)
677 return ldb_any_comparison(ldb, mem_ctx, ldif_canonicalise_prefixMap,
681 /* length limited conversion of a ldb_val to a int32_t */
682 static int val_to_int32(const struct ldb_val *in, int32_t *v)
687 /* make sure we don't read past the end of the data */
688 if (in->length > sizeof(buf)-1) {
689 return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
691 strncpy(buf, (char *)in->data, in->length);
694 /* We've to use "strtoll" here to have the intended overflows.
695 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
696 *v = (int32_t) strtoll(buf, &end, 0);
698 return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
703 /* Canonicalisation of two 32-bit integers */
704 static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx,
705 const struct ldb_val *in, struct ldb_val *out)
710 ret = val_to_int32(in, &i);
711 if (ret != LDB_SUCCESS) {
714 out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%d", i);
715 if (out->data == NULL) {
717 return LDB_ERR_OPERATIONS_ERROR;
719 out->length = strlen((char *)out->data);
723 /* Comparison of two 32-bit integers */
724 static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx,
725 const struct ldb_val *v1, const struct ldb_val *v2)
728 val_to_int32(v1, &i1);
729 val_to_int32(v2, &i2);
730 if (i1 == i2) return 0;
731 return i1 > i2? 1 : -1;
735 convert a NDR formatted blob to a ldif formatted repsFromTo
737 static int ldif_write_repsFromTo(struct ldb_context *ldb, void *mem_ctx,
738 const struct ldb_val *in, struct ldb_val *out)
740 return ldif_write_NDR(ldb, mem_ctx, in, out,
741 sizeof(struct repsFromToBlob),
742 (ndr_pull_flags_fn_t)ndr_pull_repsFromToBlob,
743 (ndr_print_fn_t)ndr_print_repsFromToBlob);
747 convert a NDR formatted blob to a ldif formatted replPropertyMetaData
749 static int ldif_write_replPropertyMetaData(struct ldb_context *ldb, void *mem_ctx,
750 const struct ldb_val *in, struct ldb_val *out)
752 return ldif_write_NDR(ldb, mem_ctx, in, out,
753 sizeof(struct replPropertyMetaDataBlob),
754 (ndr_pull_flags_fn_t)ndr_pull_replPropertyMetaDataBlob,
755 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
759 convert a NDR formatted blob to a ldif formatted replUpToDateVector
761 static int ldif_write_replUpToDateVector(struct ldb_context *ldb, void *mem_ctx,
762 const struct ldb_val *in, struct ldb_val *out)
764 return ldif_write_NDR(ldb, mem_ctx, in, out,
765 sizeof(struct replUpToDateVectorBlob),
766 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob,
767 (ndr_print_fn_t)ndr_print_replUpToDateVectorBlob);
771 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
772 const struct ldb_val *in, struct ldb_val *out)
774 *out = data_blob_string_const(data_blob_hex_string_lower(mem_ctx, in));
781 static const struct ldb_schema_syntax samba_syntaxes[] = {
783 .name = LDB_SYNTAX_SAMBA_SID,
784 .ldif_read_fn = ldif_read_objectSid,
785 .ldif_write_fn = ldif_write_objectSid,
786 .canonicalise_fn = ldif_canonicalise_objectSid,
787 .comparison_fn = ldif_comparison_objectSid
789 .name = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR,
790 .ldif_read_fn = ldif_read_ntSecurityDescriptor,
791 .ldif_write_fn = ldif_write_ntSecurityDescriptor,
792 .canonicalise_fn = ldb_handler_copy,
793 .comparison_fn = ldb_comparison_binary
795 .name = LDB_SYNTAX_SAMBA_GUID,
796 .ldif_read_fn = ldif_read_objectGUID,
797 .ldif_write_fn = ldif_write_objectGUID,
798 .canonicalise_fn = ldif_canonicalise_objectGUID,
799 .comparison_fn = ldif_comparison_objectGUID
801 .name = LDB_SYNTAX_SAMBA_OBJECT_CATEGORY,
802 .ldif_read_fn = ldb_handler_copy,
803 .ldif_write_fn = ldb_handler_copy,
804 .canonicalise_fn = ldif_canonicalise_objectCategory,
805 .comparison_fn = ldif_comparison_objectCategory
807 .name = LDB_SYNTAX_SAMBA_PREFIX_MAP,
808 .ldif_read_fn = ldif_read_prefixMap,
809 .ldif_write_fn = ldif_write_prefixMap,
810 .canonicalise_fn = ldif_canonicalise_prefixMap,
811 .comparison_fn = ldif_comparison_prefixMap
813 .name = LDB_SYNTAX_SAMBA_INT32,
814 .ldif_read_fn = ldb_handler_copy,
815 .ldif_write_fn = ldb_handler_copy,
816 .canonicalise_fn = ldif_canonicalise_int32,
817 .comparison_fn = ldif_comparison_int32
819 .name = LDB_SYNTAX_SAMBA_REPSFROMTO,
820 .ldif_read_fn = ldb_handler_copy,
821 .ldif_write_fn = ldif_write_repsFromTo,
822 .canonicalise_fn = ldb_handler_copy,
823 .comparison_fn = ldb_comparison_binary
825 .name = LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA,
826 .ldif_read_fn = ldb_handler_copy,
827 .ldif_write_fn = ldif_write_replPropertyMetaData,
828 .canonicalise_fn = ldb_handler_copy,
829 .comparison_fn = ldb_comparison_binary
831 .name = LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR,
832 .ldif_read_fn = ldb_handler_copy,
833 .ldif_write_fn = ldif_write_replUpToDateVector,
834 .canonicalise_fn = ldb_handler_copy,
835 .comparison_fn = ldb_comparison_binary
837 .name = DSDB_SYNTAX_BINARY_DN,
838 .ldif_read_fn = ldb_handler_copy,
839 .ldif_write_fn = ldb_handler_copy,
840 .canonicalise_fn = dsdb_dn_binary_canonicalise,
841 .comparison_fn = dsdb_dn_binary_comparison
843 .name = DSDB_SYNTAX_STRING_DN,
844 .ldif_read_fn = ldb_handler_copy,
845 .ldif_write_fn = ldb_handler_copy,
846 .canonicalise_fn = dsdb_dn_string_canonicalise,
847 .comparison_fn = dsdb_dn_string_comparison
851 static const struct ldb_dn_extended_syntax samba_dn_syntax[] = {
854 .read_fn = extended_dn_read_SID,
855 .write_clear_fn = ldif_write_objectSid,
856 .write_hex_fn = extended_dn_write_hex
859 .read_fn = extended_dn_read_GUID,
860 .write_clear_fn = ldif_write_objectGUID,
861 .write_hex_fn = extended_dn_write_hex
864 .read_fn = ldb_handler_copy,
865 .write_clear_fn = ldb_handler_copy,
866 .write_hex_fn = ldb_handler_copy
868 .name = "RMD_INVOCID",
869 .read_fn = extended_dn_read_GUID,
870 .write_clear_fn = ldif_write_objectGUID,
871 .write_hex_fn = extended_dn_write_hex
874 .read_fn = ldb_handler_copy,
875 .write_clear_fn = ldb_handler_copy,
876 .write_hex_fn = ldb_handler_copy
878 .name = "RMD_ADDTIME",
879 .read_fn = ldb_handler_copy,
880 .write_clear_fn = ldb_handler_copy,
881 .write_hex_fn = ldb_handler_copy
883 .name = "RMD_CHANGETIME",
884 .read_fn = ldb_handler_copy,
885 .write_clear_fn = ldb_handler_copy,
886 .write_hex_fn = ldb_handler_copy
888 .name = "RMD_LOCAL_USN",
889 .read_fn = ldb_handler_copy,
890 .write_clear_fn = ldb_handler_copy,
891 .write_hex_fn = ldb_handler_copy
893 .name = "RMD_ORIGINATING_USN",
894 .read_fn = ldb_handler_copy,
895 .write_clear_fn = ldb_handler_copy,
896 .write_hex_fn = ldb_handler_copy
898 .name = "RMD_VERSION",
899 .read_fn = ldb_handler_copy,
900 .write_clear_fn = ldb_handler_copy,
901 .write_hex_fn = ldb_handler_copy
905 /* TODO: Should be dynamic at some point */
906 static const struct {
909 } samba_attributes[] = {
910 { "objectSid", LDB_SYNTAX_SAMBA_SID },
911 { "securityIdentifier", LDB_SYNTAX_SAMBA_SID },
912 { "ntSecurityDescriptor", LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR },
913 { "objectGUID", LDB_SYNTAX_SAMBA_GUID },
914 { "invocationId", LDB_SYNTAX_SAMBA_GUID },
915 { "schemaIDGUID", LDB_SYNTAX_SAMBA_GUID },
916 { "oMSyntax", LDB_SYNTAX_SAMBA_INT32 },
917 { "attributeSecurityGUID", LDB_SYNTAX_SAMBA_GUID },
918 { "parentGUID", LDB_SYNTAX_SAMBA_GUID },
919 { "siteGUID", LDB_SYNTAX_SAMBA_GUID },
920 { "pKTGUID", LDB_SYNTAX_SAMBA_GUID },
921 { "fRSVersionGUID", LDB_SYNTAX_SAMBA_GUID },
922 { "fRSReplicaSetGUID", LDB_SYNTAX_SAMBA_GUID },
923 { "netbootGUID", LDB_SYNTAX_SAMBA_GUID },
924 { "msDS-OptionalFeatureGUID", LDB_SYNTAX_SAMBA_GUID },
925 { "objectCategory", LDB_SYNTAX_SAMBA_OBJECT_CATEGORY },
926 { "prefixMap", LDB_SYNTAX_SAMBA_PREFIX_MAP },
927 { "repsFrom", LDB_SYNTAX_SAMBA_REPSFROMTO },
928 { "repsTo", LDB_SYNTAX_SAMBA_REPSFROMTO },
929 { "replPropertyMetaData", LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA },
930 { "replUpToDateVector", LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR },
933 const struct ldb_schema_syntax *ldb_samba_syntax_by_name(struct ldb_context *ldb, const char *name)
936 const struct ldb_schema_syntax *s = NULL;
938 for (j=0; j < ARRAY_SIZE(samba_syntaxes); j++) {
939 if (strcmp(name, samba_syntaxes[j].name) == 0) {
940 s = &samba_syntaxes[j];
947 const struct ldb_schema_syntax *ldb_samba_syntax_by_lDAPDisplayName(struct ldb_context *ldb, const char *name)
950 const struct ldb_schema_syntax *s = NULL;
952 for (j=0; j < ARRAY_SIZE(samba_attributes); j++) {
953 if (strcmp(samba_attributes[j].name, name) == 0) {
954 s = ldb_samba_syntax_by_name(ldb, samba_attributes[j].syntax);
963 register the samba ldif handlers
965 int ldb_register_samba_handlers(struct ldb_context *ldb)
969 for (i=0; i < ARRAY_SIZE(samba_attributes); i++) {
971 const struct ldb_schema_syntax *s = NULL;
973 s = ldb_samba_syntax_by_name(ldb, samba_attributes[i].syntax);
976 s = ldb_standard_syntax_by_name(ldb, samba_attributes[i].syntax);
983 ret = ldb_schema_attribute_add_with_syntax(ldb, samba_attributes[i].name, LDB_ATTR_FLAG_FIXED, s);
984 if (ret != LDB_SUCCESS) {
989 for (i=0; i < ARRAY_SIZE(samba_dn_syntax); i++) {
991 ret = ldb_dn_extended_add_syntax(ldb, LDB_ATTR_FLAG_FIXED, &samba_dn_syntax[i]);
992 if (ret != LDB_SUCCESS) {