diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2010-02-08 18:08:55 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2010-02-09 10:42:38 +0000 |
commit | 821ecf9125544f3e0db4f07f44868f33b6936084 (patch) | |
tree | 4600572551e45b717bf154dea7e909a12a62162b /libupower-glib/up-client.c | |
parent | b93915a377c9acbd26fb3c1f7bd9b41d76e4b578 (diff) | |
download | upower-821ecf9125544f3e0db4f07f44868f33b6936084.tar.gz |
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
Diffstat (limited to 'libupower-glib/up-client.c')
-rw-r--r-- | libupower-glib/up-client.c | 16 |
1 files changed, 14 insertions, 2 deletions
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"); |