From e030984b63e4240ca4785bfa86285da1cca5e71a Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 8 Feb 2010 17:44:05 +0100 Subject: [PATCH 1/3] Add up_polkit_is_allowed() function Add a new polkit helper function up_polkit_is_allowed() which checks whether the caller has or can get a particular privilege, but without interactive authentication. https://bugs.freedesktop.org/show_bug.cgi?id=26473 --- src/up-polkit.c | 29 +++++++++++++++++++++++++++++ src/up-polkit.h | 4 ++++ 2 files changed, 33 insertions(+), 0 deletions(-) diff --git a/src/up-polkit.c b/src/up-polkit.c index 6078ff0..8d89dfe 100644 --- a/src/up-polkit.c +++ b/src/up-polkit.c @@ -97,6 +97,35 @@ out: } /** + * up_polkit_is_allowed: + **/ +gboolean +up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, DBusGMethodInvocation *context) +{ + gboolean ret = FALSE; + GError *error; + GError *error_local; + PolkitAuthorizationResult *result; + + /* check auth */ + result = polkit_authority_check_authorization_sync (polkit->priv->authority, subject, action_id, NULL, 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_error_free (error_local); + g_error_free (error); + goto out; + } + + ret = polkit_authorization_result_get_is_authorized (result) || + polkit_authorization_result_get_is_challenge (result); +out: + if (result != NULL) + g_object_unref (result); + return ret; +} + +/** * up_polkit_get_uid: **/ gboolean diff --git a/src/up-polkit.h b/src/up-polkit.h index dbc858d..acee70e 100644 --- a/src/up-polkit.h +++ b/src/up-polkit.h @@ -57,6 +57,10 @@ gboolean up_polkit_check_auth (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, DBusGMethodInvocation *context); +gboolean up_polkit_is_allowed (UpPolkit *polkit, + PolkitSubject *subject, + const gchar *action_id, + DBusGMethodInvocation *context); gboolean up_polkit_get_uid (UpPolkit *polkit, PolkitSubject *subject, uid_t *uid); -- 1.6.5