Commit graph

12252 commits

Author SHA1 Message Date
Thomas Haller
df086f5366 device/wpan: cleanup act_stage1_prepare() and don't assert with missing hwaddr 2019-08-28 16:27:00 +02:00
Thomas Haller
cc4d69c1c3 device/wireguard: drop act_stage1_prepare() implementation
act_stage1_prepare() should become re-entrant. That means, we should not clear the state
there. Instead, we clear it where necessary or on deactivate (which we do already).
2019-08-28 16:27:00 +02:00
Thomas Haller
2d42c1b102 device/ethernet: make NMDeviceEthernet.act_stage1_prepare() reentrant and minor cleanups 2019-08-28 16:27:00 +02:00
Thomas Haller
f0775963c2 device/bridge: minor cleanup in NMDeviceBridge's act_stage1_prepare()
Only reset "vlan_configured" when deactivating. stage1() should be
re-entrant.
2019-08-28 16:27:00 +02:00
Thomas Haller
aef9594fa6 device/bond: cleanup act-stage return values in NMDeviceBond's act_stage1_prepare() 2019-08-28 16:27:00 +02:00
Thomas Haller
0d0d4eaf93 device/team: drop unnecessary cast for NM_DEVICE_TEAM_GET_PRIVATE() macro 2019-08-28 16:27:00 +02:00
Thomas Haller
847f9cbef3 device/modem: drop unnecessary cast for NM_DEVICE_MODEM_GET_PRIVATE() macro
NM_DEVICE_MODEM_GET_PRIVATE() is based on _NM_GET_PRIVATE(), which has
some smarts to check the pointer type, but is fine with well-known parent
pointer types like "NMDevice *".
2019-08-28 16:27:00 +02:00
Thomas Haller
96cd0ca62f modem/trivial: rename virtual function NMModemClass.act_stage1_prepare()
NMDeviceClass already has a function with this name. It's confusing
to have multiple virtual functions named the same. Rename.
2019-08-28 16:27:00 +02:00
Beniamino Galvani
8b121c7048 core: fix adding objects to NMIPConfig with @append_force
If the @append_force argument is set and the object is already in the
list, it must be moved at the end.

Fixes: 22edeb5b69 ('core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndex')
2019-08-28 16:08:30 +02:00
Beniamino Galvani
24741bff8b core: add test to show nm_ipX_config_replace() bug
Add test to show a wrong result of ip_ipX_config_replace() due to a
bug in _nm_ip_config_add_obj(). When an address is added to the tail
of the index and another address with the same id already exists, the
existing object is left at the same place, breaking the order of
addresses.
2019-08-28 16:08:28 +02:00
Thomas Haller
0300c1823a acd: fix memleak in acd_event()
Only happens with debug logging enabled. So, not a large problem.

Found by Coverity.

Fixes: d9a4b59c18 ('acd: adapt NM code and build options')
2019-08-27 18:19:01 +02:00
Thomas Haller
3b8aab2999 settings/keyfile: check whether profile can be re-read before writing to disk and fail
First of all, keyfile writer (and reader) are supposed to be able to store
every profile to disk and re-read a valid profile back. Note that the profile
might be modified in the process, for example, blob certificates are written
to a file. So, the result might no be exactly the same, but it must still be
valid (and should only diverge in expected ways from the original, like mangled
certificates).

Previously, we would re-read the profile after writing to disk. If that failed,
we would only fail an assertion but otherwise proceeed. It is a bug
after all. However, it's bad to check only after writing to file,
because it results in a unreadable profile on disk, and in the first
moment it appears that noting went wrong. Instead, we should fail early.

Note that nms_keyfile_reader_from_keyfile() must entirely operate on the in-memory
representation of the keyfile. It must not actually access any files on disk. Hence,
moving this check before writing the profile must work. Otherwise, that would be
a separate bug. Actually, keyfile reader and writer violate this. I
added FIXME comments for that. But it doesn't interfere with this
patch.
2019-08-27 11:45:06 +02:00
Thomas Haller
1c2c7d3cb7 settings/keyfile: log reason why re-read connection cannot be normalized
It's a bug either way, but let's log what exactly went wrong.
2019-08-27 10:44:23 +02:00
Beniamino Galvani
a205eb4aa4 wifi: support WPA2 ad-hoc (ibss-rsn)
If the device supports it, allow usage of WPA2 in ad-hoc networks.

