mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -05:00
New Plink operating mode: 'plink -shareexists'.
A Plink invocation of the form 'plink -shareexists <session>' tests for a currently live connection-sharing upstream for the session in question. <session> can be any syntax you'd use with Plink to make the actual connection (a host/port number, a bare saved session name, -load, whatever). I envisage this being useful for things like adaptive proxying - e.g. if you want to connect to host A which you can't route to directly, and you might already have a connection to either of hosts B or C which are viable proxies, then you could write a proxy shell script which checks whether you already have an upstream for B or C and goes via whichever one is currently active. Testing for the upstream's existence has to be done by actually connecting to its socket, because on Unix the mere existence of a Unix-domain socket file doesn't guarantee that there's a process listening to it. So we make a test connection, and then immediately disconnect; hence, that shows up in the upstream's event log.
This commit is contained in:
@ -607,6 +607,7 @@ int main(int argc, char **argv)
|
||||
int errors;
|
||||
int use_subsystem = 0;
|
||||
int got_host = FALSE;
|
||||
int just_test_share_exists = FALSE;
|
||||
unsigned long now;
|
||||
struct winsize size;
|
||||
|
||||
@ -685,6 +686,8 @@ int main(int argc, char **argv)
|
||||
--argc;
|
||||
provide_xrm_string(*++argv);
|
||||
}
|
||||
} else if (!strcmp(p, "-shareexists")) {
|
||||
just_test_share_exists = TRUE;
|
||||
} else {
|
||||
fprintf(stderr, "plink: unknown option \"%s\"\n", p);
|
||||
errors = 1;
|
||||
@ -959,6 +962,19 @@ int main(int argc, char **argv)
|
||||
!conf_get_str_nthstrkey(conf, CONF_portfwd, 0))
|
||||
conf_set_int(conf, CONF_ssh_simple, TRUE);
|
||||
|
||||
if (just_test_share_exists) {
|
||||
if (!back->test_for_upstream) {
|
||||
fprintf(stderr, "Connection sharing not supported for connection "
|
||||
"type '%s'\n", back->name);
|
||||
return 1;
|
||||
}
|
||||
if (back->test_for_upstream(conf_get_str(conf, CONF_host),
|
||||
conf_get_int(conf, CONF_port), conf))
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Start up the connection.
|
||||
*/
|
||||
|
@ -1218,6 +1218,7 @@ Backend pty_backend = {
|
||||
pty_provide_logctx,
|
||||
pty_unthrottle,
|
||||
pty_cfg_info,
|
||||
NULL /* test_for_upstream */,
|
||||
"pty",
|
||||
-1,
|
||||
0
|
||||
|
@ -591,6 +591,7 @@ Backend serial_backend = {
|
||||
serial_provide_logctx,
|
||||
serial_unthrottle,
|
||||
serial_cfg_info,
|
||||
NULL /* test_for_upstream */,
|
||||
"serial",
|
||||
PROT_SERIAL,
|
||||
0
|
||||
|
Reference in New Issue
Block a user