mirror of
https://github.com/samba-team/samba.git
synced 2025-08-29 13:49:30 +03:00
s4/ldb: added --show-binary command line option
This add --show-binary to ldbsearch. When this flag is set, binary blobs will be shown as-is, instead of base64 encoded. This is useful for some XML encoded attributes, and will also be used as part of some NDR print formatting for attributes like repsTo.
This commit is contained in:
@ -185,11 +185,15 @@ char *ldb_base64_encode(void *mem_ctx, const char *buf, int len)
|
||||
/*
|
||||
see if a buffer should be base64 encoded
|
||||
*/
|
||||
int ldb_should_b64_encode(const struct ldb_val *val)
|
||||
int ldb_should_b64_encode(struct ldb_context *ldb, const struct ldb_val *val)
|
||||
{
|
||||
unsigned int i;
|
||||
uint8_t *p = val->data;
|
||||
|
||||
if (ldb->flags & LDB_FLG_SHOW_BINARY) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (val->length == 0) {
|
||||
return 0;
|
||||
}
|
||||
@ -333,7 +337,7 @@ int ldb_ldif_write(struct ldb_context *ldb,
|
||||
if (ret != LDB_SUCCESS) {
|
||||
v = msg->elements[i].values[j];
|
||||
}
|
||||
if (ret != LDB_SUCCESS || ldb_should_b64_encode(&v)) {
|
||||
if (ret != LDB_SUCCESS || ldb_should_b64_encode(ldb, &v)) {
|
||||
ret = fprintf_fn(private_data, "%s:: ",
|
||||
msg->elements[i].name);
|
||||
CHECK_RET;
|
||||
|
@ -240,6 +240,12 @@ struct ldb_utf8_fns {
|
||||
*/
|
||||
#define LDB_FLG_NOMMAP 8
|
||||
|
||||
/**
|
||||
Flag to tell ldif handlers not to force encoding of binary
|
||||
structures in base64
|
||||
*/
|
||||
#define LDB_FLG_SHOW_BINARY 16
|
||||
|
||||
/*
|
||||
structures for ldb_parse_tree handling code
|
||||
*/
|
||||
|
@ -102,7 +102,7 @@ int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct l
|
||||
int check_critical_controls(struct ldb_control **controls);
|
||||
|
||||
/* The following definitions come from lib/ldb/common/ldb_ldif.c */
|
||||
int ldb_should_b64_encode(const struct ldb_val *val);
|
||||
int ldb_should_b64_encode(struct ldb_context *ldb, const struct ldb_val *val);
|
||||
|
||||
/* The following definitions come from lib/ldb/common/ldb_match.c */
|
||||
int ldb_match_msg(struct ldb_context *ldb,
|
||||
|
@ -455,7 +455,7 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context *ldb,
|
||||
talloc_free(attr_folded);
|
||||
return NULL;
|
||||
}
|
||||
if (ldb_should_b64_encode(&v)) {
|
||||
if (ldb_should_b64_encode(ldb, &v)) {
|
||||
char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length);
|
||||
if (!vstr) return NULL;
|
||||
ret = ldb_dn_new_fmt(ldb, ldb, "%s:%s::%s", LTDB_INDEX, attr_folded, vstr);
|
||||
|
@ -56,6 +56,7 @@ static struct poptOption popt_options[] = {
|
||||
{ "output", 'O', POPT_ARG_STRING, &options.output, 0, "Output File", "Output" },
|
||||
{ NULL, 'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" },
|
||||
{ "controls", 0, POPT_ARG_STRING, NULL, 'c', "controls", NULL },
|
||||
{ "show-binary", 0, POPT_ARG_NONE, &options.show_binary, 0, "display binary LDIF", NULL },
|
||||
#if (_SAMBA_BUILD_ >= 4)
|
||||
POPT_COMMON_SAMBA
|
||||
POPT_COMMON_CREDENTIALS
|
||||
@ -215,6 +216,10 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
|
||||
flags |= LDB_FLG_NOSYNC;
|
||||
}
|
||||
|
||||
if (options.show_binary) {
|
||||
flags |= LDB_FLG_SHOW_BINARY;
|
||||
}
|
||||
|
||||
#if (_SAMBA_BUILD_ >= 4)
|
||||
/* Must be after we have processed command line options */
|
||||
gensec_init(cmdline_lp_ctx);
|
||||
|
@ -44,6 +44,7 @@ struct ldb_cmdline {
|
||||
const char *input;
|
||||
const char *output;
|
||||
char **controls;
|
||||
int show_binary;
|
||||
};
|
||||
|
||||
struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const char **argv,
|
||||
|
Reference in New Issue
Block a user