[PATCH pinentry] emacs: Forward PINENTRY_USER_DATA

Daiki Ueno ueno at gnu.org
Thu Feb 18 08:21:21 CET 2016


* pinentry/pinentry-emacs.c (set_label): Add missing 'static'.
(pinentry_emacs_init): If PINENTRY_USER_DATA envvar is set, send it to
Emacs upon connection.  This is useful to pass around context
information, such as a file name or buffer, for instance.

Signed-off-by: Daiki Ueno <ueno at gnu.org>
---
 pinentry/pinentry-emacs.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/pinentry/pinentry-emacs.c b/pinentry/pinentry-emacs.c
index 9ced8da..53c779b 100644
--- a/pinentry/pinentry-emacs.c
+++ b/pinentry/pinentry-emacs.c
@@ -438,7 +438,7 @@ read_from_emacs (int s, int timeout, char *buffer, size_t capacity)
   return result;
 }
 
-int
+static int
 set_label (pinentry_t pe, const char *name, const char *value)
 {
   char buffer[16], *escaped;
@@ -675,6 +675,7 @@ pinentry_emacs_init (void)
 {
   char buffer[256];
   gpg_error_t error;
+  const char *envvar;
 
   assert (emacs_socket < 0);
 
@@ -691,5 +692,28 @@ pinentry_emacs_init (void)
       emacs_socket = -1;
       return 0;
     }
+
+  /* If PINENTRY_USER_DATA envvar is set, send it to the server.  */
+  envvar = getenv ("PINENTRY_USER_DATA");
+  if (envvar && *envvar)
+    {
+      char *escaped = escape (envvar);
+
+      if (!escaped
+	  || !send_to_emacs (emacs_socket, "OPTION")
+	  || !send_to_emacs (emacs_socket, " ")
+	  || !send_to_emacs (emacs_socket, "pinentry-user-data=")
+	  || !send_to_emacs (emacs_socket, escaped)
+	  || !send_to_emacs (emacs_socket, "\n"))
+	{
+	  free (escaped);
+	  close (emacs_socket);
+	  emacs_socket = -1;
+	  return 0;
+	}
+
+      free (escaped);
+    }
+
   return 1;
 }
-- 
2.5.0




More information about the Gnupg-devel mailing list