From ce794a0a88a8dca11810ac79e6be6bf6b4e5326c Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 4 Nov 2022 17:55:34 +0900 Subject: w32: Add SENDFD internal command. * src/assuan-handler.c (w32_handler_sendfd): New. (std_cmd_table): Add the "SENDFD" command. -- GnuPG-bug-id: 6236 Signed-off-by: NIIBE Yutaka --- src/assuan-handler.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/assuan-handler.c b/src/assuan-handler.c index 126eccb..37f84b6 100644 --- a/src/assuan-handler.c +++ b/src/assuan-handler.c @@ -27,6 +27,9 @@ #include #include #include +#if HAVE_W32_SYSTEM || HAVE_W64_SYSTEM +#include +#endif #include "assuan-defs.h" #include "debug.h" @@ -356,6 +359,48 @@ std_handler_output (assuan_context_t ctx, char *line) } +#if HAVE_W32_SYSTEM || HAVE_W64_SYSTEM +/* + * The command used by a client to send FD. That is, from the viewpoint + * of handling this command, it is to _receive_ a file handle. + */ +static const char w32_help_sendfd[] = + "SENDFD \n" + "\n" + "Used by a client to pass a file HANDLE to the server.\n" + "The server opens as a local file HANDLE."; +static gpg_error_t +w32_handler_sendfd (assuan_context_t ctx, char *line) +{ + gpg_error_t err = 0; + char *endp; + intptr_t file_handle; + int fd; + +#if HAVE_W64_SYSTEM + file_handle = strtoull (line, &endp, 16); +#elif HAVE_W32_SYSTEM + file_handle = strtoul (line, &endp, 16); +#endif + + if (*endp) + { + err = set_error (ctx, GPG_ERR_ASS_SYNTAX, "hex number required"); + return PROCESS_DONE (ctx, err); + } + + fd = _open_osfhandle ((intptr_t)file_handle, _O_RDWR); + if (fd < 0) + { + CloseHandle ((HANDLE)file_handle); + err = GPG_ERR_ASSUAN; + } + + ctx->uds.pendingfds[ctx->uds.pendingfdscount++] = (assuan_fd_t)fd; + return PROCESS_DONE (ctx, err); +} +#endif + /* This is a table with the standard commands and handler for them. The table is used to initialize a new context and associate strings with default handlers */ @@ -376,6 +421,9 @@ static struct { { "INPUT", std_handler_input, std_help_input, 0 }, { "OUTPUT", std_handler_output, std_help_output, 0 }, +#if HAVE_W32_SYSTEM + { "SENDFD", w32_handler_sendfd, w32_help_sendfd, 1 }, +#endif { } }; -- cgit v1.2.1