From 821ecf9125544f3e0db4f07f44868f33b6936084 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 8 Feb 2010 18:08:55 +0100 Subject: Check PolicyKit in client's can_{suspend,hibernate} properties Check for PK privileges in UpClient's can_{suspend,hibernate} properties, so that clients like gnome-session or gnome-power-manager hide the related actions if the admin or OEM disabled suspend/hibernate through a PolicyKit .pkla file like $ cat /etc/polkit-1/localauthority/50-local.d/disable-suspend.pkla [Disable suspend] Identity=unix-user:* Action=org.freedesktop.upower.suspend ResultActive=no ResultAny=no https://bugs.freedesktop.org/show_bug.cgi?id=26473 --- libupower-glib/up-client.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libupower-glib/up-client.c') diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c index e0727eb..12201cd 100644 --- a/libupower-glib/up-client.c +++ b/libupower-glib/up-client.c @@ -297,6 +297,7 @@ gboolean up_client_get_properties_sync (UpClient *client, GCancellable *cancellable, GError **error) { gboolean ret = TRUE; + gboolean allowed = FALSE; GHashTable *props; GValue *value; @@ -328,7 +329,13 @@ up_client_get_properties_sync (UpClient *client, GCancellable *cancellable, GErr g_warning ("No 'CanSuspend' property"); goto out; } - ret = g_value_get_boolean (value); + + ret = dbus_g_proxy_call (client->priv->proxy, "SuspendAllowed", error, + G_TYPE_INVALID, G_TYPE_BOOLEAN, &allowed, G_TYPE_INVALID); + if (!ret) + goto out; + + ret = g_value_get_boolean (value) && allowed; if (ret != client->priv->can_suspend) { client->priv->can_suspend = ret; g_object_notify (G_OBJECT(client), "can-suspend"); @@ -339,7 +346,12 @@ up_client_get_properties_sync (UpClient *client, GCancellable *cancellable, GErr g_warning ("No 'CanHibernate' property"); goto out; } - ret = g_value_get_boolean (value); + ret = dbus_g_proxy_call (client->priv->proxy, "HibernateAllowed", error, + G_TYPE_INVALID, G_TYPE_BOOLEAN, &allowed, G_TYPE_INVALID); + if (!ret) + goto out; + + ret = g_value_get_boolean (value) && allowed; if (ret != client->priv->can_hibernate) { client->priv->can_hibernate = ret; g_object_notify (G_OBJECT(client), "can-hibernate"); -- cgit v1.2.1