mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-26 05:20:08 +01:00
Use PolicyKit to authorize the system settings' AddConnection method
and the system settings connections' Update and Delete methods.
* libnm-glib/nm-settings.c (impl_exported_connection_update)
(impl_exported_connection_delete, nm_exported_connection_update)
(nm_exported_connection_delete): Return boolean and fill GError
to notify the callers of the reasons why it might have failed.
* libnm-glib/nm-dbus-settings-system.c
(nm_dbus_settings_system_add_connection): Return the error from dbus
call so that the callers can see why it failed.
* libnm-glib/nm-dbus-connection.c (update, delete): Update the
signatures.
* system-settings/src/nm-polkit-helpers.[ch]: Implement.
* system-settings/src/nm-sysconfig-connection.[ch]: Implement. New
abstract base class that checks PolicyKit permissions.
* system-settings/src/dbus-settings.c:
(impl_settings_add_connection): Check the policy before carring out
the request.
* system-settings/plugins/keyfile/nm-keyfile-connection.c:
Inherit from NMSysconfigConnection, check the policies before
allowing updating or removing.
* system-settings/plugins/ifcfg-suse/nm-suse-connection.c:
Inherit from NMSysconfigConnection.
* introspection/nm-exported-connection.xml: Annotate "Update" and
"Delete" methods with async flag so that the implementations can get
access to DBusGMethodInvocation.
* system-settings/src/dbus-settings.c
(settings_add_connection_check_privileges): Implement.
(impl_settings_add_connection): Check the privileges before adding a new
connection. Improve error reporting.
* introspection/nm-settings-system.xml: Make the 'AddConnection' method
async so that the implementation can access DBusGMethodInvocation.
* configure.in: Check for PolicyKit.
* policy/org.freedesktop.network-manager-settings.system.policy:
New file.
* policy/Makefile.am: Install the policy file.
* configure.in: Add 'policy' subdir.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3646 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
86 lines
2.6 KiB
C
86 lines
2.6 KiB
C
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
|
|
|
#include <NetworkManager.h>
|
|
#include "nm-sysconfig-connection.h"
|
|
#include "nm-polkit-helpers.h"
|
|
|
|
G_DEFINE_ABSTRACT_TYPE (NMSysconfigConnection, nm_sysconfig_connection, NM_TYPE_EXPORTED_CONNECTION)
|
|
|
|
#define NM_SYSCONFIG_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SYSCONFIG_CONNECTION, NMSysconfigConnectionPrivate))
|
|
|
|
typedef struct {
|
|
DBusGConnection *dbus_connection;
|
|
PolKitContext *pol_ctx;
|
|
} NMSysconfigConnectionPrivate;
|
|
|
|
static gboolean
|
|
update (NMExportedConnection *exported,
|
|
GHashTable *new_settings,
|
|
GError **err)
|
|
{
|
|
NMSysconfigConnectionPrivate *priv = NM_SYSCONFIG_CONNECTION_GET_PRIVATE (exported);
|
|
DBusGMethodInvocation *context;
|
|
|
|
context = g_object_get_data (G_OBJECT (exported), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION);
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
|
|
|
return check_polkit_privileges (priv->dbus_connection, priv->pol_ctx, context, err);
|
|
}
|
|
|
|
static gboolean
|
|
delete (NMExportedConnection *exported, GError **err)
|
|
{
|
|
NMSysconfigConnectionPrivate *priv = NM_SYSCONFIG_CONNECTION_GET_PRIVATE (exported);
|
|
DBusGMethodInvocation *context;
|
|
|
|
context = g_object_get_data (G_OBJECT (exported), NM_EXPORTED_CONNECTION_DBUS_METHOD_INVOCATION);
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
|
|
|
return check_polkit_privileges (priv->dbus_connection, priv->pol_ctx, context, err);
|
|
}
|
|
|
|
/* GObject */
|
|
|
|
static void
|
|
nm_sysconfig_connection_init (NMSysconfigConnection *self)
|
|
{
|
|
NMSysconfigConnectionPrivate *priv = NM_SYSCONFIG_CONNECTION_GET_PRIVATE (self);
|
|
GError *err = NULL;
|
|
|
|
priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
|
|
if (err) {
|
|
g_warning ("Could not get DBus connection: %s", err->message);
|
|
g_error_free (err);
|
|
}
|
|
|
|
priv->pol_ctx = create_polkit_context ();
|
|
}
|
|
|
|
static void
|
|
finalize (GObject *object)
|
|
{
|
|
NMSysconfigConnectionPrivate *priv = NM_SYSCONFIG_CONNECTION_GET_PRIVATE (object);
|
|
|
|
if (priv->pol_ctx)
|
|
polkit_context_unref (priv->pol_ctx);
|
|
|
|
if (priv->dbus_connection)
|
|
dbus_g_connection_unref (priv->dbus_connection);
|
|
|
|
G_OBJECT_CLASS (nm_sysconfig_connection_parent_class)->finalize (object);
|
|
}
|
|
|
|
static void
|
|
nm_sysconfig_connection_class_init (NMSysconfigConnectionClass *sysconfig_connection_class)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (sysconfig_connection_class);
|
|
NMExportedConnectionClass *connection_class = NM_EXPORTED_CONNECTION_CLASS (sysconfig_connection_class);
|
|
|
|
g_type_class_add_private (sysconfig_connection_class, sizeof (NMSysconfigConnectionPrivate));
|
|
|
|
/* Virtual methods */
|
|
object_class->finalize = finalize;
|
|
|
|
connection_class->update = update;
|
|
connection_class->delete = delete;
|
|
}
|