diff options
author | Thomas Haller <thaller@redhat.com> | 2020-04-29 16:14:09 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-04-29 16:15:30 +0200 |
commit | 4a3339d37c7a8dd614db03ea52237d39b65d4096 (patch) | |
tree | 43adffdcf9e4ac3dbdfed69eaac81493458eaf4f | |
parent | 5238b8dde7633a40ec955962a636b8cc9dd2476e (diff) | |
download | NetworkManager-4a3339d37c7a8dd614db03ea52237d39b65d4096.tar.gz |
clients: define VPN password list closer to where it is used in nm_vpn_get_secret_names()
-rw-r--r-- | clients/common/nm-secret-agent-simple.c | 4 | ||||
-rw-r--r-- | clients/common/nm-vpn-helpers.c | 82 | ||||
-rw-r--r-- | clients/common/nm-vpn-helpers.h | 2 |
3 files changed, 49 insertions, 39 deletions
diff --git a/clients/common/nm-secret-agent-simple.c b/clients/common/nm-secret-agent-simple.c index ca9250ca6f..4e027584c8 100644 --- a/clients/common/nm-secret-agent-simple.c +++ b/clients/common/nm-secret-agent-simple.c @@ -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++; diff --git a/clients/common/nm-vpn-helpers.c b/clients/common/nm-vpn-helpers.c index 5c3b9fa4e7..a7740d0735 100644 --- a/clients/common/nm-vpn-helpers.c +++ b/clients/common/nm-vpn-helpers.c @@ -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; } diff --git a/clients/common/nm-vpn-helpers.h b/clients/common/nm-vpn-helpers.h index 611f09dd41..dc7c0c9f69 100644 --- a/clients/common/nm-vpn-helpers.h +++ b/clients/common/nm-vpn-helpers.h @@ -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, |