clients: define VPN password list closer to where it is used in nm_vpn_get_secret_names()

This commit is contained in:
Thomas Haller 2020-04-29 16:14:09 +02:00
parent 5238b8dde7
commit 4a3339d37c
3 changed files with 49 additions and 39 deletions

View file

@ -422,7 +422,7 @@ add_vpn_secrets (RequestData *request,
char **msg)
{
NMSettingVpn *s_vpn = nm_connection_get_setting_vpn (request->connection);
const VpnPasswordName *secret_names, *p;
const VpnPasswordName *p;
const char *vpn_msg = NULL;
char **iter;
@ -439,7 +439,7 @@ add_vpn_secrets (RequestData *request,
NM_SET_OUT (msg, g_strdup (vpn_msg));
/* Now add what client thinks might be required, because hints may be empty or incomplete */
p = secret_names = nm_vpn_get_secret_names (nm_setting_vpn_get_service_type (s_vpn));
p = nm_vpn_get_secret_names (nm_setting_vpn_get_service_type (s_vpn));
while (p && p->name) {
add_vpn_secret_helper (secrets, s_vpn, p->name, _(p->ui_name));
p++;

View file

@ -106,32 +106,6 @@ nm_vpn_supports_ipv6 (NMConnection *connection)
const VpnPasswordName *
nm_vpn_get_secret_names (const char *service_type)
{
static const VpnPasswordName generic_vpn_secrets[] = {
{ "password", N_("Password") },
{ 0 }
};
static const VpnPasswordName openvpn_secrets[] = {
{ "password", N_("Password") },
{ "cert-pass", N_("Certificate password") },
{ "http-proxy-password", N_("HTTP proxy password") },
{ 0 }
};
static const VpnPasswordName vpnc_secrets[] = {
{ "Xauth password", N_("Password") },
{ "IPSec secret", N_("Group password") },
{ 0 }
};
static const VpnPasswordName swan_secrets[] = {
{ "xauthpassword", N_("Password") },
{ "pskvalue", N_("Group password") },
{ 0 }
};
static const VpnPasswordName openconnect_secrets[] = {
{ "gateway", N_("Gateway") },
{ "cookie", N_("Cookie") },
{ "gwcert", N_("Gateway certificate hash") },
{ 0 }
};
const char *type;
if (!service_type)
@ -144,22 +118,58 @@ nm_vpn_get_secret_names (const char *service_type)
}
type = service_type + (NM_STRLEN (NM_DBUS_INTERFACE) + 1);
#define _VPN_PASSWORD_LIST(...) \
({ \
static const VpnPasswordName _arr[] = { \
__VA_ARGS__ \
{ .name = NULL, .ui_name = NULL }, \
}; \
_arr; \
})
if (NM_IN_STRSET (type, "pptp",
"iodine",
"ssh",
"l2tp",
"fortisslvpn"))
return generic_vpn_secrets;
if (NM_IN_STRSET (type, "openvpn"))
return openvpn_secrets;
if (NM_IN_STRSET (type, "vpnc"))
return vpnc_secrets;
"fortisslvpn")) {
return _VPN_PASSWORD_LIST (
{ "password", N_("Password") },
);
}
if (NM_IN_STRSET (type, "openvpn")) {
return _VPN_PASSWORD_LIST (
{ "password", N_("Password") },
{ "cert-pass", N_("Certificate password") },
{ "http-proxy-password", N_("HTTP proxy password") },
);
}
if (NM_IN_STRSET (type, "vpnc")) {
return _VPN_PASSWORD_LIST (
{ "Xauth password", N_("Password") },
{ "IPSec secret", N_("Group password") },
);
};
if (NM_IN_STRSET (type, "openswan",
"libreswan",
"strongswan"))
return swan_secrets;
if (NM_IN_STRSET (type, "openconnect"))
return openconnect_secrets;
"strongswan")) {
return _VPN_PASSWORD_LIST (
{ "xauthpassword", N_("Password") },
{ "pskvalue", N_("Group password") },
);
};
if (NM_IN_STRSET (type, "openconnect")) {
return _VPN_PASSWORD_LIST (
{ "gateway", N_("Gateway") },
{ "cookie", N_("Cookie") },
{ "gwcert", N_("Gateway certificate hash") },
);
};
return NULL;
}

View file

@ -17,7 +17,7 @@ NMVpnEditorPlugin *nm_vpn_get_editor_plugin (const char *service_type, GError **
gboolean nm_vpn_supports_ipv6 (NMConnection *connection);
const VpnPasswordName * nm_vpn_get_secret_names (const char *service_type);
const VpnPasswordName *nm_vpn_get_secret_names (const char *service_type);
gboolean nm_vpn_openconnect_authenticate_helper (const char *host,
char **cookie,