summaryrefslogtreecommitdiff
path: root/source4/utils
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2005-03-13 03:16:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:11:03 -0500
commitd93d5f967f3f3e8c0061bcfc213be0a9278b0372 (patch)
treea92ce9d3eaf09330354ce508ac7b73b71ec9e6d4 /source4/utils
parentee461300a5a888d632f4046796ea119023d1303c (diff)
downloadsamba-d93d5f967f3f3e8c0061bcfc213be0a9278b0372.tar.gz
samba-d93d5f967f3f3e8c0061bcfc213be0a9278b0372.tar.bz2
samba-d93d5f967f3f3e8c0061bcfc213be0a9278b0372.zip
r5782: Use standard input for reading packet data if filename not specified.
(This used to be commit c3c6dafc3120ed5018a27a882cbc09e9d05fac33)
Diffstat (limited to 'source4/utils')
-rw-r--r--source4/utils/ndrdump.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/source4/utils/ndrdump.c b/source4/utils/ndrdump.c
index bad74c061e..48b1a3ef61 100644
--- a/source4/utils/ndrdump.c
+++ b/source4/utils/ndrdump.c
@@ -21,6 +21,7 @@
#include "includes.h"
#include "lib/cmdline/popt_common.h"
#include "system/iconv.h"
+#include "system/filesys.h"
static const struct dcerpc_interface_call *find_function(
const struct dcerpc_interface_table *p,
@@ -70,6 +71,32 @@ static void show_functions(const struct dcerpc_interface_table *p)
exit(1);
}
+static char *stdin_load(TALLOC_CTX *mem_ctx, size_t *size)
+{
+ int num_read, total_len = 0;
+ char buf[255];
+ char *result = NULL;
+
+ while((num_read = read(STDIN_FILENO, buf, 255)) > 0) {
+
+ if (result) {
+ result = (char *) talloc_realloc(
+ mem_ctx, result, char *, total_len + num_read);
+ } else {
+ result = talloc_size(mem_ctx, num_read);
+ }
+
+ memcpy(result + total_len, buf, num_read);
+
+ total_len += num_read;
+ }
+
+ if (size)
+ *size = total_len;
+
+ return result;
+}
+
int main(int argc, const char *argv[])
{
const struct dcerpc_interface_table *p;
@@ -100,7 +127,7 @@ static void show_functions(const struct dcerpc_interface_table *p)
pc = poptGetContext("ndrdump", argc, argv, long_options, 0);
- poptSetOtherOptionHelp(pc, "<pipe> <function> <inout> <filename>");
+ poptSetOtherOptionHelp(pc, "<pipe> <function> <inout> [<filename>]");
while ((opt = poptGetNextOpt(pc)) != -1) {
}
@@ -124,7 +151,7 @@ static void show_functions(const struct dcerpc_interface_table *p)
inout = poptGetArg(pc);
filename = poptGetArg(pc);
- if (!function || !inout || !filename) {
+ if (!function || !inout) {
poptPrintUsage(pc, stderr, 0);
show_functions(p);
exit(1);
@@ -180,9 +207,16 @@ static void show_functions(const struct dcerpc_interface_table *p)
}
}
- data = (uint8_t *)file_load(filename, &size);
+ if (filename)
+ data = (uint8_t *)file_load(filename, &size);
+ else
+ data = (uint8_t *)stdin_load(mem_ctx, &size);
+
if (!data) {
- perror(filename);
+ if (filename)
+ perror(filename);
+ else
+ perror("stdin");
exit(1);
}