From b951d05819a73131353a88a7014e5ceb2b196d67 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 19 Apr 2020 14:40:30 +0100 Subject: [PATCH] PSCP: change handling of default protocol/port. A user points out that in the current state of PSCP, if you have some protocol other than SSH configured in Default Settings, then specifying a non-saved-session hostname on the PSCP command line will cause it to try to connect with protocol SSH but the port number from Default Settings. A better approach is the one used in PSFTP: we use the port number from the saved session _if_ the protocol is also one that's known to PSCP (i.e. SSH or bare ssh-connection), and otherwise, we reset both to sensible values. --- pscp.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pscp.c b/pscp.c index b983169f..9827b7f4 100644 --- a/pscp.c +++ b/pscp.c @@ -395,6 +395,17 @@ static void do_cmd(char *host, char *user, char *cmd) } } + /* + * Force protocol to SSH if the user has somehow contrived to + * select one we don't support (e.g. by loading an inappropriate + * saved session). In that situation we assume the port number is + * useless too.) + */ + if (!backend_vt_from_proto(conf_get_int(conf, CONF_protocol))) { + conf_set_int(conf, CONF_protocol, PROT_SSH); + conf_set_int(conf, CONF_port, 22); + } + /* * Disable scary things which shouldn't be enabled for simple * things like SCP and SFTP: agent forwarding, port forwarding, @@ -2242,8 +2253,6 @@ int psftp_main(int argc, char *argv[]) int i; bool sanitise_stderr = true; - settings_set_default_protocol(PROT_SSH); - sk_init(); /* Load Default Settings before doing anything else. */