summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2023-05-10 13:24:43 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2023-05-10 13:24:43 +0900
commit17055e1c995367e60f45ee73fa1a39e7a09efd59 (patch)
tree9408cb9597e4f31b37dca4367e1f74b477681b72 /src
parent9110945ce625e4a668eeed6a00252b7851e6d4b6 (diff)
downloadlibassuan-17055e1c995367e60f45ee73fa1a39e7a09efd59.tar.gz
w32: Fix the semantics of sending FD, it's Windows HANDLE.
* src/assuan-handler.c (w32_handler_sendfd): It's Windows HANDLE. * src/system-w32.c (get_file_handle, w32_fdpass_send): Likewise. * tests/fdpassing.c (cmd_echo): Received FD is Windows HANDLE. (client): Use Windows HANDLE for assuan_sendfd. -- GnuPG-bug-id: 6236 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'src')
-rw-r--r--src/assuan-handler.c20
-rw-r--r--src/system-w32.c21
2 files changed, 12 insertions, 29 deletions
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index 37f84b6..a04ab4e 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -27,9 +27,6 @@
#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"
@@ -359,10 +356,11 @@ std_handler_output (assuan_context_t ctx, char *line)
}
-#if HAVE_W32_SYSTEM || HAVE_W64_SYSTEM
+#ifdef HAVE_W32_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.
+ * The command used by a client to send an 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"
@@ -375,7 +373,6 @@ 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);
@@ -389,14 +386,7 @@ w32_handler_sendfd (assuan_context_t ctx, char *line)
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;
+ ctx->uds.pendingfds[ctx->uds.pendingfdscount++] = (assuan_fd_t)file_handle;
return PROCESS_DONE (ctx, err);
}
#endif
diff --git a/src/system-w32.c b/src/system-w32.c
index b7a14c8..28d3564 100644
--- a/src/system-w32.c
+++ b/src/system-w32.c
@@ -167,19 +167,17 @@ __assuan_close (assuan_context_t ctx, assuan_fd_t fd)
-/* Get a file HANDLE to send, from POSIX fd. */
+/* Get a file HANDLE for other end to send, from MY_HANDLE. */
static gpg_error_t
-get_file_handle (int fd, int process_id, HANDLE *r_handle)
+get_file_handle (assuan_fd_t my_handle, int process_id, HANDLE *r_handle)
{
- HANDLE prochandle, handle, newhandle;
-
- handle = (void *)_get_osfhandle (fd);
+ HANDLE prochandle, newhandle;
prochandle = OpenProcess (PROCESS_DUP_HANDLE, FALSE, process_id);
if (!prochandle)
return gpg_error (GPG_ERR_ASS_PARAMETER);/*FIXME: error*/
- if (!DuplicateHandle (GetCurrentProcess (), handle, prochandle, &newhandle,
+ if (!DuplicateHandle (GetCurrentProcess (), my_handle, prochandle, &newhandle,
0, TRUE, DUPLICATE_SAME_ACCESS))
{
CloseHandle (prochandle);
@@ -191,21 +189,16 @@ get_file_handle (int fd, int process_id, HANDLE *r_handle)
}
-/* Send a FD (which means POSIX fd) to the peer. */
+/* Send an FD (which means Windows HANDLE) to the peer. */
gpg_error_t
w32_fdpass_send (assuan_context_t ctx, assuan_fd_t fd)
{
char fdpass_msg[256];
int res;
- int fd0; /* POSIX fd */
- intptr_t fd_converted_to_integer;
HANDLE file_handle;
gpg_error_t err;
- fd_converted_to_integer = (intptr_t)fd;
- fd0 = (int)fd_converted_to_integer; /* Bit pattern is possibly truncated. */
-
- err = get_file_handle (fd0, ctx->process_id, &file_handle);
+ err = get_file_handle (fd, ctx->process_id, &file_handle);
if (err)
return err;
@@ -221,7 +214,7 @@ w32_fdpass_send (assuan_context_t ctx, assuan_fd_t fd)
}
-/* Receive a HANDLE from the peer and turn it into a FD (POSIX fd). */
+/* Receive a HANDLE from the peer and turn it into an FD. */
gpg_error_t
w32_fdpass_recv (assuan_context_t ctx, assuan_fd_t *fd)
{