Commit graph

14067 commits

Author SHA1 Message Date
Jonas Dreßler
2bc3cf0cb8
supplicant/config: Disallow SHA1 ciphers when using required PMF
As mentioned in the wpa_supplicant reference config, when setting PMF to
required with WPA2 (personal or enterprise) authentication, we want to
only enable SHA256 and upwards as HMAC. So enforce that by not passing
WPA-PSK and WPA-EAP to the config in case pmf is set to REQUIRED.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
a4b95a9fcd
libnm-core: Don't allow disabling PMF when using WPA3 key management
Modern WPA3 authentication methods like SAE and WPA-EAP-SUITE-B-192 need
to have management frame protection set to required according to the
standard. Since the last commit, we enforce this automatically when
key-mgmt is set to 'owe', 'sae' or 'wpa-eap-suite-b-192', so disabling
it manually should not be possible.

Add a check to the pmf property that makes sure it can't be set to
'disabled' or 'optional' when one of those key-mgmt methods is used.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
8816cfe736
supplicant/config: Require pmf for owe, sae and wpa-eap-suite-b-192
When using modern WPA3 encryption like owe, sae or wpa-eap-suite-b-192
without fallbacks (so not WPA3+WPA2), protected management frames are
required to be enabled by the specification.

For wpa-eap-suite-b-192 we already do this and force PMF to REQUIRED, we
should also do it for OWE and SAE.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
e06f9508d1
libnm-core: Rewrite comment of key-mgmt property
The key-mgmt property of NMSettingWirelessSecurity is slightly confusing
when you know there's also a wpa_supplicant configuration option called
"key_mgmt". Our property is not the same as that supplicant option even
though they do have things in common. NMs key-mgmt is not exactly meant
to configure which AKM suites you want to use, but rather which method
of wifi security is being used (so "wpa2+wpa3 personal", "wpa3 personal
only" or "wpa3 enterprise only").

Try to make this a bit clearer in the documentation of the property by
rewriting it and listing those security methods.
2021-05-06 22:23:28 +02:00
Jonas Dreßler
5f146b40f3
supplicant/config: Refactor key_mgmt config generation
Refactor the generation of the key_mgmt option of the wpa_supplicant
config we generate. The goal of this is to lay out all the cases we
support more obviously and to make it a bit clearer that our key-mgmt
property of NMSettingsWirelessSecurity is not the same as the "key_mgmt"
config we set in wpa_supplicant.
2021-05-06 22:23:28 +02:00
Thomas Haller
a6cf94cfc4
strbuf: drop nm_str_buf_append_c[24]() for nm_str_buf_append_c() 2021-05-06 13:18:56 +02:00
Thomas Haller
94ce36f816
strbuf: make nm_str_buf_append_c() a variadic macro
We already have nm_str_buf_append_c2() and nm_str_buf_append_c4()
to support 2 or 4 characters.

I'd like to also have one for 3 characters.

At this point, just make it a variadic macro. This now supports 1 up to
4 characters, and it will be easy to extend further.
2021-05-06 13:18:19 +02:00
Thomas Haller
b86545e7c0
firewall: rename NMFirewallManager to NMFirewalldManager
The file was already renamed. Now also rename the type and API.
2021-05-06 12:22:37 +02:00
Thomas Haller
8483c47d70
firewall: rename "nm-firewall-manager.[ch]" to "nm-firewalld-manager.[ch]"
We will add a general "firewall-manager", so rename the firewalld related
file. This commit only renames the file. The next commit will change the
symbol naming.
2021-05-06 12:22:37 +02:00
Thomas Haller
0bc5a2c76f
core: add "nm-device-utils.[ch]" with simple helper functions
"nm-device.c" is huge, and it does complicated things like handling the
state of the device and IP configuration.

It also contains simpler, individual functions, like converting enums to
strings. Let's move those trivial functions to a new module, so that the
remaining part is smaller.

"nm-device-utils.[ch]" should only contain simpler functions that have
no complex behavior or state.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/840
2021-05-06 12:19:44 +02:00
Thomas Haller
037a94e837
ppp: cleanup nm-ppp-manager-call to use const pointer and atomic operations
- Mark NMPPPOps variable as const. It really must not be modified.

- We cache the loaded symbols in a global variable. While this code
  is not used in a multi threaded situation, I think we should not
  add code that uses global variables that is not thread safe.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/837
2021-05-06 11:34:28 +02:00
Wen Liang
86dcb31ab3
build: replace ./tools/generate-docs-nm-property-infos.pl with python script
In order to have more structured settings in man page and make it more
manageable to generate the docbook, it is recommended to use python
script to replace `./tools/generate-docs-nm-property-infos.pl` (this
tool is used to parse the comment section starting with `---nmcli---`,
`---dbus---`, `---keyfile---`, `---ifcfg-rh---`).

Signed-off-by: Wen Liang <liangwen12year@gmail.com>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/824
2021-05-05 15:28:17 +02:00
Thomas Haller
207cf3d5d4
libnm: normalize "connection.uuid"
For NetworkManager profiles, "connection.uuid" is the identifier of the
profile. It is supposed to be a UUID, however:

- the UUID was not ensured to be all-lower case. We should make sure
  that our UUIDs are in a consistent manner, so that users can rely
  on the format of the string.

- the UUID was never actually interpreted as a UUID. It only was some
  opaque string, that we use as identifier. We had nm_utils_is_uuid()
  which checks that the format is valid, however that did not fully
  validate the format, like it would accept "----7daf444dd78741a59e1ef1b3c8b1c0e8"
  and "549fac10a25f4bcc912d1ae688c2b4987daf444d" (40 hex characters).

Both invalid UUIDs and non-normalized UUID should be normalized. We
don't want to break existing profiles that use such UUIDs, thus we don't
outright reject them. Let's instead mangle them during
nm_connection_normalize().
2021-05-04 15:51:59 +02:00
Thomas Haller
5bd03fd9a3
libnm: use nm_uuid_is_valid_nmlegacy() to implement nm_utils_is_uuid() 2021-05-04 15:51:57 +02:00
Thomas Haller
ce65fc52a8
glib-aux: add nm_uuid_is_valid() helper 2021-05-04 15:51:55 +02:00
Thomas Haller
b12f116a02
glib-aux: add nm_uuid_is_valid_nmlegacy() helper 2021-05-04 15:51:53 +02:00
Thomas Haller
2fcabf5699
all: only include "libnm-glib-aux/nm-uuid.h" where needed
Don't let "nm-core-internal.h" (which is a very popular header itself)
drag in "nm-uuid.h".
2021-05-04 15:51:51 +02:00
Thomas Haller
414ce2236e
glib-aux: add NMUuidType enum for nm_uuid_generate_from_string()
Let's have an enum instead of plain "int" and #define.
2021-05-04 15:51:50 +02:00
Thomas Haller
995c78245e
glib-aux/trivial: rename NMUuid API 2021-05-04 15:51:49 +02:00
Thomas Haller
78297db721
libnm,glib-aux: move nm_utils_uuid_*() API to libnm-glib-aux 2021-05-04 15:51:47 +02:00
Thomas Haller
c5985db7cf
libnm,glib-aux: move nm_crypto_md5_hash() to "libnm-glib-aux"
This only uses glib's md5 code and has no dependency on our
crypto libraries (gnutls, nss).

Move it to "libnm-glib-aux" so it can be freely used.

Maybe it deserves a better name, but "nm-shared-utils.h" is a heap of
various utility functions, it's hard to name them well.
2021-05-04 15:51:46 +02:00
Thomas Haller
73cfc4097a
libnm,glib-aux: add and use nm_uuid_generate_random_str*() helpers 2021-05-04 15:51:45 +02:00
Thomas Haller
dd1a618745
libnm,glib-aux: move nm_utils_uuid_is_null() to "nm-uuid.h" 2021-05-04 15:51:45 +02:00
Thomas Haller
73b9883c6f
build: don't link libnm/libnm-core against libuuid
We use util-linux's libuuid for handling UUIDs. But UUIDs are
really a trivial thing, at least the portion that we use.

Reimplement the parse/unparse/generate_random() methods and drop
the dependency. Note that no other libraries from our dependency chain
was dragging in libuuid, so thereby we really get rid of the dependency.

We still require libuuid for building, because it is used by an example
program. Maybe that should be changed, to avoid the build dependency.
But that can be done at a later time.
2021-05-04 15:51:44 +02:00
Thomas Haller
7a15144f75
glib-aux: use nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
b4608b3ff7
glib-aux: add nm_uuid_generate_random() helper 2021-05-04 15:51:43 +02:00
Thomas Haller
42d67415b4
glib-aux: use nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
e7568e29b2
glib-aux: add nm_uuid_parse() helper 2021-05-04 15:51:42 +02:00
Thomas Haller
596bf4b91b
glib-aux: use nm_uuid_unparse() 2021-05-04 15:51:42 +02:00
Thomas Haller
cd45ad4acf
glib-aux: add nm_uuid_unparse() 2021-05-04 15:51:42 +02:00
Thomas Haller
daebb11af8
glib-aux: move NMUuid to "src/libnm-glib-aux/nm-uuid.h" 2021-05-04 15:51:41 +02:00
Thomas Haller
50add1c75a
glib-aux: add "nm-uuid.[ch]" sources 2021-05-04 15:51:41 +02:00
Thomas Haller
36d92182a8
libnm-core/tests: add test for connection.uuid of settings 2021-05-04 15:51:41 +02:00
Thomas Haller
05130b6e10
ifupdown: replace _str_has_prefix() by NM_STR_HAS_PREFIX() 2021-05-04 15:51:41 +02:00
Thomas Haller
21321ac736
clang-format: reformat code with clang 12
The format depends on the version of the tool. Now that Fedora 34 is
released, update to clang 12 (clang-tools-extra-12.0.0-0.3.rc1.fc34.x86_64).
2021-05-04 13:56:26 +02:00
Beniamino Galvani
23cc0bf335 manager: fix assertion failure in active_connection_find()
Active-connections in the async_op_lst are not guaranteed to have a
settings-connection. In particular, the settings-connection for an
AddAndActivate() AC is set only after the authorization succeeds. Use
the non-asserting variant of the function to fix the following
failure:

 nm_active_connection_get_settings_connection: assertion 'sett_conn' failed

 1    _g_log_abort()
 2    g_logv()
 3    g_log()
 4    _nm_g_return_if_fail_warning.constprop.14()
 5    nm_active_connection_get_settings_connection()
 6    active_connection_find()
 7    _get_activatable_connections_filter()
 8    nm_settings_get_connections_clone()
 9    nm_manager_get_activatable_connections()
 10   auto_activate_device_cb()
 11   g_idle_dispatch()
 12   g_main_context_dispatch()
 13   g_main_context_iterate.isra.21()
 14   g_main_loop_run()
 15   main()

Fixes: 33b9fa3a3c ('manager: Keep volatile/external connections while referenced by async_op_lst')

https://bugzilla.redhat.com/show_bug.cgi?id=1933719
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/834
2021-05-04 08:48:29 +02:00
Thomas Haller
ad2226eacd
core/firewalld: use changeZoneOfInterface() instead of deprecated changeZone()
`man firewalld.dbus` comments that changeZone() is deprecated.
Apparently this is the case since 0.3.3-1 (2013).

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/836
2021-05-04 08:26:42 +02:00
Beniamino Galvani
a0aa727af2 nmcli: remove nmc_dbus_call_sync()
The function is unused now. All operations should be asynchronous so
that nmcli keeps running the main loop.
2021-05-03 22:22:01 +02:00
Beniamino Galvani
9d0aca6757 nmcli: invoke ReloadConnections() D-Bus method asynchronously 2021-05-03 22:22:01 +02:00
Beniamino Galvani
1d82c39bfa nmcli: invoke Reload() D-Bus method asynchronously
Invoke Reload() asynchronously and run the main loop. In this way, the
polkit agent built into nmcli can be used to authenticate the reload
request.

Fixes: 5afcf9c045 ('cli: add 'general reload' command')
2021-05-03 22:22:01 +02:00
Beniamino Galvani
126ee6a1e8 libnm-glib-aux: add nm_dbus_call()
Add nm_dbus_call() to get a D-Bus connection and call a method
asynchronously.
2021-05-03 22:13:46 +02:00
Beniamino Galvani
43fc984989 man: document the 'nmcli general reload' command 2021-05-03 22:13:36 +02:00
Beniamino Galvani
fa1f628bce core: force emission of DNS_CONFIG_CHANGED signal on SIGUSR1
If the configuration contains dns=none and resolv.conf is updated
through a dispatcher script, currently there is no way to tell NM that
the content of resolv.conf changed, so that it can restart a hostname
resolution.

Use SIGUSR1 (and SIGHUP) for that.
2021-05-03 22:13:36 +02:00
Thomas Haller
caea7514cb
platform: cleanup ethtool calls in "nm-platform-utils.c"
- consistently check for success/failure of _ethtool_call_handle()
  with "< 0" / ">= 0".

- drop unnecessary memset(). In the past, I argued to add this because
  there were obscure cases with valgrind where this made a difference.
  As it's not clear when/how that is necessary, drop it again.
  Also, we want to prefer explicit struct initialization over memset(),
  so if memset() would be necessary, those places would be problematic
  as well.

- inline unnecessary helper functions. They had only one caller and
  only make the code more verbose.

- use _ethtool_call_once() instead of _ethtool_call_handle() at places
  where we use the handle only once. The handle and _ethtool_call_handle()
  are useful to cache and reuse the file descriptor and the interface
  name. If we only make one call with the handle, we can use
  _ethtool_call_once() instead.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/830
2021-05-03 13:57:07 +02:00
Thomas Haller
d800009552
libnm: add missing "---end---" tag for ifcfg-rh's "dhcp-hostname-flags" doc
This missing tag confuses the parser and it results in an error in
`man nm-settings-ifcfg-rh`.
2021-05-03 10:41:13 +02:00
Thomas Haller
ea67f48050
cli: handle empty/unset values for "gsm.apn" property
Most string properties can be either %NULL (unset) or a non-empty
string.

For a few properties, like "gsm.apn", also the empty word is a valid
value. That makes it problematic to use from nmcli, because

  nmcli connection modify "$PROFILE" gsm.apn ""

means to reset the default (NULL). How to configure the empty word?
For the APN, "" has a specific meaning, distinct from NULL, so we
need to be able to represent that.

The other problem with nmcli is that

  nmcli -g gsm.apn connection show "$PROFILE"

is supposed to give you a value that you an set again, like

  X="$(nmcli -g gsm.apn connection show "$PROFILE"; echo x)"
  nmcli connection modify "$PROFILE2" gsm.apn "${X%$'\n'x}"

but for %NULL and "" the output would be the same.

The "solution" to that is interpreting "" as NULL (like we always did)
and a non-empty string that contains all whitespace, like a string with
one whitespace less. This way, all values can be expressed.

Note that in case of "gsm.apn", the string is anyway internally
normalized with g_strstrip(), so a string with all whitespace was
not expressable.
2021-05-03 10:11:25 +02:00
Thomas Haller
10567386f0
cli/tests: add unit test for checking setting/getting of "gsm.apn"
"gsm.apn" is special, because it can both be %NULL and "".

Add a test for how we handle that.
2021-05-03 10:11:24 +02:00
Thomas Haller
2c37a34d53
cli: fix RETURN_STR_EMPTYUNSET() macro for printing handle_emptyunset string
This was currently unused, because actually no property of type string
had handle_emptyunuset set.

Fixes: e9ee4e39f1 ('cli: handle string properties that can both be empty and %NULL')
2021-05-03 10:11:24 +02:00
Thomas Haller
95932ab577
cli: reset GSM's APN/username/password when setting auto-config
Otherwise,

  nmcli connection modify "$GSM_PROFILE" gsm.auto-config yes

has no effect -- if APN/username/password is set.
2021-05-03 10:11:23 +02:00
Thomas Haller
40032f4614
cli: fix resetting values via property alias
Property aliases should really just be shortcuts for one fully spelled
out property (sometimes, they do more like "master").

Anyway, we must also handle resetting the value, otherwise:

  $ nmcli connection add type gsm apn ""

will still result in "gsm.apn=internet", unlike

  $ nmcli connection add type gsm gsm.apn ""
2021-05-03 10:11:23 +02:00