ndr: added --ndr64 flag to ndrdump
[kai/samba-autobuild/.git] / librpc / tools / ndrdump.c
index 3ecf10a167bd53edff17e0e98856a6bf8c6ac90f..fbb0f3ab2acfa4d4197ca949870acc0a6a71faa0 100644 (file)
 */
 
 #include "includes.h"
-#if (_SAMBA_BUILD_ >= 4)
-#include "lib/cmdline/popt_common.h"
 #include "system/filesys.h"
 #include "system/locale.h"
 #include "librpc/ndr/libndr.h"
 #include "librpc/ndr/ndr_table.h"
+#if (_SAMBA_BUILD_ >= 4)
+#include "lib/cmdline/popt_common.h"
 #include "param/param.h"
-#else
-#define _NORETURN_
 #endif
 
 static const struct ndr_interface_call *find_function(
@@ -51,8 +49,6 @@ static const struct ndr_interface_call *find_function(
        return &p->calls[i];
 }
 
-#if (_SAMBA_BUILD_ >= 4)
-
 _NORETURN_ static void show_pipes(void)
 {
        const struct ndr_interface_list *l;
@@ -68,8 +64,6 @@ _NORETURN_ static void show_pipes(void)
        exit(1);
 }
 
-#endif
-
 _NORETURN_ static void show_functions(const struct ndr_interface_table *p)
 {
        int i;
@@ -163,22 +157,27 @@ 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", 'l', POPT_ARG_NONE, NULL, OPT_NDR64, "Assume NDR64 data", NULL },
                POPT_COMMON_SAMBA
                POPT_COMMON_VERSION
                { NULL }
        };
 
-#if (_SAMBA_BUILD_ >= 4)
+       if (DEBUGLEVEL < 1) {
+               DEBUGLEVEL = 1;
+       }
+
        ndr_table_init();
-#else
+
        /* Initialise samba stuff */
        load_case_tables();
 
@@ -186,8 +185,7 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
 
        dbf = x_stderr;
 
-       setup_logging(argv[0],True);
-#endif
+       setup_logging_stdout();
 
        pc = poptGetContext("ndrdump", argc, argv, long_options, 0);
        
@@ -208,6 +206,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;
                }
        }
 
@@ -215,21 +216,13 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
 
        if (!pipe_name) {
                poptPrintUsage(pc, stderr, 0);
-#if (_SAMBA_BUILD_ >= 4)
                show_pipes();
-#endif
                exit(1);
        }
 
        if (plugin != NULL) {
                p = load_iface_from_plugin(plugin, pipe_name);
        } 
-#if (_SAMBA_BUILD_ <= 3)
-       else {
-               fprintf(stderr, "Only loading from DSO's supported in Samba 3\n");
-               exit(1);
-       }
-#else
        if (!p) {
                p = ndr_table_by_name(pipe_name);
        }
@@ -243,7 +236,6 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
                        p = ndr_table_by_uuid(&uuid);
                }
        }
-#endif
 
        if (!p) {
                printf("Unknown pipe or UUID '%s'\n", pipe_name);
@@ -304,6 +296,9 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
 
                ndr_pull = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(cmdline_lp_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);
 
@@ -337,6 +332,9 @@ static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
 
        ndr_pull = ndr_pull_init_blob(&blob, mem_ctx, lp_iconv_convenience(cmdline_lp_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);