summaryrefslogtreecommitdiffstats
path: root/lib/Utils
diff options
context:
space:
mode:
authordnovotny <danny@rawhide.localdomain>2009-09-16 10:42:40 -0400
committerdnovotny <danny@rawhide.localdomain>2009-09-16 10:42:40 -0400
commitf5ebde6f7a629dd74f023a185b0398305ecad604 (patch)
treea2f57bb0fab91468b8eee5b1aa27ee5a12693e06 /lib/Utils
parent42a96a87f17b45c6cba999cb965ae6ef9f7c5735 (diff)
downloadabrt-f5ebde6f7a629dd74f023a185b0398305ecad604.tar.gz
abrt-f5ebde6f7a629dd74f023a185b0398305ecad604.tar.xz
abrt-f5ebde6f7a629dd74f023a185b0398305ecad604.zip
added timeout to Polkit, added authorization check for debuginfo-install
Diffstat (limited to 'lib/Utils')
-rw-r--r--lib/Utils/Polkit.cpp77
1 files changed, 33 insertions, 44 deletions
diff --git a/lib/Utils/Polkit.cpp b/lib/Utils/Polkit.cpp
index ea2316a2..a5541c9f 100644
--- a/lib/Utils/Polkit.cpp
+++ b/lib/Utils/Polkit.cpp
@@ -25,24 +25,38 @@
#include <unistd.h>
#include "Polkit.h"
+#include "abrtlib.h"
-PolkitResult polkit_check_authorization(const char *dbus_name, const char *action_id)
+/*number of seconds: timeout for the authorization*/
+#define POLKIT_TIMEOUT 20
+
+static gboolean do_cancel(GCancellable* cancellable)
+{
+ log("Timer has expired; cancelling authorization check\n");
+ g_cancellable_cancel(cancellable);
+ return FALSE;
+}
+
+static PolkitResult do_check(PolkitSubject *subject, const char *action_id)
{
PolkitAuthority *authority;
- PolkitSubject *subject;
PolkitAuthorizationResult *result;
GError *error = NULL;
+ GCancellable * cancellable;
- g_type_init();
authority = polkit_authority_get();
- subject = polkit_system_bus_name_new(dbus_name);
+ cancellable = g_cancellable_new();
+
+ g_timeout_add (POLKIT_TIMEOUT * 1000,
+ (GSourceFunc) do_cancel,
+ cancellable);
result = polkit_authority_check_authorization_sync(authority,
subject,
action_id,
NULL,
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
- NULL,
+ cancellable,
&error);
if (error)
@@ -53,53 +67,28 @@ 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(pid_t pid, const char *action_id)
+PolkitResult polkit_check_authorization(const char *dbus_name, 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;
- }
+ PolkitSubject *subject = polkit_system_bus_name_new(dbus_name);
+ return do_check(subject, action_id);
+}
- return PolkitUnknown;
+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);
}