summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <matthias.clasen@gmail.com>2010-08-19 13:04:38 +0200
committerMartin Pitt <martin.pitt@ubuntu.com>2010-08-19 13:04:38 +0200
commit3967e062ef5a58c4f3f283f34d591c6e8a5d8788 (patch)
tree99ba577a7f76857c5871267077c0da86d7c6e556
parentd815c491eb105c49a7dbcb29c355ca9aaa8d92c4 (diff)
Fix double D-BUS return in up_daemon_*_allowed
Do not send a D-BUS return message any more in up_polkit_is_allowed(), since this makes it hard for callers to ensure that they return exactly one result to the D-BUS caller. Instead, just pass a GError to the caller. Update up_daemon_suspend_allowed() and up_daemon_hibernate_allowed() accordingly, to always return either a result or an error. Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
-rw-r--r--src/up-daemon.c24
-rw-r--r--src/up-polkit.c7
-rw-r--r--src/up-polkit.h2
3 files changed, 23 insertions, 10 deletions
diff --git a/src/up-daemon.c b/src/up-daemon.c
index 40bab80..532ebe8 100644
--- a/src/up-daemon.c
+++ b/src/up-daemon.c
@@ -511,13 +511,21 @@ up_daemon_suspend_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
gboolean ret;
PolkitSubject *subject = NULL;
UpDaemonPrivate *priv = daemon->priv;
+ GError *error;
subject = up_polkit_get_subject (priv->polkit, context);
if (subject == NULL)
goto out;
- ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", context);
- dbus_g_method_return (context, ret);
+ error = NULL;
+ ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.suspend", &error);
+ if (error) {
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ }
+ else {
+ dbus_g_method_return (context, ret);
+ }
out:
if (subject != NULL)
@@ -627,13 +635,21 @@ up_daemon_hibernate_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
gboolean ret;
PolkitSubject *subject = NULL;
UpDaemonPrivate *priv = daemon->priv;
+ GError *error;
subject = up_polkit_get_subject (priv->polkit, context);
if (subject == NULL)
goto out;
- ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", context);
- dbus_g_method_return (context, ret);
+ error = NULL;
+ ret = up_polkit_is_allowed (priv->polkit, subject, "org.freedesktop.upower.hibernate", &error);
+ if (error) {
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ }
+ else {
+ dbus_g_method_return (context, ret);
+ }
out:
if (subject != NULL)
diff --git a/src/up-polkit.c b/src/up-polkit.c
index 9b86394..ab2c66d 100644
--- a/src/up-polkit.c
+++ b/src/up-polkit.c
@@ -103,10 +103,9 @@ out:
* up_polkit_is_allowed:
**/
gboolean
-up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, DBusGMethodInvocation *context)
+up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, GError **error)
{
gboolean ret = FALSE;
- GError *error;
GError *error_local = NULL;
PolkitAuthorizationResult *result;
@@ -116,10 +115,8 @@ up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *act
POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE,
NULL, &error_local);
if (result == NULL) {
- error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message);
- dbus_g_method_return_error (context, error);
+ g_set_error (error, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message);
g_error_free (error_local);
- g_error_free (error);
goto out;
}
diff --git a/src/up-polkit.h b/src/up-polkit.h
index acee70e..1ddac58 100644
--- a/src/up-polkit.h
+++ b/src/up-polkit.h
@@ -60,7 +60,7 @@ gboolean up_polkit_check_auth (UpPolkit *polkit,
gboolean up_polkit_is_allowed (UpPolkit *polkit,
PolkitSubject *subject,
const gchar *action_id,
- DBusGMethodInvocation *context);
+ GError **error);
gboolean up_polkit_get_uid (UpPolkit *polkit,
PolkitSubject *subject,
uid_t *uid);