2008-08-12 18:39:03 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
2008-11-03 16:05:11 +00:00
|
|
|
/* NetworkManager system settings service - keyfile plugin
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008 Novell, Inc.
|
2013-11-12 15:04:15 +01:00
|
|
|
* Copyright (C) 2008 - 2013 Red Hat, Inc.
|
2008-11-03 16:05:11 +00:00
|
|
|
*/
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-05-11 20:12:18 +00:00
|
|
|
#include <config.h>
|
2008-04-22 14:48:02 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/types.h>
|
2008-08-27 03:09:14 +00:00
|
|
|
#include <string.h>
|
2009-08-20 13:00:37 -05:00
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
#include <gmodule.h>
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
#include <glib/gstdio.h>
|
2009-08-20 13:00:37 -05:00
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
#include <nm-connection.h>
|
|
|
|
|
#include <nm-setting.h>
|
|
|
|
|
#include <nm-setting-connection.h>
|
2013-02-12 18:00:48 -05:00
|
|
|
#include <nm-utils.h>
|
2013-03-12 11:11:54 -04:00
|
|
|
#include <nm-config.h>
|
2014-04-05 09:37:04 -04:00
|
|
|
#include <nm-logging.h>
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
#include "nm-system-config-interface.h"
|
2008-05-07 09:48:12 +00:00
|
|
|
#include "nm-keyfile-connection.h"
|
2008-04-22 14:48:02 +00:00
|
|
|
#include "writer.h"
|
2010-09-16 17:39:06 -05:00
|
|
|
#include "common.h"
|
2010-11-10 16:21:25 +01:00
|
|
|
#include "utils.h"
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
static char *plugin_get_hostname (SCPluginKeyfile *plugin);
|
2008-04-22 14:48:02 +00:00
|
|
|
static void system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_EXTENDED (SCPluginKeyfile, sc_plugin_keyfile, G_TYPE_OBJECT, 0,
|
|
|
|
|
G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE,
|
|
|
|
|
system_config_interface_init))
|
|
|
|
|
|
|
|
|
|
#define SC_PLUGIN_KEYFILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SC_TYPE_PLUGIN_KEYFILE, SCPluginKeyfilePrivate))
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2013-04-18 13:54:36 -05:00
|
|
|
GHashTable *connections; /* uuid::connection */
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
gboolean initialized;
|
2008-04-22 14:48:02 +00:00
|
|
|
GFileMonitor *monitor;
|
|
|
|
|
guint monitor_id;
|
|
|
|
|
|
2013-03-12 11:11:54 -04:00
|
|
|
const char *conf_file;
|
2008-09-24 15:03:33 +00:00
|
|
|
GFileMonitor *conf_file_monitor;
|
|
|
|
|
guint conf_file_monitor_id;
|
|
|
|
|
|
|
|
|
|
char *hostname;
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
gboolean disposed;
|
|
|
|
|
} SCPluginKeyfilePrivate;
|
|
|
|
|
|
2013-08-08 15:54:32 -05:00
|
|
|
static void
|
|
|
|
|
connection_removed_cb (NMSettingsConnection *obj, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
g_hash_table_remove (SC_PLUGIN_KEYFILE_GET_PRIVATE (user_data)->connections,
|
|
|
|
|
nm_connection_get_uuid (NM_CONNECTION (obj)));
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
/* Monitoring */
|
|
|
|
|
|
2010-09-16 15:43:22 -05:00
|
|
|
static void
|
2013-04-18 13:54:36 -05:00
|
|
|
remove_connection (SCPluginKeyfile *self, NMKeyfileConnection *connection)
|
2010-09-16 15:43:22 -05:00
|
|
|
{
|
2014-06-11 13:24:10 -05:00
|
|
|
gboolean removed;
|
|
|
|
|
|
2010-09-16 15:43:22 -05:00
|
|
|
g_return_if_fail (connection != NULL);
|
|
|
|
|
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_info (LOGD_SETTINGS, "removed %s.", nm_keyfile_connection_get_path (connection));
|
2013-05-23 19:05:40 -03:00
|
|
|
|
2010-09-16 15:43:22 -05:00
|
|
|
/* Removing from the hash table should drop the last reference */
|
|
|
|
|
g_object_ref (connection);
|
2014-06-11 13:24:10 -05:00
|
|
|
g_signal_handlers_disconnect_by_func (connection, connection_removed_cb, self);
|
|
|
|
|
removed = g_hash_table_remove (SC_PLUGIN_KEYFILE_GET_PRIVATE (self)->connections,
|
|
|
|
|
nm_connection_get_uuid (NM_CONNECTION (connection)));
|
2011-02-11 21:29:41 -06:00
|
|
|
nm_settings_connection_signal_remove (NM_SETTINGS_CONNECTION (connection));
|
2010-09-16 15:43:22 -05:00
|
|
|
g_object_unref (connection);
|
2014-06-11 13:24:10 -05:00
|
|
|
|
|
|
|
|
g_return_if_fail (removed);
|
2010-09-16 15:43:22 -05:00
|
|
|
}
|
|
|
|
|
|
2013-05-23 19:05:40 -03:00
|
|
|
static void
|
|
|
|
|
update_connection (SCPluginKeyfile *self,
|
|
|
|
|
NMKeyfileConnection *connection,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
NMKeyfileConnection *tmp;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
tmp = nm_keyfile_connection_new (NULL, name, &error);
|
|
|
|
|
if (!tmp) {
|
|
|
|
|
/* Error; remove the connection */
|
2014-06-11 13:32:00 -05:00
|
|
|
nm_log_warn (LOGD_SETTINGS, " error in connection %s: %s", name,
|
|
|
|
|
(error && error->message) ? error->message : "(unknown)");
|
2013-05-23 19:05:40 -03:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
remove_connection (self, connection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!nm_connection_compare (NM_CONNECTION (connection),
|
|
|
|
|
NM_CONNECTION (tmp),
|
|
|
|
|
NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS |
|
|
|
|
|
NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS)) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_info (LOGD_SETTINGS, "updating %s", name);
|
2013-05-23 19:05:40 -03:00
|
|
|
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection),
|
|
|
|
|
NM_CONNECTION (tmp),
|
|
|
|
|
FALSE, /* don't set Unsaved */
|
|
|
|
|
&error)) {
|
|
|
|
|
/* Shouldn't ever get here as 'new' was verified by the reader already */
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (tmp);
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-29 14:34:33 -05:00
|
|
|
static NMKeyfileConnection *
|
2013-04-18 13:54:36 -05:00
|
|
|
find_by_path (SCPluginKeyfile *self, const char *path)
|
2010-10-29 14:34:33 -05:00
|
|
|
{
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
|
|
|
|
|
GHashTableIter iter;
|
2013-04-18 13:54:36 -05:00
|
|
|
NMKeyfileConnection *candidate = NULL;
|
2010-10-29 14:34:33 -05:00
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
2010-10-29 14:34:33 -05:00
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
g_hash_table_iter_init (&iter, priv->connections);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &candidate)) {
|
2013-11-01 12:29:31 +01:00
|
|
|
if (g_strcmp0 (path, nm_keyfile_connection_get_path (candidate)) == 0)
|
2013-04-18 13:54:36 -05:00
|
|
|
return candidate;
|
2010-10-29 14:34:33 -05:00
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 19:05:40 -03:00
|
|
|
static void
|
|
|
|
|
new_connection (SCPluginKeyfile *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
char **out_old_path)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
|
|
|
|
|
NMKeyfileConnection *tmp, *connection;
|
|
|
|
|
GError *error = NULL;
|
2014-06-11 13:24:10 -05:00
|
|
|
const char *uuid;
|
2013-05-23 19:05:40 -03:00
|
|
|
|
|
|
|
|
if (out_old_path)
|
|
|
|
|
*out_old_path = NULL;
|
|
|
|
|
|
|
|
|
|
tmp = nm_keyfile_connection_new (NULL, name, &error);
|
|
|
|
|
if (!tmp) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, " error in connection %s: %s", name,
|
|
|
|
|
(error && error->message) ? error->message : "(unknown)");
|
2013-05-23 19:05:40 -03:00
|
|
|
g_clear_error (&error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Connection renames will show as different paths but same UUID */
|
2014-06-11 13:24:10 -05:00
|
|
|
uuid = nm_connection_get_uuid (NM_CONNECTION (tmp));
|
|
|
|
|
connection = g_hash_table_lookup (priv->connections, uuid);
|
2013-05-23 19:05:40 -03:00
|
|
|
if (connection) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_info (LOGD_SETTINGS, "rename %s -> %s", nm_keyfile_connection_get_path (connection), name);
|
2013-05-23 19:05:40 -03:00
|
|
|
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (connection),
|
|
|
|
|
NM_CONNECTION (tmp),
|
|
|
|
|
FALSE, /* don't set Unsaved */
|
|
|
|
|
&error)) {
|
|
|
|
|
/* Shouldn't ever get here as 'tmp' was verified by the reader already */
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (tmp);
|
|
|
|
|
if (out_old_path)
|
|
|
|
|
*out_old_path = g_strdup (nm_keyfile_connection_get_path (connection));
|
|
|
|
|
nm_keyfile_connection_set_path (connection, name);
|
|
|
|
|
} else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_info (LOGD_SETTINGS, "new connection %s", name);
|
2014-06-11 13:24:10 -05:00
|
|
|
g_hash_table_insert (priv->connections, g_strdup (uuid), tmp);
|
2013-05-23 19:05:40 -03:00
|
|
|
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_CONNECTION_ADDED, tmp);
|
2013-08-08 15:54:32 -05:00
|
|
|
|
|
|
|
|
g_signal_connect (tmp, NM_SETTINGS_CONNECTION_REMOVED,
|
|
|
|
|
G_CALLBACK (connection_removed_cb),
|
|
|
|
|
self);
|
2013-05-23 19:05:40 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
static void
|
|
|
|
|
dir_changed (GFileMonitor *monitor,
|
2010-09-16 15:43:22 -05:00
|
|
|
GFile *file,
|
|
|
|
|
GFile *other_file,
|
|
|
|
|
GFileMonitorEvent event_type,
|
|
|
|
|
gpointer user_data)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
|
|
|
|
NMSystemConfigInterface *config = NM_SYSTEM_CONFIG_INTERFACE (user_data);
|
2010-10-29 14:34:33 -05:00
|
|
|
SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
|
2013-05-23 19:05:40 -03:00
|
|
|
NMKeyfileConnection *connection;
|
2010-10-29 14:34:33 -05:00
|
|
|
char *full_path;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2010-10-29 14:34:33 -05:00
|
|
|
full_path = g_file_get_path (file);
|
2011-02-04 15:59:45 -06:00
|
|
|
if (nm_keyfile_plugin_utils_should_ignore_file (full_path)) {
|
2010-11-16 18:08:48 -06:00
|
|
|
g_free (full_path);
|
2010-11-10 16:21:25 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
connection = find_by_path (self, full_path);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
switch (event_type) {
|
|
|
|
|
case G_FILE_MONITOR_EVENT_DELETED:
|
2013-05-23 19:05:40 -03:00
|
|
|
if (connection)
|
2013-04-18 13:54:36 -05:00
|
|
|
remove_connection (SC_PLUGIN_KEYFILE (config), connection);
|
2008-04-22 14:48:02 +00:00
|
|
|
break;
|
2008-05-09 06:33:30 +00:00
|
|
|
case G_FILE_MONITOR_EVENT_CREATED:
|
2008-04-22 14:48:02 +00:00
|
|
|
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
2013-05-23 19:05:40 -03:00
|
|
|
if (connection)
|
|
|
|
|
update_connection (SC_PLUGIN_KEYFILE (config), connection, full_path);
|
|
|
|
|
else
|
|
|
|
|
new_connection (SC_PLUGIN_KEYFILE (config), full_path, NULL);
|
2008-04-22 14:48:02 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-29 14:34:33 -05:00
|
|
|
g_free (full_path);
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
static void
|
|
|
|
|
conf_file_changed (GFileMonitor *monitor,
|
|
|
|
|
GFile *file,
|
|
|
|
|
GFile *other_file,
|
|
|
|
|
GFileMonitorEvent event_type,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (data);
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
|
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
|
|
switch (event_type) {
|
|
|
|
|
case G_FILE_MONITOR_EVENT_DELETED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_CREATED:
|
|
|
|
|
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
2009-07-23 09:20:52 -04:00
|
|
|
g_signal_emit_by_name (self, NM_SYSTEM_CONFIG_INTERFACE_UNMANAGED_SPECS_CHANGED);
|
2008-09-24 15:03:33 +00:00
|
|
|
|
|
|
|
|
/* hostname */
|
|
|
|
|
tmp = plugin_get_hostname (self);
|
|
|
|
|
if ((tmp && !priv->hostname)
|
|
|
|
|
|| (!tmp && priv->hostname)
|
|
|
|
|
|| (priv->hostname && tmp && strcmp (priv->hostname, tmp))) {
|
|
|
|
|
|
|
|
|
|
g_free (priv->hostname);
|
|
|
|
|
priv->hostname = tmp;
|
|
|
|
|
tmp = NULL;
|
|
|
|
|
g_object_notify (G_OBJECT (self), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (tmp);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
static void
|
|
|
|
|
setup_monitoring (NMSystemConfigInterface *config)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);
|
|
|
|
|
GFile *file;
|
|
|
|
|
GFileMonitor *monitor;
|
|
|
|
|
|
2013-05-23 19:05:40 -03:00
|
|
|
if (nm_config_get_monitor_connection_files (nm_config_get ())) {
|
|
|
|
|
file = g_file_new_for_path (KEYFILE_DIR);
|
|
|
|
|
monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
|
|
|
|
g_object_unref (file);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2013-05-23 19:05:40 -03:00
|
|
|
if (monitor) {
|
|
|
|
|
priv->monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (dir_changed), config);
|
|
|
|
|
priv->monitor = monitor;
|
|
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2012-01-13 16:42:58 -06:00
|
|
|
if (priv->conf_file) {
|
|
|
|
|
file = g_file_new_for_path (priv->conf_file);
|
|
|
|
|
monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
|
|
|
|
|
if (monitor) {
|
|
|
|
|
priv->conf_file_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (conf_file_changed), config);
|
|
|
|
|
priv->conf_file_monitor = monitor;
|
|
|
|
|
}
|
2008-09-24 15:03:33 +00:00
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2013-05-23 19:05:40 -03:00
|
|
|
static void
|
|
|
|
|
read_connections (NMSystemConfigInterface *config)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
|
|
|
|
|
GDir *dir;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
const char *item;
|
|
|
|
|
GHashTable *oldconns;
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer data;
|
|
|
|
|
|
|
|
|
|
dir = g_dir_open (KEYFILE_DIR, 0, &error);
|
|
|
|
|
if (!dir) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Cannot read directory '%s': (%d) %s",
|
2013-05-23 19:05:40 -03:00
|
|
|
KEYFILE_DIR,
|
|
|
|
|
error ? error->code : -1,
|
|
|
|
|
error && error->message ? error->message : "(unknown)");
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
oldconns = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
|
|
|
g_hash_table_iter_init (&iter, priv->connections);
|
2013-11-12 15:04:15 +01:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &data)) {
|
|
|
|
|
const char *con_path = nm_keyfile_connection_get_path (data);
|
|
|
|
|
if (con_path)
|
|
|
|
|
g_hash_table_insert (oldconns, g_strdup (con_path), data);
|
|
|
|
|
}
|
2013-05-23 19:05:40 -03:00
|
|
|
|
|
|
|
|
while ((item = g_dir_read_name (dir))) {
|
|
|
|
|
NMKeyfileConnection *connection;
|
|
|
|
|
char *full_path, *old_path;
|
|
|
|
|
|
|
|
|
|
if (nm_keyfile_plugin_utils_should_ignore_file (item))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
full_path = g_build_filename (KEYFILE_DIR, item, NULL);
|
|
|
|
|
|
|
|
|
|
connection = g_hash_table_lookup (oldconns, full_path);
|
|
|
|
|
if (connection) {
|
|
|
|
|
g_hash_table_remove (oldconns, full_path);
|
|
|
|
|
update_connection (self, connection, full_path);
|
|
|
|
|
} else {
|
|
|
|
|
new_connection (self, full_path, &old_path);
|
|
|
|
|
if (old_path) {
|
|
|
|
|
g_hash_table_remove (oldconns, old_path);
|
|
|
|
|
g_free (old_path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (full_path);
|
|
|
|
|
}
|
|
|
|
|
g_dir_close (dir);
|
|
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, oldconns);
|
|
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &data)) {
|
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
|
remove_connection (self, data);
|
|
|
|
|
}
|
|
|
|
|
g_hash_table_destroy (oldconns);
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
/* Plugin */
|
|
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
|
get_connections (NMSystemConfigInterface *config)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);
|
2010-10-29 14:34:33 -05:00
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer data = NULL;
|
|
|
|
|
GSList *list = NULL;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
if (!priv->initialized) {
|
2008-04-22 14:48:02 +00:00
|
|
|
setup_monitoring (config);
|
|
|
|
|
read_connections (config);
|
2013-04-18 13:54:36 -05:00
|
|
|
priv->initialized = TRUE;
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
g_hash_table_iter_init (&iter, priv->connections);
|
2010-10-29 14:34:33 -05:00
|
|
|
while (g_hash_table_iter_next (&iter, NULL, &data))
|
|
|
|
|
list = g_slist_prepend (list, data);
|
|
|
|
|
return list;
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-31 15:17:33 -04:00
|
|
|
static gboolean
|
|
|
|
|
load_connection (NMSystemConfigInterface *config,
|
|
|
|
|
const char *filename)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
|
|
|
|
|
NMKeyfileConnection *connection;
|
|
|
|
|
int dir_len = strlen (KEYFILE_DIR);
|
|
|
|
|
|
|
|
|
|
if ( strncmp (filename, KEYFILE_DIR, dir_len) != 0
|
|
|
|
|
|| filename[dir_len] != '/'
|
|
|
|
|
|| strchr (filename + dir_len + 1, '/') != NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (nm_keyfile_plugin_utils_should_ignore_file (filename + dir_len + 1))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
connection = find_by_path (self, filename);
|
|
|
|
|
if (connection)
|
|
|
|
|
update_connection (self, connection, filename);
|
|
|
|
|
else {
|
|
|
|
|
new_connection (self, filename, NULL);
|
|
|
|
|
connection = find_by_path (self, filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (connection != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-23 19:05:40 -03:00
|
|
|
static void
|
|
|
|
|
reload_connections (NMSystemConfigInterface *config)
|
|
|
|
|
{
|
|
|
|
|
read_connections (config);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-26 11:38:12 -06:00
|
|
|
static NMSettingsConnection *
|
2008-08-12 18:39:03 +00:00
|
|
|
add_connection (NMSystemConfigInterface *config,
|
|
|
|
|
NMConnection *connection,
|
2013-04-12 16:09:29 -05:00
|
|
|
gboolean save_to_disk,
|
2008-08-12 18:39:03 +00:00
|
|
|
GError **error)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
2010-10-29 14:34:33 -05:00
|
|
|
SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
|
2014-06-11 13:24:10 -05:00
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (self);
|
2011-01-26 11:38:12 -06:00
|
|
|
NMSettingsConnection *added = NULL;
|
2010-10-29 14:34:33 -05:00
|
|
|
char *path = NULL;
|
|
|
|
|
|
2013-04-12 16:09:29 -05:00
|
|
|
if (save_to_disk) {
|
|
|
|
|
if (!nm_keyfile_plugin_write_connection (connection, NULL, &path, error))
|
|
|
|
|
return NULL;
|
2010-10-29 14:34:33 -05:00
|
|
|
}
|
2014-06-11 13:24:10 -05:00
|
|
|
|
|
|
|
|
added = (NMSettingsConnection *) nm_keyfile_connection_new (connection, path, error);
|
|
|
|
|
if (added) {
|
|
|
|
|
g_hash_table_insert (priv->connections,
|
|
|
|
|
g_strdup (nm_connection_get_uuid (NM_CONNECTION (added))),
|
|
|
|
|
added);
|
|
|
|
|
g_signal_connect (added, NM_SETTINGS_CONNECTION_REMOVED,
|
|
|
|
|
G_CALLBACK (connection_removed_cb),
|
|
|
|
|
self);
|
|
|
|
|
}
|
2013-04-12 16:09:29 -05:00
|
|
|
g_free (path);
|
2010-10-29 14:34:33 -05:00
|
|
|
return added;
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-06 14:13:26 -05:00
|
|
|
static gboolean
|
|
|
|
|
parse_key_file_allow_none (SCPluginKeyfilePrivate *priv,
|
|
|
|
|
GKeyFile *key_file,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
GError *local_error = NULL;
|
|
|
|
|
|
|
|
|
|
if (!g_key_file_load_from_file (key_file, priv->conf_file, G_KEY_FILE_NONE, &local_error)) {
|
|
|
|
|
if (g_error_matches (local_error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
|
|
|
|
g_clear_error (&local_error);
|
|
|
|
|
else {
|
|
|
|
|
g_propagate_prefixed_error (error, local_error,
|
|
|
|
|
"Error parsing file '%s': ",
|
|
|
|
|
priv->conf_file);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
static GSList *
|
2009-06-11 00:39:12 -04:00
|
|
|
get_unmanaged_specs (NMSystemConfigInterface *config)
|
2008-09-24 15:03:33 +00:00
|
|
|
{
|
2010-03-06 00:18:28 -08:00
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (config);
|
2008-09-24 15:03:33 +00:00
|
|
|
GKeyFile *key_file;
|
2009-06-11 00:39:12 -04:00
|
|
|
GSList *specs = NULL;
|
2008-09-24 15:03:33 +00:00
|
|
|
GError *error = NULL;
|
2013-03-06 14:00:41 -05:00
|
|
|
char *str;
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2012-01-13 16:42:58 -06:00
|
|
|
if (!priv->conf_file)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
key_file = g_key_file_new ();
|
2013-03-06 14:13:26 -05:00
|
|
|
if (!parse_key_file_allow_none (priv, key_file, &error))
|
2013-03-06 14:00:41 -05:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
str = g_key_file_get_value (key_file, "keyfile", "unmanaged-devices", NULL);
|
|
|
|
|
if (str) {
|
|
|
|
|
char **udis;
|
|
|
|
|
int i;
|
|
|
|
|
|
2014-08-15 14:36:28 -05:00
|
|
|
udis = g_strsplit_set (str, ";,", -1);
|
2013-03-06 14:00:41 -05:00
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
|
|
for (i = 0; udis[i] != NULL; i++) {
|
|
|
|
|
/* Verify unmanaged specification and add it to the list */
|
2014-07-04 15:59:19 -04:00
|
|
|
if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4, -1)) {
|
2013-03-06 14:00:41 -05:00
|
|
|
specs = g_slist_append (specs, udis[i]);
|
2013-03-14 11:58:06 +01:00
|
|
|
} else if (!strncmp (udis[i], "interface-name:", 15) && nm_utils_iface_valid_name (udis[i] + 15)) {
|
2013-02-12 18:00:48 -05:00
|
|
|
specs = g_slist_append (specs, udis[i]);
|
2013-03-06 14:00:41 -05:00
|
|
|
} else {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "Error in file '%s': invalid unmanaged-devices entry: '%s'", priv->conf_file, udis[i]);
|
2013-03-06 14:00:41 -05:00
|
|
|
g_free (udis[i]);
|
2010-11-23 16:27:21 +01:00
|
|
|
}
|
2008-09-24 15:03:33 +00:00
|
|
|
}
|
2013-03-06 14:00:41 -05:00
|
|
|
|
|
|
|
|
g_free (udis); /* Yes, g_free, not g_strfreev because we need the strings in the list */
|
2008-09-24 15:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
out:
|
|
|
|
|
if (error) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s", error->message);
|
2013-03-06 14:00:41 -05:00
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
if (key_file)
|
|
|
|
|
g_key_file_free (key_file);
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2009-06-11 00:39:12 -04:00
|
|
|
return specs;
|
2008-09-24 15:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
plugin_get_hostname (SCPluginKeyfile *plugin)
|
|
|
|
|
{
|
2010-03-06 00:18:28 -08:00
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin);
|
2008-09-24 15:03:33 +00:00
|
|
|
GKeyFile *key_file;
|
2008-09-24 16:49:59 +00:00
|
|
|
char *hostname = NULL;
|
2008-09-24 15:03:33 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2012-01-13 16:42:58 -06:00
|
|
|
if (!priv->conf_file)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
key_file = g_key_file_new ();
|
2013-03-06 14:13:26 -05:00
|
|
|
if (!parse_key_file_allow_none (priv, key_file, &error))
|
2013-03-06 14:00:41 -05:00
|
|
|
goto out;
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
hostname = g_key_file_get_value (key_file, "keyfile", "hostname", NULL);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (error) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s", error->message);
|
2013-03-06 14:00:41 -05:00
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
if (key_file)
|
|
|
|
|
g_key_file_free (key_file);
|
2008-09-24 15:03:33 +00:00
|
|
|
|
|
|
|
|
return hostname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
plugin_set_hostname (SCPluginKeyfile *plugin, const char *hostname)
|
|
|
|
|
{
|
2013-03-06 14:00:41 -05:00
|
|
|
gboolean ret = FALSE;
|
2008-09-24 15:03:33 +00:00
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin);
|
2013-03-06 14:00:41 -05:00
|
|
|
GKeyFile *key_file = NULL;
|
2008-09-24 15:03:33 +00:00
|
|
|
GError *error = NULL;
|
2013-03-06 14:00:41 -05:00
|
|
|
char *data = NULL;
|
|
|
|
|
gsize len;
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2012-01-13 16:42:58 -06:00
|
|
|
if (!priv->conf_file) {
|
2013-03-06 14:00:41 -05:00
|
|
|
g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
|
|
|
"Error saving hostname: no config file");
|
|
|
|
|
goto out;
|
2012-01-13 16:42:58 -06:00
|
|
|
}
|
|
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
g_free (priv->hostname);
|
|
|
|
|
priv->hostname = g_strdup (hostname);
|
|
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
key_file = g_key_file_new ();
|
2013-03-06 14:13:26 -05:00
|
|
|
if (!parse_key_file_allow_none (priv, key_file, &error))
|
2013-03-06 14:00:41 -05:00
|
|
|
goto out;
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
g_key_file_set_string (key_file, "keyfile", "hostname", hostname);
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
data = g_key_file_to_data (key_file, &len, &error);
|
|
|
|
|
if (!data)
|
|
|
|
|
goto out;
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
if (!g_file_set_contents (priv->conf_file, data, len, &error)) {
|
|
|
|
|
g_prefix_error (&error, "Error saving hostname: ");
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
ret = TRUE;
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (error) {
|
2014-04-05 09:37:04 -04:00
|
|
|
nm_log_warn (LOGD_SETTINGS, "%s", error->message);
|
2008-09-24 15:03:33 +00:00
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2013-03-06 14:00:41 -05:00
|
|
|
g_free (data);
|
|
|
|
|
if (key_file)
|
|
|
|
|
g_key_file_free (key_file);
|
2008-09-24 15:03:33 +00:00
|
|
|
|
2013-03-06 14:00:41 -05:00
|
|
|
return ret;
|
2008-09-24 15:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
2008-04-22 14:48:02 +00:00
|
|
|
/* GObject */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sc_plugin_keyfile_init (SCPluginKeyfile *plugin)
|
|
|
|
|
{
|
2013-04-18 13:54:36 -05:00
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (plugin);
|
|
|
|
|
|
2014-06-11 13:24:10 -05:00
|
|
|
priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
get_property (GObject *object, guint prop_id,
|
|
|
|
|
GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME:
|
|
|
|
|
g_value_set_string (value, KEYFILE_PLUGIN_NAME);
|
|
|
|
|
break;
|
|
|
|
|
case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO:
|
|
|
|
|
g_value_set_string (value, KEYFILE_PLUGIN_INFO);
|
|
|
|
|
break;
|
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
|
|
|
case NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES:
|
2008-09-24 15:03:33 +00:00
|
|
|
g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS |
|
|
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME);
|
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
|
|
|
break;
|
|
|
|
|
case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
|
2008-09-24 15:03:33 +00:00
|
|
|
g_value_set_string (value, SC_PLUGIN_KEYFILE_GET_PRIVATE (object)->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)
|
|
|
|
|
{
|
|
|
|
|
const char *hostname;
|
|
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
|
|
|
|
|
hostname = g_value_get_string (value);
|
|
|
|
|
if (hostname && strlen (hostname) < 1)
|
|
|
|
|
hostname = NULL;
|
|
|
|
|
plugin_set_hostname (SC_PLUGIN_KEYFILE (object), hostname);
|
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
|
|
|
break;
|
2008-04-22 14:48:02 +00:00
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
SCPluginKeyfilePrivate *priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (object);
|
|
|
|
|
|
|
|
|
|
if (priv->disposed)
|
2013-10-18 17:55:52 +02:00
|
|
|
goto out;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
priv->disposed = TRUE;
|
|
|
|
|
|
|
|
|
|
if (priv->monitor) {
|
|
|
|
|
if (priv->monitor_id)
|
|
|
|
|
g_signal_handler_disconnect (priv->monitor, priv->monitor_id);
|
|
|
|
|
|
|
|
|
|
g_file_monitor_cancel (priv->monitor);
|
|
|
|
|
g_object_unref (priv->monitor);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-24 15:03:33 +00:00
|
|
|
if (priv->conf_file_monitor) {
|
|
|
|
|
if (priv->conf_file_monitor_id)
|
|
|
|
|
g_signal_handler_disconnect (priv->conf_file_monitor, priv->conf_file_monitor_id);
|
|
|
|
|
|
|
|
|
|
g_file_monitor_cancel (priv->conf_file_monitor);
|
|
|
|
|
g_object_unref (priv->conf_file_monitor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (priv->hostname);
|
|
|
|
|
|
2013-04-18 13:54:36 -05:00
|
|
|
if (priv->connections) {
|
|
|
|
|
g_hash_table_destroy (priv->connections);
|
|
|
|
|
priv->connections = NULL;
|
|
|
|
|
}
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2013-10-18 17:55:52 +02:00
|
|
|
out:
|
2008-04-22 14:48:02 +00:00
|
|
|
G_OBJECT_CLASS (sc_plugin_keyfile_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sc_plugin_keyfile_class_init (SCPluginKeyfileClass *req_class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (req_class);
|
|
|
|
|
|
|
|
|
|
g_type_class_add_private (req_class, sizeof (SCPluginKeyfilePrivate));
|
|
|
|
|
|
|
|
|
|
object_class->dispose = dispose;
|
|
|
|
|
object_class->get_property = get_property;
|
2008-09-24 15:03:33 +00:00
|
|
|
object_class->set_property = set_property;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
g_object_class_override_property (object_class,
|
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
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME,
|
|
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_NAME);
|
|
|
|
|
|
|
|
|
|
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_CAPABILITIES,
|
|
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_CAPABILITIES);
|
2008-04-22 14:48:02 +00:00
|
|
|
|
|
|
|
|
g_object_class_override_property (object_class,
|
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
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME,
|
|
|
|
|
NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
system_config_interface_init (NMSystemConfigInterface *system_config_interface_class)
|
|
|
|
|
{
|
|
|
|
|
/* interface implementation */
|
|
|
|
|
system_config_interface_class->get_connections = get_connections;
|
2013-10-31 15:17:33 -04:00
|
|
|
system_config_interface_class->load_connection = load_connection;
|
2013-05-23 19:05:40 -03:00
|
|
|
system_config_interface_class->reload_connections = reload_connections;
|
2008-04-22 14:48:02 +00:00
|
|
|
system_config_interface_class->add_connection = add_connection;
|
2009-06-11 00:39:12 -04:00
|
|
|
system_config_interface_class->get_unmanaged_specs = get_unmanaged_specs;
|
2008-04-22 14:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-12 18:12:23 -06:00
|
|
|
GObject *
|
2013-03-12 11:11:54 -04:00
|
|
|
nm_settings_keyfile_plugin_new (void)
|
2008-04-22 14:48:02 +00:00
|
|
|
{
|
|
|
|
|
static SCPluginKeyfile *singleton = NULL;
|
2011-11-15 13:30:16 +01:00
|
|
|
SCPluginKeyfilePrivate *priv;
|
2008-04-22 14:48:02 +00:00
|
|
|
|
2011-11-15 13:30:16 +01:00
|
|
|
if (!singleton) {
|
2008-04-22 14:48:02 +00:00
|
|
|
singleton = SC_PLUGIN_KEYFILE (g_object_new (SC_TYPE_PLUGIN_KEYFILE, NULL));
|
2013-01-31 15:36:12 -05:00
|
|
|
priv = SC_PLUGIN_KEYFILE_GET_PRIVATE (singleton);
|
2011-11-15 13:30:16 +01:00
|
|
|
|
2013-03-12 11:11:54 -04:00
|
|
|
priv->conf_file = nm_config_get_path (nm_config_get ());
|
2011-11-15 13:30:16 +01:00
|
|
|
|
2013-01-31 15:36:12 -05:00
|
|
|
/* plugin_set_hostname() has to be called *after* priv->conf_file is set */
|
|
|
|
|
priv->hostname = plugin_get_hostname (singleton);
|
2011-11-15 13:30:16 +01:00
|
|
|
} else
|
2008-04-22 14:48:02 +00:00
|
|
|
g_object_ref (singleton);
|
|
|
|
|
|
|
|
|
|
return G_OBJECT (singleton);
|
|
|
|
|
}
|