Commit graph

121 commits

Author SHA1 Message Date
Daniel Mack ed6d629a34 bus-proxyd: explicitly address messages to unique and well-known name
In order to check for matching policy entries at message transfers, we
have to consider the following:

* check the currently owned names of both the sending and the receiving
peer. If the sending peer is connected via kdbus, the currently owned
names are already attached to the message. If it was originated by the
connection we're proxying for, we store the owned names in our own strv
so we can check against them.

* Walk the list of names to check which name would allow the message to
pass, and explicitly use that name as destination of the message. If the
destination is on kdbus, store both the connection's unique name and the
chosen well-known-name in the message. That way, the kernel will make sure
the supplied name is owned by the supplied unique name, at the time of
sending, and return -EREMCHG otherwise.

* Make the policy checks optional by retrieving the bus owner creds, and
when the uid matches the current user's uid and is non-null, don't check
the bus policy.
2014-11-11 16:51:45 +01:00
Michal Schmidt 15e9297ebf Revert "bus-proxyd: make policy checks optional"
This reverts commit 5bb24cccbc.

It does not even compile (unbalanced {)
2014-11-11 15:36:48 +01:00
Daniel Mack 5bb24cccbc bus-proxyd: make policy checks optional
Retrieve the bus owner creds, and when the uid matches the current user's
uid and is non-null, don't check the bus policy.
2014-11-11 14:14:01 +01:00
Daniel Mack 2a2be74654 bus-proxyd: move name list iteration to policy users
We need to figure out which of the possible names satisfied the policy,
so we cannot do the iteration in check_policy_item() but have to leave it
to the users.

Test cases amended accordingly.
2014-11-11 14:14:01 +01:00
Daniel Mack 9cd751d2d0 bus-proxyd: enforce policy for method calls 2014-11-11 14:14:01 +01:00
Daniel Mack f0a4c7391c bus-proxyd: enforce policy for name ownership 2014-11-11 14:14:01 +01:00
Daniel Mack 8573b68fec bus-proxyd: enforce policy for Hello messages 2014-11-11 14:14:01 +01:00
Daniel Mack ac4eaf6dd4 bus-proxyd: keep track of names acquired by legacy client
Store names successfully acquired by the legacy client into a hashmap.
We need to take these names into account when checking for send policies.
2014-11-11 14:14:01 +01:00
Lennart Poettering f7fce3454c sd-bus: rename sd_bus_get_server_id() to sd_bus_get_owner_id()
In kdbus a "server id" is mostly a misnomer, as there isn't any "server"
involved anymore. Let's rename this to "owner" id hence, since it is an
ID that is picked by the owner of a bus or direct connection. This
matches nicely the sd_bus_get_owner_creds() call we already have.
2014-11-04 18:09:19 +01:00
Lennart Poettering 455971c149 sd-bus: rename "connection name" to "description" for the sd-bus API too
kdbus recently renamed this concept, and so should we in what we expose
in userspace.
2014-11-04 16:13:49 +01:00
Daniel Mack 635f9f0d95 sd-bus: sync kdbus.h (ABI break)
Catch up with some changes in kdbus.h:

  * KDBUS_{ITEM,ATTACH}_CONN_NAME were renamed to
    KDBUS_{ITEM,ATTACH}_CONN_DESCRIPTION, so the term 'name' is not
    overloaded as much.

  * The item types were re-ordered a little so they are lined up to the
    order of the corresponding KDBUS_ATTACH flags

  * A new item type KDBUS_ITEM_OWNED_NAME was introduced, designated to
    store a struct kdbus_name in item->name. KDBUS_ITEM_NAME soley
    stores data in item->str now

  * Some kerneldoc fixes
2014-11-04 12:44:53 +01:00
Lennart Poettering 96343c3039 bus-proxy: it's OK if getpeercred doesn't work
We should use the data if we can (if stdin/stdout is an AF_UNIX socket),
but still work if we can't (if stdin/stdout are pipes, like in the SSH
case).

This effectively reverts 55534fb5e4
2014-10-24 19:29:59 +02:00
Daniel Mack 056f95d0a7 sd-bus: rename sd_bus_get_owner_uid(), sd_bus_get_owner_machine_id() and sd_bus_get_peer_creds()
Clean up the function namespace by renaming the following:

  sd_bus_get_owner_uid()        → sd_bus_get_name_creds_uid()
  sd_bus_get_owner_machine_id() → sd_bus_get_name_machine_id()
  sd_bus_get_peer_creds()       → sd_bus_get_owner_creds()
2014-10-22 19:45:07 +02:00
Daniel Mack bc75205c77 sd-bus: sync kdbus.h (ABI break)
In kdbus.h, the following details changed:

 * All commands gained a 'kernel_flags' field to report the flags supported
   by the driver. Before, this was done in the 'flags' field in a
   bidirectional way, which turned out to be a problem for the code in
   sd-bus, as many parts of it reuse the same ioctl struct more than once
   and consider them to be owned by userspace.

 * Name listings are now returned by a new struct instead of reusing struct
   kdbus_cmd_name for that matter. This way, we don't add more unneeded
   fields to it and make the API cleaner.

 * 'conn_flags' was renamed to 'flags' in struct kdbus_cmd_hello to make
   the API a bit more unified.
2014-10-21 19:19:44 +02:00
Lennart Poettering 2dd1ca3fd6 bus-proxy: let's make use of the translated errors get_creds_by_name() provides us with 2014-10-20 21:50:37 +02:00
Lennart Poettering 24078eebf3 Revert "bus-proxyd: improve compatibility with dbus-1"
This reverts commit b0f84d4d78.

get_creds_by_name() already translate the error nicely, we just need to
make use of it.
2014-10-20 21:46:09 +02:00
Lukasz Skalski 14759eeb71 bus-proxyd: add missing flag translation for RequestName 2014-10-15 09:09:01 +02:00
Lukasz Skalski b0f84d4d78 bus-proxyd: improve compatibility with dbus-1
'GetConnectionUnixProcessID', 'GetConnectionUnixUser' and
'GetConnectionSELinuxSecurityContext' methods should return
'NameHasNoOwner' error (if chosen name is not available on bus)
with more detailed description - like dbus-1:

Could not get PID of name 'org.freedesktop.test': no such name.
Could not get UID of name 'org.freedesktop.test': no such name.
Could not get security context of name 'org.freedesktop.test': no such name.

Otherwise we have only laconic message without proper dbus error:

Error System.Error.ENXIO: No such device or address
2014-10-14 19:39:55 +02:00
Lukasz Skalski 547e849b72 bus-proxyd: fix compatibility with old dbus-1
'ListQueuedOwners' method should return 'NameHasNoOwner' error
if chosen name is not available on bus.
2014-10-10 23:43:59 +02:00
Daniel Mack 7ff3bb4e47 bus-proxy: allow getpeersec() to fail
getpeersec() will fail for non-SELinux enabled machines, so don't make that
a hard error.
2014-10-09 15:41:44 +02:00
Daniel Mack 55534fb5e4 bus-proxyd: check return values of getpeercred() and getpeersec()
If we can't get the remote peer or security creds, bail out.

Spotted by coverity.
2014-10-07 12:36:09 +02:00
Daniel Mack d663f1b1a9 sd-bus: sync kdbus.h (ABI break)
The KDBUS_CMD_FREE ioctl now uses a struct rather than a direct pointer
to the offset to free.

The KDBUS_CMD_MSG_CANCEL ioctl has also changes, but there's no user of
it yet in systemd.
2014-10-06 18:36:16 +02:00
Thomas Hindoe Paaboel Andersen cf4acf84c6 Remove repeated includes
In pty.c there was both an include of our pty.h and the system installed pty.h.
The latter contains only two functions openpty and forkpty. We use neither so
I assume it was a typo and removed it. We still compile and pass all tests.
2014-10-01 23:25:50 +02:00
Tom Gundersen 94a2c2f64a bus-proxyd: add some asserts
Both as documentation, and to make Coverity happy.

Fixes CID #1241495 and #1241496.
2014-09-25 15:59:24 +02:00
Daniel Mack f8c2425287 sd-bus: sync kdbus.h (API+ABI break)
The kdbus logic name registry logic was changed to transport the actual
name to acquire, release or report in a kdbus item.

This brings the name API a little more in line with other calls, and allows
for later augmentation.

Follow that change on the systemd side.
2014-09-22 18:22:53 +02:00
Lennart Poettering af4ec4309e notify: send STOPPING=1 from our daemons 2014-08-21 17:24:21 +02:00
Thomas Hindoe Paaboel Andersen 17a6dfa3be bus-proxy: service_name_is_valid will never be < 0 2014-08-05 18:22:31 +02:00
Lennart Poettering 249968612f bus: always explicitly close bus from main programs
Since b5eca3a205 we don't attempt to GC
busses anymore when unsent messages remain that keep their reference,
when they otherwise are not referenced anymore. This means that if we
explicitly want connections to go away, we need to close them.

With this change we will no do so explicitly wherver we connect to the
bus from a main program (and thus know when the bus connection should go
away), or when we create a private bus connection, that really should go
away after our use.

This fixes connection leaks in the NSS and PAM modules.
2014-08-04 16:25:24 +02:00
Zbigniew Jędrzejewski-Szmek 601185b43d Unify parse_argv style
getopt is usually good at printing out a nice error message when
commandline options are invalid. It distinguishes between an unknown
option and a known option with a missing arg. It is better to let it
do its job and not use opterr=0 unless we actually want to suppress
messages. So remove opterr=0 in the few places where it wasn't really
useful.

When an error in options is encountered, we should not print a lengthy
help() and overwhelm the user, when we know precisely what is wrong
with the commandline. In addition, since help() prints to stdout, it
should not be used except when requested with -h or --help.

Also, simplify things here and there.
2014-08-03 21:46:07 -04:00
Lukas Nykryn e05aa2e02b bus-proxyd: fix incorrect comparison
We should be interested in k variable.
2014-07-25 10:25:06 +02:00
Lukas Nykryn eb17e17859 bus-proxyd: fix incorrect comparison
Err can't be bigger then zero. Rest of the code uses negative Exxxx values.
2014-07-25 09:58:52 +02:00
Lennart Poettering 7f0d207d2c sd-bus: support connecting to remote hosts, directly into containers
systemctl -H root@foobar:waldi

will now show a list of services running on container "waldi" on host
"foobar", using "root" for authenticating at "foobar".

Since entereing a container requires priviliges, this will only work
correctly for root logins.
2014-07-03 01:17:26 +02:00
Lennart Poettering 62bb05f64f bus-proxy: restore operation in non-kdbus mode
bus-proxyd is not only the bridge between legacy dbus clients and kdbus
but is also used to access remote dbus servers via ssh. Let's make sure
it actually works for that.
2014-07-02 17:12:24 +02:00
Lennart Poettering 2e2b36084a bus-proxy: read the right policy when running in user mode 2014-06-10 17:56:51 +02:00
Lennart Poettering bcf3295d2b bus: add basic dbus1 policy parser
Enforcement is still missing, but at least we can parse it now.
2014-06-06 19:41:24 +02:00
Lennart Poettering 6a010ac9e5 bus-proxy: drop priviliges if we can
Either become uid/gid of the client we have been forked for, or become
the "systemd-bus-proxy" user if the client was root. We retain
CAP_IPC_OWNER so that we can tell kdbus we are actually our own client.
2014-06-04 11:13:08 +02:00
Lennart Poettering 19befb2d5f sd-bus: introduce sd_bus_slot objects encapsulating callbacks or vtables attached to a bus connection
This makes callback behaviour more like sd-event or sd-resolve, and
creates proper object for unregistering callbacks.

Taking the refernce to the slot is optional. If not taken life time of
the slot will be bound to the underlying bus object (or in the case of
an async call until the reply has been recieved).
2014-05-15 01:15:30 +02:00
Kay Sievers dc780ecf10 bus-proxyd: handle org.freedesktob.DBus calls natively 2014-04-22 19:15:35 +02:00
Thomas Hindoe Paaboel Andersen b8ec9ba918 bus-proxy: remove unused variable 2014-04-14 21:02:25 +02:00
Lennart Poettering 2f1a3d0868 bus-proxy: when replying to bus calls set a synthetic serial number and patch the sender address
Otherwise old libdbus1 is confused and will not accept our replies.
2014-04-13 19:43:00 -07:00
Lennart Poettering 2a0abe5b6d bus: process AddMatch/RemoveMatch driver call in proxy
Previously, AddMatch/RemoveMatch calls where processed exclusively in
the proxy. That's racy however, since subscribing to a signal might not
complete before the signal is sent due to some subsequent method call.
Hence, in order to expose the same ordering guarantees as dbus1 process
the AddMatch/RemoveMatch calls from the proxy, so that they are
dispatched synchronously to all following messages, thus fixing the
race.

Ultimately, we should probabably dissolve the driver entirely into the
proxy, as it is purely a compatibility feature anyway...
2014-04-13 18:34:55 -07:00
Zbigniew Jędrzejewski-Szmek bdd13f6be4 Remove dead lines in various places
As pointed-out by clang -Wunreachable-code.

