2 years agopython: Wrap utility functions.
Justus Winter [Tue, 14 Feb 2017 15:30:30 +0000 (16:30 +0100)]
python: Wrap utility functions.

* NEWS: Update.
* lang/python/gpg/ (pubkey_algo_string): New function.
(pubkey_algo_name): Add docstring.
(hash_algo_name): Likewise.
(get_protocol_name): Likewise.
(addrspec_from_uid): New function.
* lang/python/gpgme.i (gpgme_pubkey_algo_string): Result must be
(gpgme_addrspec_from_uid): Likewise.

Signed-off-by: Justus Winter <>
2 years agopython: Use the correct function to free buffers.
Justus Winter [Tue, 14 Feb 2017 15:16:05 +0000 (16:16 +0100)]
python: Use the correct function to free buffers.

* lang/python/gpgme.i (char *): Free using 'gpgme_free'.

Signed-off-by: Justus Winter <>
2 years agopython: Add keylist mode parameter.
Justus Winter [Tue, 14 Feb 2017 14:56:41 +0000 (15:56 +0100)]
python: Add keylist mode parameter.

* NEWS: Update.
* lang/python/gpg/ (Context.keylist): Add 'mode' parameter.

Signed-off-by: Justus Winter <>
2 years agopython: Nicer repr for user ids.
Justus Winter [Tue, 14 Feb 2017 14:55:20 +0000 (15:55 +0100)]
python: Nicer repr for user ids.

* lang/python/gpgme.i (_gpgme_user_id): Provide a nicer repr() for
user ids.

Signed-off-by: Justus Winter <>
2 years agopython: Add convenience functions for the home directory.
Justus Winter [Tue, 14 Feb 2017 12:43:01 +0000 (13:43 +0100)]
python: Add convenience functions for the home directory.

* NEWS: Update.
* lang/python/gpg/ (Context.__init__): Add 'home_dir' argument.
(__repr__): Include 'home_dir'.
(Context.home_dir): New property.

Signed-off-by: Justus Winter <>
2 years agoqt: Make sure to remove the tofu.db on clean.
Justus Winter [Tue, 14 Feb 2017 11:45:15 +0000 (12:45 +0100)]
qt: Make sure to remove the tofu.db on clean.

* lang/qt/tests/ (CLEANFILES): Add 'tofu.db'.

Signed-off-by: Justus Winter <>
2 years agopython: Extend SWIG gpgme_{sub,}key with a __repr__ method.
Tobias Mueller [Tue, 20 Dec 2016 17:02:36 +0000 (18:02 +0100)]
python: Extend SWIG gpgme_{sub,}key with a __repr__ method.

* lang/python/gpgme.i: Added a genericrepr macro and use it for
gpgme_key, gpgme_subkey, and gpgme_key_sig.

To look nicer in Python's REPL.

We define a generic __repr__ as a SWIG macro and use that to extend some
defined SWIG objects.

The alternative would have been to write a custom __repr__ function for
each class but that would need to be changed everytime the object's
structure changes. The bindings should be easy to maintain, I guess.
This comes at the expense that the reprs are now relatively long and
contain, for example, both keyid and fingerprint.

Signed-off-by: Tobias Mueller <>
2 years agopython: Remove the -builtin flag for SWIG.
Tobias Mueller [Tue, 20 Dec 2016 17:02:20 +0000 (18:02 +0100)]
python: Remove the -builtin flag for SWIG.

* lang/python/ Call SWIG without the builtin flag.

The SWIG documentation
<> leaves the
impression that -builtin is solely for increasing performance:

    New in SWIG version 2.0.4: The use of Python proxy classes has
    performance implications that may be unacceptable for a high-
    performance library. The new -builtin option instructs SWIG to
    forego the use of proxy classes, and instead create wrapped types as
    new built-in Python types. When this option is used, the following
    section ("Proxy classes") does not apply. Details on the use of the
    -builtin option are in the Built-in Types section.

While not wasting CPU cycles is good, it also prevents Python code being
written in the wrapper itself. That, however, may be useful to make it
easier to extend the wrapper.

Partially reverts: 856bcfe2934237011984fab0bc69800a7c25c34b

Signed-off-by: Tobias Mueller <>
2 years agopython: Call SWIG_NewPointerObj rather than SWIG_Python_NewPointerObj.
Tobias Mueller [Tue, 20 Dec 2016 17:01:27 +0000 (18:01 +0100)]
python: Call SWIG_NewPointerObj rather than SWIG_Python_NewPointerObj.

* lang/python/gpgme.i (pygpgme_wrap_gpgme_data_t): Provide a "self"
variable for SWIG_NewPointerObj and call SWIG_NewPointerObj rather than

SWIG_Python_NewPointerObj seems to be an implementation detail, because
SWIG's documentation does not mention that function at all.  In fact,
SWIG_NewPointerObj is a call to SWIG_Python_NewPointerObj with the first
parameter being either NULL or the "self" variable, depending on whether
SWIG is called with the -builtin flag.  So far, the first parameter was
hard-coded to NULL.  This change also hard-codes it to NULL but makes
it more explicit.  The benefit is that the documented function is being
used and that compilation works regardless of the -builtin flag.

Partially reverts: 856bcfe2934237011984fab0bc69800a7c25c34b

Signed-off-by: Tobias Mueller <>
2 years agopython: Conditionally provide py3 argument to SWIG
Tobias Mueller [Tue, 20 Dec 2016 17:00:36 +0000 (18:00 +0100)]
python: Conditionally provide py3 argument to SWIG

* lang/python/ Only call with -py3 when we run under python3
or higher.

If we ever remove the -builtin flag and leave the the -py3 flag, SWIG
will generate Python code which will be incompatible with Python 2,
because the py3 flag generates python3 code which is incompatible with

So we conditionally generate SWIG bindings with -py3.

Signed-off-by: Tobias Mueller <>
2 years agopython: Use one copy of the source tree per Python version.
Justus Winter [Mon, 13 Feb 2017 15:44:53 +0000 (16:44 +0100)]
python: Use one copy of the source tree per Python version.

* lang/python/ (copystamp): Create one copy per Python
(all-local): Adapt.
(clean-local): Likewise.
(install-exec-local): Likewise.
* lang/python/tests/ Likewise.

Currently, we use one copy of the Python module's source to build for
all Python versions.  This is problematic, because SWIG writes a
wrapper file into the source tree.  Currently, this file works with
both Python 2 and 3, but this is purely by chance.

Improve the situation by creating one copy per Python version so that
SWIG can write version-specific code into each copy.

Signed-off-by: Justus Winter <>
2 years agobuild: Use macOS' compatibility macros to enable all features.
Justus Winter [Mon, 13 Feb 2017 13:58:07 +0000 (14:58 +0100)]
build: Use macOS' compatibility macros to enable all features.

* On macOS, use the compatibility macros to expose every
feature of the libc.  This is the equivalent of _GNU_SOURCE on GNU
Not defining this leads to compilation errors or superfluous warnings
on macOS.

GnuPG-bug-id: 2910
Signed-off-by: Justus Winter <>
2 years agoRevert "Disable fd-passing for Apple."
Justus Winter [Mon, 13 Feb 2017 13:01:32 +0000 (14:01 +0100)]
Revert "Disable fd-passing for Apple."

The actual bug has been located, so this can be reverted.

This reverts commit ef5b4ae37d13142e89a051908dc080cda3d24baa.

2 years agoqt: Add missing #include <functional>
Igor Gnatenko [Sat, 11 Feb 2017 07:36:24 +0000 (08:36 +0100)]
qt: Add missing #include <functional>

* lang/qt/src/qgpgmenewcryptoconfig.cpp,
lang/qt/src/threadedjobmixin.h: Include functional.

With GCC 7.0, functional is not included transitively and we get:
In file included from qgpgmedeletejob.h:39:0,
                 from qgpgmedeletejob.cpp:38:
threadedjobmixin.h:98:33: error: 'function' in namespace 'std'
    does not name a template type
     void setFunction(const std::function<T_result()> &function)

std::{function,bind,placeholders,mem_fn} are defined in functional.

Signed-off-by: Igor Gnatenko <>
GnuPG-Bug-Id: 2955

Commit Message amended by Andre Heinecke

Signed-off-by: Andre Heinecke <>
2 years agoqt: Don't rely on implicit include in t-verify
Andre Heinecke [Tue, 7 Feb 2017 09:01:58 +0000 (10:01 +0100)]
qt: Don't rely on implicit include in t-verify

* lang/qt/tests/t-various.cpp: Include QTemporaryDir

This fixes build with some Qt Versions

2 years agodoc: Document that gpgme_op_genkey() parms parameter is not XML.
Daniel Kahn Gillmor [Thu, 26 Jan 2017 23:36:39 +0000 (18:36 -0500)]
doc: Document that gpgme_op_genkey() parms parameter is not XML.

* doc/gpgme.texi (GnupgKeyParms): document that input format is not
true XML.


Please see discussion at

Signed-off-by: Daniel Kahn Gillmor <>
2 years agocore: Optimize fork/exec for *BSD and Solaris.
Werner Koch [Fri, 3 Feb 2017 12:56:23 +0000 (13:56 +0100)]
core: Optimize fork/exec for *BSD and Solaris.

* (closefrom): Add to ac_check_funcs.
* src/posix-io.c (_gpgme_io_spawn): Use closefrom.

Signed-off-by: Werner Koch <>
2 years agocore: Fix possible deadlock due to get_max_fds.
Werner Koch [Fri, 3 Feb 2017 12:13:22 +0000 (13:13 +0100)]
core: Fix possible deadlock due to get_max_fds.

* src/posix-io.c (get_max_fds): Do not use the Linux optimization.

Signed-off-by: Werner Koch <>
2 years agocore: Minor cleanup of commit 195c735
Werner Koch [Fri, 3 Feb 2017 12:08:39 +0000 (13:08 +0100)]
core: Minor cleanup of commit 195c735

* src/verify.c (parse_tofu_user): For cleanness use gpg_error ...
(_gpgme_verify_status_handler): ... and gpg_err_code.

Signed-off-by: Werner Koch <>
2 years agoqt: Add test for tofu conflict
Andre Heinecke [Thu, 2 Feb 2017 16:16:27 +0000 (17:16 +0100)]
qt: Add test for tofu conflict

* lang/qt/tests/t-tofuinfo.cpp (TofuInfoTest::testTofuConflict): New.

2 years agocore: Handle multiple TOFU_USER lines in verify
Andre Heinecke [Thu, 2 Feb 2017 13:02:31 +0000 (14:02 +0100)]
core: Handle multiple TOFU_USER lines in verify

* src/verify.c (op_data_t): Add conflict_user_seen.
(parse_tofu_user): Return ERR_DUP_VALUE for mutltiple TOFU_USERS.
(_gpgme_verify_status_handler): Handle ERR_DUP_VALUE from
parse_tofu_user to ignore the next TOFU_STATS.

This fixes TOFU Conflict verification with GnuPG-2.1.17 and 2.1.18

GnuPG-Bug-Id: 2914

2 years agocore: Replace all calls to *sprintf by gpgrt_*sprintf.
Werner Koch [Thu, 2 Feb 2017 11:35:59 +0000 (12:35 +0100)]
core: Replace all calls to *sprintf by gpgrt_*sprintf.

* (vasprintf): Remove check.
* src/vasprintf.c: Remove file.
* src/util.h (vasprintf, asprintf): Remove prototypes.  Replace all
calls to vasprintf and asprintf by gpgrt_vasprintf or gpgrt_asprintf.
Also take care to use gpgrt_free on the returned value.
* src/w32-util.c (_gpgme_get_gpgconf_path): Replace a gpgrt_asprintf
by _gpgme_strconcat.
(snprintf): New macro to use gpgrt_snprintf instead of the system's
standard snprintf.

Signed-off-by: Werner Koch <>
2 years agocore: Remove unused check for funopen/fopencookie.
Werner Koch [Thu, 2 Feb 2017 11:28:39 +0000 (12:28 +0100)]
core: Remove unused check for funopen/fopencookie.

* (funopen): Remove check.
* src/funopen.c: Remove file.

Signed-off-by: Werner Koch <>
2 years agocore: Explain in gpgme.h that most stucts are read-only.
Werner Koch [Thu, 2 Feb 2017 09:13:36 +0000 (10:13 +0100)]
core: Explain in gpgme.h that most stucts are read-only.


It is common that developers look up only the header file and do not
read the manual.  These comments should make it clear that most
structures in gpgme.h are read-only and may only be allocated by

Signed-off-by: Werner Koch <>
2 years agocore: Un-deprecate gpgme_data_rewind.
Werner Koch [Thu, 2 Feb 2017 08:50:47 +0000 (09:50 +0100)]
core: Un-deprecate gpgme_data_rewind.

* src/ (gpgme_data_rewind): Un-deprecate.
* src/data-compat.c (gpgme_data_rewind): Move to ...
* src/data.c (gpgme_data_rewind): here.

That function is very convenient because it is required a lot with
memory streams.  It also documents the intention of the caller better
than gpgme_data_seek with its addition parameters and the need to map
system errors.  Thus it does not make sense to make it a first class
citizen again.

Signed-off-by: Werner Koch <>
2 years agocore: Move all deprecated stuff to the end of gpgme.h.
Werner Koch [Thu, 2 Feb 2017 08:46:01 +0000 (09:46 +0100)]
core: Move all deprecated stuff to the end of gpgme.h.

Signed-off-by: Werner Koch <>
2 years agocore: Cleanup gpgme_key_unref frees
Andre Heinecke [Wed, 1 Feb 2017 17:06:54 +0000 (18:06 +0100)]
core: Cleanup gpgme_key_unref frees

