summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/bus-match.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-06-17 11:42:39 +0200
committerLennart Poettering <lennart@poettering.net>2015-06-17 11:42:39 +0200
commitcc65fe5e14770d0116e0f475c5dc2ef57113bc98 (patch)
tree90a3ea575e749110fb7273d99b13896fedc823c6 /src/libsystemd/sd-bus/bus-match.c
parent3eb3228e583e7e07dc3f2d17ea02dcb06f30fcc0 (diff)
sd-bus: suppress installing local bus matches server side
Matches that can only match against messages from the org.freedesktop.DBus.Local service (or the local interfaces or path) should never be installed server side, suppress them hence. Similar, on kdbus matches that can only match driver messages shouldn't be passed to the kernel.
Diffstat (limited to 'src/libsystemd/sd-bus/bus-match.c')
-rw-r--r--src/libsystemd/sd-bus/bus-match.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c
index 7c5264fad4..132b37526e 100644
--- a/src/libsystemd/sd-bus/bus-match.c
+++ b/src/libsystemd/sd-bus/bus-match.c
@@ -1149,3 +1149,40 @@ void bus_match_dump(struct bus_match_node *node, unsigned level) {
for (c = node->child; c; c = c->next)
bus_match_dump(c, level + 1);
}
+
+enum bus_match_scope bus_match_get_scope(const struct bus_match_component *components, unsigned n_components) {
+ bool found_driver = false;
+ unsigned i;
+
+ if (n_components <= 0)
+ return BUS_MATCH_GENERIC;
+
+ assert(components);
+
+ /* Checks whether the specified match can only match the
+ * pseudo-service for local messages, which we detect by
+ * sender, interface or path. If a match is not restricted to
+ * local messages, then we check if it only matches on the
+ * driver. */
+
+ for (i = 0; i < n_components; i++) {
+ const struct bus_match_component *c = components + i;
+
+ if (c->type == BUS_MATCH_SENDER) {
+ if (streq_ptr(c->value_str, "org.freedesktop.DBus.Local"))
+ return BUS_MATCH_LOCAL;
+
+ if (streq_ptr(c->value_str, "org.freedesktop.DBus"))
+ found_driver = true;
+ }
+
+ if (c->type == BUS_MATCH_INTERFACE && streq_ptr(c->value_str, "org.freedesktop.DBus.Local"))
+ return BUS_MATCH_LOCAL;
+
+ if (c->type == BUS_MATCH_PATH && streq_ptr(c->value_str, "/org/freedesktop/DBus/Local"))
+ return BUS_MATCH_LOCAL;
+ }
+
+ return found_driver ? BUS_MATCH_DRIVER : BUS_MATCH_GENERIC;
+
+}