1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 09:27:59 +00:00

FdSocket, HandleSocket: store a notional peer address.

In the case where these socket types are constructed because of a
local proxy command, we do actually have a SockAddr representing the
logical host we were trying to make a connection to. So we might as
well store it in the socket implementation, and then we can include it
in the PLUGLOG_CONNECT_SUCCESS call to make the log message more
informative.
This commit is contained in:
Simon Tatham 2021-09-13 14:34:46 +01:00
parent 8f5e9a4f8d
commit a4b8ff911b
10 changed files with 32 additions and 18 deletions

View File

@ -23,6 +23,8 @@ typedef struct FdSocket {
int pending_error;
SockAddr *addr;
int port;
Plug *plug;
Socket sock;
@ -134,6 +136,9 @@ static void fdsocket_close(Socket *s)
bufchain_clear(&fds->pending_input_data);
bufchain_clear(&fds->pending_output_data);
if (fds->addr)
sk_addr_free(fds->addr);
delete_callbacks_for_context(fds);
sfree(fds);
@ -318,15 +323,19 @@ static const SocketVtable FdSocket_sockvt = {
static void fdsocket_connect_success_callback(void *ctx)
{
FdSocket *fds = (FdSocket *)ctx;
plug_log(fds->plug, PLUGLOG_CONNECT_SUCCESS, NULL, 0, NULL, 0);
plug_log(fds->plug, PLUGLOG_CONNECT_SUCCESS, fds->addr, fds->port,
NULL, 0);
}
Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug)
Socket *make_fd_socket(int infd, int outfd, int inerrfd,
SockAddr *addr, int port, Plug *plug)
{
FdSocket *fds;
fds = snew(FdSocket);
fds->sock.vt = &FdSocket_sockvt;
fds->addr = addr;
fds->port = port;
fds->plug = plug;
fds->outgoingeof = EOF_NO;
fds->pending_error = 0;

View File

@ -98,8 +98,5 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
inerrfd = -1;
}
/* We are responsible for this and don't need it any more */
sk_addr_free(addr);
return make_fd_socket(infd, outfd, inerrfd, plug);
return make_fd_socket(infd, outfd, inerrfd, addr, port, plug);
}

View File

@ -380,7 +380,8 @@ bool so_peercred(int fd, int *pid, int *uid, int *gid);
/*
* uxfdsock.c.
*/
Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug);
Socket *make_fd_socket(int infd, int outfd, int inerrfd,
SockAddr *addr, int port, Plug *plug);
/*
* Default font setting, which can vary depending on NOT_X_WINDOWS.

View File

@ -411,7 +411,7 @@ int main(int argc, char **argv)
} else {
struct server_instance *inst;
Plug *plug = server_conn_plug(&scfg, &inst);
ssh_server_start(plug, make_fd_socket(0, 1, -1, plug));
ssh_server_start(plug, make_fd_socket(0, 1, -1, NULL, 0, plug));
log_to_stderr(inst->id, "running directly on stdio");
}

View File

@ -869,7 +869,7 @@ int main(int argc, char **argv)
} else {
struct server_instance *inst;
Plug *plug = server_conn_plug(&scfg, &inst);
ssh_server_start(plug, make_fd_socket(0, 1, -1, plug));
ssh_server_start(plug, make_fd_socket(0, 1, -1, NULL, 0, plug));
log_to_stderr(inst->id, "speaking SSH on stdio");
}

View File

@ -40,6 +40,8 @@ typedef struct HandleSocket {
char *error;
SockAddr *addr;
int port;
Plug *plug;
Socket sock;
@ -128,6 +130,9 @@ static void sk_handle_close(Socket *s)
CloseHandle(hs->recv_H);
bufchain_clear(&hs->inputdata);
if (hs->addr)
sk_addr_free(hs->addr);
delete_callbacks_for_context(hs);
sfree(hs);
@ -317,17 +322,20 @@ static const SocketVtable HandleSocket_sockvt = {
static void sk_handle_connect_success_callback(void *ctx)
{
HandleSocket *hs = (HandleSocket *)ctx;
plug_log(hs->plug, PLUGLOG_CONNECT_SUCCESS, NULL, 0, NULL, 0);
plug_log(hs->plug, PLUGLOG_CONNECT_SUCCESS, hs->addr, hs->port, NULL, 0);
}
Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
Plug *plug, bool overlapped)
SockAddr *addr, int port, Plug *plug,
bool overlapped)
{
HandleSocket *hs;
int flags = (overlapped ? HANDLE_FLAG_OVERLAPPED : 0);
hs = snew(HandleSocket);
hs->sock.vt = &HandleSocket_sockvt;
hs->addr = addr;
hs->port = port;
hs->plug = plug;
hs->error = NULL;
hs->frozen = UNFROZEN;

View File

@ -30,9 +30,6 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
cmd = format_telnet_command(addr, port, conf);
/* We are responsible for this and don't need it any more */
sk_addr_free(addr);
{
char *msg = dupprintf("Starting local proxy command: %s", cmd);
plug_log(plug, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0);
@ -103,5 +100,5 @@ Socket *platform_new_connection(SockAddr *addr, const char *hostname,
CloseHandle(cmd_err_to_us);
return make_handle_socket(us_to_cmd, us_from_cmd, us_from_cmd_err,
plug, false);
addr, port, plug, false);
}

View File

@ -90,5 +90,6 @@ Socket *new_named_pipe_client(const char *pipename, Plug *plug)
if (pipehandle == INVALID_HANDLE_VALUE)
return new_error_socket_consume_string(plug, err);
else
return make_handle_socket(pipehandle, pipehandle, NULL, plug, true);
return make_handle_socket(pipehandle, pipehandle, NULL, NULL, 0,
plug, true);
}

View File

@ -112,7 +112,7 @@ static Socket *named_pipe_accept(accept_ctx_t ctx, Plug *plug)
{
HANDLE conn = (HANDLE)ctx.p;
return make_handle_socket(conn, conn, NULL, plug, true);
return make_handle_socket(conn, conn, NULL, NULL, 0, plug, true);
}
static void named_pipe_accept_loop(NamedPipeServerSocket *ps,

View File

@ -341,7 +341,8 @@ extern HANDLE winselcli_event;
* Network-subsystem-related functions provided in other Windows modules.
*/
Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
Plug *plug, bool overlapped); /* winhsock */
SockAddr *addr, int port, Plug *plug,
bool overlapped); /* winhsock */
Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */