From: Werner Koch Date: Wed, 7 May 2008 15:41:14 +0000 (+0000) Subject: Support --locate-keys feature of gpg. X-Git-Tag: gpgme-1.1.8~39 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b72c0012830eb8904678e18cc80ceb74a03e152c;p=gpgme.git Support --locate-keys feature of gpg. --- diff --git a/NEWS b/NEWS index 8455091..0fb12fc 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,10 @@ Noteworthy changes in version 1.1.7 (unreleased) ------------------------------------------------ + * Using GPGME_KEYLIST_MODE_LOCAL combined with + GPGME_KEYLIST_MODE_EXTERN is now supported; it uses the + --locate-keys feature of gpg (>= 2.0.10). + * The encoding of gpgme_data_t objects can affect the output encoding of export, sign and encrypt operations now (the same operations that are also affected by the ASCII mode switch). We believe this diff --git a/TODO b/TODO index 2c180e0..bd961a5 100644 --- a/TODO +++ b/TODO @@ -148,6 +148,10 @@ Hey Emacs, this is -*- outline -*- mode! ** Map ASSUAN/GpgSM ERR error values in a better way than is done now. !! ** Some error values should identify the source more correctly (mostly error values derived from status messages). +** In rungpg.c we need to check the version of the engine + This requires a way to get the cached version number from the + engine layer. + * Tests ** Write a fake gpg-agent so that we can supply known passphrases to diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 1f1a8a6..cb59355 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -2180,10 +2180,10 @@ is the default. @item GPGME_KEYLIST_MODE_EXTERN The @code{GPGME_KEYLIST_MODE_EXTERN} symbol specifies that an external -source should be searched for keys in the keylisting -operation. The type of external source is dependant on the crypto -engine used. For example, it can be a remote keyserver or LDAP -certificate server. +source should be searched for keys in the keylisting operation. The +type of external source is dependant on the crypto engine used and +whether it is combined with @code{GPGME_KEYLIST_MODE_LOCAL}. For +example, it can be a remote keyserver or LDAP certificate server. @item GPGME_KEYLIST_MODE_SIGS The @code{GPGME_KEYLIST_MODE_SIGS} symbol specifies that the key @@ -2208,7 +2208,7 @@ At least one of @code{GPGME_KEYLIST_MODE_LOCAL} and @code{GPGME_KEYLIST_MODE_EXTERN} must be specified. For future binary compatibility, you should get the current mode with @code{gpgme_get_keylist_mode} and modify it by setting or clearing the -appropriate bits, and then using that calulcated value in the +appropriate bits, and then using that calculated value in the @code{gpgme_set_keylisting_mode} operation. This will leave all other bits in the mode value intact (in particular those that are not used in the current version of the library). diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 23b5c5d..7c47da8 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,14 @@ +2008-05-07 Werner Koch + + * engine-gpgconf.c (gpgconf_write): Change argv[0] to a + self-explaining string. Needs a proper fix, though. + + * rungpg.c (gpg_keylist, gpg_keylist_ext): Factor common code out + to .. + (gpg_build_keylist_options): .. new. Allow combination of extern + and intern mode. + (gpg_new): DFT_TTYNAME is an array, thus check the first character. + 2008-05-06 Werner Koch * version.c (extract_version_string): New. diff --git a/gpgme/engine-gpgconf.c b/gpgme/engine-gpgconf.c index 456f330..ede2c9c 100644 --- a/gpgme/engine-gpgconf.c +++ b/gpgme/engine-gpgconf.c @@ -628,7 +628,7 @@ gpgconf_write (void *engine, char *arg1, char *arg2, gpgme_data_t conf) /* _gpgme_engine_new guarantees that this is not NULL. */ argv[0] = gpgconf->file_name; - argv[0] = "/home/marcus/g10/install/bin/gpgconf"; + argv[0] = "/nowhere/path-needs-to-be-fixed/gpgconf"; if (_gpgme_io_pipe (rp, 0) < 0) return gpg_error_from_syserror (); diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index af6b239..7bd8aae 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -72,7 +72,7 @@ extern "C" { AM_PATH_GPGME macro) check that this header matches the installed library. Warning: Do not edit the next line. configure will do that for you! */ -#define GPGME_VERSION "1.1.7-svn1307" +#define GPGME_VERSION "1.1.7-svn1311" diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 64a8ee2..f4ca2ad 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -486,7 +486,7 @@ gpg_new (void **engine, const char *file_name, const char *home_dir) rc = gpg_error_from_errno (errno); else { - if (dft_ttyname) + if (*dft_ttyname) { rc = add_arg (gpg, "--ttyname"); if (!rc) @@ -1872,20 +1872,12 @@ gpg_keylist_preprocess (char *line, char **r_line) } -static gpgme_error_t -gpg_keylist (void *engine, const char *pattern, int secret_only, - gpgme_keylist_mode_t mode) +static gpg_error_t +gpg_keylist_build_options (engine_gpg_t gpg, int secret_only, + gpgme_keylist_mode_t mode) { - engine_gpg_t gpg = engine; - gpgme_error_t err; + gpg_error_t err; - if (mode & GPGME_KEYLIST_MODE_EXTERN) - { - if ((mode & GPGME_KEYLIST_MODE_LOCAL) - || secret_only) - return gpg_error (GPG_ERR_NOT_SUPPORTED); - } - err = add_arg (gpg, "--with-colons"); if (!err) err = add_arg (gpg, "--fixed-list-mode"); @@ -1893,7 +1885,8 @@ gpg_keylist (void *engine, const char *pattern, int secret_only, err = add_arg (gpg, "--with-fingerprint"); if (!err) err = add_arg (gpg, "--with-fingerprint"); - if (!err && (mode & GPGME_KEYLIST_MODE_SIGS) + if (!err + && (mode & GPGME_KEYLIST_MODE_SIGS) && (mode & GPGME_KEYLIST_MODE_SIG_NOTATIONS)) { err = add_arg (gpg, "--list-options"); @@ -1902,22 +1895,51 @@ gpg_keylist (void *engine, const char *pattern, int secret_only, } if (!err) { - if (mode & GPGME_KEYLIST_MODE_EXTERN) + if ( (mode & GPGME_KEYLIST_MODE_EXTERN) ) { - err = add_arg (gpg, "--search-keys"); - gpg->colon.preprocess_fnc = gpg_keylist_preprocess; + if (secret_only) + err = gpg_error (GPG_ERR_NOT_SUPPORTED); + else if ( (mode & GPGME_KEYLIST_MODE_LOCAL)) + { + /* The local+extern mode is special. It works only with + gpg >= 2.0.10. FIXME: We should check that we have + such a version to that we can return a proper error + code. The problem is that we don't know the context + here and thus can't accesses the cached version + number for the engine info structure. */ + err = add_arg (gpg, "--locate-keys"); + if ((mode & GPGME_KEYLIST_MODE_SIGS)) + err = add_arg (gpg, "--with-sig-check"); + } + else + { + err = add_arg (gpg, "--search-keys"); + gpg->colon.preprocess_fnc = gpg_keylist_preprocess; + } } else - { - err = add_arg (gpg, secret_only ? "--list-secret-keys" - : ((mode & GPGME_KEYLIST_MODE_SIGS) - ? "--check-sigs" : "--list-keys")); - } + { + err = add_arg (gpg, secret_only ? "--list-secret-keys" + : ((mode & GPGME_KEYLIST_MODE_SIGS) + ? "--check-sigs" : "--list-keys")); + } } - - /* Tell the gpg object about the data. */ if (!err) err = add_arg (gpg, "--"); + + return err; +} + + +static gpgme_error_t +gpg_keylist (void *engine, const char *pattern, int secret_only, + gpgme_keylist_mode_t mode) +{ + engine_gpg_t gpg = engine; + gpgme_error_t err; + + err = gpg_keylist_build_options (gpg, secret_only, mode); + if (!err && pattern && *pattern) err = add_arg (gpg, pattern); @@ -1938,26 +1960,7 @@ gpg_keylist_ext (void *engine, const char *pattern[], int secret_only, if (reserved) return gpg_error (GPG_ERR_INV_VALUE); - err = add_arg (gpg, "--with-colons"); - if (!err) - err = add_arg (gpg, "--fixed-list-mode"); - if (!err) - err = add_arg (gpg, "--with-fingerprint"); - if (!err) - err = add_arg (gpg, "--with-fingerprint"); - if (!err && (mode & GPGME_KEYLIST_MODE_SIGS) - && (mode & GPGME_KEYLIST_MODE_SIG_NOTATIONS)) - { - err = add_arg (gpg, "--list-options"); - if (!err) - err = add_arg (gpg, "show-sig-subpackets=\"20,26\""); - } - if (!err) - err = add_arg (gpg, secret_only ? "--list-secret-keys" - : ((mode & GPGME_KEYLIST_MODE_SIGS) - ? "--check-sigs" : "--list-keys")); - if (!err) - err = add_arg (gpg, "--"); + err = gpg_keylist_build_options (gpg, secret_only, mode); if (pattern) {