From 1f0f033f552b5cd81f02e761a0e31eb9a2c89ab8 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Fri, 21 Jan 2011 04:21:30 +0100 Subject: [PATCH 1/4] Fix gpgconf option change if not self-assigning. 2011-01-21 Marcus Brinkmann * engine-gpgconf.c (_gpgme_conf_opt_change): Fix the case that is not self-assignment. --- src/ChangeLog | 5 +++++ src/engine-gpgconf.c | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index f891d980..fdd3e496 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-01-21 Marcus Brinkmann + + * engine-gpgconf.c (_gpgme_conf_opt_change): Fix the case that is + not self-assignment. + 2010-12-08 Werner Koch * gpgme-tool.c (strcpy_escaped_plus): New. diff --git a/src/engine-gpgconf.c b/src/engine-gpgconf.c index d08ed03c..6807dce9 100644 --- a/src/engine-gpgconf.c +++ b/src/engine-gpgconf.c @@ -622,7 +622,7 @@ _gpgme_conf_opt_change (gpgme_conf_opt_t opt, int reset, gpgme_conf_arg_t arg) { if (opt->new_value) release_arg (opt->new_value, opt->alt_type); - opt->new_value = NULL; + opt->new_value = NULL; opt->change_value = 0; } else @@ -630,10 +630,8 @@ _gpgme_conf_opt_change (gpgme_conf_opt_t opt, int reset, gpgme_conf_arg_t arg) /* Support self-assignment, for example for adding an item to an existing list. */ if (opt->new_value && arg != opt->new_value) - { - release_arg (opt->new_value, opt->alt_type); - opt->new_value = arg; - } + release_arg (opt->new_value, opt->alt_type); + opt->new_value = arg; opt->change_value = 1; } return 0; From a2b9adafe46c55a2c26dd46163055bbdf3526835 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 2 Feb 2011 13:47:53 +0100 Subject: [PATCH 2/4] 2011-02-02 Marcus Brinkmann * w32-util.c (mkstemp): Don't use CreateFile instead of open (the function is not used on Windows CE, and the callers were not adjusted). --- src/ChangeLog | 6 ++++++ src/w32-util.c | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 562d2977..fe850956 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2011-02-02 Marcus Brinkmann + + * w32-util.c (mkstemp): Don't use CreateFile instead of open (the + function is not used on Windows CE, and the callers were not + adjusted). + 2010-11-02 Werner Koch * data-fd.c (read, write, lseek) [W32CE && ! __MINGW32CE__]: New. diff --git a/src/w32-util.c b/src/w32-util.c index ec2fe50f..c29ff490 100644 --- a/src/w32-util.c +++ b/src/w32-util.c @@ -473,6 +473,14 @@ _gpgme_get_conf_int (const char *key, int *value) } +#ifdef HAVE_W32CE_SYSTEM +int +_gpgme_mkstemp (int *fd, char **name) +{ + return -1; +} +#else + /* mkstemp extracted from libc/sysdeps/posix/tempname.c. Copyright (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc. @@ -496,7 +504,7 @@ mkstemp (char *tmpl) static uint64_t value; uint64_t random_time_bits; unsigned int count; - HANDLE fd = INVALID_HANDLE_VALUE; + int fd = -1; int save_errno = errno; /* A lower bound on the number of temporary files to attempt to @@ -552,23 +560,14 @@ mkstemp (char *tmpl) v /= 62; XXXXXX[5] = letters[v % 62]; - fd = CreateFileA (tmpl, - GENERIC_WRITE|GENERIC_READ, - FILE_SHARE_READ|FILE_SHARE_WRITE, - NULL, - CREATE_NEW, - FILE_ATTRIBUTE_NORMAL, - NULL); - if (fd != INVALID_HANDLE_VALUE) + fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); + if (fd >= 0) { gpg_err_set_errno (save_errno); - return (int)fd; + return fd; } - else if (GetLastError () != ERROR_FILE_EXISTS) - { - gpg_err_set_errno (EIO); - return -1; - } + else if (errno != EEXIST) + return -1; } /* We got out of the loop because we ran out of combinations to try. */ @@ -613,6 +612,7 @@ _gpgme_mkstemp (int *fd, char **name) *name = tmpname; return 0; } +#endif From 129741d2f713305a862a1505f20738a0ce2ea656 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 2 Feb 2011 14:07:05 +0100 Subject: [PATCH 3/4] 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 31a16b07..27e73745 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 66b794cc..d515d544 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 fbe92be0..73a62fe3 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 f49ab32b..52643467 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 9c70d22f..770c0617 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 168177e5..10e0dade 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 ()); From 2bdbe888228ce09f15be4773800ed13263a8e43e Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 3 Feb 2011 12:38:28 +0100 Subject: [PATCH 4/4] Fix socket implementation on Windows. 2011-02-03 Marcus Brinkmann * w32-io.c (_gpgme_io_socket): Return fd, not res. --- src/ChangeLog | 4 ++++ src/w32-io.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 73a62fe3..4afcdf98 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2011-02-03 Marcus Brinkmann + + * w32-io.c (_gpgme_io_socket): Return fd, not res. + 2011-02-02 Marcus Brinkmann * assuan-support.c (my_socket, my_connect): New functions. diff --git a/src/w32-io.c b/src/w32-io.c index 10e0dade..56a05c4b 100644 --- a/src/w32-io.c +++ b/src/w32-io.c @@ -2035,7 +2035,7 @@ _gpgme_io_socket (int domain, int type, int proto) TRACE_SUC2 ("socket=0x%x (0x%x)", fd, fd_table[fd].socket); - return res; + return fd; }