aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2021-06-25 07:55:27 +0000
committerWerner Koch <[email protected]>2021-06-25 08:35:24 +0000
commit5fe4b978875271fb55f1f674ab545bed2b97a7a8 (patch)
treed929bb49f4fa79118f41d003114dca88f3e7acc4
parentscd:ccid: Handle LIBUSB_TRANSFER_OVERFLOW interrupt transfer. (diff)
downloadgnupg-5fe4b978875271fb55f1f674ab545bed2b97a7a8.tar.gz
gnupg-5fe4b978875271fb55f1f674ab545bed2b97a7a8.zip
gpg: Let --fetch-key return an exit code on failure.
* g10/keyserver.c (keyserver_fetch): Return an error code. * g10/gpg.c (main) <aFetchKeys>: Return 1 in case of no data. -- GnuPG-bug-id: 5376
-rw-r--r--g10/gpg.c4
-rw-r--r--g10/keyserver.c20
2 files changed, 20 insertions, 4 deletions
diff --git a/g10/gpg.c b/g10/gpg.c
index dbbe990c7..632a8a558 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -4699,12 +4699,14 @@ main (int argc, char **argv)
for( ; argc; argc--, argv++ )
append_to_strlist2( &sl, *argv, utf8_strings );
rc = keyserver_fetch (ctrl, sl, opt.key_origin);
+ free_strlist (sl);
if(rc)
{
write_status_failure ("fetch-keys", rc);
log_error ("key fetch failed: %s\n",gpg_strerror (rc));
+ if (gpg_err_code (rc) == GPG_ERR_NO_DATA)
+ g10_exit (1); /* In this case return 1 and not 2. */
}
- free_strlist(sl);
break;
case aExportSecret:
diff --git a/g10/keyserver.c b/g10/keyserver.c
index 751022a36..1fbe728ac 100644
--- a/g10/keyserver.c
+++ b/g10/keyserver.c
@@ -1667,6 +1667,8 @@ keyserver_fetch (ctrl_t ctrl, strlist_t urilist, int origin)
strlist_t sl;
estream_t datastream;
unsigned int save_options = opt.keyserver_options.import_options;
+ int any_success = 0;
+ gpg_error_t firsterr = 0;
/* Switch on fast-import, since fetch can handle more than one
import and we don't want each set to rebuild the trustdb.
@@ -1690,13 +1692,25 @@ keyserver_fetch (ctrl_t ctrl, strlist_t urilist, int origin)
import_print_stats (stats_handle);
import_release_stats_handle (stats_handle);
+ any_success = 1;
}
else
- log_info (_("WARNING: unable to fetch URI %s: %s\n"),
- sl->d, gpg_strerror (err));
+ {
+ log_info (_("WARNING: unable to fetch URI %s: %s\n"),
+ sl->d, gpg_strerror (err));
+ if (!firsterr)
+ firsterr = err;
+ }
es_fclose (datastream);
}
+ if (!urilist)
+ err = gpg_error (GPG_ERR_NO_NAME);
+ else if (any_success)
+ err = 0;
+ else
+ err = firsterr;
+
opt.keyserver_options.import_options = save_options;
/* If the original options didn't have fast import, and the trustdb
@@ -1704,7 +1718,7 @@ keyserver_fetch (ctrl_t ctrl, strlist_t urilist, int origin)
if (!(opt.keyserver_options.import_options&IMPORT_FAST))
check_or_update_trustdb (ctrl);
- return 0;
+ return err;
}