Commit 9d5a2291 authored by Dan Williams's avatar Dan Williams

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
parent 410a0cf5
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
2008-09-18 Dan Williams <dcbw@redhat.com>
* libnm-util/nm-setting-wireless.c
......
......@@ -5,9 +5,6 @@
<property name="Addresses" type="aau" access="read">
<tp:docstring>Tuples of IPv4 address/prefix/gateway.</tp:docstring>
</property>
<property name="Hostname" type="s" access="read">
<tp:docstring>The hostname associated with this IPv4 address. FIXME: what about multiple hostnames?</tp:docstring>
</property>
<property name="Nameservers" type="au" access="read">
<tp:docstring>The nameservers in use.</tp:docstring>
</property>
......
......@@ -19,6 +19,24 @@
</arg>
</method>
<method name="SaveHostname">
<tp:docstring>
Save the hostname to persistent configuration.
</tp:docstring>
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_settings_save_hostname"/>
<arg name="hostname" type="s" direction="in">
<tp:docstring>
The hostname to save to persistent configuration. If blank, the persistent hostname is cleared.
</tp:docstring>
</arg>
</method>
<property name="Hostname" type="s" access="read">
<tp:docstring>
The machine hostname stored in persistent configuration.
</tp:docstring>
</property>
<property name="UnmanagedDevices" type="ao" access="read">
<tp:docstring>
The list of HAL UDIs of devices that should not be managed by NetworkManager.
......
......@@ -16,12 +16,16 @@ typedef struct {
gboolean got_unmanaged_devices;
GSList *unmanaged_devices;
gboolean got_hostname;
char *hostname;
gboolean disposed;
} NMDBusSettingsSystemPrivate;
enum {
PROP_0,
PROP_UNMANAGED_DEVICES,
PROP_HOSTNAME,
LAST_PROP
};
......@@ -114,6 +118,68 @@ nm_dbus_settings_system_get_unmanaged_devices (NMDBusSettingsSystem *self)
return priv->unmanaged_devices;
}
gboolean
nm_dbus_settings_system_save_hostname (NMDBusSettingsSystem *self,
const char *hostname,
GError **err)
{
NMDBusSettingsSystemPrivate *priv;
g_return_val_if_fail (NM_IS_DBUS_SETTINGS_SYSTEM (self), FALSE);
priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (self);
return org_freedesktop_NetworkManagerSettings_System_save_hostname (priv->settings_proxy, hostname ? hostname : "", err);
}
static void
update_hostname (NMDBusSettingsSystem *self, GValue *value)
{
NMDBusSettingsSystemPrivate *priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (self);
if (priv->hostname) {
g_free (priv->hostname);
priv->hostname = NULL;
}
if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
priv->hostname = g_value_dup_string (value);
priv->got_hostname = TRUE;
} else
g_warning ("%s: Invalid return value type: %s", __func__, G_VALUE_TYPE_NAME (value));
}
const char *
nm_dbus_settings_system_get_hostname (NMDBusSettingsSystem *self)
{
NMDBusSettingsSystemPrivate *priv;
GValue value = { 0, };
GError *err = NULL;
g_return_val_if_fail (NM_IS_DBUS_SETTINGS_SYSTEM (self), NULL);
priv = NM_DBUS_SETTINGS_SYSTEM_GET_PRIVATE (self);
if (priv->got_hostname)
return priv->hostname;
if (!dbus_g_proxy_call (priv->props_proxy, "Get", &err,
G_TYPE_STRING, NM_DBUS_SERVICE_SYSTEM_SETTINGS,
G_TYPE_STRING, "Hostname",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
g_warning ("Could not retrieve hostname: %s", err->message);
g_error_free (err);
return NULL;
}
update_hostname (self, &value);
g_value_unset (&value);
return priv->hostname;
}
static void
proxy_properties_changed (DBusGProxy *proxy,
GHashTable *properties,
......@@ -127,6 +193,12 @@ proxy_properties_changed (DBusGProxy *proxy,
update_unmanaged_devices (self, value);
g_object_notify (G_OBJECT (self), NM_DBUS_SETTINGS_SYSTEM_UNMANAGED_DEVICES);
}
value = (GValue *) g_hash_table_lookup (properties, "Hostname");
if (value) {
update_hostname (self, value);
g_object_notify (G_OBJECT (self), NM_DBUS_SETTINGS_SYSTEM_HOSTNAME);
}
}
static void
......@@ -184,6 +256,8 @@ dispose (GObject *object)
priv->disposed = TRUE;
g_free (priv->hostname);
if (priv->unmanaged_devices) {
g_slist_foreach (priv->unmanaged_devices, (GFunc) g_free, NULL);
g_slist_free (priv->unmanaged_devices);
......@@ -205,6 +279,9 @@ get_property (GObject *object, guint prop_id,
case PROP_UNMANAGED_DEVICES:
g_value_set_pointer (value, nm_dbus_settings_system_get_unmanaged_devices (self));
break;
case PROP_HOSTNAME:
g_value_set_string (value, nm_dbus_settings_system_get_hostname (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -230,4 +307,13 @@ nm_dbus_settings_system_class_init (NMDBusSettingsSystemClass *dbus_settings_cla
"Unmanaged devices",
"Unmanaged devices",
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_HOSTNAME,
g_param_spec_string (NM_DBUS_SETTINGS_SYSTEM_HOSTNAME,
"Hostname",
"Configured hostname",
NULL,
G_PARAM_READABLE));
}
......@@ -15,6 +15,7 @@ G_BEGIN_DECLS
#define NM_DBUS_SETTINGS_SYSTEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DBUS_SETTINGS_SYSTEM, NMDBusSettingsSystemClass))
#define NM_DBUS_SETTINGS_SYSTEM_UNMANAGED_DEVICES "unmanaged-devices"
#define NM_DBUS_SETTINGS_SYSTEM_HOSTNAME "hostname"
typedef struct {
NMDBusSettings parent;
......@@ -34,6 +35,11 @@ gboolean nm_dbus_settings_system_add_connection (NMDBusSettingsSystem *self,
GSList *nm_dbus_settings_system_get_unmanaged_devices (NMDBusSettingsSystem *self);
const char *nm_dbus_settings_system_get_hostname (NMDBusSettingsSystem *self);
gboolean nm_dbus_settings_system_save_hostname (NMDBusSettingsSystem *self,
const char *hostname,
GError **err);
G_END_DECLS
......
This diff is collapsed.
......@@ -793,10 +793,8 @@ nm_dhcp_manager_get_ip4_config (NMDHCPManager *manager,
addr = NULL;
str = g_hash_table_lookup (device->options, "new_host_name");
if (str) {
nm_ip4_config_set_hostname (ip4_config, str);
if (str)
nm_info (" hostname '%s'", str);
}
str = g_hash_table_lookup (device->options, "new_domain_name_servers");
if (str) {
......
......@@ -1853,6 +1853,19 @@ nm_device_set_use_dhcp (NMDevice *self,
}
}
NMDHCP4Config *
nm_device_get_dhcp4_config (NMDevice *self)
{
NMDevicePrivate *priv;
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
priv = NM_DEVICE_GET_PRIVATE (self);
if (priv->dhcp_manager)
return priv->dhcp4_config;
return NULL;
}
NMIP4Config *
nm_device_get_ip4_config (NMDevice *self)
......
......@@ -29,6 +29,7 @@
#include "NetworkManager.h"
#include "nm-activation-request.h"
#include "nm-ip4-config.h"
#include "nm-dhcp4-config.h"
#include "nm-connection.h"
typedef enum NMActStageReturn
......@@ -133,6 +134,7 @@ struct in6_addr * nm_device_get_ip6_address (NMDevice *dev);
gboolean nm_device_get_use_dhcp (NMDevice *dev);
void nm_device_set_use_dhcp (NMDevice *dev,
gboolean use_dhcp);
NMDHCP4Config * nm_device_get_dhcp4_config (NMDevice *dev);
NMIP4Config * nm_device_get_ip4_config (NMDevice *dev);
gboolean nm_device_set_ip4_config (NMDevice *dev,
......
/* -*- 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
*
......@@ -18,7 +18,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2005 Red Hat, Inc.
* (C) Copyright 2005 - 2008 Red Hat, Inc.
*/
......@@ -57,7 +57,6 @@ typedef struct {
GPtrArray *domains;
GPtrArray *searches;
gchar *hostname;
GSList *routes;
} NMIP4ConfigPrivate;
......@@ -65,7 +64,6 @@ typedef struct {
enum {
PROP_0,
PROP_ADDRESSES,
PROP_HOSTNAME,
PROP_NAMESERVERS,
PROP_DOMAINS,
PROP_ROUTES,
......@@ -223,24 +221,6 @@ void nm_ip4_config_reset_nameservers (NMIP4Config *config)
g_array_remove_range (priv->nameservers, 0, priv->nameservers->len);
}
void nm_ip4_config_set_hostname (NMIP4Config *config, const char *hostname)
{
g_return_if_fail (NM_IS_IP4_CONFIG (config));
g_return_if_fail (hostname != NULL);
if (!strlen (hostname))
return;
NM_IP4_CONFIG_GET_PRIVATE (config)->hostname = g_strdup (hostname);
}
const char *nm_ip4_config_get_hostname (NMIP4Config *config)
{
g_return_val_if_fail (NM_IS_IP4_CONFIG (config), NULL);
return NM_IP4_CONFIG_GET_PRIVATE (config)->hostname;
}
void
nm_ip4_config_take_route (NMIP4Config *config,
NMSettingIP4Route *route)
......@@ -510,7 +490,6 @@ finalize (GObject *object)
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
nm_utils_slist_free (priv->addresses, g_free);
g_free (priv->hostname);
g_array_free (priv->nameservers, TRUE);
g_ptr_array_free (priv->domains, TRUE);
g_ptr_array_free (priv->searches, TRUE);
......@@ -527,9 +506,6 @@ get_property (GObject *object, guint prop_id,
case PROP_ADDRESSES:
nm_utils_ip4_addresses_to_gvalue (priv->addresses, value);
break;
case PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
break;
case PROP_NAMESERVERS:
g_value_set_boxed (value, priv->nameservers);
break;
......@@ -564,13 +540,6 @@ nm_ip4_config_class_init (NMIP4ConfigClass *config_class)
"IP4 addresses",
DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT,
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_HOSTNAME,
g_param_spec_string (NM_IP4_CONFIG_HOSTNAME,
"Hostname",
"Hostname",
NULL,
G_PARAM_READABLE));
g_object_class_install_property
(object_class, PROP_NAMESERVERS,
g_param_spec_boxed (NM_IP4_CONFIG_NAMESERVERS,
......
......@@ -18,7 +18,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2004 Red Hat, Inc.
* (C) Copyright 2004 - 2008 Red Hat, Inc.
*/
#ifndef NM_IP4_CONFIG_H
......@@ -45,11 +45,8 @@ typedef struct {
} NMIP4ConfigClass;
#define NM_IP4_CONFIG_ADDRESSES "addresses"
#define NM_IP4_CONFIG_HOSTNAME "hostname"
#define NM_IP4_CONFIG_NAMESERVERS "nameservers"
#define NM_IP4_CONFIG_DOMAINS "domains"
#define NM_IP4_CONFIG_NIS_DOMAIN "nis-domain"
#define NM_IP4_CONFIG_NIS_SERVERS "nis-servers"
#define NM_IP4_CONFIG_ROUTES "routes"
GType nm_ip4_config_get_type (void);
......@@ -80,9 +77,6 @@ const NMSettingIP4Route * nm_ip4_config_get_route (NMIP4Config *config, guint32
guint32 nm_ip4_config_get_num_routes (NMIP4Config *config);
void nm_ip4_config_reset_routes (NMIP4Config *config);
void nm_ip4_config_set_hostname (NMIP4Config *config, const char *hostname);
const char * nm_ip4_config_get_hostname (NMIP4Config *config);
void nm_ip4_config_add_domain (NMIP4Config *config, const char *domain);
const char * nm_ip4_config_get_domain (NMIP4Config *config, guint i);
guint32 nm_ip4_config_get_num_domains (NMIP4Config *config);
......
......@@ -70,6 +70,10 @@ static void hal_manager_rfkill_changed_cb (NMHalManager *hal_mgr,
static void hal_manager_hal_reappeared_cb (NMHalManager *hal_mgr,
gpointer user_data);
static void system_settings_properties_changed_cb (DBusGProxy *proxy,
GHashTable *properties,
gpointer user_data);
#define SSD_POKE_INTERVAL 120000
typedef struct {
......@@ -95,6 +99,7 @@ typedef struct {
DBusGProxy *system_proxy;
DBusGProxy *system_props_proxy;
GSList *unmanaged_udis;
char *hostname;
PendingConnectionInfo *pending_connection_info;
gboolean wireless_enabled;
......@@ -139,6 +144,9 @@ enum {
PROP_WIRELESS_HARDWARE_ENABLED,
PROP_ACTIVE_CONNECTIONS,
/* Not exported */
PROP_HOSTNAME,
LAST_PROP
};
......@@ -280,6 +288,8 @@ nm_manager_init (NMManager *manager)
priv->vpn_manager_id = id;
g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
/* avahi-autoipd stuff */
priv->aipd_proxy = dbus_g_proxy_new_for_name (g_connection,
NM_AUTOIP_DBUS_SERVICE,
"/",
......@@ -300,7 +310,24 @@ nm_manager_init (NMManager *manager)
manager,
NULL);
} else
nm_warning ("Could not initialize avahi-autoipd D-Bus proxy");
nm_warning ("%s: could not initialize avahi-autoipd D-Bus proxy", __func__);
/* System settings stuff */
priv->system_props_proxy = dbus_g_proxy_new_for_name (g_connection,
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
NM_DBUS_PATH_SETTINGS,
"org.freedesktop.NetworkManagerSettings.System");
if (priv->system_props_proxy) {
dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->system_props_proxy, "PropertiesChanged",
DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->system_props_proxy, "PropertiesChanged",
G_CALLBACK (system_settings_properties_changed_cb),
manager,
NULL);
} else
nm_warning ("%s: could not initialize system settings properties D-Bus proxy", __func__);
}
NMState
......@@ -434,6 +461,8 @@ dispose (GObject *object)
g_hash_table_destroy (priv->system_connections);
priv->system_connections = NULL;
g_free (priv->hostname);
if (priv->system_props_proxy) {
g_object_unref (priv->system_props_proxy);
priv->system_props_proxy = NULL;
......@@ -526,6 +555,9 @@ get_property (GObject *object, guint prop_id,
case PROP_ACTIVE_CONNECTIONS:
g_value_take_boxed (value, get_active_connections (self, NULL));
break;
case PROP_HOSTNAME:
g_value_set_string (value, priv->hostname);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -579,6 +611,15 @@ nm_manager_class_init (NMManagerClass *manager_class)
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
G_PARAM_READABLE));
/* Hostname is not exported over D-Bus */
g_object_class_install_property
(object_class, PROP_HOSTNAME,
g_param_spec_string (NM_MANAGER_HOSTNAME,
"Hostname",
"Hostname",
NULL,
G_PARAM_READABLE | NM_PROPERTY_PARAM_NO_EXPORT));
/* signals */
signals[DEVICE_ADDED] =
g_signal_new ("device-added",
......@@ -1127,6 +1168,22 @@ handle_unmanaged_devices (NMManager *manager, GPtrArray *ops)
g_slist_free (unmanaged);
}
static void
handle_hostname (NMManager *manager, const char *hostname)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
if (!hostname && !priv->hostname)
return;
if (hostname && priv->hostname && !strcmp (hostname, priv->hostname))
return;
g_free (priv->hostname);
priv->hostname = (hostname && strlen (hostname)) ? g_strdup (hostname) : NULL;
g_object_notify (G_OBJECT (manager), NM_MANAGER_HOSTNAME);
}
static void
system_settings_properties_changed_cb (DBusGProxy *proxy,
GHashTable *properties,
......@@ -1136,10 +1193,12 @@ system_settings_properties_changed_cb (DBusGProxy *proxy,
GValue *value;
value = g_hash_table_lookup (properties, "UnmanagedDevices");
if (!value || !G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH))
return;
if (value && G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH))
handle_unmanaged_devices (manager, g_value_get_boxed (value));
handle_unmanaged_devices (manager, g_value_get_boxed (value));
value = g_hash_table_lookup (properties, "Hostname");
if (value && G_VALUE_HOLDS (value, G_TYPE_STRING))
handle_hostname (manager, g_value_get_string (value));
}
static void
......@@ -1158,6 +1217,7 @@ system_settings_get_unmanaged_devices_cb (DBusGProxy *proxy,
"settings service: (%d) %s",
__func__, error->code, error->message);
g_error_free (error);
g_object_unref (proxy);
return;
}
......@@ -1165,37 +1225,45 @@ system_settings_get_unmanaged_devices_cb (DBusGProxy *proxy,
handle_unmanaged_devices (manager, g_value_get_boxed (&value));
g_value_unset (&value);
g_object_unref (proxy);
}
static void
system_settings_get_hostname_cb (DBusGProxy *proxy,
DBusGProxyCall *call_id,
gpointer user_data)
{
NMManager *manager = NM_MANAGER (user_data);
GError *error = NULL;
GValue value = { 0, };
if (!dbus_g_proxy_end_call (proxy, call_id, &error,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
nm_warning ("%s: Error getting hostname from the system settings service: (%d) %s",
__func__, error->code, error->message);
g_error_free (error);
g_object_unref (proxy);
return;
}
if (G_VALUE_HOLDS (&value, G_TYPE_STRING))
handle_hostname (manager, g_value_get_string (&value));
g_value_unset (&value);
g_object_unref (proxy);
}
static void
query_unmanaged_devices (NMManager *manager)
query_system_settings_property (NMManager *manager,
const char *property,
DBusGProxyCallNotify callback)
{
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
DBusGConnection *g_connection;
DBusGProxy *get_proxy;
g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
if (!priv->system_props_proxy) {
priv->system_props_proxy = dbus_g_proxy_new_for_name (g_connection,
NM_DBUS_SERVICE_SYSTEM_SETTINGS,
NM_DBUS_PATH_SETTINGS,
"org.freedesktop.NetworkManagerSettings.System");
if (!priv->system_props_proxy) {
nm_warning ("Error: could not init system settings properties proxy.");
return;
}
dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->system_props_proxy, "PropertiesChanged",
DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->system_props_proxy, "PropertiesChanged",
G_CALLBACK (system_settings_properties_changed_cb),
manager,
NULL);
}
/* Get unmanaged devices */
get_proxy = dbus_g_proxy_new_for_name (g_connection,
......@@ -1203,12 +1271,9 @@ query_unmanaged_devices (NMManager *manager)
NM_DBUS_PATH_SETTINGS,
"org.freedesktop.DBus.Properties");
dbus_g_proxy_begin_call (get_proxy, "Get",
system_settings_get_unmanaged_devices_cb,
manager,
NULL,
G_TYPE_STRING, "org.freedesktop.NetworkManagerSettings.System",
G_TYPE_STRING, "UnmanagedDevices",
dbus_g_proxy_begin_call (get_proxy, "Get", callback, manager, NULL,
G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS_SYSTEM,
G_TYPE_STRING, property,
G_TYPE_INVALID);
}
......@@ -1240,7 +1305,8 @@ nm_manager_name_owner_changed (NMDBusManager *mgr,
}
/* System Settings service appeared, update stuff */
query_unmanaged_devices (manager);
query_system_settings_property (manager, "UnmanagedDevices", system_settings_get_unmanaged_devices_cb);
query_system_settings_property (manager, "Hostname", system_settings_get_hostname_cb);
query_connections (manager, NM_CONNECTION_SCOPE_SYSTEM);
} else {
/* System Settings service disappeared, throw them away (?) */
......@@ -1299,7 +1365,8 @@ initial_get_connections (gpointer user_data)
if (nm_dbus_manager_name_has_owner (nm_dbus_manager_get (),
NM_DBUS_SERVICE_SYSTEM_SETTINGS)) {
query_unmanaged_devices (manager);
query_system_settings_property (manager, "UnmanagedDevices", system_settings_get_unmanaged_devices_cb);
query_system_settings_property (manager, "Hostname", system_settings_get_hostname_cb);
query_connections (manager, NM_CONNECTION_SCOPE_SYSTEM);
} else {
/* Try to activate the system settings daemon */
......
......@@ -19,6 +19,9 @@
#define NM_MANAGER_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
#define NM_MANAGER_ACTIVE_CONNECTIONS "active-connections"
/* Not exported */
#define NM_MANAGER_HOSTNAME "hostname"
#define NM_MANAGER_CONNECTION_PROXY_TAG "dbus-proxy"
#define NM_MANAGER_CONNECTION_SECRETS_PROXY_TAG "dbus-secrets-proxy"
......
/* NetworkManager system settings service
*
* Dan Williams <dcbw@redhat.com>
* Søren Sandmann <sandmann@daimi.au.dk>
*
* This program is free software; you can redistribute it and/or modify
......@@ -44,6 +45,8 @@
#include "plugin.h"
#include "nm-system-config-interface.h"
#include "nm-ifcfg-connection.h"
#include "nm-inotify-helper.h"
#include "shvar.h"
#define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts/"
......@@ -74,6 +77,10 @@ typedef struct {
GHashTable *connections;
gulong ih_event_id;
int sc_network_wd;
char *hostname;
GFileMonitor *monitor;
guint monitor_id;
} SCPluginIfcfgPrivate;
......@@ -417,7 +424,7 @@ dir_changed (GFileMonitor *monitor,
}
static void
setup_monitoring (SCPluginIfcfg *plugin)
setup_ifcfg_monitoring (SCPluginIfcfg *plugin)
{
SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin);
GFile *file;
......@@ -453,7 +460,7 @@ get_connections (NMSystemConfigInterface *config)
GSList *list = NULL;
if (!priv->connections) {
setup_monitoring (plugin);
setup_ifcfg_monitoring (plugin);
read_connections (plugin);
}
......@@ -462,6 +469,70 @@ get_connections (NMSystemConfigInterface *config)
return list;
}
#define SC_NETWORK_FILE SYSCONFDIR"/sysconfig/network"
static char *
plugin_get_hostname (SCPluginIfcfg *plugin)