1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

New Seat method, notify_session_started().

This is called by the backend to notify the Seat that the connection
has progressed to the point where the main session channel (i.e. the
thing that would typically correspond to the client's stdin/stdout)
has been successfully set up.

The only Seat that implements this method nontrivially is the one in
SshProxy, which uses it as an indication that the proxied connection
to the remote host has succeeded, and sends the
PLUGLOG_CONNECT_SUCCESS notification to its own Plug.

Hence, the only backends that need to implement it at the moment are
the two SSH-shaped backends (SSH proper and bare-connection / psusan).
For other backends, it's not always obvious what 'main session
channel' would even mean, or whether it means anything very useful; so
I've also introduced a backend flag indicating whether the backend is
expecting to call that method at all, so as not to have to spend
pointless effort on defining an arbitrary meaning for it in other
contexts.

So a lot of this patch is just introducing the new method and putting
its trivial do-nothing implementation into all the existing Seat
methods. The interesting parts happen in ssh/mainchan.c (which
actually calls it), and sshproxy.c (which does something useful in
response).
This commit is contained in:
Simon Tatham 2021-09-12 11:48:42 +01:00
parent c336643576
commit 346a7548e2
13 changed files with 45 additions and 2 deletions

1
pscp.c
View File

@ -67,6 +67,7 @@ static const SeatVtable pscp_seat_vt = {
.eof = pscp_eof,
.sent = nullseat_sent,
.get_userpass_input = filexfer_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = nullseat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = console_connection_fatal,

View File

@ -49,6 +49,7 @@ static const SeatVtable psftp_seat_vt = {
.eof = psftp_eof,
.sent = nullseat_sent,
.get_userpass_input = filexfer_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = nullseat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = console_connection_fatal,

16
putty.h
View File

@ -620,6 +620,8 @@ enum {
#define BACKEND_NEEDS_TERMINAL 0x02 /* Backend must have terminal */
#define BACKEND_SUPPORTS_NC_HOST 0x04 /* Backend can honour
CONF_ssh_nc_host */
#define BACKEND_NOTIFIES_SESSION_START 0x08 /* Backend will call
seat_notify_session_started */
/* In (no)sshproxy.c */
extern const bool ssh_proxy_supported;
@ -932,6 +934,17 @@ struct SeatVtable {
*/
int (*get_userpass_input)(Seat *seat, prompts_t *p, bufchain *input);
/*
* Notify the seat that the main session channel has been
* successfully set up.
*
* This is only used as part of the SSH proxying system, so it's
* not necessary to implement it in all backends. A backend must
* call this if it advertises the BACKEND_NOTIFIES_SESSION_START
* flag, and otherwise, doesn't have to.
*/
void (*notify_session_started)(Seat *seat);
/*
* Notify the seat that the process running at the other end of
* the connection has finished.
@ -1138,6 +1151,8 @@ static inline void seat_sent(Seat *seat, size_t bufsize)
static inline int seat_get_userpass_input(
Seat *seat, prompts_t *p, bufchain *input)
{ return seat->vt->get_userpass_input(seat, p, input); }
static inline void seat_notify_session_started(Seat *seat)
{ seat->vt->notify_session_started(seat); }
static inline void seat_notify_remote_exit(Seat *seat)
{ seat->vt->notify_remote_exit(seat); }
static inline void seat_notify_remote_disconnect(Seat *seat)
@ -1212,6 +1227,7 @@ size_t nullseat_output(
bool nullseat_eof(Seat *seat);
void nullseat_sent(Seat *seat, size_t bufsize);
int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
void nullseat_notify_session_started(Seat *seat);
void nullseat_notify_remote_exit(Seat *seat);
void nullseat_notify_remote_disconnect(Seat *seat);
void nullseat_connection_fatal(Seat *seat, const char *message);

View File

@ -129,6 +129,7 @@ static void mainchan_open_confirmation(Channel *chan)
seat_update_specials_menu(mc->ppl->seat);
ppl_logevent("Opened main channel");
seat_notify_session_started(mc->ppl->seat);
if (mc->is_simple)
sshfwd_hint_channel_is_simple(mc->sc);

View File

@ -109,6 +109,7 @@ static const SeatVtable server_seat_vt = {
.eof = nullseat_eof,
.sent = nullseat_sent,
.get_userpass_input = nullseat_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = nullseat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = nullseat_connection_fatal,

View File

@ -188,6 +188,7 @@ static const SeatVtable sesschan_seat_vt = {
.eof = sesschan_seat_eof,
.sent = nullseat_sent,
.get_userpass_input = nullseat_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = sesschan_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = sesschan_connection_fatal,

View File

@ -1230,7 +1230,7 @@ const BackendVtable ssh_backend = {
.id = "ssh",
.displayname = "SSH",
.protocol = PROT_SSH,
.flags = BACKEND_SUPPORTS_NC_HOST,
.flags = BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
.default_port = 22,
};
@ -1255,5 +1255,5 @@ const BackendVtable sshconn_backend = {
.id = "ssh-connection",
.displayname = "Bare ssh-connection",
.protocol = PROT_SSHCONN,
.flags = BACKEND_SUPPORTS_NC_HOST,
.flags = BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
};

View File

@ -66,6 +66,7 @@ typedef struct SshProxy {
bool rcvd_eof_ssh_to_socket, sent_eof_ssh_to_socket;
SockAddr *addr;
int port;
/* Traits implemented: we're a Socket from the point of view of
* the client connection, and a Seat from the POV of the SSH
@ -245,6 +246,12 @@ static void try_send_ssh_to_socket(void *ctx)
}
}
static void sshproxy_notify_session_started(Seat *seat)
{
SshProxy *sp = container_of(seat, SshProxy, seat);
plug_log(sp->plug, PLUGLOG_CONNECT_SUCCESS, sp->addr, sp->port, NULL, 0);
}
static size_t sshproxy_output(Seat *seat, bool is_stderr,
const void *data, size_t len)
{
@ -431,6 +438,7 @@ static const SeatVtable SshProxy_seat_vt = {
.eof = sshproxy_eof,
.sent = sshproxy_sent,
.get_userpass_input = sshproxy_get_userpass_input,
.notify_session_started = sshproxy_notify_session_started,
.notify_remote_exit = nullseat_notify_remote_exit,
.notify_remote_disconnect = sshproxy_notify_remote_disconnect,
.connection_fatal = sshproxy_connection_fatal,
@ -470,6 +478,7 @@ Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
bufchain_init(&sp->ssh_to_socket);
sp->addr = addr;
sp->port = port;
sp->conf = conf_new();
/* Try to treat proxy_hostname as the title of a saved session. If
@ -513,6 +522,14 @@ Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
return &sp->sock;
}
/*
* We also expect that the backend will announce a willingness to
* notify us that the session has started. Any backend providing
* NC_HOST should also provide this.
*/
assert(backvt->flags & BACKEND_NOTIFIES_SESSION_START &&
"Backend provides NC_HOST without SESSION_START!");
/*
* Turn off SSH features we definitely don't want. It would be
* awkward and counterintuitive to have the proxy SSH connection

View File

@ -391,6 +391,7 @@ static const SeatVtable plink_seat_vt = {
.eof = plink_eof,
.sent = nullseat_sent,
.get_userpass_input = plink_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = nullseat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = console_connection_fatal,

View File

@ -392,6 +392,7 @@ static const SeatVtable gtk_seat_vt = {
.eof = gtk_seat_eof,
.sent = nullseat_sent,
.get_userpass_input = gtk_seat_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = gtk_seat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = gtk_seat_connection_fatal,

View File

@ -10,6 +10,7 @@ bool nullseat_eof(Seat *seat) { return true; }
void nullseat_sent(Seat *seat, size_t bufsize) {}
int nullseat_get_userpass_input(
Seat *seat, prompts_t *p, bufchain *input) { return 0; }
void nullseat_notify_session_started(Seat *seat) {}
void nullseat_notify_remote_exit(Seat *seat) {}
void nullseat_notify_remote_disconnect(Seat *seat) {}
void nullseat_connection_fatal(Seat *seat, const char *message) {}

View File

@ -85,6 +85,7 @@ static const SeatVtable plink_seat_vt = {
.eof = plink_eof,
.sent = nullseat_sent,
.get_userpass_input = plink_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = nullseat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = console_connection_fatal,

View File

@ -333,6 +333,7 @@ static const SeatVtable win_seat_vt = {
.eof = win_seat_eof,
.sent = nullseat_sent,
.get_userpass_input = win_seat_get_userpass_input,
.notify_session_started = nullseat_notify_session_started,
.notify_remote_exit = win_seat_notify_remote_exit,
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
.connection_fatal = win_seat_connection_fatal,