From 81f05550490e222185736eb198d3d760a636722d Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 13 Aug 2008 02:34:35 +0200 Subject: [PATCH] Create PolicyKit context and register security callbacks --- plugins/Makefile.am | 3 +- plugins/polkit.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 3aee132..03ac0f3 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -11,6 +11,7 @@ ethernet_la_SOURCES = ethernet.c wifi_la_SOURCES = wifi.c supplicant.h supplicant.c bluetooth_la_SOURCES = bluetooth.c +bluetooth_la_LIBADD = @GDBUS_LIBS@ dhclient_la_SOURCES = dhclient.c dhclient_la_CFLAGS = @GLIB_CFLAGS@ @GDBUS_CFLAGS@ -DDHCLIENT=\"@DHCLIENT@\" \ @@ -34,7 +35,7 @@ if POLKIT plugin_LTLIBRARIES += polkit.la polkit_la_SOURCES = polkit.c -polkit_la_LIBADD = @POLKIT_LIBS@ +polkit_la_LIBADD = @POLKIT_LIBS@ @GLIB_LIBS@ polkit_la_CFLAGS = @GLIB_CFLAGS@ @POLKIT_CFLAGS@ endif diff --git a/plugins/polkit.c b/plugins/polkit.c index 76e6452..bff357f 100644 --- a/plugins/polkit.c +++ b/plugins/polkit.c @@ -23,16 +23,104 @@ #include #endif +#include + +#include +#include + #include +#include #include +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, -- 2.7.4