From c1a59f0fea03523b055d334e7dca5dcdc7054df3 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 4 Oct 2016 18:39:11 +0100 Subject: [PATCH 2/2] bus: Add LSM label to connection loginfo string If it is set (i.e. if an LSM is in use) this will make it appear in various places in log output. With SELinux, for example, this appends something like: label="system_u:object_r:unlabeled_t:s0" This commit partially rearranges the code which sets the loginfo string, so that it consistently puts a space between fields, and not one at the end. https://bugs.freedesktop.org/show_bug.cgi?id=68212 --- bus/connection.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/bus/connection.c b/bus/connection.c index 17995ca..bdb2fea 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -584,7 +584,7 @@ cache_peer_loginfo_string (BusConnectionData *d, DBusString loginfo_buf; unsigned long uid; unsigned long pid; - char *windows_sid; + char *windows_sid, *security_label; dbus_bool_t prev_added; if (!_dbus_string_init (&loginfo_buf)) @@ -613,16 +613,46 @@ cache_peer_loginfo_string (BusConnectionData *d, _dbus_command_for_pid (pid, &loginfo_buf, MAX_LOG_COMMAND_LEN, NULL); if (!_dbus_string_append_byte (&loginfo_buf, '"')) goto oom; + else + prev_added = TRUE; } if (dbus_connection_get_windows_user (connection, &windows_sid)) { 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, - "sid=\"%s\" ", windows_sid); + "sid=\"%s\"", windows_sid); dbus_free (windows_sid); if (!did_append) goto oom; + else + prev_added = TRUE; + } + + if (_dbus_connection_get_linux_security_label (connection, &security_label)) + { + 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, + "label=\"%s\"", security_label); + dbus_free (security_label); + if (!did_append) + goto oom; + else + prev_added = TRUE; } if (!_dbus_string_steal_data (&loginfo_buf, &(d->cached_loginfo_string))) -- 2.7.4