mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-20 17:55:49 +00:00
vpn: fix connecting to VPN (bgo #708255)
The ConnectInteractive() -> Connect() fallback code doesn't work, because _connect_internal() changes the state to NM_VPN_SERVICE_STATE_STARTING before checking if it can implement ConnectInteractive(), and then when the Connect() call comes in, the VPN is not in STOPPED or INIT, so it returns an error. The commit moves setting state to STARTING after the ConnectInteractive() check availability, in the plugin. We introduce new plugin error and set it when the the plugin does not implement ConnectInteractive(). NetworkManager uses this error for ConnectInteractive() -> Connect() fallback. https://bugzilla.gnome.org/show_bug.cgi?id=708255
This commit is contained in:
parent
f9bb4bb2ca
commit
9dff830692
|
@ -47,6 +47,7 @@
|
|||
#define NM_DBUS_VPN_ALREADY_STOPPED "AlreadyStopped"
|
||||
#define NM_DBUS_VPN_WRONG_STATE "WrongState"
|
||||
#define NM_DBUS_VPN_BAD_ARGUMENTS "BadArguments"
|
||||
#define NM_DBUS_VPN_INTERACTIVE_NOT_SUPPORTED "InteractiveNotSupported"
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.BadArguments"/>
|
||||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.LaunchFailed"/>
|
||||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.WrongState"/>
|
||||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.InteractiveNotSupported"/>
|
||||
</tp:possible-errors>
|
||||
</method>
|
||||
|
||||
|
@ -191,6 +192,7 @@
|
|||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.WrongState"/>
|
||||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.BadArguments"/>
|
||||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.LaunchFailed"/>
|
||||
<tp:error name="org.freedesktop.NetworkManager.VPN.Error.InteractiveNotSupported"/>
|
||||
</tp:possible-errors>
|
||||
</method>
|
||||
|
||||
|
|
|
@ -28,5 +28,11 @@
|
|||
<tp:error name="ConnectionInvalid">
|
||||
<tp:docstring>The request could not be processed because the VPN connection settings were invalid.</tp:docstring>
|
||||
</tp:error>
|
||||
<tp:error name="InteractiveNotSupported">
|
||||
<tp:docstring>
|
||||
The request could not be processed because the plugin does not support
|
||||
interactive operations, such as ConnectInteractive() or NewSecrets().
|
||||
</tp:docstring>
|
||||
</tp:error>
|
||||
</tp:errors>
|
||||
|
||||
|
|
|
@ -457,15 +457,16 @@ _connect_generic (NMVPNPlugin *plugin,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING);
|
||||
|
||||
priv->interactive = FALSE;
|
||||
if (details && !vpn_class->connect_interactive) {
|
||||
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_GENERAL,
|
||||
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED,
|
||||
"Plugin does not implement ConnectInteractive()");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STARTING);
|
||||
|
||||
if (details) {
|
||||
priv->interactive = TRUE;
|
||||
success = vpn_class->connect_interactive (plugin, connection, details, error);
|
||||
|
@ -586,7 +587,7 @@ impl_vpn_plugin_new_secrets (NMVPNPlugin *plugin,
|
|||
}
|
||||
|
||||
if (!NM_VPN_PLUGIN_GET_CLASS (plugin)->new_secrets) {
|
||||
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_GENERAL,
|
||||
g_set_error_literal (error, NM_VPN_PLUGIN_ERROR, NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED,
|
||||
"Could not accept new secrets: plugin cannot process interactive secrets");
|
||||
g_object_unref (connection);
|
||||
return FALSE;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2007 - 2008 Novell, Inc.
|
||||
* Copyright (C) 2007 - 2008 Red Hat, Inc.
|
||||
* Copyright (C) 2007 - 2013 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef NM_VPN_PLUGIN_H
|
||||
|
@ -63,19 +63,23 @@ G_BEGIN_DECLS
|
|||
* @NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID: the operation could not be performed
|
||||
* because the connection was invalid. Usually means that the connection's
|
||||
* VPN setting was missing some required data item or secret.
|
||||
* @NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED: the operation could not be
|
||||
* performed as the plugin does not support interactive operations, such as
|
||||
* ConnectInteractive() or NewSecrets()
|
||||
*
|
||||
* Returned by the VPN service plugin to indicate errors.
|
||||
**/
|
||||
typedef enum {
|
||||
NM_VPN_PLUGIN_ERROR_GENERAL, /*< nick=General >*/
|
||||
NM_VPN_PLUGIN_ERROR_STARTING_IN_PROGRESS, /*< nick=StartingInProgress >*/
|
||||
NM_VPN_PLUGIN_ERROR_ALREADY_STARTED, /*< nick=AlreadyStarted >*/
|
||||
NM_VPN_PLUGIN_ERROR_STOPPING_IN_PROGRESS, /*< nick=StoppingInProgress >*/
|
||||
NM_VPN_PLUGIN_ERROR_ALREADY_STOPPED, /*< nick=AlreadyStopped >*/
|
||||
NM_VPN_PLUGIN_ERROR_WRONG_STATE, /*< nick=WrongState >*/
|
||||
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, /*< nick=BadArguments >*/
|
||||
NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED, /*< nick=LaunchFailed >*/
|
||||
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/
|
||||
NM_VPN_PLUGIN_ERROR_GENERAL, /*< nick=General >*/
|
||||
NM_VPN_PLUGIN_ERROR_STARTING_IN_PROGRESS, /*< nick=StartingInProgress >*/
|
||||
NM_VPN_PLUGIN_ERROR_ALREADY_STARTED, /*< nick=AlreadyStarted >*/
|
||||
NM_VPN_PLUGIN_ERROR_STOPPING_IN_PROGRESS, /*< nick=StoppingInProgress >*/
|
||||
NM_VPN_PLUGIN_ERROR_ALREADY_STOPPED, /*< nick=AlreadyStopped >*/
|
||||
NM_VPN_PLUGIN_ERROR_WRONG_STATE, /*< nick=WrongState >*/
|
||||
NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS, /*< nick=BadArguments >*/
|
||||
NM_VPN_PLUGIN_ERROR_LAUNCH_FAILED, /*< nick=LaunchFailed >*/
|
||||
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID, /*< nick=ConnectionInvalid >*/
|
||||
NM_VPN_PLUGIN_ERROR_INTERACTIVE_NOT_SUPPORTED /*< nick=InteractiveNotSupported >*/
|
||||
} NMVPNPluginError;
|
||||
|
||||
#define NM_VPN_PLUGIN_ERROR (nm_vpn_plugin_error_quark ())
|
||||
|
|
|
@ -1181,11 +1181,20 @@ connect_interactive_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data
|
|||
return;
|
||||
}
|
||||
|
||||
/* Fall back to Connect() */
|
||||
dbus_g_proxy_begin_call (priv->proxy, "Connect",
|
||||
connect_cb, self, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, priv->connect_hash,
|
||||
G_TYPE_INVALID);
|
||||
if (dbus_g_error_has_name (err, "org.freedesktop.NetworkManager.VPN.Plugin.InteractiveNotSupported")) {
|
||||
/* Fall back to Connect() */
|
||||
dbus_g_proxy_begin_call (priv->proxy, "Connect",
|
||||
connect_cb, self, NULL,
|
||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, priv->connect_hash,
|
||||
G_TYPE_INVALID);
|
||||
} else {
|
||||
nm_log_warn (LOGD_VPN, "VPN connection '%s' failed to connect interactively: '%s'.",
|
||||
nm_connection_get_id (priv->connection), err->message);
|
||||
g_error_free (err);
|
||||
nm_vpn_connection_set_vpn_state (self,
|
||||
NM_VPN_CONNECTION_STATE_FAILED,
|
||||
NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a username to a hashed connection */
|
||||
|
|
Loading…
Reference in a new issue