mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-08 07:48:05 +02:00
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
This commit is contained in:
parent
b93915a377
commit
821ecf9125
2 changed files with 28 additions and 4 deletions
|
|
@ -232,6 +232,7 @@ static void
|
|||
dkp_client_ensure_properties (DkpClient *client)
|
||||
{
|
||||
gboolean ret;
|
||||
gboolean allowed = FALSE;
|
||||
GError *error;
|
||||
GHashTable *props;
|
||||
GValue *value;
|
||||
|
|
@ -267,7 +268,13 @@ dkp_client_ensure_properties (DkpClient *client)
|
|||
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");
|
||||
|
|
@ -278,7 +285,12 @@ dkp_client_ensure_properties (DkpClient *client)
|
|||
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");
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue