From: Simon McVittie Date: Fri, 12 Jan 2018 19:12:41 +0000 (+0000) Subject: DBusTransport, DBusConnection: Add internal getter for the credentials X-Git-Tag: dbus-1.13.4~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a07eda31e6c2fd3d4965ed7ff46991ac86c615b;p=thirdparty%2Fdbus.git 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 Reviewed-by: Philip Withnall Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737 --- diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 483573212..05b69e3c9 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 c525b6dc1..b097cc6e0 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -5380,6 +5380,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 f2a961503..2337dd358 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 9e3787ddb..a76430273 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,