Commit 29eb46b1 authored by Thomas Haller's avatar Thomas Haller

settings: merge branch 'th/uuid-duplicate-rh1171751'

https://bugzilla.redhat.com/show_bug.cgi?id=1171751
parents 91fd36e1 4475f59b
......@@ -2091,9 +2091,9 @@ nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base,
connection_diff_are_same = nm_connection_diff (connection, diff_base, NM_SETTING_COMPARE_FLAG_EXACT | NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT, &connection_diff);
if (connection_diff_are_same) {
if (diff_base)
nm_log (level, domain, "%sconnection '%s' (%p and %p): no difference", prefix, name, connection, diff_base);
nm_log (level, domain, "%sconnection '%s' (%p/%s and %p/%s): no difference", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), diff_base, G_OBJECT_TYPE_NAME (diff_base));
else
nm_log (level, domain, "%sconnection '%s' (%p): no properties set", prefix, name, connection);
nm_log (level, domain, "%sconnection '%s' (%p/%s): no properties set", prefix, name, connection, G_OBJECT_TYPE_NAME (connection));
g_assert (!connection_diff);
return;
}
......@@ -2128,9 +2128,9 @@ nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base,
GError *err_verify = NULL;
if (diff_base)
nm_log (level, domain, "%sconnection '%s' (%p < %p):", prefix, name, connection, diff_base);
nm_log (level, domain, "%sconnection '%s' (%p/%s < %p/%s):", prefix, name, connection, G_OBJECT_TYPE_NAME (connection), diff_base, G_OBJECT_TYPE_NAME (diff_base));
else
nm_log (level, domain, "%sconnection '%s' (%p):", prefix, name, connection);
nm_log (level, domain, "%sconnection '%s' (%p/%s):", prefix, name, connection, G_OBJECT_TYPE_NAME (connection));
print_header = FALSE;
if (!nm_connection_verify (connection, &err_verify)) {
......
......@@ -148,8 +148,8 @@ notify (GObject *object, GParamSpec *pspec)
break;
}
if (!dbus_property_name) {
nm_log_dbg (LOGD_DBUS_PROPS, "ignoring notification for prop %s on type %s",
pspec->name, G_OBJECT_TYPE_NAME (object));
nm_log_trace (LOGD_DBUS_PROPS, "ignoring notification for prop %s on type %s",
pspec->name, G_OBJECT_TYPE_NAME (object));
return;
}
......
......@@ -450,6 +450,7 @@ gboolean
nm_settings_connection_replace_settings (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean update_unsaved,
const char *log_diff_name,
GError **error)
{
NMSettingsConnectionPrivate *priv;
......@@ -463,6 +464,15 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self,
if (!nm_connection_normalize (new_connection, NULL, NULL, error))
return FALSE;
if ( nm_connection_get_path (NM_CONNECTION (self))
&& g_strcmp0 (nm_connection_get_uuid (NM_CONNECTION (self)), nm_connection_get_uuid (new_connection)) != 0) {
/* Updating the UUID is not allowed once the path is exported. */
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
"connection %s cannot change the UUID from %s to %s", nm_connection_get_id (NM_CONNECTION (self)),
nm_connection_get_uuid (NM_CONNECTION (self)), nm_connection_get_uuid (new_connection));
return FALSE;
}
/* Do nothing if there's nothing to update */
if (nm_connection_compare (NM_CONNECTION (self),
new_connection,
......@@ -475,7 +485,8 @@ nm_settings_connection_replace_settings (NMSettingsConnection *self,
*/
g_signal_handlers_block_by_func (self, G_CALLBACK (changed_cb), GUINT_TO_POINTER (TRUE));
nm_utils_log_connection_diff (new_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, "update connection", "++ ");
if (log_diff_name)
nm_utils_log_connection_diff (new_connection, NM_CONNECTION (self), LOGL_DEBUG, LOGD_CORE, log_diff_name, "++ ");
nm_connection_replace_settings_from_connection (NM_CONNECTION (self), new_connection);
nm_settings_connection_set_flags (self,
......@@ -535,9 +546,10 @@ replace_and_commit (NMSettingsConnection *self,
{
GError *error = NULL;
if (nm_settings_connection_replace_settings (self, new_connection, TRUE, &error)) {
if (nm_settings_connection_replace_settings (self, new_connection, TRUE, "replace-and-commit-disk", &error))
nm_settings_connection_commit_changes (self, callback, user_data);
} else {
else {
g_assert (error);
if (callback)
callback (self, error, user_data);
g_clear_error (&error);
......@@ -1366,11 +1378,8 @@ update_auth_cb (NMSettingsConnection *self,
con_update_cb,
info);
} else {
/* Do nothing if there's nothing to update */
if (!nm_connection_compare (NM_CONNECTION (self), info->new_settings, NM_SETTING_COMPARE_FLAG_EXACT)) {
if (!nm_settings_connection_replace_settings (self, info->new_settings, TRUE, &local))
g_assert (local);
}
if (!nm_settings_connection_replace_settings (self, info->new_settings, TRUE, "replace-and-commit-memory", &local))
g_assert (local);
con_update_cb (self, local, info);
g_clear_error (&local);
}
......
......@@ -123,6 +123,7 @@ void nm_settings_connection_commit_changes (NMSettingsConnection *connection,
gboolean nm_settings_connection_replace_settings (NMSettingsConnection *self,
NMConnection *new_connection,
gboolean update_unsaved,
const char *log_diff_name,
GError **error);
void nm_settings_connection_replace_and_commit (NMSettingsConnection *self,
......
......@@ -886,6 +886,7 @@ claim_connection (NMSettings *self,
GHashTableIter iter;
gpointer data;
char *path;
NMSettingsConnection *existing;
g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
g_return_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);
......@@ -904,6 +905,23 @@ claim_connection (NMSettings *self,
return;
}
existing = nm_settings_get_connection_by_uuid (self, nm_connection_get_uuid (NM_CONNECTION (connection)));
if (existing) {
/* Cannot add duplicate connections per UUID. Just return without action and
* log a warning.
*
* This means, that plugins must not provide duplicate connections (UUID).
* In fact, none of the plugins currently would do that.
*
* But globaly, over different setting plugins, there could be duplicates
* without the individual plugins being aware. Don't handle that at all, just
* error out. That should not happen unless the admin misconfigured the system
* to create conflicting connections. */
nm_log_warn (LOGD_SETTINGS, "plugin provided duplicate connection with UUID %s",
nm_connection_get_uuid (NM_CONNECTION (connection)));
return;
}
/* Read timestamp from look-aside file and put it into the connection's data */
nm_settings_connection_read_and_fill_timestamp (connection);
......
......@@ -82,6 +82,7 @@ nm_example_connection_new (const char *full_path,
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
TRUE,
NULL,
error)) {
g_object_unref (object);
object = NULL;
......
......@@ -46,6 +46,7 @@ nm_ibft_connection_new (const GPtrArray *block, GError **error)
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
source,
FALSE,
NULL,
error))
g_clear_object (&object);
......
......@@ -41,7 +41,7 @@
#define IFCFG_DIR SYSCONFDIR"/sysconfig/network-scripts"
#define IFCFG_PLUGIN_NAME "ifcfg-rh"
#define IFCFG_PLUGIN_INFO "(c) 2007 - 2013 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define IFCFG_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define TYPE_ETHERNET "Ethernet"
#define TYPE_WIRELESS "Wireless"
......
......@@ -235,6 +235,7 @@ nm_ifcfg_connection_new (NMConnection *source,
if (nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
NULL,
error))
nm_ifcfg_connection_check_devtimeout (NM_IFCFG_CONNECTION (object));
else
......
This diff is collapsed.
......@@ -121,7 +121,7 @@ int main (int argc, char **argv)
{
char *base;
nmtst_init (&argc, &argv, TRUE);
nmtst_init_assert_logging (&argc, &argv);
/* The tests */
test_get_ifcfg_name ("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL);
......
......@@ -25,6 +25,13 @@
#include <nm-connection.h>
#include "shvar.h"
#include "common.h"
#include "nm-logging.h"
#define NM_IFCFG_CONNECTION_LOG_PATH(path) str_if_set (path,"in-memory")
#define NM_IFCFG_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
#define NM_IFCFG_CONNECTION_LOG_ARG(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
#define NM_IFCFG_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
#define NM_IFCFG_CONNECTION_LOG_ARGD(con) NM_IFCFG_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
char *utils_single_quote_string (const char *str);
......
......@@ -82,6 +82,7 @@ nm_ifnet_connection_new (NMConnection *source, const char *conn_name)
nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
NULL,
NULL);
g_object_unref (tmp);
......
......@@ -313,10 +313,13 @@ reload_connections (NMSystemConfigInterface *config)
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (old),
NM_CONNECTION (new),
FALSE, /* don't set Unsaved */
"ifnet-update",
&error)) {
/* Shouldn't ever get here as 'new' was verified by the reader already */
g_assert_no_error (error);
/* Shouldn't ever get here as 'new' was verified by the reader already
* and the UUID did not change. */
g_assert_not_reached ();
}
g_assert_no_error (error);
nm_log_info (LOGD_SETTINGS, "Connection %s updated",
nm_connection_get_id (NM_CONNECTION (new)));
}
......
......@@ -24,7 +24,7 @@
#include <glib.h>
#define KEYFILE_PLUGIN_NAME "keyfile"
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2013 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define KEYFILE_PLUGIN_INFO "(c) 2007 - 2015 Red Hat, Inc. To report bugs please use the NetworkManager mailing list."
#define KEYFILE_DIR NMCONFDIR "/system-connections"
......
......@@ -76,6 +76,7 @@ nm_keyfile_connection_new (NMConnection *source,
if (!nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp,
update_unsaved,
NULL,
error)) {
g_object_unref (object);
object = NULL;
......
This diff is collapsed.
......@@ -23,6 +23,13 @@
#include <glib.h>
#include "common.h"
#include "NetworkManagerUtils.h"
#define NM_KEYFILE_CONNECTION_LOG_PATH(path) str_if_set (path,"in-memory")
#define NM_KEYFILE_CONNECTION_LOG_FMT "%s (%s,\"%s\")"
#define NM_KEYFILE_CONNECTION_LOG_ARG(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con))
#define NM_KEYFILE_CONNECTION_LOG_FMTD "%s (%s,\"%s\",%p)"
#define NM_KEYFILE_CONNECTION_LOG_ARGD(con) NM_KEYFILE_CONNECTION_LOG_PATH (nm_settings_connection_get_filename ((NMSettingsConnection *) (con))), nm_connection_get_uuid ((NMConnection *) (con)), nm_connection_get_id ((NMConnection *) (con)), (con)
gboolean nm_keyfile_plugin_utils_should_ignore_file (const char *filename);
......
......@@ -813,13 +813,10 @@ _internal_write_connection (NMConnection *connection,
WriteInfo info;
GError *local_err = NULL;
if (out_path)
g_return_val_if_fail (*out_path == NULL, FALSE);
g_return_val_if_fail (!out_path || !*out_path, FALSE);
if (!nm_connection_verify (connection, error)) {
if (!nm_connection_verify (connection, error))
g_return_val_if_reached (FALSE);
return FALSE;
}
id = nm_connection_get_id (connection);
g_assert (id && *id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment