Commit graph

24577 commits

Author SHA1 Message Date
Thomas Haller
53b74bc614 n-dhcp4/socket: use SO_REUSEADDR on UDP socket
Otherwise, other applications cannot bind to port 0.0.0.0:68 at the same time.
This is for example what dhclient wants to do. So even when running
dhclient on another, unrelated interface, it would fail to bind the UDP
socket and quit.

Note that also systemd-networkd's DHCPv4 client sets this socket option.
Presumably for the same reasons.

Signed-off-by: Thomas Haller <thaller@redhat.com>

https://github.com/nettools/n-dhcp4/pull/12
2019-12-11 09:24:14 +01:00
Beniamino Galvani
622eef4882 cli: expose device D-Bus path
https://bugzilla.redhat.com/show_bug.cgi?id=1745574
2019-12-10 17:57:10 +01:00
Thomas Haller
3d07708f59 doc: clarify default values for ipv4.mdns and ipv4.llmnr settings
LLMNR and mDNS settings can have their global default value configured
in "NetworkManager.conf".

Global default values should work the way that all regular values of the property
can be configured explicitly in the connection profile. The special "default" value
only indicates to allow lookup of the global default, but it should not have a
meaning of its own.

Note that if mDNS/LLMNR settings are left unspecified, we will set the
argument to SetLinkMulticastDNS() and SetLinkLLMNR() functions to "",
which means that systemd-resolved decides on a default. Also, depending
on the DNS plugin, the default value differs. This is all fine however.
In this case, the ultimate default value depends on other things (like
the DNS plugin), but each possible value is in fact explicitly
configurable. We also do that for "ipv6.ip6-privacy".

Anyway, cleanup the documentation a bit and try to better explain what
the default is.
2019-12-10 16:49:23 +01:00
Thomas Haller
a5779595ce all: merge branch 'th/polkit-permissions-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/355
2019-12-10 09:21:24 +01:00
Thomas Haller
cb755afa24 clients: in debug builds randomly use sync init of NMClient for testing
This affects nmtui and nm-cloud-setup, which use nmc_client_new_waitsync().
2019-12-10 09:17:17 +01:00
Thomas Haller
030e1472f4 cli: don't fetch permissions for NMClient in nmcli unless required
This avoids unnecessarily fetching permissions, which are not needed
most of the time.

During `nmcli general permissions` we require to fetch the permissions. This is
now solved better, because previously the code waited for any permissions to be
not UNKNOWN. That was a hack, because there are cases where all permissions would
be UNKNOWN (hidepid mount option) and nmcli would hang.

There is a downside too: for `nmcli general permissions` we now first
need to wait for NMClient to initialize, before starting to fetch
permissions. Previously, we would call GetPermissions() in parallel
with initializing NMClient. It now takes longer.
That should be fixed be refactoring the code in nmcli to not wait for
NMClient to be fully initialized, before requesting the permissions.
2019-12-10 09:17:17 +01:00
Thomas Haller
3035837aa8 cli: use nmc_client_new_async() instead of nm_client_new_async()
This will allow us to set construct parameters to the instance, like
NM_CLIENT_INSTANCE_FLAGS.
2019-12-10 09:17:17 +01:00
Thomas Haller
0046163201 nm-online: don't fetch permissions for NMClient in nm-online
nm-online doesn't care about the permissions. Don't fetch them.
2019-12-10 09:17:17 +01:00
Thomas Haller
0b5e72b90d nm-online: use nmc_client_new_async() instead of nm_client_new_async()
This will allow us to set construct parameters to the instance, like
NM_CLIENT_INSTANCE_FLAGS.
2019-12-10 09:17:17 +01:00
Thomas Haller
b78e5cf45c cloud-setup: don't fetch permissions for NMClient in nm-cloud-setup
nm-cloud-setup doesn't care about the permissions. Don't fetch them.
2019-12-10 09:17:17 +01:00
Thomas Haller
c5c7fffda8 cloud-setup: reuse nmc_client_new_waitsync() to create NMClient instance 2019-12-10 09:17:17 +01:00
Thomas Haller
b6c83d18e4 tui: don't fetch permissions for NMClient in nmtui
nmtui doesn't care about the permissions. Don't fetch them.
2019-12-10 09:17:17 +01:00
Thomas Haller
5859e9a53d tui: create NMClient instance via async init
Using sync init (nm_client_new()) has an overhead as it requires an internal
GMainContext to ensure preserving the order of D-Bus messages. Let's avoid
that by using the async init. Note that the difference here is that we will
iterate the caller's GMainContext while creating the instance. But that
is no problem for nmtui at that point.
2019-12-10 09:17:17 +01:00
Thomas Haller
9e10b4f699 shared: add nmc_client_new_waitsync() and nmc_client_new_async*() helpers
Benefits:

- nmc_client_new_async*() allows to set properties on the NMClient
  instance before calling g_async_initable_init_async().
  It also allows to subscribe to any signals (like NM_CLIENT_DEVICE_ADDED)
  before actually iterating the GMainContext. This is a sensible and
  supported thing to do!

- nmc_client_new_waitsync() iterates the GMainContext until the (async)
  initialization is complete. That is different from synchronous nm_client_new(),
  which does not iterate the caller's GMainContext, and hence needs an
  internal context to ensure the order of events is honored.

- nmc_client_new_waitsync() always returns the NMClient instance, even
  if initialization fails.
  That is useful if you need the nm_client_get_context_busy_watcher() instance
  to ensure all pending messages are completed.
2019-12-10 09:17:17 +01:00
Thomas Haller
3843e0c87d shared: add "shared/nm-libnm-aux" static library
We have "shared/nm-libnm-core-aux", which is shared code that can be used
by anybody (including libnm-core, src, libnm and clients).

We have "clients/common", which are helper function for clients. But
that implies that the code is inside "clients". I think it would be
useful to have auxiliary code that extends libnm, but is not only
usable by code in "clients". In other words, "shared/nm-libnm-aux"
is a better place than "clients/common", and I think most of the
functionality form "clients/common" should move there.
2019-12-10 09:17:17 +01:00
Thomas Haller
44c5331e29 shared: move "shared/nm-utils/tests/test-shared-general" to "shared/nm-glib-aux/tests"
"shared/nm-utils" got long renamed and split into separate parts. The remaining
tests are really to test nm-std-aux and nm-glib-aux (no libnm dependencies). Move
the tests to the appropriate place.
2019-12-10 09:17:17 +01:00
Thomas Haller
a33ed5ad82 libnm: allow to enable/disable fetching of permissions in NMClient
Currently, NMClient by default always fetches the permissions
("GetPermissions()") and refreshes them on "CheckPermissions" signal.

Fetching permissions is relatively expensive, while they are not used
most of the time. Allow the user to opt out of this.

For that, have a NMClientInstanceFlags to enable/disable automatic
fetching. Also add a "permissions-state" property that allows the user
to understand whether the cached permissions are up to date or not.

This is a bit an awkward API for handling this. E.g. you cannot
explicitly request permissions, you can just enable/disable fetching
permissions. And then you can watch the permission-state to know whether
you are ready. It's done this way because it fits the previous model
and extends the API with a (relative) small amount of new functions and
properties.
2019-12-10 09:17:17 +01:00
Thomas Haller
f7aeda0390 libnm: add NMClient:instance-flags property
Add a flags property to control behavior of NMClient.
Possible future use cases:

 - currently it would always automatically fetch permissions. Often that
   is not used and the user could opt out of it.

 - currently, using sync init creates an internal GMainContext. This
   has an overhead and may be undesirable. We could implement another
   "sync" initialization that would merely iterate the callers mainloop
   until the initialization completes. A flag would allow to opt in.

 - currently, NMClient always fetches all connection settings
   automatically. Via a flag the user could opt out of that.
   Instead NMClient could provide an API so the user can request
   settings as they are needed.
2019-12-10 07:53:25 +01:00
Thomas Haller
51bc2c0224 libnm: track permissions in NMClient as an array of well known permissions
On D-Bus, the permission names are just the PolicyKit action names, like
"org.freedesktop.NetworkManager.wifi.scan". But NMClient already
ignores all strings that it doesn't know at compile time and only
keeps track of well known permission.

