Commit graph

112 commits

Author SHA1 Message Date
Simon McVittie
ade23fe461 config-parser: Eliminate duplicate functionality
We had two ways to append a path to the list of service directories.
Collapse them into one.

Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2017-02-17 12:16:32 +00: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
36930b224b Remove unused functions from Windows builds
Several internal functions are not used on Windows. This patch
hides them behind DBUS_WIN.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
Reviewed-by: Simon McVittie <smcv@debian.org>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
2016-10-10 15:09:38 +01:00
Simon McVittie
f1cd229f83 Remove trailing newlines from _dbus_warn, _dbus_warn_check_failed
They used to be needed, but are not needed any more, and we were
never completely consistent about including them in any case.

Signed-off-by: Simon McVittie <smcv@debian.org>
2016-09-30 19:36:51 +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
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
9d89710c1f config-parser: remove unnecessary newline from _dbus_log()
_dbus_log() already adds a newline.

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
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
a89e450181 Merge branch 'dbus-1.10' 2015-11-06 12:12:55 +01:00
Ralf Habacker
34d0c73f99 Test system bus config files on Unix only
Previously, we didn't consistently test parsing of every file in
valid-config-files-system/ everywhere that we tested valid-config-files/.
We now test it on Unix.

The system bus is not supported on Windows, so we do not test
valid-config-files-system/ there.

valid-config-files/many-rules.conf contains <user> and <group> rules
which are not applicable to Windows. Copy the original many-rules.conf
to valid-config-files-system/ so that it will be tested on Unix, and
remove the non-portable rules from valid-config-files/many-rules.conf.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
[rh:base patch came from Simon]
2015-11-03 14:22:30 +01:00
Simon McVittie
2f1a715e7f test_default_session_servicedirs: use the intended data directory
If D-Bus was configured for /usr/local and built in Z:/build,
the previous code would use

    Z:/build/dbus/.libs/usr/local/share/dbus-1/services

whereas the intention was to replace the configured prefix /usr/local
with the detected location, more like

    Z:/build/dbus/.libs/share/dbus-1/services

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-11-02 23:24:11 +01:00
Simon McVittie
50b07fbb01 test_default_session_servicedirs: simplify to a single exit code-path
A similar simplification was already done on master as part of commit
f830e14, Bug #83539.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-11-02 23:22:42 +01:00
Ralf Habacker
b0286eed76 Wrap path verbose output with '' to be able to see trailing spaces.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92721
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-11-02 13:19:22 +01:00
Simon McVittie
f5e5894a47 Assume that DBUS_DATADIR is absolute on Windows
Both build systems arrange for this to be the case,
and we already assume that it's absolute on Unix.
On Windows, it's probably going to be /mingw/share or
something; it gets relocated via _dbus_replace_install_prefix()
at runtime.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83539
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-10-05 16:29:54 +01:00
Simon McVittie
9b8f844e10 Replace build-time prefix with installation prefix when including config files
This was already done for the contents of .service files, but not
config files.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92028
Tested-by: Ralf Habacker <ralf.habacker@freenet.de>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-10-05 16:29:44 +01:00
Simon McVittie
f830e14d30 Use DBusString for all relocation and install-root code
This means we handle OOM correctly, and makes it obvious
that we are not overflowing buffers. This change does not
affect the actual content of the strings.

Instead of redefining DBUS_DATADIR to be a function call
(which hides the fact that DBUS_DATADIR is used),
this patch makes each use explicit: DBUS_DATADIR
is always the #define from configure or cmake, before
replacing the prefix.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=83539
Tested-by: Ralf Habacker <ralf.habacker@freenet.de>
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2015-10-05 16:29:29 +01:00
Ralf Habacker
26a3c0dc5b include_dir: skip processing on error (CID 54744)
We already skipped processing for DBUS_ERROR_FILE_NOT_FOUND;
but if the error was something else, we would pass the NULL
pointer dir to _dbus_directory_get_next_file(), which dereferences it.
Reported by Coverity: CID 54744: Dereference after null check (FORWARD_NULL)

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90021
[smcv: re-worded commit message]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-04-16 13:15:19 +01:00
Dimitri John Ledkov
57971f69ef Make include_dir non-existing directory, to not be an error.
Empty include directories were already not treated as failures.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89280
Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-25 15:59:24 +00:00
Tyler Hicks
06033cb20f Add apparmor element support to bus config parsing
The <apparmor> element can contain a single mode attribute that has one
of three values:

 "enabled"
 "disabled"
 "required"

"enabled" means that kernel support is autodetected and, if available,
AppArmor mediation occurs in dbus-daemon. If kernel support is not
detected, mediation is disabled. "disabled" means that mediation does
not occur. "required" means that kernel support must be detected for
dbus-daemon to start.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=75113
Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2015-02-18 17:04:00 +00:00
Simon McVittie
02e1ddf91e Revert "config: change default auth_timeout to 5 seconds"
This reverts commit 54d26df52b.

It appears this change may cause intermittent slow or failed boot,
more commonly on slower/older machines, in at least Mageia and
possibly also Debian. This would indicate that while the system
is under load, system services are not completing authentication
within 5 seconds.

This change was not the main part of fixing CVE-2014-3639, but does
help to mitigate that attack. As such, increasing this timeout makes
the denial of service attack described by CVE-2014-3639 somewhat
more effective: a local user connecting to the system bus repeatedly
from many parallel processes can cause other users' attempts to
connect to take longer.

If your machine boots reliably with the shorter timeout, and
resilience against local denial of service attacks is important
to you, putting this in /etc/dbus-1/system-local.conf
or a file matching /etc/dbus-1/system.d/*.conf can restore
the lower limit:

    <busconfig>
      <limit name="auth_timeout">5000</limit>
    </busconfig>

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=86431
2014-11-22 10:49:21 +00:00
Alban Crequy
bbf11cd5f9 config: add new limit: pending_fd_timeout
This is one of four commits needed to address CVE-2014-3637.

When a file descriptor is passed to dbus-daemon, the associated D-Bus message
might not be fully sent to dbus-daemon yet. Dbus-daemon keeps the file
descriptor in the DBusMessageLoader of the connection, waiting for the rest of
the message. If the client stops sending the remaining bytes, dbus-daemon will
wait forever and keep that file descriptor.

This patch adds pending_fd_timeout (milliseconds) in the configuration to
disconnect a connection after a timeout when a file descriptor was sent but not
the remaining message.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80559
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:29:30 +01:00
Alban Crequy
54d26df52b config: change default auth_timeout to 5 seconds
This partially addresses CVE-2014-3639.

This will change the default on the system bus where the limit
  <limit name="auth_timeout">...</limit>
is not specified.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=80919
Reviewed-by: Thiago Macieira <thiago@kde.org>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:28:10 +01:00
Alban Crequy
5bc7f9519e system bus limit: use max_replies_per_connection=128 by default
This addresses CVE-2014-3638.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=81053
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-09-15 12:27:20 +01:00
Matt Hoosier
fc3bf2f304 Don't forget allow_anonymous when merging configs
The algorithm to collapse a subsidiary config file's data into the
master data structure forgot to examine this flag.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73475
Reviewed-by: Chengwei Yang <chengwei.yang@intel.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2014-01-14 11:04:18 +00:00
Simon McVittie
412538b3b9 Export dbus_setenv() as a utility function
It's sufficiently portable that GLib has an equivalent, and I really
don't want to have to either open-code it in dbus-run-session or
link dbus-run-session statically. We have enough statically-linked
rubbish already.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39196
Reviewed-by: Colin Walters <walters@verbum.org>
2013-08-23 11:40:50 +01:00
Chengwei Yang
db2757f812 tests to embedded tests: replaced in dbus-daemon
Signed-off-by: Chengwei Yang <chengwei.yang@intel.com>
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=66291
2013-06-28 12:13:28 +01:00
Matt Fischer
977293549d Set default maximum number of Unix fds according to OS
QNX has an arbitrary limit to the number of file descriptors
which may be passed in a message, which is smaller than the
current default.  This patch therefore changes the default from
a hardcoded constant to a macro, which is determined at configure
time by looking at the host operating system.

[This reduces the limit from 4096 (session)/1024 (system) to 128 fds
per message on QNX, and 1024 fds per message on other operating systems.
I think the reduced session bus limit on other OSs is a reasonable change
too, given that the default hard/soft ulimits in Linux are only 4096/1024
fds per process. -smcv]

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61176
Reviewed-by: Simon McVittie <simon.mcvittie.collabora.co.uk>
2013-04-11 13:34:55 +01:00
Krzysztof Konopko
161b7d7007 Merge <servicehelper> from included config file
<servicehelper> is not supported in the included config file, i. e. it's
not merged in merge_included().  There's clearly no reason it shouldn't
be supported in the included config file along with <user>, <type>
and others.  It's quite reasonable for a client willing to override the
default servicehelper, e. g. in system-local.conf.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=51560
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2013-02-12 10:49:29 +00:00
Alban Crequy
f1cfc138ef test: enforce own_prefix policy rules
After parsing [allow|deny] rules with own_prefix, check they are enforced
correctly.

https://bugs.freedesktop.org/show_bug.cgi?id=46886
2012-03-22 11:51:23 +00:00
Alban Crequy
5670dc6cf7 config parser: add own_prefix
https://bugs.freedesktop.org/show_bug.cgi?id=46882
2012-03-04 14:36:56 +00:00
Simon McVittie
fccb5a0fe1 Explicitly don't search XDG_DATA_DIRS for system services, and document it
In practice, it never works, because the activation helper doesn't
respect environment variables for security reasons.
If you want to vary the search path, alter system.conf instead, to
replace or augment <standard_system_servicedirs/> with your preferred
search path.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=21620
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2012-02-08 16:11:35 +00:00
Simon McVittie
222b7d9f97 config-parser: don't try to get CommonProgramFiles from the environment on Unix
It's unused on Unix, and gcc warns.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39231
Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
2011-08-05 12:27:04 +01:00
Lennart Poettering
d837d937c5 activation: add /lib/dbus-1/system-services to the search path for services
In order to allow D-Bus usage during early boot (where /usr is not
accessible) also search for bus activation files in
/lib/dbus-1/system-services/. This is only a first step in the right
direction, before we really can boot without /usr we'd need to move all
current activation files (or possibly replace
/usr/dbus-1/system-services to a symlink to
/lib/dbus-1/system-services).
2011-07-28 21:22:07 +02:00
Simon McVittie
75cecfc374 Break up the monster conditional in config-parser so gcov can cope
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=10887
Reviewed-by: Colin Walters <walters@verbum.org>
2011-04-07 11:25:54 +01:00
Andre Heinecke
e0fc90bdf2 Do not use the name ELEMENT_TYPE
On Windows Systems ELEMENT_TYPE is already defined
in Winioctl.h this header is included indirectly
in dbus-sysdeps.h. By avoiding the use of the Name
ELEMENT_TYPE it is ensured that config-parser-common.h
can be included together with dbus-sysdeps.h

Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2011-03-07 13:50:38 +00:00
Simon McVittie
7848abe6c2 config-parser regression test: don't require that fd.o #34496 exists
Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
2011-02-24 18:40:11 +00:00
Simon McVittie
7480dfdb2a If a file included via <includedir/> is invalid, syslog and skip it
This is more graceful than failing entirely (our previous behaviour),
but more visible than ignoring it completely (the previous behaviour
patched in by Debian and derivatives).

Based on a patch from Daniel Silverstone back in 2004, which was meant
to be temporary; I think it makes sense to change this permanently,
since files in *.d are typically supplied by other packages, whose bugs
shouldn't be able to bring down dbus-daemon.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=19186
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=230231
Reviewed-by: Colin Walters <walters@verbum.org>
2011-01-31 19:16:00 +00:00
Ralf Habacker
02d973686a Use absolute session service dir path in bus-test on windows. 2010-12-29 14:43:24 +01:00
Marcus Brinkmann
dbecdeabb2 Consistently include <config.h> in all C source files and never in header files. 2010-03-19 20:11:48 +01:00
Ralf Habacker
73b926275f uses tcp based test connections for now 2009-12-01 11:17:40 +01:00
Thiago Macieira
37019e9d27 Merge branch 'fd-passing'
Conflicts:
	dbus/dbus-connection.c
	dbus/dbus-message-util.c
	dbus/dbus-sysdeps-unix.c
2009-07-16 16:05:16 +02:00
Tobias Mueller
5baf2f856a Bug 21161 - Update the FSF address
No comment.

Signed-off-by: Colin Walters <walters@verbum.org>
2009-07-10 19:32:38 -04:00
Scott James Remnant
8f1d2a2fa8 Change default reply timeout.
* bus/config-parser.c (bus_config_parser_new): change the default reply
  timeout to "never"

Signed-off-by: Scott James Remnant <scott@ubuntu.com>
2009-05-28 11:47:36 +02:00
Lennart Poettering
64ad844967 bus: make use of new unix fd limits
Create configuration settings and enforce message unix fd limits the
same way we do for allocated message memory.
2009-05-20 02:10:17 +02:00
Thiago Macieira
63196f69c4 Merge branch 'dbus-1.2'
Conflicts:
	bus/bus.c
	bus/config-parser-common.c
	bus/config-parser-common.h
	bus/config-parser.c
	bus/connection.c
	bus/dbus-daemon.1.in
	dbus/dbus-marshal-validate-util.c
	dbus/dbus-marshal-validate.c
	dbus/dbus-sysdeps-util-unix.c
	test/name-test/tmp-session-like-system.conf
2009-04-28 15:16:36 +02:00
Matt McCutchen
6663d1dd35 Bug 18446: Keep umask for session bus
Signed-off-by: Colin Walters <walters@verbum.org>
2009-01-06 18:20:13 -05:00
Colin Walters
427ff01f9d Add optional logging on allow rules
This lets us have a backwards compatibility allow rule but still easily
see when that rule is being used.
2008-12-16 12:20:43 -05:00
Colin Walters
6053d2208e Add optional logging on allow rules
This lets us have a backwards compatibility allow rule but still easily
see when that rule is being used.
2008-12-16 11:57:27 -05:00
Colin Walters
69ed32cbcc Add syslog of security denials and configuration file reloads
We need to start logging denials so that they become more easily trackable
and debuggable.
2008-12-12 15:18:12 -05:00
Colin Walters
bb2a464067 Add syslog of security denials and configuration file reloads
We need to start logging denials so that they become more easily trackable
and debuggable.
2008-12-12 14:00:16 -05:00