From 65dae17a2f890b12a07dd4901b3db02b1031c463 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 4 Dec 2013 23:36:02 +0100 Subject: [PATCH] bus: switch to multiple KDBUS_ITEM_NAME including the flags --- src/libsystemd-bus/bus-control.c | 9 +++------ src/libsystemd-bus/bus-creds.c | 17 +++------------- src/libsystemd-bus/bus-creds.h | 4 +--- src/libsystemd-bus/bus-kernel.c | 8 +++++--- src/libsystemd-bus/kdbus.h | 33 +++++++++++++++++++++----------- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c index b1172899d..186724e8a 100644 --- a/src/libsystemd-bus/bus-control.c +++ b/src/libsystemd-bus/bus-control.c @@ -504,14 +504,11 @@ static int bus_get_owner_kdbus( } break; - case KDBUS_ITEM_NAMES: + case KDBUS_ITEM_NAME: if (mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) { - c->well_known_names_size = item->size - KDBUS_PART_HEADER_SIZE; - c->well_known_names = memdup(item->data, c->well_known_names_size); - if (!c->well_known_names) { - r = -ENOMEM; + r = strv_extend(&c->well_known_names, item->name.name); + if (r < 0) goto fail; - } c->mask |= SD_BUS_CREDS_WELL_KNOWN_NAMES; } diff --git a/src/libsystemd-bus/bus-creds.c b/src/libsystemd-bus/bus-creds.c index 607131273..1eb0e02e7 100644 --- a/src/libsystemd-bus/bus-creds.c +++ b/src/libsystemd-bus/bus-creds.c @@ -50,7 +50,7 @@ void bus_creds_done(sd_bus_creds *c) { free(c->slice); strv_free(c->cmdline_array); - strv_free(c->well_known_names_array); + strv_free(c->well_known_names); } _public_ sd_bus_creds *sd_bus_creds_ref(sd_bus_creds *c) { @@ -89,7 +89,6 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) { free(c->capability); free(c->label); free(c->unique_name); - free(c->well_known_names); free(c); } } else { @@ -385,15 +384,7 @@ _public_ int sd_bus_creds_get_well_known_names(sd_bus_creds *c, char ***well_kno assert_return(well_known_names, -EINVAL); assert_return(c->mask & SD_BUS_CREDS_WELL_KNOWN_NAMES, -ENODATA); - assert(c->well_known_names); - - if (!c->well_known_names_array) { - c->well_known_names_array = strv_parse_nulstr(c->well_known_names, c->well_known_names_size); - if (!c->well_known_names_array) - return -ENOMEM; - } - - *well_known_names = c->well_known_names_array; + *well_known_names = c->well_known_names; return 0; } @@ -804,11 +795,9 @@ int bus_creds_extend_by_pid(sd_bus_creds *c, uint64_t mask, sd_bus_creds **ret) } if (c->mask & mask & SD_BUS_CREDS_WELL_KNOWN_NAMES) { - n->well_known_names = memdup(c->well_known_names, c->well_known_names_size); + n->well_known_names = strv_copy(c->well_known_names); if (!n->well_known_names) return -ENOMEM; - - n->well_known_names_size = c->well_known_names_size; } /* Get more data */ diff --git a/src/libsystemd-bus/bus-creds.h b/src/libsystemd-bus/bus-creds.h index 269688a48..089a64bfc 100644 --- a/src/libsystemd-bus/bus-creds.h +++ b/src/libsystemd-bus/bus-creds.h @@ -61,9 +61,7 @@ struct sd_bus_creds { char *unique_name; - char *well_known_names; - size_t well_known_names_size; - char **well_known_names_array; + char **well_known_names; }; sd_bus_creds* bus_creds_new(void); diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index b85a10dd3..2c87f22fd 100644 --- a/src/libsystemd-bus/bus-kernel.c +++ b/src/libsystemd-bus/bus-kernel.c @@ -28,6 +28,7 @@ #include #include "util.h" +#include "strv.h" #include "bus-internal.h" #include "bus-message.h" @@ -800,9 +801,10 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { destination = d->str; break; - case KDBUS_ITEM_NAMES: - m->creds.well_known_names = d->str; - m->creds.well_known_names_size = l; + case KDBUS_ITEM_NAME: + 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; diff --git a/src/libsystemd-bus/kdbus.h b/src/libsystemd-bus/kdbus.h index 16edcc646..76333099d 100644 --- a/src/libsystemd-bus/kdbus.h +++ b/src/libsystemd-bus/kdbus.h @@ -27,7 +27,7 @@ #define KDBUS_DST_ID_BROADCAST (~0ULL) /** - * struct KDBUS_PART_HEADER - header + * struct KDBUS_PART_HEADER - anonymous struct used as header * @size: Size of element, excluding padding bytes * @type Type of element * @@ -81,10 +81,10 @@ struct kdbus_notify_id_change { /** * struct kdbus_creds - process credentials - * @uid User id - * @gid Group id - * @pid Process id - * @tid Thread id + * @uid User ID + * @gid Group ID + * @pid Process ID + * @tid Thread ID * @starttime Starttime of the process * * The starttime of the process PID. This is useful to detect PID overruns @@ -146,6 +146,16 @@ struct kdbus_memfd { __u32 __pad; }; +/** + * struct kdbus_name - a registered well-known name with its flags + * @flags flags from KDBUS_NAME_* + * @name well-known name + */ +struct kdbus_name { + __u64 flags; + char name[0]; +}; + /* Message Item Types */ enum { _KDBUS_ITEM_NULL, @@ -162,7 +172,7 @@ enum { /* Filled in by kernelspace */ _KDBUS_ITEM_ATTACH_BASE = 0x400, - KDBUS_ITEM_NAMES = 0x400,/* NUL separated string list with well-known names of source */ + KDBUS_ITEM_NAME = 0x400,/* NUL separated string list with well-known names of source */ KDBUS_ITEM_STARTER_NAME, /* Only used in HELLO for starter connection */ KDBUS_ITEM_TIMESTAMP, /* .timestamp */ @@ -212,6 +222,7 @@ struct kdbus_item { struct kdbus_creds creds; struct kdbus_audit audit; struct kdbus_timestamp timestamp; + struct kdbus_name name; /* specific fields */ struct kdbus_memfd memfd; @@ -354,7 +365,7 @@ enum { * KDBUS_CMD_BUS_MAKE ioctl. It's intended to be useful * to do negotiation of features of the payload that is * transferred (kernel → userspace) - * @id: The id of this connection (kernel → userspace) + * @id: The ID of this connection (kernel → userspace) * @bloom_size: The bloom filter size chosen by the owner * (kernel → userspace) * @pool_size: Maximum size of the pool buffer (kernel → userspace) @@ -559,10 +570,10 @@ struct kdbus_conn_info { enum { _KDBUS_MATCH_NULL, KDBUS_MATCH_BLOOM, /* Matches a mask blob against KDBUS_MSG_BLOOM */ - KDBUS_MATCH_SRC_NAME, /* Matches a name string against KDBUS_MSG_SRC_NAMES */ - KDBUS_MATCH_NAME_ADD, /* Matches a name string against KDBUS_MSG_NAME_ADD */ - KDBUS_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_MSG_NAME_REMOVE */ - KDBUS_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_MSG_NAME_CHANGE */ + KDBUS_MATCH_SRC_NAME, /* Matches a name string against KDBUS_ITEM_NAME */ + KDBUS_MATCH_NAME_ADD, /* Matches a name string against KDBUS_ITEM_NAME_ADD */ + KDBUS_MATCH_NAME_REMOVE, /* Matches a name string against KDBUS_ITEM_NAME_REMOVE */ + KDBUS_MATCH_NAME_CHANGE, /* Matches a name string against KDBUS_ITEM_NAME_CHANGE */ KDBUS_MATCH_ID_ADD, /* Matches an ID against KDBUS_MSG_ID_ADD */ KDBUS_MATCH_ID_REMOVE, /* Matches an ID against KDBUS_MSG_ID_REMOVE */ }; -- 2.30.2