Commit 5a07eda3 authored by Simon McVittie's avatar Simon McVittie

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's avatarSimon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall's avatarPhilip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737
parent 03c0db9f
......@@ -25,6 +25,7 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-connection.h>
#include <dbus/dbus-credentials.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-transport.h>
#include <dbus/dbus-resources.h>
......@@ -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
......
......@@ -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
......
......@@ -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().
*
......
......@@ -25,6 +25,7 @@
#include <dbus/dbus-internals.h>
#include <dbus/dbus-connection.h>
#include <dbus/dbus-credentials.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-address.h>
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment