From cf29125fb464169d1bab88a0bc9c18a4ca5a983a Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 1 Jan 2020 16:47:11 +0000 Subject: [PATCH] Windows: use named-pipe IPC for stream agent forwarding. Now that Pageant runs a named-pipe server as well as a WM_COPYDATA server, we prefer the former (if available) for agent forwarding, for the same reasons as on Unix: it lets us establish a simple raw-data streaming connection instead of agentf.c's complicated message boundary detection and buffer management, and if agent connections ever become stateful, this technique will cope. On Windows, another advantage of this change is that forwarded agent requests can now be asynchronous: if the agent takes time to respond to a request for any reason, then the rest of PuTTY's GUI and SSH connection are not blocked, and you can carry on working while the agent is thinking about the request. (I didn't list that as a benefit of doing the same thing for Unix in commit ae1148267, because on Unix, agent_query() could _already_ run asynchronously. It's only on Windows that that's new.) --- windows/winpgntc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/windows/winpgntc.c b/windows/winpgntc.c index af1ae7e2..e2ddf3d5 100644 --- a/windows/winpgntc.c +++ b/windows/winpgntc.c @@ -150,7 +150,30 @@ char *agent_named_pipe_name(void) return pipename; } -#endif /* NO_SECURITY */ +struct agent_connect_ctx { + char *pipename; +}; + +Socket *agent_connect(void *vctx, Plug *plug) +{ + agent_connect_ctx *ctx = (agent_connect_ctx *)vctx; + return new_named_pipe_client(ctx->pipename, plug); +} + +agent_connect_ctx *agent_get_connect_ctx(void) +{ + agent_connect_ctx *ctx = snew(agent_connect_ctx); + ctx->pipename = agent_named_pipe_name(); + return ctx; +} + +void agent_free_connect_ctx(agent_connect_ctx *ctx) +{ + sfree(ctx->pipename); + sfree(ctx); +} + +#else /* NO_SECURITY */ Socket *agent_connect(void *vctx, Plug *plug) { @@ -165,3 +188,5 @@ agent_connect_ctx *agent_get_connect_ctx(void) void agent_free_connect_ctx(agent_connect_ctx *ctx) { } + +#endif /* NO_SECURITY */