From 9acc90f195babd6be689ea30a5b6dbdb42ba55a1 Mon Sep 17 00:00:00 2001 From: Mike Gilbert Date: Fri, 13 Jun 2025 19:07:34 -0400 Subject: [PATCH] user-info.eclass: fix egetgroups when ROOT is not empty Closes: https://bugs.gentoo.org/958022 Signed-off-by: Mike Gilbert --- eclass/user-info.eclass | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/eclass/user-info.eclass b/eclass/user-info.eclass index 1cc7b82503091..848622fe94e90 100644 --- a/eclass/user-info.eclass +++ b/eclass/user-info.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2023 Gentoo Authors +# Copyright 1999-2025 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: user-info.eclass @@ -165,13 +165,18 @@ egetgroups() { [[ $# -eq 1 ]] || die "usage: egetgroups " local egroups_arr - if [[ -n "${ROOT}" ]]; then - local pgroup=$(egetent passwd "$1" | cut -d: -f1) - local sgroups=( $(grep -E ":([^:]*,)?$1(,[^:]*)?$" "${ROOT}/etc/group" | cut -d: -f1) ) - # Remove primary group from list - sgroups=${sgroups#${pgroup}} - egroups_arr=( ${pgroup} ${sgroups[@]} ) + if [[ -n "${ROOT}" ]]; then + local pgid=$(egetent passwd "$1" | cut -d: -f4) + local pgroup=$(egetent group "${pgid}" | cut -d: -f1) + local sgroups=( $(grep -E ":([^:]*,)?$1(,[^:]*)?$" "${ROOT}/etc/group" | cut -d: -f1) ) + egroups_arr=( "${pgroup}" ) + local sg + for sg in "${sgroups[@]}"; do + if [[ ${sg} != ${pgroup} ]]; then + egroups_arr+=( "${sg}" ) + fi + done else read -r -a egroups_arr < <(id -G -n "$1") fi