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 @@ -96,6 +96,35 @@ out: return ret; } +/** + * 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: **/ 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);