1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 14:39:24 -05:00

New plug_closing error type for 'user abort'.

This is generated when setup of a network connection is cancelled by
deliberate user action, namely, pressing ^C or ^D or the like at a
get_userpass_input prompt presented during proxy setup.

It's handled just like normal socket setup errors, except that it
omits the call to seat_connection_fatal, on the grounds that in this
one case of connection-setup failure, the user doesn't need to be
_informed_ that the connection failed - they already know, because
they failed it themself on purpose.
This commit is contained in:
Simon Tatham 2021-11-06 13:31:09 +00:00
parent 0fe41294e6
commit 2ae338b407
7 changed files with 26 additions and 17 deletions

View File

@ -55,6 +55,7 @@ typedef enum PlugCloseType {
PLUGCLOSE_NORMAL, PLUGCLOSE_NORMAL,
PLUGCLOSE_ERROR, PLUGCLOSE_ERROR,
PLUGCLOSE_BROKEN_PIPE, PLUGCLOSE_BROKEN_PIPE,
PLUGCLOSE_USER_ABORT,
} PlugCloseType; } PlugCloseType;
struct PlugVtable { struct PlugVtable {
@ -112,6 +113,16 @@ struct PlugVtable {
* distinguishes the particular error condition signalled by * distinguishes the particular error condition signalled by
* EPIPE / ERROR_BROKEN_PIPE, which ssh/sharing.c needs to * EPIPE / ERROR_BROKEN_PIPE, which ssh/sharing.c needs to
* recognise and handle specially in one situation. * recognise and handle specially in one situation.
*
* - PLUGCLOSE_USER_ABORT means that the close has happened as a
* result of some kind of deliberate user action (e.g. hitting
* ^C at a password prompt presented by a proxy socket setup
* phase). This can be used to suppress interactive error
* messages sent to the user (such as dialog boxes), on the
* grounds that the user already knows. However, 'error_msg'
* will still contain some appropriate text, so that
* non-interactive error reporting (e.g. event logs) can still
* record why the connection terminated.
*/ */
void (*closing)(Plug *p, PlugCloseType type, const char *error_msg); void (*closing)(Plug *p, PlugCloseType type, const char *error_msg);
@ -242,6 +253,8 @@ static inline void plug_closing_normal(Plug *p)
{ p->vt->closing(p, PLUGCLOSE_NORMAL, NULL); } { p->vt->closing(p, PLUGCLOSE_NORMAL, NULL); }
static inline void plug_closing_error(Plug *p, const char *msg) static inline void plug_closing_error(Plug *p, const char *msg)
{ p->vt->closing(p, PLUGCLOSE_ERROR, msg); } { p->vt->closing(p, PLUGCLOSE_ERROR, msg); }
static inline void plug_closing_user_abort(Plug *p)
{ p->vt->closing(p, PLUGCLOSE_USER_ABORT, "User aborted connection setup"); }
static inline void plug_receive(Plug *p, int urg, const char *data, size_t len) static inline void plug_receive(Plug *p, int urg, const char *data, size_t len)
{ p->vt->receive(p, urg, data, len); } { p->vt->receive(p, urg, data, len); }
static inline void plug_sent (Plug *p, size_t bufsize) static inline void plug_sent (Plug *p, size_t bufsize)

View File

@ -79,7 +79,8 @@ static void raw_closing(Plug *plug, PlugCloseType type, const char *error_msg)
seat_notify_remote_disconnect(raw->seat); seat_notify_remote_disconnect(raw->seat);
} }
logevent(raw->logctx, error_msg); logevent(raw->logctx, error_msg);
seat_connection_fatal(raw->seat, "%s", error_msg); if (type != PLUGCLOSE_USER_ABORT)
seat_connection_fatal(raw->seat, "%s", error_msg);
} else { } else {
/* Otherwise, the remote side closed the connection normally. */ /* Otherwise, the remote side closed the connection normally. */
if (!raw->sent_console_eof && seat_eof(raw->seat)) { if (!raw->sent_console_eof && seat_eof(raw->seat)) {

View File

@ -107,7 +107,8 @@ static void rlogin_closing(Plug *plug, PlugCloseType type,
if (type != PLUGCLOSE_NORMAL) { if (type != PLUGCLOSE_NORMAL) {
/* A socket error has occurred. */ /* A socket error has occurred. */
logevent(rlogin->logctx, error_msg); logevent(rlogin->logctx, error_msg);
seat_connection_fatal(rlogin->seat, "%s", error_msg); if (type != PLUGCLOSE_USER_ABORT)
seat_connection_fatal(rlogin->seat, "%s", error_msg);
} }
/* Otherwise, the remote side closed the connection normally. */ /* Otherwise, the remote side closed the connection normally. */
} }

View File

@ -594,7 +594,8 @@ static void supdup_closing(Plug *plug, PlugCloseType type,
} }
if (type != PLUGCLOSE_NORMAL) { if (type != PLUGCLOSE_NORMAL) {
logevent(supdup->logctx, error_msg); logevent(supdup->logctx, error_msg);
seat_connection_fatal(supdup->seat, "%s", error_msg); if (type != PLUGCLOSE_USER_ABORT)
seat_connection_fatal(supdup->seat, "%s", error_msg);
} }
/* Otherwise, the remote side closed the connection normally. */ /* Otherwise, the remote side closed the connection normally. */
} }

View File

@ -656,7 +656,8 @@ static void telnet_closing(Plug *plug, PlugCloseType type,
} }
if (type != PLUGCLOSE_NORMAL) { if (type != PLUGCLOSE_NORMAL) {
logevent(telnet->logctx, error_msg); logevent(telnet->logctx, error_msg);
seat_connection_fatal(telnet->seat, "%s", error_msg); if (type != PLUGCLOSE_USER_ABORT)
seat_connection_fatal(telnet->seat, "%s", error_msg);
} }
/* Otherwise, the remote side closed the connection normally. */ /* Otherwise, the remote side closed the connection normally. */
} }

View File

@ -13,18 +13,6 @@
const bool ssh_proxy_supported = true; const bool ssh_proxy_supported = true;
/*
* TODO for future work:
*
* If the user manually aborts the attempt to make the proxy SSH
* connection (e.g. by hitting ^C at a userpass prompt, or refusing to
* accept the proxy server's host key), then I think it would be nicer
* if we didn't give a connection_fatal error box. If I've aborted the
* connection deliberately, I don't need to be told it happened, and
* I'd rather not have the UI annoyance of clicking away an extra
* error dialog.
*/
typedef struct SshProxy { typedef struct SshProxy {
char *errmsg; char *errmsg;
Conf *conf; Conf *conf;
@ -318,6 +306,8 @@ static void sshproxy_send_close(SshProxy *sp)
if (sp->errmsg) if (sp->errmsg)
plug_closing_error(sp->plug, sp->errmsg); plug_closing_error(sp->plug, sp->errmsg);
else if (!sp->conn_established && backend_exitcode(sp->backend) == 0)
plug_closing_user_abort(sp->plug);
else else
plug_closing_normal(sp->plug); plug_closing_normal(sp->plug);
} }

View File

@ -606,7 +606,9 @@ static void ssh_socket_log(Plug *plug, PlugLogType type, SockAddr *addr,
static void ssh_closing(Plug *plug, PlugCloseType type, const char *error_msg) static void ssh_closing(Plug *plug, PlugCloseType type, const char *error_msg)
{ {
Ssh *ssh = container_of(plug, Ssh, plug); Ssh *ssh = container_of(plug, Ssh, plug);
if (type != PLUGCLOSE_NORMAL) { if (type == PLUGCLOSE_USER_ABORT) {
ssh_user_close(ssh, "%s", error_msg);
} else if (type != PLUGCLOSE_NORMAL) {
ssh_remote_error(ssh, "%s", error_msg); ssh_remote_error(ssh, "%s", error_msg);
} else if (ssh->bpp) { } else if (ssh->bpp) {
ssh->bpp->input_eof = true; ssh->bpp->input_eof = true;