metadata: preserve INVALID_UID when exporting creds into destination

When exporting creds into destination, if the meta creds were faked then
use the from_kuid() form instead of from_kuid_munged() this way we
preserve the INVALID_UID (uid_t) -1 and do not convert it to nobody.

This is useful for the bus proxy. We can change it later if it happens
this is not what we want. This is just an internal representation of
uid/gid values that can be changed at any time.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
metadata: duplicate owned names and connection description

In order to support moving messages between different pools, we also
need to remember the connection's description and all the names it
owned, because oth details might have changed between the initial
storing and the later move.

Already prepare struct kdbus_items of type KDBUS_ITEM_OWNED_NAME in
kdbus_meta_collect() for fewer memory fragmentation and faster
play-out in kdbus_meta_export().

This way, kdbus_meta_collect() needs to know about the source
connection to take the names and description from, while
kdbus_meta_export only needs to care for the destination to translate
for.

Signed-off-by: Daniel Mack <daniel@zonque.org>
metadata: fix conn_description regression

Debug left-over.

Signed-off-by: Daniel Mack <daniel@zonque.org>
connection: rename 'name' to 'description'

The item is referred to as CONN_DESCRIPTION in the external API, so
rename it internally as well to be consistent.

Signed-off-by: Daniel Mack <daniel@zonque.org>
metadata: split kdbus_meta_collect()

We need to collect connection description and owned names for CMD_INFO.

For that, factor out code to update this information in metadata into
kdbus_meta_collect_src(). This function will free existing information
and update it with current data.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test-conn-info: compare all cred fields with the ones of creation time

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
meta: add kdbus_meta_set_attach_flags() to set attach flags and use it

Add the new kdbus_meta_set_attach_flags() helper to check and set the
attach flags of buses and connections and use it.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection: use kdbus_meta_set_attach_flags() when updating connection flags

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test-connection: test case for update connection with invalid flags

The test case for the update connection attach flags with invalid flags

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection: on update check attach flags send against the bus attach requirements

Make sure that the attach_flags_send always satisfy the bus requirements

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
kdbus.txt: add some more text about KDBUS_ATTACH_SECLABEL items

Signed-off-by: Daniel Mack <daniel@zonque.org>
test-message: make sure that sender will not receive its own broadcasts

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test-endpoint: broadcast and kernel notification checks on custom endpoints

Make sure that connections on custom endpoints do not receive various
kernel notifications, unless there is a TALK policy that allows to
receive NAME notification.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test-message: quota checks for broadcast messages

This adds quota checks for broadcasts messages

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
metadata: properly pass uid==-1 through metadata

We explicitly allow user-space to provide -1 for data it is not aware of.
Make sure to pass it through metadata unchanged. However, always make sure
to munge IDs that cannot be mapped, even for faked data. Never turn
anything real into INVALID_UID, and never turn INVALID_UID into anything
real!

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
metadata: fix race when collecting conn-data

We really need to hold the connection lock when collecting metadata from
connections.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
metadata: fix information leak in conn-names items

We may have a lot of padding between items, due to 8byte alignment
restrictions. Make sure to clear the ITME_OWNED_NAME memory before adding
items, otherwise, we will leak un-initialized kernel memory to user-space.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
metadata: fix coding-style

Avoid splitting assignments if we can just split parameter-passing.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
metadata: fix KDBUS_ATTACH_NAMES item layout

The memory layout of owned names was broken in:

    commit 8f6365d12aff7850efeef32c5c06844b7a6b400c
    Author: Daniel Mack <daniel@zonque.org>
    Date:   Fri Nov 28 23:11:31 2014 +0100

        metadata: duplicate owned names and connection description

..which changed the item layout from "struct kdbus_name" to "char[]". Fix
this and restore the old behavior. Otherwise, we will be unable to read
name-flags from KDBUS_ITEM_OWNED_NAME.

This also fixes the test-suite to run properly again.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
bus: count dropped messages for monitors

Don't treat monitors differently from normal connections regarding dropped
messages. Especially for monitors it is highly interesting to know the
number of messages dropped.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>