1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-09 21:28:51 +01:00

wks: Allow reading of --install-key arguments from stdin.

* tools/wks-util.c (install_key_from_spec_file): New.
(wks_cmd_install_key): Call it.
* tools/gpg-wks-client.c (main): Allow --install-key w/o arguments.
* tools/gpg-wks-server.c (main): Ditto.

Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit ba46a359b9)
This commit is contained in:
Werner Koch 2018-12-04 15:27:19 +01:00
parent bf29d7c822
commit b6fd60dfa1
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 81 additions and 10 deletions

View File

@ -95,8 +95,11 @@ local directory (see option @option{-C}) reflecting the structure of a
WKD. The arguments are a file with the keyblock and the user-id to WKD. The arguments are a file with the keyblock and the user-id to
install. If the first argument resembles a fingerprint the key is install. If the first argument resembles a fingerprint the key is
taken from the current keyring; to force the use of a file, prefix the taken from the current keyring; to force the use of a file, prefix the
first argument with "./". The command @option{--remove-key} removes a first argument with "./". If no arguments are given the parameters
key from that directory, its only argument is a user-id. are read from stdin; the expected format are lines with the
fingerprint and the mailbox separated by a space. The command
@option{--remove-key} removes a key from that directory, its only
argument is a user-id.
@command{gpg-wks-client} is not commonly invoked directly and thus it @command{gpg-wks-client} is not commonly invoked directly and thus it
is not installed in the bin directory. Here is an example how it can is not installed in the bin directory. Here is an example how it can
@ -280,7 +283,9 @@ The command @option{--install-key} manually installs a key into the
WKD. The arguments are a file with the keyblock and the user-id to WKD. The arguments are a file with the keyblock and the user-id to
install. If the first argument resembles a fingerprint the key is install. If the first argument resembles a fingerprint the key is
taken from the current keyring; to force the use of a file, prefix the taken from the current keyring; to force the use of a file, prefix the
first argument with "./". first argument with "./". If no arguments are given the parameters
are read from stdin; the expected format are lines with the
fingerprint and the mailbox separated by a space.
The command @option{--remove-key} uninstalls a key from the WKD. The The command @option{--remove-key} uninstalls a key from the WKD. The
process returns success in this case; to also print a diagnostic, use process returns success in this case; to also print a diagnostic, use

View File

@ -363,9 +363,12 @@ main (int argc, char **argv)
break; break;
case aInstallKey: case aInstallKey:
if (argc != 2) if (!argc)
wrong_args ("--install-key FILE|FINGERPRINT USER-ID"); err = wks_cmd_install_key (NULL, NULL);
err = wks_cmd_install_key (*argv, argv[1]); else if (argc == 2)
err = wks_cmd_install_key (*argv, argv[1]);
else
wrong_args ("--install-key [FILE|FINGERPRINT USER-ID]");
break; break;
case aRemoveKey: case aRemoveKey:

View File

@ -381,9 +381,12 @@ main (int argc, char **argv)
break; break;
case aInstallKey: case aInstallKey:
if (argc != 2) if (!argc)
wrong_args ("--install-key FILE USER-ID"); err = wks_cmd_install_key (NULL, NULL);
err = wks_cmd_install_key (*argv, argv[1]); else if (argc == 2)
err = wks_cmd_install_key (*argv, argv[1]);
else
wrong_args ("--install-key [FILE|FINGERPRINT USER-ID]");
break; break;
case aRemoveKey: case aRemoveKey:

View File

@ -855,8 +855,65 @@ wks_compute_hu_fname (char **r_fname, const char *addrspec)
} }
/* Helper form wks_cmd_install_key. */
static gpg_error_t
install_key_from_spec_file (const char *fname)
{
gpg_error_t err;
estream_t fp;
char *line = NULL;
size_t linelen = 0;
char *fields[2];
unsigned int lnr = 0;
if (!fname || !strcmp (fname, ""))
fp = es_stdin;
else
fp = es_fopen (fname, "rb");
if (!fp)
{
err = gpg_error_from_syserror ();
log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
goto leave;
}
while (es_getline (&line, &linelen, fp) >= 0)
{
lnr++;
trim_spaces (line);
log_debug ("got line='%s'\n", line);
if (!*line || *line == '#')
continue;
if (split_fields (line, fields, DIM(fields)) < 2)
{
log_error ("error reading '%s': syntax error at line %u\n",
fname, lnr);
continue;
}
err = wks_cmd_install_key (fields[0], fields[1]);
if (err)
goto leave;
}
if (es_ferror (fp))
{
err = gpg_error_from_syserror ();
log_error ("error reading '%s': %s\n", fname, gpg_strerror (err));
goto leave;
}
leave:
if (fp != es_stdin)
es_fclose (fp);
es_free (line);
return err;
}
/* Install a single key into the WKD by reading FNAME and extracting /* Install a single key into the WKD by reading FNAME and extracting
* USERID. */ * USERID. If USERID is NULL FNAME is expected to be a list of fpr
* mbox lines and for each line the respective key will be
* installed. */
gpg_error_t gpg_error_t
wks_cmd_install_key (const char *fname, const char *userid) wks_cmd_install_key (const char *fname, const char *userid)
{ {
@ -871,6 +928,9 @@ wks_cmd_install_key (const char *fname, const char *userid)
char *huname = NULL; char *huname = NULL;
int any; int any;
if (!userid)
return install_key_from_spec_file (fname);
addrspec = mailbox_from_userid (userid); addrspec = mailbox_from_userid (userid);
if (!addrspec) if (!addrspec)
{ {