X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-bus%2Fsd-bus.c;h=2cb1aafa2b147914650bf6135413227682764100;hb=15411c0cb1192799b37ec8f25d6f30e8d7292fc6;hp=a8d03b8ac463828c482c8d502f6af814a817b125;hpb=146d47736780e06f618379a6c9f46edcf46803a7;p=elogind.git diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index a8d03b8ac..2cb1aafa2 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -20,19 +20,16 @@ ***/ #include -#include #include #include #include -#include -#include +#include #include #include #include "util.h" #include "macro.h" #include "strv.h" -#include "set.h" #include "missing.h" #include "def.h" #include "cgroup-util.h" @@ -45,8 +42,6 @@ #include "bus-socket.h" #include "bus-kernel.h" #include "bus-control.h" -#include "bus-introspect.h" -#include "bus-signature.h" #include "bus-objects.h" #include "bus-util.h" #include "bus-container.h" @@ -357,6 +352,21 @@ _public_ int sd_bus_set_description(sd_bus *bus, const char *description) { return free_and_strdup(&bus->description, description); } +_public_ int sd_bus_set_allow_interactive_authorization(sd_bus *bus, int b) { + assert_return(bus, -EINVAL); + assert_return(!bus_pid_changed(bus), -ECHILD); + + bus->allow_interactive_authorization = !!b; + return 0; +} + +_public_ int sd_bus_get_allow_interactive_authorization(sd_bus *bus) { + assert_return(bus, -EINVAL); + assert_return(!bus_pid_changed(bus), -ECHILD); + + return bus->allow_interactive_authorization; +} + static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) { const char *s; int r; @@ -1286,7 +1296,7 @@ int bus_set_address_system_remote(sd_bus *b, const char *host) { if (!e) return -ENOMEM; - c = strappenda(",argv4=--machine=", m); + c = strjoina(",argv4=--machine=", m); } } @@ -1513,21 +1523,43 @@ static int bus_seal_message(sd_bus *b, sd_bus_message *m, usec_t timeout) { } static int bus_remarshal_message(sd_bus *b, sd_bus_message **m) { + bool remarshal = false; + assert(b); - /* Do packet version and endianness already match? */ - if ((b->message_version == 0 || b->message_version == (*m)->header->version) && - (b->message_endian == 0 || b->message_endian == (*m)->header->endian)) - return 0; + /* wrong packet version */ + if (b->message_version != 0 && b->message_version != (*m)->header->version) + remarshal = true; + + /* wrong packet endianness */ + if (b->message_endian != 0 && b->message_endian != (*m)->header->endian) + remarshal = true; - /* No? Then remarshal! */ - return bus_message_remarshal(b, m); + /* TODO: kdbus-messages received from the kernel contain data which is + * not allowed to be passed to KDBUS_CMD_SEND. Therefore, we have to + * force remarshaling of the message. Technically, we could just + * recreate the kdbus message, but that is non-trivial as other parts of + * the message refer to m->kdbus already. This should be fixed! */ + if ((*m)->kdbus && (*m)->release_kdbus) + remarshal = true; + + return remarshal ? bus_message_remarshal(b, m) : 0; } int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) { assert(b); assert(m); + /* Fake some timestamps, if they were requested, and not + * already initialized */ + if (b->attach_flags & KDBUS_ATTACH_TIMESTAMP) { + if (m->realtime <= 0) + m->realtime = now(CLOCK_REALTIME); + + if (m->monotonic <= 0) + m->monotonic = now(CLOCK_MONOTONIC); + } + /* The bus specification says the serial number cannot be 0, * hence let's fill something in for synthetic messages. Since * synthetic messages might have a fake sender and we don't @@ -1535,7 +1567,6 @@ int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) { * pick a fixed, artificial one. We use (uint32_t) -1 rather * than (uint64_t) -1 since dbus1 only had 32bit identifiers, * even though kdbus can do 64bit. */ - return bus_message_seal(m, 0xFFFFFFFFULL, 0); } @@ -1675,7 +1706,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, if (r < 0) return r; if (r == 0) - return -ENOTSUP; + return -EOPNOTSUPP; } /* If the cookie number isn't kept, then we know that no reply @@ -1695,8 +1726,8 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, /* If this is a reply and no reply was requested, then let's * suppress this, if we can */ - if (m->dont_send && !cookie) - return 1; + if (m->dont_send) + goto finish; if ((bus->state == BUS_RUNNING || bus->state == BUS_HELLO) && bus->wqueue_size <= 0) { size_t idx = 0; @@ -1709,7 +1740,9 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, } return r; - } else if (!bus->is_kernel && idx < BUS_MESSAGE_SIZE(m)) { + } + + if (!bus->is_kernel && idx < BUS_MESSAGE_SIZE(m)) { /* Wasn't fully written. So let's remember how * much was written. Note that the first entry * of the wqueue array is always allocated so @@ -1719,6 +1752,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, bus->wqueue_size = 1; bus->windex = idx; } + } else { /* Just append it to the queue. */ @@ -1731,6 +1765,7 @@ static int bus_send_internal(sd_bus *bus, sd_bus_message *_m, uint64_t *cookie, bus->wqueue[bus->wqueue_size ++] = sd_bus_message_ref(m); } +finish: if (cookie) *cookie = BUS_MESSAGE_COOKIE(m); @@ -2140,8 +2175,6 @@ static int process_timeout(sd_bus *bus) { if (r < 0) return r; - m->sender = "org.freedesktop.DBus"; - r = bus_seal_synthetic_message(bus, m); if (r < 0) return r; @@ -2239,6 +2272,11 @@ static int process_reply(sd_bus *bus, sd_bus_message *m) { if (r < 0) return r; + /* Copy over original timestamp */ + synthetic_reply->realtime = m->realtime; + synthetic_reply->monotonic = m->monotonic; + synthetic_reply->seqnum = m->seqnum; + r = bus_seal_synthetic_message(bus, synthetic_reply); if (r < 0) return r; @@ -2544,15 +2582,6 @@ null_message: return r; } -static void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) { - assert(bus); - assert(m); - - m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus.Local"; - m->creds.well_known_names_local = true; - m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask; -} - static int process_closing(sd_bus *bus, sd_bus_message **ret) { _cleanup_bus_message_unref_ sd_bus_message *m = NULL; struct reply_callback *c; @@ -3369,7 +3398,7 @@ _public_ int sd_bus_try_close(sd_bus *bus) { assert_return(!bus_pid_changed(bus), -ECHILD); if (!bus->is_kernel) - return -ENOTSUP; + return -EOPNOTSUPP; if (!BUS_IS_OPEN(bus->state)) return -ENOTCONN;