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>
struct program_options {
char *hostname;
struct program_options {
char *hostname;
char *cmd;
struct cli_credentials *credentials;
char *runas;
char *cmd;
struct cli_credentials *credentials;
char *runas;
int argc_new;
char **argv_new;
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;
int flag_interactive = SVC_IGNORE_INTERACTIVE;
int flag_ostype = 2;
int flag_reinstall = 0;
pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,
0);
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,
if (((opt = poptGetNextOpt(pc)) != -1) || flag_help || flag_version) {
fprintf(stderr, version_message_fmt, SAMBA_VERSION_MAJOR,
+ 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);
}
if (opt_debuglevel) {
lp_set_cmdline("log level", opt_debuglevel);
}
options->credentials = cred;
options->hostname = argv_new[0] + 2;
options->credentials = cred;
options->hostname = argv_new[0] + 2;
options->cmd = argv_new[1];
options->flags = flag_interactive;
options->cmd = argv_new[1];
options->flags = flag_interactive;
static NTSTATUS winexe_svc_upload(
const char *hostname,
static NTSTATUS winexe_svc_upload(
const char *hostname,
const char *service_filename,
const DATA_BLOB *svc32_exe,
const DATA_BLOB *svc64_exe,
const char *service_filename,
const DATA_BLOB *svc32_exe,
const DATA_BLOB *svc64_exe,
"ADMIN$",
"?????",
credentials,
"ADMIN$",
"?????",
credentials,
static NTSTATUS winexe_svc_install(
struct cli_state *cli,
const char *hostname,
static NTSTATUS winexe_svc_install(
struct cli_state *cli,
const char *hostname,
const char *service_name,
const char *service_filename,
const DATA_BLOB *svc32_exe,
const char *service_name,
const char *service_filename,
const DATA_BLOB *svc32_exe,
if (need_start) {
status = winexe_svc_upload(
hostname,
if (need_start) {
status = winexe_svc_upload(
hostname,
service_filename,
svc32_exe,
svc64_exe,
service_filename,
svc32_exe,
svc64_exe,
NULL,
options.hostname,
NULL,
NULL,
options.hostname,
NULL,
"IPC$",
"?????",
options.credentials,
"IPC$",
"?????",
options.credentials,
status = winexe_svc_install(
cli,
options.hostname,
status = winexe_svc_install(
cli,
options.hostname,
service_name,
service_filename,
winexesvc32_exe,
service_name,
service_filename,
winexesvc32_exe,