From f4e485117a0dea627addfb8518e6517c7104fd9e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Nov 2003 13:19:00 +0000 Subject: * fixed byte order in epmapper parsing * allow rpc transport to be specified on command line in smbtorture (This used to be commit 8a82050fd6f45bcdb31c2c365eaed5fc12599e4f) --- source4/lib/util.c | 2 +- source4/librpc/rpc/dcerpc_tcp.c | 5 +++ source4/torture/rpc/epmapper.c | 14 +++--- source4/torture/torture.c | 94 ++++++++++++++++++++++++++++------------- 4 files changed, 78 insertions(+), 37 deletions(-) (limited to 'source4') diff --git a/source4/lib/util.c b/source4/lib/util.c index 64e3dfe88c..c9c38ddd33 100644 --- a/source4/lib/util.c +++ b/source4/lib/util.c @@ -467,7 +467,7 @@ uint32 interpret_addr(const char *str) if (strcmp(str,"255.255.255.255") == 0) return(0xFFFFFFFF); - /* if it's in the form of an IP address then get the lib to interpret it */ + /* if it's in the form of an IP address then get the lib to interpret it */ if (is_ipaddress(str)) { res = inet_addr(str); } else { diff --git a/source4/librpc/rpc/dcerpc_tcp.c b/source4/librpc/rpc/dcerpc_tcp.c index 785ef46423..ec94baf583 100644 --- a/source4/librpc/rpc/dcerpc_tcp.c +++ b/source4/librpc/rpc/dcerpc_tcp.c @@ -155,6 +155,10 @@ NTSTATUS dcerpc_pipe_open_tcp(struct dcerpc_pipe **p, int fd; struct in_addr addr; + if (port == 0) { + port = 135; + } + addr.s_addr = interpret_addr(server); if (addr.s_addr == 0) { return NT_STATUS_BAD_NETWORK_NAME; @@ -195,6 +199,7 @@ NTSTATUS dcerpc_pipe_open_tcp(struct dcerpc_pipe **p, if (!NT_STATUS_IS_OK(status)) { dcerpc_pipe_close(*p); + return status; } return NT_STATUS_OK; diff --git a/source4/torture/rpc/epmapper.c b/source4/torture/rpc/epmapper.c index a056f2254e..cef3355b8a 100644 --- a/source4/torture/rpc/epmapper.c +++ b/source4/torture/rpc/epmapper.c @@ -50,7 +50,7 @@ static void display_tower(TALLOC_CTX *mem_ctx, struct epm_towers *twr) printf(" IP:"); if (rhs->rhs_data.length == 4) { struct in_addr in; - in.s_addr = RIVAL(rhs->rhs_data.data, 0); + in.s_addr = IVAL(rhs->rhs_data.data, 0); printf("%s", inet_ntoa(in)); } break; @@ -74,14 +74,14 @@ static void display_tower(TALLOC_CTX *mem_ctx, struct epm_towers *twr) case 0x1f: printf(" TCP:"); if (rhs->rhs_data.length == 2) { - printf("%d", SVAL(rhs->rhs_data.data, 0)); + printf("%d", RSVAL(rhs->rhs_data.data, 0)); } break; default: printf(" UNK(%02x):", lhs->protocol); if (rhs->rhs_data.length == 2) { - printf("%d", SVAL(rhs->rhs_data.data, 0)); + printf("%d", RSVAL(rhs->rhs_data.data, 0)); } break; } @@ -179,10 +179,10 @@ BOOL torture_rpc_epmapper(int dummy) mem_ctx = talloc_init("torture_rpc_epmapper"); - status = torture_rpc_tcp(&p, - DCERPC_EPMAPPER_NAME, - DCERPC_EPMAPPER_UUID, - DCERPC_EPMAPPER_VERSION); + status = torture_rpc_connection(&p, + DCERPC_EPMAPPER_NAME, + DCERPC_EPMAPPER_UUID, + DCERPC_EPMAPPER_VERSION); if (!NT_STATUS_IS_OK(status)) { return False; } diff --git a/source4/torture/torture.c b/source4/torture/torture.c index 73373d944c..22798ed236 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -131,23 +131,22 @@ BOOL torture_close_connection(struct cli_state *c) } /* open a rpc connection to a named pipe */ -NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, +static NTSTATUS torture_rpc_tcp(struct dcerpc_pipe **p, const char *pipe_name, const char *pipe_uuid, uint32 pipe_version) { - struct cli_state *cli; NTSTATUS status; + char *host = lp_parm_string(-1, "torture", "host"); + const char *port = lp_parm_string(-1, "torture", "share"); - if (!torture_open_connection(&cli)) { - return NT_STATUS_UNSUCCESSFUL; - } + DEBUG(2,("Connecting to dcerpc server %s:%s\n", host, port)); - status = dcerpc_pipe_open_smb(p, cli->tree, pipe_name, pipe_uuid, pipe_version); + status = dcerpc_pipe_open_tcp(p, host, atoi(port), + pipe_uuid, pipe_version); if (!NT_STATUS_IS_OK(status)) { printf("Open of pipe '%s' failed with error (%s)\n", pipe_name, nt_errstr(status)); - torture_close_connection(cli); return status; } @@ -157,21 +156,35 @@ NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, return status; } + /* open a rpc connection to a named pipe */ -NTSTATUS torture_rpc_tcp(struct dcerpc_pipe **p, - const char *pipe_name, - const char *pipe_uuid, - uint32 pipe_version) +NTSTATUS torture_rpc_connection(struct dcerpc_pipe **p, + const char *pipe_name, + const char *pipe_uuid, + uint32 pipe_version) { + struct cli_state *cli; NTSTATUS status; + char *transport = lp_parm_string(-1, "torture", "transport"); - status = dcerpc_pipe_open_tcp(p, - lp_parm_string(-1, "torture", "host"), - lp_parm_int(-1, "torture", "share"), - pipe_uuid, pipe_version); + if (strcmp(transport, "ncacn_ip_tcp") == 0) { + return torture_rpc_tcp(p, pipe_name, pipe_uuid, pipe_version); + } + + if (strcmp(transport, "ncacn_np") != 0) { + printf("Unsupported RPC transport '%s'\n", transport); + return NT_STATUS_UNSUCCESSFUL; + } + + if (!torture_open_connection(&cli)) { + return NT_STATUS_UNSUCCESSFUL; + } + + status = dcerpc_pipe_open_smb(p, cli->tree, pipe_name, pipe_uuid, pipe_version); if (!NT_STATUS_IS_OK(status)) { printf("Open of pipe '%s' failed with error (%s)\n", pipe_name, nt_errstr(status)); + torture_close_connection(cli); return status; } @@ -4148,27 +4161,50 @@ static void usage(void) for(p = argv[1]; *p; p++) if(*p == '\\') *p = '/'; - - if (strncmp(argv[1], "//", 2)) { - usage(); - } - host = strdup(&argv[1][2]); - p = strchr_m(&host[2],'/'); - if (!p) { - usage(); + + /* see if its a RPC transport specifier */ + if (strncmp(argv[1], "ncacn", 5) == 0) { + char *transport = strdup(argv[1]); + p = strchr_m(transport, ':'); + if (!p) usage(); + *p = 0; + host = p+1; + p = strchr_m(host, ':'); + if (p) { + *p = 0; + share = p+1; + lp_set_cmdline("torture:share", share); + } else { + share = ""; + lp_set_cmdline("torture:share", share); + } + lp_set_cmdline("torture:host", host); + lp_set_cmdline("torture:transport", transport); + } else { + if (strncmp(argv[1], "//", 2)) { + usage(); + } + + host = strdup(&argv[1][2]); + p = strchr_m(&host[2],'/'); + if (!p) { + usage(); + } + *p = 0; + share = strdup(p+1); + + lp_set_cmdline("torture:host", host); + lp_set_cmdline("torture:share", share); + lp_set_cmdline("torture:password", ""); + lp_set_cmdline("torture:transport", "ncacn_np"); } - *p = 0; - share = strdup(p+1); if (getenv("LOGNAME")) { username = strdup(getenv("LOGNAME")); } - - lp_set_cmdline("torture:host", host); - lp_set_cmdline("torture:share", share); lp_set_cmdline("torture:username", username); - lp_set_cmdline("torture:password", ""); + argc--; argv++; -- cgit