From cvs at cvs.gnupg.org Mon Mar 1 13:49:17 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 01 Mar 2010 13:49:17 +0100 Subject: [svn] GnuPG - r5274 - trunk/jnlib Message-ID: Author: wk Date: 2010-03-01 13:49:17 +0100 (Mon, 01 Mar 2010) New Revision: 5274 Added: trunk/jnlib/t-w32-reg.c Modified: trunk/jnlib/ChangeLog trunk/jnlib/Makefile.am trunk/jnlib/w32-afunix.h trunk/jnlib/w32-reg.c Log: Finished jnlib port to CE. Modified: trunk/jnlib/ChangeLog =================================================================== --- trunk/jnlib/ChangeLog 2010-02-26 18:44:36 UTC (rev 5273) +++ trunk/jnlib/ChangeLog 2010-03-01 12:49:17 UTC (rev 5274) @@ -1,3 +1,10 @@ +2010-03-01 Werner Koch + + * t-w32-reg.c: New. + + * w32-reg.c (read_w32_registry_string) + (write_w32_registry_string): Support W32CE. + 2010-02-26 Werner Koch * t-timestuff.c: New. Modified: trunk/jnlib/Makefile.am =================================================================== --- trunk/jnlib/Makefile.am 2010-02-26 18:44:36 UTC (rev 5273) +++ trunk/jnlib/Makefile.am 2010-03-01 12:49:17 UTC (rev 5274) @@ -61,6 +61,9 @@ # so that there is no dependency on libgcrypt. # module_tests = t-stringhelp t-timestuff +if HAVE_W32_SYSTEM +module_tests += t-w32-reg +endif t_jnlib_src = t-support.c t-support.h t_jnlib_ldadd = libjnlib.a $(LIBINTL) $(LIBICONV) @@ -75,4 +78,8 @@ t_timestuff_SOURCES = t-timestuff.c $(t_jnlib_src) t_timestuff_LDADD = $(t_jnlib_ldadd) +if HAVE_W32_SYSTEM +t_w32_reg_SOURCES = t-w32-reg.c $(t_jnlib_src) +t_w32_reg_LDADD = $(t_jnlib_ldadd) +endif Added: trunk/jnlib/t-w32-reg.c =================================================================== --- trunk/jnlib/t-w32-reg.c (rev 0) +++ trunk/jnlib/t-w32-reg.c 2010-03-01 12:49:17 UTC (rev 5274) @@ -0,0 +1,70 @@ +/* t-w32-reg.c - Regression tests for W32 registry functions + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * This file is part of JNLIB. + * + * JNLIB is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 3 of + * the License, or (at your option) any later version. + * + * JNLIB is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include "mischelp.h" + +#include "t-support.h" +#include "w32help.h" + + +static void +test_read_registry (void) +{ + char *string; + +#ifdef HAVE_W32CE_SYSTEM + string = read_w32_registry_string ("HKEY_CLASSES_ROOT", + "BOOTSTRAP\\CLSID", NULL); + if (!string) + fail (0); + fprintf (stderr, "Bootstrap clsid: %s\n", string); + xfree (string); +#endif + + string = read_w32_registry_string + ("HKEY_CURRENT_USER", + "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", + "User Agent"); + if (!string) + fail (0); + fprintf (stderr, "User agent: %s\n", string); + xfree (string); +} + + + + +int +main (int argc, char **argv) +{ + (void)argc; + (void)argv; + + test_read_registry (); + + return 0; +} + Modified: trunk/jnlib/w32-afunix.h =================================================================== --- trunk/jnlib/w32-afunix.h 2010-02-26 18:44:36 UTC (rev 5273) +++ trunk/jnlib/w32-afunix.h 2010-03-01 12:49:17 UTC (rev 5274) @@ -26,6 +26,9 @@ #include #include +/* We can easiliy replace this code by the socket wrappers from libassuan. */ +#warning Please do not use this module anymore + #define DIRSEP_C '\\' #define AF_LOCAL AF_UNIX Modified: trunk/jnlib/w32-reg.c =================================================================== --- trunk/jnlib/w32-reg.c 2010-02-26 18:44:36 UTC (rev 5273) +++ trunk/jnlib/w32-reg.c 2010-03-01 12:49:17 UTC (rev 5274) @@ -28,8 +28,10 @@ #include #include "libjnlib-config.h" +#include "utf8conv.h" #include "w32help.h" + static HKEY get_root_key(const char *root) { @@ -62,16 +64,80 @@ char * read_w32_registry_string (const char *root, const char *dir, const char *name) { +#ifdef HAVE_W32CE_SYSTEM HKEY root_key, key_handle; DWORD n1, nbytes, type; char *result = NULL; + wchar_t *wdir, *wname; if ( !(root_key = get_root_key(root) ) ) return NULL; - if ( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) + wdir = utf8_to_wchar (dir); + if (!wdir) + return NULL; + + if (RegOpenKeyEx (root_key, wdir, 0, KEY_READ, &key_handle) ) { if (root) + { + jnlib_free (wdir); + return NULL; /* No need for a RegClose, so return immediately. */ + } + /* It seems to be common practise to fall back to HKLM. */ + if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, wdir, 0, KEY_READ, &key_handle) ) + { + jnlib_free (wdir); + return NULL; /* Still no need for a RegClose. */ + } + } + jnlib_free (wdir); + + if (name) + { + wname = utf8_to_wchar (name); + if (!wname) + goto leave; + } + else + wname = NULL; + + nbytes = 2; + if (RegQueryValueEx (key_handle, wname, 0, NULL, NULL, &nbytes)) + goto leave; + result = jnlib_malloc ((n1=nbytes+2)); + if (!result) + goto leave; + if (RegQueryValueEx (key_handle, wname, 0, &type, result, &n1)) + { + jnlib_free (result); + result = NULL; + goto leave; + } + result[nbytes] = 0; /* Make sure it is a string. */ + result[nbytes+1] = 0; + if (type == REG_SZ || type == REG_EXPAND_SZ) + { + wchar_t *tmp = (void*)result; + result = wchar_to_utf8 (tmp); + jnlib_free (tmp); + } + + leave: + jnlib_free (wname); + RegCloseKey (key_handle); + return result; +#else /*!HAVE_W32CE_SYSTEM*/ + HKEY root_key, key_handle; + DWORD n1, nbytes, type; + char *result = NULL; + + if ( !(root_key = get_root_key(root) ) ) + return NULL; + + if (RegOpenKeyEx (root_key, dir, 0, KEY_READ, &key_handle) ) + { + if (root) return NULL; /* No need for a RegClose, so return immediately. */ /* It seems to be common practise to fall back to HKLM. */ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, dir, 0, KEY_READ, &key_handle) ) @@ -142,15 +208,79 @@ leave: RegCloseKey (key_handle); return result; +#endif /*!HAVE_W32CE_SYSTEM*/ } +/* Note: This code is not well tested. However, it is not used in + GnuPG. */ int write_w32_registry_string (const char *root, const char *dir, const char *name, const char *value) { HKEY root_key, reg_key; +#ifdef HAVE_W32CE_SYSTEM + wchar_t *wdir, *wname, *wvalue; + DWORD disp; + + if ( !(root_key = get_root_key(root) ) ) + return -1; + + wdir = utf8_to_wchar (dir); + if (!wdir) + return -1; + + if (RegOpenKeyEx (root_key, wdir, 0, 0, ®_key)) + { + jnlib_free (wdir); + return -1; + } + jnlib_free (wdir); + if (name) + { + wname = utf8_to_wchar (name); + if (!wname) + return -1; + } + else + wname = NULL; + + wvalue = utf8_to_wchar (value); + if (wvalue) + { + jnlib_free (wname); + return -1; + } + + if (RegSetValueEx (reg_key, wname, 0, REG_SZ, + (BYTE *)wvalue, wcslen (wvalue)) != ERROR_SUCCESS ) + { + + if (RegCreateKeyEx (root_key, wname, 0, NULL, 0, 0, NULL, + ®_key, &disp) != ERROR_SUCCESS) + { + RegCloseKey(reg_key); + jnlib_free (wname); + jnlib_free (wvalue); + return -1; + } + if (RegSetValueEx (reg_key, wname, 0, REG_SZ, + (BYTE *)wvalue, wcslen (wvalue)) != ERROR_SUCCESS ) + { + RegCloseKey(reg_key); + jnlib_free (wname); + jnlib_free (wvalue); + return -1; + } + } + + jnlib_free (wname); + jnlib_free (wvalue); + RegCloseKey (reg_key); + return 0; +#else /*!HAVE_W32CE_SYSTEM*/ + if ( !(root_key = get_root_key(root) ) ) return -1; @@ -175,8 +305,8 @@ } RegCloseKey (reg_key); - return 0; +#endif /*!HAVE_W32CE_SYSTEM*/ } #endif /*HAVE_W32_SYSTEM*/ From cvs at cvs.gnupg.org Mon Mar 1 20:54:41 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 01 Mar 2010 20:54:41 +0100 Subject: [svn] gpg-error - r234 - in trunk: . src Message-ID: Author: wk Date: 2010-03-01 20:54:41 +0100 (Mon, 01 Mar 2010) New Revision: 234 Modified: trunk/ChangeLog trunk/autogen.sh trunk/src/mkw32errmap.c trunk/src/w32-gettext.c Log: Add a mapping for ESPIPE on W32CE. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-02-17 17:08:04 UTC (rev 233) +++ trunk/ChangeLog 2010-03-01 19:54:41 UTC (rev 234) @@ -1,3 +1,7 @@ +2010-03-01 Werner Koch + + * src/mkw32errmap.c: Map ESPIPE. + 2010-02-17 Werner Koch * src/Makefile.am: Revert last change. Modified: trunk/autogen.sh =================================================================== --- trunk/autogen.sh 2010-02-17 17:08:04 UTC (rev 233) +++ trunk/autogen.sh 2010-03-01 19:54:41 UTC (rev 234) @@ -103,7 +103,7 @@ fi ./configure --enable-maintainer-mode --prefix=${w32root} \ - --host=${host} --build=${build} + --host=${host} --build=${build} "$@" exit $? fi @@ -222,4 +222,6 @@ echo "Running autoconf${FORCE} ..." $AUTOCONF${FORCE} -echo "You may now run \"./configure --enable-maintainer-mode && make\"." +echo "You may now run + ./configure --enable-maintainer-mode && make +" Modified: trunk/src/mkw32errmap.c =================================================================== --- trunk/src/mkw32errmap.c 2010-02-17 17:08:04 UTC (rev 233) +++ trunk/src/mkw32errmap.c 2010-03-01 19:54:41 UTC (rev 234) @@ -79,7 +79,6 @@ #ifdef RESOLVE_MACROS #define X(a,b) \ {&mkw32errmap_marker, (a), (b)} - X( "EPERM", ERROR_CANNOT_MAKE ), X( "ENOENT", ERROR_FILE_NOT_FOUND ), X( "EINTR", ERROR_INVALID_AT_INTERRUPT_TIME ), @@ -98,6 +97,8 @@ X( "EXDEV", ERROR_NOT_SAME_DEVICE ), X( "ENODEV", ERROR_BAD_DEVICE ), + /* FIXME: ERROR_DEV_NOT_EXIST */ + X( "ENOTDIR",ERROR_DIRECTORY ), X( "EINVAL", ERROR_INVALID_PARAMETER ), X( "ENFILE", ERROR_NO_MORE_FILES ), @@ -111,11 +112,11 @@ X( "ENOLCK", ERROR_SHARING_BUFFER_EXCEEDED ), X( "ENOSYS", ERROR_NOT_SUPPORTED ), X( "ENOTEMPTY",ERROR_DIR_NOT_EMPTY ), + X( "ESPIPE", ERROR_SEEK_ON_DEVICE ), #if 0 /* FIXME: Find appropriate mappings. */ X( "EILSEQ", ), X( "EDOM", ), X( "EMLINK", ), - X( "ESPIPE", ), /* Invalid seek (seek on a pipe?) */ X( "ESRCH", ), /* No such process */ X( "E2BIG", ), /* Arg list too long */ X( "ENOEXEC", ), /* Exec format error */ Modified: trunk/src/w32-gettext.c =================================================================== --- trunk/src/w32-gettext.c 2010-02-17 17:08:04 UTC (rev 233) +++ trunk/src/w32-gettext.c 2010-03-01 19:54:41 UTC (rev 234) @@ -1837,7 +1837,7 @@ /* With a VALUE of 1 switch the gettext functions into utf8 mode. That is the strings are returned without translation to the native - charset. A VALUE of 0 swicthes back to trnslated strings. A VALUE + charset. A VALUE of 0 switches back to translated strings. A VALUE of -1 returns the current value. */ int _gpg_w32_gettext_use_utf8 (int value) From cvs at cvs.gnupg.org Tue Mar 2 13:27:44 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 02 Mar 2010 13:27:44 +0100 Subject: [svn] pinentry - r220 - in trunk: . qt4 Message-ID: Author: wk Date: 2010-03-02 13:27:43 +0100 (Tue, 02 Mar 2010) New Revision: 220 Modified: trunk/ChangeLog trunk/qt4/main.cpp Log: invalid utf8 workaround Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-02-19 15:07:24 UTC (rev 219) +++ trunk/ChangeLog 2010-03-02 12:27:43 UTC (rev 220) @@ -1,3 +1,25 @@ +2010-03-02 Werner Koch + + * qt4/main.cpp (from_utf8): Add extra braces for clarity. + (main): Copy the fixed --display string. + +2010-02-25 Marc Mutz (wk) + + * qt4/main.cpp (from_utf8): don't throw InvalidUtf8(); for now, + fall back to QString::fromLocal8Bit() + +2010-02-22 Marc Mutz (wk) + + * qt4/main.cpp (InvalidUtf8): New exception class. + (from_utf8): wrapper around QString::fromUtf8 throwing + InvalidUtf8. + (qt_cmd_handler): Use from_utf8 instead of QString::fromUtf8. + (qt_cmd_handler_ex): New wrapper around qt_cmd_handler. + (pinentry_cmd_handler): Use qt_cmd_handler_ex. + + * qt4/main.cpp (qt_cmd_handler): Also handle accels in + SET{OK,NOTOK,CANCEL} string. + 2010-02-19 Marc Mutz (wk) * qt4/main.cpp (qt_cmd_handler), qt4/pinentrydialog.cpp Modified: trunk/qt4/main.cpp =================================================================== --- trunk/qt4/main.cpp 2010-02-19 15:07:24 UTC (rev 219) +++ trunk/qt4/main.cpp 2010-03-02 12:27:43 UTC (rev 220) @@ -43,6 +43,7 @@ #include #include +#include #ifdef FALLBACK_CURSES #include @@ -102,6 +103,29 @@ } }; +namespace { + class InvalidUtf8 : public std::invalid_argument { + public: + InvalidUtf8() : std::invalid_argument( "invalid utf8" ) {} + ~InvalidUtf8() throw() {} + }; +} + +static const bool GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8 = false; + +static QString from_utf8( const char * s ) { + const QString result = QString::fromUtf8( s ); + if ( result.contains( QChar::ReplacementCharacter ) ) + { + if ( GPG_AGENT_IS_PORTED_TO_ONLY_SEND_UTF8 ) + throw InvalidUtf8(); + else + return QString::fromLocal8Bit( s ); + } + + return result; +} + static int qt_cmd_handler (pinentry_t pe) { @@ -114,15 +138,15 @@ int want_pass = !!pe->pin; const QString ok = - pe->ok ? QString::fromUtf8( pe->ok ) : - pe->default_ok ? escape_accel( QString::fromUtf8( pe->default_ok ) ) : + pe->ok ? escape_accel( from_utf8( pe->ok ) ) : + pe->default_ok ? escape_accel( from_utf8( pe->default_ok ) ) : /* else */ QLatin1String( "&OK" ) ; const QString cancel = - pe->cancel ? QString::fromUtf8( pe->cancel ) : - pe->default_cancel ? escape_accel( QString::fromUtf8( pe->default_cancel ) ) : + pe->cancel ? escape_accel( from_utf8( pe->cancel ) ) : + pe->default_cancel ? escape_accel( from_utf8( pe->default_cancel ) ) : /* else */ QLatin1String( "&Cancel" ) ; const QString title = - pe->title ? QString::fromUtf8( pe->title ) : + pe->title ? from_utf8( pe->title ) : /* else */ QLatin1String( "pinentry-qt4" ) ; @@ -131,10 +155,10 @@ PinEntryDialog pinentry (parent, 0, true, !!pe->quality_bar); pinentry.setPinentryInfo (pe); - pinentry.setPrompt (escape_accel (QString::fromUtf8 (pe->prompt)) ); - pinentry.setDescription (QString::fromUtf8 (pe->description)); + pinentry.setPrompt (escape_accel (from_utf8 (pe->prompt)) ); + pinentry.setDescription (from_utf8 (pe->description)); if ( pe->title ) - pinentry.setWindowTitle( QString::fromUtf8( pe->title ) ); + pinentry.setWindowTitle( from_utf8( pe->title ) ); /* If we reuse the same dialog window. */ pinentry.setPin (secqstring()); @@ -142,11 +166,11 @@ pinentry.setOkText (ok); pinentry.setCancelText (cancel); if (pe->error) - pinentry.setError (QString::fromUtf8 (pe->error)); + pinentry.setError (from_utf8 (pe->error)); if (pe->quality_bar) - pinentry.setQualityBar (QString::fromUtf8 (pe->quality_bar)); + pinentry.setQualityBar (from_utf8 (pe->quality_bar)); if (pe->quality_bar_tt) - pinentry.setQualityBarTT (QString::fromUtf8 (pe->quality_bar_tt)); + pinentry.setQualityBarTT (from_utf8 (pe->quality_bar_tt)); bool ret = pinentry.exec (); if (!ret) @@ -169,8 +193,8 @@ } else { - const QString desc = pe->description ? QString::fromUtf8 ( pe->description ) : QString(); - const QString notok = pe->notok ? QString::fromUtf8 ( pe->notok ) : QString(); + const QString desc = pe->description ? from_utf8 ( pe->description ) : QString(); + const QString notok = pe->notok ? escape_accel (from_utf8 ( pe->notok )) : QString(); const QMessageBox::StandardButtons buttons = pe->one_button ? QMessageBox::Ok : @@ -211,8 +235,22 @@ } } -pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler; +static int +qt_cmd_handler_ex (pinentry_t pe) +{ + try { + return qt_cmd_handler (pe); + } catch ( const InvalidUtf8 & ) { + pe->locale_err = true; + return pe->pin ? -1 : false ; + } catch ( ... ) { + pe->canceled = true; + return pe->pin ? -1 : false ; + } +} +pinentry_cmd_handler_t pinentry_cmd_handler = qt_cmd_handler_ex; + int main (int argc, char *argv[]) { @@ -249,7 +287,8 @@ for (done=0,p=*new_argv,i=0; i < argc; i++) if (!done && !strcmp (argv[i], "--display")) { - new_argv[i] = "-display"; + new_argv[i] = strcpy (p, argv[i]+1); + p += strlen (argv[i]+1) + 1; done = 1; } else From cvs at cvs.gnupg.org Tue Mar 2 22:25:08 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 02 Mar 2010 22:25:08 +0100 Subject: [svn] GnuPG - r5275 - in trunk: . common Message-ID: Author: wk Date: 2010-03-02 22:25:08 +0100 (Tue, 02 Mar 2010) New Revision: 5275 Modified: trunk/common/ChangeLog trunk/common/convert.c trunk/common/estream-printf.c trunk/common/estream-printf.h trunk/common/estream.c trunk/common/estream.h trunk/common/gettime.c trunk/common/homedir.c trunk/common/http.c trunk/common/i18n.c trunk/common/iobuf.c trunk/common/membuf.c trunk/common/signal.c trunk/common/sysutils.c trunk/common/util.h trunk/common/xreadline.c trunk/configure.ac Log: First steps towards the W32CE port Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/ChangeLog 2010-03-02 21:25:08 UTC (rev 5275) @@ -1,3 +1,33 @@ +2010-03-02 Werner Koch + + * estream.c, estream.h, estream-printf.c, estream-printf.h: Update + from libestream. + +2010-03-01 Werner Koch + + * 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 * 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 @@ -481,7 +511,7 @@ 2007-11-05 Werner Koch - * 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 * gettime.c (check_isotime, add_isotime): New. Originally written @@ -527,7 +557,7 @@ 2007-08-22 Werner Koch 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 - * t-gettime.c: New. + * t-gettime.c: New. * gettime.c (isotime2epoch, epoch2isotime): New. 2007-07-04 Werner Koch @@ -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 * 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 @@ -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 * 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 @@ -854,9 +884,9 @@ 2006-10-17 Werner Koch - * 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 (wk) - + * iobuf.c (iobuf_unread): New. 2006-09-22 Werner Koch @@ -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 * 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 * dynload.h. New. W32 wrapper around the dynload mechanism. - + 2003-07-15 Werner Koch - * 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 @@ -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 - * maperror.c: Add mapping for Not_Trusted. + * maperror.c: Add mapping for Not_Trusted. 2002-01-11 Werner Koch @@ -1570,11 +1600,11 @@ * 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 modifications, as long as this notice is preserved. @@ -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. - - Modified: trunk/common/convert.c =================================================================== --- trunk/common/convert.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/convert.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -115,7 +115,7 @@ 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 @@ { if (r_count) *r_count = 0; - errno = EINVAL; + gpg_err_set_errno (EINVAL); return NULL; } if (r_count) Modified: trunk/common/estream-printf.c =================================================================== --- trunk/common/estream-printf.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/estream-printf.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -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 . + * + * 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 #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 #include #include @@ -57,6 +98,9 @@ #ifdef HAVE_LANGINFO_THOUSANDS_SEP #include #endif +#ifdef HAVE_W32CE_SYSTEM +#include /* ERRNO replacement. */ +#endif #ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE # include _ESTREAM_PRINTF_EXTRA_INCLUDE #endif @@ -77,7 +121,14 @@ #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 #define DIM(array) (sizeof (array) / sizeof (*array)) @@ -634,7 +685,7 @@ return 0; /* Success. */ leave_einval: - errno = EINVAL; + _set_errno (EINVAL); leave: if (argspecs != *argspecs_addr) free (argspecs); @@ -1540,7 +1591,7 @@ goto leave; leave_einval: - errno = EINVAL; + _set_errno (EINVAL); leave_error: rc = -1; leave: @@ -1702,7 +1753,7 @@ { /* 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 @@ if (rc != -1 && parm.error_flag) { rc = -1; - errno = parm.error_flag; + _set_errno (parm.error_flag); } if (rc == -1) { Modified: trunk/common/estream-printf.h =================================================================== --- trunk/common/estream-printf.h 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/estream-printf.h 2010-03-02 21:25:08 UTC (rev 5275) @@ -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 . + * + * 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 Modified: trunk/common/estream.c =================================================================== --- trunk/common/estream.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/estream.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -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 . + * + * 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 @@ -44,6 +81,9 @@ #ifdef HAVE_W32_SYSTEM # include #endif +#ifdef HAVE_W32CE_SYSTEM +# include /* ERRNO replacement. */ +#endif #ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */ # undef HAVE_PTH @@ -76,6 +116,13 @@ #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 @@ if (!data && (data_n || data_len)) { - errno = EINVAL; + _set_errno (EINVAL); return -1; } @@ -511,7 +558,7 @@ newsize = mem_cookie->memory_size + (nleft - size); if (newsize < mem_cookie->offset) { - errno = EINVAL; + _set_errno (EINVAL); return -1; } @@ -522,7 +569,7 @@ 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 @@ /* 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 @@ break; default: - errno = EINVAL; + _set_errno (EINVAL); return -1; } @@ -592,14 +639,14 @@ 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 @@ if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit) { - errno = ENOSPC; + _set_errno (ENOSPC); return -1; } @@ -971,7 +1018,7 @@ oflags = O_APPEND | O_CREAT; break; default: - errno = EINVAL; + _set_errno (EINVAL); return -1; } for (mode++; *mode; mode++) @@ -1010,7 +1057,7 @@ if (!stream->intern->func_read) { - errno = EOPNOTSUPP; + _set_errno (EOPNOTSUPP); err = -1; } else @@ -1173,7 +1220,7 @@ 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 @@ if (! func_seek) { - errno = EOPNOTSUPP; + _set_errno (EOPNOTSUPP); err = -1; goto out; } @@ -1730,7 +1777,7 @@ if (stream->data_offset + size > stream->data_len) { - errno = EINVAL; + _set_errno (EINVAL); err = -1; } else @@ -2309,7 +2356,7 @@ 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 @@ { /* 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 @@ 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 @@ { #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 @@ *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 @@ 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 @@ } else { - errno = EINVAL; + _set_errno (EINVAL); err = -1; } Modified: trunk/common/estream.h =================================================================== --- trunk/common/estream.h 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/estream.h 2010-03-02 21:25:08 UTC (rev 5275) @@ -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 . + * + * 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 Modified: trunk/common/gettime.c =================================================================== --- trunk/common/gettime.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/gettime.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -500,7 +500,7 @@ 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); Modified: trunk/common/homedir.c =================================================================== --- trunk/common/homedir.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/homedir.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -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 @@ /* 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 @@ if (!got_dir) { char *p; + int rc; - if ( !GetModuleFileName ( NULL, dir, MAX_PATH) ) +#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; Modified: trunk/common/http.c =================================================================== --- trunk/common/http.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/http.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -1225,7 +1225,7 @@ 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 @@ 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 @@ #endif if (sock != -1) sock_close (sock); - errno = last_errno; + gpg_err_set_errno (last_errno); return -1; } return sock; @@ -1805,7 +1806,7 @@ 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 @@ } 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 @@ { if ( write_server (c->fd, buffer, size) ) { - errno = EIO; + gpg_err_set_errno (EIO); nwritten = -1; } else Modified: trunk/common/i18n.c =================================================================== --- trunk/common/i18n.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/i18n.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -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 @@ 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 @@ 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) { Modified: trunk/common/iobuf.c =================================================================== --- trunk/common/iobuf.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/iobuf.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -306,7 +306,21 @@ 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 @@ { /* 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 Modified: trunk/common/membuf.c =================================================================== --- trunk/common/membuf.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/membuf.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -105,7 +105,7 @@ xfree (mb->buf); mb->buf = NULL; } - errno = mb->out_of_core; + gpg_err_set_errno (mb->out_of_core); return NULL; } Modified: trunk/common/signal.c =================================================================== --- trunk/common/signal.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/signal.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -21,7 +21,9 @@ #include #include #include -#include +#ifdef HAVE_SIGNAL_H +# include +#endif #include #include #include Modified: trunk/common/sysutils.c =================================================================== --- trunk/common/sysutils.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/sysutils.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -130,31 +130,20 @@ -/* 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 @@ 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 @@ { #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 @@ 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 @@ *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 @@ 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 @@ 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 @@ (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*/ + Modified: trunk/common/util.h =================================================================== --- trunk/common/util.h 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/util.h 2010-03-02 21:25:08 UTC (rev 5275) @@ -300,7 +300,14 @@ } #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') #define digitp(p) (*(p) >= '0' && *(p) <= '9') Modified: trunk/common/xreadline.c =================================================================== --- trunk/common/xreadline.c 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/common/xreadline.c 2010-03-02 21:25:08 UTC (rev 5275) @@ -98,7 +98,7 @@ *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; Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-01 12:49:17 UTC (rev 5274) +++ trunk/configure.ac 2010-03-02 21:25:08 UTC (rev 5275) @@ -999,8 +999,8 @@ # 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 From cvs at cvs.gnupg.org Wed Mar 3 15:08:22 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 03 Mar 2010 15:08:22 +0100 Subject: [svn] pinentry - r221 - trunk Message-ID: Author: wk Date: 2010-03-03 15:08:21 +0100 (Wed, 03 Mar 2010) New Revision: 221 Modified: trunk/ChangeLog trunk/NEWS trunk/configure.ac Log: Prepare a release. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-02 12:27:43 UTC (rev 220) +++ trunk/ChangeLog 2010-03-03 14:08:21 UTC (rev 221) @@ -1,3 +1,7 @@ +2010-03-03 Werner Koch + + Release 0.8.0. + 2010-03-02 Werner Koch * qt4/main.cpp (from_utf8): Add extra braces for clarity. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-02 12:27:43 UTC (rev 220) +++ trunk/NEWS 2010-03-03 14:08:21 UTC (rev 221) @@ -1,7 +1,11 @@ -Noteworthy changes in version 0.7.7 (unreleased) +Noteworthy changes in version 0.8.0 (2010-03-03) ------------------------------------------------ + * Beautified the qt4 pinentry + * Minor enhancements. + + Noteworthy changes in version 0.7.6 (2009-06-19) ------------------------------------------------ Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-02 12:27:43 UTC (rev 220) +++ trunk/configure.ac 2010-03-03 14:08:21 UTC (rev 221) @@ -31,8 +31,8 @@ # specific feature can already be done under the assumption that the # SVN version is the most recent one in a branch. To disable the SVN # version for the real release, set the my_issvn macro to no. -m4_define(my_version, [0.7.7]) -m4_define(my_issvn, [yes]) +m4_define(my_version, [0.8.0]) +m4_define(my_issvn, [no]) m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)])) From cvs at cvs.gnupg.org Wed Mar 3 15:42:33 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 03 Mar 2010 15:42:33 +0100 Subject: [svn] pinentry - r222 - tags Message-ID: Author: wk Date: 2010-03-03 15:42:33 +0100 (Wed, 03 Mar 2010) New Revision: 222 Added: tags/pinentry-0.8.0/ Log: Released 0.8.0. From cvs at cvs.gnupg.org Fri Mar 5 12:52:14 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 05 Mar 2010 12:52:14 +0100 Subject: [svn] GnuPG - r5276 - branches/STABLE-BRANCH-2-0/doc Message-ID: Author: wk Date: 2010-03-05 12:52:13 +0100 (Fri, 05 Mar 2010) New Revision: 5276 Modified: branches/STABLE-BRANCH-2-0/doc/ChangeLog branches/STABLE-BRANCH-2-0/doc/gpg.texi Log: Minor change Modified: branches/STABLE-BRANCH-2-0/doc/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/doc/ChangeLog 2010-03-02 21:25:08 UTC (rev 5275) +++ branches/STABLE-BRANCH-2-0/doc/ChangeLog 2010-03-05 11:52:13 UTC (rev 5276) @@ -1,3 +1,9 @@ +2010-03-05 Werner Koch + + * gpg.texi (GPG Configuration Options): Mention that + show-uid-validity does only work with public keys. Noted by + Daniel Kahn Gillmor. + 2009-08-24 David Shaw * gpg.texi: Suggested new ordering for --edit-key. Modified: branches/STABLE-BRANCH-2-0/doc/gpg.texi =================================================================== --- branches/STABLE-BRANCH-2-0/doc/gpg.texi 2010-03-02 21:25:08 UTC (rev 5275) +++ branches/STABLE-BRANCH-2-0/doc/gpg.texi 2010-03-05 11:52:13 UTC (rev 5276) @@ -1043,7 +1043,7 @@ @option{--check-sigs} listings. Defaults to no. @item show-uid-validity -Display the calculated validity of user IDs during key listings. +Display the calculated validity of user IDs during public key listings. Defaults to no. @item show-unusable-uids From cvs at cvs.gnupg.org Fri Mar 5 18:55:58 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 05 Mar 2010 18:55:58 +0100 Subject: [svn] assuan - r359 - in trunk: . src Message-ID: Author: wk Date: 2010-03-05 18:55:57 +0100 (Fri, 05 Mar 2010) New Revision: 359 Modified: trunk/README trunk/src/ChangeLog trunk/src/gpgcemgr.c Log: Add options and documentation for gpgcedev. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-02-25 13:03:16 UTC (rev 358) +++ trunk/src/ChangeLog 2010-03-05 17:55:57 UTC (rev 359) @@ -1,3 +1,7 @@ +2010-03-05 Werner Koch + + * gpgcemgr.c: Add options to register a device and activate it. + 2010-02-24 Werner Koch * gpgcemgr.c: New. Modified: trunk/README =================================================================== --- trunk/README 2010-02-25 13:03:16 UTC (rev 358) +++ trunk/README 2010-03-05 17:55:57 UTC (rev 359) @@ -13,3 +13,23 @@ The primary FTP site is ftp://ftp.gnupg.org/gcrypt/libassuan. + + +Notes for Windows CE: +---------------------- + +Libassuan supports WindowsCE (tested with WindowsMobile 6.5). To +install it, copy libassuan-0.dll into a location where DLL are found +and install the included gpgcedev driver: First copy "gpgcedev.dll" +into the root directory, second run the included program gpgcemgr on +the device: "gpgcemgr --register". This creates the necessary +registry keys. In case the copy step fails, the driver may still be +in use: Close all applications using that driver, run "gpgcemgr +--deactivate" to deactivate the running driver and try again. + +Registry keys created by "gpgcemgr --register" are: + + Drivers\\GnuPG_Device\dll -> "gpgcedev.dll" + Drivers\\GnuPG_Device\prefix -> "GPG" + Drivers\\GnuPG_Device\Index -> 1 (dword) + Modified: trunk/src/gpgcemgr.c =================================================================== --- trunk/src/gpgcemgr.c 2010-02-25 13:03:16 UTC (rev 358) +++ trunk/src/gpgcemgr.c 2010-03-05 17:55:57 UTC (rev 359) @@ -24,11 +24,45 @@ #define PGM "gpgcemgr" -#warning Fixme: Add support to create the device. +#define GPGCEDEV_KEY_NAME L"Drivers\\GnuPG_Device" +#define GPGCEDEV_DLL_NAME L"gpgcedev.dll" +#define GPGCEDEV_PREFIX L"GPG" -int -main (int argc, char **argv) + +static int +install (void) { + HKEY handle; + DWORD disp, dw; + + if (RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPGCEDEV_KEY_NAME, 0, NULL, 0, + KEY_WRITE, NULL, &handle, &disp)) + { + fprintf (stderr, PGM": error creating registry key: rc=%d\n", + (int)GetLastError ()); + return 1; + } + + RegSetValueEx (handle, L"dll", 0, REG_SZ, + (void*)GPGCEDEV_DLL_NAME, sizeof (GPGCEDEV_DLL_NAME)); + RegSetValueEx (handle, L"prefix", 0, REG_SZ, + (void*)GPGCEDEV_PREFIX, sizeof (GPGCEDEV_PREFIX)); + + dw = 1; + RegSetValueEx (handle, L"Index", 0, REG_DWORD, (void*)&dw, sizeof dw); + + RegCloseKey (handle); + + fprintf (stderr, PGM": registry key created\n"); + + + return 0; +} + + +static int +deinstall (void) +{ int result = 0; HANDLE shd; DEVMGR_DEVICE_INFORMATION dinfo; @@ -63,6 +97,40 @@ } FindClose (shd); } + + return result; +} + + + +int +main (int argc, char **argv) +{ + int result = 0; + + if (argc > 1 && !strcmp (argv[1], "--register")) + result = install (); + else if (argc > 1 && !strcmp (argv[1], "--deactivate")) + result = deinstall (); + else if (argc > 1 && !strcmp (argv[1], "--activate")) + { + /* This is mainly for testing. The activation is usually done + right before the device is opened. */ + if (ActivateDevice (GPGCEDEV_DLL_NAME, 0) == INVALID_HANDLE_VALUE) + { + fprintf (stderr, PGM": ActivateDevice failed: rc=%d\n", + (int)GetLastError ()); + result = 1; + } + else + fprintf (stderr, PGM": device activated\n"); + } + else + { + fprintf (stderr, "usage: " PGM " --register|--deactivate|--activate\n"); + result = 1; + } + fflush (stdout); fflush (stderr); Sleep (1000); From cvs at cvs.gnupg.org Mon Mar 8 13:18:20 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 13:18:20 +0100 Subject: [svn] GnuPG - r5277 - trunk/common Message-ID: Author: wk Date: 2010-03-08 13:18:19 +0100 (Mon, 08 Mar 2010) New Revision: 5277 Modified: trunk/common/ChangeLog trunk/common/exechelp.c trunk/common/exechelp.h Log: Changes required to use estream in gpgsm. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-05 11:52:13 UTC (rev 5276) +++ trunk/common/ChangeLog 2010-03-08 12:18:19 UTC (rev 5277) @@ -1,3 +1,9 @@ +2010-03-08 Werner Koch + + * exechelp.h: Include "estream.h". + + * exechelp.c (gnupg_spawn_process): Change OUTFILE to an estream_t. + 2010-03-02 Werner Koch * estream.c, estream.h, estream-printf.c, estream-printf.h: Update Modified: trunk/common/exechelp.c =================================================================== --- trunk/common/exechelp.c 2010-03-05 11:52:13 UTC (rev 5276) +++ trunk/common/exechelp.c 2010-03-08 12:18:19 UTC (rev 5277) @@ -1,5 +1,6 @@ /* exechelp.c - fork and exec helpers - * Copyright (C) 2004, 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2004, 2007, 2008, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -174,7 +175,7 @@ close (fd); } - errno = 0; + gpg_err_set_errno (0); } @@ -555,7 +556,7 @@ Returns 0 on success or an error code. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - FILE *infile, FILE *outfile, + FILE *infile, estream_t outfile, void (*preexec)(void), unsigned int flags, FILE **statusfile, pid_t *pid) { @@ -582,7 +583,7 @@ fflush (infile); rewind (infile); fd = _get_osfhandle (fileno (infile)); - fdout = _get_osfhandle (fileno (outfile)); + fdout = _get_osfhandle (es_fileno (outfile)); if (fd == -1 || fdout == -1) log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); @@ -690,7 +691,7 @@ fflush (infile); rewind (infile); fd = fileno (infile); - fdout = fileno (outfile); + fdout = es_fileno (outfile); if (fd == -1 || fdout == -1) log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); Modified: trunk/common/exechelp.h =================================================================== --- trunk/common/exechelp.h 2010-03-05 11:52:13 UTC (rev 5276) +++ trunk/common/exechelp.h 2010-03-08 12:18:19 UTC (rev 5277) @@ -20,6 +20,9 @@ #ifndef GNUPG_COMMON_EXECHELP_H #define GNUPG_COMMON_EXECHELP_H +#include "estream.h" + + /* Return the maximum number of currently allowed file descriptors. Only useful on POSIX systems. */ int get_max_fds (void); @@ -59,7 +62,7 @@ details. Calling gnupg_wait_process is required. Returns 0 on success or an error code. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - FILE *infile, FILE *outfile, + FILE *infile, estream_t outfile, void (*preexec)(void), unsigned int flags, FILE **statusfile, pid_t *pid); From cvs at cvs.gnupg.org Mon Mar 8 13:22:18 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 13:22:18 +0100 Subject: [svn] GnuPG - r5278 - in trunk: sm tools Message-ID: Author: wk Date: 2010-03-08 13:22:18 +0100 (Mon, 08 Mar 2010) New Revision: 5278 Modified: trunk/sm/ChangeLog trunk/sm/base64.c trunk/sm/decrypt.c trunk/sm/encrypt.c trunk/sm/export.c trunk/sm/gpgsm.c trunk/sm/gpgsm.h trunk/sm/import.c trunk/sm/server.c trunk/sm/sign.c trunk/sm/verify.c trunk/tools/ChangeLog trunk/tools/no-libgcrypt.c Log: Replace use stdio by estream functions. Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/ChangeLog 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,3 +1,29 @@ +2010-03-08 Werner Koch + + * server.c (cmd_encrypt, cmd_decrypt, cmd_verify, cmd_sign): Avoid + dup call by using es_fdopen_nc. + (do_listkeys): Use es_fdopen_nc instead of dup and es_fdopen. + * export.c (popen_protect_tool): Change OUTFILE to an estream_t. + (export_p12): Change OUTFP and arg RETFP to an estream_t. + (gpgsm_p12_export): Change DATAFP to an estream_t. + * import.c (import_one): Change CERTFP and arg FP to an estream_t. + (popen_protect_tool): Ditto for OUTFILE. + (parse_p12): Change CERTFP to an estream_t. + * sign.c (hash_data, hash_and_copy_data): Use estream. + (gpgsm_sign): Change arg OUT_FP to an estream_t. + * verify.c (gpgsm_verify): Rename FP to IN_FP. Change FP and arg + OUT_FP to an estream_t. + (hash_data): Use estream. + * base64.c (struct reader_cb_parm_s): Change FP to an estream_t. + (gpgsm_create_reader): Ditto. + (simple_reader_cb, base64_reader_cb): Adjust accordingly. + * decrypt.c (gpgsm_decrypt): Change OUT_FP and IN_FP to an estream_t. + * encrypt.c (gpgsm_encrypt): Change OUT_FP to an estream_t. Ditto + for DATA_FD. + (encrypt_cb): Use estream. + * gpgsm.c (main) : Use estream + functions. + 2009-12-14 Werner Koch * server.c (cmd_passwd): New. @@ -324,7 +350,7 @@ * server.c (cmd_encrypt): Ditto. (cmd_decrypt, cmd_verify, cmd_import, cmd_genkey): Ditto. * call-agent.c (gpgsm_scd_pksign): Ditto. - * call-dirmngr.c (release_dirmngr, release_dirmngr2) + * call-dirmngr.c (release_dirmngr, release_dirmngr2) (run_command_cb): Ditto. * certlist.c (gpgsm_add_cert_to_certlist): Ditto. * certchain.c (find_up_dirmngr): Ditto. @@ -364,7 +390,7 @@ 2008-09-03 Werner Koch * sign.c (MY_GCRY_MD_SHA224): New, so that we don't need libgcrypt - 1.2. + 1.2. 2008-08-13 Werner Koch @@ -468,7 +494,7 @@ (gpgsm_walk_cert_chain): Use it here. * gpgsm.c: Add option --no-common-certs-import. - + * certchain.c (find_up_dirmngr, find_up, do_validate_chain) (check_cert_policy): Be more silent with --quiet. @@ -481,8 +507,8 @@ * server.c (option_handler): Add option allow-pinentry-notify. (gpgsm_proxy_pinentry_notify): New. * call-agent.c (default_inq_cb): New. - (gpgsm_agent_pksign, gpgsm_scd_pksign, gpgsm_agent_readkey) - (gpgsm_agent_istrusted, gpgsm_agent_marktrusted) + (gpgsm_agent_pksign, gpgsm_scd_pksign, gpgsm_agent_readkey) + (gpgsm_agent_istrusted, gpgsm_agent_marktrusted) (gpgsm_agent_passwd, gpgsm_agent_get_confirmation): Call it. (struct cipher_parm_s, struct genkey_parm_s): Add field CTRL. (inq_ciphertext_cb): Test keyword and fallback to default_inq_cb. @@ -580,7 +606,7 @@ * gpgsm.c (get_status_string): Remove. * gpgsm.h: Include status.h instead of errors.h. - + 2007-10-19 Werner Koch * qualified.c (gpgsm_qualified_consent): Use i18N-swicth functions. @@ -594,7 +620,7 @@ 2007-08-24 Werner Koch - * Makefile.am (common_libs): Swap libkeybox and jnlib. + * Makefile.am (common_libs): Swap libkeybox and jnlib. 2007-08-23 Werner Koch @@ -614,7 +640,7 @@ * import.c (parse_p12): Use gnupg_tmpfile. * export.c (export_p12): Ditto. - + 2007-08-20 Werner Koch * certreqgen.c (read_parameters): Change FP to an estream_t. @@ -669,7 +695,7 @@ 2007-08-06 Werner Koch Implementation of the chain model. - + * gpgsm.h (struct rootca_flags_s): Define new members VALID and CHAIN_MODEL. * call-agent.c (gpgsm_agent_istrusted): Mark ROOTCA_FLAGS valid. @@ -721,7 +747,7 @@ when passing an int value. * server.c (cmd_encrypt, cmd_decrypt, cmd_verify, cmd_import) (cmd_export, cmd_message, cmd_genkey): Translate file descriptors. - + 2007-07-05 Werner Koch * Makefile.am (common_libs): Changed order of libs. @@ -746,7 +772,7 @@ 2007-06-24 Werner Koch * gpgsm.c (open_es_fwrite): Avoid the dup by using the new - es_fdopen_nc(). + es_fdopen_nc(). 2007-06-21 Werner Koch @@ -849,14 +875,14 @@ the certificate is not available. * gpgsm.c: Add option --p12-charset. - * gpgsm.h (struct opt): Add p12_charset. + * gpgsm.h (struct opt): Add p12_charset. * export.c (popen_protect_tool): Use new option. 2007-03-19 Werner Koch Changes to let export and key listing use estream to help systems without funopen. - + * keylist.c: Use estream in place of stdio functions. * gpgsm.c (open_es_fwrite): New. (main): Use it for the list commands. @@ -872,7 +898,7 @@ (print_dn_parts): Ditto. * certchain.c (gpgsm_validate_chain): Changed FP to type estream_t. - (do_list, unknown_criticals, allowed_ca, check_cert_policy) + (do_list, unknown_criticals, allowed_ca, check_cert_policy) (is_cert_still_valid): Ditto. * export.c (gpgsm_export): New arg STREAM. @@ -974,7 +1000,7 @@ 2006-10-17 Werner Koch - * gpgsm.c: No need for pth.h. + * gpgsm.c: No need for pth.h. (main): or to init it. It used to be hack for W32. * sign.c (gpgsm_get_default_cert): Changed to return only @@ -982,7 +1008,7 @@ 2006-10-16 Werner Koch - * certchain.c (already_asked_marktrusted) + * certchain.c (already_asked_marktrusted) (set_already_asked_marktrusted): New. (gpgsm_validate_chain) : Keep track of certificates we already asked for. @@ -1014,7 +1040,7 @@ * certchain.c (gpgsm_validate_chain): More changes for the relax feature. Use certificate reference counting instead of the old - explicit tests. Added a missing free. + explicit tests. Added a missing free. 2006-09-25 Werner Koch @@ -1065,9 +1091,9 @@ Replaced all Assuan error codes by libgpg-error codes. Removed all map_to_assuan_status and map_assuan_err. - + * gpgsm.c (main): Call assuan_set_assuan_err_source to have Assuan - switch to gpg-error codes. + switch to gpg-error codes. * server.c (set_error): Adjusted. 2006-08-29 Werner Koch @@ -1111,7 +1137,7 @@ * keydb.c (keydb_delete): Likewise. Only unlock if this is set. * delete.c (delete_one): Add new argument to invocation of keydb_delete. - + 2006-05-15 Werner Koch * keylist.c (print_names_raw): Sanitize URI. @@ -1330,7 +1356,7 @@ (run_command_status_cb): Return cancel status if gpgsm_status returned an error. - * server.c (gpgsm_status, gpgsm_status2) + * server.c (gpgsm_status, gpgsm_status2) (gpgsm_status_with_err_code): Return an error code. (gpgsm_status2): Always call va_end(). @@ -1420,7 +1446,7 @@ * Makefile.am: Adjusted for gettext 0.14. * keylist.c (list_cert_colon): Make sure that the expired flag has - a higher precedence than the invalid flag. + a higher precedence than the invalid flag. 2004-09-29 Werner Koch @@ -1455,7 +1481,7 @@ * certchain.c (gpgsm_basic_cert_check): Print more detailed error messages. - + * certcheck.c (do_encode_md): Partly support DSA. Add new arg PKALGO. Changed all callers to pass it. (pk_algo_from_sexp): New. @@ -1492,7 +1518,7 @@ 2004-06-06 Werner Koch * certreqgen.c (get_parameter_uint, create_request): Create - an extension for key usage when requested. + an extension for key usage when requested. 2004-05-12 Werner Koch @@ -1548,9 +1574,9 @@ * gpgsm.c (main) : Do not use /dev/null as default config filename. - * call-agent.c (gpgsm_agent_pksign, gpgsm_agent_pkdecrypt) - (gpgsm_agent_genkey, gpgsm_agent_istrusted) - (gpgsm_agent_marktrusted, gpgsm_agent_havekey) + * call-agent.c (gpgsm_agent_pksign, gpgsm_agent_pkdecrypt) + (gpgsm_agent_genkey, gpgsm_agent_istrusted) + (gpgsm_agent_marktrusted, gpgsm_agent_havekey) (gpgsm_agent_passwd): Add new arg CTRL and changed all callers. (start_agent): New arg CTRL. Send progress item when starting a new agent. @@ -1582,7 +1608,7 @@ 2004-04-08 Werner Koch - * decrypt.c (gpgsm_decrypt): Return GPG_ERR_NO_DATA if it is not a + * decrypt.c (gpgsm_decrypt): Return GPG_ERR_NO_DATA if it is not a encrypted message. 2004-04-07 Werner Koch @@ -1686,12 +1712,12 @@ * export.c (export_p12, popen_protect_tool) (gpgsm_p12_export): New. - * gpgsm.c (main): New command --export-secret-key-p12. + * gpgsm.c (main): New command --export-secret-key-p12. 2004-02-18 Werner Koch * gpgsm.c (set_debug): Set the new --debug-level flags. - (main): New option --gpgconf-list. + (main): New option --gpgconf-list. (main): Do not setup -u and -r keys when not required. (main): Setup the used character set. @@ -1713,7 +1739,7 @@ WITH_VALIDATION. Changed callers to set it. (list_external_cb, list_external_keys): Pass CTRL to the callback. (list_cert_colon): Add arg CTRL. Check validation if requested. - * certchain.c (unknown_criticals, allowed_ca, check_cert_policy) + * certchain.c (unknown_criticals, allowed_ca, check_cert_policy) (gpgsm_validate_chain): New args LISTMODE and FP. (do_list): New helper for info output. (find_up): New arg FIND_NEXT. @@ -1730,7 +1756,7 @@ * certcheck.c (gpgsm_create_cms_signature): Format a description for use by the pinentry. * decrypt.c (gpgsm_decrypt): Ditto. Free HEXKEYGRIP. - * certdump.c (format_name_cookie, format_name_writer) + * certdump.c (format_name_cookie, format_name_writer) (gpgsm_format_name): New. (gpgsm_format_serial): New. (gpgsm_format_keydesc): New. @@ -1804,7 +1830,7 @@ (print_dn_part): Do not delimit multiple RDN by " + ". Handle multi-valued RDNs in a special way, i.e. in the order specified by the certificate. - (print_dn_parts): Simplified. + (print_dn_parts): Simplified. 2004-01-16 Werner Koch @@ -1892,7 +1918,7 @@ 2003-08-14 Timo Schulz * encrypt.c (encode_session_key): Use new Libgcrypt interface. - + 2003-07-31 Werner Koch * Makefile.am (gpgsm_LDADD): Added INTLLIBS. @@ -1915,7 +1941,7 @@ * verify.c (strtimestamp): Renamed to strtimestamp_r Adjusted for changes in the libgcrypt API. Some more fixes for the - libgpg-error stuff. + libgpg-error stuff. 2003-06-04 Werner Koch @@ -1944,7 +1970,7 @@ 2002-11-25 Werner Koch - * verify.c (gpgsm_verify): Handle content-type attribute. + * verify.c (gpgsm_verify): Handle content-type attribute. 2002-11-13 Werner Koch @@ -1954,7 +1980,7 @@ 2002-11-12 Werner Koch - * gpgsm.c: New command --call-dirmngr. + * gpgsm.c: New command --call-dirmngr. * call-dirmngr.c (gpgsm_dirmngr_run_command) (run_command_inq_cb,run_command_cb) (run_command_status_cb): New. @@ -1972,7 +1998,7 @@ * certcheck.c (gpgsm_check_cert_sig): Add cert hash debugging. - * certchain.c (find_up): Print info when the cert was not found + * certchain.c (find_up): Print info when the cert was not found by the autorithyKeyIdentifier. 2002-09-03 Werner Koch @@ -2046,10 +2072,10 @@ * sign.c (gpgsm_sign): New argument SIGNERLIST and implemt multiple signers. * gpgsm.c (main): Support more than one -u. - + * server.c (cmd_recipient): Return reason code 1 for No_Public_Key which is actually what gets returned from add_to_certlist. - + 2002-07-26 Werner Koch * certcheck.c (gpgsm_check_cert_sig): Implement proper cleanup. @@ -2151,7 +2177,7 @@ 2002-06-24 Werner Koch * gpgsm.c: Removed duped help entry for --list-keys. - + * gpgsm.c, gpgsm.h: New option --debug-no-path-validation. * certpath.c (gpgsm_validate_path): Use it here instead of the @@ -2194,7 +2220,7 @@ * export.c (gpgsm_export): Kludge to export epehmeral certificates. * gpgsm.c (main): New command --list-external-keys. - + 2002-06-17 Werner Koch * certreqgen.c (read_parameters): Improved error handling. @@ -2216,7 +2242,7 @@ * sign.c (hash_and_copy_data): New. (gpgsm_sign): Implemented normal (non-detached) signatures. * gpgsm.c (main): Ditto. - + * certpath.c (gpgsm_validate_path): Special error handling for no policy match. @@ -2224,7 +2250,7 @@ * server.c (get_status_string): Add STATUS_ERROR. - * certpath.c (gpgsm_validate_path): Tweaked the error checking to + * certpath.c (gpgsm_validate_path): Tweaked the error checking to return error codes in a more sensitive way. * verify.c (gpgsm_verify): Send status TRUST_NEVER also for a bad CA certificate and when the certificate has been revoked. Issue @@ -2346,7 +2372,7 @@ * export.c: New. * gpgsm.c: Add command --export. * server.c (cmd_export): New. - + 2002-03-13 Werner Koch * decrypt.c (gpgsm_decrypt): Allow multiple recipients. @@ -2588,10 +2614,10 @@ print the first item. * keylist.c (list_cert_colon): Ditto. * keydb.c (keydb_search_issuer_sn): Ditto. - * decrypt.c (print_integer_sexp): Removed and made callers + * decrypt.c (print_integer_sexp): Removed and made callers use gpgsm_dump_serial. * verify.c (print_time): Removed, made callers use gpgsm_dump_time. - + 2001-12-19 Marcus Brinkmann * call-agent.c (start_agent): Add new argument to assuan_pipe_connect. @@ -2647,7 +2673,7 @@ * base64.c (base64_reader_cb): Reset the linelen when we need to skip the line and adjusted test; I somehow forgot about DeMorgan. - * server.c (cmd_encrypt,cmd_decrypt,cmd_sign,cmd_verify) + * server.c (cmd_encrypt,cmd_decrypt,cmd_sign,cmd_verify) (cmd_import): Close the FDs on success. (close_message_fd): New. (input_notify): Setting autodetect_encoding to 0 after initializing @@ -2671,7 +2697,7 @@ 2001-12-12 Werner Koch - * gpgsm.c (main): New options --assume-{armor,base64,binary}. + * gpgsm.c (main): New options --assume-{armor,base64,binary}. * base64.c (base64_reader_cb): Fixed non-autodetection mode. 2001-12-04 Werner Koch @@ -2699,10 +2725,10 @@ * server.c (rc_to_assuan_status): New. Use it for all commands. - - 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 modifications, as long as this notice is preserved. Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/tools/ChangeLog 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,3 +1,7 @@ +2010-03-08 Werner Koch + + * no-libgcrypt.c (gcry_create_nonce): New. + 2010-02-26 Werner Koch * gpg-connect-agent.c (main): New option --tcp-socket. Modified: trunk/sm/base64.c =================================================================== --- trunk/sm/base64.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/base64.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,5 @@ /* base64.c - * Copyright (C) 2001, 2003 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -39,9 +39,10 @@ #define LF "\n" #endif -/* data used by the reader callbacks */ -struct reader_cb_parm_s { - FILE *fp; +/* Data used by the reader callbacks. */ +struct reader_cb_parm_s +{ + estream_t fp; unsigned char line[1024]; int linelen; @@ -69,7 +70,8 @@ } base64; }; -/* data used by the writer callbacks */ + +/* Data used by the writer callbacks. */ struct writer_cb_parm_s { FILE *fp; /* FP is only used if STREAM is NULL. */ estream_t stream; /* Alternative output if not NULL. */ @@ -179,11 +181,11 @@ parm->have_lf = 0; for (n=0; n < DIM(parm->line);) { - c = getc (parm->fp); + c = es_getc (parm->fp); if (c == EOF) { parm->eof_seen = 1; - if (ferror (parm->fp)) + if (es_ferror (parm->fp)) return -1; break; } @@ -382,14 +384,14 @@ for (n=0; n < count; n++) { - c = getc (parm->fp); + c = es_getc (parm->fp); if (c == EOF) { parm->eof_seen = 1; - if ( ferror (parm->fp) ) + if (es_ferror (parm->fp)) return -1; if (n) - break; /* return what we have before an EOF */ + break; /* Return what we have before an EOF. */ return -1; } *(byte *)buffer++ = c; @@ -579,7 +581,7 @@ until no more objects were found. */ int gpgsm_create_reader (Base64Context *ctx, - ctrl_t ctrl, FILE *fp, int allow_multi_pem, + ctrl_t ctrl, estream_t fp, int allow_multi_pem, ksba_reader_t *r_reader) { int rc; Modified: trunk/sm/decrypt.c =================================================================== --- trunk/sm/decrypt.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/decrypt.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,5 @@ /* decrypt.c - Decrypt a message - * Copyright (C) 2001, 2003 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -33,7 +33,8 @@ #include "keydb.h" #include "i18n.h" -struct decrypt_filter_parm_s { +struct decrypt_filter_parm_s +{ int algo; int mode; int blklen; @@ -237,7 +238,7 @@ /* Perform a decrypt operation. */ int -gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp) +gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp) { int rc; Base64Context b64reader = NULL; @@ -248,7 +249,7 @@ ksba_stop_reason_t stopreason; KEYDB_HANDLE kh; int recp; - FILE *in_fp = NULL; + estream_t in_fp = NULL; struct decrypt_filter_parm_s dfparm; memset (&dfparm, 0, sizeof dfparm); @@ -263,11 +264,10 @@ goto leave; } - - in_fp = fdopen ( dup (in_fd), "rb"); + in_fp = es_fdopen_nc (in_fd, "rb"); if (!in_fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } @@ -279,7 +279,7 @@ goto leave; } - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); @@ -576,8 +576,7 @@ gpgsm_destroy_reader (b64reader); gpgsm_destroy_writer (b64writer); keydb_release (kh); - if (in_fp) - fclose (in_fp); + es_fclose (in_fp); if (dfparm.hd) gcry_cipher_close (dfparm.hd); return rc; Modified: trunk/sm/encrypt.c =================================================================== --- trunk/sm/encrypt.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/encrypt.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,6 @@ /* encrypt.c - Encrypt a message - * Copyright (C) 2001, 2003, 2004, 2007, 2008 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2004, 2007, 2008, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -45,8 +46,11 @@ }; typedef struct dek_s *DEK; -struct encrypt_cb_parm_s { - FILE *fp; + +/* Callback parameters for the encryption. */ +struct encrypt_cb_parm_s +{ + estream_t fp; DEK dek; int eof_seen; int ready; @@ -239,10 +243,10 @@ p = parm->buffer; for (n=parm->buflen; n < parm->bufsize; n++) { - int c = getc (parm->fp); + int c = es_getc (parm->fp); if (c == EOF) { - if (ferror (parm->fp)) + if (es_ferror (parm->fp)) { parm->readerror = errno; return -1; @@ -289,7 +293,7 @@ recipients are take from the certificate given in recplist; if this is NULL it will be encrypted for a default recipient */ int -gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, FILE *out_fp) +gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, estream_t out_fp) { int rc = 0; Base64Context b64writer = NULL; @@ -302,7 +306,7 @@ struct encrypt_cb_parm_s encparm; DEK dek = NULL; int recpno; - FILE *data_fp = NULL; + estream_t data_fp = NULL; certlist_t cl; int count; @@ -337,10 +341,11 @@ goto leave; } - data_fp = fdopen ( dup (data_fd), "rb"); + /* Fixme: We should use the unlocked version of the es functions. */ + data_fp = es_fdopen_nc (data_fd, "rb"); if (!data_fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } @@ -356,7 +361,7 @@ encparm.fp = data_fp; ctrl->pem_name = "ENCRYPTED MESSAGE"; - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); @@ -506,8 +511,7 @@ ksba_reader_release (reader); keydb_release (kh); xfree (dek); - if (data_fp) - fclose (data_fp); + es_fclose (data_fp); xfree (encparm.buffer); return rc; } Modified: trunk/sm/export.c =================================================================== --- trunk/sm/export.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/export.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,6 @@ /* export.c - Export certificates and private keys. - * Copyright (C) 2002, 2003, 2004, 2007, 2009 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003, 2004, 2007, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -60,7 +61,7 @@ static gpg_error_t export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen, const char *prompt, const char *keygrip, - FILE **retfp); + estream_t *retfp); /* Create a table used to indetify duplicated certificates. */ @@ -341,7 +342,7 @@ char *prompt; char buffer[1024]; int nread; - FILE *datafp = NULL; + estream_t datafp = NULL; hd = keydb_new (0); @@ -447,16 +448,16 @@ xfree (prompt); if (rc) goto leave; - rewind (datafp); - while ( (nread = fread (buffer, 1, sizeof buffer, datafp)) > 0 ) + es_rewind (datafp); + while ( (nread = es_fread (buffer, 1, sizeof buffer, datafp)) > 0 ) if ((rc = ksba_writer_write (writer, buffer, nread))) { log_error ("write failed: %s\n", gpg_strerror (rc)); goto leave; } - if (ferror (datafp)) + if (es_ferror (datafp)) { - rc = gpg_error_from_errno (rc); + rc = gpg_error_from_syserror (); log_error ("error reading temporary file: %s\n", gpg_strerror (rc)); goto leave; } @@ -478,8 +479,7 @@ cert = NULL; leave: - if (datafp) - fclose (datafp); + es_fclose (datafp); gpgsm_destroy_writer (b64writer); ksba_cert_release (cert); xfree (desc); @@ -570,7 +570,7 @@ static gpg_error_t popen_protect_tool (ctrl_t ctrl, const char *pgmname, - FILE *infile, FILE *outfile, FILE **statusfile, + FILE *infile, estream_t outfile, FILE **statusfile, const char *prompt, const char *keygrip, pid_t *pid) { @@ -614,14 +614,14 @@ static gpg_error_t export_p12 (ctrl_t ctrl, const unsigned char *certimg, size_t certimglen, - const char *prompt, const char *keygrip, - FILE **retfp) + const char *prompt, const char *keygrip, estream_t *retfp) { const char *pgmname; gpg_error_t err = 0, child_err = 0; int c, cont_line; unsigned int pos; - FILE *infp = NULL, *outfp = NULL, *fp = NULL; + FILE *infp = NULL, *fp = NULL; + estream_t outfp = NULL; char buffer[1024]; pid_t pid = -1; int bad_pass = 0; @@ -647,7 +647,7 @@ goto cleanup; } - outfp = gnupg_tmpfile (); + outfp = es_tmpfile (); if (!outfp) { err = gpg_error_from_syserror (); @@ -731,8 +731,7 @@ err = child_err; if (err) { - if (outfp) - fclose (outfp); + es_fclose (outfp); } else *retfp = outfp; Modified: trunk/sm/gpgsm.c =================================================================== --- trunk/sm/gpgsm.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/gpgsm.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,6 +1,6 @@ /* gpgsm.c - GnuPG for S/MIME - * Copyright (C) 2001, 2002, 2003, 2004, 2005, - * 2006, 2007, 2008 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -1702,7 +1702,7 @@ case aEncr: /* Encrypt the given file. */ { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); set_binary (stdin); @@ -1713,14 +1713,13 @@ else wrong_args ("--encrypt [datafile]"); - if (fp != stdout) - fclose (fp); + es_fclose (fp); } break; case aSign: /* Sign the given file. */ { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); /* Fixme: We should also allow to concatenate multiple files for signing because that is what gpg does.*/ @@ -1733,8 +1732,7 @@ else wrong_args ("--sign [datafile]"); - if (fp != stdout) - fclose (fp); + es_fclose (fp); } break; @@ -1748,13 +1746,13 @@ case aVerify: { - FILE *fp = NULL; + estream_t fp = NULL; set_binary (stdin); if (argc == 2 && opt.outfile) log_info ("option --output ignored for a detached signature\n"); else if (opt.outfile) - fp = open_fwrite (opt.outfile); + fp = open_es_fwrite (opt.outfile); if (!argc) gpgsm_verify (&ctrl, 0, -1, fp); /* normal signature from stdin */ @@ -1765,14 +1763,13 @@ else wrong_args ("--verify [signature [detached_data]]"); - if (fp && fp != stdout) - fclose (fp); + es_fclose (fp); } break; case aDecrypt: { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); set_binary (stdin); if (!argc) @@ -1781,8 +1778,8 @@ gpgsm_decrypt (&ctrl, open_read (*argv), fp); /* from file */ else wrong_args ("--decrypt [filename]"); - if (fp != stdout) - fclose (fp); + + es_fclose (fp); } break; @@ -2034,9 +2031,9 @@ -/* Open the FILENAME for read and return the filedescriptor. Stop +/* Open the FILENAME for read and return the file descriptor. Stop with an error message in case of problems. "-" denotes stdin and - if special filenames are allowed the given fd is opened instead. */ + if special filenames are allowed the given fd is opened instead. */ static int open_read (const char *filename) { Modified: trunk/sm/gpgsm.h =================================================================== --- trunk/sm/gpgsm.h 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/gpgsm.h 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,6 @@ /* gpgsm.h - Global definitions for GpgSM - * Copyright (C) 2001, 2003, 2004, 2007, 2009 Free Software Foundation, Inc. + * Copyright (C) 2001, 2003, 2004, 2007, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -255,7 +256,7 @@ /*-- base64.c --*/ int gpgsm_create_reader (Base64Context *ctx, - ctrl_t ctrl, FILE *fp, int allow_multi_pem, + ctrl_t ctrl, estream_t fp, int allow_multi_pem, ksba_reader_t *r_reader); int gpgsm_reader_eof_seen (Base64Context ctx); void gpgsm_destroy_reader (Base64Context ctx); @@ -350,18 +351,19 @@ int gpgsm_delete (ctrl_t ctrl, strlist_t names); /*-- verify.c --*/ -int gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp); +int gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp); /*-- sign.c --*/ int gpgsm_get_default_cert (ctrl_t ctrl, ksba_cert_t *r_cert); int gpgsm_sign (ctrl_t ctrl, certlist_t signerlist, - int data_fd, int detached, FILE *out_fp); + int data_fd, int detached, estream_t out_fp); /*-- encrypt.c --*/ -int gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int in_fd, FILE *out_fp); +int gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, + int in_fd, estream_t out_fp); /*-- decrypt.c --*/ -int gpgsm_decrypt (ctrl_t ctrl, int in_fd, FILE *out_fp); +int gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp); /*-- certreqgen.c --*/ int gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, FILE *out_fp); Modified: trunk/sm/import.c =================================================================== --- trunk/sm/import.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/import.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -48,8 +48,8 @@ }; -static gpg_error_t parse_p12 (ctrl_t ctrl, ksba_reader_t reader, FILE **retfp, - struct stats_s *stats); +static gpg_error_t parse_p12 (ctrl_t ctrl, ksba_reader_t reader, + estream_t *retfp, struct stats_s *stats); @@ -254,14 +254,14 @@ ksba_reader_t reader; ksba_cert_t cert = NULL; ksba_cms_t cms = NULL; - FILE *fp = NULL; + estream_t fp = NULL; ksba_content_type_t ct; int any = 0; - fp = fdopen ( dup (in_fd), "rb"); + fp = es_fdopen_nc (in_fd, "rb"); if (!fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } @@ -331,7 +331,7 @@ certificate we included in the p12 file; then we continue to look for other pkcs12 files (works only if they are in PEM format. */ - FILE *certfp; + estream_t certfp; Base64Context b64p12rdr; ksba_reader_t p12rdr; @@ -340,12 +340,12 @@ { any = 1; - rewind (certfp); + es_rewind (certfp); rc = gpgsm_create_reader (&b64p12rdr, ctrl, certfp, 1, &p12rdr); if (rc) { log_error ("can't create reader: %s\n", gpg_strerror (rc)); - fclose (certfp); + es_fclose (certfp); goto leave; } @@ -366,7 +366,7 @@ if (gpg_err_code (rc) == GPG_ERR_EOF) rc = 0; gpgsm_destroy_reader (b64p12rdr); - fclose (certfp); + es_fclose (certfp); if (rc) goto leave; } @@ -401,8 +401,7 @@ ksba_cms_release (cms); ksba_cert_release (cert); gpgsm_destroy_reader (b64reader); - if (fp) - fclose (fp); + es_fclose (fp); return rc; } @@ -585,7 +584,8 @@ success or an error code. */ static gpg_error_t popen_protect_tool (ctrl_t ctrl, const char *pgmname, - FILE *infile, FILE *outfile, FILE **statusfile, pid_t *pid) + FILE *infile, estream_t outfile, + FILE **statusfile, pid_t *pid) { const char *argv[22]; int i=0; @@ -627,17 +627,18 @@ certificates from that stupid format. We will also store secret keys. All of the pkcs#12 parsing and key storing is handled by the gpg-protect-tool, we merely have to take care of receiving the - certificates. On success RETFP returns a temporary file with - certificates. */ + certificates. On success RETFP returns a stream to a temporary + file with certificates. */ static gpg_error_t parse_p12 (ctrl_t ctrl, ksba_reader_t reader, - FILE **retfp, struct stats_s *stats) + estream_t *retfp, struct stats_s *stats) { const char *pgmname; gpg_error_t err = 0, child_err = 0; int c, cont_line; unsigned int pos; - FILE *tmpfp, *certfp = NULL, *fp = NULL; + FILE *tmpfp, *fp = NULL; + estream_t certfp = NULL; char buffer[1024]; size_t nread; pid_t pid = -1; @@ -679,7 +680,7 @@ goto cleanup; } - certfp = gnupg_tmpfile (); + certfp = es_tmpfile (); if (!certfp) { err = gpg_error_from_syserror (); @@ -780,8 +781,7 @@ err = child_err; if (err) { - if (certfp) - fclose (certfp); + es_fclose (certfp); } else *retfp = certfp; Modified: trunk/sm/server.c =================================================================== --- trunk/sm/server.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/server.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,6 +1,6 @@ /* server.c - Server mode and main entry point - * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -451,7 +451,7 @@ ctrl_t ctrl = assuan_get_pointer (ctx); certlist_t cl; int inp_fd, out_fd; - FILE *out_fp; + estream_t out_fp; int rc; (void)line; @@ -463,9 +463,9 @@ if (out_fd == -1) return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); - out_fp = fdopen (dup (out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); /* Now add all encrypt-to marked recipients from the default list. */ @@ -483,7 +483,7 @@ rc = gpgsm_encrypt (assuan_get_pointer (ctx), ctrl->server_local->recplist, inp_fd, out_fp); - fclose (out_fp); + es_fclose (out_fp); gpgsm_release_certlist (ctrl->server_local->recplist); ctrl->server_local->recplist = NULL; @@ -508,7 +508,7 @@ { ctrl_t ctrl = assuan_get_pointer (ctx); int inp_fd, out_fd; - FILE *out_fp; + estream_t out_fp; int rc; (void)line; @@ -520,16 +520,16 @@ if (out_fd == -1) return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); - out_fp = fdopen (dup(out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); rc = start_audit_session (ctrl); if (!rc) rc = gpgsm_decrypt (ctrl, inp_fd, out_fp); - fclose (out_fp); + es_fclose (out_fp); - /* close and reset the fd */ + /* Close and reset the fds. */ close_message_fd (ctrl); assuan_close_input_fd (ctx); assuan_close_output_fd (ctx); @@ -554,7 +554,7 @@ ctrl_t ctrl = assuan_get_pointer (ctx); int fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0); int out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1); - FILE *out_fp = NULL; + estream_t out_fp = NULL; (void)line; @@ -563,19 +563,18 @@ if (out_fd != -1) { - out_fp = fdopen ( dup(out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); } rc = start_audit_session (ctrl); if (!rc) rc = gpgsm_verify (assuan_get_pointer (ctx), fd, ctrl->server_local->message_fd, out_fp); - if (out_fp) - fclose (out_fp); + es_fclose (out_fp); - /* close and reset the fd */ + /* Close and reset the fd. */ close_message_fd (ctrl); assuan_close_input_fd (ctx); assuan_close_output_fd (ctx); @@ -595,7 +594,7 @@ { ctrl_t ctrl = assuan_get_pointer (ctx); int inp_fd, out_fd; - FILE *out_fp; + estream_t out_fp; int detached; int rc; @@ -608,7 +607,7 @@ detached = has_option (line, "--detached"); - out_fp = fdopen ( dup(out_fd), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); @@ -616,7 +615,7 @@ if (!rc) rc = gpgsm_sign (assuan_get_pointer (ctx), ctrl->server_local->signerlist, inp_fd, detached, out_fp); - fclose (out_fp); + es_fclose (out_fp); /* close and reset the fd */ close_message_fd (ctrl); @@ -916,9 +915,9 @@ if ( outfd == -1 ) return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); - fp = es_fdopen ( dup (outfd), "w"); + fp = es_fdopen_nc (outfd, "w"); if (!fp) - return set_error (GPG_ERR_ASS_GENERAL, "es_fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "es_fdopen() failed"); } else { Modified: trunk/sm/sign.c =================================================================== --- trunk/sm/sign.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/sign.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,6 @@ /* sign.c - Sign a message - * Copyright (C) 2001, 2002, 2003, 2008 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2008, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -38,12 +39,12 @@ static int hash_data (int fd, gcry_md_hd_t md) { - FILE *fp; + estream_t fp; char buffer[4096]; int nread; int rc = 0; - fp = fdopen ( dup (fd), "rb"); + fp = es_fdopen_nc (fd, "rb"); if (!fp) { log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno)); @@ -52,40 +53,41 @@ do { - nread = fread (buffer, 1, DIM(buffer), fp); + nread = es_fread (buffer, 1, DIM(buffer), fp); gcry_md_write (md, buffer, nread); } while (nread); - if (ferror (fp)) + if (es_ferror (fp)) { log_error ("read error on fd %d: %s\n", fd, strerror (errno)); rc = -1; } - fclose (fp); + es_fclose (fp); return rc; } + static int hash_and_copy_data (int fd, gcry_md_hd_t md, ksba_writer_t writer) { gpg_error_t err; - FILE *fp; + estream_t fp; char buffer[4096]; int nread; int rc = 0; int any = 0; - fp = fdopen ( dup (fd), "rb"); + fp = es_fdopen_nc (fd, "rb"); if (!fp) { - gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno)); + gpg_error_t tmperr = gpg_error_from_syserror (); log_error ("fdopen(%d) failed: %s\n", fd, strerror (errno)); return tmperr; } do { - nread = fread (buffer, 1, DIM(buffer), fp); + nread = es_fread (buffer, 1, DIM(buffer), fp); if (nread) { any = 1; @@ -99,18 +101,18 @@ } } while (nread && !rc); - if (ferror (fp)) + if (es_ferror (fp)) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("read error on fd %d: %s\n", fd, strerror (errno)); } - fclose (fp); + es_fclose (fp); if (!any) { /* We can't allow to sign an empty message because it does not - make much sense and more seriously, ksba-cms_build has + make much sense and more seriously, ksba_cms_build has already written the tag for data and now expects an octet - string but an octet string of zeize 0 is illegal. */ + string and an octet string of size 0 is illegal. */ log_error ("cannot sign an empty message\n"); rc = gpg_error (GPG_ERR_NO_DATA); } @@ -310,7 +312,7 @@ be used if the value of this argument is NULL. */ int gpgsm_sign (ctrl_t ctrl, certlist_t signerlist, - int data_fd, int detached, FILE *out_fp) + int data_fd, int detached, estream_t out_fp) { int i, rc; gpg_error_t err; @@ -338,7 +340,7 @@ } ctrl->pem_name = "SIGNED MESSAGE"; - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); Modified: trunk/sm/verify.c =================================================================== --- trunk/sm/verify.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/sm/verify.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -1,5 +1,6 @@ /* verify.c - Verify a messages signature - * Copyright (C) 2001, 2002, 2003, 2007 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2007, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -52,11 +53,11 @@ hash_data (int fd, gcry_md_hd_t md) { gpg_error_t err = 0; - FILE *fp; + estream_t fp; char buffer[4096]; int nread; - fp = fdopen ( dup (fd), "rb"); + fp = es_fdopen_nc (fd, "rb"); if (!fp) { err = gpg_error_from_syserror (); @@ -66,27 +67,27 @@ do { - nread = fread (buffer, 1, DIM(buffer), fp); + nread = es_fread (buffer, 1, DIM(buffer), fp); gcry_md_write (md, buffer, nread); } while (nread); - if (ferror (fp)) + if (es_ferror (fp)) { err = gpg_error_from_syserror (); log_error ("read error on fd %d: %s\n", fd, gpg_strerror (err)); } - fclose (fp); + es_fclose (fp); return err; } -/* Perform a verify operation. To verify detached signatures, data_fd +/* Perform a verify operation. To verify detached signatures, DATA_FD must be different than -1. With OUT_FP given and a non-detached - signature, the signed material is written to that stream. */ + signature, the signed material is written to that stream. */ int -gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, FILE *out_fp) +gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp) { int i, rc; Base64Context b64reader = NULL; @@ -102,7 +103,7 @@ const char *algoid; int algo; int is_detached; - FILE *fp = NULL; + estream_t in_fp = NULL; char *p; audit_set_type (ctrl->audit, AUDIT_TYPE_VERIFY); @@ -116,15 +117,15 @@ } - fp = fdopen ( dup (in_fd), "rb"); - if (!fp) + in_fp = es_fdopen_nc (in_fd, "rb"); + if (!in_fp) { - rc = gpg_error (gpg_err_code_from_errno (errno)); + rc = gpg_error_from_syserror (); log_error ("fdopen() failed: %s\n", strerror (errno)); goto leave; } - rc = gpgsm_create_reader (&b64reader, ctrl, fp, 0, &reader); + rc = gpgsm_create_reader (&b64reader, ctrl, in_fp, 0, &reader); if (rc) { log_error ("can't create reader: %s\n", gpg_strerror (rc)); @@ -133,7 +134,7 @@ if (out_fp) { - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_fp, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); @@ -644,8 +645,7 @@ gpgsm_destroy_writer (b64writer); keydb_release (kh); gcry_md_close (data_md); - if (fp) - fclose (fp); + es_fclose (in_fp); if (rc) { Modified: trunk/tools/no-libgcrypt.c =================================================================== --- trunk/tools/no-libgcrypt.c 2010-03-08 12:18:19 UTC (rev 5277) +++ trunk/tools/no-libgcrypt.c 2010-03-08 12:22:18 UTC (rev 5278) @@ -142,3 +142,13 @@ (void)f; (void)opaque; } + + +void +gcry_create_nonce (void *buffer, size_t length) +{ + (void)buffer; + (void)length; + + log_fatal ("unexpected call to gcry_create_nonce\n"); +} From cvs at cvs.gnupg.org Mon Mar 8 13:37:55 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 13:37:55 +0100 Subject: [svn] GnuPG - r5279 - trunk/common Message-ID: Author: wk Date: 2010-03-08 13:37:54 +0100 (Mon, 08 Mar 2010) New Revision: 5279 Modified: trunk/common/ChangeLog trunk/common/iobuf.c Log: Remove unused code. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-08 12:22:18 UTC (rev 5278) +++ trunk/common/ChangeLog 2010-03-08 12:37:54 UTC (rev 5279) @@ -1,5 +1,8 @@ 2010-03-08 Werner Koch + * iobuf.c [FILE_FILTER_USES_STDIO]: Remove all code. It has not + been used for a long time. + * exechelp.h: Include "estream.h". * exechelp.c (gnupg_spawn_process): Change OUTFILE to an estream_t. Modified: trunk/common/iobuf.c =================================================================== --- trunk/common/iobuf.c 2010-03-08 12:22:18 UTC (rev 5278) +++ trunk/common/iobuf.c 2010-03-08 12:37:54 UTC (rev 5279) @@ -1,6 +1,6 @@ /* iobuf.c - File Handling for OpenPGP. - * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2006, 2007, 2008, + * 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -48,10 +48,6 @@ test "armored_key_8192" in armor.test! */ #define IOBUF_BUFFER_SIZE 8192 -/* We don't want to use the STDIO based backend. If you change this - be aware that there is no fsync support for the stdio backend. */ -#undef FILE_FILTER_USES_STDIO - /*-- End configurable part. --*/ @@ -85,33 +81,23 @@ Are macros defined depending on the used backend. */ -#ifdef FILE_FILTER_USES_STDIO -# define my_fileno(a) fileno ((a)) -# define my_fopen_ro(a,b) fopen ((a),(b)) -# define my_fopen(a,b) fopen ((a),(b)) - typedef FILE *fp_or_fd_t; -# define INVALID_FP NULL -# define FILEP_OR_FD_FOR_STDIN (stdin) -# define FILEP_OR_FD_FOR_STDOUT (stdout) -#else /*!FILE_FILTER_USES_STDIO*/ -# define my_fopen_ro(a,b) fd_cache_open ((a),(b)) -# define my_fopen(a,b) direct_open ((a),(b)) -# ifdef HAVE_W32_SYSTEM - /* (We assume that a HANDLE first into an int.) */ -# define my_fileno(a) ((int)(a)) - typedef HANDLE fp_or_fd_t; -# define INVALID_FP ((HANDLE)-1) -# define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) -# define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) -# undef USE_SETMODE -# else /*!HAVE_W32_SYSTEM*/ -# define my_fileno(a) (a) - typedef int fp_or_fd_t; -# define INVALID_FP (-1) -# define FILEP_OR_FD_FOR_STDIN (0) -# define FILEP_OR_FD_FOR_STDOUT (1) -# endif /*!HAVE_W32_SYSTEM*/ -#endif /*!FILE_FILTER_USES_STDIO*/ +#define my_fopen_ro(a,b) fd_cache_open ((a),(b)) +#define my_fopen(a,b) direct_open ((a),(b)) +#ifdef HAVE_W32_SYSTEM +/* (We assume that a HANDLE fits into an int.) */ +# define my_fileno(a) ((int)(a)) + typedef HANDLE fp_or_fd_t; +# define INVALID_FP ((HANDLE)-1) +# define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) +# define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) +# undef USE_SETMODE +#else /*!HAVE_W32_SYSTEM*/ +# define my_fileno(a) (a) + typedef int fp_or_fd_t; +# define INVALID_FP (-1) +# define FILEP_OR_FD_FOR_STDIN (0) +# define FILEP_OR_FD_FOR_STDOUT (1) +#endif /*!HAVE_W32_SYSTEM*/ /* The context used by the file filter. */ typedef struct @@ -126,9 +112,7 @@ file_filter_ctx_t; -/* If we are not using stdio as the backend we make use of a "close - cache". */ -#ifndef FILE_FILTER_USES_STDIO +/* Object to control the "close cache". */ struct close_cache_s { struct close_cache_s *next; @@ -137,7 +121,6 @@ }; typedef struct close_cache_s *close_cache_t; static close_cache_t close_cache; -#endif /*!FILE_FILTER_USES_STDIO*/ @@ -150,8 +133,8 @@ int eof_seen; int print_only_name; /* Flag indicating that fname is not a real file. */ char fname[1]; /* Name of the file */ -} -sock_filter_ctx_t; + +} sock_filter_ctx_t; #endif /*HAVE_W32_SYSTEM*/ /* The first partial length header block must be of size 512 @@ -187,7 +170,6 @@ -#ifndef FILE_FILTER_USES_STDIO /* This is a replacement for strcmp. Under W32 it does not distinguish between backslash and slash. */ static int @@ -447,9 +429,7 @@ return direct_open (fname, mode); } -#endif /*FILE_FILTER_USES_STDIO */ - /**************** * Read data from a file into buf which has an allocated length of *LEN. * return the number of read bytes in *LEN. OPAQUE is the FILE * of @@ -486,73 +466,8 @@ (void)chain; /* Not used. */ -#ifdef FILE_FILTER_USES_STDIO if (control == IOBUFCTRL_UNDERFLOW) { - assert (size); /* We need a buffer. */ - if (feof (f)) - { - /* On terminals you could easily read as many EOFs as you - call fread() or fgetc() repeatly. Every call will block - until you press CTRL-D. So we catch this case before we - call fread() again. */ - rc = -1; - *ret_len = 0; - } - else - { - clearerr (f); - nbytes = fread (buf, 1, size, f); - if (feof (f) && !nbytes) - { - rc = -1; /* Okay: we can return EOF now. */ - } - else if (ferror (f) && errno != EPIPE) - { - rc = gpg_error_from_syserror (); - log_error ("%s: read error: %s\n", a->fname, strerror (errno)); - } - *ret_len = nbytes; - } - } - else if (control == IOBUFCTRL_FLUSH) - { - if (size) - { - clearerr (f); - nbytes = fwrite (buf, 1, size, f); - if (ferror (f)) - { - rc = gpg_error_from_syserror (); - log_error ("%s: write error: %s\n", a->fname, strerror (errno)); - } - } - *ret_len = nbytes; - } - else if (control == IOBUFCTRL_INIT) - { - a->keep_open = a->no_cache = 0; - } - else if (control == IOBUFCTRL_DESC) - { - *(char **) buf = "file_filter"; - } - else if (control == IOBUFCTRL_FREE) - { - if (f != stdin && f != stdout) - { - if (DBG_IOBUF) - log_debug ("%s: close fd %d\n", a->fname, fileno (f)); - if (!a->keep_open) - fclose (f); - } - f = NULL; - xfree (a); /* We can free our context now. */ - } -#else /* !stdio implementation */ - - if (control == IOBUFCTRL_UNDERFLOW) - { assert (size); /* We need a buffer. */ if (a->eof_seen) { @@ -700,7 +615,7 @@ #endif xfree (a); /* We can free our context now. */ } -#endif /* !stdio implementation. */ + return rc; } @@ -1364,12 +1279,8 @@ file_filter_ctx_t *fcx; size_t len; -#ifdef FILE_FILTER_USES_STDIO - if (!(fp = fdopen (fd, mode))) - return NULL; -#else fp = (fp_or_fd_t) fd; -#endif + a = iobuf_alloc (strchr (mode, 'w') ? 2 : 1, IOBUF_BUFFER_SIZE); fcx = xmalloc (sizeof *fcx + 20); fcx->fp = fp; @@ -1553,10 +1464,8 @@ ptrval ? (char *) ptrval : "?"); if (!a && !intval && ptrval) { -#ifndef FILE_FILTER_USES_STDIO if (fd_cache_invalidate (ptrval)) return -1; -#endif return 0; } } @@ -1593,11 +1502,7 @@ if (!a && !intval && ptrval) { -#ifndef FILE_FILTER_USES_STDIO return fd_cache_synchronize (ptrval); -#else - return 0; -#endif } } @@ -2209,7 +2114,7 @@ file_filter_ctx_t *b = a->filter_ov; fp_or_fd_t fp = b->fp; -#if defined(HAVE_W32_SYSTEM) && !defined(FILE_FILTER_USES_STDIO) +#if defined(HAVE_W32_SYSTEM) ulong size; static int (* __stdcall get_file_size_ex) (void *handle, LARGE_INTEGER *r_size); @@ -2357,13 +2262,6 @@ } if (!a) return -1; -#ifdef FILE_FILTER_USES_STDIO - if (fseeko (b->fp, newpos, SEEK_SET)) - { - log_error ("can't fseek: %s\n", strerror (errno)); - return -1; - } -#else #ifdef HAVE_W32_SYSTEM if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff) { @@ -2378,7 +2276,6 @@ return -1; } #endif -#endif } a->d.len = 0; /* discard buffer */ a->d.start = 0; @@ -2546,9 +2443,6 @@ translate_file_handle (int fd, int for_write) { #ifdef HAVE_W32_SYSTEM -# ifdef FILE_FILTER_USES_STDIO - fd = translate_sys2libc_fd (fd, for_write); -# else { int x; @@ -2569,7 +2463,6 @@ fd = x; } -# endif #else (void)for_write; #endif From cvs at cvs.gnupg.org Mon Mar 8 14:06:53 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 14:06:53 +0100 Subject: [svn] GnuPG - r5280 - trunk/common Message-ID: Author: wk Date: 2010-03-08 14:06:53 +0100 (Mon, 08 Mar 2010) New Revision: 5280 Modified: trunk/common/ChangeLog trunk/common/iobuf.c Log: More cleanups Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-08 12:37:54 UTC (rev 5279) +++ trunk/common/ChangeLog 2010-03-08 13:06:53 UTC (rev 5280) @@ -1,5 +1,14 @@ 2010-03-08 Werner Koch + * iobuf.c (INVALID_FD): Replace by GNUPG_INVALID_FD. + (fp_or_fd_t): Replace by gnupg_fd_t. + (my_fileno): Replace by the FD2INT macro. + (FILEP_OR_FD_FOR_STDIN, FILEP_OR_FD_FOR_STDOUT): Rename to + FD_FOR_STDIN, FD_FOR_STDOUT. + (file_filter): Make full use of FD_FOR_STDIN. + (USE_SETMODE): Remove. Not needed without stdio. + (my_fopen_ro, my_fopen): Replace unneeded macros. + * iobuf.c [FILE_FILTER_USES_STDIO]: Remove all code. It has not been used for a long time. Modified: trunk/common/iobuf.c =================================================================== --- trunk/common/iobuf.c 2010-03-08 12:37:54 UTC (rev 5279) +++ trunk/common/iobuf.c 2010-03-08 13:06:53 UTC (rev 5280) @@ -51,72 +51,32 @@ /*-- End configurable part. --*/ -/* Under W32 the default is to use the setmode call. Define a macro - which allows us to enable this call. */ #ifdef HAVE_W32_SYSTEM -# define USE_SETMODE 1 -#endif /*HAVE_W32_SYSTEM*/ - - -/* Definition of constants and macros used by our file filter - implementation. What we define here are 3 macros to make the - appropriate calls: - - my_fileno - Is expanded to fileno(a) if using a stdion backend and to a if we - are using the low-level backend. - - my_fopen - Is defined to fopen for the stdio backend and to direct_open if - we are using the low-evel backend. - - my_fopen_ro - Is defined to fopen for the stdio backend and to fd_cache_open if - we are using the low-evel backend. - - fp_or_fd_t - Is the type we use for the backend stream or file descriptor. - - INVALID_FP, FILEP_OR_FD_FOR_STDIN, FILEP_OR_FD_FOR_STDOUT - Are macros defined depending on the used backend. - -*/ -#define my_fopen_ro(a,b) fd_cache_open ((a),(b)) -#define my_fopen(a,b) direct_open ((a),(b)) -#ifdef HAVE_W32_SYSTEM -/* (We assume that a HANDLE fits into an int.) */ -# define my_fileno(a) ((int)(a)) - typedef HANDLE fp_or_fd_t; -# define INVALID_FP ((HANDLE)-1) -# define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) -# define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) -# undef USE_SETMODE +# define FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) +# define FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) #else /*!HAVE_W32_SYSTEM*/ -# define my_fileno(a) (a) - typedef int fp_or_fd_t; -# define INVALID_FP (-1) -# define FILEP_OR_FD_FOR_STDIN (0) -# define FILEP_OR_FD_FOR_STDOUT (1) +# define FD_FOR_STDIN (0) +# define FD_FOR_STDOUT (1) #endif /*!HAVE_W32_SYSTEM*/ + /* The context used by the file filter. */ typedef struct { - fp_or_fd_t fp; /* Open file pointer or handle. */ + gnupg_fd_t fp; /* Open file pointer or handle. */ int keep_open; int no_cache; int eof_seen; int print_only_name; /* Flags indicating that fname is not a real file. */ char fname[1]; /* Name of the file. */ -} -file_filter_ctx_t; +} file_filter_ctx_t; /* Object to control the "close cache". */ struct close_cache_s { struct close_cache_s *next; - fp_or_fd_t fp; + gnupg_fd_t fp; char fname[1]; }; typedef struct close_cache_s *close_cache_t; @@ -203,7 +163,7 @@ for (cc = close_cache; cc; cc = cc->next) { - if (cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname)) + if (cc->fp != GNUPG_INVALID_FD && !fd_cache_strcmp (cc->fname, fname)) { if (DBG_IOBUF) log_debug (" did (%s)\n", cc->fname); @@ -213,7 +173,7 @@ #else rc = close (cc->fp); #endif - cc->fp = INVALID_FP; + cc->fp = GNUPG_INVALID_FD; } } return rc; @@ -236,7 +196,7 @@ for (cc=close_cache; cc; cc = cc->next ) { - if (cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname)) + if (cc->fp != GNUPG_INVALID_FD && !fd_cache_strcmp (cc->fname, fname)) { if (DBG_IOBUF) log_debug (" did (%s)\n", cc->fname); @@ -252,7 +212,7 @@ } -static fp_or_fd_t +static gnupg_fd_t direct_open (const char *fname, const char *mode) { #ifdef HAVE_W32_SYSTEM @@ -268,7 +228,7 @@ if (strchr (mode, '+')) { if (fd_cache_invalidate (fname)) - return INVALID_FP; + return GNUPG_INVALID_FD; da = GENERIC_READ | GENERIC_WRITE; cd = OPEN_EXISTING; sm = FILE_SHARE_READ | FILE_SHARE_WRITE; @@ -276,7 +236,7 @@ else if (strchr (mode, 'w')) { if (fd_cache_invalidate (fname)) - return INVALID_FP; + return GNUPG_INVALID_FD; da = GENERIC_WRITE; cd = CREATE_ALWAYS; sm = FILE_SHARE_WRITE; @@ -312,13 +272,13 @@ if (strchr (mode, '+')) { if (fd_cache_invalidate (fname)) - return INVALID_FP; + return GNUPG_INVALID_FD; oflag = O_RDWR; } else if (strchr (mode, 'w')) { if (fd_cache_invalidate (fname)) - return INVALID_FP; + return GNUPG_INVALID_FD; oflag = O_WRONLY | O_CREAT | O_TRUNC; } else @@ -353,7 +313,7 @@ * Note that this caching strategy only works if the process does not chdir. */ static void -fd_cache_close (const char *fname, fp_or_fd_t fp) +fd_cache_close (const char *fname, gnupg_fd_t fp) { close_cache_t cc; @@ -372,7 +332,7 @@ /* try to reuse a slot */ for (cc = close_cache; cc; cc = cc->next) { - if (cc->fp == INVALID_FP && !fd_cache_strcmp (cc->fname, fname)) + if (cc->fp == GNUPG_INVALID_FD && !fd_cache_strcmp (cc->fname, fname)) { cc->fp = fp; if (DBG_IOBUF) @@ -393,7 +353,7 @@ /* * Do an direct_open on FNAME but first try to reuse one from the fd_cache */ -static fp_or_fd_t +static gnupg_fd_t fd_cache_open (const char *fname, const char *mode) { close_cache_t cc; @@ -401,10 +361,10 @@ assert (fname); for (cc = close_cache; cc; cc = cc->next) { - if (cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname)) + if (cc->fp != GNUPG_INVALID_FD && !fd_cache_strcmp (cc->fname, fname)) { - fp_or_fd_t fp = cc->fp; - cc->fp = INVALID_FP; + gnupg_fd_t fp = cc->fp; + cc->fp = GNUPG_INVALID_FD; if (DBG_IOBUF) log_debug ("fd_cache_open (%s) using cached fp\n", fname); #ifdef HAVE_W32_SYSTEM @@ -412,13 +372,13 @@ { log_error ("rewind file failed on handle %p: ec=%d\n", fp, (int) GetLastError ()); - fp = INVALID_FP; + fp = GNUPG_INVALID_FD; } #else if (lseek (fp, 0, SEEK_SET) == (off_t) - 1) { log_error ("can't rewind fd %d: %s\n", fp, strerror (errno)); - fp = INVALID_FP; + fp = GNUPG_INVALID_FD; } #endif return fp; @@ -459,7 +419,7 @@ size_t * ret_len) { file_filter_ctx_t *a = opaque; - fp_or_fd_t f = a->fp; + gnupg_fd_t f = a->fp; size_t size = *ret_len; size_t nbytes = 0; int rc = 0; @@ -595,24 +555,14 @@ } else if (control == IOBUFCTRL_FREE) { -#ifdef HAVE_W32_SYSTEM - if (f != FILEP_OR_FD_FOR_STDIN && f != FILEP_OR_FD_FOR_STDOUT) + if (f != FD_FOR_STDIN && f != FD_FOR_STDOUT) { if (DBG_IOBUF) - log_debug ("%s: close handle %p\n", a->fname, f); + log_debug ("%s: close fd/handle %d\n", a->fname, FD2INT (f)); if (!a->keep_open) fd_cache_close (a->no_cache ? NULL : a->fname, f); } -#else - if ((int) f != 0 && (int) f != 1) - { - if (DBG_IOBUF) - log_debug ("%s: close fd %d\n", a->fname, f); - if (!a->keep_open) - fd_cache_close (a->no_cache ? NULL : a->fname, f); - } - f = INVALID_FP; -#endif + f = GNUPG_INVALID_FD; xfree (a); /* We can free our context now. */ } @@ -1230,7 +1180,7 @@ iobuf_open (const char *fname) { iobuf_t a; - fp_or_fd_t fp; + gnupg_fd_t fp; file_filter_ctx_t *fcx; size_t len; int print_only = 0; @@ -1238,16 +1188,13 @@ if (!fname || (*fname == '-' && !fname[1])) { - fp = FILEP_OR_FD_FOR_STDIN; -#ifdef USE_SETMODE - setmode (my_fileno (fp), O_BINARY); -#endif + fp = FD_FOR_STDIN; fname = "[stdin]"; print_only = 1; } else if ((fd = check_special_filename (fname)) != -1) return iobuf_fdopen (translate_file_handle (fd, 0), "rb"); - else if ((fp = my_fopen_ro (fname, "rb")) == INVALID_FP) + else if ((fp = fd_cache_open (fname, "rb")) == GNUPG_INVALID_FD) return NULL; a = iobuf_alloc (1, IOBUF_BUFFER_SIZE); fcx = xmalloc (sizeof *fcx + strlen (fname)); @@ -1262,7 +1209,7 @@ file_filter (fcx, IOBUFCTRL_INIT, NULL, NULL, &len); if (DBG_IOBUF) log_debug ("iobuf-%d.%d: open `%s' fd=%d\n", - a->no, a->subno, fname, (int) my_fileno (fcx->fp)); + a->no, a->subno, fname, FD2INT (fcx->fp)); return a; } @@ -1275,11 +1222,11 @@ iobuf_fdopen (int fd, const char *mode) { iobuf_t a; - fp_or_fd_t fp; + gnupg_fd_t fp; file_filter_ctx_t *fcx; size_t len; - fp = (fp_or_fd_t) fd; + fp = (gnupg_fd_t) fd; a = iobuf_alloc (strchr (mode, 'w') ? 2 : 1, IOBUF_BUFFER_SIZE); fcx = xmalloc (sizeof *fcx + 20); @@ -1330,7 +1277,7 @@ iobuf_create (const char *fname) { iobuf_t a; - fp_or_fd_t fp; + gnupg_fd_t fp; file_filter_ctx_t *fcx; size_t len; int print_only = 0; @@ -1338,16 +1285,13 @@ if (!fname || (*fname == '-' && !fname[1])) { - fp = FILEP_OR_FD_FOR_STDOUT; -#ifdef USE_SETMODE - setmode (my_fileno (fp), O_BINARY); -#endif + fp = FD_FOR_STDOUT; fname = "[stdout]"; print_only = 1; } else if ((fd = check_special_filename (fname)) != -1) return iobuf_fdopen (translate_file_handle (fd, 1), "wb"); - else if ((fp = my_fopen (fname, "wb")) == INVALID_FP) + else if ((fp = direct_open (fname, "wb")) == GNUPG_INVALID_FD) return NULL; a = iobuf_alloc (2, IOBUF_BUFFER_SIZE); fcx = xmalloc (sizeof *fcx + strlen (fname)); @@ -1383,7 +1327,7 @@ if (!fname) return NULL; - else if (!(fp = my_fopen (fname, "ab"))) + else if (!(fp = direct_open (fname, "ab"))) return NULL; a = iobuf_alloc (2, IOBUF_BUFFER_SIZE); fcx = m_alloc (sizeof *fcx + strlen (fname)); @@ -1406,13 +1350,13 @@ iobuf_openrw (const char *fname) { iobuf_t a; - fp_or_fd_t fp; + gnupg_fd_t fp; file_filter_ctx_t *fcx; size_t len; if (!fname) return NULL; - else if ((fp = my_fopen (fname, "r+b")) == INVALID_FP) + else if ((fp = direct_open (fname, "r+b")) == GNUPG_INVALID_FD) return NULL; a = iobuf_alloc (2, IOBUF_BUFFER_SIZE); fcx = xmalloc (sizeof *fcx + strlen (fname)); @@ -2112,7 +2056,7 @@ if ( !a->chain && a->filter == file_filter ) { file_filter_ctx_t *b = a->filter_ov; - fp_or_fd_t fp = b->fp; + gnupg_fd_t fp = b->fp; #if defined(HAVE_W32_SYSTEM) ulong size; @@ -2158,7 +2102,7 @@ log_error ("GetFileSize for handle %p failed: %s\n", fp, w32_strerror (0)); #else - if ( !fstat(my_fileno(fp), &st) ) + if ( !fstat (FD2INT (fp), &st) ) return st.st_size; log_error("fstat() failed: %s\n", strerror(errno) ); #endif @@ -2181,9 +2125,9 @@ if (!a->chain && a->filter == file_filter) { file_filter_ctx_t *b = a->filter_ov; - fp_or_fd_t fp = b->fp; + gnupg_fd_t fp = b->fp; - return my_fileno (fp); + return FD2INT (fp); } return -1; From cvs at cvs.gnupg.org Mon Mar 8 18:05:38 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 18:05:38 +0100 Subject: [svn] GnuPG - r5281 - in trunk: common g10 kbx Message-ID: Author: wk Date: 2010-03-08 18:05:37 +0100 (Mon, 08 Mar 2010) New Revision: 5281 Modified: trunk/common/ChangeLog trunk/common/iobuf.c trunk/common/iobuf.h trunk/g10/ChangeLog trunk/g10/decrypt.c trunk/g10/encrypt.c trunk/g10/exec.c trunk/g10/import.c trunk/g10/keydb.c trunk/g10/keyedit.c trunk/g10/keygen.c trunk/g10/keyring.c trunk/g10/openfile.c trunk/g10/verify.c trunk/kbx/ChangeLog trunk/kbx/keybox-update.c Log: Use macros for iobuf ioctls. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/common/ChangeLog 2010-03-08 17:05:37 UTC (rev 5281) @@ -1,5 +1,13 @@ 2010-03-08 Werner Koch + * iobuf.h (iobuf_ioctl_t): New. Use the new macros instead of the + hard wired values. + * iobuf.c (iobuf_append): Remove. + (iobuf_fdopen): Factor code out to ... + (do_iobuf_fdopen): ... new. + (iobuf_fdopen_nc): New. + (iobuf_open_fd_or_name): Implement using iobuf_fdopen_nc. + * iobuf.c (INVALID_FD): Replace by GNUPG_INVALID_FD. (fp_or_fd_t): Replace by gnupg_fd_t. (my_fileno): Replace by the FD2INT macro. @@ -250,7 +258,7 @@ * iobuf.c: Port David's changes from 1.4: (fd_cache_invalidate): Pass return code from close back. - (direct_open, iobuf_ioctl): Check that eturn value. + (direct_open, iobuf_ioctl): Check that return value. (fd_cache_synchronize): New. (iobuf_ioctl): Add new sub command 4 (fsync). Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/ChangeLog 2010-03-08 17:05:37 UTC (rev 5281) @@ -1,3 +1,7 @@ +2010-03-08 Werner Koch + + Use macros for iobuf_ioctl commands. + 2010-02-17 Werner Koch * keygen.c (ask_user_id): Avoid infinite loop in case of invalid Modified: trunk/kbx/ChangeLog =================================================================== --- trunk/kbx/ChangeLog 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/kbx/ChangeLog 2010-03-08 17:05:37 UTC (rev 5281) @@ -1,3 +1,7 @@ +2010-03-08 Werner Koch + + Use macros for iobuf_ioctl commands. + 2009-12-08 Werner Koch * keybox-search-desc.h (keydb_search_desc): Use u32 type for Modified: trunk/common/iobuf.c =================================================================== --- trunk/common/iobuf.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/common/iobuf.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -1159,15 +1159,7 @@ if (fd == -1) a = iobuf_open (fname); else - { - int fd2; - - fd2 = dup (fd); - if (fd2 == -1) - a = NULL; - else - a = iobuf_fdopen (fd2, mode); - } + a = iobuf_fdopen_nc (fd, mode); return a; } @@ -1214,37 +1206,51 @@ return a; } -/**************** - * Create a head iobuf for reading or writing from/to a file - * Returns: NULL if an error occures and sets ERRNO. - */ -iobuf_t -iobuf_fdopen (int fd, const char *mode) + +static iobuf_t +do_iobuf_fdopen (int fd, const char *mode, int keep_open) { iobuf_t a; gnupg_fd_t fp; file_filter_ctx_t *fcx; size_t len; - fp = (gnupg_fd_t) fd; + fp = INT2FD (fd); a = iobuf_alloc (strchr (mode, 'w') ? 2 : 1, IOBUF_BUFFER_SIZE); fcx = xmalloc (sizeof *fcx + 20); fcx->fp = fp; fcx->print_only_name = 1; + fcx->keep_open = keep_open; sprintf (fcx->fname, "[fd %d]", fd); a->filter = file_filter; a->filter_ov = fcx; file_filter (fcx, IOBUFCTRL_DESC, NULL, (byte *) & a->desc, &len); file_filter (fcx, IOBUFCTRL_INIT, NULL, NULL, &len); if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: fdopen `%s'\n", a->no, a->subno, fcx->fname); - iobuf_ioctl (a, 3, 1, NULL); /* disable fd caching */ + log_debug ("iobuf-%d.%d: fdopen%s `%s'\n", + a->no, a->subno, keep_open? "_nc":"", fcx->fname); + iobuf_ioctl (a, IOBUF_IOCTL_NO_CACHE, 1, NULL); return a; } +/* Create a head iobuf for reading or writing from/to a file Returns: + * NULL and sets ERRNO if an error occured. */ iobuf_t +iobuf_fdopen (int fd, const char *mode) +{ + return do_iobuf_fdopen (fd, mode, 0); +} + +iobuf_t +iobuf_fdopen_nc (int fd, const char *mode) +{ + return do_iobuf_fdopen (fd, mode, 1); +} + + +iobuf_t iobuf_sockopen (int fd, const char *mode) { iobuf_t a; @@ -1263,7 +1269,7 @@ sock_filter (scx, IOBUFCTRL_INIT, NULL, NULL, &len); if (DBG_IOBUF) log_debug ("iobuf-%d.%d: sockopen `%s'\n", a->no, a->subno, scx->fname); - iobuf_ioctl (a, 3, 1, NULL); /* disable fd caching */ + iobuf_ioctl (a, IOBUF_IOCTL_NO_CACHE, 1, NULL); #else a = iobuf_fdopen (fd, mode); #endif @@ -1311,41 +1317,7 @@ return a; } -/**************** - * append to an iobuf; if the file does not exist, create it. - * cannot be used for stdout. - * Note: This is not used. - */ -#if 0 /* not used */ -iobuf_t -iobuf_append (const char *fname) -{ - iobuf_t a; - FILE *fp; - file_filter_ctx_t *fcx; - size_t len; - if (!fname) - return NULL; - else if (!(fp = direct_open (fname, "ab"))) - return NULL; - a = iobuf_alloc (2, IOBUF_BUFFER_SIZE); - fcx = m_alloc (sizeof *fcx + strlen (fname)); - fcx->fp = fp; - strcpy (fcx->fname, fname); - a->real_fname = m_strdup (fname); - a->filter = file_filter; - a->filter_ov = fcx; - file_filter (fcx, IOBUFCTRL_DESC, NULL, (byte *) & a->desc, &len); - file_filter (fcx, IOBUFCTRL_INIT, NULL, NULL, &len); - if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: append `%s'\n", a->no, a->subno, - a->desc?a->desc:"?"); - - return a; -} -#endif - iobuf_t iobuf_openrw (const char *fname) { @@ -1376,12 +1348,15 @@ int -iobuf_ioctl (iobuf_t a, int cmd, int intval, void *ptrval) +iobuf_ioctl (iobuf_t a, iobuf_ioctl_t cmd, int intval, void *ptrval) { - if (cmd == 1) - { /* keep system filepointer/descriptor open */ + if (cmd == IOBUF_IOCTL_KEEP_OPEN) + { + /* Keep system filepointer/descriptor open. This was used in + the past by http.c; this ioctl is not directly used + anymore. */ if (DBG_IOBUF) - log_debug ("iobuf-%d.%d: ioctl `%s' keep=%d\n", + log_debug ("iobuf-%d.%d: ioctl `%s' keep_open=%d\n", a ? a->no : -1, a ? a->subno : -1, a && a->desc ? a->desc : "?", intval); @@ -1401,8 +1376,8 @@ } #endif } - else if (cmd == 2) - { /* invalidate cache */ + else if (cmd == IOBUF_IOCTL_INVALIDATE_CACHE) + { if (DBG_IOBUF) log_debug ("iobuf-*.*: ioctl `%s' invalidate\n", ptrval ? (char *) ptrval : "?"); @@ -1413,8 +1388,8 @@ return 0; } } - else if (cmd == 3) - { /* disallow/allow caching */ + else if (cmd == IOBUF_IOCTL_NO_CACHE) + { if (DBG_IOBUF) log_debug ("iobuf-%d.%d: ioctl `%s' no_cache=%d\n", a ? a->no : -1, a ? a->subno : -1, @@ -1436,7 +1411,7 @@ } #endif } - else if (cmd == 4) + else if (cmd == IOBUF_IOCTL_FSYNC) { /* Do a fsync on the open fd and return any errors to the caller of iobuf_ioctl. Note that we work on a file name here. */ Modified: trunk/common/iobuf.h =================================================================== --- trunk/common/iobuf.h 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/common/iobuf.h 2010-03-08 17:05:37 UTC (rev 5281) @@ -1,5 +1,6 @@ /* iobuf.h - I/O buffer - * Copyright (C) 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2003, + * 2010 Free Software Foundation, Inc. * * This file is part of GNUPG. * @@ -25,7 +26,7 @@ #define DBG_IOBUF iobuf_debug_mode - +/* Filter control modes. */ #define IOBUFCTRL_INIT 1 #define IOBUFCTRL_FREE 2 #define IOBUFCTRL_UNDERFLOW 3 @@ -34,6 +35,17 @@ #define IOBUFCTRL_CANCEL 6 #define IOBUFCTRL_USER 16 + +/* Command codes for iobuf_ioctl. */ +typedef enum + { + IOBUF_IOCTL_KEEP_OPEN = 1, /* Uses intval. */ + IOBUF_IOCTL_INVALIDATE_CACHE = 2, /* Uses ptrval. */ + IOBUF_IOCTL_NO_CACHE = 3, /* Uses intval. */ + IOBUF_IOCTL_FSYNC = 4 /* Uses ptrval. */ + } iobuf_ioctl_t; + + typedef struct iobuf_struct *iobuf_t; typedef struct iobuf_struct *IOBUF; /* Compatibility with gpg 1.4. */ @@ -89,11 +101,12 @@ const char *mode); iobuf_t iobuf_open (const char *fname); iobuf_t iobuf_fdopen (int fd, const char *mode); +iobuf_t iobuf_fdopen_nc (int fd, const char *mode); iobuf_t iobuf_sockopen (int fd, const char *mode); iobuf_t iobuf_create (const char *fname); iobuf_t iobuf_append (const char *fname); iobuf_t iobuf_openrw (const char *fname); -int iobuf_ioctl (iobuf_t a, int cmd, int intval, void *ptrval); +int iobuf_ioctl (iobuf_t a, iobuf_ioctl_t cmd, int intval, void *ptrval); int iobuf_close (iobuf_t iobuf); int iobuf_cancel (iobuf_t iobuf); @@ -140,10 +153,10 @@ void iobuf_skip_rest (iobuf_t a, unsigned long n, int partial); -/* get a byte form the iobuf; must check for eof prior to this function - * this function returns values in the range 0 .. 255 or -1 to indicate EOF - * iobuf_get_noeof() does not return -1 to indicate EOF, but masks the - * returned value to be in the range 0 ..255. +/* Get a byte from the iobuf; must check for eof prior to this + * function. This function returns values in the range 0 .. 255 or -1 + * to indicate EOF. iobuf_get_noeof() does not return -1 to indicate + * EOF, but masks the returned value to be in the range 0 .. 255. */ #define iobuf_get(a) \ ( ((a)->nofast || (a)->d.start >= (a)->d.len )? \ Modified: trunk/g10/decrypt.c =================================================================== --- trunk/g10/decrypt.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/decrypt.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -223,7 +223,7 @@ goto next_file; fp = iobuf_open(filename); if (fp) - iobuf_ioctl (fp,3,1,NULL); /* disable fd caching */ + iobuf_ioctl (fp, IOBUF_IOCTL_NO_CACHE, 1, NULL); if (fp && is_secured_file (iobuf_get_fd (fp))) { iobuf_close (fp); Modified: trunk/g10/encrypt.c =================================================================== --- trunk/g10/encrypt.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/encrypt.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -185,7 +185,7 @@ /* Prepare iobufs. */ inp = iobuf_open(filename); if (inp) - iobuf_ioctl (inp,3,1,NULL); /* disable fd caching */ + iobuf_ioctl (inp, IOBUF_IOCTL_NO_CACHE, 1, NULL); if (inp && is_secured_file (iobuf_get_fd (inp))) { iobuf_close (inp); @@ -526,7 +526,7 @@ /* Prepare iobufs. */ inp = iobuf_open_fd_or_name (filefd, filename, "rb"); if (inp) - iobuf_ioctl (inp, 3, 1, NULL); /* Disable fd caching. */ + iobuf_ioctl (inp, IOBUF_IOCTL_NO_CACHE, 1, NULL); if (inp && is_secured_file (iobuf_get_fd (inp))) { iobuf_close (inp); Modified: trunk/g10/exec.c =================================================================== --- trunk/g10/exec.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/exec.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -449,8 +449,8 @@ goto fail; } - /* fd iobufs are cached?! */ - iobuf_ioctl((*info)->fromchild,3,1,NULL); + /* fd iobufs are cached! */ + iobuf_ioctl((*info)->fromchild, IOBUF_IOCTL_NO_CACHE, 1, NULL); return 0; } @@ -556,7 +556,7 @@ } /* Do not cache this iobuf on close */ - iobuf_ioctl(info->fromchild,3,1,NULL); + iobuf_ioctl(info->fromchild, IOBUF_IOCTL_NO_CACHE, 1, NULL); } } Modified: trunk/g10/import.c =================================================================== --- trunk/g10/import.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/import.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -196,7 +196,8 @@ rc = import( inp2, fname, stats, fpr, fpr_len, options ); iobuf_close(inp2); /* Must invalidate that ugly cache to actually close it. */ - iobuf_ioctl (NULL, 2, 0, (char*)fname); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, + 0, (char*)fname); if( rc ) log_error("import from `%s' failed: %s\n", fname, g10_errstr(rc) ); Modified: trunk/g10/keydb.c =================================================================== --- trunk/g10/keydb.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/keydb.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -188,7 +188,7 @@ iobuf_close (iobuf); /* Must invalidate that ugly cache */ - iobuf_ioctl (NULL, 2, 0, filename); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, filename); rc = 0; leave: Modified: trunk/g10/keyedit.c =================================================================== --- trunk/g10/keyedit.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/keyedit.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -1981,7 +1981,7 @@ init_packet (pkt); rc = parse_packet (a, pkt); iobuf_close (a); - iobuf_ioctl (NULL, 2, 0, (char*)fname); /* (invalidate cache). */ + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname); if (!rc && pkt->pkttype != PKT_SECRET_KEY && pkt->pkttype != PKT_SECRET_SUBKEY) Modified: trunk/g10/keygen.c =================================================================== --- trunk/g10/keygen.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/keygen.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -2877,7 +2877,7 @@ log_error (_("can't open `%s': %s\n"), fname, strerror(errno) ); return; } - iobuf_ioctl (fp, 3, 1, NULL); /* No file caching. */ + iobuf_ioctl (fp, IOBUF_IOCTL_NO_CACHE, 1, NULL); lnr = 0; err = NULL; @@ -3018,9 +3018,11 @@ /* Must invalidate that ugly cache to actually close it. */ if (outctrl.pub.fname) - iobuf_ioctl (NULL, 2, 0, (char*)outctrl.pub.fname); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, + 0, (char*)outctrl.pub.fname); if (outctrl.sec.fname) - iobuf_ioctl (NULL, 2, 0, (char*)outctrl.sec.fname); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, + 0, (char*)outctrl.sec.fname); xfree( outctrl.pub.fname ); xfree( outctrl.pub.newfname ); @@ -3377,7 +3379,8 @@ iobuf_close(outctrl->pub.stream); outctrl->pub.stream = NULL; if (outctrl->pub.fname) - iobuf_ioctl (NULL, 2, 0, (char*)outctrl->pub.fname); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, + 0, (char*)outctrl->pub.fname); xfree( outctrl->pub.fname ); outctrl->pub.fname = outctrl->pub.newfname; outctrl->pub.newfname = NULL; @@ -3408,7 +3411,8 @@ iobuf_close(outctrl->sec.stream); outctrl->sec.stream = NULL; if (outctrl->sec.fname) - iobuf_ioctl (NULL, 2, 0, (char*)outctrl->sec.fname); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, + 0, (char*)outctrl->sec.fname); xfree( outctrl->sec.fname ); outctrl->sec.fname = outctrl->sec.newfname; outctrl->sec.newfname = NULL; @@ -4187,7 +4191,7 @@ char *fprbuf, *p; iobuf_close (fp); - iobuf_ioctl (NULL, 2, 0, (char*)fname); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname); log_info (_("NOTE: backup of card key saved to `%s'\n"), fname); fingerprint_from_sk (sk, array, &n); Modified: trunk/g10/keyring.c =================================================================== --- trunk/g10/keyring.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/keyring.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -1255,20 +1255,20 @@ /* It's a secret keyring, so let's force a fsync just to be safe on filesystems that may not sync data and metadata together (e.g. ext4). */ - if (secret && iobuf_ioctl (NULL, 4, 0, (char*)tmpfname)) + if (secret && iobuf_ioctl (NULL, IOBUF_IOCTL_FSYNC, 0, (char*)tmpfname)) { rc = gpg_error_from_syserror (); goto fail; } /* Invalidate close caches. */ - if (iobuf_ioctl (NULL, 2, 0, (char*)tmpfname )) + if (iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)tmpfname )) { rc = gpg_error_from_syserror (); goto fail; } - iobuf_ioctl (NULL, 2, 0, (char*)bakfname ); - iobuf_ioctl (NULL, 2, 0, (char*)fname ); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)bakfname ); + iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname ); /* first make a backup file except for secret keyrings */ if (!secret) Modified: trunk/g10/openfile.c =================================================================== --- trunk/g10/openfile.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/openfile.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -305,7 +305,7 @@ } if (*a) - iobuf_ioctl (*a, 3, 1, NULL); /* Disable fd caching. */ + iobuf_ioctl (*a, IOBUF_IOCTL_NO_CACHE, 1, NULL); return rc; } Modified: trunk/g10/verify.c =================================================================== --- trunk/g10/verify.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/g10/verify.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -150,7 +150,7 @@ print_file_status( STATUS_FILE_START, name, 1 ); fp = iobuf_open(name); if (fp) - iobuf_ioctl (fp,3,1,NULL); /* disable fd caching */ + iobuf_ioctl (fp, IOBUF_IOCTL_NO_CACHE, 1, NULL); if (fp && is_secured_file (iobuf_get_fd (fp))) { iobuf_close (fp); Modified: trunk/kbx/keybox-update.c =================================================================== --- trunk/kbx/keybox-update.c 2010-03-08 13:06:53 UTC (rev 5280) +++ trunk/kbx/keybox-update.c 2010-03-08 17:05:37 UTC (rev 5281) @@ -166,9 +166,9 @@ #endif /* fixme: invalidate close caches (not used with stdio)*/ -/* iobuf_ioctl (NULL, 2, 0, (char*)tmpfname ); */ -/* iobuf_ioctl (NULL, 2, 0, (char*)bakfname ); */ -/* iobuf_ioctl (NULL, 2, 0, (char*)fname ); */ +/* iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)tmpfname ); */ +/* iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)bakfname ); */ +/* iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname ); */ /* First make a backup file except for secret keyboxes. */ if (!secret) From cvs at cvs.gnupg.org Mon Mar 8 19:19:21 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 19:19:21 +0100 Subject: [svn] GnuPG - r5282 - in trunk: g10 sm Message-ID: Author: wk Date: 2010-03-08 19:19:21 +0100 (Mon, 08 Mar 2010) New Revision: 5282 Modified: trunk/g10/ChangeLog trunk/g10/main.h trunk/g10/mainproc.c trunk/g10/openfile.c trunk/g10/plaintext.c trunk/g10/server.c trunk/g10/verify.c trunk/sm/ChangeLog trunk/sm/certreqgen-ui.c trunk/sm/certreqgen.c trunk/sm/export.c trunk/sm/gpgsm.c trunk/sm/gpgsm.h trunk/sm/server.c Log: Removed almost al dup calls. Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/ChangeLog 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,5 +1,15 @@ 2010-03-08 Werner Koch + * main.h: Include "estream.h" + * openfile.c (open_outfile): Replace dup/iobuf_fdopen by + iobuf_fdopen_nc. + * mainproc.c (proc_signature_packets_by_fd): Return error on + memory failure. + * plaintext.c (hash_datafile_by_fd): Ditto. + * verify.c (gpg_verify): Use iobuf_fdopen_nc. Change OUT_FP to an + estream_t. + * server.c (cmd_verify): Do not dup the fds. + Use macros for iobuf_ioctl commands. 2010-02-17 Werner Koch @@ -23,7 +33,7 @@ * revoke.c (gen_desig_revoke): Ditto. * skclist.c (release_sk_list): Ditto. * keyedit.c (sign_uids): Ditto. - * misc.c (get_signature_count): Ditto. + * misc.c (get_signature_count): Ditto. * main.h (struct expand_args): s/sk/pksk/. Change all users. * keyedit.c (keyedit_passwd): Finish implementation. Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/ChangeLog 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,11 +1,20 @@ 2010-03-08 Werner Koch + * certreqgen.c (gpgsm_genkey): Change OUT_FP to an estream_t + OUT_STREAM. + * certreqgen-ui.c (gpgsm_gencertreq_tty): ditto. + + * server.c (cmd_genkey): Close IN_STREAM. + * server.c (cmd_encrypt, cmd_decrypt, cmd_verify, cmd_sign): Avoid dup call by using es_fdopen_nc. (do_listkeys): Use es_fdopen_nc instead of dup and es_fdopen. + (cmd_export): Ditto. + (cmd_genkey): Ditto. * export.c (popen_protect_tool): Change OUTFILE to an estream_t. (export_p12): Change OUTFP and arg RETFP to an estream_t. (gpgsm_p12_export): Change DATAFP to an estream_t. + (gpgsm_export): Remove arg FP. * import.c (import_one): Change CERTFP and arg FP to an estream_t. (popen_protect_tool): Ditto for OUTFILE. (parse_p12): Change CERTFP to an estream_t. @@ -23,6 +32,7 @@ (encrypt_cb): Use estream. * gpgsm.c (main) : Use estream functions. + (main) : Use open_es_fwrite. 2009-12-14 Werner Koch Modified: trunk/g10/main.h =================================================================== --- trunk/g10/main.h 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/main.h 2010-03-08 18:19:21 UTC (rev 5282) @@ -25,8 +25,8 @@ #include "cipher.h" #include "keydb.h" #include "util.h" +#include "../common/estream.h" - /* It could be argued that the default cipher should be 3DES rather than CAST5, and the default compression should be 0 (i.e. uncompressed) rather than 1 (zip). However, the real world @@ -316,7 +316,7 @@ void print_file_status( int status, const char *name, int what ); int verify_signatures( int nfiles, char **files ); int verify_files( int nfiles, char **files ); -int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, FILE *out_fp); +int gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp); /*-- decrypt.c --*/ int decrypt_message( const char *filename ); Modified: trunk/g10/mainproc.c =================================================================== --- trunk/g10/mainproc.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/mainproc.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -78,7 +78,7 @@ /* A list of filenames with the data files or NULL. This is only used if DATA_FD is -1. */ strlist_t data_names; - /* Flag to indicated that either one of the next previous fieldss + /* Flag to indicated that either one of the next previous fields is used. This is only needed for better readability. */ int used; } signed_data; @@ -1221,12 +1221,17 @@ return rc; } + int proc_signature_packets_by_fd (void *anchor, IOBUF a, int signed_data_fd ) { int rc; - CTX c = xcalloc (1, sizeof *c); + CTX c; + c = xtrycalloc (1, sizeof *c); + if (!c) + return gpg_error_from_syserror (); + c->anchor = anchor; c->sigs_only = 1; Modified: trunk/g10/openfile.c =================================================================== --- trunk/g10/openfile.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/openfile.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,6 +1,6 @@ /* openfile.c - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, - * 2005, 2009 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -192,13 +192,8 @@ if (inp_fd != -1) { char xname[64]; - int fd2; - fd2 = dup (inp_fd); - if (fd2 == -1) - *a = NULL; - else - *a = iobuf_fdopen (fd2, "wb"); + *a = iobuf_fdopen_nc (inp_fd, "wb"); if (!*a) { rc = gpg_error_from_syserror (); Modified: trunk/g10/plaintext.c =================================================================== --- trunk/g10/plaintext.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/plaintext.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,6 +1,6 @@ /* plaintext.c - process plaintext packets * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - * 2006, 2009 Free Software Foundation, Inc. + * 2006, 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -651,13 +651,14 @@ progress_filter_context_t *pfx = new_progress_context (); iobuf_t fp; - fp = iobuf_fdopen (data_fd, "rb"); - if (fp && is_secured_file (data_fd)) + if (is_secured_file (data_fd)) { - iobuf_close (fp); fp = NULL; errno = EPERM; } + else + fp = iobuf_fdopen_nc (data_fd, "rb"); + if (!fp) { int rc = gpg_error_from_syserror (); Modified: trunk/g10/server.c =================================================================== --- trunk/g10/server.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/server.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -400,7 +400,7 @@ ctrl_t ctrl = assuan_get_pointer (ctx); gnupg_fd_t fd = assuan_get_input_fd (ctx); gnupg_fd_t out_fd = assuan_get_output_fd (ctx); - FILE *out_fp = NULL; + estream_t out_fp = NULL; /* FIXME: Revamp this code it is nearly to 3 years old and was only intended as a quick test. */ @@ -412,23 +412,17 @@ if (out_fd != GNUPG_INVALID_FD) { - out_fp = fdopen ( dup (FD2INT (out_fd)), "w"); + out_fp = es_fdopen_nc (out_fd, "w"); if (!out_fp) - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); } log_debug ("WARNING: The server mode is WORK " "iN PROGRESS and not ready for use\n"); - /* Need to dup it because it might get closed and libassuan won't - know about it then. */ - rc = gpg_verify (ctrl, - dup ( FD2INT (fd)), - dup ( FD2INT (ctrl->server_local->message_fd)), - out_fp); + rc = gpg_verify (ctrl, fd, ctrl->server_local->message_fd, out_fp); - if (out_fp) - fclose (out_fp); + es_fclose (out_fp); close_message_fd (ctrl); assuan_close_input_fd (ctx); assuan_close_output_fd (ctx); Modified: trunk/g10/verify.c =================================================================== --- trunk/g10/verify.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/g10/verify.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,6 +1,6 @@ /* verify.c - Verify signed data * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, - * 2007 Free Software Foundation, Inc. + * 2007, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -39,7 +39,6 @@ #include "i18n.h" - /**************** * Assume that the input is a signature and verify it without * generating any output. With no arguments, the signature packet @@ -231,7 +230,7 @@ FIXME: OUTFP is not yet implemented. */ int -gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, FILE *out_fp) +gpg_verify (ctrl_t ctrl, int sig_fd, int data_fd, estream_t out_fp) { int rc; iobuf_t fp; @@ -241,13 +240,14 @@ (void)ctrl; (void)out_fp; - fp = iobuf_fdopen (sig_fd, "rb"); - if (fp && is_secured_file (sig_fd)) + if (is_secured_file (sig_fd)) { fp = NULL; - errno = EPERM; + gpg_err_set_errno (EPERM); } - if ( !fp ) + else + fp = iobuf_fdopen_nc (sig_fd, "rb"); + if (!fp) { rc = gpg_error_from_syserror (); log_error (_("can't open fd %d: %s\n"), sig_fd, strerror (errno)); @@ -262,15 +262,14 @@ push_armor_filter (afx, fp); } - rc = proc_signature_packets_by_fd ( NULL, fp, data_fd ); + rc = proc_signature_packets_by_fd (NULL, fp, data_fd); if ( afx && afx->no_openpgp_data && (rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF) ) rc = gpg_error (GPG_ERR_NO_DATA); leave: - if (fp) - iobuf_close (fp); + iobuf_close (fp); release_progress_context (pfx); release_armor_context (afx); return rc; Modified: trunk/sm/certreqgen-ui.c =================================================================== --- trunk/sm/certreqgen-ui.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/certreqgen-ui.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,5 +1,5 @@ /* certreqgen-ui.c - Simple user interface for certreqgen.c - * Copyright (C) 2007 Free Software Foundation, Inc. + * Copyright (C) 2007, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -125,7 +125,7 @@ and thus is not suitable for the Windows port. So here is the re-implementation. */ void -gpgsm_gencertreq_tty (ctrl_t ctrl, FILE *output_fp) +gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t output_stream) { gpg_error_t err; char *answer; @@ -391,7 +391,7 @@ { int save_pem = ctrl->create_pem; ctrl->create_pem = 1; /* Force creation of PEM. */ - err = gpgsm_genkey (ctrl, fp, output_fp); + err = gpgsm_genkey (ctrl, fp, output_stream); ctrl->create_pem = save_pem; } if (!err) Modified: trunk/sm/certreqgen.c =================================================================== --- trunk/sm/certreqgen.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/certreqgen.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -1,5 +1,6 @@ /* certreqgen.c - Generate a key and a certification request - * Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc. + * Copyright (C) 2002, 2003, 2005, 2007, + * 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -846,14 +847,14 @@ /* Create a new key by reading the parameters from IN_FP. Multiple keys may be created */ int -gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, FILE *out_fp) +gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, estream_t out_stream) { int rc; Base64Context b64writer = NULL; ksba_writer_t writer; ctrl->pem_name = "CERTIFICATE REQUEST"; - rc = gpgsm_create_writer (&b64writer, ctrl, out_fp, NULL, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, NULL, out_stream, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); Modified: trunk/sm/export.c =================================================================== --- trunk/sm/export.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/export.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -125,12 +125,10 @@ } - - -/* Export all certificates or just those given in NAMES. If STREAM is - not NULL the output is send to this extended stream. */ +/* Export all certificates or just those given in NAMES. The output + is written to STREAM. */ void -gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream) +gpgsm_export (ctrl_t ctrl, strlist_t names, estream_t stream) { KEYDB_HANDLE hd = NULL; KEYDB_SEARCH_DESC *desc = NULL; @@ -256,24 +254,17 @@ if (ctrl->create_pem) { if (count) - { - if (stream) - es_putc ('\n', stream); - else - putc ('\n', fp); - } - print_short_info (cert, fp, stream); - if (stream) es_putc ('\n', stream); - else - putc ('\n', fp); + print_short_info (cert, NULL, stream); + es_putc ('\n', stream); } count++; if (!b64writer) { ctrl->pem_name = "CERTIFICATE"; - rc = gpgsm_create_writer (&b64writer, ctrl, fp, stream, &writer); + rc = gpgsm_create_writer (&b64writer, ctrl, + NULL, stream, &writer); if (rc) { log_error ("can't create writer: %s\n", gpg_strerror (rc)); Modified: trunk/sm/gpgsm.c =================================================================== --- trunk/sm/gpgsm.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/gpgsm.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -1829,7 +1829,7 @@ case aKeygen: /* Generate a key; well kind of. */ { estream_t fpin = NULL; - FILE *fpout; + estream_t fpout; if (opt.batch) { @@ -1841,15 +1841,14 @@ wrong_args ("--gen-key --batch [parmfile]"); } - fpout = open_fwrite (opt.outfile?opt.outfile:"-"); + fpout = open_es_fwrite (opt.outfile?opt.outfile:"-"); if (fpin) gpgsm_genkey (&ctrl, fpin, fpout); else gpgsm_gencertreq_tty (&ctrl, fpout); - if (fpout != stdout) - fclose (fpout); + es_fclose (fpout); } break; @@ -1860,14 +1859,14 @@ case aExport: { - FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-"); + estream_t fp; + fp = open_es_fwrite (opt.outfile?opt.outfile:"-"); for (sl=NULL; argc; argc--, argv++) add_to_strlist (&sl, *argv); - gpgsm_export (&ctrl, sl, fp, NULL); + gpgsm_export (&ctrl, sl, fp); free_strlist(sl); - if (fp != stdout) - fclose (fp); + es_fclose (fp); } break; Modified: trunk/sm/gpgsm.h =================================================================== --- trunk/sm/gpgsm.h 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/gpgsm.h 2010-03-08 18:19:21 UTC (rev 5282) @@ -344,7 +344,7 @@ int (*of)(const char *fname)); /*-- export.c --*/ -void gpgsm_export (ctrl_t ctrl, strlist_t names, FILE *fp, estream_t stream); +void gpgsm_export (ctrl_t ctrl, strlist_t names, estream_t stream); void gpgsm_p12_export (ctrl_t ctrl, const char *name, FILE *fp); /*-- delete.c --*/ @@ -366,10 +366,10 @@ int gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp); /*-- certreqgen.c --*/ -int gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, FILE *out_fp); +int gpgsm_genkey (ctrl_t ctrl, estream_t in_stream, estream_t out_stream); /*-- certreqgen-ui.c --*/ -void gpgsm_gencertreq_tty (ctrl_t ctrl, FILE *out_fp); +void gpgsm_gencertreq_tty (ctrl_t ctrl, estream_t out_stream); /*-- qualified.c --*/ Modified: trunk/sm/server.c =================================================================== --- trunk/sm/server.c 2010-03-08 17:05:37 UTC (rev 5281) +++ trunk/sm/server.c 2010-03-08 18:19:21 UTC (rev 5282) @@ -723,28 +723,28 @@ return set_error (GPG_ERR_ASS_GENERAL, "error setting up a data stream"); } - gpgsm_export (ctrl, list, NULL, stream); + gpgsm_export (ctrl, list, stream); es_fclose (stream); } else { int fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1); - FILE *out_fp; + estream_t out_fp; if (fd == -1) { free_strlist (list); return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL); } - out_fp = fdopen ( dup(fd), "w"); + out_fp = es_fdopen_nc (fd, "w"); if (!out_fp) { free_strlist (list); - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); } - gpgsm_export (ctrl, list, out_fp, NULL); - fclose (out_fp); + gpgsm_export (ctrl, list, out_fp); + es_fclose (out_fp); } free_strlist (list); @@ -977,9 +977,8 @@ { ctrl_t ctrl = assuan_get_pointer (ctx); int inp_fd, out_fd; - FILE *out_fp; + estream_t in_stream, out_stream; int rc; - estream_t in_stream; (void)line; @@ -994,14 +993,15 @@ if (!in_stream) return set_error (GPG_ERR_ASS_GENERAL, "es_fdopen failed"); - out_fp = fdopen ( dup(out_fd), "w"); - if (!out_fp) + out_stream = es_fdopen_nc (out_fd, "w"); + if (!out_stream) { es_fclose (in_stream); - return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed"); + return set_error (gpg_err_code_from_syserror (), "fdopen() failed"); } - rc = gpgsm_genkey (ctrl, in_stream, out_fp); - fclose (out_fp); + rc = gpgsm_genkey (ctrl, in_stream, out_stream); + es_fclose (out_stream); + es_fclose (in_stream); /* close and reset the fds */ assuan_close_input_fd (ctx); From cvs at cvs.gnupg.org Mon Mar 8 21:53:09 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 08 Mar 2010 21:53:09 +0100 Subject: [svn] gpg-error - r235 - in trunk: . src Message-ID: Author: wk Date: 2010-03-08 21:53:08 +0100 (Mon, 08 Mar 2010) New Revision: 235 Modified: trunk/ChangeLog trunk/src/w32-add.h Log: Use format_arg attribute Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-01 19:54:41 UTC (rev 234) +++ trunk/ChangeLog 2010-03-08 20:53:08 UTC (rev 235) @@ -1,3 +1,8 @@ +2010-03-08 Werner Koch + + * src/w32-add.h (_GPG_ERR_ATTR_FORMAT_ARG): New. + (_gpg_w32_gettext, _gpg_w32_dgettext, _gpg_w32_dngettext): Use it. + 2010-03-01 Werner Koch * src/mkw32errmap.c: Map ESPIPE. @@ -167,9 +172,9 @@ 2008-11-26 Werner Koch Release 1.7. - + * configure.ac: Set LT version to C5/A5/R0. - + 2008-11-12 Werner Koch * src/err-codes.h.in: Add GPG_ERR_NO_PASSPHRASE and GPG_ERR_NO_PIN. @@ -207,9 +212,9 @@ * configure.ac: Set LT version to C4/A4/R0. * config.guess, config.sub: Updated. - - * src/err-sources.h.in: (GPG_ERR_SOURCE_KLEO): New. + * src/err-sources.h.in: (GPG_ERR_SOURCE_KLEO): New. + * w32-gettext.c (SUBLANG_BENGALI_BANGLADESH): Fix to 2 as per MSDN. (SUBLANG_PUNJABI_PAKISTAN): Remove as it is not in MSDN. (SUBLANG_ROMANIAN_MOLDOVA): Remove as it is not in MSDN. @@ -232,7 +237,7 @@ * lang/cl/Makefile.am: Do not use :=, but =. * Makefile.am [!LANGUAGES_SOME]: Don't add lang to subdirs. * m4/inttypes-h.m4, m4/lock.m4, m4/visibility.m4: New files. - + 2007-05-19 Marcus Brinkmann * lang/cl/gpg-error.lisp (gpg-err-source-t): Add @@ -263,7 +268,7 @@ 2006-11-30 Werner Koch Released 1.5. - + * configure.ac: Set LT version to C3/A3/R1. * README: Switch to tar.bz2 and sha1sum. @@ -316,7 +321,7 @@ * lang/cl/gpg-error.lisp ("gpg_err_code_from_syserror"): New. (gpg-err-code-from-syserror): New. (gpg-error-from-syserror): New. - * lang/cl/gpg-error-package.lisp: Export new functions + * lang/cl/gpg-error-package.lisp: Export new functions * src/gpg-error.h.in (gpg_error_from_syserror): New. * src/code-from-errno.c (gpg_err_code_from_errno): Cosmetic change @@ -363,7 +368,7 @@ * lang/cl/mkerrcodes.awk, lang/cl/gpg-error-package.lisp, lang/cl/gpg-error.lisp, lang/cl/gpg-error.asd, lang/cl/Makefile.am (clfilesdir): Fix package and file names. - + * lang/cl/Makefile.am (clfilesdir): Use datadir, not prefix. 2006-05-05 Marcus Brinkmann @@ -461,7 +466,7 @@ AC_LIBTOOL_WIN32_DLL and AC_LIBTOOL_RC. * src/Makefile.am [HAVE_W32_SYSTEM]: Use libtool, which simplifies the rules. - + 2005-10-02 Marcus Brinkmann * configure.ac: Escape arguments in AC_INIT invocation. @@ -477,7 +482,7 @@ 2005-06-20 Marcus Brinkmann Released 1.1. - + * configure.ac: Bump up LIBGPG_ERROR_LT_REVISION, update version field. @@ -514,7 +519,7 @@ 2004-07-30 Werner Koch Released 1.0. - + * configure.ac: Bumbed version to 1.0, LT to C1/A1/R3. 2004-07-15 Werner Koch @@ -567,7 +572,7 @@ * libgpg-error.spec.in (%files): Add gpg-error. Submitted by Albrecht Dre? . - + * src/mkerrcodes.c (main): Fix type of argv. Return something. 2004-03-09 Werner Koch @@ -612,7 +617,7 @@ anyway). * src/mkerrcodes.awk: New file. * src/mkerrcodes.c: New file. - + 2004-02-27 Marcus Brinkmann * src/Makefile.am (noinst_PROGRAMS): Rename to ... @@ -690,7 +695,7 @@ * configure.ac: Bumbed version number to 0.7. Released 0.6. - + * configure.ac: Bumbed up LIBGPG_ERROR_LT_REVISON. 2003-11-13 Werner Koch @@ -713,13 +718,13 @@ GPG_ERR_UNSUPPORTED_CMS_OBJ, GPG_ERR_UNSUPPORTED_ENCODING, GPG_ERR_UNSUPPORTED_CMS_VERSION, GPG_ERR_UNKNOWN_ALGORITHM, GPG_ERR_ENCODING_PROBLEM, GPG_ERR_INV_STATE, GPG_ERR_DUP_VALUE, - GPG_ERR_MISSING_ACTION, GPG_ERR_MODULE_NOT_FOUND, + GPG_ERR_MISSING_ACTION, GPG_ERR_MODULE_NOT_FOUND, GPG_ERR_INV_OID_STRING, GPG_ERR_INV_TIME, GPG_ERR_INV_CRL_OBJ, GPG_ERR_UNSUPPORTED_CRL_VERSION, GPG_ERR_INV_CERT_OBJ, GPG_ERR_UNKNOWN_NAME, GPG_ERR_IO_ERROR, GPG_ERR_FILE_ERROR, GPG_ERR_READ_ERROR, GPG_ERR_WRITE_ERROR, GPG_ERR_LOCK_ERROR, GPG_ERR_BUFFER_TOO_SHORT. - + 2003-11-06 Werner Koch * src/gpg-error.h, src/err-sources.h.in: Added error sources for @@ -727,7 +732,7 @@ 2003-11-03 Werner Koch - * src/gpg-error.h: Allow GPG_ERR_INLINE to get overriden, so that + * src/gpg-error.h: Allow GPG_ERR_INLINE to get overriden, so that one can use the -D flag to specify the inline keyword. Suggested by Philip Brown. @@ -737,7 +742,7 @@ GPG_ERR_NO_ENCODING_METHOD, GPG_ERR_NO_ENCRYPTION_SCHEME, GPG_ERR_NO_SIGNATURE_SCHEME. * src/err-codes.h.in: Likewise. - + 2003-10-25 Werner Koch * src/strerror.c: Include stdio.h for snprintf @@ -781,7 +786,7 @@ * libgpg-error.spec.in: New file. * Makefile.am (EXTRA_DIST): Add libgpg-error.spec.in. * AUTHORS (Maintainer): Add Robert Schiele as contributor. - + 2003-09-03 Marcus Brinkmann * src/gpg-error-config.in: Rewritten. @@ -986,7 +991,7 @@ * src/gpg-error.h: ... here. New file. * src/strerror.c: Include , not . * src/strsource.c: Likewise. - + * src/gpg/error.h (gpg_error_t): Change type to unsigned int, not long. @@ -1011,7 +1016,7 @@ * tests/Makefile.am: Likewise. * src/mkstrtable.awk: New variable HEADER. Copy input until first - line with an actual code and description occurs. + line with an actual code and description occurs. * src/err-codes.h.in: Uncomment license, so it is copied into the output. * src/err-sources.h.in: Likewise. @@ -1024,7 +1029,7 @@ * Initial check-in. - Copyright 2003, 2004, 2005, 2006, 2007 g10 Code GmbH + Copyright 2003, 2004, 2005, 2006, 2007, 2010 g10 Code GmbH This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without Modified: trunk/src/w32-add.h =================================================================== --- trunk/src/w32-add.h 2010-03-01 19:54:41 UTC (rev 234) +++ trunk/src/w32-add.h 2010-03-08 20:53:08 UTC (rev 235) @@ -1,16 +1,28 @@ ## w32-add.h - Snippet to be be included into gpg-error.h. -## (Comments are indicated by a double hash mark) +## Comments are indicated by a double hash mark. Due to a +## peculiarity of the script the first used line must not +## start with a hash mark. +/* Decide whether to use the format_arg attribute. */ +#if _GPG_ERR_GCC_VERSION > 20800 +# define _GPG_ERR_ATTR_FORMAT_ARG(a) __attribute__ ((__format_arg__ (a))) +#else +# define _GPG_ERR_ATTR_FORMAT_ARG(a) +#endif + /* A lean gettext implementation based on GNU style mo files which are required to be encoded in UTF-8. There is a limit on 65534 entries to save some RAM. Only Germanic plural rules are supported. */ const char *_gpg_w32_bindtextdomain (const char *domainname, const char *dirname); const char *_gpg_w32_textdomain (const char *domainname); -const char *_gpg_w32_gettext (const char *msgid); -const char *_gpg_w32_dgettext (const char *domainname, const char *msgid); +const char *_gpg_w32_gettext (const char *msgid) + _GPG_ERR_ATTR_FORMAT_ARG (1); +const char *_gpg_w32_dgettext (const char *domainname, const char *msgid) + _GPG_ERR_ATTR_FORMAT_ARG (2); const char *_gpg_w32_dngettext (const char *domainname, const char *msgid1, - const char *msgid2, unsigned long int n); + const char *msgid2, unsigned long int n) + _GPG_ERR_ATTR_FORMAT_ARG (2) _GPG_ERR_ATTR_FORMAT_ARG (3); const char *_gpg_w32_gettext_localename (void); int _gpg_w32_gettext_use_utf8 (int value); From cvs at cvs.gnupg.org Tue Mar 9 10:55:25 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 10:55:25 +0100 Subject: [svn] GnuPG - r5283 - in branches/STABLE-BRANCH-2-0: . g10 Message-ID: Author: wk Date: 2010-03-09 10:55:24 +0100 (Tue, 09 Mar 2010) New Revision: 5283 Modified: branches/STABLE-BRANCH-2-0/ChangeLog branches/STABLE-BRANCH-2-0/configure.ac branches/STABLE-BRANCH-2-0/g10/ChangeLog branches/STABLE-BRANCH-2-0/g10/sign.c Log: Add configure option --disable-ccid-driver Modified: branches/STABLE-BRANCH-2-0/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/ChangeLog 2010-03-08 18:19:21 UTC (rev 5282) +++ branches/STABLE-BRANCH-2-0/ChangeLog 2010-03-09 09:55:24 UTC (rev 5283) @@ -1,3 +1,7 @@ +2010-03-09 Werner Koch + + * configure.ac: Add option --disable-ccid-driver. + 2010-02-18 Werner Koch Release 2.0.15rc1. Modified: branches/STABLE-BRANCH-2-0/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/g10/ChangeLog 2010-03-08 18:19:21 UTC (rev 5282) +++ branches/STABLE-BRANCH-2-0/g10/ChangeLog 2010-03-09 09:55:24 UTC (rev 5283) @@ -1,3 +1,8 @@ +2010-02-25 Werner Koch + + * sign.c (hash_for): Force SHA1 only for v1 OpenPGP cards. Fixes + bug#1194. + 2010-02-17 Werner Koch * keygen.c (ask_user_id): Avoid infinite loop in case of invalid Modified: branches/STABLE-BRANCH-2-0/configure.ac =================================================================== --- branches/STABLE-BRANCH-2-0/configure.ac 2010-03-08 18:19:21 UTC (rev 5282) +++ branches/STABLE-BRANCH-2-0/configure.ac 2010-03-09 09:55:24 UTC (rev 5283) @@ -74,8 +74,8 @@ use_bzip2=yes use_exec=yes disable_keyserver_path=no +use_ccid_driver=yes - GNUPG_BUILD_PROGRAM(gpg, yes) GNUPG_BUILD_PROGRAM(gpgsm, yes) GNUPG_BUILD_PROGRAM(agent, yes) @@ -298,7 +298,20 @@ [use_capabilities="$withval"],[use_capabilities=no]) AC_MSG_RESULT($use_capabilities) + # +# Allow disabling of internal CCID support. +# It is defined only after we confirm the library is available later +# +AC_MSG_CHECKING([whether to enable the internal CCID driver]) +AC_ARG_ENABLE(ccid-driver, + AC_HELP_STRING([--disable-ccid-driver], + [disable the internal CCID driver]), + use_ccid_driver=$enableval) +AC_MSG_RESULT($use_ccid_driver) + + +# # To avoid double inclusion of config.h which might happen at some # places, we add the usual double inclusion protection at the top of # config.h. @@ -629,14 +642,16 @@ # libusb allows us to use the integrated CCID smartcard reader driver. # # FiXME: Use GNUPG_CHECK_LIBUSB and modify to use separate AC_SUBSTs. -AC_CHECK_LIB(usb, usb_bulk_write, - [ LIBUSB_LIBS="$LIBUSB_LIBS -lusb" - AC_DEFINE(HAVE_LIBUSB,1, - [defined if libusb is available]) - have_libusb=yes - ]) +if test "$use_ccid_driver" = yes ; then + AC_CHECK_LIB(usb, usb_bulk_write, + [ LIBUSB_LIBS="$LIBUSB_LIBS -lusb" + AC_DEFINE(HAVE_LIBUSB,1, + [defined if libusb is available]) + have_libusb=yes + ]) + AC_CHECK_FUNCS(usb_create_match) +fi AC_SUBST(LIBUSB_LIBS) -AC_CHECK_FUNCS(usb_create_match) # # Check wether it is necessary to link against libdl. Modified: branches/STABLE-BRANCH-2-0/g10/sign.c =================================================================== --- branches/STABLE-BRANCH-2-0/g10/sign.c 2010-03-08 18:19:21 UTC (rev 5282) +++ branches/STABLE-BRANCH-2-0/g10/sign.c 2010-03-09 09:55:24 UTC (rev 5283) @@ -415,12 +415,15 @@ return match_dsa_hash(qbytes); } - else if (sk->is_protected && sk->protect.s2k.mode==1002) + else if (sk->is_protected && sk->protect.s2k.mode == 1002 + && sk->protect.ivlen == 16 + && !memcmp (sk->protect.iv, "\xD2\x76\x00\x01\x24\x01\x01", 7)) { - /* The sk lives on a smartcard, and current smartcards only - handle SHA-1 and RIPEMD/160. This is correct now, but may - need revision as the cards add algorithms. */ - + /* The sk lives on a smartcard, and old smartcards only handle + SHA-1 and RIPEMD/160. Newer smartcards (v2.0) don't have + this restriction anymore. Fortunately the serial number + encodes the version of the card and thus we know that this + key is on a v1 card. */ if(opt.personal_digest_prefs) { prefitem_t *prefs; From cvs at cvs.gnupg.org Tue Mar 9 11:09:07 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 11:09:07 +0100 Subject: [svn] GnuPG - r5284 - in branches/STABLE-BRANCH-2-0: . po Message-ID: Author: wk Date: 2010-03-09 11:09:04 +0100 (Tue, 09 Mar 2010) New Revision: 5284 Modified: branches/STABLE-BRANCH-2-0/ChangeLog branches/STABLE-BRANCH-2-0/NEWS branches/STABLE-BRANCH-2-0/configure.ac branches/STABLE-BRANCH-2-0/po/be.po branches/STABLE-BRANCH-2-0/po/ca.po branches/STABLE-BRANCH-2-0/po/cs.po branches/STABLE-BRANCH-2-0/po/da.po branches/STABLE-BRANCH-2-0/po/de.po branches/STABLE-BRANCH-2-0/po/el.po branches/STABLE-BRANCH-2-0/po/eo.po branches/STABLE-BRANCH-2-0/po/es.po branches/STABLE-BRANCH-2-0/po/et.po branches/STABLE-BRANCH-2-0/po/fi.po branches/STABLE-BRANCH-2-0/po/fr.po branches/STABLE-BRANCH-2-0/po/gl.po branches/STABLE-BRANCH-2-0/po/hu.po branches/STABLE-BRANCH-2-0/po/id.po branches/STABLE-BRANCH-2-0/po/it.po branches/STABLE-BRANCH-2-0/po/ja.po branches/STABLE-BRANCH-2-0/po/nb.po branches/STABLE-BRANCH-2-0/po/pl.po branches/STABLE-BRANCH-2-0/po/pt.po branches/STABLE-BRANCH-2-0/po/pt_BR.po branches/STABLE-BRANCH-2-0/po/ro.po branches/STABLE-BRANCH-2-0/po/ru.po branches/STABLE-BRANCH-2-0/po/sk.po branches/STABLE-BRANCH-2-0/po/sv.po branches/STABLE-BRANCH-2-0/po/tr.po branches/STABLE-BRANCH-2-0/po/zh_CN.po branches/STABLE-BRANCH-2-0/po/zh_TW.po Log: Prepare a release Modified: branches/STABLE-BRANCH-2-0/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/ChangeLog 2010-03-09 09:55:24 UTC (rev 5283) +++ branches/STABLE-BRANCH-2-0/ChangeLog 2010-03-09 10:09:04 UTC (rev 5284) @@ -1,5 +1,7 @@ 2010-03-09 Werner Koch + Release 2.0.15. + * configure.ac: Add option --disable-ccid-driver. 2010-02-18 Werner Koch @@ -1147,10 +1149,10 @@ * configure.ac (HAVE_JNLIB_LOGGING): always define it. - - Copyright 2001, 2002, 2003, 2004, 2005, 2006, - 2007 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 modifications, as long as this notice is preserved. @@ -1158,5 +1160,5 @@ 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. - + Modified: branches/STABLE-BRANCH-2-0/NEWS =================================================================== --- branches/STABLE-BRANCH-2-0/NEWS 2010-03-09 09:55:24 UTC (rev 5283) +++ branches/STABLE-BRANCH-2-0/NEWS 2010-03-09 10:09:04 UTC (rev 5284) @@ -1,4 +1,4 @@ -Noteworthy changes in version 2.0.15 (unreleased) +Noteworthy changes in version 2.0.15 (2010-03-09) ------------------------------------------------- * New command --passwd for GPG. @@ -747,8 +747,8 @@ development branch. - Copyright 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009 Free Software Foundation, Inc. + Copyright 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 Modified: branches/STABLE-BRANCH-2-0/configure.ac =================================================================== --- branches/STABLE-BRANCH-2-0/configure.ac 2010-03-09 09:55:24 UTC (rev 5283) +++ branches/STABLE-BRANCH-2-0/configure.ac 2010-03-09 10:09:04 UTC (rev 5284) @@ -24,7 +24,7 @@ # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. -m4_define([my_version], [2.0.15rc1]) +m4_define([my_version], [2.0.15]) m4_define([my_issvn], [no]) m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ Modified: branches/STABLE-BRANCH-2-0/po/be.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/ca.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/cs.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/da.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/de.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/el.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/eo.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/es.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/et.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/fi.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/fr.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/gl.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/hu.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/id.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/it.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/ja.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/nb.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/pl.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/pt.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/pt_BR.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/ro.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/ru.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/sk.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/sv.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/tr.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/zh_CN.po [not shown] Modified: branches/STABLE-BRANCH-2-0/po/zh_TW.po [not shown] From cvs at cvs.gnupg.org Tue Mar 9 12:15:53 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 12:15:53 +0100 Subject: [svn] gpgme - r1455 - trunk/src Message-ID: Author: wk Date: 2010-03-09 12:15:53 +0100 (Tue, 09 Mar 2010) New Revision: 1455 Modified: trunk/src/ChangeLog trunk/src/engine-gpgsm.c Log: Hack to start the agent as a side-effect of a secret key listing Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-02-17 21:40:02 UTC (rev 1454) +++ trunk/src/ChangeLog 2010-03-09 11:15:53 UTC (rev 1455) @@ -1,3 +1,7 @@ +2010-03-09 Werner Koch + + * engine-gpgsm.c (gpgsm_keylist): Try to start the agent. + 2010-02-17 Werner Koch * posix-io.c (notify_table): Change implementation. Modified: trunk/src/engine-gpgsm.c =================================================================== --- trunk/src/engine-gpgsm.c 2010-02-17 21:40:02 UTC (rev 1454) +++ trunk/src/engine-gpgsm.c 2010-03-09 11:15:53 UTC (rev 1455) @@ -1538,6 +1538,18 @@ if (!pattern) pattern = ""; + /* Hack to make sure that the agent is started. Only if the agent + has been started an application may connect to the agent via + GPGME_PROTOCOL_ASSUAN - for example to look for smartcards. We + do this only if a secret key listing has been requested. In + general this is not needed because a secret key listing starts + the agent. However on a fresh installation no public keys are + available and thus there is no need for gpgsm to ask the agent + whether a secret key exists for the public key. */ + if (secret_only) + gpgsm_assuan_simple_command (gpgsm->assuan_ctx, "GETINFO agent-check", + NULL, NULL); + /* Always send list-mode option because RESET does not reset it. */ if (asprintf (&line, "OPTION list-mode=%d", (list_mode & 3)) < 0) return gpg_error_from_errno (errno); From cvs at cvs.gnupg.org Tue Mar 9 12:35:25 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 12:35:25 +0100 Subject: [svn] gpg-error - r236 - in trunk: . src Message-ID: Author: wk Date: 2010-03-09 12:35:25 +0100 (Tue, 09 Mar 2010) New Revision: 236 Modified: trunk/ChangeLog trunk/configure.ac trunk/src/gpg-error.h.in trunk/src/w32-add.h Log: Add macro to enable gettext macros. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-08 20:53:08 UTC (rev 235) +++ trunk/ChangeLog 2010-03-09 11:35:25 UTC (rev 236) @@ -1,3 +1,8 @@ +2010-03-09 Werner Koch + + * src/w32-add.h [!GPG_ERR_ENABLE_GETTEXT_MACROS]: Do not provide + gettext macros. + 2010-03-08 Werner Koch * src/w32-add.h (_GPG_ERR_ATTR_FORMAT_ARG): New. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-08 20:53:08 UTC (rev 235) +++ trunk/configure.ac 2010-03-09 11:35:25 UTC (rev 236) @@ -106,6 +106,8 @@ #if defined(HAVE_W32_SYSTEM) && !defined(ENABLE_NLS) #define ENABLE_NLS 1 #endif +/* For building we need to define this macro. */ +#define GPG_ERR_ENABLE_GETTEXT_MACROS ]) Modified: trunk/src/gpg-error.h.in =================================================================== --- trunk/src/gpg-error.h.in 2010-03-08 20:53:08 UTC (rev 235) +++ trunk/src/gpg-error.h.in 2010-03-09 11:35:25 UTC (rev 236) @@ -53,13 +53,17 @@ another, it preserver the information about the source and nature of the error. - A component of the GnuPG project can define the following macro to + A component of the GnuPG project can define the following macros to tune the behaviour of the library: GPG_ERR_SOURCE_DEFAULT: Define to an error source of type gpg_err_source_t to make that source the default for gpg_error(). - Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default. */ + Otherwise GPG_ERR_SOURCE_UNKNOWN is used as default. + GPG_ERR_ENABLE_GETTEXT_MACROS: Define to provide macros to map the + internal gettext API to standard names. This has only an effect on + Windows platforms. */ + /* The error source type gpg_err_source_t. Modified: trunk/src/w32-add.h =================================================================== --- trunk/src/w32-add.h 2010-03-08 20:53:08 UTC (rev 235) +++ trunk/src/w32-add.h 2010-03-09 11:35:25 UTC (rev 236) @@ -26,11 +26,15 @@ const char *_gpg_w32_gettext_localename (void); int _gpg_w32_gettext_use_utf8 (int value); -#define bindtextdomain(a,b) _gpg_w32_bindtextdomain ((a), (b)) -#define textdomain(a) _gpg_w32_textdomain ((a)) -#define gettext(a) _gpg_w32_gettext ((a)) -#define dgettext(a,b) _gpg_w32_dgettext ((a), (b)) -#define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c)) -#define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d)) -#define gettext_localname() _gpg_w32_gettext_localename () -#define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a) +#ifdef GPG_ERR_ENABLE_GETTEXT_MACROS +# define bindtextdomain(a,b) _gpg_w32_bindtextdomain ((a), (b)) +# define textdomain(a) _gpg_w32_textdomain ((a)) +# define gettext(a) _gpg_w32_gettext ((a)) +# define dgettext(a,b) _gpg_w32_dgettext ((a), (b)) +# define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c)) +# define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d)) +# define gettext_localname() _gpg_w32_gettext_localename () +# define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a) +#endif /*GPG_ERR_ENABLE_GETTEXT_MACROS*/ + + From cvs at cvs.gnupg.org Tue Mar 9 12:55:46 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 12:55:46 +0100 Subject: [svn] GnuPG - r5285 - tags Message-ID: Author: wk Date: 2010-03-09 12:55:45 +0100 (Tue, 09 Mar 2010) New Revision: 5285 Added: tags/gnupg-2.0.15/ Log: tag release From cvs at cvs.gnupg.org Tue Mar 9 13:12:20 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 13:12:20 +0100 Subject: [svn] GnuPG - r5286 - branches/STABLE-BRANCH-2-0 Message-ID: Author: wk Date: 2010-03-09 13:12:20 +0100 (Tue, 09 Mar 2010) New Revision: 5286 Modified: branches/STABLE-BRANCH-2-0/NEWS branches/STABLE-BRANCH-2-0/announce.txt branches/STABLE-BRANCH-2-0/configure.ac Log: Post release updates Modified: branches/STABLE-BRANCH-2-0/NEWS =================================================================== --- branches/STABLE-BRANCH-2-0/NEWS 2010-03-09 11:55:45 UTC (rev 5285) +++ branches/STABLE-BRANCH-2-0/NEWS 2010-03-09 12:12:20 UTC (rev 5286) @@ -1,3 +1,7 @@ +Noteworthy changes in version 2.0.16 (unreleased) +------------------------------------------------- + + Noteworthy changes in version 2.0.15 (2010-03-09) ------------------------------------------------- Modified: branches/STABLE-BRANCH-2-0/announce.txt =================================================================== --- branches/STABLE-BRANCH-2-0/announce.txt 2010-03-09 11:55:45 UTC (rev 5285) +++ branches/STABLE-BRANCH-2-0/announce.txt 2010-03-09 12:12:20 UTC (rev 5286) @@ -5,7 +5,7 @@ Hello! We are pleased to announce the availability of a new stable GnuPG-2 -release: Version 2.0.14. +release: Version 2.0.15. The GNU Privacy Guard (GnuPG) is GNU's tool for secure communication and data storage. It can be used to encrypt data, create digital @@ -31,30 +31,21 @@ What's New =========== - * The default for --include-cert is now to include all certificates - in the chain except for the root certificate. + * New command --passwd for GPG. - * Numerical values may now be used as an alternative to the - debug-level keywords. + * Fixes a regression in 2.0.14 which prevented unprotection of new + or changed gpg-agent passphrases. - * The GPGSM --audit-log feature is now more complete. + * Uses libassuan 2.0 which is available as a DSO. - * GPG now supports DNS lookups for SRV, PKA and CERT on W32. - * New GPGSM option --ignore-cert-extension. - - * New and changed passphrases are now created with an iteration count - requiring about 100ms of CPU work. - - - Getting the Software ==================== Please follow the instructions found at http://www.gnupg.org/download/ or read on: -GnuPG 2.0.14 may be downloaded from one of the GnuPG mirror sites or +GnuPG 2.0.15 may be downloaded from one of the GnuPG mirror sites or direct from ftp://ftp.gnupg.org/gcrypt/gnupg/ . The list of mirrors can be found at http://www.gnupg.org/mirrors.html . Note, that GnuPG is not available at ftp.gnu.org. @@ -62,14 +53,14 @@ On the FTP server and its mirrors you should find the following files in the gnupg/ directory: - gnupg-2.0.14.tar.bz2 (3889k) - gnupg-2.0.14.tar.bz2.sig + gnupg-2.0.15.tar.bz2 (3884k) + gnupg-2.0.15.tar.bz2.sig GnuPG source compressed using BZIP2 and OpenPGP signature. - gnupg-2.0.13-2.0.14.diff.bz2 (42k) + gnupg-2.0.14-2.0.15.diff.bz2 (40k) - A patch file to upgrade a 2.0.13 GnuPG source tree. This patch + A patch file to upgrade a 2.0.14 GnuPG source tree. This patch does not include updates of the language files. Note, that we don't distribute gzip compressed tarballs for GnuPG-2. @@ -84,9 +75,9 @@ * If you already have a trusted version of GnuPG installed, you can simply check the supplied signature. For example to check the - signature of the file gnupg-2.0.14.tar.bz2 you would use this command: + signature of the file gnupg-2.0.15.tar.bz2 you would use this command: - gpg --verify gnupg-2.0.14.tar.bz2.sig + gpg --verify gnupg-2.0.15.tar.bz2.sig This checks whether the signature file matches the source file. You should see a message indicating that the signature is good and @@ -112,13 +103,13 @@ the SHA-1 checksum. Assuming you downloaded the file gnupg-2.0.14.tar.bz2, you would run the sha1sum command like this: - sha1sum gnupg-2.0.14.tar.bz2 + sha1sum gnupg-2.0.15.tar.bz2 and check that the output matches the first line from the following list: -cc5e4637f37f5bc82b00c73fc094ddadb7401821 gnupg-2.0.14.tar.bz2 -cad88a7f3653479df41ddb7956b9f8a0ff6f2185 gnupg-2.0.13-2.0.14.diff.bz2 +3596668fb9cc8ec0714463a5009f990fc23434b0 gnupg-2.0.15.tar.bz2 +ed35765ae081706c8856fd491201f4f9576135fd gnupg-2.0.14-2.0.15.diff.bz2 Internationalization Modified: branches/STABLE-BRANCH-2-0/configure.ac =================================================================== --- branches/STABLE-BRANCH-2-0/configure.ac 2010-03-09 11:55:45 UTC (rev 5285) +++ branches/STABLE-BRANCH-2-0/configure.ac 2010-03-09 12:12:20 UTC (rev 5286) @@ -24,8 +24,8 @@ # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. -m4_define([my_version], [2.0.15]) -m4_define([my_issvn], [no]) +m4_define([my_version], [2.0.16]) +m4_define([my_issvn], [yes]) m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)])) From cvs at cvs.gnupg.org Tue Mar 9 13:50:48 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 13:50:48 +0100 Subject: [svn] GnuPG - r5287 - trunk Message-ID: Author: wk Date: 2010-03-09 13:50:48 +0100 (Tue, 09 Mar 2010) New Revision: 5287 Modified: trunk/ChangeLog trunk/configure.ac Log: Fix for latest libgpg-error. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-09 12:12:20 UTC (rev 5286) +++ trunk/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) @@ -1,3 +1,8 @@ +2010-03-09 Werner Koch + + * configure.ac: Add option --disable-ccid-driver. + (AH_BOTTOM): Define GPG_ERR_ENABLE_GETTEXT_MACROS. + 2010-02-26 Werner Koch * gl/mkdtemp.c (__set_errno) [W32CE]: Use gpg_err_set_errno. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-09 12:12:20 UTC (rev 5286) +++ trunk/configure.ac 2010-03-09 12:50:48 UTC (rev 5287) @@ -74,8 +74,8 @@ use_bzip2=yes use_exec=yes disable_keyserver_path=no +use_ccid_driver=yes - GNUPG_BUILD_PROGRAM(gpg, yes) GNUPG_BUILD_PROGRAM(gpgsm, yes) GNUPG_BUILD_PROGRAM(agent, yes) @@ -299,7 +299,20 @@ [use_capabilities="$withval"],[use_capabilities=no]) AC_MSG_RESULT($use_capabilities) + # +# Allow disabling of internal CCID support. +# It is defined only after we confirm the library is available later +# +AC_MSG_CHECKING([whether to enable the internal CCID driver]) +AC_ARG_ENABLE(ccid-driver, + AC_HELP_STRING([--disable-ccid-driver], + [disable the internal CCID driver]), + use_ccid_driver=$enableval) +AC_MSG_RESULT($use_ccid_driver) + + +# # To avoid double inclusion of config.h which might happen at some # places, we add the usual double inclusion protection at the top of # config.h. @@ -428,6 +441,9 @@ #define _ESTREAM_PRINTF_FREE gcry_free #define _ESTREAM_PRINTF_EXTRA_INCLUDE "util.h" +/* Under Windows we use the gettext code from libgpg-error. */ +#define GPG_ERR_ENABLE_GETTEXT_MACROS + #endif /*GNUPG_CONFIG_H_INCLUDED*/ ]) @@ -636,14 +652,16 @@ # libusb allows us to use the integrated CCID smartcard reader driver. # # FiXME: Use GNUPG_CHECK_LIBUSB and modify to use separate AC_SUBSTs. -AC_CHECK_LIB(usb, usb_bulk_write, - [ LIBUSB_LIBS="$LIBUSB_LIBS -lusb" - AC_DEFINE(HAVE_LIBUSB,1, - [defined if libusb is available]) - have_libusb=yes - ]) +if test "$use_ccid_driver" = yes ; then + AC_CHECK_LIB(usb, usb_bulk_write, + [ LIBUSB_LIBS="$LIBUSB_LIBS -lusb" + AC_DEFINE(HAVE_LIBUSB,1, + [defined if libusb is available]) + have_libusb=yes + ]) + AC_CHECK_FUNCS(usb_create_match) +fi AC_SUBST(LIBUSB_LIBS) -AC_CHECK_FUNCS(usb_create_match) # # Check wether it is necessary to link against libdl. From cvs at cvs.gnupg.org Tue Mar 9 14:42:03 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 14:42:03 +0100 Subject: [svn] dirmngr - r336 - in trunk: . doc jnlib po src Message-ID: Author: wk Date: 2010-03-09 14:42:02 +0100 (Tue, 09 Mar 2010) New Revision: 336 Modified: trunk/AUTHORS trunk/NEWS trunk/README trunk/configure.ac trunk/doc/dirmngr.texi trunk/jnlib/argparse.c trunk/po/de.po trunk/po/dirmngr.pot trunk/src/ChangeLog trunk/src/dirmngr-client.c trunk/src/dirmngr.c trunk/src/server.c Log: Preparing a release candidate. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/src/ChangeLog 2010-03-09 13:42:02 UTC (rev 336) @@ -1,3 +1,7 @@ +2010-03-09 Werner Koch + + * dirmngr.c (set_debug): Allow numerical values. + 2009-12-15 Werner Koch * dirmngr.c: Add option --ignore-cert-extension. Modified: trunk/AUTHORS =================================================================== --- trunk/AUTHORS 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/AUTHORS 2010-03-09 13:42:02 UTC (rev 336) @@ -25,7 +25,7 @@ src/cdblib.h which are in the public domain. - Copyright 2003, 2004, 2006, 2007, 2008 g10 Code GmbH + Copyright 2003, 2004, 2006, 2007, 2008, 2010 g10 Code GmbH This file is free software; as a special exception the author gives unlimited permission to copy and/or distribute it, with or without Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/NEWS 2010-03-09 13:42:02 UTC (rev 336) @@ -1,4 +1,4 @@ -Noteworthy changes in version 1.1.0 +Noteworthy changes in version 1.1.0 (unreleased) ------------------------------------------------ * Fixed a resource problem with LDAP CRLs. Modified: trunk/README =================================================================== --- trunk/README 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/README 2010-03-09 13:42:02 UTC (rev 336) @@ -1,7 +1,7 @@ DirMngr - X.509 Directory Manager ------------------------------------- - Version 1.0.3 + Version 1.1.0 Intro @@ -9,10 +9,10 @@ DirMngr is a server for managing and downloading certificate revocation lists (CRLs) for X.509 certificates and for downloading - the certificates themselves. Dirmngr also handles OCSP requests as - an alternative to CRLs. Dirmngr is either invoked internaly by - gpgsm (from gnupg 1.9) or when running as a system daemon through - the dirmngr-client tool. + the certificates themselves. Dirmngr also handles OCSP requests + as an alternative to CRLs. Dirmngr is either invoked internally + by gpgsm (GnuPG-2) or when running as a system daemon through the + dirmngr-client tool. See the file COPYING for copyright and warranty information. See the file AUTHORS for contact addresses and code history. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/configure.ac 2010-03-09 13:42:02 UTC (rev 336) @@ -27,8 +27,8 @@ # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. -m4_define([my_version], [1.1.0]) -m4_define([my_issvn], [yes]) +m4_define([my_version], [1.1.0rc1]) +m4_define([my_issvn], [no]) m4_define([svn_revision], m4_esyscmd([printf "%d" $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) @@ -47,7 +47,7 @@ NEED_KSBA_API=1 NEED_KSBA_VERSION=1.0.2 -COPYRIGHT_YEAR_NAME="2009 g10 Code GmbH" +COPYRIGHT_YEAR_NAME="2010 g10 Code GmbH" PACKAGE=$PACKAGE_NAME VERSION=$PACKAGE_VERSION Modified: trunk/doc/dirmngr.texi =================================================================== --- trunk/doc/dirmngr.texi 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/doc/dirmngr.texi 2010-03-09 13:42:02 UTC (rev 336) @@ -347,20 +347,26 @@ @item --debug-level @var{level} @opindex debug-level -Select the debug level for investigating problems. @var{level} may be -one of: +Select the debug level for investigating problems. @var{level} may be a +numeric value or by a keyword: @table @code @item none -no debugging at all. +No debugging at all. A value of less than 1 may be used instead of +the keyword. @item basic -some basic debug messages +Some basic debug messages. A value between 1 and 2 may be used +instead of the keyword. @item advanced -more verbose debug messages +More verbose debug messages. A value between 3 and 5 may be used +instead of the keyword. @item expert -even more detailed messages +Even more detailed messages. A value between 6 and 8 may be used +instead of the keyword. @item guru -all of the debug messages you can get +All of the debug messages you can get. A value greater than 8 may be +used instead of the keyword. The creation of hash tracing files is +only enabled if the keyword is used. @end table How these messages are mapped to the actual debugging flags is not Modified: trunk/jnlib/argparse.c =================================================================== --- trunk/jnlib/argparse.c 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/jnlib/argparse.c 2010-03-09 13:42:02 UTC (rev 336) @@ -936,7 +936,7 @@ switch( level ) { case 11: p = "foo"; break; case 13: p = "0.0"; break; - case 14: p = "Copyright (C) 2008 Free Software Foundation, Inc."; break; + case 14: p = "Copyright (C) 2010 Free Software Foundation, Inc."; break; case 15: p = "This program comes with ABSOLUTELY NO WARRANTY.\n" "This is free software, and you are welcome to redistribute it\n" Modified: trunk/po/de.po [not shown] Modified: trunk/po/dirmngr.pot =================================================================== --- trunk/po/dirmngr.pot 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/po/dirmngr.pot 2010-03-09 13:42:02 UTC (rev 336) @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: gpa-dev at gnupg.org\n" -"POT-Creation-Date: 2009-07-31 14:26+0200\n" +"POT-Creation-Date: 2010-03-09 13:10+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -51,7 +51,7 @@ msgid "can't access directory `%s': %s\n" msgstr "" -#: src/certcache.c:390 src/crlcache.c:2367 src/dirmngr.c:1458 +#: src/certcache.c:390 src/crlcache.c:2367 src/dirmngr.c:1479 #, c-format msgid "can't open `%s': %s\n" msgstr "" @@ -109,7 +109,7 @@ msgid " runtime cached certificates: %u\n" msgstr "" -#: src/certcache.c:531 src/dirmngr-client.c:385 +#: src/certcache.c:531 src/dirmngr-client.c:384 msgid "certificate already cached\n" msgstr "" @@ -117,7 +117,7 @@ msgid "certificate cached\n" msgstr "" -#: src/certcache.c:535 src/certcache.c:555 src/dirmngr-client.c:389 +#: src/certcache.c:535 src/certcache.c:555 src/dirmngr-client.c:388 #, c-format msgid "error caching certificate: %s\n" msgstr "" @@ -137,7 +137,7 @@ msgid "error fetching certificate by subject: %s\n" msgstr "" -#: src/certcache.c:1338 src/validate.c:445 +#: src/certcache.c:1338 src/validate.c:461 msgid "no issuer found in certificate\n" msgstr "" @@ -245,7 +245,7 @@ msgstr "" #: src/crlcache.c:649 src/crlcache.c:654 src/crlcache.c:908 src/crlcache.c:914 -#: src/dirmngr.c:1404 +#: src/dirmngr.c:1425 #, c-format msgid "error reading `%s': %s\n" msgstr "" @@ -406,7 +406,7 @@ msgid "error getting data from cache file: %s\n" msgstr "" -#: src/crlcache.c:1534 src/validate.c:868 +#: src/crlcache.c:1534 src/validate.c:884 #, c-format msgid "unknown hash algorithm `%s'\n" msgstr "" @@ -606,7 +606,7 @@ msgid "End CRL dump\n" msgstr "" -#: src/crlcache.c:2376 src/crlfetch.c:213 src/ldap.c:685 +#: src/crlcache.c:2376 src/crlfetch.c:219 src/ldap.c:687 #, c-format msgid "error initializing reader object: %s\n" msgstr "" @@ -630,189 +630,189 @@ msgid "reader to file mapping table full - waiting\n" msgstr "" -#: src/crlfetch.c:172 +#: src/crlfetch.c:178 msgid "using \"http\" instead of \"https\"\n" msgstr "" -#: src/crlfetch.c:183 src/crlfetch.c:278 src/crlfetch.c:298 src/crlfetch.c:316 +#: src/crlfetch.c:189 src/crlfetch.c:284 src/crlfetch.c:304 src/crlfetch.c:322 #, c-format msgid "CRL access not possible due to disabled %s\n" msgstr "" -#: src/crlfetch.c:238 src/ocsp.c:212 +#: src/crlfetch.c:244 src/ocsp.c:212 #, c-format msgid "URL `%s' redirected to `%s' (%u)\n" msgstr "" -#: src/crlfetch.c:257 src/ocsp.c:229 +#: src/crlfetch.c:263 src/ocsp.c:229 msgid "too many redirections\n" msgstr "" -#: src/crlfetch.c:263 +#: src/crlfetch.c:269 #, c-format msgid "error retrieving `%s': %s\n" msgstr "" -#: src/crlfetch.c:268 +#: src/crlfetch.c:274 #, c-format msgid "error retrieving `%s': http status %u\n" msgstr "" -#: src/crlfetch.c:330 +#: src/crlfetch.c:336 #, c-format msgid "certificate search not possible due to disabled %s\n" msgstr "" -#: src/dirmngr.c:123 +#: src/dirmngr.c:124 msgid "" "@Commands:\n" " " msgstr "" -#: src/dirmngr.c:125 +#: src/dirmngr.c:126 msgid "run in server mode (foreground)" msgstr "" -#: src/dirmngr.c:126 +#: src/dirmngr.c:127 msgid "run in daemon mode (background)" msgstr "" -#: src/dirmngr.c:128 +#: src/dirmngr.c:129 msgid "run as windows service (background)" msgstr "" -#: src/dirmngr.c:130 +#: src/dirmngr.c:131 msgid "list the contents of the CRL cache" msgstr "" -#: src/dirmngr.c:131 +#: src/dirmngr.c:132 msgid "|FILE|load CRL from FILE into cache" msgstr "" -#: src/dirmngr.c:132 +#: src/dirmngr.c:133 msgid "|URL|fetch a CRL from URL" msgstr "" -#: src/dirmngr.c:133 +#: src/dirmngr.c:134 msgid "shutdown the dirmngr" msgstr "" -#: src/dirmngr.c:134 +#: src/dirmngr.c:135 msgid "flush the cache" msgstr "" -#: src/dirmngr.c:138 +#: src/dirmngr.c:139 msgid "" "@\n" "Options:\n" " " msgstr "" -#: src/dirmngr.c:140 src/dirmngr-client.c:69 src/dirmngr_ldap.c:85 +#: src/dirmngr.c:141 src/dirmngr-client.c:69 src/dirmngr_ldap.c:85 msgid "verbose" msgstr "" -#: src/dirmngr.c:141 src/dirmngr-client.c:70 src/dirmngr_ldap.c:86 +#: src/dirmngr.c:142 src/dirmngr-client.c:70 src/dirmngr_ldap.c:86 msgid "be somewhat more quiet" msgstr "" -#: src/dirmngr.c:142 +#: src/dirmngr.c:143 msgid "sh-style command output" msgstr "" -#: src/dirmngr.c:143 +#: src/dirmngr.c:144 msgid "csh-style command output" msgstr "" -#: src/dirmngr.c:144 +#: src/dirmngr.c:145 msgid "|FILE|read options from FILE" msgstr "" -#: src/dirmngr.c:146 +#: src/dirmngr.c:147 msgid "|LEVEL|set the debugging level to LEVEL" msgstr "" -#: src/dirmngr.c:147 +#: src/dirmngr.c:148 msgid "do not detach from the console" msgstr "" -#: src/dirmngr.c:148 +#: src/dirmngr.c:149 msgid "|FILE|write server mode logs to FILE" msgstr "" -#: src/dirmngr.c:149 +#: src/dirmngr.c:150 msgid "run without asking a user" msgstr "" -#: src/dirmngr.c:150 +#: src/dirmngr.c:151 msgid "force loading of outdated CRLs" msgstr "" -#: src/dirmngr.c:151 +#: src/dirmngr.c:152 msgid "allow sending OCSP requests" msgstr "" -#: src/dirmngr.c:152 +#: src/dirmngr.c:153 msgid "inhibit the use of HTTP" msgstr "" -#: src/dirmngr.c:153 +#: src/dirmngr.c:154 msgid "inhibit the use of LDAP" msgstr "" -#: src/dirmngr.c:155 +#: src/dirmngr.c:156 msgid "ignore HTTP CRL distribution points" msgstr "" -#: src/dirmngr.c:157 +#: src/dirmngr.c:158 msgid "ignore LDAP CRL distribution points" msgstr "" -#: src/dirmngr.c:159 +#: src/dirmngr.c:160 msgid "ignore certificate contained OCSP service URLs" msgstr "" -#: src/dirmngr.c:165 +#: src/dirmngr.c:166 msgid "|URL|redirect all HTTP requests to URL" msgstr "" -#: src/dirmngr.c:167 +#: src/dirmngr.c:168 msgid "|HOST|use HOST for LDAP queries" msgstr "" -#: src/dirmngr.c:169 +#: src/dirmngr.c:170 msgid "do not use fallback hosts with --ldap-proxy" msgstr "" -#: src/dirmngr.c:172 +#: src/dirmngr.c:173 msgid "|FILE|read LDAP server list from FILE" msgstr "" -#: src/dirmngr.c:174 +#: src/dirmngr.c:175 msgid "add new servers discovered in CRL distribution points to serverlist" msgstr "" -#: src/dirmngr.c:176 src/dirmngr_ldap.c:87 +#: src/dirmngr.c:177 src/dirmngr_ldap.c:87 msgid "|N|set LDAP timeout to N seconds" msgstr "" -#: src/dirmngr.c:178 +#: src/dirmngr.c:179 msgid "|URL|use OCSP responder at URL" msgstr "" -#: src/dirmngr.c:179 +#: src/dirmngr.c:180 msgid "|FPR|OCSP response signed by FPR" msgstr "" -#: src/dirmngr.c:185 +#: src/dirmngr.c:186 msgid "|N|do not return more than N items in one query" msgstr "" -#: src/dirmngr.c:187 +#: src/dirmngr.c:188 msgid "|FILE|listen on socket FILE" msgstr "" -#: src/dirmngr.c:200 +#: src/dirmngr.c:201 msgid "" "@\n" "(See the \"info\" manual for a complete listing of all commands and " @@ -822,285 +822,285 @@ #. TRANSLATORS: @EMAIL@ will get replaced by the actual bug #. reporting address. This is so that we can change the #. reporting address without breaking the translations. -#: src/dirmngr.c:273 src/dirmngr-client.c:149 src/dirmngr_ldap.c:148 +#: src/dirmngr.c:275 src/dirmngr-client.c:149 src/dirmngr_ldap.c:148 msgid "Please report bugs to <@EMAIL@>.\n" msgstr "" -#: src/dirmngr.c:276 +#: src/dirmngr.c:278 msgid "Usage: dirmngr [options] (-h for help)" msgstr "" -#: src/dirmngr.c:278 +#: src/dirmngr.c:280 msgid "" "Syntax: dirmngr [options] [command [args]]\n" "LDAP and OCSP access for GnuPG\n" msgstr "" -#: src/dirmngr.c:353 +#: src/dirmngr.c:366 #, c-format msgid "invalid debug-level `%s' given\n" msgstr "" -#: src/dirmngr.c:354 +#: src/dirmngr.c:367 #, c-format msgid "valid debug levels are: %s\n" msgstr "" -#: src/dirmngr.c:392 +#: src/dirmngr.c:405 msgid "usage: dirmngr [options] " msgstr "" -#: src/dirmngr.c:417 +#: src/dirmngr.c:430 #, c-format msgid "error spawning ldap wrapper reaper thread: %s\n" msgstr "" -#: src/dirmngr.c:638 src/dirmngr.c:648 +#: src/dirmngr.c:657 src/dirmngr.c:667 #, c-format msgid "%s is too old (need %s, have %s)\n" msgstr "" -#: src/dirmngr.c:760 +#: src/dirmngr.c:783 #, c-format msgid "NOTE: no default option file `%s'\n" msgstr "" -#: src/dirmngr.c:765 src/dirmngr.c:1564 +#: src/dirmngr.c:788 src/dirmngr.c:1585 #, c-format msgid "option file `%s': %s\n" msgstr "" -#: src/dirmngr.c:773 +#: src/dirmngr.c:796 #, c-format msgid "reading options from `%s'\n" msgstr "" -#: src/dirmngr.c:875 +#: src/dirmngr.c:898 #, c-format msgid "WARNING: running with faked system time %s\n" msgstr "" -#: src/dirmngr.c:958 +#: src/dirmngr.c:979 msgid "colons are not allowed in the socket name\n" msgstr "" -#: src/dirmngr.c:964 +#: src/dirmngr.c:985 msgid "name of socket too long\n" msgstr "" -#: src/dirmngr.c:971 +#: src/dirmngr.c:992 #, c-format msgid "can't create socket: %s\n" msgstr "" -#: src/dirmngr.c:990 +#: src/dirmngr.c:1011 msgid "error getting nonce for the socket\n" msgstr "" -#: src/dirmngr.c:993 +#: src/dirmngr.c:1014 #, c-format msgid "error binding socket to `%s': %s\n" msgstr "" -#: src/dirmngr.c:1002 +#: src/dirmngr.c:1023 #, c-format msgid "listen() failed: %s\n" msgstr "" -#: src/dirmngr.c:1008 +#: src/dirmngr.c:1029 #, c-format msgid "listening on socket `%s'\n" msgstr "" -#: src/dirmngr.c:1019 +#: src/dirmngr.c:1040 #, c-format msgid "fork failed: %s\n" msgstr "" -#: src/dirmngr.c:1037 +#: src/dirmngr.c:1058 msgid "out of core\n" msgstr "" -#: src/dirmngr.c:1076 +#: src/dirmngr.c:1097 #, c-format msgid "setsid() failed: %s\n" msgstr "" -#: src/dirmngr.c:1086 +#: src/dirmngr.c:1107 #, c-format msgid "chdir to / failed: %s\n" msgstr "" -#: src/dirmngr.c:1156 src/server.c:1102 +#: src/dirmngr.c:1177 src/server.c:1103 #, c-format msgid "fetching CRL from `%s' failed: %s\n" msgstr "" -#: src/dirmngr.c:1162 src/server.c:1108 +#: src/dirmngr.c:1183 src/server.c:1109 #, c-format msgid "processing CRL from `%s' failed: %s\n" msgstr "" -#: src/dirmngr.c:1366 +#: src/dirmngr.c:1387 #, c-format msgid "error opening `%s': %s\n" msgstr "" -#: src/dirmngr.c:1381 +#: src/dirmngr.c:1402 #, c-format msgid "%s:%u: line too long - skipped\n" msgstr "" -#: src/dirmngr.c:1436 src/dirmngr.c:1520 +#: src/dirmngr.c:1457 src/dirmngr.c:1541 #, c-format msgid "%s:%u: invalid fingerprint detected\n" msgstr "" -#: src/dirmngr.c:1472 src/dirmngr.c:1498 +#: src/dirmngr.c:1493 src/dirmngr.c:1519 #, c-format msgid "%s:%u: read error: %s\n" msgstr "" -#: src/dirmngr.c:1527 +#: src/dirmngr.c:1548 #, c-format msgid "%s:%u: garbage at end of line ignored\n" msgstr "" -#: src/dirmngr.c:1597 +#: src/dirmngr.c:1618 msgid "SIGHUP received - re-reading configuration and flushing caches\n" msgstr "" -#: src/dirmngr.c:1611 +#: src/dirmngr.c:1632 msgid "SIGUSR2 received - no action defined\n" msgstr "" -#: src/dirmngr.c:1616 src/dirmngr.c:1653 +#: src/dirmngr.c:1637 src/dirmngr.c:1674 msgid "SIGTERM received - shutting down ...\n" msgstr "" -#: src/dirmngr.c:1618 +#: src/dirmngr.c:1639 #, c-format msgid "SIGTERM received - still %d active connections\n" msgstr "" -#: src/dirmngr.c:1623 src/dirmngr.c:1656 +#: src/dirmngr.c:1644 src/dirmngr.c:1677 msgid "shutdown forced\n" msgstr "" -#: src/dirmngr.c:1631 +#: src/dirmngr.c:1652 msgid "SIGINT received - immediate shutdown\n" msgstr "" -#: src/dirmngr.c:1638 +#: src/dirmngr.c:1659 #, c-format msgid "signal %d received - no action defined\n" msgstr "" -#: src/dirmngr.c:1672 +#: src/dirmngr.c:1693 #, c-format msgid "error reading nonce on fd %d: %s\n" msgstr "" -#: src/dirmngr.c:1697 +#: src/dirmngr.c:1718 #, c-format msgid "handler for fd %d started\n" msgstr "" -#: src/dirmngr.c:1702 +#: src/dirmngr.c:1723 #, c-format msgid "handler for fd %d terminated\n" msgstr "" -#: src/dirmngr.c:1785 +#: src/dirmngr.c:1806 #, c-format msgid "accept failed: %s - waiting 1s\n" msgstr "" -#: src/dirmngr.c:1811 +#: src/dirmngr.c:1832 #, c-format msgid "error spawning connection handler: %s\n" msgstr "" -#: src/http.c:1471 +#: src/http.c:1505 #, c-format msgid "error creating socket: %s\n" msgstr "" -#: src/http.c:1515 +#: src/http.c:1549 msgid "host not found" msgstr "" -#: src/ldap.c:146 +#: src/ldap.c:149 #, c-format msgid "invalid char 0x%02x in host name - not added\n" msgstr "" -#: src/ldap.c:150 +#: src/ldap.c:153 #, c-format msgid "adding `%s:%d' to the ldap server list\n" msgstr "" -#: src/ldap.c:153 src/misc.c:745 +#: src/ldap.c:156 src/misc.c:745 #, c-format msgid "malloc failed: %s\n" msgstr "" -#: src/ldap.c:233 +#: src/ldap.c:234 #, c-format msgid "error printing log line: %s\n" msgstr "" -#: src/ldap.c:270 +#: src/ldap.c:263 #, c-format -msgid "pth_event failed: %s\n" +msgid "error reading log from ldap wrapper %d: %s\n" msgstr "" -#: src/ldap.c:290 +#: src/ldap.c:301 #, c-format -msgid "pth_wait failed: %s\n" +msgid "pth_event failed: %s\n" msgstr "" -#: src/ldap.c:320 +#: src/ldap.c:321 #, c-format -msgid "error reading log from ldap wrapper %d: %s\n" +msgid "pth_wait failed: %s\n" msgstr "" -#: src/ldap.c:352 +#: src/ldap.c:358 #, c-format msgid "ldap wrapper %d ready: timeout\n" msgstr "" -#: src/ldap.c:353 +#: src/ldap.c:359 #, c-format msgid "ldap wrapper %d ready" msgstr "" -#: src/ldap.c:361 +#: src/ldap.c:367 #, c-format msgid "waiting for ldap wrapper %d failed: %s\n" msgstr "" -#: src/ldap.c:373 +#: src/ldap.c:379 #, c-format msgid "ldap wrapper %d stalled - killing\n" msgstr "" -#: src/ldap.c:462 src/ldap.c:483 +#: src/ldap.c:466 src/ldap.c:487 #, c-format msgid "reading from ldap wrapper %d failed: %s\n" msgstr "" -#: src/ldap.c:652 +#: src/ldap.c:654 #, c-format msgid "error allocating memory: %s\n" msgstr "" -#: src/ldap.c:1218 +#: src/ldap.c:1220 #, c-format msgid "start_cert_fetch: invalid pattern `%s'\n" msgstr "" -#: src/ldap.c:1424 +#: src/ldap.c:1426 msgid "ldap_search hit the size limit of the server\n" msgstr "" @@ -1202,7 +1202,7 @@ msgid "no suitable certificate found to verify the OCSP response\n" msgstr "" -#: src/ocsp.c:551 src/validate.c:609 +#: src/ocsp.c:551 src/validate.c:625 #, c-format msgid "issuer certificate not found: %s\n" msgstr "" @@ -1296,46 +1296,46 @@ msgid "assuan_inquire(%s) failed: %s\n" msgstr "" -#: src/server.c:451 +#: src/server.c:455 msgid "ldapserver missing" msgstr "" -#: src/server.c:522 +#: src/server.c:525 msgid "serialno missing in cert ID" msgstr "" -#: src/server.c:575 src/server.c:689 src/server.c:774 src/server.c:1069 -#: src/server.c:1129 src/server.c:1155 src/server.c:1208 src/server.c:1277 +#: src/server.c:578 src/server.c:692 src/server.c:777 src/server.c:1070 +#: src/server.c:1130 src/server.c:1155 src/server.c:1208 src/server.c:1277 #, c-format msgid "command %s failed: %s\n" msgstr "" -#: src/server.c:660 src/server.c:748 src/server.c:1188 src/server.c:1241 +#: src/server.c:663 src/server.c:751 src/server.c:1188 src/server.c:1241 #, c-format msgid "assuan_inquire failed: %s\n" msgstr "" -#: src/server.c:793 +#: src/server.c:796 #, c-format msgid "fetch_cert_by_url failed: %s\n" msgstr "" -#: src/server.c:805 src/server.c:836 src/server.c:992 +#: src/server.c:808 src/server.c:839 src/server.c:995 #, c-format msgid "error sending data: %s\n" msgstr "" -#: src/server.c:940 +#: src/server.c:943 #, c-format msgid "start_cert_fetch failed: %s\n" msgstr "" -#: src/server.c:973 +#: src/server.c:976 #, c-format msgid "fetch_next_cert failed: %s\n" msgstr "" -#: src/server.c:1000 +#: src/server.c:1003 #, c-format msgid "max_replies %d exceeded\n" msgstr "" @@ -1344,166 +1344,166 @@ msgid "no data stream" msgstr "" -#: src/server.c:1343 +#: src/server.c:1346 #, c-format msgid "can't allocate control structure: %s\n" msgstr "" -#: src/server.c:1366 +#: src/server.c:1378 #, c-format msgid "failed to initialize the server: %s\n" msgstr "" -#: src/server.c:1374 +#: src/server.c:1386 #, c-format msgid "failed to the register commands with Assuan: %s\n" msgstr "" -#: src/server.c:1417 +#: src/server.c:1429 #, c-format msgid "Assuan accept problem: %s\n" msgstr "" -#: src/server.c:1437 +#: src/server.c:1448 #, c-format msgid "Assuan processing failed: %s\n" msgstr "" -#: src/validate.c:93 +#: src/validate.c:109 #, c-format msgid "critical certificate extension %s is not supported" msgstr "" -#: src/validate.c:153 +#: src/validate.c:169 msgid "note: non-critical certificate policy not allowed" msgstr "" -#: src/validate.c:158 +#: src/validate.c:174 msgid "certificate policy not allowed" msgstr "" -#: src/validate.c:187 +#: src/validate.c:203 msgid "accepting root CA not marked as a CA" msgstr "" -#: src/validate.c:191 +#: src/validate.c:207 msgid "issuer certificate is not marked as a CA" msgstr "" -#: src/validate.c:213 +#: src/validate.c:229 msgid "CRL checking too deeply nested\n" msgstr "" -#: src/validate.c:231 +#: src/validate.c:247 msgid "not checking CRL for" msgstr "" -#: src/validate.c:236 +#: src/validate.c:252 msgid "checking CRL for" msgstr "" -#: src/validate.c:374 +#: src/validate.c:390 msgid "running in compatibility mode - certificate chain not checked!\n" msgstr "" -#: src/validate.c:459 +#: src/validate.c:475 #, c-format msgid "certificate with invalid validity: %s" msgstr "" -#: src/validate.c:477 +#: src/validate.c:493 msgid "certificate not yet valid" msgstr "" -#: src/validate.c:488 +#: src/validate.c:504 msgid "certificate has expired" msgstr "" -#: src/validate.c:518 +#: src/validate.c:534 msgid "selfsigned certificate has a BAD signature" msgstr "" -#: src/validate.c:536 +#: src/validate.c:552 msgid "root certificate is not marked trusted" msgstr "" -#: src/validate.c:538 +#: src/validate.c:554 #, c-format msgid "fingerprint=%s\n" msgstr "" -#: src/validate.c:551 +#: src/validate.c:567 #, c-format msgid "checking trustworthiness of root certificate failed: %s\n" msgstr "" -#: src/validate.c:591 +#: src/validate.c:607 msgid "certificate chain too long\n" msgstr "" -#: src/validate.c:603 +#: src/validate.c:619 msgid "issuer certificate not found" msgstr "" -#: src/validate.c:629 +#: src/validate.c:645 msgid "certificate has a BAD signature" msgstr "" -#: src/validate.c:653 +#: src/validate.c:669 msgid "found another possible matching CA certificate - trying again" msgstr "" -#: src/validate.c:678 +#: src/validate.c:694 #, c-format msgid "certificate chain longer than allowed by CA (%d)" msgstr "" -#: src/validate.c:708 +#: src/validate.c:724 msgid "certificate is good\n" msgstr "" -#: src/validate.c:728 +#: src/validate.c:744 msgid "certificate chain is good\n" msgstr "" -#: src/validate.c:958 +#: src/validate.c:974 msgid "DSA requires the use of a 160 bit hash algorithm\n" msgstr "" -#: src/validate.c:1065 +#: src/validate.c:1081 msgid "no key usage specified - assuming all usages\n" msgstr "" -#: src/validate.c:1075 +#: src/validate.c:1091 #, c-format msgid "error getting key usage information: %s\n" msgstr "" -#: src/validate.c:1085 +#: src/validate.c:1101 msgid "certificate should have not been used for certification\n" msgstr "" -#: src/validate.c:1097 +#: src/validate.c:1113 msgid "certificate should have not been used for OCSP response signing\n" msgstr "" -#: src/validate.c:1106 +#: src/validate.c:1122 msgid "certificate should have not been used for CRL signing\n" msgstr "" -#: src/validate.c:1117 +#: src/validate.c:1133 msgid "certificate should have not been used for encryption\n" msgstr "" -#: src/validate.c:1119 +#: src/validate.c:1135 msgid "certificate should have not been used for signing\n" msgstr "" -#: src/validate.c:1120 +#: src/validate.c:1136 msgid "certificate is not usable for encryption\n" msgstr "" -#: src/validate.c:1121 +#: src/validate.c:1137 msgid "certificate is not usable for signing\n" msgstr "" @@ -1563,98 +1563,103 @@ "not valid and other error codes for general failures\n" msgstr "" -#: src/dirmngr-client.c:285 src/dirmngr-client.c:1004 +#: src/dirmngr-client.c:284 src/dirmngr-client.c:1013 #, c-format msgid "error reading certificate from stdin: %s\n" msgstr "" -#: src/dirmngr-client.c:292 +#: src/dirmngr-client.c:291 #, c-format msgid "error reading certificate from `%s': %s\n" msgstr "" -#: src/dirmngr-client.c:306 +#: src/dirmngr-client.c:305 msgid "certificate too large to make any sense\n" msgstr "" -#: src/dirmngr-client.c:332 +#: src/dirmngr-client.c:331 #, c-format msgid "lookup failed: %s\n" msgstr "" -#: src/dirmngr-client.c:347 +#: src/dirmngr-client.c:346 #, c-format msgid "loading CRL `%s' failed: %s\n" msgstr "" -#: src/dirmngr-client.c:375 +#: src/dirmngr-client.c:374 msgid "a dirmngr daemon is up and running\n" msgstr "" -#: src/dirmngr-client.c:397 +#: src/dirmngr-client.c:396 #, c-format msgid "validation of certificate failed: %s\n" msgstr "" -#: src/dirmngr-client.c:404 src/dirmngr-client.c:1015 +#: src/dirmngr-client.c:403 src/dirmngr-client.c:1024 msgid "certificate is valid\n" msgstr "" -#: src/dirmngr-client.c:410 src/dirmngr-client.c:1023 +#: src/dirmngr-client.c:409 src/dirmngr-client.c:1032 msgid "certificate has been revoked\n" msgstr "" -#: src/dirmngr-client.c:415 src/dirmngr-client.c:1025 +#: src/dirmngr-client.c:414 src/dirmngr-client.c:1034 #, c-format msgid "certificate check failed: %s\n" msgstr "" -#: src/dirmngr-client.c:428 +#: src/dirmngr-client.c:427 #, c-format msgid "got status: `%s'\n" msgstr "" -#: src/dirmngr-client.c:443 +#: src/dirmngr-client.c:442 #, c-format msgid "error writing base64 encoding: %s\n" msgstr "" -#: src/dirmngr-client.c:475 +#: src/dirmngr-client.c:469 +#, c-format +msgid "failed to allocate assuan context: %s\n" +msgstr "" + +#: src/dirmngr-client.c:483 msgid "apparently no running dirmngr\n" msgstr "" -#: src/dirmngr-client.c:480 +#: src/dirmngr-client.c:488 msgid "no running dirmngr - starting one\n" msgstr "" -#: src/dirmngr-client.c:513 +#: src/dirmngr-client.c:521 msgid "malformed DIRMNGR_INFO environment variable\n" msgstr "" -#: src/dirmngr-client.c:528 +#: src/dirmngr-client.c:536 #, c-format msgid "dirmngr protocol version %d is not supported\n" msgstr "" -#: src/dirmngr-client.c:544 +#: src/dirmngr-client.c:552 msgid "can't connect to the dirmngr - trying fall back\n" msgstr "" -#: src/dirmngr-client.c:552 +#: src/dirmngr-client.c:561 #, c-format msgid "can't connect to the dirmngr: %s\n" msgstr "" -#: src/dirmngr-client.c:801 +#: src/dirmngr-client.c:810 #, c-format msgid "unsupported inquiry `%s'\n" msgstr "" -#: src/dirmngr-client.c:903 +#: src/dirmngr-client.c:912 msgid "absolute file name expected\n" msgstr "" -#: src/dirmngr-client.c:948 +#: src/dirmngr-client.c:957 #, c-format msgid "looking up `%s'\n" msgstr "" Modified: trunk/src/dirmngr-client.c =================================================================== --- trunk/src/dirmngr-client.c 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/src/dirmngr-client.c 2010-03-09 13:42:02 UTC (rev 336) @@ -466,7 +466,8 @@ rc = assuan_new (&ctx); if (rc) { - log_error (_("can't create assuan context: %s\n"), gpg_strerror (rc)); + log_error (_("failed to allocate assuan context: %s\n"), + gpg_strerror (rc)); return NULL; } Modified: trunk/src/dirmngr.c =================================================================== --- trunk/src/dirmngr.c 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/src/dirmngr.c 2010-03-09 13:42:02 UTC (rev 336) @@ -1,6 +1,6 @@ /* dirmngr.c - LDAP access * Copyright (C) 2002 Klar?lvdalens Datakonsult AB - * Copyright (C) 2003, 2004, 2006, 2007, 2008 g10 Code GmbH + * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2010 g10 Code GmbH * * This file is part of DirMngr. * @@ -337,19 +337,30 @@ static void set_debug (void) { + int numok = (debug_level && digitp (debug_level)); + int numlvl = numok? atoi (debug_level) : 0; + if (!debug_level) ; - else if (!strcmp (debug_level, "none")) + else if (!strcmp (debug_level, "none") || (numok && numlvl < 1)) opt.debug = 0; - else if (!strcmp (debug_level, "basic")) + else if (!strcmp (debug_level, "basic") || (numok && numlvl <= 2)) opt.debug = DBG_ASSUAN_VALUE; - else if (!strcmp (debug_level, "advanced")) + else if (!strcmp (debug_level, "advanced") || (numok && numlvl <= 5)) opt.debug = (DBG_ASSUAN_VALUE|DBG_X509_VALUE|DBG_LOOKUP_VALUE); - else if (!strcmp (debug_level, "expert")) + else if (!strcmp (debug_level, "expert") || (numok && numlvl <= 8)) opt.debug = (DBG_ASSUAN_VALUE|DBG_X509_VALUE|DBG_LOOKUP_VALUE |DBG_CACHE_VALUE|DBG_CRYPTO_VALUE); - else if (!strcmp (debug_level, "guru")) - opt.debug = ~0; + else if (!strcmp (debug_level, "guru") || numok) + { + opt.debug = ~0; + /* Unless the "guru" string has been used we don't want to allow + hashing debugging. The rationale is that people tend to + select the highest debug value and would then clutter their + disk with debug files which may reveal confidential data. */ + if (numok) + opt.debug &= ~(DBG_HASHING_VALUE); + } else { log_error (_("invalid debug-level `%s' given\n"), debug_level); Modified: trunk/src/server.c =================================================================== --- trunk/src/server.c 2009-12-22 13:02:09 UTC (rev 335) +++ trunk/src/server.c 2010-03-09 13:42:02 UTC (rev 336) @@ -1354,7 +1354,7 @@ rc = assuan_new (&ctx); if (rc) { - log_error (_("failed to allocate assuan context: %s\n"), + log_error (_(), gpg_strerror (rc)); dirmngr_exit (2); } From cvs at cvs.gnupg.org Tue Mar 9 14:42:34 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 14:42:34 +0100 Subject: [svn] dirmngr - r337 - trunk Message-ID: Author: wk Date: 2010-03-09 14:42:33 +0100 (Tue, 09 Mar 2010) New Revision: 337 Modified: trunk/ChangeLog Log: From cvs at cvs.gnupg.org Tue Mar 9 14:43:59 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 14:43:59 +0100 Subject: [svn] dirmngr - r338 - trunk/src Message-ID: Author: wk Date: 2010-03-09 14:43:59 +0100 (Tue, 09 Mar 2010) New Revision: 338 Modified: trunk/src/server.c Log: Fix last fix Modified: trunk/src/server.c =================================================================== --- trunk/src/server.c 2010-03-09 13:42:33 UTC (rev 337) +++ trunk/src/server.c 2010-03-09 13:43:59 UTC (rev 338) @@ -1354,7 +1354,7 @@ rc = assuan_new (&ctx); if (rc) { - log_error (_(), + log_error (_("failed to allocate assuan context: %s\n"), gpg_strerror (rc)); dirmngr_exit (2); } From cvs at cvs.gnupg.org Tue Mar 9 14:47:40 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 14:47:40 +0100 Subject: [svn] dirmngr - r339 - trunk/po Message-ID: Author: wk Date: 2010-03-09 14:47:40 +0100 (Tue, 09 Mar 2010) New Revision: 339 Modified: trunk/po/de.po trunk/po/dirmngr.pot Log: ready to release Modified: trunk/po/de.po [not shown] Modified: trunk/po/dirmngr.pot =================================================================== --- trunk/po/dirmngr.pot 2010-03-09 13:43:59 UTC (rev 338) +++ trunk/po/dirmngr.pot 2010-03-09 13:47:40 UTC (rev 339) @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: gpa-dev at gnupg.org\n" -"POT-Creation-Date: 2010-03-09 13:10+0100\n" +"POT-Creation-Date: 2010-03-09 13:14+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1349,6 +1349,11 @@ msgid "can't allocate control structure: %s\n" msgstr "" +#: src/server.c:1357 src/dirmngr-client.c:469 +#, c-format +msgid "failed to allocate assuan context: %s\n" +msgstr "" + #: src/server.c:1378 #, c-format msgid "failed to initialize the server: %s\n" @@ -1619,11 +1624,6 @@ msgid "error writing base64 encoding: %s\n" msgstr "" -#: src/dirmngr-client.c:469 -#, c-format -msgid "failed to allocate assuan context: %s\n" -msgstr "" - #: src/dirmngr-client.c:483 msgid "apparently no running dirmngr\n" msgstr "" From cvs at cvs.gnupg.org Tue Mar 9 14:57:55 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 09 Mar 2010 14:57:55 +0100 Subject: [svn] dirmngr - r340 - tags Message-ID: Author: wk Date: 2010-03-09 14:57:55 +0100 (Tue, 09 Mar 2010) New Revision: 340 Added: tags/dirmngr-1.1.0rc1/ Log: From cvs at cvs.gnupg.org Wed Mar 10 13:25:00 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 10 Mar 2010 13:25:00 +0100 Subject: [svn] GnuPG - r5288 - in trunk: . agent common g10 g13 jnlib kbx keyserver po scd sm tools Message-ID: Author: wk Date: 2010-03-10 13:24:58 +0100 (Wed, 10 Mar 2010) New Revision: 5288 Added: trunk/common/ChangeLog.jnlib trunk/common/README.jnlib trunk/common/argparse.c trunk/common/argparse.h trunk/common/dotlock.c trunk/common/dotlock.h trunk/common/dynload.h trunk/common/estream-printf.c trunk/common/estream-printf.h trunk/common/estream.c trunk/common/estream.h trunk/common/libjnlib-config.h trunk/common/logging.c trunk/common/logging.h trunk/common/mischelp.c trunk/common/mischelp.h trunk/common/stringhelp.c trunk/common/stringhelp.h trunk/common/strlist.c trunk/common/strlist.h trunk/common/t-stringhelp.c trunk/common/t-support.c trunk/common/t-support.h trunk/common/t-timestuff.c trunk/common/t-w32-reg.c trunk/common/types.h trunk/common/utf8conv.c trunk/common/utf8conv.h trunk/common/w32-afunix.c trunk/common/w32-afunix.h trunk/common/w32-reg.c trunk/common/w32help.h trunk/common/xmalloc.c trunk/common/xmalloc.h Removed: trunk/common/estream-printf.c trunk/common/estream-printf.h trunk/common/estream.c trunk/common/estream.h trunk/jnlib/ChangeLog trunk/jnlib/Makefile.am trunk/jnlib/README trunk/jnlib/argparse.c trunk/jnlib/argparse.h trunk/jnlib/dotlock.c trunk/jnlib/dotlock.h trunk/jnlib/dynload.h trunk/jnlib/libjnlib-config.h trunk/jnlib/logging.c trunk/jnlib/logging.h trunk/jnlib/mischelp.c trunk/jnlib/mischelp.h trunk/jnlib/stringhelp.c trunk/jnlib/stringhelp.h trunk/jnlib/strlist.c trunk/jnlib/strlist.h trunk/jnlib/t-stringhelp.c trunk/jnlib/t-support.c trunk/jnlib/t-support.h trunk/jnlib/t-timestuff.c trunk/jnlib/t-w32-reg.c trunk/jnlib/types.h trunk/jnlib/utf8conv.c trunk/jnlib/utf8conv.h trunk/jnlib/w32-afunix.c trunk/jnlib/w32-afunix.h trunk/jnlib/w32-reg.c trunk/jnlib/w32help.h trunk/jnlib/xmalloc.c trunk/jnlib/xmalloc.h Modified: trunk/ChangeLog trunk/Makefile.am trunk/acinclude.m4 trunk/agent/ChangeLog trunk/agent/Makefile.am trunk/agent/command-ssh.c trunk/agent/minip12.c trunk/agent/protect-tool.c trunk/agent/trustlist.c trunk/common/ChangeLog trunk/common/Makefile.am trunk/common/audit.h trunk/common/exechelp.c trunk/common/exechelp.h trunk/common/http.h trunk/common/i18n.h trunk/common/init.c trunk/common/iobuf.c trunk/common/localename.c trunk/common/simple-pwquery.c trunk/common/simple-pwquery.h trunk/common/sysutils.h trunk/common/ttyio.c trunk/common/util.h trunk/common/xasprintf.c trunk/configure.ac trunk/g10/ChangeLog trunk/g10/Makefile.am trunk/g10/main.h trunk/g10/packet.h trunk/g10/rmd160.c trunk/g13/Makefile.am trunk/kbx/ChangeLog trunk/kbx/Makefile.am trunk/kbx/kbxutil.c trunk/kbx/keybox-defs.h trunk/kbx/keybox-dump.c trunk/kbx/keybox-init.c trunk/kbx/keybox-search.c trunk/keyserver/Makefile.am trunk/po/POTFILES.in trunk/scd/ChangeLog trunk/scd/Makefile.am trunk/sm/ChangeLog trunk/sm/Makefile.am trunk/sm/gpgsm.h trunk/tools/ChangeLog trunk/tools/Makefile.am Log: Merged jnlib into common. [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,12 @@ +2010-03-10 Werner Koch + + * jnlib/: Move all code to common/. + * Makefile.am (SUBDIRS): Remove jnlib. + * configure.ac (AC_CONFIG_FILES): Remove jnlib/Makefile. + + * configure.ac (AM_PATH_LIBASSUAN): Remove double test. + * acinclude.m4 (GNUPG_CHECK_ENDIAN): Remove bogus warning. + 2010-03-09 Werner Koch * configure.ac: Add option --disable-ccid-driver. Modified: trunk/agent/ChangeLog =================================================================== --- trunk/agent/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/agent/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,9 @@ +2010-03-10 Werner Koch + + * Makefile.am (common_libs): Remove libjnlib.a. + + * trustlist.c, protect-tool.c, command-ssh.c: Remove estream.h. + 2010-02-17 Werner Koch * call-pinentry.c (start_pinentry): Always free OPTSTR. Send Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/common/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,5 +1,32 @@ +2010-03-10 Werner Koch + + * util.h: Replace jnlib path part by common. + (snprintf): Use the replacement macro on all platforms. + + * Makefile.am (jnlib_sources): New. + (libcommon_a_SOURCES, libcommonpth_a_SOURCES): Add jnlib_sources. + (jnlib_tests): New. + (noinst_PROGRAMS, TESTS): Add jnlib_tests. + (t_common_ldadd): Remove libjnlib.a. + + * README.jnlib, ChangeLog.jnlib, libjnlib-config.h, argparse.c + * argparse.h, dotlock.c, dotlock.h, dynload.h, logging.c + * logging.h, mischelp.c, mischelp.h, stringhelp.c, stringhelp.h + * strlist.c, strlist.h, types.h, utf8conv.c, utf8conv.h + * w32-afunix.c, w32-afunix.h, w32-reg.c, w32help.h, xmalloc.c + * xmalloc.h, t-stringhelp.c, t-support.c, t-support.h + * t-timestuff.c, t-w32-reg.c: Move from jnlib to here. + + * init.c: Remove "estream.h". + * util.h: Include "estream.h". + + * xasprintf.c, ttyio.c: Remove "estream-printf.h". + 2010-03-08 Werner Koch + * exechelp.c [!HAVE_SIGNAL_H]: Do not include signal.h. + (DETACHED_PROCESS, CREATE_NEW_PROCESS_GROUP) [W32CE]: Provide stubs. + * iobuf.h (iobuf_ioctl_t): New. Use the new macros instead of the hard wired values. * iobuf.c (iobuf_append): Remove. Copied: trunk/common/ChangeLog.jnlib (from rev 5274, trunk/jnlib/ChangeLog) =================================================================== --- trunk/common/ChangeLog.jnlib (rev 0) +++ trunk/common/ChangeLog.jnlib 2010-03-10 12:24:58 UTC (rev 5288) @@ -0,0 +1,769 @@ +2010-03-10 Werner Koch + + See gnupg/common/ChangeLog for newer changes. + + JNLIB has been merged into GnuPG's common directory. README.jnlib + list the files making up JNLIB. + + * README: Rename to README.jnlib + * ChangeLog: Rename to ChangeLog.jnlib. + * Makefile.am: Remove. + +2010-03-01 Werner Koch + + * t-w32-reg.c: New. + + * w32-reg.c (read_w32_registry_string) + (write_w32_registry_string): Support W32CE. + +2010-02-26 Werner Koch + + * t-timestuff.c: New. + + * dynload.h (dlopen, dlsym) [W32CE]: Map to wchar_t. + + * mischelp.c (_jnlib_free): New. + (same_file_p) [W32CE]: Map to wchar_t. + + * utf8conv.c (set_native_charset) [W32CE]: Do not use + GetConsoleOutputCP. + (wchar_to_utf8, utf8_to_wchar) [W32]: New. + + * Makefile.am (t_jnlib_ldadd) [W32CE]: Add gpg-error. + + * t-support.h (getenv) [HAVE_GETENV]: Add getenv stub. + [W32CE]: Include gpg-error.h + * t-support.c (gpg_err_code_from_errno) + (gpg_err_code_from_syserror) [GPG_ERROR_H]: Do not build. + + * t-stringhelp.c (gethome) [!HAVE_GETPWUID]: Keep result of getenv. + + * dotlock.c [!HAVE_SIGNAL_H]: Don't include signal.h. + (create_dotlock) [W32CE]: Map filename top wchar_t. + + * libjnlib-config.h [USE_SIMPLE_GETTEXT]: Include gpg-error.h and + remove w32help.h. + (jnlib_set_errno): New. Use it everywhere to set ERRNO. + (getenv) [!HAVE_GETENV]: New. + (getpid) [W32E]: New. + + * stringhelp.c (get_pwdir) [!HAVE_PWD_H]: Mark unused args. + (w32_strerror) [W32CE]: Use a simple implementation. + + * w32help.h [USE_SIMPLE_GETTEXT]: Remove all definitions; we are + now using the gpg-error included implementation. + * w32-gettext.c: Remove. + + * mischelp.c (same_file_p): Fix bug in case the second file can't + be opened. + +2009-10-19 Werner Koch + + * strlist.c (add_to_strlist_try): New. + +2009-09-22 Werner Koch + + * dotlock.h (DOTLOCK): Rename to dotlock_t. Change all users. + +2009-08-26 Werner Koch + + * stringhelp.c (do_make_filename): Factor some code out to .. + (get_pwdir): .. new. + +2009-08-26 Werner Koch + + * stringhelp.c [HAVE_PWD_H]: Include pwd.h. + (do_make_filename): New. + (make_filename, make_filename_try): Implement using the new + function. + * t-stringhelp.c (test_make_filename_try): New. + * t-support.c (gcry_strdup): Fix. + + * stringhelp.h (make_filename, make_filename_try): Add sentinel + attribute. + +2009-08-25 Werner Koch + + * stringhelp.c: Include errno.h. + (do_strconcat): New. + (strconcat, xstrconcat): New. + * types.h (GNUPG_GCC_A_SENTINEL): New. + * t-stringhelp.c (test_strconcat, test_xstrconcat): New. + (main): Run them. + +2009-07-07 Werner Koch + + * stringhelp.c (make_filename_try): Use jnlib_malloc. + + * dotlock.c (read_lockfile): Replace jnlib_xmalloc by jnlib_malloc. + +2009-06-04 Werner Koch + + * mischelp.h: Include SUN_LEN etc also for W32. + +2009-05-19 Werner Koch + + * mischelp.h: Define PF_LOCAL, AF_LOCAL and SUN_LEN if requested. + * logging.c (fun_writer): Use SUN_LEN to fix a Mac OS X freeze. + +2009-03-25 Werner Koch + + * logging.c (fun_closer): Never close fd 2. + (set_file_fd): Close logstream early. + +2009-02-25 Werner Koch + + * logging.c (get_tid_callback): New. + (do_logv): Use it. + (log_set_get_tid_callback): New. + +2009-01-22 Werner Koch + + * t-support.c (gpg_err_code_from_errno) + (gpg_err_code_from_syserror): New. + +2008-11-20 Werner Koch + + * argparse.c (arg_parse): Fix last change. + +2008-11-11 Werner Koch + + * argparse.h: Add a bunch of macros and constants. + * argparse.c: Use the new macros. Re-indent the code. Change + license back to LGPL 2.1. + +2008-11-04 Werner Koch + + * w32-gettext.c: Merged with code from libgpg-error and rewrote + most parts. + + * Makefile.am (AM_CFLAGS): Add -DJNLIB_IN_JNLIB. + +2008-10-29 Werner Koch + + * stringhelp.c (make_filename): Implement using macros. Factor some + code out to .. + (change_slashes): New. + (make_filename_try): New. + + * w32-gettext.c (gettext): Return if no domain is loaded. + Reported by Tom Pegios. + +2008-10-28 Werner Koch + + * w32-gettext.c (gettext): Try the binary search if the string was + not found in the hash table. + +2008-10-20 Werner Koch + + * w32-afunix.c (_w32_sock_connect): Mark ADDRLEN as unused. + + * dotlock.c (release_dotlock): Do not mix declaration and code. + + * stringhelp.c (make_basename): Silent gcc warning about unused arg. + * argparse.c (store_alias): Ditto. + (find_long_option): + +2008-10-15 Werner Koch + + * logging.c (do_logv) [W32]: Flush the log stream. + +2008-09-29 Werner Koch + + * argparse.c (ARGERR_): Use constants for error values. + (optfile_parse): Prettify. Replace xmalloc and xrealloc by malloc + and realloc. + * libjnlib-config.h (jnlib_strdup, jnlib_realloc): New. + +2008-06-26 Werner Koch + + * stringhelp.c (print_sanitized_buffer2): Loose check for control + characters to better cope with utf-8. The range 0x80..0x9f is + nowadays not anymore accidently used for control charaters. + +2008-06-13 Werner Koch + + * dotlock.c: Reformat code and implement locking for W32. + (create_dotlock): Use snprintf. + +2008-06-11 Werner Koch + + * utf8conv.c: Remove useless variable ACTIVE_CHARSET. Suggested + by Petr Uzel. + +2008-05-26 Werner Koch + + * argparse.c (usage): Make sure to print a trailing LF for usage(1). + +2008-04-08 Werner Koch + + * w32-gettext.c (gettext_select_utf8): New. + (get_string): Support switching encodings. + (load_domain): Allocate space for DATA_NATIVE. + +2008-03-25 Werner Koch + + * w32-gettext.c (_nl_locale_name): New. Taken from + ../common/localename and GNU gettext's localename.c. + (set_gettext_file): Rewritten. + (gettext_localename): New. + +2008-03-17 Werner Koch + + * logging.c (my_funopen_hook_size_t): New. + (fun_writer): Use it to cope with fopencookie/funopen differences. + * dotlock.c (read_lockfile): Initialize PID. Reported by St?phane + Corth?sy. + +2008-02-22 Werner Koch + + * argparse.c (strusage): Set copyright year to 2008. + +2007-11-19 Werner Koch + + * stringhelp.c (percent_escape): Factor code out to + (do_percent_escape): .. new. + (try_percent_escape): New. + +2007-10-01 Werner Koch + + * w32-afunix.c: Only keep the client related code. + (read_port_and_nonce): New. Taken from Assuan. + (_w32_sock_connect): Rewritten. + +2007-08-29 Werner Koch + + * argparse.c (initialize): Make strings translatable and remove + extra LF. + +2007-08-24 Werner Koch + + * mischelp.c (same_file_p): New. + (libjnlib_dummy_mischelp_func): Remove as we now always have one + function. + +2007-08-09 Werner Koch + + * argparse.c (show_help): Expand the @EMAIL@ macro in the package + bug reporting address. + +2007-08-02 Werner Koch + + * t-stringhelp.c (test_compare_filenames): New. + + * stringhelp.c (compare_filenames) [HAVE_DRIVE_LETTERS]: Fixed + comparison to take slash and backslash in account. + (make_filename): Avoid mixing / and \. + +2007-07-04 Werner Koch + + * utf8conv.c (load_libiconv): Remove URL from translatble string. + + Switched JNLIB from LGPLv2.1 to LGPLv3. + +2007-07-01 Werner Koch + + * argparse.c (strusage): Use id 10 for the license string; + default to GPL3+. Change long note to version 3 or later. + (show_version): Print the license info. + +2007-06-19 Werner Koch + + * Makefile.am: Add support for regression tests. + * t-support.h, t-support.c: New. + * t-stringhelp.c: New. + + * stringhelp.c (percent_escape): Add arg EXTRA to make it a more + general function. Changed all callers. + +2007-06-18 Werner Koch + + * w32-afunix.c (_w32_sock_bind): Changed to properly detect an + already used socket. + +2007-06-18 Marcus Brinkmann + + * stringhelp.h (percent_escape): New prototype. + * stringhelp.c (percent_escape): New function. + +2007-06-11 Werner Koch + + * utf8conv.c (jnlib_iconv_open, jnlib_iconv, jnlib_iconv_close): New. + +2007-06-06 Werner Koch + + * w32help.h: New. + * w32-gettext.c: New. Taken from gnupg 1.4, added ngettext, + changed to use jnlib malloc functions and put under the LGPL. + * w32-reg.c: New. Taken from../common/w32reg.c and changed to + LGPL. Changed API to use the jnlib malloc functions. + * Makefile.am (libjnlib_a_SOURCES) [!W32]: Do not build the w32 + specific modules. + + * dotlock.c: Include stringhelp.h for stpcpy prototype. + +2007-06-04 Werner Koch + + * dynload.h: New. Taken from ../common and changed to LGPL. + + * utf8conv.c (load_libiconv): New. Taken from GnuPG 1.4 + +2007-05-30 Werner Koch + + * w32-pth.h, w32-pth.c: Remove. + +2007-04-25 Werner Koch + + * argparse.c (long_opt_strlen): Fixed for utf-8. + +2007-03-07 Werner Koch + + * argparse.c (strusage): Set copyright year to 2007. + +2007-01-25 Werner Koch + + * stringhelp.c (utf8_charcount): New. + +2006-11-29 Werner Koch + + * utf8conv.c (set_native_charset) [HAVE_W32_SYSTEM]: Fixed typo in + macro name. + +2006-11-15 Werner Koch + + * logging.c (my_funopen_hook_ret_t): New. + (fun_writer): Use it. + +2006-10-19 Werner Koch + + * stringhelp.c (memrchr) [!HAVE_MEMRCHR]: Provide a replacement. + +2006-09-27 Werner Koch + + * mischelp.c: New. + (timegm): Copied from gnupg 1.4, changed from GPL to LGPL. Fixed + a memory leak. + + * stringhelp.h (isascii): New. + + * stringhelp.c (strsep): New. Copied from gnupg 1.4.5 + util/strgutil.c. + + * strlist.h (STRLIST): Removed deprecated typedef. + + * types.h: Made cpp commands work with old compilers. Also shows + up nicer with Emacs' font locking. + + * w32-afunix.c (_w32_sock_connect): Set ERRNO for an invalid port. + + Changed license from GPL to LGPL. Note that all code has either + been written by me, David, employees of g10 Code or taken from + glibc. + + * libjnlib-config.h, stringhelp.c, stringhelp.h: + * strlist.c, strlist.h, utf8conv.c, utf8conv.h: + * argparse.c, argparse.h, logging.c, logging.h: + * dotlock.c, dotlock.h, types.h, mischelp.h: + * xmalloc.c, xmalloc.h, w32-pth.c, w32-pth.h: + * w32-afunix.c, w32-afunix.h: Tagged them to be long to jnlib + which is a part of GnuPG but also used by other projetcs. + +2006-09-22 Werner Koch + + * utf8conv.c: Reworked to match the gnupg 1.4.5 code. This now + requires iconv support but this is reasonable for all modern + systems. + +2006-08-29 Werner Koch + + * logging.c (do_logv): Emit a missing LF for fatal errors. + +2006-06-28 Werner Koch + + * dotlock.c (make_dotlock, release_dotlock, read_lockfile) + (maybe_deadlock, destroy_dotlock, create_dotlock): Re-indented. + (create_dotlock): Repalces some log_fatal by log_error as it was + not intended that they should terminate. Write the nodename to + the locking file. Code cleanups. + (read_lockfile): Reworked to read the node name. + (make_dotlock): Test for identical node name and delete lock stale + file. + (release_dotlock): Likewise. + +2006-05-23 Werner Koch + + * libjnlib-config.h (JNLIB_NEED_UTF8CONV): Fixed typo in name. + + * dotlock.c (release_dotlock): Don't act if we don't have any + locks at all. + (destroy_dotlock): New. From 1.4.3. + (dotlock_remove_lockfiles): Make use of destroy function. + +2006-05-19 Werner Koch + + * strlist.c (append_to_strlist2): Enabled. + + * stringhelp.c (print_sanitized_buffer2): New. Changed the rules + to match the behaviour of print_string2 from gnupg 1.4.3. + (print_sanitized_buffer): Use the new function. + (print_sanitized_string2): New. + (hextobyte): New. Taken from gpg 1.4.3. + +2006-04-28 Werner Koch + + * stringhelp.c (print_sanitized_buffer): Fix bug where the count + got wrong for the \xNN representation. + (sanitize_buffer): Fix bug where some control characters lose part + of their \xNN representation. + +2006-04-20 Werner Koch + + * stringhelp.c (make_basename): New arg INPUTPATH for future + riscos compatibility. + +2006-04-18 Werner Koch + + * libjnlib-config.h (JNLIB_NEED_UTF8CONF): Defined. + * strlist.c (add_to_strlist2) [JNLIB_NEED_UTF8CONV]: Enabled. + +2005-06-15 Werner Koch + + * stringhelp.c (sanitize_buffer): Make P a void*. + (ascii_memistr, memistr): Ditto. + (ascii_memcasecmp): Ditto. + * logging.c (writen): Use void * for arg BUFFER. + * stringhelp.c (memistr): Fixed unsigned/signed pointer conflict. + (ascii_memistr): Ditto. + (ascii_memcasemem): Ditto. + * utf8conv.c (utf8_to_native): Ditto. + (utf8_to_native): Ditto. + * argparse.c (show_version): Removed non-required cast. + +2005-01-19 Werner Koch + + * logging.c (fun_writer): Don't fallback to stderr. Print to + stderr only if connected to a tty. + +2004-12-20 Werner Koch + + * w32-pth.c (do_pth_event_free): The events are hold in a ring + buffer. Adjust for that. + (do_pth_event_body): Ditto. + (pth_event_isolate): Ditto. + (do_pth_wait): Ditto. + (_pth_event_count): Renamed to .. + (event_count): .. and adjusted as above. + (pth_init): Define 3 debug levels and change all debug calls to + make use of them. This makes the moule now silent. + +2004-12-19 Werner Koch + + * w32-pth.c (pth_init): Enable debugging depending on env var. + (pth_self): New. + (pth_mutex_release, pth_mutex_acquire): Implemented directly using + the W32 API. + +2004-12-18 Werner Koch + + * w32-pth.c (pth_init): Reverse return values. Use TRUE and FALSE + constants. + (pth_kill, pth_mutex_acquire, pth_attr_set, pth_join, pth_cancel): + Ditto. + +2004-12-15 Werner Koch + + * logging.c [W32]: Don't include unavailable headers. + +2004-12-14 Werner Koch + + * w32-pth.c (_pth_strerror): Renamed to ... + (w32_strerror): .. this. And let callers provide a buffer. + (spawn_helper_thread): Removed HD arg and hardwire the stack size + to 32k. + (do_pth_wait): Removed use of ATTR; not needed for the helper + threads. + (helper_thread): Renamed to .. + (launch_thread): .. this. Release handle if not joinable. + (struct pth_priv_hd_s): Renamed to ... + (struct thread_info_s): .. this. Add member JOINABLE and TH. + +2004-12-14 Timo Schulz + + * w32-pth.c (pth_kill): Just release the crit section if + pth_init was really called. And set all handles to NULL. + (_pth_strerror): New. + (do_pth_wait): Before we enter the loop we check if there + are too much events in the ring. + +2004-12-14 Werner Koch + + * w32-pth.h (pth_event_occured): Removed macro. + * w32-pth.c: Fixed license statement; its under the LGPL. + (enter_pth, leave_pth): Use them to bracket almost all public + functions. + +2004-12-13 Timo Schulz + + * w32-pth.c (enter_pth, leave_pth): New. + (pth_init): Initialize global mutex section. + (pth_kill): Release global mutex section. + (helper_thread): New. + (pth_spawn): Make sure only one thread is running. + +2004-12-13 Werner Koch + + * stringhelp.c (w32_strerror) [W32]: New. + + * w32-pth.c, w32-pth.h: Added real code written by Timo Schulz. + Not finished, though. + +2004-12-07 Werner Koch + + * w32-pth.c, w32-pth.h: New. + +2004-11-26 Werner Koch + + * logging.c [_WIN32]: Don't include socket headers. + +2004-11-30 Timo Schulz + + * w32-afunix.c: New. AF_UNIX emulation for W32. + * w32-afunix.h: Likewise. + +2004-11-22 Werner Koch + + * logging.c (log_test_fd): Add test on LOGSTREAM. Reported by + Barry Schwartz. + +2004-11-18 Werner Koch + + * logging.c: Explicitly include sys/stat.h for the S_I* constants. + +2004-10-21 Werner Koch + + * logging.c (do_logv): Use set_log_stream to setup a default. + (log_set_file): Factored code out to .. + (set_file_fd): .. New function to allow using a file descriptor. + (log_set_fd): Make use of new fucntion. + (fun_writer): Reworked. + +2004-08-18 Werner Koch + + * stringhelp.c (print_sanitized_utf8_string): Actually implement + it. + +2004-06-21 Werner Koch + + * logging.c (log_set_file): Do not close an old logstream if it + used to be stderr or stdout. + +2004-05-05 Werner Koch + + * logging.c (log_set_file): Oops, don't close if LOGSTREAM is NULL. + +2004-04-30 Werner Koch + + * logging.c (log_set_file): Make sure the log stream will be + closed even if the stderr fileno will be assigned to a new socket. + +2004-04-16 Werner Koch + + * logging.h (JNLIB_LOG_WITH_PREFIX): Add constants for the flag + values. + * logging.c (log_set_prefix): New flag DETACHED. + (fun_writer): Take care of this flag. + (log_test_fd): New. + +2004-02-18 Werner Koch + + * stringhelp.c (print_sanitized_buffer): Don't care about + non-ASCII characaters. + (sanitize_buffer): Ditto. + +2004-02-12 Werner Koch + + * Makefile.am: Replaced INCLUDES by AM_CPPFLAGS. + +2004-01-05 Werner Koch + + * argparse.c (strusage): Changed default copyright year to 2004. + +2003-12-17 Werner Koch + + * argparse.c (initialize): Replaced use of non-literal format + args. Suggested by Florian Weimer. + +2003-12-16 Werner Koch + + * logging.c (writen, fun_writer, fun_closer): New. + (log_set_file): Add feature to log to a socket. + (log_set_file, do_logv): Force printing with prefix and pid. + +2003-11-13 Werner Koch + + * strlist.c (strlist_copy): New. + + * dotlock.c: Define DIRSEP_C et al. if not defined. + +2003-11-06 Werner Koch + + * strlist.h (strlist_t): New. STRLIST is now deprecated. + +2003-06-18 Werner Koch + + * strlist.c (strlist_pop): New. + + * dotlock.c (dotlock_remove_lockfiles): Prefixed with dotlock_ and + made global. + +2003-06-17 Werner Koch + + * stringhelp.c (length_sans_trailing_chars) + (length_sans_trailing_ws): New. + + * logging.c (log_inc_errorcount): New. + + * stringhelp.c (print_sanitized_utf8_buffer): Implement utf8 + conversion. + (sanitize_buffer): New. Based on gnupg 1.3.2 make_printable_string. + + * dotlock.c: Updated to match the version from 1.3.2 + * utf8conv.c: New. Code taken from strgutil.c of gnupg 1.3.2. + * utf8conv.h: New. + +2003-06-16 Werner Koch + + * logging.c (do_logv): Hack to optionally suppress a leading space. + + * stringhelp.c (ascii_strncasecmp): New. Taken from gnupg 1.3. + (ascii_memistr): New. Taken from gnupg 1.3 + +2003-06-13 Werner Koch + + * mischelp.h (wipememory2,wipememory): New. Taken from GnuPG 1.3.2. + +2002-06-04 Werner Koch + + * stringhelp.c (print_sanitized_utf8_string): New. No real + implementation for now. + (print_sanitized_utf8_buffer): Ditto. + +2002-04-04 Werner Koch + + * logging.c (log_get_prefix): New. + +2002-03-15 Werner Koch + + * argparse.c (optfile_parse): Fixed missing argument handling. + +2002-02-25 Werner Koch + + * stringhelp.c (ascii_memcasemem): New. + +2002-02-14 Werner Koch + + * Makefile.am (INCLUDES): Add cflags for libgcrypt. + +2002-02-07 Werner Koch + + * logging.c (log_set_fd): New. + + * stringhelp.c (print_sanitized_buffer): New. + (print_sanitized_string): New. + +2002-01-24 Werner Koch + + * argparse.c (strusage): Set default copyright notice year to 2002. + + Fixed the copyright notice of this file, as it has always been + part of GnuPG and therefore belongs to the FSF. + +2001-11-01 Marcus Brinkmann + + * logging.c (log_printf): Do not initialize ARG_PTR with 0, we + don't know the correct type. Instead, run va_start and va_end + unconditionally. + Reported by Jose Carlos Garcia Sogo . + +2002-01-19 Werner Koch + + * logging.c (log_get_stream): New. + +2001-12-05 Werner Koch + + * logging.c (log_set_prefix): New. + (do_logv): Include prefix and pid only if enabled. Print time only + when explicitly enabled. + (log_logv): New. + * logging.h: Include log_logv() only when requested. + +2001-11-06 Werner Koch + + * strlist.c, strlist.h: New. Taken from pgnupg/util/strgutil.c + +2001-08-30 Werner Koch + + * logging.c (log_printf): Don't pass NULL instead of arg_ptr. + +2001-07-19 Werner Koch + + * stringhelp.c (ascii_memistr,ascii_isupper,ascii_islower, + ascii_toupper,ascii_tolower, ascii_strcasecmp, ascii_memcasecmp): New. + +2000-07-26 10:02:51 Werner Koch (wk at habibti.openit.de) + + * stringhelp.c.: Add stdarg.h + * argparse.h: s/ulong/unsigned long/ although this should be defined + by types.h. + +2000-06-28 19:40:23 Werner Koch (wk at habibti.openit.de) + + * Makefile.am: Replaced second logging.c by .h + +2000-05-24 08:58:15 Werner Koch (wk at habibti.openit.de) + + * logging.c (log_get_errorcount): New. + +2000-05-24 08:44:47 Werner Koch (wk at habibti.openit.de) + + * stringhelp.c: Added a few filename related helper functions. + +2000-05-11 18:04:43 Werner Koch (wk at habibti.openit.de) + + * xmalloc.c (xstrcat2): Replaced stpcpy to quickly address W32 + problems. + +2000-05-02 19:43:38 Werner Koch (wk at habibti.openit.de) + + * xmalloc.c (xstrcat2): New. + +Mon Jan 24 13:04:28 CET 2000 Werner Koch + + * README: New. + * Makefile.am: new. + * argparse.c, argparse.h, logging.c, logging.h: + * mischelp.h, stringhelp.c, stringhelp.h, xmalloc.c: + * xmalloc.h, dotlock.c: Moved from ../util to here. + * dotlock.h: New. + * libjnlib-config.h: New. + + * logging.c (log_set_file): New. + (log_printf): New. + (do_logv): Add kludge to insert LFs. + + + *********************************************************** + * Please note that JNLIB is maintained as part of GnuPG. * + * You may find it source-copied in other packages. * + *********************************************************** + + Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, + 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 + modifications, as long as this notice is preserved. + + 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. Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/g10/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,9 @@ +2010-03-10 Werner Koch + + * Makefile.am (needed_libs): Remove libjnlib.a. + + * main.h: Remove "estream.h". + 2010-03-08 Werner Koch * main.h: Include "estream.h" Modified: trunk/kbx/ChangeLog =================================================================== --- trunk/kbx/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/kbx/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,10 @@ +2010-03-10 Werner Koch + + * Makefile.am (kbxutil_LDADD, $(PROGRAMS)): Remove libjnlib.a. + + * keybox-search.c, keybox-init.c, keybox-defs.h, kbxutil.c: + Replace "jnlib" include file part by "common". + 2010-03-08 Werner Koch Use macros for iobuf_ioctl commands. Modified: trunk/scd/ChangeLog =================================================================== --- trunk/scd/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/scd/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,7 @@ +2010-03-10 Werner Koch + + * Makefile.am (scdaemon_LDADD): Remove libjnlib.a. + 2009-12-15 Werner Koch * iso7816.c (do_generate_keypair): s/readonly/read_only/ because Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/sm/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,9 @@ +2010-03-10 Werner Koch + + * Makefile.am (common_libs): Remove libjnlib.a. Change order. + + * gpgsm.h: Remove "estream.h". + 2010-03-08 Werner Koch * certreqgen.c (gpgsm_genkey): Change OUT_FP to an estream_t Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/tools/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,3 +1,7 @@ +2010-03-10 Werner Koch + + * Makefile.am (common_libs): Remove libjnlib.a. + 2010-03-08 Werner Koch * no-libgcrypt.c (gcry_create_nonce): New. Modified: trunk/Makefile.am =================================================================== --- trunk/Makefile.am 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/Makefile.am 2010-03-10 12:24:58 UTC (rev 5288) @@ -76,7 +76,7 @@ tests = tests endif -SUBDIRS = m4 gl include jnlib common ${kbx} \ +SUBDIRS = m4 gl include common ${kbx} \ ${gpg} ${keyserver} ${sm} ${agent} ${scd} ${g13} ${tools} po ${doc} ${tests} dist_doc_DATA = README Modified: trunk/acinclude.m4 =================================================================== --- trunk/acinclude.m4 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/acinclude.m4 2010-03-10 12:24:58 UTC (rev 5288) @@ -103,6 +103,7 @@ AC_DEFUN([GNUPG_CHECK_ENDIAN], [ tmp_assumed_endian=big + tmp_assume_warn="" if test "$cross_compiling" = yes; then case "$host_cpu" in i@<:@345678@:>@* ) @@ -111,7 +112,6 @@ *) ;; esac - AC_MSG_WARN(cross compiling; assuming $tmp_assumed_endian endianess) fi AC_MSG_CHECKING(endianess) AC_CACHE_VAL(gnupg_cv_c_endian, @@ -141,10 +141,11 @@ gnupg_cv_c_endian=little, gnupg_cv_c_endian=big, gnupg_cv_c_endian=$tmp_assumed_endian + tmp_assumed_warn=" (assumed)" ) fi ]) - AC_MSG_RESULT([$gnupg_cv_c_endian]) + AC_MSG_RESULT([${gnupg_cv_c_endian}${tmp_assumed_warn}]) if test "$gnupg_cv_c_endian" = little; then AC_DEFINE(LITTLE_ENDIAN_HOST,1, [Defined if the host has little endian byte ordering]) Modified: trunk/agent/Makefile.am =================================================================== --- trunk/agent/Makefile.am 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/agent/Makefile.am 2010-03-10 12:24:58 UTC (rev 5288) @@ -45,8 +45,8 @@ call-scd.c \ learncard.c -common_libs = $(libcommon) ../jnlib/libjnlib.a ../gl/libgnu.a -commonpth_libs = $(libcommonpth) ../jnlib/libjnlib.a ../gl/libgnu.a +common_libs = $(libcommon) ../gl/libgnu.a +commonpth_libs = $(libcommonpth) ../gl/libgnu.a pwquery_libs = ../common/libsimple-pwquery.a #if HAVE_W32_SYSTEM Modified: trunk/agent/command-ssh.c =================================================================== --- trunk/agent/command-ssh.c 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/agent/command-ssh.c 2010-03-10 12:24:58 UTC (rev 5288) @@ -32,7 +32,6 @@ #include "agent.h" -#include "estream.h" #include "i18n.h" Modified: trunk/agent/minip12.c =================================================================== --- trunk/agent/minip12.c 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/agent/minip12.c 2010-03-10 12:24:58 UTC (rev 5288) @@ -32,8 +32,8 @@ #include #endif -#include "../jnlib/logging.h" -#include "../jnlib/utf8conv.h" +#include "../common/logging.h" +#include "../common/utf8conv.h" #include "minip12.h" #ifndef DIM @@ -2354,7 +2354,7 @@ /* Local Variables: -compile-command: "gcc -Wall -O0 -g -DTEST=1 -o minip12 minip12.c ../jnlib/libjnlib.a -L /usr/local/lib -lgcrypt -lgpg-error" +compile-command: "gcc -Wall -O0 -g -DTEST=1 -o minip12 minip12.c ../common/libcommon.a -L /usr/local/lib -lgcrypt -lgpg-error" End: */ #endif /* TEST */ Modified: trunk/agent/protect-tool.c =================================================================== --- trunk/agent/protect-tool.c 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/agent/protect-tool.c 2010-03-10 12:24:58 UTC (rev 5288) @@ -44,7 +44,6 @@ #include "i18n.h" #include "get-passphrase.h" #include "sysutils.h" -#include "estream.h" enum cmd_and_opt_values Modified: trunk/agent/trustlist.c =================================================================== --- trunk/agent/trustlist.c 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/agent/trustlist.c 2010-03-10 12:24:58 UTC (rev 5288) @@ -31,7 +31,6 @@ #include "agent.h" #include /* fixme: need a way to avoid assuan calls here */ #include "i18n.h" -#include "estream.h" /* A structure to store the information from the trust file. */ Property changes on: trunk/common/ChangeLog.jnlib ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Modified: trunk/common/Makefile.am =================================================================== --- trunk/common/Makefile.am 2010-03-09 12:50:48 UTC (rev 5287) +++ trunk/common/Makefile.am 2010-03-10 12:24:58 UTC (rev 5288) @@ -1,5 +1,5 @@ # Makefile for common gnupg modules -# Copyright (C) 2001, 2003, 2007 Free Software Foundation, Inc. +# Copyright (C) 2001, 2003, 2007, 2010 Free Software Foundation, Inc. # # This file is part of GnuPG. # @@ -19,11 +19,11 @@ ## Process this file with automake to produce Makefile.in EXTRA_DIST = mkstrtable.awk exaudit.awk exstatus.awk \ - audit-events.h status-codes.h + audit-events.h status-codes.h README.jnlib ChangeLog.jnlib noinst_LIBRARIES = libcommon.a libcommonpth.a libsimple-pwquery.a libgpgrl.a -noinst_PROGRAMS = $(module_tests) $(module_maint_tests) -TESTS = $(module_tests) +noinst_PROGRAMS = $(jnlib_tests) $(module_tests) $(module_maint_tests) +TESTS = $(jnlib_tests) $(module_tests) BUILT_SOURCES = audit-events.h status-codes.h @@ -35,9 +35,26 @@ include $(top_srcdir)/am/cmacros.am +jnlib_sources = \ + libjnlib-config.h \ + types.h dynload.h w32help.h \ + stringhelp.c stringhelp.h \ + strlist.c strlist.h \ + utf8conv.c utf8conv.h \ + argparse.c argparse.h \ + logging.c logging.h \ + dotlock.c dotlock.h \ + mischelp.c mischelp.h + +if HAVE_W32_SYSTEM +jnlib_sources += w32-reg.c w32-afunix.c w32-afunix.h +endif + + common_sources = \ common-defs.h \ util.h i18n.c i18n.h \ + estream.c estream.h estream-printf.c estream-printf.h \ status.c status.h\ openpgpdefs.h \ gc-opt-flags.h \ @@ -62,7 +79,6 @@ asshelp.c asshelp.h \ exechelp.c exechelp.h \ signal.c \ - estream.c estream.h estream-printf.c estream-printf.h \ audit.c audit.h \ srv.h \ dns-cert.c dns-cert.h \ @@ -78,13 +94,13 @@ get-passphrase.c get-passphrase.h -libcommon_a_SOURCES = $(common_sources) $(without_pth_sources) +libcommon_a_SOURCES = $(jnlib_sources) $(common_sources) $(without_pth_sources) if USE_DNS_SRV libcommon_a_SOURCES += srv.c endif libcommon_a_CFLAGS = $(AM_CFLAGS) $(LIBASSUAN_CFLAGS) -DWITHOUT_GNU_PTH=1 -libcommonpth_a_SOURCES = $(common_sources) +libcommonpth_a_SOURCES = $(jnlib_sources) $(common_sources) if USE_DNS_SRV libcommonpth_a_SOURCES += srv.c endif @@ -121,13 +137,32 @@ # # Module tests # +t_jnlib_src = t-support.c t-support.h +jnlib_tests = t-stringhelp t-timestuff +if HAVE_W32_SYSTEM +jnlib_tests += t-w32-reg +endif module_tests = t-convert t-percent t-gettime t-sysutils t-sexputil t-exechelp \ t-session-env module_maint_tests = t-helpfile t-b64 -t_common_ldadd = libcommon.a ../jnlib/libjnlib.a ../gl/libgnu.a \ + +t_common_ldadd = libcommon.a ../gl/libgnu.a \ $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) $(LIBINTL) $(LIBICONV) +# jnlib tests +t_stringhelp_SOURCES = t-stringhelp.c $(t_jnlib_src) +t_stringhelp_LDADD = $(t_common_ldadd) + +t_timestuff_SOURCES = t-timestuff.c $(t_jnlib_src) +t_timestuff_LDADD = $(t_common_ldadd) + +if HAVE_W32_SYSTEM +t_w32_reg_SOURCES = t-w32-reg.c $(t_jnlib_src) +t_w32_reg_LDADD = $(t_common_ldadd) +endif + +# common tests t_convert_LDADD = $(t_common_ldadd) t_percent_LDADD = $(t_common_ldadd) t_gettime_LDADD = $(t_common_ldadd) @@ -138,3 +173,6 @@ t_exechelp_LDADD = $(t_common_ldadd) t_session_env_LDADD = $(t_common_ldadd) + + + Copied: trunk/common/README.jnlib (from rev 5272, trunk/jnlib/README) =================================================================== --- trunk/common/README.jnlib (rev 0) +++ trunk/common/README.jnlib 2010-03-10 12:24:58 UTC (rev 5288) @@ -0,0 +1,101 @@ +JNLIB - This is a collection of utility function which are too small +to put into a library. The code here is licensed under the LGPL. + +libjnlib-config.h should be be modified for each project to make these +functions fit into the software. Mainly these are memory functions in +case you need another allocator. + +Files which make up jnlib: + README.jnlib + ChangeLog.jnlib + libjnlib-config.h + argparse.c + argparse.h + dotlock.c + dotlock.h + dynload.h + logging.c + logging.h + mischelp.c + mischelp.h + stringhelp.c + stringhelp.h + strlist.c + strlist.h + types.h + utf8conv.c + utf8conv.h + w32-afunix.c + w32-afunix.h + w32-reg.c + w32help.h + xmalloc.c + xmalloc.h + t-stringhelp.c + t-support.c + t-support.h + t-timestuff.c + t-w32-reg.c + + +Here is a template Makefile.am for these jnlib modules: +===8<================================================== +EXTRA_DIST = README +noinst_PROGRAMS = $(module_tests) +TESTS = $(module_tests) + +AM_CPPFLAGS = -I$(top_srcdir)/intl + +# We need libgcrypt because libjnlib-config includes gcrypt.h +AM_CFLAGS = $(LIBGCRYPT_CFLAGS) + +noinst_LIBRARIES = libjnlib.a + +libjnlib_a_SOURCES = \ + libjnlib-config.h \ + stringhelp.c stringhelp.h \ + strlist.c strlist.h \ + utf8conv.c utf8conv.h \ + argparse.c argparse.h \ + logging.c logging.h \ + dotlock.c dotlock.h \ + types.h mischelp.c mischelp.h dynload.h w32help.h \ + xmalloc.c xmalloc.h + +if HAVE_W32_SYSTEM +libjnlib_a_SOURCES += w32-reg.c w32-afunix.c w32-afunix.h +endif + +# +# Module tests. +# +# These tests should only be used at the canonical location of jnlib +# which is the GnuPG package. The reason for this is that t-support.c +# defines replacements for the actual used memory allocation functions +# so that there is no dependency on libgcrypt. +# +module_tests = t-stringhelp t-timestuff +if HAVE_W32_SYSTEM +module_tests += t-w32-reg +endif + +t_jnlib_src = t-support.c t-support.h +t_jnlib_ldadd = libjnlib.a $(LIBINTL) $(LIBICONV) +# For W32 we need libgpg-error because it provides gettext. +if HAVE_W32_SYSTEM +t_jnlib_ldadd += $(GPG_ERROR_LIBS) +endif + +t_stringhelp_SOURCES = t-stringhelp.c $(t_jnlib_src) +t_stringhelp_LDADD = $(t_jnlib_ldadd) + +t_timestuff_SOURCES = t-timestuff.c $(t_jnlib_src) +t_timestuff_LDADD = $(t_jnlib_ldadd) + +if HAVE_W32_SYSTEM +t_w32_reg_SOURCES = t-w32-reg.c $(t_jnlib_src) +t_w32_reg_LDADD = $(t_jnlib_ldadd) +endif +==>8=================================================== + + Property changes on: trunk/common/README.jnlib ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Copied: trunk/common/argparse.c (from rev 5272, trunk/jnlib/argparse.c) =================================================================== --- trunk/common/argparse.c (rev 0) +++ trunk/common/argparse.c 2010-03-10 12:24:58 UTC (rev 5288) @@ -0,0 +1,1205 @@ +/* [argparse.c wk 17.06.97] Argument Parser for option handling + * Copyright (C) 1998, 1999, 2000, 2001, 2006 + * 2007, 2008 Free Software Foundation, Inc. + * + * This file is part of JNLIB. + * + * JNLIB is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * JNLIB is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "libjnlib-config.h" +#include "mischelp.h" +#include "stringhelp.h" +#include "logging.h" +#ifdef JNLIB_NEED_UTF8CONV +#include "utf8conv.h" +#endif +#include "argparse.h" + + + +/********************************* + * @Summary arg_parse + * #include + * + * typedef struct { + * char *argc; pointer to argc (value subject to change) + * char ***argv; pointer to argv (value subject to change) + * unsigned flags; Global flags (DO NOT CHANGE) + * int err; print error about last option + * 1 = warning, 2 = abort + * int r_opt; return option + * int r_type; type of return value (0 = no argument found) + * union { + * int ret_int; + * long ret_long + * ulong ret_ulong; + * char *ret_str; + * } r; Return values + * struct { + * int idx; + * const char *last; + * void *aliases; + * } internal; DO NOT CHANGE + * } ARGPARSE_ARGS; + * + * typedef struct { + * int short_opt; + * const char *long_opt; + * unsigned flags; + * } ARGPARSE_OPTS; + * + * int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts ); + * + * @Description + * This is my replacement for getopt(). See the example for a typical usage. + * Global flags are: + * Bit 0 : Do not remove options form argv + * Bit 1 : Do not stop at last option but return other args + * with r_opt set to -1. + * Bit 2 : Assume options and real args are mixed. + * Bit 3 : Do not use -- to stop option processing. + * Bit 4 : Do not skip the first arg. + * Bit 5 : allow usage of long option with only one dash + * Bit 6 : ignore --version + * all other bits must be set to zero, this value is modified by the + * function, so assume this is write only. + * Local flags (for each option): + * Bit 2-0 : 0 = does not take an argument + * 1 = takes int argument + * 2 = takes string argument + * 3 = takes long argument + * 4 = takes ulong argument + * Bit 3 : argument is optional (r_type will the be set to 0) + * Bit 4 : allow 0x etc. prefixed values. + * Bit 7 : this is a command and not an option + * You stop the option processing by setting opts to NULL, the function will + * then return 0. + * @Return Value + * Returns the args.r_opt or 0 if ready + * r_opt may be -2/-7 to indicate an unknown option/command. + * @See Also + * ArgExpand + * @Notes + * You do not need to process the options 'h', '--help' or '--version' + * because this function includes standard help processing; but if you + * specify '-h', '--help' or '--version' you have to do it yourself. + * The option '--' stops argument processing; if bit 1 is set the function + * continues to return normal arguments. + * To process float args or unsigned args you must use a string args and do + * the conversion yourself. + * @Example + * + * ARGPARSE_OPTS opts[] = { + * { 'v', "verbose", 0 }, + * { 'd', "debug", 0 }, + * { 'o', "output", 2 }, + * { 'c', "cross-ref", 2|8 }, + * { 'm', "my-option", 1|8 }, + * { 500, "have-no-short-option-for-this-long-option", 0 }, + * {0} }; + * ARGPARSE_ARGS pargs = { &argc, &argv, 0 } + * + * while( ArgParse( &pargs, &opts) ) { + * switch( pargs.r_opt ) { + * case 'v': opt.verbose++; break; + * case 'd': opt.debug++; break; + * case 'o': opt.outfile = pargs.r.ret_str; break; + * case 'c': opt.crf = pargs.r_type? pargs.r.ret_str:"a.crf"; break; + * case 'm': opt.myopt = pargs.r_type? pargs.r.ret_int : 1; break; + * case 500: opt.a_long_one++; break + * default : pargs.err = 1; break; -- force warning output -- + * } + * } + * if( argc > 1 ) + * log_fatal( "Too many args"); + * + */ + +typedef struct alias_def_s *ALIAS_DEF; +struct alias_def_s { + ALIAS_DEF next; + char *name; /* malloced buffer with name, \0, value */ + const char *value; /* ptr into name */ +}; + +static const char *(*strusage_handler)( int ) = NULL; + +static int set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s); +static void show_help(ARGPARSE_OPTS *opts, unsigned flags); +static void show_version(void); + + +static void +initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno ) +{ + if( !(arg->flags & (1<<15)) ) + { + /* Initialize this instance. */ + arg->internal.idx = 0; + arg->internal.last = NULL; + arg->internal.inarg = 0; + arg->internal.stopped = 0; + arg->internal.aliases = NULL; + arg->internal.cur_alias = NULL; + arg->err = 0; + arg->flags |= 1<<15; /* Mark as initialized. */ + if ( *arg->argc < 0 ) + jnlib_log_bug ("invalid argument for arg_parsee\n"); + } + + + if (arg->err) + { + /* Last option was erroneous. */ + const char *s; + + if (filename) + { + if ( arg->r_opt == ARGPARSE_UNEXPECTED_ARG ) + s = _("argument not expected"); + else if ( arg->r_opt == ARGPARSE_READ_ERROR ) + s = _("read error"); + else if ( arg->r_opt == ARGPARSE_KEYWORD_TOO_LONG ) + s = _("keyword too long"); + else if ( arg->r_opt == ARGPARSE_MISSING_ARG ) + s = _("missing argument"); + else if ( arg->r_opt == ARGPARSE_INVALID_COMMAND ) + s = _("invalid command"); + else if ( arg->r_opt == ARGPARSE_INVALID_ALIAS ) + s = _("invalid alias definition"); + else if ( arg->r_opt == ARGPARSE_OUT_OF_CORE ) + s = _("out of core"); + else + s = _("invalid option"); + jnlib_log_error ("%s:%u: %s\n", filename, *lineno, s); + } + else + { + s = arg->internal.last? arg->internal.last:"[??]"; + + if ( arg->r_opt == ARGPARSE_MISSING_ARG ) + jnlib_log_error (_("missing argument for option \"%.50s\"\n"), s); + else if ( arg->r_opt == ARGPARSE_UNEXPECTED_ARG ) + jnlib_log_error (_("option \"%.50s\" does not expect an " + "argument\n"), s ); + else if ( arg->r_opt == ARGPARSE_INVALID_COMMAND ) + jnlib_log_error (_("invalid command \"%.50s\"\n"), s); + else if ( arg->r_opt == ARGPARSE_AMBIGUOUS_OPTION ) + jnlib_log_error (_("option \"%.50s\" is ambiguous\n"), s); + else if ( arg->r_opt == ARGPARSE_AMBIGUOUS_OPTION ) + jnlib_log_error (_("command \"%.50s\" is ambiguous\n"),s ); + else if ( arg->r_opt == ARGPARSE_OUT_OF_CORE ) + jnlib_log_error ("%s\n", _("out of core\n")); + else + jnlib_log_error (_("invalid option \"%.50s\"\n"), s); + } + if ( arg->err != 1 ) + exit (2); + arg->err = 0; + } + + /* Zero out the return value union. */ + arg->r.ret_str = NULL; + arg->r.ret_long = 0; +} + + +static void +store_alias( ARGPARSE_ARGS *arg, char *name, char *value ) +{ + /* TODO: replace this dummy function with a rea one + * and fix the probelms IRIX has with (ALIAS_DEV)arg.. + * used as lvalue + */ + (void)arg; + (void)name; + (void)value; +#if 0 + ALIAS_DEF a = jnlib_xmalloc( sizeof *a ); + a->name = name; + a->value = value; + a->next = (ALIAS_DEF)arg->internal.aliases; + (ALIAS_DEF)arg->internal.aliases = a; +#endif +} + +/**************** + * Get options from a file. + * Lines starting with '#' are comment lines. + * Syntax is simply a keyword and the argument. + * Valid keywords are all keywords from the long_opt list without + * the leading dashes. The special keywords "help", "warranty" and "version" + * are not valid here. + * The special keyword "alias" may be used to store alias definitions, + * which are later expanded like long options. + * Caller must free returned strings. + * If called with FP set to NULL command line args are parse instead. + * + * Q: Should we allow the syntax + * keyword = value + * and accept for boolean options a value of 1/0, yes/no or true/false? + * Note: Abbreviation of options is here not allowed. + */ +int +optfile_parse (FILE *fp, const char *filename, unsigned *lineno, + ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts) +{ + int state, i, c; + int idx=0; + char keyword[100]; + char *buffer = NULL; + size_t buflen = 0; + int in_alias=0; + + if (!fp) /* Divert to to arg_parse() in this case. */ + return arg_parse (arg, opts); + + initialize (arg, filename, lineno); + + /* Find the next keyword. */ + state = i = 0; + for (;;) + { + c = getc (fp); + if (c == '\n' || c== EOF ) + { + if ( c != EOF ) + ++*lineno; + if (state == -1) + break; + else if (state == 2) + { + keyword[i] = 0; + for (i=0; opts[i].short_opt; i++ ) + { + if (opts[i].long_opt && !strcmp (opts[i].long_opt, keyword)) + break; + } + idx = i; + arg->r_opt = opts[idx].short_opt; + if (!opts[idx].short_opt ) + arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND) + ? ARGPARSE_INVALID_COMMAND + : ARGPARSE_INVALID_OPTION); + else if (!(opts[idx].flags & 7)) + arg->r_type = 0; /* Does not take an arg. */ + else if ((opts[idx].flags & 8) ) + arg->r_type = 0; /* Arg is optional. */ + else + arg->r_opt = ARGPARSE_MISSING_ARG; + + break; + } + else if (state == 3) + { + /* No argument found. */ + if (in_alias) + arg->r_opt = ARGPARSE_MISSING_ARG; + else if (!(opts[idx].flags & 7)) + arg->r_type = 0; /* Does not take an arg. */ + else if ((opts[idx].flags & 8)) + arg->r_type = 0; /* No optional argument. */ + else + arg->r_opt = ARGPARSE_MISSING_ARG; + + break; + } + else if (state == 4) + { + /* Has an argument. */ + if (in_alias) + { + if (!buffer) + arg->r_opt = ARGPARSE_UNEXPECTED_ARG; + else + { + char *p; + + buffer[i] = 0; + p = strpbrk (buffer, " \t"); + if (p) + { + *p++ = 0; + trim_spaces (p); + } + if (!p || !*p) + { + jnlib_free (buffer); + arg->r_opt = ARGPARSE_INVALID_ALIAS; + } + else + { + store_alias (arg, buffer, p); + } + } + } + else if (!(opts[idx].flags & 7)) + arg->r_opt = ARGPARSE_UNEXPECTED_ARG; + else + { + char *p; + + if (!buffer) + { + keyword[i] = 0; + buffer = jnlib_strdup (keyword); + if (!buffer) + arg->r_opt = ARGPARSE_OUT_OF_CORE; + } + else + buffer[i] = 0; + + if (buffer) + { + trim_spaces (buffer); + p = buffer; + if (*p == '"') + { + /* Remove quotes. */ + p++; + if (*p && p[strlen(p)-1] == '\"' ) + p[strlen(p)-1] = 0; + } + if (!set_opt_arg (arg, opts[idx].flags, p)) + jnlib_free(buffer); + } + } + break; + } + else if (c == EOF) + { + if (ferror (fp)) + arg->r_opt = ARGPARSE_READ_ERROR; + else + arg->r_opt = 0; /* EOF. */ + break; + } + state = 0; + i = 0; + } + else if (state == -1) + ; /* Skip. */ + else if (state == 0 && isascii (c) && isspace(c)) + ; /* Skip leading white space. */ + else if (state == 0 && c == '#' ) + state = 1; /* Start of a comment. */ + else if (state == 1) + ; /* Skip comments. */ + else if (state == 2 && isascii (c) && isspace(c)) + { + /* Check keyword. */ + keyword[i] = 0; + for (i=0; opts[i].short_opt; i++ ) + if (opts[i].long_opt && !strcmp (opts[i].long_opt, keyword)) + break; + idx = i; + arg->r_opt = opts[idx].short_opt; + if (!opts[idx].short_opt) + { + if (!strcmp (keyword, "alias")) + { + in_alias = 1; + state = 3; + } + else + { + arg->r_opt = ((opts[idx].flags & ARGPARSE_OPT_COMMAND) + ? ARGPARSE_INVALID_COMMAND + : ARGPARSE_INVALID_OPTION); + state = -1; /* Skip rest of line and leave. */ + } + } + else + state = 3; + } + else if (state == 3) + { + /* Skip leading spaces of the argument. */ + if (!isascii (c) || !isspace(c)) + { + i = 0; + keyword[i++] = c; + state = 4; + } + } + else if (state == 4) + { + /* Collect the argument. */ + if (buffer) + { + if (i < buflen-1) + buffer[i++] = c; + else + { + char *tmp; + size_t tmplen = buflen + 50; + + tmp = jnlib_realloc (buffer, tmplen); + if (tmp) + { + buflen = tmplen; + buffer = tmp; + buffer[i++] = c; + } + else + { + jnlib_free (buffer); + arg->r_opt = ARGPARSE_OUT_OF_CORE; + break; + } + } + } + else if (i < DIM(keyword)-1) + keyword[i++] = c; + else + { + size_t tmplen = DIM(keyword) + 50; + buffer = jnlib_malloc (tmplen); + if (buffer) + { + buflen = tmplen; + memcpy(buffer, keyword, i); + buffer[i++] = c; + } + else + { + arg->r_opt = ARGPARSE_OUT_OF_CORE; + break; + } + } + } + else if (i >= DIM(keyword)-1) + { + arg->r_opt = ARGPARSE_KEYWORD_TOO_LONG; + state = -1; /* Skip rest of line and leave. */ + } + else + { + keyword[i++] = c; + state = 2; + } + } + + return arg->r_opt; +} + + + +static int +find_long_option( ARGPARSE_ARGS *arg, + ARGPARSE_OPTS *opts, const char *keyword ) +{ + int i; + size_t n; + + (void)arg; + + /* Would be better if we can do a binary search, but it is not + possible to reorder our option table because we would mess + up our help strings - What we can do is: Build a nice option + lookup table wehn this function is first invoked */ + if( !*keyword ) + return -1; + for(i=0; opts[i].short_opt; i++ ) + if( opts[i].long_opt && !strcmp( opts[i].long_opt, keyword) ) + return i; +#if 0 + { + ALIAS_DEF a; + /* see whether it is an alias */ + for( a = args->internal.aliases; a; a = a->next ) { + if( !strcmp( a->name, keyword) ) { + /* todo: must parse the alias here */ + args->internal.cur_alias = a; + return -3; /* alias available */ + } + } + } +#endif + /* not found, see whether it is an abbreviation */ + /* aliases may not be abbreviated */ + n = strlen( keyword ); + for(i=0; opts[i].short_opt; i++ ) { + if( opts[i].long_opt && !strncmp( opts[i].long_opt, keyword, n ) ) { + int j; + for(j=i+1; opts[j].short_opt; j++ ) { + if( opts[j].long_opt + && !strncmp( opts[j].long_opt, keyword, n ) ) + return -2; /* abbreviation is ambiguous */ + } + return i; + } + } + return -1; +} + +int +arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts) +{ + int idx; + int argc; + char **argv; + char *s, *s2; + int i; + + initialize( arg, NULL, NULL ); + argc = *arg->argc; + argv = *arg->argv; + idx = arg->internal.idx; + + if (!idx && argc && !(arg->flags & ARGPARSE_FLAG_ARG0)) + { + /* Skip the first argument. */ + argc--; argv++; idx++; + } + + next_one: + if (!argc) + { + /* No more args. */ + arg->r_opt = 0; + goto leave; /* Ready. */ + } + + s = *argv; + arg->internal.last = s; + + if (arg->internal.stopped && (arg->flags & ARGPARSE_FLAG_ALL)) + { + arg->r_opt = ARGPARSE_IS_ARG; /* Not an option but an argument. */ + arg->r_type = 2; + arg->r.ret_str = s; + argc--; argv++; idx++; /* set to next one */ + } + else if( arg->internal.stopped ) + { + arg->r_opt = 0; + goto leave; /* Ready. */ + } + else if ( *s == '-' && s[1] == '-' ) + { + /* Long option. */ + char *argpos; + + arg->internal.inarg = 0; + if (!s[2] && !(arg->flags & ARGPARSE_FLAG_NOSTOP)) + { + /* Stop option processing. */ + arg->internal.stopped = 1; + argc--; argv++; idx++; + goto next_one; + } + + argpos = strchr( s+2, '=' ); + if ( argpos ) + *argpos = 0; + i = find_long_option ( arg, opts, s+2 ); + if ( argpos ) + *argpos = '='; + + if ( i < 0 && !strcmp ( "help", s+2) ) + show_help (opts, arg->flags); + else if ( i < 0 && !strcmp ( "version", s+2) ) + { + if (!(arg->flags & ARGPARSE_FLAG_NOVERSION)) + { + show_version (); + exit(0); + } + } + else if ( i < 0 && !strcmp( "warranty", s+2)) + { + puts ( strusage (16) ); + exit (0); + } + else if ( i < 0 && !strcmp( "dump-options", s+2) ) + { + for (i=0; opts[i].short_opt; i++ ) + { + if ( opts[i].long_opt ) + printf ("--%s\n", opts[i].long_opt); + } + fputs ("--dump-options\n--help\n--version\n--warranty\n", stdout); + exit (0); + } + + if ( i == -2 ) + arg->r_opt = ARGPARSE_AMBIGUOUS_OPTION; + else if ( i == -1 ) + { + arg->r_opt = ARGPARSE_INVALID_OPTION; + arg->r.ret_str = s+2; + } + else + arg->r_opt = opts[i].short_opt; + if ( i < 0 ) + ; + else if ( (opts[i].flags & 0x07) ) + { + if ( argpos ) + { + s2 = argpos+1; + if ( !*s2 ) + s2 = NULL; + } + else + s2 = argv[1]; + if ( !s2 && (opts[i].flags & ARGPARSE_OPT_OPTIONAL) ) + { + arg->r_type = ARGPARSE_TYPE_NONE; /* Argument is optional. */ + } + else if ( !s2 ) + { + arg->r_opt = ARGPARSE_MISSING_ARG; + } + else if ( !argpos && *s2 == '-' + && (opts[i].flags & ARGPARSE_OPT_OPTIONAL) ) + { + /* The argument is optional and the next seems to be an + option. We do not check this possible option but + assume no argument */ + arg->r_type = ARGPARSE_TYPE_NONE; + } + else + { + set_opt_arg (arg, opts[i].flags, s2); + if ( !argpos ) + { + argc--; argv++; idx++; /* Skip one. */ + } + } + } + else + { + /* Does not take an argument. */ + if ( argpos ) + arg->r_type = ARGPARSE_UNEXPECTED_ARG; + else + arg->r_type = 0; + } + argc--; argv++; idx++; /* Set to next one. */ + } + else if ( (*s == '-' && s[1]) || arg->internal.inarg ) + { + /* Short option. */ + int dash_kludge = 0; + + i = 0; + if ( !arg->internal.inarg ) + { + arg->internal.inarg++; + if ( (arg->flags & ARGPARSE_FLAG_ONEDASH) ) + { + for (i=0; opts[i].short_opt; i++ ) + if ( opts[i].long_opt && !strcmp (opts[i].long_opt, s+1)) + { + dash_kludge = 1; + break; + } + } + } + s += arg->internal.inarg; + + if (!dash_kludge ) + { + for (i=0; opts[i].short_opt; i++ ) + if ( opts[i].short_opt == *s ) + break; + } + + if ( !opts[i].short_opt && ( *s == 'h' || *s == '?' ) ) + show_help (opts, arg->flags); + + arg->r_opt = opts[i].short_opt; + if (!opts[i].short_opt ) + { + arg->r_opt = (opts[i].flags & ARGPARSE_OPT_COMMAND)? + ARGPARSE_INVALID_COMMAND:ARGPARSE_INVALID_OPTION; + arg->internal.inarg++; /* Point to the next arg. */ + arg->r.ret_str = s; + } + else if ( (opts[i].flags & 7) ) + { + if ( s[1] && !dash_kludge ) + { + s2 = s+1; + set_opt_arg (arg, opts[i].flags, s2); + } + else + { + s2 = argv[1]; + if ( !s2 && (opts[i].flags & ARGPARSE_OPT_OPTIONAL) ) + { + arg->r_type = ARGPARSE_TYPE_NONE; + } + else if ( !s2 ) + { + arg->r_opt = ARGPARSE_MISSING_ARG; + } + else if ( *s2 == '-' && s2[1] + && (opts[i].flags & ARGPARSE_OPT_OPTIONAL) ) + { + /* The argument is optional and the next seems to + be an option. We do not check this possible + option but assume no argument. */ + arg->r_type = ARGPARSE_TYPE_NONE; + } + else + { + set_opt_arg (arg, opts[i].flags, s2); + argc--; argv++; idx++; /* Skip one. */ + } + } + s = "x"; /* This is so that !s[1] yields false. */ + } + else + { + /* Does not take an argument. */ + arg->r_type = ARGPARSE_TYPE_NONE; + arg->internal.inarg++; /* Point to the next arg. */ + } + if ( !s[1] || dash_kludge ) + { + /* No more concatenated short options. */ + arg->internal.inarg = 0; + argc--; argv++; idx++; + } + } + else if ( arg->flags & ARGPARSE_FLAG_MIXED ) + { + arg->r_opt = ARGPARSE_IS_ARG; + arg->r_type = 2; + arg->r.ret_str = s; + argc--; argv++; idx++; /* Set to next one. */ + } + else + { + arg->internal.stopped = 1; /* Stop option processing. */ + goto next_one; + } + + leave: + *arg->argc = argc; + *arg->argv = argv; + arg->internal.idx = idx; + return arg->r_opt; +} + + + +static int +set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s) +{ + int base = (flags & 16)? 0 : 10; + + switch ( (arg->r_type = (flags & 7)) ) + { + case ARGPARSE_TYPE_INT: + arg->r.ret_int = (int)strtol(s,NULL,base); + return 0; + case ARGPARSE_TYPE_LONG: + arg->r.ret_long= strtol(s,NULL,base); + return 0; + case ARGPARSE_TYPE_ULONG: + arg->r.ret_ulong= strtoul(s,NULL,base); + return 0; + case ARGPARSE_TYPE_STRING: + default: + arg->r.ret_str = s; + return 1; + } +} + + +static size_t +long_opt_strlen( ARGPARSE_OPTS *o ) +{ + size_t n = strlen (o->long_opt); + + if ( o->description && *o->description == '|' ) + { + const char *s; +#ifdef JNLIB_NEED_UTF8CONV + int is_utf8 = is_native_utf8 (); +#endif + + s=o->description+1; + if ( *s != '=' ) + n++; + /* For a (mostly) correct length calculation we exclude + continuation bytes (10xxxxxx) if we are on a native utf8 + terminal. */ + for (; *s && *s != '|'; s++ ) +#ifdef JNLIB_NEED_UTF8CONV + if ( is_utf8 && (*s&0xc0) != 0x80 ) +#endif + n++; + } + return n; +} + + +/**************** + * Print formatted help. The description string has some special + * meanings: + * - A description string which is "@" suppresses help output for + * this option + * - a description,ine which starts with a '@' and is followed by + * any other characters is printed as is; this may be used for examples + * ans such. + * - A description which starts with a '|' outputs the string between this + * bar and the next one as arguments of the long option. + */ +static void +show_help (ARGPARSE_OPTS *opts, unsigned int flags) +{ + const char *s; + + show_version (); + putchar ('\n'); + s = strusage(41); + puts (s); + if ( opts[0].description ) + { + /* Auto format the option description. */ + int i,j, indent; + + /* Get max. length of long options. */ + for (i=indent=0; opts[i].short_opt; i++ ) + { + if ( opts[i].long_opt ) + if ( !opts[i].description || *opts[i].description != '@' ) + if ( (j=long_opt_strlen(opts+i)) > indent && j < 35 ) + indent = j; + } + + /* Example: " -v, --verbose Viele Sachen ausgeben" */ + indent += 10; + if ( *opts[0].description != '@' ) + puts ("Options:"); + for (i=0; opts[i].short_opt; i++ ) + { + s = _( opts[i].description ); + if ( s && *s== '@' && !s[1] ) /* Hide this line. */ + continue; + if ( s && *s == '@' ) /* Unindented comment only line. */ + { + for (s++; *s; s++ ) + { + if ( *s == '\n' ) + { + if( s[1] ) + putchar('\n'); + } + else + putchar(*s); + } + putchar('\n'); + continue; + } + + j = 3; + if ( opts[i].short_opt < 256 ) + { + printf (" -%c", opts[i].short_opt); + if ( !opts[i].long_opt ) + { + if (s && *s == '|' ) + { + putchar (' '); j++; + for (s++ ; *s && *s != '|'; s++, j++ ) + putchar (*s); + if ( *s ) + s++; + } + } + } + else + fputs(" ", stdout); + if ( opts[i].long_opt ) + { + j += printf ("%c --%s", opts[i].short_opt < 256?',':' ', + opts[i].long_opt ); + if (s && *s == '|' ) + { + if ( *++s != '=' ) + { + putchar(' '); + j++; + } + for ( ; *s && *s != '|'; s++, j++ ) + putchar(*s); + if ( *s ) + s++; + } + fputs (" ", stdout); + j += 3; + } + for (;j < indent; j++ ) + putchar(' '); + if ( s ) + { + if ( *s && j > indent ) + { + putchar('\n'); + for (j=0;j < indent; j++ ) + putchar (' '); + } + for (; *s; s++ ) + { + if ( *s == '\n' ) + { + if ( s[1] ) + { + putchar ('\n'); + for (j=0; j < indent; j++ ) + putchar (' '); + } + } + else + putchar (*s); + } + } + putchar ('\n'); + } + if ( (flags & ARGPARSE_FLAG_ONEDASH) ) + puts ("\n(A single dash may be used instead of the double ones)"); + } + if ( (s=strusage(19)) ) + { + /* bug reports to ... */ + char *s2; + + putchar('\n'); + s2 = strstr (s, "@EMAIL@"); + if (s2) + { + if (s2-s) + fwrite (s, s2-s, 1, stdout); +#ifdef PACKAGE_BUGREPORT + fputs (PACKAGE_BUGREPORT, stdout); +#else + fputs ("bug at example.org", stdout); +#endif + s2 += 7; + if (*s2) + fputs (s2, stdout); + } + else + fputs(s, stdout); + } + fflush(stdout); + exit(0); +} + +static void +show_version () +{ + const char *s; + int i; + + /* Version line. */ + fputs (strusage (11), stdout); + if ((s=strusage (12))) + printf (" (%s)", s ); + printf (" %s\n", strusage (13) ); + /* Additional version lines. */ + for (i=20; i < 30; i++) + if ((s=strusage (i))) + printf ("%s\n", s ); + /* Copyright string. */ + if( (s=strusage (14)) ) + printf("%s\n", s ); + /* Licence string. */ + if( (s=strusage (10)) ) + printf("%s\n", s ); + /* Copying conditions. */ + if ( (s=strusage(15)) ) + fputs (s, stdout); + /* Thanks. */ + if ((s=strusage(18))) + fputs (s, stdout); + /* Additional program info. */ + for (i=30; i < 40; i++ ) + if ( (s=strusage (i)) ) + fputs (s, stdout); + fflush (stdout); +} + + +void +usage (int level) +{ + const char *p; + + if (!level) + { + fprintf(stderr,"%s %s; %s\n", strusage(11), strusage(13), strusage (14)); + fflush (stderr); + } + else if (level == 1) + { + p = strusage (40); + fputs (p, stderr); + if (*p && p[strlen(p)] != '\n') + putc ('\n', stderr); + exit (2); + } + else if (level == 2) + { + puts (strusage(41)); + exit (0); + } +} + +/* Level + * 0: Print copyright string to stderr + * 1: Print a short usage hint to stderr and terminate + * 2: Print a long usage hint to stdout and terminate + * 10: Return license info string + * 11: Return the name of the program + * 12: Return optional name of package which includes this program. + * 13: version string + * 14: copyright string + * 15: Short copying conditions (with LFs) + * 16: Long copying conditions (with LFs) + * 17: Optional printable OS name + * 18: Optional thanks list (with LFs) + * 19: Bug report info + *20..29: Additional lib version strings. + *30..39: Additional program info (with LFs) + * 40: short usage note (with LF) + * 41: long usage note (with LF) + */ +const char * +strusage( int level ) +{ + const char *p = strusage_handler? strusage_handler(level) : NULL; + + if ( p ) + return p; + + switch ( level ) + { + case 10: p = ("License GPLv3+: GNU GPL version 3 or later " + ""); + break; + case 11: p = "foo"; break; + case 13: p = "0.0"; break; + case 14: p = "Copyright (C) 2010 Free Software Foundation, Inc."; break; + case 15: p = +"This is free software: you are free to change and redistribute it.\n" +"There is NO WARRANTY, to the extent permitted by law.\n"; + break; + case 16: p = +"This is free software; you can redistribute it and/or modify\n" +"it under the terms of the GNU General Public License as published by\n" +"the Free Software Foundation; either version 3 of the License, or\n" +"(at your option) any later version.\n\n" +"It is distributed in the hope that it will be useful,\n" +"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" From cvs at cvs.gnupg.org Wed Mar 10 18:22:23 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 10 Mar 2010 18:22:23 +0100 Subject: [svn] GnuPG - r5289 - trunk/common Message-ID: Author: wk Date: 2010-03-10 18:22:23 +0100 (Wed, 10 Mar 2010) New Revision: 5289 Modified: trunk/common/ChangeLog trunk/common/estream.c trunk/common/estream.h trunk/common/logging.c trunk/common/logging.h Log: Change logging to use estream. The makes logging to a socket also work on Solaris etc. Further changes required.. This is just a first step. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-10 12:24:58 UTC (rev 5288) +++ trunk/common/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) @@ -1,5 +1,27 @@ 2010-03-10 Werner Koch + * estream.c (es_func_fp_read, es_func_fp_write, es_func_fp_seek) + (es_func_fp_destroy): Allow a NULL FP to implement a dummy stream. + (do_fpopen): Ditto. + (es_vfprintf_unlocked): New. + (es_fprintf_unlocked): Make public. + (es_fputs_unlocked): New. + + * logging.h: Replace FILE* by estream_t. + * logging.c: Remove USE_FUNWRITER cpp conditional because we now + use estream. + (my_funopen_hook_ret_t, my_funopen_hook_size_t): Replace by + ssize_t. + (log_get_stream): Change to return an estream_t. + (set_file_fd): Always close the log stream because it can't be + assigned to stderr or stdout directly. Use a dummy estream as + last resort log stream. + (log_test_fd, log_get_fd): Use es_fileno. + (log_get_stream): Assert that we have a log stream. + (do_logv): Use estream functions and lock the output. + +2010-03-10 Werner Koch + * util.h: Replace jnlib path part by common. (snprintf): Use the replacement macro on all platforms. Modified: trunk/common/estream.c =================================================================== --- trunk/common/estream.c 2010-03-10 12:24:58 UTC (rev 5288) +++ trunk/common/estream.c 2010-03-10 17:22:23 UTC (rev 5289) @@ -869,7 +869,10 @@ estream_cookie_fp_t file_cookie = cookie; ssize_t bytes_read; - bytes_read = fread (buffer, 1, size, file_cookie->fp); + if (file_cookie->fp) + bytes_read = fread (buffer, 1, size, file_cookie->fp); + else + bytes_read = 0; if (!bytes_read && ferror (file_cookie->fp)) return -1; return bytes_read; @@ -883,7 +886,11 @@ estream_cookie_fp_t file_cookie = cookie; size_t bytes_written; - bytes_written = fwrite (buffer, 1, size, file_cookie->fp); + + if (file_cookie->fp) + bytes_written = fwrite (buffer, 1, size, file_cookie->fp); + else + bytes_written = size; /* Successfully written to the bit bucket. */ if (bytes_written != size) return -1; return bytes_written; @@ -896,17 +903,25 @@ estream_cookie_fp_t file_cookie = cookie; long int offset_new; + if (!file_cookie->fp) + { + _set_errno (ESPIPE); + return -1; + } + if ( fseek (file_cookie->fp, (long int)*offset, whence) ) { - fprintf (stderr, "\nfseek failed: errno=%d (%s)\n", errno,strerror (errno)); - return -1; + /* fprintf (stderr, "\nfseek failed: errno=%d (%s)\n", */ + /* errno,strerror (errno)); */ + return -1; } offset_new = ftell (file_cookie->fp); if (offset_new == -1) { - fprintf (stderr, "\nftell failed: errno=%d (%s)\n", errno,strerror (errno)); - return -1; + /* fprintf (stderr, "\nftell failed: errno=%d (%s)\n", */ + /* errno,strerror (errno)); */ + return -1; } *offset = offset_new; return 0; @@ -921,8 +936,13 @@ if (fp_cookie) { - fflush (fp_cookie->fp); - err = fp_cookie->no_close? 0 : fclose (fp_cookie->fp); + if (fp_cookie->fp) + { + fflush (fp_cookie->fp); + err = fp_cookie->no_close? 0 : fclose (fp_cookie->fp); + } + else + err = 0; mem_free (fp_cookie); } else @@ -2268,13 +2288,14 @@ if (err) goto out; - fflush (fp); + if (fp) + fflush (fp); err = es_func_fp_create (&cookie, fp, modeflags, no_close); if (err) goto out; - + create_called = 1; - err = es_create (&stream, cookie, fileno (fp), estream_functions_fp, + err = es_create (&stream, cookie, fp? fileno (fp):-1, estream_functions_fp, modeflags); out: @@ -2738,6 +2759,17 @@ int +es_fputs_unlocked (const char *ES__RESTRICT s, estream_t ES__RESTRICT stream) +{ + size_t length; + int err; + + length = strlen (s); + err = es_writen (stream, s, length, NULL); + return err ? EOF : 0; +} + +int es_fputs (const char *ES__RESTRICT s, estream_t ES__RESTRICT stream) { size_t length; @@ -2932,6 +2964,15 @@ int +es_vfprintf_unlocked (estream_t ES__RESTRICT stream, + const char *ES__RESTRICT format, + va_list ap) +{ + return es_print (stream, format, ap); +} + + +int es_vfprintf (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format, va_list ap) { @@ -2945,9 +2986,9 @@ } -static int +int es_fprintf_unlocked (estream_t ES__RESTRICT stream, - const char *ES__RESTRICT format, ...) + const char *ES__RESTRICT format, ...) { int ret; Modified: trunk/common/estream.h =================================================================== --- trunk/common/estream.h 2010-03-10 12:24:58 UTC (rev 5288) +++ trunk/common/estream.h 2010-03-10 17:22:23 UTC (rev 5289) @@ -113,11 +113,14 @@ #define es_fwrite _ESTREAM_PREFIX(es_fwrite) #define es_fgets _ESTREAM_PREFIX(es_fgets) #define es_fputs _ESTREAM_PREFIX(es_fputs) +#define es_fputs_unlocked _ESTREAM_PREFIX(es_fputs_unlocked) #define es_getline _ESTREAM_PREFIX(es_getline) #define es_read_line _ESTREAM_PREFIX(es_read_line) #define es_free _ESTREAM_PREFIX(es_free) -#define es_fprf _ESTREAM_PREFIX(es_fprf) -#define es_vfprf _ESTREAM_PREFIX(es_vfprf) +#define es_fprintf _ESTREAM_PREFIX(es_fprintf) +#define es_fprintf_unlocked _ESTREAM_PREFIX(es_fprintf_unlocked) +#define es_vfprintf _ESTREAM_PREFIX(es_vfprint) +#define es_vfprintf_unlocked _ESTREAM_PREFIX(es_vfprint_unlocked) #define es_setvbuf _ESTREAM_PREFIX(es_setvbuf) #define es_setbuf _ESTREAM_PREFIX(es_setbuf) #define es_tmpfile _ESTREAM_PREFIX(es_tmpfile) @@ -311,6 +314,8 @@ char *es_fgets (char *ES__RESTRICT s, int n, estream_t ES__RESTRICT stream); int es_fputs (const char *ES__RESTRICT s, estream_t ES__RESTRICT stream); +int es_fputs_unlocked (const char *ES__RESTRICT s, + estream_t ES__RESTRICT stream); ssize_t es_getline (char *ES__RESTRICT *ES__RESTRICT lineptr, size_t *ES__RESTRICT n, @@ -323,9 +328,17 @@ int es_fprintf (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format, ...) _ESTREAM_GCC_A_PRINTF(2,3); +int es_fprintf_unlocked (estream_t ES__RESTRICT stream, + const char *ES__RESTRICT format, ...) + _ESTREAM_GCC_A_PRINTF(2,3); + int es_vfprintf (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format, va_list ap) _ESTREAM_GCC_A_PRINTF(2,0); +int es_vfprintf_unlocked (estream_t ES__RESTRICT stream, + const char *ES__RESTRICT format, va_list ap) + _ESTREAM_GCC_A_PRINTF(2,0); + int es_setvbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf, int mode, size_t size); void es_setbuf (estream_t ES__RESTRICT stream, char *ES__RESTRICT buf); Modified: trunk/common/logging.c =================================================================== --- trunk/common/logging.c 2010-03-10 12:24:58 UTC (rev 5288) +++ trunk/common/logging.c 2010-03-10 17:22:23 UTC (rev 5289) @@ -1,6 +1,6 @@ /* logging.c - Useful logging functions - * Copyright (C) 1998, 1999, 2000, 2001, 2003, - * 2004, 2005, 2006, 2009 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, + * 2009, 2010 Free Software Foundation, Inc. * * This file is part of JNLIB. * @@ -43,20 +43,8 @@ #include "libjnlib-config.h" #include "logging.h" -#if defined (HAVE_FOPENCOOKIE) || defined (HAVE_FUNOPEN) -#define USE_FUNWRITER 1 -#endif -#ifdef HAVE_FOPENCOOKIE -typedef ssize_t my_funopen_hook_ret_t; -typedef size_t my_funopen_hook_size_t; -#else -typedef int my_funopen_hook_ret_t; -typedef int my_funopen_hook_size_t; -#endif - - -static FILE *logstream; +static estream_t logstream; static int log_socket = -1; static char prefix_buffer[80]; static int with_time; @@ -86,10 +74,10 @@ } -/* The follwing 3 functions are used by funopen to write logs to a - socket. */ -#ifdef USE_FUNWRITER -struct fun_cookie_s { +/* The following 3 functions are used by es_fopencookie to write logs + to a socket. */ +struct fun_cookie_s +{ int fd; int quiet; int want_socket; @@ -97,6 +85,7 @@ char name[1]; }; + /* Write NBYTES of BUFFER to file descriptor FD. */ static int writen (int fd, const void *buffer, size_t nbytes) @@ -120,8 +109,8 @@ } -static my_funopen_hook_ret_t -fun_writer (void *cookie_arg, const char *buffer, my_funopen_hook_size_t size) +static ssize_t +fun_writer (void *cookie_arg, const void *buffer, size_t size) { struct fun_cookie_s *cookie = cookie_arg; @@ -191,7 +180,7 @@ log_socket = cookie->fd; if (cookie->fd != -1 && !writen (cookie->fd, buffer, size)) - return (my_funopen_hook_ret_t)size; /* Okay. */ + return (ssize_t)size; /* Okay. */ if (!running_detached && cookie->fd != -1 && isatty (fileno (stderr))) @@ -210,9 +199,10 @@ log_socket = -1; } - return (my_funopen_hook_ret_t)size; + return (ssize_t)size; } + static int fun_closer (void *cookie_arg) { @@ -224,26 +214,21 @@ log_socket = -1; return 0; } -#endif /*USE_FUNWRITER*/ - /* Common function to either set the logging to a file or a file descriptor. */ static void set_file_fd (const char *name, int fd) { - FILE *fp; + estream_t fp; int want_socket; -#ifdef USE_FUNWRITER struct fun_cookie_s *cookie; -#endif /* Close an open log stream. */ if (logstream) { - if (logstream != stderr && logstream != stdout) - fclose (logstream); + es_fclose (logstream); logstream = NULL; } @@ -266,7 +251,7 @@ } /* Setup a new stream. */ -#ifdef USE_FUNWRITER + /* The xmalloc below is justified because we can expect that this function is called only during initialization and there is no easy way out of this error condition. */ @@ -288,55 +273,44 @@ } log_socket = cookie->fd; -#ifdef HAVE_FOPENCOOKIE { - cookie_io_functions_t io = { NULL }; - io.write = fun_writer; - io.close = fun_closer; + es_cookie_io_functions_t io = { NULL }; + io.func_write = fun_writer; + io.func_close = fun_closer; - fp = fopencookie (cookie, "w", io); + fp = es_fopencookie (cookie, "w", io); } -#else /*!HAVE_FOPENCOOKIE*/ - fp = funopen (cookie, NULL, fun_writer, NULL, fun_closer); -#endif /*!HAVE_FOPENCOOKIE*/ -#else /*!USE_FUNWRITER*/ - - /* The system does not feature custom streams. Thus fallback to - plain stdio. */ - if (want_socket) - { - fprintf (stderr, "system does not support logging to a socket - " - "using stderr\n"); - fp = stderr; - } - else if (name) - fp = fopen (name, "a"); - else if (fd == 1) - fp = stdout; - else if (fd == 2) - fp = stderr; - else - fp = fdopen (fd, "a"); - - log_socket = -1; - -#endif /*!USE_FUNWRITER*/ - - /* On error default to stderr. */ + /* On error default to a stderr based estream. */ if (!fp) { - if (name) - fprintf (stderr, "failed to open log file `%s': %s\n", - name, strerror(errno)); + fp = es_fpopen (stderr, "a"); + if (fp) + { + if (name) + es_fprintf (fp, "failed to open log file `%s': %s\n", + name, strerror (errno)); + else + es_fprintf (fp, "failed to fdopen file descriptor %d: %s\n", + fd, strerror (errno)); + } else - fprintf (stderr, "failed to fdopen file descriptor %d: %s\n", - fd, strerror(errno)); - /* We need to make sure that there is a log stream. We use stderr. */ - fp = stderr; + { + fprintf (stderr, "failed to use stderr as log stream: %s\n", + strerror (errno)); + /* No way to log something. Create a dummy estream so that + there is something we can use. */ + fp = es_fpopen (NULL, "a"); + if (!fp) + { + fprintf (stderr, "fatal: failed to open dummy stream: %s\n", + strerror (errno)); + abort(); + } + } } - else - setvbuf (fp, NULL, _IOLBF, 0); + + es_setvbuf (fp, NULL, _IOLBF, 0); logstream = fp; @@ -412,13 +386,13 @@ /* This function returns true if the file descriptor FD is in use for logging. This is preferable over a test using log_get_fd in that - it allows the logging code to use more then one file descriptor. */ + it allows the logging code to use more then one file descriptor. */ int log_test_fd (int fd) { if (logstream) { - int tmp = fileno (logstream); + int tmp = es_fileno (logstream); if ( tmp != -1 && tmp == fd) return 1; } @@ -430,16 +404,14 @@ int log_get_fd () { - return fileno(logstream?logstream:stderr); + return logstream? es_fileno(logstream) : -1; } -FILE * +estream_t log_get_stream () { - /* FIXME: We should not return stderr here but initialize the log - stream properly. This might break more things than using stderr, - though */ - return logstream?logstream:stderr; + assert (logstream); + return logstream; } static void @@ -451,8 +423,9 @@ assert (logstream); } + es_flockfile (logstream); if (missing_lf && level != JNLIB_LOG_CONT) - putc('\n', logstream ); + es_putc_unlocked ('\n', logstream ); missing_lf = 0; if (level != JNLIB_LOG_CONT) @@ -464,28 +437,28 @@ time_t atime = time (NULL); tp = localtime (&atime); - fprintf (logstream, "%04d-%02d-%02d %02d:%02d:%02d ", - 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, - tp->tm_hour, tp->tm_min, tp->tm_sec ); + es_fprintf_unlocked (logstream, "%04d-%02d-%02d %02d:%02d:%02d ", + 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, + tp->tm_hour, tp->tm_min, tp->tm_sec ); } if (with_prefix || force_prefixes) - fputs (prefix_buffer, logstream); + es_fputs_unlocked (prefix_buffer, logstream); if (with_pid || force_prefixes) { if (get_tid_callback) - fprintf (logstream, "[%u.%lx]", - (unsigned int)getpid (), get_tid_callback ()); + es_fprintf_unlocked (logstream, "[%u.%lx]", + (unsigned int)getpid (), get_tid_callback ()); else - fprintf (logstream, "[%u]", (unsigned int)getpid ()); + es_fprintf_unlocked (logstream, "[%u]", (unsigned int)getpid ()); } if (!with_time || force_prefixes) - putc (':', logstream); + es_putc_unlocked (':', logstream); /* A leading backspace suppresses the extra space so that we can correctly output, programname, filename and linenumber. */ if (fmt && *fmt == '\b') fmt++; else - putc (' ', logstream); + es_putc_unlocked (' ', logstream); } switch (level) @@ -495,38 +468,40 @@ case JNLIB_LOG_INFO: break; case JNLIB_LOG_WARN: break; case JNLIB_LOG_ERROR: break; - case JNLIB_LOG_FATAL: fputs("Fatal: ",logstream ); break; - case JNLIB_LOG_BUG: fputs("Ohhhh jeeee: ", logstream); break; - case JNLIB_LOG_DEBUG: fputs("DBG: ", logstream ); break; - default: fprintf(logstream,"[Unknown log level %d]: ", level ); break; + case JNLIB_LOG_FATAL: es_fputs_unlocked ("Fatal: ",logstream ); break; + case JNLIB_LOG_BUG: es_fputs_unlocked ("Ohhhh jeeee: ", logstream); break; + case JNLIB_LOG_DEBUG: es_fputs_unlocked ("DBG: ", logstream ); break; + default: + es_fprintf_unlocked (logstream,"[Unknown log level %d]: ", level); + break; } - if (fmt) { - vfprintf(logstream,fmt,arg_ptr) ; + es_vfprintf_unlocked (logstream, fmt, arg_ptr); if (*fmt && fmt[strlen(fmt)-1] != '\n') missing_lf = 1; -#ifdef HAVE_W32_SYSTEM - else - fflush (logstream); -#endif } if (level == JNLIB_LOG_FATAL) { if (missing_lf) - putc('\n', logstream ); - exit(2); + es_putc_unlocked ('\n', logstream); + es_funlockfile (logstream); + exit (2); } - if (level == JNLIB_LOG_BUG) + else if (level == JNLIB_LOG_BUG) { if (missing_lf) - putc('\n', logstream ); - abort(); + es_putc_unlocked ('\n', logstream ); + es_funlockfile (logstream); + abort (); } + else + es_funlockfile (logstream); } + static void do_log( int level, const char *fmt, ... ) { Modified: trunk/common/logging.h =================================================================== --- trunk/common/logging.h 2010-03-10 12:24:58 UTC (rev 5288) +++ trunk/common/logging.h 2010-03-10 17:22:23 UTC (rev 5289) @@ -1,5 +1,6 @@ /* logging.h - * Copyright (C) 1999, 2000, 2001, 2004, 2006 Free Software Foundation, Inc. + * Copyright (C) 1999, 2000, 2001, 2004, 2006, + * 2010 Free Software Foundation, Inc. * * This file is part of JNLIB. * @@ -21,6 +22,7 @@ #define LIBJNLIB_LOGGING_H #include +#include "estream.h" #include "mischelp.h" /* Flag values for log_set_prefix. */ @@ -38,7 +40,7 @@ const char *log_get_prefix (unsigned int *flags); int log_test_fd (int fd); int log_get_fd(void); -FILE *log_get_stream (void); +estream_t log_get_stream (void); #ifdef JNLIB_GCC_M_FUNCTION void bug_at( const char *file, int line, const char *func ) JNLIB_GCC_A_NR; From cvs at cvs.gnupg.org Thu Mar 11 13:00:11 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Thu, 11 Mar 2010 13:00:11 +0100 Subject: [svn] assuan - r360 - in trunk: . doc src Message-ID: Author: wk Date: 2010-03-11 13:00:10 +0100 (Thu, 11 Mar 2010) New Revision: 360 Modified: trunk/NEWS trunk/doc/assuan.texi trunk/src/ChangeLog trunk/src/assuan-buffer.c trunk/src/assuan-defs.h trunk/src/assuan-logging.c trunk/src/assuan.c trunk/src/assuan.h trunk/src/debug.c trunk/src/vasprintf.c Log: Cleaned up the logging Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/ChangeLog 2010-03-11 12:00:10 UTC (rev 360) @@ -1,3 +1,22 @@ +2010-03-11 Werner Koch + + * assuan-defs.h [!HAVE_VASPRINTF]: Add macros vasprintf and asprintf. + + * vasprintf.c (asprintf): Rename to _assuan_asprintf. + (vasprintf): Rename to _assuan_vasprintf. + + * assuan.h (ASSUAN_LOG_CONTROL): New. + * assuan-logging.c (assuan_set_assuan_log_stream): Default to + ASSUAN_LOG_CONTROL. + (_assuan_log_print_buffer): Remove. + (_assuan_log_control_channel): New. + (assuan_set_assuan_log_stream): Factor envvar code out to .. + (_assuan_init_log_envvars): .. New. + * assuan.c (assuan_set_log_cb): Call _assuan_init_log_envvars. + * assuan-buffer.c (_assuan_read_line, _assuan_write_line) + (assuan_write_line, _assuan_cookie_write_data) + (_assuan_cookie_write_flush): Use _assuan_log_control_channel. + 2010-03-05 Werner Koch * gpgcemgr.c: Add options to register a device and activate it. @@ -370,7 +389,7 @@ * assuan.c (assuan_set_system_hooks): New function. (assuan_new_ext): Initialize CTX->system. (assuan_release): Always output trace message. - + * assuan-error.c (_assuan_error_is_eagain): Add ctx argument, pass along to _assuan_usleep. * assuan-inquire.c assuan-listen.c, assuan-socket-server.c, @@ -424,7 +443,7 @@ (sock_ctx): New singleton. (assuan_sock_init, assuan_sock_deinit): New functions to initialize and deinitialize the singleton. - + 2009-10-14 Werner Koch * assuan-defs.h (assuan_context_s): Add field CURRENT_CMD_NAME. @@ -725,9 +744,9 @@ (_assuan_io_read, _assuan_simple_read): Add hook feature. (do_io_write): Take all code from _assuan_io_write. (_assuan_io_write, _assuan_simple_write): Add hook feature. - * assuan-io-pth.c (_assuan_simple_read, _assuan_simple_write) + * assuan-io-pth.c (_assuan_simple_read, _assuan_simple_write) (_assuan_io_read, _assuan_io_write): Add hook feature. - + 2007-10-05 Marcus Brinkmann * assuan.h (_assuan_error_is_eagain): Add prefix macro. @@ -812,7 +831,7 @@ * assuan-inquire.c (assuan_inquire_ext): If MAXLEN is 0, still initialize MEMBUF. - + * assuan-inquire.c (_assuan_inquire_ext_cb): Clear CTX->in_inquire before invoking callback and returning. @@ -867,7 +886,7 @@ (_assuan_inquire_ext_cb, assuan_inquire_ext): New functions. * assuan-pipe-server.c (_assuan_release_context): Call _assuan_inquire_release. - + 2007-07-12 Werner Koch * assuan.h (assuan_fd_t): New. @@ -886,7 +905,7 @@ * assuan-io.c (_assuan_simple_write): Return EPIPE on a closed pipe. (_assuan_simple_read): Likewise - + 2007-07-08 Marcus Brinkmann * assuan-defs.h (struct assuan_context_s): Have full peercred @@ -912,7 +931,7 @@ 2007-06-18 Werner Koch - * assuan-logging.c (load_libgpg_error, _assuan_gpg_strerror_r) + * assuan-logging.c (load_libgpg_error, _assuan_gpg_strerror_r) (_assuan_gpg_strsource): New. * assuan-handler.c (process_request) [W32]: Use these new functions for human understable error codes. @@ -932,7 +951,7 @@ * assuan-io-pth.c: Include sys/socket.h only if available. Remove double inclusion of sys/wait.h - + * assuan-pipe-connect.c (build_w32_commandline): Make ARGV const. * assuan-pipe-server.c (is_valid_socket) [W32]: Do not define. @@ -985,7 +1004,7 @@ * libassuan.m4 (AM_CHECK_LIBASSUAN): New. - * assuan-handler.c (assuan_register_post_cmd_notify) + * assuan-handler.c (assuan_register_post_cmd_notify) (assuan_register_post_cmd_notify): New. * assuan-util.c (assuan_set_io_monitor): New. * assuan-buffer.c (_assuan_read_line): Use it. @@ -1111,9 +1130,9 @@ * assuan-domain-server.c: Removed. * assuan-domain-connect.c: Renamed to .. * assuan-uds.c: this. - (domain_reader, domain_writer, domain_sendfd, domain_receivefd) - (assuan_domain_connect, _assuan_domain_init): Removed. - (uds_reader, uds_writer, uds_sendfd, uds_receivefd) + (domain_reader, domain_writer, domain_sendfd, domain_receivefd) + (assuan_domain_connect, _assuan_domain_init): Removed. + (uds_reader, uds_writer, uds_sendfd, uds_receivefd) (_assuan_init_uds_io): New. (_assuan_uds_deinit): New. @@ -1234,7 +1253,7 @@ * assuan-pipe-connect.c (fix_signals) [_ASSUAN_NO_FIXED_SIGNALS]: New. (assuan_pipe_connect2) [_ASSUAN_USE_DOUBLE_FORK]: Use double fork. (fix_signals) [_ASSUAN_USE_DOUBLE_FORK]: Do not wait.. - + 2005-05-21 Werner Koch * assuan-util.c (assuan_set_flag, assuan_get_flag): New. @@ -1276,7 +1295,7 @@ 2004-12-18 Werner Koch - * assuan-logging.c (_assuan_w32_strerror): New. + * assuan-logging.c (_assuan_w32_strerror): New. * assuan-defs.h (w32_strerror): new. * assuan-pipe-connect.c (assuan_pipe_connect2, fix_signals): Factored signal code out to new function. @@ -1327,7 +1346,7 @@ * assuan-socket-connect.c (assuan_socket_connect): Use DIRSEP_C for a better portability. (assuan-defs.h): Define DIRSEP_C. - + 2004-11-19 Werner Koch * assuan-handler.c (assuan_write_status): Return an error code. @@ -1339,7 +1358,7 @@ * assuan-socket.c (_assuan_close): New. (_assuan_sock_new): New. (_assuan_sock_bind): New. - + 2004-11-16 Werner Koch * assuan-socket-connect.c (LOG): Fixed macro to print not only the @@ -1506,7 +1525,7 @@ * isascii.c: Likewise. * memrchr.c: Likewise. * putc_unlocked.c: Likewise. - + 2003-02-18 Neal H. Walfield * assuan-handler.c (_IO_cookie_io_functions_t): Remove. @@ -1805,10 +1824,10 @@ * assuan-connect.c: Move all except assuan_get_pid to... * assuan-pipe-connect.c: this. (assuan_pipe_disconnect): Removed. - (do_finish, do_deinit): New + (do_finish, do_deinit): New (assuan_pipe_connect): and set them into the context. * assuan-socket-connect.c: New. - + * assuan-util.c (_assuan_log_sanitized_string): New. * assuan-pipe-server.c (assuan_init_pipe_server): Factored most @@ -1901,7 +1920,7 @@ * assuan-connect.c (assuan_pipe_connect): Implemented the inital handshake. - * assuan-client.c (read_from_server): Renamed to + * assuan-client.c (read_from_server): Renamed to (_assuan_read_from_server): this and made external. * assuan-listen.c (assuan_set_hello_line): New. @@ -1948,9 +1967,9 @@ than a line. * assuan-defs.h: Add space in the context for this. - - Copyright 2001, 2002, 2006, 2007 Free Software Foundation, Inc. + Copyright 2001, 2002, 2006, 2007, 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 modifications, as long as this notice is preserved. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/NEWS 2010-03-11 12:00:10 UTC (rev 360) @@ -8,10 +8,13 @@ * Input and output notification handler can now really access the parsed fd as stated in the manual. + * Cleaned up the logging. + * Interface changes relative to the 2.0.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ assuan_free NEW. _assuan_w32ce_create_pipe NEW. + ASSUAN_LOG_CONTROL NEW. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modified: trunk/doc/assuan.texi =================================================================== --- trunk/doc/assuan.texi 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/doc/assuan.texi 2010-03-11 12:00:10 UTC (rev 360) @@ -655,7 +655,11 @@ @item ASSUAN_LOG_CTX @item ASSUAN_LOG_ENGINE @item ASSUAN_LOG_DATA +RFU @item ASSUAN_LOG_SYSIO +Log lowlevel I/O data. + at item ASSUAN_LOG_CONTROL +Log the control channel. @end table The user may then, depending on the category, write the message to a @@ -973,23 +977,23 @@ @deftypefun gpg_error_t assuan_read_line (@w{assuan_context_t @var{ctx}}, @w{char **@var{line}}, @w{size_t *@var{linelen}}) -Read the next line written by the peer and store a pointer to the -buffer holding that line at the address @var{line}. The valid length -of the lines is stored at the address of @var{linelen}. This buffer -is valid until the next read operation on the same context @var{ctx}. -You may modify the context of this buffer. The buffer is invalid -(i.e. must not be used) if an error is returned. This function +Read the next line written by the peer to the control channel and store +a pointer to the buffer holding that line at the address @var{line}. +The valid length of the lines is stored at the address of @var{linelen}. +This buffer is valid until the next read operation on the same context + at var{ctx}. You may modify the context of this buffer. The buffer is +invalid (i.e. must not be used) if an error is returned. This function returns @code{0} on success or an error value. @end deftypefun @deftypefun gpg_error_t assuan_write_line (@w{assuan_context_t @var{ctx}}, @w{const char *@var{line}}) -Write the string @var{line} to the other end. This string needs to be -a proper formatted Assuan protocol line and should not include a -linefeed. Sending linefeed or @code{Nul} characters is not possible -and not allowed by the assuan protocol. This function shall not be -used for sending data (@code{D}) lines. This function returns - at code{0} on success or an error value. +Write the string @var{line} to the other end on the control channel. +This string needs to be a proper formatted Assuan protocol line and +should not include a linefeed. Sending linefeed or @code{Nul} +characters is not possible and not allowed by the assuan protocol. This +function shall not be used for sending data (@code{D}) lines. This +function returns @code{0} on success or an error value. @end deftypefun @noindent @@ -997,11 +1001,11 @@ @deftypefun gpg_error_t assuan_send_data (@w{assuan_context_t @var{ctx}}, @w{const void *@var{buffer}}, @w{size_t @var{length}}) -This function is used by a server or a client to send - at var{length} bytes of bulk data in @var{buffer} to the other end. -The data will be escaped as required by the Assuan protocol and -may get buffered until a line is full. To flush any pending data, - at var{buffer} may be passed as @code{NULL} and @var{length} be @code{0}. +This function is used by a server or a client to send @var{length} bytes +of bulk data in @var{buffer} to the other end on the control channel. +The data will be escaped as required by the Assuan protocol and may get +buffered until a line is full. To flush any pending data, @var{buffer} +may be passed as @code{NULL} and @var{length} be @code{0}. @noindent When used by a client, this flush operation does also send the Modified: trunk/src/assuan-buffer.c =================================================================== --- trunk/src/assuan-buffer.c 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/assuan-buffer.c 2010-03-11 12:00:10 UTC (rev 360) @@ -1,5 +1,5 @@ /* assuan-buffer.c - read and send data - Copyright (C) 2001-2004, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006, 2009, 2010 Free Software Foundation, Inc. This file is part of Assuan. @@ -138,12 +138,10 @@ if (rc) { int saved_errno = errno; + char buf[100]; - if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Error: %s]\n", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd, - strerror (errno)); + snprintf (buf, sizeof buf, "error: %s", strerror (errno)); + _assuan_log_control_channel (ctx, 0, buf, NULL, 0, NULL, 0); if (saved_errno == EAGAIN) { @@ -161,11 +159,7 @@ if (!nread) { assert (ctx->inbound.eof); - if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [EOF]\n", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); - + _assuan_log_control_channel (ctx, 0, "eof", NULL, 0, NULL, 0); return _assuan_error (ctx, GPG_ERR_EOF); } @@ -205,27 +199,16 @@ if (monitor_result & ASSUAN_IO_MONITOR_IGNORE) ctx->inbound.linelen = 0; - if (ctx->log_fp && !(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) - { - fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- ", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); - if (ctx->flags.confidential) - fputs ("[Confidential data not shown]", ctx->log_fp); - else - _assuan_log_print_buffer (ctx->log_fp, - ctx->inbound.line, - ctx->inbound.linelen); - putc ('\n', ctx->log_fp); - } + if ( !(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) + _assuan_log_control_channel (ctx, 0, NULL, + ctx->inbound.line, ctx->inbound.linelen, + NULL, 0); return 0; } else { - if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [Invalid line]\n", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); + _assuan_log_control_channel (ctx, 0, "invalid line", + NULL, 0, NULL, 0); *line = 0; ctx->inbound.linelen = 0; return _assuan_error (ctx, ctx->inbound.eof @@ -285,11 +268,9 @@ /* Make sure that the line is short enough. */ if (len + prefixlen + 2 > ASSUAN_LINELENGTH) { - if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> " - "[supplied line too long -truncated]\n", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); + _assuan_log_control_channel (ctx, 1, + "supplied line too long - truncated", + NULL, 0, NULL, 0); if (prefixlen > 5) prefixlen = 5; if (len > ASSUAN_LINELENGTH - prefixlen - 2) @@ -301,21 +282,10 @@ monitor_result = ctx->io_monitor (ctx, ctx->io_monitor_data, 1, line, len); /* Fixme: we should do some kind of line buffering. */ - if (ctx->log_fp && !(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) - { - fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); - if (ctx->flags.confidential) - fputs ("[Confidential data not shown]", ctx->log_fp); - else - { - if (prefixlen) - _assuan_log_print_buffer (ctx->log_fp, prefix, prefixlen); - _assuan_log_print_buffer (ctx->log_fp, line, len); - } - putc ('\n', ctx->log_fp); - } + if (!(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) + _assuan_log_control_channel (ctx, 1, NULL, + prefixlen? prefix:NULL, prefixlen, + line, len); if (prefixlen && !(monitor_result & ASSUAN_IO_MONITOR_IGNORE)) { @@ -353,11 +323,10 @@ str = strchr (line, '\n'); len = str ? (str - line) : strlen (line); - if (ctx->log_fp && str) - fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> " - "[supplied line contained a LF - truncated]\n", - assuan_get_assuan_log_prefix (), - (unsigned int) getpid (), (int) ctx->inbound.fd); + if (str) + _assuan_log_control_channel (ctx, 1, + "supplied line with LF - truncated", + NULL, 0, NULL, 0); return _assuan_write_line (ctx, NULL, line, len); } @@ -418,20 +387,11 @@ if (linelen >= LINELENGTH-2-2) { - if (ctx->log_fp && !(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) - { - fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); + if (!(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) + _assuan_log_control_channel (ctx, 1, NULL, + ctx->outbound.data.line, linelen, + NULL, 0); - if (ctx->flags.confidential) - fputs ("[Confidential data not shown]", ctx->log_fp); - else - _assuan_log_print_buffer (ctx->log_fp, - ctx->outbound.data.line, - linelen); - putc ('\n', ctx->log_fp); - } *line++ = '\n'; linelen++; if ( !(monitor_result & ASSUAN_IO_MONITOR_IGNORE) @@ -474,18 +434,10 @@ if (linelen) { - if (ctx->log_fp && !(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) - { - fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", - assuan_get_assuan_log_prefix (), - (unsigned int)getpid (), (int)ctx->inbound.fd); - if (ctx->flags.confidential) - fputs ("[Confidential data not shown]", ctx->log_fp); - else - _assuan_log_print_buffer (ctx->log_fp, - ctx->outbound.data.line, linelen); - putc ('\n', ctx->log_fp); - } + if (!(monitor_result & ASSUAN_IO_MONITOR_NOLOG)) + _assuan_log_control_channel (ctx, 1, NULL, + ctx->outbound.data.line, linelen, + NULL, 0); *line++ = '\n'; linelen++; if (! (monitor_result & ASSUAN_IO_MONITOR_IGNORE) Modified: trunk/src/assuan-defs.h =================================================================== --- trunk/src/assuan-defs.h 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/assuan-defs.h 2010-03-11 12:00:10 UTC (rev 360) @@ -302,7 +302,11 @@ /*-- assuan-logging.c --*/ -void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length); +void _assuan_init_log_envvars (void); +void _assuan_log_control_channel (assuan_context_t ctx, int outbound, + const char *string, + const void *buffer1, size_t length1, + const void *buffer2, size_t length2); /*-- assuan-io.c --*/ @@ -364,7 +368,14 @@ #ifndef HAVE_PUTC_UNLOCKED int putc_unlocked (int c, FILE *stream); #endif +#ifndef HAVE_VASPRINTF +int _assuan_vasprintf (char **result, const char *format, va_list args); +int _assuan_asprintf (char **buf, const char *fmt, ...); +#define vasprintf _assuan_vasprintf +#define asprintf _assuan_asprintf +#endif + #define DIM(v) (sizeof(v)/sizeof((v)[0])) #if HAVE_W32_SYSTEM Modified: trunk/src/assuan-logging.c =================================================================== --- trunk/src/assuan-logging.c 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/assuan-logging.c 2010-03-11 12:00:10 UTC (rev 360) @@ -1,5 +1,6 @@ /* assuan-logging.c - Default logging function. - Copyright (C) 2002, 2003, 2004, 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 2004, 2007, 2009, + 2010 Free Software Foundation, Inc. This file is part of Assuan. @@ -41,35 +42,42 @@ static char prefix_buffer[80]; /* A global flag read from the environment to check if to enable full - logging of buffer data. */ + logging of buffer data. This is also used by custom log + handlers. */ static int full_logging; -/* A bitfield that specifies the categories to log. Note that - assuan-buffer currently does not log through the default handler, - but directly. This will be changed later. Then the default here - should be to log that and only that. */ +/* A bitfield that specifies the categories to log. */ static int log_cats; #define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1)))) static FILE *_assuan_log; + void -assuan_set_assuan_log_stream (FILE *fp) +_assuan_init_log_envvars (void) { char *flagstr; - _assuan_log = fp; - - /* Set defaults. */ full_logging = !!getenv ("ASSUAN_FULL_LOGGING"); flagstr = getenv ("ASSUAN_DEBUG"); if (flagstr) log_cats = atoi (flagstr); + else /* Default to log the control channel. */ + log_cats = (1 << (ASSUAN_LOG_CONTROL - 1)); _assuan_sysutils_blurb (); /* Make sure this code gets linked in. */ } +void +assuan_set_assuan_log_stream (FILE *fp) +{ + _assuan_log = fp; + + _assuan_init_log_envvars (); +} + + /* Set the per context log stream. Also enable the default log stream if it has not been set. */ void @@ -144,45 +152,148 @@ return 0; } + -/* Dump a possibly binary string (used for debugging). Distinguish - ascii text from binary and print it accordingly. This function - takes FILE pointer arg because logging may be enabled on a per - context basis. */ +/* Log a control channel message. This is either a STRING with a + diagnostic or actual data in (BUFFER1,LENGTH1) and + (BUFFER2,LENGTH2). If OUTBOUND is true the data is intended for + the peer. */ void -_assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length) +_assuan_log_control_channel (assuan_context_t ctx, int outbound, + const char *string, + const void *buffer1, size_t length1, + const void *buffer2, size_t length2) { - const unsigned char *s; - unsigned int n; + int res; + char *outbuf; + int saved_errno; - for (n = length, s = buffer; n; n--, s++) - if ((! isascii (*s) || iscntrl (*s) || ! isprint (*s)) && !(*s >= 0x80)) - break; + /* Check whether logging is enabled and do a quick check to see + whether the callback supports our category. */ + if (!ctx || !ctx->log_cb + || !(*ctx->log_cb) (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, NULL)) + return; - s = buffer; - if (! n && *s != '[') - fwrite (buffer, length, 1, fp); - else + saved_errno = errno; + + /* Note that we use the inbound channel fd as the printed channel + number for both directions. */ +#ifdef HAVE_W32_SYSTEM +# define CHANNEL_FMT "%p" +#else +# define CHANNEL_FMT "%d" +#endif +#define TOHEX(val) (((val) < 10) ? ((val) + '0') : ((val) - 10 + 'a')) + + if (!buffer1 && buffer2) { -#ifdef HAVE_FLOCKFILE - flockfile (fp); -#endif - putc_unlocked ('[', fp); - if (length > 16 && ! full_logging) + buffer1 = buffer2; + length1 = length2; + buffer2 = NULL; + length2 = 0; + } + + if (ctx->flags.confidential && !string && buffer1) + string = "[Confidential data not shown]"; + + if (string) + { + /* Print the diagnostic. */ + res = asprintf (&outbuf, "chan_" CHANNEL_FMT " %s [%s]\n", + ctx->inbound.fd, outbound? "->":"<-", string); + } + else if (buffer1) + { + /* Print the control channel data. */ + const unsigned char *s; + unsigned int n, x; + + for (n = length1, s = buffer1; n; n--, s++) + if ((!isascii (*s) || iscntrl (*s) || !isprint (*s) || !*s) + && !(*s >= 0x80)) + break; + if (!n && buffer2) { - for (n = 0; n < 12; n++, s++) - fprintf (fp, " %02x", *s); - fprintf (fp, " ...(%d bytes skipped)", (int) length - 12); + for (n = length2, s = buffer2; n; n--, s++) + if ((!isascii (*s) || iscntrl (*s) || !isprint (*s) || !*s) + && !(*s >= 0x80)) + break; } + if (!buffer2) + length2 = 0; + + if (!n && (length1 && *(const char*)buffer1 != '[')) + { + /* No control characters and not starting with our error + message indicator. Log it verbatim. */ + res = asprintf (&outbuf, "chan_" CHANNEL_FMT " %s %.*s%.*s\n", + ctx->inbound.fd, outbound? "->":"<-", + (int)length1, (const char*)buffer1, + (int)length2, buffer2? (const char*)buffer2:""); + } else { - for (n = 0; n < length; n++, s++) - fprintf (fp, " %02x", *s); + /* The buffer contains control characters - do a hex dump. + Even in full logging mode we limit the line length - + however this is no real limit because the provided + buffers will never be larger than the maximum assuan line + length. */ + char *hp; + unsigned int nbytes; + unsigned int maxbytes = full_logging? (2*LINELENGTH) : 16; + + nbytes = length1 + length2; + if (nbytes > maxbytes) + nbytes = maxbytes; + + if (!(outbuf = malloc (50 + 3*nbytes + 60 + 3 + 1))) + res = -1; + else + { + res = 0; + hp = outbuf; + snprintf (hp, 50, "chan_" CHANNEL_FMT " %s [", + ctx->inbound.fd, outbound? "->":"<-"); + hp += strlen (hp); + n = 0; + for (s = buffer1, x = 0; x < length1 && n < nbytes; x++, n++) + { + *hp++ = ' '; + *hp++ = TOHEX (*s >> 4); + *hp++ = TOHEX (*s & 0x0f); + s++; + } + for (s = buffer2, x = 0; x < length2 && n < nbytes; x++, n++) + { + *hp++ = ' '; + *hp++ = TOHEX (*s >> 4); + *hp++ = TOHEX (*s & 0x0f); + s++; + } + if (nbytes < length1 + length2) + { + snprintf (hp, 60, " ...(%u byte(s) skipped)", + (unsigned int)((length1+length2) - nbytes)); + hp += strlen (hp); + } + strcpy (hp, " ]\n"); + } } - putc_unlocked (' ', fp); - putc_unlocked (']', fp); -#ifdef HAVE_FUNLOCKFILE - funlockfile (fp); -#endif } + else + { + res = 0; + outbuf = NULL; + } + if (res < 0) + ctx->log_cb (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, + "[libassuan failed to format the log message]"); + else if (outbuf) + { + ctx->log_cb (ctx, ctx->log_cb_data, ASSUAN_LOG_CONTROL, outbuf); + free (outbuf); + } +#undef TOHEX +#undef CHANNEL_FMT + gpg_err_set_errno (saved_errno); } Modified: trunk/src/assuan.c =================================================================== --- trunk/src/assuan.c 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/assuan.c 2010-03-11 12:00:10 UTC (rev 360) @@ -80,6 +80,7 @@ { _assuan_default_log_cb = log_cb; _assuan_default_log_cb_data = log_cb_data; + _assuan_init_log_envvars (); } Modified: trunk/src/assuan.h =================================================================== --- trunk/src/assuan.h 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/assuan.h 2010-03-11 12:00:10 UTC (rev 360) @@ -159,6 +159,7 @@ #define ASSUAN_LOG_ENGINE 3 #define ASSUAN_LOG_DATA 4 #define ASSUAN_LOG_SYSIO 5 +#define ASSUAN_LOG_CONTROL 8 /* If MSG is NULL, return true/false depending on if this category is logged. This is used to probe before expensive log message Modified: trunk/src/debug.c =================================================================== --- trunk/src/debug.c 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/debug.c 2010-03-11 12:00:10 UTC (rev 360) @@ -40,7 +40,7 @@ #include "debug.h" -/* Log the formatted string FORMAT at debug category CAT or higher. */ +/* Log the formatted string FORMAT at debug category CAT higher. */ void _assuan_debug (assuan_context_t ctx, unsigned int cat, const char *format, ...) { Modified: trunk/src/vasprintf.c =================================================================== --- trunk/src/vasprintf.c 2010-03-05 17:55:57 UTC (rev 359) +++ trunk/src/vasprintf.c 2010-03-11 12:00:10 UTC (rev 360) @@ -135,34 +135,33 @@ return 0; } + +/* We use the _assuan prefix to keep our name space clean. */ int -vasprintf (result, format, args) - char **result; - const char *format; -#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__) - _BSD_VA_LIST_ args; -#else - va_list args; -#endif +_assuan_vasprintf (char **result, const char *format, va_list args) { return int_vasprintf (result, format, &args); } int -asprintf (char **buf, const char *fmt, ...) +_assuan_asprintf (char **buf, const char *fmt, ...) { int status; va_list ap; va_start (ap, fmt); - status = vasprintf (buf, fmt, ap); + status = _assuan_vasprintf (buf, fmt, ap); va_end (ap); return status; } #ifdef TEST + +#define asprintf _assuan_asprintf +#define vasprintf _assuan_vasprintf + void checkit (const char* format, ...) { From cvs at cvs.gnupg.org Thu Mar 11 13:34:12 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Thu, 11 Mar 2010 13:34:12 +0100 Subject: [svn] GnuPG - r5290 - in trunk: agent common g10 g13 scd sm Message-ID: Author: wk Date: 2010-03-11 13:34:11 +0100 (Thu, 11 Mar 2010) New Revision: 5290 Modified: trunk/agent/ChangeLog trunk/agent/call-scd.c trunk/agent/gpg-agent.c trunk/common/ChangeLog trunk/common/asshelp.c trunk/common/asshelp.h trunk/common/estream.c trunk/common/logging.c trunk/common/logging.h trunk/common/miscellaneous.c trunk/g10/ChangeLog trunk/g10/gpg.c trunk/g10/server.c trunk/g13/ChangeLog trunk/g13/g13.c trunk/g13/server.c trunk/scd/ChangeLog trunk/scd/command.c trunk/scd/scdaemon.c trunk/sm/ChangeLog trunk/sm/gpgsm.c trunk/sm/server.c Log: Use a custom log handler for libassuan. Modified: trunk/agent/ChangeLog =================================================================== --- trunk/agent/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/agent/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) @@ -1,3 +1,12 @@ +2010-03-11 Werner Koch + + * gpg-agent.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + (handle_signal): Disable pth ctrl dumping. + (parse_rereadable_options, main): Remove assuan_set_assuan_log_stream. + * call-scd.c (start_scd): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (common_libs): Remove libjnlib.a. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) @@ -1,3 +1,11 @@ +2010-03-11 Werner Koch + + * estream.c (es_setvbuf): Fix parameter check. + (es_set_buffering): Allow a SIZE of 0. + * asshelp.c (setup_libassuan_logging, my_libassuan_log_handler): New. + * logging.c (do_logv): Add arg IGNORE_ARG_PTR. Change all callers. + (log_string): New. + 2010-03-10 Werner Koch * estream.c (es_func_fp_read, es_func_fp_write, es_func_fp_seek) Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/g10/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) @@ -1,3 +1,10 @@ +2010-03-11 Werner Koch + + * gpg.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + * server.c (gpg_server): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (needed_libs): Remove libjnlib.a. Modified: trunk/g13/ChangeLog =================================================================== --- trunk/g13/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/g13/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) @@ -1,4 +1,4 @@ -009-11-04 Werner Koch +2009-11-04 Werner Koch Under initial development - no need for a ChangeLog. Modified: trunk/scd/ChangeLog =================================================================== --- trunk/scd/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/scd/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) @@ -1,3 +1,11 @@ +2010-03-11 Werner Koch + + * scdaemon.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + (handle_signal): Disable pth ctrl dumping. + * command.c (scd_command_handler): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (scdaemon_LDADD): Remove libjnlib.a. Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/sm/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) @@ -1,3 +1,10 @@ +2010-03-11 Werner Koch + + * gpgsm.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + * server.c (gpgsm_server): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (common_libs): Remove libjnlib.a. Change order. Modified: trunk/agent/call-scd.c =================================================================== --- trunk/agent/call-scd.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/agent/call-scd.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -354,8 +354,6 @@ if (opt.verbose) log_debug ("first connection to SCdaemon established\n"); - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); /* Get the name of the additional socket opened by scdaemon. */ { Modified: trunk/agent/gpg-agent.c =================================================================== --- trunk/agent/gpg-agent.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/agent/gpg-agent.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -49,6 +49,7 @@ #include "setenv.h" #include "gc-opt-flags.h" #include "exechelp.h" +#include "asshelp.h" enum cmd_and_opt_values { aNull = 0, @@ -494,8 +495,6 @@ || strcmp (current_logfile, pargs->r.ret_str)) { log_set_file (pargs->r.ret_str); - if (DBG_ASSUAN) - assuan_set_assuan_log_stream (log_get_stream ()); xfree (current_logfile); current_logfile = xtrystrdup (pargs->r.ret_str); } @@ -616,10 +615,10 @@ malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); - assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); + assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); assuan_set_system_hooks (ASSUAN_SYSTEM_PTH); assuan_sock_init (); + setup_libassuan_logging (&opt.debug); setup_libgcrypt_logging (); gcry_control (GCRYCTL_USE_SECURE_RNDPOOL); @@ -946,8 +945,6 @@ |JNLIB_LOG_WITH_PID)); current_logfile = xstrdup (logfile); } - if (DBG_ASSUAN) - assuan_set_assuan_log_stream (log_get_stream ()); /* Make sure that we have a default ttyname. */ if (!default_ttyname && ttyname (1)) @@ -1711,7 +1708,9 @@ case SIGUSR1: log_info ("SIGUSR1 received - printing internal information:\n"); - pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); + /* Fixme: We need to see how to integrate pth dumping into our + logging system. */ + /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */ agent_query_dump_state (); agent_scd_dump_state (); break; Modified: trunk/common/asshelp.c =================================================================== --- trunk/common/asshelp.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/asshelp.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -27,6 +27,7 @@ #include #endif +#define JNLIB_NEED_LOG_LOGV #include "i18n.h" #include "util.h" #include "exechelp.h" @@ -34,6 +35,36 @@ #include "status.h" #include "asshelp.h" + +static int +my_libassuan_log_handler (assuan_context_t ctx, void *hook, + unsigned int cat, const char *msg) +{ + unsigned int dbgval; + + if (cat != ASSUAN_LOG_CONTROL) + return 0; /* We only want the control channel messages. */ + dbgval = hook? *(unsigned int*)hook : 0; + if (!(dbgval & 1024)) + return 0; /* Assuan debugging is not enabled. */ + + if (msg) + log_string (JNLIB_LOG_DEBUG, msg); + + return 1; +} + + +/* Setup libassuan to use our own logging functions. Should be used + early at startup. */ +void +setup_libassuan_logging (unsigned int *debug_var_address) +{ + assuan_set_log_cb (my_libassuan_log_handler, debug_var_address); +} + + + static gpg_error_t send_one_option (assuan_context_t ctx, gpg_err_source_t errsource, const char *name, const char *value, int use_putenv) Modified: trunk/common/asshelp.h =================================================================== --- trunk/common/asshelp.h 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/asshelp.h 2010-03-11 12:34:11 UTC (rev 5290) @@ -25,6 +25,9 @@ #include "session-env.h" +void setup_libassuan_logging (unsigned int *debug_var_address); + + gpg_error_t send_pinentry_environment (assuan_context_t ctx, gpg_err_source_t errsource, Modified: trunk/common/estream.c =================================================================== --- trunk/common/estream.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/estream.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -2028,6 +2028,8 @@ buffer_new = buffer; else { + if (!size) + size = BUFSIZ; buffer_new = mem_alloc (size); if (! buffer_new) { @@ -3207,8 +3209,8 @@ { int err; - if (((type == _IOFBF) || (type == _IOLBF) || (type == _IONBF)) - && (! ((! size) && (type != _IONBF)))) + if ((type == _IOFBF || type == _IOLBF || type == _IONBF) + && (!buf || size || type == _IONBF)) { ESTREAM_LOCK (stream); err = es_set_buffering (stream, buf, type, size); Modified: trunk/common/logging.c =================================================================== --- trunk/common/logging.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/logging.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -415,7 +415,7 @@ } static void -do_logv (int level, const char *fmt, va_list arg_ptr) +do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr) { if (!logstream) { @@ -478,7 +478,10 @@ if (fmt) { - es_vfprintf_unlocked (logstream, fmt, arg_ptr); + if (ignore_arg_ptr) + es_fputs_unlocked (fmt, logstream); + else + es_vfprintf_unlocked (logstream, fmt, arg_ptr); if (*fmt && fmt[strlen(fmt)-1] != '\n') missing_lf = 1; } @@ -503,76 +506,91 @@ static void -do_log( int level, const char *fmt, ... ) +do_log (int level, const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( level, fmt, arg_ptr ); - va_end(arg_ptr); + va_list arg_ptr ; + + va_start (arg_ptr, fmt) ; + do_logv (level, 0, fmt, arg_ptr); + va_end (arg_ptr); } void log_logv (int level, const char *fmt, va_list arg_ptr) { - do_logv (level, fmt, arg_ptr); + do_logv (level, 0, fmt, arg_ptr); } + void -log_info( const char *fmt, ... ) +log_string (int level, const char *string) { - va_list arg_ptr ; + /* We need to provide a dummy arg_ptr. volatile is needed to + suppress compiler warnings. */ + volatile va_list dummy_arg_ptr; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_INFO, fmt, arg_ptr ); - va_end(arg_ptr); + do_logv (level, 1, string, dummy_arg_ptr); } + void -log_error( const char *fmt, ... ) +log_info (const char *fmt, ...) { - va_list arg_ptr ; + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_INFO, 0, fmt, arg_ptr); + va_end (arg_ptr); +} - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_ERROR, fmt, arg_ptr ); - va_end(arg_ptr); - /* protect against counter overflow */ - if( errorcount < 30000 ) - errorcount++; + +void +log_error (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_ERROR, 0, fmt, arg_ptr); + va_end (arg_ptr); + /* Protect against counter overflow. */ + if (errorcount < 30000) + errorcount++; } void -log_fatal( const char *fmt, ... ) +log_fatal (const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_FATAL, fmt, arg_ptr ); - va_end(arg_ptr); - abort(); /* never called, but it makes the compiler happy */ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_FATAL, 0, fmt, arg_ptr); + va_end (arg_ptr); + abort (); /* Never called; just to make the compiler happy. */ } + void -log_bug( const char *fmt, ... ) +log_bug (const char *fmt, ...) { - va_list arg_ptr ; + va_list arg_ptr ; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_BUG, fmt, arg_ptr ); - va_end(arg_ptr); - abort(); /* never called, but it makes the compiler happy */ + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_BUG, 0, fmt, arg_ptr); + va_end (arg_ptr); + abort (); /* Never called; just to make the compiler happy. */ } + void -log_debug( const char *fmt, ... ) +log_debug (const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_DEBUG, fmt, arg_ptr ); - va_end(arg_ptr); + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_DEBUG, 0, fmt, arg_ptr); + va_end (arg_ptr); } @@ -580,12 +598,13 @@ log_printf (const char *fmt, ...) { va_list arg_ptr; - + va_start (arg_ptr, fmt); - do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, fmt, arg_ptr); + do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, 0, fmt, arg_ptr); va_end (arg_ptr); } + /* Print a hexdump of BUFFER. With TEXT of NULL print just the raw dump, with TEXT just an empty string, print a trailing linefeed, otherwise print an entire debug line. */ @@ -610,17 +629,15 @@ void bug_at( const char *file, int line, const char *func ) { - do_log( JNLIB_LOG_BUG, - ("... this is a bug (%s:%d:%s)\n"), file, line, func ); - abort(); /* never called, but it makes the compiler happy */ + do_log (JNLIB_LOG_BUG, ("... this is a bug (%s:%d:%s)\n"), file, line, func); + abort (); /* Never called; just to make the compiler happy. */ } #else void bug_at( const char *file, int line ) { - do_log( JNLIB_LOG_BUG, - _("you found a bug ... (%s:%d)\n"), file, line); - abort(); /* never called, but it makes the compiler happy */ + do_log (JNLIB_LOG_BUG, _("you found a bug ... (%s:%d)\n"), file, line); + abort (); /* Never called; just to make the compiler happy. */ } #endif Modified: trunk/common/logging.h =================================================================== --- trunk/common/logging.h 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/logging.h 2010-03-11 12:34:11 UTC (rev 5290) @@ -65,6 +65,7 @@ JNLIB_LOG_DEBUG }; void log_logv (int level, const char *fmt, va_list arg_ptr); +void log_string (int level, const char *string); #endif /*JNLIB_NEED_LOG_LOGV*/ Modified: trunk/common/miscellaneous.c =================================================================== --- trunk/common/miscellaneous.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/common/miscellaneous.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -26,7 +26,6 @@ #include "iobuf.h" #include "i18n.h" - /* Used by libgcrypt for logging. */ static void my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr) @@ -97,7 +96,6 @@ } - /* Decide whether the filename is stdout or a real filename and return * an appropriate string. */ const char * Modified: trunk/g10/gpg.c =================================================================== --- trunk/g10/gpg.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/g10/gpg.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -53,6 +53,7 @@ #include "keyserver-internal.h" #include "exec.h" #include "gc-opt-flags.h" +#include "asshelp.h" #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__) #define MY_O_BINARY O_BINARY @@ -2070,8 +2071,8 @@ malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); + setup_libassuan_logging (&opt.debug); /* Try for a version specific config file first */ default_configname = get_default_configname (); Modified: trunk/g10/server.c =================================================================== --- trunk/g10/server.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/g10/server.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -735,9 +735,6 @@ ctrl->server_local->assuan_ctx = ctx; ctrl->server_local->message_fd = GNUPG_INVALID_FD; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - for (;;) { rc = assuan_accept (ctx); Modified: trunk/g13/g13.c =================================================================== --- trunk/g13/g13.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/g13/g13.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -35,6 +35,7 @@ #include "i18n.h" #include "sysutils.h" #include "gc-opt-flags.h" +#include "asshelp.h" #include "keyblob.h" #include "server.h" #include "runner.h" @@ -432,11 +433,10 @@ } /* Prepare libassuan. */ - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); assuan_set_system_hooks (ASSUAN_SYSTEM_PTH); + setup_libassuan_logging (&opt.debug); - /* Setup a default control structure for command line mode. */ memset (&ctrl, 0, sizeof ctrl); g13_init_default_ctrl (&ctrl); @@ -799,7 +799,9 @@ case SIGUSR1: log_info ("SIGUSR1 received - printing internal information:\n"); - pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); + /* Fixme: We need to see how to integrate pth dumping into our + logging system. */ + /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */ mountinfo_dump_all (); break; Modified: trunk/g13/server.c =================================================================== --- trunk/g13/server.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/g13/server.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -642,9 +642,6 @@ } ctrl->server_local->assuan_ctx = ctx; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - while ( !(err = assuan_accept (ctx)) ) { err = assuan_process (ctx); Modified: trunk/scd/command.c =================================================================== --- trunk/scd/command.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/scd/command.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -1947,9 +1947,6 @@ ctrl->server_local->ctrl_backlink = ctrl; ctrl->server_local->assuan_ctx = ctx; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - /* We open the reader right at startup so that the ticker is able to update the status file. */ if (ctrl->reader_slot == -1) Modified: trunk/scd/scdaemon.c =================================================================== --- trunk/scd/scdaemon.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/scd/scdaemon.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -52,6 +52,7 @@ #include "ccid-driver.h" #include "mkdtemp.h" #include "gc-opt-flags.h" +#include "asshelp.h" enum cmd_and_opt_values { aNull = 0, @@ -432,10 +433,10 @@ malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); assuan_set_system_hooks (ASSUAN_SYSTEM_PTH); assuan_sock_init (); + setup_libassuan_logging (&opt.debug); setup_libgcrypt_logging (); gcry_control (GCRYCTL_USE_SECURE_RNDPOOL); @@ -951,7 +952,9 @@ case SIGUSR1: log_info ("SIGUSR1 received - printing internal information:\n"); - pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); + /* Fixme: We need to see how to integrate pth dumping into our + logging system. */ + /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */ app_dump_state (); break; Modified: trunk/sm/gpgsm.c =================================================================== --- trunk/sm/gpgsm.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/sm/gpgsm.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -37,8 +37,8 @@ #include "keydb.h" #include "sysutils.h" #include "gc-opt-flags.h" +#include "asshelp.h" - #ifndef O_BINARY #define O_BINARY 0 #endif @@ -982,8 +982,8 @@ malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); + setup_libassuan_logging (&opt.debug); keybox_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free); Modified: trunk/sm/server.c =================================================================== --- trunk/sm/server.c 2010-03-10 17:22:23 UTC (rev 5289) +++ trunk/sm/server.c 2010-03-11 12:34:11 UTC (rev 5290) @@ -1311,9 +1311,6 @@ ctrl.server_local->list_external = 0; ctrl.server_local->default_recplist = default_recplist; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - for (;;) { rc = assuan_accept (ctx); From cvs at cvs.gnupg.org Fri Mar 12 18:24:07 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 12 Mar 2010 18:24:07 +0100 Subject: [svn] GnuPG - r5291 - in branches/STABLE-BRANCH-2-0: common g10 Message-ID: Author: wk Date: 2010-03-12 18:24:06 +0100 (Fri, 12 Mar 2010) New Revision: 5291 Modified: branches/STABLE-BRANCH-2-0/common/ChangeLog branches/STABLE-BRANCH-2-0/common/status.h branches/STABLE-BRANCH-2-0/g10/ChangeLog branches/STABLE-BRANCH-2-0/g10/gpg.h branches/STABLE-BRANCH-2-0/g10/keyedit.c branches/STABLE-BRANCH-2-0/g10/seckey-cert.c Log: Return a posiive status message for a successfull passphrase change. Modified: branches/STABLE-BRANCH-2-0/common/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/common/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) +++ branches/STABLE-BRANCH-2-0/common/ChangeLog 2010-03-12 17:24:06 UTC (rev 5291) @@ -1,3 +1,7 @@ +2010-03-12 Werner Koch + + * status.h (STATUS_ENTER): New. + 2010-02-11 Marcus Brinkmann From trunk 2009-10-16, 2009-11-02, 2009-11-05: Modified: branches/STABLE-BRANCH-2-0/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/g10/ChangeLog 2010-03-11 12:34:11 UTC (rev 5290) +++ branches/STABLE-BRANCH-2-0/g10/ChangeLog 2010-03-12 17:24:06 UTC (rev 5291) @@ -1,3 +1,10 @@ +2010-03-12 Werner Koch + + * seckey-cert.c (do_check): Return GPG_ERR_CANCELED. + * keyedit.c (change_passphrase): Add arg R_ERR. + (keyedit_passwd): Return the correct error or emit a success + status message. + 2010-02-25 Werner Koch * sign.c (hash_for): Force SHA1 only for v1 OpenPGP cards. Fixes Modified: branches/STABLE-BRANCH-2-0/common/status.h =================================================================== --- branches/STABLE-BRANCH-2-0/common/status.h 2010-03-11 12:34:11 UTC (rev 5290) +++ branches/STABLE-BRANCH-2-0/common/status.h 2010-03-12 17:24:06 UTC (rev 5291) @@ -124,7 +124,8 @@ STATUS_PKA_TRUST_GOOD, STATUS_TRUNCATED, - STATUS_ERROR + STATUS_ERROR, + STATUS_SUCCESS }; Modified: branches/STABLE-BRANCH-2-0/g10/gpg.h =================================================================== --- branches/STABLE-BRANCH-2-0/g10/gpg.h 2010-03-11 12:34:11 UTC (rev 5290) +++ branches/STABLE-BRANCH-2-0/g10/gpg.h 2010-03-12 17:24:06 UTC (rev 5291) @@ -119,5 +119,4 @@ #define G10ERR_UNU_SECKEY GPG_ERR_UNUSABLE_SECKEY #define G10ERR_WRONG_SECKEY GPG_ERR_WRONG_SECKEY - #endif /*GNUPG_G10_GPG_H*/ Modified: branches/STABLE-BRANCH-2-0/g10/keyedit.c =================================================================== --- branches/STABLE-BRANCH-2-0/g10/keyedit.c 2010-03-11 12:34:11 UTC (rev 5290) +++ branches/STABLE-BRANCH-2-0/g10/keyedit.c 2010-03-12 17:24:06 UTC (rev 5291) @@ -1098,7 +1098,7 @@ * We use only one passphrase for all keys. */ static int -change_passphrase( KBNODE keyblock ) +change_passphrase (KBNODE keyblock, int *r_err) { int rc = 0; int changed=0; @@ -1262,6 +1262,8 @@ leave: xfree( passphrase ); set_next_passphrase( NULL ); + if (r_err) + *r_err = rc; return changed && !rc; } @@ -2121,7 +2123,7 @@ break; case cmdPASSWD: - if( change_passphrase( sec_keyblock ) ) + if (change_passphrase (sec_keyblock, NULL)) sec_modified = 1; break; @@ -2341,11 +2343,8 @@ if (err) goto leave; - if (!change_passphrase (keyblock)) - { - err = gpg_error (GPG_ERR_GENERAL); - goto leave; - } + if (!change_passphrase (keyblock, &err)) + goto leave; err = keydb_update_keyblock (kdh, keyblock); if (err) @@ -2362,6 +2361,8 @@ username, gpg_strerror (err)); write_status_error ("keyedit.passwd", gpg_err_code (err)); } + else + write_status_text (STATUS_SUCCESS, "keyedit.passwd"); } Modified: branches/STABLE-BRANCH-2-0/g10/seckey-cert.c =================================================================== --- branches/STABLE-BRANCH-2-0/g10/seckey-cert.c 2010-03-11 12:34:11 UTC (rev 5290) +++ branches/STABLE-BRANCH-2-0/g10/seckey-cert.c 2010-03-12 17:24:06 UTC (rev 5291) @@ -83,7 +83,7 @@ &sk->protect.s2k, mode, tryagain_text, canceled ); if (!dek && canceled && *canceled) - return G10ERR_GENERAL; + return GPG_ERR_CANCELED; err = openpgp_cipher_open (&cipher_hd, sk->protect.algo, From cvs at cvs.gnupg.org Fri Mar 12 19:03:03 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 12 Mar 2010 19:03:03 +0100 Subject: [svn] gpgme - r1456 - in trunk: . src Message-ID: Author: wk Date: 2010-03-12 19:03:02 +0100 (Fri, 12 Mar 2010) New Revision: 1456 Modified: trunk/NEWS trunk/src/ChangeLog trunk/src/context.h trunk/src/passwd.c Log: Detect old gpg versions not featuring the --passwd command. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-09 11:15:53 UTC (rev 1455) +++ trunk/src/ChangeLog 2010-03-12 18:03:02 UTC (rev 1456) @@ -1,3 +1,11 @@ +2010-03-12 Werner Koch + + * passwd.c (op_data_t): New. + (passwd_start): Setup OPD. + (passwd_status_handler): Return GPG_ERR_NOT_SUPPORTED if needed. + * context.h (OPDATA_PASSWD): New. + * gpgme.h (GPGME_STATUS_SUCCESS): New. + 2010-03-09 Werner Koch * engine-gpgsm.c (gpgsm_keylist): Try to start the agent. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-09 11:15:53 UTC (rev 1455) +++ trunk/NEWS 2010-03-12 18:03:02 UTC (rev 1456) @@ -3,6 +3,8 @@ * Under development. + * Detect GPG versions not supporting ---passwd. + * Interface changes relative to the 1.3.0 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GPGME_EXPORT_MODE_MINIMAL NEW. Modified: trunk/src/context.h =================================================================== --- trunk/src/context.h 2010-03-09 11:15:53 UTC (rev 1455) +++ trunk/src/context.h 2010-03-12 18:03:02 UTC (rev 1456) @@ -37,7 +37,8 @@ { OPDATA_DECRYPT, OPDATA_SIGN, OPDATA_ENCRYPT, OPDATA_PASSPHRASE, OPDATA_IMPORT, OPDATA_GENKEY, OPDATA_KEYLIST, OPDATA_EDIT, - OPDATA_VERIFY, OPDATA_TRUSTLIST, OPDATA_ASSUAN, OPDATA_VFS_MOUNT + OPDATA_VERIFY, OPDATA_TRUSTLIST, OPDATA_ASSUAN, OPDATA_VFS_MOUNT, + OPDATA_PASSWD } ctx_op_data_id_t; Modified: trunk/src/passwd.c =================================================================== --- trunk/src/passwd.c 2010-03-09 11:15:53 UTC (rev 1455) +++ trunk/src/passwd.c 2010-03-12 18:03:02 UTC (rev 1456) @@ -27,6 +27,14 @@ #include "context.h" #include "ops.h" + +typedef struct +{ + int success_seen; + int error_seen; +} *op_data_t; + + /* Parse an error status line and return the error code. */ static gpgme_error_t @@ -63,16 +71,39 @@ passwd_status_handler (void *priv, gpgme_status_code_t code, char *args) { gpgme_ctx_t ctx = (gpgme_ctx_t) priv; - gpgme_error_t err = 0; + gpgme_error_t err; + void *hook; + op_data_t opd; - (void)ctx; + err = _gpgme_op_data_lookup (ctx, OPDATA_PASSWD, &hook, -1, NULL); + opd = hook; + if (err) + return err; switch (code) { case GPGME_STATUS_ERROR: err = parse_error (args); + if (err) + opd->error_seen = 1; break; - + + case GPGME_STATUS_SUCCESS: + opd->success_seen = 1; + break; + + case GPGME_STATUS_EOF: + /* In case the OpenPGP engine does not properly implement the + passwd command we won't get a success status back and thus we + conclude that this operation is not supported. This is for + example the case for GnuPG < 2.0.16. Note that this test is + obsolete for assuan based engines because they will properly + return an error for an unknown command. */ + if (ctx->protocol == GPGME_PROTOCOL_OpenPGP + && !opd->error_seen && !opd->success_seen) + err = gpg_error (GPG_ERR_NOT_SUPPORTED); + break; + default: break; } @@ -86,6 +117,8 @@ unsigned int flags) { gpgme_error_t err; + void *hook; + op_data_t opd; if (!key) return gpg_error (GPG_ERR_INV_VALUE); @@ -96,6 +129,14 @@ if (err) return err; + err = _gpgme_op_data_lookup (ctx, OPDATA_PASSWD, &hook, sizeof (*opd), NULL); + opd = hook; + if (err) + return err; + + opd->success_seen = 0; + opd->error_seen = 0; + _gpgme_engine_set_status_handler (ctx->engine, passwd_status_handler, ctx); return _gpgme_engine_op_passwd (ctx->engine, key, flags); From cvs at cvs.gnupg.org Fri Mar 12 19:08:02 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 12 Mar 2010 19:08:02 +0100 Subject: [svn] GnuPG - r5292 - branches/STABLE-BRANCH-2-0/sm Message-ID: Author: wk Date: 2010-03-12 19:08:02 +0100 (Fri, 12 Mar 2010) New Revision: 5292 Modified: branches/STABLE-BRANCH-2-0/sm/ChangeLog branches/STABLE-BRANCH-2-0/sm/server.c Log: Add command passwd. Modified: branches/STABLE-BRANCH-2-0/sm/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/sm/ChangeLog 2010-03-12 17:24:06 UTC (rev 5291) +++ branches/STABLE-BRANCH-2-0/sm/ChangeLog 2010-03-12 18:08:02 UTC (rev 5292) @@ -1,3 +1,8 @@ +2010-03-12 Werner Koch + + * server.c (cmd_passwd): New. From trunk. + (register_commands): Register it. + 2010-02-11 Marcus Brinkmann From trunk 2009-09-23, 2009-11-02, 2009-11-04, 2009-11-05, 2009-11-25, Modified: branches/STABLE-BRANCH-2-0/sm/server.c =================================================================== --- branches/STABLE-BRANCH-2-0/sm/server.c 2010-03-12 17:24:06 UTC (rev 5291) +++ branches/STABLE-BRANCH-2-0/sm/server.c 2010-03-12 18:08:02 UTC (rev 5292) @@ -1,6 +1,6 @@ /* server.c - Server mode and main entry point - * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, + * 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -1142,6 +1142,42 @@ +static const char hlp_passwd[] = + "PASSWD \n" + "\n" + "Change the passphrase of the secret key for USERID."; +static gpg_error_t +cmd_passwd (assuan_context_t ctx, char *line) +{ + ctrl_t ctrl = assuan_get_pointer (ctx); + gpg_error_t err; + ksba_cert_t cert = NULL; + char *grip = NULL; + + line = skip_options (line); + + err = gpgsm_find_cert (line, NULL, &cert); + if (err) + ; + else if (!(grip = gpgsm_get_keygrip_hexstring (cert))) + err = gpg_error (GPG_ERR_INTERNAL); + else + { + char *desc = gpgsm_format_keydesc (cert); + err = gpgsm_agent_passwd (ctrl, grip, desc); + xfree (desc); + } + + xfree (grip); + ksba_cert_release (cert); + + return err; +} + + + + + /* Return true if the command CMD implements the option OPT. */ static int command_has_option (const char *cmd, const char *cmdopt) @@ -1184,6 +1220,7 @@ { "DELKEYS", cmd_delkeys, hlp_delkeys }, { "GETAUDITLOG", cmd_getauditlog, hlp_getauditlog }, { "GETINFO", cmd_getinfo, hlp_getinfo }, + { "PASSWD", cmd_passwd, hlp_passwd }, { NULL } }; int i, rc; From cvs at cvs.gnupg.org Fri Mar 12 19:46:34 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 12 Mar 2010 19:46:34 +0100 Subject: [svn] GnuPG - r5293 - branches/STABLE-BRANCH-2-0/g10 Message-ID: Author: wk Date: 2010-03-12 19:46:33 +0100 (Fri, 12 Mar 2010) New Revision: 5293 Modified: branches/STABLE-BRANCH-2-0/g10/ChangeLog branches/STABLE-BRANCH-2-0/g10/plaintext.c Log: Fix for bug#1201. Modified: branches/STABLE-BRANCH-2-0/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-2-0/g10/ChangeLog 2010-03-12 18:08:02 UTC (rev 5292) +++ branches/STABLE-BRANCH-2-0/g10/ChangeLog 2010-03-12 18:46:33 UTC (rev 5293) @@ -1,5 +1,8 @@ 2010-03-12 Werner Koch + * plaintext.c (setup_plaintext_name): Do not encode pipe like + filenames. This helps with bug#1201. + * seckey-cert.c (do_check): Return GPG_ERR_CANCELED. * keyedit.c (change_passphrase): Add arg R_ERR. (keyedit_passwd): Return the correct error or emit a success Modified: branches/STABLE-BRANCH-2-0/g10/plaintext.c =================================================================== --- branches/STABLE-BRANCH-2-0/g10/plaintext.c 2010-03-12 18:08:02 UTC (rev 5292) +++ branches/STABLE-BRANCH-2-0/g10/plaintext.c 2010-03-12 18:46:33 UTC (rev 5293) @@ -623,7 +623,8 @@ { PKT_plaintext *pt; - if(filename || opt.set_filename) + if ((filename && !iobuf_is_pipe_filename (filename)) + || (opt.set_filename && !iobuf_is_pipe_filename (opt.set_filename))) { char *s; From cvs at cvs.gnupg.org Fri Mar 12 23:24:13 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 12 Mar 2010 23:24:13 +0100 Subject: [svn] gpgme - r1457 - trunk/src Message-ID: Author: wk Date: 2010-03-12 23:24:13 +0100 (Fri, 12 Mar 2010) New Revision: 1457 Modified: trunk/src/ChangeLog trunk/src/gpgme.h.in Log: Add constant to the template and not to a built file. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-12 18:03:02 UTC (rev 1456) +++ trunk/src/ChangeLog 2010-03-12 22:24:13 UTC (rev 1457) @@ -1,5 +1,8 @@ 2010-03-12 Werner Koch + * gpgme.h.in (GPGME_STATUS_SUCCESS): Use the right file for the + change; see below. + * passwd.c (op_data_t): New. (passwd_start): Setup OPD. (passwd_status_handler): Return GPG_ERR_NOT_SUPPORTED if needed. Modified: trunk/src/gpgme.h.in =================================================================== --- trunk/src/gpgme.h.in 2010-03-12 18:03:02 UTC (rev 1456) +++ trunk/src/gpgme.h.in 2010-03-12 22:24:13 UTC (rev 1457) @@ -494,7 +494,8 @@ GPGME_STATUS_PLAINTEXT = 81, GPGME_STATUS_INV_SGNR = 82, - GPGME_STATUS_NO_SGNR = 83 + GPGME_STATUS_NO_SGNR = 83, + GPGME_STATUS_SUCCESS = 84 } gpgme_status_code_t; From cvs at cvs.gnupg.org Sat Mar 13 10:12:28 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Sat, 13 Mar 2010 10:12:28 +0100 Subject: [svn] dirmngr - r341 - in trunk: . src Message-ID: Author: wk Date: 2010-03-13 10:12:28 +0100 (Sat, 13 Mar 2010) New Revision: 341 Modified: trunk/NEWS trunk/configure.ac trunk/src/ChangeLog trunk/src/certcache.c trunk/src/dirmngr.c Log: Fix compiler warnings Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-09 13:57:55 UTC (rev 340) +++ trunk/src/ChangeLog 2010-03-13 09:12:28 UTC (rev 341) @@ -1,3 +1,10 @@ +2010-03-13 Werner Koch + + * dirmngr.c (int_and_ptr_u): New. + (pid_suffix_callback): Trick out compiler. + (start_connection_thread): Ditto. + (handle_connections): Ditto. + 2010-03-09 Werner Koch * dirmngr.c (set_debug): Allow numerical values. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-09 13:57:55 UTC (rev 340) +++ trunk/NEWS 2010-03-13 09:12:28 UTC (rev 341) @@ -9,7 +9,9 @@ * New option --ignore-cert-extension. + * Make use of libassuan 2.0 which is available as a DSO. + Noteworthy changes in version 1.0.3 (2009-06-17) ------------------------------------------------ Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-09 13:57:55 UTC (rev 340) +++ trunk/configure.ac 2010-03-13 09:12:28 UTC (rev 341) @@ -27,8 +27,8 @@ # Remember to change the version number immediately *after* a release. # Set my_issvn to "yes" for non-released code. Remember to run an # "svn up" and "autogen.sh" right before creating a distribution. -m4_define([my_version], [1.1.0rc1]) -m4_define([my_issvn], [no]) +m4_define([my_version], [1.1.0]) +m4_define([my_issvn], [yes]) m4_define([svn_revision], m4_esyscmd([printf "%d" $( (svn info 2>/dev/null \ || echo 'Revision: 0')|sed -n '/^Revision:/ {s/[^0-9]//gp;q;}')])) Modified: trunk/src/certcache.c =================================================================== --- trunk/src/certcache.c 2010-03-09 13:57:55 UTC (rev 340) +++ trunk/src/certcache.c 2010-03-13 09:12:28 UTC (rev 341) @@ -183,7 +183,7 @@ char numbuf[40]; len = unhexify (NULL, hexsn); - snprintf (numbuf, sizeof numbuf, "(%u:", len); + snprintf (numbuf, sizeof numbuf, "(%u:", (unsigned int)len); buffer = xtrymalloc (strlen (numbuf) + len + 2 ); if (!buffer) return NULL; Modified: trunk/src/dirmngr.c =================================================================== --- trunk/src/dirmngr.c 2010-03-09 13:57:55 UTC (rev 340) +++ trunk/src/dirmngr.c 2010-03-13 09:12:28 UTC (rev 341) @@ -239,7 +239,18 @@ #define TIMERTICK_INTERVAL (2) /* Seconds. */ #endif +/* This union is used to avoid compiler warnings in case a pointer is + 64 bit and an int 32 bit. We store an integer in a pointer and get + it back later (pth_key_getdata et al.). */ +union int_and_ptr_u +{ + int aint; + assuan_fd_t afd; + void *aptr; +}; + + /* The key used to store the current file descriptor in the thread local storage. We use this in conjunction with the log_set_pid_suffix_cb feature.. */ @@ -576,7 +587,10 @@ static int pid_suffix_callback (int *r_suffix) { - *r_suffix = (int)pth_key_getdata (my_tlskey_current_fd); + union int_and_ptr_u value; + + value.aptr = pth_key_getdata (my_tlskey_current_fd); + *r_suffix = value.aint; return (*r_suffix != -1); } #endif /*!HAVE_W32_SYSTEM*/ @@ -1704,13 +1718,17 @@ static void * start_connection_thread (void *arg) { - assuan_fd_t fd = (assuan_fd_t) arg; + union int_and_ptr_u argval; + assuan_fd_t fd; + argval.aptr = arg; + fd = argval.afd; + if (check_nonce (fd, &socket_nonce)) return NULL; #ifndef HAVE_W32_SYSTEM - pth_key_setdata (my_tlskey_current_fd, (void*)FD2INT (fd)); + pth_key_setdata (my_tlskey_current_fd, argval.aptr); #endif active_connections++; @@ -1724,7 +1742,8 @@ active_connections--; #ifndef HAVE_W32_SYSTEM - pth_key_setdata (my_tlskey_current_fd, (void*)(-1)); + argval.afd = ASSUAN_INVALID_FD; + pth_key_setdata (my_tlskey_current_fd, argval.aptr); #endif return NULL; @@ -1827,13 +1846,18 @@ pth_sigmask (SIG_BLOCK, &sigs, &oldsigs); /* Create thread to handle this connection. */ - if (!pth_spawn (tattr, start_connection_thread, (void*)fd)) - { - log_error (_("error spawning connection handler: %s\n"), - strerror (errno) ); - assuan_sock_close (fd); - } + { + union int_and_ptr_u argval; + argval.afd = fd; + if (!pth_spawn (tattr, start_connection_thread, argval.aptr)) + { + log_error (_("error spawning connection handler: %s\n"), + strerror (errno) ); + assuan_sock_close (fd); + } + } + /* Restore the signal mask. */ pth_sigmask (SIG_SETMASK, &oldsigs, NULL); } From cvs at cvs.gnupg.org Mon Mar 15 12:15:46 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 15 Mar 2010 12:15:46 +0100 Subject: [svn] GnuPG - r5294 - in trunk: . common doc g10 sm Message-ID: Author: wk Date: 2010-03-15 12:15:45 +0100 (Mon, 15 Mar 2010) New Revision: 5294 Modified: trunk/ChangeLog trunk/common/ChangeLog trunk/common/asshelp.c trunk/common/estream.c trunk/common/estream.h trunk/common/logging.c trunk/common/logging.h trunk/common/miscellaneous.c trunk/common/status.h trunk/common/ttyio.c trunk/common/ttyio.h trunk/common/util.h trunk/configure.ac trunk/doc/DETAILS trunk/g10/ChangeLog trunk/g10/armor.c trunk/g10/card-util.c trunk/g10/gpg.c trunk/g10/import.c trunk/g10/kbnode.c trunk/g10/keyedit.c trunk/g10/keylist.c trunk/g10/main.h trunk/g10/mainproc.c trunk/g10/misc.c trunk/g10/parse-packet.c trunk/g10/pkclist.c trunk/g10/plaintext.c trunk/g10/seckey-cert.c trunk/g10/trustdb.c trunk/sm/ChangeLog trunk/sm/verify.c Log: Finished the bulk of changes to use estream in most places instead of stdio. [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/ChangeLog 2010-03-15 11:15:45 UTC (rev 5294) @@ -1,3 +1,7 @@ +2010-03-12 Werner Koch + + * configure.ac (AC_INIT): Prepare for using git. + 2010-03-10 Werner Koch * jnlib/: Move all code to common/. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/ChangeLog 2010-03-15 11:15:45 UTC (rev 5294) @@ -1,11 +1,27 @@ +2010-03-12 Werner Koch + + * status.h (STATUS_ENTER): New. + + * ttyio.c (tty_fprintf): Change to use estream. + + * miscellaneous.c (print_utf8_string): Rename to print_utf8_buffer + and change FP arg to an estream. Change all callers. + (print_utf8_string2): Ditto; new name is to print_utf8_buffer2. + 2010-03-11 Werner Koch + * miscellaneous.c (print_string): Remove. + * estream.c (es_setvbuf): Fix parameter check. (es_set_buffering): Allow a SIZE of 0. * asshelp.c (setup_libassuan_logging, my_libassuan_log_handler): New. * logging.c (do_logv): Add arg IGNORE_ARG_PTR. Change all callers. (log_string): New. + (log_flush): New. + (set_file_fd): Simplify by using estreams es_stderr. + * estream.h (es_stdout, es_stderr, es_stdin): New. + 2010-03-10 Werner Koch * estream.c (es_func_fp_read, es_func_fp_write, es_func_fp_seek) Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/ChangeLog 2010-03-15 11:15:45 UTC (rev 5294) @@ -1,5 +1,39 @@ +2010-03-15 Werner Koch + + * card-util.c: Replace stdio by estream. + * keylist.c: Ditto. + +2010-03-12 Werner Koch + + * plaintext.c (setup_plaintext_name): Do not encode pipe like + filenames. This helps with bug#1201. + + * seckey-cert.c (do_check): Return GPG_ERR_CANCELED. + * keyedit.c (change_passphrase): Add arg R_ERR. + (keyedit_passwd): Return the correct error or emit a success + status message. + 2010-03-11 Werner Koch + * misc.c (mpi_print): Change to take a estream_t arg. + + * parse-packet.c (listfp): Change to an estream_t. Change all + users to use estream functions. + + * kbnode.c (dump_kbnode): Change to use log functions. + * pkclist.c (do_show_revocation_reason): Ditto + + * armor.c (parse_header_line): Replace print_string by + es_print_sanitized. + (fake_packet): Ditto. + * keyedit.c (print_and_check_one_sig_colon): Ditto. + (show_key_with_all_names_colon): Ditto. + (ask_revoke_sig): Ditto. + * keylist.c (list_keyblock_colon): Ditto. + * mainproc.c (print_userid, list_node): Ditto. + * trustdb.c (dump_key_array): Ditto. + * gpg.c (list_config): ditto. + * gpg.c: Include "asshelp.h". (main): Remove assuan_set_assuan_log_prefix. Add assuan_set_log_cb. Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/sm/ChangeLog 2010-03-15 11:15:45 UTC (rev 5294) @@ -1,5 +1,7 @@ 2010-03-11 Werner Koch + * verify.c (gpgsm_verify): Use gpgsm_es_print_name. + * gpgsm.c: Include "asshelp.h". (main): Remove assuan_set_assuan_log_prefix. Add assuan_set_log_cb. Modified: trunk/common/asshelp.c =================================================================== --- trunk/common/asshelp.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/asshelp.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -42,6 +42,8 @@ { unsigned int dbgval; + (void)ctx; + if (cat != ASSUAN_LOG_CONTROL) return 0; /* We only want the control channel messages. */ dbgval = hook? *(unsigned int*)hook : 0; Modified: trunk/common/estream.c =================================================================== --- trunk/common/estream.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/estream.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -213,6 +213,8 @@ unsigned int eof: 1; } indicators; unsigned int deallocate_buffer: 1; + unsigned int is_stdstream:1; /* This is a standard stream. */ + unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */ unsigned int print_err: 1; /* Error in print_fun_writer. */ int print_errno; /* Errno from print_fun_writer. */ size_t print_ntotal; /* Bytes written from in print_fun_writer. */ @@ -302,9 +304,11 @@ * List manipulation. */ -/* Add STREAM to the list of registered stream objects. */ +/* Add STREAM to the list of registered stream objects. If + WITH_LOCKED_LIST is true we assumed that the list of streams is + already locked. */ static int -es_list_add (estream_t stream) +es_list_add (estream_t stream, int with_locked_list) { estream_list_t list_obj; int ret; @@ -314,14 +318,16 @@ ret = -1; else { - ESTREAM_LIST_LOCK; + if (!with_locked_list) + ESTREAM_LIST_LOCK; list_obj->car = stream; list_obj->cdr = estream_list; list_obj->prev_cdr = &estream_list; if (estream_list) estream_list->prev_cdr = &list_obj->cdr; estream_list = list_obj; - ESTREAM_LIST_UNLOCK; + if (!with_locked_list) + ESTREAM_LIST_UNLOCK; ret = 0; } @@ -330,11 +336,12 @@ /* Remove STREAM from the list of registered stream objects. */ static void -es_list_remove (estream_t stream) +es_list_remove (estream_t stream, int with_locked_list) { estream_list_t list_obj; - ESTREAM_LIST_LOCK; + if (!with_locked_list) + ESTREAM_LIST_LOCK; for (list_obj = estream_list; list_obj; list_obj = list_obj->cdr) if (list_obj->car == stream) { @@ -344,7 +351,8 @@ mem_free (list_obj); break; } - ESTREAM_LIST_UNLOCK; + if (!with_locked_list) + ESTREAM_LIST_UNLOCK; } /* Type of an stream-iterator-function. */ @@ -1211,6 +1219,8 @@ stream->intern->print_fp = NULL; stream->intern->indicators.err = 0; stream->intern->indicators.eof = 0; + stream->intern->is_stdstream = 0; + stream->intern->stdstream_fd = 0; stream->intern->deallocate_buffer = 0; stream->data_len = 0; @@ -1219,7 +1229,7 @@ stream->unread_data_len = 0; /* Depending on the modeflags we set whether we start in writing or reading mode. This is required in case we are working on a - wronly stream which is not seeekable (like stdout). Without this + stream which is not seeekable (like stdout). Without this pre-initialization we would do a seek at the first write call and as this will fail no utput will be delivered. */ if ((modeflags & O_WRONLY) || (modeflags & O_RDWR) ) @@ -1258,7 +1268,8 @@ /* Create a new stream object, initialize it. */ static int es_create (estream_t *stream, void *cookie, int fd, - es_cookie_io_functions_t functions, unsigned int modeflags) + es_cookie_io_functions_t functions, unsigned int modeflags, + int with_locked_list) { estream_internal_t stream_internal_new; estream_t stream_new; @@ -1290,7 +1301,7 @@ ESTREAM_MUTEX_INITIALIZE (stream_new->intern->lock); es_initialize (stream_new, cookie, fd, functions, modeflags); - err = es_list_add (stream_new); + err = es_list_add (stream_new, with_locked_list); if (err) goto out; @@ -1312,13 +1323,13 @@ /* Deinitialize a stream object and destroy it. */ static int -es_destroy (estream_t stream) +es_destroy (estream_t stream, int with_locked_list) { int err = 0; if (stream) { - es_list_remove (stream); + es_list_remove (stream, with_locked_list); err = es_deinitialize (stream); mem_free (stream->intern); mem_free (stream); @@ -1838,7 +1849,7 @@ goto out; err = es_create (&line_stream, line_stream_cookie, -1, - estream_functions_mem, O_RDWR); + estream_functions_mem, O_RDWR, 0); if (err) goto out; @@ -1923,7 +1934,7 @@ out: if (line_stream) - es_destroy (line_stream); + es_destroy (line_stream, 0); else if (line_stream_cookie) es_func_mem_destroy (line_stream_cookie); @@ -2122,7 +2133,7 @@ goto out; create_called = 1; - err = es_create (&stream, cookie, fd, estream_functions_file, modeflags); + err = es_create (&stream, cookie, fd, estream_functions_file, modeflags, 0); if (err) goto out; @@ -2162,7 +2173,7 @@ goto out; create_called = 1; - err = es_create (&stream, cookie, -1, estream_functions_mem, modeflags); + err = es_create (&stream, cookie, -1, estream_functions_mem, modeflags, 0); out: @@ -2193,7 +2204,7 @@ memlimit)) return NULL; - if (es_create (&stream, cookie, -1, estream_functions_mem, modeflags)) + if (es_create (&stream, cookie, -1, estream_functions_mem, modeflags, 0)) (*estream_functions_mem.func_close) (cookie); return stream; @@ -2217,7 +2228,7 @@ if (err) goto out; - err = es_create (&stream, cookie, -1, functions, modeflags); + err = es_create (&stream, cookie, -1, functions, modeflags, 0); if (err) goto out; @@ -2249,7 +2260,8 @@ goto out; create_called = 1; - err = es_create (&stream, cookie, filedes, estream_functions_fd, modeflags); + err = es_create (&stream, cookie, filedes, estream_functions_fd, + modeflags, 0); out: @@ -2274,7 +2286,7 @@ estream_t -do_fpopen (FILE *fp, const char *mode, int no_close) +do_fpopen (FILE *fp, const char *mode, int no_close, int with_locked_list) { unsigned int modeflags; int create_called; @@ -2298,7 +2310,7 @@ create_called = 1; err = es_create (&stream, cookie, fp? fileno (fp):-1, estream_functions_fp, - modeflags); + modeflags, with_locked_list); out: @@ -2320,7 +2332,7 @@ estream_t es_fpopen (FILE *fp, const char *mode) { - return do_fpopen (fp, mode, 0); + return do_fpopen (fp, mode, 0, 0); } @@ -2328,11 +2340,56 @@ estream_t es_fpopen_nc (FILE *fp, const char *mode) { - return do_fpopen (fp, mode, 1); + return do_fpopen (fp, mode, 1, 0); } estream_t +_es_get_std_stream (int fd) +{ + estream_list_t list_obj; + estream_t stream = NULL; + + fd %= 3; /* We only allow 0, 1 or 2 but we don't want to return an error. */ + ESTREAM_LIST_LOCK; + for (list_obj = estream_list; list_obj; list_obj = list_obj->cdr) + if (list_obj->car->intern->is_stdstream + && list_obj->car->intern->stdstream_fd == fd) + { + stream = list_obj->car; + break; + } + if (!stream) + { + /* Standard stream not yet created - do it now. */ + if (!fd) + stream = do_fpopen (stdin, "r", 1, 1); + else if (fd == 1) + stream = do_fpopen (stdout, "a", 1, 1); + else + stream = do_fpopen (stderr, "a", 1, 1); + + if (!stream) /* Fallback: Create a bit bucket. */ + { + stream = do_fpopen (NULL, fd? "a":"r", 0, 1); + if (!stream) + { + fprintf (stderr, "fatal: error creating a dummy estream" + " for %d: %s\n", fd, strerror (errno)); + abort(); + } + } + stream->intern->is_stdstream = 1; + stream->intern->stdstream_fd = fd; + if (fd == 2) + es_set_buffering (stream, NULL, _IOLBF, 0); + } + ESTREAM_LIST_UNLOCK; + return stream; +} + + +estream_t es_freopen (const char *ES__RESTRICT path, const char *ES__RESTRICT mode, estream_t ES__RESTRICT stream) { @@ -2370,7 +2427,7 @@ if (create_called) es_func_fd_destroy (cookie); - es_destroy (stream); + es_destroy (stream, 0); stream = NULL; } else @@ -2381,7 +2438,7 @@ /* FIXME? We don't support re-opening at the moment. */ _set_errno (EINVAL); es_deinitialize (stream); - es_destroy (stream); + es_destroy (stream, 0); stream = NULL; } @@ -2394,7 +2451,7 @@ { int err; - err = es_destroy (stream); + err = es_destroy (stream, 0); return err; } @@ -2496,6 +2553,23 @@ } +static int +do_fflush (estream_t stream) +{ + int err; + + if (stream->flags.writing) + err = es_flush (stream); + else + { + es_empty (stream); + err = 0; + } + + return err; +} + + int es_fflush (estream_t stream) { @@ -2504,17 +2578,11 @@ if (stream) { ESTREAM_LOCK (stream); - if (stream->flags.writing) - err = es_flush (stream); - else - { - es_empty (stream); - err = 0; - } + err = do_fflush (stream); ESTREAM_UNLOCK (stream); } else - err = es_list_iterate (es_fflush); + err = es_list_iterate (do_fflush); return err ? EOF : 0; } @@ -3186,7 +3254,7 @@ goto out; create_called = 1; - err = es_create (&stream, cookie, fd, estream_functions_fd, modeflags); + err = es_create (&stream, cookie, fd, estream_functions_fd, modeflags, 0); out: Modified: trunk/common/estream.h =================================================================== --- trunk/common/estream.h 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/estream.h 2010-03-15 11:15:45 UTC (rev 5294) @@ -80,6 +80,7 @@ #define es_fdopen_nc _ESTREAM_PREFIX(es_fdopen_nc) #define es_fpopen _ESTREAM_PREFIX(es_fpopen) #define es_fpopen_nc _ESTREAM_PREFIX(es_fpopen_nc) +#define _es_get_std_stream _ESTREAM_PREFIX(_es_get_std_stream) #define es_freopen _ESTREAM_PREFIX(es_freopen) #define es_fopencookie _ESTREAM_PREFIX(es_fopencookie) #define es_fclose _ESTREAM_PREFIX(es_fclose) @@ -250,6 +251,13 @@ int es_fileno (estream_t stream); int es_fileno_unlocked (estream_t stream); +estream_t _es_get_std_stream (int fd); + +#define es_stdin _es_get_std_stream (0) +#define es_stdout _es_get_std_stream (1) +#define es_stderr _es_get_std_stream (2) + + void es_flockfile (estream_t stream); int es_ftrylockfile (estream_t stream); void es_funlockfile (estream_t stream); Modified: trunk/common/logging.c =================================================================== --- trunk/common/logging.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/logging.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -283,32 +283,7 @@ /* On error default to a stderr based estream. */ if (!fp) - { - fp = es_fpopen (stderr, "a"); - if (fp) - { - if (name) - es_fprintf (fp, "failed to open log file `%s': %s\n", - name, strerror (errno)); - else - es_fprintf (fp, "failed to fdopen file descriptor %d: %s\n", - fd, strerror (errno)); - } - else - { - fprintf (stderr, "failed to use stderr as log stream: %s\n", - strerror (errno)); - /* No way to log something. Create a dummy estream so that - there is something we can use. */ - fp = es_fpopen (NULL, "a"); - if (!fp) - { - fprintf (stderr, "fatal: failed to open dummy stream: %s\n", - strerror (errno)); - abort(); - } - } - } + fp = es_stderr; es_setvbuf (fp, NULL, _IOLBF, 0); @@ -605,6 +580,16 @@ } +/* Flush the log - this is useful to make sure that the trailing + linefeed has been printed. */ +void +log_flush (void) +{ + volatile va_list dummy_arg_ptr; + do_logv (JNLIB_LOG_CONT, 1, NULL, dummy_arg_ptr); +} + + /* Print a hexdump of BUFFER. With TEXT of NULL print just the raw dump, with TEXT just an empty string, print a trailing linefeed, otherwise print an entire debug line. */ Modified: trunk/common/logging.h =================================================================== --- trunk/common/logging.h 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/logging.h 2010-03-15 11:15:45 UTC (rev 5294) @@ -75,6 +75,7 @@ void log_info( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); void log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); void log_printf( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2); +void log_flush (void); /* Print a hexdump of BUFFER. With TEXT passes as NULL print just the raw dump, with TEXT being an empty string, print a trailing Modified: trunk/common/miscellaneous.c =================================================================== --- trunk/common/miscellaneous.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/miscellaneous.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -117,23 +117,22 @@ return s; } -/* fixme: Globally replace it by print_sanitized_buffer. */ -void -print_string( FILE *fp, const byte *p, size_t n, int delim ) -{ - print_sanitized_buffer (fp, p, n, delim); -} void -print_utf8_string2 ( FILE *fp, const byte *p, size_t n, int delim ) +print_utf8_buffer2 (estream_t stream, const void *p, size_t n, int delim) { - print_sanitized_utf8_buffer (fp, p, n, delim); + char tmp[2]; + + tmp[0] = delim; + tmp[1] = 0; + es_write_sanitized_utf8_buffer (stream, p, n, tmp, NULL); } + void -print_utf8_string( FILE *fp, const byte *p, size_t n ) +print_utf8_buffer (estream_t stream, const void *p, size_t n) { - print_utf8_string2 (fp, p, n, 0); + es_write_sanitized_utf8_buffer (stream, p, n, NULL, NULL); } /* Write LENGTH bytes of BUFFER to FP as a hex encoded string. Modified: trunk/common/status.h =================================================================== --- trunk/common/status.h 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/status.h 2010-03-15 11:15:45 UTC (rev 5294) @@ -126,7 +126,8 @@ STATUS_TRUNCATED, STATUS_MOUNTPOINT, - STATUS_ERROR + STATUS_ERROR, + STATUS_SUCCESS }; Modified: trunk/common/ttyio.c =================================================================== --- trunk/common/ttyio.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/ttyio.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -1,6 +1,6 @@ /* ttyio.c - tty i/O functions * Copyright (C) 1998,1999,2000,2001,2002,2003,2004,2006,2007, - * 2009 Free Software Foundation, Inc. + * 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -244,14 +244,14 @@ /* Same as tty_printf but if FP is not NULL, behave like a regular fprintf. */ void -tty_fprintf (FILE *fp, const char *fmt, ... ) +tty_fprintf (estream_t fp, const char *fmt, ... ) { va_list arg_ptr; if (fp) { va_start (arg_ptr, fmt) ; - vfprintf (fp, fmt, arg_ptr ); + es_vfprintf (fp, fmt, arg_ptr ); va_end (arg_ptr); return; } @@ -259,32 +259,32 @@ if (no_terminal) return; - if( !initialized ) - init_ttyfp(); + if (!initialized) + init_ttyfp (); - va_start( arg_ptr, fmt ) ; + va_start (arg_ptr, fmt); #ifdef _WIN32 - { - char *buf = NULL; - int n; - DWORD nwritten; - - n = vasprintf(&buf, fmt, arg_ptr); - if( !buf ) - log_bug("vasprintf() failed\n"); - - if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) ) - log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() ); - if( n != nwritten ) - log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten ); - last_prompt_len += n; - xfree (buf); - } + { + char *buf = NULL; + int n; + DWORD nwritten; + + n = vasprintf(&buf, fmt, arg_ptr); + if (!buf) + log_bug("vasprintf() failed\n"); + + if (!WriteConsoleA( con.out, buf, n, &nwritten, NULL )) + log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() ); + if (n != nwritten) + log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten ); + last_prompt_len += n; + xfree (buf); + } #else - last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ; - fflush(ttyfp); + last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ; + fflush(ttyfp); #endif - va_end(arg_ptr); + va_end(arg_ptr); } Modified: trunk/common/ttyio.h =================================================================== --- trunk/common/ttyio.h 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/ttyio.h 2010-03-15 11:15:45 UTC (rev 5294) @@ -28,13 +28,13 @@ #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) void tty_printf (const char *fmt, ... ) __attribute__ ((format (printf,1,2))); -void tty_fprintf (FILE *fp, const char *fmt, ... ) +void tty_fprintf (estream_t fp, const char *fmt, ... ) __attribute__ ((format (printf,2,3))); char *tty_getf (const char *promptfmt, ... ) __attribute__ ((format (printf,1,2))); #else void tty_printf (const char *fmt, ... ); -void tty_fprintf (FILE *fp, const char *fmt, ... ); +void tty_fprintf (estream_t fp, const char *fmt, ... ); char *tty_getf (const char *promptfmt, ... ); #endif void tty_print_string (const unsigned char *p, size_t n); Modified: trunk/common/util.h =================================================================== --- trunk/common/util.h 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/common/util.h 2010-03-15 11:15:45 UTC (rev 5294) @@ -278,9 +278,8 @@ const char *print_fname_stdout (const char *s); const char *print_fname_stdin (const char *s); -void print_string (FILE *fp, const byte *p, size_t n, int delim); -void print_utf8_string2 ( FILE *fp, const byte *p, size_t n, int delim); -void print_utf8_string (FILE *fp, const byte *p, size_t n); +void print_utf8_buffer2 (estream_t fp, const void *p, size_t n, int delim); +void print_utf8_buffer (estream_t fp, const void *p, size_t n); void print_hexstring (FILE *fp, const void *buffer, size_t length, int reserved); char *make_printable_string (const void *p, size_t n, int delim); Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/configure.ac 2010-03-15 11:15:45 UTC (rev 5294) @@ -29,8 +29,11 @@ m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)])) +m4_define([git_revision], m4_esyscmd([git branch -v 2>/dev/null \ + | awk '/^\* / {printf "%s",$3}'])) AC_INIT([gnupg], - [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], + [my_version[]m4_if(my_issvn,[yes], + [m4_if(git_revision,[],[-svn[]svn_revision],[-git[]git_revision])])], [http://bugs.gnupg.org]) # Set development_version to yes if the minor number is odd or you # feel that the default check for a development version is not Modified: trunk/doc/DETAILS =================================================================== --- trunk/doc/DETAILS 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/doc/DETAILS 2010-03-15 11:15:45 UTC (rev 5294) @@ -617,6 +617,12 @@ prefixed with a numerical error code and an underscore; e.g.: "151011327_EOF". + SUCCESS [] + Postive confirimation that an operation succeeded. + is optional but if given should not contain spaces. + Used only with a few commands. + + ATTRIBUTE This is one long line issued for each attribute subpacket when Modified: trunk/g10/armor.c =================================================================== --- trunk/g10/armor.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/armor.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -415,9 +415,9 @@ if( !p || (RFC2440 && p[1]!=' ') || (!RFC2440 && p[1]!=' ' && p[1]!='\n' && p[1]!='\r')) { - log_error(_("invalid armor header: ")); - print_string( stderr, line, len, 0 ); - putc('\n', stderr); + log_error (_("invalid armor header: ")); + es_write_sanitized (log_get_stream (), line, len, NULL, NULL); + log_printf ("\n"); return -1; } @@ -427,8 +427,8 @@ if( opt.verbose ) { log_info(_("armor header: ")); - print_string( stderr, line, len, 0 ); - putc('\n', stderr); + es_write_sanitized (log_get_stream (), line, len, NULL, NULL); + log_printf ("\n"); } if( afx->in_cleartext ) @@ -453,8 +453,8 @@ signed data section is "Hash". */ log_info(_("unknown armor header: ")); - print_string( stderr, line, len, 0 ); - putc('\n', stderr); + es_write_sanitized (log_get_stream (), line, len, NULL, NULL); + log_printf ("\n"); } return 1; @@ -641,8 +641,9 @@ if( type != BEGIN_SIGNATURE ) { log_info(_("unexpected armor: ")); - print_string( stderr, p, n, 0 ); - putc('\n', stderr); + es_write_sanitized (log_get_stream (), p, n, + NULL, NULL); + log_printf ("\n"); } lastline = 1; @@ -652,9 +653,9 @@ else if(!afx->not_dash_escaped) { /* Bad dash-escaping. */ - log_info(_("invalid dash escaped line: ")); - print_string( stderr, p, n, 0 ); - putc('\n', stderr); + log_info (_("invalid dash escaped line: ")); + es_write_sanitized (log_get_stream (), p, n, NULL, NULL); + log_printf ("\n"); } } Modified: trunk/g10/card-util.c =================================================================== --- trunk/g10/card-util.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/card-util.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -218,7 +218,7 @@ static void -print_sha1_fpr (FILE *fp, const unsigned char *fpr) +print_sha1_fpr (estream_t fp, const unsigned char *fpr) { int i; @@ -238,21 +238,21 @@ static void -print_sha1_fpr_colon (FILE *fp, const unsigned char *fpr) +print_sha1_fpr_colon (estream_t fp, const unsigned char *fpr) { int i; if (fpr) { for (i=0; i < 20 ; i++, fpr++) - fprintf (fp, "%02X", *fpr); + es_fprintf (fp, "%02X", *fpr); } - putc (':', fp); + es_putc (':', fp); } static void -print_name (FILE *fp, const char *text, const char *name) +print_name (estream_t fp, const char *text, const char *name) { tty_fprintf (fp, "%s", text); @@ -261,7 +261,7 @@ if (name && *name) { if (fp) - print_utf8_string2 (fp, name, strlen (name), '\n'); + print_utf8_buffer2 (fp, name, strlen (name), '\n'); else tty_print_utf8_string2 (name, strlen (name), 0); } @@ -271,10 +271,11 @@ } static void -print_isoname (FILE *fp, const char *text, const char *tag, const char *name) +print_isoname (estream_t fp, const char *text, + const char *tag, const char *name) { if (opt.with_colons) - fprintf (fp, "%s:", tag); + es_fprintf (fp, "%s:", tag); else tty_fprintf (fp, "%s", text); @@ -291,22 +292,22 @@ *given = 0; given += 2; if (opt.with_colons) - print_string (fp, given, strlen (given), ':'); + es_write_sanitized (fp, given, strlen (given), ":", NULL); else if (fp) - print_utf8_string2 (fp, given, strlen (given), '\n'); + print_utf8_buffer2 (fp, given, strlen (given), '\n'); else tty_print_utf8_string2 (given, strlen (given), 0); if (opt.with_colons) - putc (':', fp); + es_putc (':', fp); else if (*buf) tty_fprintf (fp, " "); } if (opt.with_colons) - print_string (fp, buf, strlen (buf), ':'); + es_write_sanitized (fp, buf, strlen (buf), ":", NULL); else if (fp) - print_utf8_string2 (fp, buf, strlen (buf), '\n'); + print_utf8_buffer2 (fp, buf, strlen (buf), '\n'); else tty_print_utf8_string2 (buf, strlen (buf), 0); xfree (buf); @@ -314,13 +315,13 @@ else { if (opt.with_colons) - putc (':', fp); + es_putc (':', fp); else tty_fprintf (fp, _("[not set]")); } if (opt.with_colons) - fputs (":\n", fp); + es_fputs (":\n", fp); else tty_fprintf (fp, "\n"); } @@ -351,7 +352,7 @@ /* Print all available information about the current card. */ void -card_status (FILE *fp, char *serialno, size_t serialnobuflen) +card_status (estream_t fp, char *serialno, size_t serialnobuflen) { struct agent_card_info_s info; PKT_public_key *pk = xcalloc (1, sizeof *pk); @@ -367,15 +368,14 @@ if (rc) { if (opt.with_colons) - fputs ("AID:::\n", fp); - log_error (_("OpenPGP card not available: %s\n"), - gpg_strerror (rc)); + es_fputs ("AID:::\n", fp); + log_error (_("OpenPGP card not available: %s\n"), gpg_strerror (rc)); xfree (pk); return; } if (opt.with_colons) - fprintf (fp, "AID:%s:", info.serialno? info.serialno : ""); + es_fprintf (fp, "AID:%s:", info.serialno? info.serialno : ""); else tty_fprintf (fp, "Application ID ...: %s\n", info.serialno? info.serialno : "[none]"); @@ -385,31 +385,31 @@ if (info.apptype && !strcmp (info.apptype, "NKS")) { if (opt.with_colons) - fputs ("netkey-card:\n", fp); + es_fputs ("netkey-card:\n", fp); log_info ("this is a NetKey card\n"); } else if (info.apptype && !strcmp (info.apptype, "DINSIG")) { if (opt.with_colons) - fputs ("dinsig-card:\n", fp); + es_fputs ("dinsig-card:\n", fp); log_info ("this is a DINSIG compliant card\n"); } else if (info.apptype && !strcmp (info.apptype, "P15")) { if (opt.with_colons) - fputs ("pkcs15-card:\n", fp); + es_fputs ("pkcs15-card:\n", fp); log_info ("this is a PKCS#15 compliant card\n"); } else if (info.apptype && !strcmp (info.apptype, "GELDKARTE")) { if (opt.with_colons) - fputs ("geldkarte-card:\n", fp); + es_fputs ("geldkarte-card:\n", fp); log_info ("this is a Geldkarte compliant card\n"); } else { if (opt.with_colons) - fputs ("unknown:\n", fp); + es_fputs ("unknown:\n", fp); } log_info ("not an OpenPGP card\n"); agent_release_card_info (&info); @@ -425,69 +425,72 @@ strcpy (serialno, info.serialno); if (opt.with_colons) - fputs ("openpgp-card:\n", fp); + es_fputs ("openpgp-card:\n", fp); if (opt.with_colons) { - fprintf (fp, "version:%.4s:\n", info.serialno+12); + es_fprintf (fp, "version:%.4s:\n", info.serialno+12); uval = xtoi_2(info.serialno+16)*256 + xtoi_2 (info.serialno+18); - fprintf (fp, "vendor:%04x:%s:\n", uval, get_manufacturer (uval)); - fprintf (fp, "serial:%.8s:\n", info.serialno+20); + es_fprintf (fp, "vendor:%04x:%s:\n", uval, get_manufacturer (uval)); + es_fprintf (fp, "serial:%.8s:\n", info.serialno+20); print_isoname (fp, "Name of cardholder: ", "name", info.disp_name); - fputs ("lang:", fp); + es_fputs ("lang:", fp); if (info.disp_lang) - print_string (fp, info.disp_lang, strlen (info.disp_lang), ':'); - fputs (":\n", fp); + es_write_sanitized (fp, info.disp_lang, strlen (info.disp_lang), + ":", NULL); + es_fputs (":\n", fp); - fprintf (fp, "sex:%c:\n", (info.disp_sex == 1? 'm': + es_fprintf (fp, "sex:%c:\n", (info.disp_sex == 1? 'm': info.disp_sex == 2? 'f' : 'u')); - fputs ("url:", fp); + es_fputs ("url:", fp); if (info.pubkey_url) - print_string (fp, info.pubkey_url, strlen (info.pubkey_url), ':'); - fputs (":\n", fp); + es_write_sanitized (fp, info.pubkey_url, strlen (info.pubkey_url), + ":", NULL); + es_fputs (":\n", fp); - fputs ("login:", fp); + es_fputs ("login:", fp); if (info.login_data) - print_string (fp, info.login_data, strlen (info.login_data), ':'); - fputs (":\n", fp); + es_write_sanitized (fp, info.login_data, strlen (info.login_data), + ":", NULL); + es_fputs (":\n", fp); - fprintf (fp, "forcepin:%d:::\n", !info.chv1_cached); + es_fprintf (fp, "forcepin:%d:::\n", !info.chv1_cached); for (i=0; i < DIM (info.key_attr); i++) if (info.key_attr[0].algo) - fprintf (fp, "keyattr:%d:%d:%u:\n", i+1, - info.key_attr[i].algo, info.key_attr[i].nbits); - fprintf (fp, "maxpinlen:%d:%d:%d:\n", - info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]); - fprintf (fp, "pinretry:%d:%d:%d:\n", - info.chvretry[0], info.chvretry[1], info.chvretry[2]); - fprintf (fp, "sigcount:%lu:::\n", info.sig_counter); + es_fprintf (fp, "keyattr:%d:%d:%u:\n", i+1, + info.key_attr[i].algo, info.key_attr[i].nbits); + es_fprintf (fp, "maxpinlen:%d:%d:%d:\n", + info.chvmaxlen[0], info.chvmaxlen[1], info.chvmaxlen[2]); + es_fprintf (fp, "pinretry:%d:%d:%d:\n", + info.chvretry[0], info.chvretry[1], info.chvretry[2]); + es_fprintf (fp, "sigcount:%lu:::\n", info.sig_counter); for (i=0; i < 4; i++) { if (info.private_do[i]) { - fprintf (fp, "private_do:%d:", i+1); - print_string (fp, info.private_do[i], - strlen (info.private_do[i]), ':'); - fputs (":\n", fp); + es_fprintf (fp, "private_do:%d:", i+1); + es_write_sanitized (fp, info.private_do[i], + strlen (info.private_do[i]), ":", NULL); + es_fputs (":\n", fp); } } - fputs ("cafpr:", fp); + es_fputs ("cafpr:", fp); print_sha1_fpr_colon (fp, info.cafpr1valid? info.cafpr1:NULL); print_sha1_fpr_colon (fp, info.cafpr2valid? info.cafpr2:NULL); print_sha1_fpr_colon (fp, info.cafpr3valid? info.cafpr3:NULL); - putc ('\n', fp); - fputs ("fpr:", fp); + es_putc ('\n', fp); + es_fputs ("fpr:", fp); print_sha1_fpr_colon (fp, info.fpr1valid? info.fpr1:NULL); print_sha1_fpr_colon (fp, info.fpr2valid? info.fpr2:NULL); print_sha1_fpr_colon (fp, info.fpr3valid? info.fpr3:NULL); - putc ('\n', fp); - fprintf (fp, "fprtime:%lu:%lu:%lu:\n", + es_putc ('\n', fp); + es_fprintf (fp, "fprtime:%lu:%lu:%lu:\n", (unsigned long)info.fpr1time, (unsigned long)info.fpr2time, (unsigned long)info.fpr3time); } @@ -764,13 +767,13 @@ static int get_data_from_file (const char *fname, size_t maxlen, char **r_buffer) { - FILE *fp; + estream_t fp; char *data; int n; *r_buffer = NULL; - fp = fopen (fname, "rb"); + fp = es_fopen (fname, "rb"); #if GNUPG_MAJOR_VERSION == 1 if (fp && is_secured_file (fileno (fp))) { @@ -789,15 +792,15 @@ if (!data) { tty_printf (_("error allocating enough memory: %s\n"), strerror (errno)); - fclose (fp); + es_fclose (fp); return -1; } if (maxlen) - n = fread (data, 1, maxlen, fp); + n = es_fread (data, 1, maxlen, fp); else n = 0; - fclose (fp); + es_fclose (fp); if (n < 0) { tty_printf (_("error reading `%s': %s\n"), fname, strerror (errno)); @@ -814,9 +817,9 @@ static int put_data_to_file (const char *fname, const void *buffer, size_t length) { - FILE *fp; + estream_t fp; - fp = fopen (fname, "wb"); + fp = es_fopen (fname, "wb"); #if GNUPG_MAJOR_VERSION == 1 if (fp && is_secured_file (fileno (fp))) { @@ -831,13 +834,13 @@ return -1; } - if (length && fwrite (buffer, length, 1, fp) != 1) + if (length && es_fwrite (buffer, length, 1, fp) != 1) { tty_printf (_("error writing `%s': %s\n"), fname, strerror (errno)); - fclose (fp); + es_fclose (fp); return -1; } - fclose (fp); + es_fclose (fp); return 0; } @@ -1785,7 +1788,7 @@ { if (opt.with_colons) { - card_status (stdout, serialnobuf, DIM (serialnobuf)); + card_status (es_stdout, serialnobuf, DIM (serialnobuf)); fflush (stdout); } else Modified: trunk/g10/gpg.c =================================================================== --- trunk/g10/gpg.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/gpg.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -1497,9 +1497,10 @@ { strlist_t sl; - printf("cfg:group:"); - print_string(stdout,iter->name,strlen(iter->name),':'); - printf(":"); + es_fprintf (es_stdout, "cfg:group:"); + es_write_sanitized (es_stdout, iter->name, strlen(iter->name), + ":", NULL); + es_putc (':', es_stdout); for(sl=iter->values;sl;sl=sl->next) { @@ -1517,7 +1518,7 @@ if(show_all || ascii_strcasecmp(name,"version")==0) { printf("cfg:version:"); - print_string(stdout,VERSION,strlen(VERSION),':'); + es_write_sanitized (es_stdout, VERSION, strlen(VERSION), ":", NULL); printf("\n"); any=1; } @@ -3828,29 +3829,30 @@ { int mode = argc < 2 ? 0 : atoi(*argv); if( mode == 1 && argc == 2 ) { - mpi_print( stdout, generate_public_prime( atoi(argv[1]) ), 1); + mpi_print (es_stdout, + generate_public_prime( atoi(argv[1]) ), 1); } else if( mode == 2 && argc == 3 ) { - mpi_print( stdout, generate_elg_prime( + mpi_print (es_stdout, generate_elg_prime( 0, atoi(argv[1]), atoi(argv[2]), NULL,NULL ), 1); } else if( mode == 3 && argc == 3 ) { MPI *factors; - mpi_print( stdout, generate_elg_prime( + mpi_print (es_stdout, generate_elg_prime( 1, atoi(argv[1]), atoi(argv[2]), NULL,&factors ), 1); putchar('\n'); - mpi_print( stdout, factors[0], 1 ); /* print q */ + mpi_print (es_stdout, factors[0], 1 ); /* print q */ } else if( mode == 4 && argc == 3 ) { MPI g = mpi_alloc(1); - mpi_print( stdout, generate_elg_prime( + mpi_print (es_stdout, generate_elg_prime( 0, atoi(argv[1]), atoi(argv[2]), g, NULL ), 1); putchar('\n'); - mpi_print( stdout, g, 1 ); - mpi_free(g); + mpi_print (es_stdout, g, 1 ); + mpi_free (g); } else wrong_args("--gen-prime mode bits [qbits] "); @@ -3987,7 +3989,7 @@ case aCardStatus: if (argc) wrong_args ("--card-status"); - card_status (stdout, NULL, 0); + card_status (es_stdout, NULL, 0); break; case aCardEdit: Modified: trunk/g10/import.c =================================================================== --- trunk/g10/import.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/import.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -718,7 +718,7 @@ pubkey_letter( pk->pubkey_algo ), keystr_from_pk(pk), datestr_from_pk(pk) ); if (uidnode) - print_utf8_string (log_get_stream (), + print_utf8_buffer (log_get_stream (), uidnode->pkt->pkt.user_id->name, uidnode->pkt->pkt.user_id->len ); log_printf ("\n"); @@ -1127,7 +1127,7 @@ pubkey_letter( sk->pubkey_algo ), keystr_from_sk(sk), datestr_from_sk(sk) ); if( uidnode ) - print_utf8_string( stderr, uidnode->pkt->pkt.user_id->name, + print_utf8_buffer (es_stderr, uidnode->pkt->pkt.user_id->name, uidnode->pkt->pkt.user_id->len ); log_printf ("\n"); } Modified: trunk/g10/kbnode.c =================================================================== --- trunk/g10/kbnode.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/kbnode.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -1,6 +1,6 @@ /* kbnode.c - keyblock node utility functions * Copyright (C) 1998, 1999, 2000, 2001, 2002, - * 2005 Free Software Foundation, Inc. + * 2005, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -336,63 +336,71 @@ void -dump_kbnode( KBNODE node ) +dump_kbnode (KBNODE node) { - for(; node; node = node->next ) { - const char *s; - switch( node->pkt->pkttype ) { - case 0: s="empty"; break; - case PKT_PUBLIC_KEY: s="public-key"; break; - case PKT_SECRET_KEY: s="secret-key"; break; - case PKT_SECRET_SUBKEY: s= "secret-subkey"; break; - case PKT_PUBKEY_ENC: s="public-enc"; break; - case PKT_SIGNATURE: s="signature"; break; - case PKT_ONEPASS_SIG: s="onepass-sig"; break; - case PKT_USER_ID: s="user-id"; break; - case PKT_PUBLIC_SUBKEY: s="public-subkey"; break; - case PKT_COMMENT: s="comment"; break; - case PKT_RING_TRUST: s="trust"; break; - case PKT_PLAINTEXT: s="plaintext"; break; - case PKT_COMPRESSED: s="compressed"; break; - case PKT_ENCRYPTED: s="encrypted"; break; - case PKT_GPG_CONTROL: s="gpg-control"; break; - default: s="unknown"; break; + for (; node; node = node->next ) + { + const char *s; + switch (node->pkt->pkttype) + { + case 0: s="empty"; break; + case PKT_PUBLIC_KEY: s="public-key"; break; + case PKT_SECRET_KEY: s="secret-key"; break; + case PKT_SECRET_SUBKEY: s= "secret-subkey"; break; + case PKT_PUBKEY_ENC: s="public-enc"; break; + case PKT_SIGNATURE: s="signature"; break; + case PKT_ONEPASS_SIG: s="onepass-sig"; break; + case PKT_USER_ID: s="user-id"; break; + case PKT_PUBLIC_SUBKEY: s="public-subkey"; break; + case PKT_COMMENT: s="comment"; break; + case PKT_RING_TRUST: s="trust"; break; + case PKT_PLAINTEXT: s="plaintext"; break; + case PKT_COMPRESSED: s="compressed"; break; + case PKT_ENCRYPTED: s="encrypted"; break; + case PKT_GPG_CONTROL: s="gpg-control"; break; + default: s="unknown"; break; } - fprintf(stderr, "node %p %02x/%02x type=%s", - node, node->flag, node->private_flag, s); - if( node->pkt->pkttype == PKT_USER_ID ) { - PKT_user_id *uid = node->pkt->pkt.user_id; - fputs(" \"", stderr); - print_string( stderr, uid->name, uid->len, 0 ); - fprintf (stderr, "\" %c%c%c%c\n", - uid->is_expired? 'e':'.', - uid->is_revoked? 'r':'.', - uid->created? 'v':'.', - uid->is_primary? 'p':'.' ); - } - else if( node->pkt->pkttype == PKT_SIGNATURE ) { - fprintf(stderr, " class=%02x keyid=%08lX ts=%lu\n", - node->pkt->pkt.signature->sig_class, - (ulong)node->pkt->pkt.signature->keyid[1], - (ulong)node->pkt->pkt.signature->timestamp); - } - else if( node->pkt->pkttype == PKT_GPG_CONTROL ) { - fprintf(stderr, " ctrl=%d len=%u\n", - node->pkt->pkt.gpg_control->control, - (unsigned int)node->pkt->pkt.gpg_control->datalen); - } - else if( node->pkt->pkttype == PKT_PUBLIC_KEY - || node->pkt->pkttype == PKT_PUBLIC_SUBKEY ) { - PKT_public_key *pk = node->pkt->pkt.public_key; - fprintf(stderr, " keyid=%08lX a=%d u=%d %c%c%c%c\n", - (ulong)keyid_from_pk( pk, NULL ), - pk->pubkey_algo, pk->pubkey_usage, - pk->has_expired? 'e':'.', - pk->is_revoked? 'r':'.', - pk->is_valid? 'v':'.', - pk->mdc_feature? 'm':'.'); - } - else - fputs("\n", stderr); + log_debug ("node %p %02x/%02x type=%s", + node, node->flag, node->private_flag, s); + if (node->pkt->pkttype == PKT_USER_ID) + { + PKT_user_id *uid = node->pkt->pkt.user_id; + log_printf (" \""); + es_write_sanitized (log_get_stream (), uid->name, uid->len, + NULL, NULL); + log_printf ("\" %c%c%c%c\n", + uid->is_expired? 'e':'.', + uid->is_revoked? 'r':'.', + uid->created? 'v':'.', + uid->is_primary? 'p':'.' ); + } + else if (node->pkt->pkttype == PKT_SIGNATURE) + { + log_printf (" class=%02x keyid=%08lX ts=%lu\n", + node->pkt->pkt.signature->sig_class, + (ulong)node->pkt->pkt.signature->keyid[1], + (ulong)node->pkt->pkt.signature->timestamp); + } + else if (node->pkt->pkttype == PKT_GPG_CONTROL) + { + log_printf (" ctrl=%d len=%u\n", + node->pkt->pkt.gpg_control->control, + (unsigned int)node->pkt->pkt.gpg_control->datalen); + } + else if (node->pkt->pkttype == PKT_PUBLIC_KEY + || node->pkt->pkttype == PKT_PUBLIC_SUBKEY) + { + PKT_public_key *pk = node->pkt->pkt.public_key; + + log_printf (" keyid=%08lX a=%d u=%d %c%c%c%c\n", + (ulong)keyid_from_pk( pk, NULL ), + pk->pubkey_algo, pk->pubkey_usage, + pk->has_expired? 'e':'.', + pk->is_revoked? 'r':'.', + pk->is_valid? 'v':'.', + pk->mdc_feature? 'm':'.'); + } + + log_flush (); } } Modified: trunk/g10/keyedit.c =================================================================== --- trunk/g10/keyedit.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/keyedit.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -188,7 +188,9 @@ printf(":"); if(sig->trust_regexp) - print_string(stdout,sig->trust_regexp,strlen(sig->trust_regexp),':'); + es_write_sanitized (es_stdout, + sig->trust_regexp, strlen (sig->trust_regexp), + ":", NULL); printf("::%02x%c\n",sig->sig_class,sig->flags.exportable?'x':'l'); @@ -1100,7 +1102,7 @@ * We use only one passphrase for all keys. */ static int -change_passphrase( KBNODE keyblock ) +change_passphrase (KBNODE keyblock, int *r_err) { int rc = 0; int changed=0; @@ -1264,6 +1266,8 @@ leave: xfree( passphrase ); set_next_passphrase( NULL ); + if (r_err) + *r_err = rc; return changed && !rc; } @@ -2150,7 +2154,7 @@ break; case cmdPASSWD: - if( change_passphrase( sec_keyblock ) ) + if (change_passphrase (sec_keyblock, NULL)) sec_modified = 1; break; @@ -2372,11 +2376,8 @@ if (err) goto leave; - if (!change_passphrase (keyblock)) - { - err = gpg_error (GPG_ERR_GENERAL); - goto leave; - } + if (!change_passphrase (keyblock, &err)) + goto leave; err = keydb_update_keyblock (kdh, keyblock); if (err) @@ -2393,6 +2394,8 @@ username, gpg_strerror (err)); write_status_error ("keyedit.passwd", err); } + else + write_status_text (STATUS_SUCCESS, "keyedit.passwd"); } @@ -2685,7 +2688,7 @@ if(uid->attrib_data) printf ("%u %lu",uid->numattribs,uid->attrib_len); else - print_string (stdout, uid->name, uid->len, ':'); + es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL); putchar (':'); /* signature class */ @@ -4791,7 +4794,7 @@ else { printf("uid:::::::::"); - print_string (stdout, uid->name, uid->len, ':'); + es_write_sanitized (es_stdout, uid->name, uid->len, ":", NULL); } printf("\n"); Modified: trunk/g10/keylist.c =================================================================== --- trunk/g10/keylist.c 2010-03-12 18:46:33 UTC (rev 5293) +++ trunk/g10/keylist.c 2010-03-15 11:15:45 UTC (rev 5294) @@ -54,7 +54,7 @@ }; /* The stream used to write attribute packets to. */ -static FILE *attrib_fp = NULL; +static estream_t attrib_fp; /* List the keys. If list is NULL, all available keys are listed. @@ -71,32 +71,32 @@ read_trust_options (&trust_model, &created, &nextcheck, &marginals, &completes, &cert_depth); - printf ("tru:"); + es_fprintf (es_stdout, "tru:"); if (nextcheck && nextcheck <= make_timestamp ()) - printf ("o"); + es_fprintf (es_stdout, "o"); if (trust_model != opt.trust_model) - printf ("t"); + es_fprintf (es_stdout, "t"); if (opt.trust_model == TM_PGP || opt.trust_model == TM_CLASSIC) { if (marginals != opt.marginals_needed) - printf ("m"); + es_fprintf (es_stdout, "m"); if (completes != opt.completes_needed) - printf ("c"); + es_fprintf (es_stdout, "c"); if (cert_depth != opt.max_cert_depth) - printf ("d"); + es_fprintf (es_stdout, "d"); } - printf (":%d:%lu:%lu", trust_model, created, nextcheck); + es_fprintf (es_stdout, ":%d:%lu:%lu", trust_model, created, nextcheck); /* Only show marginals, completes, and cert_depth in the classic or PGP trust models since they are not meaningful otherwise. */ if (trust_model == TM_PGP || trust_model == TM_CLASSIC) - printf (":%d:%d:%d", marginals, completes, cert_depth); + es_fprintf (es_stdout, ":%d:%d:%d", marginals, completes, cert_depth); - printf ("\n"); + es_fprintf (es_stdout, "\n"); } /* We need to do the stale check right here because it might need to @@ -147,7 +147,7 @@ the tty output interface is used, otherwise output is directted to the given stream. */ void -print_pubkey_info (FILE * fp, PKT_public_key * pk) +print_pubkey_info (estream_t fp, PKT_public_key * pk) { u32 keyid[2]; char *p; @@ -162,15 +162,11 @@ p = get_user_id_native (keyid); if (fp) - fprintf (fp, "pub %4u%c/%s %s %s\n", - nbits_from_pk (pk), - pubkey_letter (pk->pubkey_algo), - keystr (keyid), datestr_from_pk (pk), p); - else - tty_printf ("\npub %4u%c/%s %s %s\n", - nbits_from_pk (pk), pubkey_letter (pk->pubkey_algo), - keystr (keyid), datestr_from_pk (pk), p); - + tty_printf ("\n"); + tty_fprintf (fp, "pub %4u%c/%s %s %s\n", + nbits_from_pk (pk), + pubkey_letter (pk->pubkey_algo), + keystr (keyid), datestr_from_pk (pk), p); xfree (p); } @@ -178,7 +174,7 @@ /* Print basic information of a secret key including the card serial From cvs at cvs.gnupg.org Mon Mar 15 13:04:54 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 15 Mar 2010 13:04:54 +0100 Subject: [svn] gpgme - r1458 - in trunk: . src Message-ID: Author: wk Date: 2010-03-15 13:04:53 +0100 (Mon, 15 Mar 2010) New Revision: 1458 Modified: trunk/ChangeLog trunk/configure.ac trunk/src/ChangeLog trunk/src/gpgme.h.in Log: Make generated header file read-only in an emacs buffer. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-12 22:24:13 UTC (rev 1457) +++ trunk/ChangeLog 2010-03-15 12:04:53 UTC (rev 1458) @@ -1,3 +1,8 @@ +2010-03-15 Werner Koch + + * configure.ac (emacs_local_vars_begin) + (emacs_local_vars_read_only, emacs_local_vars_end): New. + 2010-01-22 Werner Koch * autogen.sh (--build-w32): Add --with-libassuan-prefix. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-12 22:24:13 UTC (rev 1457) +++ trunk/src/ChangeLog 2010-03-15 12:04:53 UTC (rev 1458) @@ -1,3 +1,8 @@ +2010-03-15 Werner Koch + + * gpgme.h.in: Add autoconf template to set generated file to + read-only in an emacs buffer. + 2010-03-12 Werner Koch * gpgme.h.in (GPGME_STATUS_SUCCESS): Use the right file for the Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-12 22:24:13 UTC (rev 1457) +++ trunk/configure.ac 2010-03-15 12:04:53 UTC (rev 1458) @@ -871,6 +871,12 @@ [#include ]) +# A substitution to set generated files in a Emacs buffer to read-only. +AC_SUBST(emacs_local_vars_begin, ['Local Variables:']) +AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t']) +AC_SUBST(emacs_local_vars_end, ['End:']) + + # Last check. die=no if test "$require_libassuan" = "no"; then Modified: trunk/src/gpgme.h.in =================================================================== --- trunk/src/gpgme.h.in 2010-03-12 22:24:13 UTC (rev 1457) +++ trunk/src/gpgme.h.in 2010-03-15 12:04:53 UTC (rev 1458) @@ -2101,3 +2101,8 @@ } #endif #endif /* GPGME_H */ +/* + at emacs_local_vars_begin@ + at emacs_local_vars_read_only@ + at emacs_local_vars_end@ +*/ From cvs at cvs.gnupg.org Mon Mar 15 13:21:59 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 15 Mar 2010 13:21:59 +0100 Subject: [svn] gpg-error - r237 - in trunk: . src Message-ID: Author: wk Date: 2010-03-15 13:21:59 +0100 (Mon, 15 Mar 2010) New Revision: 237 Modified: trunk/ChangeLog trunk/configure.ac trunk/src/mkheader.awk trunk/src/w32-add.h Log: Fix type in macro name. Set generated header to read-only. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-09 11:35:25 UTC (rev 236) +++ trunk/ChangeLog 2010-03-15 12:21:59 UTC (rev 237) @@ -1,3 +1,9 @@ +2010-03-15 Werner Koch + + * src/mkheader.awk: Add emacs local-var line. + + * src/w32-add.h (gettext_localename): Fix type in name. + 2010-03-09 Werner Koch * src/w32-add.h [!GPG_ERR_ENABLE_GETTEXT_MACROS]: Do not provide Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-09 11:35:25 UTC (rev 236) +++ trunk/configure.ac 2010-03-15 12:21:59 UTC (rev 237) @@ -172,7 +172,6 @@ AM_CONDITIONAL([LANGUAGES_SOME], [test "x$enable_languages" != xno]) - # Substitution AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([po/Makefile.in m4/Makefile]) Modified: trunk/src/mkheader.awk =================================================================== --- trunk/src/mkheader.awk 2010-03-09 11:35:25 UTC (rev 236) +++ trunk/src/mkheader.awk 2010-03-15 12:21:59 UTC (rev 237) @@ -71,11 +71,12 @@ extra_body = 0; gpg_error_h = 0; - print "/* Output of mkheader.awk. DO NOT EDIT. */"; + print "/* Output of mkheader.awk. DO NOT EDIT. -*- buffer-read-only: t -*- */"; print ""; } + sources_header { if ($1 ~ /^[0123456789]+$/) { Modified: trunk/src/w32-add.h =================================================================== --- trunk/src/w32-add.h 2010-03-09 11:35:25 UTC (rev 236) +++ trunk/src/w32-add.h 2010-03-15 12:21:59 UTC (rev 237) @@ -33,7 +33,7 @@ # define dgettext(a,b) _gpg_w32_dgettext ((a), (b)) # define ngettext(a,b,c) _gpg_w32_dngettext (NULL, (a), (b), (c)) # define dngettext(a,b,c,d) _gpg_w32_dngettext ((a), (b), (c), (d)) -# define gettext_localname() _gpg_w32_gettext_localename () +# define gettext_localename() _gpg_w32_gettext_localename () # define gettext_use_utf8(a) _gpg_w32_gettext_use_utf8 (a) #endif /*GPG_ERR_ENABLE_GETTEXT_MACROS*/ From cvs at cvs.gnupg.org Mon Mar 15 13:27:29 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 15 Mar 2010 13:27:29 +0100 Subject: [svn] gcry - r1423 - in trunk: . src Message-ID: Author: wk Date: 2010-03-15 13:27:29 +0100 (Mon, 15 Mar 2010) New Revision: 1423 Modified: trunk/ChangeLog trunk/THANKS trunk/configure.ac trunk/src/ChangeLog trunk/src/gcrypt.h.in Log: Help not to edit a generated buffer. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-02-22 11:35:38 UTC (rev 1422) +++ trunk/ChangeLog 2010-03-15 12:27:29 UTC (rev 1423) @@ -1,3 +1,8 @@ +2010-03-15 Werner Koch + + * configure.ac (emacs_local_vars_begin) + (emacs_local_vars_read_only, emacs_local_vars_end): New. + 2010-01-21 Werner Koch * compat/Makefile.am: New. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-02-22 11:35:38 UTC (rev 1422) +++ trunk/src/ChangeLog 2010-03-15 12:27:29 UTC (rev 1423) @@ -1,3 +1,8 @@ +2010-03-15 Werner Koch + + * gcrypt.h.in: Add autoconf template to set generated file to + read-only in an Emacs buffer. + 2010-01-21 Werner Koch * Makefile.am (arch_gpg_error_cflags, arch_gpg_error_libs): New. Modified: trunk/THANKS =================================================================== --- trunk/THANKS 2010-02-22 11:35:38 UTC (rev 1422) +++ trunk/THANKS 2010-03-15 12:27:29 UTC (rev 1423) @@ -7,6 +7,7 @@ Anand Kumria wildfire at progsoc.uts.edu.au Andreas Metzler ametzler at downhill.at.eu.org Ariel T Glenn ariel at columbia.edu +Aurelien Jarno aurel32 at debian.org Ben Hutchings ben decadent org uk Bodo Moeller Bodo_Moeller at public.uni-hamburg.de Brenno de Winter brenno at dewinter.com Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-02-22 11:35:38 UTC (rev 1422) +++ trunk/configure.ac 2010-03-15 12:27:29 UTC (rev 1423) @@ -31,8 +31,11 @@ m4_define([svn_revision], m4_esyscmd([printf "%d" $(svn info 2>/dev/null \ | sed -n '/^Revision:/ s/[^0-9]//gp'|head -1)])) +m4_define([git_revision], m4_esyscmd([git branch -v 2>/dev/null \ + | awk '/^\* / {printf "%s",$3}'])) AC_INIT([libgcrypt], - [my_version[]m4_if(my_issvn,[yes],[-svn[]svn_revision])], + [my_version[]m4_if(my_issvn,[yes], + [m4_if(git_revision,[],[-svn[]svn_revision],[-git[]git_revision])])], [bug-libgcrypt at gnupg.org]) # LT Version numbers, remember to change them just *before* a release. # (Interfaces removed: CURRENT++, AGE=0, REVISION=0) @@ -1140,7 +1143,12 @@ [Subversion revision used to build this package]) +# Substitutions to set generated files in a Emacs buffer to read-only. +AC_SUBST(emacs_local_vars_begin, ['Local Variables:']) +AC_SUBST(emacs_local_vars_read_only, ['buffer-read-only: t']) +AC_SUBST(emacs_local_vars_end, ['End:']) + # And create the files. AC_CONFIG_FILES([ Makefile Modified: trunk/src/gcrypt.h.in =================================================================== --- trunk/src/gcrypt.h.in 2010-02-22 11:35:38 UTC (rev 1422) +++ trunk/src/gcrypt.h.in 2010-03-15 12:27:29 UTC (rev 1423) @@ -1831,3 +1831,8 @@ } #endif #endif /* _GCRYPT_H */ +/* + at emacs_local_vars_begin@ + at emacs_local_vars_read_only@ + at emacs_local_vars_end@ +*/ From cvs at cvs.gnupg.org Mon Mar 15 14:08:51 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 15 Mar 2010 14:08:51 +0100 Subject: [svn] GnuPG - r5295 - in trunk: . common tools Message-ID: Author: wk Date: 2010-03-15 14:08:51 +0100 (Mon, 15 Mar 2010) New Revision: 5295 Modified: trunk/autogen.sh trunk/common/ChangeLog trunk/common/localename.c trunk/common/logging.c trunk/common/util.h trunk/common/w32-afunix.c trunk/tools/ChangeLog trunk/tools/gpgconf-comp.c Log: Builds again for W32. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/common/ChangeLog 2010-03-15 13:08:51 UTC (rev 5295) @@ -1,3 +1,12 @@ +2010-03-15 Werner Koch + + * logging.c (S_IRGRP, S_IROTH, S_IWGRP, S_IWOTH) [W32]: New. + (fun_writer, set_file_fd) [W32]: Disable socket code. + + * localename.c: Include gpg-error.h. + + * util.h (GPG_ERR_NOT_ENABLED): Remove this temporary definition. + 2010-03-12 Werner Koch * status.h (STATUS_ENTER): New. Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/tools/ChangeLog 2010-03-15 13:08:51 UTC (rev 5295) @@ -1,3 +1,8 @@ +2010-03-15 Werner Koch + + * gpgconf-comp.c (my_dgettext): + s/gettext_select_utf8/gettext_use_utf8/. + 2010-03-10 Werner Koch * Makefile.am (common_libs): Remove libjnlib.a. Modified: trunk/autogen.sh =================================================================== --- trunk/autogen.sh 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/autogen.sh 2010-03-15 13:08:51 UTC (rev 5295) @@ -123,7 +123,8 @@ --with-zlib=${w32root} \ --with-regex=${w32root} \ --with-pth-prefix=${w32root} \ - --with-adns=${w32root} "$@" + --with-adns=${w32root} \ + --disable-g13 "$@" rc=$? exit $rc fi Modified: trunk/common/localename.c =================================================================== --- trunk/common/localename.c 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/common/localename.c 2010-03-15 13:08:51 UTC (rev 5295) @@ -29,6 +29,7 @@ #ifdef HAVE_LOCALE_H #include #endif +#include /* We need gettext_localename for W32. */ #include "../common/w32help.h" @@ -101,7 +102,7 @@ const char *s; #ifdef HAVE_W32_SYSTEM - /* We use the localname function from ../common/w32-gettext.c. */ + /* We use the localename function libgpg-error. */ s = gettext_localename (); #else s = do_nl_locale_name (LC_MESSAGES, "LC_MESSAGES"); Modified: trunk/common/logging.c =================================================================== --- trunk/common/logging.c 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/common/logging.c 2010-03-15 13:08:51 UTC (rev 5295) @@ -30,20 +30,28 @@ #include #include #ifndef HAVE_W32_SYSTEM -#include -#include -#endif /*!HAVE_W32_SYSTEM*/ +# include +# include +#endif /*HAVE_W32_SYSTEM*/ #include #include #include + #define JNLIB_NEED_LOG_LOGV 1 #define JNLIB_NEED_AFLOCAL 1 #include "libjnlib-config.h" #include "logging.h" +#ifdef HAVE_W32_SYSTEM +# define S_IRGRP S_IRUSR +# define S_IROTH S_IRUSR +# define S_IWGRP S_IWUSR +# define S_IWOTH S_IWUSR +#endif + static estream_t logstream; static int log_socket = -1; static char prefix_buffer[80]; @@ -121,6 +129,7 @@ processes often close stderr and by writing to file descriptor 2 we might send the log message to a file not intended for logging (e.g. a pipe or network connection). */ +#ifndef HAVE_W32_SYSTEM if (cookie->want_socket && cookie->fd == -1) { /* Not yet open or meanwhile closed due to an error. */ @@ -177,6 +186,7 @@ cookie->is_socket = 1; } } +#endif /*HAVE_W32_SYSTEM*/ log_socket = cookie->fd; if (cookie->fd != -1 && !writen (cookie->fd, buffer, size)) @@ -239,6 +249,7 @@ fd = fileno (stderr); } +#ifndef HAVE_W32_SYSTEM if (name) { want_socket = (!strncmp (name, "socket://", 9) && name[9]); @@ -246,6 +257,7 @@ name += 9; } else +#endif /*HAVE_W32_SYSTEM*/ { want_socket = 0; } Modified: trunk/common/util.h =================================================================== --- trunk/common/util.h 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/common/util.h 2010-03-15 13:08:51 UTC (rev 5295) @@ -25,11 +25,6 @@ #include /* We need errno. */ #include /* We need gpg_error_t. */ -/* Add error codes available only in newer versions of libgpg-error. */ -#ifndef GPG_ERR_NOT_ENABLED -#define GPG_ERR_NOT_ENABLED 179 -#endif - /* Hash function used with libksba. */ #define HASH_FNC ((void (*)(void *, const void*,size_t))gcry_md_write) Modified: trunk/common/w32-afunix.c =================================================================== --- trunk/common/w32-afunix.c 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/common/w32-afunix.c 2010-03-15 13:08:51 UTC (rev 5295) @@ -17,7 +17,7 @@ * License along with this program; if not, see . */ -/* Use of this code is preprecated - you better use the sockt wrappers +/* Use of this code is deprecated - you better use the socket wrappers from libassuan. */ #ifdef _WIN32 @@ -51,15 +51,14 @@ fclose (fp); if (!nread) { -#warning remove this file - jnlib_set_errno (EIO); + gpg_err_set_errno (EIO); return -1; } buffer[nread] = 0; aval = atoi (buffer); if (aval < 1 || aval > 65535) { - jnlib_set_errno (EINVAL); + gpg_err_set_errno (EINVAL); return -1; } *port = (unsigned int)aval; @@ -67,7 +66,7 @@ ; if (*p != '\n' || nread != 17) { - jnlib_set_errno (EINVAL); + gpg_err_set_errno (EINVAL); return -1; } p++; nread--; @@ -127,7 +126,7 @@ ret = send (sockfd, nonce, 16, 0); if (ret >= 0 && ret != 16) { - jnlib_set_errno (EIO); + gpg_err_set_errno (EIO); ret = -1; } } Modified: trunk/tools/gpgconf-comp.c =================================================================== --- trunk/tools/gpgconf-comp.c 2010-03-15 11:15:45 UTC (rev 5294) +++ trunk/tools/gpgconf-comp.c 2010-03-15 13:08:51 UTC (rev 5295) @@ -1144,7 +1144,7 @@ if (!switched_codeset) { switched_codeset = 1; - gettext_select_utf8 (1); + gettext_use_utf8 (1); } if (!strcmp (domain, "gnupg")) From cvs at cvs.gnupg.org Tue Mar 16 14:04:42 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 16 Mar 2010 14:04:42 +0100 Subject: [svn] assuan - r361 - trunk/src Message-ID: Author: wk Date: 2010-03-16 14:04:42 +0100 (Tue, 16 Mar 2010) New Revision: 361 Added: trunk/src/system-posix.c trunk/src/system-w32.c trunk/src/system-w32ce.c Modified: trunk/src/ChangeLog trunk/src/Makefile.am trunk/src/system.c Log: Refactored platform system code. [The diff below has been truncated] Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-11 12:00:10 UTC (rev 360) +++ trunk/src/ChangeLog 2010-03-16 13:04:42 UTC (rev 361) @@ -1,3 +1,9 @@ +2010-03-16 Werner Koch + + * system.c: For better readability move platform dependend code to .. + * system-posix.c, system-w32.c, system-w32ce.c: .. New. + * Makefile.am (common_sources): Account for this change. + 2010-03-11 Werner Koch * assuan-defs.h [!HAVE_VASPRINTF]: Add macros vasprintf and asprintf. Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2010-03-11 12:00:10 UTC (rev 360) +++ trunk/src/Makefile.am 2010-03-16 13:04:42 UTC (rev 361) @@ -57,7 +57,18 @@ assuan-socket.c if HAVE_W32_SYSTEM +if HAVE_W32CE_SYSTEM +common_sources += system-w32ce.c +else +common_sources += system-w32.c +endif +else +common_sources += system-posix.c +endif + +if HAVE_W32_SYSTEM + LTRCCOMPILE = $(LIBTOOL) --mode=compile $(RC) \ `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \ sed -e 's/-I/--include-dir /g;s/-D/--define /g'` Added: trunk/src/system-posix.c =================================================================== --- trunk/src/system-posix.c (rev 0) +++ trunk/src/system-posix.c 2010-03-16 13:04:42 UTC (rev 361) @@ -0,0 +1,339 @@ +/* system-posix.c - System support functions. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. + + This file is part of Assuan. + + Assuan is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Assuan is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see . + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +/* Solaris 8 needs sys/types.h before time.h. */ +#include +#include +#include +#include + +#include "assuan-defs.h" +#include "debug.h" + +#ifdef _POSIX_OPEN_MAX +#define MAX_OPEN_FDS _POSIX_OPEN_MAX +#else +#define MAX_OPEN_FDS 20 +#endif + + + + +assuan_fd_t +assuan_fdopen (int fd) +{ + return dup (fd); +} + + + +/* Sleep for the given number of microseconds. Default + implementation. */ +void +__assuan_usleep (assuan_context_t ctx, unsigned int usec) +{ + if (! usec) + return; + +#ifdef HAVE_NANOSLEEP + { + struct timespec req; + struct timespec rem; + + req.tv_sec = 0; + req.tv_nsec = usec * 1000; + + while (nanosleep (&req, &rem) < 0 && errno == EINTR) + req = rem; + } +#else + { + struct timeval tv; + + tv.tv_sec = usec / 1000000; + tv.tv_usec = usec % 1000000; + select (0, NULL, NULL, NULL, &tv); + } +#endif +} + + + +/* Create a pipe with one inheritable end. Easy for Posix. */ +int +__assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx) +{ + return pipe (fd); +} + + + +/* Close the given file descriptor, created with _assuan_pipe or one + of the socket functions. Easy for Posix. */ +int +__assuan_close (assuan_context_t ctx, assuan_fd_t fd) +{ + return close (fd); +} + + + +static ssize_t +__assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size) +{ + return read (fd, buffer, size); +} + + + +static ssize_t +__assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer, + size_t size) +{ + return write (fd, buffer, size); +} + + + +static int +__assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags) +{ + int ret; + + do + ret = recvmsg (fd, msg, flags); + while (ret == -1 && errno == EINTR); + + return ret; +} + + + +static int +__assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags) +{ + int ret; + + do + ret = sendmsg (fd, msg, flags); + while (ret == -1 && errno == EINTR); + + return ret; +} + + + +static int +writen (int fd, const char *buffer, size_t length) +{ + while (length) + { + int nwritten = write (fd, buffer, length); + + if (nwritten < 0) + { + if (errno == EINTR) + continue; + return -1; /* write error */ + } + length -= nwritten; + buffer += nwritten; + } + return 0; /* okay */ +} + + +int +__assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, + assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags) +{ + int pid; + + pid = fork (); + if (pid < 0) + return -1; + + if (pid == 0) + { + /* Child process (server side). */ + int i; + int n; + char errbuf[512]; + int *fdp; + int fdnul; + + if (atfork) + atfork (atforkvalue, 0); + + fdnul = open ("/dev/null", O_WRONLY); + if (fdnul == -1) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx, + "can't open `/dev/null': %s", strerror (errno)); + _exit (4); + } + + /* Dup handles to stdin/stdout. */ + if (fd_out != STDOUT_FILENO) + { + if (dup2 (fd_out == ASSUAN_INVALID_FD ? fdnul : fd_out, + STDOUT_FILENO) == -1) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx, + "dup2 failed in child: %s", strerror (errno)); + _exit (4); + } + } + + if (fd_in != STDIN_FILENO) + { + if (dup2 (fd_in == ASSUAN_INVALID_FD ? fdnul : fd_in, + STDIN_FILENO) == -1) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx, + "dup2 failed in child: %s", strerror (errno)); + _exit (4); + } + } + + /* Dup stderr to /dev/null unless it is in the list of FDs to be + passed to the child. */ + fdp = fd_child_list; + if (fdp) + { + for (; *fdp != -1 && *fdp != STDERR_FILENO; fdp++) + ; + } + if (!fdp || *fdp == -1) + { + if (dup2 (fdnul, STDERR_FILENO) == -1) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "pipe_connect_unix", ctx, + "dup2(dev/null, 2) failed: %s", strerror (errno)); + _exit (4); + } + } + close (fdnul); + + /* Close all files which will not be duped and are not in the + fd_child_list. */ + n = sysconf (_SC_OPEN_MAX); + if (n < 0) + n = MAX_OPEN_FDS; + for (i = 0; i < n; i++) + { + if (i == STDIN_FILENO || i == STDOUT_FILENO || i == STDERR_FILENO) + continue; + fdp = fd_child_list; + if (fdp) + { + while (*fdp != -1 && *fdp != i) + fdp++; + } + + if (!(fdp && *fdp != -1)) + close (i); + } + gpg_err_set_errno (0); + + if (! name) + { + /* No name and no args given, thus we don't do an exec + but continue the forked process. */ + *argv = "server"; + + /* FIXME: Cleanup. */ + return 0; + } + + execv (name, (char *const *) argv); + + /* oops - use the pipe to tell the parent about it */ + snprintf (errbuf, sizeof(errbuf)-1, + "ERR %d can't exec `%s': %.50s\n", + _assuan_error (ctx, GPG_ERR_ASS_SERVER_START), + name, strerror (errno)); + errbuf[sizeof(errbuf)-1] = 0; + writen (1, errbuf, strlen (errbuf)); + _exit (4); + } + + if (! name) + *argv = "client"; + + *r_pid = pid; + + return 0; +} + + + +/* FIXME: Add some sort of waitpid function that covers GPGME and + gpg-agent's use of assuan. */ +static pid_t +__assuan_waitpid (assuan_context_t ctx, pid_t pid, int nowait, + int *status, int options) +{ + /* We can't just release the PID, a waitpid is mandatory. But + NOWAIT in POSIX systems just means the caller already did the + waitpid for this child. */ + if (! nowait) + return waitpid (pid, NULL, 0); + return 0; +} + + + +int +__assuan_socketpair (assuan_context_t ctx, int namespace, int style, + int protocol, assuan_fd_t filedes[2]) +{ + return socketpair (namespace, style, protocol, filedes); +} + + + +/* The default system hooks for assuan contexts. */ +struct assuan_system_hooks _assuan_system_hooks = + { + ASSUAN_SYSTEM_HOOKS_VERSION, + __assuan_usleep, + __assuan_pipe, + __assuan_close, + __assuan_read, + __assuan_write, + __assuan_recvmsg, + __assuan_sendmsg, + __assuan_spawn, + __assuan_waitpid, + __assuan_socketpair + }; Added: trunk/src/system-w32.c =================================================================== --- trunk/src/system-w32.c (rev 0) +++ trunk/src/system-w32.c 2010-03-16 13:04:42 UTC (rev 361) @@ -0,0 +1,466 @@ +/* system-w32.c - System support functions for Windows. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. + + This file is part of Assuan. + + Assuan is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Assuan is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see . + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "assuan-defs.h" +#include "debug.h" + + + +assuan_fd_t +assuan_fdopen (int fd) +{ + assuan_fd_t ifd = (assuan_fd_t) _get_osfhandle (fd); + assuan_fd_t ofd; + + if (! DuplicateHandle(GetCurrentProcess(), ifd, + GetCurrentProcess(), &ofd, 0, + TRUE, DUPLICATE_SAME_ACCESS)) + { + gpg_err_set_errno (EIO); + return ASSUAN_INVALID_FD; + } + return ofd; +} + + + +/* Sleep for the given number of microseconds. Default + implementation. */ +void +__assuan_usleep (assuan_context_t ctx, unsigned int usec) +{ + if (!usec) + return; + + Sleep (usec / 1000); +} + + + +/* Create a pipe with one inheritable end. Default implementation. */ +int +__assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx) +{ + HANDLE rh; + HANDLE wh; + HANDLE th; + SECURITY_ATTRIBUTES sec_attr; + + memset (&sec_attr, 0, sizeof (sec_attr)); + sec_attr.nLength = sizeof (sec_attr); + sec_attr.bInheritHandle = FALSE; + + if (!CreatePipe (&rh, &wh, &sec_attr, 0)) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx, + "CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1)); + gpg_err_set_errno (EIO); + return -1; + } + + if (! DuplicateHandle (GetCurrentProcess(), (inherit_idx == 0) ? rh : wh, + GetCurrentProcess(), &th, 0, + TRUE, DUPLICATE_SAME_ACCESS )) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx, + "DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1)); + CloseHandle (rh); + CloseHandle (wh); + gpg_err_set_errno (EIO); + return -1; + } + if (inherit_idx == 0) + { + CloseHandle (rh); + rh = th; + } + else + { + CloseHandle (wh); + wh = th; + } + + fd[0] = rh; + fd[1] = wh; + + return 0; +} + + + +/* Close the given file descriptor, created with _assuan_pipe or one + of the socket functions. Default implementation. */ +int +__assuan_close (assuan_context_t ctx, assuan_fd_t fd) +{ + int rc = closesocket (HANDLE2SOCKET(fd)); + if (rc) + gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()) ); + if (rc && WSAGetLastError () == WSAENOTSOCK) + { + rc = CloseHandle (fd); + if (rc) + /* FIXME. */ + gpg_err_set_errno (EIO); + } + return rc; +} + + + +static ssize_t +__assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size) +{ + /* Due to the peculiarities of the W32 API we can't use read for a + network socket and thus we try to use recv first and fallback to + read if recv detects that it is not a network socket. */ + int res; + + res = recv (HANDLE2SOCKET (fd), buffer, size, 0); + if (res == -1) + { + switch (WSAGetLastError ()) + { + case WSAENOTSOCK: + { + DWORD nread = 0; + + res = ReadFile (fd, buffer, size, &nread, NULL); + if (! res) + { + switch (GetLastError ()) + { + case ERROR_BROKEN_PIPE: + gpg_err_set_errno (EPIPE); + break; + + default: + gpg_err_set_errno (EIO); + } + res = -1; + } + else + res = (int) nread; + } + break; + + case WSAEWOULDBLOCK: + gpg_err_set_errno (EAGAIN); + break; + + case ERROR_BROKEN_PIPE: + gpg_err_set_errno (EPIPE); + break; + + default: + gpg_err_set_errno (EIO); + break; + } + } + return res; +} + + + +static ssize_t +__assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer, + size_t size) +{ + /* Due to the peculiarities of the W32 API we can't use write for a + network socket and thus we try to use send first and fallback to + write if send detects that it is not a network socket. */ + int res; + + res = send (HANDLE2SOCKET (fd), buffer, size, 0); + if (res == -1 && WSAGetLastError () == WSAENOTSOCK) + { + DWORD nwrite; + + res = WriteFile (fd, buffer, size, &nwrite, NULL); + if (! res) + { + switch (GetLastError ()) + { + case ERROR_BROKEN_PIPE: + case ERROR_NO_DATA: + gpg_err_set_errno (EPIPE); + break; + + default: + gpg_err_set_errno (EIO); + break; + } + res = -1; + } + else + res = (int) nwrite; + } + return res; +} + + + +static int +__assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags) +{ + gpg_err_set_errno (ENOSYS); + return -1; +} + + + + +static int +__assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags) +{ + gpg_err_set_errno (ENOSYS); + return -1; +} + + + + +/* Build a command line for use with W32's CreateProcess. On success + CMDLINE gets the address of a newly allocated string. */ +static int +build_w32_commandline (assuan_context_t ctx, const char * const *argv, + char **cmdline) +{ + int i, n; + const char *s; + char *buf, *p; + + *cmdline = NULL; + n = 0; + for (i=0; (s = argv[i]); i++) + { + n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ + for (; *s; s++) + if (*s == '\"') + n++; /* Need to double inner quotes. */ + } + n++; + + buf = p = _assuan_malloc (ctx, n); + if (! buf) + return -1; + + for (i = 0; argv[i]; i++) + { + if (i) + p = stpcpy (p, " "); + if (! *argv[i]) /* Empty string. */ + p = stpcpy (p, "\"\""); + else if (strpbrk (argv[i], " \t\n\v\f\"")) + { + p = stpcpy (p, "\""); + for (s = argv[i]; *s; s++) + { + *p++ = *s; + if (*s == '\"') + *p++ = *s; + } + *p++ = '\"'; + *p = 0; + } + else + p = stpcpy (p, argv[i]); + } + + *cmdline= buf; + return 0; +} + + +int +__assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, + assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags) +{ + SECURITY_ATTRIBUTES sec_attr; + PROCESS_INFORMATION pi = + { + NULL, /* Returns process handle. */ + 0, /* Returns primary thread handle. */ + 0, /* Returns pid. */ + 0 /* Returns tid. */ + }; + STARTUPINFO si; + assuan_fd_t fd; + assuan_fd_t *fdp; + char *cmdline; + HANDLE nullfd = INVALID_HANDLE_VALUE; + + /* fixme: Actually we should set the "_assuan_pipe_connect_pid" env + variable. However this requires us to write a full environment + handler, because the strings are expected in sorted order. The + suggestion given in the MS Reference Library, to save the old + value, changeit, create proces and restore it, is not thread + safe. */ + + /* Build the command line. */ + if (build_w32_commandline (ctx, argv, &cmdline)) + return -1; + + /* Start the process. */ + memset (&sec_attr, 0, sizeof sec_attr); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + memset (&si, 0, sizeof si); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES; + /* FIXME: Dup to nul if ASSUAN_INVALID_FD. */ + si.hStdInput = fd_in; + si.hStdOutput = fd_out; + + /* Dup stderr to /dev/null unless it is in the list of FDs to be + passed to the child. */ + fd = assuan_fd_from_posix_fd (fileno (stderr)); + fdp = fd_child_list; + if (fdp) + { + for (; *fdp != ASSUAN_INVALID_FD && *fdp != fd; fdp++) + ; + } + if (!fdp || *fdp == ASSUAN_INVALID_FD) + { + nullfd = CreateFileW (L"nul", GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (nullfd == INVALID_HANDLE_VALUE) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx, + "can't open `nul': %s", _assuan_w32_strerror (ctx, -1)); + _assuan_free (ctx, cmdline); + gpg_err_set_errno (EIO); + return -1; + } + si.hStdError = nullfd; + } + else + si.hStdError = fd; + + /* Note: We inherit all handles flagged as inheritable. This seems + to be a security flaw but there seems to be no way of selecting + handles to inherit. */ + /* _assuan_log_printf ("CreateProcess, path=`%s' cmdline=`%s'\n", */ + /* name, cmdline); */ + if (!CreateProcess (name, /* Program to start. */ + cmdline, /* Command line arguments. */ + &sec_attr, /* Process security attributes. */ + &sec_attr, /* Thread security attributes. */ + TRUE, /* Inherit handles. */ + (CREATE_DEFAULT_ERROR_MODE + | ((flags & 128)? DETACHED_PROCESS : 0) + | GetPriorityClass (GetCurrentProcess ()) + | CREATE_SUSPENDED), /* Creation flags. */ + NULL, /* Environment. */ + NULL, /* Use current drive/directory. */ + &si, /* Startup information. */ + &pi /* Returns process information. */ + )) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "pipe_connect_w32", ctx, + "CreateProcess failed: %s", _assuan_w32_strerror (ctx, -1)); + _assuan_free (ctx, cmdline); + if (nullfd != INVALID_HANDLE_VALUE) + CloseHandle (nullfd); + + gpg_err_set_errno (EIO); + return -1; + } + + _assuan_free (ctx, cmdline); + if (nullfd != INVALID_HANDLE_VALUE) + CloseHandle (nullfd); + + ResumeThread (pi.hThread); + CloseHandle (pi.hThread); + + /* _assuan_log_printf ("CreateProcess ready: hProcess=%p hThread=%p" */ + /* " dwProcessID=%d dwThreadId=%d\n", */ + /* pi.hProcess, pi.hThread, */ + /* (int) pi.dwProcessId, (int) pi.dwThreadId); */ + + *r_pid = (pid_t) pi.hProcess; + + /* No need to modify peer process, as we don't change the handle + names. However this also means we are not safe, as we inherit + too many handles. Should use approach similar to gpgme and glib + using a helper process. */ + + return 0; +} + + + + +/* FIXME: Add some sort of waitpid function that covers GPGME and + gpg-agent's use of assuan. */ +static pid_t +__assuan_waitpid (assuan_context_t ctx, pid_t pid, int nowait, + int *status, int options) +{ + CloseHandle ((HANDLE) pid); + return 0; +} + + + +int +__assuan_socketpair (assuan_context_t ctx, int namespace, int style, + int protocol, assuan_fd_t filedes[2]) +{ + gpg_err_set_errno (ENOSYS); + return -1; +} + + +/* The default system hooks for assuan contexts. */ +struct assuan_system_hooks _assuan_system_hooks = + { + ASSUAN_SYSTEM_HOOKS_VERSION, + __assuan_usleep, + __assuan_pipe, + __assuan_close, + __assuan_read, + __assuan_write, + __assuan_recvmsg, + __assuan_sendmsg, + __assuan_spawn, + __assuan_waitpid, + __assuan_socketpair + }; Added: trunk/src/system-w32ce.c =================================================================== --- trunk/src/system-w32ce.c (rev 0) +++ trunk/src/system-w32ce.c 2010-03-16 13:04:42 UTC (rev 361) @@ -0,0 +1,464 @@ +/* system-w32ce.c - System support functions for WindowsCE. + Copyright (C) 2010 Free Software Foundation, Inc. + + This file is part of Assuan. + + Assuan is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Assuan is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see . + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "assuan-defs.h" +#include "debug.h" + + + +assuan_fd_t +assuan_fdopen (int fd) +{ + assuan_fd_t ifd = (assuan_fd_t)fd; + assuan_fd_t ofd; + + if (! DuplicateHandle(GetCurrentProcess(), ifd, + GetCurrentProcess(), &ofd, 0, + TRUE, DUPLICATE_SAME_ACCESS)) + { + gpg_err_set_errno (EIO); + return ASSUAN_INVALID_FD; + } + return ofd; +} + + + +/* Sleep for the given number of microseconds. Default + implementation. */ +void +__assuan_usleep (assuan_context_t ctx, unsigned int usec) +{ + if (!usec) + return; + + Sleep (usec / 1000); +} + + + +/* Create a pipe with one inheritable end. Default implementation. */ +int +__assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx) +{ + HANDLE rh; + HANDLE wh; + HANDLE th; + SECURITY_ATTRIBUTES sec_attr; + + memset (&sec_attr, 0, sizeof (sec_attr)); + sec_attr.nLength = sizeof (sec_attr); + sec_attr.bInheritHandle = FALSE; + + if (!CreatePipe (&rh, &wh, &sec_attr, 0)) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx, + "CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1)); + gpg_err_set_errno (EIO); + return -1; + } + + if (! DuplicateHandle (GetCurrentProcess(), (inherit_idx == 0) ? rh : wh, + GetCurrentProcess(), &th, 0, + TRUE, DUPLICATE_SAME_ACCESS )) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx, + "DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1)); + CloseHandle (rh); + CloseHandle (wh); + gpg_err_set_errno (EIO); + return -1; + } + if (inherit_idx == 0) + { + CloseHandle (rh); + rh = th; + } + else + { + CloseHandle (wh); + wh = th; + } + + fd[0] = rh; + fd[1] = wh; + + return 0; +} + + + +/* Close the given file descriptor, created with _assuan_pipe or one + of the socket functions. Default implementation. */ +int +__assuan_close (assuan_context_t ctx, assuan_fd_t fd) +{ + int rc = closesocket (HANDLE2SOCKET(fd)); + if (rc) + gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()) ); + if (rc && WSAGetLastError () == WSAENOTSOCK) + { + rc = CloseHandle (fd); + if (rc) + /* FIXME. */ + gpg_err_set_errno (EIO); + } + return rc; +} + + + +static ssize_t +__assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size) +{ + /* Due to the peculiarities of the W32 API we can't use read for a + network socket and thus we try to use recv first and fallback to + read if recv detects that it is not a network socket. */ + int res; + + res = recv (HANDLE2SOCKET (fd), buffer, size, 0); + if (res == -1) + { + switch (WSAGetLastError ()) + { + case WSAENOTSOCK: + { + DWORD nread = 0; + + res = ReadFile (fd, buffer, size, &nread, NULL); + if (! res) + { + switch (GetLastError ()) + { + case ERROR_BROKEN_PIPE: + gpg_err_set_errno (EPIPE); + break; + + default: + gpg_err_set_errno (EIO); + } + res = -1; + } + else + res = (int) nread; + } + break; + + case WSAEWOULDBLOCK: + gpg_err_set_errno (EAGAIN); + break; + + case ERROR_BROKEN_PIPE: + gpg_err_set_errno (EPIPE); + break; + + default: + gpg_err_set_errno (EIO); + break; + } + } + return res; +} + + + +static ssize_t +__assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer, + size_t size) +{ + /* Due to the peculiarities of the W32 API we can't use write for a + network socket and thus we try to use send first and fallback to + write if send detects that it is not a network socket. */ + int res; + + res = send (HANDLE2SOCKET (fd), buffer, size, 0); + if (res == -1 && WSAGetLastError () == WSAENOTSOCK) + { + DWORD nwrite; + + res = WriteFile (fd, buffer, size, &nwrite, NULL); + if (! res) + { + switch (GetLastError ()) + { + case ERROR_BROKEN_PIPE: + case ERROR_NO_DATA: + gpg_err_set_errno (EPIPE); + break; + + default: + gpg_err_set_errno (EIO); + break; + } + res = -1; + } + else + res = (int) nwrite; + } + return res; +} + + + +static int +__assuan_recvmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags) +{ + gpg_err_set_errno (ENOSYS); + return -1; +} + + + + +static int +__assuan_sendmsg (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags) +{ + gpg_err_set_errno (ENOSYS); + return -1; +} + + + + +/* Build a command line for use with W32's CreateProcess. On success + CMDLINE gets the address of a newly allocated string. */ +static int +build_w32_commandline (assuan_context_t ctx, const char * const *argv, + char **cmdline) +{ + int i, n; + const char *s; + char *buf, *p; + + *cmdline = NULL; + n = 0; + for (i=0; (s = argv[i]); i++) + { + n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ + for (; *s; s++) + if (*s == '\"') + n++; /* Need to double inner quotes. */ + } + n++; + + buf = p = _assuan_malloc (ctx, n); + if (! buf) + return -1; + + for (i = 0; argv[i]; i++) + { + if (i) + p = stpcpy (p, " "); + if (! *argv[i]) /* Empty string. */ + p = stpcpy (p, "\"\""); + else if (strpbrk (argv[i], " \t\n\v\f\"")) + { + p = stpcpy (p, "\""); + for (s = argv[i]; *s; s++) + { + *p++ = *s; + if (*s == '\"') + *p++ = *s; + } + *p++ = '\"'; + *p = 0; + } + else + p = stpcpy (p, argv[i]); + } + + *cmdline= buf; + return 0; +} + + +int +__assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, + assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags) +{ + SECURITY_ATTRIBUTES sec_attr; + PROCESS_INFORMATION pi = + { + NULL, /* Returns process handle. */ + 0, /* Returns primary thread handle. */ + 0, /* Returns pid. */ + 0 /* Returns tid. */ + }; + STARTUPINFO si; + assuan_fd_t fd; + assuan_fd_t *fdp; + char *cmdline; + HANDLE nullfd = INVALID_HANDLE_VALUE; + + /* fixme: Actually we should set the "_assuan_pipe_connect_pid" env + variable. However this requires us to write a full environment + handler, because the strings are expected in sorted order. The + suggestion given in the MS Reference Library, to save the old + value, changeit, create proces and restore it, is not thread + safe. */ + + /* Build the command line. */ + if (build_w32_commandline (ctx, argv, &cmdline)) + return -1; + + /* Start the process. */ + memset (&sec_attr, 0, sizeof sec_attr); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + memset (&si, 0, sizeof si); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES; + /* FIXME: Dup to nul if ASSUAN_INVALID_FD. */ + si.hStdInput = fd_in; + si.hStdOutput = fd_out; + + /* Dup stderr to /dev/null unless it is in the list of FDs to be + passed to the child. */ + fd = assuan_fd_from_posix_fd (fileno (stderr)); + fdp = fd_child_list; + if (fdp) + { + for (; *fdp != ASSUAN_INVALID_FD && *fdp != fd; fdp++) + ; + } + if (!fdp || *fdp == ASSUAN_INVALID_FD) + { + nullfd = CreateFileW (L"nul", GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (nullfd == INVALID_HANDLE_VALUE) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_spawn", ctx, + "can't open `nul': %s", _assuan_w32_strerror (ctx, -1)); + _assuan_free (ctx, cmdline); + gpg_err_set_errno (EIO); + return -1; + } + si.hStdError = nullfd; + } + else + si.hStdError = fd; + + /* Note: We inherit all handles flagged as inheritable. This seems + to be a security flaw but there seems to be no way of selecting + handles to inherit. */ + /* _assuan_log_printf ("CreateProcess, path=`%s' cmdline=`%s'\n", */ + /* name, cmdline); */ + if (!CreateProcess (name, /* Program to start. */ + cmdline, /* Command line arguments. */ + &sec_attr, /* Process security attributes. */ + &sec_attr, /* Thread security attributes. */ + TRUE, /* Inherit handles. */ + (CREATE_DEFAULT_ERROR_MODE + | CREATE_SUSPENDED), /* Creation flags. */ + NULL, /* Environment. */ + NULL, /* Use current drive/directory. */ + &si, /* Startup information. */ + &pi /* Returns process information. */ + )) + { + TRACE1 (ctx, ASSUAN_LOG_SYSIO, "pipe_connect_w32", ctx, + "CreateProcess failed: %s", _assuan_w32_strerror (ctx, -1)); + _assuan_free (ctx, cmdline); + if (nullfd != INVALID_HANDLE_VALUE) + CloseHandle (nullfd); + + gpg_err_set_errno (EIO); + return -1; + } + + _assuan_free (ctx, cmdline); + if (nullfd != INVALID_HANDLE_VALUE) + CloseHandle (nullfd); + + ResumeThread (pi.hThread); + CloseHandle (pi.hThread); + + /* _assuan_log_printf ("CreateProcess ready: hProcess=%p hThread=%p" */ + /* " dwProcessID=%d dwThreadId=%d\n", */ + /* pi.hProcess, pi.hThread, */ + /* (int) pi.dwProcessId, (int) pi.dwThreadId); */ + + *r_pid = (pid_t) pi.hProcess; + + /* No need to modify peer process, as we don't change the handle + names. However this also means we are not safe, as we inherit + too many handles. Should use approach similar to gpgme and glib + using a helper process. */ + + return 0; +} + + + + +/* FIXME: Add some sort of waitpid function that covers GPGME and + gpg-agent's use of assuan. */ +static pid_t +__assuan_waitpid (assuan_context_t ctx, pid_t pid, int nowait, + int *status, int options) +{ + CloseHandle ((HANDLE) pid); + return 0; +} + + + +int +__assuan_socketpair (assuan_context_t ctx, int namespace, int style, + int protocol, assuan_fd_t filedes[2]) +{ + gpg_err_set_errno (ENOSYS); + return -1; +} + + +/* The default system hooks for assuan contexts. */ +struct assuan_system_hooks _assuan_system_hooks = + { + ASSUAN_SYSTEM_HOOKS_VERSION, + __assuan_usleep, + __assuan_pipe, + __assuan_close, + __assuan_read, + __assuan_write, + __assuan_recvmsg, + __assuan_sendmsg, + __assuan_spawn, + __assuan_waitpid, + __assuan_socketpair + }; Modified: trunk/src/system.c =================================================================== --- trunk/src/system.c 2010-03-11 12:00:10 UTC (rev 360) +++ trunk/src/system.c 2010-03-16 13:04:42 UTC (rev 361) @@ -28,11 +28,6 @@ #include #include #include -#ifdef HAVE_W32_SYSTEM -# include -#else -# include -#endif #include "assuan-defs.h" #include "debug.h" @@ -45,30 +40,7 @@ #define DEBUG_SYSIO 0 - -assuan_fd_t -assuan_fdopen (int fd) -{ -#ifdef HAVE_W32_SYSTEM -#ifdef HAVE_W32CE_SYSTEM - assuan_fd_t ifd = (assuan_fd_t)fd; -#else - assuan_fd_t ifd = (assuan_fd_t) _get_osfhandle (fd); -#endif - assuan_fd_t ofd; - if (! DuplicateHandle(GetCurrentProcess(), ifd, - GetCurrentProcess(), &ofd, 0, - TRUE, DUPLICATE_SAME_ACCESS)) - { - gpg_err_set_errno (EIO); - return ASSUAN_INVALID_FD; - } - return ofd; -#else - return dup (fd); -#endif -} /* Manage memory specific to a context. */ @@ -154,40 +126,8 @@ ; } - -/* Sleep for the given number of microseconds. Default - implementation. */ -void -__assuan_usleep (assuan_context_t ctx, unsigned int usec) -{ - if (! usec) - return; -#ifdef HAVE_NANOSLEEP - { - struct timespec req; - struct timespec rem; - - req.tv_sec = 0; - req.tv_nsec = usec * 1000; - - while (nanosleep (&req, &rem) < 0 && errno == EINTR) - req = rem; - } -#elif defined(HAVE_W32_SYSTEM) - Sleep (usec / 1000); -#else - { - struct timeval tv; - - tv.tv_sec = usec / 1000000; - tv.tv_usec = usec % 1000000; - select (0, NULL, NULL, NULL, &tv); - } -#endif -} - - + /* Sleep for the given number of microseconds. */ void _assuan_usleep (assuan_context_t ctx, unsigned int usec) @@ -198,61 +138,8 @@ (ctx->system.usleep) (ctx, usec); } - -/* Create a pipe with one inheritable end. Default implementation. */ -int -__assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx) -{ -#ifdef HAVE_W32_SYSTEM - HANDLE rh; - HANDLE wh; - HANDLE th; - SECURITY_ATTRIBUTES sec_attr; - memset (&sec_attr, 0, sizeof (sec_attr)); - sec_attr.nLength = sizeof (sec_attr); - sec_attr.bInheritHandle = FALSE; - - if (!CreatePipe (&rh, &wh, &sec_attr, 0)) - { - TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx, - "CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1)); - gpg_err_set_errno (EIO); - return -1; - } - - if (! DuplicateHandle (GetCurrentProcess(), (inherit_idx == 0) ? rh : wh, - GetCurrentProcess(), &th, 0, - TRUE, DUPLICATE_SAME_ACCESS )) - { - TRACE1 (ctx, ASSUAN_LOG_SYSIO, "__assuan_pipe", ctx, - "DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1)); - CloseHandle (rh); - CloseHandle (wh); - gpg_err_set_errno (EIO); - return -1; - } - if (inherit_idx == 0) - { - CloseHandle (rh); - rh = th; - } - else - { - CloseHandle (wh); - wh = th; - } - - fd[0] = rh; - fd[1] = wh; - - return 0; -#else - return pipe (fd); -#endif -} - - + /* Create a pipe with one inheritable end. */ int _assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx) @@ -269,31 +156,9 @@ return TRACE_SUC2 ("read=0x%x, write=0x%x", fd[0], fd[1]); } + /* Close the given file descriptor, created with _assuan_pipe or one - of the socket functions. Default implementation. */ -int -__assuan_close (assuan_context_t ctx, assuan_fd_t fd) -{ -#ifdef HAVE_W32_SYSTEM - int rc = closesocket (HANDLE2SOCKET(fd)); - if (rc) - gpg_err_set_errno ( _assuan_sock_wsa2errno (WSAGetLastError ()) ); - if (rc && WSAGetLastError () == WSAENOTSOCK) - { - rc = CloseHandle (fd); - if (rc) - /* FIXME. */ - gpg_err_set_errno (EIO); - } - return rc; -#else - return close (fd); -#endif -} - - -/* Close the given file descriptor, created with _assuan_pipe or one of the socket functions. */ int _assuan_close (assuan_context_t ctx, assuan_fd_t fd) @@ -304,64 +169,8 @@ return (ctx->system.close) (ctx, fd); } From cvs at cvs.gnupg.org Mon Mar 22 13:16:18 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 22 Mar 2010 13:16:18 +0100 Subject: [svn] assuan - r362 - in trunk: . doc src tests Message-ID: Author: wk Date: 2010-03-22 13:16:18 +0100 (Mon, 22 Mar 2010) New Revision: 362 Added: trunk/src/assuan.h.in trunk/src/mkheader.c trunk/tests/ChangeLog trunk/tests/pipeconnect.c Removed: trunk/src/assuan.h Modified: trunk/ChangeLog trunk/configure.ac trunk/doc/assuan.texi trunk/src/ChangeLog trunk/src/Makefile.am trunk/src/assuan-defs.h trunk/src/assuan-pipe-connect.c trunk/src/gpgcedev.c trunk/src/libassuan.def trunk/src/system-w32.c trunk/src/system-w32ce.c trunk/src/system.c trunk/src/sysutils.c trunk/tests/Makefile.am trunk/tests/ce-createpipe.c trunk/tests/ce-server.c Log: Changed the implementation of CreatePipe under W32CE. Reorganized the source. [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/ChangeLog 2010-03-22 12:16:18 UTC (rev 362) @@ -1,14 +1,16 @@ -2010-02-25 Werner Koch +2010-03-22 Werner Koch - * m4/libtool.m4 (_LT_CHECK_MAGIC_METHOD): Fix for non x86 mingw - targets. + * configure.ac (CC_FOR_BUILD): Add test. -2010-02-24 Werner Koch +2010-03-17 Werner Koch - * tests/ce-server.c: New. + * tests/ChangeLog: New. Move all relevant entries to there. - * tests/ce-createpipe.c [W32CE]: New. +2010-02-25 Werner Koch + * m4/libtool.m4 (_LT_CHECK_MAGIC_METHOD): Fix for non x86 mingw + targets. + 2010-02-11 Werner Koch * configure.ac (inet_pton): Check for it. @@ -17,10 +19,6 @@ * configure.ac (AC_TYPE_UINT16_T): New. -2010-01-27 Werner Koch - - * tests/common.h (SOCKET2HANDLE, HANDLE2SOCKET): New. - 2010-01-26 Werner Koch * configure.ac (NETLIBS) [W32CE]: Use -lws2. @@ -49,16 +47,6 @@ * configure.ac: Bump version to 2.0.0. -2009-11-05 Marcus Brinkmann - - * tests/fdpassing.c (main): Call assuan_pipe_connect instead - of assuan_pipe_connect_ext. - -2009-11-04 Werner Koch - - * tests/fdpassing.c (register_commands): Add NULL arg to - assuan_register_command. - 2009-10-16 Marcus Brinkmann * autogen.sh: Remove --with-pth-prefix from configure invocation. @@ -74,7 +62,6 @@ 2009-09-19 Marcus Brinkmann - * tests/fdpassing.c: Update to new API. * configure.ac: Check for stdint.h and inttypes.h. Invoke AC_TYPE_UINTPTR_T. @@ -101,18 +88,11 @@ (AC_CONFIG_FILES): Add src/versioninfo.rc. * ltmain.sh, m4/libtool.m4, m4/ltoptions.m4, m4/ltsugar.m4, m4/ltversion.m4, m4/lt~obsolete.m4: New files from libtool 2.2.6. - * tests/Makefile.am (AM_CFLAGS, LDADD): Add gpg-error. - * tests/fdpassing.c: Change error values to gpg-error ones. 2009-01-22 Werner Koch * configure.ac: Check for nanoleep only in libc. -2008-11-03 Marcus Brinkmann - - * tests/fdpassing.c (register_commands): Add missing initializer - to silence gcc -W warning. - 2008-05-25 Werner Koch Released 1.0.5. @@ -130,7 +110,7 @@ 2007-08-24 Werner Koch Released 1.0.3. - + Switched license of the library code back to LGPLv2.1. See NEWS. * COPYING.LIB: Replaced by LPGLv2.1 @@ -138,7 +118,7 @@ 2007-07-05 Werner Koch Released 1.0.2. - + Relicensed to LGPLv3. * COPYING: Replaced by GPLv3. @@ -162,13 +142,13 @@ 2007-05-30 Werner Koch - * autogen.sh <--build-w32>: Modernize. + * autogen.sh <--build-w32>: Modernize. 2007-05-29 Werner Koch * configure.ac: Require automake 1.10 and autoconf 2.61. (AM_PROG_CC_C_O): New. Error out if no C-89 cc is installed. - (gl_HEADER_SYS_SOCKET): Explicitly add this for documentation. + (gl_HEADER_SYS_SOCKET): Explicitly add this for documentation. 2007-05-24 Werner Koch @@ -202,8 +182,6 @@ Released 0.9.3. - * tests/Makefile.am (LDADD): Add NETLIBS. - * configure.ac: Check for cmsghdr. (USE_DESCRIPTOR_PASSING): Define it then. @@ -214,29 +192,15 @@ 2006-10-04 Werner Koch Released 0.9.2. - + 2006-10-04 Werner Koch Released 0.9.1. - + * configure.ac (AB_INIT): New. * m4/autobuild.m4: New. -2006-09-19 Werner Koch - - * tests/fdpassing.c: Reverted Marcus changes. - (client): New arg FNAME to replace hardwired file name. - (main): Pass motd to client. - * tests/Makefile.am (AM_CPPFLAGS): Removed. - (EXTRA_DIST): Add motd. - -2006-09-19 Marcus Brinkmann - - * tests/fdpassing.c (MOTD): New macro. - * tests/Makefile.am (AM_CPPFLAGS): New variable. - * tests/motd: New file. - 2006-09-14 Werner Koch Released 0.9.0. @@ -292,7 +256,7 @@ 2004-09-27 Werner Koch - * config.sub, config.guess: Updated. + * config.sub, config.guess: Updated. 2004-06-23 Marcus Brinkmann @@ -398,7 +362,7 @@ * tests: New directory. - Copyright 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright 2003, 2004, 2005, 2006, 2007, 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 @@ -407,5 +371,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. - - Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/ChangeLog 2010-03-22 12:16:18 UTC (rev 362) @@ -1,5 +1,39 @@ +2010-03-22 Werner Koch + + * Makefile.am (mkheader, assuan.h): Build header file. + * mkheader.c: New. + * assuan.h: Rename to assuan.h.in. + +2010-03-18 Werner Koch + + * libassuan.def (_assuan_w32ce_prepare_pipe) + (_assuan_w32ce_finish_pipe): New + * gpgcedev.c (struct opnctx_s): Replace HD by RVID. + (GPGCEDEV_IOCTL_SET_HANDLE): Remove. + (GPGCEDEV_IOCTL_GET_RVID): New. + (create_rendezvous_id): New. + (get_new_opnctx): Init the RVID. + (set_handle): Remove. + (find_and_lock_opnctx, make_pipe, GPG_IOControl): Change to new + method. + * system-w32ce.c (_assuan_w32ce_prepare_pipe) + (_assuan_w32ce_finish_pipe): New. + (_assuan_w32ce_create_pipe): Re-implement using the new functions. + (__assuan_pipe): Create an inheritable pipe. + (build_w32_commandline): New arg FD2_ISNULL. + * system.c (_assuan_close_inheritable): New. + * assuan-pipe-connect.c (pipe_connect): Use the new function. + + * sysutils.c (_assuan_w32ce_create_pipe): Move to system-w32ce.c. + 2010-03-16 Werner Koch + * system-w32ce.c (build_w32_commandline): Add args to pass the + special options for the standard descriptors. + (utf8_to_wchar, free_wchar): New. + (__assuan_spawn): Adjust for changes. Convert strings for + CreateProcess to wchar_t. + * system.c: For better readability move platform dependend code to .. * system-posix.c, system-w32.c, system-w32ce.c: .. New. * Makefile.am (common_sources): Account for this change. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/configure.ac 2010-03-22 12:16:18 UTC (rev 362) @@ -58,7 +58,7 @@ AM_INIT_AUTOMAKE AM_MAINTAINER_MODE -AC_CONFIG_SRCDIR(src/assuan.h) +AC_CONFIG_SRCDIR(src/assuan.h.in) AC_CONFIG_MACRO_DIR(m4) AM_CONFIG_HEADER(config.h) AC_CANONICAL_HOST @@ -118,6 +118,22 @@ AC_PROG_MAKE_SET #AC_ARG_PROGRAM +# We need to compile and run a program on the build machine. A +# comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in +# the AC archive is broken for autoconf 2.57. Given that there is no +# newer version of that macro, we assume that it is also broken for +# autoconf 2.61 and thus we use a simple but usually sufficient +# approach. +AC_MSG_CHECKING(for cc for build) +if test "$cross_compiling" = "yes"; then + CC_FOR_BUILD="${CC_FOR_BUILD-cc}" +else + CC_FOR_BUILD="${CC_FOR_BUILD-$CC}" +fi +AC_MSG_RESULT($CC_FOR_BUILD) +AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler]) + + if test "$GCC" = yes; then CFLAGS="$CFLAGS -Wall -Wcast-align -Wshadow -Wstrict-prototypes" @@ -325,8 +341,6 @@ fi - - # Create the config files. AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([m4/Makefile]) Modified: trunk/doc/assuan.texi =================================================================== --- trunk/doc/assuan.texi 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/doc/assuan.texi 2010-03-22 12:16:18 UTC (rev 362) @@ -1064,12 +1064,13 @@ list @var{argv}. A list of file descriptors not to be closed may be given using the @code{ASSUAN_INVLID_FD} terminated array @var{fd_child_list}. -If @var{name} is a null pointer, only a fork but no exec is done. -Thus the child continues to run. However all file descriptors are -closed and some special environment variables are set. To let the -caller detect whether the child or the parent continues, the parent -returns with @code{"client"} returned in @var{argv} and the child -returns with @code{"server"} in @var{argv}. +If @var{name} is a null pointer, only a fork but no exec is done. Thus +the child continues to run. However all file descriptors are closed and +some special environment variables are set. To let the caller detect +whether the child or the parent continues, the parent returns with + at code{"client"} returned in @var{argv} and the child returns with + at code{"server"} in @var{argv}. This feature is only available on POSIX +platforms. If @var{atfork} is not NULL, this function is called in the child right after the fork and the value @var{atforkvalue} is passed as the first Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/Makefile.am 2010-03-22 12:16:18 UTC (rev 362) @@ -1,5 +1,5 @@ # Assuan Makefile -# Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +# Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. # # This file is part of Assuan. # @@ -18,7 +18,7 @@ ## Process this file with automake to produce Makefile.in EXTRA_DIST = libassuan-config.in libassuan.m4 libassuan.vers \ - versioninfo.rc.in libassuan.def + versioninfo.rc.in libassuan.def mkheader.c INCLUDES = -I.. -I$(top_srcdir)/include bin_SCRIPTS = libassuan-config @@ -37,8 +37,12 @@ libassuan_version_script_cmd = endif +CLEANFILES = mkheader assuan.h +BUILT_SOURCES = assuan.h + common_sources = \ + assuan.h.in assuan.h w32ce-add.h \ assuan-defs.h \ assuan.c context.c system.c \ debug.c debug.h conversion.c sysutils.c \ @@ -121,3 +125,10 @@ gpgcemgr_SOURCES = gpgcemgr.c gpgcemgr_CPPFLAGS = $(AM_CPPFLAGS) endif + +mkheader: mkheader.c Makefile + $(CC_FOR_BUILD) -I. -I$(srcdir) -o $@ $(srcdir)/mkheader.c + +assuan.h: assuan.h.in mkheader w32ce-add.h + ./mkheader $(host_os) $(srcdir)/assuan.h.in >$@ + Modified: trunk/src/assuan-defs.h =================================================================== --- trunk/src/assuan-defs.h 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/assuan-defs.h 2010-03-22 12:16:18 UTC (rev 362) @@ -230,6 +230,7 @@ void _assuan_usleep (assuan_context_t ctx, unsigned int usec); int _assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx); int _assuan_close (assuan_context_t ctx, assuan_fd_t fd); +int _assuan_close_inheritable (assuan_context_t ctx, assuan_fd_t fd); ssize_t _assuan_read (assuan_context_t ctx, assuan_fd_t fd, void *buffer, size_t size); ssize_t _assuan_write (assuan_context_t ctx, assuan_fd_t fd, const void *buffer, Modified: trunk/src/assuan-pipe-connect.c =================================================================== --- trunk/src/assuan-pipe-connect.c 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/assuan-pipe-connect.c 2010-03-22 12:16:18 UTC (rev 362) @@ -175,7 +175,7 @@ if (_assuan_pipe (ctx, wp, 0) < 0) { _assuan_close (ctx, rp[0]); - _assuan_close (ctx, rp[1]); + _assuan_close_inheritable (ctx, rp[1]); return _assuan_error (ctx, gpg_err_code_from_syserror ()); } @@ -197,8 +197,8 @@ } /* Close the stdin/stdout child fds in the parent. */ - _assuan_close (ctx, rp[1]); - _assuan_close (ctx, wp[0]); + _assuan_close_inheritable (ctx, rp[1]); + _assuan_close_inheritable (ctx, wp[0]); ctx->engine.release = _assuan_client_release; ctx->engine.readfnc = _assuan_simple_read; @@ -393,7 +393,7 @@ environment variables are set. To let the caller detect whether the child or the parent continues, the child returns "client" or "server" in *ARGV (but it is sufficient to check only the first - character). */ + character). This feature is only available on POSIX platforms. */ gpg_error_t assuan_pipe_connect (assuan_context_t ctx, const char *name, const char *argv[], Deleted: trunk/src/assuan.h Copied: trunk/src/assuan.h.in (from rev 361, trunk/src/assuan.h) =================================================================== --- trunk/src/assuan.h.in (rev 0) +++ trunk/src/assuan.h.in 2010-03-22 12:16:18 UTC (rev 362) @@ -0,0 +1,649 @@ +/* assuan.h - Definitions for the Assuan IPC library -*- c -*- + Copyright (C) 2001, 2002, 2003, 2005, 2007, 2008, 2009, + 2010 Free Software Foundation, Inc. + + This file is part of Assuan. + + Assuan is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + Assuan is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, see . + + @configure_input@ + */ + +#ifndef ASSUAN_H +#define ASSUAN_H + +#include +#include +#include +#include + +#ifndef _ASSUAN_NO_SOCKET_WRAPPER +#ifdef _WIN32 +#include +#else +#include +#endif +#endif /*!_ASSUAN_NO_SOCKET_WRAPPER*/ + +#ifdef _WIN32 +typedef void *assuan_msghdr_t; +#else +typedef struct msghdr *assuan_msghdr_t; +#endif + +#include + +/* Compile time configuration: + + #define _ASSUAN_NO_SOCKET_WRAPPER + + Do not include the definitions for the socket wrapper feature. */ + + +#ifdef __cplusplus +extern "C" +{ +#if 0 +} +#endif +#endif + + +/* Check for compiler features. */ +#if __GNUC__ +#define _ASSUAN_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if _ASSUAN_GCC_VERSION > 30100 +#define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__)) +#endif +#endif +#ifndef _ASSUAN_DEPRECATED +#define _ASSUAN_DEPRECATED +#endif + + +#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */ + +struct assuan_context_s; +typedef struct assuan_context_s *assuan_context_t; + +/* Because we use system handles and not libc low level file + descriptors on W32, we need to declare them as HANDLE (which + actually is a plain pointer). This is required to eventually + support 64 bit Windows systems. */ +#ifdef _WIN32 +typedef void *assuan_fd_t; +#define ASSUAN_INVALID_FD ((void*)(-1)) +#define ASSUAN_INVALID_PID ((pid_t) -1) +static inline assuan_fd_t +assuan_fd_from_posix_fd (int fd) +{ +#ifdef __MINGW32CE__ + return (assuan_fd_t)(fd); +#else + if (fd < 0) + return ASSUAN_INVALID_FD; + else + return (assuan_fd_t) _get_osfhandle (fd); +#endif +} +#else +typedef int assuan_fd_t; +#define ASSUAN_INVALID_FD (-1) +#define ASSUAN_INVALID_PID ((pid_t) -1) +static inline assuan_fd_t +assuan_fd_from_posix_fd (int fd) +{ + return fd; +} +#endif + +assuan_fd_t assuan_fdopen (int fd); + + +/* Assuan features an emulation of Unix domain sockets based on a + local TCP connections. To implement access permissions based on + file permissions a nonce is used which is expected by the server as + the first bytes received. This structure is used by the server to + save the nonce created initially by bind. On POSIX systems this is + a dummy operation. */ +struct assuan_sock_nonce_s +{ + size_t length; +#ifdef _WIN32 + char nonce[16]; +#endif +}; +typedef struct assuan_sock_nonce_s assuan_sock_nonce_t; + +/* Define the Unix domain socket structure for Windows. */ +#if defined(_WIN32) && !defined(_ASSUAN_NO_SOCKET_WRAPPER) +#ifndef AF_LOCAL +#define AF_LOCAL AF_UNIX +#endif +#define EADDRINUSE WSAEADDRINUSE +struct sockaddr_un +{ + short sun_family; + unsigned short sun_port; + struct in_addr sun_addr; + char sun_path[108-2-4]; +}; +#endif + + +/* Global interface. */ + +struct assuan_malloc_hooks +{ + void *(*malloc) (size_t cnt); + void *(*realloc) (void *ptr, size_t cnt); + void (*free) (void *ptr); +}; +typedef struct assuan_malloc_hooks *assuan_malloc_hooks_t; + +/* Categories for log messages. */ +#define ASSUAN_LOG_INIT 1 +#define ASSUAN_LOG_CTX 2 +#define ASSUAN_LOG_ENGINE 3 +#define ASSUAN_LOG_DATA 4 +#define ASSUAN_LOG_SYSIO 5 +#define ASSUAN_LOG_CONTROL 8 + +/* If MSG is NULL, return true/false depending on if this category is + logged. This is used to probe before expensive log message + generation (buffer dumps). */ +typedef int (*assuan_log_cb_t) (assuan_context_t ctx, void *hook, + unsigned int cat, const char *msg); + +/* Set the default gpg error source. */ +void assuan_set_gpg_err_source (gpg_err_source_t errsource); + +/* Get the default gpg error source. */ +gpg_err_source_t assuan_get_gpg_err_source (void); + + +/* Set the default malloc hooks. */ +void assuan_set_malloc_hooks (assuan_malloc_hooks_t malloc_hooks); + +/* Get the default malloc hooks. */ +assuan_malloc_hooks_t assuan_get_malloc_hooks (void); + + +/* Set the default log callback handler. */ +void assuan_set_log_cb (assuan_log_cb_t log_cb, void *log_cb_data); + +/* Get the default log callback handler. */ +void assuan_get_log_cb (assuan_log_cb_t *log_cb, void **log_cb_data); + + +/* Create a new Assuan context. The initial parameters are all needed + in the creation of the context. */ +gpg_error_t assuan_new_ext (assuan_context_t *ctx, gpg_err_source_t errsource, + assuan_malloc_hooks_t malloc_hooks, + assuan_log_cb_t log_cb, void *log_cb_data); + +/* Create a new context with default arguments. */ +gpg_error_t assuan_new (assuan_context_t *ctx); + +/* Release all resources associated with the given context. */ +void assuan_release (assuan_context_t ctx); + +/* Release the memory at PTR using the allocation handler of the + context CTX. This is a convenience function. */ +void assuan_free (assuan_context_t ctx, void *ptr); + + +/* Set user-data in a context. */ +void assuan_set_pointer (assuan_context_t ctx, void *pointer); + +/* Get user-data in a context. */ +void *assuan_get_pointer (assuan_context_t ctx); + + +/* Definitions of flags for assuan_set_flag(). */ +typedef unsigned int assuan_flag_t; + +/* When using a pipe server, by default Assuan will wait for the + forked process to die in assuan_release. In certain cases this + is not desirable. By setting this flag, the waitpid will be + skipped and the caller is responsible to cleanup a forked + process. */ +#define ASSUAN_NO_WAITPID 1 +/* This flag indicates whether Assuan logging is in confidential mode. + You can use assuan_{begin,end}_condidential to change the mode. */ +#define ASSUAN_CONFIDENTIAL 2 +/* This flag suppresses fix up of signal handlers for pipes. */ +#define ASSUAN_NO_FIXSIGNALS 3 + +/* For context CTX, set the flag FLAG to VALUE. Values for flags + are usually 1 or 0 but certain flags might allow for other values; + see the description of the type assuan_flag_t for details. */ +void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value); + +/* Return the VALUE of FLAG in context CTX. */ +int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag); + + +/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 1). */ +void assuan_begin_confidential (assuan_context_t ctx); + +/* Same as assuan_set_flag (ctx, ASSUAN_CONFIDENTIAL, 0). */ +void assuan_end_confidential (assuan_context_t ctx); + + +/* Direction values for assuan_set_io_monitor. */ +#define ASSUAN_IO_FROM_PEER 0 +#define ASSUAN_IO_TO_PEER 1 + +/* Return flags of I/O monitor. */ +#define ASSUAN_IO_MONITOR_NOLOG 1 +#define ASSUAN_IO_MONITOR_IGNORE 2 + +/* The IO monitor gets to see all I/O on the context, and can return + ASSUAN_IO_MONITOR_* bits to control actions on it. */ +typedef unsigned int (*assuan_io_monitor_t) (assuan_context_t ctx, void *hook, + int inout, const char *line, + size_t linelen); + +/* Set the IO monitor function. */ +void assuan_set_io_monitor (assuan_context_t ctx, + assuan_io_monitor_t io_monitor, void *hook_data); + + +#define ASSUAN_SYSTEM_HOOKS_VERSION 1 +#define ASSUAN_SPAWN_DETACHED 128 +struct assuan_system_hooks +{ + /* Always set to ASSUAN_SYTEM_HOOKS_VERSION. */ + int version; + + /* Sleep for the given number of microseconds. */ + void (*usleep) (assuan_context_t ctx, unsigned int usec); + + /* Create a pipe with an inheritable end. */ + int (*pipe) (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx); + + /* Close the given file descriptor, created with _assuan_pipe or one + of the socket functions. */ + int (*close) (assuan_context_t ctx, assuan_fd_t fd); + + + ssize_t (*read) (assuan_context_t ctx, assuan_fd_t fd, void *buffer, + size_t size); + ssize_t (*write) (assuan_context_t ctx, assuan_fd_t fd, + const void *buffer, size_t size); + + int (*recvmsg) (assuan_context_t ctx, assuan_fd_t fd, assuan_msghdr_t msg, + int flags); + int (*sendmsg) (assuan_context_t ctx, assuan_fd_t fd, + const assuan_msghdr_t msg, int flags); + + /* If NAME is NULL, don't exec, just fork. FD_CHILD_LIST is + modified to reflect the value of the FD in the peer process (on + Windows). */ + int (*spawn) (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, + assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags); + + /* If action is 0, like waitpid. If action is 1, just release the PID? */ + pid_t (*waitpid) (assuan_context_t ctx, pid_t pid, + int action, int *status, int options); + int (*socketpair) (assuan_context_t ctx, int _namespace, int style, + int protocol, assuan_fd_t filedes[2]); +}; +typedef struct assuan_system_hooks *assuan_system_hooks_t; + + +/* Configuration of the default log handler. */ + +/* Set the prefix to be used at the start of a line emitted by assuan + on the log stream. The default is the empty string. Note, that + this function is not thread-safe and should in general be used + right at startup. */ +void assuan_set_assuan_log_prefix (const char *text); + +/* Return a prefix to be used at the start of a line emitted by assuan + on the log stream. The default implementation returns the empty + string, i.e. "" */ +const char *assuan_get_assuan_log_prefix (void); + +/* Global default log stream. */ +void assuan_set_assuan_log_stream (FILE *fp); + +/* Set the per context log stream for the default log handler. */ +void assuan_set_log_stream (assuan_context_t ctx, FILE *fp); + + +typedef gpg_error_t (*assuan_handler_t) (assuan_context_t, char *); + +/*-- assuan-handler.c --*/ +gpg_error_t assuan_register_command (assuan_context_t ctx, + const char *cmd_string, + assuan_handler_t handler, + const char *help_string); +gpg_error_t assuan_register_post_cmd_notify (assuan_context_t ctx, + void (*fnc)(assuan_context_t, + gpg_error_t)); +gpg_error_t assuan_register_bye_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_reset_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_cancel_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_input_notify (assuan_context_t ctx, + assuan_handler_t handler); +gpg_error_t assuan_register_output_notify (assuan_context_t ctx, + assuan_handler_t handler); + +gpg_error_t assuan_register_option_handler (assuan_context_t ctx, + gpg_error_t (*fnc)(assuan_context_t, + const char*, + const char*)); + +gpg_error_t assuan_process (assuan_context_t ctx); +gpg_error_t assuan_process_next (assuan_context_t ctx, int *done); +gpg_error_t assuan_process_done (assuan_context_t ctx, gpg_error_t rc); +int assuan_get_active_fds (assuan_context_t ctx, int what, + assuan_fd_t *fdarray, int fdarraysize); + +const char *assuan_get_command_name (assuan_context_t ctx); + +FILE *assuan_get_data_fp (assuan_context_t ctx); +gpg_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line); +gpg_error_t assuan_write_status (assuan_context_t ctx, + const char *keyword, const char *text); + +/* Negotiate a file descriptor. If LINE contains "FD=N", returns N + assuming a local file descriptor. If LINE contains "FD" reads a + file descriptor via CTX and stores it in *RDF (the CTX must be + capable of passing file descriptors). Under W32 the returned FD is + a libc-type one. */ +gpg_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line, + assuan_fd_t *rfd); + + +/*-- assuan-listen.c --*/ +gpg_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line); +gpg_error_t assuan_accept (assuan_context_t ctx); +assuan_fd_t assuan_get_input_fd (assuan_context_t ctx); +assuan_fd_t assuan_get_output_fd (assuan_context_t ctx); +gpg_error_t assuan_close_input_fd (assuan_context_t ctx); +gpg_error_t assuan_close_output_fd (assuan_context_t ctx); + + +/*-- assuan-pipe-server.c --*/ +gpg_error_t assuan_init_pipe_server (assuan_context_t ctx, + assuan_fd_t filedes[2]); + +/*-- assuan-socket-server.c --*/ +#define ASSUAN_SOCKET_SERVER_FDPASSING 1 +#define ASSUAN_SOCKET_SERVER_ACCEPTED 2 +gpg_error_t assuan_init_socket_server (assuan_context_t ctx, + assuan_fd_t listen_fd, + unsigned int flags); +void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce); + +/*-- assuan-pipe-connect.c --*/ +#define ASSUAN_PIPE_CONNECT_FDPASSING 1 +#define ASSUAN_PIPE_CONNECT_DETACHED 128 +gpg_error_t assuan_pipe_connect (assuan_context_t ctx, + const char *name, + const char *argv[], + assuan_fd_t *fd_child_list, + void (*atfork) (void *, int), + void *atforkvalue, + unsigned int flags); + +/*-- assuan-socket-connect.c --*/ +#define ASSUAN_SOCKET_CONNECT_FDPASSING 1 +gpg_error_t assuan_socket_connect (assuan_context_t ctx, const char *name, + pid_t server_pid, unsigned int flags); + +/*-- assuan-connect.c --*/ +pid_t assuan_get_pid (assuan_context_t ctx); +struct _assuan_peercred +{ +#ifdef _WIN32 + /* Empty struct not allowed on some compilers. */ + unsigned int _dummy; +#else + pid_t pid; + uid_t uid; + gid_t gid; +#endif +}; +typedef struct _assuan_peercred *assuan_peercred_t; + +gpg_error_t assuan_get_peercred (assuan_context_t ctx, + assuan_peercred_t *peercred); + + + +/* Client interface. */ +#define ASSUAN_RESPONSE_ERROR 0 +#define ASSUAN_RESPONSE_OK 1 +#define ASSUAN_RESPONSE_DATA 2 +#define ASSUAN_RESPONSE_INQUIRE 3 +#define ASSUAN_RESPONSE_STATUS 4 +#define ASSUAN_RESPONSE_END 5 +#define ASSUAN_RESPONSE_COMMENT 6 +typedef int assuan_response_t; + +/* This already de-escapes data lines. */ +gpg_error_t assuan_client_read_response (assuan_context_t ctx, + char **line, int *linelen); + +gpg_error_t assuan_client_parse_response (assuan_context_t ctx, + char *line, int linelen, + assuan_response_t *response, + int *off); + +/*-- assuan-client.c --*/ +gpg_error_t +assuan_transact (assuan_context_t ctx, + const char *command, + gpg_error_t (*data_cb)(void *, const void *, size_t), + void *data_cb_arg, + gpg_error_t (*inquire_cb)(void*, const char *), + void *inquire_cb_arg, + gpg_error_t (*status_cb)(void*, const char *), + void *status_cb_arg); + + +/*-- assuan-inquire.c --*/ +gpg_error_t assuan_inquire (assuan_context_t ctx, const char *keyword, + unsigned char **r_buffer, size_t *r_length, + size_t maxlen); +gpg_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword, + size_t maxlen, + gpg_error_t (*cb) (void *cb_data, + gpg_error_t rc, + unsigned char *buf, + size_t buf_len), + void *cb_data); +/*-- assuan-buffer.c --*/ +gpg_error_t assuan_read_line (assuan_context_t ctx, + char **line, size_t *linelen); +int assuan_pending_line (assuan_context_t ctx); +gpg_error_t assuan_write_line (assuan_context_t ctx, const char *line); +gpg_error_t assuan_send_data (assuan_context_t ctx, + const void *buffer, size_t length); + +/* The file descriptor must be pending before assuan_receivefd is + called. This means that assuan_sendfd should be called *before* the + trigger is sent (normally via assuan_write_line ("INPUT FD")). */ +gpg_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd); +gpg_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd); + + +/*-- assuan-util.c --*/ +gpg_error_t assuan_set_error (assuan_context_t ctx, gpg_error_t err, + const char *text); + + + +/*-- assuan-socket.c --*/ + +/* These are socket wrapper functions to support an emulation of Unix + domain sockets on Windows W32. */ +gpg_error_t assuan_sock_init (void); +void assuan_sock_deinit (void); +int assuan_sock_close (assuan_fd_t fd); +assuan_fd_t assuan_sock_new (int domain, int type, int proto); +int assuan_sock_connect (assuan_fd_t sockfd, + struct sockaddr *addr, int addrlen); +int assuan_sock_bind (assuan_fd_t sockfd, struct sockaddr *addr, int addrlen); +int assuan_sock_get_nonce (struct sockaddr *addr, int addrlen, + assuan_sock_nonce_t *nonce); +int assuan_sock_check_nonce (assuan_fd_t fd, assuan_sock_nonce_t *nonce); + + +/* Set the default or per context system callbacks. This is + irreversible. */ +void assuan_set_system_hooks (assuan_system_hooks_t system_hooks); + +void assuan_ctx_set_system_hooks (assuan_context_t ctx, + assuan_system_hooks_t system_hooks); + +void __assuan_usleep (assuan_context_t ctx, unsigned int usec); +int __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx); +int __assuan_close (assuan_context_t ctx, assuan_fd_t fd); +int __assuan_spawn (assuan_context_t ctx, pid_t *r_pid, const char *name, + const char **argv, assuan_fd_t fd_in, assuan_fd_t fd_out, + assuan_fd_t *fd_child_list, + void (*atfork) (void *opaque, int reserved), + void *atforkvalue, unsigned int flags); +int __assuan_socketpair (assuan_context_t ctx, int _namespace, int style, + int protocol, assuan_fd_t filedes[2]); + +#ifdef _WIN32 +#define _ASSUAN_SYSTEM_PTH_IMPL \ + static int _assuan_pth_recvmsg (assuan_context_t ctx, assuan_fd_t fd, \ + assuan_msghdr_t msg, int flags) \ + { \ + (void) ctx; \ + errno = ENOSYS; \ + return -1; \ + } \ + static int _assuan_pth_sendmsg (assuan_context_t ctx, assuan_fd_t fd, \ + const assuan_msghdr_t msg, int flags) \ + { \ + (void) ctx; \ + errno = ENOSYS; \ + return -1; \ + } +#else +#define _ASSUAN_SYSTEM_PTH_IMPL \ + static int _assuan_pth_recvmsg (assuan_context_t ctx, assuan_fd_t fd, \ + assuan_msghdr_t msg, int flags) \ + { \ + /* Pth does not provide a recvmsg function. We implement it. */ \ + int ret; \ + int fdmode; \ + \ + (void) ctx; \ + fdmode = pth_fdmode (fd, PTH_FDMODE_POLL); \ + if (fdmode == PTH_FDMODE_ERROR) \ + { \ + errno = EBADF; \ + return -1; \ + } \ + if (fdmode == PTH_FDMODE_BLOCK) \ + { \ + fd_set fds; \ + \ + FD_ZERO (&fds); \ + FD_SET (fd, &fds); \ + while ((ret = pth_select (fd + 1, &fds, NULL, NULL, NULL)) < 0 \ + && errno == EINTR) \ + ; \ + if (ret < 0) \ + return -1; \ + } \ + \ + while ((ret = recvmsg (fd, msg, flags)) == -1 && errno == EINTR) \ + ; \ + return ret; \ + } \ + static int _assuan_pth_sendmsg (assuan_context_t ctx, assuan_fd_t fd, \ + const assuan_msghdr_t msg, int flags) \ + { \ + /* Pth does not provide a sendmsg function. We implement it. */ \ + int ret; \ + int fdmode; \ + \ + (void) ctx; \ + fdmode = pth_fdmode (fd, PTH_FDMODE_POLL); \ + if (fdmode == PTH_FDMODE_ERROR) \ + { \ + errno = EBADF; \ + return -1; \ + } \ + if (fdmode == PTH_FDMODE_BLOCK) \ + { \ + fd_set fds; \ + \ + FD_ZERO (&fds); \ + FD_SET (fd, &fds); \ + while ((ret = pth_select (fd + 1, NULL, &fds, NULL, NULL)) < 0 \ + && errno == EINTR) \ + ; \ + if (ret < 0) \ + return -1; \ + } \ + \ + while ((ret = sendmsg (fd, msg, flags)) == -1 && errno == EINTR) \ + ; \ + return ret; \ + } +#endif + + +#define ASSUAN_SYSTEM_PTH_IMPL \ + static void _assuan_pth_usleep (assuan_context_t ctx, unsigned int usec) \ + { (void) ctx; pth_usleep (usec); } \ + static ssize_t _assuan_pth_read (assuan_context_t ctx, assuan_fd_t fd, \ + void *buffer, size_t size) \ + { (void) ctx; return pth_read (fd, buffer, size); } \ + static ssize_t _assuan_pth_write (assuan_context_t ctx, assuan_fd_t fd, \ + const void *buffer, size_t size) \ + { (void) ctx; return pth_write (fd, buffer, size); } \ + _ASSUAN_SYSTEM_PTH_IMPL \ + static pid_t _assuan_pth_waitpid (assuan_context_t ctx, pid_t pid, \ + int nowait, int *status, int options) \ + { (void) ctx; \ + if (!nowait) return pth_waitpid (pid, status, options); \ + else return 0; } \ + \ + struct assuan_system_hooks _assuan_system_pth = \ + { ASSUAN_SYSTEM_HOOKS_VERSION, _assuan_pth_usleep, __assuan_pipe, \ + __assuan_close, _assuan_pth_read, _assuan_pth_write, \ + _assuan_pth_recvmsg, _assuan_pth_sendmsg, \ + __assuan_spawn, _assuan_pth_waitpid, __assuan_socketpair } + +extern struct assuan_system_hooks _assuan_system_pth; +#define ASSUAN_SYSTEM_PTH &_assuan_system_pth + + at include:w32ce-add@ + +#ifdef __cplusplus +} +#endif +#endif /* ASSUAN_H */ Property changes on: trunk/src/assuan.h.in ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Modified: trunk/src/gpgcedev.c =================================================================== --- trunk/src/gpgcedev.c 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/gpgcedev.c 2010-03-22 12:16:18 UTC (rev 362) @@ -17,6 +17,7 @@ License along with this program; if not, see . */ + #include #include #include @@ -35,19 +36,21 @@ #endif /*IOCTL_PSL_NOTIFY*/ -/* The IOCTL used to tell the device about the handle. +/* The IOCTL to return the rendezvous id of the handle. - The required inbuf parameter is the address of a variable holding - the handle. */ -#define GPGCEDEV_IOCTL_SET_HANDLE \ + The required outbuf parameter is the address of a variable to store + the rendezvous ID, which is a LONG value. */ +#define GPGCEDEV_IOCTL_GET_RVID \ CTL_CODE (FILE_DEVICE_STREAMS, 2048, METHOD_BUFFERED, FILE_ANY_ACCESS) /* The IOCTL used to create the pipe. - The caller sends this IOCTL to the read handle. The required inbuf - parameter is the address of variable holding the write handle. - Note that the SET_HANDLE IOCTLs must have been used prior to this - one. */ + The caller sends this IOCTL to the read or the write handle. The + required inbuf parameter is address of a variable holding the + rendezvous id of the pipe's other end. There is one possible + problem with eocdde: If a pipe is kept in non-rendezvous state + until after the rendezvous ids overflow, it is possible that the + wrong end will be used. However this is not a realistic scenario. */ #define GPGCEDEV_IOCTL_MAKE_PIPE \ CTL_CODE (FILE_DEVICE_STREAMS, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS) @@ -62,7 +65,7 @@ other context; i.e. a pipe has been established. */ int is_write; /* True if this is the write end of the pipe. */ - HANDLE hd; /* The system's handle object or INVALID_HANDLE_VALUE. */ + LONG rvid; /* The unique rendezvous identifier. */ DWORD access_code;/* Value from OpenFile. */ DWORD share_mode; /* Value from OpenFile. */ CRITICAL_SECTION critsect; /* Lock for all operations. */ @@ -118,7 +121,20 @@ } +/* Return a new rendezvous next command id. Command Ids are used to group + resources of one command. We will never return an RVID of 0. */ +static LONG +create_rendezvous_id (void) +{ + static LONG rendezvous_id; + LONG rvid; + while (!(rvid = InterlockedIncrement (&rendezvous_id))) + ; + return rvid; +} + + /* Return a new opnctx handle and mark it as used. Returns NULL and sets LastError on memory failure etc. On success the context is @@ -152,8 +168,7 @@ } opnctx = opnctx_table + idx; opnctx->assoc = NULL; - opnctx->hd = INVALID_HANDLE_VALUE; - opnctx->assoc = 0; + opnctx->rvid = create_rendezvous_id (); opnctx->buffer_size = 512; opnctx->buffer = malloc (opnctx->buffer_size); if (!opnctx->buffer) @@ -173,36 +188,45 @@ leave: LeaveCriticalSection (&opnctx_table_cs); - log_debug ("get_new_opnctx -> %p\n", opnctx); + if (opnctx) + log_debug ("get_new_opnctx -> %p (rvid=%ld)\n", opnctx, opnctx->rvid); + else + log_debug ("get_new_opnctx -> failed\n"); return opnctx; } -/* Find the OPNCTX for handle HD. */ +/* Find the OPNCTX object with the rendezvous id RVID. */ static opnctx_t -find_and_lock_opnctx (HANDLE hd) +find_and_lock_opnctx (LONG rvid) { opnctx_t result = NULL; int idx; EnterCriticalSection (&opnctx_table_cs); for (idx=0; idx < opnctx_table_size; idx++) - if (opnctx_table[idx].inuse && opnctx_table[idx].hd == hd) + if (opnctx_table[idx].inuse && opnctx_table[idx].rvid == rvid) { result = opnctx_table + idx; break; } LeaveCriticalSection (&opnctx_table_cs); if (!result) - SetLastError (ERROR_INVALID_HANDLE); + { + SetLastError (ERROR_INVALID_HANDLE); + log_debug ("find_opnctx -> invalid rendezvous id\n"); + } else if (TryEnterCriticalSection (&result->critsect)) - result->locked++; + { + result->locked++; + log_debug ("find_opnctx -> %p (rvid=%ld)\n", result, result->rvid); + } else { SetLastError (ERROR_BUSY); result = NULL; + log_debug ("find_opnctx -> busy\n"); } - log_debug ("find_opnctx -> %p\n", result); return result; } @@ -353,14 +377,10 @@ for (idx=0; idx < opnctx_table_size; idx++) if (opnctx_table[idx].inuse && (opnctx_table + idx) == opnctx) { - if (opnctx->hd != INVALID_HANDLE_VALUE) + if (opnctx->assoc) { - if (opnctx->assoc) - { - opnctx->assoc->assoc = NULL; - opnctx->assoc = NULL; - } - opnctx->hd = INVALID_HANDLE_VALUE; + opnctx->assoc->assoc = NULL; + opnctx->assoc = NULL; } if (opnctx->locked) { @@ -419,7 +439,7 @@ SetLastError (ERROR_INVALID_ACCESS); goto leave; } - if (rctx->hd == INVALID_HANDLE_VALUE || !rctx->assoc) + if (!rctx->assoc) { SetLastError (ERROR_BROKEN_PIPE); goto leave; @@ -490,7 +510,7 @@ SetLastError (ERROR_INVALID_ACCESS); goto leave; } - if (wctx->hd == INVALID_HANDLE_VALUE || !wctx->assoc) + if (!wctx->assoc) { SetLastError (ERROR_BROKEN_PIPE); goto leave; @@ -546,79 +566,78 @@ static BOOL -set_handle (opnctx_t opnctx, HANDLE hd) +make_pipe (opnctx_t ctx, LONG rvid) { - log_debug (" set_handle(%p, hd=%p)\n", opnctx, hd); - if (opnctx->hd != INVALID_HANDLE_VALUE) - { - SetLastError (ERROR_ALREADY_ASSIGNED); - return FALSE; - } - opnctx->hd = hd; - return TRUE; -} - -static BOOL -make_pipe (opnctx_t rctx, HANDLE hd) -{ BOOL result = FALSE; - opnctx_t wctx = NULL; + opnctx_t peerctx = NULL; - log_debug (" make_pipe(%p, hd=%p)\n", rctx, hd); - if (rctx->hd == INVALID_HANDLE_VALUE) + log_debug (" make_pipe(%p, rvid=%ld)\n", ctx, rvid); + if (ctx->assoc) { - SetLastError (ERROR_NOT_READY); - goto leave; - } - if (rctx->assoc) - { SetLastError (ERROR_ALREADY_ASSIGNED); goto leave; } - if (!(rctx->access_code & GENERIC_READ)) - { - SetLastError (ERROR_INVALID_ACCESS); - goto leave; - } - wctx = find_and_lock_opnctx (hd); - if (!wctx) + peerctx = find_and_lock_opnctx (rvid); + if (!peerctx) { SetLastError (ERROR_NOT_FOUND); goto leave; } - if (wctx == rctx) + if (peerctx == ctx) { SetLastError (ERROR_INVALID_TARGET_HANDLE); goto leave; } - if (wctx->hd == INVALID_HANDLE_VALUE) + if (peerctx->assoc) { - SetLastError (ERROR_NOT_READY); + SetLastError (ERROR_ALREADY_ASSIGNED); goto leave; } - if (wctx->assoc) + + if ((ctx->access_code & GENERIC_READ)) { - SetLastError (ERROR_ALREADY_ASSIGNED); - goto leave; + /* Check that the peer is a write end. */ + if (!(peerctx->access_code & GENERIC_WRITE)) + { + SetLastError (ERROR_INVALID_ACCESS); + goto leave; + } + peerctx->space_available = CreateEvent (NULL, FALSE, FALSE, NULL); + peerctx->data_available = CreateEvent (NULL, FALSE, FALSE, NULL); + + ctx->assoc = peerctx; + peerctx->assoc = ctx; + ctx->is_write = 0; + peerctx->is_write = 1; + result = TRUE; } - if (!(wctx->access_code & GENERIC_WRITE)) + else if ((ctx->access_code & GENERIC_WRITE)) { + /* Check that the peer is a read end. */ + if (!(peerctx->access_code & GENERIC_READ)) + { + SetLastError (ERROR_INVALID_ACCESS); + goto leave; + } + ctx->space_available = CreateEvent (NULL, FALSE, FALSE, NULL); + ctx->data_available = CreateEvent (NULL, FALSE, FALSE, NULL); + + ctx->assoc = peerctx; + peerctx->assoc = ctx; + ctx->is_write = 1; + peerctx->is_write = 0; + result = TRUE; + } + else + { SetLastError (ERROR_INVALID_ACCESS); goto leave; } - wctx->space_available = CreateEvent (NULL, FALSE, FALSE, NULL); - wctx->data_available = CreateEvent (NULL, FALSE, FALSE, NULL); - - rctx->assoc = wctx; - wctx->assoc = rctx; - rctx->is_write = 0; - wctx->is_write = 1; - result = TRUE; leave: - if (wctx) - unlock_opnctx (wctx); + if (peerctx) + unlock_opnctx (peerctx); return result; } @@ -629,6 +648,7 @@ { opnctx_t opnctx = (opnctx_t)opnctx_arg; BOOL result = FALSE; + LONG rvid; log_debug ("GPG_IOControl(%p, %d)\n", (void*)opnctx, code); if (!validate_and_lock_opnctx (opnctx, LOCK_TRY)) @@ -636,25 +656,28 @@ switch (code) { - case GPGCEDEV_IOCTL_SET_HANDLE: - if (!opnctx || !inbuf || inbuflen < sizeof (HANDLE) - || outbuf || outbuflen || actualoutlen ) + case GPGCEDEV_IOCTL_GET_RVID: + if (!opnctx || inbuf || inbuflen + || !outbuf || outbuflen < sizeof (LONG)) { SetLastError (ERROR_INVALID_PARAMETER); goto leave; } - if (set_handle (opnctx, *(HANDLE*)inbuf)) - result = TRUE; + memcpy (outbuf, &opnctx->rvid, sizeof (LONG)); + if (actualoutlen) + *actualoutlen = sizeof (LONG); + result = TRUE; break; case GPGCEDEV_IOCTL_MAKE_PIPE: - if (!opnctx || !inbuf || inbuflen < sizeof (HANDLE) + if (!opnctx || !inbuf || inbuflen < sizeof (LONG) || outbuf || outbuflen || actualoutlen ) { SetLastError (ERROR_INVALID_PARAMETER); goto leave; } - if (make_pipe (opnctx, *(HANDLE*)inbuf)) + memcpy (&rvid, inbuf, sizeof (LONG)); + if (make_pipe (opnctx, rvid)) result = TRUE; break; Modified: trunk/src/libassuan.def =================================================================== --- trunk/src/libassuan.def 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/libassuan.def 2010-03-22 12:16:18 UTC (rev 362) @@ -99,6 +99,8 @@ assuan_set_sock_nonce @78 _assuan_w32ce_create_pipe @79 assuan_free @80 + _assuan_w32ce_prepare_pipe @81 + _assuan_w32ce_finish_pipe @82 ; END Added: trunk/src/mkheader.c =================================================================== --- trunk/src/mkheader.c (rev 0) +++ trunk/src/mkheader.c 2010-03-22 12:16:18 UTC (rev 362) @@ -0,0 +1,192 @@ +/* mkheader.c - Create a header file for libassuan. + * Copyright (C) 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 + * modifications, as long as this notice is preserved. + * + * 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. + */ + + +#include +#include +#include +#include + +#define PGM "mkheader" + +#define LINESIZE 1024 + +static const char *host_os; +static char *srcdir; + + +/* Include the file NAME form the source directory. The included file + is not further expanded. It may have comments indicated by a + double hash masrk at the begin of a line. */ +static void +include_file (const char *fname, int lnr, const char *name) +{ + FILE *fp; + char *incfname; + char line[LINESIZE]; + + incfname = malloc (strlen (srcdir) + strlen (name) + 1); + if (!incfname) + { + fputs (PGM ": out of core\n", stderr); + exit (1); + } + strcpy (incfname, srcdir); + strcat (incfname, name); + + fp = fopen (incfname, "r"); + if (!fp) + { + fprintf (stderr, "%s:%d: error including `%s': %s\n", + fname, lnr, incfname, strerror (errno)); + exit (1); + } + + while (fgets (line, LINESIZE, fp)) + { + if (line[0] != '#' && line[1] != '#') + fputs (line, stdout); + } + if (ferror (fp)) + { + fprintf (stderr, "%s:%d: error reading `%s': %s\n", + fname, lnr, incfname, strerror (errno)); + exit (1); + } + fclose (fp); + free (incfname); +} + + +static int +write_special (const char *fname, int lnr, const char *tag) +{ + if (!strcmp (tag, "include:w32ce-add")) + { + if (!strcmp (host_os, "mingw32ce")) + include_file (fname, lnr, "w32ce-add.h"); + } + else + return 0; /* Unknown tag. */ + + return 1; /* Tag processed. */ +} + + +int +main (int argc, char **argv) +{ + FILE *fp; + char line[LINESIZE]; + int lnr = 0; + const char *fname, *s; + char *p1, *p2; + + if (argc) + { + argc--; argv++; + } + + if (argc != 2) + { + fputs ("usage: " PGM " host_os template.h\n", stderr); + return 1; + } + host_os = argv[0]; + fname = argv[1]; + + srcdir = malloc (strlen (fname) + 2 + 1); + if (!srcdir) + { + fputs (PGM ": out of core\n", stderr); + return 1; + } + strcpy (srcdir, fname); + p1 = strrchr (srcdir, '/'); + if (p1) + p1[1] = 0; + else + strcpy (srcdir, "./"); + + fp = fopen (fname, "r"); + if (!fp) + { + fprintf (stderr, "%s:%d: can't open file: %s", + fname, lnr, strerror (errno)); + return 1; + } + + while (fgets (line, LINESIZE, fp)) + { + size_t n = strlen (line); + + lnr++; + if (!n || line[n-1] != '\n') + { + fprintf (stderr, + "%s:%d: trailing linefeed missing, line too long or " + "embedded Nul character", fname, lnr); + break; + } + line[--n] = 0; + + p1 = strchr (line, '@'); + p2 = p1? strchr (p1+1, '@') : NULL; + if (!p1 || !p2 || p2-p1 == 1) + { + puts (line); + continue; + } + *p1++ = 0; + *p2++ = 0; + fputs (line, stdout); + + if (!strcmp (p1, "configure_input")) + { + s = strrchr (fname, '/'); + printf ("Do not edit. Generated from %s by %s for %s.", + s? s+1 : fname, PGM, host_os); + } + else if (!write_special (fname, lnr, p1)) + { + putchar ('@'); + fputs (p1, stdout); + putchar ('@'); + } + + fputs (p2, stdout); + putchar ('\n'); + } + + if (ferror (fp)) + { + fprintf (stderr, "%s:%d: error reading file: %s\n", + fname, lnr, strerror (errno)); + return 1; + } + + fputs ("/*\n" + "Local Variables:\n" + "buffer-read-only: t\n" + "End:\n" + "*/\n", stdout); + + if (ferror (stdout)) + { + fprintf (stderr, PGM ": error writing stdout: %s\n", strerror (errno)); + return 1; + } + + fclose (fp); + + return 0; +} Modified: trunk/src/system-w32.c =================================================================== --- trunk/src/system-w32.c 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/system-w32.c 2010-03-22 12:16:18 UTC (rev 362) @@ -64,6 +64,33 @@ +/* Three simple wrappers, only used because thes function are named in + the def file. */ +HANDLE +_assuan_w32ce_prepare_pipe (int *r_rvid, int write_end) +{ + (void)r_rvid; + (void)write_end; + return INVALID_HANDLE_VALUE; +} + +HANDLE +_assuan_w32ce_finish_pipe (int rvid, int write_end) +{ + (void)rvid; + (void)write_end; + return INVALID_HANDLE_VALUE; +} + +DWORD +_assuan_w32ce_create_pipe (HANDLE *read_hd, HANDLE *write_hd, + LPSECURITY_ATTRIBUTES sec_attr, DWORD size) +{ + return CreatePipe (read_hd, write_hd, sec_attr, size); +} + + + /* Create a pipe with one inheritable end. Default implementation. */ int __assuan_pipe (assuan_context_t ctx, assuan_fd_t fd[2], int inherit_idx) Modified: trunk/src/system-w32ce.c =================================================================== --- trunk/src/system-w32ce.c 2010-03-16 13:04:42 UTC (rev 361) +++ trunk/src/system-w32ce.c 2010-03-22 12:16:18 UTC (rev 362) @@ -27,57 +27,207 @@ #include #include #include +#include +#include #include "assuan-defs.h" #include "debug.h" +#define GPGCEDEV_IOCTL_GET_RVID \ + CTL_CODE (FILE_DEVICE_STREAMS, 2048, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define GPGCEDEV_IOCTL_MAKE_PIPE \ + CTL_CODE (FILE_DEVICE_STREAMS, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS) + + + -assuan_fd_t -assuan_fdopen (int fd) +static wchar_t * +utf8_to_wchar (const char *string) { - assuan_fd_t ifd = (assuan_fd_t)fd; - assuan_fd_t ofd; + int n; + size_t nbytes; + wchar_t *result; - if (! DuplicateHandle(GetCurrentProcess(), ifd, - GetCurrentProcess(), &ofd, 0, - TRUE, DUPLICATE_SAME_ACCESS)) + if (!string) + return NULL; + + n = MultiByteToWideChar (CP_UTF8, 0, string, -1, NULL, 0); + if (n < 0) { - gpg_err_set_errno (EIO); - return ASSUAN_INVALID_FD; + gpg_err_set_errno (EINVAL); + return NULL; } - return ofd; + + nbytes = (size_t)(n+1) * sizeof(*result); + if (nbytes / sizeof(*result) != (n+1)) + { + gpg_err_set_errno (ENOMEM); + return NULL; + } + result = malloc (nbytes); + if (!result) + return NULL; + + n = MultiByteToWideChar (CP_UTF8, 0, string, -1, result, n); + if (n < 0) + { + free (result); + gpg_err_set_errno (EINVAL); + result = NULL; + } + return result; } +/* Convenience function. */ +static void +free_wchar (wchar_t *string) +{ + if (string) + free (string); +} From cvs at cvs.gnupg.org Mon Mar 22 13:33:12 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 22 Mar 2010 13:33:12 +0100 Subject: [svn] assuan - r363 - trunk/src Message-ID: Author: wk Date: 2010-03-22 13:33:12 +0100 (Mon, 22 Mar 2010) New Revision: 363 Added: trunk/src/w32ce-add.h Modified: trunk/src/ChangeLog trunk/src/Makefile.am trunk/src/mkheader.c Log: Do not distribute assuan.h. Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-22 12:16:18 UTC (rev 362) +++ trunk/src/ChangeLog 2010-03-22 12:33:12 UTC (rev 363) @@ -1,6 +1,7 @@ 2010-03-22 Werner Koch * Makefile.am (mkheader, assuan.h): Build header file. + (nodist_libassuan_la_SOURCES): New. Use it for assuan.h. * mkheader.c: New. * assuan.h: Rename to assuan.h.in. Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2010-03-22 12:16:18 UTC (rev 362) +++ trunk/src/Makefile.am 2010-03-22 12:33:12 UTC (rev 363) @@ -29,7 +29,7 @@ lib_LTLIBRARIES += libgpgcedev.la bin_PROGRAMS = gpgcemgr endif -include_HEADERS = assuan.h +nodist_include_HEADERS = assuan.h if HAVE_LD_VERSION_SCRIPT libassuan_version_script_cmd = -Wl,--version-script=$(srcdir)/libassuan.vers @@ -42,7 +42,7 @@ BUILT_SOURCES = assuan.h common_sources = \ - assuan.h.in assuan.h w32ce-add.h \ + assuan.h.in w32ce-add.h \ assuan-defs.h \ assuan.c context.c system.c \ debug.c debug.h conversion.c sysutils.c \ @@ -109,6 +109,7 @@ libassuan_la_SOURCES = $(common_sources) assuan-io.c +nodist_libassuan_la_SOURCES = assuan.h libassuan_la_CPPFLAGS = $(AM_CPPFLAGS) @GPG_ERROR_CFLAGS@ libassuan_la_LDFLAGS = $(libassuan_res_ldflag) $(no_undefined) \ $(export_symbols) $(libassuan_version_script_cmd) -version-info \ Modified: trunk/src/mkheader.c =================================================================== --- trunk/src/mkheader.c 2010-03-22 12:16:18 UTC (rev 362) +++ trunk/src/mkheader.c 2010-03-22 12:33:12 UTC (rev 363) @@ -53,7 +53,9 @@ while (fgets (line, LINESIZE, fp)) { - if (line[0] != '#' && line[1] != '#') + if (line[0] == '#' && line[1] == '#') + ; + else fputs (line, stdout); } if (ferror (fp)) Added: trunk/src/w32ce-add.h =================================================================== --- trunk/src/w32ce-add.h (rev 0) +++ trunk/src/w32ce-add.h 2010-03-22 12:33:12 UTC (rev 363) @@ -0,0 +1,28 @@ +## w32ce-add.h - Include fragment to build assuan.h. +## Copyright (C) 2010 Free Software Foundation, Inc. +## +## This file is part of Assuan. +## +## Assuan is free software; you can redistribute it and/or modify it +## under the terms of the GNU Lesser General Public License as +## published by the Free Software Foundation; either version 2.1 of +## the License, or (at your option) any later version. +## +## Assuan is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this program; if not, see . +## +## +## This file is included by the mkheader tool. Lines starting with +## a double hash mark are not copied to the destination file. + +HANDLE _assuan_w32ce_prepare_pipe (int *r_rvid, int write_end); +HANDLE _assuan_w32ce_finish_pipe (int rvid, int write_end); +DWORD _assuan_w32ce_create_pipe (HANDLE *read_hd, HANDLE *write_hd, + LPSECURITY_ATTRIBUTES sec_attr, DWORD size); +#define CreatePipe(a,b,c,d) _assuan_w32ce_create_pipe ((a),(b),(c),(d)) + From cvs at cvs.gnupg.org Mon Mar 22 13:46:06 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 22 Mar 2010 13:46:06 +0100 Subject: [svn] GnuPG - r5296 - in trunk: . agent common g10 g13 kbx scd sm tools Message-ID: Author: wk Date: 2010-03-22 13:46:05 +0100 (Mon, 22 Mar 2010) New Revision: 5296 Modified: trunk/agent/gpg-agent.c trunk/agent/preset-passphrase.c trunk/agent/protect-tool.c trunk/autogen.sh trunk/common/ChangeLog trunk/common/Makefile.am trunk/common/argparse.c trunk/common/asshelp.c trunk/common/dns-cert.c trunk/common/estream.c trunk/common/estream.h trunk/common/exechelp.c trunk/common/http.c trunk/common/init.c trunk/common/init.h trunk/common/logging.c trunk/common/pka.c trunk/common/signal.c trunk/common/sysutils.c trunk/common/t-sysutils.c trunk/common/util.h trunk/configure.ac trunk/g10/gpg.c trunk/g10/gpgv.c trunk/g13/g13.c trunk/kbx/kbxutil.c trunk/scd/scdaemon.c trunk/sm/gpgsm.c trunk/sm/server.c trunk/tools/gpg-check-pattern.c trunk/tools/gpg-connect-agent.c trunk/tools/gpgconf.c trunk/tools/symcryptrun.c Log: More chnages to use estream. Add a way to replace the standard descriptors. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/ChangeLog 2010-03-22 12:46:05 UTC (rev 5296) @@ -1,5 +1,42 @@ +2010-03-22 Werner Koch + + * init.c (parse_std_file_handles): Change to use rendezvous ids. + 2010-03-15 Werner Koch + * init.c (init_common_subsystems): Add args ARGCP and + ARGVP. Change all callers to provide them. + (parse_std_file_handles): New. + + * t-sysutils.c (rewind) [W32CE]: Provide a replacement. + + * Makefile.am (module_tests) [W32CE]: Don't build t-exechelp for now. + + * sysutils.c (gnupg_allow_set_foregound_window) [W32CE]: Don't + call AllowSetForegroundWindow. + + * logging.c (isatty) [W32CE]: New. + (fun_writer, set_file_fd): Use estream even for the internal error + messages. + (log_string, log_flush): Make DUMMY_ARG_PTR static. + +2010-03-15 Werner Koch + + * asshelp.c (send_pinentry_environment) [!HAVE_SETLOCALE]: Do not + define OLD_LC. + * http.c (connect_server) [!USE_DNS_SRV]: Mark SRVTAG unused. + * dns-cert.c (get_dns_cert) [!USE_DNS_CERT]: Mark args unused. + * pka.c (get_pka_info): Ditto. + + * signal.c (pause_on_sigusr): Remove. It was used in ancient gpg + version with shared memory IPC. Last caller removed on 2006-04-18. + (do_block) [W32]: Mark arg unused. + + * exechelp.c (w32_open_null): Use CreateFileW. + + * init.c (init_common_subsystems): Add args ARGCP and ARGVP. + Change all callers to pass them. + * logging.c (S_IRGRP, S_IROTH, S_IWGRP, S_IWOTH) [W32]: New. (fun_writer, set_file_fd) [W32]: Disable socket code. Modified: trunk/agent/gpg-agent.c =================================================================== --- trunk/agent/gpg-agent.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/agent/gpg-agent.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -589,7 +589,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Libgcrypt requires us to register the threading model first. @@ -1385,7 +1385,7 @@ HANDLE h, h2; SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE}; - /* We need to use manual reset evet object due to the way our + /* We need to use a manual reset event object due to the way our w32-pth wait function works: If we would use an automatic reset event we are not able to figure out which handle has been signaled because at the time we single out the signaled Modified: trunk/agent/preset-passphrase.c =================================================================== --- trunk/agent/preset-passphrase.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/agent/preset-passphrase.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -210,7 +210,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); opt_homedir = default_homedir (); Modified: trunk/agent/protect-tool.c =================================================================== --- trunk/agent/protect-tool.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/agent/protect-tool.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -1025,7 +1025,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) { Modified: trunk/autogen.sh =================================================================== --- trunk/autogen.sh 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/autogen.sh 2010-03-22 12:46:05 UTC (rev 5296) @@ -76,10 +76,12 @@ fi build=`$tsdir/scripts/config.guess` + extraoptions="" case $myhostsub in ce) [ -z "$w32root" ] && w32root="$HOME/w32ce_root" toolprefixes="arm-mingw32ce" + extraoptions="--disable-scdaemon" ;; *) [ -z "$w32root" ] && w32root="$HOME/w32root" @@ -124,7 +126,7 @@ --with-regex=${w32root} \ --with-pth-prefix=${w32root} \ --with-adns=${w32root} \ - --disable-g13 "$@" + ${extraoptions} --disable-g13 "$@" rc=$? exit $rc fi Modified: trunk/common/Makefile.am =================================================================== --- trunk/common/Makefile.am 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/Makefile.am 2010-03-22 12:46:05 UTC (rev 5296) @@ -142,8 +142,11 @@ if HAVE_W32_SYSTEM jnlib_tests += t-w32-reg endif -module_tests = t-convert t-percent t-gettime t-sysutils t-sexputil t-exechelp \ +module_tests = t-convert t-percent t-gettime t-sysutils t-sexputil \ t-session-env +if !HAVE_W32CE_SYSTEM +module_tests += t-exechelp +endif module_maint_tests = t-helpfile t-b64 Modified: trunk/common/argparse.c =================================================================== --- trunk/common/argparse.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/argparse.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -1131,6 +1131,8 @@ return p; } + +/* Set the usage handler. This function is basically a constructor. */ void set_strusage ( const char *(*f)( int ) ) { Modified: trunk/common/asshelp.c =================================================================== --- trunk/common/asshelp.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/asshelp.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -103,7 +103,9 @@ { gpg_error_t err = 0; +#if defined(HAVE_SETLOCALE) char *old_lc = NULL; +#endif char *dft_lc = NULL; const char *dft_ttyname; int iterator; Modified: trunk/common/dns-cert.c =================================================================== --- trunk/common/dns-cert.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/dns-cert.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -279,6 +279,13 @@ return ret; #endif /*!USE_ADNS*/ #else /* !USE_DNS_CERT */ + (void)name; + (void)max_size; + (void)iobuf; + (void)fpr; + (void)fpr_len; + (void)url; + return -1; #endif } Modified: trunk/common/estream.c =================================================================== --- trunk/common/estream.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/estream.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -245,6 +245,11 @@ #define ESTREAM_LIST_LOCK ESTREAM_MUTEX_LOCK (estream_list_lock) #define ESTREAM_LIST_UNLOCK ESTREAM_MUTEX_UNLOCK (estream_list_lock) +/* File descriptors registered to be used as the standard file handles. */ +static int custom_std_fds[3]; +static unsigned char custom_std_fds_valid[3]; + + #ifndef EOPNOTSUPP # define EOPNOTSUPP ENOSYS #endif @@ -2239,7 +2244,7 @@ estream_t -do_fdopen (int filedes, const char *mode, int no_close) +do_fdopen (int filedes, const char *mode, int no_close, int with_locked_list) { unsigned int modeflags; int create_called; @@ -2261,7 +2266,7 @@ create_called = 1; err = es_create (&stream, cookie, filedes, estream_functions_fd, - modeflags, 0); + modeflags, with_locked_list); out: @@ -2274,14 +2279,14 @@ estream_t es_fdopen (int filedes, const char *mode) { - return do_fdopen (filedes, mode, 0); + return do_fdopen (filedes, mode, 0, 0); } /* A variant of es_fdopen which does not close FILEDES at the end. */ estream_t es_fdopen_nc (int filedes, const char *mode) { - return do_fdopen (filedes, mode, 1); + return do_fdopen (filedes, mode, 1, 0); } @@ -2344,6 +2349,23 @@ } +/* Set custom standard descriptors to be used for stdin, stdout and + stderr. This function needs to be called before any of the + standard streams are accessed. */ +void +_es_set_std_fd (int no, int fd) +{ + ESTREAM_LIST_LOCK; + if (no >= 0 && no < 3 && !custom_std_fds_valid[no]) + { + custom_std_fds[no] = fd; + custom_std_fds_valid[no] = 1; + } + ESTREAM_LIST_UNLOCK; +} + + +/* Return the stream used for stdin, stdout or stderr. */ estream_t _es_get_std_stream (int fd) { @@ -2361,6 +2383,17 @@ } if (!stream) { + /* Standard stream not yet created. We first try to create them + from registered file descriptors. */ + if (!fd && custom_std_fds_valid[0]) + stream = do_fdopen (custom_std_fds[0], "r", 1, 1); + else if (fd == 1 && custom_std_fds_valid[1]) + stream = do_fdopen (custom_std_fds[1], "a", 1, 1); + else if (custom_std_fds_valid[2]) + stream = do_fdopen (custom_std_fds[1], "a", 1, 1); + } + if (!stream) + { /* Standard stream not yet created - do it now. */ if (!fd) stream = do_fpopen (stdin, "r", 1, 1); Modified: trunk/common/estream.h =================================================================== --- trunk/common/estream.h 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/estream.h 2010-03-22 12:46:05 UTC (rev 5296) @@ -80,6 +80,7 @@ #define es_fdopen_nc _ESTREAM_PREFIX(es_fdopen_nc) #define es_fpopen _ESTREAM_PREFIX(es_fpopen) #define es_fpopen_nc _ESTREAM_PREFIX(es_fpopen_nc) +#define _es_set_std_fd _ESTREAM_PREFIX(_es_set_std_fd) #define _es_get_std_stream _ESTREAM_PREFIX(_es_get_std_stream) #define es_freopen _ESTREAM_PREFIX(es_freopen) #define es_fopencookie _ESTREAM_PREFIX(es_fopencookie) @@ -251,6 +252,7 @@ int es_fileno (estream_t stream); int es_fileno_unlocked (estream_t stream); +void _es_set_std_fd (int no, int fd); estream_t _es_get_std_stream (int fd); #define es_stdin _es_get_std_stream (0) @@ -364,7 +366,6 @@ size_t *bytes_written); #endif /*GNUPG_MAJOR_VERSION*/ - #ifdef __cplusplus } #endif Modified: trunk/common/exechelp.c =================================================================== --- trunk/common/exechelp.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/exechelp.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -381,10 +381,10 @@ { HANDLE hfile; - hfile = CreateFile ("nul", - for_write? GENERIC_WRITE : GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_EXISTING, 0, NULL); + hfile = CreateFileW (L"nul", + for_write? GENERIC_WRITE : GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); if (hfile == INVALID_HANDLE_VALUE) log_debug ("can't open `nul': %s\n", w32_strerror (-1)); return hfile; Modified: trunk/common/http.c =================================================================== --- trunk/common/http.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/http.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -1600,6 +1600,8 @@ srvcount = getsrv (srvname, &serverlist); } } +#else + (void)srvtag; #endif /*USE_DNS_SRV*/ if (!serverlist) Modified: trunk/common/init.c =================================================================== --- trunk/common/init.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/init.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -33,16 +33,23 @@ #include "util.h" +#ifdef HAVE_W32CE_SYSTEM +#include +static void parse_std_file_handles (int *argcp, char ***argvp); +#endif /*HAVE_W32CE_SYSTEM*/ + /* This function is to be used early at program startup to make sure that some subsystems are initialized. This is in particular important for W32 to initialize the sockets so that our socket emulation code used directly as well as in libassuan may be used. It should best be called before any I/O is done so that setup - required for logging is ready. CAUTION: This might be called while - running suid(root). */ + required for logging is ready. ARGCP and ARGVP are the addresses + of the parameters given to main. This function may modify them. + + CAUTION: This might be called while running suid(root). */ void -init_common_subsystems (void) +init_common_subsystems (int *argcp, char ***argvp) { /* Try to auto set the character set. */ set_native_charset (NULL); @@ -66,5 +73,85 @@ /* Initialize the Estream library. */ es_init (); + + /* Special hack for Windows CE: We extract some options from arg + to setup the standard handles. */ +#ifdef HAVE_W32CE_SYSTEM + parse_std_file_handles (argcp, argvp); +#else + (void)argcp; + (void)argvp; +#endif } + + +/* WindowsCE uses a very strange way of handling the standard streams. + There is a function SetStdioPath to associate a standard stream + with a file or a device but what we really want is to use pipes as + standard streams. Despite that we implement pipes using a device, + we would have some limitations on the number of open pipes due to + the 3 character limit of device file name. Thus we don't take this + path. Another option would be to install a file system driver with + support for pipes; this would allow us to get rid of the device + name length limitation. However, with GnuPG we can get away be + redefining the standard streams and passing the handles to be used + on the command line. This has also the advantage that it makes + creating a process much easier and does not require the + SetStdioPath set and restore game. The caller needs to pass the + rendezvous ids using up to three options: + + -&S0= -&S1= -&S2= + + They are all optional but they must be the first arguments on the + command line. Parsing stops as soon as an invalid option is found. + These rendezvous ids are then used to finish the pipe creation.*/ +#ifdef HAVE_W32CE_SYSTEM +static void +parse_std_file_handles (int *argcp, char ***argvp) +{ + int argc = *argcp; + char **argv = *argvp; + const char *s; + assuan_fd_t fd; + int i; + int fixup = 0; + + if (!argc) + return; + + for (argc--, argv++; argc; argc--, argv++) + { + s = *argv; + if (*s == '-' && s[1] == '&' && s[2] == 'S' + && (s[3] == '0' || s[3] == '1' || s[3] == '2') + && s[4] == '=' + && (strchr ("-01234567890", s[5]) || !strcmp (s+5, "null"))) + { + if (s[5] == 'n') + fd = ASSUAN_INVALID_FD; + else + fd = _assuan_w32ce_finish_pipe (atoi (s+5), s[3] != '0'); + _es_set_std_fd (s[3] - '0', (int)fd); + fixup++; + } + else + break; + } + + if (fixup) + { + argc = *argcp; + argc -= fixup; + *argcp = argc; + + argv = *argvp; + for (i=1; i < argc; i++) + argv[i] = argv[i + fixup]; + for (; i < argc + fixup; i++) + argv[i] = NULL; + } + + +} +#endif /*HAVE_W32CE_SYSTEM*/ Modified: trunk/common/init.h =================================================================== --- trunk/common/init.h 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/init.h 2010-03-22 12:46:05 UTC (rev 5296) @@ -20,7 +20,7 @@ #ifndef GNUPG_COMMON_INIT_H #define GNUPG_COMMON_INIT_H -void init_common_subsystems (void); +void init_common_subsystems (int *argcp, char ***argvp); #endif /*GNUPG_COMMON_INIT_H*/ Modified: trunk/common/logging.c =================================================================== --- trunk/common/logging.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/logging.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -52,6 +52,11 @@ #endif +#ifdef HAVE_W32CE_SYSTEM +# define isatty(a) (0) +#endif + + static estream_t logstream; static int log_socket = -1; static char prefix_buffer[80]; @@ -138,9 +143,9 @@ if (cookie->fd == -1) { if (!cookie->quiet && !running_detached - && isatty (fileno (stderr))) - fprintf (stderr, "failed to create socket for logging: %s\n", - strerror(errno)); + && isatty (es_fileno (es_stderr))) + es_fprintf (es_stderr, "failed to create socket for logging: %s\n", + strerror(errno)); } else { @@ -156,9 +161,9 @@ if (connect (cookie->fd, (struct sockaddr *) &addr, addrlen) == -1) { if (!cookie->quiet && !running_detached - && isatty (fileno (stderr))) - fprintf (stderr, "can't connect to `%s': %s\n", - cookie->name, strerror(errno)); + && isatty (es_fileno (es_stderr))) + es_fprintf (es_stderr, "can't connect to `%s': %s\n", + cookie->name, strerror(errno)); close (cookie->fd); cookie->fd = -1; } @@ -193,14 +198,14 @@ return (ssize_t)size; /* Okay. */ if (!running_detached && cookie->fd != -1 - && isatty (fileno (stderr))) + && isatty (es_fileno (es_stderr))) { if (*cookie->name) - fprintf (stderr, "error writing to `%s': %s\n", - cookie->name, strerror(errno)); + es_fprintf (es_stderr, "error writing to `%s': %s\n", + cookie->name, strerror(errno)); else - fprintf (stderr, "error writing to file descriptor %d: %s\n", - cookie->fd, strerror(errno)); + es_fprintf (es_stderr, "error writing to file descriptor %d: %s\n", + cookie->fd, strerror(errno)); } if (cookie->is_socket && cookie->fd != -1) { @@ -246,7 +251,7 @@ if (name && !strcmp (name, "-")) { name = NULL; - fd = fileno (stderr); + fd = es_fileno (es_stderr); } #ifndef HAVE_W32_SYSTEM @@ -514,8 +519,10 @@ log_string (int level, const char *string) { /* We need to provide a dummy arg_ptr. volatile is needed to - suppress compiler warnings. */ - volatile va_list dummy_arg_ptr; + suppress compiler warnings. The static is required for gcc 4.4 + because it seems that it detects that a volatile automatic + variable is not any good if not initialized. */ + static volatile va_list dummy_arg_ptr; do_logv (level, 1, string, dummy_arg_ptr); } @@ -597,7 +604,7 @@ void log_flush (void) { - volatile va_list dummy_arg_ptr; + static volatile va_list dummy_arg_ptr; do_logv (JNLIB_LOG_CONT, 1, NULL, dummy_arg_ptr); } Modified: trunk/common/pka.c =================================================================== --- trunk/common/pka.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/pka.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -274,6 +274,8 @@ char * get_pka_info (const char *address, unsigned char *fpr) { + (void)address; + (void)fpr; return NULL; } #endif /* !USE_DNS_PKA */ Modified: trunk/common/signal.c =================================================================== --- trunk/common/signal.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/signal.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -170,38 +170,13 @@ #endif } -void -gnupg_pause_on_sigusr (int which) -{ -#ifndef HAVE_DOSISH_SYSTEM -# ifdef HAVE_SIGPROCMASK - sigset_t mask, oldmask; - assert (which == 1); - sigemptyset( &mask ); - sigaddset( &mask, SIGUSR1 ); - - sigprocmask( SIG_BLOCK, &mask, &oldmask ); - while (!caught_sigusr1) - sigsuspend (&oldmask); - caught_sigusr1 = 0; - sigprocmask (SIG_UNBLOCK, &mask, NULL); -# else - assert (which == 1); - sighold (SIGUSR1); - while (!caught_sigusr1) - sigpause(SIGUSR1); - caught_sigusr1 = 0; - sigrelease(SIGUSR1); -# endif /*!HAVE_SIGPROCMASK*/ -#endif -} - - static void -do_block( int block ) +do_block (int block) { -#ifndef HAVE_DOSISH_SYSTEM +#ifdef HAVE_DOSISH_SYSTEM + (void)block; +#else /*!HAVE_DOSISH_SYSTEM*/ static int is_blocked; #ifdef HAVE_SIGPROCMASK static sigset_t oldmask; @@ -247,7 +222,7 @@ is_blocked = 0; } #endif /*!HAVE_SIGPROCMASK*/ -#endif /*HAVE_DOSISH_SYSTEM*/ +#endif /*!HAVE_DOSISH_SYSTEM*/ } Modified: trunk/common/sysutils.c =================================================================== --- trunk/common/sysutils.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/sysutils.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -498,7 +498,7 @@ if (!pid) log_info ("%s called with invalid pid %lu\n", "gnupg_allow_set_foregound_window", (unsigned long)pid); -#ifdef HAVE_W32_SYSTEM +#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM) else if (!AllowSetForegroundWindow ((pid_t)pid == (pid_t)(-1)?ASFW_ANY:pid)) log_info ("AllowSetForegroundWindow(%lu) failed: %s\n", (unsigned long)pid, w32_strerror (-1)); Modified: trunk/common/t-sysutils.c =================================================================== --- trunk/common/t-sysutils.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/t-sysutils.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -24,6 +24,10 @@ #include "util.h" #include "sysutils.h" +#ifdef HAVE_W32CE_SYSTEM +# define rewind(f) do { fseek (f, 0, SEEK_SET); clearerr (f); } while (0) +#endif + #define pass() do { ; } while(0) #define fail(a) do { fprintf (stderr, "%s:%d: test %d failed\n",\ __FILE__,__LINE__, (a)); \ Modified: trunk/common/util.h =================================================================== --- trunk/common/util.h 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/common/util.h 2010-03-22 12:46:05 UTC (rev 5296) @@ -141,7 +141,6 @@ /*-- signal.c --*/ void gnupg_init_signals (int mode, void (*fast_cleanup)(void)); -void gnupg_pause_on_sigusr (int which); void gnupg_block_all_signals (void); void gnupg_unblock_all_signals (void); Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/configure.ac 2010-03-22 12:46:05 UTC (rev 5296) @@ -484,7 +484,7 @@ # We need to compile and run a program on the build machine. A # comment in libgpg-error says that the AC_PROG_CC_FOR_BUILD macro in -# the AC archive is broken for autoconf 2.57. Given that tehre is no +# the AC archive is broken for autoconf 2.57. Given that there is no # newer version of that macro, we assume that it is also broken for # autoconf 2.61 and thus we use a simple but usually sufficient # approach. Modified: trunk/g10/gpg.c =================================================================== --- trunk/g10/gpg.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/g10/gpg.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -1940,7 +1940,7 @@ /* Make sure that our subsystems are ready. */ i18n_init(); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Check that the libraries are suitable. Do it right here because the option parsing may need services of the library. */ Modified: trunk/g10/gpgv.c =================================================================== --- trunk/g10/gpgv.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/g10/gpgv.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -148,7 +148,7 @@ /* Make sure that our subsystems are ready. */ i18n_init(); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); gnupg_init_signals (0, NULL); Modified: trunk/g13/g13.c =================================================================== --- trunk/g13/g13.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/g13/g13.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -359,7 +359,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Libgcrypt requires us to register the threading model first. Note that this will also do the pth_init. */ Modified: trunk/kbx/kbxutil.c =================================================================== --- trunk/kbx/kbxutil.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/kbx/kbxutil.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -419,7 +419,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Check that the libraries are suitable. Do it here because the option parsing may need services of the library. */ Modified: trunk/scd/scdaemon.c =================================================================== --- trunk/scd/scdaemon.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/scd/scdaemon.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -406,7 +406,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Libgcrypt requires us to register the threading model first. Modified: trunk/sm/gpgsm.c =================================================================== --- trunk/sm/gpgsm.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/sm/gpgsm.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -911,7 +911,7 @@ /* Make sure that our subsystems are ready. */ i18n_init(); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Check that the libraries are suitable. Do it here because the option parse may need services of the library */ Modified: trunk/sm/server.c =================================================================== --- trunk/sm/server.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/sm/server.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -1248,7 +1248,7 @@ /* We use a pipe based server so that we can work from scripts. assuan_init_pipe_server will automagically detect when we are - called with a socketpair and ignore FIELDES in this case. */ + called with a socketpair and ignore FILEDES in this case. */ filedes[0] = assuan_fdopen (0); filedes[1] = assuan_fdopen (1); rc = assuan_new (&ctx); Modified: trunk/tools/gpg-check-pattern.c =================================================================== --- trunk/tools/gpg-check-pattern.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/tools/gpg-check-pattern.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -169,7 +169,7 @@ /* Make sure that our subsystems are ready. */ i18n_init (); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* We need Libgcrypt for hashing. */ if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) Modified: trunk/tools/gpg-connect-agent.c =================================================================== --- trunk/tools/gpg-connect-agent.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/tools/gpg-connect-agent.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -1158,7 +1158,7 @@ /* Make sure that our subsystems are ready. */ i18n_init(); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); assuan_set_gpg_err_source (0); Modified: trunk/tools/gpgconf.c =================================================================== --- trunk/tools/gpgconf.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/tools/gpgconf.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -152,7 +152,7 @@ /* Make sure that our subsystems are ready. */ i18n_init(); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); /* Parse the command line. */ pargs.argc = &argc; Modified: trunk/tools/symcryptrun.c =================================================================== --- trunk/tools/symcryptrun.c 2010-03-15 13:08:51 UTC (rev 5295) +++ trunk/tools/symcryptrun.c 2010-03-22 12:46:05 UTC (rev 5296) @@ -884,7 +884,7 @@ /* Make sure that our subsystems are ready. */ i18n_init(); - init_common_subsystems (); + init_common_subsystems (&argc, &argv); opt.homedir = default_homedir (); From cvs at cvs.gnupg.org Mon Mar 22 15:22:41 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 22 Mar 2010 15:22:41 +0100 Subject: [svn] GnuPG - r5297 - trunk/common Message-ID: Author: wk Date: 2010-03-22 15:22:41 +0100 (Mon, 22 Mar 2010) New Revision: 5297 Modified: trunk/common/ChangeLog trunk/common/exechelp.c Log: Code cleanup. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-22 12:46:05 UTC (rev 5296) +++ trunk/common/ChangeLog 2010-03-22 14:22:41 UTC (rev 5297) @@ -1,5 +1,12 @@ 2010-03-22 Werner Koch + * exechelp.c (create_inheritable_pipe_r) + (create_inheritable_pipe_w): Fold both into ... + (create_inheritable_pipe): .. New. Change callers to use this. + (gnupg_create_inbound_pipe, gnupg_create_outbound_pipe): Factor + code out to ... + (do_create_pipe): .. New. + * init.c (parse_std_file_handles): Change to use rendezvous ids. 2010-03-15 Werner Koch Modified: trunk/common/exechelp.c =================================================================== --- trunk/common/exechelp.c 2010-03-22 12:46:05 UTC (rev 5296) +++ trunk/common/exechelp.c 2010-03-22 14:22:41 UTC (rev 5297) @@ -250,7 +250,7 @@ p = stpcpy (p, "\"\""); else if (strpbrk (string, " \t\n\v\f\"")) { - /* Need top do some kind of quoting. */ + /* Need to do some kind of quoting. */ p = stpcpy (p, "\""); for (s=string; *s; s++) { @@ -311,9 +311,10 @@ #ifdef HAVE_W32_SYSTEM -/* Create pipe where the write end is inheritable. */ +/* Create pipe where one end is inheritable: With an INHERIT_IDX of 0 + the read end is inheritable, with 1 the write end is inheritable. */ static int -create_inheritable_pipe_w (int filedes[2]) +create_inheritable_pipe (int filedes[2], int inherit_idx) { HANDLE r, w, h; SECURITY_ATTRIBUTES sec_attr; @@ -325,7 +326,7 @@ if (!CreatePipe (&r, &w, &sec_attr, 0)) return -1; - if (!DuplicateHandle (GetCurrentProcess(), w, + if (!DuplicateHandle (GetCurrentProcess(), inherit_idx? w : r, GetCurrentProcess(), &h, 0, TRUE, DUPLICATE_SAME_ACCESS )) { @@ -334,39 +335,17 @@ CloseHandle (w); return -1; } - CloseHandle (w); - w = h; - filedes[0] = handle_to_fd (r); - filedes[1] = handle_to_fd (w); - return 0; -} - -/* Create pipe where the read end is inheritable. */ -static int -create_inheritable_pipe_r (int filedes[2]) -{ - HANDLE r, w, h; - SECURITY_ATTRIBUTES sec_attr; - - memset (&sec_attr, 0, sizeof sec_attr ); - sec_attr.nLength = sizeof sec_attr; - sec_attr.bInheritHandle = FALSE; - - if (!CreatePipe (&r, &w, &sec_attr, 0)) - return -1; - - if (!DuplicateHandle (GetCurrentProcess(), r, - GetCurrentProcess(), &h, 0, - TRUE, DUPLICATE_SAME_ACCESS )) + if (inherit_idx) { - log_error ("DuplicateHandle failed: %s\n", w32_strerror (-1)); - CloseHandle (r); CloseHandle (w); - return -1; + w = h; } - CloseHandle (r); - r = h; + else + { + CloseHandle (r); + r = h; + } filedes[0] = handle_to_fd (r); filedes[1] = handle_to_fd (w); @@ -454,10 +433,8 @@ #endif /*!HAVE_W32_SYSTEM*/ -/* Portable function to create a pipe. Under Windows the write end is - inheritable. */ -gpg_error_t -gnupg_create_inbound_pipe (int filedes[2]) +static gpg_error_t +do_create_pipe (int filedes[2], int inherit_idx) { gpg_error_t err = 0; #if HAVE_W32_SYSTEM @@ -465,7 +442,7 @@ filedes[0] = filedes[1] = -1; err = gpg_error (GPG_ERR_GENERAL); - if (!create_inheritable_pipe_w (fds)) + if (!create_inheritable_pipe (fds, inherit_idx)) { filedes[0] = _open_osfhandle (fds[0], 0); if (filedes[0] == -1) @@ -497,48 +474,21 @@ return err; } +/* Portable function to create a pipe. Under Windows the write end is + inheritable. */ +gpg_error_t +gnupg_create_inbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes, 1); +} + /* Portable function to create a pipe. Under Windows the read end is inheritable. */ gpg_error_t gnupg_create_outbound_pipe (int filedes[2]) { - gpg_error_t err = 0; -#if HAVE_W32_SYSTEM - int fds[2]; - - filedes[0] = filedes[1] = -1; - err = gpg_error (GPG_ERR_GENERAL); - if (!create_inheritable_pipe_r (fds)) - { - filedes[0] = _open_osfhandle (fds[0], 0); - if (filedes[0] == -1) - { - log_error ("failed to translate osfhandle %p\n", (void*)fds[0]); - CloseHandle (fd_to_handle (fds[1])); - } - else - { - filedes[1] = _open_osfhandle (fds[1], 1); - if (filedes[1] == -1) - { - log_error ("failed to translate osfhandle %p\n", (void*)fds[1]); - close (filedes[0]); - filedes[0] = -1; - CloseHandle (fd_to_handle (fds[1])); - } - else - err = 0; - } - } -#else - if (pipe (filedes) == -1) - { - err = gpg_error_from_syserror (); - filedes[0] = filedes[1] = -1; - } -#endif - return err; + return do_create_pipe (filedes, 0); } @@ -606,7 +556,7 @@ return err; /* Create a pipe. */ - if (create_inheritable_pipe_w (rp)) + if (create_inheritable_pipe (rp, 1)) { err = gpg_error (GPG_ERR_GENERAL); log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); From cvs at cvs.gnupg.org Mon Mar 22 16:00:54 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 22 Mar 2010 16:00:54 +0100 Subject: [svn] GnuPG - r5298 - trunk/common Message-ID: Author: wk Date: 2010-03-22 16:00:54 +0100 (Mon, 22 Mar 2010) New Revision: 5298 Added: trunk/common/exechelp-posix.c trunk/common/exechelp-w32.c trunk/common/exechelp-w32ce.c Removed: trunk/common/exechelp.c Modified: trunk/common/ChangeLog trunk/common/Makefile.am Log: Reorganized the exechelp code. [The diff below has been truncated] Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-22 14:22:41 UTC (rev 5297) +++ trunk/common/ChangeLog 2010-03-22 15:00:54 UTC (rev 5298) @@ -1,5 +1,8 @@ 2010-03-22 Werner Koch + * exechelp.c: Remove after factoring all code out to ... + * exechelp-posix.c, exechelp-w32.c, exechelp-w32ce.c: .. new. + * exechelp.c (create_inheritable_pipe_r) (create_inheritable_pipe_w): Fold both into ... (create_inheritable_pipe): .. New. Change callers to use this. Modified: trunk/common/Makefile.am =================================================================== --- trunk/common/Makefile.am 2010-03-22 14:22:41 UTC (rev 5297) +++ trunk/common/Makefile.am 2010-03-22 15:00:54 UTC (rev 5298) @@ -77,7 +77,7 @@ iobuf.c iobuf.h \ ttyio.c ttyio.h \ asshelp.c asshelp.h \ - exechelp.c exechelp.h \ + exechelp.h \ signal.c \ audit.c audit.h \ srv.h \ @@ -89,6 +89,18 @@ userids.c userids.h \ helpfile.c +# To make the code easier to read we have split home some code into +# separate source files. +if HAVE_W32_SYSTEM +if HAVE_W32CE_SYSTEM +common_sources += exechelp-w32ce.c +else +common_sources += exechelp-w32.c +endif +else +common_sources += exechelp-posix.c +endif + # Sources only useful without PTH. without_pth_sources = \ get-passphrase.c get-passphrase.h Copied: trunk/common/exechelp-posix.c (from rev 5297, trunk/common/exechelp.c) =================================================================== --- trunk/common/exechelp-posix.c (rev 0) +++ trunk/common/exechelp-posix.c 2010-03-22 15:00:54 UTC (rev 5298) @@ -0,0 +1,555 @@ +/* exechelp.c - Fork and exec helpers for POSIX + * Copyright (C) 2004, 2007, 2008, 2009, + * 2010 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#if defined(HAVE_W32_SYSTEM) || defined (HAVE_W32CE_SYSTEM) +#error This code is only used on POSIX +#endif + +#include +#include +#include +#include +#include +#ifdef HAVE_SIGNAL_H +# include +#endif +#include +#include + +#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */ +#undef HAVE_PTH +#undef USE_GNU_PTH +#endif + +#ifdef USE_GNU_PTH +#include +#endif +#include + +#ifdef HAVE_GETRLIMIT +#include +#include +#endif /*HAVE_GETRLIMIT*/ + +#ifdef HAVE_STAT +# include +#endif + +#include "util.h" +#include "i18n.h" +#include "sysutils.h" +#include "exechelp.h" + + +/* We have the usual problem here: Some modules are linked against pth + and some are not. However we want to use pth_fork and pth_waitpid + here. Using a weak symbol works but is not portable - we should + provide a an explicit dummy pth module instead of using the + pragma. */ +#pragma weak pth_fork +#pragma weak pth_waitpid + + +/* Return the maximum number of currently allowed open file + descriptors. Only useful on POSIX systems but returns a value on + other systems too. */ +int +get_max_fds (void) +{ + int max_fds = -1; +#ifdef HAVE_GETRLIMIT + struct rlimit rl; + +# ifdef RLIMIT_NOFILE + if (!getrlimit (RLIMIT_NOFILE, &rl)) + max_fds = rl.rlim_max; +# endif + +# ifdef RLIMIT_OFILE + if (max_fds == -1 && !getrlimit (RLIMIT_OFILE, &rl)) + max_fds = rl.rlim_max; + +# endif +#endif /*HAVE_GETRLIMIT*/ + +#ifdef _SC_OPEN_MAX + if (max_fds == -1) + { + long int scres = sysconf (_SC_OPEN_MAX); + if (scres >= 0) + max_fds = scres; + } +#endif + +#ifdef _POSIX_OPEN_MAX + if (max_fds == -1) + max_fds = _POSIX_OPEN_MAX; +#endif + +#ifdef OPEN_MAX + if (max_fds == -1) + max_fds = OPEN_MAX; +#endif + + if (max_fds == -1) + max_fds = 256; /* Arbitrary limit. */ + + return max_fds; +} + + +/* Close all file descriptors starting with descriptor FIRST. If + EXCEPT is not NULL, it is expected to be a list of file descriptors + which shall not be closed. This list shall be sorted in ascending + order with the end marked by -1. */ +void +close_all_fds (int first, int *except) +{ + int max_fd = get_max_fds (); + int fd, i, except_start; + + if (except) + { + except_start = 0; + for (fd=first; fd < max_fd; fd++) + { + for (i=except_start; except[i] != -1; i++) + { + if (except[i] == fd) + { + /* If we found the descriptor in the exception list + we can start the next compare run at the next + index because the exception list is ordered. */ + except_start = i + 1; + break; + } + } + if (except[i] == -1) + close (fd); + } + } + else + { + for (fd=first; fd < max_fd; fd++) + close (fd); + } + + gpg_err_set_errno (0); +} + + +/* Returns an array with all currently open file descriptors. The end + of the array is marked by -1. The caller needs to release this + array using the *standard free* and not with xfree. This allow the + use of this fucntion right at startup even before libgcrypt has + been initialized. Returns NULL on error and sets ERRNO + accordingly. */ +int * +get_all_open_fds (void) +{ + int *array; + size_t narray; + int fd, max_fd, idx; +#ifndef HAVE_STAT + array = calloc (1, sizeof *array); + if (array) + array[0] = -1; +#else /*HAVE_STAT*/ + struct stat statbuf; + + max_fd = get_max_fds (); + narray = 32; /* If you change this change also t-exechelp.c. */ + array = calloc (narray, sizeof *array); + if (!array) + return NULL; + + /* Note: The list we return is ordered. */ + for (idx=0, fd=0; fd < max_fd; fd++) + if (!(fstat (fd, &statbuf) == -1 && errno == EBADF)) + { + if (idx+1 >= narray) + { + int *tmp; + + narray += (narray < 256)? 32:256; + tmp = realloc (array, narray * sizeof *array); + if (!tmp) + { + free (array); + return NULL; + } + array = tmp; + } + array[idx++] = fd; + } + array[idx] = -1; +#endif /*HAVE_STAT*/ + return array; +} + + +/* The exec core used right after the fork. This will never return. */ +static void +do_exec (const char *pgmname, const char *argv[], + int fd_in, int fd_out, int fd_err, + void (*preexec)(void) ) +{ + char **arg_list; + int i, j; + int fds[3]; + + fds[0] = fd_in; + fds[1] = fd_out; + fds[2] = fd_err; + + /* Create the command line argument array. */ + i = 0; + if (argv) + while (argv[i]) + i++; + arg_list = xcalloc (i+2, sizeof *arg_list); + arg_list[0] = strrchr (pgmname, '/'); + if (arg_list[0]) + arg_list[0]++; + else + arg_list[0] = xstrdup (pgmname); + if (argv) + for (i=0,j=1; argv[i]; i++, j++) + arg_list[j] = (char*)argv[i]; + + /* Assign /dev/null to unused FDs. */ + for (i=0; i <= 2; i++) + { + if (fds[i] == -1 ) + { + fds[i] = open ("/dev/null", i? O_WRONLY : O_RDONLY); + if (fds[i] == -1) + log_fatal ("failed to open `%s': %s\n", + "/dev/null", strerror (errno)); + } + } + + /* Connect the standard files. */ + for (i=0; i <= 2; i++) + { + if (fds[i] != i && dup2 (fds[i], i) == -1) + log_fatal ("dup2 std%s failed: %s\n", + i==0?"in":i==1?"out":"err", strerror (errno)); + } + + /* Close all other files. */ + close_all_fds (3, NULL); + + if (preexec) + preexec (); + execv (pgmname, arg_list); + /* No way to print anything, as we have closed all streams. */ + _exit (127); +} + + +static gpg_error_t +do_create_pipe (int filedes[2]) +{ + gpg_error_t err = 0; + + if (pipe (filedes) == -1) + { + err = gpg_error_from_syserror (); + filedes[0] = filedes[1] = -1; + } + + return err; +} + +/* Portable function to create a pipe. Under Windows the write end is + inheritable. */ +gpg_error_t +gnupg_create_inbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes); +} + + +/* Portable function to create a pipe. Under Windows the read end is + inheritable. */ +gpg_error_t +gnupg_create_outbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes); +} + + +/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to + stdin, write the output to OUTFILE, return a new stream in + STATUSFILE for stderr and the pid of the process in PID. The + arguments for the process are expected in the NULL terminated array + ARGV. The program name itself should not be included there. If + PREEXEC is not NULL, that function will be called right before the + exec. Calling gnupg_wait_process is required. + + FLAGS is a bit vector with just one bit defined for now: + + Bit 7: If set the process will be started as a background process. + This flag is only useful under W32 systems, so that no new + console is created and pops up a console window when + starting the server + + Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to + error problems this actually allows SetForegroundWindow for + childs of this process. + + Returns 0 on success or an error code. */ +gpg_error_t +gnupg_spawn_process (const char *pgmname, const char *argv[], + FILE *infile, estream_t outfile, + void (*preexec)(void), unsigned int flags, + FILE **statusfile, pid_t *pid) +{ + gpg_error_t err; + int fd, fdout, rp[2]; + + (void)flags; /* Currently not used. */ + + *statusfile = NULL; + *pid = (pid_t)(-1); + fflush (infile); + rewind (infile); + fd = fileno (infile); + fdout = es_fileno (outfile); + if (fd == -1 || fdout == -1) + log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); + + if (pipe (rp) == -1) + { + err = gpg_error_from_syserror (); + log_error (_("error creating a pipe: %s\n"), strerror (errno)); + return err; + } + +#ifdef USE_GNU_PTH + *pid = pth_fork? pth_fork () : fork (); +#else + *pid = fork (); +#endif + if (*pid == (pid_t)(-1)) + { + err = gpg_error_from_syserror (); + log_error (_("error forking process: %s\n"), strerror (errno)); + close (rp[0]); + close (rp[1]); + return err; + } + + if (!*pid) + { + gcry_control (GCRYCTL_TERM_SECMEM); + /* Run child. */ + do_exec (pgmname, argv, fd, fdout, rp[1], preexec); + /*NOTREACHED*/ + } + + /* Parent. */ + close (rp[1]); + + *statusfile = fdopen (rp[0], "r"); + if (!*statusfile) + { + err = gpg_error_from_syserror (); + log_error (_("can't fdopen pipe for reading: %s\n"), strerror (errno)); + kill (*pid, SIGTERM); + *pid = (pid_t)(-1); + return err; + } + + return 0; +} + + + +/* Simplified version of gnupg_spawn_process. This function forks and + then execs PGMNAME, while connecting INFD to stdin, OUTFD to stdout + and ERRFD to stderr (any of them may be -1 to connect them to + /dev/null). The arguments for the process are expected in the NULL + terminated array ARGV. The program name itself should not be + included there. Calling gnupg_wait_process is required. + + Returns 0 on success or an error code. */ +gpg_error_t +gnupg_spawn_process_fd (const char *pgmname, const char *argv[], + int infd, int outfd, int errfd, pid_t *pid) +{ + gpg_error_t err; + +#ifdef USE_GNU_PTH + *pid = pth_fork? pth_fork () : fork (); +#else + *pid = fork (); +#endif + if (*pid == (pid_t)(-1)) + { + err = gpg_error_from_syserror (); + log_error (_("error forking process: %s\n"), strerror (errno)); + return err; + } + + if (!*pid) + { + gcry_control (GCRYCTL_TERM_SECMEM); + /* Run child. */ + do_exec (pgmname, argv, infd, outfd, errfd, NULL); + /*NOTREACHED*/ + } + + return 0; +} + + +/* Wait for the process identified by PID to terminate. PGMNAME should + be the same as supplied to the spawn function and is only used for + diagnostics. Returns 0 if the process succeeded, GPG_ERR_GENERAL + for any failures of the spawned program or other error codes. If + EXITCODE is not NULL the exit code of the process is stored at this + address or -1 if it could not be retrieved. */ +gpg_error_t +gnupg_wait_process (const char *pgmname, pid_t pid, int *exitcode) +{ + gpg_err_code_t ec; + + int i, status; + + if (exitcode) + *exitcode = -1; + + if (pid == (pid_t)(-1)) + return gpg_error (GPG_ERR_INV_VALUE); + +#ifdef USE_GNU_PTH + i = pth_waitpid ? pth_waitpid (pid, &status, 0) : waitpid (pid, &status, 0); +#else + while ( (i=waitpid (pid, &status, 0)) == -1 && errno == EINTR) + ; +#endif + if (i == (pid_t)(-1)) + { + log_error (_("waiting for process %d to terminate failed: %s\n"), + (int)pid, strerror (errno)); + ec = gpg_err_code_from_errno (errno); + } + else if (WIFEXITED (status) && WEXITSTATUS (status) == 127) + { + log_error (_("error running `%s': probably not installed\n"), pgmname); + ec = GPG_ERR_CONFIGURATION; + } + else if (WIFEXITED (status) && WEXITSTATUS (status)) + { + log_error (_("error running `%s': exit status %d\n"), pgmname, + WEXITSTATUS (status)); + if (exitcode) + *exitcode = WEXITSTATUS (status); + ec = GPG_ERR_GENERAL; + } + else if (!WIFEXITED (status)) + { + log_error (_("error running `%s': terminated\n"), pgmname); + ec = GPG_ERR_GENERAL; + } + else + { + if (exitcode) + *exitcode = 0; + ec = 0; + } + + return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, ec); +} + + +/* Spawn a new process and immediatley detach from it. The name of + the program to exec is PGMNAME and its arguments are in ARGV (the + programname is automatically passed as first argument). + Environment strings in ENVP are set. An error is returned if + pgmname is not executable; to make this work it is necessary to + provide an absolute file name. All standard file descriptors are + connected to /dev/null. */ +gpg_error_t +gnupg_spawn_process_detached (const char *pgmname, const char *argv[], + const char *envp[] ) +{ + pid_t pid; + int i; + + if (getuid() != geteuid()) + return gpg_error (GPG_ERR_BUG); + + if (access (pgmname, X_OK)) + return gpg_error_from_syserror (); + +#ifdef USE_GNU_PTH + pid = pth_fork? pth_fork () : fork (); +#else + pid = fork (); +#endif + if (pid == (pid_t)(-1)) + { + log_error (_("error forking process: %s\n"), strerror (errno)); + return gpg_error_from_syserror (); + } + if (!pid) + { + gcry_control (GCRYCTL_TERM_SECMEM); + if (setsid() == -1 || chdir ("/")) + _exit (1); + pid = fork (); /* Double fork to let init takes over the new child. */ + if (pid == (pid_t)(-1)) + _exit (1); + if (pid) + _exit (0); /* Let the parent exit immediately. */ + + if (envp) + for (i=0; envp[i]; i++) + putenv (xstrdup (envp[i])); + + do_exec (pgmname, argv, -1, -1, -1, NULL); + + /*NOTREACHED*/ + } + + if (waitpid (pid, NULL, 0) == -1) + log_error ("waitpid failed in gnupg_spawn_process_detached: %s", + strerror (errno)); + + return 0; +} + + +/* Kill a process; that is send an appropriate signal to the process. + gnupg_wait_process must be called to actually remove the process + from the system. An invalid PID is ignored. */ +void +gnupg_kill_process (pid_t pid) +{ + if (pid != (pid_t)(-1)) + { + kill (pid, SIGTERM); + } +} Property changes on: trunk/common/exechelp-posix.c ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:mergeinfo + Name: svn:eol-style + native Added: trunk/common/exechelp-w32.c =================================================================== --- trunk/common/exechelp-w32.c (rev 0) +++ trunk/common/exechelp-w32.c 2010-03-22 15:00:54 UTC (rev 5298) @@ -0,0 +1,766 @@ +/* exechelp-w32.c - Fork and exec helpers for W32. + * Copyright (C) 2004, 2007, 2008, 2009, + * 2010 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#if !defined(HAVE_W32_SYSTEM) || defined (HAVE_W32CE_SYSTEM) +#error This code is only used on W32. +#endif + +#include +#include +#include +#include +#include +#ifdef HAVE_SIGNAL_H +# include +#endif +#include +#include + +#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */ +#undef HAVE_PTH +#undef USE_GNU_PTH +#endif + +#ifdef USE_GNU_PTH +#include +#endif + +#ifdef HAVE_STAT +# include +#endif + + +#include "util.h" +#include "i18n.h" +#include "sysutils.h" +#include "exechelp.h" + +/* Define to 1 do enable debugging. */ +#define DEBUG_W32_SPAWN 1 + + +/* It seems Vista doesn't grok X_OK and so fails access() tests. + Previous versions interpreted X_OK as F_OK anyway, so we'll just + use F_OK directly. */ +#undef X_OK +#define X_OK F_OK + +/* We assume that a HANDLE can be represented by an int which should + be true for all i386 systems (HANDLE is defined as void *) and + these are the only systems for which Windows is available. Further + we assume that -1 denotes an invalid handle. */ +# define fd_to_handle(a) ((HANDLE)(a)) +# define handle_to_fd(a) ((int)(a)) +# define pid_to_handle(a) ((HANDLE)(a)) +# define handle_to_pid(a) ((int)(a)) + + +/* Return the maximum number of currently allowed open file + descriptors. Only useful on POSIX systems but returns a value on + other systems too. */ +int +get_max_fds (void) +{ + int max_fds = -1; + +#ifdef OPEN_MAX + if (max_fds == -1) + max_fds = OPEN_MAX; +#endif + + if (max_fds == -1) + max_fds = 256; /* Arbitrary limit. */ + + return max_fds; +} + + +/* Close all file descriptors starting with descriptor FIRST. If + EXCEPT is not NULL, it is expected to be a list of file descriptors + which shall not be closed. This list shall be sorted in ascending + order with the end marked by -1. */ +void +close_all_fds (int first, int *except) +{ + int max_fd = get_max_fds (); + int fd, i, except_start; + + if (except) + { + except_start = 0; + for (fd=first; fd < max_fd; fd++) + { + for (i=except_start; except[i] != -1; i++) + { + if (except[i] == fd) + { + /* If we found the descriptor in the exception list + we can start the next compare run at the next + index because the exception list is ordered. */ + except_start = i + 1; + break; + } + } + if (except[i] == -1) + close (fd); + } + } + else + { + for (fd=first; fd < max_fd; fd++) + close (fd); + } + + gpg_err_set_errno (0); +} + + +/* Returns an array with all currently open file descriptors. The end + of the array is marked by -1. The caller needs to release this + array using the *standard free* and not with xfree. This allow the + use of this fucntion right at startup even before libgcrypt has + been initialized. Returns NULL on error and sets ERRNO + accordingly. */ +int * +get_all_open_fds (void) +{ + int *array; + size_t narray; + int fd, max_fd, idx; +#ifndef HAVE_STAT + array = calloc (1, sizeof *array); + if (array) + array[0] = -1; +#else /*HAVE_STAT*/ + struct stat statbuf; + + max_fd = get_max_fds (); + narray = 32; /* If you change this change also t-exechelp.c. */ + array = calloc (narray, sizeof *array); + if (!array) + return NULL; + + /* Note: The list we return is ordered. */ + for (idx=0, fd=0; fd < max_fd; fd++) + if (!(fstat (fd, &statbuf) == -1 && errno == EBADF)) + { + if (idx+1 >= narray) + { + int *tmp; + + narray += (narray < 256)? 32:256; + tmp = realloc (array, narray * sizeof *array); + if (!tmp) + { + free (array); + return NULL; + } + array = tmp; + } + array[idx++] = fd; + } + array[idx] = -1; +#endif /*HAVE_STAT*/ + return array; +} + + +/* Helper function to build_w32_commandline. */ +static char * +build_w32_commandline_copy (char *buffer, const char *string) +{ + char *p = buffer; + const char *s; + + if (!*string) /* Empty string. */ + p = stpcpy (p, "\"\""); + else if (strpbrk (string, " \t\n\v\f\"")) + { + /* Need to do some kind of quoting. */ + p = stpcpy (p, "\""); + for (s=string; *s; s++) + { + *p++ = *s; + if (*s == '\"') + *p++ = *s; + } + *p++ = '\"'; + *p = 0; + } + else + p = stpcpy (p, string); + + return p; +} + +/* Build a command line for use with W32's CreateProcess. On success + CMDLINE gets the address of a newly allocated string. */ +static gpg_error_t +build_w32_commandline (const char *pgmname, const char * const *argv, + char **cmdline) +{ + int i, n; + const char *s; + char *buf, *p; + + *cmdline = NULL; + n = 0; + s = pgmname; + n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ + for (; *s; s++) + if (*s == '\"') + n++; /* Need to double inner quotes. */ + for (i=0; (s=argv[i]); i++) + { + n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ + for (; *s; s++) + if (*s == '\"') + n++; /* Need to double inner quotes. */ + } + n++; + + buf = p = xtrymalloc (n); + if (!buf) + return gpg_error_from_syserror (); + + p = build_w32_commandline_copy (p, pgmname); + for (i=0; argv[i]; i++) + { + *p++ = ' '; + p = build_w32_commandline_copy (p, argv[i]); + } + + *cmdline= buf; + return 0; +} + + +/* Create pipe where one end is inheritable: With an INHERIT_IDX of 0 + the read end is inheritable, with 1 the write end is inheritable. */ +static int +create_inheritable_pipe (int filedes[2], int inherit_idx) +{ + HANDLE r, w, h; + SECURITY_ATTRIBUTES sec_attr; + + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + if (!CreatePipe (&r, &w, &sec_attr, 0)) + return -1; + + if (!DuplicateHandle (GetCurrentProcess(), inherit_idx? w : r, + GetCurrentProcess(), &h, 0, + TRUE, DUPLICATE_SAME_ACCESS )) + { + log_error ("DuplicateHandle failed: %s\n", w32_strerror (-1)); + CloseHandle (r); + CloseHandle (w); + return -1; + } + + if (inherit_idx) + { + CloseHandle (w); + w = h; + } + else + { + CloseHandle (r); + r = h; + } + + filedes[0] = handle_to_fd (r); + filedes[1] = handle_to_fd (w); + return 0; +} + + +static HANDLE +w32_open_null (int for_write) +{ + HANDLE hfile; + + hfile = CreateFileW (L"nul", + for_write? GENERIC_WRITE : GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_EXISTING, 0, NULL); + if (hfile == INVALID_HANDLE_VALUE) + log_debug ("can't open `nul': %s\n", w32_strerror (-1)); + return hfile; +} + + +static gpg_error_t +do_create_pipe (int filedes[2], int inherit_idx) +{ + gpg_error_t err = 0; + int fds[2]; + + filedes[0] = filedes[1] = -1; + err = gpg_error (GPG_ERR_GENERAL); + if (!create_inheritable_pipe (fds, inherit_idx)) + { + filedes[0] = _open_osfhandle (fds[0], 0); + if (filedes[0] == -1) + { + log_error ("failed to translate osfhandle %p\n", (void*)fds[0]); + CloseHandle (fd_to_handle (fds[1])); + } + else + { + filedes[1] = _open_osfhandle (fds[1], 1); + if (filedes[1] == -1) + { + log_error ("failed to translate osfhandle %p\n", (void*)fds[1]); + close (filedes[0]); + filedes[0] = -1; + CloseHandle (fd_to_handle (fds[1])); + } + else + err = 0; + } + } + return err; +} + +/* Portable function to create a pipe. Under Windows the write end is + inheritable. */ +gpg_error_t +gnupg_create_inbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes, 1); +} + + +/* Portable function to create a pipe. Under Windows the read end is + inheritable. */ +gpg_error_t +gnupg_create_outbound_pipe (int filedes[2]) +{ + return do_create_pipe (filedes, 0); +} + + +/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to + stdin, write the output to OUTFILE, return a new stream in + STATUSFILE for stderr and the pid of the process in PID. The + arguments for the process are expected in the NULL terminated array + ARGV. The program name itself should not be included there. If + PREEXEC is not NULL, that function will be called right before the + exec. Calling gnupg_wait_process is required. + + FLAGS is a bit vector with just one bit defined for now: + + Bit 7: If set the process will be started as a background process. + This flag is only useful under W32 systems, so that no new + console is created and pops up a console window when + starting the server + + Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to + error problems this actually allows SetForegroundWindow for + childs of this process. + + Returns 0 on success or an error code. */ +gpg_error_t +gnupg_spawn_process (const char *pgmname, const char *argv[], + FILE *infile, estream_t outfile, + void (*preexec)(void), unsigned int flags, + FILE **statusfile, pid_t *pid) +{ + gpg_error_t err; + SECURITY_ATTRIBUTES sec_attr; + PROCESS_INFORMATION pi = + { + NULL, /* Returns process handle. */ + 0, /* Returns primary thread handle. */ + 0, /* Returns pid. */ + 0 /* Returns tid. */ + }; + STARTUPINFO si; + int cr_flags; + char *cmdline; + int fd, fdout, rp[2]; + + (void)preexec; + + /* Setup return values. */ + *statusfile = NULL; + *pid = (pid_t)(-1); + fflush (infile); + rewind (infile); + fd = _get_osfhandle (fileno (infile)); + fdout = _get_osfhandle (es_fileno (outfile)); + if (fd == -1 || fdout == -1) + log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); + + /* Prepare security attributes. */ + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + /* Build the command line. */ + err = build_w32_commandline (pgmname, argv, &cmdline); + if (err) + return err; + + /* Create a pipe. */ + if (create_inheritable_pipe (rp, 1)) + { + err = gpg_error (GPG_ERR_GENERAL); + log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); + xfree (cmdline); + return err; + } + + /* Start the process. Note that we can't run the PREEXEC function + because this would change our own environment. */ + memset (&si, 0, sizeof si); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + si.wShowWindow = DEBUG_W32_SPAWN? SW_SHOW : SW_MINIMIZE; + si.hStdInput = fd_to_handle (fd); + si.hStdOutput = fd_to_handle (fdout); + si.hStdError = fd_to_handle (rp[1]); + + cr_flags = (CREATE_DEFAULT_ERROR_MODE + | ((flags & 128)? DETACHED_PROCESS : 0) + | GetPriorityClass (GetCurrentProcess ()) + | CREATE_SUSPENDED); +/* log_debug ("CreateProcess, path=`%s' cmdline=`%s'\n", pgmname, cmdline); */ + if (!CreateProcess (pgmname, /* Program to start. */ + cmdline, /* Command line arguments. */ + &sec_attr, /* Process security attributes. */ + &sec_attr, /* Thread security attributes. */ + TRUE, /* Inherit handles. */ + cr_flags, /* Creation flags. */ + NULL, /* Environment. */ + NULL, /* Use current drive/directory. */ + &si, /* Startup information. */ + &pi /* Returns process information. */ + )) + { + log_error ("CreateProcess failed: %s\n", w32_strerror (-1)); + xfree (cmdline); + CloseHandle (fd_to_handle (rp[0])); + CloseHandle (fd_to_handle (rp[1])); + return gpg_error (GPG_ERR_GENERAL); + } + xfree (cmdline); + cmdline = NULL; + + /* Close the other end of the pipe. */ + CloseHandle (fd_to_handle (rp[1])); + +/* log_debug ("CreateProcess ready: hProcess=%p hThread=%p" */ +/* " dwProcessID=%d dwThreadId=%d\n", */ +/* pi.hProcess, pi.hThread, */ +/* (int) pi.dwProcessId, (int) pi.dwThreadId); */ + + /* Fixme: For unknown reasons AllowSetForegroundWindow returns an + invalid argument error if we pass the correct processID to + it. As a workaround we use -1 (ASFW_ANY). */ + if ( (flags & 64) ) + gnupg_allow_set_foregound_window ((pid_t)(-1)/*pi.dwProcessId*/); + + /* Process has been created suspended; resume it now. */ + ResumeThread (pi.hThread); + CloseHandle (pi.hThread); + + { + int x; + + x = _open_osfhandle (rp[0], 0); + if (x == -1) + log_error ("failed to translate osfhandle %p\n", (void*)rp[0] ); + else + *statusfile = fdopen (x, "r"); + } + if (!*statusfile) + { + err = gpg_error_from_syserror (); + log_error (_("can't fdopen pipe for reading: %s\n"), gpg_strerror (err)); + CloseHandle (pi.hProcess); + return err; + } + + *pid = handle_to_pid (pi.hProcess); + return 0; + +} + + + +/* Simplified version of gnupg_spawn_process. This function forks and + then execs PGMNAME, while connecting INFD to stdin, OUTFD to stdout + and ERRFD to stderr (any of them may be -1 to connect them to + /dev/null). The arguments for the process are expected in the NULL + terminated array ARGV. The program name itself should not be + included there. Calling gnupg_wait_process is required. + + Returns 0 on success or an error code. */ +gpg_error_t +gnupg_spawn_process_fd (const char *pgmname, const char *argv[], + int infd, int outfd, int errfd, pid_t *pid) +{ + gpg_error_t err; + SECURITY_ATTRIBUTES sec_attr; + PROCESS_INFORMATION pi = { NULL, 0, 0, 0 }; + STARTUPINFO si; + char *cmdline; + int i; + HANDLE stdhd[3]; + + /* Setup return values. */ + *pid = (pid_t)(-1); + + /* Prepare security attributes. */ + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + /* Build the command line. */ + err = build_w32_commandline (pgmname, argv, &cmdline); + if (err) + return err; + + memset (&si, 0, sizeof si); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; + si.wShowWindow = DEBUG_W32_SPAWN? SW_SHOW : SW_MINIMIZE; + stdhd[0] = infd == -1? w32_open_null (0) : INVALID_HANDLE_VALUE; + stdhd[1] = outfd == -1? w32_open_null (1) : INVALID_HANDLE_VALUE; + stdhd[2] = errfd == -1? w32_open_null (1) : INVALID_HANDLE_VALUE; + si.hStdInput = infd == -1? stdhd[0] : (void*)_get_osfhandle (infd); + si.hStdOutput = outfd == -1? stdhd[1] : (void*)_get_osfhandle (outfd); + si.hStdError = errfd == -1? stdhd[2] : (void*)_get_osfhandle (errfd); + +/* log_debug ("CreateProcess, path=`%s' cmdline=`%s'\n", pgmname, cmdline); */ + if (!CreateProcess (pgmname, /* Program to start. */ + cmdline, /* Command line arguments. */ + &sec_attr, /* Process security attributes. */ + &sec_attr, /* Thread security attributes. */ + TRUE, /* Inherit handles. */ + (CREATE_DEFAULT_ERROR_MODE + | GetPriorityClass (GetCurrentProcess ()) + | CREATE_SUSPENDED | DETACHED_PROCESS), + NULL, /* Environment. */ + NULL, /* Use current drive/directory. */ + &si, /* Startup information. */ + &pi /* Returns process information. */ + )) + { + log_error ("CreateProcess failed: %s\n", w32_strerror (-1)); + err = gpg_error (GPG_ERR_GENERAL); + } + else + err = 0; + xfree (cmdline); + for (i=0; i < 3; i++) + if (stdhd[i] != INVALID_HANDLE_VALUE) + CloseHandle (stdhd[i]); + if (err) + return err; + +/* log_debug ("CreateProcess ready: hProcess=%p hThread=%p" */ +/* " dwProcessID=%d dwThreadId=%d\n", */ +/* pi.hProcess, pi.hThread, */ +/* (int) pi.dwProcessId, (int) pi.dwThreadId); */ + + /* Process has been created suspended; resume it now. */ + ResumeThread (pi.hThread); + CloseHandle (pi.hThread); + + *pid = handle_to_pid (pi.hProcess); + return 0; + +} + + +/* Wait for the process identified by PID to terminate. PGMNAME should + be the same as supplied to the spawn function and is only used for + diagnostics. Returns 0 if the process succeeded, GPG_ERR_GENERAL + for any failures of the spawned program or other error codes. If + EXITCODE is not NULL the exit code of the process is stored at this + address or -1 if it could not be retrieved. */ +gpg_error_t +gnupg_wait_process (const char *pgmname, pid_t pid, int *exitcode) +{ + gpg_err_code_t ec; + HANDLE proc = fd_to_handle (pid); + int code; + DWORD exc; + + if (exitcode) + *exitcode = -1; + + if (pid == (pid_t)(-1)) + return gpg_error (GPG_ERR_INV_VALUE); + + /* FIXME: We should do a pth_waitpid here. However this has not yet + been implemented. A special W32 pth system call would even be + better. */ + code = WaitForSingleObject (proc, INFINITE); + switch (code) + { + case WAIT_FAILED: + log_error (_("waiting for process %d to terminate failed: %s\n"), + (int)pid, w32_strerror (-1)); + ec = GPG_ERR_GENERAL; + break; + + case WAIT_OBJECT_0: + if (!GetExitCodeProcess (proc, &exc)) + { + log_error (_("error getting exit code of process %d: %s\n"), + (int)pid, w32_strerror (-1) ); + ec = GPG_ERR_GENERAL; + } + else if (exc) + { + log_error (_("error running `%s': exit status %d\n"), + pgmname, (int)exc ); + if (exitcode) + *exitcode = (int)exc; + ec = GPG_ERR_GENERAL; + } + else + { + if (exitcode) + *exitcode = 0; + ec = 0; + } + CloseHandle (proc); + break; + + default: + log_error ("WaitForSingleObject returned unexpected " + "code %d for pid %d\n", code, (int)pid ); + ec = GPG_ERR_GENERAL; + break; + } + + return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, ec); +} + + +/* Spawn a new process and immediatley detach from it. The name of + the program to exec is PGMNAME and its arguments are in ARGV (the + programname is automatically passed as first argument). + Environment strings in ENVP are set. An error is returned if + pgmname is not executable; to make this work it is necessary to + provide an absolute file name. All standard file descriptors are + connected to /dev/null. */ +gpg_error_t +gnupg_spawn_process_detached (const char *pgmname, const char *argv[], + const char *envp[] ) +{ + gpg_error_t err; + SECURITY_ATTRIBUTES sec_attr; + PROCESS_INFORMATION pi = + { + NULL, /* Returns process handle. */ + 0, /* Returns primary thread handle. */ + 0, /* Returns pid. */ + 0 /* Returns tid. */ + }; + STARTUPINFO si; + int cr_flags; + char *cmdline; + + + /* FIXME: We don't make use of ENVP yet. It is currently only used + to pass the GPG_AGENT_INFO variable to gpg-agent. As the default + on windows is to use a standard socket, this does not really + matter. */ + (void)envp; + + if (access (pgmname, X_OK)) + return gpg_error_from_syserror (); + + /* Prepare security attributes. */ + memset (&sec_attr, 0, sizeof sec_attr ); + sec_attr.nLength = sizeof sec_attr; + sec_attr.bInheritHandle = FALSE; + + /* Build the command line. */ + err = build_w32_commandline (pgmname, argv, &cmdline); + if (err) + return err; + + /* Start the process. */ + memset (&si, 0, sizeof si); + si.cb = sizeof (si); + si.dwFlags = STARTF_USESHOWWINDOW; + si.wShowWindow = DEBUG_W32_SPAWN? SW_SHOW : SW_MINIMIZE; + + cr_flags = (CREATE_DEFAULT_ERROR_MODE + | GetPriorityClass (GetCurrentProcess ()) + | CREATE_NEW_PROCESS_GROUP + | DETACHED_PROCESS); +/* log_debug ("CreateProcess(detached), path=`%s' cmdline=`%s'\n", */ +/* pgmname, cmdline); */ + if (!CreateProcess (pgmname, /* Program to start. */ + cmdline, /* Command line arguments. */ + &sec_attr, /* Process security attributes. */ + &sec_attr, /* Thread security attributes. */ + FALSE, /* Inherit handles. */ + cr_flags, /* Creation flags. */ + NULL, /* Environment. */ + NULL, /* Use current drive/directory. */ + &si, /* Startup information. */ + &pi /* Returns process information. */ + )) + { + log_error ("CreateProcess(detached) failed: %s\n", w32_strerror (-1)); + xfree (cmdline); + return gpg_error (GPG_ERR_GENERAL); + } + xfree (cmdline); + cmdline = NULL; + +/* log_debug ("CreateProcess(detached) ready: hProcess=%p hThread=%p" */ +/* " dwProcessID=%d dwThreadId=%d\n", */ +/* pi.hProcess, pi.hThread, */ +/* (int) pi.dwProcessId, (int) pi.dwThreadId); */ + + CloseHandle (pi.hThread); + + return 0; +} + + +/* Kill a process; that is send an appropriate signal to the process. + gnupg_wait_process must be called to actually remove the process + from the system. An invalid PID is ignored. */ +void +gnupg_kill_process (pid_t pid) +{ + if (pid != (pid_t) INVALID_HANDLE_VALUE) + { + HANDLE process = (HANDLE) pid; + + /* Arbitrary error code. */ + TerminateProcess (process, 1); + } +} Added: trunk/common/exechelp-w32ce.c =================================================================== --- trunk/common/exechelp-w32ce.c (rev 0) +++ trunk/common/exechelp-w32ce.c 2010-03-22 15:00:54 UTC (rev 5298) @@ -0,0 +1,697 @@ +/* exechelp-w32.c - Fork and exec helpers for W32CE. + * Copyright (C) 2004, 2007, 2008, 2009, + * 2010 Free Software Foundation, Inc. + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include + +#if !defined(HAVE_W32_SYSTEM) && !defined (HAVE_W32CE_SYSTEM) +#error This code is only used on W32CE. +#endif + +#include +#include +#include +#include +#include +#ifdef HAVE_SIGNAL_H +# include +#endif +#include +#include + +#ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth. */ +#undef HAVE_PTH +#undef USE_GNU_PTH +#endif + +#ifdef USE_GNU_PTH +#include +#endif + +#ifdef HAVE_STAT +# include +#endif + + +#include "util.h" +#include "i18n.h" +#include "sysutils.h" +#include "exechelp.h" + + +/* It seems Vista doesn't grok X_OK and so fails access() tests. + Previous versions interpreted X_OK as F_OK anyway, so we'll just + use F_OK directly. */ +#undef X_OK +#define X_OK F_OK + + +/* We assume that a HANDLE can be represented by an int which should + be true for all i386 systems (HANDLE is defined as void *) and + these are the only systems for which Windows is available. Further + we assume that -1 denotes an invalid handle. */ +#define fd_to_handle(a) ((HANDLE)(a)) +#define handle_to_fd(a) ((int)(a)) +#define pid_to_handle(a) ((HANDLE)(a)) +#define handle_to_pid(a) ((int)(a)) + + +/* Return the maximum number of currently allowed open file + descriptors. Only useful on POSIX systems but returns a value on + other systems too. */ +int +get_max_fds (void) +{ + int max_fds = -1; + +#ifdef OPEN_MAX + if (max_fds == -1) + max_fds = OPEN_MAX; +#endif + + if (max_fds == -1) + max_fds = 256; /* Arbitrary limit. */ + + return max_fds; +} + + +/* Close all file descriptors starting with descriptor FIRST. If + EXCEPT is not NULL, it is expected to be a list of file descriptors + which shall not be closed. This list shall be sorted in ascending + order with the end marked by -1. */ +void +close_all_fds (int first, int *except) +{ + int max_fd = get_max_fds (); + int fd, i, except_start; + + if (except) + { + except_start = 0; + for (fd=first; fd < max_fd; fd++) + { + for (i=except_start; except[i] != -1; i++) + { + if (except[i] == fd) + { + /* If we found the descriptor in the exception list + we can start the next compare run at the next + index because the exception list is ordered. */ + except_start = i + 1; + break; + } From cvs at cvs.gnupg.org Tue Mar 23 11:20:56 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 23 Mar 2010 11:20:56 +0100 Subject: [svn] w32pth - r34 - trunk Message-ID: Author: wk Date: 2010-03-23 11:20:55 +0100 (Tue, 23 Mar 2010) New Revision: 34 Modified: trunk/ChangeLog trunk/w32-io.c trunk/w32-pth.c Log: Chnage for new gpgcedev semantics Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-02-26 10:34:34 UTC (rev 33) +++ trunk/ChangeLog 2010-03-23 10:20:55 UTC (rev 34) @@ -1,3 +1,7 @@ +2010-03-23 Werner Koch + + * w32-io.c (create_pipe) [W32CE]: Change to new driver semantics. + 2010-02-26 Werner Koch * w32-pth.c (w32ce_timer_thread): Take care of an empty timer Modified: trunk/w32-io.c =================================================================== --- trunk/w32-io.c 2010-02-26 10:34:34 UTC (rev 33) +++ trunk/w32-io.c 2010-03-23 10:20:55 UTC (rev 34) @@ -32,14 +32,16 @@ #ifdef HAVE_W32CE_SYSTEM # include # include -# define GPGCEDEV_IOCTL_SET_HANDLE \ +# define GPGCEDEV_IOCTL_GET_RVID \ CTL_CODE (FILE_DEVICE_STREAMS, 2048, METHOD_BUFFERED, FILE_ANY_ACCESS) # define GPGCEDEV_IOCTL_MAKE_PIPE \ CTL_CODE (FILE_DEVICE_STREAMS, 2049, METHOD_BUFFERED, FILE_ANY_ACCESS) + +#warning fixme pth_pipe is not correct - only used in dirmngr - remove it? + #endif /*HAVE_W32CE_SYSTEM*/ - #include "utils.h" #include "debug.h" #include "w32-io.h" @@ -941,62 +943,62 @@ LPSECURITY_ATTRIBUTES sec_attr, DWORD size) { #ifdef HAVE_W32CE_SYSTEM - HANDLE hd[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE}; + HANDLE hd[2]; + LONG rvid; TRACE_BEG (DEBUG_SYSIO, "pth:create_pipe", read_hd); *read_hd = *write_hd = INVALID_HANDLE_VALUE; ActivateDevice (L"Drivers\\GnuPG_Device", 0); - /* Note: Using "\\$device\\GPG1" should be identical to "GPG1:". - However this returns an invalid parameter error without having - called GPG_Init in the driver. The docs mention something about - RegisterAFXEx but that API is not documented. */ hd[0] = CreateFile (L"GPG1:", GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hd[0] == INVALID_HANDLE_VALUE) - return 0; + { + DWORD lastrc = GetLastError (); + TRACE_LOG1 ("CreateFile(\"GPG1:\", READ) failed: %d\n", lastrc); + SetLastError (lastrc); + return 0; + } - if (!DeviceIoControl (hd[0], GPGCEDEV_IOCTL_SET_HANDLE, - &hd[0], sizeof hd[0], NULL, 0, NULL, NULL)) - TRACE_LOG1 ("GPGCEDEV_IOCTL_SET_HANDLE(0) failed: %d\n", - (int)GetLastError ()); - + if (!DeviceIoControl (hd[0], GPGCEDEV_IOCTL_GET_RVID, + NULL, 0, &rvid, sizeof rvid, NULL, NULL)) + { + DWORD lastrc = GetLastError (); + TRACE_LOG1 ("GPGCEDEV_IOCTL_GET_RVID failed: %d\n", lastrc); + CloseHandle (hd[0]); + SetLastError (lastrc); + return 0; + } + hd[1] = CreateFile (L"GPG1:", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL); if (hd[1] == INVALID_HANDLE_VALUE) { - DWORD lasterr = GetLastError (); + DWORD lastrc = GetLastError (); + TRACE_LOG1 ("CreateFile(\"GPG1:\", WRITE) failed: %d\n", lastrc); CloseHandle (hd[0]); - SetLastError (lasterr); + SetLastError (lastrc); return 0; } - if (!DeviceIoControl (hd[1], GPGCEDEV_IOCTL_SET_HANDLE, - &hd[1], sizeof hd[1], NULL, 0, NULL, NULL)) - TRACE_LOG1 ("GPGCEDEV_IOCTL_SET_HANDLE(1) failed: %d\n", - (int)GetLastError ()); - - if (!DeviceIoControl (hd[0], GPGCEDEV_IOCTL_MAKE_PIPE, - &hd[1], sizeof hd[1], NULL, 0, NULL, NULL)) + + if (!DeviceIoControl (hd, GPGCEDEV_IOCTL_MAKE_PIPE, + &rvid, sizeof rvid, NULL, 0, NULL, NULL)) { - TRACE_LOG1 ("GPGCEDEV_IOCTL_MAKE_PIPE failed: %d\n", - (int)GetLastError ()); - if (hd[0] != INVALID_HANDLE_VALUE) - CloseHandle (hd[0]); - if (hd[1] != INVALID_HANDLE_VALUE) - CloseHandle (hd[1]); - TRACE_SUC (); + DWORD lastrc = GetLastError (); + TRACE_LOG1 ("GPGCEDEV_IOCTL_MAKE_PIPE failed: %d\n", lastrc); + CloseHandle (hd[0]); + CloseHandle (hd[1]); + SetLastError (lastrc); return 0; } - else - { - *read_hd = hd[0]; - *write_hd = hd[1]; - TRACE_SUC (); - return 1; - } + + *read_hd = hd[0]; + *write_hd = hd[1]; + TRACE_SUC (); + return 1; #else /*!HAVE_W32CE_SYSTEM*/ return CreatePipe (read_hd, write_hd, sec_attr, size); #endif /*!HAVE_W32CE_SYSTEM*/ Modified: trunk/w32-pth.c =================================================================== --- trunk/w32-pth.c 2010-02-26 10:34:34 UTC (rev 33) +++ trunk/w32-pth.c 2010-03-23 10:20:55 UTC (rev 34) @@ -1612,7 +1612,7 @@ /* Special W32 function to cope with the problem that pth_self returns - just a pseudo handle which is not very usefule for debugging. */ + just a pseudo handle which is not very useful for debugging. */ unsigned long pth_thread_id (void) { From cvs at cvs.gnupg.org Wed Mar 24 13:15:31 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 24 Mar 2010 13:15:31 +0100 Subject: [svn] GnuPG - r5299 - in trunk: . am common g10 kbx sm Message-ID: Author: wk Date: 2010-03-24 13:15:30 +0100 (Wed, 24 Mar 2010) New Revision: 5299 Modified: trunk/ChangeLog trunk/am/cmacros.am trunk/common/ChangeLog trunk/common/dotlock.c trunk/common/exechelp-posix.c trunk/common/exechelp-w32.c trunk/common/exechelp-w32ce.c trunk/common/exechelp.h trunk/common/init.c trunk/common/iobuf.c trunk/common/session-env.c trunk/common/stringhelp.c trunk/common/sysutils.c trunk/common/sysutils.h trunk/common/ttyio.c trunk/configure.ac trunk/g10/ChangeLog trunk/kbx/ChangeLog trunk/kbx/Makefile.am trunk/kbx/keybox-update.c trunk/sm/ChangeLog trunk/sm/Makefile.am trunk/sm/certdump.c trunk/sm/export.c trunk/sm/gpgsm.c trunk/sm/import.c trunk/sm/qualified.c trunk/sm/server.c Log: More changes for CE. gpgsm does now build and run a keylisting. [The diff below has been truncated] Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/ChangeLog 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,3 +1,14 @@ +2010-03-24 Werner Koch + + * configure.ac (AH_BOTTOM): Use /gnupg as the default homedir on + dosish systems which don't support drive letters (e.g. W32CE). + + * am/cmacros.am (extra_sys_libs): New. + +2010-03-23 Werner Koch + + * configure.ac (W32SOCKLIBS): Change value for W32CE. + 2010-03-12 Werner Koch * configure.ac (AC_INIT): Prepare for using git. Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/ChangeLog 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,5 +1,36 @@ +2010-03-24 Werner Koch + + * stringhelp.c (change_slashes, compare_filenames): Replace + HAVE_DRIVE_LETTERS by HAVE_DOSISH_SYSTEM. + (make_basename, make_dirname): Detect backslashes and drive + letters separately. + + * dotlock.c (make_dotlock, create_dotlock, release_dotlock): Use + LockFileEx and UnlockFileEx to support W32CE. + + * ttyio.c (USE_W32_CONSOLE): Replace all _WIN32 by this. + (init_ttyfp) [W32CE]: Use stderr. + + * iobuf.c (FD_FOR_STDIN, FD_FOR_STDOUT) [W32CE]: Use estream. + (translate_file_handle) [W32CE]: Remove handle translation. + +2010-03-23 Werner Koch + + * sysutils.c (gnupg_remove): New. + 2010-03-22 Werner Koch + * exechelp-w32ce.c (build_w32_commandline): Replace by code from + libassuan. + (create_inheritable_pipe): Use _assuan_w32ce_prepare_pipe. + (build_w32_commandline_copy, do_create_pipe): Remove. + + * exechelp-posix.c (gnupg_spawn_process): Change to use estream + also for INFILE and STATUSFILE. + * exechelp-w32.c (gnupg_spawn_process): Ditto. + +2010-03-22 Werner Koch + * exechelp.c: Remove after factoring all code out to ... * exechelp-posix.c, exechelp-w32.c, exechelp-w32ce.c: .. new. Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/g10/ChangeLog 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,3 +1,8 @@ +2010-03-24 Werner Koch + + * openfile.c (CMP_FILENAME): Depend on HAVE_DOSISH_SYSTEM instead + of HAVE_DRIVE_LETTERS. + 2010-03-15 Werner Koch * card-util.c: Replace stdio by estream. Modified: trunk/kbx/ChangeLog =================================================================== --- trunk/kbx/ChangeLog 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/kbx/ChangeLog 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,3 +1,12 @@ +2010-03-23 Werner Koch + + * Makefile.am (extra_libs): New. + (kbxutil_LDADD): Use it. + + * keybox-update.c: [HAVE_DOSISH_SYSTEM]: Include sysutils.h. + (keybox_compress): Replace rewind by fseek+clearerr. + (rename_tmp_file, keybox_compress): s/remove/gnupg_remove/. + 2010-03-10 Werner Koch * Makefile.am (kbxutil_LDADD, $(PROGRAMS)): Remove libjnlib.a. Modified: trunk/sm/ChangeLog =================================================================== --- trunk/sm/ChangeLog 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/sm/ChangeLog 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,3 +1,17 @@ +2010-03-24 Werner Koch + + * Makefile.am (gpgsm_LDADD): Add extra_sys_libs. + +2010-03-23 Werner Koch + + * qualified.c (gpgsm_is_in_qualified_list): Replace rewind by + fseek+clearerr. + +2010-03-22 Werner Koch + + * import.c (parse_p12): Use estream functions for the tmp streams. + * export.c (export_p12): Ditto. + 2010-03-11 Werner Koch * verify.c (gpgsm_verify): Use gpgsm_es_print_name. Modified: trunk/am/cmacros.am =================================================================== --- trunk/am/cmacros.am 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/am/cmacros.am 2010-03-24 12:15:30 UTC (rev 5299) @@ -48,7 +48,16 @@ AM_CPPFLAGS += -DGNUPG_DEFAULT_PROTECT_TOOL="\"@GNUPG_PROTECT_TOOL_PGM@\"" endif +# Under Windows we use LockFileEx. WindowsCE provides this only on +# the WindowsMobile 6 platform and thus we need to use the coredll6 +# import library. +if HAVE_W32CE_SYSTEM +extra_sys_libs = -lcoredll6 +else +extra_sys_libs = +endif + # Convenience macros libcommon = ../common/libcommon.a libcommonpth = ../common/libcommonpth.a Modified: trunk/common/dotlock.c =================================================================== --- trunk/common/dotlock.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/dotlock.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,6 +1,6 @@ /* dotlock.c - dotfile locking * Copyright (C) 1998, 2000, 2001, 2003, 2004, - * 2005, 2006, 2008 Free Software Foundation, Inc. + * 2005, 2006, 2008, 2010 Free Software Foundation, Inc. * * This file is part of JNLIB. * @@ -362,7 +362,10 @@ #ifdef HAVE_DOSISH_SYSTEM if (h->locked) { - UnlockFile (h->lockhd, 0, 0, 1, 0); + OVERLAPPED ovl; + + memset (&ovl, 0, sizeof ovl); + UnlockFileEx (h->lockhd, 0, 1, 0, &ovl); } CloseHandle (h->lockhd); #else /* !HAVE_DOSISH_SYSTEM */ @@ -497,8 +500,12 @@ return -1; #else /*HAVE_DOSISH_SYSTEM*/ int w32err; + OVERLAPPED ovl; - if (LockFile (h->lockhd, 0, 0, 1, 0)) + /* Lock one byte at offset 0. The offset is given by OVL. */ + memset (&ovl, 0, sizeof ovl); + if (LockFileEx (h->lockhd, (LOCKFILE_EXCLUSIVE_LOCK + | LOCKFILE_FAIL_IMMEDIATELY), 0, 1, 0, &ovl)) { h->locked = 1; return 0; /* okay */ @@ -552,12 +559,17 @@ } #ifdef HAVE_DOSISH_SYSTEM - if (!UnlockFile (h->lockhd, 0, 0, 1, 0)) - { - log_error ("release_dotlock: error removing lockfile `%s': %s\n", - h->lockname, w32_strerror (-1)); - return -1; - } + { + OVERLAPPED ovl; + + memset (&ovl, 0, sizeof ovl); + if (!UnlockFileEx (h->lockhd, 0, 1, 0, &ovl)) + { + log_error ("release_dotlock: error removing lockfile `%s': %s\n", + h->lockname, w32_strerror (-1)); + return -1; + } + } #else pid = read_lockfile (h, &same_node); Modified: trunk/common/exechelp-posix.c =================================================================== --- trunk/common/exechelp-posix.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/exechelp-posix.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -299,31 +299,12 @@ } -/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to - stdin, write the output to OUTFILE, return a new stream in - STATUSFILE for stderr and the pid of the process in PID. The - arguments for the process are expected in the NULL terminated array - ARGV. The program name itself should not be included there. If - PREEXEC is not NULL, that function will be called right before the - exec. Calling gnupg_wait_process is required. - - FLAGS is a bit vector with just one bit defined for now: - - Bit 7: If set the process will be started as a background process. - This flag is only useful under W32 systems, so that no new - console is created and pops up a console window when - starting the server - - Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to - error problems this actually allows SetForegroundWindow for - childs of this process. - - Returns 0 on success or an error code. */ +/* Fork and exec the PGMNAME, see exechelp.h for details. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - FILE *infile, estream_t outfile, + estream_t infile, estream_t outfile, void (*preexec)(void), unsigned int flags, - FILE **statusfile, pid_t *pid) + estream_t *statusfile, pid_t *pid) { gpg_error_t err; int fd, fdout, rp[2]; @@ -332,9 +313,9 @@ *statusfile = NULL; *pid = (pid_t)(-1); - fflush (infile); - rewind (infile); - fd = fileno (infile); + es_fflush (infile); + es_rewind (infile); + fd = es_fileno (infile); fdout = es_fileno (outfile); if (fd == -1 || fdout == -1) log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); @@ -371,7 +352,7 @@ /* Parent. */ close (rp[1]); - *statusfile = fdopen (rp[0], "r"); + *statusfile = es_fdopen (rp[0], "r"); if (!*statusfile) { err = gpg_error_from_syserror (); Modified: trunk/common/exechelp-w32.c =================================================================== --- trunk/common/exechelp-w32.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/exechelp-w32.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -362,31 +362,12 @@ } -/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to - stdin, write the output to OUTFILE, return a new stream in - STATUSFILE for stderr and the pid of the process in PID. The - arguments for the process are expected in the NULL terminated array - ARGV. The program name itself should not be included there. If - PREEXEC is not NULL, that function will be called right before the - exec. Calling gnupg_wait_process is required. - - FLAGS is a bit vector with just one bit defined for now: - - Bit 7: If set the process will be started as a background process. - This flag is only useful under W32 systems, so that no new - console is created and pops up a console window when - starting the server - - Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to - error problems this actually allows SetForegroundWindow for - childs of this process. - - Returns 0 on success or an error code. */ +/* Fork and exec the PGMNAME, see exechelp.h for details. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - FILE *infile, estream_t outfile, + estream_t infile, estream_t outfile, void (*preexec)(void), unsigned int flags, - FILE **statusfile, pid_t *pid) + estream_t *statusfile, pid_t *pid) { gpg_error_t err; SECURITY_ATTRIBUTES sec_attr; @@ -407,9 +388,9 @@ /* Setup return values. */ *statusfile = NULL; *pid = (pid_t)(-1); - fflush (infile); - rewind (infile); - fd = _get_osfhandle (fileno (infile)); + es_fflush (infile); + es_rewind (infile); + fd = _get_osfhandle (es_fileno (infile)); fdout = _get_osfhandle (es_fileno (outfile)); if (fd == -1 || fdout == -1) log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); @@ -494,7 +475,7 @@ if (x == -1) log_error ("failed to translate osfhandle %p\n", (void*)rp[0] ); else - *statusfile = fdopen (x, "r"); + *statusfile = es_fdopen (x, "r"); } if (!*statusfile) { Modified: trunk/common/exechelp-w32ce.c =================================================================== --- trunk/common/exechelp-w32ce.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/exechelp-w32ce.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -48,6 +48,7 @@ # include #endif +#include #include "util.h" #include "i18n.h" @@ -71,7 +72,128 @@ #define pid_to_handle(a) ((HANDLE)(a)) #define handle_to_pid(a) ((int)(a)) + +#ifdef USE_GNU_PTH +/* The data passed to the feeder_thread. */ +struct feeder_thread_parms +{ + estream_t stream; + int fd; + int direction; +}; + +/* The thread started by start_feeded. */ +static void * +feeder_thread (void *arg) +{ + struct feeder_thread_parms *parm = arg; + char buffer[4096]; + + if (parm->direction) + { + size_t nread; + DWORD nwritten; + + while (!es_read (parm->stream, buffer, sizeof buffer, &nread)) + { + do + { + if (!WriteFile (fd_to_handle (parm->fd), + buffer, nread, &nwritten, NULL)) + { + log_debug ("feeder(%d): WriteFile error: rc=%d\n", + parm->fd, (int)GetLastError ()); + goto leave; + } + nread -= nwritten; + } + while (nread); + } + if (nread) + log_debug ("feeder(%d): es_read error: %s\n", + parm->fd, strerror (errno)); + } + else + { + DWORD nread; + size_t nwritten; + + while (ReadFile (fd_to_handle (parm->fd), + buffer, sizeof buffer, &nread, NULL) && nread) + { + do + { + if (es_write (parm->stream, buffer, nread, &nwritten)) + { + log_debug ("feeder(%d): es_write error: %s\n", + parm->fd, strerror (errno)); + goto leave; + } + nread -= nwritten; + } + while (nread); + } + if (nread) + log_debug ("feeder(%d): ReadFile error: rc=%d\n", + parm->fd, (int)GetLastError ()); + else + log_debug ("feeder(%d): eof\n", parm->fd); + } + +leave: + CloseHandle (fd_to_handle (parm->fd)); + xfree (parm); + return NULL; +} +#endif /*USE_GNU_PTH*/ + +/* Fire up a thread to copy data between STREAM and a pipe's + descriptor FD. With DIRECTION set to true the copy takes place + from the stream to the pipe, otherwise from the pipe to the + stream. */ +static gpg_error_t +start_feeder (estream_t stream, int fd, int direction) +{ +#ifdef USE_GNU_PTH + gpg_error_t err; + struct feeder_thread_parms *parm; + pth_attr_t tattr; + + parm = xtrymalloc (sizeof *parm); + if (!parm) + return gpg_error_from_syserror (); + parm->stream = stream; + parm->fd = fd; + parm->direction = direction; + + tattr = pth_attr_new (); + pth_attr_set (tattr, PTH_ATTR_JOINABLE, 0); + pth_attr_set (tattr, PTH_ATTR_STACK_SIZE, 64*1024); + pth_attr_set (tattr, PTH_ATTR_NAME, "exec-feeder"); + + log_error ("spawning new feeder(%p, %d, %d)\n", stream, fd, direction); + if(!pth_spawn (tattr, feeder_thread, parm)) + { + err = gpg_error_from_syserror (); + log_error ("error spawning feeder: %s\n", gpg_strerror (err)); + xfree (parm); + } + else + err = 0; + pth_attr_destroy (tattr); + + return err; +#else + (void)stream; + (void)fd; + (void)direction; + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); /* No Pth. */ +#endif +} + + + /* Return the maximum number of currently allowed open file descriptors. Only useful on POSIX systems but returns a value on other systems too. */ @@ -182,20 +304,18 @@ } -/* Helper function to build_w32_commandline. */ + static char * -build_w32_commandline_copy (char *buffer, const char *string) +copy_quoted (char *p, const char *string) { - char *p = buffer; const char *s; if (!*string) /* Empty string. */ p = stpcpy (p, "\"\""); - else if (strpbrk (string, " \t\n\v\f\"")) + else if (strpbrk (string, " \t\n\v\f\"")) /* Need quotes. */ { - /* Need to do some kind of quoting. */ p = stpcpy (p, "\""); - for (s=string; *s; s++) + for (s = string; *s; s++) { *p++ = *s; if (*s == '\"') @@ -204,32 +324,52 @@ *p++ = '\"'; *p = 0; } - else + else /* Copy verbatim. */ p = stpcpy (p, string); return p; } + /* Build a command line for use with W32's CreateProcess. On success CMDLINE gets the address of a newly allocated string. */ -static gpg_error_t -build_w32_commandline (const char *pgmname, const char * const *argv, +static int +build_w32_commandline (const char *pgmname, const char * const *argv, + int fd0, int fd1, int fd2, int fd2_isnull, char **cmdline) { int i, n; const char *s; char *buf, *p; + char fdbuf[3*30]; + p = fdbuf; + *p = 0; + if (fd0) + { + snprintf (p, 25, "-&S0=%d ", fd0); + p += strlen (p); + } + if (fd1) + { + snprintf (p, 25, "-&S1=%d ", fd1); + p += strlen (p); + } + if (fd2) + { + if (fd2_isnull) + strcpy (p, "-&S2=null "); + else + snprintf (p, 25, "-&S2=%d ", fd2); + p += strlen (p); + } + *cmdline = NULL; - n = 0; - s = pgmname; - n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ - for (; *s; s++) - if (*s == '\"') - n++; /* Need to double inner quotes. */ - for (i=0; (s=argv[i]); i++) + n = strlen (fdbuf); + n += strlen (pgmname) + 1 + 2; /* (1 space, 2 quoting) */ + for (i=0; (s = argv[i]); i++) { - n += strlen (s) + 1 + 2; /* (1 space, 2 quoting */ + n += strlen (s) + 1 + 2; /* (1 space, 2 quoting) */ for (; *s; s++) if (*s == '\"') n++; /* Need to double inner quotes. */ @@ -237,229 +377,203 @@ n++; buf = p = xtrymalloc (n); - if (!buf) - return gpg_error_from_syserror (); + if (! buf) + return -1; - p = build_w32_commandline_copy (p, pgmname); - for (i=0; argv[i]; i++) + p = stpcpy (p, fdbuf); + p = copy_quoted (p, pgmname); + for (i = 0; argv[i]; i++) { *p++ = ' '; - p = build_w32_commandline_copy (p, argv[i]); + p = copy_quoted (p, argv[i]); } - *cmdline= buf; + *cmdline = buf; return 0; } /* Create pipe where one end is inheritable: With an INHERIT_IDX of 0 - the read end is inheritable, with 1 the write end is inheritable. */ -static int + the read end is inheritable, with 1 the write end is inheritable. + Note that the inheritable ends are rendezvous ids and no file + descriptors or handles. */ +static gpg_error_t create_inheritable_pipe (int filedes[2], int inherit_idx) { - HANDLE r, w, h; + HANDLE hd; + int rvid; - if (!CreatePipe (&r, &w, NULL, 0)) - return -1; - - if (!DuplicateHandle (GetCurrentProcess(), inherit_idx? w : r, - GetCurrentProcess(), &h, 0, - TRUE, DUPLICATE_SAME_ACCESS )) + filedes[0] = filedes[1] = -1; + hd = _assuan_w32ce_prepare_pipe (&rvid, !inherit_idx); + if (hd == INVALID_HANDLE_VALUE) { - log_error ("DuplicateHandle failed: %s\n", w32_strerror (-1)); - CloseHandle (r); - CloseHandle (w); - return -1; + log_error ("_assuan_w32ce_prepare_pipe failed: %s\n", w32_strerror (-1)); + gpg_err_set_errno (EIO); + return gpg_error_from_syserror (); } if (inherit_idx) { - CloseHandle (w); - w = h; + filedes[0] = handle_to_fd (hd); + filedes[1] = rvid; } else { - CloseHandle (r); - r = h; + filedes[0] = rvid; + filedes[1] = handle_to_fd (hd); } - - filedes[0] = handle_to_fd (r); - filedes[1] = handle_to_fd (w); return 0; } -static gpg_error_t -do_create_pipe (int filedes[2], int inherit_idx) -{ - gpg_error_t err = 0; - int fds[2]; - - filedes[0] = filedes[1] = -1; - err = gpg_error (GPG_ERR_GENERAL); - if (!create_inheritable_pipe (fds, inherit_idx)) - { - filedes[0] = _open_osfhandle (fds[0], 0); - if (filedes[0] == -1) - { - log_error ("failed to translate osfhandle %p\n", (void*)fds[0]); - CloseHandle (fd_to_handle (fds[1])); - } - else - { - filedes[1] = _open_osfhandle (fds[1], 1); - if (filedes[1] == -1) - { - log_error ("failed to translate osfhandle %p\n", (void*)fds[1]); - close (filedes[0]); - filedes[0] = -1; - CloseHandle (fd_to_handle (fds[1])); - } - else - err = 0; - } - } - return err; -} - /* Portable function to create a pipe. Under Windows the write end is - inheritable. */ + inheritable (i.e. an rendezvous id). */ gpg_error_t gnupg_create_inbound_pipe (int filedes[2]) { - return do_create_pipe (filedes, 1); + return create_inheritable_pipe (filedes, 1); } /* Portable function to create a pipe. Under Windows the read end is - inheritable. */ + inheritable (i.e. an rendezvous id). */ gpg_error_t gnupg_create_outbound_pipe (int filedes[2]) { - return do_create_pipe (filedes, 0); + return create_inheritable_pipe (filedes, 0); } -/* Fork and exec the PGMNAME, connect the file descriptor of INFILE to - stdin, write the output to OUTFILE, return a new stream in - STATUSFILE for stderr and the pid of the process in PID. The - arguments for the process are expected in the NULL terminated array - ARGV. The program name itself should not be included there. If - PREEXEC is not NULL, that function will be called right before the - exec. Calling gnupg_wait_process is required. +static int +create_process (const char *pgmname, const char *cmdline, + PROCESS_INFORMATION *pi) +{ + int res; + wchar_t *wpgmname, *wcmdline; - FLAGS is a bit vector with just one bit defined for now: + wpgmname = utf8_to_wchar (pgmname); + if (!wpgmname) + return 0; + wcmdline = utf8_to_wchar (cmdline); + if (!wcmdline) + { + xfree (wpgmname); + return 0; + } + res = CreateProcess (wpgmname, /* Program to start. */ + wcmdline, /* Command line arguments. */ + NULL, /* Process security attributes. */ + NULL, /* Thread security attributes. */ + FALSE, /* Inherit handles. */ + CREATE_SUSPENDED, /* Creation flags. */ + NULL, /* Environment. */ + NULL, /* Use current drive/directory. */ + NULL, /* Startup information. */ + pi); /* Returns process information. */ + xfree (wcmdline); + xfree (wpgmname); + return res; +} - Bit 7: If set the process will be started as a background process. - This flag is only useful under W32 systems, so that no new - console is created and pops up a console window when - starting the server. Does not work on W32CE. - - Bit 6: On W32 run AllowSetForegroundWindow for the child. Due to - error problems this actually allows SetForegroundWindow for - childs of this process. - Returns 0 on success or an error code. */ +/* Fork and exec the PGMNAME, see exechelp.h for details. */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - FILE *infile, estream_t outfile, + estream_t infile, estream_t outfile, void (*preexec)(void), unsigned int flags, - FILE **statusfile, pid_t *pid) + estream_t *statusfile, pid_t *pid) { gpg_error_t err; - PROCESS_INFORMATION pi = - { - NULL, /* Returns process handle. */ - 0, /* Returns primary thread handle. */ - 0, /* Returns pid. */ - 0 /* Returns tid. */ - }; - STARTUPINFO si; + PROCESS_INFORMATION pi = {NULL }; char *cmdline; - int fd, fdout, rp[2]; + int inpipe[2], outpipe[2], errpipe[2]; (void)preexec; - + (void)flags; + /* Setup return values. */ *statusfile = NULL; *pid = (pid_t)(-1); - fflush (infile); - rewind (infile); - fd = _get_osfhandle (fileno (infile)); - fdout = _get_osfhandle (es_fileno (outfile)); - if (fd == -1 || fdout == -1) - log_fatal ("no file descriptor for file passed to gnupg_spawn_process\n"); - /* Build the command line. */ - err = build_w32_commandline (pgmname, argv, &cmdline); + es_fflush (infile); + es_rewind (infile); + + /* Create a pipe to copy our infile to the stdin of the child + process. On success inpipe[1] is owned by the feeder. */ + err = create_inheritable_pipe (inpipe, 0); if (err) - return err; + { + log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); + return err; + } + err = start_feeder (infile, inpipe[1], 1); + if (err) + { + log_error (_("error spawning feeder: %s\n"), gpg_strerror (err)); + CloseHandle (fd_to_handle (inpipe[1])); + return err; + } - /* Create a pipe. */ - if (create_inheritable_pipe (rp, 1)) + /* Create a pipe to copy stdout of the child process to our + outfile. On success outpipe[0] is owned by the feeded. */ + err = create_inheritable_pipe (outpipe, 1); + if (err) { - err = gpg_error (GPG_ERR_GENERAL); log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); - xfree (cmdline); return err; } - - /* Start the process. Note that we can't run the PREEXEC function - because this would change our own environment. */ - /* si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; */ - /* si.hStdInput = fd_to_handle (fd); */ - /* si.hStdOutput = fd_to_handle (fdout); */ - /* si.hStdError = fd_to_handle (rp[1]); */ + err = start_feeder (outfile, outpipe[0], 0); + if (err) + { + log_error (_("error spawning feeder: %s\n"), gpg_strerror (err)); + CloseHandle (fd_to_handle (outpipe[0])); + return err; + } -/* log_debug ("CreateProcess, path=`%s' cmdline=`%s'\n", pgmname, cmdline); */ - if (!CreateProcess (pgmname, /* Program to start. */ - cmdline, /* Command line arguments. */ - NULL, /* Process security attributes. */ - NULL, /* Thread security attributes. */ - FALSE, /* Inherit handles. */ - CREATE_SUSPENDED, /* Creation flags. */ - NULL, /* Environment. */ - NULL, /* Use current drive/directory. */ - NULL, /* Startup information. */ - &pi /* Returns process information. */ - )) + + /* Create a pipe for use with stderr of the child process. */ + err = create_inheritable_pipe (errpipe, 1); + if (err) { + log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); + return err; + } + + /* Build the command line. */ + err = build_w32_commandline (pgmname, argv, inpipe[0], outpipe[1], errpipe[1], + 0, &cmdline); + if (err) + { + CloseHandle (fd_to_handle (errpipe[0])); + return err; + } + + + log_debug ("CreateProcess, path=`%s' cmdline=`%s'\n", pgmname, cmdline); + if (!create_process (pgmname, cmdline, &pi)) + { log_error ("CreateProcess failed: %s\n", w32_strerror (-1)); xfree (cmdline); - CloseHandle (fd_to_handle (rp[0])); - CloseHandle (fd_to_handle (rp[1])); + CloseHandle (fd_to_handle (errpipe[0])); return gpg_error (GPG_ERR_GENERAL); } xfree (cmdline); cmdline = NULL; - /* Close the other end of the pipe. */ - CloseHandle (fd_to_handle (rp[1])); + /* Note: The other end of the pipe is a rendezvous id and thus there + is no need to close. */ + + log_debug ("CreateProcess ready: hProcess=%p hThread=%p" + " dwProcessID=%d dwThreadId=%d\n", + pi.hProcess, pi.hThread, + (int) pi.dwProcessId, (int) pi.dwThreadId); -/* log_debug ("CreateProcess ready: hProcess=%p hThread=%p" */ -/* " dwProcessID=%d dwThreadId=%d\n", */ -/* pi.hProcess, pi.hThread, */ -/* (int) pi.dwProcessId, (int) pi.dwThreadId); */ - - /* Fixme: For unknown reasons AllowSetForegroundWindow returns an - invalid argument error if we pass the correct processID to - it. As a workaround we use -1 (ASFW_ANY). */ - if ( (flags & 64) ) - gnupg_allow_set_foregound_window ((pid_t)(-1)/*pi.dwProcessId*/); /* Process has been created suspended; resume it now. */ ResumeThread (pi.hThread); CloseHandle (pi.hThread); - { - int x; - - x = _open_osfhandle (rp[0], 0); - if (x == -1) - log_error ("failed to translate osfhandle %p\n", (void*)rp[0] ); - else - *statusfile = fdopen (x, "r"); - } + *statusfile = es_fdopen (handle_to_fd (errpipe[0]), "r"); if (!*statusfile) { err = gpg_error_from_syserror (); @@ -487,6 +601,8 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[], int infd, int outfd, int errfd, pid_t *pid) { + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); +#if 0 gpg_error_t err; PROCESS_INFORMATION pi = { NULL, 0, 0, 0 }; STARTUPINFO si; @@ -546,10 +662,9 @@ *pid = handle_to_pid (pi.hProcess); return 0; - +#endif } - /* Wait for the process identified by PID to terminate. PGMNAME should be the same as supplied to the spawn function and is only used for diagnostics. Returns 0 if the process succeeded, GPG_ERR_GENERAL @@ -628,6 +743,8 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[], const char *envp[] ) { + return gpg_error (GPG_ERR_NOT_IMPLEMENTED); +#if 0 gpg_error_t err; PROCESS_INFORMATION pi = { @@ -678,9 +795,9 @@ CloseHandle (pi.hThread); return 0; +#endif } - /* Kill a process; that is send an appropriate signal to the process. gnupg_wait_process must be called to actually remove the process from the system. An invalid PID is ignored. */ Modified: trunk/common/exechelp.h =================================================================== --- trunk/common/exechelp.h 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/exechelp.h 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,5 +1,5 @@ /* exechelp.h - Definitions for the fork and exec helpers - * Copyright (C) 2004, 2009 Free Software Foundation, Inc. + * Copyright (C) 2004, 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -58,13 +58,25 @@ arguments for the process are expected in the NULL terminated array ARGV. The program name itself should not be included there. If PREEXEC is not NULL, that function will be called right before the - exec. FLAGS is currently only useful for W32, see the source for - details. Calling gnupg_wait_process is required. Returns 0 on - success or an error code. */ + exec. Calling gnupg_wait_process is required. Returns 0 on + success or an error code. + + FLAGS is a bit vector: + + Bit 7: If set the process will be started as a background process. + This flag is only useful under W32 (but not W32CE) systems, + so that no new console is created and pops up a console + window when starting the server. Does not work on W32CE. + + Bit 6: On W32 (but not on W32CE) run AllowSetForegroundWindow for + the child. Note that due to unknown problems this actually + allows SetForegroundWindow for all childs of this process. + + */ gpg_error_t gnupg_spawn_process (const char *pgmname, const char *argv[], - FILE *infile, estream_t outfile, + estream_t infile, estream_t outfile, void (*preexec)(void), unsigned int flags, - FILE **statusfile, pid_t *pid); + estream_t *statusfile, pid_t *pid); /* Simplified version of gnupg_spawn_process. This function forks and Modified: trunk/common/init.c =================================================================== --- trunk/common/init.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/init.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -101,7 +101,7 @@ SetStdioPath set and restore game. The caller needs to pass the rendezvous ids using up to three options: - -&S0= -&S1= -&S2= + -&S0= -&S1= -&S2= They are all optional but they must be the first arguments on the command line. Parsing stops as soon as an invalid option is found. Modified: trunk/common/iobuf.c =================================================================== --- trunk/common/iobuf.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/iobuf.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -52,8 +52,13 @@ #ifdef HAVE_W32_SYSTEM -# define FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) -# define FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) +# ifdef HAVE_W32CE_SYSTEM +# define FD_FOR_STDIN (es_fileno (es_stdin)) +# define FD_FOR_STDOUT (es_fileno (es_stdout)) +# else +# define FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) +# define FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) +# endif #else /*!HAVE_W32_SYSTEM*/ # define FD_FOR_STDIN (0) # define FD_FOR_STDOUT (1) @@ -2361,7 +2366,7 @@ static int translate_file_handle (int fd, int for_write) { -#ifdef HAVE_W32_SYSTEM +#if defined(HAVE_W32_SYSTEM) && !defined (HAVE_W32CE_SYSTEM) { int x; Modified: trunk/common/session-env.c =================================================================== --- trunk/common/session-env.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/session-env.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,4 +1,4 @@ -/* se4ssiobn-env.c - session environment helper functions. +/* session-env.c - Session environment helper functions. * Copyright (C) 2009 Free Software Foundation, Inc. * * This file is part of GnuPG. @@ -300,7 +300,7 @@ /* Return the value of the environment variable NAME from the SE object. The returned value is valid as long as SE is valid and as long it has not been removed or updated by a call to - session_env_putenv. If the variable does not exist, the fucntion + session_env_putenv. If the variable does not exist, the function tries to return the value trough a call to getenv; if that returns a value, this value is recorded and and used. If no value could be found, returns NULL. The caller must not change the returned @@ -325,7 +325,7 @@ return se->array[idx]->value; } - /* Get the default value with and additional fallback for GPG_TTY. */ + /* Get the default value with an additional fallback for GPG_TTY. */ defvalue = getenv (name); if ((!defvalue || !*defvalue) && !strcmp (name, "GPG_TTY") && ttyname (0)) defvalue = ttyname (0); Modified: trunk/common/stringhelp.c =================================================================== --- trunk/common/stringhelp.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/stringhelp.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -1,6 +1,6 @@ /* stringhelp.c - standard string helper functions - * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, - * 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, + * 2008, 2009, 2010 Free Software Foundation, Inc. * * This file is part of JNLIB. * @@ -48,7 +48,7 @@ static inline char * change_slashes (char *name) { -#ifdef HAVE_DRIVE_LETTERS +#ifdef HAVE_DOSISH_SYSTEM char *p; if (strchr (name, '\\')) @@ -57,7 +57,7 @@ if (*p == '/') *p = '\\'; } -#endif /*HAVE_DRIVE_LETTERS*/ +#endif /*HAVE_DOSISH_SYSTEM*/ return name; } @@ -273,8 +273,10 @@ (void)inputpath; /* Only required for riscos. */ if ( !(p=strrchr(filepath, '/')) ) +#ifdef HAVE_DOSISH_SYSTEM + if ( !(p=strrchr(filepath, '\\')) ) +#endif #ifdef HAVE_DRIVE_LETTERS - if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) #endif { @@ -300,8 +302,10 @@ char *p; if ( !(p=strrchr(filepath, '/')) ) +#ifdef HAVE_DOSISH_SYSTEM + if ( !(p=strrchr(filepath, '\\')) ) +#endif #ifdef HAVE_DRIVE_LETTERS - if ( !(p=strrchr(filepath, '\\')) ) if ( !(p=strrchr(filepath, ':')) ) #endif { @@ -479,12 +483,12 @@ /* Compare whether the filenames are identical. This is a special version of strcmp() taking the semantics of filenames in account. Note that this function works only on the supplied names - without considereing any context like the current directory. See + without considering any context like the current directory. See also same_file_p(). */ int compare_filenames (const char *a, const char *b) { -#ifdef HAVE_DRIVE_LETTERS +#ifdef HAVE_DOSISH_SYSTEM for ( ; *a && *b; a++, b++ ) { if (*a != *b Modified: trunk/common/sysutils.c =================================================================== --- trunk/common/sysutils.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/sysutils.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -505,8 +505,32 @@ #endif } +int +gnupg_remove (const char *fname) +{ +#ifdef HAVE_W32CE_SYSTEM + int rc; + wchar_t *wfname; + wfname = utf8_to_wchar (fname); + if (!wfname) + rc = 0; + else + { + rc = DeleteFile (wfname); + xfree (wfname); + } + if (!rc) + gpg_err_set_errno (EIO); + return !rc; +#else + return remove; +#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 Modified: trunk/common/sysutils.h =================================================================== --- trunk/common/sysutils.h 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/sysutils.h 2010-03-24 12:15:30 UTC (rev 5299) @@ -48,8 +48,8 @@ FILE *gnupg_tmpfile (void); void gnupg_reopen_std (const char *pgmname); void gnupg_allow_set_foregound_window (pid_t pid); +int gnupg_remove (const char *fname); - #ifdef HAVE_W32_SYSTEM #include "../common/w32help.h" Modified: trunk/common/ttyio.c =================================================================== --- trunk/common/ttyio.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/common/ttyio.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -24,6 +24,11 @@ #include #include #include + +#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM) +# define USE_W32_CONSOLE 1 +#endif + #ifdef HAVE_TCGETATTR #include #else @@ -37,12 +42,12 @@ #define HAVE_TCGETATTR #endif #endif -#ifdef _WIN32 /* use the odd Win32 functions */ -#include -#ifdef HAVE_TCGETATTR -#error mingw32 and termios +#ifdef USE_W32_CONSOLE +# include +# ifdef HAVE_TCGETATTR +# error mingw32 and termios +# endif #endif -#endif #include #include @@ -52,7 +57,8 @@ #define CONTROL_D ('D' - 'A' + 1) -#ifdef _WIN32 /* use the odd Win32 functions */ + +#ifdef USE_W32_CONSOLE static struct { HANDLE in, out; } con; @@ -116,7 +122,7 @@ } #endif /*HAVE_CTERMID*/ /* Assume the standard tty on memory error or when tehre is no - certmid. */ + ctermid. */ return name? name : "/dev/tty"; } @@ -140,7 +146,7 @@ if( initialized ) return; -#if defined(_WIN32) +#if defined(USE_W32_CONSOLE) { SECURITY_ATTRIBUTES sa; @@ -168,6 +174,8 @@ ttyfp = stdout; /* Fixme: replace by the real functions: see wklib */ if (my_rl_init_stream) my_rl_init_stream (ttyfp); +#elif defined (HAVE_W32CE_SYSTEM) + ttyfp = stderr; #else ttyfp = batchmode? stderr : fopen (tty_get_ttyname (), "r+"); if( !ttyfp ) { @@ -216,7 +224,7 @@ init_ttyfp(); va_start( arg_ptr, fmt ) ; -#ifdef _WIN32 +#ifdef USE_W32_CONSOLE { char *buf = NULL; int n; @@ -263,7 +271,7 @@ init_ttyfp (); va_start (arg_ptr, fmt); -#ifdef _WIN32 +#ifdef USE_W32_CONSOLE { char *buf = NULL; int n; @@ -300,7 +308,7 @@ if( !initialized ) init_ttyfp(); -#ifdef _WIN32 +#ifdef USE_W32_CONSOLE /* not so effective, change it if you want */ for( ; n; n--, p++ ) if( iscntrl( *p ) ) { @@ -394,7 +402,7 @@ buf = xmalloc((n=50)); i = 0; -#ifdef _WIN32 /* windoze version */ +#ifdef USE_W32_CONSOLE if( hidden ) SetConsoleMode(con.in, HID_INPMODE ); @@ -428,9 +436,17 @@ if( hidden ) SetConsoleMode(con.in, DEF_INPMODE ); -#elif defined(__riscos__) +#elif defined(__riscos__) || defined(HAVE_W32CE_SYSTEM) do { +#ifdef HAVE_W32CE_SYSTEM + /* Using getchar is not a correct solution but for now it + doesn't matter becuase we have no real console at all. We + should rework this as soon as we have switched this entire + module to estream. */ + c = getchar(); +#else c = riscos_getchar(); +#endif if (c == 0xa || c == 0xd) { /* Return || Enter */ c = (int) '\n'; } else if (c == 0x8 || c == 0x7f) { /* Backspace || Delete */ @@ -468,7 +484,7 @@ } } while (c != '\n'); i = (i>0) ? i-1 : 0; -#else /* unix version */ +#else /* Other systems. */ if( hidden ) { #ifdef HAVE_TCGETATTR struct termios term; @@ -509,7 +525,6 @@ i = 1; } - if( hidden ) { #ifdef HAVE_TCGETATTR if( tcsetattr(fileno(ttyfp), TCSAFLUSH, &termsave) ) @@ -601,7 +616,7 @@ last_prompt_len = 0; if( !last_prompt_len ) return; -#ifdef _WIN32 +#ifdef USE_W32_CONSOLE tty_printf("\r%*s\r", last_prompt_len, ""); #else { Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/configure.ac 2010-03-24 12:15:30 UTC (rev 5299) @@ -364,8 +364,12 @@ #define SAFE_VERSION_DASH '-' /* Some global constants. */ -#ifdef HAVE_DRIVE_LETTERS -#define GNUPG_DEFAULT_HOMEDIR "c:/gnupg" +#ifdef HAVE_DOSISH_SYSTEM +# ifdef HAVE_DRIVE_LETTERS +# define GNUPG_DEFAULT_HOMEDIR "c:/gnupg" +# else +# define GNUPG_DEFAULT_HOMEDIR "/gnupg" +# endif #elif defined(__VMS) #define GNUPG_DEFAULT_HOMEDIR "/SYS\$LOGIN/gnupg" #else @@ -376,15 +380,22 @@ /* For some systems (DOS currently), we hardcode the path here. For POSIX systems the values are constructed by the Makefiles, so that the values may be overridden by the make invocations; this is to - comply with the GNU coding standards. */ -#ifdef HAVE_DRIVE_LETTERS - /* FIXME: We need to use a function to determine these values depending - on the actual installation directory. */ -#define GNUPG_BINDIR "c:\\gnupg" -#define GNUPG_LIBEXECDIR "c:\\gnupg" -#define GNUPG_LIBDIR "c:\\gnupg" -#define GNUPG_DATADIR "c:\\gnupg" -#define GNUPG_SYSCONFDIR "c:\\gnupg" + comply with the GNU coding standards. Note that these values are + only defaults. */ +#ifdef HAVE_DOSISH_SYSTEM +# ifdef HAVE_DRIVE_LETTERS +# define GNUPG_BINDIR "c:\\gnupg" +# define GNUPG_LIBEXECDIR "c:\\gnupg" +# define GNUPG_LIBDIR "c:\\gnupg" +# define GNUPG_DATADIR "c:\\gnupg" +# define GNUPG_SYSCONFDIR "c:\\gnupg" +# else +# define GNUPG_BINDIR "\\gnupg" +# define GNUPG_LIBEXECDIR "\\gnupg" +# define GNUPG_LIBDIR "\\gnupg" +# define GNUPG_DATADIR "\\gnupg" +# define GNUPG_SYSCONFDIR "\\gnupg" +# endif #endif /* Derive some other constants. */ @@ -509,17 +520,23 @@ # special stuff for Windoze NT ac_cv_have_dev_random=no AC_DEFINE(USE_ONLY_8DOT3,1, - [set this to limit filenames to the 8.3 format]) - AC_DEFINE(HAVE_DRIVE_LETTERS,1, - [defined if we must run on a stupid file system]) + [Set this to limit filenames to the 8.3 format]) AC_DEFINE(USE_SIMPLE_GETTEXT,1, - [because the Unix gettext has too much overhead on + [Because the Unix gettext has too much overhead on MingW32 systems and these systems lack Posix functions, we use a simplified version of gettext]) disable_keyserver_path=yes have_dosish_system=yes have_w32_system=yes - case "${host}" in *-mingw32ce*) have_w32ce_system=yes ;; esac + case "${host}" in + *-mingw32ce*) + have_w32ce_system=yes + ;; + *) + AC_DEFINE(HAVE_DRIVE_LETTERS,1, + [Defined if the OS supports drive letters.]) + ;; + esac try_gettext="no" use_simple_gettext=yes ;; @@ -576,7 +593,8 @@ AC_DEFINE(HAVE_DOSISH_SYSTEM,1, [Defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2) with special properties like - no file modes]) + no file modes, case insensitive file names and preferred + use of backslashes as directory name separators.]) fi AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = yes) @@ -1272,9 +1290,13 @@ # mysterious reasons - the final link step should bail out. # W32SOCKLIBS is also defined so that if can be used for tools not # requiring any network stuff but linking to code in libcommon which -# tracks in winsock stuff (e.g. init_common_subsystems. +# tracks in winsock stuff (e.g. init_common_subsystems). if test "$have_w32_system" = yes; then - W32SOCKLIBS="-lws2_32" + if test "$have_w32ce_system" = yes; then + W32SOCKLIBS="-lws2" + else + W32SOCKLIBS="-lws2_32" + fi NETLIBS="${NETLIBS} ${W32SOCKLIBS}" fi Modified: trunk/kbx/Makefile.am =================================================================== --- trunk/kbx/Makefile.am 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/kbx/Makefile.am 2010-03-24 12:15:30 UTC (rev 5299) @@ -28,6 +28,12 @@ noinst_LIBRARIES = libkeybox.a bin_PROGRAMS = kbxutil +if HAVE_W32CE_SYSTEM +extra_libs = $(LIBASSUAN_LIBS) +else +extra_libs = +endif + common_sources = \ keybox.h keybox-defs.h keybox-search-desc.h \ keybox-util.c \ @@ -47,7 +53,7 @@ # to do it this way. kbxutil_SOURCES = kbxutil.c $(common_sources) kbxutil_LDADD = ../common/libcommon.a ../gl/libgnu.a \ - $(KSBA_LIBS) $(LIBGCRYPT_LIBS) \ + $(KSBA_LIBS) $(LIBGCRYPT_LIBS) $(extra_libs) \ $(GPG_ERROR_LIBS) $(LIBINTL) $(LIBICONV) $(W32SOCKLIBS) $(PROGRAMS) : ../common/libcommon.a ../gl/libgnu.a Modified: trunk/kbx/keybox-update.c =================================================================== --- trunk/kbx/keybox-update.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/kbx/keybox-update.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -26,6 +26,9 @@ #include #include "keybox-defs.h" +#ifdef HAVE_DOSISH_SYSTEM +#include "../common/sysutils.h" +#endif #define EXTSEP_S "." @@ -174,7 +177,7 @@ if (!secret) { #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) - remove (bakfname); + gnupg_remove (bakfname); #endif if (rename (fname, bakfname) ) { @@ -184,7 +187,7 @@ /* Then rename the file. */ #if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) - remove (fname); + gnupg_remove (fname); #endif if (rename (tmpfname, fname) ) { @@ -607,7 +610,8 @@ } } _keybox_release_blob (blob); - rewind (fp); + fseek (fp, 0, SEEK_SET); + clearerr (fp); } /* Create the new file. */ @@ -709,7 +713,7 @@ /* Rename or remove the temporary file. */ if (rc || !any_changes) - remove (tmpfname); + gnupg_remove (tmpfname); else rc = rename_tmp_file (bakfname, tmpfname, fname, hd->secret); Modified: trunk/sm/Makefile.am =================================================================== --- trunk/sm/Makefile.am 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/sm/Makefile.am 2010-03-24 12:15:30 UTC (rev 5299) @@ -56,7 +56,8 @@ gpgsm_LDADD = $(common_libs) ../common/libgpgrl.a \ $(LIBGCRYPT_LIBS) $(KSBA_LIBS) $(LIBASSUAN_LIBS) \ - $(GPG_ERROR_LIBS) $(LIBREADLINE) $(LIBINTL) $(ZLIBS) $(LIBICONV) + $(GPG_ERROR_LIBS) $(LIBREADLINE) $(LIBINTL) $(ZLIBS) \ + $(LIBICONV) $(extra_sys_libs) # Make sure that all libs are build before we use them. This is # important for things like make -j2. Modified: trunk/sm/certdump.c =================================================================== --- trunk/sm/certdump.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/sm/certdump.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -786,7 +786,7 @@ else if (c->len + size < c->len) { p = NULL; - errno = ENOMEM; + gpg_err_set_errno (ENOMEM); } else if (c->size < c->len + size) { @@ -804,7 +804,7 @@ c->error = errno; xfree (c->buffer); c->buffer = NULL; - errno = c->error; + gpg_err_set_errno (c->error); return -1; } memcpy (p + c->len, buffer, size); @@ -834,8 +834,8 @@ if (!fp) { int save_errno = errno; - log_error ("error creating memory stream: %s\n", strerror (errno)); - errno = save_errno; + log_error ("error creating memory stream: %s\n", strerror (save_errno)); + gpg_err_set_errno (save_errno); return NULL; } gpgsm_es_print_name2 (fp, name, translate); @@ -843,7 +843,7 @@ if (cookie.error || !cookie.buffer) { xfree (cookie.buffer); - errno = cookie.error; + gpg_err_set_errno (cookie.error); return NULL; } return cookie.buffer; Modified: trunk/sm/export.c =================================================================== --- trunk/sm/export.c 2010-03-22 15:00:54 UTC (rev 5298) +++ trunk/sm/export.c 2010-03-24 12:15:30 UTC (rev 5299) @@ -561,7 +561,8 @@ static gpg_error_t popen_protect_tool (ctrl_t ctrl, const char *pgmname, - FILE *infile, estream_t outfile, FILE **statusfile, + estream_t infile, estream_t outfile, + estream_t *statusfile, const char *prompt, const char *keygrip, pid_t *pid) { @@ -611,7 +612,8 @@ gpg_error_t err = 0, child_err = 0; int c, cont_line; unsigned int pos; - FILE *infp = NULL, *fp = NULL; + estream_t infp = NULL; + estream_t fp = NULL; estream_t outfp = NULL; char buffer[1024]; pid_t pid = -1; @@ -622,7 +624,7 @@ else pgmname = opt.protect_tool_program; - infp = gnupg_tmpfile (); + infp = es_tmpfile (); if (!infp) From cvs at cvs.gnupg.org Wed Mar 24 16:51:37 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Wed, 24 Mar 2010 16:51:37 +0100 Subject: [svn] gcry - r1424 - in trunk: . random Message-ID: Author: wk Date: 2010-03-24 16:51:37 +0100 (Wed, 24 Mar 2010) New Revision: 1424 Added: trunk/random/rndw32ce.c Modified: trunk/ChangeLog trunk/configure.ac trunk/random/ChangeLog trunk/random/Makefile.am trunk/random/rand-internal.h trunk/random/random-csprng.c trunk/random/rndw32.c Log: Added an entropy gatherer for W32CE. Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/ChangeLog 2010-03-24 15:51:37 UTC (rev 1424) @@ -1,3 +1,7 @@ +2010-03-24 Werner Koch + + * configure.ac (USE_RNDW32CE): New. + 2010-03-15 Werner Koch * configure.ac (emacs_local_vars_begin) Modified: trunk/random/ChangeLog =================================================================== --- trunk/random/ChangeLog 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/random/ChangeLog 2010-03-24 15:51:37 UTC (rev 1424) @@ -1,3 +1,12 @@ +2010-03-24 Werner Koch + + * rndw32.c: Revert all changes from 2010-01-21. + + * rndw32ce.c: New. + * Makefile.am (EXTRA_librandom_la_SOURCES): Add it. + * random-csprng.c (getfnc_gather_random) + (getfnc_fast_random_poll) [USE_RNDW32CE]: Use rndw32ce. + 2010-01-21 Werner Koch * rndw32.c (read_mbm_data) [W32CE]: Do not build. Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/configure.ac 2010-03-24 15:51:37 UTC (rev 1424) @@ -179,10 +179,17 @@ # Setup some stuff depending on host. case "${host}" in *-*-mingw32*) - available_random_modules="w32" ac_cv_have_dev_random=no have_w32_system=yes - case "${host}" in *-mingw32ce*) have_w32ce_system=yes ;; esac + case "${host}" in + *-mingw32ce*) + have_w32ce_system=yes + available_random_modules="w32ce" + ;; + *) + available_random_modules="w32" + ;; + esac AC_DEFINE(USE_ONLY_8DOT3,1, [set this to limit filenames to the 8.3 format]) AC_DEFINE(HAVE_DRIVE_LETTERS,1, @@ -245,11 +252,11 @@ # A printable OS Name is sometimes useful. case "${host}" in *-*-mingw32ce*) - PRINTABLE_OS_NAME="MingW32CE" + PRINTABLE_OS_NAME="W32CE" ;; *-*-mingw32*) - PRINTABLE_OS_NAME="MingW32" + PRINTABLE_OS_NAME="W32" ;; i?86-emx-os2 | i?86-*-os2*emx ) @@ -807,6 +814,10 @@ random_modules="linux" else case "${host}" in + *-*-mingw32ce*) + # WindowsCE random device. + random_modules="w32ce" + ;; *-*-mingw32*|*-*-cygwin*) # Windows random device. random_modules="w32" @@ -1105,6 +1116,13 @@ [Defined if the Windows specific RNG should be used.]) fi +LIST_MEMBER(w32ce, $random_modules) +if test "$found" = "1" ; then + GCRYPT_RANDOM="$GCRYPT_RANDOM rndw32ce.lo" + AC_DEFINE(USE_RNDW32CE, 1, + [Defined if the WindowsCE specific RNG should be used.]) +fi + AC_SUBST([GCRYPT_CIPHERS]) AC_SUBST([GCRYPT_PUBKEY_CIPHERS]) AC_SUBST([GCRYPT_DIGESTS]) Modified: trunk/random/Makefile.am =================================================================== --- trunk/random/Makefile.am 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/random/Makefile.am 2010-03-24 15:51:37 UTC (rev 1424) @@ -46,4 +46,5 @@ rndlinux.c \ rndegd.c \ rndunix.c \ -rndw32.c +rndw32.c \ +rndw32ce.c Modified: trunk/random/rand-internal.h =================================================================== --- trunk/random/rand-internal.h 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/random/rand-internal.h 2010-03-24 15:51:37 UTC (rev 1424) @@ -123,6 +123,15 @@ enum random_origins), enum random_origins origin ); +/*-- rndw32ce.c --*/ +int _gcry_rndw32ce_gather_random (void (*add) (const void *, size_t, + enum random_origins), + enum random_origins origin, + size_t length, int level); +void _gcry_rndw32ce_gather_random_fast (void (*add)(const void*, size_t, + enum random_origins), + enum random_origins origin ); + /*-- rndhw.c --*/ int _gcry_rndhw_failed_p (void); void _gcry_rndhw_poll_fast (void (*add)(const void*, size_t, Modified: trunk/random/random-csprng.c =================================================================== --- trunk/random/random-csprng.c 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/random/random-csprng.c 2010-03-24 15:51:37 UTC (rev 1424) @@ -1,6 +1,6 @@ /* random-csprng.c - CSPRNG style random number generator (libgcrypt classic) * Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008 Free Software Foundation, Inc. + * 2007, 2008, 2010 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * @@ -1144,6 +1144,11 @@ return fnc; #endif +#if USE_RNDW32CE + fnc = _gcry_rndw32ce_gather_random; + return fnc; +#endif + log_fatal (_("no entropy gathering module detected\n")); return NULL; /*NOTREACHED*/ @@ -1159,6 +1164,9 @@ #if USE_RNDW32 return _gcry_rndw32_gather_random_fast; #endif +#if USE_RNDW32CE + return _gcry_rndw32ce_gather_random_fast; +#endif return NULL; } Modified: trunk/random/rndw32.c =================================================================== --- trunk/random/rndw32.c 2010-03-15 12:27:29 UTC (rev 1423) +++ trunk/random/rndw32.c 2010-03-24 15:51:37 UTC (rev 1424) @@ -329,7 +329,6 @@ /* Read data from MBM. This communicates via shared memory, so all we need to do is map a file and read the data out. */ -#ifndef HAVE_W32CE_SYSTEM static void read_mbm_data (void (*add)(const void*, size_t, enum random_origins), enum random_origins requester) @@ -352,7 +351,6 @@ CloseHandle (hMBMData); } } -#endif /*!HAVE_W32CE_SYSTEM*/ /* Fallback method using the registry to poll the statistics. */ @@ -559,9 +557,7 @@ } read_system_rng ( add, requester ); -#ifndef HAVE_W32CE_SYSTEM read_mbm_data ( add, requester ); -#endif /* Get network statistics. Note: Both NT Workstation and NT Server by default will be running both the workstation and server services. The @@ -779,13 +775,8 @@ OSVERSIONINFO osvi = { sizeof( osvi ) }; GetVersionEx( &osvi ); -#ifdef HAVE_W32CE_SYSTEM - if (osvi.dwPlatformId != VER_PLATFORM_WIN32_CE) - log_fatal ("can only run on a Windows CE platform\n" ); -#else if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) log_fatal ("can only run on a Windows NT platform\n" ); -#endif system_is_w2000 = (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0); init_system_rng (); is_initialized = 1; @@ -831,28 +822,23 @@ memcpy (bufptr, &along, sizeof (along) ); \ bufptr += sizeof (along); \ } while (0) -#ifdef HAVE_W32CE_SYSTEM -# define ADD_NO_CE(f) -#else -# define ADD_NO_CE(f) ADD(f) -#endif ADD ( GetActiveWindow ()); ADD ( GetCapture ()); ADD ( GetClipboardOwner ()); - ADD_NO_CE ( GetClipboardViewer ()); + ADD ( GetClipboardViewer ()); ADD ( GetCurrentProcess ()); ADD ( GetCurrentProcessId ()); ADD ( GetCurrentThread ()); ADD ( GetCurrentThreadId ()); ADD ( GetDesktopWindow ()); ADD ( GetFocus ()); - ADD_NO_CE ( GetInputState ()); + ADD ( GetInputState ()); ADD ( GetMessagePos ()); - ADD_NO_CE ( GetMessageTime ()); + ADD ( GetMessageTime ()); ADD ( GetOpenClipboardWindow ()); ADD ( GetProcessHeap ()); - ADD_NO_CE ( GetProcessWindowStation ()); + ADD ( GetProcessWindowStation ()); ADD ( GetQueueStatus (QS_ALLEVENTS)); ADD ( GetTickCount ()); @@ -898,15 +884,9 @@ (*add) ( &kernelTime, sizeof (kernelTime), origin ); (*add) ( &userTime, sizeof (userTime), origin ); -#ifdef HAVE_W32CE_SYSTEM - handle = GetCurrentThread (); - GetThreadTimes (handle, &creationTime, &exitTime, - &kernelTime, &userTime); -#else handle = GetCurrentProcess (); GetProcessTimes (handle, &creationTime, &exitTime, &kernelTime, &userTime); -#endif (*add) ( &creationTime, sizeof (creationTime), origin ); (*add) ( &exitTime, sizeof (exitTime), origin ); (*add) ( &kernelTime, sizeof (kernelTime), origin ); @@ -914,20 +894,17 @@ /* Get the minimum and maximum working set size for the current process. */ -#ifndef HAVE_W32CE_SYSTEM GetProcessWorkingSetSize (handle, &minimumWorkingSetSize, &maximumWorkingSetSize); (*add) ( &minimumWorkingSetSize, sizeof (minimumWorkingSetSize), origin ); (*add) ( &maximumWorkingSetSize, sizeof (maximumWorkingSetSize), origin ); -#endif /*!HAVE_W32CE_SYSTEM*/ } /* The following are fixed for the lifetime of the process so we only * add them once */ -#ifndef HAVE_W32CE_SYSTEM if (!addedFixedItems) { STARTUPINFO startupInfo; @@ -940,7 +917,6 @@ (*add) ( &startupInfo, sizeof (STARTUPINFO), origin ); addedFixedItems = 1; } -#endif /*!HAVE_W32CE_SYSTEM*/ /* The performance of QPC varies depending on the architecture it's running on and on the OS, the MS documentation is vague about the Added: trunk/random/rndw32ce.c =================================================================== --- trunk/random/rndw32ce.c (rev 0) +++ trunk/random/rndw32ce.c 2010-03-24 15:51:37 UTC (rev 1424) @@ -0,0 +1,193 @@ +/* rndw32ce.c - W32CE entropy gatherer + * Copyright (C) 2010 Free Software Foundation, Inc. + * + * Libgcrypt is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * Libgcrypt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "types.h" +#include "g10lib.h" +#include "rand-internal.h" + + +/* The Microsoft docs say that it is suggested to see the buffer with + some extra random. We do this, despite that it is a questionable + suggestion as the OS as better means of collecting entropy than an + application. */ +static void +fillup_buffer (unsigned char *buffer, size_t length) +{ + size_t used = 0; + + /* This code uses gcc anyway, thus we can use a nested function. */ + void filler (const void *data, size_t datalen, enum random_origins dummy) + { + (void)dummy; + if (used + datalen > length) + datalen = length - used; + memcpy (buffer+used, data, datalen); + used += datalen; + } + + while (used < length) + _gcry_rndw32ce_gather_random_fast (filler, 0); +} + + + +int +_gcry_rndw32ce_gather_random (void (*add)(const void*, size_t, + enum random_origins), + enum random_origins origin, + size_t length, int level ) +{ + HCRYPTPROV prov; + unsigned char buffer [256]; + DWORD buflen; + + if (!level) + return 0; + + /* Note that LENGTH is not really important because the caller + checks the returned lengths and calls this function until it + feels that enough entropy has been gathered. */ + + buflen = sizeof buffer; + if (length+8 < buflen) + buflen = length+8; /* Return a bit more than requested. */ + + if (!CryptAcquireContext (&prov, NULL, NULL, PROV_RSA_FULL, + (CRYPT_VERIFYCONTEXT|CRYPT_SILENT)) ) + log_debug ("CryptAcquireContext failed: rc=%d\n", (int)GetLastError ()); + else + { + fillup_buffer (buffer, buflen); + if (!CryptGenRandom (prov, buflen, buffer)) + log_debug ("CryptGenRandom(%d) failed: rc=%d\n", + (int)buflen, (int)GetLastError ()); + else + (*add) (buffer, buflen, origin); + CryptReleaseContext (prov, 0); + wipememory (buffer, sizeof buffer); + } + + return 0; +} + + + +void +_gcry_rndw32ce_gather_random_fast (void (*add)(const void*, size_t, + enum random_origins), + enum random_origins origin) +{ + + /* Add word sized values. */ + { +# define ADD(t,f) do { \ + t along = (f); \ + memcpy (bufptr, &along, sizeof (along)); \ + bufptr += sizeof (along); \ + } while (0) + unsigned char buffer[20*sizeof(ulong)], *bufptr; + + bufptr = buffer; + ADD (HWND, GetActiveWindow ()); + ADD (HWND, GetCapture ()); + ADD (HWND, GetClipboardOwner ()); + ADD (HANDLE, GetCurrentProcess ()); + ADD (DWORD, GetCurrentProcessId ()); + ADD (HANDLE, GetCurrentThread ()); + ADD (DWORD, GetCurrentThreadId ()); + ADD (HWND, GetDesktopWindow ()); + ADD (HWND, GetFocus ()); + ADD (DWORD, GetMessagePos ()); + ADD (HWND, GetOpenClipboardWindow ()); + ADD (HWND, GetProcessHeap ()); + ADD (DWORD, GetQueueStatus (QS_ALLEVENTS)); + ADD (DWORD, GetTickCount ()); + + gcry_assert ( bufptr-buffer < sizeof (buffer) ); + (*add) ( buffer, bufptr-buffer, origin ); +# undef ADD + } + + /* Get multiword system information: Current caret position, current + mouse cursor position. */ + { + POINT point; + + GetCaretPos (&point); + (*add) ( &point, sizeof (point), origin ); + GetCursorPos (&point); + (*add) ( &point, sizeof (point), origin ); + } + + /* Get percent of memory in use, bytes of physical memory, bytes of + free physical memory, bytes in paging file, free bytes in paging + file, user bytes of address space, and free user bytes. */ + { + MEMORYSTATUS memoryStatus; + + memoryStatus.dwLength = sizeof (MEMORYSTATUS); + GlobalMemoryStatus (&memoryStatus); + (*add) ( &memoryStatus, sizeof (memoryStatus), origin ); + } + + + /* Get thread and process creation time, exit time, time in kernel + mode, and time in user mode in 100ns intervals. */ + { + HANDLE handle; + FILETIME creationTime, exitTime, kernelTime, userTime; + + handle = GetCurrentThread (); + GetThreadTimes (handle, &creationTime, &exitTime, + &kernelTime, &userTime); + (*add) ( &creationTime, sizeof (creationTime), origin ); + (*add) ( &exitTime, sizeof (exitTime), origin ); + (*add) ( &kernelTime, sizeof (kernelTime), origin ); + (*add) ( &userTime, sizeof (userTime), origin ); + + handle = GetCurrentThread (); + GetThreadTimes (handle, &creationTime, &exitTime, + &kernelTime, &userTime); + (*add) ( &creationTime, sizeof (creationTime), origin ); + (*add) ( &exitTime, sizeof (exitTime), origin ); + (*add) ( &kernelTime, sizeof (kernelTime), origin ); + (*add) ( &userTime, sizeof (userTime), origin ); + + } + + + /* In case the OEM provides a high precision timer get this. If + none is available the default implementation returns the + GetTickCount. */ + { + LARGE_INTEGER performanceCount; + + if (QueryPerformanceCounter (&performanceCount)) + (*add) (&performanceCount, sizeof (performanceCount), origin); + } + +} From cvs at cvs.gnupg.org Fri Mar 26 15:06:44 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 26 Mar 2010 15:06:44 +0100 Subject: [svn] gcry - r1425 - in trunk: . cipher doc src tests Message-ID: Author: wk Date: 2010-03-26 15:06:43 +0100 (Fri, 26 Mar 2010) New Revision: 1425 Modified: trunk/NEWS trunk/cipher/ChangeLog trunk/cipher/md.c trunk/cipher/tiger.c trunk/doc/gcrypt.texi trunk/src/cipher.h trunk/src/gcrypt.h.in trunk/tests/ChangeLog trunk/tests/basic.c Log: Add new TIGER variants Modified: trunk/cipher/ChangeLog =================================================================== --- trunk/cipher/ChangeLog 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/cipher/ChangeLog 2010-03-26 14:06:43 UTC (rev 1425) @@ -1,3 +1,13 @@ +2010-03-26 Werner Koch + + * tiger.c (asn): Unfetter the old TIGER from an OID. + (TIGER_CONTEXT): Add field VARIANT. + (tiger_init): Factor code out to ... + (do_init): New. + (tiger1_init, tiger2_init): New. + (_gcry_digest_spec_tiger1, _gcry_digest_spec_tiger2): New. + * md.c (digest_table): Add TIGER1 and TIGER2 variants. + 2009-12-11 Werner Koch * sha256.c (Cho, Maj, Sum0, Sum1): Turn macros into inline @@ -3953,8 +3963,8 @@ (digest_algo_to_string): New. - Copyright 1998,1999,2000,2001,2002,2003,2004,2005,2006 - 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright 1998, 1999, 2000, 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 Modified: trunk/tests/ChangeLog =================================================================== --- trunk/tests/ChangeLog 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/tests/ChangeLog 2010-03-26 14:06:43 UTC (rev 1425) @@ -1,3 +1,8 @@ +2010-03-26 Werner Koch + + * basic.c (check_digests): Add tests for TIGER1 and TIGER2 from + the NESSIE project. + 2010-01-21 Werner Koch * benchmark.c [_GCRYPT_IN_LIBGCRYPT]: Include libcompat.h. Modified: trunk/NEWS =================================================================== --- trunk/NEWS 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/NEWS 2010-03-26 14:06:43 UTC (rev 1425) @@ -1,6 +1,8 @@ Noteworthy changes in version 1.5.x (unreleased) ------------------------------------------------ + * New variants of the TIGER algorithm. + * New cipher algorithm mode for AES-WRAP. * Fixed minor memory leak in DSA key generation. @@ -20,6 +22,8 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GCRY_CIPHER_MODE_AESWRAP NEW. GCRY_PK_ECDH NEW. + GCRY_MD_TIGER1 NEW. + GCRY_MD_TIGER2 NEW. Noteworthy changes in version 1.4.4 (2009-01-22) Modified: trunk/cipher/md.c =================================================================== --- trunk/cipher/md.c 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/cipher/md.c 2010-03-26 14:06:43 UTC (rev 1425) @@ -87,6 +87,10 @@ #if USE_TIGER { &_gcry_digest_spec_tiger, &dummy_extra_spec, GCRY_MD_TIGER }, + { &_gcry_digest_spec_tiger1, + &dummy_extra_spec, GCRY_MD_TIGER1 }, + { &_gcry_digest_spec_tiger2, + &dummy_extra_spec, GCRY_MD_TIGER2 }, #endif #if USE_WHIRLPOOL { &_gcry_digest_spec_whirlpool, Modified: trunk/cipher/tiger.c =================================================================== --- trunk/cipher/tiger.c 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/cipher/tiger.c 2010-03-26 14:06:43 UTC (rev 1425) @@ -1,5 +1,5 @@ /* tiger.c - The TIGER hash function - * Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation, Inc. + * Copyright (C) 1998, 2001, 2002, 2003, 2010 Free Software Foundation, Inc. * * This file is part of Libgcrypt. * @@ -18,6 +18,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +/* See http://www.cs.technion.ac.il/~biham/Reports/Tiger/ */ + #include #include #include @@ -26,16 +28,16 @@ #include "g10lib.h" #include "cipher.h" +/* We really need a 64 bit type for this code. */ #ifdef HAVE_U64_TYPEDEF -/* we really need it here, but as this is only experiment we - * can live without Tiger */ - -typedef struct { - u64 a, b, c; - byte buf[64]; - int count; - u32 nblocks; +typedef struct +{ + u64 a, b, c; + byte buf[64]; + int count; + u32 nblocks; + int variant; /* 0 = old code, 1 = fixed code, 2 - TIGER2. */ } TIGER_CONTEXT; @@ -587,7 +589,7 @@ }; static void -tiger_init( void *context ) +do_init (void *context, int variant) { TIGER_CONTEXT *hd = context; @@ -596,9 +598,28 @@ hd->c = 0xf096a5b4c3b2e187LL; hd->nblocks = 0; hd->count = 0; + hd->variant = variant; } static void +tiger_init (void *context) +{ + do_init (context, 0); +} + +static void +tiger1_init (void *context) +{ + do_init (context, 1); +} + +static void +tiger2_init (void *context) +{ + do_init (context, 2); +} + +static void tiger_round( u64 *ra, u64 *rb, u64 *rc, u64 x, int mul ) { u64 a = *ra; @@ -762,6 +783,7 @@ TIGER_CONTEXT *hd = context; u32 t, msb, lsb; byte *p; + byte pad = hd->variant == 2? 0x80 : 0x01; tiger_write(hd, NULL, 0); /* flush */; @@ -781,13 +803,13 @@ if( hd->count < 56 ) /* enough room */ { - hd->buf[hd->count++] = 0x01; /* pad */ + hd->buf[hd->count++] = pad; while( hd->count < 56 ) hd->buf[hd->count++] = 0; /* pad */ } else /* need one extra block */ { - hd->buf[hd->count++] = 0x01; /* pad character */ + hd->buf[hd->count++] = pad; /* pad character */ while( hd->count < 64 ) hd->buf[hd->count++] = 0; tiger_write(hd, NULL, 0); /* flush */; @@ -814,10 +836,24 @@ *p++ = hd->a >> 24; *p++ = hd->a >> 16; \ *p++ = hd->a >> 8; *p++ = hd->a; } while(0) #endif - X(a); - X(b); - X(c); +#define Y(a) do { *p++ = hd->a ; *p++ = hd->a >> 8; \ + *p++ = hd->a >> 16; *p++ = hd->a >> 24; \ + *p++ = hd->a >> 32; *p++ = hd->a >> 40; \ + *p++ = hd->a >> 48; *p++ = hd->a >> 56; } while(0) + if (hd->variant == 0) + { + X(a); + X(b); + X(c); + } + else + { + Y(a); + Y(b); + Y(c); + } #undef X +#undef Y } static byte * @@ -828,23 +864,48 @@ return hd->buf; } -static byte asn[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */ + + +/* This is the old TIGER variant based on the unfixed reference + implementation. IT was used in GnupG up to 1.3.2. We don't provide + an OID anymore because that would not be correct. */ +gcry_md_spec_t _gcry_digest_spec_tiger = + { + "TIGER192", NULL, 0, NULL, 24, + tiger_init, tiger_write, tiger_final, tiger_read, + sizeof (TIGER_CONTEXT) + }; + + + +/* This is the fixed TIGER implemenation. */ +static byte asn1[19] = /* Object ID is 1.3.6.1.4.1.11591.12.2 */ { 0x30, 0x29, 0x30, 0x0d, 0x06, 0x09, 0x2b, 0x06, 0x01, 0x04, 0x01, 0xda, 0x47, 0x0c, 0x02, 0x05, 0x00, 0x04, 0x18 }; -static gcry_md_oid_spec_t oid_spec_tiger[] = +static gcry_md_oid_spec_t oid_spec_tiger1[] = { /* GNU.digestAlgorithm TIGER */ { "1.3.6.1.4.1.11591.12.2" }, { NULL } }; -gcry_md_spec_t _gcry_digest_spec_tiger = +gcry_md_spec_t _gcry_digest_spec_tiger1 = { - "TIGER192", asn, DIM (asn), oid_spec_tiger, 24, - tiger_init, tiger_write, tiger_final, tiger_read, + "TIGER", asn1, DIM (asn1), oid_spec_tiger1, 24, + tiger1_init, tiger_write, tiger_final, tiger_read, sizeof (TIGER_CONTEXT) }; + + +/* This is TIGER2 which usues a changed padding algorithm. */ +gcry_md_spec_t _gcry_digest_spec_tiger2 = + { + "TIGER2", NULL, 0, NULL, 24, + tiger2_init, tiger_write, tiger_final, tiger_read, + sizeof (TIGER_CONTEXT) + }; + #endif /* HAVE_U64_TYPEDEF */ Modified: trunk/doc/gcrypt.texi =================================================================== --- trunk/doc/gcrypt.texi 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/doc/gcrypt.texi 2010-03-26 14:06:43 UTC (rev 1425) @@ -3427,7 +3427,7 @@ @cindex SHA-224, SHA-256, SHA-384, SHA-512 @cindex RIPE-MD-160 @cindex MD2, MD4, MD5 - at cindex TIGER + at cindex TIGER, TIGER1, TIGER2 @cindex HAVAL @cindex Whirlpool @cindex CRC32 @@ -3464,8 +3464,18 @@ This algorithm has severe weaknesses and should not be used. @item GCRY_MD_TIGER -This is the TIGER/192 algorithm which yields a message digest of 24 bytes. +This is the TIGER/192 algorithm which yields a message digest of 24 +bytes. Actually this is a variant of TIGER with a different output +print order as used by GnuPG up to version 1.3.2. + at item GCRY_MD_TIGER1 +This is the TIGER variant as used by the NESSIE project. It uses the +most commonly used output print order. + + at item GCRY_MD_TIGER2 +This is another variant of TIGER with a different padding scheme. + + @item GCRY_MD_HAVAL This is an reserved value for the HAVAL algorithm with 5 passes and 160 bit. It yields a message digest of 20 bytes. Note that there is no Modified: trunk/src/cipher.h =================================================================== --- trunk/src/cipher.h 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/src/cipher.h 2010-03-26 14:06:43 UTC (rev 1425) @@ -114,6 +114,8 @@ extern gcry_md_spec_t _gcry_digest_spec_sha512; extern gcry_md_spec_t _gcry_digest_spec_sha384; extern gcry_md_spec_t _gcry_digest_spec_tiger; +extern gcry_md_spec_t _gcry_digest_spec_tiger1; +extern gcry_md_spec_t _gcry_digest_spec_tiger2; extern gcry_md_spec_t _gcry_digest_spec_whirlpool; extern md_extra_spec_t _gcry_digest_extraspec_sha1; Modified: trunk/src/gcrypt.h.in =================================================================== --- trunk/src/gcrypt.h.in 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/src/gcrypt.h.in 2010-03-26 14:06:43 UTC (rev 1425) @@ -1061,7 +1061,7 @@ GCRY_MD_SHA1 = 2, GCRY_MD_RMD160 = 3, GCRY_MD_MD2 = 5, - GCRY_MD_TIGER = 6, /* TIGER/192. */ + GCRY_MD_TIGER = 6, /* TIGER/192 as used by gpg <= 1.3.2. */ GCRY_MD_HAVAL = 7, /* HAVAL, 5 pass, 160 bit. */ GCRY_MD_SHA256 = 8, GCRY_MD_SHA384 = 9, @@ -1071,7 +1071,9 @@ GCRY_MD_CRC32 = 302, GCRY_MD_CRC32_RFC1510 = 303, GCRY_MD_CRC24_RFC2440 = 304, - GCRY_MD_WHIRLPOOL = 305 + GCRY_MD_WHIRLPOOL = 305, + GCRY_MD_TIGER1 = 306, /* TIGER fixed. */ + GCRY_MD_TIGER2 = 307 /* TIGER2 variant. */ }; /* Flags used with the open function. */ Modified: trunk/tests/basic.c =================================================================== --- trunk/tests/basic.c 2010-03-24 15:51:37 UTC (rev 1424) +++ trunk/tests/basic.c 2010-03-26 14:06:43 UTC (rev 1425) @@ -1319,6 +1319,7 @@ #endif { GCRY_MD_CRC24_RFC2440, "", "\xb7\x04\xce" }, { GCRY_MD_CRC24_RFC2440, "foo", "\x4f\xc2\x55" }, + { GCRY_MD_TIGER, "", "\x24\xF0\x13\x0C\x63\xAC\x93\x32\x16\x16\x6E\x76" "\xB1\xBB\x92\x5F\xF3\x73\xDE\x2D\x49\x58\x4E\x7A" }, @@ -1355,6 +1356,73 @@ "TUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-", "\x00\xB8\x3E\xB4\xE5\x34\x40\xC5\x76\xAC\x6A\xAE" "\xE0\xA7\x48\x58\x25\xFD\x15\xE7\x0A\x59\xFF\xE4" }, + + { GCRY_MD_TIGER1, "", + "\x32\x93\xAC\x63\x0C\x13\xF0\x24\x5F\x92\xBB\xB1" + "\x76\x6E\x16\x16\x7A\x4E\x58\x49\x2D\xDE\x73\xF3" }, + { GCRY_MD_TIGER1, "a", + "\x77\xBE\xFB\xEF\x2E\x7E\xF8\xAB\x2E\xC8\xF9\x3B" + "\xF5\x87\xA7\xFC\x61\x3E\x24\x7F\x5F\x24\x78\x09" }, + { GCRY_MD_TIGER1, "abc", + "\x2A\xAB\x14\x84\xE8\xC1\x58\xF2\xBF\xB8\xC5\xFF" + "\x41\xB5\x7A\x52\x51\x29\x13\x1C\x95\x7B\x5F\x93" }, + { GCRY_MD_TIGER1, "message digest", + "\xD9\x81\xF8\xCB\x78\x20\x1A\x95\x0D\xCF\x30\x48" + "\x75\x1E\x44\x1C\x51\x7F\xCA\x1A\xA5\x5A\x29\xF6" }, + { GCRY_MD_TIGER1, "abcdefghijklmnopqrstuvwxyz", + "\x17\x14\xA4\x72\xEE\xE5\x7D\x30\x04\x04\x12\xBF" + "\xCC\x55\x03\x2A\x0B\x11\x60\x2F\xF3\x7B\xEE\xE9" }, + { GCRY_MD_TIGER1, + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "\x0F\x7B\xF9\xA1\x9B\x9C\x58\xF2\xB7\x61\x0D\xF7" + "\xE8\x4F\x0A\xC3\xA7\x1C\x63\x1E\x7B\x53\xF7\x8E" }, + { GCRY_MD_TIGER1, + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" "0123456789", + "\x8D\xCE\xA6\x80\xA1\x75\x83\xEE\x50\x2B\xA3\x8A" + "\x3C\x36\x86\x51\x89\x0F\xFB\xCC\xDC\x49\xA8\xCC" }, + { GCRY_MD_TIGER1, + "1234567890" "1234567890" "1234567890" "1234567890" + "1234567890" "1234567890" "1234567890" "1234567890", + "\x1C\x14\x79\x55\x29\xFD\x9F\x20\x7A\x95\x8F\x84" + "\xC5\x2F\x11\xE8\x87\xFA\x0C\xAB\xDF\xD9\x1B\xFD" }, + { GCRY_MD_TIGER1, "!", + "\x6D\xB0\xE2\x72\x9C\xBE\xAD\x93\xD7\x15\xC6\xA7" + "\xD3\x63\x02\xE9\xB3\xCE\xE0\xD2\xBC\x31\x4B\x41" }, + + { GCRY_MD_TIGER2, "", + "\x44\x41\xBE\x75\xF6\x01\x87\x73\xC2\x06\xC2\x27" + "\x45\x37\x4B\x92\x4A\xA8\x31\x3F\xEF\x91\x9F\x41" }, + { GCRY_MD_TIGER2, "a", + "\x67\xE6\xAE\x8E\x9E\x96\x89\x99\xF7\x0A\x23\xE7" + "\x2A\xEA\xA9\x25\x1C\xBC\x7C\x78\xA7\x91\x66\x36" }, + { GCRY_MD_TIGER2, "abc", + "\xF6\x8D\x7B\xC5\xAF\x4B\x43\xA0\x6E\x04\x8D\x78" + "\x29\x56\x0D\x4A\x94\x15\x65\x8B\xB0\xB1\xF3\xBF" }, + { GCRY_MD_TIGER2, "message digest", + "\xE2\x94\x19\xA1\xB5\xFA\x25\x9D\xE8\x00\x5E\x7D" + "\xE7\x50\x78\xEA\x81\xA5\x42\xEF\x25\x52\x46\x2D" }, + { GCRY_MD_TIGER2, "abcdefghijklmnopqrstuvwxyz", + "\xF5\xB6\xB6\xA7\x8C\x40\x5C\x85\x47\xE9\x1C\xD8" + "\x62\x4C\xB8\xBE\x83\xFC\x80\x4A\x47\x44\x88\xFD" }, + { GCRY_MD_TIGER2, + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "\xA6\x73\x7F\x39\x97\xE8\xFB\xB6\x3D\x20\xD2\xDF" + "\x88\xF8\x63\x76\xB5\xFE\x2D\x5C\xE3\x66\x46\xA9" }, + { GCRY_MD_TIGER2, + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" "0123456789", + "\xEA\x9A\xB6\x22\x8C\xEE\x7B\x51\xB7\x75\x44\xFC" + "\xA6\x06\x6C\x8C\xBB\x5B\xBA\xE6\x31\x95\x05\xCD" }, + { GCRY_MD_TIGER2, + "1234567890" "1234567890" "1234567890" "1234567890" + "1234567890" "1234567890" "1234567890" "1234567890", + "\xD8\x52\x78\x11\x53\x29\xEB\xAA\x0E\xEC\x85\xEC" + "\xDC\x53\x96\xFD\xA8\xAA\x3A\x58\x20\x94\x2F\xFF" }, + { GCRY_MD_TIGER2, "!", + "\xE0\x68\x28\x1F\x06\x0F\x55\x16\x28\xCC\x57\x15" + "\xB9\xD0\x22\x67\x96\x91\x4D\x45\xF7\x71\x7C\xF4" }, + { GCRY_MD_WHIRLPOOL, "", "\x19\xFA\x61\xD7\x55\x22\xA4\x66\x9B\x44\xE3\x9C\x1D\x2E\x17\x26" "\xC5\x30\x23\x21\x30\xD4\x07\xF8\x9A\xFE\xE0\x96\x49\x97\xF7\xA7" From cvs at cvs.gnupg.org Fri Mar 26 17:57:10 2010 From: cvs at cvs.gnupg.org (svn author dshaw) Date: Fri, 26 Mar 2010 17:57:10 +0100 Subject: [svn] GnuPG - r5300 - branches/STABLE-BRANCH-1-4/g10 Message-ID: Author: dshaw Date: 2010-03-26 17:57:09 +0100 (Fri, 26 Mar 2010) New Revision: 5300 Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog branches/STABLE-BRANCH-1-4/g10/plaintext.c Log: * plaintext.c (handle_plaintext): Make sure that the stdout flush succeeded, so we can't lose data when using gpg in a pipeline. Fixes bug #1207. Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/g10/ChangeLog 2010-03-24 12:15:30 UTC (rev 5299) +++ branches/STABLE-BRANCH-1-4/g10/ChangeLog 2010-03-26 16:57:09 UTC (rev 5300) @@ -1,3 +1,9 @@ +2010-03-26 David Shaw + + * plaintext.c (handle_plaintext): Make sure that the stdout flush + succeeded, so we can't lose data when using gpg in a pipeline. + Fixes bug #1207. + 2010-02-17 Werner Koch * keygen.c (ask_user_id): Avoid infinite loop in case of invalid @@ -13615,7 +13621,7 @@ Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009 Free Software Foundation, Inc. + 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 Modified: branches/STABLE-BRANCH-1-4/g10/plaintext.c =================================================================== --- branches/STABLE-BRANCH-1-4/g10/plaintext.c 2010-03-24 12:15:30 UTC (rev 5299) +++ branches/STABLE-BRANCH-1-4/g10/plaintext.c 2010-03-26 16:57:09 UTC (rev 5300) @@ -1,6 +1,6 @@ /* plaintext.c - process plaintext packets - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - * 2006 Free Software Foundation, Inc. + * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + * 2007, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -392,7 +392,15 @@ /* Make sure that stdout gets flushed after the plaintext has been handled. This is for extra security as we do a flush anyway before checking the signature. */ - fflush (stdout); + if(fflush(stdout)) + { + /* We check whether this fflush succeeded since fp might have + been stdout piping to a file. The fflush could fail if the + file cannot be written (disk full, etc). See bug 1207 for + more. */ + log_error("Error flushing plaintext: %s\n",strerror(errno)); + rc=G10ERR_WRITE_FILE; + } if( fp && fp != stdout ) fclose(fp); From cvs at cvs.gnupg.org Fri Mar 26 19:11:31 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Fri, 26 Mar 2010 19:11:31 +0100 Subject: [svn] GnuPG - r5301 - branches/STABLE-BRANCH-1-4/g10 Message-ID: Author: wk Date: 2010-03-26 19:11:30 +0100 (Fri, 26 Mar 2010) New Revision: 5301 Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog branches/STABLE-BRANCH-1-4/g10/sign.c Log: Force SHA1 only for v1 cards Modified: branches/STABLE-BRANCH-1-4/g10/ChangeLog =================================================================== --- branches/STABLE-BRANCH-1-4/g10/ChangeLog 2010-03-26 16:57:09 UTC (rev 5300) +++ branches/STABLE-BRANCH-1-4/g10/ChangeLog 2010-03-26 18:11:30 UTC (rev 5301) @@ -4,6 +4,11 @@ succeeded, so we can't lose data when using gpg in a pipeline. Fixes bug #1207. +2010-02-25 Werner Koch + + * sign.c (hash_for): Force SHA1 only for v1 OpenPGP cards. Fixes + bug#1194. + 2010-02-17 Werner Koch * keygen.c (ask_user_id): Avoid infinite loop in case of invalid Modified: branches/STABLE-BRANCH-1-4/g10/sign.c =================================================================== --- branches/STABLE-BRANCH-1-4/g10/sign.c 2010-03-26 16:57:09 UTC (rev 5300) +++ branches/STABLE-BRANCH-1-4/g10/sign.c 2010-03-26 18:11:30 UTC (rev 5301) @@ -1,6 +1,6 @@ /* sign.c - sign data * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - * 2007 Free Software Foundation, Inc. + * 2007, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -414,12 +414,15 @@ return match_dsa_hash(qbytes); } - else if(sk->is_protected && sk->protect.s2k.mode==1002) + else if (sk->is_protected && sk->protect.s2k.mode == 1002 + && sk->protect.ivlen == 16 + && !memcmp (sk->protect.iv, "\xD2\x76\x00\x01\x24\x01\x01", 7)) { - /* The sk lives on a smartcard, and current smartcards only - handle SHA-1 and RIPEMD/160. This is correct now, but may - need revision as the cards add algorithms. */ - + /* The sk lives on a smartcard, and old smartcards only handle + SHA-1 and RIPEMD/160. Newer smartcards (v2.0) don't have + this restriction anymore. Fortunately the serial number + encodes the version of the card and thus we know that this + key is on a v1 card. */ if(opt.personal_digest_prefs) { prefitem_t *prefs; From cvs at cvs.gnupg.org Mon Mar 29 14:57:12 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Mon, 29 Mar 2010 14:57:12 +0200 Subject: [svn] GnuPG - r5302 - in trunk: common g10 sm tools Message-ID: Author: wk Date: 2010-03-29 14:57:11 +0200 (Mon, 29 Mar 2010) New Revision: 5302 Modified: trunk/common/ChangeLog trunk/common/init.c trunk/g10/ChangeLog trunk/g10/main.h trunk/g10/signal.c trunk/sm/gpgsm.c trunk/tools/ChangeLog trunk/tools/Makefile.am trunk/tools/gpg-connect-agent.c trunk/tools/gpgconf-comp.c Log: Minor cleanups Modified: trunk/common/ChangeLog =================================================================== --- trunk/common/ChangeLog 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/common/ChangeLog 2010-03-29 12:57:11 UTC (rev 5302) @@ -1,3 +1,12 @@ +2010-03-29 Werner Koch + + * init.c (sleep_on_exit): Change to 400ms. + +2010-03-25 Werner Koch + + * init.c (sleep_on_exit) [W32CE]: New. + (init_common_subsystems): Call it. + 2010-03-24 Werner Koch * stringhelp.c (change_slashes, compare_filenames): Replace Modified: trunk/g10/ChangeLog =================================================================== --- trunk/g10/ChangeLog 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/g10/ChangeLog 2010-03-29 12:57:11 UTC (rev 5302) @@ -1,3 +1,8 @@ +2010-03-26 Werner Koch + + * signal.c (pause_on_sigusr): Remove. It was used in ancient gpg + version with shared memory IPC. Last caller removed on 2006-04-18. + 2010-03-24 Werner Koch * openfile.c (CMP_FILENAME): Depend on HAVE_DOSISH_SYSTEM instead Modified: trunk/tools/ChangeLog =================================================================== --- trunk/tools/ChangeLog 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/tools/ChangeLog 2010-03-29 12:57:11 UTC (rev 5302) @@ -1,3 +1,12 @@ +2010-03-25 Werner Koch + + * Makefile.am (opt_libassuan_libs) [W32CE]: New. + (gpgconf_LDADD): Use it. + + * gpgconf-comp.c: Include signal.h only if available. Use + gpg_err_set_errno. + (key_matches_user_or_group) [W32CE]: Do not match any user. + 2010-03-15 Werner Koch * gpgconf-comp.c (my_dgettext): Modified: trunk/common/init.c =================================================================== --- trunk/common/init.c 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/common/init.c 2010-03-29 12:57:11 UTC (rev 5302) @@ -36,6 +36,13 @@ #ifdef HAVE_W32CE_SYSTEM #include static void parse_std_file_handles (int *argcp, char ***argvp); +static void +sleep_on_exit (void) +{ + /* The sshd on CE swallows some of the command output. Sleeping a + while usually helps. */ + Sleep (400); +} #endif /*HAVE_W32CE_SYSTEM*/ @@ -77,6 +84,7 @@ /* Special hack for Windows CE: We extract some options from arg to setup the standard handles. */ #ifdef HAVE_W32CE_SYSTEM + atexit (sleep_on_exit); parse_std_file_handles (argcp, argvp); #else (void)argcp; Modified: trunk/g10/main.h =================================================================== --- trunk/g10/main.h 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/g10/main.h 2010-03-29 12:57:11 UTC (rev 5302) @@ -331,7 +331,6 @@ /*-- signal.c --*/ void init_signals(void); -void pause_on_sigusr( int which ); void block_all_signals(void); void unblock_all_signals(void); Modified: trunk/g10/signal.c =================================================================== --- trunk/g10/signal.c 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/g10/signal.c 2010-03-29 12:57:11 UTC (rev 5302) @@ -36,7 +36,6 @@ #ifdef HAVE_DOSISH_SYSTEM void init_signals(void) {} -void pause_on_sigusr(int which) {} #else static volatile int caught_fatal_sig = 0; static volatile int caught_sigusr1 = 0; @@ -133,31 +132,6 @@ } -void -pause_on_sigusr( int which ) -{ -#if defined(HAVE_SIGPROCMASK) && defined(HAVE_SIGSET_T) - sigset_t mask, oldmask; - - assert( which == 1 ); - sigemptyset( &mask ); - sigaddset( &mask, SIGUSR1 ); - - sigprocmask( SIG_BLOCK, &mask, &oldmask ); - while( !caught_sigusr1 ) - sigsuspend( &oldmask ); - caught_sigusr1 = 0; - sigprocmask( SIG_UNBLOCK, &mask, NULL ); -#else - assert (which == 1); - sighold (SIGUSR1); - while (!caught_sigusr1) - sigpause(SIGUSR1); - caught_sigusr1 = 0; - sigrelse(SIGUSR1); -#endif /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */ -} - /* Disabled - see comment in tdbio.c:tdbio_begin_transaction() */ #if 0 static void Modified: trunk/sm/gpgsm.c =================================================================== --- trunk/sm/gpgsm.c 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/sm/gpgsm.c 2010-03-29 12:57:11 UTC (rev 5302) @@ -1969,7 +1969,6 @@ emergency_cleanup (void) { gcry_control (GCRYCTL_TERM_SECMEM ); - gnupg_sleep (2); } Modified: trunk/tools/Makefile.am =================================================================== --- trunk/tools/Makefile.am 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/tools/Makefile.am 2010-03-29 12:57:11 UTC (rev 5302) @@ -56,6 +56,10 @@ common_libs = $(libcommon) ../gl/libgnu.a pwquery_libs = ../common/libsimple-pwquery.a +if HAVE_W32CE_SYSTEM +opt_libassuan_libs = $(LIBASSUAN_LIBS) +endif + gpgsplit_LDADD = $(common_libs) \ $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) \ $(ZLIBS) $(LIBINTL) $(LIBICONV) @@ -64,7 +68,7 @@ # common sucks in gpg-error, will they, nil they (some compilers # do not eliminate the supposed-to-be-unused-inline-functions). -gpgconf_LDADD = $(common_libs) \ +gpgconf_LDADD = $(common_libs) $(opt_libassuan_libs) \ $(LIBINTL) $(GPG_ERROR_LIBS) $(LIBICONV) $(W32SOCKLIBS) gpgparsemail_SOURCES = gpgparsemail.c rfc822parse.c rfc822parse.h Modified: trunk/tools/gpg-connect-agent.c =================================================================== --- trunk/tools/gpg-connect-agent.c 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/tools/gpg-connect-agent.c 2010-03-29 12:57:11 UTC (rev 5302) @@ -1,5 +1,5 @@ /* gpg-connect-agent.c - Tool to connect to the agent. - * Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc. + * Copyright (C) 2005, 2007, 2008, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * Modified: trunk/tools/gpgconf-comp.c =================================================================== --- trunk/tools/gpgconf-comp.c 2010-03-26 18:11:30 UTC (rev 5301) +++ trunk/tools/gpgconf-comp.c 2010-03-29 12:57:11 UTC (rev 5302) @@ -1,5 +1,5 @@ /* gpgconf-comp.c - Configuration utility for GnuPG. - * Copyright (C) 2004, 2007, 2008, 2009 Free Software Foundation, Inc. + * Copyright (C) 2004, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -30,7 +30,9 @@ #include #include #include -#include +#ifdef HAVE_SIGNAL_H +# include +#endif #include #ifdef HAVE_W32_SYSTEM # define WIN32_LEAN_AND_MEAN 1 @@ -1869,7 +1871,7 @@ if (end) *(end++) = '\0'; - errno = 0; + gpg_err_set_errno (0); flags = strtoul (linep, &tail, 0); if (errno) gc_error (1, errno, "malformed flags in option %s from %s", @@ -2185,7 +2187,7 @@ { char *tail; - errno = 0; + gpg_err_set_errno (0); *new_value_nr = strtoul (new_value, &tail, 0); if (errno) @@ -2239,7 +2241,7 @@ } else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_INT32) { - errno = 0; + gpg_err_set_errno (0); (void) strtol (arg, &arg, 0); if (errno) @@ -2252,7 +2254,7 @@ } else if (gc_arg_type[option->arg_type].fallback == GC_ARG_TYPE_INT32) { - errno = 0; + gpg_err_set_errno (0); (void) strtoul (arg, &arg, 0); if (errno) @@ -2289,7 +2291,7 @@ { int saved_err = errno; fclose (src); - errno = saved_err; + gpg_err_set_errno (saved_err); return -1; } @@ -2312,7 +2314,7 @@ fclose (src); fclose (dst); unlink (dst_name); - errno = saved_errno; + gpg_err_set_errno (saved_errno); return -1; } @@ -2360,8 +2362,8 @@ /* Note that get_config_filename() calls percent_deescape(), so we call this before processing the arguments. */ dest_filename = xstrdup (get_config_filename (component, backend)); - src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, getpid ()); - orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename, getpid ()); + src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, (int)getpid ()); + orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename,(int)getpid ()); arg = option->new_value; if (arg && arg[0] == '\0') @@ -2412,7 +2414,7 @@ res = errno; if (!src_file) { - errno = res; + gpg_err_set_errno (res); return -1; } @@ -2599,7 +2601,7 @@ close (fd); if (dest_file) fclose (dest_file); - errno = res; + gpg_err_set_errno (res); return -1; } close (fd); @@ -2621,7 +2623,7 @@ } if (dest_file) fclose (dest_file); - errno = res; + gpg_err_set_errno (res); return -1; } @@ -2652,8 +2654,8 @@ /* FIXME. Throughout the function, do better error reporting. */ dest_filename = xstrdup (get_config_filename (component, backend)); - src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, getpid ()); - orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename, getpid ()); + src_filename = xasprintf ("%s.gpgconf.%i.new", dest_filename, (int)getpid ()); + orig_filename = xasprintf ("%s.gpgconf.%i.bak", dest_filename,(int)getpid ()); #ifdef HAVE_W32_SYSTEM res = copy_file (dest_filename, orig_filename); @@ -2682,7 +2684,7 @@ res = errno; if (!src_file) { - errno = res; + gpg_err_set_errno (res); return -1; } @@ -2897,7 +2899,7 @@ close (fd); if (dest_file) fclose (dest_file); - errno = res; + gpg_err_set_errno (res); return -1; } close (fd); @@ -2919,7 +2921,7 @@ } if (dest_file) fclose (dest_file); - errno = res; + gpg_err_set_errno (res); return -1; } @@ -3017,7 +3019,7 @@ if (end) *(end++) = '\0'; - errno = 0; + gpg_err_set_errno (0); flags = strtoul (linep, &tail, 0); if (errno) gc_error (1, errno, "malformed flags in option %s", line); @@ -3087,7 +3089,7 @@ gc_error (0, 0, _("External verification of component %s failed"), gc_component[component].name); - errno = EINVAL; + gpg_err_set_errno (EINVAL); } } @@ -3236,6 +3238,7 @@ /* Under Windows we don't support groups. */ if (group && *group) gc_error (0, 0, _("Note that group specifications are ignored\n")); +#ifndef HAVE_W32CE_SYSTEM if (*user) { static char *my_name; @@ -3255,6 +3258,7 @@ if (!strcmp (user, my_name)) return 1; /* Found. */ } +#endif /*HAVE_W32CE_SYSTEM*/ #else /*!HAVE_W32_SYSTEM*/ /* First check whether the user matches. */ if (*user) From cvs at cvs.gnupg.org Tue Mar 30 20:54:04 2010 From: cvs at cvs.gnupg.org (svn author wk) Date: Tue, 30 Mar 2010 20:54:04 +0200 Subject: [svn] assuan - r364 - trunk/src Message-ID: Author: wk Date: 2010-03-30 20:54:03 +0200 (Tue, 30 Mar 2010) New Revision: 364 Modified: trunk/src/ChangeLog trunk/src/assuan-error.c trunk/src/gpgcedev.c Log: typo fixes and fix w32ce message formatting Modified: trunk/src/ChangeLog =================================================================== --- trunk/src/ChangeLog 2010-03-22 12:33:12 UTC (rev 363) +++ trunk/src/ChangeLog 2010-03-30 18:54:03 UTC (rev 364) @@ -1,3 +1,7 @@ +2010-03-23 Werner Koch + + * assuan-error.c (_assuan_w32_strerror) [W32CE]: Print only the code. + 2010-03-22 Werner Koch * Makefile.am (mkheader, assuan.h): Build header file. Modified: trunk/src/assuan-error.c =================================================================== --- trunk/src/assuan-error.c 2010-03-22 12:33:12 UTC (rev 363) +++ trunk/src/assuan-error.c 2010-03-30 18:54:03 UTC (rev 364) @@ -53,10 +53,14 @@ { if (ec == -1) ec = (int)GetLastError (); +#ifdef HAVE_W32CE_SYSTEM + snprintf (ctx->w32_strerror, sizeof (ctx->w32_strerror) - 1, + "ec=%d", (int)GetLastError ()); +#else FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, ec, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), ctx->w32_strerror, sizeof (ctx->w32_strerror) - 1, NULL); - +#endif return ctx->w32_strerror; } #endif Modified: trunk/src/gpgcedev.c =================================================================== --- trunk/src/gpgcedev.c 2010-03-22 12:33:12 UTC (rev 363) +++ trunk/src/gpgcedev.c 2010-03-30 18:54:03 UTC (rev 364) @@ -48,7 +48,7 @@ The caller sends this IOCTL to the read or the write handle. The required inbuf parameter is address of a variable holding the rendezvous id of the pipe's other end. There is one possible - problem with eocdde: If a pipe is kept in non-rendezvous state + problem with the code: If a pipe is kept in non-rendezvous state until after the rendezvous ids overflow, it is possible that the wrong end will be used. However this is not a realistic scenario. */ #define GPGCEDEV_IOCTL_MAKE_PIPE \