No behaviour changes.
2014-02-24 19:24:14 -05:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Greg KH 29804cc1e0 use memzero(foo, length); for all memset(foo, 0, length); calls
In trying to track down a stupid linker bug, I noticed a bunch of
memset() calls that should be using memzero() to make it more "obvious"
that the options are correct (i.e. 0 is not the length, but the data to
set).  So fix up all current calls to memset(foo, 0, length) to
memzero(foo, length).
2014-01-31 11:55:01 +01:00
Lennart Poettering 7b217f41d2 bus: when proxying messages from the bus driver patch the driver's well-known name into the sender 2014-01-29 21:26:57 +01:00
Lennart Poettering 373f14222e bus: fake security labels again
(The kernel module got fixed, so let's reenable this again)
2014-01-29 13:42:06 +01:00
Lennart Poettering aa575ef8de bus: temporarily disable faking of seclabels, as this is broken in kdbus right now 2014-01-22 19:39:10 +01:00
Lennart Poettering 44b0ed0586 bus: set debug name of proxy bus connections 2014-01-22 19:08:22 +01:00
Tom Gundersen 920e2957be bus-proxyd: add some more debugging
Make sure we print a message when exiting with an error.
2014-01-12 15:37:20 +01:00
Lennart Poettering 441d56a12a bus: properly handle EOF error conditions in proxyd
EOF is not an error so we should not print an error message about it.
2014-01-12 10:56:40 +08:00
Zbigniew Jędrzejewski-Szmek ccd06097c7 Use format patterns for usec_t, pid_t, nsec_t, usec_t
It is nicer to predefine patterns using configure time check instead of
using casts everywhere.

Since we do not need to use any flags, include "%" in the format instead
of excluding it like PRI* macros.
2014-01-02 19:45:47 -05:00
Zbigniew Jędrzejewski-Szmek ab9001a1e3 Move bus path definitions to def.h 2014-01-02 19:45:47 -05:00
Lennart Poettering c2595875c6 bus: add a temporary hard-coded policy to proxyd to make gdm work
gdm relies on the policy to deny its own requests to not deadlock. Given
that we currently do not enforce any policy in the dbus1 compat proxy
service this means that gdm will necessarily deadlock on our systems.

To work around this, enforce a fixed policy teomporarily, until we
interpret the legacy XML policy in full.

Booh, gdm, booh, for requring this and making me waste two days on
tracking this brokenness down.
2013-12-26 17:16:56 +01:00
Lennart Poettering 758bf0c755 bus: don't process Peer interface messages in the proxy 2013-12-26 03:08:52 +01:00
Lennart Poettering 4cdf07519a bus: be a bit more verbose when debug mode is on 2013-12-25 02:41:09 +01:00
Lennart Poettering 9f6445e34a log: log_error() and friends add a newline after each line anyway, so avoid including it in the log strings 2013-12-24 16:39:37 +01:00
Lennart Poettering eff0527098 util: unify SO_PEERCRED/SO_PEERSEC invocations
Introduce new call getpeercred() which internally just uses SO_PEERCRED
but checks if the returned data is actually useful due to namespace
quirks.
2013-12-24 15:53:04 +01:00
Lennart Poettering 8a0e0ed9dd bus: fake client side creds in the proxy to the caller's creds 2013-12-24 15:27:59 +01:00
Kay Sievers 94a6ce5b7c bus-proxyd: init cleanup variable 2013-12-23 19:16:49 +01:00
Lennart Poettering a7639e37af bus-proxyd: synthesize NameAcquire/NameLost signals for socket clients 2013-12-23 04:20:55 +01:00
Kay Sievers f72a3e5bad Revert "bus-proxyd: use a loop instead of c&p"
This reverts commit 9818fa6d6d.

The proxy does not work anymore with this patch.
2013-12-22 16:41:24 +01:00
Zbigniew Jędrzejewski-Szmek 2dc38ed00f man: add systemd-dbus-proxy@.service(8) and systemd-dbus.proxy(8) 2013-12-21 18:34:40 -05:00
Zbigniew Jędrzejewski-Szmek 9818fa6d6d bus-proxyd: use a loop instead of c&p 2013-12-21 18:34:40 -05:00
Zbigniew Jędrzejewski-Szmek cc4e8b6f70 bus-proxyd: show address nicely in --help 2013-12-21 18:26:47 -05:00
Lennart Poettering b2bb3469fd bus: poll() on the right fds in proxyd 2013-12-21 17:54:29 +01:00
Lennart Poettering 0721804f03 bus: send status message from proxyd to systemd about client we are working for 2013-12-21 05:15:09 +01:00
Lennart Poettering 0358b3f95d bus: properly react to Disconnected messages in bus-proxyd 2013-12-21 04:03:12 +01:00
Lennart Poettering ba7689164c bus: change bus-proxyd command line parsing to be more similar to other tools 2013-12-21 03:59:07 +01:00
Lennart Poettering 7c9a6f9063 bus: install systemd-bus-proxyd unit files for compatibility with dbus1 2013-12-13 20:49:57 +01:00
David Strauss 683fc3a448 bus-proxyd: Fix CLI help. --bus-path is also usable as -p. 2013-11-30 16:55:30 +10:00
Kay Sievers f252ff1742 rename stdio-bridge to bus-proxyd 2013-11-29 22:12:59 +01:00
Renamed from src/stdio-bridge/stdio-bridge.c (Browse further)