From a8d660a0c5d007e79d7c620bebc36ca0aad788f3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 16 Nov 2022 21:22:45 +0100 Subject: c-e: don't reset VPN connection during import nm-connection-editor -i basic.pcf -t vpn:vpnc should import the profile of type vpnc. This did not work and opened an empty VPN window. The reason is that the imported profile gets reset. Avoid that. --- src/connection-editor/ce-page.c | 24 ++++++++++++++---------- src/connection-editor/page-vpn.c | 11 +++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c index 1e523e47..d808912e 100644 --- a/src/connection-editor/ce-page.c +++ b/src/connection-editor/ce-page.c @@ -859,8 +859,6 @@ ce_page_complete_connection (NMConnection *connection, NMClient *client) { NMSettingConnection *s_con; - char *id, *uuid; - const GPtrArray *connections; s_con = nm_connection_get_setting_connection (connection); if (!s_con) { @@ -869,19 +867,25 @@ ce_page_complete_connection (NMConnection *connection, } if (!nm_setting_connection_get_id (s_con)) { + const GPtrArray *connections; + gs_free char *id = NULL; + connections = nm_client_get_connections (client); id = ce_page_get_next_available_name (connections, format); g_object_set (s_con, NM_SETTING_CONNECTION_ID, id, NULL); - g_free (id); } - uuid = nm_utils_uuid_generate (); - g_object_set (s_con, - NM_SETTING_CONNECTION_UUID, uuid, - NM_SETTING_CONNECTION_TYPE, ctype, - NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect, - NULL); - g_free (uuid); + if (!nm_setting_connection_get_uuid (s_con)) { + gs_free char *uuid = NULL; + + uuid = nm_utils_uuid_generate (); + g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL); + } + + if (ctype) + g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, ctype, NULL); + + g_object_set (s_con, NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect, NULL); } CEPage * diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c index 0eab8b62..194cd4c7 100644 --- a/src/connection-editor/page-vpn.c +++ b/src/connection-editor/page-vpn.c @@ -256,6 +256,7 @@ vpn_connection_new (FUNC_TAG_PAGE_NEW_CONNECTION_IMPL, } connection = _ensure_connection_other (connection, &connection_tmp); + if (detail) { service_type = detail; add_detail_key = vpn_data ? vpn_data->add_detail_key : NULL; @@ -300,8 +301,14 @@ vpn_connection_new (FUNC_TAG_PAGE_NEW_CONNECTION_IMPL, if (!service_type) service_type = detail; - s_vpn = nm_setting_vpn_new (); - g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, service_type, NULL); + s_vpn = NM_SETTING (nm_connection_get_setting_vpn (connection)); + if (!s_vpn) + s_vpn = nm_setting_vpn_new (); + else + g_object_ref (s_vpn); + + if (!nm_setting_vpn_get_service_type (NM_SETTING_VPN(s_vpn))) + g_object_set (s_vpn, NM_SETTING_VPN_SERVICE_TYPE, service_type, NULL); if (add_detail_key) nm_setting_vpn_add_data_item ((NMSettingVpn *) s_vpn, add_detail_key, add_detail_val); -- cgit v1.2.1