Move channel-opening logic out into subroutines.

Each of the new subroutines corresponds to one of the channel types
for which we know how to parse a CHANNEL_OPEN, and has a collection of
parameters corresponding to the fields of that message structure.
ssh2_connection_filter_queue now confines itself to parsing the
message, calling one of those functions, and constructing an
appropriate reply message if any.
This commit is contained in:
Simon Tatham 2018-09-26 18:02:33 +01:00
Родитель 2339efcd83
Коммит d1cd8b2591
8 изменённых файлов: 695 добавлений и 489 удалений

Просмотреть файл

@ -159,6 +159,7 @@ static const struct ChannelVtable agentf_channelvt = {
chan_no_exit_status,
chan_no_exit_signal,
chan_no_exit_signal_numeric,
chan_no_request_response,
};
Channel *agentf_new(SshChannel *c)

Просмотреть файл

@ -454,6 +454,7 @@ static const struct ChannelVtable PortForwarding_channelvt = {
chan_no_exit_status,
chan_no_exit_signal,
chan_no_exit_signal_numeric,
chan_no_request_response,
};
/*

Просмотреть файл

@ -186,6 +186,18 @@ static const struct SshChannelVtable ssh1channel_vtable = {
ssh1channel_unthrottle,
ssh1channel_get_conf,
ssh1channel_window_override_removed,
NULL /* x11_sharing_handover is only used by SSH-2 connection sharing */,
NULL /* request_x11_forwarding */,
NULL /* request_agent_forwarding */,
NULL /* request_pty */,
NULL /* send_env_var */,
NULL /* start_shell */,
NULL /* start_command */,
NULL /* start_subsystem */,
NULL /* send_serial_break */,
NULL /* send_signal */,
NULL /* send_terminal_size_change */,
NULL /* hint_channel_is_simple */,
};
static void ssh1_channel_init(struct ssh1_channel *c);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -34,6 +34,11 @@ struct ChannelVtable {
Channel *chan, ptrlen signame, int core_dumped, ptrlen msg);
int (*rcvd_exit_signal_numeric)(
Channel *chan, int signum, int core_dumped, ptrlen msg);
/* A method for signalling success/failure responses to channel
* requests initiated from the SshChannel vtable with want_reply
* true. */
void (*request_response)(Channel *, int success);
};
struct Channel {
@ -56,6 +61,8 @@ struct Channel {
((ch)->vt->rcvd_exit_signal(ch, sig, core, msg))
#define chan_rcvd_exit_signal_numeric(ch, sig, core, msg) \
((ch)->vt->rcvd_exit_signal_numeric(ch, sig, core, msg))
#define chan_request_response(ch, success) \
((ch)->vt->request_response(ch, success))
/*
* Reusable methods you can put in vtables to give default handling of
@ -75,6 +82,9 @@ int chan_no_exit_status(Channel *, int);
int chan_no_exit_signal(Channel *, ptrlen, int, ptrlen);
int chan_no_exit_signal_numeric(Channel *, int, int, ptrlen);
/* default implementation that never expects to receive a response */
void chan_no_request_response(Channel *, int);
/*
* Constructor for a trivial do-nothing implementation of
* ChannelVtable. Used for 'zombie' channels, i.e. channels whose
@ -106,6 +116,43 @@ struct SshChannelVtable {
const char *peer_addr, int peer_port,
int endian, int protomajor, int protominor,
const void *initial_data, int initial_len);
/*
* All the outgoing channel requests we support. Each one has a
* want_reply flag, which will cause a callback to
* chan_request_response when the result is available.
*
* The ones that return 'int' use it to indicate that the SSH
* protocol in use doesn't support this request at all.
*
* (It's also intentional that not all of them have a want_reply
* flag: the ones that don't are because SSH-1 has no method for
* signalling success or failure of that request, or because we
* wouldn't do anything usefully different with the reply in any
* case.)
*/
void (*request_x11_forwarding)(
SshChannel *c, int want_reply, const char *authproto,
const char *authdata, int screen_number, int oneshot);
void (*request_agent_forwarding)(
SshChannel *c, int want_reply);
void (*request_pty)(
SshChannel *c, int want_reply, Conf *conf, int w, int h);
int (*send_env_var)(
SshChannel *c, int want_reply, const char *var, const char *value);
void (*start_shell)(
SshChannel *c, int want_reply);
void (*start_command)(
SshChannel *c, int want_reply, const char *command);
int (*start_subsystem)(
SshChannel *c, int want_reply, const char *subsystem);
int (*send_serial_break)(
SshChannel *c, int want_reply, int length); /* length=0 for default */
int (*send_signal)(
SshChannel *c, int want_reply, const char *signame);
void (*send_terminal_size_change)(
SshChannel *c, int w, int h);
void (*hint_channel_is_simple)(SshChannel *c);
};
struct SshChannel {
@ -120,5 +167,27 @@ struct SshChannel {
#define sshfwd_window_override_removed(c) ((c)->vt->window_override_removed(c))
#define sshfwd_x11_sharing_handover(c, cs, ch, pa, pp, e, pmaj, pmin, d, l) \
((c)->vt->x11_sharing_handover(c, cs, ch, pa, pp, e, pmaj, pmin, d, l))
#define sshfwd_request_x11_forwarding(c, wr, ap, ad, scr, oneshot) \
((c)->vt->request_x11_forwarding(c, wr, ap, ad, scr, oneshot))
#define sshfwd_request_agent_forwarding(c, wr) \
((c)->vt->request_agent_forwarding(c, wr))
#define sshfwd_request_pty(c, wr, conf, w, h) \
((c)->vt->request_pty(c, wr, conf, w, h))
#define sshfwd_send_env_var(c, wr, var, value) \
((c)->vt->send_env_var(c, wr, var, value))
#define sshfwd_start_shell(c, wr) \
((c)->vt->start_shell(c, wr))
#define sshfwd_start_command(c, wr, cmd) \
((c)->vt->start_command(c, wr, cmd))
#define sshfwd_start_subsystem(c, wr, subsys) \
((c)->vt->start_subsystem(c, wr, subsys))
#define sshfwd_send_serial_break(c, wr, length) \
((c)->vt->send_serial_break(c, wr, length))
#define sshfwd_send_signal(c, wr, sig) \
((c)->vt->send_signal(c, wr, sig))
#define sshfwd_send_terminal_size_change(c, w, h) \
((c)->vt->send_terminal_size_change(c, w, h))
#define sshfwd_hint_channel_is_simple(c) \
((c)->vt->hint_channel_is_simple(c))
#endif /* PUTTY_SSHCHAN_H */

Просмотреть файл

@ -280,6 +280,7 @@ static const struct ChannelVtable zombiechan_channelvt = {
chan_no_exit_status,
chan_no_exit_signal,
chan_no_exit_signal_numeric,
chan_no_request_response,
};
Channel *zombiechan_new(void)
@ -360,6 +361,11 @@ int chan_no_exit_signal_numeric(
return FALSE;
}
void chan_no_request_response(Channel *chan, int success)
{
assert(0 && "this channel type should never send a want-reply request");
}
/* ----------------------------------------------------------------------
* Common routine to marshal tty modes into an SSH packet.
*/

Просмотреть файл

@ -130,6 +130,7 @@ int chan_no_exit_signal(Channel *ch, ptrlen s, int c, ptrlen m)
{ return FALSE; }
int chan_no_exit_signal_numeric(Channel *ch, int s, int c, ptrlen m)
{ return FALSE; }
void chan_no_request_response(Channel *chan, int success) {}
/*
* These functions are part of the plug for our connection to the X

Просмотреть файл

@ -734,6 +734,7 @@ static const struct ChannelVtable X11Connection_channelvt = {
chan_no_exit_status,
chan_no_exit_signal,
chan_no_exit_signal_numeric,
chan_no_request_response,
};
/*