test: sync the policy tests with the recent activators and policy holders changes

Recent commit 7015a1e6746e0c2 prevents special-purpose connections from
owning names, so update the test-kdbus-policy tests to follow and test
these changes.

Create a new policy holder connection which will register the policy for
an X name, and make the first conn_db[0] connection own that name.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
handle: return -EOPNOTSUPP instead of -EPERM if an operation is not supported

If userspace calls in with the wrong connection type, just return
-EOPNOTSUPP instead of -EPERM.

This will not confuse unprivileged and privileged processes, and permits
to identify legitimate -EPERM errors.

This just converts errors introduced in commit 7015a1e6746

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
handle: allow KDBUS_CMD_CONN_UPDATE ioctl for policy holders

Allow KDBUS_CMD_CONN_UPDATE for KDBUS_CONN_POLICY_HOLDER connections.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection: improve kdbus_cmd_conn_update() connection type checks

Do another round of connection type checks inside the KDBUS_ITEM
iterator.

We need this since we do not want to allow ordinary connections to
update policy entries that belong to another policy holder connection.

We also do it for the attach flags since only ordinary connections are
interessted in it.

And update a kdbus_policy_set() call to only pass a one name per
policy-holding connection

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
test: split conn_update() into update attach-flags and update policy

Since ordinary connections are only interested in the attach-flags and
policy holders in policies, split conn_update() into:
1) conn_update_attach_flags()
2) conn_update_policy()

This way we use the conn_update_policy() function in test-kdbus-policy
with a policy-holding connection and we pass all the tests. This
prevents messing up with the attach-flags.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
metadata: add new item type KDBUS_ITEM_AUXGROUPS (ABI break)

Add new data type to dump the auxiliary groups the sending task is a member
of.
test: add test code for KDBUS_ITEM_AUXGROUPS
metadata: return -EFAULT if get_task_mm(current) fails
pool: remove unneeded semicolon
test: test-kdbus: fix monitor and byebye tests

Since commit 7015a1e6 ("prevent special-purpose connections from
owning names or exchanging messages"), ioctl() calls return
-EOPNOTSUPP they are issued to a handle of a inapproprate type.
Follow this change in the test as well.
names: flush policy TALK cache when a connection loses a name

When a connection loses a name, make sure cache entries that allow
TALK access to it are properly removed. Upon the next TALK query,
the connection's names will be iterated and checked again.
policy: rename send_access_hash to talk_access_hash

We've already renamed the SEND policy to TALK for more clarity,
so let's do the same with the access hash.
policy, connection: rename policy cache related functions

Just so they reflect a little better what they're doing.
metadata: add kdbus_meta_offset_of()

kdbus_meta_offset_of() will iterate over the given metadata and return
the offset of the item of type @type, if it exists.
connection, metadata: do namespace translation as late as possible

We have to do the namespace translation just before a message is
installed into the receiver's task, so we actually know about the
currently used pid and user namespaces.

To achive this, store the byte offset pointer in the message in
kdbus_conn_queue_alloc(), and patch the values over from
kdbus_conn_msg_install().

Thanks to Djalal Harouni for pointing this out.
metadata: allow NULL pointers in kdbus_meta_append_data()

Allow NULL pointers to be passed as data argument to
kdbus_meta_append_data(), so users can use the function to only make space
in the metadata without actually copying any payload.
connection, metadata: convert auxgrp information as late as possible

Same as with the cred block - do the from_kgid() conversion shortly before
installing the message in the receiver's task.