[systemd-commits] 4 commits - man/sd_bus_creds_get_pid.xml src/bus-proxyd src/core src/libsystemd src/systemd
Daniel Mack
zonque at kemper.freedesktop.org
Wed Oct 22 10:45:19 PDT 2014
man/sd_bus_creds_get_pid.xml | 4
src/bus-proxyd/bus-proxyd.c | 10 -
src/core/service.c | 2
src/libsystemd/libsystemd.sym.m4 | 6
src/libsystemd/sd-bus/bus-control.c | 269 +++++++++++++++++++-------------
src/libsystemd/sd-bus/bus-convenience.c | 4
src/libsystemd/sd-bus/bus-track.c | 2
src/libsystemd/sd-bus/busctl.c | 6
src/libsystemd/sd-bus/kdbus.h | 18 +-
src/libsystemd/sd-bus/sd-bus.c | 51 ------
src/systemd/sd-bus.h | 6
11 files changed, 197 insertions(+), 181 deletions(-)
New commits:
commit 8f44e3ea3e0821625e584938e54623e7fb381bb8
Author: Daniel Mack <daniel at zonque.org>
Date: Wed Oct 22 19:43:09 2014 +0200
sd-bus: implement sd_bus_get_owner_creds() for kdbus
kdbus learned a new ioctl to tell userspace about a bus creator's
credentials, which is what we need to implement sd_bus_get_owner_creds() for
kdbus.
Move the function from sd-bus.c to bus-control.c to be able to reuse
the bus_populate_creds_from_items() helper.
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 96f59f9..a84b060 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -796,6 +796,72 @@ _public_ int sd_bus_get_name_creds(
return bus_get_name_creds_dbus1(bus, name, mask, creds);
}
+_public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
+ _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
+ pid_t pid = 0;
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP);
+ assert_return(ret, -EINVAL);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+
+ if (!BUS_IS_OPEN(bus->state))
+ return -ENOTCONN;
+
+ if (!bus->ucred_valid && !isempty(bus->label))
+ return -ENODATA;
+
+ c = bus_creds_new();
+ if (!c)
+ return -ENOMEM;
+
+ if (bus->ucred_valid) {
+ pid = c->pid = bus->ucred.pid;
+ c->uid = bus->ucred.uid;
+ c->gid = bus->ucred.gid;
+
+ c->mask |= (SD_BUS_CREDS_UID | SD_BUS_CREDS_PID | SD_BUS_CREDS_GID) & mask;
+ }
+
+ if (!isempty(bus->label) && (mask & SD_BUS_CREDS_SELINUX_CONTEXT)) {
+ c->label = strdup(bus->label);
+ if (!c->label) {
+ sd_bus_creds_unref(c);
+ return -ENOMEM;
+ }
+
+ c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
+ }
+
+ if (bus->is_kernel) {
+ struct kdbus_cmd_info cmd = {};
+ struct kdbus_info *creator_info;
+
+ cmd.size = sizeof(cmd);
+ r = ioctl(bus->input_fd, KDBUS_CMD_BUS_CREATOR_INFO, &cmd);
+ if (r < 0)
+ return -errno;
+
+ creator_info = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd.offset);
+
+ r = bus_populate_creds_from_items(bus, creator_info, mask, c);
+ kernel_cmd_free(bus, cmd.offset);
+
+ if (r < 0)
+ return r;
+ } else {
+ r = bus_creds_add_more(c, mask, pid, 0);
+ if (r < 0) {
+ sd_bus_creds_unref(c);
+ return r;
+ }
+ }
+
+ *ret = c;
+ return 0;
+}
+
static int add_name_change_match(sd_bus *bus,
uint64_t cookie,
const char *name,
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 9ec1565..f379617 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -3300,57 +3300,6 @@ _public_ int sd_bus_path_decode(const char *path, const char *prefix, char **ext
return 1;
}
-_public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
- sd_bus_creds *c;
- pid_t pid = 0;
- int r;
-
- assert_return(bus, -EINVAL);
- assert_return(mask <= _SD_BUS_CREDS_ALL, -ENOTSUP);
- assert_return(ret, -EINVAL);
- assert_return(!bus_pid_changed(bus), -ECHILD);
-
- if (bus->is_kernel)
- return -ENOTSUP;
-
- if (!BUS_IS_OPEN(bus->state))
- return -ENOTCONN;
-
- if (!bus->ucred_valid && !isempty(bus->label))
- return -ENODATA;
-
- c = bus_creds_new();
- if (!c)
- return -ENOMEM;
-
- if (bus->ucred_valid) {
- pid = c->pid = bus->ucred.pid;
- c->uid = bus->ucred.uid;
- c->gid = bus->ucred.gid;
-
- c->mask |= (SD_BUS_CREDS_UID | SD_BUS_CREDS_PID | SD_BUS_CREDS_GID) & mask;
- }
-
- if (!isempty(bus->label) && (mask & SD_BUS_CREDS_SELINUX_CONTEXT)) {
- c->label = strdup(bus->label);
- if (!c->label) {
- sd_bus_creds_unref(c);
- return -ENOMEM;
- }
-
- c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
- }
-
- r = bus_creds_add_more(c, mask, pid, 0);
- if (r < 0) {
- sd_bus_creds_unref(c);
- return r;
- }
-
- *ret = c;
- return 0;
-}
-
_public_ int sd_bus_try_close(sd_bus *bus) {
int r;
commit 056f95d0a70413e10e4a4ea9966baabb5a1450ed
Author: Daniel Mack <daniel at zonque.org>
Date: Wed Oct 22 19:17:24 2014 +0200
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()
diff --git a/man/sd_bus_creds_get_pid.xml b/man/sd_bus_creds_get_pid.xml
index cc8603c..23763bd 100644
--- a/man/sd_bus_creds_get_pid.xml
+++ b/man/sd_bus_creds_get_pid.xml
@@ -237,7 +237,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<citerefentry><refentrytitle>sd_bus_creds_new_from_pid</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
in which case it will describe the specified process, or it may be
created by
- <citerefentry><refentrytitle>sd_bus_get_peer_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+ <citerefentry><refentrytitle>sd_bus_get_owner_creds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
in which case it will describe the process at the other endpoint
of a connection.
</para>
@@ -410,7 +410,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
<function>sd_bus_get_user_unit()</function>,
<function>sd_bus_get_slice()</function>,
<function>sd_bus_get_session()</function>, and
- <function>sd_bus_get_owner_uid()</function> if the sender is not
+ <function>sd_bus_get_name_creds_uid()</function> if the sender is not
part of a systemd system unit, systemd user unit, systemd
slice, logind session, or a systemd user session.</para>
</listitem>
diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c
index a9f64da..11d0e28 100644
--- a/src/bus-proxyd/bus-proxyd.c
+++ b/src/bus-proxyd/bus-proxyd.c
@@ -186,7 +186,7 @@ static int rename_service(sd_bus *a, sd_bus *b) {
assert(a);
assert(b);
- r = sd_bus_get_peer_creds(b, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_CMDLINE|SD_BUS_CREDS_COMM, &creds);
+ r = sd_bus_get_owner_creds(b, SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_CMDLINE|SD_BUS_CREDS_COMM, &creds);
if (r < 0)
return r;
@@ -454,7 +454,7 @@ static int get_creds_by_name(sd_bus *bus, const char *name, uint64_t mask, sd_bu
assert_return(service_name_is_valid(name), -EINVAL);
- r = sd_bus_get_owner(bus, name, mask, &c);
+ r = sd_bus_get_name_creds(bus, name, mask, &c);
if (r == -ESRCH || r == -ENXIO)
return sd_bus_error_setf(error, SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Name %s is currently not owned by anyone.", name);
if (r < 0)
@@ -747,7 +747,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
if (!service_name_is_valid(arg0))
return synthetic_reply_method_errno(m, -EINVAL, NULL);
- r = sd_bus_get_owner(a, arg0, 0, NULL);
+ r = sd_bus_get_name_creds(a, arg0, 0, NULL);
if (r == -ESRCH || r == -ENXIO) {
sd_bus_error_setf(&error, SD_BUS_ERROR_NAME_HAS_NO_OWNER, "Could not get owners of name '%s': no such name.", arg0);
return synthetic_reply_method_errno(m, r, &error);
@@ -811,7 +811,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
if (streq(name, "org.freedesktop.DBus"))
return synthetic_reply_method_return(m, "b", true);
- r = sd_bus_get_owner(a, name, 0, NULL);
+ r = sd_bus_get_name_creds(a, name, 0, NULL);
if (r < 0 && r != -ESRCH && r != -ENXIO)
return synthetic_reply_method_errno(m, r, NULL);
@@ -895,7 +895,7 @@ static int process_driver(sd_bus *a, sd_bus *b, sd_bus_message *m) {
if (flags != 0)
return synthetic_reply_method_errno(m, -EINVAL, NULL);
- r = sd_bus_get_owner(a, name, 0, NULL);
+ r = sd_bus_get_name_creds(a, name, 0, NULL);
if (r >= 0 || streq(name, "org.freedesktop.DBus"))
return synthetic_reply_method_return(m, "u", BUS_START_REPLY_ALREADY_RUNNING);
if (r != -ESRCH)
diff --git a/src/core/service.c b/src/core/service.c
index 7676344..d160c4e 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -2729,7 +2729,7 @@ static void service_bus_name_owner_change(
/* Try to acquire PID from bus service */
- r = sd_bus_get_owner(u->manager->api_bus, name, SD_BUS_CREDS_PID, &creds);
+ r = sd_bus_get_name_creds(u->manager->api_bus, name, SD_BUS_CREDS_PID, &creds);
if (r >= 0)
r = sd_bus_creds_get_pid(creds, &pid);
if (r >= 0) {
diff --git a/src/libsystemd/libsystemd.sym.m4 b/src/libsystemd/libsystemd.sym.m4
index 87da7ac..ab11448 100644
--- a/src/libsystemd/libsystemd.sym.m4
+++ b/src/libsystemd/libsystemd.sym.m4
@@ -191,7 +191,7 @@ global:
sd_bus_is_open;
sd_bus_can_send;
sd_bus_get_server_id;
- sd_bus_get_peer_creds;
+ sd_bus_get_owner_creds;
sd_bus_get_name;
sd_bus_send;
sd_bus_send_to;
@@ -287,8 +287,8 @@ global:
sd_bus_request_name;
sd_bus_release_name;
sd_bus_list_names;
- sd_bus_get_owner;
- sd_bus_get_owner_machine_id;
+ sd_bus_get_name_creds;
+ sd_bus_get_name_machine_id;
sd_bus_call_method;
sd_bus_get_property;
sd_bus_get_property_trivial;
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index b666067..96f59f9 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -549,7 +549,7 @@ static int bus_populate_creds_from_items(sd_bus *bus,
return 0;
}
-static int bus_get_owner_kdbus(
+static int bus_get_name_creds_kdbus(
sd_bus *bus,
const char *name,
uint64_t mask,
@@ -627,7 +627,7 @@ fail:
return r;
}
-static int bus_get_owner_dbus1(
+static int bus_get_name_creds_dbus1(
sd_bus *bus,
const char *name,
uint64_t mask,
@@ -773,7 +773,7 @@ static int bus_get_owner_dbus1(
return 0;
}
-_public_ int sd_bus_get_owner(
+_public_ int sd_bus_get_name_creds(
sd_bus *bus,
const char *name,
uint64_t mask,
@@ -791,9 +791,9 @@ _public_ int sd_bus_get_owner(
return -ENOTCONN;
if (bus->is_kernel)
- return bus_get_owner_kdbus(bus, name, mask, creds);
+ return bus_get_name_creds_kdbus(bus, name, mask, creds);
else
- return bus_get_owner_dbus1(bus, name, mask, creds);
+ return bus_get_name_creds_dbus1(bus, name, mask, creds);
}
static int add_name_change_match(sd_bus *bus,
@@ -1245,7 +1245,7 @@ int bus_remove_match_internal(
return bus_remove_match_internal_dbus1(bus, match);
}
-_public_ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
+_public_ int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
const char *mid;
int r;
diff --git a/src/libsystemd/sd-bus/bus-convenience.c b/src/libsystemd/sd-bus/bus-convenience.c
index f88836b..8081a2f 100644
--- a/src/libsystemd/sd-bus/bus-convenience.c
+++ b/src/libsystemd/sd-bus/bus-convenience.c
@@ -465,9 +465,9 @@ _public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_b
* to get it from the sender or peer */
if (call->sender)
- return sd_bus_get_owner(call->bus, call->sender, mask, creds);
+ return sd_bus_get_name_creds(call->bus, call->sender, mask, creds);
else
- return sd_bus_get_peer_creds(call->bus, mask, creds);
+ return sd_bus_get_owner_creds(call->bus, mask, creds);
}
return bus_creds_extend_by_pid(c, mask, creds);
diff --git a/src/libsystemd/sd-bus/bus-track.c b/src/libsystemd/sd-bus/bus-track.c
index 4b6a8bf..f3b593d 100644
--- a/src/libsystemd/sd-bus/bus-track.c
+++ b/src/libsystemd/sd-bus/bus-track.c
@@ -188,7 +188,7 @@ _public_ int sd_bus_track_add_name(sd_bus_track *track, const char *name) {
/* Second, check if it is currently existing, or maybe
* doesn't, or maybe disappeared already. */
- r = sd_bus_get_owner(track->bus, n, 0, NULL);
+ r = sd_bus_get_name_creds(track->bus, n, 0, NULL);
if (r < 0) {
hashmap_remove(track->names, n);
return r;
diff --git a/src/libsystemd/sd-bus/busctl.c b/src/libsystemd/sd-bus/busctl.c
index f06b745..fdc275c 100644
--- a/src/libsystemd/sd-bus/busctl.c
+++ b/src/libsystemd/sd-bus/busctl.c
@@ -142,7 +142,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
printf("%-*s", (int) max_i, *i);
- r = sd_bus_get_owner(bus, *i,
+ r = sd_bus_get_name_creds(bus, *i,
SD_BUS_CREDS_UID|SD_BUS_CREDS_PID|SD_BUS_CREDS_COMM|
SD_BUS_CREDS_UNIQUE_NAME|SD_BUS_CREDS_UNIT|SD_BUS_CREDS_SESSION|
SD_BUS_CREDS_CONNECTION_NAME, &creds);
@@ -210,7 +210,7 @@ static int list_bus_names(sd_bus *bus, char **argv) {
printf(" - - - - - - - ");
if (arg_show_machine) {
- r = sd_bus_get_owner_machine_id(bus, *i, &mid);
+ r = sd_bus_get_name_machine_id(bus, *i, &mid);
if (r >= 0) {
char m[SD_ID128_STRING_MAX];
printf(" %s\n", sd_id128_to_string(mid, m));
@@ -306,7 +306,7 @@ static int status(sd_bus *bus, char *argv[]) {
r = parse_pid(argv[1], &pid);
if (r < 0)
- r = sd_bus_get_owner(bus, argv[1], _SD_BUS_CREDS_ALL, &creds);
+ r = sd_bus_get_name_creds(bus, argv[1], _SD_BUS_CREDS_ALL, &creds);
else
r = sd_bus_creds_new_from_pid(&creds, pid, _SD_BUS_CREDS_ALL);
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 549f9e0..9ec1565 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -3300,7 +3300,7 @@ _public_ int sd_bus_path_decode(const char *path, const char *prefix, char **ext
return 1;
}
-_public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
+_public_ int sd_bus_get_owner_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
sd_bus_creds *c;
pid_t pid = 0;
int r;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 9d13e94..18acfc2 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -131,7 +131,7 @@ sd_bus *sd_bus_unref(sd_bus *bus);
int sd_bus_is_open(sd_bus *bus);
int sd_bus_can_send(sd_bus *bus, char type);
int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *peer);
-int sd_bus_get_peer_creds(sd_bus *bus, uint64_t creds_mask, sd_bus_creds **ret);
+int sd_bus_get_owner_creds(sd_bus *bus, uint64_t creds_mask, sd_bus_creds **ret);
int sd_bus_get_name(sd_bus *bus, const char **name);
int sd_bus_get_tid(sd_bus *bus, pid_t *tid);
@@ -260,8 +260,8 @@ int sd_bus_get_unique_name(sd_bus *bus, const char **unique);
int sd_bus_request_name(sd_bus *bus, const char *name, uint64_t flags);
int sd_bus_release_name(sd_bus *bus, const char *name);
int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatable); /* free the results */
-int sd_bus_get_owner(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **creds); /* unref the result! */
-int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine);
+int sd_bus_get_name_creds(sd_bus *bus, const char *name, uint64_t mask, sd_bus_creds **creds); /* unref the result! */
+int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine);
/* Convenience calls */
commit 370d7a9c0fe558c5846a2abd919e397639b69506
Author: Daniel Mack <daniel at zonque.org>
Date: Wed Oct 22 19:04:27 2014 +0200
sd-bus: factor out creds item iterator
We will re-use the code to walk items in order to populate a creds object,
so let's factor it out first.
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index d344387..b666067 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -392,70 +392,16 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***acquired, char ***activatabl
return bus_list_names_dbus1(bus, acquired, activatable);
}
-static int bus_get_owner_kdbus(
- sd_bus *bus,
- const char *name,
- uint64_t mask,
- sd_bus_creds **creds) {
+static int bus_populate_creds_from_items(sd_bus *bus,
+ struct kdbus_info *info,
+ uint64_t mask,
+ sd_bus_creds *c) {
- _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
- struct kdbus_cmd_info *cmd;
- struct kdbus_info *conn_info;
struct kdbus_item *item;
- size_t size, l;
- uint64_t m, id;
+ uint64_t m;
int r;
- r = bus_kernel_parse_unique_name(name, &id);
- if (r < 0)
- return r;
- if (r > 0) {
- size = offsetof(struct kdbus_cmd_info, items);
- cmd = alloca0_align(size, 8);
- cmd->id = id;
- } else {
- l = strlen(name) + 1;
- size = offsetof(struct kdbus_cmd_info, items) + KDBUS_ITEM_SIZE(l);
- cmd = alloca0_align(size, 8);
- cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
- cmd->items[0].type = KDBUS_ITEM_NAME;
- memcpy(cmd->items[0].str, name, l);
- }
-
- cmd->size = size;
- kdbus_translate_attach_flags(mask, (uint64_t*) &cmd->flags);
-
- r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
- if (r < 0)
- return -errno;
-
- conn_info = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
-
- /* Non-activated names are considered not available */
- if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
- if (name[0] == ':')
- r = -ENXIO;
- else
- r = -ESRCH;
- goto fail;
- }
-
- c = bus_creds_new();
- if (!c) {
- r = -ENOMEM;
- goto fail;
- }
-
- if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
- if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0) {
- r = -ENOMEM;
- goto fail;
- }
-
- c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
- }
-
- KDBUS_ITEM_FOREACH(item, conn_info, items) {
+ KDBUS_ITEM_FOREACH(item, info, items) {
switch (item->type) {
@@ -484,10 +430,8 @@ static int bus_get_owner_kdbus(
case KDBUS_ITEM_PID_COMM:
if (mask & SD_BUS_CREDS_COMM) {
c->comm = strdup(item->str);
- if (!c->comm) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->comm)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_COMM;
}
@@ -496,10 +440,8 @@ static int bus_get_owner_kdbus(
case KDBUS_ITEM_TID_COMM:
if (mask & SD_BUS_CREDS_TID_COMM) {
c->tid_comm = strdup(item->str);
- if (!c->tid_comm) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->tid_comm)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_TID_COMM;
}
@@ -508,10 +450,8 @@ static int bus_get_owner_kdbus(
case KDBUS_ITEM_EXE:
if (mask & SD_BUS_CREDS_EXE) {
c->exe = strdup(item->str);
- if (!c->exe) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->exe)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_EXE;
}
@@ -521,10 +461,8 @@ static int bus_get_owner_kdbus(
if (mask & SD_BUS_CREDS_CMDLINE) {
c->cmdline_size = item->size - KDBUS_ITEM_HEADER_SIZE;
c->cmdline = memdup(item->data, c->cmdline_size);
- if (!c->cmdline) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->cmdline)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_CMDLINE;
}
@@ -537,20 +475,16 @@ static int bus_get_owner_kdbus(
if (m) {
c->cgroup = strdup(item->str);
- if (!c->cgroup) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->cgroup)
+ return -ENOMEM;
r = bus_get_root_path(bus);
if (r < 0)
- goto fail;
+ return r;
c->cgroup_root = strdup(bus->cgroup_root);
- if (!c->cgroup_root) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->cgroup_root)
+ return -ENOMEM;
c->mask |= m;
}
@@ -563,10 +497,8 @@ static int bus_get_owner_kdbus(
if (m) {
c->capability_size = item->size - KDBUS_ITEM_HEADER_SIZE;
c->capability = memdup(item->data, c->capability_size);
- if (!c->capability) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->capability)
+ return -ENOMEM;
c->mask |= m;
}
@@ -575,10 +507,8 @@ static int bus_get_owner_kdbus(
case KDBUS_ITEM_SECLABEL:
if (mask & SD_BUS_CREDS_SELINUX_CONTEXT) {
c->label = strdup(item->str);
- if (!c->label) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->label)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_SELINUX_CONTEXT;
}
@@ -598,7 +528,7 @@ static int bus_get_owner_kdbus(
if ((mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) && service_name_is_valid(item->name.name)) {
r = strv_extend(&c->well_known_names, item->name.name);
if (r < 0)
- goto fail;
+ return r;
c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES;
}
@@ -607,10 +537,8 @@ static int bus_get_owner_kdbus(
case KDBUS_ITEM_CONN_NAME:
if ((mask & SD_BUS_CREDS_CONNECTION_NAME)) {
c->conn_name = strdup(item->str);
- if (!c->conn_name) {
- r = -ENOMEM;
- goto fail;
- }
+ if (!c->conn_name)
+ return -ENOMEM;
c->mask |= SD_BUS_CREDS_CONNECTION_NAME;
}
@@ -618,6 +546,75 @@ static int bus_get_owner_kdbus(
}
}
+ return 0;
+}
+
+static int bus_get_owner_kdbus(
+ sd_bus *bus,
+ const char *name,
+ uint64_t mask,
+ sd_bus_creds **creds) {
+
+ _cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
+ struct kdbus_cmd_info *cmd;
+ struct kdbus_info *conn_info;
+ size_t size, l;
+ uint64_t id;
+ int r;
+
+ r = bus_kernel_parse_unique_name(name, &id);
+ if (r < 0)
+ return r;
+ if (r > 0) {
+ size = offsetof(struct kdbus_cmd_info, items);
+ cmd = alloca0_align(size, 8);
+ cmd->id = id;
+ } else {
+ l = strlen(name) + 1;
+ size = offsetof(struct kdbus_cmd_info, items) + KDBUS_ITEM_SIZE(l);
+ cmd = alloca0_align(size, 8);
+ cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
+ cmd->items[0].type = KDBUS_ITEM_NAME;
+ memcpy(cmd->items[0].str, name, l);
+ }
+
+ cmd->size = size;
+ kdbus_translate_attach_flags(mask, (uint64_t*) &cmd->flags);
+
+ r = ioctl(bus->input_fd, KDBUS_CMD_CONN_INFO, cmd);
+ if (r < 0)
+ return -errno;
+
+ conn_info = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
+
+ /* Non-activated names are considered not available */
+ if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
+ if (name[0] == ':')
+ r = -ENXIO;
+ else
+ r = -ESRCH;
+ goto fail;
+ }
+
+ c = bus_creds_new();
+ if (!c) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ if (mask & SD_BUS_CREDS_UNIQUE_NAME) {
+ if (asprintf(&c->unique_name, ":1.%llu", (unsigned long long) conn_info->id) < 0) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
+ c->mask |= SD_BUS_CREDS_UNIQUE_NAME;
+ }
+
+ r = bus_populate_creds_from_items(bus, conn_info, mask, c);
+ if (r < 0)
+ goto fail;
+
if (creds) {
*creds = c;
c = NULL;
commit a1783d61a8a74dd91028cd065b8a23067419fe0a
Author: Daniel Mack <daniel at zonque.org>
Date: Wed Oct 22 18:44:40 2014 +0200
sd-bus: sync kdbus.h
kdbus learned a new command to query a bus creator's credentials. Sync
kdbus.h first, which also renames some struct to more generic terms.
That is, however, not an ABI break this time.
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 5ff746c..d344387 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -399,8 +399,8 @@ static int bus_get_owner_kdbus(
sd_bus_creds **creds) {
_cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
- struct kdbus_cmd_conn_info *cmd;
- struct kdbus_conn_info *conn_info;
+ struct kdbus_cmd_info *cmd;
+ struct kdbus_info *conn_info;
struct kdbus_item *item;
size_t size, l;
uint64_t m, id;
@@ -410,12 +410,12 @@ static int bus_get_owner_kdbus(
if (r < 0)
return r;
if (r > 0) {
- size = offsetof(struct kdbus_cmd_conn_info, items);
+ size = offsetof(struct kdbus_cmd_info, items);
cmd = alloca0_align(size, 8);
cmd->id = id;
} else {
l = strlen(name) + 1;
- size = offsetof(struct kdbus_cmd_conn_info, items) + KDBUS_ITEM_SIZE(l);
+ size = offsetof(struct kdbus_cmd_info, items) + KDBUS_ITEM_SIZE(l);
cmd = alloca0_align(size, 8);
cmd->items[0].size = KDBUS_ITEM_HEADER_SIZE + l;
cmd->items[0].type = KDBUS_ITEM_NAME;
@@ -429,7 +429,7 @@ static int bus_get_owner_kdbus(
if (r < 0)
return -errno;
- conn_info = (struct kdbus_conn_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
+ conn_info = (struct kdbus_info *) ((uint8_t *) bus->kdbus_buffer + cmd->offset);
/* Non-activated names are considered not available */
if (conn_info->flags & KDBUS_HELLO_ACTIVATOR) {
diff --git a/src/libsystemd/sd-bus/kdbus.h b/src/libsystemd/sd-bus/kdbus.h
index 50b4ec4..7a715a0 100644
--- a/src/libsystemd/sd-bus/kdbus.h
+++ b/src/libsystemd/sd-bus/kdbus.h
@@ -721,7 +721,7 @@ struct kdbus_name_list {
};
/**
- * struct kdbus_cmd_conn_info - struct used for KDBUS_CMD_CONN_INFO ioctl
+ * struct kdbus_cmd_info - struct used for KDBUS_CMD_CONN_INFO ioctl
* @size: The total size of the struct
* @flags: KDBUS_ATTACH_* flags, userspace â kernel
* @kernel_flags: Supported KDBUS_ATTACH_* flags, kernel â userspace
@@ -729,16 +729,16 @@ struct kdbus_name_list {
* @name is required. kdbus will look up the name to
* determine the ID in this case.
* @offset: Returned offset in the caller's pool buffer where the
- * kdbus_conn_info struct result is stored. The user must
+ * kdbus_info struct result is stored. The user must
* use KDBUS_CMD_FREE to free the allocated memory.
* @name: The optional well-known name to look up. Only needed in
* case @id is zero.
*
* On success, the KDBUS_CMD_CONN_INFO ioctl will return 0 and @offset will
* tell the user the offset in the connection pool buffer at which to find the
- * result in a struct kdbus_conn_info.
+ * result in a struct kdbus_info.
*/
-struct kdbus_cmd_conn_info {
+struct kdbus_cmd_info {
__u64 size;
__u64 flags;
__u64 kernel_flags;
@@ -748,7 +748,7 @@ struct kdbus_cmd_conn_info {
} __attribute__((aligned(8)));
/**
- * struct kdbus_conn_info - information returned by KDBUS_CMD_CONN_INFO
+ * struct kdbus_info - information returned by KDBUS_CMD_CONN_INFO
* @size: The total size of the struct
* @id: The connection's 64-bit ID
* @flags: The connection's flags
@@ -757,7 +757,7 @@ struct kdbus_cmd_conn_info {
* Note that the user is responsible for freeing the allocated memory with
* the KDBUS_CMD_FREE ioctl.
*/
-struct kdbus_conn_info {
+struct kdbus_info {
__u64 size;
__u64 id;
__u64 flags;
@@ -856,6 +856,8 @@ struct kdbus_cmd_match {
* @KDBUS_CMD_CONN_UPDATE: Update the properties of a connection. Used to
* update the metadata subscription mask and
* policy.
+ * @KDBUS_CMD_BUS_CREATOR_INFO: Retrieve information of the creator of the bus
+ * a connection is attached to.
* @KDBUS_CMD_ENDPOINT_UPDATE: Update the properties of a custom enpoint. Used
* to update the policy.
* @KDBUS_CMD_MATCH_ADD: Install a match which broadcast messages should
@@ -891,9 +893,11 @@ enum kdbus_ioctl_type {
struct kdbus_cmd_name_list),
KDBUS_CMD_CONN_INFO = _IOWR(KDBUS_IOCTL_MAGIC, 0x60,
- struct kdbus_cmd_conn_info),
+ struct kdbus_cmd_info),
KDBUS_CMD_CONN_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x61,
struct kdbus_cmd_update),
+ KDBUS_CMD_BUS_CREATOR_INFO = _IOWR(KDBUS_IOCTL_MAGIC, 0x62,
+ struct kdbus_cmd_info),
KDBUS_CMD_ENDPOINT_UPDATE = _IOW(KDBUS_IOCTL_MAGIC, 0x71,
struct kdbus_cmd_update),
More information about the systemd-commits
mailing list