From 0a1eb8d27e3ba34cf8f1aadaa101c8edbfd9fc6b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Sep 2009 19:15:50 +0200 Subject: reuse code, do not cut-n-paste Signed-off-by: Denys Vlasenko --- lib/Utils/Polkit.cpp | 56 ++++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) (limited to 'lib') diff --git a/lib/Utils/Polkit.cpp b/lib/Utils/Polkit.cpp index ea2316a2..71e57030 100644 --- a/lib/Utils/Polkit.cpp +++ b/lib/Utils/Polkit.cpp @@ -26,16 +26,14 @@ #include "Polkit.h" -PolkitResult polkit_check_authorization(const char *dbus_name, const char *action_id) +static PolkitResult do_check(PolkitSubject *subject, const char *action_id) { PolkitAuthority *authority; - PolkitSubject *subject; PolkitAuthorizationResult *result; GError *error = NULL; g_type_init(); authority = polkit_authority_get(); - subject = polkit_system_bus_name_new(dbus_name); result = polkit_authority_check_authorization_sync(authority, subject, @@ -53,53 +51,25 @@ PolkitResult polkit_check_authorization(const char *dbus_name, const char *actio if (result) { - if (polkit_authorization_result_get_is_challenge(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 PolkitChallenge; + if (polkit_authorization_result_get_is_authorized(result)) + return PolkitYes; + return PolkitNo; } return PolkitUnknown; + +PolkitResult polkit_check_authorization(const char *dbus_name, const char *action_id) +{ + PolkitSubject *subject = polkit_system_bus_name_new(dbus_name); + return do_check(subject, action_id); } 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; + PolkitSubject *subject = polkit_unix_process_new(pid); + return do_check(subject, action_id); } -- cgit