mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-04 04:52:47 -05:00
Log identifying information for the other end of connections.
When anyone connects to a PuTTY tool's listening socket - whether it's a user of a local->remote port forwarding, a connection-sharing downstream or a client of Pageant - we'd like to log as much information as we can find out about where the connection came from. To that end, I've implemented a function sk_peer_info() in the socket abstraction, which returns a freeform text string as best it can (or NULL, if it can't get anything at all) describing the thing at the other end of the connection. For TCP connections, this is done using getpeername() to get an IP address and port in the obvious way; for Unix-domain sockets, we attempt SO_PEERCRED (conditionalised on some moderately hairy autoconfery) to get the pid and owner of the peer. I haven't implemented anything for Windows named pipes, but I will if I hear of anything useful.
This commit is contained in:
19
portfwd.c
19
portfwd.c
@ -157,6 +157,21 @@ static int pfl_closing(Plug plug, const char *error_msg, int error_code,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void wrap_send_port_open(void *channel, const char *hostname, int port,
|
||||
Socket s)
|
||||
{
|
||||
char *peerinfo, *description;
|
||||
peerinfo = sk_peer_info(s);
|
||||
if (peerinfo) {
|
||||
description = dupprintf("forwarding from %s", peerinfo);
|
||||
sfree(peerinfo);
|
||||
} else {
|
||||
description = dupstr("forwarding");
|
||||
}
|
||||
ssh_send_port_open(channel, hostname, port, description);
|
||||
sfree(description);
|
||||
}
|
||||
|
||||
static int pfd_receive(Plug plug, int urgent, char *data, int len)
|
||||
{
|
||||
struct PortForwarding *pf = (struct PortForwarding *) plug;
|
||||
@ -371,7 +386,7 @@ static int pfd_receive(Plug plug, int urgent, char *data, int len)
|
||||
return 1;
|
||||
} else {
|
||||
/* asks to forward to the specified host/port for this */
|
||||
ssh_send_port_open(pf->c, pf->hostname, pf->port, "forwarding");
|
||||
wrap_send_port_open(pf->c, pf->hostname, pf->port, pf->s);
|
||||
}
|
||||
pf->dynamic = 0;
|
||||
|
||||
@ -510,7 +525,7 @@ static int pfl_accepting(Plug p, accept_fn_t constructor, accept_ctx_t ctx)
|
||||
return 1;
|
||||
} else {
|
||||
/* asks to forward to the specified host/port for this */
|
||||
ssh_send_port_open(pf->c, pf->hostname, pf->port, "forwarding");
|
||||
wrap_send_port_open(pf->c, pf->hostname, pf->port, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user