From faa3ee6f37efb0dbb3b387f73ca01cf8a9284632 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 15 Jan 2018 19:45:39 +0000 Subject: [PATCH 08/11] 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 --- bus/connection.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/bus/connection.c b/bus/connection.c index 91b1966e..a3046dcb 100644 --- a/bus/connection.c +++ b/bus/connection.c @@ -1032,11 +1032,38 @@ bus_connection_get_unix_groups (DBusConnection *connection, int *n_groups, DBusError *error) { + const unsigned long *groups_borrowed = NULL; + DBusCredentials *credentials; unsigned long uid; *groups = NULL; *n_groups = 0; + credentials = _dbus_connection_get_credentials (connection); + + if (credentials != NULL && + _dbus_credentials_get_unix_gids (credentials, &groups_borrowed, + n_groups)) + { + int i; + + /* We got the group IDs from SO_PEERGROUPS or equivalent - no + * need to ask NSS */ + + *groups = dbus_new (dbus_gid_t, *n_groups); + + if (groups == NULL) + { + BUS_SET_OOM (error); + return FALSE; + } + + for (i = 0; i < *n_groups; 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)) -- 2.15.1