From a8e8a3161164ec469d65d7489d2f71fdc288a131 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 8 Sep 2009 21:55:56 +1000 Subject: s4/ldb: allow printing ntSecurityDescriptor in full print security descriptors in NDR format if --show-binary is given. This is easier to read than sddl format. --- source4/lib/ldb-samba/ldif_handlers.c | 72 +++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'source4/lib') diff --git a/source4/lib/ldb-samba/ldif_handlers.c b/source4/lib/ldb-samba/ldif_handlers.c index 60b6ccd101..6927576ca6 100644 --- a/source4/lib/ldb-samba/ldif_handlers.c +++ b/source4/lib/ldb-samba/ldif_handlers.c @@ -34,6 +34,37 @@ #include "libcli/security/security.h" #include "param/param.h" +/* + use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob +*/ +static int ldif_write_NDR(struct ldb_context *ldb, void *mem_ctx, + const struct ldb_val *in, struct ldb_val *out, + size_t struct_size, + ndr_pull_flags_fn_t pull_fn, + ndr_print_fn_t print_fn) +{ + uint8_t *p; + enum ndr_err_code err; + if (!(ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY)) { + return ldb_handler_copy(ldb, mem_ctx, in, out); + } + p = talloc_size(mem_ctx, struct_size); + err = ndr_pull_struct_blob(in, mem_ctx, + lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), + p, pull_fn); + if (err != NDR_ERR_SUCCESS) { + talloc_free(p); + return ldb_handler_copy(ldb, mem_ctx, in, out); + } + out->data = (uint8_t *)ndr_print_struct_string(mem_ctx, print_fn, "NDR", p); + talloc_free(p); + if (out->data == NULL) { + return ldb_handler_copy(ldb, mem_ctx, in, out); + } + out->length = strlen((char *)out->data); + return 0; +} + /* convert a ldif formatted objectSid to a NDR formatted blob */ @@ -315,7 +346,6 @@ static int ldif_read_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ctx const struct ldb_val *in, struct ldb_val *out) { struct security_descriptor *sd; - enum ndr_err_code ndr_err; sd = talloc(mem_ctx, struct security_descriptor); @@ -355,6 +385,14 @@ static int ldif_write_ntSecurityDescriptor(struct ldb_context *ldb, void *mem_ct struct security_descriptor *sd; enum ndr_err_code ndr_err; + if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) { + return ldif_write_NDR(ldb, mem_ctx, in, out, + sizeof(struct security_descriptor), + (ndr_pull_flags_fn_t)ndr_pull_security_descriptor, + (ndr_print_fn_t)ndr_print_security_descriptor); + + } + sd = talloc(mem_ctx, struct security_descriptor); if (sd == NULL) { return -1; @@ -674,38 +712,6 @@ static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx, - (int32_t) strtoll((char *)v2->data, NULL, 0); } -/* - use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob -*/ -static int ldif_write_NDR(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out, - size_t struct_size, - ndr_pull_flags_fn_t pull_fn, - ndr_print_fn_t print_fn) -{ - uint8_t *p; - enum ndr_err_code err; - if (!(ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY)) { - return ldb_handler_copy(ldb, mem_ctx, in, out); - } - p = talloc_size(mem_ctx, struct_size); - err = ndr_pull_struct_blob(in, mem_ctx, - lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")), - p, pull_fn); - if (err != NDR_ERR_SUCCESS) { - talloc_free(p); - return ldb_handler_copy(ldb, mem_ctx, in, out); - } - out->data = (uint8_t *)ndr_print_struct_string(mem_ctx, print_fn, "NDR", p); - talloc_free(p); - if (out->data == NULL) { - return ldb_handler_copy(ldb, mem_ctx, in, out); - } - out->length = strlen((char *)out->data); - return 0; -} - - /* convert a NDR formatted blob to a ldif formatted repsFromTo */ -- cgit