NetworkManager r3941 - in trunk: . introspection system-settings/plugins/ifcfg-fedora system-settings/plugins/ifcfg-suse system-settings/plugins/keyfile system-settings/src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: NetworkManager r3941 - in trunk: . introspection system-settings/plugins/ifcfg-fedora system-settings/plugins/ifcfg-suse system-settings/plugins/keyfile system-settings/src
- Date: Tue, 12 Aug 2008 18:39:03 +0000 (UTC)
Author: dcbw
Date: Tue Aug 12 18:39:03 2008
New Revision: 3941
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3941&view=rev
Log:
2008-08-12 Dan Williams <dcbw redhat com>
* introspection/nm-settings-system.xml
system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- Add a 'Hostname' property (rw) which represents the configured
hostname and domain of the system, if any
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Add a 'hostname' property to the plugin interface
- Add a method to send updated hostname to plugins to save in their
backing configuration store
* system-settings/plugins/keyfile/nm-keyfile-connection.c
system-settings/plugins/keyfile/plugin.c
system-settings/plugins/keyfile/writer.c
system-settings/plugins/keyfile/writer.h
system-settings/plugins/ifcfg-suse/plugin.c
- Add minimal hostname support
* system-settings/plugins/ifcfg-fedora/plugin.c
- Add support for updating system hostname in /etc/sysconfig/network
Modified:
trunk/ChangeLog
trunk/introspection/nm-settings-system.xml
trunk/system-settings/plugins/ifcfg-fedora/plugin.c
trunk/system-settings/plugins/ifcfg-suse/plugin.c
trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c
trunk/system-settings/plugins/keyfile/plugin.c
trunk/system-settings/plugins/keyfile/writer.c
trunk/system-settings/plugins/keyfile/writer.h
trunk/system-settings/src/dbus-settings.c
trunk/system-settings/src/dbus-settings.h
trunk/system-settings/src/nm-system-config-error.c
trunk/system-settings/src/nm-system-config-error.h
trunk/system-settings/src/nm-system-config-interface.c
trunk/system-settings/src/nm-system-config-interface.h
Modified: trunk/introspection/nm-settings-system.xml
==============================================================================
--- trunk/introspection/nm-settings-system.xml (original)
+++ trunk/introspection/nm-settings-system.xml Tue Aug 12 18:39:03 2008
@@ -8,14 +8,27 @@
<method name="AddConnection">
<tp:docstring>
- Add new connection.
+ Add new connection.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_add_connection"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="connection" type="a{sa{sv}}" direction="in">
- <tp:docstring>
- Connection properties.
- </tp:docstring>
+ <tp:docstring>
+ Connection properties.
+ </tp:docstring>
+ </arg>
+ </method>
+
+ <method name="SetHostname">
+ <tp:docstring>
+ Sets the configured machine hostname and domain.
+ </tp:docstring>
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_set_hostname"/>
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="hostname" type="s" direction="in">
+ <tp:docstring>
+ Fully-qualified hostname to set in configuration. To clear hostname, pass a zero-length string. Example: "mycomputer.foobar.com"
+ </tp:docstring>
</arg>
</method>
@@ -25,6 +38,12 @@
</tp:docstring>
</property>
+ <property name="Hostname" type="s" access="readwrite">
+ <tp:docstring>
+ The configured hostname of the machine.
+ </tp:docstring>
+ </property>
+
<signal name="PropertiesChanged">
<arg name="properties" type="a{sv}" tp:type="String_Variant_Map">
<tp:docstring>
Modified: trunk/system-settings/plugins/ifcfg-fedora/plugin.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-fedora/plugin.c (original)
+++ trunk/system-settings/plugins/ifcfg-fedora/plugin.c Tue Aug 12 18:39:03 2008
@@ -44,8 +44,10 @@
#include "plugin.h"
#include "nm-system-config-interface.h"
#include "nm-ifcfg-connection.h"
+#include "shvar.h"
#define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts/"
+#define NETWORK_FILE SYSCONFDIR"/sysconfig/network"
static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
@@ -73,9 +75,13 @@
NMSystemConfigHalManager *hal_mgr;
GHashTable *connections;
+ char *hostname;
- GFileMonitor *monitor;
- guint monitor_id;
+ GFileMonitor *ifcfg_monitor;
+ guint ifcfg_monitor_id;
+
+ GFileMonitor *network_monitor;
+ guint network_monitor_id;
} SCPluginIfcfgPrivate;
@@ -417,21 +423,119 @@
}
static void
+read_hostname (SCPluginIfcfg *plugin, gboolean notify)
+{
+ SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
+ shvarFile *network;
+ char *new_hostname;
+ gboolean changed = FALSE;
+
+ network = svNewFile (NETWORK_FILE);
+ if (!network)
+ return;
+
+ new_hostname = svGetValue (network, "HOSTNAME");
+ if (new_hostname && strlen (new_hostname)) {
+ g_free (priv->hostname);
+ priv->hostname = new_hostname;
+ changed = TRUE;
+ } else
+ g_free (new_hostname);
+ svCloseFile (network);
+
+ if (changed) {
+ PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "system hostname '%s'.", priv->hostname);
+ if (notify)
+ g_object_notify (G_OBJECT (plugin), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
+ }
+}
+
+static gboolean
+write_hostname (SCPluginIfcfg *plugin, const char *hostname, GError **error)
+{
+ shvarFile *network;
+ gboolean success = FALSE;
+
+ network = svNewFile (NETWORK_FILE);
+ if (!network) {
+ /* May not be created; try to create it */
+ network = svCreateFile (NETWORK_FILE);
+ if (!network)
+ return FALSE;
+ }
+
+ svSetValue (network, "HOSTNAME", hostname);
+ if (svWriteFile (network, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) == 0)
+ success = TRUE;
+
+ svCloseFile (network);
+ return success;
+}
+
+static void
+network_changed (GFileMonitor *monitor,
+ GFile *file,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
+{
+ SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (user_data);
+ SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
+
+ switch (event_type) {
+ case G_FILE_MONITOR_EVENT_DELETED:
+ PLUGIN_PRINT (IFCFG_PLUGIN_NAME, "system hostname cleared.");
+ g_free (priv->hostname);
+ priv->hostname = NULL;
+ g_object_notify (G_OBJECT (plugin), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
+ break;
+ case G_FILE_MONITOR_EVENT_CREATED:
+ case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
+ read_hostname (plugin, TRUE);
+ break;
+ default:
+ break;
+ }
+}
+
+static void
setup_monitoring (SCPluginIfcfg *plugin)
{
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
GFile *file;
GFileMonitor *monitor;
+ GError *error = NULL;
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
+ /* monitor the ifcfg file directory */
file = g_file_new_for_path (IFCFG_DIR);
- monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
+ monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, &error);
+ g_object_unref (file);
+
+ if (monitor) {
+ priv->ifcfg_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (dir_changed), plugin);
+ priv->ifcfg_monitor = monitor;
+ } else {
+ PLUGIN_WARN (IFCFG_PLUGIN_NAME, "unable to monitor %s for changes: (%d) %s.",
+ IFCFG_DIR, error->code, error->message);
+ g_error_free (error);
+ error = NULL;
+ }
+
+ /* monitor the 'network' file */
+ file = g_file_new_for_path (NETWORK_FILE);
+ monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
g_object_unref (file);
if (monitor) {
- priv->monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (dir_changed), plugin);
- priv->monitor = monitor;
+ priv->network_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (network_changed), plugin);
+ priv->network_monitor = monitor;
+ } else {
+ PLUGIN_WARN (IFCFG_PLUGIN_NAME, "unable to monitor %s for changes: (%d) %s.",
+ NETWORK_FILE, error->code, error->message);
+ g_error_free (error);
+ error = NULL;
}
}
@@ -462,6 +566,12 @@
return list;
}
+static gboolean
+set_hostname (NMSystemConfigInterface *config, const char *hostname, GError **error)
+{
+ return write_hostname (SC_PLUGIN_IFCFG (config), hostname, error);
+}
+
static void
init (NMSystemConfigInterface *config, NMSystemConfigHalManager *hal_manager)
{
@@ -483,6 +593,8 @@
error->message ? error->message : "(unknown)");
g_error_free (error);
}
+
+ read_hostname (plugin, FALSE);
}
static void
@@ -499,12 +611,22 @@
if (priv->connections)
g_hash_table_destroy (priv->connections);
- if (priv->monitor) {
- if (priv->monitor_id)
- g_signal_handler_disconnect (priv->monitor, priv->monitor_id);
+ g_free (priv->hostname);
+
+ if (priv->ifcfg_monitor) {
+ if (priv->ifcfg_monitor_id)
+ g_signal_handler_disconnect (priv->ifcfg_monitor, priv->ifcfg_monitor_id);
- g_file_monitor_cancel (priv->monitor);
- g_object_unref (priv->monitor);
+ g_file_monitor_cancel (priv->ifcfg_monitor);
+ g_object_unref (priv->ifcfg_monitor);
+ }
+
+ if (priv->network_monitor) {
+ if (priv->network_monitor_id)
+ g_signal_handler_disconnect (priv->network_monitor, priv->network_monitor_id);
+
+ g_file_monitor_cancel (priv->network_monitor);
+ g_object_unref (priv->network_monitor);
}
G_OBJECT_CLASS (sc_plugin_ifcfg_parent_class)->dispose (object);
@@ -520,6 +642,9 @@
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
+ SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (object);
+ SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
+
switch (prop_id) {
case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME:
g_value_set_string (value, IFCFG_PLUGIN_NAME);
@@ -527,6 +652,31 @@
case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO:
g_value_set_string (value, IFCFG_PLUGIN_INFO);
break;
+ case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
+ g_value_set_string (value, priv->hostname);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (object);
+ GError *error = NULL;
+
+ switch (prop_id) {
+ case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
+ if (!write_hostname (plugin, g_value_get_string (value), &error)) {
+ PLUGIN_WARN (IFCFG_PLUGIN_NAME, "Could not save hostname: %s",
+ (error && error->message) ? error->message : "(unknown)");
+ if (error)
+ g_error_free (error);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -543,6 +693,7 @@
object_class->dispose = dispose;
object_class->finalize = finalize;
object_class->get_property = get_property;
+ object_class->set_property = set_property;
g_object_class_override_property (object_class,
NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME,
@@ -551,6 +702,10 @@
g_object_class_override_property (object_class,
NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO,
NM_SYSTEM_CONFIG_INTERFACE_INFO);
+
+ g_object_class_override_property (object_class,
+ NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME,
+ NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
}
static void
@@ -559,6 +714,7 @@
/* interface implementation */
system_config_interface_class->get_connections = get_connections;
system_config_interface_class->get_unmanaged_devices = get_unmanaged_devices;
+ system_config_interface_class->set_hostname = set_hostname;
system_config_interface_class->init = init;
}
Modified: trunk/system-settings/plugins/ifcfg-suse/plugin.c
==============================================================================
--- trunk/system-settings/plugins/ifcfg-suse/plugin.c (original)
+++ trunk/system-settings/plugins/ifcfg-suse/plugin.c Tue Aug 12 18:39:03 2008
@@ -65,6 +65,7 @@
gboolean initialized;
GHashTable *connections;
GHashTable *unmanaged_devices;
+ char *hostname;
guint32 default_gw;
GFileMonitor *default_gw_monitor;
@@ -351,6 +352,7 @@
g_hash_table_destroy (priv->connections);
g_hash_table_destroy (priv->unmanaged_devices);
+ g_free (priv->hostname);
if (priv->default_gw_monitor) {
if (priv->default_gw_monitor_id)
@@ -372,6 +374,8 @@
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
+ SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (object);
+
switch (prop_id) {
case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME:
g_value_set_string (value, IFCFG_PLUGIN_NAME);
@@ -379,6 +383,20 @@
case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO:
g_value_set_string (value, IFCFG_PLUGIN_INFO);
break;
+ case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
+ g_value_set_string (value, priv->hostname);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -393,6 +411,7 @@
g_type_class_add_private (req_class, sizeof (SCPluginIfcfgPrivate));
object_class->get_property = get_property;
+ object_class->set_property = set_property;
object_class->dispose = dispose;
g_object_class_override_property (object_class,
@@ -402,6 +421,10 @@
g_object_class_override_property (object_class,
NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO,
NM_SYSTEM_CONFIG_INTERFACE_INFO);
+
+ g_object_class_override_property (object_class,
+ NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME,
+ NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
}
static void
Modified: trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c (original)
+++ trunk/system-settings/plugins/keyfile/nm-keyfile-connection.c Tue Aug 12 18:39:03 2008
@@ -55,14 +55,13 @@
static gboolean
update (NMExportedConnection *exported,
GHashTable *new_settings,
- GError **err)
+ GError **error)
{
gboolean success;
- success = NM_EXPORTED_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->update (exported, new_settings, err);
-
+ success = NM_EXPORTED_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->update (exported, new_settings, error);
if (success)
- write_connection (nm_exported_connection_get_connection (exported));
+ success = write_connection (nm_exported_connection_get_connection (exported), error);
return success;
}
Modified: trunk/system-settings/plugins/keyfile/plugin.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/plugin.c (original)
+++ trunk/system-settings/plugins/keyfile/plugin.c Tue Aug 12 18:39:03 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#include <config.h>
#include <sys/stat.h>
@@ -36,6 +36,8 @@
typedef struct {
GHashTable *hash;
+ char *hostname;
+
GFileMonitor *monitor;
guint monitor_id;
@@ -182,9 +184,11 @@
}
static gboolean
-add_connection (NMSystemConfigInterface *config, NMConnection *connection)
+add_connection (NMSystemConfigInterface *config,
+ NMConnection *connection,
+ GError **error)
{
- return write_connection (connection);
+ return write_connection (connection, error);
}
/* GObject */
@@ -198,6 +202,8 @@
get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
+ SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (object);
+
switch (prop_id) {
case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME:
g_value_set_string (value, KEYFILE_PLUGIN_NAME);
@@ -205,6 +211,20 @@
case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO:
g_value_set_string (value, KEYFILE_PLUGIN_INFO);
break;
+ case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
+ g_value_set_string (value, priv->hostname);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ switch (prop_id) {
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -232,6 +252,8 @@
if (priv->hash)
g_hash_table_destroy (priv->hash);
+ g_free (priv->hostname);
+
G_OBJECT_CLASS (sc_plugin_keyfile_parent_class)->dispose (object);
}
@@ -244,6 +266,7 @@
object_class->dispose = dispose;
object_class->get_property = get_property;
+ object_class->set_property = set_property;
g_object_class_override_property (object_class,
NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME,
@@ -252,6 +275,10 @@
g_object_class_override_property (object_class,
NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO,
NM_SYSTEM_CONFIG_INTERFACE_INFO);
+
+ g_object_class_override_property (object_class,
+ NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME,
+ NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
}
static void
Modified: trunk/system-settings/plugins/keyfile/writer.c
==============================================================================
--- trunk/system-settings/plugins/keyfile/writer.c (original)
+++ trunk/system-settings/plugins/keyfile/writer.c Tue Aug 12 18:39:03 2008
@@ -264,7 +264,7 @@
}
gboolean
-write_connection (NMConnection *connection)
+write_connection (NMConnection *connection, GError **error)
{
NMSettingConnection *s_con;
GKeyFile *key_file;
Modified: trunk/system-settings/plugins/keyfile/writer.h
==============================================================================
--- trunk/system-settings/plugins/keyfile/writer.h (original)
+++ trunk/system-settings/plugins/keyfile/writer.h Tue Aug 12 18:39:03 2008
@@ -6,6 +6,6 @@
#include <glib.h>
#include <nm-connection.h>
-gboolean write_connection (NMConnection *connection);
+gboolean write_connection (NMConnection *connection, GError **error);
#endif /* _KEYFILE_PLUGIN_WRITER_H */
Modified: trunk/system-settings/src/dbus-settings.c
==============================================================================
--- trunk/system-settings/src/dbus-settings.c (original)
+++ trunk/system-settings/src/dbus-settings.c Tue Aug 12 18:39:03 2008
@@ -1,8 +1,10 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager system settings service
*
* SÃren Sandmann <sandmann daimi au dk>
+ * Dan Williams <dcbw redhat com>
+ * Tambet Ingo <tambet gmail com>
*
* 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
@@ -18,7 +20,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * (C) Copyright 2007 Red Hat, Inc.
+ * (C) Copyright 2007 - 2008 Red Hat, Inc.
+ * (C) Copyright 2008 Novell, Inc.
*/
#include <NetworkManager.h>
@@ -36,6 +39,9 @@
static gboolean
impl_settings_add_connection (NMSysconfigSettings *self, GHashTable *hash, DBusGMethodInvocation *context);
+static gboolean
+impl_settings_set_hostname (NMSysconfigSettings *self, const char *hostname, DBusGMethodInvocation *context);
+
#include "nm-settings-system-glue.h"
static void unmanaged_devices_changed (NMSystemConfigInterface *config, gpointer user_data);
@@ -49,6 +55,8 @@
gboolean connections_loaded;
GHashTable *connections;
GHashTable *unmanaged_devices;
+
+ char *hostname;
} NMSysconfigSettingsPrivate;
G_DEFINE_TYPE (NMSysconfigSettings, nm_sysconfig_settings, NM_TYPE_SETTINGS);
@@ -66,6 +74,7 @@
enum {
PROP_0,
PROP_UNMANAGED_DEVICES,
+ PROP_HOSTNAME,
LAST_PROP
};
@@ -94,6 +103,16 @@
nm_sysconfig_settings_add_connection (self, NM_EXPORTED_CONNECTION (elt->data));
g_slist_free (plugin_connections);
+
+ /* Update hostname */
+ if (!priv->hostname) {
+ const char *hostname = NULL;
+
+ g_object_get (G_OBJECT (plugin),
+ NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME, &hostname,
+ NULL);
+ priv->hostname = g_strdup (hostname);
+ }
}
/* FIXME: Bad hack */
@@ -136,6 +155,8 @@
g_slist_foreach (priv->plugins, (GFunc) g_object_unref, NULL);
g_slist_free (priv->plugins);
+ g_free (priv->hostname);
+
if (priv->pol_ctx)
polkit_context_unref (priv->pol_ctx);
@@ -211,16 +232,88 @@
return devices;
}
+static gboolean
+write_hostname_to_plugins (NMSysconfigSettings *self,
+ const char *hostname,
+ GError **error)
+{
+ NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
+ GSList *iter;
+ gboolean success = FALSE;
+ const char *real_new_hostname = NULL;
+
+ if (hostname && strlen (hostname))
+ real_new_hostname = hostname;
+
+ /* Try to update the hostname in all plugins */
+ for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
+ NMSystemConfigInterface *plugin = NM_SYSTEM_CONFIG_INTERFACE (iter->data);
+ GError *plugin_error = NULL;
+
+ if (nm_system_config_interface_set_hostname (plugin, real_new_hostname, &plugin_error))
+ success = TRUE;
+ else {
+ char *plugin_name = NULL;
+
+ g_object_get (G_OBJECT (plugin),
+ NM_SYSTEM_CONFIG_INTERFACE_NAME, &plugin_name,
+ NULL);
+ g_warning ("Error: plugin '%s' could not set hostname: (%d) %s",
+ plugin_name ? plugin_name : "unknown",
+ plugin_error ? plugin_error->code : 0,
+ plugin_error ? plugin_error->message : "unknown error");
+ g_free (plugin_name);
+ if (plugin_error)
+ g_error_free (plugin_error);
+ }
+ }
+
+ if (!success) {
+ g_set_error (error,
+ NM_SYSCONFIG_SETTINGS_ERROR,
+ NM_SYSCONFIG_SETTINGS_ERROR_SET_HOSTNAME_FAILED,
+ "%s",
+ "None of the registered plugins could set the requested hostname.");
+ }
+
+ return success;
+}
+
static void
get_property (GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
+ GValue *value, GParamSpec *pspec)
{
NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object);
+ NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
switch (prop_id) {
case PROP_UNMANAGED_DEVICES:
g_value_take_boxed (value, get_unmanaged_devices (self));
break;
+ case PROP_HOSTNAME:
+ g_value_set_string (value, priv->hostname);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (object);
+ GError *error = NULL;
+
+ switch (prop_id) {
+ case PROP_HOSTNAME:
+ if (!write_hostname_to_plugins (self, g_value_get_string (value), &error)) {
+ g_warning ("%s: could not set hostname: (%d) %s",
+ __func__, error->code, error->message);
+ g_error_free (error);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -238,6 +331,7 @@
/* virtual methods */
object_class->notify = notify;
object_class->get_property = get_property;
+ object_class->set_property = set_property;
object_class->finalize = settings_finalize;
settings_class->list_connections = list_connections;
@@ -250,6 +344,14 @@
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
G_PARAM_READABLE));
+ g_object_class_install_property
+ (object_class, PROP_HOSTNAME,
+ g_param_spec_string (NM_SYSCONFIG_SETTINGS_HOSTNAME,
+ "Hostname",
+ "Configured hostname",
+ NULL,
+ G_PARAM_READWRITE));
+
/* signals */
signals[PROPERTIES_CHANGED] =
g_signal_new ("properties-changed",
@@ -263,7 +365,9 @@
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (settings_class),
&dbus_glib_nm_settings_system_object_info);
- dbus_g_error_domain_register (NM_SYSCONFIG_SETTINGS_ERROR, NULL, NM_TYPE_SYSCONFIG_SETTINGS_ERROR);
+ dbus_g_error_domain_register (NM_SYSCONFIG_SETTINGS_ERROR,
+ NM_DBUS_IFACE_SETTINGS_SYSTEM,
+ NM_TYPE_SYSCONFIG_SETTINGS_ERROR);
}
static void
@@ -334,6 +438,41 @@
g_object_notify (G_OBJECT (self), NM_SYSCONFIG_SETTINGS_UNMANAGED_DEVICES);
}
+static void
+hostname_changed (NMSystemConfigInterface *config,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ NMSysconfigSettings *self = NM_SYSCONFIG_SETTINGS (user_data);
+ NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
+ gboolean changed = FALSE;
+ GSList *iter;
+
+ /* Ask each plugin for the hostname, use the highest-priority plugin's response */
+ for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
+ NMSystemConfigInterface *plugin = NM_SYSTEM_CONFIG_INTERFACE (iter->data);
+ char *new_hostname = NULL;
+
+ g_object_get (G_OBJECT (plugin),
+ NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME, &new_hostname,
+ NULL);
+ if (new_hostname && strlen (new_hostname)) {
+ if (g_utf8_validate (new_hostname, -1, NULL)) {
+ g_free (priv->hostname);
+ priv->hostname = g_strdup (new_hostname);
+ g_free (new_hostname);
+ changed = TRUE;
+ break;
+ } else
+ g_message ("Error: hostname '%s' not UTF-8, ignoring.", new_hostname);
+ }
+ g_free (new_hostname);
+ }
+
+ if (changed)
+ g_object_notify (G_OBJECT (self), NM_SYSCONFIG_SETTINGS_HOSTNAME);
+}
+
void
nm_sysconfig_settings_add_plugin (NMSysconfigSettings *self,
NMSystemConfigInterface *plugin)
@@ -351,6 +490,7 @@
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);
+ g_signal_connect (plugin, "notify::" NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME, G_CALLBACK (hostname_changed), self);
nm_system_config_interface_init (plugin, priv->hal_mgr);
@@ -453,6 +593,8 @@
connection = nm_connection_new_from_hash (hash, &cnfh_error);
if (connection) {
+ GError *add_error = NULL;
+
/* Here's how it works:
1) plugin writes a connection.
2) plugin notices that a new connection is available for reading.
@@ -461,9 +603,12 @@
*/
success = FALSE;
- for (iter = priv->plugins; iter && success == FALSE; iter = iter->next)
+ for (iter = priv->plugins; iter && success == FALSE; iter = iter->next) {
success = nm_system_config_interface_add_connection (NM_SYSTEM_CONFIG_INTERFACE (iter->data),
- connection);
+ connection, &add_error);
+ if (!success && add_error)
+ g_error_free (add_error);
+ }
g_object_unref (connection);
@@ -491,3 +636,57 @@
return TRUE;
}
}
+
+static gboolean
+impl_settings_set_hostname (NMSysconfigSettings *self,
+ const char *hostname,
+ DBusGMethodInvocation *context)
+{
+ NMSysconfigSettingsPrivate *priv = NM_SYSCONFIG_SETTINGS_GET_PRIVATE (self);
+ GError *error = NULL;
+ gboolean success = FALSE, malformed = FALSE;
+ const char *p = hostname;
+ guint32 count = 0;
+
+ /* do some minimal hostname validation:
+ * 1) must have at least two '.'
+ * 2) must not start with '.'
+ * 3) must not have two '.' in succession
+ */
+ do {
+ if (*p == '.') {
+ count++;
+ if (*(p+1) == '.') {
+ malformed = TRUE;
+ break;
+ }
+ }
+ } while (*p++);
+
+ if (count < 2 || malformed || (*hostname == '.')) {
+ error = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR,
+ NM_SYSCONFIG_SETTINGS_ERROR_INVALID_HOSTNAME,
+ "%s",
+ "The hostname was malformed or invalid.");
+ goto out;
+ }
+
+ if (check_polkit_privileges (priv->g_connection, priv->pol_ctx, context, &error))
+ success = write_hostname_to_plugins (self, hostname, &error);
+
+out:
+ if (success)
+ dbus_g_method_return (context);
+ else {
+ if (!error) {
+ error = g_error_new (NM_SYSCONFIG_SETTINGS_ERROR,
+ NM_SYSCONFIG_SETTINGS_ERROR_SET_HOSTNAME_FAILED,
+ "%s",
+ "Hostname could not be saved due to an unknown error.");
+ }
+ dbus_g_method_return_error (context, error);
+ g_error_free (error);
+ }
+
+ return success;
+}
Modified: trunk/system-settings/src/dbus-settings.h
==============================================================================
--- trunk/system-settings/src/dbus-settings.h (original)
+++ trunk/system-settings/src/dbus-settings.h Tue Aug 12 18:39:03 2008
@@ -39,6 +39,7 @@
#define NM_SYSCONFIG_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SYSCONFIG_SETTINGS, NMSysconfigSettingsClass))
#define NM_SYSCONFIG_SETTINGS_UNMANAGED_DEVICES "unmanaged-devices"
+#define NM_SYSCONFIG_SETTINGS_HOSTNAME "hostname"
struct _NMSysconfigSettings
{
Modified: trunk/system-settings/src/nm-system-config-error.c
==============================================================================
--- trunk/system-settings/src/nm-system-config-error.c (original)
+++ trunk/system-settings/src/nm-system-config-error.c Tue Aug 12 18:39:03 2008
@@ -29,6 +29,8 @@
ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_UPDATE_NOT_SUPPORTED, "UpdateNotSupported"),
ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_DELETE_NOT_SUPPORTED, "DeleteNotSupported"),
ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_ADD_FAILED, "AddFailed"),
+ ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_SET_HOSTNAME_FAILED, "SetHostnameFailed"),
+ ENUM_ENTRY (NM_SYSCONFIG_SETTINGS_ERROR_INVALID_HOSTNAME, "InvalidHostname"),
{ 0, 0, 0 }
};
Modified: trunk/system-settings/src/nm-system-config-error.h
==============================================================================
--- trunk/system-settings/src/nm-system-config-error.h (original)
+++ trunk/system-settings/src/nm-system-config-error.h Tue Aug 12 18:39:03 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
#ifndef NM_SYSTEM_CONFIG_ERROR_H
#define NM_SYSTEM_CONFIG_ERROR_H
@@ -13,7 +13,9 @@
NM_SYSCONFIG_SETTINGS_ERROR_ADD_NOT_SUPPORTED,
NM_SYSCONFIG_SETTINGS_ERROR_UPDATE_NOT_SUPPORTED,
NM_SYSCONFIG_SETTINGS_ERROR_DELETE_NOT_SUPPORTED,
- NM_SYSCONFIG_SETTINGS_ERROR_ADD_FAILED
+ NM_SYSCONFIG_SETTINGS_ERROR_ADD_FAILED,
+ NM_SYSCONFIG_SETTINGS_ERROR_SET_HOSTNAME_FAILED,
+ NM_SYSCONFIG_SETTINGS_ERROR_INVALID_HOSTNAME
};
#define NM_SYSCONFIG_SETTINGS_ERROR (nm_sysconfig_settings_error_quark ())
Modified: trunk/system-settings/src/nm-system-config-interface.c
==============================================================================
--- trunk/system-settings/src/nm-system-config-interface.c (original)
+++ trunk/system-settings/src/nm-system-config-interface.c Tue Aug 12 18:39:03 2008
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw redhat com>
@@ -48,6 +48,14 @@
NULL,
G_PARAM_READABLE));
+ g_object_interface_install_property
+ (g_iface,
+ g_param_spec_string (NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME,
+ "Hostname",
+ "Configured system hostname",
+ NULL,
+ G_PARAM_READWRITE));
+
/* Signals */
g_signal_new ("connection-added",
iface_type,
@@ -139,7 +147,8 @@
gboolean
nm_system_config_interface_add_connection (NMSystemConfigInterface *config,
- NMConnection *connection)
+ NMConnection *connection,
+ GError **error)
{
gboolean success = FALSE;
@@ -147,7 +156,23 @@
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
if (NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->add_connection)
- success = NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->add_connection (config, connection);
+ success = NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->add_connection (config, connection, error);
return success;
}
+
+gboolean
+nm_system_config_interface_set_hostname (NMSystemConfigInterface *config,
+ const char *hostname,
+ GError **error)
+{
+ gboolean success = FALSE;
+
+ g_return_val_if_fail (config != NULL, FALSE);
+
+ if (NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->set_hostname)
+ success = NM_SYSTEM_CONFIG_INTERFACE_GET_INTERFACE (config)->set_hostname (config, hostname, error);
+
+ return success;
+}
+
Modified: trunk/system-settings/src/nm-system-config-interface.h
==============================================================================
--- trunk/system-settings/src/nm-system-config-interface.h (original)
+++ trunk/system-settings/src/nm-system-config-interface.h Tue Aug 12 18:39:03 2008
@@ -60,12 +60,14 @@
#define NM_SYSTEM_CONFIG_INTERFACE_NAME "name"
#define NM_SYSTEM_CONFIG_INTERFACE_INFO "info"
+#define NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME "hostname"
typedef enum {
NM_SYSTEM_CONFIG_INTERFACE_PROP_FIRST = 0x1000,
NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME = NM_SYSTEM_CONFIG_INTERFACE_PROP_FIRST,
NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO,
+ NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME,
} NMSystemConfigInterfaceProp;
@@ -92,7 +94,13 @@
/*
* Add a new connection.
*/
- gboolean (*add_connection) (NMSystemConfigInterface *config, NMConnection *connection);
+ gboolean (*add_connection) (NMSystemConfigInterface *config, NMConnection *connection, GError **error);
+
+ /*
+ * Set the configured hostname/domain in the plugin's backing configuration store.
+ * Should _NOT_ call sethostname(2) or setdomainname(2).
+ */
+ gboolean (*set_hostname) (NMSystemConfigInterface *config, const char *hostname, GError **error);
/* Signals */
@@ -115,7 +123,12 @@
gboolean nm_system_config_interface_supports_add (NMSystemConfigInterface *config);
gboolean nm_system_config_interface_add_connection (NMSystemConfigInterface *config,
- NMConnection *connection);
+ NMConnection *connection,
+ GError **error);
+
+gboolean nm_system_config_interface_set_hostname (NMSystemConfigInterface *config,
+ const char *hostname,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]