[Xfce4-commits] [xfce/xfce4-session] 01/01: Use systemd-logind methods instead of polkit permissions (Bug #14707)

noreply at xfce.org noreply at xfce.org
Thu Apr 25 00:51:29 CEST 2019


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-session.

commit e10ac91be3301c92900168855b265101ba9884e2
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Thu Apr 25 00:50:05 2019 +0200

    Use systemd-logind methods instead of polkit permissions (Bug #14707)
---
 xfce4-session/xfsm-systemd.c | 61 +++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 26 deletions(-)

diff --git a/xfce4-session/xfsm-systemd.c b/xfce4-session/xfsm-systemd.c
index 46a321c..3b59bf1 100644
--- a/xfce4-session/xfsm-systemd.c
+++ b/xfce4-session/xfsm-systemd.c
@@ -38,11 +38,11 @@
 #define SYSTEMD_SUSPEND_ACTION          "Suspend"
 #define SYSTEMD_HIBERNATE_ACTION        "Hibernate"
 #define SYSTEMD_HYBRID_SLEEP_ACTION     "HybridSleep"
-#define SYSTEMD_REBOOT_TEST             "org.freedesktop.login1.reboot"
-#define SYSTEMD_POWEROFF_TEST           "org.freedesktop.login1.power-off"
-#define SYSTEMD_SUSPEND_TEST            "org.freedesktop.login1.suspend"
-#define SYSTEMD_HIBERNATE_TEST          "org.freedesktop.login1.hibernate"
-#define SYSTEMD_HYBRID_SLEEP_TEST       "org.freedesktop.login1.hibernate"
+#define SYSTEMD_REBOOT_TEST             "CanReboot"
+#define SYSTEMD_POWEROFF_TEST           "CanPowerOff"
+#define SYSTEMD_SUSPEND_TEST            "CanSuspend"
+#define SYSTEMD_HIBERNATE_TEST          "CanHibernate"
+#define SYSTEMD_HYBRID_SLEEP_TEST       "CanHybridSleep"
 
 
 
@@ -132,33 +132,42 @@ xfsm_systemd_can_method (XfsmSystemd  *systemd,
                          const gchar  *method,
                          GError      **error)
 {
-#ifdef HAVE_POLKIT
-  PolkitAuthorizationResult *res;
-  GError                    *local_error = NULL;
-#endif
-
+  GDBusConnection *bus;
+  GError *local_error = NULL;
+  GVariant *dbus_ret;
+  const gchar *str;
   *can_method = FALSE;
 
-#ifdef HAVE_POLKIT
-  res = polkit_authority_check_authorization_sync (systemd->authority,
-                                                   systemd->subject,
-                                                   method,
-                                                   NULL,
-                                                   POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
-                                                   NULL,
-                                                   &local_error);
-
-  if (res == NULL)
+  bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
+  if (G_UNLIKELY (bus == NULL))
+    return FALSE;
+
+  dbus_ret = g_dbus_connection_call_sync (bus,
+                                          SYSTEMD_DBUS_NAME,
+                                          SYSTEMD_DBUS_PATH,
+                                          SYSTEMD_DBUS_INTERFACE,
+                                          method,
+                                          NULL,
+                                          NULL,
+                                          G_DBUS_CALL_FLAGS_NONE,
+                                          -1,
+                                          NULL,
+                                          &local_error);
+
+  if (dbus_ret != NULL)
     {
-      g_propagate_error (error, local_error);
-      return FALSE;
+      g_variant_get (dbus_ret, "(&s)", &str);
+      if (!strcmp (str, "yes"))
+        *can_method = TRUE;
     }
 
-  *can_method = polkit_authorization_result_get_is_authorized (res)
-                || polkit_authorization_result_get_is_challenge (res);
+  g_object_unref (G_OBJECT (bus));
 
-  g_object_unref (G_OBJECT (res));
-#endif
+  if (local_error != NULL)
+    {
+      g_propagate_error (error, local_error);
+      return FALSE;
+    }
 
   return TRUE;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list