core: Implement recpstring option parsing for gpgsm.

* src/engine-gpg.c (append_args_from_recipients_string): Detect bad
options.
* src/engine-gpgsm.c (set_recipients_from_string): Implement option
parsing.
--

The only option we actually implement is "--" but the code layout is
now very simlar to engine-gpg and can easily be extended if ever
needed.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-06-04 09:29:09 +02:00
parent e9ca36f876
commit 1024884e07
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 26 additions and 16 deletions

View File

@ -2075,6 +2075,8 @@ append_args_from_recipients_string (engine_gpg_t gpg,
file = 0; file = 0;
flags = orig_flags; flags = orig_flags;
} }
else if (!ignore && n > 2 && !memcmp (string, "--", 2))
err = gpg_error (GPG_ERR_UNKNOWN_OPTION);
else if (n) /* Not empty - use it. */ else if (n) /* Not empty - use it. */
{ {
err = add_arg (gpg, file? (hidden? "-F":"-f") : (hidden? "-R":"-r")); err = add_arg (gpg, file? (hidden? "-F":"-f") : (hidden? "-R":"-r"));

View File

@ -1407,11 +1407,12 @@ set_recipients_from_string (engine_gpgsm_t gpgsm, const char *string)
{ {
gpg_error_t err = 0; gpg_error_t err = 0;
char *line = NULL; char *line = NULL;
int no_pubkey = 0; int ignore = 0;
int any = 0;
const char *s; const char *s;
int n; int n;
for (;;) do
{ {
while (*string == ' ' || *string == '\t') while (*string == ' ' || *string == '\t')
string++; string++;
@ -1426,25 +1427,32 @@ set_recipients_from_string (engine_gpgsm_t gpgsm, const char *string)
while (n && (string[n-1] == ' ' || string[n-1] == '\t')) while (n && (string[n-1] == ' ' || string[n-1] == '\t'))
n--; n--;
gpgrt_free (line); if (!ignore && n == 2 && !memcmp (string, "--", 2))
if (gpgrt_asprintf (&line, "RECIPIENT %.*s", n, string) < 0) ignore = 1;
else if (!ignore && n > 2 && !memcmp (string, "--", 2))
err = gpg_error (GPG_ERR_UNKNOWN_OPTION);
else if (n) /* Not empty - use it. */
{ {
err = gpg_error_from_syserror (); gpgrt_free (line);
break; if (gpgrt_asprintf (&line, "RECIPIENT %.*s", n, string) < 0)
err = gpg_error_from_syserror ();
else
{
err = gpgsm_assuan_simple_command (gpgsm, line, gpgsm->status.fnc,
gpgsm->status.fnc_value);
if (!err)
any = 1;
}
} }
string += n + !!s; string += n + !!s;
err = gpgsm_assuan_simple_command (gpgsm, line, gpgsm->status.fnc,
gpgsm->status.fnc_value);
/* Fixme: Improve error reporting. */
if (gpg_err_code (err) == GPG_ERR_NO_PUBKEY)
no_pubkey++;
else if (err)
break;
} }
while (!err);
if (!err && !any)
err = gpg_error (GPG_ERR_MISSING_KEY);
gpgrt_free (line); gpgrt_free (line);
return err? err : no_pubkey? gpg_error (GPG_ERR_NO_PUBKEY) : 0; return err;
} }