summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKarl Lenz <xorangekiller@gmail.com>2019-07-04 20:28:33 -0400
committerAndrew Bartlett <abartlet@samba.org>2019-07-05 03:33:19 +0000
commit7425a8fbbe358c389f863a7295a95dff023f52dc (patch)
treeb6b584d0f8d04ad62f1c8a026a4518582202f608 /examples
parentf31333d40e6fa38daa32a3ebb32d5a317c06fc62 (diff)
downloadsamba-7425a8fbbe358c389f863a7295a95dff023f52dc.tar.gz
winexe: Add support for connecting to a host on an alternate port
This commit allows an optional port number to be specified after the hostname on the winexe command line. If no port is given, it defaults to port 445, just like it used before. Although this is probably a pretty uncommon use-case, it allows port-forwarding the service through a firewall to an alternate port, which can occassionally be helpful. $ ./bin/winexe -U karl%password1 //127.0.0.1:5445 cmd.exe Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Windows\system32> Signed-off-by: Karl Lenz <xorangekiller@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Diffstat (limited to 'examples')
-rw-r--r--examples/winexe/winexe.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/examples/winexe/winexe.c b/examples/winexe/winexe.c
index b2257852272..22f748b1d45 100644
--- a/examples/winexe/winexe.c
+++ b/examples/winexe/winexe.c
@@ -58,6 +58,7 @@ static const char version_message_fmt[] = "winexe version %d.%d\n"
struct program_options {
char *hostname;
+ int port;
char *cmd;
struct cli_credentials *credentials;
char *runas;
@@ -77,6 +78,9 @@ static void parse_args(int argc, const char *argv[],
int argc_new;
char **argv_new;
+ int port = 445;
+ char *port_str = NULL;
+
int flag_interactive = SVC_IGNORE_INTERACTIVE;
int flag_ostype = 2;
int flag_reinstall = 0;
@@ -212,7 +216,7 @@ static void parse_args(int argc, const char *argv[],
pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,
0);
- poptSetOtherOptionHelp(pc, "[OPTION]... //HOST COMMAND\nOptions:");
+ poptSetOtherOptionHelp(pc, "[OPTION]... //HOST[:PORT] COMMAND\nOptions:");
if (((opt = poptGetNextOpt(pc)) != -1) || flag_help || flag_version) {
fprintf(stderr, version_message_fmt, SAMBA_VERSION_MAJOR,
@@ -244,6 +248,17 @@ static void parse_args(int argc, const char *argv[],
exit(1);
}
+ port_str = strchr(argv_new[0], ':');
+ if (port_str) {
+ if (sscanf(port_str + 1, "%d", &port) != 1 || port <= 0) {
+ fprintf(stderr, version_message_fmt,
+ SAMBA_VERSION_MAJOR, SAMBA_VERSION_MINOR);
+ poptPrintHelp(pc, stdout, 0);
+ exit(1);
+ }
+ *port_str = '\0';
+ }
+
if (opt_debuglevel) {
lp_set_cmdline("log level", opt_debuglevel);
}
@@ -304,6 +319,7 @@ static void parse_args(int argc, const char *argv[],
options->credentials = cred;
options->hostname = argv_new[0] + 2;
+ options->port = port;
options->cmd = argv_new[1];
options->flags = flag_interactive;
@@ -323,6 +339,7 @@ static void parse_args(int argc, const char *argv[],
static NTSTATUS winexe_svc_upload(
const char *hostname,
+ int port,
const char *service_filename,
const DATA_BLOB *svc32_exe,
const DATA_BLOB *svc64_exe,
@@ -339,7 +356,7 @@ static NTSTATUS winexe_svc_upload(
NULL,
hostname,
NULL,
- 445,
+ port,
"ADMIN$",
"?????",
credentials,
@@ -421,6 +438,7 @@ done:
static NTSTATUS winexe_svc_install(
struct cli_state *cli,
const char *hostname,
+ int port,
const char *service_name,
const char *service_filename,
const DATA_BLOB *svc32_exe,
@@ -628,6 +646,7 @@ static NTSTATUS winexe_svc_install(
if (need_start) {
status = winexe_svc_upload(
hostname,
+ port,
service_filename,
svc32_exe,
svc64_exe,
@@ -1894,7 +1913,7 @@ int main(int argc, const char *argv[])
NULL,
options.hostname,
NULL,
- 445,
+ options.port,
"IPC$",
"?????",
options.credentials,
@@ -1910,6 +1929,7 @@ int main(int argc, const char *argv[])
status = winexe_svc_install(
cli,
options.hostname,
+ options.port,
service_name,
service_filename,
winexesvc32_exe,