#include "system/locale.h"
#include "librpc/ndr/libndr.h"
#include "librpc/ndr/ndr_table.h"
+#include "librpc/gen_ndr/ndr_dcerpc.h"
#include "lib/cmdline/popt_common.h"
#include "param/param.h"
if (!p) {
printf("%s: Unable to find DCE/RPC interface table for '%s': %s\n", plugin, pipe_name, dlerror());
talloc_free(symbol);
+ dlclose(handle);
return NULL;
}
for (i=0; i < pipes->num_pipes; i++) {
uint64_t idx = 0;
while (true) {
+ void *saved_mem_ctx;
uint32_t *count;
void *c;
char *n;
function, pipes->pipes[i].name,
(unsigned long long)idx);
+ saved_mem_ctx = ndr_pull->current_mem_ctx;
+ ndr_pull->current_mem_ctx = c;
ndr_err = pipes->pipes[i].ndr_pull(ndr_pull, NDR_SCALARS, c);
+ ndr_pull->current_mem_ctx = saved_mem_ctx;
status = ndr_map_error2ntstatus(ndr_err);
printf("pull returned %s\n", nt_errstr(status));
if (!NT_STATUS_IS_OK(status)) {
+ talloc_free(c);
return status;
}
pipes->pipes[i].ndr_print(ndr_print, n, c);
-
+ talloc_free(c);
if (*count == 0) {
break;
}
return NT_STATUS_OK;
}
+static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
+{
+ /* This is here so that you can turn ndr printing off for the purposes
+ of benchmarking ndr parsing. */
+}
+
int main(int argc, const char *argv[])
{
const struct ndr_interface_table *p = NULL;
bool validate = false;
bool dumpdata = false;
bool assume_ndr64 = false;
+ bool quiet = false;
+ bool hex_input = false;
int opt;
- enum {OPT_CONTEXT_FILE=1000, OPT_VALIDATE, OPT_DUMP_DATA, OPT_LOAD_DSO, OPT_NDR64};
+ enum {OPT_CONTEXT_FILE=1000, OPT_VALIDATE, OPT_DUMP_DATA, OPT_LOAD_DSO, OPT_NDR64, OPT_QUIET, OPT_HEX_INPUT};
struct poptOption long_options[] = {
POPT_AUTOHELP
{"context-file", 'c', POPT_ARG_STRING, NULL, OPT_CONTEXT_FILE, "In-filename to parse first", "CTX-FILE" },
{"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 },
+ {"quiet", 0, POPT_ARG_NONE, NULL, OPT_QUIET, "Don't actually dump anything", NULL },
+ {"hex-input", 0, POPT_ARG_NONE, NULL, OPT_HEX_INPUT, "Read the input file in as a hex dump", NULL },
POPT_COMMON_SAMBA
POPT_COMMON_VERSION
{ NULL }
const struct ndr_interface_call_pipes *in_pipes = NULL;
const struct ndr_interface_call_pipes *out_pipes = NULL;
uint32_t highest_ofs;
-
+ struct dcerpc_sec_verification_trailer *sec_vt = NULL;
+
ndr_table_init();
/* Initialise samba stuff */
- load_case_tables();
+ smb_init_locale();
setlinebuf(stdout);
case OPT_NDR64:
assume_ndr64 = true;
break;
+ case OPT_QUIET:
+ quiet = true;
+ break;
+ case OPT_HEX_INPUT:
+ hex_input = true;
+ break;
}
}
exit(1);
}
memcpy(v_st, st, f->struct_size);
- }
+ }
if (filename)
data = (uint8_t *)file_load(filename, &size, 0, mem_ctx);
perror("stdin");
exit(1);
}
-
- blob.data = data;
- blob.length = size;
+
+ if (hex_input) {
+ blob = hexdump_to_data_blob(mem_ctx, (char *)data, size);
+ } else {
+ blob.data = data;
+ blob.length = size;
+ }
ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
if (ndr_pull == NULL) {
}
ndr_print = talloc_zero(mem_ctx, struct ndr_print);
- ndr_print->print = ndr_print_printf_helper;
+ if (quiet) {
+ ndr_print->print = ndr_print_dummy;
+ } else {
+ ndr_print->print = ndr_print_printf_helper;
+ }
ndr_print->depth = 1;
+ ndr_err = ndr_pop_dcerpc_sec_verification_trailer(ndr_pull, mem_ctx, &sec_vt);
+ status = ndr_map_error2ntstatus(ndr_err);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("ndr_pop_dcerpc_sec_verification_trailer returned %s\n",
+ nt_errstr(status));
+ }
+
+ if (sec_vt != NULL && sec_vt->count.count > 0) {
+ printf("SEC_VT: consumed %d bytes\n",
+ (int)(blob.length - ndr_pull->data_size));
+ if (dumpdata) {
+ ndrdump_data(blob.data + ndr_pull->data_size,
+ blob.length - ndr_pull->data_size,
+ dumpdata);
+ }
+ ndr_print_dcerpc_sec_verification_trailer(ndr_print, "SEC_VT", sec_vt);
+ }
+ TALLOC_FREE(sec_vt);
+
if (out_pipes) {
status = ndrdump_pull_and_print_pipes(function, ndr_pull, ndr_print, out_pipes);
if (!NT_STATUS_IS_OK(status)) {
}
if (dumpdata) {
- printf("%d bytes consumed\n", ndr_pull->offset);
+ printf("%d bytes consumed\n", highest_ofs);
ndrdump_data(blob.data, blob.length, dumpdata);
}
struct ndr_push *ndr_v_push;
struct ndr_pull *ndr_v_pull;
struct ndr_print *ndr_v_print;
+ uint32_t highest_v_ofs;
uint32_t i;
uint8_t byte_a, byte_b;
bool differ;
ndr_v_push = ndr_push_init_ctx(mem_ctx);
-
+ if (ndr_v_push == NULL) {
+ printf("No memory\n");
+ exit(1);
+ }
+
+ if (assume_ndr64) {
+ ndr_v_push->flags |= LIBNDR_FLAG_NDR64;
+ }
+
ndr_err = f->ndr_push(ndr_v_push, flags, st);
status = ndr_map_error2ntstatus(ndr_err);
printf("push returned %s\n", nt_errstr(status));
exit(1);
}
+ if (ndr_v_pull->offset > ndr_v_pull->relative_highest_offset) {
+ highest_v_ofs = ndr_v_pull->offset;
+ } else {
+ highest_v_ofs = ndr_v_pull->relative_highest_offset;
+ }
- if (ndr_v_pull->offset != ndr_v_pull->data_size) {
- printf("WARNING! %d unread bytes in validation\n", ndr_v_pull->data_size - ndr_v_pull->offset);
- ndrdump_data(ndr_v_pull->data+ndr_v_pull->offset,
- ndr_v_pull->data_size - ndr_v_pull->offset,
+ if (highest_v_ofs != ndr_v_pull->data_size) {
+ printf("WARNING! %d unread bytes in validation\n",
+ ndr_v_pull->data_size - highest_v_ofs);
+ ndrdump_data(ndr_v_pull->data + highest_v_ofs,
+ ndr_v_pull->data_size - highest_v_ofs,
dumpdata);
}
(unsigned long long)blob.length, (unsigned long long)v_blob.length);
}
- if (ndr_pull->offset != ndr_v_pull->offset) {
+ if (highest_ofs != highest_v_ofs) {
printf("WARNING! orig pulled bytes:%llu validated pulled bytes:%llu\n",
- (unsigned long long)ndr_pull->offset, (unsigned long long)ndr_v_pull->offset);
+ (unsigned long long)highest_ofs, (unsigned long long)highest_v_ofs);
}
differ = false;
}
printf("dump OK\n");
-
talloc_free(mem_ctx);
poptFreeContext(pc);