Commit graph

6248 commits

Author SHA1 Message Date
Evgeny Vereshchagin
de9e130207 config-parser: no longer get past the last NULL passed to locate_attributes
Fixes: bc86794f23
Fixes:
```
==302818==ERROR: AddressSanitizer: stack-buffer-underflow on address 0x7ffd6ac253c0 at pc 0x000000534d0b bp 0x7ffd6ac24e10 sp 0x7ffd6ac24e08
READ of size 8 at 0x7ffd6ac253c0 thread T0
    #0 0x534d0a in locate_attributes /home/vagrant/dbus/build/../bus/config-parser.c:658:16
    #1 0x52ea3f in start_busconfig_child /home/vagrant/dbus/build/../bus/config-parser.c:1080:12
    #2 0x52cca4 in bus_config_parser_start_element /home/vagrant/dbus/build/../bus/config-parser.c:2039:14
    #3 0x52b82b in expat_StartElementHandler /home/vagrant/dbus/build/../bus/config-loader-expat.c:107:8
    #4 0x7f2179f2d2bd  (/lib64/libexpat.so.1+0xd2bd) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #5 0x7f2179f2aed3  (/lib64/libexpat.so.1+0xaed3) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #6 0x7f2179f2c9ec  (/lib64/libexpat.so.1+0xc9ec) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #7 0x7f2179f30a8e in XML_ParseBuffer (/lib64/libexpat.so.1+0x10a8e) (BuildId: 0165eed77c910f6ef2227d21afa9c5c5ed5849c2)
    #8 0x52b040 in bus_config_load /home/vagrant/dbus/build/../bus/config-loader-expat.c:259:9
    #9 0x523c8a in bus_context_new /home/vagrant/dbus/build/../bus/bus.c:828:12
    #10 0x521056 in main /home/vagrant/dbus/build/../bus/main.c:716:13
    #11 0x7f2179a2954f in __libc_start_call_main (/lib64/libc.so.6+0x2954f) (BuildId: 9c5863396a11aab52ae8918ae01a362cefa855fe)
    #12 0x7f2179a29608 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x29608) (BuildId: 9c5863396a11aab52ae8918ae01a362cefa855fe)
    #13 0x42a914 in _start (/home/vagrant/dbus/build/bus/dbus-daemon+0x42a914) (BuildId: df5369f85137975aff9bd398ae859706cc3c52ff)

Address 0x7ffd6ac253c0 is located in stack of thread T0 at offset 0 in frame
    #0 0x52cfaf in start_busconfig_child /home/vagrant/dbus/build/../bus/config-parser.c:733
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
(cherry picked from commit ae03bcdb11)
2022-10-11 14:35:22 +01:00
Simon McVittie
7a0f050a54 dbus-message: Report OOM as OOM, not InvalidArgs
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/420
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 3c0e63c10a)
2022-10-11 14:35:22 +01:00
Kai A. Hiller
37a65e0a36 dbus-connection: Test built-in filters 2022-10-11 14:29:52 +01:00
Kai A. Hiller
c4573311dd dbus-monitor: Disable automatic message filtering 2022-10-11 14:29:52 +01:00
Kai A. Hiller
caf532c3d0 dbus-connection: Add builtin_filters_enabled flag 2022-10-11 14:29:52 +01:00
Simon McVittie
2a546c1acb Post-release version bump
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 14:50:37 +01:00
Simon McVittie
8501a73dfe Prepare v1.14.4
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 11:02:41 +01:00
Simon McVittie
32e7655568 Update NEWS
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:42:05 +01:00
Simon McVittie
71dd3ad20c test: Parse a message with a byteswapped Unix fd index
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/417
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit bef693f442)
[backport to 1.14.x: discard Meson build system updates]
2022-10-05 10:41:03 +01:00
Simon McVittie
7a8f3c2af9 test: Add infrastructure to parse valid raw message blobs
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 7a2c13d21b)
[backport to 1.14.x: discard Meson build system updates]
2022-10-05 10:41:03 +01:00
Simon McVittie
3fb065b075 dbus-marshal-byteswap: Byte-swap Unix fd indexes if needed
When a D-Bus message includes attached file descriptors, the body of the
message contains unsigned 32-bit indexes pointing into an out-of-band
array of file descriptors. Some D-Bus APIs like GLib's GDBus refer to
these indexes as "handles" for the associated fds (not to be confused
with a Windows HANDLE, which is a kernel object).

The assertion message removed by this commit is arguably correct up to
a point: fd-passing is only reasonable on a local machine, and no known
operating system allows processes of differing endianness even on a
multi-endian ARM or PowerPC CPU, so it makes little sense for the sender
to specify a byte-order that differs from the byte-order of the recipient.

However, this doesn't account for the fact that a malicious sender
doesn't have to restrict itself to only doing things that make sense.
On a system with untrusted local users, a message sender could crash
the system dbus-daemon (a denial of service) by sending a message in
the opposite endianness that contains handles to file descriptors.

Before this commit, if assertions are enabled, attempting to byteswap
a fd index would cleanly crash the message recipient with an assertion
failure. If assertions are disabled, attempting to byteswap a fd index
would silently do nothing without advancing the pointer p, causing the
message's type and the pointer into its contents to go out of sync, which
can result in a subsequent crash (the crash demonstrated by fuzzing was
a use-after-free, but other failure modes might be possible).

In principle we could resolve this by rejecting wrong-endianness messages
from a local sender, but it's actually simpler and less code to treat
wrong-endianness messages as valid and byteswap them.

Thanks: Evgeny Vereshchagin
Fixes: ba7daa60 "unix-fd: add basic marshalling code for unix fds"
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/417
Resolves: CVE-2022-42012
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 236f16e444)
2022-10-05 10:41:03 +01:00
Simon McVittie
6b88e768d8 test: Add targeted tests for dbus/dbus#413, dbus/dbus#418
Unlike the message-internals test, these do not rely on extra debug
instrumentation in libdbus, and so can be used for "as-installed"
testing. (However, they do require GLib.)

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 3ef342410a)
2022-10-05 10:41:03 +01:00
Simon McVittie
bbf5ef008a test: Export G_TEST_BUILDDIR, G_TEST_SRCDIR
These environment variables are used by GLib's g_test_build_filename()
and related convenience functions, which make it easier for unit tests
to find data files in a way that works for both build-time tests and
"as-installed" tests. During "as-installed" testing, both variables
will normally be unset, and GLib uses the directory containing the
executable. In most cases that results in the right thing happening, and
this will also be true for dbus, since we install the test executables
in ${libexecdir}/installed-tests, helper executables in the same place,
and test data in ${libexecdir}/installed-tests/data.

Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 37e0125943)
[backport to 1.14.x: discard Meson build system updates]
2022-10-05 10:41:03 +01:00
Simon McVittie
c0bfcc0978 test/data: Add messages that reproduce dbus/dbus#413, dbus/dbus#418
In debug builds with "embedded tests" enabled, these will automatically
be used as input for the message-internals test.

Some of the messages themselves are output from a fuzzer, others are
simplifications to include only one reason for lack of validity per
message.

I've included an annotated hex-dump for each message here, but the dbus
test suite doesn't currently know how to convert hex to binary, so I've
also committed the corresponding binary. See the comment at the top of
each hex-dump for how to create the binary version (which requires the
xxd tool shipped with vim).

It would be nice for the dbus test suite to be able to convert the
annotated hex-dump to binary, either at build-time with a Python script
or at runtime by loading the text file and decoding the hex, but I don't
want to block on that for dbus/dbus#413 and dbus/dbus#418.

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit d633016f73)
[backport to 1.14.x: discard Meson build system updates]
2022-10-05 10:41:03 +01:00
Simon McVittie
b9e6a75230 dbus-marshal-validate: Validate length of arrays of fixed-length items
This fast-path previously did not check that the array was made up
of an integer number of items. This could lead to assertion failures
and out-of-bounds accesses during subsequent message processing (which
assumes that the message has already been validated), particularly after
the addition of _dbus_header_remove_unknown_fields(), which makes it
more likely that dbus-daemon will apply non-trivial edits to messages.

Thanks: Evgeny Vereshchagin
Fixes: e61f13cf "Bug 18064 - more efficient validation for fixed-size type arrays"
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Resolves: CVE-2022-42011
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 079bbf1618)
2022-10-05 10:41:03 +01:00
Simon McVittie
fd73d1ef1b test-syntax: Exercise correctly- and incorrectly-nested structs, dicts
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 67800ac5fe)
2022-10-05 10:41:03 +01:00
Simon McVittie
3e53a785de dbus-marshal-validate: Check brackets in signature nest correctly
In debug builds with assertions enabled, a signature with incorrectly
nested `()` and `{}`, for example `a{i(u}` or `(a{ii)}`, could result
in an assertion failure.

In production builds without assertions enabled, a signature with
incorrectly nested `()` and `{}` could potentially result in a crash
or incorrect message parsing, although we do not have a concrete example
of either of these failure modes.

Thanks: Evgeny Vereshchagin
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Resolves: CVE-2022-42010
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 9d07424e90)
2022-10-05 10:40:49 +01:00
Simon McVittie
1aa0d897c2 NEWS: Describe the behaviour change resulting from fixing dbus#416
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-02 15:04:29 +01:00
Simon McVittie
b5a09fb11c dbus-server-socket: Make unix:tmpdir equivalent to unix:dir
On Linux, there are two classes of AF_UNIX socket, which D-Bus refers
to as unix:path=... (portable to non-Linux systems) and unix:abstract=...
(not portable).

Back in 2003 when dbus gained support for abstract Unix sockets on Linux,
everyone thought they were better in every way than path-based Unix
sockets: if a DBusServer crashes or is terminated abnormally, there's
no detritus left in the filesystem. What's not to like? As a result,
since commit a70b042f (2003-06-04), when a DBusServer listens on a
unix:tmpdir=... address on Linux, the default is for the result to be
a unix:abstract=... address, with unix:path=... addresses only used on
non-Linux platforms.

However, the world has changed in the last 19 years, and namespace-based
Linux containers (which didn't exist in 2003) are now very popular. This
makes abstract sockets problematic.

Abstract sockets are tied to the network namespace, which is
all-or-nothing: if a container is to access the Internet without using
some sort of proxy or intermediary (like slirp4netns) then it needs to
share the network namespace with the host system, and that implies
sharing all abstract sockets with the host system. If the well-known
session bus is listening on an abstract socket, then it's a sandbox
escape route for any sandboxed or containerized app running under the
same uid. Conversely, if a container is *not* sharing the network
namespace with the host system, then it cannot access a session bus that
is listening on an abstract socket without using some sort of proxy
(like xdg-dbus-proxy), even if it isn't intended to impose a security
boundary and giving it direct access to the session bus would have been
more desirable.

Path-based sockets do not have this problem because they exist in the
filesystem (part of the "everything is a file" Unix philosophy),
allowing mount namespaces and bind-mounts to be used to share or
unshare them selectively.

On systems with `systemd --user` where dbus has been configured with
`--enable-user-session`, in general the session bus will already be
using a path-based socket for the "user bus", disregarding the listening
address specified in /usr/share/dbus-1/session.conf. The default in many
recent Linux distributions is either to use dbus-daemon in this way, or
to use dbus-broker, a reimplementation of the message bus service which
has similar "user bus" behaviour.

However, the <listen> address in session.conf is used when dbus-launch(1)
or dbus-run-session(1) is used to start a session bus, either manually,
via autolaunching, or via system integration glue in operating systems
that are not using `systemd --user`. This will occur particularly often
in operating systems that boot using a non-systemd init system.

Making unix:tmpdir=/tmp equivalent to unix:dir=/tmp ensures that the
well-known session bus listens on a path-based socket, allowing container
and sandboxing frameworks to mediate access to it in the same way they
would for the user bus. The D-Bus Specification already allows (but does
not require) this behaviour, because it is the only thing that was
implementable on non-Linux systems such as *BSD.

This change has the potential to cause regressions. If a container
framework enters a chroot or unshares the mount namespace but does not
unshare the network namespace, and is relying on the ability for a
process inside a container to access the session bus outside the
container via its abstract socket, then that assumption will be broken
by this change. Some use cases of schroot(1) are likely to suffer from
this. However, container frameworks with that assumption would already
have found that it does not hold when using the user bus, and it is
necessary to break that assumption if we want it to be possible to apply
application-level sandboxing in a secure way.

Another potential regression from this change is that if a dbus-daemon
is terminated abnormally, it will leave a socket in /tmp. Distributors
of operating systems where heavy use of dbus-launch(1) is expected might
wish to run dbus-cleanup-sockets(1) periodically.

This partially reverts commit a70b042f.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/416
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit f01382ae31)
[backport to 1.14.x: adjust to absence of d98c98d1 in this branch]
2022-10-02 15:00:56 +01:00
Simon McVittie
cdd2dc4140 Post-release version bump
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-26 19:30:21 +01:00
Simon McVittie
c8c8712fab Prepare v1.14.2
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-26 16:53:09 +01:00
Simon McVittie
cba75022e9 AUTHORS: Update
Result of: make -C $builddir update-authors

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-26 09:26:44 +01:00
Simon McVittie
ad1d223ada Disable deprecation warnings for stable branch
We're not going to replace deprecated functions here, similar to commit
88e0ccb2 in the dbus-1.10 branch.

Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 93efaf7873)
2022-09-22 12:23:27 +01:00
Simon McVittie
ff363d1bb0 Merge branch '1.14.x-backports' into 'dbus-1.14'
Backport various fixes from 1.15.x branch

See merge request dbus/dbus!341
2022-09-13 12:12:15 +00:00
Simon McVittie
ccb5247454 Update NEWS for 1.14.x branch
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-13 12:47:29 +01:00
Alex Richardson
a41ee157dd cmake: Always try to find pkg-config
Commit 97bdefd4e2 move the
include(FindPkgConfig) call into a Linux-specific codepath, so pkg-config
was not being detected on FreeBSD. This mean that the check for
PKG_CONFIG_FOUND to determine whether to install .pc files later on
would always fail and .pc files were not installed on FreeBSD.

(cherry picked from commit 82f5c96644)
Backported-from: dbus!280
2022-09-13 12:47:29 +01:00
Alex Richardson
a817ff39d2 cmake: Check for setresuid and getresuid
This was not being checked, so the codepaths using the define were
never included.

(cherry picked from commit dafb5ddc09)
2022-09-13 12:47:29 +01:00
Alex Richardson
e1d2cd286b dir-watch-kqueue: Silence -Wshadow warning
This should be the last warning that is preventing us from using -Werror
for FreeBSD builds.

(cherry picked from commit 2480181af4)
Backported-from: dbus!307
2022-09-13 12:47:29 +01:00
Ralf Habacker
890f0e0fc6 Fix building on Mac OSX when using launchd
Provided by Dawid Wróbel at
https://invent.kde.org/packaging/craft-blueprints-kde\
/-/blob/master/libs/dbus/0002-fix-macos-build.diff

(cherry picked from commit 30426b26e6)
Backported-from: dbus!287
2022-09-13 12:27:10 +01:00
Alex Richardson
6a5e212b39 dbus-sysdeps-util-unix.c: Avoid including sys/syslimits.h
This header is GCC specific header that on my system just contains
`#include_next <limits.h>`. FreeBSD also provides this header but it
contains a `#warning` that it should not be used. Replace the one use
with `#include <limit.h>` and drop the configure checks.

(cherry picked from commit a214ed824d)
Backported-from: dbus!280
2022-09-13 12:26:36 +01:00
Simon McVittie
2d36911fc3 Move release checklist to its own file
In other projects I've found that having a separate file that only
lists the release steps makes them easier to check.

Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 3758e5b164)
2022-09-13 12:26:33 +01:00
Simon McVittie
c8dd76206b test: Skip tests that involve switching uid if unable to do so
In a Linux user namespace, it is possible that we are uid 0 but are
unable to switch to some other uid like DBUS_USER or DBUS_TEST_USER,
because the other uid is not "mapped" in the user namespace, resulting
in setuid() or setresuid() failing with EINVAL "Invalid argument".
For example, it's easy for this to happen when running under the
bubblewrap tool.

Try to drop privileges in a child process, and skip the test if we
are unable to do so.

Resolves: dbus#407
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 8b08dd3264)
Backported-from: dbus!330
2022-09-13 12:26:24 +01:00
Simon McVittie
a54da99a06 sysdeps: Only open oom_score_adj read/write if we need to write it
If we're running in a sandbox, we might not have write access to
oom_score_adj. In the common case where we don't have any special
protection from the OOM-killer, we can detect that with only read
access, and skip the part where we open it for writing.

(We would also not have write access to oom_score_adj if we're running
with elevated Linux capabilities while not root, but that should never
actually happen for dbus-daemon-launch-helper, which is setuid root
for production use or has no capabilities during unit-testing.)

Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit a8006841ce)
Backported-from: dbus!291
2022-09-13 12:26:20 +01:00
Simon McVittie
aacd468108 activation-helper: Never crash if unable to write oom_score_adj
_dbus_warn() normally only logs a warning, but can be made fatal by
environment variables. In particular, we do that during unit testing,
which can result in a build-time test failure if dbus is built in a
sandbox environment that prevents write access.

_dbus_log() does only the logging part of _dbus_warn(), which seems
more appropriate here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit ad72e3b9e3)
Backported-from: dbus!291
2022-09-13 12:26:13 +01:00
Simon McVittie
434ac5fdb3 COPYING: The project is called dbus, not D-Bus
We are trying to be consistent about saying this codebase is dbus
(a piece of software), which is the reference implementation of D-Bus
(a protocol).

Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 789d97ad53)
2022-09-13 12:26:07 +01:00
Alex Richardson
6d7ec5fc6d configure: Avoid exit() when checking for __sync_sub_and_fetch()
Use of exit() requires a stdlib.h include. This check was failing for me
since the compiler defaulted to -Werror=implicit-function-declaration, so
__sync_sub_and_fetch() support was not dectected.

(cherry picked from commit 56e52a4212)
Backported-from: dbus!320
2022-09-13 12:25:54 +01:00
Jan Tojnar
6625f220c4 build: Do not dist built XML catalog
It will have whatever paths the person who built the dist tarball hardcoded.

(cherry picked from commit dcd19cc0d9)
Backported-from: dbus!317
2022-09-13 12:25:40 +01:00
Alex Richardson
9cf3b0810f cmake: Fix definition of DBUS_USE_SYNC
dbus-sysdeps-unix.c checks for DBUS_USE_SYNC using 0/1 checks not defined
checks, so we should be using #cmakedefine01. This fixes lots of -Wundef
warnings when compiling for FreeBSD and ensures that we actually use
atomics instead of the pthread fallback there.

(cherry picked from commit b932c343c4)
Backported-from: dbus!306
2022-09-13 12:24:56 +01:00
Jan Tojnar
9e8fe0718c bus/dir-watch: Do not crash with > 128 dirs
Without this running, dbus-daemon with long XDG_DATA_DIRS
will crash on out-of-bounds write:

	$ XDG_DATA_DIRS=$(seq  -f "/foo/%g" -s ':' 129) dbus-daemon --session
	*** stack smashing detected ***: terminated

(cherry picked from commit b551b3e973)
Backported-from: dbus!302
2022-09-13 12:24:49 +01:00
Alex Richardson
3533087ea4 cmake: Correct DBUS_{SYSTEM,SESSION}_CONFIG_FILE on UNIX systems
We always install to a dbus-1 subdir, but the path encoded in the binary
was missing the dbus-1/ subdirectory, so we end up getting errors when
trying to load it.

(cherry picked from commit f4876e7cb5)
Backported-from: dbus!297
2022-09-13 12:24:43 +01:00
Alex Richardson
1c08115609 Fix no-X11 build after d847b5f6ae
Since that commit the error variable is used in all cases not only the
DBUS_BUILD_X11 #ifdef branches.

Fixes: https://gitlab.freedesktop.org/dbus/dbus/-/issues/392
(cherry picked from commit 6c1c7e539f)
Backported-from: dbus!298
2022-09-13 12:24:35 +01:00
Simon McVittie
e2dd13d906 cmake: Look for dbus-arch-deps.h next to DBus1Config.cmake
<dbus/dbus-arch-deps.h> is architecture-dependent, and compilers have
not traditionally supported an installation path for architecture-specific
headers (Debian-based systems have /usr/include/${multiarch_tuple}, but
that isn't portable beyond Debian). When dbus was built using Autotools,
dependent projects that use CMake need to look for this header in the
right place.

Unfortunately, it seems that at least recent versions of CMake will
ignore the HINTS we get from pkg-config if they are told to search in
a non-standard prefix via ${DBus1_ROOT}.

Look for dbus-arch-deps.h in a directory derived from the filename of
the CMake config file, before trying the normal search algorithm. The
CMake config file is in ${libdir}, and so is the architecture-specific
header, so this should work reasonably reliably.

According to the CMake documentation, if we search for the same thing
multiple times, the first successful result will be used; and searching
with NO_DEFAULT_PATH is the official way to prepend things to the
search order.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/314
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit 104df89947)
Backported-from: dbus!191
2022-09-13 12:24:24 +01:00
Mike Gilbert
d5f9a6e075 sysdeps-unix: check fd before calling _dbus_fd_set_close_on_exec()
If /proc/self/oom_score_adj does not exist, fd will invalid (-1).
Attempting to set the CLOEXEC flag will obviously fail, and we lose the
original errno value from open().

Bug: https://bugs.gentoo.org/834725
Signed-off-by: Mike Gilbert <floppym@gentoo.org>
(cherry picked from commit 769a0462be)
Backported-from: dbus!285
2022-09-13 12:24:13 +01:00
Alex Richardson
0d3ca74340 cmake: Fix DBUS_SESSION_SOCKET_DIR when cross-compiling
Inferring it from the environment is not correct, since the host system
could have a different temporary directory defined. Instead of guessing
based on the host, require the user to pass an explicit directory when
cross-compiling. This is helpful for me since I am cross-compiling for
FreeBSD from macOS and on my host TMPDIR is set to
/var/folders/<random characters>/T/ instead of the expected /tmp.

(cherry picked from commit e827309976)
Backported-from: dbus!279
2022-09-13 12:24:07 +01:00
Alex Richardson
ce73955aad cmake: Use -Wl,-export_dynamic when building for macOS
The macOS linker does not accept --export-dynamic, so use this
alternate spelling.

(cherry picked from commit c7f6d07252)
Backported-from: dbus!278
2022-09-13 12:24:05 +01:00
Alex Richardson
41d2026fbd cmake: Only pass -Wl,--export-dynamic when linking
Otherwise we get the following warnings when building .o files with Clang:
clang-13: warning: -Wl,--export-dynamic: 'linker' input unused [-Wunused-command-line-argument]

