Commit graph

1372 commits

Author SHA1 Message Date
Beniamino Galvani
ec6b243738 cli: fix crash on autocompletion
@connections is NULL when doing autocompletion. Fixes the following:

 $ nmcli --complete-args con monitor ""
  help
  id
  uuid
  path
  filename
  ...
  Segmentation fault (core dumped)

Fixes: 4b3297271e ('cli: rework connection handling for multiple results')

https://bugzilla.redhat.com/show_bug.cgi?id=1716948
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/177
(cherry picked from commit 6a3bb90ad4)
(cherry picked from commit 52c886a6d7)
2019-06-20 11:20:46 +02:00
Beniamino Galvani
2666aa0bf1 cli: don't wait for connection change on update failure
When saving a connection, we wait the connection-changed signal before
proceeding to ensure that the remote connection is up to date.
However, no signal is emitted if the update fails and so we shouldn't
wait for it.

Fixes: a370faeb59 ('cli: wait for changed signal after updating a connection'):

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/124
https://bugzilla.redhat.com/show_bug.cgi?id=1702203
(cherry picked from commit 2d347e7e17)
(cherry picked from commit 3423629ff0)
2019-06-14 17:31:30 +02:00
Beniamino Galvani
3a8cab979d tui: add only some options to new bond connections
Instead of adding every known option to new bond connections, only add
the ones supported by UI.

https://bugzilla.redhat.com/show_bug.cgi?id=1715720
(cherry picked from commit b247950c6f)
(cherry picked from commit 5221af1123)
2019-06-11 18:38:01 +02:00
Beniamino Galvani
3c35fdd058 clients: disable asan leak detection in client tests
Leak detection adds unhelpful messages to the stderr of nmcli, making
tests fail. For example:

 =================================================================
 ==17156==ERROR: LeakSanitizer: detected memory leaks

 Direct leak of 256 byte(s) in 2 object(s) allocated from:
     #0 0x7f08c7e27c88 in realloc (/lib64/libasan.so.5+0xefc88)
     #1 0x7f08c7546e7d in g_realloc (/lib64/libglib-2.0.so.0+0x54e7d)

(cherry picked from commit 2fe9141960)
2019-04-12 11:51:50 +02:00
Beniamino Galvani
eee2eda4b5 clients: fix assertion when requesting gsm pin secret
[root@gsm-r5s4-01 ~]# nmcli  connection up id gsm
  **
  libnmc:ERROR:clients/common/nm-secret-agent-simple.c:171:_secret_real_new_plain: assertion failed: ((secret_type == NM_SECRET_AGENT_SECRET_TYPE_SECRET) == nm_setting_get_secret_flags (setting, property, ((void *)0), ((void *)0)))
  Aborted (core dumped)

The pin is a secret property.

https://bugzilla.redhat.com/show_bug.cgi?id=1698495
(cherry picked from commit a94ccc9acc)
2019-04-11 13:54:54 +02:00
Beniamino Galvani
fed4694f9b clients: only ask secrets for settings that require them
When nmcli needs secrets for a connection it asks them for every known
setting. nmtui is a bit smarter and asks them only for settings that
actually exist in the connection. Make a step further and let clients
ask secrets only for setting that exist *and* have any secret
property. This decreases the number of D-Bus calls when editing or
showing a connection with secrets.

https://bugzilla.redhat.com/show_bug.cgi?id=1506536
https://github.com/NetworkManager/NetworkManager/pull/327
(cherry picked from commit 5b5a768b69)
2019-04-02 11:21:25 +02:00
Lubomir Rintel
4251f4e476 all: codespell fixes
Codespel run with the same arguments as described in
commit 58510ed566 ('docs: misc. typos pt2').

(cherry picked from commit bf0c4e6ac2)
2019-03-11 12:03:46 +01:00
Lubomir Rintel
bf365e9762 clients/tests: add wireguard import tests
(cherry picked from commit c152ca37ef)
2019-03-07 22:22:39 +01:00
Thomas Haller
a6ee43d1c1 cli/wireguard: add import functionality for WireGuard
Support importing ".conf" files as `wg-quick up` supports it.

`wg-quick` parses several options under "[Interface]" and
passes the remainder to `wg setconf`.

The PreUp/PreDown/PostUp/PostDown options are of course not supported.

"Table" for the moment behaves different.

(cherry picked from commit a3a8583c31)
2019-03-07 22:22:39 +01:00
Thomas Haller
4a137f919b cli: fix completion for nmcli connection import
If we already specified "type" or "file", don't offer it for
completion again.

  $ nmcli connection import type openvpn <TAB>
  file  type

(cherry picked from commit fea0f4a5ea)
2019-03-07 22:22:39 +01:00
Thomas Haller
c5a247c4c0 cli: add nmc_complete_strv() which takes a string array for completion that may contain NULL
This will allow for a convenient calling pattern when some elements
should be printed optionally.

(cherry picked from commit 62b939de4e)
2019-03-07 22:22:39 +01:00
Thomas Haller
2d34d06e5f wireguard: add "peer-routes" setting for WireGuard profiles
This setting is not yet implemented.

This adds new API for 1.16.0 and is an ABI break since 1.16-rc1.

(cherry picked from commit d719ad31f0)
2019-03-05 12:23:59 +01:00
Thomas Haller
89d40d6579 wireguard: add "mtu" setting for WireGuard profiles
This adds new API for 1.16.0 and is an ABI break since 1.16-rc1.

(cherry picked from commit d5e93ae613)
2019-03-05 12:23:59 +01:00
Beniamino Galvani
42304b34fd clients: fix GVariantBuilder memory leak
Fixes: acf86f68b3
(cherry picked from commit 22c87f0df8)
2019-03-05 09:45:02 +01:00
Beniamino Galvani
f1628ea6f1 clients: fix i/o stream memory leaks
Fixes: 5a0d67f739
(cherry picked from commit 91a644d4a5)
2019-03-05 09:44:59 +01:00
Beniamino Galvani
efce1e34f2 clients: fix keyfile string memory leak
The return value of g_key_file_get_string() was leaked.

Fixes: 5a0d67f739
(cherry picked from commit 082ae508a0)
2019-03-05 09:44:57 +01:00
Beniamino Galvani
72f40fc421 clients: fix double free
@secrets is unreferenced at the end of request_secrets_from_ui() and
so try_spawn_vpn_auth_helper() must take a reference to it.

Fixes: 1a0fc8d437
(cherry picked from commit b57a3a4cc6)
2019-03-05 09:44:56 +01:00
Thomas Haller
a6160cb131 cli/tests: fix cli tests after changing Polish translations
The tests run nmcli with Polish locale and compare the output.
After modifying Polish translation we must regenerate the expected
output.

Fixes: 01b7b32afb

(cherry picked from commit 3089b7df52)
2019-02-25 16:20:59 +01:00
Thomas Haller
95c8f74f8c cli: support NM_SETTING_WIFI_P2P_WFD_IES property 2019-02-22 14:04:13 +01:00
Thomas Haller
0e7e8adc12 cli: rework NM_SETTING_802_1X_PASSWORD_RAW property functions to operate on generic GBytes
Rework the explicit implementation of NM_SETTING_802_1X_PASSWORD_RAW
handling to generically handle GBytes properties.

Note that the NM_SETTING_802_1X_PASSWORD_RAW setter accepts a legacy
format where hex-words are separated by space. I don't think we want
to support this format for new options.

So, there are two possibilities:

1) either leave _set_fcn_802_1x_password_raw() as-is, with the special
   handling.

2) interpret a property-data gobject_bytes.legacy_format.

1) seems to make more sense, because there is only one such property,
and we won't use this for new properties. However let's do 2), because
it shows nicely the two styles side-by-side. In other words, let's
password-raw also be a _pt_gobject_bytes typed property, with some
special legacy handling. Instead, of having it an entirely separate
property type (with a different setter implementation). I think it's
better to have the parts where they differ pushed down (the "stack") as
much as possible.
2019-02-22 14:04:13 +01:00
Thomas Haller
3059a30da9 cli: use nm_utils_bin2hexstr_full() in nmcli to convert bytes to string
- it's less lines of code (for the caller).

 - it's a function that can be easier unit-tested on its own.
   Possibly there are already other unit-tests that cover it.

 - it's more efficient than the GString based implementation.

 - it reuses our one and only bin-to-hexstr implementation.
2019-02-22 14:04:13 +01:00
Thomas Haller
974a010d80 cli: use correct define for NM_SETTING_WIFI_P2P_WPS_METHOD name
There is no change in behavior, because NM_SETTING_WIFI_P2P_WPS_METHOD
and NM_SETTING_WIRELESS_SECURITY_WPS_METHOD both are "wps-method".
2019-02-22 14:04:13 +01:00
Thomas Haller
e148ec07d5 libnm: add NMWireGuardPeer and libnm support for peers 2019-02-22 11:00:10 +01:00
Thomas Haller
b521f426ab libnm,cli: add NMSettingWireGuard
For now only add the core settings, no peers' data.

To support peers and the allowed-ips of the peers is more complicated
and will be done later. It's more complicated because these are nested
lists (allowed-ips) inside a list (peers). That is quite unusual and to
conveniently support that in D-Bus API, in keyfile format, in libnm,
and nmcli, is a effort.
Also, it's further complicated by the fact that each peer has a secret (the
preshared-key). Thus we probably need secret flags for each peer, which
is a novelty as well (until now we require a fixed set of secrets per
profile that is well known).
2019-02-22 11:00:10 +01:00
Thomas Haller
5106d7290b cli/tests: fix tests after adding polkit action for Wi-Fi scans
Fixes: 243af16c5b
2019-02-21 15:33:28 +01:00
Jonathan Kang
243af16c5b Add polkit action for Wi-Fi scans
Previously, Wi-Fi scans uses polkit action
"org.freedesktop.NetworkManager.network-control". This is introduced
in commit 5e3e19d0. But in a system with restrict polkit rules, for
example "org.freedesktop.NetworkManager.network-control" was set as
auth_admin. When you open the network panel of GNOME Control Center, a
polkit dialog will keep showing up asking for admin password, as GNOME
Control Center scans the Wi-Fi list every 15 seconds.

Fix that by adding a new polkit action
"org.freedesktop.NetworkManager.wifi.scan" so that distributions can
add specific rule to allow Wi-Fi scans.

[thaller@redhat.com: fix macro in "shared/nm-common-macros.h"]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/68
2019-02-21 13:49:17 +01:00
Thomas Haller
d10024684f cli: fix generated documentation
Fixes: 8ed7aef26d
2019-02-21 10:19:11 +01:00
Thomas Haller
55ce9d9de9 clients/secret-agent: allow suppressing prompting the entry-id when requesting secrets
When asking for the preshared-key for WireGuard peers, the secret request
will be very verbose with redundant information. Allow suppressing the entry
id from the prompt.
2019-02-14 08:00:29 +01:00
Thomas Haller
ead7c00348 clients/secret-agent: split creation of secret-request data 2019-02-14 08:00:29 +01:00
Thomas Haller
a4f0bda6d4 clients/secret-agent: fail request_secrets_from_ui() if there are no secrets to be requested
From looking at the code above, this likely shouldn't actually happen.
2019-02-14 08:00:29 +01:00
Thomas Haller
6ef825d501 clients/secret-agent: keep setting-name in request-data
It's not really used, but we shouldn't just forget about it.

Currently, we fill requests only based on the connection-type, ignoring
the setting-name. I guess, the concept of requesting secrets for a setting
is utterly broken. But equally broken it is to just look at the connection
(type). At least, don't just throw parts of the request away but keep
it.
2019-02-14 08:00:29 +01:00
Thomas Haller
9beed4f661 all: replace strerror() calls with nm_strerror_native() 2019-02-12 08:50:28 +01:00
Thomas Haller
047998f80a all: cache errno in local variable before using it 2019-02-12 08:50:28 +01:00
Thomas Haller
b7bb744973 libnm,core: use _nm_utils_ascii_str_to_uint64() instead of strtol()
Using strtol() correctly proves to be hard.

Usually, we want to also check that the end pointer is points to the end
of the string. Othewise, we silently accept trailing garbage.
2019-02-12 08:50:28 +01:00
Thomas Haller
a3370af3a8 all: drop unnecessary includes of <errno.h> and <string.h>
"nm-macros-interal.h" already includes <errno.h> and <string.h>.
No need to include it everywhere else too.
2019-02-12 08:50:28 +01:00
Thomas Haller
65884733ec all: minor coding style fixes (space before parentheses) 2019-02-11 15:22:57 +01:00
Thomas Haller
fcb7001302 cli: avoid "-Wmissing-braces" warning for INT_VALUE_INFOS() and ENUM_VALUE_INFOS()
Also fix indentations and enforce that each block is terminated by a
trailing comma.
2019-02-08 20:14:50 +01:00
Thomas Haller
2510f60e92 cli: avoid "-Wduplicate-decl-specifier" warning in nmcli's resolve_color_alias()
[1/2] Compiling C object 'clients/cli/2641089@@nmcli@exe/nmcli.c.o'.
    ../clients/cli/nmcli.c: In function ‘resolve_color_alias’:
    ../clients/cli/nmcli.c:507:4: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      } const aliases[] = {
        ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
7a8a4a5fa3 clients: avoid "-Wduplicate-decl-specifier" warning in array declarions in "nm-vpn-helpers.c"
[1/5] Compiling C object 'clients/common/913ef36@@nmc-base@sta/nm-vpn-helpers.c.o'.
    ../clients/common/nm-vpn-helpers.c: In function ‘nm_vpn_get_secret_names’:
    ../clients/common/nm-vpn-helpers.c:118:31: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
      static const VpnPasswordName const generic_vpn_secrets[] = {
                                   ^~~~~
2019-02-08 20:14:50 +01:00
Thomas Haller
e95cf643c3 cli: drop invalid validation for default-routes in nmcli
Currently, default-routes cannot be added like regular static-routes
as ipv4.routes setting.
Instead, one has to configure "ipv4.gateway" and "ipv4.never-default".
That of course should be fixed, for example to configure a default-route
in different routing tables.

As it is, both nmcli's parse function and libnm's
NMSettingIPConfig:verify() functions reject default-routes.

But nmcli goes way beyond that, it also rejects all networks with
"0.0.0.0"/"::" even if their prefix length is not zero. Such routes are
not default-routes, and nmcli has no business rejecting them. The
correct way for checking for a default-route is to check the prefix-length
for zero.

Drop the wrong validation in nmcli.

Note, it may still not be the best idea to add catch-all routes like
"0.0.0.0/1" and "128.0.0.0/1". It just defeats what counts as a default-route.
NM has other means (like configuring the route-metric) to handle routing
in face of multiple interfaces. But sure, whatever works for you.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/114
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/75
2019-02-07 17:21:40 +01:00
Thomas Haller
708f810515 Revert "clients/tests: fix client tests"
This reverts commit dc1187a161.
2019-02-06 12:12:51 +01:00
Thomas Haller
e357d15023 Revert "cli: verify connections before sending them over to daemon"
Just calling nm_connection_verify() is not correct. We need
nm_connection_normalize() because otherwise we miss out on places
where we have common normalization steps implemented to fix a
connection. This is also what server-side is done.

Revert the patch, as it breaks CI tests.

I wonder also whether this is the right place. There are already
several places in "clients/cli/connections.c" that call verify()
and normalize(). These places should be unified so that there is
one place where we complete the connection. And it probably should be
done as a separate step before the add_new_connection()/update_connection()
calls.

This reverts commit ca58bcca0c.
2019-02-06 11:51:38 +01:00
Thomas Haller
dc1187a161 clients/tests: fix client tests
Fixes: d081aa1d84
2019-02-05 11:12:07 +01:00
Lubomir Rintel
ca58bcca0c cli: verify connections before sending them over to daemon
This way we generate the error messages on the client side and therefore
can localize them.
2019-02-05 10:20:30 +01:00
Lubomir Rintel
fab1116494 clients/cli: if the AP supports SAE, claim WPA3 support
RSN with SAE is what's called WPA3-Personal.
Also, if there's neither PSK nor 802.1x, it's not WPA2.
2019-02-05 10:20:30 +01:00
Lubomir Rintel
640164e979 clients/test: vary RSN capabilities across APs
This allows us to test if we distinguish WPA1, WPA2 and WPA3 in the
client.
2019-02-05 10:20:29 +01:00
Lubomir Rintel
245c9c93d1 clients/cli: don't translate abbreviations 2019-02-05 10:20:27 +01:00
Lubomir Rintel
2344e958cf client/cli: send a PSK when using SAE 2019-02-05 10:20:27 +01:00
Lubomir Rintel
998ebe731e client/cli: add support for SAE key management flag 2019-02-05 10:20:27 +01:00
Lubomir Rintel
ab0d348792 client/devices: get rid of useless g_strdup()s
And, while at that, add a hint to the developer adding new items. It's
helps avoid a mistake that I believe is common (because I just made it
twice...).
2019-02-05 10:20:27 +01:00