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 *out = data_blob_talloc(mem_ctx, in->data, in->length);
436 if (in->data && !out->data) {
437 return LDB_ERR_OPERATIONS_ERROR;
441 dn1 = ldb_dn_from_ldb_val(tmp_ctx, ldb, in);
442 if ( ! ldb_dn_validate(dn1)) {
443 const char *lDAPDisplayName = talloc_strndup(tmp_ctx, (char *)in->data, in->length);
444 sclass = dsdb_class_by_lDAPDisplayName(schema, lDAPDisplayName);
446 struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb,
447 sclass->defaultObjectCategory);
448 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn));
449 talloc_free(tmp_ctx);
452 return LDB_ERR_OPERATIONS_ERROR;
456 *out = data_blob_talloc(mem_ctx, in->data, in->length);
457 talloc_free(tmp_ctx);
459 if (in->data && !out->data) {
460 return LDB_ERR_OPERATIONS_ERROR;
465 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn1));
466 talloc_free(tmp_ctx);
469 return LDB_ERR_OPERATIONS_ERROR;
474 static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx,
475 const struct ldb_val *v1,
476 const struct ldb_val *v2)
480 struct ldb_val v1_canon, v2_canon;
481 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
483 /* I could try and bail if tmp_ctx was NULL, but what return
486 * It seems easier to continue on the NULL context
488 ret1 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v1, &v1_canon);
489 ret2 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v2, &v2_canon);
491 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
492 ret = data_blob_cmp(&v1_canon, &v2_canon);
494 ret = data_blob_cmp(v1, v2);
496 talloc_free(tmp_ctx);
501 convert a ldif formatted prefixMap to a NDR formatted blob
503 static int ldif_read_prefixMap(struct ldb_context *ldb, void *mem_ctx,
504 const struct ldb_val *in, struct ldb_val *out)
506 struct prefixMapBlob *blob;
507 enum ndr_err_code ndr_err;
508 char *string, *line, *p, *oid;
510 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
512 if (tmp_ctx == NULL) {
516 blob = talloc_zero(tmp_ctx, struct prefixMapBlob);
522 blob->version = PREFIX_MAP_VERSION_DSDB;
524 string = talloc_strndup(mem_ctx, (const char *)in->data, in->length);
525 if (string == NULL) {
531 while (line && line[0]) {
536 p=strchr(line, '\n');
541 /* allow a traling seperator */
546 blob->ctr.dsdb.mappings = talloc_realloc(blob,
547 blob->ctr.dsdb.mappings,
548 struct drsuapi_DsReplicaOIDMapping,
549 blob->ctr.dsdb.num_mappings+1);
550 if (!blob->ctr.dsdb.mappings) {
551 talloc_free(tmp_ctx);
555 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].id_prefix = strtoul(line, &oid, 10);
558 talloc_free(tmp_ctx);
562 /* we know there must be at least ":" */
565 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].oid.oid
566 = talloc_strdup(blob->ctr.dsdb.mappings, oid);
568 blob->ctr.dsdb.num_mappings++;
570 /* Now look past the terminator we added above */
578 ndr_err = ndr_push_struct_blob(out, mem_ctx,
579 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
581 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
582 talloc_free(tmp_ctx);
583 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
590 convert a NDR formatted blob to a ldif formatted prefixMap
592 static int ldif_write_prefixMap(struct ldb_context *ldb, void *mem_ctx,
593 const struct ldb_val *in, struct ldb_val *out)
595 struct prefixMapBlob *blob;
596 enum ndr_err_code ndr_err;
600 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
601 return ldif_write_NDR(ldb, mem_ctx, in, out,
602 sizeof(struct prefixMapBlob),
603 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob,
604 (ndr_print_fn_t)ndr_print_prefixMapBlob);
608 blob = talloc(mem_ctx, struct prefixMapBlob);
612 ndr_err = ndr_pull_struct_blob_all(in, blob,
613 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
615 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
616 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
620 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
623 string = talloc_strdup(mem_ctx, "");
624 if (string == NULL) {
628 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
630 string = talloc_asprintf_append(string, ";");
632 string = talloc_asprintf_append(string, "%u:%s",
633 blob->ctr.dsdb.mappings[i].id_prefix,
634 blob->ctr.dsdb.mappings[i].oid.oid);
635 if (string == NULL) {
641 *out = data_blob_string_const(string);
645 static bool ldif_comparision_prefixMap_isString(const struct ldb_val *v)
651 if (IVAL(v->data, 0) == PREFIX_MAP_VERSION_DSDB) {
659 canonicalise a prefixMap
661 static int ldif_canonicalise_prefixMap(struct ldb_context *ldb, void *mem_ctx,
662 const struct ldb_val *in, struct ldb_val *out)
664 if (ldif_comparision_prefixMap_isString(in)) {
665 return ldif_read_prefixMap(ldb, mem_ctx, in, out);
667 return ldb_handler_copy(ldb, mem_ctx, in, out);
670 static int ldif_comparison_prefixMap(struct ldb_context *ldb, void *mem_ctx,
671 const struct ldb_val *v1,
672 const struct ldb_val *v2)
676 struct ldb_val v1_canon, v2_canon;
677 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
679 /* I could try and bail if tmp_ctx was NULL, but what return
682 * It seems easier to continue on the NULL context
684 ret1 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v1, &v1_canon);
685 ret2 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v2, &v2_canon);
687 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
688 ret = data_blob_cmp(&v1_canon, &v2_canon);
690 ret = data_blob_cmp(v1, v2);
692 talloc_free(tmp_ctx);
696 /* Canonicalisation of two 32-bit integers */
697 static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx,
698 const struct ldb_val *in, struct ldb_val *out)
701 /* We've to use "strtoll" here to have the intended overflows.
702 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
703 int32_t i = (int32_t) strtoll((char *)in->data, &end, 0);
707 out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%d", i);
708 if (out->data == NULL) {
711 out->length = strlen((char *)out->data);
715 /* Comparison of two 32-bit integers */
716 static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx,
717 const struct ldb_val *v1, const struct ldb_val *v2)
719 /* We've to use "strtoll" here to have the intended overflows.
720 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
721 return (int32_t) strtoll((char *)v1->data, NULL, 0)
722 - (int32_t) strtoll((char *)v2->data, NULL, 0);
726 convert a NDR formatted blob to a ldif formatted repsFromTo
728 static int ldif_write_repsFromTo(struct ldb_context *ldb, void *mem_ctx,
729 const struct ldb_val *in, struct ldb_val *out)
731 return ldif_write_NDR(ldb, mem_ctx, in, out,
732 sizeof(struct repsFromToBlob),
733 (ndr_pull_flags_fn_t)ndr_pull_repsFromToBlob,
734 (ndr_print_fn_t)ndr_print_repsFromToBlob);
738 convert a NDR formatted blob to a ldif formatted replPropertyMetaData
740 static int ldif_write_replPropertyMetaData(struct ldb_context *ldb, void *mem_ctx,
741 const struct ldb_val *in, struct ldb_val *out)
743 return ldif_write_NDR(ldb, mem_ctx, in, out,
744 sizeof(struct replPropertyMetaDataBlob),
745 (ndr_pull_flags_fn_t)ndr_pull_replPropertyMetaDataBlob,
746 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
750 convert a NDR formatted blob to a ldif formatted replUpToDateVector
752 static int ldif_write_replUpToDateVector(struct ldb_context *ldb, void *mem_ctx,
753 const struct ldb_val *in, struct ldb_val *out)
755 return ldif_write_NDR(ldb, mem_ctx, in, out,
756 sizeof(struct replUpToDateVectorBlob),
757 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob,
758 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
762 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
763 const struct ldb_val *in, struct ldb_val *out)
765 *out = data_blob_string_const(data_blob_hex_string(mem_ctx, in));
772 static const struct ldb_schema_syntax samba_syntaxes[] = {
774 .name = LDB_SYNTAX_SAMBA_SID,
775 .ldif_read_fn = ldif_read_objectSid,
776 .ldif_write_fn = ldif_write_objectSid,
777 .canonicalise_fn = ldif_canonicalise_objectSid,
778 .comparison_fn = ldif_comparison_objectSid
780 .name = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR,
781 .ldif_read_fn = ldif_read_ntSecurityDescriptor,
782 .ldif_write_fn = ldif_write_ntSecurityDescriptor,
783 .canonicalise_fn = ldb_handler_copy,
784 .comparison_fn = ldb_comparison_binary
786 .name = LDB_SYNTAX_SAMBA_GUID,
787 .ldif_read_fn = ldif_read_objectGUID,
788 .ldif_write_fn = ldif_write_objectGUID,
789 .canonicalise_fn = ldif_canonicalise_objectGUID,
790 .comparison_fn = ldif_comparison_objectGUID
792 .name = LDB_SYNTAX_SAMBA_OBJECT_CATEGORY,
793 .ldif_read_fn = ldb_handler_copy,
794 .ldif_write_fn = ldb_handler_copy,
795 .canonicalise_fn = ldif_canonicalise_objectCategory,
796 .comparison_fn = ldif_comparison_objectCategory
798 .name = LDB_SYNTAX_SAMBA_PREFIX_MAP,
799 .ldif_read_fn = ldif_read_prefixMap,
800 .ldif_write_fn = ldif_write_prefixMap,
801 .canonicalise_fn = ldif_canonicalise_prefixMap,
802 .comparison_fn = ldif_comparison_prefixMap
804 .name = LDB_SYNTAX_SAMBA_INT32,
805 .ldif_read_fn = ldb_handler_copy,
806 .ldif_write_fn = ldb_handler_copy,
807 .canonicalise_fn = ldif_canonicalise_int32,
808 .comparison_fn = ldif_comparison_int32
810 .name = LDB_SYNTAX_SAMBA_REPSFROMTO,
811 .ldif_read_fn = ldb_handler_copy,
812 .ldif_write_fn = ldif_write_repsFromTo,
813 .canonicalise_fn = ldb_handler_copy,
814 .comparison_fn = ldb_comparison_binary
816 .name = LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA,
817 .ldif_read_fn = ldb_handler_copy,
818 .ldif_write_fn = ldif_write_replPropertyMetaData,
819 .canonicalise_fn = ldb_handler_copy,
820 .comparison_fn = ldb_comparison_binary
822 .name = LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR,
823 .ldif_read_fn = ldb_handler_copy,
824 .ldif_write_fn = ldif_write_replUpToDateVector,
825 .canonicalise_fn = ldb_handler_copy,
826 .comparison_fn = ldb_comparison_binary
830 static const struct ldb_dn_extended_syntax samba_dn_syntax[] = {
833 .read_fn = extended_dn_read_SID,
834 .write_clear_fn = ldif_write_objectSid,
835 .write_hex_fn = extended_dn_write_hex
838 .read_fn = extended_dn_read_GUID,
839 .write_clear_fn = ldif_write_objectGUID,
840 .write_hex_fn = extended_dn_write_hex
843 .read_fn = ldb_handler_copy,
844 .write_clear_fn = ldb_handler_copy,
845 .write_hex_fn = ldb_handler_copy
849 /* TODO: Should be dynamic at some point */
850 static const struct {
853 } samba_attributes[] = {
854 { "objectSid", LDB_SYNTAX_SAMBA_SID },
855 { "securityIdentifier", LDB_SYNTAX_SAMBA_SID },
856 { "ntSecurityDescriptor", LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR },
857 { "objectGUID", LDB_SYNTAX_SAMBA_GUID },
858 { "invocationId", LDB_SYNTAX_SAMBA_GUID },
859 { "schemaIDGUID", LDB_SYNTAX_SAMBA_GUID },
860 { "attributeSecurityGUID", LDB_SYNTAX_SAMBA_GUID },
861 { "parentGUID", LDB_SYNTAX_SAMBA_GUID },
862 { "siteGUID", LDB_SYNTAX_SAMBA_GUID },
863 { "pKTGUID", LDB_SYNTAX_SAMBA_GUID },
864 { "fRSVersionGUID", LDB_SYNTAX_SAMBA_GUID },
865 { "fRSReplicaSetGUID", LDB_SYNTAX_SAMBA_GUID },
866 { "netbootGUID", LDB_SYNTAX_SAMBA_GUID },
867 { "objectCategory", LDB_SYNTAX_SAMBA_OBJECT_CATEGORY },
868 { "prefixMap", LDB_SYNTAX_SAMBA_PREFIX_MAP },
869 { "repsFrom", LDB_SYNTAX_SAMBA_REPSFROMTO },
870 { "repsTo", LDB_SYNTAX_SAMBA_REPSFROMTO },
871 { "replPropertyMetaData", LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA },
872 { "replUpToDateVector", LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR },
875 const struct ldb_schema_syntax *ldb_samba_syntax_by_name(struct ldb_context *ldb, const char *name)
878 const struct ldb_schema_syntax *s = NULL;
880 for (j=0; j < ARRAY_SIZE(samba_syntaxes); j++) {
881 if (strcmp(name, samba_syntaxes[j].name) == 0) {
882 s = &samba_syntaxes[j];
889 const struct ldb_schema_syntax *ldb_samba_syntax_by_lDAPDisplayName(struct ldb_context *ldb, const char *name)
892 const struct ldb_schema_syntax *s = NULL;
894 for (j=0; j < ARRAY_SIZE(samba_attributes); j++) {
895 if (strcmp(samba_attributes[j].name, name) == 0) {
896 s = ldb_samba_syntax_by_name(ldb, samba_attributes[j].syntax);
905 register the samba ldif handlers
907 int ldb_register_samba_handlers(struct ldb_context *ldb)
911 for (i=0; i < ARRAY_SIZE(samba_attributes); i++) {
913 const struct ldb_schema_syntax *s = NULL;
915 s = ldb_samba_syntax_by_name(ldb, samba_attributes[i].syntax);
918 s = ldb_standard_syntax_by_name(ldb, samba_attributes[i].syntax);
925 ret = ldb_schema_attribute_add_with_syntax(ldb, samba_attributes[i].name, LDB_ATTR_FLAG_FIXED, s);
926 if (ret != LDB_SUCCESS) {
931 for (i=0; i < ARRAY_SIZE(samba_dn_syntax); i++) {
933 ret = ldb_dn_extended_add_syntax(ldb, LDB_ATTR_FLAG_FIXED, &samba_dn_syntax[i]);
934 if (ret != LDB_SUCCESS) {