Commit graph

1133 commits

Author SHA1 Message Date
Simon McVittie
9d60676ae0 Disable the Containers interface
We've had a request for a 1.14.x stable-branch, but the Containers
interface is only partially implemented, not yet described in the
D-Bus Specification, and not ready to be part of our API guarantees.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-12-10 16:48:51 +00:00
Ralf Habacker
3a2e0ba5fe Avoid assertation in bus_activation_reload()
In the mentioned function a local DBusError instance is now used to
fulfill the requirement of dbus_error_has_name() that the parameter
'error' must not be null.

See #360
2021-12-09 12:54:22 +01:00
Ralf Habacker
79df3d2811 tools/dbus-run-session: fix race between manual and automatically started dbus-daemon on Windows
dbus-run-session starts a dbus-daemon before the client application.
We must avoid letting the application try to connect before the
dbus-daemon's DBusServer is listening for connections.

In the Unix implementation, we already achieved this via the
--print-address option. If the client tried to connect too soon,
the server would not yet be listening and the client would fail.

In the Windows implementation, we communicate the bus address to
the client application as an autolaunch: address, so if the client
tried to connect too soon, it would autolaunch a new dbus-daemon
instead of using the one that it was intended to use.

We can avoid this by using a new option to pass in a Windows event
object, which will be set when the server has started and is ready
to process connections.

Fixes #297
2021-11-23 08:38:14 +01:00
Simon McVittie
81a5731bcb bus: Separate RemoveMatch into prepare and commit stages
This means we don't send a spurious successful reply if a caller removes
a match rule that they never added.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-22 16:10:51 +00:00
David Redondo
03b4fba4b0 Put dbus-daemon into session slice
The session slice and the  app and background slices are special slices defined by
https://systemd.io/DESKTOP_ENVIRONMENTS/, where:
  session.slice: Contains only processes essential to run the user’s graphical session
  app.slice: Contains all normal applications that the user is running
This allows users or sysadmins to control resource allocation depending on the type
of the service.
Since v249 (23dce98e89)
systemd puts user services into the app slice by default so dbus needs to manually state
that it belongs in the session slice.
2021-11-18 11:35:49 +00:00
Chris PeBenito
2d5d40d5a5 bus/selinux: Fix audit message types.
The SELinux log callback includes a message type. Not all messages are
auditable and those that are have varying audit types. An audit message is
a security-relevant event: security state changes, MAC permission denied,
etc.  A message that is auditable is not necessarily sensitive.  Messages
that are not auditable are not security-relevant, like messages about
socket polling errors.  Update the auditing accordingly.

If the message is not auditable, fall through and write it to syslog.

Signed-off-by: Chris PeBenito <chpebeni@linux.microsoft.com>
2020-11-23 13:07:19 +00:00
Ralf Habacker
5b1870a5bd cmake: make support for traditional activation optional
Traditional activation is enabled/disabled with the cmake configure
parameter -DENABLE_TRADITIONAL_ACTIVATION, which is enabled by default.

This was added to the Autotools build system as part of dbus/dbus!107
but until now was not possible to disable when building with CMake.
2020-09-23 17:21:40 +02:00
Ralf Habacker
2148a5a803 cmake: install dbus-daemon-launch-helper on Unix
Previously it was built on Unix platforms, but not installed. This
would prevent traditional activation on the system bus (on Linux
without systemd or non-Linux, or for services without SystemdService),
which requires the activation helper.

Because the executable is an internal implementation detail of how
traditional activation is implemented on Unix, it is not exported to
the generated cmake support files.

Resolves: dbus#310
2020-09-22 11:22:40 +02:00
Ralf Habacker
927a5f4d75 cmake: add support for user session semantic on Linux operating systems
Systemd user support is controlled by the cmake variable ENABLE_USER_SESSION,
which and WITH_SYSTEMD_USERUNITDIR to specify a custom installation
location. If WITH_SYSTEMD_USERUNITDIR is not specified, the related install
path is determined from an installed systemd package, if present.

This was added to the Autotools build system as part of fd.o#61301,
but until now was not possible to enable when building with CMake.
2020-06-10 18:13:47 +00:00
Ralf Habacker
97bdefd4e2 cmake: Add support for systemd integration on Linux operating systems
Previously, only the Autotools build system could do this. This commit
includes most of the same features as in the Autotools build, although
not the user-session semantics, which will be added separately.

Systemd support is controlled by the cmake variable ENABLE_SYSTEMD, which can
have the values OFF, ON and AUTO, the latter enabling support by default if
the required libraries are available.

With WITH_SYSTEMD_SYSTEMUNITDIR a custom installation location can be specified.
If it is not specified, the related install path is determined from the installed
systemd package, if present.
2020-06-10 18:13:47 +00:00
Ralf Habacker
3f3368b490 cmake: Use CMAKE_INSTALL_FULL_<dir> for configuration and state
This means we apply GNUInstallDirs' various special cases when
the prefix is /, /usr or something starting with /opt; these are
not applied when installing to CMAKE_INSTALL_<dir>. See
https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html#special-cases
2020-06-10 18:13:47 +00:00
Ralf Habacker
d5fd3d76f7 cmake: fix installation of example files 2020-06-10 18:13:47 +00:00
Simon McVittie
eeef787418 Normalize C source files to end with exactly one newline
Some editors automatically remove trailing blank lines, or
automatically add a trailing newline to avoid having a trailing
non-blank line that is not terminated by a newline. To avoid unrelated
whitespace changes when users of such editors contribute to dbus,
let's pre-emptively normalize all files.

Unlike more intrusive whitespace normalization like removing trailing
whitespace from each line, this seems unlikely to cause significant
issues with cherry-picking changes to stable branches.

Implemented by:

    find . -name '*.[ch]' -print0 | \
    xargs -0 perl -0777 -p -i -e 's/\n+\z//g; s/\z/\n/g'

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-06-10 10:47:31 +00:00
Taras Zaporozhets
73139d57bb Fix indentation in bus source file 2020-03-25 13:22:38 +01:00
Simon McVittie
b034b83b59 bus: Don't explicitly clear BusConnections.monitors
Each connection that is an active monitor holds a pointer to its own
link in this list, via BusConnectionData.link_in_monitors. We can't
validly free the list while these pointers exist: that would be a
use-after-free, when each connection gets disconnected and tries to
remove itself from the list.

Instead, let each connection remove itself from the list, then assert
that the list has become empty.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/291
2020-02-20 12:43:34 +00:00
Ralf Habacker
2d256d42ce cmake: complete adding version info to all installed executables on Windows 2020-02-19 10:23:01 +01:00
Laurent Bigonville
6072f8b241 Stop using selinux_set_mapping() function
Currently, if the "dbus" security class or the associated AV doesn't
exist, dbus-daemon fails to initialize and exits immediately. Also the
security classes or access vector cannot be reordered in the policy.
This can be a problem for people developing their own policy or trying
to access a machine where, for some reasons, there is not policy defined
at all.

The code here copy the behaviour of the selinux_check_access() function.
We cannot use this function here as it doesn't allow us to define the
AVC entry reference.

See the discussion at https://marc.info/?l=selinux&m=152163374332372&w=2

Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/198
2019-10-22 19:12:13 +02:00
Simon McVittie
1b1c5ddd35 bus: Make audit initialization idempotent
The audit module is initialized every time a new BusContext is created,
which is only once in the real dbus-daemon, but can happen several times
in some unit tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:11:23 +01:00
Simon McVittie
3b2217821b bus: Clarify names of methods that query owned names
It wasn't immediately clear from the names of these method whether they
should return TRUE or FALSE for queued owners other than the primary
owner. Renaming them makes it obvious that the answer should be TRUE.

While I'm there, make the corresponding _dbus_verbose() messages more
precise.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/270
2019-05-30 15:59:10 +01:00
Simon McVittie
463ecfb4fd Merge branch 'send_destination_prefix' into 'master'
Send destination prefix

See merge request dbus/dbus!85
2019-05-30 14:49:09 +00:00
Simon McVittie
6884f63e0e Merge branch 'unix-gids' into 'master'
Add UnixGroupIDs to connection credentials

See merge request dbus/dbus!105

Fixes: dbus/dbus#196
2019-05-13 11:32:24 +00:00
Adrian Szyndela
055ff9e64a dbus-daemon: add send_destination_prefix support
This extends dbus-daemon with support for send_destination_prefix
attribute in XML policies.

It allows having policy rules for sending to bus names generated
within namespaces defined by a prefix. The similar behaviour can be
emulated by owning an additional name, not used for addressing messages,
as described in
https://lists.freedesktop.org/archives/dbus/2017-May/017188.html
However, introducing send_destination_prefix creates possibility
of communicating intentions in a more direct way, which is easier
to understand.

Signed-off-by: Adrian Szyndela <adrian.s@samsung.com>
Change-Id: I0016ad93f1c16b7742fef5f45ebaf01b55694d3c
2019-04-26 13:29:42 +02:00
Adrian Szyndela
3486e0f48d DBusString: extend with checking for starting with words
This extracts a few lines of code and adds it as a DBusString function
that checks if a DBusString starts with words given with a C string
and a word separator. In other words, it checks if:
- a DBusString is a given C string, or
- a DBusString starts with a given C string and the next character is
  a given word separator.

It is used for matching names to prefixes when checking the policy.

Signed-off-by: Adrian Szyndela <adrian.s@samsung.com>
Change-Id: Ie39d33916863d950dde38d3b8b20c8a539217302
2019-04-26 13:29:42 +02:00
Simon McVittie
7eacbfece7 bus: Try to raise soft fd limit to match hard limit
Linux systems have traditionally set the soft limit to 1024 and the hard
limit to 4096. Recent versions of systemd keep the soft fd limit at
1024 to avoid breaking programs that still use select(), but raise the
hard limit to 512*1024, while in recent Debian versions a complicated
interaction between components gives a soft limit of 1024 and a hard
limit of 1024*1024. If we can, we might as well elevate our soft limit
to match the hard limit, minimizing the chance that we will run out of
file descriptor slots.

Unlike the previous code to raise the hard and soft limits to at least
65536, we do this even if we don't have privileges: privileges are
unnecessary to raise the soft limit up to the hard limit.

If we *do* have privileges, we also continue to raise the hard and soft
limits to at least 65536 if they weren't already that high, making
it harder to carry out a denial of service attack on the system bus on
systems that use the traditional limit (CVE-2014-7824).

As was previously the case on the system bus, we'll drop the limits back
to our initial limits before we execute a subprocess for traditional
(non-systemd) activation, if enabled.

systemd activation doesn't involve us starting subprocesses at all,
so in both cases activated services will still inherit the same limits
they did previously.

Reviewed-by: Lennart Poettering <lennart@poettering.net>
[smcv: Correct a comment based on Lennart's review, reword commit message]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-04-18 11:54:48 +01:00
Simon McVittie
9e0fd2fbbf bus_driver_credentials_fill_unix_gids: Comment on a non-error
As described in the spec, we want GetConnectionCredentials() to report
less information, successfully, if it sees a group ID that it can't
represent.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-04-17 14:22:15 +01:00
Matthijs van Duin
afafd2fad0 Add UnixGroupIDs to connection credentials
Signed-off-by: Matthijs van Duin <matthijsvanduin@gmail.com>
2019-03-25 23:01:26 +01:00
Topi Miettinen
94b5b236aa
Configure option to disable traditional activation
Traditional activation could be disabled if all services use
SystemdService activation instead. Provide an example of a hardened
DBus systemd service drop-in file for such a setup.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
2019-03-25 21:51:33 +02:00
Ralf Habacker
9dc72c9fb8 cmake: install missing files to keep in sync with autotools builds 2019-03-13 08:56:59 +01:00
Ralf Habacker
6332f7d4b1 Fixes remaining indentations that are not covered by the cmake formatting script in CMakeLists.txt files 2019-01-24 09:08:15 +01:00
Ralf Habacker
904fa97a1b Remove obsolete parameter in end... cmake keywords 2019-01-24 09:07:27 +01:00
Ralf Habacker
5972bbe382 Remove spaces between cmake command and opening bracket 2019-01-24 09:07:27 +01:00
Ralf Habacker
3927b1dd39 Use lower case cmake keywords in CMakeLists.txt files 2019-01-24 09:07:27 +01:00
Ralf Habacker
7dd83ba874 Replace tabs by 4 spaces in CMakeLists.txt files 2019-01-24 09:07:27 +01:00
Ralf Habacker
38b7c2859e Remove trailing spaces in CMakeLists.txt files 2019-01-24 09:07:27 +01:00
Simon McVittie
6d8280ec93 Merge branch 'code-coverage' into 'master'
Adapt to API change in AX_CODE_COVERAGE version 28

Closes #249

See merge request dbus/dbus!88

Reviewed-by: @pwithnall
2019-01-23 20:45:32 +00:00
Ralf Habacker
a8e5e5c552 Add cmake macros add_executable_version_info and add_library_version_info
This helps to reduce duplicated code.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2019-01-22 09:58:27 +01:00
Ralf Habacker
3bf97922bd Move cmake related build system to top level
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2019-01-22 09:57:40 +01:00
Simon McVittie
2938c2125e Adapt to API change in AX_CODE_COVERAGE version 28
AX_CODE_COVERAGE recently changed the way it embedded its Makefile rules
in the output file: instead of using @CODE_COVERAGE_RULES@, users
are now meant to include aminclude_static.am.

The new AX_CODE_COVERAGE is only in the latest autoconf-archive release,
version 2019.01.06, which is inconveniently new, so bundle everything
we need for the moment.

This requires us to stop using the deprecated CODE_COVERAGE_LDFLAGS
(which we still used to support older versions of autoconf-archive)
and replace them with CODE_COVERAGE_LIBS.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 18:43:08 +00:00
Simon McVittie
e23bba929a test: Move dbus-daemon-launch-helper-test here, and rename
The -test suffix does not indicate that this is a test, but rather that
it is for tests (similar to the -unix and -win suffixes on modules like
dbus-sysdeps). This seems unnecessarily confusing, so rename it to end
with -for-tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:18:46 +00:00
Simon McVittie
a15839da9b test: Move dbus-daemon and d-d-launch-helper tests from bus/
This groups them with the other tests, and avoids having them influence
the test coverage stats in bus/.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:16:51 +00:00
Simon McVittie
2732038528 bus tests: Collect possible copyright holders from git history
This is in preparation to move some of this code into the test/
directory. I've ignored changes that appear to be trivial.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:15:21 +00:00
Simon McVittie
d7644b7d4f build: Compile most bus/ files into static libraries
This means we can share them between tests without having to compile
the same file repeatedly, and makes them easier to share between
directories when we move test executables into test/.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:14:29 +00:00
Simon McVittie
88032367a9 dbus-spawn: Don't take ownership of envp
It's unexpected for a function to take ownership of its arguments
without indicating that in its name, or at least documenting it.

The only caller with envp != NULL is in
bus_activation_activate_service(), which has been updated.

Based on part of a larger commit by Ralf Habacker.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-05 11:41:58 +01:00
Simon McVittie
295e5a19a7 tests: Collect common code from embedded-test main executables
This all seems to have been written by Red Hat or by Collabora, so we
have permission to relicense it under the MIT/X11 license, and we
might as well do so.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-17 14:12:59 +00:00
Simon McVittie
9c4f9206c4 bus tests: Skip unsupported fd-passing test internally, not from main()
This results in one less special case in test-main, which will be
significant when we want to make the tests more data-driven.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-17 14:12:59 +00:00
Simon McVittie
4587be1442 embedded tests: Time how long each test takes
This will help to split them up into modules that each take a
reasonable time.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-17 14:12:59 +00:00
Simon McVittie
0315809596 embedded tests: Conform to the same API for all tests
This will make it possible to unify the wrapper code that runs them.

I'm using a plain C string rather than a DBusString to make it
more straightforward to carve out tests into their own executables.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-17 14:12:59 +00:00
Simon McVittie
39ea37b587 trivial: Remove trailing whitespace from copyright notices
We don't usually mass-remove trailing whitespace from the actual source
code because it would complicate cherry-picking bug fixes to older
branches, but that reasoning doesn't really apply to the comments
containing copyright and licensing notices.

Removing trailing whitespace makes it much easier to move code around:
we have a commit hook that rejects commits containing trailing
whitespace, but that commit hook counts moving a file as a delete + add
pair, so it objects to moving code that contains trailing whitespace.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-17 11:22:39 +00:00
Simon McVittie
83034f38be _dbus_threads_init_debug: Remove
libdbus has been thread-safe by default since 1.7.6 (2013):
dbus_threads_init_default() is called on a just-in-time basis
whenever needed, and _dbus_thread_init_debug() is equivalent to that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 20:06:02 +00:00
Simon McVittie
fa63c16346 .gitignore: Ignore many more generated files
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 13:28:50 +00:00