diff options
-rw-r--r-- | common/ChangeLog | 84 | ||||
-rw-r--r-- | common/convert.c | 4 | ||||
-rw-r--r-- | common/estream-printf.c | 63 | ||||
-rw-r--r-- | common/estream-printf.h | 38 | ||||
-rw-r--r-- | common/estream.c | 110 | ||||
-rw-r--r-- | common/estream.h | 36 | ||||
-rw-r--r-- | common/gettime.c | 2 | ||||
-rw-r--r-- | common/homedir.c | 31 | ||||
-rw-r--r-- | common/http.c | 15 | ||||
-rw-r--r-- | common/i18n.c | 9 | ||||
-rw-r--r-- | common/iobuf.c | 21 | ||||
-rw-r--r-- | common/membuf.c | 2 | ||||
-rw-r--r-- | common/signal.c | 4 | ||||
-rw-r--r-- | common/sysutils.c | 85 | ||||
-rw-r--r-- | common/util.h | 7 | ||||
-rw-r--r-- | common/xreadline.c | 2 | ||||
-rw-r--r-- | configure.ac | 4 |
17 files changed, 406 insertions, 111 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 19ccd79e9..d63b3657e 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,33 @@ +2010-03-02 Werner Koch <wk@g10code.com> + + * estream.c, estream.h, estream-printf.c, estream-printf.h: Update + from libestream. + +2010-03-01 Werner Koch <wk@g10code.com> + + * signal.c [!HAVE_SIGNAL_H]: Don't include signal.h. + + * iobuf.c (direct_open) [W32CE]: Make filename to wchar_t. + (iobuf_cancel) [W32CE]: Use DeleteFile. + + * gettime.c (dump_isotime): Use "%s" to print "none". + + * homedir.c (standard_homedir) [W32CE]: Use wchar_t to create the + directory. + (w32_rootdir) [W32CE]: Likewise. + + * sysutils.c (translate_sys2libc_fd) [W32CE]: Add support. + (gnupg_tmpfile) [W32CE]: Ditto. + (_gnupg_getenv) [W32CE]: New. + + * util.h (getpid, getenv) [W32CE]: New. + + * i18n.c (i18n_switchto_utf8) + (i18n_switchback) [USE_SIMPLE_GETTEXT]: Use new function from + libgpg-error which supports proper restoring. + + * sysutils.c (get_session_marker): Simplified by using gcrypt. + 2009-12-08 Marcus Brinkmann <marcus@g10code.de> * Makefile.am (audit-events.h, status.h) [!MAINTAINER_MODE]: No @@ -266,7 +296,7 @@ * percent.c, t-percent.c: New. - * exechelp.c (gnupg_spawn_process, gnupg_spawn_process_fd) + * exechelp.c (gnupg_spawn_process, gnupg_spawn_process_fd) (gnupg_spawn_process_detached) [W32]: Remove debug output. 2008-11-20 Werner Koch <wk@g10code.com> @@ -481,7 +511,7 @@ 2007-11-05 Werner Koch <wk@g10code.com> - * audit.c, audit.h: New. + * audit.c, audit.h: New. * Makefile.am: Add rules to build audit-events.h. * exaudit.awk: New. * mkstrtable.awk: New. Taken from libgpg-error. @@ -506,7 +536,7 @@ (gnupg_create_inbound_pipe): New. * util.h (GNUPG_MODULE_NAME_GPGSM, GNUPG_MODULE_NAME_GPG): New. * homedir.c (gnupg_module_name): Add them - + 2007-08-28 Werner Koch <wk@g10code.com> * gettime.c (check_isotime, add_isotime): New. Originally written @@ -527,7 +557,7 @@ 2007-08-22 Werner Koch <wk@g10code.com> Updated estream from libestream. - + * estream.c (mem_malloc, mem_realloc, mem_free): New. Use them instead of the ES_MEM_foo. * estream.c (estream_cookie_mem): Remove members DONT_FREE, @@ -596,7 +626,7 @@ 2007-07-05 Werner Koch <wk@g10code.com> - * t-gettime.c: New. + * t-gettime.c: New. * gettime.c (isotime2epoch, epoch2isotime): New. 2007-07-04 Werner Koch <wk@g10code.com> @@ -628,7 +658,7 @@ (iobuf_translate_file_handle): Remove. (translate_file_handle): Use new function. - * estream-printf.c [TEST]: Header including fixes. + * estream-printf.c [TEST]: Header including fixes. (do_format): Do not append a trailing Nul. This avoids spurious Nuls in the es_printf output. (estream_vsnprintf, estream_vasprintf): Take this in account. @@ -642,11 +672,11 @@ (es_convert_mode): Set O_BINARY. (es_func_fd_create, es_func_fp_create, es_func_file_create) [W32]: Call setmode if requested. - + 2007-06-24 Werner Koch <wk@g10code.com> * estream.c (do_fpopen, es_fpopen, es_fpopen_nc): New. - (es_func_fp_create, es_func_fp_read, es_func_fp_write) + (es_func_fp_create, es_func_fp_read, es_func_fp_write) (es_func_fp_seek, es_func_fp_destroy): New. 2007-06-22 Werner Koch <wk@g10code.com> @@ -654,7 +684,7 @@ * estream.c (es_fdopen): Factored code out to.. (do_fdopen): .. new. (es_fdopen_nc): New. - (estream_cookie_fd): Add field NO_CLOSE. + (estream_cookie_fd): Add field NO_CLOSE. (es_func_fd_create): Add arg NO_CLOSE and changed all callers. (es_func_fd_destroy): Handle the new flag. @@ -696,8 +726,8 @@ (agent_open): Use it if GPG_AGENT_INFO is not set. (simple_pwquery): Extended to allow returning of otehyr error codes. - * util.h (GNUPG_MODULE_NAME_AGENT, GNUPG_MODULE_NAME_PINENTRY) - (GNUPG_MODULE_NAME_SCDAEMON, GNUPG_MODULE_NAME_DIRMNGR) + * util.h (GNUPG_MODULE_NAME_AGENT, GNUPG_MODULE_NAME_PINENTRY) + (GNUPG_MODULE_NAME_SCDAEMON, GNUPG_MODULE_NAME_DIRMNGR) (GNUPG_MODULE_NAME_PROTECT_TOOL): New. * homedir.c (gnupg_module_name): New. (gnupg_bindir): New. @@ -778,7 +808,7 @@ 2007-05-07 Werner Koch <wk@g10code.com> * signal.c (got_fatal_signal): Protect SIG from being clobbered by - a faulty signal implementaion. Suggested by James Juran. + a faulty signal implementaion. Suggested by James Juran. 2007-04-25 Werner Koch <wk@g10code.com> @@ -854,9 +884,9 @@ 2006-10-17 Werner Koch <wk@g10code.com> - * estream.c (struct estream_internal, es_initialize) + * estream.c (struct estream_internal, es_initialize) (es_deinitialize, print_fun_writer, es_print): New and modified - functions to avoid tempfiles for printf style printing. + functions to avoid tempfiles for printf style printing. * Makefile.am (libcommonpth_a_SOURCES): New. We now build a secon version of the library with explicit Pth support. @@ -899,7 +929,7 @@ buffer. 2006-09-27 Florian Weimer <fweimer@bfk.de> (wk) - + * iobuf.c (iobuf_unread): New. 2006-09-22 Werner Koch <wk@g10code.com> @@ -1086,7 +1116,7 @@ * estream.c (estream_cookie_mem): Make MEMORY unsigned char*. (es_write): Make BUFFER a void *. (es_writen): Ditto. - (es_func_fd_read, es_func_fd_write, es_func_mem_read) + (es_func_fd_read, es_func_fd_write, es_func_mem_read) (es_func_mem_write): Ditto. (es_read, es_readn): Ditto. (es_func_mem_write): Made MEMORY_NEW an unsigned char *. @@ -1097,7 +1127,7 @@ * estream.c: Use HAVE_CONFIG_H and not USE_CONFIG_H! (es_func_fd_read, es_func_fd_write): Protect against EINTR. - + 2005-06-01 Werner Koch <wk@g10code.com> * Makefile.am (AM_CPPFLAGS): Added. @@ -1169,7 +1199,7 @@ * signal.c (got_fatal_signal, got_usr_signal) (got_fatal_signal) [DOSISH]: Don't build. - * simple-gettext.c: Include sysutils.h + * simple-gettext.c: Include sysutils.h * homedir.c: New. Use CSIDL_APPDATA for W32 as the default home directory. @@ -1363,10 +1393,10 @@ 2003-08-14 Timo Schulz <twoaday@freakmail.de> * dynload.h. New. W32 wrapper around the dynload mechanism. - + 2003-07-15 Werner Koch <wk@gnupg.org> - * simple-pwquery.c, simple-pwquery.h: New; moved from ../agent. + * simple-pwquery.c, simple-pwquery.h: New; moved from ../agent. * Makefile.am (libsimple_pwquery_a_LIBADD): New. 2003-06-25 Werner Koch <wk@gnupg.org> @@ -1540,10 +1570,10 @@ * sysutils.c: New. This is the misc.c file from gnupg 1.0.6 with the OpenPGP stuff removed. * sysutils.h: New. - + 2002-01-15 Werner Koch <wk@gnupg.org> - * maperror.c: Add mapping for Not_Trusted. + * maperror.c: Add mapping for Not_Trusted. 2002-01-11 Werner Koch <wk@gnupg.org> @@ -1570,10 +1600,10 @@ * util.h (digitp, hexdigitp): New ctype like macros. (atoi_1,atoi_2,atoi_4,xtoi_1,xtoi_2): New. - - - Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009 Free Software Foundation, Inc. + + + Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, + 2009, 2010 Free Software Foundation, Inc. This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without @@ -1582,5 +1612,3 @@ This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY, to the extent permitted by law; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - diff --git a/common/convert.c b/common/convert.c index d3e8b642e..aa3a3a809 100644 --- a/common/convert.c +++ b/common/convert.c @@ -115,7 +115,7 @@ do_bin2hex (const void *buffer, size_t length, char *stringbuf, int with_colon) size_t nbytes = n * length + 1; if (length && (nbytes-1) / n != length) { - errno = ENOMEM; + gpg_err_set_errno (ENOMEM); return NULL; } stringbuf = xtrymalloc (nbytes); @@ -232,7 +232,7 @@ hex2str_alloc (const char *hexstring, size_t *r_count) { if (r_count) *r_count = 0; - errno = EINVAL; + gpg_err_set_errno (EINVAL); return NULL; } if (r_count) diff --git a/common/estream-printf.c b/common/estream-printf.c index 54ecb2377..3955a01cb 100644 --- a/common/estream-printf.c +++ b/common/estream-printf.c @@ -1,5 +1,5 @@ -/* estream-printf.c - Versatile C-99 compliant printf formatting - * Copyright (C) 2007, 2008, 2009 g10 Code GmbH +/* estream-printf.c - Versatile mostly C-99 compliant printf formatting + * Copyright (C) 2007, 2008, 2009, 2010 g10 Code GmbH * * This file is part of Libestream. * @@ -15,6 +15,40 @@ * * You should have received a copy of the GNU General Public License * along with Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ /* Required autoconf tests: @@ -41,6 +75,13 @@ # include <config.h> #endif +#if defined(_WIN32) && !defined(HAVE_W32_SYSTEM) +# define HAVE_W32_SYSTEM 1 +# if defined(__MINGW32CE__) && !defined (HAVE_W32CE_SYSTEM) +# define HAVE_W32CE_SYSTEM +# endif +#endif + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -57,6 +98,9 @@ #ifdef HAVE_LANGINFO_THOUSANDS_SEP #include <langinfo.h> #endif +#ifdef HAVE_W32CE_SYSTEM +#include <gpg-error.h> /* ERRNO replacement. */ +#endif #ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE # include _ESTREAM_PRINTF_EXTRA_INCLUDE #endif @@ -77,6 +121,13 @@ #define my_printf_free(a) free((a)) #endif +/* A wrapper to set ERRNO. */ +#ifdef HAVE_W32CE_SYSTEM +# define _set_errno(a) gpg_err_set_errno ((a)) +#else +# define _set_errno(a) do { errno = (a); } while (0) +#endif + /* Calculate array dimension. */ #ifndef DIM @@ -634,7 +685,7 @@ parse_format (const char *format, return 0; /* Success. */ leave_einval: - errno = EINVAL; + _set_errno (EINVAL); leave: if (argspecs != *argspecs_addr) free (argspecs); @@ -1540,7 +1591,7 @@ estream_format (estream_printf_out_t outfnc, goto leave; leave_einval: - errno = EINVAL; + _set_errno (EINVAL); leave_error: rc = -1; leave: @@ -1702,7 +1753,7 @@ dynamic_buffer_out (void *outfncarg, const char *buf, size_t buflen) { /* Just in case some formatting routine did not checked for an error. */ - errno = parm->error_flag; + _set_errno (parm->error_flag); return -1; } @@ -1755,7 +1806,7 @@ estream_vasprintf (char **bufp, const char *format, va_list arg_ptr) if (rc != -1 && parm.error_flag) { rc = -1; - errno = parm.error_flag; + _set_errno (parm.error_flag); } if (rc == -1) { diff --git a/common/estream-printf.h b/common/estream-printf.h index 3987b33f2..16e42490c 100644 --- a/common/estream-printf.h +++ b/common/estream-printf.h @@ -1,5 +1,5 @@ -/* estream-printf.h - Versatile C-99 compliant printf formatting. - * Copyright (C) 2007 g10 Code GmbH +/* estream-printf.h - Versatile mostly C-99 compliant printf formatting. + * Copyright (C) 2007, 2010 g10 Code GmbH * * This file is part of Libestream. * @@ -15,6 +15,40 @@ * * You should have received a copy of the GNU General Public License * along with Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef ESTREAM_PRINTF_H diff --git a/common/estream.c b/common/estream.c index 401590552..af7da7052 100644 --- a/common/estream.c +++ b/common/estream.c @@ -1,5 +1,5 @@ /* estream.c - Extended Stream I/O Library - * Copyright (C) 2004, 2005, 2006, 2007, 2009 g10 Code GmbH + * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 g10 Code GmbH * * This file is part of Libestream. * @@ -15,6 +15,40 @@ * * You should have received a copy of the GNU General Public License * along with Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifdef USE_ESTREAM_SUPPORT_H @@ -27,6 +61,9 @@ #if defined(_WIN32) && !defined(HAVE_W32_SYSTEM) # define HAVE_W32_SYSTEM 1 +# if defined(__MINGW32CE__) && !defined (HAVE_W32CE_SYSTEM) +# define HAVE_W32CE_SYSTEM +# endif #endif #include <sys/types.h> @@ -44,6 +81,9 @@ #ifdef HAVE_W32_SYSTEM # include <windows.h> #endif +#ifdef HAVE_W32CE_SYSTEM +# include <gpg-error.h> /* ERRNO replacement. */ +#endif #ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */ # undef HAVE_PTH @@ -76,6 +116,13 @@ void *memrchr (const void *block, int c, size_t size); #define O_BINARY 0 #endif +#ifdef HAVE_W32CE_SYSTEM +# define _set_errno(a) gpg_err_set_errno ((a)) +#else +# define _set_errno(a) do { errno = (a); } while (0) +#endif + + /* Generally used types. */ typedef void *(*func_realloc_t) (void *mem, size_t size); @@ -427,7 +474,7 @@ es_func_mem_create (void *ES__RESTRICT *ES__RESTRICT cookie, if (!data && (data_n || data_len)) { - errno = EINVAL; + _set_errno (EINVAL); return -1; } @@ -511,7 +558,7 @@ es_func_mem_write (void *cookie, const void *buffer, size_t size) newsize = mem_cookie->memory_size + (nleft - size); if (newsize < mem_cookie->offset) { - errno = EINVAL; + _set_errno (EINVAL); return -1; } @@ -522,7 +569,7 @@ es_func_mem_write (void *cookie, const void *buffer, size_t size) newsize += mem_cookie->block_size - 1; if (newsize < mem_cookie->offset) { - errno = EINVAL; + _set_errno (EINVAL); return -1; } newsize /= mem_cookie->block_size; @@ -532,7 +579,7 @@ es_func_mem_write (void *cookie, const void *buffer, size_t size) /* Check for a total limit. */ if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit) { - errno = ENOSPC; + _set_errno (ENOSPC); return -1; } @@ -581,7 +628,7 @@ es_func_mem_seek (void *cookie, off_t *offset, int whence) break; default: - errno = EINVAL; + _set_errno (EINVAL); return -1; } @@ -592,14 +639,14 @@ es_func_mem_seek (void *cookie, off_t *offset, int whence) if (!mem_cookie->flags.grow) { - errno = ENOSPC; + _set_errno (ENOSPC); return -1; } newsize = pos_new + mem_cookie->block_size - 1; if (newsize < pos_new) { - errno = EINVAL; + _set_errno (EINVAL); return -1; } newsize /= mem_cookie->block_size; @@ -607,7 +654,7 @@ es_func_mem_seek (void *cookie, off_t *offset, int whence) if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit) { - errno = ENOSPC; + _set_errno (ENOSPC); return -1; } @@ -971,7 +1018,7 @@ es_convert_mode (const char *mode, unsigned int *modeflags) oflags = O_APPEND | O_CREAT; break; default: - errno = EINVAL; + _set_errno (EINVAL); return -1; } for (mode++; *mode; mode++) @@ -1010,7 +1057,7 @@ es_fill (estream_t stream) if (!stream->intern->func_read) { - errno = EOPNOTSUPP; + _set_errno (EOPNOTSUPP); err = -1; } else @@ -1173,7 +1220,7 @@ es_deinitialize (estream_t stream) int save_errno = errno; fclose (stream->intern->print_fp); stream->intern->print_fp = NULL; - errno = save_errno; + _set_errno (save_errno); } func_close = stream->intern->func_close; @@ -1460,7 +1507,7 @@ es_seek (estream_t ES__RESTRICT stream, off_t offset, int whence, if (! func_seek) { - errno = EOPNOTSUPP; + _set_errno (EOPNOTSUPP); err = -1; goto out; } @@ -1730,7 +1777,7 @@ es_skip (estream_t stream, size_t size) if (stream->data_offset + size > stream->data_len) { - errno = EINVAL; + _set_errno (EINVAL); err = -1; } else @@ -2309,7 +2356,7 @@ es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode, else { /* FIXME? We don't support re-opening at the moment. */ - errno = EINVAL; + _set_errno (EINVAL); es_deinitialize (stream); es_destroy (stream); stream = NULL; @@ -2821,7 +2868,7 @@ es_read_line (estream_t stream, { /* This should never happen. If it does, the function has been called with wrong arguments. */ - errno = EINVAL; + _set_errno (EINVAL); return -1; } length -= 3; /* Reserve 3 bytes for CR,LF,EOL. */ @@ -2855,7 +2902,7 @@ es_read_line (estream_t stream, if (max_length) *max_length = 0; ESTREAM_UNLOCK (stream); - errno = save_errno; + _set_errno (save_errno); return -1; } buffer = *addr_of_buffer; @@ -2973,21 +3020,32 @@ tmpfd (void) { #ifdef HAVE_W32_SYSTEM int attempts, n; +#ifdef HAVE_W32CE_SYSTEM + wchar_t buffer[MAX_PATH+9+12+1]; +# define mystrlen(a) wcslen (a) + wchar_t *name, *p; +#else char buffer[MAX_PATH+9+12+1]; +# define mystrlen(a) strlen (a) char *name, *p; +#endif HANDLE file; int pid = GetCurrentProcessId (); unsigned int value; int i; n = GetTempPath (MAX_PATH+1, buffer); - if (!n || n > MAX_PATH || strlen (buffer) > MAX_PATH) + if (!n || n > MAX_PATH || mystrlen (buffer) > MAX_PATH) { - errno = ENOENT; + _set_errno (ENOENT); return -1; } - p = buffer + strlen (buffer); + p = buffer + mystrlen (buffer); +#ifdef HAVE_W32CE_SYSTEM + wcscpy (p, L"_estream"); +#else strcpy (p, "_estream"); +#endif p += 8; /* We try to create the directory but don't care about an error as it may already exist and the CreateFile would throw an error @@ -3004,7 +3062,11 @@ tmpfd (void) *p++ = tohex (((value >> 28) & 0x0f)); value <<= 4; } +#ifdef HAVE_W32CE_SYSTEM + wcscpy (p, L".tmp"); +#else strcpy (p, ".tmp"); +#endif file = CreateFile (buffer, GENERIC_READ | GENERIC_WRITE, 0, @@ -3014,17 +3076,21 @@ tmpfd (void) NULL); if (file != INVALID_HANDLE_VALUE) { +#ifdef HAVE_W32CE_SYSTEM + int fd = (int)file; +#else int fd = _open_osfhandle ((long)file, 0); if (fd == -1) { CloseHandle (file); return -1; } +#endif return fd; } Sleep (1); /* One ms as this is the granularity of GetTickCount. */ } - errno = ENOENT; + _set_errno (ENOENT); return -1; #else /*!HAVE_W32_SYSTEM*/ FILE *fp; @@ -3109,7 +3175,7 @@ es_setvbuf (estream_t ES__RESTRICT stream, } else { - errno = EINVAL; + _set_errno (EINVAL); err = -1; } diff --git a/common/estream.h b/common/estream.h index d1f94724f..b22c5de43 100644 --- a/common/estream.h +++ b/common/estream.h @@ -1,5 +1,5 @@ /* estream.h - Extended stream I/O Library - * Copyright (C) 2004, 2005, 2006, 2007 g10 Code GmbH + * Copyright (C) 2004, 2005, 2006, 2007, 2010 g10 Code GmbH * * This file is part of Libestream. * @@ -15,6 +15,40 @@ * * You should have received a copy of the GNU General Public License * along with Libestream; if not, see <http://www.gnu.org/licenses/>. + * + * ALTERNATIVELY, Libestream may be distributed under the terms of the + * following license, in which case the provisions of this license are + * required INSTEAD OF the GNU General Public License. If you wish to + * allow use of your version of this file only under the terms of the + * GNU General Public License, and not to allow others to use your + * version of this file under the terms of the following license, + * indicate your decision by deleting this paragraph and the license + * below. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef ESTREAM_H diff --git a/common/gettime.c b/common/gettime.c index 1b4e435a1..52f94b535 100644 --- a/common/gettime.c +++ b/common/gettime.c @@ -500,7 +500,7 @@ void dump_isotime (const gnupg_isotime_t t) { if (!t || !*t) - log_printf (_("[none]")); + log_printf ("%s", _("[none]")); else log_printf ("%.4s-%.2s-%.2s %.2s:%.2s:%s", t, t+4, t+6, t+9, t+11, t+13); diff --git a/common/homedir.c b/common/homedir.c index 5f2e31e0a..a8bec42e4 100644 --- a/common/homedir.c +++ b/common/homedir.c @@ -1,5 +1,5 @@ /* homedir.c - Setup the home directory. - * Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc. + * Copyright (C) 2004, 2006, 2007, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -114,7 +114,18 @@ standard_homedir (void) /* Try to create the directory if it does not yet exists. */ if (access (dir, F_OK)) - CreateDirectory (dir, NULL); + { +#ifdef HAVE_W32CE_SYSTEM + wchar_t *wdir = utf8_to_wchar (dir); + if (wdir) + { + CreateDirectory (wdir, NULL); + xfree (wdir); + } +#else + CreateDirectory (dir, NULL); +#endif + } } else dir = GNUPG_DEFAULT_HOMEDIR; @@ -178,8 +189,20 @@ w32_rootdir (void) if (!got_dir) { char *p; - - if ( !GetModuleFileName ( NULL, dir, MAX_PATH) ) + int rc; + +#ifdef HAVE_W32CE_SYSTEM + { + wchar_t wdir [MAX_PATH+5]; + rc = GetModuleFileName (NULL, wdir, MAX_PATH); + if (rc && WideCharToMultiByte (CP_UTF8, 0, wdir, -1, dir, MAX_PATH-4, + NULL, NULL) < 0) + rc = 0; + } +#else + rc = GetModuleFileName (NULL, dir, MAX_PATH); +#endif + if (!rc) { log_debug ("GetModuleFileName failed: %s\n", w32_strerror (0)); *dir = 0; diff --git a/common/http.c b/common/http.c index c12bd2b3e..a7f6739e5 100644 --- a/common/http.c +++ b/common/http.c @@ -1225,7 +1225,7 @@ my_read_line ( int save_errno = errno; xfree (buffer); *length_of_buffer = *max_length = 0; - errno = save_errno; + gpg_err_set_errno (save_errno); return 0; } buffer = *addr_of_buffer; @@ -1548,12 +1548,13 @@ connect_server (const char *server, unsigned short port, int srv, connected; int last_errno = 0; struct srventry *serverlist = NULL; - +#ifdef HAVE_W32_SYSTEM + unsigned long inaddr; +#endif /* Not currently using the flags */ (void)flags; #ifdef HAVE_W32_SYSTEM - unsigned long inaddr; #ifndef HTTP_NO_WSASTARTUP init_sockets (); @@ -1724,7 +1725,7 @@ connect_server (const char *server, unsigned short port, #endif if (sock != -1) sock_close (sock); - errno = last_errno; + gpg_err_set_errno (last_errno); return -1; } return sock; @@ -1805,7 +1806,7 @@ cookie_read (void *cookie, void *buffer, size_t size) if (nread == GNUTLS_E_REHANDSHAKE) goto again; /* A client is allowed to just ignore this request. */ log_info ("TLS network read failed: %s\n", gnutls_strerror (nread)); - errno = EIO; + gpg_err_set_errno (EIO); return -1; } } @@ -1856,7 +1857,7 @@ cookie_write (void *cookie, const void *buffer, size_t size) } log_info ("TLS network write failed: %s\n", gnutls_strerror (nwritten)); - errno = EIO; + gpg_err_set_errno (EIO); return -1; } nleft -= nwritten; @@ -1868,7 +1869,7 @@ cookie_write (void *cookie, const void *buffer, size_t size) { if ( write_server (c->fd, buffer, size) ) { - errno = EIO; + gpg_err_set_errno (EIO); nwritten = -1; } else diff --git a/common/i18n.c b/common/i18n.c index db5ddf5f8..7601cf8bd 100644 --- a/common/i18n.c +++ b/common/i18n.c @@ -1,5 +1,5 @@ /* i18n.c - gettext initialization - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -51,8 +51,8 @@ char * i18n_switchto_utf8 (void) { #ifdef USE_SIMPLE_GETTEXT - gettext_select_utf8 (1); - return NULL; + /* Return an arbitrary pointer as true value. */ + return gettext_use_utf8 (1) ? (char*)(-1) : NULL; #elif defined(ENABLE_NLS) char *orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL); # ifdef HAVE_LANGINFO_CODESET @@ -82,8 +82,7 @@ void i18n_switchback (char *saved_codeset) { #ifdef USE_SIMPLE_GETTEXT - (void)saved_codeset; - gettext_select_utf8 (0); + gettext_use_utf8 (!!saved_codeset); #elif defined(ENABLE_NLS) if (saved_codeset) { diff --git a/common/iobuf.c b/common/iobuf.c index 0d2a5a5ba..356e9cdc3 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -306,7 +306,21 @@ direct_open (const char *fname, const char *mode) sm = FILE_SHARE_READ; } +#ifdef HAVE_W32CE_SYSTEM + { + wchar_t *wfname = utf8_to_wchar (fname); + if (wfname) + { + hfile = CreateFile (wfname, da, sm, NULL, cd, + FILE_ATTRIBUTE_NORMAL, NULL); + xfree (wfname); + } + else + hfile = INVALID_HANDLE_VALUE; + } +#else hfile = CreateFile (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL); +#endif return hfile; #else /*!HAVE_W32_SYSTEM*/ int oflag; @@ -1188,7 +1202,14 @@ iobuf_cancel (iobuf_t a) { /* Argg, MSDOS does not allow to remove open files. So * we have to do it here */ +#ifdef HAVE_W32CE_SYSTEM + wchar_t *wtmp = utf8_to_wchar (remove_name); + if (wtmp) + DeleteFile (wtmp); + xfree (wtmp); +#else remove (remove_name); +#endif xfree (remove_name); } #endif diff --git a/common/membuf.c b/common/membuf.c index 737930b76..dc8f6f692 100644 --- a/common/membuf.c +++ b/common/membuf.c @@ -105,7 +105,7 @@ get_membuf (membuf_t *mb, size_t *len) xfree (mb->buf); mb->buf = NULL; } - errno = mb->out_of_core; + gpg_err_set_errno (mb->out_of_core); return NULL; } diff --git a/common/signal.c b/common/signal.c index 98859a43d..2147dacab 100644 --- a/common/signal.c +++ b/common/signal.c @@ -21,7 +21,9 @@ #include <config.h> #include <stdio.h> #include <stdlib.h> -#include <signal.h> +#ifdef HAVE_SIGNAL_H +# include <signal.h> +#endif #include <unistd.h> #include <string.h> #include <errno.h> diff --git a/common/sysutils.c b/common/sysutils.c index 8e0c75c1a..822ceab61 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -130,31 +130,20 @@ enable_core_dumps (void) -/* Return a string which is used as a kind of process ID */ +/* Return a string which is used as a kind of process ID. */ const byte * -get_session_marker( size_t *rlen ) +get_session_marker (size_t *rlen) { - static byte marker[SIZEOF_UNSIGNED_LONG*2]; - static int initialized; - - if ( !initialized ) { - volatile ulong aa, bb; /* we really want the uninitialized value */ - ulong a, b; - - initialized = 1; - /* Although this marker is guessable it is not easy to use - * for a faked control packet because an attacker does not - * have enough control about the time the verification does - * take place. Of course, we can add just more random but - * than we need the random generator even for verification - * tasks - which does not make sense. */ - a = aa ^ (ulong)getpid(); - b = bb ^ (ulong)time(NULL); - memcpy( marker, &a, SIZEOF_UNSIGNED_LONG ); - memcpy( marker+SIZEOF_UNSIGNED_LONG, &b, SIZEOF_UNSIGNED_LONG ); + static byte marker[SIZEOF_UNSIGNED_LONG*2]; + static int initialized; + + if (!initialized) + { + gcry_create_nonce (marker, sizeof marker); + initialized = 1; } - *rlen = sizeof(marker); - return marker; + *rlen = sizeof (marker); + return marker; } @@ -286,7 +275,10 @@ gnupg_sleep (unsigned int seconds) int translate_sys2libc_fd (gnupg_fd_t fd, int for_write) { -#ifdef HAVE_W32_SYSTEM +#if defined(HAVE_W32CE_SYSTEM) + (void)for_write; + return (int)fd; +#elif defined(HAVE_W32_SYSTEM) int x; if (fd == GNUPG_INVALID_FD) @@ -331,8 +323,15 @@ gnupg_tmpfile (void) { #ifdef HAVE_W32_SYSTEM int attempts, n; +#ifdef HAVE_W32CE_SYSTEM + wchar_t buffer[MAX_PATH+7+12+1]; +# define mystrlen(a) wcslen (a) + wchar_t *name, *p; +#else char buffer[MAX_PATH+7+12+1]; +# define mystrlen(a) strlen (a) char *name, *p; +#endif HANDLE file; int pid = GetCurrentProcessId (); unsigned int value; @@ -344,13 +343,18 @@ gnupg_tmpfile (void) sec_attr.bInheritHandle = TRUE; n = GetTempPath (MAX_PATH+1, buffer); - if (!n || n > MAX_PATH || strlen (buffer) > MAX_PATH) + if (!n || n > MAX_PATH || mystrlen (buffer) > MAX_PATH) { - errno = ENOENT; + gpg_err_set_errno (ENOENT); return NULL; } - p = buffer + strlen (buffer); + p = buffer + mystrlen (buffer); +#ifdef HAVE_W32CE_SYSTEM + wcscpy (p, L"_gnupg"); + p += 7; +#else p = stpcpy (p, "_gnupg"); +#endif /* We try to create the directory but don't care about an error as it may already exist and the CreateFile would throw an error anyway. */ @@ -366,7 +370,11 @@ gnupg_tmpfile (void) *p++ = tohex (((value >> 28) & 0x0f)); value <<= 4; } +#ifdef HAVE_W32CE_SYSTEM + wcscpy (p, L".tmp"); +#else strcpy (p, ".tmp"); +#endif file = CreateFile (buffer, GENERIC_READ | GENERIC_WRITE, 0, @@ -377,6 +385,10 @@ gnupg_tmpfile (void) if (file != INVALID_HANDLE_VALUE) { FILE *fp; +#ifdef HAVE_W32CE_SYSTEM + int fd = (int)file; + fp = _wfdopen (fd, L"w+b"); +#else int fd = _open_osfhandle ((long)file, 0); if (fd == -1) { @@ -384,19 +396,21 @@ gnupg_tmpfile (void) return NULL; } fp = fdopen (fd, "w+b"); +#endif if (!fp) { int save = errno; close (fd); - errno = save; + gpg_err_set_errno (save); return NULL; } return fp; } Sleep (1); /* One ms as this is the granularity of GetTickCount. */ } - errno = ENOENT; + gpg_err_set_errno (ENOENT); return NULL; +#undef mystrlen #else /*!HAVE_W32_SYSTEM*/ return tmpfile (); #endif /*!HAVE_W32_SYSTEM*/ @@ -490,3 +504,18 @@ gnupg_allow_set_foregound_window (pid_t pid) (unsigned long)pid, w32_strerror (-1)); #endif } + + + +#ifdef HAVE_W32CE_SYSTEM +/* Replacement for getenv which takes care of the our use of getenv. + The code is not thread safe but we expect it to work in all cases + because it is called for the first time early enough. */ +char * +_gnupg_getenv (const char *name) +{ + (void)name; + return NULL; +} +#endif /*HAVE_W32CE_SYSTEM*/ + diff --git a/common/util.h b/common/util.h index 3eed4eba8..56678620b 100644 --- a/common/util.h +++ b/common/util.h @@ -300,6 +300,13 @@ ttyname (int fd) } #endif /* !HAVE_TTYNAME */ +#ifdef HAVE_W32CE_SYSTEM +#define getpid() GetCurrentProcessId () +char *_gnupg_getenv (const char *name); /* See sysutils.c */ +#define getenv(a) _gnupg_getenv ((a)) +#endif + + /*-- Macros to replace ctype ones to avoid locale problems. --*/ #define spacep(p) (*(p) == ' ' || *(p) == '\t') diff --git a/common/xreadline.c b/common/xreadline.c index 8ca72b75f..4ea10d75b 100644 --- a/common/xreadline.c +++ b/common/xreadline.c @@ -98,7 +98,7 @@ read_line (FILE *fp, *length_of_buffer = 0; if (max_length) *max_length = 0; - errno = save_errno; + gpg_err_set_errno (save_errno); return -1; } buffer = *addr_of_buffer; diff --git a/configure.ac b/configure.ac index abb26cfd5..f53f8d929 100644 --- a/configure.ac +++ b/configure.ac @@ -999,8 +999,8 @@ fi # AC_MSG_NOTICE([checking for header files]) AC_HEADER_STDC -AC_CHECK_HEADERS([string.h unistd.h langinfo.h termio.h locale.h getopt.h]) -AC_CHECK_HEADERS([pty.h pwd.h inttypes.h]) +AC_CHECK_HEADERS([string.h unistd.h langinfo.h termio.h locale.h getopt.h \ + pty.h pwd.h inttypes.h signal.h]) AC_HEADER_TIME |