summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-09-15 19:15:50 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-09-15 19:15:50 +0200
commit0a1eb8d27e3ba34cf8f1aadaa101c8edbfd9fc6b (patch)
tree75efdf6de14e66c577f2b72d9a20fb51c6d0d97b /lib
parentb60ce4965bee80f44db8a7e76382ecbd2947e4d4 (diff)
downloadabrt-0a1eb8d27e3ba34cf8f1aadaa101c8edbfd9fc6b.tar.gz
abrt-0a1eb8d27e3ba34cf8f1aadaa101c8edbfd9fc6b.tar.xz
abrt-0a1eb8d27e3ba34cf8f1aadaa101c8edbfd9fc6b.zip
reuse code, do not cut-n-paste
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Utils/Polkit.cpp56
1 files changed, 13 insertions, 43 deletions
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);
}