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;
185 if (ldif_comparision_objectSid_isString(in)) {
186 if (ldif_read_objectSid(ldb, mem_ctx, in, out) == 0) {
191 tmp_ctx = talloc_new(mem_ctx);
196 /* Perhaps not a string after all */
197 *out = data_blob_talloc(tmp_ctx, NULL, in->length/2+1);
200 talloc_free(tmp_ctx);
204 out->length = strhex_to_str((char *)out->data, out->length,
205 (const char *)in->data, in->length);
207 /* Check it looks like a SID */
208 ndr_err = ndr_pull_struct_blob_all(out, tmp_ctx, NULL, &sid,
209 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
210 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
211 talloc_free(tmp_ctx);
214 talloc_steal(mem_ctx, out->data);
215 talloc_free(tmp_ctx);
220 convert a ldif formatted objectGUID to a NDR formatted blob
222 static int ldif_read_objectGUID(struct ldb_context *ldb, void *mem_ctx,
223 const struct ldb_val *in, struct ldb_val *out)
227 enum ndr_err_code ndr_err;
228 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
233 status = GUID_from_data_blob(in, &guid);
234 if (!NT_STATUS_IS_OK(status)) {
238 ndr_err = ndr_push_struct_blob(out, tmp_ctx, NULL, &guid,
239 (ndr_push_flags_fn_t)ndr_push_GUID);
240 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
241 talloc_free(tmp_ctx);
244 talloc_steal(mem_ctx, out->data);
245 talloc_free(tmp_ctx);
250 convert a NDR formatted blob to a ldif formatted objectGUID
252 static int ldif_write_objectGUID(struct ldb_context *ldb, void *mem_ctx,
253 const struct ldb_val *in, struct ldb_val *out)
256 enum ndr_err_code ndr_err;
257 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
261 ndr_err = ndr_pull_struct_blob_all(in, tmp_ctx, NULL, &guid,
262 (ndr_pull_flags_fn_t)ndr_pull_GUID);
263 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
264 talloc_free(tmp_ctx);
267 out->data = (uint8_t *)GUID_string(mem_ctx, &guid);
268 talloc_free(tmp_ctx);
269 if (out->data == NULL) {
272 out->length = strlen((const char *)out->data);
276 static bool ldif_comparision_objectGUID_isString(const struct ldb_val *v)
278 if (v->length != 36 && v->length != 38) return false;
280 /* Might be a GUID string, can't be a binary GUID (fixed 16 bytes) */
284 static int extended_dn_read_GUID(struct ldb_context *ldb, void *mem_ctx,
285 const struct ldb_val *in, struct ldb_val *out)
288 enum ndr_err_code ndr_err;
290 if (in->length == 36 && ldif_read_objectGUID(ldb, mem_ctx, in, out) == 0) {
294 /* Try as 'hex' form */
295 if (in->length != 32) {
299 tmp_ctx = talloc_new(mem_ctx);
304 *out = data_blob_talloc(tmp_ctx, NULL, in->length/2+1);
307 talloc_free(tmp_ctx);
311 out->length = strhex_to_str((char *)out->data, out->length,
312 (const char *)in->data, in->length);
314 /* Check it looks like a GUID */
315 ndr_err = ndr_pull_struct_blob_all(out, tmp_ctx, NULL, &guid,
316 (ndr_pull_flags_fn_t)ndr_pull_GUID);
317 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
318 talloc_free(tmp_ctx);
321 talloc_steal(mem_ctx, out->data);
322 talloc_free(tmp_ctx);
327 compare two objectGUIDs
329 static int ldif_comparison_objectGUID(struct ldb_context *ldb, void *mem_ctx,
330 const struct ldb_val *v1, const struct ldb_val *v2)
332 if (ldif_comparision_objectGUID_isString(v1) && ldif_comparision_objectGUID_isString(v2)) {
333 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
334 } else if (ldif_comparision_objectGUID_isString(v1)
335 && !ldif_comparision_objectGUID_isString(v2)) {
338 if (ldif_read_objectGUID(ldb, mem_ctx, v1, &v) != 0) {
339 /* Perhaps it wasn't a valid string after all */
340 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
342 ret = ldb_comparison_binary(ldb, mem_ctx, &v, v2);
345 } else if (!ldif_comparision_objectGUID_isString(v1)
346 && ldif_comparision_objectGUID_isString(v2)) {
349 if (ldif_read_objectGUID(ldb, mem_ctx, v2, &v) != 0) {
350 /* Perhaps it wasn't a valid string after all */
351 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
353 ret = ldb_comparison_binary(ldb, mem_ctx, v1, &v);
357 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
361 canonicalise a objectGUID
363 static int ldif_canonicalise_objectGUID(struct ldb_context *ldb, void *mem_ctx,
364 const struct ldb_val *in, struct ldb_val *out)
366 if (ldif_comparision_objectGUID_isString(in)) {
367 if (ldif_read_objectGUID(ldb, mem_ctx, in, out) != 0) {
368 /* Perhaps it wasn't a valid string after all */
369 return ldb_handler_copy(ldb, mem_ctx, in, out);
373 return ldb_handler_copy(ldb, mem_ctx, in, out);
378 convert a ldif (SDDL) formatted ntSecurityDescriptor to a NDR formatted blob
380 static int ldif_read_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx,
381 const struct ldb_val *in, struct ldb_val *out)
383 struct security_descriptor *sd;
384 enum ndr_err_code ndr_err;
386 sd = talloc(mem_ctx, struct security_descriptor);
391 ndr_err = ndr_pull_struct_blob(in, sd, NULL, sd,
392 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
393 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
394 /* If this does not parse, then it is probably SDDL, and we should try it that way */
396 const struct dom_sid *sid = samdb_domain_sid(ldb);
398 sd = sddl_decode(mem_ctx, (const char *)in->data, sid);
404 ndr_err = ndr_push_struct_blob(out, sd, NULL, sd,
405 (ndr_push_flags_fn_t)ndr_push_security_descriptor);
406 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
410 talloc_steal(mem_ctx, out->data);
417 convert a NDR formatted blob to a ldif formatted ntSecurityDescriptor (SDDL format)
419 static int ldif_write_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx,
420 const struct ldb_val *in, struct ldb_val *out)
422 struct security_descriptor *sd;
423 enum ndr_err_code ndr_err;
425 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
426 return ldif_write_NDR(ldb, mem_ctx, in, out,
427 sizeof(struct security_descriptor),
428 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor,
429 (ndr_print_fn_t)ndr_print_security_descriptor);
433 sd = talloc(mem_ctx, struct security_descriptor);
437 /* We can't use ndr_pull_struct_blob_all because this contains relative pointers */
438 ndr_err = ndr_pull_struct_blob(in, sd, NULL, sd,
439 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
440 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
444 out->data = (uint8_t *)sddl_encode(mem_ctx, sd, NULL);
446 if (out->data == NULL) {
449 out->length = strlen((const char *)out->data);
454 canonicalise an objectCategory. We use the short form as the cannoical form:
455 cn=Person,cn=Schema,cn=Configuration,<basedn> becomes 'person'
458 static int ldif_canonicalise_objectCategory(struct ldb_context *ldb, void *mem_ctx,
459 const struct ldb_val *in, struct ldb_val *out)
461 struct ldb_dn *dn1 = NULL;
462 const struct dsdb_schema *schema = dsdb_get_schema(ldb);
463 const struct dsdb_class *sclass;
464 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
466 return LDB_ERR_OPERATIONS_ERROR;
470 talloc_free(tmp_ctx);
471 *out = data_blob_talloc(mem_ctx, in->data, in->length);
472 if (in->data && !out->data) {
473 return LDB_ERR_OPERATIONS_ERROR;
477 dn1 = ldb_dn_from_ldb_val(tmp_ctx, ldb, in);
478 if ( ! ldb_dn_validate(dn1)) {
479 const char *lDAPDisplayName = talloc_strndup(tmp_ctx, (char *)in->data, in->length);
480 sclass = dsdb_class_by_lDAPDisplayName(schema, lDAPDisplayName);
482 struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb,
483 sclass->defaultObjectCategory);
484 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn));
485 talloc_free(tmp_ctx);
488 return LDB_ERR_OPERATIONS_ERROR;
492 *out = data_blob_talloc(mem_ctx, in->data, in->length);
493 talloc_free(tmp_ctx);
495 if (in->data && !out->data) {
496 return LDB_ERR_OPERATIONS_ERROR;
501 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn1));
502 talloc_free(tmp_ctx);
505 return LDB_ERR_OPERATIONS_ERROR;
510 static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx,
511 const struct ldb_val *v1,
512 const struct ldb_val *v2)
516 struct ldb_val v1_canon, v2_canon;
517 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
519 /* I could try and bail if tmp_ctx was NULL, but what return
522 * It seems easier to continue on the NULL context
524 ret1 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v1, &v1_canon);
525 ret2 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v2, &v2_canon);
527 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
528 ret = data_blob_cmp(&v1_canon, &v2_canon);
530 ret = data_blob_cmp(v1, v2);
532 talloc_free(tmp_ctx);
537 convert a ldif formatted prefixMap to a NDR formatted blob
539 static int ldif_read_prefixMap(struct ldb_context *ldb, void *mem_ctx,
540 const struct ldb_val *in, struct ldb_val *out)
542 struct prefixMapBlob *blob;
543 enum ndr_err_code ndr_err;
544 char *string, *line, *p, *oid;
546 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
548 if (tmp_ctx == NULL) {
552 blob = talloc_zero(tmp_ctx, struct prefixMapBlob);
558 blob->version = PREFIX_MAP_VERSION_DSDB;
560 string = talloc_strndup(mem_ctx, (const char *)in->data, in->length);
561 if (string == NULL) {
567 while (line && line[0]) {
572 p=strchr(line, '\n');
577 /* allow a traling seperator */
582 blob->ctr.dsdb.mappings = talloc_realloc(blob,
583 blob->ctr.dsdb.mappings,
584 struct drsuapi_DsReplicaOIDMapping,
585 blob->ctr.dsdb.num_mappings+1);
586 if (!blob->ctr.dsdb.mappings) {
587 talloc_free(tmp_ctx);
591 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].id_prefix = strtoul(line, &oid, 10);
594 talloc_free(tmp_ctx);
598 /* we know there must be at least ":" */
601 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].oid.oid
602 = talloc_strdup(blob->ctr.dsdb.mappings, oid);
604 blob->ctr.dsdb.num_mappings++;
606 /* Now look past the terminator we added above */
614 ndr_err = ndr_push_struct_blob(out, mem_ctx,
615 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
617 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
618 talloc_free(tmp_ctx);
619 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
626 convert a NDR formatted blob to a ldif formatted prefixMap
628 static int ldif_write_prefixMap(struct ldb_context *ldb, void *mem_ctx,
629 const struct ldb_val *in, struct ldb_val *out)
631 struct prefixMapBlob *blob;
632 enum ndr_err_code ndr_err;
636 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
637 return ldif_write_NDR(ldb, mem_ctx, in, out,
638 sizeof(struct prefixMapBlob),
639 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob,
640 (ndr_print_fn_t)ndr_print_prefixMapBlob);
644 blob = talloc(mem_ctx, struct prefixMapBlob);
648 ndr_err = ndr_pull_struct_blob_all(in, blob,
649 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
651 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
652 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
656 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
659 string = talloc_strdup(mem_ctx, "");
660 if (string == NULL) {
664 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
666 string = talloc_asprintf_append(string, ";");
668 string = talloc_asprintf_append(string, "%u:%s",
669 blob->ctr.dsdb.mappings[i].id_prefix,
670 blob->ctr.dsdb.mappings[i].oid.oid);
671 if (string == NULL) {
677 *out = data_blob_string_const(string);
681 static bool ldif_comparision_prefixMap_isString(const struct ldb_val *v)
687 if (IVAL(v->data, 0) == PREFIX_MAP_VERSION_DSDB) {
695 canonicalise a prefixMap
697 static int ldif_canonicalise_prefixMap(struct ldb_context *ldb, void *mem_ctx,
698 const struct ldb_val *in, struct ldb_val *out)
700 if (ldif_comparision_prefixMap_isString(in)) {
701 return ldif_read_prefixMap(ldb, mem_ctx, in, out);
703 return ldb_handler_copy(ldb, mem_ctx, in, out);
706 static int ldif_comparison_prefixMap(struct ldb_context *ldb, void *mem_ctx,
707 const struct ldb_val *v1,
708 const struct ldb_val *v2)
712 struct ldb_val v1_canon, v2_canon;
713 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
715 /* I could try and bail if tmp_ctx was NULL, but what return
718 * It seems easier to continue on the NULL context
720 ret1 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v1, &v1_canon);
721 ret2 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v2, &v2_canon);
723 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
724 ret = data_blob_cmp(&v1_canon, &v2_canon);
726 ret = data_blob_cmp(v1, v2);
728 talloc_free(tmp_ctx);
732 /* Canonicalisation of two 32-bit integers */
733 static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx,
734 const struct ldb_val *in, struct ldb_val *out)
737 /* We've to use "strtoll" here to have the intended overflows.
738 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
739 int32_t i = (int32_t) strtoll((char *)in->data, &end, 0);
743 out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%d", i);
744 if (out->data == NULL) {
747 out->length = strlen((char *)out->data);
751 /* Comparison of two 32-bit integers */
752 static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx,
753 const struct ldb_val *v1, const struct ldb_val *v2)
755 /* We've to use "strtoll" here to have the intended overflows.
756 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
757 return (int32_t) strtoll((char *)v1->data, NULL, 0)
758 - (int32_t) strtoll((char *)v2->data, NULL, 0);
762 convert a NDR formatted blob to a ldif formatted repsFromTo
764 static int ldif_write_repsFromTo(struct ldb_context *ldb, void *mem_ctx,
765 const struct ldb_val *in, struct ldb_val *out)
767 return ldif_write_NDR(ldb, mem_ctx, in, out,
768 sizeof(struct repsFromToBlob),
769 (ndr_pull_flags_fn_t)ndr_pull_repsFromToBlob,
770 (ndr_print_fn_t)ndr_print_repsFromToBlob);
774 convert a NDR formatted blob to a ldif formatted replPropertyMetaData
776 static int ldif_write_replPropertyMetaData(struct ldb_context *ldb, void *mem_ctx,
777 const struct ldb_val *in, struct ldb_val *out)
779 return ldif_write_NDR(ldb, mem_ctx, in, out,
780 sizeof(struct replPropertyMetaDataBlob),
781 (ndr_pull_flags_fn_t)ndr_pull_replPropertyMetaDataBlob,
782 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
786 convert a NDR formatted blob to a ldif formatted replUpToDateVector
788 static int ldif_write_replUpToDateVector(struct ldb_context *ldb, void *mem_ctx,
789 const struct ldb_val *in, struct ldb_val *out)
791 return ldif_write_NDR(ldb, mem_ctx, in, out,
792 sizeof(struct replUpToDateVectorBlob),
793 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob,
794 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
798 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
799 const struct ldb_val *in, struct ldb_val *out)
801 *out = data_blob_string_const(data_blob_hex_string(mem_ctx, in));
808 static const struct ldb_schema_syntax samba_syntaxes[] = {
810 .name = LDB_SYNTAX_SAMBA_SID,
811 .ldif_read_fn = ldif_read_objectSid,
812 .ldif_write_fn = ldif_write_objectSid,
813 .canonicalise_fn = ldif_canonicalise_objectSid,
814 .comparison_fn = ldif_comparison_objectSid
816 .name = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR,
817 .ldif_read_fn = ldif_read_ntSecurityDescriptor,
818 .ldif_write_fn = ldif_write_ntSecurityDescriptor,
819 .canonicalise_fn = ldb_handler_copy,
820 .comparison_fn = ldb_comparison_binary
822 .name = LDB_SYNTAX_SAMBA_GUID,
823 .ldif_read_fn = ldif_read_objectGUID,
824 .ldif_write_fn = ldif_write_objectGUID,
825 .canonicalise_fn = ldif_canonicalise_objectGUID,
826 .comparison_fn = ldif_comparison_objectGUID
828 .name = LDB_SYNTAX_SAMBA_OBJECT_CATEGORY,
829 .ldif_read_fn = ldb_handler_copy,
830 .ldif_write_fn = ldb_handler_copy,
831 .canonicalise_fn = ldif_canonicalise_objectCategory,
832 .comparison_fn = ldif_comparison_objectCategory
834 .name = LDB_SYNTAX_SAMBA_PREFIX_MAP,
835 .ldif_read_fn = ldif_read_prefixMap,
836 .ldif_write_fn = ldif_write_prefixMap,
837 .canonicalise_fn = ldif_canonicalise_prefixMap,
838 .comparison_fn = ldif_comparison_prefixMap
840 .name = LDB_SYNTAX_SAMBA_INT32,
841 .ldif_read_fn = ldb_handler_copy,
842 .ldif_write_fn = ldb_handler_copy,
843 .canonicalise_fn = ldif_canonicalise_int32,
844 .comparison_fn = ldif_comparison_int32
846 .name = LDB_SYNTAX_SAMBA_REPSFROMTO,
847 .ldif_read_fn = ldb_handler_copy,
848 .ldif_write_fn = ldif_write_repsFromTo,
849 .canonicalise_fn = ldb_handler_copy,
850 .comparison_fn = ldb_comparison_binary
852 .name = LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA,
853 .ldif_read_fn = ldb_handler_copy,
854 .ldif_write_fn = ldif_write_replPropertyMetaData,
855 .canonicalise_fn = ldb_handler_copy,
856 .comparison_fn = ldb_comparison_binary
858 .name = LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR,
859 .ldif_read_fn = ldb_handler_copy,
860 .ldif_write_fn = ldif_write_replUpToDateVector,
861 .canonicalise_fn = ldb_handler_copy,
862 .comparison_fn = ldb_comparison_binary
866 static const struct ldb_dn_extended_syntax samba_dn_syntax[] = {
869 .read_fn = extended_dn_read_SID,
870 .write_clear_fn = ldif_write_objectSid,
871 .write_hex_fn = extended_dn_write_hex
874 .read_fn = extended_dn_read_GUID,
875 .write_clear_fn = ldif_write_objectGUID,
876 .write_hex_fn = extended_dn_write_hex
879 .read_fn = ldb_handler_copy,
880 .write_clear_fn = ldb_handler_copy,
881 .write_hex_fn = ldb_handler_copy
885 /* TODO: Should be dynamic at some point */
886 static const struct {
889 } samba_attributes[] = {
890 { "objectSid", LDB_SYNTAX_SAMBA_SID },
891 { "securityIdentifier", LDB_SYNTAX_SAMBA_SID },
892 { "ntSecurityDescriptor", LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR },
893 { "objectGUID", LDB_SYNTAX_SAMBA_GUID },
894 { "invocationId", LDB_SYNTAX_SAMBA_GUID },
895 { "schemaIDGUID", LDB_SYNTAX_SAMBA_GUID },
896 { "attributeSecurityGUID", LDB_SYNTAX_SAMBA_GUID },
897 { "parentGUID", LDB_SYNTAX_SAMBA_GUID },
898 { "siteGUID", LDB_SYNTAX_SAMBA_GUID },
899 { "pKTGUID", LDB_SYNTAX_SAMBA_GUID },
900 { "fRSVersionGUID", LDB_SYNTAX_SAMBA_GUID },
901 { "fRSReplicaSetGUID", LDB_SYNTAX_SAMBA_GUID },
902 { "netbootGUID", LDB_SYNTAX_SAMBA_GUID },
903 { "objectCategory", LDB_SYNTAX_SAMBA_OBJECT_CATEGORY },
904 { "prefixMap", LDB_SYNTAX_SAMBA_PREFIX_MAP },
905 { "repsFrom", LDB_SYNTAX_SAMBA_REPSFROMTO },
906 { "repsTo", LDB_SYNTAX_SAMBA_REPSFROMTO },
907 { "replPropertyMetaData", LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA },
908 { "replUpToDateVector", LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR },
911 const struct ldb_schema_syntax *ldb_samba_syntax_by_name(struct ldb_context *ldb, const char *name)
914 const struct ldb_schema_syntax *s = NULL;
916 for (j=0; j < ARRAY_SIZE(samba_syntaxes); j++) {
917 if (strcmp(name, samba_syntaxes[j].name) == 0) {
918 s = &samba_syntaxes[j];
925 const struct ldb_schema_syntax *ldb_samba_syntax_by_lDAPDisplayName(struct ldb_context *ldb, const char *name)
928 const struct ldb_schema_syntax *s = NULL;
930 for (j=0; j < ARRAY_SIZE(samba_attributes); j++) {
931 if (strcmp(samba_attributes[j].name, name) == 0) {
932 s = ldb_samba_syntax_by_name(ldb, samba_attributes[j].syntax);
941 register the samba ldif handlers
943 int ldb_register_samba_handlers(struct ldb_context *ldb)
947 for (i=0; i < ARRAY_SIZE(samba_attributes); i++) {
949 const struct ldb_schema_syntax *s = NULL;
951 s = ldb_samba_syntax_by_name(ldb, samba_attributes[i].syntax);
954 s = ldb_standard_syntax_by_name(ldb, samba_attributes[i].syntax);
961 ret = ldb_schema_attribute_add_with_syntax(ldb, samba_attributes[i].name, LDB_ATTR_FLAG_FIXED, s);
962 if (ret != LDB_SUCCESS) {
967 for (i=0; i < ARRAY_SIZE(samba_dn_syntax); i++) {
969 ret = ldb_dn_extended_add_syntax(ldb, LDB_ATTR_FLAG_FIXED, &samba_dn_syntax[i]);
970 if (ret != LDB_SUCCESS) {