mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-23 17:50:31 +01:00
2008-08-12 Dan Williams <dcbw@redhat.com>
Revert most of the 'hostname' patch. Too much stuff still breaks when hostname is updated at runtime. Distros or users who want hostname updates can use dispatcher scripts to update the hostname if they need it. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3945 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
751fe86da8
commit
5611f4c4d0
11 changed files with 19 additions and 463 deletions
|
|
@ -1,3 +1,9 @@
|
|||
2008-08-12 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
Revert most of the 'hostname' patch. Too much stuff still breaks when
|
||||
hostname is updated at runtime. Distros or users who want hostname updates
|
||||
can use dispatcher scripts to update the hostname if they need it.
|
||||
|
||||
2008-08-12 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* introspection/nm-settings-system.xml
|
||||
|
|
|
|||
|
|
@ -19,31 +19,12 @@
|
|||
</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>
|
||||
|
||||
<property name="UnmanagedDevices" type="ao" access="read">
|
||||
<tp:docstring>
|
||||
The list of HAL UDIs of devices that should not be managed by NetworkManager.
|
||||
</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>
|
||||
|
|
|
|||
|
|
@ -44,10 +44,8 @@
|
|||
#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);
|
||||
|
||||
|
|
@ -75,13 +73,9 @@ typedef struct {
|
|||
NMSystemConfigHalManager *hal_mgr;
|
||||
|
||||
GHashTable *connections;
|
||||
char *hostname;
|
||||
|
||||
GFileMonitor *ifcfg_monitor;
|
||||
guint ifcfg_monitor_id;
|
||||
|
||||
GFileMonitor *network_monitor;
|
||||
guint network_monitor_id;
|
||||
GFileMonitor *monitor;
|
||||
guint monitor_id;
|
||||
} SCPluginIfcfgPrivate;
|
||||
|
||||
|
||||
|
|
@ -422,120 +416,22 @@ dir_changed (GFileMonitor *monitor,
|
|||
g_free (name);
|
||||
}
|
||||
|
||||
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, &error);
|
||||
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
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->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;
|
||||
priv->monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (dir_changed), plugin);
|
||||
priv->monitor = monitor;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -566,12 +462,6 @@ get_connections (NMSystemConfigInterface *config)
|
|||
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)
|
||||
{
|
||||
|
|
@ -593,8 +483,6 @@ sc_plugin_ifcfg_init (SCPluginIfcfg *plugin)
|
|||
error->message ? error->message : "(unknown)");
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
read_hostname (plugin, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -611,22 +499,12 @@ dispose (GObject *object)
|
|||
if (priv->connections)
|
||||
g_hash_table_destroy (priv->connections);
|
||||
|
||||
g_free (priv->hostname);
|
||||
if (priv->monitor) {
|
||||
if (priv->monitor_id)
|
||||
g_signal_handler_disconnect (priv->monitor, priv->monitor_id);
|
||||
|
||||
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->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_file_monitor_cancel (priv->monitor);
|
||||
g_object_unref (priv->monitor);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (sc_plugin_ifcfg_parent_class)->dispose (object);
|
||||
|
|
@ -642,9 +520,6 @@ static void
|
|||
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);
|
||||
|
|
@ -652,31 +527,6 @@ get_property (GObject *object, guint prop_id,
|
|||
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;
|
||||
|
|
@ -693,7 +543,6 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
|
|||
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,
|
||||
|
|
@ -702,10 +551,6 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
|
|||
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
|
||||
|
|
@ -714,7 +559,6 @@ system_config_interface_init (NMSystemConfigInterface *system_config_interface_c
|
|||
/* 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ typedef struct {
|
|||
gboolean initialized;
|
||||
GHashTable *connections;
|
||||
GHashTable *unmanaged_devices;
|
||||
char *hostname;
|
||||
|
||||
guint32 default_gw;
|
||||
GFileMonitor *default_gw_monitor;
|
||||
|
|
@ -352,7 +351,6 @@ dispose (GObject *object)
|
|||
|
||||
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)
|
||||
|
|
@ -374,8 +372,6 @@ static void
|
|||
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);
|
||||
|
|
@ -383,20 +379,6 @@ get_property (GObject *object, guint prop_id,
|
|||
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;
|
||||
|
|
@ -411,7 +393,6 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
|
|||
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,
|
||||
|
|
@ -421,10 +402,6 @@ sc_plugin_ifcfg_class_init (SCPluginIfcfgClass *req_class)
|
|||
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
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ G_DEFINE_TYPE_EXTENDED (SCPluginKeyfile, sc_plugin_keyfile, G_TYPE_OBJECT, 0,
|
|||
typedef struct {
|
||||
GHashTable *hash;
|
||||
|
||||
char *hostname;
|
||||
|
||||
GFileMonitor *monitor;
|
||||
guint monitor_id;
|
||||
|
||||
|
|
@ -202,8 +200,6 @@ static void
|
|||
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);
|
||||
|
|
@ -211,20 +207,6 @@ get_property (GObject *object, guint prop_id,
|
|||
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;
|
||||
|
|
@ -252,8 +234,6 @@ dispose (GObject *object)
|
|||
if (priv->hash)
|
||||
g_hash_table_destroy (priv->hash);
|
||||
|
||||
g_free (priv->hostname);
|
||||
|
||||
G_OBJECT_CLASS (sc_plugin_keyfile_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +246,6 @@ sc_plugin_keyfile_class_init (SCPluginKeyfileClass *req_class)
|
|||
|
||||
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,
|
||||
|
|
@ -275,10 +254,6 @@ sc_plugin_keyfile_class_init (SCPluginKeyfileClass *req_class)
|
|||
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
|
||||
|
|
|
|||
|
|
@ -39,9 +39,6 @@
|
|||
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);
|
||||
|
|
@ -55,8 +52,6 @@ typedef struct {
|
|||
gboolean connections_loaded;
|
||||
GHashTable *connections;
|
||||
GHashTable *unmanaged_devices;
|
||||
|
||||
char *hostname;
|
||||
} NMSysconfigSettingsPrivate;
|
||||
|
||||
G_DEFINE_TYPE (NMSysconfigSettings, nm_sysconfig_settings, NM_TYPE_SETTINGS);
|
||||
|
|
@ -74,7 +69,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
|
|||
enum {
|
||||
PROP_0,
|
||||
PROP_UNMANAGED_DEVICES,
|
||||
PROP_HOSTNAME,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
|
@ -103,16 +97,6 @@ load_connections (NMSysconfigSettings *self)
|
|||
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 */
|
||||
|
|
@ -155,8 +139,6 @@ settings_finalize (GObject *object)
|
|||
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);
|
||||
|
||||
|
|
@ -232,88 +214,16 @@ get_unmanaged_devices (NMSysconfigSettings *self)
|
|||
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;
|
||||
|
|
@ -331,7 +241,6 @@ nm_sysconfig_settings_class_init (NMSysconfigSettingsClass *class)
|
|||
/* 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;
|
||||
|
||||
|
|
@ -344,14 +253,6 @@ nm_sysconfig_settings_class_init (NMSysconfigSettingsClass *class)
|
|||
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",
|
||||
|
|
@ -438,41 +339,6 @@ unmanaged_devices_changed (NMSystemConfigInterface *config,
|
|||
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)
|
||||
|
|
@ -490,7 +356,6 @@ nm_sysconfig_settings_add_plugin (NMSysconfigSettings *self,
|
|||
|
||||
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);
|
||||
|
||||
|
|
@ -637,56 +502,3 @@ impl_settings_add_connection (NMSysconfigSettings *self,
|
|||
}
|
||||
}
|
||||
|
||||
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 one '.'
|
||||
* 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 < 1 || 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ typedef struct _NMSysconfigSettingsClass NMSysconfigSettingsClass;
|
|||
#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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ nm_sysconfig_settings_error_get_type (void)
|
|||
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 }
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
|
||||
|
||||
#ifndef NM_SYSTEM_CONFIG_ERROR_H
|
||||
#define NM_SYSTEM_CONFIG_ERROR_H
|
||||
|
|
@ -13,9 +13,7 @@ enum {
|
|||
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_SET_HOSTNAME_FAILED,
|
||||
NM_SYSCONFIG_SETTINGS_ERROR_INVALID_HOSTNAME
|
||||
NM_SYSCONFIG_SETTINGS_ERROR_ADD_FAILED
|
||||
};
|
||||
|
||||
#define NM_SYSCONFIG_SETTINGS_ERROR (nm_sysconfig_settings_error_quark ())
|
||||
|
|
|
|||
|
|
@ -48,14 +48,6 @@ interface_init (gpointer g_iface)
|
|||
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,
|
||||
|
|
@ -160,19 +152,3 @@ nm_system_config_interface_add_connection (NMSystemConfigInterface *config,
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,12 +96,6 @@ struct _NMSystemConfigInterface {
|
|||
*/
|
||||
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 */
|
||||
|
||||
/* Emitted when a new connection has been found by the plugin */
|
||||
|
|
@ -126,10 +120,6 @@ gboolean nm_system_config_interface_add_connection (NMSystemConfigInterface *con
|
|||
NMConnection *connection,
|
||||
GError **error);
|
||||
|
||||
gboolean nm_system_config_interface_set_hostname (NMSystemConfigInterface *config,
|
||||
const char *hostname,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* NM_SYSTEM_CONFIG_INTERFACE_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue