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/Utils/Polkit.cpp') 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 From 9c5be05fba0e0ec0acd650d00412779c48344649 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 15 Sep 2009 19:19:28 +0200 Subject: add forgotten } Signed-off-by: Denys Vlasenko --- lib/Utils/Polkit.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/Utils/Polkit.cpp') diff --git a/lib/Utils/Polkit.cpp b/lib/Utils/Polkit.cpp index 71e57030..d3d92d14 100644 --- a/lib/Utils/Polkit.cpp +++ b/lib/Utils/Polkit.cpp @@ -61,6 +61,7 @@ static PolkitResult do_check(PolkitSubject *subject, const char *action_id) } return PolkitUnknown; +} PolkitResult polkit_check_authorization(const char *dbus_name, const char *action_id) { -- cgit From 84e7d725639764752088976914bfdc40fce8f3d0 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Wed, 16 Sep 2009 16:22:39 +0200 Subject: moved g_type_init() to right place --- lib/Utils/Polkit.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/Utils/Polkit.cpp') diff --git a/lib/Utils/Polkit.cpp b/lib/Utils/Polkit.cpp index d3d92d14..6d6cf0dd 100644 --- a/lib/Utils/Polkit.cpp +++ b/lib/Utils/Polkit.cpp @@ -32,7 +32,6 @@ static PolkitResult do_check(PolkitSubject *subject, const char *action_id) PolkitAuthorizationResult *result; GError *error = NULL; - g_type_init(); authority = polkit_authority_get(); result = polkit_authority_check_authorization_sync(authority, @@ -65,12 +64,14 @@ static PolkitResult do_check(PolkitSubject *subject, const char *action_id) PolkitResult polkit_check_authorization(const char *dbus_name, const char *action_id) { + g_type_init(); 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) { + g_type_init(); PolkitSubject *subject = polkit_unix_process_new(pid); return do_check(subject, action_id); } -- cgit