From c2ee2304f698b3144aefaf82662b12be02e769b9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Jun 2017 22:27:52 +0100 Subject: [PATCH] bus/containers: Indicate in loginfo whether connection is contained Signed-off-by: Simon McVittie --- bus/connection.c | 26 ++++++++++++++++++++++++++ bus/containers.c | 29 +++++++++++++++++++++++++++++ bus/containers.h | 5 +++++ 3 files changed, 60 insertions(+) diff --git a/bus/connection.c b/bus/connection.c index 4d6c4e43..1b5b4917 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -588,6 +588,9 @@ cache_peer_loginfo_string (BusConnectionData *d, unsigned long pid; char *windows_sid = NULL, *security_label = NULL; dbus_bool_t prev_added; + const char *container = NULL; + const char *container_type = NULL; + const char *container_name = NULL; if (!_dbus_string_init (&loginfo_buf)) return FALSE; @@ -659,6 +662,29 @@ cache_peer_loginfo_string (BusConnectionData *d, prev_added = TRUE; } + if (bus_containers_connection_is_contained (connection, &container, + &container_type, + &container_name)) + { + dbus_bool_t did_append; + + if (prev_added) + { + if (!_dbus_string_append_byte (&loginfo_buf, ' ')) + goto oom; + } + + did_append = _dbus_string_append_printf (&loginfo_buf, + "container=%s %s=\"%s\")", + container, + container_type, + container_name); + if (!did_append) + goto oom; + else + prev_added = TRUE; + } + if (!_dbus_string_steal_data (&loginfo_buf, &(d->cached_loginfo_string))) goto oom; diff --git a/bus/containers.c b/bus/containers.c index 0d670578..6777290a 100644 --- a/bus/containers.c +++ b/bus/containers.c @@ -1087,3 +1087,32 @@ bus_containers_remove_connection (BusContainers *self, dbus_connection_unref (connection); #endif /* DBUS_ENABLE_CONTAINERS */ } + +dbus_bool_t +bus_containers_connection_is_contained (DBusConnection *connection, + const char **path, + const char **type, + const char **name) +{ +#ifdef DBUS_ENABLE_CONTAINERS + BusContainerInstance *instance; + + instance = dbus_connection_get_data (connection, contained_data_slot); + + if (instance != NULL) + { + if (path != NULL) + *path = instance->path; + + if (type != NULL) + *type = instance->type; + + if (name != NULL) + *name = instance->name; + + return TRUE; + } +#endif /* DBUS_ENABLE_CONTAINERS */ + + return FALSE; +} diff --git a/bus/containers.h b/bus/containers.h index ed52625b..10457baa 100644 --- a/bus/containers.h +++ b/bus/containers.h @@ -50,4 +50,9 @@ dbus_bool_t bus_containers_supported_arguments_getter (BusContext *context, void bus_containers_remove_connection (BusContainers *self, DBusConnection *connection); +dbus_bool_t bus_containers_connection_is_contained (DBusConnection *connection, + const char **path, + const char **type, + const char **name); + #endif /* multiple-inclusion guard */ -- 2.13.2