Commit graph

179 commits

Author SHA1 Message Date
Kay Sievers 1b09f548c7 turn kdbus support into a runtime option
./configure --enable/disable-kdbus can be used to set the default
behavior regarding kdbus.

If no kdbus kernel support is available, dbus-dameon will be used.

With --enable-kdbus, the kernel command line option "kdbus=0" can
be used to disable kdbus.

With --disable-kdbus, the kernel command line option "kdbus=1" is
required to enable kdbus support.
2015-06-17 18:01:49 +02:00
Lennart Poettering b860a90ea5 bus-proxy: fix GetConnectionSELinuxSecurityContext() return value 2015-05-21 21:24:55 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
David Herrmann 15411c0cb1 tree-wide: there is no ENOTSUP on linux
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-13 14:10:39 +01:00
David Herrmann ec2c7b5659 bus-proxy: complain only once about queue overflows
If the local peer does not dispatch its incoming queue, the bus-proxy will
slowly fill its outgoing queue. Once its full, it will continously
complain that it cannot forward its messages.

As it turns out, pulseaudio does have an idle background dbus connection
that is not integrated into any mainloop (and given that gdbus and
libdbus1 both support background shared connections, PA is probably not
the only example), therefore, the bus-proxy will loudly complain if it
cannot forward NameOwnerChanged events once the queue is full.

This commit makes the proxy track queue-state and complain only once the
queue runs full, not if it is already full.

A PA bug-report (and patch) has been filed, and other applications should
be fixed similarly. Hence, lets keep the error message, instead of
dropping it. It's unused resources we really want to get rid of, so
silencing the message does not really help (which is actually what
dbus-daemon does).
2015-03-11 13:57:38 +01:00
Lukasz Skalski 52fa7a3af1 bus-proxy: add support for "GetConnectionCredentials" method
GetConnectionCredentials method was added to dbus-1 specification
more than one year ago. This method should return "[...] as many
credentials as possible for the process connected to the server",
but at this moment only "UnixUserID", "LinuxSecurityLabel" and
"ProcessID" are defined by the specification. We should add support
for next credentials after extending dbus-1 spec.
2015-03-10 16:12:14 +01:00
Zbigniew Jędrzejewski-Szmek c29005212d bus-proxyd: avoid logging oom twice 2015-03-03 10:19:51 -05:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
David Herrmann e28569311f bus-proxy: be more verbose if messages cannot be forwarded
If we cannot forward messages, include information on the peer and message
just like the xml-policy does. This helps debugging such situations and
figuring out what exactly is going wrong.
2015-02-14 19:01:21 +01:00
David Herrmann d90c154eb1 bus-proxy: don't fake data we don't have
UDS sockets transmit EUID+EGID only. Don't try to fake data we don't know!
Otherwise, this might be used to override user-limits by non-root setuid
programs (by faking UID==EUID).

Now that sd-bus is fixed to always use EUID even on UDS, we can safely set
all other UID/GID fields to INVALID.
2015-02-14 15:13:38 +01:00
Lennart Poettering c74f883c6f bus-proxy: ECONNRESET/ENOTCONN can hit us on every step, hence handle it on every step 2015-02-13 17:18:36 +01:00
Lennart Poettering 5569b33a8c bus-proxy: a few simplifications 2015-02-13 17:18:36 +01:00
Lennart Poettering 95eb099fa8 bus-proxy: close each connection fd only once
After passing the fds over to the sd_bus object, we should forget them,
so that we don't close them a second time when the object goes away.
2015-02-13 17:18:36 +01:00
Lennart Poettering 557b5d4a94 bus-proxy: also consider ENOTCONN a clean termination condition
Sometimes, when we try to reply to messages we don't check return
values. This means we might miss a ECONNRESET, and will get a ENOTCONN
on next command. Treat both the same hence.
2015-02-13 17:18:35 +01:00
Lennart Poettering 5f6cb09127 bus-proxy: whenever we cannot forward a message, report this back to caller, but don't exit
Errors like EPERM from the kernel should certainly not be reason to
exit. Let's try to be defensive here, and try to continue on most send
errors, but possibly tell the sender about it.
2015-02-13 15:49:51 +01:00
Lennart Poettering 1433efd219 bus-proxy: rename synthetic_reply_return_strv() to synthetic_reply_method_return_strv()
That way it matches more closely the nomenclature of our other
success reply calls.
2015-02-13 15:49:51 +01:00
Lennart Poettering 418e4cb07d bus-proxy: minor simplifications 2015-02-13 15:49:51 +01:00
Lennart Poettering 61adca52f6 bus-proxy: no need to negate error codes, log_error_errno() already does it 2015-02-13 15:49:51 +01:00
Lennart Poettering 1140e15410 bus-proxy: tell Coverity we don't care about these return values 2015-02-13 15:49:51 +01:00
Lennart Poettering d27efd9384 bus-proxy: we don't pointlessly abbreviate function names
It's fine to abbreviate local variables, but it's not OK to abbreviate
function names needlessly. This is not an excercise in writing
unreadable code.
2015-02-13 15:49:51 +01:00
Thomas Hindoe Paaboel Andersen 0a6f50c0af include <poll.h> instead of <sys/poll.h>
include-what-you-use automatically does this and it makes finding
unnecessary harder to spot. The only content of poll.h is a include
of sys/poll.h so should be harmless.
2015-02-12 20:47:38 +01:00
Lennart Poettering df3efc3c90 bus-proxyd: initialize ioctl structure only once 2015-02-10 20:46:09 +01:00
Lukasz Skalski cfcc160f22 bus-proxyd: fix 'ListQueuedOwners' call
Set proper kdbus_cmd_list object size, otherwise:

dbus-send --system --dest=org.freedesktop.DBus --type=method_call \
print-reply / org.freedesktop.DBus.ListQueuedOwners string:org.freedesktop.systemd1

Error org.freedesktop.DBus.Error.InvalidArgs: Invalid argument
2015-02-07 10:27:45 +01:00
David Herrmann b2086f601b bus: sync with kdbus (ABI break) 2015-02-05 16:52:42 +01:00
Thomas Hindoe Paaboel Andersen fed6df828d remove unused variables 2015-02-02 22:58:06 +01:00
Zbigniew Jędrzejewski-Szmek 1fa2f38f0f Assorted format fixes
Types used for pids and uids in various interfaces are unpredictable.
Too bad.
2015-01-22 01:14:52 -05:00
David Herrmann 50efadb0ae bus-proxy: don't pretend everyone is root
While it's a lovely scenario, it's probably not really useful. Fix our
GetConnectionUnixUser() to return the actual 'euid' which we asked for,
not the possible uninitialized 'uid'.
2015-01-18 21:34:33 +01:00
David Herrmann 05bae4a60c bus: use EUID over UID and fix unix-creds
Whenever a process performs an action on an object, the kernel uses the
EUID of the process to do permission checks and to apply on any newly
created objects. The UID of a process is only used if someone *ELSE* acts
on the process. That is, the UID of a process defines who owns the
process, the EUID defines what privileges are used by this process when
performing an action.

Process limits, on the other hand, are always applied to the real UID, not
the effective UID. This is, because a process has a user object linked,
which always corresponds to its UID. A process never has a user object
linked for its EUID. Thus, accounting (and limits) is always done on the
real UID.

