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 return ldb_handler_copy(ldb, mem_ctx, in, out);
59 out->data = (uint8_t *)ndr_print_struct_string(mem_ctx, print_fn, "NDR", p);
61 if (out->data == NULL) {
62 return ldb_handler_copy(ldb, mem_ctx, in, out);
64 out->length = strlen((char *)out->data);
69 convert a ldif formatted objectSid to a NDR formatted blob
71 static int ldif_read_objectSid(struct ldb_context *ldb, void *mem_ctx,
72 const struct ldb_val *in, struct ldb_val *out)
74 enum ndr_err_code ndr_err;
76 sid = dom_sid_parse_length(mem_ctx, in);
80 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, sid,
81 (ndr_push_flags_fn_t)ndr_push_dom_sid);
83 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
90 convert a NDR formatted blob to a ldif formatted objectSid
92 static int ldif_write_objectSid(struct ldb_context *ldb, void *mem_ctx,
93 const struct ldb_val *in, struct ldb_val *out)
96 enum ndr_err_code ndr_err;
98 sid = talloc(mem_ctx, struct dom_sid);
102 ndr_err = ndr_pull_struct_blob_all(in, sid, NULL, sid,
103 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
104 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
108 *out = data_blob_string_const(dom_sid_string(mem_ctx, sid));
110 if (out->data == NULL) {
116 static bool ldif_comparision_objectSid_isString(const struct ldb_val *v)
122 if (strncmp("S-", (const char *)v->data, 2) != 0) return false;
128 compare two objectSids
130 static int ldif_comparison_objectSid(struct ldb_context *ldb, void *mem_ctx,
131 const struct ldb_val *v1, const struct ldb_val *v2)
133 if (ldif_comparision_objectSid_isString(v1) && ldif_comparision_objectSid_isString(v2)) {
134 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
135 } else if (ldif_comparision_objectSid_isString(v1)
136 && !ldif_comparision_objectSid_isString(v2)) {
139 if (ldif_read_objectSid(ldb, mem_ctx, v1, &v) != 0) {
140 /* Perhaps not a string after all */
141 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
143 ret = ldb_comparison_binary(ldb, mem_ctx, &v, v2);
146 } else if (!ldif_comparision_objectSid_isString(v1)
147 && ldif_comparision_objectSid_isString(v2)) {
150 if (ldif_read_objectSid(ldb, mem_ctx, v2, &v) != 0) {
151 /* Perhaps not a string after all */
152 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
154 ret = ldb_comparison_binary(ldb, mem_ctx, v1, &v);
158 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
162 canonicalise a objectSid
164 static int ldif_canonicalise_objectSid(struct ldb_context *ldb, void *mem_ctx,
165 const struct ldb_val *in, struct ldb_val *out)
167 if (ldif_comparision_objectSid_isString(in)) {
168 if (ldif_read_objectSid(ldb, mem_ctx, in, out) != 0) {
169 /* Perhaps not a string after all */
170 return ldb_handler_copy(ldb, mem_ctx, in, out);
174 return ldb_handler_copy(ldb, mem_ctx, in, out);
177 static int extended_dn_read_SID(struct ldb_context *ldb, void *mem_ctx,
178 const struct ldb_val *in, struct ldb_val *out)
181 enum ndr_err_code ndr_err;
182 if (ldif_comparision_objectSid_isString(in)) {
183 if (ldif_read_objectSid(ldb, mem_ctx, in, out) == 0) {
188 /* Perhaps not a string after all */
189 *out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
195 (*out).length = strhex_to_str((char *)out->data, out->length,
196 (const char *)in->data, in->length);
198 /* Check it looks like a SID */
199 ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &sid,
200 (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
201 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
208 convert a ldif formatted objectGUID to a NDR formatted blob
210 static int ldif_read_objectGUID(struct ldb_context *ldb, void *mem_ctx,
211 const struct ldb_val *in, struct ldb_val *out)
215 enum ndr_err_code ndr_err;
217 status = GUID_from_data_blob(in, &guid);
218 if (!NT_STATUS_IS_OK(status)) {
222 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, &guid,
223 (ndr_push_flags_fn_t)ndr_push_GUID);
224 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
231 convert a NDR formatted blob to a ldif formatted objectGUID
233 static int ldif_write_objectGUID(struct ldb_context *ldb, void *mem_ctx,
234 const struct ldb_val *in, struct ldb_val *out)
237 enum ndr_err_code ndr_err;
238 ndr_err = ndr_pull_struct_blob_all(in, mem_ctx, NULL, &guid,
239 (ndr_pull_flags_fn_t)ndr_pull_GUID);
240 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
243 out->data = (uint8_t *)GUID_string(mem_ctx, &guid);
244 if (out->data == NULL) {
247 out->length = strlen((const char *)out->data);
251 static bool ldif_comparision_objectGUID_isString(const struct ldb_val *v)
253 if (v->length != 36 && v->length != 38) return false;
255 /* Might be a GUID string, can't be a binary GUID (fixed 16 bytes) */
259 static int extended_dn_read_GUID(struct ldb_context *ldb, void *mem_ctx,
260 const struct ldb_val *in, struct ldb_val *out)
263 enum ndr_err_code ndr_err;
264 if (in->length == 36 && ldif_read_objectGUID(ldb, mem_ctx, in, out) == 0) {
268 /* Try as 'hex' form */
269 if (in->length != 32) {
273 *out = data_blob_talloc(mem_ctx, NULL, in->length/2+1);
279 (*out).length = strhex_to_str((char *)out->data, out->length,
280 (const char *)in->data, in->length);
282 /* Check it looks like a GUID */
283 ndr_err = ndr_pull_struct_blob_all(out, mem_ctx, NULL, &guid,
284 (ndr_pull_flags_fn_t)ndr_pull_GUID);
285 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
292 compare two objectGUIDs
294 static int ldif_comparison_objectGUID(struct ldb_context *ldb, void *mem_ctx,
295 const struct ldb_val *v1, const struct ldb_val *v2)
297 if (ldif_comparision_objectGUID_isString(v1) && ldif_comparision_objectGUID_isString(v2)) {
298 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
299 } else if (ldif_comparision_objectGUID_isString(v1)
300 && !ldif_comparision_objectGUID_isString(v2)) {
303 if (ldif_read_objectGUID(ldb, mem_ctx, v1, &v) != 0) {
304 /* Perhaps it wasn't a valid string after all */
305 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
307 ret = ldb_comparison_binary(ldb, mem_ctx, &v, v2);
310 } else if (!ldif_comparision_objectGUID_isString(v1)
311 && ldif_comparision_objectGUID_isString(v2)) {
314 if (ldif_read_objectGUID(ldb, mem_ctx, v2, &v) != 0) {
315 /* Perhaps it wasn't a valid string after all */
316 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
318 ret = ldb_comparison_binary(ldb, mem_ctx, v1, &v);
322 return ldb_comparison_binary(ldb, mem_ctx, v1, v2);
326 canonicalise a objectGUID
328 static int ldif_canonicalise_objectGUID(struct ldb_context *ldb, void *mem_ctx,
329 const struct ldb_val *in, struct ldb_val *out)
331 if (ldif_comparision_objectGUID_isString(in)) {
332 if (ldif_read_objectGUID(ldb, mem_ctx, in, out) != 0) {
333 /* Perhaps it wasn't a valid string after all */
334 return ldb_handler_copy(ldb, mem_ctx, in, out);
338 return ldb_handler_copy(ldb, mem_ctx, in, out);
343 convert a ldif (SDDL) formatted ntSecurityDescriptor to a NDR formatted blob
345 static int ldif_read_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx,
346 const struct ldb_val *in, struct ldb_val *out)
348 struct security_descriptor *sd;
349 enum ndr_err_code ndr_err;
351 sd = talloc(mem_ctx, struct security_descriptor);
356 ndr_err = ndr_pull_struct_blob(in, sd, NULL, sd,
357 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
358 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
359 /* If this does not parse, then it is probably SDDL, and we should try it that way */
361 const struct dom_sid *sid = samdb_domain_sid(ldb);
363 sd = sddl_decode(mem_ctx, (const char *)in->data, sid);
369 ndr_err = ndr_push_struct_blob(out, mem_ctx, NULL, sd,
370 (ndr_push_flags_fn_t)ndr_push_security_descriptor);
372 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
380 convert a NDR formatted blob to a ldif formatted ntSecurityDescriptor (SDDL format)
382 static int ldif_write_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx,
383 const struct ldb_val *in, struct ldb_val *out)
385 struct security_descriptor *sd;
386 enum ndr_err_code ndr_err;
388 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
389 return ldif_write_NDR(ldb, mem_ctx, in, out,
390 sizeof(struct security_descriptor),
391 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor,
392 (ndr_print_fn_t)ndr_print_security_descriptor);
396 sd = talloc(mem_ctx, struct security_descriptor);
400 /* We can't use ndr_pull_struct_blob_all because this contains relative pointers */
401 ndr_err = ndr_pull_struct_blob(in, sd, NULL, sd,
402 (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
403 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
407 out->data = (uint8_t *)sddl_encode(mem_ctx, sd, NULL);
409 if (out->data == NULL) {
412 out->length = strlen((const char *)out->data);
417 canonicalise an objectCategory. We use the short form as the cannoical form:
418 cn=Person,cn=Schema,cn=Configuration,<basedn> becomes 'person'
421 static int ldif_canonicalise_objectCategory(struct ldb_context *ldb, void *mem_ctx,
422 const struct ldb_val *in, struct ldb_val *out)
424 struct ldb_dn *dn1 = NULL;
425 const struct dsdb_schema *schema = dsdb_get_schema(ldb);
426 const struct dsdb_class *sclass;
427 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
429 return LDB_ERR_OPERATIONS_ERROR;
433 *out = data_blob_talloc(mem_ctx, in->data, in->length);
434 if (in->data && !out->data) {
435 return LDB_ERR_OPERATIONS_ERROR;
439 dn1 = ldb_dn_from_ldb_val(tmp_ctx, ldb, in);
440 if ( ! ldb_dn_validate(dn1)) {
441 const char *lDAPDisplayName = talloc_strndup(tmp_ctx, (char *)in->data, in->length);
442 sclass = dsdb_class_by_lDAPDisplayName(schema, lDAPDisplayName);
444 struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb,
445 sclass->defaultObjectCategory);
446 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn));
447 talloc_free(tmp_ctx);
450 return LDB_ERR_OPERATIONS_ERROR;
454 *out = data_blob_talloc(mem_ctx, in->data, in->length);
455 talloc_free(tmp_ctx);
457 if (in->data && !out->data) {
458 return LDB_ERR_OPERATIONS_ERROR;
463 *out = data_blob_string_const(ldb_dn_alloc_casefold(mem_ctx, dn1));
464 talloc_free(tmp_ctx);
467 return LDB_ERR_OPERATIONS_ERROR;
472 static int ldif_comparison_objectCategory(struct ldb_context *ldb, void *mem_ctx,
473 const struct ldb_val *v1,
474 const struct ldb_val *v2)
478 struct ldb_val v1_canon, v2_canon;
479 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
481 /* I could try and bail if tmp_ctx was NULL, but what return
484 * It seems easier to continue on the NULL context
486 ret1 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v1, &v1_canon);
487 ret2 = ldif_canonicalise_objectCategory(ldb, tmp_ctx, v2, &v2_canon);
489 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
490 ret = data_blob_cmp(&v1_canon, &v2_canon);
492 ret = data_blob_cmp(v1, v2);
494 talloc_free(tmp_ctx);
499 convert a ldif formatted prefixMap to a NDR formatted blob
501 static int ldif_read_prefixMap(struct ldb_context *ldb, void *mem_ctx,
502 const struct ldb_val *in, struct ldb_val *out)
504 struct prefixMapBlob *blob;
505 enum ndr_err_code ndr_err;
506 char *string, *line, *p, *oid;
508 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
510 if (tmp_ctx == NULL) {
514 blob = talloc_zero(tmp_ctx, struct prefixMapBlob);
520 blob->version = PREFIX_MAP_VERSION_DSDB;
522 string = talloc_strndup(mem_ctx, (const char *)in->data, in->length);
523 if (string == NULL) {
529 while (line && line[0]) {
534 p=strchr(line, '\n');
539 /* allow a traling seperator */
544 blob->ctr.dsdb.mappings = talloc_realloc(blob,
545 blob->ctr.dsdb.mappings,
546 struct drsuapi_DsReplicaOIDMapping,
547 blob->ctr.dsdb.num_mappings+1);
548 if (!blob->ctr.dsdb.mappings) {
549 talloc_free(tmp_ctx);
553 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].id_prefix = strtoul(line, &oid, 10);
556 talloc_free(tmp_ctx);
560 /* we know there must be at least ":" */
563 blob->ctr.dsdb.mappings[blob->ctr.dsdb.num_mappings].oid.oid
564 = talloc_strdup(blob->ctr.dsdb.mappings, oid);
566 blob->ctr.dsdb.num_mappings++;
568 /* Now look past the terminator we added above */
576 ndr_err = ndr_push_struct_blob(out, mem_ctx,
577 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
579 (ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
580 talloc_free(tmp_ctx);
581 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
588 convert a NDR formatted blob to a ldif formatted prefixMap
590 static int ldif_write_prefixMap(struct ldb_context *ldb, void *mem_ctx,
591 const struct ldb_val *in, struct ldb_val *out)
593 struct prefixMapBlob *blob;
594 enum ndr_err_code ndr_err;
598 if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
599 return ldif_write_NDR(ldb, mem_ctx, in, out,
600 sizeof(struct prefixMapBlob),
601 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob,
602 (ndr_print_fn_t)ndr_print_prefixMapBlob);
606 blob = talloc(mem_ctx, struct prefixMapBlob);
610 ndr_err = ndr_pull_struct_blob_all(in, blob,
611 lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
613 (ndr_pull_flags_fn_t)ndr_pull_prefixMapBlob);
614 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
618 if (blob->version != PREFIX_MAP_VERSION_DSDB) {
621 string = talloc_strdup(mem_ctx, "");
622 if (string == NULL) {
626 for (i=0; i < blob->ctr.dsdb.num_mappings; i++) {
628 string = talloc_asprintf_append(string, ";");
630 string = talloc_asprintf_append(string, "%u:%s",
631 blob->ctr.dsdb.mappings[i].id_prefix,
632 blob->ctr.dsdb.mappings[i].oid.oid);
633 if (string == NULL) {
639 *out = data_blob_string_const(string);
643 static bool ldif_comparision_prefixMap_isString(const struct ldb_val *v)
649 if (IVAL(v->data, 0) == PREFIX_MAP_VERSION_DSDB) {
657 canonicalise a prefixMap
659 static int ldif_canonicalise_prefixMap(struct ldb_context *ldb, void *mem_ctx,
660 const struct ldb_val *in, struct ldb_val *out)
662 if (ldif_comparision_prefixMap_isString(in)) {
663 return ldif_read_prefixMap(ldb, mem_ctx, in, out);
665 return ldb_handler_copy(ldb, mem_ctx, in, out);
668 static int ldif_comparison_prefixMap(struct ldb_context *ldb, void *mem_ctx,
669 const struct ldb_val *v1,
670 const struct ldb_val *v2)
674 struct ldb_val v1_canon, v2_canon;
675 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
677 /* I could try and bail if tmp_ctx was NULL, but what return
680 * It seems easier to continue on the NULL context
682 ret1 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v1, &v1_canon);
683 ret2 = ldif_canonicalise_prefixMap(ldb, tmp_ctx, v2, &v2_canon);
685 if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
686 ret = data_blob_cmp(&v1_canon, &v2_canon);
688 ret = data_blob_cmp(v1, v2);
690 talloc_free(tmp_ctx);
694 /* Canonicalisation of two 32-bit integers */
695 static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx,
696 const struct ldb_val *in, struct ldb_val *out)
699 /* We've to use "strtoll" here to have the intended overflows.
700 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
701 int32_t i = (int32_t) strtoll((char *)in->data, &end, 0);
705 out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%d", i);
706 if (out->data == NULL) {
709 out->length = strlen((char *)out->data);
713 /* Comparison of two 32-bit integers */
714 static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx,
715 const struct ldb_val *v1, const struct ldb_val *v2)
717 /* We've to use "strtoll" here to have the intended overflows.
718 * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
719 return (int32_t) strtoll((char *)v1->data, NULL, 0)
720 - (int32_t) strtoll((char *)v2->data, NULL, 0);
724 convert a NDR formatted blob to a ldif formatted repsFromTo
726 static int ldif_write_repsFromTo(struct ldb_context *ldb, void *mem_ctx,
727 const struct ldb_val *in, struct ldb_val *out)
729 return ldif_write_NDR(ldb, mem_ctx, in, out,
730 sizeof(struct repsFromToBlob),
731 (ndr_pull_flags_fn_t)ndr_pull_repsFromToBlob,
732 (ndr_print_fn_t)ndr_print_repsFromToBlob);
736 convert a NDR formatted blob to a ldif formatted replPropertyMetaData
738 static int ldif_write_replPropertyMetaData(struct ldb_context *ldb, void *mem_ctx,
739 const struct ldb_val *in, struct ldb_val *out)
741 return ldif_write_NDR(ldb, mem_ctx, in, out,
742 sizeof(struct replPropertyMetaDataBlob),
743 (ndr_pull_flags_fn_t)ndr_pull_replPropertyMetaDataBlob,
744 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
748 convert a NDR formatted blob to a ldif formatted replUpToDateVector
750 static int ldif_write_replUpToDateVector(struct ldb_context *ldb, void *mem_ctx,
751 const struct ldb_val *in, struct ldb_val *out)
753 return ldif_write_NDR(ldb, mem_ctx, in, out,
754 sizeof(struct replUpToDateVectorBlob),
755 (ndr_pull_flags_fn_t)ndr_pull_replUpToDateVectorBlob,
756 (ndr_print_fn_t)ndr_print_replPropertyMetaDataBlob);
760 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
761 const struct ldb_val *in, struct ldb_val *out)
763 *out = data_blob_string_const(data_blob_hex_string(mem_ctx, in));
770 static const struct ldb_schema_syntax samba_syntaxes[] = {
772 .name = LDB_SYNTAX_SAMBA_SID,
773 .ldif_read_fn = ldif_read_objectSid,
774 .ldif_write_fn = ldif_write_objectSid,
775 .canonicalise_fn = ldif_canonicalise_objectSid,
776 .comparison_fn = ldif_comparison_objectSid
778 .name = LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR,
779 .ldif_read_fn = ldif_read_ntSecurityDescriptor,
780 .ldif_write_fn = ldif_write_ntSecurityDescriptor,
781 .canonicalise_fn = ldb_handler_copy,
782 .comparison_fn = ldb_comparison_binary
784 .name = LDB_SYNTAX_SAMBA_GUID,
785 .ldif_read_fn = ldif_read_objectGUID,
786 .ldif_write_fn = ldif_write_objectGUID,
787 .canonicalise_fn = ldif_canonicalise_objectGUID,
788 .comparison_fn = ldif_comparison_objectGUID
790 .name = LDB_SYNTAX_SAMBA_OBJECT_CATEGORY,
791 .ldif_read_fn = ldb_handler_copy,
792 .ldif_write_fn = ldb_handler_copy,
793 .canonicalise_fn = ldif_canonicalise_objectCategory,
794 .comparison_fn = ldif_comparison_objectCategory
796 .name = LDB_SYNTAX_SAMBA_PREFIX_MAP,
797 .ldif_read_fn = ldif_read_prefixMap,
798 .ldif_write_fn = ldif_write_prefixMap,
799 .canonicalise_fn = ldif_canonicalise_prefixMap,
800 .comparison_fn = ldif_comparison_prefixMap
802 .name = LDB_SYNTAX_SAMBA_INT32,
803 .ldif_read_fn = ldb_handler_copy,
804 .ldif_write_fn = ldb_handler_copy,
805 .canonicalise_fn = ldif_canonicalise_int32,
806 .comparison_fn = ldif_comparison_int32
808 .name = LDB_SYNTAX_SAMBA_REPSFROMTO,
809 .ldif_read_fn = ldb_handler_copy,
810 .ldif_write_fn = ldif_write_repsFromTo,
811 .canonicalise_fn = ldb_handler_copy,
812 .comparison_fn = ldb_comparison_binary
814 .name = LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA,
815 .ldif_read_fn = ldb_handler_copy,
816 .ldif_write_fn = ldif_write_replPropertyMetaData,
817 .canonicalise_fn = ldb_handler_copy,
818 .comparison_fn = ldb_comparison_binary
820 .name = LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR,
821 .ldif_read_fn = ldb_handler_copy,
822 .ldif_write_fn = ldif_write_replUpToDateVector,
823 .canonicalise_fn = ldb_handler_copy,
824 .comparison_fn = ldb_comparison_binary
828 static const struct ldb_dn_extended_syntax samba_dn_syntax[] = {
831 .read_fn = extended_dn_read_SID,
832 .write_clear_fn = ldif_write_objectSid,
833 .write_hex_fn = extended_dn_write_hex
836 .read_fn = extended_dn_read_GUID,
837 .write_clear_fn = ldif_write_objectGUID,
838 .write_hex_fn = extended_dn_write_hex
841 .read_fn = ldb_handler_copy,
842 .write_clear_fn = ldb_handler_copy,
843 .write_hex_fn = ldb_handler_copy
847 /* TODO: Should be dynamic at some point */
848 static const struct {
851 } samba_attributes[] = {
852 { "objectSid", LDB_SYNTAX_SAMBA_SID },
853 { "securityIdentifier", LDB_SYNTAX_SAMBA_SID },
854 { "ntSecurityDescriptor", LDB_SYNTAX_SAMBA_SECURITY_DESCRIPTOR },
855 { "objectGUID", LDB_SYNTAX_SAMBA_GUID },
856 { "invocationId", LDB_SYNTAX_SAMBA_GUID },
857 { "schemaIDGUID", LDB_SYNTAX_SAMBA_GUID },
858 { "attributeSecurityGUID", LDB_SYNTAX_SAMBA_GUID },
859 { "parentGUID", LDB_SYNTAX_SAMBA_GUID },
860 { "siteGUID", LDB_SYNTAX_SAMBA_GUID },
861 { "pKTGUID", LDB_SYNTAX_SAMBA_GUID },
862 { "fRSVersionGUID", LDB_SYNTAX_SAMBA_GUID },
863 { "fRSReplicaSetGUID", LDB_SYNTAX_SAMBA_GUID },
864 { "netbootGUID", LDB_SYNTAX_SAMBA_GUID },
865 { "objectCategory", LDB_SYNTAX_SAMBA_OBJECT_CATEGORY },
866 { "prefixMap", LDB_SYNTAX_SAMBA_PREFIX_MAP },
867 { "repsFrom", LDB_SYNTAX_SAMBA_REPSFROMTO },
868 { "repsTo", LDB_SYNTAX_SAMBA_REPSFROMTO },
869 { "replPropertyMetaData", LDB_SYNTAX_SAMBA_REPLPROPERTYMETADATA },
870 { "replUpToDateVector", LDB_SYNTAX_SAMBA_REPLUPTODATEVECTOR },
873 const struct ldb_schema_syntax *ldb_samba_syntax_by_name(struct ldb_context *ldb, const char *name)
876 const struct ldb_schema_syntax *s = NULL;
878 for (j=0; j < ARRAY_SIZE(samba_syntaxes); j++) {
879 if (strcmp(name, samba_syntaxes[j].name) == 0) {
880 s = &samba_syntaxes[j];
887 const struct ldb_schema_syntax *ldb_samba_syntax_by_lDAPDisplayName(struct ldb_context *ldb, const char *name)
890 const struct ldb_schema_syntax *s = NULL;
892 for (j=0; j < ARRAY_SIZE(samba_attributes); j++) {
893 if (strcmp(samba_attributes[j].name, name) == 0) {
894 s = ldb_samba_syntax_by_name(ldb, samba_attributes[j].syntax);
903 register the samba ldif handlers
905 int ldb_register_samba_handlers(struct ldb_context *ldb)
909 for (i=0; i < ARRAY_SIZE(samba_attributes); i++) {
911 const struct ldb_schema_syntax *s = NULL;
913 s = ldb_samba_syntax_by_name(ldb, samba_attributes[i].syntax);
916 s = ldb_standard_syntax_by_name(ldb, samba_attributes[i].syntax);
923 ret = ldb_schema_attribute_add_with_syntax(ldb, samba_attributes[i].name, LDB_ATTR_FLAG_FIXED, s);
924 if (ret != LDB_SUCCESS) {
929 for (i=0; i < ARRAY_SIZE(samba_dn_syntax); i++) {
931 ret = ldb_dn_extended_add_syntax(ldb, LDB_ATTR_FLAG_FIXED, &samba_dn_syntax[i]);
932 if (ret != LDB_SUCCESS) {