2002-11-19 12:29:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 Simon Tatham
|
|
|
|
* Copyright (c) 1999 Ben Harris
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use,
|
|
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
* sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following
|
|
|
|
* conditions:
|
2019-09-08 19:29:00 +00:00
|
|
|
*
|
2002-11-19 12:29:45 +00:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2019-09-08 19:29:00 +00:00
|
|
|
*
|
2002-11-19 12:29:45 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
|
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* PuTTY test backends */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
|
2020-04-18 12:28:33 +00:00
|
|
|
static char *null_init(const BackendVtable *, Seat *, Backend **, LogContext *,
|
|
|
|
Conf *, const char *, int, char **, bool, bool);
|
|
|
|
static char *loop_init(const BackendVtable *, Seat *, Backend **, LogContext *,
|
|
|
|
Conf *, const char *, int, char **, bool, bool);
|
2018-09-11 15:23:38 +00:00
|
|
|
static void null_free(Backend *);
|
|
|
|
static void loop_free(Backend *);
|
|
|
|
static void null_reconfig(Backend *, Conf *);
|
2019-02-06 20:42:44 +00:00
|
|
|
static size_t null_send(Backend *, const char *, size_t);
|
|
|
|
static size_t loop_send(Backend *, const char *, size_t);
|
|
|
|
static size_t null_sendbuffer(Backend *);
|
2018-09-11 15:23:38 +00:00
|
|
|
static void null_size(Backend *, int, int);
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static void null_special(Backend *, SessionSpecialCode, int);
|
|
|
|
static const SessionSpecial *null_get_specials(Backend *);
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_connected(Backend *);
|
|
|
|
static int null_exitcode(Backend *);
|
|
|
|
static int null_sendok(Backend *);
|
|
|
|
static int null_ldisc(Backend *, int);
|
|
|
|
static void null_provide_ldisc(Backend *, Ldisc *);
|
2019-02-06 20:42:44 +00:00
|
|
|
static void null_unthrottle(Backend *, size_t);
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_cfg_info(Backend *);
|
|
|
|
|
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 null_backend = {
|
|
|
|
.init = null_init,
|
|
|
|
.free = null_free,
|
|
|
|
.reconfig = null_reconfig,
|
|
|
|
.send = null_send,
|
|
|
|
.sendbuffer = null_sendbuffer,
|
|
|
|
.size = null_size,
|
|
|
|
.special = null_special,
|
|
|
|
.get_specials = null_get_specials,
|
|
|
|
.connected = null_connected,
|
|
|
|
.exitcode = null_exitcode,
|
|
|
|
.sendok = null_sendok,
|
|
|
|
.ldisc_option_state = null_ldisc,
|
|
|
|
.provide_ldisc = null_provide_ldisc,
|
|
|
|
.unthrottle = null_unthrottle,
|
|
|
|
.cfg_info = null_cfg_info,
|
|
|
|
.id = "null",
|
|
|
|
.displayname = "null",
|
|
|
|
.protocol = -1,
|
|
|
|
.default_port = 0,
|
2002-11-19 12:29:45 +00:00
|
|
|
};
|
|
|
|
|
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 loop_backend = {
|
|
|
|
.init = loop_init,
|
|
|
|
.free = loop_free,
|
|
|
|
.reconfig = null_reconfig,
|
|
|
|
.send = loop_send,
|
|
|
|
.sendbuffer = null_sendbuffer,
|
|
|
|
.size = null_size,
|
|
|
|
.special = null_special,
|
|
|
|
.get_specials = null_get_specials,
|
|
|
|
.connected = null_connected,
|
|
|
|
.exitcode = null_exitcode,
|
|
|
|
.sendok = null_sendok,
|
|
|
|
.ldisc_option_state = null_ldisc,
|
|
|
|
.provide_ldisc = null_provide_ldisc,
|
|
|
|
.unthrottle = null_unthrottle,
|
|
|
|
.cfg_info = null_cfg_info,
|
|
|
|
.id = "loop",
|
|
|
|
.displayname = "loop",
|
|
|
|
.protocol = -1,
|
|
|
|
.default_port = 0,
|
2002-11-19 12:29:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct loop_state {
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 18:58:42 +00:00
|
|
|
Seat *seat;
|
2018-09-11 15:23:38 +00:00
|
|
|
Backend backend;
|
2002-11-19 12:29:45 +00:00
|
|
|
};
|
|
|
|
|
2020-04-18 12:28:33 +00:00
|
|
|
static char *null_init(const BackendVtable *vt, Seat *seat,
|
|
|
|
Backend **backend_handle, LogContext *logctx,
|
|
|
|
Conf *conf, const char *host, int port,
|
|
|
|
char **realhost, bool nodelay, bool keepalive) {
|
2019-03-10 14:42:11 +00:00
|
|
|
/* No local authentication phase in this protocol */
|
|
|
|
seat_set_trust_status(seat, false);
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
*backend_handle = NULL;
|
2002-11-19 12:29:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-18 12:28:33 +00:00
|
|
|
static char *loop_init(const BackendVtable *vt, Seat *seat,
|
|
|
|
Backend **backend_handle, LogContext *logctx,
|
|
|
|
Conf *conf, const char *host, int port,
|
|
|
|
char **realhost, bool nodelay, bool keepalive) {
|
2003-03-29 16:14:26 +00:00
|
|
|
struct loop_state *st = snew(struct loop_state);
|
2002-11-19 12:29:45 +00:00
|
|
|
|
2019-03-10 14:42:11 +00:00
|
|
|
/* No local authentication phase in this protocol */
|
|
|
|
seat_set_trust_status(seat, false);
|
|
|
|
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 18:58:42 +00:00
|
|
|
st->seat = seat;
|
2018-09-11 15:23:38 +00:00
|
|
|
*backend_handle = &st->backend;
|
2002-11-23 19:58:55 +00:00
|
|
|
return NULL;
|
2002-11-19 12:29:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void null_free(Backend *be)
|
2003-01-15 23:30:21 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void loop_free(Backend *be)
|
2003-01-15 23:30:21 +00:00
|
|
|
{
|
2018-10-05 22:49:08 +00:00
|
|
|
struct loop_state *st = container_of(be, struct loop_state, backend);
|
2003-01-15 23:30:21 +00:00
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
sfree(st);
|
2003-01-15 23:30:21 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void null_reconfig(Backend *be, Conf *conf) {
|
2003-01-12 16:11:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-02-06 20:42:44 +00:00
|
|
|
static size_t null_send(Backend *be, const char *buf, size_t len) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-06 20:42:44 +00:00
|
|
|
static size_t loop_send(Backend *be, const char *buf, size_t len) {
|
2018-10-05 22:49:08 +00:00
|
|
|
struct loop_state *st = container_of(be, struct loop_state, backend);
|
2002-11-19 12:29:45 +00:00
|
|
|
|
New abstraction 'Seat', to pass to backends.
This is a new vtable-based abstraction which is passed to a backend in
place of Frontend, and it implements only the subset of the Frontend
functions needed by a backend. (Many other Frontend functions still
exist, notably the wide range of things called by terminal.c providing
platform-independent operations on the GUI terminal window.)
The purpose of making it a vtable is that this opens up the
possibility of creating a backend as an internal implementation detail
of some other activity, by providing just that one backend with a
custom Seat that implements the methods differently.
For example, this refactoring should make it feasible to directly
implement an SSH proxy type, aka the 'jump host' feature supported by
OpenSSH, aka 'open a secondary SSH session in MAINCHAN_DIRECT_TCP
mode, and then expose the main channel of that as the Socket for the
primary connection'. (Which of course you can already do by spawning
'plink -nc' as a separate proxy process, but this would permit it in
the _same_ process without anything getting confused.)
I've centralised a full set of stub methods in misc.c for the new
abstraction, which allows me to get rid of several annoying stubs in
the previous code. Also, while I'm here, I've moved a lot of
duplicated modalfatalbox() type functions from application main
program files into wincons.c / uxcons.c, which I think saves
duplication overall. (A minor visible effect is that the prefixes on
those console-based fatal error messages will now be more consistent
between applications.)
2018-10-11 18:58:42 +00:00
|
|
|
return seat_output(st->seat, 0, buf, len);
|
2002-11-19 12:29:45 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 20:42:44 +00:00
|
|
|
static size_t null_sendbuffer(Backend *be) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void null_size(Backend *be, int width, int height) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static void null_special(Backend *be, SessionSpecialCode code, int arg) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
Rework special-commands system to add an integer argument.
In order to list cross-certifiable host keys in the GUI specials menu,
the SSH backend has been inventing new values on the end of the
Telnet_Special enumeration, starting from the value TS_LOCALSTART.
This is inelegant, and also makes it awkward to break up special
handlers (e.g. to dispatch different specials to different SSH
layers), since if all you know about a special is that it's somewhere
in the TS_LOCALSTART+n space, you can't tell what _general kind_ of
thing it is. Also, if I ever need another open-ended set of specials
in future, I'll have to remember which TS_LOCALSTART+n codes are in
which set.
So here's a revamp that causes every special to take an extra integer
argument. For all previously numbered specials, this argument is
passed as zero and ignored, but there's a new main special code for
SSH host key cross-certification, in which the integer argument is an
index into the backend's list of available keys. TS_LOCALSTART is now
a thing of the past: if I need any other open-ended sets of specials
in future, I can add a new top-level code with a nicely separated
space of arguments.
While I'm at it, I've removed the legacy misnomer 'Telnet_Special'
from the code completely; the enum is now SessionSpecialCode, the
struct containing full details of a menu entry is SessionSpecial, and
the enum values now start SS_ rather than TS_.
2018-09-24 08:35:52 +00:00
|
|
|
static const SessionSpecial *null_get_specials (Backend *be) {
|
2003-04-05 14:32:58 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_connected(Backend *be) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
2007-02-18 15:59:38 +00:00
|
|
|
return 0;
|
2002-11-19 12:29:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_exitcode(Backend *be) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_sendok(Backend *be) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-06 20:42:44 +00:00
|
|
|
static void null_unthrottle(Backend *be, size_t backlog) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_ldisc(Backend *be, int option) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static void null_provide_ldisc (Backend *be, Ldisc *ldisc) {
|
2002-11-19 12:29:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-11 15:23:38 +00:00
|
|
|
static int null_cfg_info(Backend *be)
|
2004-12-29 12:32:25 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-19 12:29:45 +00:00
|
|
|
/*
|
|
|
|
* Emacs magic:
|
|
|
|
* Local Variables:
|
|
|
|
* c-file-style: "simon"
|
|
|
|
* End:
|
|
|
|
*/
|