diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2010-02-08 17:44:05 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2010-02-09 10:42:34 +0000 |
commit | a057e36751aa7885c9ce9fc43cad4e975498fc60 (patch) | |
tree | 38e51587ee11d9c5a748657639676b916361e39c | |
parent | 1738ac30b779a87f9d4d1a2a0f3ace2385d789a7 (diff) |
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
-rw-r--r-- | src/up-polkit.c | 29 | ||||
-rw-r--r-- | 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); |