1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Pass the Ssh structure to portfwd.c with a tag.

Again, safer than using a 'void *'.
This commit is contained in:
Simon Tatham 2018-09-11 15:33:10 +01:00
parent 3814a5cee8
commit c51fe7c217
4 changed files with 13 additions and 14 deletions

1
defs.h
View File

@ -47,6 +47,7 @@ typedef struct Plug_vtable Plug_vtable;
typedef struct Ldisc_tag Ldisc; typedef struct Ldisc_tag Ldisc;
typedef struct LogContext_tag LogContext; typedef struct LogContext_tag LogContext;
typedef struct ssh_tag *Ssh;
/* Note indirection: for historical reasons (it used to be closer to /* 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 * the OS socket type), the type that most code uses for a socket is
* 'Socket', not 'Socket *'. So an implementation of Socket or Plug * 'Socket', not 'Socket *'. So an implementation of Socket or Plug

View File

@ -23,8 +23,8 @@ typedef enum {
struct PortForwarding { struct PortForwarding {
struct ssh_channel *c; /* channel structure held by ssh.c */ struct ssh_channel *c; /* channel structure held by ssh.c */
void *backhandle; /* instance of SSH backend itself */ Ssh ssh; /* instance of SSH backend itself */
/* Note that backhandle need not be filled in if c is non-NULL */ /* Note that ssh need not be filled in if c is non-NULL */
Socket s; Socket s;
int throttled, throttle_override; int throttled, throttle_override;
int ready; int ready;
@ -47,7 +47,7 @@ struct PortForwarding {
}; };
struct PortListener { struct PortListener {
void *backhandle; /* instance of SSH backend itself */ Ssh ssh; /* instance of SSH backend itself */
Socket s; Socket s;
int is_dynamic; 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); 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) { if (pf->c == NULL) {
pfd_close(pf); pfd_close(pf);
return; return;
@ -464,7 +464,7 @@ char *pfd_connect(struct PortForwarding **pf_ret, char *hostname,int port,
pf->throttled = pf->throttle_override = 0; pf->throttled = pf->throttle_override = 0;
pf->ready = 1; pf->ready = 1;
pf->c = c; 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->socks_state = SOCKS_NONE;
pf->s = new_connection(addr, dummy_realhost, port, 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->plugvt = &PortForwarding_plugvt;
pf->c = NULL; pf->c = NULL;
pf->backhandle = pl->backhandle; pf->ssh = pl->ssh;
pf->s = s = constructor(ctx, &pf->plugvt); pf->s = s = constructor(ctx, &pf->plugvt);
if ((err = sk_socket_error(s)) != NULL) { 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->socks_state = SOCKS_NONE;
pf->hostname = dupstr(pl->hostname); pf->hostname = dupstr(pl->hostname);
pf->port = pl->port; pf->port = pl->port;
pf->c = new_sock_channel(pl->backhandle, pf); pf->c = new_sock_channel(pl->ssh, pf);
if (pf->c == NULL) { if (pf->c == NULL) {
free_portfwd_state(pf); free_portfwd_state(pf);
@ -547,7 +547,7 @@ static const Plug_vtable PortListener_plugvt = {
* dynamically allocated error message string. * dynamically allocated error message string.
*/ */
char *pfl_listen(char *desthost, int destport, char *srcaddr, 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) struct PortListener **pl_ret, int address_family)
{ {
const char *err; const char *err;
@ -564,7 +564,7 @@ char *pfl_listen(char *desthost, int destport, char *srcaddr,
pl->is_dynamic = FALSE; pl->is_dynamic = FALSE;
} else } else
pl->is_dynamic = TRUE; pl->is_dynamic = TRUE;
pl->backhandle = backhandle; pl->ssh = ssh;
pl->s = new_listener(srcaddr, port, &pl->plugvt, pl->s = new_listener(srcaddr, port, &pl->plugvt,
!conf_get_int(conf, CONF_lport_acceptall), !conf_get_int(conf, CONF_lport_acceptall),

3
ssh.c
View File

@ -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; struct ssh_channel *c;
c = snew(struct ssh_channel); c = snew(struct ssh_channel);

5
ssh.h
View File

@ -8,7 +8,6 @@
#include "misc.h" #include "misc.h"
struct ssh_channel; struct ssh_channel;
typedef struct ssh_tag *Ssh;
extern int sshfwd_write(struct ssh_channel *c, const void *, int); extern int sshfwd_write(struct ssh_channel *c, const void *, int);
extern void sshfwd_write_eof(struct ssh_channel *c); extern void sshfwd_write_eof(struct ssh_channel *c);
@ -666,7 +665,7 @@ void logevent(void *, const char *);
struct PortForwarding; struct PortForwarding;
/* Allocate and register a new channel for port forwarding */ /* 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, void ssh_send_port_open(void *channel, const char *hostname, int port,
const char *org); const char *org);
@ -682,7 +681,7 @@ extern void pfd_override_throttle(struct PortForwarding *, int enable);
struct PortListener; struct PortListener;
/* desthost == NULL indicates dynamic (SOCKS) port forwarding */ /* desthost == NULL indicates dynamic (SOCKS) port forwarding */
extern char *pfl_listen(char *desthost, int destport, char *srcaddr, 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); struct PortListener **pl, int address_family);
extern void pfl_terminate(struct PortListener *); extern void pfl_terminate(struct PortListener *);