2019-04-02 10:16:25 +00:00
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Supdup backend
|
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TTYOPT FUNCTION BITS (36-bit bitmasks)
|
2022-08-03 19:48:46 +00:00
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
#define TOALT 0200000000000LL // Characters 0175 and 0176 are converted to altmode (0033) on input
|
|
|
|
#define TOCLC 0100000000000LL // (user option bit) Convert lower-case input to upper-case
|
|
|
|
#define TOERS 0040000000000LL // Selective erase is supported
|
|
|
|
#define TOMVB 0010000000000LL // Backspacing is supported
|
|
|
|
#define TOSAI 0004000000000LL // Stanford/ITS extended ASCII graphics character set is supported
|
|
|
|
#define TOSA1 0002000000000LL // (user option bit) Characters 0001-0037 displayed using Stanford/ITS chars
|
|
|
|
#define TOOVR 0001000000000LL // Overprinting is supported
|
|
|
|
#define TOMVU 0000400000000LL // Moving cursor upwards is supported
|
|
|
|
#define TOMOR 0000200000000LL // (user option bit) System should provide **MORE** processing
|
|
|
|
#define TOROL 0000100000000LL // (user option bit) Terminal should scroll instead of wrapping
|
|
|
|
#define TOLWR 0000020000000LL // Lowercase characters are supported
|
|
|
|
#define TOFCI 0000010000000LL // Terminal can generate CONTROL and META characters
|
|
|
|
#define TOLID 0000002000000LL // Line insert/delete operations supported
|
|
|
|
#define TOCID 0000001000000LL // Character insert/delete operations supported
|
|
|
|
#define TPCBS 0000000000040LL // Terminal is using the "intelligent terminal protocol" (must be on)
|
|
|
|
#define TPORS 0000000000010LL // Server should process output resets
|
|
|
|
|
|
|
|
// Initialization words (36-bit constants)
|
|
|
|
#define WORDS 0777773000000 // Negative number of config words to send (6) in high 18 bits
|
|
|
|
#define TCTYP 0000000000007 // Defines the terminal type (MUST be 7)
|
|
|
|
#define TTYROL 0000000000001 // Scroll amount for terminal (1 line at a time)
|
|
|
|
|
|
|
|
|
|
|
|
// %TD opcodes
|
|
|
|
//
|
|
|
|
#define TDMOV 0200 // Cursor positioning
|
|
|
|
#define TDMV1 0201 // Internal cursor positioning
|
|
|
|
#define TDEOF 0202 // Erase to end of screen
|
|
|
|
#define TDEOL 0203 // Erase to end of line
|
|
|
|
#define TDDLF 0204 // Clear the character the cursor is on
|
|
|
|
#define TDCRL 0207 // Carriage return
|
|
|
|
#define TDNOP 0210 // No-op; should be ignored.
|
|
|
|
#define TDBS 0211 // Backspace (not in official SUPDUP spec)
|
|
|
|
#define TDLF 0212 // Linefeed (not in official SUPDUP spec)
|
|
|
|
#define TDCR 0213 // Carriage Return (ditto)
|
|
|
|
#define TDORS 0214 // Output reset
|
|
|
|
#define TDQOT 0215 // Quotes the following character
|
|
|
|
#define TDFS 0216 // Non-destructive forward space
|
|
|
|
#define TDMV0 0217 // General cursor positioning code
|
|
|
|
#define TDCLR 0220 // Erase the screen, home cursor
|
|
|
|
#define TDBEL 0221 // Generate an audio tone, bell, whatever
|
|
|
|
#define TDILP 0223 // Insert blank lines at the cursor
|
|
|
|
#define TDDLP 0224 // Delete lines at the cursor
|
|
|
|
#define TDICP 0225 // Insert blanks at cursor
|
|
|
|
#define TDDCP 0226 // Delete characters at cursor
|
|
|
|
#define TDBOW 0227 // Display black chars on white screen
|
|
|
|
#define TDRST 0230 // Reset %TDBOW
|
|
|
|
|
|
|
|
/* Maximum number of octets following a %TD code. */
|
|
|
|
#define TD_ARGS_MAX 4
|
|
|
|
|
|
|
|
typedef struct supdup_tag Supdup;
|
|
|
|
struct supdup_tag
|
|
|
|
{
|
|
|
|
Socket *s;
|
2021-09-13 11:00:01 +00:00
|
|
|
bool socket_connected;
|
2019-04-02 10:16:25 +00:00
|
|
|
bool closed_on_socket_error;
|
|
|
|
|
|
|
|
Seat *seat;
|
|
|
|
LogContext *logctx;
|
2021-09-14 09:13:28 +00:00
|
|
|
Ldisc *ldisc;
|
2019-04-02 10:16:25 +00:00
|
|
|
int term_width, term_height;
|
Add 'description' methods for Backend and Plug.
These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.
Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.
The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.
Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"
In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
2021-10-24 08:18:12 +00:00
|
|
|
char *description;
|
2019-04-02 10:16:25 +00:00
|
|
|
|
|
|
|
long long ttyopt;
|
|
|
|
long tcmxv;
|
|
|
|
long tcmxh;
|
|
|
|
|
|
|
|
bool sent_location;
|
|
|
|
|
|
|
|
Conf *conf;
|
|
|
|
|
|
|
|
int bufsize;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CONNECTING, // waiting for %TDNOP from server after sending connection params
|
|
|
|
CONNECTED // %TDNOP received, connected.
|
|
|
|
} state;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
TD_TOPLEVEL,
|
|
|
|
TD_ARGS,
|
|
|
|
TD_ARGSDONE
|
|
|
|
} tdstate;
|
|
|
|
|
|
|
|
int td_code;
|
|
|
|
int td_argcount;
|
|
|
|
char td_args[TD_ARGS_MAX];
|
|
|
|
int td_argindex;
|
|
|
|
|
|
|
|
void (*print) (strbuf *outbuf, int c);
|
|
|
|
|
|
|
|
Pinger *pinger;
|
|
|
|
|
|
|
|
Plug plug;
|
|
|
|
Backend backend;
|
Introduce a new 'Interactor' trait.
This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.
To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.
I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.
The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
2021-10-30 16:16:08 +00:00
|
|
|
Interactor interactor;
|
2019-04-02 10:16:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SUPDUP_MAX_BACKLOG 4096
|
|
|
|
|
|
|
|
static void c_write(Supdup *supdup, unsigned char *buf, int len)
|
|
|
|
{
|
|
|
|
size_t backlog = seat_stdout(supdup->seat, buf, len);
|
|
|
|
sk_set_frozen(supdup->s, backlog > SUPDUP_MAX_BACKLOG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_send_location(Supdup *supdup)
|
|
|
|
{
|
|
|
|
char locHeader[] = { 0300, 0302 };
|
|
|
|
char* locString = conf_get_str(supdup->conf, CONF_supdup_location);
|
|
|
|
|
|
|
|
sk_write(supdup->s, locHeader, sizeof(locHeader));
|
|
|
|
sk_write(supdup->s, locString, strlen(locString) + 1); // include NULL terminator
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_ascii(strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
/* In ASCII mode, ignore control characters. The server shouldn't
|
|
|
|
send them. */
|
|
|
|
if (c >= 040 && c < 0177)
|
|
|
|
put_byte (outbuf, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_its(strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
/* The ITS character set is documented in RFC 734. */
|
|
|
|
static const char *map[] = {
|
|
|
|
"\xc2\xb7", "\342\206\223", "\316\261", "\316\262",
|
|
|
|
"\342\210\247", "\302\254", "\316\265", "\317\200",
|
|
|
|
"\316\273", "\xce\xb3", "\xce\xb4", "\xe2\x86\x91",
|
|
|
|
"\xc2\xb1", "\xe2\x8a\x95", "\342\210\236", "\342\210\202",
|
|
|
|
"\342\212\202", "\342\212\203", "\342\210\251", "\342\210\252",
|
|
|
|
"\342\210\200", "\342\210\203", "\xe2\x8a\x97", "\342\206\224",
|
|
|
|
"\xe2\x86\x90", "\342\206\222", "\xe2\x89\xa0", "\xe2\x97\x8a",
|
|
|
|
"\342\211\244", "\342\211\245", "\342\211\241", "\342\210\250",
|
|
|
|
" ", "!", "\"", "#", "$", "%", "&", "'",
|
|
|
|
"(", ")", "*", "+", ",", "-", ".", "/",
|
|
|
|
"0", "1", "2", "3", "4", "5", "6", "7",
|
|
|
|
"8", "9", ":", ";", "<", "=", ">", "?",
|
|
|
|
"@", "A", "B", "C", "D", "E", "F", "G",
|
|
|
|
"H", "I", "J", "K", "L", "M", "N", "O",
|
|
|
|
"P", "Q", "R", "S", "T", "U", "V", "W",
|
|
|
|
"X", "Y", "Z", "[", "\\", "]", "^", "_",
|
|
|
|
"`", "a", "b", "c", "d", "e", "f", "g",
|
|
|
|
"h", "i", "j", "k", "l", "m", "n", "o",
|
|
|
|
"p", "q", "r", "s", "t", "u", "v", "w",
|
|
|
|
"x", "y", "z", "{", "|", "}", "~", "\xe2\x88\xab"
|
|
|
|
};
|
|
|
|
|
|
|
|
put_data (outbuf, map[c], strlen(map[c]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_waits(strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
/* The WAITS character set used at the Stanford AI Lab is documented
|
|
|
|
here: https://www.saildart.org/allow/sail-charset-utf8.html */
|
|
|
|
static const char *map[] = {
|
|
|
|
"", "\342\206\223", "\316\261", "\316\262",
|
|
|
|
"\342\210\247", "\302\254", "\316\265", "\317\200",
|
|
|
|
"\316\273", "", "", "",
|
|
|
|
"", "", "\342\210\236", "\342\210\202",
|
|
|
|
"\342\212\202", "\342\212\203", "\342\210\251", "\342\210\252",
|
|
|
|
"\342\210\200", "\342\210\203", "\xe2\x8a\x97", "\342\206\224",
|
|
|
|
"_", "\342\206\222", "~", "\xe2\x89\xa0",
|
|
|
|
"\342\211\244", "\342\211\245", "\342\211\241", "\342\210\250",
|
|
|
|
" ", "!", "\"", "#", "$", "%", "&", "'",
|
|
|
|
"(", ")", "*", "+", ",", "-", ".", "/",
|
|
|
|
"0", "1", "2", "3", "4", "5", "6", "7",
|
|
|
|
"8", "9", ":", ";", "<", "=", ">", "?",
|
|
|
|
"@", "A", "B", "C", "D", "E", "F", "G",
|
|
|
|
"H", "I", "J", "K", "L", "M", "N", "O",
|
|
|
|
"P", "Q", "R", "S", "T", "U", "V", "W",
|
|
|
|
"X", "Y", "Z", "[", "\\", "]", "\xe2\x86\x91", "\xe2\x86\x90",
|
|
|
|
"`", "a", "b", "c", "d", "e", "f", "g",
|
|
|
|
"h", "i", "j", "k", "l", "m", "n", "o",
|
|
|
|
"p", "q", "r", "s", "t", "u", "v", "w",
|
|
|
|
"x", "y", "z", "{", "|", "\xe2\x97\x8a", "}", ""
|
|
|
|
};
|
|
|
|
|
|
|
|
put_data (outbuf, map[c], strlen(map[c]));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_toplevel(Supdup *supdup, strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
// Toplevel: Waiting for a %TD code or a printable character
|
|
|
|
if (c >= 0200) {
|
|
|
|
// Handle SUPDUP %TD codes (codes greater than or equal to 200)
|
|
|
|
supdup->td_argindex = 0;
|
|
|
|
supdup->td_code = c;
|
|
|
|
switch (c) {
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDMOV:
|
2019-04-02 10:16:25 +00:00
|
|
|
// %TD codes using 4 arguments
|
|
|
|
supdup->td_argcount = 4;
|
|
|
|
supdup->tdstate = TD_ARGS;
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDMV0:
|
|
|
|
case TDMV1:
|
2019-04-02 10:16:25 +00:00
|
|
|
// %TD codes using 2 arguments
|
|
|
|
supdup->td_argcount = 2;
|
|
|
|
supdup->tdstate = TD_ARGS;
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDQOT:
|
|
|
|
case TDILP:
|
|
|
|
case TDDLP:
|
|
|
|
case TDICP:
|
|
|
|
case TDDCP:
|
2019-04-02 10:16:25 +00:00
|
|
|
// %TD codes using 1 argument
|
|
|
|
supdup->td_argcount = 1;
|
|
|
|
supdup->tdstate = TD_ARGS;
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDEOF:
|
|
|
|
case TDEOL:
|
|
|
|
case TDDLF:
|
|
|
|
case TDCRL:
|
|
|
|
case TDNOP:
|
|
|
|
case TDORS:
|
|
|
|
case TDFS:
|
|
|
|
case TDCLR:
|
|
|
|
case TDBEL:
|
|
|
|
case TDBOW:
|
|
|
|
case TDRST:
|
|
|
|
case TDBS:
|
|
|
|
case TDCR:
|
|
|
|
case TDLF:
|
2019-04-02 10:16:25 +00:00
|
|
|
// %TD codes using 0 arguments
|
|
|
|
supdup->td_argcount = 0;
|
|
|
|
supdup->tdstate = TD_ARGSDONE;
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
default:
|
2019-04-02 10:16:25 +00:00
|
|
|
// Unhandled, ignore
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
supdup->print(outbuf, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_args(Supdup *supdup, strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
// Collect up args for %TD code
|
|
|
|
if (supdup->td_argindex < TD_ARGS_MAX) {
|
|
|
|
supdup->td_args[supdup->td_argindex] = c;
|
|
|
|
supdup->td_argindex++;
|
|
|
|
|
|
|
|
if (supdup->td_argcount == supdup->td_argindex) {
|
|
|
|
// No more args, %TD code is ready to go.
|
|
|
|
supdup->tdstate = TD_ARGSDONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Should never hit this state, if we do we will just
|
|
|
|
// return to TOPLEVEL.
|
|
|
|
supdup->tdstate = TD_TOPLEVEL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_argsdone(Supdup *supdup, strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
char buf[4];
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
// Arguments for %TD code have been collected; dispatch based
|
|
|
|
// on the %TD code we're handling.
|
|
|
|
switch (supdup->td_code) {
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDMOV:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
General cursor position code. Followed by four bytes;
|
|
|
|
the first two are the "old" vertical and horizontal
|
|
|
|
positions and may be ignored. The next two are the new
|
|
|
|
vertical and horizontal positions. The cursor should be
|
|
|
|
moved to this position.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// We only care about the new position.
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[%d;%dH", supdup->td_args[2]+1, supdup->td_args[3]+1);
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDMV0:
|
|
|
|
case TDMV1:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
General cursor position code. Followed by two bytes;
|
|
|
|
the new vertical and horizontal positions.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[%d;%dH", supdup->td_args[0]+1, supdup->td_args[1]+1);
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDEOF:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Erase to end of screen. This is an optional function
|
|
|
|
since many terminals do not support this. If the
|
|
|
|
terminal does not support this function, it should be
|
|
|
|
treated the same as %TDEOL.
|
|
|
|
|
|
|
|
%TDEOF does an erase to end of line, then erases all
|
|
|
|
lines lower on the screen than the cursor. The cursor
|
|
|
|
does not move.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[J");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDEOL:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Erase to end of line. This erases the character
|
|
|
|
position the cursor is at and all positions to the right
|
|
|
|
on the same line. The cursor does not move.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[K");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDDLF:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Clear the character position the cursor is on. The
|
|
|
|
cursor does not move.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[X");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDCRL:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
If the cursor is not on the bottom line of the screen,
|
|
|
|
move cursor to the beginning of the next line and clear
|
|
|
|
that line. If the cursor is at the bottom line, scroll
|
|
|
|
up.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\015\012");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDNOP:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
No-op; should be ignored.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDORS:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Output reset. This code serves as a data mark for
|
|
|
|
aborting output much as IAC DM does in the ordinary
|
|
|
|
TELNET protocol.
|
|
|
|
*/
|
|
|
|
outbuf->len = 0;
|
|
|
|
if (!seat_get_cursor_position(supdup->seat, &x, &y))
|
|
|
|
x = y = 0;
|
|
|
|
buf[0] = 034;
|
|
|
|
buf[1] = 020;
|
|
|
|
buf[2] = y;
|
|
|
|
buf[3] = x;
|
|
|
|
sk_write(supdup->s, buf, 4);
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDQOT:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Quotes the following character. This is used when
|
|
|
|
sending 8-bit codes which are not %TD codes, for
|
|
|
|
instance when loading programs into an intelligent
|
|
|
|
terminal. The following character should be passed
|
|
|
|
through intact to the terminal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
put_byte(outbuf, supdup->td_args[0]);
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDFS:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Non-destructive forward space. The cursor moves right
|
|
|
|
one position; this code will not be sent at the end of a
|
|
|
|
line.
|
|
|
|
*/
|
|
|
|
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[C");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDCLR:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Erase the screen. Home the cursor to the top left hand
|
|
|
|
corner of the screen.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[2J\033[H");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDBEL:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Generate an audio tone, bell, whatever.
|
|
|
|
*/
|
|
|
|
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\007");
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDILP:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Insert blank lines at the cursor; followed by a byte
|
|
|
|
containing a count of the number of blank lines to
|
|
|
|
insert. The cursor is unmoved. The line the cursor is
|
|
|
|
on and all lines below it move down; lines moved off the
|
|
|
|
bottom of the screen are lost.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[%dL", supdup->td_args[0]);
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDDLP:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Delete lines at the cursor; followed by a count. The
|
|
|
|
cursor is unmoved. The first line deleted is the one
|
|
|
|
the cursor is on. Lines below those deleted move up.
|
|
|
|
Newly- created lines at the bottom of the screen are
|
|
|
|
blank.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[%dM", supdup->td_args[0]);
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDICP:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Insert blank character positions at the cursor; followed
|
|
|
|
by a count. The cursor is unmoved. The character the
|
|
|
|
cursor is on and all characters to the right on the
|
|
|
|
current line move to the right; characters moved off the
|
|
|
|
end of the line are lost.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[%d@", supdup->td_args[0]);
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDDCP:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Delete characters at the cursor; followed by a count.
|
|
|
|
The cursor is unmoved. The first character deleted is
|
|
|
|
the one the cursor is on. Newly-created characters at
|
|
|
|
the end of the line are blank.
|
|
|
|
*/
|
2021-11-19 10:23:32 +00:00
|
|
|
put_fmt(outbuf, "\033[%dP", supdup->td_args[0]);
|
2019-04-02 10:16:25 +00:00
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDBOW:
|
|
|
|
case TDRST:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
Display black characters on white screen.
|
|
|
|
HIGHLY OPTIONAL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Since this is HIGHLY OPTIONAL, I'm not going
|
|
|
|
// to implement it yet.
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Non-standard (whatever "standard" means here) SUPDUP
|
|
|
|
* commands. These are used (at the very least) by
|
|
|
|
* Genera's SUPDUP implementation. Cannot find any
|
|
|
|
* official documentation, behavior is based on UNIX
|
|
|
|
* SUPDUP implementation from MIT.
|
|
|
|
*/
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDBS:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
* Backspace -- move cursor back one character (does not
|
|
|
|
* appear to wrap...)
|
|
|
|
*/
|
|
|
|
put_byte(outbuf, '\010');
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDLF:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
* Linefeed -- move cursor down one line (again, no wrapping)
|
|
|
|
*/
|
|
|
|
put_byte(outbuf, '\012');
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case TDCR:
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
|
|
|
* Carriage return -- move cursor to start of current line.
|
|
|
|
*/
|
|
|
|
put_byte(outbuf, '\015');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return to top level to pick up the next %TD code or
|
|
|
|
// printable character.
|
|
|
|
supdup->tdstate = TD_TOPLEVEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void term_out_supdup(Supdup *supdup, strbuf *outbuf, int c)
|
|
|
|
{
|
|
|
|
if (supdup->tdstate == TD_TOPLEVEL) {
|
|
|
|
do_toplevel (supdup, outbuf, c);
|
|
|
|
} else if (supdup->tdstate == TD_ARGS) {
|
|
|
|
do_args (supdup, outbuf, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If all arguments for a %TD code are ready, we will execute the code now.
|
|
|
|
if (supdup->tdstate == TD_ARGSDONE) {
|
|
|
|
do_argsdone (supdup, outbuf, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_supdup_read(Supdup *supdup, const char *buf, size_t len)
|
|
|
|
{
|
|
|
|
strbuf *outbuf = strbuf_new();
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
int c = (unsigned char)*buf++;
|
|
|
|
switch (supdup->state) {
|
2022-08-03 19:48:46 +00:00
|
|
|
case CONNECTING:
|
2019-04-02 10:16:25 +00:00
|
|
|
// "Following the transmission of the terminal options by
|
|
|
|
// the user, the server should respond with an ASCII
|
|
|
|
// greeting message, terminated with a %TDNOP code..."
|
|
|
|
if (TDNOP == c) {
|
|
|
|
// Greeting done, switch to the CONNECTED state.
|
|
|
|
supdup->state = CONNECTED;
|
|
|
|
supdup->tdstate = TD_TOPLEVEL;
|
|
|
|
} else {
|
|
|
|
// Forward the greeting message (which is straight
|
|
|
|
// ASCII, no controls) on so it gets displayed TODO:
|
|
|
|
// filter out only printable chars?
|
|
|
|
put_byte(outbuf, c);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2022-08-03 19:48:46 +00:00
|
|
|
case CONNECTED:
|
2019-04-02 10:16:25 +00:00
|
|
|
// "All transmissions from the server after the %TDNOP
|
|
|
|
// [see above] are either printing characters or virtual
|
|
|
|
// terminal display codes." Forward these on to the
|
|
|
|
// frontend which will decide what to do with them.
|
|
|
|
term_out_supdup(supdup, outbuf, c);
|
|
|
|
/*
|
|
|
|
* Hack to make Symbolics Genera SUPDUP happy: Wait until
|
|
|
|
* after we're connected (finished the initial handshake
|
|
|
|
* and have gotten additional data) before sending the
|
|
|
|
* location string. For some reason doing so earlier
|
|
|
|
* causes the Symbolics SUPDUP to end up in an odd state.
|
|
|
|
*/
|
|
|
|
if (!supdup->sent_location) {
|
|
|
|
supdup_send_location(supdup);
|
|
|
|
supdup->sent_location = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outbuf->len >= 4096) {
|
|
|
|
c_write(supdup, outbuf->u, outbuf->len);
|
|
|
|
outbuf->len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outbuf->len)
|
|
|
|
c_write(supdup, outbuf->u, outbuf->len);
|
|
|
|
strbuf_free(outbuf);
|
|
|
|
}
|
|
|
|
|
2024-06-26 07:29:39 +00:00
|
|
|
static void supdup_log(Plug *plug, Socket *s, PlugLogType type, SockAddr *addr,
|
|
|
|
int port, const char *error_msg, int error_code)
|
2019-04-02 10:16:25 +00:00
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(plug, Supdup, plug);
|
2024-06-26 07:29:39 +00:00
|
|
|
backend_socket_log(supdup->seat, supdup->logctx, s, type, addr, port,
|
2019-04-02 10:16:25 +00:00
|
|
|
error_msg, error_code,
|
2021-09-13 11:00:01 +00:00
|
|
|
supdup->conf, supdup->socket_connected);
|
Allow new_connection to take an optional Seat. (NFC)
This is working towards allowing the subsidiary SSH connection in an
SshProxy to share the main user-facing Seat, so as to be able to pass
through interactive prompts.
This is more difficult than the similar change with LogPolicy, because
Seats are stateful. In particular, the trust-sigil status will need to
be controlled by the SshProxy until it's ready to pass over control to
the main SSH (or whatever) connection.
To make this work, I've introduced a thing called a TempSeat, which is
(yet) another Seat implementation. When a backend hands its Seat to
new_connection(), it does it in a way that allows new_connection() to
borrow it completely, and replace it in the main backend structure
with a TempSeat, which acts as a temporary placeholder. If the main
backend tries to do things like changing trust status or sending
output, the TempSeat will buffer them; later on, when the connection
is established, TempSeat will replay the changes into the real Seat.
So, in each backend, I've made the following changes:
- pass &foo->seat to new_connection, which may overwrite it with a
TempSeat.
- if it has done so (which we can tell via the is_tempseat() query
function), then we have to free the TempSeat and reinstate our main
Seat. The signal that we can do so is the PLUGLOG_CONNECT_SUCCESS
notification, which indicates that SshProxy has finished all its
connection setup work.
- we also have to remember to free the TempSeat if our backend is
disposed of without that having happened (e.g. because the
connection _doesn't_ succeed).
- in backends which have no local auth phase to worry about, ensure
we don't call seat_set_trust_status on the main Seat _before_ it
gets potentially replaced with a TempSeat. Moved some calls of
seat_set_trust_status to just after new_connection(), so that now
the initial trust status setup will go into the TempSeat (if
appropriate) and be buffered until that seat is relinquished.
In all other uses of new_connection, where we don't have a Seat
available at all, we just pass NULL.
This is NFC, because neither new_connection() nor any of its delegates
will _actually_ do this replacement yet. We're just setting up the
framework to enable it to do so in the next commit.
2021-09-13 16:17:20 +00:00
|
|
|
if (type == PLUGLOG_CONNECT_SUCCESS) {
|
2021-09-13 11:00:01 +00:00
|
|
|
supdup->socket_connected = true;
|
2021-09-14 09:13:28 +00:00
|
|
|
if (supdup->ldisc)
|
|
|
|
ldisc_check_sendok(supdup->ldisc);
|
Allow new_connection to take an optional Seat. (NFC)
This is working towards allowing the subsidiary SSH connection in an
SshProxy to share the main user-facing Seat, so as to be able to pass
through interactive prompts.
This is more difficult than the similar change with LogPolicy, because
Seats are stateful. In particular, the trust-sigil status will need to
be controlled by the SshProxy until it's ready to pass over control to
the main SSH (or whatever) connection.
To make this work, I've introduced a thing called a TempSeat, which is
(yet) another Seat implementation. When a backend hands its Seat to
new_connection(), it does it in a way that allows new_connection() to
borrow it completely, and replace it in the main backend structure
with a TempSeat, which acts as a temporary placeholder. If the main
backend tries to do things like changing trust status or sending
output, the TempSeat will buffer them; later on, when the connection
is established, TempSeat will replay the changes into the real Seat.
So, in each backend, I've made the following changes:
- pass &foo->seat to new_connection, which may overwrite it with a
TempSeat.
- if it has done so (which we can tell via the is_tempseat() query
function), then we have to free the TempSeat and reinstate our main
Seat. The signal that we can do so is the PLUGLOG_CONNECT_SUCCESS
notification, which indicates that SshProxy has finished all its
connection setup work.
- we also have to remember to free the TempSeat if our backend is
disposed of without that having happened (e.g. because the
connection _doesn't_ succeed).
- in backends which have no local auth phase to worry about, ensure
we don't call seat_set_trust_status on the main Seat _before_ it
gets potentially replaced with a TempSeat. Moved some calls of
seat_set_trust_status to just after new_connection(), so that now
the initial trust status setup will go into the TempSeat (if
appropriate) and be buffered until that seat is relinquished.
In all other uses of new_connection, where we don't have a Seat
available at all, we just pass NULL.
This is NFC, because neither new_connection() nor any of its delegates
will _actually_ do this replacement yet. We're just setting up the
framework to enable it to do so in the next commit.
2021-09-13 16:17:20 +00:00
|
|
|
}
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
|
New API for plug_closing() with a custom type enum.
Passing an operating-system-specific error code to plug_closing(),
such as errno or GetLastError(), was always a bit weird, given that it
generally had to be handled by cross-platform receiving code in
backends. I had the platform.h implementations #define any error
values that the cross-platform code would have to handle specially,
but that's still not a great system, because it also doesn't leave
freedom to invent error representations of my own that don't
correspond to any OS code. (For example, the ones I just removed from
proxy.h.)
So now, the OS error code is gone from the plug_closing API, and in
its place is a custom enumeration of closure types: normal, error, and
the special case BROKEN_PIPE which is the only OS error code we have
so far needed to handle specially. (All others just mean 'abandon the
connection and print the textual message'.)
Having already centralised the handling of OS error codes in the
previous commit, we've now got a convenient place to add any further
type codes for errors needing special handling: each of Unix
plug_closing_errno(), Windows plug_closing_system_error(), and Windows
plug_closing_winsock_error() can easily grow extra special cases if
need be, and each one will only have to live in one place.
2021-11-06 13:28:32 +00:00
|
|
|
static void supdup_closing(Plug *plug, PlugCloseType type,
|
|
|
|
const char *error_msg)
|
2019-04-02 10:16:25 +00:00
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(plug, Supdup, plug);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't implement independent EOF in each direction for Telnet
|
|
|
|
* connections; as soon as we get word that the remote side has
|
|
|
|
* sent us EOF, we wind up the whole connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (supdup->s) {
|
|
|
|
sk_close(supdup->s);
|
|
|
|
supdup->s = NULL;
|
|
|
|
if (error_msg)
|
|
|
|
supdup->closed_on_socket_error = true;
|
|
|
|
seat_notify_remote_exit(supdup->seat);
|
2021-05-22 11:47:51 +00:00
|
|
|
seat_notify_remote_disconnect(supdup->seat);
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
New API for plug_closing() with a custom type enum.
Passing an operating-system-specific error code to plug_closing(),
such as errno or GetLastError(), was always a bit weird, given that it
generally had to be handled by cross-platform receiving code in
backends. I had the platform.h implementations #define any error
values that the cross-platform code would have to handle specially,
but that's still not a great system, because it also doesn't leave
freedom to invent error representations of my own that don't
correspond to any OS code. (For example, the ones I just removed from
proxy.h.)
So now, the OS error code is gone from the plug_closing API, and in
its place is a custom enumeration of closure types: normal, error, and
the special case BROKEN_PIPE which is the only OS error code we have
so far needed to handle specially. (All others just mean 'abandon the
connection and print the textual message'.)
Having already centralised the handling of OS error codes in the
previous commit, we've now got a convenient place to add any further
type codes for errors needing special handling: each of Unix
plug_closing_errno(), Windows plug_closing_system_error(), and Windows
plug_closing_winsock_error() can easily grow extra special cases if
need be, and each one will only have to live in one place.
2021-11-06 13:28:32 +00:00
|
|
|
if (type != PLUGCLOSE_NORMAL) {
|
2019-04-02 10:16:25 +00:00
|
|
|
logevent(supdup->logctx, error_msg);
|
2021-11-06 13:31:09 +00:00
|
|
|
if (type != PLUGCLOSE_USER_ABORT)
|
|
|
|
seat_connection_fatal(supdup->seat, "%s", error_msg);
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
/* Otherwise, the remote side closed the connection normally. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_receive(Plug *plug, int urgent, const char *data, size_t len)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(plug, Supdup, plug);
|
|
|
|
do_supdup_read(supdup, data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_sent(Plug *plug, size_t bufsize)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(plug, Supdup, plug);
|
|
|
|
supdup->bufsize = bufsize;
|
New Seat callback, seat_sent().
This is used to notify the Seat that some data has been cleared from
the backend's outgoing data buffer. In other words, it notifies the
Seat that it might be worth calling backend_sendbuffer() again.
We've never needed this before, because until now, Seats have always
been the 'main program' part of the application, meaning they were
also in control of the event loop. So they've been able to call
backend_sendbuffer() proactively, every time they go round the event
loop, instead of having to wait for a callback.
But now, the SSH proxy is the first example of a Seat without
privileged access to the event loop, so it has no way to find out that
the backend's sendbuffer has got smaller. And without that, it can't
pass that notification on to plug_sent, to unblock in turn whatever
the proxied connection might have been waiting to send.
In fact, before this commit, sshproxy.c never called plug_sent at all.
As a result, large data uploads over an SSH jump host would hang
forever as soon as the outgoing buffer filled up for the first time:
the main backend (to which sshproxy.c was acting as a Socket) would
carefully stop filling up the buffer, and then never receive the call
to plug_sent that would cause it to start again.
The new callback is ignored everywhere except in sshproxy.c. It might
be a good idea to remove backend_sendbuffer() entirely and convert all
previous uses of it into non-empty implementations of this callback,
so that we've only got one system; but for the moment, I haven't done
that.
2021-06-27 12:52:48 +00:00
|
|
|
seat_sent(supdup->seat, supdup->bufsize);
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_send_36bits(Supdup *supdup, unsigned long long thirtysix)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// From RFC734:
|
|
|
|
// "Each word is sent through the 8-bit connection as six
|
|
|
|
// 6-bit bytes, most-significant first."
|
|
|
|
//
|
|
|
|
// Split the 36-bit word into 6 6-bit "bytes", packed into
|
|
|
|
// 8-bit bytes and send, most-significant byte first.
|
|
|
|
//
|
|
|
|
for (int i = 5; i >= 0; i--) {
|
|
|
|
char sixBits = (thirtysix >> (i * 6)) & 077;
|
|
|
|
sk_write(supdup->s, &sixBits, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_send_config(Supdup *supdup)
|
|
|
|
{
|
|
|
|
supdup_send_36bits(supdup, WORDS); // negative length
|
|
|
|
supdup_send_36bits(supdup, TCTYP); // terminal type
|
|
|
|
supdup_send_36bits(supdup, supdup->ttyopt); // options
|
|
|
|
supdup_send_36bits(supdup, supdup->tcmxv); // height
|
|
|
|
supdup_send_36bits(supdup, supdup->tcmxh); // width
|
|
|
|
supdup_send_36bits(supdup, TTYROL); // scroll amount
|
|
|
|
}
|
|
|
|
|
Introduce a new 'Interactor' trait.
This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.
To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.
I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.
The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
2021-10-30 16:16:08 +00:00
|
|
|
static char *supdup_description(Interactor *itr)
|
Add 'description' methods for Backend and Plug.
These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.
Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.
The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.
Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"
In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
2021-10-24 08:18:12 +00:00
|
|
|
{
|
Introduce a new 'Interactor' trait.
This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.
To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.
I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.
The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
2021-10-30 16:16:08 +00:00
|
|
|
Supdup *supdup = container_of(itr, Supdup, interactor);
|
Add 'description' methods for Backend and Plug.
These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.
Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.
The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.
Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"
In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
2021-10-24 08:18:12 +00:00
|
|
|
return dupstr(supdup->description);
|
|
|
|
}
|
|
|
|
|
2021-10-30 16:34:53 +00:00
|
|
|
static LogPolicy *supdup_logpolicy(Interactor *itr)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(itr, Supdup, interactor);
|
|
|
|
return log_get_policy(supdup->logctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Seat *supdup_get_seat(Interactor *itr)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(itr, Supdup, interactor);
|
|
|
|
return supdup->seat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_set_seat(Interactor *itr, Seat *seat)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(itr, Supdup, interactor);
|
|
|
|
supdup->seat = seat;
|
|
|
|
}
|
|
|
|
|
Introduce a new 'Interactor' trait.
This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.
To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.
I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.
The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
2021-10-30 16:16:08 +00:00
|
|
|
static const InteractorVtable Supdup_interactorvt = {
|
|
|
|
.description = supdup_description,
|
2021-10-30 16:34:53 +00:00
|
|
|
.logpolicy = supdup_logpolicy,
|
|
|
|
.get_seat = supdup_get_seat,
|
|
|
|
.set_seat = supdup_set_seat,
|
Introduce a new 'Interactor' trait.
This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.
To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.
I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.
The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
2021-10-30 16:16:08 +00:00
|
|
|
};
|
Add 'description' methods for Backend and Plug.
These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.
Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.
The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.
Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"
In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
2021-10-24 08:18:12 +00:00
|
|
|
|
2019-04-02 10:16:25 +00:00
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Called to set up the Supdup connection.
|
|
|
|
*
|
|
|
|
* Returns an error message, or NULL on success.
|
|
|
|
*
|
|
|
|
* Also places the canonical host name into `realhost'. It must be
|
|
|
|
* freed by the caller.
|
|
|
|
*/
|
2020-04-18 12:28:33 +00:00
|
|
|
static char *supdup_init(const BackendVtable *x, Seat *seat,
|
|
|
|
Backend **backend_handle,
|
|
|
|
LogContext *logctx, Conf *conf,
|
|
|
|
const char *host, int port, char **realhost,
|
|
|
|
bool nodelay, bool keepalive)
|
2019-04-02 10:16:25 +00:00
|
|
|
{
|
|
|
|
static const PlugVtable fn_table = {
|
Change vtable defs to use C99 designated initialisers.
This is a sweeping change applied across the whole code base by a spot
of Emacs Lisp. Now, everywhere I declare a vtable filled with function
pointers (and the occasional const data member), all the members of
the vtable structure are initialised by name using the '.fieldname =
value' syntax introduced in C99.
We were already using this syntax for a handful of things in the new
key-generation progress report system, so it's not new to the code
base as a whole.
The advantage is that now, when a vtable only declares a subset of the
available fields, I can initialise the rest to NULL or zero just by
leaving them out. This is most dramatic in a couple of the outlying
vtables in things like psocks (which has a ConnectionLayerVtable
containing only one non-NULL method), but less dramatically, it means
that the new 'flags' field in BackendVtable can be completely left out
of every backend definition except for the SUPDUP one which defines it
to a nonzero value. Similarly, the test_for_upstream method only used
by SSH doesn't have to be mentioned in the rest of the backends;
network Plugs for listening sockets don't have to explicitly null out
'receive' and 'sent', and vice versa for 'accepting', and so on.
While I'm at it, I've normalised the declarations so they don't use
the unnecessarily verbose 'struct' keyword. Also a handful of them
weren't const; now they are.
2020-03-10 21:06:29 +00:00
|
|
|
.log = supdup_log,
|
|
|
|
.closing = supdup_closing,
|
|
|
|
.receive = supdup_receive,
|
|
|
|
.sent = supdup_sent,
|
2019-04-02 10:16:25 +00:00
|
|
|
};
|
|
|
|
SockAddr *addr;
|
|
|
|
const char *err;
|
|
|
|
Supdup *supdup;
|
|
|
|
char *loghost;
|
|
|
|
int addressfamily;
|
|
|
|
const char *utf8 = "\033%G";
|
|
|
|
|
|
|
|
supdup = snew(struct supdup_tag);
|
2021-10-30 13:51:24 +00:00
|
|
|
memset(supdup, 0, sizeof(Supdup));
|
2019-04-02 10:16:25 +00:00
|
|
|
supdup->plug.vt = &fn_table;
|
|
|
|
supdup->backend.vt = &supdup_backend;
|
Introduce a new 'Interactor' trait.
This trait will be implemented by anything that wants to display
interactive prompts or notifications to the user in the course of
setting up a network connection, _or_ anything that wants to make a
network connection whose proxy setup might in turn need to do that.
To begin with, that means every Backend that makes network connections
at all must be an Interactor, because any of those network connections
might be proxied via an SSH jump host which might need to interact
with the user.
I'll fill in the contents of this trait over the next few commits, to
keep the patches comprehensible. For the moment, I've just introduced
the trait, set up implementations of it in the five network backends,
and given it a single 'description' method.
The previous 'description' methods of Backend and Plug are now
removed, and their work is done by the new Interactor method instead.
(I changed my mind since last week about where that should best live.)
This isn't too much of an upheaval, fortunately, because I hadn't got
round yet to committing anything that used those methods!
2021-10-30 16:16:08 +00:00
|
|
|
supdup->interactor.vt = &Supdup_interactorvt;
|
|
|
|
supdup->backend.interactor = &supdup->interactor;
|
2019-04-02 10:16:25 +00:00
|
|
|
supdup->logctx = logctx;
|
|
|
|
supdup->conf = conf_copy(conf);
|
|
|
|
supdup->s = NULL;
|
2021-09-13 11:00:01 +00:00
|
|
|
supdup->socket_connected = false;
|
2019-04-02 10:16:25 +00:00
|
|
|
supdup->closed_on_socket_error = false;
|
|
|
|
supdup->seat = seat;
|
|
|
|
supdup->term_width = conf_get_int(supdup->conf, CONF_width);
|
|
|
|
supdup->term_height = conf_get_int(supdup->conf, CONF_height);
|
|
|
|
supdup->pinger = NULL;
|
|
|
|
supdup->sent_location = false;
|
Add 'description' methods for Backend and Plug.
These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.
Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.
The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.
Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"
In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
2021-10-24 08:18:12 +00:00
|
|
|
supdup->description = default_description(supdup->backend.vt, host, port);
|
2019-04-02 10:16:25 +00:00
|
|
|
*backend_handle = &supdup->backend;
|
|
|
|
|
|
|
|
switch (conf_get_int(supdup->conf, CONF_supdup_ascii_set)) {
|
2022-08-03 19:48:46 +00:00
|
|
|
case SUPDUP_CHARSET_ASCII:
|
|
|
|
supdup->print = print_ascii;
|
|
|
|
break;
|
|
|
|
case SUPDUP_CHARSET_ITS:
|
|
|
|
supdup->print = print_its;
|
|
|
|
break;
|
|
|
|
case SUPDUP_CHARSET_WAITS:
|
|
|
|
supdup->print = print_waits;
|
|
|
|
break;
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find host.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
addressfamily = conf_get_int(supdup->conf, CONF_addressfamily);
|
|
|
|
buf = dupprintf("Looking up host \"%s\"%s", host,
|
|
|
|
(addressfamily == ADDRTYPE_IPV4 ? " (IPv4)" :
|
|
|
|
(addressfamily == ADDRTYPE_IPV6 ? " (IPv6)" :
|
|
|
|
"")));
|
|
|
|
logevent(supdup->logctx, buf);
|
|
|
|
sfree(buf);
|
|
|
|
}
|
|
|
|
addr = name_lookup(host, port, realhost, supdup->conf, addressfamily, NULL, "");
|
|
|
|
if ((err = sk_addr_error(addr)) != NULL) {
|
|
|
|
sk_addr_free(addr);
|
2020-04-18 12:28:33 +00:00
|
|
|
return dupstr(err);
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (port < 0)
|
|
|
|
port = 0137; /* default supdup port */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open socket.
|
|
|
|
*/
|
|
|
|
supdup->s = new_connection(addr, *realhost, port, false, true,
|
2021-09-13 16:17:20 +00:00
|
|
|
nodelay, keepalive, &supdup->plug, supdup->conf,
|
2021-10-30 16:36:52 +00:00
|
|
|
&supdup->interactor);
|
2019-04-02 10:16:25 +00:00
|
|
|
if ((err = sk_socket_error(supdup->s)) != NULL)
|
2020-04-18 12:28:33 +00:00
|
|
|
return dupstr(err);
|
2019-04-02 10:16:25 +00:00
|
|
|
|
|
|
|
supdup->pinger = pinger_new(supdup->conf, &supdup->backend);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can send special commands from the start.
|
|
|
|
*/
|
|
|
|
seat_update_specials_menu(supdup->seat);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loghost overrides realhost, if specified.
|
|
|
|
*/
|
|
|
|
loghost = conf_get_str(supdup->conf, CONF_loghost);
|
|
|
|
if (*loghost) {
|
|
|
|
char *colon;
|
|
|
|
|
|
|
|
sfree(*realhost);
|
|
|
|
*realhost = dupstr(loghost);
|
|
|
|
|
|
|
|
colon = host_strrchr(*realhost, ':');
|
|
|
|
if (colon)
|
|
|
|
*colon++ = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up TTYOPTS based on config
|
|
|
|
*/
|
|
|
|
int ascii_set = conf_get_int(supdup->conf, CONF_supdup_ascii_set);
|
|
|
|
int more_processing = conf_get_bool(supdup->conf, CONF_supdup_more);
|
|
|
|
int scrolling = conf_get_bool(supdup->conf, CONF_supdup_scroll);
|
|
|
|
supdup->ttyopt =
|
|
|
|
TOERS |
|
|
|
|
TOMVB |
|
|
|
|
(ascii_set == SUPDUP_CHARSET_ASCII ? 0 : TOSAI | TOSA1) |
|
|
|
|
TOMVU |
|
|
|
|
TOLWR |
|
|
|
|
TOLID |
|
|
|
|
TOCID |
|
|
|
|
TPCBS |
|
|
|
|
(scrolling ? TOROL : 0) |
|
|
|
|
(more_processing ? TOMOR : 0) |
|
|
|
|
TPORS;
|
|
|
|
|
|
|
|
supdup->tcmxh = supdup->term_width - 1; // -1 "..one column is used to indicate line continuation."
|
|
|
|
supdup->tcmxv = supdup->term_height;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send our configuration words to the server
|
|
|
|
*/
|
|
|
|
supdup_send_config(supdup);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We next expect a connection message followed by %TDNOP from the server
|
|
|
|
*/
|
|
|
|
supdup->state = CONNECTING;
|
|
|
|
seat_set_trust_status(supdup->seat, false);
|
|
|
|
|
|
|
|
/* Make sure the terminal is in UTF-8 mode. */
|
|
|
|
c_write(supdup, (unsigned char *)utf8, strlen(utf8));
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void supdup_free(Backend *be)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
|
Allow new_connection to take an optional Seat. (NFC)
This is working towards allowing the subsidiary SSH connection in an
SshProxy to share the main user-facing Seat, so as to be able to pass
through interactive prompts.
This is more difficult than the similar change with LogPolicy, because
Seats are stateful. In particular, the trust-sigil status will need to
be controlled by the SshProxy until it's ready to pass over control to
the main SSH (or whatever) connection.
To make this work, I've introduced a thing called a TempSeat, which is
(yet) another Seat implementation. When a backend hands its Seat to
new_connection(), it does it in a way that allows new_connection() to
borrow it completely, and replace it in the main backend structure
with a TempSeat, which acts as a temporary placeholder. If the main
backend tries to do things like changing trust status or sending
output, the TempSeat will buffer them; later on, when the connection
is established, TempSeat will replay the changes into the real Seat.
So, in each backend, I've made the following changes:
- pass &foo->seat to new_connection, which may overwrite it with a
TempSeat.
- if it has done so (which we can tell via the is_tempseat() query
function), then we have to free the TempSeat and reinstate our main
Seat. The signal that we can do so is the PLUGLOG_CONNECT_SUCCESS
notification, which indicates that SshProxy has finished all its
connection setup work.
- we also have to remember to free the TempSeat if our backend is
disposed of without that having happened (e.g. because the
connection _doesn't_ succeed).
- in backends which have no local auth phase to worry about, ensure
we don't call seat_set_trust_status on the main Seat _before_ it
gets potentially replaced with a TempSeat. Moved some calls of
seat_set_trust_status to just after new_connection(), so that now
the initial trust status setup will go into the TempSeat (if
appropriate) and be buffered until that seat is relinquished.
In all other uses of new_connection, where we don't have a Seat
available at all, we just pass NULL.
This is NFC, because neither new_connection() nor any of its delegates
will _actually_ do this replacement yet. We're just setting up the
framework to enable it to do so in the next commit.
2021-09-13 16:17:20 +00:00
|
|
|
if (is_tempseat(supdup->seat))
|
|
|
|
tempseat_free(supdup->seat);
|
2019-04-02 10:16:25 +00:00
|
|
|
if (supdup->s)
|
|
|
|
sk_close(supdup->s);
|
|
|
|
if (supdup->pinger)
|
|
|
|
pinger_free(supdup->pinger);
|
|
|
|
conf_free(supdup->conf);
|
Add 'description' methods for Backend and Plug.
These will typically be implemented by objects that are both a Backend
*and* a Plug, and the two methods will deliver the same results to any
caller, regardless of which facet of the object is known to that
caller.
Their purpose is to deliver a user-oriented natural-language
description of what network connection the object is handling, so that
it can appear in diagnostic messages.
The messages I specifically have in mind are going to appear in cases
where proxies require interactive authentication: when PuTTY prompts
interactively for a password, it will need to explain which *thing*
it's asking for the password for, and these descriptions are what it
will use to describe the thing in question.
Each backend is allowed to compose these messages however it thinks
best. In all cases at present, the description string is constructed
by the new centralised default_description() function, which takes a
host name and port number and combines them with the backend's display
name. But the SSH backend does things a bit differently, because it
uses the _logical_ host name (the one that goes with the SSH host key)
rather than the physical destination of the network connection. That
seems more appropriate when the question it's really helping the user
to answer is "What host am I supposed to be entering the password for?"
In this commit, no clients of the new methods are introduced. I have a
draft implementation of actually using it for the purpose I describe
above, but it needs polishing.
2021-10-24 08:18:12 +00:00
|
|
|
sfree(supdup->description);
|
2019-04-02 10:16:25 +00:00
|
|
|
sfree(supdup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Reconfigure the Supdup backend.
|
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
static void supdup_reconfig(Backend *be, Conf *conf)
|
|
|
|
{
|
|
|
|
/* Nothing to do; SUPDUP cannot be reconfigured while running. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Called to send data down the Supdup connection.
|
|
|
|
*/
|
2021-09-12 08:52:46 +00:00
|
|
|
static void supdup_send(Backend *be, const char *buf, size_t len)
|
2019-04-02 10:16:25 +00:00
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
char c;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (supdup->s == NULL)
|
2021-09-12 08:52:46 +00:00
|
|
|
return;
|
2019-04-02 10:16:25 +00:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (buf[i] == 034)
|
|
|
|
supdup->bufsize = sk_write(supdup->s, "\034\034", 2);
|
|
|
|
else {
|
|
|
|
c = buf[i] & 0177;
|
|
|
|
supdup->bufsize = sk_write(supdup->s, &c, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Called to query the current socket sendability status.
|
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
static size_t supdup_sendbuffer(Backend *be)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
return supdup->bufsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Called to set the size of the window from Supdup's POV.
|
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
static void supdup_size(Backend *be, int width, int height)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
|
|
|
|
supdup->term_width = width;
|
|
|
|
supdup->term_height = height;
|
|
|
|
|
|
|
|
//
|
|
|
|
// SUPDUP does not support resizing the terminal after connection
|
|
|
|
// establishment.
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* Send Telnet special codes.
|
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
static void supdup_special(Backend *be, SessionSpecialCode code, int arg)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SessionSpecial *supdup_get_specials(Backend *be)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool supdup_connected(Backend *be)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
return supdup->s != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool supdup_sendok(Backend *be)
|
|
|
|
{
|
2021-09-13 11:00:01 +00:00
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
return supdup->socket_connected;
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_unthrottle(Backend *be, size_t backlog)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
sk_set_frozen(supdup->s, backlog > SUPDUP_MAX_BACKLOG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool supdup_ldisc(Backend *be, int option)
|
|
|
|
{
|
|
|
|
/* No support for echoing or local editing. */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void supdup_provide_ldisc(Backend *be, Ldisc *ldisc)
|
|
|
|
{
|
2021-09-14 09:13:28 +00:00
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
supdup->ldisc = ldisc;
|
2019-04-02 10:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int supdup_exitcode(Backend *be)
|
|
|
|
{
|
|
|
|
Supdup *supdup = container_of(be, Supdup, backend);
|
|
|
|
if (supdup->s != NULL)
|
|
|
|
return -1; /* still connected */
|
|
|
|
else if (supdup->closed_on_socket_error)
|
|
|
|
return INT_MAX; /* a socket error counts as an unclean exit */
|
|
|
|
else
|
|
|
|
/* Supdup doesn't transmit exit codes back to the client */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-08-03 19:48:46 +00:00
|
|
|
* cfg_info for Supdup does nothing at all.
|
2022-08-03 19:48:46 +00:00
|
|
|
*/
|
2019-04-02 10:16:25 +00:00
|
|
|
static int supdup_cfg_info(Backend *be)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Change vtable defs to use C99 designated initialisers.
This is a sweeping change applied across the whole code base by a spot
of Emacs Lisp. Now, everywhere I declare a vtable filled with function
pointers (and the occasional const data member), all the members of
the vtable structure are initialised by name using the '.fieldname =
value' syntax introduced in C99.
We were already using this syntax for a handful of things in the new
key-generation progress report system, so it's not new to the code
base as a whole.
The advantage is that now, when a vtable only declares a subset of the
available fields, I can initialise the rest to NULL or zero just by
leaving them out. This is most dramatic in a couple of the outlying
vtables in things like psocks (which has a ConnectionLayerVtable
containing only one non-NULL method), but less dramatically, it means
that the new 'flags' field in BackendVtable can be completely left out
of every backend definition except for the SUPDUP one which defines it
to a nonzero value. Similarly, the test_for_upstream method only used
by SSH doesn't have to be mentioned in the rest of the backends;
network Plugs for listening sockets don't have to explicitly null out
'receive' and 'sent', and vice versa for 'accepting', and so on.
While I'm at it, I've normalised the declarations so they don't use
the unnecessarily verbose 'struct' keyword. Also a handful of them
weren't const; now they are.
2020-03-10 21:06:29 +00:00
|
|
|
const BackendVtable supdup_backend = {
|
|
|
|
.init = supdup_init,
|
|
|
|
.free = supdup_free,
|
|
|
|
.reconfig = supdup_reconfig,
|
|
|
|
.send = supdup_send,
|
|
|
|
.sendbuffer = supdup_sendbuffer,
|
|
|
|
.size = supdup_size,
|
|
|
|
.special = supdup_special,
|
|
|
|
.get_specials = supdup_get_specials,
|
|
|
|
.connected = supdup_connected,
|
|
|
|
.exitcode = supdup_exitcode,
|
|
|
|
.sendok = supdup_sendok,
|
|
|
|
.ldisc_option_state = supdup_ldisc,
|
|
|
|
.provide_ldisc = supdup_provide_ldisc,
|
|
|
|
.unthrottle = supdup_unthrottle,
|
|
|
|
.cfg_info = supdup_cfg_info,
|
|
|
|
.id = "supdup",
|
2021-10-23 17:26:34 +00:00
|
|
|
.displayname_tc = "SUPDUP",
|
|
|
|
.displayname_lc = "SUPDUP", /* proper name, so capitalise it anyway */
|
Change vtable defs to use C99 designated initialisers.
This is a sweeping change applied across the whole code base by a spot
of Emacs Lisp. Now, everywhere I declare a vtable filled with function
pointers (and the occasional const data member), all the members of
the vtable structure are initialised by name using the '.fieldname =
value' syntax introduced in C99.
We were already using this syntax for a handful of things in the new
key-generation progress report system, so it's not new to the code
base as a whole.
The advantage is that now, when a vtable only declares a subset of the
available fields, I can initialise the rest to NULL or zero just by
leaving them out. This is most dramatic in a couple of the outlying
vtables in things like psocks (which has a ConnectionLayerVtable
containing only one non-NULL method), but less dramatically, it means
that the new 'flags' field in BackendVtable can be completely left out
of every backend definition except for the SUPDUP one which defines it
to a nonzero value. Similarly, the test_for_upstream method only used
by SSH doesn't have to be mentioned in the rest of the backends;
network Plugs for listening sockets don't have to explicitly null out
'receive' and 'sent', and vice versa for 'accepting', and so on.
While I'm at it, I've normalised the declarations so they don't use
the unnecessarily verbose 'struct' keyword. Also a handful of them
weren't const; now they are.
2020-03-10 21:06:29 +00:00
|
|
|
.protocol = PROT_SUPDUP,
|
|
|
|
.default_port = 0137,
|
|
|
|
.flags = BACKEND_RESIZE_FORBIDDEN | BACKEND_NEEDS_TERMINAL,
|
2019-04-02 10:16:25 +00:00
|
|
|
};
|