Based-on-patch-by: Nicolas Cavallari <cavallar@lri.fr>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/184
2019-08-26 10:38:02 +02:00
Beniamino Galvani
c97e0ce30b wifi: drop support for wpa-none key-mgmt
NM didn't support wpa-none for years because kernel drivers used to be
broken. Note that it wasn't even possible to *add* a connection with
wpa-none because it was rejected in nm_settings_add_connection_dbus().
Given that wpa-none is also deprecated in wpa_supplicant and is
considered insecure, drop altogether any reference to it.
2019-08-26 10:25:00 +02:00
Beniamino Galvani
73b3806228 wifi: expose IBSS_RSN capability
The new capability indicates whether the device supports WPA2/RSN in
an IBSS (ad-hoc) network.

https://bugzilla.gnome.org/show_bug.cgi?id=757823
2019-08-26 10:25:00 +02:00
Thomas Haller
e9ccc2da19 ifupdown: fix crash loading ifupdown settings with empty entries like bridge-ports and mappings
Fixes: d35d3c468a ('settings: rework tracking settings connections and settings plugins')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/235
2019-08-24 13:45:54 +02:00
Thomas Haller
a49027ab22 ifupdown/tests: add test with duplicate interfaces
This file causes a crash [1], add it to the tests.
Note that the test only check parsing the file and the
crash happens in the "upper" layers. So, it's not really
a test for the crash. But at least have such a file in
our repository.

