From 42a96a87f17b45c6cba999cb965ae6ef9f7c5735 Mon Sep 17 00:00:00 2001 From: dnovotny Date: Tue, 15 Sep 2009 08:15:43 -0400 Subject: added another form of checking Polkit rights: from PID --- lib/Utils/Polkit.cpp | 38 ++++++++++++++++++++++++++++++++++++++ lib/Utils/Polkit.h | 5 ++++- 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Utils/Polkit.cpp b/lib/Utils/Polkit.cpp index f68c3ae1..ea2316a2 100644 --- a/lib/Utils/Polkit.cpp +++ b/lib/Utils/Polkit.cpp @@ -65,3 +65,41 @@ PolkitResult polkit_check_authorization(const char *dbus_name, const char *actio return PolkitUnknown; } +PolkitResult polkit_check_authorization(pid_t pid, const char *action_id) +{ + PolkitAuthority *authority; + PolkitSubject *subject; + PolkitAuthorizationResult *result; + GError *error = NULL; + + g_type_init(); + authority = polkit_authority_get(); + subject = polkit_unix_process_new(pid); + + result = polkit_authority_check_authorization_sync(authority, + subject, + action_id, + NULL, + POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, + NULL, + &error); + + if (error) + { + g_error_free(error); + return PolkitUnknown; + } + + if (result) + { + if (polkit_authorization_result_get_is_challenge(result)) + /* Can't happen (happens only with + * POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE flag) */ + return PolkitChallenge; + if (polkit_authorization_result_get_is_authorized(result)) + return PolkitYes; + return PolkitNo; + } + + return PolkitUnknown; +} diff --git a/lib/Utils/Polkit.h b/lib/Utils/Polkit.h index c126f864..22b34019 100644 --- a/lib/Utils/Polkit.h +++ b/lib/Utils/Polkit.h @@ -22,6 +22,9 @@ #ifndef ABRT_POLKIT_H #define ABRT_POLKIT_H +#include +#include + typedef enum { /* Authorization status is unknown */ PolkitUnknown = 0x0, @@ -35,6 +38,6 @@ typedef enum { } PolkitResult; PolkitResult polkit_check_authorization(const char *dbus_name, const char *action_id); -PolkitResult polkit_check_authorization(unsigned int UID, const char *action_id); +PolkitResult polkit_check_authorization(pid_t pid, const char *action_id); #endif -- cgit