summaryrefslogtreecommitdiffstats
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2009-09-08 20:57:31 +1000
committerAndrew Tridgell <tridge@samba.org>2009-09-08 21:56:31 +1000
commit29ba7765d90eda0b3d0f45f7a970272f0ef2ab2f (patch)
tree9ece67758a9ee31c50e1ec70fa7f4de6f5fac3a5 /source4/lib
parent5b2b5abf4f630c28dc5f018ecced3894ae66f491 (diff)
downloadsamba-29ba7765d90eda0b3d0f45f7a970272f0ef2ab2f.tar.gz
samba-29ba7765d90eda0b3d0f45f7a970272f0ef2ab2f.tar.xz
samba-29ba7765d90eda0b3d0f45f7a970272f0ef2ab2f.zip
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.
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/common/ldb_ldif.c8
-rw-r--r--source4/lib/ldb/include/ldb.h6
-rw-r--r--source4/lib/ldb/include/ldb_module.h2
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c2
-rw-r--r--source4/lib/ldb/tools/cmdline.c5
-rw-r--r--source4/lib/ldb/tools/cmdline.h1
6 files changed, 20 insertions, 4 deletions
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index 83f08b609b8..b73fee18431 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -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;
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index f38dc8f227b..b75d63b8482 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -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
*/
diff --git a/source4/lib/ldb/include/ldb_module.h b/source4/lib/ldb/include/ldb_module.h
index 1d6329ca2fd..199c0bb40de 100644
--- a/source4/lib/ldb/include/ldb_module.h
+++ b/source4/lib/ldb/include/ldb_module.h
@@ -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,
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 7db22de0978..85fbfa0458f 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -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);
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index b6c1de3a4f2..8541106060c 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -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);
diff --git a/source4/lib/ldb/tools/cmdline.h b/source4/lib/ldb/tools/cmdline.h
index 4decf4588f8..9f728fba0bd 100644
--- a/source4/lib/ldb/tools/cmdline.h
+++ b/source4/lib/ldb/tools/cmdline.h
@@ -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,