[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/235
2019-08-24 13:38:33 +02:00
Thomas Haller
017a4b274f ifupdown/tests: cleanup tests by freeing Expected variable with nm_auto() 2019-08-24 13:31:19 +02:00
Thomas Haller
af277fdedc bluetooth: fix getting error code creating sdp-session in nm_bluez5_dun_connect() 2019-08-24 11:32:16 +02:00
Thomas Haller
25571bb639 bluetooth: fix leak in get_managed_objects_cb()
Fixes: 1ae5d53354 ('bluez: add support for BlueZ 5')
2019-08-23 11:54:09 +02:00
Thomas Haller
aa100d89a4 core/logging: don't log plain pointer value from nm_log_ptr()
Logging pointer values might reveal information that can be used to defeat
ASLR. We should avoid that.

On the other hand, it's useful to tag a logging message with the pointer
value of the "source" of the message. It helps to correlate messages and
search for relevant messages in the log.

As a compromise, use NM_HASH_OBFUSCATE_PTR(), like we do at several places
already. For example, we also log

  <debug> [1566550899.7901] setup NMPlatform singleton (29a6af9867f2e5d0)

This obfuscated value is a 64 bit unsigned integer with the siphash24
hash of the raw value with a randomized seed. Of course, contrary to the
pointer value, there is a tiny chance that two different pointers hash
to the same identifier. However, that seems unlikely enough to be of no
concern. Note that this pointer value is only logged to aid debugging.
It is sufficiently unlikely that this causes confusion.

One other downside of printed the obfuscated value, is that you can no
longer read the pointer from the log and use it in gdb directly. That
might be sometimes convenient, but making this impossible is kinda the
purpose of this change.

As such, nm_log_ptr() becomes a bit of a misnomer. But not too bad, it
still is a good name. For example, if we wanted we could redefine the
NM_HASH_OBFUSCATE_PTR* macros when building "--with-more-asserts".
2019-08-23 11:19:17 +02:00
Thomas Haller
2f8a4e90f0 wifi: detect FT support per interface and avoid enabling it
Previously we only cared whether supplicant is build with support for
FT. In that case we would pass FT-PSK to supplicant, like

  Config: added 'key_mgmt' value 'WPA-PSK WPA-PSK-SHA256 FT-PSK'

Supplicant would then always try FT with preference, regardless whether
the interface/driver support it. That results in a failure to associate, if
the driver does not support it.

  NetworkManager[1356]: <info>  [1566296144.9940] Config: added 'key_mgmt' value 'WPA-PSK WPA-PSK-SHA256 FT-PSK'
  ...
  wpa_supplicant[1348]: wlan0: WPA: AP key_mgmt 0x42 network profile key_mgmt 0x142; available key_mgmt 0x42
  wpa_supplicant[1348]: wlan0: WPA: using KEY_MGMT FT/PSK
  ...
  wpa_supplicant[1348]:   * akm=0xfac04
  ...
  kernel: ERROR @wl_set_key_mgmt :
  kernel: invalid cipher group (1027076)

Since we pass a list of acceptable "key_mgmt" options to supplicant,
FT-PSK should not be used when supplicant knows it's not supported.
That is a supplicant bug.

Regardless, work around it by checking the per-interface capability, and
avoid it if support is apparently not present.
2019-08-20 16:28:28 +02:00
Thomas Haller
c167e0140b all: allow configuring default-routes as manual, static routes
Up until now, a default-route (with prefix length zero) could not
be configured directly. The user could only set ipv4.gateway,
ipv4.never-default, ipv4.route-metric and ipv4.route-table to influence
the setting of the default-route (respectively for IPv6).

That is a problematic limitation. For one, whether a route has prefix
length zero or non-zero does not make a fundamental difference. Also,
it makes it impossible to configure all the routing attributes that one can
configure otherwise for static routes. For example, the default-route could
not be configured as "onlink", could not have a special MTU, nor could it be
placed in a dedicated routing table.

Fix that by lifting the restriction. Note that "ipv4.never-default" does
not apply to /0 manual routes. Likewise, the previous manners of
configuring default-routes ("ipv4.gateway") don't conflict with manual
default-routes.

Server-side this all the pieces are already in place to accept a default-route
as static routes. This was done by earlier commits like 5c299454b4
('core: rework tracking of gateway/default-route in ip-config').

A long time ago, NMIPRoute would assert that the prefix length is
positive. That was relaxed by commit a2e93f2de4 ('libnm: allow zero
prefix length for NMIPRoute'), already before 1.0.0. Using libnm from
before 1.0.0 would result in assertion failures.

Note that the default-route-metric-penalty based on connectivity
checking applies to all /0 routes, even these static routes. Be they
added due to DHCP, "ipv4.gateway", "ipv4.routes" or "wireguard.peer-routes".
I wonder whether doing that unconditionally is desirable, and maybe
there should be a way to opt-out/opt-in for the entire profile or even
per-routes.

https://bugzilla.redhat.com/show_bug.cgi?id=1714438
2019-08-13 10:45:04 +02:00
Thomas Haller
75503c8554 dhcp: minor refactoring to switch default IPv4 DHCP plugin to "nettools" with one-line change
Minor refactoring so that there is only a one-line change necessary to
flip the implementation of the "internal" DHCP plugin for IPv4 from
"systemd" to "nettools".

We don't do that yet, because there are still some issues (e.g. the
lease is not persisted for nettools plugin). Eventually we want to
switch, so prepare the code to be almost there.
2019-08-13 09:42:15 +02:00
Thomas Haller
b53e261427 dhcp: make "systemd" DHCP plugin configurable
We have the "internal" DHCP plugin. That's our preferred plugin,
and eventually we may drop all other plugins.

Currently, the "internal" plugin is based on code from systemd-networkd
and implemented in "src/dhcp/nm-dhcp-systemd.c". As this code is forked
we eventually want to switch to nettools' n-dhcp4 library (for IPv4).
For that reason we already have "src/dhcp/nm-dhcp-nettools.c".

Note that "nettools" can be configured as a DHCP plugin, but this configuration
is only experimental and for testing. There is never supposed to be a
"nettools" plugin, but eventually the "internal" plugin will switch
implementation.

We don't want to replace systemd-based implementation right away. Not until
we are sure that nettools works well. For that reason we keep them
both in parallel for a while.

This commit makes "systemd" DHCP plugin explicitly configurable
in NetworkManager.conf. Like "nettools" this is an undocumented option,
only for testing.

If you choose "internal" (the default), you get one of the
implementations (currently the "systemd" one). But by selecting
"systemd" or "nettools" explicitly, you can select the exact plugin.
2019-08-13 09:42:15 +02:00
Thomas Haller
8d8cc0da3d dhcp: log effectively used DHCP plugin type 2019-08-13 09:42:15 +02:00
Thomas Haller
b32cf71814 dhcp: cleanup selecting GType from DHCP client factory
Instead of returning a client-factory, return the GType right
away.
2019-08-13 09:42:15 +02:00
Thomas Haller
3e8cba2e5b bluetooth: add _NMLOG() logging macro to NMBluezDevice 2019-08-12 16:07:12 +02:00
Thomas Haller
a76e906dca bluetooth: pass GDBusConnection to NMBluezDevice
No need to let NMBluezDevice ask for glib's G_BUS_TYPE_SYSTEM
connection. We already have the right D-Bus connection at hand,
just use it.
2019-08-12 16:07:12 +02:00
Thomas Haller
3c9b646524 bluetooth: drop BlueZ 4 support (2) 2019-08-12 16:07:05 +02:00
Thomas Haller
907ea97088 bluetooth: drop BlueZ 4 support (1)
BlueZ 5.0 was released in December 2012 and broke API with
BlueZ 4. NetworkManager supports Bluez 5 for years already.

Of course, version 4 is long gone by now, so remove it.
2019-08-12 16:05:30 +02:00
Thomas Haller
b80784a785 auth: drop unused idle-reason for NMAuthManagerCallId
We now only call the idle action with the same reason: authorized.
That is since we no longer use GDBusProxy, there are no other reasons
where we would fail.

Drop the unused code.
2019-08-10 10:36:17 +02:00
Thomas Haller
4e36521d4c settings: return errno from nms_keyfile_nmmeta_write() for better logging
I encountered a failure in the log

    <trace> [1564647990.7822] keyfile: commit: deleting nmmeta file "/etc/NetworkManager/system-connections/35370b0b-e53b-42ea-9fe3-f1b1d552343b.nmmeta" failed
    <trace> [1564647990.7822] keyfile: commit: deleting nmmeta file "/etc/NetworkManager/system-connections/35370b0b-e53b-42ea-9fe3-f1b1d552343b.nmmeta" simulated

I think that was due to SELinux (rh #1738010).

Let nms_keyfile_nmmeta_write() return an errno code so we can log
more information about the failure.
2019-08-08 12:03:15 +02:00
Thomas Haller
b216abb012 shared,all: return boolean success from nm_utils_file_get_contents()
... and nm_utils_fd_get_contents() and nm_utils_file_set_contents().

Don't mix negative errno return value with a GError output. Instead,
return a boolean result indicating success or failure.

Also, optionally

  - output GError

  - set out_errsv to the positive errno (or 0 on success)

Obviously, the return value and the output arguments (contents, length,
out_errsv, error) must all agree in their success/failure result.
That means, you may check any of the return value, out_errsv, error, and
contents to reliably detect failure or success.

Also note that out_errsv gives the positive(!) errno. But you probably
shouldn't care about the distinction and use nm_errno_native() either
way to normalize the value.
2019-08-08 11:59:59 +02:00
Thomas Haller
1bad35061f shared: let nm_utils_file_set_contents() return a errno error code
nm_utils_file_set_contents() is a re-implementation of g_file_set_contents(),
as such it returned merely a boolean success value.

It's sometimes interesting to get the native error code. Let the function
deviate from glib's original g_file_set_contents() and return the error code
(as negative value) instead.

This requires all callers to change. Also, it's potentially a dangerous
change, as this is easy to miss.

Note that nm_utils_file_get_contents() also returns an errno, and
already deviates from g_file_get_contents() in the same way. This patch
resolves at least the inconsistency with nm_utils_file_get_contents().
2019-08-08 10:53:03 +02:00
Thomas Haller
f662465948 secret-agent: rework secret-agent to better handle service shutdown
The secret-agent D-Bus API knows 4 methods: GetSecrets, SaveSecrets,
DeleteSecrets and CancelGetSecrets. When we cancel a GetSecrets
request, we must issue another CancelGetSecrets to tell the agent
that the request was aborted. This is also true during shutdown.
Well, technically, during shutdown we anyway drop off the bus and
it woudn't matter. In practice, I think we should get this right and
always cancel properly.

To better handle shutdown change the following:

- each request now takes a reference on NMSecretAgent. That means,
  as long as there are pending requests, the instance stays alive.
  The way to get this right during shutdown, is that NMSecretAgent
  registers itself via nm_shutdown_wait_obj_register() and
  NetworkManager is supposed to keep running as long as requests
  are keeping the instance alive.

- now, the 3 regular methods are cancellable (which means: we are
  no longer interested in the result). CancelGetSecrets is not
  cancellable, but it has a short timeout NM_SHUTDOWN_TIMEOUT_MS
  to handle this. We anyway don't really care about the result,
  aside logging and to be sure that the request fully completed.

- this means, a request (NMSecretAgentCallId) can now immediately
  be cancelled and destroyed, both when the request returns and
  when the caller cancels it. The exception is GetSecrets which
  keeps the request alive while waiting for CancelGetSecrets. But
  this is easily handled by unlinking the call-id and pass it on
  to the CancelGetSecrets callback.
  Previously, the NMSecretAgentCallId was only destroyed when
  the D-Bus call returns, even if it was cancelled earlier. That's
  unnecessary complicated.

- previously, D-Bus requests SaveSecrets and DeleteSecrets were not cancellable.
  That is a problem. We need to be able to cancel them in order to shutdown in
  time.

- use GDBusConnection instead of GDBusProxy. As most of the time, GDBusProxy
  provides features we don't use.

- again, don't log direct pointer values, but obfuscate the indentifiers.
2019-08-08 10:10:34 +02:00
Thomas Haller
52f9c8ecf3 secret-agent: use NMCListElem to track permissions in NMSecretAgent
I don't like GSList.
2019-08-08 10:07:55 +02:00
Thomas Haller
91364f4c0a secret-agent/trivial: rename dbus_connection field of NMSecretAgentPrivate 2019-08-08 10:07:55 +02:00
Thomas Haller
a010484c40 secret-agent: avoid log plain pointer values
This defeats ASLR. Obfuscate the pointers.
2019-08-08 10:07:55 +02:00
Thomas Haller
0dbb870f82 dbus-manager: drop unused private-socket functions from "nm-dbus-manager.c"
These functions are now unused. Drop them.

Also, if we ever reintroduce private unix socket, we sure won't use
GDBusProxy. Good riddance.
2019-08-08 10:07:55 +02:00
Thomas Haller
8a347dbd55 secret-agent: drop unused private-socket code from secret-agent
In the past, we had a private unix socket. That is long gone.
Drop the remains in "nm-secret-agent.c". The request here really
always comes from the main D-Bus connection.

Maybe the private unix socket makes sense and we might resurrect it one
day. But at that point it would be an entire rewrite and the existing
code is probably not useful either way. Drop it.
2019-08-08 10:07:55 +02:00
Thomas Haller
58e5e55f17 secret-agent: enable trace log messages
They seem useful for debugging. Don't only enable them --with-more-logging.
2019-08-08 10:07:55 +02:00
Thomas Haller
dda3289206 shared: add nm_c_list_elem_find_first() helper macro
- add nm_c_list_elem_find_first() macro that takes a predicate
  and returns the first match.

  This macro has a non-function-like behavior, which we often try to
  avoid because macros should behave like functions. In this case it's
  however convenient, so let's do it.
  Also, despite being non-function-like, it should be pretty hard to
  use wrongly.

- rename nm_c_list_elem_find_first() to nm_c_list_elem_find_first_ptr().
2019-08-08 10:07:15 +02:00
Thomas Haller
1b59d752be firewall: refactor "nm-firewall-manager.c" to not use GDBusProxy
- Don't use GDBusProxy but plain GDBusConnection. NMFirewallManager
  is very simple, it doesn't use any of the features that GDBusProxy
  provides.

- make NMFirewallManagerCallId typedef a pointer to the opaque call-id
  struct, instead of the struct itself. It's confusing to have a
  variable that does not look like a pointer and assigning %NULL to
  it.

- internally drop the CBInfo typename and name the call-id variable
  constsistantly as "call_id".

- no need to keep the call-id struct alive after cancelling it. That
  simplifies the lifetime managment of the pending call because the
  completion callback is always invoked shortly before destroying
  the call-id.

- note that the caller is no longer allowed to cancel a call-id from
  inside the completion callback. That just complicates the
  implementation and is not necessary. Assert against that.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/230
2019-08-07 13:21:48 +02:00
Thomas Haller
ddb08e3602 ifupdown: fix assertion during logging %NULL storage in load_eni_ifaces() 2019-08-06 12:10:37 +02:00
Beniamino Galvani
22cd9e754b modem: fix memory leak
Fixes: 9b935fad9b ('modem: don't use GAsyncResult pattern for disconnecting modem')
2019-08-06 08:35:01 +02:00
Beniamino Galvani
91b9b08e33 build: fix meson warning about wrong custom target argument
src/meson.build:294: WARNING: Custom target input 'NetworkManager'
can't be converted to File object(s).
This will become a hard error in the future.
2019-08-05 16:05:30 +02:00
Beniamino Galvani
956ffb7e96 settings: fix memory leak
Fixes: d35d3c468a
2019-08-05 09:36:12 +02:00
Thomas Haller
1634fff1ad settings: fix registering AgentManager.RegisterWithCapabilities() twice
Fixes: 297d4985ab
2019-08-03 18:33:55 +02:00