mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2026-05-05 11:08:03 +02:00
bus: Try to get groups directly from credentials, not userdb
If we avoid consulting the userdb, then it's one less chance to deadlock. Signed-off-by: Simon McVittie <smcv@collabora.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103737 Reviewed-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
005bded7a8
commit
aaf690e805
1 changed files with 32 additions and 0 deletions
|
|
@ -1033,11 +1033,43 @@ bus_connection_get_unix_groups (DBusConnection *connection,
|
|||
int *n_groups,
|
||||
DBusError *error)
|
||||
{
|
||||
/* Assigning dbus_gid_t to unsigned long is lossless (in fact
|
||||
* they are the same type) */
|
||||
_DBUS_STATIC_ASSERT (sizeof (unsigned long) == sizeof (dbus_gid_t));
|
||||
|
||||
const dbus_gid_t *groups_borrowed = NULL;
|
||||
DBusCredentials *credentials;
|
||||
unsigned long uid;
|
||||
size_t n = 0;
|
||||
|
||||
*groups = NULL;
|
||||
*n_groups = 0;
|
||||
|
||||
credentials = _dbus_connection_get_credentials (connection);
|
||||
|
||||
if (credentials != NULL &&
|
||||
_dbus_credentials_get_unix_gids (credentials, &groups_borrowed, &n))
|
||||
{
|
||||
size_t i;
|
||||
|
||||
/* We got the group IDs from SO_PEERGROUPS or equivalent - no
|
||||
* need to ask NSS */
|
||||
|
||||
*n_groups = n;
|
||||
*groups = dbus_new (unsigned long, n);
|
||||
|
||||
if (groups == NULL)
|
||||
{
|
||||
BUS_SET_OOM (error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
(*groups)[i] = groups_borrowed[i];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (dbus_connection_get_unix_user (connection, &uid))
|
||||
{
|
||||
if (!_dbus_unix_groups_from_uid (uid, groups, n_groups))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue