Commit graph

1060 commits

Author SHA1 Message Date
Simon McVittie
ea0275aaea bus_config_parser_check_doctype: Remove, unused
We have never checked the <!DOCTYPE> of busconfig XML since the libxml
parser was removed in 2013, and the libxml parser was broken before
that anyway. The recommended Expat parser (our only parser since 2013)
does not appear to have ever validated this, so now does not seem like
the time to start. Just ignore the <!DOCTYPE> if there is one.

(We never validated this particularly strictly anyway;
<!DOCTYPE busconfig SYSTEM "http://example.com/bees"> would have been
treated as perfectly valid.)

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:38 +01:00
Simon McVittie
10124ae11e BusConfigParser test: Check that all limits are equal, not just one
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:35 +01:00
Simon McVittie
2b8c1b0813 bus_context_get_policy: Remove, unused
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:34 +01:00
Simon McVittie
a3800e2d41 bus_connections_get_context: Remove, unused
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:33 +01:00
Simon McVittie
170adbd6af bus_connections_foreach, bus_connections_foreach_active: Remove
These do not appear in code coverage statistics, and `git grep`
reveals that they are unused.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:31 +01:00
Simon McVittie
7ae750c4e8 bus: Free address (from --address) when we have finished using it
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107320
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2018-08-23 18:23:21 +01:00
Simon McVittie
bbe7935196 dispatch test: Simplify OOM testing
Instead of having separate test wrappers for the cases that do and
don't take a DBusConnection, we can just pass a NULL DBusConnection
to the one that doesn't.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:17:07 +01:00
Simon McVittie
46cdc12830 Add and use _dbus_list_clear_full
In gcc 8, -Wall -Wextra includes -Wcast-function-type, which warns
about passing an extra (unwanted) parameter to callbacks. Instead
of using _dbus_list_foreach(), add a function to do what we actually
wanted here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107349
Reviewed-by: Thiago Macieira <thiago@kde.org>
2018-08-02 15:26:27 +01:00
Simon McVittie
7512fe4993 containers: Factor out connection_get_instance and make it NULL-safe
When I introduce per-container message filtering, it'll be useful to
be able to get the instance for a connection without worrying about
whether that connection is NULL (representing the dbus-daemon itself,
or an activatable service that has not yet been activated).

Also make it robust against Containers having not been initialized,
for completeness.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656
2018-06-21 17:42:16 +01:00
Simon McVittie
9a369ee3bd bus: Document arguments of bus_activation_activate_service
It isn't completely obvious that connection is allowed to be NULL here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656
2018-06-21 17:42:15 +01:00
Simon McVittie
7389460247 bus_service_list_queued_owners: Don't return a DBusError
This makes it clearer that the only possible error is out-of-memory,
so its use in ListQueuedOwners() is not leaking information to callers
that might not be allowed to know the difference between "doesn't exist"
and "exists but you are not allowed to know that".

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656
2018-06-21 17:42:12 +01:00
Simon McVittie
f67509cbaf bus_driver_get_owner_of_name: Clarify role of connection
This connection is the one looking at the name, as opposed to the
one that owns the name (if any).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656
2018-06-21 17:42:09 +01:00
Simon McVittie
f366c4748a driver: Remove references to an obsolete constant
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656
2018-06-20 12:12:57 +01:00
Simon McVittie
66246fff2a bus: Clear INVOCATION_ID when carrying out traditional activation
We weren't sure whether this one should be inherited or not, so I
asked on systemd-devel, and Lennart thought it shouldn't.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2018-03-22 19:25:16 +00:00
Ralf Habacker
7c9f6ca79b bus_connection_get_unix_groups: NULL-check *groups, not groups
groups is never NULL here, but *groups can be NULL on OOM, and that's the
check that was intended.

Coverity ID 265358.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737
Reviewed-by: Simon McVittie <smcv@collabora.com>
2018-03-20 13:27:59 +01:00
Simon McVittie
52594df070 bus driver: Use DBusCredentials to fill credentials structure
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737
2018-03-02 14:52:20 +00:00
Simon McVittie
395269e0bc bus: Get loginfo string bits from DBusCredentials
This saves a couple of _dbus_strdup/dbus_free pairs.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737
2018-03-02 14:52:17 +00:00
Simon McVittie
aaf690e805 bus: Try to get groups directly from credentials, not userdb
If we avoid consulting the userdb, then it's one less chance to
deadlock.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2018-03-02 14:52:06 +00:00
Simon McVittie
03c0db9ff5 bus: Also tell systemd before we shut down
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641
2018-03-02 14:49:15 +00:00
Simon McVittie
c937a39e4b bus: Also tell systemd when we're reloading
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641
2018-03-02 14:49:11 +00:00
Simon McVittie
18a0a8892b bus: Notify systemd when we are ready
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2018-03-02 14:48:49 +00:00
Simon McVittie
be46707673 bus: Don't pass systemd environment variables to activated services
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104641
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2018-03-02 14:48:24 +00:00
David King
6e42964f5f bus: raise fd limits before dropping privs
Startup ordering was changed in #92832 to ensure that SELinux audit
messages could be sent. As a side effect, the raising of file descriptor
limits was moved to after the dropping of root privileges, resulting in
the limit change always failing.

Move the raise_file_descriptor_limit() call to ensure that it is called
before dropping root privileges.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105165
Bug-RedHat: https://bugzilla.redhat.com/show_bug.cgi?id=1529044
[smcv: Call raise_file_descriptor_limit() even if !context->user]
Reviewed-by: Simon McVittie <smcv@collabora.com>
2018-02-20 17:40:01 +00:00
Simon McVittie
624e924284 containers: Add a method to ask to be sent the connection instance header
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101899
2018-02-16 15:27:51 +00:00
Simon McVittie
953bc072a3 DBusMessage: Add a header field for the container instance
In the bus daemon, don't pass through the container instance path:
if there's any value here at all, we want to be able to guarantee that
we sent it (in a later commit).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101899
2018-02-16 15:27:37 +00:00
Simon McVittie
c6b91129fa bus_transaction_send: Take sender and destination connections
We'll need this if we want to stamp optional header fields on the
message according to the preferences of the recipient(s).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101899
2018-02-16 15:27:05 +00:00
Simon McVittie
8fd3073691 tmpfiles: Add a note that one line is not needed with newer systemd
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-01-29 11:59:40 +00:00
Simon McVittie
1086acbd79 containers: Include credentials of initiator in container instance info
This provides the necessary information for services to make an
informed decision about how far they should trust the container type,
name and metadata fields.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104610
2018-01-15 14:00:52 +00:00
Simon McVittie
d6d01c7881 driver: Factor out bus_driver_fill_connection_credentials
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104610
2018-01-15 14:00:20 +00:00
Simon McVittie
d7840fe7b4 bus driver: Omit container type, name from GetConnectionCredentials
On the session bus, the container type and name might be
uncontroversial, but on the system bus, it's questionable how far
they can be trusted: they're supplied by the initiator of the
per-container server, so we only have their word for it. While we
think about what to do about this, remove them, leaving only the
instance (which can be used to look up the rest).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104610
2018-01-15 12:28:57 +00:00
Simon McVittie
9bb330d82a dbus-daemon: Filter out unknown header fields
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100317
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-01-11 18:35:20 +00:00
Chris Lesiak
aeebf801f1 Modify systemd tmpfiles.d snippet to create /var/lib/dbus/
This snippet was already attempting to create /var/lib/dbus/machine-id,
but would fail on volatile or stateless systems where /var/lib/dbus/
did not already exist. systemd-tmpfiles automatically creates parent
directories for tmpfiles of type 'd', 'D', etc., but not for files
or symlinks (https://github.com/systemd/systemd/issues/7853).

Signed-off-by: Chris Lesiak <chris.lesiak@licor.com>
[smcv: Extended commit message to clarify why we need this]
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104577
Reviewed-by: Simon McVittie <smcv@collabora.com>
2018-01-11 12:33:03 +00:00
Simon McVittie
485e819693 system.conf: Allow creating containers on the system bus
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
a28b8c8640 bus/driver: Allow unprivileged connections to create app-containers
This lets ordinary users create a limited number of app-containers
on the system bus.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
4b4f2a89be containers: Enforce max_containers_per_user
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
62e8fd7a9c bus/containers: Enforce max_connections_per_container
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
7b5c76b655 bus/containers: Enforce max_containers limit
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
e4b5ec2b07 bus/containers: Limit the size of metadata we will store
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
913ea94c22 bus: Add (unused) settings for resource limits for containers
These will be enforced in subsequent commits.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Fix whitespace]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:35 +00:00
Simon McVittie
232615f371 bus/driver: Add GetConnectionInstance(), GetInstanceInfo()
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
843acf3c59 bus/driver: Add basic container info to GetConnectionCredentials()
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
fa139de711 bus/driver: Containers can't use the Verbose and Stats interfaces
These are debugging interfaces, which are essentially read-only.
By default, Verbose is not available on the system bus at all and
Stats is only available to uid 0, but both are available on the
session bus, and they can be allowed for other uids by configuring
the system bus.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
85c428d937 bus/driver: Add a flag for methods that can't be invoked by containers
We can relax AddServer() from PRIVILEGED to NOT_CONTAINERS when we've
put resource limits in place, although for now it must remain
PRIVILEGED because it uses up resources.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
6b8ee7a68c bus/driver: Treat connections from inside containers as unprivileged
Even if the uid matches, a contained app shouldn't count as the owner
of the bus.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
7743c98b4b bus/containers: Indicate in loginfo whether connection is contained
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
7bf06575c4 bus/containers: Emit InstanceRemoved signal
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
0dc09f29ee bus/containers: Don't allow stopping other users' containers
On the system bus, that would be a denial of service, assuming we
relax the access-control from METHOD_FLAG_PRIVILEGED to a new
METHOD_FLAG_NOT_CONTAINERS later.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
69d164cbd3 bus/containers: Implement methods to stop containers explicitly
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
d5ff91ff9a bus/containers: Give each instance a list of all its connections
Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Fix minor conflict]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00
Simon McVittie
3048c90ccb bus/containers: Shut down container servers when initiator goes away
We will eventually want to have other ways to signal that a
container server should stop listening, so that the container manager
doesn't have to stay on D-Bus (fd-passing the read end of a pipe
whose write end will be closed by the container manager has been
suggested as easier to deal with for Flatpak/Bubblewrap), but for
now we're doing the simplest possible thing.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101354
2017-12-12 16:22:34 +00:00