diff options
author | Thomas Haller <thaller@redhat.com> | 2022-11-16 21:25:30 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-11-17 12:38:45 +0100 |
commit | e65a19781e3ceb5e910f0aee13c18da683a97653 (patch) | |
tree | d6c7910a6cd93d1218a62ac45c4cf7d9b7162ef4 /src/connection-editor/connection-helpers.c | |
parent | 3ff5b6cc984162c27949139306bd5acb9a6ea0e0 (diff) | |
download | network-manager-applet-e65a19781e3ceb5e910f0aee13c18da683a97653.tar.gz |
c-e: honor selected VPN plugin during import
When calling
nm-connection-editor -i basic.pcf -t vpn:vpnc
then the import should only try the VPNC plugin. For that to work,
we need to honor the detail and pass it on to the import code, to
only use the selected VPN plugin.
Diffstat (limited to 'src/connection-editor/connection-helpers.c')
-rw-r--r-- | src/connection-editor/connection-helpers.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c index 7ef75c67..a58a2fbb 100644 --- a/src/connection-editor/connection-helpers.c +++ b/src/connection-editor/connection-helpers.c @@ -163,7 +163,10 @@ no_description: } NMConnection * -connection_import_from_file (const char *filename, GType ctype, GError **error) +connection_import_from_file (const char *filename, + GType ctype, + const char *vpn_detail, + GError **error) { gs_free_error GError *unused_error = NULL; NMConnection *connection = NULL; @@ -181,14 +184,32 @@ connection_import_from_file (const char *filename, GType ctype, GError **error) } if (NM_IN_SET (ctype, G_TYPE_INVALID, NM_TYPE_SETTING_VPN)) { - for (iter = vpn_get_plugin_infos (); !connection && iter; iter = iter->next) { - NMVpnEditorPlugin *plugin; + GSList *plugin_infos = vpn_get_plugin_infos (); + NMVpnPluginInfo *plugin_info; + NMVpnEditorPlugin *plugin; - plugin = nm_vpn_plugin_info_get_editor_plugin (iter->data); - g_clear_error (error); - connection = nm_vpn_editor_plugin_import (plugin, filename, error); - if (connection) - break; + if (vpn_detail) { + gs_free char *service_type = NULL; + + if ((service_type = + nm_vpn_plugin_info_list_find_service_type (plugin_infos, vpn_detail)) && + (plugin_info = + nm_vpn_plugin_info_list_find_by_service (plugin_infos, service_type))) { + plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info); + connection = nm_vpn_editor_plugin_import (plugin, filename, error); + } else { + g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, + _("VPN plugin ā%sā not found"), vpn_detail); + } + } else { + for (iter = plugin_infos; iter; iter = iter->next) { + plugin_info = iter->data; + plugin = nm_vpn_plugin_info_get_editor_plugin (plugin_info); + g_clear_error (error); + connection = nm_vpn_editor_plugin_import (plugin, filename, error); + if (connection) + break; + } } if (connection) { @@ -248,7 +269,7 @@ import_vpn_from_file_cb (GtkWidget *dialog, gint response, gpointer user_data) } canceled = FALSE; - connection = connection_import_from_file (filename, G_TYPE_INVALID, &error); + connection = connection_import_from_file (filename, G_TYPE_INVALID, NULL, &error); if (!connection) { /* pass */ } else if (nm_streq (nm_connection_get_connection_type (connection), |