mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 05:58:01 +02:00
clients,cli: for connection-add consider VPNs as loaded from the plugin
Instead of using (only) a hard-coded list of VPN types,
prefer lookup the VPN settings from the .name files.
Still, fallback to a hard-coded list if the plugin cannot
be found, because for connection-add we currently don't
actually need the plugin installed.
(cherry picked from commit 41976e3069)
This commit is contained in:
parent
83ea6abc6c
commit
7c209b2a7d
3 changed files with 90 additions and 20 deletions
|
|
@ -53,21 +53,6 @@
|
||||||
#define PROMPT_IP_TUNNEL_MODE _("Tunnel mode: ")
|
#define PROMPT_IP_TUNNEL_MODE _("Tunnel mode: ")
|
||||||
#define PROMPT_MACVLAN_MODE _("MACVLAN mode: ")
|
#define PROMPT_MACVLAN_MODE _("MACVLAN mode: ")
|
||||||
|
|
||||||
static const char *nmc_known_vpns[] = {
|
|
||||||
"openvpn",
|
|
||||||
"vpnc",
|
|
||||||
"pptp",
|
|
||||||
"openconnect",
|
|
||||||
"openswan",
|
|
||||||
"libreswan",
|
|
||||||
"strongswan",
|
|
||||||
"ssh",
|
|
||||||
"l2tp",
|
|
||||||
"iodine",
|
|
||||||
"fortisslvpn",
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Available fields for 'connection show' */
|
/* Available fields for 'connection show' */
|
||||||
static NmcOutputField nmc_fields_con_show[] = {
|
static NmcOutputField nmc_fields_con_show[] = {
|
||||||
{"NAME", N_("NAME")}, /* 0 */
|
{"NAME", N_("NAME")}, /* 0 */
|
||||||
|
|
@ -5904,10 +5889,12 @@ cleanup_bridge_slave:
|
||||||
const char *user_c = NULL;
|
const char *user_c = NULL;
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
const char *st;
|
const char *st;
|
||||||
char *service_type = NULL;
|
gs_free char *service_type_free = NULL;
|
||||||
|
const char *service_type = NULL;
|
||||||
nmc_arg_t exp_args[] = { {"vpn-type", TRUE, &vpn_type, !ask},
|
nmc_arg_t exp_args[] = { {"vpn-type", TRUE, &vpn_type, !ask},
|
||||||
{"user", TRUE, &user_c, FALSE},
|
{"user", TRUE, &user_c, FALSE},
|
||||||
{NULL} };
|
{NULL} };
|
||||||
|
gs_free const char **plugin_names = NULL;
|
||||||
|
|
||||||
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
|
if (!nmc_parse_args (exp_args, FALSE, &argc, &argv, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
@ -5922,11 +5909,15 @@ cleanup_bridge_slave:
|
||||||
if (vpn_type_ask)
|
if (vpn_type_ask)
|
||||||
vpn_type = g_strstrip (vpn_type_ask);
|
vpn_type = g_strstrip (vpn_type_ask);
|
||||||
|
|
||||||
if (!(st = nmc_string_is_valid (vpn_type, nmc_known_vpns, NULL))) {
|
plugin_names = nm_vpn_get_plugin_names (FALSE);
|
||||||
|
if (!(st = nmc_string_is_valid (vpn_type, plugin_names, NULL))) {
|
||||||
g_print (_("Warning: 'vpn-type': %s not known.\n"), vpn_type);
|
g_print (_("Warning: 'vpn-type': %s not known.\n"), vpn_type);
|
||||||
st = vpn_type;
|
st = vpn_type;
|
||||||
}
|
}
|
||||||
service_type = g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, st);
|
|
||||||
|
service_type = nm_vpn_get_service_for_name (st);
|
||||||
|
if (!service_type)
|
||||||
|
service_type = service_type_free = nm_vpn_get_service_for_name_default (st);
|
||||||
|
|
||||||
/* Also ask for all optional arguments if '--ask' is specified. */
|
/* Also ask for all optional arguments if '--ask' is specified. */
|
||||||
user = g_strdup (user_c);
|
user = g_strdup (user_c);
|
||||||
|
|
@ -5943,7 +5934,6 @@ cleanup_bridge_slave:
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
cleanup_vpn:
|
cleanup_vpn:
|
||||||
g_free (vpn_type_ask);
|
g_free (vpn_type_ask);
|
||||||
g_free (service_type);
|
|
||||||
g_free (user);
|
g_free (user);
|
||||||
if (!success)
|
if (!success)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
@ -6711,7 +6701,10 @@ update_connection (gboolean persistent,
|
||||||
static char *
|
static char *
|
||||||
gen_func_vpn_types (const char *text, int state)
|
gen_func_vpn_types (const char *text, int state)
|
||||||
{
|
{
|
||||||
return nmc_rl_gen_func_basic (text, state, nmc_known_vpns);
|
gs_free const char **plugin_names = NULL;
|
||||||
|
|
||||||
|
plugin_names = nm_vpn_get_plugin_names (FALSE);
|
||||||
|
return nmc_rl_gen_func_basic (text, state, plugin_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,78 @@ nm_vpn_get_plugins (void)
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_strcmp_data (gconstpointer a, gconstpointer b, gpointer unused)
|
||||||
|
{
|
||||||
|
return strcmp (a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char **
|
||||||
|
nm_vpn_get_plugin_names (gboolean only_available_plugins)
|
||||||
|
{
|
||||||
|
GSList *p;
|
||||||
|
const char **list;
|
||||||
|
const char *known_names[] = {
|
||||||
|
"openvpn",
|
||||||
|
"vpnc",
|
||||||
|
"pptp",
|
||||||
|
"openconnect",
|
||||||
|
"openswan",
|
||||||
|
"libreswan",
|
||||||
|
"strongswan",
|
||||||
|
"ssh",
|
||||||
|
"l2tp",
|
||||||
|
"iodine",
|
||||||
|
"fortisslvpn",
|
||||||
|
};
|
||||||
|
guint i, j, k;
|
||||||
|
|
||||||
|
p = nm_vpn_get_plugins ();
|
||||||
|
list = g_new0 (const char *, g_slist_length (p) + G_N_ELEMENTS (known_names) + 1);
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
for (i = 0; p; p = p->next)
|
||||||
|
list[i++] = nm_vpn_plugin_info_get_name (p->data);
|
||||||
|
if (!only_available_plugins) {
|
||||||
|
for (j = 0; j < G_N_ELEMENTS (known_names); j++)
|
||||||
|
list[i++] = known_names[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
g_qsort_with_data (list, i, sizeof (gpointer), _strcmp_data, NULL);
|
||||||
|
|
||||||
|
/* remove duplicates */
|
||||||
|
for (k = 0, j = 1; j < i; j++) {
|
||||||
|
if (nm_streq (list[k], list[j]))
|
||||||
|
continue;
|
||||||
|
list[k++] = list[j];
|
||||||
|
}
|
||||||
|
list[k++] = NULL;
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
nm_vpn_get_service_for_name (const char *name)
|
||||||
|
{
|
||||||
|
NMVpnPluginInfo *plugin_info;
|
||||||
|
|
||||||
|
g_return_val_if_fail (name, NULL);
|
||||||
|
|
||||||
|
plugin_info = nm_vpn_plugin_info_list_find_by_name (nm_vpn_get_plugins (), name);
|
||||||
|
if (plugin_info) {
|
||||||
|
/* this only means we have a .name file (NMVpnPluginInfo). Possibly the
|
||||||
|
* NMVpnEditorPlugin is not loadable. */
|
||||||
|
return nm_vpn_plugin_info_get_service (plugin_info);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
nm_vpn_get_service_for_name_default (const char *name)
|
||||||
|
{
|
||||||
|
return g_strdup_printf ("%s.%s", NM_DBUS_INTERFACE, name);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_vpn_supports_ipv6 (NMConnection *connection)
|
nm_vpn_supports_ipv6 (NMConnection *connection)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ struct {
|
||||||
|
|
||||||
GSList *nm_vpn_get_plugins (void);
|
GSList *nm_vpn_get_plugins (void);
|
||||||
|
|
||||||
|
const char **nm_vpn_get_plugin_names (gboolean only_available_plugins);
|
||||||
|
|
||||||
|
const char *nm_vpn_get_service_for_name (const char *name);
|
||||||
|
char * nm_vpn_get_service_for_name_default (const char *name);
|
||||||
|
|
||||||
NMVpnEditorPlugin *nm_vpn_lookup_plugin (const char *name, const char *service, GError **error);
|
NMVpnEditorPlugin *nm_vpn_lookup_plugin (const char *name, const char *service, GError **error);
|
||||||
|
|
||||||
gboolean nm_vpn_supports_ipv6 (NMConnection *connection);
|
gboolean nm_vpn_supports_ipv6 (NMConnection *connection);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue