Add a Seat vtable method to get a stripctrl.

If centralised code like the SSH implementation wants to sanitise
escape sequences out of a piece of server-provided text, it will need
to do it by making a locale-based StripCtrlChars if it's running in a
console context, or a Terminal-based one if it's in a GUI terminal-
window application.

All the other changes of behaviour needed between those two contexts
are handled by providing reconfigurable methods in the Seat vtable;
this one is no different. So now there's a new method in the Seat
vtable that will construct a StripCtrlChars appropriate to that kind
of seat. Terminal-window seats (gtkwin.c, window.c) implement it by
calling the new stripctrl_new_term(), and console ones use the locale-
based stripctrl_new().
This commit is contained in:
Simon Tatham 2019-03-05 21:13:00 +00:00
Родитель 36a11ef8d5
Коммит d60dcc2c82
12 изменённых файлов: 51 добавлений и 0 удалений

2
misc.c
Просмотреть файл

@ -333,6 +333,8 @@ const char *nullseat_get_x_display(Seat *seat) { return NULL; }
bool nullseat_get_windowid(Seat *seat, long *id_out) { return false; }
bool nullseat_get_window_pixel_size(
Seat *seat, int *width, int *height) { return false; }
StripCtrlChars *nullseat_stripctrl_new(
Seat *seat, BinarySink *bs, bool cr, wchar_t sub) { return NULL; }
void sk_free_peer_info(SocketPeerInfo *pi)
{

1
pscp.c
Просмотреть файл

@ -80,6 +80,7 @@ static const SeatVtable pscp_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
nullseat_get_window_pixel_size,
console_stripctrl_new,
};
static Seat pscp_seat[1] = {{ &pscp_seat_vt }};

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

@ -61,6 +61,7 @@ static const SeatVtable psftp_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
nullseat_get_window_pixel_size,
console_stripctrl_new,
};
static Seat psftp_seat[1] = {{ &psftp_seat_vt }};

16
putty.h
Просмотреть файл

@ -930,6 +930,15 @@ struct SeatVtable {
* true.
*/
bool (*get_window_pixel_size)(Seat *seat, int *width, int *height);
/*
* Return a StripCtrlChars appropriate for sanitising untrusted
* terminal data (e.g. SSH banners, prompts) being sent to the
* user of this seat. May return NULL if no sanitisation is
* needed.
*/
StripCtrlChars *(*stripctrl_new)(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution);
};
static inline size_t seat_output(
@ -970,6 +979,9 @@ static inline bool seat_get_windowid(Seat *seat, long *id_out)
{ return seat->vt->get_windowid(seat, id_out); }
static inline bool seat_get_window_pixel_size(Seat *seat, int *w, int *h)
{ return seat->vt->get_window_pixel_size(seat, w, h); }
static inline StripCtrlChars *seat_stripctrl_new(
Seat *seat, BinarySink *bs, bool cr, wchar_t sub)
{ return seat->vt->stripctrl_new(seat, bs, cr, sub); }
/* Unlike the seat's actual method, the public entry point
* seat_connection_fatal is a wrapper function with a printf-like API,
@ -1014,6 +1026,8 @@ void nullseat_echoedit_update(Seat *seat, bool echoing, bool editing);
const char *nullseat_get_x_display(Seat *seat);
bool nullseat_get_windowid(Seat *seat, long *id_out);
bool nullseat_get_window_pixel_size(Seat *seat, int *width, int *height);
StripCtrlChars *nullseat_stripctrl_new(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution);
/*
* Seat functions provided by the platform's console-application
@ -1031,6 +1045,8 @@ int console_confirm_weak_crypto_primitive(
int console_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
void (*callback)(void *ctx, int result), void *ctx);
StripCtrlChars *console_stripctrl_new(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution);
/*
* Other centralised seat functions.

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

@ -193,6 +193,7 @@ static const SeatVtable sesschan_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
sesschan_get_window_pixel_size,
nullseat_stripctrl_new,
};
Channel *sesschan_new(SshChannel *c, LogContext *logctx,

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

@ -113,6 +113,7 @@ static const SeatVtable server_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
nullseat_get_window_pixel_size,
nullseat_stripctrl_new,
};
static void server_socket_log(Plug *plug, int type, SockAddr *addr, int port,

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

@ -351,6 +351,13 @@ static bool gtk_seat_get_window_pixel_size(Seat *seat, int *w, int *h)
return true;
}
StripCtrlChars *gtk_seat_stripctrl_new(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution)
{
GtkFrontend *inst = container_of(seat, GtkFrontend, seat);
return stripctrl_new_term(bs_out, permit_cr, substitution, inst->term);
}
static void gtk_seat_notify_remote_exit(Seat *seat);
static void gtk_seat_update_specials_menu(Seat *seat);
static void gtk_seat_set_busy_status(Seat *seat, BusyStatus status);
@ -380,6 +387,7 @@ static const SeatVtable gtk_seat_vt = {
gtk_seat_get_windowid,
#endif
gtk_seat_get_window_pixel_size,
gtk_seat_stripctrl_new,
};
static void gtk_eventlog(LogPolicy *lp, const char *string)

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

@ -465,6 +465,12 @@ static void console_eventlog(LogPolicy *lp, const char *string)
console_logging_error(lp, string);
}
StripCtrlChars *console_stripctrl_new(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution)
{
return stripctrl_new(bs_out, permit_cr, substitution);
}
/*
* Special functions to read and print to the console for password
* prompts and the like. Uses /dev/tty or stdin/stderr, in that order

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

@ -403,6 +403,7 @@ static const SeatVtable plink_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
nullseat_get_window_pixel_size,
console_stripctrl_new,
};
static Seat plink_seat[1] = {{ &plink_seat_vt }};

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

@ -388,6 +388,12 @@ static void console_eventlog(LogPolicy *lp, const char *string)
console_logging_error(lp, string);
}
StripCtrlChars *console_stripctrl_new(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution)
{
return stripctrl_new(bs_out, permit_cr, substitution);
}
static void console_data_untrusted(HANDLE hout, const char *data, size_t len)
{
DWORD dummy;

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

@ -320,6 +320,12 @@ bool win_seat_get_window_pixel_size(Seat *seat, int *x, int *y)
return true;
}
StripCtrlChars *win_seat_stripctrl_new(Seat *seat, BinarySink *bs_out,
bool permit_cr, wchar_t substitution)
{
return stripctrl_new_term(bs_out, permit_cr, substitution, term);
}
static size_t win_seat_output(
Seat *seat, bool is_stderr, const void *, size_t);
static bool win_seat_eof(Seat *seat);
@ -347,6 +353,7 @@ static const SeatVtable win_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
win_seat_get_window_pixel_size,
win_seat_stripctrl_new,
};
static Seat win_seat_impl = { &win_seat_vt };
Seat *const win_seat = &win_seat_impl;

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

@ -105,6 +105,7 @@ static const SeatVtable plink_seat_vt = {
nullseat_get_x_display,
nullseat_get_windowid,
nullseat_get_window_pixel_size,
console_stripctrl_new,
};
static Seat plink_seat[1] = {{ &plink_seat_vt }};