2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 static const struct dcerpc_interface_table *find_pipe(const char *pipe_name)
26 for (i=0;dcerpc_pipes[i];i++) {
27 if (strcmp(dcerpc_pipes[i]->name, pipe_name) == 0) {
31 if (!dcerpc_pipes[i]) {
32 printf("pipe '%s' not in table\n", pipe_name);
35 return dcerpc_pipes[i];
38 static const struct dcerpc_interface_call *find_function(
39 const struct dcerpc_interface_table *p,
43 for (i=0;i<p->num_calls;i++) {
44 if (strcmp(p->calls[i].name, function) == 0) {
48 if (i == p->num_calls) {
49 printf("Function '%s' not found\n", function);
55 static void usage(void)
57 printf("Usage: ndrdump <pipe> <function> <inout> <filename>\n");
61 static void show_pipes(void)
65 printf("\nYou must specify a pipe\n");
66 printf("known pipes are:\n");
67 for (i=0;dcerpc_pipes[i];i++) {
68 printf("\t%s\n", dcerpc_pipes[i]->name);
73 static void show_functions(const struct dcerpc_interface_table *p)
77 printf("\nYou must specify a function\n");
78 printf("known functions on '%s' are:\n", p->name);
79 for (i=0;i<p->num_calls;i++) {
80 printf("\t0x%02x (%2d) %s\n", i, i, p->calls[i].name);
85 int main(int argc, char *argv[])
87 const struct dcerpc_interface_table *p;
88 const struct dcerpc_interface_call *f;
89 const char *pipe_name, *function, *inout, *filename;
102 setup_logging("smbtorture", DEBUG_STDOUT);
111 p = find_pipe(pipe_name);
122 if (strcmp(inout, "in") == 0 ||
123 strcmp(inout, "request") == 0) {
125 } else if (strcmp(inout, "out") == 0 ||
126 strcmp(inout, "response") == 0) {
129 printf("Bad inout value '%s'\n", inout);
133 f = find_function(p, function);
135 data = file_load(filename, &size);
144 mem_ctx = talloc_init("ndrdump");
146 ndr = ndr_pull_init_blob(&blob, mem_ctx);
148 st = talloc_zero(mem_ctx, f->struct_size);
150 printf("Unable to allocate %d bytes\n", f->struct_size);
154 if (flags == NDR_OUT) {
155 ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
158 status = f->ndr_pull(ndr, flags, st);
160 printf("pull returned %s\n", nt_errstr(status));
162 if (ndr->offset != ndr->data_size) {
163 printf("WARNING! %d unread bytes\n", ndr->data_size - ndr->offset);
166 pr.mem_ctx = mem_ctx;
167 pr.print = ndr_print_debug_helper;
169 f->ndr_print(&pr, function, flags, st);
171 if (!NT_STATUS_IS_OK(status) ||
172 ndr->offset != ndr->data_size) {
173 printf("dump FAILED\n");