containers: Factor out connection_get_instance and make it NULL-safe

When I introduce per-container message filtering, it'll be useful to
be able to get the instance for a connection without worrying about
whether that connection is NULL (representing the dbus-daemon itself,
or an activatable service that has not yet been activated).

Also make it robust against Containers having not been initialized,
for completeness.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=105656
This commit is contained in:
Simon McVittie 2018-04-16 19:35:59 +01:00
parent 9a369ee3bd
commit 7512fe4993

View file

@ -1119,6 +1119,23 @@ failed:
return FALSE;
}
/*
* This accepts a NULL connection so that it can be used when checking
* whether to allow sending or receiving a message, which might involve
* the dbus-daemon itself as a message sender or recipient.
*/
static BusContainerInstance *
connection_get_instance (DBusConnection *connection)
{
if (connection == NULL)
return NULL;
if (contained_data_slot == -1)
return NULL;
return dbus_connection_get_data (connection, contained_data_slot);
}
dbus_bool_t
bus_containers_handle_get_connection_instance (DBusConnection *caller,
BusTransaction *transaction,
@ -1154,7 +1171,7 @@ bus_containers_handle_get_connection_instance (DBusConnection *caller,
goto failed;
}
instance = dbus_connection_get_data (subject, contained_data_slot);
instance = connection_get_instance (subject);
if (instance == NULL)
{
@ -1413,7 +1430,7 @@ bus_containers_remove_connection (BusContainers *self,
}
}
instance = dbus_connection_get_data (connection, contained_data_slot);
instance = connection_get_instance (connection);
if (instance != NULL)
{
@ -1438,7 +1455,7 @@ bus_containers_connection_is_contained (DBusConnection *connection,
#ifdef DBUS_ENABLE_CONTAINERS
BusContainerInstance *instance;
instance = dbus_connection_get_data (connection, contained_data_slot);
instance = connection_get_instance (connection);
if (instance != NULL)
{