mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-02-02 14:20:35 +01:00
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
This commit is contained in:
parent
1738ac30b7
commit
a057e36751
2 changed files with 33 additions and 0 deletions
|
|
@ -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:
|
||||
**/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue