mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Add Norman Brandinger's suggested `-m' option in plink, to read the
remote command from a local file. Advantage: you can have more than one line in it, so you can remotely run what's effectively a small script. [originally from svn r1010]
This commit is contained in:
parent
c152034706
commit
4b5cda8aaa
32
plink.c
32
plink.c
@ -238,6 +238,7 @@ static void usage(void)
|
||||
printf(" -ssh force use of ssh protocol\n");
|
||||
printf(" -P port connect to specified port\n");
|
||||
printf(" -pw passw login with specified password\n");
|
||||
printf(" -m file read remote command(s) from file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -319,6 +320,35 @@ int main(int argc, char **argv) {
|
||||
--argc, username = *++argv;
|
||||
strncpy(cfg.username, username, sizeof(cfg.username));
|
||||
cfg.username[sizeof(cfg.username)-1] = '\0';
|
||||
} else if (!strcmp(p, "-m") && argc > 1) {
|
||||
char *filename, *command;
|
||||
int cmdlen, cmdsize;
|
||||
FILE *fp;
|
||||
int c, d;
|
||||
|
||||
--argc, filename = *++argv;
|
||||
|
||||
cmdlen = cmdsize = 0;
|
||||
command = NULL;
|
||||
fp = fopen(filename, "r");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "plink: unable to open command "
|
||||
"file \"%s\"\n", filename);
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
c = fgetc(fp);
|
||||
d = c;
|
||||
if (c == EOF)
|
||||
d = 0;
|
||||
if (cmdlen >= cmdsize) {
|
||||
cmdsize = cmdlen + 512;
|
||||
command = srealloc(command, cmdsize);
|
||||
}
|
||||
command[cmdlen++] = d;
|
||||
} while (c != EOF);
|
||||
cfg.remote_cmd_ptr = command;
|
||||
cfg.nopty = TRUE; /* command => no terminal */
|
||||
} else if (!strcmp(p, "-P") && argc > 1) {
|
||||
--argc, portnumber = atoi(*++argv);
|
||||
}
|
||||
@ -427,7 +457,7 @@ int main(int argc, char **argv) {
|
||||
usage();
|
||||
}
|
||||
|
||||
if (!*cfg.remote_cmd)
|
||||
if (!*cfg.remote_cmd_ptr)
|
||||
flags |= FLAG_INTERACTIVE;
|
||||
|
||||
/*
|
||||
|
2
putty.h
2
putty.h
@ -168,6 +168,8 @@ typedef struct {
|
||||
int ping_interval; /* in seconds */
|
||||
/* SSH options */
|
||||
char remote_cmd[512];
|
||||
char *remote_cmd_ptr; /* might point to a larger command
|
||||
* but never for loading/saving */
|
||||
int nopty;
|
||||
int compression;
|
||||
int agentfwd;
|
||||
|
@ -72,7 +72,6 @@ void save_settings (char *section, int do_host, Config *cfg) {
|
||||
write_setting_i (sesskey, "NoPTY", cfg->nopty);
|
||||
write_setting_i (sesskey, "Compression", cfg->compression);
|
||||
write_setting_i (sesskey, "AgentFwd", cfg->agentfwd);
|
||||
write_setting_s (sesskey, "RemoteCmd", cfg->remote_cmd);
|
||||
write_setting_s (sesskey, "Cipher",
|
||||
cfg->cipher == CIPHER_BLOWFISH ? "blowfish" :
|
||||
cfg->cipher == CIPHER_DES ? "des" :
|
||||
@ -161,6 +160,7 @@ void load_settings (char *section, int do_host, Config *cfg) {
|
||||
sesskey = open_settings_r(section);
|
||||
|
||||
cfg->ssh_subsys = 0; /* FIXME: load this properly */
|
||||
cfg->remote_cmd_ptr = cfg->remote_cmd;
|
||||
|
||||
gpps (sesskey, "HostName", "", cfg->host, sizeof(cfg->host));
|
||||
gppi (sesskey, "PortNumber", default_port, &cfg->port);
|
||||
@ -213,7 +213,6 @@ void load_settings (char *section, int do_host, Config *cfg) {
|
||||
gppi (sesskey, "NoPTY", 0, &cfg->nopty);
|
||||
gppi (sesskey, "Compression", 0, &cfg->compression);
|
||||
gppi (sesskey, "AgentFwd", 0, &cfg->agentfwd);
|
||||
gpps (sesskey, "RemoteCmd", "", cfg->remote_cmd, sizeof(cfg->remote_cmd));
|
||||
{
|
||||
char cipher[10];
|
||||
gpps (sesskey, "Cipher", "3des", cipher, 10);
|
||||
|
10
ssh.c
10
ssh.c
@ -2127,8 +2127,8 @@ static void ssh1_protocol(unsigned char *in, int inlen, int ispkt) {
|
||||
zlib_decompress_init();
|
||||
}
|
||||
|
||||
if (*cfg.remote_cmd)
|
||||
send_packet(SSH1_CMSG_EXEC_CMD, PKT_STR, cfg.remote_cmd, PKT_END);
|
||||
if (*cfg.remote_cmd_ptr)
|
||||
send_packet(SSH1_CMSG_EXEC_CMD, PKT_STR, cfg.remote_cmd_ptr, PKT_END);
|
||||
else
|
||||
send_packet(SSH1_CMSG_EXEC_SHELL, PKT_END);
|
||||
logevent("Started session");
|
||||
@ -3578,11 +3578,11 @@ static void do_ssh2_authconn(unsigned char *in, int inlen, int ispkt)
|
||||
if (cfg.ssh_subsys) {
|
||||
ssh2_pkt_addstring("subsystem");
|
||||
ssh2_pkt_addbool(1); /* want reply */
|
||||
ssh2_pkt_addstring(cfg.remote_cmd);
|
||||
} else if (*cfg.remote_cmd) {
|
||||
ssh2_pkt_addstring(cfg.remote_cmd_ptr);
|
||||
} else if (*cfg.remote_cmd_ptr) {
|
||||
ssh2_pkt_addstring("exec");
|
||||
ssh2_pkt_addbool(1); /* want reply */
|
||||
ssh2_pkt_addstring(cfg.remote_cmd);
|
||||
ssh2_pkt_addstring(cfg.remote_cmd_ptr);
|
||||
} else {
|
||||
ssh2_pkt_addstring("shell");
|
||||
ssh2_pkt_addbool(1); /* want reply */
|
||||
|
Loading…
Reference in New Issue
Block a user