summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordnovotny <danny@rawhide.localdomain>2009-09-15 08:15:43 -0400
committerdnovotny <danny@rawhide.localdomain>2009-09-15 08:15:43 -0400
commit42a96a87f17b45c6cba999cb965ae6ef9f7c5735 (patch)
tree0c4f9f53aabd627b245e8ebc01da64b20509f715 /lib
parentbd28b0764868080c98866a0cebf7abfdd6a0acd3 (diff)
downloadabrt-42a96a87f17b45c6cba999cb965ae6ef9f7c5735.tar.gz
abrt-42a96a87f17b45c6cba999cb965ae6ef9f7c5735.tar.xz
abrt-42a96a87f17b45c6cba999cb965ae6ef9f7c5735.zip
added another form of checking Polkit rights: from PID
Diffstat (limited to 'lib')
-rw-r--r--lib/Utils/Polkit.cpp38
-rw-r--r--lib/Utils/Polkit.h5
2 files changed, 42 insertions, 1 deletions
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 <sys/types.h>
+#include <unistd.h>
+
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