2008-08-12 18:39:03 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2007-11-21 06:24:15 +00:00
|
|
|
/* NetworkManager system settings service
|
|
|
|
|
*
|
|
|
|
|
* Søren Sandmann <sandmann@daimi.au.dk>
|
2008-08-12 18:39:03 +00:00
|
|
|
* Dan Williams <dcbw@redhat.com>
|
|
|
|
|
* Tambet Ingo <tambet@gmail.com>
|
2007-11-21 06:24:15 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2008-06-26 18:31:52 +00:00
|
|
|
* 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.
|
2007-11-21 06:24:15 +00:00
|
|
|
*
|
2008-08-12 18:39:03 +00:00
|
|
|
* (C) Copyright 2007 - 2008 Red Hat, Inc.
|
|
|
|
|
* (C) Copyright 2008 Novell, Inc.
|
2007-11-21 06:24:15 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-10-01 22:59:21 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2007-11-21 06:24:15 +00:00
|
|
|
#include <NetworkManager.h>
|
|
|
|
|
#include <nm-connection.h>
|
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
#include <nm-setting-connection.h>
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
#include "nm-dbus-glib-types.h"
|
2007-11-21 06:24:15 +00:00
|
|
|
#include "dbus-settings.h"
|
2008-05-09 06:33:30 +00:00
|
|
|
#include "nm-polkit-helpers.h"
|
2008-07-16 07:37:10 +00:00
|
|
|
#include "nm-system-config-error.h"
|
2007-11-21 06:24:15 +00:00
|
|
|
#include "nm-utils.h"
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
static gboolean
|
2008-05-09 06:33:30 +00:00
|
|
|
impl_settings_add_connection (NMSysconfigSettings *self, GHashTable *hash, DBusGMethodInvocation *context);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
static gboolean
|
|
|
|
|
impl_settings_save_hostname (NMSysconfigSettings *self, const char *hostname, DBusGMethodInvocation *context);
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
#include "nm-settings-system-glue.h"
|
|
|
|
|
|
2008-05-07 09:48:12 +00:00
|
|
|
static void unmanaged_devices_changed (NMSystemConfigInterface *config, gpointer user_data);
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
typedef struct {
|
2008-04-22 14:48:02 +00:00
|
|
|
DBusGConnection *g_connection;
|
2008-05-09 06:33:30 +00:00
|
|
|
PolKitContext *pol_ctx;
|
2008-04-22 14:48:02 +00:00
|
|
|
NMSystemConfigHalManager *hal_mgr;
|
|
|
|
|
|
|
|
|
|
GSList *plugins;
|
|
|
|
|
gboolean connections_loaded;
|
2008-05-07 09:48:12 +00:00
|
|
|
GHashTable *connections;
|
2008-04-08 01:36:39 +00:00
|
|
|
GHashTable *unmanaged_devices;
|
2008-10-01 22:59:21 +00:00
|
|
|
char *orig_hostname;
|
2008-04-08 01:36:39 +00:00
|
|
|
} NMSysconfigSettingsPrivate;
|
|
|
|
|
|
2007-11-21 06:24:15 +00:00
|
|
|
G_DEFINE_TYPE (NMSysconfigSettings, nm_sysconfig_settings, NM_TYPE_SETTINGS);
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
#define NM_SYSCONFIG_SETTINGS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SYSCONFIG_SETTINGS, NMSysconfigSettingsPrivate))
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROPERTIES_CHANGED,
|
|
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_UNMANAGED_DEVICES,
|
2008-09-18 14:46:57 +00:00
|
|
|
PROP_HOSTNAME,
|
2008-11-14 18:24:38 +00:00
|
|
|
PROP_CAN_MODIFY,
|
2008-04-08 01:36:39 +00:00
|
|
|
|
|
|
|
|
LAST_PROP
|
|
|
|
|
};
|
|
|
|
|
|
2008-05-11 20:20:52 +00:00
|
|
|
static void
|
|
|
|
|
load_connections (NMSysconfigSettings *self)
|
|
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
|
|
if (priv->connections_loaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
NMSystemConfigInterface *plugin = NM_SYSTEM_CONFIG_INTERFACE (iter->data);
|
|
|
|
|
GSList *plugin_connections;
|
|
|
|
|
GSList *elt;
|
|
|
|
|
|
|
|
|
|
plugin_connections = nm_system_config_interface_get_connections (plugin);
|
|
|
|
|
|
|
|
|
|
// FIXME: ensure connections from plugins loaded with a lower priority
|
|
|
|
|
// get rejected when they conflict with connections from a higher
|
|
|
|
|
// priority plugin.
|
|
|
|
|
|
|
|
|
|
for (elt = plugin_connections; elt; elt = g_slist_next (elt))
|
2009-03-02 12:58:45 -05:00
|
|
|
nm_sysconfig_settings_add_connection (self, NM_EXPORTED_CONNECTION (elt->data), TRUE);
|
2008-05-11 20:20:52 +00:00
|
|
|
|
|
|
|
|
g_slist_free (plugin_connections);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
priv->connections_loaded = TRUE;
|
|
|
|
|
|
2008-05-11 20:20:52 +00:00
|
|
|
/* FIXME: Bad hack */
|
|
|
|
|
unmanaged_devices_changed (NULL, self);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-07 09:48:12 +00:00
|
|
|
static void
|
|
|
|
|
hash_keys_to_slist (gpointer key, gpointer val, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GSList **list = (GSList **) user_data;
|
|
|
|
|
|
|
|
|
|
*list = g_slist_prepend (*list, key);
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-05 07:07:44 +00:00
|
|
|
static GSList *
|
2008-04-08 01:36:39 +00:00
|
|
|
list_connections (NMSettings *settings)
|
2007-11-21 06:24:15 +00:00
|
|
|
{
|
2008-04-08 01:36:39 +00:00
|
|
|
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (settings);
|
2008-05-07 09:48:12 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GSList *list = NULL;
|
|
|
|
|
|
2008-05-11 20:20:52 +00:00
|
|
|
load_connections (self);
|
2008-05-07 09:48:12 +00:00
|
|
|
|
|
|
|
|
g_hash_table_foreach (priv->connections, hash_keys_to_slist, &list);
|
|
|
|
|
|
|
|
|
|
return list;
|
2007-11-21 06:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-04-08 01:36:39 +00:00
|
|
|
settings_finalize (GObject *object)
|
2007-11-21 06:24:15 +00:00
|
|
|
{
|
2008-04-08 01:36:39 +00:00
|
|
|
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object);
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2007-11-21 06:24:15 +00:00
|
|
|
|
2008-05-07 09:48:12 +00:00
|
|
|
g_hash_table_destroy (priv->connections);
|
2008-04-08 01:36:39 +00:00
|
|
|
g_hash_table_destroy (priv->unmanaged_devices);
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
g_slist_foreach (priv->plugins, (GFunc) g_object_unref, NULL);
|
|
|
|
|
g_slist_free (priv->plugins);
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
if (priv->pol_ctx)
|
|
|
|
|
polkit_context_unref (priv->pol_ctx);
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_unref (priv->hal_mgr);
|
|
|
|
|
dbus_g_connection_unref (priv->g_connection);
|
|
|
|
|
|
2008-10-01 22:59:21 +00:00
|
|
|
g_free (priv->orig_hostname);
|
|
|
|
|
|
2007-11-21 06:24:15 +00:00
|
|
|
G_OBJECT_CLASS (nm_sysconfig_settings_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
static void
|
|
|
|
|
add_one_unmanaged_device (gpointer key, gpointer data, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GPtrArray *devices = (GPtrArray *) user_data;
|
|
|
|
|
|
|
|
|
|
g_ptr_array_add (devices, g_strdup (key));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char*
|
|
|
|
|
uscore_to_wincaps (const char *uscore)
|
|
|
|
|
{
|
|
|
|
|
const char *p;
|
|
|
|
|
GString *str;
|
|
|
|
|
gboolean last_was_uscore;
|
|
|
|
|
|
|
|
|
|
last_was_uscore = TRUE;
|
|
|
|
|
|
|
|
|
|
str = g_string_new (NULL);
|
|
|
|
|
p = uscore;
|
|
|
|
|
while (p && *p) {
|
|
|
|
|
if (*p == '-' || *p == '_')
|
|
|
|
|
last_was_uscore = TRUE;
|
|
|
|
|
else {
|
|
|
|
|
if (last_was_uscore) {
|
|
|
|
|
g_string_append_c (str, g_ascii_toupper (*p));
|
|
|
|
|
last_was_uscore = FALSE;
|
|
|
|
|
} else
|
|
|
|
|
g_string_append_c (str, *p);
|
|
|
|
|
}
|
|
|
|
|
++p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_string_free (str, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
notify (GObject *object, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GValue *value;
|
|
|
|
|
GHashTable *hash;
|
|
|
|
|
|
|
|
|
|
value = g_slice_new0 (GValue);
|
|
|
|
|
hash = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, NULL);
|
|
|
|
|
|
|
|
|
|
g_value_init (value, pspec->value_type);
|
|
|
|
|
g_object_get_property (object, pspec->name, value);
|
|
|
|
|
g_hash_table_insert (hash, uscore_to_wincaps (pspec->name), value);
|
|
|
|
|
g_signal_emit (object, signals[PROPERTIES_CHANGED], 0, hash);
|
|
|
|
|
g_hash_table_destroy (hash);
|
|
|
|
|
g_value_unset (value);
|
|
|
|
|
g_slice_free (GValue, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GPtrArray *
|
|
|
|
|
get_unmanaged_devices (NMSysconfigSettings *self)
|
|
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GPtrArray *devices;
|
|
|
|
|
|
2008-05-11 20:20:52 +00:00
|
|
|
load_connections (self);
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
devices = g_ptr_array_sized_new (3);
|
|
|
|
|
g_hash_table_foreach (priv->unmanaged_devices, (GHFunc) add_one_unmanaged_device, devices);
|
|
|
|
|
return devices;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-02 12:58:45 -05:00
|
|
|
NMSystemConfigInterface *
|
|
|
|
|
nm_sysconfig_settings_get_plugin (NMSysconfigSettings *self,
|
|
|
|
|
guint32 capability)
|
2008-11-14 18:24:38 +00:00
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GSList *iter;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (self != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* Do any of the plugins support setting the hostname? */
|
|
|
|
|
for (iter = priv->plugins; iter; iter = iter->next) {
|
|
|
|
|
NMSystemConfigInterfaceCapabilities caps = NM_SYSTEM_CONFIG_INTERFACE_CAP_NONE;
|
|
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (iter->data), NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES, &caps, NULL);
|
|
|
|
|
if (caps & capability)
|
|
|
|
|
return NM_SYSTEM_CONFIG_INTERFACE (iter->data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
2008-08-12 22:37:08 +00:00
|
|
|
GValue *value, GParamSpec *pspec)
|
2008-04-08 01:36:39 +00:00
|
|
|
{
|
|
|
|
|
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object);
|
2008-09-18 14:46:57 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GSList *iter;
|
2008-04-08 01:36:39 +00:00
|
|
|
|
2008-11-14 18:24:38 +00:00
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_UNMANAGED_DEVICES:
|
|
|
|
|
g_value_take_boxed (value, get_unmanaged_devices (self));
|
|
|
|
|
break;
|
2008-09-18 14:46:57 +00:00
|
|
|
case PROP_HOSTNAME:
|
|
|
|
|
/* Hostname returned is the hostname returned from the first plugin
|
|
|
|
|
* that provides one.
|
|
|
|
|
*/
|
|
|
|
|
for (iter = priv->plugins; iter; iter = iter->next) {
|
|
|
|
|
NMSystemConfigInterfaceCapabilities caps = NM_SYSTEM_CONFIG_INTERFACE_CAP_NONE;
|
|
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (iter->data), NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES, &caps, NULL);
|
|
|
|
|
if (caps & NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME) {
|
|
|
|
|
char *hostname = NULL;
|
|
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (iter->data), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME, &hostname, NULL);
|
|
|
|
|
if (hostname && strlen (hostname)) {
|
|
|
|
|
g_value_take_string (value, hostname);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-01 22:59:21 +00:00
|
|
|
/* If no plugin provided a hostname, try the original hostname of the machine */
|
|
|
|
|
if (!g_value_get_string (value) && priv->orig_hostname)
|
|
|
|
|
g_value_set_string (value, priv->orig_hostname);
|
|
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
/* Don't ever pass NULL through D-Bus */
|
|
|
|
|
if (!g_value_get_string (value))
|
|
|
|
|
g_value_set_static_string (value, "");
|
|
|
|
|
break;
|
2008-11-14 18:24:38 +00:00
|
|
|
case PROP_CAN_MODIFY:
|
2009-03-02 12:58:45 -05:00
|
|
|
g_value_set_boolean (value, !!nm_sysconfig_settings_get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS));
|
2008-11-14 18:24:38 +00:00
|
|
|
break;
|
2008-04-08 01:36:39 +00:00
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-21 06:24:15 +00:00
|
|
|
static void
|
|
|
|
|
nm_sysconfig_settings_class_init (NMSysconfigSettingsClass *class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
NMSettingsClass *settings_class = NM_SETTINGS_CLASS (class);
|
|
|
|
|
|
2008-05-09 06:33:30 +00:00
|
|
|
g_type_class_add_private (class, sizeof (NMSysconfigSettingsPrivate));
|
2008-04-08 01:36:39 +00:00
|
|
|
|
|
|
|
|
/* virtual methods */
|
|
|
|
|
object_class->notify = notify;
|
|
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
object_class->finalize = settings_finalize;
|
|
|
|
|
settings_class->list_connections = list_connections;
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_UNMANAGED_DEVICES,
|
|
|
|
|
g_param_spec_boxed (NM_SYSCONFIG_SETTINGS_UNMANAGED_DEVICES,
|
|
|
|
|
"Unamanged devices",
|
|
|
|
|
"Unmanaged devices",
|
|
|
|
|
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
|
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_HOSTNAME,
|
|
|
|
|
g_param_spec_string (NM_SYSCONFIG_SETTINGS_HOSTNAME,
|
|
|
|
|
"Hostname",
|
|
|
|
|
"Hostname",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
2008-11-14 18:24:38 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_CAN_MODIFY,
|
|
|
|
|
g_param_spec_boolean (NM_SYSCONFIG_SETTINGS_CAN_MODIFY,
|
|
|
|
|
"CanModify",
|
|
|
|
|
"Can modify",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_READABLE));
|
|
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
/* signals */
|
|
|
|
|
signals[PROPERTIES_CHANGED] =
|
|
|
|
|
g_signal_new ("properties-changed",
|
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (NMSysconfigSettingsClass, properties_changed),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
g_cclosure_marshal_VOID__BOXED,
|
|
|
|
|
G_TYPE_NONE, 1, DBUS_TYPE_G_MAP_OF_VARIANT);
|
|
|
|
|
|
|
|
|
|
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (settings_class),
|
|
|
|
|
&dbus_glib_nm_settings_system_object_info);
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2008-08-12 18:39:03 +00:00
|
|
|
dbus_g_error_domain_register (NM_SYSCONFIG_SETTINGS_ERROR,
|
|
|
|
|
NM_DBUS_IFACE_SETTINGS_SYSTEM,
|
|
|
|
|
NM_TYPE_SYSCONFIG_SETTINGS_ERROR);
|
2007-11-21 06:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-04-08 01:36:39 +00:00
|
|
|
nm_sysconfig_settings_init (NMSysconfigSettings *self)
|
2007-11-21 06:24:15 +00:00
|
|
|
{
|
2008-04-08 01:36:39 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2008-10-01 22:59:21 +00:00
|
|
|
char hostname[HOST_NAME_MAX + 2];
|
2009-04-04 11:37:11 -04:00
|
|
|
GError *error = NULL;
|
2008-04-08 01:36:39 +00:00
|
|
|
|
2008-05-07 09:48:12 +00:00
|
|
|
priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
|
2008-04-08 01:36:39 +00:00
|
|
|
priv->unmanaged_devices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2009-04-04 11:37:11 -04:00
|
|
|
priv->pol_ctx = create_polkit_context (&error);
|
|
|
|
|
if (!priv->pol_ctx) {
|
|
|
|
|
g_warning ("%s: failed to create PolicyKit context: %s",
|
|
|
|
|
__func__,
|
|
|
|
|
(error && error->message) ? error->message : "(unknown)");
|
|
|
|
|
}
|
2008-10-01 22:59:21 +00:00
|
|
|
|
|
|
|
|
/* Grab hostname on startup and use that if no plugins provide one */
|
|
|
|
|
memset (hostname, 0, sizeof (hostname));
|
|
|
|
|
if (gethostname (&hostname[0], HOST_NAME_MAX) == 0) {
|
|
|
|
|
/* only cache it if it's a valid hostname */
|
|
|
|
|
if (strlen (hostname) && strcmp (hostname, "localhost") && strcmp (hostname, "localhost.localdomain"))
|
|
|
|
|
priv->orig_hostname = g_strdup (hostname);
|
|
|
|
|
}
|
2007-11-21 06:24:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMSysconfigSettings *
|
2008-04-22 14:48:02 +00:00
|
|
|
nm_sysconfig_settings_new (DBusGConnection *g_conn, NMSystemConfigHalManager *hal_mgr)
|
2007-11-21 06:24:15 +00:00
|
|
|
{
|
|
|
|
|
NMSysconfigSettings *settings;
|
2008-04-22 14:48:02 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv;
|
2007-11-21 06:24:15 +00:00
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
g_return_val_if_fail (g_conn != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (hal_mgr != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
settings = g_object_new (NM_TYPE_SYSCONFIG_SETTINGS, NULL);
|
2007-11-21 06:24:15 +00:00
|
|
|
dbus_g_connection_register_g_object (g_conn, NM_DBUS_PATH_SETTINGS, G_OBJECT (settings));
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (settings);
|
|
|
|
|
priv->g_connection = dbus_g_connection_ref (g_conn);
|
|
|
|
|
priv->hal_mgr = g_object_ref (hal_mgr);
|
|
|
|
|
|
2007-11-21 06:24:15 +00:00
|
|
|
return settings;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
static void
|
|
|
|
|
plugin_connection_added (NMSystemConfigInterface *config,
|
2009-03-02 12:58:45 -05:00
|
|
|
NMExportedConnection *connection,
|
|
|
|
|
gpointer user_data)
|
2007-11-21 06:24:15 +00:00
|
|
|
{
|
2009-03-02 12:58:45 -05:00
|
|
|
nm_sysconfig_settings_add_connection (NM_SYSCONFIG_SETTINGS (user_data), connection, TRUE);
|
2007-11-27 19:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-04-22 14:48:02 +00:00
|
|
|
unmanaged_devices_changed (NMSystemConfigInterface *config,
|
|
|
|
|
gpointer user_data)
|
2007-11-27 19:25:46 +00:00
|
|
|
{
|
2008-04-22 14:48:02 +00:00
|
|
|
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (user_data);
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2007-11-27 19:25:46 +00:00
|
|
|
GSList *iter;
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
g_hash_table_remove_all (priv->unmanaged_devices);
|
2007-11-27 19:25:46 +00:00
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
/* Ask all the plugins for their unmanaged devices */
|
|
|
|
|
for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
|
|
|
|
|
GSList *udis = nm_system_config_interface_get_unmanaged_devices (NM_SYSTEM_CONFIG_INTERFACE (iter->data));
|
|
|
|
|
GSList *udi_iter;
|
|
|
|
|
|
|
|
|
|
for (udi_iter = udis; udi_iter; udi_iter = udi_iter->next) {
|
|
|
|
|
if (!g_hash_table_lookup (priv->unmanaged_devices, udi_iter->data)) {
|
|
|
|
|
g_hash_table_insert (priv->unmanaged_devices,
|
|
|
|
|
udi_iter->data,
|
|
|
|
|
GUINT_TO_POINTER (1));
|
|
|
|
|
} else
|
|
|
|
|
g_free (udi_iter->data);
|
2007-11-27 19:25:46 +00:00
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
g_slist_free (udis);
|
2007-11-27 19:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_notify (G_OBJECT (self), NM_SYSCONFIG_SETTINGS_UNMANAGED_DEVICES);
|
2007-11-21 06:24:15 +00:00
|
|
|
}
|
2007-11-27 19:25:46 +00:00
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
static void
|
|
|
|
|
hostname_changed (NMSystemConfigInterface *config,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
g_object_notify (G_OBJECT (user_data), NM_SYSCONFIG_SETTINGS_HOSTNAME);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-27 19:25:46 +00:00
|
|
|
void
|
2008-04-22 14:48:02 +00:00
|
|
|
nm_sysconfig_settings_add_plugin (NMSysconfigSettings *self,
|
|
|
|
|
NMSystemConfigInterface *plugin)
|
2007-11-27 19:25:46 +00:00
|
|
|
{
|
2008-04-08 01:36:39 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv;
|
2008-04-22 14:48:02 +00:00
|
|
|
char *pname = NULL;
|
|
|
|
|
char *pinfo = NULL;
|
2007-11-27 19:25:46 +00:00
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self));
|
2008-04-22 14:48:02 +00:00
|
|
|
g_return_if_fail (NM_IS_SYSTEM_CONFIG_INTERFACE (plugin));
|
2007-11-27 19:25:46 +00:00
|
|
|
|
2008-04-08 01:36:39 +00:00
|
|
|
priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2008-02-20 22:37:39 +00:00
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
priv->plugins = g_slist_append (priv->plugins, g_object_ref (plugin));
|
|
|
|
|
|
|
|
|
|
g_signal_connect (plugin, "connection-added", G_CALLBACK (plugin_connection_added), self);
|
|
|
|
|
g_signal_connect (plugin, "unmanaged-devices-changed", G_CALLBACK (unmanaged_devices_changed), self);
|
2008-09-18 14:46:57 +00:00
|
|
|
g_signal_connect (plugin, "notify::hostname", G_CALLBACK (hostname_changed), self);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
nm_system_config_interface_init (plugin, priv->hal_mgr);
|
|
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (plugin),
|
|
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_NAME, &pname,
|
2008-10-01 22:31:53 +00:00
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_INFO, &pinfo,
|
2008-04-22 14:48:02 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
g_message ("Loaded plugin %s: %s", pname, pinfo);
|
|
|
|
|
g_free (pname);
|
|
|
|
|
g_free (pinfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-05-07 09:48:12 +00:00
|
|
|
connection_removed (NMExportedConnection *connection,
|
2008-04-22 14:48:02 +00:00
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (user_data);
|
|
|
|
|
|
2008-05-07 09:48:12 +00:00
|
|
|
g_hash_table_remove (priv->connections, connection);
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
nm_sysconfig_settings_add_connection (NMSysconfigSettings *self,
|
2009-03-02 12:58:45 -05:00
|
|
|
NMExportedConnection *connection,
|
|
|
|
|
gboolean do_export)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self));
|
2008-05-07 09:48:12 +00:00
|
|
|
g_return_if_fail (NM_IS_EXPORTED_CONNECTION (connection));
|
2007-11-27 19:25:46 +00:00
|
|
|
|
2008-05-08 07:20:02 +00:00
|
|
|
if (g_hash_table_lookup (priv->connections, connection))
|
|
|
|
|
/* A plugin is lying to us. */
|
2007-11-27 19:25:46 +00:00
|
|
|
return;
|
|
|
|
|
|
2008-05-08 07:20:02 +00:00
|
|
|
g_hash_table_insert (priv->connections, g_object_ref (connection), GINT_TO_POINTER (1));
|
2008-05-07 09:48:12 +00:00
|
|
|
g_signal_connect (connection, "removed", G_CALLBACK (connection_removed), self);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2009-03-02 12:58:45 -05:00
|
|
|
if (do_export) {
|
|
|
|
|
nm_exported_connection_register_object (connection, NM_CONNECTION_SCOPE_SYSTEM, priv->g_connection);
|
|
|
|
|
nm_settings_signal_new_connection (NM_SETTINGS (self), connection);
|
|
|
|
|
}
|
2007-11-27 19:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
void
|
|
|
|
|
nm_sysconfig_settings_remove_connection (NMSysconfigSettings *self,
|
2009-03-02 12:58:45 -05:00
|
|
|
NMExportedConnection *connection,
|
|
|
|
|
gboolean do_signal)
|
2008-04-08 01:36:39 +00:00
|
|
|
{
|
2008-05-07 09:48:12 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2008-04-08 01:36:39 +00:00
|
|
|
|
|
|
|
|
g_return_if_fail (NM_IS_SYSCONFIG_SETTINGS (self));
|
2008-05-07 09:48:12 +00:00
|
|
|
g_return_if_fail (NM_IS_EXPORTED_CONNECTION (connection));
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-05-07 09:48:12 +00:00
|
|
|
if (g_hash_table_lookup (priv->connections, connection)) {
|
|
|
|
|
nm_exported_connection_signal_removed (connection);
|
|
|
|
|
g_hash_table_remove (priv->connections, connection);
|
2008-04-08 01:36:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-08 14:57:17 +00:00
|
|
|
gboolean
|
|
|
|
|
nm_sysconfig_settings_is_device_managed (NMSysconfigSettings *self,
|
|
|
|
|
const char *udi)
|
|
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (NM_IS_SYSCONFIG_SETTINGS (self), FALSE);
|
|
|
|
|
|
|
|
|
|
priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2008-05-11 20:20:52 +00:00
|
|
|
|
|
|
|
|
load_connections (self);
|
|
|
|
|
|
2008-04-08 14:57:17 +00:00
|
|
|
if (g_hash_table_lookup (priv->unmanaged_devices, udi))
|
|
|
|
|
return FALSE;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-02 12:58:45 -05:00
|
|
|
gboolean
|
|
|
|
|
nm_sysconfig_settings_add_new_connection (NMSysconfigSettings *self,
|
|
|
|
|
GHashTable *hash,
|
|
|
|
|
GError **error)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
2008-05-09 06:33:30 +00:00
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
2008-04-22 14:48:02 +00:00
|
|
|
NMConnection *connection;
|
2009-03-02 12:58:45 -05:00
|
|
|
GError *tmp_error = NULL, *last_error = NULL;
|
2008-07-16 07:37:10 +00:00
|
|
|
GSList *iter;
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
gboolean success = FALSE;
|
2008-05-09 06:33:30 +00:00
|
|
|
|
2009-03-02 12:58:45 -05:00
|
|
|
connection = nm_connection_new_from_hash (hash, &tmp_error);
|
|
|
|
|
if (!connection) {
|
|
|
|
|
/* Invalid connection hash */
|
|
|
|
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
|
|
|
|
"Invalid connection: '%s' / '%s' invalid: %d",
|
|
|
|
|
tmp_error ? g_type_name (nm_connection_lookup_setting_type_by_quark (tmp_error->domain)) : "(unknown)",
|
|
|
|
|
tmp_error ? tmp_error->message : "(unknown)", tmp_error ? tmp_error->code : -1);
|
|
|
|
|
g_clear_error (&tmp_error);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Here's how it works:
|
|
|
|
|
1) plugin writes a connection.
|
|
|
|
|
2) plugin notices that a new connection is available for reading.
|
|
|
|
|
3) plugin reads the new connection (the one it wrote in 1) and emits 'connection-added' signal.
|
|
|
|
|
4) NMSysconfigSettings receives the signal and adds it to it's connection list.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (iter = priv->plugins; iter && !success; iter = iter->next) {
|
|
|
|
|
success = nm_system_config_interface_add_connection (NM_SYSTEM_CONFIG_INTERFACE (iter->data),
|
|
|
|
|
connection, &tmp_error);
|
|
|
|
|
g_clear_error (&last_error);
|
|
|
|
|
if (!success)
|
|
|
|
|
last_error = tmp_error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (connection);
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
g_set_error (error, NM_SYSCONFIG_SETTINGS_ERROR,
|
|
|
|
|
NM_SYSCONFIG_SETTINGS_ERROR_ADD_FAILED,
|
|
|
|
|
"Saving connection failed: (%d) %s",
|
|
|
|
|
last_error ? last_error->code : -1,
|
|
|
|
|
last_error && last_error->message ? last_error->message : "(unknown)");
|
|
|
|
|
g_clear_error (&last_error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
impl_settings_add_connection (NMSysconfigSettings *self,
|
|
|
|
|
GHashTable *hash,
|
|
|
|
|
DBusGMethodInvocation *context)
|
|
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GError *err = NULL;
|
|
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
/* Do any of the plugins support adding? */
|
2009-03-02 12:58:45 -05:00
|
|
|
if (!nm_sysconfig_settings_get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS)) {
|
2008-07-16 07:37:10 +00:00
|
|
|
err = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR,
|
|
|
|
|
NM_SYSCONFIG_SETTINGS_ERROR_ADD_NOT_SUPPORTED,
|
|
|
|
|
"%s", "None of the registered plugins support add.");
|
|
|
|
|
goto out;
|
2008-05-09 06:33:30 +00:00
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-07-16 07:37:10 +00:00
|
|
|
if (!check_polkit_privileges (priv->g_connection, priv->pol_ctx, context, &err))
|
|
|
|
|
goto out;
|
|
|
|
|
|
2009-03-02 12:58:45 -05:00
|
|
|
nm_sysconfig_settings_add_new_connection (self, hash, &err);
|
2008-07-16 07:37:10 +00:00
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (err) {
|
2008-05-09 06:33:30 +00:00
|
|
|
dbus_g_method_return_error (context, err);
|
|
|
|
|
g_error_free (err);
|
2008-04-22 14:48:02 +00:00
|
|
|
return FALSE;
|
2008-07-16 07:37:10 +00:00
|
|
|
} else {
|
|
|
|
|
dbus_g_method_return (context);
|
|
|
|
|
return TRUE;
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-08-12 18:39:03 +00:00
|
|
|
|
2008-09-18 14:46:57 +00:00
|
|
|
static gboolean
|
|
|
|
|
impl_settings_save_hostname (NMSysconfigSettings *self,
|
|
|
|
|
const char *hostname,
|
|
|
|
|
DBusGMethodInvocation *context)
|
|
|
|
|
{
|
|
|
|
|
NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
|
|
|
|
|
GError *err = NULL;
|
|
|
|
|
GSList *iter;
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
gboolean success = FALSE;
|
2008-09-18 14:46:57 +00:00
|
|
|
|
|
|
|
|
/* Do any of the plugins support setting the hostname? */
|
2009-03-02 12:58:45 -05:00
|
|
|
if (!nm_sysconfig_settings_get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME)) {
|
2008-09-18 14:46:57 +00:00
|
|
|
err = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR,
|
|
|
|
|
NM_SYSCONFIG_SETTINGS_ERROR_SAVE_HOSTNAME_NOT_SUPPORTED,
|
|
|
|
|
"%s", "None of the registered plugins support setting the hostname.");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!check_polkit_privileges (priv->g_connection, priv->pol_ctx, context, &err))
|
|
|
|
|
goto out;
|
|
|
|
|
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
/* Set the hostname in all plugins */
|
|
|
|
|
for (iter = priv->plugins; iter; iter = iter->next) {
|
2008-09-18 14:46:57 +00:00
|
|
|
NMSystemConfigInterfaceCapabilities caps = NM_SYSTEM_CONFIG_INTERFACE_CAP_NONE;
|
|
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (iter->data), NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES, &caps, NULL);
|
|
|
|
|
if (caps & NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME) {
|
|
|
|
|
g_object_set (G_OBJECT (iter->data), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME, hostname, NULL);
|
|
|
|
|
success = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
err = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR,
|
|
|
|
|
NM_SYSCONFIG_SETTINGS_ERROR_SAVE_HOSTNAME_FAILED,
|
|
|
|
|
"%s", "Saving the hostname failed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (err) {
|
|
|
|
|
dbus_g_method_return_error (context, err);
|
|
|
|
|
g_error_free (err);
|
|
|
|
|
return FALSE;
|
|
|
|
|
} else {
|
|
|
|
|
dbus_g_method_return (context);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|