summaryrefslogtreecommitdiff
path: root/ssh.c
diff options
context:
space:
mode:
authorbluhm@openbsd.org <bluhm@openbsd.org>2017-05-30 18:58:37 +0000
committerDamien Miller <djm@mindrot.org>2017-05-31 10:51:09 +1000
commit1112b534a6a7a07190e497e6bf86b0d5c5fb02dc (patch)
treead8c53c5857fe2290828b378b8c4cb8aff27fefe /ssh.c
parenteb272ea4099fd6157846f15c129ac5727933aa69 (diff)
downloadopenssh-git-1112b534a6a7a07190e497e6bf86b0d5c5fb02dc.tar.gz
upstream commit
Add RemoteCommand option to specify a command in the ssh config file instead of giving it on the client's command line. This command will be executed on the remote host. The feature allows to automate tasks using ssh config. OK markus@ Upstream-ID: 5d982fc17adea373a9c68cae1021ce0a0904a5ee
Diffstat (limited to 'ssh.c')
-rw-r--r--ssh.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/ssh.c b/ssh.c
index cfd6b70e..6137fd7d 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.460 2017/05/30 08:52:19 markus Exp $ */
+/* $OpenBSD: ssh.c,v 1.461 2017/05/30 18:58:37 bluhm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -973,12 +973,6 @@ main(int ac, char **av)
}
}
- /* Cannot fork to background if no command. */
- if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
- !no_shell_flag)
- fatal("Cannot fork into background without a command "
- "to execute.");
-
/*
* Initialize "log" output. Since we are the client all output
* goes to stderr unless otherwise specified by -y or -E.
@@ -1133,6 +1127,15 @@ main(int ac, char **av)
options.use_privileged_port = 0;
#endif
+ if (buffer_len(&command) != 0 && options.remote_command != NULL)
+ fatal("Cannot execute command-line and remote command.");
+
+ /* Cannot fork to background if no command. */
+ if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
+ options.remote_command == NULL && !no_shell_flag)
+ fatal("Cannot fork into background without a command "
+ "to execute.");
+
/* reinit */
log_init(argv0, options.log_level, options.log_facility, !use_syslog);
@@ -1141,7 +1144,7 @@ main(int ac, char **av)
tty_flag = 1;
/* Allocate a tty by default if no command specified. */
- if (buffer_len(&command) == 0)
+ if (buffer_len(&command) == 0 && options.remote_command == NULL)
tty_flag = options.request_tty != REQUEST_TTY_NO;
/* Force no tty */
@@ -1197,6 +1200,27 @@ main(int ac, char **av)
free(cp);
}
+ if (options.remote_command != NULL) {
+ debug3("expanding RemoteCommand: %s", options.remote_command);
+ cp = options.remote_command;
+ options.remote_command = percent_expand(cp,
+ "C", conn_hash_hex,
+ "L", shorthost,
+ "d", pw->pw_dir,
+ "h", host,
+ "l", thishost,
+ "n", host_arg,
+ "p", portstr,
+ "r", options.user,
+ "u", pw->pw_name,
+ (char *)NULL);
+ debug3("expanded RemoteCommand: %s", options.remote_command);
+ free(cp);
+ buffer_append(&command, options.remote_command,
+ strlen(options.remote_command));
+
+ }
+
if (options.control_path != NULL) {
cp = tilde_expand_filename(options.control_path,
original_real_uid);