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:
parent
c336643576
commit
346a7548e2
1
pscp.c
1
pscp.c
@ -67,6 +67,7 @@ static const SeatVtable pscp_seat_vt = {
|
|||||||
.eof = pscp_eof,
|
.eof = pscp_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = filexfer_get_userpass_input,
|
.get_userpass_input = filexfer_get_userpass_input,
|
||||||
|
.notify_session_started = nullseat_notify_session_started,
|
||||||
.notify_remote_exit = nullseat_notify_remote_exit,
|
.notify_remote_exit = nullseat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = console_connection_fatal,
|
.connection_fatal = console_connection_fatal,
|
||||||
|
1
psftp.c
1
psftp.c
@ -49,6 +49,7 @@ static const SeatVtable psftp_seat_vt = {
|
|||||||
.eof = psftp_eof,
|
.eof = psftp_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = filexfer_get_userpass_input,
|
.get_userpass_input = filexfer_get_userpass_input,
|
||||||
|
.notify_session_started = nullseat_notify_session_started,
|
||||||
.notify_remote_exit = nullseat_notify_remote_exit,
|
.notify_remote_exit = nullseat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = console_connection_fatal,
|
.connection_fatal = console_connection_fatal,
|
||||||
|
16
putty.h
16
putty.h
@ -620,6 +620,8 @@ enum {
|
|||||||
#define BACKEND_NEEDS_TERMINAL 0x02 /* Backend must have terminal */
|
#define BACKEND_NEEDS_TERMINAL 0x02 /* Backend must have terminal */
|
||||||
#define BACKEND_SUPPORTS_NC_HOST 0x04 /* Backend can honour
|
#define BACKEND_SUPPORTS_NC_HOST 0x04 /* Backend can honour
|
||||||
CONF_ssh_nc_host */
|
CONF_ssh_nc_host */
|
||||||
|
#define BACKEND_NOTIFIES_SESSION_START 0x08 /* Backend will call
|
||||||
|
seat_notify_session_started */
|
||||||
|
|
||||||
/* In (no)sshproxy.c */
|
/* In (no)sshproxy.c */
|
||||||
extern const bool ssh_proxy_supported;
|
extern const bool ssh_proxy_supported;
|
||||||
@ -932,6 +934,17 @@ struct SeatVtable {
|
|||||||
*/
|
*/
|
||||||
int (*get_userpass_input)(Seat *seat, prompts_t *p, bufchain *input);
|
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
|
* Notify the seat that the process running at the other end of
|
||||||
* the connection has finished.
|
* 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(
|
static inline int seat_get_userpass_input(
|
||||||
Seat *seat, prompts_t *p, bufchain *input)
|
Seat *seat, prompts_t *p, bufchain *input)
|
||||||
{ return seat->vt->get_userpass_input(seat, p, 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)
|
static inline void seat_notify_remote_exit(Seat *seat)
|
||||||
{ seat->vt->notify_remote_exit(seat); }
|
{ seat->vt->notify_remote_exit(seat); }
|
||||||
static inline void seat_notify_remote_disconnect(Seat *seat)
|
static inline void seat_notify_remote_disconnect(Seat *seat)
|
||||||
@ -1212,6 +1227,7 @@ size_t nullseat_output(
|
|||||||
bool nullseat_eof(Seat *seat);
|
bool nullseat_eof(Seat *seat);
|
||||||
void nullseat_sent(Seat *seat, size_t bufsize);
|
void nullseat_sent(Seat *seat, size_t bufsize);
|
||||||
int nullseat_get_userpass_input(Seat *seat, prompts_t *p, bufchain *input);
|
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_exit(Seat *seat);
|
||||||
void nullseat_notify_remote_disconnect(Seat *seat);
|
void nullseat_notify_remote_disconnect(Seat *seat);
|
||||||
void nullseat_connection_fatal(Seat *seat, const char *message);
|
void nullseat_connection_fatal(Seat *seat, const char *message);
|
||||||
|
@ -129,6 +129,7 @@ static void mainchan_open_confirmation(Channel *chan)
|
|||||||
|
|
||||||
seat_update_specials_menu(mc->ppl->seat);
|
seat_update_specials_menu(mc->ppl->seat);
|
||||||
ppl_logevent("Opened main channel");
|
ppl_logevent("Opened main channel");
|
||||||
|
seat_notify_session_started(mc->ppl->seat);
|
||||||
|
|
||||||
if (mc->is_simple)
|
if (mc->is_simple)
|
||||||
sshfwd_hint_channel_is_simple(mc->sc);
|
sshfwd_hint_channel_is_simple(mc->sc);
|
||||||
|
@ -109,6 +109,7 @@ static const SeatVtable server_seat_vt = {
|
|||||||
.eof = nullseat_eof,
|
.eof = nullseat_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = nullseat_get_userpass_input,
|
.get_userpass_input = nullseat_get_userpass_input,
|
||||||
|
.notify_session_started = nullseat_notify_session_started,
|
||||||
.notify_remote_exit = nullseat_notify_remote_exit,
|
.notify_remote_exit = nullseat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = nullseat_connection_fatal,
|
.connection_fatal = nullseat_connection_fatal,
|
||||||
|
@ -188,6 +188,7 @@ static const SeatVtable sesschan_seat_vt = {
|
|||||||
.eof = sesschan_seat_eof,
|
.eof = sesschan_seat_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = nullseat_get_userpass_input,
|
.get_userpass_input = nullseat_get_userpass_input,
|
||||||
|
.notify_session_started = nullseat_notify_session_started,
|
||||||
.notify_remote_exit = sesschan_notify_remote_exit,
|
.notify_remote_exit = sesschan_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = sesschan_connection_fatal,
|
.connection_fatal = sesschan_connection_fatal,
|
||||||
|
@ -1230,7 +1230,7 @@ const BackendVtable ssh_backend = {
|
|||||||
.id = "ssh",
|
.id = "ssh",
|
||||||
.displayname = "SSH",
|
.displayname = "SSH",
|
||||||
.protocol = PROT_SSH,
|
.protocol = PROT_SSH,
|
||||||
.flags = BACKEND_SUPPORTS_NC_HOST,
|
.flags = BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
|
||||||
.default_port = 22,
|
.default_port = 22,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1255,5 +1255,5 @@ const BackendVtable sshconn_backend = {
|
|||||||
.id = "ssh-connection",
|
.id = "ssh-connection",
|
||||||
.displayname = "Bare ssh-connection",
|
.displayname = "Bare ssh-connection",
|
||||||
.protocol = PROT_SSHCONN,
|
.protocol = PROT_SSHCONN,
|
||||||
.flags = BACKEND_SUPPORTS_NC_HOST,
|
.flags = BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
|
||||||
};
|
};
|
||||||
|
17
sshproxy.c
17
sshproxy.c
@ -66,6 +66,7 @@ typedef struct SshProxy {
|
|||||||
bool rcvd_eof_ssh_to_socket, sent_eof_ssh_to_socket;
|
bool rcvd_eof_ssh_to_socket, sent_eof_ssh_to_socket;
|
||||||
|
|
||||||
SockAddr *addr;
|
SockAddr *addr;
|
||||||
|
int port;
|
||||||
|
|
||||||
/* Traits implemented: we're a Socket from the point of view of
|
/* Traits implemented: we're a Socket from the point of view of
|
||||||
* the client connection, and a Seat from the POV of the SSH
|
* 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,
|
static size_t sshproxy_output(Seat *seat, bool is_stderr,
|
||||||
const void *data, size_t len)
|
const void *data, size_t len)
|
||||||
{
|
{
|
||||||
@ -431,6 +438,7 @@ static const SeatVtable SshProxy_seat_vt = {
|
|||||||
.eof = sshproxy_eof,
|
.eof = sshproxy_eof,
|
||||||
.sent = sshproxy_sent,
|
.sent = sshproxy_sent,
|
||||||
.get_userpass_input = sshproxy_get_userpass_input,
|
.get_userpass_input = sshproxy_get_userpass_input,
|
||||||
|
.notify_session_started = sshproxy_notify_session_started,
|
||||||
.notify_remote_exit = nullseat_notify_remote_exit,
|
.notify_remote_exit = nullseat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = sshproxy_notify_remote_disconnect,
|
.notify_remote_disconnect = sshproxy_notify_remote_disconnect,
|
||||||
.connection_fatal = sshproxy_connection_fatal,
|
.connection_fatal = sshproxy_connection_fatal,
|
||||||
@ -470,6 +478,7 @@ Socket *sshproxy_new_connection(SockAddr *addr, const char *hostname,
|
|||||||
bufchain_init(&sp->ssh_to_socket);
|
bufchain_init(&sp->ssh_to_socket);
|
||||||
|
|
||||||
sp->addr = addr;
|
sp->addr = addr;
|
||||||
|
sp->port = port;
|
||||||
|
|
||||||
sp->conf = conf_new();
|
sp->conf = conf_new();
|
||||||
/* Try to treat proxy_hostname as the title of a saved session. If
|
/* 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;
|
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
|
* Turn off SSH features we definitely don't want. It would be
|
||||||
* awkward and counterintuitive to have the proxy SSH connection
|
* awkward and counterintuitive to have the proxy SSH connection
|
||||||
|
@ -391,6 +391,7 @@ static const SeatVtable plink_seat_vt = {
|
|||||||
.eof = plink_eof,
|
.eof = plink_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = plink_get_userpass_input,
|
.get_userpass_input = plink_get_userpass_input,
|
||||||
|
.notify_session_started = nullseat_notify_session_started,
|
||||||
.notify_remote_exit = nullseat_notify_remote_exit,
|
.notify_remote_exit = nullseat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = console_connection_fatal,
|
.connection_fatal = console_connection_fatal,
|
||||||
|
@ -392,6 +392,7 @@ static const SeatVtable gtk_seat_vt = {
|
|||||||
.eof = gtk_seat_eof,
|
.eof = gtk_seat_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = gtk_seat_get_userpass_input,
|
.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_exit = gtk_seat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = gtk_seat_connection_fatal,
|
.connection_fatal = gtk_seat_connection_fatal,
|
||||||
|
@ -10,6 +10,7 @@ bool nullseat_eof(Seat *seat) { return true; }
|
|||||||
void nullseat_sent(Seat *seat, size_t bufsize) {}
|
void nullseat_sent(Seat *seat, size_t bufsize) {}
|
||||||
int nullseat_get_userpass_input(
|
int nullseat_get_userpass_input(
|
||||||
Seat *seat, prompts_t *p, bufchain *input) { return 0; }
|
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_exit(Seat *seat) {}
|
||||||
void nullseat_notify_remote_disconnect(Seat *seat) {}
|
void nullseat_notify_remote_disconnect(Seat *seat) {}
|
||||||
void nullseat_connection_fatal(Seat *seat, const char *message) {}
|
void nullseat_connection_fatal(Seat *seat, const char *message) {}
|
||||||
|
@ -85,6 +85,7 @@ static const SeatVtable plink_seat_vt = {
|
|||||||
.eof = plink_eof,
|
.eof = plink_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = plink_get_userpass_input,
|
.get_userpass_input = plink_get_userpass_input,
|
||||||
|
.notify_session_started = nullseat_notify_session_started,
|
||||||
.notify_remote_exit = nullseat_notify_remote_exit,
|
.notify_remote_exit = nullseat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = console_connection_fatal,
|
.connection_fatal = console_connection_fatal,
|
||||||
|
@ -333,6 +333,7 @@ static const SeatVtable win_seat_vt = {
|
|||||||
.eof = win_seat_eof,
|
.eof = win_seat_eof,
|
||||||
.sent = nullseat_sent,
|
.sent = nullseat_sent,
|
||||||
.get_userpass_input = win_seat_get_userpass_input,
|
.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_exit = win_seat_notify_remote_exit,
|
||||||
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
.notify_remote_disconnect = nullseat_notify_remote_disconnect,
|
||||||
.connection_fatal = win_seat_connection_fatal,
|
.connection_fatal = win_seat_connection_fatal,
|
||||||
|
Loading…
Reference in New Issue
Block a user