5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <polkit-dbus/polkit-dbus.h>
31 #include <connman/plugin.h>
32 #include <connman/security.h>
33 #include <connman/log.h>
35 static PolKitContext *polkit_context = NULL;
37 static int polkit_authorize(const char *sender)
39 DBG("sender %s", sender);
44 static struct connman_security polkit_security = {
46 .authorize_sender = polkit_authorize,
49 static gboolean watch_event(GIOChannel *channel, GIOCondition condition,
52 PolKitContext *context = user_data;
55 DBG("context %p", context);
57 fd = g_io_channel_unix_get_fd(channel);
59 polkit_context_io_func(context, fd);
64 static int add_watch(PolKitContext *context, int fd)
69 DBG("context %p", context);
71 channel = g_io_channel_unix_new(fd);
75 id = g_io_add_watch(channel, G_IO_IN, watch_event, context);
77 g_io_channel_unref(channel);
82 static void remove_watch(PolKitContext *context, int id)
84 DBG("context %p", context);
89 static int polkit_init(void)
93 polkit_context = polkit_context_new();
95 polkit_context_set_io_watch_functions(polkit_context,
96 add_watch, remove_watch);
98 if (polkit_context_init(polkit_context, NULL) == FALSE) {
99 connman_error("Can't initialize PolicyKit");
100 polkit_context_unref(polkit_context);
101 polkit_context = NULL;
105 err = connman_security_register(&polkit_security);
107 polkit_context_unref(polkit_context);
108 polkit_context = NULL;
115 static void polkit_exit(void)
117 connman_security_unregister(&polkit_security);
119 if (polkit_context == NULL)
122 polkit_context_unref(polkit_context);
123 polkit_context = NULL;
126 CONNMAN_PLUGIN_DEFINE("polkit", "PolicyKit authorization plugin", VERSION,
127 polkit_init, polkit_exit)