diff options
Diffstat (limited to 'libnm-glib/nm-vpn-plugin.c')
| -rw-r--r-- | libnm-glib/nm-vpn-plugin.c | 57 |
1 files changed, 21 insertions, 36 deletions
diff --git a/libnm-glib/nm-vpn-plugin.c b/libnm-glib/nm-vpn-plugin.c index 67ddd83b..2af9deb4 100644 --- a/libnm-glib/nm-vpn-plugin.c +++ b/libnm-glib/nm-vpn-plugin.c @@ -29,6 +29,7 @@ #include "nm-utils.h" #include "nm-connection.h" #include "nm-dbus-glib-types.h" +#include "nm-setting-private.h" static gboolean impl_vpn_plugin_connect (NMVPNPlugin *plugin, GHashTable *connection, @@ -301,12 +302,15 @@ fail_stop (gpointer data) } static void -schedule_fail_stop (NMVPNPlugin *plugin) +schedule_fail_stop (NMVPNPlugin *plugin, guint timeout_secs) { NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); nm_clear_g_source (&priv->fail_stop_id); - priv->fail_stop_id = g_idle_add (fail_stop, plugin); + if (timeout_secs) + priv->fail_stop_id = g_timeout_add_seconds (timeout_secs, fail_stop, plugin); + else + priv->fail_stop_id = g_idle_add (fail_stop, plugin); } static void @@ -439,6 +443,7 @@ _connect_generic (NMVPNPlugin *plugin, NMConnection *connection; gboolean success = FALSE; GError *local = NULL; + guint fail_stop_timeout = 0; if (priv->state != NM_VPN_SERVICE_STATE_STOPPED && priv->state != NM_VPN_SERVICE_STATE_INIT) { @@ -448,15 +453,7 @@ _connect_generic (NMVPNPlugin *plugin, return FALSE; } - connection = nm_connection_new_from_hash (properties, &local); - if (!connection) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, - "Invalid connection: (%d) %s", - local->code, local->message); - g_clear_error (&local); - return FALSE; - } - + connection = _nm_connection_new_from_hash (properties); priv->interactive = FALSE; if (details && !vpn_class->connect_interactive) { @@ -465,22 +462,29 @@ _connect_generic (NMVPNPlugin *plugin, return FALSE; } - nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); + nm_clear_g_source (&priv->fail_stop_id); if (details) { priv->interactive = TRUE; - success = vpn_class->connect_interactive (plugin, connection, details, error); + success = vpn_class->connect_interactive (plugin, connection, details, &local); + if (g_error_matches (local, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED)) { + /* Give NetworkManager a bit of time to fall back to Connect() */ + fail_stop_timeout = 5; + } + g_propagate_error (error, local); } else success = vpn_class->connect (plugin, connection, error); if (success) { + nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING); + /* Add a timer to make sure we do not wait indefinitely for the successful connect. */ connect_timer_start (plugin); } else { /* Stop the plugin from an idle handler so that the Connect * method return gets sent before the STOP StateChanged signal. */ - schedule_fail_stop (plugin); + schedule_fail_stop (plugin, fail_stop_timeout); } g_object_unref (connection); @@ -517,22 +521,11 @@ impl_vpn_plugin_need_secrets (NMVPNPlugin *plugin, char *sn = NULL; GError *ns_err = NULL; gboolean needed = FALSE; - GError *cnfh_err = NULL; g_return_val_if_fail (NM_IS_VPN_PLUGIN (plugin), FALSE); g_return_val_if_fail (properties != NULL, FALSE); - connection = nm_connection_new_from_hash (properties, &cnfh_err); - if (!connection) { - g_set_error (err, - NM_VPN_PLUGIN_ERROR, - NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, - "The connection was invalid: '%s' / '%s' invalid: %d.", - g_type_name (nm_connection_lookup_setting_type_by_quark (cnfh_err->domain)), - cnfh_err->message, cnfh_err->code); - g_error_free (cnfh_err); - return FALSE; - } + connection = _nm_connection_new_from_hash (properties); if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->need_secrets) { *setting_name = ""; @@ -572,7 +565,6 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin, { NMVPNPluginPrivate *priv = NM_VPN_PLUGIN_GET_PRIVATE (plugin); NMConnection *connection; - GError *local = NULL; gboolean success; if (priv->state != NM_VPN_SERVICE_STATE_STARTING) { @@ -582,14 +574,7 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin, return FALSE; } - connection = nm_connection_new_from_hash (properties, &local); - if (!connection) { - g_set_error (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, - "Invalid connection: (%d) %s", - local->code, local->message); - g_clear_error (&local); - return FALSE; - } + connection = _nm_connection_new_from_hash (properties); if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) { g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED, @@ -606,7 +591,7 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin, /* Stop the plugin from and idle handler so that the NewSecrets * method return gets sent before the STOP StateChanged signal. */ - schedule_fail_stop (plugin); + schedule_fail_stop (plugin, 0); } g_object_unref (connection); |