aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-05-07 09:50:38 +0000
committerWerner Koch <[email protected]>2019-05-07 09:50:38 +0000
commit69e0b080f06b66eee96327617c6fbffe8a88d586 (patch)
tree2b7d104e84d71ee8ea01be3dd56e1220fa81c20d
parentagent: Allow the use of "Label:" in a key file. (diff)
downloadgnupg-69e0b080f06b66eee96327617c6fbffe8a88d586.tar.gz
gnupg-69e0b080f06b66eee96327617c6fbffe8a88d586.zip
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 <[email protected]>
-rw-r--r--agent/findkey.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/agent/findkey.c b/agent/findkey.c
index 5699a215e..755a90be1 100644
--- a/agent/findkey.c
+++ b/agent/findkey.c
@@ -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;
}