1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-15 10:07:39 -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:
Simon Tatham
2015-05-18 13:57:45 +01:00
parent 63d7365ae6
commit c8f83979a3
17 changed files with 227 additions and 19 deletions

View File

@ -38,6 +38,7 @@ struct socket_function_table {
void (*set_frozen) (Socket s, int is_frozen);
/* ignored by tcp, but vital for ssl */
const char *(*socket_error) (Socket s);
char *(*peer_info) (Socket s);
};
typedef union { void *p; int i; } accept_ctx_t;
@ -182,6 +183,13 @@ const char *sk_addr_error(SockAddr addr);
*/
#define sk_set_frozen(s, is_frozen) (((*s)->set_frozen) (s, is_frozen))
/*
* Return a (dynamically allocated) string giving some information
* about the other end of the socket, suitable for putting in log
* files. May be NULL if nothing is available at all.
*/
#define sk_peer_info(s) (((*s)->peer_info) (s))
/*
* Simple wrapper on getservbyname(), needed by ssh.c. Returns the
* port number, in host byte order (suitable for printf and so on).