1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

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.
This commit is contained in:
Werner Koch 2023-01-20 09:00:31 +01:00
parent e28b6c301d
commit 33b6ee5047
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
4 changed files with 39 additions and 11 deletions

View file

@ -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));