1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

agent: If a Label is make sure that label is part of the prompt.

* agent/findkey.c (has_comment_expando): New.
(agent_key_from_file): Modify DESC_TEXT.
--

A Label entry in the keyfile is always set manually and thus we can
assume that the user wants to have this label in the prompt.  In case
the prompt template does not demand a comment this patch appends a
comment to thhe template.  This is a common case for on-disk keys used
by gpg.

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2019-05-07 11:50:38 +02:00
parent 5388537806
commit 69e0b080f0
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -401,6 +401,33 @@ try_unprotect_cb (struct pin_entry_info_s *pi)
}
/* Return true if the STRING has an %C or %c expando. */
static int
has_comment_expando (const char *string)
{
const char *s;
int percent = 0;
if (!string)
return 0;
for (s = string; *s; s++)
{
if (percent)
{
if (*s == 'c' || *s == 'C')
return 1;
percent = 0;
}
else if (*s == '%')
percent = 1;
}
return 0;
}
/* Modify a Key description, replacing certain special format
characters. List of currently supported replacements:
@ -946,6 +973,7 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
size_t len, buflen, erroff;
gcry_sexp_t s_skey;
nvc_t keymeta = NULL;
char *desc_text_buffer = NULL; /* Used in case we extend DESC_TEXT. */
*result = NULL;
if (shadow_info)
@ -968,6 +996,7 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
if (err)
{
nvc_release (keymeta);
xfree (desc_text_buffer);
return err;
}
@ -1006,6 +1035,14 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
if (strchr (comment, '\n')
&& (comment_buffer = linefeed_to_percent0A (comment)))
comment = comment_buffer;
/* In case DESC_TEXT has no escape pattern for a comment
* we append one. */
if (desc_text && !has_comment_expando (desc_text))
{
desc_text_buffer = strconcat (desc_text, "%0A%C", NULL);
if (desc_text_buffer)
desc_text = desc_text_buffer;
}
}
else
{
@ -1078,6 +1115,7 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
*r_passphrase = NULL;
}
nvc_release (keymeta);
xfree (desc_text_buffer);
return err;
}
@ -1095,11 +1133,13 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
*r_passphrase = NULL;
}
nvc_release (keymeta);
xfree (desc_text_buffer);
return err;
}
*result = s_skey;
nvc_release (keymeta);
xfree (desc_text_buffer);
return 0;
}