And neither does the API nm_client_get_permissions_result() allow to
expose permissions unknown to libnm.

Maybe the API of NMClient should be more generic and allow exposing
any permissions announced by NetworkManager. As it is however, it's
not necessary to track the permissions in a hash table. An array with
fixed indices is sufficient.
2019-12-10 07:53:25 +01:00
Thomas Haller
89d55ad6e1 cli: sort permission in output of nmcli general permissions 2019-12-10 07:53:25 +01:00
Thomas Haller
33754752ea core: use nm_client_permission_result_to_string() to map permission result
In NetworkManager we have NMAuthCallResult, which is really a duplicate
of NMClientPermissionResult.

Maybe NMAuthCallResult should be entirely replaced by NMClientPermissionResult.
But the name NMClientPermissionResult is a bit awkward. But then the
duplication is even more awkward... fixing this is left for another day.
2019-12-10 07:53:25 +01:00
Thomas Haller
466a4c4562 core: don't duplicate list of known permissions in impl_manager_get_permissions()
Reuse the list of all permissions and don't duplicate it.

Also, now the result of GetPermissions() on D-Bus contains the
permissions sorted by name. We get it almost for free, and it's
a nice property.
2019-12-10 07:53:25 +01:00
Thomas Haller
dab61a919b shared: add nm_client_permission_result_to_string() helper 2019-12-10 07:53:25 +01:00
Thomas Haller
b7462b1910 libnm,shared: move nm_permission_result_to_client() to shared's nm_client_permission_result_from_string() 2019-12-10 07:53:25 +01:00
Thomas Haller
bfdd352a61 libnm,cli: cleanup mapping between NMClientPermission and strings 2019-12-10 07:53:25 +01:00
Thomas Haller
09e17888f7 libnm: add mapping functions between string and NMClientPermission enum 2019-12-10 07:53:25 +01:00
Thomas Haller
5ad095374f libnm: move NMClientPermission/NMClientPermissionResult enums from libnm to libnm-core
We will also use the enum from core.
2019-12-10 07:53:25 +01:00
Thomas Haller
50a12ce2d5 core: also return unknown permission check result
For example with

  mount -o remount,rw,hidepid=1 /proc/

all permission checks will fail with an error. Internally, we map the
failure to NM_AUTH_CALL_RESULT_UNKNOWN.

    <trace> [1575645672.5958] auth: call[1069]: CheckAuthorization(org.freedesktop.NetworkManager.enable-disable-connectivity-check), subject=unix-process[pid=468316, uid=1000, start=1912881]
    <trace> [1575645672.6295] auth: call[1069]: completed: failed: GDBus.Error:org.gtk.GDBus.UnmappedGError.Quark._g_2dfile_2derror_2dquark.Code4: Failed to open file “/proc/468316/status”: No such file or directory
    <debug> [1575645672.6296] manager: unknown auth chain result 0

First of all, we should not log a debug message about that (we already log the
result of permission checks separately).

Also, we should include the unknown result in the response. The permission was
checked, and omitting it from GetPermissions() result seems wrong (even if we
failed to get the result).

Note that "unknown" is now a new possible return value on D-Bus. But
see how nm_permission_result_to_client() would map such a value to
"unknown" as well. So, it's probably a fine extension of the D-Bus API.

Note that NMClient API is currently quite limited. The user won't know
whether permissions were received (and if they were received, they
could not distinguish between UNKNOWN and absent). Hence, returning
all permissions as unknown (or not at all) causes `nmcli general permissions`
to hang. The solution here is to improve NMClient API to allow the user
to know when the permissions are received. But this patch doesn't
fix the hanging of nmcli nor the limitation of NMClient's API.
2019-12-10 07:53:25 +01:00
Thomas Haller
b650d1d181 core: also check "org.freedesktop.NetworkManager.wifi.scan" permissions 2019-12-10 07:53:25 +01:00
Thomas Haller
e0569ee575 settings: assert that we don't leak error variable in impl_settings_load_connections() 2019-12-09 09:54:17 +01:00
Thomas Haller
eb642fecdf settings: fix use after free in keyfile's load_connections()
Fixes: d35d3c468a ('settings: rework tracking settings connections and settings plugins')
2019-12-09 09:54:11 +01:00
Thomas Haller
1e742e0fb4 ifcfg: don't use D-Bus connection if NMDBusManager is without main connection
In configure-and-quit mode, NMDBusManager does not have a D-Bus connection.
Likewise, ifcfg-rh plugin should not use one either.
2019-12-09 09:02:24 +01:00
Thomas Haller
9d602529cc settings/trivial: comment why we create GDBusConnection for ifcfg D-Bus interface
There is nothing to fix. Replace the FIXME comment.
2019-12-09 08:59:29 +01:00
Thomas Haller
4eed1a6596 libnm/docs: fix gtk-doc for #NMDhcpHostnameFlags 2019-12-09 07:49:16 +01:00
Beniamino Galvani
93e9010b75 device: don't transition assumed devices to FAILED before ACTIVATED
If the activation of an assumed device fails, we first set the device
state to FAILED and then to ACTIVATED. In the FAILED state, the active
connection transitions to DEACTIVATED and clears its device pointer;
hence we end up with an inconsistent state which causes assertion
failures in other parts of the code (for example, get_best_ip_config()
assumes that the device of the best active connection is not NULL).

Don't first transition to FAILED and then to ACTIVATED, just set the
latter.

https://bugzilla.redhat.com/show_bug.cgi?id=1737774
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/351
2019-12-05 17:09:53 +01:00
Beniamino Galvani
8c0e5b323a merge: support for Wi-Fi Enhanced Open (OWE)
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/345
2019-12-05 14:01:18 +01:00
David Bauer
fc42a74ece libnm-core: support OWE when determining AP compatibility 2019-12-05 14:00:10 +01:00
David Bauer
cb33a27f96 libnm/utils: add OWE security type 2019-12-05 14:00:10 +01:00
David Bauer
a8d5fef607 client/tui: add OWE support 2019-12-05 14:00:10 +01:00
David Bauer
977c0c2387 client/cli: add support for OWE key management flag 2019-12-05 14:00:10 +01:00
David Bauer
f7aa5b3a36 clients/secret-agent: don't require secrets for OWE connections 2019-12-05 14:00:10 +01:00
David Bauer
046f6f7227 clients/meta-setting-desc: allow setting wifi-sec.key-mgmt to OWE 2019-12-05 14:00:10 +01:00
David Bauer
9a2bbbbc7a wifi/utils: complete key-mgmt=owe for OWE capable APs 2019-12-05 14:00:10 +01:00
David Bauer
235cb4a5d3 settings/ifcfg: add support for KEY_MGMT=OWE 2019-12-05 14:00:10 +01:00
David Bauer
1e55eff498 supplicant: add support for OWE key management 2019-12-05 14:00:10 +01:00
David Bauer
85c4a757ad libnm-core/setting-wireless-security: add support for OWE key-management 2019-12-05 14:00:10 +01:00
David Bauer
1bae844fac wifi/ap: expose OWE capability 2019-12-05 14:00:10 +01:00
David Bauer
ba299d0d0c libnm-core: add OWE support flag 2019-12-05 14:00:10 +01:00
Thomas Haller
abaad34fd2 initrd: merge branch 'th/initrd-parse-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/282
2019-12-05 13:10:13 +01:00
Thomas Haller
d68373c305 initrd: don't use inet_aton() to parse IPv4 address
inet_aton() is very accepting when parsing the address. For example,
it accepts addresses with fewer octets (interpreting the last octet
as a number in network byte order for multiple bytes). It also ignores
any trailing garbage after the first delimiting whitespace (at least,
the glibc implementation). It also accepts octets in hex and octal
notation.

For the initrd reader we want to be more forgiving than inet_pton()
and also accept addresses like 255.000.000.000 (octal notation). For
that we would want to use inet_aton(). But we should not accept all the
craziness that inet_aton() otherwise accepts.

Use nm_utils_parse_inaddr_bin_full() instead. This function implements
our way how we want to interpret IP addresses in string representation.
Under the hood, of course it also uses inet_pton() and even inet_aton(),
but it is stricter than inet_aton() and only accepts certain formats.
2019-12-05 12:36:13 +01:00