[pkg-gnupg-maint] Bug#842015: [PINENTRY PATCH v2] gnome3: Test if Gcr System Prompter is available at startup.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Thu Nov 3 16:31:40 UTC 2016
* gnome3/pinentry-gnome3.c (gcr_system_prompt_available): New. Tests
whether it is possible to create a GcrSystemPrompt.
(main): Use gcr_system_prompt_available() to decide whether to fall
back to curses or not.
Debian-bug-id: 842015
Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
---
gnome3/pinentry-gnome3.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/gnome3/pinentry-gnome3.c b/gnome3/pinentry-gnome3.c
index d6d7d16..37c7a44 100644
--- a/gnome3/pinentry-gnome3.c
+++ b/gnome3/pinentry-gnome3.c
@@ -258,6 +258,39 @@ gnome3_cmd_handler (pinentry_t pe)
pinentry_cmd_handler_t pinentry_cmd_handler = gnome3_cmd_handler;
+
+/* test whether we can create a system prompt or not. This briefly
+ does create a system prompt, which blocks other tools from making
+ the same concurrent request, so we just create it to test if it is
+ available, and quickly close it.
+*/
+int gcr_system_prompt_available ()
+{
+ GcrSystemPrompt *prompt;
+ GError *error = NULL;
+ int ret = 0;
+
+ prompt = gcr_system_prompt_open (0, NULL, &error);
+ if (prompt)
+ {
+ ret = 1;
+ if (!gcr_system_prompt_close (prompt, NULL, &error))
+ fprintf (stderr, "failed to close test Gcr System Prompt (%d): %s\n",
+ error ? error->code : -1, error ? error->message : "<no GError>");
+ g_clear_object (&prompt);
+ }
+ else
+ /* This one particular failure is OK; we're clearly capable of
+ making a system prompt, even though someone else has the
+ system prompter right now: */
+ if (error && error->code == GCR_SYSTEM_PROMPT_IN_PROGRESS)
+ ret = 1;
+
+ if (error)
+ g_error_free (error);
+ return ret;
+}
+
int
main (int argc, char *argv[])
{
@@ -270,6 +303,12 @@ main (int argc, char *argv[])
" falling back to curses\n");
pinentry_cmd_handler = curses_cmd_handler;
}
+ else if (!gcr_system_prompt_available ())
+ {
+ fprintf (stderr, "No Gcr System Prompter available,"
+ " falling back to curses\n");
+ pinentry_cmd_handler = curses_cmd_handler;
+ }
#endif
pinentry_parse_opts (argc, argv);
--
2.10.1
More information about the pkg-gnupg-maint
mailing list