diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/assuan-handler.c | 44 | ||||
-rw-r--r-- | src/system-w32.c | 12 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/assuan-handler.c b/src/assuan-handler.c index 126eccb..8eae253 100644 --- a/src/assuan-handler.c +++ b/src/assuan-handler.c @@ -27,6 +27,9 @@ #include <stdio.h> #include <string.h> #include <errno.h> +#if HAVE_W32_SYSTEM || HAVE_W64_SYSTEM +#include <fcntl.h> +#endif #include "assuan-defs.h" #include "debug.h" @@ -356,6 +359,44 @@ std_handler_output (assuan_context_t ctx, char *line) } +#if HAVE_W32_SYSTEM || HAVE_W64_SYSTEM +static const char w32_help_sendfd[] = + "SENDFD <N>\n" + "\n" + "Used by a client to pass a file HANDLE to the server.\n" + "The server opens <N> 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 +417,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 { } }; diff --git a/src/system-w32.c b/src/system-w32.c index 2e2d83f..037a924 100644 --- a/src/system-w32.c +++ b/src/system-w32.c @@ -249,6 +249,7 @@ w32_fdpass_send (assuan_context_t ctx, assuan_fd_t fd) if (err) return err; +#if 0 res = snprintf (fdpass_msg, sizeof (fdpass_msg), FDPASS_FORMAT, file_handle); if (res < 0) { @@ -261,6 +262,17 @@ w32_fdpass_send (assuan_context_t ctx, assuan_fd_t fd) res = send (HANDLE2SOCKET (ctx->outbound.fd), "!", 1, MSG_OOB); res = send (HANDLE2SOCKET (ctx->outbound.fd), fdpass_msg, msglen, 0); return 0; +#else + res = snprintf (fdpass_msg, sizeof (fdpass_msg), "SENDFD %p", file_handle); + if (res < 0) + { + CloseHandle (file_handle); + return gpg_error (GPG_ERR_ASS_PARAMETER);/*FIXME: error*/ + } + + err = assuan_transact (ctx, fdpass_msg, NULL, NULL, NULL, NULL, NULL, NULL); + return err; +#endif } static int |