s4/ldb: added --show-binary command line option
authorAndrew Tridgell <tridge@samba.org>
Tue, 8 Sep 2009 10:57:31 +0000 (20:57 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 8 Sep 2009 11:56:31 +0000 (21:56 +1000)
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.

source4/lib/ldb/common/ldb_ldif.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/include/ldb_module.h
source4/lib/ldb/ldb_tdb/ldb_index.c
source4/lib/ldb/tools/cmdline.c
source4/lib/ldb/tools/cmdline.h

index 83f08b609b8c4772dd003fe0b030ca2dc347a723..b73fee184316e19d78045356c7b5e400782a27db 100644 (file)
@@ -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;
index f38dc8f227b4eb1ac235c5fff57050d6ad5612c7..b75d63b8482558821e04bec136e554124cf385d9 100644 (file)
@@ -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
 */
index 1d6329ca2fd660085f13e96111ac6cbe9039e2ee..199c0bb40de37e5b76d61bb115239a398eba99a5 100644 (file)
@@ -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,
index 7db22de09783bf851a2c5e66a32c6737b2c908a2..85fbfa0458fce8093bd7ec29bbb742520d38ca43 100644 (file)
@@ -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);
index b6c1de3a4f2ac0307398c085b6a8ae62d5df85a3..8541106060c3de0af61ab719fc3d624346e9240d 100644 (file)
@@ -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); 
index 4decf4588f8566d39957f02c47aba8a88748bcb3..9f728fba0bd77e1015f740dd5447c9a748f3288d 100644 (file)
@@ -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,