From c51fe7c2171a8aa38e2246af22862f6f02d2b3d8 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 11 Sep 2018 15:33:10 +0100 Subject: [PATCH] Pass the Ssh structure to portfwd.c with a tag. Again, safer than using a 'void *'. --- defs.h | 1 + portfwd.c | 18 +++++++++--------- ssh.c | 3 +-- ssh.h | 5 ++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/defs.h b/defs.h index 45b56d60..58a4edff 100644 --- a/defs.h +++ b/defs.h @@ -47,6 +47,7 @@ typedef struct Plug_vtable Plug_vtable; typedef struct Ldisc_tag Ldisc; typedef struct LogContext_tag LogContext; +typedef struct ssh_tag *Ssh; /* Note indirection: for historical reasons (it used to be closer to * the OS socket type), the type that most code uses for a socket is * 'Socket', not 'Socket *'. So an implementation of Socket or Plug diff --git a/portfwd.c b/portfwd.c index 069bc3bf..e6b06e14 100644 --- a/portfwd.c +++ b/portfwd.c @@ -23,8 +23,8 @@ typedef enum { struct PortForwarding { struct ssh_channel *c; /* channel structure held by ssh.c */ - void *backhandle; /* instance of SSH backend itself */ - /* Note that backhandle need not be filled in if c is non-NULL */ + Ssh ssh; /* instance of SSH backend itself */ + /* Note that ssh need not be filled in if c is non-NULL */ Socket s; int throttled, throttle_override; int ready; @@ -47,7 +47,7 @@ struct PortForwarding { }; struct PortListener { - void *backhandle; /* instance of SSH backend itself */ + Ssh ssh; /* instance of SSH backend itself */ Socket s; int is_dynamic; /* @@ -396,7 +396,7 @@ static void pfd_receive(Plug plug, int urgent, char *data, int len) */ sk_set_frozen(pf->s, 1); - pf->c = new_sock_channel(pf->backhandle, pf); + pf->c = new_sock_channel(pf->ssh, pf); if (pf->c == NULL) { pfd_close(pf); return; @@ -464,7 +464,7 @@ char *pfd_connect(struct PortForwarding **pf_ret, char *hostname,int port, pf->throttled = pf->throttle_override = 0; pf->ready = 1; pf->c = c; - pf->backhandle = NULL; /* we shouldn't need this */ + pf->ssh = NULL; /* we shouldn't need this */ pf->socks_state = SOCKS_NONE; pf->s = new_connection(addr, dummy_realhost, port, @@ -497,7 +497,7 @@ static int pfl_accepting(Plug p, accept_fn_t constructor, accept_ctx_t ctx) pf->plugvt = &PortForwarding_plugvt; pf->c = NULL; - pf->backhandle = pl->backhandle; + pf->ssh = pl->ssh; pf->s = s = constructor(ctx, &pf->plugvt); if ((err = sk_socket_error(s)) != NULL) { @@ -518,7 +518,7 @@ static int pfl_accepting(Plug p, accept_fn_t constructor, accept_ctx_t ctx) pf->socks_state = SOCKS_NONE; pf->hostname = dupstr(pl->hostname); pf->port = pl->port; - pf->c = new_sock_channel(pl->backhandle, pf); + pf->c = new_sock_channel(pl->ssh, pf); if (pf->c == NULL) { free_portfwd_state(pf); @@ -547,7 +547,7 @@ static const Plug_vtable PortListener_plugvt = { * dynamically allocated error message string. */ char *pfl_listen(char *desthost, int destport, char *srcaddr, - int port, void *backhandle, Conf *conf, + int port, Ssh ssh, Conf *conf, struct PortListener **pl_ret, int address_family) { const char *err; @@ -564,7 +564,7 @@ char *pfl_listen(char *desthost, int destport, char *srcaddr, pl->is_dynamic = FALSE; } else pl->is_dynamic = TRUE; - pl->backhandle = backhandle; + pl->ssh = ssh; pl->s = new_listener(srcaddr, port, &pl->plugvt, !conf_get_int(conf, CONF_lport_acceptall), diff --git a/ssh.c b/ssh.c index 609e1155..1b75fb84 100644 --- a/ssh.c +++ b/ssh.c @@ -11293,9 +11293,8 @@ static void ssh_special(void *handle, Telnet_Special code) } } -void *new_sock_channel(void *handle, struct PortForwarding *pf) +void *new_sock_channel(Ssh ssh, struct PortForwarding *pf) { - Ssh ssh = (Ssh) handle; struct ssh_channel *c; c = snew(struct ssh_channel); diff --git a/ssh.h b/ssh.h index 99ff5b73..6c606abb 100644 --- a/ssh.h +++ b/ssh.h @@ -8,7 +8,6 @@ #include "misc.h" struct ssh_channel; -typedef struct ssh_tag *Ssh; extern int sshfwd_write(struct ssh_channel *c, const void *, int); extern void sshfwd_write_eof(struct ssh_channel *c); @@ -666,7 +665,7 @@ void logevent(void *, const char *); struct PortForwarding; /* Allocate and register a new channel for port forwarding */ -void *new_sock_channel(void *handle, struct PortForwarding *pf); +void *new_sock_channel(Ssh ssh, struct PortForwarding *pf); void ssh_send_port_open(void *channel, const char *hostname, int port, const char *org); @@ -682,7 +681,7 @@ extern void pfd_override_throttle(struct PortForwarding *, int enable); struct PortListener; /* desthost == NULL indicates dynamic (SOCKS) port forwarding */ extern char *pfl_listen(char *desthost, int destport, char *srcaddr, - int port, void *backhandle, Conf *conf, + int port, Ssh ssh, Conf *conf, struct PortListener **pl, int address_family); extern void pfl_terminate(struct PortListener *);