From 9a2b2633095fb901fc1931ab0c600392d68bb3b4 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Mon, 14 Jul 2014 08:16:06 +0300 Subject: Remove polkit dependency With the removal of the suspend/hibernate code, there's no longer a need for upower to depend on polkit. This patch removes the old polkit code. Signed-off-by: Richard Hughes --- configure.ac | 1 - src/Makefile.am | 4 - src/up-daemon.c | 4 - src/up-daemon.h | 1 - src/up-device.h | 1 - src/up-polkit.c | 278 -------------------------------------------------------- src/up-polkit.h | 74 --------------- 7 files changed, 363 deletions(-) delete mode 100644 src/up-polkit.c delete mode 100644 src/up-polkit.h diff --git a/configure.ac b/configure.ac index 9ead3d4..61244fa 100644 --- a/configure.ac +++ b/configure.ac @@ -155,7 +155,6 @@ AC_SUBST([RELRO_LDFLAGS]) PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.29.19]) PKG_CHECK_MODULES(DBUS, [dbus-1 >= 1.0]) PKG_CHECK_MODULES(DBUS_GLIB, [dbus-glib-1 >= 0.76]) -PKG_CHECK_MODULES(POLKIT, polkit-gobject-1 >= 0.97) PKG_CHECK_MODULES(GIO, [gio-2.0 >= 2.16.1]) PKG_CHECK_MODULES(GIO_UNIX, [gio-unix-2.0]) diff --git a/src/Makefile.am b/src/Makefile.am index 7ef0ca5..2de5e6d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,6 @@ AM_CPPFLAGS = \ $(GIO_CFLAGS) \ $(DBUS_GLIB_CFLAGS) \ $(GUDEV_CFLAGS) \ - $(POLKIT_CFLAGS) \ $(GLIB_CFLAGS) UPOWER_LIBS = $(top_builddir)/libupower-glib/libupower-glib.la @@ -62,8 +61,6 @@ dbusif_DATA = \ org.freedesktop.UPower.Wakeups.xml upowerd_SOURCES = \ - up-polkit.h \ - up-polkit.c \ up-daemon.h \ up-daemon.c \ up-device.h \ @@ -92,7 +89,6 @@ upowerd_LDADD = \ $(USB_LIBS) \ $(GIO_LIBS) \ $(DBUS_GLIB_LIBS) \ - $(POLKIT_LIBS) \ $(UPOWER_LIBS) if BACKEND_TYPE_DUMMY diff --git a/src/up-daemon.c b/src/up-daemon.c index c7fea62..d53facc 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -33,7 +33,6 @@ #include #include "up-config.h" -#include "up-polkit.h" #include "up-device-list.h" #include "up-device.h" #include "up-backend.h" @@ -66,7 +65,6 @@ struct UpDaemonPrivate DBusGConnection *connection; DBusGProxy *proxy; UpConfig *config; - UpPolkit *polkit; UpBackend *backend; UpDeviceList *power_devices; guint action_timeout_id; @@ -1103,7 +1101,6 @@ static void up_daemon_init (UpDaemon *daemon) { daemon->priv = UP_DAEMON_GET_PRIVATE (daemon); - daemon->priv->polkit = up_polkit_new (); daemon->priv->config = up_config_new (); daemon->priv->power_devices = up_device_list_new (); daemon->priv->display_device = up_device_new (); @@ -1272,7 +1269,6 @@ up_daemon_finalize (GObject *object) if (priv->connection != NULL) dbus_g_connection_unref (priv->connection); g_object_unref (priv->power_devices); - g_object_unref (priv->polkit); g_object_unref (priv->config); g_object_unref (priv->backend); diff --git a/src/up-daemon.h b/src/up-daemon.h index 2d25bb2..3392ad0 100644 --- a/src/up-daemon.h +++ b/src/up-daemon.h @@ -22,7 +22,6 @@ #define __UP_DAEMON_H__ #include -#include #include #include "up-types.h" diff --git a/src/up-device.h b/src/up-device.h index 34acf8c..53415e7 100644 --- a/src/up-device.h +++ b/src/up-device.h @@ -23,7 +23,6 @@ #define __UP_DEVICE_H__ #include -#include #include #include "up-daemon.h" diff --git a/src/up-polkit.c b/src/up-polkit.c deleted file mode 100644 index ce84c04..0000000 --- a/src/up-polkit.c +++ /dev/null @@ -1,278 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 David Zeuthen - * Copyright (C) 2008 Richard Hughes - * - * Licensed under the GNU General Public License Version 2 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include - -#include "up-polkit.h" -#include "up-daemon.h" - -#define UP_POLKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_POLKIT, UpPolkitPrivate)) - -struct UpPolkitPrivate -{ - DBusGConnection *connection; - PolkitAuthority *authority; -}; - -G_DEFINE_TYPE (UpPolkit, up_polkit, G_TYPE_OBJECT) -static gpointer up_polkit_object = NULL; - -/** - * up_polkit_get_subject: - **/ -PolkitSubject * -up_polkit_get_subject (UpPolkit *polkit, DBusGMethodInvocation *context) -{ - GError *error; - gchar *sender; - PolkitSubject *subject; - - sender = dbus_g_method_get_sender (context); - subject = polkit_system_bus_name_new (sender); - g_free (sender); - - if (subject == NULL) { - error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to get PolicyKit subject"); - dbus_g_method_return_error (context, error); - g_error_free (error); - } - - return subject; -} - -/** - * up_polkit_check_auth: - **/ -gboolean -up_polkit_check_auth (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, DBusGMethodInvocation *context) -{ - gboolean ret = FALSE; - GError *error; - GError *error_local = NULL; - PolkitAuthorizationResult *result; - - /* check auth */ - result = polkit_authority_check_authorization_sync (polkit->priv->authority, - subject, action_id, NULL, - POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION, - NULL, &error_local); - if (result == NULL) { - error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message); - dbus_g_method_return_error (context, error); - g_error_free (error_local); - g_error_free (error); - goto out; - } - - /* okay? */ - if (polkit_authorization_result_get_is_authorized (result)) { - ret = TRUE; - } else { - error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "not authorized"); - dbus_g_method_return_error (context, error); - g_error_free (error); - } -out: - if (result != NULL) - g_object_unref (result); - return ret; -} - -/** - * up_polkit_is_allowed: - **/ -gboolean -up_polkit_is_allowed (UpPolkit *polkit, PolkitSubject *subject, const gchar *action_id, GError **error) -{ - gboolean ret = FALSE; - GError *error_local = NULL; - PolkitAuthorizationResult *result; - - /* check auth */ - result = polkit_authority_check_authorization_sync (polkit->priv->authority, - subject, action_id, NULL, - POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE, - NULL, &error_local); - if (result == NULL) { - g_set_error (error, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "failed to check authorisation: %s", error_local->message); - g_error_free (error_local); - goto out; - } - - ret = polkit_authorization_result_get_is_authorized (result) || - polkit_authorization_result_get_is_challenge (result); -out: - if (result != NULL) - g_object_unref (result); - return ret; -} - -/** - * up_polkit_get_uid: - **/ -gboolean -up_polkit_get_uid (UpPolkit *polkit, PolkitSubject *subject, uid_t *uid) -{ - DBusConnection *connection; - const gchar *name; - - if (!POLKIT_IS_SYSTEM_BUS_NAME (subject)) { - g_debug ("not system bus name"); - return FALSE; - } - - connection = dbus_g_connection_get_connection (polkit->priv->connection); - name = polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)); - *uid = dbus_bus_get_unix_user (connection, name, NULL); - return TRUE; -} - -/** - * up_polkit_get_pid: - **/ -gboolean -up_polkit_get_pid (UpPolkit *polkit, PolkitSubject *subject, pid_t *pid) -{ - gboolean ret = FALSE; - GError *error = NULL; - const gchar *name; - DBusGProxy *proxy = NULL; - - /* bus name? */ - if (!POLKIT_IS_SYSTEM_BUS_NAME (subject)) { - g_debug ("not system bus name"); - goto out; - } - - name = polkit_system_bus_name_get_name (POLKIT_SYSTEM_BUS_NAME (subject)); - proxy = dbus_g_proxy_new_for_name_owner (polkit->priv->connection, - "org.freedesktop.DBus", - "/org/freedesktop/DBus/Bus", - "org.freedesktop.DBus", &error); - if (proxy == NULL) { - g_warning ("DBUS error: %s", error->message); - g_error_free (error); - goto out; - } - - /* get pid from DBus (quite slow) */ - ret = dbus_g_proxy_call (proxy, "GetConnectionUnixProcessID", &error, - G_TYPE_STRING, name, - G_TYPE_INVALID, - G_TYPE_UINT, pid, - G_TYPE_INVALID); - if (!ret) { - g_warning ("failed to get pid: %s", error->message); - g_error_free (error); - goto out; - } -out: - if (proxy != NULL) - g_object_unref (proxy); - return ret; -} - -/** - * up_polkit_finalize: - **/ -static void -up_polkit_finalize (GObject *object) -{ - UpPolkit *polkit; - g_return_if_fail (UP_IS_POLKIT (object)); - polkit = UP_POLKIT (object); - - if (polkit->priv->connection != NULL) - dbus_g_connection_unref (polkit->priv->connection); - g_object_unref (polkit->priv->authority); - - G_OBJECT_CLASS (up_polkit_parent_class)->finalize (object); -} - -/** - * up_polkit_class_init: - **/ -static void -up_polkit_class_init (UpPolkitClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = up_polkit_finalize; - g_type_class_add_private (klass, sizeof (UpPolkitPrivate)); -} - -/** - * up_polkit_init: - * - * initializes the polkit class. NOTE: We expect polkit objects - * to *NOT* be removed or added during the session. - * We only control the first polkit object if there are more than one. - **/ -static void -up_polkit_init (UpPolkit *polkit) -{ - GError *error = NULL; - - polkit->priv = UP_POLKIT_GET_PRIVATE (polkit); - - polkit->priv->connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (polkit->priv->connection == NULL) { - if (error != NULL) { - g_critical ("error getting system bus: %s", error->message); - g_error_free (error); - } - goto out; - } - - polkit->priv->authority = polkit_authority_get_sync (NULL, &error); - if (polkit->priv->authority == NULL) { - g_error ("failed to get pokit authority: %s", error->message); - g_error_free (error); - goto out; - } -out: - return; -} - -/** - * up_polkit_new: - * Return value: A new polkit class instance. - **/ -UpPolkit * -up_polkit_new (void) -{ - if (up_polkit_object != NULL) { - g_object_ref (up_polkit_object); - } else { - up_polkit_object = g_object_new (UP_TYPE_POLKIT, NULL); - g_object_add_weak_pointer (up_polkit_object, &up_polkit_object); - } - return UP_POLKIT (up_polkit_object); -} - diff --git a/src/up-polkit.h b/src/up-polkit.h deleted file mode 100644 index 1ddac58..0000000 --- a/src/up-polkit.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2008 Richard Hughes - * - * Licensed under the GNU General Public License Version 2 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __UP_POLKIT_H -#define __UP_POLKIT_H - -#include -#include - -G_BEGIN_DECLS - -#define UP_TYPE_POLKIT (up_polkit_get_type ()) -#define UP_POLKIT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_POLKIT, UpPolkit)) -#define UP_POLKIT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_POLKIT, UpPolkitClass)) -#define UP_IS_POLKIT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_POLKIT)) -#define UP_IS_POLKIT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_POLKIT)) -#define UP_POLKIT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_POLKIT, UpPolkitClass)) - -typedef struct UpPolkitPrivate UpPolkitPrivate; - -typedef struct -{ - GObject parent; - UpPolkitPrivate *priv; -} UpPolkit; - -typedef struct -{ - GObjectClass parent_class; -} UpPolkitClass; - -GType up_polkit_get_type (void); -UpPolkit *up_polkit_new (void); -void up_polkit_test (gpointer user_data); - -PolkitSubject *up_polkit_get_subject (UpPolkit *polkit, - DBusGMethodInvocation *context); -gboolean up_polkit_check_auth (UpPolkit *polkit, - PolkitSubject *subject, - const gchar *action_id, - DBusGMethodInvocation *context); -gboolean up_polkit_is_allowed (UpPolkit *polkit, - PolkitSubject *subject, - const gchar *action_id, - GError **error); -gboolean up_polkit_get_uid (UpPolkit *polkit, - PolkitSubject *subject, - uid_t *uid); -gboolean up_polkit_get_pid (UpPolkit *polkit, - PolkitSubject *subject, - pid_t *pid); - -G_END_DECLS - -#endif /* __UP_POLKIT_H */ - -- cgit v1.2.1