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@\" \
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
#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,