From 8ec031fb0ebeedbd6da4a5981395352514008276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Fri, 1 Nov 2013 13:59:57 +0100 Subject: [PATCH] core: again allow calling AddAndActivateConnection() without a connection When settings are NULL or empty in impl_manager_add_and_activate_connection(), the connection is created and completed by nm_utils_complete_generic() or nm_device_complete_connection(). Also, do not assert in nm_connection_is_type(). Returning FALSE there is sufficient. Related commit a878cd814564e9d349eb8fd4f7d7d5d81d4aecaf --- libnm-util/nm-connection.c | 3 ++- src/nm-manager.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c index ab971c20ff..fec2950964 100644 --- a/libnm-util/nm-connection.c +++ b/libnm-util/nm-connection.c @@ -956,7 +956,8 @@ nm_connection_is_type (NMConnection *connection, const char *type) g_return_val_if_fail (type != NULL, FALSE); s_con = nm_connection_get_setting_connection (connection); - g_assert (s_con); + if (!s_con) + return FALSE; type2 = nm_setting_connection_get_connection_type (s_con); diff --git a/src/nm-manager.c b/src/nm-manager.c index 3a54bc4d29..9aa40e68a4 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3299,15 +3299,16 @@ impl_manager_add_and_activate_connection (NMManager *self, NMDevice *device = NULL; gboolean vpn = FALSE; - if (!settings || !g_hash_table_size (settings)) { - error = g_error_new_literal (NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION, - "Settings required to create a connection."); - goto error; - } - - /* Try to create a new connection with the given settings */ + /* Try to create a new connection with the given settings. + * We allow empty settings for AddAndActivateConnection(). In that case, + * the connection will be completed in nm_utils_complete_generic() or + * nm_device_complete_connection() below. Just make sure we don't expect + * specific data being in the connection till then (especially in + * validate_activation_request()). + */ connection = nm_connection_new (); - nm_connection_replace_settings (connection, settings, NULL); + if (settings && g_hash_table_size (settings)) + nm_connection_replace_settings (connection, settings, NULL); subject = validate_activation_request (self, context,