summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2010-02-08 17:46:11 +0100
committerRichard Hughes <richard@hughsie.com>2010-02-09 10:42:36 +0000
commitb93915a377c9acbd26fb3c1f7bd9b41d76e4b578 (patch)
treedce50d0897ecc5b724985076207d9d744044e25c
parenta057e36751aa7885c9ce9fc43cad4e975498fc60 (diff)
Add {Suspend,Hibernate}Allowed D-Bus methods
Add two D-Bus server methods to check whether the caller has the privilege to suspend or hibernate. This enables us to check for PK privileges in UpClient's can_{suspend,hibernate} properties, so that clients like gnome-session or gnome-power-manager hide the suspend/hibernate related actions if the admin or OEM disabled suspend/hibernate through a PolicyKit .pkla file. https://bugs.freedesktop.org/show_bug.cgi?id=26473
-rw-r--r--src/org.freedesktop.UPower.xml33
-rw-r--r--src/up-daemon.c46
-rw-r--r--src/up-daemon.h4
3 files changed, 83 insertions, 0 deletions
diff --git a/src/org.freedesktop.UPower.xml b/src/org.freedesktop.UPower.xml
index cf32edc..a4066ff 100644
--- a/src/org.freedesktop.UPower.xml
+++ b/src/org.freedesktop.UPower.xml
@@ -195,6 +195,23 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
<!-- ************************************************************ -->
+ <method name="SuspendAllowed">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="allowed" direction="out" type="b">
+ <doc:doc><doc:summary>TRUE if allowed, otherwise FALSE</doc:summary></doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ Check if the caller has (or can get) the PolicyKit privilege to call
+ <doc:ref type="method" to="Power.Suspend">Suspend</doc:ref>.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
+
+ <!-- ************************************************************ -->
+
<method name="Hibernate">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<doc:doc>
@@ -216,6 +233,22 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
</doc:doc>
</method>
+ <!-- ************************************************************ -->
+
+ <method name="HibernateAllowed">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="allowed" direction="out" type="b">
+ <doc:doc><doc:summary>TRUE if allowed, otherwise FALSE</doc:summary></doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ Check if the caller has (or can get) the PolicyKit privilege to call
+ <doc:ref type="method" to="Power.Hibernate">Hibernate</doc:ref>.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
<!-- ************************************************************ -->
diff --git a/src/up-daemon.c b/src/up-daemon.c
index ac6e937..9aeffcf 100644
--- a/src/up-daemon.c
+++ b/src/up-daemon.c
@@ -659,6 +659,29 @@ out:
}
/**
+ * up_daemon_suspend_allowed:
+ **/
+gboolean
+up_daemon_suspend_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
+{
+ gboolean ret;
+ GError *error;
+ PolkitSubject *subject = NULL;
+
+ subject = up_polkit_get_subject (daemon->priv->polkit, context);
+ if (subject == NULL)
+ goto out;
+
+ ret = up_polkit_is_allowed (daemon->priv->polkit, subject, "org.freedesktop.upower.suspend", context);
+ dbus_g_method_return (context, ret);
+
+out:
+ if (subject != NULL)
+ g_object_unref (subject);
+ return TRUE;
+}
+
+/**
* up_daemon_hibernate:
**/
gboolean
@@ -719,6 +742,29 @@ out:
}
/**
+ * up_daemon_hibernate_allowed:
+ **/
+gboolean
+up_daemon_hibernate_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
+{
+ gboolean ret;
+ GError *error;
+ PolkitSubject *subject = NULL;
+
+ subject = up_polkit_get_subject (daemon->priv->polkit, context);
+ if (subject == NULL)
+ goto out;
+
+ ret = up_polkit_is_allowed (daemon->priv->polkit, subject, "org.freedesktop.upower.hibernate", context);
+ dbus_g_method_return (context, ret);
+
+out:
+ if (subject != NULL)
+ g_object_unref (subject);
+ return TRUE;
+}
+
+/**
* up_daemon_register_power_daemon:
**/
static gboolean
diff --git a/src/up-daemon.h b/src/up-daemon.h
index c919a91..d2bcf91 100644
--- a/src/up-daemon.h
+++ b/src/up-daemon.h
@@ -85,8 +85,12 @@ gboolean up_daemon_suspend (UpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean up_daemon_about_to_sleep (UpDaemon *daemon,
DBusGMethodInvocation *context);
+gboolean up_daemon_suspend_allowed (UpDaemon *daemon,
+ DBusGMethodInvocation *context);
gboolean up_daemon_hibernate (UpDaemon *daemon,
DBusGMethodInvocation *context);
+gboolean up_daemon_hibernate_allowed (UpDaemon *daemon,
+ DBusGMethodInvocation *context);
gboolean up_daemon_can_suspend (UpDaemon *daemon,
gboolean interactive,
DBusGMethodInvocation *context);