Commit graph

406 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Lubomir Rintel
fa2fe3688d clients/secret-agent: respond to SAE password requests 2019-02-05 10:20:27 +01:00
Lubomir Rintel
fd64417f1d clients/meta-setting-desc: allow setting wifi-sec.key-mgmt to SAE 2019-02-05 10:20:27 +01:00
Lubomir Rintel
2d3e42b5a7 libnm-core/setting-wireless-security: add support for SAE key management
This adds support for configuring the Wi-Fi connections to use SAE. SAE
is a password-based authentication mechanism that replaces WPA-PSK in
WPA3-Personal.

The pass phrase is still stored in the "psk" property, with some
limitations lifted.
2019-02-05 10:20:27 +01:00
Lubomir Rintel
49ac11f84b clients/common: drop unuseful wifi-sec.psk validation
The generic connection validation produces a good result:
  Error: failed to modify 802-11-wireless-security.psk: ':(' is not a valid PSK.
vs.:
  Error: Failed to add 'wifi666' connection: 802-11-wireless-security.psk: property is invalid
2019-02-05 10:20:27 +01:00
Thomas Haller
c67ebc8abf build/meson: add intermediate shared/nm-utils base library
Like also done for autotools, create and use intermediate libraries
from "shared/nm-utils/".

Also, replace "shared_dep" by "shared_nm_utils_base_dep". We don't
need super fine-grained selection of what we link. We can always
link in "shared/libnm-utils-base.a", and let the linker throw away
unsed parts.
2019-02-05 09:53:24 +01:00
Thomas Haller
472f89da6b wifi,clients/secret-agent: use defines for property names in secret hints 2019-02-05 08:34:23 +01:00
Thomas Haller
787f5f7a46 clients/secret-agent: refactor code in request_secrets_from_ui() to return early 2019-02-05 08:34:23 +01:00
Thomas Haller
1a0fc8d437 clients/secret-agent: fix leaks in request_secrets_from_ui()
Fixes: 3bda3fb60c
2019-02-05 08:34:23 +01:00
Thomas Haller
883978ec99 clients/secret-agent: use g_hash_table_get_keys_as_array() in nm_secret_agent_simple_enable() 2019-02-05 08:34:23 +01:00
Thomas Haller
72f90a8fbc clients/secret-agent: fix cancel_get_secrets() implementation
The callback must be invoked, as also documented.

Otherwise, the tracked info gets leaked.

Let NMSecretAgentOld (the caller) be a bit resilient against
bugs in the client, and avoid a crash by prematurely remove
the request-info from the pending list. That does not fully
workaround the bug (it leads to a leak), but at least it does
not cause other "severe" issues.

The leak was present earlier as well.
2019-02-05 08:34:23 +01:00
Thomas Haller
99497a7674 clients/secret-agent: sink reference for variant passed to callback
NMSecretAgentOld's get_secrets_cb() gets this right and takes
a floating reference. So this was correct.

However, make this a bit more robust, and don't pass on
floating references. This was, we don't require the callee
to consume the reference.
2019-02-05 08:31:44 +01:00
Thomas Haller
c9ca1186c2 clients/secret-agent: add complete function for invoking secret callback
The completion of the request and the deletion usually goes hand in
hand. Add a function to unify them.
2019-02-05 08:27:43 +01:00
Thomas Haller
93c848ca03 clients: don't tread secret agent as NMSecretAgentOld
Most of the times we actually need a NMSecretAgentSimple typed pointer.
This way, need need to cast less.

But even if we would need to cast more, it's better to have pointers
point to the actual type, not merely to avoid shortcomings of C.
2019-02-05 08:27:42 +01:00
Thomas Haller
82472c557c clients/secret-agent: use nm-utils error reason for callback while disposing NMSecretAgentSimple
No caller cared about the NM_SECRET_AGENT_ERROR_AGENT_CANCELED reason.
In particular, because previously the requests would keep the secret-agent
instance alive, and this never happend.

Also, NM_SECRET_AGENT_ERROR_AGENT_CANCELED precicley exists for
NMSecretAgentOld:cancel_get_secrets() (as documented). During finalize
we are not cancelled -- at least not the same way as
cancel_get_secrets(). Setting NM_SECRET_AGENT_ERROR_AGENT_CANCELED
is wrong.

Anyway, we have a default error for such cases already.
2019-02-05 08:27:42 +01:00
Thomas Haller
d68bdce206 clients/secret-agent: minor cleanup of child-watch-id for secret-agent
The code was correct. But it's hard to follow when and whether
the child-watch-id was destroyed at the right time.

Instead, always let _auth_dialog_data_free() clear the signal handlers.
2019-02-05 08:27:42 +01:00
Thomas Haller
8b951afac9 clients/secret-agent: don't let request keep secret-agent alive
Don't let RequestData keep the parent NMSecretAgentSimple instance
alive. Previously, the code in finalize() was never actually reached.

Also, move the final callback from finalize() to dispose(). It feels
wrong to invoke callbacks from finalize().
2019-02-05 08:27:42 +01:00
Thomas Haller
16e0f38c3e clients/secret-agent: cancel pending operations
We must actually cancel the GCancellable. Otherwise, the pending async
operations are not cancelled. _auth_dialog_write_done() doesn't care
about that, but _auth_dialog_read_done() does. It must not touch the
destroyed data, after the operation is cancelled.
2019-02-05 08:27:42 +01:00
Thomas Haller
f2973fd72e clients/secret-agent: remove request in finalize loop early
It's ugly to keep the request in the list. Just remove it
right away.
2019-02-05 08:27:42 +01:00
Thomas Haller
4157092a8a clients/secret-agent: rework tracking of requests in secret-agent-simple
Note that previously the @requests hash took the request-id as key and
the RequestData as value. Likewise, the destroy functions of the head
would destroy the key and the value.

However, RequestData also had a field "request_id". But that pointer was
not owned (nor freed) by the RequestData structure. Instead, it was
relied that the hash kept the request-id alive long enough.

That is confusing. Let RequestData own the request-id.

Also, we don't need to track a separate key. Just move the request-id
as first filed in RequestData, and use compare/hash functions that
handle that correctly (nm_pstr_*()).
2019-02-05 08:27:12 +01:00
Thomas Haller
5572c8f81c clients/secret-agent: only pass char buffer to _auth_dialog_write_done()
We don't need the entire GString. It's only to keep the buffer alive
for long enough.
2019-02-05 08:22:01 +01:00
Thomas Haller
73f423c5e5 clients/secret-agent: various cleanups in secret-agent-simple 2019-02-05 08:22:01 +01:00
Thomas Haller
378a4a8e1a clients/secret-agent: drop strv_has() implementation 2019-02-05 08:22:01 +01:00
Thomas Haller
aaaa8902fd clients/secret-agent/trival: rename internal types, functions and variables
Code that is internal to a source file should not have a "nm" prefix.
That is what differenciates it from declarations in header files. It
makes it clearer that these names are only defined in the current file.

Also, our implementations of virtual functions shall have the same
name as the function pointer of the VTable (or at least, it shouldn't
have a "nm" prefix).
2019-02-05 08:22:01 +01:00
Thomas Haller
9d1becb0dd clients/secret-agent: embed private data in NMSecretAgentSimple class 2019-02-05 08:22:01 +01:00