summaryrefslogtreecommitdiff
path: root/src/libsystemd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsystemd')
-rw-r--r--src/libsystemd/libsystemd.sym.m44
-rw-r--r--src/libsystemd/sd-bus/bus-creds.c3
-rw-r--r--src/libsystemd/sd-bus/bus-kernel.c9
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c42
-rw-r--r--src/libsystemd/sd-bus/sd-memfd.c7
-rw-r--r--src/libsystemd/sd-bus/test-bus-marshal.c25
6 files changed, 73 insertions, 17 deletions
diff --git a/src/libsystemd/libsystemd.sym.m4 b/src/libsystemd/libsystemd.sym.m4
index c708c7f38f..9c29169e7c 100644
--- a/src/libsystemd/libsystemd.sym.m4
+++ b/src/libsystemd/libsystemd.sym.m4
@@ -311,8 +311,8 @@ m4_ifdef(`ENABLE_KDBUS',
sd_bus_error_copy;
sd_bus_error_is_set;
sd_bus_error_has_name;
- sd_bus_label_escape;
- sd_bus_label_unescape;
+ sd_bus_path_encode;
+ sd_bus_path_decode;
sd_bus_track_new;
sd_bus_track_ref;
sd_bus_track_unref;
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index 2d56f3c461..3da77cf1d7 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -30,6 +30,7 @@
#include "time-util.h"
#include "strv.h"
#include "bus-creds.h"
+#include "bus-label.h"
enum {
CAP_OFFSET_INHERITABLE = 0,
@@ -474,7 +475,7 @@ _public_ int sd_bus_creds_get_connection_name(sd_bus_creds *c, const char **ret)
assert(c->conn_name);
if (!c->unescaped_conn_name) {
- c->unescaped_conn_name = sd_bus_label_unescape(c->conn_name);
+ c->unescaped_conn_name = bus_label_unescape(c->conn_name);
if (!c->unescaped_conn_name)
return -ENOMEM;
}
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 2a1b0b424a..8a2ca02996 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -36,6 +36,7 @@
#include "bus-kernel.h"
#include "bus-bloom.h"
#include "bus-util.h"
+#include "bus-label.h"
#include "cgroup-util.h"
#define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
@@ -658,7 +659,7 @@ int bus_kernel_take_fd(sd_bus *b) {
b->use_memfd = 1;
if (b->connection_name) {
- g = sd_bus_label_escape(b->connection_name);
+ g = bus_label_escape(b->connection_name);
if (!g)
return -ENOMEM;
@@ -678,7 +679,7 @@ int bus_kernel_take_fd(sd_bus *b) {
} else {
_cleanup_free_ char *e = NULL;
- e = sd_bus_label_escape(pr);
+ e = bus_label_escape(pr);
if (!e)
return -ENOMEM;
@@ -691,7 +692,7 @@ int bus_kernel_take_fd(sd_bus *b) {
name = g;
}
- b->connection_name = sd_bus_label_unescape(name);
+ b->connection_name = bus_label_unescape(name);
if (!b->connection_name)
return -ENOMEM;
}
@@ -1119,7 +1120,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *al
assert(bus->connection_name);
- g = sd_bus_label_escape(bus->connection_name);
+ g = bus_label_escape(bus->connection_name);
if (!g)
return -ENOMEM;
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index fbf1a5919f..ffa3369feb 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -3063,12 +3063,46 @@ _public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) {
return -ENXIO;
}
-_public_ char *sd_bus_label_escape(const char *s) {
- return bus_label_escape(s);
+_public_ int sd_bus_path_encode(const char *prefix, const char *external_id, char **ret_path) {
+ _cleanup_free_ char *e = NULL;
+ char *ret;
+
+ assert_return(object_path_is_valid(prefix), -EINVAL);
+ assert_return(external_id, -EINVAL);
+ assert_return(ret_path, -EINVAL);
+
+ e = bus_label_escape(external_id);
+ if (!e)
+ return -ENOMEM;
+
+ ret = strjoin(prefix, "/", e, NULL);
+ if (!ret)
+ return -ENOMEM;
+
+ *ret_path = ret;
+ return 0;
}
-_public_ char *sd_bus_label_unescape(const char *f) {
- return bus_label_unescape(f);
+_public_ int sd_bus_path_decode(const char *path, const char *prefix, char **external_id) {
+ const char *e;
+ char *ret;
+
+ assert_return(object_path_is_valid(path), -EINVAL);
+ assert_return(object_path_is_valid(prefix), -EINVAL);
+ assert_return(external_id, -EINVAL);
+
+ e = object_path_startswith(path, prefix);
+ if (!e) {
+ *external_id = NULL;
+ return 0;
+ }
+
+ ret = bus_label_unescape(e);
+ if (!ret)
+ return -ENOMEM;
+
+ *external_id = ret;
+ return 1;
}
_public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
diff --git a/src/libsystemd/sd-bus/sd-memfd.c b/src/libsystemd/sd-bus/sd-memfd.c
index 7c71476eee..8f9e236392 100644
--- a/src/libsystemd/sd-bus/sd-memfd.c
+++ b/src/libsystemd/sd-bus/sd-memfd.c
@@ -27,6 +27,7 @@
#include "util.h"
#include "kdbus.h"
+#include "bus-label.h"
#include "sd-memfd.h"
#include "sd-bus.h"
@@ -56,7 +57,7 @@ _public_ int sd_memfd_new(sd_memfd **m, const char *name) {
* set here, let's do the usual bus escaping to deal
* with that. */
- g = sd_bus_label_escape(name);
+ g = bus_label_escape(name);
if (!g)
return -ENOMEM;
@@ -76,7 +77,7 @@ _public_ int sd_memfd_new(sd_memfd **m, const char *name) {
else {
_cleanup_free_ char *e = NULL;
- e = sd_bus_label_escape(pr);
+ e = bus_label_escape(pr);
if (!e)
return -ENOMEM;
@@ -311,7 +312,7 @@ _public_ int sd_memfd_get_name(sd_memfd *m, char **name) {
if (!n)
return -ENOMEM;
- e = sd_bus_label_unescape(n);
+ e = bus_label_unescape(n);
if (!e)
return -ENOMEM;
diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c
index d438a231a6..2321873da5 100644
--- a/src/libsystemd/sd-bus/test-bus-marshal.c
+++ b/src/libsystemd/sd-bus/test-bus-marshal.c
@@ -38,17 +38,35 @@
#include "bus-message.h"
#include "bus-util.h"
#include "bus-dump.h"
+#include "bus-label.h"
+
+static void test_bus_path_encode(void) {
+ _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL;
+
+ assert_se(sd_bus_path_encode("/foo/bar", "waldo", &a) >= 0 && streq(a, "/foo/bar/waldo"));
+ assert_se(sd_bus_path_decode(a, "/waldo", &b) == 0 && b == NULL);
+ assert_se(sd_bus_path_decode(a, "/foo/bar", &b) > 0 && streq(b, "waldo"));
+
+ assert_se(sd_bus_path_encode("xxxx", "waldo", &c) < 0);
+ assert_se(sd_bus_path_encode("/foo/", "waldo", &c) < 0);
+
+ assert_se(sd_bus_path_encode("/foo/bar", "", &c) >= 0 && streq(c, "/foo/bar/_"));
+ assert_se(sd_bus_path_decode(c, "/foo/bar", &d) > 0 && streq(d, ""));
+
+ assert_se(sd_bus_path_encode("/foo/bar", "foo.bar", &e) >= 0 && streq(e, "/foo/bar/foo_2ebar"));
+ assert_se(sd_bus_path_decode(e, "/foo/bar", &f) > 0 && streq(f, "foo.bar"));
+}
static void test_bus_label_escape_one(const char *a, const char *b) {
_cleanup_free_ char *t = NULL, *x = NULL, *y = NULL;
- assert_se(t = sd_bus_label_escape(a));
+ assert_se(t = bus_label_escape(a));
assert_se(streq(t, b));
- assert_se(x = sd_bus_label_unescape(t));
+ assert_se(x = bus_label_unescape(t));
assert_se(streq(a, x));
- assert_se(y = sd_bus_label_unescape(b));
+ assert_se(y = bus_label_unescape(b));
assert_se(streq(a, y));
}
@@ -322,6 +340,7 @@ int main(int argc, char *argv[]) {
assert_se(streq(d, "3"));
test_bus_label_escape();
+ test_bus_path_encode();
return 0;
}