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)
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 cfd6b70e5..6137fd7da 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.460 2017/05/30 08:52:19 markus Exp $ */ 1/* $OpenBSD: ssh.c,v 1.461 2017/05/30 18:58:37 bluhm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -973,12 +973,6 @@ main(int ac, char **av)
973 } 973 }
974 } 974 }
975 975
976 /* Cannot fork to background if no command. */
977 if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
978 !no_shell_flag)
979 fatal("Cannot fork into background without a command "
980 "to execute.");
981
982 /* 976 /*
983 * Initialize "log" output. Since we are the client all output 977 * Initialize "log" output. Since we are the client all output
984 * goes to stderr unless otherwise specified by -y or -E. 978 * goes to stderr unless otherwise specified by -y or -E.
@@ -1133,6 +1127,15 @@ main(int ac, char **av)
1133 options.use_privileged_port = 0; 1127 options.use_privileged_port = 0;
1134#endif 1128#endif
1135 1129
1130 if (buffer_len(&command) != 0 && options.remote_command != NULL)
1131 fatal("Cannot execute command-line and remote command.");
1132
1133 /* Cannot fork to background if no command. */
1134 if (fork_after_authentication_flag && buffer_len(&command) == 0 &&
1135 options.remote_command == NULL && !no_shell_flag)
1136 fatal("Cannot fork into background without a command "
1137 "to execute.");
1138
1136 /* reinit */ 1139 /* reinit */
1137 log_init(argv0, options.log_level, options.log_facility, !use_syslog); 1140 log_init(argv0, options.log_level, options.log_facility, !use_syslog);
1138 1141
@@ -1141,7 +1144,7 @@ main(int ac, char **av)
1141 tty_flag = 1; 1144 tty_flag = 1;
1142 1145
1143 /* Allocate a tty by default if no command specified. */ 1146 /* Allocate a tty by default if no command specified. */
1144 if (buffer_len(&command) == 0) 1147 if (buffer_len(&command) == 0 && options.remote_command == NULL)
1145 tty_flag = options.request_tty != REQUEST_TTY_NO; 1148 tty_flag = options.request_tty != REQUEST_TTY_NO;
1146 1149
1147 /* Force no tty */ 1150 /* Force no tty */
@@ -1197,6 +1200,27 @@ main(int ac, char **av)
1197 free(cp); 1200 free(cp);
1198 } 1201 }
1199 1202
1203 if (options.remote_command != NULL) {
1204 debug3("expanding RemoteCommand: %s", options.remote_command);
1205 cp = options.remote_command;
1206 options.remote_command = percent_expand(cp,
1207 "C", conn_hash_hex,
1208 "L", shorthost,
1209 "d", pw->pw_dir,
1210 "h", host,
1211 "l", thishost,
1212 "n", host_arg,
1213 "p", portstr,
1214 "r", options.user,
1215 "u", pw->pw_name,
1216 (char *)NULL);
1217 debug3("expanded RemoteCommand: %s", options.remote_command);
1218 free(cp);
1219 buffer_append(&command, options.remote_command,
1220 strlen(options.remote_command));
1221
1222 }
1223
1200 if (options.control_path != NULL) { 1224 if (options.control_path != NULL) {
1201 cp = tilde_expand_filename(options.control_path, 1225 cp = tilde_expand_filename(options.control_path,
1202 original_real_uid); 1226 original_real_uid);