This commit fixes all sd-bus users to use the EUID when performing
privilege checks and alike. Furthermore, it fixes unix-creds to be parsed
as EUID, not UID (as the kernel always takes the EUID on UDS). Anyone
using UID (eg., to do user-accounting) has to fall back to the EUID as UDS
does not transmit the UID.
2015-01-18 13:55:55 +01:00
David Herrmann e23f4bb525 bus-proxy: fake all UIDs/GIDs, not just the real UID/GID
Make sure we tell the kernel to fake all UIDs/GIDs. Otherwise, the remote
side has no chance of querying our effective UID (which is usually what
they're interested in).
2015-01-18 13:54:46 +01:00
David Herrmann d340f82032 bus-proxy: fix bus-uid tracking
We need to implicitly allow HELLO from users with the same uid as the bus.
Fix the bus-uid tracking to use the original uid, not the uid after
privilege-dropping.
2015-01-18 13:07:21 +01:00
David Herrmann 7447362c53 bus-proxy: don't print error-messages if we check multiple dests
If we test the policy against multiple destination names, we really should
not print warnings if one of the names results in DENY. Instead, pass the
whole array of names to the policy and let it deal with it.
2015-01-17 21:18:52 +01:00
David Herrmann 0d620e5336 bus-proxy: implement org.freedesktop.DBus.ReloadConfig()
Make sure to reload our xml policy configuration if requested via the bus.
2015-01-17 19:06:34 +01:00
David Herrmann bae8352c1d bus-proxy: fix indentation
Fix whitespace indentation.
2015-01-17 18:54:09 +01:00
David Herrmann a80a3a7543 bus-proxy: drop privileges if run as root
We cannot use "User=" in unit-files if we want to retain privileges. So
make bus-proxy.c explicitly drop privileges. However, only do that if
we're root, as there is no need to drop it on the user-bus.
2015-01-17 18:27:23 +01:00
David Herrmann c4bc1a8434 bus-proxy: share policy between threads
This implements a shared policy cache with read-write locks. We no longer
parse the XML policy in each thread.

This will allow us to easily implement ReloadConfig().
2015-01-17 18:27:23 +01:00
David Herrmann d3394ff47c bus-proxy: set custom thread names
Set thread-names to "p$PIDu$UID" and suffix with '*' if truncated. This
helps debugging bus-proxy issues if we want to figure out which
connections are currently open.
2015-01-17 14:32:58 +01:00
David Herrmann a8a1a43f48 bus-proxy: turn into multi-threaded daemon
Instead of using Accept=true and running one proxy for each connection, we
now run one proxy-daemon with a thread per connection. This will enable us
to share resources like policies in the future.
2015-01-17 14:00:19 +01:00
David Herrmann f299e3e430 bus-proxy: bring back systemd-stdio-bridge
Now that we want to make bus-proxy multi-threaded, we have to bring back
the systemd-stdio-bridge for our TCP use-cases.
2015-01-17 11:55:14 +01:00
David Herrmann c0395aeb90 bus-proxy: extract proxy into Proxy object
Move all the proxy code into a "struct Proxy" object that can be used
from multiple binaries.

We now dropped SMACK as we have to refactor it to work properly. We can
introduce it later on.
2015-01-17 11:55:14 +01:00
David Herrmann 91fd0103cc bus-proxy: refactor bus-creation
Move local and destination bus creation into a helper function. This
further reduces the line count of main().
2015-01-17 11:55:14 +01:00
Daniel Mack 5e2de0eb1d bus-proxyd: move synthesize_name_acquired()
Move synthesize_name_acquired() to synthesize.c.
2015-01-15 14:10:28 +01:00
Daniel Mack f3c4724635 bus-proxy: factor out code for driver handling and message synthesis
Move synthesize_*() into synthesize.c and bus_proxy_process_driver() into
driver.c for better code separation.
2015-01-15 14:08:05 +01:00
David Herrmann 87b934960a bus-proxy: implement 'at_console'
The 'at_console' policy-category allows to apply policy-items to clients
depending on whether they're run from within a valid user-session or not.
We use sd_uid_get_seats() to check whether a user has a valid seat (which
excludes remote-sessions like ssh).
2015-01-11 17:23:24 +01:00
David Herrmann b49c7806a3 bus-proxy: print message direction in policy logs
Make sure to print "dbus-1 to kernel" or "kernel to dbus-1" in policy logs
to better diagnose the situation.
2015-01-11 15:27:18 +01:00
David Herrmann b5cfc2b953 bus-proxy: fix receiver policy on dbus-1 to kdbus signals
If a dbus-1 client sends a broadcasted signal via the bus-proxy to kdbus,
the bus-proxy has no idea who the receiver is. Classic dbus-daemon has
bus-access and can perform policy checks for each receiver, but we cant.
Instead, we know the kernel will perform receiver policy checks for
broadcasts, so we can skip the policy check and just push it into the
kernel.

This fixes wpa_supplicant which has DENY rules on receive_type=signal for
non-root. As we never know the target, we always DENY all broadcasts from
wpa_supplicant.

Note that will still perform receiver-policy checks for signals that we
get from the kernel back to us. In those cases, we know the receiver
(which is us).
2015-01-11 15:14:14 +01:00
David Herrmann fa188b9b24 bus-proxy: fix swapped path/interface debug messages
The policy debug messages swapped "path=" and "interface=", fix this.
2015-01-11 14:54:33 +01:00
David Herrmann 0042d824e3 bus-proxy: fix policy for expected/non-expected reply tags
dbus-1 distinguishes expected and non-expected replies. An expected reply
is a reply that is sent as answer to a previously forwarded method-call
before the timeout fires. Those replies are, by default, forwarded and
DENY policy tags are ignored on them (unless explicitly stated otherwise).

We don't track reply-windows in the bus-proxy as the kernel already does
this. Furthermore, the kernel prohibits any non-expected replies (which
breaks dbus-1, but it was an odd feature, anyway).

Therefore, skip policy checks on replies and always let the kernel deal
with it!

To be correct, we should still process DENY tags marked as
send_expected_reply=true (which is *NOT* the default!). However, so far we
don't parse those attributes, and no-one really uses it, so lets not
implement it for now. It's marked as TODO if anyone feels like fixing it.
2015-01-11 14:18:29 +01:00
Lennart Poettering d714387ed7 bus-proxy: make sure we have creds when two legacy clients talk to each other 2015-01-09 21:24:37 +01:00
Lennart Poettering 48aae6d6a0 bus-proxy-test: show parsed system/session policy 2015-01-09 19:30:01 +01:00
Lennart Poettering 585b46db6b bus-proxy: eat up "*" matches, they are pointless 2015-01-09 19:28:18 +01:00