This is required to allow the -Werror build to pass on FreeBSD.

(cherry picked from commit 1a8fd7a382)
Backported-from: dbus!278
2022-09-13 12:23:56 +01:00
Alex Richardson
8c05bdc586 cmake: Drop an unnecessary include directory
There should be no need to include the directory above the DBus sources,
if that is actually required users can always pass -I flags to CMake.
I noticed this because CLion started indexing all my cloned projects when
I opened DBus due to this include path.

(cherry picked from commit be5da7305e)
Backported-from: dbus!282
2022-09-13 12:23:50 +01:00
Alex Richardson
42b8ac2ba0 cmake: Detect backtrace() support on platforms such as FreeBSD
On FreeBSD use of backtrace requires linking libexecinfo. The current
check_symbol_exists() will fail due to that missing library. Fortunately,
CMake ships with a FindBacktrace module (at least since 3.0) that can
be used to correctly handle platforms such as FreeBSD (and OpenBSD
according to the FindBacktrace source).

(cherry picked from commit 3f5bdf0c2d)
Backported-from: dbus!281
2022-09-13 12:23:44 +01:00
Alex Richardson
83325d29ad Revert "Fix gcc compile error: redundant redeclaration of ‘environ’ [-Werror=redundant-decls]"
Breaks the build on FreeBSD which doens't have an environ declaration.
The CMake check_symbol_exists call sets `HAVE_DECL_ENVIRON` to an empty
variable (which means if(DEFINED) suceeds). This normalization should not
be necessary as it will be handled correctly by `#cmakedefine01`. If not,
all the other HAVE_* defines would also be wrong.

This reverts commit e8b34b419e.

(cherry picked from commit d4dbde9fc5)
Backported-from: dbus!277
2022-09-13 12:23:36 +01:00
Ralf Habacker
b745747f52 cmake: Set DBUS_*_CONFIG_FILE to be in datadir on Unix
The files were installed to the datadir (usually /usr/share) since
commit 70950325, but the macros used to implement dbus-daemon --system
and dbus-daemon --session still looked for them in the sysconfdir
(usually /etc).

Fixes: 70950325 "Adjust cmake build to match autoconf installation locations"
(cherry picked from commit 6c21072a1e)
Backported-from: dbus!267
2022-09-13 12:23:24 +01:00