[PINENTRY PATCH] gnome3: Fall back to curses if screensaver is locked.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sun Nov 6 08:17:04 CET 2016


* gnome3/pinentry-gnome3.c (pe_gnome_screen_locked): New Function.
Returns true only if we can talk to a GNOME screensaver over D-Bus and
it assures us that it is locked.
(main): If GNOME screensaver is locked, fall back to curses.

--

We assume that if pinentry is triggered while the screensaver is
locked, then it is likely being done by some sort of remote connection
(e.g. ssh), and isn't being done directly from the graphical console.
In that case, prompting at the graphical console won't be able to get
the attention of the user, so we should fall back to curses if
possible.

GnuPG-bug-id: 2818
---
 gnome3/pinentry-gnome3.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/gnome3/pinentry-gnome3.c b/gnome3/pinentry-gnome3.c
index ba6ab46..fd345a5 100644
--- a/gnome3/pinentry-gnome3.c
+++ b/gnome3/pinentry-gnome3.c
@@ -390,6 +390,69 @@ pe_gcr_timeout_done (gpointer user_data)
 
 pinentry_cmd_handler_t pinentry_cmd_handler = gnome3_cmd_handler;
 
+/* Test whether there is a GNOME screensaver running that happens to
+ * be locked.  Note that if there is no GNOME screensaver running at
+ * all the answer is still FALSE */
+static gboolean
+pe_gnome_screen_locked (void)
+{
+  GDBusConnection *dbus;
+  GError *error;
+  GVariant *reply, *reply_bool;
+  gboolean ret;
+
+  dbus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+
+  if (!dbus)
+    {
+      fprintf (stderr, "failed to connect to user session D-Bus (%d): %s",
+               error ? error->code : -1,
+               error ? error->message : "<no GError>");
+      if (error)
+        g_error_free (error);
+      return FALSE;
+    }
+
+  /* this is intended to be the equivalent of:
+   * dbus-send --print-reply=literal --session          \
+   *           --dest=org.gnome.ScreenSaver             \
+   *           /org/gnome/ScreenSaver                   \
+   *           org.gnome.ScreenSaver.GetActive
+   */
+  reply = g_dbus_connection_call_sync (dbus,
+                                       "org.gnome.ScreenSaver",
+                                       "/org/gnome/ScreenSaver",
+                                       "org.gnome.ScreenSaver",
+                                       "GetActive",
+                                       NULL,
+                                       ((const GVariantType *) "(b)"),
+                                       G_DBUS_CALL_FLAGS_NO_AUTO_START,
+                                       0,
+                                       NULL,
+                                       &error);
+  g_object_unref(dbus);
+  if (!reply)
+    {
+      fprintf (stderr, "failed to get reply (%d): %s",
+               error ? error->code : -1,
+               error ? error->message : "<no GError>");
+      if (error)
+        g_error_free (error);
+      return FALSE;
+    }
+  reply_bool = g_variant_get_child_value (reply, 0);
+  if (!reply_bool)
+    {
+      fprintf (stderr, "failed to get boolean from reply\n");
+      ret = FALSE;
+    }
+  else
+    ret = g_variant_get_boolean (reply_bool);
+
+  g_variant_unref (reply_bool);
+  g_variant_unref (reply);
+  return ret;
+}
 
 /* Test whether we can create a system prompt or not.  This briefly
  * does create a system prompt, which blocks other tools from making
@@ -443,6 +506,12 @@ main (int argc, char *argv[])
                " falling back to curses\n");
       pinentry_cmd_handler = curses_cmd_handler;
     }
+  else if (pe_gnome_screen_locked ())
+    {
+      fprintf (stderr, "GNOME screensaver is locked,"
+               " falling back to curses\n");
+      pinentry_cmd_handler = curses_cmd_handler;
+    }
 #endif
 
   pinentry_parse_opts (argc, argv);
-- 
2.10.2




More information about the Gnupg-devel mailing list