s3: lib: Add new clistr_smb2_extract_snapshot_token() function.
[Samba.git] / librpc / tools / ndrdump.c
blob0d39ed3714bf28a65aa046a2dab8efe48f4c5415
1 /*
2 Unix SMB/CIFS implementation.
3 SMB torture tester
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) Jelmer Vernooij 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "system/filesys.h"
23 #include "system/locale.h"
24 #include "librpc/ndr/libndr.h"
25 #include "librpc/ndr/ndr_table.h"
26 #include "librpc/gen_ndr/ndr_dcerpc.h"
27 #include "lib/cmdline/cmdline.h"
28 #include "param/param.h"
29 #include "lib/util/base64.h"
31 static const struct ndr_interface_call *find_function(
32 const struct ndr_interface_table *p,
33 const char *function)
35 unsigned int i;
36 if (isdigit(function[0])) {
37 char *eptr = NULL;
38 i = strtoul(function, &eptr, 0);
39 if (i >= p->num_calls
40 || eptr == NULL
41 || eptr[0] != '\0') {
42 printf("Function number '%s' not found\n",
43 function);
44 exit(1);
46 return &p->calls[i];
48 for (i=0;i<p->num_calls;i++) {
49 if (strcmp(p->calls[i].name, function) == 0) {
50 break;
53 if (i == p->num_calls) {
54 printf("Function '%s' not found\n", function);
55 exit(1);
57 return &p->calls[i];
61 * Find a public structure on the pipe and return it as if it were
62 * a function (as the rest of ndrdump is based around functions)
64 static const struct ndr_interface_call *find_struct(
65 const struct ndr_interface_table *p,
66 const char *struct_name,
67 struct ndr_interface_call *out_buffer)
69 unsigned int i;
70 const struct ndr_interface_public_struct *public_struct = NULL;
71 if (isdigit(struct_name[0])) {
72 char *eptr = NULL;
73 i = strtoul(struct_name, &eptr, 0);
74 if (i >= p->num_public_structs
75 || eptr == NULL
76 || eptr[0] != '\0') {
77 printf("Public structure number '%s' not found\n",
78 struct_name);
79 exit(1);
81 public_struct = &p->public_structs[i];
82 } else {
83 for (i=0;i<p->num_public_structs;i++) {
84 if (strcmp(p->public_structs[i].name, struct_name) == 0) {
85 break;
88 if (i == p->num_public_structs) {
89 printf("Public structure '%s' not found\n", struct_name);
90 exit(1);
92 public_struct = &p->public_structs[i];
94 *out_buffer = (struct ndr_interface_call) {
95 .name = public_struct->name,
96 .struct_size = public_struct->struct_size,
97 .ndr_pull = public_struct->ndr_pull,
98 .ndr_push = public_struct->ndr_push,
99 .ndr_print = public_struct->ndr_print
101 return out_buffer;
104 _NORETURN_ static void show_pipes(void)
106 const struct ndr_interface_list *l;
107 printf("\nYou must specify a pipe\n");
108 printf("known pipes are:\n");
109 for (l=ndr_table_list();l;l=l->next) {
110 if(l->table->helpstring) {
111 printf("\t%s - %s\n", l->table->name, l->table->helpstring);
112 } else {
113 printf("\t%s\n", l->table->name);
116 exit(1);
119 _NORETURN_ static void show_functions(const struct ndr_interface_table *p)
121 int i;
122 printf("\nYou must specify a function\n");
123 printf("known functions on '%s' are:\n", p->name);
124 for (i=0;i<p->num_calls;i++) {
125 printf("\t0x%02x (%2d) %s\n", i, i, p->calls[i].name);
127 printf("known public structures on '%s' are:\n", p->name);
128 for (i=0;i<p->num_public_structs;i++) {
129 printf("\t%s\n", p->public_structs[i].name);
131 exit(1);
134 static char *stdin_load(TALLOC_CTX *mem_ctx, size_t *size)
136 int num_read, total_len = 0;
137 char buf[255];
138 char *result = NULL;
140 while((num_read = read(STDIN_FILENO, buf, 255)) > 0) {
142 if (result) {
143 result = talloc_realloc(
144 mem_ctx, result, char, total_len + num_read);
145 } else {
146 result = talloc_array(mem_ctx, char, num_read);
149 memcpy(result + total_len, buf, num_read);
151 total_len += num_read;
154 if (size)
155 *size = total_len;
157 return result;
160 static const struct ndr_interface_table *load_iface_from_plugin(const char *plugin, const char *pipe_name)
162 const struct ndr_interface_table *p;
163 void *handle;
164 char *symbol;
166 handle = dlopen(plugin, RTLD_NOW);
167 if (handle == NULL) {
168 printf("%s: Unable to open: %s\n", plugin, dlerror());
169 return NULL;
172 symbol = talloc_asprintf(NULL, "ndr_table_%s", pipe_name);
173 p = (const struct ndr_interface_table *)dlsym(handle, symbol);
175 if (!p) {
176 printf("%s: Unable to find DCE/RPC interface table for '%s': %s\n", plugin, pipe_name, dlerror());
177 talloc_free(symbol);
178 dlclose(handle);
179 return NULL;
182 talloc_free(symbol);
184 return p;
187 static void ndrdump_data(uint8_t *d, uint32_t l, bool force)
189 dump_data_file(d, l, !force, stdout);
192 static void ndrdump_data_diff(const uint8_t *d1, size_t l1,
193 const uint8_t *d2, size_t l2,
194 bool force)
196 dump_data_file_diff(stdout, !force, d1, l1, d2, l2);
199 static NTSTATUS ndrdump_pull_and_print_pipes(const char *function,
200 struct ndr_pull *ndr_pull,
201 struct ndr_print *ndr_print,
202 const struct ndr_interface_call_pipes *pipes)
204 enum ndr_err_code ndr_err;
205 uint32_t i;
207 for (i=0; i < pipes->num_pipes; i++) {
208 uint64_t idx = 0;
209 while (true) {
210 void *saved_mem_ctx;
211 uint32_t *count;
212 void *c;
213 char *n;
215 c = talloc_zero_size(ndr_pull, pipes->pipes[i].chunk_struct_size);
216 talloc_set_name(c, "struct %s", pipes->pipes[i].name);
218 * Note: the first struct member is always
219 * 'uint32_t count;'
221 count = (uint32_t *)c;
223 n = talloc_asprintf(c, "%s: %s[%llu]",
224 function, pipes->pipes[i].name,
225 (unsigned long long)idx);
227 saved_mem_ctx = ndr_pull->current_mem_ctx;
228 ndr_pull->current_mem_ctx = c;
229 ndr_err = pipes->pipes[i].ndr_pull(ndr_pull, NDR_SCALARS, c);
230 ndr_pull->current_mem_ctx = saved_mem_ctx;
232 printf("pull returned %s\n",
233 ndr_map_error2string(ndr_err));
234 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
235 talloc_free(c);
236 return ndr_map_error2ntstatus(ndr_err);
238 pipes->pipes[i].ndr_print(ndr_print, n, c);
239 if (*count == 0) {
240 talloc_free(c);
241 break;
243 talloc_free(c);
244 idx++;
248 return NT_STATUS_OK;
251 static void ndr_print_dummy(struct ndr_print *ndr, const char *format, ...)
253 /* This is here so that you can turn ndr printing off for the purposes
254 of benchmarking ndr parsing. */
257 int main(int argc, const char *argv[])
259 const struct ndr_interface_table *p = NULL;
260 const struct ndr_interface_call *f;
261 struct ndr_interface_call f_buffer;
262 const char *pipe_name = NULL;
263 const char *filename = NULL;
265 * The format type:
266 * in: a request
267 * out: a response
268 * struct: a public structure
270 const char *type = NULL;
272 * Format is either the name of the decoding function or the
273 * name of a public structure
275 const char *format = NULL;
276 const char *cmdline_input = NULL;
277 const uint8_t *data;
278 size_t size;
279 DATA_BLOB blob;
280 struct ndr_pull *ndr_pull;
281 struct ndr_print *ndr_print;
282 TALLOC_CTX *mem_ctx;
283 int flags = 0;
284 poptContext pc;
285 NTSTATUS status;
286 enum ndr_err_code ndr_err;
287 void *st;
288 void *v_st;
289 const char *ctx_filename = NULL;
290 const char *plugin = NULL;
291 bool validate = false;
292 bool dumpdata = false;
293 bool assume_ndr64 = false;
294 bool quiet = false;
295 bool hex_input = false;
296 bool base64_input = false;
297 bool print_after_parse_failure = false;
298 int opt;
299 enum {
300 OPT_CONTEXT_FILE=1000,
301 OPT_VALIDATE,
302 OPT_DUMP_DATA,
303 OPT_LOAD_DSO,
304 OPT_NDR64,
305 OPT_QUIET,
306 OPT_BASE64_INPUT,
307 OPT_HEX_INPUT,
308 OPT_CMDLINE_INPUT,
309 OPT_PRINT_AFTER_PARSE_FAILURE,
311 struct poptOption long_options[] = {
312 POPT_AUTOHELP
313 {"context-file", 'c', POPT_ARG_STRING, NULL, OPT_CONTEXT_FILE, "In-filename to parse first", "CTX-FILE" },
314 {"validate", 0, POPT_ARG_NONE, NULL, OPT_VALIDATE, "try to validate the data", NULL },
315 {"dump-data", 0, POPT_ARG_NONE, NULL, OPT_DUMP_DATA, "dump the hex data", NULL },
316 {"load-dso", 0, POPT_ARG_STRING, NULL, OPT_LOAD_DSO, "load from shared object file", NULL },
317 {"ndr64", 0, POPT_ARG_NONE, NULL, OPT_NDR64, "Assume NDR64 data", NULL },
318 {"quiet", 0, POPT_ARG_NONE, NULL, OPT_QUIET, "Don't actually dump anything", NULL },
319 {"base64-input", 0, POPT_ARG_NONE, NULL, OPT_BASE64_INPUT, "Read the input file in as a base64 string", NULL },
320 {"hex-input", 0, POPT_ARG_NONE, NULL, OPT_HEX_INPUT, "Read the input file in as a hex dump", NULL },
321 {"input", 0, POPT_ARG_STRING, NULL, OPT_CMDLINE_INPUT, "Provide the input on the command line (use with --base64-input)", "INPUT" },
322 {"print-after-parse-failure", 0, POPT_ARG_NONE, NULL, OPT_PRINT_AFTER_PARSE_FAILURE,
323 "Try to print structures that fail to parse (used to develop parsers, segfaults are likely).", NULL },
324 POPT_COMMON_SAMBA
325 POPT_COMMON_VERSION
326 POPT_TABLEEND
328 uint32_t highest_ofs;
329 struct dcerpc_sec_verification_trailer *sec_vt = NULL;
330 bool ok;
332 ndr_table_init();
334 /* Initialise samba stuff */
335 smb_init_locale();
337 setlinebuf(stdout);
339 mem_ctx = talloc_init("ndrdump.c/main");
340 if (mem_ctx == NULL) {
341 exit(ENOMEM);
344 ok = samba_cmdline_init(mem_ctx,
345 SAMBA_CMDLINE_CONFIG_CLIENT,
346 false /* require_smbconf */);
347 if (!ok) {
348 DBG_ERR("Failed to init cmdline parser!\n");
349 TALLOC_FREE(mem_ctx);
350 exit(1);
353 pc = samba_popt_get_context(getprogname(),
354 argc,
355 argv,
356 long_options,
358 if (pc == NULL) {
359 DBG_ERR("Failed to setup popt context!\n");
360 TALLOC_FREE(mem_ctx);
361 exit(1);
364 poptSetOtherOptionHelp(
365 pc, "<pipe|uuid> <format> <in|out|struct> [<filename>]");
367 while ((opt = poptGetNextOpt(pc)) != -1) {
368 switch (opt) {
369 case OPT_CONTEXT_FILE:
370 ctx_filename = poptGetOptArg(pc);
371 break;
372 case OPT_VALIDATE:
373 validate = true;
374 break;
375 case OPT_DUMP_DATA:
376 dumpdata = true;
377 break;
378 case OPT_LOAD_DSO:
379 plugin = poptGetOptArg(pc);
380 break;
381 case OPT_NDR64:
382 assume_ndr64 = true;
383 break;
384 case OPT_QUIET:
385 quiet = true;
386 break;
387 case OPT_BASE64_INPUT:
388 base64_input = true;
389 break;
390 case OPT_HEX_INPUT:
391 hex_input = true;
392 break;
393 case OPT_CMDLINE_INPUT:
394 cmdline_input = poptGetOptArg(pc);
395 break;
396 case OPT_PRINT_AFTER_PARSE_FAILURE:
397 print_after_parse_failure = true;
398 break;
402 pipe_name = poptGetArg(pc);
404 if (!pipe_name) {
405 poptPrintUsage(pc, stderr, 0);
406 show_pipes();
407 exit(1);
410 if (plugin != NULL) {
411 p = load_iface_from_plugin(plugin, pipe_name);
413 if (!p) {
414 p = ndr_table_by_name(pipe_name);
417 if (!p) {
418 struct GUID uuid;
420 status = GUID_from_string(pipe_name, &uuid);
422 if (NT_STATUS_IS_OK(status)) {
423 p = ndr_table_by_uuid(&uuid);
427 if (!p) {
428 printf("Unknown pipe or UUID '%s'\n", pipe_name);
429 exit(1);
432 format = poptGetArg(pc);
433 type = poptGetArg(pc);
434 filename = poptGetArg(pc);
436 if (!format || !type) {
437 poptPrintUsage(pc, stderr, 0);
438 show_functions(p);
439 exit(1);
442 if (strcmp(type, "struct") == 0) {
443 flags = NDR_SCALARS|NDR_BUFFERS; /* neither NDR_IN nor NDR_OUT */
444 f = find_struct(p, format, &f_buffer);
445 } else {
446 f = find_function(p, format);
447 if (strcmp(type, "in") == 0 ||
448 strcmp(type, "request") == 0) {
449 flags |= NDR_IN;
450 } else if (strcmp(type, "out") == 0 ||
451 strcmp(type, "response") == 0) {
452 flags |= NDR_OUT;
453 } else {
454 printf("Bad type value '%s'\n", type);
455 exit(1);
459 st = talloc_zero_size(mem_ctx, f->struct_size);
460 if (!st) {
461 printf("Unable to allocate %d bytes for %s structure\n",
462 (int)f->struct_size,
463 f->name);
464 TALLOC_FREE(mem_ctx);
465 exit(1);
468 v_st = talloc_zero_size(mem_ctx, f->struct_size);
469 if (!v_st) {
470 printf("Unable to allocate %d bytes for %s validation "
471 "structure\n",
472 (int)f->struct_size,
473 f->name);
474 TALLOC_FREE(mem_ctx);
475 exit(1);
478 if (ctx_filename) {
479 if (flags & NDR_IN) {
480 printf("Context file can only be used for \"out\" packages\n");
481 TALLOC_FREE(mem_ctx);
482 exit(1);
485 data = (uint8_t *)file_load(ctx_filename, &size, 0, mem_ctx);
486 if (!data) {
487 perror(ctx_filename);
488 TALLOC_FREE(mem_ctx);
489 exit(1);
492 blob = data_blob_const(data, size);
494 ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
495 if (ndr_pull == NULL) {
496 perror("ndr_pull_init_blob");
497 TALLOC_FREE(mem_ctx);
498 exit(1);
500 ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
501 if (assume_ndr64) {
502 ndr_pull->flags |= LIBNDR_FLAG_NDR64;
505 ndr_err = f->ndr_pull(ndr_pull, NDR_IN, st);
507 if (ndr_pull->offset > ndr_pull->relative_highest_offset) {
508 highest_ofs = ndr_pull->offset;
509 } else {
510 highest_ofs = ndr_pull->relative_highest_offset;
513 if (highest_ofs != ndr_pull->data_size) {
514 printf("WARNING! %d unread bytes while parsing context file\n", ndr_pull->data_size - highest_ofs);
517 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
518 printf("pull for context file returned %s\n",
519 ndr_map_error2string(ndr_err));
520 TALLOC_FREE(mem_ctx);
521 exit(2);
523 memcpy(v_st, st, f->struct_size);
526 if (filename && cmdline_input) {
527 printf("cannot combine --input with a filename\n");
528 TALLOC_FREE(mem_ctx);
529 exit(1);
530 } else if (cmdline_input) {
531 data = (const uint8_t *)cmdline_input;
532 size = strlen(cmdline_input);
533 } else if (filename) {
534 data = (uint8_t *)file_load(filename, &size, 0, mem_ctx);
535 } else {
536 data = (uint8_t *)stdin_load(mem_ctx, &size);
539 if (!data) {
540 if (filename)
541 perror(filename);
542 else
543 perror("stdin");
544 exit(1);
547 if (hex_input && base64_input) {
548 printf("cannot combine --hex-input with --base64-input\n");
549 TALLOC_FREE(mem_ctx);
550 exit(1);
552 } else if (hex_input) {
553 blob = hexdump_to_data_blob(mem_ctx, (const char *)data, size);
554 } else if (base64_input) {
555 /* Use talloc_strndup() to ensure null termination */
556 blob = base64_decode_data_blob_talloc(
557 mem_ctx,
558 talloc_strndup(mem_ctx, (const char *)data, size));
559 } else {
560 blob = data_blob_const(data, size);
563 if (data != NULL && blob.data == NULL) {
564 printf("failed to decode input data\n");
565 TALLOC_FREE(mem_ctx);
566 exit(1);
569 ndr_pull = ndr_pull_init_blob(&blob, mem_ctx);
570 if (ndr_pull == NULL) {
571 perror("ndr_pull_init_blob");
572 TALLOC_FREE(mem_ctx);
573 exit(1);
575 ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
576 if (assume_ndr64) {
577 ndr_pull->flags |= LIBNDR_FLAG_NDR64;
580 ndr_print = talloc_zero(mem_ctx, struct ndr_print);
581 if (quiet) {
582 ndr_print->print = ndr_print_dummy;
583 } else {
584 ndr_print->print = ndr_print_printf_helper;
586 ndr_print->depth = 1;
588 ndr_err = ndr_pop_dcerpc_sec_verification_trailer(ndr_pull, mem_ctx, &sec_vt);
589 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
590 printf("ndr_pop_dcerpc_sec_verification_trailer returned %s\n",
591 ndr_map_error2string(ndr_err));
594 if (sec_vt != NULL && sec_vt->count.count > 0) {
595 printf("SEC_VT: consumed %d bytes\n",
596 (int)(blob.length - ndr_pull->data_size));
597 if (dumpdata) {
598 ndrdump_data(blob.data + ndr_pull->data_size,
599 blob.length - ndr_pull->data_size,
600 dumpdata);
602 ndr_print_dcerpc_sec_verification_trailer(ndr_print, "SEC_VT", sec_vt);
604 TALLOC_FREE(sec_vt);
606 if (flags & NDR_OUT) {
607 status = ndrdump_pull_and_print_pipes(format,
608 ndr_pull,
609 ndr_print,
610 &f->out_pipes);
611 if (!NT_STATUS_IS_OK(status)) {
612 printf("pull and dump of OUT pipes FAILED: %s\n",
613 nt_errstr(status));
614 TALLOC_FREE(mem_ctx);
615 exit(2);
619 ndr_err = f->ndr_pull(ndr_pull, flags, st);
620 printf("pull returned %s\n",
621 ndr_map_error2string(ndr_err));
623 if (ndr_pull->offset > ndr_pull->relative_highest_offset) {
624 highest_ofs = ndr_pull->offset;
625 } else {
626 highest_ofs = ndr_pull->relative_highest_offset;
629 if (dumpdata) {
630 printf("%d bytes consumed\n", highest_ofs);
631 ndrdump_data(blob.data, blob.length, dumpdata);
634 if (!print_after_parse_failure && !NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
635 TALLOC_FREE(mem_ctx);
636 exit(2);
639 if (highest_ofs != ndr_pull->data_size) {
640 printf("WARNING! %d unread bytes\n", ndr_pull->data_size - highest_ofs);
641 ndrdump_data(ndr_pull->data+highest_ofs,
642 ndr_pull->data_size - highest_ofs,
643 dumpdata);
646 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
647 printf("WARNING: pull of %s was incomplete, "
648 "therefore the parse below may SEGFAULT\n",
649 f->name);
652 f->ndr_print(ndr_print, f->name, flags, st);
654 if (flags & NDR_IN) {
655 status = ndrdump_pull_and_print_pipes(format,
656 ndr_pull,
657 ndr_print,
658 &f->in_pipes);
659 if (!NT_STATUS_IS_OK(status)) {
660 printf("pull and dump of IN pipes FAILED: %s\n",
661 nt_errstr(status));
662 exit(1);
666 /* Do not proceed to validate if we got an error */
667 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
668 printf("dump of failed-to-parse %s complete\n",
669 f->name);
670 TALLOC_FREE(mem_ctx);
671 exit(2);
674 if (validate) {
675 DATA_BLOB v_blob;
676 struct ndr_push *ndr_v_push;
677 struct ndr_pull *ndr_v_pull;
678 struct ndr_print *ndr_v_print;
679 uint32_t highest_v_ofs;
680 uint32_t i;
681 uint8_t byte_a, byte_b;
682 bool differ;
684 ndr_v_push = ndr_push_init_ctx(mem_ctx);
685 if (ndr_v_push == NULL) {
686 printf("No memory\n");
687 exit(1);
690 if (assume_ndr64) {
691 ndr_v_push->flags |= LIBNDR_FLAG_NDR64;
694 ndr_err = f->ndr_push(ndr_v_push, flags, st);
695 printf("push returned %s\n",
696 ndr_map_error2string(ndr_err));
697 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
698 printf("validate push FAILED\n");
699 TALLOC_FREE(mem_ctx);
700 exit(1);
703 v_blob = ndr_push_blob(ndr_v_push);
705 if (dumpdata) {
706 printf("%ld bytes generated (validate)\n", (long)v_blob.length);
707 ndrdump_data(v_blob.data, v_blob.length, dumpdata);
710 ndr_v_pull = ndr_pull_init_blob(&v_blob, mem_ctx);
711 if (ndr_v_pull == NULL) {
712 perror("ndr_pull_init_blob");
713 TALLOC_FREE(mem_ctx);
714 exit(1);
716 ndr_v_pull->flags |= LIBNDR_FLAG_REF_ALLOC;
718 ndr_err = f->ndr_pull(ndr_v_pull, flags, v_st);
719 printf("pull returned %s\n",
720 ndr_map_error2string(ndr_err));
721 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
722 printf("validate pull FAILED\n");
723 TALLOC_FREE(mem_ctx);
724 exit(1);
727 if (ndr_v_pull->offset > ndr_v_pull->relative_highest_offset) {
728 highest_v_ofs = ndr_v_pull->offset;
729 } else {
730 highest_v_ofs = ndr_v_pull->relative_highest_offset;
733 if (highest_v_ofs != ndr_v_pull->data_size) {
734 printf("WARNING! %d unread bytes in validation\n",
735 ndr_v_pull->data_size - highest_v_ofs);
736 ndrdump_data(ndr_v_pull->data + highest_v_ofs,
737 ndr_v_pull->data_size - highest_v_ofs,
738 dumpdata);
741 ndr_v_print = talloc_zero(mem_ctx, struct ndr_print);
742 ndr_v_print->print = ndr_print_debug_helper;
743 ndr_v_print->depth = 1;
744 f->ndr_print(ndr_v_print,
745 format,
746 flags, v_st);
748 if (blob.length != v_blob.length) {
749 printf("WARNING! orig bytes:%llu validated pushed bytes:%llu\n",
750 (unsigned long long)blob.length, (unsigned long long)v_blob.length);
753 if (highest_ofs != highest_v_ofs) {
754 printf("WARNING! orig pulled bytes:%llu validated pulled bytes:%llu\n",
755 (unsigned long long)highest_ofs, (unsigned long long)highest_v_ofs);
758 differ = false;
759 byte_a = 0x00;
760 byte_b = 0x00;
761 for (i=0; i < blob.length; i++) {
762 byte_a = blob.data[i];
764 if (i == v_blob.length) {
765 byte_b = 0x00;
766 differ = true;
767 break;
770 byte_b = v_blob.data[i];
772 if (byte_a != byte_b) {
773 differ = true;
774 break;
777 if (differ) {
778 printf("WARNING! orig and validated differ at byte 0x%02X (%u)\n", i, i);
779 printf("WARNING! orig byte[0x%02X] = 0x%02X validated byte[0x%02X] = 0x%02X\n",
780 i, byte_a, i, byte_b);
781 ndrdump_data_diff(blob.data, blob.length,
782 v_blob.data, v_blob.length,
783 dumpdata);
787 printf("dump OK\n");
788 TALLOC_FREE(mem_ctx);
790 poptFreeContext(pc);
792 return 0;