[systemd-commits] 9 commits - src/bus-driverd src/bus-proxyd src/core src/libsystemd-bus
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Dec 20 19:07:32 PST 2013
src/bus-driverd/bus-driverd.c | 6 ++++
src/bus-proxyd/bus-proxyd.c | 55 +++++++++++++++++++++++++++------------
src/core/dbus.c | 1
src/libsystemd-bus/bus-kernel.c | 28 ++++++++++++-------
src/libsystemd-bus/bus-match.c | 37 +++++++++++++++++---------
src/libsystemd-bus/bus-message.c | 8 +++++
src/libsystemd-bus/sd-bus.c | 3 ++
7 files changed, 99 insertions(+), 39 deletions(-)
New commits:
commit 76252ffbde7e8163c67d847db2445d8c49e32457
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 04:06:11 2013 +0100
driverd: sort list of names returned by ListNames
diff --git a/src/bus-driverd/bus-driverd.c b/src/bus-driverd/bus-driverd.c
index 46ee349..de23445 100644
--- a/src/bus-driverd/bus-driverd.c
+++ b/src/bus-driverd/bus-driverd.c
@@ -484,6 +484,9 @@ static int driver_list_names(sd_bus *bus, sd_bus_message *m, void *userdata, sd_
if (r < 0)
return r;
+ /* Let's sort the names list to make it stable */
+ strv_sort(names);
+
return return_strv(bus, m, names);
}
@@ -495,6 +498,9 @@ static int driver_list_activatable_names(sd_bus *bus, sd_bus_message *m, void *u
if (r < 0)
return r;
+ /* Let's sort the names list to make it stable */
+ strv_sort(names);
+
return return_strv(bus, m, names);
}
commit 0358b3f95d7cfdd05e7cb8394cfdb6b3b4b14ffc
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 04:03:12 2013 +0100
bus: properly react to Disconnected messages in bus-proxyd
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index ce2a20b..4145217 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -209,11 +209,22 @@ int main(int argc, char *argv[]) {
r = sd_bus_process(a, &m);
if (r < 0) {
- log_error("Failed to process bus a: %s", strerror(-r));
+ /* treat 'connection reset by peer' as clean exit condition */
+ if (r == -ECONNRESET)
+ r = 0;
+ else
+ log_error("Failed to process bus a: %s", strerror(-r));
+
goto finish;
}
if (m) {
+ /* We officially got EOF, let's quit */
+ if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected")) {
+ r = 0;
+ goto finish;
+ }
+
r = sd_bus_send(b, m, NULL);
if (r < 0) {
log_error("Failed to send message: %s", strerror(-r));
@@ -229,11 +240,19 @@ int main(int argc, char *argv[]) {
/* treat 'connection reset by peer' as clean exit condition */
if (r == -ECONNRESET)
r = 0;
+ else
+ log_error("Failed to process bus b: %s", strerror(-r));
goto finish;
}
if (m) {
+ /* We officially got EOF, let's quit */
+ if (sd_bus_message_is_signal(m, "org.freedesktop.DBus.Local", "Disconnected")) {
+ r = 0;
+ goto finish;
+ }
+
r = sd_bus_send(a, m, NULL);
if (r < 0) {
log_error("Failed to send message: %s", strerror(-r));
@@ -309,5 +328,8 @@ int main(int argc, char *argv[]) {
r = 0;
finish:
+ sd_bus_flush(a);
+ sd_bus_flush(b);
+
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
commit ba7689164c0f81ad23861b486514c86ec908ffee
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 03:59:07 2013 +0100
bus: change bus-proxyd command line parsing to be more similar to other tools
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index 015f40a..ce2a20b 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -41,19 +41,19 @@
#include "build.h"
#ifdef ENABLE_KDBUS
-const char *arg_bus_path = "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket";
+const char *arg_address = "kernel:path=/dev/kdbus/0-system/bus;unix:path=/run/dbus/system_bus_socket";
#else
-const char *arg_bus_path = "unix:path=/run/dbus/system_bus_socket";
+const char *arg_address = "unix:path=/run/dbus/system_bus_socket";
#endif
static int help(void) {
printf("%s [OPTIONS...]\n\n"
- "Connection STDIO or a socket to a given bus address.\n\n"
+ "Connect STDIO or a socket to a given bus address.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
- " -p --bus-path=PATH Bus address to forward to (default: %s)\n",
- program_invocation_short_name, arg_bus_path);
+ " --address=ADDRESS Connect to bus specified by address\n",
+ program_invocation_short_name);
return 0;
}
@@ -62,12 +62,14 @@ static int parse_argv(int argc, char *argv[]) {
enum {
ARG_VERSION = 0x100,
+ ARG_ADDRESS,
};
static const struct option options[] = {
- { "help", no_argument, NULL, 'h' },
- { "bus-path", required_argument, NULL, 'p' },
- { NULL, 0, NULL, 0 }
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, ARG_VERSION },
+ { "address", required_argument, NULL, ARG_ADDRESS },
+ { NULL, 0, NULL, 0 }
};
int c;
@@ -88,16 +90,15 @@ static int parse_argv(int argc, char *argv[]) {
puts(SYSTEMD_FEATURES);
return 0;
+ case ARG_ADDRESS:
+ arg_address = optarg;
+ break;
+
case '?':
return -EINVAL;
- case 'p':
- arg_bus_path = optarg;
- break;
-
default:
- log_error("Unknown option code %c", c);
- return -EINVAL;
+ assert_not_reached("Unhandled option");
}
}
@@ -140,7 +141,7 @@ int main(int argc, char *argv[]) {
goto finish;
}
- r = sd_bus_set_address(a, arg_bus_path);
+ r = sd_bus_set_address(a, arg_address);
if (r < 0) {
log_error("Failed to set address to connect to: %s", strerror(-r));
goto finish;
commit 3547329642fef7468548320131ab992517957e81
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 03:52:39 2013 +0100
bus: refuse messages pretending to originate from local interface
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index d688873..b0f4b16 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -5133,6 +5133,14 @@ int bus_message_parse_fields(sd_bus_message *m) {
break;
}
+ /* Refuse non-local messages that claim they are local */
+ if (streq_ptr(m->path, "/org/freedesktop/DBus/Local"))
+ return -EBADMSG;
+ if (streq_ptr(m->interface, "org.freedesktop.DBus.Local"))
+ return -EBADMSG;
+ if (streq_ptr(m->sender, "org.freedesktop.DBus.Local"))
+ return -EBADMSG;
+
m->root_container.end = BUS_MESSAGE_BODY_SIZE(m);
if (BUS_MESSAGE_IS_GVARIANT(m)) {
commit bd746b8b0ce91be3f28532d319ffa577590f52d8
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 03:46:26 2013 +0100
bus: in sd_bus_try_close() consider local read queue too
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index a394955..6e44068 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2965,6 +2965,9 @@ _public_ int sd_bus_try_close(sd_bus *bus) {
assert_return(!bus_pid_changed(bus), -ECHILD);
assert_return(bus->is_kernel, -ENOTSUP);
+ if (bus->rqueue_size > 0)
+ return -EBUSY;
+
r = bus_kernel_try_close(bus);
if (r < 0)
return r;
commit 8e8d37602f33269df0b0d3d93f017d7263b5cea0
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 03:17:29 2013 +0100
bus: always override message destination field with data from kdbus
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 5913d42..e53bc51 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -848,14 +848,15 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
m->sender = m->creds.unique_name = m->sender_buffer;
}
- if (!m->destination) {
- if (destination)
- m->destination = destination;
- else if (k->dst_id != KDBUS_DST_ID_NAME &&
- k->dst_id != KDBUS_DST_ID_BROADCAST) {
- snprintf(m->destination_buffer, sizeof(m->destination_buffer), ":1.%llu", (unsigned long long) k->dst_id);
- m->destination = m->destination_buffer;
- }
+ if (destination)
+ m->destination = destination;
+ else if (k->dst_id == KDBUS_DST_ID_BROADCAST)
+ m->destination = NULL;
+ else if (k->dst_id == KDBUS_DST_ID_NAME)
+ m->destination = bus->unique_name; /* fill in unique name if the well-known name is missing */
+ else {
+ snprintf(m->destination_buffer, sizeof(m->destination_buffer), ":1.%llu", (unsigned long long) k->dst_id);
+ m->destination = m->destination_buffer;
}
/* We take possession of the kmsg struct now */
commit 253ce82b643569564ca8f5730e728f41fcf23d08
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 03:16:39 2013 +0100
bus: always consider well-known names sender credentials as attached to messages
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 2802187..5913d42 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -693,6 +693,13 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
if (r < 0)
return r;
+ /* The well-known names list is different from the other
+ credentials. If we asked for it, but nothing is there, this
+ means that the list of well-known names is simply empty, not
+ that we lack any data */
+
+ m->creds.mask |= (SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_WELL_KNOWN_NAMES) & bus->creds_mask;
+
KDBUS_ITEM_FOREACH(d, k, items) {
size_t l;
@@ -818,7 +825,6 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
r = strv_extend(&m->creds.well_known_names, d->name.name);
if (r < 0)
goto fail;
- m->creds.mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES & bus->creds_mask;
break;
case KDBUS_ITEM_FDS:
@@ -836,11 +842,10 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
/* Override information from the user header with data from the kernel */
if (k->src_id == KDBUS_SRC_ID_KERNEL)
- m->sender = "org.freedesktop.DBus";
+ m->sender = m->creds.unique_name = (char*) "org.freedesktop.DBus";
else {
snprintf(m->sender_buffer, sizeof(m->sender_buffer), ":1.%llu", (unsigned long long) k->src_id);
m->sender = m->creds.unique_name = m->sender_buffer;
- m->creds.mask |= SD_BUS_CREDS_UNIQUE_NAME & bus->creds_mask;
}
if (!m->destination) {
commit 06100c7a1ea503b33708120b09dac95de3264fd5
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 02:56:34 2013 +0100
bus: when filtering by sender take well known names lest from attached creds into account
diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c
index 7638f20..34488d8 100644
--- a/src/libsystemd-bus/bus-match.c
+++ b/src/libsystemd-bus/bus-match.c
@@ -24,6 +24,7 @@
#include "bus-match.h"
#include "bus-error.h"
#include "bus-util.h"
+#include "strv.h"
/* Example:
*
@@ -129,7 +130,8 @@ static bool value_node_test(
struct bus_match_node *node,
enum bus_match_node_type parent_type,
uint8_t value_u8,
- const char *value_str) {
+ const char *value_str,
+ sd_bus_message *m) {
assert(node);
assert(node->type == BUS_MATCH_VALUE);
@@ -143,23 +145,34 @@ static bool value_node_test(
return node->value.u8 == value_u8;
case BUS_MATCH_SENDER:
- case BUS_MATCH_DESTINATION:
if (streq_ptr(node->value.str, value_str))
return true;
- /* FIXME: So here's an ugliness: if the match is for a
- * well-known name then we cannot actually check this
- * correctly here. This doesn't matter much for dbus1
- * where no false positives exist, hence we just
- * ignore this case here. For kdbus the messages
- * should contain all well-known names of the sender,
- * hence we can fix things there correctly. */
+ if (m->creds.mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) {
+ char **i;
- if (node->value.str[0] != ':' && value_str && value_str[0] == ':')
- return true;
+ /* on kdbus we have the well known names list
+ * in the credentials, let's make use of that
+ * for an accurate match */
+
+ STRV_FOREACH(i, m->creds.well_known_names)
+ if (streq_ptr(node->value.str, *i))
+ return true;
+
+ } else {
+
+ /* If we don't have kdbus, we don't know the
+ * well-known names of the senders. In that,
+ * let's just hope that dbus-daemon doesn't
+ * send us stuff we didn't want. */
+
+ if (node->value.str[0] != ':' && value_str && value_str[0] == ':')
+ return true;
+ }
return false;
+ case BUS_MATCH_DESTINATION:
case BUS_MATCH_INTERFACE:
case BUS_MATCH_MEMBER:
case BUS_MATCH_PATH:
@@ -349,7 +362,7 @@ int bus_match_run(
/* No hash table, so let's iterate manually... */
for (c = node->child; c; c = c->next) {
- if (!value_node_test(c, node->type, test_u8, test_str))
+ if (!value_node_test(c, node->type, test_u8, test_str, m))
continue;
r = bus_match_run(bus, c, m);
commit 27fc65e14d56a92f2d6615c0a0c8ec2f45401193
Author: Lennart Poettering <lennart at poettering.net>
Date: Sat Dec 21 02:40:40 2013 +0100
core: make check for Disconnected message more precise
diff --git a/src/core/dbus.c b/src/core/dbus.c
index ccbbc34..967f991 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -623,6 +623,7 @@ static int bus_setup_disconnected_match(Manager *m, sd_bus *bus) {
r = sd_bus_add_match(
bus,
+ "sender='org.freedesktop.DBus.Local',"
"type='signal',"
"path='/org/freedesktop/DBus/Local',"
"interface='org.freedesktop.DBus.Local',"
More information about the systemd-commits
mailing list