diff options
author | Werner Koch <wk@gnupg.org> | 2023-01-20 09:00:31 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2023-01-20 09:00:31 +0100 |
commit | 33b6ee5047c8992fe65c494313b6c0f468969188 (patch) | |
tree | 76cc68ce971cd782781c57bb4f9e290d84d9b6c5 /tools | |
parent | doc: Revert last change the gpg --unwrap description (diff) | |
download | gnupg2-33b6ee5047c8992fe65c494313b6c0f468969188.tar.xz gnupg2-33b6ee5047c8992fe65c494313b6c0f468969188.zip |
wkd: Support option --output for command --check.
* tools/wks-util.c (write_to_file): Rename to ...
(wks_write_to_file): this, make global, and support NULL for fname.
* tools/gpg-wks-client.c (command_check): Write to key.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gpg-wks-client.c | 13 | ||||
-rw-r--r-- | tools/gpg-wks.h | 1 | ||||
-rw-r--r-- | tools/wks-util.c | 32 |
3 files changed, 36 insertions, 10 deletions
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c index c603cc043..521222631 100644 --- a/tools/gpg-wks-client.c +++ b/tools/gpg-wks-client.c @@ -1126,6 +1126,19 @@ command_check (char *userid) addrspec); err = gpg_error (GPG_ERR_CERT_REVOKED); } + else if (opt.output) + { + /* Save to file. */ + const char *fname = opt.output; + + if (*fname == '-' && !fname[1]) + fname = NULL; + es_rewind (key); + err = wks_write_to_file (key, fname); + if (err) + log_error ("writing key to '%s' failed: %s\n", + fname? fname : "[stdout]", gpg_strerror (err)); + } leave: xfree (fpr); diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h index a7c17ca52..93039c1e8 100644 --- a/tools/gpg-wks.h +++ b/tools/gpg-wks.h @@ -106,6 +106,7 @@ gpg_error_t wks_send_mime (mime_maker_t mime); gpg_error_t wks_parse_policy (policy_flags_t flags, estream_t stream, int ignore_unknown); void wks_free_policy (policy_flags_t policy); +gpg_error_t wks_write_to_file (estream_t src, const char *fname); gpg_error_t wks_fname_from_userid (const char *userid, int hash_only, char **r_fname, char **r_addrspec); diff --git a/tools/wks-util.c b/tools/wks-util.c index 6caa4ee82..0aeb94b1d 100644 --- a/tools/wks-util.c +++ b/tools/wks-util.c @@ -892,18 +892,27 @@ wks_free_policy (policy_flags_t policy) } -/* Write the content of SRC to the new file FNAME. */ -static gpg_error_t -write_to_file (estream_t src, const char *fname) +/* Write the content of SRC to the new file FNAME. If FNAME is NULL + * SRC is written to stdout. */ +gpg_error_t +wks_write_to_file (estream_t src, const char *fname) { gpg_error_t err; estream_t dst; char buffer[4096]; size_t nread, written; - dst = es_fopen (fname, "wb"); - if (!dst) - return gpg_error_from_syserror (); + if (!fname) + { + dst = es_stdout; + es_set_binary (es_stdout); + } + else + { + dst = es_fopen (fname, "wb"); + if (!dst) + return gpg_error_from_syserror (); + } do { @@ -918,12 +927,15 @@ write_to_file (estream_t src, const char *fname) if (!es_feof (src) || es_ferror (src) || es_ferror (dst)) { err = gpg_error_from_syserror (); - es_fclose (dst); - gnupg_remove (fname); + if (dst != es_stdout) + { + es_fclose (dst); + gnupg_remove (fname); + } return err; } - if (es_fclose (dst)) + if (dst != es_stdout && es_fclose (dst)) { err = gpg_error_from_syserror (); log_error ("error closing '%s': %s\n", fname, gpg_strerror (err)); @@ -1225,7 +1237,7 @@ wks_install_key_core (estream_t key, const char *addrspec) goto leave; /* Publish. */ - err = write_to_file (key, huname); + err = wks_write_to_file (key, huname); if (err) { log_error ("copying key to '%s' failed: %s\n", huname,gpg_strerror (err)); |