From dc59fcf8e3a959f48d65ba3ba392761959132c8e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 30 Jan 2020 06:40:21 +0000 Subject: [PATCH] Remove FLAG_INTERACTIVE. This is simpler than FLAG_VERBOSE: everywhere we need to check it, we have a Seat available, so we can just make it a Seat query method. --- misc.c | 2 ++ pscp.c | 1 + psftp.c | 3 ++- putty.h | 15 +++++++++------ sesschan.c | 1 + ssh.c | 2 +- ssh1login.c | 4 ++-- ssh2userauth.c | 4 ++-- sshserver.c | 1 + unix/gtkwin.c | 1 + unix/uxplink.c | 13 ++++++++----- unix/uxputty.c | 1 - windows/window.c | 2 +- windows/winplink.c | 13 ++++++++----- 14 files changed, 39 insertions(+), 24 deletions(-) diff --git a/misc.c b/misc.c index b3175244..9775fccb 100644 --- a/misc.c +++ b/misc.c @@ -366,6 +366,8 @@ bool nullseat_set_trust_status(Seat *seat, bool tr) { return false; } bool nullseat_set_trust_status_vacuously(Seat *seat, bool tr) { return true; } bool nullseat_verbose_no(Seat *seat) { return false; } bool nullseat_verbose_yes(Seat *seat) { return true; } +bool nullseat_interactive_no(Seat *seat) { return false; } +bool nullseat_interactive_yes(Seat *seat) { return true; } bool null_lp_verbose_no(LogPolicy *lp) { return false; } bool null_lp_verbose_yes(LogPolicy *lp) { return true; } diff --git a/pscp.c b/pscp.c index 3cdb93ce..5b010ff1 100644 --- a/pscp.c +++ b/pscp.c @@ -83,6 +83,7 @@ static const SeatVtable pscp_seat_vt = { console_stripctrl_new, nullseat_set_trust_status_vacuously, cmdline_seat_verbose, + nullseat_interactive_no, }; static Seat pscp_seat[1] = {{ &pscp_seat_vt }}; diff --git a/psftp.c b/psftp.c index 4d128c03..c7e2414b 100644 --- a/psftp.c +++ b/psftp.c @@ -65,6 +65,7 @@ static const SeatVtable psftp_seat_vt = { console_stripctrl_new, nullseat_set_trust_status_vacuously, cmdline_seat_verbose, + nullseat_interactive_yes, }; static Seat psftp_seat[1] = {{ &psftp_seat_vt }}; @@ -2768,7 +2769,7 @@ int psftp_main(int argc, char *argv[]) bool sanitise_stderr = true; char *batchfile = NULL; - flags = FLAG_INTERACTIVE + flags = 0 #ifdef FLAG_SYNCAGENT | FLAG_SYNCAGENT #endif diff --git a/putty.h b/putty.h index fc7cc451..b441f93d 100644 --- a/putty.h +++ b/putty.h @@ -581,11 +581,6 @@ extern const char *const appname; /* * Some global flags denoting the type of application. * - * FLAG_INTERACTIVE is set when a full interactive shell session is - * being run, _either_ because no remote command has been provided - * _or_ because the application is GUI and can't run non- - * interactively. - * * These flags describe the type of _application_ - they wouldn't * vary between individual sessions - and so it's OK to have this * variable be GLOBAL. @@ -594,7 +589,6 @@ extern const char *const appname; * headers. It's probably best if those ones start from 0x1000, to * avoid collision. */ -#define FLAG_INTERACTIVE 0x0002 GLOBAL int flags; /* @@ -956,6 +950,11 @@ struct SeatVtable { * Ask the seat whether it would like verbose messages. */ bool (*verbose)(Seat *seat); + + /* + * Ask the seat whether it's an interactive program. + */ + bool (*interactive)(Seat *seat); }; static inline size_t seat_output( @@ -1003,6 +1002,8 @@ static inline bool seat_set_trust_status(Seat *seat, bool trusted) { return seat->vt->set_trust_status(seat, trusted); } static inline bool seat_verbose(Seat *seat) { return seat->vt->verbose(seat); } +static inline bool seat_interactive(Seat *seat) +{ return seat->vt->interactive(seat); } /* Unlike the seat's actual method, the public entry point * seat_connection_fatal is a wrapper function with a printf-like API, @@ -1057,6 +1058,8 @@ bool nullseat_set_trust_status(Seat *seat, bool trusted); bool nullseat_set_trust_status_vacuously(Seat *seat, bool trusted); bool nullseat_verbose_no(Seat *seat); bool nullseat_verbose_yes(Seat *seat); +bool nullseat_interactive_no(Seat *seat); +bool nullseat_interactive_yes(Seat *seat); /* * Seat functions provided by the platform's console-application diff --git a/sesschan.c b/sesschan.c index 2aee4a1c..703f1fdc 100644 --- a/sesschan.c +++ b/sesschan.c @@ -198,6 +198,7 @@ static const SeatVtable sesschan_seat_vt = { nullseat_stripctrl_new, nullseat_set_trust_status, nullseat_verbose_no, + nullseat_interactive_no, }; Channel *sesschan_new(SshChannel *c, LogContext *logctx, diff --git a/ssh.c b/ssh.c index 30f4ac6a..22e275a0 100644 --- a/ssh.c +++ b/ssh.c @@ -744,7 +744,7 @@ static const char *connect_to_host( ssh->fullhostname = NULL; *realhost = dupstr(host); /* best we can do */ - if (seat_verbose(ssh->seat) || (flags & FLAG_INTERACTIVE)) { + if (seat_verbose(ssh->seat) || seat_interactive(ssh->seat)) { /* In an interactive session, or in verbose mode, announce * in the console window that we're a sharing downstream, * to avoid confusing users as to why this session doesn't diff --git a/ssh1login.c b/ssh1login.c index 5e6269d3..fd36eea2 100644 --- a/ssh1login.c +++ b/ssh1login.c @@ -426,7 +426,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) pq_push(s->ppl.out_pq, pkt); ppl_logevent("Sent username \"%s\"", s->username); - if (seat_verbose(s->ppl.seat) || (flags & FLAG_INTERACTIVE)) + if (seat_verbose(s->ppl.seat) || seat_interactive(s->ppl.seat)) ppl_printf("Sent username \"%s\"\r\n", s->username); crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL); @@ -799,7 +799,7 @@ static void ssh1_login_process_queue(PacketProtocolLayer *ppl) crMaybeWaitUntilV((pktin = ssh1_login_pop(s)) != NULL); if (pktin->type == SSH1_SMSG_FAILURE) { ppl_logevent("TIS authentication declined"); - if (flags & FLAG_INTERACTIVE) + if (seat_interactive(s->ppl.seat)) ppl_printf("TIS authentication refused.\r\n"); s->tis_auth_refused = true; continue; diff --git a/ssh2userauth.c b/ssh2userauth.c index e019b318..6a0b47a1 100644 --- a/ssh2userauth.c +++ b/ssh2userauth.c @@ -433,7 +433,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) prompt_get_result(s->cur_prompt->prompts[0]); free_prompts(s->cur_prompt); } else { - if (seat_verbose(s->ppl.seat) || (flags & FLAG_INTERACTIVE)) + if (seat_verbose(s->ppl.seat) || seat_interactive(s->ppl.seat)) ppl_printf("Using username \"%s\".\r\n", s->username); } s->got_username = true; @@ -496,7 +496,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) * anti-spoofing header lines. */ if (bufchain_size(&s->banner) && - (seat_verbose(s->ppl.seat) || (flags & FLAG_INTERACTIVE))) { + (seat_verbose(s->ppl.seat) || seat_interactive(s->ppl.seat))) { if (s->banner_scc) { ssh2_userauth_antispoof_msg( s, "Pre-authentication banner message from server:"); diff --git a/sshserver.c b/sshserver.c index b08373b3..34ecd923 100644 --- a/sshserver.c +++ b/sshserver.c @@ -121,6 +121,7 @@ static const SeatVtable server_seat_vt = { nullseat_stripctrl_new, nullseat_set_trust_status, nullseat_verbose_no, + nullseat_interactive_no, }; static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port, diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 589f7f7b..b0f679c8 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -400,6 +400,7 @@ static const SeatVtable gtk_seat_vt = { gtk_seat_stripctrl_new, gtk_seat_set_trust_status, nullseat_verbose_yes, + nullseat_interactive_yes, }; static void gtk_eventlog(LogPolicy *lp, const char *string) diff --git a/unix/uxplink.c b/unix/uxplink.c index 420fb4c8..c42037cc 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -380,6 +380,13 @@ static int plink_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input) return ret; } +static bool plink_seat_interactive(Seat *seat) +{ + return (!*conf_get_str(conf, CONF_remote_cmd) && + !*conf_get_str(conf, CONF_remote_cmd2) && + !*conf_get_str(conf, CONF_ssh_nc_host)); +} + static const SeatVtable plink_seat_vt = { plink_output, plink_eof, @@ -400,6 +407,7 @@ static const SeatVtable plink_seat_vt = { console_stripctrl_new, console_set_trust_status, cmdline_seat_verbose, + plink_seat_interactive, }; static Seat plink_seat[1] = {{ &plink_seat_vt }}; @@ -739,11 +747,6 @@ int main(int argc, char **argv) if (use_subsystem) conf_set_bool(conf, CONF_ssh_subsys, true); - if (!*conf_get_str(conf, CONF_remote_cmd) && - !*conf_get_str(conf, CONF_remote_cmd2) && - !*conf_get_str(conf, CONF_ssh_nc_host)) - flags |= FLAG_INTERACTIVE; - /* * Select protocol. This is farmed out into a table in a * separate file to enable an ssh-free variant. diff --git a/unix/uxputty.c b/unix/uxputty.c index eb28b698..9299bd80 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -80,7 +80,6 @@ const bool share_can_be_upstream = true; void setup(bool single) { sk_init(); - flags = FLAG_INTERACTIVE; cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG | TOOLTYPE_NO_VERBOSE_OPTION; default_protocol = be_default_protocol; diff --git a/windows/window.c b/windows/window.c index a27a1c09..8fe21856 100644 --- a/windows/window.c +++ b/windows/window.c @@ -361,6 +361,7 @@ static const SeatVtable win_seat_vt = { win_seat_stripctrl_new, win_seat_set_trust_status, nullseat_verbose_yes, + nullseat_interactive_yes, }; static Seat win_seat_impl = { &win_seat_vt }; Seat *const win_seat = &win_seat_impl; @@ -484,7 +485,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) hinst = inst; hwnd = NULL; - flags = FLAG_INTERACTIVE; cmdline_tooltype |= TOOLTYPE_HOST_ARG | TOOLTYPE_PORT_ARG | TOOLTYPE_NO_VERBOSE_OPTION; diff --git a/windows/winplink.c b/windows/winplink.c index 99933013..45a07f4b 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -82,6 +82,13 @@ static int plink_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input) return ret; } +static bool plink_seat_interactive(Seat *seat) +{ + return (!*conf_get_str(conf, CONF_remote_cmd) && + !*conf_get_str(conf, CONF_remote_cmd2) && + !*conf_get_str(conf, CONF_ssh_nc_host)); +} + static const SeatVtable plink_seat_vt = { plink_output, plink_eof, @@ -102,6 +109,7 @@ static const SeatVtable plink_seat_vt = { console_stripctrl_new, console_set_trust_status, cmdline_seat_verbose, + plink_seat_interactive, }; static Seat plink_seat[1] = {{ &plink_seat_vt }}; @@ -375,11 +383,6 @@ int main(int argc, char **argv) if (use_subsystem) conf_set_bool(conf, CONF_ssh_subsys, true); - if (!*conf_get_str(conf, CONF_remote_cmd) && - !*conf_get_str(conf, CONF_remote_cmd2) && - !*conf_get_str(conf, CONF_ssh_nc_host)) - flags |= FLAG_INTERACTIVE; - /* * Select protocol. This is farmed out into a table in a * separate file to enable an ssh-free variant.