size_t dst_name_len = 0;
size_t payloads = 0;
size_t fds = 0;
- size_t meta = 0;
+ size_t meta_off = 0;
size_t vec_data;
size_t want, have;
int ret = 0;
/* space for metadata/credential items */
if (kmsg->meta && kmsg->meta->size > 0 &&
kmsg->meta->domain == conn->meta->domain) {
- meta = msg_size;
+ meta_off = msg_size;
msg_size += kmsg->meta->size;
}
}
/* append message metadata/credential items */
- if (meta > 0) {
- struct kdbus_item *item;
+ if (meta_off > 0) {
+ struct kdbus_meta *meta = kmsg->meta;
/*
* If the receiver requested credential information, store the
* offset to the item here, so we can patch in the namespace
- * translated versions later.
+ * translated versions later. k
*/
- item = kdbus_meta_find_item(kmsg->meta, KDBUS_ITEM_CREDS);
- if (item) {
+ if (meta->attached & KDBUS_ATTACH_CREDS) {
/* store kernel-view of the credentials */
queue->uid = current_uid();
queue->gid = current_gid();
queue->tid = get_task_pid(current->group_leader,
PIDTYPE_PID);
- queue->creds_item_offset =
- ((u8 *) item - (u8 *) kmsg->meta->data) + meta;
+ queue->creds_item_offset = meta_off +
+ meta->creds_item_off;
}
- item = kdbus_meta_find_item(kmsg->meta, KDBUS_ITEM_AUXGROUPS);
- if (item) {
+ if (meta->attached & KDBUS_ATTACH_AUXGROUPS) {
struct group_info *info;
+ struct kdbus_item *item;
size_t item_elements;
int i;
* metadata element was composed, clamp the array
* length.
*/
+ item = (struct kdbus_item *)
+ ((u8 *) meta->data + meta->auxgrps_item_off);
item_elements = KDBUS_ITEM_PAYLOAD_SIZE(item) /
sizeof(__u64);
queue->auxgrps_count = min_t(unsigned int,
}
put_group_info(info);
- queue->auxgrp_item_offset =
- ((u8 *) item - (u8 *) kmsg->meta->data) + meta;
+ queue->auxgrp_item_offset = meta_off +
+ meta->auxgrps_item_off;
}
- ret = kdbus_pool_slice_copy(queue->slice, meta,
+ ret = kdbus_pool_slice_copy(queue->slice, meta_off,
kmsg->meta->data,
kmsg->meta->size);
if (ret < 0)
return 0;
}
-/**
- * kdbus_meta_find_item() - return the offset of a meta data element
- * @meta: Metadata object
- * @type: The metadata type to look for (KDBUS_ITEM_*)
- *
- * This function will iterate over the given metadata and return the
- * item of type @type, if it exists.
- *
- * Return: the first item of the requested type, if found. NULL otherwise.
- */
-struct kdbus_item *kdbus_meta_find_item(struct kdbus_meta *meta, u64 type)
-{
- struct kdbus_item *item;
-
- KDBUS_ITEMS_FOREACH(item, meta->data, meta->size)
- if (item->type == type)
- return item;
-
- return NULL;
-}
-
/**
* kdbus_meta_free() - release metadata
* @meta: Metadata object
}
static struct kdbus_item *
-kdbus_meta_append_item(struct kdbus_meta *meta, size_t extra_size)
+kdbus_meta_append_item(struct kdbus_meta *meta, u64 type, size_t extra_size)
{
struct kdbus_item *item;
size_t size;
/* insert new record */
item = (struct kdbus_item *)((u8 *)meta->data + meta->size);
+ item->type = type;
+
+ switch (type) {
+ case KDBUS_ITEM_CREDS:
+ meta->creds_item_off = meta->size;
+ break;
+ case KDBUS_ITEM_AUXGROUPS:
+ meta->auxgrps_item_off = meta->size;
+ break;
+ }
+
meta->size += KDBUS_ALIGN8(extra_size);
return item;
return 0;
size = KDBUS_ITEM_SIZE(len);
- item = kdbus_meta_append_item(meta, size);
+ item = kdbus_meta_append_item(meta, type, size);
if (IS_ERR(item))
return PTR_ERR(item);
- item->type = type;
item->size = KDBUS_ITEM_HEADER_SIZE + len;
if (data)
memcpy(item->data, data, len);
u64 size = KDBUS_ITEM_SIZE(sizeof(struct kdbus_timestamp));
struct timespec ts;
- item = kdbus_meta_append_item(meta, size);
+ item = kdbus_meta_append_item(meta, KDBUS_ITEM_TIMESTAMP, size);
if (IS_ERR(item))
return PTR_ERR(item);
- item->type = KDBUS_ITEM_TIMESTAMP;
item->size = size;
if (seq > 0)
len = strlen(e->name) + 1;
size = KDBUS_ITEM_SIZE(sizeof(struct kdbus_name) + len);
- item = kdbus_meta_append_item(meta, size);
+ item = kdbus_meta_append_item(meta, KDBUS_ITEM_NAME, size);
if (IS_ERR(item)) {
ret = PTR_ERR(item);
break;
}
- item->type = KDBUS_ITEM_NAME;
item->size = KDBUS_ITEM_HEADER_SIZE +
sizeof(struct kdbus_name) + len;
item->name.flags = e->flags;