* src/key.c (gpgme_key_unref): Nowadays we assume free(NULL) is ok.

2 years agocore: Fix leakage of address for mail only uids
Andre Heinecke [Wed, 1 Feb 2017 17:03:35 +0000 (18:03 +0100)]
core: Fix leakage of address for mail only uids

* src/key.c (gpgme_key_unref): Always free address if set.
(_gpgme_key_append_name): Remove memory optimization for address.

The check if address is not allocated would now be more complicated
then just comparing it to email because email is set to address
also when an email was not parsed from the user id.

2 years agocore: Improve mailbox only uid handling
Andre Heinecke [Wed, 1 Feb 2017 15:16:22 +0000 (16:16 +0100)]
core: Improve mailbox only uid handling

* src/key.c (_gpgme_key_append_name): Set email and remove name
for uid only keys.

If we have a name and no email but the name can be parsed as
an address we now treat the address as email and remove the name.

This fixes downstream users that rely on email to show email
addresses and don't expilicity handle this case.

E.g. A userid was:
uid->name = ""
uid->email = ""
uid->address = ""

It is now:
uid->name = ""
uid->email = ""
uid->address = ""

2 years agoqt: Increase timeout when waiting for signals.
Justus Winter [Tue, 31 Jan 2017 09:47:00 +0000 (10:47 +0100)]
qt: Increase timeout when waiting for signals.

* lang/qt/tests/t-support.h (QSIGNALSPY_TIMEOUT): New macro.
* lang/qt/tests/t-encrypt.cpp: Use the new macro as timeout when
waiting for signals.
* lang/qt/tests/t-keylist.cpp: Likewise.
* lang/qt/tests/t-keylocate.cpp: Likewise.
* lang/qt/tests/t-ownertrust.cpp: Likewise.
* lang/qt/tests/t-wkspublish.cpp: Likewise.
Increase the timeout when waiting for signals from 5 seconds to 60.
This addresses intermittent test failures on slow machines.

Signed-off-by: Justus Winter <>
2 years agocore: Add new context flag "redraw".
Werner Koch [Tue, 31 Jan 2017 08:44:29 +0000 (09:44 +0100)]
core: Add new context flag "redraw".

* src/context.h (struct gpgme_context): New field 'redraw_suggested'.
* src/op-support.c (_gpgme_op_reset): Clear REDRAW_SUGGESTED.
* src/progress.c (_gpgme_progress_status_handler): Set REDRAW_SUGGESTED.
* src/gpgme.c (gpgme_set_ctx_flag, gpgme_get_ctx_flag): Add "redraw".
* tests/run-sign.c (main): Use it.

Signed-off-by: Werner Koch <>
2 years agotests: Reduce iterations / threads
Andre Heinecke [Mon, 30 Jan 2017 13:19:52 +0000 (14:19 +0100)]
tests: Reduce iterations / threads

* tests/gpg/t-gpgconf.c (main): Reduce iterations to 10.
* tests/gpg/t-thread-keylist-verify.c,
tests/gpg/t-thread-keylist.c (THREAD_COUNT): Reduce to 10.

While these tests tested for race conditions a smaller number
of iteration should still show problems if they are run on
multiple systems and regulary. While the 100 Thread count in
the t-thread tests could lead to resource problems.

2 years agopython: Ensure quick-random is used if gpg is gpg2
Andre Heinecke [Thu, 26 Jan 2017 09:44:02 +0000 (10:44 +0100)]
python: Ensure quick-random is used if gpg is gpg2

* lang/python/tests/ (gpg.conf): Configure
agent-program accordingly.

2 years agopython: default op_keylist_start parameters.
Tobias Mueller [Sat, 3 Dec 2016 22:12:37 +0000 (23:12 +0100)]
python: default op_keylist_start parameters.

* lang/python/gpgme.i: Added gpgme_op_keylist_start with defaults
* lang/python/tests/ Added tests for default parameters

To increase the ease of use, op_keylist_start
parameters default to sensible values.
The empty string matches all keys.
We assume that the user wants to retrieve public keys most of the time,
so we default to public keys rather than secret keys.

Signed-off-by: Tobias Mueller <>
2 years agotests: Use --debug-quick-random for tests
Andre Heinecke [Wed, 25 Jan 2017 13:10:18 +0000 (14:10 +0100)]
tests: Use --debug-quick-random for tests

* tests/start-stop-agent: Don't autostart agent on --stop and
running check. Use --debug-quick-random when starting.

This should speed up the tests especially on low entropy systems.
Possibly fixing a hang on pythons op_genkey test in the Launchpad
build enviorment (see launchpad issue 1655298)

2 years agow32: Fix closing file descriptors.
Justus Winter [Mon, 23 Jan 2017 14:08:23 +0000 (15:08 +0100)]
w32: Fix closing file descriptors.

* src/w32-io.c (writer): Only stop once the buffer is drained.
(destroy_writer): Wait for the writers buffer to be drained.  This
aligns '_gpgme_io_close's behavior with close(2) and fclose(3).

GnuPG-bug-id: 2881
Signed-off-by: Justus Winter <>
2 years agotests: Add safeguards against nullptr deref
Andre Heinecke [Tue, 17 Jan 2017 14:20:56 +0000 (15:20 +0100)]
tests: Add safeguards against nullptr deref

* t-gpgconf.c (main): Test some values before dereferencing them.

2 years agoqt: Use QVERIFY instead of Q_ASSERT in conf test
Andre Heinecke [Mon, 16 Jan 2017 13:16:20 +0000 (14:16 +0100)]
qt: Use QVERIFY instead of Q_ASSERT in conf test

* lang/qt/tests/t-config.cpp: Use QVERIFY instead of Q_ASSERT.

2 years agoqt: Add test for CryptoConfig
Andre Heinecke [Wed, 21 Dec 2016 09:32:25 +0000 (10:32 +0100)]
qt: Add test for CryptoConfig

* lang/qt/tests/t-config.cpp: New.
* lang/qt/tests/ Update accordingly.

2 years agotests: Fix distcheck.
Justus Winter [Mon, 16 Jan 2017 12:21:02 +0000 (13:21 +0100)]
tests: Fix distcheck.

* tests/gpg/ (CLEANFILES): Remove gpgconf backups.

Fixes-commit: ea7bb62f5d981615847528b3ce53be9cc4d741a7
Signed-off-by: Justus Winter <>
2 years agoFix changing options with gpgconf.
Justus Winter [Thu, 12 Jan 2017 13:05:15 +0000 (14:05 +0100)]
Fix changing options with gpgconf.

* src/engine-gpgconf.c (gpgconf_write): Connect a pipe to the child's
stderr, and wait for it to be closed as an indication that gpgconf has
exited.  Also improve error handling.

