From 1f313f36f09a0f0bbbfcae485e6f1e622a682ac8 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 9 Feb 2011 18:41:48 -0600 Subject: [PATCH] settings: do some basic validate in AddConnection Like making sure the connection verifies, and making sure the new connection's UUID is indeed unique. --- src/settings/nm-settings.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index b28ae36dde..7276094fa4 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -749,6 +749,21 @@ add_new_connection (NMSettings *self, NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); GSList *iter; NMSettingsConnection *added = NULL; + GHashTableIter citer; + NMConnection *candidate = NULL; + + /* Make sure a connection with this UUID doesn't already exist */ + g_hash_table_iter_init (&citer, priv->connections); + while (g_hash_table_iter_next (&citer, NULL, (gpointer *) &candidate)) { + if (g_strcmp0 (nm_connection_get_uuid (connection), + nm_connection_get_uuid (candidate)) == 0) { + g_set_error_literal (error, + NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_UUID_EXISTS, + "A connection with this UUID already exists."); + return NULL; + } + } /* 1) plugin writes the NMConnection to disk * 2) plugin creates a new NMSettingsConnection subclass with the settings @@ -881,7 +896,20 @@ nm_settings_add_connection (NMSettings *self, { NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self); NMAuthChain *chain; - GError *error; + GError *error = NULL, *tmp_error = NULL; + + /* Connection must be valid, of course */ + if (!nm_connection_verify (connection, &tmp_error)) { + error = g_error_new (NM_SETTINGS_ERROR, + NM_SETTINGS_ERROR_INVALID_CONNECTION, + "The connection was invalid: %s", + tmp_error ? tmp_error->message : "(unknown)"); + g_error_free (tmp_error); + + callback (self, NULL, error, context, user_data); + g_error_free (error); + return; + } /* Do any of the plugins support adding? */ if (!get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS)) {