summaryrefslogtreecommitdiff
path: root/plugins/polkit.c
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-08-13 02:34:35 +0200
committerMarcel Holtmann <marcel@holtmann.org>2008-08-13 02:34:35 +0200
commit81f05550490e222185736eb198d3d760a636722d (patch)
tree0823fb6635976d75651b457f48aff337284dad32 /plugins/polkit.c
parent531e3460465e6f493eb0b7de2a3b8a7d8959563d (diff)
downloadconnman-81f05550490e222185736eb198d3d760a636722d.tar.gz
connman-81f05550490e222185736eb198d3d760a636722d.tar.bz2
connman-81f05550490e222185736eb198d3d760a636722d.zip
Create PolicyKit context and register security callbacks
Diffstat (limited to 'plugins/polkit.c')
-rw-r--r--plugins/polkit.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/plugins/polkit.c b/plugins/polkit.c
index 76e64521..bff357fb 100644
--- a/plugins/polkit.c
+++ b/plugins/polkit.c
@@ -23,16 +23,104 @@
#include <config.h>
#endif
+#include <errno.h>
+
+#include <glib.h>
+#include <polkit-dbus/polkit-dbus.h>
+
#include <connman/plugin.h>
+#include <connman/security.h>
#include <connman/log.h>
+static PolKitContext *polkit_context = NULL;
+
+static int polkit_authorize(const char *sender)
+{
+ DBG("sender %s", sender);
+
+ return -EPERM;
+}
+
+static struct connman_security polkit_security = {
+ .name = "polkit",
+ .authorize_sender = polkit_authorize,
+};
+
+static gboolean watch_event(GIOChannel *channel, GIOCondition condition,
+ gpointer user_data)
+{
+ PolKitContext *context = user_data;
+ int fd;
+
+ DBG("context %p", context);
+
+ fd = g_io_channel_unix_get_fd(channel);
+
+ polkit_context_io_func(context, fd);
+
+ return TRUE;
+}
+
+static int add_watch(PolKitContext *context, int fd)
+{
+ GIOChannel *channel;
+ guint id = 0;
+
+ DBG("context %p", context);
+
+ channel = g_io_channel_unix_new(fd);
+ if (channel == NULL)
+ return 0;
+
+ id = g_io_add_watch(channel, G_IO_IN, watch_event, context);
+
+ g_io_channel_unref(channel);
+
+ return id;
+}
+
+static void remove_watch(PolKitContext *context, int id)
+{
+ DBG("context %p", context);
+
+ g_source_remove(id);
+}
+
static int polkit_init(void)
{
+ int err;
+
+ polkit_context = polkit_context_new();
+
+ polkit_context_set_io_watch_functions(polkit_context,
+ add_watch, remove_watch);
+
+ if (polkit_context_init(polkit_context, NULL) == FALSE) {
+ connman_error("Can't initialize PolicyKit");
+ polkit_context_unref(polkit_context);
+ polkit_context = NULL;
+ return -EIO;
+ }
+
+ err = connman_security_register(&polkit_security);
+ if (err < 0) {
+ polkit_context_unref(polkit_context);
+ polkit_context = NULL;
+ return err;
+ }
+
return 0;
}
static void polkit_exit(void)
{
+ connman_security_unregister(&polkit_security);
+
+ if (polkit_context == NULL)
+ return;
+
+ polkit_context_unref(polkit_context);
+ polkit_context = NULL;
}
CONNMAN_PLUGIN_DEFINE("polkit", "PolicyKit authorization plugin", VERSION,