GnuPG-bug-id: 2881
Signed-off-by: Justus Winter <>
2 years agotests: Improve the gpgconf test.
Justus Winter [Thu, 12 Jan 2017 13:01:00 +0000 (14:01 +0100)]
tests: Improve the gpgconf test.

* tests/gpg/t-gpgconf.c: Include support functions.
(fail_if_err): Remove macro.
(init_gpgme): Remove function.
(lookup): New function.
(main): Update some values and verify that the changes are applied.
* tests/gpg/t-support.h (test): New assert-like macro.

GnuPG-bug-id: 2881
Signed-off-by: Justus Winter <>
2 years agotests: Enable gpgconf test.
Justus Winter [Mon, 9 Jan 2017 12:09:39 +0000 (13:09 +0100)]
tests: Enable gpgconf test.

Fixes: 02ba35c1b6a2cbb3361b2f2ad507c53564b2be0b
Signed-off-by: Justus Winter <>
2 years agoqt: Add support for stringValueList in CryptoConf
Andre Heinecke [Thu, 12 Jan 2017 11:57:00 +0000 (12:57 +0100)]
qt: Add support for stringValueList in CryptoConf

* lang/qt/src/ (qgpgme_sources): Add cryptoconfig.cpp
* lang/qt/src/cryptoconfig.cpp: New.
* lang/qt/src/cryptoconfig.h (CryptoConfigEntry::stringValueList):
* lang/qt/src/qgpgmenewcryptoconfig.cpp
(QGpgMENewCryptoConfigEntry::stringValueList): New.
* lang/qt/src/qgpgmenewcryptoconfig.h: Update accordingly.

This is a pardigm change in cryptoconfig.h to avoid ABI breaks
with each new config value we support it now has an implementation
that is directly related to qgpgmenewcryptoconfig, which is now
the only one.

2 years agoqt: Don't use qstrdup in test passphrase cb
Andre Heinecke [Thu, 12 Jan 2017 10:44:11 +0000 (11:44 +0100)]
qt: Don't use qstrdup in test passphrase cb

* lang/qt/tests/t-support.h (TestPassphraseProvider::getPassphrase):
Use gpgrt_asprintf instead of strdup.

To avoid problems on MacOS we want to avoid strdup so that
qgpgme can be built without extensions. But qstrdup allocates
with new and not with malloc, so use gpgrt_asprintf instead.

2 years agoqt: Clean up test dirs on failure
Andre Heinecke [Wed, 11 Jan 2017 15:20:31 +0000 (16:20 +0100)]
qt: Clean up test dirs on failure

* t-encrypt.cpp,
t-wkspublish.cpp: Use QVERIFY instead of Q_ASSERT

2 years agoqt: Add test for uid functions
Andre Heinecke [Wed, 11 Jan 2017 15:18:17 +0000 (16:18 +0100)]
qt: Add test for uid functions

* lang/qt/tests/t-various.cpp: New.
* lang/qt/tests/ Update accordingly.

2 years agocpp: Add revuid and adduid support
Andre Heinecke [Wed, 11 Jan 2017 15:14:45 +0000 (16:14 +0100)]
cpp: Add revuid and adduid support

* lang/cpp/src/context.cpp
(Context::revUid, Context::startRevUid),
(Context::addUid, Context::startAddUid): New.
* lang/cpp/src/context.h: Declare new functions.
* lang/cpp/src/key.cpp (Key::UserID::revoke)
(Key::addUid): Idomatic helpers.
lang/cpp/src/key.h: Declare new functions.
* NEWS: Update accordingly.

2 years agoFix Qgpgme build for macos
Andre Heinecke [Wed, 11 Jan 2017 14:52:44 +0000 (15:52 +0100)]
Fix Qgpgme build for macos

* lang/qt/src/dn.cpp: Include string.h
(parse_dn_part): Use qstrdup.
* lang/qt/tests/t-support.h (getPassphrase): Use qstrdup.

2 years agoFix cmake configuration files for MacOS
Andre Heinecke [Wed, 11 Jan 2017 14:49:00 +0000 (15:49 +0100)]
Fix cmake configuration files for MacOS

* Set HAVE_MACOS_SYSTEM conditional.
* lang/qt/src/,
lang/cpp/src/ Use libsuffix again to
distinguish between macos .dylib

GnuPG-Bug-Id: 2884

2 years agopython: Improve compatibility with Scheme tests.
Justus Winter [Tue, 3 Jan 2017 14:27:49 +0000 (15:27 +0100)]
python: Improve compatibility with Scheme tests.

* lang/python/tests/ Add stub --parallel option.

Signed-off-by: Justus Winter <>
2 years agopython: Add a switch '--quiet' to the test runner.
Justus Winter [Wed, 30 Nov 2016 09:39:25 +0000 (10:39 +0100)]
python: Add a switch '--quiet' to the test runner.

* lang/python/tests/ Add and honor a switch '--quiet'.
This way we can use this script to run Python tests one by one without
the noise, and the script will setup the necessary environment for us.

Signed-off-by: Justus Winter <>
2 years agoqt: Update config sync doc / comment
Andre Heinecke [Mon, 2 Jan 2017 13:03:08 +0000 (14:03 +0100)]
qt: Update config sync doc / comment

* lang/qt/src/cryptoconfig.h (CryptoConfig::sync): Document
that runtime option is always set.
* lang/qt/Src/qgpgmenewcryptoconfig.cpp
(QGpgMENewCryptoConfigComponent::sync): Remove outdated comment
and warn on error.

2 years agocore: Always use runtime for gpgconf changes
Andre Heinecke [Mon, 2 Jan 2017 12:11:10 +0000 (13:11 +0100)]
core: Always use runtime for gpgconf changes

* src/engine-gpgconf.c (gpgconf_write): Add --runtime.
* src/ (gpgme_conf_opt_change): Document this

If a tool uses GPGME for changing configuration values it
needs a way to ensure that these changes take effect. Otherwise
users may change and see config values and do not understand
why they are not working.

2 years agoFix gpg_addkey() to work with GPGME_CREATE_NOPASSWD as well.
Ben Kibbey [Sat, 31 Dec 2016 23:09:49 +0000 (18:09 -0500)]
Fix gpg_addkey() to work with GPGME_CREATE_NOPASSWD as well.

* src/engine-gpg.c (gpg_addkey): Pass --batch to gpg when
GPGME_CREATE_NOPASSWD is set to fix pinentry without loopback mode.

Signed-off-by: Ben Kibbey <>
2 years agoFix GPGME_CREATE_NOPASSWD without pinentry loopback.
Ben Kibbey [Tue, 27 Dec 2016 00:57:22 +0000 (19:57 -0500)]
Fix GPGME_CREATE_NOPASSWD without pinentry loopback.

* src/engine-gpg.c(gpg_createkey): Pass --batch to gpg when

Signed-off-by: Ben Kibbey <>
2 years agoQt: Make sure extended grep is used with '|'.
Raphael Kubo da Costa [Sun, 18 Dec 2016 10:41:33 +0000 (11:41 +0100)]
Qt: Make sure extended grep is used with '|'.

* m4/qt.m4: Use grep -E when using the alternation character.

POSIX specifies '|' is only supposed to work as an alternation special
character when grep is used in extended mode. The code worked fine
with GNU grep because it accepts extended regular expressions by
default, but other POSIX-compliant implementations might fail and take
it literally.

Signed-off-by: Raphael Kubo da Costa <>
2 years agocpp: Ensure that hasSecret is correct after update
Andre Heinecke [Fri, 16 Dec 2016 18:09:13 +0000 (19:09 +0100)]
cpp: Ensure that hasSecret is correct after update

* lang/cpp/src/key.cpp (Key::update): Check for
a secret key first before listing public keys.

This is a performance delay but the update should
only be called in a non gui thread anyway. The information
if we have the secret key for this key is important to provide
after update.

2 years agocpp: Fix addrSpec for keys without email
Andre Heinecke [Thu, 15 Dec 2016 10:31:14 +0000 (11:31 +0100)]
cpp: Fix addrSpec for keys without email

* lang/cpp/src/key.cpp (UserID::addrSpec): Use uid->address instead
of normalizing again.
(&operator<<(std::ostream &, const UserID &): Print it.

This saves a normalization and fixes the case where a user id
is just a mail address without name, in that case gpgme sets
"address" but not email. Because the email is then the name.

2 years agocpp: Fix update of partial key in verifyresult
Andre Heinecke [Thu, 15 Dec 2016 10:24:43 +0000 (11:24 +0100)]
cpp: Fix update of partial key in verifyresult

* lang/cpp/src/verificationresult.cpp
(Signature::key(bool,bool)): Don't update the returned copy
but the actual key of the signature.

The whole point of the update is to change the partial key
from the signature (e.g. only fingerprint and one uid as we
would have from tofu) to a fully keylisted one.

2 years agodoc: Let's suggest GNU guidelines for bit checking.
Werner Koch [Wed, 7 Dec 2016 22:25:50 +0000 (23:25 +0100)]
doc: Let's suggest GNU guidelines for bit checking.


While educating students we can also get them to use useful habits, in
particular to parenthese bit tests.

Signed-off-by: Werner Koch <>
2 years agoClarify what "checking on bit" means
Andre Heinecke [Wed, 7 Dec 2016 20:41:34 +0000 (21:41 +0100)]
Clarify what "checking on bit" means

* doc/gpgme.texi (gpgme_sigsum_t summary): Clarify what "you
can check one bit means"

It was unclear which bit to test for is. And tests
with students have shown that they would "test" for
this one bit by using if(sig.summary == GPGME_SIGSUM_VALID)
which would fail because valid sigs are also SIGSUM_GREEN.

So lets give an example for people not used to checking bits and
clarify through this example which bit is meant to be checked.

2 years agopython: Try to be more helpful when given a string to encrypt().
Tobias Mueller [Fri, 2 Dec 2016 22:37:27 +0000 (23:37 +0100)]
python: Try to be more helpful when given a string to encrypt().

* lang/python/helpers.c (_gpg_obj2gpgme_data_t): Extended error
* lang/python/tests/ Test for "encode" in error message.
The motivation is to help the user when encrypting fails. I claim that
it is not obvious to not being able to encrypt a string directly.  To
nudge the user into encoding it to bytes, the error message is a bit

Signed-off-by: Tobias Mueller <>
2 years agopython: Define a macro for wrapping fragile result objects.
Tobias Mueller [Thu, 1 Dec 2016 20:15:12 +0000 (21:15 +0100)]
python: Define a macro for wrapping fragile result objects.

* lang/python/gpgme.i (wrapresult): New Macro.

This reduces the amount of copy and pasted code at the expense of a
slightly more complicated logic with a macro.

Signed-off-by: Tobias Mueller <>
2 years agopython: Check "buffer" when writing to sys.stdout for python2 compat.
Tobias Mueller [Wed, 30 Nov 2016 22:08:47 +0000 (23:08 +0100)]
python: Check "buffer" when writing to sys.stdout for python2 compat.

* lang/python/tests/ (print_data): Add check for buffer.

When running with something like make -C lang/python check verbose=2 the
test would fail under python2, because the file objects do not have a
buffer property.

Signed-off-by: Tobias Mueller <>
2 years agopython: Make Context have a repr method.
Tobias Mueller [Tue, 29 Nov 2016 22:26:20 +0000 (23:26 +0100)]
python: Make Context have a repr method.

* lang/python/gpg/ (Context.__repr__): New function.

This makes Context objects look nicer in a REPL.

Signed-off-by: Tobias Mueller <>
2 years agopython: Make Results have a nicer __repr__.
Tobias Mueller [Wed, 30 Nov 2016 07:47:29 +0000 (08:47 +0100)]
python: Make Results have a nicer __repr__.

* lang/python/gpg/ (Result.__str__): Renamed to '__repr__'
* lang/python/gpg/ (Result.__repr__): ... and added fields.

So that it looks a bit nicer in the Python REPL.

It looked like this before:

In [2]: gpg.core.get_engine_info()[0]
<gpg.results.EngineInfo at 0x7fb23509a240>

Now the output is

In [2]: gpg.core.get_engine_info()[0]
EngineInfo(file_name='/usr/bin/gpg2', home_dir=None,
protocol=0, req_version='1.4.0', version='2.1.11')

This also applies to other results, e.g. the ImportResult.

Note that the format now changed from "<Class >" to "Class()". The
Python documentation on repr states: "For many object types, including
most builtins, eval(repr(obj)) == obj."

Signed-off-by: Tobias Mueller <>
2 years agopython: Fix removing the TOFU database.
Justus Winter [Fri, 25 Nov 2016 08:55:42 +0000 (09:55 +0100)]
python: Fix removing the TOFU database.

* lang/python/ (CLEANFILES): Move 'tofu.db'...
* lang/python/tests/ (CLEANFILES): ... here.

Fixes-commit: 9b22f82afc5518961e4bea1fc516b79800e379a2
Signed-off-by: Justus Winter <>
2 years agotests: Remove tofu.db.
Justus Winter [Fri, 25 Nov 2016 08:13:01 +0000 (09:13 +0100)]
tests: Remove tofu.db.

* lang/python/ (CLEANFILES): Add 'tofu.db'.
* tests/gpg/ (CLEANFILES): Likewise.

Signed-off-by: Justus Winter <>
2 years agoRemove a forgotten instance of @libsuffix@
Heiko Becker [Wed, 16 Nov 2016 22:09:45 +0000 (23:09 +0100)]
Remove a forgotten instance of @libsuffix@

* lang/cpp/src/ Remove a forgotten
instance of @libsuffix@.

b2c07bd47bd608afa5cc819b60a7b5bb8c9dd96a removed @libsuffix@ from
cmake config files, but missed one instance.

Signed-off-by: Heiko Becker <>
2 years agoPost release updates.
Werner Koch [Wed, 16 Nov 2016 13:03:40 +0000 (14:03 +0100)]
Post release updates.


2 years agoRelease 1.8.0 gpgme-1.8.0
Werner Koch [Wed, 16 Nov 2016 12:29:02 +0000 (13:29 +0100)]
Release 1.8.0

* Set version to 1.8.0.  Set LT version C28/A17/RO.
Set CPP LT version to C9/A3/R0.  Set Qt LT version to C8/A1/R0.

Signed-off-by: Werner Koch <>
2 years agodoc: Replace http: by https: in core source files.
Werner Koch [Wed, 16 Nov 2016 12:27:00 +0000 (13:27 +0100)]
doc: Replace http: by https: in core source files.


Signed-off-by: Werner Koch <>
2 years agocore: Do not leak the override session key to ps(1).
Werner Koch [Wed, 16 Nov 2016 09:12:19 +0000 (10:12 +0100)]
core: Do not leak the override session key to ps(1).

* src/engine-gpg.c (struct engine_gpg): New field
(gpg_release): Free that field.
(gpg_decrypt): With gnupg 2.1.16 use --override-session-key-fd.

* tests/run-decrypt.c (main): Fix setting over the override key.

Note that this works only with gnupg 2.1.16 and later.

Signed-off-by: Werner Koch <>
2 years agodoc,tests: Require use of ctx_flag before use of session_key.
Daniel Kahn Gillmor [Wed, 16 Nov 2016 05:10:22 +0000 (14:10 +0900)]
doc,tests: Require use of ctx_flag before use of session_key.

* doc/gpgme.texi: Document requirements of verifying that it is OK to
use session_key.
* tests/run-decrypt.c: Ensure that we fail if we're unable to access
the session key, so that we do not violate the guidance above.

Signed-off-by: Daniel Kahn Gillmor <>
Changed the description

 -@code{gpgme_set_ctx_flag (ctx, "export-session-key")} returns
 -@code{GPG_ERR_NO_ERROR} or @code{gpgme_get_ctx_flag (ctx,
 -"export-session-key")} returns @code{"1"}.
 +@code{gpgme_set_ctx_flag (ctx, "export-session-key")} returns success
 +or @code{gpgme_get_ctx_flag (ctx, "export-session-key")} returns true
 +(non-empty string).

to get gpgme_get_ctx_flag for boolean values in sync with its own

Note that I don't agree with the above suggestion but it does not
really harm to have it in the man page.

Signed-off-by: Werner Koch <>
2 years agoqt, cpp: Add cmake config files for w32
Andre Heinecke [Tue, 15 Nov 2016 13:33:31 +0000 (14:33 +0100)]
qt, cpp: Add cmake config files for w32

* lang/cpp/src/
lang/qt/src/ New.
* lang/cpp/src/,
lang/qt/src/ Remove libsuffix handling.
* lang/cpp/src/,
lang/qt/src/ Create / install w32 config files.
* Configure them.

To work with DLL's cmake needs to know about the implib and
the final DLL. So the config files look different enough
that it's better to use alternative files.

2 years agoqt: Use new style connect in th..mixin
Andre Heinecke [Tue, 15 Nov 2016 11:30:56 +0000 (12:30 +0100)]
qt: Use new style connect in th..mixin

* lang/qt/src/threadedjobmixin.h
(ThreadedJobMixin::lateInitialization): Use new style connect.

2 years agodoc: Fix typos.
Daniel Kahn Gillmor [Tue, 15 Nov 2016 10:53:35 +0000 (19:53 +0900)]
doc: Fix typos.


2 years agocore: Implement context flag "override-session-key".
Werner Koch [Tue, 15 Nov 2016 09:29:48 +0000 (10:29 +0100)]
core: Implement context flag "override-session-key".

* src/gpgme.c (gpgme_set_ctx_flag): Add flags "export-session-key" and
(gpgme_get_ctx_flag): Ditto.
(gpgme_set_export_session_keys): Remove.
(gpgme_get_export_session_keys): Remove.
* src/gpgme.def, src/libgpgme.vers: Remove them.
* src/context.h (struct gpgme_context): Add field
* src/decrypt-verify.c (decrypt_verify_start): Pass
override_session_key value to the engine.
* src/decrypt.c (decrypt_start): Ditto.
* src/engine.c (_gpgme_engine_op_decrypt): Ditto.
(_gpgme_engine_op_decrypt_verify): Ditto.
* src/engine-backend.h (struct engine_ops): Extend DECRYPT and
DECRYPT_VERIFY_START with override_session_key.
* src/engine-uiserver.c (_uiserver_decrypt): Add stub arg
(uiserver_decrypt): Ditto.
(uiserver_decrypt_verify): Ditto.
* src/engine-gpgsm.c (gpgsm_decrypt): Ditto.
* src/engine-gpg.c (gpg_decrypt): Add arg override_session_key and set
corresponding gpg option.

* tests/run-decrypt.c (print_result): Print the session key if
(main): Add options --export-session-key and --override-session-key.


To keep the number of context manipulation functions at bay, this
patches removes the just added gpgme_set_export_session_keys and
gpgme_get_export_session_keys by flags for the generic context

The patch also implements the --override-session-key feature.

GnuPG-bug-id: 2754
Signed-off-by: Werner Koch <>
2 years agocore: Add public function gpgme_get_ctx_flag.
Werner Koch [Tue, 15 Nov 2016 08:24:17 +0000 (09:24 +0100)]
core: Add public function gpgme_get_ctx_flag.

* src/ (gpgme_get_ctx_flag): New.
* src/gpgme.c (gpgme_set_ctx_flag): Move down the file and add a trace
(gpgme_get_ctx_flag): New.
* src/gpgme.def, src/libgpgme.vers: Add new interface.

Signed-off-by: Werner Koch <>
2 years agocore: Enable extraction of session keys.
Daniel Kahn Gillmor [Fri, 11 Nov 2016 07:49:28 +0000 (16:49 +0900)]
core: Enable extraction of session keys.

* src/gpgme.c (gpgme_set_export_session_keys): New function.
(gpgme_get_export_session_keys): New function.
* src/ (struct _gpgme_op_decrypt_result): Add session_key
(gpgme_{set,get}_export_session_keys): Declare new functions.
* src/libgpgme.vers, src/gpgme.def: Export new functions in shared
* src/engine.h: (_gpgme_engine_op_decrypt) Add export_session_key
(_gpgme_engine_op_decrypt_verify): Add export_session_key parameter.
* src/engine-backend.h: (struct engine_ops): Change function
pointer declarations to match.
* src/context.h (struct gpgme_context): Add export_session_keys member.
* src/decrypt.c (release_op_data): Free result.session_key.
(_gpgme_decrypt_status_handler): Store a copy of the exported session
(decrypt_start): Pass export_session_keys from the context.
* src/decrypt-verify.c (decrypt_verify_start): Pass
export_session_keys from context.
* src/engine.c (_gpgme_engine_op_decrypt): Pass through
export_session_key flag.
(_gpgme_engine_op_decrypt_verify): Pass through export_session_key
* src/engine-gpg.c (gpg_decrypt): If export_session_key is set, add
--export-session-key to argument list.
* src/engine-gpgsm.c (gpgsm_decrypt): Ignore export_session_key for
now, since gpgsm offers no such mechanism.
* src/engine-uiserver.c (_uiserver_decrypt): If export_session_key is
set, add --export-session-key flag to cmd.
* doc/gpgme.texi: Document new functions and session_key member of
* doc/uiserver.texi: Add --export-session-key flag to DECRYPT command.


gpg(1) documents session key export as useful for key escrow, and is
rightly dubious of that use case.  However, session key export is also
useful in other use cases.  Two examples from MUA development (where
this functionality would be specifically useful to me right now):

 * If the MUA stores a local copy of the session key upon decrypting
   the message, it can re-decrypt the message without expensive
   asymmetric operations.  When rendering a thread with dozens of
   encrypted messages, this can represent a significant speedup.

 * A user may have expired encryption-capable secret key material,
   along with many messages encrypted to that material.  If she stores
   the session keys for those messages she wants to keep, she can
   destroy her secret key material and make any messages she has
   deleted completely unrecoverable, even to an attacker who gets her
   remaining secret keys in the future.

This patchset makes a two specific implementation decisions that could
have gone in different ways.  I welcome feedback on preferred outcomes.

 0) session key representation: we currently represent the session key
    as an opaque textual string, rather than trying to provide any
    sort of in-memory structure.  While it wouldn't be hard to parse
    the data produced by gpg's --export-session-key, I chose to use
    the opaque string rather than lock in a particular data format.

 1) API/ABI: i've added a member to gpgme_op_decrypt_result_t.  This
    has the potential to cause an out-of-bound memory access if
    someone uses code compiled against the newer verision, but linked
    at runtime against an older version.  I've attempted to limit that
    risk by documenting that users must verify
    gpgme_get_export_session_keys() before accessing this new struct
    member -- this means that code expecting this capability will
    require the symbol at link-time, and will refuse to link against
    older versions.

    Another approach to solving this problem would be to avoid
    modifying gpgme_op_decrypt_result_t, and to introduce instead a
    new function gpgme_op_session_key(), which could be called in the
    same places as gpgme_op_decrypt_result().  Depending on the
    representation of the session key, this might introduce new
    memory-management burdens on the user of the library, and the
    session key is certainly part of a decryption result, so it seemed
    simpler to go with what i have here.

