From 9ed59dd16b7860d6df28e64a37cc1e42f21fbc7c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Jan 2018 19:12:41 +0000 Subject: [PATCH 01/11] DBusTransport, DBusConnection: Add internal getter for the credentials We have a lot of dbus_connection_get_foo() and _dbus_transport_get_foo() that are actually rather redundant. Signed-off-by: Simon McVittie --- dbus/dbus-connection-internal.h | 3 +++ dbus/dbus-connection.c | 19 +++++++++++++++++++ dbus/dbus-transport.c | 16 ++++++++++++++++ dbus/dbus-transport.h | 2 ++ 4 files changed, 40 insertions(+) diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 48357321..05b69e3c 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -117,6 +118,8 @@ void _dbus_connection_set_pending_fds_function (DBusConnectio DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_connection_get_linux_security_label (DBusConnection *connection, char **label_p); +DBUS_PRIVATE_EXPORT +DBusCredentials *_dbus_connection_get_credentials (DBusConnection *connection); /* if DBUS_ENABLE_STATS */ DBUS_PRIVATE_EXPORT diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 1079e35e..b43d43a8 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -5379,6 +5379,25 @@ _dbus_connection_get_linux_security_label (DBusConnection *connection, return result; } +DBusCredentials * +_dbus_connection_get_credentials (DBusConnection *connection) +{ + DBusCredentials *result; + + _dbus_assert (connection != NULL); + + CONNECTION_LOCK (connection); + + if (!_dbus_transport_try_to_authenticate (connection->transport)) + result = NULL; + else + result = _dbus_transport_get_credentials (connection->transport); + + CONNECTION_UNLOCK (connection); + + return result; +} + /** * Gets the Windows user SID of the connection if known. Returns * #TRUE if the ID is filled in. Always returns #FALSE on non-Windows diff --git a/dbus/dbus-transport.c b/dbus/dbus-transport.c index f2a96150..2337dd35 100644 --- a/dbus/dbus-transport.c +++ b/dbus/dbus-transport.c @@ -1475,6 +1475,22 @@ _dbus_transport_get_linux_security_label (DBusTransport *transport, } } +/** + * If the transport has already been authenticated, return its + * credentials. If not, return #NULL. + * + * The caller must ref the returned credentials object if it wants to + * keep it. + */ +DBusCredentials * +_dbus_transport_get_credentials (DBusTransport *transport) +{ + if (!transport->authenticated) + return FALSE; + + return _dbus_auth_get_identity (transport->auth); +} + /** * See dbus_connection_get_windows_user(). * diff --git a/dbus/dbus-transport.h b/dbus/dbus-transport.h index 9e3787dd..a7643027 100644 --- a/dbus/dbus-transport.h +++ b/dbus/dbus-transport.h @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -89,6 +90,7 @@ dbus_bool_t _dbus_transport_get_windows_user (DBusTransport char **windows_sid_p); dbus_bool_t _dbus_transport_get_linux_security_label (DBusTransport *transport, char **label_p); +DBusCredentials *_dbus_transport_get_credentials (DBusTransport *transport); void _dbus_transport_set_windows_user_function (DBusTransport *transport, DBusAllowWindowsUserFunction function, -- 2.15.1