lib/util Remove setup_logging_stdout()
[sfrench/samba-autobuild/.git] / librpc / tools / ndrdump.c
index 69b304dc9c078f081d6629065f2a1e677574273e..f0f4eaff4e62d9910e78c8cf3310d6487cefa470 100644 (file)
@@ -127,13 +127,14 @@ static const struct ndr_interface_table *load_iface_from_plugin(const char *plug
        return p;
 }
 
+static void printf_cb(const char *buf, void *private_data)
+{
+       printf("%s", buf);
+}
+
 static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
 {
-       if (force) {
-               dump_data(0, d, l);
-       } else {
-               dump_data_skip_zeros(0, d, l);
-       }
+       dump_data_cb(d, l, !force, printf_cb, NULL);
 }
 
  int main(int argc, const char *argv[])
@@ -157,14 +158,16 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
        const char *plugin = NULL;
        bool validate = false;
        bool dumpdata = false;
+       bool assume_ndr64 = false;
        int opt;
-       enum {OPT_CONTEXT_FILE=1000, OPT_VALIDATE, OPT_DUMP_DATA, OPT_LOAD_DSO};
+       enum {OPT_CONTEXT_FILE=1000, OPT_VALIDATE, OPT_DUMP_DATA, OPT_LOAD_DSO, OPT_NDR64};
        struct poptOption long_options[] = {
                POPT_AUTOHELP
                {"context-file", 'c', POPT_ARG_STRING, NULL, OPT_CONTEXT_FILE, "In-filename to parse first", "CTX-FILE" },
                {"validate", 0, POPT_ARG_NONE, NULL, OPT_VALIDATE, "try to validate the data", NULL },  
                {"dump-data", 0, POPT_ARG_NONE, NULL, OPT_DUMP_DATA, "dump the hex data", NULL },       
                {"load-dso", 'l', POPT_ARG_STRING, NULL, OPT_LOAD_DSO, "load from shared object file", NULL },
+               {"ndr64", 0, POPT_ARG_NONE, NULL, OPT_NDR64, "Assume NDR64 data", NULL },
                POPT_COMMON_SAMBA
                POPT_COMMON_VERSION
                { NULL }
@@ -177,9 +180,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
 
        setlinebuf(stdout);
 
-       dbf = x_stderr;
-
-       setup_logging(argv[0], true);
+       setup_logging("ndrdump", DEBUG_STDOUT);
 
        pc = poptGetContext("ndrdump", argc, argv, long_options, 0);
        
@@ -200,6 +201,9 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
                case OPT_LOAD_DSO:
                        plugin = poptGetOptArg(pc);
                        break;
+               case OPT_NDR64:
+                       assume_ndr64 = true;
+                       break;
                }
        }
 
@@ -285,8 +289,11 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
                blob.data = data;
                blob.length = size;
 
-               ndr_pull = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(cmdline_lp_ctx));
+               ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
                ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
+               if (assume_ndr64) {
+                       ndr_pull->flags |= LIBNDR_FLAG_NDR64;
+               }
 
                ndr_err = f->ndr_pull(ndr_pull, NDR_IN, st);
 
@@ -318,8 +325,11 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
        blob.data = data;
        blob.length = size;
 
-       ndr_pull = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(cmdline_lp_ctx));
+       ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
        ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
+       if (assume_ndr64) {
+               ndr_pull->flags |= LIBNDR_FLAG_NDR64;
+       }
 
        ndr_err = f->ndr_pull(ndr_pull, flags, st);
        status = ndr_map_error2ntstatus(ndr_err);
@@ -339,7 +349,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
        }
 
        ndr_print = talloc_zero(mem_ctx, struct ndr_print);
-       ndr_print->print = ndr_print_debug_helper;
+       ndr_print->print = ndr_print_printf_helper;
        ndr_print->depth = 1;
        f->ndr_print(ndr_print, function, flags, st);
 
@@ -357,7 +367,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
                uint8_t byte_a, byte_b;
                bool differ;
 
-               ndr_v_push = ndr_push_init_ctx(mem_ctx, lp_iconv_convenience(cmdline_lp_ctx));
+               ndr_v_push = ndr_push_init_ctx(mem_ctx);
                
                ndr_err = f->ndr_push(ndr_v_push, flags, st);
                status = ndr_map_error2ntstatus(ndr_err);
@@ -374,7 +384,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
                        ndrdump_data(v_blob.data, v_blob.length, dumpdata);
                }
 
-               ndr_v_pull = ndr_pull_init_blob(&v_blob, mem_ctx, lp_iconv_convenience(cmdline_lp_ctx));
+               ndr_v_pull = ndr_pull_init_blob(&v_blob, mem_ctx);
                ndr_v_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
 
                ndr_err = f->ndr_pull(ndr_v_pull, flags, v_st);