If anyone has strong preferences that these choices should be solved
in a different way, i'm happy to hear them.

Additionally, I note that i'm also still pretty unclear about how the
"UI Server" fits into this whole ecosystem. In particular, I don't
know whether it's kosher to just add an --export-session-key flag to
the DECRYPT operation without actually having implemented it anywhere,
but i don't see where i would actually implement it either :/

If this patch (or some variant) is adopted, i will supply another
patch that permits offering a session key during decryption (e.g. "gpg
--override-session-key"), but I wanted to get these implementation
choices ironed out first.

Gnupg-Bug-Id: 2754
Signed-off-by: Daniel Kahn Gillmor <>
On the concern of adding a new field to a structure: It may not be
clearly documented but we don't expect that a user ever allocates such
a structure - those result structure may only be created bu gpgme and
are read-only for the user.  Adding a new member constitutes a
compatible ABI change and thus an older SO may not be used by code
compiled with a header for the newer API.  Unless someone tinkers with
the build system, this should never happen.  We have added new fields
to result structure may times and I can't remember any problems.

 - wk

2 years agoqt: Add API to get the context for a Job
Andre Heinecke [Mon, 14 Nov 2016 19:40:29 +0000 (20:40 +0100)]
qt: Add API to get the context for a Job

* lang/qt/src/job.cpp,
lang/qt/src/job.h (Job::context): New.
* lang/qt/src/threadedjobmixin.cpp
(ThreadedJobMixin::~ThreadedJobMixin): New. Unregister context.
(ThreadedJobMixin::lateInitialization): Register context.
* NEWS: Update for cpp and qt.

The global map hack is necessary because the job class does
not know about the context which is held in threadedjobmixin.
Adding a virtual function in Job would be an ABI break which
I'd like to avoid at this point. Although QGpgME's API will
need a big ABI break to make it ABI maintainable. The virtual
jobs -> implementation classes are nearly unmaintainable ABI wise.

The context is exposed to provide more flexibility to users, e.g.
to add a passphrase callback or to set the sender in a context.

2 years agocpp: Add get / set Sender API
Andre Heinecke [Mon, 14 Nov 2016 15:13:27 +0000 (16:13 +0100)]
cpp: Add get / set Sender API

* cpp/src/context.cpp, cpp/src/context.h (Context::setSender),
(Context::getSender): Add simple wrappers.

2 years agoqt, cpp: Enable dll build for windows
Andre Heinecke [Mon, 14 Nov 2016 18:37:34 +0000 (19:37 +0100)]
qt, cpp: Enable dll build for windows

* lang/cpp/src/,
lang/qt/src/ Add -no-undefined to LDFLAGS.

2 years agow32: Fix build of w32-glib
Andre Heinecke [Mon, 14 Nov 2016 16:18:50 +0000 (17:18 +0100)]
w32: Fix build of w32-glib

* src/ (main_sources): Remove system_components_not_extra.
(libgpgme_la_SOURCES): Add system_components_not_extra.
(libgpgme_glib_la_SOURCES): Remove duplicated ath files.

2 years agodoc: Correct deftypefun for gpgme_op_decrypt_verify_start.
Daniel Kahn Gillmor [Fri, 11 Nov 2016 06:16:43 +0000 (15:16 +0900)]
doc: Correct deftypefun for gpgme_op_decrypt_verify_start.

* doc/gpgme.texi: Documentationabout gpgme_op_decrypt_verify_start was
stored under the name gpgme_op_decrypt_verify instead.

Signed-off-by: Daniel Kahn Gillmor <>
2 years agodoc: Correct text about gpgme_cancel_async.
Daniel Kahn Gillmor [Fri, 11 Nov 2016 05:25:19 +0000 (14:25 +0900)]
doc: Correct text about gpgme_cancel_async.

* doc/gpgme.texi: Documentation about gpgme_cancel_async should refer
to the correct name.

Signed-off-by: Daniel Kahn Gillmor <>
2 years agocore: Non-zero values should set _armor, _textmode, and _online.
Daniel Kahn Gillmor [Thu, 10 Nov 2016 23:47:48 +0000 (15:47 -0800)]
core: Non-zero values should set _armor, _textmode, and _online.

* src/gpgme.c (gpgme_set_armor, gpgme_set_textmode,
gpgme_set_offline): Ensure that non-zero values actually set the
appropriate internal bit.


The documentation for these functions says things like "disabled if
YES is zero, and enabled otherwise", where YES is an integer.
However, if you pass an even integer, it will be aliased back to 0
because the context member variables are declared as single bits.

This should make the implementation match the documentation.

Signed-off-by: Daniel Kahn Gillmor <>
2 years agodoc: Fix regression in macro handling
Werner Koch [Fri, 11 Nov 2016 14:10:57 +0000 (15:10 +0100)]
doc: Fix regression in macro handling


The way macros are handled seem to have changed since 2008.  Fix that:

Signed-off-by: Werner Koch <>
2 years agotests,python: Atomic directory creation
Alon Bar-Lev [Wed, 19 Oct 2016 09:04:07 +0000 (12:04 +0300)]
tests,python: Atomic directory creation

* lang/python/tests/  Use MIDIR_P.
* tests/gpg/ Ditto.
* tests/gpgsm/ Ditto.

Solves race in parallel build when mkdir fails if directory exists.

Signed-off-by: Alon Bar-Lev <>
- Tweaked the ChangeLog

Signed-off-by: Werner Koch <>
2 years agocore: Use better error code when using select with a too high fd.
Werner Koch [Thu, 10 Nov 2016 18:49:13 +0000 (19:49 +0100)]
core: Use better error code when using select with a too high fd.

* src/posix-io.c (_gpgme_io_select): Return EMFILE instead of EBADF.

Also EBADF seem more correct, EMFILE (Too man open files) gives
a clearer message to the user that there are somehow too many files
open.  The problem can be exhibited by running lots of threads,

We should eventually move to poll but that would be a large change and
so we better fix it with the planned migration of the I/O subsystem to
libgpgrt (currently known as libgpg-error).

Signed-off-by: Werner Koch <>
2 years agotests: Reduce thread count in new thread tests
Andre Heinecke [Thu, 10 Nov 2016 17:32:26 +0000 (18:32 +0100)]
tests: Reduce thread count in new thread tests

* gpg/t-thread-keylist-verify.c,
gpg/t-thread-keylist.c: Reduce threads to 100

Due to the limit of FD_SETSIZE the
number of parallel threads is limited. So some systems
run into this problem when running the testsuite.

2 years agodoc: s/Multi Threading/Multi-Threading/
Werner Koch [Thu, 10 Nov 2016 16:28:29 +0000 (17:28 +0100)]
doc: s/Multi Threading/Multi-Threading/


2 years agocore: Detect unreadable keyrings.
Werner Koch [Thu, 10 Nov 2016 16:13:02 +0000 (17:13 +0100)]
core: Detect unreadable keyrings.

* src/keylist.c (op_data_t): Add field keydb_search_err.
(keylist_status_handler): Parse STATUS_ERROR into that var.
(gpgme_op_keylist_next): Use that err instead of GPG_ERR_EOF.

With a recent GnuPG version this allows to detect a keyring with wrong
permissions (i.e. no read access).  GPG_ERR_OPEN_KEYRING will be
returned instead of GPG_ERR_EOF.

Signed-off-by: Werner Koch <>
2 years agotests: Fix additional memleaks in thread tests
Andre Heinecke [Thu, 10 Nov 2016 14:04:17 +0000 (15:04 +0100)]
tests: Fix additional memleaks in thread tests

* tests/gpg/t-thread-keylist-verify.c (start_verify): Release
(start_keylist): Unref keys.
* tests/gpg/t-thread-keylist.c (start_keylist): Unref keys.

2 years agotests: Improve new thread tests
Andre Heinecke [Thu, 10 Nov 2016 13:10:11 +0000 (14:10 +0100)]
tests: Improve new thread tests

* tests/gpg/t-thread-keylist-verify.c (start_keylist): Mark
arg as unused. Release context.
(start_verify): Ditto.
(main): Mark args as unused.
* tests/gpg/t-thread-keylist.c (start_keylist):  Mark
arg as unused. Release context.
(main): Mark args as unused.

2 years agocore: Use gpgrt locking for thread safeness
Andre Heinecke [Tue, 8 Nov 2016 14:32:14 +0000 (15:32 +0100)]
core: Use gpgrt locking for thread safeness

* Require libgpg-error 1.17. No longer
check for pthread.
* doc/gpgme.texi: Document removed neccessity for thread
safe gpgme flavours.
* src/sema.h (DEFINE_GLOBAL_LOCK),
(DESTROY_LOCK, LOCK, UNLOCK): Change to gpgrt equivalents.
* src/posix-sema.c, src/w32-sema.c: Removed.
* src/ Remove libpthread and
Update accordingly.
* src/ath.c, src/ath.h (ath_mutex_init)
(ath_mutex_destroy, ath_mutex_lock, ath_mutex_unlock): Removed.
* src/ath.h (ATH_MUTEX_INITIALIZER): Removed.
* src/version.c (do_subsystem_inits): sema_subsystem_init is
no longer required.
* tests/gpg/ Add new threading tests.
(t_thread1_LDADD, t_cancel_LDADD):
Use just gpgme.
* tests/gpg/t-thread-keylist-verify.c,
tests/gpg/t-thread-keylist.c: New.
* src/ Use -lgpgme for thread-model pthread.

Using gpgrt locks instead of pthread locks removes
the neccessity to link pthread directly to gpgme and
have a different, thread safe flavor of gpgme. Now
gpgme is thread-safe if the conditions mentioned
in the doc are met.

As the cpp bindings linked against libgpgme
and not libgpgme-pthread this fixes threading problems
with them.

libgpgme-pthread is removed but gpgme-config still supports
--thread=pthread for compatibility with find scripts.

2 years agopython: Require at least GPGME 1.7 for out-of-tree builds.
Justus Winter [Wed, 9 Nov 2016 12:56:00 +0000 (13:56 +0100)]
python: Require at least GPGME 1.7 for out-of-tree builds.

* lang/python/ Bump required version to 1.7.

Signed-off-by: Justus Winter <>
2 years agow32: Better protect the IO-system's fd_table
Werner Koch [Wed, 9 Nov 2016 07:33:02 +0000 (08:33 +0100)]
w32: Better protect the IO-system's fd_table

* src/w32-io.c (fd_table_lock): New.
(new_fd): Lock allocation of a new slot.
(release_fd): Lock deallocation of a slot.

Note that we lock only the allocation but not the sanitiy checks we do
further down in the code.

Signed-off-by: Werner Koch <>
2 years agocpp: Add API for swdb queries
Andre Heinecke [Fri, 4 Nov 2016 11:33:57 +0000 (12:33 +0100)]
cpp: Add API for swdb queries

* lang/cpp/src/swdbresult.cpp,
 lang/cpp/src/swdbresult.h (SwdbResult): New.
* lang/cpp/src/ Update accordingly.