Commit graph

19949 commits

Author SHA1 Message Date
Thomas Haller
f0bddb44e0 auth-manager: add helper function nm_auth_call_result_eval()
This makes NMAuthCallResult not only usable from within a NMAuthChain.
It makes sense to just call nm-auth-manager directly, but then we need
a way to convert the more detailed result into an NMAuthCallResult
value.
2018-04-13 09:09:46 +02:00
Thomas Haller
798b2a7527 auth-manager: let NMAuthChain always call to NMAuthManager for dummy requests
NMAuthChain's nm_auth_chain_add_call() used to add special handling for
the NMAuthSubject. This handling really belongs to NMAuthManager for two
reasons:
 - NMAuthManager already goes through the effort of scheduling an idle
   handler to handle the case where no GDBusProxy is present. It can
   just as well handle the special cases where polkit-auth is disabled
   or when we have internal requests.
 - by NMAuthChain doing special handling, it makes it more complicated
   to call nm_auth_manager_check_authorization() directly. Previously,
   the NMAuthChain had additional logic, which means you either were
   forced to create an NMAuthChain, or you had to reimplement special
   handling like nm_auth_chain_add_call().
2018-04-13 09:09:46 +02:00
Thomas Haller
41abf9f8e8 auth-manager: always compile D-Bus calls to polkit
Supporting PolicyKit required no additional library, just extra code
to handle the D-Bus calls. For that, there was a compile time option
to even stip out that code. Note, that you could (and still can)
configure the system not to use policy-kit. The point was to reduce
the binary size in case you don't need it.

Remove this. I guess, we we aim for such aggressive optimization of
the binary size, we should instead make all device types disablable
at configuration time. We don't do that either and other low hanging
fruits, because it's better to always enable features, unless they
require external dependencies.

Also, the next commit will make more use of NMAuthManager. So, having
it disabled at compile time, makes even less sense.
2018-04-13 09:09:46 +02:00
Thomas Haller
2ea2df3184 auth-manager: rework auth-manager's API
Don't use the GAsyncResult pattern for internal API of auth-manager. Instead,
use a simpler API that has a more strict API and simpler use.

- return a call-id handle when scheduling the authorization request.
  The request is always scheduled asynchronsously and thus call-id
  is never %NULL.
- the call-id can be used to cancel the request. It can be used exactly
  once, and only before the callback is invoked.
- the async keeps the auth-manager alive. It needs to do so, because
  when cancelling the request we might not yet be done: instead we
  might still need to issue a CancelCheckAuthorization call (which
  we need to handle as well).
- the callback is always invoked exactly once.

Currently NMAuthManager's API effectivly is only called by NMAuthChain.
The point of this is to make NMAuthManager's API more consumable, and
thus let users use it directly (instead of using the NMAuthChain layer).

As well known, we don't do a good job during shutdown of NetworkManager
to release all resources and cancel pending requests. This rework also
makes it possible to actually get this right. See the comment in
nm_auth_manager_force_shutdown(). But yes, it is still a bit complicated
to do a controlled shutdown, because we cannot just synchronously
complete. We need to issue CancelCheckAuthorization D-Bus calls, and
give these requests time to complete. The new API introduced by this patch
would make that easier.
2018-04-13 09:09:46 +02:00
Thomas Haller
999594a56f auth-manager: drop unused property getter for NM_AUTH_MANAGER_POLKIT_ENABLED
We need the setter, because we want that the property is set only
once during creation of the instance. Nobody cares about the GObject
property getter otherwise.
2018-04-13 09:09:46 +02:00
Thomas Haller
f8b74e19ea auth-manager: emit signal by ID
It's more efficient, as it saves a lookup by name. Also,
it's more idiomatic to do it this way. I didn't find where
the signal gets emitted at first, because usually we don't emit
by name.
2018-04-13 09:09:46 +02:00
Thomas Haller
290d02536c auth-chain: avoid another idle-call when auth-request completes
NMAuthChain schedules (possibly) multiple authentication requests.
When they all complete, it will once invoke the result-callback.

There is no need to schedule this result-callback on another idle-handler,
because nm_auth_manager_polkit_authority_check_authorization() should guarantee
to invoke the callback never-synchronously and on a clean call-stack (to avoid
problems with re-entrancy). At that point, NMAuthChain does not need to
delay this further.
2018-04-13 09:09:46 +02:00
Thomas Haller
50b74731f6 auth-chain/trivial: rename nm_auth_chain_unref() to nm_auth_chain_destroy()
NMAuthChain is not really ref-counted. True, we have an internal ref-counter
to ensure that the instance stays alive while the callback is invoked. However,
the user cannot take additional references as there is no nm_auth_chain_ref().

When the user wants to get rid of the auth-chain, with the current API it
is important that the callback won't be called after that point. From the
name nm_auth_chain_unref(), it sounds like that there could be multiple references
to the auth-chain, and merely unreferencing the object might not guarantee that
the callback is canceled. However, that is luckily not the case, because
there is no real ref-counting involved here.

Just rename the destroy function to make this clearer.
2018-04-13 09:09:46 +02:00
Thomas Haller
bfaa291d89 core: use NMDBusTrackObjPath for NM_DEVICE_ACTIVE_CONNECTION path 2018-04-13 09:09:46 +02:00
Thomas Haller
be70e71698 core: use NMDBusTrackObjPath for NM_DEVICE_PARENT path 2018-04-13 09:09:46 +02:00
Thomas Haller
1acb3622aa core: use NMDBusTrackObjPath for NM_ACTIVE_CONNECTION_CONNECTION path 2018-04-13 09:09:46 +02:00
Thomas Haller
86229a669b core: add NMDBusTrackObjPath helper
When one D-Bus object exposes (the path of) another D-Bus object,
we want that the path property gets cleared before the other
object gets unexported(). That essentially requires to register
to the "exported-changed" signal.

Add a helper struct NMDBusTrackObjPath to help with this.
2018-04-13 09:09:46 +02:00
Thomas Haller
4127f1234f settings: track connections via CList 2018-04-13 09:09:46 +02:00
Thomas Haller
0dd3e6099c core: don't unexport active-connection when settings connection disappears
When a settings-connection gets deleted, we need to bring down the
NMActiveConnection that contains it. However, we shouldn't just unexport
the active connection from D-Bus. Instead, clear the settings path.

We need to drop the path, because the connection is going away. It's a
bit ugly, that an active-connection might reference no
settings-connection. However, this only happens during shut-down.
The alternative, would be to keep the settings-connection object
in a zombie state, exported on D-Bus. However, that seems even more
confusing to me.
2018-04-13 09:09:46 +02:00
Thomas Haller
cd71ec3084 core: convert NMDBusObject's "path" property to signal "exported-changed"
The GObject property "path" exists for the sole reasons so that
other components can connect to the "notify::path" signal.

However, notifications are blocked by g_object_freeze_notify(),
and especially for NMDBusObject we want to make use of that to
combine multiple PropertiesChanged events into one.

This blocking of the signal is not desired for the case where
we wait for "notify::path". Convert that to a signal, which
will not be blocked.
2018-04-13 09:09:46 +02:00
Thomas Haller
7595b4f1c7 settings: don't let connection keep NMSettings alive
NMSettings already references NMSettingsConnection. Hence, it should not
at the same time reference itself. Arguably, during shutdown we do not properly
release all NMSettingsConnection. For example, there is no nm_settings_stop().
But that is a bug that needs fixing.

No need to keep the NMSettings instance alive here. If this is really
necessary, it needs fixing somewhere else. Besides, we know that we leak
a lot during shutdown, so this needs more work to do a clean shutdown.
2018-04-13 09:09:46 +02:00
Thomas Haller
1f3b47deea settings: reorder D-Bus events when removing settings-connection
It makes more sense to me this way.
2018-04-13 09:09:46 +02:00
Thomas Haller
ebd53888b6 core: avoid unnecessary action in NMPolicy's _deactivate_if_active()
We only need @state, after we verified that the active connection
references the right settings connection. Most of the time, that
is not the case.
2018-04-13 09:09:46 +02:00
Thomas Haller
dcbb5c07e1 core: drop unused NMConnectionProvider typedef
We dopped NMConnectionProvider a while ago. Forgot something.

Fixes: 5337003c4c
2018-04-13 09:09:46 +02:00
Thomas Haller
1b532b5fdc core: minor cleanup of nm_utils_g_value_set_strv()
Add some assertion, use an unsigned loop variable (that matches
GPtrArray.len type), and add a comment.
2018-04-13 09:09:46 +02:00
Thomas Haller
a5e9980b34 core: use nm_dbus_utils_g_value_set_object_path_from_hash() 2018-04-13 09:09:46 +02:00
Thomas Haller
de5d07392d libnm: optimize nm_simple_connection_new_clone() to not needlessly set the path
Server never sets the path, so this is entirely unused server-side.
Also NMConnection is a glib interface and stores it's private date
in the GObject's data. It's less efficient to look it up. Just
avoid it.
2018-04-13 09:09:46 +02:00
Thomas Haller
755c8bb30f settings: no longer call nm_connection_set_path() in server
It's unused.
2018-04-13 09:09:46 +02:00
Thomas Haller
b0bf9b2b9b core: explicitly pass D-Bus path to nm_utils_log_connection_diff()
No longer rely on nm_connection_get_path() being meaningful in server.
It also was wrong. During update, nm_settings_connection_update()
would call
  nm_utils_log_connection_diff (replace_connection, NM_CONNECTION (self), ...
where replace_connection has no path set, and nothing was logged.

Fix it, by explicitly passing the D-Bus path. Also, because
nm-core-utils.c should be independent of nm-dbus-object.h.
2018-04-13 09:09:46 +02:00
Thomas Haller
9efa7c7220 core: use nm_dbus_object_get_path() instead of nm_connection_get_path()
Essentially, nm_connection_get_path() mirros nm_dbus_object_get_path().
However, when cloning a simple-connection, the path also gets cloned.

I think this field doesn't belong to NMConnection in the first place,
because NMConnection is not a D-Bus object. NMSettingsConnection (in
core) and NMRemoteConnection (in libnm) is.

Don't use the misleading alias, but use nm_dbus_object_get_path()
directly.
2018-04-13 09:09:46 +02:00
Thomas Haller
efe5cf79c0 core: simplify NMActiveConnection.get_property to not create temporary GPtrArrray
Fixes: c050fb7cd2
2018-04-13 09:09:46 +02:00
Thomas Haller
fdbf696f22 settings: clear connection path when unexporting from D-Bus
At that point, the path becomes meaningless. Clear it.
2018-04-13 09:09:46 +02:00
Thomas Haller
24c3eacac6 settings/trivial: add code comments 2018-04-13 09:09:46 +02:00
Thomas Haller
f41279ca1d settings: use cleanup attribute to keep connection alive during connection_removed() 2018-04-13 09:09:46 +02:00
Thomas Haller
213323a6a7 settings: fix unrefing setting is there are no plugins loaded
This wasn't a problem, because load_plugins() can only fails
if the settings plugins fail to load, which can only happen
if you have a broken installation.
2018-04-13 09:09:46 +02:00
Thomas Haller
8c56c47bba settings: handle default-wired-connection in connection-removed signal
Don't subscribe twice to the same signal. The more subscribers a
signal has, the more confusing it gets what is happening.

We can handle also the default-wired-connection in the regular
connection-removed signal.

Note how connection_removed() is registered with
g_signal_connect_after(), but that is fine. There are few subscribers
to this signal (that don't do anything that interferes here).
Especially, since all other subscribers subscribe with the same
priority (hence, are unordered). So, moving this task explicitly
to after, does not change any ordering guarantee -- in fact, it
ensures an ordering that was undefined previously. Anyway, it
doesn't matter.
2018-04-13 09:09:46 +02:00
Thomas Haller
76df7a3088 shared: add nm_dbus_utils_get_paths_for_clist() util 2018-04-13 09:09:46 +02:00
Thomas Haller
67e06924e1 core/trivial: add code comment to NMActiveConnection's get_property() 2018-04-13 09:09:46 +02:00
Thomas Haller
d95717cdbe auth-chain: remove unused error argument 2018-04-13 09:09:46 +02:00
Thomas Haller
786adf969c manager: don't coalesce duplicate internal activations with different reasons
When combining internal activations, do that only if their reason also
matches.

Fixes: 4985ca5ada
2018-04-12 15:57:39 +02:00
Thomas Haller
69b7a76dc2 device: merge branch 'pr/92'
https://bugzilla.gnome.org/show_bug.cgi?id=795196
https://github.com/NetworkManager/NetworkManager/pull/92
2018-04-12 14:23:25 +02:00
Thomas Haller
251e5707d5 device: return early from handle_auth_or_fail() on failure
Don't do if-else, if one branch is going to return with failure.
2018-04-12 14:17:05 +02:00
Thomas Haller
d5ee549e07 device: let macsec connection fail on supplicant timeout if no secrets are required
Like for ethernet.
2018-04-12 14:17:05 +02:00
Michael Schaller
7dab990eb2 device: let Ethernet connection fail on supplicant timeout if no secrets are required
Without this patch an Ethernet connection attempt that encountered a supplicant
timeout was stuck in the needs-auth state even if it didn't require secrets.
This patch applies the respective WiFi behaviour also to Ethernet devices.

https://bugzilla.gnome.org/show_bug.cgi?id=795196
https://github.com/NetworkManager/NetworkManager/pull/92
2018-04-12 14:16:53 +02:00
Thomas Haller
f92a68c9e5 device/trivial: add code comment to nm_device_ipv4_sysctl_get_effective_uint32() 2018-04-12 13:48:12 +02:00
Beniamino Galvani
150cf44d50 device: look at 'all' rp_filter value too to determine actual value
Currently we overwrite the interface rp_filter value with 2 ("loose")
only when it is 1 ("strict") because when it is 0 ("no validation") it
is already more permissive.

So, if the value for the interface is 0 and
net/ipv4/conf/all/rp_filter is 1 (like it happens by default on Fedora
28), we don't overwrite it; since kernel considers the maximum between
{all,$dev}/rp_filter, the effective value remains 'strict'.

We should instead combine the two {all,$dev}/rp_filter, and if it's 1
overwrite the value with 2.

https://bugzilla.redhat.com/show_bug.cgi?id=1565529
2018-04-12 09:53:32 +02:00
Beniamino Galvani
ae8015b4a5 build: meson: merge branch 'bg/meson-tests'
Enable all tests when building with meson.
2018-04-12 09:21:39 +02:00
Beniamino Galvani
0136915211 build: meson: add prefix to test names
There are multiple tests with the same in different directories; add a
unique prefix to test names so that it is clear from the output which
one is running.
2018-04-12 09:21:10 +02:00
Beniamino Galvani
0c39a02ce0 build: meson: enable all tests again
Some tests were disabled because they failed when run in parallel.
Now that we use the wrapper script they succeed and can be enabled
again.
2018-04-12 09:21:10 +02:00
Beniamino Galvani
0dace9b52a build: meson: increase timeout for some tests
Some tests, when run in parallel, can take more than the default
timeout (30 seconds). Increase the timeout for them.
2018-04-12 09:21:10 +02:00
Beniamino Galvani
a2479b95c0 build: meson: use run-nm-test.sh to run tests
Like autotools, use the wrapper script 'run-nm-test.sh' that starts a
separate D-Bus session when needed.
2018-04-12 09:21:10 +02:00
Thomas Haller
3b5a522ef6 connectivity: merge branch 'th/fix-fake-connectivity-state'
https://github.com/NetworkManager/NetworkManager/pull/89
2018-04-12 08:23:29 +02:00
Thomas Haller
d0cee07a0f connectivity: fix the device's fake connectivity state
Otherwise, if connectivity checking was disabled, we would never
reset the connectivity state and leave it wrongly at UNKNOWN.

nm_device_check_connectivity_update_interval() is already called
during state-changes, so this is the right place. However,
it's far from perfect still, because we might not notice when
a default-route gets added or removed. Also, devices that are not
in ACTIVATED state, are considered with connectivity NONE. Which
might not be correct.

Fixes: 0a62a0e903
2018-04-11 12:06:36 +02:00
Thomas Haller
f48b4af850 manager: merge set_state() in nm_manager_update_state() function 2018-04-11 11:45:42 +02:00
Thomas Haller
835a5f7248 connectivity: also expose fake connectivity states to dispatcher
The fake states still encode whether the device have a default-route.
So, they are not entirely useless. Also, don't add special handling
of "#if !WITH_CONCHECK" where we don't need it.

There is no fundamental difference between compiling without connectivity
check and disabling connectivity checks.
2018-04-11 11:38:02 +02:00