2 ldb database library - ldif handlers for Samba
4 Copyright (C) Andrew Tridgell 2005
5 Copyright (C) Andrew Bartlett 2006-2007
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"
38 use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob
40 static int ldif_write_NDR(struct ldb_context *ldb, void *mem_ctx,
41 const struct ldb_val *in, struct ldb_val *out,
43 ndr_pull_flags_fn_t pull_fn,
44 ndr_print_fn_t print_fn)
47 enum ndr_err_code err;
48 if (!(ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY)) {
49 return ldb_handler_copy(ldb, mem_ctx, in, out);
51 p = talloc_size(mem_ctx, struct_size);
52 err = ndr_pull_struct_blob(in, mem_ctx,
53 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
55 if (err != NDR_ERR_SUCCESS) {
57 out->data = (uint8_t *)talloc_strdup(mem_ctx, "<Unable to decode binary data>");
58 out->length = strlen((const char *)out->data);
61 out->data = (uint8_t *)ndr_print_struct_string(mem_ctx, print_fn, "NDR", p);
63 if (out->data == NULL) {
64 return ldb_handler_copy(ldb, mem_ctx, in, out);
66 out->length = strlen((char *)out->data);
71 convert a ldif formatted objectSid to a NDR formatted blob
73 static int ldif_read_objectSid(struct ldb_context *ldb, void *mem_ctx,
74 const struct ldb_val *in, struct ldb_val *out)
76 enum ndr_err_code ndr_err;
78 sid = dom_sid_parse_length(mem_ctx, in);
82 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, sid,
83 (ndr_push_flags_fn_t)ndr_push_dom_sid);
85 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
92 convert a NDR formatted blob to a ldif formatted objectSid
94 static int ldif_write_objectSid(struct ldb_context *ldb, void *mem_ctx,
95 const struct ldb_val *in, struct ldb_val *out)
98 enum ndr_err_code ndr_err;
100 sid = talloc(mem_ctx, struct dom_sid);
104 ndr_err = ndr_pull_struct_blob_all(in, sid, NULL, sid,
105 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
106 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
110 *out = data_blob_string_const(dom_sid_string(mem_ctx, sid));
112 if (out->data == NULL) {
118 static bool ldif_comparision_objectSid_isString(const struct ldb_val *v)
124 if (strncmp("S-", (const char *)v->data, 2) != 0) return false;
130 compare two objectSids
132 static int ldif_comparison_objectSid(struct ldb_context *ldb, void *mem_ctx,
133 const struct ldb_val *v1, const struct ldb_val *v2)
135 if (ldif_comparision_objectSid_isString(v1) && ldif_comparision_objectSid_isString(v2)) {
136 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
137 } else if (ldif_comparision_objectSid_isString(v1)
138 && !ldif_comparision_objectSid_isString(v2)) {
141 if (ldif_read_objectSid(ldb, mem_ctx, v1, &v) != 0) {
142 /* Perhaps not a string after all */
143 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
145 ret = ldb_comparison_binary(ldb, mem_ctx, &v, v2);
148 } else if (!ldif_comparision_objectSid_isString(v1)
149 && ldif_comparision_objectSid_isString(v2)) {
152 if (ldif_read_objectSid(ldb, mem_ctx, v2, &v) != 0) {
153 /* Perhaps not a string after all */
154 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
156 ret = ldb_comparison_binary(ldb, mem_ctx, v1, &v);
160 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
164 canonicalise a objectSid
166 static int ldif_canonicalise_objectSid(struct ldb_context *ldb, void *mem_ctx,
167 const struct ldb_val *in, struct ldb_val *out)
169 if (ldif_comparision_objectSid_isString(in)) {
170 if (ldif_read_objectSid(ldb, mem_ctx, in, out) != 0) {
171 /* Perhaps not a string after all */
172 return ldb_handler_copy(ldb, mem_ctx, in, out);
176 return ldb_handler_copy(ldb, mem_ctx, in, out);
179 static int extended_dn_read_SID(struct ldb_context *ldb, void *mem_ctx,
180 const struct ldb_val *in, struct ldb_val *out)
183 enum ndr_err_code ndr_err;
184 if (ldif_comparision_objectSid_isString(in)) {
185 if (ldif_read_objectSid(ldb, mem_ctx, in, out) == 0) {
190 /* Perhaps not a string after all */
191 *out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
197 (*out).length = strhex_to_str((char *)out->data, out->length,
198 (const char *)in->data, in->length);
200 /* Check it looks like a SID */
201 ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &sid,
202 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
203 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
210 convert a ldif formatted objectGUID to a NDR formatted blob
212 static int ldif_read_objectGUID(struct ldb_context *ldb, void *mem_ctx,
213 const struct ldb_val *in, struct ldb_val *out)
217 enum ndr_err_code ndr_err;
219 status = GUID_from_data_blob(in, &guid);
220 if (!NT_STATUS_IS_OK(status)) {
224 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, &guid,
225 (ndr_push_flags_fn_t)ndr_push_GUID);
226 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
233 convert a NDR formatted blob to a ldif formatted objectGUID
235 static int ldif_write_objectGUID(struct ldb_context *ldb, void *mem_ctx,
236 const struct ldb_val *in, struct ldb_val *out)
239 enum ndr_err_code ndr_err;
240 ndr_err = ndr_pull_struct_blob_all(in, mem_ctx, NULL, &guid,
241 (ndr_pull_flags_fn_t)ndr_pull_GUID);
242 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
245 out->data = (uint8_t *)GUID_string(mem_ctx, &guid);
246 if (out->data == NULL) {
249 out->length = strlen((const char *)out->data);
253 static bool ldif_comparision_objectGUID_isString(const struct ldb_val *v)
255 if (v->length != 36 && v->length != 38) return false;
257 /* Might be a GUID string, can't be a binary GUID (fixed 16 bytes) */
261 static int extended_dn_read_GUID(struct ldb_context *ldb, void *mem_ctx,
262 const struct ldb_val *in, struct ldb_val *out)
265 enum ndr_err_code ndr_err;
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 ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &guid,
286 (ndr_pull_flags_fn_t)ndr_pull_GUID);
287 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
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)
481 struct ldb_val v1_canon, v2_canon;
482 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
484 /* I could try and bail if tmp_ctx was NULL, but what return
487 * It seems easier to continue on the NULL context
489 ret1 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v1, &v1_canon);
490 ret2 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v2, &v2_canon);
492 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
493 ret = data_blob_cmp(&v1_canon, &v2_canon);
495 ret = data_blob_cmp(v1, v2);
497 talloc_free(tmp_ctx);
502 convert a ldif formatted prefixMap to a NDR formatted blob
504 static int ldif_read_prefixMap(struct ldb_context *ldb, void *mem_ctx,
505 const struct ldb_val *in, struct ldb_val *out)
507 struct prefixMapBlob *blob;
508 enum ndr_err_code ndr_err;
509 char *string, *line, *p, *oid;
511 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
513 if (tmp_ctx == NULL) {
517 blob = talloc_zero(tmp_ctx, struct prefixMapBlob);
523 blob->version = PREFIX_MAP_VERSION_DSDB;
525 string = talloc_strndup(mem_ctx, (const char *)in->data, in->length);
526 if (string == NULL) {
532 while (line && line[0]) {
537 p=strchr(line, '\n');
542 /* allow a traling seperator */
547 blob->ctr.dsdb.mappings = talloc_realloc(blob,
548 blob->ctr.dsdb.mappings,
549 struct drsuapi_DsReplicaOIDMapping,
550 blob->ctr.dsdb.num_mappings+1);
551 if (!blob->ctr.dsdb.mappings) {
552 talloc_free(tmp_ctx);
556 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].id_prefix = strtoul(line, &oid, 10);
559 talloc_free(tmp_ctx);
563 /* we know there must be at least ":" */
566 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].oid.oid
567 = talloc_strdup(blob->ctr.dsdb.mappings, oid);
569 blob->ctr.dsdb.num_mappings++;
571 /* Now look past the terminator we added above */
579 ndr_err = ndr_push_struct_blob(out, mem_ctx,
580 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
582 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
583 talloc_free(tmp_ctx);
584 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
591 convert a NDR formatted blob to a ldif formatted prefixMap
593 static int ldif_write_prefixMap(struct ldb_context *ldb, void *mem_ctx,
594 const struct ldb_val *in, struct ldb_val *out)
596 struct prefixMapBlob *blob;
597 enum ndr_err_code ndr_err;
601 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
602 return ldif_write_NDR(ldb, mem_ctx, in, out,
603 sizeof(struct prefixMapBlob),
604 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob,
605 (ndr_print_fn_t)ndr_print_prefixMapBlob);
609 blob = talloc(mem_ctx, struct prefixMapBlob);
613 ndr_err = ndr_pull_struct_blob_all(in, blob,
614 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
616 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
617 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
621 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
624 string = talloc_strdup(mem_ctx, "");
625 if (string == NULL) {
629 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
631 string = talloc_asprintf_append(string, ";");
633 string = talloc_asprintf_append(string, "%u:%s",
634 blob->ctr.dsdb.mappings[i].id_prefix,
635 blob->ctr.dsdb.mappings[i].oid.oid);
636 if (string == NULL) {
642 *out = data_blob_string_const(string);
646 static bool ldif_comparision_prefixMap_isString(const struct ldb_val *v)
652 if (IVAL(v->data, 0) == PREFIX_MAP_VERSION_DSDB) {
660 canonicalise a prefixMap
662 static int ldif_canonicalise_prefixMap(struct ldb_context *ldb, void *mem_ctx,
663 const struct ldb_val *in, struct ldb_val *out)
665 if (ldif_comparision_prefixMap_isString(in)) {
666 return ldif_read_prefixMap(ldb, mem_ctx, in, out);
668 return ldb_handler_copy(ldb, mem_ctx, in, out);
671 static int ldif_comparison_prefixMap(struct ldb_context *ldb, void *mem_ctx,
672 const struct ldb_val *v1,
673 const struct ldb_val *v2)
677 struct ldb_val v1_canon, v2_canon;
678 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
680 /* I could try and bail if tmp_ctx was NULL, but what return
683 * It seems easier to continue on the NULL context
685 ret1 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v1, &v1_canon);
686 ret2 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v2, &v2_canon);
688 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
689 ret = data_blob_cmp(&v1_canon, &v2_canon);
691 ret = data_blob_cmp(v1, v2);
693 talloc_free(tmp_ctx);
697 /* Canonicalisation of two 32-bit integers */
698 static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx,
699 const struct ldb_val *in, struct ldb_val *out)
702 /* We've to use "strtoll" here to have the intended overflows.
703 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
704 int32_t i = (int32_t) strtoll((char *)in->data, &end, 0);
708 out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%d", i);
709 if (out->data == NULL) {
712 out->length = strlen((char *)out->data);
716 /* Comparison of two 32-bit integers */
717 static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx,
718 const struct ldb_val *v1, const struct ldb_val *v2)
720 /* We've to use "strtoll" here to have the intended overflows.
721 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
722 return (int32_t) strtoll((char *)v1->data, NULL, 0)
723 - (int32_t) strtoll((char *)v2->data, NULL, 0);
727 convert a NDR formatted blob to a ldif formatted repsFromTo
729 static int ldif_write_repsFromTo(struct ldb_context *ldb, void *mem_ctx,
730 const struct ldb_val *in, struct ldb_val *out)
732 return ldif_write_NDR(ldb, mem_ctx, in, out,
733 sizeof(struct repsFromToBlob),
734 (ndr_pull_flags_fn_t)ndr_pull_repsFromToBlob,
735 (ndr_print_fn_t)ndr_print_repsFromToBlob);
739 convert a NDR formatted blob to a ldif formatted replPropertyMetaData
741 static int ldif_write_replPropertyMetaData(struct ldb_context *ldb, void *mem_ctx,
742 const struct ldb_val *in, struct ldb_val *out)
744 return ldif_write_NDR(ldb, mem_ctx, in, out,
745 sizeof(struct replPropertyMetaDataBlob),
746 (ndr_pull_flags_fn_t)ndr_pull_replPropertyMetaDataBlob,
747 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
751 convert a NDR formatted blob to a ldif formatted replUpToDateVector
753 static int ldif_write_replUpToDateVector(struct ldb_context *ldb, void *mem_ctx,
754 const struct ldb_val *in, struct ldb_val *out)
756 return ldif_write_NDR(ldb, mem_ctx, in, out,
757 sizeof(struct replUpToDateVectorBlob),
758 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob,
759 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
763 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
764 const struct ldb_val *in, struct ldb_val *out)
766 *out = data_blob_string_const(data_blob_hex_string(mem_ctx, in));
773 static const struct ldb_schema_syntax samba_syntaxes[] = {
775 .name = LDB_SYNTAX_SAMBA_SID,
776 .ldif_read_fn = ldif_read_objectSid,
777 .ldif_write_fn = ldif_write_objectSid,
778 .canonicalise_fn = ldif_canonicalise_objectSid,
779 .comparison_fn = ldif_comparison_objectSid
781 .name = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR,
782 .ldif_read_fn = ldif_read_ntSecurityDescriptor,
783 .ldif_write_fn = ldif_write_ntSecurityDescriptor,
784 .canonicalise_fn = ldb_handler_copy,
785 .comparison_fn = ldb_comparison_binary
787 .name = LDB_SYNTAX_SAMBA_GUID,
788 .ldif_read_fn = ldif_read_objectGUID,
789 .ldif_write_fn = ldif_write_objectGUID,
790 .canonicalise_fn = ldif_canonicalise_objectGUID,
791 .comparison_fn = ldif_comparison_objectGUID
793 .name = LDB_SYNTAX_SAMBA_OBJECT_CATEGORY,
794 .ldif_read_fn = ldb_handler_copy,
795 .ldif_write_fn = ldb_handler_copy,
796 .canonicalise_fn = ldif_canonicalise_objectCategory,
797 .comparison_fn = ldif_comparison_objectCategory
799 .name = LDB_SYNTAX_SAMBA_PREFIX_MAP,
800 .ldif_read_fn = ldif_read_prefixMap,
801 .ldif_write_fn = ldif_write_prefixMap,
802 .canonicalise_fn = ldif_canonicalise_prefixMap,
803 .comparison_fn = ldif_comparison_prefixMap
805 .name = LDB_SYNTAX_SAMBA_INT32,
806 .ldif_read_fn = ldb_handler_copy,
807 .ldif_write_fn = ldb_handler_copy,
808 .canonicalise_fn = ldif_canonicalise_int32,
809 .comparison_fn = ldif_comparison_int32
811 .name = LDB_SYNTAX_SAMBA_REPSFROMTO,
812 .ldif_read_fn = ldb_handler_copy,
813 .ldif_write_fn = ldif_write_repsFromTo,
814 .canonicalise_fn = ldb_handler_copy,
815 .comparison_fn = ldb_comparison_binary
817 .name = LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA,
818 .ldif_read_fn = ldb_handler_copy,
819 .ldif_write_fn = ldif_write_replPropertyMetaData,
820 .canonicalise_fn = ldb_handler_copy,
821 .comparison_fn = ldb_comparison_binary
823 .name = LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR,
824 .ldif_read_fn = ldb_handler_copy,
825 .ldif_write_fn = ldif_write_replUpToDateVector,
826 .canonicalise_fn = ldb_handler_copy,
827 .comparison_fn = ldb_comparison_binary
831 static const struct ldb_dn_extended_syntax samba_dn_syntax[] = {
834 .read_fn = extended_dn_read_SID,
835 .write_clear_fn = ldif_write_objectSid,
836 .write_hex_fn = extended_dn_write_hex
839 .read_fn = extended_dn_read_GUID,
840 .write_clear_fn = ldif_write_objectGUID,
841 .write_hex_fn = extended_dn_write_hex
844 .read_fn = ldb_handler_copy,
845 .write_clear_fn = ldb_handler_copy,
846 .write_hex_fn = ldb_handler_copy
850 /* TODO: Should be dynamic at some point */
851 static const struct {
854 } samba_attributes[] = {
855 { "objectSid", LDB_SYNTAX_SAMBA_SID },
856 { "securityIdentifier", LDB_SYNTAX_SAMBA_SID },
857 { "ntSecurityDescriptor", LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR },
858 { "objectGUID", LDB_SYNTAX_SAMBA_GUID },
859 { "invocationId", LDB_SYNTAX_SAMBA_GUID },
860 { "schemaIDGUID", LDB_SYNTAX_SAMBA_GUID },
861 { "attributeSecurityGUID", LDB_SYNTAX_SAMBA_GUID },
862 { "parentGUID", LDB_SYNTAX_SAMBA_GUID },
863 { "siteGUID", LDB_SYNTAX_SAMBA_GUID },
864 { "pKTGUID", LDB_SYNTAX_SAMBA_GUID },
865 { "fRSVersionGUID", LDB_SYNTAX_SAMBA_GUID },
866 { "fRSReplicaSetGUID", LDB_SYNTAX_SAMBA_GUID },
867 { "netbootGUID", LDB_SYNTAX_SAMBA_GUID },
868 { "objectCategory", LDB_SYNTAX_SAMBA_OBJECT_CATEGORY },
869 { "prefixMap", LDB_SYNTAX_SAMBA_PREFIX_MAP },
870 { "repsFrom", LDB_SYNTAX_SAMBA_REPSFROMTO },
871 { "repsTo", LDB_SYNTAX_SAMBA_REPSFROMTO },
872 { "replPropertyMetaData", LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA },
873 { "replUpToDateVector", LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR },
876 const struct ldb_schema_syntax *ldb_samba_syntax_by_name(struct ldb_context *ldb, const char *name)
879 const struct ldb_schema_syntax *s = NULL;
881 for (j=0; j < ARRAY_SIZE(samba_syntaxes); j++) {
882 if (strcmp(name, samba_syntaxes[j].name) == 0) {
883 s = &samba_syntaxes[j];
890 const struct ldb_schema_syntax *ldb_samba_syntax_by_lDAPDisplayName(struct ldb_context *ldb, const char *name)
893 const struct ldb_schema_syntax *s = NULL;
895 for (j=0; j < ARRAY_SIZE(samba_attributes); j++) {
896 if (strcmp(samba_attributes[j].name, name) == 0) {
897 s = ldb_samba_syntax_by_name(ldb, samba_attributes[j].syntax);
906 register the samba ldif handlers
908 int ldb_register_samba_handlers(struct ldb_context *ldb)
912 for (i=0; i < ARRAY_SIZE(samba_attributes); i++) {
914 const struct ldb_schema_syntax *s = NULL;
916 s = ldb_samba_syntax_by_name(ldb, samba_attributes[i].syntax);
919 s = ldb_standard_syntax_by_name(ldb, samba_attributes[i].syntax);
926 ret = ldb_schema_attribute_add_with_syntax(ldb, samba_attributes[i].name, LDB_ATTR_FLAG_FIXED, s);
927 if (ret != LDB_SUCCESS) {
932 for (i=0; i < ARRAY_SIZE(samba_dn_syntax); i++) {
934 ret = ldb_dn_extended_add_syntax(ldb, LDB_ATTR_FLAG_FIXED, &samba_dn_syntax[i]);
935 if (ret != LDB_SUCCESS) {