Commit Graph

25044 Commits

Author SHA1 Message Date
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
7e8a5d98e3 settings: assert that we don't leak error variable in impl_settings_load_connections()
(cherry picked from commit e0569ee575)
2019-12-09 09:55:16 +01:00
Thomas Haller
6d37f690ad settings: fix use after free in keyfile's load_connections()
Fixes: d35d3c468a ('settings: rework tracking settings connections and settings plugins')
(cherry picked from commit eb642fecdf)
2019-12-09 09:55:15 +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
8bcb48ee3b libnm/docs: fix gtk-doc for #NMDhcpHostnameFlags
(cherry picked from commit 4eed1a6596)
2019-12-09 07:49:49 +01:00
Thomas Haller
4eed1a6596 libnm/docs: fix gtk-doc for #NMDhcpHostnameFlags 2019-12-09 07:49:16 +01:00
Beniamino Galvani
366b90db87 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
(cherry picked from commit 93e9010b75)
2019-12-05 17:11:36 +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
40a7d13666 initrd: merge branch 'th/initrd-parse-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/282

(cherry picked from commit abaad34fd2)
2019-12-05 13:12:04 +01:00
Thomas Haller
9f76f5eb81 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.

(cherry picked from commit d68373c305)
2019-12-05 13:12:04 +01:00
Thomas Haller
4f3e31f7c5 initrd: fix out-of-bounds read when detecting address family in dt_get_ipaddr_property()
The @family argument is an input and output argument.

Initially, the family is set to AF_UNSPEC, in which case the family
gets detected based on the IP address. However, we call
dt_get_ipaddr_property() multiple times to parse the netmask, the
gateway and the IP address.

That means, after the first successfull call, the @family is set to
AF_INET or AF_INET6.

Note that the previous code (in the switch block) would only check that
the family is set to AF_UNSPEC, but it would not check that the @family
matches the expected binary address length @len. Later, we then might call
nm_ip_address_new_binary() with a family and a binary address of
unexpected length.

Also drop the error checking for nm_ip_address_new_binary().
nm_ip_address_new_binary() can only fail if the prefix length is larger
than 32/128. The function has no way to validate the input arguments
beyond that and can thus not fail (short of undefined behavior).

(cherry picked from commit 9618f1bb4b)
2019-12-05 13:12:04 +01:00
Thomas Haller
90c33b798e initrd: use cleanup attribute in nmi_dt_reader_parse()
(cherry picked from commit e7cf22be3e)
2019-12-05 13:12:04 +01:00
Thomas Haller
f970039122 initrd: fix use-after-free for variable "s_gateway" in nmi_dt_reader_parse()
(cherry picked from commit 321a323df4)
2019-12-05 13:12:04 +01:00
Thomas Haller
f17bb012fe shared: add nm_utils_parse_inaddr_bin_full() to support legacy IPv4 formats as inet_aton()
inet_aton() also supports IPv4 addresses in octal (with a leading '0')
or where not all 4 digits of the address are present.

Add nm_utils_parse_inaddr_bin_full() to optionally fallback to
parse the address with inet_aton().

Note taht inet_aton() also supports all crazy formats, including
ignoring trailing garbage after a whitespace. We don't want to accept
that in general.

Note that even in legacy format we:

  - accept everything that inet_pton() would accept

  - additionally, we also accept some forms which inet_aton() would
    accept, but not all.

That means, the legacy format that we accept is a superset of
inet_pton() and a subset of inet_aton(). Which is desirable.

(cherry picked from commit 8fbf67d138)
2019-12-05 13:12:04 +01:00