mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-27 23:08:27 +02: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
144 lines
3.7 KiB
C
144 lines
3.7 KiB
C
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
|
|
|
#include <string.h>
|
|
#include <glib/gstdio.h>
|
|
#include <gio/gio.h>
|
|
#include <NetworkManager.h>
|
|
#include "nm-suse-connection.h"
|
|
#include "parser.h"
|
|
|
|
G_DEFINE_TYPE (NMSuseConnection, nm_suse_connection, NM_TYPE_SYSCONFIG_CONNECTION)
|
|
|
|
#define NM_SUSE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SUSE_CONNECTION, NMSuseConnectionPrivate))
|
|
|
|
typedef struct {
|
|
GFileMonitor *monitor;
|
|
guint monitor_id;
|
|
|
|
const char *iface;
|
|
NMDeviceType dev_type;
|
|
char *filename;
|
|
} NMSuseConnectionPrivate;
|
|
|
|
static void
|
|
file_changed (GFileMonitor *monitor,
|
|
GFile *file,
|
|
GFile *other_file,
|
|
GFileMonitorEvent event_type,
|
|
gpointer user_data)
|
|
{
|
|
NMExportedConnection *exported = NM_EXPORTED_CONNECTION (user_data);
|
|
NMSuseConnectionPrivate *priv = NM_SUSE_CONNECTION_GET_PRIVATE (exported);
|
|
NMConnection *new_connection;
|
|
GHashTable *new_settings;
|
|
|
|
switch (event_type) {
|
|
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
|
new_connection = parse_ifcfg (priv->iface, priv->dev_type);
|
|
if (new_connection) {
|
|
new_settings = nm_connection_to_hash (new_connection);
|
|
nm_exported_connection_update (exported, new_settings, NULL);
|
|
g_hash_table_destroy (new_settings);
|
|
g_object_unref (new_connection);
|
|
} else
|
|
nm_exported_connection_delete (exported, NULL);
|
|
break;
|
|
case G_FILE_MONITOR_EVENT_DELETED:
|
|
nm_exported_connection_delete (exported, NULL);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
NMSuseConnection *
|
|
nm_suse_connection_new (const char *iface, NMDeviceType dev_type)
|
|
{
|
|
NMConnection *connection;
|
|
GFile *file;
|
|
GFileMonitor *monitor;
|
|
NMSuseConnection *exported;
|
|
NMSuseConnectionPrivate *priv;
|
|
|
|
g_return_val_if_fail (iface != NULL, NULL);
|
|
|
|
connection = parse_ifcfg (iface, dev_type);
|
|
if (!connection)
|
|
return NULL;
|
|
|
|
exported = (NMSuseConnection *) g_object_new (NM_TYPE_SUSE_CONNECTION,
|
|
NM_EXPORTED_CONNECTION_CONNECTION, connection,
|
|
NULL);
|
|
g_object_unref (connection);
|
|
if (!exported)
|
|
return NULL;
|
|
|
|
priv = NM_SUSE_CONNECTION_GET_PRIVATE (exported);
|
|
|
|
priv->iface = g_strdup (iface);
|
|
priv->dev_type = dev_type;
|
|
priv->filename = g_strdup_printf (SYSCONFDIR "/sysconfig/network/ifcfg-%s", iface);
|
|
|
|
file = g_file_new_for_path (priv->filename);
|
|
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
|
g_object_unref (file);
|
|
|
|
if (monitor) {
|
|
priv->monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (file_changed), exported);
|
|
priv->monitor = monitor;
|
|
}
|
|
|
|
return exported;
|
|
}
|
|
|
|
static GHashTable *
|
|
get_settings (NMExportedConnection *exported)
|
|
{
|
|
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
|
|
}
|
|
|
|
static const char *
|
|
get_id (NMExportedConnection *exported)
|
|
{
|
|
return NM_SUSE_CONNECTION_GET_PRIVATE (exported)->filename;
|
|
}
|
|
|
|
/* GObject */
|
|
|
|
static void
|
|
nm_suse_connection_init (NMSuseConnection *connection)
|
|
{
|
|
}
|
|
|
|
static void
|
|
finalize (GObject *object)
|
|
{
|
|
NMSuseConnectionPrivate *priv = NM_SUSE_CONNECTION_GET_PRIVATE (object);
|
|
|
|
if (priv->monitor) {
|
|
if (priv->monitor_id)
|
|
g_signal_handler_disconnect (priv->monitor, priv->monitor_id);
|
|
|
|
g_file_monitor_cancel (priv->monitor);
|
|
g_object_unref (priv->monitor);
|
|
}
|
|
|
|
g_free (priv->filename);
|
|
|
|
G_OBJECT_CLASS (nm_suse_connection_parent_class)->finalize (object);
|
|
}
|
|
|
|
static void
|
|
nm_suse_connection_class_init (NMSuseConnectionClass *suse_connection_class)
|
|
{
|
|
GObjectClass *object_class = G_OBJECT_CLASS (suse_connection_class);
|
|
NMExportedConnectionClass *connection_class = NM_EXPORTED_CONNECTION_CLASS (suse_connection_class);
|
|
|
|
g_type_class_add_private (suse_connection_class, sizeof (NMSuseConnectionPrivate));
|
|
|
|
/* Virtual methods */
|
|
object_class->finalize = finalize;
|
|
|
|
connection_class->get_settings = get_settings;
|
|
connection_class->get_id = get_id;
|
|
}
|