From 129741d2f713305a862a1505f20738a0ce2ea656 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 2 Feb 2011 14:07:05 +0100 Subject: [PATCH] Fix Windows port (spawn and assuan engine). 2011-02-02 Marcus Brinkmann * configure.ac (NEED_LIBASSUAN_VERSION): Bump to 2.0.2 for system hooks. src/ 2011-02-02 Marcus Brinkmann * assuan-support.c (my_socket, my_connect): New functions. (_gpgme_assuan_system_hooks): Add my_Socket, my_connect. * priv-io.h (_gpgme_io_socket): New prototype. * w32-io.c (pid_to_handle, handle_to_oid, fd_to_handle): Remove macros. (is_socket): Remove function. (_gpgme_io_spawn) [HAVE_W32CE_SYSTEM]: Remove some dead code. (_gpgme_io_spawn): Translate handles before DuplicateHandle them. --- ChangeLog | 4 ++++ configure.ac | 2 +- src/ChangeLog | 10 +++++++++ src/assuan-support.c | 19 +++++++++++++++- src/priv-io.h | 1 + src/w32-io.c | 52 ++++++++------------------------------------ 6 files changed, 43 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31a16b0..27e7374 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-02-02 Marcus Brinkmann + + * configure.ac (NEED_LIBASSUAN_VERSION): Bump to 2.0.2 for system hooks. + 2010-12-30 Werner Koch * configure.ac: Support a git revision. diff --git a/configure.ac b/configure.ac index 66b794c..d515d54 100644 --- a/configure.ac +++ b/configure.ac @@ -62,7 +62,7 @@ GPGME_CONFIG_API_VERSION=1 ############################################## NEED_LIBASSUAN_API=2 -NEED_LIBASSUAN_VERSION=2.0.0 +NEED_LIBASSUAN_VERSION=2.0.2 m4_define([git_brevis],m4_esyscmd(printf "%u" 0x[]m4_substr(git_revision,0,4))) diff --git a/src/ChangeLog b/src/ChangeLog index fbe92be..73a62fe 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2011-02-02 Marcus Brinkmann + + * assuan-support.c (my_socket, my_connect): New functions. + (_gpgme_assuan_system_hooks): Add my_Socket, my_connect. + * priv-io.h (_gpgme_io_socket): New prototype. + * w32-io.c (pid_to_handle, handle_to_oid, fd_to_handle): Remove macros. + (is_socket): Remove function. + (_gpgme_io_spawn) [HAVE_W32CE_SYSTEM]: Remove some dead code. + (_gpgme_io_spawn): Translate handles before DuplicateHandle them. + 2011-02-02 Marcus Brinkmann * w32-util.c (mkstemp): Don't use CreateFile instead of open (the diff --git a/src/assuan-support.c b/src/assuan-support.c index f49ab32..5264346 100644 --- a/src/assuan-support.c +++ b/src/assuan-support.c @@ -222,6 +222,21 @@ my_socketpair (assuan_context_t ctx, int namespace, int style, } +static int +my_socket (assuan_context_t ctx, int namespace, int style, int protocol) +{ + return _gpgme_io_socket (namespace, style, protocol); +} + + +static int +my_connect (assuan_context_t ctx, int sock, struct sockaddr *addr, + socklen_t length) +{ + return _gpgme_io_connect (sock, addr, length); +} + + struct assuan_system_hooks _gpgme_assuan_system_hooks = { ASSUAN_SYSTEM_HOOKS_VERSION, @@ -234,6 +249,8 @@ struct assuan_system_hooks _gpgme_assuan_system_hooks = my_sendmsg, my_spawn, my_waitpid, - my_socketpair + my_socketpair, + my_socket, + my_connect }; diff --git a/src/priv-io.h b/src/priv-io.h index 9c70d22..770c061 100644 --- a/src/priv-io.h +++ b/src/priv-io.h @@ -64,6 +64,7 @@ struct io_select_fd_s /* These function are either defined in posix-io.c or w32-io.c. */ void _gpgme_io_subsystem_init (void); +int _gpgme_io_socket (int namespace, int style, int protocol); int _gpgme_io_connect (int fd, struct sockaddr *addr, int addrlen); int _gpgme_io_read (int fd, void *buffer, size_t count); int _gpgme_io_write (int fd, const void *buffer, size_t count); diff --git a/src/w32-io.c b/src/w32-io.c index 168177e..10e0dad 100644 --- a/src/w32-io.c +++ b/src/w32-io.c @@ -125,9 +125,6 @@ release_fd (int fd) } -#define pid_to_handle(a) ((HANDLE)(a)) -#define handle_to_pid(a) ((int)(a)) -#define fd_to_handle(a) ((HANDLE)(a)) #define handle_to_fd(a) ((int)(a)) #define READBUF_SIZE 4096 @@ -260,40 +257,6 @@ set_synchronize (HANDLE hd) } -/* Return 1 if HD refers to a socket, 0 if it does not refer to a - socket, and -1 for unknown (autodetect). */ -static int -is_socket (HANDLE hd) -{ -#ifdef HAVE_W32CE_SYSTEM - return -1; -#else - /* We need to figure out whether we are working on a socket or on a - handle. A trivial way would be to check for the return code of - recv and see if it is WSAENOTSOCK. However the recv may block - after the server process died and thus the destroy_reader will - hang. Another option is to use getsockopt to test whether it is - a socket. The bug here is that once a socket with a certain - values has been opened, closed and later a CreatePipe returned - the same value (i.e. handle), getsockopt still believes it is a - socket. What we do now is to use a combination of GetFileType - and GetNamedPipeInfo. The specs say that the latter may be used - on anonymous pipes as well. Note that there are claims that - since winsocket version 2 ReadFile may be used on a socket but - only if it is supported by the service provider. Tests on a - stock XP using a local TCP socket show that it does not work. */ - DWORD dummyflags, dummyoutsize, dummyinsize, dummyinst; - - if (GetFileType (hd) == FILE_TYPE_PIPE - && !GetNamedPipeInfo (hd, &dummyflags, &dummyoutsize, - &dummyinsize, &dummyinst)) - return 1; /* Function failed; thus we assume it is a socket. */ - else - return 0; /* Success; this is not a socket. */ -#endif -} - - static DWORD CALLBACK reader (void *arg) { @@ -1605,11 +1568,9 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags, si.hStdOutput = INVALID_HANDLE_VALUE; si.hStdError = INVALID_HANDLE_VALUE; - cr_flags |= CREATE_SUSPENDED; -#ifndef HAVE_W32CE_SYSTEM + cr_flags |= CREATE_SUSPENDED; cr_flags |= DETACHED_PROCESS; cr_flags |= GetPriorityClass (GetCurrentProcess ()); -#endif if (!CreateProcessA (_gpgme_get_w32spawn_path (), arg_string, &sec_attr, /* process security attributes */ @@ -1639,10 +1600,15 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags, /* Insert the inherited handles. */ for (i = 0; fd_list[i].fd != -1; i++) { - HANDLE hd; - + int fd = fd_list[i].fd; + HANDLE ohd = INVALID_HANDLE_VALUE; + HANDLE hd = INVALID_HANDLE_VALUE; + /* Make it inheritable for the wrapper process. */ - if (!DuplicateHandle (GetCurrentProcess(), fd_to_handle (fd_list[i].fd), + if (fd >= 0 && fd < MAX_SLAFD && fd_table[fd].used) + ohd = fd_table[fd].handle; + + if (!DuplicateHandle (GetCurrentProcess(), ohd, pi.hProcess, &hd, 0, TRUE, DUPLICATE_SAME_ACCESS)) { TRACE_LOG1 ("DuplicateHandle failed: ec=%d", (int) GetLastError ()); -- 2.26.2