diff options
author | Thomas Haller <thaller@redhat.com> | 2020-02-17 17:36:55 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-02-26 17:51:13 +0100 |
commit | 47a654d398485d574c1ac9df2ff38114a28783f8 (patch) | |
tree | 366ca975254271792161a25ff2f266b88216e753 | |
parent | 41480d48aea10238f48baa34b7c1b1a610fbdf2b (diff) | |
download | NetworkManager-47a654d398485d574c1ac9df2ff38114a28783f8.tar.gz |
clients: use nm_utils_ifname_valid() to validate interface name in nm_vpn_wireguard_import()
We use the filename of the imported .conf file for "connection.interface-name".
That follows what `wg-quick` does.
However, we also validate that the interface name is valid UTF-8
(otherwise -- as it currently is -- the setting couldn't be send via
D-Bus). As such, we have stricter requirements.
We want to fail early and tell the user when the filename is unsuitable.
Failing later gives a worse user experience, because the failure message
about invalid "connection.interface-name" wouldn't make it clear that
the filename is wrong.
Use the appropriate function to validate "connection.interface-name".
Before:
$ touch $'./a\344b.conf'
$ nmcli connection import type wireguard file $'./a\344b.conf'
Error: failed to import './a?b.conf': Failed to create WireGuard connection: connection.interface-name: 'a?b': interface name must be UTF-8 encoded.
Now:
$ nmcli connection import type wireguard file $'./a\344b.conf'
Error: failed to import './a?b.conf': The name of the WireGuard config must be a valid interface name followed by ".conf".
-rw-r--r-- | clients/common/nm-vpn-helpers.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/clients/common/nm-vpn-helpers.c b/clients/common/nm-vpn-helpers.c index e1d8355147..33490c57d5 100644 --- a/clients/common/nm-vpn-helpers.c +++ b/clients/common/nm-vpn-helpers.c @@ -368,13 +368,13 @@ nm_vpn_wireguard_import (const char *filename, memcpy (ifname, cstr, len); ifname[len] = '\0'; - if (nm_utils_ifname_valid_kernel (ifname, NULL)) + if (nm_utils_ifname_valid (ifname, NMU_IFACE_KERNEL, NULL)) ifname_valid = TRUE; } } if (!ifname_valid) { nm_utils_error_set_literal (error, NM_UTILS_ERROR_UNKNOWN, - _("The WireGuard config file must be a valid interface name followed by \".conf\"")); + _("The name of the WireGuard config must be a valid interface name followed by \".conf\"")); return FALSE; } |