Commit graph

944 commits

Author SHA1 Message Date
Simon McVittie
ca2cdab866 activation test: don't crash if AppArmor is built but unavailable
Also don't try to clean up a process we didn't start.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98666
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2016-11-29 12:32:40 +00:00
Simon McVittie
6dd92fd825 Don't test AppArmor mediation of activation if libapparmor < 2.10
We need libapparmor 2.10 for the test, but not for the actual
functionality, for which 2.8.95 is enough. In particular this lets
us compile with AppArmor enabled on Ubuntu 14.04, which is still
the newest host platform available on travis-ci.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98666
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
2016-11-29 12:31:52 +00:00
Simon McVittie
025c5dc5d5 Activation test: exercise what happens with nonexistent AppArmor labels
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98666
2016-11-28 12:11:56 +00:00
Simon McVittie
80654389f8 Add an integration test for AppArmor mediating activation
This requires libapparmor 2.10, for aa_features_new_from_kernel()
and related functions.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98666
2016-11-28 12:11:52 +00:00
Simon McVittie
373cc47c7c Do not auto-activate services if we could not send a message
We specifically do not check recipient policies, because
the recipient policy is based on properties of the
recipient process (in particular, its uid), which we do
not necessarily know until we have already started it.

In this initial implementation we do not check LSMs either,
because we cannot know what LSM context the recipient process
is going to have. However, LSM support will need to be added
to make this feature useful, because StartServiceByName is
normally allowed in non-LSM environments, and is more
powerful than auto-activation anyway.

The StartServiceByName method does not go through this check,
because if access to that method has been granted, then
it's somewhat obvious that you can start arbitrary services.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98666
2016-11-28 12:11:41 +00:00
Simon McVittie
5503511f91 Add tests for activation when message send/receive is denied
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98666
2016-11-28 12:11:32 +00:00
Simon McVittie
f745d59bc1 Merge branch 'dbus-1.10' 2016-11-22 20:08:22 +00:00
Simon McVittie
5a1dcca8bf Don't test X11 autolaunching if it was disabled at compile time
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98665
2016-11-22 19:27:43 +00:00
Simon McVittie
d5fae1db78 Make uid 0 immune to pending_fd_timeout limit
This is a workaround for
<https://bugs.freedesktop.org/show_bug.cgi?id=95263>. If a service
sends a file descriptor sufficiently frequently that its queue of
messages never goes down to 0 fds pending, then it will eventually be
disconnected. logind is one such service.

We do not currently have a good solution for this: the proposed
patches either don't work, or reintroduce a denial of service
security vulnerability (CVE-2014-3637). Neither seems desirable.
However, we can avoid the worst symptoms by trusting uid 0 not to be
malicious.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95263
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1591411
Reviewed-by:  Łukasz Zemczak
Tested-by: Ivan Kozik
Tested-by: Finn Herpich
Tested-by: autostatic
Tested-by: Ben Parafina
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-11-11 16:40:44 +00:00
Simon McVittie
259d2bcf59 Add more _DBUS_GNUC_PRINTF annotations
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98658
2016-11-10 11:46:33 +00:00
Simon McVittie
7959d90719 Add missing function attributes suggested by clang (but not by gcc)
clang is a little more enthusiastic about suggesting these.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-10-13 22:44:13 +01:00
Simon McVittie
35cdfc5e76 test-segfault: mark exception_handler as NORETURN
It calls ExitProcess(), which is correctly detected as not returning.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-10-13 22:44:13 +01:00
Simon McVittie
28eb0f9004 test-privserver: avoid -Wformat-security
This is not a security vulnerability because it's test code that
should never be compiled in production.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-10-13 22:44:13 +01:00
Simon McVittie
b6caf69d46 Fix remaining -Wundef warnings
Vaguely based on a patch from Thomas Zimmermann, but with a different
solution to RECURSIVE_MARSHAL_WRITE_TRACE, and additionally fixing
a build failure that only occurs when targeting Unix without libsystemd,
and another that occurs when targeting Windows.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
2016-10-13 17:20:38 +01:00
Simon McVittie
8db5ca900f Be more const-correct
As a general design principle, strings that we aren't going to modify
should usually be const. When compiling with -Wwrite-strings, quoted
string constants are of type "const char *", causing compiler warnings
when they are assigned to char * variables.

Unfortunately, we need to add casts in a few places:

* _dbus_list_append(), _dbus_test_oom_handling() and similar generic
  "user-data" APIs take a void *, not a const void *, so we have
  to cast
* For historical reasons the execve() family of functions take a
  (char * const *), i.e. a constant pointer to an array of mutable
  strings, so again we have to cast
* _dbus_spawn_async_with_babysitter similarly takes a char **,
  although we can make it a little more const-correct by making it
  take (char * const *) like execve() does

This also incorporates a subsequent patch by Thomas Zimmermann to
put various string constants in static storage, which is a little
more efficient.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
2016-10-13 17:20:28 +01:00
Thomas Zimmermann
d0be2333d5 Fix warnings from compiler option '-Wshadow'
Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98192
2016-10-10 18:04:09 +01:00
Thomas Zimmermann
45d68fe384 Fix function declarations
This patch adds 'void' to function declarations without parameters.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
[smcv: fix coding style while we're touching these lines anyway]
Reviewed-by: Simon McVittie <smcv@debian.org>
2016-10-10 15:09:28 +01:00
Simon McVittie
814560d56a Only redirect child processes to systemd Journal if using syslog
In particular this means the test suite won't spam the Journal
any more.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
2016-09-30 19:36:50 +01:00
Simon McVittie
2c472b8398 syslog test: extend assertions to cover new functionality
Signed-off-by: Simon McVittie <smcv@debian.org>
2016-09-30 19:36:50 +01:00
Simon McVittie
92bd5ef290 _dbus_logv: configurably log to syslog and/or stderr
This changes the behaviour of _dbus_logv() if _dbus_init_system_log() was
not called. Previously, _dbus_logv() would always log to syslog;
additionally, it would log to stderr, unless the process is dbus-daemon
and it was started by systemd. Now, it will log to stderr only,
unless _dbus_init_system_log() was called first.

This is the desired behaviour because when we hook up
_dbus_warn_check_failed() to _dbus_logv() in the next commit, we don't
want typical users of libdbus to start logging their check failures to
syslog - we only want the dbus-daemon to do that.

In practice this is not usually a behaviour change, because there was
only one situation in which we called _dbus_logv() without first calling
_dbus_init_system_log(), namely an error while parsing configuration
files. Initialize the system log "just in time" in that situation
to preserve existing behaviour.

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-09-30 19:36:50 +01:00
Simon McVittie
a363822f5f dbus-daemon test: exercise pending fd timeout test
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-16 18:27:43 +01:00
Simon McVittie
3bc74092ca dbus-daemon test: exercise max_names_per_connection limit
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86442
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-16 17:44:30 +01:00
Simon McVittie
951fd317ca dbus-daemon test: exercise maximum match rules per connection
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86442
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-16 17:44:30 +01:00
Simon McVittie
5cfd755f5d dbus-daemon test: exercise maximum replies per connection
This time we're doing so deliberately.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86442
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-16 17:44:30 +01:00
Simon McVittie
78b40bbde8 dbus-daemon test: avoid reaching pending reply limit
We were not actually doing what was intended (flooding the bus with
10k or 100k messages for the other side) because the bus was limiting
the sender to 128 parallel method calls.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86442
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-16 17:44:30 +01:00
Simon McVittie
de0cf5a070 dbus-daemon test: exercise maximum connection counts
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86442
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-16 17:44:30 +01:00
Simon McVittie
73b03e0bfb name-test, tools: add missing COVERAGE_CFLAGS
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-08-15 15:17:31 +01:00
Thomas Zimmermann
be04ba8354 Use AX_CODE_COVERAGE for test-coverage statistics
DBus uses custom rules in its Makefiles to implement test-coverage
statistics.

This patch implements test-coverage statistics with the autoconf macro
AX_CODE_COVERAGE. The script automatically tests for tools (e.g., gcov,
lcov), sets build variables and creates Makefile rules.

Run 'configure' with '--enable-code-coverage' to enable support for
test-coverage statistics. Run 'make check-code-coverage' to run the
tests and generate the statistics.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
[smcv: do not alter compiler.m4; move AM_CXXFLAGS to the one place we
compile C++]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88922
2016-08-15 14:30:51 +01:00
Simon McVittie
c56cc26164 Add a regression test for dbus-launch in X11
[Modified for the dbus-1.10 branch: DBUS_USE_TEST_BINARY is needed.]

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 18:21:36 +01:00
Simon McVittie
6ce19c8625 test-dbus-daemon-fork: exercise closed stdin, stdout, stderr
Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 18:21:36 +01:00
Simon McVittie
1679f58a14 test: expand dbus-launch-eval test to cover stdin being closed
Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 18:21:36 +01:00
Simon McVittie
a7caca9f47 Add a simple test for dbus-daemon --fork
[Modified for the dbus-1.10 branch: DBUS_USE_TEST_BINARY is needed.]

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 18:21:32 +01:00
Simon McVittie
042391e88a test: add a regression test for eval "$(dbus-launch --sh-syntax)"
[Modified for the dbus-1.10 branch: DBUS_USE_TEST_BINARY is needed.]

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 18:21:01 +01:00
Simon McVittie
67f2fed1fd test-dbus-launch-x11: extend to cover --exit-with-x11
Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 18:13:47 +01:00
Simon McVittie
01ffa21501 Add a regression test for dbus-launch in X11
Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008
2016-08-12 18:13:21 +01:00
Simon McVittie
53fe3b44af test-dbus-daemon-fork: exercise closed stdin, stdout, stderr
Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008
2016-08-12 18:13:13 +01:00
Simon McVittie
4710c60bbf Add a simple test for dbus-daemon --fork
Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Colin Walters
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008
2016-08-12 18:12:46 +01:00
Simon McVittie
0e0a032aa2 test: add a regression test for eval "$(dbus-launch --sh-syntax)"
Signed-off-by: Simon McVittie <smcv@debian.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97008
2016-08-12 18:12:41 +01:00
Simon McVittie
76ae52735e Remove trailing newlines from _dbus_assert_not_reached
This was never necessary: _dbus_assert_not_reached() always added one.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
2016-08-12 17:11:48 +01:00
Simon McVittie
6d8a198de9 various tests: produce better diagnostics on error
Same root cause as <https://bugs.freedesktop.org/show_bug.cgi?id=96653>:
we didn't check whether the message was in fact an error reply.

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-08-12 10:25:06 +01:00
Simon McVittie
d97d561a46 _dbus_system_log: rename to _dbus_log
This is a step towards making it write to either stderr or syslog
or both, as configured globally.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
2016-08-11 16:41:16 +01:00
Simon McVittie
8ef699dd20 _dbus_init_system_log: record a syslog tag (executable name)
Instead of hard-coding "dbus", report what the executable really is.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
2016-08-11 16:41:16 +01:00
Simon McVittie
e3d76634c3 test-bus: don't write to the syslog
We want to emulate the behaviour of the system bus, but we don't
really want to spam the system log with lots of test messages.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
2016-08-11 16:41:16 +01:00
Simon McVittie
b5bef9dc16 Merge branch 'dbus-1.10' into dbus-1.10-ci 2016-06-30 13:57:29 +01:00
Simon McVittie
e536ea93ec Merge branch 'dbus-1.10' 2016-06-30 13:56:44 +01:00
Руслан Ижбулатов
e0f26388f7 Use dbus_set_error_from_message() to check for an error
Do not rely on dbus_message_get_args() to turn an ERROR message
into DBusError.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=96653
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2016-06-30 13:52:44 +01:00
Simon McVittie
5602ef4bf2 Merge branch 'dbus-1.10' into dbus-1.10-ci 2016-05-18 18:14:16 +01:00
Simon McVittie
78362cfc62 test-segfault: add missing include of <stdio.h> on Windows
Needed for fprintf (stderr, ...).

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
(cherry picked from commit 07b7dcd717)
2016-05-18 18:13:48 +01:00
Simon McVittie
07b7dcd717 test-segfault: add missing include of <stdio.h> on Windows
Needed for fprintf (stderr, ...).

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2016-05-16 21:20:19 +02:00
Ralf Habacker
a050be5b6a Merge branch 'dbus-1.10' 2016-05-09 21:50:56 +02:00