test: clean up kdbus_hello() a bit

Make clean in the struct layout where the conn_name item is.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test: utils: restore previous logic of kdbus_msg_recv_poll()

kdbus_msg_recv_poll() must return -ETIMEDOUT, and return the result of
kdbus_msg_recv() and in case of -EAGAIN (Resource temporarily
unavailable) we need to try again...

Currently all of these are ignored, so restor them back.

Our tests and logic depend on this.

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
connection: release the write lock on errors

Signed-off-by: Djalal Harouni <tixxdz@opendz.org>
domain: simplify kdbus_domain_find()

This helper is unlocked. There is no reason to take references to domains
if we never use them.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
domain: embed 'struct device'

We currently allocate a dynamic "struct device" object as domain->dev.
There is really no need to do that. We can safely embed it as part of
"struct kdbus_domain" and get rid of our own ref-counter. Instead, use the
ref-counter of the device.

This way, container_of(device, struct kdbus_domain, dev) on "struct
device" will return a pointer to our kdbus-domain. This will be very handy
once we embed char-devs, too. We can finally get rid of our own IDRs and
use the char-dev IDRs for lookup.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
endpoint: embed 'struct device'

Same as for domains: there is no reason to keep dynamically allocated
devices. We can safely embed it in our own object and drop the kref
ref-count.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
bus: fix typo in comment
handle: minor fix to documentation
handle: don't leak endpoint when KDBUS_HANDLE_EP_OWNER handle is released

Signed-off-by: Tom Gundersen <teg@jklm.no>
endpoint: clean up kdbus_ep_policy_check_see_access_unlocked()

Just a cosmetic cleanup.

Signed-off-by: Daniel Mack <daniel@zonque.org>
endpoint: don't leak hints on whether a name exists on a custom endpoint

The whole point of installing policy on custom endpoint is not not let
users of that endpoint know that a name exists. Returning -EPERM in
response to such attempts leaks the information that the name in fact
exists, but is firewalled.

To fix this, return -ENOENT when policy returns -EPERM on custom
endpoints.

Signed-off-by: Daniel Mack <daniel@zonque.org>
item: add kdbus_items_get_str()

Introduce a new helper function called kdbus_items_get_str(), which
walks a list of items in order to find one which matches a given type
and return the ->str pointer inside of it.

This allows us to ditch various implementations of similar functions.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test: add custom endpoint test

Add a test to check the behavior of custom endpoints. Not finished yet.

Signed-off-by: Daniel Mack <daniel@zonque.org>
test-util: fix kdbus_msg_recv_poll()

Implement kdbus_msg_recv_poll() so that it really takes the time before
and after poll() is called, so that we know how ofter we have to repeat
the loop before we give up.

Signed-off-by: Daniel Mack <daniel@zonque.org>
handle: document kdbus_handle.ptr

Signed-off-by: Daniel Mack <daniel@zonque.org>
handle.c: drop unused include

Signed-off-by: Daniel Mack <daniel@zonque.org>
item: make kdbus_items_get_str() work with KDBUS_ITEM_NAME_{ADD,REMOVE,CHANGE}

KDBUS_ITEM_NAME_{ADD,REMOVE,CHANGE} embed their string in
item->name_change.name, not item->str. Handle that case.

Signed-off-by: Daniel Mack <daniel@zonque.org>
ep: add kdbus_ep_policy_check_notification()

When delivering notification to connections, make sure to check whether
their carried name is allowed by the destination endpoint's policy, and
supress the notification otherwise.

This is important to we don't leak notifications on added names if the
endpoint enforces a SEE policy.

Signed-off-by: Daniel Mack <daniel@zonque.org>
connection: switch to timespec64

Signed-off-by: Daniel Mack <daniel@zonque.org>
endpoint: fix kernel-doc

Fix kernel-doc spelling for kdbus_ep_policy_check_notification()

Signed-off-by: Daniel Mack <daniel@zonque.org>